]> Pileus Git - ~andy/linux/commitdiff
mmc: core: Prevent violation of specs while initializing cards
authorUlf Hansson <ulf.hansson@linaro.org>
Mon, 16 Sep 2013 09:28:42 +0000 (11:28 +0200)
committerChris Ball <cjb@laptop.org>
Thu, 31 Oct 2013 00:26:30 +0000 (20:26 -0400)
According to eMMC/SD/SDIO specs, the VDD (VCC) voltage level must be
maintained during the initialization sequence. If we want/need to tune
the voltage level, a complete power cycle of the card must be executed.

Most host drivers conforms to the specifications by only allowing to
change VDD voltage level at the MMC_POWER_UP state, but some also cares
about MMC_POWER_ON state, which they should'nt. This patch will not
break those drivers, but they could clean up code to better reflect
what is expected from the protocol layer.

A big re-work of the mmc_select_voltage function is done to only change
VDD voltage level if the host supports MMC_CAP2_FULL_PWR_CYCLE.
Otherwise only validation of the host and card ocr mask will be done.

A very nice side-effect of this patch is that we now don't need to
reset the negotiated ocr mask at the mmc_power_off function, since now
it will actually reflect the present voltage level, which safely can be
used at the next power up and re-initialization. Moreover, we then only
need to execute mmc_select_voltage from the attach sequence.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Chris Ball <cjb@laptop.org>
drivers/mmc/core/core.c
drivers/mmc/core/mmc.c
drivers/mmc/core/sd.c
drivers/mmc/core/sdio.c

index 529d2eff6095daf66938bb6a38a7f549f4656c68..63672aba0e98ec2e4d3174866678fb3713f4c37b 100644 (file)
@@ -1358,21 +1358,20 @@ u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
        int bit;
 
        ocr &= host->ocr_avail;
+       if (!ocr) {
+               dev_warn(mmc_dev(host), "no support for card's volts\n");
+               return 0;
+       }
 
-       bit = ffs(ocr);
-       if (bit) {
-               bit -= 1;
-
+       if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) {
+               bit = ffs(ocr) - 1;
                ocr &= 3 << bit;
-
-               mmc_host_clk_hold(host);
-               host->ios.vdd = bit;
-               mmc_set_ios(host);
-               mmc_host_clk_release(host);
+               mmc_power_cycle(host, ocr);
        } else {
-               pr_warning("%s: host doesn't support card's voltages\n",
-                               mmc_hostname(host));
-               ocr = 0;
+               bit = fls(ocr) - 1;
+               ocr &= 3 << bit;
+               if (bit != host->ios.vdd)
+                       dev_warn(mmc_dev(host), "exceeding card's volts\n");
        }
 
        return ocr;
@@ -1571,14 +1570,6 @@ void mmc_power_off(struct mmc_host *host)
        host->ios.clock = 0;
        host->ios.vdd = 0;
 
-
-       /*
-        * Reset ocr mask to be the highest possible voltage supported for
-        * this card. This value will be used at next power up.
-        */
-       if (host->card)
-               host->card->ocr = 1 << (fls(host->ocr_avail) - 1);
-
        if (!mmc_host_is_spi(host)) {
                host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
                host->ios.chip_select = MMC_CS_DONTCARE;
index eb7161c1158739cee935c8ea404f00bcc70a8f93..18ce81a85c9b8422a150a2bfd9c34c29c0acb9d4 100644 (file)
@@ -1535,7 +1535,6 @@ static int mmc_resume(struct mmc_host *host)
 
        mmc_claim_host(host);
        mmc_power_up(host, host->card->ocr);
-       mmc_select_voltage(host, host->card->ocr);
        err = mmc_init_card(host, host->card->ocr, host->card);
        mmc_release_host(host);
 
index 398065c57edfbfae08fbb73b0d51d407886a731d..53db60a76dae0e03e5465c77255fec8ab23b7d9f 100644 (file)
@@ -1103,7 +1103,6 @@ static int mmc_sd_resume(struct mmc_host *host)
 
        mmc_claim_host(host);
        mmc_power_up(host, host->card->ocr);
-       mmc_select_voltage(host, host->card->ocr);
        err = mmc_sd_init_card(host, host->card->ocr, host->card);
        mmc_release_host(host);
 
index e0a135a635f545690aae7289a026f153e91d712b..b7c19e894dd30cb158c81320a60a872fa82ec1f9 100644 (file)
@@ -987,7 +987,6 @@ static int mmc_sdio_resume(struct mmc_host *host)
        /* Restore power if needed */
        if (!mmc_card_keep_power(host)) {
                mmc_power_up(host, host->card->ocr);
-               mmc_select_voltage(host, host->card->ocr);
                /*
                 * Tell runtime PM core we just powered up the card,
                 * since it still believes the card is powered off.
@@ -1045,7 +1044,6 @@ static int mmc_sdio_resume(struct mmc_host *host)
 static int mmc_sdio_power_restore(struct mmc_host *host)
 {
        int ret;
-       u32 ocr, rocr;
 
        BUG_ON(!host);
        BUG_ON(!host->card);
@@ -1067,28 +1065,17 @@ static int mmc_sdio_power_restore(struct mmc_host *host)
         * for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and
         * harmless in other situations.
         *
-        * With these steps taken, mmc_select_voltage() is also required to
-        * restore the correct voltage setting of the card.
         */
 
        sdio_reset(host);
        mmc_go_idle(host);
        mmc_send_if_cond(host, host->ocr_avail);
 
-       ret = mmc_send_io_op_cond(host, 0, &ocr);
+       ret = mmc_send_io_op_cond(host, 0, NULL);
        if (ret)
                goto out;
 
-       if (host->ocr_avail_sdio)
-               host->ocr_avail = host->ocr_avail_sdio;
-
-       rocr = mmc_select_voltage(host, ocr & ~0x7F);
-       if (!rocr) {
-               ret = -EINVAL;
-               goto out;
-       }
-
-       ret = mmc_sdio_init_card(host, rocr, host->card,
+       ret = mmc_sdio_init_card(host, host->card->ocr, host->card,
                                mmc_card_keep_power(host));
        if (!ret && host->sdio_irqs)
                mmc_signal_sdio_irq(host);