mmc: sdhci-esdhc-imx: enable IPG clock before register access during suspend/resume
Subsystems (4)
[email protected]
maintainerPATCH 1/2 mmc: sdhci-esdhc-imx: enable IPG clock before register access 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 a card slot do not insert a card, so when system suspend, sdhci_esdhc_runtime_resume() will not be called before sdhci_esdhc_suspend(), so will meet system hung or bus err once access usdhc register.
---
The first thing I do is try to merge the sdhci_esdhc_suspend() into current sdhci_esdhc_runtime_suspend(), but find some obstacles:
1, sdhci_esdhc_imx_hwinit() is called in original sdhci_esdhc_resume(),
it will clear the DLL config, which after remove to sdhci_esdhc_runtime_resume, will finally impact the DDR50 timing.
2, if merge, everytime after sdhci_esdhc_runtime_resume, will do re-tuning,
this is unnecessary for the normal runtime PM case without power lost.
3, the CD gpio wakeup. Seems strange to enable the CD gpio wakeup in
sdhci_esdhc_runtime_suspend().
So, finally I drop this merge method, and directly add change in the original sdhci_esdhc_suspend()/sdhci_esdhc_resume().
--- drivers/mmc/host/sdhci-esdhc-imx.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/mmc/host/sdhci-esdhc-imx.c +8 -0
@@ -1836,6 +1836,8 @@ static int sdhci_esdhc_suspend(struct device *dev)struct pltfm_imx_data *imx_data =sdhci_pltfm_priv (pltfm_host);int ret; +pm_runtime_get_sync (dev); +if (host->mmc->caps2 &MMC_CAP2_CQE ) { ret =cqhci_suspend (host->mmc);if (ret)
@@ -1855,6 +1857,8 @@ static int sdhci_esdhc_suspend(struct device *dev)if (ret)return ret; +pm_runtime_force_suspend (dev); + ret =pinctrl_pm_select_sleep_state (dev);if (ret)return ret;
@@ -1873,6 +1877,8 @@ static int sdhci_esdhc_resume(struct device *dev)if (ret)return ret; +pm_runtime_force_resume (dev); +/* re-initialize hw state in case it's lost in low power mode */ sdhci_esdhc_imx_hwinit (host);
@@ -1886,6 +1892,8 @@ static int sdhci_esdhc_resume(struct device *dev)if (!ret) ret =mmc_gpio_set_cd_wake (host->mmc, false); +pm_runtime_put_autosuspend (dev); + return ret; }#endif
Signature · 1 line
2.34.1
[email protected]
maintainerPATCH 2/2 mmc: sdhci-esdhc-imx: use pm_runtime_force_suspend() to optimize remove callback
From: Haibo Chen <[email protected]>
Currently some code in sdhci_esdhc_imx_remove() duplicate with sdhci_esdhc_runtime_suspend(), so use pm_runtime_force_suspend() instead.
--- drivers/mmc/host/sdhci-esdhc-imx.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/mmc/host/sdhci-esdhc-imx.c +5 -12
@@ -1805,23 +1805,16 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)static int sdhci_esdhc_imx_remove (struct platform_device *pdev) {struct sdhci_host *host =platform_get_drvdata (pdev); -struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host); -struct pltfm_imx_data *imx_data =sdhci_pltfm_priv (pltfm_host);int dead;pm_runtime_get_sync (&pdev->dev); dead = (readl (host->ioaddr +SDHCI_INT_STATUS ) ==0xffffffff ); -pm_runtime_disable (&pdev->dev); -pm_runtime_put_noidle (&pdev->dev); -sdhci_remove_host (host, dead); - -clk_disable_unprepare (imx_data->clk_per); -clk_disable_unprepare (imx_data->clk_ipg); -clk_disable_unprepare (imx_data->clk_ahb); - -if (imx_data->socdata->flags &ESDHC_FLAG_PMQOS ) -cpu_latency_qos_remove_request (&imx_data->pm_qos_req); +device_set_wakeup_capable (&pdev->dev, false); +pm_runtime_dont_use_autosuspend (&pdev->dev); +pm_runtime_put_sync (&pdev->dev); +/* Ensure device disabled */ +pm_runtime_force_suspend (&pdev->dev);sdhci_pltfm_free (pdev);
Signature · 1 line
2.34.1
Re: [PATCH 2/2] mmc: sdhci-esdhc-imx: use pm_runtime_force_suspend() to optimize remove callback
Quoted 6 lines · On Thu, 18 May 2023 at 10:17, <[email protected]> wrote:
From: Haibo Chen <[email protected]>
Currently some code in
sdhci_esdhc_imx_remove()duplicate withsdhci_esdhc_runtime_suspend(), so usepm_runtime_force_suspend()instead.
This is reasonable, but note that CONFIG_PM must always be set, as that is needed to let pm_runtime_force_suspend() gate the clocks.
So, this boils down to whether there are cases when sdhci-esdhc-imx can be built with CONFIG_PM unset?
Kind regards
Uffe
Quoted 42 lines
Signed-off-by Haibo Chen <[email protected]>--- drivers/mmc/host/sdhci-esdhc-imx.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)drivers/mmc/host/sdhci-esdhc-imx.c +5
-13@@ -1805,23 +1805,16 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)static int sdhci_esdhc_imx_remove (struct platform_device *pdev) {struct sdhci_host *host =platform_get_drvdata (pdev); -struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host); -struct pltfm_imx_data *imx_data =sdhci_pltfm_priv (pltfm_host);int dead;pm_runtime_get_sync (&pdev->dev); dead = (readl (host->ioaddr +SDHCI_INT_STATUS ) ==0xffffffff ); -pm_runtime_disable (&pdev->dev); -pm_runtime_put_noidle (&pdev->dev); -sdhci_remove_host (host, dead); - -clk_disable_unprepare (imx_data->clk_per); -clk_disable_unprepare (imx_data->clk_ipg); -clk_disable_unprepare (imx_data->clk_ahb); - -if (imx_data->socdata->flags &ESDHC_FLAG_PMQOS ) -cpu_latency_qos_remove_request (&imx_data->pm_qos_req); +device_set_wakeup_capable (&pdev->dev, false); +pm_runtime_dont_use_autosuspend (&pdev->dev); +pm_runtime_put_sync (&pdev->dev); +/* Ensure device disabled */ +pm_runtime_force_suspend (&pdev->dev);sdhci_pltfm_free (pdev); --2.34.1
Adrian Hunter
maintainerQuoted 42 lines · On 18/05/23 11:20, [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 a card slot do not insert a card, so when system suspend,
sdhci_esdhc_runtime_resume()will not be called beforesdhci_esdhc_suspend(), so will meet system hung or bus err once access usdhc register.Signed-off-by Haibo Chen <[email protected]>---
The first thing I do is try to merge thesdhci_esdhc_suspend()into currentsdhci_esdhc_runtime_suspend(), but find some obstacles:
1,sdhci_esdhc_imx_hwinit()is called in originalsdhci_esdhc_resume(),
it will clear the DLL config, which after remove tosdhci_esdhc_runtime_resume, will finally impact the DDR50 timing.
2, if merge, everytime aftersdhci_esdhc_runtime_resume, will do re-tuning,
this is unnecessary for the normal runtime PM case without power lost.
3, the CD gpio wakeup. Seems strange to enable the CD gpio wakeup in
sdhci_esdhc_runtime_suspend().So, finally I drop this merge method, and directly add change in the original sdhci_esdhc_suspend()/sdhci_esdhc_resume().
--- drivers/mmc/host/sdhci-esdhc-imx.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/mmc/host/sdhci-esdhc-imx.c +2
-0@@ -1836,6 +1836,8 @@ static int sdhci_esdhc_suspend(struct device *dev)struct pltfm_imx_data *imx_data =sdhci_pltfm_priv (pltfm_host);int ret; +pm_runtime_get_sync (dev); +if (host->mmc->caps2 &MMC_CAP2_CQE ) { ret =cqhci_suspend (host->mmc);if (ret)
drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_suspend(struct device *dev) · line 1860
Quoted 4 lines
drivers/mmc/host/sdhci-esdhc-imx.c +1
-0@@ -1855,6 +1857,8 @@ static int sdhci_esdhc_suspend(struct device *dev)if (ret)return ret; +pm_runtime_force_suspend (dev);
Won't this result both in sdhci_suspend_host() and sdhci_runtime_suspend_host() being called. Please ensure that just call one of them is called.
And cqhci_suspend() will be called twice. Please avoid that.
Quoted 22 lines
drivers/mmc/host/sdhci-esdhc-imx.c +5
-0+ ret =pinctrl_pm_select_sleep_state (dev);if (ret)return ret;@@ -1873,6 +1877,8 @@ static int sdhci_esdhc_resume(struct device *dev)if (ret)return ret; +pm_runtime_force_resume (dev); +/* re-initialize hw state in case it's lost in low power mode */ sdhci_esdhc_imx_hwinit (host);@@ -1886,6 +1892,8 @@ static int sdhci_esdhc_resume(struct device *dev)if (!ret) ret =mmc_gpio_set_cd_wake (host->mmc, false); +pm_runtime_put_autosuspend (dev); + return ret; }#endif
Quoted 23 lines · On Thu, 18 May 2023 at 10:17, <[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 a card slot do not insert a card, so when system suspend,
sdhci_esdhc_runtime_resume()will not be called beforesdhci_esdhc_suspend(), so will meet system hung or bus err once access usdhc register.Signed-off-by Haibo Chen <[email protected]>---
The first thing I do is try to merge thesdhci_esdhc_suspend()into currentsdhci_esdhc_runtime_suspend(), but find some obstacles:
1,sdhci_esdhc_imx_hwinit()is called in originalsdhci_esdhc_resume(),
it will clear the DLL config, which after remove tosdhci_esdhc_runtime_resume, will finally impact the DDR50 timing.
2, if merge, everytime aftersdhci_esdhc_runtime_resume, will do re-tuning,
this is unnecessary for the normal runtime PM case without power lost.
3, the CD gpio wakeup. Seems strange to enable the CD gpio wakeup in
sdhci_esdhc_runtime_suspend().
Quoted 2 lines
So, finally I drop this merge method, and directly add change in the original sdhci_esdhc_suspend()/sdhci_esdhc_resume().
Looks like you need some differentiation between runtime suspend/resume and system suspend/resume. One way to deal with this is to set some driver flags during system suspend and then monitor those flags at runtime resume - and then act accordingly.
There are a couple of sdhci drivers that do this, like sdhci-xenon.c and sdhci-of-at91.c. Those drivers don't seems to need the sdhci_suspend|resume_host(). Maybe that pattern can help to fix this too?
Kind regards
Uffe
Quoted 47 lines
--- drivers/mmc/host/sdhci-esdhc-imx.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/mmc/host/sdhci-esdhc-imx.c +8
-1@@ -1836,6 +1836,8 @@ static int sdhci_esdhc_suspend(struct device *dev)struct pltfm_imx_data *imx_data =sdhci_pltfm_priv (pltfm_host);int ret; +pm_runtime_get_sync (dev); +if (host->mmc->caps2 &MMC_CAP2_CQE ) { ret =cqhci_suspend (host->mmc);if (ret)@@ -1855,6 +1857,8 @@ static int sdhci_esdhc_suspend(struct device *dev)if (ret)return ret; +pm_runtime_force_suspend (dev); + ret =pinctrl_pm_select_sleep_state (dev);if (ret)return ret;@@ -1873,6 +1877,8 @@ static int sdhci_esdhc_resume(struct device *dev)if (ret)return ret; +pm_runtime_force_resume (dev); +/* re-initialize hw state in case it's lost in low power mode */ sdhci_esdhc_imx_hwinit (host);@@ -1886,6 +1892,8 @@ static int sdhci_esdhc_resume(struct device *dev)if (!ret) ret =mmc_gpio_set_cd_wake (host->mmc, false); +pm_runtime_put_autosuspend (dev); + return ret; }#endif --2.34.1