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