3 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Lennart Augustsson (lennart@augustsson.net) at
8 * Carlstedt Research & Technology.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
43 * HID spec: http://www.usb.org/developers/data/devclass/hid1_1.pdf
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/malloc.h>
50 #include <sys/module.h>
52 #include <sys/ioccom.h>
56 #if __FreeBSD_version >= 500014
57 #include <sys/selinfo.h>
59 #include <sys/select.h>
61 #include <sys/vnode.h>
63 #include <sys/sysctl.h>
65 #include <dev/usb/usb.h>
66 #include <dev/usb/usbhid.h>
68 #include <dev/usb/usbdi.h>
69 #include <dev/usb/usbdi_util.h>
70 #include <dev/usb/usbdevs.h>
71 #include <dev/usb/usb_quirks.h>
72 #include <dev/usb/hid.h>
74 #include <sys/mouse.h>
77 #define DPRINTF(x) if (umsdebug) logprintf x
78 #define DPRINTFN(n,x) if (umsdebug>(n)) logprintf x
80 SYSCTL_NODE(_hw_usb, OID_AUTO, ums, CTLFLAG_RW, 0, "USB ums");
81 SYSCTL_INT(_hw_usb_ums, OID_AUTO, debug, CTLFLAG_RW,
82 &umsdebug, 0, "ums debug level");
88 #define UMSUNIT(s) (minor(s)&0x1f)
90 #define MS_TO_TICKS(ms) ((ms) * hz / 1000)
92 #define QUEUE_BUFSIZE 400 /* MUST be divisible by 5 _and_ 8 */
95 device_t sc_dev; /* base device */
96 usbd_interface_handle sc_iface; /* interface */
97 usbd_pipe_handle sc_intrpipe; /* interrupt pipe */
103 struct hid_location sc_loc_x, sc_loc_y, sc_loc_z;
104 struct hid_location *sc_loc_btn;
106 usb_callout_t callout_handle; /* for spurious button ups */
109 int sc_disconnected; /* device is gone */
111 int flags; /* device configuration */
112 #define UMS_Z 0x01 /* z direction available */
113 #define UMS_SPUR_BUT_UP 0x02 /* spurious button up events */
115 #define MAX_BUTTONS 7 /* chosen because sc_buttons is u_char */
117 u_char qbuf[QUEUE_BUFSIZE]; /* must be divisable by 3&4 */
118 u_char dummy[100]; /* XXX just for safety and for now */
119 int qcount, qhead, qtail;
122 mousestatus_t status;
125 # define UMS_ASLEEP 0x01 /* readFromDevice is waiting */
126 # define UMS_SELECT 0x02 /* select is waiting */
127 struct selinfo rsel; /* process waiting in select */
129 dev_t dev; /* specfs */
132 #define MOUSE_FLAGS_MASK (HIO_CONST|HIO_RELATIVE)
133 #define MOUSE_FLAGS (HIO_RELATIVE)
135 Static void ums_intr(usbd_xfer_handle xfer,
136 usbd_private_handle priv, usbd_status status);
138 Static void ums_add_to_queue(struct ums_softc *sc,
139 int dx, int dy, int dz, int buttons);
140 Static void ums_add_to_queue_timeout(void *priv);
142 Static int ums_enable(void *);
143 Static void ums_disable(void *);
145 Static d_open_t ums_open;
146 Static d_close_t ums_close;
147 Static d_read_t ums_read;
148 Static d_ioctl_t ums_ioctl;
149 Static d_poll_t ums_poll;
151 #define UMS_CDEV_MAJOR 111
153 Static struct cdevsw ums_cdevsw = {
155 .d_close = ums_close,
157 .d_ioctl = ums_ioctl,
160 .d_maj = UMS_CDEV_MAJOR,
161 #if __FreeBSD_version < 500014
166 USB_DECLARE_DRIVER(ums);
170 USB_MATCH_START(ums, uaa);
171 usb_interface_descriptor_t *id;
177 return (UMATCH_NONE);
178 id = usbd_get_interface_descriptor(uaa->iface);
179 if (!id || id->bInterfaceClass != UICLASS_HID)
180 return (UMATCH_NONE);
182 err = usbd_read_report_desc(uaa->iface, &desc, &size, M_TEMP);
184 return (UMATCH_NONE);
186 if (hid_is_collection(desc, size,
187 HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE)))
188 ret = UMATCH_IFACECLASS;
198 USB_ATTACH_START(ums, sc, uaa);
199 usbd_interface_handle iface = uaa->iface;
200 usb_interface_descriptor_t *id;
201 usb_endpoint_descriptor_t *ed;
208 struct hid_location loc_btn;
210 sc->sc_disconnected = 1;
211 sc->sc_iface = iface;
212 id = usbd_get_interface_descriptor(iface);
213 usbd_devinfo(uaa->device, 0, devinfo);
215 printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev),
216 devinfo, id->bInterfaceClass, id->bInterfaceSubClass);
217 ed = usbd_interface2endpoint_descriptor(iface, 0);
219 printf("%s: could not read endpoint descriptor\n",
220 USBDEVNAME(sc->sc_dev));
221 USB_ATTACH_ERROR_RETURN;
224 DPRINTFN(10,("ums_attach: bLength=%d bDescriptorType=%d "
225 "bEndpointAddress=%d-%s bmAttributes=%d wMaxPacketSize=%d"
227 ed->bLength, ed->bDescriptorType,
228 UE_GET_ADDR(ed->bEndpointAddress),
229 UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN ? "in":"out",
230 UE_GET_XFERTYPE(ed->bmAttributes),
231 UGETW(ed->wMaxPacketSize), ed->bInterval));
233 if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_IN ||
234 UE_GET_XFERTYPE(ed->bmAttributes) != UE_INTERRUPT) {
235 printf("%s: unexpected endpoint\n",
236 USBDEVNAME(sc->sc_dev));
237 USB_ATTACH_ERROR_RETURN;
240 err = usbd_read_report_desc(uaa->iface, &desc, &size, M_TEMP);
242 USB_ATTACH_ERROR_RETURN;
244 if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
245 hid_input, &sc->sc_loc_x, &flags)) {
246 printf("%s: mouse has no X report\n", USBDEVNAME(sc->sc_dev));
247 USB_ATTACH_ERROR_RETURN;
249 if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
250 printf("%s: X report 0x%04x not supported\n",
251 USBDEVNAME(sc->sc_dev), flags);
252 USB_ATTACH_ERROR_RETURN;
255 if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y),
256 hid_input, &sc->sc_loc_y, &flags)) {
257 printf("%s: mouse has no Y report\n", USBDEVNAME(sc->sc_dev));
258 USB_ATTACH_ERROR_RETURN;
260 if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
261 printf("%s: Y report 0x%04x not supported\n",
262 USBDEVNAME(sc->sc_dev), flags);
263 USB_ATTACH_ERROR_RETURN;
266 /* try to guess the Z activator: first check Z, then WHEEL */
267 if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Z),
268 hid_input, &sc->sc_loc_z, &flags) ||
269 hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL),
270 hid_input, &sc->sc_loc_z, &flags)) {
271 if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
272 sc->sc_loc_z.size = 0; /* Bad Z coord, ignore it */
278 /* figure out the number of buttons */
279 for (i = 1; i <= MAX_BUTTONS; i++)
280 if (!hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
281 hid_input, &loc_btn, 0))
283 sc->nbuttons = i - 1;
284 sc->sc_loc_btn = malloc(sizeof(struct hid_location)*sc->nbuttons,
286 if (!sc->sc_loc_btn) {
287 printf("%s: no memory\n", USBDEVNAME(sc->sc_dev));
288 USB_ATTACH_ERROR_RETURN;
291 printf("%s: %d buttons%s\n", USBDEVNAME(sc->sc_dev),
292 sc->nbuttons, sc->flags & UMS_Z? " and Z dir." : "");
294 for (i = 1; i <= sc->nbuttons; i++)
295 hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
296 hid_input, &sc->sc_loc_btn[i-1], 0);
298 sc->sc_isize = hid_report_size(desc, size, hid_input, &sc->sc_iid);
299 sc->sc_ibuf = malloc(sc->sc_isize, M_USB, M_NOWAIT);
301 printf("%s: no memory\n", USBDEVNAME(sc->sc_dev));
302 free(sc->sc_loc_btn, M_USB);
303 USB_ATTACH_ERROR_RETURN;
306 sc->sc_ep_addr = ed->bEndpointAddress;
307 sc->sc_disconnected = 0;
311 DPRINTF(("ums_attach: sc=%p\n", sc));
312 DPRINTF(("ums_attach: X\t%d/%d\n",
313 sc->sc_loc_x.pos, sc->sc_loc_x.size));
314 DPRINTF(("ums_attach: Y\t%d/%d\n",
315 sc->sc_loc_y.pos, sc->sc_loc_y.size));
316 if (sc->flags & UMS_Z)
317 DPRINTF(("ums_attach: Z\t%d/%d\n",
318 sc->sc_loc_z.pos, sc->sc_loc_z.size));
319 for (i = 1; i <= sc->nbuttons; i++) {
320 DPRINTF(("ums_attach: B%d\t%d/%d\n",
321 i, sc->sc_loc_btn[i-1].pos,sc->sc_loc_btn[i-1].size));
323 DPRINTF(("ums_attach: size=%d, id=%d\n", sc->sc_isize, sc->sc_iid));
326 if (sc->nbuttons > MOUSE_MSC_MAXBUTTON)
327 sc->hw.buttons = MOUSE_MSC_MAXBUTTON;
329 sc->hw.buttons = sc->nbuttons;
330 sc->hw.iftype = MOUSE_IF_USB;
331 sc->hw.type = MOUSE_MOUSE;
332 sc->hw.model = MOUSE_MODEL_GENERIC;
334 sc->mode.protocol = MOUSE_PROTO_MSC;
336 sc->mode.resolution = MOUSE_RES_UNKNOWN;
337 sc->mode.accelfactor = 0;
339 sc->mode.packetsize = MOUSE_MSC_PACKETSIZE;
340 sc->mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
341 sc->mode.syncmask[1] = MOUSE_MSC_SYNC;
343 sc->status.flags = 0;
344 sc->status.button = sc->status.obutton = 0;
345 sc->status.dx = sc->status.dy = sc->status.dz = 0;
348 sc->rsel.si_flags = 0;
352 sc->dev = make_dev(&ums_cdevsw, device_get_unit(self),
353 UID_ROOT, GID_OPERATOR,
354 0644, "ums%d", device_get_unit(self));
356 if (usbd_get_quirks(uaa->device)->uq_flags & UQ_SPUR_BUT_UP) {
357 DPRINTF(("%s: Spurious button up events\n",
358 USBDEVNAME(sc->sc_dev)));
359 sc->flags |= UMS_SPUR_BUT_UP;
362 USB_ATTACH_SUCCESS_RETURN;
367 ums_detach(device_t self)
369 struct ums_softc *sc = device_get_softc(self);
375 DPRINTF(("%s: disconnected\n", USBDEVNAME(self)));
377 free(sc->sc_loc_btn, M_USB);
378 free(sc->sc_ibuf, M_USB);
380 vp = SLIST_FIRST(&sc->dev->si_hlist);
382 VOP_REVOKE(vp, REVOKEALL);
384 /* someone waiting for data */
386 * XXX If we wakeup the process here, the device will be gone by
387 * the time the process gets a chance to notice. *_close and friends
388 * should be fixed to handle this case.
389 * Or we should do a delayed detach for this.
390 * Does this delay now force tsleep to exit with an error?
392 if (sc->state & UMS_ASLEEP) {
393 sc->state &= ~UMS_ASLEEP;
396 if (sc->state & UMS_SELECT) {
397 sc->state &= ~UMS_SELECT;
398 selwakeup(&sc->rsel);
401 destroy_dev(sc->dev);
407 ums_intr(xfer, addr, status)
408 usbd_xfer_handle xfer;
409 usbd_private_handle addr;
412 struct ums_softc *sc = addr;
418 #define UMS_BUT(i) ((i) < 3 ? (((i) + 2) % 3) : (i))
420 DPRINTFN(5, ("ums_intr: sc=%p status=%d\n", sc, status));
421 DPRINTFN(5, ("ums_intr: data = %02x %02x %02x\n",
422 sc->sc_ibuf[0], sc->sc_ibuf[1], sc->sc_ibuf[2]));
424 if (status == USBD_CANCELLED)
427 if (status != USBD_NORMAL_COMPLETION) {
428 DPRINTF(("ums_intr: status=%d\n", status));
429 if (status == USBD_STALLED)
430 usbd_clear_endpoint_stall_async(sc->sc_intrpipe);
436 if (*ibuf++ != sc->sc_iid)
440 dx = hid_get_data(ibuf, &sc->sc_loc_x);
441 dy = -hid_get_data(ibuf, &sc->sc_loc_y);
442 dz = -hid_get_data(ibuf, &sc->sc_loc_z);
443 for (i = 0; i < sc->nbuttons; i++)
444 if (hid_get_data(ibuf, &sc->sc_loc_btn[i]))
445 buttons |= (1 << UMS_BUT(i));
447 if (dx || dy || dz || (sc->flags & UMS_Z)
448 || buttons != sc->status.button) {
449 DPRINTFN(5, ("ums_intr: x:%d y:%d z:%d buttons:0x%x\n",
450 dx, dy, dz, buttons));
452 sc->status.button = buttons;
457 /* Discard data in case of full buffer */
458 if (sc->qcount == sizeof(sc->qbuf)) {
459 DPRINTF(("Buffer full, discarded packet"));
464 * The Qtronix keyboard has a built in PS/2 port for a mouse.
465 * The firmware once in a while posts a spurious button up
466 * event. This event we ignore by doing a timeout for 50 msecs.
467 * If we receive dx=dy=dz=buttons=0 before we add the event to
469 * In any other case we delete the timeout event.
471 if (sc->flags & UMS_SPUR_BUT_UP &&
472 dx == 0 && dy == 0 && dz == 0 && buttons == 0) {
473 usb_callout(sc->callout_handle, MS_TO_TICKS(50 /*msecs*/),
474 ums_add_to_queue_timeout, (void *) sc);
476 usb_uncallout(sc->callout_handle,
477 ums_add_to_queue_timeout, (void *) sc);
478 ums_add_to_queue(sc, dx, dy, dz, buttons);
484 ums_add_to_queue_timeout(void *priv)
486 struct ums_softc *sc = priv;
490 ums_add_to_queue(sc, 0, 0, 0, 0);
495 ums_add_to_queue(struct ums_softc *sc, int dx, int dy, int dz, int buttons)
497 /* Discard data in case of full buffer */
498 if (sc->qhead+sc->mode.packetsize > sizeof(sc->qbuf)) {
499 DPRINTF(("Buffer full, discarded packet"));
503 if (dx > 254) dx = 254;
504 if (dx < -256) dx = -256;
505 if (dy > 254) dy = 254;
506 if (dy < -256) dy = -256;
507 if (dz > 126) dz = 126;
508 if (dz < -128) dz = -128;
510 sc->qbuf[sc->qhead] = sc->mode.syncmask[1];
511 sc->qbuf[sc->qhead] |= ~buttons & MOUSE_MSC_BUTTONS;
512 sc->qbuf[sc->qhead+1] = dx >> 1;
513 sc->qbuf[sc->qhead+2] = dy >> 1;
514 sc->qbuf[sc->qhead+3] = dx - (dx >> 1);
515 sc->qbuf[sc->qhead+4] = dy - (dy >> 1);
517 if (sc->mode.level == 1) {
518 sc->qbuf[sc->qhead+5] = dz >> 1;
519 sc->qbuf[sc->qhead+6] = dz - (dz >> 1);
520 sc->qbuf[sc->qhead+7] = ((~buttons >> 3)
521 & MOUSE_SYS_EXTBUTTONS);
524 sc->qhead += sc->mode.packetsize;
525 sc->qcount += sc->mode.packetsize;
526 /* wrap round at end of buffer */
527 if (sc->qhead >= sizeof(sc->qbuf))
530 /* someone waiting for data */
531 if (sc->state & UMS_ASLEEP) {
532 sc->state &= ~UMS_ASLEEP;
535 if (sc->state & UMS_SELECT) {
536 sc->state &= ~UMS_SELECT;
537 selwakeup(&sc->rsel);
544 struct ums_softc *sc = v;
553 sc->qhead = sc->qtail = 0;
554 sc->status.flags = 0;
555 sc->status.button = sc->status.obutton = 0;
556 sc->status.dx = sc->status.dy = sc->status.dz = 0;
558 callout_handle_init((struct callout_handle *)&sc->callout_handle);
560 /* Set up interrupt pipe. */
561 err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ep_addr,
562 USBD_SHORT_XFER_OK, &sc->sc_intrpipe, sc,
563 sc->sc_ibuf, sc->sc_isize, ums_intr,
564 USBD_DEFAULT_INTERVAL);
566 DPRINTF(("ums_enable: usbd_open_pipe_intr failed, error=%d\n",
578 struct ums_softc *sc = priv;
580 usb_uncallout(sc->callout_handle, ums_add_to_queue_timeout, sc);
582 /* Disable interrupts. */
583 usbd_abort_pipe(sc->sc_intrpipe);
584 usbd_close_pipe(sc->sc_intrpipe);
589 DPRINTF(("Discarded %d bytes in queue\n", sc->qcount));
593 ums_open(dev_t dev, int flag, int fmt, usb_proc_ptr p)
595 struct ums_softc *sc;
597 USB_GET_SC_OPEN(ums, UMSUNIT(dev), sc);
599 return ums_enable(sc);
603 ums_close(dev_t dev, int flag, int fmt, usb_proc_ptr p)
605 struct ums_softc *sc;
607 USB_GET_SC(ums, UMSUNIT(dev), sc);
619 ums_read(dev_t dev, struct uio *uio, int flag)
621 struct ums_softc *sc;
623 char buf[sizeof(sc->qbuf)];
627 USB_GET_SC(ums, UMSUNIT(dev), sc);
635 while (sc->qcount == 0 ) {
636 if (flag & IO_NDELAY) { /* non-blocking I/O */
641 sc->state |= UMS_ASLEEP; /* blocking I/O */
642 error = tsleep(sc, PZERO | PCATCH, "umsrea", 0);
646 } else if (!sc->sc_enabled) {
650 /* check whether the device is still there */
652 sc = devclass_get_softc(ums_devclass, UMSUNIT(dev));
660 * XXX we could optimise the use of splx/splusb somewhat. The writer
661 * process only extends qcount and qtail. We could copy them and use the copies
662 * to do the copying out of the queue.
665 while ((sc->qcount > 0) && (uio->uio_resid > 0)) {
666 l = (sc->qcount < uio->uio_resid? sc->qcount:uio->uio_resid);
669 if (l > sizeof(sc->qbuf) - sc->qtail) /* transfer till end of buf */
670 l = sizeof(sc->qbuf) - sc->qtail;
673 uiomove(&sc->qbuf[sc->qtail], l, uio);
676 if ( sc->qcount - l < 0 ) {
677 DPRINTF(("qcount below 0, count=%d l=%d\n", sc->qcount, l));
680 sc->qcount -= l; /* remove the bytes from the buffer */
681 sc->qtail = (sc->qtail + l) % sizeof(sc->qbuf);
689 ums_poll(dev_t dev, int events, usb_proc_ptr p)
691 struct ums_softc *sc;
695 USB_GET_SC(ums, UMSUNIT(dev), sc);
701 if (events & (POLLIN | POLLRDNORM)) {
703 revents = events & (POLLIN | POLLRDNORM);
705 sc->state |= UMS_SELECT;
706 selrecord(p, &sc->rsel);
715 ums_ioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, usb_proc_ptr p)
717 struct ums_softc *sc;
722 USB_GET_SC(ums, UMSUNIT(dev), sc);
728 case MOUSE_GETHWINFO:
729 *(mousehw_t *)addr = sc->hw;
732 *(mousemode_t *)addr = sc->mode;
735 mode = *(mousemode_t *)addr;
737 if (mode.level == -1)
738 /* don't change the current setting */
740 else if ((mode.level < 0) || (mode.level > 1))
744 sc->mode.level = mode.level;
746 if (sc->mode.level == 0) {
747 if (sc->nbuttons > MOUSE_MSC_MAXBUTTON)
748 sc->hw.buttons = MOUSE_MSC_MAXBUTTON;
750 sc->hw.buttons = sc->nbuttons;
751 sc->mode.protocol = MOUSE_PROTO_MSC;
752 sc->mode.packetsize = MOUSE_MSC_PACKETSIZE;
753 sc->mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
754 sc->mode.syncmask[1] = MOUSE_MSC_SYNC;
755 } else if (sc->mode.level == 1) {
756 if (sc->nbuttons > MOUSE_SYS_MAXBUTTON)
757 sc->hw.buttons = MOUSE_SYS_MAXBUTTON;
759 sc->hw.buttons = sc->nbuttons;
760 sc->mode.protocol = MOUSE_PROTO_SYSMOUSE;
761 sc->mode.packetsize = MOUSE_SYS_PACKETSIZE;
762 sc->mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
763 sc->mode.syncmask[1] = MOUSE_SYS_SYNC;
766 bzero(sc->qbuf, sizeof(sc->qbuf));
767 sc->qhead = sc->qtail = sc->qcount = 0;
772 *(int *)addr = sc->mode.level;
775 if (*(int *)addr < 0 || *(int *)addr > 1)
779 sc->mode.level = *(int *)addr;
781 if (sc->mode.level == 0) {
782 if (sc->nbuttons > MOUSE_MSC_MAXBUTTON)
783 sc->hw.buttons = MOUSE_MSC_MAXBUTTON;
785 sc->hw.buttons = sc->nbuttons;
786 sc->mode.protocol = MOUSE_PROTO_MSC;
787 sc->mode.packetsize = MOUSE_MSC_PACKETSIZE;
788 sc->mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
789 sc->mode.syncmask[1] = MOUSE_MSC_SYNC;
790 } else if (sc->mode.level == 1) {
791 if (sc->nbuttons > MOUSE_SYS_MAXBUTTON)
792 sc->hw.buttons = MOUSE_SYS_MAXBUTTON;
794 sc->hw.buttons = sc->nbuttons;
795 sc->mode.protocol = MOUSE_PROTO_SYSMOUSE;
796 sc->mode.packetsize = MOUSE_SYS_PACKETSIZE;
797 sc->mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
798 sc->mode.syncmask[1] = MOUSE_SYS_SYNC;
801 bzero(sc->qbuf, sizeof(sc->qbuf));
802 sc->qhead = sc->qtail = sc->qcount = 0;
806 case MOUSE_GETSTATUS: {
807 mousestatus_t *status = (mousestatus_t *) addr;
810 *status = sc->status;
811 sc->status.obutton = sc->status.button;
812 sc->status.button = 0;
813 sc->status.dx = sc->status.dy = sc->status.dz = 0;
816 if (status->dx || status->dy || status->dz)
817 status->flags |= MOUSE_POSCHANGED;
818 if (status->button != status->obutton)
819 status->flags |= MOUSE_BUTTONSCHANGED;
829 DRIVER_MODULE(ums, uhub, ums_driver, ums_devclass, usbd_driver_load, 0);