Skip to content

Commit cc4f414

Browse files
ahunter6storulf
authored andcommitted
mmc: mmc: Add driver strength selection
Add the ability to set eMMC driver strength for HS200 and HS400. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent b097e07 commit cc4f414

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

drivers/mmc/core/mmc.c

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,7 @@ static int mmc_select_hs400(struct mmc_card *card)
10441044
{
10451045
struct mmc_host *host = card->host;
10461046
int err = 0;
1047+
u8 val;
10471048

10481049
/*
10491050
* HS400 mode requires 8-bit bus width
@@ -1059,8 +1060,10 @@ static int mmc_select_hs400(struct mmc_card *card)
10591060
mmc_set_timing(card->host, MMC_TIMING_MMC_HS);
10601061
mmc_set_bus_speed(card);
10611062

1063+
val = EXT_CSD_TIMING_HS |
1064+
card->drive_strength << EXT_CSD_DRV_STR_SHIFT;
10621065
err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1063-
EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS,
1066+
EXT_CSD_HS_TIMING, val,
10641067
card->ext_csd.generic_cmd6_time,
10651068
true, true, true);
10661069
if (err) {
@@ -1079,8 +1082,10 @@ static int mmc_select_hs400(struct mmc_card *card)
10791082
return err;
10801083
}
10811084

1085+
val = EXT_CSD_TIMING_HS400 |
1086+
card->drive_strength << EXT_CSD_DRV_STR_SHIFT;
10821087
err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1083-
EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS400,
1088+
EXT_CSD_HS_TIMING, val,
10841089
card->ext_csd.generic_cmd6_time,
10851090
true, true, true);
10861091
if (err) {
@@ -1119,6 +1124,7 @@ int mmc_hs400_to_hs200(struct mmc_card *card)
11191124
bool send_status = true;
11201125
unsigned int max_dtr;
11211126
int err;
1127+
u8 val;
11221128

11231129
if (host->caps & MMC_CAP_WAIT_WHILE_BUSY)
11241130
send_status = false;
@@ -1128,8 +1134,10 @@ int mmc_hs400_to_hs200(struct mmc_card *card)
11281134
mmc_set_clock(host, max_dtr);
11291135

11301136
/* Switch HS400 to HS DDR */
1137+
val = EXT_CSD_TIMING_HS |
1138+
card->drive_strength << EXT_CSD_DRV_STR_SHIFT;
11311139
err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING,
1132-
EXT_CSD_TIMING_HS, card->ext_csd.generic_cmd6_time,
1140+
val, card->ext_csd.generic_cmd6_time,
11331141
true, send_status, true);
11341142
if (err)
11351143
goto out_err;
@@ -1158,10 +1166,11 @@ int mmc_hs400_to_hs200(struct mmc_card *card)
11581166
}
11591167

11601168
/* Switch HS to HS200 */
1169+
val = EXT_CSD_TIMING_HS200 |
1170+
card->drive_strength << EXT_CSD_DRV_STR_SHIFT;
11611171
err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING,
1162-
EXT_CSD_TIMING_HS200,
1163-
card->ext_csd.generic_cmd6_time, true, send_status,
1164-
true);
1172+
val, card->ext_csd.generic_cmd6_time, true,
1173+
send_status, true);
11651174
if (err)
11661175
goto out_err;
11671176

@@ -1183,6 +1192,23 @@ int mmc_hs400_to_hs200(struct mmc_card *card)
11831192
return err;
11841193
}
11851194

1195+
static void mmc_select_driver_type(struct mmc_card *card)
1196+
{
1197+
int card_drv_type, drive_strength, drv_type;
1198+
1199+
card_drv_type = card->ext_csd.raw_driver_strength |
1200+
mmc_driver_type_mask(0);
1201+
1202+
drive_strength = mmc_select_drive_strength(card,
1203+
card->ext_csd.hs200_max_dtr,
1204+
card_drv_type, &drv_type);
1205+
1206+
card->drive_strength = drive_strength;
1207+
1208+
if (drv_type)
1209+
mmc_set_driver_type(card->host, drv_type);
1210+
}
1211+
11861212
/*
11871213
* For device supporting HS200 mode, the following sequence
11881214
* should be done before executing the tuning process.
@@ -1194,6 +1220,7 @@ static int mmc_select_hs200(struct mmc_card *card)
11941220
{
11951221
struct mmc_host *host = card->host;
11961222
int err = -EINVAL;
1223+
u8 val;
11971224

11981225
if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_2V)
11991226
err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120);
@@ -1205,14 +1232,18 @@ static int mmc_select_hs200(struct mmc_card *card)
12051232
if (err)
12061233
goto err;
12071234

1235+
mmc_select_driver_type(card);
1236+
12081237
/*
12091238
* Set the bus width(4 or 8) with host's support and
12101239
* switch to HS200 mode if bus width is set successfully.
12111240
*/
12121241
err = mmc_select_bus_width(card);
12131242
if (!IS_ERR_VALUE(err)) {
1243+
val = EXT_CSD_TIMING_HS200 |
1244+
card->drive_strength << EXT_CSD_DRV_STR_SHIFT;
12141245
err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1215-
EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS200,
1246+
EXT_CSD_HS_TIMING, val,
12161247
card->ext_csd.generic_cmd6_time,
12171248
true, true, true);
12181249
if (!err)

include/linux/mmc/mmc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ struct _mmc_csd {
391391
#define EXT_CSD_TIMING_HS 1 /* High speed */
392392
#define EXT_CSD_TIMING_HS200 2 /* HS200 */
393393
#define EXT_CSD_TIMING_HS400 3 /* HS400 */
394+
#define EXT_CSD_DRV_STR_SHIFT 4 /* Driver Strength shift */
394395

395396
#define EXT_CSD_SEC_ER_EN BIT(0)
396397
#define EXT_CSD_SEC_BD_BLK_EN BIT(2)
@@ -442,4 +443,6 @@ struct _mmc_csd {
442443
#define MMC_SWITCH_MODE_CLEAR_BITS 0x02 /* Clear bits which are 1 in value */
443444
#define MMC_SWITCH_MODE_WRITE_BYTE 0x03 /* Set target to value */
444445

446+
#define mmc_driver_type_mask(n) (1 << (n))
447+
445448
#endif /* LINUX_MMC_MMC_H */

0 commit comments

Comments
 (0)