:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / drivers / bus / acpi / hardware / hwgpe.c
1
2 /******************************************************************************
3  *
4  * Module Name: hwgpe - Low level GPE enable/disable/clear functions
5  *              $Revision$
6  *
7  *****************************************************************************/
8
9 /*
10  *  Copyright (C) 2000, 2001 R. Byron Moore
11  *
12  *  This program is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25  */
26
27 #include "acpi.h"
28 #include "achware.h"
29 #include "acnamesp.h"
30 #include "acevents.h"
31
32 #define _COMPONENT          ACPI_HARDWARE
33          MODULE_NAME         ("hwgpe")
34
35
36 /******************************************************************************
37  *
38  * FUNCTION:    Acpi_hw_enable_gpe
39  *
40  * PARAMETERS:  Gpe_number      - The GPE
41  *
42  * RETURN:      None
43  *
44  * DESCRIPTION: Enable a single GPE.
45  *
46  ******************************************************************************/
47
48 void
49 acpi_hw_enable_gpe (
50         u32                     gpe_number)
51 {
52         u8                      in_byte;
53         u32                     register_index;
54         u8                      bit_mask;
55
56         /*
57          * Translate GPE number to index into global registers array.
58          */
59         register_index = acpi_gbl_gpe_valid[gpe_number];
60
61         /*
62          * Figure out the bit offset for this GPE within the target register.
63          */
64         bit_mask = acpi_gbl_decode_to8bit [MOD_8 (gpe_number)];
65
66         /*
67          * Read the current value of the register, set the appropriate bit
68          * to enable the GPE, and write out the new register.
69          */
70         in_byte = acpi_os_in8 (acpi_gbl_gpe_registers[register_index].enable_addr);
71         acpi_os_out8 (acpi_gbl_gpe_registers[register_index].enable_addr,
72                          (u8)(in_byte | bit_mask));
73 }
74
75
76 /******************************************************************************
77  *
78  * FUNCTION:    Acpi_hw_disable_gpe
79  *
80  * PARAMETERS:  Gpe_number      - The GPE
81  *
82  * RETURN:      None
83  *
84  * DESCRIPTION: Disable a single GPE.
85  *
86  ******************************************************************************/
87
88 void
89 acpi_hw_disable_gpe (
90         u32                     gpe_number)
91 {
92         u8                      in_byte;
93         u32                     register_index;
94         u8                      bit_mask;
95
96         /*
97          * Translate GPE number to index into global registers array.
98          */
99         register_index = acpi_gbl_gpe_valid[gpe_number];
100
101         /*
102          * Figure out the bit offset for this GPE within the target register.
103          */
104         bit_mask = acpi_gbl_decode_to8bit [MOD_8 (gpe_number)];
105
106         /*
107          * Read the current value of the register, clear the appropriate bit,
108          * and write out the new register value to disable the GPE.
109          */
110         in_byte = acpi_os_in8 (acpi_gbl_gpe_registers[register_index].enable_addr);
111         acpi_os_out8 (acpi_gbl_gpe_registers[register_index].enable_addr,
112                          (u8)(in_byte & ~bit_mask));
113 }
114
115
116 /******************************************************************************
117  *
118  * FUNCTION:    Acpi_hw_clear_gpe
119  *
120  * PARAMETERS:  Gpe_number      - The GPE
121  *
122  * RETURN:      None
123  *
124  * DESCRIPTION: Clear a single GPE.
125  *
126  ******************************************************************************/
127
128 void
129 acpi_hw_clear_gpe (
130         u32                     gpe_number)
131 {
132         u32                     register_index;
133         u8                      bit_mask;
134
135         /*
136          * Translate GPE number to index into global registers array.
137          */
138         register_index = acpi_gbl_gpe_valid[gpe_number];
139
140         /*
141          * Figure out the bit offset for this GPE within the target register.
142          */
143         bit_mask = acpi_gbl_decode_to8bit [MOD_8 (gpe_number)];
144
145         /*
146          * Write a one to the appropriate bit in the status register to
147          * clear this GPE.
148          */
149         acpi_os_out8 (acpi_gbl_gpe_registers[register_index].status_addr, bit_mask);
150 }
151
152
153 /******************************************************************************
154  *
155  * FUNCTION:    Acpi_hw_get_gpe_status
156  *
157  * PARAMETERS:  Gpe_number      - The GPE
158  *
159  * RETURN:      None
160  *
161  * DESCRIPTION: Return the status of a single GPE.
162  *
163  ******************************************************************************/
164
165 void
166 acpi_hw_get_gpe_status (
167         u32                     gpe_number,
168         ACPI_EVENT_STATUS       *event_status)
169 {
170         u8                      in_byte = 0;
171         u32                     register_index = 0;
172         u8                      bit_mask = 0;
173
174         if (!event_status) {
175                 return;
176         }
177
178         (*event_status) = 0;
179
180         /*
181          * Translate GPE number to index into global registers array.
182          */
183         register_index = acpi_gbl_gpe_valid[gpe_number];
184
185         /*
186          * Figure out the bit offset for this GPE within the target register.
187          */
188         bit_mask = acpi_gbl_decode_to8bit [MOD_8 (gpe_number)];
189
190         /*
191          * Enabled?:
192          */
193         in_byte = acpi_os_in8 (acpi_gbl_gpe_registers[register_index].enable_addr);
194
195         if (bit_mask & in_byte) {
196                 (*event_status) |= ACPI_EVENT_FLAG_ENABLED;
197         }
198
199         /*
200          * Set?
201          */
202         in_byte = acpi_os_in8 (acpi_gbl_gpe_registers[register_index].status_addr);
203
204         if (bit_mask & in_byte) {
205                 (*event_status) |= ACPI_EVENT_FLAG_SET;
206         }
207 }