sched: make early bootup sched_clock() use safer
[wrt350n-kernel.git] / drivers / acpi / sleep / wakeup.c
blobed8e41becf0c4997177697157ac8ee8a368d9ab1
1 /*
2 * wakeup.c - support wakeup devices
3 * Copyright (C) 2004 Li Shaohua <shaohua.li@intel.com>
4 */
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>
12 #include "sleep.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;
20 /**
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,
36 struct acpi_device,
37 wakeup_list);
39 if (!dev->wakeup.flags.valid ||
40 !dev->wakeup.state.enabled ||
41 (sleep_state > (u32) dev->wakeup.sleep_state))
42 continue;
44 spin_unlock(&acpi_device_lock);
45 acpi_enable_wakeup_device_power(dev);
46 spin_lock(&acpi_device_lock);
48 spin_unlock(&acpi_device_lock);
51 /**
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;
60 /*
61 * Caution: this routine must be invoked when interrupt is disabled
62 * Refer ACPI2.0: P212
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);
69 if (!dev->wakeup.flags.valid)
70 continue;
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 ||
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);
84 continue;
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, ACPI_ISR);
90 spin_lock(&acpi_device_lock);
92 spin_unlock(&acpi_device_lock);
95 /**
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 ACPI_FUNCTION_TRACE("acpi_disable_wakeup_device");
106 spin_lock(&acpi_device_lock);
107 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
108 struct acpi_device *dev =
109 container_of(node, struct acpi_device, wakeup_list);
111 if (!dev->wakeup.flags.valid)
112 continue;
113 if (!dev->wakeup.state.enabled ||
114 sleep_state > (u32) dev->wakeup.sleep_state) {
115 if (dev->wakeup.flags.run_wake) {
116 spin_unlock(&acpi_device_lock);
117 acpi_set_gpe_type(dev->wakeup.gpe_device,
118 dev->wakeup.gpe_number,
119 ACPI_GPE_TYPE_WAKE_RUN);
120 /* Re-enable it, since set_gpe_type will disable it */
121 acpi_enable_gpe(dev->wakeup.gpe_device,
122 dev->wakeup.gpe_number, ACPI_NOT_ISR);
123 spin_lock(&acpi_device_lock);
125 continue;
128 spin_unlock(&acpi_device_lock);
129 acpi_disable_wakeup_device_power(dev);
130 /* Never disable run-wake GPE */
131 if (!dev->wakeup.flags.run_wake) {
132 acpi_disable_gpe(dev->wakeup.gpe_device,
133 dev->wakeup.gpe_number, ACPI_NOT_ISR);
134 acpi_clear_gpe(dev->wakeup.gpe_device,
135 dev->wakeup.gpe_number, ACPI_NOT_ISR);
137 spin_lock(&acpi_device_lock);
139 spin_unlock(&acpi_device_lock);
142 static int __init acpi_wakeup_device_init(void)
144 struct list_head *node, *next;
146 if (acpi_disabled)
147 return 0;
149 spin_lock(&acpi_device_lock);
150 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
151 struct acpi_device *dev = container_of(node,
152 struct acpi_device,
153 wakeup_list);
154 /* In case user doesn't load button driver */
155 if (!dev->wakeup.flags.run_wake || dev->wakeup.state.enabled)
156 continue;
157 spin_unlock(&acpi_device_lock);
158 acpi_set_gpe_type(dev->wakeup.gpe_device,
159 dev->wakeup.gpe_number,
160 ACPI_GPE_TYPE_WAKE_RUN);
161 acpi_enable_gpe(dev->wakeup.gpe_device,
162 dev->wakeup.gpe_number, ACPI_NOT_ISR);
163 dev->wakeup.state.enabled = 1;
164 spin_lock(&acpi_device_lock);
166 spin_unlock(&acpi_device_lock);
167 return 0;
170 late_initcall(acpi_wakeup_device_init);