In computing, a keyboard controller is a device that interfaces a keyboard to a computer. Its main function is to inform the computer when a key is pressed or released. When data from the keyboard arrives, the controller raises an interrupt (a keyboard interrupt) to allow the CPU to handle the input.
If a keyboard is a separate peripheral system unit (such as in most modern desktop computers), the keyboard controller is not directly attached to the keys but receives scancodes from a microcontroller embedded in the keyboard via some kind of serial interface. In this case, the controller usually also controls the keyboard's LEDs by sending data back to the keyboard through the wire.
In the 80s the IBM PC AT used an Intel 8042 chip to interface to the keyboard. This computer also controlled access to the A20 line in order to implement a workaround for a chip bug in the Intel 80286. The keyboard controller was also used to initiate a software CPU reset in order to allow the CPU to transition from protected mode to real mode because the 286 did not allow the CPU to go from protected mode to real mode unless the CPU is reset. This was a problem because the BIOS and the operating system services could only be called by programs in real mode. These behaviors have been used by plenty of software that expects this behavior, and therefore keyboard controllers have continued controlling the A20 line and performing software CPU interrupts even when the need for a reset via the keyboard controller was obviated by the Intel 80386's ability to switch to real mode from protected mode without a CPU reset. The keyboard controller also handles PS/2 mouse input if a PS/2 mouse port is present.
Today the keyboard controller is either a unit inside a super I/O device or is missing, having the keyboard controller integrated in the USB keyboard itself, and its role in controlling the A20 line handled by the chipset.
IBM
IBM plays a small role in the creation of the keyboard controller. With the IBM compatible computers, the keyboard controller or Intel 8042 keyboard controller is found on the motherboard. The controller handles input received from the computer keyboard, A20 lines, reset, deciphering scan codes, as well as the PS/2 mouse. With later models of keyboards, the 8042 was replaced with the 8742 micro-controller, which had a microprocessor, RAM, and I/O ports. Anyone trying to use the classic 8042-style keyboard controller (KBC) found in the IBM PC/AT and nearly all later PCs typically runs into a problem with a lack of accurate documentation. The 8042 (or 8742, or any number of compatible parts built into later Super I/O chips) is actually quite well documented. The catch is that the 8042 is a programmable micro-controller with its own control software in (usually) ROM. Until recently, no one outside a few companies (IBM, AMI, Phoenix) knew exactly what the control software did. IBM documented a number of commands the host can send to the KBC. It should be understood that all those commands are a pure software construct, with nothing about the 8042 hardware dictating that the commands need to follow any specific format, function, or that they even need to be there at all. Therefore, understanding the 8042 ROM code is the only way towards understanding exactly what the commands are and what they do, with the caveat that different controllers may and do have somewhat different code in their ROM.
List of KBC commands
The commands listed as “ignored” perform no function.
00h–1Fh: Read KBC RAM indirect. Not documented. 20h–3Fh: Read KBC RAM at offset 20h-3Fh. Only command 20h is documented by IBM. 40h–5Fh: Write KBC RAM indirect. Not documented. 60h–7Fh: Write KBC RAM at offset 20h-3Fh. Only command 60h is documented by IBM. The byte at offset 20h is the command byte and is treated specially. 80h–A8h: Ignored. AAh: Self test. This command is documented, but its side effects are not. ABh: Interface test. ACh: Diagnostic dump. Mentioned by third parties, but not documented by IBM. ADh: Disable keyboard. AEh: Enable keyboard. AFh–BFh: Ignored. C0h: Read input port. C1h: Continuous input port poll, high nibble. Mentioned by third parties, but not documented by IBM. C2h: Continuous input port poll, low nibble. Mentioned by third parties, but not documented by IBM. C3h–CFh: Ignored. D0h: Read output port. D1h: Write output port. D2h–DEh: Ignored. E0h: Read test inputs. E1h–EFh: Ignored. F0h–FFh: Pulse output bits.