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