2 PS2 Mouse Communication Interface
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 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.
20 #define PS2_PACKET_LENGTH 3
21 #define PS2_SYNC_MASK 0xc
22 #define PS2_SYNC_BYTE 0x8
24 #define IS_PS2_SYNC_BYTE(byte) ((byte & PS2_SYNC_MASK) == PS2_SYNC_BYTE)
26 #define PS2_READ_BYTE_ONE 0
27 #define PS2_READ_DATA_BYTE 1
28 #define PS2_PROCESS_PACKET 2
31 #define BAT_TIMEOUT 500000
36 #define KBC_DATA_PORT 0x60
37 #define KBC_CMD_STS_PORT 0x64
42 #define READ_CMD_BYTE 0x20
43 #define WRITE_CMD_BYTE 0x60
44 #define DISABLE_AUX 0xa7
45 #define ENABLE_AUX 0xa8
46 #define SELF_TEST 0xaa
47 #define DISABLE_KB 0xad
48 #define ENABLE_KB 0xae
49 #define WRITE_AUX_DEV 0xd4
51 #define CMD_SYS_FLAG 0x04
52 #define CMD_KB_STS 0x10
53 #define CMD_KB_DIS 0x10
57 // 8042 Auxiliary Device Command
59 #define SETSF1_CMD 0xe6
60 #define SETSF2_CMD 0xe7
61 #define SETRE_CMD 0xe8
63 #define SETRM_CMD 0xf0
64 #define SETSR_CMD 0xf3
65 #define ENABLE_CMD 0xf4
66 #define DISABLE_CMD 0xf5
67 #define RESET_CMD 0xff
73 #define PS2_RESEND 0xfe
74 #define PS2MOUSE_BAT1 0xaa
75 #define PS2MOUSE_BAT2 0x0
78 // Keyboard Controller Status
89 /// Output buffer for auxiliary device (PS/2):
90 /// 0 - Holds keyboard data
91 /// 1 - Holds data for auxiliary device
95 /// Keyboard lock status:
96 /// 0 - keyboard locked
102 /// 0 - data byte written via port 60h
103 /// 1 - command byte written via port 64h
108 /// 0 - power-on reset
109 /// 1 - self-test successful
111 #define KBC_SYSF 0x04
113 /// Input Buffer Status :
114 /// 0 - input buffer empty
115 /// 1 - CPU data in input buffer
117 #define KBC_INPB 0x02
119 /// Output Buffer Status :
120 /// 0 - output buffer empty
121 /// 1 - keyboard controller data in output buffer
123 #define KBC_OUTB 0x01
126 Issue self test command via IsaIo interface.
128 @return EFI_SUCCESS Success to do keyboard self testing.
129 @return others Fail to do keyboard self testing.
137 Issue command to enable keyboard AUX functionality.
139 @return Status of command issuing.
147 Issue command to disable keyboard AUX functionality.
149 @return Status of command issuing.
157 Issue command to enable keyboard.
159 @return Status of command issuing.
167 Issue command to disable keyboard.
169 @return Status of command issuing.
177 Issue command to check keyboard status.
179 @param KeyboardEnable return whether keyboard is enable.
181 @return Status of command issuing.
185 OUT BOOLEAN
*KeyboardEnable
189 Issue command to reset keyboard.
191 @return Status of command issuing.
199 Issue command to set mouse's sample rate
201 @param SampleRate value of sample rate
203 @return Status of command issuing.
206 PS2MouseSetSampleRate (
207 IN MOUSE_SR SampleRate
211 Issue command to set mouse's resolution.
213 @param Resolution value of resolution
215 @return Status of command issuing.
218 PS2MouseSetResolution (
219 IN MOUSE_RE Resolution
223 Issue command to set mouse's scaling.
225 @param Scaling value of scaling
227 @return Status of command issuing.
235 Issue command to enable Ps2 mouse.
237 @return Status of command issuing.
245 Get mouse packet . Only care first 3 bytes
247 @param MouseDev Pointer of PS2 Mouse Private Data Structure
249 @retval EFI_NOT_READY Mouse Device not ready to input data packet, or some error happened during getting the packet
250 @retval EFI_SUCCESS The data packet is gotten successfully.
255 PS2_MOUSE_DEV
*MouseDev
259 Read data via IsaIo protocol with given number.
261 @param Buffer Buffer receive data of mouse
262 @param BufSize The size of buffer
263 @param State Check input or read data
265 @return status of reading mouse data.
270 IN OUT UINTN
*BufSize
,
278 I/O work flow of outing 8042 command.
280 @param Command I/O command.
282 @retval EFI_SUCCESS Success to execute I/O work flow
283 @retval EFI_TIMEOUT Keyboard controller time out.
291 I/O work flow of in 8042 data.
293 @param Data Data value
295 @retval EFI_SUCCESS Success to execute I/O work flow
296 @retval EFI_TIMEOUT Keyboard controller time out.
304 I/O work flow of outing 8042 data.
306 @param Data Data value
308 @retval EFI_SUCCESS Success to execute I/O work flow
309 @retval EFI_TIMEOUT Keyboard controller time out.
317 I/O work flow of outing 8042 Aux command.
319 @param Command Aux I/O command
320 @param Resend Whether need resend the Aux command.
322 @retval EFI_SUCCESS Success to execute I/O work flow
323 @retval EFI_TIMEOUT Keyboard controller time out.
332 I/O work flow of in 8042 Aux data.
334 @param Data Buffer holding return value.
336 @retval EFI_SUCCESS Success to execute I/O work flow
337 @retval EFI_TIMEOUT Keyboard controller time out.
345 I/O work flow of outing 8042 Aux data.
347 @param Data Buffer holding return value
349 @retval EFI_SUCCESS Success to execute I/O work flow
350 @retval EFI_TIMEOUT Keyboard controller time out.
358 Check keyboard controller status, if it is output buffer full and for auxiliary device.
360 @retval EFI_SUCCESS Keyboard controller is ready
361 @retval EFI_NOT_READY Keyboard controller is not ready
369 I/O work flow to wait input buffer empty in given time.
371 @param Timeout Wating time.
373 @retval EFI_TIMEOUT if input is still not empty in given time.
374 @retval EFI_SUCCESS input is empty.
382 I/O work flow to wait output buffer full in given time.
384 @param Timeout given time
386 @retval EFI_TIMEOUT output is not full in given time
387 @retval EFI_SUCCESS output is full in given time.