U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephan Gerhold <stephan.gerhold@linaro.org>
To: Aswin Murugan <aswin.murugan@oss.qualcomm.com>
Cc: casey.connolly@linaro.org, neil.armstrong@linaro.org,
	sumit.garg@kernel.org, trini@konsulko.com, peng.fan@nxp.com,
	jh80.chung@samsung.com, tanmay.kathpalia@altera.com,
	nathbappai@gmail.com, balaji.selvanathan@oss.qualcomm.com,
	Michael.Srba@seznam.cz, u-boot-qcom@groups.io,
	u-boot@lists.u-boot-project.org
Subject: Re: [PATCH v4 2/4] mmc: msm_sdhci: add CM_DLL init and HS200 tuning support
Date: Mon, 23 Nov 2026 16:05:06 +0100	[thread overview]
Message-ID: <awRWIvN0mcOa6p_b@linaro.org> (raw)
In-Reply-To: <20261110114520.229480-3-aswin.murugan@oss.qualcomm.com>

On Tue, Nov 10, 2026 at 05:15:18PM +0530, Aswin Murugan wrote:
> Add the CM_DLL (delay-locked loop) initialization sequence and wire up
> platform_execute_tuning so the driver can perform HS200 tuning. The
> 14LPP DLL reset and Tassadar DLL variants are selected based on the
> SDCC core version, and an optional qcom,dll-config DT property can
> override the computed DLL configuration.
> 
> Signed-off-by: Aswin Murugan <aswin.murugan@oss.qualcomm.com>
> ---
>  drivers/mmc/msm_sdhci.c | 411 ++++++++++++++++++++++++++++++++++++++++
>  drivers/mmc/msm_sdhci.h |  45 +++++
>  2 files changed, 456 insertions(+)
> 
> diff --git a/drivers/mmc/msm_sdhci.c b/drivers/mmc/msm_sdhci.c
> index d7ae26c609c..23c06e8d15e 100644
> --- a/drivers/mmc/msm_sdhci.c
> +++ b/drivers/mmc/msm_sdhci.c
> [...]
> +/*
> + * Programs the MCLK_FREQ (CMUX_SHIFT_PHASE) field. Must be set before
> + * enabling CORE_DLL_EN/CORE_CK_OUT_EN, otherwise the DLL will not lock.
> + *
> + * host->clock is not updated by the generic sdhci.c, so mmc->clock is
> + * used instead.
> + */
> +static void msm_cm_dll_set_freq(struct sdhci_host *host)
> +{
> +	struct udevice *dev = host->mmc->dev;
> +	struct mmc *mmc = host->mmc;
> +	const struct msm_sdhc_variant_info *var_info =
> +		(void *)dev_get_driver_data(dev);
> +	u32 mclk_freq = 0, config;
> +	unsigned int clock = mmc->clock;
> +
> +	if (clock <= 112000000)
> +		mclk_freq = 0;
> +	else if (clock <= 125000000)
> +		mclk_freq = 1;
> +	else if (clock <= 137000000)
> +		mclk_freq = 2;
> +	else if (clock <= 150000000)
> +		mclk_freq = 3;
> +	else if (clock <= 162000000)
> +		mclk_freq = 4;
> +	else if (clock <= 175000000)
> +		mclk_freq = 5;
> +	else if (clock <= 187000000)
> +		mclk_freq = 6;
> +	else if (clock <= 200000000)
> +		mclk_freq = 7;

I'm not sure if this is correct. At the moment, the U-Boot
implementation sets the GCC clock to the maximum possible rate in
msm_sdc_clk_init(), and then relies on the internal SDHCI dividers to
get the correct clock for the MMC card.

Linux on the other hand avoids using the internal SDHCI dividers and
changes the GCC clock rate instead.

This code path needs to pick a value depending on the input clock to the
DLL. I'm not sure if the internal SDHCI dividers are applied to the DLL
input. If not, using this function as-is may result in picking the wrong
register value in U-Boot.

It's hard to make any claims about the setup with the internal SDHCI
dividers. Given that the Linux code contains the following comment:

 * MSM controller does not use internal divider and
 * instead directly control the GCC clock as per
 * HW recommendation.

I think you should prepend a patch to set the proper GCC clock rate via
clk_set_rate() and make sure the internal SDHCI dividers are disabled.

> +
> +	config = readl(host->ioaddr + var_info->core_dll_config);
> +	config &= ~CMUX_SHIFT_PHASE_MASK;
> +	config |= mclk_freq << CMUX_SHIFT_PHASE_SHIFT;
> +	writel(config, host->ioaddr + var_info->core_dll_config);
> +}
> +
> [...]
> +/* CM_DLL initialization sequence */
> +static int msm_init_cm_dll(struct sdhci_host *host)
> +{
> +	struct udevice *dev = host->mmc->dev;
> +	struct msm_sdhc *priv = dev_get_priv(dev);
> +	const struct msm_sdhc_variant_info *var_info =
> +		(void *)dev_get_driver_data(dev);
> +	u32 config;
> +	int ret;
> +
> +	/*
> +	 * Keep the clock enabled while DLL tuning is in progress; PWRSAVE
> +	 * may otherwise turn it off.
> +	 */
> +	config = readl(host->ioaddr + var_info->core_vendor_spec);
> +	config &= ~CORE_CLK_PWRSAVE;
> +	writel(config, host->ioaddr + var_info->core_vendor_spec);
> +
> +	if (priv->dll_config)
> +		writel(priv->dll_config, host->ioaddr + var_info->core_dll_config);
> +
> +	if (priv->use_14lpp_dll_reset) {
> +		config = readl(host->ioaddr + var_info->core_dll_config);
> +		config &= ~CORE_CK_OUT_EN;
> +		writel(config, host->ioaddr + var_info->core_dll_config);
> +
> +		if (var_info->core_dll_config_2) {
> +			config = readl(host->ioaddr + var_info->core_dll_config_2);
> +			config |= CORE_DLL_CLOCK_DISABLE;
> +			writel(config, host->ioaddr + var_info->core_dll_config_2);
> +		}
> +	}
> +
> +	config = readl(host->ioaddr + var_info->core_dll_config);
> +	config |= CORE_DLL_RST;
> +	writel(config, host->ioaddr + var_info->core_dll_config);
> +
> +	config = readl(host->ioaddr + var_info->core_dll_config);
> +	config |= CORE_DLL_PDN;
> +	writel(config, host->ioaddr + var_info->core_dll_config);
> +
> +	/*
> +	 * MCLK_FREQ must be programmed while the DLL is reset and powered
> +	 * down, unless a DT dll-config override is in effect.
> +	 */
> +	if (!priv->dll_config)
> +		msm_cm_dll_set_freq(host);

CORE_FLL_CYCLE_CNT part is missing here for the
priv->use_14lpp_dll_reset case, which is strange because this seems to
be pretty much an exact copy of the Linux source code otherwise.

Did you omit it on purpose?

> +
> +	config = readl(host->ioaddr + var_info->core_dll_config);
> +	config &= ~CORE_DLL_RST;
> +	writel(config, host->ioaddr + var_info->core_dll_config);
> +
> +	config = readl(host->ioaddr + var_info->core_dll_config);
> +	config &= ~CORE_DLL_PDN;
> +	writel(config, host->ioaddr + var_info->core_dll_config);
> +
> +	if (priv->use_14lpp_dll_reset) {
> +		if (!priv->dll_config)
> +			msm_cm_dll_set_freq(host);
> +
> +		if (var_info->core_dll_config_2) {
> +			config = readl(host->ioaddr + var_info->core_dll_config_2);
> +			config &= ~CORE_DLL_CLOCK_DISABLE;
> +			writel(config, host->ioaddr + var_info->core_dll_config_2);
> +		}
> +	}
> +
> +	/* Applicable to SDCC v5.1 onwards only */
> +	if (priv->uses_tassadar_dll && var_info->core_dll_usr_ctl) {
> +		config = DLL_USR_CTL_POR_VAL | FINE_TUNE_MODE_EN |
> +			 ENABLE_DLL_LOCK_STATUS | BIAS_OK_SIGNAL;
> +		writel(config, host->ioaddr + var_info->core_dll_usr_ctl);
> +
> +		if (var_info->core_dll_config_3) {

These extra checks feel redundant. I wouldn't expect a v4 that lacks
this to have priv->uses_tassadar_dll set.

> +			config = readl(host->ioaddr + var_info->core_dll_config_3);
> +			config &= ~0xFF;
> +			if (host->mmc->clock < 150000000)

Linux checks msm_host->clk_rate here, which is not the same as
host->mmc->clock (also see my comment above about the U-Boot clock
setup).

> +				config |= DLL_CONFIG_3_LOW_FREQ_VAL;
> +			else
> +				config |= DLL_CONFIG_3_HIGH_FREQ_VAL;
> +			writel(config, host->ioaddr + var_info->core_dll_config_3);
> +		}
> +	}
> +
> +	config = readl(host->ioaddr + var_info->core_dll_config);
> +	config |= CORE_DLL_EN;
> +	writel(config, host->ioaddr + var_info->core_dll_config);
> +
> +	config = readl(host->ioaddr + var_info->core_dll_config);
> +	config |= CORE_CK_OUT_EN;
> +	writel(config, host->ioaddr + var_info->core_dll_config);
> +
> +	ret = msm_dll_poll_lock_status(host);
> +	if (ret)
> +		return ret;
> +
> +	config = readl(host->ioaddr + var_info->core_dll_config);
> +	config |= CORE_CDR_EN;
> +	config &= ~CORE_CDR_EXT_EN;
> +	writel(config, host->ioaddr + var_info->core_dll_config);

I think you need to clear this again later somewhere for write commands,
see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a89e7bcb18081c611eb6cf50edd440fa4983a71a

> +
> +	priv->calibration_done = false;
> +
> +	return 0;
> +}
> +
> +static int msm_find_most_appropriate_phase(struct sdhci_host *host,
> +					   u8 *phase_table,
> +					   u8 total_phases)
> +{
> +	int ret;
> +	u8 ranges[MAX_PHASES][MAX_PHASES] = { {0}, {0} };
> +	u8 phases_per_row[MAX_PHASES] = { 0 };
> +	int row_index = 0, col_index = 0, selected_row_index = 0;
> +	int i, longest_range_len = 0;
> +	bool found = false;
> +
> +	if (!total_phases || total_phases > MAX_PHASES) {
> +		printf("%s: Invalid argument: total_phases=%d\n",
> +		       host->name, total_phases);
> +		return -EINVAL;
> +	}
> +
> +	for (i = 0; i < total_phases; i++) {
> +		ranges[row_index][col_index] = phase_table[i];
> +		phases_per_row[row_index] += 1;
> +		col_index++;
> +
> +		if ((i + 1) == total_phases)
> +			continue;
> +
> +		if (phase_table[i] + 1 != phase_table[i + 1]) {
> +			row_index++;
> +			col_index = 0;
> +		}
> +	}
> +
> +	if (row_index == 0) {
> +		ret = phase_table[total_phases / 2];
> +		goto exit;
> +	}
> +
> +	for (i = 0; i <= row_index; i++) {
> +		if (phases_per_row[i] > longest_range_len) {
> +			longest_range_len = phases_per_row[i];
> +			selected_row_index = i;
> +			found = true;
> +		}
> +	}
> +
> +	if (found) {
> +		ret = ranges[selected_row_index][longest_range_len / 2];
> +	} else {
> +		ret = -EIO;
> +		printf("%s: Failed to find a valid phase\n", host->name);
> +	}
> +
> +exit:
> +	return ret;
> +}

This looks similar to the Linux implementation, but then some minor
implementation details differ and the phase selection is not the same.
Did you implement this differently on purpose?

Thanks,
Stephan

  reply	other threads:[~2026-11-23 15:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 11:45 [PATCH v4 0/4] qcom: Enable HS200/HS400 eMMC modes on Qualcomm platforms Aswin Murugan
2026-11-10 11:45 ` [PATCH v4 1/4] mmc: msm_sdhci: move definitions to msm_sdhci.h Aswin Murugan
2026-11-10 11:45 ` [PATCH v4 2/4] mmc: msm_sdhci: add CM_DLL init and HS200 tuning support Aswin Murugan
2026-11-23 15:05   ` Stephan Gerhold [this message]
2026-11-10 11:45 ` [PATCH v4 3/4] mmc: msm_sdhci: add HS400 DDR/SDC4 DLL calibration Aswin Murugan
2026-11-23 15:06   ` Stephan Gerhold
2026-11-10 11:45 ` [PATCH v4 4/4] configs: qcom: enable CONFIG_MMC_HS400_SUPPORT Aswin Murugan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awRWIvN0mcOa6p_b@linaro.org \
    --to=stephan.gerhold@linaro.org \
    --cc=Michael.Srba@seznam.cz \
    --cc=aswin.murugan@oss.qualcomm.com \
    --cc=balaji.selvanathan@oss.qualcomm.com \
    --cc=casey.connolly@linaro.org \
    --cc=jh80.chung@samsung.com \
    --cc=nathbappai@gmail.com \
    --cc=neil.armstrong@linaro.org \
    --cc=peng.fan@nxp.com \
    --cc=sumit.garg@kernel.org \
    --cc=tanmay.kathpalia@altera.com \
    --cc=trini@konsulko.com \
    --cc=u-boot-qcom@groups.io \
    --cc=u-boot@lists.u-boot-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox