diff options
Diffstat (limited to 'drivers/mmc/core/mmc.c')
-rw-r--r-- | drivers/mmc/core/mmc.c | 203 |
1 files changed, 188 insertions, 15 deletions
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index d240427c124..59b9ba52e66 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c | |||
@@ -286,6 +286,27 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) | |||
286 | } | 286 | } |
287 | card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; | 287 | card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; |
288 | switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) { | 288 | switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) { |
289 | case EXT_CSD_CARD_TYPE_SDR_ALL: | ||
290 | case EXT_CSD_CARD_TYPE_SDR_ALL_DDR_1_8V: | ||
291 | case EXT_CSD_CARD_TYPE_SDR_ALL_DDR_1_2V: | ||
292 | case EXT_CSD_CARD_TYPE_SDR_ALL_DDR_52: | ||
293 | card->ext_csd.hs_max_dtr = 200000000; | ||
294 | card->ext_csd.card_type = EXT_CSD_CARD_TYPE_SDR_200; | ||
295 | break; | ||
296 | case EXT_CSD_CARD_TYPE_SDR_1_2V_ALL: | ||
297 | case EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_1_8V: | ||
298 | case EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_1_2V: | ||
299 | case EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_52: | ||
300 | card->ext_csd.hs_max_dtr = 200000000; | ||
301 | card->ext_csd.card_type = EXT_CSD_CARD_TYPE_SDR_1_2V; | ||
302 | break; | ||
303 | case EXT_CSD_CARD_TYPE_SDR_1_8V_ALL: | ||
304 | case EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_1_8V: | ||
305 | case EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_1_2V: | ||
306 | case EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_52: | ||
307 | card->ext_csd.hs_max_dtr = 200000000; | ||
308 | card->ext_csd.card_type = EXT_CSD_CARD_TYPE_SDR_1_8V; | ||
309 | break; | ||
289 | case EXT_CSD_CARD_TYPE_DDR_52 | EXT_CSD_CARD_TYPE_52 | | 310 | case EXT_CSD_CARD_TYPE_DDR_52 | EXT_CSD_CARD_TYPE_52 | |
290 | EXT_CSD_CARD_TYPE_26: | 311 | EXT_CSD_CARD_TYPE_26: |
291 | card->ext_csd.hs_max_dtr = 52000000; | 312 | card->ext_csd.hs_max_dtr = 52000000; |
@@ -348,7 +369,8 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) | |||
348 | part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17; | 369 | part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17; |
349 | mmc_part_add(card, part_size, | 370 | mmc_part_add(card, part_size, |
350 | EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx, | 371 | EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx, |
351 | "boot%d", idx, true); | 372 | "boot%d", idx, true, |
373 | MMC_BLK_DATA_AREA_BOOT); | ||
352 | } | 374 | } |
353 | } | 375 | } |
354 | } | 376 | } |
@@ -435,7 +457,8 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) | |||
435 | hc_wp_grp_sz); | 457 | hc_wp_grp_sz); |
436 | mmc_part_add(card, part_size << 19, | 458 | mmc_part_add(card, part_size << 19, |
437 | EXT_CSD_PART_CONFIG_ACC_GP0 + idx, | 459 | EXT_CSD_PART_CONFIG_ACC_GP0 + idx, |
438 | "gp%d", idx, false); | 460 | "gp%d", idx, false, |
461 | MMC_BLK_DATA_AREA_GP); | ||
439 | } | 462 | } |
440 | } | 463 | } |
441 | card->ext_csd.sec_trim_mult = | 464 | card->ext_csd.sec_trim_mult = |
@@ -446,6 +469,14 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) | |||
446 | ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; | 469 | ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; |
447 | card->ext_csd.trim_timeout = 300 * | 470 | card->ext_csd.trim_timeout = 300 * |
448 | ext_csd[EXT_CSD_TRIM_MULT]; | 471 | ext_csd[EXT_CSD_TRIM_MULT]; |
472 | |||
473 | /* | ||
474 | * Note that the call to mmc_part_add above defaults to read | ||
475 | * only. If this default assumption is changed, the call must | ||
476 | * take into account the value of boot_locked below. | ||
477 | */ | ||
478 | card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP]; | ||
479 | card->ext_csd.boot_ro_lockable = true; | ||
449 | } | 480 | } |
450 | 481 | ||
451 | if (card->ext_csd.rev >= 5) { | 482 | if (card->ext_csd.rev >= 5) { |
@@ -690,6 +721,79 @@ static int mmc_select_powerclass(struct mmc_card *card, | |||
690 | } | 721 | } |
691 | 722 | ||
692 | /* | 723 | /* |
724 | * Selects the desired buswidth and switch to the HS200 mode | ||
725 | * if bus width set without error | ||
726 | */ | ||
727 | static int mmc_select_hs200(struct mmc_card *card) | ||
728 | { | ||
729 | int idx, err = 0; | ||
730 | struct mmc_host *host; | ||
731 | static unsigned ext_csd_bits[] = { | ||
732 | EXT_CSD_BUS_WIDTH_4, | ||
733 | EXT_CSD_BUS_WIDTH_8, | ||
734 | }; | ||
735 | static unsigned bus_widths[] = { | ||
736 | MMC_BUS_WIDTH_4, | ||
737 | MMC_BUS_WIDTH_8, | ||
738 | }; | ||
739 | |||
740 | BUG_ON(!card); | ||
741 | |||
742 | host = card->host; | ||
743 | |||
744 | if (card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_2V && | ||
745 | host->caps2 & MMC_CAP2_HS200_1_2V_SDR) | ||
746 | if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120, 0)) | ||
747 | err = mmc_set_signal_voltage(host, | ||
748 | MMC_SIGNAL_VOLTAGE_180, 0); | ||
749 | |||
750 | /* If fails try again during next card power cycle */ | ||
751 | if (err) | ||
752 | goto err; | ||
753 | |||
754 | idx = (host->caps & MMC_CAP_8_BIT_DATA) ? 1 : 0; | ||
755 | |||
756 | /* | ||
757 | * Unlike SD, MMC cards dont have a configuration register to notify | ||
758 | * supported bus width. So bus test command should be run to identify | ||
759 | * the supported bus width or compare the ext csd values of current | ||
760 | * bus width and ext csd values of 1 bit mode read earlier. | ||
761 | */ | ||
762 | for (; idx >= 0; idx--) { | ||
763 | |||
764 | /* | ||
765 | * Host is capable of 8bit transfer, then switch | ||
766 | * the device to work in 8bit transfer mode. If the | ||
767 | * mmc switch command returns error then switch to | ||
768 | * 4bit transfer mode. On success set the corresponding | ||
769 | * bus width on the host. | ||
770 | */ | ||
771 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | ||
772 | EXT_CSD_BUS_WIDTH, | ||
773 | ext_csd_bits[idx], | ||
774 | card->ext_csd.generic_cmd6_time); | ||
775 | if (err) | ||
776 | continue; | ||
777 | |||
778 | mmc_set_bus_width(card->host, bus_widths[idx]); | ||
779 | |||
780 | if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST)) | ||
781 | err = mmc_compare_ext_csds(card, bus_widths[idx]); | ||
782 | else | ||
783 | err = mmc_bus_test(card, bus_widths[idx]); | ||
784 | if (!err) | ||
785 | break; | ||
786 | } | ||
787 | |||
788 | /* switch to HS200 mode if bus width set successfully */ | ||
789 | if (!err) | ||
790 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | ||
791 | EXT_CSD_HS_TIMING, 2, 0); | ||
792 | err: | ||
793 | return err; | ||
794 | } | ||
795 | |||
796 | /* | ||
693 | * Handle the detection and initialisation of a card. | 797 | * Handle the detection and initialisation of a card. |
694 | * | 798 | * |
695 | * In the case of a resume, "oldcard" will contain the card | 799 | * In the case of a resume, "oldcard" will contain the card |
@@ -895,11 +999,15 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, | |||
895 | /* | 999 | /* |
896 | * Activate high speed (if supported) | 1000 | * Activate high speed (if supported) |
897 | */ | 1001 | */ |
898 | if ((card->ext_csd.hs_max_dtr != 0) && | 1002 | if (card->ext_csd.hs_max_dtr != 0) { |
899 | (host->caps & MMC_CAP_MMC_HIGHSPEED)) { | 1003 | err = 0; |
900 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 1004 | if (card->ext_csd.hs_max_dtr > 52000000 && |
901 | EXT_CSD_HS_TIMING, 1, | 1005 | host->caps2 & MMC_CAP2_HS200) |
902 | card->ext_csd.generic_cmd6_time); | 1006 | err = mmc_select_hs200(card); |
1007 | else if (host->caps & MMC_CAP_MMC_HIGHSPEED) | ||
1008 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | ||
1009 | EXT_CSD_HS_TIMING, 1, 0); | ||
1010 | |||
903 | if (err && err != -EBADMSG) | 1011 | if (err && err != -EBADMSG) |
904 | goto free_card; | 1012 | goto free_card; |
905 | 1013 | ||
@@ -908,8 +1016,15 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, | |||
908 | mmc_hostname(card->host)); | 1016 | mmc_hostname(card->host)); |
909 | err = 0; | 1017 | err = 0; |
910 | } else { | 1018 | } else { |
911 | mmc_card_set_highspeed(card); | 1019 | if (card->ext_csd.hs_max_dtr > 52000000 && |
912 | mmc_set_timing(card->host, MMC_TIMING_MMC_HS); | 1020 | host->caps2 & MMC_CAP2_HS200) { |
1021 | mmc_card_set_hs200(card); | ||
1022 | mmc_set_timing(card->host, | ||
1023 | MMC_TIMING_MMC_HS200); | ||
1024 | } else { | ||
1025 | mmc_card_set_highspeed(card); | ||
1026 | mmc_set_timing(card->host, MMC_TIMING_MMC_HS); | ||
1027 | } | ||
913 | } | 1028 | } |
914 | } | 1029 | } |
915 | 1030 | ||
@@ -934,7 +1049,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, | |||
934 | */ | 1049 | */ |
935 | max_dtr = (unsigned int)-1; | 1050 | max_dtr = (unsigned int)-1; |
936 | 1051 | ||
937 | if (mmc_card_highspeed(card)) { | 1052 | if (mmc_card_highspeed(card) || mmc_card_hs200(card)) { |
938 | if (max_dtr > card->ext_csd.hs_max_dtr) | 1053 | if (max_dtr > card->ext_csd.hs_max_dtr) |
939 | max_dtr = card->ext_csd.hs_max_dtr; | 1054 | max_dtr = card->ext_csd.hs_max_dtr; |
940 | } else if (max_dtr > card->csd.max_dtr) { | 1055 | } else if (max_dtr > card->csd.max_dtr) { |
@@ -960,9 +1075,48 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, | |||
960 | } | 1075 | } |
961 | 1076 | ||
962 | /* | 1077 | /* |
1078 | * Indicate HS200 SDR mode (if supported). | ||
1079 | */ | ||
1080 | if (mmc_card_hs200(card)) { | ||
1081 | u32 ext_csd_bits; | ||
1082 | u32 bus_width = card->host->ios.bus_width; | ||
1083 | |||
1084 | /* | ||
1085 | * For devices supporting HS200 mode, the bus width has | ||
1086 | * to be set before executing the tuning function. If | ||
1087 | * set before tuning, then device will respond with CRC | ||
1088 | * errors for responses on CMD line. So for HS200 the | ||
1089 | * sequence will be | ||
1090 | * 1. set bus width 4bit / 8 bit (1 bit not supported) | ||
1091 | * 2. switch to HS200 mode | ||
1092 | * 3. set the clock to > 52Mhz <=200MHz and | ||
1093 | * 4. execute tuning for HS200 | ||
1094 | */ | ||
1095 | if ((host->caps2 & MMC_CAP2_HS200) && | ||
1096 | card->host->ops->execute_tuning) | ||
1097 | err = card->host->ops->execute_tuning(card->host, | ||
1098 | MMC_SEND_TUNING_BLOCK_HS200); | ||
1099 | if (err) { | ||
1100 | pr_warning("%s: tuning execution failed\n", | ||
1101 | mmc_hostname(card->host)); | ||
1102 | goto err; | ||
1103 | } | ||
1104 | |||
1105 | ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ? | ||
1106 | EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4; | ||
1107 | err = mmc_select_powerclass(card, ext_csd_bits, ext_csd); | ||
1108 | if (err) { | ||
1109 | pr_err("%s: power class selection to bus width %d failed\n", | ||
1110 | mmc_hostname(card->host), 1 << bus_width); | ||
1111 | goto err; | ||
1112 | } | ||
1113 | } | ||
1114 | |||
1115 | /* | ||
963 | * Activate wide bus and DDR (if supported). | 1116 | * Activate wide bus and DDR (if supported). |
964 | */ | 1117 | */ |
965 | if ((card->csd.mmca_vsn >= CSD_SPEC_VER_4) && | 1118 | if (!mmc_card_hs200(card) && |
1119 | (card->csd.mmca_vsn >= CSD_SPEC_VER_3) && | ||
966 | (host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) { | 1120 | (host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) { |
967 | static unsigned ext_csd_bits[][2] = { | 1121 | static unsigned ext_csd_bits[][2] = { |
968 | { EXT_CSD_BUS_WIDTH_8, EXT_CSD_DDR_BUS_WIDTH_8 }, | 1122 | { EXT_CSD_BUS_WIDTH_8, EXT_CSD_DDR_BUS_WIDTH_8 }, |
@@ -1048,7 +1202,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, | |||
1048 | * | 1202 | * |
1049 | * WARNING: eMMC rules are NOT the same as SD DDR | 1203 | * WARNING: eMMC rules are NOT the same as SD DDR |
1050 | */ | 1204 | */ |
1051 | if (ddr == EXT_CSD_CARD_TYPE_DDR_1_2V) { | 1205 | if (ddr == MMC_1_2V_DDR_MODE) { |
1052 | err = mmc_set_signal_voltage(host, | 1206 | err = mmc_set_signal_voltage(host, |
1053 | MMC_SIGNAL_VOLTAGE_120, 0); | 1207 | MMC_SIGNAL_VOLTAGE_120, 0); |
1054 | if (err) | 1208 | if (err) |
@@ -1067,14 +1221,23 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, | |||
1067 | if ((host->caps2 & MMC_CAP2_CACHE_CTRL) && | 1221 | if ((host->caps2 & MMC_CAP2_CACHE_CTRL) && |
1068 | card->ext_csd.cache_size > 0) { | 1222 | card->ext_csd.cache_size > 0) { |
1069 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 1223 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
1070 | EXT_CSD_CACHE_CTRL, 1, 0); | 1224 | EXT_CSD_CACHE_CTRL, 1, |
1225 | card->ext_csd.generic_cmd6_time); | ||
1071 | if (err && err != -EBADMSG) | 1226 | if (err && err != -EBADMSG) |
1072 | goto free_card; | 1227 | goto free_card; |
1073 | 1228 | ||
1074 | /* | 1229 | /* |
1075 | * Only if no error, cache is turned on successfully. | 1230 | * Only if no error, cache is turned on successfully. |
1076 | */ | 1231 | */ |
1077 | card->ext_csd.cache_ctrl = err ? 0 : 1; | 1232 | if (err) { |
1233 | pr_warning("%s: Cache is supported, " | ||
1234 | "but failed to turn on (%d)\n", | ||
1235 | mmc_hostname(card->host), err); | ||
1236 | card->ext_csd.cache_ctrl = 0; | ||
1237 | err = 0; | ||
1238 | } else { | ||
1239 | card->ext_csd.cache_ctrl = 1; | ||
1240 | } | ||
1078 | } | 1241 | } |
1079 | 1242 | ||
1080 | if (!oldcard) | 1243 | if (!oldcard) |
@@ -1105,6 +1268,14 @@ static void mmc_remove(struct mmc_host *host) | |||
1105 | } | 1268 | } |
1106 | 1269 | ||
1107 | /* | 1270 | /* |
1271 | * Card detection - card is alive. | ||
1272 | */ | ||
1273 | static int mmc_alive(struct mmc_host *host) | ||
1274 | { | ||
1275 | return mmc_send_status(host->card, NULL); | ||
1276 | } | ||
1277 | |||
1278 | /* | ||
1108 | * Card detection callback from host. | 1279 | * Card detection callback from host. |
1109 | */ | 1280 | */ |
1110 | static void mmc_detect(struct mmc_host *host) | 1281 | static void mmc_detect(struct mmc_host *host) |
@@ -1119,7 +1290,7 @@ static void mmc_detect(struct mmc_host *host) | |||
1119 | /* | 1290 | /* |
1120 | * Just check if our card has been removed. | 1291 | * Just check if our card has been removed. |
1121 | */ | 1292 | */ |
1122 | err = mmc_send_status(host->card, NULL); | 1293 | err = _mmc_detect_card_removed(host); |
1123 | 1294 | ||
1124 | mmc_release_host(host); | 1295 | mmc_release_host(host); |
1125 | 1296 | ||
@@ -1224,6 +1395,7 @@ static const struct mmc_bus_ops mmc_ops = { | |||
1224 | .suspend = NULL, | 1395 | .suspend = NULL, |
1225 | .resume = NULL, | 1396 | .resume = NULL, |
1226 | .power_restore = mmc_power_restore, | 1397 | .power_restore = mmc_power_restore, |
1398 | .alive = mmc_alive, | ||
1227 | }; | 1399 | }; |
1228 | 1400 | ||
1229 | static const struct mmc_bus_ops mmc_ops_unsafe = { | 1401 | static const struct mmc_bus_ops mmc_ops_unsafe = { |
@@ -1234,6 +1406,7 @@ static const struct mmc_bus_ops mmc_ops_unsafe = { | |||
1234 | .suspend = mmc_suspend, | 1406 | .suspend = mmc_suspend, |
1235 | .resume = mmc_resume, | 1407 | .resume = mmc_resume, |
1236 | .power_restore = mmc_power_restore, | 1408 | .power_restore = mmc_power_restore, |
1409 | .alive = mmc_alive, | ||
1237 | }; | 1410 | }; |
1238 | 1411 | ||
1239 | static void mmc_attach_bus_ops(struct mmc_host *host) | 1412 | static void mmc_attach_bus_ops(struct mmc_host *host) |