Skip to contentSkip to conversation

mmc: sdhci-esdhc-imx: make sure usdhc clock enabled while doing suspend

PATCH In review Haibo Chen 3 participants 8 messages Oct 18, 2016 – Oct 21, 2016

Subsystems (4)
lore
Share & tools
lore

Haibo Chen

author maintainer
#0 lore raw

PATCH 1/1 mmc: sdhci-esdhc-imx: make sure usdhc clock enabled while doing suspend

When suspend usdhc, it will access usdhc register. So usdhc clock should be enabled, otherwise the access usdhc register will return error or cause system hung.

Take this into consideration, if system enable a usdhc and do not connect any SD/SDIO/MMC card, after system boot up, this usdhc will do runtime suspend, and close all usdhc clock. At this time, if suspend the system, due to no card persent, usdhc runtime resume will not be called. So usdhc clock still closed, then in suspend, once access usdhc register, system hung or bus error return.

This patch make sure usdhc clock always enabled while doing usdhc suspend.

---
 drivers/mmc/host/sdhci-esdhc-imx.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-esdhc-imx.c +12 -1
index 7123ef9..1df3846 100644
@@ -1322,17 +1322,28 @@ static int sdhci_esdhc_suspend(struct device *dev)
 {
 	struct sdhci_host *host = dev_get_drvdata(dev);
 
+#ifdef CONFIG_PM
+	pm_runtime_get_sync(host->mmc->parent);
+#endif
+
 	return sdhci_suspend_host(host);
 }
 
 static int sdhci_esdhc_resume(struct device *dev)
 {
 	struct sdhci_host *host = dev_get_drvdata(dev);
+	int ret;
 
 	/* re-initialize hw state in case it's lost in low power mode */
 	sdhci_esdhc_imx_hwinit(host);
+	ret = sdhci_resume_host(host);
 
-	return sdhci_resume_host(host);
+#ifdef CONFIG_PM
+	pm_runtime_mark_last_busy(host->mmc->parent);
+	pm_runtime_put_autosuspend(host->mmc->parent);
+#endif
+
+	return ret;
 }
 #endif
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 11 lines · Haibo Chen

When suspend usdhc, it will access usdhc register. So usdhc clock should be enabled, otherwise the access usdhc register will return error or cause system hung.

Take this into consideration, if system enable a usdhc and do not connect any SD/SDIO/MMC card, after system boot up, this usdhc will do runtime suspend, and close all usdhc clock. At this time, if suspend the system, due to no card persent, usdhc runtime resume will not be called. So usdhc clock still closed, then in suspend, once access usdhc register, system hung or bus error return.

Quoted 2 lines

This patch make sure usdhc clock always enabled while doing usdhc suspend.

Yes, and since the clocks are kept enabled during system suspend that means wasting power, doesn't it!?

May I propose another solution. Currently you deal only with clock gating/ungating during runtime suspend/resume. I am wondering whether you could extend those operations to be similar to what is needed during system suspend/resume?

If that is possible, you can instead deploy the runtime PM centric approach and get system suspend/resume for free. All you would have to do is to assign the system PM callbacks to pm_runtime_force_suspend|resume(). In that way, the above problem would be solved and you don't need to keep the clocks enabled during system suspend/resume.

Kind regards
Uffe

Quoted 43 lines
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-esdhc-imx.c +12 -2
index 7123ef9..1df3846 100644
@@ -1322,17 +1322,28 @@ static int sdhci_esdhc_suspend(struct device *dev)
 {
        struct sdhci_host *host = dev_get_drvdata(dev);
 
+#ifdef CONFIG_PM
+       pm_runtime_get_sync(host->mmc->parent);
+#endif
+
        return sdhci_suspend_host(host);
 }
 
 static int sdhci_esdhc_resume(struct device *dev)
 {
        struct sdhci_host *host = dev_get_drvdata(dev);
+       int ret;
 
        /* re-initialize hw state in case it's lost in low power mode */
        sdhci_esdhc_imx_hwinit(host);
+       ret = sdhci_resume_host(host);
 
-       return sdhci_resume_host(host);
+#ifdef CONFIG_PM
+       pm_runtime_mark_last_busy(host->mmc->parent);
+       pm_runtime_put_autosuspend(host->mmc->parent);
+#endif
+
+       return ret;
 }
 #endif
 
--

1.9.1

#2 lore raw

Hi Ulf,

Quoted 12 lines · Ulf Hansson
Quoted 11 lines · Haibo Chen

When suspend usdhc, it will access usdhc register. So usdhc clock should be enabled, otherwise the access usdhc register will return error or cause system hung.

Take this into consideration, if system enable a usdhc and do not connect any SD/SDIO/MMC card, after system boot up, this usdhc will do runtime suspend, and close all usdhc clock. At this time, if suspend the system, due to no card persent, usdhc runtime resume will not be called. So usdhc clock still closed, then in suspend, once access usdhc register, system hung or bus error return.

Quoted 6 lines
Quoted 2 lines

This patch make sure usdhc clock always enabled while doing usdhc suspend.

Yes, and since the clocks are kept enabled during system suspend that means wasting power, doesn't it!?

IMX SoCs will disable all modules clocks in system stop mode automatically by hardware
even it's enabled before
CCGR value Clock Activity Description:
00 clock is off during all modes. stop enter hardware handshake is disabled. 01 clock is on in run mode, but off in wait and stop modes
10 Not applicable (Reserved).
11 clock is on during all modes, except stop mode.

Although HW will gate off it automatically, but i think it's still good to align the state between
SW and HW.

Quoted 5 lines

May I propose another solution. Currently you deal only with clock gating/ungating during runtime suspend/resume. I am wondering whether you could extend those operations to be similar to what is needed during system suspend/resume?

IMX driver are calling sdhci_runtime_suspend_host() and sdhci_suspend_host() for runtime
suspend and system sleep case respectively.
Those two APIs definitions are different.
e.g. sdhci_suspend_host will disable card detection and enable wakeup if any while
sdhci_runtime_suspend_host() not.

It may not be suitable to extend runtime operations to be similar as sleep pm operations
if using common sdhci suspend function, unless we implement totoally IMX specific
PM/Runtime PM function.

Another option may be like what omap_hsmmc does:

Something like:

int sdhci_esdhc_suspend(struct device *dev)

{
        pm_runtime_get_sync(host->dev);
        ret = sdhci_pltfm_suspend(dev);
        pm_runtime_put_sync(host->dev);

        return ret;
}

int sdhci_esdhc_resume(struct device *dev)

{
        pm_runtime_get_sync(host->dev);

        ...
        ret = sdhci_pltfm_resume(dev);

        pm_runtime_mark_last_busy(host->dev);
        pm_runtime_put_autosuspend(host->dev);

        return ret;
}

Does that seem ok?

Quoted 10 lines

If that is possible, you can instead deploy the runtime PM centric approach and get system suspend/resume for free. All you would have to do is to assign the system PM callbacks to pm_runtime_force_suspend|resume(). In that way, the above problem would be solved and you don't need to keep the clocks enabled during system suspend/resume.

Kind regards
Uffe

Regards
Dong Aisheng

Quoted 43 lines
Quoted 43 lines
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-esdhc-imx.c +12 -2
index 7123ef9..1df3846 100644
@@ -1322,17 +1322,28 @@ static int sdhci_esdhc_suspend(struct device *dev)
 {
        struct sdhci_host *host = dev_get_drvdata(dev);
 
+#ifdef CONFIG_PM
+       pm_runtime_get_sync(host->mmc->parent);
+#endif
+
        return sdhci_suspend_host(host);
 }
 
 static int sdhci_esdhc_resume(struct device *dev)
 {
        struct sdhci_host *host = dev_get_drvdata(dev);
+       int ret;
 
        /* re-initialize hw state in case it's lost in low power mode */
        sdhci_esdhc_imx_hwinit(host);
+       ret = sdhci_resume_host(host);
 
-       return sdhci_resume_host(host);
+#ifdef CONFIG_PM
+       pm_runtime_mark_last_busy(host->mmc->parent);
+       pm_runtime_put_autosuspend(host->mmc->parent);
+#endif
+
+       return ret;
 }
 #endif
 
--

1.9.1

author maintainer
#3 lore raw
Quoted 41 lines

-----Original Message-----
From: Dong Aisheng [mailto:[email protected]]
Sent: Wednesday, October 19, 2016 5:18 PM
To: Ulf Hansson <[email protected]>
Cc: Bough Chen <[email protected]>; Adrian Hunter <[email protected]>; linux-mmc <[email protected]>; A.S. Dong <[email protected]>
Subject: Re: [PATCH] mmc: sdhci-esdhc-imx: make sure usdhc clock enabled while doing suspend

Hi Ulf,

Quoted 12 lines · Ulf Hansson
Quoted 11 lines · Haibo Chen

When suspend usdhc, it will access usdhc register. So usdhc clock should be enabled, otherwise the access usdhc register will return error or cause system hung.

Take this into consideration, if system enable a usdhc and do not connect any SD/SDIO/MMC card, after system boot up, this usdhc will do runtime suspend, and close all usdhc clock. At this time, if suspend the system, due to no card persent, usdhc runtime resume will not be called. So usdhc clock still closed, then in suspend, once access usdhc register, system hung or bus error return.

Quoted 6 lines
Quoted 2 lines

This patch make sure usdhc clock always enabled while doing usdhc suspend.

Yes, and since the clocks are kept enabled during system suspend that means wasting power, doesn't it!?

IMX SoCs will disable all modules clocks in system stop mode automatically by hardware even it's enabled before CCGR value Clock Activity Description:
00 clock is off during all modes. stop enter hardware handshake is disabled. 01 clock is on in run mode, but off in wait and stop modes
10 Not applicable (Reserved).
11 clock is on during all modes, except stop mode.

Quoted 3 lines

Although HW will gate off it automatically, but i think it's still good to align the state between SW and HW.

Agree

Quoted 23 lines
Quoted 5 lines

May I propose another solution. Currently you deal only with clock gating/ungating during runtime suspend/resume. I am wondering whether you could extend those operations to be similar to what is needed during system suspend/resume?

IMX driver are calling sdhci_runtime_suspend_host() and sdhci_suspend_host() for runtime
suspend and system sleep case respectively.
Those two APIs definitions are different.
e.g. sdhci_suspend_host will disable card detection and enable wakeup if any while
sdhci_runtime_suspend_host() not.

It may not be suitable to extend runtime operations to be similar as sleep pm operations if using common sdhci suspend function, unless we implement totoally IMX specific PM/Runtime PM function.

Another option may be like what omap_hsmmc does:

Something like:

Quoted 8 lines
int sdhci_esdhc_suspend(struct device *dev) {
        pm_runtime_get_sync(host->dev);
        ret = sdhci_pltfm_suspend(dev);
        pm_runtime_put_sync(host->dev);

        return ret;
}

I think this method still has the same issue. According to the /Documentation/power/runtime_pm.txt

370 int pm_runtime_get_sync(struct device *dev);
371 - increment the device's usage counter, run pm_runtime_resume(dev) and
372 return its result

385 int pm_runtime_put_sync(struct device *dev);
386 - decrement the device's usage counter; if the result is 0 then run
387 pm_runtime_idle(dev) and return its result

pm_runtime_put_sync() will not call pm_runtime_suspend(), so clock still enabled, the same issue.

Quoted 70 lines
int sdhci_esdhc_resume(struct device *dev) {
        pm_runtime_get_sync(host->dev);

        ...
        ret = sdhci_pltfm_resume(dev);

        pm_runtime_mark_last_busy(host->dev);
        pm_runtime_put_autosuspend(host->dev);

        return ret;
}

Does that seem ok?

Quoted 10 lines

If that is possible, you can instead deploy the runtime PM centric approach and get system suspend/resume for free. All you would have to do is to assign the system PM callbacks to pm_runtime_force_suspend|resume(). In that way, the above problem would be solved and you don't need to keep the clocks enabled during system suspend/resume.

Kind regards
Uffe

Regards
Dong Aisheng

Quoted 42 lines
Quoted 42 lines
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-esdhc-imx.c +12 -2
index 7123ef9..1df3846 100644
@@ -1322,17 +1322,28 @@ static int sdhci_esdhc_suspend(struct device
 *dev)  {
        struct sdhci_host *host = dev_get_drvdata(dev);
 
+#ifdef CONFIG_PM
+       pm_runtime_get_sync(host->mmc->parent);
+#endif
+
        return sdhci_suspend_host(host);  }
 
 static int sdhci_esdhc_resume(struct device *dev)  {
        struct sdhci_host *host = dev_get_drvdata(dev);
+       int ret;
 
        /* re-initialize hw state in case it's lost in low power mode */
        sdhci_esdhc_imx_hwinit(host);
+       ret = sdhci_resume_host(host);
 
-       return sdhci_resume_host(host);
+#ifdef CONFIG_PM
+       pm_runtime_mark_last_busy(host->mmc->parent);
+       pm_runtime_put_autosuspend(host->mmc->parent);
+#endif
+
+       return ret;
 }
 #endif
 
--

1.9.1

#4 lore raw
Quoted 86 lines · Bough Chen
Quoted 41 lines

-----Original Message-----
From: Dong Aisheng [mailto:[email protected]]
Sent: Wednesday, October 19, 2016 5:18 PM
To: Ulf Hansson <[email protected]>
Cc: Bough Chen <[email protected]>; Adrian Hunter <[email protected]>; linux-mmc <[email protected]>; A.S. Dong <[email protected]>
Subject: Re: [PATCH] mmc: sdhci-esdhc-imx: make sure usdhc clock enabled while doing suspend

Hi Ulf,

Quoted 12 lines · Ulf Hansson
Quoted 11 lines · Haibo Chen

When suspend usdhc, it will access usdhc register. So usdhc clock should be enabled, otherwise the access usdhc register will return error or cause system hung.

Take this into consideration, if system enable a usdhc and do not connect any SD/SDIO/MMC card, after system boot up, this usdhc will do runtime suspend, and close all usdhc clock. At this time, if suspend the system, due to no card persent, usdhc runtime resume will not be called. So usdhc clock still closed, then in suspend, once access usdhc register, system hung or bus error return.

Quoted 6 lines
Quoted 2 lines

This patch make sure usdhc clock always enabled while doing usdhc suspend.

Yes, and since the clocks are kept enabled during system suspend that means wasting power, doesn't it!?

IMX SoCs will disable all modules clocks in system stop mode automatically by hardware even it's enabled before CCGR value Clock Activity Description:
00 clock is off during all modes. stop enter hardware handshake is disabled. 01 clock is on in run mode, but off in wait and stop modes
10 Not applicable (Reserved).
11 clock is on during all modes, except stop mode.

Quoted 3 lines

Although HW will gate off it automatically, but i think it's still good to align the state between SW and HW.

Agree

Quoted 23 lines
Quoted 5 lines

May I propose another solution. Currently you deal only with clock gating/ungating during runtime suspend/resume. I am wondering whether you could extend those operations to be similar to what is needed during system suspend/resume?

IMX driver are calling sdhci_runtime_suspend_host() and sdhci_suspend_host() for runtime
suspend and system sleep case respectively.
Those two APIs definitions are different.
e.g. sdhci_suspend_host will disable card detection and enable wakeup if any while
sdhci_runtime_suspend_host() not.

It may not be suitable to extend runtime operations to be similar as sleep pm operations if using common sdhci suspend function, unless we implement totoally IMX specific PM/Runtime PM function.

Another option may be like what omap_hsmmc does:

Something like:

Quoted 8 lines
int sdhci_esdhc_suspend(struct device *dev) {
        pm_runtime_get_sync(host->dev);
        ret = sdhci_pltfm_suspend(dev);
        pm_runtime_put_sync(host->dev);

        return ret;
}

I think this method still has the same issue. According to the /Documentation/power/runtime_pm.txt

370 int pm_runtime_get_sync(struct device *dev);
371 - increment the device's usage counter, run pm_runtime_resume(dev) and
372 return its result

Quoted 6 lines

385 int pm_runtime_put_sync(struct device *dev);
386 - decrement the device's usage counter; if the result is 0 then run
387 pm_runtime_idle(dev) and return its result

pm_runtime_put_sync() will not call pm_runtime_suspend(), so clock still enabled, the same issue.

Yes, you're right.
Device may be already in runtime resumed state before.

Regards
Dong Aisheng

Quoted 70 lines
Quoted 70 lines
int sdhci_esdhc_resume(struct device *dev) {
        pm_runtime_get_sync(host->dev);

        ...
        ret = sdhci_pltfm_resume(dev);

        pm_runtime_mark_last_busy(host->dev);
        pm_runtime_put_autosuspend(host->dev);

        return ret;
}

Does that seem ok?

Quoted 10 lines

If that is possible, you can instead deploy the runtime PM centric approach and get system suspend/resume for free. All you would have to do is to assign the system PM callbacks to pm_runtime_force_suspend|resume(). In that way, the above problem would be solved and you don't need to keep the clocks enabled during system suspend/resume.

Kind regards
Uffe

Regards
Dong Aisheng

Quoted 42 lines
Quoted 42 lines
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-esdhc-imx.c +12 -2
index 7123ef9..1df3846 100644
@@ -1322,17 +1322,28 @@ static int sdhci_esdhc_suspend(struct device
 *dev)  {
        struct sdhci_host *host = dev_get_drvdata(dev);
 
+#ifdef CONFIG_PM
+       pm_runtime_get_sync(host->mmc->parent);
+#endif
+
        return sdhci_suspend_host(host);  }
 
 static int sdhci_esdhc_resume(struct device *dev)  {
        struct sdhci_host *host = dev_get_drvdata(dev);
+       int ret;
 
        /* re-initialize hw state in case it's lost in low power mode */
        sdhci_esdhc_imx_hwinit(host);
+       ret = sdhci_resume_host(host);
 
-       return sdhci_resume_host(host);
+#ifdef CONFIG_PM
+       pm_runtime_mark_last_busy(host->mmc->parent);
+       pm_runtime_put_autosuspend(host->mmc->parent);
+#endif
+
+       return ret;
 }
 #endif
 
--

1.9.1

#5 lore raw
In reply to Dong Aisheng
Quoted 31 lines · Dong Aisheng

Hi Ulf,

Quoted 12 lines · Ulf Hansson
Quoted 11 lines · Haibo Chen

When suspend usdhc, it will access usdhc register. So usdhc clock should be enabled, otherwise the access usdhc register will return error or cause system hung.

Take this into consideration, if system enable a usdhc and do not connect any SD/SDIO/MMC card, after system boot up, this usdhc will do runtime suspend, and close all usdhc clock. At this time, if suspend the system, due to no card persent, usdhc runtime resume will not be called. So usdhc clock still closed, then in suspend, once access usdhc register, system hung or bus error return.

Quoted 6 lines
Quoted 2 lines

This patch make sure usdhc clock always enabled while doing usdhc suspend.

Yes, and since the clocks are kept enabled during system suspend that means wasting power, doesn't it!?

IMX SoCs will disable all modules clocks in system stop mode automatically by hardware
even it's enabled before
CCGR value Clock Activity Description:
00 clock is off during all modes. stop enter hardware handshake is disabled. 01 clock is on in run mode, but off in wait and stop modes
10 Not applicable (Reserved).
11 clock is on during all modes, except stop mode.

Quoted 3 lines

Although HW will gate off it automatically, but i think it's still good to align the state between
SW and HW.

Yes, indeed!

Quoted 7 lines
Quoted 6 lines

May I propose another solution. Currently you deal only with clock gating/ungating during runtime suspend/resume. I am wondering whether you could extend those operations to be similar to what is needed during system suspend/resume?

Quoted 7 lines

IMX driver are calling sdhci_runtime_suspend_host() and sdhci_suspend_host() for runtime
suspend and system sleep case respectively.
Those two APIs definitions are different.
e.g. sdhci_suspend_host will disable card detection and enable wakeup if any while
sdhci_runtime_suspend_host() not.

Yes, and that is weird and most likely wrong!

Quoted 3 lines

It may not be suitable to extend runtime operations to be similar as sleep pm operations

I have several times by know had kind of similar discussions, but for different sdhci variants. I believe we are papering over a PM issue in sdhci, instead of actually trying to solve the real problem and in a generic fashion.

As a first step, why not try to combine sdhci_suspend_host() and sdhci_runtime_suspend_host() into one function, and vice verse for the resume functions.

Then sdhci variants can decide how they want to use them. Particularly, those that uses runtime PM, should benefit from using the runtime PM centric approach and thus get system PM suspend/resume for "free".

Quoted 31 lines

if using common sdhci suspend function, unless we implement totoally IMX specific
PM/Runtime PM function.

Another option may be like what omap_hsmmc does:

Something like:

int sdhci_esdhc_suspend(struct device *dev)

{
        pm_runtime_get_sync(host->dev);
        ret = sdhci_pltfm_suspend(dev);
        pm_runtime_put_sync(host->dev);

        return ret;
}

int sdhci_esdhc_resume(struct device *dev)

{
        pm_runtime_get_sync(host->dev);

        ...
        ret = sdhci_pltfm_resume(dev);

        pm_runtime_mark_last_busy(host->dev);
        pm_runtime_put_autosuspend(host->dev);

        return ret;
}
Quoted 1 line

Does that seem ok?

No, this doesn't work!

People that aren't into runtime PM, believes that the pm_runtime_put*() in these paths means that the device enters runtime suspend state. That's not the case.

Instead the device will remain runtime resumed while the system enters suspend. Is that really what you want?

[...]

Kind regards
Uffe

#6 lore raw
Quoted 59 lines · Ulf Hansson
Quoted 31 lines · Dong Aisheng

Hi Ulf,

Quoted 12 lines · Ulf Hansson
Quoted 11 lines · Haibo Chen

When suspend usdhc, it will access usdhc register. So usdhc clock should be enabled, otherwise the access usdhc register will return error or cause system hung.

Take this into consideration, if system enable a usdhc and do not connect any SD/SDIO/MMC card, after system boot up, this usdhc will do runtime suspend, and close all usdhc clock. At this time, if suspend the system, due to no card persent, usdhc runtime resume will not be called. So usdhc clock still closed, then in suspend, once access usdhc register, system hung or bus error return.

Quoted 6 lines
Quoted 2 lines

This patch make sure usdhc clock always enabled while doing usdhc suspend.

Yes, and since the clocks are kept enabled during system suspend that means wasting power, doesn't it!?

IMX SoCs will disable all modules clocks in system stop mode automatically by hardware
even it's enabled before
CCGR value Clock Activity Description:
00 clock is off during all modes. stop enter hardware handshake is disabled. 01 clock is on in run mode, but off in wait and stop modes
10 Not applicable (Reserved).
11 clock is on during all modes, except stop mode.

Quoted 3 lines

Although HW will gate off it automatically, but i think it's still good to align the state between
SW and HW.

Yes, indeed!

Quoted 7 lines
Quoted 6 lines

May I propose another solution. Currently you deal only with clock gating/ungating during runtime suspend/resume. I am wondering whether you could extend those operations to be similar to what is needed during system suspend/resume?

Quoted 7 lines

IMX driver are calling sdhci_runtime_suspend_host() and sdhci_suspend_host() for runtime
suspend and system sleep case respectively.
Those two APIs definitions are different.
e.g. sdhci_suspend_host will disable card detection and enable wakeup if any while
sdhci_runtime_suspend_host() not.

Yes, and that is weird and most likely wrong!

Quoted 3 lines

It may not be suitable to extend runtime operations to be similar as sleep pm operations

Quoted 9 lines

I have several times by know had kind of similar discussions, but for different sdhci variants. I believe we are papering over a PM issue in sdhci, instead of actually trying to solve the real problem and in a generic fashion.

As a first step, why not try to combine sdhci_suspend_host() and sdhci_runtime_suspend_host() into one function, and vice verse for the resume functions.

Yes, that's a reasonable way.
We may need double check whether we can combine them into one function since they're defined for different purpose currently.

Quoted 38 lines

Then sdhci variants can decide how they want to use them. Particularly, those that uses runtime PM, should benefit from using the runtime PM centric approach and thus get system PM suspend/resume for "free".

Quoted 31 lines

if using common sdhci suspend function, unless we implement totoally IMX specific
PM/Runtime PM function.

Another option may be like what omap_hsmmc does:

Something like:

int sdhci_esdhc_suspend(struct device *dev)

{
        pm_runtime_get_sync(host->dev);
        ret = sdhci_pltfm_suspend(dev);
        pm_runtime_put_sync(host->dev);

        return ret;
}

int sdhci_esdhc_resume(struct device *dev)

{
        pm_runtime_get_sync(host->dev);

        ...
        ret = sdhci_pltfm_resume(dev);

        pm_runtime_mark_last_busy(host->dev);
        pm_runtime_put_autosuspend(host->dev);

        return ret;
}
Quoted 1 line

Does that seem ok?

Quoted 8 lines

No, this doesn't work!

People that aren't into runtime PM, believes that the pm_runtime_put*() in these paths means that the device enters runtime suspend state. That's not the case.

Instead the device will remain runtime resumed while the system enters suspend. Is that really what you want?

Yes, it's true.
Thanks for spotting it.

Quoted 5 lines

[...]

Kind regards
Uffe

Regards
Dong Aisheng

#7 lore raw
In reply to Haibo Chen

Hi Haibo,

Quoted 11 lines · Haibo Chen

When suspend usdhc, it will access usdhc register. So usdhc clock should be enabled, otherwise the access usdhc register will return error or cause system hung.

Take this into consideration, if system enable a usdhc and do not connect any SD/SDIO/MMC card, after system boot up, this usdhc will do runtime suspend, and close all usdhc clock. At this time, if suspend the system, due to no card persent, usdhc runtime resume will not be called. So usdhc clock still closed, then in suspend, once access usdhc register, system hung or bus error return.

Quoted 3 lines

This patch make sure usdhc clock always enabled while doing usdhc suspend.

Besides the former comments in my last reply, it would be good to explain a bit more why the former SoC series do not have this issue in the patch commit message.
That would make people more clear about it.

And more minor comment below:

Quoted 10 lines
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-esdhc-imx.c +0 -0
index 7123ef9..1df3846 100644

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

Quoted 4 lines
drivers/mmc/host/sdhci-esdhc-imx.c +1 -0
@@ -1322,17 +1322,28 @@ static int sdhci_esdhc_suspend(struct device *dev)
 {
        struct sdhci_host *host = dev_get_drvdata(dev);
 
+#ifdef CONFIG_PM

Do you really need this?

Quoted 7 lines
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+       pm_runtime_get_sync(host->mmc->parent);
+#endif
+
        return sdhci_suspend_host(host);
 }
 
 static int sdhci_esdhc_resume(struct device *dev)

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

Quoted 10 lines
drivers/mmc/host/sdhci-esdhc-imx.c +3 -1
 {
        struct sdhci_host *host = dev_get_drvdata(dev);
+       int ret;
 
        /* re-initialize hw state in case it's lost in low power mode */
        sdhci_esdhc_imx_hwinit(host);
+       ret = sdhci_resume_host(host);
 
-       return sdhci_resume_host(host);
+#ifdef CONFIG_PM

ditto

Quoted 11 lines
drivers/mmc/host/sdhci-esdhc-imx.c +5 -1
+       pm_runtime_mark_last_busy(host->mmc->parent);
+       pm_runtime_put_autosuspend(host->mmc->parent);
+#endif
+
+       return ret;
 }
 #endif
 
--

1.9.1

Regards
Dong Aisheg