grml...
[seabios.git] / src / kbd.c
index 461d1b77dacb40d354f90ce66aefa08ee47cb06e..1977c5d018c72ff87da3a8e90882090d97a3b356 100644 (file)
--- a/src/kbd.c
+++ b/src/kbd.c
@@ -8,9 +8,9 @@
 #include "biosvar.h" // GET_BDA
 #include "util.h" // debug_enter
 #include "config.h" // CONFIG_*
-#include "pic.h" // eoi_pic1
 #include "bregs.h" // struct bregs
-#include "ps2port.h" // i8042_flush
+#include "ps2port.h" // ps2_kbd_command
+#include "usb-hid.h" // usb_kbd_command
 
 // Bit definitions for BDA kbd_flag[012]
 #define KF0_RSHIFT       (1<<0)
 #define KF2_RALT       (1<<3)
 #define KF2_101KBD     (1<<4)
 
-static void
-keyboard_init()
-{
-    /* flush incoming keys */
-    int ret = i8042_flush();
-    if (ret)
-        return;
-
-    // Controller self-test.
-    u8 param[2];
-    ret = i8042_command(I8042_CMD_CTL_TEST, param);
-    if (ret)
-        return;
-    if (param[0] != 0x55) {
-        dprintf(1, "i8042 self test failed (got %x not 0x55)\n", param[0]);
-        return;
-    }
-
-    // Controller keyboard test.
-    ret = i8042_command(I8042_CMD_KBD_TEST, param);
-    if (ret)
-        return;
-    if (param[0] != 0x00) {
-        dprintf(1, "i8042 keyboard test failed (got %x not 0x00)\n", param[0]);
-        return;
-    }
-
-    // Enable keyboard and mouse ports.
-    ret = i8042_command(I8042_CMD_KBD_ENABLE, NULL);
-    if (ret)
-        return;
-    ret = i8042_command(I8042_CMD_AUX_ENABLE, NULL);
-    if (ret)
-        return;
-
-
-    /* ------------------- keyboard side ------------------------*/
-    /* reset keyboard and self test  (keyboard side) */
-    ret = kbd_command(ATKBD_CMD_RESET_BAT, param);
-    if (ret)
-        return;
-    if (param[0] != 0xaa) {
-        dprintf(1, "keyboard self test failed (got %x not 0xaa)\n", param[0]);
-        return;
-    }
-
-    /* Disable keyboard */
-    ret = kbd_command(ATKBD_CMD_RESET_DIS, NULL);
-    if (ret)
-        return;
-
-    // Set scancode command (mode 2)
-    param[0] = 0x02;
-    ret = kbd_command(ATKBD_CMD_SSCANSET, param);
-    if (ret)
-        return;
-
-    // Keyboard Mode: scan code convert, disable mouse, enable IRQ 1
-    SET_EBDA(ps2ctr, I8042_CTR_AUXDIS | I8042_CTR_XLATE | I8042_CTR_KBDINT);
-
-    /* Enable keyboard */
-    ret = kbd_command(ATKBD_CMD_ENABLE, NULL);
-    if (ret)
-        return;
-
-    dprintf(1, "keyboard initialized\n");
-}
-
 void
-kbd_setup()
+kbd_setup(void)
 {
     dprintf(3, "init keyboard\n");
     u16 x = offsetof(struct bios_data_area_s, kbd_buf);
@@ -114,13 +46,6 @@ kbd_setup()
 
     SET_BDA(kbd_buf_end_offset
             , x + FIELD_SIZEOF(struct bios_data_area_s, kbd_buf));
-
-    if (! CONFIG_KEYBOARD)
-        return;
-
-    run_thread(keyboard_init, NULL);
-
-    enable_hwirq(1, entry_09);
 }
 
 static u8
@@ -149,6 +74,7 @@ enqueue_key(u8 scan_code, u8 ascii_code)
 static void
 dequeue_key(struct bregs *regs, int incr, int extended)
 {
+    yield();
     u16 buffer_head;
     u16 buffer_tail;
     for (;;) {
@@ -184,6 +110,14 @@ dequeue_key(struct bregs *regs, int incr, int extended)
     SET_BDA(kbd_buf_head, buffer_head);
 }
 
+static inline int
+kbd_command(int command, u8 *param)
+{
+    if (usb_kbd_active())
+        return usb_kbd_command(command, param);
+    return ps2_kbd_command(command, param);
+}
+
 // read keyboard input
 static void
 handle_1600(struct bregs *regs)
@@ -202,6 +136,7 @@ handle_1601(struct bregs *regs)
 static void
 handle_1602(struct bregs *regs)
 {
+    yield();
     regs->al = GET_BDA(kbd_flag0);
 }
 
@@ -260,6 +195,7 @@ handle_1611(struct bregs *regs)
 static void
 handle_1612(struct bregs *regs)
 {
+    yield();
     regs->al = GET_BDA(kbd_flag0);
     regs->ah = ((GET_BDA(kbd_flag1) & ~(KF2_RCTRL|KF2_RALT))
                 | (GET_BDA(kbd_flag2) & (KF2_RCTRL|KF2_RALT)));
@@ -292,11 +228,11 @@ handle_16a2(struct bregs *regs)
 static void
 handle_16XX(struct bregs *regs)
 {
-    debug_stub(regs);
+    warn_unimplemented(regs);
 }
 
 static void
-set_leds()
+set_leds(void)
 {
     u8 shift_flags = (GET_BDA(kbd_flag0) >> 4) & 0x07;
     u8 kbd_led = GET_BDA(kbd_led);
@@ -621,6 +557,9 @@ __process_key(u8 scancode)
 void
 process_key(u8 key)
 {
+    if (!CONFIG_KEYBOARD)
+        return;
+
     if (CONFIG_KBD_CALL_INT15_4F) {
         // allow for keyboard intercept
         u32 eax = (0x4f << 8) | key;
@@ -632,25 +571,3 @@ process_key(u8 key)
     }
     __process_key(key);
 }
-
-// INT09h : Keyboard Hardware Service Entry Point
-void VISIBLE16
-handle_09()
-{
-    debug_isr(DEBUG_ISR_09);
-    if (! CONFIG_KEYBOARD)
-        goto done;
-
-    // read key from keyboard controller
-    u8 v = inb(PORT_PS2_STATUS);
-    if ((v & (I8042_STR_OBF|I8042_STR_AUXDATA)) != I8042_STR_OBF) {
-        dprintf(1, "keyboard irq but no keyboard data.\n");
-        goto done;
-    }
-    v = inb(PORT_PS2_DATA);
-
-    process_key(v);
-
-done:
-    eoi_pic1();
-}