aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/core/debugfs.c2
-rw-r--r--drivers/mmc/core/mmc.c431
2 files changed, 233 insertions, 200 deletions
diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
index 509229b48b55..1f730dbfaeea 100644
--- a/drivers/mmc/core/debugfs.c
+++ b/drivers/mmc/core/debugfs.c
@@ -139,7 +139,7 @@ static int mmc_ios_show(struct seq_file *s, void *data)
139 str = "mmc DDR52"; 139 str = "mmc DDR52";
140 break; 140 break;
141 case MMC_TIMING_MMC_HS200: 141 case MMC_TIMING_MMC_HS200:
142 str = "mmc high-speed SDR200"; 142 str = "mmc HS200";
143 break; 143 break;
144 default: 144 default:
145 str = "invalid"; 145 str = "invalid";
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 4538541ac5ab..bec6786efd19 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -242,7 +242,7 @@ static void mmc_select_card_type(struct mmc_card *card)
242 struct mmc_host *host = card->host; 242 struct mmc_host *host = card->host;
243 u8 card_type = card->ext_csd.raw_card_type & EXT_CSD_CARD_TYPE_MASK; 243 u8 card_type = card->ext_csd.raw_card_type & EXT_CSD_CARD_TYPE_MASK;
244 u32 caps = host->caps, caps2 = host->caps2; 244 u32 caps = host->caps, caps2 = host->caps2;
245 unsigned int hs_max_dtr = 0; 245 unsigned int hs_max_dtr = 0, hs200_max_dtr = 0;
246 unsigned int avail_type = 0; 246 unsigned int avail_type = 0;
247 247
248 if (caps & MMC_CAP_MMC_HIGHSPEED && 248 if (caps & MMC_CAP_MMC_HIGHSPEED &&
@@ -271,17 +271,18 @@ static void mmc_select_card_type(struct mmc_card *card)
271 271
272 if (caps2 & MMC_CAP2_HS200_1_8V_SDR && 272 if (caps2 & MMC_CAP2_HS200_1_8V_SDR &&
273 card_type & EXT_CSD_CARD_TYPE_HS200_1_8V) { 273 card_type & EXT_CSD_CARD_TYPE_HS200_1_8V) {
274 hs_max_dtr = MMC_HS200_MAX_DTR; 274 hs200_max_dtr = MMC_HS200_MAX_DTR;
275 avail_type |= EXT_CSD_CARD_TYPE_HS200_1_8V; 275 avail_type |= EXT_CSD_CARD_TYPE_HS200_1_8V;
276 } 276 }
277 277
278 if (caps2 & MMC_CAP2_HS200_1_2V_SDR && 278 if (caps2 & MMC_CAP2_HS200_1_2V_SDR &&
279 card_type & EXT_CSD_CARD_TYPE_HS200_1_2V) { 279 card_type & EXT_CSD_CARD_TYPE_HS200_1_2V) {
280 hs_max_dtr = MMC_HS200_MAX_DTR; 280 hs200_max_dtr = MMC_HS200_MAX_DTR;
281 avail_type |= EXT_CSD_CARD_TYPE_HS200_1_2V; 281 avail_type |= EXT_CSD_CARD_TYPE_HS200_1_2V;
282 } 282 }
283 283
284 card->ext_csd.hs_max_dtr = hs_max_dtr; 284 card->ext_csd.hs_max_dtr = hs_max_dtr;
285 card->ext_csd.hs200_max_dtr = hs200_max_dtr;
285 card->mmc_avail_type = avail_type; 286 card->mmc_avail_type = avail_type;
286} 287}
287 288
@@ -825,37 +826,46 @@ static int mmc_select_powerclass(struct mmc_card *card)
825} 826}
826 827
827/* 828/*
828 * Selects the desired buswidth and switch to the HS200 mode 829 * Set the bus speed for the selected speed mode.
829 * if bus width set without error
830 */ 830 */
831static int mmc_select_hs200(struct mmc_card *card) 831static void mmc_set_bus_speed(struct mmc_card *card)
832{
833 unsigned int max_dtr = (unsigned int)-1;
834
835 if (mmc_card_hs200(card) && max_dtr > card->ext_csd.hs200_max_dtr)
836 max_dtr = card->ext_csd.hs200_max_dtr;
837 else if (mmc_card_hs(card) && max_dtr > card->ext_csd.hs_max_dtr)
838 max_dtr = card->ext_csd.hs_max_dtr;
839 else if (max_dtr > card->csd.max_dtr)
840 max_dtr = card->csd.max_dtr;
841
842 mmc_set_clock(card->host, max_dtr);
843}
844
845/*
846 * Select the bus width amoung 4-bit and 8-bit(SDR).
847 * If the bus width is changed successfully, return the selected width value.
848 * Zero is returned instead of error value if the wide width is not supported.
849 */
850static int mmc_select_bus_width(struct mmc_card *card)
832{ 851{
833 int idx, err = -EINVAL;
834 struct mmc_host *host;
835 static unsigned ext_csd_bits[] = { 852 static unsigned ext_csd_bits[] = {
836 EXT_CSD_BUS_WIDTH_4,
837 EXT_CSD_BUS_WIDTH_8, 853 EXT_CSD_BUS_WIDTH_8,
854 EXT_CSD_BUS_WIDTH_4,
838 }; 855 };
839 static unsigned bus_widths[] = { 856 static unsigned bus_widths[] = {
840 MMC_BUS_WIDTH_4,
841 MMC_BUS_WIDTH_8, 857 MMC_BUS_WIDTH_8,
858 MMC_BUS_WIDTH_4,
842 }; 859 };
860 struct mmc_host *host = card->host;
861 unsigned idx, bus_width = 0;
862 int err = 0;
843 863
844 BUG_ON(!card); 864 if ((card->csd.mmca_vsn < CSD_SPEC_VER_4) &&
845 865 !(host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)))
846 host = card->host; 866 return 0;
847
848 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_2V)
849 err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120);
850
851 if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_8V)
852 err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180);
853
854 /* If fails try again during next card power cycle */
855 if (err)
856 goto err;
857 867
858 idx = (host->caps & MMC_CAP_8_BIT_DATA) ? 1 : 0; 868 idx = (host->caps & MMC_CAP_8_BIT_DATA) ? 0 : 1;
859 869
860 /* 870 /*
861 * Unlike SD, MMC cards dont have a configuration register to notify 871 * Unlike SD, MMC cards dont have a configuration register to notify
@@ -863,8 +873,7 @@ static int mmc_select_hs200(struct mmc_card *card)
863 * the supported bus width or compare the ext csd values of current 873 * the supported bus width or compare the ext csd values of current
864 * bus width and ext csd values of 1 bit mode read earlier. 874 * bus width and ext csd values of 1 bit mode read earlier.
865 */ 875 */
866 for (; idx >= 0; idx--) { 876 for (; idx < ARRAY_SIZE(bus_widths); idx++) {
867
868 /* 877 /*
869 * Host is capable of 8bit transfer, then switch 878 * Host is capable of 8bit transfer, then switch
870 * the device to work in 8bit transfer mode. If the 879 * the device to work in 8bit transfer mode. If the
@@ -879,27 +888,202 @@ static int mmc_select_hs200(struct mmc_card *card)
879 if (err) 888 if (err)
880 continue; 889 continue;
881 890
882 mmc_set_bus_width(card->host, bus_widths[idx]); 891 bus_width = bus_widths[idx];
892 mmc_set_bus_width(host, bus_width);
883 893
894 /*
895 * If controller can't handle bus width test,
896 * compare ext_csd previously read in 1 bit mode
897 * against ext_csd at new bus width
898 */
884 if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST)) 899 if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST))
885 err = mmc_compare_ext_csds(card, bus_widths[idx]); 900 err = mmc_compare_ext_csds(card, bus_width);
886 else 901 else
887 err = mmc_bus_test(card, bus_widths[idx]); 902 err = mmc_bus_test(card, bus_width);
888 if (!err) 903
904 if (!err) {
905 err = bus_width;
889 break; 906 break;
907 } else {
908 pr_warn("%s: switch to bus width %d failed\n",
909 mmc_hostname(host), ext_csd_bits[idx]);
910 }
890 } 911 }
891 912
892 /* switch to HS200 mode if bus width set successfully */ 913 return err;
914}
915
916/*
917 * Switch to the high-speed mode
918 */
919static int mmc_select_hs(struct mmc_card *card)
920{
921 int err;
922
923 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
924 EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS,
925 card->ext_csd.generic_cmd6_time,
926 true, true, true);
893 if (!err) 927 if (!err)
928 mmc_set_timing(card->host, MMC_TIMING_MMC_HS);
929
930 return err;
931}
932
933/*
934 * Activate wide bus and DDR if supported.
935 */
936static int mmc_select_hs_ddr(struct mmc_card *card)
937{
938 struct mmc_host *host = card->host;
939 u32 bus_width, ext_csd_bits;
940 int err = 0;
941
942 if (!(card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_52))
943 return 0;
944
945 bus_width = host->ios.bus_width;
946 if (bus_width == MMC_BUS_WIDTH_1)
947 return 0;
948
949 ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ?
950 EXT_CSD_DDR_BUS_WIDTH_8 : EXT_CSD_DDR_BUS_WIDTH_4;
951
952 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
953 EXT_CSD_BUS_WIDTH,
954 ext_csd_bits,
955 card->ext_csd.generic_cmd6_time);
956 if (err) {
957 pr_warn("%s: switch to bus width %d ddr failed\n",
958 mmc_hostname(host), 1 << bus_width);
959 return err;
960 }
961
962 /*
963 * eMMC cards can support 3.3V to 1.2V i/o (vccq)
964 * signaling.
965 *
966 * EXT_CSD_CARD_TYPE_DDR_1_8V means 3.3V or 1.8V vccq.
967 *
968 * 1.8V vccq at 3.3V core voltage (vcc) is not required
969 * in the JEDEC spec for DDR.
970 *
971 * Do not force change in vccq since we are obviously
972 * working and no change to vccq is needed.
973 *
974 * WARNING: eMMC rules are NOT the same as SD DDR
975 */
976 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_1_2V) {
977 err = __mmc_set_signal_voltage(host,
978 MMC_SIGNAL_VOLTAGE_120);
979 if (err)
980 return err;
981 }
982
983 mmc_set_timing(host, MMC_TIMING_MMC_DDR52);
984
985 return err;
986}
987
988/*
989 * For device supporting HS200 mode, the following sequence
990 * should be done before executing the tuning process.
991 * 1. set the desired bus width(4-bit or 8-bit, 1-bit is not supported)
992 * 2. switch to HS200 mode
993 * 3. set the clock to > 52Mhz and <=200MHz
994 */
995static int mmc_select_hs200(struct mmc_card *card)
996{
997 struct mmc_host *host = card->host;
998 int err = -EINVAL;
999
1000 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_2V)
1001 err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120);
1002
1003 if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_8V)
1004 err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180);
1005
1006 /* If fails try again during next card power cycle */
1007 if (err)
1008 goto err;
1009
1010 /*
1011 * Set the bus width(4 or 8) with host's support and
1012 * switch to HS200 mode if bus width is set successfully.
1013 */
1014 err = mmc_select_bus_width(card);
1015 if (!IS_ERR_VALUE(err)) {
894 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1016 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
895 EXT_CSD_HS_TIMING, 2, 1017 EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS200,
896 card->ext_csd.generic_cmd6_time, 1018 card->ext_csd.generic_cmd6_time,
897 true, true, true); 1019 true, true, true);
1020 if (!err)
1021 mmc_set_timing(host, MMC_TIMING_MMC_HS200);
1022 }
898err: 1023err:
899 return err; 1024 return err;
900} 1025}
901 1026
902/* 1027/*
1028 * Activate High Speed or HS200 mode if supported.
1029 */
1030static int mmc_select_timing(struct mmc_card *card)
1031{
1032 int err = 0;
1033
1034 if ((card->csd.mmca_vsn < CSD_SPEC_VER_4 &&
1035 card->ext_csd.hs_max_dtr == 0))
1036 goto bus_speed;
1037
1038 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200)
1039 err = mmc_select_hs200(card);
1040 else if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS)
1041 err = mmc_select_hs(card);
1042
1043 if (err && err != -EBADMSG)
1044 return err;
1045
1046 if (err) {
1047 pr_warn("%s: switch to %s failed\n",
1048 mmc_card_hs(card) ? "high-speed" :
1049 (mmc_card_hs200(card) ? "hs200" : ""),
1050 mmc_hostname(card->host));
1051 err = 0;
1052 }
1053
1054bus_speed:
1055 /*
1056 * Set the bus speed to the selected bus timing.
1057 * If timing is not selected, backward compatible is the default.
1058 */
1059 mmc_set_bus_speed(card);
1060 return err;
1061}
1062
1063/*
1064 * Execute tuning sequence to seek the proper bus operating
1065 * conditions for HS200, which sends CMD21 to the device.
1066 */
1067static int mmc_hs200_tuning(struct mmc_card *card)
1068{
1069 struct mmc_host *host = card->host;
1070 int err = 0;
1071
1072 if (host->ops->execute_tuning) {
1073 mmc_host_clk_hold(host);
1074 err = host->ops->execute_tuning(host,
1075 MMC_SEND_TUNING_BLOCK_HS200);
1076 mmc_host_clk_release(host);
1077
1078 if (err)
1079 pr_warn("%s: tuning execution failed\n",
1080 mmc_hostname(host));
1081 }
1082
1083 return err;
1084}
1085
1086/*
903 * Handle the detection and initialisation of a card. 1087 * Handle the detection and initialisation of a card.
904 * 1088 *
905 * In the case of a resume, "oldcard" will contain the card 1089 * In the case of a resume, "oldcard" will contain the card
@@ -909,9 +1093,8 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
909 struct mmc_card *oldcard) 1093 struct mmc_card *oldcard)
910{ 1094{
911 struct mmc_card *card; 1095 struct mmc_card *card;
912 int err, ddr = 0; 1096 int err;
913 u32 cid[4]; 1097 u32 cid[4];
914 unsigned int max_dtr;
915 u32 rocr; 1098 u32 rocr;
916 u8 *ext_csd = NULL; 1099 u8 *ext_csd = NULL;
917 1100
@@ -1103,173 +1286,23 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1103 } 1286 }
1104 1287
1105 /* 1288 /*
1106 * Activate high speed (if supported) 1289 * Select timing interface
1107 */
1108 if (card->ext_csd.hs_max_dtr != 0) {
1109 err = 0;
1110 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200)
1111 err = mmc_select_hs200(card);
1112 else if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS)
1113 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1114 EXT_CSD_HS_TIMING, 1,
1115 card->ext_csd.generic_cmd6_time,
1116 true, true, true);
1117
1118 if (err && err != -EBADMSG)
1119 goto free_card;
1120
1121 if (err) {
1122 pr_warning("%s: switch to highspeed failed\n",
1123 mmc_hostname(card->host));
1124 err = 0;
1125 } else {
1126 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200)
1127 mmc_set_timing(card->host,
1128 MMC_TIMING_MMC_HS200);
1129 else
1130 mmc_set_timing(card->host, MMC_TIMING_MMC_HS);
1131 }
1132 }
1133
1134 /*
1135 * Compute bus speed.
1136 */
1137 max_dtr = (unsigned int)-1;
1138
1139 if (mmc_card_hs(card) || mmc_card_hs200(card)) {
1140 if (max_dtr > card->ext_csd.hs_max_dtr)
1141 max_dtr = card->ext_csd.hs_max_dtr;
1142 if (mmc_card_hs(card) && (max_dtr > 52000000))
1143 max_dtr = 52000000;
1144 } else if (max_dtr > card->csd.max_dtr) {
1145 max_dtr = card->csd.max_dtr;
1146 }
1147
1148 mmc_set_clock(host, max_dtr);
1149
1150 /*
1151 * Indicate DDR mode (if supported).
1152 */ 1290 */
1153 if (mmc_card_hs(card)) 1291 err = mmc_select_timing(card);
1154 ddr = card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_52; 1292 if (err)
1293 goto free_card;
1155 1294
1156 /*
1157 * Indicate HS200 SDR mode (if supported).
1158 */
1159 if (mmc_card_hs200(card)) { 1295 if (mmc_card_hs200(card)) {
1160 u32 ext_csd_bits; 1296 err = mmc_hs200_tuning(card);
1161 u32 bus_width = card->host->ios.bus_width; 1297 if (err)
1162
1163 /*
1164 * For devices supporting HS200 mode, the bus width has
1165 * to be set before executing the tuning function. If
1166 * set before tuning, then device will respond with CRC
1167 * errors for responses on CMD line. So for HS200 the
1168 * sequence will be
1169 * 1. set bus width 4bit / 8 bit (1 bit not supported)
1170 * 2. switch to HS200 mode
1171 * 3. set the clock to > 52Mhz <=200MHz and
1172 * 4. execute tuning for HS200
1173 */
1174 if (card->host->ops->execute_tuning) {
1175 mmc_host_clk_hold(card->host);
1176 err = card->host->ops->execute_tuning(card->host,
1177 MMC_SEND_TUNING_BLOCK_HS200);
1178 mmc_host_clk_release(card->host);
1179 }
1180 if (err) {
1181 pr_warning("%s: tuning execution failed\n",
1182 mmc_hostname(card->host));
1183 goto err; 1298 goto err;
1184 } 1299 } else if (mmc_card_hs(card)) {
1185 1300 /* Select the desired bus width optionally */
1186 ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ? 1301 err = mmc_select_bus_width(card);
1187 EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4; 1302 if (!IS_ERR_VALUE(err)) {
1188 } 1303 err = mmc_select_hs_ddr(card);
1189 1304 if (err)
1190 /* 1305 goto err;
1191 * Activate wide bus and DDR (if supported).
1192 */
1193 if (!mmc_card_hs200(card) &&
1194 (card->csd.mmca_vsn >= CSD_SPEC_VER_4) &&
1195 (host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) {
1196 static unsigned ext_csd_bits[][2] = {
1197 { EXT_CSD_BUS_WIDTH_8, EXT_CSD_DDR_BUS_WIDTH_8 },
1198 { EXT_CSD_BUS_WIDTH_4, EXT_CSD_DDR_BUS_WIDTH_4 },
1199 { EXT_CSD_BUS_WIDTH_1, EXT_CSD_BUS_WIDTH_1 },
1200 };
1201 static unsigned bus_widths[] = {
1202 MMC_BUS_WIDTH_8,
1203 MMC_BUS_WIDTH_4,
1204 MMC_BUS_WIDTH_1
1205 };
1206 unsigned idx, bus_width = 0;
1207
1208 if (host->caps & MMC_CAP_8_BIT_DATA)
1209 idx = 0;
1210 else
1211 idx = 1;
1212 for (; idx < ARRAY_SIZE(bus_widths); idx++) {
1213 bus_width = bus_widths[idx];
1214 if (bus_width == MMC_BUS_WIDTH_1)
1215 ddr = 0; /* no DDR for 1-bit width */
1216
1217 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1218 EXT_CSD_BUS_WIDTH,
1219 ext_csd_bits[idx][0],
1220 card->ext_csd.generic_cmd6_time);
1221 if (!err) {
1222 mmc_set_bus_width(card->host, bus_width);
1223
1224 /*
1225 * If controller can't handle bus width test,
1226 * compare ext_csd previously read in 1 bit mode
1227 * against ext_csd at new bus width
1228 */
1229 if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST))
1230 err = mmc_compare_ext_csds(card,
1231 bus_width);
1232 else
1233 err = mmc_bus_test(card, bus_width);
1234 if (!err)
1235 break;
1236 }
1237 }
1238
1239 if (!err && ddr) {
1240 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1241 EXT_CSD_BUS_WIDTH,
1242 ext_csd_bits[idx][1],
1243 card->ext_csd.generic_cmd6_time);
1244 }
1245 if (err) {
1246 pr_warning("%s: switch to bus width %d ddr %d "
1247 "failed\n", mmc_hostname(card->host),
1248 1 << bus_width, ddr);
1249 goto free_card;
1250 } else if (ddr) {
1251 /*
1252 * eMMC cards can support 3.3V to 1.2V i/o (vccq)
1253 * signaling.
1254 *
1255 * EXT_CSD_CARD_TYPE_DDR_1_8V means 3.3V or 1.8V vccq.
1256 *
1257 * 1.8V vccq at 3.3V core voltage (vcc) is not required
1258 * in the JEDEC spec for DDR.
1259 *
1260 * Do not force change in vccq since we are obviously
1261 * working and no change to vccq is needed.
1262 *
1263 * WARNING: eMMC rules are NOT the same as SD DDR
1264 */
1265 if (ddr & EXT_CSD_CARD_TYPE_DDR_1_2V) {
1266 err = __mmc_set_signal_voltage(host,
1267 MMC_SIGNAL_VOLTAGE_120);
1268 if (err)
1269 goto err;
1270 }
1271 mmc_set_timing(card->host, MMC_TIMING_MMC_DDR52);
1272 mmc_set_bus_width(card->host, bus_width);
1273 } 1306 }
1274 } 1307 }
1275 1308