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 1 [ Input Port ]

Pin

Name

Function

0

P10

Keyboard Data [PS/2]

1

P11

Mouse Data [PS/2]

2

P12


3

P13


4

P14

External ROM

1:Enable 

0:Disable

5

P15

Manufacturing Setting

1:Enable

0:Disable

6

P16

Display Type Switch

1:Color

0:Monochrome

7

P17

Keyboard Inhibit Switch

1:Enable

0:Disable


  • PORT #2

Port 2 [ Output Port ]

Pin

Name

Function

0

P20

System Reset

1:Nornal

0:Reset 

1

P21

Gate A20

2

P22

Mouse Data [PS/2]

1:Pull Data low

0:High –Z

3

P23

Mouse Clock [PS/2]

1:Pull Data low

0:High –Z

4

P24

Input Buffer Full / Keyboard IBF interrupt [PS/2]

1:Assert IRQ 1

0:Deassert IRQ1

5

P25

Output Buffer Empty / Mouse IBF interrupt [PS/2]

1:Assert IRQ 12

0:De-assert IRQ12

6

P26

Keyboard Clock

1:Pull Clock low

0:High Z

7

P27

Keyboard Data

1:Pull Data low

0:High Z


  • PORT #3

Port 3 [ Test Port ]

Pin

Name

Function

0

T0

Keyboard Clock

1

T1

Keyboard Data

2



3



4



5



6



7




  • Status Register



7

6

5

4

3

2

1

0

AT – Compatible Mode

PERR

RxTO

TxTO

INH

A2

SYS

IBF

OBF

PS/2 – Compatible Mode

PERR

TO

MOBF

INH

A2

SYS

IBF

OBF


  • 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



7

6

5

4

3

2

1

0

AT – Compatible Mode


XLAT

PC

_IN

OVR

SYS


INT

PS/2 – Compatible Mode


XLAT

_EN2

_IN


SYS

INT2

INT

  • 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.

WaitIBE:

          in      al,64h

          and     al,10b

jnz WaitIBE

          out     60h,cl



  • 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.

WaitOBF:

          in      al,64h

          and     al,01b

          jz      WaitOBF

          in      al,60h


  • 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.

Value

Description

Value

Description

0x0

OK

0x3

Data Line 為 LOW

0x1

Clock line is LOW

0x4

Data Line 為 HIGH

0x2

Clock line is HIGH



  • 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.

Value

Description

Value

Description

0x0

OK

0x3

Data Line 為 LOW

0x1

Clock line is LOW

0x4

Data Line 為 HIGH

0x2

Clock line is HIGH



  • 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


留言

這個網誌中的熱門文章

EC 所需知識 - SMBUS

EC Required Knowledge - LPC