- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / acpi / events / evxfevnt.c
blob5b7652e52bd7e194383674432757dcd8ae3b1f66
1 /******************************************************************************
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4 * $Revision: 26 $
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "acpi.h"
28 #include "achware.h"
29 #include "acnamesp.h"
30 #include "acevents.h"
31 #include "amlcode.h"
32 #include "acinterp.h"
34 #define _COMPONENT EVENT_HANDLING
35 MODULE_NAME ("evxfevnt")
38 /**************************************************************************
40 * FUNCTION: Acpi_enable
42 * PARAMETERS: None
44 * RETURN: Status
46 * DESCRIPTION: Transfers the system into ACPI mode.
48 *************************************************************************/
50 ACPI_STATUS
51 acpi_enable (void)
53 ACPI_STATUS status;
56 /* Make sure we've got ACPI tables */
58 if (!acpi_gbl_DSDT) {
59 return (AE_NO_ACPI_TABLES);
62 /* Make sure the BIOS supports ACPI mode */
64 if (SYS_MODE_LEGACY == acpi_hw_get_mode_capabilities()) {
65 return (AE_ERROR);
68 /* Transition to ACPI mode */
70 status = acpi_hw_set_mode (SYS_MODE_ACPI);
71 if (ACPI_FAILURE (status)) {
72 return (status);
75 return (status);
79 /**************************************************************************
81 * FUNCTION: Acpi_disable
83 * PARAMETERS: None
85 * RETURN: Status
87 * DESCRIPTION: Returns the system to original ACPI/legacy mode, and
88 * uninstalls the SCI interrupt handler.
90 *************************************************************************/
92 ACPI_STATUS
93 acpi_disable (void)
95 ACPI_STATUS status;
98 /* Restore original mode */
100 status = acpi_hw_set_mode (acpi_gbl_original_mode);
101 if (ACPI_FAILURE (status)) {
102 return (status);
105 /* Unload the SCI interrupt handler */
107 acpi_ev_remove_sci_handler ();
108 acpi_ev_restore_acpi_state ();
110 return (status);
114 /******************************************************************************
116 * FUNCTION: Acpi_enable_event
118 * PARAMETERS: Event - The fixed event or GPE to be enabled
119 * Type - The type of event
121 * RETURN: Status
123 * DESCRIPTION: Enable an ACPI event (fixed and general purpose)
125 ******************************************************************************/
127 ACPI_STATUS
128 acpi_enable_event (
129 u32 event,
130 u32 type)
132 ACPI_STATUS status = AE_OK;
133 u32 register_id;
136 /* The Type must be either Fixed Acpi_event or GPE */
138 switch (type)
141 case ACPI_EVENT_FIXED:
143 /* Decode the Fixed Acpi_event */
145 switch (event)
147 case ACPI_EVENT_PMTIMER:
148 register_id = TMR_EN;
149 break;
151 case ACPI_EVENT_GLOBAL:
152 register_id = GBL_EN;
153 break;
155 case ACPI_EVENT_POWER_BUTTON:
156 register_id = PWRBTN_EN;
157 break;
159 case ACPI_EVENT_SLEEP_BUTTON:
160 register_id = SLPBTN_EN;
161 break;
163 case ACPI_EVENT_RTC:
164 register_id = RTC_EN;
165 break;
167 default:
168 return (AE_BAD_PARAMETER);
169 break;
173 * Enable the requested fixed event (by writing a one to the
174 * enable register bit)
177 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_LOCK, register_id, 1);
179 if (1 != acpi_hw_register_bit_access(ACPI_READ, ACPI_MTX_LOCK, register_id)) {
180 return (AE_ERROR);
183 break;
186 case ACPI_EVENT_GPE:
188 /* Ensure that we have a valid GPE number */
190 if ((event >= NUM_GPE) ||
191 (acpi_gbl_gpe_valid[event] == ACPI_GPE_INVALID))
193 return (AE_BAD_PARAMETER);
197 /* Enable the requested GPE number */
199 acpi_hw_enable_gpe (event);
200 break;
203 default:
205 status = AE_BAD_PARAMETER;
209 return (status);
213 /******************************************************************************
215 * FUNCTION: Acpi_disable_event
217 * PARAMETERS: Event - The fixed event or GPE to be enabled
218 * Type - The type of event
220 * RETURN: Status
222 * DESCRIPTION: Disable an ACPI event (fixed and general purpose)
224 ******************************************************************************/
226 ACPI_STATUS
227 acpi_disable_event (
228 u32 event,
229 u32 type)
231 ACPI_STATUS status = AE_OK;
232 u32 register_id;
235 /* The Type must be either Fixed Acpi_event or GPE */
237 switch (type)
240 case ACPI_EVENT_FIXED:
242 /* Decode the Fixed Acpi_event */
244 switch (event)
246 case ACPI_EVENT_PMTIMER:
247 register_id = TMR_EN;
248 break;
250 case ACPI_EVENT_GLOBAL:
251 register_id = GBL_EN;
252 break;
254 case ACPI_EVENT_POWER_BUTTON:
255 register_id = PWRBTN_EN;
256 break;
258 case ACPI_EVENT_SLEEP_BUTTON:
259 register_id = SLPBTN_EN;
260 break;
262 case ACPI_EVENT_RTC:
263 register_id = RTC_EN;
264 break;
266 default:
267 return (AE_BAD_PARAMETER);
268 break;
272 * Disable the requested fixed event (by writing a zero to the
273 * enable register bit)
276 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_LOCK, register_id, 0);
278 if (0 != acpi_hw_register_bit_access(ACPI_READ, ACPI_MTX_LOCK, register_id)) {
279 return (AE_ERROR);
282 break;
285 case ACPI_EVENT_GPE:
287 /* Ensure that we have a valid GPE number */
289 if ((event >= NUM_GPE) ||
290 (acpi_gbl_gpe_valid[event] == ACPI_GPE_INVALID))
292 return (AE_BAD_PARAMETER);
295 /* Disable the requested GPE number */
297 acpi_hw_disable_gpe (event);
298 break;
301 default:
302 status = AE_BAD_PARAMETER;
305 return (status);
309 /******************************************************************************
311 * FUNCTION: Acpi_clear_event
313 * PARAMETERS: Event - The fixed event or GPE to be cleared
314 * Type - The type of event
316 * RETURN: Status
318 * DESCRIPTION: Clear an ACPI event (fixed and general purpose)
320 ******************************************************************************/
322 ACPI_STATUS
323 acpi_clear_event (
324 u32 event,
325 u32 type)
327 ACPI_STATUS status = AE_OK;
328 u32 register_id;
331 /* The Type must be either Fixed Acpi_event or GPE */
333 switch (type)
336 case ACPI_EVENT_FIXED:
338 /* Decode the Fixed Acpi_event */
340 switch (event)
342 case ACPI_EVENT_PMTIMER:
343 register_id = TMR_STS;
344 break;
346 case ACPI_EVENT_GLOBAL:
347 register_id = GBL_STS;
348 break;
350 case ACPI_EVENT_POWER_BUTTON:
351 register_id = PWRBTN_STS;
352 break;
354 case ACPI_EVENT_SLEEP_BUTTON:
355 register_id = SLPBTN_STS;
356 break;
358 case ACPI_EVENT_RTC:
359 register_id = RTC_STS;
360 break;
362 default:
363 return (AE_BAD_PARAMETER);
364 break;
368 * Clear the requested fixed event (By writing a one to the
369 * status register bit)
372 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_LOCK, register_id, 1);
373 break;
376 case ACPI_EVENT_GPE:
378 /* Ensure that we have a valid GPE number */
380 if ((event >= NUM_GPE) ||
381 (acpi_gbl_gpe_valid[event] == ACPI_GPE_INVALID))
383 return (AE_BAD_PARAMETER);
387 acpi_hw_clear_gpe (event);
388 break;
391 default:
393 status = AE_BAD_PARAMETER;
396 return (status);
400 /******************************************************************************
402 * FUNCTION: Acpi_get_event_status
404 * PARAMETERS: Event - The fixed event or GPE
405 * Type - The type of event
406 * Status - Where the current status of the event will
407 * be returned
409 * RETURN: Status
411 * DESCRIPTION: Obtains and returns the current status of the event
413 ******************************************************************************/
416 ACPI_STATUS
417 acpi_get_event_status (
418 u32 event,
419 u32 type,
420 ACPI_EVENT_STATUS *event_status)
422 ACPI_STATUS status = AE_OK;
423 u32 register_id;
426 if (!event_status) {
427 return (AE_BAD_PARAMETER);
431 /* The Type must be either Fixed Acpi_event or GPE */
433 switch (type)
436 case ACPI_EVENT_FIXED:
438 /* Decode the Fixed Acpi_event */
440 switch (event)
442 case ACPI_EVENT_PMTIMER:
443 register_id = TMR_STS;
444 break;
446 case ACPI_EVENT_GLOBAL:
447 register_id = GBL_STS;
448 break;
450 case ACPI_EVENT_POWER_BUTTON:
451 register_id = PWRBTN_STS;
452 break;
454 case ACPI_EVENT_SLEEP_BUTTON:
455 register_id = SLPBTN_STS;
456 break;
458 case ACPI_EVENT_RTC:
459 register_id = RTC_STS;
460 break;
462 default:
463 return (AE_BAD_PARAMETER);
464 break;
467 /* Get the status of the requested fixed event */
469 *event_status = acpi_hw_register_bit_access (ACPI_READ, ACPI_MTX_LOCK, register_id);
470 break;
473 case ACPI_EVENT_GPE:
475 /* Ensure that we have a valid GPE number */
477 if ((event >= NUM_GPE) ||
478 (acpi_gbl_gpe_valid[event] == ACPI_GPE_INVALID))
480 return (AE_BAD_PARAMETER);
484 /* Obtain status on the requested GPE number */
486 acpi_hw_get_gpe_status (event, event_status);
487 break;
490 default:
491 status = AE_BAD_PARAMETER;
495 return (status);