From f7faac151abfedca5f56d7587edf4e54030f8015 Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Sun, 1 Nov 2020 19:29:41 +0100 Subject: 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/47084 Reviewed-by: Angel Pons Reviewed-by: Paul Menzel Tested-by: build bot (Jenkins) --- payloads/libpayload/drivers/i8042/keyboard.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'payloads/libpayload/drivers') diff --git a/payloads/libpayload/drivers/i8042/keyboard.c b/payloads/libpayload/drivers/i8042/keyboard.c index 42d4fdccf5..46afdc03f0 100644 --- a/payloads/libpayload/drivers/i8042/keyboard.c +++ b/payloads/libpayload/drivers/i8042/keyboard.c @@ -172,6 +172,12 @@ static struct layout_maps keyboard_layouts[] = { #endif }; +static void keyboard_drain_input(void) +{ + while (i8042_data_ready_ps2()) + (void)i8042_read_data_ps2(); +} + static bool keyboard_cmd(unsigned char cmd) { 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()) return; - /* Empty keyboard buffer */ - while (keyboard_havechar()) - keyboard_getchar(); + keyboard_drain_input(); /* Enable first PS/2 port */ i8042_cmd(I8042_CMD_EN_KB); @@ -400,9 +404,7 @@ void keyboard_disconnect(void) if (!i8042_has_ps2()) return; - /* Empty keyboard buffer */ - while (keyboard_havechar()) - keyboard_getchar(); + keyboard_drain_input(); /* Disable scanning */ keyboard_cmd(I8042_KBCMD_DEFAULT_DIS); @@ -411,8 +413,7 @@ void keyboard_disconnect(void) i8042_cmd(I8042_CMD_DIS_KB); /* Hand off with empty buffer */ - while (keyboard_havechar()) - keyboard_getchar(); + keyboard_drain_input(); /* Release keyboard controller driver */ i8042_close(); -- cgit v1.2.3