Skip to content

Commit 2385049

Browse files
Seungwon Jeoncjb
authored andcommitted
mmc: step power class after final selection of bus mode
Power class is changed once only after selection of bus modes including speed and bus-width finishes finally. Signed-off-by: Seungwon Jeon <tgih.jun@samsung.com> Tested-by: Jaehoon Chung <jh80.chung@samsung.com> Acked-by: Jaehoon Chung <jh80.chung@samsung.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Chris Ball <chris@printf.net>
1 parent 2415c0e commit 2385049

1 file changed

Lines changed: 55 additions & 41 deletions

File tree

‎drivers/mmc/core/mmc.c‎

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -724,17 +724,13 @@ static struct device_type mmc_type = {
724724
* extended CSD register, select it by executing the
725725
* mmc_switch command.
726726
*/
727-
static int mmc_select_powerclass(struct mmc_card *card,
728-
unsigned int bus_width)
727+
static int __mmc_select_powerclass(struct mmc_card *card,
728+
unsigned int bus_width)
729729
{
730-
int err = 0;
730+
struct mmc_host *host = card->host;
731+
struct mmc_ext_csd *ext_csd = &card->ext_csd;
731732
unsigned int pwrclass_val = 0;
732-
struct mmc_host *host;
733-
734-
BUG_ON(!card);
735-
736-
host = card->host;
737-
BUG_ON(!host);
733+
int err = 0;
738734

739735
/* Power class selection is supported for versions >= 4.0 */
740736
if (card->csd.mmca_vsn < CSD_SPEC_VER_4)
@@ -746,14 +742,14 @@ static int mmc_select_powerclass(struct mmc_card *card,
746742

747743
switch (1 << host->ios.vdd) {
748744
case MMC_VDD_165_195:
749-
if (host->ios.clock <= 26000000)
750-
pwrclass_val = card->ext_csd.raw_pwr_cl_26_195;
751-
else if (host->ios.clock <= 52000000)
745+
if (host->ios.clock <= MMC_HIGH_26_MAX_DTR)
746+
pwrclass_val = ext_csd->raw_pwr_cl_26_195;
747+
else if (host->ios.clock <= MMC_HIGH_52_MAX_DTR)
752748
pwrclass_val = (bus_width <= EXT_CSD_BUS_WIDTH_8) ?
753-
card->ext_csd.raw_pwr_cl_52_195 :
754-
card->ext_csd.raw_pwr_cl_ddr_52_195;
755-
else if (host->ios.clock <= 200000000)
756-
pwrclass_val = card->ext_csd.raw_pwr_cl_200_195;
749+
ext_csd->raw_pwr_cl_52_195 :
750+
ext_csd->raw_pwr_cl_ddr_52_195;
751+
else if (host->ios.clock <= MMC_HS200_MAX_DTR)
752+
pwrclass_val = ext_csd->raw_pwr_cl_200_195;
757753
break;
758754
case MMC_VDD_27_28:
759755
case MMC_VDD_28_29:
@@ -764,14 +760,14 @@ static int mmc_select_powerclass(struct mmc_card *card,
764760
case MMC_VDD_33_34:
765761
case MMC_VDD_34_35:
766762
case MMC_VDD_35_36:
767-
if (host->ios.clock <= 26000000)
768-
pwrclass_val = card->ext_csd.raw_pwr_cl_26_360;
769-
else if (host->ios.clock <= 52000000)
763+
if (host->ios.clock <= MMC_HIGH_26_MAX_DTR)
764+
pwrclass_val = ext_csd->raw_pwr_cl_26_360;
765+
else if (host->ios.clock <= MMC_HIGH_52_MAX_DTR)
770766
pwrclass_val = (bus_width <= EXT_CSD_BUS_WIDTH_8) ?
771-
card->ext_csd.raw_pwr_cl_52_360 :
772-
card->ext_csd.raw_pwr_cl_ddr_52_360;
773-
else if (host->ios.clock <= 200000000)
774-
pwrclass_val = card->ext_csd.raw_pwr_cl_200_360;
767+
ext_csd->raw_pwr_cl_52_360 :
768+
ext_csd->raw_pwr_cl_ddr_52_360;
769+
else if (host->ios.clock <= MMC_HS200_MAX_DTR)
770+
pwrclass_val = ext_csd->raw_pwr_cl_200_360;
775771
break;
776772
default:
777773
pr_warning("%s: Voltage range not supported "
@@ -797,6 +793,37 @@ static int mmc_select_powerclass(struct mmc_card *card,
797793
return err;
798794
}
799795

796+
static int mmc_select_powerclass(struct mmc_card *card)
797+
{
798+
struct mmc_host *host = card->host;
799+
u32 bus_width, ext_csd_bits;
800+
int err, ddr;
801+
802+
/* Power class selection is supported for versions >= 4.0 */
803+
if (card->csd.mmca_vsn < CSD_SPEC_VER_4)
804+
return 0;
805+
806+
bus_width = host->ios.bus_width;
807+
/* Power class values are defined only for 4/8 bit bus */
808+
if (bus_width == MMC_BUS_WIDTH_1)
809+
return 0;
810+
811+
ddr = card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_52;
812+
if (ddr)
813+
ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ?
814+
EXT_CSD_DDR_BUS_WIDTH_8 : EXT_CSD_DDR_BUS_WIDTH_4;
815+
else
816+
ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ?
817+
EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4;
818+
819+
err = __mmc_select_powerclass(card, ext_csd_bits);
820+
if (err)
821+
pr_warn("%s: power class selection to bus width %d ddr %d failed\n",
822+
mmc_hostname(host), 1 << bus_width, ddr);
823+
824+
return err;
825+
}
826+
800827
/*
801828
* Selects the desired buswidth and switch to the HS200 mode
802829
* if bus width set without error
@@ -1158,11 +1185,6 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
11581185

11591186
ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ?
11601187
EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4;
1161-
err = mmc_select_powerclass(card, ext_csd_bits);
1162-
if (err)
1163-
pr_warning("%s: power class selection to bus width %d"
1164-
" failed\n", mmc_hostname(card->host),
1165-
1 << bus_width);
11661188
}
11671189

11681190
/*
@@ -1191,12 +1213,6 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
11911213
bus_width = bus_widths[idx];
11921214
if (bus_width == MMC_BUS_WIDTH_1)
11931215
ddr = 0; /* no DDR for 1-bit width */
1194-
err = mmc_select_powerclass(card, ext_csd_bits[idx][0]);
1195-
if (err)
1196-
pr_warning("%s: power class selection to "
1197-
"bus width %d failed\n",
1198-
mmc_hostname(card->host),
1199-
1 << bus_width);
12001216

12011217
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
12021218
EXT_CSD_BUS_WIDTH,
@@ -1221,13 +1237,6 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
12211237
}
12221238

12231239
if (!err && ddr) {
1224-
err = mmc_select_powerclass(card, ext_csd_bits[idx][1]);
1225-
if (err)
1226-
pr_warning("%s: power class selection to "
1227-
"bus width %d ddr %d failed\n",
1228-
mmc_hostname(card->host),
1229-
1 << bus_width, ddr);
1230-
12311240
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
12321241
EXT_CSD_BUS_WIDTH,
12331242
ext_csd_bits[idx][1],
@@ -1264,6 +1273,11 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
12641273
}
12651274
}
12661275

1276+
/*
1277+
* Choose the power class with selected bus interface
1278+
*/
1279+
mmc_select_powerclass(card);
1280+
12671281
/*
12681282
* Enable HPI feature (if supported)
12691283
*/

0 commit comments

Comments
 (0)