All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] ARM: bcm2835: (Raspberry Pi) Fix issue on SD Host driver, where wait_transfer_complete was not waiting long enough
@ 2019-06-11 14:12 Raul Benet
  0 siblings, 0 replies; 2+ messages in thread
From: Raul Benet @ 2019-06-11 14:12 UTC (permalink / raw)
  To: u-boot

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;
  }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH] ARM: bcm2835: (Raspberry Pi) Fix issue on SD Host driver, where wait_transfer_complete was not waiting long enough
@ 2019-06-13 13:59 Raul Benet
  0 siblings, 0 replies; 2+ messages in thread
From: Raul Benet @ 2019-06-13 13:59 UTC (permalink / raw)
  To: u-boot

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;
  }

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-13 13:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-11 14:12 [U-Boot] [PATCH] ARM: bcm2835: (Raspberry Pi) Fix issue on SD Host driver, where wait_transfer_complete was not waiting long enough Raul Benet
2019-06-13 13:59 Raul Benet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.