2#include <kernel/drivers/ps2/ps2.h>
3#include <kernel/drivers/ps2/ps2_kbd.h>
4#include <kernel/drivers/ps2/ps2_mouse.h>
28#define PS2_KNOWN_DEVICE_AMOUNT (sizeof(knownDevices) / sizeof(knownDevices[0]))
37 return "clock stuck low";
39 return "clock stuck high";
41 return "data stuck low";
43 return "data stuck high";
45 return "invalid response";
58 return "invalid response";
71 return "invalid device";
84 return "mouse standard";
86 return "mouse scroll";
88 return "mouse 5button";
90 return "invalid device type";
98 LOG_ERR(
"ps2 failed to read initial config\n");
102 LOG_DEBUG(
"ps2 initial config byte: 0x%02x\n", *cfg);
104 LOG_DEBUG(
"ps2 setting config byte to: 0x%02x\n", *cfg);
108 LOG_ERR(
"ps2 failed to write initial config\n");
120 LOG_ERR(
"ps2 failed to read config byte.\n");
127 LOG_ERR(
"ps2 failed to send self test command\n");
139 LOG_ERR(
"ps2 failed to write config byte.\n");
151 LOG_ERR(
"ps2 failed to read config for dual channel check\n");
159 LOG_ERR(
"ps2 failed to send second port enable command\n");
165 LOG_ERR(
"ps2 failed to read config after second port enable\n");
172 LOG_INFO(
"dual channel PS/2 controller detected\n");
176 LOG_ERR(
"ps2 failed to disable second port after detection\n");
183 LOG_INFO(
"single channel PS/2 controller detected\n");
189 LOG_INFO(
"single channel PS/2 controller detected (second port clock not disabled)\n");
229 info->device = device;
270 info->firstIdByte = 0xFF;
330 panic(
NULL,
"ps2 not supported by hardware (ACPI FADT indicates no PS/2 controller)");
332 LOG_INFO(
"ps2 controller detected via FADT\n");
336 panic(
NULL,
"ps2 first device disable failed");
340 panic(
NULL,
"ps2 second device disable failed");
347 panic(
NULL,
"ps2 initial configuration failed");
351 panic(
NULL,
"ps2 controller self test failed");
355 panic(
NULL,
"ps2 dual channel detection failed");
368 panic(
NULL,
"ps2 first device initialization failed");
382 panic(
NULL,
"ps2 second device initialization failed");
394 panic(
NULL,
"ps2 failed to write config byte");
401 panic(
NULL,
"ps2 first device enable failed");
409 panic(
NULL,
"ps2 second device enable failed");
434 asm volatile(
"pause");
449 asm volatile(
"pause");
#define FADT_GET()
Type safe way to get the FADT table.
@ FADT_BOOT_ARCH_PS2_EXISTS
static uint8_t port_inb(uint16_t port)
static void port_outb(uint16_t port, uint8_t val)
void hpet_wait(clock_t nanoseconds)
Wait for a specified number of nanoseconds using the HPET.
uint64_t ps2_kbd_init(ps2_device_info_t *info)
Initialize a PS/2 keyboard device.
uint64_t ps2_mouse_init(ps2_device_info_t *info)
Initialize a PS/2 mouse device.
ps2_device_t
PS/2 device identifiers.
#define PS2_CMD(command)
Send a command to the PS/2 controller without reading response.
ps2_status_bits_t
PS/2 controller status register bits.
#define PS2_COMMAND_RETRIES
Number of retries for commands.
#define PS2_CMD_AND_WRITE(command, data)
Send a command to the PS/2 controller and write data.
ps2_device_test_response_t
PS/2 device test responses.
ps2_cmd_t
PS/2 controller commands.
#define PS2_WAIT_TIMEOUT
Wait timeout for PS/2 controller.
ps2_config_bits_t
PS/2 controller configuration bits.
uint64_t ps2_wait_until_set(ps2_status_bits_t status)
Wait until status bit(s) is set.
uint64_t ps2_send_device_cmd(ps2_device_t device, ps2_device_cmd_t command)
Send a command to a PS/2 device.
#define PS2_LARGE_DELAY
Large delay for various operations.
#define PS2_DEV_CMD_AND_READ(device, command, data)
Send a command to a PS/2 device and read response.
#define PS2_WRITE(data)
Write data to PS/2 controller.
ps2_self_test_response_t
PS/2 controller self-test responses.
ps2_device_type_t
PS/2 device types.
uint64_t ps2_send_cmd(ps2_cmd_t command)
Send a command to the PS/2 controller.
void ps2_drain(void)
Drain the PS/2 output buffer.
#define PS2_DEV_CMD(device, command)
Send a command to a PS/2 device without reading response.
#define PS2_SMALL_DELAY
Small delay for various operations.
#define PS2_READ(data)
Read data from PS/2 controller.
#define PS2_CMD_AND_READ(command, data)
Send a command to the PS/2 controller and read response.
uint64_t ps2_wait_until_clear(ps2_status_bits_t status)
Wait until status bit(s) is clear.
ps2_device_cmd_t
PS/2 device commands.
ps2_device_response_t
PS/2 device command responses.
void ps2_init(void)
Initialize the PS/2 controller.
@ PS2_DEV_COUNT
Total number of ports.
@ PS2_DEV_SECOND
Second PS/2 port.
@ PS2_DEV_FIRST
First PS/2 port.
@ PS2_STATUS_IN_FULL
Input buffer status (0 = empty, 1 = full)
@ PS2_STATUS_OUT_FULL
Output buffer status (0 = empty, 1 = full)
@ PS2_DEV_TEST_DATA_STUCK_LOW
@ PS2_DEV_TEST_DATA_STUCK_HIGH
@ PS2_DEV_TEST_CLOCK_STUCK_HIGH
@ PS2_DEV_TEST_CLOCK_STUCK_LOW
@ PS2_CFG_SECOND_IRQ
Second PS/2 port interrupt enable.
@ PS2_CFG_FIRST_IRQ
First PS/2 port interrupt enable.
@ PS2_CFG_SECOND_CLOCK_DISABLE
Second PS/2 port clock disable.
@ PS2_CFG_FIRST_CLOCK_DISABLE
First PS/2 port clock disable.
@ PS2_CFG_FIRST_TRANSLATION
First PS/2 port translation enable.
@ PS2_DEV_TYPE_MOUSE_5BUTTON
@ PS2_DEV_TYPE_MOUSE_STANDARD
@ PS2_DEV_TYPE_MOUSE_SCROLL
@ PS2_DEV_CMD_DISABLE_SCANNING
@ PS2_DEV_CMD_ENABLE_SCANNING
@ PS2_DEV_RESPONSE_RESEND
@ PS2_DEV_RESPONSE_BAT_OK
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
#define LOG_ERR(format,...)
#define LOG_WARN(format,...)
#define LOG_INFO(format,...)
#define LOG_DEBUG(format,...)
clock_t timer_uptime(void)
Time since boot.
#define ETIMEDOUT
Connection timed out.
#define errno
Error number variable.
#define NULL
Pointer error value.
#define ERR
Integer error value.
static bool isDualChannel
static const ps2_device_info_t knownDevices[]
static uint64_t ps2_device_init(ps2_device_t device)
static const char * ps2_device_type_to_string(ps2_device_type_t type)
static uint64_t ps2_self_test(void)
static const char * ps2_self_test_response_to_string(ps2_self_test_response_t response)
static uint64_t ps2_check_if_dual_channel(void)
#define PS2_KNOWN_DEVICE_AMOUNT
static uint64_t ps2_devices_test(void)
static const char * ps2_device_test_response_to_string(ps2_device_test_response_t response)
static const char * ps2_device_to_string(ps2_device_t device)
static ps2_device_info_t devices[PS2_DEV_COUNT]
static uint64_t ps2_set_initial_config(ps2_config_bits_t *cfg)
Fixed ACPI Description Table.
PS/2 device information structure.