]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
mmc: fsl_esdhc: Fix PIO timeout
authorBenoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
Sun, 29 Oct 2017 21:08:58 +0000 (22:08 +0100)
committerStefano Babic <sbabic@denx.de>
Tue, 7 Nov 2017 09:26:27 +0000 (10:26 +0100)
The following error has been observed on i.MX25 with a high-speed SDSC
card:
    Data Write Failed in PIO Mode.

It was caused by the timeout set on PRSSTAT.BWEN, which was triggered
because this bit takes 15 ms to be set after writing the first block to
DATPORT with this card. Without this timeout, all the blocks are
properly written.

This timeout was implemented by decrementing a variable, so it was
depending on the CPU frequency. Fix this issue by setting this timeout
to a long enough absolute duration (500 ms).

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Fabio Estevam <fabio.estevam@nxp.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>
drivers/mmc/fsl_esdhc.c
include/fsl_esdhc.h

index cc188c4260737c4fa29a399f410ba939ab09b67f..499d622c6d925d64d44f903bd5a7dafb72e4efdb 100644 (file)
@@ -171,20 +171,20 @@ static void esdhc_pio_read_write(struct fsl_esdhc_priv *priv,
        uint databuf;
        uint size;
        uint irqstat;
-       uint timeout;
+       ulong start;
 
        if (data->flags & MMC_DATA_READ) {
                blocks = data->blocks;
                buffer = data->dest;
                while (blocks) {
-                       timeout = PIO_TIMEOUT;
+                       start = get_timer(0);
                        size = data->blocksize;
                        irqstat = esdhc_read32(&regs->irqstat);
-                       while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BREN)
-                               && --timeout);
-                       if (timeout <= 0) {
-                               printf("\nData Read Failed in PIO Mode.");
-                               return;
+                       while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BREN)) {
+                               if (get_timer(start) > PIO_TIMEOUT) {
+                                       printf("\nData Read Failed in PIO Mode.");
+                                       return;
+                               }
                        }
                        while (size && (!(irqstat & IRQSTAT_TC))) {
                                udelay(100); /* Wait before last byte transfer complete */
@@ -200,14 +200,14 @@ static void esdhc_pio_read_write(struct fsl_esdhc_priv *priv,
                blocks = data->blocks;
                buffer = (char *)data->src;
                while (blocks) {
-                       timeout = PIO_TIMEOUT;
+                       start = get_timer(0);
                        size = data->blocksize;
                        irqstat = esdhc_read32(&regs->irqstat);
-                       while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BWEN)
-                               && --timeout);
-                       if (timeout <= 0) {
-                               printf("\nData Write Failed in PIO Mode.");
-                               return;
+                       while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BWEN)) {
+                               if (get_timer(start) > PIO_TIMEOUT) {
+                                       printf("\nData Write Failed in PIO Mode.");
+                                       return;
+                               }
                        }
                        while (size && (!(irqstat & IRQSTAT_TC))) {
                                udelay(100); /* Wait before last byte transfer complete */
index 02b362d5e36e2d74a06960d4005f39f67f32adf0..de1f5e7d9f5d1155ca1def0977caadfe7f2c2868 100644 (file)
 #define XFERTYP_DMAEN          0x00000001
 
 #define CINS_TIMEOUT           1000
-#define PIO_TIMEOUT            100000
+#define PIO_TIMEOUT            500
 
 #define DSADDR         0x2e004