]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/mmc/mmc.c
mmc: Restructure polling loops to avoid extra delays
[karo-tx-uboot.git] / drivers / mmc / mmc.c
index 454a1d76c4be5b21f8b9fbca51778aed456a2acb..408f97d51f6ef0db0d307f3840991f0be3723132 100644 (file)
@@ -119,7 +119,7 @@ int mmc_send_status(struct mmc *mmc, int timeout)
        if (!mmc_host_is_spi(mmc))
                cmd.cmdarg = mmc->rca << 16;
 
-       do {
+       while (1) {
                err = mmc_send_cmd(mmc, &cmd, NULL);
                if (!err) {
                        if ((cmd.response[0] & MMC_STATUS_RDY_FOR_DATA) &&
@@ -136,9 +136,11 @@ int mmc_send_status(struct mmc *mmc, int timeout)
                } else if (--retries < 0)
                        return err;
 
-               udelay(1000);
+               if (timeout-- <= 0)
+                       break;
 
-       } while (timeout--);
+               udelay(1000);
+       }
 
 #ifdef CONFIG_MMC_TRACE
        status = (cmd.response[0] & MMC_STATUS_CURR_STATE) >> 9;
@@ -292,7 +294,7 @@ static int sd_send_op_cond(struct mmc *mmc)
        int err;
        struct mmc_cmd cmd;
 
-       do {
+       while (1) {
                cmd.cmdidx = MMC_CMD_APP_CMD;
                cmd.resp_type = MMC_RSP_R1;
                cmd.cmdarg = 0;
@@ -323,10 +325,14 @@ static int sd_send_op_cond(struct mmc *mmc)
                if (err)
                        return err;
 
+               if (cmd.response[0] & OCR_BUSY)
+                       break;
+
+               if (timeout-- <= 0)
+                       return UNUSABLE_ERR;
+
                udelay(1000);
-       } while ((!(cmd.response[0] & OCR_BUSY)) && timeout--);
-       if (!(cmd.response[0] & OCR_BUSY))
-               return UNUSABLE_ERR;
+       }
 
        if (mmc->version != SD_VERSION_2)
                mmc->version = SD_VERSION_1_0;
@@ -405,17 +411,15 @@ static int mmc_complete_op_cond(struct mmc *mmc)
        mmc->op_cond_pending = 0;
        if (!(mmc->ocr & OCR_BUSY)) {
                start = get_timer_masked();
-               do {
+               while (1) {
                        err = mmc_send_op_cond_iter(mmc, 1);
                        if (err)
                                return err;
-                       udelay(100);
-                       if (get_timer(start) > timeout)
+                       if (mmc->ocr & OCR_BUSY)
                                break;
-               } while (!(mmc->ocr & OCR_BUSY));
-               if (!(mmc->ocr & OCR_BUSY)) {
-                       debug("%s: timeout\n", __func__);
-                       return UNUSABLE_ERR;
+                       if (get_timer(start) > timeout)
+                               return UNUSABLE_ERR;
+                       udelay(100);
                }
        }