]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/acpi/acpica/hwgpe.c
Merge branch 'for-linus' of git://oss.sgi.com/xfs/xfs
[net-next-2.6.git] / drivers / acpi / acpica / hwgpe.c
CommitLineData
1da177e4
LT
1
2/******************************************************************************
3 *
4 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
5 *
6 *****************************************************************************/
7
8/*
a8357b0c 9 * Copyright (C) 2000 - 2010, Intel Corp.
1da177e4
LT
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
e2f7a777
LB
46#include "accommon.h"
47#include "acevents.h"
1da177e4
LT
48
49#define _COMPONENT ACPI_HARDWARE
4be44fcd 50ACPI_MODULE_NAME("hwgpe")
1da177e4 51
44f6c012 52/* Local prototypes */
44f6c012 53static acpi_status
4be44fcd 54acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
e97d6bf1
BM
55 struct acpi_gpe_block_info *gpe_block,
56 void *context);
1da177e4 57
e4e9a735
RW
58/******************************************************************************
59 *
60 * FUNCTION: acpi_hw_gpe_register_bit
61 *
62 * PARAMETERS: gpe_event_info - Info block for the GPE
63 * gpe_register_info - Info block for the GPE register
64 *
65 * RETURN: Status
66 *
67 * DESCRIPTION: Compute GPE enable mask with one bit corresponding to the given
68 * GPE set.
69 *
70 ******************************************************************************/
71
72u32 acpi_hw_gpe_register_bit(struct acpi_gpe_event_info *gpe_event_info,
73 struct acpi_gpe_register_info *gpe_register_info)
74{
75 return (u32)1 << (gpe_event_info->gpe_number -
76 gpe_register_info->base_gpe_number);
77}
78
e38e8a07
BM
79/******************************************************************************
80 *
fd247447 81 * FUNCTION: acpi_hw_low_set_gpe
e38e8a07
BM
82 *
83 * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled
fd247447 84 * action - Enable or disable
e38e8a07
BM
85 *
86 * RETURN: Status
87 *
fd247447 88 * DESCRIPTION: Enable or disable a single GPE in its enable register.
e38e8a07
BM
89 *
90 ******************************************************************************/
91
fd247447
RW
92acpi_status
93acpi_hw_low_set_gpe(struct acpi_gpe_event_info *gpe_event_info, u8 action)
e38e8a07
BM
94{
95 struct acpi_gpe_register_info *gpe_register_info;
96 acpi_status status;
97 u32 enable_mask;
e4e9a735 98 u32 register_bit;
e38e8a07 99
fd247447
RW
100 ACPI_FUNCTION_ENTRY();
101
e38e8a07
BM
102 /* Get the info block for the entire GPE register */
103
104 gpe_register_info = gpe_event_info->register_info;
105 if (!gpe_register_info) {
106 return (AE_NOT_EXIST);
107 }
108
109 /* Get current value of the enable register that contains this GPE */
110
c6b5774c 111 status = acpi_hw_read(&enable_mask, &gpe_register_info->enable_address);
e38e8a07
BM
112 if (ACPI_FAILURE(status)) {
113 return (status);
114 }
115
fd247447 116 /* Set ot clear just the bit that corresponds to this GPE */
e38e8a07 117
e4e9a735
RW
118 register_bit = acpi_hw_gpe_register_bit(gpe_event_info,
119 gpe_register_info);
fd247447 120 switch (action) {
c9a8bbb7
RW
121 case ACPI_GPE_COND_ENABLE:
122 if (!(register_bit & gpe_register_info->enable_for_run))
123 return (AE_BAD_PARAMETER);
124
fd247447
RW
125 case ACPI_GPE_ENABLE:
126 ACPI_SET_BIT(enable_mask, register_bit);
127 break;
128
129 case ACPI_GPE_DISABLE:
130 ACPI_CLEAR_BIT(enable_mask, register_bit);
131 break;
132
133 default:
134 ACPI_ERROR((AE_INFO, "Invalid action\n"));
135 return (AE_BAD_PARAMETER);
136 }
e38e8a07
BM
137
138 /* Write the updated enable mask */
139
c6b5774c 140 status = acpi_hw_write(enable_mask, &gpe_register_info->enable_address);
e38e8a07
BM
141 return (status);
142}
143
1da177e4
LT
144/******************************************************************************
145 *
146 * FUNCTION: acpi_hw_write_gpe_enable_reg
147 *
148 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
149 *
150 * RETURN: Status
151 *
152 * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
153 * already be cleared or set in the parent register
154 * enable_for_run mask.
155 *
156 ******************************************************************************/
157
158acpi_status
e38e8a07 159acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info * gpe_event_info)
1da177e4 160{
4be44fcd 161 acpi_status status;
1da177e4 162
4be44fcd 163 ACPI_FUNCTION_ENTRY();
1da177e4 164
c9a8bbb7 165 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_COND_ENABLE);
1da177e4
LT
166 return (status);
167}
168
1da177e4
LT
169/******************************************************************************
170 *
171 * FUNCTION: acpi_hw_clear_gpe
172 *
173 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
174 *
175 * RETURN: Status
176 *
177 * DESCRIPTION: Clear the status bit for a single GPE.
178 *
179 ******************************************************************************/
180
4be44fcd 181acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
1da177e4 182{
e4e9a735 183 struct acpi_gpe_register_info *gpe_register_info;
4be44fcd 184 acpi_status status;
e4e9a735 185 u32 register_bit;
1da177e4 186
4be44fcd 187 ACPI_FUNCTION_ENTRY();
1da177e4 188
e4e9a735
RW
189 /* Get the info block for the entire GPE register */
190
191 gpe_register_info = gpe_event_info->register_info;
192 if (!gpe_register_info) {
193 return (AE_NOT_EXIST);
194 }
195
196 register_bit = acpi_hw_gpe_register_bit(gpe_event_info,
197 gpe_register_info);
69874165 198
1da177e4
LT
199 /*
200 * Write a one to the appropriate bit in the status register to
201 * clear this GPE.
202 */
c6b5774c 203 status = acpi_hw_write(register_bit,
e4e9a735 204 &gpe_register_info->status_address);
1da177e4
LT
205
206 return (status);
207}
208
1da177e4
LT
209/******************************************************************************
210 *
211 * FUNCTION: acpi_hw_get_gpe_status
212 *
213 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
214 * event_status - Where the GPE status is returned
215 *
216 * RETURN: Status
217 *
218 * DESCRIPTION: Return the status of a single GPE.
219 *
220 ******************************************************************************/
44f6c012 221
1da177e4 222acpi_status
4be44fcd
LB
223acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
224 acpi_event_status * event_status)
1da177e4 225{
4be44fcd 226 u32 in_byte;
e4e9a735 227 u32 register_bit;
4be44fcd
LB
228 struct acpi_gpe_register_info *gpe_register_info;
229 acpi_status status;
230 acpi_event_status local_event_status = 0;
1da177e4 231
4be44fcd 232 ACPI_FUNCTION_ENTRY();
1da177e4
LT
233
234 if (!event_status) {
235 return (AE_BAD_PARAMETER);
236 }
237
238 /* Get the info block for the entire GPE register */
239
240 gpe_register_info = gpe_event_info->register_info;
241
242 /* Get the register bitmask for this GPE */
243
e4e9a735
RW
244 register_bit = acpi_hw_gpe_register_bit(gpe_event_info,
245 gpe_register_info);
1da177e4
LT
246
247 /* GPE currently enabled? (enabled for runtime?) */
248
249 if (register_bit & gpe_register_info->enable_for_run) {
250 local_event_status |= ACPI_EVENT_FLAG_ENABLED;
251 }
252
253 /* GPE enabled for wake? */
254
255 if (register_bit & gpe_register_info->enable_for_wake) {
256 local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
257 }
258
259 /* GPE currently active (status bit == 1)? */
260
c6b5774c 261 status = acpi_hw_read(&in_byte, &gpe_register_info->status_address);
4be44fcd 262 if (ACPI_FAILURE(status)) {
2147d3f0 263 return (status);
1da177e4
LT
264 }
265
266 if (register_bit & in_byte) {
267 local_event_status |= ACPI_EVENT_FLAG_SET;
268 }
269
270 /* Set return value */
271
272 (*event_status) = local_event_status;
2147d3f0 273 return (AE_OK);
1da177e4 274}
1da177e4
LT
275
276/******************************************************************************
277 *
278 * FUNCTION: acpi_hw_disable_gpe_block
279 *
280 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
281 * gpe_block - Gpe Block info
282 *
283 * RETURN: Status
284 *
44f6c012 285 * DESCRIPTION: Disable all GPEs within a single GPE block
1da177e4
LT
286 *
287 ******************************************************************************/
288
289acpi_status
e97d6bf1
BM
290acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
291 struct acpi_gpe_block_info *gpe_block, void *context)
1da177e4 292{
4be44fcd
LB
293 u32 i;
294 acpi_status status;
1da177e4
LT
295
296 /* Examine each GPE Register within the block */
297
298 for (i = 0; i < gpe_block->register_count; i++) {
52fc0b02 299
1da177e4
LT
300 /* Disable all GPEs in this register */
301
ecfbbc7b 302 status =
c6b5774c
BM
303 acpi_hw_write(0x00,
304 &gpe_block->register_info[i].enable_address);
4be44fcd 305 if (ACPI_FAILURE(status)) {
1da177e4
LT
306 return (status);
307 }
308 }
309
310 return (AE_OK);
311}
312
1da177e4
LT
313/******************************************************************************
314 *
315 * FUNCTION: acpi_hw_clear_gpe_block
316 *
317 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
318 * gpe_block - Gpe Block info
319 *
320 * RETURN: Status
321 *
44f6c012 322 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
1da177e4
LT
323 *
324 ******************************************************************************/
325
326acpi_status
e97d6bf1
BM
327acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
328 struct acpi_gpe_block_info *gpe_block, void *context)
1da177e4 329{
4be44fcd
LB
330 u32 i;
331 acpi_status status;
1da177e4
LT
332
333 /* Examine each GPE Register within the block */
334
335 for (i = 0; i < gpe_block->register_count; i++) {
52fc0b02 336
1da177e4
LT
337 /* Clear status on all GPEs in this register */
338
ecfbbc7b 339 status =
c6b5774c
BM
340 acpi_hw_write(0xFF,
341 &gpe_block->register_info[i].status_address);
4be44fcd 342 if (ACPI_FAILURE(status)) {
1da177e4
LT
343 return (status);
344 }
345 }
346
347 return (AE_OK);
348}
349
1da177e4
LT
350/******************************************************************************
351 *
352 * FUNCTION: acpi_hw_enable_runtime_gpe_block
353 *
354 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
355 * gpe_block - Gpe Block info
356 *
357 * RETURN: Status
358 *
44f6c012
RM
359 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
360 * combination wake/run GPEs.
1da177e4
LT
361 *
362 ******************************************************************************/
363
364acpi_status
e97d6bf1
BM
365acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
366 struct acpi_gpe_block_info *gpe_block, void *context)
1da177e4 367{
4be44fcd
LB
368 u32 i;
369 acpi_status status;
1da177e4
LT
370
371 /* NOTE: assumes that all GPEs are currently disabled */
372
373 /* Examine each GPE Register within the block */
374
375 for (i = 0; i < gpe_block->register_count; i++) {
376 if (!gpe_block->register_info[i].enable_for_run) {
377 continue;
378 }
379
380 /* Enable all "runtime" GPEs in this register */
381
c6b5774c
BM
382 status =
383 acpi_hw_write(gpe_block->register_info[i].enable_for_run,
384 &gpe_block->register_info[i].enable_address);
4be44fcd 385 if (ACPI_FAILURE(status)) {
1da177e4
LT
386 return (status);
387 }
388 }
389
390 return (AE_OK);
391}
392
1da177e4
LT
393/******************************************************************************
394 *
395 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
396 *
397 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
398 * gpe_block - Gpe Block info
399 *
400 * RETURN: Status
401 *
44f6c012
RM
402 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
403 * combination wake/run GPEs.
1da177e4
LT
404 *
405 ******************************************************************************/
406
44f6c012 407static acpi_status
4be44fcd 408acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
e97d6bf1
BM
409 struct acpi_gpe_block_info *gpe_block,
410 void *context)
1da177e4 411{
4be44fcd
LB
412 u32 i;
413 acpi_status status;
1da177e4
LT
414
415 /* Examine each GPE Register within the block */
416
417 for (i = 0; i < gpe_block->register_count; i++) {
418 if (!gpe_block->register_info[i].enable_for_wake) {
419 continue;
420 }
421
422 /* Enable all "wake" GPEs in this register */
423
c6b5774c
BM
424 status =
425 acpi_hw_write(gpe_block->register_info[i].enable_for_wake,
426 &gpe_block->register_info[i].enable_address);
4be44fcd 427 if (ACPI_FAILURE(status)) {
1da177e4
LT
428 return (status);
429 }
430 }
431
432 return (AE_OK);
433}
434
1da177e4
LT
435/******************************************************************************
436 *
437 * FUNCTION: acpi_hw_disable_all_gpes
438 *
73459f73 439 * PARAMETERS: None
1da177e4
LT
440 *
441 * RETURN: Status
442 *
44f6c012 443 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
1da177e4
LT
444 *
445 ******************************************************************************/
446
4be44fcd 447acpi_status acpi_hw_disable_all_gpes(void)
1da177e4 448{
4be44fcd 449 acpi_status status;
1da177e4 450
b229cf92 451 ACPI_FUNCTION_TRACE(hw_disable_all_gpes);
1da177e4 452
e97d6bf1
BM
453 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
454 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
4be44fcd 455 return_ACPI_STATUS(status);
1da177e4
LT
456}
457
1da177e4
LT
458/******************************************************************************
459 *
460 * FUNCTION: acpi_hw_enable_all_runtime_gpes
461 *
73459f73 462 * PARAMETERS: None
1da177e4
LT
463 *
464 * RETURN: Status
465 *
44f6c012 466 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
1da177e4
LT
467 *
468 ******************************************************************************/
469
4be44fcd 470acpi_status acpi_hw_enable_all_runtime_gpes(void)
1da177e4 471{
4be44fcd 472 acpi_status status;
1da177e4 473
b229cf92 474 ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes);
1da177e4 475
e97d6bf1 476 status = acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block, NULL);
4be44fcd 477 return_ACPI_STATUS(status);
1da177e4
LT
478}
479
1da177e4
LT
480/******************************************************************************
481 *
482 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
483 *
73459f73 484 * PARAMETERS: None
1da177e4
LT
485 *
486 * RETURN: Status
487 *
44f6c012 488 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
1da177e4
LT
489 *
490 ******************************************************************************/
491
4be44fcd 492acpi_status acpi_hw_enable_all_wakeup_gpes(void)
1da177e4 493{
4be44fcd 494 acpi_status status;
1da177e4 495
b229cf92 496 ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes);
1da177e4 497
e97d6bf1 498 status = acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block, NULL);
4be44fcd 499 return_ACPI_STATUS(status);
1da177e4 500}