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