mmc: core: Fix PowerOff Notify suspend/resume
authorGirish K S <girish.shivananjappa@linaro.org>
Tue, 31 Jan 2012 10:14:03 +0000 (15:44 +0530)
committerChris Ball <cjb@laptop.org>
Tue, 14 Feb 2012 01:39:02 +0000 (20:39 -0500)
Modified the mmc_poweroff to resume before sending the poweroff
notification command. In sleep mode only AWAKE and RESET commands are
allowed, so before sending the poweroff notification command resume from
sleep mode and then send the notification command.

PowerOff Notify is tested on a Synopsis Designware Host Controller
(eMMC 4.5). The suspend to RAM and resume works fine.

Signed-off-by: Girish K S <girish.shivananjappa@linaro.org>
Tested-by: Girish K S <girish.shivananjappa@linaro.org>
Reviewed-by: Saugata Das <saugata.das@linaro.org>
Signed-off-by: Chris Ball <cjb@laptop.org>
drivers/mmc/core/core.c
drivers/mmc/core/mmc.c
include/linux/mmc/card.h

index 18661554e79cdc954bb9dd641852394dc341f95d..690255c7d4dcc8c407e7b0852216edab75f4ef31 100644 (file)
@@ -1256,6 +1256,7 @@ static void mmc_poweroff_notify(struct mmc_host *host)
        int err = 0;
 
        card = host->card;
+       mmc_claim_host(host);
 
        /*
         * Send power notify command only if card
@@ -1286,6 +1287,7 @@ static void mmc_poweroff_notify(struct mmc_host *host)
                /* Set the card state to no notification after the poweroff */
                card->poweroff_notify_state = MMC_NO_POWER_NOTIFICATION;
        }
+       mmc_release_host(host);
 }
 
 /*
@@ -1344,12 +1346,28 @@ static void mmc_power_up(struct mmc_host *host)
 
 void mmc_power_off(struct mmc_host *host)
 {
+       int err = 0;
        mmc_host_clk_hold(host);
 
        host->ios.clock = 0;
        host->ios.vdd = 0;
 
-       mmc_poweroff_notify(host);
+       /*
+        * For eMMC 4.5 device send AWAKE command before
+        * POWER_OFF_NOTIFY command, because in sleep state
+        * eMMC 4.5 devices respond to only RESET and AWAKE cmd
+        */
+       if (host->card && mmc_card_is_sleep(host->card) &&
+           host->bus_ops->resume) {
+               err = host->bus_ops->resume(host);
+
+               if (!err)
+                       mmc_poweroff_notify(host);
+               else
+                       pr_warning("%s: error %d during resume "
+                                  "(continue with poweroff sequence)\n",
+                                  mmc_hostname(host), err);
+       }
 
        /*
         * Reset ocr mask to be the highest possible voltage supported for
@@ -2403,12 +2421,6 @@ int mmc_suspend_host(struct mmc_host *host)
                 */
                if (mmc_try_claim_host(host)) {
                        if (host->bus_ops->suspend) {
-                               /*
-                                * For eMMC 4.5 device send notify command
-                                * before sleep, because in sleep state eMMC 4.5
-                                * devices respond to only RESET and AWAKE cmd
-                                */
-                               mmc_poweroff_notify(host);
                                err = host->bus_ops->suspend(host);
                        }
                        mmc_do_release_host(host);
index dd3fcac684a3646c3c1287f3325b43b226c87301..9be031934e33190bc545d9531b2e55bcdd929ba8 100644 (file)
@@ -1316,11 +1316,13 @@ static int mmc_suspend(struct mmc_host *host)
        BUG_ON(!host->card);
 
        mmc_claim_host(host);
-       if (mmc_card_can_sleep(host))
+       if (mmc_card_can_sleep(host)) {
                err = mmc_card_sleep(host);
-       else if (!mmc_host_is_spi(host))
+               if (!err)
+                       mmc_card_set_sleep(host->card);
+       } else if (!mmc_host_is_spi(host))
                mmc_deselect_cards(host);
-       host->card->state &= ~MMC_STATE_HIGHSPEED;
+       host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200);
        mmc_release_host(host);
 
        return err;
@@ -1340,7 +1342,11 @@ static int mmc_resume(struct mmc_host *host)
        BUG_ON(!host->card);
 
        mmc_claim_host(host);
-       err = mmc_init_card(host, host->ocr, host->card);
+       if (mmc_card_is_sleep(host->card)) {
+               err = mmc_card_awake(host);
+               mmc_card_clr_sleep(host->card);
+       } else
+               err = mmc_init_card(host, host->ocr, host->card);
        mmc_release_host(host);
 
        return err;
@@ -1350,7 +1356,8 @@ static int mmc_power_restore(struct mmc_host *host)
 {
        int ret;
 
-       host->card->state &= ~MMC_STATE_HIGHSPEED;
+       host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200);
+       mmc_card_clr_sleep(host->card);
        mmc_claim_host(host);
        ret = mmc_init_card(host, host->ocr, host->card);
        mmc_release_host(host);
index 9f22ba572de0a9a332ec4c2156560b0eac8726cc..19a41d1737afd25cb4462870ae75eea0802a4664 100644 (file)
@@ -217,6 +217,7 @@ struct mmc_card {
 #define MMC_CARD_SDXC          (1<<6)          /* card is SDXC */
 #define MMC_CARD_REMOVED       (1<<7)          /* card has been removed */
 #define MMC_STATE_HIGHSPEED_200        (1<<8)          /* card is in HS200 mode */
+#define MMC_STATE_SLEEP                (1<<9)          /* card is in sleep state */
        unsigned int            quirks;         /* card quirks */
 #define MMC_QUIRK_LENIENT_FN0  (1<<0)          /* allow SDIO FN0 writes outside of the VS CCCR range */
 #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1)   /* use func->cur_blksize */
@@ -382,6 +383,7 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
 #define mmc_sd_card_uhs(c)     ((c)->state & MMC_STATE_ULTRAHIGHSPEED)
 #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC)
 #define mmc_card_removed(c)    ((c) && ((c)->state & MMC_CARD_REMOVED))
+#define mmc_card_is_sleep(c)   ((c)->state & MMC_STATE_SLEEP)
 
 #define mmc_card_set_present(c)        ((c)->state |= MMC_STATE_PRESENT)
 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
@@ -393,7 +395,9 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
 #define mmc_sd_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED)
 #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC)
 #define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED)
+#define mmc_card_set_sleep(c)  ((c)->state |= MMC_STATE_SLEEP)
 
+#define mmc_card_clr_sleep(c)  ((c)->state &= ~MMC_STATE_SLEEP)
 /*
  * Quirk add/remove for MMC products.
  */