Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Synaptics TouchPad PS/2 mouse driver |
| 3 | * |
| 4 | * 2003 Dmitry Torokhov <dtor@mail.ru> |
| 5 | * Added support for pass-through port. Special thanks to Peter Berg Larsen |
| 6 | * for explaining various Synaptics quirks. |
| 7 | * |
| 8 | * 2003 Peter Osterlund <petero2@telia.com> |
| 9 | * Ported to 2.5 input device infrastructure. |
| 10 | * |
| 11 | * Copyright (C) 2001 Stefan Gmeiner <riddlebox@freesurf.ch> |
| 12 | * start merging tpconfig and gpm code to a xfree-input module |
| 13 | * adding some changes and extensions (ex. 3rd and 4th button) |
| 14 | * |
| 15 | * Copyright (c) 1997 C. Scott Ananian <cananian@alumni.priceton.edu> |
| 16 | * Copyright (c) 1998-2000 Bruce Kalk <kall@compass.com> |
| 17 | * code for the special synaptics commands (from the tpconfig-source) |
| 18 | * |
| 19 | * This program is free software; you can redistribute it and/or modify it |
| 20 | * under the terms of the GNU General Public License version 2 as published by |
| 21 | * the Free Software Foundation. |
| 22 | * |
| 23 | * Trademarks are the property of their respective owners. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
Dmitry Torokhov | 8521478 | 2011-12-12 00:05:53 -0800 | [diff] [blame] | 27 | #include <linux/delay.h> |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 28 | #include <linux/dmi.h> |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 29 | #include <linux/input/mt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/serio.h> |
| 31 | #include <linux/libps2.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #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 Torokhov | 83ba9ea8 | 2010-05-10 23:06:52 -0700 | [diff] [blame] | 40 | * Note that newer firmware allows querying device for maximum useable |
| 41 | * coordinates. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | */ |
Seth Forshee | c0394506 | 2012-07-24 23:54:11 -0700 | [diff] [blame] | 43 | #define XMIN 0 |
| 44 | #define XMAX 6143 |
| 45 | #define YMIN 0 |
| 46 | #define YMAX 6143 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define XMIN_NOMINAL 1472 |
| 48 | #define XMAX_NOMINAL 5472 |
| 49 | #define YMIN_NOMINAL 1408 |
| 50 | #define YMAX_NOMINAL 4448 |
| 51 | |
Seth Forshee | c0394506 | 2012-07-24 23:54:11 -0700 | [diff] [blame] | 52 | /* Size in bits of absolute position values reported by the hardware */ |
| 53 | #define ABS_POS_BITS 13 |
| 54 | |
| 55 | /* |
Seth Forshee | 824efd3 | 2012-09-28 10:29:21 -0700 | [diff] [blame] | 56 | * 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 Forshee | c0394506 | 2012-07-24 23:54:11 -0700 | [diff] [blame] | 66 | */ |
Seth Forshee | 824efd3 | 2012-09-28 10:29:21 -0700 | [diff] [blame] | 67 | #define X_MAX_POSITIVE 8176 |
| 68 | #define Y_MAX_POSITIVE 8176 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 70 | /***************************************************************************** |
| 71 | * Stuff we need even when we do not want native Synaptics support |
| 72 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * Set the synaptics touchpad mode byte by special commands |
| 76 | */ |
| 77 | static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode) |
| 78 | { |
| 79 | unsigned char param[1]; |
| 80 | |
| 81 | if (psmouse_sliced_command(psmouse, mode)) |
| 82 | return -1; |
| 83 | param[0] = SYN_PS_SET_MODE2; |
| 84 | if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE)) |
| 85 | return -1; |
| 86 | return 0; |
| 87 | } |
| 88 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 89 | int synaptics_detect(struct psmouse *psmouse, bool set_properties) |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 90 | { |
| 91 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 92 | unsigned char param[4]; |
| 93 | |
| 94 | param[0] = 0; |
| 95 | |
| 96 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); |
| 97 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); |
| 98 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); |
| 99 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); |
| 100 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO); |
| 101 | |
| 102 | if (param[1] != 0x47) |
| 103 | return -ENODEV; |
| 104 | |
| 105 | if (set_properties) { |
| 106 | psmouse->vendor = "Synaptics"; |
| 107 | psmouse->name = "TouchPad"; |
| 108 | } |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | void synaptics_reset(struct psmouse *psmouse) |
| 114 | { |
| 115 | /* reset touchpad back to relative mode, gestures enabled */ |
| 116 | synaptics_mode_cmd(psmouse, 0); |
| 117 | } |
| 118 | |
| 119 | #ifdef CONFIG_MOUSE_PS2_SYNAPTICS |
Hans de Goede | 43e1988 | 2014-04-19 22:26:41 -0700 | [diff] [blame] | 120 | /* This list has been kindly provided by Synaptics. */ |
| 121 | static const char * const topbuttonpad_pnp_ids[] = { |
| 122 | "LEN0017", |
| 123 | "LEN0018", |
| 124 | "LEN0019", |
| 125 | "LEN0023", |
| 126 | "LEN002A", |
| 127 | "LEN002B", |
| 128 | "LEN002C", |
| 129 | "LEN002D", |
| 130 | "LEN002E", |
| 131 | "LEN0033", /* Helix */ |
| 132 | "LEN0034", /* T431s, T540, X1 Carbon 2nd */ |
| 133 | "LEN0035", /* X240 */ |
| 134 | "LEN0036", /* T440 */ |
| 135 | "LEN0037", |
| 136 | "LEN0038", |
| 137 | "LEN0041", |
| 138 | "LEN0042", /* Yoga */ |
| 139 | "LEN0045", |
| 140 | "LEN0046", |
| 141 | "LEN0047", |
| 142 | "LEN0048", |
| 143 | "LEN0049", |
| 144 | "LEN2000", |
| 145 | "LEN2001", |
| 146 | "LEN2002", |
| 147 | "LEN2003", |
| 148 | "LEN2004", /* L440 */ |
| 149 | "LEN2005", |
| 150 | "LEN2006", |
| 151 | "LEN2007", |
| 152 | "LEN2008", |
| 153 | "LEN2009", |
| 154 | "LEN200A", |
| 155 | "LEN200B", |
| 156 | NULL |
| 157 | }; |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 158 | |
Hans de Goede | e2f6110 | 2014-05-19 22:53:23 -0700 | [diff] [blame^] | 159 | static bool matches_pnp_id(struct psmouse *psmouse, const char * const ids[]) |
| 160 | { |
| 161 | int i; |
| 162 | |
| 163 | if (!strncmp(psmouse->ps2dev.serio->firmware_id, "PNP:", 4)) |
| 164 | for (i = 0; ids[i]; i++) |
| 165 | if (strstr(psmouse->ps2dev.serio->firmware_id, ids[i])) |
| 166 | return true; |
| 167 | |
| 168 | return false; |
| 169 | } |
| 170 | |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 171 | /***************************************************************************** |
| 172 | * Synaptics communications functions |
| 173 | ****************************************************************************/ |
| 174 | |
| 175 | /* |
JJ Ding | 1a49a0a | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 176 | * Synaptics touchpads report the y coordinate from bottom to top, which is |
| 177 | * opposite from what userspace expects. |
| 178 | * This function is used to invert y before reporting. |
| 179 | */ |
| 180 | static int synaptics_invert_y(int y) |
| 181 | { |
| 182 | return YMAX_NOMINAL + YMIN_NOMINAL - y; |
| 183 | } |
| 184 | |
| 185 | /* |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 186 | * Send a command to the synpatics touchpad by special commands |
| 187 | */ |
| 188 | static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param) |
| 189 | { |
| 190 | if (psmouse_sliced_command(psmouse, c)) |
| 191 | return -1; |
| 192 | if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 193 | return -1; |
| 194 | return 0; |
| 195 | } |
| 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | /* |
| 198 | * Read the model-id bytes from the touchpad |
| 199 | * see also SYN_MODEL_* macros |
| 200 | */ |
| 201 | static int synaptics_model_id(struct psmouse *psmouse) |
| 202 | { |
| 203 | struct synaptics_data *priv = psmouse->private; |
| 204 | unsigned char mi[3]; |
| 205 | |
| 206 | if (synaptics_send_cmd(psmouse, SYN_QUE_MODEL, mi)) |
| 207 | return -1; |
| 208 | priv->model_id = (mi[0]<<16) | (mi[1]<<8) | mi[2]; |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | /* |
Daniel Kurtz | c6bd9d4 | 2012-07-07 18:08:51 -0700 | [diff] [blame] | 213 | * Read the board id from the touchpad |
| 214 | * The board id is encoded in the "QUERY MODES" response |
| 215 | */ |
| 216 | static int synaptics_board_id(struct psmouse *psmouse) |
| 217 | { |
| 218 | struct synaptics_data *priv = psmouse->private; |
| 219 | unsigned char bid[3]; |
| 220 | |
| 221 | if (synaptics_send_cmd(psmouse, SYN_QUE_MODES, bid)) |
| 222 | return -1; |
| 223 | priv->board_id = ((bid[0] & 0xfc) << 6) | bid[1]; |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | /* |
| 228 | * Read the firmware id from the touchpad |
| 229 | */ |
| 230 | static int synaptics_firmware_id(struct psmouse *psmouse) |
| 231 | { |
| 232 | struct synaptics_data *priv = psmouse->private; |
| 233 | unsigned char fwid[3]; |
| 234 | |
| 235 | if (synaptics_send_cmd(psmouse, SYN_QUE_FIRMWARE_ID, fwid)) |
| 236 | return -1; |
| 237 | priv->firmware_id = (fwid[0] << 16) | (fwid[1] << 8) | fwid[2]; |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | * Read the capability-bits from the touchpad |
| 243 | * see also the SYN_CAP_* macros |
| 244 | */ |
| 245 | static int synaptics_capability(struct psmouse *psmouse) |
| 246 | { |
| 247 | struct synaptics_data *priv = psmouse->private; |
| 248 | unsigned char cap[3]; |
| 249 | |
| 250 | if (synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap)) |
| 251 | return -1; |
| 252 | priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2]; |
Takashi Iwai | 5f57d67 | 2010-04-19 10:37:21 -0700 | [diff] [blame] | 253 | priv->ext_cap = priv->ext_cap_0c = 0; |
| 254 | |
Dmitry Torokhov | 3619b8f | 2010-07-21 00:01:19 -0700 | [diff] [blame] | 255 | /* |
| 256 | * Older firmwares had submodel ID fixed to 0x47 |
| 257 | */ |
| 258 | if (SYN_ID_FULL(priv->identity) < 0x705 && |
| 259 | SYN_CAP_SUBMODEL_ID(priv->capabilities) != 0x47) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | return -1; |
Dmitry Torokhov | 3619b8f | 2010-07-21 00:01:19 -0700 | [diff] [blame] | 261 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
| 263 | /* |
| 264 | * Unless capExtended is set the rest of the flags should be ignored |
| 265 | */ |
| 266 | if (!SYN_CAP_EXTENDED(priv->capabilities)) |
| 267 | priv->capabilities = 0; |
| 268 | |
| 269 | if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 1) { |
| 270 | if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB, cap)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 271 | psmouse_warn(psmouse, |
| 272 | "device claims to have extended capabilities, but I'm not able to read them.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | } else { |
| 274 | priv->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2]; |
| 275 | |
| 276 | /* |
| 277 | * if nExtBtn is greater than 8 it should be considered |
| 278 | * invalid and treated as 0 |
| 279 | */ |
| 280 | if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) > 8) |
| 281 | priv->ext_cap &= 0xff0fff; |
| 282 | } |
| 283 | } |
Takashi Iwai | 5f57d67 | 2010-04-19 10:37:21 -0700 | [diff] [blame] | 284 | |
| 285 | if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 4) { |
| 286 | if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB_0C, cap)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 287 | psmouse_warn(psmouse, |
| 288 | "device claims to have extended capability 0x0c, but I'm not able to read it.\n"); |
Takashi Iwai | 5f57d67 | 2010-04-19 10:37:21 -0700 | [diff] [blame] | 289 | } else { |
| 290 | priv->ext_cap_0c = (cap[0] << 16) | (cap[1] << 8) | cap[2]; |
| 291 | } |
| 292 | } |
| 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * Identify Touchpad |
| 299 | * See also the SYN_ID_* macros |
| 300 | */ |
| 301 | static int synaptics_identify(struct psmouse *psmouse) |
| 302 | { |
| 303 | struct synaptics_data *priv = psmouse->private; |
| 304 | unsigned char id[3]; |
| 305 | |
| 306 | if (synaptics_send_cmd(psmouse, SYN_QUE_IDENTIFY, id)) |
| 307 | return -1; |
| 308 | priv->identity = (id[0]<<16) | (id[1]<<8) | id[2]; |
| 309 | if (SYN_ID_IS_SYNAPTICS(priv->identity)) |
| 310 | return 0; |
| 311 | return -1; |
| 312 | } |
| 313 | |
Tero Saarni | ec20a02 | 2009-06-10 23:27:24 -0700 | [diff] [blame] | 314 | /* |
Dmitry Torokhov | 83ba9ea8 | 2010-05-10 23:06:52 -0700 | [diff] [blame] | 315 | * Read touchpad resolution and maximum reported coordinates |
Tero Saarni | ec20a02 | 2009-06-10 23:27:24 -0700 | [diff] [blame] | 316 | * Resolution is left zero if touchpad does not support the query |
| 317 | */ |
Benjamin Tissoires | 421e08c | 2014-03-28 00:43:00 -0700 | [diff] [blame] | 318 | |
| 319 | static const int *quirk_min_max; |
| 320 | |
Tero Saarni | ec20a02 | 2009-06-10 23:27:24 -0700 | [diff] [blame] | 321 | static int synaptics_resolution(struct psmouse *psmouse) |
| 322 | { |
| 323 | struct synaptics_data *priv = psmouse->private; |
Dmitry Torokhov | a66413f | 2011-07-09 12:32:56 -0700 | [diff] [blame] | 324 | unsigned char resp[3]; |
Tero Saarni | ec20a02 | 2009-06-10 23:27:24 -0700 | [diff] [blame] | 325 | |
Benjamin Tissoires | 421e08c | 2014-03-28 00:43:00 -0700 | [diff] [blame] | 326 | if (quirk_min_max) { |
| 327 | priv->x_min = quirk_min_max[0]; |
| 328 | priv->x_max = quirk_min_max[1]; |
| 329 | priv->y_min = quirk_min_max[2]; |
| 330 | priv->y_max = quirk_min_max[3]; |
| 331 | return 0; |
| 332 | } |
| 333 | |
Tero Saarni | ec20a02 | 2009-06-10 23:27:24 -0700 | [diff] [blame] | 334 | if (SYN_ID_MAJOR(priv->identity) < 4) |
Takashi Iwai | bbddd19 | 2010-07-14 09:32:46 -0700 | [diff] [blame] | 335 | return 0; |
Tero Saarni | ec20a02 | 2009-06-10 23:27:24 -0700 | [diff] [blame] | 336 | |
Dmitry Torokhov | a66413f | 2011-07-09 12:32:56 -0700 | [diff] [blame] | 337 | if (synaptics_send_cmd(psmouse, SYN_QUE_RESOLUTION, resp) == 0) { |
| 338 | if (resp[0] != 0 && (resp[1] & 0x80) && resp[2] != 0) { |
| 339 | priv->x_res = resp[0]; /* x resolution in units/mm */ |
| 340 | priv->y_res = resp[2]; /* y resolution in units/mm */ |
Dmitry Torokhov | 83ba9ea8 | 2010-05-10 23:06:52 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
Tero Saarni | ec20a02 | 2009-06-10 23:27:24 -0700 | [diff] [blame] | 343 | |
Dmitry Torokhov | 83ba9ea8 | 2010-05-10 23:06:52 -0700 | [diff] [blame] | 344 | if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 5 && |
| 345 | SYN_CAP_MAX_DIMENSIONS(priv->ext_cap_0c)) { |
Dmitry Torokhov | a66413f | 2011-07-09 12:32:56 -0700 | [diff] [blame] | 346 | if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_MAX_COORDS, resp)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 347 | psmouse_warn(psmouse, |
| 348 | "device claims to have max coordinates query, but I'm not able to read it.\n"); |
Dmitry Torokhov | 83ba9ea8 | 2010-05-10 23:06:52 -0700 | [diff] [blame] | 349 | } else { |
Dmitry Torokhov | a66413f | 2011-07-09 12:32:56 -0700 | [diff] [blame] | 350 | priv->x_max = (resp[0] << 5) | ((resp[1] & 0x0f) << 1); |
| 351 | priv->y_max = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 7 && |
| 356 | SYN_CAP_MIN_DIMENSIONS(priv->ext_cap_0c)) { |
| 357 | if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_MIN_COORDS, resp)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 358 | psmouse_warn(psmouse, |
| 359 | "device claims to have min coordinates query, but I'm not able to read it.\n"); |
Dmitry Torokhov | a66413f | 2011-07-09 12:32:56 -0700 | [diff] [blame] | 360 | } else { |
| 361 | priv->x_min = (resp[0] << 5) | ((resp[1] & 0x0f) << 1); |
| 362 | priv->y_min = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3); |
Dmitry Torokhov | 83ba9ea8 | 2010-05-10 23:06:52 -0700 | [diff] [blame] | 363 | } |
Tero Saarni | ec20a02 | 2009-06-10 23:27:24 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | static int synaptics_query_hardware(struct psmouse *psmouse) |
| 370 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | if (synaptics_identify(psmouse)) |
| 372 | return -1; |
| 373 | if (synaptics_model_id(psmouse)) |
| 374 | return -1; |
Daniel Kurtz | c6bd9d4 | 2012-07-07 18:08:51 -0700 | [diff] [blame] | 375 | if (synaptics_firmware_id(psmouse)) |
| 376 | return -1; |
| 377 | if (synaptics_board_id(psmouse)) |
| 378 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | if (synaptics_capability(psmouse)) |
| 380 | return -1; |
Tero Saarni | ec20a02 | 2009-06-10 23:27:24 -0700 | [diff] [blame] | 381 | if (synaptics_resolution(psmouse)) |
| 382 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 387 | static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse) |
| 388 | { |
| 389 | static unsigned char param = 0xc8; |
| 390 | struct synaptics_data *priv = psmouse->private; |
| 391 | |
Benjamin Herrenschmidt | 899c612 | 2012-04-20 22:34:49 -0700 | [diff] [blame] | 392 | if (!(SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) || |
| 393 | SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c))) |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 394 | return 0; |
| 395 | |
| 396 | if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL)) |
| 397 | return -1; |
| 398 | |
| 399 | if (ps2_command(&psmouse->ps2dev, ¶m, PSMOUSE_CMD_SETRATE)) |
| 400 | return -1; |
| 401 | |
| 402 | /* Advanced gesture mode also sends multi finger data */ |
| 403 | priv->capabilities |= BIT(1); |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | static int synaptics_set_mode(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | { |
| 410 | struct synaptics_data *priv = psmouse->private; |
| 411 | |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 412 | priv->mode = 0; |
| 413 | if (priv->absolute_mode) |
| 414 | priv->mode |= SYN_BIT_ABSOLUTE_MODE; |
| 415 | if (priv->disable_gesture) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | priv->mode |= SYN_BIT_DISABLE_GESTURE; |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 417 | if (psmouse->rate >= 80) |
| 418 | priv->mode |= SYN_BIT_HIGH_RATE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | if (SYN_CAP_EXTENDED(priv->capabilities)) |
| 420 | priv->mode |= SYN_BIT_W_MODE; |
| 421 | |
| 422 | if (synaptics_mode_cmd(psmouse, priv->mode)) |
| 423 | return -1; |
| 424 | |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 425 | if (priv->absolute_mode && |
| 426 | synaptics_set_advanced_gesture_mode(psmouse)) { |
| 427 | psmouse_err(psmouse, "Advanced gesture mode init failed.\n"); |
| 428 | return -1; |
| 429 | } |
| 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate) |
| 435 | { |
| 436 | struct synaptics_data *priv = psmouse->private; |
| 437 | |
| 438 | if (rate >= 80) { |
| 439 | priv->mode |= SYN_BIT_HIGH_RATE; |
| 440 | psmouse->rate = 80; |
| 441 | } else { |
| 442 | priv->mode &= ~SYN_BIT_HIGH_RATE; |
| 443 | psmouse->rate = 40; |
| 444 | } |
| 445 | |
| 446 | synaptics_mode_cmd(psmouse, priv->mode); |
| 447 | } |
| 448 | |
| 449 | /***************************************************************************** |
| 450 | * Synaptics pass-through PS/2 port support |
| 451 | ****************************************************************************/ |
| 452 | static int synaptics_pt_write(struct serio *serio, unsigned char c) |
| 453 | { |
| 454 | struct psmouse *parent = serio_get_drvdata(serio->parent); |
| 455 | char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */ |
| 456 | |
| 457 | if (psmouse_sliced_command(parent, c)) |
| 458 | return -1; |
| 459 | if (ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE)) |
| 460 | return -1; |
| 461 | return 0; |
| 462 | } |
| 463 | |
Dmitry Torokhov | a8b3c0f | 2010-10-04 21:46:10 -0700 | [diff] [blame] | 464 | static int synaptics_pt_start(struct serio *serio) |
| 465 | { |
| 466 | struct psmouse *parent = serio_get_drvdata(serio->parent); |
| 467 | struct synaptics_data *priv = parent->private; |
| 468 | |
| 469 | serio_pause_rx(parent->ps2dev.serio); |
| 470 | priv->pt_port = serio; |
| 471 | serio_continue_rx(parent->ps2dev.serio); |
| 472 | |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | static void synaptics_pt_stop(struct serio *serio) |
| 477 | { |
| 478 | struct psmouse *parent = serio_get_drvdata(serio->parent); |
| 479 | struct synaptics_data *priv = parent->private; |
| 480 | |
| 481 | serio_pause_rx(parent->ps2dev.serio); |
| 482 | priv->pt_port = NULL; |
| 483 | serio_continue_rx(parent->ps2dev.serio); |
| 484 | } |
| 485 | |
| 486 | static int synaptics_is_pt_packet(unsigned char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | { |
| 488 | return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4; |
| 489 | } |
| 490 | |
| 491 | static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet) |
| 492 | { |
| 493 | struct psmouse *child = serio_get_drvdata(ptport); |
| 494 | |
| 495 | if (child && child->state == PSMOUSE_ACTIVATED) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 496 | serio_interrupt(ptport, packet[1], 0); |
| 497 | serio_interrupt(ptport, packet[4], 0); |
| 498 | serio_interrupt(ptport, packet[5], 0); |
Sergey Vlasov | 33fdfa9 | 2005-07-24 00:53:32 -0500 | [diff] [blame] | 499 | if (child->pktsize == 4) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 500 | serio_interrupt(ptport, packet[2], 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | } else |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 502 | serio_interrupt(ptport, packet[1], 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | static void synaptics_pt_activate(struct psmouse *psmouse) |
| 506 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | struct synaptics_data *priv = psmouse->private; |
Dmitry Torokhov | a8b3c0f | 2010-10-04 21:46:10 -0700 | [diff] [blame] | 508 | struct psmouse *child = serio_get_drvdata(priv->pt_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
| 510 | /* adjust the touchpad to child's choice of protocol */ |
| 511 | if (child) { |
Sergey Vlasov | 33fdfa9 | 2005-07-24 00:53:32 -0500 | [diff] [blame] | 512 | if (child->pktsize == 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT; |
| 514 | else |
| 515 | priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT; |
| 516 | |
| 517 | if (synaptics_mode_cmd(psmouse, priv->mode)) |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 518 | psmouse_warn(psmouse, |
| 519 | "failed to switch guest protocol\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | |
| 523 | static void synaptics_pt_create(struct psmouse *psmouse) |
| 524 | { |
| 525 | struct serio *serio; |
| 526 | |
Eric Sesterhenn | b39787a | 2006-03-14 00:09:16 -0500 | [diff] [blame] | 527 | serio = kzalloc(sizeof(struct serio), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | if (!serio) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 529 | psmouse_err(psmouse, |
| 530 | "not enough memory for pass-through port\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | return; |
| 532 | } |
| 533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | serio->id.type = SERIO_PS_PSTHRU; |
| 535 | strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name)); |
| 536 | strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name)); |
| 537 | serio->write = synaptics_pt_write; |
Dmitry Torokhov | a8b3c0f | 2010-10-04 21:46:10 -0700 | [diff] [blame] | 538 | serio->start = synaptics_pt_start; |
| 539 | serio->stop = synaptics_pt_stop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | serio->parent = psmouse->ps2dev.serio; |
| 541 | |
| 542 | psmouse->pt_activate = synaptics_pt_activate; |
| 543 | |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 544 | psmouse_info(psmouse, "serio: %s port at %s\n", |
| 545 | serio->name, psmouse->phys); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | serio_register_port(serio); |
| 547 | } |
| 548 | |
| 549 | /***************************************************************************** |
| 550 | * Functions to interpret the absolute mode packets |
| 551 | ****************************************************************************/ |
| 552 | |
Daniel Kurtz | a6ca40c | 2011-08-23 23:02:31 -0700 | [diff] [blame] | 553 | static void synaptics_mt_state_set(struct synaptics_mt_state *state, int count, |
| 554 | int sgm, int agm) |
| 555 | { |
| 556 | state->count = count; |
| 557 | state->sgm = sgm; |
| 558 | state->agm = agm; |
| 559 | } |
| 560 | |
Daniel Kurtz | 7afdb84 | 2011-08-23 23:00:33 -0700 | [diff] [blame] | 561 | static void synaptics_parse_agm(const unsigned char buf[], |
Daniel Kurtz | a6ca40c | 2011-08-23 23:02:31 -0700 | [diff] [blame] | 562 | struct synaptics_data *priv, |
| 563 | struct synaptics_hw_state *hw) |
Daniel Kurtz | 7afdb84 | 2011-08-23 23:00:33 -0700 | [diff] [blame] | 564 | { |
| 565 | struct synaptics_hw_state *agm = &priv->agm; |
Daniel Kurtz | a6ca40c | 2011-08-23 23:02:31 -0700 | [diff] [blame] | 566 | int agm_packet_type; |
Daniel Kurtz | 7afdb84 | 2011-08-23 23:00:33 -0700 | [diff] [blame] | 567 | |
Daniel Kurtz | a6ca40c | 2011-08-23 23:02:31 -0700 | [diff] [blame] | 568 | agm_packet_type = (buf[5] & 0x30) >> 4; |
| 569 | switch (agm_packet_type) { |
| 570 | case 1: |
| 571 | /* Gesture packet: (x, y, z) half resolution */ |
| 572 | agm->w = hw->w; |
| 573 | agm->x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1; |
| 574 | agm->y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1; |
| 575 | agm->z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1; |
| 576 | break; |
| 577 | |
| 578 | case 2: |
| 579 | /* AGM-CONTACT packet: (count, sgm, agm) */ |
| 580 | synaptics_mt_state_set(&agm->mt_state, buf[1], buf[2], buf[4]); |
| 581 | break; |
| 582 | |
| 583 | default: |
| 584 | break; |
| 585 | } |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 586 | |
| 587 | /* Record that at least one AGM has been received since last SGM */ |
| 588 | priv->agm_pending = true; |
Daniel Kurtz | 7afdb84 | 2011-08-23 23:00:33 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 591 | static int synaptics_parse_hw_state(const unsigned char buf[], |
| 592 | struct synaptics_data *priv, |
| 593 | struct synaptics_hw_state *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | { |
| 595 | memset(hw, 0, sizeof(struct synaptics_hw_state)); |
| 596 | |
| 597 | if (SYN_MODEL_NEWABS(priv->model_id)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | hw->w = (((buf[0] & 0x30) >> 2) | |
| 599 | ((buf[0] & 0x04) >> 1) | |
| 600 | ((buf[3] & 0x04) >> 2)); |
| 601 | |
| 602 | hw->left = (buf[0] & 0x01) ? 1 : 0; |
| 603 | hw->right = (buf[0] & 0x02) ? 1 : 0; |
| 604 | |
Takashi Iwai | 5f57d67 | 2010-04-19 10:37:21 -0700 | [diff] [blame] | 605 | if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) { |
| 606 | /* |
| 607 | * Clickpad's button is transmitted as middle button, |
| 608 | * however, since it is primary button, we will report |
| 609 | * it as BTN_LEFT. |
| 610 | */ |
| 611 | hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; |
| 612 | |
| 613 | } else if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; |
| 615 | if (hw->w == 2) |
| 616 | hw->scroll = (signed char)(buf[1]); |
| 617 | } |
| 618 | |
| 619 | if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) { |
| 620 | hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; |
| 621 | hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0; |
| 622 | } |
| 623 | |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 624 | if ((SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) || |
| 625 | SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) && |
| 626 | hw->w == 2) { |
Daniel Kurtz | a6ca40c | 2011-08-23 23:02:31 -0700 | [diff] [blame] | 627 | synaptics_parse_agm(buf, priv, hw); |
Daniel Kurtz | 28d5fd8 | 2011-07-06 22:57:39 -0700 | [diff] [blame] | 628 | return 1; |
| 629 | } |
| 630 | |
| 631 | hw->x = (((buf[3] & 0x10) << 8) | |
| 632 | ((buf[1] & 0x0f) << 8) | |
| 633 | buf[4]); |
| 634 | hw->y = (((buf[3] & 0x20) << 7) | |
| 635 | ((buf[1] & 0xf0) << 4) | |
| 636 | buf[5]); |
| 637 | hw->z = buf[2]; |
| 638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) && |
| 640 | ((buf[0] ^ buf[3]) & 0x02)) { |
| 641 | switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) { |
| 642 | default: |
| 643 | /* |
| 644 | * if nExtBtn is greater than 8 it should be |
| 645 | * considered invalid and treated as 0 |
| 646 | */ |
| 647 | break; |
| 648 | case 8: |
| 649 | hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0; |
| 650 | hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0; |
| 651 | case 6: |
| 652 | hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0; |
| 653 | hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0; |
| 654 | case 4: |
| 655 | hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0; |
| 656 | hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0; |
| 657 | case 2: |
| 658 | hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0; |
| 659 | hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0; |
| 660 | } |
| 661 | } |
| 662 | } else { |
| 663 | hw->x = (((buf[1] & 0x1f) << 8) | buf[2]); |
| 664 | hw->y = (((buf[4] & 0x1f) << 8) | buf[5]); |
| 665 | |
| 666 | hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F)); |
| 667 | hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1)); |
| 668 | |
| 669 | hw->left = (buf[0] & 0x01) ? 1 : 0; |
| 670 | hw->right = (buf[0] & 0x02) ? 1 : 0; |
| 671 | } |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 672 | |
Seth Forshee | 824efd3 | 2012-09-28 10:29:21 -0700 | [diff] [blame] | 673 | /* |
| 674 | * Convert wrap-around values to negative. (X|Y)_MAX_POSITIVE |
| 675 | * is used by some firmware to indicate a finger at the edge of |
| 676 | * the touchpad whose precise position cannot be determined, so |
| 677 | * convert these values to the maximum axis value. |
| 678 | */ |
Seth Forshee | c0394506 | 2012-07-24 23:54:11 -0700 | [diff] [blame] | 679 | if (hw->x > X_MAX_POSITIVE) |
| 680 | hw->x -= 1 << ABS_POS_BITS; |
Seth Forshee | 824efd3 | 2012-09-28 10:29:21 -0700 | [diff] [blame] | 681 | else if (hw->x == X_MAX_POSITIVE) |
| 682 | hw->x = XMAX; |
| 683 | |
Seth Forshee | c0394506 | 2012-07-24 23:54:11 -0700 | [diff] [blame] | 684 | if (hw->y > Y_MAX_POSITIVE) |
| 685 | hw->y -= 1 << ABS_POS_BITS; |
Seth Forshee | 824efd3 | 2012-09-28 10:29:21 -0700 | [diff] [blame] | 686 | else if (hw->y == Y_MAX_POSITIVE) |
| 687 | hw->y = YMAX; |
Seth Forshee | c0394506 | 2012-07-24 23:54:11 -0700 | [diff] [blame] | 688 | |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 689 | return 0; |
| 690 | } |
| 691 | |
Daniel Kurtz | bea9f0f | 2011-07-06 22:42:52 -0700 | [diff] [blame] | 692 | static void synaptics_report_semi_mt_slot(struct input_dev *dev, int slot, |
| 693 | bool active, int x, int y) |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 694 | { |
| 695 | input_mt_slot(dev, slot); |
| 696 | input_mt_report_slot_state(dev, MT_TOOL_FINGER, active); |
| 697 | if (active) { |
| 698 | input_report_abs(dev, ABS_MT_POSITION_X, x); |
Daniel Kurtz | 6de58dd | 2011-08-23 23:00:24 -0700 | [diff] [blame] | 699 | input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(y)); |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | |
| 703 | static void synaptics_report_semi_mt_data(struct input_dev *dev, |
| 704 | const struct synaptics_hw_state *a, |
| 705 | const struct synaptics_hw_state *b, |
| 706 | int num_fingers) |
| 707 | { |
| 708 | if (num_fingers >= 2) { |
Daniel Kurtz | bea9f0f | 2011-07-06 22:42:52 -0700 | [diff] [blame] | 709 | synaptics_report_semi_mt_slot(dev, 0, true, min(a->x, b->x), |
| 710 | min(a->y, b->y)); |
| 711 | synaptics_report_semi_mt_slot(dev, 1, true, max(a->x, b->x), |
| 712 | max(a->y, b->y)); |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 713 | } else if (num_fingers == 1) { |
Daniel Kurtz | bea9f0f | 2011-07-06 22:42:52 -0700 | [diff] [blame] | 714 | synaptics_report_semi_mt_slot(dev, 0, true, a->x, a->y); |
| 715 | synaptics_report_semi_mt_slot(dev, 1, false, 0, 0); |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 716 | } else { |
Daniel Kurtz | bea9f0f | 2011-07-06 22:42:52 -0700 | [diff] [blame] | 717 | synaptics_report_semi_mt_slot(dev, 0, false, 0, 0); |
| 718 | synaptics_report_semi_mt_slot(dev, 1, false, 0, 0); |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 719 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 722 | static void synaptics_report_buttons(struct psmouse *psmouse, |
| 723 | const struct synaptics_hw_state *hw) |
| 724 | { |
| 725 | struct input_dev *dev = psmouse->dev; |
| 726 | struct synaptics_data *priv = psmouse->private; |
| 727 | int i; |
| 728 | |
| 729 | input_report_key(dev, BTN_LEFT, hw->left); |
| 730 | input_report_key(dev, BTN_RIGHT, hw->right); |
| 731 | |
| 732 | if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) |
| 733 | input_report_key(dev, BTN_MIDDLE, hw->middle); |
| 734 | |
| 735 | if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) { |
| 736 | input_report_key(dev, BTN_FORWARD, hw->up); |
| 737 | input_report_key(dev, BTN_BACK, hw->down); |
| 738 | } |
| 739 | |
| 740 | for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++) |
| 741 | input_report_key(dev, BTN_0 + i, hw->ext_buttons & (1 << i)); |
| 742 | } |
| 743 | |
| 744 | static void synaptics_report_slot(struct input_dev *dev, int slot, |
| 745 | const struct synaptics_hw_state *hw) |
| 746 | { |
| 747 | input_mt_slot(dev, slot); |
| 748 | input_mt_report_slot_state(dev, MT_TOOL_FINGER, (hw != NULL)); |
| 749 | if (!hw) |
| 750 | return; |
| 751 | |
| 752 | input_report_abs(dev, ABS_MT_POSITION_X, hw->x); |
| 753 | input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(hw->y)); |
| 754 | input_report_abs(dev, ABS_MT_PRESSURE, hw->z); |
| 755 | } |
| 756 | |
| 757 | static void synaptics_report_mt_data(struct psmouse *psmouse, |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 758 | struct synaptics_mt_state *mt_state, |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 759 | const struct synaptics_hw_state *sgm) |
| 760 | { |
| 761 | struct input_dev *dev = psmouse->dev; |
| 762 | struct synaptics_data *priv = psmouse->private; |
| 763 | struct synaptics_hw_state *agm = &priv->agm; |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 764 | struct synaptics_mt_state *old = &priv->mt_state; |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 765 | |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 766 | switch (mt_state->count) { |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 767 | case 0: |
| 768 | synaptics_report_slot(dev, 0, NULL); |
| 769 | synaptics_report_slot(dev, 1, NULL); |
| 770 | break; |
| 771 | case 1: |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 772 | if (mt_state->sgm == -1) { |
| 773 | synaptics_report_slot(dev, 0, NULL); |
| 774 | synaptics_report_slot(dev, 1, NULL); |
| 775 | } else if (mt_state->sgm == 0) { |
| 776 | synaptics_report_slot(dev, 0, sgm); |
| 777 | synaptics_report_slot(dev, 1, NULL); |
| 778 | } else { |
| 779 | synaptics_report_slot(dev, 0, NULL); |
| 780 | synaptics_report_slot(dev, 1, sgm); |
| 781 | } |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 782 | break; |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 783 | default: |
| 784 | /* |
| 785 | * If the finger slot contained in SGM is valid, and either |
Daniel Kurtz | 48064bd | 2013-02-13 13:53:07 -0800 | [diff] [blame] | 786 | * hasn't changed, or is new, or the old SGM has now moved to |
| 787 | * AGM, then report SGM in MTB slot 0. |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 788 | * Otherwise, empty MTB slot 0. |
| 789 | */ |
| 790 | if (mt_state->sgm != -1 && |
Daniel Kurtz | 48064bd | 2013-02-13 13:53:07 -0800 | [diff] [blame] | 791 | (mt_state->sgm == old->sgm || |
| 792 | old->sgm == -1 || mt_state->agm == old->sgm)) |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 793 | synaptics_report_slot(dev, 0, sgm); |
| 794 | else |
| 795 | synaptics_report_slot(dev, 0, NULL); |
| 796 | |
| 797 | /* |
| 798 | * If the finger slot contained in AGM is valid, and either |
| 799 | * hasn't changed, or is new, then report AGM in MTB slot 1. |
| 800 | * Otherwise, empty MTB slot 1. |
Daniel Kurtz | 48064bd | 2013-02-13 13:53:07 -0800 | [diff] [blame] | 801 | * |
| 802 | * However, in the case where the AGM is new, make sure that |
| 803 | * that it is either the same as the old SGM, or there was no |
| 804 | * SGM. |
| 805 | * |
| 806 | * Otherwise, if the SGM was just 1, and the new AGM is 2, then |
| 807 | * the new AGM will keep the old SGM's tracking ID, which can |
| 808 | * cause apparent drumroll. This happens if in the following |
| 809 | * valid finger sequence: |
| 810 | * |
| 811 | * Action SGM AGM (MTB slot:Contact) |
| 812 | * 1. Touch contact 0 (0:0) |
| 813 | * 2. Touch contact 1 (0:0, 1:1) |
| 814 | * 3. Lift contact 0 (1:1) |
| 815 | * 4. Touch contacts 2,3 (0:2, 1:3) |
| 816 | * |
| 817 | * In step 4, contact 3, in AGM must not be given the same |
| 818 | * tracking ID as contact 1 had in step 3. To avoid this, |
| 819 | * the first agm with contact 3 is dropped and slot 1 is |
| 820 | * invalidated (tracking ID = -1). |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 821 | */ |
| 822 | if (mt_state->agm != -1 && |
Daniel Kurtz | 48064bd | 2013-02-13 13:53:07 -0800 | [diff] [blame] | 823 | (mt_state->agm == old->agm || |
| 824 | (old->agm == -1 && |
| 825 | (old->sgm == -1 || mt_state->agm == old->sgm)))) |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 826 | synaptics_report_slot(dev, 1, agm); |
| 827 | else |
| 828 | synaptics_report_slot(dev, 1, NULL); |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 829 | break; |
| 830 | } |
| 831 | |
| 832 | /* Don't use active slot count to generate BTN_TOOL events. */ |
| 833 | input_mt_report_pointer_emulation(dev, false); |
| 834 | |
| 835 | /* Send the number of fingers reported by touchpad itself. */ |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 836 | input_mt_report_finger_count(dev, mt_state->count); |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 837 | |
| 838 | synaptics_report_buttons(psmouse, sgm); |
| 839 | |
| 840 | input_sync(dev); |
| 841 | } |
| 842 | |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 843 | /* Handle case where mt_state->count = 0 */ |
| 844 | static void synaptics_image_sensor_0f(struct synaptics_data *priv, |
| 845 | struct synaptics_mt_state *mt_state) |
| 846 | { |
| 847 | synaptics_mt_state_set(mt_state, 0, -1, -1); |
| 848 | priv->mt_state_lost = false; |
| 849 | } |
| 850 | |
| 851 | /* Handle case where mt_state->count = 1 */ |
| 852 | static void synaptics_image_sensor_1f(struct synaptics_data *priv, |
| 853 | struct synaptics_mt_state *mt_state) |
| 854 | { |
| 855 | struct synaptics_hw_state *agm = &priv->agm; |
| 856 | struct synaptics_mt_state *old = &priv->mt_state; |
| 857 | |
| 858 | /* |
| 859 | * If the last AGM was (0,0,0), and there is only one finger left, |
| 860 | * then we absolutely know that SGM contains slot 0, and all other |
| 861 | * fingers have been removed. |
| 862 | */ |
| 863 | if (priv->agm_pending && agm->z == 0) { |
| 864 | synaptics_mt_state_set(mt_state, 1, 0, -1); |
| 865 | priv->mt_state_lost = false; |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | switch (old->count) { |
| 870 | case 0: |
| 871 | synaptics_mt_state_set(mt_state, 1, 0, -1); |
| 872 | break; |
| 873 | case 1: |
| 874 | /* |
| 875 | * If mt_state_lost, then the previous transition was 3->1, |
| 876 | * and SGM now contains either slot 0 or 1, but we don't know |
| 877 | * which. So, we just assume that the SGM now contains slot 1. |
| 878 | * |
| 879 | * If pending AGM and either: |
| 880 | * (a) the previous SGM slot contains slot 0, or |
| 881 | * (b) there was no SGM slot |
| 882 | * then, the SGM now contains slot 1 |
| 883 | * |
| 884 | * Case (a) happens with very rapid "drum roll" gestures, where |
| 885 | * slot 0 finger is lifted and a new slot 1 finger touches |
| 886 | * within one reporting interval. |
| 887 | * |
| 888 | * Case (b) happens if initially two or more fingers tap |
| 889 | * briefly, and all but one lift before the end of the first |
| 890 | * reporting interval. |
| 891 | * |
| 892 | * (In both these cases, slot 0 will becomes empty, so SGM |
| 893 | * contains slot 1 with the new finger) |
| 894 | * |
| 895 | * Else, if there was no previous SGM, it now contains slot 0. |
| 896 | * |
| 897 | * Otherwise, SGM still contains the same slot. |
| 898 | */ |
| 899 | if (priv->mt_state_lost || |
| 900 | (priv->agm_pending && old->sgm <= 0)) |
| 901 | synaptics_mt_state_set(mt_state, 1, 1, -1); |
| 902 | else if (old->sgm == -1) |
| 903 | synaptics_mt_state_set(mt_state, 1, 0, -1); |
| 904 | break; |
| 905 | case 2: |
| 906 | /* |
| 907 | * If mt_state_lost, we don't know which finger SGM contains. |
| 908 | * |
| 909 | * So, report 1 finger, but with both slots empty. |
| 910 | * We will use slot 1 on subsequent 1->1 |
| 911 | */ |
| 912 | if (priv->mt_state_lost) { |
| 913 | synaptics_mt_state_set(mt_state, 1, -1, -1); |
| 914 | break; |
| 915 | } |
| 916 | /* |
| 917 | * Since the last AGM was NOT (0,0,0), it was the finger in |
| 918 | * slot 0 that has been removed. |
| 919 | * So, SGM now contains previous AGM's slot, and AGM is now |
| 920 | * empty. |
| 921 | */ |
| 922 | synaptics_mt_state_set(mt_state, 1, old->agm, -1); |
| 923 | break; |
| 924 | case 3: |
| 925 | /* |
| 926 | * Since last AGM was not (0,0,0), we don't know which finger |
| 927 | * is left. |
| 928 | * |
| 929 | * So, report 1 finger, but with both slots empty. |
| 930 | * We will use slot 1 on subsequent 1->1 |
| 931 | */ |
| 932 | synaptics_mt_state_set(mt_state, 1, -1, -1); |
| 933 | priv->mt_state_lost = true; |
| 934 | break; |
Daniel Kurtz | 6b4b49f | 2011-08-23 23:02:56 -0700 | [diff] [blame] | 935 | case 4: |
| 936 | case 5: |
| 937 | /* mt_state was updated by AGM-CONTACT packet */ |
| 938 | break; |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | |
| 942 | /* Handle case where mt_state->count = 2 */ |
| 943 | static void synaptics_image_sensor_2f(struct synaptics_data *priv, |
| 944 | struct synaptics_mt_state *mt_state) |
| 945 | { |
| 946 | struct synaptics_mt_state *old = &priv->mt_state; |
| 947 | |
| 948 | switch (old->count) { |
| 949 | case 0: |
| 950 | synaptics_mt_state_set(mt_state, 2, 0, 1); |
| 951 | break; |
| 952 | case 1: |
| 953 | /* |
| 954 | * If previous SGM contained slot 1 or higher, SGM now contains |
| 955 | * slot 0 (the newly touching finger) and AGM contains SGM's |
| 956 | * previous slot. |
| 957 | * |
| 958 | * Otherwise, SGM still contains slot 0 and AGM now contains |
| 959 | * slot 1. |
| 960 | */ |
| 961 | if (old->sgm >= 1) |
| 962 | synaptics_mt_state_set(mt_state, 2, 0, old->sgm); |
| 963 | else |
| 964 | synaptics_mt_state_set(mt_state, 2, 0, 1); |
| 965 | break; |
| 966 | case 2: |
| 967 | /* |
| 968 | * If mt_state_lost, SGM now contains either finger 1 or 2, but |
| 969 | * we don't know which. |
| 970 | * So, we just assume that the SGM contains slot 0 and AGM 1. |
| 971 | */ |
| 972 | if (priv->mt_state_lost) |
| 973 | synaptics_mt_state_set(mt_state, 2, 0, 1); |
| 974 | /* |
| 975 | * Otherwise, use the same mt_state, since it either hasn't |
| 976 | * changed, or was updated by a recently received AGM-CONTACT |
| 977 | * packet. |
| 978 | */ |
| 979 | break; |
| 980 | case 3: |
| 981 | /* |
| 982 | * 3->2 transitions have two unsolvable problems: |
| 983 | * 1) no indication is given which finger was removed |
| 984 | * 2) no way to tell if agm packet was for finger 3 |
| 985 | * before 3->2, or finger 2 after 3->2. |
| 986 | * |
| 987 | * So, report 2 fingers, but empty all slots. |
| 988 | * We will guess slots [0,1] on subsequent 2->2. |
| 989 | */ |
| 990 | synaptics_mt_state_set(mt_state, 2, -1, -1); |
| 991 | priv->mt_state_lost = true; |
| 992 | break; |
Daniel Kurtz | 6b4b49f | 2011-08-23 23:02:56 -0700 | [diff] [blame] | 993 | case 4: |
| 994 | case 5: |
| 995 | /* mt_state was updated by AGM-CONTACT packet */ |
| 996 | break; |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | |
| 1000 | /* Handle case where mt_state->count = 3 */ |
| 1001 | static void synaptics_image_sensor_3f(struct synaptics_data *priv, |
| 1002 | struct synaptics_mt_state *mt_state) |
| 1003 | { |
| 1004 | struct synaptics_mt_state *old = &priv->mt_state; |
| 1005 | |
| 1006 | switch (old->count) { |
| 1007 | case 0: |
| 1008 | synaptics_mt_state_set(mt_state, 3, 0, 2); |
| 1009 | break; |
| 1010 | case 1: |
| 1011 | /* |
| 1012 | * If previous SGM contained slot 2 or higher, SGM now contains |
| 1013 | * slot 0 (one of the newly touching fingers) and AGM contains |
| 1014 | * SGM's previous slot. |
| 1015 | * |
| 1016 | * Otherwise, SGM now contains slot 0 and AGM contains slot 2. |
| 1017 | */ |
| 1018 | if (old->sgm >= 2) |
| 1019 | synaptics_mt_state_set(mt_state, 3, 0, old->sgm); |
| 1020 | else |
| 1021 | synaptics_mt_state_set(mt_state, 3, 0, 2); |
| 1022 | break; |
| 1023 | case 2: |
| 1024 | /* |
Daniel Kurtz | 6b4b49f | 2011-08-23 23:02:56 -0700 | [diff] [blame] | 1025 | * If the AGM previously contained slot 3 or higher, then the |
| 1026 | * newly touching finger is in the lowest available slot. |
| 1027 | * |
| 1028 | * If SGM was previously 1 or higher, then the new SGM is |
| 1029 | * now slot 0 (with a new finger), otherwise, the new finger |
| 1030 | * is now in a hidden slot between 0 and AGM's slot. |
| 1031 | * |
| 1032 | * In all such cases, the SGM now contains slot 0, and the AGM |
| 1033 | * continues to contain the same slot as before. |
| 1034 | */ |
| 1035 | if (old->agm >= 3) { |
| 1036 | synaptics_mt_state_set(mt_state, 3, 0, old->agm); |
| 1037 | break; |
| 1038 | } |
| 1039 | |
| 1040 | /* |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 1041 | * After some 3->1 and all 3->2 transitions, we lose track |
| 1042 | * of which slot is reported by SGM and AGM. |
| 1043 | * |
| 1044 | * For 2->3 in this state, report 3 fingers, but empty all |
| 1045 | * slots, and we will guess (0,2) on a subsequent 0->3. |
| 1046 | * |
| 1047 | * To userspace, the resulting transition will look like: |
| 1048 | * 2:[0,1] -> 3:[-1,-1] -> 3:[0,2] |
| 1049 | */ |
| 1050 | if (priv->mt_state_lost) { |
| 1051 | synaptics_mt_state_set(mt_state, 3, -1, -1); |
| 1052 | break; |
| 1053 | } |
| 1054 | |
| 1055 | /* |
| 1056 | * If the (SGM,AGM) really previously contained slots (0, 1), |
| 1057 | * then we cannot know what slot was just reported by the AGM, |
| 1058 | * because the 2->3 transition can occur either before or after |
| 1059 | * the AGM packet. Thus, this most recent AGM could contain |
| 1060 | * either the same old slot 1 or the new slot 2. |
| 1061 | * Subsequent AGMs will be reporting slot 2. |
| 1062 | * |
| 1063 | * To userspace, the resulting transition will look like: |
| 1064 | * 2:[0,1] -> 3:[0,-1] -> 3:[0,2] |
| 1065 | */ |
| 1066 | synaptics_mt_state_set(mt_state, 3, 0, -1); |
| 1067 | break; |
| 1068 | case 3: |
| 1069 | /* |
| 1070 | * If, for whatever reason, the previous agm was invalid, |
| 1071 | * Assume SGM now contains slot 0, AGM now contains slot 2. |
| 1072 | */ |
| 1073 | if (old->agm <= 2) |
| 1074 | synaptics_mt_state_set(mt_state, 3, 0, 2); |
| 1075 | /* |
| 1076 | * mt_state either hasn't changed, or was updated by a recently |
| 1077 | * received AGM-CONTACT packet. |
| 1078 | */ |
| 1079 | break; |
Daniel Kurtz | 6b4b49f | 2011-08-23 23:02:56 -0700 | [diff] [blame] | 1080 | |
| 1081 | case 4: |
| 1082 | case 5: |
| 1083 | /* mt_state was updated by AGM-CONTACT packet */ |
| 1084 | break; |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | |
Daniel Kurtz | 6b4b49f | 2011-08-23 23:02:56 -0700 | [diff] [blame] | 1088 | /* Handle case where mt_state->count = 4, or = 5 */ |
| 1089 | static void synaptics_image_sensor_45f(struct synaptics_data *priv, |
| 1090 | struct synaptics_mt_state *mt_state) |
| 1091 | { |
| 1092 | /* mt_state was updated correctly by AGM-CONTACT packet */ |
| 1093 | priv->mt_state_lost = false; |
| 1094 | } |
| 1095 | |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 1096 | static void synaptics_image_sensor_process(struct psmouse *psmouse, |
| 1097 | struct synaptics_hw_state *sgm) |
| 1098 | { |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 1099 | struct synaptics_data *priv = psmouse->private; |
| 1100 | struct synaptics_hw_state *agm = &priv->agm; |
| 1101 | struct synaptics_mt_state mt_state; |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 1102 | |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 1103 | /* Initialize using current mt_state (as updated by last agm) */ |
| 1104 | mt_state = agm->mt_state; |
| 1105 | |
| 1106 | /* |
| 1107 | * Update mt_state using the new finger count and current mt_state. |
| 1108 | */ |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 1109 | if (sgm->z == 0) |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 1110 | synaptics_image_sensor_0f(priv, &mt_state); |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 1111 | else if (sgm->w >= 4) |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 1112 | synaptics_image_sensor_1f(priv, &mt_state); |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 1113 | else if (sgm->w == 0) |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 1114 | synaptics_image_sensor_2f(priv, &mt_state); |
Daniel Kurtz | 6b4b49f | 2011-08-23 23:02:56 -0700 | [diff] [blame] | 1115 | else if (sgm->w == 1 && mt_state.count <= 3) |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 1116 | synaptics_image_sensor_3f(priv, &mt_state); |
Daniel Kurtz | 6b4b49f | 2011-08-23 23:02:56 -0700 | [diff] [blame] | 1117 | else |
| 1118 | synaptics_image_sensor_45f(priv, &mt_state); |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 1119 | |
| 1120 | /* Send resulting input events to user space */ |
Daniel Kurtz | 4dc772d | 2011-08-23 23:02:40 -0700 | [diff] [blame] | 1121 | synaptics_report_mt_data(psmouse, &mt_state, sgm); |
| 1122 | |
| 1123 | /* Store updated mt_state */ |
| 1124 | priv->mt_state = agm->mt_state = mt_state; |
| 1125 | priv->agm_pending = false; |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | /* |
| 1129 | * called for each full received packet from the touchpad |
| 1130 | */ |
| 1131 | static void synaptics_process_packet(struct psmouse *psmouse) |
| 1132 | { |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1133 | struct input_dev *dev = psmouse->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | struct synaptics_data *priv = psmouse->private; |
| 1135 | struct synaptics_hw_state hw; |
| 1136 | int num_fingers; |
| 1137 | int finger_width; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 1139 | if (synaptics_parse_hw_state(psmouse->packet, priv, &hw)) |
| 1140 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 1142 | if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) { |
| 1143 | synaptics_image_sensor_process(psmouse, &hw); |
| 1144 | return; |
| 1145 | } |
| 1146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | if (hw.scroll) { |
| 1148 | priv->scroll += hw.scroll; |
| 1149 | |
| 1150 | while (priv->scroll >= 4) { |
| 1151 | input_report_key(dev, BTN_BACK, !hw.down); |
| 1152 | input_sync(dev); |
| 1153 | input_report_key(dev, BTN_BACK, hw.down); |
| 1154 | input_sync(dev); |
| 1155 | priv->scroll -= 4; |
| 1156 | } |
| 1157 | while (priv->scroll <= -4) { |
| 1158 | input_report_key(dev, BTN_FORWARD, !hw.up); |
| 1159 | input_sync(dev); |
| 1160 | input_report_key(dev, BTN_FORWARD, hw.up); |
| 1161 | input_sync(dev); |
| 1162 | priv->scroll += 4; |
| 1163 | } |
| 1164 | return; |
| 1165 | } |
| 1166 | |
Henrik Rydberg | 4f56ce9 | 2010-12-18 15:42:30 +0100 | [diff] [blame] | 1167 | if (hw.z > 0 && hw.x > 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | num_fingers = 1; |
| 1169 | finger_width = 5; |
| 1170 | if (SYN_CAP_EXTENDED(priv->capabilities)) { |
| 1171 | switch (hw.w) { |
| 1172 | case 0 ... 1: |
| 1173 | if (SYN_CAP_MULTIFINGER(priv->capabilities)) |
| 1174 | num_fingers = hw.w + 2; |
| 1175 | break; |
| 1176 | case 2: |
| 1177 | if (SYN_MODEL_PEN(priv->model_id)) |
| 1178 | ; /* Nothing, treat a pen as a single finger */ |
| 1179 | break; |
| 1180 | case 4 ... 15: |
| 1181 | if (SYN_CAP_PALMDETECT(priv->capabilities)) |
| 1182 | finger_width = hw.w; |
| 1183 | break; |
| 1184 | } |
| 1185 | } |
| 1186 | } else { |
| 1187 | num_fingers = 0; |
| 1188 | finger_width = 0; |
| 1189 | } |
| 1190 | |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 1191 | if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) |
Daniel Kurtz | 7afdb84 | 2011-08-23 23:00:33 -0700 | [diff] [blame] | 1192 | synaptics_report_semi_mt_data(dev, &hw, &priv->agm, |
| 1193 | num_fingers); |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 1194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | /* Post events |
| 1196 | * BTN_TOUCH has to be first as mousedev relies on it when doing |
| 1197 | * absolute -> relative conversion |
| 1198 | */ |
| 1199 | if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1); |
| 1200 | if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0); |
| 1201 | |
Henrik Rydberg | 4f56ce9 | 2010-12-18 15:42:30 +0100 | [diff] [blame] | 1202 | if (num_fingers > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | input_report_abs(dev, ABS_X, hw.x); |
Daniel Kurtz | 6de58dd | 2011-08-23 23:00:24 -0700 | [diff] [blame] | 1204 | input_report_abs(dev, ABS_Y, synaptics_invert_y(hw.y)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | } |
| 1206 | input_report_abs(dev, ABS_PRESSURE, hw.z); |
| 1207 | |
Chris Bagwell | 2a8e771 | 2010-07-19 09:06:15 -0700 | [diff] [blame] | 1208 | if (SYN_CAP_PALMDETECT(priv->capabilities)) |
| 1209 | input_report_abs(dev, ABS_TOOL_WIDTH, finger_width); |
| 1210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1); |
Peter Hutterer | e42b664 | 2008-11-20 15:24:42 -0500 | [diff] [blame] | 1212 | if (SYN_CAP_MULTIFINGER(priv->capabilities)) { |
| 1213 | input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2); |
| 1214 | input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3); |
| 1215 | } |
| 1216 | |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 1217 | synaptics_report_buttons(psmouse, &hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | |
| 1219 | input_sync(dev); |
| 1220 | } |
| 1221 | |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1222 | static int synaptics_validate_byte(struct psmouse *psmouse, |
| 1223 | int idx, unsigned char pkt_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | { |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 1225 | static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 }; |
| 1226 | static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 }; |
| 1227 | static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 }; |
| 1228 | static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 }; |
| 1229 | static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 }; |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1230 | const char *packet = psmouse->packet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | |
| 1232 | if (idx < 0 || idx > 4) |
| 1233 | return 0; |
| 1234 | |
| 1235 | switch (pkt_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 1237 | case SYN_NEWABS: |
| 1238 | case SYN_NEWABS_RELAXED: |
| 1239 | return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 1241 | case SYN_NEWABS_STRICT: |
| 1242 | return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 1244 | case SYN_OLDABS: |
| 1245 | return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx]; |
| 1246 | |
| 1247 | default: |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1248 | psmouse_err(psmouse, "unknown packet type %d\n", pkt_type); |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 1249 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse) |
| 1254 | { |
| 1255 | int i; |
| 1256 | |
| 1257 | for (i = 0; i < 5; i++) |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1258 | if (!synaptics_validate_byte(psmouse, i, SYN_NEWABS_STRICT)) { |
| 1259 | psmouse_info(psmouse, "using relaxed packet validation\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | return SYN_NEWABS_RELAXED; |
| 1261 | } |
| 1262 | |
| 1263 | return SYN_NEWABS_STRICT; |
| 1264 | } |
| 1265 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1266 | static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | struct synaptics_data *priv = psmouse->private; |
| 1269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | if (psmouse->pktcnt >= 6) { /* Full packet received */ |
| 1271 | if (unlikely(priv->pkt_type == SYN_NEWABS)) |
| 1272 | priv->pkt_type = synaptics_detect_pkt_type(psmouse); |
| 1273 | |
Dmitry Torokhov | a8b3c0f | 2010-10-04 21:46:10 -0700 | [diff] [blame] | 1274 | if (SYN_CAP_PASS_THROUGH(priv->capabilities) && |
| 1275 | synaptics_is_pt_packet(psmouse->packet)) { |
| 1276 | if (priv->pt_port) |
| 1277 | synaptics_pass_pt_packet(priv->pt_port, psmouse->packet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | } else |
| 1279 | synaptics_process_packet(psmouse); |
| 1280 | |
| 1281 | return PSMOUSE_FULL_PACKET; |
| 1282 | } |
| 1283 | |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1284 | return synaptics_validate_byte(psmouse, psmouse->pktcnt - 1, priv->pkt_type) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA; |
| 1286 | } |
| 1287 | |
| 1288 | /***************************************************************************** |
| 1289 | * Driver initialization/cleanup functions |
| 1290 | ****************************************************************************/ |
Daniel Kurtz | 8561547 | 2011-08-23 23:00:41 -0700 | [diff] [blame] | 1291 | static void set_abs_position_params(struct input_dev *dev, |
| 1292 | struct synaptics_data *priv, int x_code, |
| 1293 | int y_code) |
| 1294 | { |
| 1295 | int x_min = priv->x_min ?: XMIN_NOMINAL; |
| 1296 | int x_max = priv->x_max ?: XMAX_NOMINAL; |
| 1297 | int y_min = priv->y_min ?: YMIN_NOMINAL; |
| 1298 | int y_max = priv->y_max ?: YMAX_NOMINAL; |
| 1299 | int fuzz = SYN_CAP_REDUCED_FILTERING(priv->ext_cap_0c) ? |
| 1300 | SYN_REDUCED_FILTER_FUZZ : 0; |
| 1301 | |
| 1302 | input_set_abs_params(dev, x_code, x_min, x_max, fuzz, 0); |
| 1303 | input_set_abs_params(dev, y_code, y_min, y_max, fuzz, 0); |
| 1304 | input_abs_set_res(dev, x_code, priv->x_res); |
| 1305 | input_abs_set_res(dev, y_code, priv->y_res); |
| 1306 | } |
| 1307 | |
Hans de Goede | 43e1988 | 2014-04-19 22:26:41 -0700 | [diff] [blame] | 1308 | static void set_input_params(struct psmouse *psmouse, |
| 1309 | struct synaptics_data *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | { |
Hans de Goede | 43e1988 | 2014-04-19 22:26:41 -0700 | [diff] [blame] | 1311 | struct input_dev *dev = psmouse->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | int i; |
| 1313 | |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1314 | /* Things that apply to both modes */ |
Henrik Rydberg | c14890a | 2010-12-16 09:52:23 +0100 | [diff] [blame] | 1315 | __set_bit(INPUT_PROP_POINTER, dev->propbit); |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1316 | __set_bit(EV_KEY, dev->evbit); |
| 1317 | __set_bit(BTN_LEFT, dev->keybit); |
| 1318 | __set_bit(BTN_RIGHT, dev->keybit); |
Henrik Rydberg | c14890a | 2010-12-16 09:52:23 +0100 | [diff] [blame] | 1319 | |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1320 | if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) |
| 1321 | __set_bit(BTN_MIDDLE, dev->keybit); |
| 1322 | |
| 1323 | if (!priv->absolute_mode) { |
| 1324 | /* Relative mode */ |
| 1325 | __set_bit(EV_REL, dev->evbit); |
| 1326 | __set_bit(REL_X, dev->relbit); |
| 1327 | __set_bit(REL_Y, dev->relbit); |
| 1328 | return; |
| 1329 | } |
| 1330 | |
| 1331 | /* Absolute mode */ |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1332 | __set_bit(EV_ABS, dev->evbit); |
Daniel Kurtz | 8561547 | 2011-08-23 23:00:41 -0700 | [diff] [blame] | 1333 | set_abs_position_params(dev, priv, ABS_X, ABS_Y); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0); |
Chris Bagwell | 2a8e771 | 2010-07-19 09:06:15 -0700 | [diff] [blame] | 1335 | |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 1336 | if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) { |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 1337 | set_abs_position_params(dev, priv, ABS_MT_POSITION_X, |
| 1338 | ABS_MT_POSITION_Y); |
| 1339 | /* Image sensors can report per-contact pressure */ |
| 1340 | input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0); |
Henrik Rydberg | 0b85bf7 | 2013-02-15 17:04:03 -0800 | [diff] [blame] | 1341 | input_mt_init_slots(dev, 2, INPUT_MT_POINTER); |
Daniel Kurtz | 6b4b49f | 2011-08-23 23:02:56 -0700 | [diff] [blame] | 1342 | |
| 1343 | /* Image sensors can signal 4 and 5 finger clicks */ |
| 1344 | __set_bit(BTN_TOOL_QUADTAP, dev->keybit); |
| 1345 | __set_bit(BTN_TOOL_QUINTTAP, dev->keybit); |
Daniel Kurtz | 3cdfee9 | 2011-08-23 23:02:25 -0700 | [diff] [blame] | 1346 | } else if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) { |
| 1347 | /* Non-image sensors with AGM use semi-mt */ |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 1348 | __set_bit(INPUT_PROP_SEMI_MT, dev->propbit); |
Henrik Rydberg | b4adbbe | 2012-08-11 22:07:55 +0200 | [diff] [blame] | 1349 | input_mt_init_slots(dev, 2, 0); |
Daniel Kurtz | 8561547 | 2011-08-23 23:00:41 -0700 | [diff] [blame] | 1350 | set_abs_position_params(dev, priv, ABS_MT_POSITION_X, |
| 1351 | ABS_MT_POSITION_Y); |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 1352 | } |
| 1353 | |
Chris Bagwell | 2a8e771 | 2010-07-19 09:06:15 -0700 | [diff] [blame] | 1354 | if (SYN_CAP_PALMDETECT(priv->capabilities)) |
Chris Bagwell | 58fb021 | 2010-07-19 09:06:15 -0700 | [diff] [blame] | 1355 | input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1357 | __set_bit(BTN_TOUCH, dev->keybit); |
| 1358 | __set_bit(BTN_TOOL_FINGER, dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | |
Peter Hutterer | e42b664 | 2008-11-20 15:24:42 -0500 | [diff] [blame] | 1360 | if (SYN_CAP_MULTIFINGER(priv->capabilities)) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1361 | __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit); |
| 1362 | __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit); |
Peter Hutterer | e42b664 | 2008-11-20 15:24:42 -0500 | [diff] [blame] | 1363 | } |
| 1364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | if (SYN_CAP_FOUR_BUTTON(priv->capabilities) || |
| 1366 | SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1367 | __set_bit(BTN_FORWARD, dev->keybit); |
| 1368 | __set_bit(BTN_BACK, dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1372 | __set_bit(BTN_0 + i, dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1374 | __clear_bit(EV_REL, dev->evbit); |
| 1375 | __clear_bit(REL_X, dev->relbit); |
| 1376 | __clear_bit(REL_Y, dev->relbit); |
Tero Saarni | ec20a02 | 2009-06-10 23:27:24 -0700 | [diff] [blame] | 1377 | |
Takashi Iwai | 5f57d67 | 2010-04-19 10:37:21 -0700 | [diff] [blame] | 1378 | if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) { |
Henrik Rydberg | c14890a | 2010-12-16 09:52:23 +0100 | [diff] [blame] | 1379 | __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit); |
Hans de Goede | e2f6110 | 2014-05-19 22:53:23 -0700 | [diff] [blame^] | 1380 | if (matches_pnp_id(psmouse, topbuttonpad_pnp_ids)) |
| 1381 | __set_bit(INPUT_PROP_TOPBUTTONPAD, dev->propbit); |
Takashi Iwai | 5f57d67 | 2010-04-19 10:37:21 -0700 | [diff] [blame] | 1382 | /* Clickpads report only left button */ |
| 1383 | __clear_bit(BTN_RIGHT, dev->keybit); |
| 1384 | __clear_bit(BTN_MIDDLE, dev->keybit); |
| 1385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1388 | static ssize_t synaptics_show_disable_gesture(struct psmouse *psmouse, |
| 1389 | void *data, char *buf) |
| 1390 | { |
| 1391 | struct synaptics_data *priv = psmouse->private; |
| 1392 | |
| 1393 | return sprintf(buf, "%c\n", priv->disable_gesture ? '1' : '0'); |
| 1394 | } |
| 1395 | |
| 1396 | static ssize_t synaptics_set_disable_gesture(struct psmouse *psmouse, |
| 1397 | void *data, const char *buf, |
| 1398 | size_t len) |
| 1399 | { |
| 1400 | struct synaptics_data *priv = psmouse->private; |
| 1401 | unsigned int value; |
| 1402 | int err; |
| 1403 | |
| 1404 | err = kstrtouint(buf, 10, &value); |
| 1405 | if (err) |
| 1406 | return err; |
| 1407 | |
| 1408 | if (value > 1) |
| 1409 | return -EINVAL; |
| 1410 | |
| 1411 | if (value == priv->disable_gesture) |
| 1412 | return len; |
| 1413 | |
| 1414 | priv->disable_gesture = value; |
| 1415 | if (value) |
| 1416 | priv->mode |= SYN_BIT_DISABLE_GESTURE; |
| 1417 | else |
| 1418 | priv->mode &= ~SYN_BIT_DISABLE_GESTURE; |
| 1419 | |
| 1420 | if (synaptics_mode_cmd(psmouse, priv->mode)) |
| 1421 | return -EIO; |
| 1422 | |
| 1423 | return len; |
| 1424 | } |
| 1425 | |
| 1426 | PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL, |
| 1427 | synaptics_show_disable_gesture, |
| 1428 | synaptics_set_disable_gesture); |
| 1429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | static void synaptics_disconnect(struct psmouse *psmouse) |
| 1431 | { |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1432 | struct synaptics_data *priv = psmouse->private; |
| 1433 | |
| 1434 | if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(priv->identity)) |
| 1435 | device_remove_file(&psmouse->ps2dev.serio->dev, |
| 1436 | &psmouse_attr_disable_gesture.dattr); |
| 1437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | synaptics_reset(psmouse); |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1439 | kfree(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | psmouse->private = NULL; |
| 1441 | } |
| 1442 | |
| 1443 | static int synaptics_reconnect(struct psmouse *psmouse) |
| 1444 | { |
| 1445 | struct synaptics_data *priv = psmouse->private; |
| 1446 | struct synaptics_data old_priv = *priv; |
Eric Miao | eeb0655 | 2013-06-04 09:30:55 -0700 | [diff] [blame] | 1447 | unsigned char param[2]; |
Alexandre Peixoto Ferreira | c63fe0a | 2011-01-28 22:05:14 -0800 | [diff] [blame] | 1448 | int retry = 0; |
| 1449 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | |
Alexandre Peixoto Ferreira | c63fe0a | 2011-01-28 22:05:14 -0800 | [diff] [blame] | 1451 | do { |
| 1452 | psmouse_reset(psmouse); |
Dmitry Torokhov | 8521478 | 2011-12-12 00:05:53 -0800 | [diff] [blame] | 1453 | if (retry) { |
| 1454 | /* |
| 1455 | * On some boxes, right after resuming, the touchpad |
| 1456 | * needs some time to finish initializing (I assume |
| 1457 | * it needs time to calibrate) and start responding |
| 1458 | * to Synaptics-specific queries, so let's wait a |
| 1459 | * bit. |
| 1460 | */ |
| 1461 | ssleep(1); |
| 1462 | } |
Eric Miao | eeb0655 | 2013-06-04 09:30:55 -0700 | [diff] [blame] | 1463 | ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETID); |
Alexandre Peixoto Ferreira | c63fe0a | 2011-01-28 22:05:14 -0800 | [diff] [blame] | 1464 | error = synaptics_detect(psmouse, 0); |
| 1465 | } while (error && ++retry < 3); |
Andy Whitcroft | 4d36845 | 2009-02-28 12:51:01 -0800 | [diff] [blame] | 1466 | |
Alexandre Peixoto Ferreira | c63fe0a | 2011-01-28 22:05:14 -0800 | [diff] [blame] | 1467 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | return -1; |
| 1469 | |
Alexandre Peixoto Ferreira | c63fe0a | 2011-01-28 22:05:14 -0800 | [diff] [blame] | 1470 | if (retry > 1) |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1471 | psmouse_dbg(psmouse, "reconnected after %d tries\n", retry); |
Alexandre Peixoto Ferreira | c63fe0a | 2011-01-28 22:05:14 -0800 | [diff] [blame] | 1472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | if (synaptics_query_hardware(psmouse)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1474 | psmouse_err(psmouse, "Unable to query device.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | return -1; |
| 1476 | } |
| 1477 | |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1478 | if (synaptics_set_mode(psmouse)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1479 | psmouse_err(psmouse, "Unable to initialize device.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | return -1; |
| 1481 | } |
| 1482 | |
Alexandre Peixoto Ferreira | baddf58 | 2011-01-28 22:05:14 -0800 | [diff] [blame] | 1483 | if (old_priv.identity != priv->identity || |
| 1484 | old_priv.model_id != priv->model_id || |
| 1485 | old_priv.capabilities != priv->capabilities || |
| 1486 | old_priv.ext_cap != priv->ext_cap) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1487 | psmouse_err(psmouse, |
| 1488 | "hardware appears to be different: id(%ld-%ld), model(%ld-%ld), caps(%lx-%lx), ext(%lx-%lx).\n", |
| 1489 | old_priv.identity, priv->identity, |
| 1490 | old_priv.model_id, priv->model_id, |
| 1491 | old_priv.capabilities, priv->capabilities, |
| 1492 | old_priv.ext_cap, priv->ext_cap); |
Alexandre Peixoto Ferreira | baddf58 | 2011-01-28 22:05:14 -0800 | [diff] [blame] | 1493 | return -1; |
| 1494 | } |
| 1495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | return 0; |
| 1497 | } |
| 1498 | |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 1499 | static bool impaired_toshiba_kbc; |
| 1500 | |
Sachin Kamat | c963156 | 2013-08-12 11:05:58 -0700 | [diff] [blame] | 1501 | static const struct dmi_system_id toshiba_dmi_table[] __initconst = { |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 1502 | #if defined(CONFIG_DMI) && defined(CONFIG_X86) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | { |
Dmitry Torokhov | 9961e25 | 2009-12-04 10:24:20 -0800 | [diff] [blame] | 1504 | /* Toshiba Satellite */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | .matches = { |
| 1506 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
Richard Thrippleton | 53a2670 | 2006-04-02 00:10:18 -0500 | [diff] [blame] | 1507 | DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | }, |
| 1509 | }, |
Simon Horman | 9ba5eaa | 2005-07-11 01:07:20 -0500 | [diff] [blame] | 1510 | { |
Dmitry Torokhov | 9961e25 | 2009-12-04 10:24:20 -0800 | [diff] [blame] | 1511 | /* Toshiba Dynabook */ |
Simon Horman | 9ba5eaa | 2005-07-11 01:07:20 -0500 | [diff] [blame] | 1512 | .matches = { |
| 1513 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
Richard Thrippleton | 53a2670 | 2006-04-02 00:10:18 -0500 | [diff] [blame] | 1514 | DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"), |
| 1515 | }, |
| 1516 | }, |
| 1517 | { |
Dmitry Torokhov | 9961e25 | 2009-12-04 10:24:20 -0800 | [diff] [blame] | 1518 | /* Toshiba Portege M300 */ |
Richard Thrippleton | 53a2670 | 2006-04-02 00:10:18 -0500 | [diff] [blame] | 1519 | .matches = { |
| 1520 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
| 1521 | DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"), |
Simon Horman | 9ba5eaa | 2005-07-11 01:07:20 -0500 | [diff] [blame] | 1522 | }, |
Dmitry Torokhov | 5f5eeff | 2009-10-12 21:35:00 -0700 | [diff] [blame] | 1523 | |
| 1524 | }, |
| 1525 | { |
Dmitry Torokhov | 9961e25 | 2009-12-04 10:24:20 -0800 | [diff] [blame] | 1526 | /* Toshiba Portege M300 */ |
Dmitry Torokhov | 5f5eeff | 2009-10-12 21:35:00 -0700 | [diff] [blame] | 1527 | .matches = { |
| 1528 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
| 1529 | DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"), |
| 1530 | DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"), |
| 1531 | }, |
| 1532 | |
Simon Horman | 9ba5eaa | 2005-07-11 01:07:20 -0500 | [diff] [blame] | 1533 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | #endif |
Jan Beulich | 7087486 | 2011-03-31 00:01:58 -0700 | [diff] [blame] | 1535 | { } |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 1536 | }; |
| 1537 | |
Andres Salomon | ef8313b | 2010-12-23 01:19:38 -0800 | [diff] [blame] | 1538 | static bool broken_olpc_ec; |
| 1539 | |
Sachin Kamat | c963156 | 2013-08-12 11:05:58 -0700 | [diff] [blame] | 1540 | static const struct dmi_system_id olpc_dmi_table[] __initconst = { |
Andres Salomon | ef8313b | 2010-12-23 01:19:38 -0800 | [diff] [blame] | 1541 | #if defined(CONFIG_DMI) && defined(CONFIG_OLPC) |
| 1542 | { |
| 1543 | /* OLPC XO-1 or XO-1.5 */ |
| 1544 | .matches = { |
| 1545 | DMI_MATCH(DMI_SYS_VENDOR, "OLPC"), |
| 1546 | DMI_MATCH(DMI_PRODUCT_NAME, "XO"), |
| 1547 | }, |
| 1548 | }, |
Andres Salomon | ef8313b | 2010-12-23 01:19:38 -0800 | [diff] [blame] | 1549 | #endif |
Jan Beulich | 7087486 | 2011-03-31 00:01:58 -0700 | [diff] [blame] | 1550 | { } |
Andres Salomon | ef8313b | 2010-12-23 01:19:38 -0800 | [diff] [blame] | 1551 | }; |
| 1552 | |
Benjamin Tissoires | 421e08c | 2014-03-28 00:43:00 -0700 | [diff] [blame] | 1553 | static const struct dmi_system_id min_max_dmi_table[] __initconst = { |
| 1554 | #if defined(CONFIG_DMI) |
| 1555 | { |
| 1556 | /* Lenovo ThinkPad Helix */ |
| 1557 | .matches = { |
| 1558 | DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), |
| 1559 | DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad Helix"), |
| 1560 | }, |
| 1561 | .driver_data = (int []){1024, 5052, 2258, 4832}, |
| 1562 | }, |
| 1563 | { |
Hans de Goede | 8a0435d | 2014-03-28 01:01:38 -0700 | [diff] [blame] | 1564 | /* Lenovo ThinkPad X240 */ |
| 1565 | .matches = { |
| 1566 | DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), |
| 1567 | DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X240"), |
| 1568 | }, |
| 1569 | .driver_data = (int []){1232, 5710, 1156, 4696}, |
| 1570 | }, |
| 1571 | { |
Hans de Goede | 27a3885 | 2014-04-23 13:02:35 -0700 | [diff] [blame] | 1572 | /* Lenovo ThinkPad Edge E431 */ |
| 1573 | .matches = { |
| 1574 | DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), |
| 1575 | DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad Edge E431"), |
| 1576 | }, |
| 1577 | .driver_data = (int []){1024, 5022, 2508, 4832}, |
| 1578 | }, |
| 1579 | { |
Hans de Goede | 46a2986 | 2014-04-19 22:31:18 -0700 | [diff] [blame] | 1580 | /* Lenovo ThinkPad T431s */ |
| 1581 | .matches = { |
| 1582 | DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), |
| 1583 | DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T431"), |
| 1584 | }, |
| 1585 | .driver_data = (int []){1024, 5112, 2024, 4832}, |
| 1586 | }, |
| 1587 | { |
Benjamin Tissoires | 421e08c | 2014-03-28 00:43:00 -0700 | [diff] [blame] | 1588 | /* Lenovo ThinkPad T440s */ |
| 1589 | .matches = { |
| 1590 | DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), |
| 1591 | DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T440"), |
| 1592 | }, |
| 1593 | .driver_data = (int []){1024, 5112, 2024, 4832}, |
| 1594 | }, |
| 1595 | { |
Hans de Goede | 46a2986 | 2014-04-19 22:31:18 -0700 | [diff] [blame] | 1596 | /* Lenovo ThinkPad L440 */ |
| 1597 | .matches = { |
| 1598 | DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), |
| 1599 | DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad L440"), |
| 1600 | }, |
| 1601 | .driver_data = (int []){1024, 5112, 2024, 4832}, |
| 1602 | }, |
| 1603 | { |
Benjamin Tissoires | 421e08c | 2014-03-28 00:43:00 -0700 | [diff] [blame] | 1604 | /* Lenovo ThinkPad T540p */ |
| 1605 | .matches = { |
| 1606 | DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), |
| 1607 | DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T540"), |
| 1608 | }, |
Hans de Goede | 6d396ed | 2014-05-19 22:52:30 -0700 | [diff] [blame] | 1609 | .driver_data = (int []){1024, 5112, 2024, 4832}, |
Benjamin Tissoires | 421e08c | 2014-03-28 00:43:00 -0700 | [diff] [blame] | 1610 | }, |
Hans de Goede | 46a2986 | 2014-04-19 22:31:18 -0700 | [diff] [blame] | 1611 | { |
| 1612 | /* Lenovo ThinkPad L540 */ |
| 1613 | .matches = { |
| 1614 | DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), |
| 1615 | DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad L540"), |
| 1616 | }, |
| 1617 | .driver_data = (int []){1024, 5112, 2024, 4832}, |
| 1618 | }, |
| 1619 | { |
Hans de Goede | 0b5fe73 | 2014-05-14 11:10:40 -0700 | [diff] [blame] | 1620 | /* Lenovo ThinkPad W540 */ |
| 1621 | .matches = { |
| 1622 | DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), |
| 1623 | DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad W540"), |
| 1624 | }, |
| 1625 | .driver_data = (int []){1024, 5112, 2024, 4832}, |
| 1626 | }, |
| 1627 | { |
Hans de Goede | 46a2986 | 2014-04-19 22:31:18 -0700 | [diff] [blame] | 1628 | /* Lenovo Yoga S1 */ |
| 1629 | .matches = { |
| 1630 | DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), |
| 1631 | DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, |
| 1632 | "ThinkPad S1 Yoga"), |
| 1633 | }, |
| 1634 | .driver_data = (int []){1232, 5710, 1156, 4696}, |
| 1635 | }, |
| 1636 | { |
| 1637 | /* Lenovo ThinkPad X1 Carbon Haswell (3rd generation) */ |
| 1638 | .matches = { |
| 1639 | DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), |
| 1640 | DMI_MATCH(DMI_PRODUCT_VERSION, |
| 1641 | "ThinkPad X1 Carbon 2nd"), |
| 1642 | }, |
| 1643 | .driver_data = (int []){1024, 5112, 2024, 4832}, |
| 1644 | }, |
Benjamin Tissoires | 421e08c | 2014-03-28 00:43:00 -0700 | [diff] [blame] | 1645 | #endif |
| 1646 | { } |
| 1647 | }; |
| 1648 | |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 1649 | void __init synaptics_module_init(void) |
| 1650 | { |
Benjamin Tissoires | 421e08c | 2014-03-28 00:43:00 -0700 | [diff] [blame] | 1651 | const struct dmi_system_id *min_max_dmi; |
| 1652 | |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 1653 | impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table); |
Andres Salomon | ef8313b | 2010-12-23 01:19:38 -0800 | [diff] [blame] | 1654 | broken_olpc_ec = dmi_check_system(olpc_dmi_table); |
Benjamin Tissoires | 421e08c | 2014-03-28 00:43:00 -0700 | [diff] [blame] | 1655 | |
| 1656 | min_max_dmi = dmi_first_match(min_max_dmi_table); |
| 1657 | if (min_max_dmi) |
| 1658 | quirk_min_max = min_max_dmi->driver_data; |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 1659 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1661 | static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | { |
| 1663 | struct synaptics_data *priv; |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1664 | int err = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | |
Andres Salomon | ef8313b | 2010-12-23 01:19:38 -0800 | [diff] [blame] | 1666 | /* |
Daniel Drake | 83551c0 | 2011-11-11 16:05:04 -0800 | [diff] [blame] | 1667 | * The OLPC XO has issues with Synaptics' absolute mode; the constant |
| 1668 | * packet spew overloads the EC such that key presses on the keyboard |
| 1669 | * are missed. Given that, don't even attempt to use Absolute mode. |
| 1670 | * Relative mode seems to work just fine. |
Andres Salomon | ef8313b | 2010-12-23 01:19:38 -0800 | [diff] [blame] | 1671 | */ |
Daniel Drake | 83551c0 | 2011-11-11 16:05:04 -0800 | [diff] [blame] | 1672 | if (absolute_mode && broken_olpc_ec) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1673 | psmouse_info(psmouse, |
| 1674 | "OLPC XO detected, not enabling Synaptics protocol.\n"); |
Andres Salomon | ef8313b | 2010-12-23 01:19:38 -0800 | [diff] [blame] | 1675 | return -ENODEV; |
| 1676 | } |
| 1677 | |
Eric Sesterhenn | b39787a | 2006-03-14 00:09:16 -0500 | [diff] [blame] | 1678 | psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | if (!priv) |
Davidlohr Bueso | 6792cbb | 2010-09-29 18:53:35 -0700 | [diff] [blame] | 1680 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | |
Andy Whitcroft | 4d36845 | 2009-02-28 12:51:01 -0800 | [diff] [blame] | 1682 | psmouse_reset(psmouse); |
| 1683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | if (synaptics_query_hardware(psmouse)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1685 | psmouse_err(psmouse, "Unable to query device.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | goto init_fail; |
| 1687 | } |
| 1688 | |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1689 | priv->absolute_mode = absolute_mode; |
| 1690 | if (SYN_ID_DISGEST_SUPPORTED(priv->identity)) |
| 1691 | priv->disable_gesture = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1693 | if (synaptics_set_mode(psmouse)) { |
| 1694 | psmouse_err(psmouse, "Unable to initialize device.\n"); |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 1695 | goto init_fail; |
| 1696 | } |
| 1697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS; |
| 1699 | |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1700 | psmouse_info(psmouse, |
Daniel Kurtz | c6bd9d4 | 2012-07-07 18:08:51 -0700 | [diff] [blame] | 1701 | "Touchpad model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx, board id: %lu, fw id: %lu\n", |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1702 | SYN_ID_MODEL(priv->identity), |
| 1703 | SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity), |
| 1704 | priv->model_id, |
Daniel Kurtz | c6bd9d4 | 2012-07-07 18:08:51 -0700 | [diff] [blame] | 1705 | priv->capabilities, priv->ext_cap, priv->ext_cap_0c, |
| 1706 | priv->board_id, priv->firmware_id); |
Dmitry Torokhov | 409b750 | 2005-05-28 02:12:18 -0500 | [diff] [blame] | 1707 | |
Hans de Goede | 43e1988 | 2014-04-19 22:26:41 -0700 | [diff] [blame] | 1708 | set_input_params(psmouse, priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | |
Dmitry Torokhov | 887cc12 | 2007-04-12 01:30:41 -0400 | [diff] [blame] | 1710 | /* |
| 1711 | * Encode touchpad model so that it can be used to set |
| 1712 | * input device->id.version and be visible to userspace. |
| 1713 | * Because version is __u16 we have to drop something. |
| 1714 | * Hardware info bits seem to be good candidates as they |
| 1715 | * are documented to be for Synaptics corp. internal use. |
| 1716 | */ |
| 1717 | psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) | |
| 1718 | (priv->model_id & 0x000000ff); |
| 1719 | |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1720 | if (absolute_mode) { |
| 1721 | psmouse->protocol_handler = synaptics_process_byte; |
| 1722 | psmouse->pktsize = 6; |
| 1723 | } else { |
| 1724 | /* Relative mode follows standard PS/2 mouse protocol */ |
| 1725 | psmouse->protocol_handler = psmouse_process_byte; |
| 1726 | psmouse->pktsize = 3; |
| 1727 | } |
| 1728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | psmouse->set_rate = synaptics_set_rate; |
| 1730 | psmouse->disconnect = synaptics_disconnect; |
| 1731 | psmouse->reconnect = synaptics_reconnect; |
Dmitry Torokhov | a1cec06 | 2007-02-18 01:40:24 -0500 | [diff] [blame] | 1732 | psmouse->cleanup = synaptics_reset; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1733 | /* Synaptics can usually stay in sync without extra help */ |
| 1734 | psmouse->resync_time = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | |
| 1736 | if (SYN_CAP_PASS_THROUGH(priv->capabilities)) |
| 1737 | synaptics_pt_create(psmouse); |
| 1738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | /* |
| 1740 | * Toshiba's KBC seems to have trouble handling data from |
Andres Salomon | 7ee9916 | 2010-12-23 01:18:28 -0800 | [diff] [blame] | 1741 | * Synaptics at full rate. Switch to a lower rate (roughly |
| 1742 | * the same rate as a standard PS/2 mouse). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | */ |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 1744 | if (psmouse->rate >= 80 && impaired_toshiba_kbc) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1745 | psmouse_info(psmouse, |
| 1746 | "Toshiba %s detected, limiting rate to 40pps.\n", |
| 1747 | dmi_get_system_info(DMI_PRODUCT_NAME)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | psmouse->rate = 40; |
| 1749 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1751 | if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(priv->identity)) { |
| 1752 | err = device_create_file(&psmouse->ps2dev.serio->dev, |
| 1753 | &psmouse_attr_disable_gesture.dattr); |
| 1754 | if (err) { |
| 1755 | psmouse_err(psmouse, |
| 1756 | "Failed to create disable_gesture attribute (%d)", |
| 1757 | err); |
| 1758 | goto init_fail; |
| 1759 | } |
| 1760 | } |
| 1761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | return 0; |
| 1763 | |
| 1764 | init_fail: |
| 1765 | kfree(priv); |
Daniel Drake | 7968a5d | 2011-11-08 00:00:35 -0800 | [diff] [blame] | 1766 | return err; |
| 1767 | } |
| 1768 | |
| 1769 | int synaptics_init(struct psmouse *psmouse) |
| 1770 | { |
| 1771 | return __synaptics_init(psmouse, true); |
| 1772 | } |
| 1773 | |
| 1774 | int synaptics_init_relative(struct psmouse *psmouse) |
| 1775 | { |
| 1776 | return __synaptics_init(psmouse, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
Daniel Drake | e4e6efd | 2010-01-07 01:52:39 -0800 | [diff] [blame] | 1779 | bool synaptics_supported(void) |
| 1780 | { |
| 1781 | return true; |
| 1782 | } |
| 1783 | |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 1784 | #else /* CONFIG_MOUSE_PS2_SYNAPTICS */ |
| 1785 | |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 1786 | void __init synaptics_module_init(void) |
| 1787 | { |
| 1788 | } |
| 1789 | |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 1790 | int synaptics_init(struct psmouse *psmouse) |
| 1791 | { |
| 1792 | return -ENOSYS; |
| 1793 | } |
| 1794 | |
Daniel Drake | e4e6efd | 2010-01-07 01:52:39 -0800 | [diff] [blame] | 1795 | bool synaptics_supported(void) |
| 1796 | { |
| 1797 | return false; |
| 1798 | } |
| 1799 | |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 1800 | #endif /* CONFIG_MOUSE_PS2_SYNAPTICS */ |