[POWERPC] Don't use HOSTCFLAGS in BOOTCFLAGS
[linux-ginger.git] / drivers / acpi / hardware / hwgpe.c
blob117a05cadaaa9014ca2a6c5b29a5fa566accca08
2 /******************************************************************************
4 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2007, R. Byron Moore
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 <acpi/acevents.h>
48 #define _COMPONENT ACPI_HARDWARE
49 ACPI_MODULE_NAME("hwgpe")
51 /* Local prototypes */
52 static acpi_status
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_write_gpe_enable_reg
60 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
62 * RETURN: Status
64 * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
65 * already be cleared or set in the parent register
66 * enable_for_run mask.
68 ******************************************************************************/
70 acpi_status
71 acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info *gpe_event_info)
73 struct acpi_gpe_register_info *gpe_register_info;
74 acpi_status status;
76 ACPI_FUNCTION_ENTRY();
78 /* Get the info block for the entire GPE register */
80 gpe_register_info = gpe_event_info->register_info;
81 if (!gpe_register_info) {
82 return (AE_NOT_EXIST);
85 /* Write the entire GPE (runtime) enable register */
87 status = acpi_hw_low_level_write(8, gpe_register_info->enable_for_run,
88 &gpe_register_info->enable_address);
90 return (status);
93 /******************************************************************************
95 * FUNCTION: acpi_hw_clear_gpe
97 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
99 * RETURN: Status
101 * DESCRIPTION: Clear the status bit for a single GPE.
103 ******************************************************************************/
105 acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
107 acpi_status status;
108 u8 register_bit;
110 ACPI_FUNCTION_ENTRY();
112 register_bit = (u8)
113 (1 <<
114 (gpe_event_info->gpe_number -
115 gpe_event_info->register_info->base_gpe_number));
118 * Write a one to the appropriate bit in the status register to
119 * clear this GPE.
121 status = acpi_hw_low_level_write(8, register_bit,
122 &gpe_event_info->register_info->
123 status_address);
125 return (status);
128 /******************************************************************************
130 * FUNCTION: acpi_hw_get_gpe_status
132 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
133 * event_status - Where the GPE status is returned
135 * RETURN: Status
137 * DESCRIPTION: Return the status of a single GPE.
139 ******************************************************************************/
141 #ifdef ACPI_FUTURE_USAGE
142 acpi_status
143 acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
144 acpi_event_status * event_status)
146 u32 in_byte;
147 u8 register_bit;
148 struct acpi_gpe_register_info *gpe_register_info;
149 acpi_status status;
150 acpi_event_status local_event_status = 0;
152 ACPI_FUNCTION_ENTRY();
154 if (!event_status) {
155 return (AE_BAD_PARAMETER);
158 /* Get the info block for the entire GPE register */
160 gpe_register_info = gpe_event_info->register_info;
162 /* Get the register bitmask for this GPE */
164 register_bit = (u8)
165 (1 <<
166 (gpe_event_info->gpe_number -
167 gpe_event_info->register_info->base_gpe_number));
169 /* GPE currently enabled? (enabled for runtime?) */
171 if (register_bit & gpe_register_info->enable_for_run) {
172 local_event_status |= ACPI_EVENT_FLAG_ENABLED;
175 /* GPE enabled for wake? */
177 if (register_bit & gpe_register_info->enable_for_wake) {
178 local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
181 /* GPE currently active (status bit == 1)? */
183 status =
184 acpi_hw_low_level_read(8, &in_byte,
185 &gpe_register_info->status_address);
186 if (ACPI_FAILURE(status)) {
187 goto unlock_and_exit;
190 if (register_bit & in_byte) {
191 local_event_status |= ACPI_EVENT_FLAG_SET;
194 /* Set return value */
196 (*event_status) = local_event_status;
198 unlock_and_exit:
199 return (status);
201 #endif /* ACPI_FUTURE_USAGE */
203 /******************************************************************************
205 * FUNCTION: acpi_hw_disable_gpe_block
207 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
208 * gpe_block - Gpe Block info
210 * RETURN: Status
212 * DESCRIPTION: Disable all GPEs within a single GPE block
214 ******************************************************************************/
216 acpi_status
217 acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info * gpe_xrupt_info,
218 struct acpi_gpe_block_info * gpe_block)
220 u32 i;
221 acpi_status status;
223 /* Examine each GPE Register within the block */
225 for (i = 0; i < gpe_block->register_count; i++) {
227 /* Disable all GPEs in this register */
229 status = acpi_hw_low_level_write(8, 0x00,
230 &gpe_block->register_info[i].
231 enable_address);
232 if (ACPI_FAILURE(status)) {
233 return (status);
237 return (AE_OK);
240 /******************************************************************************
242 * FUNCTION: acpi_hw_clear_gpe_block
244 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
245 * gpe_block - Gpe Block info
247 * RETURN: Status
249 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
251 ******************************************************************************/
253 acpi_status
254 acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info * gpe_xrupt_info,
255 struct acpi_gpe_block_info * gpe_block)
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 /* Clear status on all GPEs in this register */
266 status = acpi_hw_low_level_write(8, 0xFF,
267 &gpe_block->register_info[i].
268 status_address);
269 if (ACPI_FAILURE(status)) {
270 return (status);
274 return (AE_OK);
277 /******************************************************************************
279 * FUNCTION: acpi_hw_enable_runtime_gpe_block
281 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
282 * gpe_block - Gpe Block info
284 * RETURN: Status
286 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
287 * combination wake/run GPEs.
289 ******************************************************************************/
291 acpi_status
292 acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info * gpe_xrupt_info,
293 struct acpi_gpe_block_info * gpe_block)
295 u32 i;
296 acpi_status status;
298 /* NOTE: assumes that all GPEs are currently disabled */
300 /* Examine each GPE Register within the block */
302 for (i = 0; i < gpe_block->register_count; i++) {
303 if (!gpe_block->register_info[i].enable_for_run) {
304 continue;
307 /* Enable all "runtime" GPEs in this register */
309 status =
310 acpi_hw_low_level_write(8,
311 gpe_block->register_info[i].
312 enable_for_run,
313 &gpe_block->register_info[i].
314 enable_address);
315 if (ACPI_FAILURE(status)) {
316 return (status);
320 return (AE_OK);
323 /******************************************************************************
325 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
327 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
328 * gpe_block - Gpe Block info
330 * RETURN: Status
332 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
333 * combination wake/run GPEs.
335 ******************************************************************************/
337 static acpi_status
338 acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
339 struct acpi_gpe_block_info *gpe_block)
341 u32 i;
342 acpi_status status;
344 /* Examine each GPE Register within the block */
346 for (i = 0; i < gpe_block->register_count; i++) {
347 if (!gpe_block->register_info[i].enable_for_wake) {
348 continue;
351 /* Enable all "wake" GPEs in this register */
353 status = acpi_hw_low_level_write(8,
354 gpe_block->register_info[i].
355 enable_for_wake,
356 &gpe_block->register_info[i].
357 enable_address);
358 if (ACPI_FAILURE(status)) {
359 return (status);
363 return (AE_OK);
366 /******************************************************************************
368 * FUNCTION: acpi_hw_disable_all_gpes
370 * PARAMETERS: None
372 * RETURN: Status
374 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
376 ******************************************************************************/
378 acpi_status acpi_hw_disable_all_gpes(void)
380 acpi_status status;
382 ACPI_FUNCTION_TRACE(hw_disable_all_gpes);
384 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block);
385 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block);
386 return_ACPI_STATUS(status);
389 /******************************************************************************
391 * FUNCTION: acpi_hw_enable_all_runtime_gpes
393 * PARAMETERS: None
395 * RETURN: Status
397 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
399 ******************************************************************************/
401 acpi_status acpi_hw_enable_all_runtime_gpes(void)
403 acpi_status status;
405 ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes);
407 status = acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block);
408 return_ACPI_STATUS(status);
411 /******************************************************************************
413 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
415 * PARAMETERS: None
417 * RETURN: Status
419 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
421 ******************************************************************************/
423 acpi_status acpi_hw_enable_all_wakeup_gpes(void)
425 acpi_status status;
427 ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes);
429 status = acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block);
430 return_ACPI_STATUS(status);