ACPICA: Update local C library module comments for ASCII table
[deliverable/linux.git] / drivers / acpi / acpica / hwgpe.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
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
44#include <acpi/acpi.h>
e2f7a777
LB
45#include "accommon.h"
46#include "acevents.h"
1da177e4
LT
47
48#define _COMPONENT ACPI_HARDWARE
4be44fcd 49ACPI_MODULE_NAME("hwgpe")
33620c54 50#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
44f6c012 51/* Local prototypes */
44f6c012 52static acpi_status
4be44fcd 53acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
e97d6bf1
BM
54 struct acpi_gpe_block_info *gpe_block,
55 void *context);
1da177e4 56
e4e9a735
RW
57/******************************************************************************
58 *
b76df673 59 * FUNCTION: acpi_hw_get_gpe_register_bit
e4e9a735
RW
60 *
61 * PARAMETERS: gpe_event_info - Info block for the GPE
e4e9a735 62 *
da503373 63 * RETURN: Register mask with a one in the GPE bit position
e4e9a735 64 *
da503373
LM
65 * DESCRIPTION: Compute the register mask for this GPE. One bit is set in the
66 * correct position for the input GPE.
e4e9a735
RW
67 *
68 ******************************************************************************/
69
1d94e1e8 70u32 acpi_hw_get_gpe_register_bit(struct acpi_gpe_event_info *gpe_event_info)
e4e9a735
RW
71{
72 return (u32)1 << (gpe_event_info->gpe_number -
1d94e1e8 73 gpe_event_info->register_info->base_gpe_number);
e4e9a735
RW
74}
75
e38e8a07
BM
76/******************************************************************************
77 *
fd247447 78 * FUNCTION: acpi_hw_low_set_gpe
e38e8a07
BM
79 *
80 * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled
fd247447 81 * action - Enable or disable
e38e8a07
BM
82 *
83 * RETURN: Status
84 *
da503373 85 * DESCRIPTION: Enable or disable a single GPE in the parent enable register.
e38e8a07
BM
86 *
87 ******************************************************************************/
88
fd247447 89acpi_status
da503373 90acpi_hw_low_set_gpe(struct acpi_gpe_event_info *gpe_event_info, u32 action)
e38e8a07
BM
91{
92 struct acpi_gpe_register_info *gpe_register_info;
93 acpi_status status;
94 u32 enable_mask;
e4e9a735 95 u32 register_bit;
e38e8a07 96
fd247447
RW
97 ACPI_FUNCTION_ENTRY();
98
e38e8a07
BM
99 /* Get the info block for the entire GPE register */
100
101 gpe_register_info = gpe_event_info->register_info;
102 if (!gpe_register_info) {
103 return (AE_NOT_EXIST);
104 }
105
106 /* Get current value of the enable register that contains this GPE */
107
c6b5774c 108 status = acpi_hw_read(&enable_mask, &gpe_register_info->enable_address);
e38e8a07
BM
109 if (ACPI_FAILURE(status)) {
110 return (status);
111 }
112
da503373 113 /* Set or clear just the bit that corresponds to this GPE */
e38e8a07 114
1d94e1e8 115 register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
fd247447 116 switch (action) {
3a37898d 117 case ACPI_GPE_CONDITIONAL_ENABLE:
da503373
LM
118
119 /* Only enable if the enable_for_run bit is set */
120
121 if (!(register_bit & gpe_register_info->enable_for_run)) {
c9a8bbb7 122 return (AE_BAD_PARAMETER);
da503373
LM
123 }
124
125 /*lint -fallthrough */
c9a8bbb7 126
fd247447
RW
127 case ACPI_GPE_ENABLE:
128 ACPI_SET_BIT(enable_mask, register_bit);
129 break;
130
131 case ACPI_GPE_DISABLE:
132 ACPI_CLEAR_BIT(enable_mask, register_bit);
133 break;
134
135 default:
da503373 136 ACPI_ERROR((AE_INFO, "Invalid GPE Action, %u\n", action));
fd247447
RW
137 return (AE_BAD_PARAMETER);
138 }
e38e8a07
BM
139
140 /* Write the updated enable mask */
141
c6b5774c 142 status = acpi_hw_write(enable_mask, &gpe_register_info->enable_address);
e38e8a07
BM
143 return (status);
144}
145
1da177e4
LT
146/******************************************************************************
147 *
148 * FUNCTION: acpi_hw_clear_gpe
149 *
150 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
151 *
152 * RETURN: Status
153 *
154 * DESCRIPTION: Clear the status bit for a single GPE.
155 *
156 ******************************************************************************/
157
4be44fcd 158acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
1da177e4 159{
e4e9a735 160 struct acpi_gpe_register_info *gpe_register_info;
4be44fcd 161 acpi_status status;
e4e9a735 162 u32 register_bit;
1da177e4 163
4be44fcd 164 ACPI_FUNCTION_ENTRY();
1da177e4 165
e4e9a735
RW
166 /* Get the info block for the entire GPE register */
167
168 gpe_register_info = gpe_event_info->register_info;
169 if (!gpe_register_info) {
170 return (AE_NOT_EXIST);
171 }
172
1da177e4
LT
173 /*
174 * Write a one to the appropriate bit in the status register to
175 * clear this GPE.
176 */
1d94e1e8 177 register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
da503373 178
c6b5774c 179 status = acpi_hw_write(register_bit,
e4e9a735 180 &gpe_register_info->status_address);
1da177e4
LT
181
182 return (status);
183}
184
1da177e4
LT
185/******************************************************************************
186 *
187 * FUNCTION: acpi_hw_get_gpe_status
188 *
189 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
190 * event_status - Where the GPE status is returned
191 *
192 * RETURN: Status
193 *
194 * DESCRIPTION: Return the status of a single GPE.
195 *
196 ******************************************************************************/
44f6c012 197
1da177e4 198acpi_status
4be44fcd
LB
199acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
200 acpi_event_status * event_status)
1da177e4 201{
4be44fcd 202 u32 in_byte;
e4e9a735 203 u32 register_bit;
4be44fcd 204 struct acpi_gpe_register_info *gpe_register_info;
4be44fcd 205 acpi_event_status local_event_status = 0;
da503373 206 acpi_status status;
1da177e4 207
4be44fcd 208 ACPI_FUNCTION_ENTRY();
1da177e4
LT
209
210 if (!event_status) {
211 return (AE_BAD_PARAMETER);
212 }
213
214 /* Get the info block for the entire GPE register */
215
216 gpe_register_info = gpe_event_info->register_info;
217
218 /* Get the register bitmask for this GPE */
219
1d94e1e8 220 register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
1da177e4
LT
221
222 /* GPE currently enabled? (enabled for runtime?) */
223
224 if (register_bit & gpe_register_info->enable_for_run) {
225 local_event_status |= ACPI_EVENT_FLAG_ENABLED;
226 }
227
228 /* GPE enabled for wake? */
229
230 if (register_bit & gpe_register_info->enable_for_wake) {
231 local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
232 }
233
234 /* GPE currently active (status bit == 1)? */
235
c6b5774c 236 status = acpi_hw_read(&in_byte, &gpe_register_info->status_address);
4be44fcd 237 if (ACPI_FAILURE(status)) {
2147d3f0 238 return (status);
1da177e4
LT
239 }
240
241 if (register_bit & in_byte) {
242 local_event_status |= ACPI_EVENT_FLAG_SET;
243 }
244
245 /* Set return value */
246
247 (*event_status) = local_event_status;
2147d3f0 248 return (AE_OK);
1da177e4 249}
1da177e4
LT
250
251/******************************************************************************
252 *
253 * FUNCTION: acpi_hw_disable_gpe_block
254 *
255 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
256 * gpe_block - Gpe Block info
257 *
258 * RETURN: Status
259 *
44f6c012 260 * DESCRIPTION: Disable all GPEs within a single GPE block
1da177e4
LT
261 *
262 ******************************************************************************/
263
264acpi_status
e97d6bf1
BM
265acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
266 struct acpi_gpe_block_info *gpe_block, void *context)
1da177e4 267{
4be44fcd
LB
268 u32 i;
269 acpi_status status;
1da177e4
LT
270
271 /* Examine each GPE Register within the block */
272
273 for (i = 0; i < gpe_block->register_count; i++) {
52fc0b02 274
1da177e4
LT
275 /* Disable all GPEs in this register */
276
ecfbbc7b 277 status =
c6b5774c
BM
278 acpi_hw_write(0x00,
279 &gpe_block->register_info[i].enable_address);
4be44fcd 280 if (ACPI_FAILURE(status)) {
1da177e4
LT
281 return (status);
282 }
283 }
284
285 return (AE_OK);
286}
287
1da177e4
LT
288/******************************************************************************
289 *
290 * FUNCTION: acpi_hw_clear_gpe_block
291 *
292 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
293 * gpe_block - Gpe Block info
294 *
295 * RETURN: Status
296 *
44f6c012 297 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
1da177e4
LT
298 *
299 ******************************************************************************/
300
301acpi_status
e97d6bf1
BM
302acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
303 struct acpi_gpe_block_info *gpe_block, void *context)
1da177e4 304{
4be44fcd
LB
305 u32 i;
306 acpi_status status;
1da177e4
LT
307
308 /* Examine each GPE Register within the block */
309
310 for (i = 0; i < gpe_block->register_count; i++) {
52fc0b02 311
1da177e4
LT
312 /* Clear status on all GPEs in this register */
313
ecfbbc7b 314 status =
c6b5774c
BM
315 acpi_hw_write(0xFF,
316 &gpe_block->register_info[i].status_address);
4be44fcd 317 if (ACPI_FAILURE(status)) {
1da177e4
LT
318 return (status);
319 }
320 }
321
322 return (AE_OK);
323}
324
1da177e4
LT
325/******************************************************************************
326 *
327 * FUNCTION: acpi_hw_enable_runtime_gpe_block
328 *
329 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
330 * gpe_block - Gpe Block info
331 *
332 * RETURN: Status
333 *
44f6c012
RM
334 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
335 * combination wake/run GPEs.
1da177e4
LT
336 *
337 ******************************************************************************/
338
339acpi_status
e97d6bf1 340acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
1f86e8c1
LZ
341 struct acpi_gpe_block_info * gpe_block,
342 void *context)
1da177e4 343{
4be44fcd
LB
344 u32 i;
345 acpi_status status;
1da177e4
LT
346
347 /* NOTE: assumes that all GPEs are currently disabled */
348
349 /* Examine each GPE Register within the block */
350
351 for (i = 0; i < gpe_block->register_count; i++) {
352 if (!gpe_block->register_info[i].enable_for_run) {
353 continue;
354 }
355
356 /* Enable all "runtime" GPEs in this register */
357
c6b5774c
BM
358 status =
359 acpi_hw_write(gpe_block->register_info[i].enable_for_run,
360 &gpe_block->register_info[i].enable_address);
4be44fcd 361 if (ACPI_FAILURE(status)) {
1da177e4
LT
362 return (status);
363 }
364 }
365
366 return (AE_OK);
367}
368
1da177e4
LT
369/******************************************************************************
370 *
371 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
372 *
373 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
374 * gpe_block - Gpe Block info
375 *
376 * RETURN: Status
377 *
44f6c012
RM
378 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
379 * combination wake/run GPEs.
1da177e4
LT
380 *
381 ******************************************************************************/
382
44f6c012 383static acpi_status
4be44fcd 384acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
e97d6bf1
BM
385 struct acpi_gpe_block_info *gpe_block,
386 void *context)
1da177e4 387{
4be44fcd
LB
388 u32 i;
389 acpi_status status;
1da177e4
LT
390
391 /* Examine each GPE Register within the block */
392
393 for (i = 0; i < gpe_block->register_count; i++) {
394 if (!gpe_block->register_info[i].enable_for_wake) {
395 continue;
396 }
397
398 /* Enable all "wake" GPEs in this register */
399
c6b5774c
BM
400 status =
401 acpi_hw_write(gpe_block->register_info[i].enable_for_wake,
402 &gpe_block->register_info[i].enable_address);
4be44fcd 403 if (ACPI_FAILURE(status)) {
1da177e4
LT
404 return (status);
405 }
406 }
407
408 return (AE_OK);
409}
410
1da177e4
LT
411/******************************************************************************
412 *
413 * FUNCTION: acpi_hw_disable_all_gpes
414 *
73459f73 415 * PARAMETERS: None
1da177e4
LT
416 *
417 * RETURN: Status
418 *
44f6c012 419 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
1da177e4
LT
420 *
421 ******************************************************************************/
422
4be44fcd 423acpi_status acpi_hw_disable_all_gpes(void)
1da177e4 424{
4be44fcd 425 acpi_status status;
1da177e4 426
b229cf92 427 ACPI_FUNCTION_TRACE(hw_disable_all_gpes);
1da177e4 428
e97d6bf1
BM
429 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
430 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
4be44fcd 431 return_ACPI_STATUS(status);
1da177e4
LT
432}
433
1da177e4
LT
434/******************************************************************************
435 *
436 * FUNCTION: acpi_hw_enable_all_runtime_gpes
437 *
73459f73 438 * PARAMETERS: None
1da177e4
LT
439 *
440 * RETURN: Status
441 *
44f6c012 442 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
1da177e4
LT
443 *
444 ******************************************************************************/
445
4be44fcd 446acpi_status acpi_hw_enable_all_runtime_gpes(void)
1da177e4 447{
4be44fcd 448 acpi_status status;
1da177e4 449
b229cf92 450 ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes);
1da177e4 451
e97d6bf1 452 status = acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block, NULL);
4be44fcd 453 return_ACPI_STATUS(status);
1da177e4
LT
454}
455
1da177e4
LT
456/******************************************************************************
457 *
458 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
459 *
73459f73 460 * PARAMETERS: None
1da177e4
LT
461 *
462 * RETURN: Status
463 *
44f6c012 464 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
1da177e4
LT
465 *
466 ******************************************************************************/
467
4be44fcd 468acpi_status acpi_hw_enable_all_wakeup_gpes(void)
1da177e4 469{
4be44fcd 470 acpi_status status;
1da177e4 471
b229cf92 472 ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes);
1da177e4 473
e97d6bf1 474 status = acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block, NULL);
4be44fcd 475 return_ACPI_STATUS(status);
1da177e4 476}
33620c54
BM
477
478#endif /* !ACPI_REDUCED_HARDWARE */
This page took 0.535258 seconds and 5 git commands to generate.