linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: sdhci-of-at91: wait for calibration done before proceed
@ 2021-09-15 10:28 Claudiu Beznea
  2021-09-15 12:04 ` Nicolas Ferre
  2021-09-23  9:02 ` Adrian Hunter
  0 siblings, 2 replies; 3+ messages in thread
From: Claudiu Beznea @ 2021-09-15 10:28 UTC (permalink / raw)
  To: adrian.hunter, eugen.hristev, ulf.hansson, nicolas.ferre,
	alexandre.belloni, ludovic.desroches
  Cc: linux-mmc, linux-arm-kernel, linux-kernel, Claudiu Beznea

Datasheet specifies that at the end of calibration the SDMMC_CALCR_EN
bit will be cleared. No commands should be send before calibration is
done.

Fixes: dbdea70f71d67 ("mmc: sdhci-of-at91: fix CALCR register being rewritten")
Fixes: 727d836a375ad ("mmc: sdhci-of-at91: add DT property to enable calibration on full reset")
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/mmc/host/sdhci-of-at91.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/mmc/host/sdhci-of-at91.c b/drivers/mmc/host/sdhci-of-at91.c
index 5564d7b23e7c..2b28711e039d 100644
--- a/drivers/mmc/host/sdhci-of-at91.c
+++ b/drivers/mmc/host/sdhci-of-at91.c
@@ -114,6 +114,8 @@ static void sdhci_at91_reset(struct sdhci_host *host, u8 mask)
 {
 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
 	struct sdhci_at91_priv *priv = sdhci_pltfm_priv(pltfm_host);
+	unsigned long timeout = jiffies + msecs_to_jiffies(20);
+	unsigned int tmp;
 
 	sdhci_reset(host, mask);
 
@@ -126,6 +128,14 @@ static void sdhci_at91_reset(struct sdhci_host *host, u8 mask)
 
 		sdhci_writel(host, calcr | SDMMC_CALCR_ALWYSON | SDMMC_CALCR_EN,
 			     SDMMC_CALCR);
+
+		do {
+			tmp = sdhci_readl(host, SDMMC_CALCR);
+		} while (time_before(jiffies, timeout) &&
+			 (tmp & SDMMC_CALCR_EN));
+
+		if (tmp & SDMMC_CALCR_EN)
+			dev_err(mmc_dev(host->mmc), "Failed to calibrate\n");
 	}
 }
 
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] mmc: sdhci-of-at91: wait for calibration done before proceed
  2021-09-15 10:28 [PATCH] mmc: sdhci-of-at91: wait for calibration done before proceed Claudiu Beznea
@ 2021-09-15 12:04 ` Nicolas Ferre
  2021-09-23  9:02 ` Adrian Hunter
  1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Ferre @ 2021-09-15 12:04 UTC (permalink / raw)
  To: Claudiu Beznea, adrian.hunter, eugen.hristev, ulf.hansson,
	alexandre.belloni, ludovic.desroches
  Cc: linux-mmc, linux-arm-kernel, linux-kernel

On 15/09/2021 at 12:28, Claudiu Beznea wrote:
> Datasheet specifies that at the end of calibration the SDMMC_CALCR_EN
> bit will be cleared. No commands should be send before calibration is
> done.
> 
> Fixes: dbdea70f71d67 ("mmc: sdhci-of-at91: fix CALCR register being rewritten")
> Fixes: 727d836a375ad ("mmc: sdhci-of-at91: add DT property to enable calibration on full reset")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>

Indeed, needed. Thanks Claudiu,
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>

Best regards,
   Nicolas

> ---
>   drivers/mmc/host/sdhci-of-at91.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/mmc/host/sdhci-of-at91.c b/drivers/mmc/host/sdhci-of-at91.c
> index 5564d7b23e7c..2b28711e039d 100644
> --- a/drivers/mmc/host/sdhci-of-at91.c
> +++ b/drivers/mmc/host/sdhci-of-at91.c
> @@ -114,6 +114,8 @@ static void sdhci_at91_reset(struct sdhci_host *host, u8 mask)
>   {
>   	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
>   	struct sdhci_at91_priv *priv = sdhci_pltfm_priv(pltfm_host);
> +	unsigned long timeout = jiffies + msecs_to_jiffies(20);
> +	unsigned int tmp;
>   
>   	sdhci_reset(host, mask);
>   
> @@ -126,6 +128,14 @@ static void sdhci_at91_reset(struct sdhci_host *host, u8 mask)
>   
>   		sdhci_writel(host, calcr | SDMMC_CALCR_ALWYSON | SDMMC_CALCR_EN,
>   			     SDMMC_CALCR);
> +
> +		do {
> +			tmp = sdhci_readl(host, SDMMC_CALCR);
> +		} while (time_before(jiffies, timeout) &&
> +			 (tmp & SDMMC_CALCR_EN));
> +
> +		if (tmp & SDMMC_CALCR_EN)
> +			dev_err(mmc_dev(host->mmc), "Failed to calibrate\n");
>   	}
>   }
>   
> 


-- 
Nicolas Ferre

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] mmc: sdhci-of-at91: wait for calibration done before proceed
  2021-09-15 10:28 [PATCH] mmc: sdhci-of-at91: wait for calibration done before proceed Claudiu Beznea
  2021-09-15 12:04 ` Nicolas Ferre
@ 2021-09-23  9:02 ` Adrian Hunter
  1 sibling, 0 replies; 3+ messages in thread
From: Adrian Hunter @ 2021-09-23  9:02 UTC (permalink / raw)
  To: Claudiu Beznea, eugen.hristev, ulf.hansson, nicolas.ferre,
	alexandre.belloni, ludovic.desroches
  Cc: linux-mmc, linux-arm-kernel, linux-kernel

On 15/09/21 1:28 pm, Claudiu Beznea wrote:
> Datasheet specifies that at the end of calibration the SDMMC_CALCR_EN
> bit will be cleared. No commands should be send before calibration is
> done.
> 
> Fixes: dbdea70f71d67 ("mmc: sdhci-of-at91: fix CALCR register being rewritten")
> Fixes: 727d836a375ad ("mmc: sdhci-of-at91: add DT property to enable calibration on full reset")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
>  drivers/mmc/host/sdhci-of-at91.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/mmc/host/sdhci-of-at91.c b/drivers/mmc/host/sdhci-of-at91.c
> index 5564d7b23e7c..2b28711e039d 100644
> --- a/drivers/mmc/host/sdhci-of-at91.c
> +++ b/drivers/mmc/host/sdhci-of-at91.c
> @@ -114,6 +114,8 @@ static void sdhci_at91_reset(struct sdhci_host *host, u8 mask)
>  {
>  	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
>  	struct sdhci_at91_priv *priv = sdhci_pltfm_priv(pltfm_host);
> +	unsigned long timeout = jiffies + msecs_to_jiffies(20);
> +	unsigned int tmp;
>  
>  	sdhci_reset(host, mask);
>  
> @@ -126,6 +128,14 @@ static void sdhci_at91_reset(struct sdhci_host *host, u8 mask)
>  
>  		sdhci_writel(host, calcr | SDMMC_CALCR_ALWYSON | SDMMC_CALCR_EN,
>  			     SDMMC_CALCR);
> +
> +		do {
> +			tmp = sdhci_readl(host, SDMMC_CALCR);
> +		} while (time_before(jiffies, timeout) &&
> +			 (tmp & SDMMC_CALCR_EN));
> +
> +		if (tmp & SDMMC_CALCR_EN)
> +			dev_err(mmc_dev(host->mmc), "Failed to calibrate\n");

Please use a polling macro (include <linux/iopoll.h>)
i.e.

		if (read_poll_timeout(sdhci_readl, tmp, !(tmp & SDMMC_CALCR_EN),
				      10, 20000, false, host, SDMMC_CALCR))
			dev_err(mmc_dev(host->mmc), "Failed to calibrate\n");



>  	}
>  }
>  
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2021-09-23  9:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-15 10:28 [PATCH] mmc: sdhci-of-at91: wait for calibration done before proceed Claudiu Beznea
2021-09-15 12:04 ` Nicolas Ferre
2021-09-23  9:02 ` Adrian Hunter

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).