Commit 7259683f authored by Russell King's avatar Russell King Committed by Kleber Sacilotto de Souza

mmc: sd: limit SD card power limit according to cards capabilities

BugLink: https://bugs.launchpad.net/bugs/1878232

commit d9812780 upstream.

The SD card specification allows cards to error out a SWITCH command
where the requested function in a group is not supported.  The spec
provides for a set of capabilities which indicate which functions are
supported.

In the case of the power limit, requesting an unsupported power level
via the SWITCH command fails, resulting in the power level remaining at
the power-on default of 0.72W, even though the host and card may support
higher powers levels.

This has been seen with SanDisk 8GB cards, which support the default
0.72W and 1.44W (200mA and 400mA) in combination with an iMX6 host,
supporting up to 2.88W (800mA).  This currently causes us to try to set
a power limit function value of '3' (2.88W) which the card errors out
on, and thereby causes the power level to remain at 0.72W rather than
the desired 1.44W.

Arrange to limit the selected current limit by the capabilities reported
by the card to avoid the SWITCH command failing.  Select the highest
current limit that the host and card combination support.
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
Fixes: a39ca6ae ("mmc: core: Simplify and fix for SD switch processing")
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarIan May <ian.may@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent b37f4af1
...@@ -337,6 +337,7 @@ static int mmc_read_switch(struct mmc_card *card) ...@@ -337,6 +337,7 @@ static int mmc_read_switch(struct mmc_card *card)
card->sw_caps.sd3_bus_mode = status[13]; card->sw_caps.sd3_bus_mode = status[13];
/* Driver Strengths supported by the card */ /* Driver Strengths supported by the card */
card->sw_caps.sd3_drv_type = status[9]; card->sw_caps.sd3_drv_type = status[9];
card->sw_caps.sd3_curr_limit = status[7] | status[6] << 8;
} }
out: out:
...@@ -553,14 +554,25 @@ static int sd_set_current_limit(struct mmc_card *card, u8 *status) ...@@ -553,14 +554,25 @@ static int sd_set_current_limit(struct mmc_card *card, u8 *status)
* when we set current limit to 200ma, the card will draw 200ma, 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 * when we set current limit to 400/600/800ma, the card will draw its
* maximum 300ma from the host. * maximum 300ma from the host.
*
* The above is incorrect: if we try to set a current limit that is
* not supported by the card, the card can rightfully error out the
* attempt, and remain at the default current limit. This results
* in a 300mA card being limited to 200mA even though the host
* supports 800mA. Failures seen with SanDisk 8GB UHS cards with
* an iMX6 host. --rmk
*/ */
if (max_current >= 800) if (max_current >= 800 &&
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 (max_current >= 600) else if (max_current >= 600 &&
card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_600)
current_limit = SD_SET_CURRENT_LIMIT_600; current_limit = SD_SET_CURRENT_LIMIT_600;
else if (max_current >= 400) else if (max_current >= 400 &&
card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_400)
current_limit = SD_SET_CURRENT_LIMIT_400; current_limit = SD_SET_CURRENT_LIMIT_400;
else if (max_current >= 200) else if (max_current >= 200 &&
card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_200)
current_limit = SD_SET_CURRENT_LIMIT_200; current_limit = SD_SET_CURRENT_LIMIT_200;
if (current_limit != SD_SET_CURRENT_NO_CHANGE) { if (current_limit != SD_SET_CURRENT_NO_CHANGE) {
......
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