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>
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_low_disable_gpe
62 * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled
66 * DESCRIPTION: Disable a single GPE in the enable register.
68 ******************************************************************************/
70 acpi_status
acpi_hw_low_disable_gpe(struct acpi_gpe_event_info
*gpe_event_info
)
72 struct acpi_gpe_register_info
*gpe_register_info
;
76 /* Get the info block for the entire GPE register */
78 gpe_register_info
= gpe_event_info
->register_info
;
79 if (!gpe_register_info
) {
80 return (AE_NOT_EXIST
);
83 /* Get current value of the enable register that contains this GPE */
85 status
= acpi_read(&enable_mask
, &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_write(enable_mask
, &gpe_register_info
->enable_address
);
103 /******************************************************************************
105 * FUNCTION: acpi_hw_write_gpe_enable_reg
107 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
111 * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
112 * already be cleared or set in the parent register
113 * enable_for_run mask.
115 ******************************************************************************/
118 acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info
* gpe_event_info
)
120 struct acpi_gpe_register_info
*gpe_register_info
;
123 ACPI_FUNCTION_ENTRY();
125 /* Get the info block for the entire GPE register */
127 gpe_register_info
= gpe_event_info
->register_info
;
128 if (!gpe_register_info
) {
129 return (AE_NOT_EXIST
);
132 /* Write the entire GPE (runtime) enable register */
134 status
= acpi_write(gpe_register_info
->enable_for_run
,
135 &gpe_register_info
->enable_address
);
140 /******************************************************************************
142 * FUNCTION: acpi_hw_clear_gpe
144 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
148 * DESCRIPTION: Clear the status bit for a single GPE.
150 ******************************************************************************/
152 acpi_status
acpi_hw_clear_gpe(struct acpi_gpe_event_info
* gpe_event_info
)
157 ACPI_FUNCTION_ENTRY();
161 (gpe_event_info
->gpe_number
-
162 gpe_event_info
->register_info
->base_gpe_number
));
165 * Write a one to the appropriate bit in the status register to
168 status
= acpi_write(register_bit
,
169 &gpe_event_info
->register_info
->status_address
);
174 /******************************************************************************
176 * FUNCTION: acpi_hw_get_gpe_status
178 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
179 * event_status - Where the GPE status is returned
183 * DESCRIPTION: Return the status of a single GPE.
185 ******************************************************************************/
188 acpi_hw_get_gpe_status(struct acpi_gpe_event_info
* gpe_event_info
,
189 acpi_event_status
* event_status
)
193 struct acpi_gpe_register_info
*gpe_register_info
;
195 acpi_event_status local_event_status
= 0;
197 ACPI_FUNCTION_ENTRY();
200 return (AE_BAD_PARAMETER
);
203 /* Get the info block for the entire GPE register */
205 gpe_register_info
= gpe_event_info
->register_info
;
207 /* Get the register bitmask for this GPE */
211 (gpe_event_info
->gpe_number
-
212 gpe_event_info
->register_info
->base_gpe_number
));
214 /* GPE currently enabled? (enabled for runtime?) */
216 if (register_bit
& gpe_register_info
->enable_for_run
) {
217 local_event_status
|= ACPI_EVENT_FLAG_ENABLED
;
220 /* GPE enabled for wake? */
222 if (register_bit
& gpe_register_info
->enable_for_wake
) {
223 local_event_status
|= ACPI_EVENT_FLAG_WAKE_ENABLED
;
226 /* GPE currently active (status bit == 1)? */
228 status
= acpi_read(&in_byte
, &gpe_register_info
->status_address
);
229 if (ACPI_FAILURE(status
)) {
230 goto unlock_and_exit
;
233 if (register_bit
& in_byte
) {
234 local_event_status
|= ACPI_EVENT_FLAG_SET
;
237 /* Set return value */
239 (*event_status
) = local_event_status
;
245 /******************************************************************************
247 * FUNCTION: acpi_hw_disable_gpe_block
249 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
250 * gpe_block - Gpe Block info
254 * DESCRIPTION: Disable all GPEs within a single GPE block
256 ******************************************************************************/
259 acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
260 struct acpi_gpe_block_info
*gpe_block
, void *context
)
265 /* Examine each GPE Register within the block */
267 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
269 /* Disable all GPEs in this register */
273 &gpe_block
->register_info
[i
].enable_address
);
274 if (ACPI_FAILURE(status
)) {
282 /******************************************************************************
284 * FUNCTION: acpi_hw_clear_gpe_block
286 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
287 * gpe_block - Gpe Block info
291 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
293 ******************************************************************************/
296 acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
297 struct acpi_gpe_block_info
*gpe_block
, void *context
)
302 /* Examine each GPE Register within the block */
304 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
306 /* Clear status on all GPEs in this register */
310 &gpe_block
->register_info
[i
].status_address
);
311 if (ACPI_FAILURE(status
)) {
319 /******************************************************************************
321 * FUNCTION: acpi_hw_enable_runtime_gpe_block
323 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
324 * gpe_block - Gpe Block info
328 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
329 * combination wake/run GPEs.
331 ******************************************************************************/
334 acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
335 struct acpi_gpe_block_info
*gpe_block
, void *context
)
340 /* NOTE: assumes that all GPEs are currently disabled */
342 /* Examine each GPE Register within the block */
344 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
345 if (!gpe_block
->register_info
[i
].enable_for_run
) {
349 /* Enable all "runtime" GPEs in this register */
351 status
= acpi_write(gpe_block
->register_info
[i
].enable_for_run
,
352 &gpe_block
->register_info
[i
].
354 if (ACPI_FAILURE(status
)) {
362 /******************************************************************************
364 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
366 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
367 * gpe_block - Gpe Block info
371 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
372 * combination wake/run GPEs.
374 ******************************************************************************/
377 acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
378 struct acpi_gpe_block_info
*gpe_block
,
384 /* Examine each GPE Register within the block */
386 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
387 if (!gpe_block
->register_info
[i
].enable_for_wake
) {
391 /* Enable all "wake" GPEs in this register */
393 status
= acpi_write(gpe_block
->register_info
[i
].enable_for_wake
,
394 &gpe_block
->register_info
[i
].
396 if (ACPI_FAILURE(status
)) {
404 /******************************************************************************
406 * FUNCTION: acpi_hw_disable_all_gpes
412 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
414 ******************************************************************************/
416 acpi_status
acpi_hw_disable_all_gpes(void)
420 ACPI_FUNCTION_TRACE(hw_disable_all_gpes
);
422 status
= acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block
, NULL
);
423 status
= acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block
, NULL
);
424 return_ACPI_STATUS(status
);
427 /******************************************************************************
429 * FUNCTION: acpi_hw_enable_all_runtime_gpes
435 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
437 ******************************************************************************/
439 acpi_status
acpi_hw_enable_all_runtime_gpes(void)
443 ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes
);
445 status
= acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block
, NULL
);
446 return_ACPI_STATUS(status
);
449 /******************************************************************************
451 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
457 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
459 ******************************************************************************/
461 acpi_status
acpi_hw_enable_all_wakeup_gpes(void)
465 ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes
);
467 status
= acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block
, NULL
);
468 return_ACPI_STATUS(status
);