Merge branch 'for-linus' of git://oss.sgi.com/xfs/xfs
[linux/fpc-iii.git] / drivers / acpi / acpica / hwgpe.c
blobbd72319a38f00fa9357bf76a01976b792e574a01
2 /******************************************************************************
4 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
6 *****************************************************************************/
8 /*
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
14 * are met:
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.
31 * NO WARRANTY
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 "accommon.h"
47 #include "acevents.h"
49 #define _COMPONENT ACPI_HARDWARE
50 ACPI_MODULE_NAME("hwgpe")
52 /* Local prototypes */
53 static acpi_status
54 acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
55 struct acpi_gpe_block_info *gpe_block,
56 void *context);
58 /******************************************************************************
60 * FUNCTION: acpi_hw_low_disable_gpe
62 * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled
64 * RETURN: Status
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;
73 acpi_status status;
74 u32 enable_mask;
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_hw_read(&enable_mask, &gpe_register_info->enable_address);
86 if (ACPI_FAILURE(status)) {
87 return (status);
90 /* Clear just the bit that corresponds to this GPE */
92 ACPI_CLEAR_BIT(enable_mask, ((u32)1 <<
93 (gpe_event_info->gpe_number -
94 gpe_register_info->base_gpe_number)));
96 /* Write the updated enable mask */
98 status = acpi_hw_write(enable_mask, &gpe_register_info->enable_address);
99 return (status);
102 /******************************************************************************
104 * FUNCTION: acpi_hw_write_gpe_enable_reg
106 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
108 * RETURN: Status
110 * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
111 * already be cleared or set in the parent register
112 * enable_for_run mask.
114 ******************************************************************************/
116 acpi_status
117 acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info * gpe_event_info)
119 struct acpi_gpe_register_info *gpe_register_info;
120 acpi_status status;
122 ACPI_FUNCTION_ENTRY();
124 /* Get the info block for the entire GPE register */
126 gpe_register_info = gpe_event_info->register_info;
127 if (!gpe_register_info) {
128 return (AE_NOT_EXIST);
131 /* Write the entire GPE (runtime) enable register */
133 status = acpi_hw_write(gpe_register_info->enable_for_run,
134 &gpe_register_info->enable_address);
136 return (status);
139 /******************************************************************************
141 * FUNCTION: acpi_hw_clear_gpe
143 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
145 * RETURN: Status
147 * DESCRIPTION: Clear the status bit for a single GPE.
149 ******************************************************************************/
151 acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
153 acpi_status status;
154 u8 register_bit;
156 ACPI_FUNCTION_ENTRY();
158 register_bit = (u8)(1 <<
159 (gpe_event_info->gpe_number -
160 gpe_event_info->register_info->base_gpe_number));
163 * Write a one to the appropriate bit in the status register to
164 * clear this GPE.
166 status = acpi_hw_write(register_bit,
167 &gpe_event_info->register_info->status_address);
169 return (status);
172 /******************************************************************************
174 * FUNCTION: acpi_hw_get_gpe_status
176 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
177 * event_status - Where the GPE status is returned
179 * RETURN: Status
181 * DESCRIPTION: Return the status of a single GPE.
183 ******************************************************************************/
185 acpi_status
186 acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
187 acpi_event_status * event_status)
189 u32 in_byte;
190 u8 register_bit;
191 struct acpi_gpe_register_info *gpe_register_info;
192 acpi_status status;
193 acpi_event_status local_event_status = 0;
195 ACPI_FUNCTION_ENTRY();
197 if (!event_status) {
198 return (AE_BAD_PARAMETER);
201 /* Get the info block for the entire GPE register */
203 gpe_register_info = gpe_event_info->register_info;
205 /* Get the register bitmask for this GPE */
207 register_bit = (u8)(1 <<
208 (gpe_event_info->gpe_number -
209 gpe_event_info->register_info->base_gpe_number));
211 /* GPE currently enabled? (enabled for runtime?) */
213 if (register_bit & gpe_register_info->enable_for_run) {
214 local_event_status |= ACPI_EVENT_FLAG_ENABLED;
217 /* GPE enabled for wake? */
219 if (register_bit & gpe_register_info->enable_for_wake) {
220 local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
223 /* GPE currently active (status bit == 1)? */
225 status = acpi_hw_read(&in_byte, &gpe_register_info->status_address);
226 if (ACPI_FAILURE(status)) {
227 return (status);
230 if (register_bit & in_byte) {
231 local_event_status |= ACPI_EVENT_FLAG_SET;
234 /* Set return value */
236 (*event_status) = local_event_status;
237 return (AE_OK);
240 /******************************************************************************
242 * FUNCTION: acpi_hw_disable_gpe_block
244 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
245 * gpe_block - Gpe Block info
247 * RETURN: Status
249 * DESCRIPTION: Disable all GPEs within a single GPE block
251 ******************************************************************************/
253 acpi_status
254 acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
255 struct acpi_gpe_block_info *gpe_block, void *context)
257 u32 i;
258 acpi_status status;
260 /* Examine each GPE Register within the block */
262 for (i = 0; i < gpe_block->register_count; i++) {
264 /* Disable all GPEs in this register */
266 status =
267 acpi_hw_write(0x00,
268 &gpe_block->register_info[i].enable_address);
269 if (ACPI_FAILURE(status)) {
270 return (status);
274 return (AE_OK);
277 /******************************************************************************
279 * FUNCTION: acpi_hw_clear_gpe_block
281 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
282 * gpe_block - Gpe Block info
284 * RETURN: Status
286 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
288 ******************************************************************************/
290 acpi_status
291 acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
292 struct acpi_gpe_block_info *gpe_block, void *context)
294 u32 i;
295 acpi_status status;
297 /* Examine each GPE Register within the block */
299 for (i = 0; i < gpe_block->register_count; i++) {
301 /* Clear status on all GPEs in this register */
303 status =
304 acpi_hw_write(0xFF,
305 &gpe_block->register_info[i].status_address);
306 if (ACPI_FAILURE(status)) {
307 return (status);
311 return (AE_OK);
314 /******************************************************************************
316 * FUNCTION: acpi_hw_enable_runtime_gpe_block
318 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
319 * gpe_block - Gpe Block info
321 * RETURN: Status
323 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
324 * combination wake/run GPEs.
326 ******************************************************************************/
328 acpi_status
329 acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
330 struct acpi_gpe_block_info *gpe_block, void *context)
332 u32 i;
333 acpi_status status;
335 /* NOTE: assumes that all GPEs are currently disabled */
337 /* Examine each GPE Register within the block */
339 for (i = 0; i < gpe_block->register_count; i++) {
340 if (!gpe_block->register_info[i].enable_for_run) {
341 continue;
344 /* Enable all "runtime" GPEs in this register */
346 status =
347 acpi_hw_write(gpe_block->register_info[i].enable_for_run,
348 &gpe_block->register_info[i].enable_address);
349 if (ACPI_FAILURE(status)) {
350 return (status);
354 return (AE_OK);
357 /******************************************************************************
359 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
361 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
362 * gpe_block - Gpe Block info
364 * RETURN: Status
366 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
367 * combination wake/run GPEs.
369 ******************************************************************************/
371 static acpi_status
372 acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
373 struct acpi_gpe_block_info *gpe_block,
374 void *context)
376 u32 i;
377 acpi_status status;
379 /* Examine each GPE Register within the block */
381 for (i = 0; i < gpe_block->register_count; i++) {
382 if (!gpe_block->register_info[i].enable_for_wake) {
383 continue;
386 /* Enable all "wake" GPEs in this register */
388 status =
389 acpi_hw_write(gpe_block->register_info[i].enable_for_wake,
390 &gpe_block->register_info[i].enable_address);
391 if (ACPI_FAILURE(status)) {
392 return (status);
396 return (AE_OK);
399 /******************************************************************************
401 * FUNCTION: acpi_hw_disable_all_gpes
403 * PARAMETERS: None
405 * RETURN: Status
407 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
409 ******************************************************************************/
411 acpi_status acpi_hw_disable_all_gpes(void)
413 acpi_status status;
415 ACPI_FUNCTION_TRACE(hw_disable_all_gpes);
417 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
418 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
419 return_ACPI_STATUS(status);
422 /******************************************************************************
424 * FUNCTION: acpi_hw_enable_all_runtime_gpes
426 * PARAMETERS: None
428 * RETURN: Status
430 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
432 ******************************************************************************/
434 acpi_status acpi_hw_enable_all_runtime_gpes(void)
436 acpi_status status;
438 ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes);
440 status = acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block, NULL);
441 return_ACPI_STATUS(status);
444 /******************************************************************************
446 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
448 * PARAMETERS: None
450 * RETURN: Status
452 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
454 ******************************************************************************/
456 acpi_status acpi_hw_enable_all_wakeup_gpes(void)
458 acpi_status status;
460 ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes);
462 status = acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block, NULL);
463 return_ACPI_STATUS(status);