Input: psmouse - add support for Cortron PS/2 Trackballs
[cascardo/linux.git] / drivers / input / mouse / psmouse-base.c
index 0fe5869..b9f0fb2 100644 (file)
@@ -28,6 +28,7 @@
 #include "alps.h"
 #include "lifebook.h"
 #include "trackpoint.h"
+#include "touchkit_ps2.h"
 
 #define DRIVER_DESC    "PS/2 mouse driver"
 
@@ -176,6 +177,15 @@ static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
                packet[1] |= (packet[0] & 0x40) << 1;
        }
 
+/*
+ * Cortron PS2 Trackball reports SIDE button on the 4th bit of the first
+ * byte.
+ */
+       if (psmouse->type == PSMOUSE_CORTRON) {
+               input_report_key(dev, BTN_SIDE, (packet[0] >> 3) & 1);
+               packet[0] |= 0x08;
+       }
+
 /*
  * Generic PS/2 Mouse
  */
@@ -538,6 +548,20 @@ static int ps2bare_detect(struct psmouse *psmouse, int set_properties)
        return 0;
 }
 
+/*
+ * Cortron PS/2 protocol detection. There's no special way to detect it, so it
+ * must be forced by sysfs protocol writing.
+ */
+static int cortron_detect(struct psmouse *psmouse, int set_properties)
+{
+       if (set_properties) {
+               psmouse->vendor = "Cortron";
+               psmouse->name = "PS/2 Trackball";
+               set_bit(BTN_SIDE, psmouse->dev->keybit);
+       }
+
+       return 0;
+}
 
 /*
  * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
@@ -569,7 +593,9 @@ static int psmouse_extensions(struct psmouse *psmouse,
                return PSMOUSE_THINKPS;
 
 /*
- * Try Synaptics TouchPad
+ * Try Synaptics TouchPad. Note that probing is done even if Synaptics protocol
+ * support is disabled in config - we need to know if it is synaptics so we
+ * can reset it properly after probing for intellimouse.
  */
        if (max_proto > PSMOUSE_PS2 && synaptics_detect(psmouse, set_properties) == 0) {
                synaptics_hardware = 1;
@@ -605,14 +631,20 @@ static int psmouse_extensions(struct psmouse *psmouse,
                }
        }
 
-       if (max_proto > PSMOUSE_IMEX && genius_detect(psmouse, set_properties) == 0)
-               return PSMOUSE_GENPS;
+       if (max_proto > PSMOUSE_IMEX) {
+
+               if (genius_detect(psmouse, set_properties) == 0)
+                       return PSMOUSE_GENPS;
+
+               if (ps2pp_init(psmouse, set_properties) == 0)
+                       return PSMOUSE_PS2PP;
 
-       if (max_proto > PSMOUSE_IMEX && ps2pp_init(psmouse, set_properties) == 0)
-               return PSMOUSE_PS2PP;
+               if (trackpoint_detect(psmouse, set_properties) == 0)
+                       return PSMOUSE_TRACKPOINT;
 
-       if (max_proto > PSMOUSE_IMEX && trackpoint_detect(psmouse, set_properties) == 0)
-               return PSMOUSE_TRACKPOINT;
+               if (touchkit_ps2_detect(psmouse, set_properties) == 0)
+                       return PSMOUSE_TOUCHKIT_PS2;
+       }
 
 /*
  * Reset to defaults in case the device got confused by extended
@@ -654,12 +686,14 @@ static const struct psmouse_protocol psmouse_protocols[] = {
                .maxproto       = 1,
                .detect         = ps2bare_detect,
        },
+#ifdef CONFIG_MOUSE_PS2_LOGIPS2PP
        {
                .type           = PSMOUSE_PS2PP,
                .name           = "PS2++",
                .alias          = "logitech",
                .detect         = ps2pp_init,
        },
+#endif
        {
                .type           = PSMOUSE_THINKPS,
                .name           = "ThinkPS/2",
@@ -686,6 +720,7 @@ static const struct psmouse_protocol psmouse_protocols[] = {
                .maxproto       = 1,
                .detect         = im_explorer_detect,
        },
+#ifdef CONFIG_MOUSE_PS2_SYNAPTICS
        {
                .type           = PSMOUSE_SYNAPTICS,
                .name           = "SynPS/2",
@@ -693,6 +728,8 @@ static const struct psmouse_protocol psmouse_protocols[] = {
                .detect         = synaptics_detect,
                .init           = synaptics_init,
        },
+#endif
+#ifdef CONFIG_MOUSE_PS2_ALPS
        {
                .type           = PSMOUSE_ALPS,
                .name           = "AlpsPS/2",
@@ -700,18 +737,37 @@ static const struct psmouse_protocol psmouse_protocols[] = {
                .detect         = alps_detect,
                .init           = alps_init,
        },
+#endif
+#ifdef CONFIG_MOUSE_PS2_LIFEBOOK
        {
                .type           = PSMOUSE_LIFEBOOK,
                .name           = "LBPS/2",
                .alias          = "lifebook",
                .init           = lifebook_init,
        },
+#endif
+#ifdef CONFIG_MOUSE_PS2_TRACKPOINT
        {
                .type           = PSMOUSE_TRACKPOINT,
                .name           = "TPPS/2",
                .alias          = "trackpoint",
                .detect         = trackpoint_detect,
        },
+#endif
+#ifdef CONFIG_MOUSE_PS2_TOUCHKIT
+       {
+               .type           = PSMOUSE_TOUCHKIT_PS2,
+               .name           = "touchkitPS/2",
+               .alias          = "touchkit",
+               .detect         = touchkit_ps2_detect,
+       },
+#endif
+       {
+               .type           = PSMOUSE_CORTRON,
+               .name           = "CortronPS/2",
+               .alias          = "cortps",
+               .detect         = cortron_detect,
+       },
        {
                .type           = PSMOUSE_AUTO,
                .name           = "auto",
@@ -822,12 +878,6 @@ static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate)
 
 static void psmouse_initialize(struct psmouse *psmouse)
 {
-/*
- * We set the mouse into streaming mode.
- */
-
-       ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM);
-
 /*
  * We set the mouse report rate, resolution and scaling.
  */
@@ -1062,8 +1112,7 @@ static int psmouse_switch_protocol(struct psmouse *psmouse, const struct psmouse
 {
        struct input_dev *input_dev = psmouse->dev;
 
-       input_dev->private = psmouse;
-       input_dev->cdev.dev = &psmouse->ps2dev.serio->dev;
+       input_dev->dev.parent = &psmouse->ps2dev.serio->dev;
 
        input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
        input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);