libpayload/keyboard: Introduce keyboard_drain_input()

Move the input-buffer draining into a function. It uses the low-level
i8042 API directly to avoid conflicts with changes in the high-level
keyboard API.

Change-Id: I9427c5b8be4d59c2ee3da12d6168d34590043682
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/47084
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Nico Huber 2020-11-01 19:29:41 +01:00 committed by Hung-Te Lin
parent a160d93dda
commit f7faac151a
1 changed files with 9 additions and 8 deletions

View File

@ -172,6 +172,12 @@ static struct layout_maps keyboard_layouts[] = {
#endif #endif
}; };
static void keyboard_drain_input(void)
{
while (i8042_data_ready_ps2())
(void)i8042_read_data_ps2();
}
static bool keyboard_cmd(unsigned char cmd) static bool keyboard_cmd(unsigned char cmd)
{ {
const uint64_t timeout_us = cmd == I8042_KBCMD_RESET ? 1*1000*1000 : 200*1000; const uint64_t timeout_us = cmd == I8042_KBCMD_RESET ? 1*1000*1000 : 200*1000;
@ -368,9 +374,7 @@ void keyboard_init(void)
if (!i8042_probe() || !i8042_has_ps2()) if (!i8042_probe() || !i8042_has_ps2())
return; return;
/* Empty keyboard buffer */ keyboard_drain_input();
while (keyboard_havechar())
keyboard_getchar();
/* Enable first PS/2 port */ /* Enable first PS/2 port */
i8042_cmd(I8042_CMD_EN_KB); i8042_cmd(I8042_CMD_EN_KB);
@ -400,9 +404,7 @@ void keyboard_disconnect(void)
if (!i8042_has_ps2()) if (!i8042_has_ps2())
return; return;
/* Empty keyboard buffer */ keyboard_drain_input();
while (keyboard_havechar())
keyboard_getchar();
/* Disable scanning */ /* Disable scanning */
keyboard_cmd(I8042_KBCMD_DEFAULT_DIS); keyboard_cmd(I8042_KBCMD_DEFAULT_DIS);
@ -411,8 +413,7 @@ void keyboard_disconnect(void)
i8042_cmd(I8042_CMD_DIS_KB); i8042_cmd(I8042_CMD_DIS_KB);
/* Hand off with empty buffer */ /* Hand off with empty buffer */
while (keyboard_havechar()) keyboard_drain_input();
keyboard_getchar();
/* Release keyboard controller driver */ /* Release keyboard controller driver */
i8042_close(); i8042_close();