blob: d6e4e42316db51267a901d0d45487f0e2df4363a [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
77 /* Check current mode */
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
Len Brown4be44fc2005-08-05 00:44:28 -040080 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
81 "System is already in ACPI mode\n"));
Len Brownb430acb2010-05-06 17:41:08 -040082 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 }
84
Len Brownb430acb2010-05-06 17:41:08 -040085 /* Transition to ACPI mode */
86
87 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
88 if (ACPI_FAILURE(status)) {
89 ACPI_ERROR((AE_INFO,
90 "Could not transition to ACPI mode"));
91 return_ACPI_STATUS(status);
92 }
93
94 /* Sanity check that transition succeeded */
95
Len Brown3d695832010-06-28 20:55:01 -040096 for (retry = 0; retry < 30000; ++retry) {
97 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
98 if (retry != 0)
99 ACPI_WARNING((AE_INFO,
100 "Platform took > %d00 usec to enter ACPI mode", retry));
101 return_ACPI_STATUS(AE_OK);
102 }
103 acpi_os_stall(100); /* 100 usec */
Len Brownb430acb2010-05-06 17:41:08 -0400104 }
105
Len Brown3d695832010-06-28 20:55:01 -0400106 ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
107 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108}
109
Bob Moore83135242006-10-03 00:00:00 -0400110ACPI_EXPORT_SYMBOL(acpi_enable)
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/*******************************************************************************
113 *
114 * FUNCTION: acpi_disable
115 *
116 * PARAMETERS: None
117 *
118 * RETURN: Status
119 *
Robert Moore44f6c012005-04-18 22:49:35 -0400120 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 *
122 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400123acpi_status acpi_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Len Brown4be44fc2005-08-05 00:44:28 -0400125 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Bob Mooreb229cf92006-04-21 17:15:00 -0400127 ACPI_FUNCTION_TRACE(acpi_disable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400130 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
131 "System is already in legacy (non-ACPI) mode\n"));
132 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 /* Transition to LEGACY mode */
134
Len Brown4be44fc2005-08-05 00:44:28 -0400135 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Len Brown4be44fc2005-08-05 00:44:28 -0400137 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500138 ACPI_ERROR((AE_INFO,
139 "Could not exit ACPI mode to legacy mode"));
Len Brown4be44fc2005-08-05 00:44:28 -0400140 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
142
Len Brown4be44fc2005-08-05 00:44:28 -0400143 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 }
145
Len Brown4be44fc2005-08-05 00:44:28 -0400146 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
Bob Moore83135242006-10-03 00:00:00 -0400149ACPI_EXPORT_SYMBOL(acpi_disable)
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151/*******************************************************************************
152 *
153 * FUNCTION: acpi_enable_event
154 *
Bob Mooreba494be2012-07-12 09:40:10 +0800155 * PARAMETERS: event - The fixed eventto be enabled
156 * flags - Reserved
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 *
158 * RETURN: Status
159 *
160 * DESCRIPTION: Enable an ACPI event (fixed)
161 *
162 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400163acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
Len Brown4be44fc2005-08-05 00:44:28 -0400165 acpi_status status = AE_OK;
166 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Bob Mooreb229cf92006-04-21 17:15:00 -0400168 ACPI_FUNCTION_TRACE(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 /* Decode the Fixed Event */
171
172 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400173 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 }
175
176 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800177 * Enable the requested fixed event (by writing a one to the enable
178 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 */
Len Brown4be44fc2005-08-05 00:44:28 -0400180 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800181 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800182 enable_register_id, ACPI_ENABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400183 if (ACPI_FAILURE(status)) {
184 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 }
186
187 /* Make sure that the hardware responded */
188
Len Brown4be44fc2005-08-05 00:44:28 -0400189 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800190 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
191 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400192 if (ACPI_FAILURE(status)) {
193 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 }
195
196 if (value != 1) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500197 ACPI_ERROR((AE_INFO,
198 "Could not enable %s event",
199 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400200 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 }
202
Len Brown4be44fc2005-08-05 00:44:28 -0400203 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Bob Moore83135242006-10-03 00:00:00 -0400206ACPI_EXPORT_SYMBOL(acpi_enable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208/*******************************************************************************
209 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 * FUNCTION: acpi_disable_event
211 *
Lv Zheng75c80442012-12-19 05:36:49 +0000212 * PARAMETERS: event - The fixed event to be disabled
213 * flags - Reserved
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 *
215 * RETURN: Status
216 *
217 * DESCRIPTION: Disable an ACPI event (fixed)
218 *
219 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400220acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Len Brown4be44fc2005-08-05 00:44:28 -0400222 acpi_status status = AE_OK;
223 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Bob Mooreb229cf92006-04-21 17:15:00 -0400225 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227 /* Decode the Fixed Event */
228
229 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400230 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 }
232
233 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800234 * Disable the requested fixed event (by writing a zero to the enable
235 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 */
Len Brown4be44fc2005-08-05 00:44:28 -0400237 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800238 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800239 enable_register_id, ACPI_DISABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400240 if (ACPI_FAILURE(status)) {
241 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 }
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800245 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
246 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400247 if (ACPI_FAILURE(status)) {
248 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
250
251 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500252 ACPI_ERROR((AE_INFO,
253 "Could not disable %s events",
254 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400255 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 }
257
Len Brown4be44fc2005-08-05 00:44:28 -0400258 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Bob Moore83135242006-10-03 00:00:00 -0400261ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263/*******************************************************************************
264 *
265 * FUNCTION: acpi_clear_event
266 *
Bob Mooreba494be2012-07-12 09:40:10 +0800267 * PARAMETERS: event - The fixed event to be cleared
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 *
269 * RETURN: Status
270 *
271 * DESCRIPTION: Clear an ACPI event (fixed)
272 *
273 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400274acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
Len Brown4be44fc2005-08-05 00:44:28 -0400276 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Bob Mooreb229cf92006-04-21 17:15:00 -0400278 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280 /* Decode the Fixed Event */
281
282 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400283 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 }
285
286 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800287 * Clear the requested fixed event (By writing a one to the status
288 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 */
Len Brown4be44fc2005-08-05 00:44:28 -0400290 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800291 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800292 status_register_id, ACPI_CLEAR_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Len Brown4be44fc2005-08-05 00:44:28 -0400294 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Bob Moore83135242006-10-03 00:00:00 -0400297ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299/*******************************************************************************
300 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 * FUNCTION: acpi_get_event_status
302 *
Bob Mooreba494be2012-07-12 09:40:10 +0800303 * PARAMETERS: event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400304 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 * be returned
306 *
307 * RETURN: Status
308 *
309 * DESCRIPTION: Obtains and returns the current status of the event
310 *
311 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400312acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Len Brown4be44fc2005-08-05 00:44:28 -0400314 acpi_status status = AE_OK;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800315 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Bob Mooreb229cf92006-04-21 17:15:00 -0400317 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400320 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 }
322
323 /* Decode the Fixed Event */
324
325 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400326 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
328
329 /* Get the status of the requested fixed event */
330
Len Brown4be44fc2005-08-05 00:44:28 -0400331 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800332 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800333 enable_register_id, &value);
334 if (ACPI_FAILURE(status))
335 return_ACPI_STATUS(status);
336
337 *event_status = value;
338
339 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800340 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800341 status_register_id, &value);
342 if (ACPI_FAILURE(status))
343 return_ACPI_STATUS(status);
344
345 if (value)
346 *event_status |= ACPI_EVENT_FLAG_SET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Zhang Ruied206fa2008-10-27 14:01:02 -0700348 if (acpi_gbl_fixed_event_handlers[event].handler)
349 *event_status |= ACPI_EVENT_FLAG_HANDLE;
350
Len Brown4be44fc2005-08-05 00:44:28 -0400351 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352}
353
Bob Moore83135242006-10-03 00:00:00 -0400354ACPI_EXPORT_SYMBOL(acpi_get_event_status)
Bob Moore33620c52012-02-14 18:14:27 +0800355#endif /* !ACPI_REDUCED_HARDWARE */