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>
11 #include <acpi/acevents.h>
14 #define _COMPONENT ACPI_SYSTEM_COMPONENT
15 ACPI_MODULE_NAME("wakeup_devices")
17 extern struct list_head acpi_wakeup_device_list;
18 extern spinlock_t acpi_device_lock;
21 * acpi_enable_wakeup_device_prep - prepare wakeup devices
22 * @sleep_state: ACPI state
23 * Enable all wakup devices power if the devices' wakeup level
24 * is higher than requested sleep level
27 void acpi_enable_wakeup_device_prep(u8 sleep_state)
29 struct list_head *node, *next;
31 ACPI_FUNCTION_TRACE("acpi_enable_wakeup_device_prep");
33 spin_lock(&acpi_device_lock);
34 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
35 struct acpi_device *dev = container_of(node,
39 if (!dev->wakeup.flags.valid ||
40 !dev->wakeup.state.enabled ||
41 (sleep_state > (u32) dev->wakeup.sleep_state))
44 spin_unlock(&acpi_device_lock);
45 acpi_enable_wakeup_device_power(dev, sleep_state);
46 spin_lock(&acpi_device_lock);
48 spin_unlock(&acpi_device_lock);
52 * acpi_enable_wakeup_device - enable wakeup devices
53 * @sleep_state: ACPI state
54 * Enable all wakup devices's GPE
56 void acpi_enable_wakeup_device(u8 sleep_state)
58 struct list_head *node, *next;
61 * Caution: this routine must be invoked when interrupt is disabled
64 ACPI_FUNCTION_TRACE("acpi_enable_wakeup_device");
65 spin_lock(&acpi_device_lock);
66 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
67 struct acpi_device *dev =
68 container_of(node, struct acpi_device, wakeup_list);
70 if (!dev->wakeup.flags.valid)
73 /* If users want to disable run-wake GPE,
74 * we only disable it for wake and leave it for runtime
76 if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared)
77 || sleep_state > (u32) dev->wakeup.sleep_state) {
78 if (dev->wakeup.flags.run_wake) {
79 spin_unlock(&acpi_device_lock);
80 /* set_gpe_type will disable GPE, leave it like that */
81 acpi_set_gpe_type(dev->wakeup.gpe_device,
82 dev->wakeup.gpe_number,
83 ACPI_GPE_TYPE_RUNTIME);
84 spin_lock(&acpi_device_lock);
88 spin_unlock(&acpi_device_lock);
89 if (!dev->wakeup.flags.run_wake)
90 acpi_enable_gpe(dev->wakeup.gpe_device,
91 dev->wakeup.gpe_number, ACPI_ISR);
92 spin_lock(&acpi_device_lock);
94 spin_unlock(&acpi_device_lock);
98 * acpi_disable_wakeup_device - disable devices' wakeup capability
99 * @sleep_state: ACPI state
100 * Disable all wakup devices's GPE and wakeup capability
102 void acpi_disable_wakeup_device(u8 sleep_state)
104 struct list_head *node, *next;
106 ACPI_FUNCTION_TRACE("acpi_disable_wakeup_device");
108 spin_lock(&acpi_device_lock);
109 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
110 struct acpi_device *dev =
111 container_of(node, struct acpi_device, wakeup_list);
113 if (!dev->wakeup.flags.valid)
116 if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared)
117 || sleep_state > (u32) dev->wakeup.sleep_state) {
118 if (dev->wakeup.flags.run_wake) {
119 spin_unlock(&acpi_device_lock);
120 acpi_set_gpe_type(dev->wakeup.gpe_device,
121 dev->wakeup.gpe_number,
122 ACPI_GPE_TYPE_WAKE_RUN);
123 /* Re-enable it, since set_gpe_type will disable it */
124 acpi_enable_gpe(dev->wakeup.gpe_device,
125 dev->wakeup.gpe_number, ACPI_NOT_ISR);
126 spin_lock(&acpi_device_lock);
131 spin_unlock(&acpi_device_lock);
132 acpi_disable_wakeup_device_power(dev);
133 /* Never disable run-wake GPE */
134 if (!dev->wakeup.flags.run_wake) {
135 acpi_disable_gpe(dev->wakeup.gpe_device,
136 dev->wakeup.gpe_number, ACPI_NOT_ISR);
137 acpi_clear_gpe(dev->wakeup.gpe_device,
138 dev->wakeup.gpe_number, ACPI_NOT_ISR);
140 spin_lock(&acpi_device_lock);
142 spin_unlock(&acpi_device_lock);
145 static int __init acpi_wakeup_device_init(void)
147 struct list_head *node, *next;
152 spin_lock(&acpi_device_lock);
153 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
154 struct acpi_device *dev = container_of(node,
157 /* In case user doesn't load button driver */
158 if (!dev->wakeup.flags.run_wake || dev->wakeup.state.enabled)
160 spin_unlock(&acpi_device_lock);
161 acpi_set_gpe_type(dev->wakeup.gpe_device,
162 dev->wakeup.gpe_number,
163 ACPI_GPE_TYPE_WAKE_RUN);
164 acpi_enable_gpe(dev->wakeup.gpe_device,
165 dev->wakeup.gpe_number, ACPI_NOT_ISR);
166 dev->wakeup.state.enabled = 1;
167 spin_lock(&acpi_device_lock);
169 spin_unlock(&acpi_device_lock);
173 late_initcall(acpi_wakeup_device_init);