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