libpayload/i8042/keyboard: Fix return value check for keyboard_cmd

CB:32951 ("libpayload: Reset PS/2 keyboard") added a call to reset
keyboard and check the return value of keyboard_cmd() to compare
against I8042_KBCMD_ACK. However, keyboard_cmd() already checks for
ACK and returns 1 or 0 based on whether ACK is received.

This change fixes the check introduced by CB:32951 to compare against
0 just like the other checks for keyboard_cmd(). Additionally, it adds
error messages for all failed commands in keyboard_init() to make the
prints consistent in case of failure.

BUG=b:134366527
TEST=Verified that logs do not contain "ERROR: Keyboard reset failed"
anymore.

Change-Id: Idcadaae12e0a44e404a1d98c6deb633d97058203
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/33185
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Frank Wu <frank_wu@compal.corp-partner.google.com>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
This commit is contained in:
Furquan Shaikh 2019-06-03 19:02:31 -07:00 committed by Patrick Georgi
parent 3cae9afbf9
commit a99ed13e33
1 changed files with 15 additions and 7 deletions

View File

@ -172,7 +172,7 @@ static unsigned char keyboard_cmd(unsigned char cmd)
{ {
i8042_write_data(cmd); i8042_write_data(cmd);
return i8042_wait_read_ps2() == 0xfa; return i8042_wait_read_ps2() == I8042_KBCMD_ACK;
} }
int keyboard_havechar(void) int keyboard_havechar(void)
@ -319,32 +319,40 @@ void keyboard_init(void)
/* Reset keyboard and self test (keyboard side) */ /* Reset keyboard and self test (keyboard side) */
ret = keyboard_cmd(I8042_KBCMD_RESET); ret = keyboard_cmd(I8042_KBCMD_RESET);
if (ret != I8042_KBCMD_ACK) { if (!ret) {
printf("ERROR: Keyboard reset failed ACK: 0x%x\n", ret); printf("ERROR: Keyboard reset failed!\n");
return; return;
} }
/* Set scancode set 1 */ /* Set scancode set 1 */
ret = keyboard_cmd(I8042_KBCMD_SET_SCANCODE); ret = keyboard_cmd(I8042_KBCMD_SET_SCANCODE);
if (!ret && !CONFIG(LP_PC_KEYBOARD_IGNORE_INIT_FAILURE)) if (!ret && !CONFIG(LP_PC_KEYBOARD_IGNORE_INIT_FAILURE)) {
printf("ERROR: Keyboard set scancode failed!\n");
return; return;
}
ret = keyboard_cmd(I8042_SCANCODE_SET_1); ret = keyboard_cmd(I8042_SCANCODE_SET_1);
if (!ret && !CONFIG(LP_PC_KEYBOARD_IGNORE_INIT_FAILURE)) if (!ret && !CONFIG(LP_PC_KEYBOARD_IGNORE_INIT_FAILURE)) {
printf("ERROR: Keyboard scancode set#1 failed!\n");
return; return;
}
/* /*
* Set default parameters. * Set default parameters.
* Fix for broken QEMU ps/2 make scancodes. * Fix for broken QEMU ps/2 make scancodes.
*/ */
ret = keyboard_cmd(0xf6); ret = keyboard_cmd(0xf6);
if (!ret) if (!ret) {
printf("ERROR: Keyboard set default params failed!\n");
return; return;
}
/* Enable scanning */ /* Enable scanning */
ret = keyboard_cmd(I8042_KBCMD_EN); ret = keyboard_cmd(I8042_KBCMD_EN);
if (!ret && !CONFIG(LP_PC_KEYBOARD_IGNORE_INIT_FAILURE)) if (!ret && !CONFIG(LP_PC_KEYBOARD_IGNORE_INIT_FAILURE)) {
printf("ERROR: Keyboard enable scanning failed!\n");
return; return;
}
console_add_input_driver(&cons); console_add_input_driver(&cons);
} }