2 * sleep.c - ACPI sleep support.
4 * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
5 * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com>
6 * Copyright (c) 2000-2003 Patrick Mochel
7 * Copyright (c) 2003 Open Source Development Lab
9 * This file is released under the GPLv2.
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>
18 #include <linux/reboot.h>
19 #include <linux/acpi.h>
20 #include <linux/module.h>
21 #include <linux/pm_runtime.h>
25 #include <acpi/acpi_bus.h>
26 #include <acpi/acpi_drivers.h>
31 u8 wake_sleep_flags
= ACPI_NO_OPTIONAL_METHODS
;
32 static unsigned int gts
, bfs
;
33 static int set_param_wake_flag(const char *val
, struct kernel_param
*kp
)
35 int ret
= param_set_int(val
, kp
);
40 if (kp
->arg
== (const char *)>s
) {
42 wake_sleep_flags
|= ACPI_EXECUTE_GTS
;
44 wake_sleep_flags
&= ~ACPI_EXECUTE_GTS
;
46 if (kp
->arg
== (const char *)&bfs
) {
48 wake_sleep_flags
|= ACPI_EXECUTE_BFS
;
50 wake_sleep_flags
&= ~ACPI_EXECUTE_BFS
;
54 module_param_call(gts
, set_param_wake_flag
, param_get_int
, >s
, 0644);
55 module_param_call(bfs
, set_param_wake_flag
, param_get_int
, &bfs
, 0644);
56 MODULE_PARM_DESC(gts
, "Enable evaluation of _GTS on suspend.");
57 MODULE_PARM_DESC(bfs
, "Enable evaluation of _BFS on resume".);
59 static u8 sleep_states
[ACPI_S_STATE_COUNT
];
61 static void acpi_sleep_tts_switch(u32 acpi_state
)
63 union acpi_object in_arg
= { ACPI_TYPE_INTEGER
};
64 struct acpi_object_list arg_list
= { 1, &in_arg
};
65 acpi_status status
= AE_OK
;
67 in_arg
.integer
.value
= acpi_state
;
68 status
= acpi_evaluate_object(NULL
, "\\_TTS", &arg_list
, NULL
);
69 if (ACPI_FAILURE(status
) && status
!= AE_NOT_FOUND
) {
71 * OS can't evaluate the _TTS object correctly. Some warning
72 * message will be printed. But it won't break anything.
74 printk(KERN_NOTICE
"Failure in evaluating _TTS object\n");
78 static int tts_notify_reboot(struct notifier_block
*this,
79 unsigned long code
, void *x
)
81 acpi_sleep_tts_switch(ACPI_STATE_S5
);
85 static struct notifier_block tts_notifier
= {
86 .notifier_call
= tts_notify_reboot
,
91 static int acpi_sleep_prepare(u32 acpi_state
)
93 #ifdef CONFIG_ACPI_SLEEP
94 /* do we have a wakeup address for S2 and S3? */
95 if (acpi_state
== ACPI_STATE_S3
) {
96 if (!acpi_wakeup_address
) {
99 acpi_set_firmware_waking_vector(
100 (acpi_physical_address
)acpi_wakeup_address
);
103 ACPI_FLUSH_CPU_CACHE();
105 printk(KERN_INFO PREFIX
"Preparing to enter system sleep state S%d\n",
107 acpi_enable_wakeup_devices(acpi_state
);
108 acpi_enter_sleep_state_prep(acpi_state
);
112 #ifdef CONFIG_ACPI_SLEEP
113 static u32 acpi_target_sleep_state
= ACPI_STATE_S0
;
116 * The ACPI specification wants us to save NVS memory regions during hibernation
117 * and to restore them during the subsequent resume. Windows does that also for
118 * suspend to RAM. However, it is known that this mechanism does not work on
119 * all machines, so we allow the user to disable it with the help of the
120 * 'acpi_sleep=nonvs' kernel command line option.
122 static bool nvs_nosave
;
124 void __init
acpi_nvs_nosave(void)
130 * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
131 * user to request that behavior by using the 'acpi_old_suspend_ordering'
132 * kernel command line option that causes the following variable to be set.
134 static bool old_suspend_ordering
;
136 void __init
acpi_old_suspend_ordering(void)
138 old_suspend_ordering
= true;
142 * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
144 static int acpi_pm_freeze(void)
146 acpi_disable_all_gpes();
147 acpi_os_wait_events_complete(NULL
);
148 acpi_ec_block_transactions();
153 * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
155 static int acpi_pm_pre_suspend(void)
158 return suspend_nvs_save();
162 * __acpi_pm_prepare - Prepare the platform to enter the target state.
164 * If necessary, set the firmware waking vector and do arch-specific
165 * nastiness to get the wakeup code to the waking vector.
167 static int __acpi_pm_prepare(void)
169 int error
= acpi_sleep_prepare(acpi_target_sleep_state
);
171 acpi_target_sleep_state
= ACPI_STATE_S0
;
177 * acpi_pm_prepare - Prepare the platform to enter the target sleep
178 * state and disable the GPEs.
180 static int acpi_pm_prepare(void)
182 int error
= __acpi_pm_prepare();
184 error
= acpi_pm_pre_suspend();
190 * acpi_pm_finish - Instruct the platform to leave a sleep state.
192 * This is called after we wake back up (or if entering the sleep state
195 static void acpi_pm_finish(void)
197 u32 acpi_state
= acpi_target_sleep_state
;
199 acpi_ec_unblock_transactions();
202 if (acpi_state
== ACPI_STATE_S0
)
205 printk(KERN_INFO PREFIX
"Waking up from system sleep state S%d\n",
207 acpi_disable_wakeup_devices(acpi_state
);
208 acpi_leave_sleep_state(acpi_state
);
210 /* reset firmware waking vector */
211 acpi_set_firmware_waking_vector((acpi_physical_address
) 0);
213 acpi_target_sleep_state
= ACPI_STATE_S0
;
217 * acpi_pm_end - Finish up suspend sequence.
219 static void acpi_pm_end(void)
222 * This is necessary in case acpi_pm_finish() is not called during a
223 * failing transition to a sleep state.
225 acpi_target_sleep_state
= ACPI_STATE_S0
;
226 acpi_sleep_tts_switch(acpi_target_sleep_state
);
228 #else /* !CONFIG_ACPI_SLEEP */
229 #define acpi_target_sleep_state ACPI_STATE_S0
230 #endif /* CONFIG_ACPI_SLEEP */
232 #ifdef CONFIG_SUSPEND
233 static u32 acpi_suspend_states
[] = {
234 [PM_SUSPEND_ON
] = ACPI_STATE_S0
,
235 [PM_SUSPEND_STANDBY
] = ACPI_STATE_S1
,
236 [PM_SUSPEND_MEM
] = ACPI_STATE_S3
,
237 [PM_SUSPEND_MAX
] = ACPI_STATE_S5
241 * acpi_suspend_begin - Set the target system sleep state to the state
242 * associated with given @pm_state, if supported.
244 static int acpi_suspend_begin(suspend_state_t pm_state
)
246 u32 acpi_state
= acpi_suspend_states
[pm_state
];
249 error
= nvs_nosave
? 0 : suspend_nvs_alloc();
253 if (sleep_states
[acpi_state
]) {
254 acpi_target_sleep_state
= acpi_state
;
255 acpi_sleep_tts_switch(acpi_target_sleep_state
);
257 printk(KERN_ERR
"ACPI does not support this state: %d\n",
265 * acpi_suspend_enter - Actually enter a sleep state.
268 * Flush caches and go to sleep. For STR we have to call arch-specific
269 * assembly, which in turn call acpi_enter_sleep_state().
270 * It's unfortunate, but it works. Please fix if you're feeling frisky.
272 static int acpi_suspend_enter(suspend_state_t pm_state
)
274 acpi_status status
= AE_OK
;
275 u32 acpi_state
= acpi_target_sleep_state
;
278 ACPI_FLUSH_CPU_CACHE();
280 switch (acpi_state
) {
283 status
= acpi_enter_sleep_state(acpi_state
, wake_sleep_flags
);
287 error
= acpi_suspend_lowlevel();
290 pr_info(PREFIX
"Low-level resume complete\n");
294 /* This violates the spec but is required for bug compatibility. */
295 acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE
, 1);
297 /* Reprogram control registers and execute _BFS */
298 acpi_leave_sleep_state_prep(acpi_state
, wake_sleep_flags
);
300 /* ACPI 3.0 specs (P62) says that it's the responsibility
301 * of the OSPM to clear the status bit [ implying that the
302 * POWER_BUTTON event should not reach userspace ]
304 if (ACPI_SUCCESS(status
) && (acpi_state
== ACPI_STATE_S3
))
305 acpi_clear_event(ACPI_EVENT_POWER_BUTTON
);
308 * Disable and clear GPE status before interrupt is enabled. Some GPEs
309 * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
310 * acpi_leave_sleep_state will reenable specific GPEs later
312 acpi_disable_all_gpes();
313 /* Allow EC transactions to happen. */
314 acpi_ec_unblock_transactions_early();
316 suspend_nvs_restore();
318 return ACPI_SUCCESS(status
) ? 0 : -EFAULT
;
321 static int acpi_suspend_state_valid(suspend_state_t pm_state
)
327 case PM_SUSPEND_STANDBY
:
329 acpi_state
= acpi_suspend_states
[pm_state
];
331 return sleep_states
[acpi_state
];
337 static const struct platform_suspend_ops acpi_suspend_ops
= {
338 .valid
= acpi_suspend_state_valid
,
339 .begin
= acpi_suspend_begin
,
340 .prepare_late
= acpi_pm_prepare
,
341 .enter
= acpi_suspend_enter
,
342 .wake
= acpi_pm_finish
,
347 * acpi_suspend_begin_old - Set the target system sleep state to the
348 * state associated with given @pm_state, if supported, and
349 * execute the _PTS control method. This function is used if the
350 * pre-ACPI 2.0 suspend ordering has been requested.
352 static int acpi_suspend_begin_old(suspend_state_t pm_state
)
354 int error
= acpi_suspend_begin(pm_state
);
356 error
= __acpi_pm_prepare();
362 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
365 static const struct platform_suspend_ops acpi_suspend_ops_old
= {
366 .valid
= acpi_suspend_state_valid
,
367 .begin
= acpi_suspend_begin_old
,
368 .prepare_late
= acpi_pm_pre_suspend
,
369 .enter
= acpi_suspend_enter
,
370 .wake
= acpi_pm_finish
,
372 .recover
= acpi_pm_finish
,
375 static int __init
init_old_suspend_ordering(const struct dmi_system_id
*d
)
377 old_suspend_ordering
= true;
381 static int __init
init_nvs_nosave(const struct dmi_system_id
*d
)
387 static struct dmi_system_id __initdata acpisleep_dmi_table
[] = {
389 .callback
= init_old_suspend_ordering
,
390 .ident
= "Abit KN9 (nForce4 variant)",
392 DMI_MATCH(DMI_BOARD_VENDOR
, "http://www.abit.com.tw/"),
393 DMI_MATCH(DMI_BOARD_NAME
, "KN9 Series(NF-CK804)"),
397 .callback
= init_old_suspend_ordering
,
398 .ident
= "HP xw4600 Workstation",
400 DMI_MATCH(DMI_SYS_VENDOR
, "Hewlett-Packard"),
401 DMI_MATCH(DMI_PRODUCT_NAME
, "HP xw4600 Workstation"),
405 .callback
= init_old_suspend_ordering
,
406 .ident
= "Asus Pundit P1-AH2 (M2N8L motherboard)",
408 DMI_MATCH(DMI_BOARD_VENDOR
, "ASUSTek Computer INC."),
409 DMI_MATCH(DMI_BOARD_NAME
, "M2N8L"),
413 .callback
= init_old_suspend_ordering
,
414 .ident
= "Panasonic CF51-2L",
416 DMI_MATCH(DMI_BOARD_VENDOR
,
417 "Matsushita Electric Industrial Co.,Ltd."),
418 DMI_MATCH(DMI_BOARD_NAME
, "CF51-2L"),
422 .callback
= init_nvs_nosave
,
423 .ident
= "Sony Vaio VGN-FW21E",
425 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
426 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-FW21E"),
430 .callback
= init_nvs_nosave
,
431 .ident
= "Sony Vaio VPCEB17FX",
433 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
434 DMI_MATCH(DMI_PRODUCT_NAME
, "VPCEB17FX"),
438 .callback
= init_nvs_nosave
,
439 .ident
= "Sony Vaio VGN-SR11M",
441 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
442 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-SR11M"),
446 .callback
= init_nvs_nosave
,
447 .ident
= "Everex StepNote Series",
449 DMI_MATCH(DMI_SYS_VENDOR
, "Everex Systems, Inc."),
450 DMI_MATCH(DMI_PRODUCT_NAME
, "Everex StepNote Series"),
454 .callback
= init_nvs_nosave
,
455 .ident
= "Sony Vaio VPCEB1Z1E",
457 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
458 DMI_MATCH(DMI_PRODUCT_NAME
, "VPCEB1Z1E"),
462 .callback
= init_nvs_nosave
,
463 .ident
= "Sony Vaio VGN-NW130D",
465 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
466 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-NW130D"),
470 .callback
= init_nvs_nosave
,
471 .ident
= "Sony Vaio VPCCW29FX",
473 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
474 DMI_MATCH(DMI_PRODUCT_NAME
, "VPCCW29FX"),
478 .callback
= init_nvs_nosave
,
479 .ident
= "Averatec AV1020-ED2",
481 DMI_MATCH(DMI_SYS_VENDOR
, "AVERATEC"),
482 DMI_MATCH(DMI_PRODUCT_NAME
, "1000 Series"),
486 .callback
= init_old_suspend_ordering
,
487 .ident
= "Asus A8N-SLI DELUXE",
489 DMI_MATCH(DMI_BOARD_VENDOR
, "ASUSTeK Computer INC."),
490 DMI_MATCH(DMI_BOARD_NAME
, "A8N-SLI DELUXE"),
494 .callback
= init_old_suspend_ordering
,
495 .ident
= "Asus A8N-SLI Premium",
497 DMI_MATCH(DMI_BOARD_VENDOR
, "ASUSTeK Computer INC."),
498 DMI_MATCH(DMI_BOARD_NAME
, "A8N-SLI Premium"),
502 .callback
= init_nvs_nosave
,
503 .ident
= "Sony Vaio VGN-SR26GN_P",
505 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
506 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-SR26GN_P"),
510 .callback
= init_nvs_nosave
,
511 .ident
= "Sony Vaio VGN-FW520F",
513 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
514 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-FW520F"),
518 .callback
= init_nvs_nosave
,
519 .ident
= "Asus K54C",
521 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
522 DMI_MATCH(DMI_PRODUCT_NAME
, "K54C"),
526 .callback
= init_nvs_nosave
,
527 .ident
= "Asus K54HR",
529 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
530 DMI_MATCH(DMI_PRODUCT_NAME
, "K54HR"),
535 #endif /* CONFIG_SUSPEND */
537 #ifdef CONFIG_HIBERNATION
538 static unsigned long s4_hardware_signature
;
539 static struct acpi_table_facs
*facs
;
540 static bool nosigcheck
;
542 void __init
acpi_no_s4_hw_signature(void)
547 static int acpi_hibernation_begin(void)
551 error
= nvs_nosave
? 0 : suspend_nvs_alloc();
553 acpi_target_sleep_state
= ACPI_STATE_S4
;
554 acpi_sleep_tts_switch(acpi_target_sleep_state
);
560 static int acpi_hibernation_enter(void)
562 acpi_status status
= AE_OK
;
564 ACPI_FLUSH_CPU_CACHE();
566 /* This shouldn't return. If it returns, we have a problem */
567 status
= acpi_enter_sleep_state(ACPI_STATE_S4
, wake_sleep_flags
);
568 /* Reprogram control registers and execute _BFS */
569 acpi_leave_sleep_state_prep(ACPI_STATE_S4
, wake_sleep_flags
);
571 return ACPI_SUCCESS(status
) ? 0 : -EFAULT
;
574 static void acpi_hibernation_leave(void)
577 * If ACPI is not enabled by the BIOS and the boot kernel, we need to
581 /* Reprogram control registers and execute _BFS */
582 acpi_leave_sleep_state_prep(ACPI_STATE_S4
, wake_sleep_flags
);
583 /* Check the hardware signature */
584 if (facs
&& s4_hardware_signature
!= facs
->hardware_signature
) {
585 printk(KERN_EMERG
"ACPI: Hardware changed while hibernated, "
587 panic("ACPI S4 hardware signature mismatch");
589 /* Restore the NVS memory area */
590 suspend_nvs_restore();
591 /* Allow EC transactions to happen. */
592 acpi_ec_unblock_transactions_early();
595 static void acpi_pm_thaw(void)
597 acpi_ec_unblock_transactions();
598 acpi_enable_all_runtime_gpes();
601 static const struct platform_hibernation_ops acpi_hibernation_ops
= {
602 .begin
= acpi_hibernation_begin
,
604 .pre_snapshot
= acpi_pm_prepare
,
605 .finish
= acpi_pm_finish
,
606 .prepare
= acpi_pm_prepare
,
607 .enter
= acpi_hibernation_enter
,
608 .leave
= acpi_hibernation_leave
,
609 .pre_restore
= acpi_pm_freeze
,
610 .restore_cleanup
= acpi_pm_thaw
,
614 * acpi_hibernation_begin_old - Set the target system sleep state to
615 * ACPI_STATE_S4 and execute the _PTS control method. This
616 * function is used if the pre-ACPI 2.0 suspend ordering has been
619 static int acpi_hibernation_begin_old(void)
623 * The _TTS object should always be evaluated before the _PTS object.
624 * When the old_suspended_ordering is true, the _PTS object is
625 * evaluated in the acpi_sleep_prepare.
627 acpi_sleep_tts_switch(ACPI_STATE_S4
);
629 error
= acpi_sleep_prepare(ACPI_STATE_S4
);
633 error
= suspend_nvs_alloc();
635 acpi_target_sleep_state
= ACPI_STATE_S4
;
641 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
644 static const struct platform_hibernation_ops acpi_hibernation_ops_old
= {
645 .begin
= acpi_hibernation_begin_old
,
647 .pre_snapshot
= acpi_pm_pre_suspend
,
648 .prepare
= acpi_pm_freeze
,
649 .finish
= acpi_pm_finish
,
650 .enter
= acpi_hibernation_enter
,
651 .leave
= acpi_hibernation_leave
,
652 .pre_restore
= acpi_pm_freeze
,
653 .restore_cleanup
= acpi_pm_thaw
,
654 .recover
= acpi_pm_finish
,
656 #endif /* CONFIG_HIBERNATION */
658 int acpi_suspend(u32 acpi_state
)
660 suspend_state_t states
[] = {
661 [1] = PM_SUSPEND_STANDBY
,
662 [3] = PM_SUSPEND_MEM
,
666 if (acpi_state
< 6 && states
[acpi_state
])
667 return pm_suspend(states
[acpi_state
]);
675 * acpi_pm_device_sleep_state - return preferred power state of ACPI device
676 * in the system sleep state given by %acpi_target_sleep_state
677 * @dev: device to examine; its driver model wakeup flags control
678 * whether it should be able to wake up the system
679 * @d_min_p: used to store the upper limit of allowed states range
680 * Return value: preferred power state of the device on success, -ENODEV on
681 * failure (ie. if there's no 'struct acpi_device' for @dev)
683 * Find the lowest power (highest number) ACPI device power state that
684 * device @dev can be in while the system is in the sleep state represented
685 * by %acpi_target_sleep_state. If @wake is nonzero, the device should be
686 * able to wake up the system from this sleep state. If @d_min_p is set,
687 * the highest power (lowest number) device power state of @dev allowed
688 * in this system sleep state is stored at the location pointed to by it.
690 * The caller must ensure that @dev is valid before using this function.
691 * The caller is also responsible for figuring out if the device is
692 * supposed to be able to wake up the system and passing this information
696 int acpi_pm_device_sleep_state(struct device
*dev
, int *d_min_p
)
698 acpi_handle handle
= DEVICE_ACPI_HANDLE(dev
);
699 struct acpi_device
*adev
;
700 char acpi_method
[] = "_SxD";
701 unsigned long long d_min
, d_max
;
703 if (!handle
|| ACPI_FAILURE(acpi_bus_get_device(handle
, &adev
))) {
704 printk(KERN_DEBUG
"ACPI handle has no context!\n");
708 acpi_method
[2] = '0' + acpi_target_sleep_state
;
710 * If the sleep state is S0, we will return D3, but if the device has
711 * _S0W, we will use the value from _S0W
713 d_min
= ACPI_STATE_D0
;
714 d_max
= ACPI_STATE_D3
;
717 * If present, _SxD methods return the minimum D-state (highest power
718 * state) we can use for the corresponding S-states. Otherwise, the
719 * minimum D-state is D0 (ACPI 3.x).
721 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
722 * provided -- that's our fault recovery, we ignore retval.
724 if (acpi_target_sleep_state
> ACPI_STATE_S0
)
725 acpi_evaluate_integer(handle
, acpi_method
, NULL
, &d_min
);
728 * If _PRW says we can wake up the system from the target sleep state,
729 * the D-state returned by _SxD is sufficient for that (we assume a
730 * wakeup-aware driver if wake is set). Still, if _SxW exists
731 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
732 * can wake the system. _S0W may be valid, too.
734 if (acpi_target_sleep_state
== ACPI_STATE_S0
||
735 (device_may_wakeup(dev
) &&
736 adev
->wakeup
.sleep_state
<= acpi_target_sleep_state
)) {
739 acpi_method
[3] = 'W';
740 status
= acpi_evaluate_integer(handle
, acpi_method
, NULL
,
742 if (ACPI_FAILURE(status
)) {
743 if (acpi_target_sleep_state
!= ACPI_STATE_S0
||
744 status
!= AE_NOT_FOUND
)
746 } else if (d_max
< d_min
) {
747 /* Warn the user of the broken DSDT */
748 printk(KERN_WARNING
"ACPI: Wrong value from %s\n",
759 #endif /* CONFIG_PM */
761 #ifdef CONFIG_PM_SLEEP
763 * acpi_pm_device_run_wake - Enable/disable wake-up for given device.
764 * @phys_dev: Device to enable/disable the platform to wake-up the system for.
765 * @enable: Whether enable or disable the wake-up functionality.
767 * Find the ACPI device object corresponding to @pci_dev and try to
768 * enable/disable the GPE associated with it.
770 int acpi_pm_device_run_wake(struct device
*phys_dev
, bool enable
)
772 struct acpi_device
*dev
;
775 if (!device_run_wake(phys_dev
))
778 handle
= DEVICE_ACPI_HANDLE(phys_dev
);
779 if (!handle
|| ACPI_FAILURE(acpi_bus_get_device(handle
, &dev
))) {
780 dev_dbg(phys_dev
, "ACPI handle has no context in %s!\n",
786 acpi_enable_wakeup_device_power(dev
, ACPI_STATE_S0
);
787 acpi_enable_gpe(dev
->wakeup
.gpe_device
, dev
->wakeup
.gpe_number
);
789 acpi_disable_gpe(dev
->wakeup
.gpe_device
, dev
->wakeup
.gpe_number
);
790 acpi_disable_wakeup_device_power(dev
);
797 * acpi_pm_device_sleep_wake - enable or disable the system wake-up
798 * capability of given device
799 * @dev: device to handle
800 * @enable: 'true' - enable, 'false' - disable the wake-up capability
802 int acpi_pm_device_sleep_wake(struct device
*dev
, bool enable
)
805 struct acpi_device
*adev
;
808 if (!device_can_wakeup(dev
))
811 handle
= DEVICE_ACPI_HANDLE(dev
);
812 if (!handle
|| ACPI_FAILURE(acpi_bus_get_device(handle
, &adev
))) {
813 dev_dbg(dev
, "ACPI handle has no context in %s!\n", __func__
);
818 acpi_enable_wakeup_device_power(adev
, acpi_target_sleep_state
) :
819 acpi_disable_wakeup_device_power(adev
);
821 dev_info(dev
, "wake-up capability %s by ACPI\n",
822 enable
? "enabled" : "disabled");
826 #endif /* CONFIG_PM_SLEEP */
828 static void acpi_power_off_prepare(void)
830 /* Prepare to power off the system */
831 acpi_sleep_prepare(ACPI_STATE_S5
);
832 acpi_disable_all_gpes();
835 static void acpi_power_off(void)
837 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
838 printk(KERN_DEBUG
"%s called\n", __func__
);
840 acpi_enter_sleep_state(ACPI_STATE_S5
, wake_sleep_flags
);
844 * ACPI 2.0 created the optional _GTS and _BFS,
845 * but industry adoption has been neither rapid nor broad.
847 * Linux gets into trouble when it executes poorly validated
848 * paths through the BIOS, so disable _GTS and _BFS by default,
849 * but do speak up and offer the option to enable them.
851 static void __init
acpi_gts_bfs_check(void)
855 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT
, METHOD_PATHNAME__GTS
, &dummy
)))
857 printk(KERN_NOTICE PREFIX
"BIOS offers _GTS\n");
858 printk(KERN_NOTICE PREFIX
"If \"acpi.gts=1\" improves suspend, "
859 "please notify linux-acpi@vger.kernel.org\n");
861 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT
, METHOD_PATHNAME__BFS
, &dummy
)))
863 printk(KERN_NOTICE PREFIX
"BIOS offers _BFS\n");
864 printk(KERN_NOTICE PREFIX
"If \"acpi.bfs=1\" improves resume, "
865 "please notify linux-acpi@vger.kernel.org\n");
869 int __init
acpi_sleep_init(void)
873 #ifdef CONFIG_SUSPEND
876 dmi_check_system(acpisleep_dmi_table
);
882 sleep_states
[ACPI_STATE_S0
] = 1;
883 printk(KERN_INFO PREFIX
"(supports S0");
885 #ifdef CONFIG_SUSPEND
886 for (i
= ACPI_STATE_S1
; i
< ACPI_STATE_S4
; i
++) {
887 status
= acpi_get_sleep_type_data(i
, &type_a
, &type_b
);
888 if (ACPI_SUCCESS(status
)) {
890 printk(KERN_CONT
" S%d", i
);
894 suspend_set_ops(old_suspend_ordering
?
895 &acpi_suspend_ops_old
: &acpi_suspend_ops
);
898 #ifdef CONFIG_HIBERNATION
899 status
= acpi_get_sleep_type_data(ACPI_STATE_S4
, &type_a
, &type_b
);
900 if (ACPI_SUCCESS(status
)) {
901 hibernation_set_ops(old_suspend_ordering
?
902 &acpi_hibernation_ops_old
: &acpi_hibernation_ops
);
903 sleep_states
[ACPI_STATE_S4
] = 1;
904 printk(KERN_CONT
" S4");
906 acpi_get_table(ACPI_SIG_FACS
, 1,
907 (struct acpi_table_header
**)&facs
);
909 s4_hardware_signature
=
910 facs
->hardware_signature
;
914 status
= acpi_get_sleep_type_data(ACPI_STATE_S5
, &type_a
, &type_b
);
915 if (ACPI_SUCCESS(status
)) {
916 sleep_states
[ACPI_STATE_S5
] = 1;
917 printk(KERN_CONT
" S5");
918 pm_power_off_prepare
= acpi_power_off_prepare
;
919 pm_power_off
= acpi_power_off
;
921 printk(KERN_CONT
")\n");
923 * Register the tts_notifier to reboot notifier list so that the _TTS
924 * object can also be evaluated when the system enters S5.
926 register_reboot_notifier(&tts_notifier
);
927 acpi_gts_bfs_check();