vgabios: Unify X_set_mode() functions.
[seabios.git] / src / mouse.c
index cc6c4d20e12652f49e7a2c4e6e11d54513d4f78a..e26cf694ca5bcc37791d533c564071f1ee863efd 100644 (file)
@@ -10,6 +10,7 @@
 #include "pic.h" // eoi_pic2
 #include "bregs.h" // struct bregs
 #include "ps2port.h" // ps2_mouse_command
+#include "usb-hid.h" // usb_mouse_command
 
 void
 mouse_setup(void)
@@ -24,6 +25,8 @@ mouse_setup(void)
 static inline int
 mouse_command(int command, u8 *param)
 {
+    if (usb_mouse_active())
+        return usb_mouse_command(command, param);
     return ps2_mouse_command(command, param);
 }
 
@@ -34,23 +37,11 @@ mouse_command(int command, u8 *param)
 #define RET_ENEEDRESEND  0x04
 #define RET_ENOHANDLER   0x05
 
-static int
-disable_mouse(u16 ebda_seg)
-{
-    u8 ps2ctr = GET_EBDA2(ebda_seg, ps2ctr);
-    ps2ctr |= I8042_CTR_AUXDIS;
-    ps2ctr &= ~I8042_CTR_AUXINT;
-    SET_EBDA2(ebda_seg, ps2ctr, ps2ctr);
-
-    return mouse_command(PSMOUSE_CMD_DISABLE, NULL);
-}
-
 // Disable Mouse
 static void
 mouse_15c20000(struct bregs *regs)
 {
-    u16 ebda_seg = get_ebda_seg();
-    int ret = disable_mouse(ebda_seg);
+    int ret = mouse_command(PSMOUSE_CMD_DISABLE, NULL);
     if (ret)
         set_code_invalid(regs, RET_ENEEDRESEND);
     else
@@ -61,18 +52,12 @@ mouse_15c20000(struct bregs *regs)
 static void
 mouse_15c20001(struct bregs *regs)
 {
-    u16 ebda_seg = get_ebda_seg();
-    u8 mouse_flags_2 = GET_EBDA2(ebda_seg, mouse_flag2);
+    u8 mouse_flags_2 = GET_EBDA(mouse_flag2);
     if ((mouse_flags_2 & 0x80) == 0) {
         set_code_invalid(regs, RET_ENOHANDLER);
         return;
     }
 
-    u8 ps2ctr = GET_EBDA2(ebda_seg, ps2ctr);
-    ps2ctr &= ~I8042_CTR_AUXDIS;
-    ps2ctr |= I8042_CTR_AUXINT;
-    SET_EBDA2(ebda_seg, ps2ctr, ps2ctr);
-
     int ret = mouse_command(PSMOUSE_CMD_ENABLE, NULL);
     if (ret)
         set_code_invalid(regs, RET_ENEEDRESEND);
@@ -247,7 +232,7 @@ mouse_15c207(struct bregs *regs)
         /* remove handler */
         if ((mouse_flags_2 & 0x80) != 0) {
             mouse_flags_2 &= ~0x80;
-            disable_mouse(ebda_seg);
+            mouse_command(PSMOUSE_CMD_DISABLE, NULL);
         }
     } else {
         /* install handler */