Skip to content

Commit 676a838

Browse files
Luke Wangstorulf
authored andcommitted
mmc: host: sdhci-esdhc-imx: refactor the system PM logic
Current suspend/resume logic has one issue. In suspend, will config register when call sdhci_suspend_host(), but at this time, can't guarantee host in runtime resume state. If not, the per clock is gate off, access register will hang. In sdhci_esdhc_suspend/sdhci_esdhc_resume, remove sdhci_suspend_host() and sdhci_resume_host(), all are handled in runtime PM callbacks except the wakeup irq setting. For wakeup irq setting, use pm_runtime_get_sync() in sdhci_esdhc_suspend() to make sure clock gate on. Remove pinctrl_pm_select_default_state() in sdhci_esdhc_resume, because pm_runtime_force_resume() already config the pinctrl state according to ios timing, and here config the default pinctrl state again is wrong for SDIO3.0 device if it keep power in suspend. Signed-off-by: Haibo Chen <haibo.chen@nxp.com> Signed-off-by: Luke Wang <ziniu.wang_1@nxp.com> Acked-by: Adrian Hunter <adrian.hunter@intel.com> Link: https://lore.kernel.org/r/20250514094903.1771642-2-ziniu.wang_1@nxp.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent b8b0f46 commit 676a838

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

drivers/mmc/host/sdhci-esdhc-imx.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,21 +2009,21 @@ static int sdhci_esdhc_suspend(struct device *dev)
20092009
struct pltfm_imx_data *imx_data = sdhci_pltfm_priv(pltfm_host);
20102010
int ret;
20112011

2012-
if (host->mmc->caps2 & MMC_CAP2_CQE) {
2013-
ret = cqhci_suspend(host->mmc);
2014-
if (ret)
2015-
return ret;
2016-
}
2012+
/*
2013+
* Switch to runtime resume for two reasons:
2014+
* 1, there is register access (e.g., wakeup control register), so
2015+
* need to make sure gate on ipg clock.
2016+
* 2, make sure the pm_runtime_force_resume() in sdhci_esdhc_resume() really
2017+
* invoke its ->runtime_resume callback (needs_force_resume = 1).
2018+
*/
2019+
pm_runtime_get_sync(dev);
20172020

20182021
if ((imx_data->socdata->flags & ESDHC_FLAG_STATE_LOST_IN_LPMODE) &&
20192022
(host->tuning_mode != SDHCI_TUNING_MODE_1)) {
20202023
mmc_retune_timer_stop(host->mmc);
20212024
mmc_retune_needed(host->mmc);
20222025
}
20232026

2024-
if (host->tuning_mode != SDHCI_TUNING_MODE_3)
2025-
mmc_retune_needed(host->mmc);
2026-
20272027
/*
20282028
* For the device need to keep power during system PM, need
20292029
* to save the tuning delay value just in case the usdhc
@@ -2033,16 +2033,26 @@ static int sdhci_esdhc_suspend(struct device *dev)
20332033
esdhc_is_usdhc(imx_data))
20342034
sdhc_esdhc_tuning_save(host);
20352035

2036-
ret = sdhci_suspend_host(host);
2037-
if (ret)
2038-
return ret;
2036+
if (device_may_wakeup(dev)) {
2037+
/* The irqs of imx are not shared. It is safe to disable */
2038+
disable_irq(host->irq);
2039+
ret = sdhci_enable_irq_wakeups(host);
2040+
if (!ret)
2041+
dev_warn(dev, "Failed to enable irq wakeup\n");
2042+
}
20392043

20402044
ret = pinctrl_pm_select_sleep_state(dev);
20412045
if (ret)
20422046
return ret;
20432047

20442048
ret = mmc_gpio_set_cd_wake(host->mmc, true);
20452049

2050+
/*
2051+
* Make sure invoke runtime_suspend to gate off clock.
2052+
* uSDHC IP supports in-band SDIO wakeup even without clock.
2053+
*/
2054+
pm_runtime_force_suspend(dev);
2055+
20462056
return ret;
20472057
}
20482058

@@ -2053,16 +2063,19 @@ static int sdhci_esdhc_resume(struct device *dev)
20532063
struct pltfm_imx_data *imx_data = sdhci_pltfm_priv(pltfm_host);
20542064
int ret;
20552065

2056-
ret = pinctrl_pm_select_default_state(dev);
2066+
pm_runtime_force_resume(dev);
2067+
2068+
ret = mmc_gpio_set_cd_wake(host->mmc, false);
20572069
if (ret)
20582070
return ret;
20592071

20602072
/* re-initialize hw state in case it's lost in low power mode */
20612073
sdhci_esdhc_imx_hwinit(host);
20622074

2063-
ret = sdhci_resume_host(host);
2064-
if (ret)
2065-
return ret;
2075+
if (host->irq_wake_enabled) {
2076+
sdhci_disable_irq_wakeups(host);
2077+
enable_irq(host->irq);
2078+
}
20662079

20672080
/*
20682081
* restore the saved tuning delay value for the device which keep
@@ -2072,11 +2085,8 @@ static int sdhci_esdhc_resume(struct device *dev)
20722085
esdhc_is_usdhc(imx_data))
20732086
sdhc_esdhc_tuning_restore(host);
20742087

2075-
if (host->mmc->caps2 & MMC_CAP2_CQE)
2076-
ret = cqhci_resume(host->mmc);
2077-
2078-
if (!ret)
2079-
ret = mmc_gpio_set_cd_wake(host->mmc, false);
2088+
pm_runtime_mark_last_busy(dev);
2089+
pm_runtime_put_autosuspend(dev);
20802090

20812091
return ret;
20822092
}

0 commit comments

Comments
 (0)