mmc: sdhci: clarify the get_timeout_clock callback
authorShawn Lin <shawn.lin@rock-chips.com>
Fri, 24 Mar 2017 07:50:12 +0000 (15:50 +0800)
committerUlf Hansson <ulf.hansson@linaro.org>
Mon, 24 Apr 2017 19:41:48 +0000 (21:41 +0200)
Currently the get_timeout_clock callback doesn't clearly
have a statement that it needs the variant drivers to return
the timeout clock rate in kHz if the SDHCI_TIMEOUT_CLK_UNIT
isn't present, otherwise the variant drivers should return it
in MHz. It's also very likely that further variant drivers which
are going to use this callback will be confused by this situation.
Given the fact that moderm sdhci variant hosts are very prone to get
the timeout clock from common clock framework (actually the only three
users did that), it's more natural to return the value in Hz and we
make an explicit comment there. Then we put the unit conversion inside
the sdhci core. Thus will improve the code and prevent further misuses.

Reported-by: Anssi Hannula <anssi.hannula@bitwise.fi>
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
Acked-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/mmc/host/sdhci-cadence.c
drivers/mmc/host/sdhci-of-arasan.c
drivers/mmc/host/sdhci.c
drivers/mmc/host/sdhci.h

index 48f641953844ff8749ff929330a4985f3469e056..07a27dcb42be783d62940f4d07f2b80e69acb047 100644 (file)
@@ -105,9 +105,9 @@ static unsigned int sdhci_cdns_get_timeout_clock(struct sdhci_host *host)
 {
        /*
         * Cadence's spec says the Timeout Clock Frequency is the same as the
-        * Base Clock Frequency.  Divide it by 1000 to return a value in kHz.
+        * Base Clock Frequency.
         */
-       return host->max_clk / 1000;
+       return host->max_clk;
 }
 
 static void sdhci_cdns_set_emmc_mode(struct sdhci_cdns_priv *priv, u32 mode)
index 61accf0d4739215be4a46e6a43d4a869435fc92b..ea6b36c88ae7403b260eb375d1f7d33a33dd5050 100644 (file)
@@ -157,21 +157,6 @@ static int sdhci_arasan_syscon_write(struct sdhci_host *host,
        return ret;
 }
 
-static unsigned int sdhci_arasan_get_timeout_clock(struct sdhci_host *host)
-{
-       unsigned long freq;
-       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
-
-       /* SDHCI timeout clock is in kHz */
-       freq = DIV_ROUND_UP(clk_get_rate(pltfm_host->clk), 1000);
-
-       /* or in MHz */
-       if (host->caps & SDHCI_TIMEOUT_CLK_UNIT)
-               freq = DIV_ROUND_UP(freq, 1000);
-
-       return freq;
-}
-
 static void sdhci_arasan_set_clock(struct sdhci_host *host, unsigned int clock)
 {
        struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
@@ -280,7 +265,7 @@ static int sdhci_arasan_voltage_switch(struct mmc_host *mmc,
 static struct sdhci_ops sdhci_arasan_ops = {
        .set_clock = sdhci_arasan_set_clock,
        .get_max_clock = sdhci_pltfm_clk_get_max_clock,
-       .get_timeout_clock = sdhci_arasan_get_timeout_clock,
+       .get_timeout_clock = sdhci_pltfm_clk_get_max_clock,
        .set_bus_width = sdhci_set_bus_width,
        .reset = sdhci_arasan_reset,
        .set_uhs_signaling = sdhci_set_uhs_signaling,
index a971fcfa6de7066db9ae9e3c3c83509b452a8513..147df8bcc231e70f8bf67f1f4f002a18d91e2bc0 100644 (file)
@@ -3396,20 +3396,22 @@ int sdhci_setup_host(struct sdhci_host *host)
        if (!(host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)) {
                host->timeout_clk = (host->caps & SDHCI_TIMEOUT_CLK_MASK) >>
                                        SDHCI_TIMEOUT_CLK_SHIFT;
+
+               if (host->caps & SDHCI_TIMEOUT_CLK_UNIT)
+                       host->timeout_clk *= 1000;
+
                if (host->timeout_clk == 0) {
-                       if (host->ops->get_timeout_clock) {
-                               host->timeout_clk =
-                                       host->ops->get_timeout_clock(host);
-                       } else {
+                       if (!host->ops->get_timeout_clock) {
                                pr_err("%s: Hardware doesn't specify timeout clock frequency.\n",
                                        mmc_hostname(mmc));
                                ret = -ENODEV;
                                goto undma;
                        }
-               }
 
-               if (host->caps & SDHCI_TIMEOUT_CLK_UNIT)
-                       host->timeout_clk *= 1000;
+                       host->timeout_clk =
+                               DIV_ROUND_UP(host->ops->get_timeout_clock(host),
+                                            1000);
+               }
 
                if (override_timeout_clk)
                        host->timeout_clk = override_timeout_clk;
index 35b41da0a6366af962ae2f7752a9b3a345929081..fdb5d7e1911f85386e9a0f36d42b7986703d5e30 100644 (file)
@@ -561,6 +561,7 @@ struct sdhci_ops {
        int             (*enable_dma)(struct sdhci_host *host);
        unsigned int    (*get_max_clock)(struct sdhci_host *host);
        unsigned int    (*get_min_clock)(struct sdhci_host *host);
+       /* get_timeout_clock should return clk rate in unit of Hz */
        unsigned int    (*get_timeout_clock)(struct sdhci_host *host);
        unsigned int    (*get_max_timeout_count)(struct sdhci_host *host);
        void            (*set_timeout)(struct sdhci_host *host,