From 5b3272655a8e8a9a6e2503bc5a88fc9d9c8292a4 Mon Sep 17 00:00:00 2001 From: Patrick Mochel Date: Wed, 10 May 2006 10:33:00 -0400 Subject: ACPI: create acpi_device_suspend()/acpi_device_resume() updated and tested by Konstantin Karasyov http://bugzilla.kernel.org/show_bug.cgi?id=5000 Signed-off-by: Patrick Mochel Signed-off-by: Konstantin Karasyov Signed-off-by: Len Brown --- drivers/acpi/scan.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) (limited to 'drivers/acpi') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index a0ab828b2cc5..19ae9ff10210 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1371,6 +1371,108 @@ static int acpi_bus_scan_fixed(struct acpi_device *root) return_VALUE(result); } + +static struct acpi_device * to_acpi_dev(struct device * dev) +{ + return container_of(dev, struct acpi_device, dev); +} + + +static int root_suspend(struct acpi_device * acpi_dev) +{ + struct acpi_device * dev, * next; + int result; + + spin_lock(&acpi_device_lock); + list_for_each_entry_safe_reverse(dev, next, &acpi_device_list, g_list) { + if (dev->driver && dev->driver->ops.suspend) { + spin_unlock(&acpi_device_lock); + + /* TBD: What suspend state should be passed + * to device? + */ + result = dev->driver->ops.suspend(dev, 0); + if (result) { + printk(KERN_ERR PREFIX "[%s - %s] Suspend failed: %d\n", + acpi_device_name(dev), + acpi_device_bid(dev), result); + } + spin_lock(&acpi_device_lock); + } + } + spin_unlock(&acpi_device_lock); + return 0; +} + + +static int acpi_device_suspend(struct device * dev, pm_message_t state) +{ + struct acpi_device * acpi_dev = to_acpi_dev(dev); + + /* + * For now, we should only register 1 generic device - + * the ACPI root device - and from there, we walk the + * tree of ACPI devices to suspend each one using the + * ACPI driver methods. + */ + if (acpi_dev->handle == ACPI_ROOT_OBJECT) + root_suspend(acpi_dev); + return 0; +} + + + +static int root_resume(struct acpi_device * acpi_dev) +{ + struct acpi_device * dev, * next; + int result; + + spin_lock(&acpi_device_lock); + list_for_each_entry_safe(dev, next, &acpi_device_list, g_list) { + if (dev->driver && dev->driver->ops.resume) { + spin_unlock(&acpi_device_lock); + + /* TBD: What suspend state should be passed + * to device? + */ + result = dev->driver->ops.resume(dev, 0); + if (result) { + printk(KERN_ERR PREFIX "[%s - %s] resume failed: %d\n", + acpi_device_name(dev), + acpi_device_bid(dev), result); + } + spin_lock(&acpi_device_lock); + } + } + spin_unlock(&acpi_device_lock); + return 0; +} + + +static int acpi_device_resume(struct device * dev) +{ + struct acpi_device * acpi_dev = to_acpi_dev(dev); + + /* + * For now, we should only register 1 generic device - + * the ACPI root device - and from there, we walk the + * tree of ACPI devices to resume each one using the + * ACPI driver methods. + */ + if (acpi_dev->handle == ACPI_ROOT_OBJECT) + root_resume(acpi_dev); + return 0; +} + + +struct bus_type acpi_bus_type = { + .name = "acpi", + .suspend = acpi_device_suspend, + .resume = acpi_device_resume, +}; + + + static int __init acpi_scan_init(void) { int result; @@ -1383,6 +1485,12 @@ static int __init acpi_scan_init(void) kset_register(&acpi_namespace_kset); + result = bus_register(&acpi_bus_type); + if (result) { + /* We don't want to quit even if we failed to add suspend/resume */ + printk(KERN_ERR PREFIX "Could not register bus type\n"); + } + /* * Create the root device in the bus's device tree */ @@ -1392,6 +1500,16 @@ static int __init acpi_scan_init(void) goto Done; result = acpi_start_single_object(acpi_root); + if (result) + goto Done; + + acpi_root->dev.bus = &acpi_bus_type; + snprintf(acpi_root->dev.bus_id, BUS_ID_SIZE, "%s", acpi_bus_type.name); + result = device_register(&acpi_root->dev); + if (result) { + /* We don't want to quit even if we failed to add suspend/resume */ + printk(KERN_ERR PREFIX "Could not register device\n"); + } /* * Enumerate devices in the ACPI namespace. -- cgit v1.2.1 From 531881d665ca011326bb466b97b07c95dee8d0a1 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Mon, 15 May 2006 03:06:41 -0400 Subject: ACPI: pass pm_message_t from acpi_device_suspend() to root_suspend() in case we want to decode it for future use in acpi_op_suspend(..., state) also, inline new 1-liner static function http://bugzilla.kernel.org/show_bug.cgi?id=5000 Signed-off-by: Len Brown --- drivers/acpi/scan.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 19ae9ff10210..eee58393eb46 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1372,13 +1372,13 @@ static int acpi_bus_scan_fixed(struct acpi_device *root) } -static struct acpi_device * to_acpi_dev(struct device * dev) +static inline struct acpi_device * to_acpi_dev(struct device * dev) { return container_of(dev, struct acpi_device, dev); } -static int root_suspend(struct acpi_device * acpi_dev) +static int root_suspend(struct acpi_device * acpi_dev, pm_message_t state) { struct acpi_device * dev, * next; int result; @@ -1387,10 +1387,6 @@ static int root_suspend(struct acpi_device * acpi_dev) list_for_each_entry_safe_reverse(dev, next, &acpi_device_list, g_list) { if (dev->driver && dev->driver->ops.suspend) { spin_unlock(&acpi_device_lock); - - /* TBD: What suspend state should be passed - * to device? - */ result = dev->driver->ops.suspend(dev, 0); if (result) { printk(KERN_ERR PREFIX "[%s - %s] Suspend failed: %d\n", @@ -1416,7 +1412,7 @@ static int acpi_device_suspend(struct device * dev, pm_message_t state) * ACPI driver methods. */ if (acpi_dev->handle == ACPI_ROOT_OBJECT) - root_suspend(acpi_dev); + root_suspend(acpi_dev, state); return 0; } @@ -1431,10 +1427,6 @@ static int root_resume(struct acpi_device * acpi_dev) list_for_each_entry_safe(dev, next, &acpi_device_list, g_list) { if (dev->driver && dev->driver->ops.resume) { spin_unlock(&acpi_device_lock); - - /* TBD: What suspend state should be passed - * to device? - */ result = dev->driver->ops.resume(dev, 0); if (result) { printk(KERN_ERR PREFIX "[%s - %s] resume failed: %d\n", -- cgit v1.2.1 From 0feabb01d93e5801d1127416a66cfc3963280bca Mon Sep 17 00:00:00 2001 From: Konstantin Karasyov Date: Mon, 8 May 2006 00:00:00 -0400 Subject: ACPI: create acpi_fan_suspend()/acpi_fan_resume() http://bugzilla.kernel.org/show_bug.cgi?id=5000 Signed-off-by: Len Brown --- drivers/acpi/bus.c | 14 ++++++++------ drivers/acpi/fan.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 606f8733a776..eff696f2b6bb 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -205,12 +205,14 @@ int acpi_bus_set_power(acpi_handle handle, int state) * Get device's current power state if it's unknown * This means device power state isn't initialized or previous setting failed */ - if (device->power.state == ACPI_STATE_UNKNOWN) - acpi_bus_get_power(device->handle, &device->power.state); - if (state == device->power.state) { - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", - state)); - return_VALUE(0); + if (!device->flags.force_power_state) { + if (device->power.state == ACPI_STATE_UNKNOWN) + acpi_bus_get_power(device->handle, &device->power.state); + if (state == device->power.state) { + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", + state)); + return_VALUE(0); + } } if (!device->power.states[state].flags.valid) { ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Device does not support D%d\n", diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c index e8165c4f162a..1cd25784b7a4 100644 --- a/drivers/acpi/fan.c +++ b/drivers/acpi/fan.c @@ -48,6 +48,8 @@ MODULE_LICENSE("GPL"); static int acpi_fan_add(struct acpi_device *device); static int acpi_fan_remove(struct acpi_device *device, int type); +static int acpi_fan_suspend(struct acpi_device *device, int state); +static int acpi_fan_resume(struct acpi_device *device, int state); static struct acpi_driver acpi_fan_driver = { .name = ACPI_FAN_DRIVER_NAME, @@ -56,6 +58,8 @@ static struct acpi_driver acpi_fan_driver = { .ops = { .add = acpi_fan_add, .remove = acpi_fan_remove, + .suspend = acpi_fan_suspend, + .resume = acpi_fan_resume, }, }; @@ -206,6 +210,10 @@ static int acpi_fan_add(struct acpi_device *device) goto end; } + device->flags.force_power_state = 1; + acpi_bus_set_power(device->handle, state); + device->flags.force_power_state = 0; + result = acpi_fan_add_fs(device); if (result) goto end; @@ -239,6 +247,38 @@ static int acpi_fan_remove(struct acpi_device *device, int type) return_VALUE(0); } +static int acpi_fan_suspend(struct acpi_device *device, int state) +{ + if (!device) + return -EINVAL; + + acpi_bus_set_power(device->handle, ACPI_STATE_D0); + + return AE_OK; +} + +static int acpi_fan_resume(struct acpi_device *device, int state) +{ + int result = 0; + int power_state = 0; + + if (!device) + return -EINVAL; + + result = acpi_bus_get_power(device->handle, &power_state); + if (result) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, + "Error reading fan power state\n")); + return result; + } + + device->flags.force_power_state = 1; + acpi_bus_set_power(device->handle, power_state); + device->flags.force_power_state = 0; + + return result; +} + static int __init acpi_fan_init(void) { int result = 0; -- cgit v1.2.1 From 74ce1468128e299fe6a85e7e78e528e45e72d6d9 Mon Sep 17 00:00:00 2001 From: Konstantin Karasyov Date: Mon, 8 May 2006 08:32:00 -0400 Subject: ACPI: create acpi_thermal_resume() http://bugzilla.kernel.org/show_bug.cgi?id=4364 Signed-off-by: Konstantin Karasyov Signed-off-by: Len Brown --- drivers/acpi/thermal.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'drivers/acpi') diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 19f3ea48475e..928dcf9e77c7 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -82,6 +82,7 @@ MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.\n"); static int acpi_thermal_add(struct acpi_device *device); static int acpi_thermal_remove(struct acpi_device *device, int type); +static int acpi_thermal_resume(struct acpi_device *device, int state); static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file); static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file); static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file); @@ -103,6 +104,7 @@ static struct acpi_driver acpi_thermal_driver = { .ops = { .add = acpi_thermal_add, .remove = acpi_thermal_remove, + .resume = acpi_thermal_resume, }, }; @@ -1416,6 +1418,20 @@ static int acpi_thermal_remove(struct acpi_device *device, int type) return_VALUE(0); } +static int acpi_thermal_resume(struct acpi_device *device, int state) +{ + struct acpi_thermal *tz = NULL; + + if (!device || !acpi_driver_data(device)) + return_VALUE(-EINVAL); + + tz = (struct acpi_thermal *)acpi_driver_data(device); + + acpi_thermal_check(tz); + + return AE_OK; +} + static int __init acpi_thermal_init(void) { int result = 0; -- cgit v1.2.1