[PATCH v2 1/2] mmc: core: add mmc_send_tuning_timeout()
Shawn Lin
shawn.lin at rock-chips.com
Thu Sep 24 01:50:22 PDT 2026
Add mmc_send_tuning_timeout() which takes the data timeout in
milliseconds, and turn mmc_send_tuning() into a thin wrapper keeping
the current 150 ms, so there is no behaviour change for the existing
callers. This lets drivers pass a tighter timeout for software
tuning, e.g. hosts which scan the tuning window phase by phase.
Suggested-by: Adrian Hunter <adrian.hunter at intel.com>
Signed-off-by: Shawn Lin <shawn.lin at rock-chips.com>
---
Changes in v2: None
drivers/mmc/core/mmc_ops.c | 22 +++++++++++++++-------
include/linux/mmc/host.h | 2 ++
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index a952cc8..d59ff82f 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -673,7 +673,8 @@ int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
}
EXPORT_SYMBOL_GPL(mmc_switch);
-int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error)
+int mmc_send_tuning_timeout(struct mmc_host *host, u32 opcode, int *cmd_error,
+ u32 timeout_ms)
{
struct mmc_request mrq = {};
struct mmc_command cmd = {};
@@ -707,12 +708,7 @@ int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error)
data.blocks = 1;
data.flags = MMC_DATA_READ;
- /*
- * According to the tuning specs, Tuning process
- * is normally shorter 40 executions of CMD19,
- * and timeout value should be shorter than 150 ms
- */
- data.timeout_ns = 150 * NSEC_PER_MSEC;
+ data.timeout_ns = timeout_ms * NSEC_PER_MSEC;
data.sg = &sg;
data.sg_len = 1;
@@ -740,6 +736,18 @@ int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error)
kfree(data_buf);
return err;
}
+EXPORT_SYMBOL_GPL(mmc_send_tuning_timeout);
+
+int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error)
+{
+ /*
+ * The eMMC and SD specs give the tuning process an overall
+ * budget of 150 ms. mmc_send_tuning() simply applies that as
+ * the timeout of every single tuning command. Drivers which
+ * want a different timeout can use mmc_send_tuning_timeout().
+ */
+ return mmc_send_tuning_timeout(host, opcode, cmd_error, 150);
+}
EXPORT_SYMBOL_GPL(mmc_send_tuning);
int mmc_send_abort_tuning(struct mmc_host *host, u32 opcode)
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 198554e..032c018 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -753,6 +753,8 @@ static inline int mmc_card_uhs2_hd_mode(struct mmc_host *host)
int mmc_sd_switch(struct mmc_card *card, bool mode, int group,
u8 value, u8 *resp);
int mmc_send_status(struct mmc_card *card, u32 *status);
+int mmc_send_tuning_timeout(struct mmc_host *host, u32 opcode, int *cmd_error,
+ u32 timeout_ms);
int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error);
int mmc_send_abort_tuning(struct mmc_host *host, u32 opcode);
int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd);
--
2.7.4
More information about the Linux-rockchip
mailing list