blob: 4c69e3304011d936ddc01b3f4a64e97cd0ebd353 [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
Dmitry Torokhovde4e3742014-12-29 14:43:44 -0800197/* This list has been kindly provided by Synaptics. */
198static const char * const forcepad_pnp_ids[] = {
199 "SYN300D",
200 "SYN3014",
201 NULL
202};
203
Andres Salomon55e3d922007-03-10 01:39:54 -0500204/*****************************************************************************
205 * Synaptics communications functions
206 ****************************************************************************/
207
208/*
JJ Ding1a49a0a2012-05-10 22:32:00 -0700209 * Synaptics touchpads report the y coordinate from bottom to top, which is
210 * opposite from what userspace expects.
211 * This function is used to invert y before reporting.
212 */
213static int synaptics_invert_y(int y)
214{
215 return YMAX_NOMINAL + YMIN_NOMINAL - y;
216}
217
218/*
Andres Salomon55e3d922007-03-10 01:39:54 -0500219 * Send a command to the synpatics touchpad by special commands
220 */
221static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param)
222{
223 if (psmouse_sliced_command(psmouse, c))
224 return -1;
225 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO))
226 return -1;
227 return 0;
228}
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230/*
231 * Read the model-id bytes from the touchpad
232 * see also SYN_MODEL_* macros
233 */
234static int synaptics_model_id(struct psmouse *psmouse)
235{
236 struct synaptics_data *priv = psmouse->private;
237 unsigned char mi[3];
238
239 if (synaptics_send_cmd(psmouse, SYN_QUE_MODEL, mi))
240 return -1;
241 priv->model_id = (mi[0]<<16) | (mi[1]<<8) | mi[2];
242 return 0;
243}
244
245/*
Daniel Kurtzc6bd9d42012-07-07 18:08:51 -0700246 * Read the board id from the touchpad
247 * The board id is encoded in the "QUERY MODES" response
248 */
249static int synaptics_board_id(struct psmouse *psmouse)
250{
251 struct synaptics_data *priv = psmouse->private;
252 unsigned char bid[3];
253
254 if (synaptics_send_cmd(psmouse, SYN_QUE_MODES, bid))
255 return -1;
256 priv->board_id = ((bid[0] & 0xfc) << 6) | bid[1];
257 return 0;
258}
259
260/*
261 * Read the firmware id from the touchpad
262 */
263static int synaptics_firmware_id(struct psmouse *psmouse)
264{
265 struct synaptics_data *priv = psmouse->private;
266 unsigned char fwid[3];
267
268 if (synaptics_send_cmd(psmouse, SYN_QUE_FIRMWARE_ID, fwid))
269 return -1;
270 priv->firmware_id = (fwid[0] << 16) | (fwid[1] << 8) | fwid[2];
271 return 0;
272}
273
274/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 * Read the capability-bits from the touchpad
276 * see also the SYN_CAP_* macros
277 */
278static int synaptics_capability(struct psmouse *psmouse)
279{
280 struct synaptics_data *priv = psmouse->private;
281 unsigned char cap[3];
282
283 if (synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap))
284 return -1;
285 priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
Takashi Iwai5f57d672010-04-19 10:37:21 -0700286 priv->ext_cap = priv->ext_cap_0c = 0;
287
Dmitry Torokhov3619b8f2010-07-21 00:01:19 -0700288 /*
289 * Older firmwares had submodel ID fixed to 0x47
290 */
291 if (SYN_ID_FULL(priv->identity) < 0x705 &&
292 SYN_CAP_SUBMODEL_ID(priv->capabilities) != 0x47) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 return -1;
Dmitry Torokhov3619b8f2010-07-21 00:01:19 -0700294 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 /*
297 * Unless capExtended is set the rest of the flags should be ignored
298 */
299 if (!SYN_CAP_EXTENDED(priv->capabilities))
300 priv->capabilities = 0;
301
302 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 1) {
303 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB, cap)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700304 psmouse_warn(psmouse,
305 "device claims to have extended capabilities, but I'm not able to read them.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 } else {
307 priv->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
308
309 /*
310 * if nExtBtn is greater than 8 it should be considered
311 * invalid and treated as 0
312 */
313 if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) > 8)
314 priv->ext_cap &= 0xff0fff;
315 }
316 }
Takashi Iwai5f57d672010-04-19 10:37:21 -0700317
318 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 4) {
319 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB_0C, cap)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700320 psmouse_warn(psmouse,
321 "device claims to have extended capability 0x0c, but I'm not able to read it.\n");
Takashi Iwai5f57d672010-04-19 10:37:21 -0700322 } else {
323 priv->ext_cap_0c = (cap[0] << 16) | (cap[1] << 8) | cap[2];
324 }
325 }
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 return 0;
328}
329
330/*
331 * Identify Touchpad
332 * See also the SYN_ID_* macros
333 */
334static int synaptics_identify(struct psmouse *psmouse)
335{
336 struct synaptics_data *priv = psmouse->private;
337 unsigned char id[3];
338
339 if (synaptics_send_cmd(psmouse, SYN_QUE_IDENTIFY, id))
340 return -1;
341 priv->identity = (id[0]<<16) | (id[1]<<8) | id[2];
342 if (SYN_ID_IS_SYNAPTICS(priv->identity))
343 return 0;
344 return -1;
345}
346
Tero Saarniec20a022009-06-10 23:27:24 -0700347/*
Dmitry Torokhov83ba9ea82010-05-10 23:06:52 -0700348 * Read touchpad resolution and maximum reported coordinates
Tero Saarniec20a022009-06-10 23:27:24 -0700349 * Resolution is left zero if touchpad does not support the query
350 */
Benjamin Tissoires421e08c2014-03-28 00:43:00 -0700351
Tero Saarniec20a022009-06-10 23:27:24 -0700352static int synaptics_resolution(struct psmouse *psmouse)
353{
354 struct synaptics_data *priv = psmouse->private;
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700355 unsigned char resp[3];
Hans de Goede0f68f392014-05-19 22:54:09 -0700356 int i;
Tero Saarniec20a022009-06-10 23:27:24 -0700357
358 if (SYN_ID_MAJOR(priv->identity) < 4)
Takashi Iwaibbddd192010-07-14 09:32:46 -0700359 return 0;
Tero Saarniec20a022009-06-10 23:27:24 -0700360
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700361 if (synaptics_send_cmd(psmouse, SYN_QUE_RESOLUTION, resp) == 0) {
362 if (resp[0] != 0 && (resp[1] & 0x80) && resp[2] != 0) {
363 priv->x_res = resp[0]; /* x resolution in units/mm */
364 priv->y_res = resp[2]; /* y resolution in units/mm */
Dmitry Torokhov83ba9ea82010-05-10 23:06:52 -0700365 }
366 }
Tero Saarniec20a022009-06-10 23:27:24 -0700367
Benjamin Tissoiresd49cb7a2014-06-07 22:37:47 -0700368 for (i = 0; min_max_pnpid_table[i].pnp_ids; i++) {
Hans de Goede2c75ada2014-09-11 10:14:09 -0700369 if (psmouse_matches_pnp_id(psmouse,
370 min_max_pnpid_table[i].pnp_ids)) {
Benjamin Tissoiresd49cb7a2014-06-07 22:37:47 -0700371 priv->x_min = min_max_pnpid_table[i].x_min;
372 priv->x_max = min_max_pnpid_table[i].x_max;
373 priv->y_min = min_max_pnpid_table[i].y_min;
374 priv->y_max = min_max_pnpid_table[i].y_max;
375 return 0;
376 }
377 }
378
Dmitry Torokhov83ba9ea82010-05-10 23:06:52 -0700379 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 5 &&
380 SYN_CAP_MAX_DIMENSIONS(priv->ext_cap_0c)) {
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700381 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_MAX_COORDS, resp)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700382 psmouse_warn(psmouse,
383 "device claims to have max coordinates query, but I'm not able to read it.\n");
Dmitry Torokhov83ba9ea82010-05-10 23:06:52 -0700384 } else {
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700385 priv->x_max = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
386 priv->y_max = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
387 }
388 }
389
390 if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 7 &&
391 SYN_CAP_MIN_DIMENSIONS(priv->ext_cap_0c)) {
392 if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_MIN_COORDS, resp)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700393 psmouse_warn(psmouse,
394 "device claims to have min coordinates query, but I'm not able to read it.\n");
Dmitry Torokhova66413f2011-07-09 12:32:56 -0700395 } else {
396 priv->x_min = (resp[0] << 5) | ((resp[1] & 0x0f) << 1);
397 priv->y_min = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3);
Dmitry Torokhov83ba9ea82010-05-10 23:06:52 -0700398 }
Tero Saarniec20a022009-06-10 23:27:24 -0700399 }
400
401 return 0;
402}
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404static int synaptics_query_hardware(struct psmouse *psmouse)
405{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 if (synaptics_identify(psmouse))
407 return -1;
408 if (synaptics_model_id(psmouse))
409 return -1;
Daniel Kurtzc6bd9d42012-07-07 18:08:51 -0700410 if (synaptics_firmware_id(psmouse))
411 return -1;
412 if (synaptics_board_id(psmouse))
413 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 if (synaptics_capability(psmouse))
415 return -1;
Tero Saarniec20a022009-06-10 23:27:24 -0700416 if (synaptics_resolution(psmouse))
417 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419 return 0;
420}
421
Daniel Drake7968a5d2011-11-08 00:00:35 -0800422static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse)
423{
424 static unsigned char param = 0xc8;
425 struct synaptics_data *priv = psmouse->private;
426
Benjamin Herrenschmidt899c6122012-04-20 22:34:49 -0700427 if (!(SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
428 SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)))
Daniel Drake7968a5d2011-11-08 00:00:35 -0800429 return 0;
430
431 if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL))
432 return -1;
433
434 if (ps2_command(&psmouse->ps2dev, &param, PSMOUSE_CMD_SETRATE))
435 return -1;
436
437 /* Advanced gesture mode also sends multi finger data */
438 priv->capabilities |= BIT(1);
439
440 return 0;
441}
442
443static int synaptics_set_mode(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
445 struct synaptics_data *priv = psmouse->private;
446
Daniel Drake7968a5d2011-11-08 00:00:35 -0800447 priv->mode = 0;
448 if (priv->absolute_mode)
449 priv->mode |= SYN_BIT_ABSOLUTE_MODE;
450 if (priv->disable_gesture)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 priv->mode |= SYN_BIT_DISABLE_GESTURE;
Daniel Drake7968a5d2011-11-08 00:00:35 -0800452 if (psmouse->rate >= 80)
453 priv->mode |= SYN_BIT_HIGH_RATE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 if (SYN_CAP_EXTENDED(priv->capabilities))
455 priv->mode |= SYN_BIT_W_MODE;
456
457 if (synaptics_mode_cmd(psmouse, priv->mode))
458 return -1;
459
Daniel Drake7968a5d2011-11-08 00:00:35 -0800460 if (priv->absolute_mode &&
461 synaptics_set_advanced_gesture_mode(psmouse)) {
462 psmouse_err(psmouse, "Advanced gesture mode init failed.\n");
463 return -1;
464 }
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 return 0;
467}
468
469static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
470{
471 struct synaptics_data *priv = psmouse->private;
472
473 if (rate >= 80) {
474 priv->mode |= SYN_BIT_HIGH_RATE;
475 psmouse->rate = 80;
476 } else {
477 priv->mode &= ~SYN_BIT_HIGH_RATE;
478 psmouse->rate = 40;
479 }
480
481 synaptics_mode_cmd(psmouse, priv->mode);
482}
483
484/*****************************************************************************
485 * Synaptics pass-through PS/2 port support
486 ****************************************************************************/
487static int synaptics_pt_write(struct serio *serio, unsigned char c)
488{
489 struct psmouse *parent = serio_get_drvdata(serio->parent);
490 char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */
491
492 if (psmouse_sliced_command(parent, c))
493 return -1;
494 if (ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE))
495 return -1;
496 return 0;
497}
498
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700499static int synaptics_pt_start(struct serio *serio)
500{
501 struct psmouse *parent = serio_get_drvdata(serio->parent);
502 struct synaptics_data *priv = parent->private;
503
504 serio_pause_rx(parent->ps2dev.serio);
505 priv->pt_port = serio;
506 serio_continue_rx(parent->ps2dev.serio);
507
508 return 0;
509}
510
511static void synaptics_pt_stop(struct serio *serio)
512{
513 struct psmouse *parent = serio_get_drvdata(serio->parent);
514 struct synaptics_data *priv = parent->private;
515
516 serio_pause_rx(parent->ps2dev.serio);
517 priv->pt_port = NULL;
518 serio_continue_rx(parent->ps2dev.serio);
519}
520
521static int synaptics_is_pt_packet(unsigned char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
523 return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
524}
525
526static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet)
527{
528 struct psmouse *child = serio_get_drvdata(ptport);
529
530 if (child && child->state == PSMOUSE_ACTIVATED) {
David Howells7d12e782006-10-05 14:55:46 +0100531 serio_interrupt(ptport, packet[1], 0);
532 serio_interrupt(ptport, packet[4], 0);
533 serio_interrupt(ptport, packet[5], 0);
Sergey Vlasov33fdfa92005-07-24 00:53:32 -0500534 if (child->pktsize == 4)
David Howells7d12e782006-10-05 14:55:46 +0100535 serio_interrupt(ptport, packet[2], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 } else
David Howells7d12e782006-10-05 14:55:46 +0100537 serio_interrupt(ptport, packet[1], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538}
539
540static void synaptics_pt_activate(struct psmouse *psmouse)
541{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 struct synaptics_data *priv = psmouse->private;
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700543 struct psmouse *child = serio_get_drvdata(priv->pt_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
545 /* adjust the touchpad to child's choice of protocol */
546 if (child) {
Sergey Vlasov33fdfa92005-07-24 00:53:32 -0500547 if (child->pktsize == 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
549 else
550 priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
551
552 if (synaptics_mode_cmd(psmouse, priv->mode))
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700553 psmouse_warn(psmouse,
554 "failed to switch guest protocol\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 }
556}
557
558static void synaptics_pt_create(struct psmouse *psmouse)
559{
560 struct serio *serio;
561
Eric Sesterhennb39787a2006-03-14 00:09:16 -0500562 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 if (!serio) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700564 psmouse_err(psmouse,
565 "not enough memory for pass-through port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 return;
567 }
568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 serio->id.type = SERIO_PS_PSTHRU;
570 strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
571 strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name));
572 serio->write = synaptics_pt_write;
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -0700573 serio->start = synaptics_pt_start;
574 serio->stop = synaptics_pt_stop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 serio->parent = psmouse->ps2dev.serio;
576
577 psmouse->pt_activate = synaptics_pt_activate;
578
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700579 psmouse_info(psmouse, "serio: %s port at %s\n",
580 serio->name, psmouse->phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 serio_register_port(serio);
582}
583
584/*****************************************************************************
585 * Functions to interpret the absolute mode packets
586 ****************************************************************************/
587
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700588static void synaptics_parse_agm(const unsigned char buf[],
Daniel Kurtza6ca40c2011-08-23 23:02:31 -0700589 struct synaptics_data *priv,
590 struct synaptics_hw_state *hw)
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700591{
592 struct synaptics_hw_state *agm = &priv->agm;
Daniel Kurtza6ca40c2011-08-23 23:02:31 -0700593 int agm_packet_type;
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700594
Daniel Kurtza6ca40c2011-08-23 23:02:31 -0700595 agm_packet_type = (buf[5] & 0x30) >> 4;
596 switch (agm_packet_type) {
597 case 1:
598 /* Gesture packet: (x, y, z) half resolution */
599 agm->w = hw->w;
600 agm->x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
601 agm->y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1;
602 agm->z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
603 break;
604
605 case 2:
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800606 /* AGM-CONTACT packet: we are only interested in the count */
607 priv->agm_count = buf[1];
Daniel Kurtza6ca40c2011-08-23 23:02:31 -0700608 break;
609
610 default:
611 break;
612 }
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700613}
614
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100615static int synaptics_parse_hw_state(const unsigned char buf[],
616 struct synaptics_data *priv,
617 struct synaptics_hw_state *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618{
619 memset(hw, 0, sizeof(struct synaptics_hw_state));
620
621 if (SYN_MODEL_NEWABS(priv->model_id)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 hw->w = (((buf[0] & 0x30) >> 2) |
623 ((buf[0] & 0x04) >> 1) |
624 ((buf[3] & 0x04) >> 2));
625
Dmitry Torokhov5715fc72014-08-30 13:51:06 -0700626 if ((SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
627 SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) &&
628 hw->w == 2) {
629 synaptics_parse_agm(buf, priv, hw);
630 return 1;
631 }
632
633 hw->x = (((buf[3] & 0x10) << 8) |
634 ((buf[1] & 0x0f) << 8) |
635 buf[4]);
636 hw->y = (((buf[3] & 0x20) << 7) |
637 ((buf[1] & 0xf0) << 4) |
638 buf[5]);
639 hw->z = buf[2];
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 hw->left = (buf[0] & 0x01) ? 1 : 0;
642 hw->right = (buf[0] & 0x02) ? 1 : 0;
643
Dmitry Torokhovde4e3742014-12-29 14:43:44 -0800644 if (priv->is_forcepad) {
Dmitry Torokhov5715fc72014-08-30 13:51:06 -0700645 /*
646 * ForcePads, like Clickpads, use middle button
647 * bits to report primary button clicks.
648 * Unfortunately they report primary button not
649 * only when user presses on the pad above certain
650 * threshold, but also when there are more than one
651 * finger on the touchpad, which interferes with
652 * out multi-finger gestures.
653 */
654 if (hw->z == 0) {
655 /* No contacts */
656 priv->press = priv->report_press = false;
657 } else if (hw->w >= 4 && ((buf[0] ^ buf[3]) & 0x01)) {
658 /*
659 * Single-finger touch with pressure above
660 * the threshold. If pressure stays long
661 * enough, we'll start reporting primary
662 * button. We rely on the device continuing
663 * sending data even if finger does not
664 * move.
665 */
666 if (!priv->press) {
667 priv->press_start = jiffies;
668 priv->press = true;
669 } else if (time_after(jiffies,
670 priv->press_start +
671 msecs_to_jiffies(50))) {
672 priv->report_press = true;
673 }
674 } else {
675 priv->press = false;
676 }
677
678 hw->left = priv->report_press;
679
680 } else if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
Takashi Iwai5f57d672010-04-19 10:37:21 -0700681 /*
682 * Clickpad's button is transmitted as middle button,
683 * however, since it is primary button, we will report
684 * it as BTN_LEFT.
685 */
686 hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
687
688 } else if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
690 if (hw->w == 2)
691 hw->scroll = (signed char)(buf[1]);
692 }
693
694 if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
695 hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
696 hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
697 }
698
699 if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
700 ((buf[0] ^ buf[3]) & 0x02)) {
701 switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
702 default:
703 /*
704 * if nExtBtn is greater than 8 it should be
705 * considered invalid and treated as 0
706 */
707 break;
708 case 8:
709 hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0;
710 hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0;
711 case 6:
712 hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0;
713 hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0;
714 case 4:
715 hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0;
716 hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0;
717 case 2:
718 hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0;
719 hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0;
720 }
721 }
722 } else {
723 hw->x = (((buf[1] & 0x1f) << 8) | buf[2]);
724 hw->y = (((buf[4] & 0x1f) << 8) | buf[5]);
725
726 hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
727 hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
728
729 hw->left = (buf[0] & 0x01) ? 1 : 0;
730 hw->right = (buf[0] & 0x02) ? 1 : 0;
731 }
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100732
Seth Forshee824efd32012-09-28 10:29:21 -0700733 /*
734 * Convert wrap-around values to negative. (X|Y)_MAX_POSITIVE
735 * is used by some firmware to indicate a finger at the edge of
736 * the touchpad whose precise position cannot be determined, so
737 * convert these values to the maximum axis value.
738 */
Seth Forsheec03945062012-07-24 23:54:11 -0700739 if (hw->x > X_MAX_POSITIVE)
740 hw->x -= 1 << ABS_POS_BITS;
Seth Forshee824efd32012-09-28 10:29:21 -0700741 else if (hw->x == X_MAX_POSITIVE)
742 hw->x = XMAX;
743
Seth Forsheec03945062012-07-24 23:54:11 -0700744 if (hw->y > Y_MAX_POSITIVE)
745 hw->y -= 1 << ABS_POS_BITS;
Seth Forshee824efd32012-09-28 10:29:21 -0700746 else if (hw->y == Y_MAX_POSITIVE)
747 hw->y = YMAX;
Seth Forsheec03945062012-07-24 23:54:11 -0700748
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100749 return 0;
750}
751
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700752static void synaptics_report_semi_mt_slot(struct input_dev *dev, int slot,
753 bool active, int x, int y)
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100754{
755 input_mt_slot(dev, slot);
756 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
757 if (active) {
758 input_report_abs(dev, ABS_MT_POSITION_X, x);
Daniel Kurtz6de58dd2011-08-23 23:00:24 -0700759 input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(y));
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100760 }
761}
762
763static void synaptics_report_semi_mt_data(struct input_dev *dev,
764 const struct synaptics_hw_state *a,
765 const struct synaptics_hw_state *b,
766 int num_fingers)
767{
768 if (num_fingers >= 2) {
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700769 synaptics_report_semi_mt_slot(dev, 0, true, min(a->x, b->x),
770 min(a->y, b->y));
771 synaptics_report_semi_mt_slot(dev, 1, true, max(a->x, b->x),
772 max(a->y, b->y));
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100773 } else if (num_fingers == 1) {
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700774 synaptics_report_semi_mt_slot(dev, 0, true, a->x, a->y);
775 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100776 } else {
Daniel Kurtzbea9f0f2011-07-06 22:42:52 -0700777 synaptics_report_semi_mt_slot(dev, 0, false, 0, 0);
778 synaptics_report_semi_mt_slot(dev, 1, false, 0, 0);
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100779 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780}
781
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700782static void synaptics_report_buttons(struct psmouse *psmouse,
783 const struct synaptics_hw_state *hw)
784{
785 struct input_dev *dev = psmouse->dev;
786 struct synaptics_data *priv = psmouse->private;
787 int i;
788
789 input_report_key(dev, BTN_LEFT, hw->left);
790 input_report_key(dev, BTN_RIGHT, hw->right);
791
792 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
793 input_report_key(dev, BTN_MIDDLE, hw->middle);
794
795 if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
796 input_report_key(dev, BTN_FORWARD, hw->up);
797 input_report_key(dev, BTN_BACK, hw->down);
798 }
799
800 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
801 input_report_key(dev, BTN_0 + i, hw->ext_buttons & (1 << i));
802}
803
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700804static void synaptics_report_mt_data(struct psmouse *psmouse,
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800805 const struct synaptics_hw_state *sgm,
806 int num_fingers)
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700807{
808 struct input_dev *dev = psmouse->dev;
809 struct synaptics_data *priv = psmouse->private;
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800810 const struct synaptics_hw_state *hw[2] = { sgm, &priv->agm };
811 struct input_mt_pos pos[2];
812 int slot[2], nsemi, i;
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700813
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800814 nsemi = clamp_val(num_fingers, 0, 2);
Daniel Kurtz4dc772d2011-08-23 23:02:40 -0700815
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800816 for (i = 0; i < nsemi; i++) {
817 pos[i].x = hw[i]->x;
818 pos[i].y = synaptics_invert_y(hw[i]->y);
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700819 }
820
Benjamin Tissoires6ab17a82015-02-03 15:33:49 -0800821 input_mt_assign_slots(dev, slot, pos, nsemi, DMAX * priv->x_res);
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800822
823 for (i = 0; i < nsemi; i++) {
824 input_mt_slot(dev, slot[i]);
825 input_mt_report_slot_state(dev, MT_TOOL_FINGER, true);
826 input_report_abs(dev, ABS_MT_POSITION_X, pos[i].x);
827 input_report_abs(dev, ABS_MT_POSITION_Y, pos[i].y);
828 input_report_abs(dev, ABS_MT_PRESSURE, hw[i]->z);
829 }
830
831 input_mt_drop_unused(dev);
832
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700833 /* Don't use active slot count to generate BTN_TOOL events. */
834 input_mt_report_pointer_emulation(dev, false);
835
836 /* Send the number of fingers reported by touchpad itself. */
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800837 input_mt_report_finger_count(dev, num_fingers);
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700838
839 synaptics_report_buttons(psmouse, sgm);
840
841 input_sync(dev);
842}
843
844static void synaptics_image_sensor_process(struct psmouse *psmouse,
845 struct synaptics_hw_state *sgm)
846{
Daniel Kurtz4dc772d2011-08-23 23:02:40 -0700847 struct synaptics_data *priv = psmouse->private;
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800848 int num_fingers;
Daniel Kurtz4dc772d2011-08-23 23:02:40 -0700849
850 /*
851 * Update mt_state using the new finger count and current mt_state.
852 */
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700853 if (sgm->z == 0)
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800854 num_fingers = 0;
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700855 else if (sgm->w >= 4)
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800856 num_fingers = 1;
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700857 else if (sgm->w == 0)
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800858 num_fingers = 2;
859 else if (sgm->w == 1)
860 num_fingers = priv->agm_count ? priv->agm_count : 3;
Daniel Kurtz6b4b49f2011-08-23 23:02:56 -0700861 else
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800862 num_fingers = 4;
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700863
864 /* Send resulting input events to user space */
Benjamin Tissoirese9e85202014-12-29 14:15:24 -0800865 synaptics_report_mt_data(psmouse, sgm, num_fingers);
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700866}
867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868/*
869 * called for each full received packet from the touchpad
870 */
871static void synaptics_process_packet(struct psmouse *psmouse)
872{
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500873 struct input_dev *dev = psmouse->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 struct synaptics_data *priv = psmouse->private;
875 struct synaptics_hw_state hw;
876 int num_fingers;
877 int finger_width;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100879 if (synaptics_parse_hw_state(psmouse->packet, priv, &hw))
880 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700882 if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) {
883 synaptics_image_sensor_process(psmouse, &hw);
884 return;
885 }
886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 if (hw.scroll) {
888 priv->scroll += hw.scroll;
889
890 while (priv->scroll >= 4) {
891 input_report_key(dev, BTN_BACK, !hw.down);
892 input_sync(dev);
893 input_report_key(dev, BTN_BACK, hw.down);
894 input_sync(dev);
895 priv->scroll -= 4;
896 }
897 while (priv->scroll <= -4) {
898 input_report_key(dev, BTN_FORWARD, !hw.up);
899 input_sync(dev);
900 input_report_key(dev, BTN_FORWARD, hw.up);
901 input_sync(dev);
902 priv->scroll += 4;
903 }
904 return;
905 }
906
Henrik Rydberg4f56ce92010-12-18 15:42:30 +0100907 if (hw.z > 0 && hw.x > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 num_fingers = 1;
909 finger_width = 5;
910 if (SYN_CAP_EXTENDED(priv->capabilities)) {
911 switch (hw.w) {
912 case 0 ... 1:
913 if (SYN_CAP_MULTIFINGER(priv->capabilities))
914 num_fingers = hw.w + 2;
915 break;
916 case 2:
917 if (SYN_MODEL_PEN(priv->model_id))
918 ; /* Nothing, treat a pen as a single finger */
919 break;
920 case 4 ... 15:
921 if (SYN_CAP_PALMDETECT(priv->capabilities))
922 finger_width = hw.w;
923 break;
924 }
925 }
926 } else {
927 num_fingers = 0;
928 finger_width = 0;
929 }
930
Henrik Rydberge08d9af2014-07-14 10:26:56 -0700931 if (cr48_profile_sensor) {
Benjamin Tissoiresaa104b12014-12-29 14:17:44 -0800932 synaptics_report_mt_data(psmouse, &hw, num_fingers);
Henrik Rydberge08d9af2014-07-14 10:26:56 -0700933 return;
934 }
935
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100936 if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c))
Daniel Kurtz7afdb842011-08-23 23:00:33 -0700937 synaptics_report_semi_mt_data(dev, &hw, &priv->agm,
938 num_fingers);
Henrik Rydbergfec6e522010-12-21 18:11:25 +0100939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 /* Post events
941 * BTN_TOUCH has to be first as mousedev relies on it when doing
942 * absolute -> relative conversion
943 */
944 if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1);
945 if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0);
946
Henrik Rydberg4f56ce92010-12-18 15:42:30 +0100947 if (num_fingers > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 input_report_abs(dev, ABS_X, hw.x);
Daniel Kurtz6de58dd2011-08-23 23:00:24 -0700949 input_report_abs(dev, ABS_Y, synaptics_invert_y(hw.y));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 }
951 input_report_abs(dev, ABS_PRESSURE, hw.z);
952
Chris Bagwell2a8e7712010-07-19 09:06:15 -0700953 if (SYN_CAP_PALMDETECT(priv->capabilities))
954 input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
955
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
Peter Hutterere42b6642008-11-20 15:24:42 -0500957 if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
958 input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
959 input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
960 }
961
Daniel Kurtz3cdfee92011-08-23 23:02:25 -0700962 synaptics_report_buttons(psmouse, &hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 input_sync(dev);
965}
966
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700967static int synaptics_validate_byte(struct psmouse *psmouse,
968 int idx, unsigned char pkt_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
Helge Dellere38de672006-09-10 21:54:39 -0400970 static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
971 static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
972 static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
973 static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
974 static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700975 const char *packet = psmouse->packet;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 if (idx < 0 || idx > 4)
978 return 0;
979
980 switch (pkt_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700982 case SYN_NEWABS:
983 case SYN_NEWABS_RELAXED:
984 return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700986 case SYN_NEWABS_STRICT:
987 return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700989 case SYN_OLDABS:
990 return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx];
991
992 default:
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700993 psmouse_err(psmouse, "unknown packet type %d\n", pkt_type);
Dmitry Torokhova62f0d22010-05-19 10:39:17 -0700994 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 }
996}
997
998static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse)
999{
1000 int i;
1001
1002 for (i = 0; i < 5; i++)
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001003 if (!synaptics_validate_byte(psmouse, i, SYN_NEWABS_STRICT)) {
1004 psmouse_info(psmouse, "using relaxed packet validation\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 return SYN_NEWABS_RELAXED;
1006 }
1007
1008 return SYN_NEWABS_STRICT;
1009}
1010
David Howells7d12e782006-10-05 14:55:46 +01001011static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 struct synaptics_data *priv = psmouse->private;
1014
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 if (psmouse->pktcnt >= 6) { /* Full packet received */
1016 if (unlikely(priv->pkt_type == SYN_NEWABS))
1017 priv->pkt_type = synaptics_detect_pkt_type(psmouse);
1018
Dmitry Torokhova8b3c0f2010-10-04 21:46:10 -07001019 if (SYN_CAP_PASS_THROUGH(priv->capabilities) &&
1020 synaptics_is_pt_packet(psmouse->packet)) {
1021 if (priv->pt_port)
1022 synaptics_pass_pt_packet(priv->pt_port, psmouse->packet);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 } else
1024 synaptics_process_packet(psmouse);
1025
1026 return PSMOUSE_FULL_PACKET;
1027 }
1028
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001029 return synaptics_validate_byte(psmouse, psmouse->pktcnt - 1, priv->pkt_type) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
1031}
1032
1033/*****************************************************************************
1034 * Driver initialization/cleanup functions
1035 ****************************************************************************/
Daniel Kurtz85615472011-08-23 23:00:41 -07001036static void set_abs_position_params(struct input_dev *dev,
1037 struct synaptics_data *priv, int x_code,
1038 int y_code)
1039{
1040 int x_min = priv->x_min ?: XMIN_NOMINAL;
1041 int x_max = priv->x_max ?: XMAX_NOMINAL;
1042 int y_min = priv->y_min ?: YMIN_NOMINAL;
1043 int y_max = priv->y_max ?: YMAX_NOMINAL;
1044 int fuzz = SYN_CAP_REDUCED_FILTERING(priv->ext_cap_0c) ?
1045 SYN_REDUCED_FILTER_FUZZ : 0;
1046
1047 input_set_abs_params(dev, x_code, x_min, x_max, fuzz, 0);
1048 input_set_abs_params(dev, y_code, y_min, y_max, fuzz, 0);
1049 input_abs_set_res(dev, x_code, priv->x_res);
1050 input_abs_set_res(dev, y_code, priv->y_res);
1051}
1052
Hans de Goede43e19882014-04-19 22:26:41 -07001053static void set_input_params(struct psmouse *psmouse,
1054 struct synaptics_data *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055{
Hans de Goede43e19882014-04-19 22:26:41 -07001056 struct input_dev *dev = psmouse->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 int i;
1058
Daniel Drake7968a5d2011-11-08 00:00:35 -08001059 /* Things that apply to both modes */
Henrik Rydbergc14890a2010-12-16 09:52:23 +01001060 __set_bit(INPUT_PROP_POINTER, dev->propbit);
Daniel Drake7968a5d2011-11-08 00:00:35 -08001061 __set_bit(EV_KEY, dev->evbit);
1062 __set_bit(BTN_LEFT, dev->keybit);
1063 __set_bit(BTN_RIGHT, dev->keybit);
Henrik Rydbergc14890a2010-12-16 09:52:23 +01001064
Daniel Drake7968a5d2011-11-08 00:00:35 -08001065 if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
1066 __set_bit(BTN_MIDDLE, dev->keybit);
1067
1068 if (!priv->absolute_mode) {
1069 /* Relative mode */
1070 __set_bit(EV_REL, dev->evbit);
1071 __set_bit(REL_X, dev->relbit);
1072 __set_bit(REL_Y, dev->relbit);
1073 return;
1074 }
1075
1076 /* Absolute mode */
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001077 __set_bit(EV_ABS, dev->evbit);
Daniel Kurtz85615472011-08-23 23:00:41 -07001078 set_abs_position_params(dev, priv, ABS_X, ABS_Y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
Chris Bagwell2a8e7712010-07-19 09:06:15 -07001080
Henrik Rydberge08d9af2014-07-14 10:26:56 -07001081 if (cr48_profile_sensor)
1082 input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
1083
Daniel Kurtz3cdfee92011-08-23 23:02:25 -07001084 if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) {
Daniel Kurtz3cdfee92011-08-23 23:02:25 -07001085 set_abs_position_params(dev, priv, ABS_MT_POSITION_X,
1086 ABS_MT_POSITION_Y);
1087 /* Image sensors can report per-contact pressure */
1088 input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
Benjamin Tissoirese9e85202014-12-29 14:15:24 -08001089 input_mt_init_slots(dev, 2, INPUT_MT_POINTER | INPUT_MT_TRACK);
Daniel Kurtz6b4b49f2011-08-23 23:02:56 -07001090
1091 /* Image sensors can signal 4 and 5 finger clicks */
1092 __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
1093 __set_bit(BTN_TOOL_QUINTTAP, dev->keybit);
Daniel Kurtz3cdfee92011-08-23 23:02:25 -07001094 } else if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) {
Daniel Kurtz85615472011-08-23 23:00:41 -07001095 set_abs_position_params(dev, priv, ABS_MT_POSITION_X,
1096 ABS_MT_POSITION_Y);
Henrik Rydberge08d9af2014-07-14 10:26:56 -07001097 /*
1098 * Profile sensor in CR-48 tracks contacts reasonably well,
1099 * other non-image sensors with AGM use semi-mt.
1100 */
Dmitry Torokhovae841972014-07-25 17:12:12 -07001101 input_mt_init_slots(dev, 2,
Henrik Rydberge08d9af2014-07-14 10:26:56 -07001102 INPUT_MT_POINTER |
1103 (cr48_profile_sensor ?
1104 INPUT_MT_TRACK : INPUT_MT_SEMI_MT));
Henrik Rydbergfec6e522010-12-21 18:11:25 +01001105 }
1106
Chris Bagwell2a8e7712010-07-19 09:06:15 -07001107 if (SYN_CAP_PALMDETECT(priv->capabilities))
Chris Bagwell58fb0212010-07-19 09:06:15 -07001108 input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001110 __set_bit(BTN_TOUCH, dev->keybit);
1111 __set_bit(BTN_TOOL_FINGER, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
Peter Hutterere42b6642008-11-20 15:24:42 -05001113 if (SYN_CAP_MULTIFINGER(priv->capabilities)) {
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001114 __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
1115 __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
Peter Hutterere42b6642008-11-20 15:24:42 -05001116 }
1117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 if (SYN_CAP_FOUR_BUTTON(priv->capabilities) ||
1119 SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001120 __set_bit(BTN_FORWARD, dev->keybit);
1121 __set_bit(BTN_BACK, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 }
1123
1124 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001125 __set_bit(BTN_0 + i, dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001127 __clear_bit(EV_REL, dev->evbit);
1128 __clear_bit(REL_X, dev->relbit);
1129 __clear_bit(REL_Y, dev->relbit);
Tero Saarniec20a022009-06-10 23:27:24 -07001130
Takashi Iwai5f57d672010-04-19 10:37:21 -07001131 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
Henrik Rydbergc14890a2010-12-16 09:52:23 +01001132 __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
Hans de Goede2c75ada2014-09-11 10:14:09 -07001133 if (psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids))
Hans de Goedee2f61102014-05-19 22:53:23 -07001134 __set_bit(INPUT_PROP_TOPBUTTONPAD, dev->propbit);
Takashi Iwai5f57d672010-04-19 10:37:21 -07001135 /* Clickpads report only left button */
1136 __clear_bit(BTN_RIGHT, dev->keybit);
1137 __clear_bit(BTN_MIDDLE, dev->keybit);
1138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Daniel Drake7968a5d2011-11-08 00:00:35 -08001141static ssize_t synaptics_show_disable_gesture(struct psmouse *psmouse,
1142 void *data, char *buf)
1143{
1144 struct synaptics_data *priv = psmouse->private;
1145
1146 return sprintf(buf, "%c\n", priv->disable_gesture ? '1' : '0');
1147}
1148
1149static ssize_t synaptics_set_disable_gesture(struct psmouse *psmouse,
1150 void *data, const char *buf,
1151 size_t len)
1152{
1153 struct synaptics_data *priv = psmouse->private;
1154 unsigned int value;
1155 int err;
1156
1157 err = kstrtouint(buf, 10, &value);
1158 if (err)
1159 return err;
1160
1161 if (value > 1)
1162 return -EINVAL;
1163
1164 if (value == priv->disable_gesture)
1165 return len;
1166
1167 priv->disable_gesture = value;
1168 if (value)
1169 priv->mode |= SYN_BIT_DISABLE_GESTURE;
1170 else
1171 priv->mode &= ~SYN_BIT_DISABLE_GESTURE;
1172
1173 if (synaptics_mode_cmd(psmouse, priv->mode))
1174 return -EIO;
1175
1176 return len;
1177}
1178
1179PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL,
1180 synaptics_show_disable_gesture,
1181 synaptics_set_disable_gesture);
1182
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183static void synaptics_disconnect(struct psmouse *psmouse)
1184{
Daniel Drake7968a5d2011-11-08 00:00:35 -08001185 struct synaptics_data *priv = psmouse->private;
1186
1187 if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(priv->identity))
1188 device_remove_file(&psmouse->ps2dev.serio->dev,
1189 &psmouse_attr_disable_gesture.dattr);
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 synaptics_reset(psmouse);
Daniel Drake7968a5d2011-11-08 00:00:35 -08001192 kfree(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 psmouse->private = NULL;
1194}
1195
1196static int synaptics_reconnect(struct psmouse *psmouse)
1197{
1198 struct synaptics_data *priv = psmouse->private;
1199 struct synaptics_data old_priv = *priv;
Eric Miaoeeb06552013-06-04 09:30:55 -07001200 unsigned char param[2];
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -08001201 int retry = 0;
1202 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -08001204 do {
1205 psmouse_reset(psmouse);
Dmitry Torokhov85214782011-12-12 00:05:53 -08001206 if (retry) {
1207 /*
1208 * On some boxes, right after resuming, the touchpad
1209 * needs some time to finish initializing (I assume
1210 * it needs time to calibrate) and start responding
1211 * to Synaptics-specific queries, so let's wait a
1212 * bit.
1213 */
1214 ssleep(1);
1215 }
Eric Miaoeeb06552013-06-04 09:30:55 -07001216 ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETID);
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -08001217 error = synaptics_detect(psmouse, 0);
1218 } while (error && ++retry < 3);
Andy Whitcroft4d368452009-02-28 12:51:01 -08001219
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -08001220 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 return -1;
1222
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -08001223 if (retry > 1)
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001224 psmouse_dbg(psmouse, "reconnected after %d tries\n", retry);
Alexandre Peixoto Ferreirac63fe0a2011-01-28 22:05:14 -08001225
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 if (synaptics_query_hardware(psmouse)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001227 psmouse_err(psmouse, "Unable to query device.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 return -1;
1229 }
1230
Daniel Drake7968a5d2011-11-08 00:00:35 -08001231 if (synaptics_set_mode(psmouse)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001232 psmouse_err(psmouse, "Unable to initialize device.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 return -1;
1234 }
1235
Alexandre Peixoto Ferreirabaddf582011-01-28 22:05:14 -08001236 if (old_priv.identity != priv->identity ||
1237 old_priv.model_id != priv->model_id ||
1238 old_priv.capabilities != priv->capabilities ||
1239 old_priv.ext_cap != priv->ext_cap) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001240 psmouse_err(psmouse,
1241 "hardware appears to be different: id(%ld-%ld), model(%ld-%ld), caps(%lx-%lx), ext(%lx-%lx).\n",
1242 old_priv.identity, priv->identity,
1243 old_priv.model_id, priv->model_id,
1244 old_priv.capabilities, priv->capabilities,
1245 old_priv.ext_cap, priv->ext_cap);
Alexandre Peixoto Ferreirabaddf582011-01-28 22:05:14 -08001246 return -1;
1247 }
1248
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 return 0;
1250}
1251
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001252static bool impaired_toshiba_kbc;
1253
Sachin Kamatc9631562013-08-12 11:05:58 -07001254static const struct dmi_system_id toshiba_dmi_table[] __initconst = {
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001255#if defined(CONFIG_DMI) && defined(CONFIG_X86)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -08001257 /* Toshiba Satellite */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 .matches = {
1259 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
Richard Thrippleton53a26702006-04-02 00:10:18 -05001260 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 },
1262 },
Simon Horman9ba5eaa2005-07-11 01:07:20 -05001263 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -08001264 /* Toshiba Dynabook */
Simon Horman9ba5eaa2005-07-11 01:07:20 -05001265 .matches = {
1266 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
Richard Thrippleton53a26702006-04-02 00:10:18 -05001267 DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
1268 },
1269 },
1270 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -08001271 /* Toshiba Portege M300 */
Richard Thrippleton53a26702006-04-02 00:10:18 -05001272 .matches = {
1273 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1274 DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
Simon Horman9ba5eaa2005-07-11 01:07:20 -05001275 },
Dmitry Torokhov5f5eeff2009-10-12 21:35:00 -07001276
1277 },
1278 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -08001279 /* Toshiba Portege M300 */
Dmitry Torokhov5f5eeff2009-10-12 21:35:00 -07001280 .matches = {
1281 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1282 DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
1283 DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
1284 },
1285
Simon Horman9ba5eaa2005-07-11 01:07:20 -05001286 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287#endif
Jan Beulich70874862011-03-31 00:01:58 -07001288 { }
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001289};
1290
Andres Salomonef8313b2010-12-23 01:19:38 -08001291static bool broken_olpc_ec;
1292
Sachin Kamatc9631562013-08-12 11:05:58 -07001293static const struct dmi_system_id olpc_dmi_table[] __initconst = {
Andres Salomonef8313b2010-12-23 01:19:38 -08001294#if defined(CONFIG_DMI) && defined(CONFIG_OLPC)
1295 {
1296 /* OLPC XO-1 or XO-1.5 */
1297 .matches = {
1298 DMI_MATCH(DMI_SYS_VENDOR, "OLPC"),
1299 DMI_MATCH(DMI_PRODUCT_NAME, "XO"),
1300 },
1301 },
Andres Salomonef8313b2010-12-23 01:19:38 -08001302#endif
Jan Beulich70874862011-03-31 00:01:58 -07001303 { }
Andres Salomonef8313b2010-12-23 01:19:38 -08001304};
1305
Henrik Rydberge08d9af2014-07-14 10:26:56 -07001306static const struct dmi_system_id __initconst cr48_dmi_table[] = {
1307#if defined(CONFIG_DMI) && defined(CONFIG_X86)
1308 {
1309 /* Cr-48 Chromebook (Codename Mario) */
1310 .matches = {
1311 DMI_MATCH(DMI_SYS_VENDOR, "IEC"),
1312 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
1313 },
1314 },
1315#endif
1316 { }
1317};
1318
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001319void __init synaptics_module_init(void)
1320{
1321 impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
Andres Salomonef8313b2010-12-23 01:19:38 -08001322 broken_olpc_ec = dmi_check_system(olpc_dmi_table);
Henrik Rydberge08d9af2014-07-14 10:26:56 -07001323 cr48_profile_sensor = dmi_check_system(cr48_dmi_table);
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001324}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
Daniel Drake7968a5d2011-11-08 00:00:35 -08001326static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
1328 struct synaptics_data *priv;
Daniel Drake7968a5d2011-11-08 00:00:35 -08001329 int err = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Andres Salomonef8313b2010-12-23 01:19:38 -08001331 /*
Daniel Drake83551c02011-11-11 16:05:04 -08001332 * The OLPC XO has issues with Synaptics' absolute mode; the constant
1333 * packet spew overloads the EC such that key presses on the keyboard
1334 * are missed. Given that, don't even attempt to use Absolute mode.
1335 * Relative mode seems to work just fine.
Andres Salomonef8313b2010-12-23 01:19:38 -08001336 */
Daniel Drake83551c02011-11-11 16:05:04 -08001337 if (absolute_mode && broken_olpc_ec) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001338 psmouse_info(psmouse,
1339 "OLPC XO detected, not enabling Synaptics protocol.\n");
Andres Salomonef8313b2010-12-23 01:19:38 -08001340 return -ENODEV;
1341 }
1342
Eric Sesterhennb39787a2006-03-14 00:09:16 -05001343 psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 if (!priv)
Davidlohr Bueso6792cbb2010-09-29 18:53:35 -07001345 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
Andy Whitcroft4d368452009-02-28 12:51:01 -08001347 psmouse_reset(psmouse);
1348
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 if (synaptics_query_hardware(psmouse)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001350 psmouse_err(psmouse, "Unable to query device.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 goto init_fail;
1352 }
1353
Daniel Drake7968a5d2011-11-08 00:00:35 -08001354 priv->absolute_mode = absolute_mode;
1355 if (SYN_ID_DISGEST_SUPPORTED(priv->identity))
1356 priv->disable_gesture = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Dmitry Torokhovde4e3742014-12-29 14:43:44 -08001358 /*
1359 * Unfortunately ForcePad capability is not exported over PS/2,
1360 * so we have to resort to checking PNP IDs.
1361 */
1362 priv->is_forcepad = psmouse_matches_pnp_id(psmouse, forcepad_pnp_ids);
1363
Daniel Drake7968a5d2011-11-08 00:00:35 -08001364 if (synaptics_set_mode(psmouse)) {
1365 psmouse_err(psmouse, "Unable to initialize device.\n");
Henrik Rydbergfec6e522010-12-21 18:11:25 +01001366 goto init_fail;
1367 }
1368
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS;
1370
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001371 psmouse_info(psmouse,
Daniel Kurtzc6bd9d42012-07-07 18:08:51 -07001372 "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 -07001373 SYN_ID_MODEL(priv->identity),
1374 SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity),
1375 priv->model_id,
Daniel Kurtzc6bd9d42012-07-07 18:08:51 -07001376 priv->capabilities, priv->ext_cap, priv->ext_cap_0c,
1377 priv->board_id, priv->firmware_id);
Dmitry Torokhov409b7502005-05-28 02:12:18 -05001378
Hans de Goede43e19882014-04-19 22:26:41 -07001379 set_input_params(psmouse, priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Dmitry Torokhov887cc122007-04-12 01:30:41 -04001381 /*
1382 * Encode touchpad model so that it can be used to set
1383 * input device->id.version and be visible to userspace.
1384 * Because version is __u16 we have to drop something.
1385 * Hardware info bits seem to be good candidates as they
1386 * are documented to be for Synaptics corp. internal use.
1387 */
1388 psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) |
1389 (priv->model_id & 0x000000ff);
1390
Daniel Drake7968a5d2011-11-08 00:00:35 -08001391 if (absolute_mode) {
1392 psmouse->protocol_handler = synaptics_process_byte;
1393 psmouse->pktsize = 6;
1394 } else {
1395 /* Relative mode follows standard PS/2 mouse protocol */
1396 psmouse->protocol_handler = psmouse_process_byte;
1397 psmouse->pktsize = 3;
1398 }
1399
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 psmouse->set_rate = synaptics_set_rate;
1401 psmouse->disconnect = synaptics_disconnect;
1402 psmouse->reconnect = synaptics_reconnect;
Dmitry Torokhova1cec062007-02-18 01:40:24 -05001403 psmouse->cleanup = synaptics_reset;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001404 /* Synaptics can usually stay in sync without extra help */
1405 psmouse->resync_time = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
1407 if (SYN_CAP_PASS_THROUGH(priv->capabilities))
1408 synaptics_pt_create(psmouse);
1409
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 /*
1411 * Toshiba's KBC seems to have trouble handling data from
Andres Salomon7ee99162010-12-23 01:18:28 -08001412 * Synaptics at full rate. Switch to a lower rate (roughly
1413 * the same rate as a standard PS/2 mouse).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 */
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001415 if (psmouse->rate >= 80 && impaired_toshiba_kbc) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001416 psmouse_info(psmouse,
1417 "Toshiba %s detected, limiting rate to 40pps.\n",
1418 dmi_get_system_info(DMI_PRODUCT_NAME));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 psmouse->rate = 40;
1420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
Daniel Drake7968a5d2011-11-08 00:00:35 -08001422 if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(priv->identity)) {
1423 err = device_create_file(&psmouse->ps2dev.serio->dev,
1424 &psmouse_attr_disable_gesture.dattr);
1425 if (err) {
1426 psmouse_err(psmouse,
1427 "Failed to create disable_gesture attribute (%d)",
1428 err);
1429 goto init_fail;
1430 }
1431 }
1432
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 return 0;
1434
1435 init_fail:
1436 kfree(priv);
Daniel Drake7968a5d2011-11-08 00:00:35 -08001437 return err;
1438}
1439
1440int synaptics_init(struct psmouse *psmouse)
1441{
1442 return __synaptics_init(psmouse, true);
1443}
1444
1445int synaptics_init_relative(struct psmouse *psmouse)
1446{
1447 return __synaptics_init(psmouse, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448}
1449
Andres Salomon55e3d922007-03-10 01:39:54 -05001450#else /* CONFIG_MOUSE_PS2_SYNAPTICS */
1451
Dmitry Torokhov7705d542009-12-03 23:21:14 -08001452void __init synaptics_module_init(void)
1453{
1454}
1455
Andres Salomon55e3d922007-03-10 01:39:54 -05001456int synaptics_init(struct psmouse *psmouse)
1457{
1458 return -ENOSYS;
1459}
1460
1461#endif /* CONFIG_MOUSE_PS2_SYNAPTICS */