linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: sdhci-msm: Add pm_runtime and system PM support
@ 2016-06-16 12:35 Pramod Gurav
  2016-08-29  8:59 ` Pramod Gurav
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Pramod Gurav @ 2016-06-16 12:35 UTC (permalink / raw)
  To: adrian.hunter, ulf.hansson; +Cc: linux-mmc, linux-kernel, Pramod Gurav

Provides runtime PM callbacks to enable and disable clock resources
when idle. Also support system PM callbacks to be called during system
suspend and resume.

Signed-off-by: Pramod Gurav <pramod.gurav@linaro.org>
---
 drivers/mmc/host/sdhci-msm.c | 57 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
index 0653fe7..f4394c8 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -18,6 +18,7 @@
 #include <linux/of_device.h>
 #include <linux/delay.h>
 #include <linux/mmc/mmc.h>
+#include <linux/pm_runtime.h>
 #include <linux/slab.h>
 
 #include "sdhci-pltfm.h"
@@ -549,6 +550,11 @@ static int sdhci_msm_probe(struct platform_device *pdev)
 	if (ret)
 		goto clk_disable;
 
+	platform_set_drvdata(pdev, msm_host);
+
+	pm_runtime_set_active(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+
 	return 0;
 
 clk_disable:
@@ -580,12 +586,63 @@ static int sdhci_msm_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static int sdhci_msm_runtime_suspend(struct device *dev)
+{
+	struct sdhci_msm_host *msm_host = dev_get_drvdata(dev);
+
+	clk_disable_unprepare(msm_host->clk);
+	clk_disable_unprepare(msm_host->pclk);
+
+	return 0;
+}
+
+static int sdhci_msm_runtime_resume(struct device *dev)
+{
+	struct sdhci_msm_host *msm_host = dev_get_drvdata(dev);
+	int ret;
+
+	ret = clk_prepare_enable(msm_host->clk);
+	if (ret) {
+		dev_err(dev, "clk_enable failed: %d\n", ret);
+		return ret;
+	}
+	ret = clk_prepare_enable(msm_host->pclk);
+	if (ret) {
+		dev_err(dev, "clk_enable failed: %d\n", ret);
+		clk_disable_unprepare(msm_host->clk);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int sdhci_msm_suspend(struct device *dev)
+{
+	pm_runtime_force_suspend(dev);
+
+	return 0;
+}
+
+static int sdhci_msm_resume(struct device *dev)
+{
+	pm_runtime_force_resume(dev);
+
+	return 0;
+}
+
+static const struct dev_pm_ops sdhci_msm_pm_ops = {
+	SET_LATE_SYSTEM_SLEEP_PM_OPS(sdhci_msm_suspend, sdhci_msm_resume)
+	SET_RUNTIME_PM_OPS(sdhci_msm_runtime_suspend, sdhci_msm_runtime_resume,
+				NULL)
+};
+
 static struct platform_driver sdhci_msm_driver = {
 	.probe = sdhci_msm_probe,
 	.remove = sdhci_msm_remove,
 	.driver = {
 		   .name = "sdhci_msm",
 		   .of_match_table = sdhci_msm_dt_match,
+		   .pm = &sdhci_msm_pm_ops,
 	},
 };
 
-- 
1.8.2.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] mmc: sdhci-msm: Add pm_runtime and system PM support
  2016-06-16 12:35 [PATCH] mmc: sdhci-msm: Add pm_runtime and system PM support Pramod Gurav
@ 2016-08-29  8:59 ` Pramod Gurav
  2016-08-29 14:20 ` Ulf Hansson
  2016-09-08  7:47 ` Adrian Hunter
  2 siblings, 0 replies; 7+ messages in thread
From: Pramod Gurav @ 2016-08-29  8:59 UTC (permalink / raw)
  To: adrian.hunter, Ulf Hansson
  Cc: linux-mmc, open list, Pramod Gurav, open list:ARM/QUALCOMM SUPPORT

Hi Ulf,


On 16 June 2016 at 18:05, Pramod Gurav <pramod.gurav@linaro.org> wrote:
> Provides runtime PM callbacks to enable and disable clock resources
> when idle. Also support system PM callbacks to be called during system
> suspend and resume.
>
> Signed-off-by: Pramod Gurav <pramod.gurav@linaro.org>

Any comments on this patch?

> ---
>  drivers/mmc/host/sdhci-msm.c | 57 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 57 insertions(+)
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mmc: sdhci-msm: Add pm_runtime and system PM support
  2016-06-16 12:35 [PATCH] mmc: sdhci-msm: Add pm_runtime and system PM support Pramod Gurav
  2016-08-29  8:59 ` Pramod Gurav
@ 2016-08-29 14:20 ` Ulf Hansson
  2016-08-31  5:22   ` Pramod Gurav
  2016-09-08  7:47 ` Adrian Hunter
  2 siblings, 1 reply; 7+ messages in thread
From: Ulf Hansson @ 2016-08-29 14:20 UTC (permalink / raw)
  To: Pramod Gurav; +Cc: Adrian Hunter, linux-mmc, linux-kernel

On 16 June 2016 at 14:35, Pramod Gurav <pramod.gurav@linaro.org> wrote:
> Provides runtime PM callbacks to enable and disable clock resources
> when idle. Also support system PM callbacks to be called during system
> suspend and resume.
>
> Signed-off-by: Pramod Gurav <pramod.gurav@linaro.org>
> ---
>  drivers/mmc/host/sdhci-msm.c | 57 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 57 insertions(+)
>
> diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
> index 0653fe7..f4394c8 100644
> --- a/drivers/mmc/host/sdhci-msm.c
> +++ b/drivers/mmc/host/sdhci-msm.c
> @@ -18,6 +18,7 @@
>  #include <linux/of_device.h>
>  #include <linux/delay.h>
>  #include <linux/mmc/mmc.h>
> +#include <linux/pm_runtime.h>
>  #include <linux/slab.h>
>
>  #include "sdhci-pltfm.h"
> @@ -549,6 +550,11 @@ static int sdhci_msm_probe(struct platform_device *pdev)
>         if (ret)
>                 goto clk_disable;
>
> +       platform_set_drvdata(pdev, msm_host);
> +
> +       pm_runtime_set_active(&pdev->dev);
> +       pm_runtime_enable(&pdev->dev);

I think you need to move these a bit earlier, before calling sdhci_add_host().

Maybe it's just easier if you look at the sdhci-of-at91.c driver,
which behaves nicely around runtime PM deployment. You can probably
use the very similar code, except the ->runtime_suspend|resume()
callbacks.

And don't forget to deploy runtime PM support in the ->remove()
callback as well, again sdhci-of-at91 is a good reference.

[...]

Kind regards
Uffe

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mmc: sdhci-msm: Add pm_runtime and system PM support
  2016-08-29 14:20 ` Ulf Hansson
@ 2016-08-31  5:22   ` Pramod Gurav
  0 siblings, 0 replies; 7+ messages in thread
From: Pramod Gurav @ 2016-08-31  5:22 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: Adrian Hunter, linux-mmc, linux-kernel

Thanks Ulf for the review.

On 29 August 2016 at 19:50, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> On 16 June 2016 at 14:35, Pramod Gurav <pramod.gurav@linaro.org> wrote:

<snip>

>> +       platform_set_drvdata(pdev, msm_host);
>> +
>> +       pm_runtime_set_active(&pdev->dev);
>> +       pm_runtime_enable(&pdev->dev);
>
> I think you need to move these a bit earlier, before calling sdhci_add_host().
>
> Maybe it's just easier if you look at the sdhci-of-at91.c driver,
> which behaves nicely around runtime PM deployment. You can probably
> use the very similar code, except the ->runtime_suspend|resume()
> callbacks.
>
> And don't forget to deploy runtime PM support in the ->remove()
> callback as well, again sdhci-of-at91 is a good reference.
>

Will take a look at the said driver and do necessary changes and repost.
Thanks again.

Regards,
Pramod

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mmc: sdhci-msm: Add pm_runtime and system PM support
  2016-06-16 12:35 [PATCH] mmc: sdhci-msm: Add pm_runtime and system PM support Pramod Gurav
  2016-08-29  8:59 ` Pramod Gurav
  2016-08-29 14:20 ` Ulf Hansson
@ 2016-09-08  7:47 ` Adrian Hunter
  2016-09-08  8:00   ` Adrian Hunter
  2 siblings, 1 reply; 7+ messages in thread
From: Adrian Hunter @ 2016-09-08  7:47 UTC (permalink / raw)
  To: Pramod Gurav, ulf.hansson
  Cc: linux-mmc, linux-kernel, Ritesh Harjani, Georgi Djakov, Stephen Boyd

On 16/06/16 15:35, Pramod Gurav wrote:
> Provides runtime PM callbacks to enable and disable clock resources
> when idle. Also support system PM callbacks to be called during system
> suspend and resume.
> 
> Signed-off-by: Pramod Gurav <pramod.gurav@linaro.org>

Can we get some Tested/Reviewed/Acked-by from people using this driver?

> ---
>  drivers/mmc/host/sdhci-msm.c | 57 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 57 insertions(+)
> 
> diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
> index 0653fe7..f4394c8 100644
> --- a/drivers/mmc/host/sdhci-msm.c
> +++ b/drivers/mmc/host/sdhci-msm.c
> @@ -18,6 +18,7 @@
>  #include <linux/of_device.h>
>  #include <linux/delay.h>
>  #include <linux/mmc/mmc.h>
> +#include <linux/pm_runtime.h>
>  #include <linux/slab.h>
>  
>  #include "sdhci-pltfm.h"
> @@ -549,6 +550,11 @@ static int sdhci_msm_probe(struct platform_device *pdev)
>  	if (ret)
>  		goto clk_disable;
>  
> +	platform_set_drvdata(pdev, msm_host);
> +
> +	pm_runtime_set_active(&pdev->dev);
> +	pm_runtime_enable(&pdev->dev);
> +
>  	return 0;
>  
>  clk_disable:
> @@ -580,12 +586,63 @@ static int sdhci_msm_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +static int sdhci_msm_runtime_suspend(struct device *dev)
> +{
> +	struct sdhci_msm_host *msm_host = dev_get_drvdata(dev);
> +
> +	clk_disable_unprepare(msm_host->clk);
> +	clk_disable_unprepare(msm_host->pclk);
> +
> +	return 0;
> +}
> +
> +static int sdhci_msm_runtime_resume(struct device *dev)
> +{
> +	struct sdhci_msm_host *msm_host = dev_get_drvdata(dev);
> +	int ret;
> +
> +	ret = clk_prepare_enable(msm_host->clk);
> +	if (ret) {
> +		dev_err(dev, "clk_enable failed: %d\n", ret);
> +		return ret;
> +	}
> +	ret = clk_prepare_enable(msm_host->pclk);
> +	if (ret) {
> +		dev_err(dev, "clk_enable failed: %d\n", ret);
> +		clk_disable_unprepare(msm_host->clk);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +static int sdhci_msm_suspend(struct device *dev)
> +{
> +	pm_runtime_force_suspend(dev);
> +
> +	return 0;
> +}
> +
> +static int sdhci_msm_resume(struct device *dev)
> +{
> +	pm_runtime_force_resume(dev);
> +
> +	return 0;
> +}
> +
> +static const struct dev_pm_ops sdhci_msm_pm_ops = {
> +	SET_LATE_SYSTEM_SLEEP_PM_OPS(sdhci_msm_suspend, sdhci_msm_resume)
> +	SET_RUNTIME_PM_OPS(sdhci_msm_runtime_suspend, sdhci_msm_runtime_resume,
> +				NULL)
> +};
> +
>  static struct platform_driver sdhci_msm_driver = {
>  	.probe = sdhci_msm_probe,
>  	.remove = sdhci_msm_remove,
>  	.driver = {
>  		   .name = "sdhci_msm",
>  		   .of_match_table = sdhci_msm_dt_match,
> +		   .pm = &sdhci_msm_pm_ops,
>  	},
>  };
>  
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mmc: sdhci-msm: Add pm_runtime and system PM support
  2016-09-08  7:47 ` Adrian Hunter
@ 2016-09-08  8:00   ` Adrian Hunter
  0 siblings, 0 replies; 7+ messages in thread
From: Adrian Hunter @ 2016-09-08  8:00 UTC (permalink / raw)
  To: Adrian Hunter, Pramod Gurav, ulf.hansson
  Cc: linux-mmc, linux-kernel, Ritesh Harjani, Georgi Djakov, Stephen Boyd

On 08/09/16 10:47, Adrian Hunter wrote:
> On 16/06/16 15:35, Pramod Gurav wrote:
>> Provides runtime PM callbacks to enable and disable clock resources
>> when idle. Also support system PM callbacks to be called during system
>> suspend and resume.
>>
>> Signed-off-by: Pramod Gurav <pramod.gurav@linaro.org>
> 
> Can we get some Tested/Reviewed/Acked-by from people using this driver?

Oops wrong version of the patch.  Please disregard the comment for this
patch, and see instead the later patch.

> 
>> ---
>>  drivers/mmc/host/sdhci-msm.c | 57 ++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 57 insertions(+)
>>
>> diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
>> index 0653fe7..f4394c8 100644
>> --- a/drivers/mmc/host/sdhci-msm.c
>> +++ b/drivers/mmc/host/sdhci-msm.c
>> @@ -18,6 +18,7 @@
>>  #include <linux/of_device.h>
>>  #include <linux/delay.h>
>>  #include <linux/mmc/mmc.h>
>> +#include <linux/pm_runtime.h>
>>  #include <linux/slab.h>
>>  
>>  #include "sdhci-pltfm.h"
>> @@ -549,6 +550,11 @@ static int sdhci_msm_probe(struct platform_device *pdev)
>>  	if (ret)
>>  		goto clk_disable;
>>  
>> +	platform_set_drvdata(pdev, msm_host);
>> +
>> +	pm_runtime_set_active(&pdev->dev);
>> +	pm_runtime_enable(&pdev->dev);
>> +
>>  	return 0;
>>  
>>  clk_disable:
>> @@ -580,12 +586,63 @@ static int sdhci_msm_remove(struct platform_device *pdev)
>>  	return 0;
>>  }
>>  
>> +static int sdhci_msm_runtime_suspend(struct device *dev)
>> +{
>> +	struct sdhci_msm_host *msm_host = dev_get_drvdata(dev);
>> +
>> +	clk_disable_unprepare(msm_host->clk);
>> +	clk_disable_unprepare(msm_host->pclk);
>> +
>> +	return 0;
>> +}
>> +
>> +static int sdhci_msm_runtime_resume(struct device *dev)
>> +{
>> +	struct sdhci_msm_host *msm_host = dev_get_drvdata(dev);
>> +	int ret;
>> +
>> +	ret = clk_prepare_enable(msm_host->clk);
>> +	if (ret) {
>> +		dev_err(dev, "clk_enable failed: %d\n", ret);
>> +		return ret;
>> +	}
>> +	ret = clk_prepare_enable(msm_host->pclk);
>> +	if (ret) {
>> +		dev_err(dev, "clk_enable failed: %d\n", ret);
>> +		clk_disable_unprepare(msm_host->clk);
>> +		return ret;
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>> +static int sdhci_msm_suspend(struct device *dev)
>> +{
>> +	pm_runtime_force_suspend(dev);
>> +
>> +	return 0;
>> +}
>> +
>> +static int sdhci_msm_resume(struct device *dev)
>> +{
>> +	pm_runtime_force_resume(dev);
>> +
>> +	return 0;
>> +}
>> +
>> +static const struct dev_pm_ops sdhci_msm_pm_ops = {
>> +	SET_LATE_SYSTEM_SLEEP_PM_OPS(sdhci_msm_suspend, sdhci_msm_resume)
>> +	SET_RUNTIME_PM_OPS(sdhci_msm_runtime_suspend, sdhci_msm_runtime_resume,
>> +				NULL)
>> +};
>> +
>>  static struct platform_driver sdhci_msm_driver = {
>>  	.probe = sdhci_msm_probe,
>>  	.remove = sdhci_msm_remove,
>>  	.driver = {
>>  		   .name = "sdhci_msm",
>>  		   .of_match_table = sdhci_msm_dt_match,
>> +		   .pm = &sdhci_msm_pm_ops,
>>  	},
>>  };
>>  
>>
> 
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] mmc: sdhci-msm: Add pm_runtime and system PM support
@ 2016-09-01 14:17 Pramod Gurav
  0 siblings, 0 replies; 7+ messages in thread
From: Pramod Gurav @ 2016-09-01 14:17 UTC (permalink / raw)
  To: linux-mmc, linux-arm-msm
  Cc: linux-kernel, adrian.hunter, ulf.hansson, Pramod Gurav

Provides runtime PM callbacks to enable and disable clock resources
when idle. Also support system PM callbacks to be called during system
suspend and resume.

Signed-off-by: Pramod Gurav <pramod.gurav@linaro.org>
---
Changes in v1:
- Added CONFIG_PM around runtime pm function.
- Replaced msm suspend/resume with generic function directly

Changes in v2:
- Moved pm_rutime enabling before adding host
- Handled pm_rutime in remove
- Changed runtime handling with reference from sdhci-of-at91.c

 drivers/mmc/host/sdhci-msm.c | 71 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 70 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
index 8ef44a2a..881c564 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -18,6 +18,7 @@
 #include <linux/of_device.h>
 #include <linux/delay.h>
 #include <linux/mmc/mmc.h>
+#include <linux/pm_runtime.h>
 #include <linux/slab.h>
 
 #include "sdhci-pltfm.h"
@@ -658,12 +659,26 @@ static int sdhci_msm_probe(struct platform_device *pdev)
 		goto clk_disable;
 	}
 
+	pm_runtime_get_noresume(&pdev->dev);
+	pm_runtime_set_active(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+	pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
+	pm_runtime_use_autosuspend(&pdev->dev);
+
 	ret = sdhci_add_host(host);
 	if (ret)
-		goto clk_disable;
+		goto pm_runtime_disable;
+
+	platform_set_drvdata(pdev, host);
+
+	pm_runtime_put_autosuspend(&pdev->dev);
 
 	return 0;
 
+pm_runtime_disable:
+	pm_runtime_disable(&pdev->dev);
+	pm_runtime_set_suspended(&pdev->dev);
+	pm_runtime_put_noidle(&pdev->dev);
 clk_disable:
 	clk_disable_unprepare(msm_host->clk);
 pclk_disable:
@@ -685,6 +700,11 @@ static int sdhci_msm_remove(struct platform_device *pdev)
 		    0xffffffff);
 
 	sdhci_remove_host(host, dead);
+
+	pm_runtime_get_sync(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+	pm_runtime_put_noidle(&pdev->dev);
+
 	clk_disable_unprepare(msm_host->clk);
 	clk_disable_unprepare(msm_host->pclk);
 	if (!IS_ERR(msm_host->bus_clk))
@@ -693,12 +713,61 @@ static int sdhci_msm_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM
+static int sdhci_msm_runtime_suspend(struct device *dev)
+{
+	struct sdhci_host *host = dev_get_drvdata(dev);
+	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+	struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
+	int ret;
+
+	ret = sdhci_runtime_suspend_host(host);
+	if (ret)
+		return ret;
+
+	clk_disable_unprepare(msm_host->clk);
+	clk_disable_unprepare(msm_host->pclk);
+
+	return 0;
+}
+
+static int sdhci_msm_runtime_resume(struct device *dev)
+{
+	struct sdhci_host *host = dev_get_drvdata(dev);
+	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+	struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
+	int ret;
+
+	ret = clk_prepare_enable(msm_host->clk);
+	if (ret) {
+		dev_err(dev, "clk_enable failed: %d\n", ret);
+		return ret;
+	}
+	ret = clk_prepare_enable(msm_host->pclk);
+	if (ret) {
+		dev_err(dev, "clk_enable failed: %d\n", ret);
+		clk_disable_unprepare(msm_host->clk);
+		return ret;
+	}
+
+	return sdhci_runtime_resume_host(host);
+}
+#endif
+
+static const struct dev_pm_ops sdhci_msm_pm_ops = {
+	SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
+					pm_runtime_force_resume)
+	SET_RUNTIME_PM_OPS(sdhci_msm_runtime_suspend, sdhci_msm_runtime_resume,
+				NULL)
+};
+
 static struct platform_driver sdhci_msm_driver = {
 	.probe = sdhci_msm_probe,
 	.remove = sdhci_msm_remove,
 	.driver = {
 		   .name = "sdhci_msm",
 		   .of_match_table = sdhci_msm_dt_match,
+		   .pm = &sdhci_msm_pm_ops,
 	},
 };
 
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-09-08  8:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-16 12:35 [PATCH] mmc: sdhci-msm: Add pm_runtime and system PM support Pramod Gurav
2016-08-29  8:59 ` Pramod Gurav
2016-08-29 14:20 ` Ulf Hansson
2016-08-31  5:22   ` Pramod Gurav
2016-09-08  7:47 ` Adrian Hunter
2016-09-08  8:00   ` Adrian Hunter
2016-09-01 14:17 Pramod Gurav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).