If regulator_is_enabled() of both vmmc and vqmmc returns false,
_mmc_suspend() should call mmc_poweroff_nofity() instead of
mmc_sleep().

Note that this is possible to happen when the regulator-fixed driver
turns the vmmc and vqmmc off by firmware like PSCI while the system
is suspended.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 drivers/mmc/core/mmc.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 4203303..75df5f8 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -12,6 +12,7 @@
 #include <linux/slab.h>
 #include <linux/stat.h>
 #include <linux/pm_runtime.h>
+#include <linux/regulator/consumer.h>
 
 #include <linux/mmc/host.h>
 #include <linux/mmc/card.h>
@@ -2022,6 +2023,18 @@ static void mmc_detect(struct mmc_host *host)
        }
 }
 
+static bool mmc_regulators_are_disabled(struct mmc_host *host)
+{
+       if (IS_ERR(host->supply.vmmc) ||
+           regulator_is_enabled(host->supply.vmmc))
+               return false;
+       if (IS_ERR(host->supply.vqmmc) ||
+           regulator_is_enabled(host->supply.vqmmc))
+               return false;
+
+       return true;
+}
+
 static int _mmc_suspend(struct mmc_host *host, bool is_suspend)
 {
        int err = 0;
@@ -2038,7 +2051,8 @@ static int _mmc_suspend(struct mmc_host *host, bool 
is_suspend)
                goto out;
 
        if (mmc_can_poweroff_notify(host->card) &&
-               ((host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) || !is_suspend))
+           ((host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) || !is_suspend ||
+            mmc_regulators_are_disabled(host)))
                err = mmc_poweroff_notify(host->card, notify_type);
        else if (mmc_can_sleep(host->card))
                err = mmc_sleep(host);
-- 
2.7.4

Reply via email to