LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] mmc: mmci: stm32: check when the voltage switch procedure should be done
@ 2021-07-01 14:33 Yann Gautier
  2021-08-04 11:34 ` Ulf Hansson
  0 siblings, 1 reply; 2+ messages in thread
From: Yann Gautier @ 2021-07-01 14:33 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Maxime Coquelin, Alexandre Torgue, Philipp Zabel,
	Christophe Kerello, Yann Gautier, linux-mmc, linux-stm32,
	linux-arm-kernel, linux-kernel

From: Christophe Kerello <christophe.kerello@foss.st.com>

If the card has not been power cycled, it may still be using 1.8V
signaling. This situation is detected in mmc_sd_init_card function and
should be handled in mmci stm32 variant.
The host->pwr_reg variable is also correctly protected with spin locks.

Fixes: 94b94a93e355 ("mmc: mmci_sdmmc: Implement signal voltage callbacks")

Signed-off-by: Christophe Kerello <christophe.kerello@foss.st.com>
Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
---
 drivers/mmc/host/mmci_stm32_sdmmc.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/mmci_stm32_sdmmc.c b/drivers/mmc/host/mmci_stm32_sdmmc.c
index 51db30acf4dc..fdaa11f92fe6 100644
--- a/drivers/mmc/host/mmci_stm32_sdmmc.c
+++ b/drivers/mmc/host/mmci_stm32_sdmmc.c
@@ -479,8 +479,9 @@ static int sdmmc_post_sig_volt_switch(struct mmci_host *host,
 	u32 status;
 	int ret = 0;
 
-	if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180) {
-		spin_lock_irqsave(&host->lock, flags);
+	spin_lock_irqsave(&host->lock, flags);
+	if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180 &&
+	    host->pwr_reg & MCI_STM32_VSWITCHEN) {
 		mmci_write_pwrreg(host, host->pwr_reg | MCI_STM32_VSWITCH);
 		spin_unlock_irqrestore(&host->lock, flags);
 
@@ -492,9 +493,11 @@ static int sdmmc_post_sig_volt_switch(struct mmci_host *host,
 
 		writel_relaxed(MCI_STM32_VSWENDC | MCI_STM32_CKSTOPC,
 			       host->base + MMCICLEAR);
+		spin_lock_irqsave(&host->lock, flags);
 		mmci_write_pwrreg(host, host->pwr_reg &
 				  ~(MCI_STM32_VSWITCHEN | MCI_STM32_VSWITCH));
 	}
+	spin_unlock_irqrestore(&host->lock, flags);
 
 	return ret;
 }
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mmc: mmci: stm32: check when the voltage switch procedure should be done
  2021-07-01 14:33 [PATCH] mmc: mmci: stm32: check when the voltage switch procedure should be done Yann Gautier
@ 2021-08-04 11:34 ` Ulf Hansson
  0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2021-08-04 11:34 UTC (permalink / raw)
  To: Yann Gautier
  Cc: Maxime Coquelin, Alexandre Torgue, Philipp Zabel,
	Christophe Kerello, linux-mmc, linux-stm32, Linux ARM,
	Linux Kernel Mailing List

On Thu, 1 Jul 2021 at 16:34, Yann Gautier <yann.gautier@foss.st.com> wrote:
>
> From: Christophe Kerello <christophe.kerello@foss.st.com>
>
> If the card has not been power cycled, it may still be using 1.8V
> signaling. This situation is detected in mmc_sd_init_card function and
> should be handled in mmci stm32 variant.
> The host->pwr_reg variable is also correctly protected with spin locks.
>
> Fixes: 94b94a93e355 ("mmc: mmci_sdmmc: Implement signal voltage callbacks")
>
> Signed-off-by: Christophe Kerello <christophe.kerello@foss.st.com>
> Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>

Applied for fixes and by adding stable tag, thanks!

Kind regards
Uffe


> ---
>  drivers/mmc/host/mmci_stm32_sdmmc.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/host/mmci_stm32_sdmmc.c b/drivers/mmc/host/mmci_stm32_sdmmc.c
> index 51db30acf4dc..fdaa11f92fe6 100644
> --- a/drivers/mmc/host/mmci_stm32_sdmmc.c
> +++ b/drivers/mmc/host/mmci_stm32_sdmmc.c
> @@ -479,8 +479,9 @@ static int sdmmc_post_sig_volt_switch(struct mmci_host *host,
>         u32 status;
>         int ret = 0;
>
> -       if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180) {
> -               spin_lock_irqsave(&host->lock, flags);
> +       spin_lock_irqsave(&host->lock, flags);
> +       if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180 &&
> +           host->pwr_reg & MCI_STM32_VSWITCHEN) {
>                 mmci_write_pwrreg(host, host->pwr_reg | MCI_STM32_VSWITCH);
>                 spin_unlock_irqrestore(&host->lock, flags);
>
> @@ -492,9 +493,11 @@ static int sdmmc_post_sig_volt_switch(struct mmci_host *host,
>
>                 writel_relaxed(MCI_STM32_VSWENDC | MCI_STM32_CKSTOPC,
>                                host->base + MMCICLEAR);
> +               spin_lock_irqsave(&host->lock, flags);
>                 mmci_write_pwrreg(host, host->pwr_reg &
>                                   ~(MCI_STM32_VSWITCHEN | MCI_STM32_VSWITCH));
>         }
> +       spin_unlock_irqrestore(&host->lock, flags);
>
>         return ret;
>  }
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-04 11:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 14:33 [PATCH] mmc: mmci: stm32: check when the voltage switch procedure should be done Yann Gautier
2021-08-04 11:34 ` 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).