Re: [PATCH v3 4/4] mmc: sdhci-cadence6: read SD6HC DDR50 tuning from device tree
From: NG, TZE YEE
Date: Wed Nov 18 2026 - 06:02:03 EST
Hi Tanmay,
Thanks for the review.
On 16/11/2026 2:47 am, Kathpalia, Tanmay wrote:
On 06-11-2026 11:46, tze.yee.ng@xxxxxxxxxx wrote:
From: Tze Yee Ng <tze.yee.ng@xxxxxxxxxx>
DDR50 has no CMD19 tuning, so the SD6HC read path relies on static PHY
settings that need board/SoC characterisation. Read the read-DQS delay,
Nit: the subject and this line say DDR50, but DDR52 is covered too.
I will name both DDR50 and DDR52.
read-DQS source and phony DQS assertion timing from the new
cdns,ddr-read-dqs-delay, cdns,ddr-no-lpbk-dqs and
cdns,ddr-phony-dqs-timing DT properties at PHY probe and apply them in
the extended-read DDR modes (DDR50 and DDR52). The read-DQS delay is a
count of DLL delay elements (each cdns,delay-element-ps wide) written
directly to the 8-bit PHY field (0-255).
Loopback DQS is the recommended read-capture path and stays the default;
cdns,ddr-no-lpbk-dqs lets a board fall back to the fabricated phony DQS.
When a property is absent the driver-computed value is kept - for the
phony DQS timing, the value derived from the RE# pulse width
(REBAR_PULSE_CYCLES-1).
The Cadence guide gives no rebar pulse width. It has only the formula and an example
of 4 (field value 3). The 2 is your measurement at SDMCLK 200 MHz and SDCLK 50 MHz, so it should not
be an unexplained constant in the common driver. Please see my comment on the override below.
Agreed. I wil drop the the SDHCI_CDNS6_PHY_REBAR_PULSE_CYCLES constant and derives the field from the live clocks instead:
/*
* In extended-read mode the RE# pulse is held high for half an
* SDCLK period, so its width in SDMCLK cycles is half the
* SDCLK/SDMCLK divider; the field 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;
}
There is no magic number now: the field value comes from the phony DQS timing formula in the Cadence PHY guide (cdn_ip6185) applied to the live clocks. The guide defines the RE# pulse as half an SDCLK period, so its width in SDMCLK cycles is half the SDCLK/SDMCLK divider and the
field holds that width minus one. The guide's own worked example (pulse width 4 -> field 3) is the divide-by-8 case; the divide-by-4 case at SDMCLK 200 MHz / SDCLK 50 MHz gives width 2 -> field 1, which is also what we saw on hardware (field 1 captures both DDR beats, 0 corrupts reads). Both lie on width = divider / 2, so the driver derives the field from t_sdclk / t_sdmclk rather than carrying a fixed value.
Signed-off-by: Tze Yee Ng <tze.yee.ng@xxxxxxxxxx>
---
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 | 48 +++++++++++++++++++++++ +++++++---
1 file changed, 44 insertions(+), 4 deletions(-)
diff --git a/drivers/mmc/host/sdhci-cadence-phy-v6.c b/drivers/mmc/ host/sdhci-cadence-phy-v6.c
index 8d6a9c26c139..d905e39d4b6f 100644
--- a/drivers/mmc/host/sdhci-cadence-phy-v6.c
+++ b/drivers/mmc/host/sdhci-cadence-phy-v6.c
@@ -129,6 +129,11 @@ struct sdhci_cdns6_phy {
/* Active delay element (ps); doubled when one SDMCLK requires > 256 steps */
u32 delay_element;
+ /* DDR read-path overrides (SoC-specific) */
+ u32 ddr_read_dqs_delay;
+ bool ddr_no_lpbk_dqs;
+ s32 ddr_phony_dqs_timing;
+
ddr_read_dqs_delay should be u8 (it maps to cp_read_dqs_delay, u8 bits [7:0]).
Same for ddr_phony_dqs_timing.
I will change it to u8 bits.
/* PHY_DLL_SLAVE_CTRL register fields */
u8 cp_read_dqs_cmd_delay; /* bits [31:24] */
u8 cp_clk_wrdqs_delay; /* bits [23:16] */
@@ -145,6 +150,7 @@ 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 */
u32 cp_phony_dqs_timing;
@@ -511,6 +517,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);
Patch 2 already tests the DDR modes, so please add this local in patch 2.
Then patch 4 does not rewrite lines that patch 2 added.
I'll fold patch 2 (the PHONY_DQS_TIMING programming) into this patch. It has no standalone effect, where loopback DQS is force-selected until this patch adds the opt-out, so the field is muxed out on its own. Merging keeps the DDR local and the timing programming in one patch with no cross-patch rewrite.
if (strobe_dat) {
phy->cp_use_phony_dqs = false;
@@ -523,13 +530,31 @@ 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 (phy->sdhc_extended_rd_mode &&
- (phy->mode == MMC_TIMING_UHS_DDR50 ||
- phy->mode == MMC_TIMING_MMC_DDR52))
+ if (ddr && phy->ddr_read_dqs_delay)
+ phy->cp_read_dqs_delay = phy->ddr_read_dqs_delay;
+
+ phy->cp_use_lpbk_dqs = 1;
+
+ if (phy->sdhc_extended_rd_mode && ddr)
phy->cp_phony_dqs_timing = SDHCI_CDNS6_PHY_REBAR_PULSE_CYCLES - 1;
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 = 0;
Nit: true/false, like the other cp_use_* fields (also for the = 0 below).
Will use true/false.
+
+ /*
+ * The computed phony DQS timing above is derived from the RE# pulse
+ * width. Allow a DT override for boards whose flight time shifts the
+ * returning DDR data relative to the fabricated strobe.
+ */
Please drop phony DQS timing override. The PHY guide sets this field from the rebar pulse
width, not from the board flight time. Board delay belongs in the read DQS delay. This
property also puts a raw register value in the device tree.
Agreed. v4 removes the cdns,ddr-phony-dqs-timing property and its driver
override from both the driver and the binding. Board flight time is centred through cdns,ddr-read-dqs-delay, and the phony DQS timing is computed as above.
The open question is the width itself. The PHY guide gives no number, only the formula and an
example of 4. Your 2 is a measurement at 50 MHz. Please try phony_dqs_timing from 0 to 4 in DDR,
with the phony DQS selected, at 50 MHz and again at a lower card clock (about 25 MHz, by
lowering max-frequency; please check the actual clock). Compare the data byte for byte.
If the best value changes with the clock, compute the width in the driver from the two clocks. If
it stays the same, take the width from the SoC data, or from one device tree property for the width
in clock cycles. Not a register value, and not a fixed number in the common driver.
Also, I do not expect the pulse width itself to differ between boards of the same SoC, since the
controller generates it. I would suggest to open a ticket with Cadence to ask what sets this width.
See my reply above regarding the phony_dqs_timing formula and the example in Cadence document. Since they are from that Cadence document, I don't think a separate Cadence ticket is needed.
+ if (ddr && phy->ddr_phony_dqs_timing >= 0)
+ phy->cp_phony_dqs_timing = phy->ddr_phony_dqs_timing;
+
If it stays, this must also check phy->sdhc_extended_rd_mode: the guide requires 0 when extended
read is off.
It is dropped, so this is moot; the computed value already returns 0 when extended read is off (the else branch above).
Thanks,
Tze Yee
if (strobe_dat) {
/* dqs loopback input via IO cell */
hcsdclkadj += phy->iocell_input_delay;
@@ -693,10 +718,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);
@@ -878,6 +904,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 prop;
int ret;
phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
@@ -916,6 +943,19 @@ 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;
+ of_property_read_u32(dev->of_node, "cdns,ddr-read-dqs-delay", &phy->ddr_read_dqs_delay);
+
+ phy->ddr_no_lpbk_dqs = of_property_read_bool(dev->of_node, "cdns,ddr-no-lpbk-dqs");
+
+ phy->ddr_phony_dqs_timing = -1;
+ if (!of_property_read_u32(dev->of_node, "cdns,ddr-phony-dqs- timing", &prop))
+ phy->ddr_phony_dqs_timing = prop;
+
priv->phy = phy;
return 0;