[PATCH v11 5/6] mmc: core: Move and split reset functions for eMMC

From: Kamal Dasu

Date: Fri Oct 30 2026 - 14:12:21 EST


From: Ulf Hansson <ulf.hansson@xxxxxxxxxxxxxxxx>

To prepare for a subsequent change and to simplify review, let's move the
function for resetting the eMMC card a few lines up in the file.

While at it, split the cache flush out of _mmc_hw_reset() into a new
mmc_hw_reset_recovery() function and use that for the ->hw_reset() bus
operation. This keeps the flush for recovery, where it was intended, but
allows the card to be reset without it, by calling _mmc_hw_reset()
directly. That is needed when resetting the card at system resume, as the
cache has already been flushed at suspend and the flush would only fail
with a timeout, after the card has been accessed by firmware.

There are no functional changes.

Signed-off-by: Ulf Hansson <ulf.hansson@xxxxxxxxxxxxxxxx>
Co-developed-by: Kamal Dasu <kamal.dasu@xxxxxxxxxxxx>
Signed-off-by: Kamal Dasu <kamal.dasu@xxxxxxxxxxxx>
---
drivers/mmc/core/mmc.c | 73 ++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 34 deletions(-)

diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index c936272bcd81..026003ba507d 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -2271,6 +2271,44 @@ static int mmc_shutdown(struct mmc_host *host)
return err;
}

+static bool mmc_card_can_reset(struct mmc_card *card)
+{
+ u8 rst_n_function;
+
+ rst_n_function = card->ext_csd.rst_n_function;
+ return ((rst_n_function & EXT_CSD_RST_N_EN_MASK) == EXT_CSD_RST_N_ENABLED);
+}
+
+static int _mmc_hw_reset(struct mmc_host *host)
+{
+ struct mmc_card *card = host->card;
+
+ if ((host->caps & MMC_CAP_HW_RESET) && host->ops->card_hw_reset &&
+ mmc_card_can_reset(card)) {
+ /* If the card accept RST_n signal, send it. */
+ mmc_set_clock(host, host->f_init);
+ host->ops->card_hw_reset(host);
+ /* Set initial state and call mmc_set_ios */
+ mmc_set_initial_state(host);
+ } else {
+ /* Do a brute force power cycle */
+ mmc_power_cycle(host, card->ocr);
+ mmc_pwrseq_reset(host);
+ }
+ return mmc_init_card(host, card->ocr, card);
+}
+
+static int mmc_hw_reset_recovery(struct mmc_host *host)
+{
+ /*
+ * In the case of recovery, we can't expect flushing the cache to work
+ * always, but we have a go and ignore errors.
+ */
+ _mmc_flush_cache(host);
+
+ return _mmc_hw_reset(host);
+}
+
/*
* Callback for resume.
*/
@@ -2319,39 +2357,6 @@ static int mmc_runtime_resume(struct mmc_host *host)
return 0;
}

-static bool mmc_card_can_reset(struct mmc_card *card)
-{
- u8 rst_n_function;
-
- rst_n_function = card->ext_csd.rst_n_function;
- return ((rst_n_function & EXT_CSD_RST_N_EN_MASK) == EXT_CSD_RST_N_ENABLED);
-}
-
-static int _mmc_hw_reset(struct mmc_host *host)
-{
- struct mmc_card *card = host->card;
-
- /*
- * In the case of recovery, we can't expect flushing the cache to work
- * always, but we have a go and ignore errors.
- */
- _mmc_flush_cache(host);
-
- if ((host->caps & MMC_CAP_HW_RESET) && host->ops->card_hw_reset &&
- mmc_card_can_reset(card)) {
- /* If the card accept RST_n signal, send it. */
- mmc_set_clock(host, host->f_init);
- host->ops->card_hw_reset(host);
- /* Set initial state and call mmc_set_ios */
- mmc_set_initial_state(host);
- } else {
- /* Do a brute force power cycle */
- mmc_power_cycle(host, card->ocr);
- mmc_pwrseq_reset(host);
- }
- return mmc_init_card(host, card->ocr, card);
-}
-
/**
* _mmc_handle_undervoltage - Handle an undervoltage event for MMC/eMMC devices
* @host: MMC host structure
@@ -2410,7 +2415,7 @@ static const struct mmc_bus_ops mmc_ops = {
.runtime_resume = mmc_runtime_resume,
.alive = mmc_alive,
.shutdown = mmc_shutdown,
- .hw_reset = _mmc_hw_reset,
+ .hw_reset = mmc_hw_reset_recovery,
.cache_enabled = _mmc_cache_enabled,
.flush_cache = _mmc_flush_cache,
.handle_undervoltage = _mmc_handle_undervoltage,
--
2.34.1