ACPICA: Update header files copyrights to 2012
[deliverable/linux.git] / drivers / acpi / acpica / evxfevnt.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4 *
5 *****************************************************************************/
6
7/*
77848130 8 * Copyright (C) 2000 - 2012, Intel Corp.
1da177e4
LT
9 * 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
214f2c90 44#include <linux/export.h>
1da177e4 45#include <acpi/acpi.h>
e2f7a777 46#include "accommon.h"
e2f7a777 47#include "actables.h"
1da177e4
LT
48
49#define _COMPONENT ACPI_EVENTS
4be44fcd 50ACPI_MODULE_NAME("evxfevnt")
1da177e4 51
33620c54 52#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
1da177e4
LT
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_enable
56 *
57 * PARAMETERS: None
58 *
59 * RETURN: Status
60 *
61 * DESCRIPTION: Transfers the system into ACPI mode.
62 *
63 ******************************************************************************/
e97d6bf1 64
4be44fcd 65acpi_status acpi_enable(void)
1da177e4 66{
b430acbd 67 acpi_status status;
3d695839 68 int retry;
1da177e4 69
b229cf92 70 ACPI_FUNCTION_TRACE(acpi_enable);
1da177e4 71
c857303a
BM
72 /* 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
1da177e4 80 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
4be44fcd
LB
81 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
82 "System is already in ACPI mode\n"));
b430acbd
LB
83 return_ACPI_STATUS(AE_OK);
84 }
1da177e4 85
b430acbd 86 /* Transition to ACPI mode */
1da177e4 87
b430acbd
LB
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
3d695839
LB
97 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 */
1da177e4
LT
105 }
106
3d695839
LB
107 ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
108 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
1da177e4
LT
109}
110
8313524a
BM
111ACPI_EXPORT_SYMBOL(acpi_enable)
112
1da177e4
LT
113/*******************************************************************************
114 *
115 * FUNCTION: acpi_disable
116 *
117 * PARAMETERS: None
118 *
119 * RETURN: Status
120 *
44f6c012 121 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
1da177e4
LT
122 *
123 ******************************************************************************/
4be44fcd 124acpi_status acpi_disable(void)
1da177e4 125{
4be44fcd 126 acpi_status status = AE_OK;
1da177e4 127
b229cf92 128 ACPI_FUNCTION_TRACE(acpi_disable);
1da177e4 129
1da177e4 130 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
4be44fcd
LB
131 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
132 "System is already in legacy (non-ACPI) mode\n"));
133 } else {
1da177e4
LT
134 /* Transition to LEGACY mode */
135
4be44fcd 136 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
1da177e4 137
4be44fcd 138 if (ACPI_FAILURE(status)) {
b8e4d893
BM
139 ACPI_ERROR((AE_INFO,
140 "Could not exit ACPI mode to legacy mode"));
4be44fcd 141 return_ACPI_STATUS(status);
1da177e4
LT
142 }
143
4be44fcd 144 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
1da177e4
LT
145 }
146
4be44fcd 147 return_ACPI_STATUS(status);
1da177e4
LT
148}
149
8313524a
BM
150ACPI_EXPORT_SYMBOL(acpi_disable)
151
1da177e4
LT
152/*******************************************************************************
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 ******************************************************************************/
4be44fcd 164acpi_status acpi_enable_event(u32 event, u32 flags)
1da177e4 165{
4be44fcd
LB
166 acpi_status status = AE_OK;
167 u32 value;
1da177e4 168
b229cf92 169 ACPI_FUNCTION_TRACE(acpi_enable_event);
1da177e4
LT
170
171 /* Decode the Fixed Event */
172
173 if (event > ACPI_EVENT_MAX) {
4be44fcd 174 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
175 }
176
177 /*
9f15fc66
BM
178 * Enable the requested fixed event (by writing a one to the enable
179 * register bit)
1da177e4 180 */
4be44fcd 181 status =
50ffba1b 182 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
768aaaf1 183 enable_register_id, ACPI_ENABLE_EVENT);
4be44fcd
LB
184 if (ACPI_FAILURE(status)) {
185 return_ACPI_STATUS(status);
1da177e4
LT
186 }
187
188 /* Make sure that the hardware responded */
189
4be44fcd 190 status =
50ffba1b
BM
191 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
192 enable_register_id, &value);
4be44fcd
LB
193 if (ACPI_FAILURE(status)) {
194 return_ACPI_STATUS(status);
1da177e4
LT
195 }
196
197 if (value != 1) {
b8e4d893
BM
198 ACPI_ERROR((AE_INFO,
199 "Could not enable %s event",
200 acpi_ut_get_event_name(event)));
4be44fcd 201 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
1da177e4
LT
202 }
203
4be44fcd 204 return_ACPI_STATUS(status);
1da177e4 205}
1da177e4 206
8313524a 207ACPI_EXPORT_SYMBOL(acpi_enable_event)
1da177e4 208
1da177e4
LT
209/*******************************************************************************
210 *
211 * 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 ******************************************************************************/
4be44fcd 221acpi_status acpi_disable_event(u32 event, u32 flags)
1da177e4 222{
4be44fcd
LB
223 acpi_status status = AE_OK;
224 u32 value;
1da177e4 225
b229cf92 226 ACPI_FUNCTION_TRACE(acpi_disable_event);
1da177e4
LT
227
228 /* Decode the Fixed Event */
229
230 if (event > ACPI_EVENT_MAX) {
4be44fcd 231 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
232 }
233
234 /*
9f15fc66
BM
235 * Disable the requested fixed event (by writing a zero to the enable
236 * register bit)
1da177e4 237 */
4be44fcd 238 status =
50ffba1b 239 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
768aaaf1 240 enable_register_id, ACPI_DISABLE_EVENT);
4be44fcd
LB
241 if (ACPI_FAILURE(status)) {
242 return_ACPI_STATUS(status);
1da177e4
LT
243 }
244
4be44fcd 245 status =
50ffba1b
BM
246 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
247 enable_register_id, &value);
4be44fcd
LB
248 if (ACPI_FAILURE(status)) {
249 return_ACPI_STATUS(status);
1da177e4
LT
250 }
251
252 if (value != 0) {
b8e4d893
BM
253 ACPI_ERROR((AE_INFO,
254 "Could not disable %s events",
255 acpi_ut_get_event_name(event)));
4be44fcd 256 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
1da177e4
LT
257 }
258
4be44fcd 259 return_ACPI_STATUS(status);
1da177e4 260}
1da177e4 261
8313524a 262ACPI_EXPORT_SYMBOL(acpi_disable_event)
1da177e4
LT
263
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 ******************************************************************************/
4be44fcd 275acpi_status acpi_clear_event(u32 event)
1da177e4 276{
4be44fcd 277 acpi_status status = AE_OK;
1da177e4 278
b229cf92 279 ACPI_FUNCTION_TRACE(acpi_clear_event);
1da177e4
LT
280
281 /* Decode the Fixed Event */
282
283 if (event > ACPI_EVENT_MAX) {
4be44fcd 284 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
285 }
286
287 /*
9f15fc66
BM
288 * Clear the requested fixed event (By writing a one to the status
289 * register bit)
1da177e4 290 */
4be44fcd 291 status =
50ffba1b 292 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
768aaaf1 293 status_register_id, ACPI_CLEAR_STATUS);
1da177e4 294
4be44fcd 295 return_ACPI_STATUS(status);
1da177e4 296}
1da177e4 297
8313524a 298ACPI_EXPORT_SYMBOL(acpi_clear_event)
1da177e4 299
1da177e4
LT
300/*******************************************************************************
301 *
302 * FUNCTION: acpi_get_event_status
303 *
304 * PARAMETERS: Event - The fixed event
44f6c012 305 * event_status - Where the current status of the event will
1da177e4
LT
306 * be returned
307 *
308 * RETURN: Status
309 *
310 * DESCRIPTION: Obtains and returns the current status of the event
311 *
312 ******************************************************************************/
4be44fcd 313acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
1da177e4 314{
4be44fcd 315 acpi_status status = AE_OK;
71b58cbb 316 u32 value;
1da177e4 317
b229cf92 318 ACPI_FUNCTION_TRACE(acpi_get_event_status);
1da177e4
LT
319
320 if (!event_status) {
4be44fcd 321 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
322 }
323
324 /* Decode the Fixed Event */
325
326 if (event > ACPI_EVENT_MAX) {
4be44fcd 327 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
328 }
329
330 /* Get the status of the requested fixed event */
331
4be44fcd 332 status =
50ffba1b 333 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
71b58cbb
ZR
334 enable_register_id, &value);
335 if (ACPI_FAILURE(status))
336 return_ACPI_STATUS(status);
337
338 *event_status = value;
339
340 status =
50ffba1b 341 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
71b58cbb
ZR
342 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;
1da177e4 348
ed206fac
ZR
349 if (acpi_gbl_fixed_event_handlers[event].handler)
350 *event_status |= ACPI_EVENT_FLAG_HANDLE;
351
4be44fcd 352 return_ACPI_STATUS(status);
1da177e4
LT
353}
354
8313524a 355ACPI_EXPORT_SYMBOL(acpi_get_event_status)
33620c54 356#endif /* !ACPI_REDUCED_HARDWARE */
This page took 0.511086 seconds and 5 git commands to generate.