Skip to contentSkip to conversation

Suspend support for PNP bus.

RFC PATCH New Pierre Ossman 1 participant 1 message Oct 28, 2005 Pnp support

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Suspend support for PNP bus.

Add support for suspending devices connected to the PNP bus. New callbacks are added for the drivers and the PNP hardware layer is told to disable the device during the suspend.

---

 drivers/pnp/driver.c  |   51 +++++++++++++++++++++++++++++++-
 drivers/pnp/manager.c |   78 +++++++++++++++++++++++++++++++++++++------------
 include/linux/pnp.h   |   10 +++++-
 3 files changed, 116 insertions(+), 23 deletions(-)
drivers/pnp/driver.c +49 -2
@@ -146,10 +146,57 @@ static int pnp_bus_match(struct device *
 	return 1;
 }
 
+static int pnp_bus_suspend(struct device *dev, pm_message_t state)
+{
+	struct pnp_dev * pnp_dev = to_pnp_dev(dev);
+	struct pnp_driver * drv = pnp_dev->driver;
+	int error;
+
+	if (!drv)
+		return 0;
+
+	if (drv->suspend) {
+		error = drv->suspend(pnp_dev, state);
+		if (error)
+			return error;
+	}
+
+	if (!(drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE) &&
+	    pnp_can_disable(pnp_dev)) {
+	    	error = pnp_stop_dev(pnp_dev);
+	    	if (error)
+	    		return error;
+	}
+
+	return 0;
+}
+
+static int pnp_bus_resume(struct device *dev)
+{
+	struct pnp_dev * pnp_dev = to_pnp_dev(dev);
+	struct pnp_driver * drv = pnp_dev->driver;
+	int error;
+
+	if (!drv)
+		return 0;
+
+	if (!(drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE)) {
+		error = pnp_start_dev(pnp_dev);
+		if (error)
+			return error;
+	}
+
+	if (drv->resume)
+		return drv->resume(pnp_dev);
+
+	return 0;
+}
 
 struct bus_type pnp_bus_type = {
-	.name	= "pnp",
-	.match	= pnp_bus_match,
+	.name		= "pnp",
+	.match		= pnp_bus_match,
+	.suspend	= pnp_bus_suspend,
+	.resume		= pnp_bus_resume,
 };
 
 
drivers/pnp/manager.c +59 -19

118 lines not on this page · raw message

include/linux/pnp.h +8 -2
@@ -292,8 +292,10 @@ struct pnp_driver {
 	char * name;
 	const struct pnp_device_id *id_table;
 	unsigned int flags;
-	int  (*probe)  (struct pnp_dev *dev, const struct pnp_device_id *dev_id);
-	void (*remove) (struct pnp_dev *dev);
+	int  (*probe)   (struct pnp_dev *dev, const struct pnp_device_id *dev_id);
+	void (*remove)  (struct pnp_dev *dev);
+	int  (*suspend) (struct pnp_dev *dev, pm_message_t state);
+	int  (*resume)  (struct pnp_dev *dev);
 	struct device_driver driver;
 };
 
@@ -381,6 +383,8 @@ void pnp_init_resource_table(struct pnp_
 int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, int mode);
 int pnp_auto_config_dev(struct pnp_dev *dev);
 int pnp_validate_config(struct pnp_dev *dev);
+int pnp_start_dev(struct pnp_dev *dev);
+int pnp_stop_dev(struct pnp_dev *dev);
 int pnp_activate_dev(struct pnp_dev *dev);
 int pnp_disable_dev(struct pnp_dev *dev);
 void pnp_resource_change(struct resource *resource, unsigned long start, unsigned long size);
@@ -425,6 +429,8 @@ static inline void pnp_init_resource_tab
 static inline int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, int mode) { return -ENODEV; }
 static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_validate_config(struct pnp_dev *dev) { return -ENODEV; }
+static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; }
+static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; }
 static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; }
 static inline void pnp_resource_change(struct resource *resource, unsigned long start, unsigned long size) { }