From: Dmitry Torokhov Date: Tue, 3 Nov 2009 05:57:40 +0000 (-0800) Subject: Input: i8042 - try to get stable CTR value when initializing X-Git-Tag: v2.6.32-rc6~5^2~2 X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=ee1e82cee5e463a885d3c71acb2c769490e6927f;p=~emulex%2Finfiniband.git Input: i8042 - try to get stable CTR value when initializing If user presses keys while i8042 is being initialized there is a chance that keyboard data will be mistaken for results of Read Control Register command causing futher troubles. Work around this issue by reading CTR several times and stop when we get matching results. Reported-and-tested-by: Dave Young Signed-off-by: Dmitry Torokhov --- diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c index a31578170cc..1df02d25aca 100644 --- a/drivers/input/serio/i8042.c +++ b/drivers/input/serio/i8042.c @@ -836,17 +836,32 @@ static int i8042_controller_selftest(void) static int i8042_controller_init(void) { unsigned long flags; + int n = 0; + unsigned char ctr[2]; /* - * Save the CTR for restoral on unload / reboot. + * Save the CTR for restore on unload / reboot. */ - if (i8042_command(&i8042_ctr, I8042_CMD_CTL_RCTR)) { - printk(KERN_ERR "i8042.c: Can't read CTR while initializing i8042.\n"); - return -EIO; - } + do { + if (n >= 10) { + printk(KERN_ERR + "i8042.c: Unable to get stable CTR read.\n"); + return -EIO; + } + + if (n != 0) + udelay(50); + + if (i8042_command(&ctr[n++ % 2], I8042_CMD_CTL_RCTR)) { + printk(KERN_ERR + "i8042.c: Can't read CTR while initializing i8042.\n"); + return -EIO; + } - i8042_initial_ctr = i8042_ctr; + } while (n < 2 || ctr[0] != ctr[1]); + + i8042_initial_ctr = i8042_ctr = ctr[0]; /* * Disable the keyboard interface and interrupt. @@ -895,6 +910,12 @@ static int i8042_controller_init(void) return -EIO; } +/* + * Flush whatever accumulated while we were disabling keyboard port. + */ + + i8042_flush(); + return 0; } @@ -914,7 +935,7 @@ static void i8042_controller_reset(void) i8042_ctr |= I8042_CTR_KBDDIS | I8042_CTR_AUXDIS; i8042_ctr &= ~(I8042_CTR_KBDINT | I8042_CTR_AUXINT); - if (i8042_command(&i8042_initial_ctr, I8042_CMD_CTL_WCTR)) + if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) printk(KERN_WARNING "i8042.c: Can't write CTR while resetting.\n"); /*