summaryrefslogtreecommitdiff
path: root/payloads/libpayload
diff options
context:
space:
mode:
authorNico Huber <nico.h@gmx.de>2020-11-01 19:29:41 +0100
committerHung-Te Lin <hungte@chromium.org>2020-12-24 08:18:57 +0000
commitf7faac151abfedca5f56d7587edf4e54030f8015 (patch)
tree1880821a28731e3a3e3583885f24c90258a9a9b3 /payloads/libpayload
parenta160d93dda188b33b4b28bb888bd78120e42695d (diff)
downloadcoreboot-f7faac151abfedca5f56d7587edf4e54030f8015.tar.xz
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>
Diffstat (limited to 'payloads/libpayload')
-rw-r--r--payloads/libpayload/drivers/i8042/keyboard.c17
1 files changed, 9 insertions, 8 deletions
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();