2 * Copyright (c) 2012 Huang Wen Hui
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/malloc.h>
34 #include <sys/module.h>
36 #include <sys/mutex.h>
39 #include <sys/fcntl.h>
41 #include <sys/selinfo.h>
43 #include <sys/sysctl.h>
45 #include <dev/usb/usb.h>
46 #include <dev/usb/usbdi.h>
47 #include <dev/usb/usbdi_util.h>
48 #include <dev/usb/usbhid.h>
52 #define USB_DEBUG_VAR wsp_debug
53 #include <dev/usb/usb_debug.h>
55 #include <sys/mouse.h>
57 #define WSP_DRIVER_NAME "wsp"
58 #define WSP_BUFFER_MAX 1024
60 #define WSP_CLAMP(x,low,high) do { \
63 else if ((x) > (high)) \
68 static SYSCTL_NODE(_hw_usb, OID_AUTO, wsp, CTLFLAG_RW, 0, "USB wsp");
72 WSP_LLEVEL_DISABLED = 0,
74 WSP_LLEVEL_DEBUG, /* for troubleshooting */
75 WSP_LLEVEL_INFO, /* for diagnostics */
77 static int wsp_debug = WSP_LLEVEL_ERROR;/* the default is to only log errors */
79 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, debug, CTLFLAG_RW,
80 &wsp_debug, WSP_LLEVEL_ERROR, "WSP debug level");
81 #endif /* USB_DEBUG */
83 static struct wsp_tuning {
86 int pressure_touch_threshold;
87 int pressure_untouch_threshold;
88 int pressure_tap_threshold;
89 int scr_hor_threshold;
95 .pressure_touch_threshold = 50,
96 .pressure_untouch_threshold = 10,
97 .pressure_tap_threshold = 120,
98 .scr_hor_threshold = 20,
102 wsp_runing_rangecheck(struct wsp_tuning *ptun)
104 WSP_CLAMP(ptun->scale_factor, 1, 63);
105 WSP_CLAMP(ptun->z_factor, 1, 63);
106 WSP_CLAMP(ptun->pressure_touch_threshold, 1, 255);
107 WSP_CLAMP(ptun->pressure_untouch_threshold, 1, 255);
108 WSP_CLAMP(ptun->pressure_tap_threshold, 1, 255);
109 WSP_CLAMP(ptun->scr_hor_threshold, 1, 255);
112 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, scale_factor, CTLFLAG_RW,
113 &wsp_tuning.scale_factor, 0, "movement scale factor");
114 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, z_factor, CTLFLAG_RW,
115 &wsp_tuning.z_factor, 0, "Z-axis scale factor");
116 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, pressure_touch_threshold, CTLFLAG_RW,
117 &wsp_tuning.pressure_touch_threshold, 0, "touch pressure threshold");
118 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, pressure_untouch_threshold, CTLFLAG_RW,
119 &wsp_tuning.pressure_untouch_threshold, 0, "untouch pressure threshold");
120 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, pressure_tap_threshold, CTLFLAG_RW,
121 &wsp_tuning.pressure_tap_threshold, 0, "tap pressure threshold");
122 SYSCTL_INT(_hw_usb_wsp, OID_AUTO, scr_hor_threshold, CTLFLAG_RW,
123 &wsp_tuning.scr_hor_threshold, 0, "horizontal scrolling threshold");
126 * Some tables, structures, definitions and constant values for the
127 * touchpad protocol has been copied from Linux's
128 * "drivers/input/mouse/bcm5974.c" which has the following copyright
129 * holders under GPLv2. All device specific code in this driver has
130 * been written from scratch. The decoding algorithm is based on
131 * output from FreeBSD's usbdump.
133 * Copyright (C) 2008 Henrik Rydberg (rydberg@euromail.se)
134 * Copyright (C) 2008 Scott Shawcroft (scott.shawcroft@gmail.com)
135 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
136 * Copyright (C) 2005 Johannes Berg (johannes@sipsolutions.net)
137 * Copyright (C) 2005 Stelian Pop (stelian@popies.net)
138 * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de)
139 * Copyright (C) 2005 Peter Osterlund (petero2@telia.com)
140 * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch)
141 * Copyright (C) 2006 Nicolas Boichat (nicolas@boichat.ch)
144 /* button data structure */
146 uint8_t unknown1; /* constant */
147 uint8_t button; /* left button */
148 uint8_t rel_x; /* relative x coordinate */
149 uint8_t rel_y; /* relative y coordinate */
152 /* trackpad header types */
154 TYPE1, /* plain trackpad */
155 TYPE2, /* button integrated in trackpad */
156 TYPE3, /* additional header fields since June 2013 */
157 TYPE4 /* additional header field for pressure data */
160 /* trackpad finger data offsets, le16-aligned */
161 #define FINGER_TYPE1 (13 * 2)
162 #define FINGER_TYPE2 (15 * 2)
163 #define FINGER_TYPE3 (19 * 2)
164 #define FINGER_TYPE4 (23 * 2)
166 /* trackpad button data offsets */
167 #define BUTTON_TYPE2 15
168 #define BUTTON_TYPE3 23
169 #define BUTTON_TYPE4 31
171 /* list of device capability bits */
172 #define HAS_INTEGRATED_BUTTON 1
174 /* trackpad finger data block size */
175 #define FSIZE_TYPE1 (14 * 2)
176 #define FSIZE_TYPE2 (14 * 2)
177 #define FSIZE_TYPE3 (14 * 2)
178 #define FSIZE_TYPE4 (15 * 2)
180 /* trackpad finger header - little endian */
195 /* trackpad finger structure - little endian */
197 int16_t origin; /* zero when switching track finger */
198 int16_t abs_x; /* absolute x coodinate */
199 int16_t abs_y; /* absolute y coodinate */
200 int16_t rel_x; /* relative x coodinate */
201 int16_t rel_y; /* relative y coodinate */
202 int16_t tool_major; /* tool area, major axis */
203 int16_t tool_minor; /* tool area, minor axis */
204 int16_t orientation; /* 16384 when point, else 15 bit angle */
205 int16_t touch_major; /* touch area, major axis */
206 int16_t touch_minor; /* touch area, minor axis */
207 int16_t unused[2]; /* zeros */
208 int16_t pressure; /* pressure on forcetouch touchpad */
209 int16_t multi; /* one finger: varies, more fingers:
213 /* trackpad finger data size, empirically at least ten fingers */
214 #define MAX_FINGERS 16
215 #define SIZEOF_FINGER sizeof(struct tp_finger)
216 #define SIZEOF_ALL_FINGERS (MAX_FINGERS * SIZEOF_FINGER)
218 #if (WSP_BUFFER_MAX < ((MAX_FINGERS * FSIZE_TYPE4) + FINGER_TYPE4))
219 #error "WSP_BUFFER_MAX is too small"
223 WSP_FLAG_WELLSPRING1,
224 WSP_FLAG_WELLSPRING2,
225 WSP_FLAG_WELLSPRING3,
226 WSP_FLAG_WELLSPRING4,
227 WSP_FLAG_WELLSPRING4A,
228 WSP_FLAG_WELLSPRING5,
229 WSP_FLAG_WELLSPRING6A,
230 WSP_FLAG_WELLSPRING6,
231 WSP_FLAG_WELLSPRING5A,
232 WSP_FLAG_WELLSPRING7,
233 WSP_FLAG_WELLSPRING7A,
234 WSP_FLAG_WELLSPRING8,
235 WSP_FLAG_WELLSPRING9,
239 /* device-specific configuration */
240 struct wsp_dev_params {
241 uint8_t caps; /* device capability bitmask */
242 uint8_t tp_type; /* type of trackpad interface */
243 uint8_t tp_button; /* offset to button data */
244 uint8_t tp_offset; /* offset to trackpad finger data */
245 uint8_t tp_fsize; /* bytes in single finger block */
246 uint8_t tp_delta; /* offset from header to finger struct */
248 uint8_t um_size; /* usb control message length */
249 uint8_t um_req_val; /* usb control message value */
250 uint8_t um_req_idx; /* usb control message index */
251 uint8_t um_switch_idx; /* usb control message mode switch index */
252 uint8_t um_switch_on; /* usb control message mode switch on */
253 uint8_t um_switch_off; /* usb control message mode switch off */
256 static const struct wsp_dev_params wsp_dev_params[WSP_FLAG_MAX] = {
257 [WSP_FLAG_WELLSPRING1] = {
261 .tp_offset = FINGER_TYPE1,
262 .tp_fsize = FSIZE_TYPE1,
269 .um_switch_on = 0x01,
270 .um_switch_off = 0x08,
272 [WSP_FLAG_WELLSPRING2] = {
276 .tp_offset = FINGER_TYPE1,
277 .tp_fsize = FSIZE_TYPE1,
284 .um_switch_on = 0x01,
285 .um_switch_off = 0x08,
287 [WSP_FLAG_WELLSPRING3] = {
288 .caps = HAS_INTEGRATED_BUTTON,
290 .tp_button = BUTTON_TYPE2,
291 .tp_offset = FINGER_TYPE2,
292 .tp_fsize = FSIZE_TYPE2,
299 .um_switch_on = 0x01,
300 .um_switch_off = 0x08,
302 [WSP_FLAG_WELLSPRING4] = {
303 .caps = HAS_INTEGRATED_BUTTON,
305 .tp_button = BUTTON_TYPE2,
306 .tp_offset = FINGER_TYPE2,
307 .tp_fsize = FSIZE_TYPE2,
314 .um_switch_on = 0x01,
315 .um_switch_off = 0x08,
317 [WSP_FLAG_WELLSPRING4A] = {
318 .caps = HAS_INTEGRATED_BUTTON,
320 .tp_button = BUTTON_TYPE2,
321 .tp_offset = FINGER_TYPE2,
322 .tp_fsize = FSIZE_TYPE2,
329 .um_switch_on = 0x01,
330 .um_switch_off = 0x08,
332 [WSP_FLAG_WELLSPRING5] = {
333 .caps = HAS_INTEGRATED_BUTTON,
335 .tp_button = BUTTON_TYPE2,
336 .tp_offset = FINGER_TYPE2,
337 .tp_fsize = FSIZE_TYPE2,
344 .um_switch_on = 0x01,
345 .um_switch_off = 0x08,
347 [WSP_FLAG_WELLSPRING6] = {
348 .caps = HAS_INTEGRATED_BUTTON,
350 .tp_button = BUTTON_TYPE2,
351 .tp_offset = FINGER_TYPE2,
352 .tp_fsize = FSIZE_TYPE2,
359 .um_switch_on = 0x01,
360 .um_switch_off = 0x08,
362 [WSP_FLAG_WELLSPRING5A] = {
363 .caps = HAS_INTEGRATED_BUTTON,
365 .tp_button = BUTTON_TYPE2,
366 .tp_offset = FINGER_TYPE2,
367 .tp_fsize = FSIZE_TYPE2,
374 .um_switch_on = 0x01,
375 .um_switch_off = 0x08,
377 [WSP_FLAG_WELLSPRING6A] = {
378 .caps = HAS_INTEGRATED_BUTTON,
380 .tp_button = BUTTON_TYPE2,
381 .tp_offset = FINGER_TYPE2,
382 .tp_fsize = FSIZE_TYPE2,
388 .um_switch_on = 0x01,
389 .um_switch_off = 0x08,
391 [WSP_FLAG_WELLSPRING7] = {
392 .caps = HAS_INTEGRATED_BUTTON,
394 .tp_button = BUTTON_TYPE2,
395 .tp_offset = FINGER_TYPE2,
396 .tp_fsize = FSIZE_TYPE2,
403 .um_switch_on = 0x01,
404 .um_switch_off = 0x08,
406 [WSP_FLAG_WELLSPRING7A] = {
407 .caps = HAS_INTEGRATED_BUTTON,
409 .tp_button = BUTTON_TYPE2,
410 .tp_offset = FINGER_TYPE2,
411 .tp_fsize = FSIZE_TYPE2,
418 .um_switch_on = 0x01,
419 .um_switch_off = 0x08,
421 [WSP_FLAG_WELLSPRING8] = {
422 .caps = HAS_INTEGRATED_BUTTON,
424 .tp_button = BUTTON_TYPE3,
425 .tp_offset = FINGER_TYPE3,
426 .tp_fsize = FSIZE_TYPE3,
433 .um_switch_on = 0x01,
434 .um_switch_off = 0x08,
436 [WSP_FLAG_WELLSPRING9] = {
437 .caps = HAS_INTEGRATED_BUTTON,
439 .tp_button = BUTTON_TYPE4,
440 .tp_offset = FINGER_TYPE4,
441 .tp_fsize = FSIZE_TYPE4,
448 .um_switch_on = 0x01,
449 .um_switch_off = 0x00,
453 #define WSP_DEV(v,p,i) { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) }
455 static const STRUCT_USB_HOST_ID wsp_devs[] = {
457 WSP_DEV(APPLE, WELLSPRING_ANSI, WSP_FLAG_WELLSPRING1),
458 WSP_DEV(APPLE, WELLSPRING_ISO, WSP_FLAG_WELLSPRING1),
459 WSP_DEV(APPLE, WELLSPRING_JIS, WSP_FLAG_WELLSPRING1),
461 /* MacbookProPenryn, aka wellspring2 */
462 WSP_DEV(APPLE, WELLSPRING2_ANSI, WSP_FLAG_WELLSPRING2),
463 WSP_DEV(APPLE, WELLSPRING2_ISO, WSP_FLAG_WELLSPRING2),
464 WSP_DEV(APPLE, WELLSPRING2_JIS, WSP_FLAG_WELLSPRING2),
466 /* Macbook5,1 (unibody), aka wellspring3 */
467 WSP_DEV(APPLE, WELLSPRING3_ANSI, WSP_FLAG_WELLSPRING3),
468 WSP_DEV(APPLE, WELLSPRING3_ISO, WSP_FLAG_WELLSPRING3),
469 WSP_DEV(APPLE, WELLSPRING3_JIS, WSP_FLAG_WELLSPRING3),
471 /* MacbookAir3,2 (unibody), aka wellspring4 */
472 WSP_DEV(APPLE, WELLSPRING4_ANSI, WSP_FLAG_WELLSPRING4),
473 WSP_DEV(APPLE, WELLSPRING4_ISO, WSP_FLAG_WELLSPRING4),
474 WSP_DEV(APPLE, WELLSPRING4_JIS, WSP_FLAG_WELLSPRING4),
476 /* MacbookAir3,1 (unibody), aka wellspring4 */
477 WSP_DEV(APPLE, WELLSPRING4A_ANSI, WSP_FLAG_WELLSPRING4A),
478 WSP_DEV(APPLE, WELLSPRING4A_ISO, WSP_FLAG_WELLSPRING4A),
479 WSP_DEV(APPLE, WELLSPRING4A_JIS, WSP_FLAG_WELLSPRING4A),
481 /* Macbook8 (unibody, March 2011) */
482 WSP_DEV(APPLE, WELLSPRING5_ANSI, WSP_FLAG_WELLSPRING5),
483 WSP_DEV(APPLE, WELLSPRING5_ISO, WSP_FLAG_WELLSPRING5),
484 WSP_DEV(APPLE, WELLSPRING5_JIS, WSP_FLAG_WELLSPRING5),
486 /* MacbookAir4,1 (unibody, July 2011) */
487 WSP_DEV(APPLE, WELLSPRING6A_ANSI, WSP_FLAG_WELLSPRING6A),
488 WSP_DEV(APPLE, WELLSPRING6A_ISO, WSP_FLAG_WELLSPRING6A),
489 WSP_DEV(APPLE, WELLSPRING6A_JIS, WSP_FLAG_WELLSPRING6A),
491 /* MacbookAir4,2 (unibody, July 2011) */
492 WSP_DEV(APPLE, WELLSPRING6_ANSI, WSP_FLAG_WELLSPRING6),
493 WSP_DEV(APPLE, WELLSPRING6_ISO, WSP_FLAG_WELLSPRING6),
494 WSP_DEV(APPLE, WELLSPRING6_JIS, WSP_FLAG_WELLSPRING6),
496 /* Macbook8,2 (unibody) */
497 WSP_DEV(APPLE, WELLSPRING5A_ANSI, WSP_FLAG_WELLSPRING5A),
498 WSP_DEV(APPLE, WELLSPRING5A_ISO, WSP_FLAG_WELLSPRING5A),
499 WSP_DEV(APPLE, WELLSPRING5A_JIS, WSP_FLAG_WELLSPRING5A),
501 /* MacbookPro10,1 (unibody, June 2012) */
502 /* MacbookPro11,1-3 (unibody, June 2013) */
503 WSP_DEV(APPLE, WELLSPRING7_ANSI, WSP_FLAG_WELLSPRING7),
504 WSP_DEV(APPLE, WELLSPRING7_ISO, WSP_FLAG_WELLSPRING7),
505 WSP_DEV(APPLE, WELLSPRING7_JIS, WSP_FLAG_WELLSPRING7),
507 /* MacbookPro10,2 (unibody, October 2012) */
508 WSP_DEV(APPLE, WELLSPRING7A_ANSI, WSP_FLAG_WELLSPRING7A),
509 WSP_DEV(APPLE, WELLSPRING7A_ISO, WSP_FLAG_WELLSPRING7A),
510 WSP_DEV(APPLE, WELLSPRING7A_JIS, WSP_FLAG_WELLSPRING7A),
512 /* MacbookAir6,2 (unibody, June 2013) */
513 WSP_DEV(APPLE, WELLSPRING8_ANSI, WSP_FLAG_WELLSPRING8),
514 WSP_DEV(APPLE, WELLSPRING8_ISO, WSP_FLAG_WELLSPRING8),
515 WSP_DEV(APPLE, WELLSPRING8_JIS, WSP_FLAG_WELLSPRING8),
517 /* MacbookPro12,1 MacbookPro11,4 */
518 WSP_DEV(APPLE, WELLSPRING9_ANSI, WSP_FLAG_WELLSPRING9),
519 WSP_DEV(APPLE, WELLSPRING9_ISO, WSP_FLAG_WELLSPRING9),
520 WSP_DEV(APPLE, WELLSPRING9_JIS, WSP_FLAG_WELLSPRING9),
523 #define WSP_FIFO_BUF_SIZE 8 /* bytes */
524 #define WSP_FIFO_QUEUE_MAXLEN 50 /* units */
532 struct usb_device *sc_usb_device;
533 struct mtx sc_mutex; /* for synchronization */
534 struct usb_xfer *sc_xfer[WSP_N_TRANSFER];
535 struct usb_fifo_sc sc_fifo;
537 const struct wsp_dev_params *sc_params; /* device configuration */
542 mousestatus_t sc_status;
544 #define WSP_ENABLED 0x01
546 struct tp_finger *index[MAX_FINGERS]; /* finger index data */
547 int16_t pos_x[MAX_FINGERS]; /* position array */
548 int16_t pos_y[MAX_FINGERS]; /* position array */
549 u_int sc_touch; /* touch status */
550 #define WSP_UNTOUCH 0x00
551 #define WSP_FIRST_TOUCH 0x01
552 #define WSP_SECOND_TOUCH 0x02
553 #define WSP_TOUCHING 0x04
554 int16_t pre_pos_x; /* previous position array */
555 int16_t pre_pos_y; /* previous position array */
556 int dx_sum; /* x axis cumulative movement */
557 int dy_sum; /* y axis cumulative movement */
558 int dz_sum; /* z axis cumulative movement */
560 #define WSP_DZ_MAX_COUNT 32
561 int dt_sum; /* T-axis cumulative movement */
562 int rdx; /* x axis remainder of divide by scale_factor */
563 int rdy; /* y axis remainder of divide by scale_factor */
564 int rdz; /* z axis remainder of divide by scale_factor */
566 uint8_t o_ntouch; /* old touch finger status */
567 uint8_t finger; /* 0 or 1 *, check which finger moving */
569 #define WSP_TAP_THRESHOLD 3
570 #define WSP_TAP_MAX_COUNT 20
571 int distance; /* the distance of 2 fingers */
572 #define MAX_DISTANCE 2500 /* the max allowed distance */
573 uint8_t ibtn; /* button status in tapping */
574 uint8_t ntaps; /* finger status in tapping */
575 uint8_t scr_mode; /* scroll status in movement */
576 #define WSP_SCR_NONE 0
577 #define WSP_SCR_VER 1
578 #define WSP_SCR_HOR 2
579 uint8_t tp_data[WSP_BUFFER_MAX] __aligned(4); /* trackpad transferred data */
583 * function prototypes
585 static usb_fifo_cmd_t wsp_start_read;
586 static usb_fifo_cmd_t wsp_stop_read;
587 static usb_fifo_open_t wsp_open;
588 static usb_fifo_close_t wsp_close;
589 static usb_fifo_ioctl_t wsp_ioctl;
591 static struct usb_fifo_methods wsp_fifo_methods = {
593 .f_close = &wsp_close,
594 .f_ioctl = &wsp_ioctl,
595 .f_start_read = &wsp_start_read,
596 .f_stop_read = &wsp_stop_read,
597 .basename[0] = WSP_DRIVER_NAME,
600 /* device initialization and shutdown */
601 static int wsp_enable(struct wsp_softc *sc);
602 static void wsp_disable(struct wsp_softc *sc);
605 static void wsp_reset_buf(struct wsp_softc *sc);
606 static void wsp_add_to_queue(struct wsp_softc *, int, int, int, uint32_t);
608 /* Device methods. */
609 static device_probe_t wsp_probe;
610 static device_attach_t wsp_attach;
611 static device_detach_t wsp_detach;
612 static usb_callback_t wsp_intr_callback;
614 static const struct usb_config wsp_config[WSP_N_TRANSFER] = {
616 .type = UE_INTERRUPT,
617 .endpoint = UE_ADDR_ANY,
618 .direction = UE_DIR_IN,
623 .bufsize = WSP_BUFFER_MAX,
624 .callback = &wsp_intr_callback,
629 wsp_set_device_mode(struct wsp_softc *sc, uint8_t on)
631 const struct wsp_dev_params *params = sc->sc_params;
632 uint8_t mode_bytes[8];
635 /* Type 3 does not require a mode switch */
636 if (params->tp_type == TYPE3)
639 err = usbd_req_get_report(sc->sc_usb_device, NULL,
640 mode_bytes, params->um_size, params->iface_index,
641 params->um_req_val, params->um_req_idx);
643 if (err != USB_ERR_NORMAL_COMPLETION) {
644 DPRINTF("Failed to read device mode (%d)\n", err);
649 * XXX Need to wait at least 250ms for hardware to get
650 * ready. The device mode handling appears to be handled
651 * asynchronously and we should not issue these commands too
654 pause("WHW", hz / 4);
656 mode_bytes[params->um_switch_idx] =
657 on ? params->um_switch_on : params->um_switch_off;
659 return (usbd_req_set_report(sc->sc_usb_device, NULL,
660 mode_bytes, params->um_size, params->iface_index,
661 params->um_req_val, params->um_req_idx));
665 wsp_enable(struct wsp_softc *sc)
668 memset(&sc->sc_status, 0, sizeof(sc->sc_status));
669 sc->sc_state |= WSP_ENABLED;
671 DPRINTFN(WSP_LLEVEL_INFO, "enabled wsp\n");
676 wsp_disable(struct wsp_softc *sc)
678 sc->sc_state &= ~WSP_ENABLED;
679 DPRINTFN(WSP_LLEVEL_INFO, "disabled wsp\n");
683 wsp_probe(device_t self)
685 struct usb_attach_arg *uaa = device_get_ivars(self);
686 struct usb_interface_descriptor *id;
687 struct usb_interface *iface;
690 if (uaa->usb_mode != USB_MODE_HOST)
693 /* figure out first interface matching */
695 iface = usbd_get_iface(uaa->device, i);
696 if (iface == NULL || i == 3)
700 (id->bInterfaceClass != UICLASS_HID) ||
701 (id->bInterfaceProtocol != 0 &&
702 id->bInterfaceProtocol != UIPROTO_MOUSE))
706 /* check if we are attaching to the first match */
707 if (uaa->info.bIfaceIndex != i)
709 return (usbd_lookup_id_by_uaa(wsp_devs, sizeof(wsp_devs), uaa));
713 wsp_attach(device_t dev)
715 struct wsp_softc *sc = device_get_softc(dev);
716 struct usb_attach_arg *uaa = device_get_ivars(dev);
721 DPRINTFN(WSP_LLEVEL_INFO, "sc=%p\n", sc);
723 /* Get HID descriptor */
724 err = usbd_req_get_hid_desc(uaa->device, NULL, &d_ptr,
725 &d_len, M_TEMP, uaa->info.bIfaceIndex);
727 if (err == USB_ERR_NORMAL_COMPLETION) {
728 /* Get HID report descriptor length */
729 sc->tp_datalen = hid_report_size(d_ptr, d_len, hid_input, NULL);
732 if (sc->tp_datalen <= 0 || sc->tp_datalen > WSP_BUFFER_MAX) {
733 DPRINTF("Invalid datalength or too big "
734 "datalength: %d\n", sc->tp_datalen);
741 sc->sc_usb_device = uaa->device;
743 /* get device specific configuration */
744 sc->sc_params = wsp_dev_params + USB_GET_DRIVER_INFO(uaa);
747 * By default the touchpad behaves like a HID device, sending
748 * packets with reportID = 8. Such reports contain only
749 * limited information. They encode movement deltas and button
750 * events, but do not include data from the pressure
751 * sensors. The device input mode can be switched from HID
752 * reports to raw sensor data using vendor-specific USB
757 * During re-enumeration of the device we need to force the
758 * device back into HID mode before switching it to RAW
759 * mode. Else the device does not work like expected.
761 err = wsp_set_device_mode(sc, 0);
762 if (err != USB_ERR_NORMAL_COMPLETION) {
763 DPRINTF("Failed to set mode to HID MODE (%d)\n", err);
767 err = wsp_set_device_mode(sc, 1);
768 if (err != USB_ERR_NORMAL_COMPLETION) {
769 DPRINTF("failed to set mode to RAW MODE (%d)\n", err);
773 mtx_init(&sc->sc_mutex, "wspmtx", NULL, MTX_DEF | MTX_RECURSE);
775 err = usbd_transfer_setup(uaa->device,
776 &uaa->info.bIfaceIndex, sc->sc_xfer, wsp_config,
777 WSP_N_TRANSFER, sc, &sc->sc_mutex);
779 DPRINTF("error=%s\n", usbd_errstr(err));
782 if (usb_fifo_attach(sc->sc_usb_device, sc, &sc->sc_mutex,
783 &wsp_fifo_methods, &sc->sc_fifo,
784 device_get_unit(dev), -1, uaa->info.bIfaceIndex,
785 UID_ROOT, GID_OPERATOR, 0644)) {
788 device_set_usb_desc(dev);
790 sc->sc_hw.buttons = 3;
791 sc->sc_hw.iftype = MOUSE_IF_USB;
792 sc->sc_hw.type = MOUSE_PAD;
793 sc->sc_hw.model = MOUSE_MODEL_GENERIC;
794 sc->sc_mode.protocol = MOUSE_PROTO_MSC;
795 sc->sc_mode.rate = -1;
796 sc->sc_mode.resolution = MOUSE_RES_UNKNOWN;
797 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE;
798 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
799 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC;
801 sc->sc_touch = WSP_UNTOUCH;
802 sc->scr_mode = WSP_SCR_NONE;
812 wsp_detach(device_t dev)
814 struct wsp_softc *sc = device_get_softc(dev);
816 (void) wsp_set_device_mode(sc, 0);
818 mtx_lock(&sc->sc_mutex);
819 if (sc->sc_state & WSP_ENABLED)
821 mtx_unlock(&sc->sc_mutex);
823 usb_fifo_detach(&sc->sc_fifo);
825 usbd_transfer_unsetup(sc->sc_xfer, WSP_N_TRANSFER);
827 mtx_destroy(&sc->sc_mutex);
833 wsp_intr_callback(struct usb_xfer *xfer, usb_error_t error)
835 struct wsp_softc *sc = usbd_xfer_softc(xfer);
836 const struct wsp_dev_params *params = sc->sc_params;
837 struct usb_page_cache *pc;
840 struct wsp_tuning tun = wsp_tuning;
841 int ntouch = 0; /* the finger number in touch */
842 int ibt = 0; /* button status */
852 wsp_runing_rangecheck(&tun);
854 if (sc->dz_count == 0)
855 sc->dz_count = WSP_DZ_MAX_COUNT;
857 usbd_xfer_status(xfer, &len, NULL, NULL, NULL);
859 switch (USB_GET_STATE(xfer)) {
860 case USB_ST_TRANSFERRED:
862 /* copy out received data */
863 pc = usbd_xfer_get_frame(xfer, 0);
864 usbd_copy_out(pc, 0, sc->tp_data, len);
866 if ((len < params->tp_offset + params->tp_fsize) ||
867 ((len - params->tp_offset) % params->tp_fsize) != 0) {
868 DPRINTFN(WSP_LLEVEL_INFO, "Invalid length: %d, %x, %x\n",
869 len, sc->tp_data[0], sc->tp_data[1]);
873 if (len < sc->tp_datalen) {
874 /* make sure we don't process old data */
875 memset(sc->tp_data + len, 0, sc->tp_datalen - len);
878 h = (struct tp_header *)(sc->tp_data);
880 if (params->tp_type >= TYPE2) {
881 ibt = sc->tp_data[params->tp_button];
882 ntouch = sc->tp_data[params->tp_button - 1];
887 else if (ntouch > MAX_FINGERS)
888 ntouch = MAX_FINGERS;
890 for (i = 0; i != ntouch; i++) {
891 f = (struct tp_finger *)(sc->tp_data + params->tp_offset + params->tp_delta + i * params->tp_fsize);
892 /* swap endianness, if any */
893 if (le16toh(0x1234) != 0x1234) {
894 f->origin = le16toh((uint16_t)f->origin);
895 f->abs_x = le16toh((uint16_t)f->abs_x);
896 f->abs_y = le16toh((uint16_t)f->abs_y);
897 f->rel_x = le16toh((uint16_t)f->rel_x);
898 f->rel_y = le16toh((uint16_t)f->rel_y);
899 f->tool_major = le16toh((uint16_t)f->tool_major);
900 f->tool_minor = le16toh((uint16_t)f->tool_minor);
901 f->orientation = le16toh((uint16_t)f->orientation);
902 f->touch_major = le16toh((uint16_t)f->touch_major);
903 f->touch_minor = le16toh((uint16_t)f->touch_minor);
904 f->pressure = le16toh((uint16_t)f->pressure);
905 f->multi = le16toh((uint16_t)f->multi);
907 DPRINTFN(WSP_LLEVEL_INFO,
908 "[%d]ibt=%d, taps=%d, o=%4d, ax=%5d, ay=%5d, "
909 "rx=%5d, ry=%5d, tlmaj=%4d, tlmin=%4d, ot=%4x, "
910 "tchmaj=%4d, tchmin=%4d, presure=%4d, m=%4x\n",
911 i, ibt, ntouch, f->origin, f->abs_x, f->abs_y,
912 f->rel_x, f->rel_y, f->tool_major, f->tool_minor, f->orientation,
913 f->touch_major, f->touch_minor, f->pressure, f->multi);
914 sc->pos_x[i] = f->abs_x;
915 sc->pos_y[i] = -f->abs_y;
919 sc->sc_status.flags &= ~MOUSE_POSCHANGED;
920 sc->sc_status.flags &= ~MOUSE_STDBUTTONSCHANGED;
921 sc->sc_status.obutton = sc->sc_status.button;
922 sc->sc_status.button = 0;
925 if ((params->caps & HAS_INTEGRATED_BUTTON) && ntouch == 2)
926 sc->sc_status.button |= MOUSE_BUTTON3DOWN;
927 else if ((params->caps & HAS_INTEGRATED_BUTTON) && ntouch == 3)
928 sc->sc_status.button |= MOUSE_BUTTON2DOWN;
930 sc->sc_status.button |= MOUSE_BUTTON1DOWN;
935 if (sc->ntaps < ntouch) {
938 if (sc->index[0]->touch_major > tun.pressure_tap_threshold &&
939 sc->index[0]->tool_major <= 1200)
943 if (sc->index[0]->touch_major > tun.pressure_tap_threshold-30 &&
944 sc->index[1]->touch_major > tun.pressure_tap_threshold-30)
948 if (sc->index[0]->touch_major > tun.pressure_tap_threshold-40 &&
949 sc->index[1]->touch_major > tun.pressure_tap_threshold-40 &&
950 sc->index[2]->touch_major > tun.pressure_tap_threshold-40)
958 sc->distance = max(sc->distance, max(
959 abs(sc->pos_x[0] - sc->pos_x[1]),
960 abs(sc->pos_y[0] - sc->pos_y[1])));
962 if (sc->index[0]->touch_major < tun.pressure_untouch_threshold &&
963 sc->sc_status.button == 0) {
964 sc->sc_touch = WSP_UNTOUCH;
965 if (sc->intr_count < WSP_TAP_MAX_COUNT &&
966 sc->intr_count > WSP_TAP_THRESHOLD &&
967 sc->ntaps && sc->ibtn == 0) {
969 * Add a pair of events (button-down and
974 if (!(params->caps & HAS_INTEGRATED_BUTTON)) {
975 wsp_add_to_queue(sc, 0, 0, 0, MOUSE_BUTTON1DOWN);
976 DPRINTFN(WSP_LLEVEL_INFO, "LEFT CLICK!\n");
980 DPRINTFN(WSP_LLEVEL_INFO, "sum_x=%5d, sum_y=%5d\n",
981 sc->dx_sum, sc->dy_sum);
982 if (sc->distance < MAX_DISTANCE && abs(sc->dx_sum) < 5 &&
983 abs(sc->dy_sum) < 5) {
984 wsp_add_to_queue(sc, 0, 0, 0, MOUSE_BUTTON3DOWN);
985 DPRINTFN(WSP_LLEVEL_INFO, "RIGHT CLICK!\n");
989 wsp_add_to_queue(sc, 0, 0, 0, MOUSE_BUTTON2DOWN);
992 /* we don't handle taps of more than three fingers */
995 wsp_add_to_queue(sc, 0, 0, 0, 0); /* button release */
997 if ((sc->dt_sum / tun.scr_hor_threshold) != 0 &&
998 sc->ntaps == 2 && sc->scr_mode == WSP_SCR_HOR) {
1001 * translate T-axis into button presses
1005 wsp_add_to_queue(sc, 0, 0, 0, 1UL << 3);
1006 else if (sc->dt_sum < 0)
1007 wsp_add_to_queue(sc, 0, 0, 0, 1UL << 4);
1009 sc->dz_count = WSP_DZ_MAX_COUNT;
1022 sc->scr_mode = WSP_SCR_NONE;
1023 } else if (sc->index[0]->touch_major >= tun.pressure_touch_threshold &&
1024 sc->sc_touch == WSP_UNTOUCH) { /* ignore first touch */
1025 sc->sc_touch = WSP_FIRST_TOUCH;
1026 } else if (sc->index[0]->touch_major >= tun.pressure_touch_threshold &&
1027 sc->sc_touch == WSP_FIRST_TOUCH) { /* ignore second touch */
1028 sc->sc_touch = WSP_SECOND_TOUCH;
1029 DPRINTFN(WSP_LLEVEL_INFO, "Fist pre_x=%5d, pre_y=%5d\n",
1030 sc->pre_pos_x, sc->pre_pos_y);
1032 if (sc->sc_touch == WSP_SECOND_TOUCH)
1033 sc->sc_touch = WSP_TOUCHING;
1036 sc->index[0]->touch_major >= tun.pressure_touch_threshold) {
1037 dx = sc->pos_x[0] - sc->pre_pos_x;
1038 dy = sc->pos_y[0] - sc->pre_pos_y;
1040 /* Ignore movement during button is releasing */
1041 if (sc->ibtn != 0 && sc->sc_status.button == 0)
1044 /* Ignore movement if ntouch changed */
1045 if (sc->o_ntouch != ntouch)
1048 /* Ignore unexpeted movment when typing */
1049 if (ntouch == 1 && sc->index[0]->tool_major > 1200)
1052 if (sc->ibtn != 0 && ntouch == 1 &&
1053 sc->intr_count < WSP_TAP_MAX_COUNT &&
1054 abs(sc->dx_sum) < 1 && abs(sc->dy_sum) < 1 )
1057 if (ntouch == 2 && sc->sc_status.button != 0) {
1058 dx = sc->pos_x[sc->finger] - sc->pre_pos_x;
1059 dy = sc->pos_y[sc->finger] - sc->pre_pos_y;
1062 * Ignore movement of switch finger or
1063 * movement from ibt=0 to ibt=1
1065 if (sc->index[0]->origin == 0 || sc->index[1]->origin == 0 ||
1066 sc->sc_status.obutton != sc->sc_status.button) {
1070 if ((abs(sc->index[0]->rel_x) + abs(sc->index[0]->rel_y)) <
1071 (abs(sc->index[1]->rel_x) + abs(sc->index[1]->rel_y)) &&
1073 sc->sc_touch = WSP_SECOND_TOUCH;
1077 if ((abs(sc->index[0]->rel_x) + abs(sc->index[0]->rel_y)) >=
1078 (abs(sc->index[1]->rel_x) + abs(sc->index[1]->rel_y)) &&
1080 sc->sc_touch = WSP_SECOND_TOUCH;
1084 DPRINTFN(WSP_LLEVEL_INFO, "dx=%5d, dy=%5d, mov=%5d\n",
1085 dx, dy, sc->finger);
1087 if (sc->dz_count--) {
1088 rdz = (dy + sc->rdz) % tun.scale_factor;
1089 sc->dz_sum -= (dy + sc->rdz) / tun.scale_factor;
1092 if ((sc->dz_sum / tun.z_factor) != 0)
1095 rdx = (dx + sc->rdx) % tun.scale_factor;
1096 dx = (dx + sc->rdx) / tun.scale_factor;
1099 rdy = (dy + sc->rdy) % tun.scale_factor;
1100 dy = (dy + sc->rdy) / tun.scale_factor;
1106 if (ntouch == 2 && sc->sc_status.button == 0) {
1107 if (sc->scr_mode == WSP_SCR_NONE &&
1108 abs(sc->dx_sum) + abs(sc->dy_sum) > tun.scr_hor_threshold)
1109 sc->scr_mode = abs(sc->dx_sum) >
1110 abs(sc->dy_sum) * 2 ? WSP_SCR_HOR : WSP_SCR_VER;
1111 DPRINTFN(WSP_LLEVEL_INFO, "scr_mode=%5d, count=%d, dx_sum=%d, dy_sum=%d\n",
1112 sc->scr_mode, sc->intr_count, sc->dx_sum, sc->dy_sum);
1113 if (sc->scr_mode == WSP_SCR_HOR)
1119 if (sc->dz_count == 0)
1120 dz = sc->dz_sum / tun.z_factor;
1121 if (sc->scr_mode == WSP_SCR_HOR ||
1122 abs(sc->pos_x[0] - sc->pos_x[1]) > MAX_DISTANCE ||
1123 abs(sc->pos_y[0] - sc->pos_y[1]) > MAX_DISTANCE)
1128 if (sc->intr_count < WSP_TAP_MAX_COUNT &&
1129 abs(dx) < 3 && abs(dy) < 3 && abs(dz) < 3)
1132 sc->intr_count = WSP_TAP_MAX_COUNT;
1134 sc->sc_status.flags |= MOUSE_POSCHANGED;
1135 DPRINTFN(WSP_LLEVEL_INFO, "dx=%5d, dy=%5d, dz=%5d, sc_touch=%x, btn=%x\n",
1136 dx, dy, dz, sc->sc_touch, sc->sc_status.button);
1137 sc->sc_status.dx += dx;
1138 sc->sc_status.dy += dy;
1139 sc->sc_status.dz += dz;
1141 wsp_add_to_queue(sc, dx, -dy, dz, sc->sc_status.button);
1142 if (sc->dz_count == 0) {
1148 sc->pre_pos_x = sc->pos_x[0];
1149 sc->pre_pos_y = sc->pos_y[0];
1151 if (ntouch == 2 && sc->sc_status.button != 0) {
1152 sc->pre_pos_x = sc->pos_x[sc->finger];
1153 sc->pre_pos_y = sc->pos_y[sc->finger];
1155 sc->o_ntouch = ntouch;
1159 /* check if we can put more data into the FIFO */
1160 if (usb_fifo_put_bytes_max(
1161 sc->sc_fifo.fp[USB_FIFO_RX]) != 0) {
1162 usbd_xfer_set_frame_len(xfer, 0,
1164 usbd_transfer_submit(xfer);
1168 default: /* Error */
1169 if (error != USB_ERR_CANCELLED) {
1170 /* try clear stall first */
1171 usbd_xfer_set_stall(xfer);
1179 wsp_add_to_queue(struct wsp_softc *sc, int dx, int dy, int dz,
1180 uint32_t buttons_in)
1182 uint32_t buttons_out;
1186 dx = imax(dx, -256);
1188 dy = imax(dy, -256);
1190 dz = imax(dz, -128);
1192 buttons_out = MOUSE_MSC_BUTTONS;
1193 if (buttons_in & MOUSE_BUTTON1DOWN)
1194 buttons_out &= ~MOUSE_MSC_BUTTON1UP;
1195 else if (buttons_in & MOUSE_BUTTON2DOWN)
1196 buttons_out &= ~MOUSE_MSC_BUTTON2UP;
1197 else if (buttons_in & MOUSE_BUTTON3DOWN)
1198 buttons_out &= ~MOUSE_MSC_BUTTON3UP;
1200 /* Encode the mouse data in standard format; refer to mouse(4) */
1201 buf[0] = sc->sc_mode.syncmask[1];
1202 buf[0] |= buttons_out;
1205 buf[3] = dx - (dx >> 1);
1206 buf[4] = dy - (dy >> 1);
1207 /* Encode extra bytes for level 1 */
1208 if (sc->sc_mode.level == 1) {
1209 buf[5] = dz >> 1; /* dz / 2 */
1210 buf[6] = dz - (dz >> 1);/* dz - (dz / 2) */
1211 buf[7] = (((~buttons_in) >> 3) & MOUSE_SYS_EXTBUTTONS);
1213 usb_fifo_put_data_linear(sc->sc_fifo.fp[USB_FIFO_RX], buf,
1214 sc->sc_mode.packetsize, 1);
1218 wsp_reset_buf(struct wsp_softc *sc)
1220 /* reset read queue */
1221 usb_fifo_reset(sc->sc_fifo.fp[USB_FIFO_RX]);
1225 wsp_start_read(struct usb_fifo *fifo)
1227 struct wsp_softc *sc = usb_fifo_softc(fifo);
1230 /* Check if we should override the default polling interval */
1231 rate = sc->sc_pollrate;
1232 /* Range check rate */
1235 /* Check for set rate */
1236 if ((rate > 0) && (sc->sc_xfer[WSP_INTR_DT] != NULL)) {
1237 /* Stop current transfer, if any */
1238 usbd_transfer_stop(sc->sc_xfer[WSP_INTR_DT]);
1239 /* Set new interval */
1240 usbd_xfer_set_interval(sc->sc_xfer[WSP_INTR_DT], 1000 / rate);
1241 /* Only set pollrate once */
1242 sc->sc_pollrate = 0;
1244 usbd_transfer_start(sc->sc_xfer[WSP_INTR_DT]);
1248 wsp_stop_read(struct usb_fifo *fifo)
1250 struct wsp_softc *sc = usb_fifo_softc(fifo);
1252 usbd_transfer_stop(sc->sc_xfer[WSP_INTR_DT]);
1257 wsp_open(struct usb_fifo *fifo, int fflags)
1259 DPRINTFN(WSP_LLEVEL_INFO, "\n");
1261 if (fflags & FREAD) {
1262 struct wsp_softc *sc = usb_fifo_softc(fifo);
1265 if (sc->sc_state & WSP_ENABLED)
1268 if (usb_fifo_alloc_buffer(fifo,
1269 WSP_FIFO_BUF_SIZE, WSP_FIFO_QUEUE_MAXLEN)) {
1272 rc = wsp_enable(sc);
1274 usb_fifo_free_buffer(fifo);
1282 wsp_close(struct usb_fifo *fifo, int fflags)
1284 if (fflags & FREAD) {
1285 struct wsp_softc *sc = usb_fifo_softc(fifo);
1288 usb_fifo_free_buffer(fifo);
1293 wsp_ioctl(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags)
1295 struct wsp_softc *sc = usb_fifo_softc(fifo);
1299 mtx_lock(&sc->sc_mutex);
1302 case MOUSE_GETHWINFO:
1303 *(mousehw_t *)addr = sc->sc_hw;
1306 *(mousemode_t *)addr = sc->sc_mode;
1309 mode = *(mousemode_t *)addr;
1311 if (mode.level == -1)
1312 /* Don't change the current setting */
1314 else if ((mode.level < 0) || (mode.level > 1)) {
1318 sc->sc_mode.level = mode.level;
1319 sc->sc_pollrate = mode.rate;
1320 sc->sc_hw.buttons = 3;
1322 if (sc->sc_mode.level == 0) {
1323 sc->sc_mode.protocol = MOUSE_PROTO_MSC;
1324 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE;
1325 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
1326 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC;
1327 } else if (sc->sc_mode.level == 1) {
1328 sc->sc_mode.protocol = MOUSE_PROTO_SYSMOUSE;
1329 sc->sc_mode.packetsize = MOUSE_SYS_PACKETSIZE;
1330 sc->sc_mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
1331 sc->sc_mode.syncmask[1] = MOUSE_SYS_SYNC;
1335 case MOUSE_GETLEVEL:
1336 *(int *)addr = sc->sc_mode.level;
1338 case MOUSE_SETLEVEL:
1339 if (*(int *)addr < 0 || *(int *)addr > 1) {
1343 sc->sc_mode.level = *(int *)addr;
1344 sc->sc_hw.buttons = 3;
1346 if (sc->sc_mode.level == 0) {
1347 sc->sc_mode.protocol = MOUSE_PROTO_MSC;
1348 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE;
1349 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
1350 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC;
1351 } else if (sc->sc_mode.level == 1) {
1352 sc->sc_mode.protocol = MOUSE_PROTO_SYSMOUSE;
1353 sc->sc_mode.packetsize = MOUSE_SYS_PACKETSIZE;
1354 sc->sc_mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
1355 sc->sc_mode.syncmask[1] = MOUSE_SYS_SYNC;
1359 case MOUSE_GETSTATUS:{
1360 mousestatus_t *status = (mousestatus_t *)addr;
1362 *status = sc->sc_status;
1363 sc->sc_status.obutton = sc->sc_status.button;
1364 sc->sc_status.button = 0;
1365 sc->sc_status.dx = 0;
1366 sc->sc_status.dy = 0;
1367 sc->sc_status.dz = 0;
1369 if (status->dx || status->dy || status->dz)
1370 status->flags |= MOUSE_POSCHANGED;
1371 if (status->button != status->obutton)
1372 status->flags |= MOUSE_BUTTONSCHANGED;
1380 mtx_unlock(&sc->sc_mutex);
1384 static device_method_t wsp_methods[] = {
1385 /* Device interface */
1386 DEVMETHOD(device_probe, wsp_probe),
1387 DEVMETHOD(device_attach, wsp_attach),
1388 DEVMETHOD(device_detach, wsp_detach),
1392 static driver_t wsp_driver = {
1393 .name = WSP_DRIVER_NAME,
1394 .methods = wsp_methods,
1395 .size = sizeof(struct wsp_softc)
1398 static devclass_t wsp_devclass;
1400 DRIVER_MODULE(wsp, uhub, wsp_driver, wsp_devclass, NULL, 0);
1401 MODULE_DEPEND(wsp, usb, 1, 1, 1);
1402 MODULE_VERSION(wsp, 1);