2 PS2 Mouse Communication Interface
4 Copyright (c) 2006 - 2007, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #define PS2_PACKET_LENGTH 3
19 #define PS2_SYNC_MASK 0xc
20 #define PS2_SYNC_BYTE 0x8
22 #define IS_PS2_SYNC_BYTE(byte) ((byte & PS2_SYNC_MASK) == PS2_SYNC_BYTE)
24 #define PS2_READ_BYTE_ONE 0
25 #define PS2_READ_DATA_BYTE 1
26 #define PS2_PROCESS_PACKET 2
29 #define BAT_TIMEOUT 500000
34 #define KBC_DATA_PORT 0x60
35 #define KBC_CMD_STS_PORT 0x64
40 #define READ_CMD_BYTE 0x20
41 #define WRITE_CMD_BYTE 0x60
42 #define DISABLE_AUX 0xa7
43 #define ENABLE_AUX 0xa8
44 #define SELF_TEST 0xaa
45 #define DISABLE_KB 0xad
46 #define ENABLE_KB 0xae
47 #define WRITE_AUX_DEV 0xd4
49 #define CMD_SYS_FLAG 0x04
50 #define CMD_KB_STS 0x10
51 #define CMD_KB_DIS 0x10
55 // 8042 Auxiliary Device Command
57 #define SETSF1_CMD 0xe6
58 #define SETSF2_CMD 0xe7
59 #define SETRE_CMD 0xe8
61 #define SETRM_CMD 0xf0
62 #define SETSR_CMD 0xf3
63 #define ENABLE_CMD 0xf4
64 #define DISABLE_CMD 0xf5
65 #define RESET_CMD 0xff
71 #define PS2_RESEND 0xfe
72 #define PS2MOUSE_BAT1 0xaa
73 #define PS2MOUSE_BAT2 0x0
76 // Keyboard Controller Status
78 #define KBC_PARE 0x80 // Parity Error
79 #define KBC_TIM 0x40 // General Time Out
80 #define KBC_AUXB 0x20 // Output buffer for auxiliary device (PS/2):
81 // 0 - Holds keyboard data
82 // 1 - Holds data for auxiliary device
84 #define KBC_KEYL 0x10 // Keyboard lock status:
85 // 0 - keyboard locked
88 #define KBC_CD 0x08 // Command/Data:
89 // 0 - data byte written via port 60h
90 // 1 - command byte written via port 64h
92 #define KBC_SYSF 0x04 // System Flag:
94 // 1 - self-test successful
96 #define KBC_INPB 0x02 // Input Buffer Status :
97 // 0 - input buffer empty
98 // 1 - CPU data in input buffer
100 #define KBC_OUTB 0x01 // Output Buffer Status :
101 // 0 - output buffer empty
102 // 1 - keyboard controller data in output buffer
106 Issue self test command via IsaIo interface.
108 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
110 @return EFI_SUCCESS Success to do keyboard self testing.
111 @return others Fail to do keyboard self testing.
115 IN EFI_ISA_IO_PROTOCOL
*IsaIo
119 Issue command to enable keyboard AUX functionality.
121 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
123 @return Status of command issuing.
127 IN EFI_ISA_IO_PROTOCOL
*IsaIo
131 Issue command to disable keyboard AUX functionality.
133 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
135 @return Status of command issuing.
139 IN EFI_ISA_IO_PROTOCOL
*IsaIo
143 Issue command to enable keyboard.
145 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
147 @return Status of command issuing.
151 IN EFI_ISA_IO_PROTOCOL
*IsaIo
155 Issue command to disable keyboard.
157 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
159 @return Status of command issuing.
163 IN EFI_ISA_IO_PROTOCOL
*IsaIo
167 Issue command to check keyboard status.
169 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
170 @param KeyboardEnable return whether keyboard is enable.
172 @return Status of command issuing.
176 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
177 OUT BOOLEAN
*KeyboardEnable
181 Issue command to reset keyboard.
183 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
185 @return Status of command issuing.
189 IN EFI_ISA_IO_PROTOCOL
*IsaIo
193 Issue command to set mouse's sample rate
195 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
196 @param SampleRate value of sample rate
198 @return Status of command issuing.
201 PS2MouseSetSampleRate (
202 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
203 IN MOUSE_SR SampleRate
207 Issue command to set mouse's resolution.
209 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
210 @param Resolution value of resolution
212 @return Status of command issuing.
215 PS2MouseSetResolution (
216 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
217 IN MOUSE_RE Resolution
221 Issue command to set mouse's scaling.
223 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
224 @param Scaling value of scaling
226 @return Status of command issuing.
230 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
235 Issue command to enable Ps2 mouse.
237 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
239 @return Status of command issuing.
243 IN EFI_ISA_IO_PROTOCOL
*IsaIo
247 Get mouse packet . Only care first 3 bytes
249 @param MouseDev Pointer of PS2 Mouse Private Data Structure
251 @retval EFI_NOT_READY Mouse Device not ready to input data packet, or some error happened during getting the packet
252 @retval EFI_SUCCESS The data packet is gotten successfully.
257 PS2_MOUSE_ABSOLUTE_POINTER_DEV
*MouseAbsolutePointerDev
261 Read data via IsaIo protocol with given number.
263 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
264 @param Buffer Buffer receive data of mouse
265 @param BufSize The size of buffer
266 @param State Check input or read data
268 @return status of reading mouse data.
272 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
274 IN OUT UINTN
*BufSize
,
282 I/O work flow of outing 8042 command.
284 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
285 @param Command I/O command.
287 @retval EFI_SUCCESS Success to excute I/O work flow
288 @retval EFI_TIMEOUT Keyboard controller time out.
292 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
297 I/O work flow of in 8042 data.
299 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
300 @param Data Data value
302 @retval EFI_SUCCESS Success to excute I/O work flow
303 @retval EFI_TIMEOUT Keyboard controller time out.
307 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
312 I/O work flow of outing 8042 data.
314 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
315 @param Data Data value
317 @retval EFI_SUCCESS Success to excute I/O work flow
318 @retval EFI_TIMEOUT Keyboard controller time out.
322 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
327 I/O work flow of outing 8042 Aux command.
329 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
330 @param Command Aux I/O command
331 @param Resend Whether need resend the Aux command.
333 @retval EFI_SUCCESS Success to excute I/O work flow
334 @retval EFI_TIMEOUT Keyboard controller time out.
338 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
344 I/O work flow of in 8042 Aux data.
346 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
347 @param Data Buffer holding return value.
349 @retval EFI_SUCCESS Success to excute I/O work flow
350 @retval EFI_TIMEOUT Keyboard controller time out.
354 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
359 I/O work flow of outing 8042 Aux data.
361 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
362 @param Command Aux I/O command
364 @retval EFI_SUCCESS Success to excute I/O work flow
365 @retval EFI_TIMEOUT Keyboard controller time out.
369 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
374 Check keyboard controller status, if it is output buffer full and for auxiliary device
376 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
378 @retval EFI_SUCCESS Keyboard controller is ready
379 @retval EFI_NOT_READY Keyboard controller is not ready
383 IN EFI_ISA_IO_PROTOCOL
*IsaIo
387 I/O work flow to wait input buffer empty in given time.
389 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
390 @param Timeout Wating time.
392 @retval EFI_TIMEOUT if input is still not empty in given time.
393 @retval EFI_SUCCESS input is empty.
397 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
402 I/O work flow to wait output buffer full in given time.
404 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
405 @param Timeout given time
407 @retval EFI_TIMEOUT output is not full in given time
408 @retval EFI_SUCCESS output is full in given time.
412 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
416 #endif // _COMMPS2_H_