serio_continue_rx(atkbd->ps2dev.serio);
 }
 
+static int atkbd_activate(struct atkbd *atkbd)
+{
+       struct ps2dev *ps2dev = &atkbd->ps2dev;
+
+/*
+ * Enable the keyboard to receive keystrokes.
+ */
+
+       if (ps2_command(ps2dev, NULL, ATKBD_CMD_ENABLE)) {
+               dev_err(&ps2dev->serio->dev,
+                       "Failed to enable keyboard on %s\n",
+                       ps2dev->serio->phys);
+               return -1;
+       }
+
+       return 0;
+}
+
+/*
+ * atkbd_deactivate() resets and disables the keyboard from sending
+ * keystrokes.
+ */
+
+static void 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);
+}
+
 /*
  * atkbd_probe() probes for an AT keyboard on a serio port.
  */
                return -1;
        }
 
+/*
+ * Make sure nothing is coming from the keyboard and disturbs our
+ * internal state.
+ */
+       atkbd_deactivate(atkbd);
+
        return 0;
 }
 
        return 0;
 }
 
-static int atkbd_activate(struct atkbd *atkbd)
-{
-       struct ps2dev *ps2dev = &atkbd->ps2dev;
-
-/*
- * Enable the keyboard to receive keystrokes.
- */
-
-       if (ps2_command(ps2dev, NULL, ATKBD_CMD_ENABLE)) {
-               dev_err(&ps2dev->serio->dev,
-                       "Failed to enable 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.
 
                atkbd->set = atkbd_select_set(atkbd, atkbd_set, atkbd_extra);
                atkbd_reset_state(atkbd);
-               atkbd_activate(atkbd);
 
        } else {
                atkbd->set = 2;
                goto fail3;
 
        atkbd_enable(atkbd);
+       if (serio->write)
+               atkbd_activate(atkbd);
 
        err = input_register_device(atkbd->dev);
        if (err)
                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
 
        }
 
+       /*
+        * Reset our state machine in case reconnect happened in the middle
+        * of multi-byte scancode.
+        */
+       atkbd->xl_bit = 0;
+       atkbd->emul = 0;
+
        atkbd_enable(atkbd);
+       if (atkbd->write)
+               atkbd_activate(atkbd);
+
        retval = 0;
 
  out: