blob: 00fa664d5fd8406e57bd8b28b4f4bd2dcc9127e7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sleep.c - ACPI sleep support.
3 *
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -05004 * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * 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>
Zhao Yakuie49f7112008-08-12 10:20:22 +080018#include <linux/reboot.h>
H. Peter Anvind1ee4332011-02-14 15:42:46 -080019#include <linux/acpi.h>
Lin Mingb24e5092012-03-27 15:43:25 +080020#include <linux/pm_runtime.h>
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +040021
22#include <asm/io.h>
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <acpi/acpi_bus.h>
25#include <acpi/acpi_drivers.h>
Bjorn Helgaase60cc7a2009-03-13 12:08:26 -060026
27#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include "sleep.h"
29
Stephen Hemminger01eac602010-10-18 18:47:25 -070030static u8 sleep_states[ACPI_S_STATE_COUNT];
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Zhao Yakuie49f7112008-08-12 10:20:22 +080032static void acpi_sleep_tts_switch(u32 acpi_state)
33{
34 union acpi_object in_arg = { ACPI_TYPE_INTEGER };
35 struct acpi_object_list arg_list = { 1, &in_arg };
36 acpi_status status = AE_OK;
37
38 in_arg.integer.value = acpi_state;
39 status = acpi_evaluate_object(NULL, "\\_TTS", &arg_list, NULL);
40 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
41 /*
42 * OS can't evaluate the _TTS object correctly. Some warning
43 * message will be printed. But it won't break anything.
44 */
45 printk(KERN_NOTICE "Failure in evaluating _TTS object\n");
46 }
47}
48
49static int tts_notify_reboot(struct notifier_block *this,
50 unsigned long code, void *x)
51{
52 acpi_sleep_tts_switch(ACPI_STATE_S5);
53 return NOTIFY_DONE;
54}
55
56static struct notifier_block tts_notifier = {
57 .notifier_call = tts_notify_reboot,
58 .next = NULL,
59 .priority = 0,
60};
61
Rafael J. Wysockic9b6c8f2008-01-08 00:10:57 +010062static int acpi_sleep_prepare(u32 acpi_state)
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020063{
64#ifdef CONFIG_ACPI_SLEEP
65 /* do we have a wakeup address for S2 and S3? */
66 if (acpi_state == ACPI_STATE_S3) {
67 if (!acpi_wakeup_address) {
68 return -EFAULT;
69 }
H. Peter Anvin4b4f7282008-06-24 23:03:48 +020070 acpi_set_firmware_waking_vector(
71 (acpi_physical_address)acpi_wakeup_address);
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020072
73 }
74 ACPI_FLUSH_CPU_CACHE();
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020075#endif
Rafael J. Wysockic9b6c8f2008-01-08 00:10:57 +010076 printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
77 acpi_state);
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040078 acpi_enable_wakeup_devices(acpi_state);
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020079 acpi_enter_sleep_state_prep(acpi_state);
80 return 0;
81}
82
Rafael J. Wysocki5d1e0722008-10-22 14:58:43 -040083#ifdef CONFIG_ACPI_SLEEP
Jan Beulich091aad62010-12-07 14:52:25 +000084static u32 acpi_target_sleep_state = ACPI_STATE_S0;
85
Zhang Ruid7f0eea2009-12-30 15:36:42 +080086/*
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +020087 * 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 */
93static bool nvs_nosave;
94
95void __init acpi_nvs_nosave(void)
96{
97 nvs_nosave = true;
98}
99
100/*
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200101 * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
102 * user to request that behavior by using the 'acpi_old_suspend_ordering'
103 * kernel command line option that causes the following variable to be set.
104 */
105static bool old_suspend_ordering;
106
107void __init acpi_old_suspend_ordering(void)
108{
109 old_suspend_ordering = true;
110}
111
112/**
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200113 * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200114 */
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200115static int acpi_pm_freeze(void)
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200116{
Lin Ming3d97e422008-12-16 16:57:46 +0800117 acpi_disable_all_gpes();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200118 acpi_os_wait_events_complete(NULL);
Rafael J. Wysockife955682010-04-09 01:40:38 +0200119 acpi_ec_block_transactions();
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200120 return 0;
121}
122
123/**
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200124 * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
125 */
126static int acpi_pm_pre_suspend(void)
127{
128 acpi_pm_freeze();
Jiri Slaby26fcaf62011-01-07 01:42:31 +0100129 return suspend_nvs_save();
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200130}
131
132/**
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200133 * __acpi_pm_prepare - Prepare the platform to enter the target state.
134 *
135 * If necessary, set the firmware waking vector and do arch-specific
136 * nastiness to get the wakeup code to the waking vector.
137 */
138static int __acpi_pm_prepare(void)
139{
140 int error = acpi_sleep_prepare(acpi_target_sleep_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200141 if (error)
142 acpi_target_sleep_state = ACPI_STATE_S0;
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200143
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200144 return error;
145}
146
147/**
148 * acpi_pm_prepare - Prepare the platform to enter the target sleep
149 * state and disable the GPEs.
150 */
151static int acpi_pm_prepare(void)
152{
153 int error = __acpi_pm_prepare();
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200154 if (!error)
Jiri Slaby26fcaf62011-01-07 01:42:31 +0100155 error = acpi_pm_pre_suspend();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200156
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200157 return error;
158}
159
160/**
161 * acpi_pm_finish - Instruct the platform to leave a sleep state.
162 *
163 * This is called after we wake back up (or if entering the sleep state
164 * failed).
165 */
166static void acpi_pm_finish(void)
167{
168 u32 acpi_state = acpi_target_sleep_state;
169
Len Brown42de5532010-06-12 01:15:40 -0400170 acpi_ec_unblock_transactions();
Rafael J. Wysockid551d812011-01-19 22:27:55 +0100171 suspend_nvs_free();
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400172
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200173 if (acpi_state == ACPI_STATE_S0)
174 return;
175
176 printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
177 acpi_state);
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -0400178 acpi_disable_wakeup_devices(acpi_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200179 acpi_leave_sleep_state(acpi_state);
180
181 /* reset firmware waking vector */
182 acpi_set_firmware_waking_vector((acpi_physical_address) 0);
183
184 acpi_target_sleep_state = ACPI_STATE_S0;
185}
186
187/**
188 * acpi_pm_end - Finish up suspend sequence.
189 */
190static void acpi_pm_end(void)
191{
192 /*
193 * This is necessary in case acpi_pm_finish() is not called during a
194 * failing transition to a sleep state.
195 */
196 acpi_target_sleep_state = ACPI_STATE_S0;
Zhao Yakuie49f7112008-08-12 10:20:22 +0800197 acpi_sleep_tts_switch(acpi_target_sleep_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200198}
Rafael J. Wysocki92daa7b2008-10-23 21:46:43 +0200199#else /* !CONFIG_ACPI_SLEEP */
200#define acpi_target_sleep_state ACPI_STATE_S0
Rafael J. Wysocki5d1e0722008-10-22 14:58:43 -0400201#endif /* CONFIG_ACPI_SLEEP */
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200202
203#ifdef CONFIG_SUSPEND
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204static u32 acpi_suspend_states[] = {
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500205 [PM_SUSPEND_ON] = ACPI_STATE_S0,
206 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
207 [PM_SUSPEND_MEM] = ACPI_STATE_S3,
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500208 [PM_SUSPEND_MAX] = ACPI_STATE_S5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209};
210
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200211/**
Len Brown2c6e33c2008-04-23 18:02:52 -0400212 * acpi_suspend_begin - Set the target system sleep state to the state
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200213 * associated with given @pm_state, if supported.
214 */
Len Brown2c6e33c2008-04-23 18:02:52 -0400215static int acpi_suspend_begin(suspend_state_t pm_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
217 u32 acpi_state = acpi_suspend_states[pm_state];
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200218 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200220 error = nvs_nosave ? 0 : suspend_nvs_alloc();
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400221 if (error)
222 return error;
223
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200224 if (sleep_states[acpi_state]) {
225 acpi_target_sleep_state = acpi_state;
Zhao Yakuie49f7112008-08-12 10:20:22 +0800226 acpi_sleep_tts_switch(acpi_target_sleep_state);
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200227 } else {
228 printk(KERN_ERR "ACPI does not support this state: %d\n",
229 pm_state);
230 error = -ENOSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 }
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200232 return error;
233}
234
235/**
Len Brown2c6e33c2008-04-23 18:02:52 -0400236 * acpi_suspend_enter - Actually enter a sleep state.
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200237 * @pm_state: ignored
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 *
Rafael J. Wysocki50ad1472007-07-24 11:58:39 +0200239 * Flush caches and go to sleep. For STR we have to call arch-specific
240 * assembly, which in turn call acpi_enter_sleep_state().
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 * It's unfortunate, but it works. Please fix if you're feeling frisky.
242 */
Len Brown2c6e33c2008-04-23 18:02:52 -0400243static int acpi_suspend_enter(suspend_state_t pm_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 acpi_status status = AE_OK;
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200246 u32 acpi_state = acpi_target_sleep_state;
Rafael J. Wysocki979f11b2011-02-08 23:42:09 +0100247 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 ACPI_FLUSH_CPU_CACHE();
250
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200251 switch (acpi_state) {
252 case ACPI_STATE_S1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 barrier();
254 status = acpi_enter_sleep_state(acpi_state);
255 break;
256
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200257 case ACPI_STATE_S3:
Rafael J. Wysockif1a20032011-02-08 23:42:22 +0100258 error = acpi_suspend_lowlevel();
Rafael J. Wysocki979f11b2011-02-08 23:42:09 +0100259 if (error)
260 return error;
Rafael J. Wysocki7a63f082011-02-08 23:41:57 +0100261 pr_info(PREFIX "Low-level resume complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 }
Arnaud Patard872d83d2006-04-27 05:25:00 -0400264
Matthew Garrettb6dacf62010-05-11 13:49:25 -0400265 /* This violates the spec but is required for bug compatibility. */
266 acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
Rafael J. Wysocki65df7842008-11-26 17:53:13 -0500267
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100268 /* Reprogram control registers and execute _BFS */
269 acpi_leave_sleep_state_prep(acpi_state);
270
Pavel Machek23b168d2008-02-05 19:27:12 +0100271 /* ACPI 3.0 specs (P62) says that it's the responsibility
Arnaud Patard872d83d2006-04-27 05:25:00 -0400272 * of the OSPM to clear the status bit [ implying that the
273 * POWER_BUTTON event should not reach userspace ]
274 */
275 if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3))
276 acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
277
Shaohua Lia3627f62007-06-20 09:17:58 +0800278 /*
279 * Disable and clear GPE status before interrupt is enabled. Some GPEs
280 * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
281 * acpi_leave_sleep_state will reenable specific GPEs later
282 */
Lin Ming3d97e422008-12-16 16:57:46 +0800283 acpi_disable_all_gpes();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200284 /* Allow EC transactions to happen. */
Rafael J. Wysockife955682010-04-09 01:40:38 +0200285 acpi_ec_unblock_transactions_early();
Shaohua Lia3627f62007-06-20 09:17:58 +0800286
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400287 suspend_nvs_restore();
288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
290}
291
Len Brown2c6e33c2008-04-23 18:02:52 -0400292static int acpi_suspend_state_valid(suspend_state_t pm_state)
Shaohua Lieb9289e2005-10-30 15:00:01 -0800293{
Johannes Berge8c9c502007-04-30 15:09:54 -0700294 u32 acpi_state;
Shaohua Lieb9289e2005-10-30 15:00:01 -0800295
Johannes Berge8c9c502007-04-30 15:09:54 -0700296 switch (pm_state) {
297 case PM_SUSPEND_ON:
298 case PM_SUSPEND_STANDBY:
299 case PM_SUSPEND_MEM:
300 acpi_state = acpi_suspend_states[pm_state];
301
302 return sleep_states[acpi_state];
303 default:
304 return 0;
305 }
Shaohua Lieb9289e2005-10-30 15:00:01 -0800306}
307
Lionel Debroux2f55ac02010-11-16 14:14:02 +0100308static const struct platform_suspend_ops acpi_suspend_ops = {
Len Brown2c6e33c2008-04-23 18:02:52 -0400309 .valid = acpi_suspend_state_valid,
310 .begin = acpi_suspend_begin,
Rafael J. Wysocki6a7c7ea2009-04-19 20:08:42 +0200311 .prepare_late = acpi_pm_prepare,
Len Brown2c6e33c2008-04-23 18:02:52 -0400312 .enter = acpi_suspend_enter,
Rafael J. Wysocki618d7fd2010-07-02 00:14:57 +0200313 .wake = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200314 .end = acpi_pm_end,
315};
316
317/**
318 * acpi_suspend_begin_old - Set the target system sleep state to the
319 * state associated with given @pm_state, if supported, and
320 * execute the _PTS control method. This function is used if the
321 * pre-ACPI 2.0 suspend ordering has been requested.
322 */
323static int acpi_suspend_begin_old(suspend_state_t pm_state)
324{
325 int error = acpi_suspend_begin(pm_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200326 if (!error)
327 error = __acpi_pm_prepare();
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200328
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200329 return error;
330}
331
332/*
333 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
334 * been requested.
335 */
Lionel Debroux2f55ac02010-11-16 14:14:02 +0100336static const struct platform_suspend_ops acpi_suspend_ops_old = {
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200337 .valid = acpi_suspend_state_valid,
338 .begin = acpi_suspend_begin_old,
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200339 .prepare_late = acpi_pm_pre_suspend,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200340 .enter = acpi_suspend_enter,
Rafael J. Wysocki618d7fd2010-07-02 00:14:57 +0200341 .wake = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200342 .end = acpi_pm_end,
343 .recover = acpi_pm_finish,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344};
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700345
346static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
347{
348 old_suspend_ordering = true;
349 return 0;
350}
351
Rafael J. Wysocki53998642010-09-24 16:46:14 -0400352static int __init init_nvs_nosave(const struct dmi_system_id *d)
353{
354 acpi_nvs_nosave();
355 return 0;
356}
357
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700358static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
359 {
360 .callback = init_old_suspend_ordering,
361 .ident = "Abit KN9 (nForce4 variant)",
362 .matches = {
363 DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
364 DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
365 },
366 },
Rafael J. Wysocki4fb507b2008-10-14 22:54:06 +0200367 {
368 .callback = init_old_suspend_ordering,
369 .ident = "HP xw4600 Workstation",
370 .matches = {
371 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
372 DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
373 },
374 },
Rafael J. Wysocki65df7842008-11-26 17:53:13 -0500375 {
Andy Whitcrofta1404492009-02-11 18:11:22 +0000376 .callback = init_old_suspend_ordering,
377 .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
378 .matches = {
379 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
380 DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
381 },
382 },
Zhang Rui45e77982009-03-15 22:13:44 -0400383 {
Zhao Yakui2a9ef8e2009-03-18 16:36:25 +0800384 .callback = init_old_suspend_ordering,
385 .ident = "Panasonic CF51-2L",
386 .matches = {
387 DMI_MATCH(DMI_BOARD_VENDOR,
388 "Matsushita Electric Industrial Co.,Ltd."),
389 DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
390 },
391 },
Rafael J. Wysocki53998642010-09-24 16:46:14 -0400392 {
393 .callback = init_nvs_nosave,
Dave Jonesd11c78e2011-10-19 23:15:11 +0200394 .ident = "Sony Vaio VGN-FW21E",
395 .matches = {
396 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
397 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"),
398 },
399 },
400 {
401 .callback = init_nvs_nosave,
Dave Jonesddf6ce42011-11-03 00:58:59 +0100402 .ident = "Sony Vaio VPCEB17FX",
403 .matches = {
404 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
405 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"),
406 },
407 },
408 {
409 .callback = init_nvs_nosave,
Rafael J. Wysocki53998642010-09-24 16:46:14 -0400410 .ident = "Sony Vaio VGN-SR11M",
411 .matches = {
412 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
413 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),
414 },
415 },
416 {
417 .callback = init_nvs_nosave,
418 .ident = "Everex StepNote Series",
419 .matches = {
420 DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),
421 DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),
422 },
423 },
Rafael J. Wysockiaf489312010-10-17 21:01:21 +0200424 {
425 .callback = init_nvs_nosave,
426 .ident = "Sony Vaio VPCEB1Z1E",
427 .matches = {
428 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
429 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),
430 },
431 },
Rafael J. Wysocki291a73c2010-12-12 21:10:42 +0100432 {
433 .callback = init_nvs_nosave,
434 .ident = "Sony Vaio VGN-NW130D",
435 .matches = {
436 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
437 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),
438 },
439 },
Rafael J. Wysocki7b330702011-01-06 23:37:01 +0100440 {
441 .callback = init_nvs_nosave,
Lan Tianyu93f77082012-01-21 09:23:56 +0800442 .ident = "Sony Vaio VPCCW29FX",
443 .matches = {
444 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
445 DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"),
446 },
447 },
448 {
449 .callback = init_nvs_nosave,
Rafael J. Wysocki7b330702011-01-06 23:37:01 +0100450 .ident = "Averatec AV1020-ED2",
451 .matches = {
452 DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"),
453 DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"),
454 },
455 },
Zhang Ruibb0c5ed2011-07-30 01:40:48 -0400456 {
457 .callback = init_old_suspend_ordering,
458 .ident = "Asus A8N-SLI DELUXE",
459 .matches = {
460 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
461 DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"),
462 },
463 },
464 {
465 .callback = init_old_suspend_ordering,
466 .ident = "Asus A8N-SLI Premium",
467 .matches = {
468 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
469 DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"),
470 },
471 },
Rafael J. Wysocki89e8ea12011-10-06 20:35:03 +0200472 {
473 .callback = init_nvs_nosave,
474 .ident = "Sony Vaio VGN-SR26GN_P",
475 .matches = {
476 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
477 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"),
478 },
479 },
Bogdan Radulescu731b25a2011-10-06 20:35:12 +0200480 {
481 .callback = init_nvs_nosave,
482 .ident = "Sony Vaio VGN-FW520F",
483 .matches = {
484 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
485 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"),
486 },
487 },
Keng-Yu Lin5a50a7c2011-12-02 00:04:23 +0100488 {
489 .callback = init_nvs_nosave,
490 .ident = "Asus K54C",
491 .matches = {
492 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
493 DMI_MATCH(DMI_PRODUCT_NAME, "K54C"),
494 },
495 },
496 {
497 .callback = init_nvs_nosave,
498 .ident = "Asus K54HR",
499 .matches = {
500 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
501 DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"),
502 },
503 },
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700504 {},
505};
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200506#endif /* CONFIG_SUSPEND */
507
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200508#ifdef CONFIG_HIBERNATION
Shaohua Libdfe6b72008-07-23 21:28:41 -0700509static unsigned long s4_hardware_signature;
510static struct acpi_table_facs *facs;
511static bool nosigcheck;
512
513void __init acpi_no_s4_hw_signature(void)
514{
515 nosigcheck = true;
516}
517
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100518static int acpi_hibernation_begin(void)
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700519{
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100520 int error;
521
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200522 error = nvs_nosave ? 0 : suspend_nvs_alloc();
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100523 if (!error) {
524 acpi_target_sleep_state = ACPI_STATE_S4;
525 acpi_sleep_tts_switch(acpi_target_sleep_state);
526 }
527
528 return error;
529}
530
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700531static int acpi_hibernation_enter(void)
532{
533 acpi_status status = AE_OK;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700534
535 ACPI_FLUSH_CPU_CACHE();
536
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700537 /* This shouldn't return. If it returns, we have a problem */
538 status = acpi_enter_sleep_state(ACPI_STATE_S4);
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100539 /* Reprogram control registers and execute _BFS */
540 acpi_leave_sleep_state_prep(ACPI_STATE_S4);
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700541
542 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
543}
544
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700545static void acpi_hibernation_leave(void)
546{
547 /*
548 * If ACPI is not enabled by the BIOS and the boot kernel, we need to
549 * enable it here.
550 */
551 acpi_enable();
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100552 /* Reprogram control registers and execute _BFS */
553 acpi_leave_sleep_state_prep(ACPI_STATE_S4);
Shaohua Libdfe6b72008-07-23 21:28:41 -0700554 /* Check the hardware signature */
555 if (facs && s4_hardware_signature != facs->hardware_signature) {
556 printk(KERN_EMERG "ACPI: Hardware changed while hibernated, "
557 "cannot resume!\n");
558 panic("ACPI S4 hardware signature mismatch");
559 }
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100560 /* Restore the NVS memory area */
Matthew Garrettdd4c4f12010-05-28 16:32:14 -0400561 suspend_nvs_restore();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200562 /* Allow EC transactions to happen. */
Rafael J. Wysockife955682010-04-09 01:40:38 +0200563 acpi_ec_unblock_transactions_early();
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700564}
565
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200566static void acpi_pm_thaw(void)
Rafael J. Wysockif6bb13a2010-03-04 01:52:58 +0100567{
Rafael J. Wysockife955682010-04-09 01:40:38 +0200568 acpi_ec_unblock_transactions();
Lin Ming3d97e422008-12-16 16:57:46 +0800569 acpi_enable_all_runtime_gpes();
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700570}
571
Lionel Debroux073ef1f2010-11-09 21:48:49 +0100572static const struct platform_hibernation_ops acpi_hibernation_ops = {
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100573 .begin = acpi_hibernation_begin,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200574 .end = acpi_pm_end,
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200575 .pre_snapshot = acpi_pm_prepare,
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400576 .finish = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200577 .prepare = acpi_pm_prepare,
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700578 .enter = acpi_hibernation_enter,
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700579 .leave = acpi_hibernation_leave,
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200580 .pre_restore = acpi_pm_freeze,
581 .restore_cleanup = acpi_pm_thaw,
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700582};
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200583
584/**
585 * acpi_hibernation_begin_old - Set the target system sleep state to
586 * ACPI_STATE_S4 and execute the _PTS control method. This
587 * function is used if the pre-ACPI 2.0 suspend ordering has been
588 * requested.
589 */
590static int acpi_hibernation_begin_old(void)
591{
Zhao Yakuie49f7112008-08-12 10:20:22 +0800592 int error;
593 /*
594 * The _TTS object should always be evaluated before the _PTS object.
595 * When the old_suspended_ordering is true, the _PTS object is
596 * evaluated in the acpi_sleep_prepare.
597 */
598 acpi_sleep_tts_switch(ACPI_STATE_S4);
599
600 error = acpi_sleep_prepare(ACPI_STATE_S4);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200601
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100602 if (!error) {
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200603 if (!nvs_nosave)
Matthew Garrettdd4c4f12010-05-28 16:32:14 -0400604 error = suspend_nvs_alloc();
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100605 if (!error)
606 acpi_target_sleep_state = ACPI_STATE_S4;
607 }
608 return error;
609}
610
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200611/*
612 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
613 * been requested.
614 */
Lionel Debroux073ef1f2010-11-09 21:48:49 +0100615static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200616 .begin = acpi_hibernation_begin_old,
617 .end = acpi_pm_end,
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200618 .pre_snapshot = acpi_pm_pre_suspend,
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200619 .prepare = acpi_pm_freeze,
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400620 .finish = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200621 .enter = acpi_hibernation_enter,
622 .leave = acpi_hibernation_leave,
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200623 .pre_restore = acpi_pm_freeze,
624 .restore_cleanup = acpi_pm_thaw,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200625 .recover = acpi_pm_finish,
626};
627#endif /* CONFIG_HIBERNATION */
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700628
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200629int acpi_suspend(u32 acpi_state)
630{
631 suspend_state_t states[] = {
632 [1] = PM_SUSPEND_STANDBY,
633 [3] = PM_SUSPEND_MEM,
634 [5] = PM_SUSPEND_MAX
635 };
636
637 if (acpi_state < 6 && states[acpi_state])
638 return pm_suspend(states[acpi_state]);
639 if (acpi_state == 4)
640 return hibernate();
641 return -EINVAL;
642}
643
Rafael J. Wysockiaa338602011-02-11 00:06:54 +0100644#ifdef CONFIG_PM
Shaohua Lifd4aff12007-07-17 22:40:25 +0200645/**
646 * acpi_pm_device_sleep_state - return preferred power state of ACPI device
647 * in the system sleep state given by %acpi_target_sleep_state
David Brownell2fe2de52008-06-05 01:15:40 +0200648 * @dev: device to examine; its driver model wakeup flags control
649 * whether it should be able to wake up the system
Shaohua Lifd4aff12007-07-17 22:40:25 +0200650 * @d_min_p: used to store the upper limit of allowed states range
651 * Return value: preferred power state of the device on success, -ENODEV on
652 * failure (ie. if there's no 'struct acpi_device' for @dev)
653 *
654 * Find the lowest power (highest number) ACPI device power state that
655 * device @dev can be in while the system is in the sleep state represented
656 * by %acpi_target_sleep_state. If @wake is nonzero, the device should be
657 * able to wake up the system from this sleep state. If @d_min_p is set,
658 * the highest power (lowest number) device power state of @dev allowed
659 * in this system sleep state is stored at the location pointed to by it.
660 *
661 * The caller must ensure that @dev is valid before using this function.
662 * The caller is also responsible for figuring out if the device is
663 * supposed to be able to wake up the system and passing this information
664 * via @wake.
665 */
666
David Brownell2fe2de52008-06-05 01:15:40 +0200667int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p)
Shaohua Lifd4aff12007-07-17 22:40:25 +0200668{
669 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
670 struct acpi_device *adev;
671 char acpi_method[] = "_SxD";
Matthew Wilcox27663c52008-10-10 02:22:59 -0400672 unsigned long long d_min, d_max;
Shaohua Lifd4aff12007-07-17 22:40:25 +0200673
674 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
Shaohua Liead77592007-08-23 15:01:13 +0800675 printk(KERN_DEBUG "ACPI handle has no context!\n");
Shaohua Lifd4aff12007-07-17 22:40:25 +0200676 return -ENODEV;
677 }
678
679 acpi_method[2] = '0' + acpi_target_sleep_state;
680 /*
681 * If the sleep state is S0, we will return D3, but if the device has
682 * _S0W, we will use the value from _S0W
683 */
684 d_min = ACPI_STATE_D0;
685 d_max = ACPI_STATE_D3;
686
687 /*
688 * If present, _SxD methods return the minimum D-state (highest power
689 * state) we can use for the corresponding S-states. Otherwise, the
690 * minimum D-state is D0 (ACPI 3.x).
691 *
692 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
693 * provided -- that's our fault recovery, we ignore retval.
694 */
695 if (acpi_target_sleep_state > ACPI_STATE_S0)
696 acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
697
698 /*
699 * If _PRW says we can wake up the system from the target sleep state,
700 * the D-state returned by _SxD is sufficient for that (we assume a
701 * wakeup-aware driver if wake is set). Still, if _SxW exists
702 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
703 * can wake the system. _S0W may be valid, too.
704 */
705 if (acpi_target_sleep_state == ACPI_STATE_S0 ||
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200706 (device_may_wakeup(dev) &&
Shaohua Lifd4aff12007-07-17 22:40:25 +0200707 adev->wakeup.sleep_state <= acpi_target_sleep_state)) {
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100708 acpi_status status;
709
Shaohua Lifd4aff12007-07-17 22:40:25 +0200710 acpi_method[3] = 'W';
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100711 status = acpi_evaluate_integer(handle, acpi_method, NULL,
712 &d_max);
713 if (ACPI_FAILURE(status)) {
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200714 if (acpi_target_sleep_state != ACPI_STATE_S0 ||
715 status != AE_NOT_FOUND)
716 d_max = d_min;
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100717 } else if (d_max < d_min) {
718 /* Warn the user of the broken DSDT */
719 printk(KERN_WARNING "ACPI: Wrong value from %s\n",
720 acpi_method);
721 /* Sanitize it */
Shaohua Lifd4aff12007-07-17 22:40:25 +0200722 d_min = d_max;
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100723 }
Shaohua Lifd4aff12007-07-17 22:40:25 +0200724 }
725
726 if (d_min_p)
727 *d_min_p = d_min;
728 return d_max;
729}
Rafael J. Wysockiaa338602011-02-11 00:06:54 +0100730#endif /* CONFIG_PM */
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200731
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200732#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200733/**
Lin Mingb24e5092012-03-27 15:43:25 +0800734 * acpi_pm_device_run_wake - Enable/disable wake-up for given device.
735 * @phys_dev: Device to enable/disable the platform to wake-up the system for.
736 * @enable: Whether enable or disable the wake-up functionality.
737 *
738 * Find the ACPI device object corresponding to @pci_dev and try to
739 * enable/disable the GPE associated with it.
740 */
741int acpi_pm_device_run_wake(struct device *phys_dev, bool enable)
742{
743 struct acpi_device *dev;
744 acpi_handle handle;
745
746 if (!device_run_wake(phys_dev))
747 return -EINVAL;
748
749 handle = DEVICE_ACPI_HANDLE(phys_dev);
750 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &dev))) {
751 dev_dbg(phys_dev, "ACPI handle has no context in %s!\n",
752 __func__);
753 return -ENODEV;
754 }
755
756 if (enable) {
757 acpi_enable_wakeup_device_power(dev, ACPI_STATE_S0);
758 acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number);
759 } else {
760 acpi_disable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number);
761 acpi_disable_wakeup_device_power(dev);
762 }
763
764 return 0;
765}
766
767/**
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200768 * acpi_pm_device_sleep_wake - enable or disable the system wake-up
769 * capability of given device
770 * @dev: device to handle
771 * @enable: 'true' - enable, 'false' - disable the wake-up capability
772 */
773int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
774{
775 acpi_handle handle;
776 struct acpi_device *adev;
Rafael J. Wysockidf8db912009-09-08 23:13:49 +0200777 int error;
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200778
Rafael J. Wysocki0baed8d2009-09-08 23:16:24 +0200779 if (!device_can_wakeup(dev))
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200780 return -EINVAL;
781
782 handle = DEVICE_ACPI_HANDLE(dev);
783 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
Rafael J. Wysockidf8db912009-09-08 23:13:49 +0200784 dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__);
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200785 return -ENODEV;
786 }
787
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +0200788 error = enable ?
789 acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
790 acpi_disable_wakeup_device_power(adev);
Rafael J. Wysockidf8db912009-09-08 23:13:49 +0200791 if (!error)
792 dev_info(dev, "wake-up capability %s by ACPI\n",
793 enable ? "enabled" : "disabled");
794
795 return error;
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200796}
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200797#endif /* CONFIG_PM_SLEEP */
Shaohua Lifd4aff12007-07-17 22:40:25 +0200798
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400799static void acpi_power_off_prepare(void)
800{
801 /* Prepare to power off the system */
802 acpi_sleep_prepare(ACPI_STATE_S5);
Lin Ming3d97e422008-12-16 16:57:46 +0800803 acpi_disable_all_gpes();
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400804}
805
806static void acpi_power_off(void)
807{
808 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
Frank Seidel4d939152009-02-04 17:03:07 +0100809 printk(KERN_DEBUG "%s called\n", __func__);
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400810 local_irq_disable();
811 acpi_enter_sleep_state(ACPI_STATE_S5);
812}
813
Len Brown96f15ef2009-04-17 23:32:20 -0400814/*
815 * ACPI 2.0 created the optional _GTS and _BFS,
816 * but industry adoption has been neither rapid nor broad.
817 *
818 * Linux gets into trouble when it executes poorly validated
819 * paths through the BIOS, so disable _GTS and _BFS by default,
820 * but do speak up and offer the option to enable them.
821 */
Stephen Hemminger01eac602010-10-18 18:47:25 -0700822static void __init acpi_gts_bfs_check(void)
Len Brown96f15ef2009-04-17 23:32:20 -0400823{
824 acpi_handle dummy;
825
826 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__GTS, &dummy)))
827 {
828 printk(KERN_NOTICE PREFIX "BIOS offers _GTS\n");
829 printk(KERN_NOTICE PREFIX "If \"acpi.gts=1\" improves suspend, "
830 "please notify linux-acpi@vger.kernel.org\n");
831 }
832 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__BFS, &dummy)))
833 {
834 printk(KERN_NOTICE PREFIX "BIOS offers _BFS\n");
835 printk(KERN_NOTICE PREFIX "If \"acpi.bfs=1\" improves resume, "
836 "please notify linux-acpi@vger.kernel.org\n");
837 }
838}
839
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500840int __init acpi_sleep_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200842 acpi_status status;
843 u8 type_a, type_b;
844#ifdef CONFIG_SUSPEND
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500845 int i = 0;
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700846
847 dmi_check_system(acpisleep_dmi_table);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200848#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
850 if (acpi_disabled)
851 return 0;
852
Frans Pop5a50fe72007-09-20 22:27:44 +0200853 sleep_states[ACPI_STATE_S0] = 1;
854 printk(KERN_INFO PREFIX "(supports S0");
855
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200856#ifdef CONFIG_SUSPEND
Frans Pop5a50fe72007-09-20 22:27:44 +0200857 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
859 if (ACPI_SUCCESS(status)) {
860 sleep_states[i] = 1;
861 printk(" S%d", i);
862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200865 suspend_set_ops(old_suspend_ordering ?
866 &acpi_suspend_ops_old : &acpi_suspend_ops);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200867#endif
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700868
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200869#ifdef CONFIG_HIBERNATION
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200870 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
871 if (ACPI_SUCCESS(status)) {
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200872 hibernation_set_ops(old_suspend_ordering ?
873 &acpi_hibernation_ops_old : &acpi_hibernation_ops);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200874 sleep_states[ACPI_STATE_S4] = 1;
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400875 printk(" S4");
Shaohua Libdfe6b72008-07-23 21:28:41 -0700876 if (!nosigcheck) {
Lin Ming3d97e422008-12-16 16:57:46 +0800877 acpi_get_table(ACPI_SIG_FACS, 1,
Shaohua Libdfe6b72008-07-23 21:28:41 -0700878 (struct acpi_table_header **)&facs);
879 if (facs)
880 s4_hardware_signature =
881 facs->hardware_signature;
882 }
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200883 }
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700884#endif
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400885 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
886 if (ACPI_SUCCESS(status)) {
887 sleep_states[ACPI_STATE_S5] = 1;
888 printk(" S5");
889 pm_power_off_prepare = acpi_power_off_prepare;
890 pm_power_off = acpi_power_off;
891 }
892 printk(")\n");
Zhao Yakuie49f7112008-08-12 10:20:22 +0800893 /*
894 * Register the tts_notifier to reboot notifier list so that the _TTS
895 * object can also be evaluated when the system enters S5.
896 */
897 register_reboot_notifier(&tts_notifier);
Len Brown96f15ef2009-04-17 23:32:20 -0400898 acpi_gts_bfs_check();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 return 0;
900}