Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | |
2 | /****************************************************************************** | |
3 | * | |
4 | * Module Name: hwgpe - Low level GPE enable/disable/clear functions | |
5 | * | |
6 | *****************************************************************************/ | |
7 | ||
8 | /* | |
a8357b0c | 9 | * Copyright (C) 2000 - 2010, Intel Corp. |
1da177e4 LT |
10 | * All rights reserved. |
11 | * | |
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. | |
26 | * | |
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. | |
30 | * | |
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. | |
43 | */ | |
44 | ||
45 | #include <acpi/acpi.h> | |
e2f7a777 LB |
46 | #include "accommon.h" |
47 | #include "acevents.h" | |
1da177e4 LT |
48 | |
49 | #define _COMPONENT ACPI_HARDWARE | |
4be44fcd | 50 | ACPI_MODULE_NAME("hwgpe") |
1da177e4 | 51 | |
44f6c012 | 52 | /* Local prototypes */ |
44f6c012 | 53 | static acpi_status |
4be44fcd | 54 | acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, |
e97d6bf1 BM |
55 | struct acpi_gpe_block_info *gpe_block, |
56 | void *context); | |
1da177e4 | 57 | |
e4e9a735 RW |
58 | /****************************************************************************** |
59 | * | |
60 | * FUNCTION: acpi_hw_gpe_register_bit | |
61 | * | |
62 | * PARAMETERS: gpe_event_info - Info block for the GPE | |
63 | * gpe_register_info - Info block for the GPE register | |
64 | * | |
65 | * RETURN: Status | |
66 | * | |
67 | * DESCRIPTION: Compute GPE enable mask with one bit corresponding to the given | |
68 | * GPE set. | |
69 | * | |
70 | ******************************************************************************/ | |
71 | ||
72 | u32 acpi_hw_gpe_register_bit(struct acpi_gpe_event_info *gpe_event_info, | |
73 | struct acpi_gpe_register_info *gpe_register_info) | |
74 | { | |
75 | return (u32)1 << (gpe_event_info->gpe_number - | |
76 | gpe_register_info->base_gpe_number); | |
77 | } | |
78 | ||
e38e8a07 BM |
79 | /****************************************************************************** |
80 | * | |
81 | * FUNCTION: acpi_hw_low_disable_gpe | |
82 | * | |
83 | * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled | |
84 | * | |
85 | * RETURN: Status | |
86 | * | |
87 | * DESCRIPTION: Disable a single GPE in the enable register. | |
88 | * | |
89 | ******************************************************************************/ | |
90 | ||
91 | acpi_status acpi_hw_low_disable_gpe(struct acpi_gpe_event_info *gpe_event_info) | |
92 | { | |
93 | struct acpi_gpe_register_info *gpe_register_info; | |
94 | acpi_status status; | |
95 | u32 enable_mask; | |
e4e9a735 | 96 | u32 register_bit; |
e38e8a07 BM |
97 | |
98 | /* Get the info block for the entire GPE register */ | |
99 | ||
100 | gpe_register_info = gpe_event_info->register_info; | |
101 | if (!gpe_register_info) { | |
102 | return (AE_NOT_EXIST); | |
103 | } | |
104 | ||
105 | /* Get current value of the enable register that contains this GPE */ | |
106 | ||
c6b5774c | 107 | status = acpi_hw_read(&enable_mask, &gpe_register_info->enable_address); |
e38e8a07 BM |
108 | if (ACPI_FAILURE(status)) { |
109 | return (status); | |
110 | } | |
111 | ||
112 | /* Clear just the bit that corresponds to this GPE */ | |
113 | ||
e4e9a735 RW |
114 | register_bit = acpi_hw_gpe_register_bit(gpe_event_info, |
115 | gpe_register_info); | |
116 | ACPI_CLEAR_BIT(enable_mask, register_bit); | |
e38e8a07 BM |
117 | |
118 | /* Write the updated enable mask */ | |
119 | ||
c6b5774c | 120 | status = acpi_hw_write(enable_mask, &gpe_register_info->enable_address); |
e38e8a07 BM |
121 | return (status); |
122 | } | |
123 | ||
1da177e4 LT |
124 | /****************************************************************************** |
125 | * | |
126 | * FUNCTION: acpi_hw_write_gpe_enable_reg | |
127 | * | |
128 | * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled | |
129 | * | |
130 | * RETURN: Status | |
131 | * | |
132 | * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must | |
133 | * already be cleared or set in the parent register | |
134 | * enable_for_run mask. | |
135 | * | |
136 | ******************************************************************************/ | |
137 | ||
138 | acpi_status | |
e38e8a07 | 139 | acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info * gpe_event_info) |
1da177e4 | 140 | { |
4be44fcd LB |
141 | struct acpi_gpe_register_info *gpe_register_info; |
142 | acpi_status status; | |
1da177e4 | 143 | |
4be44fcd | 144 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
145 | |
146 | /* Get the info block for the entire GPE register */ | |
147 | ||
148 | gpe_register_info = gpe_event_info->register_info; | |
149 | if (!gpe_register_info) { | |
150 | return (AE_NOT_EXIST); | |
151 | } | |
152 | ||
153 | /* Write the entire GPE (runtime) enable register */ | |
154 | ||
c6b5774c BM |
155 | status = acpi_hw_write(gpe_register_info->enable_for_run, |
156 | &gpe_register_info->enable_address); | |
1da177e4 LT |
157 | |
158 | return (status); | |
159 | } | |
160 | ||
1da177e4 LT |
161 | /****************************************************************************** |
162 | * | |
163 | * FUNCTION: acpi_hw_clear_gpe | |
164 | * | |
165 | * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared | |
166 | * | |
167 | * RETURN: Status | |
168 | * | |
169 | * DESCRIPTION: Clear the status bit for a single GPE. | |
170 | * | |
171 | ******************************************************************************/ | |
172 | ||
4be44fcd | 173 | acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info) |
1da177e4 | 174 | { |
e4e9a735 | 175 | struct acpi_gpe_register_info *gpe_register_info; |
4be44fcd | 176 | acpi_status status; |
e4e9a735 | 177 | u32 register_bit; |
1da177e4 | 178 | |
4be44fcd | 179 | ACPI_FUNCTION_ENTRY(); |
1da177e4 | 180 | |
e4e9a735 RW |
181 | /* Get the info block for the entire GPE register */ |
182 | ||
183 | gpe_register_info = gpe_event_info->register_info; | |
184 | if (!gpe_register_info) { | |
185 | return (AE_NOT_EXIST); | |
186 | } | |
187 | ||
188 | register_bit = acpi_hw_gpe_register_bit(gpe_event_info, | |
189 | gpe_register_info); | |
69874165 | 190 | |
1da177e4 LT |
191 | /* |
192 | * Write a one to the appropriate bit in the status register to | |
193 | * clear this GPE. | |
194 | */ | |
c6b5774c | 195 | status = acpi_hw_write(register_bit, |
e4e9a735 | 196 | &gpe_register_info->status_address); |
1da177e4 LT |
197 | |
198 | return (status); | |
199 | } | |
200 | ||
1da177e4 LT |
201 | /****************************************************************************** |
202 | * | |
203 | * FUNCTION: acpi_hw_get_gpe_status | |
204 | * | |
205 | * PARAMETERS: gpe_event_info - Info block for the GPE to queried | |
206 | * event_status - Where the GPE status is returned | |
207 | * | |
208 | * RETURN: Status | |
209 | * | |
210 | * DESCRIPTION: Return the status of a single GPE. | |
211 | * | |
212 | ******************************************************************************/ | |
44f6c012 | 213 | |
1da177e4 | 214 | acpi_status |
4be44fcd LB |
215 | acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info, |
216 | acpi_event_status * event_status) | |
1da177e4 | 217 | { |
4be44fcd | 218 | u32 in_byte; |
e4e9a735 | 219 | u32 register_bit; |
4be44fcd LB |
220 | struct acpi_gpe_register_info *gpe_register_info; |
221 | acpi_status status; | |
222 | acpi_event_status local_event_status = 0; | |
1da177e4 | 223 | |
4be44fcd | 224 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
225 | |
226 | if (!event_status) { | |
227 | return (AE_BAD_PARAMETER); | |
228 | } | |
229 | ||
230 | /* Get the info block for the entire GPE register */ | |
231 | ||
232 | gpe_register_info = gpe_event_info->register_info; | |
233 | ||
234 | /* Get the register bitmask for this GPE */ | |
235 | ||
e4e9a735 RW |
236 | register_bit = acpi_hw_gpe_register_bit(gpe_event_info, |
237 | gpe_register_info); | |
1da177e4 LT |
238 | |
239 | /* GPE currently enabled? (enabled for runtime?) */ | |
240 | ||
241 | if (register_bit & gpe_register_info->enable_for_run) { | |
242 | local_event_status |= ACPI_EVENT_FLAG_ENABLED; | |
243 | } | |
244 | ||
245 | /* GPE enabled for wake? */ | |
246 | ||
247 | if (register_bit & gpe_register_info->enable_for_wake) { | |
248 | local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED; | |
249 | } | |
250 | ||
251 | /* GPE currently active (status bit == 1)? */ | |
252 | ||
c6b5774c | 253 | status = acpi_hw_read(&in_byte, &gpe_register_info->status_address); |
4be44fcd | 254 | if (ACPI_FAILURE(status)) { |
2147d3f0 | 255 | return (status); |
1da177e4 LT |
256 | } |
257 | ||
258 | if (register_bit & in_byte) { | |
259 | local_event_status |= ACPI_EVENT_FLAG_SET; | |
260 | } | |
261 | ||
262 | /* Set return value */ | |
263 | ||
264 | (*event_status) = local_event_status; | |
2147d3f0 | 265 | return (AE_OK); |
1da177e4 | 266 | } |
1da177e4 LT |
267 | |
268 | /****************************************************************************** | |
269 | * | |
270 | * FUNCTION: acpi_hw_disable_gpe_block | |
271 | * | |
272 | * PARAMETERS: gpe_xrupt_info - GPE Interrupt info | |
273 | * gpe_block - Gpe Block info | |
274 | * | |
275 | * RETURN: Status | |
276 | * | |
44f6c012 | 277 | * DESCRIPTION: Disable all GPEs within a single GPE block |
1da177e4 LT |
278 | * |
279 | ******************************************************************************/ | |
280 | ||
281 | acpi_status | |
e97d6bf1 BM |
282 | acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, |
283 | struct acpi_gpe_block_info *gpe_block, void *context) | |
1da177e4 | 284 | { |
4be44fcd LB |
285 | u32 i; |
286 | acpi_status status; | |
1da177e4 LT |
287 | |
288 | /* Examine each GPE Register within the block */ | |
289 | ||
290 | for (i = 0; i < gpe_block->register_count; i++) { | |
52fc0b02 | 291 | |
1da177e4 LT |
292 | /* Disable all GPEs in this register */ |
293 | ||
ecfbbc7b | 294 | status = |
c6b5774c BM |
295 | acpi_hw_write(0x00, |
296 | &gpe_block->register_info[i].enable_address); | |
4be44fcd | 297 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
298 | return (status); |
299 | } | |
300 | } | |
301 | ||
302 | return (AE_OK); | |
303 | } | |
304 | ||
1da177e4 LT |
305 | /****************************************************************************** |
306 | * | |
307 | * FUNCTION: acpi_hw_clear_gpe_block | |
308 | * | |
309 | * PARAMETERS: gpe_xrupt_info - GPE Interrupt info | |
310 | * gpe_block - Gpe Block info | |
311 | * | |
312 | * RETURN: Status | |
313 | * | |
44f6c012 | 314 | * DESCRIPTION: Clear status bits for all GPEs within a single GPE block |
1da177e4 LT |
315 | * |
316 | ******************************************************************************/ | |
317 | ||
318 | acpi_status | |
e97d6bf1 BM |
319 | acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, |
320 | struct acpi_gpe_block_info *gpe_block, void *context) | |
1da177e4 | 321 | { |
4be44fcd LB |
322 | u32 i; |
323 | acpi_status status; | |
1da177e4 LT |
324 | |
325 | /* Examine each GPE Register within the block */ | |
326 | ||
327 | for (i = 0; i < gpe_block->register_count; i++) { | |
52fc0b02 | 328 | |
1da177e4 LT |
329 | /* Clear status on all GPEs in this register */ |
330 | ||
ecfbbc7b | 331 | status = |
c6b5774c BM |
332 | acpi_hw_write(0xFF, |
333 | &gpe_block->register_info[i].status_address); | |
4be44fcd | 334 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
335 | return (status); |
336 | } | |
337 | } | |
338 | ||
339 | return (AE_OK); | |
340 | } | |
341 | ||
1da177e4 LT |
342 | /****************************************************************************** |
343 | * | |
344 | * FUNCTION: acpi_hw_enable_runtime_gpe_block | |
345 | * | |
346 | * PARAMETERS: gpe_xrupt_info - GPE Interrupt info | |
347 | * gpe_block - Gpe Block info | |
348 | * | |
349 | * RETURN: Status | |
350 | * | |
44f6c012 RM |
351 | * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes |
352 | * combination wake/run GPEs. | |
1da177e4 LT |
353 | * |
354 | ******************************************************************************/ | |
355 | ||
356 | acpi_status | |
e97d6bf1 BM |
357 | acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, |
358 | struct acpi_gpe_block_info *gpe_block, void *context) | |
1da177e4 | 359 | { |
4be44fcd LB |
360 | u32 i; |
361 | acpi_status status; | |
1da177e4 LT |
362 | |
363 | /* NOTE: assumes that all GPEs are currently disabled */ | |
364 | ||
365 | /* Examine each GPE Register within the block */ | |
366 | ||
367 | for (i = 0; i < gpe_block->register_count; i++) { | |
368 | if (!gpe_block->register_info[i].enable_for_run) { | |
369 | continue; | |
370 | } | |
371 | ||
372 | /* Enable all "runtime" GPEs in this register */ | |
373 | ||
c6b5774c BM |
374 | status = |
375 | acpi_hw_write(gpe_block->register_info[i].enable_for_run, | |
376 | &gpe_block->register_info[i].enable_address); | |
4be44fcd | 377 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
378 | return (status); |
379 | } | |
380 | } | |
381 | ||
382 | return (AE_OK); | |
383 | } | |
384 | ||
1da177e4 LT |
385 | /****************************************************************************** |
386 | * | |
387 | * FUNCTION: acpi_hw_enable_wakeup_gpe_block | |
388 | * | |
389 | * PARAMETERS: gpe_xrupt_info - GPE Interrupt info | |
390 | * gpe_block - Gpe Block info | |
391 | * | |
392 | * RETURN: Status | |
393 | * | |
44f6c012 RM |
394 | * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes |
395 | * combination wake/run GPEs. | |
1da177e4 LT |
396 | * |
397 | ******************************************************************************/ | |
398 | ||
44f6c012 | 399 | static acpi_status |
4be44fcd | 400 | acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, |
e97d6bf1 BM |
401 | struct acpi_gpe_block_info *gpe_block, |
402 | void *context) | |
1da177e4 | 403 | { |
4be44fcd LB |
404 | u32 i; |
405 | acpi_status status; | |
1da177e4 LT |
406 | |
407 | /* Examine each GPE Register within the block */ | |
408 | ||
409 | for (i = 0; i < gpe_block->register_count; i++) { | |
410 | if (!gpe_block->register_info[i].enable_for_wake) { | |
411 | continue; | |
412 | } | |
413 | ||
414 | /* Enable all "wake" GPEs in this register */ | |
415 | ||
c6b5774c BM |
416 | status = |
417 | acpi_hw_write(gpe_block->register_info[i].enable_for_wake, | |
418 | &gpe_block->register_info[i].enable_address); | |
4be44fcd | 419 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
420 | return (status); |
421 | } | |
422 | } | |
423 | ||
424 | return (AE_OK); | |
425 | } | |
426 | ||
1da177e4 LT |
427 | /****************************************************************************** |
428 | * | |
429 | * FUNCTION: acpi_hw_disable_all_gpes | |
430 | * | |
73459f73 | 431 | * PARAMETERS: None |
1da177e4 LT |
432 | * |
433 | * RETURN: Status | |
434 | * | |
44f6c012 | 435 | * DESCRIPTION: Disable and clear all GPEs in all GPE blocks |
1da177e4 LT |
436 | * |
437 | ******************************************************************************/ | |
438 | ||
4be44fcd | 439 | acpi_status acpi_hw_disable_all_gpes(void) |
1da177e4 | 440 | { |
4be44fcd | 441 | acpi_status status; |
1da177e4 | 442 | |
b229cf92 | 443 | ACPI_FUNCTION_TRACE(hw_disable_all_gpes); |
1da177e4 | 444 | |
e97d6bf1 BM |
445 | status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL); |
446 | status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL); | |
4be44fcd | 447 | return_ACPI_STATUS(status); |
1da177e4 LT |
448 | } |
449 | ||
1da177e4 LT |
450 | /****************************************************************************** |
451 | * | |
452 | * FUNCTION: acpi_hw_enable_all_runtime_gpes | |
453 | * | |
73459f73 | 454 | * PARAMETERS: None |
1da177e4 LT |
455 | * |
456 | * RETURN: Status | |
457 | * | |
44f6c012 | 458 | * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks |
1da177e4 LT |
459 | * |
460 | ******************************************************************************/ | |
461 | ||
4be44fcd | 462 | acpi_status acpi_hw_enable_all_runtime_gpes(void) |
1da177e4 | 463 | { |
4be44fcd | 464 | acpi_status status; |
1da177e4 | 465 | |
b229cf92 | 466 | ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes); |
1da177e4 | 467 | |
e97d6bf1 | 468 | status = acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block, NULL); |
4be44fcd | 469 | return_ACPI_STATUS(status); |
1da177e4 LT |
470 | } |
471 | ||
1da177e4 LT |
472 | /****************************************************************************** |
473 | * | |
474 | * FUNCTION: acpi_hw_enable_all_wakeup_gpes | |
475 | * | |
73459f73 | 476 | * PARAMETERS: None |
1da177e4 LT |
477 | * |
478 | * RETURN: Status | |
479 | * | |
44f6c012 | 480 | * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks |
1da177e4 LT |
481 | * |
482 | ******************************************************************************/ | |
483 | ||
4be44fcd | 484 | acpi_status acpi_hw_enable_all_wakeup_gpes(void) |
1da177e4 | 485 | { |
4be44fcd | 486 | acpi_status status; |
1da177e4 | 487 | |
b229cf92 | 488 | ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes); |
1da177e4 | 489 | |
e97d6bf1 | 490 | status = acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block, NULL); |
4be44fcd | 491 | return_ACPI_STATUS(status); |
1da177e4 | 492 | } |