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 | 7784813 | 2012-01-12 13:27:23 +0800 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2012, 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" |
Shane Wang | 69575d3 | 2009-09-01 18:25:07 -0700 | [diff] [blame] | 47 | #include <linux/tboot.h> |
Paul Gortmaker | cc4b859 | 2011-07-01 14:30:49 -0400 | [diff] [blame] | 48 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | #define _COMPONENT ACPI_HARDWARE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | ACPI_MODULE_NAME("hwsleep") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Bob Moore | 7095857 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 53 | #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 54 | /******************************************************************************* |
| 55 | * |
| 56 | * FUNCTION: acpi_hw_legacy_sleep |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | * |
| 58 | * PARAMETERS: sleep_state - Which sleep state to enter |
Lin Ming | 8a73b17 | 2012-03-21 10:01:49 +0800 | [diff] [blame^] | 59 | * Flags - ACPI_EXECUTE_GTS to run optional method |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | * |
| 61 | * RETURN: Status |
| 62 | * |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 63 | * DESCRIPTION: Enter a system sleep state via the legacy FADT PM registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED |
| 65 | * |
| 66 | ******************************************************************************/ |
Lin Ming | 8a73b17 | 2012-03-21 10:01:49 +0800 | [diff] [blame^] | 67 | acpi_status acpi_hw_legacy_sleep(u8 sleep_state, u8 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | struct acpi_bit_register_info *sleep_type_reg_info; |
| 70 | struct acpi_bit_register_info *sleep_enable_reg_info; |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 71 | u32 pm1a_control; |
| 72 | u32 pm1b_control; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 73 | u32 in_value; |
| 74 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 76 | ACPI_FUNCTION_TRACE(hw_legacy_sleep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | sleep_type_reg_info = |
Bob Moore | 82d79b8 | 2009-02-18 14:31:05 +0800 | [diff] [blame] | 79 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | sleep_enable_reg_info = |
| 81 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | /* Clear wake status */ |
| 84 | |
Bob Moore | 768aaaf | 2009-03-06 09:49:25 +0800 | [diff] [blame] | 85 | status = |
| 86 | acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | if (ACPI_FAILURE(status)) { |
| 88 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /* Clear all fixed and general purpose status bits */ |
| 92 | |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 93 | status = acpi_hw_clear_acpi_status(); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | if (ACPI_FAILURE(status)) { |
| 95 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 98 | if (sleep_state != ACPI_STATE_S5) { |
| 99 | /* |
| 100 | * Disable BM arbitration. This feature is contained within an |
| 101 | * optional register (PM2 Control), so ignore a BAD_ADDRESS |
| 102 | * exception. |
| 103 | */ |
| 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); |
| 107 | } |
| 108 | } |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /* |
Pavel Machek | 23b168d | 2008-02-05 19:27:12 +0100 | [diff] [blame] | 111 | * 1) Disable/Clear all GPEs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | * 2) Enable all wakeup GPEs |
| 113 | */ |
Alexey Starikovskiy | 1d99967 | 2007-03-12 14:49:26 -0400 | [diff] [blame] | 114 | status = acpi_hw_disable_all_gpes(); |
| 115 | if (ACPI_FAILURE(status)) { |
| 116 | return_ACPI_STATUS(status); |
| 117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | acpi_gbl_system_awake_and_running = FALSE; |
| 119 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 120 | status = acpi_hw_enable_all_wakeup_gpes(); |
| 121 | if (ACPI_FAILURE(status)) { |
| 122 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Lin Ming | 8a73b17 | 2012-03-21 10:01:49 +0800 | [diff] [blame^] | 125 | /* Optionally execute _GTS (Going To Sleep) */ |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 126 | |
Lin Ming | 8a73b17 | 2012-03-21 10:01:49 +0800 | [diff] [blame^] | 127 | if (flags & ACPI_EXECUTE_GTS) { |
| 128 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__GTS, sleep_state); |
| 129 | } |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | /* Get current value of PM1A control */ |
| 132 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 133 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, |
| 134 | &pm1a_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 135 | if (ACPI_FAILURE(status)) { |
| 136 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
Bob Moore | b27d659 | 2010-05-26 11:47:13 +0800 | [diff] [blame] | 139 | "Entering sleep state [S%u]\n", sleep_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 141 | /* Clear the SLP_EN and SLP_TYP fields */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 143 | pm1a_control &= ~(sleep_type_reg_info->access_bit_mask | |
| 144 | sleep_enable_reg_info->access_bit_mask); |
| 145 | pm1b_control = pm1a_control; |
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 | /* Insert the SLP_TYP bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 149 | pm1a_control |= |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position); |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 151 | pm1b_control |= |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 152 | (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * We split the writes of SLP_TYP and SLP_EN to workaround |
| 156 | * poorly implemented hardware. |
| 157 | */ |
| 158 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 159 | /* Write #1: write the SLP_TYP data to the PM1 Control registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 161 | status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 162 | if (ACPI_FAILURE(status)) { |
| 163 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 166 | /* Insert the sleep enable (SLP_EN) bit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 168 | pm1a_control |= sleep_enable_reg_info->access_bit_mask; |
| 169 | pm1b_control |= sleep_enable_reg_info->access_bit_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 171 | /* Flush caches, as per ACPI specification */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 173 | ACPI_FLUSH_CPU_CACHE(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Joseph Cihula | 86886e5 | 2009-06-30 19:31:07 -0700 | [diff] [blame] | 175 | tboot_sleep(sleep_state, pm1a_control, pm1b_control); |
| 176 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 177 | /* Write #2: Write both SLP_TYP + SLP_EN */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 179 | status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 180 | if (ACPI_FAILURE(status)) { |
| 181 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | if (sleep_state > ACPI_STATE_S3) { |
| 185 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 186 | * We wanted to sleep > S3, but it didn't happen (by virtue of the |
| 187 | * fact that we are still executing!) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 189 | * Wait ten seconds, then try again. This is to get S4/S5 to work on |
| 190 | * all machines. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | * |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 192 | * We wait so long to allow chipsets that poll this reg very slowly |
| 193 | * to still read the right value. Ideally, this block would go |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | * away entirely. |
| 195 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | acpi_os_stall(10000000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 198 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 199 | sleep_enable_reg_info-> |
| 200 | access_bit_mask); |
| 201 | if (ACPI_FAILURE(status)) { |
| 202 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 206 | /* Wait for transition back to Working State */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | do { |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 209 | status = |
| 210 | acpi_read_bit_register(ACPI_BITREG_WAKE_STATUS, &in_value); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 211 | if (ACPI_FAILURE(status)) { |
| 212 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } while (!in_value); |
| 216 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 217 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 220 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | * |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 222 | * FUNCTION: acpi_hw_legacy_wake_prep |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | * |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 224 | * PARAMETERS: sleep_state - Which sleep state we just exited |
Lin Ming | 8a73b17 | 2012-03-21 10:01:49 +0800 | [diff] [blame^] | 225 | * Flags - ACPI_EXECUTE_BFS to run optional method |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | * |
| 227 | * RETURN: Status |
| 228 | * |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 229 | * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a |
| 230 | * sleep. |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 231 | * Called with interrupts ENABLED. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | * |
| 233 | ******************************************************************************/ |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 234 | |
Lin Ming | 8a73b17 | 2012-03-21 10:01:49 +0800 | [diff] [blame^] | 235 | acpi_status acpi_hw_legacy_wake_prep(u8 sleep_state, u8 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 237 | acpi_status status; |
| 238 | struct acpi_bit_register_info *sleep_type_reg_info; |
| 239 | struct acpi_bit_register_info *sleep_enable_reg_info; |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 240 | u32 pm1a_control; |
| 241 | u32 pm1b_control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 243 | ACPI_FUNCTION_TRACE(hw_legacy_wake_prep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
| 245 | /* |
| 246 | * Set SLP_TYPE and SLP_EN to state S0. |
| 247 | * This is unclear from the ACPI Spec, but it is required |
| 248 | * by some machines. |
| 249 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | status = acpi_get_sleep_type_data(ACPI_STATE_S0, |
| 251 | &acpi_gbl_sleep_type_a, |
| 252 | &acpi_gbl_sleep_type_b); |
| 253 | if (ACPI_SUCCESS(status)) { |
| 254 | sleep_type_reg_info = |
Bob Moore | 82d79b8 | 2009-02-18 14:31:05 +0800 | [diff] [blame] | 255 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 256 | sleep_enable_reg_info = |
| 257 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | /* Get current value of PM1A control */ |
| 260 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 261 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 262 | &pm1a_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 263 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 264 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 265 | /* Clear the SLP_EN and SLP_TYP fields */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 267 | pm1a_control &= ~(sleep_type_reg_info->access_bit_mask | |
| 268 | sleep_enable_reg_info-> |
| 269 | access_bit_mask); |
| 270 | pm1b_control = pm1a_control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 272 | /* Insert the SLP_TYP bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 274 | pm1a_control |= (acpi_gbl_sleep_type_a << |
| 275 | sleep_type_reg_info->bit_position); |
| 276 | pm1b_control |= (acpi_gbl_sleep_type_b << |
| 277 | sleep_type_reg_info->bit_position); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 279 | /* Write the control registers and ignore any errors */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 281 | (void)acpi_hw_write_pm1_control(pm1a_control, |
| 282 | pm1b_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | |
Lin Ming | 8a73b17 | 2012-03-21 10:01:49 +0800 | [diff] [blame^] | 286 | /* Optionally execute _BFS (Back From Sleep) */ |
| 287 | |
| 288 | if (flags & ACPI_EXECUTE_BFS) { |
| 289 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__BFS, sleep_state); |
| 290 | } |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 291 | return_ACPI_STATUS(status); |
| 292 | } |
| 293 | |
| 294 | /******************************************************************************* |
| 295 | * |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 296 | * FUNCTION: acpi_hw_legacy_wake |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 297 | * |
| 298 | * PARAMETERS: sleep_state - Which sleep state we just exited |
Lin Ming | 8a73b17 | 2012-03-21 10:01:49 +0800 | [diff] [blame^] | 299 | * Flags - Reserved, set to zero |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 300 | * |
| 301 | * RETURN: Status |
| 302 | * |
| 303 | * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep |
| 304 | * Called with interrupts ENABLED. |
| 305 | * |
| 306 | ******************************************************************************/ |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 307 | |
Lin Ming | 8a73b17 | 2012-03-21 10:01:49 +0800 | [diff] [blame^] | 308 | acpi_status acpi_hw_legacy_wake(u8 sleep_state, u8 flags) |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 309 | { |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 310 | acpi_status status; |
| 311 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 312 | ACPI_FUNCTION_TRACE(hw_legacy_wake); |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */ |
| 315 | |
| 316 | acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID; |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 317 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WAKING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | /* |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 320 | * GPEs must be enabled before _WAK is called as GPEs |
| 321 | * might get fired there |
| 322 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | * Restore the GPEs: |
| 324 | * 1) Disable/Clear all GPEs |
| 325 | * 2) Enable all runtime GPEs |
| 326 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 327 | status = acpi_hw_disable_all_gpes(); |
| 328 | if (ACPI_FAILURE(status)) { |
| 329 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 331 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 332 | status = acpi_hw_enable_all_runtime_gpes(); |
| 333 | if (ACPI_FAILURE(status)) { |
| 334 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 337 | /* |
| 338 | * Now we can execute _WAK, etc. Some machines require that the GPEs |
| 339 | * are enabled before the wake methods are executed. |
| 340 | */ |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 341 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__WAK, sleep_state); |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 342 | |
Matthew Garrett | a68823e | 2008-08-06 19:12:04 +0100 | [diff] [blame] | 343 | /* |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 344 | * Some BIOS code assumes that WAK_STS will be cleared on resume |
| 345 | * and use it to determine whether the system is rebooting or |
| 346 | * resuming. Clear WAK_STS for compatibility. |
Matthew Garrett | a68823e | 2008-08-06 19:12:04 +0100 | [diff] [blame] | 347 | */ |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 348 | acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, 1); |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 349 | acpi_gbl_system_awake_and_running = TRUE; |
| 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | /* Enable power button */ |
| 352 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 353 | (void) |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 354 | acpi_write_bit_register(acpi_gbl_fixed_event_info |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 355 | [ACPI_EVENT_POWER_BUTTON]. |
| 356 | enable_register_id, ACPI_ENABLE_EVENT); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 357 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 358 | (void) |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 359 | acpi_write_bit_register(acpi_gbl_fixed_event_info |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 360 | [ACPI_EVENT_POWER_BUTTON]. |
| 361 | status_register_id, ACPI_CLEAR_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 363 | /* |
| 364 | * Enable BM arbitration. This feature is contained within an |
| 365 | * optional register (PM2 Control), so ignore a BAD_ADDRESS |
| 366 | * exception. |
| 367 | */ |
| 368 | status = acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 0); |
| 369 | if (ACPI_FAILURE(status) && (status != AE_BAD_ADDRESS)) { |
| 370 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 373 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 374 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 376 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 377 | #endif /* !ACPI_REDUCED_HARDWARE */ |