1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2012 Huang Wen Hui
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #include "opt_evdev.h"
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/malloc.h>
35 #include <sys/module.h>
36 #include <sys/lock.h>
37 #include <sys/mutex.h>
38 #include <sys/bus.h>
39 #include <sys/conf.h>
40 #include <sys/fcntl.h>
41 #include <sys/file.h>
42 #include <sys/selinfo.h>
43 #include <sys/poll.h>
44 #include <sys/sysctl.h>
45
46 #include <dev/hid/hid.h>
47
48 #include <dev/usb/usb.h>
49 #include <dev/usb/usbdi.h>
50 #include <dev/usb/usbdi_util.h>
51 #include <dev/usb/usbhid.h>
52
53 #include "usbdevs.h"
54
55 #define USB_DEBUG_VAR wsp_debug
56 #include <dev/usb/usb_debug.h>
57
58 #ifdef EVDEV_SUPPORT
59 #include <dev/evdev/input.h>
60 #include <dev/evdev/evdev.h>
61 #endif
62
63 #include <sys/mouse.h>
64
65 #define WSP_DRIVER_NAME "wsp"
66 #define WSP_BUFFER_MAX 1024
67
68 #define WSP_CLAMP(x,low,high) do { \
69 if ((x) < (low)) \
70 (x) = (low); \
71 else if ((x) > (high)) \
72 (x) = (high); \
73 } while (0)
74
75 /* Tunables */
76 static SYSCTL_NODE(_hw_usb, OID_AUTO, wsp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
77 "USB wsp");
78
79 #ifdef USB_DEBUG
80 enum wsp_log_level {
81 WSP_LLEVEL_DISABLED = 0,
82 WSP_LLEVEL_ERROR,
83 WSP_LLEVEL_DEBUG, /* for troubleshooting */
84 WSP_LLEVEL_INFO, /* for diagnostics */
85 };
86 static int wsp_debug = WSP_LLEVEL_ERROR;/* the default is to only log errors */
87
88 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, debug, CTLFLAG_RWTUN,
89 &wsp_debug, WSP_LLEVEL_ERROR, "WSP debug level");
90 #endif /* USB_DEBUG */
91
92 static struct wsp_tuning {
93 int scale_factor;
94 int z_factor;
95 int z_invert;
96 int pressure_touch_threshold;
97 int pressure_untouch_threshold;
98 int pressure_tap_threshold;
99 int scr_hor_threshold;
100 int enable_single_tap_clicks;
101 }
102 wsp_tuning =
103 {
104 .scale_factor = 12,
105 .z_factor = 5,
106 .z_invert = 0,
107 .pressure_touch_threshold = 50,
108 .pressure_untouch_threshold = 10,
109 .pressure_tap_threshold = 120,
110 .scr_hor_threshold = 20,
111 .enable_single_tap_clicks = 1,
112 };
113
114 static void
wsp_runing_rangecheck(struct wsp_tuning * ptun)115 wsp_runing_rangecheck(struct wsp_tuning *ptun)
116 {
117 WSP_CLAMP(ptun->scale_factor, 1, 63);
118 WSP_CLAMP(ptun->z_factor, 1, 63);
119 WSP_CLAMP(ptun->z_invert, 0, 1);
120 WSP_CLAMP(ptun->pressure_touch_threshold, 1, 255);
121 WSP_CLAMP(ptun->pressure_untouch_threshold, 1, 255);
122 WSP_CLAMP(ptun->pressure_tap_threshold, 1, 255);
123 WSP_CLAMP(ptun->scr_hor_threshold, 1, 255);
124 WSP_CLAMP(ptun->enable_single_tap_clicks, 0, 1);
125 }
126
127 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, scale_factor, CTLFLAG_RWTUN,
128 &wsp_tuning.scale_factor, 0, "movement scale factor");
129 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, z_factor, CTLFLAG_RWTUN,
130 &wsp_tuning.z_factor, 0, "Z-axis scale factor");
131 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, z_invert, CTLFLAG_RWTUN,
132 &wsp_tuning.z_invert, 0, "enable Z-axis inversion");
133 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, pressure_touch_threshold, CTLFLAG_RWTUN,
134 &wsp_tuning.pressure_touch_threshold, 0, "touch pressure threshold");
135 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, pressure_untouch_threshold, CTLFLAG_RWTUN,
136 &wsp_tuning.pressure_untouch_threshold, 0, "untouch pressure threshold");
137 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, pressure_tap_threshold, CTLFLAG_RWTUN,
138 &wsp_tuning.pressure_tap_threshold, 0, "tap pressure threshold");
139 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, scr_hor_threshold, CTLFLAG_RWTUN,
140 &wsp_tuning.scr_hor_threshold, 0, "horizontal scrolling threshold");
141 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, enable_single_tap_clicks, CTLFLAG_RWTUN,
142 &wsp_tuning.enable_single_tap_clicks, 0, "enable single tap clicks");
143
144 /*
145 * Some tables, structures, definitions and constant values for the
146 * touchpad protocol has been copied from Linux's
147 * "drivers/input/mouse/bcm5974.c" which has the following copyright
148 * holders under GPLv2. All device specific code in this driver has
149 * been written from scratch. The decoding algorithm is based on
150 * output from FreeBSD's usbdump.
151 *
152 * Copyright (C) 2008 Henrik Rydberg (rydberg@euromail.se)
153 * Copyright (C) 2008 Scott Shawcroft (scott.shawcroft@gmail.com)
154 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
155 * Copyright (C) 2005 Johannes Berg (johannes@sipsolutions.net)
156 * Copyright (C) 2005 Stelian Pop (stelian@popies.net)
157 * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de)
158 * Copyright (C) 2005 Peter Osterlund (petero2@telia.com)
159 * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch)
160 * Copyright (C) 2006 Nicolas Boichat (nicolas@boichat.ch)
161 */
162
163 /* button data structure */
164 struct bt_data {
165 uint8_t unknown1; /* constant */
166 uint8_t button; /* left button */
167 uint8_t rel_x; /* relative x coordinate */
168 uint8_t rel_y; /* relative y coordinate */
169 } __packed;
170
171 /* trackpad header types */
172 enum tp_type {
173 TYPE1, /* plain trackpad */
174 TYPE2, /* button integrated in trackpad */
175 TYPE3, /* additional header fields since June 2013 */
176 TYPE4, /* additional header field for pressure data */
177 TYPE_CNT
178 };
179
180 /* trackpad finger data offsets, le16-aligned */
181 #define FINGER_TYPE1 (13 * 2)
182 #define FINGER_TYPE2 (15 * 2)
183 #define FINGER_TYPE3 (19 * 2)
184 #define FINGER_TYPE4 (23 * 2)
185
186 /* trackpad button data offsets */
187 #define BUTTON_TYPE2 15
188 #define BUTTON_TYPE3 23
189 #define BUTTON_TYPE4 31
190
191 /* list of device capability bits */
192 #define HAS_INTEGRATED_BUTTON 1
193
194 /* trackpad finger data block size */
195 #define FSIZE_TYPE1 (14 * 2)
196 #define FSIZE_TYPE2 (14 * 2)
197 #define FSIZE_TYPE3 (14 * 2)
198 #define FSIZE_TYPE4 (15 * 2)
199
200 struct wsp_tp {
201 uint8_t caps; /* device capability bitmask */
202 uint8_t button; /* offset to button data */
203 uint8_t offset; /* offset to trackpad finger data */
204 uint8_t fsize; /* bytes in single finger block */
205 uint8_t delta; /* offset from header to finger struct */
206 uint8_t iface_index;
207 uint8_t um_size; /* usb control message length */
208 uint8_t um_req_idx; /* usb control message index */
209 uint8_t um_switch_idx; /* usb control message mode switch index */
210 uint8_t um_switch_on; /* usb control message mode switch on */
211 uint8_t um_switch_off; /* usb control message mode switch off */
212 } const static wsp_tp[TYPE_CNT] = {
213 [TYPE1] = {
214 .caps = 0,
215 .button = 0,
216 .offset = FINGER_TYPE1,
217 .fsize = FSIZE_TYPE1,
218 .delta = 0,
219 .iface_index = 0,
220 .um_size = 8,
221 .um_req_idx = 0x00,
222 .um_switch_idx = 0,
223 .um_switch_on = 0x01,
224 .um_switch_off = 0x08,
225 },
226 [TYPE2] = {
227 .caps = HAS_INTEGRATED_BUTTON,
228 .button = BUTTON_TYPE2,
229 .offset = FINGER_TYPE2,
230 .fsize = FSIZE_TYPE2,
231 .delta = 0,
232 .iface_index = 0,
233 .um_size = 8,
234 .um_req_idx = 0x00,
235 .um_switch_idx = 0,
236 .um_switch_on = 0x01,
237 .um_switch_off = 0x08,
238 },
239 [TYPE3] = {
240 .caps = HAS_INTEGRATED_BUTTON,
241 .button = BUTTON_TYPE3,
242 .offset = FINGER_TYPE3,
243 .fsize = FSIZE_TYPE3,
244 .delta = 0,
245 },
246 [TYPE4] = {
247 .caps = HAS_INTEGRATED_BUTTON,
248 .button = BUTTON_TYPE4,
249 .offset = FINGER_TYPE4,
250 .fsize = FSIZE_TYPE4,
251 .delta = 2,
252 .iface_index = 2,
253 .um_size = 2,
254 .um_req_idx = 0x02,
255 .um_switch_idx = 1,
256 .um_switch_on = 0x01,
257 .um_switch_off = 0x00,
258 },
259 };
260
261 /* trackpad finger header - little endian */
262 struct tp_header {
263 uint8_t flag;
264 uint8_t sn0;
265 uint16_t wFixed0;
266 uint32_t dwSn1;
267 uint32_t dwFixed1;
268 uint16_t wLength;
269 uint8_t nfinger;
270 uint8_t ibt;
271 int16_t wUnknown[6];
272 uint8_t q1;
273 uint8_t q2;
274 } __packed;
275
276 /* trackpad finger structure - little endian */
277 struct tp_finger {
278 int16_t origin; /* zero when switching track finger */
279 int16_t abs_x; /* absolute x coodinate */
280 int16_t abs_y; /* absolute y coodinate */
281 int16_t rel_x; /* relative x coodinate */
282 int16_t rel_y; /* relative y coodinate */
283 int16_t tool_major; /* tool area, major axis */
284 int16_t tool_minor; /* tool area, minor axis */
285 int16_t orientation; /* 16384 when point, else 15 bit angle */
286 int16_t touch_major; /* touch area, major axis */
287 int16_t touch_minor; /* touch area, minor axis */
288 int16_t unused[2]; /* zeros */
289 int16_t pressure; /* pressure on forcetouch touchpad */
290 int16_t multi; /* one finger: varies, more fingers:
291 * constant */
292 } __packed;
293
294 /* trackpad finger data size, empirically at least ten fingers */
295 #ifdef EVDEV_SUPPORT
296 #define MAX_FINGERS MAX_MT_SLOTS
297 #else
298 #define MAX_FINGERS 16
299 #endif
300 #define SIZEOF_FINGER sizeof(struct tp_finger)
301 #define SIZEOF_ALL_FINGERS (MAX_FINGERS * SIZEOF_FINGER)
302 #define MAX_FINGER_ORIENTATION 16384
303
304 #if (WSP_BUFFER_MAX < ((MAX_FINGERS * FSIZE_TYPE4) + FINGER_TYPE4))
305 #error "WSP_BUFFER_MAX is too small"
306 #endif
307
308 enum {
309 WSP_FLAG_WELLSPRING1,
310 WSP_FLAG_WELLSPRING2,
311 WSP_FLAG_WELLSPRING3,
312 WSP_FLAG_WELLSPRING4,
313 WSP_FLAG_WELLSPRING4A,
314 WSP_FLAG_WELLSPRING5,
315 WSP_FLAG_WELLSPRING6A,
316 WSP_FLAG_WELLSPRING6,
317 WSP_FLAG_WELLSPRING5A,
318 WSP_FLAG_WELLSPRING7,
319 WSP_FLAG_WELLSPRING7A,
320 WSP_FLAG_WELLSPRING8,
321 WSP_FLAG_WELLSPRING9,
322 WSP_FLAG_MAX,
323 };
324
325 /* device-specific parameters */
326 struct wsp_param {
327 int snratio; /* signal-to-noise ratio */
328 int min; /* device minimum reading */
329 int max; /* device maximum reading */
330 int size; /* physical size, mm */
331 };
332
333 /* device-specific configuration */
334 struct wsp_dev_params {
335 const struct wsp_tp* tp;
336 struct wsp_param p; /* finger pressure limits */
337 struct wsp_param w; /* finger width limits */
338 struct wsp_param x; /* horizontal limits */
339 struct wsp_param y; /* vertical limits */
340 struct wsp_param o; /* orientation limits */
341 };
342
343 /* logical signal quality */
344 #define SN_PRESSURE 45 /* pressure signal-to-noise ratio */
345 #define SN_WIDTH 25 /* width signal-to-noise ratio */
346 #define SN_COORD 250 /* coordinate signal-to-noise ratio */
347 #define SN_ORIENT 10 /* orientation signal-to-noise ratio */
348
349 static const struct wsp_dev_params wsp_dev_params[WSP_FLAG_MAX] = {
350 [WSP_FLAG_WELLSPRING1] = {
351 .tp = wsp_tp + TYPE1,
352 .p = { SN_PRESSURE, 0, 256, 0 },
353 .w = { SN_WIDTH, 0, 2048, 0 },
354 .x = { SN_COORD, -4824, 5342, 105 },
355 .y = { SN_COORD, -172, 5820, 75 },
356 .o = { SN_ORIENT,
357 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
358 },
359 [WSP_FLAG_WELLSPRING2] = {
360 .tp = wsp_tp + TYPE1,
361 .p = { SN_PRESSURE, 0, 256, 0 },
362 .w = { SN_WIDTH, 0, 2048, 0 },
363 .x = { SN_COORD, -4824, 4824, 105 },
364 .y = { SN_COORD, -172, 4290, 75 },
365 .o = { SN_ORIENT,
366 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
367 },
368 [WSP_FLAG_WELLSPRING3] = {
369 .tp = wsp_tp + TYPE2,
370 .p = { SN_PRESSURE, 0, 300, 0 },
371 .w = { SN_WIDTH, 0, 2048, 0 },
372 .x = { SN_COORD, -4460, 5166, 105 },
373 .y = { SN_COORD, -75, 6700, 75 },
374 .o = { SN_ORIENT,
375 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
376 },
377 [WSP_FLAG_WELLSPRING4] = {
378 .tp = wsp_tp + TYPE2,
379 .p = { SN_PRESSURE, 0, 300, 0 },
380 .w = { SN_WIDTH, 0, 2048, 0 },
381 .x = { SN_COORD, -4620, 5140, 105 },
382 .y = { SN_COORD, -150, 6600, 75 },
383 .o = { SN_ORIENT,
384 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
385 },
386 [WSP_FLAG_WELLSPRING4A] = {
387 .tp = wsp_tp + TYPE2,
388 .p = { SN_PRESSURE, 0, 300, 0 },
389 .w = { SN_WIDTH, 0, 2048, 0 },
390 .x = { SN_COORD, -4616, 5112, 105 },
391 .y = { SN_COORD, -142, 5234, 75 },
392 .o = { SN_ORIENT,
393 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
394 },
395 [WSP_FLAG_WELLSPRING5] = {
396 .tp = wsp_tp + TYPE2,
397 .p = { SN_PRESSURE, 0, 300, 0 },
398 .w = { SN_WIDTH, 0, 2048, 0 },
399 .x = { SN_COORD, -4415, 5050, 105 },
400 .y = { SN_COORD, -55, 6680, 75 },
401 .o = { SN_ORIENT,
402 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
403 },
404 [WSP_FLAG_WELLSPRING6] = {
405 .tp = wsp_tp + TYPE2,
406 .p = { SN_PRESSURE, 0, 300, 0 },
407 .w = { SN_WIDTH, 0, 2048, 0 },
408 .x = { SN_COORD, -4620, 5140, 105 },
409 .y = { SN_COORD, -150, 6600, 75 },
410 .o = { SN_ORIENT,
411 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
412 },
413 [WSP_FLAG_WELLSPRING5A] = {
414 .tp = wsp_tp + TYPE2,
415 .p = { SN_PRESSURE, 0, 300, 0 },
416 .w = { SN_WIDTH, 0, 2048, 0 },
417 .x = { SN_COORD, -4750, 5280, 105 },
418 .y = { SN_COORD, -150, 6730, 75 },
419 .o = { SN_ORIENT,
420 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
421 },
422 [WSP_FLAG_WELLSPRING6A] = {
423 .tp = wsp_tp + TYPE2,
424 .p = { SN_PRESSURE, 0, 300, 0 },
425 .w = { SN_WIDTH, 0, 2048, 0 },
426 .x = { SN_COORD, -4620, 5140, 105 },
427 .y = { SN_COORD, -150, 6600, 75 },
428 .o = { SN_ORIENT,
429 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
430 },
431 [WSP_FLAG_WELLSPRING7] = {
432 .tp = wsp_tp + TYPE2,
433 .p = { SN_PRESSURE, 0, 300, 0 },
434 .w = { SN_WIDTH, 0, 2048, 0 },
435 .x = { SN_COORD, -4750, 5280, 105 },
436 .y = { SN_COORD, -150, 6730, 75 },
437 .o = { SN_ORIENT,
438 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
439 },
440 [WSP_FLAG_WELLSPRING7A] = {
441 .tp = wsp_tp + TYPE2,
442 .p = { SN_PRESSURE, 0, 300, 0 },
443 .w = { SN_WIDTH, 0, 2048, 0 },
444 .x = { SN_COORD, -4750, 5280, 105 },
445 .y = { SN_COORD, -150, 6730, 75 },
446 .o = { SN_ORIENT,
447 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
448 },
449 [WSP_FLAG_WELLSPRING8] = {
450 .tp = wsp_tp + TYPE3,
451 .p = { SN_PRESSURE, 0, 300, 0 },
452 .w = { SN_WIDTH, 0, 2048, 0 },
453 .x = { SN_COORD, -4620, 5140, 105 },
454 .y = { SN_COORD, -150, 6600, 75 },
455 .o = { SN_ORIENT,
456 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
457 },
458 [WSP_FLAG_WELLSPRING9] = {
459 .tp = wsp_tp + TYPE4,
460 .p = { SN_PRESSURE, 0, 300, 0 },
461 .w = { SN_WIDTH, 0, 2048, 0 },
462 .x = { SN_COORD, -4828, 5345, 105 },
463 .y = { SN_COORD, -203, 6803, 75 },
464 .o = { SN_ORIENT,
465 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
466 },
467 };
468 #define WSP_DEV(v,p,i) { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) }
469
470 static const STRUCT_USB_HOST_ID wsp_devs[] = {
471 /* MacbookAir1.1 */
472 WSP_DEV(APPLE, WELLSPRING_ANSI, WSP_FLAG_WELLSPRING1),
473 WSP_DEV(APPLE, WELLSPRING_ISO, WSP_FLAG_WELLSPRING1),
474 WSP_DEV(APPLE, WELLSPRING_JIS, WSP_FLAG_WELLSPRING1),
475
476 /* MacbookProPenryn, aka wellspring2 */
477 WSP_DEV(APPLE, WELLSPRING2_ANSI, WSP_FLAG_WELLSPRING2),
478 WSP_DEV(APPLE, WELLSPRING2_ISO, WSP_FLAG_WELLSPRING2),
479 WSP_DEV(APPLE, WELLSPRING2_JIS, WSP_FLAG_WELLSPRING2),
480
481 /* Macbook5,1 (unibody), aka wellspring3 */
482 WSP_DEV(APPLE, WELLSPRING3_ANSI, WSP_FLAG_WELLSPRING3),
483 WSP_DEV(APPLE, WELLSPRING3_ISO, WSP_FLAG_WELLSPRING3),
484 WSP_DEV(APPLE, WELLSPRING3_JIS, WSP_FLAG_WELLSPRING3),
485
486 /* MacbookAir3,2 (unibody), aka wellspring4 */
487 WSP_DEV(APPLE, WELLSPRING4_ANSI, WSP_FLAG_WELLSPRING4),
488 WSP_DEV(APPLE, WELLSPRING4_ISO, WSP_FLAG_WELLSPRING4),
489 WSP_DEV(APPLE, WELLSPRING4_JIS, WSP_FLAG_WELLSPRING4),
490
491 /* MacbookAir3,1 (unibody), aka wellspring4 */
492 WSP_DEV(APPLE, WELLSPRING4A_ANSI, WSP_FLAG_WELLSPRING4A),
493 WSP_DEV(APPLE, WELLSPRING4A_ISO, WSP_FLAG_WELLSPRING4A),
494 WSP_DEV(APPLE, WELLSPRING4A_JIS, WSP_FLAG_WELLSPRING4A),
495
496 /* Macbook8 (unibody, March 2011) */
497 WSP_DEV(APPLE, WELLSPRING5_ANSI, WSP_FLAG_WELLSPRING5),
498 WSP_DEV(APPLE, WELLSPRING5_ISO, WSP_FLAG_WELLSPRING5),
499 WSP_DEV(APPLE, WELLSPRING5_JIS, WSP_FLAG_WELLSPRING5),
500
501 /* MacbookAir4,1 (unibody, July 2011) */
502 WSP_DEV(APPLE, WELLSPRING6A_ANSI, WSP_FLAG_WELLSPRING6A),
503 WSP_DEV(APPLE, WELLSPRING6A_ISO, WSP_FLAG_WELLSPRING6A),
504 WSP_DEV(APPLE, WELLSPRING6A_JIS, WSP_FLAG_WELLSPRING6A),
505
506 /* MacbookAir4,2 (unibody, July 2011) */
507 WSP_DEV(APPLE, WELLSPRING6_ANSI, WSP_FLAG_WELLSPRING6),
508 WSP_DEV(APPLE, WELLSPRING6_ISO, WSP_FLAG_WELLSPRING6),
509 WSP_DEV(APPLE, WELLSPRING6_JIS, WSP_FLAG_WELLSPRING6),
510
511 /* Macbook8,2 (unibody) */
512 WSP_DEV(APPLE, WELLSPRING5A_ANSI, WSP_FLAG_WELLSPRING5A),
513 WSP_DEV(APPLE, WELLSPRING5A_ISO, WSP_FLAG_WELLSPRING5A),
514 WSP_DEV(APPLE, WELLSPRING5A_JIS, WSP_FLAG_WELLSPRING5A),
515
516 /* MacbookPro10,1 (unibody, June 2012) */
517 /* MacbookPro11,1-3 (unibody, June 2013) */
518 WSP_DEV(APPLE, WELLSPRING7_ANSI, WSP_FLAG_WELLSPRING7),
519 WSP_DEV(APPLE, WELLSPRING7_ISO, WSP_FLAG_WELLSPRING7),
520 WSP_DEV(APPLE, WELLSPRING7_JIS, WSP_FLAG_WELLSPRING7),
521
522 /* MacbookPro10,2 (unibody, October 2012) */
523 WSP_DEV(APPLE, WELLSPRING7A_ANSI, WSP_FLAG_WELLSPRING7A),
524 WSP_DEV(APPLE, WELLSPRING7A_ISO, WSP_FLAG_WELLSPRING7A),
525 WSP_DEV(APPLE, WELLSPRING7A_JIS, WSP_FLAG_WELLSPRING7A),
526
527 /* MacbookAir6,2 (unibody, June 2013) */
528 WSP_DEV(APPLE, WELLSPRING8_ANSI, WSP_FLAG_WELLSPRING8),
529 WSP_DEV(APPLE, WELLSPRING8_ISO, WSP_FLAG_WELLSPRING8),
530 WSP_DEV(APPLE, WELLSPRING8_JIS, WSP_FLAG_WELLSPRING8),
531
532 /* MacbookPro12,1 MacbookPro11,4 */
533 WSP_DEV(APPLE, WELLSPRING9_ANSI, WSP_FLAG_WELLSPRING9),
534 WSP_DEV(APPLE, WELLSPRING9_ISO, WSP_FLAG_WELLSPRING9),
535 WSP_DEV(APPLE, WELLSPRING9_JIS, WSP_FLAG_WELLSPRING9),
536 };
537
538 #define WSP_FIFO_BUF_SIZE 8 /* bytes */
539 #define WSP_FIFO_QUEUE_MAXLEN 50 /* units */
540
541 enum {
542 WSP_INTR_DT,
543 WSP_N_TRANSFER,
544 };
545
546 struct wsp_softc {
547 struct usb_device *sc_usb_device;
548 struct mtx sc_mutex; /* for synchronization */
549 struct usb_xfer *sc_xfer[WSP_N_TRANSFER];
550 struct usb_fifo_sc sc_fifo;
551
552 const struct wsp_dev_params *sc_params; /* device configuration */
553
554 #ifdef EVDEV_SUPPORT
555 struct evdev_dev *sc_evdev;
556 #endif
557 mousehw_t sc_hw;
558 mousemode_t sc_mode;
559 u_int sc_pollrate;
560 mousestatus_t sc_status;
561 int sc_fflags;
562 u_int sc_state;
563 #define WSP_ENABLED 0x01
564 #define WSP_EVDEV_OPENED 0x02
565
566 struct tp_finger *index[MAX_FINGERS]; /* finger index data */
567 int16_t pos_x[MAX_FINGERS]; /* position array */
568 int16_t pos_y[MAX_FINGERS]; /* position array */
569 u_int sc_touch; /* touch status */
570 #define WSP_UNTOUCH 0x00
571 #define WSP_FIRST_TOUCH 0x01
572 #define WSP_SECOND_TOUCH 0x02
573 #define WSP_TOUCHING 0x04
574 int16_t pre_pos_x; /* previous position array */
575 int16_t pre_pos_y; /* previous position array */
576 int dx_sum; /* x axis cumulative movement */
577 int dy_sum; /* y axis cumulative movement */
578 int dz_sum; /* z axis cumulative movement */
579 int dz_count;
580 #define WSP_DZ_MAX_COUNT 32
581 int dt_sum; /* T-axis cumulative movement */
582 int rdx; /* x axis remainder of divide by scale_factor */
583 int rdy; /* y axis remainder of divide by scale_factor */
584 int rdz; /* z axis remainder of divide by scale_factor */
585 int tp_datalen;
586 uint8_t o_ntouch; /* old touch finger status */
587 uint8_t finger; /* 0 or 1 *, check which finger moving */
588 uint16_t intr_count;
589 #define WSP_TAP_THRESHOLD 3
590 #define WSP_TAP_MAX_COUNT 20
591 int distance; /* the distance of 2 fingers */
592 #define MAX_DISTANCE 2500 /* the max allowed distance */
593 uint8_t ibtn; /* button status in tapping */
594 uint8_t ntaps; /* finger status in tapping */
595 uint8_t scr_mode; /* scroll status in movement */
596 #define WSP_SCR_NONE 0
597 #define WSP_SCR_VER 1
598 #define WSP_SCR_HOR 2
599 uint8_t tp_data[WSP_BUFFER_MAX] __aligned(4); /* trackpad transferred data */
600 };
601
602 /*
603 * function prototypes
604 */
605 static usb_fifo_cmd_t wsp_fifo_start_read;
606 static usb_fifo_cmd_t wsp_fifo_stop_read;
607 static usb_fifo_open_t wsp_open;
608 static usb_fifo_close_t wsp_close;
609 static usb_fifo_ioctl_t wsp_ioctl;
610
611 static struct usb_fifo_methods wsp_fifo_methods = {
612 .f_open = &wsp_open,
613 .f_close = &wsp_close,
614 .f_ioctl = &wsp_ioctl,
615 .f_start_read = &wsp_fifo_start_read,
616 .f_stop_read = &wsp_fifo_stop_read,
617 .basename[0] = WSP_DRIVER_NAME,
618 };
619
620 #ifdef EVDEV_SUPPORT
621 static evdev_open_t wsp_ev_open;
622 static evdev_close_t wsp_ev_close;
623 static const struct evdev_methods wsp_evdev_methods = {
624 .ev_open = &wsp_ev_open,
625 .ev_close = &wsp_ev_close,
626 };
627 #endif
628
629 /* device initialization and shutdown */
630 static int wsp_enable(struct wsp_softc *sc);
631 static void wsp_disable(struct wsp_softc *sc);
632
633 /* updating fifo */
634 static void wsp_reset_buf(struct wsp_softc *sc);
635 static void wsp_add_to_queue(struct wsp_softc *, int, int, int, uint32_t);
636
637 /* Device methods. */
638 static device_probe_t wsp_probe;
639 static device_attach_t wsp_attach;
640 static device_detach_t wsp_detach;
641 static usb_callback_t wsp_intr_callback;
642
643 static const struct usb_config wsp_config[WSP_N_TRANSFER] = {
644 [WSP_INTR_DT] = {
645 .type = UE_INTERRUPT,
646 .endpoint = UE_ADDR_ANY,
647 .direction = UE_DIR_IN,
648 .flags = {
649 .pipe_bof = 0,
650 .short_xfer_ok = 1,
651 },
652 .bufsize = WSP_BUFFER_MAX,
653 .callback = &wsp_intr_callback,
654 },
655 };
656
657 static usb_error_t
wsp_set_device_mode(struct wsp_softc * sc,uint8_t on)658 wsp_set_device_mode(struct wsp_softc *sc, uint8_t on)
659 {
660 const struct wsp_dev_params *params = sc->sc_params;
661 uint8_t mode_bytes[8];
662 usb_error_t err;
663
664 /* Type 3 does not require a mode switch */
665 if (params->tp == wsp_tp + TYPE3)
666 return 0;
667
668 err = usbd_req_get_report(sc->sc_usb_device, NULL,
669 mode_bytes, params->tp->um_size, params->tp->iface_index,
670 UHID_FEATURE_REPORT, params->tp->um_req_idx);
671
672 if (err != USB_ERR_NORMAL_COMPLETION) {
673 DPRINTF("Failed to read device mode (%d)\n", err);
674 return (err);
675 }
676
677 /*
678 * XXX Need to wait at least 250ms for hardware to get
679 * ready. The device mode handling appears to be handled
680 * asynchronously and we should not issue these commands too
681 * quickly.
682 */
683 pause("WHW", hz / 4);
684
685 mode_bytes[params->tp->um_switch_idx] =
686 on ? params->tp->um_switch_on : params->tp->um_switch_off;
687
688 return (usbd_req_set_report(sc->sc_usb_device, NULL,
689 mode_bytes, params->tp->um_size, params->tp->iface_index,
690 UHID_FEATURE_REPORT, params->tp->um_req_idx));
691 }
692
693 static int
wsp_enable(struct wsp_softc * sc)694 wsp_enable(struct wsp_softc *sc)
695 {
696 /* reset status */
697 memset(&sc->sc_status, 0, sizeof(sc->sc_status));
698 sc->sc_state |= WSP_ENABLED;
699
700 DPRINTFN(WSP_LLEVEL_INFO, "enabled wsp\n");
701 return (0);
702 }
703
704 static void
wsp_disable(struct wsp_softc * sc)705 wsp_disable(struct wsp_softc *sc)
706 {
707 sc->sc_state &= ~WSP_ENABLED;
708 DPRINTFN(WSP_LLEVEL_INFO, "disabled wsp\n");
709 }
710
711 static int
wsp_probe(device_t self)712 wsp_probe(device_t self)
713 {
714 struct usb_attach_arg *uaa = device_get_ivars(self);
715 struct usb_interface_descriptor *id;
716 struct usb_interface *iface;
717 uint8_t i;
718
719 if (uaa->usb_mode != USB_MODE_HOST)
720 return (ENXIO);
721
722 /* figure out first interface matching */
723 for (i = 1;; i++) {
724 iface = usbd_get_iface(uaa->device, i);
725 if (iface == NULL || i == 3)
726 return (ENXIO);
727 id = iface->idesc;
728 if ((id == NULL) ||
729 (id->bInterfaceClass != UICLASS_HID) ||
730 (id->bInterfaceProtocol != 0 &&
731 id->bInterfaceProtocol != UIPROTO_MOUSE))
732 continue;
733 break;
734 }
735 /* check if we are attaching to the first match */
736 if (uaa->info.bIfaceIndex != i)
737 return (ENXIO);
738 if (usbd_lookup_id_by_uaa(wsp_devs, sizeof(wsp_devs), uaa) != 0)
739 return (ENXIO);
740
741 return (BUS_PROBE_DEFAULT);
742 }
743
744 static int
wsp_attach(device_t dev)745 wsp_attach(device_t dev)
746 {
747 struct wsp_softc *sc = device_get_softc(dev);
748 struct usb_attach_arg *uaa = device_get_ivars(dev);
749 usb_error_t err;
750 void *d_ptr = NULL;
751 uint16_t d_len;
752
753 DPRINTFN(WSP_LLEVEL_INFO, "sc=%p\n", sc);
754
755 /* Get HID descriptor */
756 err = usbd_req_get_hid_desc(uaa->device, NULL, &d_ptr,
757 &d_len, M_TEMP, uaa->info.bIfaceIndex);
758
759 if (err == USB_ERR_NORMAL_COMPLETION) {
760 /* Get HID report descriptor length */
761 sc->tp_datalen = hid_report_size_max(d_ptr, d_len, hid_input,
762 NULL);
763 free(d_ptr, M_TEMP);
764
765 if (sc->tp_datalen <= 0 || sc->tp_datalen > WSP_BUFFER_MAX) {
766 DPRINTF("Invalid datalength or too big "
767 "datalength: %d\n", sc->tp_datalen);
768 return (ENXIO);
769 }
770 } else {
771 return (ENXIO);
772 }
773
774 sc->sc_usb_device = uaa->device;
775
776 /* get device specific configuration */
777 sc->sc_params = wsp_dev_params + USB_GET_DRIVER_INFO(uaa);
778
779 /*
780 * By default the touchpad behaves like a HID device, sending
781 * packets with reportID = 8. Such reports contain only
782 * limited information. They encode movement deltas and button
783 * events, but do not include data from the pressure
784 * sensors. The device input mode can be switched from HID
785 * reports to raw sensor data using vendor-specific USB
786 * control commands:
787 */
788
789 /*
790 * During re-enumeration of the device we need to force the
791 * device back into HID mode before switching it to RAW
792 * mode. Else the device does not work like expected.
793 */
794 err = wsp_set_device_mode(sc, 0);
795 if (err != USB_ERR_NORMAL_COMPLETION) {
796 DPRINTF("Failed to set mode to HID MODE (%d)\n", err);
797 return (ENXIO);
798 }
799
800 err = wsp_set_device_mode(sc, 1);
801 if (err != USB_ERR_NORMAL_COMPLETION) {
802 DPRINTF("failed to set mode to RAW MODE (%d)\n", err);
803 return (ENXIO);
804 }
805
806 mtx_init(&sc->sc_mutex, "wspmtx", NULL, MTX_DEF | MTX_RECURSE);
807
808 err = usbd_transfer_setup(uaa->device,
809 &uaa->info.bIfaceIndex, sc->sc_xfer, wsp_config,
810 WSP_N_TRANSFER, sc, &sc->sc_mutex);
811 if (err) {
812 DPRINTF("error=%s\n", usbd_errstr(err));
813 goto detach;
814 }
815 if (usb_fifo_attach(sc->sc_usb_device, sc, &sc->sc_mutex,
816 &wsp_fifo_methods, &sc->sc_fifo,
817 device_get_unit(dev), -1, uaa->info.bIfaceIndex,
818 UID_ROOT, GID_OPERATOR, 0644)) {
819 goto detach;
820 }
821 device_set_usb_desc(dev);
822
823 sc->sc_hw.buttons = 3;
824 sc->sc_hw.iftype = MOUSE_IF_USB;
825 sc->sc_hw.type = MOUSE_PAD;
826 sc->sc_hw.model = MOUSE_MODEL_GENERIC;
827 sc->sc_mode.protocol = MOUSE_PROTO_MSC;
828 sc->sc_mode.rate = -1;
829 sc->sc_mode.resolution = MOUSE_RES_UNKNOWN;
830 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE;
831 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
832 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC;
833
834 sc->sc_touch = WSP_UNTOUCH;
835 sc->scr_mode = WSP_SCR_NONE;
836
837 #ifdef EVDEV_SUPPORT
838 sc->sc_evdev = evdev_alloc();
839 evdev_set_name(sc->sc_evdev, device_get_desc(dev));
840 evdev_set_phys(sc->sc_evdev, device_get_nameunit(dev));
841 evdev_set_id(sc->sc_evdev, BUS_USB, uaa->info.idVendor,
842 uaa->info.idProduct, 0);
843 evdev_set_serial(sc->sc_evdev, usb_get_serial(uaa->device));
844 evdev_set_methods(sc->sc_evdev, sc, &wsp_evdev_methods);
845 evdev_support_prop(sc->sc_evdev, INPUT_PROP_POINTER);
846 evdev_support_event(sc->sc_evdev, EV_SYN);
847 evdev_support_event(sc->sc_evdev, EV_ABS);
848 evdev_support_event(sc->sc_evdev, EV_KEY);
849
850 #define WSP_SUPPORT_ABS(evdev, code, param) \
851 evdev_support_abs((evdev), (code), (param).min, (param).max, \
852 ((param).max - (param).min) / (param).snratio, 0, \
853 (param).size != 0 ? ((param).max - (param).min) / (param).size : 0);
854
855 /* finger position */
856 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_POSITION_X, sc->sc_params->x);
857 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_POSITION_Y, sc->sc_params->y);
858 /* finger pressure */
859 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_PRESSURE, sc->sc_params->p);
860 /* finger touch area */
861 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_TOUCH_MAJOR, sc->sc_params->w);
862 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_TOUCH_MINOR, sc->sc_params->w);
863 /* finger approach area */
864 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_WIDTH_MAJOR, sc->sc_params->w);
865 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_WIDTH_MINOR, sc->sc_params->w);
866 /* finger orientation */
867 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_ORIENTATION, sc->sc_params->o);
868 /* button properties */
869 evdev_support_key(sc->sc_evdev, BTN_LEFT);
870 if ((sc->sc_params->tp->caps & HAS_INTEGRATED_BUTTON) != 0)
871 evdev_support_prop(sc->sc_evdev, INPUT_PROP_BUTTONPAD);
872 /* Enable automatic touch assignment for type B MT protocol */
873 evdev_support_abs(sc->sc_evdev, ABS_MT_SLOT,
874 0, MAX_FINGERS - 1, 0, 0, 0);
875 evdev_support_abs(sc->sc_evdev, ABS_MT_TRACKING_ID,
876 -1, MAX_FINGERS - 1, 0, 0, 0);
877 evdev_set_flag(sc->sc_evdev, EVDEV_FLAG_MT_TRACK);
878 evdev_set_flag(sc->sc_evdev, EVDEV_FLAG_MT_AUTOREL);
879 /* Synaptics compatibility events */
880 evdev_set_flag(sc->sc_evdev, EVDEV_FLAG_MT_STCOMPAT);
881
882 err = evdev_register(sc->sc_evdev);
883 if (err)
884 goto detach;
885 #endif
886
887 return (0);
888
889 detach:
890 wsp_detach(dev);
891 return (ENOMEM);
892 }
893
894 static int
wsp_detach(device_t dev)895 wsp_detach(device_t dev)
896 {
897 struct wsp_softc *sc = device_get_softc(dev);
898
899 (void) wsp_set_device_mode(sc, 0);
900
901 mtx_lock(&sc->sc_mutex);
902 if (sc->sc_state & WSP_ENABLED)
903 wsp_disable(sc);
904 mtx_unlock(&sc->sc_mutex);
905
906 usb_fifo_detach(&sc->sc_fifo);
907
908 #ifdef EVDEV_SUPPORT
909 evdev_free(sc->sc_evdev);
910 #endif
911
912 usbd_transfer_unsetup(sc->sc_xfer, WSP_N_TRANSFER);
913
914 mtx_destroy(&sc->sc_mutex);
915
916 return (0);
917 }
918
919 static void
wsp_intr_callback(struct usb_xfer * xfer,usb_error_t error)920 wsp_intr_callback(struct usb_xfer *xfer, usb_error_t error)
921 {
922 struct wsp_softc *sc = usbd_xfer_softc(xfer);
923 const struct wsp_dev_params *params = sc->sc_params;
924 struct usb_page_cache *pc;
925 struct tp_finger *f;
926 struct wsp_tuning tun = wsp_tuning;
927 int ntouch = 0; /* the finger number in touch */
928 int ibt = 0; /* button status */
929 int dx = 0;
930 int dy = 0;
931 int dz = 0;
932 int rdx = 0;
933 int rdy = 0;
934 int rdz = 0;
935 int len;
936 int i;
937 #ifdef EVDEV_SUPPORT
938 int slot = 0;
939 #endif
940
941 wsp_runing_rangecheck(&tun);
942
943 if (sc->dz_count == 0)
944 sc->dz_count = WSP_DZ_MAX_COUNT;
945
946 usbd_xfer_status(xfer, &len, NULL, NULL, NULL);
947
948 switch (USB_GET_STATE(xfer)) {
949 case USB_ST_TRANSFERRED:
950
951 /* copy out received data */
952 pc = usbd_xfer_get_frame(xfer, 0);
953 usbd_copy_out(pc, 0, sc->tp_data, len);
954
955 if ((len < params->tp->offset + params->tp->fsize) ||
956 ((len - params->tp->offset) % params->tp->fsize) != 0) {
957 DPRINTFN(WSP_LLEVEL_INFO, "Invalid length: %d, %x, %x\n",
958 len, sc->tp_data[0], sc->tp_data[1]);
959 goto tr_setup;
960 }
961
962 if (len < sc->tp_datalen) {
963 /* make sure we don't process old data */
964 memset(sc->tp_data + len, 0, sc->tp_datalen - len);
965 }
966
967 if (params->tp != wsp_tp + TYPE1) {
968 ibt = sc->tp_data[params->tp->button];
969 ntouch = sc->tp_data[params->tp->button - 1];
970 } else
971 ntouch = (len - params->tp->offset) / params->tp->fsize;
972
973 /* range check */
974 if (ntouch < 0)
975 ntouch = 0;
976 else if (ntouch > MAX_FINGERS)
977 ntouch = MAX_FINGERS;
978
979 for (i = 0; i != ntouch; i++) {
980 f = (struct tp_finger *)(sc->tp_data + params->tp->offset + params->tp->delta + i * params->tp->fsize);
981 /* swap endianness, if any */
982 if (le16toh(0x1234) != 0x1234) {
983 f->origin = le16toh((uint16_t)f->origin);
984 f->abs_x = le16toh((uint16_t)f->abs_x);
985 f->abs_y = le16toh((uint16_t)f->abs_y);
986 f->rel_x = le16toh((uint16_t)f->rel_x);
987 f->rel_y = le16toh((uint16_t)f->rel_y);
988 f->tool_major = le16toh((uint16_t)f->tool_major);
989 f->tool_minor = le16toh((uint16_t)f->tool_minor);
990 f->orientation = le16toh((uint16_t)f->orientation);
991 f->touch_major = le16toh((uint16_t)f->touch_major);
992 f->touch_minor = le16toh((uint16_t)f->touch_minor);
993 f->pressure = le16toh((uint16_t)f->pressure);
994 f->multi = le16toh((uint16_t)f->multi);
995 }
996 DPRINTFN(WSP_LLEVEL_INFO,
997 "[%d]ibt=%d, taps=%d, o=%4d, ax=%5d, ay=%5d, "
998 "rx=%5d, ry=%5d, tlmaj=%4d, tlmin=%4d, ot=%4x, "
999 "tchmaj=%4d, tchmin=%4d, presure=%4d, m=%4x\n",
1000 i, ibt, ntouch, f->origin, f->abs_x, f->abs_y,
1001 f->rel_x, f->rel_y, f->tool_major, f->tool_minor, f->orientation,
1002 f->touch_major, f->touch_minor, f->pressure, f->multi);
1003 sc->pos_x[i] = f->abs_x;
1004 sc->pos_y[i] = -f->abs_y;
1005 sc->index[i] = f;
1006 #ifdef EVDEV_SUPPORT
1007 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE && f->touch_major != 0) {
1008 union evdev_mt_slot slot_data = {
1009 .id = slot,
1010 .x = f->abs_x,
1011 .y = params->y.min + params->y.max - f->abs_y,
1012 .p = f->pressure,
1013 .maj = f->touch_major << 1,
1014 .min = f->touch_minor << 1,
1015 .w_maj = f->tool_major << 1,
1016 .w_min = f->tool_minor << 1,
1017 .ori = params->o.max - f->orientation,
1018 };
1019 evdev_mt_push_slot(sc->sc_evdev, slot, &slot_data);
1020 slot++;
1021 }
1022 #endif
1023 }
1024
1025 #ifdef EVDEV_SUPPORT
1026 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE) {
1027 evdev_push_key(sc->sc_evdev, BTN_LEFT, ibt);
1028 evdev_sync(sc->sc_evdev);
1029 }
1030 #endif
1031 sc->sc_status.flags &= ~MOUSE_POSCHANGED;
1032 sc->sc_status.flags &= ~MOUSE_STDBUTTONSCHANGED;
1033 sc->sc_status.obutton = sc->sc_status.button;
1034 sc->sc_status.button = 0;
1035
1036 if (ibt != 0) {
1037 if ((params->tp->caps & HAS_INTEGRATED_BUTTON) && ntouch == 2)
1038 sc->sc_status.button |= MOUSE_BUTTON3DOWN;
1039 else if ((params->tp->caps & HAS_INTEGRATED_BUTTON) && ntouch == 3)
1040 sc->sc_status.button |= MOUSE_BUTTON2DOWN;
1041 else
1042 sc->sc_status.button |= MOUSE_BUTTON1DOWN;
1043 sc->ibtn = 1;
1044 }
1045 sc->intr_count++;
1046
1047 if (sc->ntaps < ntouch) {
1048 switch (ntouch) {
1049 case 1:
1050 if (sc->index[0]->touch_major > tun.pressure_tap_threshold &&
1051 sc->index[0]->tool_major <= 1200)
1052 sc->ntaps = 1;
1053 break;
1054 case 2:
1055 if (sc->index[0]->touch_major > tun.pressure_tap_threshold-30 &&
1056 sc->index[1]->touch_major > tun.pressure_tap_threshold-30)
1057 sc->ntaps = 2;
1058 break;
1059 case 3:
1060 if (sc->index[0]->touch_major > tun.pressure_tap_threshold-40 &&
1061 sc->index[1]->touch_major > tun.pressure_tap_threshold-40 &&
1062 sc->index[2]->touch_major > tun.pressure_tap_threshold-40)
1063 sc->ntaps = 3;
1064 break;
1065 default:
1066 break;
1067 }
1068 }
1069 if (ntouch == 2) {
1070 sc->distance = max(sc->distance, max(
1071 abs(sc->pos_x[0] - sc->pos_x[1]),
1072 abs(sc->pos_y[0] - sc->pos_y[1])));
1073 }
1074 if (sc->index[0]->touch_major < tun.pressure_untouch_threshold &&
1075 sc->sc_status.button == 0) {
1076 sc->sc_touch = WSP_UNTOUCH;
1077 if (sc->intr_count < WSP_TAP_MAX_COUNT &&
1078 sc->intr_count > WSP_TAP_THRESHOLD &&
1079 sc->ntaps && sc->ibtn == 0) {
1080 /*
1081 * Add a pair of events (button-down and
1082 * button-up).
1083 */
1084 switch (sc->ntaps) {
1085 case 1:
1086 if (!(params->tp->caps & HAS_INTEGRATED_BUTTON) || tun.enable_single_tap_clicks) {
1087 wsp_add_to_queue(sc, 0, 0, 0, MOUSE_BUTTON1DOWN);
1088 DPRINTFN(WSP_LLEVEL_INFO, "LEFT CLICK!\n");
1089 }
1090 break;
1091 case 2:
1092 DPRINTFN(WSP_LLEVEL_INFO, "sum_x=%5d, sum_y=%5d\n",
1093 sc->dx_sum, sc->dy_sum);
1094 if (sc->distance < MAX_DISTANCE && abs(sc->dx_sum) < 5 &&
1095 abs(sc->dy_sum) < 5) {
1096 wsp_add_to_queue(sc, 0, 0, 0, MOUSE_BUTTON3DOWN);
1097 DPRINTFN(WSP_LLEVEL_INFO, "RIGHT CLICK!\n");
1098 }
1099 break;
1100 case 3:
1101 wsp_add_to_queue(sc, 0, 0, 0, MOUSE_BUTTON2DOWN);
1102 break;
1103 default:
1104 /* we don't handle taps of more than three fingers */
1105 break;
1106 }
1107 wsp_add_to_queue(sc, 0, 0, 0, 0); /* button release */
1108 }
1109 if ((sc->dt_sum / tun.scr_hor_threshold) != 0 &&
1110 sc->ntaps == 2 && sc->scr_mode == WSP_SCR_HOR) {
1111 /*
1112 * translate T-axis into button presses
1113 * until further
1114 */
1115 if (sc->dt_sum > 0)
1116 wsp_add_to_queue(sc, 0, 0, 0, 1UL << 3);
1117 else if (sc->dt_sum < 0)
1118 wsp_add_to_queue(sc, 0, 0, 0, 1UL << 4);
1119 }
1120 sc->dz_count = WSP_DZ_MAX_COUNT;
1121 sc->dz_sum = 0;
1122 sc->intr_count = 0;
1123 sc->ibtn = 0;
1124 sc->ntaps = 0;
1125 sc->finger = 0;
1126 sc->distance = 0;
1127 sc->dt_sum = 0;
1128 sc->dx_sum = 0;
1129 sc->dy_sum = 0;
1130 sc->rdx = 0;
1131 sc->rdy = 0;
1132 sc->rdz = 0;
1133 sc->scr_mode = WSP_SCR_NONE;
1134 } else if (sc->index[0]->touch_major >= tun.pressure_touch_threshold &&
1135 sc->sc_touch == WSP_UNTOUCH) { /* ignore first touch */
1136 sc->sc_touch = WSP_FIRST_TOUCH;
1137 } else if (sc->index[0]->touch_major >= tun.pressure_touch_threshold &&
1138 sc->sc_touch == WSP_FIRST_TOUCH) { /* ignore second touch */
1139 sc->sc_touch = WSP_SECOND_TOUCH;
1140 DPRINTFN(WSP_LLEVEL_INFO, "Fist pre_x=%5d, pre_y=%5d\n",
1141 sc->pre_pos_x, sc->pre_pos_y);
1142 } else {
1143 if (sc->sc_touch == WSP_SECOND_TOUCH)
1144 sc->sc_touch = WSP_TOUCHING;
1145
1146 if (ntouch != 0 &&
1147 sc->index[0]->touch_major >= tun.pressure_touch_threshold) {
1148 dx = sc->pos_x[0] - sc->pre_pos_x;
1149 dy = sc->pos_y[0] - sc->pre_pos_y;
1150
1151 /* Ignore movement during button is releasing */
1152 if (sc->ibtn != 0 && sc->sc_status.button == 0)
1153 dx = dy = 0;
1154
1155 /* Ignore movement if ntouch changed */
1156 if (sc->o_ntouch != ntouch)
1157 dx = dy = 0;
1158
1159 /* Ignore unexpeted movement when typing */
1160 if (ntouch == 1 && sc->index[0]->tool_major > 1200)
1161 dx = dy = 0;
1162
1163 if (sc->ibtn != 0 && ntouch == 1 &&
1164 sc->intr_count < WSP_TAP_MAX_COUNT &&
1165 abs(sc->dx_sum) < 1 && abs(sc->dy_sum) < 1 )
1166 dx = dy = 0;
1167
1168 if (ntouch == 2 && sc->sc_status.button != 0) {
1169 dx = sc->pos_x[sc->finger] - sc->pre_pos_x;
1170 dy = sc->pos_y[sc->finger] - sc->pre_pos_y;
1171
1172 /*
1173 * Ignore movement of switch finger or
1174 * movement from ibt=0 to ibt=1
1175 */
1176 if (sc->index[0]->origin == 0 || sc->index[1]->origin == 0 ||
1177 sc->sc_status.obutton != sc->sc_status.button) {
1178 dx = dy = 0;
1179 sc->finger = 0;
1180 }
1181 if ((abs(sc->index[0]->rel_x) + abs(sc->index[0]->rel_y)) <
1182 (abs(sc->index[1]->rel_x) + abs(sc->index[1]->rel_y)) &&
1183 sc->finger == 0) {
1184 sc->sc_touch = WSP_SECOND_TOUCH;
1185 dx = dy = 0;
1186 sc->finger = 1;
1187 }
1188 if ((abs(sc->index[0]->rel_x) + abs(sc->index[0]->rel_y)) >=
1189 (abs(sc->index[1]->rel_x) + abs(sc->index[1]->rel_y)) &&
1190 sc->finger == 1) {
1191 sc->sc_touch = WSP_SECOND_TOUCH;
1192 dx = dy = 0;
1193 sc->finger = 0;
1194 }
1195 DPRINTFN(WSP_LLEVEL_INFO, "dx=%5d, dy=%5d, mov=%5d\n",
1196 dx, dy, sc->finger);
1197 }
1198 if (sc->dz_count--) {
1199 rdz = (dy + sc->rdz) % tun.scale_factor;
1200 sc->dz_sum -= (dy + sc->rdz) / tun.scale_factor;
1201 sc->rdz = rdz;
1202 }
1203 if ((sc->dz_sum / tun.z_factor) != 0)
1204 sc->dz_count = 0;
1205 }
1206 rdx = (dx + sc->rdx) % tun.scale_factor;
1207 dx = (dx + sc->rdx) / tun.scale_factor;
1208 sc->rdx = rdx;
1209
1210 rdy = (dy + sc->rdy) % tun.scale_factor;
1211 dy = (dy + sc->rdy) / tun.scale_factor;
1212 sc->rdy = rdy;
1213
1214 sc->dx_sum += dx;
1215 sc->dy_sum += dy;
1216
1217 if (ntouch == 2 && sc->sc_status.button == 0) {
1218 if (sc->scr_mode == WSP_SCR_NONE &&
1219 abs(sc->dx_sum) + abs(sc->dy_sum) > tun.scr_hor_threshold)
1220 sc->scr_mode = abs(sc->dx_sum) >
1221 abs(sc->dy_sum) * 2 ? WSP_SCR_HOR : WSP_SCR_VER;
1222 DPRINTFN(WSP_LLEVEL_INFO, "scr_mode=%5d, count=%d, dx_sum=%d, dy_sum=%d\n",
1223 sc->scr_mode, sc->intr_count, sc->dx_sum, sc->dy_sum);
1224 if (sc->scr_mode == WSP_SCR_HOR)
1225 sc->dt_sum += dx;
1226 else
1227 sc->dt_sum = 0;
1228
1229 dx = dy = 0;
1230 if (sc->dz_count == 0)
1231 dz = (sc->dz_sum / tun.z_factor) * (tun.z_invert ? -1 : 1);
1232 if (sc->scr_mode == WSP_SCR_HOR ||
1233 abs(sc->pos_x[0] - sc->pos_x[1]) > MAX_DISTANCE ||
1234 abs(sc->pos_y[0] - sc->pos_y[1]) > MAX_DISTANCE)
1235 dz = 0;
1236 }
1237 if (ntouch == 3)
1238 dx = dy = dz = 0;
1239 if (sc->intr_count < WSP_TAP_MAX_COUNT &&
1240 abs(dx) < 3 && abs(dy) < 3 && abs(dz) < 3)
1241 dx = dy = dz = 0;
1242 else
1243 sc->intr_count = WSP_TAP_MAX_COUNT;
1244 if (dx || dy || dz)
1245 sc->sc_status.flags |= MOUSE_POSCHANGED;
1246 DPRINTFN(WSP_LLEVEL_INFO, "dx=%5d, dy=%5d, dz=%5d, sc_touch=%x, btn=%x\n",
1247 dx, dy, dz, sc->sc_touch, sc->sc_status.button);
1248 sc->sc_status.dx += dx;
1249 sc->sc_status.dy += dy;
1250 sc->sc_status.dz += dz;
1251
1252 wsp_add_to_queue(sc, dx, -dy, dz, sc->sc_status.button);
1253 if (sc->dz_count == 0) {
1254 sc->dz_sum = 0;
1255 sc->rdz = 0;
1256 }
1257 }
1258 sc->pre_pos_x = sc->pos_x[0];
1259 sc->pre_pos_y = sc->pos_y[0];
1260
1261 if (ntouch == 2 && sc->sc_status.button != 0) {
1262 sc->pre_pos_x = sc->pos_x[sc->finger];
1263 sc->pre_pos_y = sc->pos_y[sc->finger];
1264 }
1265 sc->o_ntouch = ntouch;
1266
1267 case USB_ST_SETUP:
1268 tr_setup:
1269 /* check if we can put more data into the FIFO */
1270 if (usb_fifo_put_bytes_max(
1271 sc->sc_fifo.fp[USB_FIFO_RX]) != 0) {
1272 usbd_xfer_set_frame_len(xfer, 0,
1273 sc->tp_datalen);
1274 usbd_transfer_submit(xfer);
1275 }
1276 break;
1277
1278 default: /* Error */
1279 if (error != USB_ERR_CANCELLED) {
1280 /* try clear stall first */
1281 usbd_xfer_set_stall(xfer);
1282 goto tr_setup;
1283 }
1284 break;
1285 }
1286 }
1287
1288 static void
wsp_add_to_queue(struct wsp_softc * sc,int dx,int dy,int dz,uint32_t buttons_in)1289 wsp_add_to_queue(struct wsp_softc *sc, int dx, int dy, int dz,
1290 uint32_t buttons_in)
1291 {
1292 uint32_t buttons_out;
1293 uint8_t buf[8];
1294
1295 dx = imin(dx, 254);
1296 dx = imax(dx, -256);
1297 dy = imin(dy, 254);
1298 dy = imax(dy, -256);
1299 dz = imin(dz, 126);
1300 dz = imax(dz, -128);
1301
1302 buttons_out = MOUSE_MSC_BUTTONS;
1303 if (buttons_in & MOUSE_BUTTON1DOWN)
1304 buttons_out &= ~MOUSE_MSC_BUTTON1UP;
1305 else if (buttons_in & MOUSE_BUTTON2DOWN)
1306 buttons_out &= ~MOUSE_MSC_BUTTON2UP;
1307 else if (buttons_in & MOUSE_BUTTON3DOWN)
1308 buttons_out &= ~MOUSE_MSC_BUTTON3UP;
1309
1310 /* Encode the mouse data in standard format; refer to mouse(4) */
1311 buf[0] = sc->sc_mode.syncmask[1];
1312 buf[0] |= buttons_out;
1313 buf[1] = dx >> 1;
1314 buf[2] = dy >> 1;
1315 buf[3] = dx - (dx >> 1);
1316 buf[4] = dy - (dy >> 1);
1317 /* Encode extra bytes for level 1 */
1318 if (sc->sc_mode.level == 1) {
1319 buf[5] = dz >> 1; /* dz / 2 */
1320 buf[6] = dz - (dz >> 1);/* dz - (dz / 2) */
1321 buf[7] = (((~buttons_in) >> 3) & MOUSE_SYS_EXTBUTTONS);
1322 }
1323 usb_fifo_put_data_linear(sc->sc_fifo.fp[USB_FIFO_RX], buf,
1324 sc->sc_mode.packetsize, 1);
1325 }
1326
1327 static void
wsp_reset_buf(struct wsp_softc * sc)1328 wsp_reset_buf(struct wsp_softc *sc)
1329 {
1330 /* reset read queue */
1331 usb_fifo_reset(sc->sc_fifo.fp[USB_FIFO_RX]);
1332 }
1333
1334 static void
wsp_start_read(struct wsp_softc * sc)1335 wsp_start_read(struct wsp_softc *sc)
1336 {
1337 int rate;
1338
1339 /* Check if we should override the default polling interval */
1340 rate = sc->sc_pollrate;
1341 /* Range check rate */
1342 if (rate > 1000)
1343 rate = 1000;
1344 /* Check for set rate */
1345 if ((rate > 0) && (sc->sc_xfer[WSP_INTR_DT] != NULL)) {
1346 /* Stop current transfer, if any */
1347 usbd_transfer_stop(sc->sc_xfer[WSP_INTR_DT]);
1348 /* Set new interval */
1349 usbd_xfer_set_interval(sc->sc_xfer[WSP_INTR_DT], 1000 / rate);
1350 /* Only set pollrate once */
1351 sc->sc_pollrate = 0;
1352 }
1353 usbd_transfer_start(sc->sc_xfer[WSP_INTR_DT]);
1354 }
1355
1356 static void
wsp_stop_read(struct wsp_softc * sc)1357 wsp_stop_read(struct wsp_softc *sc)
1358 {
1359 usbd_transfer_stop(sc->sc_xfer[WSP_INTR_DT]);
1360 }
1361
1362 static int
wsp_open(struct usb_fifo * fifo,int fflags)1363 wsp_open(struct usb_fifo *fifo, int fflags)
1364 {
1365 struct wsp_softc *sc = usb_fifo_softc(fifo);
1366 int rc = 0;
1367
1368 DPRINTFN(WSP_LLEVEL_INFO, "\n");
1369
1370 if (sc->sc_fflags & fflags)
1371 return (EBUSY);
1372
1373 if (fflags & FREAD) {
1374 if (usb_fifo_alloc_buffer(fifo,
1375 WSP_FIFO_BUF_SIZE, WSP_FIFO_QUEUE_MAXLEN)) {
1376 return (ENOMEM);
1377 }
1378 #ifdef EVDEV_SUPPORT
1379 if ((sc->sc_state & WSP_EVDEV_OPENED) == 0)
1380 #endif
1381 rc = wsp_enable(sc);
1382 if (rc != 0) {
1383 usb_fifo_free_buffer(fifo);
1384 return (rc);
1385 }
1386 }
1387 sc->sc_fflags |= fflags & (FREAD | FWRITE);
1388 return (0);
1389 }
1390
1391 static void
wsp_close(struct usb_fifo * fifo,int fflags)1392 wsp_close(struct usb_fifo *fifo, int fflags)
1393 {
1394 struct wsp_softc *sc = usb_fifo_softc(fifo);
1395
1396 if (fflags & FREAD) {
1397 #ifdef EVDEV_SUPPORT
1398 if ((sc->sc_state & WSP_EVDEV_OPENED) == 0)
1399 #endif
1400 wsp_disable(sc);
1401 usb_fifo_free_buffer(fifo);
1402 }
1403
1404 sc->sc_fflags &= ~(fflags & (FREAD | FWRITE));
1405 }
1406
1407 static void
wsp_fifo_start_read(struct usb_fifo * fifo)1408 wsp_fifo_start_read(struct usb_fifo *fifo)
1409 {
1410 struct wsp_softc *sc = usb_fifo_softc(fifo);
1411
1412 wsp_start_read(sc);
1413 }
1414
1415 static void
wsp_fifo_stop_read(struct usb_fifo * fifo)1416 wsp_fifo_stop_read(struct usb_fifo *fifo)
1417 {
1418 struct wsp_softc *sc = usb_fifo_softc(fifo);
1419
1420 #ifdef EVDEV_SUPPORT
1421 if ((sc->sc_state & WSP_EVDEV_OPENED) == 0)
1422 #endif
1423 wsp_stop_read(sc);
1424 }
1425
1426 #ifdef EVDEV_SUPPORT
1427 static int
wsp_ev_open(struct evdev_dev * evdev)1428 wsp_ev_open(struct evdev_dev *evdev)
1429 {
1430 struct wsp_softc *sc = evdev_get_softc(evdev);
1431 int rc = 0;
1432
1433 mtx_lock(&sc->sc_mutex);
1434 if (sc->sc_fflags == 0)
1435 rc = wsp_enable(sc);
1436 if (rc == 0) {
1437 wsp_start_read(sc);
1438 sc->sc_state |= WSP_EVDEV_OPENED;
1439 }
1440 mtx_unlock(&sc->sc_mutex);
1441
1442 return (rc);
1443 }
1444
1445 static int
wsp_ev_close(struct evdev_dev * evdev)1446 wsp_ev_close(struct evdev_dev *evdev)
1447 {
1448 struct wsp_softc *sc = evdev_get_softc(evdev);
1449
1450 mtx_lock(&sc->sc_mutex);
1451 sc->sc_state &= ~WSP_EVDEV_OPENED;
1452 if (sc->sc_fflags == 0)
1453 wsp_stop_read(sc);
1454 mtx_unlock(&sc->sc_mutex);
1455
1456 return (0);
1457 }
1458 #endif
1459
1460 int
wsp_ioctl(struct usb_fifo * fifo,u_long cmd,void * addr,int fflags)1461 wsp_ioctl(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags)
1462 {
1463 struct wsp_softc *sc = usb_fifo_softc(fifo);
1464 mousemode_t mode;
1465 int error = 0;
1466
1467 mtx_lock(&sc->sc_mutex);
1468
1469 switch (cmd) {
1470 case MOUSE_GETHWINFO:
1471 *(mousehw_t *)addr = sc->sc_hw;
1472 break;
1473 case MOUSE_GETMODE:
1474 *(mousemode_t *)addr = sc->sc_mode;
1475 break;
1476 case MOUSE_SETMODE:
1477 mode = *(mousemode_t *)addr;
1478
1479 if (mode.level == -1)
1480 /* Don't change the current setting */
1481 ;
1482 else if ((mode.level < 0) || (mode.level > 1)) {
1483 error = EINVAL;
1484 goto done;
1485 }
1486 sc->sc_mode.level = mode.level;
1487 sc->sc_pollrate = mode.rate;
1488 sc->sc_hw.buttons = 3;
1489
1490 if (sc->sc_mode.level == 0) {
1491 sc->sc_mode.protocol = MOUSE_PROTO_MSC;
1492 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE;
1493 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
1494 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC;
1495 } else if (sc->sc_mode.level == 1) {
1496 sc->sc_mode.protocol = MOUSE_PROTO_SYSMOUSE;
1497 sc->sc_mode.packetsize = MOUSE_SYS_PACKETSIZE;
1498 sc->sc_mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
1499 sc->sc_mode.syncmask[1] = MOUSE_SYS_SYNC;
1500 }
1501 wsp_reset_buf(sc);
1502 break;
1503 case MOUSE_GETLEVEL:
1504 *(int *)addr = sc->sc_mode.level;
1505 break;
1506 case MOUSE_SETLEVEL:
1507 if (*(int *)addr < 0 || *(int *)addr > 1) {
1508 error = EINVAL;
1509 goto done;
1510 }
1511 sc->sc_mode.level = *(int *)addr;
1512 sc->sc_hw.buttons = 3;
1513
1514 if (sc->sc_mode.level == 0) {
1515 sc->sc_mode.protocol = MOUSE_PROTO_MSC;
1516 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE;
1517 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
1518 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC;
1519 } else if (sc->sc_mode.level == 1) {
1520 sc->sc_mode.protocol = MOUSE_PROTO_SYSMOUSE;
1521 sc->sc_mode.packetsize = MOUSE_SYS_PACKETSIZE;
1522 sc->sc_mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
1523 sc->sc_mode.syncmask[1] = MOUSE_SYS_SYNC;
1524 }
1525 wsp_reset_buf(sc);
1526 break;
1527 case MOUSE_GETSTATUS:{
1528 mousestatus_t *status = (mousestatus_t *)addr;
1529
1530 *status = sc->sc_status;
1531 sc->sc_status.obutton = sc->sc_status.button;
1532 sc->sc_status.button = 0;
1533 sc->sc_status.dx = 0;
1534 sc->sc_status.dy = 0;
1535 sc->sc_status.dz = 0;
1536
1537 if (status->dx || status->dy || status->dz)
1538 status->flags |= MOUSE_POSCHANGED;
1539 if (status->button != status->obutton)
1540 status->flags |= MOUSE_BUTTONSCHANGED;
1541 break;
1542 }
1543 default:
1544 error = ENOTTY;
1545 }
1546
1547 done:
1548 mtx_unlock(&sc->sc_mutex);
1549 return (error);
1550 }
1551
1552 static device_method_t wsp_methods[] = {
1553 /* Device interface */
1554 DEVMETHOD(device_probe, wsp_probe),
1555 DEVMETHOD(device_attach, wsp_attach),
1556 DEVMETHOD(device_detach, wsp_detach),
1557 DEVMETHOD_END
1558 };
1559
1560 static driver_t wsp_driver = {
1561 .name = WSP_DRIVER_NAME,
1562 .methods = wsp_methods,
1563 .size = sizeof(struct wsp_softc)
1564 };
1565
1566 DRIVER_MODULE(wsp, uhub, wsp_driver, NULL, NULL);
1567 MODULE_DEPEND(wsp, usb, 1, 1, 1);
1568 MODULE_DEPEND(wsp, hid, 1, 1, 1);
1569 #ifdef EVDEV_SUPPORT
1570 MODULE_DEPEND(wsp, evdev, 1, 1, 1);
1571 #endif
1572 MODULE_VERSION(wsp, 1);
1573 USB_PNP_HOST_INFO(wsp_devs);
1574