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)
/* ------------------- 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]);
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);
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;
// 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;
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;
}
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;
}