]> xenbits.xensource.com Git - people/aperard/linux-chromebook.git/commitdiff
CHROMIUM: atkbd: Fix scancode handling on reconnect / resume from suspend.
authorShawn Nematbakhsh <shawnn@google.com>
Fri, 14 Dec 2012 03:28:02 +0000 (19:28 -0800)
committerGerrit <chrome-bot@google.com>
Sat, 15 Dec 2012 00:53:13 +0000 (16:53 -0800)
On resume from suspend there is a possibility for multi-byte scancodes
to be handled incorrectly. atkbd_reconnect disables the processing of
scancodes in software by calling atkbd_disable, but the keyboard may
still be active because no disconnect command was sent. Later, software
handling is re-enabled. If a multi-byte scancode sent from the keyboard
straddles the re-enable, only the latter byte(s) will be handled.

In practice, this leads to cases where multi-byte break codes (ex. "e0
4d" - break code for right-arrow) are misread as make codes ("4d" - make
code for numeric 6), leading to one or more unwanted, untyped characters
being interpreted.

The solution implemented here involves sending command f5 (reset
disable) to the keyboard prior to disabling software handling of codes.
Later, the command to re-enable the keyboard is sent only after we are
prepared to handle scancodes.

TEST=spam right/left arrow keys during resume for many iterations,
verify that no phantom characters are seen.
BUG=chrome-os-partner:16605

Change-Id: Ieba1e42398c2f4f6a1623afa3ed82903dc393045
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/39690
Reviewed-by: Derek Basehore <dbasehore@chromium.org>
Reviewed-by: Andrew de los Reyes <adlr@chromium.org>
drivers/input/keyboard/atkbd.c

index 406a95426c178620c3850e32c29ce19c9486c0c5..916b994a20807ecea95f6fb43e6e91750ed0b669 100644 (file)
@@ -843,6 +843,24 @@ static int atkbd_activate(struct atkbd *atkbd)
        return 0;
 }
 
+/*
+ * atkbd_deactivate() resets and disables the keyboard from sending
+ * keystrokes.
+ */
+static int atkbd_deactivate(struct atkbd *atkbd)
+{
+       struct ps2dev *ps2dev = &atkbd->ps2dev;
+
+       if (ps2_command(ps2dev, NULL, ATKBD_CMD_RESET_DIS)) {
+               dev_err(&ps2dev->serio->dev,
+                       "Failed to deactivate keyboard on %s\n",
+                       ps2dev->serio->phys);
+               return -1;
+       }
+
+       return 0;
+}
+
 /*
  * atkbd_cleanup() restores the keyboard state so that BIOS is happy after a
  * reboot.
@@ -1199,6 +1217,9 @@ static int atkbd_reconnect(struct serio *serio)
 
        mutex_lock(&atkbd->mutex);
 
+       if (atkbd->write)
+               atkbd_deactivate(atkbd);
+
        atkbd_disable(atkbd);
 
        if (atkbd->write) {
@@ -1208,8 +1229,6 @@ static int atkbd_reconnect(struct serio *serio)
                if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra))
                        goto out;
 
-               atkbd_activate(atkbd);
-
                /*
                 * Restore LED state and repeat rate. While input core
                 * will do this for us at resume time reconnect may happen
@@ -1224,6 +1243,9 @@ static int atkbd_reconnect(struct serio *serio)
        }
 
        atkbd_enable(atkbd);
+       if (atkbd->write)
+               atkbd_activate(atkbd);
+
        retval = 0;
 
  out: