blob: f2cceb6493a0aea304c838043735ac3889041438 [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 Torokhov85214782011-12-12 00:05:53 -080027#include <linux/delay.h>
Dmitry Torokhov7705d542009-12-03 23:21:14 -080028#include <linux/dmi.h>
Henrik Rydbergfec6e522010-12-21 18:11:25 +010029#include <linux/input/mt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/serio.h>
31#include <linux/libps2.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "psmouse.h"
34#include "synaptics.h"
35
36/*
37 * The x/y limits are taken from the Synaptics TouchPad interfacing Guide,
38 * section 2.3.2, which says that they should be valid regardless of the
39 * actual size of the sensor.
Dmitry Torokhov83ba9ea82010-05-10 23:06:52 -070040 * Note that newer firmware allows querying device for maximum useable
41 * coordinates.
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 */
Seth Forsheec03945062012-07-24 23:54:11 -070043#define XMIN 0
44#define XMAX 6143
45#define YMIN 0
46#define YMAX 6143
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define XMIN_NOMINAL 1472
48#define XMAX_NOMINAL 5472
49#define YMIN_NOMINAL 1408
50#define YMAX_NOMINAL 4448
51
Seth Forsheec03945062012-07-24 23:54:11 -070052/* Size in bits of absolute position values reported by the hardware */
53#define ABS_POS_BITS 13
54
55/*
Seth Forshee824efd32012-09-28 10:29:21 -070056 * These values should represent the absolute maximum value that will
57 * be reported for a positive position value. Some Synaptics firmware
58 * uses this value to indicate a finger near the edge of the touchpad
59 * whose precise position cannot be determined.
60 *
61 * At least one touchpad is known to report positions in excess of this
62 * value which are actually negative values truncated to the 13-bit
63 * reporting range. These values have never been observed to be lower
64 * than 8184 (i.e. -8), so we treat all values greater than 8176 as
65 * negative and any other value as positive.
Seth Forsheec03945062012-07-24 23:54:11 -070066 */
Seth Forshee824efd32012-09-28 10:29:21 -070067#define X_MAX_POSITIVE 8176
68#define Y_MAX_POSITIVE 8176
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Benjamin Tissoires6ab17a82015-02-03 15:33:49 -080070/* maximum ABS_MT_POSITION displacement (in mm) */
71#define DMAX 10
72
Andres Salomon55e3d922007-03-10 01:39:54 -050073/*****************************************************************************
74 * Stuff we need even when we do not want native Synaptics support
75 ****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/*
78 * Set the synaptics touchpad mode byte by special commands
79 */
80static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode)
81{
82 unsigned char param[1];
83
84 if (psmouse_sliced_command(psmouse, mode))
85 return -1;
86 param[0] = SYN_PS_SET_MODE2;
87 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE))
88 return -1;
89 return 0;
90}
91
Dmitry Torokhovb7802c52009-09-09 19:13:20 -070092int synaptics_detect(struct psmouse *psmouse, bool set_properties)
Andres Salomon55e3d922007-03-10 01:39:54 -050093{
94 struct ps2dev *ps2dev = &psmouse->ps2dev;
95 unsigned char param[4];
96
97 param[0] = 0;
98
99 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
100 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
101 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
102 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
103 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
104
105 if (param[1] != 0x47)
106 return -ENODEV;
107
108 if (set_properties) {
109 psmouse->vendor = "Synaptics";
110 psmouse->name = "TouchPad";
111 }
112
113 return 0;
114}
115
116void synaptics_reset(struct psmouse *psmouse)
117{
118 /* reset touchpad back to relative mode, gestures enabled */
119 synaptics_mode_cmd(psmouse, 0);
120}
121
122#ifdef CONFIG_MOUSE_PS2_SYNAPTICS
Henrik Rydberge08d9af2014-07-14 10:26:56 -0700123
124static bool cr48_profile_sensor;
125
Hans de Goede0f68f392014-05-19 22:54:09 -0700126struct min_max_quirk {
127 const char * const *pnp_ids;
128 int x_min, x_max, y_min, y_max;
129};
130
131static const struct min_max_quirk min_max_pnpid_table[] = {
132 {
133 (const char * const []){"LEN0033", NULL},
134 1024, 5052, 2258, 4832
135 },
136 {
137 (const char * const []){"LEN0035", "LEN0042", NULL},
138 1232, 5710, 1156, 4696
139 },
140 {
Peter Hutterer8543cf12015-01-19 16:29:25 -0800141 (const char * const []){"LEN0034", "LEN0036", "LEN0037",
142 "LEN0039", "LEN2002", "LEN2004",
143 NULL},
Hans de Goede0f68f392014-05-19 22:54:09 -0700144 1024, 5112, 2024, 4832
145 },
146 {
147 (const char * const []){"LEN2001", NULL},
148 1024, 5022, 2508, 4832
149 },
Ben Sagalbce4f9e2014-11-16 17:23:40 -0800150 {
151 (const char * const []){"LEN2006", NULL},
152 1264, 5675, 1171, 4688
153 },
Hans de Goede0f68f392014-05-19 22:54:09 -0700154 { }
155};
156
Hans de Goede43e19882014-04-19 22:26:41 -0700157/* This list has been kindly provided by Synaptics. */
158static const char * const topbuttonpad_pnp_ids[] = {
159 "LEN0017",
160 "LEN0018",
161 "LEN0019",
162 "LEN0023",
163 "LEN002A",
164 "LEN002B",
165 "LEN002C",
166 "LEN002D",
167 "LEN002E",
168 "LEN0033", /* Helix */
Hans de Goede0f68f392014-05-19 22:54:09 -0700169 "LEN0034", /* T431s, L440, L540, T540, W540, X1 Carbon 2nd */
Hans de Goede43e19882014-04-19 22:26:41 -0700170 "LEN0035", /* X240 */
171 "LEN0036", /* T440 */
Peter Hutterer8543cf12015-01-19 16:29:25 -0800172 "LEN0037", /* X1 Carbon 2nd */
Hans de Goede43e19882014-04-19 22:26:41 -0700173 "LEN0038",
Takashi Iwaie4742b12014-11-06 09:27:11 -0800174 "LEN0039", /* T440s */
Hans de Goede43e19882014-04-19 22:26:41 -0700175 "LEN0041",
176 "LEN0042", /* Yoga */
177 "LEN0045",
178 "LEN0046",
179 "LEN0047",
180 "LEN0048",
181 "LEN0049",
182 "LEN2000",
Hans de Goede0f68f392014-05-19 22:54:09 -0700183 "LEN2001", /* Edge E431 */
Hans de Goedee76aed92014-07-14 17:12:21 -0700184 "LEN2002", /* Edge E531 */
Hans de Goede43e19882014-04-19 22:26:41 -0700185 "LEN2003",
186 "LEN2004", /* L440 */
187 "LEN2005",
188 "LEN2006",
189 "LEN2007",
190 "LEN2008",
191 "LEN2009",
192 "LEN200A",
193 "LEN200B",
194 NULL
195};
Andres Salomon55e3d922007-03-10 01:39:54 -0500196
197/*****************************************************************************
198 * Synaptics communications functions
199 ****************************************************************************/
200
201/*
JJ Ding1a49a0a2012-05-10 22:32:00 -0700202 * Synaptics touchpads report the y coordinate from bottom to top, which is
203 * opposite from what userspace expects.
204 * This function is used to invert y before reporting.
205 */
206static int synaptics_invert_y(int y)
207{
208 return YMAX_NOMINAL + YMIN_NOMINAL - y;
209}
210
211/*
Andres Salomon55e3d922007-03-10 01:39:54 -0500212 * Send a command to the synpatics touchpad by special commands
213 */
214static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param)
215{
216 if (psmouse_sliced_command(psmouse, c))
217 return -1;
218 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO))
219 return -1;
220 return 0;
221}
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223/*
224 * Read the model-id bytes from the touchpad
225 * see also SYN_MODEL_* macros
226 */
227static int synaptics_model_id(struct psmouse *psmouse)
228{
229 struct synaptics_data *priv = psmouse->private;
230 unsigned char mi[3];
231
232 if (synaptics_send_cmd(psmouse, SYN_QUE_MODEL, mi))
233 return -1;
234 priv->model_id = (mi[0]<<16) | (mi[1]<<8) | mi[2];
235 return 0;
236}
237
238/*
Daniel Kurtzc6bd9d42012-07-07 18:08:51 -0700239 * Read the board id from the touchpad
240 * The board id is encoded in the "QUERY MODES" response
241 */
242static int synaptics_board_id(struct psmouse *psmouse)
243{
244 struct synaptics_data *priv = psmouse->private;
245 unsigned char bid[3];
246
247 if (synaptics_send_cmd(psmouse, SYN_QUE_MODES, bid))
248 return -1;
249 priv->board_id = ((bid[0] & 0xfc) << 6) | bid[1];
250 return 0;
251}
252
253/*
254 * Read the firmware id from the touchpad
255 */
256static int synaptics_firmware_id(struct psmouse *psmouse)
257{
258 struct synaptics_data *priv = psmouse->private;
259 unsigned char fwid[3];
260
261 if (synaptics_send_cmd(psmouse, SYN_QUE_FIRMWARE_ID, fwid))
262 return -1;
263 priv->firmware_id = (fwid[0] << 16) | (fwid[1] << 8) | fwid[2];
264 return 0;
265}
266
267/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 * Read the capability-bits from the touchpad
269 * see also the SYN_CAP_* macros
270 */
271static int synaptics_capability(struct psmouse *psmouse)
272{
273 struct synaptics_data *priv = psmouse->private;
274 unsigned char cap[3];
275
276 if (synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap))
277 return -1;
278 priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
Takashi Iwai5f57d672010-04-19 10:37:21 -0700279 priv->ext_cap = priv->ext_cap_0c = 0;
280
Dmitry Torokhov3619b8f2010-07-21 00:01:19 -0700281 /*
282 * Older firmwares had submodel ID fixed to 0x47
283 */
284 if (SYN_ID_FULL(priv->identity) < 0x705 &&
285 SYN_CAP_SUBMODEL_ID(priv->capabilities) != 0x47) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 return -1;
Dmitry Torokhov3619b8f2010-07-21 00:01:19 -0700287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 /*
290 * Unless capExtended is set the rest of the flags should be ignored
291 */
292 if (!SYN_CAP_EXTENDED(priv->capabilities))
293 priv->capabilities = 0;
294
295 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 1) {
296 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB, cap)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700297 psmouse_warn(psmouse,
298 "device claims to have extended capabilities, but I'm not able to read them.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 } else {
300 priv->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
301
302 /*
303 * if nExtBtn is greater than 8 it should be considered
304 * invalid and treated as 0
305 */
306 if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) > 8)
307 priv->ext_cap &= 0xff0fff;
308 }
309 }
Takashi Iwai5f57d672010-04-19 10:37:21 -0700310
311 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 4) {
312 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB_0C, cap)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700313 psmouse_warn(psmouse,
314 "device claims to have extended capability 0x0c, but I'm not able to read it.\n");
Takashi Iwai5f57d672010-04-19 10:37:21 -0700315 } else {
316 priv->ext_cap_0c = (cap[0] << 16) | (cap[1] << 8) | cap[2];
317 }
318 }
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 return 0;
321}
322
323/*
324 * Identify Touchpad
325 * See also the SYN_ID_* macros
326 */
327static int synaptics_identify(struct psmouse *psmouse)
328{
329 struct synaptics_data *priv = psmouse->private;
330 unsigned char id[3];
331
332 if (synaptics_send_cmd(psmouse, SYN_QUE_IDENTIFY, id))
333 return -1;
334 priv->identity = (id[0]<<16) | (id[1]<<8) | id[2];
335 if (SYN_ID_IS_SYNAPTICS(priv->identity))
336 return 0;
337 return -1;
338}
339
Tero Saarniec20a022009-06-10 23:27:24 -0700340/*
Dmitry Torokhov83ba9ea82010-05-10 23:06:52 -0700341 * Read touchpad resolution and maximum reported coordinates
Tero Saarniec20a022009-06-10 23:27:24 -0700342 * Resolution is left zero if touchpad does not support the query
343 */
Benjamin Tissoires421e08c2014-03-28 00:43:00 -0700344
Tero Saarniec20a022009-06-10 23:27:24 -0700345static int synaptics_resolution(struct psmouse *psmouse)
346{
347 struct synaptics_data *priv = psmouse->private;
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700348 unsigned char resp[3];
Hans de Goede0f68f392014-05-19 22:54:09 -0700349 int i;
Tero Saarniec20a022009-06-10 23:27:24 -0700350
351 if (SYN_ID_MAJOR(priv->identity) < 4)
Takashi Iwaibbddd192010-07-14 09:32:46 -0700352 return 0;
Tero Saarniec20a022009-06-10 23:27:24 -0700353
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700354 if (synaptics_send_cmd(psmouse, SYN_QUE_RESOLUTION, resp) == 0) {
355 if (resp[0] != 0 && (resp[1] & 0x80) && resp[2] != 0) {
356 priv->x_res = resp[0]; /* x resolution in units/mm */
357 priv->y_res = resp[2]; /* y resolution in units/mm */
Dmitry Torokhov83ba9ea82010-05-10 23:06:52 -0700358 }
359 }
Tero Saarniec20a022009-06-10 23:27:24 -0700360
Benjamin Tissoiresd49cb7a2014-06-07 22:37:47 -0700361 for (i = 0; min_max_pnpid_table[i].pnp_ids; i++) {
Hans de Goede2c75ada2014-09-11 10:14:09 -0700362 if (psmouse_matches_pnp_id(psmouse,
363 min_max_pnpid_table[i].pnp_ids)) {
Benjamin Tissoiresd49cb7a2014-06-07 22:37:47 -0700364 priv->x_min = min_max_pnpid_table[i].x_min;
365 priv->x_max = min_max_pnpid_table[i].x_max;
366 priv->y_min = min_max_pnpid_table[i].y_min;
367 priv->y_max = min_max_pnpid_table[i].y_max;
368 return 0;
369 }
370 }
371
Dmitry Torokhov83ba9ea82010-05-10 23:06:52 -0700372 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 5 &&
373 SYN_CAP_MAX_DIMENSIONS(priv->ext_cap_0c)) {
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700374 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_MAX_COORDS, resp)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700375 psmouse_warn(psmouse,
376 "device claims to have max coordinates query, but I'm not able to read it.\n");
Dmitry Torokhov83ba9ea82010-05-10 23:06:52 -0700377 } else {
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700378 priv->x_max = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
379 priv->y_max = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
380 }
381 }
382
383 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 7 &&
384 SYN_CAP_MIN_DIMENSIONS(priv->ext_cap_0c)) {
385 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_MIN_COORDS, resp)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700386 psmouse_warn(psmouse,
387 "device claims to have min coordinates query, but I'm not able to read it.\n");
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700388 } else {
389 priv->x_min = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
390 priv->y_min = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
Dmitry Torokhov83ba9ea82010-05-10 23:06:52 -0700391 }
Tero Saarniec20a022009-06-10 23:27:24 -0700392 }
393
394 return 0;
395}
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397static int synaptics_query_hardware(struct psmouse *psmouse)
398{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (synaptics_identify(psmouse))
400 return -1;
401 if (synaptics_model_id(psmouse))
402 return -1;
Daniel Kurtzc6bd9d42012-07-07 18:08:51 -0700403 if (synaptics_firmware_id(psmouse))
404 return -1;
405 if (synaptics_board_id(psmouse))
406 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 if (synaptics_capability(psmouse))
408 return -1;
Tero Saarniec20a022009-06-10 23:27:24 -0700409 if (synaptics_resolution(psmouse))
410 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 return 0;
413}
414
Daniel Drake7968a5d2011-11-08 00:00:35 -0800415static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse)
416{
417 static unsigned char param = 0xc8;
418 struct synaptics_data *priv = psmouse->private;
419
Benjamin Herrenschmidt899c6122012-04-20 22:34:49 -0700420 if (!(SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
421 SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)))
Daniel Drake7968a5d2011-11-08 00:00:35 -0800422 return 0;
423
424 if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL))
425 return -1;
426
427 if (ps2_command(&psmouse->ps2dev, &param, PSMOUSE_CMD_SETRATE))
428 return -1;
429
430 /* Advanced gesture mode also sends multi finger data */
431 priv->capabilities |= BIT(1);
432
433 return 0;
434}
435
436static int synaptics_set_mode(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
438 struct synaptics_data *priv = psmouse->private;
439
Daniel Drake7968a5d2011-11-08 00:00:35 -0800440 priv->mode = 0;
441 if (priv->absolute_mode)
442 priv->mode |= SYN_BIT_ABSOLUTE_MODE;
443 if (priv->disable_gesture)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 priv->mode |= SYN_BIT_DISABLE_GESTURE;
Daniel Drake7968a5d2011-11-08 00:00:35 -0800445 if (psmouse->rate >= 80)
446 priv->mode |= SYN_BIT_HIGH_RATE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 if (SYN_CAP_EXTENDED(priv->capabilities))
448 priv->mode |= SYN_BIT_W_MODE;
449
450 if (synaptics_mode_cmd(psmouse, priv->mode))
451 return -1;
452
Daniel Drake7968a5d2011-11-08 00:00:35 -0800453 if (priv->absolute_mode &&
454 synaptics_set_advanced_gesture_mode(psmouse)) {
455 psmouse_err(psmouse, "Advanced gesture mode init failed.\n");
456 return -1;
457 }
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 return 0;
460}
461
462static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
463{
464 struct synaptics_data *priv = psmouse->private;
465
466 if (rate >= 80) {
467 priv->mode |= SYN_BIT_HIGH_RATE;
468 psmouse->rate = 80;
469 } else {
470 priv->mode &= ~SYN_BIT_HIGH_RATE;
471 psmouse->rate = 40;
472 }
473
474 synaptics_mode_cmd(psmouse, priv->mode);
475}
476
477/*****************************************************************************
478 * Synaptics pass-through PS/2 port support
479 ****************************************************************************/
480static int synaptics_pt_write(struct serio *serio, unsigned char c)
481{
482 struct psmouse *parent = serio_get_drvdata(serio->parent);
483 char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */
484
485 if (psmouse_sliced_command(parent, c))
486 return -1;
487 if (ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE))
488 return -1;
489 return 0;
490}
491
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700492static int synaptics_pt_start(struct serio *serio)
493{
494 struct psmouse *parent = serio_get_drvdata(serio->parent);
495 struct synaptics_data *priv = parent->private;
496
497 serio_pause_rx(parent->ps2dev.serio);
498 priv->pt_port = serio;
499 serio_continue_rx(parent->ps2dev.serio);
500
501 return 0;
502}
503
504static void synaptics_pt_stop(struct serio *serio)
505{
506 struct psmouse *parent = serio_get_drvdata(serio->parent);
507 struct synaptics_data *priv = parent->private;
508
509 serio_pause_rx(parent->ps2dev.serio);
510 priv->pt_port = NULL;
511 serio_continue_rx(parent->ps2dev.serio);
512}
513
514static int synaptics_is_pt_packet(unsigned char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
516 return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
517}
518
519static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet)
520{
521 struct psmouse *child = serio_get_drvdata(ptport);
522
523 if (child && child->state == PSMOUSE_ACTIVATED) {
David Howells7d12e782006-10-05 14:55:46 +0100524 serio_interrupt(ptport, packet[1], 0);
525 serio_interrupt(ptport, packet[4], 0);
526 serio_interrupt(ptport, packet[5], 0);
Sergey Vlasov33fdfa92005-07-24 00:53:32 -0500527 if (child->pktsize == 4)
David Howells7d12e782006-10-05 14:55:46 +0100528 serio_interrupt(ptport, packet[2], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 } else
David Howells7d12e782006-10-05 14:55:46 +0100530 serio_interrupt(ptport, packet[1], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531}
532
533static void synaptics_pt_activate(struct psmouse *psmouse)
534{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 struct synaptics_data *priv = psmouse->private;
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700536 struct psmouse *child = serio_get_drvdata(priv->pt_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 /* adjust the touchpad to child's choice of protocol */
539 if (child) {
Sergey Vlasov33fdfa92005-07-24 00:53:32 -0500540 if (child->pktsize == 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
542 else
543 priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
544
545 if (synaptics_mode_cmd(psmouse, priv->mode))
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700546 psmouse_warn(psmouse,
547 "failed to switch guest protocol\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 }
549}
550
551static void synaptics_pt_create(struct psmouse *psmouse)
552{
553 struct serio *serio;
554
Eric Sesterhennb39787a2006-03-14 00:09:16 -0500555 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 if (!serio) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700557 psmouse_err(psmouse,
558 "not enough memory for pass-through port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 return;
560 }
561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 serio->id.type = SERIO_PS_PSTHRU;
563 strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
564 strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name));
565 serio->write = synaptics_pt_write;
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700566 serio->start = synaptics_pt_start;
567 serio->stop = synaptics_pt_stop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 serio->parent = psmouse->ps2dev.serio;
569
570 psmouse->pt_activate = synaptics_pt_activate;
571
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700572 psmouse_info(psmouse, "serio: %s port at %s\n",
573 serio->name, psmouse->phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 serio_register_port(serio);
575}
576
577/*****************************************************************************
578 * Functions to interpret the absolute mode packets
579 ****************************************************************************/
580
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700581static void synaptics_parse_agm(const unsigned char buf[],
Daniel Kurtza6ca40c2011-08-23 23:02:31 -0700582 struct synaptics_data *priv,
583 struct synaptics_hw_state *hw)
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700584{
585 struct synaptics_hw_state *agm = &priv->agm;
Daniel Kurtza6ca40c2011-08-23 23:02:31 -0700586 int agm_packet_type;
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700587
Daniel Kurtza6ca40c2011-08-23 23:02:31 -0700588 agm_packet_type = (buf[5] & 0x30) >> 4;
589 switch (agm_packet_type) {
590 case 1:
591 /* Gesture packet: (x, y, z) half resolution */
592 agm->w = hw->w;
593 agm->x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
594 agm->y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1;
595 agm->z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
596 break;
597
598 case 2:
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800599 /* AGM-CONTACT packet: we are only interested in the count */
600 priv->agm_count = buf[1];
Daniel Kurtza6ca40c2011-08-23 23:02:31 -0700601 break;
602
603 default:
604 break;
605 }
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700606}
607
Dmitry Torokhovaa97240992014-09-02 09:49:18 -0700608static bool is_forcepad;
609
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100610static int synaptics_parse_hw_state(const unsigned char buf[],
611 struct synaptics_data *priv,
612 struct synaptics_hw_state *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
614 memset(hw, 0, sizeof(struct synaptics_hw_state));
615
616 if (SYN_MODEL_NEWABS(priv->model_id)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 hw->w = (((buf[0] & 0x30) >> 2) |
618 ((buf[0] & 0x04) >> 1) |
619 ((buf[3] & 0x04) >> 2));
620
Dmitry Torokhov5715fc72014-08-30 13:51:06 -0700621 if ((SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
622 SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) &&
623 hw->w == 2) {
624 synaptics_parse_agm(buf, priv, hw);
625 return 1;
626 }
627
628 hw->x = (((buf[3] & 0x10) << 8) |
629 ((buf[1] & 0x0f) << 8) |
630 buf[4]);
631 hw->y = (((buf[3] & 0x20) << 7) |
632 ((buf[1] & 0xf0) << 4) |
633 buf[5]);
634 hw->z = buf[2];
635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 hw->left = (buf[0] & 0x01) ? 1 : 0;
637 hw->right = (buf[0] & 0x02) ? 1 : 0;
638
Dmitry Torokhovaa97240992014-09-02 09:49:18 -0700639 if (is_forcepad) {
Dmitry Torokhov5715fc72014-08-30 13:51:06 -0700640 /*
641 * ForcePads, like Clickpads, use middle button
642 * bits to report primary button clicks.
643 * Unfortunately they report primary button not
644 * only when user presses on the pad above certain
645 * threshold, but also when there are more than one
646 * finger on the touchpad, which interferes with
647 * out multi-finger gestures.
648 */
649 if (hw->z == 0) {
650 /* No contacts */
651 priv->press = priv->report_press = false;
652 } else if (hw->w >= 4 && ((buf[0] ^ buf[3]) & 0x01)) {
653 /*
654 * Single-finger touch with pressure above
655 * the threshold. If pressure stays long
656 * enough, we'll start reporting primary
657 * button. We rely on the device continuing
658 * sending data even if finger does not
659 * move.
660 */
661 if (!priv->press) {
662 priv->press_start = jiffies;
663 priv->press = true;
664 } else if (time_after(jiffies,
665 priv->press_start +
666 msecs_to_jiffies(50))) {
667 priv->report_press = true;
668 }
669 } else {
670 priv->press = false;
671 }
672
673 hw->left = priv->report_press;
674
675 } else if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
Takashi Iwai5f57d672010-04-19 10:37:21 -0700676 /*
677 * Clickpad's button is transmitted as middle button,
678 * however, since it is primary button, we will report
679 * it as BTN_LEFT.
680 */
681 hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
682
683 } else if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
685 if (hw->w == 2)
686 hw->scroll = (signed char)(buf[1]);
687 }
688
689 if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
690 hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
691 hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
692 }
693
694 if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
695 ((buf[0] ^ buf[3]) & 0x02)) {
696 switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
697 default:
698 /*
699 * if nExtBtn is greater than 8 it should be
700 * considered invalid and treated as 0
701 */
702 break;
703 case 8:
704 hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0;
705 hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0;
706 case 6:
707 hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0;
708 hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0;
709 case 4:
710 hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0;
711 hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0;
712 case 2:
713 hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0;
714 hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0;
715 }
716 }
717 } else {
718 hw->x = (((buf[1] & 0x1f) << 8) | buf[2]);
719 hw->y = (((buf[4] & 0x1f) << 8) | buf[5]);
720
721 hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
722 hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
723
724 hw->left = (buf[0] & 0x01) ? 1 : 0;
725 hw->right = (buf[0] & 0x02) ? 1 : 0;
726 }
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100727
Seth Forshee824efd32012-09-28 10:29:21 -0700728 /*
729 * Convert wrap-around values to negative. (X|Y)_MAX_POSITIVE
730 * is used by some firmware to indicate a finger at the edge of
731 * the touchpad whose precise position cannot be determined, so
732 * convert these values to the maximum axis value.
733 */
Seth Forsheec03945062012-07-24 23:54:11 -0700734 if (hw->x > X_MAX_POSITIVE)
735 hw->x -= 1 << ABS_POS_BITS;
Seth Forshee824efd32012-09-28 10:29:21 -0700736 else if (hw->x == X_MAX_POSITIVE)
737 hw->x = XMAX;
738
Seth Forsheec03945062012-07-24 23:54:11 -0700739 if (hw->y > Y_MAX_POSITIVE)
740 hw->y -= 1 << ABS_POS_BITS;
Seth Forshee824efd32012-09-28 10:29:21 -0700741 else if (hw->y == Y_MAX_POSITIVE)
742 hw->y = YMAX;
Seth Forsheec03945062012-07-24 23:54:11 -0700743
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100744 return 0;
745}
746
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700747static void synaptics_report_semi_mt_slot(struct input_dev *dev, int slot,
748 bool active, int x, int y)
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100749{
750 input_mt_slot(dev, slot);
751 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
752 if (active) {
753 input_report_abs(dev, ABS_MT_POSITION_X, x);
Daniel Kurtz6de58dd2011-08-23 23:00:24 -0700754 input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(y));
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100755 }
756}
757
758static void synaptics_report_semi_mt_data(struct input_dev *dev,
759 const struct synaptics_hw_state *a,
760 const struct synaptics_hw_state *b,
761 int num_fingers)
762{
763 if (num_fingers >= 2) {
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700764 synaptics_report_semi_mt_slot(dev, 0, true, min(a->x, b->x),
765 min(a->y, b->y));
766 synaptics_report_semi_mt_slot(dev, 1, true, max(a->x, b->x),
767 max(a->y, b->y));
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100768 } else if (num_fingers == 1) {
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700769 synaptics_report_semi_mt_slot(dev, 0, true, a->x, a->y);
770 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100771 } else {
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700772 synaptics_report_semi_mt_slot(dev, 0, false, 0, 0);
773 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775}
776
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700777static void synaptics_report_buttons(struct psmouse *psmouse,
778 const struct synaptics_hw_state *hw)
779{
780 struct input_dev *dev = psmouse->dev;
781 struct synaptics_data *priv = psmouse->private;
782 int i;
783
784 input_report_key(dev, BTN_LEFT, hw->left);
785 input_report_key(dev, BTN_RIGHT, hw->right);
786
787 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
788 input_report_key(dev, BTN_MIDDLE, hw->middle);
789
790 if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
791 input_report_key(dev, BTN_FORWARD, hw->up);
792 input_report_key(dev, BTN_BACK, hw->down);
793 }
794
795 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
796 input_report_key(dev, BTN_0 + i, hw->ext_buttons & (1 << i));
797}
798
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700799static void synaptics_report_mt_data(struct psmouse *psmouse,
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800800 const struct synaptics_hw_state *sgm,
801 int num_fingers)
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700802{
803 struct input_dev *dev = psmouse->dev;
804 struct synaptics_data *priv = psmouse->private;
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800805 const struct synaptics_hw_state *hw[2] = { sgm, &priv->agm };
806 struct input_mt_pos pos[2];
807 int slot[2], nsemi, i;
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700808
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800809 nsemi = clamp_val(num_fingers, 0, 2);
Daniel Kurtz4dc772d2011-08-23 23:02:40 -0700810
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800811 for (i = 0; i < nsemi; i++) {
812 pos[i].x = hw[i]->x;
813 pos[i].y = synaptics_invert_y(hw[i]->y);
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700814 }
815
Benjamin Tissoires6ab17a82015-02-03 15:33:49 -0800816 input_mt_assign_slots(dev, slot, pos, nsemi, DMAX * priv->x_res);
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800817
818 for (i = 0; i < nsemi; i++) {
819 input_mt_slot(dev, slot[i]);
820 input_mt_report_slot_state(dev, MT_TOOL_FINGER, true);
821 input_report_abs(dev, ABS_MT_POSITION_X, pos[i].x);
822 input_report_abs(dev, ABS_MT_POSITION_Y, pos[i].y);
823 input_report_abs(dev, ABS_MT_PRESSURE, hw[i]->z);
824 }
825
826 input_mt_drop_unused(dev);
827
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700828 /* Don't use active slot count to generate BTN_TOOL events. */
829 input_mt_report_pointer_emulation(dev, false);
830
831 /* Send the number of fingers reported by touchpad itself. */
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800832 input_mt_report_finger_count(dev, num_fingers);
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700833
834 synaptics_report_buttons(psmouse, sgm);
835
836 input_sync(dev);
837}
838
839static void synaptics_image_sensor_process(struct psmouse *psmouse,
840 struct synaptics_hw_state *sgm)
841{
Daniel Kurtz4dc772d2011-08-23 23:02:40 -0700842 struct synaptics_data *priv = psmouse->private;
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800843 int num_fingers;
Daniel Kurtz4dc772d2011-08-23 23:02:40 -0700844
845 /*
846 * Update mt_state using the new finger count and current mt_state.
847 */
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700848 if (sgm->z == 0)
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800849 num_fingers = 0;
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700850 else if (sgm->w >= 4)
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800851 num_fingers = 1;
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700852 else if (sgm->w == 0)
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800853 num_fingers = 2;
854 else if (sgm->w == 1)
855 num_fingers = priv->agm_count ? priv->agm_count : 3;
Daniel Kurtz6b4b49f2011-08-23 23:02:56 -0700856 else
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800857 num_fingers = 4;
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700858
859 /* Send resulting input events to user space */
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800860 synaptics_report_mt_data(psmouse, sgm, num_fingers);
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700861}
862
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863/*
864 * called for each full received packet from the touchpad
865 */
866static void synaptics_process_packet(struct psmouse *psmouse)
867{
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500868 struct input_dev *dev = psmouse->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 struct synaptics_data *priv = psmouse->private;
870 struct synaptics_hw_state hw;
871 int num_fingers;
872 int finger_width;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100874 if (synaptics_parse_hw_state(psmouse->packet, priv, &hw))
875 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700877 if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) {
878 synaptics_image_sensor_process(psmouse, &hw);
879 return;
880 }
881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 if (hw.scroll) {
883 priv->scroll += hw.scroll;
884
885 while (priv->scroll >= 4) {
886 input_report_key(dev, BTN_BACK, !hw.down);
887 input_sync(dev);
888 input_report_key(dev, BTN_BACK, hw.down);
889 input_sync(dev);
890 priv->scroll -= 4;
891 }
892 while (priv->scroll <= -4) {
893 input_report_key(dev, BTN_FORWARD, !hw.up);
894 input_sync(dev);
895 input_report_key(dev, BTN_FORWARD, hw.up);
896 input_sync(dev);
897 priv->scroll += 4;
898 }
899 return;
900 }
901
Henrik Rydberg4f56ce92010-12-18 15:42:30 +0100902 if (hw.z > 0 && hw.x > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 num_fingers = 1;
904 finger_width = 5;
905 if (SYN_CAP_EXTENDED(priv->capabilities)) {
906 switch (hw.w) {
907 case 0 ... 1:
908 if (SYN_CAP_MULTIFINGER(priv->capabilities))
909 num_fingers = hw.w + 2;
910 break;
911 case 2:
912 if (SYN_MODEL_PEN(priv->model_id))
913 ; /* Nothing, treat a pen as a single finger */
914 break;
915 case 4 ... 15:
916 if (SYN_CAP_PALMDETECT(priv->capabilities))
917 finger_width = hw.w;
918 break;
919 }
920 }
921 } else {
922 num_fingers = 0;
923 finger_width = 0;
924 }
925
Henrik Rydberge08d9af2014-07-14 10:26:56 -0700926 if (cr48_profile_sensor) {
Benjamin Tissoiresaa104b12014-12-29 14:17:44 -0800927 synaptics_report_mt_data(psmouse, &hw, num_fingers);
Henrik Rydberge08d9af2014-07-14 10:26:56 -0700928 return;
929 }
930
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100931 if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c))
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700932 synaptics_report_semi_mt_data(dev, &hw, &priv->agm,
933 num_fingers);
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 /* Post events
936 * BTN_TOUCH has to be first as mousedev relies on it when doing
937 * absolute -> relative conversion
938 */
939 if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1);
940 if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0);
941
Henrik Rydberg4f56ce92010-12-18 15:42:30 +0100942 if (num_fingers > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 input_report_abs(dev, ABS_X, hw.x);
Daniel Kurtz6de58dd2011-08-23 23:00:24 -0700944 input_report_abs(dev, ABS_Y, synaptics_invert_y(hw.y));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 }
946 input_report_abs(dev, ABS_PRESSURE, hw.z);
947
Chris Bagwell2a8e7712010-07-19 09:06:15 -0700948 if (SYN_CAP_PALMDETECT(priv->capabilities))
949 input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
Peter Hutterere42b6642008-11-20 15:24:42 -0500952 if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
953 input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
954 input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
955 }
956
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700957 synaptics_report_buttons(psmouse, &hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959 input_sync(dev);
960}
961
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700962static int synaptics_validate_byte(struct psmouse *psmouse,
963 int idx, unsigned char pkt_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964{
Helge Dellere38de672006-09-10 21:54:39 -0400965 static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
966 static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
967 static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
968 static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
969 static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700970 const char *packet = psmouse->packet;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
972 if (idx < 0 || idx > 4)
973 return 0;
974
975 switch (pkt_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700977 case SYN_NEWABS:
978 case SYN_NEWABS_RELAXED:
979 return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700981 case SYN_NEWABS_STRICT:
982 return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700984 case SYN_OLDABS:
985 return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx];
986
987 default:
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700988 psmouse_err(psmouse, "unknown packet type %d\n", pkt_type);
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700989 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 }
991}
992
993static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse)
994{
995 int i;
996
997 for (i = 0; i < 5; i++)
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700998 if (!synaptics_validate_byte(psmouse, i, SYN_NEWABS_STRICT)) {
999 psmouse_info(psmouse, "using relaxed packet validation\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 return SYN_NEWABS_RELAXED;
1001 }
1002
1003 return SYN_NEWABS_STRICT;
1004}
1005
David Howells7d12e782006-10-05 14:55:46 +01001006static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 struct synaptics_data *priv = psmouse->private;
1009
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 if (psmouse->pktcnt >= 6) { /* Full packet received */
1011 if (unlikely(priv->pkt_type == SYN_NEWABS))
1012 priv->pkt_type = synaptics_detect_pkt_type(psmouse);
1013
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -07001014 if (SYN_CAP_PASS_THROUGH(priv->capabilities) &&
1015 synaptics_is_pt_packet(psmouse->packet)) {
1016 if (priv->pt_port)
1017 synaptics_pass_pt_packet(priv->pt_port, psmouse->packet);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 } else
1019 synaptics_process_packet(psmouse);
1020
1021 return PSMOUSE_FULL_PACKET;
1022 }
1023
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001024 return synaptics_validate_byte(psmouse, psmouse->pktcnt - 1, priv->pkt_type) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
1026}
1027
1028/*****************************************************************************
1029 * Driver initialization/cleanup functions
1030 ****************************************************************************/
Daniel Kurtz85615472011-08-23 23:00:41 -07001031static void set_abs_position_params(struct input_dev *dev,
1032 struct synaptics_data *priv, int x_code,
1033 int y_code)
1034{
1035 int x_min = priv->x_min ?: XMIN_NOMINAL;
1036 int x_max = priv->x_max ?: XMAX_NOMINAL;
1037 int y_min = priv->y_min ?: YMIN_NOMINAL;
1038 int y_max = priv->y_max ?: YMAX_NOMINAL;
1039 int fuzz = SYN_CAP_REDUCED_FILTERING(priv->ext_cap_0c) ?
1040 SYN_REDUCED_FILTER_FUZZ : 0;
1041
1042 input_set_abs_params(dev, x_code, x_min, x_max, fuzz, 0);
1043 input_set_abs_params(dev, y_code, y_min, y_max, fuzz, 0);
1044 input_abs_set_res(dev, x_code, priv->x_res);
1045 input_abs_set_res(dev, y_code, priv->y_res);
1046}
1047
Hans de Goede43e19882014-04-19 22:26:41 -07001048static void set_input_params(struct psmouse *psmouse,
1049 struct synaptics_data *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050{
Hans de Goede43e19882014-04-19 22:26:41 -07001051 struct input_dev *dev = psmouse->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 int i;
1053
Daniel Drake7968a5d2011-11-08 00:00:35 -08001054 /* Things that apply to both modes */
Henrik Rydbergc14890a2010-12-16 09:52:23 +01001055 __set_bit(INPUT_PROP_POINTER, dev->propbit);
Daniel Drake7968a5d2011-11-08 00:00:35 -08001056 __set_bit(EV_KEY, dev->evbit);
1057 __set_bit(BTN_LEFT, dev->keybit);
1058 __set_bit(BTN_RIGHT, dev->keybit);
Henrik Rydbergc14890a2010-12-16 09:52:23 +01001059
Daniel Drake7968a5d2011-11-08 00:00:35 -08001060 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
1061 __set_bit(BTN_MIDDLE, dev->keybit);
1062
1063 if (!priv->absolute_mode) {
1064 /* Relative mode */
1065 __set_bit(EV_REL, dev->evbit);
1066 __set_bit(REL_X, dev->relbit);
1067 __set_bit(REL_Y, dev->relbit);
1068 return;
1069 }
1070
1071 /* Absolute mode */
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001072 __set_bit(EV_ABS, dev->evbit);
Daniel Kurtz85615472011-08-23 23:00:41 -07001073 set_abs_position_params(dev, priv, ABS_X, ABS_Y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
Chris Bagwell2a8e7712010-07-19 09:06:15 -07001075
Henrik Rydberge08d9af2014-07-14 10:26:56 -07001076 if (cr48_profile_sensor)
1077 input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
1078
Daniel Kurtz3cdfee92011-08-23 23:02:25 -07001079 if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) {
Daniel Kurtz3cdfee92011-08-23 23:02:25 -07001080 set_abs_position_params(dev, priv, ABS_MT_POSITION_X,
1081 ABS_MT_POSITION_Y);
1082 /* Image sensors can report per-contact pressure */
1083 input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
Benjamin Tissoirese9e85202014-12-29 14:15:24 -08001084 input_mt_init_slots(dev, 2, INPUT_MT_POINTER | INPUT_MT_TRACK);
Daniel Kurtz6b4b49f2011-08-23 23:02:56 -07001085
1086 /* Image sensors can signal 4 and 5 finger clicks */
1087 __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
1088 __set_bit(BTN_TOOL_QUINTTAP, dev->keybit);
Daniel Kurtz3cdfee92011-08-23 23:02:25 -07001089 } else if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) {
Daniel Kurtz85615472011-08-23 23:00:41 -07001090 set_abs_position_params(dev, priv, ABS_MT_POSITION_X,
1091 ABS_MT_POSITION_Y);
Henrik Rydberge08d9af2014-07-14 10:26:56 -07001092 /*
1093 * Profile sensor in CR-48 tracks contacts reasonably well,
1094 * other non-image sensors with AGM use semi-mt.
1095 */
Dmitry Torokhovae841972014-07-25 17:12:12 -07001096 input_mt_init_slots(dev, 2,
Henrik Rydberge08d9af2014-07-14 10:26:56 -07001097 INPUT_MT_POINTER |
1098 (cr48_profile_sensor ?
1099 INPUT_MT_TRACK : INPUT_MT_SEMI_MT));
Henrik Rydbergfec6e522010-12-21 18:11:25 +01001100 }
1101
Chris Bagwell2a8e7712010-07-19 09:06:15 -07001102 if (SYN_CAP_PALMDETECT(priv->capabilities))
Chris Bagwell58fb0212010-07-19 09:06:15 -07001103 input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001105 __set_bit(BTN_TOUCH, dev->keybit);
1106 __set_bit(BTN_TOOL_FINGER, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
Peter Hutterere42b6642008-11-20 15:24:42 -05001108 if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001109 __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
1110 __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
Peter Hutterere42b6642008-11-20 15:24:42 -05001111 }
1112
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 if (SYN_CAP_FOUR_BUTTON(priv->capabilities) ||
1114 SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001115 __set_bit(BTN_FORWARD, dev->keybit);
1116 __set_bit(BTN_BACK, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 }
1118
1119 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001120 __set_bit(BTN_0 + i, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001122 __clear_bit(EV_REL, dev->evbit);
1123 __clear_bit(REL_X, dev->relbit);
1124 __clear_bit(REL_Y, dev->relbit);
Tero Saarniec20a022009-06-10 23:27:24 -07001125
Takashi Iwai5f57d672010-04-19 10:37:21 -07001126 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
Henrik Rydbergc14890a2010-12-16 09:52:23 +01001127 __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
Hans de Goede2c75ada2014-09-11 10:14:09 -07001128 if (psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids))
Hans de Goedee2f61102014-05-19 22:53:23 -07001129 __set_bit(INPUT_PROP_TOPBUTTONPAD, dev->propbit);
Takashi Iwai5f57d672010-04-19 10:37:21 -07001130 /* Clickpads report only left button */
1131 __clear_bit(BTN_RIGHT, dev->keybit);
1132 __clear_bit(BTN_MIDDLE, dev->keybit);
1133 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134}
1135
Daniel Drake7968a5d2011-11-08 00:00:35 -08001136static ssize_t synaptics_show_disable_gesture(struct psmouse *psmouse,
1137 void *data, char *buf)
1138{
1139 struct synaptics_data *priv = psmouse->private;
1140
1141 return sprintf(buf, "%c\n", priv->disable_gesture ? '1' : '0');
1142}
1143
1144static ssize_t synaptics_set_disable_gesture(struct psmouse *psmouse,
1145 void *data, const char *buf,
1146 size_t len)
1147{
1148 struct synaptics_data *priv = psmouse->private;
1149 unsigned int value;
1150 int err;
1151
1152 err = kstrtouint(buf, 10, &value);
1153 if (err)
1154 return err;
1155
1156 if (value > 1)
1157 return -EINVAL;
1158
1159 if (value == priv->disable_gesture)
1160 return len;
1161
1162 priv->disable_gesture = value;
1163 if (value)
1164 priv->mode |= SYN_BIT_DISABLE_GESTURE;
1165 else
1166 priv->mode &= ~SYN_BIT_DISABLE_GESTURE;
1167
1168 if (synaptics_mode_cmd(psmouse, priv->mode))
1169 return -EIO;
1170
1171 return len;
1172}
1173
1174PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL,
1175 synaptics_show_disable_gesture,
1176 synaptics_set_disable_gesture);
1177
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178static void synaptics_disconnect(struct psmouse *psmouse)
1179{
Daniel Drake7968a5d2011-11-08 00:00:35 -08001180 struct synaptics_data *priv = psmouse->private;
1181
1182 if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(priv->identity))
1183 device_remove_file(&psmouse->ps2dev.serio->dev,
1184 &psmouse_attr_disable_gesture.dattr);
1185
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 synaptics_reset(psmouse);
Daniel Drake7968a5d2011-11-08 00:00:35 -08001187 kfree(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 psmouse->private = NULL;
1189}
1190
1191static int synaptics_reconnect(struct psmouse *psmouse)
1192{
1193 struct synaptics_data *priv = psmouse->private;
1194 struct synaptics_data old_priv = *priv;
Eric Miaoeeb06552013-06-04 09:30:55 -07001195 unsigned char param[2];
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -08001196 int retry = 0;
1197 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -08001199 do {
1200 psmouse_reset(psmouse);
Dmitry Torokhov85214782011-12-12 00:05:53 -08001201 if (retry) {
1202 /*
1203 * On some boxes, right after resuming, the touchpad
1204 * needs some time to finish initializing (I assume
1205 * it needs time to calibrate) and start responding
1206 * to Synaptics-specific queries, so let's wait a
1207 * bit.
1208 */
1209 ssleep(1);
1210 }
Eric Miaoeeb06552013-06-04 09:30:55 -07001211 ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETID);
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -08001212 error = synaptics_detect(psmouse, 0);
1213 } while (error && ++retry < 3);
Andy Whitcroft4d368452009-02-28 12:51:01 -08001214
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -08001215 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 return -1;
1217
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -08001218 if (retry > 1)
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001219 psmouse_dbg(psmouse, "reconnected after %d tries\n", retry);
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -08001220
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 if (synaptics_query_hardware(psmouse)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001222 psmouse_err(psmouse, "Unable to query device.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 return -1;
1224 }
1225
Daniel Drake7968a5d2011-11-08 00:00:35 -08001226 if (synaptics_set_mode(psmouse)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001227 psmouse_err(psmouse, "Unable to initialize device.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 return -1;
1229 }
1230
Alexandre Peixoto Ferreirabaddf582011-01-28 22:05:14 -08001231 if (old_priv.identity != priv->identity ||
1232 old_priv.model_id != priv->model_id ||
1233 old_priv.capabilities != priv->capabilities ||
1234 old_priv.ext_cap != priv->ext_cap) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001235 psmouse_err(psmouse,
1236 "hardware appears to be different: id(%ld-%ld), model(%ld-%ld), caps(%lx-%lx), ext(%lx-%lx).\n",
1237 old_priv.identity, priv->identity,
1238 old_priv.model_id, priv->model_id,
1239 old_priv.capabilities, priv->capabilities,
1240 old_priv.ext_cap, priv->ext_cap);
Alexandre Peixoto Ferreirabaddf582011-01-28 22:05:14 -08001241 return -1;
1242 }
1243
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 return 0;
1245}
1246
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001247static bool impaired_toshiba_kbc;
1248
Sachin Kamatc9631562013-08-12 11:05:58 -07001249static const struct dmi_system_id toshiba_dmi_table[] __initconst = {
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001250#if defined(CONFIG_DMI) && defined(CONFIG_X86)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -08001252 /* Toshiba Satellite */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 .matches = {
1254 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
Richard Thrippleton53a26702006-04-02 00:10:18 -05001255 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 },
1257 },
Simon Horman9ba5eaa2005-07-11 01:07:20 -05001258 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -08001259 /* Toshiba Dynabook */
Simon Horman9ba5eaa2005-07-11 01:07:20 -05001260 .matches = {
1261 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
Richard Thrippleton53a26702006-04-02 00:10:18 -05001262 DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
1263 },
1264 },
1265 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -08001266 /* Toshiba Portege M300 */
Richard Thrippleton53a26702006-04-02 00:10:18 -05001267 .matches = {
1268 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1269 DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
Simon Horman9ba5eaa2005-07-11 01:07:20 -05001270 },
Dmitry Torokhov5f5eeff2009-10-12 21:35:00 -07001271
1272 },
1273 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -08001274 /* Toshiba Portege M300 */
Dmitry Torokhov5f5eeff2009-10-12 21:35:00 -07001275 .matches = {
1276 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1277 DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
1278 DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
1279 },
1280
Simon Horman9ba5eaa2005-07-11 01:07:20 -05001281 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282#endif
Jan Beulich70874862011-03-31 00:01:58 -07001283 { }
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001284};
1285
Andres Salomonef8313b2010-12-23 01:19:38 -08001286static bool broken_olpc_ec;
1287
Sachin Kamatc9631562013-08-12 11:05:58 -07001288static const struct dmi_system_id olpc_dmi_table[] __initconst = {
Andres Salomonef8313b2010-12-23 01:19:38 -08001289#if defined(CONFIG_DMI) && defined(CONFIG_OLPC)
1290 {
1291 /* OLPC XO-1 or XO-1.5 */
1292 .matches = {
1293 DMI_MATCH(DMI_SYS_VENDOR, "OLPC"),
1294 DMI_MATCH(DMI_PRODUCT_NAME, "XO"),
1295 },
1296 },
Andres Salomonef8313b2010-12-23 01:19:38 -08001297#endif
Jan Beulich70874862011-03-31 00:01:58 -07001298 { }
Andres Salomonef8313b2010-12-23 01:19:38 -08001299};
1300
Henrik Rydberge08d9af2014-07-14 10:26:56 -07001301static const struct dmi_system_id __initconst cr48_dmi_table[] = {
1302#if defined(CONFIG_DMI) && defined(CONFIG_X86)
1303 {
1304 /* Cr-48 Chromebook (Codename Mario) */
1305 .matches = {
1306 DMI_MATCH(DMI_SYS_VENDOR, "IEC"),
1307 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
1308 },
1309 },
1310#endif
1311 { }
1312};
1313
Dmitry Torokhovaa97240992014-09-02 09:49:18 -07001314static const struct dmi_system_id forcepad_dmi_table[] __initconst = {
1315#if defined(CONFIG_DMI) && defined(CONFIG_X86)
1316 {
1317 .matches = {
1318 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1319 DMI_MATCH(DMI_PRODUCT_NAME, "HP EliteBook Folio 1040 G1"),
1320 },
1321 },
1322#endif
1323 { }
1324};
1325
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001326void __init synaptics_module_init(void)
1327{
1328 impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
Andres Salomonef8313b2010-12-23 01:19:38 -08001329 broken_olpc_ec = dmi_check_system(olpc_dmi_table);
Henrik Rydberge08d9af2014-07-14 10:26:56 -07001330 cr48_profile_sensor = dmi_check_system(cr48_dmi_table);
Dmitry Torokhovaa97240992014-09-02 09:49:18 -07001331
1332 /*
1333 * Unfortunately ForcePad capability is not exported over PS/2,
1334 * so we have to resort to checking DMI.
1335 */
1336 is_forcepad = dmi_check_system(forcepad_dmi_table);
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001337}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Daniel Drake7968a5d2011-11-08 00:00:35 -08001339static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
1341 struct synaptics_data *priv;
Daniel Drake7968a5d2011-11-08 00:00:35 -08001342 int err = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Andres Salomonef8313b2010-12-23 01:19:38 -08001344 /*
Daniel Drake83551c02011-11-11 16:05:04 -08001345 * The OLPC XO has issues with Synaptics' absolute mode; the constant
1346 * packet spew overloads the EC such that key presses on the keyboard
1347 * are missed. Given that, don't even attempt to use Absolute mode.
1348 * Relative mode seems to work just fine.
Andres Salomonef8313b2010-12-23 01:19:38 -08001349 */
Daniel Drake83551c02011-11-11 16:05:04 -08001350 if (absolute_mode && broken_olpc_ec) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001351 psmouse_info(psmouse,
1352 "OLPC XO detected, not enabling Synaptics protocol.\n");
Andres Salomonef8313b2010-12-23 01:19:38 -08001353 return -ENODEV;
1354 }
1355
Eric Sesterhennb39787a2006-03-14 00:09:16 -05001356 psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 if (!priv)
Davidlohr Bueso6792cbb2010-09-29 18:53:35 -07001358 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
Andy Whitcroft4d368452009-02-28 12:51:01 -08001360 psmouse_reset(psmouse);
1361
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 if (synaptics_query_hardware(psmouse)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001363 psmouse_err(psmouse, "Unable to query device.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 goto init_fail;
1365 }
1366
Daniel Drake7968a5d2011-11-08 00:00:35 -08001367 priv->absolute_mode = absolute_mode;
1368 if (SYN_ID_DISGEST_SUPPORTED(priv->identity))
1369 priv->disable_gesture = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
Daniel Drake7968a5d2011-11-08 00:00:35 -08001371 if (synaptics_set_mode(psmouse)) {
1372 psmouse_err(psmouse, "Unable to initialize device.\n");
Henrik Rydbergfec6e522010-12-21 18:11:25 +01001373 goto init_fail;
1374 }
1375
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS;
1377
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001378 psmouse_info(psmouse,
Daniel Kurtzc6bd9d42012-07-07 18:08:51 -07001379 "Touchpad model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx, board id: %lu, fw id: %lu\n",
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001380 SYN_ID_MODEL(priv->identity),
1381 SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity),
1382 priv->model_id,
Daniel Kurtzc6bd9d42012-07-07 18:08:51 -07001383 priv->capabilities, priv->ext_cap, priv->ext_cap_0c,
1384 priv->board_id, priv->firmware_id);
Dmitry Torokhov409b7502005-05-28 02:12:18 -05001385
Hans de Goede43e19882014-04-19 22:26:41 -07001386 set_input_params(psmouse, priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Dmitry Torokhov887cc122007-04-12 01:30:41 -04001388 /*
1389 * Encode touchpad model so that it can be used to set
1390 * input device->id.version and be visible to userspace.
1391 * Because version is __u16 we have to drop something.
1392 * Hardware info bits seem to be good candidates as they
1393 * are documented to be for Synaptics corp. internal use.
1394 */
1395 psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) |
1396 (priv->model_id & 0x000000ff);
1397
Daniel Drake7968a5d2011-11-08 00:00:35 -08001398 if (absolute_mode) {
1399 psmouse->protocol_handler = synaptics_process_byte;
1400 psmouse->pktsize = 6;
1401 } else {
1402 /* Relative mode follows standard PS/2 mouse protocol */
1403 psmouse->protocol_handler = psmouse_process_byte;
1404 psmouse->pktsize = 3;
1405 }
1406
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 psmouse->set_rate = synaptics_set_rate;
1408 psmouse->disconnect = synaptics_disconnect;
1409 psmouse->reconnect = synaptics_reconnect;
Dmitry Torokhova1cec062007-02-18 01:40:24 -05001410 psmouse->cleanup = synaptics_reset;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001411 /* Synaptics can usually stay in sync without extra help */
1412 psmouse->resync_time = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
1414 if (SYN_CAP_PASS_THROUGH(priv->capabilities))
1415 synaptics_pt_create(psmouse);
1416
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 /*
1418 * Toshiba's KBC seems to have trouble handling data from
Andres Salomon7ee99162010-12-23 01:18:28 -08001419 * Synaptics at full rate. Switch to a lower rate (roughly
1420 * the same rate as a standard PS/2 mouse).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 */
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001422 if (psmouse->rate >= 80 && impaired_toshiba_kbc) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001423 psmouse_info(psmouse,
1424 "Toshiba %s detected, limiting rate to 40pps.\n",
1425 dmi_get_system_info(DMI_PRODUCT_NAME));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 psmouse->rate = 40;
1427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Daniel Drake7968a5d2011-11-08 00:00:35 -08001429 if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(priv->identity)) {
1430 err = device_create_file(&psmouse->ps2dev.serio->dev,
1431 &psmouse_attr_disable_gesture.dattr);
1432 if (err) {
1433 psmouse_err(psmouse,
1434 "Failed to create disable_gesture attribute (%d)",
1435 err);
1436 goto init_fail;
1437 }
1438 }
1439
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 return 0;
1441
1442 init_fail:
1443 kfree(priv);
Daniel Drake7968a5d2011-11-08 00:00:35 -08001444 return err;
1445}
1446
1447int synaptics_init(struct psmouse *psmouse)
1448{
1449 return __synaptics_init(psmouse, true);
1450}
1451
1452int synaptics_init_relative(struct psmouse *psmouse)
1453{
1454 return __synaptics_init(psmouse, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455}
1456
Andres Salomon55e3d922007-03-10 01:39:54 -05001457#else /* CONFIG_MOUSE_PS2_SYNAPTICS */
1458
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001459void __init synaptics_module_init(void)
1460{
1461}
1462
Andres Salomon55e3d922007-03-10 01:39:54 -05001463int synaptics_init(struct psmouse *psmouse)
1464{
1465 return -ENOSYS;
1466}
1467
1468#endif /* CONFIG_MOUSE_PS2_SYNAPTICS */