[PATCH] W1: w1_netlink: New init/fini netlink callbacks.
[linux-2.6/verdex.git] / drivers / acpi / hardware / hwsleep.c
blob34519069050c2da488fa445759398220f3ecf897
2 /******************************************************************************
4 * Name: hwsleep.c - ACPI Hardware Sleep/Wake Interface
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2005, R. Byron Moore
10 * All rights reserved.
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.
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.
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.
45 #include <linux/module.h>
46 #include <acpi/acpi.h>
48 #define _COMPONENT ACPI_HARDWARE
49 ACPI_MODULE_NAME("hwsleep")
51 /*******************************************************************************
53 * FUNCTION: acpi_set_firmware_waking_vector
55 * PARAMETERS: physical_address - Physical address of ACPI real mode
56 * entry point.
58 * RETURN: Status
60 * DESCRIPTION: Access function for the firmware_waking_vector field in FACS
62 ******************************************************************************/
63 acpi_status
64 acpi_set_firmware_waking_vector(acpi_physical_address physical_address)
67 ACPI_FUNCTION_TRACE("acpi_set_firmware_waking_vector");
69 /* Set the vector */
71 if (acpi_gbl_common_fACS.vector_width == 32) {
72 *(ACPI_CAST_PTR
73 (u32, acpi_gbl_common_fACS.firmware_waking_vector))
74 = (u32) physical_address;
75 } else {
76 *acpi_gbl_common_fACS.firmware_waking_vector = physical_address;
79 return_ACPI_STATUS(AE_OK);
82 /*******************************************************************************
84 * FUNCTION: acpi_get_firmware_waking_vector
86 * PARAMETERS: *physical_address - Where the contents of
87 * the firmware_waking_vector field of
88 * the FACS will be returned.
90 * RETURN: Status, vector
92 * DESCRIPTION: Access function for the firmware_waking_vector field in FACS
94 ******************************************************************************/
96 #ifdef ACPI_FUTURE_USAGE
97 acpi_status
98 acpi_get_firmware_waking_vector(acpi_physical_address * physical_address)
101 ACPI_FUNCTION_TRACE("acpi_get_firmware_waking_vector");
103 if (!physical_address) {
104 return_ACPI_STATUS(AE_BAD_PARAMETER);
107 /* Get the vector */
109 if (acpi_gbl_common_fACS.vector_width == 32) {
110 *physical_address = (acpi_physical_address)
112 (ACPI_CAST_PTR
113 (u32, acpi_gbl_common_fACS.firmware_waking_vector));
114 } else {
115 *physical_address =
116 *acpi_gbl_common_fACS.firmware_waking_vector;
119 return_ACPI_STATUS(AE_OK);
121 #endif
123 /*******************************************************************************
125 * FUNCTION: acpi_enter_sleep_state_prep
127 * PARAMETERS: sleep_state - Which sleep state to enter
129 * RETURN: Status
131 * DESCRIPTION: Prepare to enter a system sleep state (see ACPI 2.0 spec p 231)
132 * This function must execute with interrupts enabled.
133 * We break sleeping into 2 stages so that OSPM can handle
134 * various OS-specific tasks between the two steps.
136 ******************************************************************************/
138 acpi_status acpi_enter_sleep_state_prep(u8 sleep_state)
140 acpi_status status;
141 struct acpi_object_list arg_list;
142 union acpi_object arg;
144 ACPI_FUNCTION_TRACE("acpi_enter_sleep_state_prep");
147 * _PSW methods could be run here to enable wake-on keyboard, LAN, etc.
149 status = acpi_get_sleep_type_data(sleep_state,
150 &acpi_gbl_sleep_type_a,
151 &acpi_gbl_sleep_type_b);
152 if (ACPI_FAILURE(status)) {
153 return_ACPI_STATUS(status);
156 /* Setup parameter object */
158 arg_list.count = 1;
159 arg_list.pointer = &arg;
161 arg.type = ACPI_TYPE_INTEGER;
162 arg.integer.value = sleep_state;
164 /* Run the _PTS and _GTS methods */
166 status = acpi_evaluate_object(NULL, METHOD_NAME__PTS, &arg_list, NULL);
167 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
168 return_ACPI_STATUS(status);
171 status = acpi_evaluate_object(NULL, METHOD_NAME__GTS, &arg_list, NULL);
172 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
173 return_ACPI_STATUS(status);
176 /* Setup the argument to _SST */
178 switch (sleep_state) {
179 case ACPI_STATE_S0:
180 arg.integer.value = ACPI_SST_WORKING;
181 break;
183 case ACPI_STATE_S1:
184 case ACPI_STATE_S2:
185 case ACPI_STATE_S3:
186 arg.integer.value = ACPI_SST_SLEEPING;
187 break;
189 case ACPI_STATE_S4:
190 arg.integer.value = ACPI_SST_SLEEP_CONTEXT;
191 break;
193 default:
194 arg.integer.value = ACPI_SST_INDICATOR_OFF; /* Default is off */
195 break;
198 /* Set the system indicators to show the desired sleep state. */
200 status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL);
201 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
202 ACPI_REPORT_ERROR(("Method _SST failed, %s\n",
203 acpi_format_exception(status)));
206 return_ACPI_STATUS(AE_OK);
209 /*******************************************************************************
211 * FUNCTION: acpi_enter_sleep_state
213 * PARAMETERS: sleep_state - Which sleep state to enter
215 * RETURN: Status
217 * DESCRIPTION: Enter a system sleep state (see ACPI 2.0 spec p 231)
218 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
220 ******************************************************************************/
222 acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
224 u32 PM1Acontrol;
225 u32 PM1Bcontrol;
226 struct acpi_bit_register_info *sleep_type_reg_info;
227 struct acpi_bit_register_info *sleep_enable_reg_info;
228 u32 in_value;
229 acpi_status status;
231 ACPI_FUNCTION_TRACE("acpi_enter_sleep_state");
233 if ((acpi_gbl_sleep_type_a > ACPI_SLEEP_TYPE_MAX) ||
234 (acpi_gbl_sleep_type_b > ACPI_SLEEP_TYPE_MAX)) {
235 ACPI_REPORT_ERROR(("Sleep values out of range: A=%X B=%X\n",
236 acpi_gbl_sleep_type_a,
237 acpi_gbl_sleep_type_b));
238 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
241 sleep_type_reg_info =
242 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE_A);
243 sleep_enable_reg_info =
244 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE);
246 /* Clear wake status */
248 status =
249 acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK);
250 if (ACPI_FAILURE(status)) {
251 return_ACPI_STATUS(status);
254 /* Clear all fixed and general purpose status bits */
256 status = acpi_hw_clear_acpi_status(ACPI_MTX_DO_NOT_LOCK);
257 if (ACPI_FAILURE(status)) {
258 return_ACPI_STATUS(status);
262 * 1) Disable/Clear all GPEs
263 * 2) Enable all wakeup GPEs
265 status = acpi_hw_disable_all_gpes();
266 if (ACPI_FAILURE(status)) {
267 return_ACPI_STATUS(status);
269 acpi_gbl_system_awake_and_running = FALSE;
271 status = acpi_hw_enable_all_wakeup_gpes();
272 if (ACPI_FAILURE(status)) {
273 return_ACPI_STATUS(status);
276 /* Get current value of PM1A control */
278 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
279 ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol);
280 if (ACPI_FAILURE(status)) {
281 return_ACPI_STATUS(status);
283 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
284 "Entering sleep state [S%d]\n", sleep_state));
286 /* Clear SLP_EN and SLP_TYP fields */
288 PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask |
289 sleep_enable_reg_info->access_bit_mask);
290 PM1Bcontrol = PM1Acontrol;
292 /* Insert SLP_TYP bits */
294 PM1Acontrol |=
295 (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position);
296 PM1Bcontrol |=
297 (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position);
300 * We split the writes of SLP_TYP and SLP_EN to workaround
301 * poorly implemented hardware.
304 /* Write #1: fill in SLP_TYP data */
306 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
307 ACPI_REGISTER_PM1A_CONTROL,
308 PM1Acontrol);
309 if (ACPI_FAILURE(status)) {
310 return_ACPI_STATUS(status);
313 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
314 ACPI_REGISTER_PM1B_CONTROL,
315 PM1Bcontrol);
316 if (ACPI_FAILURE(status)) {
317 return_ACPI_STATUS(status);
320 /* Insert SLP_ENABLE bit */
322 PM1Acontrol |= sleep_enable_reg_info->access_bit_mask;
323 PM1Bcontrol |= sleep_enable_reg_info->access_bit_mask;
325 /* Write #2: SLP_TYP + SLP_EN */
327 ACPI_FLUSH_CPU_CACHE();
329 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
330 ACPI_REGISTER_PM1A_CONTROL,
331 PM1Acontrol);
332 if (ACPI_FAILURE(status)) {
333 return_ACPI_STATUS(status);
336 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
337 ACPI_REGISTER_PM1B_CONTROL,
338 PM1Bcontrol);
339 if (ACPI_FAILURE(status)) {
340 return_ACPI_STATUS(status);
343 if (sleep_state > ACPI_STATE_S3) {
345 * We wanted to sleep > S3, but it didn't happen (by virtue of the
346 * fact that we are still executing!)
348 * Wait ten seconds, then try again. This is to get S4/S5 to work on
349 * all machines.
351 * We wait so long to allow chipsets that poll this reg very slowly to
352 * still read the right value. Ideally, this block would go
353 * away entirely.
355 acpi_os_stall(10000000);
357 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
358 ACPI_REGISTER_PM1_CONTROL,
359 sleep_enable_reg_info->
360 access_bit_mask);
361 if (ACPI_FAILURE(status)) {
362 return_ACPI_STATUS(status);
366 /* Wait until we enter sleep state */
368 do {
369 status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value,
370 ACPI_MTX_DO_NOT_LOCK);
371 if (ACPI_FAILURE(status)) {
372 return_ACPI_STATUS(status);
375 /* Spin until we wake */
377 } while (!in_value);
379 return_ACPI_STATUS(AE_OK);
382 EXPORT_SYMBOL(acpi_enter_sleep_state);
384 /*******************************************************************************
386 * FUNCTION: acpi_enter_sleep_state_s4bios
388 * PARAMETERS: None
390 * RETURN: Status
392 * DESCRIPTION: Perform a S4 bios request.
393 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
395 ******************************************************************************/
397 acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void)
399 u32 in_value;
400 acpi_status status;
402 ACPI_FUNCTION_TRACE("acpi_enter_sleep_state_s4bios");
404 status =
405 acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK);
406 if (ACPI_FAILURE(status)) {
407 return_ACPI_STATUS(status);
410 status = acpi_hw_clear_acpi_status(ACPI_MTX_DO_NOT_LOCK);
411 if (ACPI_FAILURE(status)) {
412 return_ACPI_STATUS(status);
416 * 1) Disable/Clear all GPEs
417 * 2) Enable all wakeup GPEs
419 status = acpi_hw_disable_all_gpes();
420 if (ACPI_FAILURE(status)) {
421 return_ACPI_STATUS(status);
423 acpi_gbl_system_awake_and_running = FALSE;
425 status = acpi_hw_enable_all_wakeup_gpes();
426 if (ACPI_FAILURE(status)) {
427 return_ACPI_STATUS(status);
430 ACPI_FLUSH_CPU_CACHE();
432 status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd,
433 (u32) acpi_gbl_FADT->S4bios_req, 8);
435 do {
436 acpi_os_stall(1000);
437 status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value,
438 ACPI_MTX_DO_NOT_LOCK);
439 if (ACPI_FAILURE(status)) {
440 return_ACPI_STATUS(status);
442 } while (!in_value);
444 return_ACPI_STATUS(AE_OK);
447 EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios);
449 /*******************************************************************************
451 * FUNCTION: acpi_leave_sleep_state
453 * PARAMETERS: sleep_state - Which sleep state we just exited
455 * RETURN: Status
457 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
458 * Called with interrupts ENABLED.
460 ******************************************************************************/
462 acpi_status acpi_leave_sleep_state(u8 sleep_state)
464 struct acpi_object_list arg_list;
465 union acpi_object arg;
466 acpi_status status;
467 struct acpi_bit_register_info *sleep_type_reg_info;
468 struct acpi_bit_register_info *sleep_enable_reg_info;
469 u32 PM1Acontrol;
470 u32 PM1Bcontrol;
472 ACPI_FUNCTION_TRACE("acpi_leave_sleep_state");
475 * Set SLP_TYPE and SLP_EN to state S0.
476 * This is unclear from the ACPI Spec, but it is required
477 * by some machines.
479 status = acpi_get_sleep_type_data(ACPI_STATE_S0,
480 &acpi_gbl_sleep_type_a,
481 &acpi_gbl_sleep_type_b);
482 if (ACPI_SUCCESS(status)) {
483 sleep_type_reg_info =
484 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE_A);
485 sleep_enable_reg_info =
486 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE);
488 /* Get current value of PM1A control */
490 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
491 ACPI_REGISTER_PM1_CONTROL,
492 &PM1Acontrol);
493 if (ACPI_SUCCESS(status)) {
494 /* Clear SLP_EN and SLP_TYP fields */
496 PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask |
497 sleep_enable_reg_info->
498 access_bit_mask);
499 PM1Bcontrol = PM1Acontrol;
501 /* Insert SLP_TYP bits */
503 PM1Acontrol |=
504 (acpi_gbl_sleep_type_a << sleep_type_reg_info->
505 bit_position);
506 PM1Bcontrol |=
507 (acpi_gbl_sleep_type_b << sleep_type_reg_info->
508 bit_position);
510 /* Just ignore any errors */
512 (void)acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
513 ACPI_REGISTER_PM1A_CONTROL,
514 PM1Acontrol);
515 (void)acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
516 ACPI_REGISTER_PM1B_CONTROL,
517 PM1Bcontrol);
521 /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
523 acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
525 /* Setup parameter object */
527 arg_list.count = 1;
528 arg_list.pointer = &arg;
529 arg.type = ACPI_TYPE_INTEGER;
531 /* Ignore any errors from these methods */
533 arg.integer.value = ACPI_SST_WAKING;
534 status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL);
535 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
536 ACPI_REPORT_ERROR(("Method _SST failed, %s\n",
537 acpi_format_exception(status)));
540 arg.integer.value = sleep_state;
541 status = acpi_evaluate_object(NULL, METHOD_NAME__BFS, &arg_list, NULL);
542 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
543 ACPI_REPORT_ERROR(("Method _BFS failed, %s\n",
544 acpi_format_exception(status)));
547 status = acpi_evaluate_object(NULL, METHOD_NAME__WAK, &arg_list, NULL);
548 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
549 ACPI_REPORT_ERROR(("Method _WAK failed, %s\n",
550 acpi_format_exception(status)));
552 /* TBD: _WAK "sometimes" returns stuff - do we want to look at it? */
555 * Restore the GPEs:
556 * 1) Disable/Clear all GPEs
557 * 2) Enable all runtime GPEs
559 status = acpi_hw_disable_all_gpes();
560 if (ACPI_FAILURE(status)) {
561 return_ACPI_STATUS(status);
563 acpi_gbl_system_awake_and_running = TRUE;
565 status = acpi_hw_enable_all_runtime_gpes();
566 if (ACPI_FAILURE(status)) {
567 return_ACPI_STATUS(status);
570 /* Enable power button */
572 (void)
573 acpi_set_register(acpi_gbl_fixed_event_info
574 [ACPI_EVENT_POWER_BUTTON].enable_register_id, 1,
575 ACPI_MTX_DO_NOT_LOCK);
577 (void)
578 acpi_set_register(acpi_gbl_fixed_event_info
579 [ACPI_EVENT_POWER_BUTTON].status_register_id, 1,
580 ACPI_MTX_DO_NOT_LOCK);
582 arg.integer.value = ACPI_SST_WORKING;
583 status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL);
584 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
585 ACPI_REPORT_ERROR(("Method _SST failed, %s\n",
586 acpi_format_exception(status)));
589 return_ACPI_STATUS(status);