1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * drivers/acpi/power.c - ACPI Power Resources management.
5 * Copyright (C) 2001 - 2015 Intel Corp.
6 * Author: Andy Grover <andrew.grover@intel.com>
7 * Author: Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
8 * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
12 * ACPI power-managed devices may be controlled in two ways:
13 * 1. via "Device Specific (D-State) Control"
14 * 2. via "Power Resource Control".
15 * The code below deals with ACPI Power Resources control.
17 * An ACPI "power resource object" represents a software controllable power
18 * plane, clock plane, or other resource depended on by a device.
20 * A device may rely on multiple power resources, and a power resource
21 * may be shared by multiple devices.
24 #define pr_fmt(fmt) "ACPI: PM: " fmt
26 #include <linux/dmi.h>
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/slab.h>
32 #include <linux/string_choices.h>
33 #include <linux/pm_runtime.h>
34 #include <linux/sysfs.h>
35 #include <linux/acpi.h>
39 #define ACPI_POWER_CLASS "power_resource"
40 #define ACPI_POWER_DEVICE_NAME "Power Resource"
41 #define ACPI_POWER_RESOURCE_STATE_OFF 0x00
42 #define ACPI_POWER_RESOURCE_STATE_ON 0x01
43 #define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
45 struct acpi_power_dependent_device {
47 struct list_head node;
50 struct acpi_power_resource {
51 struct acpi_device device;
52 struct list_head list_node;
55 unsigned int ref_count;
57 struct mutex resource_lock;
58 struct list_head dependents;
61 struct acpi_power_resource_entry {
62 struct list_head node;
63 struct acpi_power_resource *resource;
66 static bool unused_power_resources_quirk;
68 static LIST_HEAD(acpi_power_resource_list);
69 static DEFINE_MUTEX(power_resource_list_lock);
71 /* --------------------------------------------------------------------------
72 Power Resource Management
73 -------------------------------------------------------------------------- */
75 static inline const char *resource_dev_name(struct acpi_power_resource *pr)
77 return dev_name(&pr->device.dev);
81 struct acpi_power_resource *to_power_resource(struct acpi_device *device)
83 return container_of(device, struct acpi_power_resource, device);
86 static struct acpi_power_resource *acpi_power_get_context(acpi_handle handle)
88 struct acpi_device *device = acpi_fetch_acpi_dev(handle);
93 return to_power_resource(device);
96 static int acpi_power_resources_list_add(acpi_handle handle,
97 struct list_head *list)
99 struct acpi_power_resource *resource = acpi_power_get_context(handle);
100 struct acpi_power_resource_entry *entry;
102 if (!resource || !list)
105 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
109 entry->resource = resource;
110 if (!list_empty(list)) {
111 struct acpi_power_resource_entry *e;
113 list_for_each_entry(e, list, node)
114 if (e->resource->order > resource->order) {
115 list_add_tail(&entry->node, &e->node);
119 list_add_tail(&entry->node, list);
123 void acpi_power_resources_list_free(struct list_head *list)
125 struct acpi_power_resource_entry *entry, *e;
127 list_for_each_entry_safe(entry, e, list, node) {
128 list_del(&entry->node);
133 static bool acpi_power_resource_is_dup(union acpi_object *package,
134 unsigned int start, unsigned int i)
136 acpi_handle rhandle, dup;
139 /* The caller is expected to check the package element types */
140 rhandle = package->package.elements[i].reference.handle;
141 for (j = start; j < i; j++) {
142 dup = package->package.elements[j].reference.handle;
150 int acpi_extract_power_resources(union acpi_object *package, unsigned int start,
151 struct list_head *list)
156 for (i = start; i < package->package.count; i++) {
157 union acpi_object *element = &package->package.elements[i];
158 struct acpi_device *rdev;
161 if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
165 rhandle = element->reference.handle;
171 /* Some ACPI tables contain duplicate power resource references */
172 if (acpi_power_resource_is_dup(package, start, i))
175 rdev = acpi_add_power_resource(rhandle);
180 err = acpi_power_resources_list_add(rhandle, list);
185 acpi_power_resources_list_free(list);
190 static int __get_state(acpi_handle handle, u8 *state)
192 acpi_status status = AE_OK;
193 unsigned long long sta = 0;
196 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
197 if (ACPI_FAILURE(status))
200 cur_state = sta & ACPI_POWER_RESOURCE_STATE_ON;
202 acpi_handle_debug(handle, "Power resource is %s\n",
203 str_on_off(cur_state));
209 static int acpi_power_get_state(struct acpi_power_resource *resource, u8 *state)
211 if (resource->state == ACPI_POWER_RESOURCE_STATE_UNKNOWN) {
214 ret = __get_state(resource->device.handle, &resource->state);
219 *state = resource->state;
223 static int acpi_power_get_list_state(struct list_head *list, u8 *state)
225 struct acpi_power_resource_entry *entry;
226 u8 cur_state = ACPI_POWER_RESOURCE_STATE_OFF;
231 /* The state of the list is 'on' IFF all resources are 'on'. */
232 list_for_each_entry(entry, list, node) {
233 struct acpi_power_resource *resource = entry->resource;
236 mutex_lock(&resource->resource_lock);
237 result = acpi_power_get_state(resource, &cur_state);
238 mutex_unlock(&resource->resource_lock);
242 if (cur_state != ACPI_POWER_RESOURCE_STATE_ON)
246 pr_debug("Power resource list is %s\n", str_on_off(cur_state));
253 acpi_power_resource_add_dependent(struct acpi_power_resource *resource,
256 struct acpi_power_dependent_device *dep;
259 mutex_lock(&resource->resource_lock);
260 list_for_each_entry(dep, &resource->dependents, node) {
261 /* Only add it once */
266 dep = kzalloc(sizeof(*dep), GFP_KERNEL);
273 list_add_tail(&dep->node, &resource->dependents);
274 dev_dbg(dev, "added power dependency to [%s]\n",
275 resource_dev_name(resource));
278 mutex_unlock(&resource->resource_lock);
283 acpi_power_resource_remove_dependent(struct acpi_power_resource *resource,
286 struct acpi_power_dependent_device *dep;
288 mutex_lock(&resource->resource_lock);
289 list_for_each_entry(dep, &resource->dependents, node) {
290 if (dep->dev == dev) {
291 list_del(&dep->node);
293 dev_dbg(dev, "removed power dependency to [%s]\n",
294 resource_dev_name(resource));
298 mutex_unlock(&resource->resource_lock);
302 * acpi_device_power_add_dependent - Add dependent device of this ACPI device
303 * @adev: ACPI device pointer
304 * @dev: Dependent device
306 * If @adev has non-empty _PR0 the @dev is added as dependent device to all
307 * power resources returned by it. This means that whenever these power
308 * resources are turned _ON the dependent devices get runtime resumed. This
309 * is needed for devices such as PCI to allow its driver to re-initialize
310 * it after it went to D0uninitialized.
312 * If @adev does not have _PR0 this does nothing.
314 * Returns %0 in case of success and negative errno otherwise.
316 int acpi_device_power_add_dependent(struct acpi_device *adev,
319 struct acpi_power_resource_entry *entry;
320 struct list_head *resources;
323 if (!adev->flags.power_manageable)
326 resources = &adev->power.states[ACPI_STATE_D0].resources;
327 list_for_each_entry(entry, resources, node) {
328 ret = acpi_power_resource_add_dependent(entry->resource, dev);
336 list_for_each_entry(entry, resources, node)
337 acpi_power_resource_remove_dependent(entry->resource, dev);
343 * acpi_device_power_remove_dependent - Remove dependent device
344 * @adev: ACPI device pointer
345 * @dev: Dependent device
347 * Does the opposite of acpi_device_power_add_dependent() and removes the
348 * dependent device if it is found. Can be called to @adev that does not
351 void acpi_device_power_remove_dependent(struct acpi_device *adev,
354 struct acpi_power_resource_entry *entry;
355 struct list_head *resources;
357 if (!adev->flags.power_manageable)
360 resources = &adev->power.states[ACPI_STATE_D0].resources;
361 list_for_each_entry_reverse(entry, resources, node)
362 acpi_power_resource_remove_dependent(entry->resource, dev);
365 static int __acpi_power_on(struct acpi_power_resource *resource)
367 acpi_handle handle = resource->device.handle;
368 struct acpi_power_dependent_device *dep;
369 acpi_status status = AE_OK;
371 status = acpi_evaluate_object(handle, "_ON", NULL, NULL);
372 if (ACPI_FAILURE(status)) {
373 resource->state = ACPI_POWER_RESOURCE_STATE_UNKNOWN;
377 resource->state = ACPI_POWER_RESOURCE_STATE_ON;
379 acpi_handle_debug(handle, "Power resource turned on\n");
382 * If there are other dependents on this power resource we need to
383 * resume them now so that their drivers can re-initialize the
384 * hardware properly after it went back to D0.
386 if (list_empty(&resource->dependents) ||
387 list_is_singular(&resource->dependents))
390 list_for_each_entry(dep, &resource->dependents, node) {
391 dev_dbg(dep->dev, "runtime resuming because [%s] turned on\n",
392 resource_dev_name(resource));
393 pm_request_resume(dep->dev);
399 static int acpi_power_on_unlocked(struct acpi_power_resource *resource)
403 if (resource->ref_count++) {
404 acpi_handle_debug(resource->device.handle,
405 "Power resource already on\n");
407 result = __acpi_power_on(resource);
409 resource->ref_count--;
414 static int acpi_power_on(struct acpi_power_resource *resource)
418 mutex_lock(&resource->resource_lock);
419 result = acpi_power_on_unlocked(resource);
420 mutex_unlock(&resource->resource_lock);
424 static int __acpi_power_off(struct acpi_power_resource *resource)
426 acpi_handle handle = resource->device.handle;
429 status = acpi_evaluate_object(handle, "_OFF", NULL, NULL);
430 if (ACPI_FAILURE(status)) {
431 resource->state = ACPI_POWER_RESOURCE_STATE_UNKNOWN;
435 resource->state = ACPI_POWER_RESOURCE_STATE_OFF;
437 acpi_handle_debug(handle, "Power resource turned off\n");
442 static int acpi_power_off_unlocked(struct acpi_power_resource *resource)
446 if (!resource->ref_count) {
447 acpi_handle_debug(resource->device.handle,
448 "Power resource already off\n");
452 if (--resource->ref_count) {
453 acpi_handle_debug(resource->device.handle,
454 "Power resource still in use\n");
456 result = __acpi_power_off(resource);
458 resource->ref_count++;
463 static int acpi_power_off(struct acpi_power_resource *resource)
467 mutex_lock(&resource->resource_lock);
468 result = acpi_power_off_unlocked(resource);
469 mutex_unlock(&resource->resource_lock);
473 static int acpi_power_off_list(struct list_head *list)
475 struct acpi_power_resource_entry *entry;
478 list_for_each_entry_reverse(entry, list, node) {
479 result = acpi_power_off(entry->resource);
486 list_for_each_entry_continue(entry, list, node)
487 acpi_power_on(entry->resource);
492 static int acpi_power_on_list(struct list_head *list)
494 struct acpi_power_resource_entry *entry;
497 list_for_each_entry(entry, list, node) {
498 result = acpi_power_on(entry->resource);
505 list_for_each_entry_continue_reverse(entry, list, node)
506 acpi_power_off(entry->resource);
511 static struct attribute *attrs[] = {
515 static const struct attribute_group attr_groups[] = {
517 .name = "power_resources_D0",
521 .name = "power_resources_D1",
525 .name = "power_resources_D2",
528 [ACPI_STATE_D3_HOT] = {
529 .name = "power_resources_D3hot",
534 static const struct attribute_group wakeup_attr_group = {
535 .name = "power_resources_wakeup",
539 static void acpi_power_hide_list(struct acpi_device *adev,
540 struct list_head *resources,
541 const struct attribute_group *attr_group)
543 struct acpi_power_resource_entry *entry;
545 if (list_empty(resources))
548 list_for_each_entry_reverse(entry, resources, node) {
549 struct acpi_device *res_dev = &entry->resource->device;
551 sysfs_remove_link_from_group(&adev->dev.kobj,
553 dev_name(&res_dev->dev));
555 sysfs_remove_group(&adev->dev.kobj, attr_group);
558 static void acpi_power_expose_list(struct acpi_device *adev,
559 struct list_head *resources,
560 const struct attribute_group *attr_group)
562 struct acpi_power_resource_entry *entry;
565 if (list_empty(resources))
568 ret = sysfs_create_group(&adev->dev.kobj, attr_group);
572 list_for_each_entry(entry, resources, node) {
573 struct acpi_device *res_dev = &entry->resource->device;
575 ret = sysfs_add_link_to_group(&adev->dev.kobj,
578 dev_name(&res_dev->dev));
580 acpi_power_hide_list(adev, resources, attr_group);
586 static void acpi_power_expose_hide(struct acpi_device *adev,
587 struct list_head *resources,
588 const struct attribute_group *attr_group,
592 acpi_power_expose_list(adev, resources, attr_group);
594 acpi_power_hide_list(adev, resources, attr_group);
597 void acpi_power_add_remove_device(struct acpi_device *adev, bool add)
601 if (adev->wakeup.flags.valid)
602 acpi_power_expose_hide(adev, &adev->wakeup.resources,
603 &wakeup_attr_group, add);
605 if (!adev->power.flags.power_resources)
608 for (state = ACPI_STATE_D0; state <= ACPI_STATE_D3_HOT; state++)
609 acpi_power_expose_hide(adev,
610 &adev->power.states[state].resources,
611 &attr_groups[state], add);
614 int acpi_power_wakeup_list_init(struct list_head *list, int *system_level_p)
616 struct acpi_power_resource_entry *entry;
617 int system_level = 5;
619 list_for_each_entry(entry, list, node) {
620 struct acpi_power_resource *resource = entry->resource;
623 mutex_lock(&resource->resource_lock);
626 * Make sure that the power resource state and its reference
627 * counter value are consistent with each other.
629 if (!resource->ref_count &&
630 !acpi_power_get_state(resource, &state) &&
631 state == ACPI_POWER_RESOURCE_STATE_ON)
632 __acpi_power_off(resource);
634 if (system_level > resource->system_level)
635 system_level = resource->system_level;
637 mutex_unlock(&resource->resource_lock);
639 *system_level_p = system_level;
643 /* --------------------------------------------------------------------------
644 Device Power Management
645 -------------------------------------------------------------------------- */
648 * acpi_device_sleep_wake - execute _DSW (Device Sleep Wake) or (deprecated in
649 * ACPI 3.0) _PSW (Power State Wake)
650 * @dev: Device to handle.
651 * @enable: 0 - disable, 1 - enable the wake capabilities of the device.
652 * @sleep_state: Target sleep state of the system.
653 * @dev_state: Target power state of the device.
655 * Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
656 * State Wake) for the device, if present. On failure reset the device's
657 * wakeup.flags.valid flag.
660 * 0 if either _DSW or _PSW has been successfully executed
661 * 0 if neither _DSW nor _PSW has been found
662 * -ENODEV if the execution of either _DSW or _PSW has failed
664 int acpi_device_sleep_wake(struct acpi_device *dev,
665 int enable, int sleep_state, int dev_state)
667 union acpi_object in_arg[3];
668 struct acpi_object_list arg_list = { 3, in_arg };
669 acpi_status status = AE_OK;
672 * Try to execute _DSW first.
674 * Three arguments are needed for the _DSW object:
675 * Argument 0: enable/disable the wake capabilities
676 * Argument 1: target system state
677 * Argument 2: target device state
678 * When _DSW object is called to disable the wake capabilities, maybe
679 * the first argument is filled. The values of the other two arguments
682 in_arg[0].type = ACPI_TYPE_INTEGER;
683 in_arg[0].integer.value = enable;
684 in_arg[1].type = ACPI_TYPE_INTEGER;
685 in_arg[1].integer.value = sleep_state;
686 in_arg[2].type = ACPI_TYPE_INTEGER;
687 in_arg[2].integer.value = dev_state;
688 status = acpi_evaluate_object(dev->handle, "_DSW", &arg_list, NULL);
689 if (ACPI_SUCCESS(status)) {
691 } else if (status != AE_NOT_FOUND) {
692 acpi_handle_info(dev->handle, "_DSW execution failed\n");
693 dev->wakeup.flags.valid = 0;
698 status = acpi_execute_simple_method(dev->handle, "_PSW", enable);
699 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
700 acpi_handle_info(dev->handle, "_PSW execution failed\n");
701 dev->wakeup.flags.valid = 0;
709 * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229):
710 * 1. Power on the power resources required for the wakeup device
711 * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
712 * State Wake) for the device, if present
714 int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
718 if (!dev || !dev->wakeup.flags.valid)
721 mutex_lock(&acpi_device_lock);
723 dev_dbg(&dev->dev, "Enabling wakeup power (count %d)\n",
724 dev->wakeup.prepare_count);
726 if (dev->wakeup.prepare_count++)
729 err = acpi_power_on_list(&dev->wakeup.resources);
731 dev_err(&dev->dev, "Cannot turn on wakeup power resources\n");
732 dev->wakeup.flags.valid = 0;
737 * Passing 3 as the third argument below means the device may be
738 * put into arbitrary power state afterward.
740 err = acpi_device_sleep_wake(dev, 1, sleep_state, 3);
742 acpi_power_off_list(&dev->wakeup.resources);
743 dev->wakeup.prepare_count = 0;
747 dev_dbg(&dev->dev, "Wakeup power enabled\n");
750 mutex_unlock(&acpi_device_lock);
755 * Shutdown a wakeup device, counterpart of above method
756 * 1. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
757 * State Wake) for the device, if present
758 * 2. Shutdown down the power resources
760 int acpi_disable_wakeup_device_power(struct acpi_device *dev)
762 struct acpi_power_resource_entry *entry;
765 if (!dev || !dev->wakeup.flags.valid)
768 mutex_lock(&acpi_device_lock);
770 dev_dbg(&dev->dev, "Disabling wakeup power (count %d)\n",
771 dev->wakeup.prepare_count);
773 /* Do nothing if wakeup power has not been enabled for this device. */
774 if (dev->wakeup.prepare_count <= 0)
777 if (--dev->wakeup.prepare_count > 0)
780 err = acpi_device_sleep_wake(dev, 0, 0, 0);
785 * All of the power resources in the list need to be turned off even if
788 list_for_each_entry(entry, &dev->wakeup.resources, node) {
791 ret = acpi_power_off(entry->resource);
796 dev_err(&dev->dev, "Cannot turn off wakeup power resources\n");
797 dev->wakeup.flags.valid = 0;
801 dev_dbg(&dev->dev, "Wakeup power disabled\n");
804 mutex_unlock(&acpi_device_lock);
808 int acpi_power_get_inferred_state(struct acpi_device *device, int *state)
810 u8 list_state = ACPI_POWER_RESOURCE_STATE_OFF;
814 if (!device || !state)
818 * We know a device's inferred power state when all the resources
819 * required for a given D-state are 'on'.
821 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
822 struct list_head *list = &device->power.states[i].resources;
824 if (list_empty(list))
827 result = acpi_power_get_list_state(list, &list_state);
831 if (list_state == ACPI_POWER_RESOURCE_STATE_ON) {
837 *state = device->power.states[ACPI_STATE_D3_COLD].flags.valid ?
838 ACPI_STATE_D3_COLD : ACPI_STATE_D3_HOT;
842 int acpi_power_on_resources(struct acpi_device *device, int state)
844 if (!device || state < ACPI_STATE_D0 || state > ACPI_STATE_D3_HOT)
847 return acpi_power_on_list(&device->power.states[state].resources);
850 int acpi_power_transition(struct acpi_device *device, int state)
854 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD))
857 if (device->power.state == state || !device->flags.power_manageable)
860 if ((device->power.state < ACPI_STATE_D0)
861 || (device->power.state > ACPI_STATE_D3_COLD))
865 * First we reference all power resources required in the target list
866 * (e.g. so the device doesn't lose power while transitioning). Then,
867 * we dereference all power resources used in the current list.
869 if (state < ACPI_STATE_D3_COLD)
870 result = acpi_power_on_list(
871 &device->power.states[state].resources);
873 if (!result && device->power.state < ACPI_STATE_D3_COLD)
875 &device->power.states[device->power.state].resources);
877 /* We shouldn't change the state unless the above operations succeed. */
878 device->power.state = result ? ACPI_STATE_UNKNOWN : state;
883 static void acpi_release_power_resource(struct device *dev)
885 struct acpi_device *device = to_acpi_device(dev);
886 struct acpi_power_resource *resource;
888 resource = container_of(device, struct acpi_power_resource, device);
890 mutex_lock(&power_resource_list_lock);
891 list_del(&resource->list_node);
892 mutex_unlock(&power_resource_list_lock);
894 acpi_free_pnp_ids(&device->pnp);
898 static ssize_t resource_in_use_show(struct device *dev,
899 struct device_attribute *attr,
902 struct acpi_power_resource *resource;
904 resource = to_power_resource(to_acpi_device(dev));
905 return sprintf(buf, "%u\n", !!resource->ref_count);
907 static DEVICE_ATTR_RO(resource_in_use);
909 static void acpi_power_sysfs_remove(struct acpi_device *device)
911 device_remove_file(&device->dev, &dev_attr_resource_in_use);
914 static void acpi_power_add_resource_to_list(struct acpi_power_resource *resource)
916 mutex_lock(&power_resource_list_lock);
918 if (!list_empty(&acpi_power_resource_list)) {
919 struct acpi_power_resource *r;
921 list_for_each_entry(r, &acpi_power_resource_list, list_node)
922 if (r->order > resource->order) {
923 list_add_tail(&resource->list_node, &r->list_node);
927 list_add_tail(&resource->list_node, &acpi_power_resource_list);
930 mutex_unlock(&power_resource_list_lock);
933 struct acpi_device *acpi_add_power_resource(acpi_handle handle)
935 struct acpi_device *device = acpi_fetch_acpi_dev(handle);
936 struct acpi_power_resource *resource;
937 union acpi_object acpi_object;
938 struct acpi_buffer buffer = { sizeof(acpi_object), &acpi_object };
946 resource = kzalloc(sizeof(*resource), GFP_KERNEL);
950 device = &resource->device;
951 acpi_init_device_object(device, handle, ACPI_BUS_TYPE_POWER,
952 acpi_release_power_resource);
953 mutex_init(&resource->resource_lock);
954 INIT_LIST_HEAD(&resource->list_node);
955 INIT_LIST_HEAD(&resource->dependents);
956 strscpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
957 strscpy(acpi_device_class(device), ACPI_POWER_CLASS);
958 device->power.state = ACPI_STATE_UNKNOWN;
959 device->flags.match_driver = true;
961 /* Evaluate the object to get the system level and resource order. */
962 status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
963 if (ACPI_FAILURE(status))
966 resource->system_level = acpi_object.power_resource.system_level;
967 resource->order = acpi_object.power_resource.resource_order;
968 resource->state = ACPI_POWER_RESOURCE_STATE_UNKNOWN;
970 /* Get the initial state or just flip it on if that fails. */
971 if (acpi_power_get_state(resource, &state_dummy))
972 __acpi_power_on(resource);
974 acpi_handle_info(handle, "New power resource\n");
976 result = acpi_tie_acpi_dev(device);
980 result = acpi_device_add(device);
984 if (!device_create_file(&device->dev, &dev_attr_resource_in_use))
985 device->remove = acpi_power_sysfs_remove;
987 acpi_power_add_resource_to_list(resource);
988 acpi_device_add_finalize(device);
992 acpi_release_power_resource(&device->dev);
996 #ifdef CONFIG_ACPI_SLEEP
997 void acpi_resume_power_resources(void)
999 struct acpi_power_resource *resource;
1001 mutex_lock(&power_resource_list_lock);
1003 list_for_each_entry(resource, &acpi_power_resource_list, list_node) {
1007 mutex_lock(&resource->resource_lock);
1009 resource->state = ACPI_POWER_RESOURCE_STATE_UNKNOWN;
1010 result = acpi_power_get_state(resource, &state);
1012 mutex_unlock(&resource->resource_lock);
1016 if (state == ACPI_POWER_RESOURCE_STATE_OFF
1017 && resource->ref_count) {
1018 acpi_handle_debug(resource->device.handle, "Turning ON\n");
1019 __acpi_power_on(resource);
1022 mutex_unlock(&resource->resource_lock);
1025 mutex_unlock(&power_resource_list_lock);
1029 static const struct dmi_system_id dmi_leave_unused_power_resources_on[] = {
1032 * The Toshiba Click Mini has a CPR3 power-resource which must
1033 * be on for the touchscreen to work, but which is not in any
1034 * _PR? lists. The other 2 affected power-resources are no-ops.
1037 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1038 DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
1045 * acpi_turn_off_unused_power_resources - Turn off power resources not in use.
1047 void acpi_turn_off_unused_power_resources(void)
1049 struct acpi_power_resource *resource;
1051 if (unused_power_resources_quirk)
1054 mutex_lock(&power_resource_list_lock);
1056 list_for_each_entry_reverse(resource, &acpi_power_resource_list, list_node) {
1057 mutex_lock(&resource->resource_lock);
1059 if (!resource->ref_count &&
1060 resource->state == ACPI_POWER_RESOURCE_STATE_ON) {
1061 acpi_handle_debug(resource->device.handle, "Turning OFF\n");
1062 __acpi_power_off(resource);
1065 mutex_unlock(&resource->resource_lock);
1068 mutex_unlock(&power_resource_list_lock);
1071 void __init acpi_power_resources_init(void)
1073 unused_power_resources_quirk =
1074 dmi_check_system(dmi_leave_unused_power_resources_on);