blob: c57b5c707a777647199012484e3bff977aff180b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4 *
5 *****************************************************************************/
6
7/*
Bob Mooreb4e104e2011-01-17 11:05:40 +08008 * Copyright (C) 2000 - 2011, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
Len Browne2f7a772009-01-09 00:30:03 -050046#include "actables.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("evxfevnt")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51/*******************************************************************************
52 *
53 * FUNCTION: acpi_enable
54 *
55 * PARAMETERS: None
56 *
57 * RETURN: Status
58 *
59 * DESCRIPTION: Transfers the system into ACPI mode.
60 *
61 ******************************************************************************/
Bob Mooree97d6bf2008-12-30 09:45:17 +080062
Len Brown4be44fc2005-08-05 00:44:28 -040063acpi_status acpi_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Len Brownb430acb2010-05-06 17:41:08 -040065 acpi_status status;
Len Brown3d695832010-06-28 20:55:01 -040066 int retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Bob Mooreb229cf92006-04-21 17:15:00 -040068 ACPI_FUNCTION_TRACE(acpi_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Bob Moorec8573032007-02-02 19:48:23 +030070 /* ACPI tables must be present */
71
72 if (!acpi_tb_tables_loaded()) {
73 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
74 }
75
76 /* Check current mode */
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
Len Brown4be44fc2005-08-05 00:44:28 -040079 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
80 "System is already in ACPI mode\n"));
Len Brownb430acb2010-05-06 17:41:08 -040081 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 }
83
Len Brownb430acb2010-05-06 17:41:08 -040084 /* Transition to ACPI mode */
85
86 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
87 if (ACPI_FAILURE(status)) {
88 ACPI_ERROR((AE_INFO,
89 "Could not transition to ACPI mode"));
90 return_ACPI_STATUS(status);
91 }
92
93 /* Sanity check that transition succeeded */
94
Len Brown3d695832010-06-28 20:55:01 -040095 for (retry = 0; retry < 30000; ++retry) {
96 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
97 if (retry != 0)
98 ACPI_WARNING((AE_INFO,
99 "Platform took > %d00 usec to enter ACPI mode", retry));
100 return_ACPI_STATUS(AE_OK);
101 }
102 acpi_os_stall(100); /* 100 usec */
Len Brownb430acb2010-05-06 17:41:08 -0400103 }
104
Len Brown3d695832010-06-28 20:55:01 -0400105 ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
106 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107}
108
Bob Moore83135242006-10-03 00:00:00 -0400109ACPI_EXPORT_SYMBOL(acpi_enable)
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111/*******************************************************************************
112 *
113 * FUNCTION: acpi_disable
114 *
115 * PARAMETERS: None
116 *
117 * RETURN: Status
118 *
Robert Moore44f6c012005-04-18 22:49:35 -0400119 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 *
121 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400122acpi_status acpi_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Len Brown4be44fc2005-08-05 00:44:28 -0400124 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Bob Mooreb229cf92006-04-21 17:15:00 -0400126 ACPI_FUNCTION_TRACE(acpi_disable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400129 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
130 "System is already in legacy (non-ACPI) mode\n"));
131 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 /* Transition to LEGACY mode */
133
Len Brown4be44fc2005-08-05 00:44:28 -0400134 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Len Brown4be44fc2005-08-05 00:44:28 -0400136 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500137 ACPI_ERROR((AE_INFO,
138 "Could not exit ACPI mode to legacy mode"));
Len Brown4be44fc2005-08-05 00:44:28 -0400139 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 }
141
Len Brown4be44fc2005-08-05 00:44:28 -0400142 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
144
Len Brown4be44fc2005-08-05 00:44:28 -0400145 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
Bob Moore83135242006-10-03 00:00:00 -0400148ACPI_EXPORT_SYMBOL(acpi_disable)
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150/*******************************************************************************
151 *
152 * FUNCTION: acpi_enable_event
153 *
154 * PARAMETERS: Event - The fixed eventto be enabled
155 * Flags - Reserved
156 *
157 * RETURN: Status
158 *
159 * DESCRIPTION: Enable an ACPI event (fixed)
160 *
161 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400162acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
Len Brown4be44fc2005-08-05 00:44:28 -0400164 acpi_status status = AE_OK;
165 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Bob Mooreb229cf92006-04-21 17:15:00 -0400167 ACPI_FUNCTION_TRACE(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 /* Decode the Fixed Event */
170
171 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400172 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
174
175 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800176 * Enable the requested fixed event (by writing a one to the enable
177 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 */
Len Brown4be44fc2005-08-05 00:44:28 -0400179 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800180 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800181 enable_register_id, ACPI_ENABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400182 if (ACPI_FAILURE(status)) {
183 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 }
185
186 /* Make sure that the hardware responded */
187
Len Brown4be44fc2005-08-05 00:44:28 -0400188 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800189 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
190 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400191 if (ACPI_FAILURE(status)) {
192 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 }
194
195 if (value != 1) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500196 ACPI_ERROR((AE_INFO,
197 "Could not enable %s event",
198 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400199 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 }
201
Len Brown4be44fc2005-08-05 00:44:28 -0400202 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Bob Moore83135242006-10-03 00:00:00 -0400205ACPI_EXPORT_SYMBOL(acpi_enable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207/*******************************************************************************
208 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 * FUNCTION: acpi_disable_event
210 *
211 * PARAMETERS: Event - The fixed eventto be enabled
212 * Flags - Reserved
213 *
214 * RETURN: Status
215 *
216 * DESCRIPTION: Disable an ACPI event (fixed)
217 *
218 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400219acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Len Brown4be44fc2005-08-05 00:44:28 -0400221 acpi_status status = AE_OK;
222 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Bob Mooreb229cf92006-04-21 17:15:00 -0400224 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 /* Decode the Fixed Event */
227
228 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400229 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 }
231
232 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800233 * Disable the requested fixed event (by writing a zero to the enable
234 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 */
Len Brown4be44fc2005-08-05 00:44:28 -0400236 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800237 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800238 enable_register_id, ACPI_DISABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400239 if (ACPI_FAILURE(status)) {
240 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 }
242
Len Brown4be44fc2005-08-05 00:44:28 -0400243 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800244 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
245 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400246 if (ACPI_FAILURE(status)) {
247 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 }
249
250 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500251 ACPI_ERROR((AE_INFO,
252 "Could not disable %s events",
253 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400254 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 }
256
Len Brown4be44fc2005-08-05 00:44:28 -0400257 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Bob Moore83135242006-10-03 00:00:00 -0400260ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262/*******************************************************************************
263 *
264 * FUNCTION: acpi_clear_event
265 *
266 * PARAMETERS: Event - The fixed event to be cleared
267 *
268 * RETURN: Status
269 *
270 * DESCRIPTION: Clear an ACPI event (fixed)
271 *
272 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400273acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Len Brown4be44fc2005-08-05 00:44:28 -0400275 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Bob Mooreb229cf92006-04-21 17:15:00 -0400277 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279 /* Decode the Fixed Event */
280
281 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400282 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
284
285 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800286 * Clear the requested fixed event (By writing a one to the status
287 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 */
Len Brown4be44fc2005-08-05 00:44:28 -0400289 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800290 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800291 status_register_id, ACPI_CLEAR_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Len Brown4be44fc2005-08-05 00:44:28 -0400293 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Bob Moore83135242006-10-03 00:00:00 -0400296ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298/*******************************************************************************
299 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 * FUNCTION: acpi_get_event_status
301 *
302 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400303 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 * be returned
305 *
306 * RETURN: Status
307 *
308 * DESCRIPTION: Obtains and returns the current status of the event
309 *
310 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400311acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Len Brown4be44fc2005-08-05 00:44:28 -0400313 acpi_status status = AE_OK;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800314 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Bob Mooreb229cf92006-04-21 17:15:00 -0400316 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400319 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 }
321
322 /* Decode the Fixed Event */
323
324 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400325 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 }
327
328 /* Get the status of the requested fixed event */
329
Len Brown4be44fc2005-08-05 00:44:28 -0400330 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800331 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800332 enable_register_id, &value);
333 if (ACPI_FAILURE(status))
334 return_ACPI_STATUS(status);
335
336 *event_status = value;
337
338 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800339 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800340 status_register_id, &value);
341 if (ACPI_FAILURE(status))
342 return_ACPI_STATUS(status);
343
344 if (value)
345 *event_status |= ACPI_EVENT_FLAG_SET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Zhang Ruied206fa2008-10-27 14:01:02 -0700347 if (acpi_gbl_fixed_event_handlers[event].handler)
348 *event_status |= ACPI_EVENT_FLAG_HANDLE;
349
Len Brown4be44fc2005-08-05 00:44:28 -0400350 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
352
Bob Moore83135242006-10-03 00:00:00 -0400353ACPI_EXPORT_SYMBOL(acpi_get_event_status)