2 * $FreeBSD: src/sys/dev/usb/ums.c,v 1.64 2003/11/09 09:17:22 tanimura Exp $
3 * $DragonFly: src/sys/dev/usbmisc/ums/ums.c,v 1.31 2008/08/14 20:55:54 hasso Exp $
7 * Copyright (c) 1998 The NetBSD Foundation, Inc.
10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Lennart Augustsson (lennart@augustsson.net) at
12 * Carlstedt Research & Technology.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by the NetBSD
25 * Foundation, Inc. and its contributors.
26 * 4. Neither the name of The NetBSD Foundation nor the names of its
27 * contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
31 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
34 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
44 * HID spec: http://www.usb.org/developers/data/devclass/hid1_1.pdf
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/kernel.h>
50 #include <sys/malloc.h>
51 #include <sys/module.h>
56 #include <sys/vnode.h>
57 #include <sys/event.h>
58 #include <sys/sysctl.h>
59 #include <sys/devfs.h>
60 #include <sys/thread2.h>
62 #include <bus/usb/usb.h>
63 #include <bus/usb/usbhid.h>
65 #include <bus/usb/usbdi.h>
66 #include <bus/usb/usbdi_util.h>
67 #include <bus/usb/usb_quirks.h>
68 #include <bus/usb/hid.h>
70 #include <sys/mouse.h>
73 #define DPRINTF(x) if (umsdebug) kprintf x
74 #define DPRINTFN(n,x) if (umsdebug>(n)) kprintf x
76 SYSCTL_NODE(_hw_usb, OID_AUTO, ums, CTLFLAG_RW, 0, "USB ums");
77 SYSCTL_INT(_hw_usb_ums, OID_AUTO, debug, CTLFLAG_RW,
78 &umsdebug, 0, "ums debug level");
84 #define UMSUNIT(s) (minor(s)&0x1f)
86 #define MS_TO_TICKS(ms) ((ms) * hz / 1000)
88 #define QUEUE_BUFSIZE 400 /* MUST be divisible by 5 _and_ 8 */
91 device_t sc_dev; /* base device */
93 usbd_interface_handle sc_iface; /* interface */
94 usbd_pipe_handle sc_intrpipe; /* interrupt pipe */
100 struct hid_location sc_loc_x, sc_loc_y, sc_loc_z;
101 struct hid_location *sc_loc_btn;
103 struct callout sc_timeout; /* for spurious button ups */
106 int sc_disconnected; /* device is gone */
108 int flags; /* device configuration */
109 #define UMS_Z 0x01 /* z direction available */
110 #define UMS_SPUR_BUT_UP 0x02 /* spurious button up events */
112 #define MAX_BUTTONS 31 /* must not exceed size of sc_buttons */
114 u_char qbuf[QUEUE_BUFSIZE]; /* must be divisable by 3&4 */
115 u_char dummy[100]; /* XXX just for safety and for now */
116 int qcount, qhead, qtail;
119 mousestatus_t status;
122 # define UMS_ASLEEP 0x01 /* readFromDevice is waiting */
123 struct kqinfo rkq; /* process waiting in select/poll/kq */
126 #define MOUSE_FLAGS_MASK (HIO_CONST|HIO_RELATIVE)
127 #define MOUSE_FLAGS (HIO_RELATIVE)
129 static void ums_intr(usbd_xfer_handle xfer,
130 usbd_private_handle priv, usbd_status status);
132 static void ums_add_to_queue(struct ums_softc *sc,
133 int dx, int dy, int dz, int buttons);
134 static void ums_add_to_queue_timeout(void *priv);
136 static int ums_enable(void *);
137 static void ums_disable(void *);
139 static d_open_t ums_open;
140 static d_close_t ums_close;
141 static d_read_t ums_read;
142 static d_ioctl_t ums_ioctl;
143 static d_kqfilter_t ums_kqfilter;
145 static void ums_filt_detach(struct knote *);
146 static int ums_filt(struct knote *, long);
148 #define UMS_CDEV_MAJOR 111
150 static struct dev_ops ums_ops = {
151 { "ums", UMS_CDEV_MAJOR, 0 },
153 .d_close = ums_close,
155 .d_ioctl = ums_ioctl,
156 .d_kqfilter = ums_kqfilter
159 static device_probe_t ums_match;
160 static device_attach_t ums_attach;
161 static device_detach_t ums_detach;
163 static devclass_t ums_devclass;
165 static kobj_method_t ums_methods[] = {
166 DEVMETHOD(device_probe, ums_match),
167 DEVMETHOD(device_attach, ums_attach),
168 DEVMETHOD(device_detach, ums_detach),
172 static driver_t ums_driver = {
175 sizeof(struct ums_softc)
178 MODULE_DEPEND(ums, usb, 1, 1, 1);
181 ums_match(device_t self)
183 struct usb_attach_arg *uaa = device_get_ivars(self);
184 usb_interface_descriptor_t *id;
190 return (UMATCH_NONE);
191 id = usbd_get_interface_descriptor(uaa->iface);
192 if (!id || id->bInterfaceClass != UICLASS_HID)
193 return (UMATCH_NONE);
195 err = usbd_read_report_desc(uaa->iface, &desc, &size, M_TEMP);
197 return (UMATCH_NONE);
199 if (hid_is_collection(desc, size,
200 HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE)))
201 ret = UMATCH_IFACECLASS;
210 ums_attach(device_t self)
212 struct ums_softc *sc = device_get_softc(self);
213 struct usb_attach_arg *uaa = device_get_ivars(self);
214 usbd_interface_handle iface = uaa->iface;
215 usb_endpoint_descriptor_t *ed;
221 struct hid_location loc_btn;
223 sc->sc_disconnected = 1;
224 sc->sc_iface = iface;
226 ed = usbd_interface2endpoint_descriptor(iface, 0);
228 kprintf("%s: could not read endpoint descriptor\n",
229 device_get_nameunit(sc->sc_dev));
233 DPRINTFN(10,("ums_attach: bLength=%d bDescriptorType=%d "
234 "bEndpointAddress=%d-%s bmAttributes=%d wMaxPacketSize=%d"
236 ed->bLength, ed->bDescriptorType,
237 UE_GET_ADDR(ed->bEndpointAddress),
238 UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN ? "in":"out",
239 UE_GET_XFERTYPE(ed->bmAttributes),
240 UGETW(ed->wMaxPacketSize), ed->bInterval));
242 if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_IN ||
243 UE_GET_XFERTYPE(ed->bmAttributes) != UE_INTERRUPT) {
244 kprintf("%s: unexpected endpoint\n",
245 device_get_nameunit(sc->sc_dev));
249 err = usbd_read_report_desc(uaa->iface, &desc, &size, M_TEMP);
253 if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
254 hid_input, &sc->sc_loc_x, &flags)) {
255 kprintf("%s: mouse has no X report\n", device_get_nameunit(sc->sc_dev));
258 if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
259 kprintf("%s: X report 0x%04x not supported\n",
260 device_get_nameunit(sc->sc_dev), flags);
264 if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y),
265 hid_input, &sc->sc_loc_y, &flags)) {
266 kprintf("%s: mouse has no Y report\n", device_get_nameunit(sc->sc_dev));
269 if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
270 kprintf("%s: Y report 0x%04x not supported\n",
271 device_get_nameunit(sc->sc_dev), flags);
275 /* try to guess the Z activator: first check Z, then WHEEL */
276 if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Z),
277 hid_input, &sc->sc_loc_z, &flags) ||
278 hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL),
279 hid_input, &sc->sc_loc_z, &flags)) {
280 if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
281 sc->sc_loc_z.size = 0; /* Bad Z coord, ignore it */
287 /* figure out the number of buttons */
288 for (i = 1; i <= MAX_BUTTONS; i++)
289 if (!hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
290 hid_input, &loc_btn, 0))
292 sc->nbuttons = i - 1;
293 sc->sc_loc_btn = kmalloc(sizeof(struct hid_location)*sc->nbuttons,
294 M_USBDEV, M_INTWAIT);
296 kprintf("%s: %d buttons%s\n", device_get_nameunit(sc->sc_dev),
297 sc->nbuttons, sc->flags & UMS_Z? " and Z dir." : "");
299 for (i = 1; i <= sc->nbuttons; i++)
300 hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
301 hid_input, &sc->sc_loc_btn[i-1], 0);
303 sc->sc_isize = hid_report_size(desc, size, hid_input, &sc->sc_iid);
304 sc->sc_ibuf = kmalloc(sc->sc_isize, M_USB, M_INTWAIT);
305 sc->sc_ep_addr = ed->bEndpointAddress;
306 sc->sc_disconnected = 0;
310 DPRINTF(("ums_attach: sc=%p\n", sc));
311 DPRINTF(("ums_attach: X\t%d/%d\n",
312 sc->sc_loc_x.pos, sc->sc_loc_x.size));
313 DPRINTF(("ums_attach: Y\t%d/%d\n",
314 sc->sc_loc_y.pos, sc->sc_loc_y.size));
315 if (sc->flags & UMS_Z)
316 DPRINTF(("ums_attach: Z\t%d/%d\n",
317 sc->sc_loc_z.pos, sc->sc_loc_z.size));
318 for (i = 1; i <= sc->nbuttons; i++) {
319 DPRINTF(("ums_attach: B%d\t%d/%d\n",
320 i, sc->sc_loc_btn[i-1].pos,sc->sc_loc_btn[i-1].size));
322 DPRINTF(("ums_attach: size=%d, id=%d\n", sc->sc_isize, sc->sc_iid));
325 if (sc->nbuttons > MOUSE_MSC_MAXBUTTON)
326 sc->hw.buttons = MOUSE_MSC_MAXBUTTON;
328 sc->hw.buttons = sc->nbuttons;
329 sc->hw.iftype = MOUSE_IF_USB;
330 sc->hw.type = MOUSE_MOUSE;
331 sc->hw.model = MOUSE_MODEL_GENERIC;
333 sc->mode.protocol = MOUSE_PROTO_MSC;
335 sc->mode.resolution = MOUSE_RES_UNKNOWN;
336 sc->mode.accelfactor = 0;
338 sc->mode.packetsize = MOUSE_MSC_PACKETSIZE;
339 sc->mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
340 sc->mode.syncmask[1] = MOUSE_MSC_SYNC;
342 sc->status.flags = 0;
343 sc->status.button = sc->status.obutton = 0;
344 sc->status.dx = sc->status.dy = sc->status.dz = 0;
346 sc->sc_cdev = make_dev(&ums_ops, device_get_unit(self),
347 UID_ROOT, GID_OPERATOR,
348 0644, "ums%d", device_get_unit(self));
349 reference_dev(sc->sc_cdev);
351 if (usbd_get_quirks(uaa->device)->uq_flags & UQ_SPUR_BUT_UP) {
352 DPRINTF(("%s: Spurious button up events\n",
353 device_get_nameunit(sc->sc_dev)));
354 sc->flags |= UMS_SPUR_BUT_UP;
362 ums_detach(device_t self)
364 struct ums_softc *sc = device_get_softc(self);
369 DPRINTF(("%s: disconnected\n", device_get_nameunit(self)));
371 kfree(sc->sc_loc_btn, M_USB);
372 kfree(sc->sc_ibuf, M_USB);
374 /* someone waiting for data */
376 * XXX If we wakeup the process here, the device will be gone by
377 * the time the process gets a chance to notice. *_close and friends
378 * should be fixed to handle this case.
379 * Or we should do a delayed detach for this.
380 * Does this delay now force tsleep to exit with an error?
382 if (sc->state & UMS_ASLEEP) {
383 sc->state &= ~UMS_ASLEEP;
387 dev_ops_remove_minor(&ums_ops, /*-1, */device_get_unit(self));
388 devfs_assume_knotes(sc->sc_cdev, &sc->rkq);
389 release_dev(sc->sc_cdev);
396 ums_intr(usbd_xfer_handle xfer, usbd_private_handle addr,
399 struct ums_softc *sc = addr;
405 #define UMS_BUT(i) ((i) < 3 ? (((i) + 2) % 3) : (i))
407 DPRINTFN(5, ("ums_intr: sc=%p status=%d\n", sc, status));
408 DPRINTFN(5, ("ums_intr: data = %02x %02x %02x\n",
409 sc->sc_ibuf[0], sc->sc_ibuf[1], sc->sc_ibuf[2]));
411 if (status == USBD_CANCELLED)
414 if (status != USBD_NORMAL_COMPLETION) {
415 DPRINTF(("ums_intr: status=%d\n", status));
416 if (status == USBD_STALLED)
417 usbd_clear_endpoint_stall_async(sc->sc_intrpipe);
423 if (*ibuf++ != sc->sc_iid)
427 dx = hid_get_data(ibuf, &sc->sc_loc_x);
428 dy = -hid_get_data(ibuf, &sc->sc_loc_y);
429 dz = -hid_get_data(ibuf, &sc->sc_loc_z);
430 for (i = 0; i < sc->nbuttons; i++)
431 if (hid_get_data(ibuf, &sc->sc_loc_btn[i]))
432 buttons |= (1 << UMS_BUT(i));
434 if (dx || dy || dz || (sc->flags & UMS_Z)
435 || buttons != sc->status.button) {
436 DPRINTFN(5, ("ums_intr: x:%d y:%d z:%d buttons:0x%x\n",
437 dx, dy, dz, buttons));
439 sc->status.button = buttons;
444 /* Discard data in case of full buffer */
445 if (sc->qcount == sizeof(sc->qbuf)) {
446 DPRINTF(("Buffer full, discarded packet"));
451 * The Qtronix keyboard has a built in PS/2 port for a mouse.
452 * The firmware once in a while posts a spurious button up
453 * event. This event we ignore by doing a timeout for 50 msecs.
454 * If we receive dx=dy=dz=buttons=0 before we add the event to
456 * In any other case we delete the timeout event.
458 if (sc->flags & UMS_SPUR_BUT_UP &&
459 dx == 0 && dy == 0 && dz == 0 && buttons == 0) {
460 callout_reset(&sc->sc_timeout, MS_TO_TICKS(50),
461 ums_add_to_queue_timeout, (void *) sc);
463 callout_stop(&sc->sc_timeout);
464 ums_add_to_queue(sc, dx, dy, dz, buttons);
470 ums_add_to_queue_timeout(void *priv)
472 struct ums_softc *sc = priv;
475 ums_add_to_queue(sc, 0, 0, 0, 0);
480 ums_add_to_queue(struct ums_softc *sc, int dx, int dy, int dz, int buttons)
482 /* Discard data in case of full buffer */
483 if (sc->qhead+sc->mode.packetsize > sizeof(sc->qbuf)) {
484 DPRINTF(("Buffer full, discarded packet"));
488 if (dx > 254) dx = 254;
489 if (dx < -256) dx = -256;
490 if (dy > 254) dy = 254;
491 if (dy < -256) dy = -256;
492 if (dz > 126) dz = 126;
493 if (dz < -128) dz = -128;
495 sc->qbuf[sc->qhead] = sc->mode.syncmask[1];
496 sc->qbuf[sc->qhead] |= ~buttons & MOUSE_MSC_BUTTONS;
497 sc->qbuf[sc->qhead+1] = dx >> 1;
498 sc->qbuf[sc->qhead+2] = dy >> 1;
499 sc->qbuf[sc->qhead+3] = dx - (dx >> 1);
500 sc->qbuf[sc->qhead+4] = dy - (dy >> 1);
502 if (sc->mode.level == 1) {
503 sc->qbuf[sc->qhead+5] = dz >> 1;
504 sc->qbuf[sc->qhead+6] = dz - (dz >> 1);
505 sc->qbuf[sc->qhead+7] = ((~buttons >> 3)
506 & MOUSE_SYS_EXTBUTTONS);
509 sc->qhead += sc->mode.packetsize;
510 sc->qcount += sc->mode.packetsize;
511 /* wrap round at end of buffer */
512 if (sc->qhead >= sizeof(sc->qbuf))
515 /* someone waiting for data */
516 if (sc->state & UMS_ASLEEP) {
517 sc->state &= ~UMS_ASLEEP;
520 KNOTE(&sc->rkq.ki_note, 0);
526 struct ums_softc *sc = v;
535 sc->qhead = sc->qtail = 0;
536 sc->status.flags = 0;
537 sc->status.button = sc->status.obutton = 0;
538 sc->status.dx = sc->status.dy = sc->status.dz = 0;
540 callout_init(&sc->sc_timeout);
542 /* Set up interrupt pipe. */
543 err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ep_addr,
544 USBD_SHORT_XFER_OK, &sc->sc_intrpipe, sc,
545 sc->sc_ibuf, sc->sc_isize, ums_intr,
546 USBD_DEFAULT_INTERVAL);
548 DPRINTF(("ums_enable: usbd_open_pipe_intr failed, error=%d\n",
557 ums_disable(void *priv)
559 struct ums_softc *sc = priv;
561 callout_stop(&sc->sc_timeout);
563 /* Disable interrupts. */
564 usbd_abort_pipe(sc->sc_intrpipe);
565 usbd_close_pipe(sc->sc_intrpipe);
570 DPRINTF(("Discarded %d bytes in queue\n", sc->qcount));
574 ums_open(struct dev_open_args *ap)
576 cdev_t dev = ap->a_head.a_dev;
577 struct ums_softc *sc;
579 sc = devclass_get_softc(ums_devclass, UMSUNIT(dev));
583 return ums_enable(sc);
587 ums_close(struct dev_close_args *ap)
589 cdev_t dev = ap->a_head.a_dev;
590 struct ums_softc *sc;
592 sc = devclass_get_softc(ums_devclass, UMSUNIT(dev));
604 ums_read(struct dev_read_args *ap)
606 cdev_t dev = ap->a_head.a_dev;
607 struct uio *uio = ap->a_uio;
608 struct ums_softc *sc;
609 char buf[sizeof(sc->qbuf)];
613 sc = devclass_get_softc(ums_devclass, UMSUNIT(dev));
621 while (sc->qcount == 0 ) {
622 if (ap->a_ioflag & IO_NDELAY) { /* non-blocking I/O */
627 sc->state |= UMS_ASLEEP; /* blocking I/O */
628 error = tsleep(sc, PCATCH, "umsrea", 0);
632 } else if (!sc->sc_enabled) {
636 /* check whether the device is still there */
638 sc = devclass_get_softc(ums_devclass, UMSUNIT(dev));
646 * The writer process only extends qcount and qtail. We could copy
647 * them and use the copies to do the copying out of the queue.
650 while ((sc->qcount > 0) && (uio->uio_resid > 0)) {
651 l = (sc->qcount < uio->uio_resid? sc->qcount:uio->uio_resid);
654 if (l > sizeof(sc->qbuf) - sc->qtail) /* transfer till end of buf */
655 l = sizeof(sc->qbuf) - sc->qtail;
658 uiomove(&sc->qbuf[sc->qtail], l, uio);
661 if ( sc->qcount - l < 0 ) {
662 DPRINTF(("qcount below 0, count=%d l=%d\n", sc->qcount, l));
665 sc->qcount -= l; /* remove the bytes from the buffer */
666 sc->qtail = (sc->qtail + l) % sizeof(sc->qbuf);
673 static struct filterops ums_filtops =
674 { FILTEROP_ISFD, NULL, ums_filt_detach, ums_filt };
677 ums_kqfilter(struct dev_kqfilter_args *ap)
679 cdev_t dev = ap->a_head.a_dev;
680 struct knote *kn = ap->a_kn;
681 struct ums_softc *sc;
686 switch (kn->kn_filter) {
688 sc = devclass_get_softc(ums_devclass, UMSUNIT(dev));
689 kn->kn_fop = &ums_filtops;
690 kn->kn_hook = (caddr_t)sc;
693 ap->a_result = EOPNOTSUPP;
697 klist = &sc->rkq.ki_note;
698 knote_insert(klist, kn);
704 ums_filt_detach(struct knote *kn)
706 struct ums_softc *sc = (struct ums_softc *)kn->kn_hook;
709 klist = &sc->rkq.ki_note;
710 knote_remove(klist, kn);
714 ums_filt(struct knote *kn, long hint)
716 struct ums_softc *sc = (struct ums_softc *)kn->kn_hook;
728 ums_ioctl(struct dev_ioctl_args *ap)
730 cdev_t dev = ap->a_head.a_dev;
731 struct ums_softc *sc;
735 sc = devclass_get_softc(ums_devclass, UMSUNIT(dev));
741 case MOUSE_GETHWINFO:
742 *(mousehw_t *)ap->a_data = sc->hw;
745 *(mousemode_t *)ap->a_data = sc->mode;
748 mode = *(mousemode_t *)ap->a_data;
750 if (mode.level == -1)
751 /* don't change the current setting */
753 else if ((mode.level < 0) || (mode.level > 1))
757 sc->mode.level = mode.level;
759 if (sc->mode.level == 0) {
760 if (sc->nbuttons > MOUSE_MSC_MAXBUTTON)
761 sc->hw.buttons = MOUSE_MSC_MAXBUTTON;
763 sc->hw.buttons = sc->nbuttons;
764 sc->mode.protocol = MOUSE_PROTO_MSC;
765 sc->mode.packetsize = MOUSE_MSC_PACKETSIZE;
766 sc->mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
767 sc->mode.syncmask[1] = MOUSE_MSC_SYNC;
768 } else if (sc->mode.level == 1) {
769 if (sc->nbuttons > MOUSE_SYS_MAXBUTTON)
770 sc->hw.buttons = MOUSE_SYS_MAXBUTTON;
772 sc->hw.buttons = sc->nbuttons;
773 sc->mode.protocol = MOUSE_PROTO_SYSMOUSE;
774 sc->mode.packetsize = MOUSE_SYS_PACKETSIZE;
775 sc->mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
776 sc->mode.syncmask[1] = MOUSE_SYS_SYNC;
779 bzero(sc->qbuf, sizeof(sc->qbuf));
780 sc->qhead = sc->qtail = sc->qcount = 0;
785 *(int *)ap->a_data = sc->mode.level;
788 if (*(int *)ap->a_data < 0 || *(int *)ap->a_data > 1)
792 sc->mode.level = *(int *)ap->a_data;
794 if (sc->mode.level == 0) {
795 if (sc->nbuttons > MOUSE_MSC_MAXBUTTON)
796 sc->hw.buttons = MOUSE_MSC_MAXBUTTON;
798 sc->hw.buttons = sc->nbuttons;
799 sc->mode.protocol = MOUSE_PROTO_MSC;
800 sc->mode.packetsize = MOUSE_MSC_PACKETSIZE;
801 sc->mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
802 sc->mode.syncmask[1] = MOUSE_MSC_SYNC;
803 } else if (sc->mode.level == 1) {
804 if (sc->nbuttons > MOUSE_SYS_MAXBUTTON)
805 sc->hw.buttons = MOUSE_SYS_MAXBUTTON;
807 sc->hw.buttons = sc->nbuttons;
808 sc->mode.protocol = MOUSE_PROTO_SYSMOUSE;
809 sc->mode.packetsize = MOUSE_SYS_PACKETSIZE;
810 sc->mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
811 sc->mode.syncmask[1] = MOUSE_SYS_SYNC;
814 bzero(sc->qbuf, sizeof(sc->qbuf));
815 sc->qhead = sc->qtail = sc->qcount = 0;
819 case MOUSE_GETSTATUS: {
820 mousestatus_t *status = (mousestatus_t *) ap->a_data;
823 *status = sc->status;
824 sc->status.obutton = sc->status.button;
825 sc->status.button = 0;
826 sc->status.dx = sc->status.dy = sc->status.dz = 0;
829 if (status->dx || status->dy || status->dz)
830 status->flags |= MOUSE_POSCHANGED;
831 if (status->button != status->obutton)
832 status->flags |= MOUSE_BUTTONSCHANGED;
842 DRIVER_MODULE(ums, uhub, ums_driver, ums_devclass, usbd_driver_load, 0);