blob: 77cee5a5e891b5ea5eb22245afd34ea73a070651 [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 Moore77848132012-01-12 13:27:23 +08008 * Copyright (C) 2000 - 2012, 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
Paul Gortmaker214f2c92011-10-26 16:22:14 -040044#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050046#include "accommon.h"
Len Browne2f7a772009-01-09 00:30:03 -050047#include "actables.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("evxfevnt")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Bob Moore33620c52012-02-14 18:14:27 +080052#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/*******************************************************************************
54 *
55 * FUNCTION: acpi_enable
56 *
57 * PARAMETERS: None
58 *
59 * RETURN: Status
60 *
61 * DESCRIPTION: Transfers the system into ACPI mode.
62 *
63 ******************************************************************************/
Bob Mooree97d6bf2008-12-30 09:45:17 +080064
Len Brown4be44fc2005-08-05 00:44:28 -040065acpi_status acpi_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Len Brownb430acb2010-05-06 17:41:08 -040067 acpi_status status;
Len Brown3d695832010-06-28 20:55:01 -040068 int retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Bob Mooreb229cf92006-04-21 17:15:00 -040070 ACPI_FUNCTION_TRACE(acpi_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Bob Moorec8573032007-02-02 19:48:23 +030072 /* ACPI tables must be present */
73
74 if (!acpi_tb_tables_loaded()) {
75 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
76 }
77
78 /* Check current mode */
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
Len Brown4be44fc2005-08-05 00:44:28 -040081 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
82 "System is already in ACPI mode\n"));
Len Brownb430acb2010-05-06 17:41:08 -040083 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 }
85
Len Brownb430acb2010-05-06 17:41:08 -040086 /* Transition to ACPI mode */
87
88 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
89 if (ACPI_FAILURE(status)) {
90 ACPI_ERROR((AE_INFO,
91 "Could not transition to ACPI mode"));
92 return_ACPI_STATUS(status);
93 }
94
95 /* Sanity check that transition succeeded */
96
Len Brown3d695832010-06-28 20:55:01 -040097 for (retry = 0; retry < 30000; ++retry) {
98 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
99 if (retry != 0)
100 ACPI_WARNING((AE_INFO,
101 "Platform took > %d00 usec to enter ACPI mode", retry));
102 return_ACPI_STATUS(AE_OK);
103 }
104 acpi_os_stall(100); /* 100 usec */
Len Brownb430acb2010-05-06 17:41:08 -0400105 }
106
Len Brown3d695832010-06-28 20:55:01 -0400107 ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
108 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Bob Moore83135242006-10-03 00:00:00 -0400111ACPI_EXPORT_SYMBOL(acpi_enable)
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/*******************************************************************************
114 *
115 * FUNCTION: acpi_disable
116 *
117 * PARAMETERS: None
118 *
119 * RETURN: Status
120 *
Robert Moore44f6c012005-04-18 22:49:35 -0400121 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 *
123 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400124acpi_status acpi_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
Len Brown4be44fc2005-08-05 00:44:28 -0400126 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Bob Mooreb229cf92006-04-21 17:15:00 -0400128 ACPI_FUNCTION_TRACE(acpi_disable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400131 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
132 "System is already in legacy (non-ACPI) mode\n"));
133 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 /* Transition to LEGACY mode */
135
Len Brown4be44fc2005-08-05 00:44:28 -0400136 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Len Brown4be44fc2005-08-05 00:44:28 -0400138 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500139 ACPI_ERROR((AE_INFO,
140 "Could not exit ACPI mode to legacy mode"));
Len Brown4be44fc2005-08-05 00:44:28 -0400141 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 }
143
Len Brown4be44fc2005-08-05 00:44:28 -0400144 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 }
146
Len Brown4be44fc2005-08-05 00:44:28 -0400147 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148}
149
Bob Moore83135242006-10-03 00:00:00 -0400150ACPI_EXPORT_SYMBOL(acpi_disable)
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152/*******************************************************************************
153 *
154 * FUNCTION: acpi_enable_event
155 *
156 * PARAMETERS: Event - The fixed eventto be enabled
157 * Flags - Reserved
158 *
159 * RETURN: Status
160 *
161 * DESCRIPTION: Enable an ACPI event (fixed)
162 *
163 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400164acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Len Brown4be44fc2005-08-05 00:44:28 -0400166 acpi_status status = AE_OK;
167 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Bob Mooreb229cf92006-04-21 17:15:00 -0400169 ACPI_FUNCTION_TRACE(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 /* Decode the Fixed Event */
172
173 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400174 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 }
176
177 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800178 * Enable the requested fixed event (by writing a one to the enable
179 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 */
Len Brown4be44fc2005-08-05 00:44:28 -0400181 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800182 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800183 enable_register_id, ACPI_ENABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400184 if (ACPI_FAILURE(status)) {
185 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
187
188 /* Make sure that the hardware responded */
189
Len Brown4be44fc2005-08-05 00:44:28 -0400190 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800191 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
192 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400193 if (ACPI_FAILURE(status)) {
194 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 }
196
197 if (value != 1) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500198 ACPI_ERROR((AE_INFO,
199 "Could not enable %s event",
200 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400201 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
203
Len Brown4be44fc2005-08-05 00:44:28 -0400204 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Bob Moore83135242006-10-03 00:00:00 -0400207ACPI_EXPORT_SYMBOL(acpi_enable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209/*******************************************************************************
210 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 * FUNCTION: acpi_disable_event
212 *
213 * PARAMETERS: Event - The fixed eventto be enabled
214 * Flags - Reserved
215 *
216 * RETURN: Status
217 *
218 * DESCRIPTION: Disable an ACPI event (fixed)
219 *
220 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400221acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
Len Brown4be44fc2005-08-05 00:44:28 -0400223 acpi_status status = AE_OK;
224 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Bob Mooreb229cf92006-04-21 17:15:00 -0400226 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 /* Decode the Fixed Event */
229
230 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400231 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
233
234 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800235 * Disable the requested fixed event (by writing a zero to the enable
236 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 */
Len Brown4be44fc2005-08-05 00:44:28 -0400238 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800239 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800240 enable_register_id, ACPI_DISABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400241 if (ACPI_FAILURE(status)) {
242 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 }
244
Len Brown4be44fc2005-08-05 00:44:28 -0400245 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800246 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
247 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400248 if (ACPI_FAILURE(status)) {
249 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
251
252 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500253 ACPI_ERROR((AE_INFO,
254 "Could not disable %s events",
255 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400256 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
258
Len Brown4be44fc2005-08-05 00:44:28 -0400259 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Bob Moore83135242006-10-03 00:00:00 -0400262ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264/*******************************************************************************
265 *
266 * FUNCTION: acpi_clear_event
267 *
268 * PARAMETERS: Event - The fixed event to be cleared
269 *
270 * RETURN: Status
271 *
272 * DESCRIPTION: Clear an ACPI event (fixed)
273 *
274 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400275acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
Len Brown4be44fc2005-08-05 00:44:28 -0400277 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Bob Mooreb229cf92006-04-21 17:15:00 -0400279 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 /* Decode the Fixed Event */
282
283 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400284 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 }
286
287 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800288 * Clear the requested fixed event (By writing a one to the status
289 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 */
Len Brown4be44fc2005-08-05 00:44:28 -0400291 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800292 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800293 status_register_id, ACPI_CLEAR_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Len Brown4be44fc2005-08-05 00:44:28 -0400295 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Bob Moore83135242006-10-03 00:00:00 -0400298ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300/*******************************************************************************
301 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 * FUNCTION: acpi_get_event_status
303 *
304 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400305 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 * be returned
307 *
308 * RETURN: Status
309 *
310 * DESCRIPTION: Obtains and returns the current status of the event
311 *
312 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400313acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
Len Brown4be44fc2005-08-05 00:44:28 -0400315 acpi_status status = AE_OK;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800316 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Bob Mooreb229cf92006-04-21 17:15:00 -0400318 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400321 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 }
323
324 /* Decode the Fixed Event */
325
326 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400327 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 }
329
330 /* Get the status of the requested fixed event */
331
Len Brown4be44fc2005-08-05 00:44:28 -0400332 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800333 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800334 enable_register_id, &value);
335 if (ACPI_FAILURE(status))
336 return_ACPI_STATUS(status);
337
338 *event_status = value;
339
340 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800341 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800342 status_register_id, &value);
343 if (ACPI_FAILURE(status))
344 return_ACPI_STATUS(status);
345
346 if (value)
347 *event_status |= ACPI_EVENT_FLAG_SET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Zhang Ruied206fa2008-10-27 14:01:02 -0700349 if (acpi_gbl_fixed_event_handlers[event].handler)
350 *event_status |= ACPI_EVENT_FLAG_HANDLE;
351
Len Brown4be44fc2005-08-05 00:44:28 -0400352 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
Bob Moore83135242006-10-03 00:00:00 -0400355ACPI_EXPORT_SYMBOL(acpi_get_event_status)
Bob Moore33620c52012-02-14 18:14:27 +0800356#endif /* !ACPI_REDUCED_HARDWARE */