]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
mmc: core: Convert into an enum for the poweroff-type for eMMC
authorUlf Hansson <ulf.hansson@linaro.org>
Mon, 7 Apr 2025 15:27:53 +0000 (17:27 +0200)
committerUlf Hansson <ulf.hansson@linaro.org>
Wed, 14 May 2025 14:59:16 +0000 (16:59 +0200)
Currently we are only distinguishing between the suspend and the shutdown
scenarios, which make a bool sufficient as in-parameter to the various PM
functions for eMMC. However, to prepare for adding support for another
scenario in a subsequent change, let's convert into using an enum.

Suggested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Link: https://lore.kernel.org/r/20250407152759.25160-4-ulf.hansson@linaro.org
drivers/mmc/core/mmc.c

index ee65c5b85f95c10a975dd5845e469ebc0fb9aeec..c41cee7ef2677afa5a8854df18702873c8045892 100644 (file)
 #define MIN_CACHE_EN_TIMEOUT_MS 1600
 #define CACHE_FLUSH_TIMEOUT_MS 30000 /* 30s */
 
+enum mmc_poweroff_type {
+       MMC_POWEROFF_SUSPEND,
+       MMC_POWEROFF_SHUTDOWN,
+};
+
 static const unsigned int tran_exp[] = {
        10000,          100000,         1000000,        10000000,
        0,              0,              0,              0
@@ -2015,15 +2020,16 @@ static bool mmc_can_poweroff_notify(const struct mmc_card *card)
 }
 
 static bool mmc_host_can_poweroff_notify(const struct mmc_host *host,
-                                        bool is_suspend)
+                                        enum mmc_poweroff_type pm_type)
 {
        if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE)
                return true;
 
-       if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND && is_suspend)
+       if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND &&
+           pm_type == MMC_POWEROFF_SUSPEND)
                return true;
 
-       return !is_suspend;
+       return pm_type == MMC_POWEROFF_SHUTDOWN;
 }
 
 static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type)
@@ -2120,11 +2126,13 @@ static int _mmc_flush_cache(struct mmc_host *host)
        return err;
 }
 
-static int _mmc_suspend(struct mmc_host *host, bool is_suspend)
+static int _mmc_suspend(struct mmc_host *host, enum mmc_poweroff_type pm_type)
 {
+       unsigned int notify_type = EXT_CSD_POWER_OFF_SHORT;
        int err = 0;
-       unsigned int notify_type = is_suspend ? EXT_CSD_POWER_OFF_SHORT :
-                                       EXT_CSD_POWER_OFF_LONG;
+
+       if (pm_type == MMC_POWEROFF_SHUTDOWN)
+               notify_type = EXT_CSD_POWER_OFF_LONG;
 
        mmc_claim_host(host);
 
@@ -2136,7 +2144,7 @@ static int _mmc_suspend(struct mmc_host *host, bool is_suspend)
                goto out;
 
        if (mmc_can_poweroff_notify(host->card) &&
-           mmc_host_can_poweroff_notify(host, is_suspend))
+           mmc_host_can_poweroff_notify(host, pm_type))
                err = mmc_poweroff_notify(host->card, notify_type);
        else if (mmc_can_sleep(host->card))
                err = mmc_sleep(host);
@@ -2159,7 +2167,7 @@ static int mmc_suspend(struct mmc_host *host)
 {
        int err;
 
-       err = _mmc_suspend(host, true);
+       err = _mmc_suspend(host, MMC_POWEROFF_SUSPEND);
        if (!err) {
                pm_runtime_disable(&host->card->dev);
                pm_runtime_set_suspended(&host->card->dev);
@@ -2203,11 +2211,11 @@ static int mmc_shutdown(struct mmc_host *host)
         * us to send the preferred poweroff-notification cmd at shutdown.
         */
        if (mmc_can_poweroff_notify(host->card) &&
-           !mmc_host_can_poweroff_notify(host, true))
+           !mmc_host_can_poweroff_notify(host, MMC_POWEROFF_SUSPEND))
                err = _mmc_resume(host);
 
        if (!err)
-               err = _mmc_suspend(host, false);
+               err = _mmc_suspend(host, MMC_POWEROFF_SHUTDOWN);
 
        return err;
 }
@@ -2231,7 +2239,7 @@ static int mmc_runtime_suspend(struct mmc_host *host)
        if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
                return 0;
 
-       err = _mmc_suspend(host, true);
+       err = _mmc_suspend(host, MMC_POWEROFF_SUSPEND);
        if (err)
                pr_err("%s: error %d doing aggressive suspend\n",
                        mmc_hostname(host), err);