* [PATCH RESEND v2 0/8] mmc: spacemit: Improve clock and tuning logic
@ 2026-12-01 10:54 Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 1/8] mmc: sdhci-of-k1: No pinctrl state switching Yixun Lan
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Yixun Lan @ 2026-12-01 10:54 UTC (permalink / raw)
To: Adrian Hunter, Ulf Hansson
Cc: Long Wan, Troy Mitchell, Hung-Chun Tseng, Iker Pedrosa,
Anand Moon, Adrian Hunter, Trevor Gamblin, Vincent Legoll,
linux-mmc, linux-kernel, linux-riscv, spacemit, Yixun Lan
This series includes some bug fixes and improvement to
SpacemiT SDHCI driver, which relate to pinctrl, PHY,
clock, tuning logic. Most of them are quite independent,
but put them together here for people to easy review.
Reason for the RESEND:
Rebasing on top of "Introduce tx delay DT property" [1],
it would make sashiko bot fail to apply [8/8], so decouple
the dependency and resend base on tag v7.4-rc1.
Link: https://patch.msgid.link/20261125-07-k3-sdhci-dts-v2-0-a069659ba025@kernel.org [1]
Signed-off-by: Yixun Lan <dlan@kernel.org>
---
Changes in v2:
- Fix clock defer probe error
- Fix pinctrl state check
- Add macro for tx_tuning window limit
- Link to v1: https://patch.msgid.link/20260902-07-k3-sdhci-fix-v1-0-b15c5d0f64fd@kernel.org
---
Long Wan (6):
mmc: sdhci-of-k1: No pinctrl state switching
mmc: sdhci-of-k1: Improve power control
mmc: sdhci-of-k1: Configure PHY mode
mmc: sdhci-of-k1: Use finest delay granularity for RX tuning
mmc: sdhci-of-k1: Improve RX tuning window
mmc: sdhci-of-k1: Implement SD clock gating for voltage switch
Yixun Lan (2):
mmc: sdhci-of-k1: Handle clock probe deferral
mmc: sdhci-of-k1: Drop duplicated voltage settings
drivers/mmc/host/sdhci-of-k1.c | 84 +++++++++++++++++++++++++++++++++---------
1 file changed, 66 insertions(+), 18 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20260901-07-k3-sdhci-fix-ce577d1db7b6
Best regards,
--
Yixun Lan <dlan@kernel.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH RESEND v2 1/8] mmc: sdhci-of-k1: No pinctrl state switching
2026-12-01 10:54 [PATCH RESEND v2 0/8] mmc: spacemit: Improve clock and tuning logic Yixun Lan
@ 2026-12-01 10:54 ` Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 2/8] mmc: sdhci-of-k1: Handle clock probe deferral Yixun Lan
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Yixun Lan @ 2026-12-01 10:54 UTC (permalink / raw)
To: Adrian Hunter, Ulf Hansson
Cc: Long Wan, Troy Mitchell, Hung-Chun Tseng, Iker Pedrosa,
Anand Moon, Adrian Hunter, Trevor Gamblin, Vincent Legoll,
linux-mmc, linux-kernel, linux-riscv, spacemit, Yixun Lan
From: Long Wan <long.wan@linux.spacemit.com>
No need to switch pinctrl state if the SDHCI controller only support 1.8v
IO voltage which DT will only provide a "default" pinctrl state, otherwise
function pinctrl_select_state() will trigger a NULL pointer error.
Fixes: 00a97fc57c09 ("mmc: sdhci-of-k1: add regulator and pinctrl voltage switching support")
Signed-off-by: Long Wan <long.wan@linux.spacemit.com>
Signed-off-by: Yixun Lan <dlan@kernel.org>
---
drivers/mmc/host/sdhci-of-k1.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c
index 37b0911e7cf2..9596d79fa97f 100644
--- a/drivers/mmc/host/sdhci-of-k1.c
+++ b/drivers/mmc/host/sdhci-of-k1.c
@@ -407,8 +407,12 @@ static int spacemit_sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
if (ret)
return ret;
+ /* No pinctrl */
if (!sdhst->pinctrl)
return 0;
+ /* No "uhs" state */
+ if (!sdhst->pinctrl_uhs)
+ return 0;
/* Select appropriate pinctrl state based on signal voltage */
switch (ios->signal_voltage) {
--
2.56.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH RESEND v2 2/8] mmc: sdhci-of-k1: Handle clock probe deferral
2026-12-01 10:54 [PATCH RESEND v2 0/8] mmc: spacemit: Improve clock and tuning logic Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 1/8] mmc: sdhci-of-k1: No pinctrl state switching Yixun Lan
@ 2026-12-01 10:54 ` Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 3/8] mmc: sdhci-of-k1: Drop duplicated voltage settings Yixun Lan
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Yixun Lan @ 2026-12-01 10:54 UTC (permalink / raw)
To: Adrian Hunter, Ulf Hansson
Cc: Long Wan, Troy Mitchell, Hung-Chun Tseng, Iker Pedrosa,
Anand Moon, Adrian Hunter, Trevor Gamblin, Vincent Legoll,
linux-mmc, linux-kernel, linux-riscv, spacemit, Yixun Lan
Propagate the error code when clock subsystem isn't ready, so
it will fallback to proper probe deferral mechanism.
Fixes: e5502d15b0f3 ("mmc: sdhci-of-k1: add support for SpacemiT K1 SoC")
Signed-off-by: Yixun Lan <dlan@kernel.org>
---
drivers/mmc/host/sdhci-of-k1.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c
index 9596d79fa97f..68b9958f8683 100644
--- a/drivers/mmc/host/sdhci-of-k1.c
+++ b/drivers/mmc/host/sdhci-of-k1.c
@@ -445,11 +445,11 @@ static inline int spacemit_sdhci_get_clocks(struct device *dev,
sdhst->clk_core = devm_clk_get_enabled(dev, "core");
if (IS_ERR(sdhst->clk_core))
- return -EINVAL;
+ return PTR_ERR(sdhst->clk_core);
sdhst->clk_io = devm_clk_get_enabled(dev, "io");
if (IS_ERR(sdhst->clk_io))
- return -EINVAL;
+ return PTR_ERR(sdhst->clk_io);
pltfm_host->clk = sdhst->clk_io;
--
2.56.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH RESEND v2 3/8] mmc: sdhci-of-k1: Drop duplicated voltage settings
2026-12-01 10:54 [PATCH RESEND v2 0/8] mmc: spacemit: Improve clock and tuning logic Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 1/8] mmc: sdhci-of-k1: No pinctrl state switching Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 2/8] mmc: sdhci-of-k1: Handle clock probe deferral Yixun Lan
@ 2026-12-01 10:54 ` Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 4/8] mmc: sdhci-of-k1: Improve power control Yixun Lan
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Yixun Lan @ 2026-12-01 10:54 UTC (permalink / raw)
To: Adrian Hunter, Ulf Hansson
Cc: Long Wan, Troy Mitchell, Hung-Chun Tseng, Iker Pedrosa,
Anand Moon, Adrian Hunter, Trevor Gamblin, Vincent Legoll,
linux-mmc, linux-kernel, linux-riscv, spacemit, Yixun Lan
No need to set 1.8V Signal for non-SDIO hosts, it will duplicate
what sdhci_start_signal_voltage_switch() already handled there.
Fixes: e5502d15b0f3 ("mmc: sdhci-of-k1: add support for SpacemiT K1 SoC")
Signed-off-by: Yixun Lan <dlan@kernel.org>
---
drivers/mmc/host/sdhci-of-k1.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c
index 68b9958f8683..f86f3636f5a9 100644
--- a/drivers/mmc/host/sdhci-of-k1.c
+++ b/drivers/mmc/host/sdhci-of-k1.c
@@ -195,9 +195,6 @@ static void spacemit_sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned i
spacemit_sdhci_setbits(host, SDHC_MMC_HS400, SPACEMIT_SDHC_MMC_CTRL_REG);
sdhci_set_uhs_signaling(host, timing);
-
- if (!(host->mmc->caps2 & MMC_CAP2_NO_SDIO))
- spacemit_sdhci_setbits(host, SDHCI_CTRL_VDD_180, SDHCI_HOST_CONTROL2);
}
static void spacemit_sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
--
2.56.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH RESEND v2 4/8] mmc: sdhci-of-k1: Improve power control
2026-12-01 10:54 [PATCH RESEND v2 0/8] mmc: spacemit: Improve clock and tuning logic Yixun Lan
` (2 preceding siblings ...)
2026-12-01 10:54 ` [PATCH RESEND v2 3/8] mmc: sdhci-of-k1: Drop duplicated voltage settings Yixun Lan
@ 2026-12-01 10:54 ` Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 5/8] mmc: sdhci-of-k1: Configure PHY mode Yixun Lan
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Yixun Lan @ 2026-12-01 10:54 UTC (permalink / raw)
To: Adrian Hunter, Ulf Hansson
Cc: Long Wan, Troy Mitchell, Hung-Chun Tseng, Iker Pedrosa,
Anand Moon, Adrian Hunter, Trevor Gamblin, Vincent Legoll,
linux-mmc, linux-kernel, linux-riscv, spacemit, Yixun Lan
From: Long Wan <long.wan@linux.spacemit.com>
The default sdhci_set_power() skips the SD bus voltage select field
entirely when a vmmc regulator is present, leaving SD Bus Power in off
state of the power control register. To fix this, configure the bus
voltage explicitly.
Fixes: e5502d15b0f3 ("mmc: sdhci-of-k1: add support for SpacemiT K1 SoC")
Signed-off-by: Long Wan <long.wan@linux.spacemit.com>
Signed-off-by: Yixun Lan <dlan@kernel.org>
---
drivers/mmc/host/sdhci-of-k1.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c
index f86f3636f5a9..5fb4692b58cd 100644
--- a/drivers/mmc/host/sdhci-of-k1.c
+++ b/drivers/mmc/host/sdhci-of-k1.c
@@ -497,6 +497,7 @@ static const struct sdhci_ops spacemit_sdhci_ops = {
.reset = spacemit_sdhci_reset,
.set_bus_width = sdhci_set_bus_width,
.set_clock = spacemit_sdhci_set_clock,
+ .set_power = sdhci_set_power_and_bus_voltage,
.set_uhs_signaling = spacemit_sdhci_set_uhs_signaling,
.platform_execute_tuning = spacemit_sdhci_execute_tuning,
};
--
2.56.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH RESEND v2 5/8] mmc: sdhci-of-k1: Configure PHY mode
2026-12-01 10:54 [PATCH RESEND v2 0/8] mmc: spacemit: Improve clock and tuning logic Yixun Lan
` (3 preceding siblings ...)
2026-12-01 10:54 ` [PATCH RESEND v2 4/8] mmc: sdhci-of-k1: Improve power control Yixun Lan
@ 2026-12-01 10:54 ` Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 6/8] mmc: sdhci-of-k1: Use finest delay granularity for RX tuning Yixun Lan
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Yixun Lan @ 2026-12-01 10:54 UTC (permalink / raw)
To: Adrian Hunter, Ulf Hansson
Cc: Long Wan, Troy Mitchell, Hung-Chun Tseng, Iker Pedrosa,
Anand Moon, Adrian Hunter, Trevor Gamblin, Vincent Legoll,
linux-mmc, linux-kernel, linux-riscv, spacemit, Yixun Lan
From: Long Wan <long.wan@linux.spacemit.com>
Apply PHY configuration only for eMMC hosts which enable PHY function mode,
and configure drive strength and bias. While for SD/SDIO hosts mode, bypass
the PHY mode and select TX internal clock instead.
Fixes: f87b273e4b6d ("mmc: sdhci-of-k1: enable essential clock infrastructure for SD operation")
Signed-off-by: Long Wan <long.wan@linux.spacemit.com>
Signed-off-by: Yixun Lan <dlan@kernel.org>
---
drivers/mmc/host/sdhci-of-k1.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c
index 5fb4692b58cd..01bc0f4bd6de 100644
--- a/drivers/mmc/host/sdhci-of-k1.c
+++ b/drivers/mmc/host/sdhci-of-k1.c
@@ -169,21 +169,25 @@ static void spacemit_sdhci_reset(struct sdhci_host *host, u8 mask)
if (mask != SDHCI_RESET_ALL)
return;
- spacemit_sdhci_setbits(host, SDHC_PHY_FUNC_EN | SDHC_PHY_PLL_LOCK,
- SPACEMIT_SDHC_PHY_CTRL_REG);
+ if (host->mmc->caps2 & MMC_CAP2_NO_MMC) {
+ /* SD/SDIO: bypass PHY, use TX internal clock */
+ spacemit_sdhci_setbits(host, SDHC_TX_INT_CLK_SEL, SPACEMIT_SDHC_TX_CFG_REG);
+
+ spacemit_sdhci_setbits(host, SDHC_OVRRD_CLK_OEN | SDHC_FORCE_CLK_ON,
+ SPACEMIT_SDHC_OP_EXT_REG);
+ } else {
+ /* eMMC: use PHY function mode */
+ spacemit_sdhci_setbits(host, SDHC_PHY_FUNC_EN | SDHC_PHY_PLL_LOCK,
+ SPACEMIT_SDHC_PHY_CTRL_REG);
- spacemit_sdhci_clrsetbits(host, SDHC_PHY_DRIVE_SEL,
- SDHC_RX_BIAS_CTRL | FIELD_PREP(SDHC_PHY_DRIVE_SEL, 4),
- SPACEMIT_SDHC_PHY_PADCFG_REG);
+ spacemit_sdhci_clrsetbits(host, SDHC_PHY_DRIVE_SEL,
+ SDHC_RX_BIAS_CTRL | FIELD_PREP(SDHC_PHY_DRIVE_SEL, 4),
+ SPACEMIT_SDHC_PHY_PADCFG_REG);
- if (!(host->mmc->caps2 & MMC_CAP2_NO_MMC))
spacemit_sdhci_setbits(host, SDHC_MMC_CARD_MODE, SPACEMIT_SDHC_MMC_CTRL_REG);
+ }
spacemit_sdhci_setbits(host, SDHC_GEN_PAD_CLK_ON, SPACEMIT_SDHC_LEGACY_CTRL_REG);
-
- if (host->mmc->caps2 & MMC_CAP2_NO_MMC)
- spacemit_sdhci_setbits(host, SDHC_OVRRD_CLK_OEN | SDHC_FORCE_CLK_ON,
- SPACEMIT_SDHC_OP_EXT_REG);
}
static void spacemit_sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned int timing)
--
2.56.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH RESEND v2 6/8] mmc: sdhci-of-k1: Use finest delay granularity for RX tuning
2026-12-01 10:54 [PATCH RESEND v2 0/8] mmc: spacemit: Improve clock and tuning logic Yixun Lan
` (4 preceding siblings ...)
2026-12-01 10:54 ` [PATCH RESEND v2 5/8] mmc: sdhci-of-k1: Configure PHY mode Yixun Lan
@ 2026-12-01 10:54 ` Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 7/8] mmc: sdhci-of-k1: Improve RX tuning window Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 8/8] mmc: sdhci-of-k1: Implement SD clock gating for voltage switch Yixun Lan
7 siblings, 0 replies; 9+ messages in thread
From: Yixun Lan @ 2026-12-01 10:54 UTC (permalink / raw)
To: Adrian Hunter, Ulf Hansson
Cc: Long Wan, Troy Mitchell, Hung-Chun Tseng, Iker Pedrosa,
Anand Moon, Adrian Hunter, Trevor Gamblin, Vincent Legoll,
linux-mmc, linux-kernel, linux-riscv, spacemit, Yixun Lan
From: Long Wan <long.wan@linux.spacemit.com>
Initialize the RX delay line to 0 (finest step size) instead of 9.
This improves tuning precision by allowing smaller delay increments
when searching for the optimal sampling point.
Fixes: e9cb83c10071 ("mmc: sdhci-of-k1: add comprehensive SDR tuning support")
Signed-off-by: Long Wan <long.wan@linux.spacemit.com>
Signed-off-by: Yixun Lan <dlan@kernel.org>
---
drivers/mmc/host/sdhci-of-k1.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c
index 01bc0f4bd6de..ba01434284eb 100644
--- a/drivers/mmc/host/sdhci-of-k1.c
+++ b/drivers/mmc/host/sdhci-of-k1.c
@@ -84,7 +84,7 @@
#define SDHC_RX_DLINE_GAIN BIT(8)
#define SDHC_TX_DLINE_REG_MASK GENMASK(23, 16)
-#define SPACEMIT_RX_DLINE_REG 9
+#define SPACEMIT_RX_DLINE_REG 0
#define SPACEMIT_RX_TUNE_DELAY_MIN 0x0
#define SPACEMIT_RX_TUNE_DELAY_MAX 0xFF
--
2.56.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH RESEND v2 7/8] mmc: sdhci-of-k1: Improve RX tuning window
2026-12-01 10:54 [PATCH RESEND v2 0/8] mmc: spacemit: Improve clock and tuning logic Yixun Lan
` (5 preceding siblings ...)
2026-12-01 10:54 ` [PATCH RESEND v2 6/8] mmc: sdhci-of-k1: Use finest delay granularity for RX tuning Yixun Lan
@ 2026-12-01 10:54 ` Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 8/8] mmc: sdhci-of-k1: Implement SD clock gating for voltage switch Yixun Lan
7 siblings, 0 replies; 9+ messages in thread
From: Yixun Lan @ 2026-12-01 10:54 UTC (permalink / raw)
To: Adrian Hunter, Ulf Hansson
Cc: Long Wan, Troy Mitchell, Hung-Chun Tseng, Iker Pedrosa,
Anand Moon, Adrian Hunter, Trevor Gamblin, Vincent Legoll,
linux-mmc, linux-kernel, linux-riscv, spacemit, Yixun Lan
From: Long Wan <long.wan@linux.spacemit.com>
Raise the minimum delay codes of RX tuning window from 3 to 50, to more
accurately retrieve a valid configuration.
A window of 3 codes wide leaves no sampling margin, which will result
tuning tests reporting success on a configuration that drifts out of the
window under thermal or power variation.
Fixes: e9cb83c10071 ("mmc: sdhci-of-k1: add comprehensive SDR tuning support")
Signed-off-by: Long Wan <long.wan@linux.spacemit.com>
Signed-off-by: Yixun Lan <dlan@kernel.org>
---
drivers/mmc/host/sdhci-of-k1.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c
index ba01434284eb..9f15cc6a4a8c 100644
--- a/drivers/mmc/host/sdhci-of-k1.c
+++ b/drivers/mmc/host/sdhci-of-k1.c
@@ -87,6 +87,7 @@
#define SPACEMIT_RX_DLINE_REG 0
#define SPACEMIT_RX_TUNE_DELAY_MIN 0x0
#define SPACEMIT_RX_TUNE_DELAY_MAX 0xFF
+#define SPACEMIT_RX_TUNE_WINDOW_LIMIT 50
#define SPACEMIT_TX_TUNING_DLINE_REG 0x00
#define SPACEMIT_TX_TUNING_DELAYCODE 127
@@ -316,7 +317,7 @@ static int spacemit_sdhci_execute_tuning(struct sdhci_host *host, u32 opcode)
max_pass_start = current_start;
}
- if (max_pass_len < 3) {
+ if (max_pass_len < SPACEMIT_RX_TUNE_WINDOW_LIMIT) {
dev_err(mmc_dev(host->mmc), "Tuning failed: no stable window found\n");
return -EIO;
}
--
2.56.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH RESEND v2 8/8] mmc: sdhci-of-k1: Implement SD clock gating for voltage switch
2026-12-01 10:54 [PATCH RESEND v2 0/8] mmc: spacemit: Improve clock and tuning logic Yixun Lan
` (6 preceding siblings ...)
2026-12-01 10:54 ` [PATCH RESEND v2 7/8] mmc: sdhci-of-k1: Improve RX tuning window Yixun Lan
@ 2026-12-01 10:54 ` Yixun Lan
7 siblings, 0 replies; 9+ messages in thread
From: Yixun Lan @ 2026-12-01 10:54 UTC (permalink / raw)
To: Adrian Hunter, Ulf Hansson
Cc: Long Wan, Troy Mitchell, Hung-Chun Tseng, Iker Pedrosa,
Anand Moon, Adrian Hunter, Trevor Gamblin, Vincent Legoll,
linux-mmc, linux-kernel, linux-riscv, spacemit, Yixun Lan
From: Long Wan <long.wan@linux.spacemit.com>
reset() permanently set OVRRD_CLK_OEN and FORCE_CLK_ON for SD/SDIO hosts
and never cleared them, so the SD clock was forced on for the lifetime of
the controller and hardware auto gating never took effect.
These bits are only needed during the CMD11 1.8V voltage switch, where
the clock has to keep running so DAT[3:0] can be sampled after the
switch. Add a set_clk_gate() helper, force the clock on from set_clock()
when CMD11 is in flight, and restore auto gating from card_busy() once
the switch completes.
card_busy() is registered for all card types since the CMD11 sequence is
an SD/SDIO path and the DAT[0] level check is generic.
Signed-off-by: Long Wan <long.wan@linux.spacemit.com>
Signed-off-by: Yixun Lan <dlan@kernel.org>
---
drivers/mmc/host/sdhci-of-k1.c | 49 ++++++++++++++++++++++++++++++++++++++----
1 file changed, 45 insertions(+), 4 deletions(-)
diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c
index 9f15cc6a4a8c..e99e972f006b 100644
--- a/drivers/mmc/host/sdhci-of-k1.c
+++ b/drivers/mmc/host/sdhci-of-k1.c
@@ -12,6 +12,7 @@
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
#include <linux/mmc/mmc.h>
+#include <linux/mmc/sd.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
@@ -163,6 +164,16 @@ static void spacemit_sdhci_prepare_tuning(struct sdhci_host *host)
spacemit_sdhci_setbits(host, SDHC_HS200_USE_RFIFO, SPACEMIT_SDHC_PHY_FUNC_REG);
}
+static void spacemit_sdhci_set_clk_gate(struct sdhci_host *host, unsigned int auto_gate)
+{
+ if (auto_gate)
+ spacemit_sdhci_clrbits(host, SDHC_OVRRD_CLK_OEN | SDHC_FORCE_CLK_ON,
+ SPACEMIT_SDHC_OP_EXT_REG);
+ else
+ spacemit_sdhci_setbits(host, SDHC_OVRRD_CLK_OEN | SDHC_FORCE_CLK_ON,
+ SPACEMIT_SDHC_OP_EXT_REG);
+}
+
static void spacemit_sdhci_reset(struct sdhci_host *host, u8 mask)
{
sdhci_reset(host, mask);
@@ -173,9 +184,6 @@ static void spacemit_sdhci_reset(struct sdhci_host *host, u8 mask)
if (host->mmc->caps2 & MMC_CAP2_NO_MMC) {
/* SD/SDIO: bypass PHY, use TX internal clock */
spacemit_sdhci_setbits(host, SDHC_TX_INT_CLK_SEL, SPACEMIT_SDHC_TX_CFG_REG);
-
- spacemit_sdhci_setbits(host, SDHC_OVRRD_CLK_OEN | SDHC_FORCE_CLK_ON,
- SPACEMIT_SDHC_OP_EXT_REG);
} else {
/* eMMC: use PHY function mode */
spacemit_sdhci_setbits(host, SDHC_PHY_FUNC_EN | SDHC_PHY_PLL_LOCK,
@@ -212,6 +220,20 @@ static void spacemit_sdhci_set_clock(struct sdhci_host *host, unsigned int clock
spacemit_sdhci_clrbits(host, SDHC_TX_INT_CLK_SEL, SPACEMIT_SDHC_TX_CFG_REG);
sdhci_set_clock(host, clock);
+
+ if (host->mmc->caps2 & MMC_CAP2_NO_MMC) {
+ /*
+ * During CMD11 voltage switch to 1.8V, temporarily force the
+ * clock on to ensure DAT[3:0] can be sampled correctly after
+ * the switch. Auto gating is restored in card_busy() once the
+ * switch completes.
+ */
+ if ((SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)) == SD_SWITCH_VOLTAGE) &&
+ host->mmc->ios.signal_voltage == MMC_SIGNAL_VOLTAGE_180) {
+ if (clock)
+ spacemit_sdhci_set_clk_gate(host, 0);
+ }
+ }
};
static void spacemit_sdhci_phy_dll_init(struct sdhci_host *host)
@@ -497,6 +519,23 @@ static inline void spacemit_sdhci_get_pins(struct device *dev,
sdhst->pinctrl_default, sdhst->pinctrl_uhs);
}
+static int spacemit_sdhci_card_busy(struct mmc_host *mmc)
+{
+ struct sdhci_host *host = mmc_priv(mmc);
+ u32 present_state;
+
+ present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+
+ if (host->mmc->caps2 & MMC_CAP2_NO_MMC) {
+ if ((SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)) == SD_SWITCH_VOLTAGE) &&
+ host->mmc->ios.signal_voltage == MMC_SIGNAL_VOLTAGE_180)
+ /* Recover auto clock after voltage switch */
+ spacemit_sdhci_set_clk_gate(host, 1);
+ }
+
+ return !(present_state & SDHCI_DATA_0_LVL_MASK);
+}
+
static const struct sdhci_ops spacemit_sdhci_ops = {
.get_max_clock = spacemit_sdhci_clk_get_max_clock,
.reset = spacemit_sdhci_reset,
@@ -561,8 +600,10 @@ static int spacemit_sdhci_probe(struct platform_device *pdev)
sdhci_get_of_property(pdev);
+ mops = &host->mmc_host_ops;
+ mops->card_busy = spacemit_sdhci_card_busy;
+
if (!(host->mmc->caps2 & MMC_CAP2_NO_MMC)) {
- mops = &host->mmc_host_ops;
mops->hs400_prepare_ddr = spacemit_sdhci_pre_select_hs400;
mops->hs400_complete = spacemit_sdhci_post_select_hs400;
mops->hs400_downgrade = spacemit_sdhci_pre_hs400_to_hs200;
--
2.56.0
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-12-01 10:55 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 10:54 [PATCH RESEND v2 0/8] mmc: spacemit: Improve clock and tuning logic Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 1/8] mmc: sdhci-of-k1: No pinctrl state switching Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 2/8] mmc: sdhci-of-k1: Handle clock probe deferral Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 3/8] mmc: sdhci-of-k1: Drop duplicated voltage settings Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 4/8] mmc: sdhci-of-k1: Improve power control Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 5/8] mmc: sdhci-of-k1: Configure PHY mode Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 6/8] mmc: sdhci-of-k1: Use finest delay granularity for RX tuning Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 7/8] mmc: sdhci-of-k1: Improve RX tuning window Yixun Lan
2026-12-01 10:54 ` [PATCH RESEND v2 8/8] mmc: sdhci-of-k1: Implement SD clock gating for voltage switch Yixun Lan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®