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