PatchworkOS
Loading...
Searching...
No Matches
ps2.h File Reference
#include <kernel/cpu/port.h>
#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  ps2_device_info_t
 PS/2 device information structure. More...
 

Macros

#define PS2_WAIT_TIMEOUT   (CLOCKS_PER_SEC / 2)
 Wait timeout for PS/2 controller.
 
#define PS2_SMALL_DELAY   (CLOCKS_PER_SEC / 100)
 Small delay for various operations.
 
#define PS2_LARGE_DELAY   (CLOCKS_PER_SEC / 5)
 Large delay for various operations.
 
#define PS2_COMMAND_RETRIES   3
 Number of retries for commands.
 
#define PS2_READ(data)
 Read data from PS/2 controller.
 
#define PS2_WRITE(data)
 Write data to PS/2 controller.
 
#define PS2_CMD(command)
 Send a command to the PS/2 controller without reading response.
 
#define PS2_CMD_AND_READ(command, data)
 Send a command to the PS/2 controller and read response.
 
#define PS2_CMD_AND_WRITE(command, data)
 Send a command to the PS/2 controller and write data.
 
#define PS2_DEV_CMD(device, command)
 Send a command to a PS/2 device without reading response.
 
#define PS2_DEV_CMD_AND_READ(device, command, data)
 Send a command to a PS/2 device and read response.
 
#define PS2_DEV_SUB_CMD(device, command, subCommand)
 Send a command and a subcommand to a PS/2 device.
 

Enumerations

enum  ps2_port_t {
  PS2_PORT_DATA = 0x60 ,
  PS2_PORT_STATUS = 0x64 ,
  PS2_PORT_CMD = 0x64
}
 PS/2 controller I/O ports. More...
 
enum  ps2_cmd_t {
  PS2_CMD_CFG_READ = 0x20 ,
  PS2_CMD_CFG_WRITE = 0x60 ,
  PS2_CMD_SECOND_DISABLE = 0xA7 ,
  PS2_CMD_SECOND_ENABLE = 0xA8 ,
  PS2_CMD_FIRST_DISABLE = 0xAD ,
  PS2_CMD_FIRST_ENABLE = 0xAE ,
  PS2_CMD_SECOND_TEST = 0xA9 ,
  PS2_CMD_SELF_TEST = 0xAA ,
  PS2_CMD_FIRST_TEST = 0xAB ,
  PS2_CMD_DUMP = 0xAC ,
  PS2_CMD_SECOND_WRITE = 0xD4
}
 PS/2 controller commands. More...
 
enum  ps2_status_bits_t {
  PS2_STATUS_OUT_FULL = (1 << 0) ,
  PS2_STATUS_IN_FULL = (1 << 1) ,
  PS2_STATUS_SYSTEM_FLAG = (1 << 2) ,
  PS2_STATUS_CMD_DATA = (1 << 3) ,
  PS2_STATUS_TIMEOUT_ERROR = (1 << 6) ,
  PS2_STATUS_PARITY_ERROR = (1 << 7)
}
 PS/2 controller status register bits. More...
 
enum  ps2_config_bits_t {
  PS2_CFG_FIRST_IRQ = (1 << 0) ,
  PS2_CFG_SECOND_IRQ = (1 << 1) ,
  PS2_CFG_SYSTEM_FLAG = (1 << 2) ,
  PS2_CFG_RESERVED_3 = (1 << 3) ,
  PS2_CFG_FIRST_CLOCK_DISABLE = (1 << 4) ,
  PS2_CFG_SECOND_CLOCK_DISABLE = (1 << 5) ,
  PS2_CFG_FIRST_TRANSLATION = (1 << 6) ,
  PS2_CFG_RESERVED_7 = (1 << 7)
}
 PS/2 controller configuration bits. More...
 
enum  ps2_device_cmd_t {
  PS2_DEV_CMD_ECHO = 0xEE ,
  PS2_DEV_CMD_SET_LEDS = 0xED ,
  PS2_DEV_CMD_SET_SCANCODE_SET = 0xF0 ,
  PS2_DEV_CMD_IDENTIFY = 0xF2 ,
  PS2_DEV_CMD_SET_TYPEMATIC = 0xF3 ,
  PS2_DEV_CMD_ENABLE_SCANNING = 0xF4 ,
  PS2_DEV_CMD_DISABLE_SCANNING = 0xF5 ,
  PS2_DEV_CMD_SET_DEFAULTS = 0xF6 ,
  PS2_DEV_CMD_RESEND = 0xFE ,
  PS2_DEV_CMD_RESET = 0xFF
}
 PS/2 device commands. More...
 
enum  ps2_device_t {
  PS2_DEV_NONE = -1 ,
  PS2_DEV_FIRST = 0 ,
  PS2_DEV_SECOND = 1 ,
  PS2_DEV_COUNT = 2
}
 PS/2 device identifiers. More...
 
enum  ps2_device_type_t {
  PS2_DEV_TYPE_UNKNOWN ,
  PS2_DEV_TYPE_KEYBOARD ,
  PS2_DEV_TYPE_MOUSE_STANDARD ,
  PS2_DEV_TYPE_MOUSE_SCROLL ,
  PS2_DEV_TYPE_MOUSE_5BUTTON
}
 PS/2 device types. More...
 
enum  ps2_self_test_response_t {
  PS2_SELF_TEST_PASS = 0x55 ,
  PS2_SELF_TEST_FAIL = 0xFC
}
 PS/2 controller self-test responses. More...
 
enum  ps2_device_test_response_t {
  PS2_DEV_TEST_PASS = 0x00 ,
  PS2_DEV_TEST_CLOCK_STUCK_LOW = 0x01 ,
  PS2_DEV_TEST_CLOCK_STUCK_HIGH = 0x02 ,
  PS2_DEV_TEST_DATA_STUCK_LOW = 0x03 ,
  PS2_DEV_TEST_DATA_STUCK_HIGH = 0x04
}
 PS/2 device test responses. More...
 
enum  ps2_device_response_t {
  PS2_DEV_RESPONSE_ACK = 0xFA ,
  PS2_DEV_RESPONSE_RESEND = 0xFE ,
  PS2_DEV_RESPONSE_BAT_OK = 0xAA ,
  PS2_DEV_RESPONSE_KBD_EXTENDED = 0xE0 ,
  PS2_DEV_RESPONSE_KBD_RELEASE = 0xF0
}
 PS/2 device command responses. More...
 

Functions

void ps2_init (void)
 Initialize the PS/2 controller.
 
void ps2_drain (void)
 Drain the PS/2 output buffer.
 
uint64_t ps2_wait_until_set (ps2_status_bits_t status)
 Wait until status bit(s) is set.
 
uint64_t ps2_wait_until_clear (ps2_status_bits_t status)
 Wait until status bit(s) is clear.
 
uint64_t ps2_send_cmd (ps2_cmd_t command)
 Send a command to the PS/2 controller.
 
uint64_t ps2_send_device_cmd (ps2_device_t device, ps2_device_cmd_t command)
 Send a command to a PS/2 device.