Commit 68094e32 authored by Pierre Ossman's avatar Pierre Ossman Committed by Jaroslav Kysela

[ALSA] [PATCH] alsa: Improved PnP suspend support

Also use the PnP functions to start/stop the devices during the suspend so
that drivers will not have to duplicate this code.

Cc: Adam Belay <ambx1@neo.rr.com>
Cc: Jaroslav Kysela <perex@suse.cz>
Cc: Takashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarPierre Ossman <drzeus@drzeus.cx>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 4c98cfef
...@@ -150,19 +150,46 @@ static int pnp_bus_suspend(struct device *dev, pm_message_t state) ...@@ -150,19 +150,46 @@ static int pnp_bus_suspend(struct device *dev, pm_message_t state)
{ {
struct pnp_dev * pnp_dev = to_pnp_dev(dev); struct pnp_dev * pnp_dev = to_pnp_dev(dev);
struct pnp_driver * pnp_drv = pnp_dev->driver; struct pnp_driver * pnp_drv = pnp_dev->driver;
int error;
if (!pnp_drv)
return 0;
if (pnp_drv->suspend) {
error = pnp_drv->suspend(pnp_dev, state);
if (error)
return error;
}
if (!(pnp_drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE) &&
pnp_can_disable(pnp_dev)) {
error = pnp_stop_dev(pnp_dev);
if (error)
return error;
}
if (pnp_drv && pnp_drv->suspend)
return pnp_drv->suspend(pnp_dev, state);
return 0; return 0;
} }
static void pnp_bus_resume(struct device *dev) static int pnp_bus_resume(struct device *dev)
{ {
struct pnp_dev * pnp_dev = to_pnp_dev(dev); struct pnp_dev * pnp_dev = to_pnp_dev(dev);
struct pnp_driver * pnp_drv = pnp_dev->driver; struct pnp_driver * pnp_drv = pnp_dev->driver;
int error;
if (!pnp_drv)
return 0;
if (pnp_drv && pnp_drv->resume) if (!(pnp_drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE)) {
pnp_drv->resume(pnp_dev); error = pnp_start_dev(pnp_dev);
if (error)
return error;
}
if (pnp_drv->resume)
return pnp_drv->resume(pnp_dev);
return 0;
} }
struct bus_type pnp_bus_type = { struct bus_type pnp_bus_type = {
......
...@@ -469,6 +469,53 @@ int pnp_auto_config_dev(struct pnp_dev *dev) ...@@ -469,6 +469,53 @@ int pnp_auto_config_dev(struct pnp_dev *dev)
return -EBUSY; return -EBUSY;
} }
/**
* 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 * pnp_activate_dev - activates a PnP device for use
* @dev: pointer to the desired device * @dev: pointer to the desired device
...@@ -477,6 +524,8 @@ int pnp_auto_config_dev(struct pnp_dev *dev) ...@@ -477,6 +524,8 @@ int pnp_auto_config_dev(struct pnp_dev *dev)
*/ */
int pnp_activate_dev(struct pnp_dev *dev) int pnp_activate_dev(struct pnp_dev *dev)
{ {
int error;
if (!dev) if (!dev)
return -EINVAL; return -EINVAL;
if (dev->active) { if (dev->active) {
...@@ -487,18 +536,11 @@ int pnp_activate_dev(struct pnp_dev *dev) ...@@ -487,18 +536,11 @@ int pnp_activate_dev(struct pnp_dev *dev)
if (pnp_auto_config_dev(dev)) if (pnp_auto_config_dev(dev))
return -EBUSY; return -EBUSY;
if (!pnp_can_write(dev)) { error = pnp_start_dev(dev);
pnp_info("Device %s does not supported activation.", dev->dev.bus_id); if (error)
return -EINVAL; return error;
}
if (dev->protocol->set(dev, &dev->res)<0) {
pnp_err("Failed to activate device %s.", dev->dev.bus_id);
return -EIO;
}
dev->active = 1; dev->active = 1;
pnp_info("Device %s activated.", dev->dev.bus_id);
return 1; return 1;
} }
...@@ -511,23 +553,19 @@ int pnp_activate_dev(struct pnp_dev *dev) ...@@ -511,23 +553,19 @@ int pnp_activate_dev(struct pnp_dev *dev)
*/ */
int pnp_disable_dev(struct pnp_dev *dev) int pnp_disable_dev(struct pnp_dev *dev)
{ {
int error;
if (!dev) if (!dev)
return -EINVAL; return -EINVAL;
if (!dev->active) { if (!dev->active) {
return 0; /* the device is already disabled */ return 0; /* the device is already disabled */
} }
if (!pnp_can_disable(dev)) { error = pnp_stop_dev(dev);
pnp_info("Device %s does not supported disabling.", dev->dev.bus_id); if (error)
return -EINVAL; return error;
}
if (dev->protocol->disable(dev)<0) {
pnp_err("Failed to disable device %s.", dev->dev.bus_id);
return -EIO;
}
dev->active = 0; dev->active = 0;
pnp_info("Device %s disabled.", dev->dev.bus_id);
/* release the resources so that other devices can use them */ /* release the resources so that other devices can use them */
down(&pnp_res_mutex); down(&pnp_res_mutex);
...@@ -558,6 +596,8 @@ EXPORT_SYMBOL(pnp_manual_config_dev); ...@@ -558,6 +596,8 @@ EXPORT_SYMBOL(pnp_manual_config_dev);
#if 0 #if 0
EXPORT_SYMBOL(pnp_auto_config_dev); EXPORT_SYMBOL(pnp_auto_config_dev);
#endif #endif
EXPORT_SYMBOL(pnp_start_dev);
EXPORT_SYMBOL(pnp_stop_dev);
EXPORT_SYMBOL(pnp_activate_dev); EXPORT_SYMBOL(pnp_activate_dev);
EXPORT_SYMBOL(pnp_disable_dev); EXPORT_SYMBOL(pnp_disable_dev);
EXPORT_SYMBOL(pnp_resource_change); EXPORT_SYMBOL(pnp_resource_change);
......
...@@ -385,6 +385,8 @@ void pnp_init_resource_table(struct pnp_resource_table *table); ...@@ -385,6 +385,8 @@ void pnp_init_resource_table(struct pnp_resource_table *table);
int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, int mode); 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_auto_config_dev(struct pnp_dev *dev);
int pnp_validate_config(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_activate_dev(struct pnp_dev *dev);
int pnp_disable_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); void pnp_resource_change(struct resource *resource, unsigned long start, unsigned long size);
...@@ -428,6 +430,8 @@ static inline void pnp_init_resource_table(struct pnp_resource_table *table) { } ...@@ -428,6 +430,8 @@ static inline void pnp_init_resource_table(struct pnp_resource_table *table) { }
static inline int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, int mode) { return -ENODEV; } 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_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_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_activate_dev(struct pnp_dev *dev) { return -ENODEV; }
static inline int pnp_disable_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) { } static inline void pnp_resource_change(struct resource *resource, unsigned long start, unsigned long size) { }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment