]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | PS2 Mouse Communication Interface\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #ifndef _COMMPS2_H_\r | |
16 | #define _COMMPS2_H_\r | |
17 | \r | |
18 | #include "Ps2Mouse.h"\r | |
19 | \r | |
20 | #define PS2_PACKET_LENGTH 3\r | |
21 | #define PS2_SYNC_MASK 0xc\r | |
22 | #define PS2_SYNC_BYTE 0x8\r | |
23 | \r | |
24 | #define IS_PS2_SYNC_BYTE(byte) ((byte & PS2_SYNC_MASK) == PS2_SYNC_BYTE)\r | |
25 | \r | |
26 | #define PS2_READ_BYTE_ONE 0\r | |
27 | #define PS2_READ_DATA_BYTE 1\r | |
28 | #define PS2_PROCESS_PACKET 2\r | |
29 | \r | |
30 | #define TIMEOUT 50000\r | |
31 | #define BAT_TIMEOUT 500000\r | |
32 | \r | |
33 | //\r | |
34 | // 8042 I/O Port\r | |
35 | //\r | |
36 | #define KBC_DATA_PORT 0x60\r | |
37 | #define KBC_CMD_STS_PORT 0x64\r | |
38 | \r | |
39 | //\r | |
40 | // 8042 Command\r | |
41 | //\r | |
42 | #define READ_CMD_BYTE 0x20\r | |
43 | #define WRITE_CMD_BYTE 0x60\r | |
44 | #define DISABLE_AUX 0xa7\r | |
45 | #define ENABLE_AUX 0xa8\r | |
46 | #define SELF_TEST 0xaa\r | |
47 | #define DISABLE_KB 0xad\r | |
48 | #define ENABLE_KB 0xae\r | |
49 | #define WRITE_AUX_DEV 0xd4\r | |
50 | \r | |
51 | #define CMD_SYS_FLAG 0x04\r | |
52 | #define CMD_KB_STS 0x10\r | |
53 | #define CMD_KB_DIS 0x10\r | |
54 | #define CMD_KB_EN 0x0\r | |
55 | \r | |
56 | //\r | |
57 | // 8042 Auxiliary Device Command\r | |
58 | //\r | |
59 | #define SETSF1_CMD 0xe6\r | |
60 | #define SETSF2_CMD 0xe7\r | |
61 | #define SETRE_CMD 0xe8\r | |
62 | #define READ_CMD 0xeb\r | |
63 | #define SETRM_CMD 0xf0\r | |
64 | #define SETSR_CMD 0xf3\r | |
65 | #define ENABLE_CMD 0xf4\r | |
66 | #define DISABLE_CMD 0xf5\r | |
67 | #define RESET_CMD 0xff\r | |
68 | \r | |
69 | //\r | |
70 | // return code\r | |
71 | //\r | |
72 | #define PS2_ACK 0xfa\r | |
73 | #define PS2_RESEND 0xfe\r | |
74 | #define PS2MOUSE_BAT1 0xaa\r | |
75 | #define PS2MOUSE_BAT2 0x0\r | |
76 | \r | |
77 | //\r | |
78 | // Keyboard Controller Status\r | |
79 | //\r | |
80 | ///\r | |
81 | /// Parity Error\r | |
82 | ///\r | |
83 | #define KBC_PARE 0x80\r | |
84 | ///\r | |
85 | /// General Time Out\r | |
86 | ///\r | |
87 | #define KBC_TIM 0x40\r | |
88 | ///\r | |
89 | /// Output buffer for auxiliary device (PS/2):\r | |
90 | /// 0 - Holds keyboard data\r | |
91 | /// 1 - Holds data for auxiliary device\r | |
92 | ///\r | |
93 | #define KBC_AUXB 0x20\r | |
94 | ///\r | |
95 | /// Keyboard lock status:\r | |
96 | /// 0 - keyboard locked\r | |
97 | /// 1 - keyboard free\r | |
98 | ///\r | |
99 | #define KBC_KEYL 0x10\r | |
100 | ///\r | |
101 | /// Command/Data:\r | |
102 | /// 0 - data byte written via port 60h\r | |
103 | /// 1 - command byte written via port 64h\r | |
104 | ///\r | |
105 | #define KBC_CD 0x08\r | |
106 | ///\r | |
107 | /// System Flag:\r | |
108 | /// 0 - power-on reset\r | |
109 | /// 1 - self-test successful\r | |
110 | ///\r | |
111 | #define KBC_SYSF 0x04\r | |
112 | ///\r | |
113 | /// Input Buffer Status :\r | |
114 | /// 0 - input buffer empty\r | |
115 | /// 1 - CPU data in input buffer\r | |
116 | ///\r | |
117 | #define KBC_INPB 0x02\r | |
118 | ///\r | |
119 | /// Output Buffer Status :\r | |
120 | /// 0 - output buffer empty\r | |
121 | /// 1 - keyboard controller data in output buffer\r | |
122 | ///\r | |
123 | #define KBC_OUTB 0x01\r | |
124 | \r | |
125 | /**\r | |
126 | Issue self test command via IsaIo interface.\r | |
127 | \r | |
128 | @return EFI_SUCCESS Success to do keyboard self testing.\r | |
129 | @return others Fail to do keyboard self testing.\r | |
130 | **/\r | |
131 | EFI_STATUS\r | |
132 | KbcSelfTest (\r | |
133 | VOID\r | |
134 | );\r | |
135 | \r | |
136 | /**\r | |
137 | Issue command to enable keyboard AUX functionality.\r | |
138 | \r | |
139 | @return Status of command issuing.\r | |
140 | **/\r | |
141 | EFI_STATUS\r | |
142 | KbcEnableAux (\r | |
143 | VOID\r | |
144 | );\r | |
145 | \r | |
146 | /**\r | |
147 | Issue command to disable keyboard AUX functionality.\r | |
148 | \r | |
149 | @return Status of command issuing.\r | |
150 | **/\r | |
151 | EFI_STATUS\r | |
152 | KbcDisableAux (\r | |
153 | VOID\r | |
154 | );\r | |
155 | \r | |
156 | /**\r | |
157 | Issue command to enable keyboard.\r | |
158 | \r | |
159 | @return Status of command issuing.\r | |
160 | **/\r | |
161 | EFI_STATUS\r | |
162 | KbcEnableKb (\r | |
163 | VOID\r | |
164 | );\r | |
165 | \r | |
166 | /**\r | |
167 | Issue command to disable keyboard.\r | |
168 | \r | |
169 | @return Status of command issuing.\r | |
170 | **/\r | |
171 | EFI_STATUS\r | |
172 | KbcDisableKb (\r | |
173 | VOID\r | |
174 | );\r | |
175 | \r | |
176 | /**\r | |
177 | Issue command to check keyboard status.\r | |
178 | \r | |
179 | @param KeyboardEnable return whether keyboard is enable.\r | |
180 | \r | |
181 | @return Status of command issuing.\r | |
182 | **/\r | |
183 | EFI_STATUS\r | |
184 | CheckKbStatus (\r | |
185 | OUT BOOLEAN *KeyboardEnable\r | |
186 | );\r | |
187 | \r | |
188 | /**\r | |
189 | Issue command to reset keyboard.\r | |
190 | \r | |
191 | @return Status of command issuing.\r | |
192 | **/\r | |
193 | EFI_STATUS\r | |
194 | PS2MouseReset (\r | |
195 | VOID\r | |
196 | );\r | |
197 | \r | |
198 | /**\r | |
199 | Issue command to set mouse's sample rate\r | |
200 | \r | |
201 | @param SampleRate value of sample rate\r | |
202 | \r | |
203 | @return Status of command issuing.\r | |
204 | **/\r | |
205 | EFI_STATUS\r | |
206 | PS2MouseSetSampleRate (\r | |
207 | IN MOUSE_SR SampleRate\r | |
208 | );\r | |
209 | \r | |
210 | /**\r | |
211 | Issue command to set mouse's resolution.\r | |
212 | \r | |
213 | @param Resolution value of resolution\r | |
214 | \r | |
215 | @return Status of command issuing.\r | |
216 | **/\r | |
217 | EFI_STATUS\r | |
218 | PS2MouseSetResolution (\r | |
219 | IN MOUSE_RE Resolution\r | |
220 | );\r | |
221 | \r | |
222 | /**\r | |
223 | Issue command to set mouse's scaling.\r | |
224 | \r | |
225 | @param Scaling value of scaling\r | |
226 | \r | |
227 | @return Status of command issuing.\r | |
228 | **/\r | |
229 | EFI_STATUS\r | |
230 | PS2MouseSetScaling (\r | |
231 | IN MOUSE_SF Scaling\r | |
232 | );\r | |
233 | \r | |
234 | /**\r | |
235 | Issue command to enable Ps2 mouse.\r | |
236 | \r | |
237 | @return Status of command issuing.\r | |
238 | **/\r | |
239 | EFI_STATUS\r | |
240 | PS2MouseEnable (\r | |
241 | VOID\r | |
242 | );\r | |
243 | \r | |
244 | /**\r | |
245 | Get mouse packet . Only care first 3 bytes\r | |
246 | \r | |
247 | @param MouseDev Pointer of PS2 Mouse Private Data Structure\r | |
248 | \r | |
249 | @retval EFI_NOT_READY Mouse Device not ready to input data packet, or some error happened during getting the packet\r | |
250 | @retval EFI_SUCCESS The data packet is gotten successfully.\r | |
251 | \r | |
252 | **/\r | |
253 | EFI_STATUS\r | |
254 | PS2MouseGetPacket (\r | |
255 | PS2_MOUSE_DEV *MouseDev\r | |
256 | );\r | |
257 | \r | |
258 | /**\r | |
259 | Read data via IsaIo protocol with given number.\r | |
260 | \r | |
261 | @param Buffer Buffer receive data of mouse\r | |
262 | @param BufSize The size of buffer\r | |
263 | @param State Check input or read data\r | |
264 | \r | |
265 | @return status of reading mouse data.\r | |
266 | **/\r | |
267 | EFI_STATUS\r | |
268 | PS2MouseRead (\r | |
269 | OUT UINT8 *Buffer,\r | |
270 | IN OUT UINTN *BufSize,\r | |
271 | IN UINTN State\r | |
272 | );\r | |
273 | \r | |
274 | //\r | |
275 | // 8042 I/O function\r | |
276 | //\r | |
277 | /**\r | |
278 | I/O work flow of outing 8042 command.\r | |
279 | \r | |
280 | @param Command I/O command.\r | |
281 | \r | |
282 | @retval EFI_SUCCESS Success to execute I/O work flow\r | |
283 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
284 | **/\r | |
285 | EFI_STATUS\r | |
286 | Out8042Command (\r | |
287 | IN UINT8 Command\r | |
288 | );\r | |
289 | \r | |
290 | /**\r | |
291 | I/O work flow of in 8042 data.\r | |
292 | \r | |
293 | @param Data Data value\r | |
294 | \r | |
295 | @retval EFI_SUCCESS Success to execute I/O work flow\r | |
296 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
297 | **/\r | |
298 | EFI_STATUS\r | |
299 | In8042Data (\r | |
300 | IN OUT UINT8 *Data\r | |
301 | );\r | |
302 | \r | |
303 | /**\r | |
304 | I/O work flow of outing 8042 data.\r | |
305 | \r | |
306 | @param Data Data value\r | |
307 | \r | |
308 | @retval EFI_SUCCESS Success to execute I/O work flow\r | |
309 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
310 | **/\r | |
311 | EFI_STATUS\r | |
312 | Out8042Data (\r | |
313 | IN UINT8 Data\r | |
314 | );\r | |
315 | \r | |
316 | /**\r | |
317 | I/O work flow of outing 8042 Aux command.\r | |
318 | \r | |
319 | @param Command Aux I/O command\r | |
320 | @param Resend Whether need resend the Aux command.\r | |
321 | \r | |
322 | @retval EFI_SUCCESS Success to execute I/O work flow\r | |
323 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
324 | **/\r | |
325 | EFI_STATUS\r | |
326 | Out8042AuxCommand (\r | |
327 | IN UINT8 Command,\r | |
328 | IN BOOLEAN Resend\r | |
329 | );\r | |
330 | \r | |
331 | /**\r | |
332 | I/O work flow of in 8042 Aux data.\r | |
333 | \r | |
334 | @param Data Buffer holding return value.\r | |
335 | \r | |
336 | @retval EFI_SUCCESS Success to execute I/O work flow\r | |
337 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
338 | **/\r | |
339 | EFI_STATUS\r | |
340 | In8042AuxData (\r | |
341 | IN OUT UINT8 *Data\r | |
342 | );\r | |
343 | \r | |
344 | /**\r | |
345 | I/O work flow of outing 8042 Aux data.\r | |
346 | \r | |
347 | @param Data Buffer holding return value\r | |
348 | \r | |
349 | @retval EFI_SUCCESS Success to execute I/O work flow\r | |
350 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
351 | **/\r | |
352 | EFI_STATUS\r | |
353 | Out8042AuxData (\r | |
354 | IN UINT8 Data\r | |
355 | );\r | |
356 | \r | |
357 | /**\r | |
358 | Check keyboard controller status, if it is output buffer full and for auxiliary device.\r | |
359 | \r | |
360 | @retval EFI_SUCCESS Keyboard controller is ready\r | |
361 | @retval EFI_NOT_READY Keyboard controller is not ready\r | |
362 | **/\r | |
363 | EFI_STATUS\r | |
364 | CheckForInput (\r | |
365 | VOID\r | |
366 | );\r | |
367 | \r | |
368 | /**\r | |
369 | I/O work flow to wait input buffer empty in given time.\r | |
370 | \r | |
371 | @param Timeout Wating time.\r | |
372 | \r | |
373 | @retval EFI_TIMEOUT if input is still not empty in given time.\r | |
374 | @retval EFI_SUCCESS input is empty.\r | |
375 | **/\r | |
376 | EFI_STATUS\r | |
377 | WaitInputEmpty (\r | |
378 | IN UINTN Timeout\r | |
379 | );\r | |
380 | \r | |
381 | /**\r | |
382 | I/O work flow to wait output buffer full in given time.\r | |
383 | \r | |
384 | @param Timeout given time\r | |
385 | \r | |
386 | @retval EFI_TIMEOUT output is not full in given time\r | |
387 | @retval EFI_SUCCESS output is full in given time.\r | |
388 | **/\r | |
389 | EFI_STATUS\r | |
390 | WaitOutputFull (\r | |
391 | IN UINTN Timeout\r | |
392 | );\r | |
393 | \r | |
394 | #endif\r | |
395 | \r |