[PATCH 4/4] mmc: sdhci-of-k1: Add TX tuning parameter

From: Yixun Lan

Date: Wed Sep 02 2026 - 03:09:03 EST


From: Long Wan <long.wan@xxxxxxxxxxxxxxxxxx>

Instead of setting the TX delay code via hardcoded parameter, configuring
it via device tree property, which make it able to adapt according to
board specific tuning requirement.

Signed-off-by: Long Wan <long.wan@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Yixun Lan <dlan@xxxxxxxxxx>
---
drivers/mmc/host/sdhci-of-k1.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c
index e6ab40c9a555..6cab06332747 100644
--- a/drivers/mmc/host/sdhci-of-k1.c
+++ b/drivers/mmc/host/sdhci-of-k1.c
@@ -97,6 +97,7 @@ struct spacemit_sdhci_host {
struct pinctrl *pinctrl;
struct pinctrl_state *pinctrl_default;
struct pinctrl_state *pinctrl_uhs;
+ u8 tx_delaycode;
};

/* All helper functions will update clr/set while preserve rest bits */
@@ -263,6 +264,7 @@ static int spacemit_sdhci_execute_tuning(struct sdhci_host *host, u32 opcode)
int max_pass_len = 0, max_pass_start = 0;
struct mmc_host *mmc = host->mmc;
struct mmc_ios ios = mmc->ios;
+ struct spacemit_sdhci_host *sdhst = sdhci_pltfm_priv(sdhci_priv(host));
u8 final_delay;
int ret = 0;
int i;
@@ -279,11 +281,11 @@ static int spacemit_sdhci_execute_tuning(struct sdhci_host *host, u32 opcode)

if (mmc->caps2 & MMC_CAP2_NO_MMC) {
spacemit_sdhci_set_tx_dline_reg(host, SPACEMIT_TX_TUNING_DLINE_REG);
- spacemit_sdhci_set_tx_delay(host, SPACEMIT_TX_TUNING_DELAYCODE);
+ spacemit_sdhci_set_tx_delay(host, sdhst->tx_delaycode);
spacemit_sdhci_tx_tuning_prepare(host);

dev_dbg(mmc_dev(host->mmc), "TX tuning: dline_reg=%d, delaycode=%d\n",
- SPACEMIT_TX_TUNING_DLINE_REG, SPACEMIT_TX_TUNING_DELAYCODE);
+ SPACEMIT_TX_TUNING_DLINE_REG, sdhst->tx_delaycode);
}

spacemit_sdhci_prepare_tuning(host);
@@ -496,6 +498,23 @@ static inline void spacemit_sdhci_get_pins(struct device *dev,
sdhst->pinctrl_default, sdhst->pinctrl_uhs);
}

+static void spacemit_sdhci_get_tuning_params(struct device *dev,
+ struct sdhci_pltfm_host *pltfm_host)
+{
+ struct spacemit_sdhci_host *sdhst = sdhci_pltfm_priv(pltfm_host);
+ u32 val;
+
+ sdhst->tx_delaycode = SPACEMIT_TX_TUNING_DELAYCODE;
+
+ /* Override from DT property */
+ if (!device_property_read_u32(dev, "spacemit,tx-delay", &val)) {
+ if (val <= U8_MAX)
+ sdhst->tx_delaycode = val;
+ else
+ dev_warn(dev, "ignoring invalid tx delay: %u\n", val);
+ }
+}
+
static const struct sdhci_ops spacemit_sdhci_ops = {
.get_max_clock = spacemit_sdhci_clk_get_max_clock,
.reset = spacemit_sdhci_reset,
@@ -571,6 +590,8 @@ static int spacemit_sdhci_probe(struct platform_device *pdev)

spacemit_sdhci_get_pins(dev, pltfm_host);

+ spacemit_sdhci_get_tuning_params(dev, pltfm_host);
+
host->mmc_host_ops.start_signal_voltage_switch = spacemit_sdhci_start_signal_voltage_switch;

ret = spacemit_sdhci_get_clocks(dev, pltfm_host);

--
2.55.0