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