Patchwork [U-Boot,3/5] input: i8042: Provide feature to disable keyboard before booting kernel

login
register
mail settings
Submitter Simon Glass
Date Oct. 12, 2012, 1:15 a.m.
Message ID <1350004554-18506-3-git-send-email-sjg@chromium.org>
Download mbox | patch
Permalink /patch/191028/
State Accepted, archived
Delegated to: Tom Rini
Headers show

Comments

Simon Glass - Oct. 12, 2012, 1:15 a.m.
From: Louis Yung-Chieh Lo <yjlou@chromium.org>

The BIOS leaves the keyboard enabled during boot time so that any
keystroke would interfere kernel driver initialization.

Add a way to disable the keyboard to make sure no scancode will be
generated during the boot time. Note that the keyboard will be
re-enabled again after the kernel driver is up.

This code can be called from the board functions.
Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>

Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
---
 drivers/input/i8042.c |   38 ++++++++++++++++++++++++++++++++++++++
 include/i8042.h       |   13 +++++++++++++
 2 files changed, 51 insertions(+), 0 deletions(-)

Patch

diff --git a/drivers/input/i8042.c b/drivers/input/i8042.c
index cae2d0a..6b51eb5 100644
--- a/drivers/input/i8042.c
+++ b/drivers/input/i8042.c
@@ -331,6 +331,44 @@  int __board_i8042_skip(void)
 }
 int board_i8042_skip(void) __attribute__((weak, alias("__board_i8042_skip")));
 
+void i8042_flush(void)
+{
+	int timeout;
+
+	/*
+	 * The delay is to give the keyboard controller some time to fill the
+	 * next byte.
+	 */
+	while (1) {
+		timeout = 100;  /* wait for no longer than 100us */
+		while (timeout > 0 && !(in8(I8042_STATUS_REG) & 0x01)) {
+			udelay(1);
+			timeout--;
+		}
+
+		/* Try to pull next byte if not timeout. */
+		if (in8(I8042_STATUS_REG) & 0x01)
+			in8(I8042_DATA_REG);
+		else
+			break;
+	}
+}
+
+int i8042_disable(void)
+{
+	if (kbd_input_empty() == 0)
+		return -1;
+
+	/* Disable keyboard */
+	out8(I8042_COMMAND_REG, 0xad);
+
+	if (kbd_input_empty() == 0)
+		return -1;
+
+	return 0;
+}
+
+
 /*******************************************************************************
  *
  * i8042_kbd_init - reset keyboard and init state flags
diff --git a/include/i8042.h b/include/i8042.h
index 1395289..c3e4e02 100644
--- a/include/i8042.h
+++ b/include/i8042.h
@@ -69,6 +69,19 @@ 
 
 /* exports */
 
+/**
+ * Flush all buffer from keyboard controller to host.
+ */
+void i8042_flush(void);
+
+/**
+ * Disables the keyboard so that key strokes no longer generate scancodes to
+ * the host.
+ *
+ * @return 0 if ok, -1 if keyboard input was found while disabling
+ */
+int i8042_disable(void);
+
 int i8042_kbd_init(void);
 int i8042_tstc(void);
 int i8042_getc(void);