summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabe Black <gabeblack@chromium.org>2011-09-03 18:12:09 -0700
committerGabe Black (Do Not Use) <gabeblack@google.com>2011-09-06 13:59:39 -0700
commitb10d21b57ceb1d1b10d8ea655ba2ca0711494098 (patch)
tree909f15db65a984890dfa5fbcabe524af31e4b319
parentd110b42aafb68a8f92f101e98d58d912bb97ed4f (diff)
Fix some bugs in the i8402 driver which show up when no controller is present
If no controller is present, the i8402 driver should return immediately and not attempt to operate on the missing hardware. In kbd_input_empty, the status register is checked every millisecond to see whether the input buffer is empty, up to a timeout which is tracked by decrimenting a counter each time the check is performed. The decrement is performed with a postfix -- operator, and the value of the counter is checked in place. That means that when the counter reaches zero and the loop terminates, it will actually be decrimented one more time and become -1. That value is returned as the return value of the function. That would give the right answer if it wasn't for that extra decrement because a timeout would indicate that the buffer never became empty. This change fixes both of those bugs. BUG=chrome-os-partner:5849 TEST=Built and booted on both x86-alex and stumpy. Used the built in keyboard on x86-alex. Change-Id: Id79d2067237952f95caca3f32d4928723d1fcdc1 Signed-off-by: Gabe Black <gabeblack@google.com> Reviewed-on: http://gerrit.chromium.org/gerrit/7248
-rw-r--r--drivers/input/i8042.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/input/i8042.c b/drivers/input/i8042.c
index 58094c925ce..3bdfa7d7f6a 100644
--- a/drivers/input/i8042.c
+++ b/drivers/input/i8042.c
@@ -315,6 +315,13 @@ static unsigned char ext_key_map [] =
0x00 /* map end */
};
+/******************************************************************************/
+
+static int kbd_controller_present (void)
+{
+ return in8(I8042_STATUS_REG) != 0xff;
+}
+
/*******************************************************************************
*
* i8042_kbd_init - reset keyboard and init state flags
@@ -324,6 +331,9 @@ int i8042_kbd_init (void)
int keymap, try;
char *penv;
+ if (!kbd_controller_present())
+ return -1;
+
#ifdef CONFIG_USE_CPCIDVI
if ((penv = getenv ("console")) != NULL) {
if (strncmp (penv, "serial", 7) == 0) {
@@ -629,7 +639,7 @@ static int kbd_input_empty (void)
while ((in8 (I8042_STATUS_REG) & 0x02) && kbdTimeout--)
udelay(1000);
- return kbdTimeout;
+ return kbdTimeout != -1;
}
/******************************************************************************/