blob: 5ab7cac6fbb99b471d7388a5fdab5bce6e16fcda [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
84 status = acpi_hw_low_level_read(ACPI_GPE_REGISTER_WIDTH, &enable_mask,
85 &gpe_register_info->enable_address);
86 if (ACPI_FAILURE(status)) {
87 return (status);
88 }
89
90 /* Clear just the bit that corresponds to this GPE */
91
92 ACPI_CLEAR_BIT(enable_mask,
93 ((u32) 1 <<
94 (gpe_event_info->gpe_number -
95 gpe_register_info->base_gpe_number)));
96
97 /* Write the updated enable mask */
98
99 status = acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH, enable_mask,
100 &gpe_register_info->enable_address);
101
102 return (status);
103}
104
105/******************************************************************************
106 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 * FUNCTION: acpi_hw_write_gpe_enable_reg
108 *
109 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
110 *
111 * RETURN: Status
112 *
113 * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
114 * already be cleared or set in the parent register
115 * enable_for_run mask.
116 *
117 ******************************************************************************/
118
119acpi_status
Bob Mooree38e8a02008-06-13 08:28:55 +0800120acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info * gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
Len Brown4be44fc2005-08-05 00:44:28 -0400122 struct acpi_gpe_register_info *gpe_register_info;
123 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Len Brown4be44fc2005-08-05 00:44:28 -0400125 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 /* Get the info block for the entire GPE register */
128
129 gpe_register_info = gpe_event_info->register_info;
130 if (!gpe_register_info) {
131 return (AE_NOT_EXIST);
132 }
133
134 /* Write the entire GPE (runtime) enable register */
135
Len Brown4be44fc2005-08-05 00:44:28 -0400136 status = acpi_hw_low_level_write(8, gpe_register_info->enable_for_run,
137 &gpe_register_info->enable_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 return (status);
140}
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142/******************************************************************************
143 *
144 * FUNCTION: acpi_hw_clear_gpe
145 *
146 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
147 *
148 * RETURN: Status
149 *
150 * DESCRIPTION: Clear the status bit for a single GPE.
151 *
152 ******************************************************************************/
153
Len Brown4be44fc2005-08-05 00:44:28 -0400154acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Len Brown4be44fc2005-08-05 00:44:28 -0400156 acpi_status status;
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300157 u8 register_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Len Brown4be44fc2005-08-05 00:44:28 -0400159 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300161 register_bit = (u8)
162 (1 <<
163 (gpe_event_info->gpe_number -
164 gpe_event_info->register_info->base_gpe_number));
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 /*
167 * Write a one to the appropriate bit in the status register to
168 * clear this GPE.
169 */
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300170 status = acpi_hw_low_level_write(8, register_bit,
Len Brown4be44fc2005-08-05 00:44:28 -0400171 &gpe_event_info->register_info->
172 status_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 return (status);
175}
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177/******************************************************************************
178 *
179 * FUNCTION: acpi_hw_get_gpe_status
180 *
181 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
182 * event_status - Where the GPE status is returned
183 *
184 * RETURN: Status
185 *
186 * DESCRIPTION: Return the status of a single GPE.
187 *
188 ******************************************************************************/
Robert Moore44f6c012005-04-18 22:49:35 -0400189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400191acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
192 acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
Len Brown4be44fc2005-08-05 00:44:28 -0400194 u32 in_byte;
195 u8 register_bit;
196 struct acpi_gpe_register_info *gpe_register_info;
197 acpi_status status;
198 acpi_event_status local_event_status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Len Brown4be44fc2005-08-05 00:44:28 -0400200 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 if (!event_status) {
203 return (AE_BAD_PARAMETER);
204 }
205
206 /* Get the info block for the entire GPE register */
207
208 gpe_register_info = gpe_event_info->register_info;
209
210 /* Get the register bitmask for this GPE */
211
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300212 register_bit = (u8)
213 (1 <<
214 (gpe_event_info->gpe_number -
215 gpe_event_info->register_info->base_gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 /* GPE currently enabled? (enabled for runtime?) */
218
219 if (register_bit & gpe_register_info->enable_for_run) {
220 local_event_status |= ACPI_EVENT_FLAG_ENABLED;
221 }
222
223 /* GPE enabled for wake? */
224
225 if (register_bit & gpe_register_info->enable_for_wake) {
226 local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
227 }
228
229 /* GPE currently active (status bit == 1)? */
230
Len Brown4be44fc2005-08-05 00:44:28 -0400231 status =
232 acpi_hw_low_level_read(8, &in_byte,
233 &gpe_register_info->status_address);
234 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 goto unlock_and_exit;
236 }
237
238 if (register_bit & in_byte) {
239 local_event_status |= ACPI_EVENT_FLAG_SET;
240 }
241
242 /* Set return value */
243
244 (*event_status) = local_event_status;
245
Len Brown4be44fc2005-08-05 00:44:28 -0400246 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 return (status);
248}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250/******************************************************************************
251 *
252 * FUNCTION: acpi_hw_disable_gpe_block
253 *
254 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
255 * gpe_block - Gpe Block info
256 *
257 * RETURN: Status
258 *
Robert Moore44f6c012005-04-18 22:49:35 -0400259 * DESCRIPTION: Disable all GPEs within a single GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 *
261 ******************************************************************************/
262
263acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +0800264acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
265 struct acpi_gpe_block_info *gpe_block, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
Len Brown4be44fc2005-08-05 00:44:28 -0400267 u32 i;
268 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 /* Examine each GPE Register within the block */
271
272 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 /* Disable all GPEs in this register */
275
Len Brown4be44fc2005-08-05 00:44:28 -0400276 status = acpi_hw_low_level_write(8, 0x00,
277 &gpe_block->register_info[i].
278 enable_address);
279 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 return (status);
281 }
282 }
283
284 return (AE_OK);
285}
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287/******************************************************************************
288 *
289 * FUNCTION: acpi_hw_clear_gpe_block
290 *
291 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
292 * gpe_block - Gpe Block info
293 *
294 * RETURN: Status
295 *
Robert Moore44f6c012005-04-18 22:49:35 -0400296 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 *
298 ******************************************************************************/
299
300acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +0800301acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
302 struct acpi_gpe_block_info *gpe_block, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
Len Brown4be44fc2005-08-05 00:44:28 -0400304 u32 i;
305 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 /* Examine each GPE Register within the block */
308
309 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 /* Clear status on all GPEs in this register */
312
Len Brown4be44fc2005-08-05 00:44:28 -0400313 status = acpi_hw_low_level_write(8, 0xFF,
314 &gpe_block->register_info[i].
315 status_address);
316 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 return (status);
318 }
319 }
320
321 return (AE_OK);
322}
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324/******************************************************************************
325 *
326 * FUNCTION: acpi_hw_enable_runtime_gpe_block
327 *
328 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
329 * gpe_block - Gpe Block info
330 *
331 * RETURN: Status
332 *
Robert Moore44f6c012005-04-18 22:49:35 -0400333 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
334 * combination wake/run GPEs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 *
336 ******************************************************************************/
337
338acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +0800339acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
340 struct acpi_gpe_block_info *gpe_block, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Len Brown4be44fc2005-08-05 00:44:28 -0400342 u32 i;
343 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 /* NOTE: assumes that all GPEs are currently disabled */
346
347 /* Examine each GPE Register within the block */
348
349 for (i = 0; i < gpe_block->register_count; i++) {
350 if (!gpe_block->register_info[i].enable_for_run) {
351 continue;
352 }
353
354 /* Enable all "runtime" GPEs in this register */
355
Len Brown4be44fc2005-08-05 00:44:28 -0400356 status =
357 acpi_hw_low_level_write(8,
358 gpe_block->register_info[i].
359 enable_for_run,
360 &gpe_block->register_info[i].
361 enable_address);
362 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 return (status);
364 }
365 }
366
367 return (AE_OK);
368}
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370/******************************************************************************
371 *
372 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
373 *
374 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
375 * gpe_block - Gpe Block info
376 *
377 * RETURN: Status
378 *
Robert Moore44f6c012005-04-18 22:49:35 -0400379 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
380 * combination wake/run GPEs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 *
382 ******************************************************************************/
383
Robert Moore44f6c012005-04-18 22:49:35 -0400384static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400385acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
Bob Mooree97d6bf2008-12-30 09:45:17 +0800386 struct acpi_gpe_block_info *gpe_block,
387 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
Len Brown4be44fc2005-08-05 00:44:28 -0400389 u32 i;
390 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 /* Examine each GPE Register within the block */
393
394 for (i = 0; i < gpe_block->register_count; i++) {
395 if (!gpe_block->register_info[i].enable_for_wake) {
396 continue;
397 }
398
399 /* Enable all "wake" GPEs in this register */
400
Len Brown4be44fc2005-08-05 00:44:28 -0400401 status = acpi_hw_low_level_write(8,
402 gpe_block->register_info[i].
403 enable_for_wake,
404 &gpe_block->register_info[i].
405 enable_address);
406 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return (status);
408 }
409 }
410
411 return (AE_OK);
412}
413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414/******************************************************************************
415 *
416 * FUNCTION: acpi_hw_disable_all_gpes
417 *
Robert Moore73459f72005-06-24 00:00:00 -0400418 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 *
420 * RETURN: Status
421 *
Robert Moore44f6c012005-04-18 22:49:35 -0400422 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 *
424 ******************************************************************************/
425
Len Brown4be44fc2005-08-05 00:44:28 -0400426acpi_status acpi_hw_disable_all_gpes(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
Len Brown4be44fc2005-08-05 00:44:28 -0400428 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Bob Mooreb229cf92006-04-21 17:15:00 -0400430 ACPI_FUNCTION_TRACE(hw_disable_all_gpes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Bob Mooree97d6bf2008-12-30 09:45:17 +0800432 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
433 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400434 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437/******************************************************************************
438 *
439 * FUNCTION: acpi_hw_enable_all_runtime_gpes
440 *
Robert Moore73459f72005-06-24 00:00:00 -0400441 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 *
443 * RETURN: Status
444 *
Robert Moore44f6c012005-04-18 22:49:35 -0400445 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 *
447 ******************************************************************************/
448
Len Brown4be44fc2005-08-05 00:44:28 -0400449acpi_status acpi_hw_enable_all_runtime_gpes(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
Len Brown4be44fc2005-08-05 00:44:28 -0400451 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Bob Mooreb229cf92006-04-21 17:15:00 -0400453 ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Bob Mooree97d6bf2008-12-30 09:45:17 +0800455 status = acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400456 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457}
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459/******************************************************************************
460 *
461 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
462 *
Robert Moore73459f72005-06-24 00:00:00 -0400463 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 *
465 * RETURN: Status
466 *
Robert Moore44f6c012005-04-18 22:49:35 -0400467 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 *
469 ******************************************************************************/
470
Len Brown4be44fc2005-08-05 00:44:28 -0400471acpi_status acpi_hw_enable_all_wakeup_gpes(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Len Brown4be44fc2005-08-05 00:44:28 -0400473 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Bob Mooreb229cf92006-04-21 17:15:00 -0400475 ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Bob Mooree97d6bf2008-12-30 09:45:17 +0800477 status = acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400478 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}