Home | History | Annotate | Line # | Download | only in usb
ums.c revision 1.73.8.1
      1  1.73.8.1  sborrill /*	$NetBSD: ums.c,v 1.73.8.1 2009/11/27 08:54:13 sborrill Exp $	*/
      2       1.1  augustss 
      3       1.1  augustss /*
      4       1.1  augustss  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.1  augustss  * All rights reserved.
      6       1.1  augustss  *
      7      1.11  augustss  * This code is derived from software contributed to The NetBSD Foundation
      8      1.43  augustss  * by Lennart Augustsson (lennart (at) augustsson.net) at
      9      1.11  augustss  * Carlstedt Research & Technology.
     10       1.1  augustss  *
     11       1.1  augustss  * Redistribution and use in source and binary forms, with or without
     12       1.1  augustss  * modification, are permitted provided that the following conditions
     13       1.1  augustss  * are met:
     14       1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     15       1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     16       1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     18       1.1  augustss  *    documentation and/or other materials provided with the distribution.
     19       1.1  augustss  *
     20       1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21       1.1  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22       1.1  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23       1.1  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24       1.1  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25       1.1  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26       1.1  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27       1.1  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28       1.1  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29       1.1  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30       1.1  augustss  * POSSIBILITY OF SUCH DAMAGE.
     31      1.20  augustss  */
     32      1.20  augustss 
     33      1.20  augustss /*
     34      1.60  augustss  * HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
     35       1.1  augustss  */
     36      1.52     lukem 
     37      1.52     lukem #include <sys/cdefs.h>
     38  1.73.8.1  sborrill __KERNEL_RCSID(0, "$NetBSD: ums.c,v 1.73.8.1 2009/11/27 08:54:13 sborrill Exp $");
     39       1.1  augustss 
     40       1.1  augustss #include <sys/param.h>
     41       1.1  augustss #include <sys/systm.h>
     42       1.1  augustss #include <sys/kernel.h>
     43       1.1  augustss #include <sys/malloc.h>
     44       1.1  augustss #include <sys/device.h>
     45       1.1  augustss #include <sys/ioctl.h>
     46       1.1  augustss #include <sys/tty.h>
     47       1.1  augustss #include <sys/file.h>
     48       1.1  augustss #include <sys/select.h>
     49       1.1  augustss #include <sys/proc.h>
     50       1.1  augustss #include <sys/vnode.h>
     51       1.1  augustss #include <sys/poll.h>
     52       1.1  augustss 
     53       1.1  augustss #include <dev/usb/usb.h>
     54       1.1  augustss #include <dev/usb/usbhid.h>
     55       1.1  augustss 
     56       1.1  augustss #include <dev/usb/usbdi.h>
     57       1.1  augustss #include <dev/usb/usbdi_util.h>
     58       1.1  augustss #include <dev/usb/usbdevs.h>
     59       1.1  augustss #include <dev/usb/usb_quirks.h>
     60      1.53  augustss #include <dev/usb/uhidev.h>
     61       1.1  augustss #include <dev/usb/hid.h>
     62       1.1  augustss 
     63       1.3  augustss #include <dev/wscons/wsconsio.h>
     64       1.3  augustss #include <dev/wscons/wsmousevar.h>
     65       1.3  augustss 
     66       1.1  augustss #ifdef USB_DEBUG
     67      1.26  augustss #define DPRINTF(x)	if (umsdebug) logprintf x
     68      1.26  augustss #define DPRINTFN(n,x)	if (umsdebug>(n)) logprintf x
     69       1.1  augustss int	umsdebug = 0;
     70       1.1  augustss #else
     71       1.1  augustss #define DPRINTF(x)
     72       1.1  augustss #define DPRINTFN(n,x)
     73       1.1  augustss #endif
     74       1.1  augustss 
     75      1.27  augustss #define UMS_BUT(i) ((i) == 1 || (i) == 2 ? 3 - (i) : i)
     76      1.27  augustss 
     77      1.27  augustss #define UMSUNIT(s)	(minor(s))
     78      1.16  augustss 
     79      1.16  augustss #define PS2LBUTMASK	x01
     80      1.16  augustss #define PS2RBUTMASK	x02
     81      1.16  augustss #define PS2MBUTMASK	x04
     82       1.1  augustss #define PS2BUTMASK 0x0f
     83       1.1  augustss 
     84      1.61  jmcneill #define MAX_BUTTONS	31	/* must not exceed size of sc_buttons */
     85      1.53  augustss 
     86       1.1  augustss struct ums_softc {
     87      1.53  augustss 	struct uhidev sc_hdev;
     88      1.53  augustss 
     89      1.63  augustss 	struct hid_location sc_loc_x, sc_loc_y, sc_loc_z, sc_loc_w;
     90      1.53  augustss 	struct hid_location sc_loc_btn[MAX_BUTTONS];
     91       1.1  augustss 
     92      1.16  augustss 	int sc_enabled;
     93       1.3  augustss 
     94      1.16  augustss 	int flags;		/* device configuration */
     95      1.16  augustss #define UMS_Z		0x01	/* z direction available */
     96      1.35  augustss #define UMS_SPUR_BUT_UP	0x02	/* spurious button up events */
     97      1.35  augustss #define UMS_REVZ	0x04	/* Z-axis is reversed */
     98  1.73.8.1  sborrill #define UMS_W		0x08	/* w direction/tilt available */
     99      1.35  augustss 
    100      1.16  augustss 	int nbuttons;
    101      1.16  augustss 
    102      1.27  augustss 	u_int32_t sc_buttons;	/* mouse button status */
    103      1.71    dyoung 	device_t sc_wsmousedev;
    104      1.28  augustss 
    105      1.28  augustss 	char			sc_dying;
    106       1.1  augustss };
    107       1.1  augustss 
    108       1.2  augustss #define MOUSE_FLAGS_MASK (HIO_CONST|HIO_RELATIVE)
    109       1.2  augustss #define MOUSE_FLAGS (HIO_RELATIVE)
    110       1.2  augustss 
    111      1.53  augustss Static void ums_intr(struct uhidev *addr, void *ibuf, u_int len);
    112       1.1  augustss 
    113      1.44  augustss Static int	ums_enable(void *);
    114      1.44  augustss Static void	ums_disable(void *);
    115      1.68  christos Static int	ums_ioctl(void *, u_long, void *, int, struct lwp * );
    116       1.3  augustss 
    117       1.3  augustss const struct wsmouse_accessops ums_accessops = {
    118       1.3  augustss 	ums_enable,
    119       1.3  augustss 	ums_ioctl,
    120       1.3  augustss 	ums_disable,
    121       1.3  augustss };
    122       1.3  augustss 
    123      1.73      cube int ums_match(device_t, cfdata_t, void *);
    124      1.71    dyoung void ums_attach(device_t, device_t, void *);
    125      1.71    dyoung void ums_childdet(device_t, device_t);
    126      1.71    dyoung int ums_detach(device_t, int);
    127      1.71    dyoung int ums_activate(device_t, enum devact);
    128      1.71    dyoung extern struct cfdriver ums_cd;
    129      1.73      cube CFATTACH_DECL2_NEW(ums, sizeof(struct ums_softc), ums_match, ums_attach,
    130      1.71    dyoung     ums_detach, ums_activate, NULL, ums_childdet);
    131       1.1  augustss 
    132      1.53  augustss int
    133      1.73      cube ums_match(device_t parent, cfdata_t match, void *aux)
    134       1.1  augustss {
    135      1.53  augustss 	struct uhidev_attach_arg *uha = aux;
    136      1.53  augustss 	int size;
    137       1.1  augustss 	void *desc;
    138      1.57  augustss 
    139      1.53  augustss 	uhidev_get_report_desc(uha->parent, &desc, &size);
    140      1.53  augustss 	if (!hid_is_collection(desc, size, uha->reportid,
    141      1.53  augustss 			       HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE)))
    142       1.1  augustss 		return (UMATCH_NONE);
    143       1.1  augustss 
    144      1.53  augustss 	return (UMATCH_IFACECLASS);
    145       1.1  augustss }
    146       1.1  augustss 
    147      1.53  augustss void
    148      1.73      cube ums_attach(device_t parent, device_t self, void *aux)
    149       1.1  augustss {
    150      1.73      cube 	struct ums_softc *sc = device_private(self);
    151      1.53  augustss 	struct uhidev_attach_arg *uha = aux;
    152       1.3  augustss 	struct wsmousedev_attach_args a;
    153       1.1  augustss 	int size;
    154       1.1  augustss 	void *desc;
    155      1.35  augustss 	u_int32_t flags, quirks;
    156  1.73.8.1  sborrill 	int i, hl;
    157  1.73.8.1  sborrill 	struct hid_location *zloc;
    158      1.16  augustss 	struct hid_location loc_btn;
    159       1.1  augustss 
    160      1.69  jmcneill 	aprint_naive("\n");
    161      1.69  jmcneill 
    162      1.73      cube 	sc->sc_hdev.sc_dev = self;
    163      1.53  augustss 	sc->sc_hdev.sc_intr = ums_intr;
    164      1.53  augustss 	sc->sc_hdev.sc_parent = uha->parent;
    165      1.53  augustss 	sc->sc_hdev.sc_report_id = uha->reportid;
    166       1.1  augustss 
    167      1.53  augustss 	quirks = usbd_get_quirks(uha->parent->sc_udev)->uq_flags;
    168      1.35  augustss 	if (quirks & UQ_MS_REVZ)
    169      1.35  augustss 		sc->flags |= UMS_REVZ;
    170      1.35  augustss 	if (quirks & UQ_SPUR_BUT_UP)
    171      1.35  augustss 		sc->flags |= UMS_SPUR_BUT_UP;
    172      1.24  augustss 
    173      1.53  augustss 	uhidev_get_report_desc(uha->parent, &desc, &size);
    174      1.16  augustss 
    175      1.70  jmcneill 	if (!pmf_device_register(self, NULL, NULL))
    176      1.70  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    177      1.70  jmcneill 
    178       1.2  augustss 	if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
    179      1.53  augustss 	       uha->reportid, hid_input, &sc->sc_loc_x, &flags)) {
    180      1.69  jmcneill 		aprint_error("\n%s: mouse has no X report\n",
    181      1.53  augustss 		       USBDEVNAME(sc->sc_hdev.sc_dev));
    182      1.16  augustss 		USB_ATTACH_ERROR_RETURN;
    183      1.16  augustss 	}
    184      1.16  augustss 	if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
    185      1.69  jmcneill 		aprint_error("\n%s: X report 0x%04x not supported\n",
    186      1.53  augustss 		       USBDEVNAME(sc->sc_hdev.sc_dev), flags);
    187      1.16  augustss 		USB_ATTACH_ERROR_RETURN;
    188       1.1  augustss 	}
    189      1.10  augustss 
    190       1.2  augustss 	if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y),
    191      1.53  augustss 	       uha->reportid, hid_input, &sc->sc_loc_y, &flags)) {
    192      1.69  jmcneill 		aprint_error("\n%s: mouse has no Y report\n",
    193      1.53  augustss 		       USBDEVNAME(sc->sc_hdev.sc_dev));
    194      1.16  augustss 		USB_ATTACH_ERROR_RETURN;
    195      1.16  augustss 	}
    196      1.16  augustss 	if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
    197      1.69  jmcneill 		aprint_error("\n%s: Y report 0x%04x not supported\n",
    198      1.53  augustss 		       USBDEVNAME(sc->sc_hdev.sc_dev), flags);
    199      1.16  augustss 		USB_ATTACH_ERROR_RETURN;
    200       1.1  augustss 	}
    201      1.10  augustss 
    202      1.63  augustss 	/* Try the wheel first as the Z activator since it's tradition. */
    203  1.73.8.1  sborrill 	hl = hid_locate(desc,
    204  1.73.8.1  sborrill 			size,
    205  1.73.8.1  sborrill 			HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL),
    206  1.73.8.1  sborrill 			uha->reportid,
    207  1.73.8.1  sborrill 			hid_input,
    208  1.73.8.1  sborrill 			&sc->sc_loc_z,
    209  1.73.8.1  sborrill 			&flags);
    210  1.73.8.1  sborrill 
    211  1.73.8.1  sborrill 	zloc = &sc->sc_loc_z;
    212  1.73.8.1  sborrill 	if (hl) {
    213      1.16  augustss 		if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
    214      1.69  jmcneill 			aprint_verbose("\n%s: Wheel report 0x%04x not "
    215      1.69  jmcneill 			    "supported\n", USBDEVNAME(sc->sc_hdev.sc_dev),
    216      1.69  jmcneill 			    flags);
    217      1.16  augustss 			sc->sc_loc_z.size = 0;	/* Bad Z coord, ignore it */
    218      1.16  augustss 		} else {
    219      1.16  augustss 			sc->flags |= UMS_Z;
    220      1.37  augustss 			/* Wheels need the Z axis reversed. */
    221      1.63  augustss 			sc->flags ^= UMS_REVZ;
    222  1.73.8.1  sborrill 			/* Put Z on the W coordinate */
    223  1.73.8.1  sborrill 			zloc = &sc->sc_loc_w;
    224      1.63  augustss 		}
    225  1.73.8.1  sborrill 	}
    226  1.73.8.1  sborrill 
    227  1.73.8.1  sborrill 	hl = hid_locate(desc,
    228  1.73.8.1  sborrill 			size,
    229  1.73.8.1  sborrill 			HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Z),
    230  1.73.8.1  sborrill 			uha->reportid,
    231  1.73.8.1  sborrill 			hid_input,
    232  1.73.8.1  sborrill 			zloc,
    233  1.73.8.1  sborrill 			&flags);
    234  1.73.8.1  sborrill 
    235  1.73.8.1  sborrill 	/*
    236  1.73.8.1  sborrill 	 * The horizontal component of the scrollball can also be given by
    237  1.73.8.1  sborrill 	 * Application Control Pan in the Consumer page, so if we didnt see
    238  1.73.8.1  sborrill 	 * any Z then check that.
    239  1.73.8.1  sborrill 	 */
    240  1.73.8.1  sborrill 	if (!hl) {
    241  1.73.8.1  sborrill 		hl = hid_locate(desc,
    242  1.73.8.1  sborrill 				size,
    243  1.73.8.1  sborrill 				HID_USAGE2(HUP_CONSUMER, HUC_AC_PAN),
    244  1.73.8.1  sborrill 				uha->reportid,
    245  1.73.8.1  sborrill 				hid_input,
    246  1.73.8.1  sborrill 				zloc,
    247  1.73.8.1  sborrill 				&flags);
    248  1.73.8.1  sborrill 	}
    249  1.73.8.1  sborrill 
    250  1.73.8.1  sborrill 	if (hl) {
    251      1.63  augustss 		if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
    252      1.69  jmcneill 			aprint_verbose("\n%s: Z report 0x%04x not supported\n",
    253      1.63  augustss 			       USBDEVNAME(sc->sc_hdev.sc_dev), flags);
    254  1.73.8.1  sborrill 			zloc->size = 0;	/* Bad Z coord, ignore it */
    255      1.63  augustss 		} else {
    256  1.73.8.1  sborrill 			if (sc->flags & UMS_Z)
    257  1.73.8.1  sborrill 				sc->flags |= UMS_W;
    258  1.73.8.1  sborrill 			else
    259  1.73.8.1  sborrill 				sc->flags |= UMS_Z;
    260      1.16  augustss 		}
    261       1.6  augustss 	}
    262       1.6  augustss 
    263  1.73.8.1  sborrill 	/*
    264  1.73.8.1  sborrill 	 * The Microsoft Wireless Laser Mouse 6000 v2.0 reports a bad
    265  1.73.8.1  sborrill 	 * position for the wheel and wheel tilt controls -- should be
    266  1.73.8.1  sborrill 	 * in bytes 3 & 4 of the report.  Fix this if necessary.
    267  1.73.8.1  sborrill 	 */
    268  1.73.8.1  sborrill 	if (uha->uaa->vendor == USB_VENDOR_MICROSOFT &&
    269  1.73.8.1  sborrill 	    uha->uaa->product == USB_PRODUCT_MICROSOFT_24GHZ_XCVR) {
    270  1.73.8.1  sborrill 		if ((sc->flags & UMS_Z) && sc->sc_loc_z.pos == 0)
    271  1.73.8.1  sborrill 			sc->sc_loc_z.pos = 24;
    272  1.73.8.1  sborrill 		if ((sc->flags & UMS_W) && sc->sc_loc_w.pos == 0)
    273  1.73.8.1  sborrill 			sc->sc_loc_w.pos = sc->sc_loc_z.pos + 8;
    274  1.73.8.1  sborrill 	}
    275      1.63  augustss 
    276      1.21  augustss 	/* figure out the number of buttons */
    277      1.21  augustss 	for (i = 1; i <= MAX_BUTTONS; i++)
    278      1.16  augustss 		if (!hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
    279      1.53  augustss 			uha->reportid, hid_input, &loc_btn, 0))
    280      1.16  augustss 			break;
    281      1.16  augustss 	sc->nbuttons = i - 1;
    282      1.16  augustss 
    283  1.73.8.1  sborrill 	aprint_normal(": %d button%s%s%s%s\n",
    284      1.45  augustss 	    sc->nbuttons, sc->nbuttons == 1 ? "" : "s",
    285  1.73.8.1  sborrill 	    sc->flags & UMS_W ? ", W" : "",
    286  1.73.8.1  sborrill 	    sc->flags & UMS_Z ? " and Z dir" : "",
    287  1.73.8.1  sborrill 	    sc->flags & UMS_W ? "s" : "");
    288      1.16  augustss 
    289      1.16  augustss 	for (i = 1; i <= sc->nbuttons; i++)
    290      1.16  augustss 		hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
    291      1.53  augustss 			   uha->reportid, hid_input,
    292      1.53  augustss 			   &sc->sc_loc_btn[i-1], 0);
    293       1.3  augustss 
    294      1.16  augustss #ifdef USB_DEBUG
    295      1.16  augustss 	DPRINTF(("ums_attach: sc=%p\n", sc));
    296      1.57  augustss 	DPRINTF(("ums_attach: X\t%d/%d\n",
    297      1.16  augustss 		 sc->sc_loc_x.pos, sc->sc_loc_x.size));
    298      1.57  augustss 	DPRINTF(("ums_attach: Y\t%d/%d\n",
    299      1.48  augustss 		 sc->sc_loc_y.pos, sc->sc_loc_y.size));
    300      1.16  augustss 	if (sc->flags & UMS_Z)
    301      1.57  augustss 		DPRINTF(("ums_attach: Z\t%d/%d\n",
    302      1.16  augustss 			 sc->sc_loc_z.pos, sc->sc_loc_z.size));
    303  1.73.8.1  sborrill 	if (sc->flags & UMS_W)
    304  1.73.8.1  sborrill 		DPRINTF(("ums_attach: W\t%d/%d\n",
    305  1.73.8.1  sborrill 			 sc->sc_loc_w.pos, sc->sc_loc_w.size));
    306      1.16  augustss 	for (i = 1; i <= sc->nbuttons; i++) {
    307      1.16  augustss 		DPRINTF(("ums_attach: B%d\t%d/%d\n",
    308      1.16  augustss 			 i, sc->sc_loc_btn[i-1].pos,sc->sc_loc_btn[i-1].size));
    309      1.16  augustss 	}
    310      1.16  augustss #endif
    311      1.16  augustss 
    312       1.3  augustss 	a.accessops = &ums_accessops;
    313       1.3  augustss 	a.accesscookie = sc;
    314       1.3  augustss 
    315      1.47  augustss 	sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
    316      1.40  augustss 
    317      1.16  augustss 	USB_ATTACH_SUCCESS_RETURN;
    318      1.16  augustss }
    319      1.16  augustss 
    320      1.25  augustss int
    321      1.44  augustss ums_activate(device_ptr_t self, enum devact act)
    322      1.16  augustss {
    323      1.73      cube 	struct ums_softc *sc = device_private(self);
    324      1.32  augustss 	int rv = 0;
    325      1.28  augustss 
    326      1.28  augustss 	switch (act) {
    327      1.28  augustss 	case DVACT_ACTIVATE:
    328      1.28  augustss 		return (EOPNOTSUPP);
    329      1.28  augustss 
    330      1.28  augustss 	case DVACT_DEACTIVATE:
    331      1.34  augustss 		if (sc->sc_wsmousedev != NULL)
    332      1.32  augustss 			rv = config_deactivate(sc->sc_wsmousedev);
    333      1.28  augustss 		sc->sc_dying = 1;
    334      1.28  augustss 		break;
    335      1.28  augustss 	}
    336      1.32  augustss 	return (rv);
    337       1.1  augustss }
    338       1.1  augustss 
    339      1.71    dyoung void
    340      1.71    dyoung ums_childdet(device_t self, device_t child)
    341      1.71    dyoung {
    342      1.71    dyoung 	struct ums_softc *sc = device_private(self);
    343      1.71    dyoung 
    344      1.71    dyoung 	KASSERT(sc->sc_wsmousedev == child);
    345      1.71    dyoung 	sc->sc_wsmousedev = NULL;
    346      1.71    dyoung }
    347      1.71    dyoung 
    348      1.53  augustss int
    349      1.71    dyoung ums_detach(device_t self, int flags)
    350       1.1  augustss {
    351      1.71    dyoung 	struct ums_softc *sc = device_private(self);
    352      1.25  augustss 	int rv = 0;
    353       1.8  augustss 
    354      1.25  augustss 	DPRINTF(("ums_detach: sc=%p flags=%d\n", sc, flags));
    355      1.33  augustss 
    356      1.51  augustss 	/* No need to do reference counting of ums, wsmouse has all the goo. */
    357      1.51  augustss 	if (sc->sc_wsmousedev != NULL)
    358      1.51  augustss 		rv = config_detach(sc->sc_wsmousedev, flags);
    359      1.40  augustss 
    360      1.70  jmcneill 	pmf_device_deregister(self);
    361      1.70  jmcneill 
    362      1.25  augustss 	return (rv);
    363       1.1  augustss }
    364       1.1  augustss 
    365       1.1  augustss void
    366      1.67  christos ums_intr(struct uhidev *addr, void *ibuf, u_int len)
    367       1.1  augustss {
    368      1.53  augustss 	struct ums_softc *sc = (struct ums_softc *)addr;
    369      1.63  augustss 	int dx, dy, dz, dw;
    370      1.27  augustss 	u_int32_t buttons = 0;
    371      1.16  augustss 	int i;
    372      1.23  augustss 	int s;
    373      1.54  augustss 
    374      1.54  augustss 	DPRINTFN(5,("ums_intr: len=%d\n", len));
    375      1.21  augustss 
    376       1.1  augustss 	dx =  hid_get_data(ibuf, &sc->sc_loc_x);
    377       1.1  augustss 	dy = -hid_get_data(ibuf, &sc->sc_loc_y);
    378       1.6  augustss 	dz =  hid_get_data(ibuf, &sc->sc_loc_z);
    379      1.63  augustss 	dw =  hid_get_data(ibuf, &sc->sc_loc_w);
    380      1.35  augustss 	if (sc->flags & UMS_REVZ)
    381      1.24  augustss 		dz = -dz;
    382      1.16  augustss 	for (i = 0; i < sc->nbuttons; i++)
    383      1.16  augustss 		if (hid_get_data(ibuf, &sc->sc_loc_btn[i]))
    384      1.16  augustss 			buttons |= (1 << UMS_BUT(i));
    385       1.4  augustss 
    386      1.63  augustss 	if (dx != 0 || dy != 0 || dz != 0 || dw != 0 ||
    387      1.63  augustss 	    buttons != sc->sc_buttons) {
    388      1.63  augustss 		DPRINTFN(10, ("ums_intr: x:%d y:%d z:%d w:%d buttons:0x%x\n",
    389      1.63  augustss 			dx, dy, dz, dw, buttons));
    390       1.4  augustss 		sc->sc_buttons = buttons;
    391      1.35  augustss 		if (sc->sc_wsmousedev != NULL) {
    392      1.23  augustss 			s = spltty();
    393      1.66    plunky 			wsmouse_input(sc->sc_wsmousedev,
    394      1.66    plunky 					buttons,
    395      1.66    plunky 					dx, dy, dz, dw,
    396      1.66    plunky 					WSMOUSE_INPUT_DELTA);
    397      1.23  augustss 			splx(s);
    398      1.23  augustss 		}
    399       1.1  augustss 	}
    400       1.1  augustss }
    401       1.3  augustss 
    402      1.42  augustss Static int
    403      1.44  augustss ums_enable(void *v)
    404       1.3  augustss {
    405       1.3  augustss 	struct ums_softc *sc = v;
    406      1.16  augustss 
    407      1.25  augustss 	DPRINTFN(1,("ums_enable: sc=%p\n", sc));
    408      1.28  augustss 
    409      1.28  augustss 	if (sc->sc_dying)
    410      1.28  augustss 		return (EIO);
    411      1.28  augustss 
    412       1.3  augustss 	if (sc->sc_enabled)
    413      1.28  augustss 		return (EBUSY);
    414       1.3  augustss 
    415       1.3  augustss 	sc->sc_enabled = 1;
    416       1.4  augustss 	sc->sc_buttons = 0;
    417       1.3  augustss 
    418      1.53  augustss 	return (uhidev_open(&sc->sc_hdev));
    419       1.3  augustss }
    420       1.3  augustss 
    421      1.42  augustss Static void
    422      1.44  augustss ums_disable(void *v)
    423       1.3  augustss {
    424       1.3  augustss 	struct ums_softc *sc = v;
    425      1.25  augustss 
    426      1.25  augustss 	DPRINTFN(1,("ums_disable: sc=%p\n", sc));
    427      1.25  augustss #ifdef DIAGNOSTIC
    428      1.25  augustss 	if (!sc->sc_enabled) {
    429      1.25  augustss 		printf("ums_disable: not enabled\n");
    430      1.25  augustss 		return;
    431      1.25  augustss 	}
    432      1.25  augustss #endif
    433       1.3  augustss 
    434       1.3  augustss 	sc->sc_enabled = 0;
    435      1.59    simonb 	uhidev_close(&sc->sc_hdev);
    436       1.3  augustss }
    437       1.3  augustss 
    438      1.42  augustss Static int
    439      1.68  christos ums_ioctl(void *v, u_long cmd, void *data, int flag,
    440      1.67  christos     struct lwp * p)
    441      1.16  augustss 
    442       1.3  augustss {
    443       1.3  augustss 	switch (cmd) {
    444       1.3  augustss 	case WSMOUSEIO_GTYPE:
    445      1.17  augustss 		*(u_int *)data = WSMOUSE_TYPE_USB;
    446       1.3  augustss 		return (0);
    447       1.3  augustss 	}
    448      1.16  augustss 
    449      1.56    atatat 	return (EPASSTHROUGH);
    450       1.3  augustss }
    451