kbd: wait longer for self-test on keyboard reset

Some keyboards take pretty long to respond to a reset command, some even
delay the ACK to the command. To make the keyboard driver more robust,
increase the timeout for this special command. Also do an interface test
after the self-test to ensure the keyboard is functioning properly.

Another point is to reenable the keyboard *after* the scancode was set,
not before. We also set the system bit when enabling the keyboard
because this seems to be what older operating systems do expect.

One of the problematic keyboards, which will work with this patch
applied, is the DELL RT7D20. Without the patch an overly optimistic
operating system, read Linux 2.4, will not recognise the keyboard
because coreboot didn't fully initialize it.

Change-Id: I28c8e05bdde61f71b7de084c96bc2447c1b9575e
Signed-off-by: Mathias Krause <mathias.krause@secunet.com>
Reviewed-on: http://review.coreboot.org/486
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
This commit is contained in:
Mathias Krause 2011-12-14 08:40:48 +01:00 committed by Patrick Georgi
parent f154c01802
commit 1c80cf04fe
1 changed files with 45 additions and 11 deletions

View File

@ -36,6 +36,7 @@
#define KBC_CMD_READ_COMMAND 0x20 // Read command byte #define KBC_CMD_READ_COMMAND 0x20 // Read command byte
#define KBC_CMD_WRITE_COMMAND 0x60 // Write command byte #define KBC_CMD_WRITE_COMMAND 0x60 // Write command byte
#define KBC_CMD_SELF_TEST 0xAA // Controller self-test #define KBC_CMD_SELF_TEST 0xAA // Controller self-test
#define KBC_CMD_KBD_TEST 0xAB // Keyboard Interface test
/* The Keyboard controller command byte /* The Keyboard controller command byte
* BIT | Description * BIT | Description
@ -136,6 +137,26 @@ static int kbc_self_test(void)
return 0; return 0;
} }
/* ensure the buffers are empty */
kbc_cleanup_buffers();
/* keyboard interface test */
outb(KBC_CMD_KBD_TEST, KBD_COMMAND);
if (!kbc_output_buffer_full()) {
printk(BIOS_ERR, "Keyboard Interface test timed out.\n");
return 0;
}
/* read test result, 0x00 should be returned in case of no failures */
self_test = inb(KBD_DATA);
if (self_test != 0x00) {
printk(BIOS_ERR, "Keyboard Interface test failed: 0x%x\n",
self_test);
return 0;
}
return 1; return 1;
} }
@ -147,6 +168,14 @@ static u8 send_keyboard(u8 command)
do { do {
if (!kbc_input_buffer_empty()) return 0; if (!kbc_input_buffer_empty()) return 0;
outb(command, KBD_DATA); outb(command, KBD_DATA);
/* the reset command takes much longer then normal commands and
* even worse, some keyboards do send the ACK _after_ doing the
* reset */
if (command == 0xFF) {
u8 retries;
for (retries = 9; retries && !kbc_output_buffer_full(); retries--)
;
}
if (!kbc_output_buffer_full()) { if (!kbc_output_buffer_full()) {
printk(BIOS_ERR, "Could not send keyboard command %02x\n", printk(BIOS_ERR, "Could not send keyboard command %02x\n",
command); command);
@ -161,6 +190,7 @@ static u8 send_keyboard(u8 command)
void pc_keyboard_init(struct pc_keyboard *keyboard) void pc_keyboard_init(struct pc_keyboard *keyboard)
{ {
u8 retries;
u8 regval; u8 regval;
if (!CONFIG_DRIVERS_PS2_KEYBOARD) if (!CONFIG_DRIVERS_PS2_KEYBOARD)
return; return;
@ -192,10 +222,14 @@ void pc_keyboard_init(struct pc_keyboard *keyboard)
} }
if (regval != KBD_REPLY_ACK) { if (regval != KBD_REPLY_ACK) {
printk(BIOS_ERR, "Keyboard selftest failed ACK: 0x%x\n", regval); printk(BIOS_ERR, "Keyboard reset failed ACK: 0x%x\n", regval);
return; return;
} }
/* the reset command takes some time, so wait a little longer */
for (retries = 9; retries && !kbc_output_buffer_full(); retries--)
;
if (!kbc_output_buffer_full()) { if (!kbc_output_buffer_full()) {
printk(BIOS_ERR, "Timeout waiting for keyboard after reset.\n"); printk(BIOS_ERR, "Timeout waiting for keyboard after reset.\n");
return; return;
@ -203,7 +237,7 @@ void pc_keyboard_init(struct pc_keyboard *keyboard)
regval = inb(KBD_DATA); regval = inb(KBD_DATA);
if (regval != 0xAA) { if (regval != 0xAA) {
printk(BIOS_ERR, "Keyboard selftest failed: 0x%x\n", regval); printk(BIOS_ERR, "Keyboard reset selftest failed: 0x%x\n", regval);
return; return;
} }
@ -232,20 +266,20 @@ void pc_keyboard_init(struct pc_keyboard *keyboard)
return; return;
} }
/* enable the keyboard */
regval = send_keyboard(0xF4);
if (regval != KBD_REPLY_ACK) {
printk(BIOS_ERR, "Keyboard enable failed ACK: 0x%x\n", regval);
return;
}
/* All is well - enable keyboard interface */ /* All is well - enable keyboard interface */
if (!kbc_input_buffer_empty()) return; if (!kbc_input_buffer_empty()) return;
outb(0x60, KBD_COMMAND); outb(0x60, KBD_COMMAND);
if (!kbc_input_buffer_empty()) return; if (!kbc_input_buffer_empty()) return;
outb(0x61, KBD_DATA); /* send cmd: enable keyboard and IRQ 1 */ outb(0x65, KBD_DATA); /* send cmd: enable keyboard and IRQ 1 */
if (!kbc_input_buffer_empty()) { if (!kbc_input_buffer_empty()) {
printk(BIOS_ERR, "Timeout during final keyboard enable\n"); printk(BIOS_ERR, "Timeout during keyboard enable\n");
return;
}
/* enable the keyboard */
regval = send_keyboard(0xF4);
if (regval != KBD_REPLY_ACK) {
printk(BIOS_ERR, "Keyboard enable failed ACK: 0x%x\n", regval);
return; return;
} }
} }