From: Nicolas Ferre <nicolas.ferre@atmel.com>
To: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: "Hans-Jürgen Koch" <hjk@linutronix.de>,
"Ville Syrjälä" <syrjala@sci.fi>,
"Linux Kernel list" <linux-kernel@vger.kernel.org>
Subject: [PATCH 3/7] mmc: at91_mci: avoid timeouts
Date: Fri, 30 May 2008 14:45:01 +0200 [thread overview]
Message-ID: <483FF6CD.4040801@atmel.com> (raw)
In-Reply-To: <483FE9E7.7020707@atmel.com>
From: Marc Pignat <marc.pignat@hevs.ch>
The at91 mci controller internal state machine seems to often crash.
This can
be fixed by resetting the controller after each command for at91rm9200
and by
setting the MCI_BLKR register on at91sam926*.
Signed-off-by: Marc Pignat <marc.pignat@hevs.ch>
Signed-off-by: Hans J Koch <hjk@linutronix.de>
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
drivers/mmc/host/at91_mci.c | 48
++++++++++++++++++++++++++++++++++
include/asm-arm/arch-at91/at91_mci.h | 4 +++
2 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c
index 4b4518f..6b9662e 100644
--- a/drivers/mmc/host/at91_mci.c
+++ b/drivers/mmc/host/at91_mci.c
@@ -130,6 +130,43 @@ struct at91mci_host
struct timer_list timer;
};
+/*
+ * Reset the controller and restore most of the state
+ */
+static void at91_reset_host(struct at91mci_host *host)
+{
+ unsigned long flags;
+ u32 mr;
+ u32 sdcr;
+ u32 dtor;
+ u32 imr;
+
+ local_irq_save(flags);
+ imr = at91_mci_read(host, AT91_MCI_IMR);
+
+ at91_mci_write(host, AT91_MCI_IDR, 0xffffffff);
+
+ /* save current state */
+ mr = at91_mci_read(host, AT91_MCI_MR) & 0x7fff;
+ sdcr = at91_mci_read(host, AT91_MCI_SDCR);
+ dtor = at91_mci_read(host, AT91_MCI_DTOR);
+
+ /* reset the controller */
+ at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIDIS | AT91_MCI_SWRST);
+
+ /* restore state */
+ at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN);
+ at91_mci_write(host, AT91_MCI_MR, mr);
+ at91_mci_write(host, AT91_MCI_SDCR, sdcr);
+ at91_mci_write(host, AT91_MCI_DTOR, dtor);
+ at91_mci_write(host, AT91_MCI_IER, imr);
+
+ /* make sure sdio interrupts will fire */
+ at91_mci_read(host, AT91_MCI_SR);
+
+ local_irq_restore(flags);
+}
+
static void at91_timeout_timer(unsigned long data)
{
struct at91mci_host *host;
@@ -148,6 +185,7 @@ static void at91_timeout_timer(unsigned long data)
host->request->cmd->error = -ETIMEDOUT;
}
+ at91_reset_host(host);
mmc_request_done(host->mmc, host->request);
}
}
@@ -512,6 +550,11 @@ static void at91_mci_send_command(struct
at91mci_host *host, struct mmc_command
mr |= AT91_MCI_PDCMODE;
at91_mci_write(host, AT91_MCI_MR, mr);
+ if (!cpu_is_at91rm9200())
+ at91_mci_write(host, AT91_MCI_BLKR,
+ AT91_MCI_BLKR_BCNT(blocks) |
+ AT91_MCI_BLKR_BLKLEN(block_length));
+
/*
* Disable the PDC controller
*/
@@ -584,6 +627,11 @@ static void at91_mci_process_next(struct
at91mci_host *host)
at91_mci_send_command(host, host->request->stop);
} else {
del_timer(&host->timer);
+ /* the at91rm9200 mci controller hangs after some transfers,
+ * and the workaround is to reset it after each transfer.
+ */
+ if (cpu_is_at91rm9200())
+ at91_reset_host(host);
mmc_request_done(host->mmc, host->request);
}
}
diff --git a/include/asm-arm/arch-at91/at91_mci.h
b/include/asm-arm/arch-at91/at91_mci.h
index 1551fc2..400ec10 100644
--- a/include/asm-arm/arch-at91/at91_mci.h
+++ b/include/asm-arm/arch-at91/at91_mci.h
@@ -75,6 +75,10 @@
#define AT91_MCI_TRTYP_MULTIPLE (1 << 19)
#define AT91_MCI_TRTYP_STREAM (2 << 19)
+#define AT91_MCI_BLKR 0x18 /* Block Register */
+#define AT91_MCI_BLKR_BCNT(n) ((0xffff & (n)) << 0) /* Block count */
+#define AT91_MCI_BLKR_BLKLEN(n) ((0xffff & (n)) << 16) /* Block lenght */
+
#define AT91_MCI_RSPR(n) (0x20 + ((n) * 4)) /* Response Registers 0-3 */
#define AT91_MCR_RDR 0x30 /* Receive Data Register */
#define AT91_MCR_TDR 0x34 /* Transmit Data Register */
--
1.5.3.7
next prev parent reply other threads:[~2008-05-30 12:45 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-30 11:49 [PATCH 0/7] mmc: at91_mci: rework to allow better transfer Nicolas Ferre
2008-05-30 12:18 ` [PATCH 5/7] mmc: at91_mci: update bytes_xfered value once xfer done Nicolas Ferre
2008-06-01 14:44 ` Russell King - ARM Linux
2008-05-30 12:26 ` [PATCH 6/7] mmc: at91_mci: add sdio irq management Nicolas Ferre
2008-05-30 12:28 ` [PATCH 7/7] mmc: at91_mci: do not read irq status twice as it will forget some errors Nicolas Ferre
2008-05-30 12:43 ` [PATCH 1/7] mmc: at91_mci: support for block size not modulo 4 Nicolas Ferre
2008-05-30 12:44 ` [PATCH 2/7] mmc: at91_mci: show timeouts Nicolas Ferre
2008-05-30 12:45 ` Nicolas Ferre [this message]
2008-05-30 12:45 ` [PATCH 4/7] mmc: at91_mci: add multiwrite switch Nicolas Ferre
[not found] ` <483FED84.50100@atmel.com>
2008-05-30 12:57 ` [PATCH 1/7] mmc: at91_mci: support for block size not modulo 4 Marc Pignat
[not found] ` <483FEE58.5000500@atmel.com>
2008-06-01 14:42 ` [PATCH 4/7] mmc: at91_mci: add multiwrite switch Russell King - ARM Linux
2008-06-09 10:42 ` Pierre Ossman
2008-06-09 13:08 ` Russell King - ARM Linux
2008-06-09 13:42 ` Pierre Ossman
2008-06-09 13:53 ` Russell King - ARM Linux
2008-06-09 13:58 ` Pierre Ossman
2008-06-09 10:46 ` [PATCH 0/7] mmc: at91_mci: rework to allow better transfer Pierre Ossman
2008-06-10 9:54 ` Nicolas Ferre
2008-06-14 16:28 ` Pierre Ossman
2008-06-18 10:04 ` Nicolas Ferre
2008-06-18 10:47 ` Erik Mouw
2008-06-18 11:16 ` Erik Mouw
2008-06-18 11:40 ` Hans J. Koch
2008-06-18 11:47 ` David Woodhouse
2008-06-18 13:35 ` Erik Mouw
2008-06-18 13:37 ` David Woodhouse
2008-06-18 15:17 ` Erik Mouw
2008-06-20 16:30 ` Pierre Ossman
[not found] ` <6306c640806201005n17aba42ag6f0bc344256a1ad@mail.gmail.com>
2008-06-20 17:25 ` Pierre Ossman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=483FF6CD.4040801@atmel.com \
--to=nicolas.ferre@atmel.com \
--cc=hjk@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=syrjala@sci.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox