Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
Bob Moore | 7095857 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 4 | * Name: hwsleep.c - ACPI Hardware Sleep/Wake Support functions for the |
| 5 | * original/legacy sleep/PM registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
Bob Moore | 800ba7c | 2020-01-10 11:31:49 -0800 | [diff] [blame] | 7 | * Copyright (C) 2000 - 2020, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 9 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 12 | #include "accommon.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #define _COMPONENT ACPI_HARDWARE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 15 | ACPI_MODULE_NAME("hwsleep") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Bob Moore | 7095857 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 17 | #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 18 | /******************************************************************************* |
| 19 | * |
| 20 | * FUNCTION: acpi_hw_legacy_sleep |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | * |
| 22 | * PARAMETERS: sleep_state - Which sleep state to enter |
| 23 | * |
| 24 | * RETURN: Status |
| 25 | * |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 26 | * DESCRIPTION: Enter a system sleep state via the legacy FADT PM registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED |
| 28 | * |
| 29 | ******************************************************************************/ |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 30 | acpi_status acpi_hw_legacy_sleep(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 32 | struct acpi_bit_register_info *sleep_type_reg_info; |
| 33 | struct acpi_bit_register_info *sleep_enable_reg_info; |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 34 | u32 pm1a_control; |
| 35 | u32 pm1b_control; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 36 | u32 in_value; |
| 37 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 39 | ACPI_FUNCTION_TRACE(hw_legacy_sleep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 41 | sleep_type_reg_info = |
Bob Moore | 82d79b8 | 2009-02-18 14:31:05 +0800 | [diff] [blame] | 42 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 43 | sleep_enable_reg_info = |
| 44 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | /* Clear wake status */ |
| 47 | |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 48 | status = acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, |
| 49 | ACPI_CLEAR_STATUS); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | if (ACPI_FAILURE(status)) { |
| 51 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Rafael J. Wysocki | fa85015 | 2018-07-09 11:01:07 +0200 | [diff] [blame] | 54 | /* Disable all GPEs */ |
Alexey Starikovskiy | 1d99967 | 2007-03-12 14:49:26 -0400 | [diff] [blame] | 55 | status = acpi_hw_disable_all_gpes(); |
| 56 | if (ACPI_FAILURE(status)) { |
| 57 | return_ACPI_STATUS(status); |
| 58 | } |
Rafael J. Wysocki | f317c7d | 2018-08-12 12:50:09 +0200 | [diff] [blame] | 59 | status = acpi_hw_clear_acpi_status(); |
| 60 | if (ACPI_FAILURE(status)) { |
| 61 | return_ACPI_STATUS(status); |
Rafael J. Wysocki | fa85015 | 2018-07-09 11:01:07 +0200 | [diff] [blame] | 62 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | acpi_gbl_system_awake_and_running = FALSE; |
| 64 | |
Rafael J. Wysocki | fa85015 | 2018-07-09 11:01:07 +0200 | [diff] [blame] | 65 | /* Enable all wakeup GPEs */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 66 | status = acpi_hw_enable_all_wakeup_gpes(); |
| 67 | if (ACPI_FAILURE(status)) { |
| 68 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /* Get current value of PM1A control */ |
| 72 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 73 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, |
| 74 | &pm1a_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | if (ACPI_FAILURE(status)) { |
| 76 | return_ACPI_STATUS(status); |
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 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
Bob Moore | b27d659 | 2010-05-26 11:47:13 +0800 | [diff] [blame] | 79 | "Entering sleep state [S%u]\n", sleep_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 81 | /* Clear the SLP_EN and SLP_TYP fields */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 83 | pm1a_control &= ~(sleep_type_reg_info->access_bit_mask | |
| 84 | sleep_enable_reg_info->access_bit_mask); |
| 85 | pm1b_control = pm1a_control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 87 | /* Insert the SLP_TYP bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 89 | pm1a_control |= |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 90 | (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position); |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 91 | pm1b_control |= |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * We split the writes of SLP_TYP and SLP_EN to workaround |
| 96 | * poorly implemented hardware. |
| 97 | */ |
| 98 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 99 | /* Write #1: write the SLP_TYP data to the PM1 Control registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 101 | status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | if (ACPI_FAILURE(status)) { |
| 103 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 106 | /* Insert the sleep enable (SLP_EN) bit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 108 | pm1a_control |= sleep_enable_reg_info->access_bit_mask; |
| 109 | pm1b_control |= sleep_enable_reg_info->access_bit_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 111 | /* Flush caches, as per ACPI specification */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | ACPI_FLUSH_CPU_CACHE(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Lv Zheng | 0fc5e8f | 2016-12-28 15:28:49 +0800 | [diff] [blame] | 115 | status = acpi_os_enter_sleep(sleep_state, pm1a_control, pm1b_control); |
| 116 | if (status == AE_CTRL_TERMINATE) { |
Tang Liang | 09f98a8 | 2011-12-09 10:05:54 +0800 | [diff] [blame] | 117 | return_ACPI_STATUS(AE_OK); |
Lv Zheng | 0fc5e8f | 2016-12-28 15:28:49 +0800 | [diff] [blame] | 118 | } |
| 119 | if (ACPI_FAILURE(status)) { |
Tang Liang | 09f98a8 | 2011-12-09 10:05:54 +0800 | [diff] [blame] | 120 | return_ACPI_STATUS(status); |
Lv Zheng | 0fc5e8f | 2016-12-28 15:28:49 +0800 | [diff] [blame] | 121 | } |
| 122 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 123 | /* Write #2: Write both SLP_TYP + SLP_EN */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 125 | status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 126 | if (ACPI_FAILURE(status)) { |
| 127 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | if (sleep_state > ACPI_STATE_S3) { |
| 131 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 132 | * We wanted to sleep > S3, but it didn't happen (by virtue of the |
| 133 | * fact that we are still executing!) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 135 | * Wait ten seconds, then try again. This is to get S4/S5 to work on |
| 136 | * all machines. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | * |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 138 | * We wait so long to allow chipsets that poll this reg very slowly |
| 139 | * to still read the right value. Ideally, this block would go |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | * away entirely. |
| 141 | */ |
Bob Moore | c41679a | 2012-12-31 00:05:46 +0000 | [diff] [blame] | 142 | acpi_os_stall(10 * ACPI_USEC_PER_SEC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 144 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | sleep_enable_reg_info-> |
| 146 | access_bit_mask); |
| 147 | if (ACPI_FAILURE(status)) { |
| 148 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 152 | /* Wait for transition back to Working State */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | do { |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 155 | status = |
| 156 | acpi_read_bit_register(ACPI_BITREG_WAKE_STATUS, &in_value); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | if (ACPI_FAILURE(status)) { |
| 158 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } while (!in_value); |
| 162 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 166 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | * |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 168 | * FUNCTION: acpi_hw_legacy_wake_prep |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | * |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 170 | * PARAMETERS: sleep_state - Which sleep state we just exited |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | * |
| 172 | * RETURN: Status |
| 173 | * |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 174 | * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a |
| 175 | * sleep. |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 176 | * Called with interrupts ENABLED. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | * |
| 178 | ******************************************************************************/ |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 179 | |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 180 | acpi_status acpi_hw_legacy_wake_prep(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 182 | acpi_status status; |
| 183 | struct acpi_bit_register_info *sleep_type_reg_info; |
| 184 | struct acpi_bit_register_info *sleep_enable_reg_info; |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 185 | u32 pm1a_control; |
| 186 | u32 pm1b_control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 188 | ACPI_FUNCTION_TRACE(hw_legacy_wake_prep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | /* |
| 191 | * Set SLP_TYPE and SLP_EN to state S0. |
| 192 | * This is unclear from the ACPI Spec, but it is required |
| 193 | * by some machines. |
| 194 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | status = acpi_get_sleep_type_data(ACPI_STATE_S0, |
| 196 | &acpi_gbl_sleep_type_a, |
| 197 | &acpi_gbl_sleep_type_b); |
| 198 | if (ACPI_SUCCESS(status)) { |
| 199 | sleep_type_reg_info = |
Bob Moore | 82d79b8 | 2009-02-18 14:31:05 +0800 | [diff] [blame] | 200 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | sleep_enable_reg_info = |
| 202 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | /* Get current value of PM1A control */ |
| 205 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 206 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 207 | &pm1a_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 208 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 209 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 210 | /* Clear the SLP_EN and SLP_TYP fields */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 212 | pm1a_control &= ~(sleep_type_reg_info->access_bit_mask | |
| 213 | sleep_enable_reg_info-> |
| 214 | access_bit_mask); |
| 215 | pm1b_control = pm1a_control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 217 | /* Insert the SLP_TYP bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 219 | pm1a_control |= (acpi_gbl_sleep_type_a << |
| 220 | sleep_type_reg_info->bit_position); |
| 221 | pm1b_control |= (acpi_gbl_sleep_type_b << |
| 222 | sleep_type_reg_info->bit_position); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 224 | /* Write the control registers and ignore any errors */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 226 | (void)acpi_hw_write_pm1_control(pm1a_control, |
| 227 | pm1b_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 231 | return_ACPI_STATUS(status); |
| 232 | } |
| 233 | |
| 234 | /******************************************************************************* |
| 235 | * |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 236 | * FUNCTION: acpi_hw_legacy_wake |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 237 | * |
| 238 | * PARAMETERS: sleep_state - Which sleep state we just exited |
| 239 | * |
| 240 | * RETURN: Status |
| 241 | * |
| 242 | * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep |
| 243 | * Called with interrupts ENABLED. |
| 244 | * |
| 245 | ******************************************************************************/ |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 246 | |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 247 | acpi_status acpi_hw_legacy_wake(u8 sleep_state) |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 248 | { |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 249 | acpi_status status; |
| 250 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 251 | ACPI_FUNCTION_TRACE(hw_legacy_wake); |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */ |
| 254 | |
| 255 | acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID; |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 256 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WAKING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | /* |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 259 | * GPEs must be enabled before _WAK is called as GPEs |
| 260 | * might get fired there |
| 261 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | * Restore the GPEs: |
Erik Schmauss | 18996f2 | 2018-03-14 16:12:57 -0700 | [diff] [blame] | 263 | * 1) Disable all GPEs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | * 2) Enable all runtime GPEs |
| 265 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 266 | status = acpi_hw_disable_all_gpes(); |
| 267 | if (ACPI_FAILURE(status)) { |
| 268 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | } |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 270 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | status = acpi_hw_enable_all_runtime_gpes(); |
| 272 | if (ACPI_FAILURE(status)) { |
| 273 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 276 | /* |
| 277 | * Now we can execute _WAK, etc. Some machines require that the GPEs |
| 278 | * are enabled before the wake methods are executed. |
| 279 | */ |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 280 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__WAK, sleep_state); |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 281 | |
Matthew Garrett | a68823e | 2008-08-06 19:12:04 +0100 | [diff] [blame] | 282 | /* |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 283 | * Some BIOS code assumes that WAK_STS will be cleared on resume |
| 284 | * and use it to determine whether the system is rebooting or |
| 285 | * resuming. Clear WAK_STS for compatibility. |
Matthew Garrett | a68823e | 2008-08-06 19:12:04 +0100 | [diff] [blame] | 286 | */ |
Lv Zheng | 739dcbb | 2012-12-20 01:07:26 +0000 | [diff] [blame] | 287 | (void)acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, |
| 288 | ACPI_CLEAR_STATUS); |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 289 | acpi_gbl_system_awake_and_running = TRUE; |
| 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | /* Enable power button */ |
| 292 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | (void) |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 294 | acpi_write_bit_register(acpi_gbl_fixed_event_info |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 295 | [ACPI_EVENT_POWER_BUTTON]. |
| 296 | enable_register_id, ACPI_ENABLE_EVENT); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 297 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 298 | (void) |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 299 | acpi_write_bit_register(acpi_gbl_fixed_event_info |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 300 | [ACPI_EVENT_POWER_BUTTON]. |
| 301 | status_register_id, ACPI_CLEAR_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
Anchal Agarwal | a1dc35b | 2020-02-14 10:47:58 -0800 | [diff] [blame] | 303 | /* Enable sleep button */ |
| 304 | |
| 305 | (void) |
| 306 | acpi_write_bit_register(acpi_gbl_fixed_event_info |
| 307 | [ACPI_EVENT_SLEEP_BUTTON]. |
| 308 | enable_register_id, ACPI_ENABLE_EVENT); |
| 309 | |
| 310 | (void) |
| 311 | acpi_write_bit_register(acpi_gbl_fixed_event_info |
| 312 | [ACPI_EVENT_SLEEP_BUTTON]. |
| 313 | status_register_id, ACPI_CLEAR_STATUS); |
| 314 | |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 315 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 316 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 318 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 319 | #endif /* !ACPI_REDUCED_HARDWARE */ |