Skip to content

Commit 567c890

Browse files
Johan Rudholmcjb
authored andcommitted
mmc: core: Break out start_signal_voltage_switch
Allow callers to access the start_signal_voltage_switch host_ops member without going through any cmd11 logic. This is mostly a preparation for the following signal voltage switch patch. Also, reset ios.signal_voltage to its original value if start_signal_voltage_switch fails. Signed-off-by: Johan Rudholm <[email protected]> Acked-by: Ulf Hansson <[email protected]> Tested-by: Wei WANG <[email protected]> Signed-off-by: Chris Ball <[email protected]>
1 parent d887874 commit 567c890

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

drivers/mmc/core/core.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,26 @@ u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
13171317
return ocr;
13181318
}
13191319

1320-
int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, bool cmd11)
1320+
int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage)
1321+
{
1322+
int err = 0;
1323+
int old_signal_voltage = host->ios.signal_voltage;
1324+
1325+
host->ios.signal_voltage = signal_voltage;
1326+
if (host->ops->start_signal_voltage_switch) {
1327+
mmc_host_clk_hold(host);
1328+
err = host->ops->start_signal_voltage_switch(host, &host->ios);
1329+
mmc_host_clk_release(host);
1330+
}
1331+
1332+
if (err)
1333+
host->ios.signal_voltage = old_signal_voltage;
1334+
1335+
return err;
1336+
1337+
}
1338+
1339+
int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage)
13211340
{
13221341
struct mmc_command cmd = {0};
13231342
int err = 0;
@@ -1328,7 +1347,7 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, bool cmd11
13281347
* Send CMD11 only if the request is to switch the card to
13291348
* 1.8V signalling.
13301349
*/
1331-
if ((signal_voltage != MMC_SIGNAL_VOLTAGE_330) && cmd11) {
1350+
if (signal_voltage != MMC_SIGNAL_VOLTAGE_330) {
13321351
cmd.opcode = SD_SWITCH_VOLTAGE;
13331352
cmd.arg = 0;
13341353
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
@@ -1341,15 +1360,7 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, bool cmd11
13411360
return -EIO;
13421361
}
13431362

1344-
host->ios.signal_voltage = signal_voltage;
1345-
1346-
if (host->ops->start_signal_voltage_switch) {
1347-
mmc_host_clk_hold(host);
1348-
err = host->ops->start_signal_voltage_switch(host, &host->ios);
1349-
mmc_host_clk_release(host);
1350-
}
1351-
1352-
return err;
1363+
return __mmc_set_signal_voltage(host, signal_voltage);
13531364
}
13541365

13551366
/*
@@ -1412,7 +1423,7 @@ static void mmc_power_up(struct mmc_host *host)
14121423
mmc_set_ios(host);
14131424

14141425
/* Set signal voltage to 3.3V */
1415-
mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, false);
1426+
__mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330);
14161427

14171428
/*
14181429
* This delay should be sufficient to allow the power supply

drivers/mmc/core/core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ void mmc_set_ungated(struct mmc_host *host);
4040
void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
4141
void mmc_set_bus_width(struct mmc_host *host, unsigned int width);
4242
u32 mmc_select_voltage(struct mmc_host *host, u32 ocr);
43-
int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage,
44-
bool cmd11);
43+
int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage);
44+
int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage);
4545
void mmc_set_timing(struct mmc_host *host, unsigned int timing);
4646
void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
4747
void mmc_power_off(struct mmc_host *host);

drivers/mmc/core/mmc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,11 @@ static int mmc_select_hs200(struct mmc_card *card)
769769

770770
if (card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_2V &&
771771
host->caps2 & MMC_CAP2_HS200_1_2V_SDR)
772-
err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120, 0);
772+
err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120);
773773

774774
if (err && card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_8V &&
775775
host->caps2 & MMC_CAP2_HS200_1_8V_SDR)
776-
err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180, 0);
776+
err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180);
777777

778778
/* If fails try again during next card power cycle */
779779
if (err)
@@ -1221,8 +1221,8 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
12211221
* WARNING: eMMC rules are NOT the same as SD DDR
12221222
*/
12231223
if (ddr == MMC_1_2V_DDR_MODE) {
1224-
err = mmc_set_signal_voltage(host,
1225-
MMC_SIGNAL_VOLTAGE_120, 0);
1224+
err = __mmc_set_signal_voltage(host,
1225+
MMC_SIGNAL_VOLTAGE_120);
12261226
if (err)
12271227
goto err;
12281228
}

drivers/mmc/core/sd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr)
757757
*/
758758
if (!mmc_host_is_spi(host) && rocr &&
759759
((*rocr & 0x41000000) == 0x41000000)) {
760-
err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180, true);
760+
err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180);
761761
if (err) {
762762
ocr &= ~SD_OCR_S18R;
763763
goto try_again;

drivers/mmc/core/sdio.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
647647
* it.
648648
*/
649649
if ((ocr & R4_18V_PRESENT) && mmc_host_uhs(host)) {
650-
err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180,
651-
true);
650+
err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180);
652651
if (err) {
653652
ocr &= ~R4_18V_PRESENT;
654653
host->ocr &= ~R4_18V_PRESENT;

0 commit comments

Comments
 (0)