2 * Synaptics TouchPad PS/2 mouse driver
4 * 2003 Dmitry Torokhov <dtor@mail.ru>
5 * Added support for pass-through port. Special thanks to Peter Berg Larsen
6 * for explaining various Synaptics quirks.
8 * 2003 Peter Osterlund <petero2@telia.com>
9 * Ported to 2.5 input device infrastructure.
11 * Copyright (C) 2001 Stefan Gmeiner <riddlebox@freesurf.ch>
12 * start merging tpconfig and gpm code to a xfree-input module
13 * adding some changes and extensions (ex. 3rd and 4th button)
15 * Copyright (c) 1997 C. Scott Ananian <cananian@alumni.priceton.edu>
16 * Copyright (c) 1998-2000 Bruce Kalk <kall@compass.com>
17 * code for the special synaptics commands (from the tpconfig-source)
19 * This program is free software; you can redistribute it and/or modify it
20 * under the terms of the GNU General Public License version 2 as published by
21 * the Free Software Foundation.
23 * Trademarks are the property of their respective owners.
26 #include <linux/module.h>
27 #include <linux/dmi.h>
28 #include <linux/input/mt.h>
29 #include <linux/serio.h>
30 #include <linux/libps2.h>
31 #include <linux/slab.h>
33 #include "synaptics.h"
36 * The x/y limits are taken from the Synaptics TouchPad interfacing Guide,
37 * section 2.3.2, which says that they should be valid regardless of the
38 * actual size of the sensor.
39 * Note that newer firmware allows querying device for maximum useable
42 #define XMIN_NOMINAL 1472
43 #define XMAX_NOMINAL 5472
44 #define YMIN_NOMINAL 1408
45 #define YMAX_NOMINAL 4448
48 * Synaptics touchpads report the y coordinate from bottom to top, which is
49 * opposite from what userspace expects.
50 * This function is used to invert y before reporting.
52 static int synaptics_invert_y(int y)
54 return YMAX_NOMINAL + YMIN_NOMINAL - y;
58 /*****************************************************************************
59 * Stuff we need even when we do not want native Synaptics support
60 ****************************************************************************/
63 * Set the synaptics touchpad mode byte by special commands
65 static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode)
67 unsigned char param[1];
69 if (psmouse_sliced_command(psmouse, mode))
71 param[0] = SYN_PS_SET_MODE2;
72 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE))
77 int synaptics_detect(struct psmouse *psmouse, bool set_properties)
79 struct ps2dev *ps2dev = &psmouse->ps2dev;
80 unsigned char param[4];
84 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
85 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
86 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
87 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
88 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
94 psmouse->vendor = "Synaptics";
95 psmouse->name = "TouchPad";
101 void synaptics_reset(struct psmouse *psmouse)
103 /* reset touchpad back to relative mode, gestures enabled */
104 synaptics_mode_cmd(psmouse, 0);
107 #ifdef CONFIG_MOUSE_PS2_SYNAPTICS
109 /*****************************************************************************
110 * Synaptics communications functions
111 ****************************************************************************/
114 * Send a command to the synpatics touchpad by special commands
116 static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param)
118 if (psmouse_sliced_command(psmouse, c))
120 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO))
126 * Read the model-id bytes from the touchpad
127 * see also SYN_MODEL_* macros
129 static int synaptics_model_id(struct psmouse *psmouse)
131 struct synaptics_data *priv = psmouse->private;
134 if (synaptics_send_cmd(psmouse, SYN_QUE_MODEL, mi))
136 priv->model_id = (mi[0]<<16) | (mi[1]<<8) | mi[2];
141 * Read the capability-bits from the touchpad
142 * see also the SYN_CAP_* macros
144 static int synaptics_capability(struct psmouse *psmouse)
146 struct synaptics_data *priv = psmouse->private;
147 unsigned char cap[3];
149 if (synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap))
151 priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
152 priv->ext_cap = priv->ext_cap_0c = 0;
155 * Older firmwares had submodel ID fixed to 0x47
157 if (SYN_ID_FULL(priv->identity) < 0x705 &&
158 SYN_CAP_SUBMODEL_ID(priv->capabilities) != 0x47) {
163 * Unless capExtended is set the rest of the flags should be ignored
165 if (!SYN_CAP_EXTENDED(priv->capabilities))
166 priv->capabilities = 0;
168 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 1) {
169 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB, cap)) {
170 printk(KERN_ERR "Synaptics claims to have extended capabilities,"
171 " but I'm not able to read them.\n");
173 priv->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
176 * if nExtBtn is greater than 8 it should be considered
177 * invalid and treated as 0
179 if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) > 8)
180 priv->ext_cap &= 0xff0fff;
184 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 4) {
185 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB_0C, cap)) {
186 printk(KERN_ERR "Synaptics claims to have extended capability 0x0c,"
187 " but I'm not able to read it.\n");
189 priv->ext_cap_0c = (cap[0] << 16) | (cap[1] << 8) | cap[2];
198 * See also the SYN_ID_* macros
200 static int synaptics_identify(struct psmouse *psmouse)
202 struct synaptics_data *priv = psmouse->private;
205 if (synaptics_send_cmd(psmouse, SYN_QUE_IDENTIFY, id))
207 priv->identity = (id[0]<<16) | (id[1]<<8) | id[2];
208 if (SYN_ID_IS_SYNAPTICS(priv->identity))
214 * Read touchpad resolution and maximum reported coordinates
215 * Resolution is left zero if touchpad does not support the query
217 static int synaptics_resolution(struct psmouse *psmouse)
219 struct synaptics_data *priv = psmouse->private;
220 unsigned char resp[3];
222 if (SYN_ID_MAJOR(priv->identity) < 4)
225 if (synaptics_send_cmd(psmouse, SYN_QUE_RESOLUTION, resp) == 0) {
226 if (resp[0] != 0 && (resp[1] & 0x80) && resp[2] != 0) {
227 priv->x_res = resp[0]; /* x resolution in units/mm */
228 priv->y_res = resp[2]; /* y resolution in units/mm */
232 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 5 &&
233 SYN_CAP_MAX_DIMENSIONS(priv->ext_cap_0c)) {
234 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_MAX_COORDS, resp)) {
235 printk(KERN_ERR "Synaptics claims to have max coordinates"
236 " query, but I'm not able to read it.\n");
238 priv->x_max = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
239 priv->y_max = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
243 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 7 &&
244 SYN_CAP_MIN_DIMENSIONS(priv->ext_cap_0c)) {
245 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_MIN_COORDS, resp)) {
246 printk(KERN_ERR "Synaptics claims to have min coordinates"
247 " query, but I'm not able to read it.\n");
249 priv->x_min = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
250 priv->y_min = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
257 static int synaptics_query_hardware(struct psmouse *psmouse)
259 if (synaptics_identify(psmouse))
261 if (synaptics_model_id(psmouse))
263 if (synaptics_capability(psmouse))
265 if (synaptics_resolution(psmouse))
271 static int synaptics_set_absolute_mode(struct psmouse *psmouse)
273 struct synaptics_data *priv = psmouse->private;
275 priv->mode = SYN_BIT_ABSOLUTE_MODE;
276 if (SYN_ID_MAJOR(priv->identity) >= 4)
277 priv->mode |= SYN_BIT_DISABLE_GESTURE;
278 if (SYN_CAP_EXTENDED(priv->capabilities))
279 priv->mode |= SYN_BIT_W_MODE;
281 if (synaptics_mode_cmd(psmouse, priv->mode))
287 static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
289 struct synaptics_data *priv = psmouse->private;
292 priv->mode |= SYN_BIT_HIGH_RATE;
295 priv->mode &= ~SYN_BIT_HIGH_RATE;
299 synaptics_mode_cmd(psmouse, priv->mode);
302 static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse)
304 static unsigned char param = 0xc8;
305 struct synaptics_data *priv = psmouse->private;
307 if (!SYN_CAP_ADV_GESTURE(priv->ext_cap_0c))
310 if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL))
312 if (ps2_command(&psmouse->ps2dev, ¶m, PSMOUSE_CMD_SETRATE))
315 /* Advanced gesture mode also sends multi finger data */
316 priv->capabilities |= BIT(1);
321 /*****************************************************************************
322 * Synaptics pass-through PS/2 port support
323 ****************************************************************************/
324 static int synaptics_pt_write(struct serio *serio, unsigned char c)
326 struct psmouse *parent = serio_get_drvdata(serio->parent);
327 char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */
329 if (psmouse_sliced_command(parent, c))
331 if (ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE))
336 static int synaptics_pt_start(struct serio *serio)
338 struct psmouse *parent = serio_get_drvdata(serio->parent);
339 struct synaptics_data *priv = parent->private;
341 serio_pause_rx(parent->ps2dev.serio);
342 priv->pt_port = serio;
343 serio_continue_rx(parent->ps2dev.serio);
348 static void synaptics_pt_stop(struct serio *serio)
350 struct psmouse *parent = serio_get_drvdata(serio->parent);
351 struct synaptics_data *priv = parent->private;
353 serio_pause_rx(parent->ps2dev.serio);
354 priv->pt_port = NULL;
355 serio_continue_rx(parent->ps2dev.serio);
358 static int synaptics_is_pt_packet(unsigned char *buf)
360 return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
363 static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet)
365 struct psmouse *child = serio_get_drvdata(ptport);
367 if (child && child->state == PSMOUSE_ACTIVATED) {
368 serio_interrupt(ptport, packet[1], 0);
369 serio_interrupt(ptport, packet[4], 0);
370 serio_interrupt(ptport, packet[5], 0);
371 if (child->pktsize == 4)
372 serio_interrupt(ptport, packet[2], 0);
374 serio_interrupt(ptport, packet[1], 0);
377 static void synaptics_pt_activate(struct psmouse *psmouse)
379 struct synaptics_data *priv = psmouse->private;
380 struct psmouse *child = serio_get_drvdata(priv->pt_port);
382 /* adjust the touchpad to child's choice of protocol */
384 if (child->pktsize == 4)
385 priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
387 priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
389 if (synaptics_mode_cmd(psmouse, priv->mode))
390 printk(KERN_INFO "synaptics: failed to switch guest protocol\n");
394 static void synaptics_pt_create(struct psmouse *psmouse)
398 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
400 printk(KERN_ERR "synaptics: not enough memory to allocate pass-through port\n");
404 serio->id.type = SERIO_PS_PSTHRU;
405 strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
406 strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name));
407 serio->write = synaptics_pt_write;
408 serio->start = synaptics_pt_start;
409 serio->stop = synaptics_pt_stop;
410 serio->parent = psmouse->ps2dev.serio;
412 psmouse->pt_activate = synaptics_pt_activate;
414 printk(KERN_INFO "serio: %s port at %s\n", serio->name, psmouse->phys);
415 serio_register_port(serio);
418 /*****************************************************************************
419 * Functions to interpret the absolute mode packets
420 ****************************************************************************/
422 static void synaptics_parse_agm(const unsigned char buf[],
423 struct synaptics_data *priv)
425 struct synaptics_hw_state *agm = &priv->agm;
427 /* Gesture packet: (x, y, z) at half resolution */
428 agm->x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
429 agm->y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1;
430 agm->z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
433 static int synaptics_parse_hw_state(const unsigned char buf[],
434 struct synaptics_data *priv,
435 struct synaptics_hw_state *hw)
437 memset(hw, 0, sizeof(struct synaptics_hw_state));
439 if (SYN_MODEL_NEWABS(priv->model_id)) {
440 hw->w = (((buf[0] & 0x30) >> 2) |
441 ((buf[0] & 0x04) >> 1) |
442 ((buf[3] & 0x04) >> 2));
444 hw->left = (buf[0] & 0x01) ? 1 : 0;
445 hw->right = (buf[0] & 0x02) ? 1 : 0;
447 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
449 * Clickpad's button is transmitted as middle button,
450 * however, since it is primary button, we will report
453 hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
455 } else if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
456 hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
458 hw->scroll = (signed char)(buf[1]);
461 if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
462 hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
463 hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
466 if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) && hw->w == 2) {
467 synaptics_parse_agm(buf, priv);
471 hw->x = (((buf[3] & 0x10) << 8) |
472 ((buf[1] & 0x0f) << 8) |
474 hw->y = (((buf[3] & 0x20) << 7) |
475 ((buf[1] & 0xf0) << 4) |
479 if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
480 ((buf[0] ^ buf[3]) & 0x02)) {
481 switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
484 * if nExtBtn is greater than 8 it should be
485 * considered invalid and treated as 0
489 hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0;
490 hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0;
492 hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0;
493 hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0;
495 hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0;
496 hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0;
498 hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0;
499 hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0;
503 hw->x = (((buf[1] & 0x1f) << 8) | buf[2]);
504 hw->y = (((buf[4] & 0x1f) << 8) | buf[5]);
506 hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
507 hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
509 hw->left = (buf[0] & 0x01) ? 1 : 0;
510 hw->right = (buf[0] & 0x02) ? 1 : 0;
516 static void synaptics_report_semi_mt_slot(struct input_dev *dev, int slot,
517 bool active, int x, int y)
519 input_mt_slot(dev, slot);
520 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
522 input_report_abs(dev, ABS_MT_POSITION_X, x);
523 input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(y));
527 static void synaptics_report_semi_mt_data(struct input_dev *dev,
528 const struct synaptics_hw_state *a,
529 const struct synaptics_hw_state *b,
532 if (num_fingers >= 2) {
533 synaptics_report_semi_mt_slot(dev, 0, true, min(a->x, b->x),
535 synaptics_report_semi_mt_slot(dev, 1, true, max(a->x, b->x),
537 } else if (num_fingers == 1) {
538 synaptics_report_semi_mt_slot(dev, 0, true, a->x, a->y);
539 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
541 synaptics_report_semi_mt_slot(dev, 0, false, 0, 0);
542 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
547 * called for each full received packet from the touchpad
549 static void synaptics_process_packet(struct psmouse *psmouse)
551 struct input_dev *dev = psmouse->dev;
552 struct synaptics_data *priv = psmouse->private;
553 struct synaptics_hw_state hw;
558 if (synaptics_parse_hw_state(psmouse->packet, priv, &hw))
562 priv->scroll += hw.scroll;
564 while (priv->scroll >= 4) {
565 input_report_key(dev, BTN_BACK, !hw.down);
567 input_report_key(dev, BTN_BACK, hw.down);
571 while (priv->scroll <= -4) {
572 input_report_key(dev, BTN_FORWARD, !hw.up);
574 input_report_key(dev, BTN_FORWARD, hw.up);
581 if (hw.z > 0 && hw.x > 1) {
584 if (SYN_CAP_EXTENDED(priv->capabilities)) {
587 if (SYN_CAP_MULTIFINGER(priv->capabilities))
588 num_fingers = hw.w + 2;
591 if (SYN_MODEL_PEN(priv->model_id))
592 ; /* Nothing, treat a pen as a single finger */
595 if (SYN_CAP_PALMDETECT(priv->capabilities))
605 if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c))
606 synaptics_report_semi_mt_data(dev, &hw, &priv->agm,
610 * BTN_TOUCH has to be first as mousedev relies on it when doing
611 * absolute -> relative conversion
613 if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1);
614 if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0);
616 if (num_fingers > 0) {
617 input_report_abs(dev, ABS_X, hw.x);
618 input_report_abs(dev, ABS_Y, synaptics_invert_y(hw.y));
620 input_report_abs(dev, ABS_PRESSURE, hw.z);
622 if (SYN_CAP_PALMDETECT(priv->capabilities))
623 input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
625 input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
626 input_report_key(dev, BTN_LEFT, hw.left);
627 input_report_key(dev, BTN_RIGHT, hw.right);
629 if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
630 input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
631 input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
634 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
635 input_report_key(dev, BTN_MIDDLE, hw.middle);
637 if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
638 input_report_key(dev, BTN_FORWARD, hw.up);
639 input_report_key(dev, BTN_BACK, hw.down);
642 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
643 input_report_key(dev, BTN_0 + i, hw.ext_buttons & (1 << i));
648 static int synaptics_validate_byte(unsigned char packet[], int idx, unsigned char pkt_type)
650 static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
651 static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
652 static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
653 static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
654 static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
656 if (idx < 0 || idx > 4)
662 case SYN_NEWABS_RELAXED:
663 return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx];
665 case SYN_NEWABS_STRICT:
666 return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx];
669 return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx];
672 printk(KERN_ERR "synaptics: unknown packet type %d\n", pkt_type);
677 static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse)
681 for (i = 0; i < 5; i++)
682 if (!synaptics_validate_byte(psmouse->packet, i, SYN_NEWABS_STRICT)) {
683 printk(KERN_INFO "synaptics: using relaxed packet validation\n");
684 return SYN_NEWABS_RELAXED;
687 return SYN_NEWABS_STRICT;
690 static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
692 struct synaptics_data *priv = psmouse->private;
694 if (psmouse->pktcnt >= 6) { /* Full packet received */
695 if (unlikely(priv->pkt_type == SYN_NEWABS))
696 priv->pkt_type = synaptics_detect_pkt_type(psmouse);
698 if (SYN_CAP_PASS_THROUGH(priv->capabilities) &&
699 synaptics_is_pt_packet(psmouse->packet)) {
701 synaptics_pass_pt_packet(priv->pt_port, psmouse->packet);
703 synaptics_process_packet(psmouse);
705 return PSMOUSE_FULL_PACKET;
708 return synaptics_validate_byte(psmouse->packet, psmouse->pktcnt - 1, priv->pkt_type) ?
709 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
712 /*****************************************************************************
713 * Driver initialization/cleanup functions
714 ****************************************************************************/
715 static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
718 int fuzz = SYN_CAP_REDUCED_FILTERING(priv->ext_cap_0c) ?
719 SYN_REDUCED_FILTER_FUZZ : 0;
721 __set_bit(INPUT_PROP_POINTER, dev->propbit);
723 __set_bit(EV_ABS, dev->evbit);
724 input_set_abs_params(dev, ABS_X,
725 priv->x_min ?: XMIN_NOMINAL,
726 priv->x_max ?: XMAX_NOMINAL,
728 input_set_abs_params(dev, ABS_Y,
729 priv->y_min ?: YMIN_NOMINAL,
730 priv->y_max ?: YMAX_NOMINAL,
732 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
734 if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) {
735 __set_bit(INPUT_PROP_SEMI_MT, dev->propbit);
736 input_mt_init_slots(dev, 2);
737 input_set_abs_params(dev, ABS_MT_POSITION_X,
738 priv->x_min ?: XMIN_NOMINAL,
739 priv->x_max ?: XMAX_NOMINAL,
741 input_set_abs_params(dev, ABS_MT_POSITION_Y,
742 priv->y_min ?: YMIN_NOMINAL,
743 priv->y_max ?: YMAX_NOMINAL,
746 input_abs_set_res(dev, ABS_MT_POSITION_X, priv->x_res);
747 input_abs_set_res(dev, ABS_MT_POSITION_Y, priv->y_res);
750 if (SYN_CAP_PALMDETECT(priv->capabilities))
751 input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
753 __set_bit(EV_KEY, dev->evbit);
754 __set_bit(BTN_TOUCH, dev->keybit);
755 __set_bit(BTN_TOOL_FINGER, dev->keybit);
756 __set_bit(BTN_LEFT, dev->keybit);
757 __set_bit(BTN_RIGHT, dev->keybit);
759 if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
760 __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
761 __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
764 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
765 __set_bit(BTN_MIDDLE, dev->keybit);
767 if (SYN_CAP_FOUR_BUTTON(priv->capabilities) ||
768 SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
769 __set_bit(BTN_FORWARD, dev->keybit);
770 __set_bit(BTN_BACK, dev->keybit);
773 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
774 __set_bit(BTN_0 + i, dev->keybit);
776 __clear_bit(EV_REL, dev->evbit);
777 __clear_bit(REL_X, dev->relbit);
778 __clear_bit(REL_Y, dev->relbit);
780 input_abs_set_res(dev, ABS_X, priv->x_res);
781 input_abs_set_res(dev, ABS_Y, priv->y_res);
783 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
784 __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
785 /* Clickpads report only left button */
786 __clear_bit(BTN_RIGHT, dev->keybit);
787 __clear_bit(BTN_MIDDLE, dev->keybit);
791 static void synaptics_disconnect(struct psmouse *psmouse)
793 synaptics_reset(psmouse);
794 kfree(psmouse->private);
795 psmouse->private = NULL;
798 static int synaptics_reconnect(struct psmouse *psmouse)
800 struct synaptics_data *priv = psmouse->private;
801 struct synaptics_data old_priv = *priv;
806 psmouse_reset(psmouse);
807 error = synaptics_detect(psmouse, 0);
808 } while (error && ++retry < 3);
814 printk(KERN_DEBUG "Synaptics reconnected after %d tries\n",
817 if (synaptics_query_hardware(psmouse)) {
818 printk(KERN_ERR "Unable to query Synaptics hardware.\n");
822 if (synaptics_set_absolute_mode(psmouse)) {
823 printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
827 if (synaptics_set_advanced_gesture_mode(psmouse)) {
828 printk(KERN_ERR "Advanced gesture mode reconnect failed.\n");
832 if (old_priv.identity != priv->identity ||
833 old_priv.model_id != priv->model_id ||
834 old_priv.capabilities != priv->capabilities ||
835 old_priv.ext_cap != priv->ext_cap) {
836 printk(KERN_ERR "Synaptics hardware appears to be different: "
837 "id(%ld-%ld), model(%ld-%ld), caps(%lx-%lx), ext(%lx-%lx).\n",
838 old_priv.identity, priv->identity,
839 old_priv.model_id, priv->model_id,
840 old_priv.capabilities, priv->capabilities,
841 old_priv.ext_cap, priv->ext_cap);
848 static bool impaired_toshiba_kbc;
850 static const struct dmi_system_id __initconst toshiba_dmi_table[] = {
851 #if defined(CONFIG_DMI) && defined(CONFIG_X86)
853 /* Toshiba Satellite */
855 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
856 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
860 /* Toshiba Dynabook */
862 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
863 DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
867 /* Toshiba Portege M300 */
869 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
870 DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
875 /* Toshiba Portege M300 */
877 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
878 DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
879 DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
887 static bool broken_olpc_ec;
889 static const struct dmi_system_id __initconst olpc_dmi_table[] = {
890 #if defined(CONFIG_DMI) && defined(CONFIG_OLPC)
892 /* OLPC XO-1 or XO-1.5 */
894 DMI_MATCH(DMI_SYS_VENDOR, "OLPC"),
895 DMI_MATCH(DMI_PRODUCT_NAME, "XO"),
902 void __init synaptics_module_init(void)
904 impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
905 broken_olpc_ec = dmi_check_system(olpc_dmi_table);
908 int synaptics_init(struct psmouse *psmouse)
910 struct synaptics_data *priv;
913 * The OLPC XO has issues with Synaptics' absolute mode; similarly to
914 * the HGPK, it quickly degrades and the hardware becomes jumpy and
915 * overly sensitive. Not only that, but the constant packet spew
916 * (even at a lowered 40pps rate) overloads the EC such that key
917 * presses on the keyboard are missed. Given all of that, don't
918 * even attempt to use Synaptics mode. Relative mode seems to work
921 if (broken_olpc_ec) {
922 printk(KERN_INFO "synaptics: OLPC XO detected, not enabling Synaptics protocol.\n");
926 psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
930 psmouse_reset(psmouse);
932 if (synaptics_query_hardware(psmouse)) {
933 printk(KERN_ERR "Unable to query Synaptics hardware.\n");
937 if (synaptics_set_absolute_mode(psmouse)) {
938 printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
942 if (synaptics_set_advanced_gesture_mode(psmouse)) {
943 printk(KERN_ERR "Advanced gesture mode init failed.\n");
947 priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS;
949 printk(KERN_INFO "Synaptics Touchpad, model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx\n",
950 SYN_ID_MODEL(priv->identity),
951 SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity),
952 priv->model_id, priv->capabilities, priv->ext_cap, priv->ext_cap_0c);
954 set_input_params(psmouse->dev, priv);
957 * Encode touchpad model so that it can be used to set
958 * input device->id.version and be visible to userspace.
959 * Because version is __u16 we have to drop something.
960 * Hardware info bits seem to be good candidates as they
961 * are documented to be for Synaptics corp. internal use.
963 psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) |
964 (priv->model_id & 0x000000ff);
966 psmouse->protocol_handler = synaptics_process_byte;
967 psmouse->set_rate = synaptics_set_rate;
968 psmouse->disconnect = synaptics_disconnect;
969 psmouse->reconnect = synaptics_reconnect;
970 psmouse->cleanup = synaptics_reset;
971 psmouse->pktsize = 6;
972 /* Synaptics can usually stay in sync without extra help */
973 psmouse->resync_time = 0;
975 if (SYN_CAP_PASS_THROUGH(priv->capabilities))
976 synaptics_pt_create(psmouse);
979 * Toshiba's KBC seems to have trouble handling data from
980 * Synaptics at full rate. Switch to a lower rate (roughly
981 * the same rate as a standard PS/2 mouse).
983 if (psmouse->rate >= 80 && impaired_toshiba_kbc) {
984 printk(KERN_INFO "synaptics: Toshiba %s detected, limiting rate to 40pps.\n",
985 dmi_get_system_info(DMI_PRODUCT_NAME));
996 bool synaptics_supported(void)
1001 #else /* CONFIG_MOUSE_PS2_SYNAPTICS */
1003 void __init synaptics_module_init(void)
1007 int synaptics_init(struct psmouse *psmouse)
1012 bool synaptics_supported(void)
1017 #endif /* CONFIG_MOUSE_PS2_SYNAPTICS */