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