Commit a39ca6ae authored by Aaron Lu's avatar Aaron Lu Committed by Chris Ball

mmc: core: Simplify and fix for SD switch processing

In mmc_read_switch, just do a one time mode 0 switch command to get the
support bits information, no need to do multiple times as the support
bits do not change with different arguments.

And no need to check current limit support bits, as these bits are
fixed according to the signal voltage. If the signal voltage is 1.8V,
the support bits would be 0xf and if the signal voltage is 3.3V, the
support bits would be 0x01. We will check host's ability to set the
current limit.
Signed-off-by: default avatarAaron Lu <aaron.lu@amd.com>
Signed-off-by: default avatarChris Ball <cjb@laptop.org>
parent b67c6b41
...@@ -290,8 +290,12 @@ static int mmc_read_switch(struct mmc_card *card) ...@@ -290,8 +290,12 @@ static int mmc_read_switch(struct mmc_card *card)
return -ENOMEM; return -ENOMEM;
} }
/* Find out the supported Bus Speed Modes. */ /*
err = mmc_sd_switch(card, 0, 0, 1, status); * Find out the card's support bits with a mode 0 operation.
* The argument does not matter, as the support bits do not
* change with the arguments.
*/
err = mmc_sd_switch(card, 0, 0, 0, status);
if (err) { if (err) {
/* /*
* If the host or the card can't do the switch, * If the host or the card can't do the switch,
...@@ -312,46 +316,8 @@ static int mmc_read_switch(struct mmc_card *card) ...@@ -312,46 +316,8 @@ static int mmc_read_switch(struct mmc_card *card)
if (card->scr.sda_spec3) { if (card->scr.sda_spec3) {
card->sw_caps.sd3_bus_mode = status[13]; card->sw_caps.sd3_bus_mode = status[13];
/* Driver Strengths supported by the card */
/* Find out Driver Strengths supported by the card */
err = mmc_sd_switch(card, 0, 2, 1, status);
if (err) {
/*
* If the host or the card can't do the switch,
* fail more gracefully.
*/
if (err != -EINVAL && err != -ENOSYS && err != -EFAULT)
goto out;
pr_warning("%s: problem reading "
"Driver Strength.\n",
mmc_hostname(card->host));
err = 0;
goto out;
}
card->sw_caps.sd3_drv_type = status[9]; card->sw_caps.sd3_drv_type = status[9];
/* Find out Current Limits supported by the card */
err = mmc_sd_switch(card, 0, 3, 1, status);
if (err) {
/*
* If the host or the card can't do the switch,
* fail more gracefully.
*/
if (err != -EINVAL && err != -ENOSYS && err != -EFAULT)
goto out;
pr_warning("%s: problem reading "
"Current Limit.\n",
mmc_hostname(card->host));
err = 0;
goto out;
}
card->sw_caps.sd3_curr_limit = status[7];
} }
out: out:
...@@ -560,41 +526,24 @@ static int sd_set_current_limit(struct mmc_card *card, u8 *status) ...@@ -560,41 +526,24 @@ static int sd_set_current_limit(struct mmc_card *card, u8 *status)
* Current limit switch is only defined for SDR50, SDR104, and DDR50 * Current limit switch is only defined for SDR50, SDR104, and DDR50
* bus speed modes. For other bus speed modes, we do not change the * bus speed modes. For other bus speed modes, we do not change the
* current limit. * current limit.
* We only check host's capability here, if we set a limit that is
* higher than the card's maximum current, the card will be using its
* maximum current, e.g. if the card's maximum current is 300ma, and
* when we set current limit to 200ma, the card will draw 200ma, and
* when we set current limit to 400/600/800ma, the card will draw its
* maximum 300ma from the host.
*/ */
if ((card->sd_bus_speed == UHS_SDR50_BUS_SPEED) || if ((card->sd_bus_speed == UHS_SDR50_BUS_SPEED) ||
(card->sd_bus_speed == UHS_SDR104_BUS_SPEED) || (card->sd_bus_speed == UHS_SDR104_BUS_SPEED) ||
(card->sd_bus_speed == UHS_DDR50_BUS_SPEED)) { (card->sd_bus_speed == UHS_DDR50_BUS_SPEED)) {
if (card->host->caps & MMC_CAP_MAX_CURRENT_800) { if (card->host->caps & MMC_CAP_MAX_CURRENT_800)
if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_800) current_limit = SD_SET_CURRENT_LIMIT_800;
current_limit = SD_SET_CURRENT_LIMIT_800; else if (card->host->caps & MMC_CAP_MAX_CURRENT_600)
else if (card->sw_caps.sd3_curr_limit & current_limit = SD_SET_CURRENT_LIMIT_600;
SD_MAX_CURRENT_600) else if (card->host->caps & MMC_CAP_MAX_CURRENT_400)
current_limit = SD_SET_CURRENT_LIMIT_600; current_limit = SD_SET_CURRENT_LIMIT_400;
else if (card->sw_caps.sd3_curr_limit & else if (card->host->caps & MMC_CAP_MAX_CURRENT_200)
SD_MAX_CURRENT_400) current_limit = SD_SET_CURRENT_LIMIT_200;
current_limit = SD_SET_CURRENT_LIMIT_400;
else if (card->sw_caps.sd3_curr_limit &
SD_MAX_CURRENT_200)
current_limit = SD_SET_CURRENT_LIMIT_200;
} else if (card->host->caps & MMC_CAP_MAX_CURRENT_600) {
if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_600)
current_limit = SD_SET_CURRENT_LIMIT_600;
else if (card->sw_caps.sd3_curr_limit &
SD_MAX_CURRENT_400)
current_limit = SD_SET_CURRENT_LIMIT_400;
else if (card->sw_caps.sd3_curr_limit &
SD_MAX_CURRENT_200)
current_limit = SD_SET_CURRENT_LIMIT_200;
} else if (card->host->caps & MMC_CAP_MAX_CURRENT_400) {
if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_400)
current_limit = SD_SET_CURRENT_LIMIT_400;
else if (card->sw_caps.sd3_curr_limit &
SD_MAX_CURRENT_200)
current_limit = SD_SET_CURRENT_LIMIT_200;
} else if (card->host->caps & MMC_CAP_MAX_CURRENT_200) {
if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_200)
current_limit = SD_SET_CURRENT_LIMIT_200;
}
} }
if (current_limit != SD_SET_CURRENT_NO_CHANGE) { if (current_limit != SD_SET_CURRENT_NO_CHANGE) {
...@@ -607,6 +556,7 @@ static int sd_set_current_limit(struct mmc_card *card, u8 *status) ...@@ -607,6 +556,7 @@ static int sd_set_current_limit(struct mmc_card *card, u8 *status)
mmc_hostname(card->host)); mmc_hostname(card->host));
} }
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment