blob: 7039606a0ba8c3a4753cd3aa4703f38b77c7358e [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 Moore25f044e2013-01-25 05:38:56 +00008 * Copyright (C) 2000 - 2013, 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 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040064acpi_status acpi_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Len Brownb430acb2010-05-06 17:41:08 -040066 acpi_status status;
Len Brown3d695832010-06-28 20:55:01 -040067 int retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Bob Mooreb229cf92006-04-21 17:15:00 -040069 ACPI_FUNCTION_TRACE(acpi_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Bob Moorec8573032007-02-02 19:48:23 +030071 /* ACPI tables must be present */
72
73 if (!acpi_tb_tables_loaded()) {
74 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
75 }
76
Bob Moorec39660b2013-03-08 09:22:14 +000077 /* If the Hardware Reduced flag is set, machine is always in acpi mode */
78
79 if (acpi_gbl_reduced_hardware) {
80 return_ACPI_STATUS(AE_OK);
81 }
82
Bob Moorec8573032007-02-02 19:48:23 +030083 /* Check current mode */
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
Len Brown4be44fc2005-08-05 00:44:28 -040086 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
87 "System is already in ACPI mode\n"));
Len Brownb430acb2010-05-06 17:41:08 -040088 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 }
90
Len Brownb430acb2010-05-06 17:41:08 -040091 /* Transition to ACPI mode */
92
93 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
94 if (ACPI_FAILURE(status)) {
95 ACPI_ERROR((AE_INFO,
96 "Could not transition to ACPI mode"));
97 return_ACPI_STATUS(status);
98 }
99
100 /* Sanity check that transition succeeded */
101
Len Brown3d695832010-06-28 20:55:01 -0400102 for (retry = 0; retry < 30000; ++retry) {
103 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
104 if (retry != 0)
105 ACPI_WARNING((AE_INFO,
106 "Platform took > %d00 usec to enter ACPI mode", retry));
107 return_ACPI_STATUS(AE_OK);
108 }
109 acpi_os_stall(100); /* 100 usec */
Len Brownb430acb2010-05-06 17:41:08 -0400110 }
111
Len Brown3d695832010-06-28 20:55:01 -0400112 ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
113 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
Bob Moore83135242006-10-03 00:00:00 -0400116ACPI_EXPORT_SYMBOL(acpi_enable)
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118/*******************************************************************************
119 *
120 * FUNCTION: acpi_disable
121 *
122 * PARAMETERS: None
123 *
124 * RETURN: Status
125 *
Robert Moore44f6c012005-04-18 22:49:35 -0400126 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 *
128 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400129acpi_status acpi_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
Len Brown4be44fc2005-08-05 00:44:28 -0400131 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Bob Mooreb229cf92006-04-21 17:15:00 -0400133 ACPI_FUNCTION_TRACE(acpi_disable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Bob Moorec39660b2013-03-08 09:22:14 +0000135 /* If the Hardware Reduced flag is set, machine is always in acpi mode */
136
137 if (acpi_gbl_reduced_hardware) {
138 return_ACPI_STATUS(AE_OK);
139 }
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400142 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
143 "System is already in legacy (non-ACPI) mode\n"));
144 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 /* Transition to LEGACY mode */
146
Len Brown4be44fc2005-08-05 00:44:28 -0400147 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Len Brown4be44fc2005-08-05 00:44:28 -0400149 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500150 ACPI_ERROR((AE_INFO,
151 "Could not exit ACPI mode to legacy mode"));
Len Brown4be44fc2005-08-05 00:44:28 -0400152 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 }
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157
Len Brown4be44fc2005-08-05 00:44:28 -0400158 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
Bob Moore83135242006-10-03 00:00:00 -0400161ACPI_EXPORT_SYMBOL(acpi_disable)
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163/*******************************************************************************
164 *
165 * FUNCTION: acpi_enable_event
166 *
Bob Mooreba494be2012-07-12 09:40:10 +0800167 * PARAMETERS: event - The fixed eventto be enabled
168 * flags - Reserved
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 *
170 * RETURN: Status
171 *
172 * DESCRIPTION: Enable an ACPI event (fixed)
173 *
174 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400175acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
Len Brown4be44fc2005-08-05 00:44:28 -0400177 acpi_status status = AE_OK;
178 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Bob Mooreb229cf92006-04-21 17:15:00 -0400180 ACPI_FUNCTION_TRACE(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182 /* Decode the Fixed Event */
183
184 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400185 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
187
188 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800189 * Enable the requested fixed event (by writing a one to the enable
190 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 */
Len Brown4be44fc2005-08-05 00:44:28 -0400192 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800193 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800194 enable_register_id, ACPI_ENABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400195 if (ACPI_FAILURE(status)) {
196 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
198
199 /* Make sure that the hardware responded */
200
Len Brown4be44fc2005-08-05 00:44:28 -0400201 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800202 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
203 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400204 if (ACPI_FAILURE(status)) {
205 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 }
207
208 if (value != 1) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500209 ACPI_ERROR((AE_INFO,
210 "Could not enable %s event",
211 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400212 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 }
214
Len Brown4be44fc2005-08-05 00:44:28 -0400215 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Bob Moore83135242006-10-03 00:00:00 -0400218ACPI_EXPORT_SYMBOL(acpi_enable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220/*******************************************************************************
221 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 * FUNCTION: acpi_disable_event
223 *
Lv Zheng75c80442012-12-19 05:36:49 +0000224 * PARAMETERS: event - The fixed event to be disabled
225 * flags - Reserved
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 *
227 * RETURN: Status
228 *
229 * DESCRIPTION: Disable an ACPI event (fixed)
230 *
231 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400232acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Len Brown4be44fc2005-08-05 00:44:28 -0400234 acpi_status status = AE_OK;
235 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Bob Mooreb229cf92006-04-21 17:15:00 -0400237 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239 /* Decode the Fixed Event */
240
241 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400242 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 }
244
245 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800246 * Disable the requested fixed event (by writing a zero to the enable
247 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 */
Len Brown4be44fc2005-08-05 00:44:28 -0400249 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800250 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800251 enable_register_id, ACPI_DISABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400252 if (ACPI_FAILURE(status)) {
253 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 }
255
Len Brown4be44fc2005-08-05 00:44:28 -0400256 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800257 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
258 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400259 if (ACPI_FAILURE(status)) {
260 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 }
262
263 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500264 ACPI_ERROR((AE_INFO,
265 "Could not disable %s events",
266 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400267 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269
Len Brown4be44fc2005-08-05 00:44:28 -0400270 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Bob Moore83135242006-10-03 00:00:00 -0400273ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275/*******************************************************************************
276 *
277 * FUNCTION: acpi_clear_event
278 *
Bob Mooreba494be2012-07-12 09:40:10 +0800279 * PARAMETERS: event - The fixed event to be cleared
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 *
281 * RETURN: Status
282 *
283 * DESCRIPTION: Clear an ACPI event (fixed)
284 *
285 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400286acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
Len Brown4be44fc2005-08-05 00:44:28 -0400288 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Bob Mooreb229cf92006-04-21 17:15:00 -0400290 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 /* Decode the Fixed Event */
293
294 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400295 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 }
297
298 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800299 * Clear the requested fixed event (By writing a one to the status
300 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 */
Len Brown4be44fc2005-08-05 00:44:28 -0400302 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800303 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800304 status_register_id, ACPI_CLEAR_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Len Brown4be44fc2005-08-05 00:44:28 -0400306 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Bob Moore83135242006-10-03 00:00:00 -0400309ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311/*******************************************************************************
312 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 * FUNCTION: acpi_get_event_status
314 *
Bob Mooreba494be2012-07-12 09:40:10 +0800315 * PARAMETERS: event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400316 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 * be returned
318 *
319 * RETURN: Status
320 *
321 * DESCRIPTION: Obtains and returns the current status of the event
322 *
323 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400324acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
Len Brown4be44fc2005-08-05 00:44:28 -0400326 acpi_status status = AE_OK;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800327 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Bob Mooreb229cf92006-04-21 17:15:00 -0400329 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400332 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 }
334
335 /* Decode the Fixed Event */
336
337 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400338 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 }
340
341 /* Get the status of the requested fixed event */
342
Len Brown4be44fc2005-08-05 00:44:28 -0400343 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800344 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800345 enable_register_id, &value);
346 if (ACPI_FAILURE(status))
347 return_ACPI_STATUS(status);
348
349 *event_status = value;
350
351 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800352 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800353 status_register_id, &value);
354 if (ACPI_FAILURE(status))
355 return_ACPI_STATUS(status);
356
357 if (value)
358 *event_status |= ACPI_EVENT_FLAG_SET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Zhang Ruied206fa2008-10-27 14:01:02 -0700360 if (acpi_gbl_fixed_event_handlers[event].handler)
361 *event_status |= ACPI_EVENT_FLAG_HANDLE;
362
Len Brown4be44fc2005-08-05 00:44:28 -0400363 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
Bob Moore83135242006-10-03 00:00:00 -0400366ACPI_EXPORT_SYMBOL(acpi_get_event_status)
Bob Moore33620c52012-02-14 18:14:27 +0800367#endif /* !ACPI_REDUCED_HARDWARE */