EC Required Knowledge - KBC
EC Required Knowledge
The first step for a software engineer is to thoroughly understand the relevant specifications, just as understanding the requirements is essential before developing software. Similarly, an EC engineer needs to have a clear understanding of LPC, SMBUS, PS2, KBC, and other related knowledge before moving on to the next step.
Keyboard Controller
The earliest keyboard controller was the Intel 8042, which mainly consisted of four registers and three I/O control ports. The four registers were a BYTE input buffer register, a BYTE output buffer register, a status register, and a control register.
The definitions of the three I/O control ports are shown in the table below:
PORT #1
PORT #2
PORT #3
Status Register
OBF(Output Buffer Full) – Indicates that data has been written to the 8042's output buffer.
IBF(Input Buffer Full) – The system writes data to the 8042 input buffer.
SYS(System Flag) – Indicates whether the system is Warning Boot or Cold Boot. "1" indicates Warning Boot.
A2(Address line 2) – Indicates whether system data is written to I/O PORT 0x64 or 0x60. "1" indicates PORT 0x64.
INH(Inhibit flag) – Indicates whether the system and PS/2 KEYBOARD interface are functioning correctly. LOW indicates that the clock is set to LOW, meaning that communication between the system and PS/2 KEYBOARD is disabled.
TxTO(Transmit Timeout) – The system sends a command to the keyboard but it is not received within the time limit, meaning there may be no keyboard on the system. "0" indicates that no timeout occurred.
RxTO(Receive Timeout) – Indicates that the keyboard did not respond to the system command within the time limit. "0" indicates that no timeout occurred.
PERR(Parity Error) – Indicates that there is incorrect data being transmitted between the system and the keyboard. "0" indicates that there is no incorrect data.
MOBF(Mouse Output Buffer Full) – Indicates that data has been sent to the output buffer of the PS/2 mouse.
TO(General Timeout) – Indicates that the command was not received within the time limit or that the KEYBOARD did not respond to the system command within the time limit.
Control Register
INT(Output Buffer Full Interrupt) – Controls whether to send IRQ 1 to the system when there is data in the keyboard output buffer.
SYS(System Flag) – Indicates a system boot event. "1" indicates Warning Boot.
OVR(Inhibit Override) – Controls whether the interface between the KBC and the system is disabled via the I/O PIN.
_IN(Disable Keyboard) – Setting this bit will stop the keyboard from sending data to the system.
PC (PC Mode) –
XLAT(Translate Scan Code) – Sets the keyboard Scan Code Set; "1" indicates Code Set 1.
_INT2(Mouse Output Buffer Full Interrupt) – Controls whether to send IRQ 12 to the system when there is data in the mouse output buffer.
_EN2(Disable Mouse) - Setting this bit will stop the mouse from sending data to the system.
How does the system read and write KBC?
Before writing instructions to the KBC, the system must first check if there are any instructions or data that have not yet been retrieved from the KBC's input buffer. Then, it sends the instructions or data to the KBC.
Before reading data from the KBC, the system must first check whether there is any data written by the KBC in the KBC's output buffer, and then read the data.
Keyboard Controller Command
System commands are transmitted to the KBC via PORT 0x64, and system data is transmitted to the KBC via PORT 0x60. The KBC then performs the relevant actions on the commands and data. The KBC commands are as follows:
0x20 (Read Command Byte) – Reads the control bits of the KBC.
0x60 (Write Command Byte) – Control bits written to the KBC
0x90-0x9F (Write to output buffer) –
0xA1 (Get firmware version) – Get the KBC firmware version
0xA4 (Get password) – Check if a password has been set. If a password has been set, KBC will respond with 0xFA; if no password has been set, KBC will respond with 0xF1.
0xA5 (Set password) – Sets the user password.
0xA6 (Check password) – Compares the entered password to ensure it is correct.
0xA7 (Disable mouse interface)
0xA8 (Enable mouse interface)
0xA9 (Mouse interface test) – Test the mouse interface.
0xAA (Controller self test) – KBC self-test. A successful self-test will respond with 0x55 to the system.
0xAB (Keyboard interface test) – Test the keyboard interface.
0xAD (Disable Keyboard interface)
0xAE (Enable Keyboard interface)
0xAF (Get version)
0xC0 (Read Input port) – Read input port [PORT 1]
0xC1 (Copy input port low nibble) - Reads bits [0:3] of input port [PORT 1] and copies them to the status register.
0xC2 (Copy input port high nibble) – Reads bits [4:7] of input port [PORT 1] and copies them to the status register.
0xD0 (Read output port) – Read output port [PORT 2]
0xD1 (Write output port) – Writes data to output port [PORT 2]
0xD2 (Write Keyboard buffer) – Writes data to the keyboard output buffer.
0xD3 (Write Mouse buffer) – Writes data to the mouse's output buffer.
0xD4 (Write Mouse Device) – Writes data or commands to the mouse.
0xE0 (Read Test Port) – Read test port [PORT 3]
0xFE (Warning Start) – Initiate CPU Reset
留言
張貼留言