[PATCH v6 2/4] mmc: core: Add MMC_POWEROFF_UNDERVOLTAGE support in _mmc_suspend()

Oleksij Rempel posted 4 patches 3 months, 3 weeks ago
There is a newer version of this series
[PATCH v6 2/4] mmc: core: Add MMC_POWEROFF_UNDERVOLTAGE support in _mmc_suspend()
Posted by Oleksij Rempel 3 months, 3 weeks ago
Introduce MMC_POWEROFF_UNDERVOLTAGE as a new mmc_poweroff_type value and
adjust _mmc_suspend() to skip cache flush for this case. This prepares for
undervoltage handling in a follow-up patch.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
changes v5:
- rebase against latest mmc/next
- use MMC_POWEROFF_UNDERVOLTAGE enum instead of function parameter.
changes v3:
- add comments
- make sure _mmc_flush_cache is not executed in the undervoltage case
---
 drivers/mmc/core/mmc.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 5689ab6eefe1..6812df679ba9 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -36,6 +36,7 @@
 enum mmc_poweroff_type {
 	MMC_POWEROFF_SUSPEND,
 	MMC_POWEROFF_SHUTDOWN,
+	MMC_POWEROFF_UNDERVOLTAGE,
 	MMC_POWEROFF_UNBIND,
 };
 
@@ -2132,9 +2133,15 @@ static int _mmc_suspend(struct mmc_host *host, enum mmc_poweroff_type pm_type)
 	if (mmc_card_suspended(host->card))
 		goto out;
 
-	err = _mmc_flush_cache(host);
-	if (err)
-		goto out;
+	/*
+	 * For the undervoltage case, we care more about device integrity.
+	 * Avoid cache flush and notify the device to power off quickly.
+	 */
+	if (pm_type != MMC_POWEROFF_UNDERVOLTAGE) {
+		err = _mmc_flush_cache(host);
+		if (err)
+			goto out;
+	}
 
 	if (mmc_card_can_poweroff_notify(host->card) &&
 	    mmc_host_can_poweroff_notify(host, pm_type))
-- 
2.39.5
Re: [PATCH v6 2/4] mmc: core: Add MMC_POWEROFF_UNDERVOLTAGE support in _mmc_suspend()
Posted by Ulf Hansson 3 months, 1 week ago
On Mon, 16 Jun 2025 at 12:29, Oleksij Rempel <o.rempel@pengutronix.de> wrote:
>
> Introduce MMC_POWEROFF_UNDERVOLTAGE as a new mmc_poweroff_type value and
> adjust _mmc_suspend() to skip cache flush for this case. This prepares for
> undervoltage handling in a follow-up patch.
>
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
> changes v5:
> - rebase against latest mmc/next
> - use MMC_POWEROFF_UNDERVOLTAGE enum instead of function parameter.
> changes v3:
> - add comments
> - make sure _mmc_flush_cache is not executed in the undervoltage case
> ---
>  drivers/mmc/core/mmc.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
> index 5689ab6eefe1..6812df679ba9 100644
> --- a/drivers/mmc/core/mmc.c
> +++ b/drivers/mmc/core/mmc.c
> @@ -36,6 +36,7 @@
>  enum mmc_poweroff_type {
>         MMC_POWEROFF_SUSPEND,
>         MMC_POWEROFF_SHUTDOWN,
> +       MMC_POWEROFF_UNDERVOLTAGE,
>         MMC_POWEROFF_UNBIND,
>  };
>
> @@ -2132,9 +2133,15 @@ static int _mmc_suspend(struct mmc_host *host, enum mmc_poweroff_type pm_type)
>         if (mmc_card_suspended(host->card))
>                 goto out;
>
> -       err = _mmc_flush_cache(host);
> -       if (err)
> -               goto out;
> +       /*
> +        * For the undervoltage case, we care more about device integrity.
> +        * Avoid cache flush and notify the device to power off quickly.
> +        */
> +       if (pm_type != MMC_POWEROFF_UNDERVOLTAGE) {
> +               err = _mmc_flush_cache(host);
> +               if (err)
> +                       goto out;
> +       }

I think this sounds reasonable as we may simply not have the time to
complete a flush.

Yet, it may be device specific on what makes best sense. Let's see if
Avri also agrees with this.

>
>         if (mmc_card_can_poweroff_notify(host->card) &&
>             mmc_host_can_poweroff_notify(host, pm_type))
> --
> 2.39.5
>

That said, please squash this with patch3. Especially since I think
patch3 can be made a bit simpler due to my comments on patch1.

Kind regards
Uffe