]>
Commit | Line | Data |
---|---|---|
172870ef | 1 | /** @file\r |
f8cd287b | 2 | PS2 Mouse Communication Interface \r |
05fbd06d | 3 | \r |
92a428e1 | 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 | |
05fbd06d | 12 | \r |
f8cd287b | 13 | **/\r |
05fbd06d | 14 | \r |
15 | #ifndef _COMMPS2_H_\r | |
16 | #define _COMMPS2_H_\r | |
17 | \r | |
05fbd06d | 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 | |
ff1fcef8 | 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 | |
05fbd06d | 113 | EFI_STATUS\r |
114 | KbcSelfTest (\r | |
115 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 116 | );\r |
05fbd06d | 117 | \r |
ff1fcef8 | 118 | /**\r |
119 | Issue command to enable keyboard AUX functionality.\r | |
120 | \r | |
121 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
122 | \r | |
123 | @return Status of command issuing.\r | |
124 | **/\r | |
05fbd06d | 125 | EFI_STATUS\r |
126 | KbcEnableAux (\r | |
127 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 128 | );\r |
05fbd06d | 129 | \r |
ff1fcef8 | 130 | /**\r |
131 | Issue command to disable keyboard AUX functionality.\r | |
132 | \r | |
133 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
134 | \r | |
135 | @return Status of command issuing.\r | |
136 | **/\r | |
05fbd06d | 137 | EFI_STATUS\r |
138 | KbcDisableAux (\r | |
139 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 140 | );\r |
05fbd06d | 141 | \r |
ff1fcef8 | 142 | /**\r |
143 | Issue command to enable keyboard.\r | |
144 | \r | |
145 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
146 | \r | |
147 | @return Status of command issuing.\r | |
148 | **/\r | |
05fbd06d | 149 | EFI_STATUS\r |
150 | KbcEnableKb (\r | |
151 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 152 | );\r |
05fbd06d | 153 | \r |
ff1fcef8 | 154 | /**\r |
155 | Issue command to disable keyboard.\r | |
156 | \r | |
157 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
158 | \r | |
159 | @return Status of command issuing.\r | |
160 | **/\r | |
05fbd06d | 161 | EFI_STATUS\r |
162 | KbcDisableKb (\r | |
163 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 164 | );\r |
05fbd06d | 165 | \r |
ff1fcef8 | 166 | /**\r |
167 | Issue command to check keyboard status.\r | |
168 | \r | |
169 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
170 | @param KeyboardEnable return whether keyboard is enable.\r | |
171 | \r | |
172 | @return Status of command issuing.\r | |
173 | **/\r | |
05fbd06d | 174 | EFI_STATUS\r |
175 | CheckKbStatus (\r | |
176 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
177 | OUT BOOLEAN *KeyboardEnable\r | |
ed66e1bc | 178 | );\r |
05fbd06d | 179 | \r |
ff1fcef8 | 180 | /**\r |
181 | Issue command to reset keyboard.\r | |
182 | \r | |
183 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
184 | \r | |
185 | @return Status of command issuing.\r | |
186 | **/\r | |
05fbd06d | 187 | EFI_STATUS\r |
188 | PS2MouseReset (\r | |
189 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 190 | );\r |
05fbd06d | 191 | \r |
ff1fcef8 | 192 | /**\r |
193 | Issue command to set mouse's sample rate\r | |
194 | \r | |
195 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
196 | @param SampleRate value of sample rate \r | |
197 | \r | |
198 | @return Status of command issuing.\r | |
199 | **/\r | |
05fbd06d | 200 | EFI_STATUS\r |
201 | PS2MouseSetSampleRate (\r | |
202 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
203 | IN MOUSE_SR SampleRate\r | |
ed66e1bc | 204 | );\r |
05fbd06d | 205 | \r |
ff1fcef8 | 206 | /**\r |
207 | Issue command to set mouse's resolution.\r | |
208 | \r | |
209 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
210 | @param Resolution value of resolution\r | |
211 | \r | |
212 | @return Status of command issuing.\r | |
213 | **/\r | |
05fbd06d | 214 | EFI_STATUS\r |
215 | PS2MouseSetResolution (\r | |
216 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
217 | IN MOUSE_RE Resolution\r | |
ed66e1bc | 218 | );\r |
05fbd06d | 219 | \r |
ff1fcef8 | 220 | /**\r |
221 | Issue command to set mouse's scaling.\r | |
222 | \r | |
223 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
224 | @param Scaling value of scaling\r | |
225 | \r | |
226 | @return Status of command issuing.\r | |
227 | **/\r | |
05fbd06d | 228 | EFI_STATUS\r |
229 | PS2MouseSetScaling (\r | |
230 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
231 | IN MOUSE_SF Scaling\r | |
ed66e1bc | 232 | );\r |
05fbd06d | 233 | \r |
ff1fcef8 | 234 | /**\r |
235 | Issue command to enable Ps2 mouse.\r | |
236 | \r | |
237 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
238 | \r | |
239 | @return Status of command issuing.\r | |
240 | **/\r | |
05fbd06d | 241 | EFI_STATUS\r |
242 | PS2MouseEnable (\r | |
243 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 244 | );\r |
05fbd06d | 245 | \r |
ff1fcef8 | 246 | /**\r |
247 | Get mouse packet . Only care first 3 bytes\r | |
05fbd06d | 248 | \r |
ff1fcef8 | 249 | @param MouseDev Pointer of PS2 Mouse Private Data Structure \r |
05fbd06d | 250 | \r |
ff1fcef8 | 251 | @retval EFI_NOT_READY Mouse Device not ready to input data packet, or some error happened during getting the packet\r |
252 | @retval EFI_SUCCESS The data packet is gotten successfully.\r | |
05fbd06d | 253 | \r |
bcd70414 | 254 | **/\r |
05fbd06d | 255 | EFI_STATUS\r |
256 | PS2MouseGetPacket (\r | |
257 | PS2_MOUSE_DEV *MouseDev\r | |
ed66e1bc | 258 | );\r |
05fbd06d | 259 | \r |
ff1fcef8 | 260 | /**\r |
261 | Read data via IsaIo protocol with given number.\r | |
262 | \r | |
263 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
264 | @param Buffer Buffer receive data of mouse\r | |
265 | @param BufSize The size of buffer\r | |
266 | @param State Check input or read data\r | |
267 | \r | |
268 | @return status of reading mouse data.\r | |
269 | **/\r | |
05fbd06d | 270 | EFI_STATUS\r |
271 | PS2MouseRead (\r | |
272 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
273 | OUT VOID *Buffer,\r | |
274 | IN OUT UINTN *BufSize,\r | |
275 | IN UINTN State\r | |
276 | );\r | |
277 | \r | |
278 | //\r | |
279 | // 8042 I/O function\r | |
280 | //\r | |
ff1fcef8 | 281 | /**\r |
282 | I/O work flow of outing 8042 command.\r | |
283 | \r | |
284 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
285 | @param Command I/O command.\r | |
286 | \r | |
287 | @retval EFI_SUCCESS Success to excute I/O work flow\r | |
288 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
289 | **/\r | |
05fbd06d | 290 | EFI_STATUS\r |
291 | Out8042Command (\r | |
292 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
293 | IN UINT8 Command\r | |
294 | );\r | |
295 | \r | |
ff1fcef8 | 296 | /**\r |
297 | I/O work flow of in 8042 data.\r | |
298 | \r | |
299 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
300 | @param Data Data value\r | |
301 | \r | |
302 | @retval EFI_SUCCESS Success to excute I/O work flow\r | |
303 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
304 | **/\r | |
05fbd06d | 305 | EFI_STATUS\r |
306 | In8042Data (\r | |
307 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
308 | IN OUT UINT8 *Data\r | |
309 | );\r | |
310 | \r | |
ff1fcef8 | 311 | /**\r |
312 | I/O work flow of outing 8042 data.\r | |
313 | \r | |
314 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
315 | @param Data Data value\r | |
316 | \r | |
317 | @retval EFI_SUCCESS Success to excute I/O work flow\r | |
318 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
319 | **/\r | |
05fbd06d | 320 | EFI_STATUS\r |
321 | Out8042Data (\r | |
322 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
323 | IN UINT8 Data\r | |
324 | );\r | |
325 | \r | |
ff1fcef8 | 326 | /**\r |
327 | I/O work flow of outing 8042 Aux command.\r | |
328 | \r | |
329 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
330 | @param Command Aux I/O command\r | |
331 | @param Resend Whether need resend the Aux command.\r | |
332 | \r | |
333 | @retval EFI_SUCCESS Success to excute I/O work flow\r | |
334 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
335 | **/\r | |
05fbd06d | 336 | EFI_STATUS\r |
337 | Out8042AuxCommand (\r | |
338 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
339 | IN UINT8 Command,\r | |
340 | IN BOOLEAN Resend\r | |
341 | );\r | |
342 | \r | |
ff1fcef8 | 343 | /**\r |
344 | I/O work flow of in 8042 Aux data.\r | |
345 | \r | |
346 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
347 | @param Data Buffer holding return value.\r | |
348 | \r | |
349 | @retval EFI_SUCCESS Success to excute I/O work flow\r | |
350 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
351 | **/\r | |
05fbd06d | 352 | EFI_STATUS\r |
353 | In8042AuxData (\r | |
354 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
355 | IN OUT UINT8 *Data\r | |
356 | );\r | |
357 | \r | |
ff1fcef8 | 358 | /**\r |
359 | I/O work flow of outing 8042 Aux data.\r | |
360 | \r | |
361 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
172870ef | 362 | @param Data Buffer holding return value\r |
ff1fcef8 | 363 | \r |
364 | @retval EFI_SUCCESS Success to excute I/O work flow\r | |
365 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
366 | **/\r | |
05fbd06d | 367 | EFI_STATUS\r |
368 | Out8042AuxData (\r | |
369 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
370 | IN UINT8 Data\r | |
371 | );\r | |
372 | \r | |
ff1fcef8 | 373 | /**\r |
172870ef | 374 | Check keyboard controller status, if it is output buffer full and for auxiliary device.\r |
ff1fcef8 | 375 | \r |
376 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
377 | \r | |
378 | @retval EFI_SUCCESS Keyboard controller is ready\r | |
379 | @retval EFI_NOT_READY Keyboard controller is not ready\r | |
380 | **/\r | |
05fbd06d | 381 | EFI_STATUS\r |
382 | CheckForInput (\r | |
383 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
384 | );\r | |
385 | \r | |
ff1fcef8 | 386 | /**\r |
387 | I/O work flow to wait input buffer empty in given time.\r | |
388 | \r | |
389 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
390 | @param Timeout Wating time.\r | |
391 | \r | |
392 | @retval EFI_TIMEOUT if input is still not empty in given time.\r | |
393 | @retval EFI_SUCCESS input is empty.\r | |
394 | **/\r | |
05fbd06d | 395 | EFI_STATUS\r |
396 | WaitInputEmpty (\r | |
397 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
398 | IN UINTN Timeout\r | |
399 | );\r | |
400 | \r | |
ff1fcef8 | 401 | /**\r |
402 | I/O work flow to wait output buffer full in given time.\r | |
403 | \r | |
404 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
405 | @param Timeout given time\r | |
406 | \r | |
407 | @retval EFI_TIMEOUT output is not full in given time\r | |
408 | @retval EFI_SUCCESS output is full in given time.\r | |
409 | **/\r | |
05fbd06d | 410 | EFI_STATUS\r |
411 | WaitOutputFull (\r | |
412 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
413 | IN UINTN Timeout\r | |
414 | );\r | |
415 | \r | |
416 | #endif // _COMMPS2_H_\r |