AMD Geode™ CS5536 Companion Device Data Book 121
Keyboard Emulation Logic 33238G
5.10.2 Keyboard Emulation Overview
The purpose of the KEL is to model the legacy 8042 key-
board/mouse controller interfaced via legacy I/O Addresses
060h and 064h (also known as Ports 60 and 64). This hard-
ware and supporting processor System Management
Mode (SMM) software are designed to support systems
that do not have a true PS/2-compatible keyboard and/or
mouse interface, but those that have alternative devices
performing the equivalent function. Generally, the alterna-
tive device is a keyboard or mouse off a USB (Universal
Serial Bus) port, but it need not be. Due to the origins of the
hardware to be explained shortly, this discussion generally
assumes a USB alternative device, but this is not a require-
ment from a hardware perspective.
The KEL closely models the keyboard emulation hardware
detailed in the USB OHCI specification. It is specifically
designed to be software compatible with this model. In the
USB model, it is part of the USB “Host Controller”, but is
logically separate from it. The discussion and description
that follows is taken from the OHCI specification, but with
modifications to reflect the CS5536 companion device spe-
cific implementation.
To support applications and drivers in non-USB-aware
environments (e.g., DOS), a peripheral subsystem needs
to provide some hardware support for the emulation of a
PS/2 keyboard and/or mouse by their USB equivalents
(alternative devices). For OHCI, this emulation support is
provided by a set of registers that are controlled by code
running in SMM. Working in conjunction, this hardware and
software produces approximately the same behavior-to-
application code as would be produced by a PS/2-compati-
ble keyboard and/or mouse interface.
When data is received from the alternative device, the
emulation code is notified and becomes responsible for
translating the alternative device keyboard/mouse data into
a data sequence that is equivalent to what would be pro-
duced by a PS/2-compatible keyboard/mouse interface.
The translated data is made available to the system
through the legacy keyboard interface I/O Addresses 060h
and 064h. Likewise, when data/control is to be sent to the
alternative device (as indicated by the system writing to the
legacy keyboard interface), the emulation code is notified
and becomes responsible for translating the information
into appropriate data to be sent to the alternative device.
On the PS/2 keyboard/mouse interface, a read of I/O
Address 060h returns the current contents of the keyboard
output buffer; a read of I/O Address 064h returns the con-
tents of the keyboard status register. An I/O write to I/O
Addresses 060h and 064h puts data into the keyboard
input buffer (data is being input into the keyboard sub-
system). When emulation is enabled, reads and writes of
I/O Addresses 060h and 064h are captured in the KEL
HCE Output, Status, and/or Input operational registers.
The KEL described here supports a mixed environment in
which either the keyboard or mouse is implemented as an
alternative device and the other device is attached to a
standard PS/2 interface.
The following subsections use the term “alternate device
interrupt”. This is an ASMI or IRQ as appropriate for the
device; for example the USB can generate either an ASMI
or IRQ. The KEL generates a separate ASMI or IRQ.
5.10.3 Theory - Keyboard / Mouse Input
When data is received from the alternative device, the
emulation code is notified with an alternate device interrupt
and translates the keyboard/mouse data into an equivalent
PS/2-compatible sequence for presentation to the applica-
tion software. For each byte of PS/2-compatible data that is
to be presented to the applications software, the emulation
code writes to KEL_HCE_OUT (KEL Memory Offset 108h).
The emulation code then sets the appropriate bits in
KEL_HCE_STS (KEL Memory Offset 10Ch) (normally,
OutputFull (bit 0) is set for keyboard data and OutputFull
plus AuxOutputFull (bit 5) for mouse data). If key-
board/mouse interrupts are enabled, setting the
KEL_HCE_STS bits causes the generation of an IRQ1 for
keyboard data and IRQ12 for mouse data. The emulation
code then exits and waits for the next alternate device inter-
rupt.
When the host CPU exits from SMM, it can service the
pending IRQ1/IRQ12. This normally results in a read from
I/O Address 060h. When I/O Address 060h is read, the
KEL intercepts the access and returns the current contents
of KEL_HCE_OUT. The KEL also clears the OutputFull bit
in KEL_HCE_STS (KEL Memory Offset 10Ch[0]) and de-
asserts IRQ1/IRQ12.
If the emulation software has multiple characters to send to
the application software, it sets the CharacterPending bit in
KEL_HCE_CTRL (KEL Memory Offset 100h[2]). This
causes the KEL to generate an ASMI at the beginning of
the next frame, a time after the application read from I/O
Port 060h (KEL_HCE_OUT).
5.10.4 Theory - Keyboard Output
Keyboard output is indicated by application software writing
data to either I/O Address 060h or 064h. Upon a write to
either address, the KEL captures the data in KEL_HCE_IN
(KEL Memory Offset 104h) and, except in the case of a
FA20# (Force processor Address bit 20 to zero when low)
sequence, updates the InputFull and CmdData bits (KEL
Memory Offset 10Ch[1,3]). When the InputFull bit is set, a
KEL ASMI is generated at the beginning of the next frame.
Upon receipt of the KEL ASMI, the emulation software
reads KEL_HCE_CTRL and KEL_HCE_STS to determine
the cause of the emulation interrupt and performs the oper-
ation indicated by the data. Generally, this means putting
out data to the alternate device.
5.10.5 Emulation Events
Emulation Events (EEs) are caused by reads and writes of
the emulation registers. EEs generated by the emulation
hardware are steered by the KEL to either an ASMI or an
Emulation Interrupt. Steering is determined by the Emula-
tion Event Routing bit (MSR 5140001Fh[1]).