Skip to content

Commit a4924c7

Browse files
girishkscjb
authored andcommitted
mmc: core: HS200 mode support for eMMC 4.5
This patch adds the support of the HS200 bus speed for eMMC 4.5 devices. The eMMC 4.5 devices have support for 200MHz bus speed. The function prototype of the tuning function is modified to handle the tuning command number which is different in sd and mmc case. Signed-off-by: Girish K S <girish.shivananjappa@linaro.org> Signed-off-by: Philip Rakity <prakity@marvell.com> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent ee5d19b commit a4924c7

8 files changed

Lines changed: 241 additions & 14 deletions

File tree

‎drivers/mmc/core/bus.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,11 @@ int mmc_add_card(struct mmc_card *card)
303303
mmc_card_ddr_mode(card) ? "DDR " : "",
304304
type);
305305
} else {
306-
printk(KERN_INFO "%s: new %s%s%s card at address %04x\n",
306+
pr_info("%s: new %s%s%s%s card at address %04x\n",
307307
mmc_hostname(card->host),
308308
mmc_card_uhs(card) ? "ultra high speed " :
309309
(mmc_card_highspeed(card) ? "high speed " : ""),
310+
(mmc_card_hs200(card) ? "HS200 " : ""),
310311
mmc_card_ddr_mode(card) ? "DDR " : "",
311312
type, card->rca);
312313
}

‎drivers/mmc/core/debugfs.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ static int mmc_ios_show(struct seq_file *s, void *data)
135135
case MMC_TIMING_UHS_DDR50:
136136
str = "sd uhs DDR50";
137137
break;
138+
case MMC_TIMING_MMC_HS200:
139+
str = "mmc high-speed SDR200";
140+
break;
138141
default:
139142
str = "invalid";
140143
break;

‎drivers/mmc/core/mmc.c‎

Lines changed: 153 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,27 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
286286
}
287287
card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE];
288288
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;
289310
case EXT_CSD_CARD_TYPE_DDR_52 | EXT_CSD_CARD_TYPE_52 |
290311
EXT_CSD_CARD_TYPE_26:
291312
card->ext_csd.hs_max_dtr = 52000000;
@@ -699,6 +720,79 @@ static int mmc_select_powerclass(struct mmc_card *card,
699720
return err;
700721
}
701722

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+
702796
/*
703797
* Handle the detection and initialisation of a card.
704798
*
@@ -905,11 +999,15 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
905999
/*
9061000
* Activate high speed (if supported)
9071001
*/
908-
if ((card->ext_csd.hs_max_dtr != 0) &&
909-
(host->caps & MMC_CAP_MMC_HIGHSPEED)) {
910-
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
911-
EXT_CSD_HS_TIMING, 1,
912-
card->ext_csd.generic_cmd6_time);
1002+
if (card->ext_csd.hs_max_dtr != 0) {
1003+
err = 0;
1004+
if (card->ext_csd.hs_max_dtr > 52000000 &&
1005+
host->caps2 & MMC_CAP2_HS200)
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+
9131011
if (err && err != -EBADMSG)
9141012
goto free_card;
9151013

@@ -918,8 +1016,15 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
9181016
mmc_hostname(card->host));
9191017
err = 0;
9201018
} else {
921-
mmc_card_set_highspeed(card);
922-
mmc_set_timing(card->host, MMC_TIMING_MMC_HS);
1019+
if (card->ext_csd.hs_max_dtr > 52000000 &&
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+
}
9231028
}
9241029
}
9251030

@@ -944,7 +1049,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
9441049
*/
9451050
max_dtr = (unsigned int)-1;
9461051

947-
if (mmc_card_highspeed(card)) {
1052+
if (mmc_card_highspeed(card) || mmc_card_hs200(card)) {
9481053
if (max_dtr > card->ext_csd.hs_max_dtr)
9491054
max_dtr = card->ext_csd.hs_max_dtr;
9501055
} else if (max_dtr > card->csd.max_dtr) {
@@ -969,10 +1074,49 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
9691074
ddr = MMC_1_2V_DDR_MODE;
9701075
}
9711076

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+
9721115
/*
9731116
* Activate wide bus and DDR (if supported).
9741117
*/
975-
if ((card->csd.mmca_vsn >= CSD_SPEC_VER_4) &&
1118+
if (!mmc_card_hs200(card) &&
1119+
(card->csd.mmca_vsn >= CSD_SPEC_VER_3) &&
9761120
(host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) {
9771121
static unsigned ext_csd_bits[][2] = {
9781122
{ EXT_CSD_BUS_WIDTH_8, EXT_CSD_DDR_BUS_WIDTH_8 },

‎drivers/mmc/core/sd.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,8 @@ static int mmc_sd_init_uhs_card(struct mmc_card *card)
661661

662662
/* SPI mode doesn't define CMD19 */
663663
if (!mmc_host_is_spi(card->host) && card->host->ops->execute_tuning)
664-
err = card->host->ops->execute_tuning(card->host);
664+
err = card->host->ops->execute_tuning(card->host,
665+
MMC_SEND_TUNING_BLOCK);
665666

666667
out:
667668
kfree(status);

‎drivers/mmc/core/sdio.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <linux/mmc/host.h>
1616
#include <linux/mmc/card.h>
17+
#include <linux/mmc/mmc.h>
1718
#include <linux/mmc/sdio.h>
1819
#include <linux/mmc/sdio_func.h>
1920
#include <linux/mmc/sdio_ids.h>
@@ -556,7 +557,8 @@ static int mmc_sdio_init_uhs_card(struct mmc_card *card)
556557

557558
/* Initialize and start re-tuning timer */
558559
if (!mmc_host_is_spi(card->host) && card->host->ops->execute_tuning)
559-
err = card->host->ops->execute_tuning(card->host);
560+
err = card->host->ops->execute_tuning(card->host,
561+
MMC_SEND_TUNING_BLOCK);
560562

561563
out:
562564

‎include/linux/mmc/card.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ struct mmc_card {
216216
#define MMC_STATE_ULTRAHIGHSPEED (1<<5) /* card is in ultra high speed mode */
217217
#define MMC_CARD_SDXC (1<<6) /* card is SDXC */
218218
#define MMC_CARD_REMOVED (1<<7) /* card has been removed */
219+
#define MMC_STATE_HIGHSPEED_200 (1<<8) /* card is in HS200 mode */
219220
unsigned int quirks; /* card quirks */
220221
#define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */
221222
#define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */
@@ -374,6 +375,7 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
374375
#define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT)
375376
#define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY)
376377
#define mmc_card_highspeed(c) ((c)->state & MMC_STATE_HIGHSPEED)
378+
#define mmc_card_hs200(c) ((c)->state & MMC_STATE_HIGHSPEED_200)
377379
#define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR)
378380
#define mmc_card_ddr_mode(c) ((c)->state & MMC_STATE_HIGHSPEED_DDR)
379381
#define mmc_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED)
@@ -384,6 +386,7 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
384386
#define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT)
385387
#define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
386388
#define mmc_card_set_highspeed(c) ((c)->state |= MMC_STATE_HIGHSPEED)
389+
#define mmc_card_set_hs200(c) ((c)->state |= MMC_STATE_HIGHSPEED_200)
387390
#define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR)
388391
#define mmc_card_set_ddr_mode(c) ((c)->state |= MMC_STATE_HIGHSPEED_DDR)
389392
#define mmc_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED)

‎include/linux/mmc/host.h‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,13 @@ struct mmc_ios {
5656
#define MMC_TIMING_UHS_SDR50 3
5757
#define MMC_TIMING_UHS_SDR104 4
5858
#define MMC_TIMING_UHS_DDR50 5
59+
#define MMC_TIMING_MMC_HS200 6
5960

6061
#define MMC_SDR_MODE 0
6162
#define MMC_1_2V_DDR_MODE 1
6263
#define MMC_1_8V_DDR_MODE 2
64+
#define MMC_1_2V_SDR_MODE 3
65+
#define MMC_1_8V_SDR_MODE 4
6366

6467
unsigned char signal_voltage; /* signalling voltage (1.8V or 3.3V) */
6568

@@ -148,7 +151,9 @@ struct mmc_host_ops {
148151
void (*init_card)(struct mmc_host *host, struct mmc_card *card);
149152

150153
int (*start_signal_voltage_switch)(struct mmc_host *host, struct mmc_ios *ios);
151-
int (*execute_tuning)(struct mmc_host *host);
154+
155+
/* The tuning command opcode value is different for SD and eMMC cards */
156+
int (*execute_tuning)(struct mmc_host *host, u32 opcode);
152157
void (*enable_preset_value)(struct mmc_host *host, bool enable);
153158
int (*select_drive_strength)(unsigned int max_dtr, int host_drv, int card_drv);
154159
void (*hw_reset)(struct mmc_host *host);
@@ -248,6 +253,10 @@ struct mmc_host {
248253
#define MMC_CAP2_POWEROFF_NOTIFY (1 << 2) /* Notify poweroff supported */
249254
#define MMC_CAP2_NO_MULTI_READ (1 << 3) /* Multiblock reads don't work */
250255
#define MMC_CAP2_NO_SLEEP_CMD (1 << 4) /* Don't allow sleep command */
256+
#define MMC_CAP2_HS200_1_8V_SDR (1 << 5) /* can support */
257+
#define MMC_CAP2_HS200_1_2V_SDR (1 << 6) /* can support */
258+
#define MMC_CAP2_HS200 (MMC_CAP2_HS200_1_8V_SDR | \
259+
MMC_CAP2_HS200_1_2V_SDR)
251260

252261
mmc_pm_flag_t pm_caps; /* supported pm features */
253262
unsigned int power_notify_type;

0 commit comments

Comments
 (0)