mmc: Retry the switch command
authorMaxime Ripard <maxime.ripard@free-electrons.com>
Fri, 4 Nov 2016 15:18:08 +0000 (16:18 +0100)
committerJaehoon Chung <jh80.chung@samsung.com>
Wed, 16 Nov 2016 04:30:17 +0000 (13:30 +0900)
Some eMMC will fail at the first switch, but would succeed in a subsequent
one.

Make sure we try several times to cover those cases. The number of retries
(and the behaviour) is currently what is being used in Linux.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
drivers/mmc/mmc.c

index 4380c7c195a628e343f1f0b4719be6b6bbf3fdb3..d6b7e4f510c93c3faadaa6b84646bc7402e68b1b 100644 (file)
@@ -494,6 +494,7 @@ int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value)
 {
        struct mmc_cmd cmd;
        int timeout = 1000;
+       int retries = 3;
        int ret;
 
        cmd.cmdidx = MMC_CMD_SWITCH;
@@ -502,11 +503,17 @@ int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value)
                                 (index << 16) |
                                 (value << 8);
 
-       ret = mmc_send_cmd(mmc, &cmd, NULL);
+       while (retries > 0) {
+               ret = mmc_send_cmd(mmc, &cmd, NULL);
 
-       /* Waiting for the ready status */
-       if (!ret)
-               ret = mmc_send_status(mmc, timeout);
+               /* Waiting for the ready status */
+               if (!ret) {
+                       ret = mmc_send_status(mmc, timeout);
+                       return ret;
+               }
+
+               retries--;
+       }
 
        return ret;