diff mbox series

mmc: sdhci-msm: Warn about overclocking SD/MMC

Message ID 20201210125709.1.Iec3430c7d3c2a29262695edef7b82a14aaa567e5@changeid (mailing list archive)
State New, archived
Headers show
Series mmc: sdhci-msm: Warn about overclocking SD/MMC | expand

Commit Message

Douglas Anderson Dec. 10, 2020, 8:57 p.m. UTC
As talked about in commit 5e4b7e82d497 ("clk: qcom: gcc-sdm845: Use
floor ops for sdcc clks"), most clocks handled by the Qualcomm clock
drivers are rounded _up_ by default instead of down.  We should make
sure SD/MMC clocks are always rounded down in the clock drivers.
Let's add a warning in the Qualcomm SDHCI driver to help catch the
problem.

This would have saved a bunch of time [1].

[1] http://lore.kernel.org/r/20201210102234.1.I096779f219625148900fc984dd0084ed1ba87c7f@changeid

Suggested-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

 drivers/mmc/host/sdhci-msm.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Stephen Boyd Dec. 10, 2020, 9:03 p.m. UTC | #1
Quoting Douglas Anderson (2020-12-10 12:57:25)
> diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
> index 3451eb325513..dd41f6a4dbfb 100644
> --- a/drivers/mmc/host/sdhci-msm.c
> +++ b/drivers/mmc/host/sdhci-msm.c
> @@ -353,6 +353,7 @@ static void msm_set_clock_rate_for_bus_mode(struct sdhci_host *host,
>         struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
>         struct mmc_ios curr_ios = host->mmc->ios;
>         struct clk *core_clk = msm_host->bulk_clks[0].clk;
> +       unsigned int achieved_rate;

unsigned long?

>         int rc;
>  
>         clock = msm_get_clock_rate_for_bus_mode(host, clock);
> @@ -363,6 +364,17 @@ static void msm_set_clock_rate_for_bus_mode(struct sdhci_host *host,
>                        curr_ios.timing);
>                 return;
>         }
> +
> +       /*
> +        * Qualcomm clock drivers by default round clock _up_ if they can't
> +        * make the requested rate.  This is not good for SD.  Yell if we
> +        * encounter it.
> +        */
> +       achieved_rate = clk_get_rate(core_clk);
> +       if (achieved_rate > clock)
> +               pr_warn("%s: Card appears overclocked; req %u Hz, actual %d Hz\n",

Can we use dev_warn?

dev_warn(mmc_dev(mmc)
dev_warn(&msm_host->pdev->dev

?

> +                       mmc_hostname(host->mmc), clock, achieved_rate);
> +
>         msm_host->clk_rate = clock;
>         pr_debug("%s: Setting clock at rate %lu at timing %d\n",
>                  mmc_hostname(host->mmc), clk_get_rate(core_clk),

This could use achieved_rate now.
Douglas Anderson Dec. 10, 2020, 9:20 p.m. UTC | #2
Hi,

On Thu, Dec 10, 2020 at 1:03 PM Stephen Boyd <swboyd@chromium.org> wrote:
>
> Quoting Douglas Anderson (2020-12-10 12:57:25)
> > diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
> > index 3451eb325513..dd41f6a4dbfb 100644
> > --- a/drivers/mmc/host/sdhci-msm.c
> > +++ b/drivers/mmc/host/sdhci-msm.c
> > @@ -353,6 +353,7 @@ static void msm_set_clock_rate_for_bus_mode(struct sdhci_host *host,
> >         struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
> >         struct mmc_ios curr_ios = host->mmc->ios;
> >         struct clk *core_clk = msm_host->bulk_clks[0].clk;
> > +       unsigned int achieved_rate;
>
> unsigned long?

I'm matching the type for the parameter.  ...but I guess you're right
that it's better to match clk_get_rate().

NOTE: I'm _not_ planning to change the parameter because it matches
the type in 'struct mmc_ios' and that feels like a much bigger change
to tweak.


> >         int rc;
> >
> >         clock = msm_get_clock_rate_for_bus_mode(host, clock);
> > @@ -363,6 +364,17 @@ static void msm_set_clock_rate_for_bus_mode(struct sdhci_host *host,
> >                        curr_ios.timing);
> >                 return;
> >         }
> > +
> > +       /*
> > +        * Qualcomm clock drivers by default round clock _up_ if they can't
> > +        * make the requested rate.  This is not good for SD.  Yell if we
> > +        * encounter it.
> > +        */
> > +       achieved_rate = clk_get_rate(core_clk);
> > +       if (achieved_rate > clock)
> > +               pr_warn("%s: Card appears overclocked; req %u Hz, actual %d Hz\n",
>
> Can we use dev_warn?

What's here matches other prints including other ones in the same
function and in much of the MMC subsystem.  mmc_hostname() shows
"mmc1"

> dev_warn(mmc_dev(mmc)
> dev_warn(&msm_host->pdev->dev

This show "sdhci_msm 7c4000.sdhci"

I'm going to keep with tradition and keep using mmc_hostname().  In
some parts of this file they use both (a dev_warn that also includes
the mmc_hostname()) but that feels overkill.

> ?
>
> > +                       mmc_hostname(host->mmc), clock, achieved_rate);
> > +
> >         msm_host->clk_rate = clock;
> >         pr_debug("%s: Setting clock at rate %lu at timing %d\n",
> >                  mmc_hostname(host->mmc), clk_get_rate(core_clk),
>
> This could use achieved_rate now.

Sure.

I sent up a real quick v2 since it seemed like these were small fixes
and maybe this was all good otherwise.


-Doug
Stephen Boyd Dec. 10, 2020, 9:25 p.m. UTC | #3
Quoting Doug Anderson (2020-12-10 13:20:03)
> On Thu, Dec 10, 2020 at 1:03 PM Stephen Boyd <swboyd@chromium.org> wrote:
> >
> >
> > Can we use dev_warn?
> 
> What's here matches other prints including other ones in the same
> function and in much of the MMC subsystem.  mmc_hostname() shows
> "mmc1"
> 
> > dev_warn(mmc_dev(mmc)
> > dev_warn(&msm_host->pdev->dev
> 
> This show "sdhci_msm 7c4000.sdhci"
> 
> I'm going to keep with tradition and keep using mmc_hostname().  In
> some parts of this file they use both (a dev_warn that also includes
> the mmc_hostname()) but that feels overkill.

Ok. This driver should be cleaned up I suppose.
diff mbox series

Patch

diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
index 3451eb325513..dd41f6a4dbfb 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -353,6 +353,7 @@  static void msm_set_clock_rate_for_bus_mode(struct sdhci_host *host,
 	struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
 	struct mmc_ios curr_ios = host->mmc->ios;
 	struct clk *core_clk = msm_host->bulk_clks[0].clk;
+	unsigned int achieved_rate;
 	int rc;
 
 	clock = msm_get_clock_rate_for_bus_mode(host, clock);
@@ -363,6 +364,17 @@  static void msm_set_clock_rate_for_bus_mode(struct sdhci_host *host,
 		       curr_ios.timing);
 		return;
 	}
+
+	/*
+	 * Qualcomm clock drivers by default round clock _up_ if they can't
+	 * make the requested rate.  This is not good for SD.  Yell if we
+	 * encounter it.
+	 */
+	achieved_rate = clk_get_rate(core_clk);
+	if (achieved_rate > clock)
+		pr_warn("%s: Card appears overclocked; req %u Hz, actual %d Hz\n",
+			mmc_hostname(host->mmc), clock, achieved_rate);
+
 	msm_host->clk_rate = clock;
 	pr_debug("%s: Setting clock at rate %lu at timing %d\n",
 		 mmc_hostname(host->mmc), clk_get_rate(core_clk),