1 /******************************************************************************
3 * Name: hwsleep.c - ACPI Hardware Sleep/Wake Support functions for the
4 * original/legacy sleep/PM registers.
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2012, Intel Corp.
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
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.
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 <acpi/acpi.h>
46 #include <linux/acpi.h>
48 #include <linux/module.h>
50 #define _COMPONENT ACPI_HARDWARE
51 ACPI_MODULE_NAME("hwsleep")
53 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
54 /*******************************************************************************
56 * FUNCTION: acpi_hw_legacy_sleep
58 * PARAMETERS: sleep_state - Which sleep state to enter
59 * flags - ACPI_EXECUTE_GTS to run optional method
63 * DESCRIPTION: Enter a system sleep state via the legacy FADT PM registers
64 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
66 ******************************************************************************/
67 acpi_status
acpi_hw_legacy_sleep(u8 sleep_state
, u8 flags
)
69 struct acpi_bit_register_info
*sleep_type_reg_info
;
70 struct acpi_bit_register_info
*sleep_enable_reg_info
;
76 ACPI_FUNCTION_TRACE(hw_legacy_sleep
);
79 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE
);
80 sleep_enable_reg_info
=
81 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE
);
83 /* Clear wake status */
86 acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS
, ACPI_CLEAR_STATUS
);
87 if (ACPI_FAILURE(status
)) {
88 return_ACPI_STATUS(status
);
91 /* Clear all fixed and general purpose status bits */
93 status
= acpi_hw_clear_acpi_status();
94 if (ACPI_FAILURE(status
)) {
95 return_ACPI_STATUS(status
);
98 if (sleep_state
!= ACPI_STATE_S5
) {
100 * Disable BM arbitration. This feature is contained within an
101 * optional register (PM2 Control), so ignore a BAD_ADDRESS
104 status
= acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE
, 1);
105 if (ACPI_FAILURE(status
) && (status
!= AE_BAD_ADDRESS
)) {
106 return_ACPI_STATUS(status
);
111 * 1) Disable/Clear all GPEs
112 * 2) Enable all wakeup GPEs
114 status
= acpi_hw_disable_all_gpes();
115 if (ACPI_FAILURE(status
)) {
116 return_ACPI_STATUS(status
);
118 acpi_gbl_system_awake_and_running
= FALSE
;
120 status
= acpi_hw_enable_all_wakeup_gpes();
121 if (ACPI_FAILURE(status
)) {
122 return_ACPI_STATUS(status
);
125 /* Optionally execute _GTS (Going To Sleep) */
127 if (flags
& ACPI_EXECUTE_GTS
) {
128 acpi_hw_execute_sleep_method(METHOD_PATHNAME__GTS
, sleep_state
);
131 /* Get current value of PM1A control */
133 status
= acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL
,
135 if (ACPI_FAILURE(status
)) {
136 return_ACPI_STATUS(status
);
138 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
139 "Entering sleep state [S%u]\n", sleep_state
));
141 /* Clear the SLP_EN and SLP_TYP fields */
143 pm1a_control
&= ~(sleep_type_reg_info
->access_bit_mask
|
144 sleep_enable_reg_info
->access_bit_mask
);
145 pm1b_control
= pm1a_control
;
147 /* Insert the SLP_TYP bits */
150 (acpi_gbl_sleep_type_a
<< sleep_type_reg_info
->bit_position
);
152 (acpi_gbl_sleep_type_b
<< sleep_type_reg_info
->bit_position
);
155 * We split the writes of SLP_TYP and SLP_EN to workaround
156 * poorly implemented hardware.
159 /* Write #1: write the SLP_TYP data to the PM1 Control registers */
161 status
= acpi_hw_write_pm1_control(pm1a_control
, pm1b_control
);
162 if (ACPI_FAILURE(status
)) {
163 return_ACPI_STATUS(status
);
166 /* Insert the sleep enable (SLP_EN) bit */
168 pm1a_control
|= sleep_enable_reg_info
->access_bit_mask
;
169 pm1b_control
|= sleep_enable_reg_info
->access_bit_mask
;
171 /* Flush caches, as per ACPI specification */
173 ACPI_FLUSH_CPU_CACHE();
175 status
= acpi_os_prepare_sleep(sleep_state
, pm1a_control
,
177 if (ACPI_SKIP(status
))
178 return_ACPI_STATUS(AE_OK
);
179 if (ACPI_FAILURE(status
))
180 return_ACPI_STATUS(status
);
181 /* Write #2: Write both SLP_TYP + SLP_EN */
183 status
= acpi_hw_write_pm1_control(pm1a_control
, pm1b_control
);
184 if (ACPI_FAILURE(status
)) {
185 return_ACPI_STATUS(status
);
188 if (sleep_state
> ACPI_STATE_S3
) {
190 * We wanted to sleep > S3, but it didn't happen (by virtue of the
191 * fact that we are still executing!)
193 * Wait ten seconds, then try again. This is to get S4/S5 to work on
196 * We wait so long to allow chipsets that poll this reg very slowly
197 * to still read the right value. Ideally, this block would go
200 acpi_os_stall(10000000);
202 status
= acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL
,
203 sleep_enable_reg_info
->
205 if (ACPI_FAILURE(status
)) {
206 return_ACPI_STATUS(status
);
210 /* Wait for transition back to Working State */
214 acpi_read_bit_register(ACPI_BITREG_WAKE_STATUS
, &in_value
);
215 if (ACPI_FAILURE(status
)) {
216 return_ACPI_STATUS(status
);
221 return_ACPI_STATUS(AE_OK
);
224 /*******************************************************************************
226 * FUNCTION: acpi_hw_legacy_wake_prep
228 * PARAMETERS: sleep_state - Which sleep state we just exited
229 * flags - ACPI_EXECUTE_BFS to run optional method
233 * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a
235 * Called with interrupts ENABLED.
237 ******************************************************************************/
239 acpi_status
acpi_hw_legacy_wake_prep(u8 sleep_state
, u8 flags
)
242 struct acpi_bit_register_info
*sleep_type_reg_info
;
243 struct acpi_bit_register_info
*sleep_enable_reg_info
;
247 ACPI_FUNCTION_TRACE(hw_legacy_wake_prep
);
250 * Set SLP_TYPE and SLP_EN to state S0.
251 * This is unclear from the ACPI Spec, but it is required
254 status
= acpi_get_sleep_type_data(ACPI_STATE_S0
,
255 &acpi_gbl_sleep_type_a
,
256 &acpi_gbl_sleep_type_b
);
257 if (ACPI_SUCCESS(status
)) {
258 sleep_type_reg_info
=
259 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE
);
260 sleep_enable_reg_info
=
261 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE
);
263 /* Get current value of PM1A control */
265 status
= acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL
,
267 if (ACPI_SUCCESS(status
)) {
269 /* Clear the SLP_EN and SLP_TYP fields */
271 pm1a_control
&= ~(sleep_type_reg_info
->access_bit_mask
|
272 sleep_enable_reg_info
->
274 pm1b_control
= pm1a_control
;
276 /* Insert the SLP_TYP bits */
278 pm1a_control
|= (acpi_gbl_sleep_type_a
<<
279 sleep_type_reg_info
->bit_position
);
280 pm1b_control
|= (acpi_gbl_sleep_type_b
<<
281 sleep_type_reg_info
->bit_position
);
283 /* Write the control registers and ignore any errors */
285 (void)acpi_hw_write_pm1_control(pm1a_control
,
290 /* Optionally execute _BFS (Back From Sleep) */
292 if (flags
& ACPI_EXECUTE_BFS
) {
293 acpi_hw_execute_sleep_method(METHOD_PATHNAME__BFS
, sleep_state
);
295 return_ACPI_STATUS(status
);
298 /*******************************************************************************
300 * FUNCTION: acpi_hw_legacy_wake
302 * PARAMETERS: sleep_state - Which sleep state we just exited
303 * flags - Reserved, set to zero
307 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
308 * Called with interrupts ENABLED.
310 ******************************************************************************/
312 acpi_status
acpi_hw_legacy_wake(u8 sleep_state
, u8 flags
)
316 ACPI_FUNCTION_TRACE(hw_legacy_wake
);
318 /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
320 acpi_gbl_sleep_type_a
= ACPI_SLEEP_TYPE_INVALID
;
321 acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST
, ACPI_SST_WAKING
);
324 * GPEs must be enabled before _WAK is called as GPEs
325 * might get fired there
328 * 1) Disable/Clear all GPEs
329 * 2) Enable all runtime GPEs
331 status
= acpi_hw_disable_all_gpes();
332 if (ACPI_FAILURE(status
)) {
333 return_ACPI_STATUS(status
);
336 status
= acpi_hw_enable_all_runtime_gpes();
337 if (ACPI_FAILURE(status
)) {
338 return_ACPI_STATUS(status
);
342 * Now we can execute _WAK, etc. Some machines require that the GPEs
343 * are enabled before the wake methods are executed.
345 acpi_hw_execute_sleep_method(METHOD_PATHNAME__WAK
, sleep_state
);
348 * Some BIOS code assumes that WAK_STS will be cleared on resume
349 * and use it to determine whether the system is rebooting or
350 * resuming. Clear WAK_STS for compatibility.
352 acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS
, 1);
353 acpi_gbl_system_awake_and_running
= TRUE
;
355 /* Enable power button */
358 acpi_write_bit_register(acpi_gbl_fixed_event_info
359 [ACPI_EVENT_POWER_BUTTON
].
360 enable_register_id
, ACPI_ENABLE_EVENT
);
363 acpi_write_bit_register(acpi_gbl_fixed_event_info
364 [ACPI_EVENT_POWER_BUTTON
].
365 status_register_id
, ACPI_CLEAR_STATUS
);
368 * Enable BM arbitration. This feature is contained within an
369 * optional register (PM2 Control), so ignore a BAD_ADDRESS
372 status
= acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE
, 0);
373 if (ACPI_FAILURE(status
) && (status
!= AE_BAD_ADDRESS
)) {
374 return_ACPI_STATUS(status
);
377 acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST
, ACPI_SST_WORKING
);
378 return_ACPI_STATUS(status
);
381 #endif /* !ACPI_REDUCED_HARDWARE */