Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / acpi / hardware / hwgpe.c
blob9ac1d639bf5105d4cf5ce7db4c861ccff71c1f3e
2 /******************************************************************************
4 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2005, R. Byron Moore
10 * All rights reserved.
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.
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acevents.h>
48 #define _COMPONENT ACPI_HARDWARE
49 ACPI_MODULE_NAME ("hwgpe")
52 /******************************************************************************
54 * FUNCTION: acpi_hw_write_gpe_enable_reg
56 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
58 * RETURN: Status
60 * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
61 * already be cleared or set in the parent register
62 * enable_for_run mask.
64 ******************************************************************************/
66 acpi_status
67 acpi_hw_write_gpe_enable_reg (
68 struct acpi_gpe_event_info *gpe_event_info)
70 struct acpi_gpe_register_info *gpe_register_info;
71 acpi_status status;
74 ACPI_FUNCTION_ENTRY ();
77 /* Get the info block for the entire GPE register */
79 gpe_register_info = gpe_event_info->register_info;
80 if (!gpe_register_info) {
81 return (AE_NOT_EXIST);
84 /* Write the entire GPE (runtime) enable register */
86 status = acpi_hw_low_level_write (8, gpe_register_info->enable_for_run,
87 &gpe_register_info->enable_address);
89 return (status);
93 /******************************************************************************
95 * FUNCTION: acpi_hw_clear_gpe
97 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
99 * RETURN: Status
101 * DESCRIPTION: Clear the status bit for a single GPE.
103 ******************************************************************************/
105 acpi_status
106 acpi_hw_clear_gpe (
107 struct acpi_gpe_event_info *gpe_event_info)
109 acpi_status status;
112 ACPI_FUNCTION_ENTRY ();
116 * Write a one to the appropriate bit in the status register to
117 * clear this GPE.
119 status = acpi_hw_low_level_write (8, gpe_event_info->register_bit,
120 &gpe_event_info->register_info->status_address);
122 return (status);
126 /******************************************************************************
128 * FUNCTION: acpi_hw_get_gpe_status
130 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
131 * event_status - Where the GPE status is returned
133 * RETURN: Status
135 * DESCRIPTION: Return the status of a single GPE.
137 ******************************************************************************/
138 #ifdef ACPI_FUTURE_USAGE
139 acpi_status
140 acpi_hw_get_gpe_status (
141 struct acpi_gpe_event_info *gpe_event_info,
142 acpi_event_status *event_status)
144 u32 in_byte;
145 u8 register_bit;
146 struct acpi_gpe_register_info *gpe_register_info;
147 acpi_status status;
148 acpi_event_status local_event_status = 0;
151 ACPI_FUNCTION_ENTRY ();
154 if (!event_status) {
155 return (AE_BAD_PARAMETER);
158 /* Get the info block for the entire GPE register */
160 gpe_register_info = gpe_event_info->register_info;
162 /* Get the register bitmask for this GPE */
164 register_bit = gpe_event_info->register_bit;
166 /* GPE currently enabled? (enabled for runtime?) */
168 if (register_bit & gpe_register_info->enable_for_run) {
169 local_event_status |= ACPI_EVENT_FLAG_ENABLED;
172 /* GPE enabled for wake? */
174 if (register_bit & gpe_register_info->enable_for_wake) {
175 local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
178 /* GPE currently active (status bit == 1)? */
180 status = acpi_hw_low_level_read (8, &in_byte, &gpe_register_info->status_address);
181 if (ACPI_FAILURE (status)) {
182 goto unlock_and_exit;
185 if (register_bit & in_byte) {
186 local_event_status |= ACPI_EVENT_FLAG_SET;
189 /* Set return value */
191 (*event_status) = local_event_status;
194 unlock_and_exit:
195 return (status);
197 #endif /* ACPI_FUTURE_USAGE */
200 /******************************************************************************
202 * FUNCTION: acpi_hw_disable_gpe_block
204 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
205 * gpe_block - Gpe Block info
207 * RETURN: Status
209 * DESCRIPTION: Disable all GPEs within a GPE block
211 ******************************************************************************/
213 acpi_status
214 acpi_hw_disable_gpe_block (
215 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
216 struct acpi_gpe_block_info *gpe_block)
218 u32 i;
219 acpi_status status;
222 /* Examine each GPE Register within the block */
224 for (i = 0; i < gpe_block->register_count; i++) {
225 /* Disable all GPEs in this register */
227 status = acpi_hw_low_level_write (8, 0x00,
228 &gpe_block->register_info[i].enable_address);
229 if (ACPI_FAILURE (status)) {
230 return (status);
234 return (AE_OK);
238 /******************************************************************************
240 * FUNCTION: acpi_hw_clear_gpe_block
242 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
243 * gpe_block - Gpe Block info
245 * RETURN: Status
247 * DESCRIPTION: Clear status bits for all GPEs within a GPE block
249 ******************************************************************************/
251 acpi_status
252 acpi_hw_clear_gpe_block (
253 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
254 struct acpi_gpe_block_info *gpe_block)
256 u32 i;
257 acpi_status status;
260 /* Examine each GPE Register within the block */
262 for (i = 0; i < gpe_block->register_count; i++) {
263 /* Clear status on all GPEs in this register */
265 status = acpi_hw_low_level_write (8, 0xFF,
266 &gpe_block->register_info[i].status_address);
267 if (ACPI_FAILURE (status)) {
268 return (status);
272 return (AE_OK);
276 /******************************************************************************
278 * FUNCTION: acpi_hw_enable_runtime_gpe_block
280 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
281 * gpe_block - Gpe Block info
283 * RETURN: Status
285 * DESCRIPTION: Enable all "runtime" GPEs within a GPE block. (Includes
286 * combination wake/run GPEs.)
288 ******************************************************************************/
290 acpi_status
291 acpi_hw_enable_runtime_gpe_block (
292 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
293 struct acpi_gpe_block_info *gpe_block)
295 u32 i;
296 acpi_status status;
299 /* NOTE: assumes that all GPEs are currently disabled */
301 /* Examine each GPE Register within the block */
303 for (i = 0; i < gpe_block->register_count; i++) {
304 if (!gpe_block->register_info[i].enable_for_run) {
305 continue;
308 /* Enable all "runtime" GPEs in this register */
310 status = acpi_hw_low_level_write (8, gpe_block->register_info[i].enable_for_run,
311 &gpe_block->register_info[i].enable_address);
312 if (ACPI_FAILURE (status)) {
313 return (status);
317 return (AE_OK);
321 /******************************************************************************
323 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
325 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
326 * gpe_block - Gpe Block info
328 * RETURN: Status
330 * DESCRIPTION: Enable all "wake" GPEs within a GPE block. (Includes
331 * combination wake/run GPEs.)
333 ******************************************************************************/
335 acpi_status
336 acpi_hw_enable_wakeup_gpe_block (
337 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
338 struct acpi_gpe_block_info *gpe_block)
340 u32 i;
341 acpi_status status;
344 /* Examine each GPE Register within the block */
346 for (i = 0; i < gpe_block->register_count; i++) {
347 if (!gpe_block->register_info[i].enable_for_wake) {
348 continue;
351 /* Enable all "wake" GPEs in this register */
353 status = acpi_hw_low_level_write (8, gpe_block->register_info[i].enable_for_wake,
354 &gpe_block->register_info[i].enable_address);
355 if (ACPI_FAILURE (status)) {
356 return (status);
360 return (AE_OK);
364 /******************************************************************************
366 * FUNCTION: acpi_hw_disable_all_gpes
368 * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
370 * RETURN: Status
372 * DESCRIPTION: Disable and clear all GPEs
374 ******************************************************************************/
376 acpi_status
377 acpi_hw_disable_all_gpes (
378 u32 flags)
380 acpi_status status;
383 ACPI_FUNCTION_TRACE ("hw_disable_all_gpes");
386 status = acpi_ev_walk_gpe_list (acpi_hw_disable_gpe_block, flags);
387 status = acpi_ev_walk_gpe_list (acpi_hw_clear_gpe_block, flags);
388 return_ACPI_STATUS (status);
392 /******************************************************************************
394 * FUNCTION: acpi_hw_enable_all_runtime_gpes
396 * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
398 * RETURN: Status
400 * DESCRIPTION: Enable all GPEs of the given type
402 ******************************************************************************/
404 acpi_status
405 acpi_hw_enable_all_runtime_gpes (
406 u32 flags)
408 acpi_status status;
411 ACPI_FUNCTION_TRACE ("hw_enable_all_runtime_gpes");
414 status = acpi_ev_walk_gpe_list (acpi_hw_enable_runtime_gpe_block, flags);
415 return_ACPI_STATUS (status);
419 /******************************************************************************
421 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
423 * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
425 * RETURN: Status
427 * DESCRIPTION: Enable all GPEs of the given type
429 ******************************************************************************/
431 acpi_status
432 acpi_hw_enable_all_wakeup_gpes (
433 u32 flags)
435 acpi_status status;
438 ACPI_FUNCTION_TRACE ("hw_enable_all_wakeup_gpes");
441 status = acpi_ev_walk_gpe_list (acpi_hw_enable_wakeup_gpe_block, flags);
442 return_ACPI_STATUS (status);