blob: a7af8565e2dea09ec066eb33b00e384e439be761 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Dmitry Torokhov7705d542009-12-03 23:21:14 -080027#include <linux/dmi.h>
Henrik Rydbergfec6e522010-12-21 18:11:25 +010028#include <linux/input/mt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/serio.h>
30#include <linux/libps2.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#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.
Dmitry Torokhov83ba9ea2010-05-10 23:06:52 -070039 * Note that newer firmware allows querying device for maximum useable
40 * coordinates.
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 */
42#define XMIN_NOMINAL 1472
43#define XMAX_NOMINAL 5472
44#define YMIN_NOMINAL 1408
45#define YMAX_NOMINAL 4448
46
Daniel Kurtz6de58dd2011-08-23 23:00:24 -070047/*
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.
51 */
52static int synaptics_invert_y(int y)
53{
54 return YMAX_NOMINAL + YMIN_NOMINAL - y;
55}
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Andres Salomon55e3d922007-03-10 01:39:54 -050058/*****************************************************************************
59 * Stuff we need even when we do not want native Synaptics support
60 ****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62/*
63 * Set the synaptics touchpad mode byte by special commands
64 */
65static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode)
66{
67 unsigned char param[1];
68
69 if (psmouse_sliced_command(psmouse, mode))
70 return -1;
71 param[0] = SYN_PS_SET_MODE2;
72 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE))
73 return -1;
74 return 0;
75}
76
Dmitry Torokhovb7802c52009-09-09 19:13:20 -070077int synaptics_detect(struct psmouse *psmouse, bool set_properties)
Andres Salomon55e3d922007-03-10 01:39:54 -050078{
79 struct ps2dev *ps2dev = &psmouse->ps2dev;
80 unsigned char param[4];
81
82 param[0] = 0;
83
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);
89
90 if (param[1] != 0x47)
91 return -ENODEV;
92
93 if (set_properties) {
94 psmouse->vendor = "Synaptics";
95 psmouse->name = "TouchPad";
96 }
97
98 return 0;
99}
100
101void synaptics_reset(struct psmouse *psmouse)
102{
103 /* reset touchpad back to relative mode, gestures enabled */
104 synaptics_mode_cmd(psmouse, 0);
105}
106
107#ifdef CONFIG_MOUSE_PS2_SYNAPTICS
108
109/*****************************************************************************
110 * Synaptics communications functions
111 ****************************************************************************/
112
113/*
114 * Send a command to the synpatics touchpad by special commands
115 */
116static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param)
117{
118 if (psmouse_sliced_command(psmouse, c))
119 return -1;
120 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO))
121 return -1;
122 return 0;
123}
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125/*
126 * Read the model-id bytes from the touchpad
127 * see also SYN_MODEL_* macros
128 */
129static int synaptics_model_id(struct psmouse *psmouse)
130{
131 struct synaptics_data *priv = psmouse->private;
132 unsigned char mi[3];
133
134 if (synaptics_send_cmd(psmouse, SYN_QUE_MODEL, mi))
135 return -1;
136 priv->model_id = (mi[0]<<16) | (mi[1]<<8) | mi[2];
137 return 0;
138}
139
140/*
141 * Read the capability-bits from the touchpad
142 * see also the SYN_CAP_* macros
143 */
144static int synaptics_capability(struct psmouse *psmouse)
145{
146 struct synaptics_data *priv = psmouse->private;
147 unsigned char cap[3];
148
149 if (synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap))
150 return -1;
151 priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
Takashi Iwai5f57d672010-04-19 10:37:21 -0700152 priv->ext_cap = priv->ext_cap_0c = 0;
153
Dmitry Torokhov3619b8f2010-07-21 00:01:19 -0700154 /*
155 * Older firmwares had submodel ID fixed to 0x47
156 */
157 if (SYN_ID_FULL(priv->identity) < 0x705 &&
158 SYN_CAP_SUBMODEL_ID(priv->capabilities) != 0x47) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 return -1;
Dmitry Torokhov3619b8f2010-07-21 00:01:19 -0700160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 /*
163 * Unless capExtended is set the rest of the flags should be ignored
164 */
165 if (!SYN_CAP_EXTENDED(priv->capabilities))
166 priv->capabilities = 0;
167
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,"
Takashi Iwai5f57d672010-04-19 10:37:21 -0700171 " but I'm not able to read them.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 } else {
173 priv->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
174
175 /*
176 * if nExtBtn is greater than 8 it should be considered
177 * invalid and treated as 0
178 */
179 if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) > 8)
180 priv->ext_cap &= 0xff0fff;
181 }
182 }
Takashi Iwai5f57d672010-04-19 10:37:21 -0700183
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");
188 } else {
189 priv->ext_cap_0c = (cap[0] << 16) | (cap[1] << 8) | cap[2];
190 }
191 }
192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return 0;
194}
195
196/*
197 * Identify Touchpad
198 * See also the SYN_ID_* macros
199 */
200static int synaptics_identify(struct psmouse *psmouse)
201{
202 struct synaptics_data *priv = psmouse->private;
203 unsigned char id[3];
204
205 if (synaptics_send_cmd(psmouse, SYN_QUE_IDENTIFY, id))
206 return -1;
207 priv->identity = (id[0]<<16) | (id[1]<<8) | id[2];
208 if (SYN_ID_IS_SYNAPTICS(priv->identity))
209 return 0;
210 return -1;
211}
212
Tero Saarniec20a022009-06-10 23:27:24 -0700213/*
Dmitry Torokhov83ba9ea2010-05-10 23:06:52 -0700214 * Read touchpad resolution and maximum reported coordinates
Tero Saarniec20a022009-06-10 23:27:24 -0700215 * Resolution is left zero if touchpad does not support the query
216 */
217static int synaptics_resolution(struct psmouse *psmouse)
218{
219 struct synaptics_data *priv = psmouse->private;
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700220 unsigned char resp[3];
Tero Saarniec20a022009-06-10 23:27:24 -0700221
222 if (SYN_ID_MAJOR(priv->identity) < 4)
Takashi Iwaibbddd192010-07-14 09:32:46 -0700223 return 0;
Tero Saarniec20a022009-06-10 23:27:24 -0700224
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700225 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 */
Dmitry Torokhov83ba9ea2010-05-10 23:06:52 -0700229 }
230 }
Tero Saarniec20a022009-06-10 23:27:24 -0700231
Dmitry Torokhov83ba9ea2010-05-10 23:06:52 -0700232 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 5 &&
233 SYN_CAP_MAX_DIMENSIONS(priv->ext_cap_0c)) {
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700234 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");
Dmitry Torokhov83ba9ea2010-05-10 23:06:52 -0700237 } else {
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700238 priv->x_max = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
239 priv->y_max = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
240 }
241 }
242
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");
248 } else {
249 priv->x_min = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
250 priv->y_min = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
Dmitry Torokhov83ba9ea2010-05-10 23:06:52 -0700251 }
Tero Saarniec20a022009-06-10 23:27:24 -0700252 }
253
254 return 0;
255}
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257static int synaptics_query_hardware(struct psmouse *psmouse)
258{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 if (synaptics_identify(psmouse))
260 return -1;
261 if (synaptics_model_id(psmouse))
262 return -1;
263 if (synaptics_capability(psmouse))
264 return -1;
Tero Saarniec20a022009-06-10 23:27:24 -0700265 if (synaptics_resolution(psmouse))
266 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 return 0;
269}
270
271static int synaptics_set_absolute_mode(struct psmouse *psmouse)
272{
273 struct synaptics_data *priv = psmouse->private;
274
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;
280
281 if (synaptics_mode_cmd(psmouse, priv->mode))
282 return -1;
283
284 return 0;
285}
286
287static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
288{
289 struct synaptics_data *priv = psmouse->private;
290
291 if (rate >= 80) {
292 priv->mode |= SYN_BIT_HIGH_RATE;
293 psmouse->rate = 80;
294 } else {
295 priv->mode &= ~SYN_BIT_HIGH_RATE;
296 psmouse->rate = 40;
297 }
298
299 synaptics_mode_cmd(psmouse, priv->mode);
300}
301
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100302static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse)
303{
304 static unsigned char param = 0xc8;
305 struct synaptics_data *priv = psmouse->private;
306
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700307 if (!(SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
308 SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)))
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100309 return 0;
310
311 if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL))
312 return -1;
313 if (ps2_command(&psmouse->ps2dev, &param, PSMOUSE_CMD_SETRATE))
314 return -1;
315
316 /* Advanced gesture mode also sends multi finger data */
317 priv->capabilities |= BIT(1);
318
319 return 0;
320}
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322/*****************************************************************************
323 * Synaptics pass-through PS/2 port support
324 ****************************************************************************/
325static int synaptics_pt_write(struct serio *serio, unsigned char c)
326{
327 struct psmouse *parent = serio_get_drvdata(serio->parent);
328 char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */
329
330 if (psmouse_sliced_command(parent, c))
331 return -1;
332 if (ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE))
333 return -1;
334 return 0;
335}
336
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700337static int synaptics_pt_start(struct serio *serio)
338{
339 struct psmouse *parent = serio_get_drvdata(serio->parent);
340 struct synaptics_data *priv = parent->private;
341
342 serio_pause_rx(parent->ps2dev.serio);
343 priv->pt_port = serio;
344 serio_continue_rx(parent->ps2dev.serio);
345
346 return 0;
347}
348
349static void synaptics_pt_stop(struct serio *serio)
350{
351 struct psmouse *parent = serio_get_drvdata(serio->parent);
352 struct synaptics_data *priv = parent->private;
353
354 serio_pause_rx(parent->ps2dev.serio);
355 priv->pt_port = NULL;
356 serio_continue_rx(parent->ps2dev.serio);
357}
358
359static int synaptics_is_pt_packet(unsigned char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
361 return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
362}
363
364static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet)
365{
366 struct psmouse *child = serio_get_drvdata(ptport);
367
368 if (child && child->state == PSMOUSE_ACTIVATED) {
David Howells7d12e782006-10-05 14:55:46 +0100369 serio_interrupt(ptport, packet[1], 0);
370 serio_interrupt(ptport, packet[4], 0);
371 serio_interrupt(ptport, packet[5], 0);
Sergey Vlasov33fdfa92005-07-24 00:53:32 -0500372 if (child->pktsize == 4)
David Howells7d12e782006-10-05 14:55:46 +0100373 serio_interrupt(ptport, packet[2], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 } else
David Howells7d12e782006-10-05 14:55:46 +0100375 serio_interrupt(ptport, packet[1], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
378static void synaptics_pt_activate(struct psmouse *psmouse)
379{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 struct synaptics_data *priv = psmouse->private;
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700381 struct psmouse *child = serio_get_drvdata(priv->pt_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 /* adjust the touchpad to child's choice of protocol */
384 if (child) {
Sergey Vlasov33fdfa92005-07-24 00:53:32 -0500385 if (child->pktsize == 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
387 else
388 priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
389
390 if (synaptics_mode_cmd(psmouse, priv->mode))
391 printk(KERN_INFO "synaptics: failed to switch guest protocol\n");
392 }
393}
394
395static void synaptics_pt_create(struct psmouse *psmouse)
396{
397 struct serio *serio;
398
Eric Sesterhennb39787a2006-03-14 00:09:16 -0500399 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 if (!serio) {
401 printk(KERN_ERR "synaptics: not enough memory to allocate pass-through port\n");
402 return;
403 }
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 serio->id.type = SERIO_PS_PSTHRU;
406 strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
407 strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name));
408 serio->write = synaptics_pt_write;
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700409 serio->start = synaptics_pt_start;
410 serio->stop = synaptics_pt_stop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 serio->parent = psmouse->ps2dev.serio;
412
413 psmouse->pt_activate = synaptics_pt_activate;
414
415 printk(KERN_INFO "serio: %s port at %s\n", serio->name, psmouse->phys);
416 serio_register_port(serio);
417}
418
419/*****************************************************************************
420 * Functions to interpret the absolute mode packets
421 ****************************************************************************/
422
Daniel Kurtza6ca40c2011-08-23 23:02:31 -0700423static void synaptics_mt_state_set(struct synaptics_mt_state *state, int count,
424 int sgm, int agm)
425{
426 state->count = count;
427 state->sgm = sgm;
428 state->agm = agm;
429}
430
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700431static void synaptics_parse_agm(const unsigned char buf[],
Daniel Kurtza6ca40c2011-08-23 23:02:31 -0700432 struct synaptics_data *priv,
433 struct synaptics_hw_state *hw)
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700434{
435 struct synaptics_hw_state *agm = &priv->agm;
Daniel Kurtza6ca40c2011-08-23 23:02:31 -0700436 int agm_packet_type;
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700437
Daniel Kurtza6ca40c2011-08-23 23:02:31 -0700438 agm_packet_type = (buf[5] & 0x30) >> 4;
439 switch (agm_packet_type) {
440 case 1:
441 /* Gesture packet: (x, y, z) half resolution */
442 agm->w = hw->w;
443 agm->x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
444 agm->y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1;
445 agm->z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
446 break;
447
448 case 2:
449 /* AGM-CONTACT packet: (count, sgm, agm) */
450 synaptics_mt_state_set(&agm->mt_state, buf[1], buf[2], buf[4]);
451 break;
452
453 default:
454 break;
455 }
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700456}
457
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100458static int synaptics_parse_hw_state(const unsigned char buf[],
459 struct synaptics_data *priv,
460 struct synaptics_hw_state *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
462 memset(hw, 0, sizeof(struct synaptics_hw_state));
463
464 if (SYN_MODEL_NEWABS(priv->model_id)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 hw->w = (((buf[0] & 0x30) >> 2) |
466 ((buf[0] & 0x04) >> 1) |
467 ((buf[3] & 0x04) >> 2));
468
469 hw->left = (buf[0] & 0x01) ? 1 : 0;
470 hw->right = (buf[0] & 0x02) ? 1 : 0;
471
Takashi Iwai5f57d672010-04-19 10:37:21 -0700472 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
473 /*
474 * Clickpad's button is transmitted as middle button,
475 * however, since it is primary button, we will report
476 * it as BTN_LEFT.
477 */
478 hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
479
480 } else if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
482 if (hw->w == 2)
483 hw->scroll = (signed char)(buf[1]);
484 }
485
486 if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
487 hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
488 hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
489 }
490
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700491 if ((SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
492 SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) &&
493 hw->w == 2) {
Daniel Kurtza6ca40c2011-08-23 23:02:31 -0700494 synaptics_parse_agm(buf, priv, hw);
Daniel Kurtz28d5fd82011-07-06 22:57:39 -0700495 return 1;
496 }
497
498 hw->x = (((buf[3] & 0x10) << 8) |
499 ((buf[1] & 0x0f) << 8) |
500 buf[4]);
501 hw->y = (((buf[3] & 0x20) << 7) |
502 ((buf[1] & 0xf0) << 4) |
503 buf[5]);
504 hw->z = buf[2];
505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
507 ((buf[0] ^ buf[3]) & 0x02)) {
508 switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
509 default:
510 /*
511 * if nExtBtn is greater than 8 it should be
512 * considered invalid and treated as 0
513 */
514 break;
515 case 8:
516 hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0;
517 hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0;
518 case 6:
519 hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0;
520 hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0;
521 case 4:
522 hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0;
523 hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0;
524 case 2:
525 hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0;
526 hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0;
527 }
528 }
529 } else {
530 hw->x = (((buf[1] & 0x1f) << 8) | buf[2]);
531 hw->y = (((buf[4] & 0x1f) << 8) | buf[5]);
532
533 hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
534 hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
535
536 hw->left = (buf[0] & 0x01) ? 1 : 0;
537 hw->right = (buf[0] & 0x02) ? 1 : 0;
538 }
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100539
540 return 0;
541}
542
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700543static void synaptics_report_semi_mt_slot(struct input_dev *dev, int slot,
544 bool active, int x, int y)
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100545{
546 input_mt_slot(dev, slot);
547 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
548 if (active) {
549 input_report_abs(dev, ABS_MT_POSITION_X, x);
Daniel Kurtz6de58dd2011-08-23 23:00:24 -0700550 input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(y));
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100551 }
552}
553
554static void synaptics_report_semi_mt_data(struct input_dev *dev,
555 const struct synaptics_hw_state *a,
556 const struct synaptics_hw_state *b,
557 int num_fingers)
558{
559 if (num_fingers >= 2) {
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700560 synaptics_report_semi_mt_slot(dev, 0, true, min(a->x, b->x),
561 min(a->y, b->y));
562 synaptics_report_semi_mt_slot(dev, 1, true, max(a->x, b->x),
563 max(a->y, b->y));
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100564 } else if (num_fingers == 1) {
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700565 synaptics_report_semi_mt_slot(dev, 0, true, a->x, a->y);
566 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100567 } else {
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700568 synaptics_report_semi_mt_slot(dev, 0, false, 0, 0);
569 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100570 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571}
572
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700573static void synaptics_report_buttons(struct psmouse *psmouse,
574 const struct synaptics_hw_state *hw)
575{
576 struct input_dev *dev = psmouse->dev;
577 struct synaptics_data *priv = psmouse->private;
578 int i;
579
580 input_report_key(dev, BTN_LEFT, hw->left);
581 input_report_key(dev, BTN_RIGHT, hw->right);
582
583 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
584 input_report_key(dev, BTN_MIDDLE, hw->middle);
585
586 if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
587 input_report_key(dev, BTN_FORWARD, hw->up);
588 input_report_key(dev, BTN_BACK, hw->down);
589 }
590
591 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
592 input_report_key(dev, BTN_0 + i, hw->ext_buttons & (1 << i));
593}
594
595static void synaptics_report_slot(struct input_dev *dev, int slot,
596 const struct synaptics_hw_state *hw)
597{
598 input_mt_slot(dev, slot);
599 input_mt_report_slot_state(dev, MT_TOOL_FINGER, (hw != NULL));
600 if (!hw)
601 return;
602
603 input_report_abs(dev, ABS_MT_POSITION_X, hw->x);
604 input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(hw->y));
605 input_report_abs(dev, ABS_MT_PRESSURE, hw->z);
606}
607
608static void synaptics_report_mt_data(struct psmouse *psmouse,
609 int count,
610 const struct synaptics_hw_state *sgm)
611{
612 struct input_dev *dev = psmouse->dev;
613 struct synaptics_data *priv = psmouse->private;
614 struct synaptics_hw_state *agm = &priv->agm;
615
616 switch (count) {
617 case 0:
618 synaptics_report_slot(dev, 0, NULL);
619 synaptics_report_slot(dev, 1, NULL);
620 break;
621 case 1:
622 synaptics_report_slot(dev, 0, sgm);
623 synaptics_report_slot(dev, 1, NULL);
624 break;
625 case 2:
626 case 3: /* Fall-through case */
627 synaptics_report_slot(dev, 0, sgm);
628 synaptics_report_slot(dev, 1, agm);
629 break;
630 }
631
632 /* Don't use active slot count to generate BTN_TOOL events. */
633 input_mt_report_pointer_emulation(dev, false);
634
635 /* Send the number of fingers reported by touchpad itself. */
636 input_mt_report_finger_count(dev, count);
637
638 synaptics_report_buttons(psmouse, sgm);
639
640 input_sync(dev);
641}
642
643static void synaptics_image_sensor_process(struct psmouse *psmouse,
644 struct synaptics_hw_state *sgm)
645{
646 int count;
647
648 if (sgm->z == 0)
649 count = 0;
650 else if (sgm->w >= 4)
651 count = 1;
652 else if (sgm->w == 0)
653 count = 2;
654 else
655 count = 3;
656
657 /* Send resulting input events to user space */
658 synaptics_report_mt_data(psmouse, count, sgm);
659}
660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661/*
662 * called for each full received packet from the touchpad
663 */
664static void synaptics_process_packet(struct psmouse *psmouse)
665{
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500666 struct input_dev *dev = psmouse->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 struct synaptics_data *priv = psmouse->private;
668 struct synaptics_hw_state hw;
669 int num_fingers;
670 int finger_width;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100672 if (synaptics_parse_hw_state(psmouse->packet, priv, &hw))
673 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700675 if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) {
676 synaptics_image_sensor_process(psmouse, &hw);
677 return;
678 }
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 if (hw.scroll) {
681 priv->scroll += hw.scroll;
682
683 while (priv->scroll >= 4) {
684 input_report_key(dev, BTN_BACK, !hw.down);
685 input_sync(dev);
686 input_report_key(dev, BTN_BACK, hw.down);
687 input_sync(dev);
688 priv->scroll -= 4;
689 }
690 while (priv->scroll <= -4) {
691 input_report_key(dev, BTN_FORWARD, !hw.up);
692 input_sync(dev);
693 input_report_key(dev, BTN_FORWARD, hw.up);
694 input_sync(dev);
695 priv->scroll += 4;
696 }
697 return;
698 }
699
Henrik Rydberg4f56ce92010-12-18 15:42:30 +0100700 if (hw.z > 0 && hw.x > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 num_fingers = 1;
702 finger_width = 5;
703 if (SYN_CAP_EXTENDED(priv->capabilities)) {
704 switch (hw.w) {
705 case 0 ... 1:
706 if (SYN_CAP_MULTIFINGER(priv->capabilities))
707 num_fingers = hw.w + 2;
708 break;
709 case 2:
710 if (SYN_MODEL_PEN(priv->model_id))
711 ; /* Nothing, treat a pen as a single finger */
712 break;
713 case 4 ... 15:
714 if (SYN_CAP_PALMDETECT(priv->capabilities))
715 finger_width = hw.w;
716 break;
717 }
718 }
719 } else {
720 num_fingers = 0;
721 finger_width = 0;
722 }
723
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100724 if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c))
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700725 synaptics_report_semi_mt_data(dev, &hw, &priv->agm,
726 num_fingers);
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 /* Post events
729 * BTN_TOUCH has to be first as mousedev relies on it when doing
730 * absolute -> relative conversion
731 */
732 if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1);
733 if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0);
734
Henrik Rydberg4f56ce92010-12-18 15:42:30 +0100735 if (num_fingers > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 input_report_abs(dev, ABS_X, hw.x);
Daniel Kurtz6de58dd2011-08-23 23:00:24 -0700737 input_report_abs(dev, ABS_Y, synaptics_invert_y(hw.y));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 }
739 input_report_abs(dev, ABS_PRESSURE, hw.z);
740
Chris Bagwell2a8e7712010-07-19 09:06:15 -0700741 if (SYN_CAP_PALMDETECT(priv->capabilities))
742 input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
Peter Hutterere42b6642008-11-20 15:24:42 -0500745 if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
746 input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
747 input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
748 }
749
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700750 synaptics_report_buttons(psmouse, &hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
752 input_sync(dev);
753}
754
755static int synaptics_validate_byte(unsigned char packet[], int idx, unsigned char pkt_type)
756{
Helge Dellere38de672006-09-10 21:54:39 -0400757 static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
758 static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
759 static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
760 static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
761 static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 if (idx < 0 || idx > 4)
764 return 0;
765
766 switch (pkt_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700768 case SYN_NEWABS:
769 case SYN_NEWABS_RELAXED:
770 return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700772 case SYN_NEWABS_STRICT:
773 return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700775 case SYN_OLDABS:
776 return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx];
777
778 default:
779 printk(KERN_ERR "synaptics: unknown packet type %d\n", pkt_type);
780 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 }
782}
783
784static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse)
785{
786 int i;
787
788 for (i = 0; i < 5; i++)
789 if (!synaptics_validate_byte(psmouse->packet, i, SYN_NEWABS_STRICT)) {
790 printk(KERN_INFO "synaptics: using relaxed packet validation\n");
791 return SYN_NEWABS_RELAXED;
792 }
793
794 return SYN_NEWABS_STRICT;
795}
796
David Howells7d12e782006-10-05 14:55:46 +0100797static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 struct synaptics_data *priv = psmouse->private;
800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 if (psmouse->pktcnt >= 6) { /* Full packet received */
802 if (unlikely(priv->pkt_type == SYN_NEWABS))
803 priv->pkt_type = synaptics_detect_pkt_type(psmouse);
804
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700805 if (SYN_CAP_PASS_THROUGH(priv->capabilities) &&
806 synaptics_is_pt_packet(psmouse->packet)) {
807 if (priv->pt_port)
808 synaptics_pass_pt_packet(priv->pt_port, psmouse->packet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 } else
810 synaptics_process_packet(psmouse);
811
812 return PSMOUSE_FULL_PACKET;
813 }
814
815 return synaptics_validate_byte(psmouse->packet, psmouse->pktcnt - 1, priv->pkt_type) ?
816 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
817}
818
819/*****************************************************************************
820 * Driver initialization/cleanup functions
821 ****************************************************************************/
Daniel Kurtz85615472011-08-23 23:00:41 -0700822static void set_abs_position_params(struct input_dev *dev,
823 struct synaptics_data *priv, int x_code,
824 int y_code)
825{
826 int x_min = priv->x_min ?: XMIN_NOMINAL;
827 int x_max = priv->x_max ?: XMAX_NOMINAL;
828 int y_min = priv->y_min ?: YMIN_NOMINAL;
829 int y_max = priv->y_max ?: YMAX_NOMINAL;
830 int fuzz = SYN_CAP_REDUCED_FILTERING(priv->ext_cap_0c) ?
831 SYN_REDUCED_FILTER_FUZZ : 0;
832
833 input_set_abs_params(dev, x_code, x_min, x_max, fuzz, 0);
834 input_set_abs_params(dev, y_code, y_min, y_max, fuzz, 0);
835 input_abs_set_res(dev, x_code, priv->x_res);
836 input_abs_set_res(dev, y_code, priv->y_res);
837}
838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
840{
841 int i;
842
Henrik Rydbergc14890a2010-12-16 09:52:23 +0100843 __set_bit(INPUT_PROP_POINTER, dev->propbit);
844
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700845 __set_bit(EV_ABS, dev->evbit);
Daniel Kurtz85615472011-08-23 23:00:41 -0700846 set_abs_position_params(dev, priv, ABS_X, ABS_Y);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
Chris Bagwell2a8e7712010-07-19 09:06:15 -0700848
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700849 if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) {
850 input_mt_init_slots(dev, 2);
851 set_abs_position_params(dev, priv, ABS_MT_POSITION_X,
852 ABS_MT_POSITION_Y);
853 /* Image sensors can report per-contact pressure */
854 input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
855 } else if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) {
856 /* Non-image sensors with AGM use semi-mt */
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100857 __set_bit(INPUT_PROP_SEMI_MT, dev->propbit);
858 input_mt_init_slots(dev, 2);
Daniel Kurtz85615472011-08-23 23:00:41 -0700859 set_abs_position_params(dev, priv, ABS_MT_POSITION_X,
860 ABS_MT_POSITION_Y);
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100861 }
862
Chris Bagwell2a8e7712010-07-19 09:06:15 -0700863 if (SYN_CAP_PALMDETECT(priv->capabilities))
Chris Bagwell58fb0212010-07-19 09:06:15 -0700864 input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700866 __set_bit(EV_KEY, dev->evbit);
867 __set_bit(BTN_TOUCH, dev->keybit);
868 __set_bit(BTN_TOOL_FINGER, dev->keybit);
869 __set_bit(BTN_LEFT, dev->keybit);
870 __set_bit(BTN_RIGHT, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
Peter Hutterere42b6642008-11-20 15:24:42 -0500872 if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700873 __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
874 __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
Peter Hutterere42b6642008-11-20 15:24:42 -0500875 }
876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700878 __set_bit(BTN_MIDDLE, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
880 if (SYN_CAP_FOUR_BUTTON(priv->capabilities) ||
881 SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700882 __set_bit(BTN_FORWARD, dev->keybit);
883 __set_bit(BTN_BACK, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 }
885
886 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700887 __set_bit(BTN_0 + i, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700889 __clear_bit(EV_REL, dev->evbit);
890 __clear_bit(REL_X, dev->relbit);
891 __clear_bit(REL_Y, dev->relbit);
Tero Saarniec20a022009-06-10 23:27:24 -0700892
Takashi Iwai5f57d672010-04-19 10:37:21 -0700893 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
Henrik Rydbergc14890a2010-12-16 09:52:23 +0100894 __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
Takashi Iwai5f57d672010-04-19 10:37:21 -0700895 /* Clickpads report only left button */
896 __clear_bit(BTN_RIGHT, dev->keybit);
897 __clear_bit(BTN_MIDDLE, dev->keybit);
898 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899}
900
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901static void synaptics_disconnect(struct psmouse *psmouse)
902{
903 synaptics_reset(psmouse);
904 kfree(psmouse->private);
905 psmouse->private = NULL;
906}
907
908static int synaptics_reconnect(struct psmouse *psmouse)
909{
910 struct synaptics_data *priv = psmouse->private;
911 struct synaptics_data old_priv = *priv;
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -0800912 int retry = 0;
913 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -0800915 do {
916 psmouse_reset(psmouse);
917 error = synaptics_detect(psmouse, 0);
918 } while (error && ++retry < 3);
Andy Whitcroft4d368452009-02-28 12:51:01 -0800919
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -0800920 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 return -1;
922
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -0800923 if (retry > 1)
924 printk(KERN_DEBUG "Synaptics reconnected after %d tries\n",
925 retry);
926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 if (synaptics_query_hardware(psmouse)) {
928 printk(KERN_ERR "Unable to query Synaptics hardware.\n");
929 return -1;
930 }
931
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 if (synaptics_set_absolute_mode(psmouse)) {
933 printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
934 return -1;
935 }
936
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100937 if (synaptics_set_advanced_gesture_mode(psmouse)) {
938 printk(KERN_ERR "Advanced gesture mode reconnect failed.\n");
939 return -1;
940 }
941
Alexandre Peixoto Ferreirabaddf582011-01-28 22:05:14 -0800942 if (old_priv.identity != priv->identity ||
943 old_priv.model_id != priv->model_id ||
944 old_priv.capabilities != priv->capabilities ||
945 old_priv.ext_cap != priv->ext_cap) {
946 printk(KERN_ERR "Synaptics hardware appears to be different: "
947 "id(%ld-%ld), model(%ld-%ld), caps(%lx-%lx), ext(%lx-%lx).\n",
948 old_priv.identity, priv->identity,
949 old_priv.model_id, priv->model_id,
950 old_priv.capabilities, priv->capabilities,
951 old_priv.ext_cap, priv->ext_cap);
952 return -1;
953 }
954
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 return 0;
956}
957
Dmitry Torokhov7705d542009-12-03 23:21:14 -0800958static bool impaired_toshiba_kbc;
959
960static const struct dmi_system_id __initconst toshiba_dmi_table[] = {
961#if defined(CONFIG_DMI) && defined(CONFIG_X86)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -0800963 /* Toshiba Satellite */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 .matches = {
965 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
Richard Thrippleton53a26702006-04-02 00:10:18 -0500966 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 },
968 },
Simon Horman9ba5eaa2005-07-11 01:07:20 -0500969 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -0800970 /* Toshiba Dynabook */
Simon Horman9ba5eaa2005-07-11 01:07:20 -0500971 .matches = {
972 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
Richard Thrippleton53a26702006-04-02 00:10:18 -0500973 DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
974 },
975 },
976 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -0800977 /* Toshiba Portege M300 */
Richard Thrippleton53a26702006-04-02 00:10:18 -0500978 .matches = {
979 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
980 DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
Simon Horman9ba5eaa2005-07-11 01:07:20 -0500981 },
Dmitry Torokhov5f5eeff2009-10-12 21:35:00 -0700982
983 },
984 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -0800985 /* Toshiba Portege M300 */
Dmitry Torokhov5f5eeff2009-10-12 21:35:00 -0700986 .matches = {
987 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
988 DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
989 DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
990 },
991
Simon Horman9ba5eaa2005-07-11 01:07:20 -0500992 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993#endif
Jan Beulich70874862011-03-31 00:01:58 -0700994 { }
Dmitry Torokhov7705d542009-12-03 23:21:14 -0800995};
996
Andres Salomonef8313b2010-12-23 01:19:38 -0800997static bool broken_olpc_ec;
998
999static const struct dmi_system_id __initconst olpc_dmi_table[] = {
1000#if defined(CONFIG_DMI) && defined(CONFIG_OLPC)
1001 {
1002 /* OLPC XO-1 or XO-1.5 */
1003 .matches = {
1004 DMI_MATCH(DMI_SYS_VENDOR, "OLPC"),
1005 DMI_MATCH(DMI_PRODUCT_NAME, "XO"),
1006 },
1007 },
Andres Salomonef8313b2010-12-23 01:19:38 -08001008#endif
Jan Beulich70874862011-03-31 00:01:58 -07001009 { }
Andres Salomonef8313b2010-12-23 01:19:38 -08001010};
1011
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001012void __init synaptics_module_init(void)
1013{
1014 impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
Andres Salomonef8313b2010-12-23 01:19:38 -08001015 broken_olpc_ec = dmi_check_system(olpc_dmi_table);
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001016}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
1018int synaptics_init(struct psmouse *psmouse)
1019{
1020 struct synaptics_data *priv;
1021
Andres Salomonef8313b2010-12-23 01:19:38 -08001022 /*
1023 * The OLPC XO has issues with Synaptics' absolute mode; similarly to
1024 * the HGPK, it quickly degrades and the hardware becomes jumpy and
1025 * overly sensitive. Not only that, but the constant packet spew
1026 * (even at a lowered 40pps rate) overloads the EC such that key
1027 * presses on the keyboard are missed. Given all of that, don't
1028 * even attempt to use Synaptics mode. Relative mode seems to work
1029 * just fine.
1030 */
1031 if (broken_olpc_ec) {
1032 printk(KERN_INFO "synaptics: OLPC XO detected, not enabling Synaptics protocol.\n");
1033 return -ENODEV;
1034 }
1035
Eric Sesterhennb39787a2006-03-14 00:09:16 -05001036 psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 if (!priv)
Davidlohr Bueso6792cbb2010-09-29 18:53:35 -07001038 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Andy Whitcroft4d368452009-02-28 12:51:01 -08001040 psmouse_reset(psmouse);
1041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 if (synaptics_query_hardware(psmouse)) {
1043 printk(KERN_ERR "Unable to query Synaptics hardware.\n");
1044 goto init_fail;
1045 }
1046
1047 if (synaptics_set_absolute_mode(psmouse)) {
1048 printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
1049 goto init_fail;
1050 }
1051
Henrik Rydbergfec6e522010-12-21 18:11:25 +01001052 if (synaptics_set_advanced_gesture_mode(psmouse)) {
1053 printk(KERN_ERR "Advanced gesture mode init failed.\n");
1054 goto init_fail;
1055 }
1056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS;
1058
Takashi Iwai5f57d672010-04-19 10:37:21 -07001059 printk(KERN_INFO "Synaptics Touchpad, model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx\n",
Dmitry Torokhov409b7502005-05-28 02:12:18 -05001060 SYN_ID_MODEL(priv->identity),
1061 SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity),
Takashi Iwai5f57d672010-04-19 10:37:21 -07001062 priv->model_id, priv->capabilities, priv->ext_cap, priv->ext_cap_0c);
Dmitry Torokhov409b7502005-05-28 02:12:18 -05001063
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001064 set_input_params(psmouse->dev, priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Dmitry Torokhov887cc122007-04-12 01:30:41 -04001066 /*
1067 * Encode touchpad model so that it can be used to set
1068 * input device->id.version and be visible to userspace.
1069 * Because version is __u16 we have to drop something.
1070 * Hardware info bits seem to be good candidates as they
1071 * are documented to be for Synaptics corp. internal use.
1072 */
1073 psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) |
1074 (priv->model_id & 0x000000ff);
1075
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 psmouse->protocol_handler = synaptics_process_byte;
1077 psmouse->set_rate = synaptics_set_rate;
1078 psmouse->disconnect = synaptics_disconnect;
1079 psmouse->reconnect = synaptics_reconnect;
Dmitry Torokhova1cec062007-02-18 01:40:24 -05001080 psmouse->cleanup = synaptics_reset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 psmouse->pktsize = 6;
Dmitry Torokhovf0d5c6f2006-01-14 00:27:37 -05001082 /* Synaptics can usually stay in sync without extra help */
1083 psmouse->resync_time = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
1085 if (SYN_CAP_PASS_THROUGH(priv->capabilities))
1086 synaptics_pt_create(psmouse);
1087
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 /*
1089 * Toshiba's KBC seems to have trouble handling data from
Andres Salomon7ee99162010-12-23 01:18:28 -08001090 * Synaptics at full rate. Switch to a lower rate (roughly
1091 * the same rate as a standard PS/2 mouse).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 */
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001093 if (psmouse->rate >= 80 && impaired_toshiba_kbc) {
Simon Horman9ba5eaa2005-07-11 01:07:20 -05001094 printk(KERN_INFO "synaptics: Toshiba %s detected, limiting rate to 40pps.\n",
1095 dmi_get_system_info(DMI_PRODUCT_NAME));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 psmouse->rate = 40;
1097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 return 0;
1100
1101 init_fail:
1102 kfree(priv);
1103 return -1;
1104}
1105
Daniel Drakee4e6efd2010-01-07 01:52:39 -08001106bool synaptics_supported(void)
1107{
1108 return true;
1109}
1110
Andres Salomon55e3d922007-03-10 01:39:54 -05001111#else /* CONFIG_MOUSE_PS2_SYNAPTICS */
1112
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001113void __init synaptics_module_init(void)
1114{
1115}
1116
Andres Salomon55e3d922007-03-10 01:39:54 -05001117int synaptics_init(struct psmouse *psmouse)
1118{
1119 return -ENOSYS;
1120}
1121
Daniel Drakee4e6efd2010-01-07 01:52:39 -08001122bool synaptics_supported(void)
1123{
1124 return false;
1125}
1126
Andres Salomon55e3d922007-03-10 01:39:54 -05001127#endif /* CONFIG_MOUSE_PS2_SYNAPTICS */