2 /******************************************************************************
4 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2004, 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
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.
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_enable_gpe
56 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
60 * DESCRIPTION: Enable a single GPE.
62 ******************************************************************************/
66 struct acpi_gpe_event_info *gpe_event_info)
72 ACPI_FUNCTION_ENTRY ();
76 * Read the current value of the register, set the appropriate bit
77 * to enable the GPE, and write out the new register.
79 status = acpi_hw_low_level_read (8, &in_byte,
80 &gpe_event_info->register_info->enable_address);
81 if (ACPI_FAILURE (status)) {
85 /* Write with the new GPE bit enabled */
87 status = acpi_hw_low_level_write (8, (in_byte | gpe_event_info->bit_mask),
88 &gpe_event_info->register_info->enable_address);
94 /******************************************************************************
96 * FUNCTION: acpi_hw_enable_gpe_for_wakeup
98 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
102 * DESCRIPTION: Keep track of which GPEs the OS has requested not be
103 * disabled when going to sleep.
105 ******************************************************************************/
108 acpi_hw_enable_gpe_for_wakeup (
109 struct acpi_gpe_event_info *gpe_event_info)
111 struct acpi_gpe_register_info *gpe_register_info;
114 ACPI_FUNCTION_ENTRY ();
117 /* Get the info block for the entire GPE register */
119 gpe_register_info = gpe_event_info->register_info;
120 if (!gpe_register_info) {
125 * Set the bit so we will not enable this GPE when sleeping (and disable
128 gpe_register_info->wake_enable |= gpe_event_info->bit_mask;
129 gpe_event_info->flags |= (ACPI_GPE_TYPE_WAKE | ACPI_GPE_ENABLED);
133 /******************************************************************************
135 * FUNCTION: acpi_hw_disable_gpe
137 * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled
141 * DESCRIPTION: Disable a single GPE.
143 ******************************************************************************/
146 acpi_hw_disable_gpe (
147 struct acpi_gpe_event_info *gpe_event_info)
151 struct acpi_gpe_register_info *gpe_register_info;
154 ACPI_FUNCTION_ENTRY ();
157 /* Get the info block for the entire GPE register */
159 gpe_register_info = gpe_event_info->register_info;
160 if (!gpe_register_info) {
161 return (AE_BAD_PARAMETER);
165 * Read the current value of the register, clear the appropriate bit,
166 * and write out the new register value to disable the GPE.
168 status = acpi_hw_low_level_read (8, &in_byte,
169 &gpe_register_info->enable_address);
170 if (ACPI_FAILURE (status)) {
174 /* Write the byte with this GPE bit cleared */
176 status = acpi_hw_low_level_write (8, (in_byte & ~(gpe_event_info->bit_mask)),
177 &gpe_register_info->enable_address);
178 if (ACPI_FAILURE (status)) {
182 /* Make sure this GPE is disabled for wake, also */
184 acpi_hw_disable_gpe_for_wakeup (gpe_event_info);
189 /******************************************************************************
191 * FUNCTION: acpi_hw_disable_gpe_for_wakeup
193 * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled
197 * DESCRIPTION: Keep track of which GPEs the OS has requested not be
198 * disabled when going to sleep.
200 ******************************************************************************/
203 acpi_hw_disable_gpe_for_wakeup (
204 struct acpi_gpe_event_info *gpe_event_info)
206 struct acpi_gpe_register_info *gpe_register_info;
209 ACPI_FUNCTION_ENTRY ();
212 /* Get the info block for the entire GPE register */
214 gpe_register_info = gpe_event_info->register_info;
215 if (!gpe_register_info) {
219 /* Clear the bit so we will disable this when sleeping */
221 gpe_register_info->wake_enable &= ~(gpe_event_info->bit_mask);
225 /******************************************************************************
227 * FUNCTION: acpi_hw_clear_gpe
229 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
231 * RETURN: status_status
233 * DESCRIPTION: Clear the status bit for a single GPE.
235 ******************************************************************************/
239 struct acpi_gpe_event_info *gpe_event_info)
244 ACPI_FUNCTION_ENTRY ();
248 * Write a one to the appropriate bit in the status register to
251 status = acpi_hw_low_level_write (8, gpe_event_info->bit_mask,
252 &gpe_event_info->register_info->status_address);
258 /******************************************************************************
260 * FUNCTION: acpi_hw_get_gpe_status
262 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
263 * event_status - Where the GPE status is returned
267 * DESCRIPTION: Return the status of a single GPE.
269 ******************************************************************************/
272 acpi_hw_get_gpe_status (
273 struct acpi_gpe_event_info *gpe_event_info,
274 acpi_event_status *event_status)
278 struct acpi_gpe_register_info *gpe_register_info;
280 acpi_event_status local_event_status = 0;
283 ACPI_FUNCTION_ENTRY ();
287 return (AE_BAD_PARAMETER);
290 /* Get the info block for the entire GPE register */
292 gpe_register_info = gpe_event_info->register_info;
294 /* Get the register bitmask for this GPE */
296 bit_mask = gpe_event_info->bit_mask;
300 status = acpi_hw_low_level_read (8, &in_byte, &gpe_register_info->enable_address);
301 if (ACPI_FAILURE (status)) {
302 goto unlock_and_exit;
305 if (bit_mask & in_byte) {
306 local_event_status |= ACPI_EVENT_FLAG_ENABLED;
309 /* GPE Enabled for wake? */
311 if (bit_mask & gpe_register_info->wake_enable) {
312 local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
315 /* GPE active (set)? */
317 status = acpi_hw_low_level_read (8, &in_byte, &gpe_register_info->status_address);
318 if (ACPI_FAILURE (status)) {
319 goto unlock_and_exit;
322 if (bit_mask & in_byte) {
323 local_event_status |= ACPI_EVENT_FLAG_SET;
326 /* Set return value */
328 (*event_status) = local_event_status;
336 /******************************************************************************
338 * FUNCTION: acpi_hw_disable_gpe_block
340 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
341 * gpe_block - Gpe Block info
345 * DESCRIPTION: Disable all GPEs within a GPE block
347 ******************************************************************************/
350 acpi_hw_disable_gpe_block (
351 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
352 struct acpi_gpe_block_info *gpe_block)
358 /* Examine each GPE Register within the block */
360 for (i = 0; i < gpe_block->register_count; i++) {
361 /* Disable all GPEs in this register */
363 status = acpi_hw_low_level_write (8, 0x00,
364 &gpe_block->register_info[i].enable_address);
365 if (ACPI_FAILURE (status)) {
374 /******************************************************************************
376 * FUNCTION: acpi_hw_clear_gpe_block
378 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
379 * gpe_block - Gpe Block info
383 * DESCRIPTION: Clear status bits for all GPEs within a GPE block
385 ******************************************************************************/
388 acpi_hw_clear_gpe_block (
389 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
390 struct acpi_gpe_block_info *gpe_block)
396 /* Examine each GPE Register within the block */
398 for (i = 0; i < gpe_block->register_count; i++) {
399 /* Clear status on all GPEs in this register */
401 status = acpi_hw_low_level_write (8, 0xFF,
402 &gpe_block->register_info[i].status_address);
403 if (ACPI_FAILURE (status)) {
412 /******************************************************************************
414 * FUNCTION: acpi_hw_prepare_gpe_block_for_sleep
416 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
417 * gpe_block - Gpe Block info
421 * DESCRIPTION: Disable all runtime GPEs and enable all wakeup GPEs -- within
424 ******************************************************************************/
427 acpi_hw_prepare_gpe_block_for_sleep (
428 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
429 struct acpi_gpe_block_info *gpe_block)
432 struct acpi_gpe_register_info *gpe_register_info;
437 /* Get the register info for the entire GPE block */
439 gpe_register_info = gpe_block->register_info;
441 /* Examine each GPE Register within the block */
443 for (i = 0; i < gpe_block->register_count; i++) {
445 * Read the enabled/disabled status of all GPEs. We
446 * will be using it to restore all the GPEs later.
448 * NOTE: Wake GPEs are are ALL disabled at this time, so when we wake
449 * and restore this register, they will be automatically disabled.
451 status = acpi_hw_low_level_read (8, &in_value,
452 &gpe_register_info->enable_address);
453 if (ACPI_FAILURE (status)) {
457 gpe_register_info->enable = (u8) in_value;
460 * 1) Disable all runtime GPEs
461 * 2) Enable all wakeup GPEs
463 status = acpi_hw_low_level_write (8, gpe_register_info->wake_enable,
464 &gpe_register_info->enable_address);
465 if (ACPI_FAILURE (status)) {
469 /* Point to next GPE register */
478 /******************************************************************************
480 * FUNCTION: acpi_hw_prepare_gpes_for_sleep
486 * DESCRIPTION: Disable all runtime GPEs, enable all wake GPEs.
487 * Called with interrupts disabled. The interrupt handler also
488 * modifies gpe_register_info->Enable, so it should not be
489 * given the chance to run until after the runtime GPEs are
492 ******************************************************************************/
495 acpi_hw_prepare_gpes_for_sleep (
501 ACPI_FUNCTION_ENTRY ();
504 status = acpi_ev_walk_gpe_list (acpi_hw_prepare_gpe_block_for_sleep);
509 /******************************************************************************
511 * FUNCTION: acpi_hw_restore_gpe_block_on_wake
513 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
514 * gpe_block - Gpe Block info
518 * DESCRIPTION: Enable all runtime GPEs and disable all wake GPEs -- in one
521 ******************************************************************************/
524 acpi_hw_restore_gpe_block_on_wake (
525 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
526 struct acpi_gpe_block_info *gpe_block)
529 struct acpi_gpe_register_info *gpe_register_info;
533 /* This callback processes one entire GPE block */
535 /* Get the register info for the entire GPE block */
537 gpe_register_info = gpe_block->register_info;
539 /* Examine each GPE register within the block */
541 for (i = 0; i < gpe_block->register_count; i++) {
542 /* Clear the entire status register */
544 status = acpi_hw_low_level_write (8, 0xFF,
545 &gpe_block->register_info[i].status_address);
546 if (ACPI_FAILURE (status)) {
551 * Restore the GPE Enable register, which will do the following:
553 * 1) Disable all wakeup GPEs
554 * 2) Enable all runtime GPEs
556 * (On sleep, we saved the enabled status of all GPEs)
558 status = acpi_hw_low_level_write (8, gpe_register_info->enable,
559 &gpe_register_info->enable_address);
560 if (ACPI_FAILURE (status)) {
564 /* Point to next GPE register */
573 /******************************************************************************
575 * FUNCTION: acpi_hw_restore_gpes_on_wake
581 * DESCRIPTION: Enable all runtime GPEs and disable all wake GPEs -- in all
584 ******************************************************************************/
587 acpi_hw_restore_gpes_on_wake (
593 ACPI_FUNCTION_ENTRY ();
596 status = acpi_ev_walk_gpe_list (acpi_hw_restore_gpe_block_on_wake);