2 * wakeup.c - support wakeup devices
3 * Copyright (C) 2004 Li Shaohua <shaohua.li@intel.com>
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>
15 #define _COMPONENT ACPI_SYSTEM_COMPONENT
16 ACPI_MODULE_NAME("wakeup_devices")
18 extern struct list_head acpi_wakeup_device_list;
19 extern spinlock_t acpi_device_lock;
22 * acpi_enable_wakeup_device_prep - prepare wakeup devices
23 * @sleep_state: ACPI state
24 * Enable all wakup devices power if the devices' wakeup level
25 * is higher than requested sleep level
28 void acpi_enable_wakeup_device_prep(u8 sleep_state)
30 struct list_head *node, *next;
32 spin_lock(&acpi_device_lock);
33 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
34 struct acpi_device *dev = container_of(node,
38 if (!dev->wakeup.flags.valid ||
39 !dev->wakeup.state.enabled ||
40 (sleep_state > (u32) dev->wakeup.sleep_state))
43 spin_unlock(&acpi_device_lock);
44 acpi_enable_wakeup_device_power(dev, sleep_state);
45 spin_lock(&acpi_device_lock);
47 spin_unlock(&acpi_device_lock);
51 * acpi_enable_wakeup_device - enable wakeup devices
52 * @sleep_state: ACPI state
53 * Enable all wakup devices's GPE
55 void acpi_enable_wakeup_device(u8 sleep_state)
57 struct list_head *node, *next;
60 * Caution: this routine must be invoked when interrupt is disabled
63 spin_lock(&acpi_device_lock);
64 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
65 struct acpi_device *dev =
66 container_of(node, struct acpi_device, wakeup_list);
68 if (!dev->wakeup.flags.valid)
71 /* If users want to disable run-wake GPE,
72 * we only disable it for wake and leave it for runtime
74 if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared)
75 || sleep_state > (u32) dev->wakeup.sleep_state) {
76 if (dev->wakeup.flags.run_wake) {
77 spin_unlock(&acpi_device_lock);
78 /* set_gpe_type will disable GPE, leave it like that */
79 acpi_set_gpe_type(dev->wakeup.gpe_device,
80 dev->wakeup.gpe_number,
81 ACPI_GPE_TYPE_RUNTIME);
82 spin_lock(&acpi_device_lock);
86 spin_unlock(&acpi_device_lock);
87 if (!dev->wakeup.flags.run_wake)
88 acpi_enable_gpe(dev->wakeup.gpe_device,
89 dev->wakeup.gpe_number);
90 spin_lock(&acpi_device_lock);
92 spin_unlock(&acpi_device_lock);
96 * acpi_disable_wakeup_device - disable devices' wakeup capability
97 * @sleep_state: ACPI state
98 * Disable all wakup devices's GPE and wakeup capability
100 void acpi_disable_wakeup_device(u8 sleep_state)
102 struct list_head *node, *next;
104 spin_lock(&acpi_device_lock);
105 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
106 struct acpi_device *dev =
107 container_of(node, struct acpi_device, wakeup_list);
109 if (!dev->wakeup.flags.valid)
112 if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared)
113 || sleep_state > (u32) dev->wakeup.sleep_state) {
114 if (dev->wakeup.flags.run_wake) {
115 spin_unlock(&acpi_device_lock);
116 acpi_set_gpe_type(dev->wakeup.gpe_device,
117 dev->wakeup.gpe_number,
118 ACPI_GPE_TYPE_WAKE_RUN);
119 /* Re-enable it, since set_gpe_type will disable it */
120 acpi_enable_gpe(dev->wakeup.gpe_device,
121 dev->wakeup.gpe_number);
122 spin_lock(&acpi_device_lock);
127 spin_unlock(&acpi_device_lock);
128 acpi_disable_wakeup_device_power(dev);
129 /* Never disable run-wake GPE */
130 if (!dev->wakeup.flags.run_wake) {
131 acpi_disable_gpe(dev->wakeup.gpe_device,
132 dev->wakeup.gpe_number);
133 acpi_clear_gpe(dev->wakeup.gpe_device,
134 dev->wakeup.gpe_number, ACPI_NOT_ISR);
136 spin_lock(&acpi_device_lock);
138 spin_unlock(&acpi_device_lock);
141 int __init acpi_wakeup_device_init(void)
143 struct list_head *node, *next;
145 spin_lock(&acpi_device_lock);
146 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
147 struct acpi_device *dev = container_of(node,
150 /* In case user doesn't load button driver */
151 if (!dev->wakeup.flags.run_wake || dev->wakeup.state.enabled)
153 spin_unlock(&acpi_device_lock);
154 acpi_set_gpe_type(dev->wakeup.gpe_device,
155 dev->wakeup.gpe_number,
156 ACPI_GPE_TYPE_WAKE_RUN);
157 acpi_enable_gpe(dev->wakeup.gpe_device,
158 dev->wakeup.gpe_number);
159 dev->wakeup.state.enabled = 1;
160 spin_lock(&acpi_device_lock);
162 spin_unlock(&acpi_device_lock);