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
,
57 /******************************************************************************
59 * FUNCTION: acpi_hw_low_disable_gpe
61 * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled
65 * DESCRIPTION: Disable a single GPE in the enable register.
67 ******************************************************************************/
69 acpi_status
acpi_hw_low_disable_gpe(struct acpi_gpe_event_info
*gpe_event_info
)
71 struct acpi_gpe_register_info
*gpe_register_info
;
75 /* Get the info block for the entire GPE register */
77 gpe_register_info
= gpe_event_info
->register_info
;
78 if (!gpe_register_info
) {
79 return (AE_NOT_EXIST
);
82 /* Get current value of the enable register that contains this GPE */
84 status
= acpi_hw_low_level_read(ACPI_GPE_REGISTER_WIDTH
, &enable_mask
,
85 &gpe_register_info
->enable_address
);
86 if (ACPI_FAILURE(status
)) {
90 /* Clear just the bit that corresponds to this GPE */
92 ACPI_CLEAR_BIT(enable_mask
,
94 (gpe_event_info
->gpe_number
-
95 gpe_register_info
->base_gpe_number
)));
97 /* Write the updated enable mask */
99 status
= acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH
, enable_mask
,
100 &gpe_register_info
->enable_address
);
105 /******************************************************************************
107 * FUNCTION: acpi_hw_write_gpe_enable_reg
109 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
113 * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
114 * already be cleared or set in the parent register
115 * enable_for_run mask.
117 ******************************************************************************/
120 acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info
* gpe_event_info
)
122 struct acpi_gpe_register_info
*gpe_register_info
;
125 ACPI_FUNCTION_ENTRY();
127 /* Get the info block for the entire GPE register */
129 gpe_register_info
= gpe_event_info
->register_info
;
130 if (!gpe_register_info
) {
131 return (AE_NOT_EXIST
);
134 /* Write the entire GPE (runtime) enable register */
136 status
= acpi_hw_low_level_write(8, gpe_register_info
->enable_for_run
,
137 &gpe_register_info
->enable_address
);
142 /******************************************************************************
144 * FUNCTION: acpi_hw_clear_gpe
146 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
150 * DESCRIPTION: Clear the status bit for a single GPE.
152 ******************************************************************************/
154 acpi_status
acpi_hw_clear_gpe(struct acpi_gpe_event_info
* gpe_event_info
)
159 ACPI_FUNCTION_ENTRY();
163 (gpe_event_info
->gpe_number
-
164 gpe_event_info
->register_info
->base_gpe_number
));
167 * Write a one to the appropriate bit in the status register to
170 status
= acpi_hw_low_level_write(8, register_bit
,
171 &gpe_event_info
->register_info
->
177 /******************************************************************************
179 * FUNCTION: acpi_hw_get_gpe_status
181 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
182 * event_status - Where the GPE status is returned
186 * DESCRIPTION: Return the status of a single GPE.
188 ******************************************************************************/
191 acpi_hw_get_gpe_status(struct acpi_gpe_event_info
* gpe_event_info
,
192 acpi_event_status
* event_status
)
196 struct acpi_gpe_register_info
*gpe_register_info
;
198 acpi_event_status local_event_status
= 0;
200 ACPI_FUNCTION_ENTRY();
203 return (AE_BAD_PARAMETER
);
206 /* Get the info block for the entire GPE register */
208 gpe_register_info
= gpe_event_info
->register_info
;
210 /* Get the register bitmask for this GPE */
214 (gpe_event_info
->gpe_number
-
215 gpe_event_info
->register_info
->base_gpe_number
));
217 /* GPE currently enabled? (enabled for runtime?) */
219 if (register_bit
& gpe_register_info
->enable_for_run
) {
220 local_event_status
|= ACPI_EVENT_FLAG_ENABLED
;
223 /* GPE enabled for wake? */
225 if (register_bit
& gpe_register_info
->enable_for_wake
) {
226 local_event_status
|= ACPI_EVENT_FLAG_WAKE_ENABLED
;
229 /* GPE currently active (status bit == 1)? */
232 acpi_hw_low_level_read(8, &in_byte
,
233 &gpe_register_info
->status_address
);
234 if (ACPI_FAILURE(status
)) {
235 goto unlock_and_exit
;
238 if (register_bit
& in_byte
) {
239 local_event_status
|= ACPI_EVENT_FLAG_SET
;
242 /* Set return value */
244 (*event_status
) = local_event_status
;
250 /******************************************************************************
252 * FUNCTION: acpi_hw_disable_gpe_block
254 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
255 * gpe_block - Gpe Block info
259 * DESCRIPTION: Disable all GPEs within a single GPE block
261 ******************************************************************************/
264 acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
265 struct acpi_gpe_block_info
*gpe_block
, void *context
)
270 /* Examine each GPE Register within the block */
272 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
274 /* Disable all GPEs in this register */
276 status
= acpi_hw_low_level_write(8, 0x00,
277 &gpe_block
->register_info
[i
].
279 if (ACPI_FAILURE(status
)) {
287 /******************************************************************************
289 * FUNCTION: acpi_hw_clear_gpe_block
291 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
292 * gpe_block - Gpe Block info
296 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
298 ******************************************************************************/
301 acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
302 struct acpi_gpe_block_info
*gpe_block
, void *context
)
307 /* Examine each GPE Register within the block */
309 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
311 /* Clear status on all GPEs in this register */
313 status
= acpi_hw_low_level_write(8, 0xFF,
314 &gpe_block
->register_info
[i
].
316 if (ACPI_FAILURE(status
)) {
324 /******************************************************************************
326 * FUNCTION: acpi_hw_enable_runtime_gpe_block
328 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
329 * gpe_block - Gpe Block info
333 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
334 * combination wake/run GPEs.
336 ******************************************************************************/
339 acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
340 struct acpi_gpe_block_info
*gpe_block
, void *context
)
345 /* NOTE: assumes that all GPEs are currently disabled */
347 /* Examine each GPE Register within the block */
349 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
350 if (!gpe_block
->register_info
[i
].enable_for_run
) {
354 /* Enable all "runtime" GPEs in this register */
357 acpi_hw_low_level_write(8,
358 gpe_block
->register_info
[i
].
360 &gpe_block
->register_info
[i
].
362 if (ACPI_FAILURE(status
)) {
370 /******************************************************************************
372 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
374 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
375 * gpe_block - Gpe Block info
379 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
380 * combination wake/run GPEs.
382 ******************************************************************************/
385 acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
386 struct acpi_gpe_block_info
*gpe_block
,
392 /* Examine each GPE Register within the block */
394 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
395 if (!gpe_block
->register_info
[i
].enable_for_wake
) {
399 /* Enable all "wake" GPEs in this register */
401 status
= acpi_hw_low_level_write(8,
402 gpe_block
->register_info
[i
].
404 &gpe_block
->register_info
[i
].
406 if (ACPI_FAILURE(status
)) {
414 /******************************************************************************
416 * FUNCTION: acpi_hw_disable_all_gpes
422 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
424 ******************************************************************************/
426 acpi_status
acpi_hw_disable_all_gpes(void)
430 ACPI_FUNCTION_TRACE(hw_disable_all_gpes
);
432 status
= acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block
, NULL
);
433 status
= acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block
, NULL
);
434 return_ACPI_STATUS(status
);
437 /******************************************************************************
439 * FUNCTION: acpi_hw_enable_all_runtime_gpes
445 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
447 ******************************************************************************/
449 acpi_status
acpi_hw_enable_all_runtime_gpes(void)
453 ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes
);
455 status
= acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block
, NULL
);
456 return_ACPI_STATUS(status
);
459 /******************************************************************************
461 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
467 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
469 ******************************************************************************/
471 acpi_status
acpi_hw_enable_all_wakeup_gpes(void)
475 ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes
);
477 status
= acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block
, NULL
);
478 return_ACPI_STATUS(status
);