Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | |
2 | /****************************************************************************** | |
3 | * | |
4 | * Name: hwsleep.c - ACPI Hardware Sleep/Wake Interface | |
5 | * | |
6 | *****************************************************************************/ | |
7 | ||
8 | /* | |
75a44ce0 | 9 | * Copyright (C) 2000 - 2008, Intel Corp. |
1da177e4 LT |
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 | ||
1da177e4 | 45 | #include <acpi/acpi.h> |
f3d2e786 | 46 | #include <acpi/actables.h> |
1da177e4 LT |
47 | |
48 | #define _COMPONENT ACPI_HARDWARE | |
4be44fcd | 49 | ACPI_MODULE_NAME("hwsleep") |
1da177e4 | 50 | |
44f6c012 | 51 | /******************************************************************************* |
1da177e4 LT |
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 | * | |
44f6c012 | 60 | * DESCRIPTION: Access function for the firmware_waking_vector field in FACS |
1da177e4 LT |
61 | * |
62 | ******************************************************************************/ | |
1da177e4 | 63 | acpi_status |
4be44fcd | 64 | acpi_set_firmware_waking_vector(acpi_physical_address physical_address) |
1da177e4 | 65 | { |
f3d2e786 BM |
66 | struct acpi_table_facs *facs; |
67 | acpi_status status; | |
1da177e4 | 68 | |
b229cf92 | 69 | ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector); |
1da177e4 | 70 | |
f3d2e786 BM |
71 | /* Get the FACS */ |
72 | ||
1d18c058 BM |
73 | status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS, |
74 | ACPI_CAST_INDIRECT_PTR(struct | |
75 | acpi_table_header, | |
76 | &facs)); | |
f3d2e786 BM |
77 | if (ACPI_FAILURE(status)) { |
78 | return_ACPI_STATUS(status); | |
79 | } | |
80 | ||
a6629105 RW |
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; | |
90 | ||
91 | facs->firmware_waking_vector = (u32)physical_address; | |
1da177e4 | 92 | |
4be44fcd | 93 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
94 | } |
95 | ||
8313524a BM |
96 | ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector) |
97 | ||
44f6c012 | 98 | /******************************************************************************* |
1da177e4 LT |
99 | * |
100 | * FUNCTION: acpi_get_firmware_waking_vector | |
101 | * | |
44f6c012 | 102 | * PARAMETERS: *physical_address - Where the contents of |
1da177e4 | 103 | * the firmware_waking_vector field of |
44f6c012 | 104 | * the FACS will be returned. |
1da177e4 | 105 | * |
44f6c012 | 106 | * RETURN: Status, vector |
1da177e4 | 107 | * |
44f6c012 | 108 | * DESCRIPTION: Access function for the firmware_waking_vector field in FACS |
1da177e4 LT |
109 | * |
110 | ******************************************************************************/ | |
111 | #ifdef ACPI_FUTURE_USAGE | |
112 | acpi_status | |
4be44fcd | 113 | acpi_get_firmware_waking_vector(acpi_physical_address * physical_address) |
1da177e4 | 114 | { |
f3d2e786 BM |
115 | struct acpi_table_facs *facs; |
116 | acpi_status status; | |
1da177e4 | 117 | |
b229cf92 | 118 | ACPI_FUNCTION_TRACE(acpi_get_firmware_waking_vector); |
1da177e4 LT |
119 | |
120 | if (!physical_address) { | |
4be44fcd | 121 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
122 | } |
123 | ||
f3d2e786 BM |
124 | /* Get the FACS */ |
125 | ||
1d18c058 BM |
126 | status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS, |
127 | ACPI_CAST_INDIRECT_PTR(struct | |
128 | acpi_table_header, | |
129 | &facs)); | |
f3d2e786 BM |
130 | if (ACPI_FAILURE(status)) { |
131 | return_ACPI_STATUS(status); | |
132 | } | |
133 | ||
1da177e4 | 134 | /* Get the vector */ |
a6629105 | 135 | *physical_address = (acpi_physical_address)facs->firmware_waking_vector; |
1da177e4 | 136 | |
4be44fcd | 137 | return_ACPI_STATUS(AE_OK); |
1da177e4 | 138 | } |
8313524a BM |
139 | |
140 | ACPI_EXPORT_SYMBOL(acpi_get_firmware_waking_vector) | |
1da177e4 | 141 | #endif |
44f6c012 | 142 | /******************************************************************************* |
1da177e4 LT |
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 | ******************************************************************************/ | |
4be44fcd | 156 | acpi_status acpi_enter_sleep_state_prep(u8 sleep_state) |
1da177e4 | 157 | { |
4be44fcd LB |
158 | acpi_status status; |
159 | struct acpi_object_list arg_list; | |
160 | union acpi_object arg; | |
1da177e4 | 161 | |
b229cf92 | 162 | ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_prep); |
1da177e4 LT |
163 | |
164 | /* | |
165 | * _PSW methods could be run here to enable wake-on keyboard, LAN, etc. | |
166 | */ | |
4be44fcd LB |
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); | |
1da177e4 LT |
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 | ||
c95d47a8 | 182 | /* Run the _PTS method */ |
1da177e4 | 183 | |
4be44fcd LB |
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); | |
1da177e4 LT |
187 | } |
188 | ||
1da177e4 LT |
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: | |
4be44fcd | 207 | arg.integer.value = ACPI_SST_INDICATOR_OFF; /* Default is off */ |
1da177e4 LT |
208 | break; |
209 | } | |
210 | ||
d52c79ac BM |
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 | */ | |
4be44fcd LB |
215 | status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); |
216 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { | |
b8e4d893 BM |
217 | ACPI_EXCEPTION((AE_INFO, status, |
218 | "While executing method _SST")); | |
1da177e4 LT |
219 | } |
220 | ||
d52c79ac | 221 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
222 | } |
223 | ||
8313524a BM |
224 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep) |
225 | ||
44f6c012 | 226 | /******************************************************************************* |
1da177e4 LT |
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 | ******************************************************************************/ | |
4be44fcd | 238 | acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state) |
1da177e4 | 239 | { |
4be44fcd LB |
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; | |
c95d47a8 RW |
245 | struct acpi_object_list arg_list; |
246 | union acpi_object arg; | |
4be44fcd | 247 | acpi_status status; |
1da177e4 | 248 | |
b229cf92 | 249 | ACPI_FUNCTION_TRACE(acpi_enter_sleep_state); |
1da177e4 LT |
250 | |
251 | if ((acpi_gbl_sleep_type_a > ACPI_SLEEP_TYPE_MAX) || | |
4be44fcd | 252 | (acpi_gbl_sleep_type_b > ACPI_SLEEP_TYPE_MAX)) { |
b8e4d893 BM |
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)); | |
4be44fcd | 255 | return_ACPI_STATUS(AE_AML_OPERAND_VALUE); |
1da177e4 LT |
256 | } |
257 | ||
4be44fcd LB |
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); | |
1da177e4 LT |
262 | |
263 | /* Clear wake status */ | |
264 | ||
d8c71b6d | 265 | status = acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1); |
4be44fcd LB |
266 | if (ACPI_FAILURE(status)) { |
267 | return_ACPI_STATUS(status); | |
1da177e4 LT |
268 | } |
269 | ||
270 | /* Clear all fixed and general purpose status bits */ | |
271 | ||
d8c71b6d | 272 | status = acpi_hw_clear_acpi_status(); |
4be44fcd LB |
273 | if (ACPI_FAILURE(status)) { |
274 | return_ACPI_STATUS(status); | |
1da177e4 LT |
275 | } |
276 | ||
277 | /* | |
23b168d4 | 278 | * 1) Disable/Clear all GPEs |
1da177e4 LT |
279 | * 2) Enable all wakeup GPEs |
280 | */ | |
1d99967b AS |
281 | status = acpi_hw_disable_all_gpes(); |
282 | if (ACPI_FAILURE(status)) { | |
283 | return_ACPI_STATUS(status); | |
284 | } | |
1da177e4 LT |
285 | acpi_gbl_system_awake_and_running = FALSE; |
286 | ||
4be44fcd LB |
287 | status = acpi_hw_enable_all_wakeup_gpes(); |
288 | if (ACPI_FAILURE(status)) { | |
289 | return_ACPI_STATUS(status); | |
1da177e4 LT |
290 | } |
291 | ||
c95d47a8 RW |
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 | ||
1da177e4 LT |
304 | /* Get current value of PM1A control */ |
305 | ||
d30dc9ab | 306 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol); |
4be44fcd LB |
307 | if (ACPI_FAILURE(status)) { |
308 | return_ACPI_STATUS(status); | |
1da177e4 | 309 | } |
4be44fcd LB |
310 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
311 | "Entering sleep state [S%d]\n", sleep_state)); | |
1da177e4 LT |
312 | |
313 | /* Clear SLP_EN and SLP_TYP fields */ | |
314 | ||
44f6c012 | 315 | PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask | |
4be44fcd | 316 | sleep_enable_reg_info->access_bit_mask); |
1da177e4 LT |
317 | PM1Bcontrol = PM1Acontrol; |
318 | ||
319 | /* Insert SLP_TYP bits */ | |
320 | ||
4be44fcd LB |
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); | |
1da177e4 LT |
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 | ||
d30dc9ab | 333 | status = acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, |
4be44fcd LB |
334 | PM1Acontrol); |
335 | if (ACPI_FAILURE(status)) { | |
336 | return_ACPI_STATUS(status); | |
1da177e4 LT |
337 | } |
338 | ||
d30dc9ab | 339 | status = acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL, |
4be44fcd LB |
340 | PM1Bcontrol); |
341 | if (ACPI_FAILURE(status)) { | |
342 | return_ACPI_STATUS(status); | |
1da177e4 LT |
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 | ||
4be44fcd | 352 | ACPI_FLUSH_CPU_CACHE(); |
1da177e4 | 353 | |
d30dc9ab | 354 | status = acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, |
4be44fcd LB |
355 | PM1Acontrol); |
356 | if (ACPI_FAILURE(status)) { | |
357 | return_ACPI_STATUS(status); | |
1da177e4 LT |
358 | } |
359 | ||
d30dc9ab | 360 | status = acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL, |
4be44fcd LB |
361 | PM1Bcontrol); |
362 | if (ACPI_FAILURE(status)) { | |
363 | return_ACPI_STATUS(status); | |
1da177e4 LT |
364 | } |
365 | ||
366 | if (sleep_state > ACPI_STATE_S3) { | |
367 | /* | |
44f6c012 RM |
368 | * We wanted to sleep > S3, but it didn't happen (by virtue of the |
369 | * fact that we are still executing!) | |
1da177e4 | 370 | * |
44f6c012 RM |
371 | * Wait ten seconds, then try again. This is to get S4/S5 to work on |
372 | * all machines. | |
1da177e4 LT |
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 | */ | |
4be44fcd LB |
378 | acpi_os_stall(10000000); |
379 | ||
d30dc9ab | 380 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL, |
4be44fcd LB |
381 | sleep_enable_reg_info-> |
382 | access_bit_mask); | |
383 | if (ACPI_FAILURE(status)) { | |
384 | return_ACPI_STATUS(status); | |
1da177e4 LT |
385 | } |
386 | } | |
387 | ||
388 | /* Wait until we enter sleep state */ | |
389 | ||
390 | do { | |
2d571b33 AS |
391 | status = acpi_get_register_unlocked(ACPI_BITREG_WAKE_STATUS, |
392 | &in_value); | |
4be44fcd LB |
393 | if (ACPI_FAILURE(status)) { |
394 | return_ACPI_STATUS(status); | |
1da177e4 LT |
395 | } |
396 | ||
397 | /* Spin until we wake */ | |
398 | ||
399 | } while (!in_value); | |
400 | ||
4be44fcd | 401 | return_ACPI_STATUS(AE_OK); |
1da177e4 | 402 | } |
1da177e4 | 403 | |
8313524a | 404 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state) |
1da177e4 | 405 | |
44f6c012 | 406 | /******************************************************************************* |
1da177e4 LT |
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 | ******************************************************************************/ | |
4be44fcd | 418 | acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void) |
1da177e4 | 419 | { |
4be44fcd LB |
420 | u32 in_value; |
421 | acpi_status status; | |
1da177e4 | 422 | |
b229cf92 | 423 | ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_s4bios); |
1da177e4 | 424 | |
d8c71b6d | 425 | status = acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1); |
4be44fcd LB |
426 | if (ACPI_FAILURE(status)) { |
427 | return_ACPI_STATUS(status); | |
1da177e4 LT |
428 | } |
429 | ||
d8c71b6d | 430 | status = acpi_hw_clear_acpi_status(); |
4be44fcd LB |
431 | if (ACPI_FAILURE(status)) { |
432 | return_ACPI_STATUS(status); | |
1da177e4 LT |
433 | } |
434 | ||
435 | /* | |
436 | * 1) Disable/Clear all GPEs | |
437 | * 2) Enable all wakeup GPEs | |
438 | */ | |
4be44fcd LB |
439 | status = acpi_hw_disable_all_gpes(); |
440 | if (ACPI_FAILURE(status)) { | |
441 | return_ACPI_STATUS(status); | |
1da177e4 LT |
442 | } |
443 | acpi_gbl_system_awake_and_running = FALSE; | |
444 | ||
4be44fcd LB |
445 | status = acpi_hw_enable_all_wakeup_gpes(); |
446 | if (ACPI_FAILURE(status)) { | |
447 | return_ACPI_STATUS(status); | |
1da177e4 LT |
448 | } |
449 | ||
4be44fcd | 450 | ACPI_FLUSH_CPU_CACHE(); |
1da177e4 | 451 | |
f3d2e786 BM |
452 | status = acpi_os_write_port(acpi_gbl_FADT.smi_command, |
453 | (u32) acpi_gbl_FADT.S4bios_request, 8); | |
1da177e4 LT |
454 | |
455 | do { | |
456 | acpi_os_stall(1000); | |
d8c71b6d | 457 | status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value); |
4be44fcd LB |
458 | if (ACPI_FAILURE(status)) { |
459 | return_ACPI_STATUS(status); | |
1da177e4 LT |
460 | } |
461 | } while (!in_value); | |
462 | ||
4be44fcd | 463 | return_ACPI_STATUS(AE_OK); |
1da177e4 | 464 | } |
1da177e4 | 465 | |
8313524a | 466 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios) |
1da177e4 | 467 | |
44f6c012 | 468 | /******************************************************************************* |
1da177e4 | 469 | * |
c95d47a8 | 470 | * FUNCTION: acpi_leave_sleep_state_prep |
1da177e4 | 471 | * |
c95d47a8 | 472 | * PARAMETERS: sleep_state - Which sleep state we are exiting |
1da177e4 LT |
473 | * |
474 | * RETURN: Status | |
475 | * | |
c95d47a8 RW |
476 | * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a |
477 | * sleep. | |
478 | * Called with interrupts DISABLED. | |
1da177e4 LT |
479 | * |
480 | ******************************************************************************/ | |
c95d47a8 | 481 | acpi_status acpi_leave_sleep_state_prep(u8 sleep_state) |
1da177e4 | 482 | { |
4be44fcd LB |
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; | |
1da177e4 | 490 | |
c95d47a8 | 491 | ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep); |
1da177e4 LT |
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 | */ | |
4be44fcd LB |
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); | |
1da177e4 LT |
506 | |
507 | /* Get current value of PM1A control */ | |
508 | ||
d30dc9ab | 509 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, |
4be44fcd LB |
510 | &PM1Acontrol); |
511 | if (ACPI_SUCCESS(status)) { | |
52fc0b02 | 512 | |
1da177e4 LT |
513 | /* Clear SLP_EN and SLP_TYP fields */ |
514 | ||
515 | PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask | | |
4be44fcd LB |
516 | sleep_enable_reg_info-> |
517 | access_bit_mask); | |
1da177e4 LT |
518 | PM1Bcontrol = PM1Acontrol; |
519 | ||
520 | /* Insert SLP_TYP bits */ | |
521 | ||
4be44fcd LB |
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); | |
1da177e4 LT |
528 | |
529 | /* Just ignore any errors */ | |
530 | ||
d30dc9ab | 531 | (void)acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, |
4be44fcd | 532 | PM1Acontrol); |
d30dc9ab | 533 | (void)acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL, |
4be44fcd | 534 | PM1Bcontrol); |
1da177e4 LT |
535 | } |
536 | } | |
537 | ||
c95d47a8 RW |
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 | ||
1da177e4 LT |
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; | |
4be44fcd LB |
586 | status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); |
587 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { | |
b8e4d893 | 588 | ACPI_EXCEPTION((AE_INFO, status, "During Method _SST")); |
1da177e4 LT |
589 | } |
590 | ||
1da177e4 | 591 | /* |
79d2dfaa TR |
592 | * GPEs must be enabled before _WAK is called as GPEs |
593 | * might get fired there | |
594 | * | |
1da177e4 LT |
595 | * Restore the GPEs: |
596 | * 1) Disable/Clear all GPEs | |
597 | * 2) Enable all runtime GPEs | |
598 | */ | |
4be44fcd LB |
599 | status = acpi_hw_disable_all_gpes(); |
600 | if (ACPI_FAILURE(status)) { | |
601 | return_ACPI_STATUS(status); | |
1da177e4 | 602 | } |
4be44fcd LB |
603 | status = acpi_hw_enable_all_runtime_gpes(); |
604 | if (ACPI_FAILURE(status)) { | |
605 | return_ACPI_STATUS(status); | |
1da177e4 LT |
606 | } |
607 | ||
314ccd64 | 608 | arg.integer.value = sleep_state; |
79d2dfaa TR |
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 | ||
a68823ee MG |
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 | ||
79d2dfaa TR |
622 | acpi_gbl_system_awake_and_running = TRUE; |
623 | ||
1da177e4 LT |
624 | /* Enable power button */ |
625 | ||
4be44fcd LB |
626 | (void) |
627 | acpi_set_register(acpi_gbl_fixed_event_info | |
d8c71b6d | 628 | [ACPI_EVENT_POWER_BUTTON].enable_register_id, 1); |
44f6c012 | 629 | |
4be44fcd LB |
630 | (void) |
631 | acpi_set_register(acpi_gbl_fixed_event_info | |
d8c71b6d | 632 | [ACPI_EVENT_POWER_BUTTON].status_register_id, 1); |
1da177e4 LT |
633 | |
634 | arg.integer.value = ACPI_SST_WORKING; | |
4be44fcd LB |
635 | status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); |
636 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { | |
b8e4d893 | 637 | ACPI_EXCEPTION((AE_INFO, status, "During Method _SST")); |
1da177e4 LT |
638 | } |
639 | ||
4be44fcd | 640 | return_ACPI_STATUS(status); |
1da177e4 | 641 | } |
8313524a BM |
642 | |
643 | ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state) |