mmc: core: fix using wrong io voltage if mmc_select_hs200 fails
authorDong Aisheng <aisheng.dong@nxp.com>
Wed, 20 Apr 2016 16:51:30 +0000 (00:51 +0800)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 11 Jan 2020 02:04:44 +0000 (02:04 +0000)
commit e51534c806609c806d81bfb034f02737461f855c upstream.

Currently MMC core will keep going if HS200/HS timing switch failed
with -EBADMSG error by the assumption that the old timing is still valid.

However, for mmc_select_hs200 case, the signal voltage may have already
been switched. If the timing switch failed, we should fall back to
the old voltage in case the card is continue run with legacy timing.

If fall back signal voltage failed, we explicitly report an EIO error
to force retry during the next power cycle.

Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Arnd Bergmann <arnd@arndb.de>
[bwh: Backported to 3.16:
 - Delete now-unused err label
 - Adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/mmc/core/mmc.c

index 96dc3a11e9effa7a4e093163b1497f4932e30923..a5ec5726150d5ae561c6dcc19bccd79ae7a7af00 100644 (file)
@@ -1079,8 +1079,10 @@ static int mmc_select_hs400(struct mmc_card *card)
 static int mmc_select_hs200(struct mmc_card *card)
 {
        struct mmc_host *host = card->host;
+       unsigned int old_signal_voltage;
        int err = -EINVAL;
 
+       old_signal_voltage = host->ios.signal_voltage;
        if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_2V)
                err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120);
 
@@ -1089,7 +1091,7 @@ static int mmc_select_hs200(struct mmc_card *card)
 
        /* If fails try again during next card power cycle */
        if (err)
-               goto err;
+               return err;
 
        /*
         * Set the bus width(4 or 8) with host's support and
@@ -1104,7 +1106,12 @@ static int mmc_select_hs200(struct mmc_card *card)
                if (!err)
                        mmc_set_timing(host, MMC_TIMING_MMC_HS200);
        }
-err:
+
+       if (err) {
+               /* fall back to the old signal voltage, if fails report error */
+               if (__mmc_set_signal_voltage(host, old_signal_voltage))
+                       err = -EIO;
+       }
        return err;
 }