pandora: defconfig: update
[pandora-kernel.git] / drivers / input / serio / i8042.c
index d37a48e..1233bb4 100644 (file)
@@ -67,6 +67,10 @@ static bool i8042_notimeout;
 module_param_named(notimeout, i8042_notimeout, bool, 0);
 MODULE_PARM_DESC(notimeout, "Ignore timeouts signalled by i8042");
 
+static bool i8042_kbdreset;
+module_param_named(kbdreset, i8042_kbdreset, bool, 0);
+MODULE_PARM_DESC(kbdreset, "Reset device connected to KBD port");
+
 #ifdef CONFIG_X86
 static bool i8042_dritek;
 module_param_named(dritek, i8042_dritek, bool, 0);
@@ -386,8 +390,10 @@ static int i8042_start(struct serio *serio)
 {
        struct i8042_port *port = serio->port_data;
 
+       spin_lock_irq(&i8042_lock);
        port->exists = true;
-       mb();
+       spin_unlock_irq(&i8042_lock);
+
        return 0;
 }
 
@@ -400,16 +406,20 @@ static void i8042_stop(struct serio *serio)
 {
        struct i8042_port *port = serio->port_data;
 
+       spin_lock_irq(&i8042_lock);
        port->exists = false;
+       port->serio = NULL;
+       spin_unlock_irq(&i8042_lock);
 
        /*
+        * We need to make sure that interrupt handler finishes using
+        * our serio port before we return from this function.
         * We synchronize with both AUX and KBD IRQs because there is
         * a (very unlikely) chance that AUX IRQ is raised for KBD port
         * and vice versa.
         */
        synchronize_irq(I8042_AUX_IRQ);
        synchronize_irq(I8042_KBD_IRQ);
-       port->serio = NULL;
 }
 
 /*
@@ -526,7 +536,7 @@ static irqreturn_t i8042_interrupt(int irq, void *dev_id)
 
        spin_unlock_irqrestore(&i8042_lock, flags);
 
-       if (likely(port->exists && !filtered))
+       if (likely(serio && !filtered))
                serio_interrupt(serio, data, dfl);
 
  out:
@@ -782,6 +792,16 @@ static int __init i8042_check_aux(void)
        if (i8042_toggle_aux(true))
                return -1;
 
+/*
+ * Reset keyboard (needed on some laptops to successfully detect
+ * touchpad, e.g., some Gigabyte laptop models with Elantech
+ * touchpads).
+ */
+       if (i8042_kbdreset) {
+               pr_warn("Attempting to reset device connected to KBD port\n");
+               i8042_kbd_write(NULL, (unsigned char) 0xff);
+       }
+
 /*
  * Test AUX IRQ delivery to make sure BIOS did not grab the IRQ and
  * used it for a PCI card or somethig else.
@@ -991,7 +1011,7 @@ static int i8042_controller_init(void)
  * Reset the controller and reset CRT to the original value set by BIOS.
  */
 
-static void i8042_controller_reset(void)
+static void i8042_controller_reset(bool force_reset)
 {
        i8042_flush();
 
@@ -1016,7 +1036,7 @@ static void i8042_controller_reset(void)
  * Reset the controller if requested.
  */
 
-       if (i8042_reset)
+       if (i8042_reset || force_reset)
                i8042_controller_selftest();
 
 /*
@@ -1139,9 +1159,9 @@ static int i8042_controller_resume(bool force_reset)
  * upsetting it.
  */
 
-static int i8042_pm_reset(struct device *dev)
+static int i8042_pm_suspend(struct device *dev)
 {
-       i8042_controller_reset();
+       i8042_controller_reset(true);
 
        return 0;
 }
@@ -1163,13 +1183,20 @@ static int i8042_pm_thaw(struct device *dev)
        return 0;
 }
 
+static int i8042_pm_reset(struct device *dev)
+{
+       i8042_controller_reset(false);
+
+       return 0;
+}
+
 static int i8042_pm_restore(struct device *dev)
 {
        return i8042_controller_resume(false);
 }
 
 static const struct dev_pm_ops i8042_pm_ops = {
-       .suspend        = i8042_pm_reset,
+       .suspend        = i8042_pm_suspend,
        .resume         = i8042_pm_resume,
        .thaw           = i8042_pm_thaw,
        .poweroff       = i8042_pm_reset,
@@ -1185,7 +1212,7 @@ static const struct dev_pm_ops i8042_pm_ops = {
 
 static void i8042_shutdown(struct platform_device *dev)
 {
-       i8042_controller_reset();
+       i8042_controller_reset(false);
 }
 
 static int __init i8042_create_kbd_port(void)
@@ -1202,6 +1229,7 @@ static int __init i8042_create_kbd_port(void)
        serio->start            = i8042_start;
        serio->stop             = i8042_stop;
        serio->close            = i8042_port_close;
+       serio->ps2_cmd_mutex    = &i8042_mutex;
        serio->port_data        = port;
        serio->dev.parent       = &i8042_platform_device->dev;
        strlcpy(serio->name, "i8042 KBD port", sizeof(serio->name));
@@ -1227,6 +1255,7 @@ static int __init i8042_create_aux_port(int idx)
        serio->write            = i8042_aux_write;
        serio->start            = i8042_start;
        serio->stop             = i8042_stop;
+       serio->ps2_cmd_mutex    = &i8042_mutex;
        serio->port_data        = port;
        serio->dev.parent       = &i8042_platform_device->dev;
        if (idx < 0) {
@@ -1289,21 +1318,6 @@ static void __devexit i8042_unregister_ports(void)
        }
 }
 
-/*
- * Checks whether port belongs to i8042 controller.
- */
-bool i8042_check_port_owner(const struct serio *port)
-{
-       int i;
-
-       for (i = 0; i < I8042_NUM_PORTS; i++)
-               if (i8042_ports[i].serio == port)
-                       return true;
-
-       return false;
-}
-EXPORT_SYMBOL(i8042_check_port_owner);
-
 static void i8042_free_irqs(void)
 {
        if (i8042_aux_irq_registered)
@@ -1424,7 +1438,7 @@ static int __init i8042_probe(struct platform_device *dev)
  out_fail:
        i8042_free_aux_ports(); /* in case KBD failed but AUX not */
        i8042_free_irqs();
-       i8042_controller_reset();
+       i8042_controller_reset(false);
        i8042_platform_device = NULL;
 
        return error;
@@ -1434,7 +1448,7 @@ static int __devexit i8042_remove(struct platform_device *dev)
 {
        i8042_unregister_ports();
        i8042_free_irqs();
-       i8042_controller_reset();
+       i8042_controller_reset(false);
        i8042_platform_device = NULL;
 
        return 0;