diff options
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/Kconfig | 9 | ||||
-rw-r--r-- | drivers/acpi/Makefile | 1 | ||||
-rw-r--r-- | drivers/acpi/bus.c | 22 | ||||
-rw-r--r-- | drivers/acpi/glue.c | 2 | ||||
-rw-r--r-- | drivers/acpi/pci_slot.c | 368 | ||||
-rw-r--r-- | drivers/acpi/power.c | 138 | ||||
-rw-r--r-- | drivers/acpi/scan.c | 42 | ||||
-rw-r--r-- | drivers/acpi/sleep/main.c | 301 | ||||
-rw-r--r-- | drivers/acpi/sleep/wakeup.c | 13 |
9 files changed, 706 insertions, 190 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index bba867391a85..735f5ea17473 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig | |||
@@ -336,6 +336,15 @@ config ACPI_EC | |||
336 | the battery and thermal drivers. If you are compiling for a | 336 | the battery and thermal drivers. If you are compiling for a |
337 | mobile system, say Y. | 337 | mobile system, say Y. |
338 | 338 | ||
339 | config ACPI_PCI_SLOT | ||
340 | tristate "PCI slot detection driver" | ||
341 | default n | ||
342 | help | ||
343 | This driver will attempt to discover all PCI slots in your system, | ||
344 | and creates entries in /sys/bus/pci/slots/. This feature can | ||
345 | help you correlate PCI bus addresses with the physical geography | ||
346 | of your slots. If you are unsure, say N. | ||
347 | |||
339 | config ACPI_POWER | 348 | config ACPI_POWER |
340 | bool | 349 | bool |
341 | default y | 350 | default y |
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 4efbe598c817..52a4cd4b81d0 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile | |||
@@ -48,6 +48,7 @@ obj-$(CONFIG_ACPI_DOCK) += dock.o | |||
48 | obj-$(CONFIG_ACPI_BAY) += bay.o | 48 | obj-$(CONFIG_ACPI_BAY) += bay.o |
49 | obj-$(CONFIG_ACPI_VIDEO) += video.o | 49 | obj-$(CONFIG_ACPI_VIDEO) += video.o |
50 | obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o | 50 | obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o |
51 | obj-$(CONFIG_ACPI_PCI_SLOT) += pci_slot.o | ||
51 | obj-$(CONFIG_ACPI_POWER) += power.o | 52 | obj-$(CONFIG_ACPI_POWER) += power.o |
52 | obj-$(CONFIG_ACPI_PROCESSOR) += processor.o | 53 | obj-$(CONFIG_ACPI_PROCESSOR) += processor.o |
53 | obj-$(CONFIG_ACPI_CONTAINER) += container.o | 54 | obj-$(CONFIG_ACPI_CONTAINER) += container.o |
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index afb34387d5f2..ccae305ee55d 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c | |||
@@ -295,6 +295,28 @@ int acpi_bus_set_power(acpi_handle handle, int state) | |||
295 | 295 | ||
296 | EXPORT_SYMBOL(acpi_bus_set_power); | 296 | EXPORT_SYMBOL(acpi_bus_set_power); |
297 | 297 | ||
298 | bool acpi_bus_power_manageable(acpi_handle handle) | ||
299 | { | ||
300 | struct acpi_device *device; | ||
301 | int result; | ||
302 | |||
303 | result = acpi_bus_get_device(handle, &device); | ||
304 | return result ? false : device->flags.power_manageable; | ||
305 | } | ||
306 | |||
307 | EXPORT_SYMBOL(acpi_bus_power_manageable); | ||
308 | |||
309 | bool acpi_bus_can_wakeup(acpi_handle handle) | ||
310 | { | ||
311 | struct acpi_device *device; | ||
312 | int result; | ||
313 | |||
314 | result = acpi_bus_get_device(handle, &device); | ||
315 | return result ? false : device->wakeup.flags.valid; | ||
316 | } | ||
317 | |||
318 | EXPORT_SYMBOL(acpi_bus_can_wakeup); | ||
319 | |||
298 | /* -------------------------------------------------------------------------- | 320 | /* -------------------------------------------------------------------------- |
299 | Event Management | 321 | Event Management |
300 | -------------------------------------------------------------------------- */ | 322 | -------------------------------------------------------------------------- */ |
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c index 6d18ca34b6aa..0f2dd81736bd 100644 --- a/drivers/acpi/glue.c +++ b/drivers/acpi/glue.c | |||
@@ -166,6 +166,8 @@ static int acpi_bind_one(struct device *dev, acpi_handle handle) | |||
166 | "firmware_node"); | 166 | "firmware_node"); |
167 | ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj, | 167 | ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj, |
168 | "physical_node"); | 168 | "physical_node"); |
169 | if (acpi_dev->wakeup.flags.valid) | ||
170 | device_set_wakeup_capable(dev, true); | ||
169 | } | 171 | } |
170 | 172 | ||
171 | return 0; | 173 | return 0; |
diff --git a/drivers/acpi/pci_slot.c b/drivers/acpi/pci_slot.c new file mode 100644 index 000000000000..b9ab030a52d5 --- /dev/null +++ b/drivers/acpi/pci_slot.c | |||
@@ -0,0 +1,368 @@ | |||
1 | /* | ||
2 | * pci_slot.c - ACPI PCI Slot Driver | ||
3 | * | ||
4 | * The code here is heavily leveraged from the acpiphp module. | ||
5 | * Thanks to Matthew Wilcox <matthew@wil.cx> for much guidance. | ||
6 | * Thanks to Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> for code | ||
7 | * review and fixes. | ||
8 | * | ||
9 | * Copyright (C) 2007 Alex Chiang <achiang@hp.com> | ||
10 | * Copyright (C) 2007 Hewlett-Packard Development Company, L.P. | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify it | ||
13 | * under the terms and conditions of the GNU General Public License, | ||
14 | * version 2, as published by the Free Software Foundation. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, but | ||
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License along | ||
22 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
23 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
24 | */ | ||
25 | |||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <linux/types.h> | ||
30 | #include <linux/pci.h> | ||
31 | #include <linux/acpi.h> | ||
32 | #include <acpi/acpi_bus.h> | ||
33 | #include <acpi/acpi_drivers.h> | ||
34 | |||
35 | static int debug; | ||
36 | static int check_sta_before_sun; | ||
37 | |||
38 | #define DRIVER_VERSION "0.1" | ||
39 | #define DRIVER_AUTHOR "Alex Chiang <achiang@hp.com>" | ||
40 | #define DRIVER_DESC "ACPI PCI Slot Detection Driver" | ||
41 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
42 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
43 | MODULE_LICENSE("GPL"); | ||
44 | MODULE_PARM_DESC(debug, "Debugging mode enabled or not"); | ||
45 | module_param(debug, bool, 0644); | ||
46 | |||
47 | #define _COMPONENT ACPI_PCI_COMPONENT | ||
48 | ACPI_MODULE_NAME("pci_slot"); | ||
49 | |||
50 | #define MY_NAME "pci_slot" | ||
51 | #define err(format, arg...) printk(KERN_ERR "%s: " format , MY_NAME , ## arg) | ||
52 | #define info(format, arg...) printk(KERN_INFO "%s: " format , MY_NAME , ## arg) | ||
53 | #define dbg(format, arg...) \ | ||
54 | do { \ | ||
55 | if (debug) \ | ||
56 | printk(KERN_DEBUG "%s: " format, \ | ||
57 | MY_NAME , ## arg); \ | ||
58 | } while (0) | ||
59 | |||
60 | #define SLOT_NAME_SIZE 20 /* Inspired by #define in acpiphp.h */ | ||
61 | |||
62 | struct acpi_pci_slot { | ||
63 | acpi_handle root_handle; /* handle of the root bridge */ | ||
64 | struct pci_slot *pci_slot; /* corresponding pci_slot */ | ||
65 | struct list_head list; /* node in the list of slots */ | ||
66 | }; | ||
67 | |||
68 | static int acpi_pci_slot_add(acpi_handle handle); | ||
69 | static void acpi_pci_slot_remove(acpi_handle handle); | ||
70 | |||
71 | static LIST_HEAD(slot_list); | ||
72 | static DEFINE_MUTEX(slot_list_lock); | ||
73 | static struct acpi_pci_driver acpi_pci_slot_driver = { | ||
74 | .add = acpi_pci_slot_add, | ||
75 | .remove = acpi_pci_slot_remove, | ||
76 | }; | ||
77 | |||
78 | static int | ||
79 | check_slot(acpi_handle handle, int *device, unsigned long *sun) | ||
80 | { | ||
81 | int retval = 0; | ||
82 | unsigned long adr, sta; | ||
83 | acpi_status status; | ||
84 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | ||
85 | |||
86 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); | ||
87 | dbg("Checking slot on path: %s\n", (char *)buffer.pointer); | ||
88 | |||
89 | if (check_sta_before_sun) { | ||
90 | /* If SxFy doesn't have _STA, we just assume it's there */ | ||
91 | status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); | ||
92 | if (ACPI_SUCCESS(status) && !(sta & ACPI_STA_DEVICE_PRESENT)) { | ||
93 | retval = -1; | ||
94 | goto out; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr); | ||
99 | if (ACPI_FAILURE(status)) { | ||
100 | dbg("_ADR returned %d on %s\n", status, (char *)buffer.pointer); | ||
101 | retval = -1; | ||
102 | goto out; | ||
103 | } | ||
104 | |||
105 | *device = (adr >> 16) & 0xffff; | ||
106 | |||
107 | /* No _SUN == not a slot == bail */ | ||
108 | status = acpi_evaluate_integer(handle, "_SUN", NULL, sun); | ||
109 | if (ACPI_FAILURE(status)) { | ||
110 | dbg("_SUN returned %d on %s\n", status, (char *)buffer.pointer); | ||
111 | retval = -1; | ||
112 | goto out; | ||
113 | } | ||
114 | |||
115 | out: | ||
116 | kfree(buffer.pointer); | ||
117 | return retval; | ||
118 | } | ||
119 | |||
120 | struct callback_args { | ||
121 | acpi_walk_callback user_function; /* only for walk_p2p_bridge */ | ||
122 | struct pci_bus *pci_bus; | ||
123 | acpi_handle root_handle; | ||
124 | }; | ||
125 | |||
126 | /* | ||
127 | * register_slot | ||
128 | * | ||
129 | * Called once for each SxFy object in the namespace. Don't worry about | ||
130 | * calling pci_create_slot multiple times for the same pci_bus:device, | ||
131 | * since each subsequent call simply bumps the refcount on the pci_slot. | ||
132 | * | ||
133 | * The number of calls to pci_destroy_slot from unregister_slot is | ||
134 | * symmetrical. | ||
135 | */ | ||
136 | static acpi_status | ||
137 | register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) | ||
138 | { | ||
139 | int device; | ||
140 | unsigned long sun; | ||
141 | char name[SLOT_NAME_SIZE]; | ||
142 | struct acpi_pci_slot *slot; | ||
143 | struct pci_slot *pci_slot; | ||
144 | struct callback_args *parent_context = context; | ||
145 | struct pci_bus *pci_bus = parent_context->pci_bus; | ||
146 | |||
147 | if (check_slot(handle, &device, &sun)) | ||
148 | return AE_OK; | ||
149 | |||
150 | slot = kmalloc(sizeof(*slot), GFP_KERNEL); | ||
151 | if (!slot) { | ||
152 | err("%s: cannot allocate memory\n", __func__); | ||
153 | return AE_OK; | ||
154 | } | ||
155 | |||
156 | snprintf(name, sizeof(name), "%u", (u32)sun); | ||
157 | pci_slot = pci_create_slot(pci_bus, device, name); | ||
158 | if (IS_ERR(pci_slot)) { | ||
159 | err("pci_create_slot returned %ld\n", PTR_ERR(pci_slot)); | ||
160 | kfree(slot); | ||
161 | } | ||
162 | |||
163 | slot->root_handle = parent_context->root_handle; | ||
164 | slot->pci_slot = pci_slot; | ||
165 | INIT_LIST_HEAD(&slot->list); | ||
166 | mutex_lock(&slot_list_lock); | ||
167 | list_add(&slot->list, &slot_list); | ||
168 | mutex_unlock(&slot_list_lock); | ||
169 | |||
170 | dbg("pci_slot: %p, pci_bus: %x, device: %d, name: %s\n", | ||
171 | pci_slot, pci_bus->number, device, name); | ||
172 | |||
173 | return AE_OK; | ||
174 | } | ||
175 | |||
176 | /* | ||
177 | * walk_p2p_bridge - discover and walk p2p bridges | ||
178 | * @handle: points to an acpi_pci_root | ||
179 | * @context: p2p_bridge_context pointer | ||
180 | * | ||
181 | * Note that when we call ourselves recursively, we pass a different | ||
182 | * value of pci_bus in the child_context. | ||
183 | */ | ||
184 | static acpi_status | ||
185 | walk_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv) | ||
186 | { | ||
187 | int device, function; | ||
188 | unsigned long adr; | ||
189 | acpi_status status; | ||
190 | acpi_handle dummy_handle; | ||
191 | acpi_walk_callback user_function; | ||
192 | |||
193 | struct pci_dev *dev; | ||
194 | struct pci_bus *pci_bus; | ||
195 | struct callback_args child_context; | ||
196 | struct callback_args *parent_context = context; | ||
197 | |||
198 | pci_bus = parent_context->pci_bus; | ||
199 | user_function = parent_context->user_function; | ||
200 | |||
201 | status = acpi_get_handle(handle, "_ADR", &dummy_handle); | ||
202 | if (ACPI_FAILURE(status)) | ||
203 | return AE_OK; | ||
204 | |||
205 | status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr); | ||
206 | if (ACPI_FAILURE(status)) | ||
207 | return AE_OK; | ||
208 | |||
209 | device = (adr >> 16) & 0xffff; | ||
210 | function = adr & 0xffff; | ||
211 | |||
212 | dev = pci_get_slot(pci_bus, PCI_DEVFN(device, function)); | ||
213 | if (!dev || !dev->subordinate) | ||
214 | goto out; | ||
215 | |||
216 | child_context.pci_bus = dev->subordinate; | ||
217 | child_context.user_function = user_function; | ||
218 | child_context.root_handle = parent_context->root_handle; | ||
219 | |||
220 | dbg("p2p bridge walk, pci_bus = %x\n", dev->subordinate->number); | ||
221 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, | ||
222 | user_function, &child_context, NULL); | ||
223 | if (ACPI_FAILURE(status)) | ||
224 | goto out; | ||
225 | |||
226 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, | ||
227 | walk_p2p_bridge, &child_context, NULL); | ||
228 | out: | ||
229 | pci_dev_put(dev); | ||
230 | return AE_OK; | ||
231 | } | ||
232 | |||
233 | /* | ||
234 | * walk_root_bridge - generic root bridge walker | ||
235 | * @handle: points to an acpi_pci_root | ||
236 | * @user_function: user callback for slot objects | ||
237 | * | ||
238 | * Call user_function for all objects underneath this root bridge. | ||
239 | * Walk p2p bridges underneath us and call user_function on those too. | ||
240 | */ | ||
241 | static int | ||
242 | walk_root_bridge(acpi_handle handle, acpi_walk_callback user_function) | ||
243 | { | ||
244 | int seg, bus; | ||
245 | unsigned long tmp; | ||
246 | acpi_status status; | ||
247 | acpi_handle dummy_handle; | ||
248 | struct pci_bus *pci_bus; | ||
249 | struct callback_args context; | ||
250 | |||
251 | /* If the bridge doesn't have _STA, we assume it is always there */ | ||
252 | status = acpi_get_handle(handle, "_STA", &dummy_handle); | ||
253 | if (ACPI_SUCCESS(status)) { | ||
254 | status = acpi_evaluate_integer(handle, "_STA", NULL, &tmp); | ||
255 | if (ACPI_FAILURE(status)) { | ||
256 | info("%s: _STA evaluation failure\n", __func__); | ||
257 | return 0; | ||
258 | } | ||
259 | if ((tmp & ACPI_STA_DEVICE_FUNCTIONING) == 0) | ||
260 | /* don't register this object */ | ||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | status = acpi_evaluate_integer(handle, "_SEG", NULL, &tmp); | ||
265 | seg = ACPI_SUCCESS(status) ? tmp : 0; | ||
266 | |||
267 | status = acpi_evaluate_integer(handle, "_BBN", NULL, &tmp); | ||
268 | bus = ACPI_SUCCESS(status) ? tmp : 0; | ||
269 | |||
270 | pci_bus = pci_find_bus(seg, bus); | ||
271 | if (!pci_bus) | ||
272 | return 0; | ||
273 | |||
274 | context.pci_bus = pci_bus; | ||
275 | context.user_function = user_function; | ||
276 | context.root_handle = handle; | ||
277 | |||
278 | dbg("root bridge walk, pci_bus = %x\n", pci_bus->number); | ||
279 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, | ||
280 | user_function, &context, NULL); | ||
281 | if (ACPI_FAILURE(status)) | ||
282 | return status; | ||
283 | |||
284 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, | ||
285 | walk_p2p_bridge, &context, NULL); | ||
286 | if (ACPI_FAILURE(status)) | ||
287 | err("%s: walk_p2p_bridge failure - %d\n", __func__, status); | ||
288 | |||
289 | return status; | ||
290 | } | ||
291 | |||
292 | /* | ||
293 | * acpi_pci_slot_add | ||
294 | * @handle: points to an acpi_pci_root | ||
295 | */ | ||
296 | static int | ||
297 | acpi_pci_slot_add(acpi_handle handle) | ||
298 | { | ||
299 | acpi_status status; | ||
300 | |||
301 | status = walk_root_bridge(handle, register_slot); | ||
302 | if (ACPI_FAILURE(status)) | ||
303 | err("%s: register_slot failure - %d\n", __func__, status); | ||
304 | |||
305 | return status; | ||
306 | } | ||
307 | |||
308 | /* | ||
309 | * acpi_pci_slot_remove | ||
310 | * @handle: points to an acpi_pci_root | ||
311 | */ | ||
312 | static void | ||
313 | acpi_pci_slot_remove(acpi_handle handle) | ||
314 | { | ||
315 | struct acpi_pci_slot *slot, *tmp; | ||
316 | |||
317 | mutex_lock(&slot_list_lock); | ||
318 | list_for_each_entry_safe(slot, tmp, &slot_list, list) { | ||
319 | if (slot->root_handle == handle) { | ||
320 | list_del(&slot->list); | ||
321 | pci_destroy_slot(slot->pci_slot); | ||
322 | kfree(slot); | ||
323 | } | ||
324 | } | ||
325 | mutex_unlock(&slot_list_lock); | ||
326 | } | ||
327 | |||
328 | static int do_sta_before_sun(const struct dmi_system_id *d) | ||
329 | { | ||
330 | info("%s detected: will evaluate _STA before calling _SUN\n", d->ident); | ||
331 | check_sta_before_sun = 1; | ||
332 | return 0; | ||
333 | } | ||
334 | |||
335 | static struct dmi_system_id acpi_pci_slot_dmi_table[] __initdata = { | ||
336 | /* | ||
337 | * Fujitsu Primequest machines will return 1023 to indicate an | ||
338 | * error if the _SUN method is evaluated on SxFy objects that | ||
339 | * are not present (as indicated by _STA), so for those machines, | ||
340 | * we want to check _STA before evaluating _SUN. | ||
341 | */ | ||
342 | { | ||
343 | .callback = do_sta_before_sun, | ||
344 | .ident = "Fujitsu PRIMEQUEST", | ||
345 | .matches = { | ||
346 | DMI_MATCH(DMI_BIOS_VENDOR, "FUJITSU LIMITED"), | ||
347 | DMI_MATCH(DMI_BIOS_VERSION, "PRIMEQUEST"), | ||
348 | }, | ||
349 | }, | ||
350 | {} | ||
351 | }; | ||
352 | |||
353 | static int __init | ||
354 | acpi_pci_slot_init(void) | ||
355 | { | ||
356 | dmi_check_system(acpi_pci_slot_dmi_table); | ||
357 | acpi_pci_register_driver(&acpi_pci_slot_driver); | ||
358 | return 0; | ||
359 | } | ||
360 | |||
361 | static void __exit | ||
362 | acpi_pci_slot_exit(void) | ||
363 | { | ||
364 | acpi_pci_unregister_driver(&acpi_pci_slot_driver); | ||
365 | } | ||
366 | |||
367 | module_init(acpi_pci_slot_init); | ||
368 | module_exit(acpi_pci_slot_exit); | ||
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c index 81e4f081a4ae..4ab21cb1c8c7 100644 --- a/drivers/acpi/power.c +++ b/drivers/acpi/power.c | |||
@@ -292,69 +292,135 @@ static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev) | |||
292 | return 0; | 292 | return 0; |
293 | } | 293 | } |
294 | 294 | ||
295 | /** | ||
296 | * acpi_device_sleep_wake - execute _DSW (Device Sleep Wake) or (deprecated in | ||
297 | * ACPI 3.0) _PSW (Power State Wake) | ||
298 | * @dev: Device to handle. | ||
299 | * @enable: 0 - disable, 1 - enable the wake capabilities of the device. | ||
300 | * @sleep_state: Target sleep state of the system. | ||
301 | * @dev_state: Target power state of the device. | ||
302 | * | ||
303 | * Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power | ||
304 | * State Wake) for the device, if present. On failure reset the device's | ||
305 | * wakeup.flags.valid flag. | ||
306 | * | ||
307 | * RETURN VALUE: | ||
308 | * 0 if either _DSW or _PSW has been successfully executed | ||
309 | * 0 if neither _DSW nor _PSW has been found | ||
310 | * -ENODEV if the execution of either _DSW or _PSW has failed | ||
311 | */ | ||
312 | int acpi_device_sleep_wake(struct acpi_device *dev, | ||
313 | int enable, int sleep_state, int dev_state) | ||
314 | { | ||
315 | union acpi_object in_arg[3]; | ||
316 | struct acpi_object_list arg_list = { 3, in_arg }; | ||
317 | acpi_status status = AE_OK; | ||
318 | |||
319 | /* | ||
320 | * Try to execute _DSW first. | ||
321 | * | ||
322 | * Three agruments are needed for the _DSW object: | ||
323 | * Argument 0: enable/disable the wake capabilities | ||
324 | * Argument 1: target system state | ||
325 | * Argument 2: target device state | ||
326 | * When _DSW object is called to disable the wake capabilities, maybe | ||
327 | * the first argument is filled. The values of the other two agruments | ||
328 | * are meaningless. | ||
329 | */ | ||
330 | in_arg[0].type = ACPI_TYPE_INTEGER; | ||
331 | in_arg[0].integer.value = enable; | ||
332 | in_arg[1].type = ACPI_TYPE_INTEGER; | ||
333 | in_arg[1].integer.value = sleep_state; | ||
334 | in_arg[2].type = ACPI_TYPE_INTEGER; | ||
335 | in_arg[2].integer.value = dev_state; | ||
336 | status = acpi_evaluate_object(dev->handle, "_DSW", &arg_list, NULL); | ||
337 | if (ACPI_SUCCESS(status)) { | ||
338 | return 0; | ||
339 | } else if (status != AE_NOT_FOUND) { | ||
340 | printk(KERN_ERR PREFIX "_DSW execution failed\n"); | ||
341 | dev->wakeup.flags.valid = 0; | ||
342 | return -ENODEV; | ||
343 | } | ||
344 | |||
345 | /* Execute _PSW */ | ||
346 | arg_list.count = 1; | ||
347 | in_arg[0].integer.value = enable; | ||
348 | status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); | ||
349 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { | ||
350 | printk(KERN_ERR PREFIX "_PSW execution failed\n"); | ||
351 | dev->wakeup.flags.valid = 0; | ||
352 | return -ENODEV; | ||
353 | } | ||
354 | |||
355 | return 0; | ||
356 | } | ||
357 | |||
295 | /* | 358 | /* |
296 | * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229): | 359 | * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229): |
297 | * 1. Power on the power resources required for the wakeup device | 360 | * 1. Power on the power resources required for the wakeup device |
298 | * 2. Enable _PSW (power state wake) for the device if present | 361 | * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power |
362 | * State Wake) for the device, if present | ||
299 | */ | 363 | */ |
300 | int acpi_enable_wakeup_device_power(struct acpi_device *dev) | 364 | int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state) |
301 | { | 365 | { |
302 | union acpi_object arg = { ACPI_TYPE_INTEGER }; | 366 | int i, err; |
303 | struct acpi_object_list arg_list = { 1, &arg }; | ||
304 | acpi_status status = AE_OK; | ||
305 | int i; | ||
306 | int ret = 0; | ||
307 | 367 | ||
308 | if (!dev || !dev->wakeup.flags.valid) | 368 | if (!dev || !dev->wakeup.flags.valid) |
309 | return -1; | 369 | return -EINVAL; |
370 | |||
371 | /* | ||
372 | * Do not execute the code below twice in a row without calling | ||
373 | * acpi_disable_wakeup_device_power() in between for the same device | ||
374 | */ | ||
375 | if (dev->wakeup.flags.prepared) | ||
376 | return 0; | ||
310 | 377 | ||
311 | arg.integer.value = 1; | ||
312 | /* Open power resource */ | 378 | /* Open power resource */ |
313 | for (i = 0; i < dev->wakeup.resources.count; i++) { | 379 | for (i = 0; i < dev->wakeup.resources.count; i++) { |
314 | ret = acpi_power_on(dev->wakeup.resources.handles[i], dev); | 380 | int ret = acpi_power_on(dev->wakeup.resources.handles[i], dev); |
315 | if (ret) { | 381 | if (ret) { |
316 | printk(KERN_ERR PREFIX "Transition power state\n"); | 382 | printk(KERN_ERR PREFIX "Transition power state\n"); |
317 | dev->wakeup.flags.valid = 0; | 383 | dev->wakeup.flags.valid = 0; |
318 | return -1; | 384 | return -ENODEV; |
319 | } | 385 | } |
320 | } | 386 | } |
321 | 387 | ||
322 | /* Execute PSW */ | 388 | /* |
323 | status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); | 389 | * Passing 3 as the third argument below means the device may be placed |
324 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { | 390 | * in arbitrary power state afterwards. |
325 | printk(KERN_ERR PREFIX "Evaluate _PSW\n"); | 391 | */ |
326 | dev->wakeup.flags.valid = 0; | 392 | err = acpi_device_sleep_wake(dev, 1, sleep_state, 3); |
327 | ret = -1; | 393 | if (!err) |
328 | } | 394 | dev->wakeup.flags.prepared = 1; |
329 | 395 | ||
330 | return ret; | 396 | return err; |
331 | } | 397 | } |
332 | 398 | ||
333 | /* | 399 | /* |
334 | * Shutdown a wakeup device, counterpart of above method | 400 | * Shutdown a wakeup device, counterpart of above method |
335 | * 1. Disable _PSW (power state wake) | 401 | * 1. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power |
402 | * State Wake) for the device, if present | ||
336 | * 2. Shutdown down the power resources | 403 | * 2. Shutdown down the power resources |
337 | */ | 404 | */ |
338 | int acpi_disable_wakeup_device_power(struct acpi_device *dev) | 405 | int acpi_disable_wakeup_device_power(struct acpi_device *dev) |
339 | { | 406 | { |
340 | union acpi_object arg = { ACPI_TYPE_INTEGER }; | 407 | int i, ret; |
341 | struct acpi_object_list arg_list = { 1, &arg }; | ||
342 | acpi_status status = AE_OK; | ||
343 | int i; | ||
344 | int ret = 0; | ||
345 | |||
346 | 408 | ||
347 | if (!dev || !dev->wakeup.flags.valid) | 409 | if (!dev || !dev->wakeup.flags.valid) |
348 | return -1; | 410 | return -EINVAL; |
349 | 411 | ||
350 | arg.integer.value = 0; | 412 | /* |
351 | /* Execute PSW */ | 413 | * Do not execute the code below twice in a row without calling |
352 | status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); | 414 | * acpi_enable_wakeup_device_power() in between for the same device |
353 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { | 415 | */ |
354 | printk(KERN_ERR PREFIX "Evaluate _PSW\n"); | 416 | if (!dev->wakeup.flags.prepared) |
355 | dev->wakeup.flags.valid = 0; | 417 | return 0; |
356 | return -1; | 418 | |
357 | } | 419 | dev->wakeup.flags.prepared = 0; |
420 | |||
421 | ret = acpi_device_sleep_wake(dev, 0, 0, 0); | ||
422 | if (ret) | ||
423 | return ret; | ||
358 | 424 | ||
359 | /* Close power resource */ | 425 | /* Close power resource */ |
360 | for (i = 0; i < dev->wakeup.resources.count; i++) { | 426 | for (i = 0; i < dev->wakeup.resources.count; i++) { |
@@ -362,7 +428,7 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev) | |||
362 | if (ret) { | 428 | if (ret) { |
363 | printk(KERN_ERR PREFIX "Transition power state\n"); | 429 | printk(KERN_ERR PREFIX "Transition power state\n"); |
364 | dev->wakeup.flags.valid = 0; | 430 | dev->wakeup.flags.valid = 0; |
365 | return -1; | 431 | return -ENODEV; |
366 | } | 432 | } |
367 | } | 433 | } |
368 | 434 | ||
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 5b049cd79553..f3132aa47a69 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
@@ -703,9 +703,7 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device) | |||
703 | acpi_status status = 0; | 703 | acpi_status status = 0; |
704 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | 704 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
705 | union acpi_object *package = NULL; | 705 | union acpi_object *package = NULL; |
706 | union acpi_object in_arg[3]; | 706 | int psw_error; |
707 | struct acpi_object_list arg_list = { 3, in_arg }; | ||
708 | acpi_status psw_status = AE_OK; | ||
709 | 707 | ||
710 | struct acpi_device_id button_device_ids[] = { | 708 | struct acpi_device_id button_device_ids[] = { |
711 | {"PNP0C0D", 0}, | 709 | {"PNP0C0D", 0}, |
@@ -737,39 +735,11 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device) | |||
737 | * So it is necessary to call _DSW object first. Only when it is not | 735 | * So it is necessary to call _DSW object first. Only when it is not |
738 | * present will the _PSW object used. | 736 | * present will the _PSW object used. |
739 | */ | 737 | */ |
740 | /* | 738 | psw_error = acpi_device_sleep_wake(device, 0, 0, 0); |
741 | * Three agruments are needed for the _DSW object. | 739 | if (psw_error) |
742 | * Argument 0: enable/disable the wake capabilities | 740 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
743 | * When _DSW object is called to disable the wake capabilities, maybe | 741 | "error in _DSW or _PSW evaluation\n")); |
744 | * the first argument is filled. The value of the other two agruments | 742 | |
745 | * is meaningless. | ||
746 | */ | ||
747 | in_arg[0].type = ACPI_TYPE_INTEGER; | ||
748 | in_arg[0].integer.value = 0; | ||
749 | in_arg[1].type = ACPI_TYPE_INTEGER; | ||
750 | in_arg[1].integer.value = 0; | ||
751 | in_arg[2].type = ACPI_TYPE_INTEGER; | ||
752 | in_arg[2].integer.value = 0; | ||
753 | psw_status = acpi_evaluate_object(device->handle, "_DSW", | ||
754 | &arg_list, NULL); | ||
755 | if (ACPI_FAILURE(psw_status) && (psw_status != AE_NOT_FOUND)) | ||
756 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "error in evaluate _DSW\n")); | ||
757 | /* | ||
758 | * When the _DSW object is not present, OSPM will call _PSW object. | ||
759 | */ | ||
760 | if (psw_status == AE_NOT_FOUND) { | ||
761 | /* | ||
762 | * Only one agruments is required for the _PSW object. | ||
763 | * agrument 0: enable/disable the wake capabilities | ||
764 | */ | ||
765 | arg_list.count = 1; | ||
766 | in_arg[0].integer.value = 0; | ||
767 | psw_status = acpi_evaluate_object(device->handle, "_PSW", | ||
768 | &arg_list, NULL); | ||
769 | if (ACPI_FAILURE(psw_status) && (psw_status != AE_NOT_FOUND)) | ||
770 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "error in " | ||
771 | "evaluate _PSW\n")); | ||
772 | } | ||
773 | /* Power button, Lid switch always enable wakeup */ | 743 | /* Power button, Lid switch always enable wakeup */ |
774 | if (!acpi_match_device_ids(device, button_device_ids)) | 744 | if (!acpi_match_device_ids(device, button_device_ids)) |
775 | device->wakeup.flags.run_wake = 1; | 745 | device->wakeup.flags.run_wake = 1; |
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c index 244e352f7661..0489a7d1d42c 100644 --- a/drivers/acpi/sleep/main.c +++ b/drivers/acpi/sleep/main.c | |||
@@ -24,10 +24,6 @@ | |||
24 | 24 | ||
25 | u8 sleep_states[ACPI_S_STATE_COUNT]; | 25 | u8 sleep_states[ACPI_S_STATE_COUNT]; |
26 | 26 | ||
27 | #ifdef CONFIG_PM_SLEEP | ||
28 | static u32 acpi_target_sleep_state = ACPI_STATE_S0; | ||
29 | #endif | ||
30 | |||
31 | static int acpi_sleep_prepare(u32 acpi_state) | 27 | static int acpi_sleep_prepare(u32 acpi_state) |
32 | { | 28 | { |
33 | #ifdef CONFIG_ACPI_SLEEP | 29 | #ifdef CONFIG_ACPI_SLEEP |
@@ -49,9 +45,96 @@ static int acpi_sleep_prepare(u32 acpi_state) | |||
49 | return 0; | 45 | return 0; |
50 | } | 46 | } |
51 | 47 | ||
52 | #ifdef CONFIG_SUSPEND | 48 | #ifdef CONFIG_PM_SLEEP |
53 | static struct platform_suspend_ops acpi_suspend_ops; | 49 | static u32 acpi_target_sleep_state = ACPI_STATE_S0; |
50 | |||
51 | /* | ||
52 | * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the | ||
53 | * user to request that behavior by using the 'acpi_old_suspend_ordering' | ||
54 | * kernel command line option that causes the following variable to be set. | ||
55 | */ | ||
56 | static bool old_suspend_ordering; | ||
57 | |||
58 | void __init acpi_old_suspend_ordering(void) | ||
59 | { | ||
60 | old_suspend_ordering = true; | ||
61 | } | ||
62 | |||
63 | /** | ||
64 | * acpi_pm_disable_gpes - Disable the GPEs. | ||
65 | */ | ||
66 | static int acpi_pm_disable_gpes(void) | ||
67 | { | ||
68 | acpi_hw_disable_all_gpes(); | ||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | /** | ||
73 | * __acpi_pm_prepare - Prepare the platform to enter the target state. | ||
74 | * | ||
75 | * If necessary, set the firmware waking vector and do arch-specific | ||
76 | * nastiness to get the wakeup code to the waking vector. | ||
77 | */ | ||
78 | static int __acpi_pm_prepare(void) | ||
79 | { | ||
80 | int error = acpi_sleep_prepare(acpi_target_sleep_state); | ||
81 | |||
82 | if (error) | ||
83 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
84 | return error; | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * acpi_pm_prepare - Prepare the platform to enter the target sleep | ||
89 | * state and disable the GPEs. | ||
90 | */ | ||
91 | static int acpi_pm_prepare(void) | ||
92 | { | ||
93 | int error = __acpi_pm_prepare(); | ||
94 | |||
95 | if (!error) | ||
96 | acpi_hw_disable_all_gpes(); | ||
97 | return error; | ||
98 | } | ||
99 | |||
100 | /** | ||
101 | * acpi_pm_finish - Instruct the platform to leave a sleep state. | ||
102 | * | ||
103 | * This is called after we wake back up (or if entering the sleep state | ||
104 | * failed). | ||
105 | */ | ||
106 | static void acpi_pm_finish(void) | ||
107 | { | ||
108 | u32 acpi_state = acpi_target_sleep_state; | ||
109 | |||
110 | if (acpi_state == ACPI_STATE_S0) | ||
111 | return; | ||
112 | |||
113 | printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n", | ||
114 | acpi_state); | ||
115 | acpi_disable_wakeup_device(acpi_state); | ||
116 | acpi_leave_sleep_state(acpi_state); | ||
117 | |||
118 | /* reset firmware waking vector */ | ||
119 | acpi_set_firmware_waking_vector((acpi_physical_address) 0); | ||
120 | |||
121 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
122 | } | ||
123 | |||
124 | /** | ||
125 | * acpi_pm_end - Finish up suspend sequence. | ||
126 | */ | ||
127 | static void acpi_pm_end(void) | ||
128 | { | ||
129 | /* | ||
130 | * This is necessary in case acpi_pm_finish() is not called during a | ||
131 | * failing transition to a sleep state. | ||
132 | */ | ||
133 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
134 | } | ||
135 | #endif /* CONFIG_PM_SLEEP */ | ||
54 | 136 | ||
137 | #ifdef CONFIG_SUSPEND | ||
55 | extern void do_suspend_lowlevel(void); | 138 | extern void do_suspend_lowlevel(void); |
56 | 139 | ||
57 | static u32 acpi_suspend_states[] = { | 140 | static u32 acpi_suspend_states[] = { |
@@ -65,7 +148,6 @@ static u32 acpi_suspend_states[] = { | |||
65 | * acpi_suspend_begin - Set the target system sleep state to the state | 148 | * acpi_suspend_begin - Set the target system sleep state to the state |
66 | * associated with given @pm_state, if supported. | 149 | * associated with given @pm_state, if supported. |
67 | */ | 150 | */ |
68 | |||
69 | static int acpi_suspend_begin(suspend_state_t pm_state) | 151 | static int acpi_suspend_begin(suspend_state_t pm_state) |
70 | { | 152 | { |
71 | u32 acpi_state = acpi_suspend_states[pm_state]; | 153 | u32 acpi_state = acpi_suspend_states[pm_state]; |
@@ -82,25 +164,6 @@ static int acpi_suspend_begin(suspend_state_t pm_state) | |||
82 | } | 164 | } |
83 | 165 | ||
84 | /** | 166 | /** |
85 | * acpi_suspend_prepare - Do preliminary suspend work. | ||
86 | * | ||
87 | * If necessary, set the firmware waking vector and do arch-specific | ||
88 | * nastiness to get the wakeup code to the waking vector. | ||
89 | */ | ||
90 | |||
91 | static int acpi_suspend_prepare(void) | ||
92 | { | ||
93 | int error = acpi_sleep_prepare(acpi_target_sleep_state); | ||
94 | |||
95 | if (error) { | ||
96 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
97 | return error; | ||
98 | } | ||
99 | |||
100 | return ACPI_SUCCESS(acpi_hw_disable_all_gpes()) ? 0 : -EFAULT; | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * acpi_suspend_enter - Actually enter a sleep state. | 167 | * acpi_suspend_enter - Actually enter a sleep state. |
105 | * @pm_state: ignored | 168 | * @pm_state: ignored |
106 | * | 169 | * |
@@ -108,7 +171,6 @@ static int acpi_suspend_prepare(void) | |||
108 | * assembly, which in turn call acpi_enter_sleep_state(). | 171 | * assembly, which in turn call acpi_enter_sleep_state(). |
109 | * It's unfortunate, but it works. Please fix if you're feeling frisky. | 172 | * It's unfortunate, but it works. Please fix if you're feeling frisky. |
110 | */ | 173 | */ |
111 | |||
112 | static int acpi_suspend_enter(suspend_state_t pm_state) | 174 | static int acpi_suspend_enter(suspend_state_t pm_state) |
113 | { | 175 | { |
114 | acpi_status status = AE_OK; | 176 | acpi_status status = AE_OK; |
@@ -165,39 +227,6 @@ static int acpi_suspend_enter(suspend_state_t pm_state) | |||
165 | return ACPI_SUCCESS(status) ? 0 : -EFAULT; | 227 | return ACPI_SUCCESS(status) ? 0 : -EFAULT; |
166 | } | 228 | } |
167 | 229 | ||
168 | /** | ||
169 | * acpi_suspend_finish - Instruct the platform to leave a sleep state. | ||
170 | * | ||
171 | * This is called after we wake back up (or if entering the sleep state | ||
172 | * failed). | ||
173 | */ | ||
174 | |||
175 | static void acpi_suspend_finish(void) | ||
176 | { | ||
177 | u32 acpi_state = acpi_target_sleep_state; | ||
178 | |||
179 | acpi_disable_wakeup_device(acpi_state); | ||
180 | acpi_leave_sleep_state(acpi_state); | ||
181 | |||
182 | /* reset firmware waking vector */ | ||
183 | acpi_set_firmware_waking_vector((acpi_physical_address) 0); | ||
184 | |||
185 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
186 | } | ||
187 | |||
188 | /** | ||
189 | * acpi_suspend_end - Finish up suspend sequence. | ||
190 | */ | ||
191 | |||
192 | static void acpi_suspend_end(void) | ||
193 | { | ||
194 | /* | ||
195 | * This is necessary in case acpi_suspend_finish() is not called during a | ||
196 | * failing transition to a sleep state. | ||
197 | */ | ||
198 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
199 | } | ||
200 | |||
201 | static int acpi_suspend_state_valid(suspend_state_t pm_state) | 230 | static int acpi_suspend_state_valid(suspend_state_t pm_state) |
202 | { | 231 | { |
203 | u32 acpi_state; | 232 | u32 acpi_state; |
@@ -217,10 +246,39 @@ static int acpi_suspend_state_valid(suspend_state_t pm_state) | |||
217 | static struct platform_suspend_ops acpi_suspend_ops = { | 246 | static struct platform_suspend_ops acpi_suspend_ops = { |
218 | .valid = acpi_suspend_state_valid, | 247 | .valid = acpi_suspend_state_valid, |
219 | .begin = acpi_suspend_begin, | 248 | .begin = acpi_suspend_begin, |
220 | .prepare = acpi_suspend_prepare, | 249 | .prepare = acpi_pm_prepare, |
221 | .enter = acpi_suspend_enter, | 250 | .enter = acpi_suspend_enter, |
222 | .finish = acpi_suspend_finish, | 251 | .finish = acpi_pm_finish, |
223 | .end = acpi_suspend_end, | 252 | .end = acpi_pm_end, |
253 | }; | ||
254 | |||
255 | /** | ||
256 | * acpi_suspend_begin_old - Set the target system sleep state to the | ||
257 | * state associated with given @pm_state, if supported, and | ||
258 | * execute the _PTS control method. This function is used if the | ||
259 | * pre-ACPI 2.0 suspend ordering has been requested. | ||
260 | */ | ||
261 | static int acpi_suspend_begin_old(suspend_state_t pm_state) | ||
262 | { | ||
263 | int error = acpi_suspend_begin(pm_state); | ||
264 | |||
265 | if (!error) | ||
266 | error = __acpi_pm_prepare(); | ||
267 | return error; | ||
268 | } | ||
269 | |||
270 | /* | ||
271 | * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has | ||
272 | * been requested. | ||
273 | */ | ||
274 | static struct platform_suspend_ops acpi_suspend_ops_old = { | ||
275 | .valid = acpi_suspend_state_valid, | ||
276 | .begin = acpi_suspend_begin_old, | ||
277 | .prepare = acpi_pm_disable_gpes, | ||
278 | .enter = acpi_suspend_enter, | ||
279 | .finish = acpi_pm_finish, | ||
280 | .end = acpi_pm_end, | ||
281 | .recover = acpi_pm_finish, | ||
224 | }; | 282 | }; |
225 | #endif /* CONFIG_SUSPEND */ | 283 | #endif /* CONFIG_SUSPEND */ |
226 | 284 | ||
@@ -228,22 +286,9 @@ static struct platform_suspend_ops acpi_suspend_ops = { | |||
228 | static int acpi_hibernation_begin(void) | 286 | static int acpi_hibernation_begin(void) |
229 | { | 287 | { |
230 | acpi_target_sleep_state = ACPI_STATE_S4; | 288 | acpi_target_sleep_state = ACPI_STATE_S4; |
231 | |||
232 | return 0; | 289 | return 0; |
233 | } | 290 | } |
234 | 291 | ||
235 | static int acpi_hibernation_prepare(void) | ||
236 | { | ||
237 | int error = acpi_sleep_prepare(ACPI_STATE_S4); | ||
238 | |||
239 | if (error) { | ||
240 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
241 | return error; | ||
242 | } | ||
243 | |||
244 | return ACPI_SUCCESS(acpi_hw_disable_all_gpes()) ? 0 : -EFAULT; | ||
245 | } | ||
246 | |||
247 | static int acpi_hibernation_enter(void) | 292 | static int acpi_hibernation_enter(void) |
248 | { | 293 | { |
249 | acpi_status status = AE_OK; | 294 | acpi_status status = AE_OK; |
@@ -273,52 +318,55 @@ static void acpi_hibernation_leave(void) | |||
273 | acpi_leave_sleep_state_prep(ACPI_STATE_S4); | 318 | acpi_leave_sleep_state_prep(ACPI_STATE_S4); |
274 | } | 319 | } |
275 | 320 | ||
276 | static void acpi_hibernation_finish(void) | 321 | static void acpi_pm_enable_gpes(void) |
277 | { | 322 | { |
278 | acpi_disable_wakeup_device(ACPI_STATE_S4); | 323 | acpi_hw_enable_all_runtime_gpes(); |
279 | acpi_leave_sleep_state(ACPI_STATE_S4); | ||
280 | |||
281 | /* reset firmware waking vector */ | ||
282 | acpi_set_firmware_waking_vector((acpi_physical_address) 0); | ||
283 | |||
284 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
285 | } | 324 | } |
286 | 325 | ||
287 | static void acpi_hibernation_end(void) | 326 | static struct platform_hibernation_ops acpi_hibernation_ops = { |
288 | { | 327 | .begin = acpi_hibernation_begin, |
289 | /* | 328 | .end = acpi_pm_end, |
290 | * This is necessary in case acpi_hibernation_finish() is not called | 329 | .pre_snapshot = acpi_pm_prepare, |
291 | * during a failing transition to the sleep state. | 330 | .finish = acpi_pm_finish, |
292 | */ | 331 | .prepare = acpi_pm_prepare, |
293 | acpi_target_sleep_state = ACPI_STATE_S0; | 332 | .enter = acpi_hibernation_enter, |
294 | } | 333 | .leave = acpi_hibernation_leave, |
334 | .pre_restore = acpi_pm_disable_gpes, | ||
335 | .restore_cleanup = acpi_pm_enable_gpes, | ||
336 | }; | ||
295 | 337 | ||
296 | static int acpi_hibernation_pre_restore(void) | 338 | /** |
339 | * acpi_hibernation_begin_old - Set the target system sleep state to | ||
340 | * ACPI_STATE_S4 and execute the _PTS control method. This | ||
341 | * function is used if the pre-ACPI 2.0 suspend ordering has been | ||
342 | * requested. | ||
343 | */ | ||
344 | static int acpi_hibernation_begin_old(void) | ||
297 | { | 345 | { |
298 | acpi_status status; | 346 | int error = acpi_sleep_prepare(ACPI_STATE_S4); |
299 | |||
300 | status = acpi_hw_disable_all_gpes(); | ||
301 | |||
302 | return ACPI_SUCCESS(status) ? 0 : -EFAULT; | ||
303 | } | ||
304 | 347 | ||
305 | static void acpi_hibernation_restore_cleanup(void) | 348 | if (!error) |
306 | { | 349 | acpi_target_sleep_state = ACPI_STATE_S4; |
307 | acpi_hw_enable_all_runtime_gpes(); | 350 | return error; |
308 | } | 351 | } |
309 | 352 | ||
310 | static struct platform_hibernation_ops acpi_hibernation_ops = { | 353 | /* |
311 | .begin = acpi_hibernation_begin, | 354 | * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has |
312 | .end = acpi_hibernation_end, | 355 | * been requested. |
313 | .pre_snapshot = acpi_hibernation_prepare, | 356 | */ |
314 | .finish = acpi_hibernation_finish, | 357 | static struct platform_hibernation_ops acpi_hibernation_ops_old = { |
315 | .prepare = acpi_hibernation_prepare, | 358 | .begin = acpi_hibernation_begin_old, |
359 | .end = acpi_pm_end, | ||
360 | .pre_snapshot = acpi_pm_disable_gpes, | ||
361 | .finish = acpi_pm_finish, | ||
362 | .prepare = acpi_pm_disable_gpes, | ||
316 | .enter = acpi_hibernation_enter, | 363 | .enter = acpi_hibernation_enter, |
317 | .leave = acpi_hibernation_leave, | 364 | .leave = acpi_hibernation_leave, |
318 | .pre_restore = acpi_hibernation_pre_restore, | 365 | .pre_restore = acpi_pm_disable_gpes, |
319 | .restore_cleanup = acpi_hibernation_restore_cleanup, | 366 | .restore_cleanup = acpi_pm_enable_gpes, |
367 | .recover = acpi_pm_finish, | ||
320 | }; | 368 | }; |
321 | #endif /* CONFIG_HIBERNATION */ | 369 | #endif /* CONFIG_HIBERNATION */ |
322 | 370 | ||
323 | int acpi_suspend(u32 acpi_state) | 371 | int acpi_suspend(u32 acpi_state) |
324 | { | 372 | { |
@@ -419,6 +467,31 @@ int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p) | |||
419 | *d_min_p = d_min; | 467 | *d_min_p = d_min; |
420 | return d_max; | 468 | return d_max; |
421 | } | 469 | } |
470 | |||
471 | /** | ||
472 | * acpi_pm_device_sleep_wake - enable or disable the system wake-up | ||
473 | * capability of given device | ||
474 | * @dev: device to handle | ||
475 | * @enable: 'true' - enable, 'false' - disable the wake-up capability | ||
476 | */ | ||
477 | int acpi_pm_device_sleep_wake(struct device *dev, bool enable) | ||
478 | { | ||
479 | acpi_handle handle; | ||
480 | struct acpi_device *adev; | ||
481 | |||
482 | if (!device_may_wakeup(dev)) | ||
483 | return -EINVAL; | ||
484 | |||
485 | handle = DEVICE_ACPI_HANDLE(dev); | ||
486 | if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { | ||
487 | printk(KERN_DEBUG "ACPI handle has no context!\n"); | ||
488 | return -ENODEV; | ||
489 | } | ||
490 | |||
491 | return enable ? | ||
492 | acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) : | ||
493 | acpi_disable_wakeup_device_power(adev); | ||
494 | } | ||
422 | #endif | 495 | #endif |
423 | 496 | ||
424 | static void acpi_power_off_prepare(void) | 497 | static void acpi_power_off_prepare(void) |
@@ -460,13 +533,15 @@ int __init acpi_sleep_init(void) | |||
460 | } | 533 | } |
461 | } | 534 | } |
462 | 535 | ||
463 | suspend_set_ops(&acpi_suspend_ops); | 536 | suspend_set_ops(old_suspend_ordering ? |
537 | &acpi_suspend_ops_old : &acpi_suspend_ops); | ||
464 | #endif | 538 | #endif |
465 | 539 | ||
466 | #ifdef CONFIG_HIBERNATION | 540 | #ifdef CONFIG_HIBERNATION |
467 | status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b); | 541 | status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b); |
468 | if (ACPI_SUCCESS(status)) { | 542 | if (ACPI_SUCCESS(status)) { |
469 | hibernation_set_ops(&acpi_hibernation_ops); | 543 | hibernation_set_ops(old_suspend_ordering ? |
544 | &acpi_hibernation_ops_old : &acpi_hibernation_ops); | ||
470 | sleep_states[ACPI_STATE_S4] = 1; | 545 | sleep_states[ACPI_STATE_S4] = 1; |
471 | printk(" S4"); | 546 | printk(" S4"); |
472 | } | 547 | } |
diff --git a/drivers/acpi/sleep/wakeup.c b/drivers/acpi/sleep/wakeup.c index ed8e41becf0c..38655eb132dc 100644 --- a/drivers/acpi/sleep/wakeup.c +++ b/drivers/acpi/sleep/wakeup.c | |||
@@ -42,7 +42,7 @@ void acpi_enable_wakeup_device_prep(u8 sleep_state) | |||
42 | continue; | 42 | continue; |
43 | 43 | ||
44 | spin_unlock(&acpi_device_lock); | 44 | spin_unlock(&acpi_device_lock); |
45 | acpi_enable_wakeup_device_power(dev); | 45 | acpi_enable_wakeup_device_power(dev, sleep_state); |
46 | spin_lock(&acpi_device_lock); | 46 | spin_lock(&acpi_device_lock); |
47 | } | 47 | } |
48 | spin_unlock(&acpi_device_lock); | 48 | spin_unlock(&acpi_device_lock); |
@@ -66,13 +66,15 @@ void acpi_enable_wakeup_device(u8 sleep_state) | |||
66 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | 66 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
67 | struct acpi_device *dev = | 67 | struct acpi_device *dev = |
68 | container_of(node, struct acpi_device, wakeup_list); | 68 | container_of(node, struct acpi_device, wakeup_list); |
69 | |||
69 | if (!dev->wakeup.flags.valid) | 70 | if (!dev->wakeup.flags.valid) |
70 | continue; | 71 | continue; |
72 | |||
71 | /* If users want to disable run-wake GPE, | 73 | /* If users want to disable run-wake GPE, |
72 | * we only disable it for wake and leave it for runtime | 74 | * we only disable it for wake and leave it for runtime |
73 | */ | 75 | */ |
74 | if (!dev->wakeup.state.enabled || | 76 | if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) |
75 | sleep_state > (u32) dev->wakeup.sleep_state) { | 77 | || sleep_state > (u32) dev->wakeup.sleep_state) { |
76 | if (dev->wakeup.flags.run_wake) { | 78 | if (dev->wakeup.flags.run_wake) { |
77 | spin_unlock(&acpi_device_lock); | 79 | spin_unlock(&acpi_device_lock); |
78 | /* set_gpe_type will disable GPE, leave it like that */ | 80 | /* set_gpe_type will disable GPE, leave it like that */ |
@@ -110,8 +112,9 @@ void acpi_disable_wakeup_device(u8 sleep_state) | |||
110 | 112 | ||
111 | if (!dev->wakeup.flags.valid) | 113 | if (!dev->wakeup.flags.valid) |
112 | continue; | 114 | continue; |
113 | if (!dev->wakeup.state.enabled || | 115 | |
114 | sleep_state > (u32) dev->wakeup.sleep_state) { | 116 | if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) |
117 | || sleep_state > (u32) dev->wakeup.sleep_state) { | ||
115 | if (dev->wakeup.flags.run_wake) { | 118 | if (dev->wakeup.flags.run_wake) { |
116 | spin_unlock(&acpi_device_lock); | 119 | spin_unlock(&acpi_device_lock); |
117 | acpi_set_gpe_type(dev->wakeup.gpe_device, | 120 | acpi_set_gpe_type(dev->wakeup.gpe_device, |