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