This source file includes following definitions.
- ACPI_MODULE_NAME
- acpi_disable_wakeup_devices
- acpi_wakeup_device_init
- acpi_register_wakeup_handler
- acpi_unregister_wakeup_handler
- acpi_check_wakeup_handlers
1
2
3
4
5
6
7 #include <linux/init.h>
8 #include <linux/acpi.h>
9 #include <linux/kernel.h>
10 #include <linux/types.h>
11
12 #include "internal.h"
13 #include "sleep.h"
14
15 struct acpi_wakeup_handler {
16 struct list_head list_node;
17 bool (*wakeup)(void *context);
18 void *context;
19 };
20
21 static LIST_HEAD(acpi_wakeup_handler_head);
22 static DEFINE_MUTEX(acpi_wakeup_handler_mutex);
23
24
25
26
27
28
29 #define _COMPONENT ACPI_SYSTEM_COMPONENT
30 ACPI_MODULE_NAME("wakeup_devices")
31
32
33
34
35
36
37
38
39
40 void acpi_enable_wakeup_devices(u8 sleep_state)
41 {
42 struct list_head *node, *next;
43
44 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
45 struct acpi_device *dev =
46 container_of(node, struct acpi_device, wakeup_list);
47
48 if (!dev->wakeup.flags.valid
49 || sleep_state > (u32) dev->wakeup.sleep_state
50 || !(device_may_wakeup(&dev->dev)
51 || dev->wakeup.prepare_count))
52 continue;
53
54 if (device_may_wakeup(&dev->dev))
55 acpi_enable_wakeup_device_power(dev, sleep_state);
56
57
58 acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
59 ACPI_GPE_ENABLE);
60 }
61 }
62
63
64
65
66
67 void acpi_disable_wakeup_devices(u8 sleep_state)
68 {
69 struct list_head *node, *next;
70
71 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
72 struct acpi_device *dev =
73 container_of(node, struct acpi_device, wakeup_list);
74
75 if (!dev->wakeup.flags.valid
76 || sleep_state > (u32) dev->wakeup.sleep_state
77 || !(device_may_wakeup(&dev->dev)
78 || dev->wakeup.prepare_count))
79 continue;
80
81 acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
82 ACPI_GPE_DISABLE);
83
84 if (device_may_wakeup(&dev->dev))
85 acpi_disable_wakeup_device_power(dev);
86 }
87 }
88
89 int __init acpi_wakeup_device_init(void)
90 {
91 struct list_head *node, *next;
92
93 mutex_lock(&acpi_device_lock);
94 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
95 struct acpi_device *dev = container_of(node,
96 struct acpi_device,
97 wakeup_list);
98 if (device_can_wakeup(&dev->dev)) {
99
100 acpi_enable_gpe(dev->wakeup.gpe_device,
101 dev->wakeup.gpe_number);
102 device_set_wakeup_enable(&dev->dev, true);
103 }
104 }
105 mutex_unlock(&acpi_device_lock);
106 return 0;
107 }
108
109
110
111
112
113
114
115
116
117
118
119 int acpi_register_wakeup_handler(int wake_irq, bool (*wakeup)(void *context),
120 void *context)
121 {
122 struct acpi_wakeup_handler *handler;
123
124
125
126
127
128 if (!acpi_sci_irq_valid() || wake_irq != acpi_sci_irq)
129 return 0;
130
131 handler = kmalloc(sizeof(*handler), GFP_KERNEL);
132 if (!handler)
133 return -ENOMEM;
134
135 handler->wakeup = wakeup;
136 handler->context = context;
137
138 mutex_lock(&acpi_wakeup_handler_mutex);
139 list_add(&handler->list_node, &acpi_wakeup_handler_head);
140 mutex_unlock(&acpi_wakeup_handler_mutex);
141
142 return 0;
143 }
144 EXPORT_SYMBOL_GPL(acpi_register_wakeup_handler);
145
146
147
148
149
150
151 void acpi_unregister_wakeup_handler(bool (*wakeup)(void *context),
152 void *context)
153 {
154 struct acpi_wakeup_handler *handler;
155
156 mutex_lock(&acpi_wakeup_handler_mutex);
157 list_for_each_entry(handler, &acpi_wakeup_handler_head, list_node) {
158 if (handler->wakeup == wakeup && handler->context == context) {
159 list_del(&handler->list_node);
160 kfree(handler);
161 break;
162 }
163 }
164 mutex_unlock(&acpi_wakeup_handler_mutex);
165 }
166 EXPORT_SYMBOL_GPL(acpi_unregister_wakeup_handler);
167
168 bool acpi_check_wakeup_handlers(void)
169 {
170 struct acpi_wakeup_handler *handler;
171
172
173 list_for_each_entry(handler, &acpi_wakeup_handler_head, list_node) {
174 if (handler->wakeup(handler->context))
175 return true;
176 }
177
178 return false;
179 }