38 #include <linux/kernel.h>
39 #include <linux/module.h>
41 #include <linux/types.h>
42 #include <linux/slab.h>
49 #define PREFIX "ACPI: "
51 #define _COMPONENT ACPI_POWER_COMPONENT
53 #define ACPI_POWER_CLASS "power_resource"
54 #define ACPI_POWER_DEVICE_NAME "Power Resource"
55 #define ACPI_POWER_FILE_INFO "info"
56 #define ACPI_POWER_FILE_STATUS "state"
57 #define ACPI_POWER_RESOURCE_STATE_OFF 0x00
58 #define ACPI_POWER_RESOURCE_STATE_ON 0x01
59 #define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
61 static int acpi_power_add(
struct acpi_device *
device);
62 static int acpi_power_remove(
struct acpi_device *
device,
int type);
70 #ifdef CONFIG_PM_SLEEP
71 static int acpi_power_resume(
struct device *
dev);
75 static struct acpi_driver acpi_power_driver = {
78 .ids = power_device_ids,
80 .add = acpi_power_add,
81 .remove = acpi_power_remove,
83 .drv.pm = &acpi_power_pm,
113 static struct list_head acpi_power_resource_list;
136 *resource = acpi_driver_data(device);
146 unsigned long long sta = 0;
151 if (!handle || !state)
165 *state ?
"on" :
"off"));
180 for (i = 0; i < list->
count; i++) {
185 result = acpi_power_get_context(handle, &resource);
191 result = acpi_power_get_state(handle, &cur_state);
203 cur_state ?
"on" :
"off"));
213 struct acpi_device *acpi_dev;
224 pm_request_resume(device->
dev);
247 bool resume_device =
false;
251 result = acpi_power_get_context(handle, &resource);
259 "Power resource [%s] already on",
262 result = __acpi_power_on(resource);
266 resume_device =
true;
276 device_list = resource->
devices;
277 while (device_list) {
278 acpi_power_on_device(device_list->
device);
279 device_list = device_list->
next;
293 result = acpi_power_get_context(handle, &resource);
301 "Power resource [%s] already off",
308 "Power resource [%s] still in use\n",
321 "Power resource [%s] turned off\n",
331 static void __acpi_power_off_list(
struct acpi_handle_list *list,
int num_res)
335 for (i = num_res - 1; i >= 0 ; i--)
336 acpi_power_off(list->
handles[i]);
341 __acpi_power_off_list(list, list->
count);
349 for (i = 0; i < list->
count; i++) {
350 result = acpi_power_on(list->
handles[i]);
352 __acpi_power_off_list(list, i);
360 static void __acpi_power_resource_unregister_device(
struct device *
dev,
366 if (acpi_power_get_context(res_handle, &resource))
373 if (curr->
device->dev == dev) {
392 struct acpi_device *acpi_dev;
404 for (i = 0; i < list->
count; i++)
405 __acpi_power_resource_unregister_device(dev,
410 static int __acpi_power_resource_register_device(
417 result = acpi_power_get_context(handle, &resource);
421 power_resource_device = kzalloc(
423 if (!power_resource_device)
426 power_resource_device->
device = powered_device;
430 resource->
devices = power_resource_device;
439 struct acpi_device *acpi_dev;
449 goto no_power_resource;
451 if (!acpi_dev->power.flags.power_resources)
452 goto no_power_resource;
454 powered_device = kzalloc(
sizeof(*powered_device),
GFP_KERNEL);
458 powered_device->
dev =
dev;
463 for (i = 0; i < list->
count; i++) {
464 ret = __acpi_power_resource_register_device(powered_device,
519 in_arg[1].
integer.value = sleep_state;
527 dev->wakeup.flags.valid = 0;
537 dev->wakeup.flags.valid = 0;
554 if (!dev || !dev->wakeup.flags.valid)
559 if (dev->wakeup.prepare_count++)
563 for (i = 0; i < dev->wakeup.resources.count; i++) {
564 int ret = acpi_power_on(dev->wakeup.resources.handles[i]);
567 dev->wakeup.flags.valid = 0;
581 dev->wakeup.prepare_count = 0;
598 if (!dev || !dev->wakeup.flags.valid)
603 if (--dev->wakeup.prepare_count > 0)
610 if (dev->wakeup.prepare_count < 0)
611 dev->wakeup.prepare_count = 0;
618 for (i = 0; i < dev->wakeup.resources.count; i++) {
619 int ret = acpi_power_off(dev->wakeup.resources.handles[i]);
622 dev->wakeup.flags.valid = 0;
644 if (!device || !state)
652 list = &device->power.states[
i].resources;
656 result = acpi_power_get_list_state(list, &list_state);
675 return acpi_power_on_list(&device->power.states[state].resources);
685 if (device->power.state == state)
700 result = acpi_power_on_list(
701 &device->power.states[state].resources);
705 &device->power.states[device->power.state].resources);
717 static int acpi_power_add(
struct acpi_device *device)
719 int result = 0,
state;
733 resource->
device = device;
750 result = acpi_power_get_state(device->handle, &state);
767 acpi_device_bid(device), state ?
"on" :
"off");
776 static int acpi_power_remove(
struct acpi_device *device,
int type)
783 resource = acpi_driver_data(device);
792 #ifdef CONFIG_PM_SLEEP
793 static int acpi_power_resume(
struct device *dev)
795 int result = 0,
state;
796 struct acpi_device *device;
802 device = to_acpi_device(dev);
803 resource = acpi_driver_data(device);
809 result = acpi_power_get_state(device->handle, &state);
814 result = __acpi_power_on(resource);
825 INIT_LIST_HEAD(&acpi_power_resource_list);