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 u8 sleep_states[ACPI_S_STATE_COUNT];
33 static void acpi_sleep_tts_switch(u32 acpi_state)
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;
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) {
43 * OS can't evaluate the _TTS object correctly. Some warning
44 * message will be printed. But it won't break anything.
46 printk(KERN_NOTICE "Failure in evaluating _TTS object\n");
50 static int tts_notify_reboot(struct notifier_block *this,
51 unsigned long code, void *x)
53 acpi_sleep_tts_switch(ACPI_STATE_S5);
57 static struct notifier_block tts_notifier = {
58 .notifier_call = tts_notify_reboot,
63 static int acpi_sleep_prepare(u32 acpi_state)
65 #ifdef CONFIG_ACPI_SLEEP
66 /* do we have a wakeup address for S2 and S3? */
67 if (acpi_state == ACPI_STATE_S3) {
68 if (!acpi_wakeup_address)
70 acpi_set_firmware_waking_vector(acpi_wakeup_address);
73 ACPI_FLUSH_CPU_CACHE();
75 printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
77 acpi_enable_wakeup_devices(acpi_state);
78 acpi_enter_sleep_state_prep(acpi_state);
82 #ifdef CONFIG_ACPI_SLEEP
83 static u32 acpi_target_sleep_state = ACPI_STATE_S0;
84 static bool pwr_btn_event_pending;
87 * 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.
93 static bool nvs_nosave;
95 void __init acpi_nvs_nosave(void)
101 * 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.
108 static bool nvs_nosave_s3;
110 void __init acpi_nvs_nosave_s3(void)
112 nvs_nosave_s3 = true;
116 * 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.
120 static bool old_suspend_ordering;
122 void __init acpi_old_suspend_ordering(void)
124 old_suspend_ordering = true;
128 * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
130 static int acpi_pm_freeze(void)
132 acpi_disable_all_gpes();
133 acpi_os_wait_events_complete();
134 acpi_ec_block_transactions();
139 * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
141 static int acpi_pm_pre_suspend(void)
144 return suspend_nvs_save();
148 * __acpi_pm_prepare - Prepare the platform to enter the target state.
150 * If necessary, set the firmware waking vector and do arch-specific
151 * nastiness to get the wakeup code to the waking vector.
153 static int __acpi_pm_prepare(void)
155 int error = acpi_sleep_prepare(acpi_target_sleep_state);
157 acpi_target_sleep_state = ACPI_STATE_S0;
163 * acpi_pm_prepare - Prepare the platform to enter the target sleep
164 * state and disable the GPEs.
166 static int acpi_pm_prepare(void)
168 int error = __acpi_pm_prepare();
170 error = acpi_pm_pre_suspend();
175 static int find_powerf_dev(struct device *dev, void *data)
177 struct acpi_device *device = to_acpi_device(dev);
178 const char *hid = acpi_device_hid(device);
180 return !strcmp(hid, ACPI_BUTTON_HID_POWERF);
184 * acpi_pm_finish - Instruct the platform to leave a sleep state.
186 * This is called after we wake back up (or if entering the sleep state
189 static void acpi_pm_finish(void)
191 struct device *pwr_btn_dev;
192 u32 acpi_state = acpi_target_sleep_state;
194 acpi_ec_unblock_transactions();
197 if (acpi_state == ACPI_STATE_S0)
200 printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
202 acpi_disable_wakeup_devices(acpi_state);
203 acpi_leave_sleep_state(acpi_state);
205 /* reset firmware waking vector */
206 acpi_set_firmware_waking_vector((acpi_physical_address) 0);
208 acpi_target_sleep_state = ACPI_STATE_S0;
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).
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)
219 pwr_btn_event_pending = false;
220 pwr_btn_dev = bus_find_device(&acpi_bus_type, NULL, NULL,
223 pm_wakeup_event(pwr_btn_dev, 0);
224 put_device(pwr_btn_dev);
229 * acpi_pm_end - Finish up suspend sequence.
231 static void acpi_pm_end(void)
234 * This is necessary in case acpi_pm_finish() is not called during a
235 * failing transition to a sleep state.
237 acpi_target_sleep_state = ACPI_STATE_S0;
238 acpi_sleep_tts_switch(acpi_target_sleep_state);
240 #else /* !CONFIG_ACPI_SLEEP */
241 #define acpi_target_sleep_state ACPI_STATE_S0
242 #endif /* CONFIG_ACPI_SLEEP */
244 #ifdef CONFIG_SUSPEND
245 static u32 acpi_suspend_states[] = {
246 [PM_SUSPEND_ON] = ACPI_STATE_S0,
247 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
248 [PM_SUSPEND_MEM] = ACPI_STATE_S3,
249 [PM_SUSPEND_MAX] = ACPI_STATE_S5
253 * acpi_suspend_begin - Set the target system sleep state to the state
254 * associated with given @pm_state, if supported.
256 static int acpi_suspend_begin(suspend_state_t pm_state)
258 u32 acpi_state = acpi_suspend_states[pm_state];
261 error = (nvs_nosave || nvs_nosave_s3) ? 0 : suspend_nvs_alloc();
265 if (sleep_states[acpi_state]) {
266 acpi_target_sleep_state = acpi_state;
267 acpi_sleep_tts_switch(acpi_target_sleep_state);
269 printk(KERN_ERR "ACPI does not support this state: %d\n",
277 * acpi_suspend_enter - Actually enter a sleep state.
280 * Flush caches and go to sleep. For STR we have to call arch-specific
281 * assembly, which in turn call acpi_enter_sleep_state().
282 * It's unfortunate, but it works. Please fix if you're feeling frisky.
284 static int acpi_suspend_enter(suspend_state_t pm_state)
286 acpi_status status = AE_OK;
287 u32 acpi_state = acpi_target_sleep_state;
290 ACPI_FLUSH_CPU_CACHE();
292 switch (acpi_state) {
295 status = acpi_enter_sleep_state(acpi_state);
299 error = acpi_suspend_lowlevel();
302 pr_info(PREFIX "Low-level resume complete\n");
306 /* This violates the spec but is required for bug compatibility. */
307 acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
309 /* Reprogram control registers */
310 acpi_leave_sleep_state_prep(acpi_state);
312 /* ACPI 3.0 specs (P62) says that it's the responsibility
313 * of the OSPM to clear the status bit [ implying that the
314 * POWER_BUTTON event should not reach userspace ]
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.
321 if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3)) {
322 acpi_event_status pwr_btn_status;
324 acpi_get_event_status(ACPI_EVENT_POWER_BUTTON, &pwr_btn_status);
326 if (pwr_btn_status & ACPI_EVENT_FLAG_SET) {
327 acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
329 pwr_btn_event_pending = true;
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
338 acpi_disable_all_gpes();
339 /* Allow EC transactions to happen. */
340 acpi_ec_unblock_transactions_early();
342 suspend_nvs_restore();
344 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
347 static int acpi_suspend_state_valid(suspend_state_t pm_state)
353 case PM_SUSPEND_STANDBY:
355 acpi_state = acpi_suspend_states[pm_state];
357 return sleep_states[acpi_state];
363 static const struct platform_suspend_ops acpi_suspend_ops = {
364 .valid = acpi_suspend_state_valid,
365 .begin = acpi_suspend_begin,
366 .prepare_late = acpi_pm_prepare,
367 .enter = acpi_suspend_enter,
368 .wake = acpi_pm_finish,
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.
378 static int acpi_suspend_begin_old(suspend_state_t pm_state)
380 int error = acpi_suspend_begin(pm_state);
382 error = __acpi_pm_prepare();
388 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
391 static const struct platform_suspend_ops acpi_suspend_ops_old = {
392 .valid = acpi_suspend_state_valid,
393 .begin = acpi_suspend_begin_old,
394 .prepare_late = acpi_pm_pre_suspend,
395 .enter = acpi_suspend_enter,
396 .wake = acpi_pm_finish,
398 .recover = acpi_pm_finish,
401 static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
403 old_suspend_ordering = true;
407 static int __init init_nvs_nosave(const struct dmi_system_id *d)
413 static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
415 .callback = init_old_suspend_ordering,
416 .ident = "Abit KN9 (nForce4 variant)",
418 DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
419 DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
423 .callback = init_old_suspend_ordering,
424 .ident = "HP xw4600 Workstation",
426 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
427 DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
431 .callback = init_old_suspend_ordering,
432 .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
434 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
435 DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
439 .callback = init_old_suspend_ordering,
440 .ident = "Panasonic CF51-2L",
442 DMI_MATCH(DMI_BOARD_VENDOR,
443 "Matsushita Electric Industrial Co.,Ltd."),
444 DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
448 .callback = init_nvs_nosave,
449 .ident = "Sony Vaio VGN-FW21E",
451 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
452 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"),
456 .callback = init_nvs_nosave,
457 .ident = "Sony Vaio VPCEB17FX",
459 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
460 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"),
464 .callback = init_nvs_nosave,
465 .ident = "Sony Vaio VGN-SR11M",
467 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
468 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),
472 .callback = init_nvs_nosave,
473 .ident = "Everex StepNote Series",
475 DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),
476 DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),
480 .callback = init_nvs_nosave,
481 .ident = "Sony Vaio VPCEB1Z1E",
483 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
484 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),
488 .callback = init_nvs_nosave,
489 .ident = "Sony Vaio VGN-NW130D",
491 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
492 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),
496 .callback = init_nvs_nosave,
497 .ident = "Sony Vaio VPCCW29FX",
499 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
500 DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"),
504 .callback = init_nvs_nosave,
505 .ident = "Averatec AV1020-ED2",
507 DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"),
508 DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"),
512 .callback = init_old_suspend_ordering,
513 .ident = "Asus A8N-SLI DELUXE",
515 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
516 DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"),
520 .callback = init_old_suspend_ordering,
521 .ident = "Asus A8N-SLI Premium",
523 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
524 DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"),
528 .callback = init_nvs_nosave,
529 .ident = "Sony Vaio VGN-SR26GN_P",
531 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
532 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"),
536 .callback = init_nvs_nosave,
537 .ident = "Sony Vaio VPCEB1S1E",
539 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
540 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1S1E"),
544 .callback = init_nvs_nosave,
545 .ident = "Sony Vaio VGN-FW520F",
547 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
548 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"),
552 .callback = init_nvs_nosave,
553 .ident = "Asus K54C",
555 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
556 DMI_MATCH(DMI_PRODUCT_NAME, "K54C"),
560 .callback = init_nvs_nosave,
561 .ident = "Asus K54HR",
563 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
564 DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"),
569 #endif /* CONFIG_SUSPEND */
571 #ifdef CONFIG_HIBERNATION
572 static unsigned long s4_hardware_signature;
573 static struct acpi_table_facs *facs;
574 static bool nosigcheck;
576 void __init acpi_no_s4_hw_signature(void)
581 static int acpi_hibernation_begin(void)
585 error = nvs_nosave ? 0 : suspend_nvs_alloc();
587 acpi_target_sleep_state = ACPI_STATE_S4;
588 acpi_sleep_tts_switch(acpi_target_sleep_state);
594 static int acpi_hibernation_enter(void)
596 acpi_status status = AE_OK;
598 ACPI_FLUSH_CPU_CACHE();
600 /* This shouldn't return. If it returns, we have a problem */
601 status = acpi_enter_sleep_state(ACPI_STATE_S4);
602 /* Reprogram control registers */
603 acpi_leave_sleep_state_prep(ACPI_STATE_S4);
605 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
608 static void acpi_hibernation_leave(void)
611 * If ACPI is not enabled by the BIOS and the boot kernel, we need to
615 /* Reprogram control registers */
616 acpi_leave_sleep_state_prep(ACPI_STATE_S4);
617 /* Check the hardware signature */
618 if (facs && s4_hardware_signature != facs->hardware_signature) {
619 printk(KERN_EMERG "ACPI: Hardware changed while hibernated, "
621 panic("ACPI S4 hardware signature mismatch");
623 /* Restore the NVS memory area */
624 suspend_nvs_restore();
625 /* Allow EC transactions to happen. */
626 acpi_ec_unblock_transactions_early();
629 static void acpi_pm_thaw(void)
631 acpi_ec_unblock_transactions();
632 acpi_enable_all_runtime_gpes();
635 static const struct platform_hibernation_ops acpi_hibernation_ops = {
636 .begin = acpi_hibernation_begin,
638 .pre_snapshot = acpi_pm_prepare,
639 .finish = acpi_pm_finish,
640 .prepare = acpi_pm_prepare,
641 .enter = acpi_hibernation_enter,
642 .leave = acpi_hibernation_leave,
643 .pre_restore = acpi_pm_freeze,
644 .restore_cleanup = acpi_pm_thaw,
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
653 static int acpi_hibernation_begin_old(void)
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.
661 acpi_sleep_tts_switch(ACPI_STATE_S4);
663 error = acpi_sleep_prepare(ACPI_STATE_S4);
667 error = suspend_nvs_alloc();
669 acpi_target_sleep_state = ACPI_STATE_S4;
675 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
678 static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
679 .begin = acpi_hibernation_begin_old,
681 .pre_snapshot = acpi_pm_pre_suspend,
682 .prepare = acpi_pm_freeze,
683 .finish = acpi_pm_finish,
684 .enter = acpi_hibernation_enter,
685 .leave = acpi_hibernation_leave,
686 .pre_restore = acpi_pm_freeze,
687 .restore_cleanup = acpi_pm_thaw,
688 .recover = acpi_pm_finish,
690 #endif /* CONFIG_HIBERNATION */
692 int acpi_suspend(u32 acpi_state)
694 suspend_state_t states[] = {
695 [1] = PM_SUSPEND_STANDBY,
696 [3] = PM_SUSPEND_MEM,
700 if (acpi_state < 6 && states[acpi_state])
701 return pm_suspend(states[acpi_state]);
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
711 * @dev: device to examine; its driver model wakeup flags control
712 * whether it should be able to wake up the system
713 * @d_min_p: used to store the upper limit of allowed states range
714 * @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
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.
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
731 int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in)
733 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
734 struct acpi_device *adev;
735 char acpi_method[] = "_SxD";
736 unsigned long long d_min, d_max;
738 if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3)
740 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
741 printk(KERN_DEBUG "ACPI handle has no context!\n");
745 acpi_method[2] = '0' + acpi_target_sleep_state;
747 * 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.
752 d_min = ACPI_STATE_D0;
753 d_max = ACPI_STATE_D3;
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).
760 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
761 * provided -- that's our fault recovery, we ignore retval.
763 if (acpi_target_sleep_state > ACPI_STATE_S0)
764 acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
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.
773 if (acpi_target_sleep_state == ACPI_STATE_S0 ||
774 (device_may_wakeup(dev) && adev->wakeup.flags.valid &&
775 adev->wakeup.sleep_state >= acpi_target_sleep_state)) {
778 acpi_method[3] = 'W';
779 status = acpi_evaluate_integer(handle, acpi_method, NULL,
781 if (ACPI_FAILURE(status)) {
782 if (acpi_target_sleep_state != ACPI_STATE_S0 ||
783 status != AE_NOT_FOUND)
785 } else if (d_max < d_min) {
786 /* Warn the user of the broken DSDT */
787 printk(KERN_WARNING "ACPI: Wrong value from %s\n",
794 if (d_max_in < d_min)
798 /* 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)
807 EXPORT_SYMBOL(acpi_pm_device_sleep_state);
808 #endif /* CONFIG_PM */
810 #ifdef CONFIG_PM_SLEEP
812 * 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.
816 * Find the ACPI device object corresponding to @pci_dev and try to
817 * enable/disable the GPE associated with it.
819 int acpi_pm_device_run_wake(struct device *phys_dev, bool enable)
821 struct acpi_device *dev;
824 if (!device_run_wake(phys_dev))
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",
835 acpi_enable_wakeup_device_power(dev, ACPI_STATE_S0);
836 acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number);
838 acpi_disable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number);
839 acpi_disable_wakeup_device_power(dev);
844 EXPORT_SYMBOL(acpi_pm_device_run_wake);
847 * 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
852 int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
855 struct acpi_device *adev;
858 if (!device_can_wakeup(dev))
861 handle = DEVICE_ACPI_HANDLE(dev);
862 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
863 dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__);
868 acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
869 acpi_disable_wakeup_device_power(adev);
871 dev_info(dev, "wake-up capability %s by ACPI\n",
872 enable ? "enabled" : "disabled");
876 #endif /* CONFIG_PM_SLEEP */
878 static void acpi_power_off_prepare(void)
880 /* Prepare to power off the system */
881 acpi_sleep_prepare(ACPI_STATE_S5);
882 acpi_disable_all_gpes();
885 static void acpi_power_off(void)
887 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
888 printk(KERN_DEBUG "%s called\n", __func__);
890 acpi_enter_sleep_state(ACPI_STATE_S5);
893 int __init acpi_sleep_init(void)
897 #ifdef CONFIG_SUSPEND
900 dmi_check_system(acpisleep_dmi_table);
906 sleep_states[ACPI_STATE_S0] = 1;
907 printk(KERN_INFO PREFIX "(supports S0");
909 #ifdef CONFIG_SUSPEND
910 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) {
911 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
912 if (ACPI_SUCCESS(status)) {
914 printk(KERN_CONT " S%d", i);
918 suspend_set_ops(old_suspend_ordering ?
919 &acpi_suspend_ops_old : &acpi_suspend_ops);
922 #ifdef CONFIG_HIBERNATION
923 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
924 if (ACPI_SUCCESS(status)) {
925 hibernation_set_ops(old_suspend_ordering ?
926 &acpi_hibernation_ops_old : &acpi_hibernation_ops);
927 sleep_states[ACPI_STATE_S4] = 1;
928 printk(KERN_CONT " S4");
930 acpi_get_table(ACPI_SIG_FACS, 1,
931 (struct acpi_table_header **)&facs);
933 s4_hardware_signature =
934 facs->hardware_signature;
938 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;
941 printk(KERN_CONT " S5");
942 pm_power_off_prepare = acpi_power_off_prepare;
943 pm_power_off = acpi_power_off;
945 printk(KERN_CONT ")\n");
947 * Register the tts_notifier to reboot notifier list so that the _TTS
948 * object can also be evaluated when the system enters S5.
950 register_reboot_notifier(&tts_notifier);