Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76d7b8f1 authored by Douglas Anderson's avatar Douglas Anderson Committed by Sarthak Garg
Browse files

mmc: sdhci-msm: Actually set the actual clock

The MSM SDHCI driver always set the "actual_clock" field to 0.  It had
a comment about it not being needed because we weren't using the
standard SDHCI divider mechanism and we'd just fallback to
"host->clock".  However, it's still better to provide the actual
clock.  Why?

1. It will make timeout calculations slightly better.  On one system I
   have, the eMMC requets 200 MHz (for HS400-ES) but actually gets 192
   MHz.  These are close, but why not get the more accurate one.

2. If things are seriously off in the clock driver and it's missing
   rates or picking the wrong rate (maybe it's rounding up instead of
   down), this will make it much more obvious what's going on.

NOTE: we have to be a little careful here because the "actual_clock"
field shouldn't include the multiplier that sdhci-msm needs
internally.

Change-Id: I16f0ad021209e7a0c2797c695e972888b542246f
Git-Repo: https://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git/


Git-Commit: f16c8fd4449efb4441272af6102e55523b15a7ad
Suggested-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
Reviewed-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
Acked-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Reviewed-by: default avatarVeerabhadrarao Badiganti <vbadigan@codeaurora.org>
Signed-off-by: default avatarSarthak Garg <sartgarg@codeaurora.org>
parent 56fc9502
Loading
Loading
Loading
Loading
+16 −19
Original line number Diff line number Diff line
@@ -520,8 +520,7 @@ static void sdhci_msm_v5_variant_writel_relaxed(u32 val,
	writel_relaxed(val, host->ioaddr + offset);
}

static unsigned int msm_get_clock_rate_for_bus_mode(struct sdhci_host *host,
						    unsigned int clock)
static unsigned int msm_get_clock_mult_for_bus_mode(struct sdhci_host *host)
{
	struct mmc_ios ios = host->mmc->ios;
	/*
@@ -534,8 +533,8 @@ static unsigned int msm_get_clock_rate_for_bus_mode(struct sdhci_host *host,
	    ios.timing == MMC_TIMING_MMC_DDR52 ||
	    ios.timing == MMC_TIMING_MMC_HS400 ||
	    host->flags & SDHCI_HS400_TUNING)
		clock *= 2;
	return clock;
		return 2;
	return 1;
}

#if defined(CONFIG_SDC_QTI)
@@ -561,14 +560,16 @@ static void msm_set_clock_rate_for_bus_mode(struct sdhci_host *host,
	struct mmc_ios curr_ios = host->mmc->ios;
	struct clk *core_clk = msm_host->bulk_clks[0].clk;
	unsigned long achieved_rate;
	unsigned int desired_rate;
	unsigned int mult;
	int rc;

	clock = msm_get_clock_rate_for_bus_mode(host, clock);
	rc = clk_set_rate(core_clk, clock);
	mult = msm_get_clock_mult_for_bus_mode(host);
	desired_rate = clock * mult;
	rc = clk_set_rate(core_clk, desired_rate);
	if (rc) {
		pr_err("%s: Failed to set clock at rate %u at timing %d\n",
		       mmc_hostname(host->mmc), clock,
		       curr_ios.timing);
		       mmc_hostname(host->mmc), desired_rate, curr_ios.timing);
		return;
	}

@@ -578,11 +579,14 @@ static void msm_set_clock_rate_for_bus_mode(struct sdhci_host *host,
	 * good for SD.  Yell if we encounter it.
	 */
	achieved_rate = clk_get_rate(core_clk);
	if (achieved_rate > clock)
	if (achieved_rate > desired_rate)
		pr_debug("%s: Card appears overclocked; req %u Hz, actual %lu Hz\n",
			mmc_hostname(host->mmc), clock, achieved_rate);
			mmc_hostname(host->mmc), desired_rate, achieved_rate);
	host->mmc->actual_clock = achieved_rate / mult;

	/* Stash the rate we requested to use in sdhci_msm_runtime_resume() */
	msm_host->clk_rate = desired_rate;

	msm_host->clk_rate = clock;
	pr_debug("%s: Setting clock at rate %lu at timing %d\n",
		 mmc_hostname(host->mmc), achieved_rate, curr_ios.timing);
}
@@ -2480,13 +2484,6 @@ static unsigned int sdhci_msm_get_sup_clk_rate(struct sdhci_host *host,
static void __sdhci_msm_set_clock(struct sdhci_host *host, unsigned int clock)
{
	u16 clk;
	/*
	 * Keep actual_clock as zero -
	 * - since there is no divider used so no need of having actual_clock.
	 * - MSM controller uses SDCLK for data timeout calculation. If
	 *   actual_clock is zero, host->clock is taken for calculation.
	 */
	host->mmc->actual_clock = 0;

	sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);

@@ -2509,7 +2506,7 @@ static void sdhci_msm_set_clock(struct sdhci_host *host, unsigned int clock)
	struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);

	if (!clock) {
		msm_host->clk_rate = clock;
		host->mmc->actual_clock = msm_host->clk_rate = 0;
		goto out;
	}