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 | 83ba9ea8 | 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)) { |
| 170 | printk(KERN_ERR "Synaptics claims to have extended capabilities," |
Takashi Iwai | 5f57d67 | 2010-04-19 10:37:21 -0700 | [diff] [blame] | 171 | " 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)) { |
| 186 | printk(KERN_ERR "Synaptics claims to have extended capability 0x0c," |
| 187 | " but I'm not able to read it.\n"); |
| 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 | 83ba9ea8 | 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 | 83ba9ea8 | 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 | 83ba9ea8 | 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)) { |
| 235 | printk(KERN_ERR "Synaptics claims to have max coordinates" |
| 236 | " query, but I'm not able to read it.\n"); |
Dmitry Torokhov | 83ba9ea8 | 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)) { |
| 246 | printk(KERN_ERR "Synaptics claims to have min coordinates" |
| 247 | " query, but I'm not able to read it.\n"); |
| 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 | 83ba9ea8 | 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 | |
| 307 | if (!SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) |
| 308 | return 0; |
| 309 | |
| 310 | if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL)) |
| 311 | return -1; |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | /***************************************************************************** |
| 322 | * Synaptics pass-through PS/2 port support |
| 323 | ****************************************************************************/ |
| 324 | static int synaptics_pt_write(struct serio *serio, unsigned char c) |
| 325 | { |
| 326 | struct psmouse *parent = serio_get_drvdata(serio->parent); |
| 327 | char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */ |
| 328 | |
| 329 | if (psmouse_sliced_command(parent, c)) |
| 330 | return -1; |
| 331 | if (ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE)) |
| 332 | return -1; |
| 333 | return 0; |
| 334 | } |
| 335 | |
Dmitry Torokhov | a8b3c0f | 2010-10-04 21:46:10 -0700 | [diff] [blame] | 336 | static int synaptics_pt_start(struct serio *serio) |
| 337 | { |
| 338 | struct psmouse *parent = serio_get_drvdata(serio->parent); |
| 339 | struct synaptics_data *priv = parent->private; |
| 340 | |
| 341 | serio_pause_rx(parent->ps2dev.serio); |
| 342 | priv->pt_port = serio; |
| 343 | serio_continue_rx(parent->ps2dev.serio); |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | static void synaptics_pt_stop(struct serio *serio) |
| 349 | { |
| 350 | struct psmouse *parent = serio_get_drvdata(serio->parent); |
| 351 | struct synaptics_data *priv = parent->private; |
| 352 | |
| 353 | serio_pause_rx(parent->ps2dev.serio); |
| 354 | priv->pt_port = NULL; |
| 355 | serio_continue_rx(parent->ps2dev.serio); |
| 356 | } |
| 357 | |
| 358 | static int synaptics_is_pt_packet(unsigned char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
| 360 | return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4; |
| 361 | } |
| 362 | |
| 363 | static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet) |
| 364 | { |
| 365 | struct psmouse *child = serio_get_drvdata(ptport); |
| 366 | |
| 367 | if (child && child->state == PSMOUSE_ACTIVATED) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 368 | serio_interrupt(ptport, packet[1], 0); |
| 369 | serio_interrupt(ptport, packet[4], 0); |
| 370 | serio_interrupt(ptport, packet[5], 0); |
Sergey Vlasov | 33fdfa9 | 2005-07-24 00:53:32 -0500 | [diff] [blame] | 371 | if (child->pktsize == 4) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 372 | serio_interrupt(ptport, packet[2], 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } else |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 374 | serio_interrupt(ptport, packet[1], 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static void synaptics_pt_activate(struct psmouse *psmouse) |
| 378 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | struct synaptics_data *priv = psmouse->private; |
Dmitry Torokhov | a8b3c0f | 2010-10-04 21:46:10 -0700 | [diff] [blame] | 380 | struct psmouse *child = serio_get_drvdata(priv->pt_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
| 382 | /* adjust the touchpad to child's choice of protocol */ |
| 383 | if (child) { |
Sergey Vlasov | 33fdfa9 | 2005-07-24 00:53:32 -0500 | [diff] [blame] | 384 | if (child->pktsize == 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT; |
| 386 | else |
| 387 | priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT; |
| 388 | |
| 389 | if (synaptics_mode_cmd(psmouse, priv->mode)) |
| 390 | printk(KERN_INFO "synaptics: failed to switch guest protocol\n"); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | static void synaptics_pt_create(struct psmouse *psmouse) |
| 395 | { |
| 396 | struct serio *serio; |
| 397 | |
Eric Sesterhenn | b39787a | 2006-03-14 00:09:16 -0500 | [diff] [blame] | 398 | serio = kzalloc(sizeof(struct serio), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | if (!serio) { |
| 400 | printk(KERN_ERR "synaptics: not enough memory to allocate pass-through port\n"); |
| 401 | return; |
| 402 | } |
| 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | serio->id.type = SERIO_PS_PSTHRU; |
| 405 | strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name)); |
| 406 | strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name)); |
| 407 | serio->write = synaptics_pt_write; |
Dmitry Torokhov | a8b3c0f | 2010-10-04 21:46:10 -0700 | [diff] [blame] | 408 | serio->start = synaptics_pt_start; |
| 409 | serio->stop = synaptics_pt_stop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | serio->parent = psmouse->ps2dev.serio; |
| 411 | |
| 412 | psmouse->pt_activate = synaptics_pt_activate; |
| 413 | |
| 414 | printk(KERN_INFO "serio: %s port at %s\n", serio->name, psmouse->phys); |
| 415 | serio_register_port(serio); |
| 416 | } |
| 417 | |
| 418 | /***************************************************************************** |
| 419 | * Functions to interpret the absolute mode packets |
| 420 | ****************************************************************************/ |
| 421 | |
Daniel Kurtz | 7afdb84 | 2011-08-23 23:00:33 -0700 | [diff] [blame] | 422 | static void synaptics_parse_agm(const unsigned char buf[], |
| 423 | struct synaptics_data *priv) |
| 424 | { |
| 425 | struct synaptics_hw_state *agm = &priv->agm; |
| 426 | |
| 427 | /* Gesture packet: (x, y, z) at half resolution */ |
| 428 | agm->x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1; |
| 429 | agm->y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1; |
| 430 | agm->z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1; |
| 431 | } |
| 432 | |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 433 | static int synaptics_parse_hw_state(const unsigned char buf[], |
| 434 | struct synaptics_data *priv, |
| 435 | struct synaptics_hw_state *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
| 437 | memset(hw, 0, sizeof(struct synaptics_hw_state)); |
| 438 | |
| 439 | if (SYN_MODEL_NEWABS(priv->model_id)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | hw->w = (((buf[0] & 0x30) >> 2) | |
| 441 | ((buf[0] & 0x04) >> 1) | |
| 442 | ((buf[3] & 0x04) >> 2)); |
| 443 | |
| 444 | hw->left = (buf[0] & 0x01) ? 1 : 0; |
| 445 | hw->right = (buf[0] & 0x02) ? 1 : 0; |
| 446 | |
Takashi Iwai | 5f57d67 | 2010-04-19 10:37:21 -0700 | [diff] [blame] | 447 | if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) { |
| 448 | /* |
| 449 | * Clickpad's button is transmitted as middle button, |
| 450 | * however, since it is primary button, we will report |
| 451 | * it as BTN_LEFT. |
| 452 | */ |
| 453 | hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; |
| 454 | |
| 455 | } else if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; |
| 457 | if (hw->w == 2) |
| 458 | hw->scroll = (signed char)(buf[1]); |
| 459 | } |
| 460 | |
| 461 | if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) { |
| 462 | hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; |
| 463 | hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0; |
| 464 | } |
| 465 | |
Daniel Kurtz | 28d5fd8 | 2011-07-06 22:57:39 -0700 | [diff] [blame] | 466 | if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) && hw->w == 2) { |
Daniel Kurtz | 7afdb84 | 2011-08-23 23:00:33 -0700 | [diff] [blame] | 467 | synaptics_parse_agm(buf, priv); |
Daniel Kurtz | 28d5fd8 | 2011-07-06 22:57:39 -0700 | [diff] [blame] | 468 | return 1; |
| 469 | } |
| 470 | |
| 471 | hw->x = (((buf[3] & 0x10) << 8) | |
| 472 | ((buf[1] & 0x0f) << 8) | |
| 473 | buf[4]); |
| 474 | hw->y = (((buf[3] & 0x20) << 7) | |
| 475 | ((buf[1] & 0xf0) << 4) | |
| 476 | buf[5]); |
| 477 | hw->z = buf[2]; |
| 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) && |
| 480 | ((buf[0] ^ buf[3]) & 0x02)) { |
| 481 | switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) { |
| 482 | default: |
| 483 | /* |
| 484 | * if nExtBtn is greater than 8 it should be |
| 485 | * considered invalid and treated as 0 |
| 486 | */ |
| 487 | break; |
| 488 | case 8: |
| 489 | hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0; |
| 490 | hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0; |
| 491 | case 6: |
| 492 | hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0; |
| 493 | hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0; |
| 494 | case 4: |
| 495 | hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0; |
| 496 | hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0; |
| 497 | case 2: |
| 498 | hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0; |
| 499 | hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0; |
| 500 | } |
| 501 | } |
| 502 | } else { |
| 503 | hw->x = (((buf[1] & 0x1f) << 8) | buf[2]); |
| 504 | hw->y = (((buf[4] & 0x1f) << 8) | buf[5]); |
| 505 | |
| 506 | hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F)); |
| 507 | hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1)); |
| 508 | |
| 509 | hw->left = (buf[0] & 0x01) ? 1 : 0; |
| 510 | hw->right = (buf[0] & 0x02) ? 1 : 0; |
| 511 | } |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 512 | |
| 513 | return 0; |
| 514 | } |
| 515 | |
Daniel Kurtz | bea9f0f | 2011-07-06 22:42:52 -0700 | [diff] [blame] | 516 | static void synaptics_report_semi_mt_slot(struct input_dev *dev, int slot, |
| 517 | bool active, int x, int y) |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 518 | { |
| 519 | input_mt_slot(dev, slot); |
| 520 | input_mt_report_slot_state(dev, MT_TOOL_FINGER, active); |
| 521 | if (active) { |
| 522 | input_report_abs(dev, ABS_MT_POSITION_X, x); |
Daniel Kurtz | 6de58dd | 2011-08-23 23:00:24 -0700 | [diff] [blame] | 523 | input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(y)); |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
| 527 | static void synaptics_report_semi_mt_data(struct input_dev *dev, |
| 528 | const struct synaptics_hw_state *a, |
| 529 | const struct synaptics_hw_state *b, |
| 530 | int num_fingers) |
| 531 | { |
| 532 | if (num_fingers >= 2) { |
Daniel Kurtz | bea9f0f | 2011-07-06 22:42:52 -0700 | [diff] [blame] | 533 | synaptics_report_semi_mt_slot(dev, 0, true, min(a->x, b->x), |
| 534 | min(a->y, b->y)); |
| 535 | synaptics_report_semi_mt_slot(dev, 1, true, max(a->x, b->x), |
| 536 | max(a->y, b->y)); |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 537 | } else if (num_fingers == 1) { |
Daniel Kurtz | bea9f0f | 2011-07-06 22:42:52 -0700 | [diff] [blame] | 538 | synaptics_report_semi_mt_slot(dev, 0, true, a->x, a->y); |
| 539 | synaptics_report_semi_mt_slot(dev, 1, false, 0, 0); |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 540 | } else { |
Daniel Kurtz | bea9f0f | 2011-07-06 22:42:52 -0700 | [diff] [blame] | 541 | synaptics_report_semi_mt_slot(dev, 0, false, 0, 0); |
| 542 | synaptics_report_semi_mt_slot(dev, 1, false, 0, 0); |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 543 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | /* |
| 547 | * called for each full received packet from the touchpad |
| 548 | */ |
| 549 | static void synaptics_process_packet(struct psmouse *psmouse) |
| 550 | { |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 551 | struct input_dev *dev = psmouse->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | struct synaptics_data *priv = psmouse->private; |
| 553 | struct synaptics_hw_state hw; |
| 554 | int num_fingers; |
| 555 | int finger_width; |
| 556 | int i; |
| 557 | |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 558 | if (synaptics_parse_hw_state(psmouse->packet, priv, &hw)) |
| 559 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
| 561 | if (hw.scroll) { |
| 562 | priv->scroll += hw.scroll; |
| 563 | |
| 564 | while (priv->scroll >= 4) { |
| 565 | input_report_key(dev, BTN_BACK, !hw.down); |
| 566 | input_sync(dev); |
| 567 | input_report_key(dev, BTN_BACK, hw.down); |
| 568 | input_sync(dev); |
| 569 | priv->scroll -= 4; |
| 570 | } |
| 571 | while (priv->scroll <= -4) { |
| 572 | input_report_key(dev, BTN_FORWARD, !hw.up); |
| 573 | input_sync(dev); |
| 574 | input_report_key(dev, BTN_FORWARD, hw.up); |
| 575 | input_sync(dev); |
| 576 | priv->scroll += 4; |
| 577 | } |
| 578 | return; |
| 579 | } |
| 580 | |
Henrik Rydberg | 4f56ce9 | 2010-12-18 15:42:30 +0100 | [diff] [blame] | 581 | if (hw.z > 0 && hw.x > 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | num_fingers = 1; |
| 583 | finger_width = 5; |
| 584 | if (SYN_CAP_EXTENDED(priv->capabilities)) { |
| 585 | switch (hw.w) { |
| 586 | case 0 ... 1: |
| 587 | if (SYN_CAP_MULTIFINGER(priv->capabilities)) |
| 588 | num_fingers = hw.w + 2; |
| 589 | break; |
| 590 | case 2: |
| 591 | if (SYN_MODEL_PEN(priv->model_id)) |
| 592 | ; /* Nothing, treat a pen as a single finger */ |
| 593 | break; |
| 594 | case 4 ... 15: |
| 595 | if (SYN_CAP_PALMDETECT(priv->capabilities)) |
| 596 | finger_width = hw.w; |
| 597 | break; |
| 598 | } |
| 599 | } |
| 600 | } else { |
| 601 | num_fingers = 0; |
| 602 | finger_width = 0; |
| 603 | } |
| 604 | |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 605 | if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) |
Daniel Kurtz | 7afdb84 | 2011-08-23 23:00:33 -0700 | [diff] [blame] | 606 | synaptics_report_semi_mt_data(dev, &hw, &priv->agm, |
| 607 | num_fingers); |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | /* Post events |
| 610 | * BTN_TOUCH has to be first as mousedev relies on it when doing |
| 611 | * absolute -> relative conversion |
| 612 | */ |
| 613 | if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1); |
| 614 | if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0); |
| 615 | |
Henrik Rydberg | 4f56ce9 | 2010-12-18 15:42:30 +0100 | [diff] [blame] | 616 | if (num_fingers > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | input_report_abs(dev, ABS_X, hw.x); |
Daniel Kurtz | 6de58dd | 2011-08-23 23:00:24 -0700 | [diff] [blame] | 618 | input_report_abs(dev, ABS_Y, synaptics_invert_y(hw.y)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } |
| 620 | input_report_abs(dev, ABS_PRESSURE, hw.z); |
| 621 | |
Chris Bagwell | 2a8e771 | 2010-07-19 09:06:15 -0700 | [diff] [blame] | 622 | if (SYN_CAP_PALMDETECT(priv->capabilities)) |
| 623 | input_report_abs(dev, ABS_TOOL_WIDTH, finger_width); |
| 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | input_report_key(dev, BTN_LEFT, hw.left); |
| 627 | input_report_key(dev, BTN_RIGHT, hw.right); |
| 628 | |
Peter Hutterer | e42b664 | 2008-11-20 15:24:42 -0500 | [diff] [blame] | 629 | if (SYN_CAP_MULTIFINGER(priv->capabilities)) { |
| 630 | input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2); |
| 631 | input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3); |
| 632 | } |
| 633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) |
| 635 | input_report_key(dev, BTN_MIDDLE, hw.middle); |
| 636 | |
| 637 | if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) { |
| 638 | input_report_key(dev, BTN_FORWARD, hw.up); |
| 639 | input_report_key(dev, BTN_BACK, hw.down); |
| 640 | } |
| 641 | |
| 642 | for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++) |
| 643 | input_report_key(dev, BTN_0 + i, hw.ext_buttons & (1 << i)); |
| 644 | |
| 645 | input_sync(dev); |
| 646 | } |
| 647 | |
| 648 | static int synaptics_validate_byte(unsigned char packet[], int idx, unsigned char pkt_type) |
| 649 | { |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 650 | static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 }; |
| 651 | static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 }; |
| 652 | static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 }; |
| 653 | static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 }; |
| 654 | static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
| 656 | if (idx < 0 || idx > 4) |
| 657 | return 0; |
| 658 | |
| 659 | switch (pkt_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 661 | case SYN_NEWABS: |
| 662 | case SYN_NEWABS_RELAXED: |
| 663 | return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 665 | case SYN_NEWABS_STRICT: |
| 666 | return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 668 | case SYN_OLDABS: |
| 669 | return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx]; |
| 670 | |
| 671 | default: |
| 672 | printk(KERN_ERR "synaptics: unknown packet type %d\n", pkt_type); |
| 673 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | |
| 677 | static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse) |
| 678 | { |
| 679 | int i; |
| 680 | |
| 681 | for (i = 0; i < 5; i++) |
| 682 | if (!synaptics_validate_byte(psmouse->packet, i, SYN_NEWABS_STRICT)) { |
| 683 | printk(KERN_INFO "synaptics: using relaxed packet validation\n"); |
| 684 | return SYN_NEWABS_RELAXED; |
| 685 | } |
| 686 | |
| 687 | return SYN_NEWABS_STRICT; |
| 688 | } |
| 689 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 690 | static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | struct synaptics_data *priv = psmouse->private; |
| 693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | if (psmouse->pktcnt >= 6) { /* Full packet received */ |
| 695 | if (unlikely(priv->pkt_type == SYN_NEWABS)) |
| 696 | priv->pkt_type = synaptics_detect_pkt_type(psmouse); |
| 697 | |
Dmitry Torokhov | a8b3c0f | 2010-10-04 21:46:10 -0700 | [diff] [blame] | 698 | if (SYN_CAP_PASS_THROUGH(priv->capabilities) && |
| 699 | synaptics_is_pt_packet(psmouse->packet)) { |
| 700 | if (priv->pt_port) |
| 701 | synaptics_pass_pt_packet(priv->pt_port, psmouse->packet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } else |
| 703 | synaptics_process_packet(psmouse); |
| 704 | |
| 705 | return PSMOUSE_FULL_PACKET; |
| 706 | } |
| 707 | |
| 708 | return synaptics_validate_byte(psmouse->packet, psmouse->pktcnt - 1, priv->pkt_type) ? |
| 709 | PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA; |
| 710 | } |
| 711 | |
| 712 | /***************************************************************************** |
| 713 | * Driver initialization/cleanup functions |
| 714 | ****************************************************************************/ |
Daniel Kurtz | 8561547 | 2011-08-23 23:00:41 -0700 | [diff] [blame^] | 715 | static void set_abs_position_params(struct input_dev *dev, |
| 716 | struct synaptics_data *priv, int x_code, |
| 717 | int y_code) |
| 718 | { |
| 719 | int x_min = priv->x_min ?: XMIN_NOMINAL; |
| 720 | int x_max = priv->x_max ?: XMAX_NOMINAL; |
| 721 | int y_min = priv->y_min ?: YMIN_NOMINAL; |
| 722 | int y_max = priv->y_max ?: YMAX_NOMINAL; |
| 723 | int fuzz = SYN_CAP_REDUCED_FILTERING(priv->ext_cap_0c) ? |
| 724 | SYN_REDUCED_FILTER_FUZZ : 0; |
| 725 | |
| 726 | input_set_abs_params(dev, x_code, x_min, x_max, fuzz, 0); |
| 727 | input_set_abs_params(dev, y_code, y_min, y_max, fuzz, 0); |
| 728 | input_abs_set_res(dev, x_code, priv->x_res); |
| 729 | input_abs_set_res(dev, y_code, priv->y_res); |
| 730 | } |
| 731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | static void set_input_params(struct input_dev *dev, struct synaptics_data *priv) |
| 733 | { |
| 734 | int i; |
| 735 | |
Henrik Rydberg | c14890a | 2010-12-16 09:52:23 +0100 | [diff] [blame] | 736 | __set_bit(INPUT_PROP_POINTER, dev->propbit); |
| 737 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 738 | __set_bit(EV_ABS, dev->evbit); |
Daniel Kurtz | 8561547 | 2011-08-23 23:00:41 -0700 | [diff] [blame^] | 739 | set_abs_position_params(dev, priv, ABS_X, ABS_Y); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0); |
Chris Bagwell | 2a8e771 | 2010-07-19 09:06:15 -0700 | [diff] [blame] | 741 | |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 742 | if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) { |
| 743 | __set_bit(INPUT_PROP_SEMI_MT, dev->propbit); |
| 744 | input_mt_init_slots(dev, 2); |
Daniel Kurtz | 8561547 | 2011-08-23 23:00:41 -0700 | [diff] [blame^] | 745 | set_abs_position_params(dev, priv, ABS_MT_POSITION_X, |
| 746 | ABS_MT_POSITION_Y); |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 747 | } |
| 748 | |
Chris Bagwell | 2a8e771 | 2010-07-19 09:06:15 -0700 | [diff] [blame] | 749 | if (SYN_CAP_PALMDETECT(priv->capabilities)) |
Chris Bagwell | 58fb021 | 2010-07-19 09:06:15 -0700 | [diff] [blame] | 750 | input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 752 | __set_bit(EV_KEY, dev->evbit); |
| 753 | __set_bit(BTN_TOUCH, dev->keybit); |
| 754 | __set_bit(BTN_TOOL_FINGER, dev->keybit); |
| 755 | __set_bit(BTN_LEFT, dev->keybit); |
| 756 | __set_bit(BTN_RIGHT, dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
Peter Hutterer | e42b664 | 2008-11-20 15:24:42 -0500 | [diff] [blame] | 758 | if (SYN_CAP_MULTIFINGER(priv->capabilities)) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 759 | __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit); |
| 760 | __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit); |
Peter Hutterer | e42b664 | 2008-11-20 15:24:42 -0500 | [diff] [blame] | 761 | } |
| 762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 764 | __set_bit(BTN_MIDDLE, dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
| 766 | if (SYN_CAP_FOUR_BUTTON(priv->capabilities) || |
| 767 | SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 768 | __set_bit(BTN_FORWARD, dev->keybit); |
| 769 | __set_bit(BTN_BACK, dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | 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] | 773 | __set_bit(BTN_0 + i, dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 775 | __clear_bit(EV_REL, dev->evbit); |
| 776 | __clear_bit(REL_X, dev->relbit); |
| 777 | __clear_bit(REL_Y, dev->relbit); |
Tero Saarni | ec20a02 | 2009-06-10 23:27:24 -0700 | [diff] [blame] | 778 | |
Takashi Iwai | 5f57d67 | 2010-04-19 10:37:21 -0700 | [diff] [blame] | 779 | if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) { |
Henrik Rydberg | c14890a | 2010-12-16 09:52:23 +0100 | [diff] [blame] | 780 | __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit); |
Takashi Iwai | 5f57d67 | 2010-04-19 10:37:21 -0700 | [diff] [blame] | 781 | /* Clickpads report only left button */ |
| 782 | __clear_bit(BTN_RIGHT, dev->keybit); |
| 783 | __clear_bit(BTN_MIDDLE, dev->keybit); |
| 784 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | static void synaptics_disconnect(struct psmouse *psmouse) |
| 788 | { |
| 789 | synaptics_reset(psmouse); |
| 790 | kfree(psmouse->private); |
| 791 | psmouse->private = NULL; |
| 792 | } |
| 793 | |
| 794 | static int synaptics_reconnect(struct psmouse *psmouse) |
| 795 | { |
| 796 | struct synaptics_data *priv = psmouse->private; |
| 797 | struct synaptics_data old_priv = *priv; |
Alexandre Peixoto Ferreira | c63fe0a | 2011-01-28 22:05:14 -0800 | [diff] [blame] | 798 | int retry = 0; |
| 799 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
Alexandre Peixoto Ferreira | c63fe0a | 2011-01-28 22:05:14 -0800 | [diff] [blame] | 801 | do { |
| 802 | psmouse_reset(psmouse); |
| 803 | error = synaptics_detect(psmouse, 0); |
| 804 | } while (error && ++retry < 3); |
Andy Whitcroft | 4d36845 | 2009-02-28 12:51:01 -0800 | [diff] [blame] | 805 | |
Alexandre Peixoto Ferreira | c63fe0a | 2011-01-28 22:05:14 -0800 | [diff] [blame] | 806 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | return -1; |
| 808 | |
Alexandre Peixoto Ferreira | c63fe0a | 2011-01-28 22:05:14 -0800 | [diff] [blame] | 809 | if (retry > 1) |
| 810 | printk(KERN_DEBUG "Synaptics reconnected after %d tries\n", |
| 811 | retry); |
| 812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | if (synaptics_query_hardware(psmouse)) { |
| 814 | printk(KERN_ERR "Unable to query Synaptics hardware.\n"); |
| 815 | return -1; |
| 816 | } |
| 817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | if (synaptics_set_absolute_mode(psmouse)) { |
| 819 | printk(KERN_ERR "Unable to initialize Synaptics hardware.\n"); |
| 820 | return -1; |
| 821 | } |
| 822 | |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 823 | if (synaptics_set_advanced_gesture_mode(psmouse)) { |
| 824 | printk(KERN_ERR "Advanced gesture mode reconnect failed.\n"); |
| 825 | return -1; |
| 826 | } |
| 827 | |
Alexandre Peixoto Ferreira | baddf58 | 2011-01-28 22:05:14 -0800 | [diff] [blame] | 828 | if (old_priv.identity != priv->identity || |
| 829 | old_priv.model_id != priv->model_id || |
| 830 | old_priv.capabilities != priv->capabilities || |
| 831 | old_priv.ext_cap != priv->ext_cap) { |
| 832 | printk(KERN_ERR "Synaptics hardware appears to be different: " |
| 833 | "id(%ld-%ld), model(%ld-%ld), caps(%lx-%lx), ext(%lx-%lx).\n", |
| 834 | old_priv.identity, priv->identity, |
| 835 | old_priv.model_id, priv->model_id, |
| 836 | old_priv.capabilities, priv->capabilities, |
| 837 | old_priv.ext_cap, priv->ext_cap); |
| 838 | return -1; |
| 839 | } |
| 840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | return 0; |
| 842 | } |
| 843 | |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 844 | static bool impaired_toshiba_kbc; |
| 845 | |
| 846 | static const struct dmi_system_id __initconst toshiba_dmi_table[] = { |
| 847 | #if defined(CONFIG_DMI) && defined(CONFIG_X86) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | { |
Dmitry Torokhov | 9961e25 | 2009-12-04 10:24:20 -0800 | [diff] [blame] | 849 | /* Toshiba Satellite */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | .matches = { |
| 851 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
Richard Thrippleton | 53a2670 | 2006-04-02 00:10:18 -0500 | [diff] [blame] | 852 | DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | }, |
| 854 | }, |
Simon Horman | 9ba5eaa | 2005-07-11 01:07:20 -0500 | [diff] [blame] | 855 | { |
Dmitry Torokhov | 9961e25 | 2009-12-04 10:24:20 -0800 | [diff] [blame] | 856 | /* Toshiba Dynabook */ |
Simon Horman | 9ba5eaa | 2005-07-11 01:07:20 -0500 | [diff] [blame] | 857 | .matches = { |
| 858 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
Richard Thrippleton | 53a2670 | 2006-04-02 00:10:18 -0500 | [diff] [blame] | 859 | DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"), |
| 860 | }, |
| 861 | }, |
| 862 | { |
Dmitry Torokhov | 9961e25 | 2009-12-04 10:24:20 -0800 | [diff] [blame] | 863 | /* Toshiba Portege M300 */ |
Richard Thrippleton | 53a2670 | 2006-04-02 00:10:18 -0500 | [diff] [blame] | 864 | .matches = { |
| 865 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
| 866 | DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"), |
Simon Horman | 9ba5eaa | 2005-07-11 01:07:20 -0500 | [diff] [blame] | 867 | }, |
Dmitry Torokhov | 5f5eeff | 2009-10-12 21:35:00 -0700 | [diff] [blame] | 868 | |
| 869 | }, |
| 870 | { |
Dmitry Torokhov | 9961e25 | 2009-12-04 10:24:20 -0800 | [diff] [blame] | 871 | /* Toshiba Portege M300 */ |
Dmitry Torokhov | 5f5eeff | 2009-10-12 21:35:00 -0700 | [diff] [blame] | 872 | .matches = { |
| 873 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
| 874 | DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"), |
| 875 | DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"), |
| 876 | }, |
| 877 | |
Simon Horman | 9ba5eaa | 2005-07-11 01:07:20 -0500 | [diff] [blame] | 878 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | #endif |
Jan Beulich | 7087486 | 2011-03-31 00:01:58 -0700 | [diff] [blame] | 880 | { } |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 881 | }; |
| 882 | |
Andres Salomon | ef8313b | 2010-12-23 01:19:38 -0800 | [diff] [blame] | 883 | static bool broken_olpc_ec; |
| 884 | |
| 885 | static const struct dmi_system_id __initconst olpc_dmi_table[] = { |
| 886 | #if defined(CONFIG_DMI) && defined(CONFIG_OLPC) |
| 887 | { |
| 888 | /* OLPC XO-1 or XO-1.5 */ |
| 889 | .matches = { |
| 890 | DMI_MATCH(DMI_SYS_VENDOR, "OLPC"), |
| 891 | DMI_MATCH(DMI_PRODUCT_NAME, "XO"), |
| 892 | }, |
| 893 | }, |
Andres Salomon | ef8313b | 2010-12-23 01:19:38 -0800 | [diff] [blame] | 894 | #endif |
Jan Beulich | 7087486 | 2011-03-31 00:01:58 -0700 | [diff] [blame] | 895 | { } |
Andres Salomon | ef8313b | 2010-12-23 01:19:38 -0800 | [diff] [blame] | 896 | }; |
| 897 | |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 898 | void __init synaptics_module_init(void) |
| 899 | { |
| 900 | impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table); |
Andres Salomon | ef8313b | 2010-12-23 01:19:38 -0800 | [diff] [blame] | 901 | broken_olpc_ec = dmi_check_system(olpc_dmi_table); |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 902 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
| 904 | int synaptics_init(struct psmouse *psmouse) |
| 905 | { |
| 906 | struct synaptics_data *priv; |
| 907 | |
Andres Salomon | ef8313b | 2010-12-23 01:19:38 -0800 | [diff] [blame] | 908 | /* |
| 909 | * The OLPC XO has issues with Synaptics' absolute mode; similarly to |
| 910 | * the HGPK, it quickly degrades and the hardware becomes jumpy and |
| 911 | * overly sensitive. Not only that, but the constant packet spew |
| 912 | * (even at a lowered 40pps rate) overloads the EC such that key |
| 913 | * presses on the keyboard are missed. Given all of that, don't |
| 914 | * even attempt to use Synaptics mode. Relative mode seems to work |
| 915 | * just fine. |
| 916 | */ |
| 917 | if (broken_olpc_ec) { |
| 918 | printk(KERN_INFO "synaptics: OLPC XO detected, not enabling Synaptics protocol.\n"); |
| 919 | return -ENODEV; |
| 920 | } |
| 921 | |
Eric Sesterhenn | b39787a | 2006-03-14 00:09:16 -0500 | [diff] [blame] | 922 | psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | if (!priv) |
Davidlohr Bueso | 6792cbb | 2010-09-29 18:53:35 -0700 | [diff] [blame] | 924 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Andy Whitcroft | 4d36845 | 2009-02-28 12:51:01 -0800 | [diff] [blame] | 926 | psmouse_reset(psmouse); |
| 927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | if (synaptics_query_hardware(psmouse)) { |
| 929 | printk(KERN_ERR "Unable to query Synaptics hardware.\n"); |
| 930 | goto init_fail; |
| 931 | } |
| 932 | |
| 933 | if (synaptics_set_absolute_mode(psmouse)) { |
| 934 | printk(KERN_ERR "Unable to initialize Synaptics hardware.\n"); |
| 935 | goto init_fail; |
| 936 | } |
| 937 | |
Henrik Rydberg | fec6e52 | 2010-12-21 18:11:25 +0100 | [diff] [blame] | 938 | if (synaptics_set_advanced_gesture_mode(psmouse)) { |
| 939 | printk(KERN_ERR "Advanced gesture mode init failed.\n"); |
| 940 | goto init_fail; |
| 941 | } |
| 942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS; |
| 944 | |
Takashi Iwai | 5f57d67 | 2010-04-19 10:37:21 -0700 | [diff] [blame] | 945 | printk(KERN_INFO "Synaptics Touchpad, model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx\n", |
Dmitry Torokhov | 409b750 | 2005-05-28 02:12:18 -0500 | [diff] [blame] | 946 | SYN_ID_MODEL(priv->identity), |
| 947 | SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity), |
Takashi Iwai | 5f57d67 | 2010-04-19 10:37:21 -0700 | [diff] [blame] | 948 | priv->model_id, priv->capabilities, priv->ext_cap, priv->ext_cap_0c); |
Dmitry Torokhov | 409b750 | 2005-05-28 02:12:18 -0500 | [diff] [blame] | 949 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 950 | set_input_params(psmouse->dev, priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
Dmitry Torokhov | 887cc12 | 2007-04-12 01:30:41 -0400 | [diff] [blame] | 952 | /* |
| 953 | * Encode touchpad model so that it can be used to set |
| 954 | * input device->id.version and be visible to userspace. |
| 955 | * Because version is __u16 we have to drop something. |
| 956 | * Hardware info bits seem to be good candidates as they |
| 957 | * are documented to be for Synaptics corp. internal use. |
| 958 | */ |
| 959 | psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) | |
| 960 | (priv->model_id & 0x000000ff); |
| 961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | psmouse->protocol_handler = synaptics_process_byte; |
| 963 | psmouse->set_rate = synaptics_set_rate; |
| 964 | psmouse->disconnect = synaptics_disconnect; |
| 965 | psmouse->reconnect = synaptics_reconnect; |
Dmitry Torokhov | a1cec06 | 2007-02-18 01:40:24 -0500 | [diff] [blame] | 966 | psmouse->cleanup = synaptics_reset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | psmouse->pktsize = 6; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 968 | /* Synaptics can usually stay in sync without extra help */ |
| 969 | psmouse->resync_time = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
| 971 | if (SYN_CAP_PASS_THROUGH(priv->capabilities)) |
| 972 | synaptics_pt_create(psmouse); |
| 973 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | /* |
| 975 | * Toshiba's KBC seems to have trouble handling data from |
Andres Salomon | 7ee9916 | 2010-12-23 01:18:28 -0800 | [diff] [blame] | 976 | * Synaptics at full rate. Switch to a lower rate (roughly |
| 977 | * the same rate as a standard PS/2 mouse). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | */ |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 979 | if (psmouse->rate >= 80 && impaired_toshiba_kbc) { |
Simon Horman | 9ba5eaa | 2005-07-11 01:07:20 -0500 | [diff] [blame] | 980 | printk(KERN_INFO "synaptics: Toshiba %s detected, limiting rate to 40pps.\n", |
| 981 | dmi_get_system_info(DMI_PRODUCT_NAME)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | psmouse->rate = 40; |
| 983 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | |
| 985 | return 0; |
| 986 | |
| 987 | init_fail: |
| 988 | kfree(priv); |
| 989 | return -1; |
| 990 | } |
| 991 | |
Daniel Drake | e4e6efd | 2010-01-07 01:52:39 -0800 | [diff] [blame] | 992 | bool synaptics_supported(void) |
| 993 | { |
| 994 | return true; |
| 995 | } |
| 996 | |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 997 | #else /* CONFIG_MOUSE_PS2_SYNAPTICS */ |
| 998 | |
Dmitry Torokhov | 7705d54 | 2009-12-03 23:21:14 -0800 | [diff] [blame] | 999 | void __init synaptics_module_init(void) |
| 1000 | { |
| 1001 | } |
| 1002 | |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 1003 | int synaptics_init(struct psmouse *psmouse) |
| 1004 | { |
| 1005 | return -ENOSYS; |
| 1006 | } |
| 1007 | |
Daniel Drake | e4e6efd | 2010-01-07 01:52:39 -0800 | [diff] [blame] | 1008 | bool synaptics_supported(void) |
| 1009 | { |
| 1010 | return false; |
| 1011 | } |
| 1012 | |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 1013 | #endif /* CONFIG_MOUSE_PS2_SYNAPTICS */ |