blob: 3d548b5b0dd5d378331b19852df2ace5ade6de85 [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;
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300108 u8 register_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Len Brown4be44fc2005-08-05 00:44:28 -0400110 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300112 register_bit = (u8)
113 (1 <<
114 (gpe_event_info->gpe_number -
115 gpe_event_info->register_info->base_gpe_number));
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 /*
118 * Write a one to the appropriate bit in the status register to
119 * clear this GPE.
120 */
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300121 status = acpi_hw_low_level_write(8, register_bit,
Len Brown4be44fc2005-08-05 00:44:28 -0400122 &gpe_event_info->register_info->
123 status_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 return (status);
126}
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128/******************************************************************************
129 *
130 * FUNCTION: acpi_hw_get_gpe_status
131 *
132 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
133 * event_status - Where the GPE status is returned
134 *
135 * RETURN: Status
136 *
137 * DESCRIPTION: Return the status of a single GPE.
138 *
139 ******************************************************************************/
Robert Moore44f6c012005-04-18 22:49:35 -0400140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#ifdef ACPI_FUTURE_USAGE
142acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400143acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
144 acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Len Brown4be44fc2005-08-05 00:44:28 -0400146 u32 in_byte;
147 u8 register_bit;
148 struct acpi_gpe_register_info *gpe_register_info;
149 acpi_status status;
150 acpi_event_status local_event_status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Len Brown4be44fc2005-08-05 00:44:28 -0400152 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 if (!event_status) {
155 return (AE_BAD_PARAMETER);
156 }
157
158 /* Get the info block for the entire GPE register */
159
160 gpe_register_info = gpe_event_info->register_info;
161
162 /* Get the register bitmask for this GPE */
163
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300164 register_bit = (u8)
165 (1 <<
166 (gpe_event_info->gpe_number -
167 gpe_event_info->register_info->base_gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 /* GPE currently enabled? (enabled for runtime?) */
170
171 if (register_bit & gpe_register_info->enable_for_run) {
172 local_event_status |= ACPI_EVENT_FLAG_ENABLED;
173 }
174
175 /* GPE enabled for wake? */
176
177 if (register_bit & gpe_register_info->enable_for_wake) {
178 local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
179 }
180
181 /* GPE currently active (status bit == 1)? */
182
Len Brown4be44fc2005-08-05 00:44:28 -0400183 status =
184 acpi_hw_low_level_read(8, &in_byte,
185 &gpe_register_info->status_address);
186 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 goto unlock_and_exit;
188 }
189
190 if (register_bit & in_byte) {
191 local_event_status |= ACPI_EVENT_FLAG_SET;
192 }
193
194 /* Set return value */
195
196 (*event_status) = local_event_status;
197
Len Brown4be44fc2005-08-05 00:44:28 -0400198 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 return (status);
200}
Len Brown4be44fc2005-08-05 00:44:28 -0400201#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203/******************************************************************************
204 *
205 * FUNCTION: acpi_hw_disable_gpe_block
206 *
207 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
208 * gpe_block - Gpe Block info
209 *
210 * RETURN: Status
211 *
Robert Moore44f6c012005-04-18 22:49:35 -0400212 * DESCRIPTION: Disable all GPEs within a single GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 *
214 ******************************************************************************/
215
216acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400217acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info * gpe_xrupt_info,
218 struct acpi_gpe_block_info * gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
Len Brown4be44fc2005-08-05 00:44:28 -0400220 u32 i;
221 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 /* Examine each GPE Register within the block */
224
225 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 /* Disable all GPEs in this register */
228
Len Brown4be44fc2005-08-05 00:44:28 -0400229 status = acpi_hw_low_level_write(8, 0x00,
230 &gpe_block->register_info[i].
231 enable_address);
232 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 return (status);
234 }
235 }
236
237 return (AE_OK);
238}
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240/******************************************************************************
241 *
242 * FUNCTION: acpi_hw_clear_gpe_block
243 *
244 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
245 * gpe_block - Gpe Block info
246 *
247 * RETURN: Status
248 *
Robert Moore44f6c012005-04-18 22:49:35 -0400249 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 *
251 ******************************************************************************/
252
253acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400254acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info * gpe_xrupt_info,
255 struct acpi_gpe_block_info * gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
Len Brown4be44fc2005-08-05 00:44:28 -0400257 u32 i;
258 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260 /* Examine each GPE Register within the block */
261
262 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 /* Clear status on all GPEs in this register */
265
Len Brown4be44fc2005-08-05 00:44:28 -0400266 status = acpi_hw_low_level_write(8, 0xFF,
267 &gpe_block->register_info[i].
268 status_address);
269 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 return (status);
271 }
272 }
273
274 return (AE_OK);
275}
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277/******************************************************************************
278 *
279 * FUNCTION: acpi_hw_enable_runtime_gpe_block
280 *
281 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
282 * gpe_block - Gpe Block info
283 *
284 * RETURN: Status
285 *
Robert Moore44f6c012005-04-18 22:49:35 -0400286 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
287 * combination wake/run GPEs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 *
289 ******************************************************************************/
290
291acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400292acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info * gpe_xrupt_info,
293 struct acpi_gpe_block_info * gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Len Brown4be44fc2005-08-05 00:44:28 -0400295 u32 i;
296 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 /* NOTE: assumes that all GPEs are currently disabled */
299
300 /* Examine each GPE Register within the block */
301
302 for (i = 0; i < gpe_block->register_count; i++) {
303 if (!gpe_block->register_info[i].enable_for_run) {
304 continue;
305 }
306
307 /* Enable all "runtime" GPEs in this register */
308
Len Brown4be44fc2005-08-05 00:44:28 -0400309 status =
310 acpi_hw_low_level_write(8,
311 gpe_block->register_info[i].
312 enable_for_run,
313 &gpe_block->register_info[i].
314 enable_address);
315 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 return (status);
317 }
318 }
319
320 return (AE_OK);
321}
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323/******************************************************************************
324 *
325 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
326 *
327 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
328 * gpe_block - Gpe Block info
329 *
330 * RETURN: Status
331 *
Robert Moore44f6c012005-04-18 22:49:35 -0400332 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
333 * combination wake/run GPEs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 *
335 ******************************************************************************/
336
Robert Moore44f6c012005-04-18 22:49:35 -0400337static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400338acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
339 struct acpi_gpe_block_info *gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Len Brown4be44fc2005-08-05 00:44:28 -0400341 u32 i;
342 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 /* Examine each GPE Register within the block */
345
346 for (i = 0; i < gpe_block->register_count; i++) {
347 if (!gpe_block->register_info[i].enable_for_wake) {
348 continue;
349 }
350
351 /* Enable all "wake" GPEs in this register */
352
Len Brown4be44fc2005-08-05 00:44:28 -0400353 status = acpi_hw_low_level_write(8,
354 gpe_block->register_info[i].
355 enable_for_wake,
356 &gpe_block->register_info[i].
357 enable_address);
358 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 return (status);
360 }
361 }
362
363 return (AE_OK);
364}
365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366/******************************************************************************
367 *
368 * FUNCTION: acpi_hw_disable_all_gpes
369 *
Robert Moore73459f72005-06-24 00:00:00 -0400370 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 *
372 * RETURN: Status
373 *
Robert Moore44f6c012005-04-18 22:49:35 -0400374 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 *
376 ******************************************************************************/
377
Len Brown4be44fc2005-08-05 00:44:28 -0400378acpi_status acpi_hw_disable_all_gpes(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
Len Brown4be44fc2005-08-05 00:44:28 -0400380 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Bob Mooreb229cf92006-04-21 17:15:00 -0400382 ACPI_FUNCTION_TRACE(hw_disable_all_gpes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Len Brown4be44fc2005-08-05 00:44:28 -0400384 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block);
385 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block);
386 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387}
388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389/******************************************************************************
390 *
391 * FUNCTION: acpi_hw_enable_all_runtime_gpes
392 *
Robert Moore73459f72005-06-24 00:00:00 -0400393 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 *
395 * RETURN: Status
396 *
Robert Moore44f6c012005-04-18 22:49:35 -0400397 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 *
399 ******************************************************************************/
400
Len Brown4be44fc2005-08-05 00:44:28 -0400401acpi_status acpi_hw_enable_all_runtime_gpes(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
Len Brown4be44fc2005-08-05 00:44:28 -0400403 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Bob Mooreb229cf92006-04-21 17:15:00 -0400405 ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Len Brown4be44fc2005-08-05 00:44:28 -0400407 status = acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block);
408 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409}
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411/******************************************************************************
412 *
413 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
414 *
Robert Moore73459f72005-06-24 00:00:00 -0400415 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 *
417 * RETURN: Status
418 *
Robert Moore44f6c012005-04-18 22:49:35 -0400419 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 *
421 ******************************************************************************/
422
Len Brown4be44fc2005-08-05 00:44:28 -0400423acpi_status acpi_hw_enable_all_wakeup_gpes(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
Len Brown4be44fc2005-08-05 00:44:28 -0400425 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Bob Mooreb229cf92006-04-21 17:15:00 -0400427 ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Len Brown4be44fc2005-08-05 00:44:28 -0400429 status = acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block);
430 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}