Support ps2 port RESET commands that respond with 1 or 2 bytes.
Some devices only respond with 1 byte - if they timeout reading the
second byte, don't fail the whole operation - just continue and
handle the 1 byte.
diff --git a/src/kbd.c b/src/kbd.c
index b3f7fc6..11d11d3 100644
--- a/src/kbd.c
+++ b/src/kbd.c
@@ -55,7 +55,7 @@
/* ------------------- keyboard side ------------------------*/
/* reset keyboard and self test (keyboard side) */
ret = kbd_command(ATKBD_CMD_RESET_BAT, param);
- if (ret)
+ if (ret < 0)
return;
if (param[0] != 0xaa) {
dprintf(1, "keyboard self test failed (got %x not 0xaa\n", param[0]);
diff --git a/src/mouse.c b/src/mouse.c
index 0f0a75f..7a74eba 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -97,7 +97,7 @@
{
u8 param[2];
int ret = aux_command(PSMOUSE_CMD_RESET_BAT, param);
- if (ret) {
+ if (ret < 0) {
set_code_fail(regs, RET_ENEEDRESEND);
return;
}
diff --git a/src/ps2port.c b/src/ps2port.c
index f707064..b72def6 100644
--- a/src/ps2port.c
+++ b/src/ps2port.c
@@ -207,8 +207,12 @@
// Receive parameters (if any).
for (i = 0; i < receive; i++) {
ret = i8042_wait_read();
- if (ret)
+ if (ret) {
+ // On a receive timeout, return the item number that the
+ // transfer failed on.
+ ret = i + 1;
goto fail;
+ }
param[i] = inb(PORT_PS2_DATA);
}
@@ -226,7 +230,7 @@
{
int ret = ps2_command(0, command, param);
if (ret)
- dprintf(2, "keyboard command %x failed\n", command);
+ dprintf(2, "keyboard command %x failed (ret=%d)\n", command, ret);
return ret;
}
@@ -235,6 +239,6 @@
{
int ret = ps2_command(1, command, param);
if (ret)
- dprintf(2, "mouse command %x failed\n", command);
+ dprintf(2, "mouse command %x failed (ret=%d)\n", command, ret);
return ret;
}
diff --git a/src/ps2port.h b/src/ps2port.h
index fa73a06..a0b7a65 100644
--- a/src/ps2port.h
+++ b/src/ps2port.h
@@ -22,7 +22,7 @@
#define ATKBD_CMD_GETID 0x02f2
#define ATKBD_CMD_ENABLE 0x00f4
#define ATKBD_CMD_RESET_DIS 0x00f5
-#define ATKBD_CMD_RESET_BAT 0x01ff
+#define ATKBD_CMD_RESET_BAT 0x02ff
// Mouse commands
#define PSMOUSE_CMD_SETSCALE11 0x00e6