]> git.sur5r.net Git - u-boot/commitdiff
mmc: dw_mmc: Zap endless timeout
authorMarek Vasut <marex@denx.de>
Mon, 27 Jul 2015 20:39:37 +0000 (22:39 +0200)
committerPantelis Antoniou <pantelis.antoniou@konsulko.com>
Tue, 11 Aug 2015 17:44:21 +0000 (20:44 +0300)
Endless timeouts are bad, since if we get stuck in one, we have no
way out. Zap this one by implementing proper timeout.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Dinh Nguyen <dinguyen@opensource.altera.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Tom Rini <trini@konsulko.com>
drivers/mmc/dw_mmc.c

index 3fffa7116647618a1fa3c60b45bb11728941c95c..0f61f163e2d8ee870e9dcf3add8f365c29b8fcdb 100644 (file)
@@ -211,14 +211,29 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
        }
 
        if (data) {
-               do {
+               start = get_timer(0);
+               timeout = 1000;
+               for (;;) {
                        mask = dwmci_readl(host, DWMCI_RINTSTS);
+                       /* Error during data transfer. */
                        if (mask & (DWMCI_DATA_ERR | DWMCI_DATA_TOUT)) {
                                printf("%s: DATA ERROR!\n", __func__);
                                bounce_buffer_stop(&bbstate);
                                return -1;
                        }
-               } while (!(mask & DWMCI_INTMSK_DTO));
+
+                       /* Data arrived correctly. */
+                       if (mask & DWMCI_INTMSK_DTO)
+                               break;
+
+                       /* Check for timeout. */
+                       if (get_timer(start) > timeout) {
+                               printf("%s: Timeout waiting for data!\n",
+                                      __func__);
+                               bounce_buffer_stop(&bbstate);
+                               return TIMEOUT;
+                       }
+               }
 
                dwmci_writel(host, DWMCI_RINTSTS, mask);