]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/acpi/acpica/evxfevnt.c
arm: imx6: defconfig: update tx6 defconfigs
[karo-tx-linux.git] / drivers / acpi / acpica / evxfevnt.c
1 /******************************************************************************
2  *
3  * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2013, Intel Corp.
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
44 #include <linux/export.h>
45 #include <acpi/acpi.h>
46 #include "accommon.h"
47 #include "actables.h"
48
49 #define _COMPONENT          ACPI_EVENTS
50 ACPI_MODULE_NAME("evxfevnt")
51
52 #if (!ACPI_REDUCED_HARDWARE)    /* Entire module */
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  ******************************************************************************/
64 acpi_status acpi_enable(void)
65 {
66         acpi_status status;
67         int retry;
68
69         ACPI_FUNCTION_TRACE(acpi_enable);
70
71         /* ACPI tables must be present */
72
73         if (!acpi_tb_tables_loaded()) {
74                 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
75         }
76
77         /* 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
83         /* Check current mode */
84
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);
89         }
90
91         /* 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
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);
108                 }
109                 acpi_os_stall(100);     /* 100 usec */
110         }
111
112         ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
113         return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
114 }
115
116 ACPI_EXPORT_SYMBOL(acpi_enable)
117
118 /*******************************************************************************
119  *
120  * FUNCTION:    acpi_disable
121  *
122  * PARAMETERS:  None
123  *
124  * RETURN:      Status
125  *
126  * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
127  *
128  ******************************************************************************/
129 acpi_status acpi_disable(void)
130 {
131         acpi_status status = AE_OK;
132
133         ACPI_FUNCTION_TRACE(acpi_disable);
134
135         /* 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
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 */
146
147                 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
148
149                 if (ACPI_FAILURE(status)) {
150                         ACPI_ERROR((AE_INFO,
151                                     "Could not exit ACPI mode to legacy mode"));
152                         return_ACPI_STATUS(status);
153                 }
154
155                 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
156         }
157
158         return_ACPI_STATUS(status);
159 }
160
161 ACPI_EXPORT_SYMBOL(acpi_disable)
162
163 /*******************************************************************************
164  *
165  * FUNCTION:    acpi_enable_event
166  *
167  * PARAMETERS:  event           - The fixed eventto be enabled
168  *              flags           - Reserved
169  *
170  * RETURN:      Status
171  *
172  * DESCRIPTION: Enable an ACPI event (fixed)
173  *
174  ******************************************************************************/
175 acpi_status acpi_enable_event(u32 event, u32 flags)
176 {
177         acpi_status status = AE_OK;
178         u32 value;
179
180         ACPI_FUNCTION_TRACE(acpi_enable_event);
181
182         /* Decode the Fixed Event */
183
184         if (event > ACPI_EVENT_MAX) {
185                 return_ACPI_STATUS(AE_BAD_PARAMETER);
186         }
187
188         /*
189          * Enable the requested fixed event (by writing a one to the enable
190          * register bit)
191          */
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);
197         }
198
199         /* Make sure that the hardware responded */
200
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);
206         }
207
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);
213         }
214
215         return_ACPI_STATUS(status);
216 }
217
218 ACPI_EXPORT_SYMBOL(acpi_enable_event)
219
220 /*******************************************************************************
221  *
222  * FUNCTION:    acpi_disable_event
223  *
224  * PARAMETERS:  event           - The fixed event to be disabled
225  *              flags           - Reserved
226  *
227  * RETURN:      Status
228  *
229  * DESCRIPTION: Disable an ACPI event (fixed)
230  *
231  ******************************************************************************/
232 acpi_status acpi_disable_event(u32 event, u32 flags)
233 {
234         acpi_status status = AE_OK;
235         u32 value;
236
237         ACPI_FUNCTION_TRACE(acpi_disable_event);
238
239         /* Decode the Fixed Event */
240
241         if (event > ACPI_EVENT_MAX) {
242                 return_ACPI_STATUS(AE_BAD_PARAMETER);
243         }
244
245         /*
246          * Disable the requested fixed event (by writing a zero to the enable
247          * register bit)
248          */
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);
254         }
255
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);
261         }
262
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);
268         }
269
270         return_ACPI_STATUS(status);
271 }
272
273 ACPI_EXPORT_SYMBOL(acpi_disable_event)
274
275 /*******************************************************************************
276  *
277  * FUNCTION:    acpi_clear_event
278  *
279  * PARAMETERS:  event           - The fixed event to be cleared
280  *
281  * RETURN:      Status
282  *
283  * DESCRIPTION: Clear an ACPI event (fixed)
284  *
285  ******************************************************************************/
286 acpi_status acpi_clear_event(u32 event)
287 {
288         acpi_status status = AE_OK;
289
290         ACPI_FUNCTION_TRACE(acpi_clear_event);
291
292         /* Decode the Fixed Event */
293
294         if (event > ACPI_EVENT_MAX) {
295                 return_ACPI_STATUS(AE_BAD_PARAMETER);
296         }
297
298         /*
299          * Clear the requested fixed event (By writing a one to the status
300          * register bit)
301          */
302         status =
303             acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
304                                     status_register_id, ACPI_CLEAR_STATUS);
305
306         return_ACPI_STATUS(status);
307 }
308
309 ACPI_EXPORT_SYMBOL(acpi_clear_event)
310
311 /*******************************************************************************
312  *
313  * FUNCTION:    acpi_get_event_status
314  *
315  * PARAMETERS:  event           - The fixed event
316  *              event_status    - Where the current status of the event will
317  *                                be returned
318  *
319  * RETURN:      Status
320  *
321  * DESCRIPTION: Obtains and returns the current status of the event
322  *
323  ******************************************************************************/
324 acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
325 {
326         acpi_status status = AE_OK;
327         u32 value;
328
329         ACPI_FUNCTION_TRACE(acpi_get_event_status);
330
331         if (!event_status) {
332                 return_ACPI_STATUS(AE_BAD_PARAMETER);
333         }
334
335         /* Decode the Fixed Event */
336
337         if (event > ACPI_EVENT_MAX) {
338                 return_ACPI_STATUS(AE_BAD_PARAMETER);
339         }
340
341         /* Get the status of the requested fixed event */
342
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);
348
349         *event_status = value;
350
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);
356
357         if (value)
358                 *event_status |= ACPI_EVENT_FLAG_SET;
359
360         if (acpi_gbl_fixed_event_handlers[event].handler)
361                 *event_status |= ACPI_EVENT_FLAG_HANDLE;
362
363         return_ACPI_STATUS(status);
364 }
365
366 ACPI_EXPORT_SYMBOL(acpi_get_event_status)
367 #endif                          /* !ACPI_REDUCED_HARDWARE */