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