]>
Commit | Line | Data |
---|---|---|
172870ef | 1 | /** @file\r |
f8cd287b | 2 | PS2 Mouse Communication Interface \r |
05fbd06d | 3 | \r |
180a5a35 HT |
4 | Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>\r |
5 | This program and the accompanying materials\r | |
92a428e1 | 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 | |
24a2dd3d | 78 | ///\r |
79 | /// Parity Error\r | |
80 | ///\r | |
81 | #define KBC_PARE 0x80 \r | |
82 | ///\r | |
83 | /// General Time Out\r | |
84 | ///\r | |
85 | #define KBC_TIM 0x40 \r | |
86 | ///\r | |
87 | /// Output buffer for auxiliary device (PS/2):\r | |
88 | /// 0 - Holds keyboard data\r | |
89 | /// 1 - Holds data for auxiliary device\r | |
90 | ///\r | |
91 | #define KBC_AUXB 0x20 \r | |
92 | ///\r | |
93 | /// Keyboard lock status:\r | |
94 | /// 0 - keyboard locked\r | |
95 | /// 1 - keyboard free\r | |
96 | ///\r | |
97 | #define KBC_KEYL 0x10 \r | |
98 | ///\r | |
99 | /// Command/Data:\r | |
100 | /// 0 - data byte written via port 60h\r | |
101 | /// 1 - command byte written via port 64h\r | |
102 | ///\r | |
103 | #define KBC_CD 0x08\r | |
104 | ///\r | |
105 | /// System Flag:\r | |
106 | /// 0 - power-on reset\r | |
107 | /// 1 - self-test successful\r | |
108 | ///\r | |
109 | #define KBC_SYSF 0x04 \r | |
110 | ///\r | |
111 | /// Input Buffer Status :\r | |
112 | /// 0 - input buffer empty\r | |
113 | /// 1 - CPU data in input buffer\r | |
114 | ///\r | |
115 | #define KBC_INPB 0x02 \r | |
116 | ///\r | |
117 | /// Output Buffer Status :\r | |
118 | /// 0 - output buffer empty\r | |
119 | /// 1 - keyboard controller data in output buffer\r | |
120 | ///\r | |
121 | #define KBC_OUTB 0x01 \r | |
ff1fcef8 | 122 | \r |
123 | /**\r | |
124 | Issue self test command via IsaIo interface.\r | |
125 | \r | |
126 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\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 | |
05fbd06d | 131 | EFI_STATUS\r |
132 | KbcSelfTest (\r | |
133 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 134 | );\r |
05fbd06d | 135 | \r |
ff1fcef8 | 136 | /**\r |
137 | Issue command to enable keyboard AUX functionality.\r | |
138 | \r | |
139 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
140 | \r | |
141 | @return Status of command issuing.\r | |
142 | **/\r | |
05fbd06d | 143 | EFI_STATUS\r |
144 | KbcEnableAux (\r | |
145 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 146 | );\r |
05fbd06d | 147 | \r |
ff1fcef8 | 148 | /**\r |
149 | Issue command to disable keyboard AUX functionality.\r | |
150 | \r | |
151 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
152 | \r | |
153 | @return Status of command issuing.\r | |
154 | **/\r | |
05fbd06d | 155 | EFI_STATUS\r |
156 | KbcDisableAux (\r | |
157 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 158 | );\r |
05fbd06d | 159 | \r |
ff1fcef8 | 160 | /**\r |
161 | Issue command to enable keyboard.\r | |
162 | \r | |
163 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
164 | \r | |
165 | @return Status of command issuing.\r | |
166 | **/\r | |
05fbd06d | 167 | EFI_STATUS\r |
168 | KbcEnableKb (\r | |
169 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 170 | );\r |
05fbd06d | 171 | \r |
ff1fcef8 | 172 | /**\r |
173 | Issue command to disable keyboard.\r | |
174 | \r | |
175 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
176 | \r | |
177 | @return Status of command issuing.\r | |
178 | **/\r | |
05fbd06d | 179 | EFI_STATUS\r |
180 | KbcDisableKb (\r | |
181 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 182 | );\r |
05fbd06d | 183 | \r |
ff1fcef8 | 184 | /**\r |
185 | Issue command to check keyboard status.\r | |
186 | \r | |
187 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
188 | @param KeyboardEnable return whether keyboard is enable.\r | |
189 | \r | |
190 | @return Status of command issuing.\r | |
191 | **/\r | |
05fbd06d | 192 | EFI_STATUS\r |
193 | CheckKbStatus (\r | |
194 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
195 | OUT BOOLEAN *KeyboardEnable\r | |
ed66e1bc | 196 | );\r |
05fbd06d | 197 | \r |
ff1fcef8 | 198 | /**\r |
199 | Issue command to reset keyboard.\r | |
200 | \r | |
201 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
202 | \r | |
203 | @return Status of command issuing.\r | |
204 | **/\r | |
05fbd06d | 205 | EFI_STATUS\r |
206 | PS2MouseReset (\r | |
207 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 208 | );\r |
05fbd06d | 209 | \r |
ff1fcef8 | 210 | /**\r |
211 | Issue command to set mouse's sample rate\r | |
212 | \r | |
213 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
214 | @param SampleRate value of sample rate \r | |
215 | \r | |
216 | @return Status of command issuing.\r | |
217 | **/\r | |
05fbd06d | 218 | EFI_STATUS\r |
219 | PS2MouseSetSampleRate (\r | |
220 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
221 | IN MOUSE_SR SampleRate\r | |
ed66e1bc | 222 | );\r |
05fbd06d | 223 | \r |
ff1fcef8 | 224 | /**\r |
225 | Issue command to set mouse's resolution.\r | |
226 | \r | |
227 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
228 | @param Resolution value of resolution\r | |
229 | \r | |
230 | @return Status of command issuing.\r | |
231 | **/\r | |
05fbd06d | 232 | EFI_STATUS\r |
233 | PS2MouseSetResolution (\r | |
234 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
235 | IN MOUSE_RE Resolution\r | |
ed66e1bc | 236 | );\r |
05fbd06d | 237 | \r |
ff1fcef8 | 238 | /**\r |
239 | Issue command to set mouse's scaling.\r | |
240 | \r | |
241 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
242 | @param Scaling value of scaling\r | |
243 | \r | |
244 | @return Status of command issuing.\r | |
245 | **/\r | |
05fbd06d | 246 | EFI_STATUS\r |
247 | PS2MouseSetScaling (\r | |
248 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
249 | IN MOUSE_SF Scaling\r | |
ed66e1bc | 250 | );\r |
05fbd06d | 251 | \r |
ff1fcef8 | 252 | /**\r |
253 | Issue command to enable Ps2 mouse.\r | |
254 | \r | |
255 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
256 | \r | |
257 | @return Status of command issuing.\r | |
258 | **/\r | |
05fbd06d | 259 | EFI_STATUS\r |
260 | PS2MouseEnable (\r | |
261 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
ed66e1bc | 262 | );\r |
05fbd06d | 263 | \r |
ff1fcef8 | 264 | /**\r |
265 | Get mouse packet . Only care first 3 bytes\r | |
05fbd06d | 266 | \r |
ff1fcef8 | 267 | @param MouseDev Pointer of PS2 Mouse Private Data Structure \r |
05fbd06d | 268 | \r |
ff1fcef8 | 269 | @retval EFI_NOT_READY Mouse Device not ready to input data packet, or some error happened during getting the packet\r |
270 | @retval EFI_SUCCESS The data packet is gotten successfully.\r | |
05fbd06d | 271 | \r |
bcd70414 | 272 | **/\r |
05fbd06d | 273 | EFI_STATUS\r |
274 | PS2MouseGetPacket (\r | |
275 | PS2_MOUSE_DEV *MouseDev\r | |
ed66e1bc | 276 | );\r |
05fbd06d | 277 | \r |
ff1fcef8 | 278 | /**\r |
279 | Read data via IsaIo protocol with given number.\r | |
280 | \r | |
281 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
282 | @param Buffer Buffer receive data of mouse\r | |
283 | @param BufSize The size of buffer\r | |
284 | @param State Check input or read data\r | |
285 | \r | |
286 | @return status of reading mouse data.\r | |
287 | **/\r | |
05fbd06d | 288 | EFI_STATUS\r |
289 | PS2MouseRead (\r | |
290 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
291 | OUT VOID *Buffer,\r | |
292 | IN OUT UINTN *BufSize,\r | |
293 | IN UINTN State\r | |
294 | );\r | |
295 | \r | |
296 | //\r | |
297 | // 8042 I/O function\r | |
298 | //\r | |
ff1fcef8 | 299 | /**\r |
300 | I/O work flow of outing 8042 command.\r | |
301 | \r | |
302 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
303 | @param Command I/O command.\r | |
304 | \r | |
305 | @retval EFI_SUCCESS Success to excute I/O work flow\r | |
306 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
307 | **/\r | |
05fbd06d | 308 | EFI_STATUS\r |
309 | Out8042Command (\r | |
310 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
311 | IN UINT8 Command\r | |
312 | );\r | |
313 | \r | |
ff1fcef8 | 314 | /**\r |
315 | I/O work flow of in 8042 data.\r | |
316 | \r | |
317 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
318 | @param Data Data value\r | |
319 | \r | |
320 | @retval EFI_SUCCESS Success to excute I/O work flow\r | |
321 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
322 | **/\r | |
05fbd06d | 323 | EFI_STATUS\r |
324 | In8042Data (\r | |
325 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
326 | IN OUT UINT8 *Data\r | |
327 | );\r | |
328 | \r | |
ff1fcef8 | 329 | /**\r |
330 | I/O work flow of outing 8042 data.\r | |
331 | \r | |
332 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
333 | @param Data Data value\r | |
334 | \r | |
335 | @retval EFI_SUCCESS Success to excute I/O work flow\r | |
336 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
337 | **/\r | |
05fbd06d | 338 | EFI_STATUS\r |
339 | Out8042Data (\r | |
340 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
341 | IN UINT8 Data\r | |
342 | );\r | |
343 | \r | |
ff1fcef8 | 344 | /**\r |
345 | I/O work flow of outing 8042 Aux command.\r | |
346 | \r | |
347 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
348 | @param Command Aux I/O command\r | |
349 | @param Resend Whether need resend the Aux command.\r | |
350 | \r | |
351 | @retval EFI_SUCCESS Success to excute I/O work flow\r | |
352 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
353 | **/\r | |
05fbd06d | 354 | EFI_STATUS\r |
355 | Out8042AuxCommand (\r | |
356 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
357 | IN UINT8 Command,\r | |
358 | IN BOOLEAN Resend\r | |
359 | );\r | |
360 | \r | |
ff1fcef8 | 361 | /**\r |
362 | I/O work flow of in 8042 Aux data.\r | |
363 | \r | |
364 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
365 | @param Data Buffer holding return value.\r | |
366 | \r | |
367 | @retval EFI_SUCCESS Success to excute I/O work flow\r | |
368 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
369 | **/\r | |
05fbd06d | 370 | EFI_STATUS\r |
371 | In8042AuxData (\r | |
372 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
373 | IN OUT UINT8 *Data\r | |
374 | );\r | |
375 | \r | |
ff1fcef8 | 376 | /**\r |
377 | I/O work flow of outing 8042 Aux data.\r | |
378 | \r | |
379 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
172870ef | 380 | @param Data Buffer holding return value\r |
ff1fcef8 | 381 | \r |
382 | @retval EFI_SUCCESS Success to excute I/O work flow\r | |
383 | @retval EFI_TIMEOUT Keyboard controller time out.\r | |
384 | **/\r | |
05fbd06d | 385 | EFI_STATUS\r |
386 | Out8042AuxData (\r | |
387 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
388 | IN UINT8 Data\r | |
389 | );\r | |
390 | \r | |
ff1fcef8 | 391 | /**\r |
172870ef | 392 | Check keyboard controller status, if it is output buffer full and for auxiliary device.\r |
ff1fcef8 | 393 | \r |
394 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
395 | \r | |
396 | @retval EFI_SUCCESS Keyboard controller is ready\r | |
397 | @retval EFI_NOT_READY Keyboard controller is not ready\r | |
398 | **/\r | |
05fbd06d | 399 | EFI_STATUS\r |
400 | CheckForInput (\r | |
401 | IN EFI_ISA_IO_PROTOCOL *IsaIo\r | |
402 | );\r | |
403 | \r | |
ff1fcef8 | 404 | /**\r |
405 | I/O work flow to wait input buffer empty in given time.\r | |
406 | \r | |
407 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
408 | @param Timeout Wating time.\r | |
409 | \r | |
410 | @retval EFI_TIMEOUT if input is still not empty in given time.\r | |
411 | @retval EFI_SUCCESS input is empty.\r | |
412 | **/\r | |
05fbd06d | 413 | EFI_STATUS\r |
414 | WaitInputEmpty (\r | |
415 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
416 | IN UINTN Timeout\r | |
417 | );\r | |
418 | \r | |
ff1fcef8 | 419 | /**\r |
420 | I/O work flow to wait output buffer full in given time.\r | |
421 | \r | |
422 | @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r | |
423 | @param Timeout given time\r | |
424 | \r | |
425 | @retval EFI_TIMEOUT output is not full in given time\r | |
426 | @retval EFI_SUCCESS output is full in given time.\r | |
427 | **/\r | |
05fbd06d | 428 | EFI_STATUS\r |
429 | WaitOutputFull (\r | |
430 | IN EFI_ISA_IO_PROTOCOL *IsaIo,\r | |
431 | IN UINTN Timeout\r | |
432 | );\r | |
433 | \r | |
24a2dd3d | 434 | #endif\r |
435 | \r |