All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] add runtime pm support for xenon
@ 2017-08-24 22:19 Zhoujie Wu
  2017-08-24 22:19 ` [PATCH 1/2] mmc: sdhci-xenon: add runtime pm support Zhoujie Wu
  2017-08-24 22:19 ` [PATCH 2/2] mmc: sdhci-xenon: implement system standby base on runtime pm Zhoujie Wu
  0 siblings, 2 replies; 5+ messages in thread
From: Zhoujie Wu @ 2017-08-24 22:19 UTC (permalink / raw)
  To: ulf.hansson, adrian.hunter, linux-mmc
  Cc: zmxu, jszhang, nadavh, xigu, xswang, dingwei, kostap, hannah,
	hongd, dougj, ygao, liuw, gregory.clement, thomas.petazzoni

These two patches added runtime pm support for xenon and
re-implemented standby support based on runtime pm API.

Zhoujie Wu (2):
  mmc: sdhci-xenon: add runtime pm support
  mmc: sdhci-xenon: implement system standby base on runtime pm

 drivers/mmc/host/sdhci-xenon.c | 76 ++++++++++++++++++++++++++++++++----------
 drivers/mmc/host/sdhci-xenon.h |  1 +
 2 files changed, 60 insertions(+), 17 deletions(-)

-- 
1.9.1


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

* [PATCH 1/2] mmc: sdhci-xenon: add runtime pm support
  2017-08-24 22:19 [PATCH 0/2] add runtime pm support for xenon Zhoujie Wu
@ 2017-08-24 22:19 ` Zhoujie Wu
  2017-08-28 11:49   ` Adrian Hunter
  2017-08-24 22:19 ` [PATCH 2/2] mmc: sdhci-xenon: implement system standby base on runtime pm Zhoujie Wu
  1 sibling, 1 reply; 5+ messages in thread
From: Zhoujie Wu @ 2017-08-24 22:19 UTC (permalink / raw)
  To: ulf.hansson, adrian.hunter, linux-mmc
  Cc: zmxu, jszhang, nadavh, xigu, xswang, dingwei, kostap, hannah,
	hongd, dougj, ygao, liuw, gregory.clement, thomas.petazzoni,
	Zhoujie Wu

Enable runtime pm support for xenon controller, which uses 50ms
auto runtime suspend by default.

Signed-off-by: Zhoujie Wu <zjwu@marvell.com>
---
 drivers/mmc/host/sdhci-xenon.c | 61 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 60 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-xenon.c b/drivers/mmc/host/sdhci-xenon.c
index 306ffaf..517ff2e 100644
--- a/drivers/mmc/host/sdhci-xenon.c
+++ b/drivers/mmc/host/sdhci-xenon.c
@@ -18,6 +18,8 @@
 #include <linux/ktime.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/pm.h>
+#include <linux/pm_runtime.h>
 
 #include "sdhci-pltfm.h"
 #include "sdhci-xenon.h"
@@ -506,13 +508,24 @@ static int xenon_probe(struct platform_device *pdev)
 	if (err)
 		goto err_clk;
 
+	pm_runtime_get_noresume(&pdev->dev);
+	pm_runtime_set_active(&pdev->dev);
+	pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+	pm_suspend_ignore_children(&pdev->dev, 1);
+
 	err = sdhci_add_host(host);
 	if (err)
 		goto remove_sdhc;
 
+	pm_runtime_put_autosuspend(&pdev->dev);
+
 	return 0;
 
 remove_sdhc:
+	pm_runtime_disable(&pdev->dev);
+	pm_runtime_put_noidle(&pdev->dev);
 	xenon_sdhc_unprepare(host);
 err_clk:
 	clk_disable_unprepare(pltfm_host->clk);
@@ -577,6 +590,52 @@ static int xenon_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(xenon_pmops, xenon_suspend, xenon_resume);
 
+#ifdef CONFIG_PM
+static int xenon_runtime_suspend(struct device *dev)
+{
+	struct sdhci_host *host = dev_get_drvdata(dev);
+	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+	struct xenon_priv *priv = sdhci_pltfm_priv(pltfm_host);
+	int ret;
+
+	ret = sdhci_runtime_suspend_host(host);
+
+	if (host->tuning_mode != SDHCI_TUNING_MODE_3)
+		mmc_retune_needed(host->mmc);
+
+	clk_disable_unprepare(pltfm_host->clk);
+	/*
+	 * Need to update the priv->clock here, or when runtime resume
+	 * back, phy don't aware the clock change and won't adjust phy
+	 * which will cause cmd err
+	 */
+	priv->clock = 0;
+	return ret;
+}
+
+static int xenon_runtime_resume(struct device *dev)
+{
+	struct sdhci_host *host = dev_get_drvdata(dev);
+	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+	int ret;
+
+	ret = clk_prepare_enable(pltfm_host->clk);
+	if (ret) {
+		dev_err(dev, "can't enable mainck\n");
+		return ret;
+	}
+
+	return sdhci_runtime_resume_host(host);
+}
+#endif /* CONFIG_PM */
+
+static const struct dev_pm_ops sdhci_xenon_dev_pm_ops = {
+	SET_RUNTIME_PM_OPS(xenon_runtime_suspend,
+			   xenon_runtime_resume,
+			   NULL)
+};
+
+
 static const struct of_device_id sdhci_xenon_dt_ids[] = {
 	{ .compatible = "marvell,armada-ap806-sdhci",},
 	{ .compatible = "marvell,armada-cp110-sdhci",},
@@ -589,7 +648,7 @@ static int xenon_resume(struct device *dev)
 	.driver	= {
 		.name	= "xenon-sdhci",
 		.of_match_table = sdhci_xenon_dt_ids,
-		.pm = &xenon_pmops,
+		.pm = &sdhci_xenon_dev_pm_ops,
 	},
 	.probe	= xenon_probe,
 	.remove	= xenon_remove,
-- 
1.9.1


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

* [PATCH 2/2] mmc: sdhci-xenon: implement system standby base on runtime pm
  2017-08-24 22:19 [PATCH 0/2] add runtime pm support for xenon Zhoujie Wu
  2017-08-24 22:19 ` [PATCH 1/2] mmc: sdhci-xenon: add runtime pm support Zhoujie Wu
@ 2017-08-24 22:19 ` Zhoujie Wu
  1 sibling, 0 replies; 5+ messages in thread
From: Zhoujie Wu @ 2017-08-24 22:19 UTC (permalink / raw)
  To: ulf.hansson, adrian.hunter, linux-mmc
  Cc: zmxu, jszhang, nadavh, xigu, xswang, dingwei, kostap, hannah,
	hongd, dougj, ygao, liuw, gregory.clement, thomas.petazzoni,
	Zhoujie Wu

Implement system standby based on runtime pm API.
Introduce restore_needed to restore the Xenon specific registers
when resume.

Signed-off-by: Zhoujie Wu <zjwu@marvell.com>
---
 drivers/mmc/host/sdhci-xenon.c | 41 ++++++++++++-----------------------------
 drivers/mmc/host/sdhci-xenon.h |  1 +
 2 files changed, 13 insertions(+), 29 deletions(-)

diff --git a/drivers/mmc/host/sdhci-xenon.c b/drivers/mmc/host/sdhci-xenon.c
index 517ff2e..d40ec46 100644
--- a/drivers/mmc/host/sdhci-xenon.c
+++ b/drivers/mmc/host/sdhci-xenon.c
@@ -555,40 +555,15 @@ static int xenon_suspend(struct device *dev)
 {
 	struct sdhci_host *host = dev_get_drvdata(dev);
 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+	struct xenon_priv *priv = sdhci_pltfm_priv(pltfm_host);
 	int ret;
 
-	ret = sdhci_suspend_host(host);
-	if (ret)
-		return ret;
+	ret = pm_runtime_force_suspend(dev);
 
-	clk_disable_unprepare(pltfm_host->clk);
+	priv->restore_needed = true;
 	return ret;
 }
-
-static int xenon_resume(struct device *dev)
-{
-	struct sdhci_host *host = dev_get_drvdata(dev);
-	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
-	int ret;
-
-	ret = clk_prepare_enable(pltfm_host->clk);
-	if (ret)
-		return ret;
-
-	/*
-	 * If SoCs power off the entire Xenon, registers setting will
-	 * be lost.
-	 * Re-configure Xenon specific register to enable current SDHC
-	 */
-	ret = xenon_sdhc_prepare(host);
-	if (ret)
-		return ret;
-
-	return sdhci_resume_host(host);
-}
-#endif
-
-static SIMPLE_DEV_PM_OPS(xenon_pmops, xenon_suspend, xenon_resume);
+#endif /* CONFIG_PM_SLEEP */
 
 #ifdef CONFIG_PM
 static int xenon_runtime_suspend(struct device *dev)
@@ -617,6 +592,7 @@ static int xenon_runtime_resume(struct device *dev)
 {
 	struct sdhci_host *host = dev_get_drvdata(dev);
 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+	struct xenon_priv *priv = sdhci_pltfm_priv(pltfm_host);
 	int ret;
 
 	ret = clk_prepare_enable(pltfm_host->clk);
@@ -625,11 +601,18 @@ static int xenon_runtime_resume(struct device *dev)
 		return ret;
 	}
 
+	if (priv->restore_needed) {
+		xenon_sdhc_prepare(host);
+		priv->restore_needed = false;
+	}
+
 	return sdhci_runtime_resume_host(host);
 }
 #endif /* CONFIG_PM */
 
 static const struct dev_pm_ops sdhci_xenon_dev_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(xenon_suspend,
+				pm_runtime_force_resume)
 	SET_RUNTIME_PM_OPS(xenon_runtime_suspend,
 			   xenon_runtime_resume,
 			   NULL)
diff --git a/drivers/mmc/host/sdhci-xenon.h b/drivers/mmc/host/sdhci-xenon.h
index 01937f1..2bc0510 100644
--- a/drivers/mmc/host/sdhci-xenon.h
+++ b/drivers/mmc/host/sdhci-xenon.h
@@ -91,6 +91,7 @@ struct xenon_priv {
 	 */
 	void		*phy_params;
 	struct xenon_emmc_phy_regs *emmc_phy_regs;
+	bool restore_needed;
 };
 
 int xenon_phy_adj(struct sdhci_host *host, struct mmc_ios *ios);
-- 
1.9.1


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

* Re: [PATCH 1/2] mmc: sdhci-xenon: add runtime pm support
  2017-08-24 22:19 ` [PATCH 1/2] mmc: sdhci-xenon: add runtime pm support Zhoujie Wu
@ 2017-08-28 11:49   ` Adrian Hunter
  2017-08-28 18:36     ` Zhoujie Wu
  0 siblings, 1 reply; 5+ messages in thread
From: Adrian Hunter @ 2017-08-28 11:49 UTC (permalink / raw)
  To: Zhoujie Wu, ulf.hansson, linux-mmc
  Cc: zmxu, jszhang, nadavh, xigu, xswang, dingwei, kostap, hannah,
	hongd, dougj, ygao, liuw, gregory.clement, thomas.petazzoni

On 25/08/17 01:19, Zhoujie Wu wrote:
> Enable runtime pm support for xenon controller, which uses 50ms
> auto runtime suspend by default.

This patch seems to break system system.  Does it really make sense to have
2 separate patches?  Maybe consider putting them together.

> 
> Signed-off-by: Zhoujie Wu <zjwu@marvell.com>
> ---
>  drivers/mmc/host/sdhci-xenon.c | 61 +++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 60 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mmc/host/sdhci-xenon.c b/drivers/mmc/host/sdhci-xenon.c
> index 306ffaf..517ff2e 100644
> --- a/drivers/mmc/host/sdhci-xenon.c
> +++ b/drivers/mmc/host/sdhci-xenon.c
> @@ -18,6 +18,8 @@
>  #include <linux/ktime.h>
>  #include <linux/module.h>
>  #include <linux/of.h>
> +#include <linux/pm.h>
> +#include <linux/pm_runtime.h>
>  
>  #include "sdhci-pltfm.h"
>  #include "sdhci-xenon.h"
> @@ -506,13 +508,24 @@ static int xenon_probe(struct platform_device *pdev)
>  	if (err)
>  		goto err_clk;
>  
> +	pm_runtime_get_noresume(&pdev->dev);
> +	pm_runtime_set_active(&pdev->dev);
> +	pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
> +	pm_runtime_use_autosuspend(&pdev->dev);
> +	pm_runtime_enable(&pdev->dev);

I would expect to see a corresponding pm_runtime_disable() in xenon_remove()
e.g.

	pm_runtime_get_sync(dev);
	pm_runtime_disable(dev);
	pm_runtime_put_noidle(dev);

	sdhci_remove_host(host, 0);

> +	pm_suspend_ignore_children(&pdev->dev, 1);
> +
>  	err = sdhci_add_host(host);
>  	if (err)
>  		goto remove_sdhc;
>  
> +	pm_runtime_put_autosuspend(&pdev->dev);
> +
>  	return 0;
>  
>  remove_sdhc:
> +	pm_runtime_disable(&pdev->dev);
> +	pm_runtime_put_noidle(&pdev->dev);
>  	xenon_sdhc_unprepare(host);
>  err_clk:
>  	clk_disable_unprepare(pltfm_host->clk);
> @@ -577,6 +590,52 @@ static int xenon_resume(struct device *dev)
>  
>  static SIMPLE_DEV_PM_OPS(xenon_pmops, xenon_suspend, xenon_resume);
>  
> +#ifdef CONFIG_PM
> +static int xenon_runtime_suspend(struct device *dev)
> +{
> +	struct sdhci_host *host = dev_get_drvdata(dev);
> +	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
> +	struct xenon_priv *priv = sdhci_pltfm_priv(pltfm_host);
> +	int ret;
> +
> +	ret = sdhci_runtime_suspend_host(host);
> +
> +	if (host->tuning_mode != SDHCI_TUNING_MODE_3)
> +		mmc_retune_needed(host->mmc);
> +
> +	clk_disable_unprepare(pltfm_host->clk);
> +	/*
> +	 * Need to update the priv->clock here, or when runtime resume
> +	 * back, phy don't aware the clock change and won't adjust phy
> +	 * which will cause cmd err
> +	 */
> +	priv->clock = 0;
> +	return ret;
> +}
> +
> +static int xenon_runtime_resume(struct device *dev)
> +{
> +	struct sdhci_host *host = dev_get_drvdata(dev);
> +	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
> +	int ret;
> +
> +	ret = clk_prepare_enable(pltfm_host->clk);
> +	if (ret) {
> +		dev_err(dev, "can't enable mainck\n");
> +		return ret;
> +	}
> +
> +	return sdhci_runtime_resume_host(host);
> +}
> +#endif /* CONFIG_PM */
> +
> +static const struct dev_pm_ops sdhci_xenon_dev_pm_ops = {
> +	SET_RUNTIME_PM_OPS(xenon_runtime_suspend,
> +			   xenon_runtime_resume,
> +			   NULL)
> +};
> +
> +
>  static const struct of_device_id sdhci_xenon_dt_ids[] = {
>  	{ .compatible = "marvell,armada-ap806-sdhci",},
>  	{ .compatible = "marvell,armada-cp110-sdhci",},
> @@ -589,7 +648,7 @@ static int xenon_resume(struct device *dev)
>  	.driver	= {
>  		.name	= "xenon-sdhci",
>  		.of_match_table = sdhci_xenon_dt_ids,
> -		.pm = &xenon_pmops,
> +		.pm = &sdhci_xenon_dev_pm_ops,
>  	},
>  	.probe	= xenon_probe,
>  	.remove	= xenon_remove,
> 


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

* Re: [PATCH 1/2] mmc: sdhci-xenon: add runtime pm support
  2017-08-28 11:49   ` Adrian Hunter
@ 2017-08-28 18:36     ` Zhoujie Wu
  0 siblings, 0 replies; 5+ messages in thread
From: Zhoujie Wu @ 2017-08-28 18:36 UTC (permalink / raw)
  To: Adrian Hunter, ulf.hansson, linux-mmc
  Cc: zmxu, jszhang, nadavh, xigu, xswang, dingwei, kostap, hannah,
	hongd, dougj, ygao, liuw, gregory.clement, thomas.petazzoni

Hi,

On 08/28/2017 04:49 AM, Adrian Hunter wrote:
> On 25/08/17 01:19, Zhoujie Wu wrote:
>> Enable runtime pm support for xenon controller, which uses 50ms
>> auto runtime suspend by default.
> This patch seems to break system system.  Does it really make sense to have
> 2 separate patches?  Maybe consider putting them together.
You are right, I will put them together. thanks.
>> Signed-off-by: Zhoujie Wu <zjwu@marvell.com>
>> ---
>>   drivers/mmc/host/sdhci-xenon.c | 61 +++++++++++++++++++++++++++++++++++++++++-
>>   1 file changed, 60 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/mmc/host/sdhci-xenon.c b/drivers/mmc/host/sdhci-xenon.c
>> index 306ffaf..517ff2e 100644
>> --- a/drivers/mmc/host/sdhci-xenon.c
>> +++ b/drivers/mmc/host/sdhci-xenon.c
>> @@ -18,6 +18,8 @@
>>   #include <linux/ktime.h>
>>   #include <linux/module.h>
>>   #include <linux/of.h>
>> +#include <linux/pm.h>
>> +#include <linux/pm_runtime.h>
>>   
>>   #include "sdhci-pltfm.h"
>>   #include "sdhci-xenon.h"
>> @@ -506,13 +508,24 @@ static int xenon_probe(struct platform_device *pdev)
>>   	if (err)
>>   		goto err_clk;
>>   
>> +	pm_runtime_get_noresume(&pdev->dev);
>> +	pm_runtime_set_active(&pdev->dev);
>> +	pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
>> +	pm_runtime_use_autosuspend(&pdev->dev);
>> +	pm_runtime_enable(&pdev->dev);
> I would expect to see a corresponding pm_runtime_disable() in xenon_remove()
> e.g.
>
> 	pm_runtime_get_sync(dev);
> 	pm_runtime_disable(dev);
> 	pm_runtime_put_noidle(dev);
>
> 	sdhci_remove_host(host, 0);
>
>> +	pm_suspend_ignore_children(&pdev->dev, 1);
>> +
>>   	err = sdhci_add_host(host);
>>   	if (err)
>>   		goto remove_sdhc;
>>   
>> +	pm_runtime_put_autosuspend(&pdev->dev);
>> +
>>   	return 0;
>>   
>>   remove_sdhc:
>> +	pm_runtime_disable(&pdev->dev);
>> +	pm_runtime_put_noidle(&pdev->dev);
>>   	xenon_sdhc_unprepare(host);
>>   err_clk:
>>   	clk_disable_unprepare(pltfm_host->clk);
>> @@ -577,6 +590,52 @@ static int xenon_resume(struct device *dev)
>>   
>>   static SIMPLE_DEV_PM_OPS(xenon_pmops, xenon_suspend, xenon_resume);
>>   
>> +#ifdef CONFIG_PM
>> +static int xenon_runtime_suspend(struct device *dev)
>> +{
>> +	struct sdhci_host *host = dev_get_drvdata(dev);
>> +	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
>> +	struct xenon_priv *priv = sdhci_pltfm_priv(pltfm_host);
>> +	int ret;
>> +
>> +	ret = sdhci_runtime_suspend_host(host);
>> +
>> +	if (host->tuning_mode != SDHCI_TUNING_MODE_3)
>> +		mmc_retune_needed(host->mmc);
>> +
>> +	clk_disable_unprepare(pltfm_host->clk);
>> +	/*
>> +	 * Need to update the priv->clock here, or when runtime resume
>> +	 * back, phy don't aware the clock change and won't adjust phy
>> +	 * which will cause cmd err
>> +	 */
>> +	priv->clock = 0;
>> +	return ret;
>> +}
>> +
>> +static int xenon_runtime_resume(struct device *dev)
>> +{
>> +	struct sdhci_host *host = dev_get_drvdata(dev);
>> +	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
>> +	int ret;
>> +
>> +	ret = clk_prepare_enable(pltfm_host->clk);
>> +	if (ret) {
>> +		dev_err(dev, "can't enable mainck\n");
>> +		return ret;
>> +	}
>> +
>> +	return sdhci_runtime_resume_host(host);
>> +}
>> +#endif /* CONFIG_PM */
>> +
>> +static const struct dev_pm_ops sdhci_xenon_dev_pm_ops = {
>> +	SET_RUNTIME_PM_OPS(xenon_runtime_suspend,
>> +			   xenon_runtime_resume,
>> +			   NULL)
>> +};
>> +
>> +
>>   static const struct of_device_id sdhci_xenon_dt_ids[] = {
>>   	{ .compatible = "marvell,armada-ap806-sdhci",},
>>   	{ .compatible = "marvell,armada-cp110-sdhci",},
>> @@ -589,7 +648,7 @@ static int xenon_resume(struct device *dev)
>>   	.driver	= {
>>   		.name	= "xenon-sdhci",
>>   		.of_match_table = sdhci_xenon_dt_ids,
>> -		.pm = &xenon_pmops,
>> +		.pm = &sdhci_xenon_dev_pm_ops,
>>   	},
>>   	.probe	= xenon_probe,
>>   	.remove	= xenon_remove,
>>


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

end of thread, other threads:[~2017-08-28 18:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-24 22:19 [PATCH 0/2] add runtime pm support for xenon Zhoujie Wu
2017-08-24 22:19 ` [PATCH 1/2] mmc: sdhci-xenon: add runtime pm support Zhoujie Wu
2017-08-28 11:49   ` Adrian Hunter
2017-08-28 18:36     ` Zhoujie Wu
2017-08-24 22:19 ` [PATCH 2/2] mmc: sdhci-xenon: implement system standby base on runtime pm Zhoujie Wu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.