blob: 1463c56092c4ad59fdd1cca2938beb27f4af7cad [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>
Lin Mingb24e5092012-03-27 15:43:25 +080021#include <linux/pm_runtime.h>
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +040022
23#include <asm/io.h>
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <acpi/acpi_bus.h>
26#include <acpi/acpi_drivers.h>
Bjorn Helgaase60cc7a2009-03-13 12:08:26 -060027
28#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include "sleep.h"
30
Stephen Hemminger01eac602010-10-18 18:47:25 -070031static u8 sleep_states[ACPI_S_STATE_COUNT];
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Zhao Yakuie49f7112008-08-12 10:20:22 +080033static 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
50static 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
57static struct notifier_block tts_notifier = {
58 .notifier_call = tts_notify_reboot,
59 .next = NULL,
60 .priority = 0,
61};
62
Rafael J. Wysockic9b6c8f2008-01-08 00:10:57 +010063static int acpi_sleep_prepare(u32 acpi_state)
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020064{
65#ifdef CONFIG_ACPI_SLEEP
66 /* do we have a wakeup address for S2 and S3? */
67 if (acpi_state == ACPI_STATE_S3) {
H. Peter Anvin319b6ff2012-05-30 12:33:41 +030068 if (!acpi_wakeup_address)
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020069 return -EFAULT;
H. Peter Anvin319b6ff2012-05-30 12:33:41 +030070 acpi_set_firmware_waking_vector(acpi_wakeup_address);
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020071
72 }
73 ACPI_FLUSH_CPU_CACHE();
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020074#endif
Rafael J. Wysockic9b6c8f2008-01-08 00:10:57 +010075 printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
76 acpi_state);
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040077 acpi_enable_wakeup_devices(acpi_state);
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020078 acpi_enter_sleep_state_prep(acpi_state);
79 return 0;
80}
81
Rafael J. Wysocki5d1e0722008-10-22 14:58:43 -040082#ifdef CONFIG_ACPI_SLEEP
Jan Beulich091aad62010-12-07 14:52:25 +000083static u32 acpi_target_sleep_state = ACPI_STATE_S0;
Rafael J. Wysockia5ca7342012-07-23 21:01:02 +020084static bool pwr_btn_event_pending;
Jan Beulich091aad62010-12-07 14:52:25 +000085
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/*
Kristen Carlson Accardi1bad2f12012-10-26 13:39:15 +0200101 * 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 */
108static bool nvs_nosave_s3;
109
110void __init acpi_nvs_nosave_s3(void)
111{
112 nvs_nosave_s3 = true;
113}
114
115/*
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200116 * 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 */
120static bool old_suspend_ordering;
121
122void __init acpi_old_suspend_ordering(void)
123{
124 old_suspend_ordering = true;
125}
126
127/**
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200128 * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200129 */
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200130static int acpi_pm_freeze(void)
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200131{
Lin Ming3d97e422008-12-16 16:57:46 +0800132 acpi_disable_all_gpes();
Lin Mingbd6f10a2012-05-22 16:43:49 +0800133 acpi_os_wait_events_complete();
Rafael J. Wysockife955682010-04-09 01:40:38 +0200134 acpi_ec_block_transactions();
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200135 return 0;
136}
137
138/**
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200139 * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
140 */
141static int acpi_pm_pre_suspend(void)
142{
143 acpi_pm_freeze();
Jiri Slaby26fcaf62011-01-07 01:42:31 +0100144 return suspend_nvs_save();
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200145}
146
147/**
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200148 * __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 */
153static int __acpi_pm_prepare(void)
154{
155 int error = acpi_sleep_prepare(acpi_target_sleep_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200156 if (error)
157 acpi_target_sleep_state = ACPI_STATE_S0;
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200158
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200159 return error;
160}
161
162/**
163 * acpi_pm_prepare - Prepare the platform to enter the target sleep
164 * state and disable the GPEs.
165 */
166static int acpi_pm_prepare(void)
167{
168 int error = __acpi_pm_prepare();
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200169 if (!error)
Jiri Slaby26fcaf62011-01-07 01:42:31 +0100170 error = acpi_pm_pre_suspend();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200171
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200172 return error;
173}
174
Daniel Drakec10d7a12012-05-10 00:08:43 +0100175static 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
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200183/**
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 */
189static void acpi_pm_finish(void)
190{
Daniel Drakec10d7a12012-05-10 00:08:43 +0100191 struct device *pwr_btn_dev;
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200192 u32 acpi_state = acpi_target_sleep_state;
193
Len Brown42de5532010-06-12 01:15:40 -0400194 acpi_ec_unblock_transactions();
Rafael J. Wysockid551d812011-01-19 22:27:55 +0100195 suspend_nvs_free();
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400196
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200197 if (acpi_state == ACPI_STATE_S0)
198 return;
199
200 printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
201 acpi_state);
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -0400202 acpi_disable_wakeup_devices(acpi_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200203 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;
Daniel Drakec10d7a12012-05-10 00:08:43 +0100209
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 }
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200226}
227
228/**
229 * acpi_pm_end - Finish up suspend sequence.
230 */
231static 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;
Zhao Yakuie49f7112008-08-12 10:20:22 +0800238 acpi_sleep_tts_switch(acpi_target_sleep_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200239}
Rafael J. Wysocki92daa7b2008-10-23 21:46:43 +0200240#else /* !CONFIG_ACPI_SLEEP */
241#define acpi_target_sleep_state ACPI_STATE_S0
Rafael J. Wysocki5d1e0722008-10-22 14:58:43 -0400242#endif /* CONFIG_ACPI_SLEEP */
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200243
244#ifdef CONFIG_SUSPEND
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245static u32 acpi_suspend_states[] = {
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500246 [PM_SUSPEND_ON] = ACPI_STATE_S0,
247 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
248 [PM_SUSPEND_MEM] = ACPI_STATE_S3,
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500249 [PM_SUSPEND_MAX] = ACPI_STATE_S5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250};
251
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200252/**
Len Brown2c6e33c2008-04-23 18:02:52 -0400253 * acpi_suspend_begin - Set the target system sleep state to the state
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200254 * associated with given @pm_state, if supported.
255 */
Len Brown2c6e33c2008-04-23 18:02:52 -0400256static int acpi_suspend_begin(suspend_state_t pm_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
258 u32 acpi_state = acpi_suspend_states[pm_state];
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200259 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Kristen Carlson Accardi1bad2f12012-10-26 13:39:15 +0200261 error = (nvs_nosave || nvs_nosave_s3) ? 0 : suspend_nvs_alloc();
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400262 if (error)
263 return error;
264
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200265 if (sleep_states[acpi_state]) {
266 acpi_target_sleep_state = acpi_state;
Zhao Yakuie49f7112008-08-12 10:20:22 +0800267 acpi_sleep_tts_switch(acpi_target_sleep_state);
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200268 } else {
269 printk(KERN_ERR "ACPI does not support this state: %d\n",
270 pm_state);
271 error = -ENOSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 }
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200273 return error;
274}
275
276/**
Len Brown2c6e33c2008-04-23 18:02:52 -0400277 * acpi_suspend_enter - Actually enter a sleep state.
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200278 * @pm_state: ignored
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 *
Rafael J. Wysocki50ad1472007-07-24 11:58:39 +0200280 * Flush caches and go to sleep. For STR we have to call arch-specific
281 * assembly, which in turn call acpi_enter_sleep_state().
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 * It's unfortunate, but it works. Please fix if you're feeling frisky.
283 */
Len Brown2c6e33c2008-04-23 18:02:52 -0400284static int acpi_suspend_enter(suspend_state_t pm_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
286 acpi_status status = AE_OK;
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200287 u32 acpi_state = acpi_target_sleep_state;
Rafael J. Wysocki979f11b2011-02-08 23:42:09 +0100288 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290 ACPI_FLUSH_CPU_CACHE();
291
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200292 switch (acpi_state) {
293 case ACPI_STATE_S1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 barrier();
Len Brown3f6f49c2012-07-26 20:08:54 -0400295 status = acpi_enter_sleep_state(acpi_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 break;
297
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200298 case ACPI_STATE_S3:
Rafael J. Wysockif1a20032011-02-08 23:42:22 +0100299 error = acpi_suspend_lowlevel();
Rafael J. Wysocki979f11b2011-02-08 23:42:09 +0100300 if (error)
301 return error;
Rafael J. Wysocki7a63f082011-02-08 23:41:57 +0100302 pr_info(PREFIX "Low-level resume complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 }
Arnaud Patard872d83d2006-04-27 05:25:00 -0400305
Matthew Garrettb6dacf62010-05-11 13:49:25 -0400306 /* This violates the spec but is required for bug compatibility. */
307 acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
Rafael J. Wysocki65df7842008-11-26 17:53:13 -0500308
Len Brown3f6f49c2012-07-26 20:08:54 -0400309 /* Reprogram control registers */
310 acpi_leave_sleep_state_prep(acpi_state);
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100311
Pavel Machek23b168d2008-02-05 19:27:12 +0100312 /* ACPI 3.0 specs (P62) says that it's the responsibility
Arnaud Patard872d83d2006-04-27 05:25:00 -0400313 * of the OSPM to clear the status bit [ implying that the
314 * POWER_BUTTON event should not reach userspace ]
Daniel Drakec10d7a12012-05-10 00:08:43 +0100315 *
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.
Arnaud Patard872d83d2006-04-27 05:25:00 -0400320 */
Daniel Drakec10d7a12012-05-10 00:08:43 +0100321 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 }
Arnaud Patard872d83d2006-04-27 05:25:00 -0400332
Shaohua Lia3627f62007-06-20 09:17:58 +0800333 /*
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 */
Lin Ming3d97e422008-12-16 16:57:46 +0800338 acpi_disable_all_gpes();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200339 /* Allow EC transactions to happen. */
Rafael J. Wysockife955682010-04-09 01:40:38 +0200340 acpi_ec_unblock_transactions_early();
Shaohua Lia3627f62007-06-20 09:17:58 +0800341
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400342 suspend_nvs_restore();
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
345}
346
Len Brown2c6e33c2008-04-23 18:02:52 -0400347static int acpi_suspend_state_valid(suspend_state_t pm_state)
Shaohua Lieb9289e2005-10-30 15:00:01 -0800348{
Johannes Berge8c9c502007-04-30 15:09:54 -0700349 u32 acpi_state;
Shaohua Lieb9289e2005-10-30 15:00:01 -0800350
Johannes Berge8c9c502007-04-30 15:09:54 -0700351 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 }
Shaohua Lieb9289e2005-10-30 15:00:01 -0800361}
362
Lionel Debroux2f55ac02010-11-16 14:14:02 +0100363static const struct platform_suspend_ops acpi_suspend_ops = {
Len Brown2c6e33c2008-04-23 18:02:52 -0400364 .valid = acpi_suspend_state_valid,
365 .begin = acpi_suspend_begin,
Rafael J. Wysocki6a7c7ea2009-04-19 20:08:42 +0200366 .prepare_late = acpi_pm_prepare,
Len Brown2c6e33c2008-04-23 18:02:52 -0400367 .enter = acpi_suspend_enter,
Rafael J. Wysocki618d7fd2010-07-02 00:14:57 +0200368 .wake = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200369 .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 */
378static int acpi_suspend_begin_old(suspend_state_t pm_state)
379{
380 int error = acpi_suspend_begin(pm_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200381 if (!error)
382 error = __acpi_pm_prepare();
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200383
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200384 return error;
385}
386
387/*
388 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
389 * been requested.
390 */
Lionel Debroux2f55ac02010-11-16 14:14:02 +0100391static const struct platform_suspend_ops acpi_suspend_ops_old = {
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200392 .valid = acpi_suspend_state_valid,
393 .begin = acpi_suspend_begin_old,
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200394 .prepare_late = acpi_pm_pre_suspend,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200395 .enter = acpi_suspend_enter,
Rafael J. Wysocki618d7fd2010-07-02 00:14:57 +0200396 .wake = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200397 .end = acpi_pm_end,
398 .recover = acpi_pm_finish,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399};
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700400
401static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
402{
403 old_suspend_ordering = true;
404 return 0;
405}
406
Rafael J. Wysocki53998642010-09-24 16:46:14 -0400407static int __init init_nvs_nosave(const struct dmi_system_id *d)
408{
409 acpi_nvs_nosave();
410 return 0;
411}
412
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700413static 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 },
Rafael J. Wysocki4fb507b2008-10-14 22:54:06 +0200422 {
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 },
Rafael J. Wysocki65df7842008-11-26 17:53:13 -0500430 {
Andy Whitcrofta1404492009-02-11 18:11:22 +0000431 .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 },
Zhang Rui45e77982009-03-15 22:13:44 -0400438 {
Zhao Yakui2a9ef8e2009-03-18 16:36:25 +0800439 .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 },
Rafael J. Wysocki53998642010-09-24 16:46:14 -0400447 {
448 .callback = init_nvs_nosave,
Dave Jonesd11c78e2011-10-19 23:15:11 +0200449 .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,
Dave Jonesddf6ce42011-11-03 00:58:59 +0100457 .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,
Rafael J. Wysocki53998642010-09-24 16:46:14 -0400465 .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 },
Rafael J. Wysockiaf489312010-10-17 21:01:21 +0200479 {
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 },
Rafael J. Wysocki291a73c2010-12-12 21:10:42 +0100487 {
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 },
Rafael J. Wysocki7b330702011-01-06 23:37:01 +0100495 {
496 .callback = init_nvs_nosave,
Lan Tianyu93f77082012-01-21 09:23:56 +0800497 .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,
Rafael J. Wysocki7b330702011-01-06 23:37:01 +0100505 .ident = "Averatec AV1020-ED2",
506 .matches = {
507 DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"),
508 DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"),
509 },
510 },
Zhang Ruibb0c5ed2011-07-30 01:40:48 -0400511 {
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 },
Rafael J. Wysocki89e8ea12011-10-06 20:35:03 +0200527 {
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 },
Bogdan Radulescu731b25a2011-10-06 20:35:12 +0200535 {
536 .callback = init_nvs_nosave,
Lan Tianyu876ab792012-11-21 23:12:12 +0100537 .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,
Bogdan Radulescu731b25a2011-10-06 20:35:12 +0200545 .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 },
Keng-Yu Lin5a50a7c2011-12-02 00:04:23 +0100551 {
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 },
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700567 {},
568};
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200569#endif /* CONFIG_SUSPEND */
570
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200571#ifdef CONFIG_HIBERNATION
Shaohua Libdfe6b72008-07-23 21:28:41 -0700572static unsigned long s4_hardware_signature;
573static struct acpi_table_facs *facs;
574static bool nosigcheck;
575
576void __init acpi_no_s4_hw_signature(void)
577{
578 nosigcheck = true;
579}
580
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100581static int acpi_hibernation_begin(void)
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700582{
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100583 int error;
584
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200585 error = nvs_nosave ? 0 : suspend_nvs_alloc();
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100586 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
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700594static int acpi_hibernation_enter(void)
595{
596 acpi_status status = AE_OK;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700597
598 ACPI_FLUSH_CPU_CACHE();
599
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700600 /* This shouldn't return. If it returns, we have a problem */
Len Brown3f6f49c2012-07-26 20:08:54 -0400601 status = acpi_enter_sleep_state(ACPI_STATE_S4);
602 /* Reprogram control registers */
603 acpi_leave_sleep_state_prep(ACPI_STATE_S4);
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700604
605 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
606}
607
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700608static 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();
Len Brown3f6f49c2012-07-26 20:08:54 -0400615 /* Reprogram control registers */
616 acpi_leave_sleep_state_prep(ACPI_STATE_S4);
Shaohua Libdfe6b72008-07-23 21:28:41 -0700617 /* 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 }
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100623 /* Restore the NVS memory area */
Matthew Garrettdd4c4f12010-05-28 16:32:14 -0400624 suspend_nvs_restore();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200625 /* Allow EC transactions to happen. */
Rafael J. Wysockife955682010-04-09 01:40:38 +0200626 acpi_ec_unblock_transactions_early();
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700627}
628
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200629static void acpi_pm_thaw(void)
Rafael J. Wysockif6bb13a2010-03-04 01:52:58 +0100630{
Rafael J. Wysockife955682010-04-09 01:40:38 +0200631 acpi_ec_unblock_transactions();
Lin Ming3d97e422008-12-16 16:57:46 +0800632 acpi_enable_all_runtime_gpes();
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700633}
634
Lionel Debroux073ef1f2010-11-09 21:48:49 +0100635static const struct platform_hibernation_ops acpi_hibernation_ops = {
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100636 .begin = acpi_hibernation_begin,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200637 .end = acpi_pm_end,
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200638 .pre_snapshot = acpi_pm_prepare,
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400639 .finish = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200640 .prepare = acpi_pm_prepare,
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700641 .enter = acpi_hibernation_enter,
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700642 .leave = acpi_hibernation_leave,
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200643 .pre_restore = acpi_pm_freeze,
644 .restore_cleanup = acpi_pm_thaw,
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700645};
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200646
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 */
653static int acpi_hibernation_begin_old(void)
654{
Zhao Yakuie49f7112008-08-12 10:20:22 +0800655 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);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200664
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100665 if (!error) {
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200666 if (!nvs_nosave)
Matthew Garrettdd4c4f12010-05-28 16:32:14 -0400667 error = suspend_nvs_alloc();
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100668 if (!error)
669 acpi_target_sleep_state = ACPI_STATE_S4;
670 }
671 return error;
672}
673
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200674/*
675 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
676 * been requested.
677 */
Lionel Debroux073ef1f2010-11-09 21:48:49 +0100678static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200679 .begin = acpi_hibernation_begin_old,
680 .end = acpi_pm_end,
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200681 .pre_snapshot = acpi_pm_pre_suspend,
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200682 .prepare = acpi_pm_freeze,
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400683 .finish = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200684 .enter = acpi_hibernation_enter,
685 .leave = acpi_hibernation_leave,
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200686 .pre_restore = acpi_pm_freeze,
687 .restore_cleanup = acpi_pm_thaw,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200688 .recover = acpi_pm_finish,
689};
690#endif /* CONFIG_HIBERNATION */
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700691
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200692int 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
Rafael J. Wysockiaa338602011-02-11 00:06:54 +0100707#ifdef CONFIG_PM
Shaohua Lifd4aff12007-07-17 22:40:25 +0200708/**
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
David Brownell2fe2de52008-06-05 01:15:40 +0200711 * @dev: device to examine; its driver model wakeup flags control
712 * whether it should be able to wake up the system
Shaohua Lifd4aff12007-07-17 22:40:25 +0200713 * @d_min_p: used to store the upper limit of allowed states range
Huang Yingee85f542012-06-23 10:23:48 +0800714 * @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
Shaohua Lifd4aff12007-07-17 22:40:25 +0200717 *
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
Huang Yingee85f542012-06-23 10:23:48 +0800731int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in)
Shaohua Lifd4aff12007-07-17 22:40:25 +0200732{
733 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
734 struct acpi_device *adev;
735 char acpi_method[] = "_SxD";
Matthew Wilcox27663c52008-10-10 02:22:59 -0400736 unsigned long long d_min, d_max;
Shaohua Lifd4aff12007-07-17 22:40:25 +0200737
Huang Yingee85f542012-06-23 10:23:48 +0800738 if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3)
739 return -EINVAL;
Shaohua Lifd4aff12007-07-17 22:40:25 +0200740 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
Shaohua Liead77592007-08-23 15:01:13 +0800741 printk(KERN_DEBUG "ACPI handle has no context!\n");
Shaohua Lifd4aff12007-07-17 22:40:25 +0200742 return -ENODEV;
743 }
744
745 acpi_method[2] = '0' + acpi_target_sleep_state;
746 /*
Huang Yingee85f542012-06-23 10:23:48 +0800747 * 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.
Shaohua Lifd4aff12007-07-17 22:40:25 +0200751 */
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 ||
Rafael J. Wysockidbe9a2e2012-05-29 21:21:07 +0200774 (device_may_wakeup(dev) && adev->wakeup.flags.valid &&
775 adev->wakeup.sleep_state >= acpi_target_sleep_state)) {
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100776 acpi_status status;
777
Shaohua Lifd4aff12007-07-17 22:40:25 +0200778 acpi_method[3] = 'W';
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100779 status = acpi_evaluate_integer(handle, acpi_method, NULL,
780 &d_max);
781 if (ACPI_FAILURE(status)) {
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200782 if (acpi_target_sleep_state != ACPI_STATE_S0 ||
783 status != AE_NOT_FOUND)
784 d_max = d_min;
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100785 } 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 */
Shaohua Lifd4aff12007-07-17 22:40:25 +0200790 d_min = d_max;
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100791 }
Shaohua Lifd4aff12007-07-17 22:40:25 +0200792 }
793
Huang Yingee85f542012-06-23 10:23:48 +0800794 if (d_max_in < d_min)
795 return -EINVAL;
Shaohua Lifd4aff12007-07-17 22:40:25 +0200796 if (d_min_p)
797 *d_min_p = d_min;
Huang Yingee85f542012-06-23 10:23:48 +0800798 /* 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 }
Shaohua Lifd4aff12007-07-17 22:40:25 +0200805 return d_max;
806}
Lin Ming3bd46602012-06-25 16:13:06 +0800807EXPORT_SYMBOL(acpi_pm_device_sleep_state);
Rafael J. Wysockiaa338602011-02-11 00:06:54 +0100808#endif /* CONFIG_PM */
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200809
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200810#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200811/**
Lin Mingb24e5092012-03-27 15:43:25 +0800812 * 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 */
819int 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}
Lin Ming3bd46602012-06-25 16:13:06 +0800844EXPORT_SYMBOL(acpi_pm_device_run_wake);
Lin Mingb24e5092012-03-27 15:43:25 +0800845
846/**
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200847 * 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 */
852int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
853{
854 acpi_handle handle;
855 struct acpi_device *adev;
Rafael J. Wysockidf8db912009-09-08 23:13:49 +0200856 int error;
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200857
Rafael J. Wysocki0baed8d2009-09-08 23:16:24 +0200858 if (!device_can_wakeup(dev))
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200859 return -EINVAL;
860
861 handle = DEVICE_ACPI_HANDLE(dev);
862 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
Rafael J. Wysockidf8db912009-09-08 23:13:49 +0200863 dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__);
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200864 return -ENODEV;
865 }
866
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +0200867 error = enable ?
868 acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
869 acpi_disable_wakeup_device_power(adev);
Rafael J. Wysockidf8db912009-09-08 23:13:49 +0200870 if (!error)
871 dev_info(dev, "wake-up capability %s by ACPI\n",
872 enable ? "enabled" : "disabled");
873
874 return error;
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200875}
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200876#endif /* CONFIG_PM_SLEEP */
Shaohua Lifd4aff12007-07-17 22:40:25 +0200877
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400878static void acpi_power_off_prepare(void)
879{
880 /* Prepare to power off the system */
881 acpi_sleep_prepare(ACPI_STATE_S5);
Lin Ming3d97e422008-12-16 16:57:46 +0800882 acpi_disable_all_gpes();
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400883}
884
885static void acpi_power_off(void)
886{
887 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
Frank Seidel4d939152009-02-04 17:03:07 +0100888 printk(KERN_DEBUG "%s called\n", __func__);
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400889 local_irq_disable();
Len Brown3f6f49c2012-07-26 20:08:54 -0400890 acpi_enter_sleep_state(ACPI_STATE_S5);
Len Brown96f15ef2009-04-17 23:32:20 -0400891}
892
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500893int __init acpi_sleep_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894{
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200895 acpi_status status;
896 u8 type_a, type_b;
897#ifdef CONFIG_SUSPEND
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500898 int i = 0;
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700899
900 dmi_check_system(acpisleep_dmi_table);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200901#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903 if (acpi_disabled)
904 return 0;
905
Frans Pop5a50fe72007-09-20 22:27:44 +0200906 sleep_states[ACPI_STATE_S0] = 1;
907 printk(KERN_INFO PREFIX "(supports S0");
908
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200909#ifdef CONFIG_SUSPEND
Frans Pop5a50fe72007-09-20 22:27:44 +0200910 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
912 if (ACPI_SUCCESS(status)) {
913 sleep_states[i] = 1;
Kay Sieversbe964472012-05-08 17:24:20 +0200914 printk(KERN_CONT " S%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200918 suspend_set_ops(old_suspend_ordering ?
919 &acpi_suspend_ops_old : &acpi_suspend_ops);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200920#endif
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700921
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200922#ifdef CONFIG_HIBERNATION
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200923 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
924 if (ACPI_SUCCESS(status)) {
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200925 hibernation_set_ops(old_suspend_ordering ?
926 &acpi_hibernation_ops_old : &acpi_hibernation_ops);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200927 sleep_states[ACPI_STATE_S4] = 1;
Kay Sieversbe964472012-05-08 17:24:20 +0200928 printk(KERN_CONT " S4");
Shaohua Libdfe6b72008-07-23 21:28:41 -0700929 if (!nosigcheck) {
Lin Ming3d97e422008-12-16 16:57:46 +0800930 acpi_get_table(ACPI_SIG_FACS, 1,
Shaohua Libdfe6b72008-07-23 21:28:41 -0700931 (struct acpi_table_header **)&facs);
932 if (facs)
933 s4_hardware_signature =
934 facs->hardware_signature;
935 }
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200936 }
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700937#endif
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400938 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;
Kay Sieversbe964472012-05-08 17:24:20 +0200941 printk(KERN_CONT " S5");
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400942 pm_power_off_prepare = acpi_power_off_prepare;
943 pm_power_off = acpi_power_off;
944 }
Kay Sieversbe964472012-05-08 17:24:20 +0200945 printk(KERN_CONT ")\n");
Zhao Yakuie49f7112008-08-12 10:20:22 +0800946 /*
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 return 0;
952}