Skip to contentSkip to conversation

mmc: sdhci-esdhc-imx: make sure ipg clock enabled during suspend/resume

PATCH In review [email protected] 2 participants 2 messages Mar 22, 2021 – Mar 24, 2021

Subsystems (4)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 mmc: sdhci-esdhc-imx: make sure ipg clock enabled during suspend/resume

From: Haibo Chen <[email protected]>

During suspend/resume, need to access usdhc register, so need to enable IPG clock to avoid bus error.

Find this issue when both enable CONFIG_PM and CONFIG_PM_SLEEP, which means both support PM and Runtime PM. If the card slot do not insert a card, then after system boot up, will do sdhci_esdhc_runtime_suspend(), disable all clocks, include the ipg clock. In this case, when suspend the system, due to no card present, sdhci_esdhc_runtime_resume() will not be called before sdhci_esdhc_suspend(), so will meet system hung or bus err once access usdhc register.

---
 drivers/mmc/host/sdhci-esdhc-imx.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
drivers/mmc/host/sdhci-esdhc-imx.c +24 -6
index 94327988da91..a48b977ca13f 100644
@@ -1695,10 +1695,14 @@ static int sdhci_esdhc_suspend(struct device *dev)
 	struct pltfm_imx_data *imx_data = sdhci_pltfm_priv(pltfm_host);
 	int ret;
 
+	ret = clk_prepare_enable(imx_data->clk_ipg);
+	if (ret)
+		return ret;
+
 	if (host->mmc->caps2 & MMC_CAP2_CQE) {
 		ret = cqhci_suspend(host->mmc);
 		if (ret)
-			return ret;
+			goto disable_ipg_clk;
 	}
 
 	if ((imx_data->socdata->flags & ESDHC_FLAG_STATE_LOST_IN_LPMODE) &&
@@ -1712,38 +1716,52 @@ static int sdhci_esdhc_suspend(struct device *dev)
 
 	ret = sdhci_suspend_host(host);
 	if (ret)
-		return ret;
+		goto disable_ipg_clk;
 
 	ret = pinctrl_pm_select_sleep_state(dev);
 	if (ret)
-		return ret;
+		goto disable_ipg_clk;
 
 	ret = mmc_gpio_set_cd_wake(host->mmc, true);
 
+disable_ipg_clk:
+	clk_disable_unprepare(imx_data->clk_ipg);
+
 	return ret;
 }
 
 static int sdhci_esdhc_resume(struct device *dev)
 {
 	struct sdhci_host *host = dev_get_drvdata(dev);
+	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+	struct pltfm_imx_data *imx_data = sdhci_pltfm_priv(pltfm_host);
 	int ret;
 
 	ret = pinctrl_pm_select_default_state(dev);
 	if (ret)
 		return ret;
 
+	ret = clk_prepare_enable(imx_data->clk_ipg);
+	if (ret)
+		return ret;
+
 	/* re-initialize hw state in case it's lost in low power mode */
 	sdhci_esdhc_imx_hwinit(host);
 
 	ret = sdhci_resume_host(host);
 	if (ret)
-		return ret;
+		goto disable_ipg_clk;
 
 	if (host->mmc->caps2 & MMC_CAP2_CQE)
 		ret = cqhci_resume(host->mmc);
 
-	if (!ret)
-		ret = mmc_gpio_set_cd_wake(host->mmc, false);
+	if (ret)
+		goto disable_ipg_clk;
+
+	ret = mmc_gpio_set_cd_wake(host->mmc, false);
+
+disable_ipg_clk:
+	clk_disable_unprepare(imx_data->clk_ipg);
 
 	return ret;
 }
Signature · 1 line
2.17.1
#1 lore raw
Quoted 24 lines · On Mon, 22 Mar 2021 at 10:13, <[email protected]> wrote:

From: Haibo Chen <[email protected]>

During suspend/resume, need to access usdhc register, so need to enable IPG clock to avoid bus error.

Find this issue when both enable CONFIG_PM and CONFIG_PM_SLEEP, which means both support PM and Runtime PM. If the card slot do not insert a card, then after system boot up, will do sdhci_esdhc_runtime_suspend(), disable all clocks, include the ipg clock. In this case, when suspend the system, due to no card present, sdhci_esdhc_runtime_resume() will not be called before sdhci_esdhc_suspend(), so will meet system hung or bus err once access usdhc register.

---
 drivers/mmc/host/sdhci-esdhc-imx.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
drivers/mmc/host/sdhci-esdhc-imx.c +0 -0
index 94327988da91..a48b977ca13f 100644

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_suspend(struct device *dev) · line 1701

Quoted 7 lines
drivers/mmc/host/sdhci-esdhc-imx.c +4 -0
@@ -1695,10 +1695,14 @@ static int sdhci_esdhc_suspend(struct device *dev)
        struct pltfm_imx_data *imx_data = sdhci_pltfm_priv(pltfm_host);
        int ret;
 
+       ret = clk_prepare_enable(imx_data->clk_ipg);
+       if (ret)
+               return ret;
+

This isn't sufficient.

If the device is attached to a PM domain, that needs to be powered on too. In other words, you need to call pm_runtime_get_sync() instead of clk_prepare_enable().

That said, it's kind of surprising to me, that the clocks may remain ungated during system suspend, but are gated in runtime suspend. Perhaps what you really should look into, is to re-organize the code and then can call pm_runtime_force_suspend() from sdhci_esdhc_suspend() (and pm_runtime_force_resume() from sdhci_esdhc_suspend()). I think that will be both easier and likely helps to avoid wasting energy as well.

Quoted 17 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -2
        if (host->mmc->caps2 & MMC_CAP2_CQE) {
                ret = cqhci_suspend(host->mmc);
                if (ret)
-                       return ret;
+                       goto disable_ipg_clk;
        }
 
        if ((imx_data->socdata->flags & ESDHC_FLAG_STATE_LOST_IN_LPMODE) &&
@@ -1712,38 +1716,52 @@ static int sdhci_esdhc_suspend(struct device *dev)
 
        ret = sdhci_suspend_host(host);
        if (ret)
-               return ret;
+               goto disable_ipg_clk;
 
        ret = pinctrl_pm_select_sleep_state(dev);
        if (ret)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_suspend(struct device *dev) · line 1731

Quoted 10 lines
drivers/mmc/host/sdhci-esdhc-imx.c +4 -1
-               return ret;
+               goto disable_ipg_clk;
 
        ret = mmc_gpio_set_cd_wake(host->mmc, true);
 
+disable_ipg_clk:
+       clk_disable_unprepare(imx_data->clk_ipg);
+
        return ret;
 }

[...]

Kind regards
Uffe