blob: acf81fe86b5362cdac84044b3d6e67cb9bdc154a [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 Minga2ef5c42012-03-21 10:58:46 +080020#include <linux/module.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
Lin Minga2ef5c42012-03-21 10:58:46 +080030static unsigned int gts, bfs;
31module_param(gts, uint, 0644);
32module_param(bfs, uint, 0644);
33MODULE_PARM_DESC(gts, "Enable evaluation of _GTS on suspend.");
34MODULE_PARM_DESC(bfs, "Enable evaluation of _BFS on resume".);
35
36static u8 wake_sleep_flags(void)
37{
38 u8 flags = ACPI_NO_OPTIONAL_METHODS;
39
40 if (gts)
41 flags |= ACPI_EXECUTE_GTS;
42 if (bfs)
43 flags |= ACPI_EXECUTE_BFS;
44
45 return flags;
46}
47
Stephen Hemminger01eac602010-10-18 18:47:25 -070048static u8 sleep_states[ACPI_S_STATE_COUNT];
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Zhao Yakuie49f7112008-08-12 10:20:22 +080050static void acpi_sleep_tts_switch(u32 acpi_state)
51{
52 union acpi_object in_arg = { ACPI_TYPE_INTEGER };
53 struct acpi_object_list arg_list = { 1, &in_arg };
54 acpi_status status = AE_OK;
55
56 in_arg.integer.value = acpi_state;
57 status = acpi_evaluate_object(NULL, "\\_TTS", &arg_list, NULL);
58 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
59 /*
60 * OS can't evaluate the _TTS object correctly. Some warning
61 * message will be printed. But it won't break anything.
62 */
63 printk(KERN_NOTICE "Failure in evaluating _TTS object\n");
64 }
65}
66
67static int tts_notify_reboot(struct notifier_block *this,
68 unsigned long code, void *x)
69{
70 acpi_sleep_tts_switch(ACPI_STATE_S5);
71 return NOTIFY_DONE;
72}
73
74static struct notifier_block tts_notifier = {
75 .notifier_call = tts_notify_reboot,
76 .next = NULL,
77 .priority = 0,
78};
79
Rafael J. Wysockic9b6c8f2008-01-08 00:10:57 +010080static int acpi_sleep_prepare(u32 acpi_state)
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020081{
82#ifdef CONFIG_ACPI_SLEEP
83 /* do we have a wakeup address for S2 and S3? */
84 if (acpi_state == ACPI_STATE_S3) {
85 if (!acpi_wakeup_address) {
86 return -EFAULT;
87 }
H. Peter Anvin4b4f7282008-06-24 23:03:48 +020088 acpi_set_firmware_waking_vector(
89 (acpi_physical_address)acpi_wakeup_address);
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020090
91 }
92 ACPI_FLUSH_CPU_CACHE();
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020093#endif
Rafael J. Wysockic9b6c8f2008-01-08 00:10:57 +010094 printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
95 acpi_state);
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040096 acpi_enable_wakeup_devices(acpi_state);
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020097 acpi_enter_sleep_state_prep(acpi_state);
98 return 0;
99}
100
Rafael J. Wysocki5d1e0722008-10-22 14:58:43 -0400101#ifdef CONFIG_ACPI_SLEEP
Jan Beulich091aad62010-12-07 14:52:25 +0000102static u32 acpi_target_sleep_state = ACPI_STATE_S0;
103
Zhang Ruid7f0eea2009-12-30 15:36:42 +0800104/*
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200105 * The ACPI specification wants us to save NVS memory regions during hibernation
106 * and to restore them during the subsequent resume. Windows does that also for
107 * suspend to RAM. However, it is known that this mechanism does not work on
108 * all machines, so we allow the user to disable it with the help of the
109 * 'acpi_sleep=nonvs' kernel command line option.
110 */
111static bool nvs_nosave;
112
113void __init acpi_nvs_nosave(void)
114{
115 nvs_nosave = true;
116}
117
118/*
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200119 * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
120 * user to request that behavior by using the 'acpi_old_suspend_ordering'
121 * kernel command line option that causes the following variable to be set.
122 */
123static bool old_suspend_ordering;
124
125void __init acpi_old_suspend_ordering(void)
126{
127 old_suspend_ordering = true;
128}
129
130/**
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200131 * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200132 */
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200133static int acpi_pm_freeze(void)
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200134{
Lin Ming3d97e422008-12-16 16:57:46 +0800135 acpi_disable_all_gpes();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200136 acpi_os_wait_events_complete(NULL);
Rafael J. Wysockife955682010-04-09 01:40:38 +0200137 acpi_ec_block_transactions();
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200138 return 0;
139}
140
141/**
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200142 * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
143 */
144static int acpi_pm_pre_suspend(void)
145{
146 acpi_pm_freeze();
Jiri Slaby26fcaf62011-01-07 01:42:31 +0100147 return suspend_nvs_save();
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200148}
149
150/**
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200151 * __acpi_pm_prepare - Prepare the platform to enter the target state.
152 *
153 * If necessary, set the firmware waking vector and do arch-specific
154 * nastiness to get the wakeup code to the waking vector.
155 */
156static int __acpi_pm_prepare(void)
157{
158 int error = acpi_sleep_prepare(acpi_target_sleep_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200159 if (error)
160 acpi_target_sleep_state = ACPI_STATE_S0;
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200161
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200162 return error;
163}
164
165/**
166 * acpi_pm_prepare - Prepare the platform to enter the target sleep
167 * state and disable the GPEs.
168 */
169static int acpi_pm_prepare(void)
170{
171 int error = __acpi_pm_prepare();
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200172 if (!error)
Jiri Slaby26fcaf62011-01-07 01:42:31 +0100173 error = acpi_pm_pre_suspend();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200174
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200175 return error;
176}
177
178/**
179 * acpi_pm_finish - Instruct the platform to leave a sleep state.
180 *
181 * This is called after we wake back up (or if entering the sleep state
182 * failed).
183 */
184static void acpi_pm_finish(void)
185{
186 u32 acpi_state = acpi_target_sleep_state;
187
Len Brown42de5532010-06-12 01:15:40 -0400188 acpi_ec_unblock_transactions();
Rafael J. Wysockid551d812011-01-19 22:27:55 +0100189 suspend_nvs_free();
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400190
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200191 if (acpi_state == ACPI_STATE_S0)
192 return;
193
194 printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
195 acpi_state);
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -0400196 acpi_disable_wakeup_devices(acpi_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200197 acpi_leave_sleep_state(acpi_state);
198
199 /* reset firmware waking vector */
200 acpi_set_firmware_waking_vector((acpi_physical_address) 0);
201
202 acpi_target_sleep_state = ACPI_STATE_S0;
203}
204
205/**
206 * acpi_pm_end - Finish up suspend sequence.
207 */
208static void acpi_pm_end(void)
209{
210 /*
211 * This is necessary in case acpi_pm_finish() is not called during a
212 * failing transition to a sleep state.
213 */
214 acpi_target_sleep_state = ACPI_STATE_S0;
Zhao Yakuie49f7112008-08-12 10:20:22 +0800215 acpi_sleep_tts_switch(acpi_target_sleep_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200216}
Rafael J. Wysocki92daa7b2008-10-23 21:46:43 +0200217#else /* !CONFIG_ACPI_SLEEP */
218#define acpi_target_sleep_state ACPI_STATE_S0
Rafael J. Wysocki5d1e0722008-10-22 14:58:43 -0400219#endif /* CONFIG_ACPI_SLEEP */
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200220
221#ifdef CONFIG_SUSPEND
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222static u32 acpi_suspend_states[] = {
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500223 [PM_SUSPEND_ON] = ACPI_STATE_S0,
224 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
225 [PM_SUSPEND_MEM] = ACPI_STATE_S3,
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500226 [PM_SUSPEND_MAX] = ACPI_STATE_S5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227};
228
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200229/**
Len Brown2c6e33c2008-04-23 18:02:52 -0400230 * acpi_suspend_begin - Set the target system sleep state to the state
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200231 * associated with given @pm_state, if supported.
232 */
Len Brown2c6e33c2008-04-23 18:02:52 -0400233static int acpi_suspend_begin(suspend_state_t pm_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
235 u32 acpi_state = acpi_suspend_states[pm_state];
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200236 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200238 error = nvs_nosave ? 0 : suspend_nvs_alloc();
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400239 if (error)
240 return error;
241
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200242 if (sleep_states[acpi_state]) {
243 acpi_target_sleep_state = acpi_state;
Zhao Yakuie49f7112008-08-12 10:20:22 +0800244 acpi_sleep_tts_switch(acpi_target_sleep_state);
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200245 } else {
246 printk(KERN_ERR "ACPI does not support this state: %d\n",
247 pm_state);
248 error = -ENOSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200250 return error;
251}
252
253/**
Len Brown2c6e33c2008-04-23 18:02:52 -0400254 * acpi_suspend_enter - Actually enter a sleep state.
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200255 * @pm_state: ignored
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 *
Rafael J. Wysocki50ad1472007-07-24 11:58:39 +0200257 * Flush caches and go to sleep. For STR we have to call arch-specific
258 * assembly, which in turn call acpi_enter_sleep_state().
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 * It's unfortunate, but it works. Please fix if you're feeling frisky.
260 */
Len Brown2c6e33c2008-04-23 18:02:52 -0400261static int acpi_suspend_enter(suspend_state_t pm_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
263 acpi_status status = AE_OK;
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200264 u32 acpi_state = acpi_target_sleep_state;
Lin Minga2ef5c42012-03-21 10:58:46 +0800265 u8 flags = wake_sleep_flags();
Rafael J. Wysocki979f11b2011-02-08 23:42:09 +0100266 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 ACPI_FLUSH_CPU_CACHE();
269
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200270 switch (acpi_state) {
271 case ACPI_STATE_S1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 barrier();
Lin Minga2ef5c42012-03-21 10:58:46 +0800273 status = acpi_enter_sleep_state(acpi_state, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 break;
275
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200276 case ACPI_STATE_S3:
Rafael J. Wysockif1a20032011-02-08 23:42:22 +0100277 error = acpi_suspend_lowlevel();
Rafael J. Wysocki979f11b2011-02-08 23:42:09 +0100278 if (error)
279 return error;
Rafael J. Wysocki7a63f082011-02-08 23:41:57 +0100280 pr_info(PREFIX "Low-level resume complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 }
Arnaud Patard872d83d2006-04-27 05:25:00 -0400283
Matthew Garrettb6dacf62010-05-11 13:49:25 -0400284 /* This violates the spec but is required for bug compatibility. */
285 acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
Rafael J. Wysocki65df7842008-11-26 17:53:13 -0500286
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100287 /* Reprogram control registers and execute _BFS */
Lin Minga2ef5c42012-03-21 10:58:46 +0800288 acpi_leave_sleep_state_prep(acpi_state, flags);
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100289
Pavel Machek23b168d2008-02-05 19:27:12 +0100290 /* ACPI 3.0 specs (P62) says that it's the responsibility
Arnaud Patard872d83d2006-04-27 05:25:00 -0400291 * of the OSPM to clear the status bit [ implying that the
292 * POWER_BUTTON event should not reach userspace ]
293 */
294 if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3))
295 acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
296
Shaohua Lia3627f62007-06-20 09:17:58 +0800297 /*
298 * Disable and clear GPE status before interrupt is enabled. Some GPEs
299 * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
300 * acpi_leave_sleep_state will reenable specific GPEs later
301 */
Lin Ming3d97e422008-12-16 16:57:46 +0800302 acpi_disable_all_gpes();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200303 /* Allow EC transactions to happen. */
Rafael J. Wysockife955682010-04-09 01:40:38 +0200304 acpi_ec_unblock_transactions_early();
Shaohua Lia3627f62007-06-20 09:17:58 +0800305
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400306 suspend_nvs_restore();
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
309}
310
Len Brown2c6e33c2008-04-23 18:02:52 -0400311static int acpi_suspend_state_valid(suspend_state_t pm_state)
Shaohua Lieb9289e2005-10-30 15:00:01 -0800312{
Johannes Berge8c9c502007-04-30 15:09:54 -0700313 u32 acpi_state;
Shaohua Lieb9289e2005-10-30 15:00:01 -0800314
Johannes Berge8c9c502007-04-30 15:09:54 -0700315 switch (pm_state) {
316 case PM_SUSPEND_ON:
317 case PM_SUSPEND_STANDBY:
318 case PM_SUSPEND_MEM:
319 acpi_state = acpi_suspend_states[pm_state];
320
321 return sleep_states[acpi_state];
322 default:
323 return 0;
324 }
Shaohua Lieb9289e2005-10-30 15:00:01 -0800325}
326
Lionel Debroux2f55ac02010-11-16 14:14:02 +0100327static const struct platform_suspend_ops acpi_suspend_ops = {
Len Brown2c6e33c2008-04-23 18:02:52 -0400328 .valid = acpi_suspend_state_valid,
329 .begin = acpi_suspend_begin,
Rafael J. Wysocki6a7c7ea2009-04-19 20:08:42 +0200330 .prepare_late = acpi_pm_prepare,
Len Brown2c6e33c2008-04-23 18:02:52 -0400331 .enter = acpi_suspend_enter,
Rafael J. Wysocki618d7fd2010-07-02 00:14:57 +0200332 .wake = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200333 .end = acpi_pm_end,
334};
335
336/**
337 * acpi_suspend_begin_old - Set the target system sleep state to the
338 * state associated with given @pm_state, if supported, and
339 * execute the _PTS control method. This function is used if the
340 * pre-ACPI 2.0 suspend ordering has been requested.
341 */
342static int acpi_suspend_begin_old(suspend_state_t pm_state)
343{
344 int error = acpi_suspend_begin(pm_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200345 if (!error)
346 error = __acpi_pm_prepare();
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200347
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200348 return error;
349}
350
351/*
352 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
353 * been requested.
354 */
Lionel Debroux2f55ac02010-11-16 14:14:02 +0100355static const struct platform_suspend_ops acpi_suspend_ops_old = {
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200356 .valid = acpi_suspend_state_valid,
357 .begin = acpi_suspend_begin_old,
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200358 .prepare_late = acpi_pm_pre_suspend,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200359 .enter = acpi_suspend_enter,
Rafael J. Wysocki618d7fd2010-07-02 00:14:57 +0200360 .wake = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200361 .end = acpi_pm_end,
362 .recover = acpi_pm_finish,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363};
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700364
365static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
366{
367 old_suspend_ordering = true;
368 return 0;
369}
370
Rafael J. Wysocki53998642010-09-24 16:46:14 -0400371static int __init init_nvs_nosave(const struct dmi_system_id *d)
372{
373 acpi_nvs_nosave();
374 return 0;
375}
376
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700377static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
378 {
379 .callback = init_old_suspend_ordering,
380 .ident = "Abit KN9 (nForce4 variant)",
381 .matches = {
382 DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
383 DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
384 },
385 },
Rafael J. Wysocki4fb507b2008-10-14 22:54:06 +0200386 {
387 .callback = init_old_suspend_ordering,
388 .ident = "HP xw4600 Workstation",
389 .matches = {
390 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
391 DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
392 },
393 },
Rafael J. Wysocki65df7842008-11-26 17:53:13 -0500394 {
Andy Whitcrofta1404492009-02-11 18:11:22 +0000395 .callback = init_old_suspend_ordering,
396 .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
397 .matches = {
398 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
399 DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
400 },
401 },
Zhang Rui45e77982009-03-15 22:13:44 -0400402 {
Zhao Yakui2a9ef8e2009-03-18 16:36:25 +0800403 .callback = init_old_suspend_ordering,
404 .ident = "Panasonic CF51-2L",
405 .matches = {
406 DMI_MATCH(DMI_BOARD_VENDOR,
407 "Matsushita Electric Industrial Co.,Ltd."),
408 DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
409 },
410 },
Rafael J. Wysocki53998642010-09-24 16:46:14 -0400411 {
412 .callback = init_nvs_nosave,
Dave Jonesd11c78e2011-10-19 23:15:11 +0200413 .ident = "Sony Vaio VGN-FW21E",
414 .matches = {
415 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
416 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"),
417 },
418 },
419 {
420 .callback = init_nvs_nosave,
Dave Jonesddf6ce42011-11-03 00:58:59 +0100421 .ident = "Sony Vaio VPCEB17FX",
422 .matches = {
423 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
424 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"),
425 },
426 },
427 {
428 .callback = init_nvs_nosave,
Rafael J. Wysocki53998642010-09-24 16:46:14 -0400429 .ident = "Sony Vaio VGN-SR11M",
430 .matches = {
431 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
432 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),
433 },
434 },
435 {
436 .callback = init_nvs_nosave,
437 .ident = "Everex StepNote Series",
438 .matches = {
439 DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),
440 DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),
441 },
442 },
Rafael J. Wysockiaf489312010-10-17 21:01:21 +0200443 {
444 .callback = init_nvs_nosave,
445 .ident = "Sony Vaio VPCEB1Z1E",
446 .matches = {
447 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
448 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),
449 },
450 },
Rafael J. Wysocki291a73c2010-12-12 21:10:42 +0100451 {
452 .callback = init_nvs_nosave,
453 .ident = "Sony Vaio VGN-NW130D",
454 .matches = {
455 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
456 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),
457 },
458 },
Rafael J. Wysocki7b330702011-01-06 23:37:01 +0100459 {
460 .callback = init_nvs_nosave,
Lan Tianyu93f77082012-01-21 09:23:56 +0800461 .ident = "Sony Vaio VPCCW29FX",
462 .matches = {
463 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
464 DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"),
465 },
466 },
467 {
468 .callback = init_nvs_nosave,
Rafael J. Wysocki7b330702011-01-06 23:37:01 +0100469 .ident = "Averatec AV1020-ED2",
470 .matches = {
471 DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"),
472 DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"),
473 },
474 },
Zhang Ruibb0c5ed2011-07-30 01:40:48 -0400475 {
476 .callback = init_old_suspend_ordering,
477 .ident = "Asus A8N-SLI DELUXE",
478 .matches = {
479 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
480 DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"),
481 },
482 },
483 {
484 .callback = init_old_suspend_ordering,
485 .ident = "Asus A8N-SLI Premium",
486 .matches = {
487 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
488 DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"),
489 },
490 },
Rafael J. Wysocki89e8ea12011-10-06 20:35:03 +0200491 {
492 .callback = init_nvs_nosave,
493 .ident = "Sony Vaio VGN-SR26GN_P",
494 .matches = {
495 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
496 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"),
497 },
498 },
Bogdan Radulescu731b25a2011-10-06 20:35:12 +0200499 {
500 .callback = init_nvs_nosave,
501 .ident = "Sony Vaio VGN-FW520F",
502 .matches = {
503 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
504 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"),
505 },
506 },
Keng-Yu Lin5a50a7c2011-12-02 00:04:23 +0100507 {
508 .callback = init_nvs_nosave,
509 .ident = "Asus K54C",
510 .matches = {
511 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
512 DMI_MATCH(DMI_PRODUCT_NAME, "K54C"),
513 },
514 },
515 {
516 .callback = init_nvs_nosave,
517 .ident = "Asus K54HR",
518 .matches = {
519 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
520 DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"),
521 },
522 },
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700523 {},
524};
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200525#endif /* CONFIG_SUSPEND */
526
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200527#ifdef CONFIG_HIBERNATION
Shaohua Libdfe6b72008-07-23 21:28:41 -0700528static unsigned long s4_hardware_signature;
529static struct acpi_table_facs *facs;
530static bool nosigcheck;
531
532void __init acpi_no_s4_hw_signature(void)
533{
534 nosigcheck = true;
535}
536
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100537static int acpi_hibernation_begin(void)
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700538{
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100539 int error;
540
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200541 error = nvs_nosave ? 0 : suspend_nvs_alloc();
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100542 if (!error) {
543 acpi_target_sleep_state = ACPI_STATE_S4;
544 acpi_sleep_tts_switch(acpi_target_sleep_state);
545 }
546
547 return error;
548}
549
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700550static int acpi_hibernation_enter(void)
551{
Lin Minga2ef5c42012-03-21 10:58:46 +0800552 u8 flags = wake_sleep_flags();
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700553 acpi_status status = AE_OK;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700554
555 ACPI_FLUSH_CPU_CACHE();
556
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700557 /* This shouldn't return. If it returns, we have a problem */
Lin Minga2ef5c42012-03-21 10:58:46 +0800558 status = acpi_enter_sleep_state(ACPI_STATE_S4, flags);
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100559 /* Reprogram control registers and execute _BFS */
Lin Minga2ef5c42012-03-21 10:58:46 +0800560 acpi_leave_sleep_state_prep(ACPI_STATE_S4, flags);
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700561
562 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
563}
564
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700565static void acpi_hibernation_leave(void)
566{
Lin Minga2ef5c42012-03-21 10:58:46 +0800567 u8 flags = wake_sleep_flags();
568
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700569 /*
570 * If ACPI is not enabled by the BIOS and the boot kernel, we need to
571 * enable it here.
572 */
573 acpi_enable();
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100574 /* Reprogram control registers and execute _BFS */
Lin Minga2ef5c42012-03-21 10:58:46 +0800575 acpi_leave_sleep_state_prep(ACPI_STATE_S4, flags);
Shaohua Libdfe6b72008-07-23 21:28:41 -0700576 /* Check the hardware signature */
577 if (facs && s4_hardware_signature != facs->hardware_signature) {
578 printk(KERN_EMERG "ACPI: Hardware changed while hibernated, "
579 "cannot resume!\n");
580 panic("ACPI S4 hardware signature mismatch");
581 }
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100582 /* Restore the NVS memory area */
Matthew Garrettdd4c4f12010-05-28 16:32:14 -0400583 suspend_nvs_restore();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200584 /* Allow EC transactions to happen. */
Rafael J. Wysockife955682010-04-09 01:40:38 +0200585 acpi_ec_unblock_transactions_early();
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700586}
587
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200588static void acpi_pm_thaw(void)
Rafael J. Wysockif6bb13a2010-03-04 01:52:58 +0100589{
Rafael J. Wysockife955682010-04-09 01:40:38 +0200590 acpi_ec_unblock_transactions();
Lin Ming3d97e422008-12-16 16:57:46 +0800591 acpi_enable_all_runtime_gpes();
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700592}
593
Lionel Debroux073ef1f2010-11-09 21:48:49 +0100594static const struct platform_hibernation_ops acpi_hibernation_ops = {
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100595 .begin = acpi_hibernation_begin,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200596 .end = acpi_pm_end,
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200597 .pre_snapshot = acpi_pm_prepare,
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400598 .finish = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200599 .prepare = acpi_pm_prepare,
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700600 .enter = acpi_hibernation_enter,
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700601 .leave = acpi_hibernation_leave,
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200602 .pre_restore = acpi_pm_freeze,
603 .restore_cleanup = acpi_pm_thaw,
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700604};
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200605
606/**
607 * acpi_hibernation_begin_old - Set the target system sleep state to
608 * ACPI_STATE_S4 and execute the _PTS control method. This
609 * function is used if the pre-ACPI 2.0 suspend ordering has been
610 * requested.
611 */
612static int acpi_hibernation_begin_old(void)
613{
Zhao Yakuie49f7112008-08-12 10:20:22 +0800614 int error;
615 /*
616 * The _TTS object should always be evaluated before the _PTS object.
617 * When the old_suspended_ordering is true, the _PTS object is
618 * evaluated in the acpi_sleep_prepare.
619 */
620 acpi_sleep_tts_switch(ACPI_STATE_S4);
621
622 error = acpi_sleep_prepare(ACPI_STATE_S4);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200623
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100624 if (!error) {
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200625 if (!nvs_nosave)
Matthew Garrettdd4c4f12010-05-28 16:32:14 -0400626 error = suspend_nvs_alloc();
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100627 if (!error)
628 acpi_target_sleep_state = ACPI_STATE_S4;
629 }
630 return error;
631}
632
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200633/*
634 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
635 * been requested.
636 */
Lionel Debroux073ef1f2010-11-09 21:48:49 +0100637static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200638 .begin = acpi_hibernation_begin_old,
639 .end = acpi_pm_end,
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200640 .pre_snapshot = acpi_pm_pre_suspend,
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200641 .prepare = acpi_pm_freeze,
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400642 .finish = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200643 .enter = acpi_hibernation_enter,
644 .leave = acpi_hibernation_leave,
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200645 .pre_restore = acpi_pm_freeze,
646 .restore_cleanup = acpi_pm_thaw,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200647 .recover = acpi_pm_finish,
648};
649#endif /* CONFIG_HIBERNATION */
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700650
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200651int acpi_suspend(u32 acpi_state)
652{
653 suspend_state_t states[] = {
654 [1] = PM_SUSPEND_STANDBY,
655 [3] = PM_SUSPEND_MEM,
656 [5] = PM_SUSPEND_MAX
657 };
658
659 if (acpi_state < 6 && states[acpi_state])
660 return pm_suspend(states[acpi_state]);
661 if (acpi_state == 4)
662 return hibernate();
663 return -EINVAL;
664}
665
Rafael J. Wysockiaa338602011-02-11 00:06:54 +0100666#ifdef CONFIG_PM
Shaohua Lifd4aff12007-07-17 22:40:25 +0200667/**
668 * acpi_pm_device_sleep_state - return preferred power state of ACPI device
669 * in the system sleep state given by %acpi_target_sleep_state
David Brownell2fe2de52008-06-05 01:15:40 +0200670 * @dev: device to examine; its driver model wakeup flags control
671 * whether it should be able to wake up the system
Shaohua Lifd4aff12007-07-17 22:40:25 +0200672 * @d_min_p: used to store the upper limit of allowed states range
673 * Return value: preferred power state of the device on success, -ENODEV on
674 * failure (ie. if there's no 'struct acpi_device' for @dev)
675 *
676 * Find the lowest power (highest number) ACPI device power state that
677 * device @dev can be in while the system is in the sleep state represented
678 * by %acpi_target_sleep_state. If @wake is nonzero, the device should be
679 * able to wake up the system from this sleep state. If @d_min_p is set,
680 * the highest power (lowest number) device power state of @dev allowed
681 * in this system sleep state is stored at the location pointed to by it.
682 *
683 * The caller must ensure that @dev is valid before using this function.
684 * The caller is also responsible for figuring out if the device is
685 * supposed to be able to wake up the system and passing this information
686 * via @wake.
687 */
688
David Brownell2fe2de52008-06-05 01:15:40 +0200689int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p)
Shaohua Lifd4aff12007-07-17 22:40:25 +0200690{
691 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
692 struct acpi_device *adev;
693 char acpi_method[] = "_SxD";
Matthew Wilcox27663c52008-10-10 02:22:59 -0400694 unsigned long long d_min, d_max;
Shaohua Lifd4aff12007-07-17 22:40:25 +0200695
696 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
Shaohua Liead77592007-08-23 15:01:13 +0800697 printk(KERN_DEBUG "ACPI handle has no context!\n");
Shaohua Lifd4aff12007-07-17 22:40:25 +0200698 return -ENODEV;
699 }
700
701 acpi_method[2] = '0' + acpi_target_sleep_state;
702 /*
703 * If the sleep state is S0, we will return D3, but if the device has
704 * _S0W, we will use the value from _S0W
705 */
706 d_min = ACPI_STATE_D0;
707 d_max = ACPI_STATE_D3;
708
709 /*
710 * If present, _SxD methods return the minimum D-state (highest power
711 * state) we can use for the corresponding S-states. Otherwise, the
712 * minimum D-state is D0 (ACPI 3.x).
713 *
714 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
715 * provided -- that's our fault recovery, we ignore retval.
716 */
717 if (acpi_target_sleep_state > ACPI_STATE_S0)
718 acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
719
720 /*
721 * If _PRW says we can wake up the system from the target sleep state,
722 * the D-state returned by _SxD is sufficient for that (we assume a
723 * wakeup-aware driver if wake is set). Still, if _SxW exists
724 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
725 * can wake the system. _S0W may be valid, too.
726 */
727 if (acpi_target_sleep_state == ACPI_STATE_S0 ||
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200728 (device_may_wakeup(dev) &&
Shaohua Lifd4aff12007-07-17 22:40:25 +0200729 adev->wakeup.sleep_state <= acpi_target_sleep_state)) {
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100730 acpi_status status;
731
Shaohua Lifd4aff12007-07-17 22:40:25 +0200732 acpi_method[3] = 'W';
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100733 status = acpi_evaluate_integer(handle, acpi_method, NULL,
734 &d_max);
735 if (ACPI_FAILURE(status)) {
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200736 if (acpi_target_sleep_state != ACPI_STATE_S0 ||
737 status != AE_NOT_FOUND)
738 d_max = d_min;
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100739 } else if (d_max < d_min) {
740 /* Warn the user of the broken DSDT */
741 printk(KERN_WARNING "ACPI: Wrong value from %s\n",
742 acpi_method);
743 /* Sanitize it */
Shaohua Lifd4aff12007-07-17 22:40:25 +0200744 d_min = d_max;
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100745 }
Shaohua Lifd4aff12007-07-17 22:40:25 +0200746 }
747
748 if (d_min_p)
749 *d_min_p = d_min;
750 return d_max;
751}
Rafael J. Wysockiaa338602011-02-11 00:06:54 +0100752#endif /* CONFIG_PM */
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200753
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200754#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200755/**
756 * acpi_pm_device_sleep_wake - enable or disable the system wake-up
757 * capability of given device
758 * @dev: device to handle
759 * @enable: 'true' - enable, 'false' - disable the wake-up capability
760 */
761int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
762{
763 acpi_handle handle;
764 struct acpi_device *adev;
Rafael J. Wysockidf8db912009-09-08 23:13:49 +0200765 int error;
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200766
Rafael J. Wysocki0baed8d2009-09-08 23:16:24 +0200767 if (!device_can_wakeup(dev))
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200768 return -EINVAL;
769
770 handle = DEVICE_ACPI_HANDLE(dev);
771 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
Rafael J. Wysockidf8db912009-09-08 23:13:49 +0200772 dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__);
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200773 return -ENODEV;
774 }
775
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +0200776 error = enable ?
777 acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
778 acpi_disable_wakeup_device_power(adev);
Rafael J. Wysockidf8db912009-09-08 23:13:49 +0200779 if (!error)
780 dev_info(dev, "wake-up capability %s by ACPI\n",
781 enable ? "enabled" : "disabled");
782
783 return error;
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200784}
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200785#endif /* CONFIG_PM_SLEEP */
Shaohua Lifd4aff12007-07-17 22:40:25 +0200786
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400787static void acpi_power_off_prepare(void)
788{
789 /* Prepare to power off the system */
790 acpi_sleep_prepare(ACPI_STATE_S5);
Lin Ming3d97e422008-12-16 16:57:46 +0800791 acpi_disable_all_gpes();
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400792}
793
794static void acpi_power_off(void)
795{
Lin Minga2ef5c42012-03-21 10:58:46 +0800796 u8 flags = wake_sleep_flags();
797
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400798 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
Frank Seidel4d939152009-02-04 17:03:07 +0100799 printk(KERN_DEBUG "%s called\n", __func__);
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400800 local_irq_disable();
Lin Minga2ef5c42012-03-21 10:58:46 +0800801 acpi_enter_sleep_state(ACPI_STATE_S5, flags);
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400802}
803
Len Brown96f15ef2009-04-17 23:32:20 -0400804/*
805 * ACPI 2.0 created the optional _GTS and _BFS,
806 * but industry adoption has been neither rapid nor broad.
807 *
808 * Linux gets into trouble when it executes poorly validated
809 * paths through the BIOS, so disable _GTS and _BFS by default,
810 * but do speak up and offer the option to enable them.
811 */
Stephen Hemminger01eac602010-10-18 18:47:25 -0700812static void __init acpi_gts_bfs_check(void)
Len Brown96f15ef2009-04-17 23:32:20 -0400813{
814 acpi_handle dummy;
815
Bob Moore4efeeec2012-03-21 09:42:45 +0800816 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_PATHNAME__GTS, &dummy)))
Len Brown96f15ef2009-04-17 23:32:20 -0400817 {
818 printk(KERN_NOTICE PREFIX "BIOS offers _GTS\n");
819 printk(KERN_NOTICE PREFIX "If \"acpi.gts=1\" improves suspend, "
820 "please notify linux-acpi@vger.kernel.org\n");
821 }
Bob Moore4efeeec2012-03-21 09:42:45 +0800822 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_PATHNAME__BFS, &dummy)))
Len Brown96f15ef2009-04-17 23:32:20 -0400823 {
824 printk(KERN_NOTICE PREFIX "BIOS offers _BFS\n");
825 printk(KERN_NOTICE PREFIX "If \"acpi.bfs=1\" improves resume, "
826 "please notify linux-acpi@vger.kernel.org\n");
827 }
828}
829
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500830int __init acpi_sleep_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200832 acpi_status status;
833 u8 type_a, type_b;
834#ifdef CONFIG_SUSPEND
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500835 int i = 0;
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700836
837 dmi_check_system(acpisleep_dmi_table);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200838#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 if (acpi_disabled)
841 return 0;
842
Frans Pop5a50fe72007-09-20 22:27:44 +0200843 sleep_states[ACPI_STATE_S0] = 1;
844 printk(KERN_INFO PREFIX "(supports S0");
845
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200846#ifdef CONFIG_SUSPEND
Frans Pop5a50fe72007-09-20 22:27:44 +0200847 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
849 if (ACPI_SUCCESS(status)) {
850 sleep_states[i] = 1;
851 printk(" S%d", i);
852 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200855 suspend_set_ops(old_suspend_ordering ?
856 &acpi_suspend_ops_old : &acpi_suspend_ops);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200857#endif
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700858
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200859#ifdef CONFIG_HIBERNATION
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200860 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
861 if (ACPI_SUCCESS(status)) {
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200862 hibernation_set_ops(old_suspend_ordering ?
863 &acpi_hibernation_ops_old : &acpi_hibernation_ops);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200864 sleep_states[ACPI_STATE_S4] = 1;
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400865 printk(" S4");
Shaohua Libdfe6b72008-07-23 21:28:41 -0700866 if (!nosigcheck) {
Lin Ming3d97e422008-12-16 16:57:46 +0800867 acpi_get_table(ACPI_SIG_FACS, 1,
Shaohua Libdfe6b72008-07-23 21:28:41 -0700868 (struct acpi_table_header **)&facs);
869 if (facs)
870 s4_hardware_signature =
871 facs->hardware_signature;
872 }
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200873 }
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700874#endif
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400875 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
876 if (ACPI_SUCCESS(status)) {
877 sleep_states[ACPI_STATE_S5] = 1;
878 printk(" S5");
879 pm_power_off_prepare = acpi_power_off_prepare;
880 pm_power_off = acpi_power_off;
881 }
882 printk(")\n");
Zhao Yakuie49f7112008-08-12 10:20:22 +0800883 /*
884 * Register the tts_notifier to reboot notifier list so that the _TTS
885 * object can also be evaluated when the system enters S5.
886 */
887 register_reboot_notifier(&tts_notifier);
Len Brown96f15ef2009-04-17 23:32:20 -0400888 acpi_gts_bfs_check();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 return 0;
890}