linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/11] spi: Provide core support for runtime PM during transfers
@ 2013-07-28 14:43 Mark Brown
  2013-07-28 14:43 ` [PATCH 02/11] spi/bcm63xx: Convert to core runtime PM Mark Brown
                   ` (9 more replies)
  0 siblings, 10 replies; 17+ messages in thread
From: Mark Brown @ 2013-07-28 14:43 UTC (permalink / raw)
  To: Eric Miao, Haojian Zhuang, Kukjin Kim, Stephen Warren,
	Linus Walleij
  Cc: linux-samsung-soc, linux-tegra, linux-omap, linaro-kernel,
	Mark Brown

From: Mark Brown <broonie@linaro.org>

Most SPI drivers that implement runtime PM support use identical code to
do so: they acquire a runtime PM lock in prepare_transfer_hardware() and
then they release it in unprepare_transfer_hardware(). The variations in
this are mostly missing error checking and the choice to use autosuspend.

Since these runtime PM calls are normally the only thing in the prepare
and unprepare callbacks and the autosuspend API transparently does the
right thing on devices with autosuspend disabled factor all of this out
into the core with a flag to enable the behaviour.

Signed-off-by: Mark Brown <broonie@linaro.org>
---
 drivers/spi/spi.c       | 16 ++++++++++++++++
 include/linux/spi/spi.h |  4 ++++
 2 files changed, 20 insertions(+)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 46c3f56..61f71b9 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -553,6 +553,10 @@ static void spi_pump_messages(struct kthread_work *work)
 		    master->unprepare_transfer_hardware(master))
 			dev_err(&master->dev,
 				"failed to unprepare transfer hardware\n");
+		if (master->auto_runtime_pm) {
+			pm_runtime_mark_last_busy(master->dev.parent);
+			pm_runtime_put_autosuspend(master->dev.parent);
+		}
 		return;
 	}
 
@@ -572,11 +576,23 @@ static void spi_pump_messages(struct kthread_work *work)
 		master->busy = true;
 	spin_unlock_irqrestore(&master->queue_lock, flags);
 
+	if (!was_busy && master->auto_runtime_pm) {
+		ret = pm_runtime_get_sync(master->dev.parent);
+		if (ret < 0) {
+			dev_err(&master->dev, "Failed to power device: %d\n",
+				ret);
+			return;
+		}
+	}
+
 	if (!was_busy && master->prepare_transfer_hardware) {
 		ret = master->prepare_transfer_hardware(master);
 		if (ret) {
 			dev_err(&master->dev,
 				"failed to prepare transfer hardware\n");
+
+			if (master->auto_runtime_pm)
+				pm_runtime_put(master->dev.parent);
 			return;
 		}
 	}
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index be40c97..d73059a 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -256,6 +256,8 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
  * @busy: message pump is busy
  * @running: message pump is running
  * @rt: whether this queue is set to run as a realtime task
+ * @auto_runtime_pm: the core should ensure a runtime PM reference is held
+ *                   while the hardware is prepared
  * @prepare_transfer_hardware: a message will soon arrive from the queue
  *	so the subsystem requests the driver to prepare the transfer hardware
  *	by issuing this call
@@ -380,11 +382,13 @@ struct spi_master {
 	bool				busy;
 	bool				running;
 	bool				rt;
+	bool				auto_runtime_pm;
 
 	int (*prepare_transfer_hardware)(struct spi_master *master);
 	int (*transfer_one_message)(struct spi_master *master,
 				    struct spi_message *mesg);
 	int (*unprepare_transfer_hardware)(struct spi_master *master);
+
 	/* gpio chip select */
 	int			*cs_gpios;
 };
-- 
1.8.3.2

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

end of thread, other threads:[~2013-07-29 16:56 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-28 14:43 [PATCH 01/11] spi: Provide core support for runtime PM during transfers Mark Brown
2013-07-28 14:43 ` [PATCH 02/11] spi/bcm63xx: Convert to core runtime PM Mark Brown
2013-07-28 14:43 ` [PATCH 03/11] spi/coldfire-qspi: " Mark Brown
2013-07-28 14:43 ` [PATCH 04/11] spi/omap2: Covert " Mark Brown
2013-07-28 21:20   ` Felipe Balbi
2013-07-28 14:43 ` [PATCH 05/11] spi/pl022: Convert " Mark Brown
     [not found]   ` <1375022606-7576-5-git-send-email-broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-07-28 20:52     ` Linus Walleij
2013-07-29  6:04       ` Mark Brown
2013-07-28 14:43 ` [PATCH 06/11] spi/pxa2xx: " Mark Brown
2013-07-28 14:43 ` [PATCH 07/11] spi/hspi: " Mark Brown
2013-07-28 14:43 ` [PATCH 09/11] spi/tegra114: Use " Mark Brown
2013-07-28 14:43 ` [PATCH 11/11] spi/tegra20-slink: " Mark Brown
     [not found] ` <1375022606-7576-1-git-send-email-broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-07-28 14:43   ` [PATCH 08/11] spi/s3c64xx: Use core for " Mark Brown
2013-07-28 14:43   ` [PATCH 10/11] spi/tegra20-sflash: Use core " Mark Brown
2013-07-28 20:51   ` [PATCH 01/11] spi: Provide core support for runtime PM during transfers Linus Walleij
2013-07-29  5:56     ` Mark Brown
2013-07-29 16:56 ` Stephen Warren

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