2 /******************************************************************************
4 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2008, Intel Corp.
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")
51 /* Local prototypes */
53 acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
54 struct acpi_gpe_block_info *gpe_block);
56 /******************************************************************************
58 * FUNCTION: acpi_hw_low_disable_gpe
60 * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled
64 * DESCRIPTION: Disable a single GPE in the enable register.
66 ******************************************************************************/
68 acpi_status acpi_hw_low_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
70 struct acpi_gpe_register_info *gpe_register_info;
74 /* Get the info block for the entire GPE register */
76 gpe_register_info = gpe_event_info->register_info;
77 if (!gpe_register_info) {
78 return (AE_NOT_EXIST);
81 /* Get current value of the enable register that contains this GPE */
83 status = acpi_hw_low_level_read(ACPI_GPE_REGISTER_WIDTH, &enable_mask,
84 &gpe_register_info->enable_address);
85 if (ACPI_FAILURE(status)) {
89 /* Clear just the bit that corresponds to this GPE */
91 ACPI_CLEAR_BIT(enable_mask,
93 (gpe_event_info->gpe_number -
94 gpe_register_info->base_gpe_number)));
96 /* Write the updated enable mask */
98 status = acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH, enable_mask,
99 &gpe_register_info->enable_address);
104 /******************************************************************************
106 * FUNCTION: acpi_hw_write_gpe_enable_reg
108 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
112 * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
113 * already be cleared or set in the parent register
114 * enable_for_run mask.
116 ******************************************************************************/
119 acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info * gpe_event_info)
121 struct acpi_gpe_register_info *gpe_register_info;
124 ACPI_FUNCTION_ENTRY();
126 /* Get the info block for the entire GPE register */
128 gpe_register_info = gpe_event_info->register_info;
129 if (!gpe_register_info) {
130 return (AE_NOT_EXIST);
133 /* Write the entire GPE (runtime) enable register */
135 status = acpi_hw_low_level_write(8, gpe_register_info->enable_for_run,
136 &gpe_register_info->enable_address);
141 /******************************************************************************
143 * FUNCTION: acpi_hw_clear_gpe
145 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
149 * DESCRIPTION: Clear the status bit for a single GPE.
151 ******************************************************************************/
153 acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
158 ACPI_FUNCTION_ENTRY();
162 (gpe_event_info->gpe_number -
163 gpe_event_info->register_info->base_gpe_number));
166 * Write a one to the appropriate bit in the status register to
169 status = acpi_hw_low_level_write(8, register_bit,
170 &gpe_event_info->register_info->
176 /******************************************************************************
178 * FUNCTION: acpi_hw_get_gpe_status
180 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
181 * event_status - Where the GPE status is returned
185 * DESCRIPTION: Return the status of a single GPE.
187 ******************************************************************************/
190 acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
191 acpi_event_status * event_status)
195 struct acpi_gpe_register_info *gpe_register_info;
197 acpi_event_status local_event_status = 0;
199 ACPI_FUNCTION_ENTRY();
202 return (AE_BAD_PARAMETER);
205 /* Get the info block for the entire GPE register */
207 gpe_register_info = gpe_event_info->register_info;
209 /* Get the register bitmask for this GPE */
213 (gpe_event_info->gpe_number -
214 gpe_event_info->register_info->base_gpe_number));
216 /* GPE currently enabled? (enabled for runtime?) */
218 if (register_bit & gpe_register_info->enable_for_run) {
219 local_event_status |= ACPI_EVENT_FLAG_ENABLED;
222 /* GPE enabled for wake? */
224 if (register_bit & gpe_register_info->enable_for_wake) {
225 local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
228 /* GPE currently active (status bit == 1)? */
231 acpi_hw_low_level_read(8, &in_byte,
232 &gpe_register_info->status_address);
233 if (ACPI_FAILURE(status)) {
234 goto unlock_and_exit;
237 if (register_bit & in_byte) {
238 local_event_status |= ACPI_EVENT_FLAG_SET;
241 /* Set return value */
243 (*event_status) = local_event_status;
249 /******************************************************************************
251 * FUNCTION: acpi_hw_disable_gpe_block
253 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
254 * gpe_block - Gpe Block info
258 * DESCRIPTION: Disable all GPEs within a single GPE block
260 ******************************************************************************/
263 acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info * gpe_xrupt_info,
264 struct acpi_gpe_block_info * gpe_block)
269 /* Examine each GPE Register within the block */
271 for (i = 0; i < gpe_block->register_count; i++) {
273 /* Disable all GPEs in this register */
275 status = acpi_hw_low_level_write(8, 0x00,
276 &gpe_block->register_info[i].
278 if (ACPI_FAILURE(status)) {
286 /******************************************************************************
288 * FUNCTION: acpi_hw_clear_gpe_block
290 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
291 * gpe_block - Gpe Block info
295 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
297 ******************************************************************************/
300 acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info * gpe_xrupt_info,
301 struct acpi_gpe_block_info * gpe_block)
306 /* Examine each GPE Register within the block */
308 for (i = 0; i < gpe_block->register_count; i++) {
310 /* Clear status on all GPEs in this register */
312 status = acpi_hw_low_level_write(8, 0xFF,
313 &gpe_block->register_info[i].
315 if (ACPI_FAILURE(status)) {
323 /******************************************************************************
325 * FUNCTION: acpi_hw_enable_runtime_gpe_block
327 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
328 * gpe_block - Gpe Block info
332 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
333 * combination wake/run GPEs.
335 ******************************************************************************/
338 acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info * gpe_xrupt_info,
339 struct acpi_gpe_block_info * gpe_block)
344 /* NOTE: assumes that all GPEs are currently disabled */
346 /* Examine each GPE Register within the block */
348 for (i = 0; i < gpe_block->register_count; i++) {
349 if (!gpe_block->register_info[i].enable_for_run) {
353 /* Enable all "runtime" GPEs in this register */
356 acpi_hw_low_level_write(8,
357 gpe_block->register_info[i].
359 &gpe_block->register_info[i].
361 if (ACPI_FAILURE(status)) {
369 /******************************************************************************
371 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
373 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
374 * gpe_block - Gpe Block info
378 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
379 * combination wake/run GPEs.
381 ******************************************************************************/
384 acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
385 struct acpi_gpe_block_info *gpe_block)
390 /* Examine each GPE Register within the block */
392 for (i = 0; i < gpe_block->register_count; i++) {
393 if (!gpe_block->register_info[i].enable_for_wake) {
397 /* Enable all "wake" GPEs in this register */
399 status = acpi_hw_low_level_write(8,
400 gpe_block->register_info[i].
402 &gpe_block->register_info[i].
404 if (ACPI_FAILURE(status)) {
412 /******************************************************************************
414 * FUNCTION: acpi_hw_disable_all_gpes
420 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
422 ******************************************************************************/
424 acpi_status acpi_hw_disable_all_gpes(void)
428 ACPI_FUNCTION_TRACE(hw_disable_all_gpes);
430 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block);
431 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block);
432 return_ACPI_STATUS(status);
435 /******************************************************************************
437 * FUNCTION: acpi_hw_enable_all_runtime_gpes
443 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
445 ******************************************************************************/
447 acpi_status acpi_hw_enable_all_runtime_gpes(void)
451 ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes);
453 status = acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block);
454 return_ACPI_STATUS(status);
457 /******************************************************************************
459 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
465 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
467 ******************************************************************************/
469 acpi_status acpi_hw_enable_all_wakeup_gpes(void)
473 ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes);
475 status = acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block);
476 return_ACPI_STATUS(status);