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