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