[PATCH v4 3/3] mmc: sdhci-cadence6: tune SD6HC DDR50/DDR52 read path
From: tze . yee . ng
Date: Thu Nov 19 2026 - 04:46:13 EST
From: Tze Yee Ng <tze.yee.ng@xxxxxxxxxx>
DDR50 and DDR52 have no CMD19 tuning, so the SD6HC extended-read path
relies on static PHY settings. Two things are needed to make it work.
First, PHONY_DQS_TIMING (phy_ctrl_reg[9:4]) was left at 0 in every mode.
In extended-read mode the RE# (rebar) pulse is held high for half an
SDCLK period, so its width in clk_phy (sdmclk) cycles is the SDCLK/sdmclk
divider / 2, and the field must hold that width minus 1 (0 otherwise).
Leaving it at 0 in extended-read DDR duplicates one DDR edge and corrupts
reads. Derive the width from the clock divider so it tracks the
integration rather than a hard-coded value: e.g. 1 at divide-by-4,
confirmed on DDR50 hardware where 1 captures both beats and 0 corrupts
reads. The field only takes effect when the fabricated phony DQS is
selected, so the computed value is written in every extended-read mode
and clamped to the 6-bit field. This timing model follows the Cadence
SD6HC PHY documentation.
Second, the remaining read-path knobs need board/SoC characterisation, so
read them from device tree at PHY probe and apply them in the
extended-read DDR modes (DDR50 and DDR52):
- cdns,ddr-read-dqs-delay: read-DQS delay as a count of DLL delay
elements (each cdns,delay-element-ps wide), written to the 8-bit PHY
field (0-255);
- cdns,ddr-no-lpbk-dqs: fall back from the recommended loopback DQS to
the fabricated phony DQS.
Signed-off-by: Tze Yee Ng <tze.yee.ng@xxxxxxxxxx>
---
Changes in v4:
- Merged v3 2/4 (PHONY_DQS_TIMING) and v3 4/4 (read DDR tuning from
device tree)
- Derive the PHONY_DQS_TIMING rebar pulse width from the
SDCLK/sdmclk divider (t_sdclk / (2 * t_sdmclk) - 1, clamped to the 6-bit
field) instead of the hard-coded 2 clk_phy cycles, and apply it in every
extended-read mode instead of only DDR50/DDR52.
- Dropped the cdns,ddr-phony-dqs-timing override.
- Stored ddr_read_dqs_delay as u8.
- Dropped Adrian's Acked-by from v3 2/4 since the patch was merged and
substantially reworked
Changes in v3:
- Read cdns,ddr-read-dqs-delay directly as the delay-element count and
write it to the 8-bit PHY field; dropped the ps->element conversion
(divide by cdns,delay-element-ps) and the FIELD_MAX() clamp.
(Krzysztof Kozlowski)
- Hoisted the repeated DDR-mode test to a local bool. (Adrian Hunter)
- Removed the probe-time dev_warn() that validated the firmware value.
(Adrian Hunter)
- Unwrapped the of_property_read_u32() call to 100 columns.
(Adrian Hunter)
Changes in v2:
- Updated patch title to "mmc: sdhci-cadence6:" since it touches only the
v6 PHY.
- Renamed the properties to cdns,ddr-*.
- Read cdns,ddr-read-dqs-delay-ps in ps and convert it to delay elements
(dividing by cdns,delay-element-ps), clamping that quotient to the 8-bit
PHY field. (Krzysztof Kozlowski)
- Read cdns,ddr-no-lpbk-dqs via of_property_read_bool().
(Krzysztof Kozlowski)
- Dropped the v1 per-property range checks and redundant FIELD_MAX() write
masks. (Adrian Hunter)
- Apply the overrides in both DDR50 and DDR52.
---
drivers/mmc/host/sdhci-cadence-phy-v6.c | 52 ++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/host/sdhci-cadence-phy-v6.c b/drivers/mmc/host/sdhci-cadence-phy-v6.c
index 22d56bb46d75..f3a878e86f9b 100644
--- a/drivers/mmc/host/sdhci-cadence-phy-v6.c
+++ b/drivers/mmc/host/sdhci-cadence-phy-v6.c
@@ -126,6 +126,10 @@ struct sdhci_cdns6_phy {
/* Active delay element (ps); doubled when one SDMCLK requires > 256 steps */
u32 delay_element;
+ /* DDR read-path overrides (SoC-specific) */
+ u8 ddr_read_dqs_delay;
+ bool ddr_no_lpbk_dqs;
+
/* PHY_DLL_SLAVE_CTRL register fields */
u8 cp_read_dqs_cmd_delay; /* bits [31:24] */
u8 cp_clk_wrdqs_delay; /* bits [23:16] */
@@ -142,6 +146,10 @@ struct sdhci_cdns6_phy {
/* PHY_DQS_TIMING register fields */
bool cp_use_phony_dqs; /* bit [20] */
bool cp_use_phony_dqs_cmd; /* bit [19] */
+ bool cp_use_lpbk_dqs; /* bit [21] */
+
+ /* PHY_CTRL register fields */
+ u8 cp_phony_dqs_timing; /* bits [9:4] */
/* HRS07 register - IO delay Information */
u8 sdhc_rw_compensate; /* bits [20:16] */
@@ -505,6 +513,7 @@ static void sdhci_cdns6_phy_calc_dat_in(struct sdhci_cdns6_phy *phy)
{
u32 hcsdclkadj = 0;
bool strobe_dat = (phy->mode == MMC_TIMING_MMC_HS400);
+ bool ddr = (phy->mode == MMC_TIMING_UHS_DDR50 || phy->mode == MMC_TIMING_MMC_DDR52);
if (strobe_dat) {
phy->cp_use_phony_dqs = false;
@@ -517,6 +526,33 @@ static void sdhci_cdns6_phy_calc_dat_in(struct sdhci_cdns6_phy *phy)
if (phy->mode == MMC_TIMING_MMC_HS200)
phy->cp_read_dqs_delay = phy->hs200_tune_val;
+ if (ddr && phy->ddr_read_dqs_delay)
+ phy->cp_read_dqs_delay = phy->ddr_read_dqs_delay;
+
+ phy->cp_use_lpbk_dqs = true;
+
+ /*
+ * In extended-read mode the RE# (rebar) pulse is held high for half an
+ * SDCLK period, so its width in clk_phy (sdmclk) cycles equals half the
+ * SDCLK/sdmclk divider. PHONY_DQS_TIMING holds that width minus one.
+ */
+ if (phy->sdhc_extended_rd_mode) {
+ u32 rebar_cycles = phy->t_sdclk / (2 * phy->t_sdmclk);
+
+ phy->cp_phony_dqs_timing = rebar_cycles ?
+ min_t(u32, rebar_cycles - 1,
+ FIELD_MAX(SDHCI_CDNS6_PHY_CTRL_PHONY_DQS_TIMING)) : 0;
+ } else {
+ phy->cp_phony_dqs_timing = 0;
+ }
+
+ /*
+ * Loopback DQS is the recommended read-capture path; allow boards that
+ * need the fabricated phony DQS instead to opt out in the DDR modes.
+ */
+ if (ddr && phy->ddr_no_lpbk_dqs)
+ phy->cp_use_lpbk_dqs = false;
+
if (strobe_dat) {
/* dqs loopback input via IO cell */
hcsdclkadj += phy->iocell_input_delay;
@@ -680,10 +716,11 @@ int sdhci_cdns6_phy_init(struct sdhci_cdns_priv *priv)
sdhci_cdns6_dll_reset(priv, true);
reg = sdhci_cdns6_read_phy_reg(priv, SDHCI_CDNS6_PHY_DQS_TIMING_REG);
+ reg &= ~SDHCI_CDNS6_PHY_DQS_TIMING_USE_LPBK_DQS;
reg &= ~SDHCI_CDNS6_PHY_DQS_TIMING_USE_PHONY_DQS;
reg &= ~SDHCI_CDNS6_PHY_DQS_TIMING_USE_PHONY_DQS_CMD;
reg |= SDHCI_CDNS6_PHY_DQS_TIMING_USE_EXT_LPBK_DQS;
- reg |= SDHCI_CDNS6_PHY_DQS_TIMING_USE_LPBK_DQS;
+ reg |= FIELD_PREP(SDHCI_CDNS6_PHY_DQS_TIMING_USE_LPBK_DQS, phy->cp_use_lpbk_dqs);
reg |= FIELD_PREP(SDHCI_CDNS6_PHY_DQS_TIMING_USE_PHONY_DQS, phy->cp_use_phony_dqs);
reg |= FIELD_PREP(SDHCI_CDNS6_PHY_DQS_TIMING_USE_PHONY_DQS_CMD, phy->cp_use_phony_dqs_cmd);
sdhci_cdns6_write_phy_reg(priv, SDHCI_CDNS6_PHY_DQS_TIMING_REG, reg);
@@ -715,6 +752,8 @@ int sdhci_cdns6_phy_init(struct sdhci_cdns_priv *priv)
reg = sdhci_cdns6_read_phy_reg(priv, SDHCI_CDNS6_PHY_CTRL_REG);
reg &= ~SDHCI_CDNS6_PHY_CTRL_PHONY_DQS_TIMING;
+ reg |= FIELD_PREP(SDHCI_CDNS6_PHY_CTRL_PHONY_DQS_TIMING,
+ phy->cp_phony_dqs_timing);
sdhci_cdns6_write_phy_reg(priv, SDHCI_CDNS6_PHY_CTRL_REG, reg);
/*
@@ -863,6 +902,7 @@ int sdhci_cdns6_phy_probe(struct platform_device *pdev, struct sdhci_cdns_priv *
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct sdhci_cdns6_phy *phy;
unsigned long val;
+ u32 read_dqs_delay;
int ret;
phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
@@ -901,6 +941,16 @@ int sdhci_cdns6_phy_probe(struct platform_device *pdev, struct sdhci_cdns_priv *
phy->delay_element_org = phy->delay_element;
+ /*
+ * Optional read-path tuning for the extended-read DDR modes (SD DDR50,
+ * eMMC DDR52).
+ */
+ phy->ddr_read_dqs_delay = 0;
+ if (!of_property_read_u32(dev->of_node, "cdns,ddr-read-dqs-delay", &read_dqs_delay))
+ phy->ddr_read_dqs_delay = read_dqs_delay;
+
+ phy->ddr_no_lpbk_dqs = of_property_read_bool(dev->of_node, "cdns,ddr-no-lpbk-dqs");
+
priv->phy = phy;
return 0;
--
2.43.7