linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] spi: Add hook on suspend/resume for spi master
@ 2010-08-11 14:43 Gregory CLEMENT
  0 siblings, 0 replies; only message in thread
From: Gregory CLEMENT @ 2010-08-11 14:43 UTC (permalink / raw)
  To: spi-devel-general; +Cc: linux-omap, Gregory CLEMENT

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

Some spi master need to do some action when system is going to suspend
or when it will be resumed.
Spi driver offer possibility to handle suspend and resume only for device.
Spi master will do its suspend actions after the devices and will do
its resume action before the devices.

Signed-off-by: Gregory CLEMENT <gclement00@gmail.com>
---
 drivers/spi/spi.c       |   15 ++++++++++++++-
 include/linux/spi/spi.h |    4 +++-
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 1bb1b88..fe8140e 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -17,7 +17,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-
 #include <linux/kernel.h>
 #include <linux/device.h>
 #include <linux/init.h>
@@ -106,6 +105,11 @@ static int spi_suspend(struct device *dev,
pm_message_t message)
 {
 	int			value = 0;
 	struct spi_driver	*drv = to_spi_driver(dev->driver);
+	struct spi_device *spi_dev = to_spi_device(dev);
+	struct spi_master *master = NULL;
+
+	if (spi_dev)
+		master = spi_dev->master;

 	/* suspend will stop irqs and dma; no more i/o */
 	if (drv) {
@@ -114,6 +118,9 @@ static int spi_suspend(struct device *dev,
pm_message_t message)
 		else
 			dev_dbg(dev, "... can't suspend\n");
 	}
+	if (master && master->suspend )
+		master->suspend(spi_dev);
+
 	return value;
 }

@@ -121,7 +128,11 @@ static int spi_resume(struct device *dev)
 {
 	int			value = 0;
 	struct spi_driver	*drv = to_spi_driver(dev->driver);
+	struct spi_device *spi_dev = to_spi_device(dev);
+	struct spi_master *master = NULL;

+	if (spi_dev)
+		master = spi_dev->master;
 	/* resume may restart the i/o queue */
 	if (drv) {
 		if (drv->resume)
@@ -129,6 +140,8 @@ static int spi_resume(struct device *dev)
 		else
 			dev_dbg(dev, "... can't resume\n");
 	}
+	if (master && master->resume )
+		master->resume(spi_dev);
 	return value;
 }

diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index af56071..2483a1d 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -293,7 +293,9 @@ struct spi_master {
 						struct spi_message *mesg);

 	/* called on release() to free memory provided by spi_master */
-	void			(*cleanup)(struct spi_device *spi);
+        void			(*cleanup)(struct spi_device *spi);
+     void (*suspend)(struct spi_device *spi);
+     void (*resume)(struct spi_device *spi);
 };

 static inline void *spi_master_get_devdata(struct spi_master *master)

[-- Attachment #2: 0001-spi-Add-hook-on-suspend-resume-for-spi-master.patch --]
[-- Type: text/x-patch, Size: 2121 bytes --]

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 1bb1b88..fe8140e 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -17,7 +17,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-
 #include <linux/kernel.h>
 #include <linux/device.h>
 #include <linux/init.h>
@@ -106,6 +105,11 @@ static int spi_suspend(struct device *dev, pm_message_t message)
 {
 	int			value = 0;
 	struct spi_driver	*drv = to_spi_driver(dev->driver);
+	struct spi_device *spi_dev = to_spi_device(dev);
+	struct spi_master *master = NULL;
+
+	if (spi_dev)
+		master = spi_dev->master;
 
 	/* suspend will stop irqs and dma; no more i/o */
 	if (drv) {
@@ -114,6 +118,9 @@ static int spi_suspend(struct device *dev, pm_message_t message)
 		else
 			dev_dbg(dev, "... can't suspend\n");
 	}
+	if (master && master->suspend )
+		master->suspend(spi_dev);
+
 	return value;
 }
 
@@ -121,7 +128,11 @@ static int spi_resume(struct device *dev)
 {
 	int			value = 0;
 	struct spi_driver	*drv = to_spi_driver(dev->driver);
+	struct spi_device *spi_dev = to_spi_device(dev);
+	struct spi_master *master = NULL;
 
+	if (spi_dev)
+		master = spi_dev->master;
 	/* resume may restart the i/o queue */
 	if (drv) {
 		if (drv->resume)
@@ -129,6 +140,8 @@ static int spi_resume(struct device *dev)
 		else
 			dev_dbg(dev, "... can't resume\n");
 	}
+	if (master && master->resume )
+		master->resume(spi_dev);
 	return value;
 }
 
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index af56071..2483a1d 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -293,7 +293,9 @@ struct spi_master {
 						struct spi_message *mesg);
 
 	/* called on release() to free memory provided by spi_master */
-	void			(*cleanup)(struct spi_device *spi);
+        void			(*cleanup)(struct spi_device *spi);
+     void (*suspend)(struct spi_device *spi);
+     void (*resume)(struct spi_device *spi);
 };
 
 static inline void *spi_master_get_devdata(struct spi_master *master)

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-08-11 14:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-11 14:43 [PATCH 1/2] spi: Add hook on suspend/resume for spi master Gregory CLEMENT

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