[U-Boot] mmc: dw_mmc: fix timeout calculate method
diff mbox series

Message ID 20190814083819.5784-1-kever.yang@rock-chips.com
State New
Delegated to: Peng Fan
Headers show
Series
  • [U-Boot] mmc: dw_mmc: fix timeout calculate method
Related show

Commit Message

Kever Yang Aug. 14, 2019, 8:38 a.m. UTC
There are two cases not been considered:
- use uint for timeout, it will overflow when size bigger than 512KB for
  it *8*1000 at the beginning, but we may use size up to 32MB;
- The timeout is using clock speed for data rate, but the device may not
  have such high speed, eg. clock is 52MHz while the device write speed may
  be less than 10MB/s.

Fix them in this patch, the max timeout is about 6500 when size is 32MB
after fix.

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
---

 drivers/mmc/dw_mmc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Patch
diff mbox series

diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c
index 22f6c7eefd..2cb61ba184 100644
--- a/drivers/mmc/dw_mmc.c
+++ b/drivers/mmc/dw_mmc.c
@@ -117,10 +117,10 @@  static int dwmci_fifo_ready(struct dwmci_host *host, u32 bit, u32 *len)
 
 static unsigned int dwmci_get_timeout(struct mmc *mmc, const unsigned int size)
 {
-	unsigned int timeout;
+	u64 timeout;
 
-	timeout = size * 8 * 1000;	/* counting in bits and msec */
-	timeout *= 2;			/* wait twice as long */
+	timeout = (u64)size * 8 * 1000;	/* counting in bits and msec */
+	timeout *= 10;			/* wait 10 times as long */
 	timeout /= mmc->clock;
 	timeout /= mmc->bus_width;
 	timeout /= mmc->ddr_mode ? 2 : 1;