Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * sleep.c - ACPI sleep support. | |
3 | * | |
e2a5b420 | 4 | * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com> |
1da177e4 LT |
5 | * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com> |
6 | * Copyright (c) 2000-2003 Patrick Mochel | |
7 | * Copyright (c) 2003 Open Source Development Lab | |
8 | * | |
9 | * This file is released under the GPLv2. | |
10 | * | |
11 | */ | |
12 | ||
13 | #include <linux/delay.h> | |
14 | #include <linux/irq.h> | |
15 | #include <linux/dmi.h> | |
16 | #include <linux/device.h> | |
17 | #include <linux/suspend.h> | |
e49f711c | 18 | #include <linux/reboot.h> |
d1ee4335 | 19 | #include <linux/acpi.h> |
a2ef5c4f | 20 | #include <linux/module.h> |
b24e5098 | 21 | #include <linux/pm_runtime.h> |
f216cc37 AS |
22 | |
23 | #include <asm/io.h> | |
24 | ||
1da177e4 LT |
25 | #include <acpi/acpi_bus.h> |
26 | #include <acpi/acpi_drivers.h> | |
e60cc7a6 BH |
27 | |
28 | #include "internal.h" | |
1da177e4 LT |
29 | #include "sleep.h" |
30 | ||
01eac60b | 31 | static u8 sleep_states[ACPI_S_STATE_COUNT]; |
1da177e4 | 32 | |
e49f711c ZY |
33 | static void acpi_sleep_tts_switch(u32 acpi_state) |
34 | { | |
35 | union acpi_object in_arg = { ACPI_TYPE_INTEGER }; | |
36 | struct acpi_object_list arg_list = { 1, &in_arg }; | |
37 | acpi_status status = AE_OK; | |
38 | ||
39 | in_arg.integer.value = acpi_state; | |
40 | status = acpi_evaluate_object(NULL, "\\_TTS", &arg_list, NULL); | |
41 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { | |
42 | /* | |
43 | * OS can't evaluate the _TTS object correctly. Some warning | |
44 | * message will be printed. But it won't break anything. | |
45 | */ | |
46 | printk(KERN_NOTICE "Failure in evaluating _TTS object\n"); | |
47 | } | |
48 | } | |
49 | ||
50 | static int tts_notify_reboot(struct notifier_block *this, | |
51 | unsigned long code, void *x) | |
52 | { | |
53 | acpi_sleep_tts_switch(ACPI_STATE_S5); | |
54 | return NOTIFY_DONE; | |
55 | } | |
56 | ||
57 | static struct notifier_block tts_notifier = { | |
58 | .notifier_call = tts_notify_reboot, | |
59 | .next = NULL, | |
60 | .priority = 0, | |
61 | }; | |
62 | ||
c9b6c8f6 | 63 | static int acpi_sleep_prepare(u32 acpi_state) |
2f3f2226 AS |
64 | { |
65 | #ifdef CONFIG_ACPI_SLEEP | |
66 | /* do we have a wakeup address for S2 and S3? */ | |
67 | if (acpi_state == ACPI_STATE_S3) { | |
319b6ffc | 68 | if (!acpi_wakeup_address) |
2f3f2226 | 69 | return -EFAULT; |
319b6ffc | 70 | acpi_set_firmware_waking_vector(acpi_wakeup_address); |
2f3f2226 AS |
71 | |
72 | } | |
73 | ACPI_FLUSH_CPU_CACHE(); | |
2f3f2226 | 74 | #endif |
c9b6c8f6 RW |
75 | printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n", |
76 | acpi_state); | |
78f5f023 | 77 | acpi_enable_wakeup_devices(acpi_state); |
2f3f2226 AS |
78 | acpi_enter_sleep_state_prep(acpi_state); |
79 | return 0; | |
80 | } | |
81 | ||
5d1e072b | 82 | #ifdef CONFIG_ACPI_SLEEP |
091aad6a | 83 | static u32 acpi_target_sleep_state = ACPI_STATE_S0; |
a5ca7345 | 84 | static bool pwr_btn_event_pending; |
091aad6a | 85 | |
72ad5d77 RW |
86 | /* |
87 | * The ACPI specification wants us to save NVS memory regions during hibernation | |
88 | * and to restore them during the subsequent resume. Windows does that also for | |
89 | * suspend to RAM. However, it is known that this mechanism does not work on | |
90 | * all machines, so we allow the user to disable it with the help of the | |
91 | * 'acpi_sleep=nonvs' kernel command line option. | |
92 | */ | |
93 | static bool nvs_nosave; | |
94 | ||
95 | void __init acpi_nvs_nosave(void) | |
96 | { | |
97 | nvs_nosave = true; | |
98 | } | |
99 | ||
1bad2f19 KCA |
100 | /* |
101 | * The ACPI specification wants us to save NVS memory regions during hibernation | |
102 | * but says nothing about saving NVS during S3. Not all versions of Windows | |
103 | * save NVS on S3 suspend either, and it is clear that not all systems need | |
104 | * NVS to be saved at S3 time. To improve suspend/resume time, allow the | |
105 | * user to disable saving NVS on S3 if their system does not require it, but | |
106 | * continue to save/restore NVS for S4 as specified. | |
107 | */ | |
108 | static bool nvs_nosave_s3; | |
109 | ||
110 | void __init acpi_nvs_nosave_s3(void) | |
111 | { | |
112 | nvs_nosave_s3 = true; | |
113 | } | |
114 | ||
d8f3de0d RW |
115 | /* |
116 | * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the | |
117 | * user to request that behavior by using the 'acpi_old_suspend_ordering' | |
118 | * kernel command line option that causes the following variable to be set. | |
119 | */ | |
120 | static bool old_suspend_ordering; | |
121 | ||
122 | void __init acpi_old_suspend_ordering(void) | |
123 | { | |
124 | old_suspend_ordering = true; | |
125 | } | |
126 | ||
127 | /** | |
d5a64513 | 128 | * acpi_pm_freeze - Disable the GPEs and suspend EC transactions. |
d8f3de0d | 129 | */ |
d5a64513 | 130 | static int acpi_pm_freeze(void) |
d8f3de0d | 131 | { |
3d97e426 | 132 | acpi_disable_all_gpes(); |
bd6f10a5 | 133 | acpi_os_wait_events_complete(); |
fe955682 | 134 | acpi_ec_block_transactions(); |
d8f3de0d RW |
135 | return 0; |
136 | } | |
137 | ||
c5f7a1bb RW |
138 | /** |
139 | * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS. | |
140 | */ | |
141 | static int acpi_pm_pre_suspend(void) | |
142 | { | |
143 | acpi_pm_freeze(); | |
26fcaf60 | 144 | return suspend_nvs_save(); |
c5f7a1bb RW |
145 | } |
146 | ||
d8f3de0d RW |
147 | /** |
148 | * __acpi_pm_prepare - Prepare the platform to enter the target state. | |
149 | * | |
150 | * If necessary, set the firmware waking vector and do arch-specific | |
151 | * nastiness to get the wakeup code to the waking vector. | |
152 | */ | |
153 | static int __acpi_pm_prepare(void) | |
154 | { | |
155 | int error = acpi_sleep_prepare(acpi_target_sleep_state); | |
d8f3de0d RW |
156 | if (error) |
157 | acpi_target_sleep_state = ACPI_STATE_S0; | |
c5f7a1bb | 158 | |
d8f3de0d RW |
159 | return error; |
160 | } | |
161 | ||
162 | /** | |
163 | * acpi_pm_prepare - Prepare the platform to enter the target sleep | |
164 | * state and disable the GPEs. | |
165 | */ | |
166 | static int acpi_pm_prepare(void) | |
167 | { | |
168 | int error = __acpi_pm_prepare(); | |
d8f3de0d | 169 | if (!error) |
26fcaf60 | 170 | error = acpi_pm_pre_suspend(); |
d5a64513 | 171 | |
d8f3de0d RW |
172 | return error; |
173 | } | |
174 | ||
c10d7a13 DD |
175 | static int find_powerf_dev(struct device *dev, void *data) |
176 | { | |
177 | struct acpi_device *device = to_acpi_device(dev); | |
178 | const char *hid = acpi_device_hid(device); | |
179 | ||
180 | return !strcmp(hid, ACPI_BUTTON_HID_POWERF); | |
181 | } | |
182 | ||
d8f3de0d RW |
183 | /** |
184 | * acpi_pm_finish - Instruct the platform to leave a sleep state. | |
185 | * | |
186 | * This is called after we wake back up (or if entering the sleep state | |
187 | * failed). | |
188 | */ | |
189 | static void acpi_pm_finish(void) | |
190 | { | |
c10d7a13 | 191 | struct device *pwr_btn_dev; |
d8f3de0d RW |
192 | u32 acpi_state = acpi_target_sleep_state; |
193 | ||
42de5532 | 194 | acpi_ec_unblock_transactions(); |
d551d81d | 195 | suspend_nvs_free(); |
2a6b6976 | 196 | |
d8f3de0d RW |
197 | if (acpi_state == ACPI_STATE_S0) |
198 | return; | |
1da177e4 | 199 | |
d8f3de0d RW |
200 | printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n", |
201 | acpi_state); | |
78f5f023 | 202 | acpi_disable_wakeup_devices(acpi_state); |
d8f3de0d RW |
203 | acpi_leave_sleep_state(acpi_state); |
204 | ||
205 | /* reset firmware waking vector */ | |
206 | acpi_set_firmware_waking_vector((acpi_physical_address) 0); | |
207 | ||
208 | acpi_target_sleep_state = ACPI_STATE_S0; | |
c10d7a13 DD |
209 | |
210 | /* If we were woken with the fixed power button, provide a small | |
211 | * hint to userspace in the form of a wakeup event on the fixed power | |
212 | * button device (if it can be found). | |
213 | * | |
214 | * We delay the event generation til now, as the PM layer requires | |
215 | * timekeeping to be running before we generate events. */ | |
216 | if (!pwr_btn_event_pending) | |
217 | return; | |
218 | ||
219 | pwr_btn_event_pending = false; | |
220 | pwr_btn_dev = bus_find_device(&acpi_bus_type, NULL, NULL, | |
221 | find_powerf_dev); | |
222 | if (pwr_btn_dev) { | |
223 | pm_wakeup_event(pwr_btn_dev, 0); | |
224 | put_device(pwr_btn_dev); | |
225 | } | |
d8f3de0d RW |
226 | } |
227 | ||
228 | /** | |
229 | * acpi_pm_end - Finish up suspend sequence. | |
230 | */ | |
231 | static void acpi_pm_end(void) | |
232 | { | |
233 | /* | |
234 | * This is necessary in case acpi_pm_finish() is not called during a | |
235 | * failing transition to a sleep state. | |
236 | */ | |
237 | acpi_target_sleep_state = ACPI_STATE_S0; | |
e49f711c | 238 | acpi_sleep_tts_switch(acpi_target_sleep_state); |
d8f3de0d | 239 | } |
92daa7b5 RW |
240 | #else /* !CONFIG_ACPI_SLEEP */ |
241 | #define acpi_target_sleep_state ACPI_STATE_S0 | |
5d1e072b | 242 | #endif /* CONFIG_ACPI_SLEEP */ |
1da177e4 | 243 | |
d8f3de0d | 244 | #ifdef CONFIG_SUSPEND |
1da177e4 | 245 | static u32 acpi_suspend_states[] = { |
e2a5b420 AS |
246 | [PM_SUSPEND_ON] = ACPI_STATE_S0, |
247 | [PM_SUSPEND_STANDBY] = ACPI_STATE_S1, | |
248 | [PM_SUSPEND_MEM] = ACPI_STATE_S3, | |
e2a5b420 | 249 | [PM_SUSPEND_MAX] = ACPI_STATE_S5 |
1da177e4 LT |
250 | }; |
251 | ||
e9b3aba8 | 252 | /** |
2c6e33c3 | 253 | * acpi_suspend_begin - Set the target system sleep state to the state |
e9b3aba8 RW |
254 | * associated with given @pm_state, if supported. |
255 | */ | |
2c6e33c3 | 256 | static int acpi_suspend_begin(suspend_state_t pm_state) |
e9b3aba8 RW |
257 | { |
258 | u32 acpi_state = acpi_suspend_states[pm_state]; | |
259 | int error = 0; | |
260 | ||
1bad2f19 | 261 | error = (nvs_nosave || nvs_nosave_s3) ? 0 : suspend_nvs_alloc(); |
2a6b6976 MG |
262 | if (error) |
263 | return error; | |
264 | ||
e9b3aba8 RW |
265 | if (sleep_states[acpi_state]) { |
266 | acpi_target_sleep_state = acpi_state; | |
e49f711c | 267 | acpi_sleep_tts_switch(acpi_target_sleep_state); |
e9b3aba8 RW |
268 | } else { |
269 | printk(KERN_ERR "ACPI does not support this state: %d\n", | |
270 | pm_state); | |
271 | error = -ENOSYS; | |
272 | } | |
273 | return error; | |
274 | } | |
275 | ||
1da177e4 | 276 | /** |
2c6e33c3 | 277 | * acpi_suspend_enter - Actually enter a sleep state. |
e9b3aba8 | 278 | * @pm_state: ignored |
1da177e4 | 279 | * |
50ad147a RW |
280 | * Flush caches and go to sleep. For STR we have to call arch-specific |
281 | * assembly, which in turn call acpi_enter_sleep_state(). | |
1da177e4 LT |
282 | * It's unfortunate, but it works. Please fix if you're feeling frisky. |
283 | */ | |
2c6e33c3 | 284 | static int acpi_suspend_enter(suspend_state_t pm_state) |
1da177e4 LT |
285 | { |
286 | acpi_status status = AE_OK; | |
e9b3aba8 | 287 | u32 acpi_state = acpi_target_sleep_state; |
979f11b0 | 288 | int error; |
1da177e4 LT |
289 | |
290 | ACPI_FLUSH_CPU_CACHE(); | |
291 | ||
e9b3aba8 RW |
292 | switch (acpi_state) { |
293 | case ACPI_STATE_S1: | |
1da177e4 | 294 | barrier(); |
3f6f49c7 | 295 | status = acpi_enter_sleep_state(acpi_state); |
1da177e4 LT |
296 | break; |
297 | ||
e9b3aba8 | 298 | case ACPI_STATE_S3: |
f1a2003e | 299 | error = acpi_suspend_lowlevel(); |
979f11b0 RW |
300 | if (error) |
301 | return error; | |
7a63f08b | 302 | pr_info(PREFIX "Low-level resume complete\n"); |
1da177e4 | 303 | break; |
1da177e4 | 304 | } |
872d83d0 | 305 | |
b6dacf63 MG |
306 | /* This violates the spec but is required for bug compatibility. */ |
307 | acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1); | |
65df7847 | 308 | |
3f6f49c7 LB |
309 | /* Reprogram control registers */ |
310 | acpi_leave_sleep_state_prep(acpi_state); | |
c95d47a8 | 311 | |
23b168d4 | 312 | /* ACPI 3.0 specs (P62) says that it's the responsibility |
872d83d0 AP |
313 | * of the OSPM to clear the status bit [ implying that the |
314 | * POWER_BUTTON event should not reach userspace ] | |
c10d7a13 DD |
315 | * |
316 | * However, we do generate a small hint for userspace in the form of | |
317 | * a wakeup event. We flag this condition for now and generate the | |
318 | * event later, as we're currently too early in resume to be able to | |
319 | * generate wakeup events. | |
872d83d0 | 320 | */ |
c10d7a13 DD |
321 | if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3)) { |
322 | acpi_event_status pwr_btn_status; | |
323 | ||
324 | acpi_get_event_status(ACPI_EVENT_POWER_BUTTON, &pwr_btn_status); | |
325 | ||
326 | if (pwr_btn_status & ACPI_EVENT_FLAG_SET) { | |
327 | acpi_clear_event(ACPI_EVENT_POWER_BUTTON); | |
328 | /* Flag for later */ | |
329 | pwr_btn_event_pending = true; | |
330 | } | |
331 | } | |
872d83d0 | 332 | |
a3627f67 SL |
333 | /* |
334 | * Disable and clear GPE status before interrupt is enabled. Some GPEs | |
335 | * (like wakeup GPE) haven't handler, this can avoid such GPE misfire. | |
336 | * acpi_leave_sleep_state will reenable specific GPEs later | |
337 | */ | |
3d97e426 | 338 | acpi_disable_all_gpes(); |
d5a64513 | 339 | /* Allow EC transactions to happen. */ |
fe955682 | 340 | acpi_ec_unblock_transactions_early(); |
a3627f67 | 341 | |
2a6b6976 MG |
342 | suspend_nvs_restore(); |
343 | ||
1da177e4 LT |
344 | return ACPI_SUCCESS(status) ? 0 : -EFAULT; |
345 | } | |
346 | ||
2c6e33c3 | 347 | static int acpi_suspend_state_valid(suspend_state_t pm_state) |
eb9289eb | 348 | { |
e8c9c502 | 349 | u32 acpi_state; |
eb9289eb | 350 | |
e8c9c502 JB |
351 | switch (pm_state) { |
352 | case PM_SUSPEND_ON: | |
353 | case PM_SUSPEND_STANDBY: | |
354 | case PM_SUSPEND_MEM: | |
355 | acpi_state = acpi_suspend_states[pm_state]; | |
356 | ||
357 | return sleep_states[acpi_state]; | |
358 | default: | |
359 | return 0; | |
360 | } | |
eb9289eb SL |
361 | } |
362 | ||
2f55ac07 | 363 | static const struct platform_suspend_ops acpi_suspend_ops = { |
2c6e33c3 LB |
364 | .valid = acpi_suspend_state_valid, |
365 | .begin = acpi_suspend_begin, | |
6a7c7eaf | 366 | .prepare_late = acpi_pm_prepare, |
2c6e33c3 | 367 | .enter = acpi_suspend_enter, |
618d7fd0 | 368 | .wake = acpi_pm_finish, |
d8f3de0d RW |
369 | .end = acpi_pm_end, |
370 | }; | |
371 | ||
372 | /** | |
373 | * acpi_suspend_begin_old - Set the target system sleep state to the | |
374 | * state associated with given @pm_state, if supported, and | |
375 | * execute the _PTS control method. This function is used if the | |
376 | * pre-ACPI 2.0 suspend ordering has been requested. | |
377 | */ | |
378 | static int acpi_suspend_begin_old(suspend_state_t pm_state) | |
379 | { | |
380 | int error = acpi_suspend_begin(pm_state); | |
d8f3de0d RW |
381 | if (!error) |
382 | error = __acpi_pm_prepare(); | |
c5f7a1bb | 383 | |
d8f3de0d RW |
384 | return error; |
385 | } | |
386 | ||
387 | /* | |
388 | * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has | |
389 | * been requested. | |
390 | */ | |
2f55ac07 | 391 | static const struct platform_suspend_ops acpi_suspend_ops_old = { |
d8f3de0d RW |
392 | .valid = acpi_suspend_state_valid, |
393 | .begin = acpi_suspend_begin_old, | |
c5f7a1bb | 394 | .prepare_late = acpi_pm_pre_suspend, |
2c6e33c3 | 395 | .enter = acpi_suspend_enter, |
618d7fd0 | 396 | .wake = acpi_pm_finish, |
d8f3de0d RW |
397 | .end = acpi_pm_end, |
398 | .recover = acpi_pm_finish, | |
1da177e4 | 399 | }; |
e41fb7c5 CC |
400 | |
401 | static int __init init_old_suspend_ordering(const struct dmi_system_id *d) | |
402 | { | |
403 | old_suspend_ordering = true; | |
404 | return 0; | |
405 | } | |
406 | ||
53998648 RW |
407 | static int __init init_nvs_nosave(const struct dmi_system_id *d) |
408 | { | |
409 | acpi_nvs_nosave(); | |
410 | return 0; | |
411 | } | |
412 | ||
e41fb7c5 CC |
413 | static struct dmi_system_id __initdata acpisleep_dmi_table[] = { |
414 | { | |
415 | .callback = init_old_suspend_ordering, | |
416 | .ident = "Abit KN9 (nForce4 variant)", | |
417 | .matches = { | |
418 | DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"), | |
419 | DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"), | |
420 | }, | |
421 | }, | |
4fb507b6 RW |
422 | { |
423 | .callback = init_old_suspend_ordering, | |
424 | .ident = "HP xw4600 Workstation", | |
425 | .matches = { | |
426 | DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), | |
427 | DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"), | |
428 | }, | |
429 | }, | |
65df7847 | 430 | { |
a1404495 AW |
431 | .callback = init_old_suspend_ordering, |
432 | .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)", | |
433 | .matches = { | |
434 | DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."), | |
435 | DMI_MATCH(DMI_BOARD_NAME, "M2N8L"), | |
436 | }, | |
437 | }, | |
45e77988 | 438 | { |
2a9ef8e1 ZY |
439 | .callback = init_old_suspend_ordering, |
440 | .ident = "Panasonic CF51-2L", | |
441 | .matches = { | |
442 | DMI_MATCH(DMI_BOARD_VENDOR, | |
443 | "Matsushita Electric Industrial Co.,Ltd."), | |
444 | DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"), | |
445 | }, | |
446 | }, | |
53998648 RW |
447 | { |
448 | .callback = init_nvs_nosave, | |
d11c78e9 DJ |
449 | .ident = "Sony Vaio VGN-FW21E", |
450 | .matches = { | |
451 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | |
452 | DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"), | |
453 | }, | |
454 | }, | |
455 | { | |
456 | .callback = init_nvs_nosave, | |
ddf6ce45 DJ |
457 | .ident = "Sony Vaio VPCEB17FX", |
458 | .matches = { | |
459 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | |
460 | DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"), | |
461 | }, | |
462 | }, | |
463 | { | |
464 | .callback = init_nvs_nosave, | |
53998648 RW |
465 | .ident = "Sony Vaio VGN-SR11M", |
466 | .matches = { | |
467 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | |
468 | DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"), | |
469 | }, | |
470 | }, | |
471 | { | |
472 | .callback = init_nvs_nosave, | |
473 | .ident = "Everex StepNote Series", | |
474 | .matches = { | |
475 | DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."), | |
476 | DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"), | |
477 | }, | |
478 | }, | |
af48931c RW |
479 | { |
480 | .callback = init_nvs_nosave, | |
481 | .ident = "Sony Vaio VPCEB1Z1E", | |
482 | .matches = { | |
483 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | |
484 | DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"), | |
485 | }, | |
486 | }, | |
291a73c9 RW |
487 | { |
488 | .callback = init_nvs_nosave, | |
489 | .ident = "Sony Vaio VGN-NW130D", | |
490 | .matches = { | |
491 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | |
492 | DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"), | |
493 | }, | |
494 | }, | |
7b330707 RW |
495 | { |
496 | .callback = init_nvs_nosave, | |
93f77084 LT |
497 | .ident = "Sony Vaio VPCCW29FX", |
498 | .matches = { | |
499 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | |
500 | DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"), | |
501 | }, | |
502 | }, | |
503 | { | |
504 | .callback = init_nvs_nosave, | |
7b330707 RW |
505 | .ident = "Averatec AV1020-ED2", |
506 | .matches = { | |
507 | DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"), | |
508 | DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"), | |
509 | }, | |
510 | }, | |
bb0c5ed6 ZR |
511 | { |
512 | .callback = init_old_suspend_ordering, | |
513 | .ident = "Asus A8N-SLI DELUXE", | |
514 | .matches = { | |
515 | DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), | |
516 | DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"), | |
517 | }, | |
518 | }, | |
519 | { | |
520 | .callback = init_old_suspend_ordering, | |
521 | .ident = "Asus A8N-SLI Premium", | |
522 | .matches = { | |
523 | DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), | |
524 | DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"), | |
525 | }, | |
526 | }, | |
89e8ea12 RW |
527 | { |
528 | .callback = init_nvs_nosave, | |
529 | .ident = "Sony Vaio VGN-SR26GN_P", | |
530 | .matches = { | |
531 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | |
532 | DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"), | |
533 | }, | |
534 | }, | |
731b25a4 BR |
535 | { |
536 | .callback = init_nvs_nosave, | |
876ab790 LT |
537 | .ident = "Sony Vaio VPCEB1S1E", |
538 | .matches = { | |
539 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | |
540 | DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1S1E"), | |
541 | }, | |
542 | }, | |
543 | { | |
544 | .callback = init_nvs_nosave, | |
731b25a4 BR |
545 | .ident = "Sony Vaio VGN-FW520F", |
546 | .matches = { | |
547 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | |
548 | DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"), | |
549 | }, | |
550 | }, | |
5a50a7c3 KYL |
551 | { |
552 | .callback = init_nvs_nosave, | |
553 | .ident = "Asus K54C", | |
554 | .matches = { | |
555 | DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."), | |
556 | DMI_MATCH(DMI_PRODUCT_NAME, "K54C"), | |
557 | }, | |
558 | }, | |
559 | { | |
560 | .callback = init_nvs_nosave, | |
561 | .ident = "Asus K54HR", | |
562 | .matches = { | |
563 | DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."), | |
564 | DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"), | |
565 | }, | |
566 | }, | |
e41fb7c5 CC |
567 | {}, |
568 | }; | |
296699de RW |
569 | #endif /* CONFIG_SUSPEND */ |
570 | ||
b0cb1a19 | 571 | #ifdef CONFIG_HIBERNATION |
bdfe6b7c SL |
572 | static unsigned long s4_hardware_signature; |
573 | static struct acpi_table_facs *facs; | |
574 | static bool nosigcheck; | |
575 | ||
576 | void __init acpi_no_s4_hw_signature(void) | |
577 | { | |
578 | nosigcheck = true; | |
579 | } | |
580 | ||
caea99ef | 581 | static int acpi_hibernation_begin(void) |
74f270af | 582 | { |
3f4b0ef7 RW |
583 | int error; |
584 | ||
72ad5d77 | 585 | error = nvs_nosave ? 0 : suspend_nvs_alloc(); |
3f4b0ef7 RW |
586 | if (!error) { |
587 | acpi_target_sleep_state = ACPI_STATE_S4; | |
588 | acpi_sleep_tts_switch(acpi_target_sleep_state); | |
589 | } | |
590 | ||
591 | return error; | |
592 | } | |
593 | ||
a3d25c27 RW |
594 | static int acpi_hibernation_enter(void) |
595 | { | |
596 | acpi_status status = AE_OK; | |
a3d25c27 RW |
597 | |
598 | ACPI_FLUSH_CPU_CACHE(); | |
599 | ||
a3d25c27 | 600 | /* This shouldn't return. If it returns, we have a problem */ |
3f6f49c7 LB |
601 | status = acpi_enter_sleep_state(ACPI_STATE_S4); |
602 | /* Reprogram control registers */ | |
603 | acpi_leave_sleep_state_prep(ACPI_STATE_S4); | |
a3d25c27 RW |
604 | |
605 | return ACPI_SUCCESS(status) ? 0 : -EFAULT; | |
606 | } | |
607 | ||
c7e0831d RW |
608 | static void acpi_hibernation_leave(void) |
609 | { | |
610 | /* | |
611 | * If ACPI is not enabled by the BIOS and the boot kernel, we need to | |
612 | * enable it here. | |
613 | */ | |
614 | acpi_enable(); | |
3f6f49c7 LB |
615 | /* Reprogram control registers */ |
616 | acpi_leave_sleep_state_prep(ACPI_STATE_S4); | |
bdfe6b7c SL |
617 | /* Check the hardware signature */ |
618 | if (facs && s4_hardware_signature != facs->hardware_signature) { | |
619 | printk(KERN_EMERG "ACPI: Hardware changed while hibernated, " | |
620 | "cannot resume!\n"); | |
621 | panic("ACPI S4 hardware signature mismatch"); | |
622 | } | |
3f4b0ef7 | 623 | /* Restore the NVS memory area */ |
dd4c4f17 | 624 | suspend_nvs_restore(); |
d5a64513 | 625 | /* Allow EC transactions to happen. */ |
fe955682 | 626 | acpi_ec_unblock_transactions_early(); |
c7e0831d RW |
627 | } |
628 | ||
d5a64513 | 629 | static void acpi_pm_thaw(void) |
f6bb13aa | 630 | { |
fe955682 | 631 | acpi_ec_unblock_transactions(); |
3d97e426 | 632 | acpi_enable_all_runtime_gpes(); |
a3d25c27 RW |
633 | } |
634 | ||
073ef1f6 | 635 | static const struct platform_hibernation_ops acpi_hibernation_ops = { |
d8f3de0d RW |
636 | .begin = acpi_hibernation_begin, |
637 | .end = acpi_pm_end, | |
c5f7a1bb | 638 | .pre_snapshot = acpi_pm_prepare, |
2a6b6976 | 639 | .finish = acpi_pm_finish, |
d8f3de0d RW |
640 | .prepare = acpi_pm_prepare, |
641 | .enter = acpi_hibernation_enter, | |
642 | .leave = acpi_hibernation_leave, | |
d5a64513 RW |
643 | .pre_restore = acpi_pm_freeze, |
644 | .restore_cleanup = acpi_pm_thaw, | |
d8f3de0d | 645 | }; |
caea99ef | 646 | |
d8f3de0d RW |
647 | /** |
648 | * acpi_hibernation_begin_old - Set the target system sleep state to | |
649 | * ACPI_STATE_S4 and execute the _PTS control method. This | |
650 | * function is used if the pre-ACPI 2.0 suspend ordering has been | |
651 | * requested. | |
652 | */ | |
653 | static int acpi_hibernation_begin_old(void) | |
a634cc10 | 654 | { |
e49f711c ZY |
655 | int error; |
656 | /* | |
657 | * The _TTS object should always be evaluated before the _PTS object. | |
658 | * When the old_suspended_ordering is true, the _PTS object is | |
659 | * evaluated in the acpi_sleep_prepare. | |
660 | */ | |
661 | acpi_sleep_tts_switch(ACPI_STATE_S4); | |
662 | ||
663 | error = acpi_sleep_prepare(ACPI_STATE_S4); | |
a634cc10 | 664 | |
3f4b0ef7 | 665 | if (!error) { |
72ad5d77 | 666 | if (!nvs_nosave) |
dd4c4f17 | 667 | error = suspend_nvs_alloc(); |
3f4b0ef7 RW |
668 | if (!error) |
669 | acpi_target_sleep_state = ACPI_STATE_S4; | |
670 | } | |
671 | return error; | |
672 | } | |
673 | ||
d8f3de0d RW |
674 | /* |
675 | * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has | |
676 | * been requested. | |
677 | */ | |
073ef1f6 | 678 | static const struct platform_hibernation_ops acpi_hibernation_ops_old = { |
d8f3de0d RW |
679 | .begin = acpi_hibernation_begin_old, |
680 | .end = acpi_pm_end, | |
c5f7a1bb | 681 | .pre_snapshot = acpi_pm_pre_suspend, |
d5a64513 | 682 | .prepare = acpi_pm_freeze, |
2a6b6976 | 683 | .finish = acpi_pm_finish, |
a3d25c27 | 684 | .enter = acpi_hibernation_enter, |
c7e0831d | 685 | .leave = acpi_hibernation_leave, |
d5a64513 RW |
686 | .pre_restore = acpi_pm_freeze, |
687 | .restore_cleanup = acpi_pm_thaw, | |
d8f3de0d | 688 | .recover = acpi_pm_finish, |
a3d25c27 | 689 | }; |
d8f3de0d | 690 | #endif /* CONFIG_HIBERNATION */ |
a3d25c27 | 691 | |
296699de RW |
692 | int acpi_suspend(u32 acpi_state) |
693 | { | |
694 | suspend_state_t states[] = { | |
695 | [1] = PM_SUSPEND_STANDBY, | |
696 | [3] = PM_SUSPEND_MEM, | |
697 | [5] = PM_SUSPEND_MAX | |
698 | }; | |
699 | ||
700 | if (acpi_state < 6 && states[acpi_state]) | |
701 | return pm_suspend(states[acpi_state]); | |
702 | if (acpi_state == 4) | |
703 | return hibernate(); | |
704 | return -EINVAL; | |
705 | } | |
706 | ||
aa338601 | 707 | #ifdef CONFIG_PM |
fd4aff1a SL |
708 | /** |
709 | * acpi_pm_device_sleep_state - return preferred power state of ACPI device | |
710 | * in the system sleep state given by %acpi_target_sleep_state | |
2fe2de5f DB |
711 | * @dev: device to examine; its driver model wakeup flags control |
712 | * whether it should be able to wake up the system | |
fd4aff1a | 713 | * @d_min_p: used to store the upper limit of allowed states range |
ee85f543 HY |
714 | * @d_max_in: specify the lowest allowed states |
715 | * Return value: preferred power state of the device on success, -ENODEV | |
716 | * (ie. if there's no 'struct acpi_device' for @dev) or -EINVAL on failure | |
fd4aff1a SL |
717 | * |
718 | * Find the lowest power (highest number) ACPI device power state that | |
719 | * device @dev can be in while the system is in the sleep state represented | |
720 | * by %acpi_target_sleep_state. If @wake is nonzero, the device should be | |
721 | * able to wake up the system from this sleep state. If @d_min_p is set, | |
722 | * the highest power (lowest number) device power state of @dev allowed | |
723 | * in this system sleep state is stored at the location pointed to by it. | |
724 | * | |
725 | * The caller must ensure that @dev is valid before using this function. | |
726 | * The caller is also responsible for figuring out if the device is | |
727 | * supposed to be able to wake up the system and passing this information | |
728 | * via @wake. | |
729 | */ | |
730 | ||
ee85f543 | 731 | int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in) |
fd4aff1a SL |
732 | { |
733 | acpi_handle handle = DEVICE_ACPI_HANDLE(dev); | |
734 | struct acpi_device *adev; | |
735 | char acpi_method[] = "_SxD"; | |
27663c58 | 736 | unsigned long long d_min, d_max; |
fd4aff1a | 737 | |
ee85f543 HY |
738 | if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3) |
739 | return -EINVAL; | |
fd4aff1a | 740 | if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { |
ead77594 | 741 | printk(KERN_DEBUG "ACPI handle has no context!\n"); |
fd4aff1a SL |
742 | return -ENODEV; |
743 | } | |
744 | ||
745 | acpi_method[2] = '0' + acpi_target_sleep_state; | |
746 | /* | |
ee85f543 HY |
747 | * If the sleep state is S0, the lowest limit from ACPI is D3, |
748 | * but if the device has _S0W, we will use the value from _S0W | |
749 | * as the lowest limit from ACPI. Finally, we will constrain | |
750 | * the lowest limit with the specified one. | |
fd4aff1a SL |
751 | */ |
752 | d_min = ACPI_STATE_D0; | |
753 | d_max = ACPI_STATE_D3; | |
754 | ||
755 | /* | |
756 | * If present, _SxD methods return the minimum D-state (highest power | |
757 | * state) we can use for the corresponding S-states. Otherwise, the | |
758 | * minimum D-state is D0 (ACPI 3.x). | |
759 | * | |
760 | * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer | |
761 | * provided -- that's our fault recovery, we ignore retval. | |
762 | */ | |
763 | if (acpi_target_sleep_state > ACPI_STATE_S0) | |
764 | acpi_evaluate_integer(handle, acpi_method, NULL, &d_min); | |
765 | ||
766 | /* | |
767 | * If _PRW says we can wake up the system from the target sleep state, | |
768 | * the D-state returned by _SxD is sufficient for that (we assume a | |
769 | * wakeup-aware driver if wake is set). Still, if _SxW exists | |
770 | * (ACPI 3.x), it should return the maximum (lowest power) D-state that | |
771 | * can wake the system. _S0W may be valid, too. | |
772 | */ | |
773 | if (acpi_target_sleep_state == ACPI_STATE_S0 || | |
dbe9a2ed RW |
774 | (device_may_wakeup(dev) && adev->wakeup.flags.valid && |
775 | adev->wakeup.sleep_state >= acpi_target_sleep_state)) { | |
ad3399c3 RW |
776 | acpi_status status; |
777 | ||
fd4aff1a | 778 | acpi_method[3] = 'W'; |
ad3399c3 RW |
779 | status = acpi_evaluate_integer(handle, acpi_method, NULL, |
780 | &d_max); | |
781 | if (ACPI_FAILURE(status)) { | |
761afb86 RW |
782 | if (acpi_target_sleep_state != ACPI_STATE_S0 || |
783 | status != AE_NOT_FOUND) | |
784 | d_max = d_min; | |
ad3399c3 RW |
785 | } else if (d_max < d_min) { |
786 | /* Warn the user of the broken DSDT */ | |
787 | printk(KERN_WARNING "ACPI: Wrong value from %s\n", | |
788 | acpi_method); | |
789 | /* Sanitize it */ | |
fd4aff1a | 790 | d_min = d_max; |
ad3399c3 | 791 | } |
fd4aff1a SL |
792 | } |
793 | ||
ee85f543 HY |
794 | if (d_max_in < d_min) |
795 | return -EINVAL; | |
fd4aff1a SL |
796 | if (d_min_p) |
797 | *d_min_p = d_min; | |
ee85f543 HY |
798 | /* constrain d_max with specified lowest limit (max number) */ |
799 | if (d_max > d_max_in) { | |
800 | for (d_max = d_max_in; d_max > d_min; d_max--) { | |
801 | if (adev->power.states[d_max].flags.valid) | |
802 | break; | |
803 | } | |
804 | } | |
fd4aff1a SL |
805 | return d_max; |
806 | } | |
3bd46600 | 807 | EXPORT_SYMBOL(acpi_pm_device_sleep_state); |
aa338601 | 808 | #endif /* CONFIG_PM */ |
eb9d0fe4 | 809 | |
761afb86 | 810 | #ifdef CONFIG_PM_SLEEP |
b24e5098 LM |
811 | /** |
812 | * acpi_pm_device_run_wake - Enable/disable wake-up for given device. | |
813 | * @phys_dev: Device to enable/disable the platform to wake-up the system for. | |
814 | * @enable: Whether enable or disable the wake-up functionality. | |
815 | * | |
816 | * Find the ACPI device object corresponding to @pci_dev and try to | |
817 | * enable/disable the GPE associated with it. | |
818 | */ | |
819 | int acpi_pm_device_run_wake(struct device *phys_dev, bool enable) | |
820 | { | |
821 | struct acpi_device *dev; | |
822 | acpi_handle handle; | |
823 | ||
824 | if (!device_run_wake(phys_dev)) | |
825 | return -EINVAL; | |
826 | ||
827 | handle = DEVICE_ACPI_HANDLE(phys_dev); | |
828 | if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &dev))) { | |
829 | dev_dbg(phys_dev, "ACPI handle has no context in %s!\n", | |
830 | __func__); | |
831 | return -ENODEV; | |
832 | } | |
833 | ||
834 | if (enable) { | |
835 | acpi_enable_wakeup_device_power(dev, ACPI_STATE_S0); | |
836 | acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number); | |
837 | } else { | |
838 | acpi_disable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number); | |
839 | acpi_disable_wakeup_device_power(dev); | |
840 | } | |
841 | ||
842 | return 0; | |
843 | } | |
3bd46600 | 844 | EXPORT_SYMBOL(acpi_pm_device_run_wake); |
b24e5098 | 845 | |
eb9d0fe4 RW |
846 | /** |
847 | * acpi_pm_device_sleep_wake - enable or disable the system wake-up | |
848 | * capability of given device | |
849 | * @dev: device to handle | |
850 | * @enable: 'true' - enable, 'false' - disable the wake-up capability | |
851 | */ | |
852 | int acpi_pm_device_sleep_wake(struct device *dev, bool enable) | |
853 | { | |
854 | acpi_handle handle; | |
855 | struct acpi_device *adev; | |
df8db91f | 856 | int error; |
eb9d0fe4 | 857 | |
0baed8da | 858 | if (!device_can_wakeup(dev)) |
eb9d0fe4 RW |
859 | return -EINVAL; |
860 | ||
861 | handle = DEVICE_ACPI_HANDLE(dev); | |
862 | if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { | |
df8db91f | 863 | dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__); |
eb9d0fe4 RW |
864 | return -ENODEV; |
865 | } | |
866 | ||
e8b6f970 RW |
867 | error = enable ? |
868 | acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) : | |
869 | acpi_disable_wakeup_device_power(adev); | |
df8db91f RW |
870 | if (!error) |
871 | dev_info(dev, "wake-up capability %s by ACPI\n", | |
872 | enable ? "enabled" : "disabled"); | |
873 | ||
874 | return error; | |
eb9d0fe4 | 875 | } |
761afb86 | 876 | #endif /* CONFIG_PM_SLEEP */ |
fd4aff1a | 877 | |
f216cc37 AS |
878 | static void acpi_power_off_prepare(void) |
879 | { | |
880 | /* Prepare to power off the system */ | |
881 | acpi_sleep_prepare(ACPI_STATE_S5); | |
3d97e426 | 882 | acpi_disable_all_gpes(); |
f216cc37 AS |
883 | } |
884 | ||
885 | static void acpi_power_off(void) | |
886 | { | |
887 | /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */ | |
4d939155 | 888 | printk(KERN_DEBUG "%s called\n", __func__); |
f216cc37 | 889 | local_irq_disable(); |
3f6f49c7 | 890 | acpi_enter_sleep_state(ACPI_STATE_S5); |
96f15efc LB |
891 | } |
892 | ||
aafbcd16 | 893 | int __init acpi_sleep_init(void) |
1da177e4 | 894 | { |
296699de RW |
895 | acpi_status status; |
896 | u8 type_a, type_b; | |
897 | #ifdef CONFIG_SUSPEND | |
e2a5b420 | 898 | int i = 0; |
e41fb7c5 CC |
899 | |
900 | dmi_check_system(acpisleep_dmi_table); | |
296699de | 901 | #endif |
1da177e4 LT |
902 | |
903 | if (acpi_disabled) | |
904 | return 0; | |
905 | ||
5a50fe70 FP |
906 | sleep_states[ACPI_STATE_S0] = 1; |
907 | printk(KERN_INFO PREFIX "(supports S0"); | |
908 | ||
296699de | 909 | #ifdef CONFIG_SUSPEND |
5a50fe70 | 910 | for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) { |
1da177e4 LT |
911 | status = acpi_get_sleep_type_data(i, &type_a, &type_b); |
912 | if (ACPI_SUCCESS(status)) { | |
913 | sleep_states[i] = 1; | |
be96447e | 914 | printk(KERN_CONT " S%d", i); |
1da177e4 | 915 | } |
1da177e4 | 916 | } |
1da177e4 | 917 | |
d8f3de0d RW |
918 | suspend_set_ops(old_suspend_ordering ? |
919 | &acpi_suspend_ops_old : &acpi_suspend_ops); | |
296699de | 920 | #endif |
a3d25c27 | 921 | |
b0cb1a19 | 922 | #ifdef CONFIG_HIBERNATION |
296699de RW |
923 | status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b); |
924 | if (ACPI_SUCCESS(status)) { | |
d8f3de0d RW |
925 | hibernation_set_ops(old_suspend_ordering ? |
926 | &acpi_hibernation_ops_old : &acpi_hibernation_ops); | |
296699de | 927 | sleep_states[ACPI_STATE_S4] = 1; |
be96447e | 928 | printk(KERN_CONT " S4"); |
bdfe6b7c | 929 | if (!nosigcheck) { |
3d97e426 | 930 | acpi_get_table(ACPI_SIG_FACS, 1, |
bdfe6b7c SL |
931 | (struct acpi_table_header **)&facs); |
932 | if (facs) | |
933 | s4_hardware_signature = | |
934 | facs->hardware_signature; | |
935 | } | |
296699de | 936 | } |
a3d25c27 | 937 | #endif |
f216cc37 AS |
938 | status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); |
939 | if (ACPI_SUCCESS(status)) { | |
940 | sleep_states[ACPI_STATE_S5] = 1; | |
be96447e | 941 | printk(KERN_CONT " S5"); |
f216cc37 AS |
942 | pm_power_off_prepare = acpi_power_off_prepare; |
943 | pm_power_off = acpi_power_off; | |
944 | } | |
be96447e | 945 | printk(KERN_CONT ")\n"); |
e49f711c ZY |
946 | /* |
947 | * Register the tts_notifier to reboot notifier list so that the _TTS | |
948 | * object can also be evaluated when the system enters S5. | |
949 | */ | |
950 | register_reboot_notifier(&tts_notifier); | |
1da177e4 LT |
951 | return 0; |
952 | } |