[PATCH v14 6/6] mmc: core: Add support for resetting an eMMC at system resume

From: Kamal Dasu

Date: Wed Nov 25 2026 - 13:21:28 EST


From: Ulf Hansson <ulf.hansson@xxxxxxxxxxxxxxxx>

The DT property reset-card-at-resume specifies that we need to make a reset
of an eMMC card at system resume, assuming it also has stayed powered on
during system suspend.

To implement support for this, let's start by parsing for the new DT
property and set the new bit MMC_CAP2_RESET_AT_RESUME if it's found. Based
on the property, we must also set MMC_PM_KEEP_POWER in the pm_flags for the
host, to keep the eMMC powered on during system suspend.

Finally, to manage the actual reset during system resume, let's extend
mmc_resume() to support the needed behaviour.

The property only makes sense together with keep-power-in-suspend, as the
card would otherwise be powered off and system suspend is refused. Validate
that in mmc_validate_host_caps(), to make the host probe fail upfront on
such a misconfiguration.

While at it, claim the host around the reset in mmc_resume(), as it sends
commands to the card, and propagate any error from the reset so that a
failure to re-initialize the card is reported by the resume path.

Also clear MMC_PM_KEEP_POWER in mmc_host_class_complete(), as mmc_resume()
isn't invoked if system suspend is aborted after mmc_host_class_prepare()
has set the flag.

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/host.c | 26 ++++++++++++++++++++++++++
drivers/mmc/core/mmc.c | 12 +++++++++++-
include/linux/mmc/host.h | 1 +
3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 8e9e61839198..9cb456a153ae 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -48,6 +48,14 @@ static int mmc_host_class_prepare(struct device *dev)
if (host->bus_ops->pre_suspend)
return host->bus_ops->pre_suspend(host);

+ /*
+ * If it's required to make a reset of the card at system resume, this
+ * indirectly also means that we must keep the card powered on during
+ * system suspend.
+ */
+ if (host->caps2 & MMC_CAP2_RESET_AT_RESUME)
+ return mmc_set_host_pm_flags(host, MMC_PM_KEEP_POWER);
+
return 0;
}

@@ -55,6 +63,15 @@ static void mmc_host_class_complete(struct device *dev)
{
struct mmc_host *host = cls_dev_to_mmc_host(dev);

+ /*
+ * MMC_PM_KEEP_POWER is set in ->prepare() and normally cleared by the
+ * bus ->resume() callback. If system suspend is aborted after
+ * ->prepare(), ->resume() isn't invoked, so clear the flag here to not
+ * leave it set at runtime.
+ */
+ if (host->caps2 & MMC_CAP2_RESET_AT_RESUME)
+ host->pm_flags &= ~MMC_PM_KEEP_POWER;
+
_mmc_detect_change(host, 0, false);
}

@@ -375,6 +392,8 @@ int mmc_of_parse(struct mmc_host *host)
host->pm_caps |= MMC_PM_KEEP_POWER;
if (device_property_read_bool(dev, "wakeup-source"))
host->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
+ if (device_property_read_bool(dev, "reset-card-at-resume"))
+ host->caps2 |= MMC_CAP2_RESET_AT_RESUME;
if (device_property_read_bool(dev, "mmc-ddr-3_3v"))
host->caps |= MMC_CAP_3_3V_DDR;
if (device_property_read_bool(dev, "mmc-ddr-1_8v"))
@@ -620,6 +639,13 @@ static int mmc_validate_host_caps(struct mmc_host *host)
return -EINVAL;
}

+ /* Resetting the card at resume requires that it stays powered on */
+ if (caps2 & MMC_CAP2_RESET_AT_RESUME &&
+ !(host->pm_caps & MMC_PM_KEEP_POWER)) {
+ dev_warn(dev, "reset-card-at-resume requires keep-power-in-suspend\n");
+ return -EINVAL;
+ }
+
/* UHS/DDR/HS200 modes require at least 4-bit bus */
if (!(caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) &&
((caps & (MMC_CAP_UHS | MMC_CAP_DDR)) || (caps2 & MMC_CAP2_HS200))) {
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 122ac9ba0a4b..829947374dcc 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -2316,14 +2316,24 @@ static int mmc_hw_reset_recovery(struct mmc_host *host)
*/
static int mmc_resume(struct mmc_host *host)
{
+ int err = 0;
+
if (mmc_card_keep_power(host)) {
pm_runtime_set_active(&host->card->dev);
mmc_card_clr_suspended(host->card);
}

pm_runtime_enable(&host->card->dev);
+
+ if (mmc_card_keep_power(host) &&
+ host->caps2 & MMC_CAP2_RESET_AT_RESUME) {
+ mmc_claim_host(host);
+ err = _mmc_hw_reset(host);
+ mmc_release_host(host);
+ }
+
host->pm_flags &= ~MMC_PM_KEEP_POWER;
- return 0;
+ return err;
}

/*
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 032c018650e0..3c0ea74e3e35 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -430,6 +430,7 @@ struct mmc_host {
u32 caps2; /* More host capabilities */

#define MMC_CAP2_BOOTPART_NOACC (1 << 0) /* Boot partition no access */
+#define MMC_CAP2_RESET_AT_RESUME BIT(1) /* Reset the card at system resume */
#define MMC_CAP2_FULL_PWR_CYCLE (1 << 2) /* Can do full power cycle */
#define MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND (1 << 3) /* Can do full power cycle in suspend */
#define MMC_CAP2_HS200_1_8V_SDR (1 << 5) /* can support */