Input: psmouse - use boolean type
[linux-2.6.git] / drivers / input / mouse / synaptics.c
index 36c7212..b66ff1a 100644 (file)
 #define YMIN_NOMINAL 1408
 #define YMAX_NOMINAL 4448
 
+
 /*****************************************************************************
- *     Synaptics communications functions
+ *     Stuff we need even when we do not want native Synaptics support
  ****************************************************************************/
 
 /*
- * Send a command to the synpatics touchpad by special commands
+ * Set the synaptics touchpad mode byte by special commands
  */
-static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param)
+static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode)
 {
-       if (psmouse_sliced_command(psmouse, c))
+       unsigned char param[1];
+
+       if (psmouse_sliced_command(psmouse, mode))
                return -1;
-       if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO))
+       param[0] = SYN_PS_SET_MODE2;
+       if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE))
                return -1;
        return 0;
 }
 
+int synaptics_detect(struct psmouse *psmouse, bool set_properties)
+{
+       struct ps2dev *ps2dev = &psmouse->ps2dev;
+       unsigned char param[4];
+
+       param[0] = 0;
+
+       ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+       ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+       ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+       ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+       ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
+
+       if (param[1] != 0x47)
+               return -ENODEV;
+
+       if (set_properties) {
+               psmouse->vendor = "Synaptics";
+               psmouse->name = "TouchPad";
+       }
+
+       return 0;
+}
+
+void synaptics_reset(struct psmouse *psmouse)
+{
+       /* reset touchpad back to relative mode, gestures enabled */
+       synaptics_mode_cmd(psmouse, 0);
+}
+
+#ifdef CONFIG_MOUSE_PS2_SYNAPTICS
+
+/*****************************************************************************
+ *     Synaptics communications functions
+ ****************************************************************************/
+
 /*
- * Set the synaptics touchpad mode byte by special commands
+ * Send a command to the synpatics touchpad by special commands
  */
-static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode)
+static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param)
 {
-       unsigned char param[1];
-
-       if (psmouse_sliced_command(psmouse, mode))
+       if (psmouse_sliced_command(psmouse, c))
                return -1;
-       param[0] = SYN_PS_SET_MODE2;
-       if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE))
+       if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO))
                return -1;
        return 0;
 }
@@ -143,19 +180,39 @@ static int synaptics_identify(struct psmouse *psmouse)
        return -1;
 }
 
-static int synaptics_query_hardware(struct psmouse *psmouse)
+/*
+ * Read touchpad resolution
+ * Resolution is left zero if touchpad does not support the query
+ */
+static int synaptics_resolution(struct psmouse *psmouse)
 {
-       int retries = 0;
+       struct synaptics_data *priv = psmouse->private;
+       unsigned char res[3];
+
+       if (SYN_ID_MAJOR(priv->identity) < 4)
+               return 0;
 
-       while ((retries++ < 3) && psmouse_reset(psmouse))
-               printk(KERN_ERR "synaptics reset failed\n");
+       if (synaptics_send_cmd(psmouse, SYN_QUE_RESOLUTION, res))
+               return 0;
+
+       if ((res[0] != 0) && (res[1] & 0x80) && (res[2] != 0)) {
+               priv->x_res = res[0]; /* x resolution in units/mm */
+               priv->y_res = res[2]; /* y resolution in units/mm */
+       }
+
+       return 0;
+}
 
+static int synaptics_query_hardware(struct psmouse *psmouse)
+{
        if (synaptics_identify(psmouse))
                return -1;
        if (synaptics_model_id(psmouse))
                return -1;
        if (synaptics_capability(psmouse))
                return -1;
+       if (synaptics_resolution(psmouse))
+               return -1;
 
        return 0;
 }
@@ -216,13 +273,13 @@ static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet
        struct psmouse *child = serio_get_drvdata(ptport);
 
        if (child && child->state == PSMOUSE_ACTIVATED) {
-               serio_interrupt(ptport, packet[1], 0, NULL);
-               serio_interrupt(ptport, packet[4], 0, NULL);
-               serio_interrupt(ptport, packet[5], 0, NULL);
-               if (child->type >= PSMOUSE_GENPS)
-                       serio_interrupt(ptport, packet[2], 0, NULL);
+               serio_interrupt(ptport, packet[1], 0);
+               serio_interrupt(ptport, packet[4], 0);
+               serio_interrupt(ptport, packet[5], 0);
+               if (child->pktsize == 4)
+                       serio_interrupt(ptport, packet[2], 0);
        } else
-               serio_interrupt(ptport, packet[1], 0, NULL);
+               serio_interrupt(ptport, packet[1], 0);
 }
 
 static void synaptics_pt_activate(struct psmouse *psmouse)
@@ -233,7 +290,7 @@ static void synaptics_pt_activate(struct psmouse *psmouse)
 
        /* adjust the touchpad to child's choice of protocol */
        if (child) {
-               if (child->type >= PSMOUSE_GENPS)
+               if (child->pktsize == 4)
                        priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
                else
                        priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
@@ -247,14 +304,12 @@ static void synaptics_pt_create(struct psmouse *psmouse)
 {
        struct serio *serio;
 
-       serio = kmalloc(sizeof(struct serio), GFP_KERNEL);
+       serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
        if (!serio) {
                printk(KERN_ERR "synaptics: not enough memory to allocate pass-through port\n");
                return;
        }
 
-       memset(serio, 0, sizeof(struct serio));
-
        serio->id.type = SERIO_PS_PSTHRU;
        strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
        strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name));
@@ -342,7 +397,7 @@ static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data
  */
 static void synaptics_process_packet(struct psmouse *psmouse)
 {
-       struct input_dev *dev = &psmouse->dev;
+       struct input_dev *dev = psmouse->dev;
        struct synaptics_data *priv = psmouse->private;
        struct synaptics_hw_state hw;
        int num_fingers;
@@ -410,12 +465,14 @@ static void synaptics_process_packet(struct psmouse *psmouse)
 
        input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
        input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
-       input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
-       input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
-
        input_report_key(dev, BTN_LEFT, hw.left);
        input_report_key(dev, BTN_RIGHT, hw.right);
 
+       if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
+               input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
+               input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
+       }
+
        if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
                input_report_key(dev, BTN_MIDDLE, hw.middle);
 
@@ -432,11 +489,11 @@ static void synaptics_process_packet(struct psmouse *psmouse)
 
 static int synaptics_validate_byte(unsigned char packet[], int idx, unsigned char pkt_type)
 {
-       static unsigned char newabs_mask[]      = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
-       static unsigned char newabs_rel_mask[]  = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
-       static unsigned char newabs_rslt[]      = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
-       static unsigned char oldabs_mask[]      = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
-       static unsigned char oldabs_rslt[]      = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
+       static const unsigned char newabs_mask[]        = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
+       static const unsigned char newabs_rel_mask[]    = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
+       static const unsigned char newabs_rslt[]        = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
+       static const unsigned char oldabs_mask[]        = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
+       static const unsigned char oldabs_rslt[]        = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
 
        if (idx < 0 || idx > 4)
                return 0;
@@ -471,13 +528,10 @@ static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse)
        return SYN_NEWABS_STRICT;
 }
 
-static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
+static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
 {
-       struct input_dev *dev = &psmouse->dev;
        struct synaptics_data *priv = psmouse->private;
 
-       input_regs(dev, regs);
-
        if (psmouse->pktcnt >= 6) { /* Full packet received */
                if (unlikely(priv->pkt_type == SYN_NEWABS))
                        priv->pkt_type = synaptics_detect_pkt_type(psmouse);
@@ -502,42 +556,41 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
 {
        int i;
 
-       set_bit(EV_ABS, dev->evbit);
+       __set_bit(EV_ABS, dev->evbit);
        input_set_abs_params(dev, ABS_X, XMIN_NOMINAL, XMAX_NOMINAL, 0, 0);
        input_set_abs_params(dev, ABS_Y, YMIN_NOMINAL, YMAX_NOMINAL, 0, 0);
        input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
-       set_bit(ABS_TOOL_WIDTH, dev->absbit);
+       __set_bit(ABS_TOOL_WIDTH, dev->absbit);
 
-       set_bit(EV_KEY, dev->evbit);
-       set_bit(BTN_TOUCH, dev->keybit);
-       set_bit(BTN_TOOL_FINGER, dev->keybit);
-       set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
-       set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
+       __set_bit(EV_KEY, dev->evbit);
+       __set_bit(BTN_TOUCH, dev->keybit);
+       __set_bit(BTN_TOOL_FINGER, dev->keybit);
+       __set_bit(BTN_LEFT, dev->keybit);
+       __set_bit(BTN_RIGHT, dev->keybit);
 
-       set_bit(BTN_LEFT, dev->keybit);
-       set_bit(BTN_RIGHT, dev->keybit);
+       if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
+               __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
+               __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
+       }
 
        if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
-               set_bit(BTN_MIDDLE, dev->keybit);
+               __set_bit(BTN_MIDDLE, dev->keybit);
 
        if (SYN_CAP_FOUR_BUTTON(priv->capabilities) ||
            SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
-               set_bit(BTN_FORWARD, dev->keybit);
-               set_bit(BTN_BACK, dev->keybit);
+               __set_bit(BTN_FORWARD, dev->keybit);
+               __set_bit(BTN_BACK, dev->keybit);
        }
 
        for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
-               set_bit(BTN_0 + i, dev->keybit);
+               __set_bit(BTN_0 + i, dev->keybit);
 
-       clear_bit(EV_REL, dev->evbit);
-       clear_bit(REL_X, dev->relbit);
-       clear_bit(REL_Y, dev->relbit);
-}
+       __clear_bit(EV_REL, dev->evbit);
+       __clear_bit(REL_X, dev->relbit);
+       __clear_bit(REL_Y, dev->relbit);
 
-void synaptics_reset(struct psmouse *psmouse)
-{
-       /* reset touchpad back to relative mode, gestures enabled */
-       synaptics_mode_cmd(psmouse, 0);
+       dev->absres[ABS_X] = priv->x_res;
+       dev->absres[ABS_Y] = priv->y_res;
 }
 
 static void synaptics_disconnect(struct psmouse *psmouse)
@@ -552,6 +605,8 @@ static int synaptics_reconnect(struct psmouse *psmouse)
        struct synaptics_data *priv = psmouse->private;
        struct synaptics_data old_priv = *priv;
 
+       psmouse_reset(psmouse);
+
        if (synaptics_detect(psmouse, 0))
                return -1;
 
@@ -574,38 +629,28 @@ static int synaptics_reconnect(struct psmouse *psmouse)
        return 0;
 }
 
-int synaptics_detect(struct psmouse *psmouse, int set_properties)
-{
-       struct ps2dev *ps2dev = &psmouse->ps2dev;
-       unsigned char param[4];
-
-       param[0] = 0;
-
-       ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
-       ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
-       ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
-       ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
-       ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
-
-       if (param[1] != 0x47)
-               return -1;
-
-       if (set_properties) {
-               psmouse->vendor = "Synaptics";
-               psmouse->name = "TouchPad";
-       }
-
-       return 0;
-}
-
 #if defined(__i386__)
 #include <linux/dmi.h>
-static struct dmi_system_id toshiba_dmi_table[] = {
+static const struct dmi_system_id toshiba_dmi_table[] = {
        {
                .ident = "Toshiba Satellite",
                .matches = {
                        DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
-                       DMI_MATCH(DMI_PRODUCT_NAME , "Satellite"),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
+               },
+       },
+       {
+               .ident = "Toshiba Dynabook",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
+               },
+       },
+       {
+               .ident = "Toshiba Portege M300",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
                },
        },
        { }
@@ -616,10 +661,11 @@ int synaptics_init(struct psmouse *psmouse)
 {
        struct synaptics_data *priv;
 
-       psmouse->private = priv = kmalloc(sizeof(struct synaptics_data), GFP_KERNEL);
+       psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
        if (!priv)
                return -1;
-       memset(priv, 0, sizeof(struct synaptics_data));
+
+       psmouse_reset(psmouse);
 
        if (synaptics_query_hardware(psmouse)) {
                printk(KERN_ERR "Unable to query Synaptics hardware.\n");
@@ -638,13 +684,26 @@ int synaptics_init(struct psmouse *psmouse)
                SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity),
                priv->model_id, priv->capabilities, priv->ext_cap);
 
-       set_input_params(&psmouse->dev, priv);
+       set_input_params(psmouse->dev, priv);
+
+       /*
+        * Encode touchpad model so that it can be used to set
+        * input device->id.version and be visible to userspace.
+        * Because version is __u16 we have to drop something.
+        * Hardware info bits seem to be good candidates as they
+        * are documented to be for Synaptics corp. internal use.
+        */
+       psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) |
+                         (priv->model_id & 0x000000ff);
 
        psmouse->protocol_handler = synaptics_process_byte;
        psmouse->set_rate = synaptics_set_rate;
        psmouse->disconnect = synaptics_disconnect;
        psmouse->reconnect = synaptics_reconnect;
+       psmouse->cleanup = synaptics_reset;
        psmouse->pktsize = 6;
+       /* Synaptics can usually stay in sync without extra help */
+       psmouse->resync_time = 0;
 
        if (SYN_CAP_PASS_THROUGH(priv->capabilities))
                synaptics_pt_create(psmouse);
@@ -656,7 +715,8 @@ int synaptics_init(struct psmouse *psmouse)
         * thye same as rate of standard PS/2 mouse.
         */
        if (psmouse->rate >= 80 && dmi_check_system(toshiba_dmi_table)) {
-               printk(KERN_INFO "synaptics: Toshiba Satellite detected, limiting rate to 40pps.\n");
+               printk(KERN_INFO "synaptics: Toshiba %s detected, limiting rate to 40pps.\n",
+                       dmi_get_system_info(DMI_PRODUCT_NAME));
                psmouse->rate = 40;
        }
 #endif
@@ -668,4 +728,12 @@ int synaptics_init(struct psmouse *psmouse)
        return -1;
 }
 
+#else /* CONFIG_MOUSE_PS2_SYNAPTICS */
+
+int synaptics_init(struct psmouse *psmouse)
+{
+       return -ENOSYS;
+}
+
+#endif /* CONFIG_MOUSE_PS2_SYNAPTICS */