Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
| 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Name: hwsleep.c - ACPI Hardware Sleep/Wake Interface |
| 5 | * |
| 6 | *****************************************************************************/ |
| 7 | |
| 8 | /* |
Len Brown | 75a44ce | 2008-04-23 23:00:13 -0400 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2008, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions, and the following disclaimer, |
| 17 | * without modification. |
| 18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 19 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 20 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 21 | * including a substantially similar Disclaimer requirement for further |
| 22 | * binary redistribution. |
| 23 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 24 | * of any contributors may be used to endorse or promote products derived |
| 25 | * from this software without specific prior written permission. |
| 26 | * |
| 27 | * Alternatively, this software may be distributed under the terms of the |
| 28 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 29 | * Software Foundation. |
| 30 | * |
| 31 | * NO WARRANTY |
| 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 42 | * POSSIBILITY OF SUCH DAMAGES. |
| 43 | */ |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> |
Bob Moore | 50df4d8 | 2008-12-31 03:01:23 +0800 | [diff] [blame] | 46 | #include <acpi/accommon.h> |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 47 | #include <acpi/actables.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define _COMPONENT ACPI_HARDWARE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("hwsleep") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | * |
| 54 | * FUNCTION: acpi_set_firmware_waking_vector |
| 55 | * |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 56 | * PARAMETERS: physical_address - 32-bit physical address of ACPI real mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | * entry point. |
| 58 | * |
| 59 | * RETURN: Status |
| 60 | * |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 61 | * DESCRIPTION: Sets the 32-bit firmware_waking_vector field of the FACS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * |
| 63 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | acpi_status |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 65 | acpi_set_firmware_waking_vector(u32 physical_address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 67 | ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 69 | |
Rafael J. Wysocki | a662910 | 2008-09-06 13:13:01 +0200 | [diff] [blame] | 70 | /* |
| 71 | * According to the ACPI specification 2.0c and later, the 64-bit |
| 72 | * waking vector should be cleared and the 32-bit waking vector should |
| 73 | * be used, unless we want the wake-up code to be called by the BIOS in |
| 74 | * Protected Mode. Some systems (for example HP dv5-1004nr) are known |
| 75 | * to fail to resume if the 64-bit vector is used. |
| 76 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 78 | /* Set the 32-bit vector */ |
| 79 | |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 80 | acpi_gbl_FACS->firmware_waking_vector = physical_address; |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 81 | |
| 82 | /* Clear the 64-bit vector if it exists */ |
| 83 | |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 84 | if ((acpi_gbl_FACS->length > 32) && (acpi_gbl_FACS->version >= 1)) { |
| 85 | acpi_gbl_FACS->xfirmware_waking_vector = 0; |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 86 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 88 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 91 | ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector) |
| 92 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 93 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | * |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 95 | * FUNCTION: acpi_set_firmware_waking_vector64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | * |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 97 | * PARAMETERS: physical_address - 64-bit physical address of ACPI protected |
| 98 | * mode entry point. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | * |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 100 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | * |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 102 | * DESCRIPTION: Sets the 64-bit X_firmware_waking_vector field of the FACS, if |
| 103 | * it exists in the table. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | * |
| 105 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | acpi_status |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 107 | acpi_set_firmware_waking_vector64(u64 physical_address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 109 | ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 112 | /* Determine if the 64-bit vector actually exists */ |
| 113 | |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 114 | if ((acpi_gbl_FACS->length <= 32) || (acpi_gbl_FACS->version < 1)) { |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 115 | return_ACPI_STATUS(AE_NOT_EXIST); |
| 116 | } |
| 117 | |
| 118 | /* Clear 32-bit vector, set the 64-bit X_ vector */ |
| 119 | |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 120 | acpi_gbl_FACS->firmware_waking_vector = 0; |
| 121 | acpi_gbl_FACS->xfirmware_waking_vector = physical_address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 123 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 125 | |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 126 | ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector64) |
| 127 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 128 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | * |
| 130 | * FUNCTION: acpi_enter_sleep_state_prep |
| 131 | * |
| 132 | * PARAMETERS: sleep_state - Which sleep state to enter |
| 133 | * |
| 134 | * RETURN: Status |
| 135 | * |
| 136 | * DESCRIPTION: Prepare to enter a system sleep state (see ACPI 2.0 spec p 231) |
| 137 | * This function must execute with interrupts enabled. |
| 138 | * We break sleeping into 2 stages so that OSPM can handle |
| 139 | * various OS-specific tasks between the two steps. |
| 140 | * |
| 141 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 142 | acpi_status acpi_enter_sleep_state_prep(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 144 | acpi_status status; |
| 145 | struct acpi_object_list arg_list; |
| 146 | union acpi_object arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 148 | ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_prep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | /* |
| 151 | * _PSW methods could be run here to enable wake-on keyboard, LAN, etc. |
| 152 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | status = acpi_get_sleep_type_data(sleep_state, |
| 154 | &acpi_gbl_sleep_type_a, |
| 155 | &acpi_gbl_sleep_type_b); |
| 156 | if (ACPI_FAILURE(status)) { |
| 157 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /* Setup parameter object */ |
| 161 | |
| 162 | arg_list.count = 1; |
| 163 | arg_list.pointer = &arg; |
| 164 | |
| 165 | arg.type = ACPI_TYPE_INTEGER; |
| 166 | arg.integer.value = sleep_state; |
| 167 | |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 168 | /* Run the _PTS method */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | status = acpi_evaluate_object(NULL, METHOD_NAME__PTS, &arg_list, NULL); |
| 171 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 172 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | /* Setup the argument to _SST */ |
| 176 | |
| 177 | switch (sleep_state) { |
| 178 | case ACPI_STATE_S0: |
| 179 | arg.integer.value = ACPI_SST_WORKING; |
| 180 | break; |
| 181 | |
| 182 | case ACPI_STATE_S1: |
| 183 | case ACPI_STATE_S2: |
| 184 | case ACPI_STATE_S3: |
| 185 | arg.integer.value = ACPI_SST_SLEEPING; |
| 186 | break; |
| 187 | |
| 188 | case ACPI_STATE_S4: |
| 189 | arg.integer.value = ACPI_SST_SLEEP_CONTEXT; |
| 190 | break; |
| 191 | |
| 192 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 193 | arg.integer.value = ACPI_SST_INDICATOR_OFF; /* Default is off */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | break; |
| 195 | } |
| 196 | |
Bob Moore | d52c79a | 2008-06-10 14:26:57 +0800 | [diff] [blame] | 197 | /* |
| 198 | * Set the system indicators to show the desired sleep state. |
| 199 | * _SST is an optional method (return no error if not found) |
| 200 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); |
| 202 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 203 | ACPI_EXCEPTION((AE_INFO, status, |
| 204 | "While executing method _SST")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Bob Moore | d52c79a | 2008-06-10 14:26:57 +0800 | [diff] [blame] | 207 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 210 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep) |
| 211 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 212 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | * |
| 214 | * FUNCTION: acpi_enter_sleep_state |
| 215 | * |
| 216 | * PARAMETERS: sleep_state - Which sleep state to enter |
| 217 | * |
| 218 | * RETURN: Status |
| 219 | * |
| 220 | * DESCRIPTION: Enter a system sleep state (see ACPI 2.0 spec p 231) |
| 221 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED |
| 222 | * |
| 223 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 224 | acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 226 | u32 PM1Acontrol; |
| 227 | u32 PM1Bcontrol; |
| 228 | struct acpi_bit_register_info *sleep_type_reg_info; |
| 229 | struct acpi_bit_register_info *sleep_enable_reg_info; |
| 230 | u32 in_value; |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 231 | struct acpi_object_list arg_list; |
| 232 | union acpi_object arg; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 233 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 235 | ACPI_FUNCTION_TRACE(acpi_enter_sleep_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | if ((acpi_gbl_sleep_type_a > ACPI_SLEEP_TYPE_MAX) || |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 238 | (acpi_gbl_sleep_type_b > ACPI_SLEEP_TYPE_MAX)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 239 | ACPI_ERROR((AE_INFO, "Sleep values out of range: A=%X B=%X", |
| 240 | acpi_gbl_sleep_type_a, acpi_gbl_sleep_type_b)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 241 | return_ACPI_STATUS(AE_AML_OPERAND_VALUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | sleep_type_reg_info = |
| 245 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE_A); |
| 246 | sleep_enable_reg_info = |
| 247 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | /* Clear wake status */ |
| 250 | |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 251 | status = acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 252 | if (ACPI_FAILURE(status)) { |
| 253 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /* Clear all fixed and general purpose status bits */ |
| 257 | |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 258 | status = acpi_hw_clear_acpi_status(); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | if (ACPI_FAILURE(status)) { |
| 260 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /* |
Pavel Machek | 23b168d | 2008-02-05 19:27:12 +0100 | [diff] [blame] | 264 | * 1) Disable/Clear all GPEs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | * 2) Enable all wakeup GPEs |
| 266 | */ |
Alexey Starikovskiy | 1d99967 | 2007-03-12 14:49:26 -0400 | [diff] [blame] | 267 | status = acpi_hw_disable_all_gpes(); |
| 268 | if (ACPI_FAILURE(status)) { |
| 269 | return_ACPI_STATUS(status); |
| 270 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | acpi_gbl_system_awake_and_running = FALSE; |
| 272 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 273 | status = acpi_hw_enable_all_wakeup_gpes(); |
| 274 | if (ACPI_FAILURE(status)) { |
| 275 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 278 | /* Execute the _GTS method */ |
| 279 | |
| 280 | arg_list.count = 1; |
| 281 | arg_list.pointer = &arg; |
| 282 | arg.type = ACPI_TYPE_INTEGER; |
| 283 | arg.integer.value = sleep_state; |
| 284 | |
| 285 | status = acpi_evaluate_object(NULL, METHOD_NAME__GTS, &arg_list, NULL); |
| 286 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 287 | return_ACPI_STATUS(status); |
| 288 | } |
| 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | /* Get current value of PM1A control */ |
| 291 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 292 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | if (ACPI_FAILURE(status)) { |
| 294 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 296 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
| 297 | "Entering sleep state [S%d]\n", sleep_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | /* Clear SLP_EN and SLP_TYP fields */ |
| 300 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 301 | PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 302 | sleep_enable_reg_info->access_bit_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | PM1Bcontrol = PM1Acontrol; |
| 304 | |
| 305 | /* Insert SLP_TYP bits */ |
| 306 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 307 | PM1Acontrol |= |
| 308 | (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position); |
| 309 | PM1Bcontrol |= |
| 310 | (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | /* |
| 313 | * We split the writes of SLP_TYP and SLP_EN to workaround |
| 314 | * poorly implemented hardware. |
| 315 | */ |
| 316 | |
| 317 | /* Write #1: fill in SLP_TYP data */ |
| 318 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 319 | status = acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 320 | PM1Acontrol); |
| 321 | if (ACPI_FAILURE(status)) { |
| 322 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 325 | status = acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 326 | PM1Bcontrol); |
| 327 | if (ACPI_FAILURE(status)) { |
| 328 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | /* Insert SLP_ENABLE bit */ |
| 332 | |
| 333 | PM1Acontrol |= sleep_enable_reg_info->access_bit_mask; |
| 334 | PM1Bcontrol |= sleep_enable_reg_info->access_bit_mask; |
| 335 | |
| 336 | /* Write #2: SLP_TYP + SLP_EN */ |
| 337 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 338 | ACPI_FLUSH_CPU_CACHE(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 340 | status = acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 341 | PM1Acontrol); |
| 342 | if (ACPI_FAILURE(status)) { |
| 343 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 346 | status = acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 347 | PM1Bcontrol); |
| 348 | if (ACPI_FAILURE(status)) { |
| 349 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | if (sleep_state > ACPI_STATE_S3) { |
| 353 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 354 | * We wanted to sleep > S3, but it didn't happen (by virtue of the |
| 355 | * fact that we are still executing!) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 357 | * Wait ten seconds, then try again. This is to get S4/S5 to work on |
| 358 | * all machines. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | * |
| 360 | * We wait so long to allow chipsets that poll this reg very slowly to |
| 361 | * still read the right value. Ideally, this block would go |
| 362 | * away entirely. |
| 363 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 364 | acpi_os_stall(10000000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 366 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 367 | sleep_enable_reg_info-> |
| 368 | access_bit_mask); |
| 369 | if (ACPI_FAILURE(status)) { |
| 370 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
| 374 | /* Wait until we enter sleep state */ |
| 375 | |
| 376 | do { |
Alexey Starikovskiy | 2d571b3 | 2007-09-30 22:39:42 +0400 | [diff] [blame] | 377 | status = acpi_get_register_unlocked(ACPI_BITREG_WAKE_STATUS, |
| 378 | &in_value); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 379 | if (ACPI_FAILURE(status)) { |
| 380 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /* Spin until we wake */ |
| 384 | |
| 385 | } while (!in_value); |
| 386 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 387 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 390 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 392 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | * |
| 394 | * FUNCTION: acpi_enter_sleep_state_s4bios |
| 395 | * |
| 396 | * PARAMETERS: None |
| 397 | * |
| 398 | * RETURN: Status |
| 399 | * |
| 400 | * DESCRIPTION: Perform a S4 bios request. |
| 401 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED |
| 402 | * |
| 403 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 404 | acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | u32 in_value; |
| 407 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 409 | ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_s4bios); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 411 | status = acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 412 | if (ACPI_FAILURE(status)) { |
| 413 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 416 | status = acpi_hw_clear_acpi_status(); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 417 | if (ACPI_FAILURE(status)) { |
| 418 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | /* |
| 422 | * 1) Disable/Clear all GPEs |
| 423 | * 2) Enable all wakeup GPEs |
| 424 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 425 | status = acpi_hw_disable_all_gpes(); |
| 426 | if (ACPI_FAILURE(status)) { |
| 427 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
| 429 | acpi_gbl_system_awake_and_running = FALSE; |
| 430 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 431 | status = acpi_hw_enable_all_wakeup_gpes(); |
| 432 | if (ACPI_FAILURE(status)) { |
| 433 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 436 | ACPI_FLUSH_CPU_CACHE(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 438 | status = acpi_os_write_port(acpi_gbl_FADT.smi_command, |
| 439 | (u32) acpi_gbl_FADT.S4bios_request, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | do { |
| 442 | acpi_os_stall(1000); |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 443 | status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 444 | if (ACPI_FAILURE(status)) { |
| 445 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | } while (!in_value); |
| 448 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 449 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 452 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 454 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | * |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 456 | * FUNCTION: acpi_leave_sleep_state_prep |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | * |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 458 | * PARAMETERS: sleep_state - Which sleep state we are exiting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | * |
| 460 | * RETURN: Status |
| 461 | * |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 462 | * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a |
| 463 | * sleep. |
| 464 | * Called with interrupts DISABLED. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | * |
| 466 | ******************************************************************************/ |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 467 | acpi_status acpi_leave_sleep_state_prep(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 469 | struct acpi_object_list arg_list; |
| 470 | union acpi_object arg; |
| 471 | acpi_status status; |
| 472 | struct acpi_bit_register_info *sleep_type_reg_info; |
| 473 | struct acpi_bit_register_info *sleep_enable_reg_info; |
| 474 | u32 PM1Acontrol; |
| 475 | u32 PM1Bcontrol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 477 | ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
| 479 | /* |
| 480 | * Set SLP_TYPE and SLP_EN to state S0. |
| 481 | * This is unclear from the ACPI Spec, but it is required |
| 482 | * by some machines. |
| 483 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 484 | status = acpi_get_sleep_type_data(ACPI_STATE_S0, |
| 485 | &acpi_gbl_sleep_type_a, |
| 486 | &acpi_gbl_sleep_type_b); |
| 487 | if (ACPI_SUCCESS(status)) { |
| 488 | sleep_type_reg_info = |
| 489 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE_A); |
| 490 | sleep_enable_reg_info = |
| 491 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | /* Get current value of PM1A control */ |
| 494 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 495 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 496 | &PM1Acontrol); |
| 497 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | /* Clear SLP_EN and SLP_TYP fields */ |
| 500 | |
| 501 | PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 502 | sleep_enable_reg_info-> |
| 503 | access_bit_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | PM1Bcontrol = PM1Acontrol; |
| 505 | |
| 506 | /* Insert SLP_TYP bits */ |
| 507 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 508 | PM1Acontrol |= |
| 509 | (acpi_gbl_sleep_type_a << sleep_type_reg_info-> |
| 510 | bit_position); |
| 511 | PM1Bcontrol |= |
| 512 | (acpi_gbl_sleep_type_b << sleep_type_reg_info-> |
| 513 | bit_position); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | /* Just ignore any errors */ |
| 516 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 517 | (void)acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 518 | PM1Acontrol); |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 519 | (void)acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 520 | PM1Bcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 524 | /* Execute the _BFS method */ |
| 525 | |
| 526 | arg_list.count = 1; |
| 527 | arg_list.pointer = &arg; |
| 528 | arg.type = ACPI_TYPE_INTEGER; |
| 529 | arg.integer.value = sleep_state; |
| 530 | |
| 531 | status = acpi_evaluate_object(NULL, METHOD_NAME__BFS, &arg_list, NULL); |
| 532 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 533 | ACPI_EXCEPTION((AE_INFO, status, "During Method _BFS")); |
| 534 | } |
| 535 | |
| 536 | return_ACPI_STATUS(status); |
| 537 | } |
| 538 | |
| 539 | /******************************************************************************* |
| 540 | * |
| 541 | * FUNCTION: acpi_leave_sleep_state |
| 542 | * |
| 543 | * PARAMETERS: sleep_state - Which sleep state we just exited |
| 544 | * |
| 545 | * RETURN: Status |
| 546 | * |
| 547 | * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep |
| 548 | * Called with interrupts ENABLED. |
| 549 | * |
| 550 | ******************************************************************************/ |
| 551 | acpi_status acpi_leave_sleep_state(u8 sleep_state) |
| 552 | { |
| 553 | struct acpi_object_list arg_list; |
| 554 | union acpi_object arg; |
| 555 | acpi_status status; |
| 556 | |
| 557 | ACPI_FUNCTION_TRACE(acpi_leave_sleep_state); |
| 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */ |
| 560 | |
| 561 | acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID; |
| 562 | |
| 563 | /* Setup parameter object */ |
| 564 | |
| 565 | arg_list.count = 1; |
| 566 | arg_list.pointer = &arg; |
| 567 | arg.type = ACPI_TYPE_INTEGER; |
| 568 | |
| 569 | /* Ignore any errors from these methods */ |
| 570 | |
| 571 | arg.integer.value = ACPI_SST_WAKING; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 572 | status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); |
| 573 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 574 | ACPI_EXCEPTION((AE_INFO, status, "During Method _SST")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | /* |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 578 | * GPEs must be enabled before _WAK is called as GPEs |
| 579 | * might get fired there |
| 580 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | * Restore the GPEs: |
| 582 | * 1) Disable/Clear all GPEs |
| 583 | * 2) Enable all runtime GPEs |
| 584 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 585 | status = acpi_hw_disable_all_gpes(); |
| 586 | if (ACPI_FAILURE(status)) { |
| 587 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 589 | status = acpi_hw_enable_all_runtime_gpes(); |
| 590 | if (ACPI_FAILURE(status)) { |
| 591 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Rafael J. Wysocki | 314ccd6 | 2008-02-13 00:32:16 +0100 | [diff] [blame] | 594 | arg.integer.value = sleep_state; |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 595 | status = acpi_evaluate_object(NULL, METHOD_NAME__WAK, &arg_list, NULL); |
| 596 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 597 | ACPI_EXCEPTION((AE_INFO, status, "During Method _WAK")); |
| 598 | } |
| 599 | /* TBD: _WAK "sometimes" returns stuff - do we want to look at it? */ |
| 600 | |
Matthew Garrett | a68823e | 2008-08-06 19:12:04 +0100 | [diff] [blame] | 601 | /* |
| 602 | * Some BIOSes assume that WAK_STS will be cleared on resume and use |
| 603 | * it to determine whether the system is rebooting or resuming. Clear |
| 604 | * it for compatibility. |
| 605 | */ |
| 606 | acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1); |
| 607 | |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 608 | acpi_gbl_system_awake_and_running = TRUE; |
| 609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | /* Enable power button */ |
| 611 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 612 | (void) |
| 613 | acpi_set_register(acpi_gbl_fixed_event_info |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 614 | [ACPI_EVENT_POWER_BUTTON].enable_register_id, 1); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 615 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 616 | (void) |
| 617 | acpi_set_register(acpi_gbl_fixed_event_info |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 618 | [ACPI_EVENT_POWER_BUTTON].status_register_id, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
| 620 | arg.integer.value = ACPI_SST_WORKING; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 621 | status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); |
| 622 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 623 | ACPI_EXCEPTION((AE_INFO, status, "During Method _SST")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 626 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 628 | |
| 629 | ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state) |