blob: 09aaeaac3d0b3c085b248095cbc098d6f53bf534 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/******************************************************************************
3 *
4 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
5 *
6 *****************************************************************************/
7
8/*
Len Brown75a44ce2008-04-23 23:00:13 -04009 * Copyright (C) 2000 - 2008, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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>
46#include <acpi/acevents.h>
47
48#define _COMPONENT ACPI_HARDWARE
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("hwgpe")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Robert Moore44f6c012005-04-18 22:49:35 -040051/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040052static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040053acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
Bob Mooree97d6bf2008-12-30 09:45:17 +080054 struct acpi_gpe_block_info *gpe_block,
55 void *context);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57/******************************************************************************
58 *
Bob Mooree38e8a02008-06-13 08:28:55 +080059 * FUNCTION: acpi_hw_low_disable_gpe
60 *
61 * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled
62 *
63 * RETURN: Status
64 *
65 * DESCRIPTION: Disable a single GPE in the enable register.
66 *
67 ******************************************************************************/
68
69acpi_status acpi_hw_low_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
70{
71 struct acpi_gpe_register_info *gpe_register_info;
72 acpi_status status;
73 u32 enable_mask;
74
75 /* Get the info block for the entire GPE register */
76
77 gpe_register_info = gpe_event_info->register_info;
78 if (!gpe_register_info) {
79 return (AE_NOT_EXIST);
80 }
81
82 /* Get current value of the enable register that contains this GPE */
83
Bob Mooreecfbbc72008-12-31 02:55:32 +080084 status = acpi_read(&enable_mask, &gpe_register_info->enable_address);
Bob Mooree38e8a02008-06-13 08:28:55 +080085 if (ACPI_FAILURE(status)) {
86 return (status);
87 }
88
89 /* Clear just the bit that corresponds to this GPE */
90
91 ACPI_CLEAR_BIT(enable_mask,
92 ((u32) 1 <<
93 (gpe_event_info->gpe_number -
94 gpe_register_info->base_gpe_number)));
95
96 /* Write the updated enable mask */
97
Bob Mooreecfbbc72008-12-31 02:55:32 +080098 status = acpi_write(enable_mask, &gpe_register_info->enable_address);
Bob Mooree38e8a02008-06-13 08:28:55 +080099 return (status);
100}
101
102/******************************************************************************
103 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 * FUNCTION: acpi_hw_write_gpe_enable_reg
105 *
106 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
107 *
108 * RETURN: Status
109 *
110 * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
111 * already be cleared or set in the parent register
112 * enable_for_run mask.
113 *
114 ******************************************************************************/
115
116acpi_status
Bob Mooree38e8a02008-06-13 08:28:55 +0800117acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info * gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Len Brown4be44fc2005-08-05 00:44:28 -0400119 struct acpi_gpe_register_info *gpe_register_info;
120 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Len Brown4be44fc2005-08-05 00:44:28 -0400122 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 /* Get the info block for the entire GPE register */
125
126 gpe_register_info = gpe_event_info->register_info;
127 if (!gpe_register_info) {
128 return (AE_NOT_EXIST);
129 }
130
131 /* Write the entire GPE (runtime) enable register */
132
Bob Mooreecfbbc72008-12-31 02:55:32 +0800133 status = acpi_write(gpe_register_info->enable_for_run,
134 &gpe_register_info->enable_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 return (status);
137}
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/******************************************************************************
140 *
141 * FUNCTION: acpi_hw_clear_gpe
142 *
143 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
144 *
145 * RETURN: Status
146 *
147 * DESCRIPTION: Clear the status bit for a single GPE.
148 *
149 ******************************************************************************/
150
Len Brown4be44fc2005-08-05 00:44:28 -0400151acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Len Brown4be44fc2005-08-05 00:44:28 -0400153 acpi_status status;
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300154 u8 register_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Len Brown4be44fc2005-08-05 00:44:28 -0400156 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300158 register_bit = (u8)
159 (1 <<
160 (gpe_event_info->gpe_number -
161 gpe_event_info->register_info->base_gpe_number));
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /*
164 * Write a one to the appropriate bit in the status register to
165 * clear this GPE.
166 */
Bob Mooreecfbbc72008-12-31 02:55:32 +0800167 status = acpi_write(register_bit,
168 &gpe_event_info->register_info->status_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 return (status);
171}
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173/******************************************************************************
174 *
175 * FUNCTION: acpi_hw_get_gpe_status
176 *
177 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
178 * event_status - Where the GPE status is returned
179 *
180 * RETURN: Status
181 *
182 * DESCRIPTION: Return the status of a single GPE.
183 *
184 ******************************************************************************/
Robert Moore44f6c012005-04-18 22:49:35 -0400185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400187acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
188 acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
Len Brown4be44fc2005-08-05 00:44:28 -0400190 u32 in_byte;
191 u8 register_bit;
192 struct acpi_gpe_register_info *gpe_register_info;
193 acpi_status status;
194 acpi_event_status local_event_status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Len Brown4be44fc2005-08-05 00:44:28 -0400196 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 if (!event_status) {
199 return (AE_BAD_PARAMETER);
200 }
201
202 /* Get the info block for the entire GPE register */
203
204 gpe_register_info = gpe_event_info->register_info;
205
206 /* Get the register bitmask for this GPE */
207
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300208 register_bit = (u8)
209 (1 <<
210 (gpe_event_info->gpe_number -
211 gpe_event_info->register_info->base_gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213 /* GPE currently enabled? (enabled for runtime?) */
214
215 if (register_bit & gpe_register_info->enable_for_run) {
216 local_event_status |= ACPI_EVENT_FLAG_ENABLED;
217 }
218
219 /* GPE enabled for wake? */
220
221 if (register_bit & gpe_register_info->enable_for_wake) {
222 local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
223 }
224
225 /* GPE currently active (status bit == 1)? */
226
Bob Mooreecfbbc72008-12-31 02:55:32 +0800227 status = acpi_read(&in_byte, &gpe_register_info->status_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400228 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 goto unlock_and_exit;
230 }
231
232 if (register_bit & in_byte) {
233 local_event_status |= ACPI_EVENT_FLAG_SET;
234 }
235
236 /* Set return value */
237
238 (*event_status) = local_event_status;
239
Len Brown4be44fc2005-08-05 00:44:28 -0400240 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return (status);
242}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244/******************************************************************************
245 *
246 * FUNCTION: acpi_hw_disable_gpe_block
247 *
248 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
249 * gpe_block - Gpe Block info
250 *
251 * RETURN: Status
252 *
Robert Moore44f6c012005-04-18 22:49:35 -0400253 * DESCRIPTION: Disable all GPEs within a single GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 *
255 ******************************************************************************/
256
257acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +0800258acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
259 struct acpi_gpe_block_info *gpe_block, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Len Brown4be44fc2005-08-05 00:44:28 -0400261 u32 i;
262 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 /* Examine each GPE Register within the block */
265
266 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 /* Disable all GPEs in this register */
269
Bob Mooreecfbbc72008-12-31 02:55:32 +0800270 status =
271 acpi_write(0x00,
272 &gpe_block->register_info[i].enable_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400273 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 return (status);
275 }
276 }
277
278 return (AE_OK);
279}
280
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281/******************************************************************************
282 *
283 * FUNCTION: acpi_hw_clear_gpe_block
284 *
285 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
286 * gpe_block - Gpe Block info
287 *
288 * RETURN: Status
289 *
Robert Moore44f6c012005-04-18 22:49:35 -0400290 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 *
292 ******************************************************************************/
293
294acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +0800295acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
296 struct acpi_gpe_block_info *gpe_block, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Len Brown4be44fc2005-08-05 00:44:28 -0400298 u32 i;
299 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301 /* Examine each GPE Register within the block */
302
303 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 /* Clear status on all GPEs in this register */
306
Bob Mooreecfbbc72008-12-31 02:55:32 +0800307 status =
308 acpi_write(0xFF,
309 &gpe_block->register_info[i].status_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400310 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 return (status);
312 }
313 }
314
315 return (AE_OK);
316}
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318/******************************************************************************
319 *
320 * FUNCTION: acpi_hw_enable_runtime_gpe_block
321 *
322 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
323 * gpe_block - Gpe Block info
324 *
325 * RETURN: Status
326 *
Robert Moore44f6c012005-04-18 22:49:35 -0400327 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
328 * combination wake/run GPEs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 *
330 ******************************************************************************/
331
332acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +0800333acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
334 struct acpi_gpe_block_info *gpe_block, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
Len Brown4be44fc2005-08-05 00:44:28 -0400336 u32 i;
337 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 /* NOTE: assumes that all GPEs are currently disabled */
340
341 /* Examine each GPE Register within the block */
342
343 for (i = 0; i < gpe_block->register_count; i++) {
344 if (!gpe_block->register_info[i].enable_for_run) {
345 continue;
346 }
347
348 /* Enable all "runtime" GPEs in this register */
349
Bob Mooreecfbbc72008-12-31 02:55:32 +0800350 status = acpi_write(gpe_block->register_info[i].enable_for_run,
351 &gpe_block->register_info[i].
352 enable_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400353 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 return (status);
355 }
356 }
357
358 return (AE_OK);
359}
360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361/******************************************************************************
362 *
363 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
364 *
365 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
366 * gpe_block - Gpe Block info
367 *
368 * RETURN: Status
369 *
Robert Moore44f6c012005-04-18 22:49:35 -0400370 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
371 * combination wake/run GPEs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 *
373 ******************************************************************************/
374
Robert Moore44f6c012005-04-18 22:49:35 -0400375static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400376acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
Bob Mooree97d6bf2008-12-30 09:45:17 +0800377 struct acpi_gpe_block_info *gpe_block,
378 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
Len Brown4be44fc2005-08-05 00:44:28 -0400380 u32 i;
381 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 /* Examine each GPE Register within the block */
384
385 for (i = 0; i < gpe_block->register_count; i++) {
386 if (!gpe_block->register_info[i].enable_for_wake) {
387 continue;
388 }
389
390 /* Enable all "wake" GPEs in this register */
391
Bob Mooreecfbbc72008-12-31 02:55:32 +0800392 status = acpi_write(gpe_block->register_info[i].enable_for_wake,
393 &gpe_block->register_info[i].
394 enable_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400395 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 return (status);
397 }
398 }
399
400 return (AE_OK);
401}
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403/******************************************************************************
404 *
405 * FUNCTION: acpi_hw_disable_all_gpes
406 *
Robert Moore73459f72005-06-24 00:00:00 -0400407 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 *
409 * RETURN: Status
410 *
Robert Moore44f6c012005-04-18 22:49:35 -0400411 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 *
413 ******************************************************************************/
414
Len Brown4be44fc2005-08-05 00:44:28 -0400415acpi_status acpi_hw_disable_all_gpes(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
Len Brown4be44fc2005-08-05 00:44:28 -0400417 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Bob Mooreb229cf92006-04-21 17:15:00 -0400419 ACPI_FUNCTION_TRACE(hw_disable_all_gpes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Bob Mooree97d6bf2008-12-30 09:45:17 +0800421 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
422 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400423 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424}
425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426/******************************************************************************
427 *
428 * FUNCTION: acpi_hw_enable_all_runtime_gpes
429 *
Robert Moore73459f72005-06-24 00:00:00 -0400430 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 *
432 * RETURN: Status
433 *
Robert Moore44f6c012005-04-18 22:49:35 -0400434 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 *
436 ******************************************************************************/
437
Len Brown4be44fc2005-08-05 00:44:28 -0400438acpi_status acpi_hw_enable_all_runtime_gpes(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
Len Brown4be44fc2005-08-05 00:44:28 -0400440 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Bob Mooreb229cf92006-04-21 17:15:00 -0400442 ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Bob Mooree97d6bf2008-12-30 09:45:17 +0800444 status = acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400445 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448/******************************************************************************
449 *
450 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
451 *
Robert Moore73459f72005-06-24 00:00:00 -0400452 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 *
454 * RETURN: Status
455 *
Robert Moore44f6c012005-04-18 22:49:35 -0400456 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 *
458 ******************************************************************************/
459
Len Brown4be44fc2005-08-05 00:44:28 -0400460acpi_status acpi_hw_enable_all_wakeup_gpes(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
Len Brown4be44fc2005-08-05 00:44:28 -0400462 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Bob Mooreb229cf92006-04-21 17:15:00 -0400464 ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Bob Mooree97d6bf2008-12-30 09:45:17 +0800466 status = acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400467 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}