LKML Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v3] mmc: sdhci: fix minimum clock rate for v3 controller
@ 2020-01-15  9:54 Michał Mirosław
  2020-01-15 10:01 ` Adrian Hunter
  2020-01-16 14:39 ` Ulf Hansson
  0 siblings, 2 replies; 3+ messages in thread
From: Michał Mirosław @ 2020-01-15  9:54 UTC (permalink / raw)
  To: Adrian Hunter, Ulf Hansson; +Cc: linux-mmc, linux-kernel

For SDHCIv3+ with programmable clock mode, minimal clock frequency is
still base clock / max(divider). Minimal programmable clock frequency is
always greater than minimal divided clock frequency. Without this patch,
SDHCI uses out-of-spec initial frequency when multiplier is big enough:

mmc1: mmc_rescan_try_freq: trying to init card at 468750 Hz
[for 480 MHz source clock divided by 1024]

The code in sdhci_calc_clk() already chooses a correct SDCLK clock mode.

Cc: stable@vger.kernel.org
Fixes: c3ed3877625f ("mmc: sdhci: add support for programmable clock mode")
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 v3: commitmsg/comment rewording
 v2: extend commitmsg and add comment
---
 drivers/mmc/host/sdhci.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 96609c961465..24fb6d710de6 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -3903,11 +3903,13 @@ int sdhci_setup_host(struct sdhci_host *host)
 	if (host->ops->get_min_clock)
 		mmc->f_min = host->ops->get_min_clock(host);
 	else if (host->version >= SDHCI_SPEC_300) {
-		if (host->clk_mul) {
-			mmc->f_min = (host->max_clk * host->clk_mul) / 1024;
+		if (host->clk_mul)
 			max_clk = host->max_clk * host->clk_mul;
-		} else
-			mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300;
+		/*
+		 * Divided Clock Mode minimum clock rate is always less than
+		 * Programmable Clock Mode minimum clock rate.
+		 */
+		mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300;
 	} else
 		mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200;
 
-- 
2.20.1


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

* Re: [PATCH v3] mmc: sdhci: fix minimum clock rate for v3 controller
  2020-01-15  9:54 [PATCH v3] mmc: sdhci: fix minimum clock rate for v3 controller Michał Mirosław
@ 2020-01-15 10:01 ` Adrian Hunter
  2020-01-16 14:39 ` Ulf Hansson
  1 sibling, 0 replies; 3+ messages in thread
From: Adrian Hunter @ 2020-01-15 10:01 UTC (permalink / raw)
  To: Michał Mirosław, Ulf Hansson; +Cc: linux-mmc, linux-kernel

On 15/01/20 11:54 am, Michał Mirosław wrote:
> For SDHCIv3+ with programmable clock mode, minimal clock frequency is
> still base clock / max(divider). Minimal programmable clock frequency is
> always greater than minimal divided clock frequency. Without this patch,
> SDHCI uses out-of-spec initial frequency when multiplier is big enough:
> 
> mmc1: mmc_rescan_try_freq: trying to init card at 468750 Hz
> [for 480 MHz source clock divided by 1024]
> 
> The code in sdhci_calc_clk() already chooses a correct SDCLK clock mode.
> 
> Cc: stable@vger.kernel.org
> Fixes: c3ed3877625f ("mmc: sdhci: add support for programmable clock mode")
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  v3: commitmsg/comment rewording
>  v2: extend commitmsg and add comment
> ---
>  drivers/mmc/host/sdhci.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index 96609c961465..24fb6d710de6 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -3903,11 +3903,13 @@ int sdhci_setup_host(struct sdhci_host *host)
>  	if (host->ops->get_min_clock)
>  		mmc->f_min = host->ops->get_min_clock(host);
>  	else if (host->version >= SDHCI_SPEC_300) {
> -		if (host->clk_mul) {
> -			mmc->f_min = (host->max_clk * host->clk_mul) / 1024;
> +		if (host->clk_mul)
>  			max_clk = host->max_clk * host->clk_mul;
> -		} else
> -			mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300;
> +		/*
> +		 * Divided Clock Mode minimum clock rate is always less than
> +		 * Programmable Clock Mode minimum clock rate.
> +		 */
> +		mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300;
>  	} else
>  		mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200;
>  
> 


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

* Re: [PATCH v3] mmc: sdhci: fix minimum clock rate for v3 controller
  2020-01-15  9:54 [PATCH v3] mmc: sdhci: fix minimum clock rate for v3 controller Michał Mirosław
  2020-01-15 10:01 ` Adrian Hunter
@ 2020-01-16 14:39 ` Ulf Hansson
  1 sibling, 0 replies; 3+ messages in thread
From: Ulf Hansson @ 2020-01-16 14:39 UTC (permalink / raw)
  To: Michał Mirosław
  Cc: Adrian Hunter, linux-mmc, Linux Kernel Mailing List

On Wed, 15 Jan 2020 at 10:54, Michał Mirosław <mirq-linux@rere.qmqm.pl> wrote:
>
> For SDHCIv3+ with programmable clock mode, minimal clock frequency is
> still base clock / max(divider). Minimal programmable clock frequency is
> always greater than minimal divided clock frequency. Without this patch,
> SDHCI uses out-of-spec initial frequency when multiplier is big enough:
>
> mmc1: mmc_rescan_try_freq: trying to init card at 468750 Hz
> [for 480 MHz source clock divided by 1024]
>
> The code in sdhci_calc_clk() already chooses a correct SDCLK clock mode.
>
> Cc: stable@vger.kernel.org
> Fixes: c3ed3877625f ("mmc: sdhci: add support for programmable clock mode")
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>

Applied for fixes, thanks!

Kind regards
Uffe


> ---
>  v3: commitmsg/comment rewording
>  v2: extend commitmsg and add comment
> ---
>  drivers/mmc/host/sdhci.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index 96609c961465..24fb6d710de6 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -3903,11 +3903,13 @@ int sdhci_setup_host(struct sdhci_host *host)
>         if (host->ops->get_min_clock)
>                 mmc->f_min = host->ops->get_min_clock(host);
>         else if (host->version >= SDHCI_SPEC_300) {
> -               if (host->clk_mul) {
> -                       mmc->f_min = (host->max_clk * host->clk_mul) / 1024;
> +               if (host->clk_mul)
>                         max_clk = host->max_clk * host->clk_mul;
> -               } else
> -                       mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300;
> +               /*
> +                * Divided Clock Mode minimum clock rate is always less than
> +                * Programmable Clock Mode minimum clock rate.
> +                */
> +               mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300;
>         } else
>                 mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200;
>
> --
> 2.20.1
>

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15  9:54 [PATCH v3] mmc: sdhci: fix minimum clock rate for v3 controller Michał Mirosław
2020-01-15 10:01 ` Adrian Hunter
2020-01-16 14:39 ` Ulf Hansson

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git