Rev 523 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
523 | mauro | 1 | /* |
2 | * Synaptics TouchPad PS/2 mouse driver |
||
3 | * |
||
4 | * 2003 Dmitry Torokhov <dtor@mail.ru> |
||
5 | * Added support for pass-through port |
||
6 | * |
||
7 | * 2003 Peter Osterlund <petero2@telia.com> |
||
8 | * Ported to 2.5 input device infrastructure. |
||
9 | * |
||
10 | * Copyright (C) 2001 Stefan Gmeiner <riddlebox@freesurf.ch> |
||
11 | * start merging tpconfig and gpm code to a xfree-input module |
||
12 | * adding some changes and extensions (ex. 3rd and 4th button) |
||
13 | * |
||
14 | * Copyright (c) 1997 C. Scott Ananian <cananian@alumni.priceton.edu> |
||
15 | * Copyright (c) 1998-2000 Bruce Kalk <kall@compass.com> |
||
16 | * code for the special synaptics commands (from the tpconfig-source) |
||
17 | * |
||
18 | * This program is free software; you can redistribute it and/or modify it |
||
19 | * under the terms of the GNU General Public License version 2 as published by |
||
20 | * the Free Software Foundation. |
||
21 | * |
||
22 | * Trademarks are the property of their respective owners. |
||
23 | */ |
||
24 | |||
25 | #include <linuxcomp.h> |
||
26 | |||
27 | #include <linux/module.h> |
||
28 | #include <linux/input.h> |
||
29 | #include <linux/serio.h> |
||
30 | #include "psmouse.h" |
||
31 | #include "synaptics.h" |
||
32 | |||
33 | /* |
||
34 | * The x/y limits are taken from the Synaptics TouchPad interfacing Guide, |
||
35 | * section 2.3.2, which says that they should be valid regardless of the |
||
36 | * actual size of the sensor. |
||
37 | */ |
||
38 | #define XMIN_NOMINAL 1472 |
||
39 | #define XMAX_NOMINAL 5472 |
||
40 | #define YMIN_NOMINAL 1408 |
||
41 | #define YMAX_NOMINAL 4448 |
||
42 | |||
43 | /***************************************************************************** |
||
44 | * Synaptics communications functions |
||
45 | ****************************************************************************/ |
||
46 | |||
47 | /* |
||
48 | * Use the Synaptics extended ps/2 syntax to write a special command byte. |
||
49 | * special command: 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu |
||
50 | * is the command. A 0xF3 or 0xE9 must follow (see synaptics_send_cmd |
||
51 | * and synaptics_mode_cmd) |
||
52 | */ |
||
53 | static int synaptics_special_cmd(struct psmouse *psmouse, unsigned char command) |
||
54 | { |
||
55 | int i; |
||
56 | |||
57 | if (psmouse_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11)) |
||
58 | return -1; |
||
59 | |||
60 | for (i = 6; i >= 0; i -= 2) { |
||
61 | unsigned char d = (command >> i) & 3; |
||
62 | if (psmouse_command(psmouse, &d, PSMOUSE_CMD_SETRES)) |
||
63 | return -1; |
||
64 | } |
||
65 | |||
66 | return 0; |
||
67 | } |
||
68 | |||
69 | /* |
||
70 | * Send a command to the synpatics touchpad by special commands |
||
71 | */ |
||
72 | static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param) |
||
73 | { |
||
74 | if (synaptics_special_cmd(psmouse, c)) |
||
75 | return -1; |
||
76 | if (psmouse_command(psmouse, param, PSMOUSE_CMD_GETINFO)) |
||
77 | return -1; |
||
78 | return 0; |
||
79 | } |
||
80 | |||
81 | /* |
||
82 | * Set the synaptics touchpad mode byte by special commands |
||
83 | */ |
||
84 | static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode) |
||
85 | { |
||
86 | unsigned char param[1]; |
||
87 | |||
88 | if (synaptics_special_cmd(psmouse, mode)) |
||
89 | return -1; |
||
90 | param[0] = SYN_PS_SET_MODE2; |
||
91 | if (psmouse_command(psmouse, param, PSMOUSE_CMD_SETRATE)) |
||
92 | return -1; |
||
93 | return 0; |
||
94 | } |
||
95 | |||
96 | static int synaptics_reset(struct psmouse *psmouse) |
||
97 | { |
||
98 | unsigned char r[2]; |
||
99 | |||
100 | if (psmouse_command(psmouse, r, PSMOUSE_CMD_RESET_BAT)) |
||
101 | return -1; |
||
102 | if (r[0] == PSMOUSE_RET_BAT && r[1] == PSMOUSE_RET_ID) |
||
103 | return 0; |
||
104 | return -1; |
||
105 | } |
||
106 | |||
107 | /* |
||
108 | * Read the model-id bytes from the touchpad |
||
109 | * see also SYN_MODEL_* macros |
||
110 | */ |
||
111 | static int synaptics_model_id(struct psmouse *psmouse) |
||
112 | { |
||
113 | struct synaptics_data *priv = psmouse->private; |
||
114 | unsigned char mi[3]; |
||
115 | |||
116 | if (synaptics_send_cmd(psmouse, SYN_QUE_MODEL, mi)) |
||
117 | return -1; |
||
118 | priv->model_id = (mi[0]<<16) | (mi[1]<<8) | mi[2]; |
||
119 | return 0; |
||
120 | } |
||
121 | |||
122 | /* |
||
123 | * Read the capability-bits from the touchpad |
||
124 | * see also the SYN_CAP_* macros |
||
125 | */ |
||
126 | static int synaptics_capability(struct psmouse *psmouse) |
||
127 | { |
||
128 | struct synaptics_data *priv = psmouse->private; |
||
129 | unsigned char cap[3]; |
||
130 | |||
131 | if (synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap)) |
||
132 | return -1; |
||
133 | priv->capabilities = (cap[0]<<16) | (cap[1]<<8) | cap[2]; |
||
134 | priv->ext_cap = 0; |
||
135 | if (!SYN_CAP_VALID(priv->capabilities)) |
||
136 | return -1; |
||
137 | |||
138 | if (SYN_EXT_CAP_REQUESTS(priv->capabilities)) { |
||
139 | if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB, cap)) { |
||
140 | printk(KERN_ERR "Synaptics claims to have extended capabilities," |
||
141 | " but I'm not able to read them."); |
||
142 | } else |
||
143 | priv->ext_cap = (cap[0]<<16) | (cap[1]<<8) | cap[2]; |
||
144 | } |
||
145 | return 0; |
||
146 | } |
||
147 | |||
148 | /* |
||
149 | * Identify Touchpad |
||
150 | * See also the SYN_ID_* macros |
||
151 | */ |
||
152 | static int synaptics_identify(struct psmouse *psmouse) |
||
153 | { |
||
154 | struct synaptics_data *priv = psmouse->private; |
||
155 | unsigned char id[3]; |
||
156 | |||
157 | if (synaptics_send_cmd(psmouse, SYN_QUE_IDENTIFY, id)) |
||
158 | return -1; |
||
159 | priv->identity = (id[0]<<16) | (id[1]<<8) | id[2]; |
||
160 | if (SYN_ID_IS_SYNAPTICS(priv->identity)) |
||
161 | return 0; |
||
162 | return -1; |
||
163 | } |
||
164 | |||
165 | static void print_ident(struct synaptics_data *priv) |
||
166 | { |
||
167 | printk(KERN_INFO "Synaptics Touchpad, model: %ld\n", SYN_ID_MODEL(priv->identity)); |
||
168 | printk(KERN_INFO " Firmware: %ld.%ld\n", SYN_ID_MAJOR(priv->identity), |
||
169 | SYN_ID_MINOR(priv->identity)); |
||
170 | if (SYN_MODEL_ROT180(priv->model_id)) |
||
171 | printk(KERN_INFO " 180 degree mounted touchpad\n"); |
||
172 | if (SYN_MODEL_PORTRAIT(priv->model_id)) |
||
173 | printk(KERN_INFO " portrait touchpad\n"); |
||
174 | printk(KERN_INFO " Sensor: %ld\n", SYN_MODEL_SENSOR(priv->model_id)); |
||
175 | if (SYN_MODEL_NEWABS(priv->model_id)) |
||
176 | printk(KERN_INFO " new absolute packet format\n"); |
||
177 | if (SYN_MODEL_PEN(priv->model_id)) |
||
178 | printk(KERN_INFO " pen detection\n"); |
||
179 | |||
180 | if (SYN_CAP_EXTENDED(priv->capabilities)) { |
||
181 | printk(KERN_INFO " Touchpad has extended capability bits\n"); |
||
182 | if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) && |
||
183 | SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) <= 8) |
||
184 | printk(KERN_INFO " -> %d multi-buttons, i.e. besides standard buttons\n", |
||
185 | (int)(SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap))); |
||
186 | else if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) |
||
187 | printk(KERN_INFO " -> four buttons\n"); |
||
188 | if (SYN_CAP_MULTIFINGER(priv->capabilities)) |
||
189 | printk(KERN_INFO " -> multifinger detection\n"); |
||
190 | if (SYN_CAP_PALMDETECT(priv->capabilities)) |
||
191 | printk(KERN_INFO " -> palm detection\n"); |
||
192 | if (SYN_CAP_PASS_THROUGH(priv->capabilities)) |
||
193 | printk(KERN_INFO " -> pass-through port\n"); |
||
194 | } |
||
195 | } |
||
196 | |||
197 | static int synaptics_query_hardware(struct psmouse *psmouse) |
||
198 | { |
||
199 | struct synaptics_data *priv = psmouse->private; |
||
200 | int retries = 0; |
||
201 | int mode; |
||
202 | |||
203 | while ((retries++ < 3) && synaptics_reset(psmouse)) |
||
204 | printk(KERN_ERR "synaptics reset failed\n"); |
||
205 | |||
206 | if (synaptics_identify(psmouse)) |
||
207 | return -1; |
||
208 | if (synaptics_model_id(psmouse)) |
||
209 | return -1; |
||
210 | if (synaptics_capability(psmouse)) |
||
211 | return -1; |
||
212 | |||
213 | mode = SYN_BIT_ABSOLUTE_MODE | SYN_BIT_HIGH_RATE; |
||
214 | if (SYN_ID_MAJOR(priv->identity) >= 4) |
||
215 | mode |= SYN_BIT_DISABLE_GESTURE; |
||
216 | if (SYN_CAP_EXTENDED(priv->capabilities)) |
||
217 | mode |= SYN_BIT_W_MODE; |
||
218 | if (synaptics_mode_cmd(psmouse, mode)) |
||
219 | return -1; |
||
220 | |||
221 | return 0; |
||
222 | } |
||
223 | |||
224 | /***************************************************************************** |
||
225 | * Synaptics pass-through PS/2 port support |
||
226 | ****************************************************************************/ |
||
227 | static int synaptics_pt_open(struct serio *port) |
||
228 | { |
||
229 | return 0; |
||
230 | } |
||
231 | |||
232 | static void synaptics_pt_close(struct serio *port) |
||
233 | { |
||
234 | } |
||
235 | |||
236 | static int synaptics_pt_write(struct serio *port, unsigned char c) |
||
237 | { |
||
238 | struct psmouse *parent = port->driver; |
||
239 | char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */ |
||
240 | |||
241 | if (synaptics_special_cmd(parent, c)) |
||
242 | return -1; |
||
243 | if (psmouse_command(parent, &rate_param, PSMOUSE_CMD_SETRATE)) |
||
244 | return -1; |
||
245 | return 0; |
||
246 | } |
||
247 | |||
248 | static inline int synaptics_is_pt_packet(unsigned char *buf) |
||
249 | { |
||
250 | return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4; |
||
251 | } |
||
252 | |||
253 | static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet) |
||
254 | { |
||
255 | struct psmouse *child = ptport->private; |
||
256 | |||
257 | if (child) { |
||
258 | if (child->state == PSMOUSE_ACTIVATED) { |
||
259 | serio_interrupt(ptport, packet[1], 0, NULL); |
||
260 | serio_interrupt(ptport, packet[4], 0, NULL); |
||
261 | serio_interrupt(ptport, packet[5], 0, NULL); |
||
262 | if (child->type >= PSMOUSE_GENPS) |
||
263 | serio_interrupt(ptport, packet[2], 0, NULL); |
||
264 | } else if (child->state != PSMOUSE_IGNORE) { |
||
265 | serio_interrupt(ptport, packet[1], 0, NULL); |
||
266 | } |
||
267 | } |
||
268 | } |
||
269 | |||
270 | int synaptics_pt_init(struct psmouse *psmouse) |
||
271 | { |
||
272 | struct synaptics_data *priv = psmouse->private; |
||
273 | struct serio *port; |
||
274 | struct psmouse *child; |
||
275 | |||
276 | if (psmouse->type != PSMOUSE_SYNAPTICS) |
||
277 | return -1; |
||
278 | if (!SYN_CAP_EXTENDED(priv->capabilities)) |
||
279 | return -1; |
||
280 | if (!SYN_CAP_PASS_THROUGH(priv->capabilities)) |
||
281 | return -1; |
||
282 | |||
283 | priv->ptport = port = kmalloc(sizeof(struct serio), GFP_KERNEL); |
||
284 | if (!port) { |
||
285 | printk(KERN_ERR "synaptics: not enough memory to allocate serio port\n"); |
||
286 | return -1; |
||
287 | } |
||
288 | |||
289 | memset(port, 0, sizeof(struct serio)); |
||
290 | port->type = SERIO_PS_PSTHRU; |
||
291 | port->name = "Synaptics pass-through"; |
||
292 | port->phys = "synaptics-pt/serio0"; |
||
293 | port->write = synaptics_pt_write; |
||
294 | port->open = synaptics_pt_open; |
||
295 | port->close = synaptics_pt_close; |
||
296 | port->driver = psmouse; |
||
297 | |||
298 | printk(KERN_INFO "serio: %s port at %s\n", port->name, psmouse->phys); |
||
299 | serio_register_slave_port(port); |
||
300 | |||
301 | /* adjust the touchpad to child's choice of protocol */ |
||
302 | child = port->private; |
||
303 | if (child && child->type >= PSMOUSE_GENPS) { |
||
304 | if (synaptics_mode_cmd(psmouse, (SYN_BIT_ABSOLUTE_MODE | |
||
305 | SYN_BIT_HIGH_RATE | |
||
306 | SYN_BIT_DISABLE_GESTURE | |
||
307 | SYN_BIT_FOUR_BYTE_CLIENT | |
||
308 | SYN_BIT_W_MODE))) |
||
309 | printk(KERN_INFO "synaptics: failed to enable 4-byte guest protocol\n"); |
||
310 | } |
||
311 | |||
312 | return 0; |
||
313 | } |
||
314 | |||
315 | /***************************************************************************** |
||
316 | * Driver initialization/cleanup functions |
||
317 | ****************************************************************************/ |
||
318 | |||
319 | static inline void set_abs_params(struct input_dev *dev, int axis, int min, int max, int fuzz, int flat) |
||
320 | { |
||
321 | dev->absmin[axis] = min; |
||
322 | dev->absmax[axis] = max; |
||
323 | dev->absfuzz[axis] = fuzz; |
||
324 | dev->absflat[axis] = flat; |
||
325 | |||
326 | set_bit(axis, dev->absbit); |
||
327 | } |
||
328 | |||
329 | static void set_input_params(struct input_dev *dev, struct synaptics_data *priv) |
||
330 | { |
||
331 | set_bit(EV_ABS, dev->evbit); |
||
332 | set_abs_params(dev, ABS_X, XMIN_NOMINAL, XMAX_NOMINAL, 0, 0); |
||
333 | set_abs_params(dev, ABS_Y, YMIN_NOMINAL, YMAX_NOMINAL, 0, 0); |
||
334 | set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0); |
||
335 | set_bit(ABS_TOOL_WIDTH, dev->absbit); |
||
336 | |||
337 | set_bit(EV_KEY, dev->evbit); |
||
338 | set_bit(BTN_TOUCH, dev->keybit); |
||
339 | set_bit(BTN_TOOL_FINGER, dev->keybit); |
||
340 | set_bit(BTN_TOOL_DOUBLETAP, dev->keybit); |
||
341 | set_bit(BTN_TOOL_TRIPLETAP, dev->keybit); |
||
342 | |||
343 | set_bit(BTN_LEFT, dev->keybit); |
||
344 | set_bit(BTN_RIGHT, dev->keybit); |
||
345 | set_bit(BTN_FORWARD, dev->keybit); |
||
346 | set_bit(BTN_BACK, dev->keybit); |
||
347 | if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap)) { |
||
348 | switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) { |
||
349 | default: |
||
350 | /* |
||
351 | * if nExtBtn is greater than 8 it should be considered |
||
352 | * invalid and treated as 0 |
||
353 | */ |
||
354 | break; |
||
355 | case 8: |
||
356 | set_bit(BTN_7, dev->keybit); |
||
357 | set_bit(BTN_6, dev->keybit); |
||
358 | case 6: |
||
359 | set_bit(BTN_5, dev->keybit); |
||
360 | set_bit(BTN_4, dev->keybit); |
||
361 | case 4: |
||
362 | set_bit(BTN_3, dev->keybit); |
||
363 | set_bit(BTN_2, dev->keybit); |
||
364 | case 2: |
||
365 | set_bit(BTN_1, dev->keybit); |
||
366 | set_bit(BTN_0, dev->keybit); |
||
367 | break; |
||
368 | } |
||
369 | } |
||
370 | |||
371 | clear_bit(EV_REL, dev->evbit); |
||
372 | clear_bit(REL_X, dev->relbit); |
||
373 | clear_bit(REL_Y, dev->relbit); |
||
374 | } |
||
375 | |||
376 | int synaptics_init(struct psmouse *psmouse) |
||
377 | { |
||
378 | struct synaptics_data *priv; |
||
379 | |||
380 | #ifndef CONFIG_MOUSE_PS2_SYNAPTICS |
||
381 | return -1; |
||
382 | #endif |
||
383 | |||
384 | psmouse->private = priv = kmalloc(sizeof(struct synaptics_data), GFP_KERNEL); |
||
385 | if (!priv) |
||
386 | return -1; |
||
387 | memset(priv, 0, sizeof(struct synaptics_data)); |
||
388 | |||
389 | if (synaptics_query_hardware(psmouse)) { |
||
390 | printk(KERN_ERR "Unable to query/initialize Synaptics hardware.\n"); |
||
391 | goto init_fail; |
||
392 | } |
||
393 | |||
394 | print_ident(priv); |
||
395 | set_input_params(&psmouse->dev, priv); |
||
396 | |||
397 | return 0; |
||
398 | |||
399 | init_fail: |
||
400 | kfree(priv); |
||
401 | return -1; |
||
402 | } |
||
403 | |||
404 | void synaptics_disconnect(struct psmouse *psmouse) |
||
405 | { |
||
406 | struct synaptics_data *priv = psmouse->private; |
||
407 | |||
408 | if (psmouse->type == PSMOUSE_SYNAPTICS && priv) { |
||
409 | synaptics_mode_cmd(psmouse, 0); |
||
410 | if (priv->ptport) { |
||
411 | serio_unregister_slave_port(priv->ptport); |
||
412 | kfree(priv->ptport); |
||
413 | } |
||
414 | kfree(priv); |
||
415 | } |
||
416 | } |
||
417 | |||
418 | /***************************************************************************** |
||
419 | * Functions to interpret the absolute mode packets |
||
420 | ****************************************************************************/ |
||
421 | |||
422 | static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data *priv, struct synaptics_hw_state *hw) |
||
423 | { |
||
424 | hw->up = 0; |
||
425 | hw->down = 0; |
||
426 | hw->b0 = 0; |
||
427 | hw->b1 = 0; |
||
428 | hw->b2 = 0; |
||
429 | hw->b3 = 0; |
||
430 | hw->b4 = 0; |
||
431 | hw->b5 = 0; |
||
432 | hw->b6 = 0; |
||
433 | hw->b7 = 0; |
||
434 | |||
435 | if (SYN_MODEL_NEWABS(priv->model_id)) { |
||
436 | hw->x = (((buf[3] & 0x10) << 8) | |
||
437 | ((buf[1] & 0x0f) << 8) | |
||
438 | buf[4]); |
||
439 | hw->y = (((buf[3] & 0x20) << 7) | |
||
440 | ((buf[1] & 0xf0) << 4) | |
||
441 | buf[5]); |
||
442 | |||
443 | hw->z = buf[2]; |
||
444 | hw->w = (((buf[0] & 0x30) >> 2) | |
||
445 | ((buf[0] & 0x04) >> 1) | |
||
446 | ((buf[3] & 0x04) >> 2)); |
||
447 | |||
448 | hw->left = (buf[0] & 0x01) ? 1 : 0; |
||
449 | hw->right = (buf[0] & 0x02) ? 1 : 0; |
||
450 | if (SYN_CAP_EXTENDED(priv->capabilities) && |
||
451 | (SYN_CAP_FOUR_BUTTON(priv->capabilities))) { |
||
452 | hw->up = ((buf[3] & 0x01)) ? 1 : 0; |
||
453 | if (hw->left) |
||
454 | hw->up = !hw->up; |
||
455 | hw->down = ((buf[3] & 0x02)) ? 1 : 0; |
||
456 | if (hw->right) |
||
457 | hw->down = !hw->down; |
||
458 | } |
||
459 | if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) && |
||
460 | ((buf[3] & 2) ? !hw->right : hw->right)) { |
||
461 | switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) { |
||
462 | default: |
||
463 | /* |
||
464 | * if nExtBtn is greater than 8 it should be |
||
465 | * considered invalid and treated as 0 |
||
466 | */ |
||
467 | break; |
||
468 | case 8: |
||
469 | hw->b7 = ((buf[5] & 0x08)) ? 1 : 0; |
||
470 | hw->b6 = ((buf[4] & 0x08)) ? 1 : 0; |
||
471 | case 6: |
||
472 | hw->b5 = ((buf[5] & 0x04)) ? 1 : 0; |
||
473 | hw->b4 = ((buf[4] & 0x04)) ? 1 : 0; |
||
474 | case 4: |
||
475 | hw->b3 = ((buf[5] & 0x02)) ? 1 : 0; |
||
476 | hw->b2 = ((buf[4] & 0x02)) ? 1 : 0; |
||
477 | case 2: |
||
478 | hw->b1 = ((buf[5] & 0x01)) ? 1 : 0; |
||
479 | hw->b0 = ((buf[4] & 0x01)) ? 1 : 0; |
||
480 | } |
||
481 | } |
||
482 | } else { |
||
483 | hw->x = (((buf[1] & 0x1f) << 8) | buf[2]); |
||
484 | hw->y = (((buf[4] & 0x1f) << 8) | buf[5]); |
||
485 | |||
486 | hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F)); |
||
487 | hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1)); |
||
488 | |||
489 | hw->left = (buf[0] & 0x01) ? 1 : 0; |
||
490 | hw->right = (buf[0] & 0x02) ? 1 : 0; |
||
491 | } |
||
492 | } |
||
493 | |||
494 | /* |
||
495 | * called for each full received packet from the touchpad |
||
496 | */ |
||
497 | static void synaptics_process_packet(struct psmouse *psmouse) |
||
498 | { |
||
499 | struct input_dev *dev = &psmouse->dev; |
||
500 | struct synaptics_data *priv = psmouse->private; |
||
501 | struct synaptics_hw_state hw; |
||
502 | int num_fingers; |
||
503 | int finger_width; |
||
504 | |||
505 | synaptics_parse_hw_state(psmouse->packet, priv, &hw); |
||
506 | |||
507 | if (hw.z > 0) { |
||
508 | num_fingers = 1; |
||
509 | finger_width = 5; |
||
510 | if (SYN_CAP_EXTENDED(priv->capabilities)) { |
||
511 | switch (hw.w) { |
||
512 | case 0 ... 1: |
||
513 | if (SYN_CAP_MULTIFINGER(priv->capabilities)) |
||
514 | num_fingers = hw.w + 2; |
||
515 | break; |
||
516 | case 2: |
||
517 | if (SYN_MODEL_PEN(priv->model_id)) |
||
518 | ; /* Nothing, treat a pen as a single finger */ |
||
519 | break; |
||
520 | case 4 ... 15: |
||
521 | if (SYN_CAP_PALMDETECT(priv->capabilities)) |
||
522 | finger_width = hw.w; |
||
523 | break; |
||
524 | } |
||
525 | } |
||
526 | } else { |
||
527 | num_fingers = 0; |
||
528 | finger_width = 0; |
||
529 | } |
||
530 | |||
531 | /* Post events */ |
||
532 | if (hw.z > 0) { |
||
533 | input_report_abs(dev, ABS_X, hw.x); |
||
534 | input_report_abs(dev, ABS_Y, YMAX_NOMINAL + YMIN_NOMINAL - hw.y); |
||
535 | } |
||
536 | input_report_abs(dev, ABS_PRESSURE, hw.z); |
||
537 | |||
538 | if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1); |
||
539 | if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0); |
||
540 | |||
541 | input_report_abs(dev, ABS_TOOL_WIDTH, finger_width); |
||
542 | input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1); |
||
543 | input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2); |
||
544 | input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3); |
||
545 | |||
546 | input_report_key(dev, BTN_LEFT, hw.left); |
||
547 | input_report_key(dev, BTN_RIGHT, hw.right); |
||
548 | input_report_key(dev, BTN_FORWARD, hw.up); |
||
549 | input_report_key(dev, BTN_BACK, hw.down); |
||
550 | if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap)) |
||
551 | switch(SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) { |
||
552 | default: |
||
553 | /* |
||
554 | * if nExtBtn is greater than 8 it should be considered |
||
555 | * invalid and treated as 0 |
||
556 | */ |
||
557 | break; |
||
558 | case 8: |
||
559 | input_report_key(dev, BTN_7, hw.b7); |
||
560 | input_report_key(dev, BTN_6, hw.b6); |
||
561 | case 6: |
||
562 | input_report_key(dev, BTN_5, hw.b5); |
||
563 | input_report_key(dev, BTN_4, hw.b4); |
||
564 | case 4: |
||
565 | input_report_key(dev, BTN_3, hw.b3); |
||
566 | input_report_key(dev, BTN_2, hw.b2); |
||
567 | case 2: |
||
568 | input_report_key(dev, BTN_1, hw.b1); |
||
569 | input_report_key(dev, BTN_0, hw.b0); |
||
570 | break; |
||
571 | } |
||
572 | input_sync(dev); |
||
573 | } |
||
574 | |||
575 | void synaptics_process_byte(struct psmouse *psmouse, struct pt_regs *regs) |
||
576 | { |
||
577 | struct input_dev *dev = &psmouse->dev; |
||
578 | struct synaptics_data *priv = psmouse->private; |
||
579 | unsigned char data = psmouse->packet[psmouse->pktcnt - 1]; |
||
580 | int newabs = SYN_MODEL_NEWABS(priv->model_id); |
||
581 | |||
582 | input_regs(dev, regs); |
||
583 | |||
584 | switch (psmouse->pktcnt) { |
||
585 | case 1: |
||
586 | if (newabs ? ((data & 0xC8) != 0x80) : ((data & 0xC0) != 0xC0)) { |
||
587 | printk(KERN_WARNING "Synaptics driver lost sync at 1st byte\n"); |
||
588 | goto bad_sync; |
||
589 | } |
||
590 | break; |
||
591 | case 2: |
||
592 | if (!newabs && ((data & 0x60) != 0x00)) { |
||
593 | printk(KERN_WARNING "Synaptics driver lost sync at 2nd byte\n"); |
||
594 | goto bad_sync; |
||
595 | } |
||
596 | break; |
||
597 | case 4: |
||
598 | if (newabs ? ((data & 0xC8) != 0xC0) : ((data & 0xC0) != 0x80)) { |
||
599 | printk(KERN_WARNING "Synaptics driver lost sync at 4th byte\n"); |
||
600 | goto bad_sync; |
||
601 | } |
||
602 | break; |
||
603 | case 5: |
||
604 | if (!newabs && ((data & 0x60) != 0x00)) { |
||
605 | printk(KERN_WARNING "Synaptics driver lost sync at 5th byte\n"); |
||
606 | goto bad_sync; |
||
607 | } |
||
608 | break; |
||
609 | default: |
||
610 | if (psmouse->pktcnt < 6) |
||
611 | break; /* Wait for full packet */ |
||
612 | |||
613 | if (priv->out_of_sync) { |
||
614 | priv->out_of_sync = 0; |
||
615 | printk(KERN_NOTICE "Synaptics driver resynced.\n"); |
||
616 | } |
||
617 | |||
618 | if (priv->ptport && synaptics_is_pt_packet(psmouse->packet)) |
||
619 | synaptics_pass_pt_packet(priv->ptport, psmouse->packet); |
||
620 | else |
||
621 | synaptics_process_packet(psmouse); |
||
622 | |||
623 | psmouse->pktcnt = 0; |
||
624 | break; |
||
625 | } |
||
626 | return; |
||
627 | |||
628 | bad_sync: |
||
629 | priv->out_of_sync++; |
||
630 | psmouse->pktcnt = 0; |
||
631 | if (psmouse_resetafter > 0 && priv->out_of_sync == psmouse_resetafter) { |
||
632 | psmouse->state = PSMOUSE_IGNORE; |
||
633 | serio_rescan(psmouse->serio); |
||
634 | } |
||
635 | } |