* [PATCH] mmc: core: properly select voltage range without power cycle
@ 2022-10-28 7:37 Yann Gautier
2022-11-07 20:13 ` Ulf Hansson
0 siblings, 1 reply; 2+ messages in thread
From: Yann Gautier @ 2022-10-28 7:37 UTC (permalink / raw)
To: Ulf Hansson
Cc: Wolfram Sang, Adrian Hunter, Kees Cook, Darrick J . Wong,
Shaik Sajida Bhanu, Jason A . Donenfeld, linux-mmc, linux-kernel,
christophe.kerello, Yann Gautier
In mmc_select_voltage(), if there is no full power cycle, the voltage
range selected at the end of the function will be on a single range
(e.g. 3.3V/3.4V). To keep a range around the selected voltage (3.2V/3.4V),
the mask shift should be reduced by 1.
This issue was triggered by using a specific SD-card (Verbatim Premium
16GB UHS-1) on an STM32MP157C-DK2 board. This board cannot do UHS modes
and there is no power cycle. And the card was failing to switch to
high-speed mode. When adding the range 3.2V/3.3V for this card with the
proposed shift change, the card can switch to high-speed mode.
Fixes: ce69d37b7d8f ("mmc: core: Prevent violation of specs while initializing cards")
Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
---
drivers/mmc/core/core.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 95fa8fb1d45f..c5de202f530a 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -1134,7 +1134,13 @@ u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
mmc_power_cycle(host, ocr);
} else {
bit = fls(ocr) - 1;
- ocr &= 3 << bit;
+ /*
+ * The bit variable represents the highest voltage bit set in
+ * the OCR register.
+ * To keep a range of 2 values (e.g. 3.2V/3.3V and 3.3V/3.4V),
+ * we must shift the mask '3' with (bit - 1).
+ */
+ ocr &= 3 << (bit - 1);
if (bit != host->ios.vdd)
dev_warn(mmc_dev(host), "exceeding card's volts\n");
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mmc: core: properly select voltage range without power cycle
2022-10-28 7:37 [PATCH] mmc: core: properly select voltage range without power cycle Yann Gautier
@ 2022-11-07 20:13 ` Ulf Hansson
0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2022-11-07 20:13 UTC (permalink / raw)
To: Yann Gautier
Cc: Wolfram Sang, Adrian Hunter, Kees Cook, Darrick J . Wong,
Shaik Sajida Bhanu, Jason A . Donenfeld, linux-mmc, linux-kernel,
christophe.kerello
On Fri, 28 Oct 2022 at 09:38, Yann Gautier <yann.gautier@foss.st.com> wrote:
>
> In mmc_select_voltage(), if there is no full power cycle, the voltage
> range selected at the end of the function will be on a single range
> (e.g. 3.3V/3.4V). To keep a range around the selected voltage (3.2V/3.4V),
> the mask shift should be reduced by 1.
>
> This issue was triggered by using a specific SD-card (Verbatim Premium
> 16GB UHS-1) on an STM32MP157C-DK2 board. This board cannot do UHS modes
> and there is no power cycle. And the card was failing to switch to
> high-speed mode. When adding the range 3.2V/3.3V for this card with the
> proposed shift change, the card can switch to high-speed mode.
>
> Fixes: ce69d37b7d8f ("mmc: core: Prevent violation of specs while initializing cards")
> Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
Applied for next and by adding a stable tag, thanks!
Kind regards
Uffe
> ---
> drivers/mmc/core/core.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 95fa8fb1d45f..c5de202f530a 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -1134,7 +1134,13 @@ u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
> mmc_power_cycle(host, ocr);
> } else {
> bit = fls(ocr) - 1;
> - ocr &= 3 << bit;
> + /*
> + * The bit variable represents the highest voltage bit set in
> + * the OCR register.
> + * To keep a range of 2 values (e.g. 3.2V/3.3V and 3.3V/3.4V),
> + * we must shift the mask '3' with (bit - 1).
> + */
> + ocr &= 3 << (bit - 1);
> if (bit != host->ios.vdd)
> dev_warn(mmc_dev(host), "exceeding card's volts\n");
> }
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-07 20:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-28 7:37 [PATCH] mmc: core: properly select voltage range without power cycle Yann Gautier
2022-11-07 20:13 ` Ulf Hansson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).