[U-Boot] [PATCH v2 1/5] input: Use finer grain udelays while waitng for the i8042 keyboard buffer to empty

From: Gabe Black gabeblack@chromium.org
On x86, the i8042 keyboard controller driver frequently waits for the keyboard input buffer to be empty to make sure the controller has had a chance to process the data it was given. The way the delay loop was structured, if the controller hadn't cleared the corresponding status bit immediately, it would wait 1ms before checking again. If the keyboard responded quickly but not instantly, the driver would still wait a full 1ms when perhaps 1us would have been sufficient. Because udelay is a busy wait anyway, this change decreases the delay between checks to 1us.
Also, this change gets rid of a hardcoded 250ms delay.
On Stumpy, this saves 100-150ms during boot.
Signed-off-by: Gabe Black gabeblack@chromium.org Signed-off-by: Simon Glass sjg@chromium.org --- Changes in v2: - Add constants for i8042 status registers
drivers/input/i8042.c | 9 +++------ include/i8042.h | 6 ++++++ 2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/input/i8042.c b/drivers/input/i8042.c index c3bc536..6839c6b 100644 --- a/drivers/input/i8042.c +++ b/drivers/input/i8042.c @@ -607,11 +607,10 @@ static void kbd_led_set(void)
static int kbd_input_empty(void) { - int kbdTimeout = KBD_TIMEOUT; + int kbdTimeout = KBD_TIMEOUT * 1000;
- /* wait for input buf empty */ - while ((in8(I8042_STATUS_REG) & 0x02) && kbdTimeout--) - udelay(1000); + while ((in8(I8042_STATUS_REG) & I8042_STATUS_IN_DATA) && kbdTimeout--) + udelay(1);
return kbdTimeout != -1; } @@ -625,8 +624,6 @@ static int kbd_reset(void)
out8(I8042_DATA_REG, 0xff);
- udelay(250000); - if (kbd_input_empty() == 0) return -1;
diff --git a/include/i8042.h b/include/i8042.h index 1395289..aeb3f09 100644 --- a/include/i8042.h +++ b/include/i8042.h @@ -39,6 +39,12 @@ #define I8042_STATUS_REG (CONFIG_SYS_ISA_IO + 0x0064) /* keyboard status read */ #define I8042_COMMAND_REG (CONFIG_SYS_ISA_IO + 0x0064) /* keyboard ctrl write */
+enum { + /* Output register (I8042_DATA_REG) has data for system */ + I8042_STATUS_OUT_DATA = 1 << 0, + I8042_STATUS_IN_DATA = 1 << 1, +}; + #define KBD_US 0 /* default US layout */ #define KBD_GER 1 /* german layout */

From: Gabe Black gabeblack@chromium.org
This change adds a board overridable function which can be used to decide whether or not to initialize the i8042 keyboard controller. On systems where it isn't actually connected to anything, this can save a significant amount of boot time.
On Stumpy, this saves about 200ms on boot.
Signed-off-by: Gabe Black gabeblack@chromium.org Signed-off-by: Simon Glass sjg@chromium.org --- Changes in v2: - Use __weak instead of the long attribute form
drivers/input/i8042.c | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/drivers/input/i8042.c b/drivers/input/i8042.c index 6839c6b..3a4c467 100644 --- a/drivers/input/i8042.c +++ b/drivers/input/i8042.c @@ -26,6 +26,7 @@ /* includes */
#include <common.h> +#include <linux/compiler.h>
#ifdef CONFIG_USE_CPCIDVI extern u8 gt_cpcidvi_in8(u32 offset); @@ -320,6 +321,16 @@ static int kbd_controller_present(void) return in8(I8042_STATUS_REG) != 0xff; }
+/* + * Implement a weak default function for boards that optionally + * need to skip the i8042 initialization. + */ +int __weak board_i8042_skip(void) +{ + /* As default, don't skip */ + return 0; +} + /******************************************************************************* * * i8042_kbd_init - reset keyboard and init state flags @@ -329,7 +340,7 @@ int i8042_kbd_init(void) int keymap, try; char *penv;
- if (!kbd_controller_present()) + if (!kbd_controller_present() || board_i8042_skip()) return -1;
#ifdef CONFIG_USE_CPCIDVI
participants (1)
-
Simon Glass