summaryrefslogtreecommitdiff
path: root/Core/EM/KbcEmul/Kbc.h
blob: 9ae5c9b1b3a482ee683d89ce201a6afd2ca8e24a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**         5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/KbcEmulation/ALASKA/KBCEMUL/Kbc.h 5     2/10/11 1:01a Rameshr $
//
// $Revision: 5 $
//
// $Date: 2/10/11 1:01a $
//
//****************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/KbcEmulation/ALASKA/KBCEMUL/Kbc.h $
// 
// 5     2/10/11 1:01a Rameshr
// [TAG]  		EIP53687
// [Category]  	Improvement
// [Description]  	AMI headers update for KbcEmulation Module 
// [Files]  		KbcEmul.mak,KbcEmul.dxs,KbcEmul.c,KbcEmul.h,KbcEmulLib.h,Kbc
// EmulLib.c,Kbc.h,KbcDevEmul.h,Kbccore.c,Legacykbc.c,Legacykbd.c,LegacyMo
// use.c,VirtualKbc.c,VirtualKbd.c,VirtualMouse.c,Ap4x.h,Ap4x.c,KbcUhci.c,
// KbcUhci.h,KbcEmulIrq.c, KbcOhci.c, Kbcohci.h
// 
// 4     12/23/09 1:30a Rameshr
// Symptom: KbcEmulation can't install FreeBSD
// Solution: Implemented command 0xAA (Controller self-test) and 0xAB
// (Keyboard interface test)
// EIP: 26451
// 
// 3     6/30/09 11:29a Rameshr
// Coding Standard and File header updated.
// 
// 2     12/27/07 4:54p Rameshraju
// KBC reset command added
// 
// 1     12/14/07 10:26a Rameshraju
// Initial Check-in
//****************************************************************************

//<AMI_FHDR_START>
//**********************************************************************
//
// Name:        Kbc.h
//
// Description: KBC Header file has the structure defination for Virtual and Legacy devices
//
//**********************************************************************
//<AMI_FHDR_END>

#ifndef __INC_KBC_H__
#define __INC_KBC_H__

#ifdef FRAMEWORK_AP4
#include "token.h"
#else
#include "tokens.h"
#endif

typedef struct _KBC KBC;
typedef struct _PS2SINK PS2SINK;

typedef enum {
    PS2DEV_KBD = 0x0,
    PS2DEV_MOUSE = 0x1,
} PS2DEV_TYPE;
#define     KBC_SENDQUEUE_SIZE 15

struct _PS2SINK {
    //
    //notify about a command from application
    //
    void (*onCommand)(PS2SINK* dev, UINT8 cmd );

    //
    //notify that queue is empty; pull streaming data
    //
    void (*onQueueFree)(PS2SINK* dev);

    KBC* kbc;
    BOOLEAN present_;
    BOOLEAN presence_detected_;
};

struct _KBC{
    void (*kbc_write_command)(KBC* kbc, UINT8 cmd );
    void (*kbc_write_data)(KBC* kbc, UINT8 data );
    UINT8 (*kbc_read_status)(KBC* kbc );
    UINT8 (*kbc_read_data)(KBC* kbc );

    BOOLEAN (*send_outb1)( KBC* kbc, PS2DEV_TYPE devtype, BOOLEAN ovrd, UINT8 data );
    UINT8 (*read_ccb)(KBC* kbc);
    PS2SINK* mouse_dev;
    PS2SINK* kbd_dev;
    UINT8 send_queue[KBC_SENDQUEUE_SIZE];
    UINT8 send_queue_aux[KBC_SENDQUEUE_SIZE];
    UINT8* sqHead[2];
    UINT8* sqTail[2];

    int     nSeq;
    UINT8   aux_en; // aux interface enabled/disabled (value is a KBC command)
    UINT8   kbd_en; // kbd interface enabled/disabled (value is a KBC command)
};


#define KBC_STATUS_REG              0x64
#define KBC_COMMAND_REG             0x64
#define KBC_DATA_REG                0x60
#define KBCTIMEOUT                  0x1000
//
// KBC Status bits definition
//
#define KBC_STATUS_OBF              0x1
#define KBC_STATUS_IBF              0x2
#define KBC_STATUS_SYS              0x4
#define KBC_STATUS_A2               0x8
#define KBC_STATUS_INH              0x10
#define KBC_STATUS_AUXB             0x20
#define KBC_STATUS_TO               0x40            //Timeout detected
#define KBC_STATUS_PERR             0x80            //Parity error detected

//
// KBC CCB bits definition
//
#define KBC_CCB_INT             0x01
#define KBC_CCB_INT2            0x02
#define KBC_CCB_SYS             0x04
#define KBC_CCB_EN              0x10
#define KBC_CCB_EN2             0x20
#define KBC_CCB_XLAT            0x40


//
//KBC output bits definition
//
#define CCB_KEYBOARD_DISABLED               0x10
#define CCB_MOUSE_DISABLED                  0x20
#define CCB_TRANSLATE_SCAN_CODE_BIT_MASK    0x40


//
// KBC Commands
//
#define KBCCMD_WriteAuxBuffer           0xD3
#define KBCCMD_WriteKbdBuffer           0xD2
#define KBCCMD_WriteAuxDev              0xD4
#define KBCCMD_READ_CCB                 0x20
#define KBCCMD_WRITE_CCB                0x60
#define KBCCMD_LOCK                     USB_SEND_COMMAND_TO_KBC
#define KBCCMD_AUXENBL                  0xA8
#define KBCCMD_AUXDSBL                  0xA7
#define KBCCMD_KBDENBL                  0xAE
#define KBCCMD_KBDDSBL                  0xAD
#define KBCCMD_CheckAux                 0xA9
#define KBCCMD_CheckKbd                 0xAB
#define KBCCMD_SelfTest                 0xAA
#define KBCCMD_ReadInPort               0xC0
#define KBCCMD_ReadOutPortL             0xC1
#define KBCCMD_ReadOutPortH             0xC2
#define KBCCMD_ReadOutPort              0xD0
#define KBCCMD_WriteOutPort             0xD1
#define KBCCMD_ResetSystem              0xFE

//
// KBC Command Status Response
//
#define KBCCMD_RES_SelfTestOk           0x55
#define KBCCMD_RES_KBInterfaceOk        0


#endif // __INC_KBC_H__

//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**         5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************
//****************************************************************************