blob: b0008bcb26fc8af958a7d377a9c927f83af7d7b4 [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
307 if (!SYN_CAP_ADV_GESTURE(priv->ext_cap_0c))
308 return 0;
309
310 if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL))
311 return -1;
312 if (ps2_command(&psmouse->ps2dev, &param, PSMOUSE_CMD_SETRATE))
313 return -1;
314
315 /* Advanced gesture mode also sends multi finger data */
316 priv->capabilities |= BIT(1);
317
318 return 0;
319}
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321/*****************************************************************************
322 * Synaptics pass-through PS/2 port support
323 ****************************************************************************/
324static int synaptics_pt_write(struct serio *serio, unsigned char c)
325{
326 struct psmouse *parent = serio_get_drvdata(serio->parent);
327 char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */
328
329 if (psmouse_sliced_command(parent, c))
330 return -1;
331 if (ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE))
332 return -1;
333 return 0;
334}
335
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700336static int synaptics_pt_start(struct serio *serio)
337{
338 struct psmouse *parent = serio_get_drvdata(serio->parent);
339 struct synaptics_data *priv = parent->private;
340
341 serio_pause_rx(parent->ps2dev.serio);
342 priv->pt_port = serio;
343 serio_continue_rx(parent->ps2dev.serio);
344
345 return 0;
346}
347
348static void synaptics_pt_stop(struct serio *serio)
349{
350 struct psmouse *parent = serio_get_drvdata(serio->parent);
351 struct synaptics_data *priv = parent->private;
352
353 serio_pause_rx(parent->ps2dev.serio);
354 priv->pt_port = NULL;
355 serio_continue_rx(parent->ps2dev.serio);
356}
357
358static int synaptics_is_pt_packet(unsigned char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
360 return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
361}
362
363static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet)
364{
365 struct psmouse *child = serio_get_drvdata(ptport);
366
367 if (child && child->state == PSMOUSE_ACTIVATED) {
David Howells7d12e782006-10-05 14:55:46 +0100368 serio_interrupt(ptport, packet[1], 0);
369 serio_interrupt(ptport, packet[4], 0);
370 serio_interrupt(ptport, packet[5], 0);
Sergey Vlasov33fdfa92005-07-24 00:53:32 -0500371 if (child->pktsize == 4)
David Howells7d12e782006-10-05 14:55:46 +0100372 serio_interrupt(ptport, packet[2], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 } else
David Howells7d12e782006-10-05 14:55:46 +0100374 serio_interrupt(ptport, packet[1], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375}
376
377static void synaptics_pt_activate(struct psmouse *psmouse)
378{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 struct synaptics_data *priv = psmouse->private;
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700380 struct psmouse *child = serio_get_drvdata(priv->pt_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382 /* adjust the touchpad to child's choice of protocol */
383 if (child) {
Sergey Vlasov33fdfa92005-07-24 00:53:32 -0500384 if (child->pktsize == 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
386 else
387 priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
388
389 if (synaptics_mode_cmd(psmouse, priv->mode))
390 printk(KERN_INFO "synaptics: failed to switch guest protocol\n");
391 }
392}
393
394static void synaptics_pt_create(struct psmouse *psmouse)
395{
396 struct serio *serio;
397
Eric Sesterhennb39787a2006-03-14 00:09:16 -0500398 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (!serio) {
400 printk(KERN_ERR "synaptics: not enough memory to allocate pass-through port\n");
401 return;
402 }
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 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;
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700408 serio->start = synaptics_pt_start;
409 serio->stop = synaptics_pt_stop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 serio->parent = psmouse->ps2dev.serio;
411
412 psmouse->pt_activate = synaptics_pt_activate;
413
414 printk(KERN_INFO "serio: %s port at %s\n", serio->name, psmouse->phys);
415 serio_register_port(serio);
416}
417
418/*****************************************************************************
419 * Functions to interpret the absolute mode packets
420 ****************************************************************************/
421
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100422static int synaptics_parse_hw_state(const unsigned char buf[],
423 struct synaptics_data *priv,
424 struct synaptics_hw_state *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{
426 memset(hw, 0, sizeof(struct synaptics_hw_state));
427
428 if (SYN_MODEL_NEWABS(priv->model_id)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 hw->w = (((buf[0] & 0x30) >> 2) |
430 ((buf[0] & 0x04) >> 1) |
431 ((buf[3] & 0x04) >> 2));
432
433 hw->left = (buf[0] & 0x01) ? 1 : 0;
434 hw->right = (buf[0] & 0x02) ? 1 : 0;
435
Takashi Iwai5f57d672010-04-19 10:37:21 -0700436 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
437 /*
438 * Clickpad's button is transmitted as middle button,
439 * however, since it is primary button, we will report
440 * it as BTN_LEFT.
441 */
442 hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
443
444 } else if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
446 if (hw->w == 2)
447 hw->scroll = (signed char)(buf[1]);
448 }
449
450 if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
451 hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
452 hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
453 }
454
Daniel Kurtz28d5fd82011-07-06 22:57:39 -0700455 if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) && hw->w == 2) {
456 /* Gesture packet: (x, y, z) at half resolution */
457 priv->mt.x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
458 priv->mt.y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1;
459 priv->mt.z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
460 return 1;
461 }
462
463 hw->x = (((buf[3] & 0x10) << 8) |
464 ((buf[1] & 0x0f) << 8) |
465 buf[4]);
466 hw->y = (((buf[3] & 0x20) << 7) |
467 ((buf[1] & 0xf0) << 4) |
468 buf[5]);
469 hw->z = buf[2];
470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
472 ((buf[0] ^ buf[3]) & 0x02)) {
473 switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
474 default:
475 /*
476 * if nExtBtn is greater than 8 it should be
477 * considered invalid and treated as 0
478 */
479 break;
480 case 8:
481 hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0;
482 hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0;
483 case 6:
484 hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0;
485 hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0;
486 case 4:
487 hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0;
488 hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0;
489 case 2:
490 hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0;
491 hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0;
492 }
493 }
494 } else {
495 hw->x = (((buf[1] & 0x1f) << 8) | buf[2]);
496 hw->y = (((buf[4] & 0x1f) << 8) | buf[5]);
497
498 hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
499 hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
500
501 hw->left = (buf[0] & 0x01) ? 1 : 0;
502 hw->right = (buf[0] & 0x02) ? 1 : 0;
503 }
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100504
505 return 0;
506}
507
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700508static void synaptics_report_semi_mt_slot(struct input_dev *dev, int slot,
509 bool active, int x, int y)
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100510{
511 input_mt_slot(dev, slot);
512 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
513 if (active) {
514 input_report_abs(dev, ABS_MT_POSITION_X, x);
Daniel Kurtz6de58dd2011-08-23 23:00:24 -0700515 input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(y));
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100516 }
517}
518
519static void synaptics_report_semi_mt_data(struct input_dev *dev,
520 const struct synaptics_hw_state *a,
521 const struct synaptics_hw_state *b,
522 int num_fingers)
523{
524 if (num_fingers >= 2) {
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700525 synaptics_report_semi_mt_slot(dev, 0, true, min(a->x, b->x),
526 min(a->y, b->y));
527 synaptics_report_semi_mt_slot(dev, 1, true, max(a->x, b->x),
528 max(a->y, b->y));
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100529 } else if (num_fingers == 1) {
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700530 synaptics_report_semi_mt_slot(dev, 0, true, a->x, a->y);
531 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100532 } else {
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700533 synaptics_report_semi_mt_slot(dev, 0, false, 0, 0);
534 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536}
537
538/*
539 * called for each full received packet from the touchpad
540 */
541static void synaptics_process_packet(struct psmouse *psmouse)
542{
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500543 struct input_dev *dev = psmouse->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 struct synaptics_data *priv = psmouse->private;
545 struct synaptics_hw_state hw;
546 int num_fingers;
547 int finger_width;
548 int i;
549
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100550 if (synaptics_parse_hw_state(psmouse->packet, priv, &hw))
551 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 if (hw.scroll) {
554 priv->scroll += hw.scroll;
555
556 while (priv->scroll >= 4) {
557 input_report_key(dev, BTN_BACK, !hw.down);
558 input_sync(dev);
559 input_report_key(dev, BTN_BACK, hw.down);
560 input_sync(dev);
561 priv->scroll -= 4;
562 }
563 while (priv->scroll <= -4) {
564 input_report_key(dev, BTN_FORWARD, !hw.up);
565 input_sync(dev);
566 input_report_key(dev, BTN_FORWARD, hw.up);
567 input_sync(dev);
568 priv->scroll += 4;
569 }
570 return;
571 }
572
Henrik Rydberg4f56ce92010-12-18 15:42:30 +0100573 if (hw.z > 0 && hw.x > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 num_fingers = 1;
575 finger_width = 5;
576 if (SYN_CAP_EXTENDED(priv->capabilities)) {
577 switch (hw.w) {
578 case 0 ... 1:
579 if (SYN_CAP_MULTIFINGER(priv->capabilities))
580 num_fingers = hw.w + 2;
581 break;
582 case 2:
583 if (SYN_MODEL_PEN(priv->model_id))
584 ; /* Nothing, treat a pen as a single finger */
585 break;
586 case 4 ... 15:
587 if (SYN_CAP_PALMDETECT(priv->capabilities))
588 finger_width = hw.w;
589 break;
590 }
591 }
592 } else {
593 num_fingers = 0;
594 finger_width = 0;
595 }
596
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100597 if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c))
598 synaptics_report_semi_mt_data(dev, &hw, &priv->mt, num_fingers);
599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 /* Post events
601 * BTN_TOUCH has to be first as mousedev relies on it when doing
602 * absolute -> relative conversion
603 */
604 if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1);
605 if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0);
606
Henrik Rydberg4f56ce92010-12-18 15:42:30 +0100607 if (num_fingers > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 input_report_abs(dev, ABS_X, hw.x);
Daniel Kurtz6de58dd2011-08-23 23:00:24 -0700609 input_report_abs(dev, ABS_Y, synaptics_invert_y(hw.y));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 }
611 input_report_abs(dev, ABS_PRESSURE, hw.z);
612
Chris Bagwell2a8e7712010-07-19 09:06:15 -0700613 if (SYN_CAP_PALMDETECT(priv->capabilities))
614 input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 input_report_key(dev, BTN_LEFT, hw.left);
618 input_report_key(dev, BTN_RIGHT, hw.right);
619
Peter Hutterere42b6642008-11-20 15:24:42 -0500620 if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
621 input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
622 input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
623 }
624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
626 input_report_key(dev, BTN_MIDDLE, hw.middle);
627
628 if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
629 input_report_key(dev, BTN_FORWARD, hw.up);
630 input_report_key(dev, BTN_BACK, hw.down);
631 }
632
633 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
634 input_report_key(dev, BTN_0 + i, hw.ext_buttons & (1 << i));
635
636 input_sync(dev);
637}
638
639static int synaptics_validate_byte(unsigned char packet[], int idx, unsigned char pkt_type)
640{
Helge Dellere38de672006-09-10 21:54:39 -0400641 static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
642 static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
643 static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
644 static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
645 static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
647 if (idx < 0 || idx > 4)
648 return 0;
649
650 switch (pkt_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700652 case SYN_NEWABS:
653 case SYN_NEWABS_RELAXED:
654 return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700656 case SYN_NEWABS_STRICT:
657 return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700659 case SYN_OLDABS:
660 return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx];
661
662 default:
663 printk(KERN_ERR "synaptics: unknown packet type %d\n", pkt_type);
664 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 }
666}
667
668static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse)
669{
670 int i;
671
672 for (i = 0; i < 5; i++)
673 if (!synaptics_validate_byte(psmouse->packet, i, SYN_NEWABS_STRICT)) {
674 printk(KERN_INFO "synaptics: using relaxed packet validation\n");
675 return SYN_NEWABS_RELAXED;
676 }
677
678 return SYN_NEWABS_STRICT;
679}
680
David Howells7d12e782006-10-05 14:55:46 +0100681static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 struct synaptics_data *priv = psmouse->private;
684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 if (psmouse->pktcnt >= 6) { /* Full packet received */
686 if (unlikely(priv->pkt_type == SYN_NEWABS))
687 priv->pkt_type = synaptics_detect_pkt_type(psmouse);
688
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700689 if (SYN_CAP_PASS_THROUGH(priv->capabilities) &&
690 synaptics_is_pt_packet(psmouse->packet)) {
691 if (priv->pt_port)
692 synaptics_pass_pt_packet(priv->pt_port, psmouse->packet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 } else
694 synaptics_process_packet(psmouse);
695
696 return PSMOUSE_FULL_PACKET;
697 }
698
699 return synaptics_validate_byte(psmouse->packet, psmouse->pktcnt - 1, priv->pkt_type) ?
700 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
701}
702
703/*****************************************************************************
704 * Driver initialization/cleanup functions
705 ****************************************************************************/
706static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
707{
708 int i;
Daniel Kurtza9f0b792011-07-06 22:39:14 -0700709 int fuzz = SYN_CAP_REDUCED_FILTERING(priv->ext_cap_0c) ?
710 SYN_REDUCED_FILTER_FUZZ : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Henrik Rydbergc14890a2010-12-16 09:52:23 +0100712 __set_bit(INPUT_PROP_POINTER, dev->propbit);
713
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700714 __set_bit(EV_ABS, dev->evbit);
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700715 input_set_abs_params(dev, ABS_X,
716 priv->x_min ?: XMIN_NOMINAL,
717 priv->x_max ?: XMAX_NOMINAL,
718 fuzz, 0);
719 input_set_abs_params(dev, ABS_Y,
720 priv->y_min ?: YMIN_NOMINAL,
721 priv->y_max ?: YMAX_NOMINAL,
722 fuzz, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
Chris Bagwell2a8e7712010-07-19 09:06:15 -0700724
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100725 if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) {
726 __set_bit(INPUT_PROP_SEMI_MT, dev->propbit);
727 input_mt_init_slots(dev, 2);
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700728 input_set_abs_params(dev, ABS_MT_POSITION_X,
729 priv->x_min ?: XMIN_NOMINAL,
730 priv->x_max ?: XMAX_NOMINAL,
731 fuzz, 0);
732 input_set_abs_params(dev, ABS_MT_POSITION_Y,
733 priv->y_min ?: YMIN_NOMINAL,
734 priv->y_max ?: YMAX_NOMINAL,
735 fuzz, 0);
Daniel Kurtz8be3c652011-07-06 22:27:47 -0700736
737 input_abs_set_res(dev, ABS_MT_POSITION_X, priv->x_res);
738 input_abs_set_res(dev, ABS_MT_POSITION_Y, priv->y_res);
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100739 }
740
Chris Bagwell2a8e7712010-07-19 09:06:15 -0700741 if (SYN_CAP_PALMDETECT(priv->capabilities))
Chris Bagwell58fb0212010-07-19 09:06:15 -0700742 input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700744 __set_bit(EV_KEY, dev->evbit);
745 __set_bit(BTN_TOUCH, dev->keybit);
746 __set_bit(BTN_TOOL_FINGER, dev->keybit);
747 __set_bit(BTN_LEFT, dev->keybit);
748 __set_bit(BTN_RIGHT, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Peter Hutterere42b6642008-11-20 15:24:42 -0500750 if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700751 __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
752 __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
Peter Hutterere42b6642008-11-20 15:24:42 -0500753 }
754
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700756 __set_bit(BTN_MIDDLE, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
758 if (SYN_CAP_FOUR_BUTTON(priv->capabilities) ||
759 SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700760 __set_bit(BTN_FORWARD, dev->keybit);
761 __set_bit(BTN_BACK, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 }
763
764 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700765 __set_bit(BTN_0 + i, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700767 __clear_bit(EV_REL, dev->evbit);
768 __clear_bit(REL_X, dev->relbit);
769 __clear_bit(REL_Y, dev->relbit);
Tero Saarniec20a022009-06-10 23:27:24 -0700770
Daniel Mack987a6c02010-08-02 20:15:17 -0700771 input_abs_set_res(dev, ABS_X, priv->x_res);
772 input_abs_set_res(dev, ABS_Y, priv->y_res);
Takashi Iwai5f57d672010-04-19 10:37:21 -0700773
774 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
Henrik Rydbergc14890a2010-12-16 09:52:23 +0100775 __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
Takashi Iwai5f57d672010-04-19 10:37:21 -0700776 /* Clickpads report only left button */
777 __clear_bit(BTN_RIGHT, dev->keybit);
778 __clear_bit(BTN_MIDDLE, dev->keybit);
779 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780}
781
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782static void synaptics_disconnect(struct psmouse *psmouse)
783{
784 synaptics_reset(psmouse);
785 kfree(psmouse->private);
786 psmouse->private = NULL;
787}
788
789static int synaptics_reconnect(struct psmouse *psmouse)
790{
791 struct synaptics_data *priv = psmouse->private;
792 struct synaptics_data old_priv = *priv;
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -0800793 int retry = 0;
794 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -0800796 do {
797 psmouse_reset(psmouse);
798 error = synaptics_detect(psmouse, 0);
799 } while (error && ++retry < 3);
Andy Whitcroft4d368452009-02-28 12:51:01 -0800800
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -0800801 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 return -1;
803
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -0800804 if (retry > 1)
805 printk(KERN_DEBUG "Synaptics reconnected after %d tries\n",
806 retry);
807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 if (synaptics_query_hardware(psmouse)) {
809 printk(KERN_ERR "Unable to query Synaptics hardware.\n");
810 return -1;
811 }
812
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 if (synaptics_set_absolute_mode(psmouse)) {
814 printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
815 return -1;
816 }
817
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100818 if (synaptics_set_advanced_gesture_mode(psmouse)) {
819 printk(KERN_ERR "Advanced gesture mode reconnect failed.\n");
820 return -1;
821 }
822
Alexandre Peixoto Ferreirabaddf582011-01-28 22:05:14 -0800823 if (old_priv.identity != priv->identity ||
824 old_priv.model_id != priv->model_id ||
825 old_priv.capabilities != priv->capabilities ||
826 old_priv.ext_cap != priv->ext_cap) {
827 printk(KERN_ERR "Synaptics hardware appears to be different: "
828 "id(%ld-%ld), model(%ld-%ld), caps(%lx-%lx), ext(%lx-%lx).\n",
829 old_priv.identity, priv->identity,
830 old_priv.model_id, priv->model_id,
831 old_priv.capabilities, priv->capabilities,
832 old_priv.ext_cap, priv->ext_cap);
833 return -1;
834 }
835
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 return 0;
837}
838
Dmitry Torokhov7705d542009-12-03 23:21:14 -0800839static bool impaired_toshiba_kbc;
840
841static const struct dmi_system_id __initconst toshiba_dmi_table[] = {
842#if defined(CONFIG_DMI) && defined(CONFIG_X86)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -0800844 /* Toshiba Satellite */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 .matches = {
846 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
Richard Thrippleton53a26702006-04-02 00:10:18 -0500847 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 },
849 },
Simon Horman9ba5eaa2005-07-11 01:07:20 -0500850 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -0800851 /* Toshiba Dynabook */
Simon Horman9ba5eaa2005-07-11 01:07:20 -0500852 .matches = {
853 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
Richard Thrippleton53a26702006-04-02 00:10:18 -0500854 DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
855 },
856 },
857 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -0800858 /* Toshiba Portege M300 */
Richard Thrippleton53a26702006-04-02 00:10:18 -0500859 .matches = {
860 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
861 DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
Simon Horman9ba5eaa2005-07-11 01:07:20 -0500862 },
Dmitry Torokhov5f5eeff2009-10-12 21:35:00 -0700863
864 },
865 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -0800866 /* Toshiba Portege M300 */
Dmitry Torokhov5f5eeff2009-10-12 21:35:00 -0700867 .matches = {
868 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
869 DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
870 DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
871 },
872
Simon Horman9ba5eaa2005-07-11 01:07:20 -0500873 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874#endif
Jan Beulich70874862011-03-31 00:01:58 -0700875 { }
Dmitry Torokhov7705d542009-12-03 23:21:14 -0800876};
877
Andres Salomonef8313b2010-12-23 01:19:38 -0800878static bool broken_olpc_ec;
879
880static const struct dmi_system_id __initconst olpc_dmi_table[] = {
881#if defined(CONFIG_DMI) && defined(CONFIG_OLPC)
882 {
883 /* OLPC XO-1 or XO-1.5 */
884 .matches = {
885 DMI_MATCH(DMI_SYS_VENDOR, "OLPC"),
886 DMI_MATCH(DMI_PRODUCT_NAME, "XO"),
887 },
888 },
Andres Salomonef8313b2010-12-23 01:19:38 -0800889#endif
Jan Beulich70874862011-03-31 00:01:58 -0700890 { }
Andres Salomonef8313b2010-12-23 01:19:38 -0800891};
892
Dmitry Torokhov7705d542009-12-03 23:21:14 -0800893void __init synaptics_module_init(void)
894{
895 impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
Andres Salomonef8313b2010-12-23 01:19:38 -0800896 broken_olpc_ec = dmi_check_system(olpc_dmi_table);
Dmitry Torokhov7705d542009-12-03 23:21:14 -0800897}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899int synaptics_init(struct psmouse *psmouse)
900{
901 struct synaptics_data *priv;
902
Andres Salomonef8313b2010-12-23 01:19:38 -0800903 /*
904 * The OLPC XO has issues with Synaptics' absolute mode; similarly to
905 * the HGPK, it quickly degrades and the hardware becomes jumpy and
906 * overly sensitive. Not only that, but the constant packet spew
907 * (even at a lowered 40pps rate) overloads the EC such that key
908 * presses on the keyboard are missed. Given all of that, don't
909 * even attempt to use Synaptics mode. Relative mode seems to work
910 * just fine.
911 */
912 if (broken_olpc_ec) {
913 printk(KERN_INFO "synaptics: OLPC XO detected, not enabling Synaptics protocol.\n");
914 return -ENODEV;
915 }
916
Eric Sesterhennb39787a2006-03-14 00:09:16 -0500917 psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 if (!priv)
Davidlohr Bueso6792cbb2010-09-29 18:53:35 -0700919 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
Andy Whitcroft4d368452009-02-28 12:51:01 -0800921 psmouse_reset(psmouse);
922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 if (synaptics_query_hardware(psmouse)) {
924 printk(KERN_ERR "Unable to query Synaptics hardware.\n");
925 goto init_fail;
926 }
927
928 if (synaptics_set_absolute_mode(psmouse)) {
929 printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
930 goto init_fail;
931 }
932
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100933 if (synaptics_set_advanced_gesture_mode(psmouse)) {
934 printk(KERN_ERR "Advanced gesture mode init failed.\n");
935 goto init_fail;
936 }
937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS;
939
Takashi Iwai5f57d672010-04-19 10:37:21 -0700940 printk(KERN_INFO "Synaptics Touchpad, model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx\n",
Dmitry Torokhov409b7502005-05-28 02:12:18 -0500941 SYN_ID_MODEL(priv->identity),
942 SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity),
Takashi Iwai5f57d672010-04-19 10:37:21 -0700943 priv->model_id, priv->capabilities, priv->ext_cap, priv->ext_cap_0c);
Dmitry Torokhov409b7502005-05-28 02:12:18 -0500944
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500945 set_input_params(psmouse->dev, priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
Dmitry Torokhov887cc122007-04-12 01:30:41 -0400947 /*
948 * Encode touchpad model so that it can be used to set
949 * input device->id.version and be visible to userspace.
950 * Because version is __u16 we have to drop something.
951 * Hardware info bits seem to be good candidates as they
952 * are documented to be for Synaptics corp. internal use.
953 */
954 psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) |
955 (priv->model_id & 0x000000ff);
956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 psmouse->protocol_handler = synaptics_process_byte;
958 psmouse->set_rate = synaptics_set_rate;
959 psmouse->disconnect = synaptics_disconnect;
960 psmouse->reconnect = synaptics_reconnect;
Dmitry Torokhova1cec062007-02-18 01:40:24 -0500961 psmouse->cleanup = synaptics_reset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 psmouse->pktsize = 6;
Dmitry Torokhovf0d5c6f2006-01-14 00:27:37 -0500963 /* Synaptics can usually stay in sync without extra help */
964 psmouse->resync_time = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
966 if (SYN_CAP_PASS_THROUGH(priv->capabilities))
967 synaptics_pt_create(psmouse);
968
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 /*
970 * Toshiba's KBC seems to have trouble handling data from
Andres Salomon7ee99162010-12-23 01:18:28 -0800971 * Synaptics at full rate. Switch to a lower rate (roughly
972 * the same rate as a standard PS/2 mouse).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 */
Dmitry Torokhov7705d542009-12-03 23:21:14 -0800974 if (psmouse->rate >= 80 && impaired_toshiba_kbc) {
Simon Horman9ba5eaa2005-07-11 01:07:20 -0500975 printk(KERN_INFO "synaptics: Toshiba %s detected, limiting rate to 40pps.\n",
976 dmi_get_system_info(DMI_PRODUCT_NAME));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 psmouse->rate = 40;
978 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 return 0;
981
982 init_fail:
983 kfree(priv);
984 return -1;
985}
986
Daniel Drakee4e6efd2010-01-07 01:52:39 -0800987bool synaptics_supported(void)
988{
989 return true;
990}
991
Andres Salomon55e3d922007-03-10 01:39:54 -0500992#else /* CONFIG_MOUSE_PS2_SYNAPTICS */
993
Dmitry Torokhov7705d542009-12-03 23:21:14 -0800994void __init synaptics_module_init(void)
995{
996}
997
Andres Salomon55e3d922007-03-10 01:39:54 -0500998int synaptics_init(struct psmouse *psmouse)
999{
1000 return -ENOSYS;
1001}
1002
Daniel Drakee4e6efd2010-01-07 01:52:39 -08001003bool synaptics_supported(void)
1004{
1005 return false;
1006}
1007
Andres Salomon55e3d922007-03-10 01:39:54 -05001008#endif /* CONFIG_MOUSE_PS2_SYNAPTICS */