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 static unsigned int gts
, bfs
;
32 module_param(gts
, uint
, 0644);
33 module_param(bfs
, uint
, 0644);
34 MODULE_PARM_DESC(gts
, "Enable evaluation of _GTS on suspend.");
35 MODULE_PARM_DESC(bfs
, "Enable evaluation of _BFS on resume".);
37 static u8
wake_sleep_flags(void)
39 u8 flags
= ACPI_NO_OPTIONAL_METHODS
;
42 flags
|= ACPI_EXECUTE_GTS
;
44 flags
|= ACPI_EXECUTE_BFS
;
49 static u8 sleep_states
[ACPI_S_STATE_COUNT
];
51 static void acpi_sleep_tts_switch(u32 acpi_state
)
53 union acpi_object in_arg
= { ACPI_TYPE_INTEGER
};
54 struct acpi_object_list arg_list
= { 1, &in_arg
};
55 acpi_status status
= AE_OK
;
57 in_arg
.integer
.value
= acpi_state
;
58 status
= acpi_evaluate_object(NULL
, "\\_TTS", &arg_list
, NULL
);
59 if (ACPI_FAILURE(status
) && status
!= AE_NOT_FOUND
) {
61 * OS can't evaluate the _TTS object correctly. Some warning
62 * message will be printed. But it won't break anything.
64 printk(KERN_NOTICE
"Failure in evaluating _TTS object\n");
68 static int tts_notify_reboot(struct notifier_block
*this,
69 unsigned long code
, void *x
)
71 acpi_sleep_tts_switch(ACPI_STATE_S5
);
75 static struct notifier_block tts_notifier
= {
76 .notifier_call
= tts_notify_reboot
,
81 static int acpi_sleep_prepare(u32 acpi_state
)
83 #ifdef CONFIG_ACPI_SLEEP
84 /* do we have a wakeup address for S2 and S3? */
85 if (acpi_state
== ACPI_STATE_S3
) {
86 if (!acpi_wakeup_address
) {
89 acpi_set_firmware_waking_vector(
90 (acpi_physical_address
)acpi_wakeup_address
);
93 ACPI_FLUSH_CPU_CACHE();
95 printk(KERN_INFO PREFIX
"Preparing to enter system sleep state S%d\n",
97 acpi_enable_wakeup_devices(acpi_state
);
98 acpi_enter_sleep_state_prep(acpi_state
);
102 #ifdef CONFIG_ACPI_SLEEP
103 static u32 acpi_target_sleep_state
= ACPI_STATE_S0
;
106 * The ACPI specification wants us to save NVS memory regions during hibernation
107 * and to restore them during the subsequent resume. Windows does that also for
108 * suspend to RAM. However, it is known that this mechanism does not work on
109 * all machines, so we allow the user to disable it with the help of the
110 * 'acpi_sleep=nonvs' kernel command line option.
112 static bool nvs_nosave
;
114 void __init
acpi_nvs_nosave(void)
120 * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
121 * user to request that behavior by using the 'acpi_old_suspend_ordering'
122 * kernel command line option that causes the following variable to be set.
124 static bool old_suspend_ordering
;
126 void __init
acpi_old_suspend_ordering(void)
128 old_suspend_ordering
= true;
132 * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
134 static int acpi_pm_freeze(void)
136 acpi_disable_all_gpes();
137 acpi_os_wait_events_complete(NULL
);
138 acpi_ec_block_transactions();
143 * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
145 static int acpi_pm_pre_suspend(void)
148 return suspend_nvs_save();
152 * __acpi_pm_prepare - Prepare the platform to enter the target state.
154 * If necessary, set the firmware waking vector and do arch-specific
155 * nastiness to get the wakeup code to the waking vector.
157 static int __acpi_pm_prepare(void)
159 int error
= acpi_sleep_prepare(acpi_target_sleep_state
);
161 acpi_target_sleep_state
= ACPI_STATE_S0
;
167 * acpi_pm_prepare - Prepare the platform to enter the target sleep
168 * state and disable the GPEs.
170 static int acpi_pm_prepare(void)
172 int error
= __acpi_pm_prepare();
174 error
= acpi_pm_pre_suspend();
180 * acpi_pm_finish - Instruct the platform to leave a sleep state.
182 * This is called after we wake back up (or if entering the sleep state
185 static void acpi_pm_finish(void)
187 u32 acpi_state
= acpi_target_sleep_state
;
189 acpi_ec_unblock_transactions();
192 if (acpi_state
== ACPI_STATE_S0
)
195 printk(KERN_INFO PREFIX
"Waking up from system sleep state S%d\n",
197 acpi_disable_wakeup_devices(acpi_state
);
198 acpi_leave_sleep_state(acpi_state
);
200 /* reset firmware waking vector */
201 acpi_set_firmware_waking_vector((acpi_physical_address
) 0);
203 acpi_target_sleep_state
= ACPI_STATE_S0
;
207 * acpi_pm_end - Finish up suspend sequence.
209 static void acpi_pm_end(void)
212 * This is necessary in case acpi_pm_finish() is not called during a
213 * failing transition to a sleep state.
215 acpi_target_sleep_state
= ACPI_STATE_S0
;
216 acpi_sleep_tts_switch(acpi_target_sleep_state
);
218 #else /* !CONFIG_ACPI_SLEEP */
219 #define acpi_target_sleep_state ACPI_STATE_S0
220 #endif /* CONFIG_ACPI_SLEEP */
222 #ifdef CONFIG_SUSPEND
223 static u32 acpi_suspend_states
[] = {
224 [PM_SUSPEND_ON
] = ACPI_STATE_S0
,
225 [PM_SUSPEND_STANDBY
] = ACPI_STATE_S1
,
226 [PM_SUSPEND_MEM
] = ACPI_STATE_S3
,
227 [PM_SUSPEND_MAX
] = ACPI_STATE_S5
231 * acpi_suspend_begin - Set the target system sleep state to the state
232 * associated with given @pm_state, if supported.
234 static int acpi_suspend_begin(suspend_state_t pm_state
)
236 u32 acpi_state
= acpi_suspend_states
[pm_state
];
239 error
= nvs_nosave
? 0 : suspend_nvs_alloc();
243 if (sleep_states
[acpi_state
]) {
244 acpi_target_sleep_state
= acpi_state
;
245 acpi_sleep_tts_switch(acpi_target_sleep_state
);
247 printk(KERN_ERR
"ACPI does not support this state: %d\n",
255 * acpi_suspend_enter - Actually enter a sleep state.
258 * Flush caches and go to sleep. For STR we have to call arch-specific
259 * assembly, which in turn call acpi_enter_sleep_state().
260 * It's unfortunate, but it works. Please fix if you're feeling frisky.
262 static int acpi_suspend_enter(suspend_state_t pm_state
)
264 acpi_status status
= AE_OK
;
265 u32 acpi_state
= acpi_target_sleep_state
;
266 u8 flags
= wake_sleep_flags();
269 ACPI_FLUSH_CPU_CACHE();
271 switch (acpi_state
) {
274 status
= acpi_enter_sleep_state(acpi_state
, flags
);
278 error
= acpi_suspend_lowlevel();
281 pr_info(PREFIX
"Low-level resume complete\n");
285 /* This violates the spec but is required for bug compatibility. */
286 acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE
, 1);
288 /* Reprogram control registers and execute _BFS */
289 acpi_leave_sleep_state_prep(acpi_state
, flags
);
291 /* ACPI 3.0 specs (P62) says that it's the responsibility
292 * of the OSPM to clear the status bit [ implying that the
293 * POWER_BUTTON event should not reach userspace ]
295 if (ACPI_SUCCESS(status
) && (acpi_state
== ACPI_STATE_S3
))
296 acpi_clear_event(ACPI_EVENT_POWER_BUTTON
);
299 * Disable and clear GPE status before interrupt is enabled. Some GPEs
300 * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
301 * acpi_leave_sleep_state will reenable specific GPEs later
303 acpi_disable_all_gpes();
304 /* Allow EC transactions to happen. */
305 acpi_ec_unblock_transactions_early();
307 suspend_nvs_restore();
309 return ACPI_SUCCESS(status
) ? 0 : -EFAULT
;
312 static int acpi_suspend_state_valid(suspend_state_t pm_state
)
318 case PM_SUSPEND_STANDBY
:
320 acpi_state
= acpi_suspend_states
[pm_state
];
322 return sleep_states
[acpi_state
];
328 static const struct platform_suspend_ops acpi_suspend_ops
= {
329 .valid
= acpi_suspend_state_valid
,
330 .begin
= acpi_suspend_begin
,
331 .prepare_late
= acpi_pm_prepare
,
332 .enter
= acpi_suspend_enter
,
333 .wake
= acpi_pm_finish
,
338 * acpi_suspend_begin_old - Set the target system sleep state to the
339 * state associated with given @pm_state, if supported, and
340 * execute the _PTS control method. This function is used if the
341 * pre-ACPI 2.0 suspend ordering has been requested.
343 static int acpi_suspend_begin_old(suspend_state_t pm_state
)
345 int error
= acpi_suspend_begin(pm_state
);
347 error
= __acpi_pm_prepare();
353 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
356 static const struct platform_suspend_ops acpi_suspend_ops_old
= {
357 .valid
= acpi_suspend_state_valid
,
358 .begin
= acpi_suspend_begin_old
,
359 .prepare_late
= acpi_pm_pre_suspend
,
360 .enter
= acpi_suspend_enter
,
361 .wake
= acpi_pm_finish
,
363 .recover
= acpi_pm_finish
,
366 static int __init
init_old_suspend_ordering(const struct dmi_system_id
*d
)
368 old_suspend_ordering
= true;
372 static int __init
init_nvs_nosave(const struct dmi_system_id
*d
)
378 static struct dmi_system_id __initdata acpisleep_dmi_table
[] = {
380 .callback
= init_old_suspend_ordering
,
381 .ident
= "Abit KN9 (nForce4 variant)",
383 DMI_MATCH(DMI_BOARD_VENDOR
, "http://www.abit.com.tw/"),
384 DMI_MATCH(DMI_BOARD_NAME
, "KN9 Series(NF-CK804)"),
388 .callback
= init_old_suspend_ordering
,
389 .ident
= "HP xw4600 Workstation",
391 DMI_MATCH(DMI_SYS_VENDOR
, "Hewlett-Packard"),
392 DMI_MATCH(DMI_PRODUCT_NAME
, "HP xw4600 Workstation"),
396 .callback
= init_old_suspend_ordering
,
397 .ident
= "Asus Pundit P1-AH2 (M2N8L motherboard)",
399 DMI_MATCH(DMI_BOARD_VENDOR
, "ASUSTek Computer INC."),
400 DMI_MATCH(DMI_BOARD_NAME
, "M2N8L"),
404 .callback
= init_old_suspend_ordering
,
405 .ident
= "Panasonic CF51-2L",
407 DMI_MATCH(DMI_BOARD_VENDOR
,
408 "Matsushita Electric Industrial Co.,Ltd."),
409 DMI_MATCH(DMI_BOARD_NAME
, "CF51-2L"),
413 .callback
= init_nvs_nosave
,
414 .ident
= "Sony Vaio VGN-FW21E",
416 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
417 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-FW21E"),
421 .callback
= init_nvs_nosave
,
422 .ident
= "Sony Vaio VPCEB17FX",
424 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
425 DMI_MATCH(DMI_PRODUCT_NAME
, "VPCEB17FX"),
429 .callback
= init_nvs_nosave
,
430 .ident
= "Sony Vaio VGN-SR11M",
432 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
433 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-SR11M"),
437 .callback
= init_nvs_nosave
,
438 .ident
= "Everex StepNote Series",
440 DMI_MATCH(DMI_SYS_VENDOR
, "Everex Systems, Inc."),
441 DMI_MATCH(DMI_PRODUCT_NAME
, "Everex StepNote Series"),
445 .callback
= init_nvs_nosave
,
446 .ident
= "Sony Vaio VPCEB1Z1E",
448 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
449 DMI_MATCH(DMI_PRODUCT_NAME
, "VPCEB1Z1E"),
453 .callback
= init_nvs_nosave
,
454 .ident
= "Sony Vaio VGN-NW130D",
456 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
457 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-NW130D"),
461 .callback
= init_nvs_nosave
,
462 .ident
= "Sony Vaio VPCCW29FX",
464 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
465 DMI_MATCH(DMI_PRODUCT_NAME
, "VPCCW29FX"),
469 .callback
= init_nvs_nosave
,
470 .ident
= "Averatec AV1020-ED2",
472 DMI_MATCH(DMI_SYS_VENDOR
, "AVERATEC"),
473 DMI_MATCH(DMI_PRODUCT_NAME
, "1000 Series"),
477 .callback
= init_old_suspend_ordering
,
478 .ident
= "Asus A8N-SLI DELUXE",
480 DMI_MATCH(DMI_BOARD_VENDOR
, "ASUSTeK Computer INC."),
481 DMI_MATCH(DMI_BOARD_NAME
, "A8N-SLI DELUXE"),
485 .callback
= init_old_suspend_ordering
,
486 .ident
= "Asus A8N-SLI Premium",
488 DMI_MATCH(DMI_BOARD_VENDOR
, "ASUSTeK Computer INC."),
489 DMI_MATCH(DMI_BOARD_NAME
, "A8N-SLI Premium"),
493 .callback
= init_nvs_nosave
,
494 .ident
= "Sony Vaio VGN-SR26GN_P",
496 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
497 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-SR26GN_P"),
501 .callback
= init_nvs_nosave
,
502 .ident
= "Sony Vaio VGN-FW520F",
504 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
505 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-FW520F"),
509 .callback
= init_nvs_nosave
,
510 .ident
= "Asus K54C",
512 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
513 DMI_MATCH(DMI_PRODUCT_NAME
, "K54C"),
517 .callback
= init_nvs_nosave
,
518 .ident
= "Asus K54HR",
520 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
521 DMI_MATCH(DMI_PRODUCT_NAME
, "K54HR"),
526 #endif /* CONFIG_SUSPEND */
528 #ifdef CONFIG_HIBERNATION
529 static unsigned long s4_hardware_signature
;
530 static struct acpi_table_facs
*facs
;
531 static bool nosigcheck
;
533 void __init
acpi_no_s4_hw_signature(void)
538 static int acpi_hibernation_begin(void)
542 error
= nvs_nosave
? 0 : suspend_nvs_alloc();
544 acpi_target_sleep_state
= ACPI_STATE_S4
;
545 acpi_sleep_tts_switch(acpi_target_sleep_state
);
551 static int acpi_hibernation_enter(void)
553 u8 flags
= wake_sleep_flags();
554 acpi_status status
= AE_OK
;
556 ACPI_FLUSH_CPU_CACHE();
558 /* This shouldn't return. If it returns, we have a problem */
559 status
= acpi_enter_sleep_state(ACPI_STATE_S4
, flags
);
560 /* Reprogram control registers and execute _BFS */
561 acpi_leave_sleep_state_prep(ACPI_STATE_S4
, flags
);
563 return ACPI_SUCCESS(status
) ? 0 : -EFAULT
;
566 static void acpi_hibernation_leave(void)
568 u8 flags
= wake_sleep_flags();
571 * If ACPI is not enabled by the BIOS and the boot kernel, we need to
575 /* Reprogram control registers and execute _BFS */
576 acpi_leave_sleep_state_prep(ACPI_STATE_S4
, flags
);
577 /* Check the hardware signature */
578 if (facs
&& s4_hardware_signature
!= facs
->hardware_signature
) {
579 printk(KERN_EMERG
"ACPI: Hardware changed while hibernated, "
581 panic("ACPI S4 hardware signature mismatch");
583 /* Restore the NVS memory area */
584 suspend_nvs_restore();
585 /* Allow EC transactions to happen. */
586 acpi_ec_unblock_transactions_early();
589 static void acpi_pm_thaw(void)
591 acpi_ec_unblock_transactions();
592 acpi_enable_all_runtime_gpes();
595 static const struct platform_hibernation_ops acpi_hibernation_ops
= {
596 .begin
= acpi_hibernation_begin
,
598 .pre_snapshot
= acpi_pm_prepare
,
599 .finish
= acpi_pm_finish
,
600 .prepare
= acpi_pm_prepare
,
601 .enter
= acpi_hibernation_enter
,
602 .leave
= acpi_hibernation_leave
,
603 .pre_restore
= acpi_pm_freeze
,
604 .restore_cleanup
= acpi_pm_thaw
,
608 * acpi_hibernation_begin_old - Set the target system sleep state to
609 * ACPI_STATE_S4 and execute the _PTS control method. This
610 * function is used if the pre-ACPI 2.0 suspend ordering has been
613 static int acpi_hibernation_begin_old(void)
617 * The _TTS object should always be evaluated before the _PTS object.
618 * When the old_suspended_ordering is true, the _PTS object is
619 * evaluated in the acpi_sleep_prepare.
621 acpi_sleep_tts_switch(ACPI_STATE_S4
);
623 error
= acpi_sleep_prepare(ACPI_STATE_S4
);
627 error
= suspend_nvs_alloc();
629 acpi_target_sleep_state
= ACPI_STATE_S4
;
635 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
638 static const struct platform_hibernation_ops acpi_hibernation_ops_old
= {
639 .begin
= acpi_hibernation_begin_old
,
641 .pre_snapshot
= acpi_pm_pre_suspend
,
642 .prepare
= acpi_pm_freeze
,
643 .finish
= acpi_pm_finish
,
644 .enter
= acpi_hibernation_enter
,
645 .leave
= acpi_hibernation_leave
,
646 .pre_restore
= acpi_pm_freeze
,
647 .restore_cleanup
= acpi_pm_thaw
,
648 .recover
= acpi_pm_finish
,
650 #endif /* CONFIG_HIBERNATION */
652 int acpi_suspend(u32 acpi_state
)
654 suspend_state_t states
[] = {
655 [1] = PM_SUSPEND_STANDBY
,
656 [3] = PM_SUSPEND_MEM
,
660 if (acpi_state
< 6 && states
[acpi_state
])
661 return pm_suspend(states
[acpi_state
]);
669 * acpi_pm_device_sleep_state - return preferred power state of ACPI device
670 * in the system sleep state given by %acpi_target_sleep_state
671 * @dev: device to examine; its driver model wakeup flags control
672 * whether it should be able to wake up the system
673 * @d_min_p: used to store the upper limit of allowed states range
674 * Return value: preferred power state of the device on success, -ENODEV on
675 * failure (ie. if there's no 'struct acpi_device' for @dev)
677 * Find the lowest power (highest number) ACPI device power state that
678 * device @dev can be in while the system is in the sleep state represented
679 * by %acpi_target_sleep_state. If @wake is nonzero, the device should be
680 * able to wake up the system from this sleep state. If @d_min_p is set,
681 * the highest power (lowest number) device power state of @dev allowed
682 * in this system sleep state is stored at the location pointed to by it.
684 * The caller must ensure that @dev is valid before using this function.
685 * The caller is also responsible for figuring out if the device is
686 * supposed to be able to wake up the system and passing this information
690 int acpi_pm_device_sleep_state(struct device
*dev
, int *d_min_p
)
692 acpi_handle handle
= DEVICE_ACPI_HANDLE(dev
);
693 struct acpi_device
*adev
;
694 char acpi_method
[] = "_SxD";
695 unsigned long long d_min
, d_max
;
697 if (!handle
|| ACPI_FAILURE(acpi_bus_get_device(handle
, &adev
))) {
698 printk(KERN_DEBUG
"ACPI handle has no context!\n");
702 acpi_method
[2] = '0' + acpi_target_sleep_state
;
704 * If the sleep state is S0, we will return D3, but if the device has
705 * _S0W, we will use the value from _S0W
707 d_min
= ACPI_STATE_D0
;
708 d_max
= ACPI_STATE_D3
;
711 * If present, _SxD methods return the minimum D-state (highest power
712 * state) we can use for the corresponding S-states. Otherwise, the
713 * minimum D-state is D0 (ACPI 3.x).
715 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
716 * provided -- that's our fault recovery, we ignore retval.
718 if (acpi_target_sleep_state
> ACPI_STATE_S0
)
719 acpi_evaluate_integer(handle
, acpi_method
, NULL
, &d_min
);
722 * If _PRW says we can wake up the system from the target sleep state,
723 * the D-state returned by _SxD is sufficient for that (we assume a
724 * wakeup-aware driver if wake is set). Still, if _SxW exists
725 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
726 * can wake the system. _S0W may be valid, too.
728 if (acpi_target_sleep_state
== ACPI_STATE_S0
||
729 (device_may_wakeup(dev
) &&
730 adev
->wakeup
.sleep_state
<= acpi_target_sleep_state
)) {
733 acpi_method
[3] = 'W';
734 status
= acpi_evaluate_integer(handle
, acpi_method
, NULL
,
736 if (ACPI_FAILURE(status
)) {
737 if (acpi_target_sleep_state
!= ACPI_STATE_S0
||
738 status
!= AE_NOT_FOUND
)
740 } else if (d_max
< d_min
) {
741 /* Warn the user of the broken DSDT */
742 printk(KERN_WARNING
"ACPI: Wrong value from %s\n",
753 #endif /* CONFIG_PM */
755 #ifdef CONFIG_PM_SLEEP
757 * acpi_pm_device_run_wake - Enable/disable wake-up for given device.
758 * @phys_dev: Device to enable/disable the platform to wake-up the system for.
759 * @enable: Whether enable or disable the wake-up functionality.
761 * Find the ACPI device object corresponding to @pci_dev and try to
762 * enable/disable the GPE associated with it.
764 int acpi_pm_device_run_wake(struct device
*phys_dev
, bool enable
)
766 struct acpi_device
*dev
;
769 if (!device_run_wake(phys_dev
))
772 handle
= DEVICE_ACPI_HANDLE(phys_dev
);
773 if (!handle
|| ACPI_FAILURE(acpi_bus_get_device(handle
, &dev
))) {
774 dev_dbg(phys_dev
, "ACPI handle has no context in %s!\n",
780 acpi_enable_wakeup_device_power(dev
, ACPI_STATE_S0
);
781 acpi_enable_gpe(dev
->wakeup
.gpe_device
, dev
->wakeup
.gpe_number
);
783 acpi_disable_gpe(dev
->wakeup
.gpe_device
, dev
->wakeup
.gpe_number
);
784 acpi_disable_wakeup_device_power(dev
);
791 * acpi_pm_device_sleep_wake - enable or disable the system wake-up
792 * capability of given device
793 * @dev: device to handle
794 * @enable: 'true' - enable, 'false' - disable the wake-up capability
796 int acpi_pm_device_sleep_wake(struct device
*dev
, bool enable
)
799 struct acpi_device
*adev
;
802 if (!device_can_wakeup(dev
))
805 handle
= DEVICE_ACPI_HANDLE(dev
);
806 if (!handle
|| ACPI_FAILURE(acpi_bus_get_device(handle
, &adev
))) {
807 dev_dbg(dev
, "ACPI handle has no context in %s!\n", __func__
);
812 acpi_enable_wakeup_device_power(adev
, acpi_target_sleep_state
) :
813 acpi_disable_wakeup_device_power(adev
);
815 dev_info(dev
, "wake-up capability %s by ACPI\n",
816 enable
? "enabled" : "disabled");
820 #endif /* CONFIG_PM_SLEEP */
822 static void acpi_power_off_prepare(void)
824 /* Prepare to power off the system */
825 acpi_sleep_prepare(ACPI_STATE_S5
);
826 acpi_disable_all_gpes();
829 static void acpi_power_off(void)
831 u8 flags
= wake_sleep_flags();
833 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
834 printk(KERN_DEBUG
"%s called\n", __func__
);
836 acpi_enter_sleep_state(ACPI_STATE_S5
, flags
);
840 * ACPI 2.0 created the optional _GTS and _BFS,
841 * but industry adoption has been neither rapid nor broad.
843 * Linux gets into trouble when it executes poorly validated
844 * paths through the BIOS, so disable _GTS and _BFS by default,
845 * but do speak up and offer the option to enable them.
847 static void __init
acpi_gts_bfs_check(void)
851 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT
, METHOD_PATHNAME__GTS
, &dummy
)))
853 printk(KERN_NOTICE PREFIX
"BIOS offers _GTS\n");
854 printk(KERN_NOTICE PREFIX
"If \"acpi.gts=1\" improves suspend, "
855 "please notify linux-acpi@vger.kernel.org\n");
857 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT
, METHOD_PATHNAME__BFS
, &dummy
)))
859 printk(KERN_NOTICE PREFIX
"BIOS offers _BFS\n");
860 printk(KERN_NOTICE PREFIX
"If \"acpi.bfs=1\" improves resume, "
861 "please notify linux-acpi@vger.kernel.org\n");
865 int __init
acpi_sleep_init(void)
869 #ifdef CONFIG_SUSPEND
872 dmi_check_system(acpisleep_dmi_table
);
878 sleep_states
[ACPI_STATE_S0
] = 1;
879 printk(KERN_INFO PREFIX
"(supports S0");
881 #ifdef CONFIG_SUSPEND
882 for (i
= ACPI_STATE_S1
; i
< ACPI_STATE_S4
; i
++) {
883 status
= acpi_get_sleep_type_data(i
, &type_a
, &type_b
);
884 if (ACPI_SUCCESS(status
)) {
890 suspend_set_ops(old_suspend_ordering
?
891 &acpi_suspend_ops_old
: &acpi_suspend_ops
);
894 #ifdef CONFIG_HIBERNATION
895 status
= acpi_get_sleep_type_data(ACPI_STATE_S4
, &type_a
, &type_b
);
896 if (ACPI_SUCCESS(status
)) {
897 hibernation_set_ops(old_suspend_ordering
?
898 &acpi_hibernation_ops_old
: &acpi_hibernation_ops
);
899 sleep_states
[ACPI_STATE_S4
] = 1;
902 acpi_get_table(ACPI_SIG_FACS
, 1,
903 (struct acpi_table_header
**)&facs
);
905 s4_hardware_signature
=
906 facs
->hardware_signature
;
910 status
= acpi_get_sleep_type_data(ACPI_STATE_S5
, &type_a
, &type_b
);
911 if (ACPI_SUCCESS(status
)) {
912 sleep_states
[ACPI_STATE_S5
] = 1;
914 pm_power_off_prepare
= acpi_power_off_prepare
;
915 pm_power_off
= acpi_power_off
;
919 * Register the tts_notifier to reboot notifier list so that the _TTS
920 * object can also be evaluated when the system enters S5.
922 register_reboot_notifier(&tts_notifier
);
923 acpi_gts_bfs_check();