]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/acpi/wakeup.c
ACPI / Wakeup: Simplify enabling of wakeup devices
[mirror_ubuntu-zesty-kernel.git] / drivers / acpi / wakeup.c
1 /*
2 * wakeup.c - support wakeup devices
3 * Copyright (C) 2004 Li Shaohua <shaohua.li@intel.com>
4 */
5
6 #include <linux/init.h>
7 #include <linux/acpi.h>
8 #include <acpi/acpi_drivers.h>
9 #include <linux/kernel.h>
10 #include <linux/types.h>
11
12 #include "internal.h"
13 #include "sleep.h"
14
15 /*
16 * We didn't lock acpi_device_lock in the file, because it invokes oops in
17 * suspend/resume and isn't really required as this is called in S-state. At
18 * that time, there is no device hotplug
19 **/
20 #define _COMPONENT ACPI_SYSTEM_COMPONENT
21 ACPI_MODULE_NAME("wakeup_devices")
22
23 /**
24 * acpi_enable_wakeup_devices - Enable wake-up device GPEs.
25 * @sleep_state: ACPI system sleep state.
26 *
27 * Enable wakeup device power of devices with the state.enable flag set and set
28 * the wakeup enable mask bits in the GPE registers that correspond to wakeup
29 * devices.
30 */
31 void acpi_enable_wakeup_devices(u8 sleep_state)
32 {
33 struct list_head *node, *next;
34
35 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
36 struct acpi_device *dev =
37 container_of(node, struct acpi_device, wakeup_list);
38
39 if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
40 || sleep_state > (u32) dev->wakeup.sleep_state)
41 continue;
42
43 if (dev->wakeup.state.enabled)
44 acpi_enable_wakeup_device_power(dev, sleep_state);
45
46 /* The wake-up power should have been enabled already. */
47 acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
48 ACPI_GPE_TYPE_WAKE);
49 }
50 }
51
52 /**
53 * acpi_disable_wakeup_devices - Disable devices' wakeup capability.
54 * @sleep_state: ACPI system sleep state.
55 */
56 void acpi_disable_wakeup_devices(u8 sleep_state)
57 {
58 struct list_head *node, *next;
59
60 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
61 struct acpi_device *dev =
62 container_of(node, struct acpi_device, wakeup_list);
63
64 if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
65 || (sleep_state > (u32) dev->wakeup.sleep_state))
66 continue;
67
68 acpi_disable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
69 ACPI_GPE_TYPE_WAKE);
70 acpi_disable_wakeup_device_power(dev);
71 }
72 }
73
74 int __init acpi_wakeup_device_init(void)
75 {
76 struct list_head *node, *next;
77
78 mutex_lock(&acpi_device_lock);
79 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
80 struct acpi_device *dev = container_of(node,
81 struct acpi_device,
82 wakeup_list);
83 if (dev->wakeup.flags.always_enabled)
84 dev->wakeup.state.enabled = 1;
85 }
86 mutex_unlock(&acpi_device_lock);
87 return 0;
88 }