PatchworkOS  3984a1d
A non-POSIX operating system.
Loading...
Searching...
No Matches
ps2.h File Reference
#include <kernel/cpu/io.h>
#include <kernel/cpu/irq.h>
#include <stdbool.h>
#include <stdint.h>
Include dependency graph for ps2.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ps2_known_device_t
 Known PS/2 device structure. More...
 
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   10
 Number of retries for commands.
 
#define PS2_KEYBOARD_PNP_IDS
 All known PS/2 keyboard PNP IDs.
 
#define PS2_MOUSE_PNP_IDS
 All known PS/2 mouse PNP IDs.
 

Enumerations

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_NONE , 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_drain (void)
 Drain the PS/2 output buffer.
 
uint64_t ps2_wait_until_set (ps2_status_bits_t status)
 Wait until status bit(s) are set.
 
uint64_t ps2_wait_until_clear (ps2_status_bits_t status)
 Wait until status bit(s) are clear.
 
uint64_t ps2_read (void)
 Read from the PS/2 controllers data port.
 
uint64_t ps2_read_no_wait (void)
 Read from the PS/2 controllers data port without waiting.
 
uint64_t ps2_write (uint8_t data)
 Write to the PS/2 controllers data port.
 
uint64_t ps2_cmd (ps2_cmd_t command)
 Send a command to the PS/2 controller without reading response.
 
uint64_t ps2_cmd_and_read (ps2_cmd_t command)
 Send a command to the PS/2 controller and read response.
 
uint64_t ps2_cmd_and_write (ps2_cmd_t command, uint8_t data)
 Send a command to the PS/2 controller and write data.
 
uint64_t ps2_device_cmd (ps2_device_t device, ps2_device_cmd_t command)
 Send a command to a PS/2 device without reading response.
 
uint64_t ps2_device_cmd_and_read (ps2_device_t device, ps2_device_cmd_t command)
 Send a command to a PS/2 device and read response.
 
uint64_t ps2_device_sub_cmd (ps2_device_t device, ps2_device_cmd_t command, uint8_t subCommand)
 Send a command and a subcommand to a PS/2 device.