drivers: power: report battery voltage in AOSP compatible format
[GitHub/mt8127/android_kernel_alcatel_ttab.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/*
25f044e6 8 * Copyright (C) 2000 - 2013, 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 ******************************************************************************/
4be44fcd 64acpi_status acpi_enable(void)
1da177e4 65{
b430acbd 66 acpi_status status;
3d695839 67 int retry;
1da177e4 68
b229cf92 69 ACPI_FUNCTION_TRACE(acpi_enable);
1da177e4 70
c857303a
BM
71 /* ACPI tables must be present */
72
73 if (!acpi_tb_tables_loaded()) {
74 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
75 }
76
c39660b2
BM
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
c857303a
BM
83 /* Check current mode */
84
1da177e4 85 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
4be44fcd
LB
86 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
87 "System is already in ACPI mode\n"));
b430acbd
LB
88 return_ACPI_STATUS(AE_OK);
89 }
1da177e4 90
b430acbd 91 /* Transition to ACPI mode */
1da177e4 92
b430acbd
LB
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
3d695839
LB
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 */
1da177e4
LT
110 }
111
3d695839
LB
112 ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
113 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
1da177e4
LT
114}
115
8313524a
BM
116ACPI_EXPORT_SYMBOL(acpi_enable)
117
1da177e4
LT
118/*******************************************************************************
119 *
120 * FUNCTION: acpi_disable
121 *
122 * PARAMETERS: None
123 *
124 * RETURN: Status
125 *
44f6c012 126 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
1da177e4
LT
127 *
128 ******************************************************************************/
4be44fcd 129acpi_status acpi_disable(void)
1da177e4 130{
4be44fcd 131 acpi_status status = AE_OK;
1da177e4 132
b229cf92 133 ACPI_FUNCTION_TRACE(acpi_disable);
1da177e4 134
c39660b2
BM
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
1da177e4 141 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
4be44fcd
LB
142 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
143 "System is already in legacy (non-ACPI) mode\n"));
144 } else {
1da177e4
LT
145 /* Transition to LEGACY mode */
146
4be44fcd 147 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
1da177e4 148
4be44fcd 149 if (ACPI_FAILURE(status)) {
b8e4d893
BM
150 ACPI_ERROR((AE_INFO,
151 "Could not exit ACPI mode to legacy mode"));
4be44fcd 152 return_ACPI_STATUS(status);
1da177e4
LT
153 }
154
4be44fcd 155 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
1da177e4
LT
156 }
157
4be44fcd 158 return_ACPI_STATUS(status);
1da177e4
LT
159}
160
8313524a
BM
161ACPI_EXPORT_SYMBOL(acpi_disable)
162
1da177e4
LT
163/*******************************************************************************
164 *
165 * FUNCTION: acpi_enable_event
166 *
ba494bee
BM
167 * PARAMETERS: event - The fixed eventto be enabled
168 * flags - Reserved
1da177e4
LT
169 *
170 * RETURN: Status
171 *
172 * DESCRIPTION: Enable an ACPI event (fixed)
173 *
174 ******************************************************************************/
4be44fcd 175acpi_status acpi_enable_event(u32 event, u32 flags)
1da177e4 176{
4be44fcd
LB
177 acpi_status status = AE_OK;
178 u32 value;
1da177e4 179
b229cf92 180 ACPI_FUNCTION_TRACE(acpi_enable_event);
1da177e4
LT
181
182 /* Decode the Fixed Event */
183
184 if (event > ACPI_EVENT_MAX) {
4be44fcd 185 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
186 }
187
188 /*
9f15fc66
BM
189 * Enable the requested fixed event (by writing a one to the enable
190 * register bit)
1da177e4 191 */
4be44fcd 192 status =
50ffba1b 193 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
768aaaf1 194 enable_register_id, ACPI_ENABLE_EVENT);
4be44fcd
LB
195 if (ACPI_FAILURE(status)) {
196 return_ACPI_STATUS(status);
1da177e4
LT
197 }
198
199 /* Make sure that the hardware responded */
200
4be44fcd 201 status =
50ffba1b
BM
202 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
203 enable_register_id, &value);
4be44fcd
LB
204 if (ACPI_FAILURE(status)) {
205 return_ACPI_STATUS(status);
1da177e4
LT
206 }
207
208 if (value != 1) {
b8e4d893
BM
209 ACPI_ERROR((AE_INFO,
210 "Could not enable %s event",
211 acpi_ut_get_event_name(event)));
4be44fcd 212 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
1da177e4
LT
213 }
214
4be44fcd 215 return_ACPI_STATUS(status);
1da177e4 216}
1da177e4 217
8313524a 218ACPI_EXPORT_SYMBOL(acpi_enable_event)
1da177e4 219
1da177e4
LT
220/*******************************************************************************
221 *
222 * FUNCTION: acpi_disable_event
223 *
75c8044f
LZ
224 * PARAMETERS: event - The fixed event to be disabled
225 * flags - Reserved
1da177e4
LT
226 *
227 * RETURN: Status
228 *
229 * DESCRIPTION: Disable an ACPI event (fixed)
230 *
231 ******************************************************************************/
4be44fcd 232acpi_status acpi_disable_event(u32 event, u32 flags)
1da177e4 233{
4be44fcd
LB
234 acpi_status status = AE_OK;
235 u32 value;
1da177e4 236
b229cf92 237 ACPI_FUNCTION_TRACE(acpi_disable_event);
1da177e4
LT
238
239 /* Decode the Fixed Event */
240
241 if (event > ACPI_EVENT_MAX) {
4be44fcd 242 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
243 }
244
245 /*
9f15fc66
BM
246 * Disable the requested fixed event (by writing a zero to the enable
247 * register bit)
1da177e4 248 */
4be44fcd 249 status =
50ffba1b 250 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
768aaaf1 251 enable_register_id, ACPI_DISABLE_EVENT);
4be44fcd
LB
252 if (ACPI_FAILURE(status)) {
253 return_ACPI_STATUS(status);
1da177e4
LT
254 }
255
4be44fcd 256 status =
50ffba1b
BM
257 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
258 enable_register_id, &value);
4be44fcd
LB
259 if (ACPI_FAILURE(status)) {
260 return_ACPI_STATUS(status);
1da177e4
LT
261 }
262
263 if (value != 0) {
b8e4d893
BM
264 ACPI_ERROR((AE_INFO,
265 "Could not disable %s events",
266 acpi_ut_get_event_name(event)));
4be44fcd 267 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
1da177e4
LT
268 }
269
4be44fcd 270 return_ACPI_STATUS(status);
1da177e4 271}
1da177e4 272
8313524a 273ACPI_EXPORT_SYMBOL(acpi_disable_event)
1da177e4
LT
274
275/*******************************************************************************
276 *
277 * FUNCTION: acpi_clear_event
278 *
ba494bee 279 * PARAMETERS: event - The fixed event to be cleared
1da177e4
LT
280 *
281 * RETURN: Status
282 *
283 * DESCRIPTION: Clear an ACPI event (fixed)
284 *
285 ******************************************************************************/
4be44fcd 286acpi_status acpi_clear_event(u32 event)
1da177e4 287{
4be44fcd 288 acpi_status status = AE_OK;
1da177e4 289
b229cf92 290 ACPI_FUNCTION_TRACE(acpi_clear_event);
1da177e4
LT
291
292 /* Decode the Fixed Event */
293
294 if (event > ACPI_EVENT_MAX) {
4be44fcd 295 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
296 }
297
298 /*
9f15fc66
BM
299 * Clear the requested fixed event (By writing a one to the status
300 * register bit)
1da177e4 301 */
4be44fcd 302 status =
50ffba1b 303 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
768aaaf1 304 status_register_id, ACPI_CLEAR_STATUS);
1da177e4 305
4be44fcd 306 return_ACPI_STATUS(status);
1da177e4 307}
1da177e4 308
8313524a 309ACPI_EXPORT_SYMBOL(acpi_clear_event)
1da177e4 310
1da177e4
LT
311/*******************************************************************************
312 *
313 * FUNCTION: acpi_get_event_status
314 *
ba494bee 315 * PARAMETERS: event - The fixed event
44f6c012 316 * event_status - Where the current status of the event will
1da177e4
LT
317 * be returned
318 *
319 * RETURN: Status
320 *
321 * DESCRIPTION: Obtains and returns the current status of the event
322 *
323 ******************************************************************************/
4be44fcd 324acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
1da177e4 325{
4be44fcd 326 acpi_status status = AE_OK;
71b58cbb 327 u32 value;
1da177e4 328
b229cf92 329 ACPI_FUNCTION_TRACE(acpi_get_event_status);
1da177e4
LT
330
331 if (!event_status) {
4be44fcd 332 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
333 }
334
335 /* Decode the Fixed Event */
336
337 if (event > ACPI_EVENT_MAX) {
4be44fcd 338 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
339 }
340
341 /* Get the status of the requested fixed event */
342
4be44fcd 343 status =
50ffba1b 344 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
71b58cbb
ZR
345 enable_register_id, &value);
346 if (ACPI_FAILURE(status))
347 return_ACPI_STATUS(status);
348
349 *event_status = value;
350
351 status =
50ffba1b 352 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
71b58cbb
ZR
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;
1da177e4 359
ed206fac
ZR
360 if (acpi_gbl_fixed_event_handlers[event].handler)
361 *event_status |= ACPI_EVENT_FLAG_HANDLE;
362
4be44fcd 363 return_ACPI_STATUS(status);
1da177e4
LT
364}
365
8313524a 366ACPI_EXPORT_SYMBOL(acpi_get_event_status)
33620c54 367#endif /* !ACPI_REDUCED_HARDWARE */