aboutsummaryrefslogtreecommitdiff
path: root/devices/ps2_ctrl_8042.c
diff options
context:
space:
mode:
Diffstat (limited to 'devices/ps2_ctrl_8042.c')
-rw-r--r--devices/ps2_ctrl_8042.c43
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);
+}