Cleanup keyboard reset handling.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 18 Jan 2009 04:30:01 +0000 (23:30 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 18 Jan 2009 04:30:01 +0000 (23:30 -0500)
Use custom timeouts when issuing a reset.
Handle 1-byte returns from reset in ps2 code.
Do full keyboard reset even in coreboot mode.
Send set scan mode command during reset.

src/kbd.c
src/mouse.c
src/ps2port.c
src/ps2port.h

index e976350bf09c71d3dde1edc5dceaf4a03f30e4cb..04f3ff3cf45c074651a9b0e5677163608adaaa47 100644 (file)
--- a/src/kbd.c
+++ b/src/kbd.c
 static void
 keyboard_init()
 {
-    if (CONFIG_COREBOOT)
-        // Coreboot already does low-level keyboard init.
-        goto end;
-
     /* flush incoming keys */
     int ret = i8042_flush();
     if (ret)
@@ -55,7 +51,7 @@ keyboard_init()
     /* ------------------- keyboard side ------------------------*/
     /* reset keyboard and self test  (keyboard side) */
     ret = kbd_command(ATKBD_CMD_RESET_BAT, param);
-    if (ret != 0 && ret != 2)
+    if (ret)
         return;
     if (param[0] != 0xaa) {
         dprintf(1, "keyboard self test failed (got %x not 0xaa)\n", param[0]);
@@ -67,7 +63,12 @@ keyboard_init()
     if (ret)
         return;
 
-end:
+    // 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);
 
index 19fc6ecacb6965c607a5816822b45364e4cba895..2f997c1f342c4ce5c70980e3a248d62e24a4f1b3 100644 (file)
@@ -98,7 +98,7 @@ mouse_15c201(struct bregs *regs)
 {
     u8 param[2];
     int ret = aux_command(PSMOUSE_CMD_RESET_BAT, param);
-    if (ret != 0 && ret != 2) {
+    if (ret) {
         set_code_fail(regs, RET_ENEEDRESEND);
         return;
     }
index 043d581fe2e275e217682fa4b40e36f7c8e7adf0..fc88280c62c4dccd60144c041c5feda34dca7ea3 100644 (file)
@@ -187,7 +187,8 @@ ps2_sendbyte(int aux, u8 command)
         return ret;
 
     // Read ack.
-    ret = ps2_recvbyte(aux, 1, 200);
+    int timeout = command == ATKBD_CMD_RESET_BAT ? 1000 : 200;
+    ret = ps2_recvbyte(aux, 1, timeout);
     if (ret < 0)
         return ret;
 
@@ -229,11 +230,22 @@ ps2_command(int aux, int command, u8 *param)
 
     // Receive parameters (if any).
     for (i = 0; i < receive; i++) {
-        int data = ps2_recvbyte(aux, 0, 200);
+        int timeout = 500;
+        if (command == ATKBD_CMD_RESET_BAT) {
+            // Reset is special wrt timeouts.
+            if (i==0)
+                timeout = 4000;
+            else
+                timeout = 100;
+        }
+        int data = ps2_recvbyte(aux, 0, timeout);
         if (data < 0) {
-            // On a receive timeout, return the item number that the
-            // transfer failed on.
-            ret = i + 1;
+            if (command == ATKBD_CMD_RESET_BAT && i==1) {
+                // Some devices only respond with one byte on reset.
+                param[i] = 0;
+                break;
+            }
+            ret = -1;
             goto fail;
         }
         param[i] = data;
@@ -254,7 +266,7 @@ kbd_command(int command, u8 *param)
     dprintf(7, "kbd_command cmd=%x\n", command);
     int ret = ps2_command(0, command, param);
     if (ret)
-        dprintf(2, "keyboard command %x failed (ret=%d)\n", command, ret);
+        dprintf(2, "keyboard command %x failed\n", command);
     return ret;
 }
 
@@ -264,6 +276,6 @@ aux_command(int command, u8 *param)
     dprintf(7, "aux_command cmd=%x\n", command);
     int ret = ps2_command(1, command, param);
     if (ret)
-        dprintf(2, "mouse command %x failed (ret=%d)\n", command, ret);
+        dprintf(2, "mouse command %x failed\n", command);
     return ret;
 }
index a0b7a6510a6c1bc3b7418a75980414b982028b08..3c4e4d45a4092ac7aef105e3e7f16686d8450e5c 100644 (file)
@@ -19,6 +19,7 @@
 
 // Keyboard commands
 #define ATKBD_CMD_SETLEDS       0x10ed
+#define ATKBD_CMD_SSCANSET      0x10f0
 #define ATKBD_CMD_GETID         0x02f2
 #define ATKBD_CMD_ENABLE        0x00f4
 #define ATKBD_CMD_RESET_DIS     0x00f5