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