2 /******************************************************************************
4 * Name: hwsleep.c - ACPI Hardware Sleep/Wake Interface
7 *****************************************************************************/
10 * Copyright (C) 2000, 2001 R. Byron Moore
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #define _COMPONENT ACPI_HARDWARE
32 MODULE_NAME ("hwsleep")
35 /******************************************************************************
37 * FUNCTION: Acpi_set_firmware_waking_vector
39 * PARAMETERS: Physical_address - Physical address of ACPI real mode
42 * RETURN: AE_OK or AE_ERROR
44 * DESCRIPTION: Access function for d_firmware_waking_vector field in FACS
46 ******************************************************************************/
49 acpi_set_firmware_waking_vector (
50 ACPI_PHYSICAL_ADDRESS physical_address)
53 FUNCTION_TRACE ("Acpi_set_firmware_waking_vector");
56 /* Make sure that we have an FACS */
59 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
64 if (acpi_gbl_FACS->vector_width == 32) {
65 * (u32 *) acpi_gbl_FACS->firmware_waking_vector = (u32) physical_address;
68 *acpi_gbl_FACS->firmware_waking_vector = physical_address;
71 return_ACPI_STATUS (AE_OK);
75 /******************************************************************************
77 * FUNCTION: Acpi_get_firmware_waking_vector
79 * PARAMETERS: *Physical_address - Output buffer where contents of
80 * the Firmware_waking_vector field of
81 * the FACS will be stored.
85 * DESCRIPTION: Access function for d_firmware_waking_vector field in FACS
87 ******************************************************************************/
90 acpi_get_firmware_waking_vector (
91 ACPI_PHYSICAL_ADDRESS *physical_address)
94 FUNCTION_TRACE ("Acpi_get_firmware_waking_vector");
97 if (!physical_address) {
98 return_ACPI_STATUS (AE_BAD_PARAMETER);
101 /* Make sure that we have an FACS */
103 if (!acpi_gbl_FACS) {
104 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
109 if (acpi_gbl_FACS->vector_width == 32) {
110 *physical_address = * (u32 *) acpi_gbl_FACS->firmware_waking_vector;
113 *physical_address = *acpi_gbl_FACS->firmware_waking_vector;
116 return_ACPI_STATUS (AE_OK);
119 /******************************************************************************
121 * FUNCTION: Acpi_enter_sleep_state
123 * PARAMETERS: Sleep_state - Which sleep state to enter
127 * DESCRIPTION: Enter a system sleep state (see ACPI 2.0 spec p 231)
129 ******************************************************************************/
132 acpi_enter_sleep_state (
136 acpi_object_list arg_list;
144 FUNCTION_TRACE ("Acpi_enter_sleep_state");
148 * _PSW methods could be run here to enable wake-on keyboard, LAN, etc.
150 status = acpi_hw_obtain_sleep_type_register_data (sleep_state, &type_a, &type_b);
151 if (!ACPI_SUCCESS (status)) {
155 /* run the _PTS and _GTS methods */
157 MEMSET(&arg_list, 0, sizeof(arg_list));
159 arg_list.pointer = &arg;
161 MEMSET(&arg, 0, sizeof(arg));
162 arg.type = ACPI_TYPE_INTEGER;
163 arg.integer.value = sleep_state;
165 acpi_evaluate_object (NULL, "\\_PTS", &arg_list, NULL);
166 acpi_evaluate_object (NULL, "\\_GTS", &arg_list, NULL);
168 /* clear wake status */
170 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_LOCK, WAK_STS, 1);
174 acpi_hw_disable_non_wakeup_gpes();
176 PM1Acontrol = (u16) acpi_hw_register_read (ACPI_MTX_LOCK, PM1_CONTROL);
178 ACPI_DEBUG_PRINT ((ACPI_DB_OK, "Entering S%d\n", sleep_state));
180 /* mask off SLP_EN and SLP_TYP fields */
182 PM1Acontrol &= ~(SLP_TYPE_X_MASK | SLP_EN_MASK);
183 PM1Bcontrol = PM1Acontrol;
185 /* mask in SLP_TYP */
187 PM1Acontrol |= (type_a << acpi_hw_get_bit_shift (SLP_TYPE_X_MASK));
188 PM1Bcontrol |= (type_b << acpi_hw_get_bit_shift (SLP_TYPE_X_MASK));
190 /* write #1: fill in SLP_TYP data */
192 acpi_hw_register_write (ACPI_MTX_LOCK, PM1A_CONTROL, PM1Acontrol);
193 acpi_hw_register_write (ACPI_MTX_LOCK, PM1B_CONTROL, PM1Bcontrol);
197 PM1Acontrol |= (1 << acpi_hw_get_bit_shift (SLP_EN_MASK));
198 PM1Bcontrol |= (1 << acpi_hw_get_bit_shift (SLP_EN_MASK));
204 /* write #2: SLP_TYP + SLP_EN */
206 acpi_hw_register_write (ACPI_MTX_LOCK, PM1A_CONTROL, PM1Acontrol);
207 acpi_hw_register_write (ACPI_MTX_LOCK, PM1B_CONTROL, PM1Bcontrol);
210 * Wait a second, then try again. This is to get S4/5 to work on all machines.
212 if (sleep_state > ACPI_STATE_S3) {
213 acpi_os_stall(1000000);
215 acpi_hw_register_write (ACPI_MTX_LOCK, PM1_CONTROL,
216 (1 << acpi_hw_get_bit_shift (SLP_EN_MASK)));
219 /* wait until we enter sleep state */
222 acpi_os_stall(10000);
224 while (!acpi_hw_register_bit_access (ACPI_READ, ACPI_MTX_LOCK, WAK_STS));
226 acpi_hw_enable_non_wakeup_gpes();
230 return_ACPI_STATUS (AE_OK);
233 /******************************************************************************
235 * FUNCTION: Acpi_leave_sleep_state
237 * PARAMETERS: Sleep_state - Which sleep state we just exited
241 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
243 ******************************************************************************/
246 acpi_leave_sleep_state (
249 acpi_object_list arg_list;
253 FUNCTION_TRACE ("Acpi_leave_sleep_state");
256 MEMSET (&arg_list, 0, sizeof(arg_list));
258 arg_list.pointer = &arg;
260 MEMSET (&arg, 0, sizeof(arg));
261 arg.type = ACPI_TYPE_INTEGER;
262 arg.integer.value = sleep_state;
264 acpi_evaluate_object (NULL, "\\_BFS", &arg_list, NULL);
265 acpi_evaluate_object (NULL, "\\_WAK", &arg_list, NULL);
267 /* _WAK returns stuff - do we want to look at it? */
269 acpi_hw_enable_non_wakeup_gpes();
271 return_ACPI_STATUS (AE_OK);