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