diff options
author | aqua <aqua@iserlohn-fortress.net> | 2022-11-02 09:34:31 +0200 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2022-11-02 09:34:31 +0200 |
commit | ccaf2737f82968816c5ec962f936a593686cfb72 (patch) | |
tree | 6aa87c45c05e147c56fc4f330780386a608c33c7 /devices/ps2_ctrl_8042.c | |
parent | Enable interrupts after enabling the PIC (diff) | |
download | kernel-ccaf2737f82968816c5ec962f936a593686cfb72.tar.xz |
Add ps2_ctrl_8042
Diffstat (limited to 'devices/ps2_ctrl_8042.c')
-rw-r--r-- | devices/ps2_ctrl_8042.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/devices/ps2_ctrl_8042.c b/devices/ps2_ctrl_8042.c new file mode 100644 index 0000000..4157bd8 --- /dev/null +++ b/devices/ps2_ctrl_8042.c @@ -0,0 +1,43 @@ +#include "ps2_ctrl.h" +#include <stdint.h> +#include <stdio.h> +#include <sys/io.h> + +const uint8_t comm_port = 0x64; // r status register + // w command register +const uint8_t comm_enable_first_ps2 = 0xae; +const uint8_t comm_read_ctrl_config = 0x20; +const uint8_t comm_write_ctrl_config = 0x60; + +const uint8_t data_port = 0x60; // rw +const uint8_t data_enable_scanning = 0xf4; + +void +ps2_ctrl_init() +{ + // eat all previous keystrikes + while (inb(comm_port) & 0x1) inb(data_port); + + outb(0x64, 0xaa); + printf("8042: self test 0xaa: %x\n", inb(0x60)); + outb(0x64, 0xab); + printf("8042: port1 test 0xab: %x\n", inb(0x60)); + outb(0x64, 0xa9); + printf("8042: port2 test 0xa9: %x\n", inb(0x60)); + + // printf("8042: init keyboard\n"); + + outb(comm_port, comm_enable_first_ps2); + outb(comm_port, comm_read_ctrl_config); + const uint8_t conf = (inb(data_port) | 1) & ~0x10; + outb(comm_port, comm_write_ctrl_config); + outb(data_port, conf); + outb(data_port, data_enable_scanning); + +} + +unsigned char +ps2_ctrl_read() +{ + return inb(0x60); +} |