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