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