The real, definitive, Visual C++ support branch. Accept no substitutes
[reactos.git] / drivers / bus / acpi / events / evxfevnt.c
1 /******************************************************************************
2 *
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4 * $Revision: 1.1 $
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000, 2001 R. Byron Moore
10 *
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.
15 *
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.
20 *
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
24 */
25
26
27 #include <acpi.h>
28
29 #define _COMPONENT ACPI_EVENTS
30 MODULE_NAME ("evxfevnt")
31
32
33 /**************************************************************************
34 *
35 * FUNCTION: Acpi_enable
36 *
37 * PARAMETERS: None
38 *
39 * RETURN: Status
40 *
41 * DESCRIPTION: Transfers the system into ACPI mode.
42 *
43 *************************************************************************/
44
45 ACPI_STATUS
46 acpi_enable (void)
47 {
48 ACPI_STATUS status;
49
50
51 /* Make sure we've got ACPI tables */
52
53 if (!acpi_gbl_DSDT) {
54 return (AE_NO_ACPI_TABLES);
55 }
56
57 /* Make sure the BIOS supports ACPI mode */
58
59 if (SYS_MODE_LEGACY == acpi_hw_get_mode_capabilities()) {
60 return (AE_ERROR);
61 }
62
63 /* Transition to ACPI mode */
64
65 status = acpi_hw_set_mode (SYS_MODE_ACPI);
66 if (ACPI_FAILURE (status)) {
67 return (status);
68 }
69
70 return (status);
71 }
72
73
74 /**************************************************************************
75 *
76 * FUNCTION: Acpi_disable
77 *
78 * PARAMETERS: None
79 *
80 * RETURN: Status
81 *
82 * DESCRIPTION: Returns the system to original ACPI/legacy mode, and
83 * uninstalls the SCI interrupt handler.
84 *
85 *************************************************************************/
86
87 ACPI_STATUS
88 acpi_disable (void)
89 {
90 ACPI_STATUS status;
91
92
93 /* Restore original mode */
94
95 status = acpi_hw_set_mode (acpi_gbl_original_mode);
96 if (ACPI_FAILURE (status)) {
97 return (status);
98 }
99
100 /* Unload the SCI interrupt handler */
101
102 acpi_ev_remove_sci_handler ();
103 acpi_ev_restore_acpi_state ();
104
105 return (status);
106 }
107
108
109 /******************************************************************************
110 *
111 * FUNCTION: Acpi_enable_event
112 *
113 * PARAMETERS: Event - The fixed event or GPE to be enabled
114 * Type - The type of event
115 *
116 * RETURN: Status
117 *
118 * DESCRIPTION: Enable an ACPI event (fixed and general purpose)
119 *
120 ******************************************************************************/
121
122 ACPI_STATUS
123 acpi_enable_event (
124 u32 event,
125 u32 type)
126 {
127 ACPI_STATUS status = AE_OK;
128 u32 register_id;
129
130
131 /* The Type must be either Fixed Acpi_event or GPE */
132
133 switch (type) {
134
135 case ACPI_EVENT_FIXED:
136
137 /* Decode the Fixed Acpi_event */
138
139 switch (event) {
140 case ACPI_EVENT_PMTIMER:
141 register_id = TMR_EN;
142 break;
143
144 case ACPI_EVENT_GLOBAL:
145 register_id = GBL_EN;
146 break;
147
148 case ACPI_EVENT_POWER_BUTTON:
149 register_id = PWRBTN_EN;
150 break;
151
152 case ACPI_EVENT_SLEEP_BUTTON:
153 register_id = SLPBTN_EN;
154 break;
155
156 case ACPI_EVENT_RTC:
157 register_id = RTC_EN;
158 break;
159
160 default:
161 return (AE_BAD_PARAMETER);
162 break;
163 }
164
165 /*
166 * Enable the requested fixed event (by writing a one to the
167 * enable register bit)
168 */
169
170 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_LOCK, register_id, 1);
171
172 if (1 != acpi_hw_register_bit_access(ACPI_READ, ACPI_MTX_LOCK, register_id)) {
173 return (AE_NO_HARDWARE_RESPONSE);
174 }
175
176 break;
177
178
179 case ACPI_EVENT_GPE:
180
181 /* Ensure that we have a valid GPE number */
182
183 if ((event >= NUM_GPE) ||
184 (acpi_gbl_gpe_valid[event] == ACPI_GPE_INVALID)) {
185 return (AE_BAD_PARAMETER);
186 }
187
188
189 /* Enable the requested GPE number */
190
191 acpi_hw_enable_gpe (event);
192 break;
193
194
195 default:
196
197 status = AE_BAD_PARAMETER;
198 }
199
200
201 return (status);
202 }
203
204
205 /******************************************************************************
206 *
207 * FUNCTION: Acpi_disable_event
208 *
209 * PARAMETERS: Event - The fixed event or GPE to be enabled
210 * Type - The type of event
211 *
212 * RETURN: Status
213 *
214 * DESCRIPTION: Disable an ACPI event (fixed and general purpose)
215 *
216 ******************************************************************************/
217
218 ACPI_STATUS
219 acpi_disable_event (
220 u32 event,
221 u32 type)
222 {
223 ACPI_STATUS status = AE_OK;
224 u32 register_id;
225
226
227 /* The Type must be either Fixed Acpi_event or GPE */
228
229 switch (type) {
230
231 case ACPI_EVENT_FIXED:
232
233 /* Decode the Fixed Acpi_event */
234
235 switch (event) {
236 case ACPI_EVENT_PMTIMER:
237 register_id = TMR_EN;
238 break;
239
240 case ACPI_EVENT_GLOBAL:
241 register_id = GBL_EN;
242 break;
243
244 case ACPI_EVENT_POWER_BUTTON:
245 register_id = PWRBTN_EN;
246 break;
247
248 case ACPI_EVENT_SLEEP_BUTTON:
249 register_id = SLPBTN_EN;
250 break;
251
252 case ACPI_EVENT_RTC:
253 register_id = RTC_EN;
254 break;
255
256 default:
257 return (AE_BAD_PARAMETER);
258 break;
259 }
260
261 /*
262 * Disable the requested fixed event (by writing a zero to the
263 * enable register bit)
264 */
265
266 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_LOCK, register_id, 0);
267
268 if (0 != acpi_hw_register_bit_access(ACPI_READ, ACPI_MTX_LOCK, register_id)) {
269 return (AE_NO_HARDWARE_RESPONSE);
270 }
271
272 break;
273
274
275 case ACPI_EVENT_GPE:
276
277 /* Ensure that we have a valid GPE number */
278
279 if ((event >= NUM_GPE) ||
280 (acpi_gbl_gpe_valid[event] == ACPI_GPE_INVALID)) {
281 return (AE_BAD_PARAMETER);
282 }
283
284 /* Disable the requested GPE number */
285
286 acpi_hw_disable_gpe (event);
287 break;
288
289
290 default:
291 status = AE_BAD_PARAMETER;
292 }
293
294 return (status);
295 }
296
297
298 /******************************************************************************
299 *
300 * FUNCTION: Acpi_clear_event
301 *
302 * PARAMETERS: Event - The fixed event or GPE to be cleared
303 * Type - The type of event
304 *
305 * RETURN: Status
306 *
307 * DESCRIPTION: Clear an ACPI event (fixed and general purpose)
308 *
309 ******************************************************************************/
310
311 ACPI_STATUS
312 acpi_clear_event (
313 u32 event,
314 u32 type)
315 {
316 ACPI_STATUS status = AE_OK;
317 u32 register_id;
318
319
320 /* The Type must be either Fixed Acpi_event or GPE */
321
322 switch (type) {
323
324 case ACPI_EVENT_FIXED:
325
326 /* Decode the Fixed Acpi_event */
327
328 switch (event) {
329 case ACPI_EVENT_PMTIMER:
330 register_id = TMR_STS;
331 break;
332
333 case ACPI_EVENT_GLOBAL:
334 register_id = GBL_STS;
335 break;
336
337 case ACPI_EVENT_POWER_BUTTON:
338 register_id = PWRBTN_STS;
339 break;
340
341 case ACPI_EVENT_SLEEP_BUTTON:
342 register_id = SLPBTN_STS;
343 break;
344
345 case ACPI_EVENT_RTC:
346 register_id = RTC_STS;
347 break;
348
349 default:
350 return (AE_BAD_PARAMETER);
351 break;
352 }
353
354 /*
355 * Clear the requested fixed event (By writing a one to the
356 * status register bit)
357 */
358
359 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_LOCK, register_id, 1);
360 break;
361
362
363 case ACPI_EVENT_GPE:
364
365 /* Ensure that we have a valid GPE number */
366
367 if ((event >= NUM_GPE) ||
368 (acpi_gbl_gpe_valid[event] == ACPI_GPE_INVALID)) {
369 return (AE_BAD_PARAMETER);
370 }
371
372
373 acpi_hw_clear_gpe (event);
374 break;
375
376
377 default:
378
379 status = AE_BAD_PARAMETER;
380 }
381
382 return (status);
383 }
384
385
386 /******************************************************************************
387 *
388 * FUNCTION: Acpi_get_event_status
389 *
390 * PARAMETERS: Event - The fixed event or GPE
391 * Type - The type of event
392 * Status - Where the current status of the event will
393 * be returned
394 *
395 * RETURN: Status
396 *
397 * DESCRIPTION: Obtains and returns the current status of the event
398 *
399 ******************************************************************************/
400
401
402 ACPI_STATUS
403 acpi_get_event_status (
404 u32 event,
405 u32 type,
406 ACPI_EVENT_STATUS *event_status)
407 {
408 ACPI_STATUS status = AE_OK;
409 u32 register_id;
410
411
412 if (!event_status) {
413 return (AE_BAD_PARAMETER);
414 }
415
416
417 /* The Type must be either Fixed Acpi_event or GPE */
418
419 switch (type) {
420
421 case ACPI_EVENT_FIXED:
422
423 /* Decode the Fixed Acpi_event */
424
425 switch (event) {
426 case ACPI_EVENT_PMTIMER:
427 register_id = TMR_STS;
428 break;
429
430 case ACPI_EVENT_GLOBAL:
431 register_id = GBL_STS;
432 break;
433
434 case ACPI_EVENT_POWER_BUTTON:
435 register_id = PWRBTN_STS;
436 break;
437
438 case ACPI_EVENT_SLEEP_BUTTON:
439 register_id = SLPBTN_STS;
440 break;
441
442 case ACPI_EVENT_RTC:
443 register_id = RTC_STS;
444 break;
445
446 default:
447 return (AE_BAD_PARAMETER);
448 break;
449 }
450
451 /* Get the status of the requested fixed event */
452
453 *event_status = acpi_hw_register_bit_access (ACPI_READ, ACPI_MTX_LOCK, register_id);
454 break;
455
456
457 case ACPI_EVENT_GPE:
458
459 /* Ensure that we have a valid GPE number */
460
461 if ((event >= NUM_GPE) ||
462 (acpi_gbl_gpe_valid[event] == ACPI_GPE_INVALID)) {
463 return (AE_BAD_PARAMETER);
464 }
465
466
467 /* Obtain status on the requested GPE number */
468
469 acpi_hw_get_gpe_status (event, event_status);
470 break;
471
472
473 default:
474 status = AE_BAD_PARAMETER;
475 }
476
477
478 return (status);
479 }
480