[U-Boot] [PATCH] ARM: bcm2835: (Raspberry Pi) Fix issue on SD Host driver, where wait_transfer_complete was not waiting long enough

Raul Benet raul.benet at kaptivo.com
Thu Jun 13 13:59:57 UTC 2019


Function bcm_2835_wait_transfer_complete() on driver/mmc/bcm2835_sdhost.c
(used on Raspberry Pi platform), was not waiting long enough for
transfer to complete.
The previous code was claiming to wait for ~1 seconds, but my measurements
on a RPi 3B+ indicated a maximum wait of 12 ms. Measured using
get_tiimer() function.
Some, but not all, of the cards we use, sometimes required wait times
of ~56 ms to perform
the command 'saveenv' on an EXT4 partition. (the exact operation being a CMD25
write of the superblock of EXT4).

Re-implemented the loop exit condition to use get_timer() which allows
to specify
the wait time in more reliable manner. Set the maximum wait time to
the originally
intended 1 second.

Signed-off by: Raul Benet <raul.benet_at_kaptivo.com>

---
 drivers/mmc/bcm2835_sdhost.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/bcm2835_sdhost.c b/drivers/mmc/bcm2835_sdhost.c
index 1ce019a..96e06b8 100644
--- a/drivers/mmc/bcm2835_sdhost.c
+++ b/drivers/mmc/bcm2835_sdhost.c
@@ -234,7 +234,7 @@ static void bcm2835_reset_internal(struct
bcm2835_host *host)

 static int bcm2835_wait_transfer_complete(struct bcm2835_host *host)
 {
- int timediff = 0;
+        ulong tstart_ms = get_timer(0);

  while (1) {
  u32 edm, fsm;
@@ -254,11 +254,12 @@ static int bcm2835_wait_transfer_complete(struct
bcm2835_host *host)
  break;
  }

- /* Error out after 100000 register reads (~1s) */
- if (timediff++ == 100000) {
+ /* Error out after ~1s */
+                ulong tlapse_ms = get_timer(tstart_ms);
+ if ( tlapse_ms > 1000 /* ms */ ) {
  dev_err(host->dev,
- "wait_transfer_complete - still waiting after %d retries\n",
- timediff);
+ "wait_transfer_complete - still waiting after %lu ms\n",
+ tlapse_ms);
  bcm2835_dumpregs(host);
  return -ETIMEDOUT;
  }


More information about the U-Boot mailing list