mmc: mmc: Fix partition switch timeout for some eMMCs
[pandora-kernel.git] / drivers / mmc / core / mmc.c
index dbf421a..408000d 100644 (file)
@@ -235,6 +235,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd)
        return err;
 }
 
+/* Minimum partition switch timeout in milliseconds */
+#define MMC_MIN_PART_SWITCH_TIME       300
+
 /*
  * Decode extended CSD.
  */
@@ -325,6 +328,10 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
 
                /* EXT_CSD value is in units of 10ms, but we store in ms */
                card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME];
+               /* Some eMMC set the value too low so set a minimum */
+               if (card->ext_csd.part_time &&
+                   card->ext_csd.part_time < MMC_MIN_PART_SWITCH_TIME)
+                       card->ext_csd.part_time = MMC_MIN_PART_SWITCH_TIME;
 
                /* Sleep / awake timeout in 100ns units */
                if (sa_shift > 0 && sa_shift <= 0x17)
@@ -363,13 +370,13 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
                ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT];
        card->ext_csd.raw_trim_mult =
                ext_csd[EXT_CSD_TRIM_MULT];
+       card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT];
        if (card->ext_csd.rev >= 4) {
                /*
                 * Enhanced area feature support -- check whether the eMMC
                 * card has the Enhanced area enabled.  If so, export enhanced
                 * area offset and size to user by adding sysfs interface.
                 */
-               card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT];
                if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) &&
                    (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) {
                        hc_erase_grp_sz =
@@ -876,17 +883,21 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
         * set the notification byte in the ext_csd register of device
         */
        if ((host->caps2 & MMC_CAP2_POWEROFF_NOTIFY) &&
-           (card->poweroff_notify_state == MMC_NO_POWER_NOTIFICATION)) {
+           (card->ext_csd.rev >= 6)) {
                err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
                                 EXT_CSD_POWER_OFF_NOTIFICATION,
                                 EXT_CSD_POWER_ON,
                                 card->ext_csd.generic_cmd6_time);
                if (err && err != -EBADMSG)
                        goto free_card;
-       }
 
-       if (!err)
-               card->poweroff_notify_state = MMC_POWERED_ON;
+               /*
+                * The err can be -EBADMSG or 0,
+                * so check for success and update the flag
+                */
+               if (!err)
+                       card->poweroff_notify_state = MMC_POWERED_ON;
+       }
 
        /*
         * Activate high speed (if supported)
@@ -1044,7 +1055,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
                         *
                         * WARNING: eMMC rules are NOT the same as SD DDR
                         */
-                       if (ddr == EXT_CSD_CARD_TYPE_DDR_1_2V) {
+                       if (ddr == MMC_1_2V_DDR_MODE) {
                                err = mmc_set_signal_voltage(host,
                                        MMC_SIGNAL_VOLTAGE_120, 0);
                                if (err)