blob: d84942d22dd549269b7d87dfdfc5e417e664c375 [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/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05009 * Copyright (C) 2000 - 2006, R. Byron Moore
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,
54 struct acpi_gpe_block_info *gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56/******************************************************************************
57 *
58 * FUNCTION: acpi_hw_write_gpe_enable_reg
59 *
60 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
61 *
62 * RETURN: Status
63 *
64 * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
65 * already be cleared or set in the parent register
66 * enable_for_run mask.
67 *
68 ******************************************************************************/
69
70acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040071acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info *gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
Len Brown4be44fc2005-08-05 00:44:28 -040073 struct acpi_gpe_register_info *gpe_register_info;
74 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Len Brown4be44fc2005-08-05 00:44:28 -040076 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78 /* Get the info block for the entire GPE register */
79
80 gpe_register_info = gpe_event_info->register_info;
81 if (!gpe_register_info) {
82 return (AE_NOT_EXIST);
83 }
84
85 /* Write the entire GPE (runtime) enable register */
86
Len Brown4be44fc2005-08-05 00:44:28 -040087 status = acpi_hw_low_level_write(8, gpe_register_info->enable_for_run,
88 &gpe_register_info->enable_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90 return (status);
91}
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093/******************************************************************************
94 *
95 * FUNCTION: acpi_hw_clear_gpe
96 *
97 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
98 *
99 * RETURN: Status
100 *
101 * DESCRIPTION: Clear the status bit for a single GPE.
102 *
103 ******************************************************************************/
104
Len Brown4be44fc2005-08-05 00:44:28 -0400105acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Len Brown4be44fc2005-08-05 00:44:28 -0400107 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Len Brown4be44fc2005-08-05 00:44:28 -0400109 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 /*
112 * Write a one to the appropriate bit in the status register to
113 * clear this GPE.
114 */
Len Brown4be44fc2005-08-05 00:44:28 -0400115 status = acpi_hw_low_level_write(8, gpe_event_info->register_bit,
116 &gpe_event_info->register_info->
117 status_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 return (status);
120}
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122/******************************************************************************
123 *
124 * FUNCTION: acpi_hw_get_gpe_status
125 *
126 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
127 * event_status - Where the GPE status is returned
128 *
129 * RETURN: Status
130 *
131 * DESCRIPTION: Return the status of a single GPE.
132 *
133 ******************************************************************************/
Robert Moore44f6c012005-04-18 22:49:35 -0400134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#ifdef ACPI_FUTURE_USAGE
136acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400137acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
138 acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Len Brown4be44fc2005-08-05 00:44:28 -0400140 u32 in_byte;
141 u8 register_bit;
142 struct acpi_gpe_register_info *gpe_register_info;
143 acpi_status status;
144 acpi_event_status local_event_status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Len Brown4be44fc2005-08-05 00:44:28 -0400146 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 if (!event_status) {
149 return (AE_BAD_PARAMETER);
150 }
151
152 /* Get the info block for the entire GPE register */
153
154 gpe_register_info = gpe_event_info->register_info;
155
156 /* Get the register bitmask for this GPE */
157
158 register_bit = gpe_event_info->register_bit;
159
160 /* GPE currently enabled? (enabled for runtime?) */
161
162 if (register_bit & gpe_register_info->enable_for_run) {
163 local_event_status |= ACPI_EVENT_FLAG_ENABLED;
164 }
165
166 /* GPE enabled for wake? */
167
168 if (register_bit & gpe_register_info->enable_for_wake) {
169 local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
170 }
171
172 /* GPE currently active (status bit == 1)? */
173
Len Brown4be44fc2005-08-05 00:44:28 -0400174 status =
175 acpi_hw_low_level_read(8, &in_byte,
176 &gpe_register_info->status_address);
177 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 goto unlock_and_exit;
179 }
180
181 if (register_bit & in_byte) {
182 local_event_status |= ACPI_EVENT_FLAG_SET;
183 }
184
185 /* Set return value */
186
187 (*event_status) = local_event_status;
188
Len Brown4be44fc2005-08-05 00:44:28 -0400189 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 return (status);
191}
Len Brown4be44fc2005-08-05 00:44:28 -0400192#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194/******************************************************************************
195 *
196 * FUNCTION: acpi_hw_disable_gpe_block
197 *
198 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
199 * gpe_block - Gpe Block info
200 *
201 * RETURN: Status
202 *
Robert Moore44f6c012005-04-18 22:49:35 -0400203 * DESCRIPTION: Disable all GPEs within a single GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 *
205 ******************************************************************************/
206
207acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400208acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info * gpe_xrupt_info,
209 struct acpi_gpe_block_info * gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Len Brown4be44fc2005-08-05 00:44:28 -0400211 u32 i;
212 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 /* Examine each GPE Register within the block */
215
216 for (i = 0; i < gpe_block->register_count; i++) {
217 /* Disable all GPEs in this register */
218
Len Brown4be44fc2005-08-05 00:44:28 -0400219 status = acpi_hw_low_level_write(8, 0x00,
220 &gpe_block->register_info[i].
221 enable_address);
222 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 return (status);
224 }
225 }
226
227 return (AE_OK);
228}
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230/******************************************************************************
231 *
232 * FUNCTION: acpi_hw_clear_gpe_block
233 *
234 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
235 * gpe_block - Gpe Block info
236 *
237 * RETURN: Status
238 *
Robert Moore44f6c012005-04-18 22:49:35 -0400239 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 *
241 ******************************************************************************/
242
243acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400244acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info * gpe_xrupt_info,
245 struct acpi_gpe_block_info * gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
Len Brown4be44fc2005-08-05 00:44:28 -0400247 u32 i;
248 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 /* Examine each GPE Register within the block */
251
252 for (i = 0; i < gpe_block->register_count; i++) {
253 /* Clear status on all GPEs in this register */
254
Len Brown4be44fc2005-08-05 00:44:28 -0400255 status = acpi_hw_low_level_write(8, 0xFF,
256 &gpe_block->register_info[i].
257 status_address);
258 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 return (status);
260 }
261 }
262
263 return (AE_OK);
264}
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266/******************************************************************************
267 *
268 * FUNCTION: acpi_hw_enable_runtime_gpe_block
269 *
270 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
271 * gpe_block - Gpe Block info
272 *
273 * RETURN: Status
274 *
Robert Moore44f6c012005-04-18 22:49:35 -0400275 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
276 * combination wake/run GPEs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 *
278 ******************************************************************************/
279
280acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400281acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info * gpe_xrupt_info,
282 struct acpi_gpe_block_info * gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Len Brown4be44fc2005-08-05 00:44:28 -0400284 u32 i;
285 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 /* NOTE: assumes that all GPEs are currently disabled */
288
289 /* Examine each GPE Register within the block */
290
291 for (i = 0; i < gpe_block->register_count; i++) {
292 if (!gpe_block->register_info[i].enable_for_run) {
293 continue;
294 }
295
296 /* Enable all "runtime" GPEs in this register */
297
Len Brown4be44fc2005-08-05 00:44:28 -0400298 status =
299 acpi_hw_low_level_write(8,
300 gpe_block->register_info[i].
301 enable_for_run,
302 &gpe_block->register_info[i].
303 enable_address);
304 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 return (status);
306 }
307 }
308
309 return (AE_OK);
310}
311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312/******************************************************************************
313 *
314 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
315 *
316 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
317 * gpe_block - Gpe Block info
318 *
319 * RETURN: Status
320 *
Robert Moore44f6c012005-04-18 22:49:35 -0400321 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
322 * combination wake/run GPEs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 *
324 ******************************************************************************/
325
Robert Moore44f6c012005-04-18 22:49:35 -0400326static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400327acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
328 struct acpi_gpe_block_info *gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Len Brown4be44fc2005-08-05 00:44:28 -0400330 u32 i;
331 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333 /* Examine each GPE Register within the block */
334
335 for (i = 0; i < gpe_block->register_count; i++) {
336 if (!gpe_block->register_info[i].enable_for_wake) {
337 continue;
338 }
339
340 /* Enable all "wake" GPEs in this register */
341
Len Brown4be44fc2005-08-05 00:44:28 -0400342 status = acpi_hw_low_level_write(8,
343 gpe_block->register_info[i].
344 enable_for_wake,
345 &gpe_block->register_info[i].
346 enable_address);
347 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 return (status);
349 }
350 }
351
352 return (AE_OK);
353}
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355/******************************************************************************
356 *
357 * FUNCTION: acpi_hw_disable_all_gpes
358 *
Robert Moore73459f72005-06-24 00:00:00 -0400359 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 *
361 * RETURN: Status
362 *
Robert Moore44f6c012005-04-18 22:49:35 -0400363 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 *
365 ******************************************************************************/
366
Len Brown4be44fc2005-08-05 00:44:28 -0400367acpi_status acpi_hw_disable_all_gpes(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
Len Brown4be44fc2005-08-05 00:44:28 -0400369 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Len Brown4be44fc2005-08-05 00:44:28 -0400371 ACPI_FUNCTION_TRACE("hw_disable_all_gpes");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Len Brown4be44fc2005-08-05 00:44:28 -0400373 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block);
374 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block);
375 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378/******************************************************************************
379 *
380 * FUNCTION: acpi_hw_enable_all_runtime_gpes
381 *
Robert Moore73459f72005-06-24 00:00:00 -0400382 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 *
384 * RETURN: Status
385 *
Robert Moore44f6c012005-04-18 22:49:35 -0400386 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 *
388 ******************************************************************************/
389
Len Brown4be44fc2005-08-05 00:44:28 -0400390acpi_status acpi_hw_enable_all_runtime_gpes(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
Len Brown4be44fc2005-08-05 00:44:28 -0400392 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Len Brown4be44fc2005-08-05 00:44:28 -0400394 ACPI_FUNCTION_TRACE("hw_enable_all_runtime_gpes");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Len Brown4be44fc2005-08-05 00:44:28 -0400396 status = acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block);
397 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398}
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400/******************************************************************************
401 *
402 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
403 *
Robert Moore73459f72005-06-24 00:00:00 -0400404 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 *
406 * RETURN: Status
407 *
Robert Moore44f6c012005-04-18 22:49:35 -0400408 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 *
410 ******************************************************************************/
411
Len Brown4be44fc2005-08-05 00:44:28 -0400412acpi_status acpi_hw_enable_all_wakeup_gpes(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
Len Brown4be44fc2005-08-05 00:44:28 -0400414 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Len Brown4be44fc2005-08-05 00:44:28 -0400416 ACPI_FUNCTION_TRACE("hw_enable_all_wakeup_gpes");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Len Brown4be44fc2005-08-05 00:44:28 -0400418 status = acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block);
419 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}