summaryrefslogtreecommitdiff
path: root/Board/EM/Platform/Library/Dxe/DxeKscLib/KscLib.h
blob: 2aee1c76566b85e9b7e05a2665b5f52bab4ce0cb (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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

#ifndef _KSC_LIB_H_
#define _KSC_LIB_H_

//
// Include files
//
///#include "Tiano.h"

//
// Timeout if KSC command/data fails
//
#define KSC_TIME_OUT    0x20000

//
// The Keyboard and System management Controller (KSC) implements a standard 8042 keyboard
// controller interface at ports 0x60/0x64 and a ACPI compliant system management controller
// at ports 0x62/0x66. Port 0x66 is the command and status port, port 0x62 is the data port.
// 
#define KSC_D_PORT        0x62
#define KSC_C_PORT        0x66

//
// Status Port 0x62
//
#define KSC_S_OVR_TMP     0x80    // Current CPU temperature exceeds the threshold
#define KSC_S_SMI_EVT     0x40    // SMI event is pending
#define KSC_S_SCI_EVT     0x20    // SCI event is pending
#define KSC_S_BURST       0x10    // KSC is in burst mode or normal mode
#define KSC_S_CMD         0x08    // Byte in data register is command/data
#define KSC_S_IGN         0x04    // Ignored
#define KSC_S_IBF         0x02    // Input buffer is full/empty
#define KSC_S_OBF         0x01    // Output buffer is full/empty

//
// KSC commands that are issued to the KSC through the command port (0x66). 
// New commands and command parameters should only be written by the host when IBF=0. 
// Data read from the KSC data port is valid only when OBF=1.
//
#define KSC_C_SMI_NOTIFY_ENABLE         0x04    // Enable SMI notifications to the host
#define KSC_C_SMI_NOTIFY_DISABLE        0x05    // SMI notifications are disabled and pending notifications cleared
#define KSC_C_QUERY_SYS_STATUS          0x06    // Returns 1 byte of information about the system status
#define   KSC_B_SYS_STATUS_FAN          0x40    // Fan status (1 = ON)
#define   KSC_B_SYS_STATUS_DOCK         0x20    // Dock status (1 = Docked)
#define   KSC_B_SYS_STATUS_AC           0x10    // AC power (1 = AC powered)
#define   KSC_B_SYS_STATUS_THERMAL      0x0F    // CPU thermal state (0 ~ 9)
#define KSC_C_FAB_ID                    0x0D    // Get the board fab ID in the lower 3 bits
#define KSC_C_SYSTEM_POWER_OFF          0x22    // Turn off the system power
#define KSC_C_LAN_ON                0x46  // Turn on the power to LAN through EC/KSC
#define KSC_C_LAN_OFF               0x47  // Turn off the power to LAN through EC/KSC
#define KSC_C_GET_TEMP              0x50  // Returns the CPU temperature as read from the SMBus thermal sensor.
#define KSC_C_SET_CTEMP             0x58  // The next byte written to the data port will be the shutdown temperature
#define KSC_EC_PCH_SMBUS_EN         0x60  // EC PCH SMBus thermal monitoring Enable cmd
#define KSC_EC_PCH_SMBUS_DIS        0x61  // EC PCH SMBus thermal monitoring Disable cmd
#define KSC_TS_ON_DIMM_EN           0x6B  // TS-on-DIMM thermal monitoring enable command
#define KSC_TS_ON_DIMM_DIS          0x6C  // TS-on-DIMM thermal monitoring disable command
#define KSC_C_PCH_SMBUS_MSG_LENGTH  0x6D  // PCH SMBus block read buffer length
#define KSC_C_PCH_SMBUS_PEC_EN      0x6E  // PCH SMBus Packet Error Checking (PEC) Enable command.
#define KSC_C_PCH_SMBUS_PEC_DIS     0x76  // PCH SMBus Packet Error Checking (PEC) Disable command.
#define KSC_C_EC_SMBUS_HIGH_SPEED   0x75  // EC SMBus high speed mode command
#define KSC_EC_PCH_SMBUS_WRITE_EN   0x68  // EC PCH SMBus Write Enable cmd
#define KSC_EC_PCH_SMBUS_WRITE_DIS  0x69  // EC PCH SMBus Write Disable cmd
#define KSC_C_SMI_QUERY             0x70  // The host reads the data port to retrieve the notifications
#define KSC_C_SMI_TIMER                 0x71    // Commands the KSC to generate a periodic SMI to the host
#define KSC_C_SMI_HOTKEY                0x72    // Get the scan code of hotkey pressed (CTRL + ALT + SHIFT + key)
#define KSC_C_READ_MEM                  0x80    // Read the KSC memory
#define KSC_C_WRITE_MEM                 0x81    // Write the KSC memory
#define KSC_C_DOCK_STATUS               0x8A    // Get the dock status
#define KSC_B_DOCK_STATUS_ATTACH        0x01    // Dock status (1 = Attach)
#define KSC_C_KSC_REVISION              0x90    // Get the revision for the KSC
#define KSC_C_SMI_INJECT                0xBA    // The next byte written to the data port will generate an immediate SMI
#define KSC_C_SMI_DISABLE               0xBC    // SMI generation by the KSC is disabled
#define KSC_C_SMI_ENABLE                0xBD    // SMI generation by the KSC is enabled
#define KSC_C_ACPI_ENABLE               0xAA    // Enable ACPI mode
#define KSC_C_ACPI_DISABLE              0xAB    // Disable ACPI mode

//
// KSC commands that are only valid if the EC has ACPI mode enabled.
// Note that capacity and voltage are 16 bit values, thus you need to read them from
// ACPI space with two reads (little Endian).
//
#define KSC_VIRTUAL_BAT_STATUS                48      // Status of the virtual battery (present)
#define KSC_VIRTUAL_BAT_PRESENT_MASK          0x10    // Bit 4 is the indicator 

#define KSC_REAL_BAT1_STATUS                  50      // Status of the first real battery (present, charging)
#define KSC_REAL_BAT1_REMAINING_CAPACITY      89      // Remaining capacity in mWh
#define KSC_REAL_BAT1_RESOLUTION_VOLTAGE      93      // Full resolution voltage in mV

#define KSC_REAL_BAT2_STATUS                  54      // Status of the second real battery (present, charging)
#define KSC_REAL_BAT2_REMAINING_CAPACITY      99      // Remaining capacity in mWh
#define KSC_REAL_BAT2_RESOLUTION_VOLTAGE      103     // Full resolution voltage in mV

#define KSC_REAL_BAT_PRESENT_MASK             0x8     // Bit 3 is the indicator
#define KSC_REAL_BAT_CHARGING_MASK            0x1     // Bit 1 is the indicator

//
// SMI notification code table, read through command KSC_C_SMI_QUERY
//
#define KSC_N_SMI_NULL                  0x00    // Null marks the end of the SMI notification queue
#define KSC_N_SMI_HOTKEY                0x20    // Hotkey pressed SMI
#define KSC_N_SMI_ACINSERTION           0x30    // AC insertion SMI
#define KSC_N_SMI_ACREMOVAL             0x31    // AC removal SMI
#define KSC_N_SMI_PWRSW                 0x32    // Power switch press SMI
#define KSC_N_SMI_LID                   0x33    // Lid switch change SMI
#define KSC_N_SMI_VB                    0x34    // Virtual battery switch change SMI
#define KSC_N_SMI_THERM_0               0x60    // Thermal state 0 SMI 
#define KSC_N_SMI_THERM_1               0x61    // Thermal state 1 SMI 
#define KSC_N_SMI_THERM_2               0x62    // Thermal state 2 SMI
#define KSC_N_SMI_THERM_3               0x63    // Thermal state 3 SMI
#define KSC_N_SMI_THERM_4               0x64    // Thermal state 4 SMI
#define KSC_N_SMI_THERM_5               0x65    // Thermal state 5 SMI
#define KSC_N_SMI_THERM_6               0x66    // Thermal state 6 SMI
#define KSC_N_SMI_THERM_7               0x67    // Thermal state 7 SMI
#define KSC_N_SMI_THERM_8               0x68    // Thermal state 8 SMI
#define KSC_N_SMI_DOCKED                0x70    // Dock complete SMI
#define KSC_N_SMI_UNDOCKED              0x71    // Undock complete SMI
#define KSC_N_SMI_UNDOCKREQUEST         0x72    // Undocking request SMI
#define KSC_N_SMI_TIMER                 0x80    // Timer wakeup SMI

//
// Hotkey scan code (CTRL + ALT + SHIFT + key)
//
#define KSC_HK_ESC      0x01          // ESC
#define KSC_HK_1        0x02          // 1 !
#define KSC_HK_2        0x03          // 2 @
#define KSC_HK_3        0x04          // 3 #
#define KSC_HK_4        0x05          // 4 $
#define KSC_HK_5        0x06          // 5 %
#define KSC_HK_6        0x07          // 6 ^
#define KSC_HK_7        0x08          // 7 &
#define KSC_HK_8        0x09          // 8 *
#define KSC_HK_9        0x0A          // 9 (
#define KSC_HK_0        0x0B          // 0 )
#define KSC_HK_MINUS    0x0C          // - _
#define KSC_HK_ADD      0x0D          // = +
#define KSC_HK_F1       0x3B          // F1
#define KSC_HK_F2       0x3C          // F2
#define KSC_HK_F3       0x3D          // F3
#define KSC_HK_F4       0x3E          // F4
#define KSC_HK_F5       0x3F          // F5
#define KSC_HK_F6       0x40          // F6
#define KSC_HK_F7       0x41          // F7
#define KSC_HK_F8       0x42          // F8
#define KSC_HK_F9       0x43          // F9
#define KSC_HK_F10      0x44          // F10
#define KSC_HK_F11      0x57          // F11
#define KSC_HK_F12      0x58          // F12

//
// Function declarations
//
EFI_STATUS
InitializeKscLib (
  VOID
  );
/*++

Routine Description:

  This function initializes the KSC library.
  It must be called before using any of the other KSC library functions.

Arguments:

  None.

Returns: 

  EFI_SUCCESS       - KscLib is successfully initialized.

--*/ 

EFI_STATUS
SendKscCommand (
  UINT8   Command
  );
/*++

Routine Description:

  Send a command to the Keyboard System Controller.

Arguments:

  Command  - Command byte to send

Returns: 

  EFI_SUCCESS       - Command success
  EFI_TIMEOUT       - Command timeout
  Other             - Command failed

--*/ 

EFI_STATUS
SendKscData (
  UINT8   Data
  );
/*++

Routine Description:

  Sends data to Keyboard System Controller.

Arguments:

  Data  - Data byte to send

Returns: 

  EFI_SUCCESS       - Success
  EFI_TIMEOUT       - Timeout
  Other             - Failed

--*/ 

EFI_STATUS
ReceiveKscData (
  UINT8   *Data
  );
/*++

Routine Description:

  Receives data from Keyboard System Controller.

Arguments:

  Data  - Data byte received

Returns: 

  EFI_SUCCESS       - Read success
  EFI_TIMEOUT       - Read timeout
  Other             - Read failed

--*/ 

EFI_STATUS
ReceiveKscStatus (
  UINT8   *KscStatus
  );
/*++

Routine Description:

  Receives status from Keyboard System Controller.

Arguments:

  Status  - Status byte to receive
  
Returns: 

  EFI_SUCCESS       - Success
  Other             - Failed

--*/

#endif