synaptics.c revision 1.50.2.7 1 /* $NetBSD: synaptics.c,v 1.50.2.7 2020/10/08 16:47:12 martin Exp $ */
2
3 /*
4 * Copyright (c) 2005, Steve C. Woodford
5 * Copyright (c) 2004, Ales Krenek
6 * Copyright (c) 2004, Kentaro A. Kurahone
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * * Neither the name of the authors nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 */
37
38 /*
39 * TODO:
40 * - Make the sysctl values per-instance instead of global.
41 * - Consider setting initial scaling factors at runtime according
42 * to the values returned by the 'Read Resolutions' command.
43 * - Support the serial protocol (we only support PS/2 for now)
44 * - Support auto-repeat for up/down button Z-axis emulation.
45 * - Maybe add some more gestures (can we use Palm support somehow?)
46 */
47
48 #include "opt_pms.h"
49
50 #include <sys/cdefs.h>
51 __KERNEL_RCSID(0, "$NetBSD: synaptics.c,v 1.50.2.7 2020/10/08 16:47:12 martin Exp $");
52
53 #include <sys/param.h>
54 #include <sys/systm.h>
55 #include <sys/device.h>
56 #include <sys/ioctl.h>
57 #include <sys/sysctl.h>
58 #include <sys/kernel.h>
59 #include <sys/proc.h>
60
61 #include <sys/bus.h>
62
63 #include <dev/pckbport/pckbportvar.h>
64
65 #include <dev/pckbport/synapticsreg.h>
66 #include <dev/pckbport/synapticsvar.h>
67
68 #include <dev/pckbport/pmsreg.h>
69 #include <dev/pckbport/pmsvar.h>
70
71 #include <dev/wscons/wsconsio.h>
72 #include <dev/wscons/wsmousevar.h>
73
74 /*
75 * Absolute-mode packets are decoded and passed around using
76 * the following structure.
77 */
78 struct synaptics_packet {
79 signed short sp_x; /* Unscaled absolute X/Y coordinates */
80 signed short sp_y;
81 u_char sp_z; /* Z (pressure) */
82 u_char sp_w; /* W (contact patch width) */
83 signed short sp_sx; /* Secondary finger unscaled absolute */
84 /* X/Y coordinates */
85 signed short sp_xy;
86 u_char sp_finger; /* 0 for primary, 1 for secondary */
87 char sp_left; /* Left mouse button status */
88 char sp_right; /* Right mouse button status */
89 char sp_middle; /* Middle button status (possibly emulated) */
90 char sp_up; /* Up button status */
91 char sp_down; /* Down button status */
92 };
93
94 static void pms_synaptics_input(void *, int);
95 static void pms_synaptics_process_packet(struct pms_softc *,
96 struct synaptics_packet *);
97 static void pms_sysctl_synaptics(struct sysctllog **);
98 static int pms_sysctl_synaptics_verify(SYSCTLFN_ARGS);
99
100 /* Controlled by sysctl. */
101 static int synaptics_up_down_emul = 3;
102 static int synaptics_up_down_motion_delta = 1;
103 static int synaptics_gesture_move = 200;
104 static int synaptics_gesture_length = 20;
105 static int synaptics_edge_left = SYNAPTICS_EDGE_LEFT;
106 static int synaptics_edge_right = SYNAPTICS_EDGE_RIGHT;
107 static int synaptics_edge_top = SYNAPTICS_EDGE_TOP;
108 static int synaptics_edge_bottom = SYNAPTICS_EDGE_BOTTOM;
109 static int synaptics_edge_motion_delta = 32;
110 static u_int synaptics_finger_high = SYNAPTICS_FINGER_LIGHT + 5;
111 static u_int synaptics_finger_low = SYNAPTICS_FINGER_LIGHT - 10;
112 static int synaptics_button_boundary = SYNAPTICS_EDGE_BOTTOM + 720;
113 static int synaptics_button2 = SYNAPTICS_EDGE_LEFT + (SYNAPTICS_EDGE_RIGHT - SYNAPTICS_EDGE_LEFT) / 3;
114 static int synaptics_button3 = SYNAPTICS_EDGE_LEFT + 2 * (SYNAPTICS_EDGE_RIGHT - SYNAPTICS_EDGE_LEFT) / 3;
115 static int synaptics_two_fingers_emul = 0;
116 static int synaptics_scale_x = 16;
117 static int synaptics_scale_y = 16;
118 static int synaptics_scale_z = 32;
119 static int synaptics_max_speed_x = 32;
120 static int synaptics_max_speed_y = 32;
121 static int synaptics_max_speed_z = 2;
122 static int synaptics_movement_threshold = 4;
123 static int synaptics_fscroll_min = 13;
124 static int synaptics_fscroll_max = 14;
125 static int synaptics_dz_hold = 30;
126 static int synaptics_movement_enable = 1;
127 static bool synaptics_aux_mid_button_scroll = TRUE;
128
129 /* Sysctl nodes. */
130 static int synaptics_button_boundary_nodenum;
131 static int synaptics_button2_nodenum;
132 static int synaptics_button3_nodenum;
133 static int synaptics_up_down_emul_nodenum;
134 static int synaptics_up_down_motion_delta_nodenum;
135 static int synaptics_gesture_move_nodenum;
136 static int synaptics_gesture_length_nodenum;
137 static int synaptics_edge_left_nodenum;
138 static int synaptics_edge_right_nodenum;
139 static int synaptics_edge_top_nodenum;
140 static int synaptics_edge_bottom_nodenum;
141 static int synaptics_edge_motion_delta_nodenum;
142 static int synaptics_finger_high_nodenum;
143 static int synaptics_finger_low_nodenum;
144 static int synaptics_two_fingers_emul_nodenum;
145 static int synaptics_scale_x_nodenum;
146 static int synaptics_scale_y_nodenum;
147 static int synaptics_scale_z_nodenum;
148 static int synaptics_max_speed_x_nodenum;
149 static int synaptics_max_speed_y_nodenum;
150 static int synaptics_max_speed_z_nodenum;
151 static int synaptics_movement_threshold_nodenum;
152 static int synaptics_finger_scroll_min_nodenum;
153 static int synaptics_finger_scroll_max_nodenum;
154 static int synaptics_dz_hold_nodenum;
155 static int synaptics_movement_enable_nodenum;
156 static int synaptics_aux_mid_button_scroll_nodenum;
157
158 static int
159 synaptics_poll_cmd(struct pms_softc *psc, ...)
160 {
161 u_char cmd[4];
162 size_t i;
163 va_list ap;
164
165 va_start(ap, psc);
166
167 for (i = 0; i < __arraycount(cmd); i++)
168 if ((cmd[i] = (u_char)va_arg(ap, int)) == 0)
169 break;
170 va_end(ap);
171
172 int res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot, cmd, i, 0,
173 NULL, 0);
174 if (res)
175 aprint_error_dev(psc->sc_dev, "command error %#x\n", cmd[0]);
176 return res;
177 }
178
179 static int
180 synaptics_poll_reset(struct pms_softc *psc)
181 {
182 u_char resp[2];
183 int res;
184
185 u_char cmd[1] = { PMS_RESET };
186 res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot, cmd, 1, 2,
187 resp, 1);
188 aprint_debug_dev(psc->sc_dev, "reset %d 0x%02x 0x%02x\n",
189 res, resp[0], resp[1]);
190 return res;
191 }
192
193 static int
194 synaptics_special_read(struct pms_softc *psc, u_char slice, u_char resp[3])
195 {
196 u_char cmd[1] = { PMS_SEND_DEV_STATUS };
197 int res = pms_sliced_command(psc->sc_kbctag, psc->sc_kbcslot, slice);
198
199 return res | pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
200 cmd, 1, 3, resp, 0);
201 }
202
203 static int
204 synaptics_special_write(struct pms_softc *psc, u_char command, u_char arg)
205 {
206 int res = pms_sliced_command(psc->sc_kbctag, psc->sc_kbcslot, arg);
207 if (res)
208 return res;
209
210 u_char cmd[2];
211 cmd[0] = PMS_SET_SAMPLE;
212 cmd[1] = command;
213 res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
214 cmd, 2, 0, NULL, 0);
215 return res;
216 }
217
218 static void
219 pms_synaptics_probe_extended(struct pms_softc *psc)
220 {
221 struct synaptics_softc *sc = &psc->u.synaptics;
222 u_char resp[3];
223 int res;
224
225 aprint_debug_dev(psc->sc_dev,
226 "synaptics_probe: Capabilities 0x%04x.\n", sc->caps);
227 if (sc->caps & SYNAPTICS_CAP_PASSTHROUGH)
228 sc->flags |= SYN_FLAG_HAS_PASSTHROUGH;
229
230 if (sc->caps & SYNAPTICS_CAP_PALMDETECT)
231 sc->flags |= SYN_FLAG_HAS_PALM_DETECT;
232
233 if (sc->caps & SYNAPTICS_CAP_MULTIDETECT)
234 sc->flags |= SYN_FLAG_HAS_MULTI_FINGER;
235
236 if (sc->caps & SYNAPTICS_CAP_MULTIFINGERREPORT)
237 sc->flags |= SYN_FLAG_HAS_MULTI_FINGER_REPORT;
238
239 /* Ask about extra buttons to detect up/down. */
240 if (((sc->caps & SYNAPTICS_CAP_EXTNUM) + 0x08)
241 >= SYNAPTICS_EXTENDED_QUERY)
242 {
243 res = synaptics_special_read(psc, SYNAPTICS_EXTENDED_QUERY, resp);
244 if (res == 0) {
245 int buttons = (resp[1] >> 4);
246 aprint_debug_dev(psc->sc_dev,
247 "%s: Extended Buttons: %d.\n", __func__, buttons);
248
249 aprint_debug_dev(psc->sc_dev, "%s: Extended "
250 "Capabilities: 0x%02x 0x%02x 0x%02x.\n", __func__,
251 resp[0], resp[1], resp[2]);
252 if (buttons >= 2) {
253 /* Yes. */
254 sc->flags |= SYN_FLAG_HAS_UP_DOWN_BUTTONS;
255 }
256 if (resp[0] & 0x1) {
257 /* Vertical scroll area */
258 sc->flags |= SYN_FLAG_HAS_VERTICAL_SCROLL;
259 }
260 if (resp[0] & 0x2) {
261 /* Horizontal scroll area */
262 sc->flags |= SYN_FLAG_HAS_HORIZONTAL_SCROLL;
263 }
264 if (resp[0] & 0x4) {
265 /* Extended W-Mode */
266 sc->flags |= SYN_FLAG_HAS_EXTENDED_WMODE;
267 }
268 }
269 }
270
271 /* Ask about click pad */
272 if (((sc->caps & SYNAPTICS_CAP_EXTNUM) + 0x08) >=
273 SYNAPTICS_CONTINUED_CAPABILITIES)
274 {
275 res = synaptics_special_read(psc,
276 SYNAPTICS_CONTINUED_CAPABILITIES, resp);
277
278 /*
279 * The following describes response for the
280 * SYNAPTICS_CONTINUED_CAPABILITIES query.
281 *
282 * byte mask name meaning
283 * ---- ---- ------- ------------
284 * 0 0x01 adjustable threshold capacitive button sensitivity
285 * can be adjusted
286 * 0 0x02 report max query 0x0d gives max coord reported
287 * 0 0x04 clearpad sensor is ClearPad product
288 * 0 0x08 advanced gesture not particularly meaningful
289 * 0 0x10 clickpad bit 0 1-button ClickPad
290 * 0 0x60 multifinger mode identifies firmware finger counting
291 * (not reporting!) algorithm.
292 * Not particularly meaningful
293 * 0 0x80 covered pad W clipped to 14, 15 == pad mostly covered
294 * 1 0x01 clickpad bit 1 2-button ClickPad
295 * 1 0x02 deluxe LED controls touchpad support LED commands
296 * ala multimedia control bar
297 * 1 0x04 reduced filtering firmware does less filtering on
298 * position data, driver should watch
299 * for noise.
300 * 1 0x08 image sensor image sensor tracks 5 fingers, but only
301 * reports 2.
302 * 1 0x10 uniform clickpad whole clickpad moves instead of being
303 * hinged at the top.
304 * 1 0x20 report min query 0x0f gives min coord reported
305 */
306 if (res == 0) {
307 uint val = SYN_CCAP_VALUE(resp);
308
309 aprint_debug_dev(psc->sc_dev, "%s: Continued "
310 "Capabilities 0x%02x 0x%02x 0x%02x.\n", __func__,
311 resp[0], resp[1], resp[2]);
312 switch (SYN_CCAP_CLICKPAD_TYPE(val)) {
313 case 0: /* not a clickpad */
314 break;
315 case 1:
316 sc->flags |= SYN_FLAG_HAS_ONE_BUTTON_CLICKPAD;
317 break;
318 case 2:
319 sc->flags |= SYN_FLAG_HAS_TWO_BUTTON_CLICKPAD;
320 break;
321 case 3: /* reserved */
322 default:
323 /* unreached */
324 break;
325 }
326
327 if ((val & SYN_CCAP_HAS_ADV_GESTURE_MODE))
328 sc->flags |= SYN_FLAG_HAS_ADV_GESTURE_MODE;
329 }
330 }
331 }
332
333 static const struct {
334 int bit;
335 const char *desc;
336 } syn_flags[] = {
337 { SYN_FLAG_HAS_EXTENDED_WMODE, "Extended W mode", },
338 { SYN_FLAG_HAS_PASSTHROUGH, "Passthrough", },
339 { SYN_FLAG_HAS_MIDDLE_BUTTON, "Middle button", },
340 { SYN_FLAG_HAS_BUTTONS_4_5, "Buttons 4/5", },
341 { SYN_FLAG_HAS_UP_DOWN_BUTTONS, "Up/down buttons", },
342 { SYN_FLAG_HAS_PALM_DETECT, "Palm detect", },
343 { SYN_FLAG_HAS_ONE_BUTTON_CLICKPAD, "One button click pad", },
344 { SYN_FLAG_HAS_TWO_BUTTON_CLICKPAD, "Two button click pad", },
345 { SYN_FLAG_HAS_VERTICAL_SCROLL, "Vertical scroll", },
346 { SYN_FLAG_HAS_HORIZONTAL_SCROLL, "Horizontal scroll", },
347 { SYN_FLAG_HAS_MULTI_FINGER_REPORT, "Multi-finger Report", },
348 { SYN_FLAG_HAS_MULTI_FINGER, "Multi-finger", },
349 };
350
351 int
352 pms_synaptics_probe_init(void *vsc)
353 {
354 struct pms_softc *psc = vsc;
355 struct synaptics_softc *sc = &psc->u.synaptics;
356 u_char cmd[1], resp[3];
357 int res, ver_minor, ver_major;
358 struct sysctllog *clog = NULL;
359
360 res = pms_sliced_command(psc->sc_kbctag, psc->sc_kbcslot,
361 SYNAPTICS_IDENTIFY_TOUCHPAD);
362 cmd[0] = PMS_SEND_DEV_STATUS;
363 res |= pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot, cmd, 1, 3,
364 resp, 0);
365 if (res) {
366 aprint_debug_dev(psc->sc_dev,
367 "synaptics_probe: Identify Touchpad error.\n");
368 /*
369 * Reset device in case the probe confused it.
370 */
371 doreset:
372 (void)synaptics_poll_reset(psc);
373 return res;
374 }
375
376 if (resp[1] != SYNAPTICS_MAGIC_BYTE) {
377 aprint_debug_dev(psc->sc_dev,
378 "synaptics_probe: Not synaptics.\n");
379 res = 1;
380 goto doreset;
381 }
382
383 sc->flags = 0;
384
385 /* Check for minimum version and print a nice message. */
386 ver_major = resp[2] & 0x0f;
387 ver_minor = resp[0];
388 aprint_normal_dev(psc->sc_dev, "Synaptics touchpad version %d.%d\n",
389 ver_major, ver_minor);
390 if (ver_major * 10 + ver_minor < SYNAPTICS_MIN_VERSION) {
391 /* No capability query support. */
392 sc->caps = 0;
393 goto done;
394 }
395
396
397 /* Query the hardware capabilities. */
398 res = synaptics_special_read(psc, SYNAPTICS_READ_CAPABILITIES, resp);
399 if (res) {
400 /* Hmm, failed to get capabilites. */
401 aprint_error_dev(psc->sc_dev,
402 "synaptics_probe: Failed to query capabilities.\n");
403 goto doreset;
404 }
405
406 sc->caps = SYNAPTICS_CAP_VALUE(resp);
407
408 if (sc->caps & SYNAPTICS_CAP_MBUTTON)
409 sc->flags |= SYN_FLAG_HAS_MIDDLE_BUTTON;
410
411 if (sc->caps & SYNAPTICS_CAP_4BUTTON)
412 sc->flags |= SYN_FLAG_HAS_BUTTONS_4_5;
413
414 if (sc->caps & SYNAPTICS_CAP_EXTENDED) {
415 pms_synaptics_probe_extended(psc);
416 }
417
418 if (sc->flags) {
419 const char comma[] = ", ";
420 const char *sep = "";
421 aprint_normal_dev(psc->sc_dev, "");
422 for (size_t f = 0; f < __arraycount(syn_flags); f++) {
423 if (sc->flags & syn_flags[f].bit) {
424 aprint_normal("%s%s", sep, syn_flags[f].desc);
425 sep = comma;
426 }
427 }
428 aprint_normal("\n");
429 }
430
431 done:
432 pms_sysctl_synaptics(&clog);
433 pckbport_set_inputhandler(psc->sc_kbctag, psc->sc_kbcslot,
434 pms_synaptics_input, psc, device_xname(psc->sc_dev));
435
436 return (0);
437 }
438
439 void
440 pms_synaptics_enable(void *vsc)
441 {
442 struct pms_softc *psc = vsc;
443 struct synaptics_softc *sc = &psc->u.synaptics;
444 u_char enable_modes;
445 int res, i;
446
447 if (sc->flags & SYN_FLAG_HAS_PASSTHROUGH) {
448 /*
449 * Extended capability probes can confuse the passthrough
450 * device; reset the touchpad now to cure that.
451 */
452 res = synaptics_poll_reset(psc);
453 }
454
455 /*
456 * Enable Absolute mode with W (width) reporting, and set
457 * the packet rate to maximum (80 packets per second). Enable
458 * extended W mode if supported so we can report second finger
459 * position.
460 */
461 enable_modes =
462 SYNAPTICS_MODE_ABSOLUTE | SYNAPTICS_MODE_W | SYNAPTICS_MODE_RATE;
463
464 if (sc->flags & SYN_FLAG_HAS_EXTENDED_WMODE)
465 enable_modes |= SYNAPTICS_MODE_EXTENDED_W;
466
467 /*
468 * Synaptics documentation says to disable device before
469 * setting mode.
470 */
471 synaptics_poll_cmd(psc, PMS_DEV_DISABLE, 0);
472 /* a couple of set scales to clear out pending commands */
473 for (i = 0; i < 2; i++)
474 synaptics_poll_cmd(psc, PMS_SET_SCALE11, 0);
475
476 res = synaptics_special_write(psc, SYNAPTICS_CMD_SET_MODE2, enable_modes);
477 if (res)
478 aprint_error("synaptics: set mode error\n");
479
480 /* a couple of set scales to clear out pending commands */
481 for (i = 0; i < 2; i++)
482 synaptics_poll_cmd(psc, PMS_SET_SCALE11, 0);
483
484 /* Set advanced gesture mode */
485 if ((sc->flags & SYN_FLAG_HAS_EXTENDED_WMODE) ||
486 (sc->flags & SYN_FLAG_HAS_ADV_GESTURE_MODE))
487 synaptics_special_write(psc, SYNAPTICS_WRITE_DELUXE_3, 0x3);
488
489 sc->up_down = 0;
490 sc->prev_fingers = 0;
491 sc->gesture_start_x = sc->gesture_start_y = 0;
492 sc->gesture_start_packet = 0;
493 sc->gesture_tap_packet = 0;
494 sc->gesture_type = 0;
495 sc->gesture_buttons = 0;
496 sc->dz_hold = 0;
497 for (i = 0; i < SYN_MAX_FINGERS; i++) {
498 sc->rem_x[i] = sc->rem_y[i] = sc->rem_z[i] = 0;
499 sc->movement_history[i] = 0;
500 }
501 sc->button_history = 0;
502 }
503
504 void
505 pms_synaptics_resume(void *vsc)
506 {
507 (void)synaptics_poll_reset(vsc);
508 }
509
510 static void
511 pms_sysctl_synaptics(struct sysctllog **clog)
512 {
513 int rc, root_num;
514 const struct sysctlnode *node;
515
516 if ((rc = sysctl_createv(clog, 0, NULL, &node,
517 CTLFLAG_PERMANENT, CTLTYPE_NODE, "synaptics",
518 SYSCTL_DESCR("Synaptics touchpad controls"),
519 NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL)) != 0)
520 goto err;
521
522 root_num = node->sysctl_num;
523
524 if ((rc = sysctl_createv(clog, 0, NULL, &node,
525 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
526 CTLTYPE_INT, "up_down_emulation",
527 SYSCTL_DESCR("Middle button/Z-axis emulation with up/down buttons"),
528 pms_sysctl_synaptics_verify, 0,
529 &synaptics_up_down_emul,
530 0, CTL_HW, root_num, CTL_CREATE,
531 CTL_EOL)) != 0)
532 goto err;
533
534 synaptics_up_down_emul_nodenum = node->sysctl_num;
535
536 if ((rc = sysctl_createv(clog, 0, NULL, &node,
537 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
538 CTLTYPE_INT, "up_down_motion_delta",
539 SYSCTL_DESCR("Up/down button Z-axis emulation rate"),
540 pms_sysctl_synaptics_verify, 0,
541 &synaptics_up_down_motion_delta,
542 0, CTL_HW, root_num, CTL_CREATE,
543 CTL_EOL)) != 0)
544 goto err;
545
546 synaptics_up_down_motion_delta_nodenum = node->sysctl_num;
547
548 if ((rc = sysctl_createv(clog, 0, NULL, &node,
549 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
550 CTLTYPE_INT, "gesture_move",
551 SYSCTL_DESCR("Movement greater than this between taps cancels gesture"),
552 pms_sysctl_synaptics_verify, 0,
553 &synaptics_gesture_move,
554 0, CTL_HW, root_num, CTL_CREATE,
555 CTL_EOL)) != 0)
556 goto err;
557
558 synaptics_gesture_move_nodenum = node->sysctl_num;
559
560 if ((rc = sysctl_createv(clog, 0, NULL, &node,
561 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
562 CTLTYPE_INT, "gesture_length",
563 SYSCTL_DESCR("Time period in which tap is recognised as a gesture"),
564 pms_sysctl_synaptics_verify, 0,
565 &synaptics_gesture_length,
566 0, CTL_HW, root_num, CTL_CREATE,
567 CTL_EOL)) != 0)
568 goto err;
569
570 synaptics_gesture_length_nodenum = node->sysctl_num;
571
572 if ((rc = sysctl_createv(clog, 0, NULL, &node,
573 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
574 CTLTYPE_INT, "edge_left",
575 SYSCTL_DESCR("Define left edge of touchpad"),
576 pms_sysctl_synaptics_verify, 0,
577 &synaptics_edge_left,
578 0, CTL_HW, root_num, CTL_CREATE,
579 CTL_EOL)) != 0)
580 goto err;
581
582 synaptics_edge_left_nodenum = node->sysctl_num;
583
584 if ((rc = sysctl_createv(clog, 0, NULL, &node,
585 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
586 CTLTYPE_INT, "edge_right",
587 SYSCTL_DESCR("Define right edge of touchpad"),
588 pms_sysctl_synaptics_verify, 0,
589 &synaptics_edge_right,
590 0, CTL_HW, root_num, CTL_CREATE,
591 CTL_EOL)) != 0)
592 goto err;
593
594 synaptics_edge_right_nodenum = node->sysctl_num;
595
596 if ((rc = sysctl_createv(clog, 0, NULL, &node,
597 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
598 CTLTYPE_INT, "edge_top",
599 SYSCTL_DESCR("Define top edge of touchpad"),
600 pms_sysctl_synaptics_verify, 0,
601 &synaptics_edge_top,
602 0, CTL_HW, root_num, CTL_CREATE,
603 CTL_EOL)) != 0)
604 goto err;
605
606 synaptics_edge_top_nodenum = node->sysctl_num;
607
608 if ((rc = sysctl_createv(clog, 0, NULL, &node,
609 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
610 CTLTYPE_INT, "edge_bottom",
611 SYSCTL_DESCR("Define bottom edge of touchpad"),
612 pms_sysctl_synaptics_verify, 0,
613 &synaptics_edge_bottom,
614 0, CTL_HW, root_num, CTL_CREATE,
615 CTL_EOL)) != 0)
616 goto err;
617
618 synaptics_edge_bottom_nodenum = node->sysctl_num;
619
620 if ((rc = sysctl_createv(clog, 0, NULL, &node,
621 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
622 CTLTYPE_INT, "edge_motion_delta",
623 SYSCTL_DESCR("Define edge motion rate"),
624 pms_sysctl_synaptics_verify, 0,
625 &synaptics_edge_motion_delta,
626 0, CTL_HW, root_num, CTL_CREATE,
627 CTL_EOL)) != 0)
628 goto err;
629
630 synaptics_edge_motion_delta_nodenum = node->sysctl_num;
631
632 if ((rc = sysctl_createv(clog, 0, NULL, &node,
633 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
634 CTLTYPE_INT, "finger_high",
635 SYSCTL_DESCR("Define finger applied pressure threshold"),
636 pms_sysctl_synaptics_verify, 0,
637 &synaptics_finger_high,
638 0, CTL_HW, root_num, CTL_CREATE,
639 CTL_EOL)) != 0)
640 goto err;
641
642 synaptics_finger_high_nodenum = node->sysctl_num;
643
644 if ((rc = sysctl_createv(clog, 0, NULL, &node,
645 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
646 CTLTYPE_INT, "finger_low",
647 SYSCTL_DESCR("Define finger removed pressure threshold"),
648 pms_sysctl_synaptics_verify, 0,
649 &synaptics_finger_low,
650 0, CTL_HW, root_num, CTL_CREATE,
651 CTL_EOL)) != 0)
652 goto err;
653
654 synaptics_finger_low_nodenum = node->sysctl_num;
655
656 if ((rc = sysctl_createv(clog, 0, NULL, &node,
657 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
658 CTLTYPE_INT, "two_fingers_emulation",
659 SYSCTL_DESCR("Map two fingers to middle button"),
660 pms_sysctl_synaptics_verify, 0,
661 &synaptics_two_fingers_emul,
662 0, CTL_HW, root_num, CTL_CREATE,
663 CTL_EOL)) != 0)
664 goto err;
665
666 synaptics_two_fingers_emul_nodenum = node->sysctl_num;
667
668 if ((rc = sysctl_createv(clog, 0, NULL, &node,
669 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
670 CTLTYPE_INT, "scale_x",
671 SYSCTL_DESCR("Horizontal movement scale factor"),
672 pms_sysctl_synaptics_verify, 0,
673 &synaptics_scale_x,
674 0, CTL_HW, root_num, CTL_CREATE,
675 CTL_EOL)) != 0)
676 goto err;
677
678 synaptics_scale_x_nodenum = node->sysctl_num;
679
680 if ((rc = sysctl_createv(clog, 0, NULL, &node,
681 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
682 CTLTYPE_INT, "scale_y",
683 SYSCTL_DESCR("Vertical movement scale factor"),
684 pms_sysctl_synaptics_verify, 0,
685 &synaptics_scale_y,
686 0, CTL_HW, root_num, CTL_CREATE,
687 CTL_EOL)) != 0)
688 goto err;
689
690 synaptics_scale_y_nodenum = node->sysctl_num;
691
692 if ((rc = sysctl_createv(clog, 0, NULL, &node,
693 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
694 CTLTYPE_INT, "scale_z",
695 SYSCTL_DESCR("Sroll wheel emulation scale factor"),
696 pms_sysctl_synaptics_verify, 0,
697 &synaptics_scale_z,
698 0, CTL_HW, root_num, CTL_CREATE,
699 CTL_EOL)) != 0)
700 goto err;
701
702 synaptics_scale_z_nodenum = node->sysctl_num;
703
704 if ((rc = sysctl_createv(clog, 0, NULL, &node,
705 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
706 CTLTYPE_INT, "max_speed_x",
707 SYSCTL_DESCR("Horizontal movement maximum speed"),
708 pms_sysctl_synaptics_verify, 0,
709 &synaptics_max_speed_x,
710 0, CTL_HW, root_num, CTL_CREATE,
711 CTL_EOL)) != 0)
712 goto err;
713
714 synaptics_max_speed_x_nodenum = node->sysctl_num;
715
716 if ((rc = sysctl_createv(clog, 0, NULL, &node,
717 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
718 CTLTYPE_INT, "max_speed_y",
719 SYSCTL_DESCR("Vertical movement maximum speed"),
720 pms_sysctl_synaptics_verify, 0,
721 &synaptics_max_speed_y,
722 0, CTL_HW, root_num, CTL_CREATE,
723 CTL_EOL)) != 0)
724 goto err;
725
726 synaptics_max_speed_y_nodenum = node->sysctl_num;
727
728 if ((rc = sysctl_createv(clog, 0, NULL, &node,
729 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
730 CTLTYPE_INT, "max_speed_z",
731 SYSCTL_DESCR("Scroll wheel emulation maximum speed"),
732 pms_sysctl_synaptics_verify, 0,
733 &synaptics_max_speed_z,
734 0, CTL_HW, root_num, CTL_CREATE,
735 CTL_EOL)) != 0)
736 goto err;
737
738 synaptics_max_speed_z_nodenum = node->sysctl_num;
739
740 if ((rc = sysctl_createv(clog, 0, NULL, &node,
741 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
742 CTLTYPE_INT, "movement_threshold",
743 SYSCTL_DESCR("Minimum reported movement threshold"),
744 pms_sysctl_synaptics_verify, 0,
745 &synaptics_movement_threshold,
746 0, CTL_HW, root_num, CTL_CREATE,
747 CTL_EOL)) != 0)
748 goto err;
749
750 synaptics_movement_threshold_nodenum = node->sysctl_num;
751
752 if ((rc = sysctl_createv(clog, 0, NULL, &node,
753 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
754 CTLTYPE_INT, "movement_enable",
755 SYSCTL_DESCR("Enable movement reporting"),
756 pms_sysctl_synaptics_verify, 0,
757 &synaptics_movement_enable,
758 0, CTL_HW, root_num, CTL_CREATE,
759 CTL_EOL)) != 0)
760 goto err;
761
762 synaptics_movement_enable_nodenum = node->sysctl_num;
763
764 if ((rc = sysctl_createv(clog, 0, NULL, &node,
765 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
766 CTLTYPE_INT, "button_boundary",
767 SYSCTL_DESCR("Top edge of button area"),
768 pms_sysctl_synaptics_verify, 0,
769 &synaptics_button_boundary,
770 0, CTL_HW, root_num, CTL_CREATE,
771 CTL_EOL)) != 0)
772 goto err;
773
774 synaptics_button_boundary_nodenum = node->sysctl_num;
775
776 if ((rc = sysctl_createv(clog, 0, NULL, &node,
777 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
778 CTLTYPE_INT, "button2_edge",
779 SYSCTL_DESCR("Left edge of button 2 region"),
780 pms_sysctl_synaptics_verify, 0,
781 &synaptics_button2,
782 0, CTL_HW, root_num, CTL_CREATE,
783 CTL_EOL)) != 0)
784 goto err;
785
786 synaptics_button2_nodenum = node->sysctl_num;
787
788 if ((rc = sysctl_createv(clog, 0, NULL, &node,
789 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
790 CTLTYPE_INT, "button3_edge",
791 SYSCTL_DESCR("Left edge of button 3 region"),
792 pms_sysctl_synaptics_verify, 0,
793 &synaptics_button3,
794 0, CTL_HW, root_num, CTL_CREATE,
795 CTL_EOL)) != 0)
796 goto err;
797
798 synaptics_button3_nodenum = node->sysctl_num;
799
800 if ((rc = sysctl_createv(clog, 0, NULL, &node,
801 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
802 CTLTYPE_INT, "finger_scroll-min",
803 SYSCTL_DESCR("Minimum width at which y cursor movements will be converted to scroll wheel events"),
804 pms_sysctl_synaptics_verify, 0,
805 &synaptics_fscroll_min,
806 0, CTL_HW, root_num, CTL_CREATE,
807 CTL_EOL)) != 0)
808 goto err;
809
810 synaptics_finger_scroll_min_nodenum = node->sysctl_num;
811
812 if ((rc = sysctl_createv(clog, 0, NULL, &node,
813 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
814 CTLTYPE_INT, "finger_scroll-max",
815 SYSCTL_DESCR("Maximum width at which y cursor movements will be converted to scroll wheel events"),
816 pms_sysctl_synaptics_verify, 0,
817 &synaptics_fscroll_max,
818 0, CTL_HW, root_num, CTL_CREATE,
819 CTL_EOL)) != 0)
820 goto err;
821
822 synaptics_finger_scroll_max_nodenum = node->sysctl_num;
823
824 if ((rc = sysctl_createv(clog, 0, NULL, &node,
825 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
826 CTLTYPE_INT, "finger_scroll-hysteresis",
827 SYSCTL_DESCR("Number of packets to keep reporting y cursor movements as scroll wheel events"),
828 pms_sysctl_synaptics_verify, 0,
829 &synaptics_dz_hold,
830 0, CTL_HW, root_num, CTL_CREATE,
831 CTL_EOL)) != 0)
832 goto err;
833
834 synaptics_dz_hold_nodenum = node->sysctl_num;
835
836 if ((rc = sysctl_createv(clog, 0, NULL, &node,
837 CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
838 CTLTYPE_BOOL, "aux_mid_button_scroll",
839 SYSCTL_DESCR("Interpet Y-Axis movement with the middle button held as scrolling on the passthrough device (e.g. TrackPoint)"),
840 pms_sysctl_synaptics_verify, 0,
841 &synaptics_aux_mid_button_scroll,
842 0, CTL_HW, root_num, CTL_CREATE,
843 CTL_EOL)) != 0)
844 goto err;
845
846 synaptics_aux_mid_button_scroll_nodenum = node->sysctl_num;
847 return;
848
849 err:
850 aprint_error("%s: sysctl_createv failed (rc = %d)\n", __func__, rc);
851 }
852
853 static int
854 pms_sysctl_synaptics_verify(SYSCTLFN_ARGS)
855 {
856 int error, t;
857 struct sysctlnode node;
858
859 node = *rnode;
860 t = *(int *)rnode->sysctl_data;
861 node.sysctl_data = &t;
862 error = sysctl_lookup(SYSCTLFN_CALL(&node));
863 if (error || newp == NULL)
864 return error;
865
866 /* Sanity check the params. */
867 if (node.sysctl_num == synaptics_up_down_emul_nodenum) {
868 if (t < 0 || t > 3)
869 return (EINVAL);
870 } else
871 if (node.sysctl_num == synaptics_two_fingers_emul_nodenum) {
872 if (t < 0 || t > 2)
873 return (EINVAL);
874 } else
875 if (node.sysctl_num == synaptics_gesture_length_nodenum ||
876 node.sysctl_num == synaptics_edge_motion_delta_nodenum ||
877 node.sysctl_num == synaptics_up_down_motion_delta_nodenum ||
878 node.sysctl_num == synaptics_max_speed_x_nodenum ||
879 node.sysctl_num == synaptics_max_speed_y_nodenum ||
880 node.sysctl_num == synaptics_max_speed_z_nodenum) {
881 if (t < 0)
882 return (EINVAL);
883 } else
884 if (node.sysctl_num == synaptics_edge_left_nodenum ||
885 node.sysctl_num == synaptics_edge_bottom_nodenum) {
886 if (t < 0 || t > (SYNAPTICS_EDGE_MAX / 2))
887 return (EINVAL);
888 } else
889 if (node.sysctl_num == synaptics_edge_right_nodenum ||
890 node.sysctl_num == synaptics_edge_top_nodenum) {
891 if (t < (SYNAPTICS_EDGE_MAX / 2))
892 return (EINVAL);
893 } else
894 if (node.sysctl_num == synaptics_scale_x_nodenum ||
895 node.sysctl_num == synaptics_scale_y_nodenum ||
896 node.sysctl_num == synaptics_scale_z_nodenum) {
897 if (t < 1 || t > (SYNAPTICS_EDGE_MAX / 4))
898 return (EINVAL);
899 } else
900 if (node.sysctl_num == synaptics_finger_high_nodenum) {
901 if (t < 0 || t > SYNAPTICS_FINGER_PALM ||
902 t < synaptics_finger_low)
903 return (EINVAL);
904 } else
905 if (node.sysctl_num == synaptics_finger_low_nodenum) {
906 if (t < 0 || t > SYNAPTICS_FINGER_PALM ||
907 t > synaptics_finger_high)
908 return (EINVAL);
909 } else
910 if (node.sysctl_num == synaptics_gesture_move_nodenum ||
911 node.sysctl_num == synaptics_movement_threshold_nodenum) {
912 if (t < 0 || t > (SYNAPTICS_EDGE_MAX / 4))
913 return (EINVAL);
914 } else
915 if (node.sysctl_num == synaptics_button_boundary_nodenum) {
916 if (t < 0 || t < SYNAPTICS_EDGE_BOTTOM ||
917 t > SYNAPTICS_EDGE_TOP)
918 return (EINVAL);
919 } else
920 if (node.sysctl_num == synaptics_button2_nodenum ||
921 node.sysctl_num == synaptics_button3_nodenum) {
922 if (t < SYNAPTICS_EDGE_LEFT || t > SYNAPTICS_EDGE_RIGHT)
923 return (EINVAL);
924 } else
925 if (node.sysctl_num == synaptics_finger_scroll_min_nodenum ||
926 node.sysctl_num == synaptics_finger_scroll_max_nodenum) {
927 /* make sure we avoid the "magic" widths, 4 and below
928 are for fingers, 15 is palm detect. */
929 if ((t < 5) || (t > 14))
930 return (EINVAL);
931 } else
932 if (node.sysctl_num == synaptics_dz_hold_nodenum) {
933 if (t < 0)
934 return (EINVAL);
935 } else
936 if (node.sysctl_num == synaptics_movement_enable_nodenum) {
937 if (t < 0 || t > 1)
938 return (EINVAL);
939 } else
940 if (node.sysctl_num == synaptics_aux_mid_button_scroll_nodenum) {
941 if (t < 0 || t > 1)
942 return (EINVAL);
943 } else
944 return (EINVAL);
945
946 *(int *)rnode->sysctl_data = t;
947
948 return (0);
949 }
950
951 /* Masks for the first byte of a packet */
952 #define PMS_LBUTMASK 0x01
953 #define PMS_RBUTMASK 0x02
954 #define PMS_MBUTMASK 0x04
955
956 static void
957 pms_synaptics_parse(struct pms_softc *psc)
958 {
959 struct synaptics_softc *sc = &psc->u.synaptics;
960 struct synaptics_packet sp;
961 char new_buttons, ew_mode;
962
963 memset(&sp, 0, sizeof(sp));
964
965 /* Width of finger */
966 sp.sp_w = ((psc->packet[0] & 0x30) >> 2) +
967 ((psc->packet[0] & 0x04) >> 1) +
968 ((psc->packet[3] & 0x04) >> 2);
969 sp.sp_finger = 0;
970 if (sp.sp_w == SYNAPTICS_WIDTH_EXTENDED_W) {
971 ew_mode = psc->packet[5] >> 4;
972 switch (ew_mode)
973 {
974 case SYNAPTICS_EW_WHEEL:
975 /* scroll wheel report, ignore for now */
976 aprint_debug_dev(psc->sc_dev, "mouse wheel packet\n");
977 return;
978
979 case SYNAPTICS_EW_SECONDARY_FINGER:
980 /* parse the second finger report */
981
982 sp.sp_finger = 1; /* just one other finger for now */
983 sp.sp_x = psc->packet[1]
984 + ((psc->packet[4] & 0x0f) << 8);
985 sp.sp_y = psc->packet[2]
986 + ((psc->packet[4] & 0xf0) << 4);
987 sp.sp_z = (psc->packet[3] & 0x30)
988 + (psc->packet[5] & 0x0f);
989
990 /* keep same buttons down as primary */
991 sp.sp_left = sc->button_history & PMS_LBUTMASK;
992 sp.sp_middle = sc->button_history & PMS_MBUTMASK;
993 sp.sp_right = sc->button_history & PMS_RBUTMASK;
994 break;
995
996 case SYNAPTICS_EW_FINGER_STATUS:
997 /* reports which finger is primary/secondary
998 * ignore for now.
999 */
1000 return;
1001
1002 default:
1003 aprint_error_dev(psc->sc_dev,
1004 "invalid extended w mode %d\n",
1005 ew_mode);
1006 return;
1007 }
1008 } else {
1009
1010 /* Absolute X/Y coordinates of finger */
1011 sp.sp_x = psc->packet[4] + ((psc->packet[1] & 0x0f) << 8) +
1012 ((psc->packet[3] & 0x10) << 8);
1013 sp.sp_y = psc->packet[5] + ((psc->packet[1] & 0xf0) << 4) +
1014 ((psc->packet[3] & 0x20) << 7);
1015
1016 /* Pressure */
1017 sp.sp_z = psc->packet[2];
1018
1019 if ((psc->packet[0] ^ psc->packet[3]) & 0x02) {
1020 /* extended buttons */
1021
1022 aprint_debug_dev(psc->sc_dev,
1023 "synaptics_parse: %02x %02x %02x %02x %02x %02x\n",
1024 psc->packet[0], psc->packet[1], psc->packet[2],
1025 psc->packet[3], psc->packet[4], psc->packet[5]);
1026
1027 if ((psc->packet[4] & SYN_1BUTMASK) != 0)
1028 sc->ext_left = PMS_LBUTMASK;
1029 else
1030 sc->ext_left = 0;
1031
1032 if ((psc->packet[4] & SYN_3BUTMASK) != 0)
1033 sc->ext_middle = PMS_MBUTMASK;
1034 else
1035 sc->ext_middle = 0;
1036
1037 if ((psc->packet[5] & SYN_2BUTMASK) != 0)
1038 sc->ext_right = PMS_RBUTMASK;
1039 else
1040 sc->ext_right = 0;
1041
1042 if ((psc->packet[5] & SYN_4BUTMASK) != 0)
1043 sc->ext_up = 1;
1044 else
1045 sc->ext_up = 0;
1046
1047 if ((psc->packet[4] & SYN_5BUTMASK) != 0)
1048 sc->ext_down = 1;
1049 else
1050 sc->ext_down = 0;
1051 } else {
1052 /* Left/Right button handling. */
1053 sp.sp_left = psc->packet[0] & PMS_LBUTMASK;
1054 sp.sp_right = psc->packet[0] & PMS_RBUTMASK;
1055 }
1056
1057 /* Up/Down buttons. */
1058 if (sc->flags & SYN_FLAG_HAS_BUTTONS_4_5) {
1059 /* Old up/down buttons. */
1060 sp.sp_up = sp.sp_left ^
1061 (psc->packet[3] & PMS_LBUTMASK);
1062 sp.sp_down = sp.sp_right ^
1063 (psc->packet[3] & PMS_RBUTMASK);
1064 } else if (sc->flags & SYN_FLAG_HAS_UP_DOWN_BUTTONS &&
1065 ((psc->packet[0] & PMS_RBUTMASK) ^
1066 (psc->packet[3] & PMS_RBUTMASK))) {
1067 /* New up/down button. */
1068 sp.sp_up = psc->packet[4] & SYN_1BUTMASK;
1069 sp.sp_down = psc->packet[5] & SYN_2BUTMASK;
1070 } else {
1071 sp.sp_up = 0;
1072 sp.sp_down = 0;
1073 }
1074
1075 new_buttons = 0;
1076 if(sc->flags & SYN_FLAG_HAS_ONE_BUTTON_CLICKPAD) {
1077 /* This is not correctly specified. Read this button press
1078 * from L/U bit. Emulate 3 buttons by checking the
1079 * coordinates of the click and returning the appropriate
1080 * button code. Outside the button region default to a
1081 * left click.
1082 */
1083 u_char bstate = (psc->packet[0] ^ psc->packet[3])
1084 & 0x01;
1085 if (sp.sp_y < synaptics_button_boundary) {
1086 if (sp.sp_x > synaptics_button3) {
1087 sp.sp_right =
1088 bstate ? PMS_RBUTMASK : 0;
1089 } else if (sp.sp_x > synaptics_button2) {
1090 sp.sp_middle =
1091 bstate ? PMS_MBUTMASK : 0;
1092 } else {
1093 sp.sp_left = bstate ? PMS_LBUTMASK : 0;
1094 }
1095 } else
1096 sp.sp_left = bstate ? 1 : 0;
1097 new_buttons = sp.sp_left | sp.sp_middle | sp.sp_right;
1098 if (new_buttons != sc->button_history) {
1099 if (sc->button_history == 0)
1100 sc->button_history = new_buttons;
1101 else if (new_buttons == 0) {
1102 sc->button_history = 0;
1103 /* ensure all buttons are cleared just in
1104 * case finger comes off in a different
1105 * region.
1106 */
1107 sp.sp_left = 0;
1108 sp.sp_middle = 0;
1109 sp.sp_right = 0;
1110 } else {
1111 /* make sure we keep the same button even
1112 * if the finger moves to a different
1113 * region. This precludes chording
1114 * but, oh well.
1115 */
1116 sp.sp_left = sc->button_history & PMS_LBUTMASK;
1117 sp.sp_middle = sc->button_history
1118 & PMS_MBUTMASK;
1119 sp.sp_right = sc->button_history & PMS_RBUTMASK;
1120 }
1121 }
1122 } else if (sc->flags & SYN_FLAG_HAS_MIDDLE_BUTTON) {
1123 /* Old style Middle Button. */
1124 sp.sp_middle = (psc->packet[0] & PMS_LBUTMASK) ^
1125 (psc->packet[3] & PMS_LBUTMASK);
1126 } else if (synaptics_up_down_emul != 1) {
1127 sp.sp_middle = 0;
1128 }
1129
1130 /* Overlay extended button state */
1131 sp.sp_left |= sc->ext_left;
1132 sp.sp_right |= sc->ext_right;
1133 sp.sp_middle |= sc->ext_middle;
1134 sp.sp_up |= sc->ext_up;
1135 sp.sp_down |= sc->ext_down;
1136
1137 switch (synaptics_up_down_emul) {
1138 case 1:
1139 /* Do middle button emulation using up/down buttons */
1140 sp.sp_middle = sp.sp_up | sp.sp_down;
1141 sp.sp_up = sp.sp_down = 0;
1142 break;
1143 case 3:
1144 /* Do left/right button emulation using up/down buttons */
1145 sp.sp_left = sp.sp_left | sp.sp_up;
1146 sp.sp_right = sp.sp_right | sp.sp_down;
1147 sp.sp_up = sp.sp_down = 0;
1148 break;
1149 default:
1150 /*
1151 * Don't do any remapping...
1152 * Z-axis emulation is handled in pms_synaptics_process_packet
1153 */
1154 break;
1155 }
1156 }
1157
1158 pms_synaptics_process_packet(psc, &sp);
1159 }
1160
1161 /*
1162 * Passthrough is used for e.g. TrackPoints and additional pointing
1163 * devices connected to a Synaptics touchpad.
1164 */
1165 static void
1166 pms_synaptics_passthrough(struct pms_softc *psc)
1167 {
1168 int dx, dy, dz;
1169 int buttons, changed;
1170 int s;
1171
1172 buttons = ((psc->packet[1] & PMS_LBUTMASK) ? 0x20 : 0) |
1173 ((psc->packet[1] & PMS_MBUTMASK) ? 0x40 : 0) |
1174 ((psc->packet[1] & PMS_RBUTMASK) ? 0x80 : 0);
1175
1176 dx = psc->packet[4];
1177 if (dx >= 128)
1178 dx -= 256;
1179 if (dx == -128)
1180 dx = -127;
1181
1182 dy = psc->packet[5];
1183 if (dy >= 128)
1184 dy -= 256;
1185 if (dy == -128)
1186 dy = -127;
1187
1188 dz = 0;
1189
1190 changed = buttons ^ (psc->buttons & 0xe0);
1191 psc->buttons ^= changed;
1192
1193 if (dx || dy || dz || changed) {
1194 /*
1195 * If the middle button is held, interpret Y-axis
1196 * movement as scrolling.
1197 */
1198 if (synaptics_aux_mid_button_scroll &&
1199 dy && (psc->buttons & 0x2)) {
1200 dz = -dy;
1201 dx = dy = 0;
1202 }
1203 buttons = (psc->buttons & 0x1f) | ((psc->buttons >> 5) & 0x7);
1204 s = spltty();
1205 wsmouse_input(psc->sc_wsmousedev,
1206 buttons, dx, dy, dz, 0,
1207 WSMOUSE_INPUT_DELTA);
1208 splx(s);
1209 }
1210 }
1211
1212 static void
1213 pms_synaptics_input(void *vsc, int data)
1214 {
1215 struct pms_softc *psc = vsc;
1216 struct timeval diff;
1217
1218 if (!psc->sc_enabled) {
1219 /* Interrupts are not expected. Discard the byte. */
1220 return;
1221 }
1222
1223 getmicrouptime(&psc->current);
1224
1225 if (psc->inputstate > 0) {
1226 timersub(&psc->current, &psc->last, &diff);
1227 if (diff.tv_sec > 0 || diff.tv_usec >= 40000) {
1228 aprint_debug_dev(psc->sc_dev,
1229 "pms_input: unusual delay (%ld.%06ld s), "
1230 "scheduling reset\n",
1231 (long)diff.tv_sec, (long)diff.tv_usec);
1232 printf("pms_input: unusual delay (%ld.%06ld s), "
1233 "scheduling reset\n",
1234 (long)diff.tv_sec, (long)diff.tv_usec);
1235 psc->inputstate = 0;
1236 psc->sc_enabled = 0;
1237 wakeup(&psc->sc_enabled);
1238 return;
1239 }
1240 }
1241 psc->last = psc->current;
1242
1243 switch (psc->inputstate) {
1244 case -5:
1245 case -4:
1246 case -3:
1247 case -2:
1248 case -1:
1249 case 0:
1250 if ((data & 0xc8) != 0x80) {
1251 aprint_debug_dev(psc->sc_dev,
1252 "pms_input: 0x%02x out of sync\n", data);
1253 /* use negative counts to limit resync phase */
1254 psc->inputstate--;
1255 return; /* not in sync yet, discard input */
1256 }
1257 psc->inputstate = 0;
1258 /*FALLTHROUGH*/
1259
1260 case -6:
1261 case 3:
1262 if ((data & 8) == 8) {
1263 aprint_debug_dev(psc->sc_dev,
1264 "pms_input: dropped in relative mode, reset\n");
1265 psc->inputstate = 0;
1266 psc->sc_enabled = 0;
1267 wakeup(&psc->sc_enabled);
1268 return;
1269 }
1270 }
1271
1272 psc->packet[psc->inputstate++] = data & 0xff;
1273 if (psc->inputstate == 6) {
1274 /*
1275 * We have a complete packet.
1276 * Extract the pertinent details.
1277 */
1278 psc->inputstate = 0;
1279 if ((psc->packet[0] & 0xfc) == 0x84 &&
1280 (psc->packet[3] & 0xcc) == 0xc4) {
1281 /* W = SYNAPTICS_WIDTH_PASSTHROUGH, PS/2 passthrough */
1282 pms_synaptics_passthrough(psc);
1283 } else {
1284 pms_synaptics_parse(psc);
1285 }
1286 }
1287 }
1288
1289 static inline int
1290 synaptics_finger_detect(struct synaptics_softc *sc, struct synaptics_packet *sp,
1291 int *palmp)
1292 {
1293 int fingers;
1294
1295 /* Assume no palm */
1296 *palmp = 0;
1297
1298 /*
1299 * Apply some hysteresis when checking for a finger.
1300 * When the finger is first applied, we ignore it until the
1301 * pressure exceeds the 'high' threshold. The finger is considered
1302 * removed only when pressure falls beneath the 'low' threshold.
1303 */
1304 if ((sc->prev_fingers == 0 && sp->sp_z > synaptics_finger_high) ||
1305 (sc->prev_fingers != 0 && sp->sp_z > synaptics_finger_low))
1306 fingers = 1;
1307 else
1308 fingers = 0;
1309
1310 /*
1311 * If the pad can't do palm detection, skip the rest.
1312 */
1313 if (fingers == 0 || (sc->flags & SYN_FLAG_HAS_PALM_DETECT) == 0)
1314 return (fingers);
1315
1316 /*
1317 * Palm detection
1318 */
1319 if (sp->sp_z > SYNAPTICS_FINGER_FLAT &&
1320 sp->sp_w >= SYNAPTICS_WIDTH_PALM_MIN)
1321 *palmp = 1;
1322
1323 if (sc->prev_fingers == 0 &&
1324 (sp->sp_z > SYNAPTICS_FINGER_FLAT ||
1325 sp->sp_w >= SYNAPTICS_WIDTH_PALM_MIN)) {
1326 /*
1327 * Contact area or pressure is too great to be a finger.
1328 * Just ignore it for now.
1329 */
1330 return (0);
1331 }
1332
1333 /*
1334 * Detect 2 and 3 fingers if supported, but only if multiple
1335 * fingers appear within the tap gesture time period.
1336 */
1337 if (sc->flags & SYN_FLAG_HAS_MULTI_FINGER &&
1338 SYN_TIME(sc, sc->gesture_start_packet,
1339 sp->sp_finger) < synaptics_gesture_length) {
1340 switch (sp->sp_w) {
1341 case SYNAPTICS_WIDTH_TWO_FINGERS:
1342 fingers = 2;
1343 break;
1344
1345 case SYNAPTICS_WIDTH_THREE_OR_MORE:
1346 fingers = 3;
1347 break;
1348
1349 case SYNAPTICS_WIDTH_PEN:
1350 fingers = 1;
1351 break;
1352
1353 default:
1354 /*
1355 * The width value can report spurious single-finger
1356 * events after a multi-finger event.
1357 */
1358 if (sc->prev_fingers > 1)
1359 fingers = sc->prev_fingers;
1360 else
1361 fingers = 1;
1362 break;
1363 }
1364 }
1365
1366 return (fingers);
1367 }
1368
1369 static inline void
1370 synaptics_gesture_detect(struct synaptics_softc *sc,
1371 struct synaptics_packet *sp, int fingers)
1372 {
1373 int gesture_len, gesture_buttons;
1374 int set_buttons;
1375
1376 gesture_len = SYN_TIME(sc, sc->gesture_start_packet, sp->sp_finger);
1377 gesture_buttons = sc->gesture_buttons;
1378
1379 if (fingers > 0 && (fingers == sc->prev_fingers)) {
1380 /* Finger is still present */
1381 sc->gesture_move_x = abs(sc->gesture_start_x - sp->sp_x);
1382 sc->gesture_move_y = abs(sc->gesture_start_y - sp->sp_y);
1383 } else
1384 if (fingers && sc->prev_fingers == 0) {
1385 /*
1386 * Finger was just applied.
1387 * If the previous gesture was a single-click, set things
1388 * up to deal with a possible drag or double-click gesture.
1389 * Basically, if the finger is removed again within
1390 * 'synaptics_gesture_length' packets, this is treated
1391 * as a double-click. Otherwise we will emulate holding
1392 * the left button down whilst dragging the mouse.
1393 */
1394 if (SYN_IS_SINGLE_TAP(sc->gesture_type))
1395 sc->gesture_type |= SYN_GESTURE_DRAG;
1396
1397 sc->gesture_start_x = abs(sp->sp_x);
1398 sc->gesture_start_y = abs(sp->sp_y);
1399 sc->gesture_move_x = 0;
1400 sc->gesture_move_y = 0;
1401 sc->gesture_start_packet = sc->total_packets[0];
1402
1403 #ifdef DIAGNOSTIC
1404 aprint_debug("Finger applied: gesture_start_x: %d gesture_start_y: %d\n",
1405 sc->gesture_start_x, sc->gesture_start_y);
1406 #endif
1407 } else
1408 if (fingers == 0 && sc->prev_fingers != 0) {
1409 /*
1410 * Finger was just removed.
1411 * Check if the contact time and finger movement were
1412 * small enough to qualify as a gesture.
1413 * Ignore finger movement if multiple fingers were
1414 * detected (the pad may report coordinates for any
1415 * of the fingers).
1416 */
1417
1418 #ifdef DIAGNOSTIC
1419 aprint_debug("Finger removed: gesture_len: %d (%d)\n",
1420 gesture_len, synaptics_gesture_length);
1421 aprint_debug("gesture_move_x: %d (%d) sp_x: %d\n",
1422 sc->gesture_move_x, synaptics_gesture_move, abs(sp->sp_x));
1423 aprint_debug("gesture_move_y: %d (%d) sp_y: %d\n",
1424 sc->gesture_move_y, synaptics_gesture_move, abs(sp->sp_y));
1425 #endif
1426
1427 if (gesture_len < synaptics_gesture_length &&
1428 ((sc->gesture_move_x < synaptics_gesture_move &&
1429 sc->gesture_move_y < synaptics_gesture_move))) {
1430 /*
1431 * Looking good so far.
1432 */
1433 if (SYN_IS_DRAG(sc->gesture_type)) {
1434 /*
1435 * Promote this gesture to double-click.
1436 */
1437 sc->gesture_type |= SYN_GESTURE_DOUBLE;
1438 sc->gesture_type &= ~SYN_GESTURE_SINGLE;
1439 } else {
1440 /*
1441 * Single tap gesture. Set the tap length timer
1442 * and flag a single-click.
1443 */
1444 sc->gesture_tap_packet = sc->total_packets[0];
1445 sc->gesture_type |= SYN_GESTURE_SINGLE;
1446
1447 /*
1448 * The gesture can be modified depending on
1449 * the number of fingers detected.
1450 *
1451 * 1: Normal left button emulation.
1452 * 2: Either middle button or right button
1453 * depending on the value of the two_fingers
1454 * sysctl variable.
1455 * 3: Right button.
1456 */
1457 switch (sc->prev_fingers) {
1458 case 2:
1459 if (synaptics_two_fingers_emul == 1)
1460 gesture_buttons |= PMS_RBUTMASK;
1461 else
1462 if (synaptics_two_fingers_emul == 2)
1463 gesture_buttons |= PMS_MBUTMASK;
1464 break;
1465 case 3:
1466 gesture_buttons |= PMS_RBUTMASK;
1467 break;
1468 default:
1469 gesture_buttons |= PMS_LBUTMASK;
1470 break;
1471 }
1472 }
1473 }
1474
1475 /*
1476 * Always clear drag state when the finger is removed.
1477 */
1478 sc->gesture_type &= ~SYN_GESTURE_DRAG;
1479 }
1480
1481 if (sc->gesture_type == 0) {
1482 /*
1483 * There is no gesture in progress.
1484 * Clear emulated button state.
1485 */
1486 sc->gesture_buttons = 0;
1487 return;
1488 }
1489
1490 /*
1491 * A gesture is in progress.
1492 */
1493 set_buttons = 0;
1494
1495 if (SYN_IS_SINGLE_TAP(sc->gesture_type)) {
1496 /*
1497 * Single-click.
1498 * Activate the relevant button(s) until the
1499 * gesture tap timer has expired.
1500 */
1501 if (SYN_TIME(sc, sc->gesture_tap_packet, sp->sp_finger) <
1502 synaptics_gesture_length)
1503 set_buttons = 1;
1504 else
1505 sc->gesture_type &= ~SYN_GESTURE_SINGLE;
1506 } else
1507 if (SYN_IS_DOUBLE_TAP(sc->gesture_type) && sc->prev_fingers == 0) {
1508 /*
1509 * Double-click.
1510 * Activate the relevant button(s) once.
1511 */
1512 set_buttons = 1;
1513 sc->gesture_type &= ~SYN_GESTURE_DOUBLE;
1514 }
1515
1516 if (set_buttons || SYN_IS_DRAG(sc->gesture_type)) {
1517 /*
1518 * Single-click and drag.
1519 * Maintain button state until the finger is removed.
1520 */
1521 sp->sp_left |= gesture_buttons & PMS_LBUTMASK;
1522 sp->sp_right |= gesture_buttons & PMS_RBUTMASK;
1523 sp->sp_middle |= gesture_buttons & PMS_MBUTMASK;
1524 }
1525
1526 sc->gesture_buttons = gesture_buttons;
1527 }
1528
1529 static inline int
1530 synaptics_filter_policy(struct synaptics_softc *sc, int finger, int *history,
1531 int value)
1532 {
1533 int a, b, rv, count;
1534
1535 count = sc->total_packets[finger];
1536
1537 /*
1538 * Once we've accumulated at least SYN_HIST_SIZE values, combine
1539 * each new value with the previous two and return the average.
1540 *
1541 * This is necessary when the touchpad is operating in 80 packets
1542 * per second mode, as it performs little internal filtering on
1543 * reported values.
1544 *
1545 * Using a rolling average helps to filter out jitter caused by
1546 * tiny finger movements.
1547 */
1548 if (sc->movement_history[finger] >= SYN_HIST_SIZE) {
1549 a = (history[(count + 0) % SYN_HIST_SIZE] +
1550 history[(count + 1) % SYN_HIST_SIZE]) / 2;
1551
1552 b = (value + history[(count + 0) % SYN_HIST_SIZE]) / 2;
1553
1554 rv = b - a;
1555
1556 /*
1557 * Don't report the movement if it's below a certain
1558 * threshold.
1559 */
1560 if (abs(rv) < synaptics_movement_threshold)
1561 rv = 0;
1562 } else
1563 rv = 0;
1564
1565 /*
1566 * Add the new value to the history buffer.
1567 */
1568 history[(count + 1) % SYN_HIST_SIZE] = value;
1569
1570 return (rv);
1571 }
1572
1573 /* Edge detection */
1574 #define SYN_EDGE_TOP 1
1575 #define SYN_EDGE_BOTTOM 2
1576 #define SYN_EDGE_LEFT 4
1577 #define SYN_EDGE_RIGHT 8
1578
1579 static inline int
1580 synaptics_check_edge(int x, int y)
1581 {
1582 int rv = 0;
1583
1584 if (x < synaptics_edge_left)
1585 rv |= SYN_EDGE_LEFT;
1586 else
1587 if (x > synaptics_edge_right)
1588 rv |= SYN_EDGE_RIGHT;
1589
1590 if (y < synaptics_edge_bottom)
1591 rv |= SYN_EDGE_BOTTOM;
1592 else
1593 if (y > synaptics_edge_top)
1594 rv |= SYN_EDGE_TOP;
1595
1596 return (rv);
1597 }
1598
1599 static inline int
1600 synaptics_edge_motion(struct synaptics_softc *sc, int delta, int dir)
1601 {
1602
1603 /*
1604 * When edge motion is enabled, synaptics_edge_motion_delta is
1605 * combined with the current delta, together with the direction
1606 * in which to simulate the motion. The result is added to
1607 * the delta derived from finger movement. This provides a smooth
1608 * transition from finger movement to edge motion.
1609 */
1610 delta = synaptics_edge_motion_delta + (dir * delta);
1611 if (delta < 0)
1612 return (0);
1613 if (delta > synaptics_edge_motion_delta)
1614 return (synaptics_edge_motion_delta);
1615 return (delta);
1616 }
1617
1618 static inline int
1619 synaptics_scale(int delta, int scale, int *remp)
1620 {
1621 int rv;
1622
1623 /*
1624 * Scale the raw delta in Synaptics coordinates (0-6143) into
1625 * something more reasonable by dividing the raw delta by a
1626 * scale factor. Any remainder from the previous scale result
1627 * is added to the current delta before scaling.
1628 * This prevents loss of resolution for very small/slow
1629 * movements of the finger.
1630 */
1631 delta += *remp;
1632 rv = delta / scale;
1633 *remp = delta % scale;
1634
1635 return (rv);
1636 }
1637
1638 static inline void
1639 synaptics_movement(struct synaptics_softc *sc, struct synaptics_packet *sp,
1640 int finger, int scroll_emul, int *dxp, int *dyp, int *dzp)
1641 {
1642 int dx, dy, dz, edge;
1643
1644 dx = dy = dz = 0;
1645
1646 /*
1647 * Compute the next values of dx and dy and dz. If scroll_emul
1648 * is non-zero, take the dy and used it as use it as dz so we
1649 * can emulate a scroll wheel.
1650 */
1651 if (scroll_emul == 0) {
1652 dx = synaptics_filter_policy(sc, finger, sc->history_x[finger],
1653 sp->sp_x);
1654 dy = synaptics_filter_policy(sc, finger, sc->history_y[finger],
1655 sp->sp_y);
1656 } else {
1657 dz = synaptics_filter_policy(sc, finger, sc->history_z[finger],
1658 sp->sp_y);
1659 dx = dy = 0;
1660 }
1661
1662 /*
1663 * If we're dealing with a drag gesture, and the finger moves to
1664 * the edge of the touchpad, apply edge motion emulation if it
1665 * is enabled.
1666 */
1667 if (synaptics_edge_motion_delta && SYN_IS_DRAG(sc->gesture_type)) {
1668 edge = synaptics_check_edge(sp->sp_x, sp->sp_y);
1669
1670 if (edge & SYN_EDGE_LEFT)
1671 dx -= synaptics_edge_motion(sc, dx, 1);
1672 if (edge & SYN_EDGE_RIGHT)
1673 dx += synaptics_edge_motion(sc, dx, -1);
1674 if (edge & SYN_EDGE_BOTTOM)
1675 dy -= synaptics_edge_motion(sc, dy, 1);
1676 if (edge & SYN_EDGE_TOP)
1677 dy += synaptics_edge_motion(sc, dy, -1);
1678 }
1679
1680 /*
1681 * Apply scaling to the deltas
1682 */
1683 dx = synaptics_scale(dx, synaptics_scale_x, &sc->rem_x[finger]);
1684 dy = synaptics_scale(dy, synaptics_scale_y, &sc->rem_y[finger]);
1685 dz = synaptics_scale(dz, synaptics_scale_z, &sc->rem_z[finger]);
1686
1687 /*
1688 * Clamp deltas to specified maximums.
1689 */
1690 if (abs(dx) > synaptics_max_speed_x)
1691 dx = ((dx >= 0)? 1 : -1) * synaptics_max_speed_x;
1692 if (abs(dy) > synaptics_max_speed_y)
1693 dy = ((dy >= 0)? 1 : -1) * synaptics_max_speed_y;
1694 if (abs(dz) > synaptics_max_speed_z)
1695 dz = ((dz >= 0)? 1 : -1) * synaptics_max_speed_z;
1696
1697 *dxp = dx;
1698 *dyp = dy;
1699 *dzp = dz;
1700
1701 sc->movement_history[finger]++;
1702 }
1703
1704 static void
1705 pms_synaptics_process_packet(struct pms_softc *psc, struct synaptics_packet *sp)
1706 {
1707 struct synaptics_softc *sc = &psc->u.synaptics;
1708 int dx, dy, dz;
1709 int fingers, palm, buttons, changed;
1710 int s, z_emul;
1711
1712 /*
1713 * Do Z-axis emulation using up/down buttons if required.
1714 * Note that the pad will send a one second burst of packets
1715 * when an up/down button is pressed and held. At the moment
1716 * we don't deal with auto-repeat, so convert the burst into
1717 * a one-shot.
1718 */
1719 dz = 0;
1720 if (synaptics_up_down_emul == 2) {
1721 if (sc->up_down == 0) {
1722 if (sp->sp_up && sp->sp_down) {
1723 /*
1724 * Most up/down buttons will be actuated using
1725 * a rocker switch, so we should never see
1726 * them both simultaneously. But just in case,
1727 * treat this situation as a middle button
1728 * event.
1729 */
1730 sp->sp_middle = 1;
1731 } else
1732 if (sp->sp_up)
1733 dz = -synaptics_up_down_motion_delta;
1734 else
1735 if (sp->sp_down)
1736 dz = synaptics_up_down_motion_delta;
1737 }
1738
1739 sc->up_down = sp->sp_up | sp->sp_down;
1740 sp->sp_up = sp->sp_down = 0;
1741 }
1742
1743 /*
1744 * Determine whether or not a finger is on the pad.
1745 * On some pads, this will return the number of fingers
1746 * detected.
1747 */
1748 fingers = synaptics_finger_detect(sc, sp, &palm);
1749
1750 /*
1751 * Do gesture processing only if we didn't detect a palm and
1752 * it is not the seondary finger.
1753 */
1754 if ((sp->sp_finger == 0) && (palm == 0))
1755 synaptics_gesture_detect(sc, sp, fingers);
1756 else
1757 sc->gesture_type = sc->gesture_buttons = 0;
1758
1759 /*
1760 * Determine what buttons to report
1761 */
1762 buttons = (sp->sp_left ? 0x1 : 0) |
1763 (sp->sp_middle ? 0x2 : 0) |
1764 (sp->sp_right ? 0x4 : 0) |
1765 (sp->sp_up ? 0x8 : 0) |
1766 (sp->sp_down ? 0x10 : 0);
1767 changed = buttons ^ (psc->buttons & 0x1f);
1768 psc->buttons ^= changed;
1769
1770 sc->prev_fingers = fingers;
1771 sc->total_packets[sp->sp_finger]++;
1772
1773 /*
1774 * Do movement processing IFF we have a single finger and no palm or
1775 * a secondary finger and no palm.
1776 */
1777 if (palm == 0 && synaptics_movement_enable) {
1778 if (fingers == 1) {
1779 z_emul = 0;
1780
1781 if ((sp->sp_w >= synaptics_fscroll_min) &&
1782 (sp->sp_w <= synaptics_fscroll_max)) {
1783 z_emul = 1;
1784 sc->dz_hold = synaptics_dz_hold;
1785 }
1786
1787 if (sc->dz_hold > 0) {
1788 z_emul = 1;
1789 }
1790
1791 synaptics_movement(sc, sp, sp->sp_finger,
1792 z_emul, &dx, &dy, &dz);
1793 } else {
1794 /*
1795 * No valid finger. Therefore no movement.
1796 */
1797 sc->movement_history[sp->sp_finger] = 0;
1798 sc->rem_x[sp->sp_finger] = sc->rem_y[sp->sp_finger] = 0;
1799 dx = dy = 0;
1800 }
1801 } else {
1802 /*
1803 * No valid finger. Therefore no movement.
1804 */
1805 sc->movement_history[0] = 0;
1806 sc->rem_x[0] = sc->rem_y[0] = sc->rem_z[0] = 0;
1807 dx = dy = dz = 0;
1808 }
1809
1810 if (sc->dz_hold > 0)
1811 sc->dz_hold--;
1812
1813 /*
1814 * Pass the final results up to wsmouse_input() if necessary.
1815 */
1816 if (dx || dy || dz || changed) {
1817 buttons = (psc->buttons & 0x1f) | ((psc->buttons >> 5) & 0x7);
1818 s = spltty();
1819 wsmouse_input(psc->sc_wsmousedev,
1820 buttons,
1821 dx, dy, dz, 0,
1822 WSMOUSE_INPUT_DELTA);
1823 splx(s);
1824 }
1825 }
1826