blob: 198ff8a1529a1b7e0a5689c2d73f23570f241cb1 [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>
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +040018
19#include <asm/io.h>
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <acpi/acpi_bus.h>
22#include <acpi/acpi_drivers.h>
23#include "sleep.h"
24
25u8 sleep_states[ACPI_S_STATE_COUNT];
26
Alexey Starikovskiy853298b2007-09-25 18:45:15 +040027#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki296699d2007-07-29 23:27:18 +020028static u32 acpi_target_sleep_state = ACPI_STATE_S0;
Alexey Starikovskiy853298b2007-09-25 18:45:15 +040029#endif
Rafael J. Wysocki296699d2007-07-29 23:27:18 +020030
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020031int acpi_sleep_prepare(u32 acpi_state)
32{
33#ifdef CONFIG_ACPI_SLEEP
34 /* do we have a wakeup address for S2 and S3? */
35 if (acpi_state == ACPI_STATE_S3) {
36 if (!acpi_wakeup_address) {
37 return -EFAULT;
38 }
39 acpi_set_firmware_waking_vector((acpi_physical_address)
40 virt_to_phys((void *)
41 acpi_wakeup_address));
42
43 }
44 ACPI_FLUSH_CPU_CACHE();
45 acpi_enable_wakeup_device_prep(acpi_state);
46#endif
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020047 acpi_enter_sleep_state_prep(acpi_state);
48 return 0;
49}
50
Rafael J. Wysocki296699d2007-07-29 23:27:18 +020051#ifdef CONFIG_SUSPEND
Rafael J. Wysocki26398a72007-10-18 03:04:40 -070052static struct platform_suspend_ops acpi_pm_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Linus Torvalds1da177e2005-04-16 15:20:36 -070054extern void do_suspend_lowlevel(void);
55
56static u32 acpi_suspend_states[] = {
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -050057 [PM_SUSPEND_ON] = ACPI_STATE_S0,
58 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
59 [PM_SUSPEND_MEM] = ACPI_STATE_S3,
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -050060 [PM_SUSPEND_MAX] = ACPI_STATE_S5
Linus Torvalds1da177e2005-04-16 15:20:36 -070061};
62
63static int init_8259A_after_S1;
64
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +020065/**
Rafael J. Wysockic697eec2008-01-08 00:04:17 +010066 * acpi_pm_begin - Set the target system sleep state to the state
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +020067 * associated with given @pm_state, if supported.
68 */
69
Rafael J. Wysockic697eec2008-01-08 00:04:17 +010070static int acpi_pm_begin(suspend_state_t pm_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
72 u32 acpi_state = acpi_suspend_states[pm_state];
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +020073 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +020075 if (sleep_states[acpi_state]) {
76 acpi_target_sleep_state = acpi_state;
77 } else {
78 printk(KERN_ERR "ACPI does not support this state: %d\n",
79 pm_state);
80 error = -ENOSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 }
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +020082 return error;
83}
84
85/**
86 * acpi_pm_prepare - Do preliminary suspend work.
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +020087 *
88 * If necessary, set the firmware waking vector and do arch-specific
89 * nastiness to get the wakeup code to the waking vector.
90 */
91
Rafael J. Wysockie6c5eb92007-10-18 03:04:41 -070092static int acpi_pm_prepare(void)
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +020093{
Rafael J. Wysocki3c1d2b62008-01-08 00:06:16 +010094 int error;
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +020095
Rafael J. Wysocki3c1d2b62008-01-08 00:06:16 +010096 error = acpi_sleep_prepare(acpi_target_sleep_state);
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +020097 if (error)
98 acpi_target_sleep_state = ACPI_STATE_S0;
Rafael J. Wysocki3c1d2b62008-01-08 00:06:16 +010099 else if (!ACPI_SUCCESS(acpi_hw_disable_all_gpes()))
100 error = -EFAULT;
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200101
102 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105/**
106 * acpi_pm_enter - Actually enter a sleep state.
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200107 * @pm_state: ignored
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 *
Rafael J. Wysocki50ad1472007-07-24 11:58:39 +0200109 * Flush caches and go to sleep. For STR we have to call arch-specific
110 * assembly, which in turn call acpi_enter_sleep_state().
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 * It's unfortunate, but it works. Please fix if you're feeling frisky.
112 */
113
114static int acpi_pm_enter(suspend_state_t pm_state)
115{
116 acpi_status status = AE_OK;
117 unsigned long flags = 0;
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200118 u32 acpi_state = acpi_target_sleep_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120 ACPI_FLUSH_CPU_CACHE();
121
122 /* Do arch specific saving of state. */
Rafael J. Wysocki50ad1472007-07-24 11:58:39 +0200123 if (acpi_state == ACPI_STATE_S3) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 int error = acpi_save_state_mem();
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200125
126 if (error) {
127 acpi_target_sleep_state = ACPI_STATE_S0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 return error;
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200129 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 local_irq_save(flags);
133 acpi_enable_wakeup_device(acpi_state);
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200134 switch (acpi_state) {
135 case ACPI_STATE_S1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 barrier();
137 status = acpi_enter_sleep_state(acpi_state);
138 break;
139
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200140 case ACPI_STATE_S3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 do_suspend_lowlevel();
142 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
Arnaud Patard872d83d2006-04-27 05:25:00 -0400144
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100145 /* Reprogram control registers and execute _BFS */
146 acpi_leave_sleep_state_prep(acpi_state);
147
Arnaud Patard872d83d2006-04-27 05:25:00 -0400148 /* ACPI 3.0 specs (P62) says that it's the responsabilty
149 * of the OSPM to clear the status bit [ implying that the
150 * POWER_BUTTON event should not reach userspace ]
151 */
152 if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3))
153 acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
154
Shaohua Lia3627f62007-06-20 09:17:58 +0800155 /*
156 * Disable and clear GPE status before interrupt is enabled. Some GPEs
157 * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
158 * acpi_leave_sleep_state will reenable specific GPEs later
159 */
160 acpi_hw_disable_all_gpes();
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 local_irq_restore(flags);
163 printk(KERN_DEBUG "Back to C!\n");
164
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200165 /* restore processor state */
Rafael J. Wysocki50ad1472007-07-24 11:58:39 +0200166 if (acpi_state == ACPI_STATE_S3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 acpi_restore_state_mem();
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
170}
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172/**
Rafael J. Wysockic697eec2008-01-08 00:04:17 +0100173 * acpi_pm_finish - Instruct the platform to leave a sleep state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 *
175 * This is called after we wake back up (or if entering the sleep state
176 * failed).
177 */
178
Rafael J. Wysockie6c5eb92007-10-18 03:04:41 -0700179static void acpi_pm_finish(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200181 u32 acpi_state = acpi_target_sleep_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 acpi_disable_wakeup_device(acpi_state);
Alexey Starikovskiy1dbc1fda2007-10-22 14:18:12 +0400184 acpi_leave_sleep_state(acpi_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 /* reset firmware waking vector */
187 acpi_set_firmware_waking_vector((acpi_physical_address) 0);
188
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200189 acpi_target_sleep_state = ACPI_STATE_S0;
190
Len Browne8b2fd02007-07-24 22:26:33 -0400191#ifdef CONFIG_X86
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 if (init_8259A_after_S1) {
193 printk("Broken toshiba laptop -> kicking interrupts\n");
194 init_8259A(0);
195 }
Len Browne8b2fd02007-07-24 22:26:33 -0400196#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197}
198
Rafael J. Wysockic697eec2008-01-08 00:04:17 +0100199/**
200 * acpi_pm_end - Finish up suspend sequence.
201 */
202
203static void acpi_pm_end(void)
204{
205 /*
206 * This is necessary in case acpi_pm_finish() is not called during a
207 * failing transition to a sleep state.
208 */
209 acpi_target_sleep_state = ACPI_STATE_S0;
210}
211
Shaohua Lieb9289e2005-10-30 15:00:01 -0800212static int acpi_pm_state_valid(suspend_state_t pm_state)
213{
Johannes Berge8c9c502007-04-30 15:09:54 -0700214 u32 acpi_state;
Shaohua Lieb9289e2005-10-30 15:00:01 -0800215
Johannes Berge8c9c502007-04-30 15:09:54 -0700216 switch (pm_state) {
217 case PM_SUSPEND_ON:
218 case PM_SUSPEND_STANDBY:
219 case PM_SUSPEND_MEM:
220 acpi_state = acpi_suspend_states[pm_state];
221
222 return sleep_states[acpi_state];
223 default:
224 return 0;
225 }
Shaohua Lieb9289e2005-10-30 15:00:01 -0800226}
227
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700228static struct platform_suspend_ops acpi_pm_ops = {
Shaohua Lieb9289e2005-10-30 15:00:01 -0800229 .valid = acpi_pm_state_valid,
Rafael J. Wysockic697eec2008-01-08 00:04:17 +0100230 .begin = acpi_pm_begin,
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500231 .prepare = acpi_pm_prepare,
232 .enter = acpi_pm_enter,
233 .finish = acpi_pm_finish,
Rafael J. Wysockic697eec2008-01-08 00:04:17 +0100234 .end = acpi_pm_end,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235};
236
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200237/*
238 * Toshiba fails to preserve interrupts over S1, reinitialization
239 * of 8259 is needed after S1 resume.
240 */
Jeff Garzik18552562007-10-03 15:15:40 -0400241static int __init init_ints_after_s1(const struct dmi_system_id *d)
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200242{
243 printk(KERN_WARNING "%s with broken S1 detected.\n", d->ident);
244 init_8259A_after_S1 = 1;
245 return 0;
246}
247
248static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
249 {
250 .callback = init_ints_after_s1,
251 .ident = "Toshiba Satellite 4030cdt",
252 .matches = {DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),},
253 },
254 {},
255};
256#endif /* CONFIG_SUSPEND */
257
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200258#ifdef CONFIG_HIBERNATION
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700259static int acpi_hibernation_start(void)
260{
261 acpi_target_sleep_state = ACPI_STATE_S4;
262 return 0;
263}
264
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700265static int acpi_hibernation_prepare(void)
266{
Rafael J. Wysocki3c1d2b62008-01-08 00:06:16 +0100267 int error;
268
269 error = acpi_sleep_prepare(ACPI_STATE_S4);
270 if (error)
271 return error;
272
273 if (!ACPI_SUCCESS(acpi_hw_disable_all_gpes()))
274 error = -EFAULT;
275
276 return error;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700277}
278
279static int acpi_hibernation_enter(void)
280{
281 acpi_status status = AE_OK;
282 unsigned long flags = 0;
283
284 ACPI_FLUSH_CPU_CACHE();
285
286 local_irq_save(flags);
287 acpi_enable_wakeup_device(ACPI_STATE_S4);
288 /* This shouldn't return. If it returns, we have a problem */
289 status = acpi_enter_sleep_state(ACPI_STATE_S4);
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100290 /* Reprogram control registers and execute _BFS */
291 acpi_leave_sleep_state_prep(ACPI_STATE_S4);
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700292 local_irq_restore(flags);
293
294 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
295}
296
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700297static void acpi_hibernation_leave(void)
298{
299 /*
300 * If ACPI is not enabled by the BIOS and the boot kernel, we need to
301 * enable it here.
302 */
303 acpi_enable();
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100304 /* Reprogram control registers and execute _BFS */
305 acpi_leave_sleep_state_prep(ACPI_STATE_S4);
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700306}
307
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700308static void acpi_hibernation_finish(void)
309{
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700310 acpi_disable_wakeup_device(ACPI_STATE_S4);
Alexey Starikovskiy1dbc1fda2007-10-22 14:18:12 +0400311 acpi_leave_sleep_state(ACPI_STATE_S4);
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700312
313 /* reset firmware waking vector */
314 acpi_set_firmware_waking_vector((acpi_physical_address) 0);
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700315
316 acpi_target_sleep_state = ACPI_STATE_S0;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700317}
318
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700319static int acpi_hibernation_pre_restore(void)
320{
321 acpi_status status;
322
323 status = acpi_hw_disable_all_gpes();
324
325 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
326}
327
328static void acpi_hibernation_restore_cleanup(void)
329{
330 acpi_hw_enable_all_runtime_gpes();
331}
332
Rafael J. Wysockib3dac3b2007-10-18 03:04:43 -0700333static struct platform_hibernation_ops acpi_hibernation_ops = {
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700334 .start = acpi_hibernation_start,
335 .pre_snapshot = acpi_hibernation_prepare,
336 .finish = acpi_hibernation_finish,
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700337 .prepare = acpi_hibernation_prepare,
338 .enter = acpi_hibernation_enter,
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700339 .leave = acpi_hibernation_leave,
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700340 .pre_restore = acpi_hibernation_pre_restore,
341 .restore_cleanup = acpi_hibernation_restore_cleanup,
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700342};
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200343#endif /* CONFIG_HIBERNATION */
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700344
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200345int acpi_suspend(u32 acpi_state)
346{
347 suspend_state_t states[] = {
348 [1] = PM_SUSPEND_STANDBY,
349 [3] = PM_SUSPEND_MEM,
350 [5] = PM_SUSPEND_MAX
351 };
352
353 if (acpi_state < 6 && states[acpi_state])
354 return pm_suspend(states[acpi_state]);
355 if (acpi_state == 4)
356 return hibernate();
357 return -EINVAL;
358}
359
Alexey Starikovskiy853298b2007-09-25 18:45:15 +0400360#ifdef CONFIG_PM_SLEEP
Shaohua Lifd4aff12007-07-17 22:40:25 +0200361/**
362 * acpi_pm_device_sleep_state - return preferred power state of ACPI device
363 * in the system sleep state given by %acpi_target_sleep_state
364 * @dev: device to examine
365 * @wake: if set, the device should be able to wake up the system
366 * @d_min_p: used to store the upper limit of allowed states range
367 * Return value: preferred power state of the device on success, -ENODEV on
368 * failure (ie. if there's no 'struct acpi_device' for @dev)
369 *
370 * Find the lowest power (highest number) ACPI device power state that
371 * device @dev can be in while the system is in the sleep state represented
372 * by %acpi_target_sleep_state. If @wake is nonzero, the device should be
373 * able to wake up the system from this sleep state. If @d_min_p is set,
374 * the highest power (lowest number) device power state of @dev allowed
375 * in this system sleep state is stored at the location pointed to by it.
376 *
377 * The caller must ensure that @dev is valid before using this function.
378 * The caller is also responsible for figuring out if the device is
379 * supposed to be able to wake up the system and passing this information
380 * via @wake.
381 */
382
383int acpi_pm_device_sleep_state(struct device *dev, int wake, int *d_min_p)
384{
385 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
386 struct acpi_device *adev;
387 char acpi_method[] = "_SxD";
388 unsigned long d_min, d_max;
389
390 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
Shaohua Liead77592007-08-23 15:01:13 +0800391 printk(KERN_DEBUG "ACPI handle has no context!\n");
Shaohua Lifd4aff12007-07-17 22:40:25 +0200392 return -ENODEV;
393 }
394
395 acpi_method[2] = '0' + acpi_target_sleep_state;
396 /*
397 * If the sleep state is S0, we will return D3, but if the device has
398 * _S0W, we will use the value from _S0W
399 */
400 d_min = ACPI_STATE_D0;
401 d_max = ACPI_STATE_D3;
402
403 /*
404 * If present, _SxD methods return the minimum D-state (highest power
405 * state) we can use for the corresponding S-states. Otherwise, the
406 * minimum D-state is D0 (ACPI 3.x).
407 *
408 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
409 * provided -- that's our fault recovery, we ignore retval.
410 */
411 if (acpi_target_sleep_state > ACPI_STATE_S0)
412 acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
413
414 /*
415 * If _PRW says we can wake up the system from the target sleep state,
416 * the D-state returned by _SxD is sufficient for that (we assume a
417 * wakeup-aware driver if wake is set). Still, if _SxW exists
418 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
419 * can wake the system. _S0W may be valid, too.
420 */
421 if (acpi_target_sleep_state == ACPI_STATE_S0 ||
422 (wake && adev->wakeup.state.enabled &&
423 adev->wakeup.sleep_state <= acpi_target_sleep_state)) {
424 acpi_method[3] = 'W';
425 acpi_evaluate_integer(handle, acpi_method, NULL, &d_max);
426 /* Sanity check */
427 if (d_max < d_min)
428 d_min = d_max;
429 }
430
431 if (d_min_p)
432 *d_min_p = d_min;
433 return d_max;
434}
Alexey Starikovskiy853298b2007-09-25 18:45:15 +0400435#endif
Shaohua Lifd4aff12007-07-17 22:40:25 +0200436
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400437static void acpi_power_off_prepare(void)
438{
439 /* Prepare to power off the system */
440 acpi_sleep_prepare(ACPI_STATE_S5);
Rafael J. Wysocki3c1d2b62008-01-08 00:06:16 +0100441 acpi_hw_disable_all_gpes();
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400442}
443
444static void acpi_power_off(void)
445{
446 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
447 printk("%s called\n", __FUNCTION__);
448 local_irq_disable();
Alexey Starikovskiy9c1c6a12007-10-22 14:18:06 +0400449 acpi_enable_wakeup_device(ACPI_STATE_S5);
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400450 acpi_enter_sleep_state(ACPI_STATE_S5);
451}
452
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500453int __init acpi_sleep_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200455 acpi_status status;
456 u8 type_a, type_b;
457#ifdef CONFIG_SUSPEND
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500458 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 dmi_check_system(acpisleep_dmi_table);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200461#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 if (acpi_disabled)
464 return 0;
465
Frans Pop5a50fe72007-09-20 22:27:44 +0200466 sleep_states[ACPI_STATE_S0] = 1;
467 printk(KERN_INFO PREFIX "(supports S0");
468
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200469#ifdef CONFIG_SUSPEND
Frans Pop5a50fe72007-09-20 22:27:44 +0200470 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
472 if (ACPI_SUCCESS(status)) {
473 sleep_states[i] = 1;
474 printk(" S%d", i);
475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700478 suspend_set_ops(&acpi_pm_ops);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200479#endif
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700480
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200481#ifdef CONFIG_HIBERNATION
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200482 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
483 if (ACPI_SUCCESS(status)) {
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700484 hibernation_set_ops(&acpi_hibernation_ops);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200485 sleep_states[ACPI_STATE_S4] = 1;
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400486 printk(" S4");
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200487 }
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700488#endif
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400489 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
490 if (ACPI_SUCCESS(status)) {
491 sleep_states[ACPI_STATE_S5] = 1;
492 printk(" S5");
493 pm_power_off_prepare = acpi_power_off_prepare;
494 pm_power_off = acpi_power_off;
495 }
496 printk(")\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 return 0;
498}