aboutsummaryrefslogtreecommitdiff
path: root/kernel/drivers/ps2
diff options
context:
space:
mode:
authorMarvin Borner2021-04-14 14:34:38 +0200
committerMarvin Borner2021-04-14 14:34:38 +0200
commit462eaa9531b9e62916b02ab52759cd070de755d3 (patch)
tree71bb32daa5f8b4389c9d4ce1e42d66600090485f /kernel/drivers/ps2
parent212582f69dea4c99c292081b15ea526014b9ad44 (diff)
Implemented some I/O interfaces
Diffstat (limited to 'kernel/drivers/ps2')
-rw-r--r--kernel/drivers/ps2/keyboard.c19
-rw-r--r--kernel/drivers/ps2/mouse.c119
-rw-r--r--kernel/drivers/ps2/ps2.c71
3 files changed, 67 insertions, 142 deletions
diff --git a/kernel/drivers/ps2/keyboard.c b/kernel/drivers/ps2/keyboard.c
index 9a19b5c..3c2cdbb 100644
--- a/kernel/drivers/ps2/keyboard.c
+++ b/kernel/drivers/ps2/keyboard.c
@@ -3,8 +3,8 @@
#include <cpu.h>
#include <def.h>
#include <errno.h>
-#include <fs.h>
#include <interrupts.h>
+#include <io.h>
#include <mem.h>
#include <print.h>
#include <proc.h>
@@ -14,7 +14,6 @@
#include <sys.h>
PROTECTED static struct stack *queue = NULL;
-PROTECTED static u32 dev_id = 0;
static struct event_keyboard *event = NULL;
static int state = 0;
@@ -46,9 +45,8 @@ static void keyboard_handler(struct regs *r)
merged = 0;
}
-static res keyboard_read(void *buf, u32 offset, u32 count, struct vfs_dev *dev)
+static res keyboard_read(void *buf, u32 offset, u32 count)
{
- UNUSED(dev);
if (stack_empty(queue))
return -EINVAL;
@@ -68,16 +66,15 @@ CLEAR void ps2_keyboard_reset(void)
stack_clear(queue);
}
-CLEAR void ps2_keyboard_install(void)
+CLEAR void ps2_keyboard_install(u8 device)
{
- //keyboard_rate(); TODO: Fix keyboard rate?
+ UNUSED(device);
+
irq_install_handler(1, keyboard_handler);
queue = stack_new();
- struct vfs_dev *dev = zalloc(sizeof(*dev));
- dev->name = strdup("kbd");
- dev->type = DEV_CHAR;
+ struct io_dev *dev = zalloc(sizeof(*dev));
dev->read = keyboard_read;
- /* device_add(dev); */
- dev_id = dev->id;
+ dev->ready = keyboard_ready;
+ io_add(IO_KEYBOARD, dev);
}
diff --git a/kernel/drivers/ps2/mouse.c b/kernel/drivers/ps2/mouse.c
index 9b3fa2e..1d3c1ae 100644
--- a/kernel/drivers/ps2/mouse.c
+++ b/kernel/drivers/ps2/mouse.c
@@ -3,8 +3,8 @@
#include <boot.h>
#include <cpu.h>
#include <errno.h>
-#include <fs.h>
#include <interrupts.h>
+#include <io.h>
#include <mem.h>
#include <print.h>
#include <proc.h>
@@ -14,7 +14,6 @@
#include <sys.h>
PROTECTED static struct stack *queue = NULL;
-PROTECTED static u32 dev_id = 0;
static struct event_mouse *event = NULL;
static char mouse_cycle = 0;
@@ -52,46 +51,13 @@ static void mouse_handler(struct regs *r)
}
}
-#define MOUSE_WAIT_OUT 0
-#define MOUSE_WAIT_IN 1
-CLEAR static void mouse_serial_wait(u8 in)
-{
- u32 time_out = 100000;
- if (in) {
- while (time_out--)
- if (ps2_read_status().in_full)
- return;
- return;
- } else {
- while (time_out--)
- if (ps2_read_status().out_full)
- return;
- return;
- }
-}
-
-CLEAR static void mouse_serial_write(u8 data)
-{
- mouse_serial_wait(MOUSE_WAIT_IN);
- ps2_write_command(0xd4);
- mouse_serial_wait(MOUSE_WAIT_IN);
- ps2_write_data(data);
-}
-
-CLEAR static u8 mouse_serial_read(void)
-{
- mouse_serial_wait(MOUSE_WAIT_OUT);
- return ps2_read_data();
-}
-
static res mouse_ready(void)
{
return !stack_empty(queue);
}
-static res mouse_read(void *buf, u32 offset, u32 count, struct vfs_dev *dev)
+static res mouse_read(void *buf, u32 offset, u32 count)
{
- (void)dev;
if (stack_empty(queue))
return -EINVAL;
@@ -101,96 +67,33 @@ static res mouse_read(void *buf, u32 offset, u32 count, struct vfs_dev *dev)
return MIN(count, sizeof(*e));
}
-CLEAR void ps2_mouse_install(void)
+CLEAR void ps2_mouse_install(u8 device)
{
u8 status;
// Enable auxiliary mouse device
- mouse_serial_wait(MOUSE_WAIT_IN);
- ps2_write_command(0xa8);
+ ps2_write_device(device, 0xa8);
// Enable interrupts
- mouse_serial_wait(MOUSE_WAIT_IN);
ps2_write_command(0x20);
- mouse_serial_wait(MOUSE_WAIT_OUT);
status = ps2_read_data() | 3;
- mouse_serial_wait(MOUSE_WAIT_IN);
ps2_write_command(0x60);
- mouse_serial_wait(MOUSE_WAIT_IN);
ps2_write_data(status);
// Use default settings
- mouse_serial_write(0xf6);
- mouse_serial_read();
-
- // Enable mousewheel
- mouse_serial_write(0xf2);
- mouse_serial_read();
- mouse_serial_read();
- mouse_serial_write(0xf3);
- mouse_serial_read();
- mouse_serial_write(200);
- mouse_serial_read();
- mouse_serial_write(0xf3);
- mouse_serial_read();
- mouse_serial_write(100);
- mouse_serial_read();
- mouse_serial_write(0xf3);
- mouse_serial_read();
- mouse_serial_write(80);
- mouse_serial_read();
- mouse_serial_write(0xf2);
- mouse_serial_read();
- status = (u8)mouse_serial_read();
- if (status == 3) {
- }
- /* printf("Scrollwheel support!\n"); */
-
- // Activate 4th and 5th mouse buttons
- mouse_serial_write(0xf2);
- mouse_serial_read();
- mouse_serial_read();
- mouse_serial_write(0xf3);
- mouse_serial_read();
- mouse_serial_write(200);
- mouse_serial_read();
- mouse_serial_write(0xf3);
- mouse_serial_read();
- mouse_serial_write(200);
- mouse_serial_read();
- mouse_serial_write(0xf3);
- mouse_serial_read();
- mouse_serial_write(80);
- mouse_serial_read();
- mouse_serial_write(0xf2);
- mouse_serial_read();
- status = (u8)mouse_serial_read();
- if (status == 4) {
- }
- /* printf("4th and 5th mouse button support!\n"); */
-
- /* TODO: Fix mouse laggyness
- mouse_serial_write(0xE8);
- mouse_serial_read();
- mouse_serial_write(0x03);
- mouse_serial_read();
- mouse_serial_write(0xF3);
- mouse_serial_read();
- mouse_serial_write(200);
- mouse_serial_read(); */
+ ps2_write_device(device, 0xf6);
+ ps2_read_data();
// Enable mouse
- mouse_serial_write(0xf4);
- mouse_serial_read();
+ ps2_write_device(device, 0xf4);
+ ps2_read_data();
// Setup the mouse handler
irq_install_handler(12, mouse_handler);
queue = stack_new();
- struct vfs_dev *dev = zalloc(sizeof(*dev));
- dev->name = strdup("mouse");
- dev->type = DEV_CHAR;
+ struct io_dev *dev = zalloc(sizeof(*dev));
dev->read = mouse_read;
- /* device_add(dev); */
- dev_id = dev->id;
+ dev->ready = mouse_ready;
+ io_add(IO_MOUSE, dev);
}
diff --git a/kernel/drivers/ps2/ps2.c b/kernel/drivers/ps2/ps2.c
index 1c73855..7045fbe 100644
--- a/kernel/drivers/ps2/ps2.c
+++ b/kernel/drivers/ps2/ps2.c
@@ -86,6 +86,13 @@ CLEAR static u8 ps2_write_config(struct ps2_config config)
#define PS2_TYPE_TRANSLATION_KEYBOARD2 0xabc1
#define PS2_TYPE_STANDARD_KEYBOARD 0xab83
+#define PS2_KEYBOARD(type) \
+ ((type) == PS2_TYPE_TRANSLATION_KEYBOARD1 || (type) == PS2_TYPE_TRANSLATION_KEYBOARD2 || \
+ (type) == PS2_TYPE_STANDARD_KEYBOARD)
+#define PS2_MOUSE(type) \
+ ((type) == PS2_TYPE_STANDARD_MOUSE || (type) == PS2_TYPE_WHEEL_MOUSE || \
+ (type) == PS2_TYPE_BUTTON_MOUSE)
+
PROTECTED static struct {
u8 detected : 1;
struct {
@@ -98,7 +105,7 @@ PROTECTED static struct {
} second;
} info = { 0 };
-CLEAR static u8 ps2_write_device(u8 device, u8 data)
+CLEAR u8 ps2_write_device(u8 device, u8 data)
{
u8 resp = PS2_RESEND;
for (u8 i = 0; resp == PS2_RESEND && i < 3; i++) {
@@ -114,44 +121,62 @@ CLEAR static u8 ps2_write_device(u8 device, u8 data)
return 1;
}
-CLEAR static u8 ps2_device_keyboard(u16 type)
+CLEAR static u8 ps2_device_keyboard(void)
{
- return type == PS2_TYPE_TRANSLATION_KEYBOARD1 || type == PS2_TYPE_TRANSLATION_KEYBOARD2 ||
- type == PS2_TYPE_STANDARD_KEYBOARD;
+ if (!info.detected)
+ return U8_MAX;
+
+ if (info.first.exists && PS2_KEYBOARD(info.first.type))
+ return 0;
+ else if (info.second.exists && PS2_KEYBOARD(info.second.type))
+ return 1;
+
+ return U8_MAX;
}
-CLEAR static u8 ps2_device_mouse(u16 type)
+CLEAR static u8 ps2_device_mouse(void)
{
- return type == PS2_TYPE_STANDARD_MOUSE || type == PS2_TYPE_WHEEL_MOUSE ||
- type == PS2_TYPE_BUTTON_MOUSE;
+ if (!info.detected)
+ return U8_MAX;
+
+ if (info.first.exists && PS2_MOUSE(info.first.type))
+ return 0;
+ else if (info.second.exists && PS2_MOUSE(info.second.type))
+ return 1;
+
+ return U8_MAX;
}
-CLEAR u8 ps2_keyboard_support(void)
+CLEAR u8 ps2_keyboard_detect(void)
{
if (!info.detected)
- return 0;
+ return U8_MAX;
- // Find, reset and self-test
- if ((info.first.exists && ps2_device_keyboard(info.first.type) &&
- ps2_write_device(0, 0xff)) ||
- (info.second.exists && ps2_device_keyboard(info.second.type) &&
- ps2_write_device(1, 0xff)))
- return ps2_read_data() == 0xaa;
+ u8 device = ps2_device_keyboard();
+ if (device == U8_MAX)
+ return device;
- return 0;
+ ps2_write_device(device, 0xff);
+ if (ps2_read_data() == 0xaa)
+ return device;
+
+ return U8_MAX;
}
-CLEAR u8 ps2_mouse_support(void)
+CLEAR u8 ps2_mouse_detect(void)
{
if (!info.detected)
- return 0;
+ return U8_MAX;
- // Find, reset and self-test
- if ((info.first.exists && ps2_device_mouse(info.first.type) && ps2_write_device(0, 0xff)) ||
- (info.second.exists && ps2_device_mouse(info.second.type) && ps2_write_device(1, 0xff)))
- return ps2_read_data() == 0xaa;
+ u8 device = ps2_device_mouse();
+ if (device == U8_MAX)
+ return device;
- return 0;
+ ps2_write_device(device, 0xff);
+ if (ps2_read_data() == 0xaa)
+ return device;
+
+ return U8_MAX;
}
CLEAR void ps2_detect(void)