linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi/atmel: add support for runtime PM
@ 2014-10-16  1:49 Wenyou Yang
  2014-10-16  7:30 ` Mark Brown
  2014-10-17 13:02 ` Kevin Hilman
  0 siblings, 2 replies; 11+ messages in thread
From: Wenyou Yang @ 2014-10-16  1:49 UTC (permalink / raw)
  To: broonie
  Cc: linux-spi, linux-kernel, nicolas.ferre, wenyou.yang, linux-arm-kernel

Drivers should put the device into low power states proactively whenever the
device is not in use. Thus implement support for runtime PM and use the
autosuspend feature to make sure that we can still perform well in case we see
lots of SPI traffic within short period of time.

Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
---
 drivers/spi/spi-atmel.c |   62 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 55 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index 649dcb5..aca285e 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -26,6 +26,7 @@
 #include <linux/io.h>
 #include <linux/gpio.h>
 #include <linux/pinctrl/consumer.h>
+#include <linux/pm_runtime.h>
 
 /* SPI register offsets */
 #define SPI_CR					0x0000
@@ -191,6 +192,8 @@
 
 #define SPI_DMA_TIMEOUT		(msecs_to_jiffies(1000))
 
+#define AUTOSUSPEND_TIMEOUT	2000
+
 struct atmel_spi_dma {
 	struct dma_chan			*chan_rx;
 	struct dma_chan			*chan_tx;
@@ -1313,6 +1316,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
 	master->setup = atmel_spi_setup;
 	master->transfer_one_message = atmel_spi_transfer_one_message;
 	master->cleanup = atmel_spi_cleanup;
+	master->auto_runtime_pm = true;
 	platform_set_drvdata(pdev, master);
 
 	as = spi_master_get_devdata(master);
@@ -1385,6 +1389,11 @@ static int atmel_spi_probe(struct platform_device *pdev)
 	dev_info(&pdev->dev, "Atmel SPI Controller at 0x%08lx (irq %d)\n",
 			(unsigned long)regs->start, irq);
 
+	pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT);
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_set_active(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+
 	ret = devm_spi_register_master(&pdev->dev, master);
 	if (ret)
 		goto out_free_dma;
@@ -1392,6 +1401,9 @@ static int atmel_spi_probe(struct platform_device *pdev)
 	return 0;
 
 out_free_dma:
+	pm_runtime_disable(&pdev->dev);
+	pm_runtime_set_suspended(&pdev->dev);
+
 	if (as->use_dma)
 		atmel_spi_release_dma(as);
 
@@ -1413,6 +1425,8 @@ static int atmel_spi_remove(struct platform_device *pdev)
 	struct spi_master	*master = platform_get_drvdata(pdev);
 	struct atmel_spi	*as = spi_master_get_devdata(master);
 
+	pm_runtime_get_sync(&pdev->dev);
+
 	/* reset the hardware and block queue progress */
 	spin_lock_irq(&as->lock);
 	if (as->use_dma) {
@@ -1430,9 +1444,13 @@ static int atmel_spi_remove(struct platform_device *pdev)
 
 	clk_disable_unprepare(as->clk);
 
+	pm_runtime_put_noidle(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+
 	return 0;
 }
 
+#ifdef CONFIG_PM
 #ifdef CONFIG_PM_SLEEP
 static int atmel_spi_suspend(struct device *dev)
 {
@@ -1447,9 +1465,10 @@ static int atmel_spi_suspend(struct device *dev)
 		return ret;
 	}
 
-	clk_disable_unprepare(as->clk);
-
-	pinctrl_pm_select_sleep_state(dev);
+	if (!pm_runtime_suspended(dev)) {
+		clk_disable_unprepare(as->clk);
+		pinctrl_pm_select_sleep_state(dev);
+	}
 
 	return 0;
 }
@@ -1460,9 +1479,10 @@ static int atmel_spi_resume(struct device *dev)
 	struct atmel_spi	*as = spi_master_get_devdata(master);
 	int ret;
 
-	pinctrl_pm_select_default_state(dev);
-
-	clk_prepare_enable(as->clk);
+	if (!pm_runtime_suspended(dev)) {
+		pinctrl_pm_select_default_state(dev);
+		clk_prepare_enable(as->clk);
+	}
 
 	/* Start the queue running */
 	ret = spi_master_resume(master);
@@ -1471,9 +1491,37 @@ static int atmel_spi_resume(struct device *dev)
 
 	return ret;
 }
+#endif
 
-static SIMPLE_DEV_PM_OPS(atmel_spi_pm_ops, atmel_spi_suspend, atmel_spi_resume);
+#ifdef CONFIG_PM_RUNTIME
+static int atmel_spi_runtime_suspend(struct device *dev)
+{
+	struct spi_master *master = dev_get_drvdata(dev);
+	struct atmel_spi *as = spi_master_get_devdata(master);
 
+	clk_disable_unprepare(as->clk);
+	pinctrl_pm_select_sleep_state(dev);
+
+	return 0;
+}
+
+static int atmel_spi_runtime_resume(struct device *dev)
+{
+	struct spi_master *master = dev_get_drvdata(dev);
+	struct atmel_spi *as = spi_master_get_devdata(master);
+
+	pinctrl_pm_select_default_state(dev);
+	clk_prepare_enable(as->clk);
+
+	return 0;
+}
+#endif
+
+static const struct dev_pm_ops atmel_spi_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(atmel_spi_suspend, atmel_spi_resume)
+	SET_RUNTIME_PM_OPS(atmel_spi_runtime_suspend,
+			   atmel_spi_runtime_resume, NULL)
+};
 #define ATMEL_SPI_PM_OPS	(&atmel_spi_pm_ops)
 #else
 #define ATMEL_SPI_PM_OPS	NULL
-- 
1.7.9.5


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

* Re: [PATCH] spi/atmel: add support for runtime PM
  2014-10-16  1:49 [PATCH] spi/atmel: add support for runtime PM Wenyou Yang
@ 2014-10-16  7:30 ` Mark Brown
  2014-10-16  8:09   ` Yang, Wenyou
  2014-10-17 13:02 ` Kevin Hilman
  1 sibling, 1 reply; 11+ messages in thread
From: Mark Brown @ 2014-10-16  7:30 UTC (permalink / raw)
  To: Wenyou Yang; +Cc: linux-spi, linux-kernel, nicolas.ferre, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 423 bytes --]

On Thu, Oct 16, 2014 at 09:49:20AM +0800, Wenyou Yang wrote:

> +static int atmel_spi_runtime_resume(struct device *dev)
> +{
> +	struct spi_master *master = dev_get_drvdata(dev);
> +	struct atmel_spi *as = spi_master_get_devdata(master);
> +
> +	pinctrl_pm_select_default_state(dev);
> +	clk_prepare_enable(as->clk);
> +

This looks mostly good but you should check the return value of
clk_prepare_enable() - it can fail.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* RE: [PATCH] spi/atmel: add support for runtime PM
  2014-10-16  7:30 ` Mark Brown
@ 2014-10-16  8:09   ` Yang, Wenyou
  0 siblings, 0 replies; 11+ messages in thread
From: Yang, Wenyou @ 2014-10-16  8:09 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Ferre, Nicolas, linux-arm-kernel

Hi Mark,

> -----Original Message-----
> From: Mark Brown [mailto:broonie@kernel.org]
> Sent: Thursday, October 16, 2014 3:30 PM
> To: Yang, Wenyou
> Cc: linux-spi@vger.kernel.org; linux-kernel@vger.kernel.org; Ferre, Nicolas; linux-
> arm-kernel@lists.infradead.org
> Subject: Re: [PATCH] spi/atmel: add support for runtime PM
> 
> On Thu, Oct 16, 2014 at 09:49:20AM +0800, Wenyou Yang wrote:
> 
> > +static int atmel_spi_runtime_resume(struct device *dev) {
> > +	struct spi_master *master = dev_get_drvdata(dev);
> > +	struct atmel_spi *as = spi_master_get_devdata(master);
> > +
> > +	pinctrl_pm_select_default_state(dev);
> > +	clk_prepare_enable(as->clk);
> > +
> 
> This looks mostly good but you should check the return value of
> clk_prepare_enable() - it can fail.
Thanks a lot, I will add it.

Best Regards,
Wenyou Yang

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

* Re: [PATCH] spi/atmel: add support for runtime PM
  2014-10-16  1:49 [PATCH] spi/atmel: add support for runtime PM Wenyou Yang
  2014-10-16  7:30 ` Mark Brown
@ 2014-10-17 13:02 ` Kevin Hilman
  2014-10-17 13:57   ` Mark Brown
  2014-10-20  1:59   ` Yang, Wenyou
  1 sibling, 2 replies; 11+ messages in thread
From: Kevin Hilman @ 2014-10-17 13:02 UTC (permalink / raw)
  To: Wenyou Yang
  Cc: broonie, linux-spi, linux-kernel, nicolas.ferre, linux-arm-kernel

Wenyou Yang <wenyou.yang@atmel.com> writes:

> Drivers should put the device into low power states proactively whenever the
> device is not in use. Thus implement support for runtime PM and use the
> autosuspend feature to make sure that we can still perform well in case we see
> lots of SPI traffic within short period of time.
>
> Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
> ---
>  drivers/spi/spi-atmel.c |   62 +++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 55 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
> index 649dcb5..aca285e 100644
> --- a/drivers/spi/spi-atmel.c
> +++ b/drivers/spi/spi-atmel.c
> @@ -26,6 +26,7 @@
>  #include <linux/io.h>
>  #include <linux/gpio.h>
>  #include <linux/pinctrl/consumer.h>
> +#include <linux/pm_runtime.h>
>  
>  /* SPI register offsets */
>  #define SPI_CR					0x0000
> @@ -191,6 +192,8 @@
>  
>  #define SPI_DMA_TIMEOUT		(msecs_to_jiffies(1000))
>  
> +#define AUTOSUSPEND_TIMEOUT	2000
> +
>  struct atmel_spi_dma {
>  	struct dma_chan			*chan_rx;
>  	struct dma_chan			*chan_tx;
> @@ -1313,6 +1316,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
>  	master->setup = atmel_spi_setup;
>  	master->transfer_one_message = atmel_spi_transfer_one_message;
>  	master->cleanup = atmel_spi_cleanup;
> +	master->auto_runtime_pm = true;
>  	platform_set_drvdata(pdev, master);
>  
>  	as = spi_master_get_devdata(master);
> @@ -1385,6 +1389,11 @@ static int atmel_spi_probe(struct platform_device *pdev)
>  	dev_info(&pdev->dev, "Atmel SPI Controller at 0x%08lx (irq %d)\n",
>  			(unsigned long)regs->start, irq);
>  
> +	pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT);
> +	pm_runtime_use_autosuspend(&pdev->dev);
> +	pm_runtime_set_active(&pdev->dev);
> +	pm_runtime_enable(&pdev->dev);
> +
>  	ret = devm_spi_register_master(&pdev->dev, master);
>  	if (ret)
>  		goto out_free_dma;
> @@ -1392,6 +1401,9 @@ static int atmel_spi_probe(struct platform_device *pdev)
>  	return 0;
>  
>  out_free_dma:
> +	pm_runtime_disable(&pdev->dev);
> +	pm_runtime_set_suspended(&pdev->dev);
> +
>  	if (as->use_dma)
>  		atmel_spi_release_dma(as);
>  
> @@ -1413,6 +1425,8 @@ static int atmel_spi_remove(struct platform_device *pdev)
>  	struct spi_master	*master = platform_get_drvdata(pdev);
>  	struct atmel_spi	*as = spi_master_get_devdata(master);
>  
> +	pm_runtime_get_sync(&pdev->dev);
> +
>  	/* reset the hardware and block queue progress */
>  	spin_lock_irq(&as->lock);
>  	if (as->use_dma) {
> @@ -1430,9 +1444,13 @@ static int atmel_spi_remove(struct platform_device *pdev)
>  
>  	clk_disable_unprepare(as->clk);
>  
> +	pm_runtime_put_noidle(&pdev->dev);

Why the _noidle version?

> +	pm_runtime_disable(&pdev->dev);
> +
>  	return 0;
>  }
>  
> +#ifdef CONFIG_PM

Why CONFIG_PM?  CONFIG_PM_SLEEP  causes CONFIG_PM=y, so this seems
redundant.

>  #ifdef CONFIG_PM_SLEEP
>  static int atmel_spi_suspend(struct device *dev)
>  {
> @@ -1447,9 +1465,10 @@ static int atmel_spi_suspend(struct device *dev)
>  		return ret;
>  	}
>  
> -	clk_disable_unprepare(as->clk);
> -
> -	pinctrl_pm_select_sleep_state(dev);
> +	if (!pm_runtime_suspended(dev)) {
> +		clk_disable_unprepare(as->clk);
> +		pinctrl_pm_select_sleep_state(dev);
> +	}

a.k.a. pm_runtime_put_sync() since the ->runtime_suspend() callback does
the same thing.

>  	return 0;
>  }
> @@ -1460,9 +1479,10 @@ static int atmel_spi_resume(struct device *dev)
>  	struct atmel_spi	*as = spi_master_get_devdata(master);
>  	int ret;
>  
> -	pinctrl_pm_select_default_state(dev);
> -
> -	clk_prepare_enable(as->clk);
> +	if (!pm_runtime_suspended(dev)) {
> +		pinctrl_pm_select_default_state(dev);
> +		clk_prepare_enable(as->clk);
> +	}

a.k.a. pm_runtime_get_sync()

Kevin

>  	/* Start the queue running */
>  	ret = spi_master_resume(master);
> @@ -1471,9 +1491,37 @@ static int atmel_spi_resume(struct device *dev)
>  
>  	return ret;
>  }
> +#endif
>  
> -static SIMPLE_DEV_PM_OPS(atmel_spi_pm_ops, atmel_spi_suspend, atmel_spi_resume);
> +#ifdef CONFIG_PM_RUNTIME
> +static int atmel_spi_runtime_suspend(struct device *dev)
> +{
> +	struct spi_master *master = dev_get_drvdata(dev);
> +	struct atmel_spi *as = spi_master_get_devdata(master);
>  
> +	clk_disable_unprepare(as->clk);
> +	pinctrl_pm_select_sleep_state(dev);
> +
> +	return 0;
> +}
> +
> +static int atmel_spi_runtime_resume(struct device *dev)
> +{
> +	struct spi_master *master = dev_get_drvdata(dev);
> +	struct atmel_spi *as = spi_master_get_devdata(master);
> +
> +	pinctrl_pm_select_default_state(dev);
> +	clk_prepare_enable(as->clk);
> +
> +	return 0;
> +}
> +#endif
> +
> +static const struct dev_pm_ops atmel_spi_pm_ops = {
> +	SET_SYSTEM_SLEEP_PM_OPS(atmel_spi_suspend, atmel_spi_resume)
> +	SET_RUNTIME_PM_OPS(atmel_spi_runtime_suspend,
> +			   atmel_spi_runtime_resume, NULL)
> +};
>  #define ATMEL_SPI_PM_OPS	(&atmel_spi_pm_ops)
>  #else
>  #define ATMEL_SPI_PM_OPS	NULL

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

* Re: [PATCH] spi/atmel: add support for runtime PM
  2014-10-17 13:02 ` Kevin Hilman
@ 2014-10-17 13:57   ` Mark Brown
  2014-10-17 14:22     ` Kevin Hilman
  2014-10-20  1:59   ` Yang, Wenyou
  1 sibling, 1 reply; 11+ messages in thread
From: Mark Brown @ 2014-10-17 13:57 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: Wenyou Yang, linux-spi, linux-kernel, nicolas.ferre, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 403 bytes --]

On Fri, Oct 17, 2014 at 06:02:35AM -0700, Kevin Hilman wrote:
> Wenyou Yang <wenyou.yang@atmel.com> writes:

> > +	if (!pm_runtime_suspended(dev)) {
> > +		clk_disable_unprepare(as->clk);
> > +		pinctrl_pm_select_sleep_state(dev);
> > +	}

> a.k.a. pm_runtime_put_sync() since the ->runtime_suspend() callback does
> the same thing.

Will that do the right thing when runtime PM is disabled in Kconfig?

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [PATCH] spi/atmel: add support for runtime PM
  2014-10-17 13:57   ` Mark Brown
@ 2014-10-17 14:22     ` Kevin Hilman
  2014-10-17 14:31       ` Mark Brown
  2014-10-20  2:05       ` Yang, Wenyou
  0 siblings, 2 replies; 11+ messages in thread
From: Kevin Hilman @ 2014-10-17 14:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Wenyou Yang, linux-spi, linux-kernel, nicolas.ferre, linux-arm-kernel

Mark Brown <broonie@kernel.org> writes:

> On Fri, Oct 17, 2014 at 06:02:35AM -0700, Kevin Hilman wrote:
>> Wenyou Yang <wenyou.yang@atmel.com> writes:
>
>> > +	if (!pm_runtime_suspended(dev)) {
>> > +		clk_disable_unprepare(as->clk);
>> > +		pinctrl_pm_select_sleep_state(dev);
>> > +	}
>
>> a.k.a. pm_runtime_put_sync() since the ->runtime_suspend() callback does
>> the same thing.
>
> Will that do the right thing when runtime PM is disabled in Kconfig?

Good point.

Then the way to make this cleaner, and obvious on inspection that system
suspend/resume are doing the same thing as runtime suspend/resume is to
have ->suspend call the runtime_suspend function.

The runtime suspend/resume functions then should be wrapped in CONFIG_PM
instead of CONFIG_PM_RUNTIME.

Kevin

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

* Re: [PATCH] spi/atmel: add support for runtime PM
  2014-10-17 14:22     ` Kevin Hilman
@ 2014-10-17 14:31       ` Mark Brown
  2014-10-20  2:05       ` Yang, Wenyou
  1 sibling, 0 replies; 11+ messages in thread
From: Mark Brown @ 2014-10-17 14:31 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: Wenyou Yang, linux-spi, linux-kernel, nicolas.ferre, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 962 bytes --]

On Fri, Oct 17, 2014 at 07:22:09AM -0700, Kevin Hilman wrote:
> Mark Brown <broonie@kernel.org> writes:
> > On Fri, Oct 17, 2014 at 06:02:35AM -0700, Kevin Hilman wrote:
> >> Wenyou Yang <wenyou.yang@atmel.com> writes:

> >> > +	if (!pm_runtime_suspended(dev)) {
> >> > +		clk_disable_unprepare(as->clk);
> >> > +		pinctrl_pm_select_sleep_state(dev);
> >> > +	}

> >> a.k.a. pm_runtime_put_sync() since the ->runtime_suspend() callback does
> >> the same thing.

> > Will that do the right thing when runtime PM is disabled in Kconfig?

> Good point.

> Then the way to make this cleaner, and obvious on inspection that system
> suspend/resume are doing the same thing as runtime suspend/resume is to
> have ->suspend call the runtime_suspend function.

> The runtime suspend/resume functions then should be wrapped in CONFIG_PM
> instead of CONFIG_PM_RUNTIME.

That sounds reasonable, yes.  I keep on wishing we didn't have so much
configurability in the PM :/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* RE: [PATCH] spi/atmel: add support for runtime PM
  2014-10-17 13:02 ` Kevin Hilman
  2014-10-17 13:57   ` Mark Brown
@ 2014-10-20  1:59   ` Yang, Wenyou
  1 sibling, 0 replies; 11+ messages in thread
From: Yang, Wenyou @ 2014-10-20  1:59 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: broonie, linux-spi, linux-kernel, Ferre, Nicolas, linux-arm-kernel



> -----Original Message-----
> From: Kevin Hilman [mailto:khilman@kernel.org]
> Sent: Friday, October 17, 2014 9:03 PM
> To: Yang, Wenyou
> Cc: broonie@kernel.org; linux-spi@vger.kernel.org; linux-kernel@vger.kernel.org;
> Ferre, Nicolas; linux-arm-kernel@lists.infradead.org
> Subject: Re: [PATCH] spi/atmel: add support for runtime PM
> 
> Wenyou Yang <wenyou.yang@atmel.com> writes:
> 
> > Drivers should put the device into low power states proactively
> > whenever the device is not in use. Thus implement support for runtime
> > PM and use the autosuspend feature to make sure that we can still
> > perform well in case we see lots of SPI traffic within short period of time.
> >
> > Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
> > ---
> >  drivers/spi/spi-atmel.c |   62
> +++++++++++++++++++++++++++++++++++++++++------
> >  1 file changed, 55 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index
> > 649dcb5..aca285e 100644
> > --- a/drivers/spi/spi-atmel.c
> > +++ b/drivers/spi/spi-atmel.c
> > @@ -26,6 +26,7 @@
> >  #include <linux/io.h>
> >  #include <linux/gpio.h>
> >  #include <linux/pinctrl/consumer.h>
> > +#include <linux/pm_runtime.h>
> >
> >  /* SPI register offsets */
> >  #define SPI_CR					0x0000
> > @@ -191,6 +192,8 @@
> >
> >  #define SPI_DMA_TIMEOUT		(msecs_to_jiffies(1000))
> >
> > +#define AUTOSUSPEND_TIMEOUT	2000
> > +
> >  struct atmel_spi_dma {
> >  	struct dma_chan			*chan_rx;
> >  	struct dma_chan			*chan_tx;
> > @@ -1313,6 +1316,7 @@ static int atmel_spi_probe(struct platform_device
> *pdev)
> >  	master->setup = atmel_spi_setup;
> >  	master->transfer_one_message = atmel_spi_transfer_one_message;
> >  	master->cleanup = atmel_spi_cleanup;
> > +	master->auto_runtime_pm = true;
> >  	platform_set_drvdata(pdev, master);
> >
> >  	as = spi_master_get_devdata(master); @@ -1385,6 +1389,11 @@ static
> > int atmel_spi_probe(struct platform_device *pdev)
> >  	dev_info(&pdev->dev, "Atmel SPI Controller at 0x%08lx (irq %d)\n",
> >  			(unsigned long)regs->start, irq);
> >
> > +	pm_runtime_set_autosuspend_delay(&pdev->dev,
> AUTOSUSPEND_TIMEOUT);
> > +	pm_runtime_use_autosuspend(&pdev->dev);
> > +	pm_runtime_set_active(&pdev->dev);
> > +	pm_runtime_enable(&pdev->dev);
> > +
> >  	ret = devm_spi_register_master(&pdev->dev, master);
> >  	if (ret)
> >  		goto out_free_dma;
> > @@ -1392,6 +1401,9 @@ static int atmel_spi_probe(struct platform_device
> *pdev)
> >  	return 0;
> >
> >  out_free_dma:
> > +	pm_runtime_disable(&pdev->dev);
> > +	pm_runtime_set_suspended(&pdev->dev);
> > +
> >  	if (as->use_dma)
> >  		atmel_spi_release_dma(as);
> >
> > @@ -1413,6 +1425,8 @@ static int atmel_spi_remove(struct platform_device
> *pdev)
> >  	struct spi_master	*master = platform_get_drvdata(pdev);
> >  	struct atmel_spi	*as = spi_master_get_devdata(master);
> >
> > +	pm_runtime_get_sync(&pdev->dev);
> > +
> >  	/* reset the hardware and block queue progress */
> >  	spin_lock_irq(&as->lock);
> >  	if (as->use_dma) {
> > @@ -1430,9 +1444,13 @@ static int atmel_spi_remove(struct
> > platform_device *pdev)
> >
> >  	clk_disable_unprepare(as->clk);
> >
> > +	pm_runtime_put_noidle(&pdev->dev);
> 
> Why the _noidle version?
 Because invoked from the _remove function, only decrement the device's usage counter, no further idle operation need.

> 
> > +	pm_runtime_disable(&pdev->dev);
> > +
> >  	return 0;
> >  }
> >
> > +#ifdef CONFIG_PM
> 
> Why CONFIG_PM?  CONFIG_PM_SLEEP  causes CONFIG_PM=y, so this seems
> redundant.
Accepted, I will remove it.

> 
> >  #ifdef CONFIG_PM_SLEEP
> >  static int atmel_spi_suspend(struct device *dev)  { @@ -1447,9
> > +1465,10 @@ static int atmel_spi_suspend(struct device *dev)
> >  		return ret;
> >  	}
> >
> > -	clk_disable_unprepare(as->clk);
> > -
> > -	pinctrl_pm_select_sleep_state(dev);
> > +	if (!pm_runtime_suspended(dev)) {
> > +		clk_disable_unprepare(as->clk);
> > +		pinctrl_pm_select_sleep_state(dev);
> > +	}
> 
> a.k.a. pm_runtime_put_sync() since the ->runtime_suspend() callback does the
> same thing.
> 
> >  	return 0;
> >  }
> > @@ -1460,9 +1479,10 @@ static int atmel_spi_resume(struct device *dev)
> >  	struct atmel_spi	*as = spi_master_get_devdata(master);
> >  	int ret;
> >
> > -	pinctrl_pm_select_default_state(dev);
> > -
> > -	clk_prepare_enable(as->clk);
> > +	if (!pm_runtime_suspended(dev)) {
> > +		pinctrl_pm_select_default_state(dev);
> > +		clk_prepare_enable(as->clk);
> > +	}
> 
> a.k.a. pm_runtime_get_sync()
> 
> Kevin
> 
> >  	/* Start the queue running */
> >  	ret = spi_master_resume(master);
> > @@ -1471,9 +1491,37 @@ static int atmel_spi_resume(struct device *dev)
> >
> >  	return ret;
> >  }
> > +#endif
> >
> > -static SIMPLE_DEV_PM_OPS(atmel_spi_pm_ops, atmel_spi_suspend,
> > atmel_spi_resume);
> > +#ifdef CONFIG_PM_RUNTIME
> > +static int atmel_spi_runtime_suspend(struct device *dev) {
> > +	struct spi_master *master = dev_get_drvdata(dev);
> > +	struct atmel_spi *as = spi_master_get_devdata(master);
> >
> > +	clk_disable_unprepare(as->clk);
> > +	pinctrl_pm_select_sleep_state(dev);
> > +
> > +	return 0;
> > +}
> > +
> > +static int atmel_spi_runtime_resume(struct device *dev) {
> > +	struct spi_master *master = dev_get_drvdata(dev);
> > +	struct atmel_spi *as = spi_master_get_devdata(master);
> > +
> > +	pinctrl_pm_select_default_state(dev);
> > +	clk_prepare_enable(as->clk);
> > +
> > +	return 0;
> > +}
> > +#endif
> > +
> > +static const struct dev_pm_ops atmel_spi_pm_ops = {
> > +	SET_SYSTEM_SLEEP_PM_OPS(atmel_spi_suspend, atmel_spi_resume)
> > +	SET_RUNTIME_PM_OPS(atmel_spi_runtime_suspend,
> > +			   atmel_spi_runtime_resume, NULL) };
> >  #define ATMEL_SPI_PM_OPS	(&atmel_spi_pm_ops)
> >  #else
> >  #define ATMEL_SPI_PM_OPS	NULL

Best Regards,
Wenyou Yang

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

* RE: [PATCH] spi/atmel: add support for runtime PM
  2014-10-17 14:22     ` Kevin Hilman
  2014-10-17 14:31       ` Mark Brown
@ 2014-10-20  2:05       ` Yang, Wenyou
  2014-10-20 18:09         ` Kevin Hilman
  1 sibling, 1 reply; 11+ messages in thread
From: Yang, Wenyou @ 2014-10-20  2:05 UTC (permalink / raw)
  To: Kevin Hilman, Mark Brown
  Cc: linux-spi, linux-kernel, Ferre, Nicolas, linux-arm-kernel



> -----Original Message-----
> From: Kevin Hilman [mailto:khilman@kernel.org]
> Sent: Friday, October 17, 2014 10:22 PM
> To: Mark Brown
> Cc: Yang, Wenyou; linux-spi@vger.kernel.org; linux-kernel@vger.kernel.org; Ferre,
> Nicolas; linux-arm-kernel@lists.infradead.org
> Subject: Re: [PATCH] spi/atmel: add support for runtime PM
> 
> Mark Brown <broonie@kernel.org> writes:
> 
> > On Fri, Oct 17, 2014 at 06:02:35AM -0700, Kevin Hilman wrote:
> >> Wenyou Yang <wenyou.yang@atmel.com> writes:
> >
> >> > +	if (!pm_runtime_suspended(dev)) {
> >> > +		clk_disable_unprepare(as->clk);
> >> > +		pinctrl_pm_select_sleep_state(dev);
> >> > +	}
> >
> >> a.k.a. pm_runtime_put_sync() since the ->runtime_suspend() callback
> >> does the same thing.
> >
> > Will that do the right thing when runtime PM is disabled in Kconfig?
> 
> Good point.
> 
> Then the way to make this cleaner, and obvious on inspection that system
> suspend/resume are doing the same thing as runtime suspend/resume is to have -
> >suspend call the runtime_suspend function.
> 
> The runtime suspend/resume functions then should be wrapped in CONFIG_PM
> instead of CONFIG_PM_RUNTIME.
But if the runtime PM is disabled,  __pm_runtime_idle() return -ENOSYS, which invoked by pm_runtime_put_sync(), in spite of the runtime suspend/resume functions wrapper,

> 
> Kevin

Best Regards,
Wenyou Yang

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

* Re: [PATCH] spi/atmel: add support for runtime PM
  2014-10-20  2:05       ` Yang, Wenyou
@ 2014-10-20 18:09         ` Kevin Hilman
  2014-10-21  0:51           ` Yang, Wenyou
  0 siblings, 1 reply; 11+ messages in thread
From: Kevin Hilman @ 2014-10-20 18:09 UTC (permalink / raw)
  To: Yang, Wenyou
  Cc: Mark Brown, linux-spi, linux-kernel, Ferre, Nicolas, linux-arm-kernel

"Yang, Wenyou" <Wenyou.Yang@atmel.com> writes:

>> -----Original Message-----
>> From: Kevin Hilman [mailto:khilman@kernel.org]
>> Sent: Friday, October 17, 2014 10:22 PM
>> To: Mark Brown
>> Cc: Yang, Wenyou; linux-spi@vger.kernel.org; linux-kernel@vger.kernel.org; Ferre,
>> Nicolas; linux-arm-kernel@lists.infradead.org
>> Subject: Re: [PATCH] spi/atmel: add support for runtime PM
>> 
>> Mark Brown <broonie@kernel.org> writes:
>> 
>> > On Fri, Oct 17, 2014 at 06:02:35AM -0700, Kevin Hilman wrote:
>> >> Wenyou Yang <wenyou.yang@atmel.com> writes:
>> >
>> >> > +	if (!pm_runtime_suspended(dev)) {
>> >> > +		clk_disable_unprepare(as->clk);
>> >> > +		pinctrl_pm_select_sleep_state(dev);
>> >> > +	}
>> >
>> >> a.k.a. pm_runtime_put_sync() since the ->runtime_suspend() callback
>> >> does the same thing.
>> >
>> > Will that do the right thing when runtime PM is disabled in Kconfig?
>> 
>> Good point.
>> 
>> Then the way to make this cleaner, and obvious on inspection that system
>> suspend/resume are doing the same thing as runtime suspend/resume is to have -
>> >suspend call the runtime_suspend function.
>> 
>> The runtime suspend/resume functions then should be wrapped in CONFIG_PM
>> instead of CONFIG_PM_RUNTIME.
> But if the runtime PM is disabled, __pm_runtime_idle() return -ENOSYS,
> which invoked by pm_runtime_put_sync(), in spite of the runtime
> suspend/resume functions wrapper,

You won't be calling _put_sync(), instead you'll just directly call
atmel_spi_runtime_suspend().

The goal is to make it obvious upon reading that ->suspend and
->runtime_suspend are doing exactly the same thing.

Kevin


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

* RE: [PATCH] spi/atmel: add support for runtime PM
  2014-10-20 18:09         ` Kevin Hilman
@ 2014-10-21  0:51           ` Yang, Wenyou
  0 siblings, 0 replies; 11+ messages in thread
From: Yang, Wenyou @ 2014-10-21  0:51 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: Mark Brown, linux-spi, linux-kernel, Ferre, Nicolas, linux-arm-kernel

Hi Kevin,

> -----Original Message-----
> From: Kevin Hilman [mailto:khilman@kernel.org]
> Sent: Tuesday, October 21, 2014 2:09 AM
> To: Yang, Wenyou
> Cc: Mark Brown; linux-spi@vger.kernel.org; linux-kernel@vger.kernel.org; Ferre,
> Nicolas; linux-arm-kernel@lists.infradead.org
> Subject: Re: [PATCH] spi/atmel: add support for runtime PM
> 
> "Yang, Wenyou" <Wenyou.Yang@atmel.com> writes:
> 
> >> -----Original Message-----
> >> From: Kevin Hilman [mailto:khilman@kernel.org]
> >> Sent: Friday, October 17, 2014 10:22 PM
> >> To: Mark Brown
> >> Cc: Yang, Wenyou; linux-spi@vger.kernel.org;
> >> linux-kernel@vger.kernel.org; Ferre, Nicolas;
> >> linux-arm-kernel@lists.infradead.org
> >> Subject: Re: [PATCH] spi/atmel: add support for runtime PM
> >>
> >> Mark Brown <broonie@kernel.org> writes:
> >>
> >> > On Fri, Oct 17, 2014 at 06:02:35AM -0700, Kevin Hilman wrote:
> >> >> Wenyou Yang <wenyou.yang@atmel.com> writes:
> >> >
> >> >> > +	if (!pm_runtime_suspended(dev)) {
> >> >> > +		clk_disable_unprepare(as->clk);
> >> >> > +		pinctrl_pm_select_sleep_state(dev);
> >> >> > +	}
> >> >
> >> >> a.k.a. pm_runtime_put_sync() since the ->runtime_suspend()
> >> >> callback does the same thing.
> >> >
> >> > Will that do the right thing when runtime PM is disabled in Kconfig?
> >>
> >> Good point.
> >>
> >> Then the way to make this cleaner, and obvious on inspection that
> >> system suspend/resume are doing the same thing as runtime
> >> suspend/resume is to have -
> >> >suspend call the runtime_suspend function.
> >>
> >> The runtime suspend/resume functions then should be wrapped in
> >> CONFIG_PM instead of CONFIG_PM_RUNTIME.
> > But if the runtime PM is disabled, __pm_runtime_idle() return -ENOSYS,
> > which invoked by pm_runtime_put_sync(), in spite of the runtime
> > suspend/resume functions wrapper,
> 
> You won't be calling _put_sync(), instead you'll just directly call
> atmel_spi_runtime_suspend().
Got it , I will change it. Thanks.

> 
> The goal is to make it obvious upon reading that ->suspend and
> ->runtime_suspend are doing exactly the same thing.
> 
> Kevin

Best Regards,
Wenyou Yang

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

end of thread, other threads:[~2014-10-21  9:36 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-16  1:49 [PATCH] spi/atmel: add support for runtime PM Wenyou Yang
2014-10-16  7:30 ` Mark Brown
2014-10-16  8:09   ` Yang, Wenyou
2014-10-17 13:02 ` Kevin Hilman
2014-10-17 13:57   ` Mark Brown
2014-10-17 14:22     ` Kevin Hilman
2014-10-17 14:31       ` Mark Brown
2014-10-20  2:05       ` Yang, Wenyou
2014-10-20 18:09         ` Kevin Hilman
2014-10-21  0:51           ` Yang, Wenyou
2014-10-20  1:59   ` Yang, Wenyou

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).