Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Bob Moore | 7095857 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 3 | * Name: hwsleep.c - ACPI Hardware Sleep/Wake Support functions for the |
| 4 | * original/legacy sleep/PM registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | *****************************************************************************/ |
| 7 | |
| 8 | /* |
Bob Moore | 7735ca0 | 2017-02-08 11:00:08 +0800 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2017, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions, and the following disclaimer, |
| 17 | * without modification. |
| 18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 19 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 20 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 21 | * including a substantially similar Disclaimer requirement for further |
| 22 | * binary redistribution. |
| 23 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 24 | * of any contributors may be used to endorse or promote products derived |
| 25 | * from this software without specific prior written permission. |
| 26 | * |
| 27 | * Alternatively, this software may be distributed under the terms of the |
| 28 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 29 | * Software Foundation. |
| 30 | * |
| 31 | * NO WARRANTY |
| 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 42 | * POSSIBILITY OF SUCH DAMAGES. |
| 43 | */ |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 46 | #include "accommon.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 | |
Bob Moore | 7095857 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 51 | #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 52 | /******************************************************************************* |
| 53 | * |
| 54 | * FUNCTION: acpi_hw_legacy_sleep |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | * |
| 56 | * PARAMETERS: sleep_state - Which sleep state to enter |
| 57 | * |
| 58 | * RETURN: Status |
| 59 | * |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 60 | * DESCRIPTION: Enter a system sleep state via the legacy FADT PM registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED |
| 62 | * |
| 63 | ******************************************************************************/ |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 64 | acpi_status acpi_hw_legacy_sleep(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 66 | struct acpi_bit_register_info *sleep_type_reg_info; |
| 67 | struct acpi_bit_register_info *sleep_enable_reg_info; |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 68 | u32 pm1a_control; |
| 69 | u32 pm1b_control; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 70 | u32 in_value; |
| 71 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 73 | ACPI_FUNCTION_TRACE(hw_legacy_sleep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | sleep_type_reg_info = |
Bob Moore | 82d79b8 | 2009-02-18 14:31:05 +0800 | [diff] [blame] | 76 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 77 | sleep_enable_reg_info = |
| 78 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | /* Clear wake status */ |
| 81 | |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 82 | status = acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, |
| 83 | ACPI_CLEAR_STATUS); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | if (ACPI_FAILURE(status)) { |
| 85 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /* Clear all fixed and general purpose status bits */ |
| 89 | |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 90 | status = acpi_hw_clear_acpi_status(); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 91 | if (ACPI_FAILURE(status)) { |
| 92 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /* |
Pavel Machek | 23b168d | 2008-02-05 19:27:12 +0100 | [diff] [blame] | 96 | * 1) Disable/Clear all GPEs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | * 2) Enable all wakeup GPEs |
| 98 | */ |
Alexey Starikovskiy | 1d99967 | 2007-03-12 14:49:26 -0400 | [diff] [blame] | 99 | status = acpi_hw_disable_all_gpes(); |
| 100 | if (ACPI_FAILURE(status)) { |
| 101 | return_ACPI_STATUS(status); |
| 102 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | acpi_gbl_system_awake_and_running = FALSE; |
| 104 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 105 | status = acpi_hw_enable_all_wakeup_gpes(); |
| 106 | if (ACPI_FAILURE(status)) { |
| 107 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /* Get current value of PM1A control */ |
| 111 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 112 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, |
| 113 | &pm1a_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 114 | if (ACPI_FAILURE(status)) { |
| 115 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 117 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
Bob Moore | b27d659 | 2010-05-26 11:47:13 +0800 | [diff] [blame] | 118 | "Entering sleep state [S%u]\n", sleep_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 120 | /* Clear the SLP_EN and SLP_TYP fields */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 122 | pm1a_control &= ~(sleep_type_reg_info->access_bit_mask | |
| 123 | sleep_enable_reg_info->access_bit_mask); |
| 124 | pm1b_control = pm1a_control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 126 | /* Insert the SLP_TYP bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 128 | pm1a_control |= |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 129 | (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position); |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 130 | pm1b_control |= |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 131 | (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | /* |
| 134 | * We split the writes of SLP_TYP and SLP_EN to workaround |
| 135 | * poorly implemented hardware. |
| 136 | */ |
| 137 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 138 | /* Write #1: write the SLP_TYP data to the PM1 Control registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 140 | status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 141 | if (ACPI_FAILURE(status)) { |
| 142 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 145 | /* Insert the sleep enable (SLP_EN) bit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 147 | pm1a_control |= sleep_enable_reg_info->access_bit_mask; |
| 148 | pm1b_control |= sleep_enable_reg_info->access_bit_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 150 | /* Flush caches, as per ACPI specification */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 152 | ACPI_FLUSH_CPU_CACHE(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Lv Zheng | 0fc5e8f | 2016-12-28 15:28:49 +0800 | [diff] [blame] | 154 | status = acpi_os_enter_sleep(sleep_state, pm1a_control, pm1b_control); |
| 155 | if (status == AE_CTRL_TERMINATE) { |
Tang Liang | 09f98a8 | 2011-12-09 10:05:54 +0800 | [diff] [blame] | 156 | return_ACPI_STATUS(AE_OK); |
Lv Zheng | 0fc5e8f | 2016-12-28 15:28:49 +0800 | [diff] [blame] | 157 | } |
| 158 | if (ACPI_FAILURE(status)) { |
Tang Liang | 09f98a8 | 2011-12-09 10:05:54 +0800 | [diff] [blame] | 159 | return_ACPI_STATUS(status); |
Lv Zheng | 0fc5e8f | 2016-12-28 15:28:49 +0800 | [diff] [blame] | 160 | } |
| 161 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 162 | /* Write #2: Write both SLP_TYP + SLP_EN */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 164 | status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 165 | if (ACPI_FAILURE(status)) { |
| 166 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | if (sleep_state > ACPI_STATE_S3) { |
| 170 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 171 | * We wanted to sleep > S3, but it didn't happen (by virtue of the |
| 172 | * fact that we are still executing!) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 174 | * Wait ten seconds, then try again. This is to get S4/S5 to work on |
| 175 | * all machines. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | * |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 177 | * We wait so long to allow chipsets that poll this reg very slowly |
| 178 | * to still read the right value. Ideally, this block would go |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | * away entirely. |
| 180 | */ |
Bob Moore | c41679a | 2012-12-31 00:05:46 +0000 | [diff] [blame] | 181 | acpi_os_stall(10 * ACPI_USEC_PER_SEC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 183 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 184 | sleep_enable_reg_info-> |
| 185 | access_bit_mask); |
| 186 | if (ACPI_FAILURE(status)) { |
| 187 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 191 | /* Wait for transition back to Working State */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | do { |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 194 | status = |
| 195 | acpi_read_bit_register(ACPI_BITREG_WAKE_STATUS, &in_value); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | if (ACPI_FAILURE(status)) { |
| 197 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | } |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } while (!in_value); |
| 201 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 205 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | * |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 207 | * FUNCTION: acpi_hw_legacy_wake_prep |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | * |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 209 | * PARAMETERS: sleep_state - Which sleep state we just exited |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | * |
| 211 | * RETURN: Status |
| 212 | * |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 213 | * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a |
| 214 | * sleep. |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 215 | * Called with interrupts ENABLED. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | * |
| 217 | ******************************************************************************/ |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 218 | |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 219 | acpi_status acpi_hw_legacy_wake_prep(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 221 | acpi_status status; |
| 222 | struct acpi_bit_register_info *sleep_type_reg_info; |
| 223 | struct acpi_bit_register_info *sleep_enable_reg_info; |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 224 | u32 pm1a_control; |
| 225 | u32 pm1b_control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 227 | ACPI_FUNCTION_TRACE(hw_legacy_wake_prep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
| 229 | /* |
| 230 | * Set SLP_TYPE and SLP_EN to state S0. |
| 231 | * This is unclear from the ACPI Spec, but it is required |
| 232 | * by some machines. |
| 233 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 234 | status = acpi_get_sleep_type_data(ACPI_STATE_S0, |
| 235 | &acpi_gbl_sleep_type_a, |
| 236 | &acpi_gbl_sleep_type_b); |
| 237 | if (ACPI_SUCCESS(status)) { |
| 238 | sleep_type_reg_info = |
Bob Moore | 82d79b8 | 2009-02-18 14:31:05 +0800 | [diff] [blame] | 239 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 240 | sleep_enable_reg_info = |
| 241 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
| 243 | /* Get current value of PM1A control */ |
| 244 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 245 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 246 | &pm1a_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 247 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 248 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 249 | /* Clear the SLP_EN and SLP_TYP fields */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 251 | pm1a_control &= ~(sleep_type_reg_info->access_bit_mask | |
| 252 | sleep_enable_reg_info-> |
| 253 | access_bit_mask); |
| 254 | pm1b_control = pm1a_control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 256 | /* Insert the SLP_TYP bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 258 | pm1a_control |= (acpi_gbl_sleep_type_a << |
| 259 | sleep_type_reg_info->bit_position); |
| 260 | pm1b_control |= (acpi_gbl_sleep_type_b << |
| 261 | sleep_type_reg_info->bit_position); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 263 | /* Write the control registers and ignore any errors */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 265 | (void)acpi_hw_write_pm1_control(pm1a_control, |
| 266 | pm1b_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 270 | return_ACPI_STATUS(status); |
| 271 | } |
| 272 | |
| 273 | /******************************************************************************* |
| 274 | * |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 275 | * FUNCTION: acpi_hw_legacy_wake |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 276 | * |
| 277 | * PARAMETERS: sleep_state - Which sleep state we just exited |
| 278 | * |
| 279 | * RETURN: Status |
| 280 | * |
| 281 | * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep |
| 282 | * Called with interrupts ENABLED. |
| 283 | * |
| 284 | ******************************************************************************/ |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 285 | |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 286 | acpi_status acpi_hw_legacy_wake(u8 sleep_state) |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 287 | { |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 288 | acpi_status status; |
| 289 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 290 | ACPI_FUNCTION_TRACE(hw_legacy_wake); |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */ |
| 293 | |
| 294 | acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID; |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 295 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WAKING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | /* |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 298 | * GPEs must be enabled before _WAK is called as GPEs |
| 299 | * might get fired there |
| 300 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | * Restore the GPEs: |
| 302 | * 1) Disable/Clear all GPEs |
| 303 | * 2) Enable all runtime GPEs |
| 304 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 305 | status = acpi_hw_disable_all_gpes(); |
| 306 | if (ACPI_FAILURE(status)) { |
| 307 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 309 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 310 | status = acpi_hw_enable_all_runtime_gpes(); |
| 311 | if (ACPI_FAILURE(status)) { |
| 312 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 315 | /* |
| 316 | * Now we can execute _WAK, etc. Some machines require that the GPEs |
| 317 | * are enabled before the wake methods are executed. |
| 318 | */ |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 319 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__WAK, sleep_state); |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 320 | |
Matthew Garrett | a68823e | 2008-08-06 19:12:04 +0100 | [diff] [blame] | 321 | /* |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 322 | * Some BIOS code assumes that WAK_STS will be cleared on resume |
| 323 | * and use it to determine whether the system is rebooting or |
| 324 | * resuming. Clear WAK_STS for compatibility. |
Matthew Garrett | a68823e | 2008-08-06 19:12:04 +0100 | [diff] [blame] | 325 | */ |
Lv Zheng | 739dcbb | 2012-12-20 01:07:26 +0000 | [diff] [blame] | 326 | (void)acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, |
| 327 | ACPI_CLEAR_STATUS); |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 328 | acpi_gbl_system_awake_and_running = TRUE; |
| 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | /* Enable power button */ |
| 331 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 332 | (void) |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 333 | acpi_write_bit_register(acpi_gbl_fixed_event_info |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 334 | [ACPI_EVENT_POWER_BUTTON]. |
| 335 | enable_register_id, ACPI_ENABLE_EVENT); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 336 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 337 | (void) |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 338 | acpi_write_bit_register(acpi_gbl_fixed_event_info |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 339 | [ACPI_EVENT_POWER_BUTTON]. |
| 340 | status_register_id, ACPI_CLEAR_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 342 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 343 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 345 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 346 | #endif /* !ACPI_REDUCED_HARDWARE */ |