]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/input/mouse/synaptics.c
Input: elantech - relax signature checks
[mirror_ubuntu-artful-kernel.git] / drivers / input / mouse / synaptics.c
CommitLineData
1da177e4
LT
1/*
2 * Synaptics TouchPad PS/2 mouse driver
3 *
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.
7 *
8 * 2003 Peter Osterlund <petero2@telia.com>
9 * Ported to 2.5 input device infrastructure.
10 *
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)
14 *
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)
18 *
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.
22 *
23 * Trademarks are the property of their respective owners.
24 */
25
26#include <linux/module.h>
7705d548 27#include <linux/dmi.h>
1da177e4
LT
28#include <linux/input.h>
29#include <linux/serio.h>
30#include <linux/libps2.h>
5a0e3ad6 31#include <linux/slab.h>
1da177e4
LT
32#include "psmouse.h"
33#include "synaptics.h"
34
35/*
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 */
40#define XMIN_NOMINAL 1472
41#define XMAX_NOMINAL 5472
42#define YMIN_NOMINAL 1408
43#define YMAX_NOMINAL 4448
44
55e3d922 45
1da177e4 46/*****************************************************************************
55e3d922 47 * Stuff we need even when we do not want native Synaptics support
1da177e4
LT
48 ****************************************************************************/
49
50/*
55e3d922 51 * Set the synaptics touchpad mode byte by special commands
1da177e4 52 */
55e3d922 53static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode)
1da177e4 54{
55e3d922
AS
55 unsigned char param[1];
56
57 if (psmouse_sliced_command(psmouse, mode))
1da177e4 58 return -1;
55e3d922
AS
59 param[0] = SYN_PS_SET_MODE2;
60 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE))
1da177e4
LT
61 return -1;
62 return 0;
63}
64
b7802c5c 65int synaptics_detect(struct psmouse *psmouse, bool set_properties)
55e3d922
AS
66{
67 struct ps2dev *ps2dev = &psmouse->ps2dev;
68 unsigned char param[4];
69
70 param[0] = 0;
71
72 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
73 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
74 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
75 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
76 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
77
78 if (param[1] != 0x47)
79 return -ENODEV;
80
81 if (set_properties) {
82 psmouse->vendor = "Synaptics";
83 psmouse->name = "TouchPad";
84 }
85
86 return 0;
87}
88
89void synaptics_reset(struct psmouse *psmouse)
90{
91 /* reset touchpad back to relative mode, gestures enabled */
92 synaptics_mode_cmd(psmouse, 0);
93}
94
95#ifdef CONFIG_MOUSE_PS2_SYNAPTICS
96
97/*****************************************************************************
98 * Synaptics communications functions
99 ****************************************************************************/
100
1da177e4 101/*
55e3d922 102 * Send a command to the synpatics touchpad by special commands
1da177e4 103 */
55e3d922 104static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param)
1da177e4 105{
55e3d922 106 if (psmouse_sliced_command(psmouse, c))
1da177e4 107 return -1;
55e3d922 108 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO))
1da177e4
LT
109 return -1;
110 return 0;
111}
112
113/*
114 * Read the model-id bytes from the touchpad
115 * see also SYN_MODEL_* macros
116 */
117static int synaptics_model_id(struct psmouse *psmouse)
118{
119 struct synaptics_data *priv = psmouse->private;
120 unsigned char mi[3];
121
122 if (synaptics_send_cmd(psmouse, SYN_QUE_MODEL, mi))
123 return -1;
124 priv->model_id = (mi[0]<<16) | (mi[1]<<8) | mi[2];
125 return 0;
126}
127
128/*
129 * Read the capability-bits from the touchpad
130 * see also the SYN_CAP_* macros
131 */
132static int synaptics_capability(struct psmouse *psmouse)
133{
134 struct synaptics_data *priv = psmouse->private;
135 unsigned char cap[3];
136
137 if (synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap))
138 return -1;
139 priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
5f57d67d
TI
140 priv->ext_cap = priv->ext_cap_0c = 0;
141
1da177e4
LT
142 if (!SYN_CAP_VALID(priv->capabilities))
143 return -1;
144
145 /*
146 * Unless capExtended is set the rest of the flags should be ignored
147 */
148 if (!SYN_CAP_EXTENDED(priv->capabilities))
149 priv->capabilities = 0;
150
151 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 1) {
152 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB, cap)) {
153 printk(KERN_ERR "Synaptics claims to have extended capabilities,"
5f57d67d 154 " but I'm not able to read them.\n");
1da177e4
LT
155 } else {
156 priv->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
157
158 /*
159 * if nExtBtn is greater than 8 it should be considered
160 * invalid and treated as 0
161 */
162 if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) > 8)
163 priv->ext_cap &= 0xff0fff;
164 }
165 }
5f57d67d
TI
166
167 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 4) {
168 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB_0C, cap)) {
169 printk(KERN_ERR "Synaptics claims to have extended capability 0x0c,"
170 " but I'm not able to read it.\n");
171 } else {
172 priv->ext_cap_0c = (cap[0] << 16) | (cap[1] << 8) | cap[2];
173 }
174 }
175
1da177e4
LT
176 return 0;
177}
178
179/*
180 * Identify Touchpad
181 * See also the SYN_ID_* macros
182 */
183static int synaptics_identify(struct psmouse *psmouse)
184{
185 struct synaptics_data *priv = psmouse->private;
186 unsigned char id[3];
187
188 if (synaptics_send_cmd(psmouse, SYN_QUE_IDENTIFY, id))
189 return -1;
190 priv->identity = (id[0]<<16) | (id[1]<<8) | id[2];
191 if (SYN_ID_IS_SYNAPTICS(priv->identity))
192 return 0;
193 return -1;
194}
195
ec20a022
TS
196/*
197 * Read touchpad resolution
198 * Resolution is left zero if touchpad does not support the query
199 */
200static int synaptics_resolution(struct psmouse *psmouse)
201{
202 struct synaptics_data *priv = psmouse->private;
203 unsigned char res[3];
204
205 if (SYN_ID_MAJOR(priv->identity) < 4)
206 return 0;
207
208 if (synaptics_send_cmd(psmouse, SYN_QUE_RESOLUTION, res))
209 return 0;
210
211 if ((res[0] != 0) && (res[1] & 0x80) && (res[2] != 0)) {
212 priv->x_res = res[0]; /* x resolution in units/mm */
213 priv->y_res = res[2]; /* y resolution in units/mm */
214 }
215
216 return 0;
217}
218
1da177e4
LT
219static int synaptics_query_hardware(struct psmouse *psmouse)
220{
1da177e4
LT
221 if (synaptics_identify(psmouse))
222 return -1;
223 if (synaptics_model_id(psmouse))
224 return -1;
225 if (synaptics_capability(psmouse))
226 return -1;
ec20a022
TS
227 if (synaptics_resolution(psmouse))
228 return -1;
1da177e4
LT
229
230 return 0;
231}
232
233static int synaptics_set_absolute_mode(struct psmouse *psmouse)
234{
235 struct synaptics_data *priv = psmouse->private;
236
237 priv->mode = SYN_BIT_ABSOLUTE_MODE;
238 if (SYN_ID_MAJOR(priv->identity) >= 4)
239 priv->mode |= SYN_BIT_DISABLE_GESTURE;
240 if (SYN_CAP_EXTENDED(priv->capabilities))
241 priv->mode |= SYN_BIT_W_MODE;
242
243 if (synaptics_mode_cmd(psmouse, priv->mode))
244 return -1;
245
246 return 0;
247}
248
249static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
250{
251 struct synaptics_data *priv = psmouse->private;
252
253 if (rate >= 80) {
254 priv->mode |= SYN_BIT_HIGH_RATE;
255 psmouse->rate = 80;
256 } else {
257 priv->mode &= ~SYN_BIT_HIGH_RATE;
258 psmouse->rate = 40;
259 }
260
261 synaptics_mode_cmd(psmouse, priv->mode);
262}
263
264/*****************************************************************************
265 * Synaptics pass-through PS/2 port support
266 ****************************************************************************/
267static int synaptics_pt_write(struct serio *serio, unsigned char c)
268{
269 struct psmouse *parent = serio_get_drvdata(serio->parent);
270 char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */
271
272 if (psmouse_sliced_command(parent, c))
273 return -1;
274 if (ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE))
275 return -1;
276 return 0;
277}
278
279static inline int synaptics_is_pt_packet(unsigned char *buf)
280{
281 return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
282}
283
284static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet)
285{
286 struct psmouse *child = serio_get_drvdata(ptport);
287
288 if (child && child->state == PSMOUSE_ACTIVATED) {
7d12e780
DH
289 serio_interrupt(ptport, packet[1], 0);
290 serio_interrupt(ptport, packet[4], 0);
291 serio_interrupt(ptport, packet[5], 0);
33fdfa97 292 if (child->pktsize == 4)
7d12e780 293 serio_interrupt(ptport, packet[2], 0);
1da177e4 294 } else
7d12e780 295 serio_interrupt(ptport, packet[1], 0);
1da177e4
LT
296}
297
298static void synaptics_pt_activate(struct psmouse *psmouse)
299{
300 struct serio *ptport = psmouse->ps2dev.serio->child;
301 struct psmouse *child = serio_get_drvdata(ptport);
302 struct synaptics_data *priv = psmouse->private;
303
304 /* adjust the touchpad to child's choice of protocol */
305 if (child) {
33fdfa97 306 if (child->pktsize == 4)
1da177e4
LT
307 priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
308 else
309 priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
310
311 if (synaptics_mode_cmd(psmouse, priv->mode))
312 printk(KERN_INFO "synaptics: failed to switch guest protocol\n");
313 }
314}
315
316static void synaptics_pt_create(struct psmouse *psmouse)
317{
318 struct serio *serio;
319
b39787a9 320 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
1da177e4
LT
321 if (!serio) {
322 printk(KERN_ERR "synaptics: not enough memory to allocate pass-through port\n");
323 return;
324 }
325
1da177e4
LT
326 serio->id.type = SERIO_PS_PSTHRU;
327 strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
328 strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name));
329 serio->write = synaptics_pt_write;
330 serio->parent = psmouse->ps2dev.serio;
331
332 psmouse->pt_activate = synaptics_pt_activate;
333
334 printk(KERN_INFO "serio: %s port at %s\n", serio->name, psmouse->phys);
335 serio_register_port(serio);
336}
337
338/*****************************************************************************
339 * Functions to interpret the absolute mode packets
340 ****************************************************************************/
341
342static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data *priv, struct synaptics_hw_state *hw)
343{
344 memset(hw, 0, sizeof(struct synaptics_hw_state));
345
346 if (SYN_MODEL_NEWABS(priv->model_id)) {
347 hw->x = (((buf[3] & 0x10) << 8) |
348 ((buf[1] & 0x0f) << 8) |
349 buf[4]);
350 hw->y = (((buf[3] & 0x20) << 7) |
351 ((buf[1] & 0xf0) << 4) |
352 buf[5]);
353
354 hw->z = buf[2];
355 hw->w = (((buf[0] & 0x30) >> 2) |
356 ((buf[0] & 0x04) >> 1) |
357 ((buf[3] & 0x04) >> 2));
358
359 hw->left = (buf[0] & 0x01) ? 1 : 0;
360 hw->right = (buf[0] & 0x02) ? 1 : 0;
361
5f57d67d
TI
362 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
363 /*
364 * Clickpad's button is transmitted as middle button,
365 * however, since it is primary button, we will report
366 * it as BTN_LEFT.
367 */
368 hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
369
370 } else if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
1da177e4
LT
371 hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
372 if (hw->w == 2)
373 hw->scroll = (signed char)(buf[1]);
374 }
375
376 if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
377 hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
378 hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
379 }
380
381 if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
382 ((buf[0] ^ buf[3]) & 0x02)) {
383 switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
384 default:
385 /*
386 * if nExtBtn is greater than 8 it should be
387 * considered invalid and treated as 0
388 */
389 break;
390 case 8:
391 hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0;
392 hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0;
393 case 6:
394 hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0;
395 hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0;
396 case 4:
397 hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0;
398 hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0;
399 case 2:
400 hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0;
401 hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0;
402 }
403 }
404 } else {
405 hw->x = (((buf[1] & 0x1f) << 8) | buf[2]);
406 hw->y = (((buf[4] & 0x1f) << 8) | buf[5]);
407
408 hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
409 hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
410
411 hw->left = (buf[0] & 0x01) ? 1 : 0;
412 hw->right = (buf[0] & 0x02) ? 1 : 0;
413 }
414}
415
416/*
417 * called for each full received packet from the touchpad
418 */
419static void synaptics_process_packet(struct psmouse *psmouse)
420{
2e5b636b 421 struct input_dev *dev = psmouse->dev;
1da177e4
LT
422 struct synaptics_data *priv = psmouse->private;
423 struct synaptics_hw_state hw;
424 int num_fingers;
425 int finger_width;
426 int i;
427
428 synaptics_parse_hw_state(psmouse->packet, priv, &hw);
429
430 if (hw.scroll) {
431 priv->scroll += hw.scroll;
432
433 while (priv->scroll >= 4) {
434 input_report_key(dev, BTN_BACK, !hw.down);
435 input_sync(dev);
436 input_report_key(dev, BTN_BACK, hw.down);
437 input_sync(dev);
438 priv->scroll -= 4;
439 }
440 while (priv->scroll <= -4) {
441 input_report_key(dev, BTN_FORWARD, !hw.up);
442 input_sync(dev);
443 input_report_key(dev, BTN_FORWARD, hw.up);
444 input_sync(dev);
445 priv->scroll += 4;
446 }
447 return;
448 }
449
450 if (hw.z > 0) {
451 num_fingers = 1;
452 finger_width = 5;
453 if (SYN_CAP_EXTENDED(priv->capabilities)) {
454 switch (hw.w) {
455 case 0 ... 1:
456 if (SYN_CAP_MULTIFINGER(priv->capabilities))
457 num_fingers = hw.w + 2;
458 break;
459 case 2:
460 if (SYN_MODEL_PEN(priv->model_id))
461 ; /* Nothing, treat a pen as a single finger */
462 break;
463 case 4 ... 15:
464 if (SYN_CAP_PALMDETECT(priv->capabilities))
465 finger_width = hw.w;
466 break;
467 }
468 }
469 } else {
470 num_fingers = 0;
471 finger_width = 0;
472 }
473
474 /* Post events
475 * BTN_TOUCH has to be first as mousedev relies on it when doing
476 * absolute -> relative conversion
477 */
478 if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1);
479 if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0);
480
481 if (hw.z > 0) {
482 input_report_abs(dev, ABS_X, hw.x);
483 input_report_abs(dev, ABS_Y, YMAX_NOMINAL + YMIN_NOMINAL - hw.y);
484 }
485 input_report_abs(dev, ABS_PRESSURE, hw.z);
486
487 input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
488 input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
1da177e4
LT
489 input_report_key(dev, BTN_LEFT, hw.left);
490 input_report_key(dev, BTN_RIGHT, hw.right);
491
e42b6646
PH
492 if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
493 input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
494 input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
495 }
496
1da177e4
LT
497 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
498 input_report_key(dev, BTN_MIDDLE, hw.middle);
499
500 if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
501 input_report_key(dev, BTN_FORWARD, hw.up);
502 input_report_key(dev, BTN_BACK, hw.down);
503 }
504
505 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
506 input_report_key(dev, BTN_0 + i, hw.ext_buttons & (1 << i));
507
508 input_sync(dev);
509}
510
511static int synaptics_validate_byte(unsigned char packet[], int idx, unsigned char pkt_type)
512{
e38de678
HD
513 static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
514 static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
515 static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
516 static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
517 static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
1da177e4
LT
518
519 if (idx < 0 || idx > 4)
520 return 0;
521
522 switch (pkt_type) {
523 case SYN_NEWABS:
524 case SYN_NEWABS_RELAXED:
525 return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx];
526
527 case SYN_NEWABS_STRICT:
528 return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx];
529
530 case SYN_OLDABS:
531 return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx];
532
533 default:
534 printk(KERN_ERR "synaptics: unknown packet type %d\n", pkt_type);
535 return 0;
536 }
537}
538
539static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse)
540{
541 int i;
542
543 for (i = 0; i < 5; i++)
544 if (!synaptics_validate_byte(psmouse->packet, i, SYN_NEWABS_STRICT)) {
545 printk(KERN_INFO "synaptics: using relaxed packet validation\n");
546 return SYN_NEWABS_RELAXED;
547 }
548
549 return SYN_NEWABS_STRICT;
550}
551
7d12e780 552static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
1da177e4 553{
1da177e4
LT
554 struct synaptics_data *priv = psmouse->private;
555
1da177e4
LT
556 if (psmouse->pktcnt >= 6) { /* Full packet received */
557 if (unlikely(priv->pkt_type == SYN_NEWABS))
558 priv->pkt_type = synaptics_detect_pkt_type(psmouse);
559
560 if (SYN_CAP_PASS_THROUGH(priv->capabilities) && synaptics_is_pt_packet(psmouse->packet)) {
561 if (psmouse->ps2dev.serio->child)
562 synaptics_pass_pt_packet(psmouse->ps2dev.serio->child, psmouse->packet);
563 } else
564 synaptics_process_packet(psmouse);
565
566 return PSMOUSE_FULL_PACKET;
567 }
568
569 return synaptics_validate_byte(psmouse->packet, psmouse->pktcnt - 1, priv->pkt_type) ?
570 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
571}
572
573/*****************************************************************************
574 * Driver initialization/cleanup functions
575 ****************************************************************************/
576static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
577{
578 int i;
579
b7802c5c 580 __set_bit(EV_ABS, dev->evbit);
1da177e4
LT
581 input_set_abs_params(dev, ABS_X, XMIN_NOMINAL, XMAX_NOMINAL, 0, 0);
582 input_set_abs_params(dev, ABS_Y, YMIN_NOMINAL, YMAX_NOMINAL, 0, 0);
583 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
b7802c5c 584 __set_bit(ABS_TOOL_WIDTH, dev->absbit);
1da177e4 585
b7802c5c
DT
586 __set_bit(EV_KEY, dev->evbit);
587 __set_bit(BTN_TOUCH, dev->keybit);
588 __set_bit(BTN_TOOL_FINGER, dev->keybit);
589 __set_bit(BTN_LEFT, dev->keybit);
590 __set_bit(BTN_RIGHT, dev->keybit);
1da177e4 591
e42b6646 592 if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
b7802c5c
DT
593 __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
594 __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
e42b6646
PH
595 }
596
1da177e4 597 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
b7802c5c 598 __set_bit(BTN_MIDDLE, dev->keybit);
1da177e4
LT
599
600 if (SYN_CAP_FOUR_BUTTON(priv->capabilities) ||
601 SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
b7802c5c
DT
602 __set_bit(BTN_FORWARD, dev->keybit);
603 __set_bit(BTN_BACK, dev->keybit);
1da177e4
LT
604 }
605
606 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
b7802c5c 607 __set_bit(BTN_0 + i, dev->keybit);
1da177e4 608
b7802c5c
DT
609 __clear_bit(EV_REL, dev->evbit);
610 __clear_bit(REL_X, dev->relbit);
611 __clear_bit(REL_Y, dev->relbit);
ec20a022
TS
612
613 dev->absres[ABS_X] = priv->x_res;
614 dev->absres[ABS_Y] = priv->y_res;
5f57d67d
TI
615
616 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
617 /* Clickpads report only left button */
618 __clear_bit(BTN_RIGHT, dev->keybit);
619 __clear_bit(BTN_MIDDLE, dev->keybit);
620 }
1da177e4
LT
621}
622
1da177e4
LT
623static void synaptics_disconnect(struct psmouse *psmouse)
624{
625 synaptics_reset(psmouse);
626 kfree(psmouse->private);
627 psmouse->private = NULL;
628}
629
630static int synaptics_reconnect(struct psmouse *psmouse)
631{
632 struct synaptics_data *priv = psmouse->private;
633 struct synaptics_data old_priv = *priv;
634
4d368456
AW
635 psmouse_reset(psmouse);
636
1da177e4
LT
637 if (synaptics_detect(psmouse, 0))
638 return -1;
639
640 if (synaptics_query_hardware(psmouse)) {
641 printk(KERN_ERR "Unable to query Synaptics hardware.\n");
642 return -1;
643 }
644
645 if (old_priv.identity != priv->identity ||
646 old_priv.model_id != priv->model_id ||
647 old_priv.capabilities != priv->capabilities ||
648 old_priv.ext_cap != priv->ext_cap)
649 return -1;
650
651 if (synaptics_set_absolute_mode(psmouse)) {
652 printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
653 return -1;
654 }
655
656 return 0;
657}
658
7705d548
DT
659static bool impaired_toshiba_kbc;
660
661static const struct dmi_system_id __initconst toshiba_dmi_table[] = {
662#if defined(CONFIG_DMI) && defined(CONFIG_X86)
1da177e4 663 {
9961e259 664 /* Toshiba Satellite */
1da177e4
LT
665 .matches = {
666 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
53a2670c 667 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
1da177e4
LT
668 },
669 },
9ba5eaaf 670 {
9961e259 671 /* Toshiba Dynabook */
9ba5eaaf
SH
672 .matches = {
673 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
53a2670c
RT
674 DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
675 },
676 },
677 {
9961e259 678 /* Toshiba Portege M300 */
53a2670c
RT
679 .matches = {
680 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
681 DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
9ba5eaaf 682 },
5f5eeff4
DT
683
684 },
685 {
9961e259 686 /* Toshiba Portege M300 */
5f5eeff4
DT
687 .matches = {
688 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
689 DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
690 DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
691 },
692
9ba5eaaf 693 },
1da177e4 694 { }
1da177e4 695#endif
7705d548
DT
696};
697
698void __init synaptics_module_init(void)
699{
700 impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
701}
1da177e4
LT
702
703int synaptics_init(struct psmouse *psmouse)
704{
705 struct synaptics_data *priv;
706
b39787a9 707 psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
1da177e4
LT
708 if (!priv)
709 return -1;
1da177e4 710
4d368456
AW
711 psmouse_reset(psmouse);
712
1da177e4
LT
713 if (synaptics_query_hardware(psmouse)) {
714 printk(KERN_ERR "Unable to query Synaptics hardware.\n");
715 goto init_fail;
716 }
717
718 if (synaptics_set_absolute_mode(psmouse)) {
719 printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
720 goto init_fail;
721 }
722
723 priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS;
724
5f57d67d 725 printk(KERN_INFO "Synaptics Touchpad, model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx\n",
409b7506
DT
726 SYN_ID_MODEL(priv->identity),
727 SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity),
5f57d67d 728 priv->model_id, priv->capabilities, priv->ext_cap, priv->ext_cap_0c);
409b7506 729
2e5b636b 730 set_input_params(psmouse->dev, priv);
1da177e4 731
887cc127
DT
732 /*
733 * Encode touchpad model so that it can be used to set
734 * input device->id.version and be visible to userspace.
735 * Because version is __u16 we have to drop something.
736 * Hardware info bits seem to be good candidates as they
737 * are documented to be for Synaptics corp. internal use.
738 */
739 psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) |
740 (priv->model_id & 0x000000ff);
741
1da177e4
LT
742 psmouse->protocol_handler = synaptics_process_byte;
743 psmouse->set_rate = synaptics_set_rate;
744 psmouse->disconnect = synaptics_disconnect;
745 psmouse->reconnect = synaptics_reconnect;
a1cec061 746 psmouse->cleanup = synaptics_reset;
1da177e4 747 psmouse->pktsize = 6;
f0d5c6f4
DT
748 /* Synaptics can usually stay in sync without extra help */
749 psmouse->resync_time = 0;
1da177e4
LT
750
751 if (SYN_CAP_PASS_THROUGH(priv->capabilities))
752 synaptics_pt_create(psmouse);
753
1da177e4
LT
754 /*
755 * Toshiba's KBC seems to have trouble handling data from
756 * Synaptics as full rate, switch to lower rate which is roughly
757 * thye same as rate of standard PS/2 mouse.
758 */
7705d548 759 if (psmouse->rate >= 80 && impaired_toshiba_kbc) {
9ba5eaaf
SH
760 printk(KERN_INFO "synaptics: Toshiba %s detected, limiting rate to 40pps.\n",
761 dmi_get_system_info(DMI_PRODUCT_NAME));
1da177e4
LT
762 psmouse->rate = 40;
763 }
1da177e4
LT
764
765 return 0;
766
767 init_fail:
768 kfree(priv);
769 return -1;
770}
771
e4e6efd2
DD
772bool synaptics_supported(void)
773{
774 return true;
775}
776
55e3d922
AS
777#else /* CONFIG_MOUSE_PS2_SYNAPTICS */
778
7705d548
DT
779void __init synaptics_module_init(void)
780{
781}
782
55e3d922
AS
783int synaptics_init(struct psmouse *psmouse)
784{
785 return -ENOSYS;
786}
787
e4e6efd2
DD
788bool synaptics_supported(void)
789{
790 return false;
791}
792
55e3d922 793#endif /* CONFIG_MOUSE_PS2_SYNAPTICS */
1da177e4 794