2 /******************************************************************************
4 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2010, 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>
49 #define _COMPONENT ACPI_HARDWARE
50 ACPI_MODULE_NAME("hwgpe")
52 /* Local prototypes */
54 acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
55 struct acpi_gpe_block_info *gpe_block,
58 /******************************************************************************
60 * FUNCTION: acpi_hw_gpe_register_bit
62 * PARAMETERS: gpe_event_info - Info block for the GPE
63 * gpe_register_info - Info block for the GPE register
67 * DESCRIPTION: Compute GPE enable mask with one bit corresponding to the given
70 ******************************************************************************/
72 u32 acpi_hw_gpe_register_bit(struct acpi_gpe_event_info *gpe_event_info,
73 struct acpi_gpe_register_info *gpe_register_info)
75 return (u32)1 << (gpe_event_info->gpe_number -
76 gpe_register_info->base_gpe_number);
79 /******************************************************************************
81 * FUNCTION: acpi_hw_low_disable_gpe
83 * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled
87 * DESCRIPTION: Disable a single GPE in the enable register.
89 ******************************************************************************/
91 acpi_status acpi_hw_low_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
93 struct acpi_gpe_register_info *gpe_register_info;
98 /* Get the info block for the entire GPE register */
100 gpe_register_info = gpe_event_info->register_info;
101 if (!gpe_register_info) {
102 return (AE_NOT_EXIST);
105 /* Get current value of the enable register that contains this GPE */
107 status = acpi_hw_read(&enable_mask, &gpe_register_info->enable_address);
108 if (ACPI_FAILURE(status)) {
112 /* Clear just the bit that corresponds to this GPE */
114 register_bit = acpi_hw_gpe_register_bit(gpe_event_info,
116 ACPI_CLEAR_BIT(enable_mask, register_bit);
118 /* Write the updated enable mask */
120 status = acpi_hw_write(enable_mask, &gpe_register_info->enable_address);
124 /******************************************************************************
126 * FUNCTION: acpi_hw_write_gpe_enable_reg
128 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
132 * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
133 * already be cleared or set in the parent register
134 * enable_for_run mask.
136 ******************************************************************************/
139 acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info * gpe_event_info)
141 struct acpi_gpe_register_info *gpe_register_info;
144 ACPI_FUNCTION_ENTRY();
146 /* Get the info block for the entire GPE register */
148 gpe_register_info = gpe_event_info->register_info;
149 if (!gpe_register_info) {
150 return (AE_NOT_EXIST);
153 /* Write the entire GPE (runtime) enable register */
155 status = acpi_hw_write(gpe_register_info->enable_for_run,
156 &gpe_register_info->enable_address);
161 /******************************************************************************
163 * FUNCTION: acpi_hw_clear_gpe
165 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
169 * DESCRIPTION: Clear the status bit for a single GPE.
171 ******************************************************************************/
173 acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
175 struct acpi_gpe_register_info *gpe_register_info;
179 ACPI_FUNCTION_ENTRY();
181 /* Get the info block for the entire GPE register */
183 gpe_register_info = gpe_event_info->register_info;
184 if (!gpe_register_info) {
185 return (AE_NOT_EXIST);
188 register_bit = acpi_hw_gpe_register_bit(gpe_event_info,
192 * Write a one to the appropriate bit in the status register to
195 status = acpi_hw_write(register_bit,
196 &gpe_register_info->status_address);
201 /******************************************************************************
203 * FUNCTION: acpi_hw_get_gpe_status
205 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
206 * event_status - Where the GPE status is returned
210 * DESCRIPTION: Return the status of a single GPE.
212 ******************************************************************************/
215 acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
216 acpi_event_status * event_status)
220 struct acpi_gpe_register_info *gpe_register_info;
222 acpi_event_status local_event_status = 0;
224 ACPI_FUNCTION_ENTRY();
227 return (AE_BAD_PARAMETER);
230 /* Get the info block for the entire GPE register */
232 gpe_register_info = gpe_event_info->register_info;
234 /* Get the register bitmask for this GPE */
236 register_bit = acpi_hw_gpe_register_bit(gpe_event_info,
239 /* GPE currently enabled? (enabled for runtime?) */
241 if (register_bit & gpe_register_info->enable_for_run) {
242 local_event_status |= ACPI_EVENT_FLAG_ENABLED;
245 /* GPE enabled for wake? */
247 if (register_bit & gpe_register_info->enable_for_wake) {
248 local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
251 /* GPE currently active (status bit == 1)? */
253 status = acpi_hw_read(&in_byte, &gpe_register_info->status_address);
254 if (ACPI_FAILURE(status)) {
258 if (register_bit & in_byte) {
259 local_event_status |= ACPI_EVENT_FLAG_SET;
262 /* Set return value */
264 (*event_status) = local_event_status;
268 /******************************************************************************
270 * FUNCTION: acpi_hw_disable_gpe_block
272 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
273 * gpe_block - Gpe Block info
277 * DESCRIPTION: Disable all GPEs within a single GPE block
279 ******************************************************************************/
282 acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
283 struct acpi_gpe_block_info *gpe_block, void *context)
288 /* Examine each GPE Register within the block */
290 for (i = 0; i < gpe_block->register_count; i++) {
292 /* Disable all GPEs in this register */
296 &gpe_block->register_info[i].enable_address);
297 if (ACPI_FAILURE(status)) {
305 /******************************************************************************
307 * FUNCTION: acpi_hw_clear_gpe_block
309 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
310 * gpe_block - Gpe Block info
314 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
316 ******************************************************************************/
319 acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
320 struct acpi_gpe_block_info *gpe_block, void *context)
325 /* Examine each GPE Register within the block */
327 for (i = 0; i < gpe_block->register_count; i++) {
329 /* Clear status on all GPEs in this register */
333 &gpe_block->register_info[i].status_address);
334 if (ACPI_FAILURE(status)) {
342 /******************************************************************************
344 * FUNCTION: acpi_hw_enable_runtime_gpe_block
346 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
347 * gpe_block - Gpe Block info
351 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
352 * combination wake/run GPEs.
354 ******************************************************************************/
357 acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
358 struct acpi_gpe_block_info *gpe_block, void *context)
363 /* NOTE: assumes that all GPEs are currently disabled */
365 /* Examine each GPE Register within the block */
367 for (i = 0; i < gpe_block->register_count; i++) {
368 if (!gpe_block->register_info[i].enable_for_run) {
372 /* Enable all "runtime" GPEs in this register */
375 acpi_hw_write(gpe_block->register_info[i].enable_for_run,
376 &gpe_block->register_info[i].enable_address);
377 if (ACPI_FAILURE(status)) {
385 /******************************************************************************
387 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
389 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
390 * gpe_block - Gpe Block info
394 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
395 * combination wake/run GPEs.
397 ******************************************************************************/
400 acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
401 struct acpi_gpe_block_info *gpe_block,
407 /* Examine each GPE Register within the block */
409 for (i = 0; i < gpe_block->register_count; i++) {
410 if (!gpe_block->register_info[i].enable_for_wake) {
414 /* Enable all "wake" GPEs in this register */
417 acpi_hw_write(gpe_block->register_info[i].enable_for_wake,
418 &gpe_block->register_info[i].enable_address);
419 if (ACPI_FAILURE(status)) {
427 /******************************************************************************
429 * FUNCTION: acpi_hw_disable_all_gpes
435 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
437 ******************************************************************************/
439 acpi_status acpi_hw_disable_all_gpes(void)
443 ACPI_FUNCTION_TRACE(hw_disable_all_gpes);
445 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
446 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
447 return_ACPI_STATUS(status);
450 /******************************************************************************
452 * FUNCTION: acpi_hw_enable_all_runtime_gpes
458 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
460 ******************************************************************************/
462 acpi_status acpi_hw_enable_all_runtime_gpes(void)
466 ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes);
468 status = acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block, NULL);
469 return_ACPI_STATUS(status);
472 /******************************************************************************
474 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
480 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
482 ******************************************************************************/
484 acpi_status acpi_hw_enable_all_wakeup_gpes(void)
488 ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes);
490 status = acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block, NULL);
491 return_ACPI_STATUS(status);