From: Pierre Ossman 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. Signed-off-by: Pierre Ossman Acked-by: Dmitry Torokhov Cc: Adam Belay Signed-off-by: Andrew Morton --- drivers/pnp/driver.c | 51 +++++++++++++++++++++++++++++++- drivers/pnp/manager.c | 78 +++++++++++++++++++++++++++++++++++++------------- include/linux/pnp.h | 10 +++++- 3 files changed, 116 insertions(+), 23 deletions(-) diff -puN drivers/pnp/driver.c~suspend-support-for-pnp-bus drivers/pnp/driver.c --- 25/drivers/pnp/driver.c~suspend-support-for-pnp-bus Mon Nov 7 15:22:41 2005 +++ 25-akpm/drivers/pnp/driver.c Mon Nov 7 15:22:41 2005 @@ -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, }; diff -puN drivers/pnp/manager.c~suspend-support-for-pnp-bus drivers/pnp/manager.c --- 25/drivers/pnp/manager.c~suspend-support-for-pnp-bus Mon Nov 7 15:22:41 2005 +++ 25-akpm/drivers/pnp/manager.c Mon Nov 7 15:22:41 2005 @@ -470,6 +470,53 @@ int pnp_auto_config_dev(struct pnp_dev * } /** + * pnp_start_dev - low-level start of the PnP device + * @dev: pointer to the desired device + * + * assumes that resources have alread been allocated + */ + +int pnp_start_dev(struct pnp_dev *dev) +{ + if (!pnp_can_write(dev)) { + pnp_info("Device %s does not supported activation.", dev->dev.bus_id); + return -EINVAL; + } + + if (dev->protocol->set(dev, &dev->res) < 0) { + pnp_err("Failed to activate device %s.", dev->dev.bus_id); + return -EIO; + } + + pnp_info("Device %s activated.", dev->dev.bus_id); + + return 0; +} + +/** + * pnp_stop_dev - low-level disable of the PnP device + * @dev: pointer to the desired device + * + * does not free resources + */ + +int pnp_stop_dev(struct pnp_dev *dev) +{ + if (!pnp_can_disable(dev)) { + pnp_info("Device %s does not supported disabling.", dev->dev.bus_id); + return -EINVAL; + } + if (dev->protocol->disable(dev) < 0) { + pnp_err("Failed to disable device %s.", dev->dev.bus_id); + return -EIO; + } + + pnp_info("Device %s disabled.", dev->dev.bus_id); + + return 0; +} + +/** * pnp_activate_dev - activates a PnP device for use * @dev: pointer to the desired device * @@ -477,6 +524,8 @@ int pnp_auto_config_dev(struct pnp_dev * */ int pnp_activate_dev(struct pnp_dev *dev) { + int error; + if (!dev) return -EINVAL; if (dev->active) { @@ -487,18 +536,11 @@ int pnp_activate_dev(struct pnp_dev *dev if (pnp_auto_config_dev(dev)) return -EBUSY; - if (!pnp_can_write(dev)) { - pnp_info("Device %s does not supported activation.", dev->dev.bus_id); - return -EINVAL; - } - - if (dev->protocol->set(dev, &dev->res)<0) { - pnp_err("Failed to activate device %s.", dev->dev.bus_id); - return -EIO; - } + error = pnp_start_dev(dev); + if (error) + return error; dev->active = 1; - pnp_info("Device %s activated.", dev->dev.bus_id); return 1; } @@ -511,23 +553,19 @@ int pnp_activate_dev(struct pnp_dev *dev */ int pnp_disable_dev(struct pnp_dev *dev) { + int error; + if (!dev) return -EINVAL; if (!dev->active) { return 0; /* the device is already disabled */ } - if (!pnp_can_disable(dev)) { - pnp_info("Device %s does not supported disabling.", dev->dev.bus_id); - return -EINVAL; - } - if (dev->protocol->disable(dev)<0) { - pnp_err("Failed to disable device %s.", dev->dev.bus_id); - return -EIO; - } + error = pnp_stop_dev(dev); + if (error) + return error; dev->active = 0; - pnp_info("Device %s disabled.", dev->dev.bus_id); /* release the resources so that other devices can use them */ down(&pnp_res_mutex); @@ -560,5 +598,7 @@ EXPORT_SYMBOL(pnp_auto_config_dev); #endif EXPORT_SYMBOL(pnp_activate_dev); EXPORT_SYMBOL(pnp_disable_dev); +EXPORT_SYMBOL(pnp_start_dev); +EXPORT_SYMBOL(pnp_stop_dev); EXPORT_SYMBOL(pnp_resource_change); EXPORT_SYMBOL(pnp_init_resource_table); diff -puN include/linux/pnp.h~suspend-support-for-pnp-bus include/linux/pnp.h --- 25/include/linux/pnp.h~suspend-support-for-pnp-bus Mon Nov 7 15:22:41 2005 +++ 25-akpm/include/linux/pnp.h Mon Nov 7 15:22:41 2005 @@ -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; }; @@ -380,6 +382,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); @@ -423,6 +427,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) { } _