Merge tag 'devicetree-for-linus' of git://git.secretlab.ca/git/linux
[linux-2.6.git] / drivers / acpi / acpica / evxfevnt.c
blob7039606a0ba8c3a4753cd3aa4703f38b77c7358e
1 /******************************************************************************
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include <linux/export.h>
45 #include <acpi/acpi.h>
46 #include "accommon.h"
47 #include "actables.h"
49 #define _COMPONENT ACPI_EVENTS
50 ACPI_MODULE_NAME("evxfevnt")
52 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
53 /*******************************************************************************
55 * FUNCTION: acpi_enable
57 * PARAMETERS: None
59 * RETURN: Status
61 * DESCRIPTION: Transfers the system into ACPI mode.
63 ******************************************************************************/
64 acpi_status acpi_enable(void)
66 acpi_status status;
67 int retry;
69 ACPI_FUNCTION_TRACE(acpi_enable);
71 /* ACPI tables must be present */
73 if (!acpi_tb_tables_loaded()) {
74 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
77 /* If the Hardware Reduced flag is set, machine is always in acpi mode */
79 if (acpi_gbl_reduced_hardware) {
80 return_ACPI_STATUS(AE_OK);
83 /* Check current mode */
85 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
86 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
87 "System is already in ACPI mode\n"));
88 return_ACPI_STATUS(AE_OK);
91 /* Transition to ACPI mode */
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);
100 /* Sanity check that transition succeeded */
102 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);
109 acpi_os_stall(100); /* 100 usec */
112 ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
113 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
116 ACPI_EXPORT_SYMBOL(acpi_enable)
118 /*******************************************************************************
120 * FUNCTION: acpi_disable
122 * PARAMETERS: None
124 * RETURN: Status
126 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
128 ******************************************************************************/
129 acpi_status acpi_disable(void)
131 acpi_status status = AE_OK;
133 ACPI_FUNCTION_TRACE(acpi_disable);
135 /* If the Hardware Reduced flag is set, machine is always in acpi mode */
137 if (acpi_gbl_reduced_hardware) {
138 return_ACPI_STATUS(AE_OK);
141 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
142 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
143 "System is already in legacy (non-ACPI) mode\n"));
144 } else {
145 /* Transition to LEGACY mode */
147 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
149 if (ACPI_FAILURE(status)) {
150 ACPI_ERROR((AE_INFO,
151 "Could not exit ACPI mode to legacy mode"));
152 return_ACPI_STATUS(status);
155 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
158 return_ACPI_STATUS(status);
161 ACPI_EXPORT_SYMBOL(acpi_disable)
163 /*******************************************************************************
165 * FUNCTION: acpi_enable_event
167 * PARAMETERS: event - The fixed eventto be enabled
168 * flags - Reserved
170 * RETURN: Status
172 * DESCRIPTION: Enable an ACPI event (fixed)
174 ******************************************************************************/
175 acpi_status acpi_enable_event(u32 event, u32 flags)
177 acpi_status status = AE_OK;
178 u32 value;
180 ACPI_FUNCTION_TRACE(acpi_enable_event);
182 /* Decode the Fixed Event */
184 if (event > ACPI_EVENT_MAX) {
185 return_ACPI_STATUS(AE_BAD_PARAMETER);
189 * Enable the requested fixed event (by writing a one to the enable
190 * register bit)
192 status =
193 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
194 enable_register_id, ACPI_ENABLE_EVENT);
195 if (ACPI_FAILURE(status)) {
196 return_ACPI_STATUS(status);
199 /* Make sure that the hardware responded */
201 status =
202 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
203 enable_register_id, &value);
204 if (ACPI_FAILURE(status)) {
205 return_ACPI_STATUS(status);
208 if (value != 1) {
209 ACPI_ERROR((AE_INFO,
210 "Could not enable %s event",
211 acpi_ut_get_event_name(event)));
212 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
215 return_ACPI_STATUS(status);
218 ACPI_EXPORT_SYMBOL(acpi_enable_event)
220 /*******************************************************************************
222 * FUNCTION: acpi_disable_event
224 * PARAMETERS: event - The fixed event to be disabled
225 * flags - Reserved
227 * RETURN: Status
229 * DESCRIPTION: Disable an ACPI event (fixed)
231 ******************************************************************************/
232 acpi_status acpi_disable_event(u32 event, u32 flags)
234 acpi_status status = AE_OK;
235 u32 value;
237 ACPI_FUNCTION_TRACE(acpi_disable_event);
239 /* Decode the Fixed Event */
241 if (event > ACPI_EVENT_MAX) {
242 return_ACPI_STATUS(AE_BAD_PARAMETER);
246 * Disable the requested fixed event (by writing a zero to the enable
247 * register bit)
249 status =
250 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
251 enable_register_id, ACPI_DISABLE_EVENT);
252 if (ACPI_FAILURE(status)) {
253 return_ACPI_STATUS(status);
256 status =
257 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
258 enable_register_id, &value);
259 if (ACPI_FAILURE(status)) {
260 return_ACPI_STATUS(status);
263 if (value != 0) {
264 ACPI_ERROR((AE_INFO,
265 "Could not disable %s events",
266 acpi_ut_get_event_name(event)));
267 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
270 return_ACPI_STATUS(status);
273 ACPI_EXPORT_SYMBOL(acpi_disable_event)
275 /*******************************************************************************
277 * FUNCTION: acpi_clear_event
279 * PARAMETERS: event - The fixed event to be cleared
281 * RETURN: Status
283 * DESCRIPTION: Clear an ACPI event (fixed)
285 ******************************************************************************/
286 acpi_status acpi_clear_event(u32 event)
288 acpi_status status = AE_OK;
290 ACPI_FUNCTION_TRACE(acpi_clear_event);
292 /* Decode the Fixed Event */
294 if (event > ACPI_EVENT_MAX) {
295 return_ACPI_STATUS(AE_BAD_PARAMETER);
299 * Clear the requested fixed event (By writing a one to the status
300 * register bit)
302 status =
303 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
304 status_register_id, ACPI_CLEAR_STATUS);
306 return_ACPI_STATUS(status);
309 ACPI_EXPORT_SYMBOL(acpi_clear_event)
311 /*******************************************************************************
313 * FUNCTION: acpi_get_event_status
315 * PARAMETERS: event - The fixed event
316 * event_status - Where the current status of the event will
317 * be returned
319 * RETURN: Status
321 * DESCRIPTION: Obtains and returns the current status of the event
323 ******************************************************************************/
324 acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
326 acpi_status status = AE_OK;
327 u32 value;
329 ACPI_FUNCTION_TRACE(acpi_get_event_status);
331 if (!event_status) {
332 return_ACPI_STATUS(AE_BAD_PARAMETER);
335 /* Decode the Fixed Event */
337 if (event > ACPI_EVENT_MAX) {
338 return_ACPI_STATUS(AE_BAD_PARAMETER);
341 /* Get the status of the requested fixed event */
343 status =
344 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
345 enable_register_id, &value);
346 if (ACPI_FAILURE(status))
347 return_ACPI_STATUS(status);
349 *event_status = value;
351 status =
352 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
353 status_register_id, &value);
354 if (ACPI_FAILURE(status))
355 return_ACPI_STATUS(status);
357 if (value)
358 *event_status |= ACPI_EVENT_FLAG_SET;
360 if (acpi_gbl_fixed_event_handlers[event].handler)
361 *event_status |= ACPI_EVENT_FLAG_HANDLE;
363 return_ACPI_STATUS(status);
366 ACPI_EXPORT_SYMBOL(acpi_get_event_status)
367 #endif /* !ACPI_REDUCED_HARDWARE */