Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * sleep.c - ACPI sleep support. |
| 3 | * |
Alexey Starikovskiy | e2a5b42 | 2005-03-18 16:20:46 -0500 | [diff] [blame] | 4 | * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
| 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 Yakui | e49f711 | 2008-08-12 10:20:22 +0800 | [diff] [blame] | 18 | #include <linux/reboot.h> |
H. Peter Anvin | d1ee433 | 2011-02-14 15:42:46 -0800 | [diff] [blame] | 19 | #include <linux/acpi.h> |
Lin Ming | a2ef5c4 | 2012-03-21 10:58:46 +0800 | [diff] [blame] | 20 | #include <linux/module.h> |
Lin Ming | b24e509 | 2012-03-27 15:43:25 +0800 | [diff] [blame] | 21 | #include <linux/pm_runtime.h> |
Rafael J. Wysocki | 8b713a8 | 2012-10-24 02:08:38 +0200 | [diff] [blame] | 22 | #include <linux/pm_qos.h> |
Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 23 | |
| 24 | #include <asm/io.h> |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <acpi/acpi_bus.h> |
| 27 | #include <acpi/acpi_drivers.h> |
Bjorn Helgaas | e60cc7a | 2009-03-13 12:08:26 -0600 | [diff] [blame] | 28 | |
| 29 | #include "internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "sleep.h" |
| 31 | |
Stephen Hemminger | 01eac60 | 2010-10-18 18:47:25 -0700 | [diff] [blame] | 32 | static u8 sleep_states[ACPI_S_STATE_COUNT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Zhao Yakui | e49f711 | 2008-08-12 10:20:22 +0800 | [diff] [blame] | 34 | static void acpi_sleep_tts_switch(u32 acpi_state) |
| 35 | { |
| 36 | union acpi_object in_arg = { ACPI_TYPE_INTEGER }; |
| 37 | struct acpi_object_list arg_list = { 1, &in_arg }; |
| 38 | acpi_status status = AE_OK; |
| 39 | |
| 40 | in_arg.integer.value = acpi_state; |
| 41 | status = acpi_evaluate_object(NULL, "\\_TTS", &arg_list, NULL); |
| 42 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 43 | /* |
| 44 | * OS can't evaluate the _TTS object correctly. Some warning |
| 45 | * message will be printed. But it won't break anything. |
| 46 | */ |
| 47 | printk(KERN_NOTICE "Failure in evaluating _TTS object\n"); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | static int tts_notify_reboot(struct notifier_block *this, |
| 52 | unsigned long code, void *x) |
| 53 | { |
| 54 | acpi_sleep_tts_switch(ACPI_STATE_S5); |
| 55 | return NOTIFY_DONE; |
| 56 | } |
| 57 | |
| 58 | static struct notifier_block tts_notifier = { |
| 59 | .notifier_call = tts_notify_reboot, |
| 60 | .next = NULL, |
| 61 | .priority = 0, |
| 62 | }; |
| 63 | |
Rafael J. Wysocki | c9b6c8f | 2008-01-08 00:10:57 +0100 | [diff] [blame] | 64 | static int acpi_sleep_prepare(u32 acpi_state) |
Alexey Starikovskiy | 2f3f2226 | 2007-09-24 14:33:21 +0200 | [diff] [blame] | 65 | { |
| 66 | #ifdef CONFIG_ACPI_SLEEP |
| 67 | /* do we have a wakeup address for S2 and S3? */ |
| 68 | if (acpi_state == ACPI_STATE_S3) { |
H. Peter Anvin | 319b6ff | 2012-05-30 12:33:41 +0300 | [diff] [blame] | 69 | if (!acpi_wakeup_address) |
Alexey Starikovskiy | 2f3f2226 | 2007-09-24 14:33:21 +0200 | [diff] [blame] | 70 | return -EFAULT; |
H. Peter Anvin | 319b6ff | 2012-05-30 12:33:41 +0300 | [diff] [blame] | 71 | acpi_set_firmware_waking_vector(acpi_wakeup_address); |
Alexey Starikovskiy | 2f3f2226 | 2007-09-24 14:33:21 +0200 | [diff] [blame] | 72 | |
| 73 | } |
| 74 | ACPI_FLUSH_CPU_CACHE(); |
Alexey Starikovskiy | 2f3f2226 | 2007-09-24 14:33:21 +0200 | [diff] [blame] | 75 | #endif |
Rafael J. Wysocki | c9b6c8f | 2008-01-08 00:10:57 +0100 | [diff] [blame] | 76 | printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n", |
| 77 | acpi_state); |
Rafael J. Wysocki | 78f5f02 | 2010-07-06 22:09:38 -0400 | [diff] [blame] | 78 | acpi_enable_wakeup_devices(acpi_state); |
Alexey Starikovskiy | 2f3f2226 | 2007-09-24 14:33:21 +0200 | [diff] [blame] | 79 | acpi_enter_sleep_state_prep(acpi_state); |
| 80 | return 0; |
| 81 | } |
| 82 | |
Rafael J. Wysocki | 5d1e072 | 2008-10-22 14:58:43 -0400 | [diff] [blame] | 83 | #ifdef CONFIG_ACPI_SLEEP |
Jan Beulich | 091aad6 | 2010-12-07 14:52:25 +0000 | [diff] [blame] | 84 | static u32 acpi_target_sleep_state = ACPI_STATE_S0; |
Rafael J. Wysocki | a5ca734 | 2012-07-23 21:01:02 +0200 | [diff] [blame] | 85 | static bool pwr_btn_event_pending; |
Jan Beulich | 091aad6 | 2010-12-07 14:52:25 +0000 | [diff] [blame] | 86 | |
Zhang Rui | d7f0eea | 2009-12-30 15:36:42 +0800 | [diff] [blame] | 87 | /* |
Rafael J. Wysocki | 72ad5d7 | 2010-07-23 22:59:09 +0200 | [diff] [blame] | 88 | * The ACPI specification wants us to save NVS memory regions during hibernation |
| 89 | * and to restore them during the subsequent resume. Windows does that also for |
| 90 | * suspend to RAM. However, it is known that this mechanism does not work on |
| 91 | * all machines, so we allow the user to disable it with the help of the |
| 92 | * 'acpi_sleep=nonvs' kernel command line option. |
| 93 | */ |
| 94 | static bool nvs_nosave; |
| 95 | |
| 96 | void __init acpi_nvs_nosave(void) |
| 97 | { |
| 98 | nvs_nosave = true; |
| 99 | } |
| 100 | |
| 101 | /* |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 102 | * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the |
| 103 | * user to request that behavior by using the 'acpi_old_suspend_ordering' |
| 104 | * kernel command line option that causes the following variable to be set. |
| 105 | */ |
| 106 | static bool old_suspend_ordering; |
| 107 | |
| 108 | void __init acpi_old_suspend_ordering(void) |
| 109 | { |
| 110 | old_suspend_ordering = true; |
| 111 | } |
| 112 | |
| 113 | /** |
Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 114 | * acpi_pm_freeze - Disable the GPEs and suspend EC transactions. |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 115 | */ |
Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 116 | static int acpi_pm_freeze(void) |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 117 | { |
Lin Ming | 3d97e42 | 2008-12-16 16:57:46 +0800 | [diff] [blame] | 118 | acpi_disable_all_gpes(); |
Lin Ming | bd6f10a | 2012-05-22 16:43:49 +0800 | [diff] [blame] | 119 | acpi_os_wait_events_complete(); |
Rafael J. Wysocki | fe95568 | 2010-04-09 01:40:38 +0200 | [diff] [blame] | 120 | acpi_ec_block_transactions(); |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | /** |
Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 125 | * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS. |
| 126 | */ |
| 127 | static int acpi_pm_pre_suspend(void) |
| 128 | { |
| 129 | acpi_pm_freeze(); |
Jiri Slaby | 26fcaf6 | 2011-01-07 01:42:31 +0100 | [diff] [blame] | 130 | return suspend_nvs_save(); |
Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /** |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 134 | * __acpi_pm_prepare - Prepare the platform to enter the target state. |
| 135 | * |
| 136 | * If necessary, set the firmware waking vector and do arch-specific |
| 137 | * nastiness to get the wakeup code to the waking vector. |
| 138 | */ |
| 139 | static int __acpi_pm_prepare(void) |
| 140 | { |
| 141 | int error = acpi_sleep_prepare(acpi_target_sleep_state); |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 142 | if (error) |
| 143 | acpi_target_sleep_state = ACPI_STATE_S0; |
Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 144 | |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 145 | return error; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * acpi_pm_prepare - Prepare the platform to enter the target sleep |
| 150 | * state and disable the GPEs. |
| 151 | */ |
| 152 | static int acpi_pm_prepare(void) |
| 153 | { |
| 154 | int error = __acpi_pm_prepare(); |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 155 | if (!error) |
Jiri Slaby | 26fcaf6 | 2011-01-07 01:42:31 +0100 | [diff] [blame] | 156 | error = acpi_pm_pre_suspend(); |
Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 157 | |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 158 | return error; |
| 159 | } |
| 160 | |
Daniel Drake | c10d7a1 | 2012-05-10 00:08:43 +0100 | [diff] [blame] | 161 | static int find_powerf_dev(struct device *dev, void *data) |
| 162 | { |
| 163 | struct acpi_device *device = to_acpi_device(dev); |
| 164 | const char *hid = acpi_device_hid(device); |
| 165 | |
| 166 | return !strcmp(hid, ACPI_BUTTON_HID_POWERF); |
| 167 | } |
| 168 | |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 169 | /** |
| 170 | * acpi_pm_finish - Instruct the platform to leave a sleep state. |
| 171 | * |
| 172 | * This is called after we wake back up (or if entering the sleep state |
| 173 | * failed). |
| 174 | */ |
| 175 | static void acpi_pm_finish(void) |
| 176 | { |
Daniel Drake | c10d7a1 | 2012-05-10 00:08:43 +0100 | [diff] [blame] | 177 | struct device *pwr_btn_dev; |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 178 | u32 acpi_state = acpi_target_sleep_state; |
| 179 | |
Len Brown | 42de553 | 2010-06-12 01:15:40 -0400 | [diff] [blame] | 180 | acpi_ec_unblock_transactions(); |
Rafael J. Wysocki | d551d81 | 2011-01-19 22:27:55 +0100 | [diff] [blame] | 181 | suspend_nvs_free(); |
Matthew Garrett | 2a6b697 | 2010-05-28 16:32:15 -0400 | [diff] [blame] | 182 | |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 183 | if (acpi_state == ACPI_STATE_S0) |
| 184 | return; |
| 185 | |
| 186 | printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n", |
| 187 | acpi_state); |
Rafael J. Wysocki | 78f5f02 | 2010-07-06 22:09:38 -0400 | [diff] [blame] | 188 | acpi_disable_wakeup_devices(acpi_state); |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 189 | acpi_leave_sleep_state(acpi_state); |
| 190 | |
| 191 | /* reset firmware waking vector */ |
| 192 | acpi_set_firmware_waking_vector((acpi_physical_address) 0); |
| 193 | |
| 194 | acpi_target_sleep_state = ACPI_STATE_S0; |
Daniel Drake | c10d7a1 | 2012-05-10 00:08:43 +0100 | [diff] [blame] | 195 | |
| 196 | /* If we were woken with the fixed power button, provide a small |
| 197 | * hint to userspace in the form of a wakeup event on the fixed power |
| 198 | * button device (if it can be found). |
| 199 | * |
| 200 | * We delay the event generation til now, as the PM layer requires |
| 201 | * timekeeping to be running before we generate events. */ |
| 202 | if (!pwr_btn_event_pending) |
| 203 | return; |
| 204 | |
| 205 | pwr_btn_event_pending = false; |
| 206 | pwr_btn_dev = bus_find_device(&acpi_bus_type, NULL, NULL, |
| 207 | find_powerf_dev); |
| 208 | if (pwr_btn_dev) { |
| 209 | pm_wakeup_event(pwr_btn_dev, 0); |
| 210 | put_device(pwr_btn_dev); |
| 211 | } |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /** |
| 215 | * acpi_pm_end - Finish up suspend sequence. |
| 216 | */ |
| 217 | static void acpi_pm_end(void) |
| 218 | { |
| 219 | /* |
| 220 | * This is necessary in case acpi_pm_finish() is not called during a |
| 221 | * failing transition to a sleep state. |
| 222 | */ |
| 223 | acpi_target_sleep_state = ACPI_STATE_S0; |
Zhao Yakui | e49f711 | 2008-08-12 10:20:22 +0800 | [diff] [blame] | 224 | acpi_sleep_tts_switch(acpi_target_sleep_state); |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 225 | } |
Rafael J. Wysocki | 92daa7b | 2008-10-23 21:46:43 +0200 | [diff] [blame] | 226 | #else /* !CONFIG_ACPI_SLEEP */ |
| 227 | #define acpi_target_sleep_state ACPI_STATE_S0 |
Rafael J. Wysocki | 5d1e072 | 2008-10-22 14:58:43 -0400 | [diff] [blame] | 228 | #endif /* CONFIG_ACPI_SLEEP */ |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 229 | |
| 230 | #ifdef CONFIG_SUSPEND |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | static u32 acpi_suspend_states[] = { |
Alexey Starikovskiy | e2a5b42 | 2005-03-18 16:20:46 -0500 | [diff] [blame] | 232 | [PM_SUSPEND_ON] = ACPI_STATE_S0, |
| 233 | [PM_SUSPEND_STANDBY] = ACPI_STATE_S1, |
| 234 | [PM_SUSPEND_MEM] = ACPI_STATE_S3, |
Alexey Starikovskiy | e2a5b42 | 2005-03-18 16:20:46 -0500 | [diff] [blame] | 235 | [PM_SUSPEND_MAX] = ACPI_STATE_S5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | }; |
| 237 | |
Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 238 | /** |
Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 239 | * acpi_suspend_begin - Set the target system sleep state to the state |
Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 240 | * associated with given @pm_state, if supported. |
| 241 | */ |
Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 242 | static int acpi_suspend_begin(suspend_state_t pm_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
| 244 | u32 acpi_state = acpi_suspend_states[pm_state]; |
Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 245 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
Rafael J. Wysocki | 72ad5d7 | 2010-07-23 22:59:09 +0200 | [diff] [blame] | 247 | error = nvs_nosave ? 0 : suspend_nvs_alloc(); |
Matthew Garrett | 2a6b697 | 2010-05-28 16:32:15 -0400 | [diff] [blame] | 248 | if (error) |
| 249 | return error; |
| 250 | |
Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 251 | if (sleep_states[acpi_state]) { |
| 252 | acpi_target_sleep_state = acpi_state; |
Zhao Yakui | e49f711 | 2008-08-12 10:20:22 +0800 | [diff] [blame] | 253 | acpi_sleep_tts_switch(acpi_target_sleep_state); |
Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 254 | } else { |
| 255 | printk(KERN_ERR "ACPI does not support this state: %d\n", |
| 256 | pm_state); |
| 257 | error = -ENOSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 259 | return error; |
| 260 | } |
| 261 | |
| 262 | /** |
Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 263 | * acpi_suspend_enter - Actually enter a sleep state. |
Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 264 | * @pm_state: ignored |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | * |
Rafael J. Wysocki | 50ad147 | 2007-07-24 11:58:39 +0200 | [diff] [blame] | 266 | * Flush caches and go to sleep. For STR we have to call arch-specific |
| 267 | * assembly, which in turn call acpi_enter_sleep_state(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | * It's unfortunate, but it works. Please fix if you're feeling frisky. |
| 269 | */ |
Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 270 | static int acpi_suspend_enter(suspend_state_t pm_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { |
| 272 | acpi_status status = AE_OK; |
Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 273 | u32 acpi_state = acpi_target_sleep_state; |
Rafael J. Wysocki | 979f11b | 2011-02-08 23:42:09 +0100 | [diff] [blame] | 274 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
| 276 | ACPI_FLUSH_CPU_CACHE(); |
| 277 | |
Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 278 | switch (acpi_state) { |
| 279 | case ACPI_STATE_S1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | barrier(); |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 281 | status = acpi_enter_sleep_state(acpi_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | break; |
| 283 | |
Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 284 | case ACPI_STATE_S3: |
Rafael J. Wysocki | f1a2003 | 2011-02-08 23:42:22 +0100 | [diff] [blame] | 285 | error = acpi_suspend_lowlevel(); |
Rafael J. Wysocki | 979f11b | 2011-02-08 23:42:09 +0100 | [diff] [blame] | 286 | if (error) |
| 287 | return error; |
Rafael J. Wysocki | 7a63f08 | 2011-02-08 23:41:57 +0100 | [diff] [blame] | 288 | pr_info(PREFIX "Low-level resume complete\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
Arnaud Patard | 872d83d | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 291 | |
Matthew Garrett | b6dacf6 | 2010-05-11 13:49:25 -0400 | [diff] [blame] | 292 | /* This violates the spec but is required for bug compatibility. */ |
| 293 | acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1); |
Rafael J. Wysocki | 65df784 | 2008-11-26 17:53:13 -0500 | [diff] [blame] | 294 | |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 295 | /* Reprogram control registers */ |
| 296 | acpi_leave_sleep_state_prep(acpi_state); |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 297 | |
Pavel Machek | 23b168d | 2008-02-05 19:27:12 +0100 | [diff] [blame] | 298 | /* ACPI 3.0 specs (P62) says that it's the responsibility |
Arnaud Patard | 872d83d | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 299 | * of the OSPM to clear the status bit [ implying that the |
| 300 | * POWER_BUTTON event should not reach userspace ] |
Daniel Drake | c10d7a1 | 2012-05-10 00:08:43 +0100 | [diff] [blame] | 301 | * |
| 302 | * However, we do generate a small hint for userspace in the form of |
| 303 | * a wakeup event. We flag this condition for now and generate the |
| 304 | * event later, as we're currently too early in resume to be able to |
| 305 | * generate wakeup events. |
Arnaud Patard | 872d83d | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 306 | */ |
Daniel Drake | c10d7a1 | 2012-05-10 00:08:43 +0100 | [diff] [blame] | 307 | if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3)) { |
| 308 | acpi_event_status pwr_btn_status; |
| 309 | |
| 310 | acpi_get_event_status(ACPI_EVENT_POWER_BUTTON, &pwr_btn_status); |
| 311 | |
| 312 | if (pwr_btn_status & ACPI_EVENT_FLAG_SET) { |
| 313 | acpi_clear_event(ACPI_EVENT_POWER_BUTTON); |
| 314 | /* Flag for later */ |
| 315 | pwr_btn_event_pending = true; |
| 316 | } |
| 317 | } |
Arnaud Patard | 872d83d | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 318 | |
Shaohua Li | a3627f6 | 2007-06-20 09:17:58 +0800 | [diff] [blame] | 319 | /* |
| 320 | * Disable and clear GPE status before interrupt is enabled. Some GPEs |
| 321 | * (like wakeup GPE) haven't handler, this can avoid such GPE misfire. |
| 322 | * acpi_leave_sleep_state will reenable specific GPEs later |
| 323 | */ |
Lin Ming | 3d97e42 | 2008-12-16 16:57:46 +0800 | [diff] [blame] | 324 | acpi_disable_all_gpes(); |
Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 325 | /* Allow EC transactions to happen. */ |
Rafael J. Wysocki | fe95568 | 2010-04-09 01:40:38 +0200 | [diff] [blame] | 326 | acpi_ec_unblock_transactions_early(); |
Shaohua Li | a3627f6 | 2007-06-20 09:17:58 +0800 | [diff] [blame] | 327 | |
Matthew Garrett | 2a6b697 | 2010-05-28 16:32:15 -0400 | [diff] [blame] | 328 | suspend_nvs_restore(); |
| 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | return ACPI_SUCCESS(status) ? 0 : -EFAULT; |
| 331 | } |
| 332 | |
Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 333 | static int acpi_suspend_state_valid(suspend_state_t pm_state) |
Shaohua Li | eb9289e | 2005-10-30 15:00:01 -0800 | [diff] [blame] | 334 | { |
Johannes Berg | e8c9c50 | 2007-04-30 15:09:54 -0700 | [diff] [blame] | 335 | u32 acpi_state; |
Shaohua Li | eb9289e | 2005-10-30 15:00:01 -0800 | [diff] [blame] | 336 | |
Johannes Berg | e8c9c50 | 2007-04-30 15:09:54 -0700 | [diff] [blame] | 337 | switch (pm_state) { |
| 338 | case PM_SUSPEND_ON: |
| 339 | case PM_SUSPEND_STANDBY: |
| 340 | case PM_SUSPEND_MEM: |
| 341 | acpi_state = acpi_suspend_states[pm_state]; |
| 342 | |
| 343 | return sleep_states[acpi_state]; |
| 344 | default: |
| 345 | return 0; |
| 346 | } |
Shaohua Li | eb9289e | 2005-10-30 15:00:01 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Lionel Debroux | 2f55ac0 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 349 | static const struct platform_suspend_ops acpi_suspend_ops = { |
Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 350 | .valid = acpi_suspend_state_valid, |
| 351 | .begin = acpi_suspend_begin, |
Rafael J. Wysocki | 6a7c7ea | 2009-04-19 20:08:42 +0200 | [diff] [blame] | 352 | .prepare_late = acpi_pm_prepare, |
Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 353 | .enter = acpi_suspend_enter, |
Rafael J. Wysocki | 618d7fd | 2010-07-02 00:14:57 +0200 | [diff] [blame] | 354 | .wake = acpi_pm_finish, |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 355 | .end = acpi_pm_end, |
| 356 | }; |
| 357 | |
| 358 | /** |
| 359 | * acpi_suspend_begin_old - Set the target system sleep state to the |
| 360 | * state associated with given @pm_state, if supported, and |
| 361 | * execute the _PTS control method. This function is used if the |
| 362 | * pre-ACPI 2.0 suspend ordering has been requested. |
| 363 | */ |
| 364 | static int acpi_suspend_begin_old(suspend_state_t pm_state) |
| 365 | { |
| 366 | int error = acpi_suspend_begin(pm_state); |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 367 | if (!error) |
| 368 | error = __acpi_pm_prepare(); |
Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 369 | |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 370 | return error; |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 | * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has |
| 375 | * been requested. |
| 376 | */ |
Lionel Debroux | 2f55ac0 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 377 | static const struct platform_suspend_ops acpi_suspend_ops_old = { |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 378 | .valid = acpi_suspend_state_valid, |
| 379 | .begin = acpi_suspend_begin_old, |
Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 380 | .prepare_late = acpi_pm_pre_suspend, |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 381 | .enter = acpi_suspend_enter, |
Rafael J. Wysocki | 618d7fd | 2010-07-02 00:14:57 +0200 | [diff] [blame] | 382 | .wake = acpi_pm_finish, |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 383 | .end = acpi_pm_end, |
| 384 | .recover = acpi_pm_finish, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | }; |
Carlos Corbacho | e41fb7c | 2008-07-23 21:28:43 -0700 | [diff] [blame] | 386 | |
| 387 | static int __init init_old_suspend_ordering(const struct dmi_system_id *d) |
| 388 | { |
| 389 | old_suspend_ordering = true; |
| 390 | return 0; |
| 391 | } |
| 392 | |
Rafael J. Wysocki | 5399864 | 2010-09-24 16:46:14 -0400 | [diff] [blame] | 393 | static int __init init_nvs_nosave(const struct dmi_system_id *d) |
| 394 | { |
| 395 | acpi_nvs_nosave(); |
| 396 | return 0; |
| 397 | } |
| 398 | |
Carlos Corbacho | e41fb7c | 2008-07-23 21:28:43 -0700 | [diff] [blame] | 399 | static struct dmi_system_id __initdata acpisleep_dmi_table[] = { |
| 400 | { |
| 401 | .callback = init_old_suspend_ordering, |
| 402 | .ident = "Abit KN9 (nForce4 variant)", |
| 403 | .matches = { |
| 404 | DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"), |
| 405 | DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"), |
| 406 | }, |
| 407 | }, |
Rafael J. Wysocki | 4fb507b | 2008-10-14 22:54:06 +0200 | [diff] [blame] | 408 | { |
| 409 | .callback = init_old_suspend_ordering, |
| 410 | .ident = "HP xw4600 Workstation", |
| 411 | .matches = { |
| 412 | DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), |
| 413 | DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"), |
| 414 | }, |
| 415 | }, |
Rafael J. Wysocki | 65df784 | 2008-11-26 17:53:13 -0500 | [diff] [blame] | 416 | { |
Andy Whitcroft | a140449 | 2009-02-11 18:11:22 +0000 | [diff] [blame] | 417 | .callback = init_old_suspend_ordering, |
| 418 | .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)", |
| 419 | .matches = { |
| 420 | DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."), |
| 421 | DMI_MATCH(DMI_BOARD_NAME, "M2N8L"), |
| 422 | }, |
| 423 | }, |
Zhang Rui | 45e7798 | 2009-03-15 22:13:44 -0400 | [diff] [blame] | 424 | { |
Zhao Yakui | 2a9ef8e | 2009-03-18 16:36:25 +0800 | [diff] [blame] | 425 | .callback = init_old_suspend_ordering, |
| 426 | .ident = "Panasonic CF51-2L", |
| 427 | .matches = { |
| 428 | DMI_MATCH(DMI_BOARD_VENDOR, |
| 429 | "Matsushita Electric Industrial Co.,Ltd."), |
| 430 | DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"), |
| 431 | }, |
| 432 | }, |
Rafael J. Wysocki | 5399864 | 2010-09-24 16:46:14 -0400 | [diff] [blame] | 433 | { |
| 434 | .callback = init_nvs_nosave, |
Dave Jones | d11c78e | 2011-10-19 23:15:11 +0200 | [diff] [blame] | 435 | .ident = "Sony Vaio VGN-FW21E", |
| 436 | .matches = { |
| 437 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), |
| 438 | DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"), |
| 439 | }, |
| 440 | }, |
| 441 | { |
| 442 | .callback = init_nvs_nosave, |
Dave Jones | ddf6ce4 | 2011-11-03 00:58:59 +0100 | [diff] [blame] | 443 | .ident = "Sony Vaio VPCEB17FX", |
| 444 | .matches = { |
| 445 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), |
| 446 | DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"), |
| 447 | }, |
| 448 | }, |
| 449 | { |
| 450 | .callback = init_nvs_nosave, |
Rafael J. Wysocki | 5399864 | 2010-09-24 16:46:14 -0400 | [diff] [blame] | 451 | .ident = "Sony Vaio VGN-SR11M", |
| 452 | .matches = { |
| 453 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), |
| 454 | DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"), |
| 455 | }, |
| 456 | }, |
| 457 | { |
| 458 | .callback = init_nvs_nosave, |
| 459 | .ident = "Everex StepNote Series", |
| 460 | .matches = { |
| 461 | DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."), |
| 462 | DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"), |
| 463 | }, |
| 464 | }, |
Rafael J. Wysocki | af48931 | 2010-10-17 21:01:21 +0200 | [diff] [blame] | 465 | { |
| 466 | .callback = init_nvs_nosave, |
| 467 | .ident = "Sony Vaio VPCEB1Z1E", |
| 468 | .matches = { |
| 469 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), |
| 470 | DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"), |
| 471 | }, |
| 472 | }, |
Rafael J. Wysocki | 291a73c | 2010-12-12 21:10:42 +0100 | [diff] [blame] | 473 | { |
| 474 | .callback = init_nvs_nosave, |
| 475 | .ident = "Sony Vaio VGN-NW130D", |
| 476 | .matches = { |
| 477 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), |
| 478 | DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"), |
| 479 | }, |
| 480 | }, |
Rafael J. Wysocki | 7b33070 | 2011-01-06 23:37:01 +0100 | [diff] [blame] | 481 | { |
| 482 | .callback = init_nvs_nosave, |
Lan Tianyu | 93f7708 | 2012-01-21 09:23:56 +0800 | [diff] [blame] | 483 | .ident = "Sony Vaio VPCCW29FX", |
| 484 | .matches = { |
| 485 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), |
| 486 | DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"), |
| 487 | }, |
| 488 | }, |
| 489 | { |
| 490 | .callback = init_nvs_nosave, |
Rafael J. Wysocki | 7b33070 | 2011-01-06 23:37:01 +0100 | [diff] [blame] | 491 | .ident = "Averatec AV1020-ED2", |
| 492 | .matches = { |
| 493 | DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"), |
| 494 | DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"), |
| 495 | }, |
| 496 | }, |
Zhang Rui | bb0c5ed | 2011-07-30 01:40:48 -0400 | [diff] [blame] | 497 | { |
| 498 | .callback = init_old_suspend_ordering, |
| 499 | .ident = "Asus A8N-SLI DELUXE", |
| 500 | .matches = { |
| 501 | DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), |
| 502 | DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"), |
| 503 | }, |
| 504 | }, |
| 505 | { |
| 506 | .callback = init_old_suspend_ordering, |
| 507 | .ident = "Asus A8N-SLI Premium", |
| 508 | .matches = { |
| 509 | DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), |
| 510 | DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"), |
| 511 | }, |
| 512 | }, |
Rafael J. Wysocki | 89e8ea1 | 2011-10-06 20:35:03 +0200 | [diff] [blame] | 513 | { |
| 514 | .callback = init_nvs_nosave, |
| 515 | .ident = "Sony Vaio VGN-SR26GN_P", |
| 516 | .matches = { |
| 517 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), |
| 518 | DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"), |
| 519 | }, |
| 520 | }, |
Bogdan Radulescu | 731b25a | 2011-10-06 20:35:12 +0200 | [diff] [blame] | 521 | { |
| 522 | .callback = init_nvs_nosave, |
| 523 | .ident = "Sony Vaio VGN-FW520F", |
| 524 | .matches = { |
| 525 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), |
| 526 | DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"), |
| 527 | }, |
| 528 | }, |
Keng-Yu Lin | 5a50a7c | 2011-12-02 00:04:23 +0100 | [diff] [blame] | 529 | { |
| 530 | .callback = init_nvs_nosave, |
| 531 | .ident = "Asus K54C", |
| 532 | .matches = { |
| 533 | DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."), |
| 534 | DMI_MATCH(DMI_PRODUCT_NAME, "K54C"), |
| 535 | }, |
| 536 | }, |
| 537 | { |
| 538 | .callback = init_nvs_nosave, |
| 539 | .ident = "Asus K54HR", |
| 540 | .matches = { |
| 541 | DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."), |
| 542 | DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"), |
| 543 | }, |
| 544 | }, |
Carlos Corbacho | e41fb7c | 2008-07-23 21:28:43 -0700 | [diff] [blame] | 545 | {}, |
| 546 | }; |
Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 547 | #endif /* CONFIG_SUSPEND */ |
| 548 | |
Rafael J. Wysocki | b0cb1a1 | 2007-07-29 23:24:36 +0200 | [diff] [blame] | 549 | #ifdef CONFIG_HIBERNATION |
Shaohua Li | bdfe6b7 | 2008-07-23 21:28:41 -0700 | [diff] [blame] | 550 | static unsigned long s4_hardware_signature; |
| 551 | static struct acpi_table_facs *facs; |
| 552 | static bool nosigcheck; |
| 553 | |
| 554 | void __init acpi_no_s4_hw_signature(void) |
| 555 | { |
| 556 | nosigcheck = true; |
| 557 | } |
| 558 | |
Rafael J. Wysocki | caea99e | 2008-01-08 00:08:44 +0100 | [diff] [blame] | 559 | static int acpi_hibernation_begin(void) |
Rafael J. Wysocki | 74f270a | 2007-10-18 03:04:42 -0700 | [diff] [blame] | 560 | { |
Rafael J. Wysocki | 3f4b0ef | 2008-10-26 20:52:15 +0100 | [diff] [blame] | 561 | int error; |
| 562 | |
Rafael J. Wysocki | 72ad5d7 | 2010-07-23 22:59:09 +0200 | [diff] [blame] | 563 | error = nvs_nosave ? 0 : suspend_nvs_alloc(); |
Rafael J. Wysocki | 3f4b0ef | 2008-10-26 20:52:15 +0100 | [diff] [blame] | 564 | if (!error) { |
| 565 | acpi_target_sleep_state = ACPI_STATE_S4; |
| 566 | acpi_sleep_tts_switch(acpi_target_sleep_state); |
| 567 | } |
| 568 | |
| 569 | return error; |
| 570 | } |
| 571 | |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 572 | static int acpi_hibernation_enter(void) |
| 573 | { |
| 574 | acpi_status status = AE_OK; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 575 | |
| 576 | ACPI_FLUSH_CPU_CACHE(); |
| 577 | |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 578 | /* This shouldn't return. If it returns, we have a problem */ |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 579 | status = acpi_enter_sleep_state(ACPI_STATE_S4); |
| 580 | /* Reprogram control registers */ |
| 581 | acpi_leave_sleep_state_prep(ACPI_STATE_S4); |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 582 | |
| 583 | return ACPI_SUCCESS(status) ? 0 : -EFAULT; |
| 584 | } |
| 585 | |
Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 586 | static void acpi_hibernation_leave(void) |
| 587 | { |
| 588 | /* |
| 589 | * If ACPI is not enabled by the BIOS and the boot kernel, we need to |
| 590 | * enable it here. |
| 591 | */ |
| 592 | acpi_enable(); |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 593 | /* Reprogram control registers */ |
| 594 | acpi_leave_sleep_state_prep(ACPI_STATE_S4); |
Shaohua Li | bdfe6b7 | 2008-07-23 21:28:41 -0700 | [diff] [blame] | 595 | /* Check the hardware signature */ |
| 596 | if (facs && s4_hardware_signature != facs->hardware_signature) { |
| 597 | printk(KERN_EMERG "ACPI: Hardware changed while hibernated, " |
| 598 | "cannot resume!\n"); |
| 599 | panic("ACPI S4 hardware signature mismatch"); |
| 600 | } |
Rafael J. Wysocki | 3f4b0ef | 2008-10-26 20:52:15 +0100 | [diff] [blame] | 601 | /* Restore the NVS memory area */ |
Matthew Garrett | dd4c4f1 | 2010-05-28 16:32:14 -0400 | [diff] [blame] | 602 | suspend_nvs_restore(); |
Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 603 | /* Allow EC transactions to happen. */ |
Rafael J. Wysocki | fe95568 | 2010-04-09 01:40:38 +0200 | [diff] [blame] | 604 | acpi_ec_unblock_transactions_early(); |
Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 607 | static void acpi_pm_thaw(void) |
Rafael J. Wysocki | f6bb13a | 2010-03-04 01:52:58 +0100 | [diff] [blame] | 608 | { |
Rafael J. Wysocki | fe95568 | 2010-04-09 01:40:38 +0200 | [diff] [blame] | 609 | acpi_ec_unblock_transactions(); |
Lin Ming | 3d97e42 | 2008-12-16 16:57:46 +0800 | [diff] [blame] | 610 | acpi_enable_all_runtime_gpes(); |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Lionel Debroux | 073ef1f | 2010-11-09 21:48:49 +0100 | [diff] [blame] | 613 | static const struct platform_hibernation_ops acpi_hibernation_ops = { |
Rafael J. Wysocki | caea99e | 2008-01-08 00:08:44 +0100 | [diff] [blame] | 614 | .begin = acpi_hibernation_begin, |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 615 | .end = acpi_pm_end, |
Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 616 | .pre_snapshot = acpi_pm_prepare, |
Matthew Garrett | 2a6b697 | 2010-05-28 16:32:15 -0400 | [diff] [blame] | 617 | .finish = acpi_pm_finish, |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 618 | .prepare = acpi_pm_prepare, |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 619 | .enter = acpi_hibernation_enter, |
Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 620 | .leave = acpi_hibernation_leave, |
Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 621 | .pre_restore = acpi_pm_freeze, |
| 622 | .restore_cleanup = acpi_pm_thaw, |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 623 | }; |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 624 | |
| 625 | /** |
| 626 | * acpi_hibernation_begin_old - Set the target system sleep state to |
| 627 | * ACPI_STATE_S4 and execute the _PTS control method. This |
| 628 | * function is used if the pre-ACPI 2.0 suspend ordering has been |
| 629 | * requested. |
| 630 | */ |
| 631 | static int acpi_hibernation_begin_old(void) |
| 632 | { |
Zhao Yakui | e49f711 | 2008-08-12 10:20:22 +0800 | [diff] [blame] | 633 | int error; |
| 634 | /* |
| 635 | * The _TTS object should always be evaluated before the _PTS object. |
| 636 | * When the old_suspended_ordering is true, the _PTS object is |
| 637 | * evaluated in the acpi_sleep_prepare. |
| 638 | */ |
| 639 | acpi_sleep_tts_switch(ACPI_STATE_S4); |
| 640 | |
| 641 | error = acpi_sleep_prepare(ACPI_STATE_S4); |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 642 | |
Rafael J. Wysocki | 3f4b0ef | 2008-10-26 20:52:15 +0100 | [diff] [blame] | 643 | if (!error) { |
Rafael J. Wysocki | 72ad5d7 | 2010-07-23 22:59:09 +0200 | [diff] [blame] | 644 | if (!nvs_nosave) |
Matthew Garrett | dd4c4f1 | 2010-05-28 16:32:14 -0400 | [diff] [blame] | 645 | error = suspend_nvs_alloc(); |
Rafael J. Wysocki | 3f4b0ef | 2008-10-26 20:52:15 +0100 | [diff] [blame] | 646 | if (!error) |
| 647 | acpi_target_sleep_state = ACPI_STATE_S4; |
| 648 | } |
| 649 | return error; |
| 650 | } |
| 651 | |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 652 | /* |
| 653 | * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has |
| 654 | * been requested. |
| 655 | */ |
Lionel Debroux | 073ef1f | 2010-11-09 21:48:49 +0100 | [diff] [blame] | 656 | static const struct platform_hibernation_ops acpi_hibernation_ops_old = { |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 657 | .begin = acpi_hibernation_begin_old, |
| 658 | .end = acpi_pm_end, |
Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 659 | .pre_snapshot = acpi_pm_pre_suspend, |
Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 660 | .prepare = acpi_pm_freeze, |
Matthew Garrett | 2a6b697 | 2010-05-28 16:32:15 -0400 | [diff] [blame] | 661 | .finish = acpi_pm_finish, |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 662 | .enter = acpi_hibernation_enter, |
| 663 | .leave = acpi_hibernation_leave, |
Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 664 | .pre_restore = acpi_pm_freeze, |
| 665 | .restore_cleanup = acpi_pm_thaw, |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 666 | .recover = acpi_pm_finish, |
| 667 | }; |
| 668 | #endif /* CONFIG_HIBERNATION */ |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 669 | |
Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 670 | int acpi_suspend(u32 acpi_state) |
| 671 | { |
| 672 | suspend_state_t states[] = { |
| 673 | [1] = PM_SUSPEND_STANDBY, |
| 674 | [3] = PM_SUSPEND_MEM, |
| 675 | [5] = PM_SUSPEND_MAX |
| 676 | }; |
| 677 | |
| 678 | if (acpi_state < 6 && states[acpi_state]) |
| 679 | return pm_suspend(states[acpi_state]); |
| 680 | if (acpi_state == 4) |
| 681 | return hibernate(); |
| 682 | return -EINVAL; |
| 683 | } |
| 684 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 685 | #ifdef CONFIG_PM |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 686 | /** |
Rafael J. Wysocki | bdda27f | 2012-10-26 13:40:04 +0200 | [diff] [blame^] | 687 | * acpi_pm_device_sleep_state - Get preferred power state of ACPI device. |
| 688 | * @dev: Device whose preferred target power state to return. |
| 689 | * @d_min_p: Location to store the upper limit of the allowed states range. |
| 690 | * @d_max_in: Deepest low-power state to take into consideration. |
| 691 | * Return value: Preferred power state of the device on success, -ENODEV |
| 692 | * (if there's no 'struct acpi_device' for @dev) or -EINVAL on failure |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 693 | * |
Rafael J. Wysocki | bdda27f | 2012-10-26 13:40:04 +0200 | [diff] [blame^] | 694 | * Find the lowest power (highest number) ACPI device power state that the |
| 695 | * device can be in while the system is in the sleep state represented |
| 696 | * by %acpi_target_sleep_state. If @d_min_p is set, the highest power (lowest |
| 697 | * number) device power state that @dev can be in for the given system sleep |
| 698 | * state is stored at the location pointed to by it. |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 699 | * |
Rafael J. Wysocki | bdda27f | 2012-10-26 13:40:04 +0200 | [diff] [blame^] | 700 | * The caller must ensure that @dev is valid before using this function. |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 701 | */ |
Huang Ying | ee85f54 | 2012-06-23 10:23:48 +0800 | [diff] [blame] | 702 | int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in) |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 703 | { |
| 704 | acpi_handle handle = DEVICE_ACPI_HANDLE(dev); |
| 705 | struct acpi_device *adev; |
| 706 | char acpi_method[] = "_SxD"; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 707 | unsigned long long d_min, d_max; |
Rafael J. Wysocki | 8b713a8 | 2012-10-24 02:08:38 +0200 | [diff] [blame] | 708 | bool wakeup = false; |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 709 | |
Huang Ying | ee85f54 | 2012-06-23 10:23:48 +0800 | [diff] [blame] | 710 | if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3) |
| 711 | return -EINVAL; |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 712 | if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { |
Shaohua Li | ead7759 | 2007-08-23 15:01:13 +0800 | [diff] [blame] | 713 | printk(KERN_DEBUG "ACPI handle has no context!\n"); |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 714 | return -ENODEV; |
| 715 | } |
Rafael J. Wysocki | 8b713a8 | 2012-10-24 02:08:38 +0200 | [diff] [blame] | 716 | if (d_max_in > ACPI_STATE_D3_HOT) { |
| 717 | enum pm_qos_flags_status stat; |
| 718 | |
| 719 | stat = dev_pm_qos_flags(dev, PM_QOS_FLAG_NO_POWER_OFF); |
| 720 | if (stat == PM_QOS_FLAGS_ALL) |
| 721 | d_max_in = ACPI_STATE_D3_HOT; |
| 722 | } |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 723 | |
| 724 | acpi_method[2] = '0' + acpi_target_sleep_state; |
| 725 | /* |
Huang Ying | ee85f54 | 2012-06-23 10:23:48 +0800 | [diff] [blame] | 726 | * If the sleep state is S0, the lowest limit from ACPI is D3, |
| 727 | * but if the device has _S0W, we will use the value from _S0W |
| 728 | * as the lowest limit from ACPI. Finally, we will constrain |
| 729 | * the lowest limit with the specified one. |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 730 | */ |
| 731 | d_min = ACPI_STATE_D0; |
| 732 | d_max = ACPI_STATE_D3; |
| 733 | |
| 734 | /* |
| 735 | * If present, _SxD methods return the minimum D-state (highest power |
| 736 | * state) we can use for the corresponding S-states. Otherwise, the |
| 737 | * minimum D-state is D0 (ACPI 3.x). |
| 738 | * |
| 739 | * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer |
| 740 | * provided -- that's our fault recovery, we ignore retval. |
| 741 | */ |
Rafael J. Wysocki | 8b713a8 | 2012-10-24 02:08:38 +0200 | [diff] [blame] | 742 | if (acpi_target_sleep_state > ACPI_STATE_S0) { |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 743 | acpi_evaluate_integer(handle, acpi_method, NULL, &d_min); |
Rafael J. Wysocki | 8b713a8 | 2012-10-24 02:08:38 +0200 | [diff] [blame] | 744 | wakeup = device_may_wakeup(dev) && adev->wakeup.flags.valid |
| 745 | && adev->wakeup.sleep_state >= acpi_target_sleep_state; |
| 746 | } else if (dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) != |
| 747 | PM_QOS_FLAGS_NONE) { |
| 748 | wakeup = adev->wakeup.flags.valid; |
| 749 | } |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 750 | |
| 751 | /* |
| 752 | * If _PRW says we can wake up the system from the target sleep state, |
| 753 | * the D-state returned by _SxD is sufficient for that (we assume a |
| 754 | * wakeup-aware driver if wake is set). Still, if _SxW exists |
| 755 | * (ACPI 3.x), it should return the maximum (lowest power) D-state that |
| 756 | * can wake the system. _S0W may be valid, too. |
| 757 | */ |
Rafael J. Wysocki | 8b713a8 | 2012-10-24 02:08:38 +0200 | [diff] [blame] | 758 | if (wakeup) { |
Rafael J. Wysocki | ad3399c | 2008-01-11 00:10:38 +0100 | [diff] [blame] | 759 | acpi_status status; |
| 760 | |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 761 | acpi_method[3] = 'W'; |
Rafael J. Wysocki | ad3399c | 2008-01-11 00:10:38 +0100 | [diff] [blame] | 762 | status = acpi_evaluate_integer(handle, acpi_method, NULL, |
| 763 | &d_max); |
| 764 | if (ACPI_FAILURE(status)) { |
Rafael J. Wysocki | 761afb8 | 2010-10-14 23:24:13 +0200 | [diff] [blame] | 765 | if (acpi_target_sleep_state != ACPI_STATE_S0 || |
| 766 | status != AE_NOT_FOUND) |
| 767 | d_max = d_min; |
Rafael J. Wysocki | ad3399c | 2008-01-11 00:10:38 +0100 | [diff] [blame] | 768 | } else if (d_max < d_min) { |
| 769 | /* Warn the user of the broken DSDT */ |
| 770 | printk(KERN_WARNING "ACPI: Wrong value from %s\n", |
| 771 | acpi_method); |
| 772 | /* Sanitize it */ |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 773 | d_min = d_max; |
Rafael J. Wysocki | ad3399c | 2008-01-11 00:10:38 +0100 | [diff] [blame] | 774 | } |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 775 | } |
| 776 | |
Huang Ying | ee85f54 | 2012-06-23 10:23:48 +0800 | [diff] [blame] | 777 | if (d_max_in < d_min) |
| 778 | return -EINVAL; |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 779 | if (d_min_p) |
| 780 | *d_min_p = d_min; |
Huang Ying | ee85f54 | 2012-06-23 10:23:48 +0800 | [diff] [blame] | 781 | /* constrain d_max with specified lowest limit (max number) */ |
| 782 | if (d_max > d_max_in) { |
| 783 | for (d_max = d_max_in; d_max > d_min; d_max--) { |
| 784 | if (adev->power.states[d_max].flags.valid) |
| 785 | break; |
| 786 | } |
| 787 | } |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 788 | return d_max; |
| 789 | } |
Lin Ming | 3bd4660 | 2012-06-25 16:13:06 +0800 | [diff] [blame] | 790 | EXPORT_SYMBOL(acpi_pm_device_sleep_state); |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 791 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 792 | |
Rafael J. Wysocki | bdda27f | 2012-10-26 13:40:04 +0200 | [diff] [blame^] | 793 | #ifdef CONFIG_PM_RUNTIME |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 794 | /** |
Rafael J. Wysocki | bdda27f | 2012-10-26 13:40:04 +0200 | [diff] [blame^] | 795 | * acpi_pm_device_run_wake - Enable/disable remote wakeup for given device. |
| 796 | * @phys_dev: Device to enable/disable the platform to wake up. |
| 797 | * @enable: Whether to enable or disable the wakeup functionality. |
Lin Ming | b24e509 | 2012-03-27 15:43:25 +0800 | [diff] [blame] | 798 | * |
Rafael J. Wysocki | bdda27f | 2012-10-26 13:40:04 +0200 | [diff] [blame^] | 799 | * Find the ACPI device object corresponding to @phys_dev and try to |
| 800 | * enable/disable the GPE associated with it, so that it can generate |
| 801 | * wakeup signals for the device in response to external (remote) events. |
Lin Ming | b24e509 | 2012-03-27 15:43:25 +0800 | [diff] [blame] | 802 | */ |
| 803 | int acpi_pm_device_run_wake(struct device *phys_dev, bool enable) |
| 804 | { |
| 805 | struct acpi_device *dev; |
| 806 | acpi_handle handle; |
| 807 | |
| 808 | if (!device_run_wake(phys_dev)) |
| 809 | return -EINVAL; |
| 810 | |
| 811 | handle = DEVICE_ACPI_HANDLE(phys_dev); |
| 812 | if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &dev))) { |
| 813 | dev_dbg(phys_dev, "ACPI handle has no context in %s!\n", |
| 814 | __func__); |
| 815 | return -ENODEV; |
| 816 | } |
| 817 | |
| 818 | if (enable) { |
| 819 | acpi_enable_wakeup_device_power(dev, ACPI_STATE_S0); |
| 820 | acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number); |
| 821 | } else { |
| 822 | acpi_disable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number); |
| 823 | acpi_disable_wakeup_device_power(dev); |
| 824 | } |
| 825 | |
| 826 | return 0; |
| 827 | } |
Lin Ming | 3bd4660 | 2012-06-25 16:13:06 +0800 | [diff] [blame] | 828 | EXPORT_SYMBOL(acpi_pm_device_run_wake); |
Rafael J. Wysocki | bdda27f | 2012-10-26 13:40:04 +0200 | [diff] [blame^] | 829 | #endif /* CONFIG_PM_RUNTIME */ |
Lin Ming | b24e509 | 2012-03-27 15:43:25 +0800 | [diff] [blame] | 830 | |
Rafael J. Wysocki | bdda27f | 2012-10-26 13:40:04 +0200 | [diff] [blame^] | 831 | #ifdef CONFIG_PM_SLEEP |
Lin Ming | b24e509 | 2012-03-27 15:43:25 +0800 | [diff] [blame] | 832 | /** |
Rafael J. Wysocki | bdda27f | 2012-10-26 13:40:04 +0200 | [diff] [blame^] | 833 | * acpi_pm_device_sleep_wake - Enable or disable device to wake up the system. |
| 834 | * @dev: Device to enable/desible to wake up the system from sleep states. |
| 835 | * @enable: Whether to enable or disable @dev to wake up the system. |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 836 | */ |
| 837 | int acpi_pm_device_sleep_wake(struct device *dev, bool enable) |
| 838 | { |
| 839 | acpi_handle handle; |
| 840 | struct acpi_device *adev; |
Rafael J. Wysocki | df8db91 | 2009-09-08 23:13:49 +0200 | [diff] [blame] | 841 | int error; |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 842 | |
Rafael J. Wysocki | 0baed8d | 2009-09-08 23:16:24 +0200 | [diff] [blame] | 843 | if (!device_can_wakeup(dev)) |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 844 | return -EINVAL; |
| 845 | |
| 846 | handle = DEVICE_ACPI_HANDLE(dev); |
| 847 | if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { |
Rafael J. Wysocki | df8db91 | 2009-09-08 23:13:49 +0200 | [diff] [blame] | 848 | dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__); |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 849 | return -ENODEV; |
| 850 | } |
| 851 | |
Rafael J. Wysocki | e8b6f97 | 2010-06-25 01:18:39 +0200 | [diff] [blame] | 852 | error = enable ? |
| 853 | acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) : |
| 854 | acpi_disable_wakeup_device_power(adev); |
Rafael J. Wysocki | df8db91 | 2009-09-08 23:13:49 +0200 | [diff] [blame] | 855 | if (!error) |
| 856 | dev_info(dev, "wake-up capability %s by ACPI\n", |
| 857 | enable ? "enabled" : "disabled"); |
| 858 | |
| 859 | return error; |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 860 | } |
Rafael J. Wysocki | 761afb8 | 2010-10-14 23:24:13 +0200 | [diff] [blame] | 861 | #endif /* CONFIG_PM_SLEEP */ |
Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 862 | |
Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 863 | static void acpi_power_off_prepare(void) |
| 864 | { |
| 865 | /* Prepare to power off the system */ |
| 866 | acpi_sleep_prepare(ACPI_STATE_S5); |
Lin Ming | 3d97e42 | 2008-12-16 16:57:46 +0800 | [diff] [blame] | 867 | acpi_disable_all_gpes(); |
Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | static void acpi_power_off(void) |
| 871 | { |
| 872 | /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */ |
Frank Seidel | 4d93915 | 2009-02-04 17:03:07 +0100 | [diff] [blame] | 873 | printk(KERN_DEBUG "%s called\n", __func__); |
Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 874 | local_irq_disable(); |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 875 | acpi_enter_sleep_state(ACPI_STATE_S5); |
Len Brown | 96f15ef | 2009-04-17 23:32:20 -0400 | [diff] [blame] | 876 | } |
| 877 | |
Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 878 | int __init acpi_sleep_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | { |
Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 880 | acpi_status status; |
| 881 | u8 type_a, type_b; |
| 882 | #ifdef CONFIG_SUSPEND |
Alexey Starikovskiy | e2a5b42 | 2005-03-18 16:20:46 -0500 | [diff] [blame] | 883 | int i = 0; |
Carlos Corbacho | e41fb7c | 2008-07-23 21:28:43 -0700 | [diff] [blame] | 884 | |
| 885 | dmi_check_system(acpisleep_dmi_table); |
Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 886 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | |
| 888 | if (acpi_disabled) |
| 889 | return 0; |
| 890 | |
Frans Pop | 5a50fe7 | 2007-09-20 22:27:44 +0200 | [diff] [blame] | 891 | sleep_states[ACPI_STATE_S0] = 1; |
| 892 | printk(KERN_INFO PREFIX "(supports S0"); |
| 893 | |
Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 894 | #ifdef CONFIG_SUSPEND |
Frans Pop | 5a50fe7 | 2007-09-20 22:27:44 +0200 | [diff] [blame] | 895 | for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | status = acpi_get_sleep_type_data(i, &type_a, &type_b); |
| 897 | if (ACPI_SUCCESS(status)) { |
| 898 | sleep_states[i] = 1; |
Kay Sievers | be96447 | 2012-05-08 17:24:20 +0200 | [diff] [blame] | 899 | printk(KERN_CONT " S%d", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 903 | suspend_set_ops(old_suspend_ordering ? |
| 904 | &acpi_suspend_ops_old : &acpi_suspend_ops); |
Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 905 | #endif |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 906 | |
Rafael J. Wysocki | b0cb1a1 | 2007-07-29 23:24:36 +0200 | [diff] [blame] | 907 | #ifdef CONFIG_HIBERNATION |
Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 908 | status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b); |
| 909 | if (ACPI_SUCCESS(status)) { |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 910 | hibernation_set_ops(old_suspend_ordering ? |
| 911 | &acpi_hibernation_ops_old : &acpi_hibernation_ops); |
Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 912 | sleep_states[ACPI_STATE_S4] = 1; |
Kay Sievers | be96447 | 2012-05-08 17:24:20 +0200 | [diff] [blame] | 913 | printk(KERN_CONT " S4"); |
Shaohua Li | bdfe6b7 | 2008-07-23 21:28:41 -0700 | [diff] [blame] | 914 | if (!nosigcheck) { |
Lin Ming | 3d97e42 | 2008-12-16 16:57:46 +0800 | [diff] [blame] | 915 | acpi_get_table(ACPI_SIG_FACS, 1, |
Shaohua Li | bdfe6b7 | 2008-07-23 21:28:41 -0700 | [diff] [blame] | 916 | (struct acpi_table_header **)&facs); |
| 917 | if (facs) |
| 918 | s4_hardware_signature = |
| 919 | facs->hardware_signature; |
| 920 | } |
Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 921 | } |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 922 | #endif |
Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 923 | status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); |
| 924 | if (ACPI_SUCCESS(status)) { |
| 925 | sleep_states[ACPI_STATE_S5] = 1; |
Kay Sievers | be96447 | 2012-05-08 17:24:20 +0200 | [diff] [blame] | 926 | printk(KERN_CONT " S5"); |
Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 927 | pm_power_off_prepare = acpi_power_off_prepare; |
| 928 | pm_power_off = acpi_power_off; |
| 929 | } |
Kay Sievers | be96447 | 2012-05-08 17:24:20 +0200 | [diff] [blame] | 930 | printk(KERN_CONT ")\n"); |
Zhao Yakui | e49f711 | 2008-08-12 10:20:22 +0800 | [diff] [blame] | 931 | /* |
| 932 | * Register the tts_notifier to reboot notifier list so that the _TTS |
| 933 | * object can also be evaluated when the system enters S5. |
| 934 | */ |
| 935 | register_reboot_notifier(&tts_notifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | return 0; |
| 937 | } |