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