Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
7705d548 | 27 | #include <linux/dmi.h> |
fec6e525 | 28 | #include <linux/input/mt.h> |
1da177e4 LT |
29 | #include <linux/serio.h> |
30 | #include <linux/libps2.h> | |
5a0e3ad6 | 31 | #include <linux/slab.h> |
1da177e4 LT |
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. | |
83ba9ea8 DT |
39 | * Note that newer firmware allows querying device for maximum useable |
40 | * coordinates. | |
1da177e4 LT |
41 | */ |
42 | #define XMIN_NOMINAL 1472 | |
43 | #define XMAX_NOMINAL 5472 | |
44 | #define YMIN_NOMINAL 1408 | |
45 | #define YMAX_NOMINAL 4448 | |
46 | ||
6de58dd6 DK |
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 | ||
55e3d922 | 57 | |
1da177e4 | 58 | /***************************************************************************** |
55e3d922 | 59 | * Stuff we need even when we do not want native Synaptics support |
1da177e4 LT |
60 | ****************************************************************************/ |
61 | ||
62 | /* | |
55e3d922 | 63 | * Set the synaptics touchpad mode byte by special commands |
1da177e4 | 64 | */ |
55e3d922 | 65 | static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode) |
1da177e4 | 66 | { |
55e3d922 AS |
67 | unsigned char param[1]; |
68 | ||
69 | if (psmouse_sliced_command(psmouse, mode)) | |
1da177e4 | 70 | return -1; |
55e3d922 AS |
71 | param[0] = SYN_PS_SET_MODE2; |
72 | if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE)) | |
1da177e4 LT |
73 | return -1; |
74 | return 0; | |
75 | } | |
76 | ||
b7802c5c | 77 | int synaptics_detect(struct psmouse *psmouse, bool set_properties) |
55e3d922 AS |
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 | ||
1da177e4 | 113 | /* |
55e3d922 | 114 | * Send a command to the synpatics touchpad by special commands |
1da177e4 | 115 | */ |
55e3d922 | 116 | static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param) |
1da177e4 | 117 | { |
55e3d922 | 118 | if (psmouse_sliced_command(psmouse, c)) |
1da177e4 | 119 | return -1; |
55e3d922 | 120 | if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO)) |
1da177e4 LT |
121 | return -1; |
122 | return 0; | |
123 | } | |
124 | ||
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]; | |
5f57d67d TI |
152 | priv->ext_cap = priv->ext_cap_0c = 0; |
153 | ||
3619b8fe DT |
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) { | |
1da177e4 | 159 | return -1; |
3619b8fe | 160 | } |
1da177e4 LT |
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," | |
5f57d67d | 171 | " but I'm not able to read them.\n"); |
1da177e4 LT |
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 | } | |
5f57d67d TI |
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 | ||
1da177e4 LT |
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 | ||
ec20a022 | 213 | /* |
83ba9ea8 | 214 | * Read touchpad resolution and maximum reported coordinates |
ec20a022 TS |
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; | |
a66413fb | 220 | unsigned char resp[3]; |
ec20a022 TS |
221 | |
222 | if (SYN_ID_MAJOR(priv->identity) < 4) | |
bbddd199 | 223 | return 0; |
ec20a022 | 224 | |
a66413fb DT |
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 */ | |
83ba9ea8 DT |
229 | } |
230 | } | |
ec20a022 | 231 | |
83ba9ea8 DT |
232 | if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 5 && |
233 | SYN_CAP_MAX_DIMENSIONS(priv->ext_cap_0c)) { | |
a66413fb DT |
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"); | |
237 | } else { | |
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"); | |
83ba9ea8 | 248 | } else { |
a66413fb DT |
249 | priv->x_min = (resp[0] << 5) | ((resp[1] & 0x0f) << 1); |
250 | priv->y_min = (resp[2] << 5) | ((resp[1] & 0xf0) >> 3); | |
83ba9ea8 | 251 | } |
ec20a022 TS |
252 | } |
253 | ||
254 | return 0; | |
255 | } | |
256 | ||
1da177e4 LT |
257 | static int synaptics_query_hardware(struct psmouse *psmouse) |
258 | { | |
1da177e4 LT |
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; | |
ec20a022 TS |
265 | if (synaptics_resolution(psmouse)) |
266 | return -1; | |
1da177e4 LT |
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 | ||
fec6e525 HR |
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 | ||
3cdfee9e DK |
307 | if (!(SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) || |
308 | SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c))) | |
fec6e525 HR |
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 | ||
1da177e4 LT |
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 | ||
a8b3c0f5 DT |
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) | |
1da177e4 LT |
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) { | |
7d12e780 DH |
369 | serio_interrupt(ptport, packet[1], 0); |
370 | serio_interrupt(ptport, packet[4], 0); | |
371 | serio_interrupt(ptport, packet[5], 0); | |
33fdfa97 | 372 | if (child->pktsize == 4) |
7d12e780 | 373 | serio_interrupt(ptport, packet[2], 0); |
1da177e4 | 374 | } else |
7d12e780 | 375 | serio_interrupt(ptport, packet[1], 0); |
1da177e4 LT |
376 | } |
377 | ||
378 | static void synaptics_pt_activate(struct psmouse *psmouse) | |
379 | { | |
1da177e4 | 380 | struct synaptics_data *priv = psmouse->private; |
a8b3c0f5 | 381 | struct psmouse *child = serio_get_drvdata(priv->pt_port); |
1da177e4 LT |
382 | |
383 | /* adjust the touchpad to child's choice of protocol */ | |
384 | if (child) { | |
33fdfa97 | 385 | if (child->pktsize == 4) |
1da177e4 LT |
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)) | |
391 | printk(KERN_INFO "synaptics: failed to switch guest protocol\n"); | |
392 | } | |
393 | } | |
394 | ||
395 | static void synaptics_pt_create(struct psmouse *psmouse) | |
396 | { | |
397 | struct serio *serio; | |
398 | ||
b39787a9 | 399 | serio = kzalloc(sizeof(struct serio), GFP_KERNEL); |
1da177e4 LT |
400 | if (!serio) { |
401 | printk(KERN_ERR "synaptics: not enough memory to allocate pass-through port\n"); | |
402 | return; | |
403 | } | |
404 | ||
1da177e4 LT |
405 | serio->id.type = SERIO_PS_PSTHRU; |
406 | strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name)); | |
407 | strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name)); | |
408 | serio->write = synaptics_pt_write; | |
a8b3c0f5 DT |
409 | serio->start = synaptics_pt_start; |
410 | serio->stop = synaptics_pt_stop; | |
1da177e4 LT |
411 | serio->parent = psmouse->ps2dev.serio; |
412 | ||
413 | psmouse->pt_activate = synaptics_pt_activate; | |
414 | ||
415 | printk(KERN_INFO "serio: %s port at %s\n", serio->name, psmouse->phys); | |
416 | serio_register_port(serio); | |
417 | } | |
418 | ||
419 | /***************************************************************************** | |
420 | * Functions to interpret the absolute mode packets | |
421 | ****************************************************************************/ | |
422 | ||
7afdb842 DK |
423 | static void synaptics_parse_agm(const unsigned char buf[], |
424 | struct synaptics_data *priv) | |
425 | { | |
426 | struct synaptics_hw_state *agm = &priv->agm; | |
427 | ||
428 | /* Gesture packet: (x, y, z) at half resolution */ | |
429 | agm->x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1; | |
430 | agm->y = (((buf[4] & 0xf0) << 4) | buf[2]) << 1; | |
431 | agm->z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1; | |
432 | } | |
433 | ||
fec6e525 HR |
434 | static int synaptics_parse_hw_state(const unsigned char buf[], |
435 | struct synaptics_data *priv, | |
436 | struct synaptics_hw_state *hw) | |
1da177e4 LT |
437 | { |
438 | memset(hw, 0, sizeof(struct synaptics_hw_state)); | |
439 | ||
440 | if (SYN_MODEL_NEWABS(priv->model_id)) { | |
1da177e4 LT |
441 | hw->w = (((buf[0] & 0x30) >> 2) | |
442 | ((buf[0] & 0x04) >> 1) | | |
443 | ((buf[3] & 0x04) >> 2)); | |
444 | ||
445 | hw->left = (buf[0] & 0x01) ? 1 : 0; | |
446 | hw->right = (buf[0] & 0x02) ? 1 : 0; | |
447 | ||
5f57d67d TI |
448 | if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) { |
449 | /* | |
450 | * Clickpad's button is transmitted as middle button, | |
451 | * however, since it is primary button, we will report | |
452 | * it as BTN_LEFT. | |
453 | */ | |
454 | hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; | |
455 | ||
456 | } else if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) { | |
1da177e4 LT |
457 | hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; |
458 | if (hw->w == 2) | |
459 | hw->scroll = (signed char)(buf[1]); | |
460 | } | |
461 | ||
462 | if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) { | |
463 | hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; | |
464 | hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0; | |
465 | } | |
466 | ||
3cdfee9e DK |
467 | if ((SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) || |
468 | SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) && | |
469 | hw->w == 2) { | |
7afdb842 | 470 | synaptics_parse_agm(buf, priv); |
28d5fd86 DK |
471 | return 1; |
472 | } | |
473 | ||
474 | hw->x = (((buf[3] & 0x10) << 8) | | |
475 | ((buf[1] & 0x0f) << 8) | | |
476 | buf[4]); | |
477 | hw->y = (((buf[3] & 0x20) << 7) | | |
478 | ((buf[1] & 0xf0) << 4) | | |
479 | buf[5]); | |
480 | hw->z = buf[2]; | |
481 | ||
1da177e4 LT |
482 | if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) && |
483 | ((buf[0] ^ buf[3]) & 0x02)) { | |
484 | switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) { | |
485 | default: | |
486 | /* | |
487 | * if nExtBtn is greater than 8 it should be | |
488 | * considered invalid and treated as 0 | |
489 | */ | |
490 | break; | |
491 | case 8: | |
492 | hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0; | |
493 | hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0; | |
494 | case 6: | |
495 | hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0; | |
496 | hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0; | |
497 | case 4: | |
498 | hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0; | |
499 | hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0; | |
500 | case 2: | |
501 | hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0; | |
502 | hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0; | |
503 | } | |
504 | } | |
505 | } else { | |
506 | hw->x = (((buf[1] & 0x1f) << 8) | buf[2]); | |
507 | hw->y = (((buf[4] & 0x1f) << 8) | buf[5]); | |
508 | ||
509 | hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F)); | |
510 | hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1)); | |
511 | ||
512 | hw->left = (buf[0] & 0x01) ? 1 : 0; | |
513 | hw->right = (buf[0] & 0x02) ? 1 : 0; | |
514 | } | |
fec6e525 HR |
515 | |
516 | return 0; | |
517 | } | |
518 | ||
bea9f0ff DK |
519 | static void synaptics_report_semi_mt_slot(struct input_dev *dev, int slot, |
520 | bool active, int x, int y) | |
fec6e525 HR |
521 | { |
522 | input_mt_slot(dev, slot); | |
523 | input_mt_report_slot_state(dev, MT_TOOL_FINGER, active); | |
524 | if (active) { | |
525 | input_report_abs(dev, ABS_MT_POSITION_X, x); | |
6de58dd6 | 526 | input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(y)); |
fec6e525 HR |
527 | } |
528 | } | |
529 | ||
530 | static void synaptics_report_semi_mt_data(struct input_dev *dev, | |
531 | const struct synaptics_hw_state *a, | |
532 | const struct synaptics_hw_state *b, | |
533 | int num_fingers) | |
534 | { | |
535 | if (num_fingers >= 2) { | |
bea9f0ff DK |
536 | synaptics_report_semi_mt_slot(dev, 0, true, min(a->x, b->x), |
537 | min(a->y, b->y)); | |
538 | synaptics_report_semi_mt_slot(dev, 1, true, max(a->x, b->x), | |
539 | max(a->y, b->y)); | |
fec6e525 | 540 | } else if (num_fingers == 1) { |
bea9f0ff DK |
541 | synaptics_report_semi_mt_slot(dev, 0, true, a->x, a->y); |
542 | synaptics_report_semi_mt_slot(dev, 1, false, 0, 0); | |
fec6e525 | 543 | } else { |
bea9f0ff DK |
544 | synaptics_report_semi_mt_slot(dev, 0, false, 0, 0); |
545 | synaptics_report_semi_mt_slot(dev, 1, false, 0, 0); | |
fec6e525 | 546 | } |
1da177e4 LT |
547 | } |
548 | ||
3cdfee9e DK |
549 | static void synaptics_report_buttons(struct psmouse *psmouse, |
550 | const struct synaptics_hw_state *hw) | |
551 | { | |
552 | struct input_dev *dev = psmouse->dev; | |
553 | struct synaptics_data *priv = psmouse->private; | |
554 | int i; | |
555 | ||
556 | input_report_key(dev, BTN_LEFT, hw->left); | |
557 | input_report_key(dev, BTN_RIGHT, hw->right); | |
558 | ||
559 | if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) | |
560 | input_report_key(dev, BTN_MIDDLE, hw->middle); | |
561 | ||
562 | if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) { | |
563 | input_report_key(dev, BTN_FORWARD, hw->up); | |
564 | input_report_key(dev, BTN_BACK, hw->down); | |
565 | } | |
566 | ||
567 | for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++) | |
568 | input_report_key(dev, BTN_0 + i, hw->ext_buttons & (1 << i)); | |
569 | } | |
570 | ||
571 | static void synaptics_report_slot(struct input_dev *dev, int slot, | |
572 | const struct synaptics_hw_state *hw) | |
573 | { | |
574 | input_mt_slot(dev, slot); | |
575 | input_mt_report_slot_state(dev, MT_TOOL_FINGER, (hw != NULL)); | |
576 | if (!hw) | |
577 | return; | |
578 | ||
579 | input_report_abs(dev, ABS_MT_POSITION_X, hw->x); | |
580 | input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(hw->y)); | |
581 | input_report_abs(dev, ABS_MT_PRESSURE, hw->z); | |
582 | } | |
583 | ||
584 | static void synaptics_report_mt_data(struct psmouse *psmouse, | |
585 | int count, | |
586 | const struct synaptics_hw_state *sgm) | |
587 | { | |
588 | struct input_dev *dev = psmouse->dev; | |
589 | struct synaptics_data *priv = psmouse->private; | |
590 | struct synaptics_hw_state *agm = &priv->agm; | |
591 | ||
592 | switch (count) { | |
593 | case 0: | |
594 | synaptics_report_slot(dev, 0, NULL); | |
595 | synaptics_report_slot(dev, 1, NULL); | |
596 | break; | |
597 | case 1: | |
598 | synaptics_report_slot(dev, 0, sgm); | |
599 | synaptics_report_slot(dev, 1, NULL); | |
600 | break; | |
601 | case 2: | |
602 | case 3: /* Fall-through case */ | |
603 | synaptics_report_slot(dev, 0, sgm); | |
604 | synaptics_report_slot(dev, 1, agm); | |
605 | break; | |
606 | } | |
607 | ||
608 | /* Don't use active slot count to generate BTN_TOOL events. */ | |
609 | input_mt_report_pointer_emulation(dev, false); | |
610 | ||
611 | /* Send the number of fingers reported by touchpad itself. */ | |
612 | input_mt_report_finger_count(dev, count); | |
613 | ||
614 | synaptics_report_buttons(psmouse, sgm); | |
615 | ||
616 | input_sync(dev); | |
617 | } | |
618 | ||
619 | static void synaptics_image_sensor_process(struct psmouse *psmouse, | |
620 | struct synaptics_hw_state *sgm) | |
621 | { | |
622 | int count; | |
623 | ||
624 | if (sgm->z == 0) | |
625 | count = 0; | |
626 | else if (sgm->w >= 4) | |
627 | count = 1; | |
628 | else if (sgm->w == 0) | |
629 | count = 2; | |
630 | else | |
631 | count = 3; | |
632 | ||
633 | /* Send resulting input events to user space */ | |
634 | synaptics_report_mt_data(psmouse, count, sgm); | |
635 | } | |
636 | ||
1da177e4 LT |
637 | /* |
638 | * called for each full received packet from the touchpad | |
639 | */ | |
640 | static void synaptics_process_packet(struct psmouse *psmouse) | |
641 | { | |
2e5b636b | 642 | struct input_dev *dev = psmouse->dev; |
1da177e4 LT |
643 | struct synaptics_data *priv = psmouse->private; |
644 | struct synaptics_hw_state hw; | |
645 | int num_fingers; | |
646 | int finger_width; | |
1da177e4 | 647 | |
fec6e525 HR |
648 | if (synaptics_parse_hw_state(psmouse->packet, priv, &hw)) |
649 | return; | |
1da177e4 | 650 | |
3cdfee9e DK |
651 | if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) { |
652 | synaptics_image_sensor_process(psmouse, &hw); | |
653 | return; | |
654 | } | |
655 | ||
1da177e4 LT |
656 | if (hw.scroll) { |
657 | priv->scroll += hw.scroll; | |
658 | ||
659 | while (priv->scroll >= 4) { | |
660 | input_report_key(dev, BTN_BACK, !hw.down); | |
661 | input_sync(dev); | |
662 | input_report_key(dev, BTN_BACK, hw.down); | |
663 | input_sync(dev); | |
664 | priv->scroll -= 4; | |
665 | } | |
666 | while (priv->scroll <= -4) { | |
667 | input_report_key(dev, BTN_FORWARD, !hw.up); | |
668 | input_sync(dev); | |
669 | input_report_key(dev, BTN_FORWARD, hw.up); | |
670 | input_sync(dev); | |
671 | priv->scroll += 4; | |
672 | } | |
673 | return; | |
674 | } | |
675 | ||
4f56ce92 | 676 | if (hw.z > 0 && hw.x > 1) { |
1da177e4 LT |
677 | num_fingers = 1; |
678 | finger_width = 5; | |
679 | if (SYN_CAP_EXTENDED(priv->capabilities)) { | |
680 | switch (hw.w) { | |
681 | case 0 ... 1: | |
682 | if (SYN_CAP_MULTIFINGER(priv->capabilities)) | |
683 | num_fingers = hw.w + 2; | |
684 | break; | |
685 | case 2: | |
686 | if (SYN_MODEL_PEN(priv->model_id)) | |
687 | ; /* Nothing, treat a pen as a single finger */ | |
688 | break; | |
689 | case 4 ... 15: | |
690 | if (SYN_CAP_PALMDETECT(priv->capabilities)) | |
691 | finger_width = hw.w; | |
692 | break; | |
693 | } | |
694 | } | |
695 | } else { | |
696 | num_fingers = 0; | |
697 | finger_width = 0; | |
698 | } | |
699 | ||
fec6e525 | 700 | if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) |
7afdb842 DK |
701 | synaptics_report_semi_mt_data(dev, &hw, &priv->agm, |
702 | num_fingers); | |
fec6e525 | 703 | |
1da177e4 LT |
704 | /* Post events |
705 | * BTN_TOUCH has to be first as mousedev relies on it when doing | |
706 | * absolute -> relative conversion | |
707 | */ | |
708 | if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1); | |
709 | if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0); | |
710 | ||
4f56ce92 | 711 | if (num_fingers > 0) { |
1da177e4 | 712 | input_report_abs(dev, ABS_X, hw.x); |
6de58dd6 | 713 | input_report_abs(dev, ABS_Y, synaptics_invert_y(hw.y)); |
1da177e4 LT |
714 | } |
715 | input_report_abs(dev, ABS_PRESSURE, hw.z); | |
716 | ||
2a8e7710 CB |
717 | if (SYN_CAP_PALMDETECT(priv->capabilities)) |
718 | input_report_abs(dev, ABS_TOOL_WIDTH, finger_width); | |
719 | ||
1da177e4 | 720 | input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1); |
e42b6646 PH |
721 | if (SYN_CAP_MULTIFINGER(priv->capabilities)) { |
722 | input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2); | |
723 | input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3); | |
724 | } | |
725 | ||
3cdfee9e | 726 | synaptics_report_buttons(psmouse, &hw); |
1da177e4 LT |
727 | |
728 | input_sync(dev); | |
729 | } | |
730 | ||
731 | static int synaptics_validate_byte(unsigned char packet[], int idx, unsigned char pkt_type) | |
732 | { | |
e38de678 HD |
733 | static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 }; |
734 | static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 }; | |
735 | static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 }; | |
736 | static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 }; | |
737 | static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 }; | |
1da177e4 LT |
738 | |
739 | if (idx < 0 || idx > 4) | |
740 | return 0; | |
741 | ||
742 | switch (pkt_type) { | |
1da177e4 | 743 | |
a62f0d27 DT |
744 | case SYN_NEWABS: |
745 | case SYN_NEWABS_RELAXED: | |
746 | return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx]; | |
1da177e4 | 747 | |
a62f0d27 DT |
748 | case SYN_NEWABS_STRICT: |
749 | return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx]; | |
1da177e4 | 750 | |
a62f0d27 DT |
751 | case SYN_OLDABS: |
752 | return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx]; | |
753 | ||
754 | default: | |
755 | printk(KERN_ERR "synaptics: unknown packet type %d\n", pkt_type); | |
756 | return 0; | |
1da177e4 LT |
757 | } |
758 | } | |
759 | ||
760 | static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse) | |
761 | { | |
762 | int i; | |
763 | ||
764 | for (i = 0; i < 5; i++) | |
765 | if (!synaptics_validate_byte(psmouse->packet, i, SYN_NEWABS_STRICT)) { | |
766 | printk(KERN_INFO "synaptics: using relaxed packet validation\n"); | |
767 | return SYN_NEWABS_RELAXED; | |
768 | } | |
769 | ||
770 | return SYN_NEWABS_STRICT; | |
771 | } | |
772 | ||
7d12e780 | 773 | static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse) |
1da177e4 | 774 | { |
1da177e4 LT |
775 | struct synaptics_data *priv = psmouse->private; |
776 | ||
1da177e4 LT |
777 | if (psmouse->pktcnt >= 6) { /* Full packet received */ |
778 | if (unlikely(priv->pkt_type == SYN_NEWABS)) | |
779 | priv->pkt_type = synaptics_detect_pkt_type(psmouse); | |
780 | ||
a8b3c0f5 DT |
781 | if (SYN_CAP_PASS_THROUGH(priv->capabilities) && |
782 | synaptics_is_pt_packet(psmouse->packet)) { | |
783 | if (priv->pt_port) | |
784 | synaptics_pass_pt_packet(priv->pt_port, psmouse->packet); | |
1da177e4 LT |
785 | } else |
786 | synaptics_process_packet(psmouse); | |
787 | ||
788 | return PSMOUSE_FULL_PACKET; | |
789 | } | |
790 | ||
791 | return synaptics_validate_byte(psmouse->packet, psmouse->pktcnt - 1, priv->pkt_type) ? | |
792 | PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA; | |
793 | } | |
794 | ||
795 | /***************************************************************************** | |
796 | * Driver initialization/cleanup functions | |
797 | ****************************************************************************/ | |
85615476 DK |
798 | static void set_abs_position_params(struct input_dev *dev, |
799 | struct synaptics_data *priv, int x_code, | |
800 | int y_code) | |
1da177e4 | 801 | { |
85615476 DK |
802 | int x_min = priv->x_min ?: XMIN_NOMINAL; |
803 | int x_max = priv->x_max ?: XMAX_NOMINAL; | |
804 | int y_min = priv->y_min ?: YMIN_NOMINAL; | |
805 | int y_max = priv->y_max ?: YMAX_NOMINAL; | |
a9f0b79e DK |
806 | int fuzz = SYN_CAP_REDUCED_FILTERING(priv->ext_cap_0c) ? |
807 | SYN_REDUCED_FILTER_FUZZ : 0; | |
1da177e4 | 808 | |
85615476 DK |
809 | input_set_abs_params(dev, x_code, x_min, x_max, fuzz, 0); |
810 | input_set_abs_params(dev, y_code, y_min, y_max, fuzz, 0); | |
811 | input_abs_set_res(dev, x_code, priv->x_res); | |
812 | input_abs_set_res(dev, y_code, priv->y_res); | |
813 | } | |
814 | ||
815 | static void set_input_params(struct input_dev *dev, struct synaptics_data *priv) | |
816 | { | |
817 | int i; | |
818 | ||
c14890a8 HR |
819 | __set_bit(INPUT_PROP_POINTER, dev->propbit); |
820 | ||
b7802c5c | 821 | __set_bit(EV_ABS, dev->evbit); |
85615476 | 822 | set_abs_position_params(dev, priv, ABS_X, ABS_Y); |
1da177e4 | 823 | input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0); |
2a8e7710 | 824 | |
3cdfee9e DK |
825 | if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) { |
826 | input_mt_init_slots(dev, 2); | |
827 | set_abs_position_params(dev, priv, ABS_MT_POSITION_X, | |
828 | ABS_MT_POSITION_Y); | |
829 | /* Image sensors can report per-contact pressure */ | |
830 | input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0); | |
831 | } else if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) { | |
832 | /* Non-image sensors with AGM use semi-mt */ | |
fec6e525 HR |
833 | __set_bit(INPUT_PROP_SEMI_MT, dev->propbit); |
834 | input_mt_init_slots(dev, 2); | |
85615476 DK |
835 | set_abs_position_params(dev, priv, ABS_MT_POSITION_X, |
836 | ABS_MT_POSITION_Y); | |
fec6e525 HR |
837 | } |
838 | ||
2a8e7710 | 839 | if (SYN_CAP_PALMDETECT(priv->capabilities)) |
58fb0218 | 840 | input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0); |
1da177e4 | 841 | |
b7802c5c DT |
842 | __set_bit(EV_KEY, dev->evbit); |
843 | __set_bit(BTN_TOUCH, dev->keybit); | |
844 | __set_bit(BTN_TOOL_FINGER, dev->keybit); | |
845 | __set_bit(BTN_LEFT, dev->keybit); | |
846 | __set_bit(BTN_RIGHT, dev->keybit); | |
1da177e4 | 847 | |
e42b6646 | 848 | if (SYN_CAP_MULTIFINGER(priv->capabilities)) { |
b7802c5c DT |
849 | __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit); |
850 | __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit); | |
e42b6646 PH |
851 | } |
852 | ||
1da177e4 | 853 | if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) |
b7802c5c | 854 | __set_bit(BTN_MIDDLE, dev->keybit); |
1da177e4 LT |
855 | |
856 | if (SYN_CAP_FOUR_BUTTON(priv->capabilities) || | |
857 | SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) { | |
b7802c5c DT |
858 | __set_bit(BTN_FORWARD, dev->keybit); |
859 | __set_bit(BTN_BACK, dev->keybit); | |
1da177e4 LT |
860 | } |
861 | ||
862 | for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++) | |
b7802c5c | 863 | __set_bit(BTN_0 + i, dev->keybit); |
1da177e4 | 864 | |
b7802c5c DT |
865 | __clear_bit(EV_REL, dev->evbit); |
866 | __clear_bit(REL_X, dev->relbit); | |
867 | __clear_bit(REL_Y, dev->relbit); | |
ec20a022 | 868 | |
5f57d67d | 869 | if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) { |
c14890a8 | 870 | __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit); |
5f57d67d TI |
871 | /* Clickpads report only left button */ |
872 | __clear_bit(BTN_RIGHT, dev->keybit); | |
873 | __clear_bit(BTN_MIDDLE, dev->keybit); | |
874 | } | |
1da177e4 LT |
875 | } |
876 | ||
1da177e4 LT |
877 | static void synaptics_disconnect(struct psmouse *psmouse) |
878 | { | |
879 | synaptics_reset(psmouse); | |
880 | kfree(psmouse->private); | |
881 | psmouse->private = NULL; | |
882 | } | |
883 | ||
884 | static int synaptics_reconnect(struct psmouse *psmouse) | |
885 | { | |
886 | struct synaptics_data *priv = psmouse->private; | |
887 | struct synaptics_data old_priv = *priv; | |
c63fe0a4 APF |
888 | int retry = 0; |
889 | int error; | |
1da177e4 | 890 | |
c63fe0a4 APF |
891 | do { |
892 | psmouse_reset(psmouse); | |
893 | error = synaptics_detect(psmouse, 0); | |
894 | } while (error && ++retry < 3); | |
4d368456 | 895 | |
c63fe0a4 | 896 | if (error) |
1da177e4 LT |
897 | return -1; |
898 | ||
c63fe0a4 APF |
899 | if (retry > 1) |
900 | printk(KERN_DEBUG "Synaptics reconnected after %d tries\n", | |
901 | retry); | |
902 | ||
1da177e4 LT |
903 | if (synaptics_query_hardware(psmouse)) { |
904 | printk(KERN_ERR "Unable to query Synaptics hardware.\n"); | |
905 | return -1; | |
906 | } | |
907 | ||
1da177e4 LT |
908 | if (synaptics_set_absolute_mode(psmouse)) { |
909 | printk(KERN_ERR "Unable to initialize Synaptics hardware.\n"); | |
910 | return -1; | |
911 | } | |
912 | ||
fec6e525 HR |
913 | if (synaptics_set_advanced_gesture_mode(psmouse)) { |
914 | printk(KERN_ERR "Advanced gesture mode reconnect failed.\n"); | |
915 | return -1; | |
916 | } | |
917 | ||
baddf589 APF |
918 | if (old_priv.identity != priv->identity || |
919 | old_priv.model_id != priv->model_id || | |
920 | old_priv.capabilities != priv->capabilities || | |
921 | old_priv.ext_cap != priv->ext_cap) { | |
922 | printk(KERN_ERR "Synaptics hardware appears to be different: " | |
923 | "id(%ld-%ld), model(%ld-%ld), caps(%lx-%lx), ext(%lx-%lx).\n", | |
924 | old_priv.identity, priv->identity, | |
925 | old_priv.model_id, priv->model_id, | |
926 | old_priv.capabilities, priv->capabilities, | |
927 | old_priv.ext_cap, priv->ext_cap); | |
928 | return -1; | |
929 | } | |
930 | ||
1da177e4 LT |
931 | return 0; |
932 | } | |
933 | ||
7705d548 DT |
934 | static bool impaired_toshiba_kbc; |
935 | ||
936 | static const struct dmi_system_id __initconst toshiba_dmi_table[] = { | |
937 | #if defined(CONFIG_DMI) && defined(CONFIG_X86) | |
1da177e4 | 938 | { |
9961e259 | 939 | /* Toshiba Satellite */ |
1da177e4 LT |
940 | .matches = { |
941 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), | |
53a2670c | 942 | DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"), |
1da177e4 LT |
943 | }, |
944 | }, | |
9ba5eaaf | 945 | { |
9961e259 | 946 | /* Toshiba Dynabook */ |
9ba5eaaf SH |
947 | .matches = { |
948 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), | |
53a2670c RT |
949 | DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"), |
950 | }, | |
951 | }, | |
952 | { | |
9961e259 | 953 | /* Toshiba Portege M300 */ |
53a2670c RT |
954 | .matches = { |
955 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), | |
956 | DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"), | |
9ba5eaaf | 957 | }, |
5f5eeff4 DT |
958 | |
959 | }, | |
960 | { | |
9961e259 | 961 | /* Toshiba Portege M300 */ |
5f5eeff4 DT |
962 | .matches = { |
963 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), | |
964 | DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"), | |
965 | DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"), | |
966 | }, | |
967 | ||
9ba5eaaf | 968 | }, |
1da177e4 | 969 | #endif |
70874867 | 970 | { } |
7705d548 DT |
971 | }; |
972 | ||
ef8313bb AS |
973 | static bool broken_olpc_ec; |
974 | ||
975 | static const struct dmi_system_id __initconst olpc_dmi_table[] = { | |
976 | #if defined(CONFIG_DMI) && defined(CONFIG_OLPC) | |
977 | { | |
978 | /* OLPC XO-1 or XO-1.5 */ | |
979 | .matches = { | |
980 | DMI_MATCH(DMI_SYS_VENDOR, "OLPC"), | |
981 | DMI_MATCH(DMI_PRODUCT_NAME, "XO"), | |
982 | }, | |
983 | }, | |
ef8313bb | 984 | #endif |
70874867 | 985 | { } |
ef8313bb AS |
986 | }; |
987 | ||
7705d548 DT |
988 | void __init synaptics_module_init(void) |
989 | { | |
990 | impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table); | |
ef8313bb | 991 | broken_olpc_ec = dmi_check_system(olpc_dmi_table); |
7705d548 | 992 | } |
1da177e4 LT |
993 | |
994 | int synaptics_init(struct psmouse *psmouse) | |
995 | { | |
996 | struct synaptics_data *priv; | |
997 | ||
ef8313bb AS |
998 | /* |
999 | * The OLPC XO has issues with Synaptics' absolute mode; similarly to | |
1000 | * the HGPK, it quickly degrades and the hardware becomes jumpy and | |
1001 | * overly sensitive. Not only that, but the constant packet spew | |
1002 | * (even at a lowered 40pps rate) overloads the EC such that key | |
1003 | * presses on the keyboard are missed. Given all of that, don't | |
1004 | * even attempt to use Synaptics mode. Relative mode seems to work | |
1005 | * just fine. | |
1006 | */ | |
1007 | if (broken_olpc_ec) { | |
1008 | printk(KERN_INFO "synaptics: OLPC XO detected, not enabling Synaptics protocol.\n"); | |
1009 | return -ENODEV; | |
1010 | } | |
1011 | ||
b39787a9 | 1012 | psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL); |
1da177e4 | 1013 | if (!priv) |
6792cbbb | 1014 | return -ENOMEM; |
1da177e4 | 1015 | |
4d368456 AW |
1016 | psmouse_reset(psmouse); |
1017 | ||
1da177e4 LT |
1018 | if (synaptics_query_hardware(psmouse)) { |
1019 | printk(KERN_ERR "Unable to query Synaptics hardware.\n"); | |
1020 | goto init_fail; | |
1021 | } | |
1022 | ||
1023 | if (synaptics_set_absolute_mode(psmouse)) { | |
1024 | printk(KERN_ERR "Unable to initialize Synaptics hardware.\n"); | |
1025 | goto init_fail; | |
1026 | } | |
1027 | ||
fec6e525 HR |
1028 | if (synaptics_set_advanced_gesture_mode(psmouse)) { |
1029 | printk(KERN_ERR "Advanced gesture mode init failed.\n"); | |
1030 | goto init_fail; | |
1031 | } | |
1032 | ||
1da177e4 LT |
1033 | priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS; |
1034 | ||
5f57d67d | 1035 | printk(KERN_INFO "Synaptics Touchpad, model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx\n", |
409b7506 DT |
1036 | SYN_ID_MODEL(priv->identity), |
1037 | SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity), | |
5f57d67d | 1038 | priv->model_id, priv->capabilities, priv->ext_cap, priv->ext_cap_0c); |
409b7506 | 1039 | |
2e5b636b | 1040 | set_input_params(psmouse->dev, priv); |
1da177e4 | 1041 | |
887cc127 DT |
1042 | /* |
1043 | * Encode touchpad model so that it can be used to set | |
1044 | * input device->id.version and be visible to userspace. | |
1045 | * Because version is __u16 we have to drop something. | |
1046 | * Hardware info bits seem to be good candidates as they | |
1047 | * are documented to be for Synaptics corp. internal use. | |
1048 | */ | |
1049 | psmouse->model = ((priv->model_id & 0x00ff0000) >> 8) | | |
1050 | (priv->model_id & 0x000000ff); | |
1051 | ||
1da177e4 LT |
1052 | psmouse->protocol_handler = synaptics_process_byte; |
1053 | psmouse->set_rate = synaptics_set_rate; | |
1054 | psmouse->disconnect = synaptics_disconnect; | |
1055 | psmouse->reconnect = synaptics_reconnect; | |
a1cec061 | 1056 | psmouse->cleanup = synaptics_reset; |
1da177e4 | 1057 | psmouse->pktsize = 6; |
f0d5c6f4 DT |
1058 | /* Synaptics can usually stay in sync without extra help */ |
1059 | psmouse->resync_time = 0; | |
1da177e4 LT |
1060 | |
1061 | if (SYN_CAP_PASS_THROUGH(priv->capabilities)) | |
1062 | synaptics_pt_create(psmouse); | |
1063 | ||
1da177e4 LT |
1064 | /* |
1065 | * Toshiba's KBC seems to have trouble handling data from | |
7ee99161 AS |
1066 | * Synaptics at full rate. Switch to a lower rate (roughly |
1067 | * the same rate as a standard PS/2 mouse). | |
1da177e4 | 1068 | */ |
7705d548 | 1069 | if (psmouse->rate >= 80 && impaired_toshiba_kbc) { |
9ba5eaaf SH |
1070 | printk(KERN_INFO "synaptics: Toshiba %s detected, limiting rate to 40pps.\n", |
1071 | dmi_get_system_info(DMI_PRODUCT_NAME)); | |
1da177e4 LT |
1072 | psmouse->rate = 40; |
1073 | } | |
1da177e4 LT |
1074 | |
1075 | return 0; | |
1076 | ||
1077 | init_fail: | |
1078 | kfree(priv); | |
1079 | return -1; | |
1080 | } | |
1081 | ||
e4e6efd2 DD |
1082 | bool synaptics_supported(void) |
1083 | { | |
1084 | return true; | |
1085 | } | |
1086 | ||
55e3d922 AS |
1087 | #else /* CONFIG_MOUSE_PS2_SYNAPTICS */ |
1088 | ||
7705d548 DT |
1089 | void __init synaptics_module_init(void) |
1090 | { | |
1091 | } | |
1092 | ||
55e3d922 AS |
1093 | int synaptics_init(struct psmouse *psmouse) |
1094 | { | |
1095 | return -ENOSYS; | |
1096 | } | |
1097 | ||
e4e6efd2 DD |
1098 | bool synaptics_supported(void) |
1099 | { | |
1100 | return false; | |
1101 | } | |
1102 | ||
55e3d922 | 1103 | #endif /* CONFIG_MOUSE_PS2_SYNAPTICS */ |