2 * acpi_power.c - ACPI Bus Power Management ($Revision: 39 $)
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 * ACPI power-managed devices may be controlled in two ways:
28 * 1. via "Device Specific (D-State) Control"
29 * 2. via "Power Resource Control".
30 * This module is used to manage devices relying on Power Resource Control.
32 * An ACPI "power resource object" describes a software controllable power
33 * plane, clock plane, or other resource used by a power managed device.
34 * A device may rely on multiple power resources, and a power resource
35 * may be shared by multiple devices.
38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/types.h>
42 #include <linux/slab.h>
43 #include <linux/pm_runtime.h>
44 #include <linux/sysfs.h>
45 #include <acpi/acpi_bus.h>
46 #include <acpi/acpi_drivers.h>
50 #define PREFIX "ACPI: "
52 #define _COMPONENT ACPI_POWER_COMPONENT
53 ACPI_MODULE_NAME("power");
54 #define ACPI_POWER_CLASS "power_resource"
55 #define ACPI_POWER_DEVICE_NAME "Power Resource"
56 #define ACPI_POWER_FILE_INFO "info"
57 #define ACPI_POWER_FILE_STATUS "state"
58 #define ACPI_POWER_RESOURCE_STATE_OFF 0x00
59 #define ACPI_POWER_RESOURCE_STATE_ON 0x01
60 #define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
62 struct acpi_power_dependent_device
{
63 struct list_head node
;
64 struct acpi_device
*adev
;
65 struct work_struct work
;
68 struct acpi_power_resource
{
69 struct acpi_device device
;
70 struct list_head list_node
;
71 struct list_head dependent
;
75 unsigned int ref_count
;
77 struct mutex resource_lock
;
80 struct acpi_power_resource_entry
{
81 struct list_head node
;
82 struct acpi_power_resource
*resource
;
85 static LIST_HEAD(acpi_power_resource_list
);
86 static DEFINE_MUTEX(power_resource_list_lock
);
88 /* --------------------------------------------------------------------------
89 Power Resource Management
90 -------------------------------------------------------------------------- */
93 struct acpi_power_resource
*to_power_resource(struct acpi_device
*device
)
95 return container_of(device
, struct acpi_power_resource
, device
);
98 static struct acpi_power_resource
*acpi_power_get_context(acpi_handle handle
)
100 struct acpi_device
*device
;
102 if (acpi_bus_get_device(handle
, &device
))
105 return to_power_resource(device
);
108 static int acpi_power_resources_list_add(acpi_handle handle
,
109 struct list_head
*list
)
111 struct acpi_power_resource
*resource
= acpi_power_get_context(handle
);
112 struct acpi_power_resource_entry
*entry
;
114 if (!resource
|| !list
)
117 entry
= kzalloc(sizeof(*entry
), GFP_KERNEL
);
121 entry
->resource
= resource
;
122 if (!list_empty(list
)) {
123 struct acpi_power_resource_entry
*e
;
125 list_for_each_entry(e
, list
, node
)
126 if (e
->resource
->order
> resource
->order
) {
127 list_add_tail(&entry
->node
, &e
->node
);
131 list_add_tail(&entry
->node
, list
);
135 void acpi_power_resources_list_free(struct list_head
*list
)
137 struct acpi_power_resource_entry
*entry
, *e
;
139 list_for_each_entry_safe(entry
, e
, list
, node
) {
140 list_del(&entry
->node
);
145 int acpi_extract_power_resources(union acpi_object
*package
, unsigned int start
,
146 struct list_head
*list
)
151 for (i
= start
; i
< package
->package
.count
; i
++) {
152 union acpi_object
*element
= &package
->package
.elements
[i
];
155 if (element
->type
!= ACPI_TYPE_LOCAL_REFERENCE
) {
159 rhandle
= element
->reference
.handle
;
164 err
= acpi_add_power_resource(rhandle
);
168 err
= acpi_power_resources_list_add(rhandle
, list
);
173 acpi_power_resources_list_free(list
);
178 static int acpi_power_get_state(acpi_handle handle
, int *state
)
180 acpi_status status
= AE_OK
;
181 unsigned long long sta
= 0;
183 struct acpi_buffer buffer
= { sizeof(node_name
), node_name
};
186 if (!handle
|| !state
)
189 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, &sta
);
190 if (ACPI_FAILURE(status
))
193 *state
= (sta
& 0x01)?ACPI_POWER_RESOURCE_STATE_ON
:
194 ACPI_POWER_RESOURCE_STATE_OFF
;
196 acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
);
198 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Resource [%s] is %s\n",
200 *state
? "on" : "off"));
205 static int acpi_power_get_list_state(struct list_head
*list
, int *state
)
207 struct acpi_power_resource_entry
*entry
;
213 /* The state of the list is 'on' IFF all resources are 'on'. */
214 list_for_each_entry(entry
, list
, node
) {
215 struct acpi_power_resource
*resource
= entry
->resource
;
216 acpi_handle handle
= resource
->device
.handle
;
219 mutex_lock(&resource
->resource_lock
);
220 result
= acpi_power_get_state(handle
, &cur_state
);
221 mutex_unlock(&resource
->resource_lock
);
225 if (cur_state
!= ACPI_POWER_RESOURCE_STATE_ON
)
229 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Resource list is %s\n",
230 cur_state
? "on" : "off"));
236 static void acpi_power_resume_dependent(struct work_struct
*work
)
238 struct acpi_power_dependent_device
*dep
;
239 struct acpi_device_physical_node
*pn
;
240 struct acpi_device
*adev
;
243 dep
= container_of(work
, struct acpi_power_dependent_device
, work
);
245 if (acpi_power_get_inferred_state(adev
, &state
))
248 if (state
> ACPI_STATE_D0
)
251 mutex_lock(&adev
->physical_node_lock
);
253 list_for_each_entry(pn
, &adev
->physical_node_list
, node
)
254 pm_request_resume(pn
->dev
);
256 list_for_each_entry(pn
, &adev
->power_dependent
, node
)
257 pm_request_resume(pn
->dev
);
259 mutex_unlock(&adev
->physical_node_lock
);
262 static int __acpi_power_on(struct acpi_power_resource
*resource
)
264 acpi_status status
= AE_OK
;
266 status
= acpi_evaluate_object(resource
->device
.handle
, "_ON", NULL
, NULL
);
267 if (ACPI_FAILURE(status
))
270 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Power resource [%s] turned on\n",
276 static int acpi_power_on_unlocked(struct acpi_power_resource
*resource
)
280 if (resource
->ref_count
++) {
281 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
282 "Power resource [%s] already on",
285 result
= __acpi_power_on(resource
);
287 resource
->ref_count
--;
289 struct acpi_power_dependent_device
*dep
;
291 list_for_each_entry(dep
, &resource
->dependent
, node
)
292 schedule_work(&dep
->work
);
298 static int acpi_power_on(struct acpi_power_resource
*resource
)
302 mutex_lock(&resource
->resource_lock
);
303 result
= acpi_power_on_unlocked(resource
);
304 mutex_unlock(&resource
->resource_lock
);
308 static int __acpi_power_off(struct acpi_power_resource
*resource
)
312 status
= acpi_evaluate_object(resource
->device
.handle
, "_OFF",
314 if (ACPI_FAILURE(status
))
317 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Power resource [%s] turned off\n",
322 static int acpi_power_off_unlocked(struct acpi_power_resource
*resource
)
326 if (!resource
->ref_count
) {
327 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
328 "Power resource [%s] already off",
333 if (--resource
->ref_count
) {
334 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
335 "Power resource [%s] still in use\n",
338 result
= __acpi_power_off(resource
);
340 resource
->ref_count
++;
345 static int acpi_power_off(struct acpi_power_resource
*resource
)
349 mutex_lock(&resource
->resource_lock
);
350 result
= acpi_power_off_unlocked(resource
);
351 mutex_unlock(&resource
->resource_lock
);
355 static int acpi_power_off_list(struct list_head
*list
)
357 struct acpi_power_resource_entry
*entry
;
360 list_for_each_entry_reverse(entry
, list
, node
) {
361 result
= acpi_power_off(entry
->resource
);
368 list_for_each_entry_continue(entry
, list
, node
)
369 acpi_power_on(entry
->resource
);
374 static int acpi_power_on_list(struct list_head
*list
)
376 struct acpi_power_resource_entry
*entry
;
379 list_for_each_entry(entry
, list
, node
) {
380 result
= acpi_power_on(entry
->resource
);
387 list_for_each_entry_continue_reverse(entry
, list
, node
)
388 acpi_power_off(entry
->resource
);
393 static void acpi_power_add_dependent(struct acpi_power_resource
*resource
,
394 struct acpi_device
*adev
)
396 struct acpi_power_dependent_device
*dep
;
398 mutex_lock(&resource
->resource_lock
);
400 list_for_each_entry(dep
, &resource
->dependent
, node
)
401 if (dep
->adev
== adev
)
404 dep
= kzalloc(sizeof(*dep
), GFP_KERNEL
);
409 INIT_WORK(&dep
->work
, acpi_power_resume_dependent
);
410 list_add_tail(&dep
->node
, &resource
->dependent
);
413 mutex_unlock(&resource
->resource_lock
);
416 static void acpi_power_remove_dependent(struct acpi_power_resource
*resource
,
417 struct acpi_device
*adev
)
419 struct acpi_power_dependent_device
*dep
;
420 struct work_struct
*work
= NULL
;
422 mutex_lock(&resource
->resource_lock
);
424 list_for_each_entry(dep
, &resource
->dependent
, node
)
425 if (dep
->adev
== adev
) {
426 list_del(&dep
->node
);
431 mutex_unlock(&resource
->resource_lock
);
434 cancel_work_sync(work
);
439 static struct attribute
*attrs
[] = {
443 static struct attribute_group attr_groups
[] = {
445 .name
= "power_resources_D0",
449 .name
= "power_resources_D1",
453 .name
= "power_resources_D2",
456 [ACPI_STATE_D3_HOT
] = {
457 .name
= "power_resources_D3hot",
462 static void acpi_power_hide_list(struct acpi_device
*adev
, int state
)
464 struct acpi_device_power_state
*ps
= &adev
->power
.states
[state
];
465 struct acpi_power_resource_entry
*entry
;
467 if (list_empty(&ps
->resources
))
470 list_for_each_entry_reverse(entry
, &ps
->resources
, node
) {
471 struct acpi_device
*res_dev
= &entry
->resource
->device
;
473 sysfs_remove_link_from_group(&adev
->dev
.kobj
,
474 attr_groups
[state
].name
,
475 dev_name(&res_dev
->dev
));
477 sysfs_remove_group(&adev
->dev
.kobj
, &attr_groups
[state
]);
480 static void acpi_power_expose_list(struct acpi_device
*adev
, int state
)
482 struct acpi_device_power_state
*ps
= &adev
->power
.states
[state
];
483 struct acpi_power_resource_entry
*entry
;
486 if (list_empty(&ps
->resources
))
489 ret
= sysfs_create_group(&adev
->dev
.kobj
, &attr_groups
[state
]);
493 list_for_each_entry(entry
, &ps
->resources
, node
) {
494 struct acpi_device
*res_dev
= &entry
->resource
->device
;
496 ret
= sysfs_add_link_to_group(&adev
->dev
.kobj
,
497 attr_groups
[state
].name
,
499 dev_name(&res_dev
->dev
));
501 acpi_power_hide_list(adev
, state
);
507 void acpi_power_add_remove_device(struct acpi_device
*adev
, bool add
)
509 struct acpi_device_power_state
*ps
;
510 struct acpi_power_resource_entry
*entry
;
513 if (!adev
->power
.flags
.power_resources
)
516 ps
= &adev
->power
.states
[ACPI_STATE_D0
];
517 list_for_each_entry(entry
, &ps
->resources
, node
) {
518 struct acpi_power_resource
*resource
= entry
->resource
;
521 acpi_power_add_dependent(resource
, adev
);
523 acpi_power_remove_dependent(resource
, adev
);
526 for (state
= ACPI_STATE_D0
; state
<= ACPI_STATE_D3_HOT
; state
++) {
528 acpi_power_expose_list(adev
, state
);
530 acpi_power_hide_list(adev
, state
);
534 int acpi_power_wakeup_list_init(struct list_head
*list
, int *system_level_p
)
536 struct acpi_power_resource_entry
*entry
;
537 int system_level
= 5;
539 list_for_each_entry(entry
, list
, node
) {
540 struct acpi_power_resource
*resource
= entry
->resource
;
541 acpi_handle handle
= resource
->device
.handle
;
545 mutex_lock(&resource
->resource_lock
);
547 result
= acpi_power_get_state(handle
, &state
);
549 mutex_unlock(&resource
->resource_lock
);
552 if (state
== ACPI_POWER_RESOURCE_STATE_ON
) {
553 resource
->ref_count
++;
554 resource
->wakeup_enabled
= true;
556 if (system_level
> resource
->system_level
)
557 system_level
= resource
->system_level
;
559 mutex_unlock(&resource
->resource_lock
);
561 *system_level_p
= system_level
;
565 /* --------------------------------------------------------------------------
566 Device Power Management
567 -------------------------------------------------------------------------- */
570 * acpi_device_sleep_wake - execute _DSW (Device Sleep Wake) or (deprecated in
571 * ACPI 3.0) _PSW (Power State Wake)
572 * @dev: Device to handle.
573 * @enable: 0 - disable, 1 - enable the wake capabilities of the device.
574 * @sleep_state: Target sleep state of the system.
575 * @dev_state: Target power state of the device.
577 * Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
578 * State Wake) for the device, if present. On failure reset the device's
579 * wakeup.flags.valid flag.
582 * 0 if either _DSW or _PSW has been successfully executed
583 * 0 if neither _DSW nor _PSW has been found
584 * -ENODEV if the execution of either _DSW or _PSW has failed
586 int acpi_device_sleep_wake(struct acpi_device
*dev
,
587 int enable
, int sleep_state
, int dev_state
)
589 union acpi_object in_arg
[3];
590 struct acpi_object_list arg_list
= { 3, in_arg
};
591 acpi_status status
= AE_OK
;
594 * Try to execute _DSW first.
596 * Three agruments are needed for the _DSW object:
597 * Argument 0: enable/disable the wake capabilities
598 * Argument 1: target system state
599 * Argument 2: target device state
600 * When _DSW object is called to disable the wake capabilities, maybe
601 * the first argument is filled. The values of the other two agruments
604 in_arg
[0].type
= ACPI_TYPE_INTEGER
;
605 in_arg
[0].integer
.value
= enable
;
606 in_arg
[1].type
= ACPI_TYPE_INTEGER
;
607 in_arg
[1].integer
.value
= sleep_state
;
608 in_arg
[2].type
= ACPI_TYPE_INTEGER
;
609 in_arg
[2].integer
.value
= dev_state
;
610 status
= acpi_evaluate_object(dev
->handle
, "_DSW", &arg_list
, NULL
);
611 if (ACPI_SUCCESS(status
)) {
613 } else if (status
!= AE_NOT_FOUND
) {
614 printk(KERN_ERR PREFIX
"_DSW execution failed\n");
615 dev
->wakeup
.flags
.valid
= 0;
621 in_arg
[0].integer
.value
= enable
;
622 status
= acpi_evaluate_object(dev
->handle
, "_PSW", &arg_list
, NULL
);
623 if (ACPI_FAILURE(status
) && (status
!= AE_NOT_FOUND
)) {
624 printk(KERN_ERR PREFIX
"_PSW execution failed\n");
625 dev
->wakeup
.flags
.valid
= 0;
633 * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229):
634 * 1. Power on the power resources required for the wakeup device
635 * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
636 * State Wake) for the device, if present
638 int acpi_enable_wakeup_device_power(struct acpi_device
*dev
, int sleep_state
)
640 struct acpi_power_resource_entry
*entry
;
643 if (!dev
|| !dev
->wakeup
.flags
.valid
)
646 mutex_lock(&acpi_device_lock
);
648 if (dev
->wakeup
.prepare_count
++)
651 list_for_each_entry(entry
, &dev
->wakeup
.resources
, node
) {
652 struct acpi_power_resource
*resource
= entry
->resource
;
654 mutex_lock(&resource
->resource_lock
);
656 if (!resource
->wakeup_enabled
) {
657 err
= acpi_power_on_unlocked(resource
);
659 resource
->wakeup_enabled
= true;
662 mutex_unlock(&resource
->resource_lock
);
666 "Cannot turn wakeup power resources on\n");
667 dev
->wakeup
.flags
.valid
= 0;
672 * Passing 3 as the third argument below means the device may be
673 * put into arbitrary power state afterward.
675 err
= acpi_device_sleep_wake(dev
, 1, sleep_state
, 3);
677 dev
->wakeup
.prepare_count
= 0;
680 mutex_unlock(&acpi_device_lock
);
685 * Shutdown a wakeup device, counterpart of above method
686 * 1. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
687 * State Wake) for the device, if present
688 * 2. Shutdown down the power resources
690 int acpi_disable_wakeup_device_power(struct acpi_device
*dev
)
692 struct acpi_power_resource_entry
*entry
;
695 if (!dev
|| !dev
->wakeup
.flags
.valid
)
698 mutex_lock(&acpi_device_lock
);
700 if (--dev
->wakeup
.prepare_count
> 0)
704 * Executing the code below even if prepare_count is already zero when
705 * the function is called may be useful, for example for initialisation.
707 if (dev
->wakeup
.prepare_count
< 0)
708 dev
->wakeup
.prepare_count
= 0;
710 err
= acpi_device_sleep_wake(dev
, 0, 0, 0);
714 list_for_each_entry(entry
, &dev
->wakeup
.resources
, node
) {
715 struct acpi_power_resource
*resource
= entry
->resource
;
717 mutex_lock(&resource
->resource_lock
);
719 if (resource
->wakeup_enabled
) {
720 err
= acpi_power_off_unlocked(resource
);
722 resource
->wakeup_enabled
= false;
725 mutex_unlock(&resource
->resource_lock
);
729 "Cannot turn wakeup power resources off\n");
730 dev
->wakeup
.flags
.valid
= 0;
736 mutex_unlock(&acpi_device_lock
);
740 int acpi_power_get_inferred_state(struct acpi_device
*device
, int *state
)
746 if (!device
|| !state
)
750 * We know a device's inferred power state when all the resources
751 * required for a given D-state are 'on'.
753 for (i
= ACPI_STATE_D0
; i
<= ACPI_STATE_D3_HOT
; i
++) {
754 struct list_head
*list
= &device
->power
.states
[i
].resources
;
756 if (list_empty(list
))
759 result
= acpi_power_get_list_state(list
, &list_state
);
763 if (list_state
== ACPI_POWER_RESOURCE_STATE_ON
) {
769 *state
= ACPI_STATE_D3
;
773 int acpi_power_on_resources(struct acpi_device
*device
, int state
)
775 if (!device
|| state
< ACPI_STATE_D0
|| state
> ACPI_STATE_D3_HOT
)
778 return acpi_power_on_list(&device
->power
.states
[state
].resources
);
781 int acpi_power_transition(struct acpi_device
*device
, int state
)
785 if (!device
|| (state
< ACPI_STATE_D0
) || (state
> ACPI_STATE_D3_COLD
))
788 if (device
->power
.state
== state
|| !device
->flags
.power_manageable
)
791 if ((device
->power
.state
< ACPI_STATE_D0
)
792 || (device
->power
.state
> ACPI_STATE_D3_COLD
))
795 /* TBD: Resources must be ordered. */
798 * First we reference all power resources required in the target list
799 * (e.g. so the device doesn't lose power while transitioning). Then,
800 * we dereference all power resources used in the current list.
802 if (state
< ACPI_STATE_D3_COLD
)
803 result
= acpi_power_on_list(
804 &device
->power
.states
[state
].resources
);
806 if (!result
&& device
->power
.state
< ACPI_STATE_D3_COLD
)
808 &device
->power
.states
[device
->power
.state
].resources
);
810 /* We shouldn't change the state unless the above operations succeed. */
811 device
->power
.state
= result
? ACPI_STATE_UNKNOWN
: state
;
816 static void acpi_release_power_resource(struct device
*dev
)
818 struct acpi_device
*device
= to_acpi_device(dev
);
819 struct acpi_power_resource
*resource
;
821 resource
= container_of(device
, struct acpi_power_resource
, device
);
823 mutex_lock(&power_resource_list_lock
);
824 list_del(&resource
->list_node
);
825 mutex_unlock(&power_resource_list_lock
);
827 acpi_free_ids(device
);
831 static ssize_t
acpi_power_in_use_show(struct device
*dev
,
832 struct device_attribute
*attr
,
834 struct acpi_power_resource
*resource
;
836 resource
= to_power_resource(to_acpi_device(dev
));
837 return sprintf(buf
, "%u\n", !!resource
->ref_count
);
839 static DEVICE_ATTR(resource_in_use
, 0444, acpi_power_in_use_show
, NULL
);
841 static void acpi_power_sysfs_remove(struct acpi_device
*device
)
843 device_remove_file(&device
->dev
, &dev_attr_resource_in_use
);
846 int acpi_add_power_resource(acpi_handle handle
)
848 struct acpi_power_resource
*resource
;
849 struct acpi_device
*device
= NULL
;
850 union acpi_object acpi_object
;
851 struct acpi_buffer buffer
= { sizeof(acpi_object
), &acpi_object
};
853 int state
, result
= -ENODEV
;
855 acpi_bus_get_device(handle
, &device
);
859 resource
= kzalloc(sizeof(*resource
), GFP_KERNEL
);
863 device
= &resource
->device
;
864 acpi_init_device_object(device
, handle
, ACPI_BUS_TYPE_POWER
,
866 mutex_init(&resource
->resource_lock
);
867 INIT_LIST_HEAD(&resource
->dependent
);
868 resource
->name
= device
->pnp
.bus_id
;
869 strcpy(acpi_device_name(device
), ACPI_POWER_DEVICE_NAME
);
870 strcpy(acpi_device_class(device
), ACPI_POWER_CLASS
);
871 device
->power
.state
= ACPI_STATE_UNKNOWN
;
873 /* Evalute the object to get the system level and resource order. */
874 status
= acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
);
875 if (ACPI_FAILURE(status
))
878 resource
->system_level
= acpi_object
.power_resource
.system_level
;
879 resource
->order
= acpi_object
.power_resource
.resource_order
;
881 result
= acpi_power_get_state(handle
, &state
);
885 printk(KERN_INFO PREFIX
"%s [%s] (%s)\n", acpi_device_name(device
),
886 acpi_device_bid(device
), state
? "on" : "off");
888 device
->flags
.match_driver
= true;
889 result
= acpi_device_add(device
, acpi_release_power_resource
);
893 if (!device_create_file(&device
->dev
, &dev_attr_resource_in_use
))
894 device
->remove
= acpi_power_sysfs_remove
;
896 mutex_lock(&power_resource_list_lock
);
897 list_add(&resource
->list_node
, &acpi_power_resource_list
);
898 mutex_unlock(&power_resource_list_lock
);
899 acpi_device_add_finalize(device
);
903 acpi_release_power_resource(&device
->dev
);
907 #ifdef CONFIG_ACPI_SLEEP
908 void acpi_resume_power_resources(void)
910 struct acpi_power_resource
*resource
;
912 mutex_lock(&power_resource_list_lock
);
914 list_for_each_entry(resource
, &acpi_power_resource_list
, list_node
) {
917 mutex_lock(&resource
->resource_lock
);
919 result
= acpi_power_get_state(resource
->device
.handle
, &state
);
923 if (state
== ACPI_POWER_RESOURCE_STATE_OFF
924 && resource
->ref_count
) {
925 dev_info(&resource
->device
.dev
, "Turning ON\n");
926 __acpi_power_on(resource
);
927 } else if (state
== ACPI_POWER_RESOURCE_STATE_ON
928 && !resource
->ref_count
) {
929 dev_info(&resource
->device
.dev
, "Turning OFF\n");
930 __acpi_power_off(resource
);
933 mutex_unlock(&resource
->resource_lock
);
936 mutex_unlock(&power_resource_list_lock
);