Home | History | Annotate | Line # | Download | only in usb
ums.c revision 1.80.2.1
      1  1.80.2.1  uebayasi /*	$NetBSD: ums.c,v 1.80.2.1 2010/11/06 08:08:39 uebayasi 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.80.2.1  uebayasi __KERNEL_RCSID(0, "$NetBSD: ums.c,v 1.80.2.1 2010/11/06 08:08:39 uebayasi 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/file.h>
     47       1.1  augustss #include <sys/select.h>
     48       1.1  augustss #include <sys/proc.h>
     49       1.1  augustss #include <sys/vnode.h>
     50       1.1  augustss #include <sys/poll.h>
     51       1.1  augustss 
     52       1.1  augustss #include <dev/usb/usb.h>
     53       1.1  augustss #include <dev/usb/usbhid.h>
     54       1.1  augustss 
     55       1.1  augustss #include <dev/usb/usbdi.h>
     56       1.1  augustss #include <dev/usb/usbdi_util.h>
     57       1.1  augustss #include <dev/usb/usbdevs.h>
     58       1.1  augustss #include <dev/usb/usb_quirks.h>
     59      1.53  augustss #include <dev/usb/uhidev.h>
     60       1.1  augustss #include <dev/usb/hid.h>
     61       1.1  augustss 
     62       1.3  augustss #include <dev/wscons/wsconsio.h>
     63       1.3  augustss #include <dev/wscons/wsmousevar.h>
     64       1.3  augustss 
     65       1.1  augustss #ifdef USB_DEBUG
     66  1.80.2.1  uebayasi #define DPRINTF(x)	if (umsdebug) printf x
     67  1.80.2.1  uebayasi #define DPRINTFN(n,x)	if (umsdebug>(n)) printf x
     68       1.1  augustss int	umsdebug = 0;
     69       1.1  augustss #else
     70       1.1  augustss #define DPRINTF(x)
     71       1.1  augustss #define DPRINTFN(n,x)
     72       1.1  augustss #endif
     73       1.1  augustss 
     74      1.27  augustss #define UMS_BUT(i) ((i) == 1 || (i) == 2 ? 3 - (i) : i)
     75      1.27  augustss 
     76      1.27  augustss #define UMSUNIT(s)	(minor(s))
     77      1.16  augustss 
     78      1.16  augustss #define PS2LBUTMASK	x01
     79      1.16  augustss #define PS2RBUTMASK	x02
     80      1.16  augustss #define PS2MBUTMASK	x04
     81       1.1  augustss #define PS2BUTMASK 0x0f
     82       1.1  augustss 
     83      1.61  jmcneill #define MAX_BUTTONS	31	/* must not exceed size of sc_buttons */
     84      1.53  augustss 
     85       1.1  augustss struct ums_softc {
     86      1.53  augustss 	struct uhidev sc_hdev;
     87      1.53  augustss 
     88      1.63  augustss 	struct hid_location sc_loc_x, sc_loc_y, sc_loc_z, sc_loc_w;
     89      1.53  augustss 	struct hid_location sc_loc_btn[MAX_BUTTONS];
     90       1.1  augustss 
     91      1.16  augustss 	int sc_enabled;
     92       1.3  augustss 
     93      1.16  augustss 	int flags;		/* device configuration */
     94      1.16  augustss #define UMS_Z		0x01	/* z direction available */
     95      1.35  augustss #define UMS_SPUR_BUT_UP	0x02	/* spurious button up events */
     96      1.35  augustss #define UMS_REVZ	0x04	/* Z-axis is reversed */
     97      1.75     rafal #define UMS_W		0x08	/* w direction/tilt available */
     98      1.77   mbalmer #define UMS_ABS		0x10	/* absolute position, touchpanel */
     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 
    110      1.53  augustss Static void ums_intr(struct uhidev *addr, void *ibuf, u_int len);
    111       1.1  augustss 
    112      1.44  augustss Static int	ums_enable(void *);
    113      1.44  augustss Static void	ums_disable(void *);
    114      1.68  christos Static int	ums_ioctl(void *, u_long, void *, int, struct lwp * );
    115       1.3  augustss 
    116       1.3  augustss const struct wsmouse_accessops ums_accessops = {
    117       1.3  augustss 	ums_enable,
    118       1.3  augustss 	ums_ioctl,
    119       1.3  augustss 	ums_disable,
    120       1.3  augustss };
    121       1.3  augustss 
    122      1.73      cube int ums_match(device_t, cfdata_t, void *);
    123      1.71    dyoung void ums_attach(device_t, device_t, void *);
    124      1.71    dyoung void ums_childdet(device_t, device_t);
    125      1.71    dyoung int ums_detach(device_t, int);
    126      1.71    dyoung int ums_activate(device_t, enum devact);
    127      1.71    dyoung extern struct cfdriver ums_cd;
    128      1.73      cube CFATTACH_DECL2_NEW(ums, sizeof(struct ums_softc), ums_match, ums_attach,
    129      1.71    dyoung     ums_detach, ums_activate, NULL, ums_childdet);
    130       1.1  augustss 
    131      1.53  augustss int
    132      1.73      cube ums_match(device_t parent, cfdata_t match, void *aux)
    133       1.1  augustss {
    134      1.53  augustss 	struct uhidev_attach_arg *uha = aux;
    135      1.53  augustss 	int size;
    136       1.1  augustss 	void *desc;
    137      1.57  augustss 
    138      1.79  jakllsch 	/*
    139      1.79  jakllsch 	 * Some (older) Griffin PowerMate knobs may masquerade as a
    140      1.79  jakllsch 	 * mouse, avoid treating them as such, they have only one axis.
    141      1.79  jakllsch 	 */
    142      1.79  jakllsch 	if (uha->uaa->vendor == USB_VENDOR_GRIFFIN &&
    143      1.79  jakllsch 	    uha->uaa->product == USB_PRODUCT_GRIFFIN_POWERMATE)
    144      1.79  jakllsch 		return (UMATCH_NONE);
    145      1.79  jakllsch 
    146      1.53  augustss 	uhidev_get_report_desc(uha->parent, &desc, &size);
    147      1.53  augustss 	if (!hid_is_collection(desc, size, uha->reportid,
    148      1.78  jakllsch 			       HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE)) &&
    149      1.78  jakllsch 	    !hid_is_collection(desc, size, uha->reportid,
    150      1.78  jakllsch 			       HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_POINTER)))
    151       1.1  augustss 		return (UMATCH_NONE);
    152       1.1  augustss 
    153      1.53  augustss 	return (UMATCH_IFACECLASS);
    154       1.1  augustss }
    155       1.1  augustss 
    156      1.53  augustss void
    157      1.73      cube ums_attach(device_t parent, device_t self, void *aux)
    158       1.1  augustss {
    159      1.73      cube 	struct ums_softc *sc = device_private(self);
    160      1.53  augustss 	struct uhidev_attach_arg *uha = aux;
    161       1.3  augustss 	struct wsmousedev_attach_args a;
    162       1.1  augustss 	int size;
    163       1.1  augustss 	void *desc;
    164      1.35  augustss 	u_int32_t flags, quirks;
    165      1.75     rafal 	int i, hl;
    166      1.75     rafal 	struct hid_location *zloc;
    167      1.16  augustss 	struct hid_location loc_btn;
    168       1.1  augustss 
    169      1.69  jmcneill 	aprint_naive("\n");
    170      1.69  jmcneill 
    171      1.73      cube 	sc->sc_hdev.sc_dev = self;
    172      1.53  augustss 	sc->sc_hdev.sc_intr = ums_intr;
    173      1.53  augustss 	sc->sc_hdev.sc_parent = uha->parent;
    174      1.53  augustss 	sc->sc_hdev.sc_report_id = uha->reportid;
    175       1.1  augustss 
    176      1.53  augustss 	quirks = usbd_get_quirks(uha->parent->sc_udev)->uq_flags;
    177      1.35  augustss 	if (quirks & UQ_MS_REVZ)
    178      1.35  augustss 		sc->flags |= UMS_REVZ;
    179      1.35  augustss 	if (quirks & UQ_SPUR_BUT_UP)
    180      1.35  augustss 		sc->flags |= UMS_SPUR_BUT_UP;
    181      1.24  augustss 
    182      1.53  augustss 	uhidev_get_report_desc(uha->parent, &desc, &size);
    183      1.16  augustss 
    184      1.70  jmcneill 	if (!pmf_device_register(self, NULL, NULL))
    185      1.70  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    186      1.70  jmcneill 
    187       1.2  augustss 	if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
    188      1.53  augustss 	       uha->reportid, hid_input, &sc->sc_loc_x, &flags)) {
    189      1.69  jmcneill 		aprint_error("\n%s: mouse has no X report\n",
    190  1.80.2.1  uebayasi 		       device_xname(sc->sc_hdev.sc_dev));
    191  1.80.2.1  uebayasi 		return;
    192      1.16  augustss 	}
    193      1.77   mbalmer 	switch (flags & MOUSE_FLAGS_MASK) {
    194      1.77   mbalmer 	case 0:
    195      1.77   mbalmer 		sc->flags |= UMS_ABS;
    196      1.77   mbalmer 		break;
    197      1.77   mbalmer 	case HIO_RELATIVE:
    198      1.77   mbalmer 		break;
    199      1.77   mbalmer 	default:
    200      1.69  jmcneill 		aprint_error("\n%s: X report 0x%04x not supported\n",
    201  1.80.2.1  uebayasi 		       device_xname(sc->sc_hdev.sc_dev), flags);
    202  1.80.2.1  uebayasi 		return;
    203       1.1  augustss 	}
    204      1.10  augustss 
    205       1.2  augustss 	if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y),
    206      1.53  augustss 	       uha->reportid, hid_input, &sc->sc_loc_y, &flags)) {
    207      1.69  jmcneill 		aprint_error("\n%s: mouse has no Y report\n",
    208  1.80.2.1  uebayasi 		       device_xname(sc->sc_hdev.sc_dev));
    209  1.80.2.1  uebayasi 		return;
    210      1.16  augustss 	}
    211      1.77   mbalmer 	switch (flags & MOUSE_FLAGS_MASK) {
    212      1.77   mbalmer 	case 0:
    213      1.77   mbalmer 		sc->flags |= UMS_ABS;
    214      1.77   mbalmer 		break;
    215      1.77   mbalmer 	case HIO_RELATIVE:
    216      1.77   mbalmer 		break;
    217      1.77   mbalmer 	default:
    218      1.69  jmcneill 		aprint_error("\n%s: Y report 0x%04x not supported\n",
    219  1.80.2.1  uebayasi 		       device_xname(sc->sc_hdev.sc_dev), flags);
    220  1.80.2.1  uebayasi 		return;
    221       1.1  augustss 	}
    222      1.10  augustss 
    223      1.63  augustss 	/* Try the wheel first as the Z activator since it's tradition. */
    224      1.75     rafal 	hl = hid_locate(desc,
    225      1.75     rafal 			size,
    226      1.75     rafal 			HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL),
    227      1.75     rafal 			uha->reportid,
    228      1.75     rafal 			hid_input,
    229      1.75     rafal 			&sc->sc_loc_z,
    230      1.75     rafal 			&flags);
    231      1.75     rafal 
    232      1.75     rafal 	zloc = &sc->sc_loc_z;
    233      1.75     rafal 	if (hl) {
    234      1.77   mbalmer 		if ((flags & MOUSE_FLAGS_MASK) != HIO_RELATIVE) {
    235      1.69  jmcneill 			aprint_verbose("\n%s: Wheel report 0x%04x not "
    236  1.80.2.1  uebayasi 			    "supported\n", device_xname(sc->sc_hdev.sc_dev),
    237      1.69  jmcneill 			    flags);
    238      1.16  augustss 			sc->sc_loc_z.size = 0;	/* Bad Z coord, ignore it */
    239      1.16  augustss 		} else {
    240      1.16  augustss 			sc->flags |= UMS_Z;
    241      1.37  augustss 			/* Wheels need the Z axis reversed. */
    242      1.63  augustss 			sc->flags ^= UMS_REVZ;
    243      1.75     rafal 			/* Put Z on the W coordinate */
    244      1.75     rafal 			zloc = &sc->sc_loc_w;
    245      1.63  augustss 		}
    246      1.75     rafal 	}
    247      1.75     rafal 
    248      1.75     rafal 	hl = hid_locate(desc,
    249      1.75     rafal 			size,
    250      1.75     rafal 			HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Z),
    251      1.75     rafal 			uha->reportid,
    252      1.75     rafal 			hid_input,
    253      1.75     rafal 			zloc,
    254      1.75     rafal 			&flags);
    255      1.75     rafal 
    256      1.75     rafal 	/*
    257      1.75     rafal 	 * The horizontal component of the scrollball can also be given by
    258      1.75     rafal 	 * Application Control Pan in the Consumer page, so if we didnt see
    259      1.75     rafal 	 * any Z then check that.
    260      1.75     rafal 	 */
    261      1.75     rafal 	if (!hl) {
    262      1.75     rafal 		hl = hid_locate(desc,
    263      1.75     rafal 				size,
    264      1.75     rafal 				HID_USAGE2(HUP_CONSUMER, HUC_AC_PAN),
    265      1.75     rafal 				uha->reportid,
    266      1.75     rafal 				hid_input,
    267      1.75     rafal 				zloc,
    268      1.75     rafal 				&flags);
    269      1.75     rafal 	}
    270      1.75     rafal 
    271      1.75     rafal 	if (hl) {
    272      1.77   mbalmer 		if ((flags & MOUSE_FLAGS_MASK) != HIO_RELATIVE) {
    273      1.69  jmcneill 			aprint_verbose("\n%s: Z report 0x%04x not supported\n",
    274  1.80.2.1  uebayasi 			       device_xname(sc->sc_hdev.sc_dev), flags);
    275      1.75     rafal 			zloc->size = 0;	/* Bad Z coord, ignore it */
    276      1.63  augustss 		} else {
    277      1.75     rafal 			if (sc->flags & UMS_Z)
    278      1.75     rafal 				sc->flags |= UMS_W;
    279      1.75     rafal 			else
    280      1.75     rafal 				sc->flags |= UMS_Z;
    281      1.16  augustss 		}
    282       1.6  augustss 	}
    283       1.6  augustss 
    284      1.75     rafal 	/*
    285      1.75     rafal 	 * The Microsoft Wireless Laser Mouse 6000 v2.0 reports a bad
    286      1.75     rafal 	 * position for the wheel and wheel tilt controls -- should be
    287      1.75     rafal 	 * in bytes 3 & 4 of the report.  Fix this if necessary.
    288      1.75     rafal 	 */
    289      1.75     rafal 	if (uha->uaa->vendor == USB_VENDOR_MICROSOFT &&
    290      1.80  matthias 	    (uha->uaa->product == USB_PRODUCT_MICROSOFT_24GHZ_XCVR10 ||
    291      1.80  matthias 	     uha->uaa->product == USB_PRODUCT_MICROSOFT_24GHZ_XCVR20)) {
    292      1.75     rafal 		if ((sc->flags & UMS_Z) && sc->sc_loc_z.pos == 0)
    293      1.75     rafal 			sc->sc_loc_z.pos = 24;
    294      1.75     rafal 		if ((sc->flags & UMS_W) && sc->sc_loc_w.pos == 0)
    295      1.75     rafal 			sc->sc_loc_w.pos = sc->sc_loc_z.pos + 8;
    296      1.75     rafal 	}
    297      1.63  augustss 
    298      1.21  augustss 	/* figure out the number of buttons */
    299      1.21  augustss 	for (i = 1; i <= MAX_BUTTONS; i++)
    300      1.16  augustss 		if (!hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
    301      1.53  augustss 			uha->reportid, hid_input, &loc_btn, 0))
    302      1.16  augustss 			break;
    303      1.16  augustss 	sc->nbuttons = i - 1;
    304      1.16  augustss 
    305      1.75     rafal 	aprint_normal(": %d button%s%s%s%s\n",
    306      1.45  augustss 	    sc->nbuttons, sc->nbuttons == 1 ? "" : "s",
    307      1.75     rafal 	    sc->flags & UMS_W ? ", W" : "",
    308      1.75     rafal 	    sc->flags & UMS_Z ? " and Z dir" : "",
    309      1.75     rafal 	    sc->flags & UMS_W ? "s" : "");
    310      1.16  augustss 
    311      1.16  augustss 	for (i = 1; i <= sc->nbuttons; i++)
    312      1.16  augustss 		hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
    313      1.53  augustss 			   uha->reportid, hid_input,
    314      1.53  augustss 			   &sc->sc_loc_btn[i-1], 0);
    315       1.3  augustss 
    316      1.16  augustss #ifdef USB_DEBUG
    317      1.16  augustss 	DPRINTF(("ums_attach: sc=%p\n", sc));
    318      1.57  augustss 	DPRINTF(("ums_attach: X\t%d/%d\n",
    319      1.16  augustss 		 sc->sc_loc_x.pos, sc->sc_loc_x.size));
    320      1.57  augustss 	DPRINTF(("ums_attach: Y\t%d/%d\n",
    321      1.48  augustss 		 sc->sc_loc_y.pos, sc->sc_loc_y.size));
    322      1.16  augustss 	if (sc->flags & UMS_Z)
    323      1.57  augustss 		DPRINTF(("ums_attach: Z\t%d/%d\n",
    324      1.16  augustss 			 sc->sc_loc_z.pos, sc->sc_loc_z.size));
    325      1.75     rafal 	if (sc->flags & UMS_W)
    326      1.75     rafal 		DPRINTF(("ums_attach: W\t%d/%d\n",
    327      1.75     rafal 			 sc->sc_loc_w.pos, sc->sc_loc_w.size));
    328      1.16  augustss 	for (i = 1; i <= sc->nbuttons; i++) {
    329      1.16  augustss 		DPRINTF(("ums_attach: B%d\t%d/%d\n",
    330      1.16  augustss 			 i, sc->sc_loc_btn[i-1].pos,sc->sc_loc_btn[i-1].size));
    331      1.16  augustss 	}
    332      1.16  augustss #endif
    333      1.16  augustss 
    334       1.3  augustss 	a.accessops = &ums_accessops;
    335       1.3  augustss 	a.accesscookie = sc;
    336       1.3  augustss 
    337      1.47  augustss 	sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
    338      1.40  augustss 
    339  1.80.2.1  uebayasi 	return;
    340      1.16  augustss }
    341      1.16  augustss 
    342      1.25  augustss int
    343  1.80.2.1  uebayasi ums_activate(device_t self, enum devact act)
    344      1.16  augustss {
    345      1.73      cube 	struct ums_softc *sc = device_private(self);
    346      1.28  augustss 
    347      1.28  augustss 	switch (act) {
    348      1.28  augustss 	case DVACT_DEACTIVATE:
    349      1.28  augustss 		sc->sc_dying = 1;
    350      1.76    dyoung 		return 0;
    351      1.76    dyoung 	default:
    352      1.76    dyoung 		return EOPNOTSUPP;
    353      1.28  augustss 	}
    354       1.1  augustss }
    355       1.1  augustss 
    356      1.71    dyoung void
    357      1.71    dyoung ums_childdet(device_t self, device_t child)
    358      1.71    dyoung {
    359      1.71    dyoung 	struct ums_softc *sc = device_private(self);
    360      1.71    dyoung 
    361      1.71    dyoung 	KASSERT(sc->sc_wsmousedev == child);
    362      1.71    dyoung 	sc->sc_wsmousedev = NULL;
    363      1.71    dyoung }
    364      1.71    dyoung 
    365      1.53  augustss int
    366      1.71    dyoung ums_detach(device_t self, int flags)
    367       1.1  augustss {
    368      1.71    dyoung 	struct ums_softc *sc = device_private(self);
    369      1.25  augustss 	int rv = 0;
    370       1.8  augustss 
    371      1.25  augustss 	DPRINTF(("ums_detach: sc=%p flags=%d\n", sc, flags));
    372      1.33  augustss 
    373      1.51  augustss 	/* No need to do reference counting of ums, wsmouse has all the goo. */
    374      1.51  augustss 	if (sc->sc_wsmousedev != NULL)
    375      1.51  augustss 		rv = config_detach(sc->sc_wsmousedev, flags);
    376      1.40  augustss 
    377      1.70  jmcneill 	pmf_device_deregister(self);
    378      1.70  jmcneill 
    379      1.25  augustss 	return (rv);
    380       1.1  augustss }
    381       1.1  augustss 
    382       1.1  augustss void
    383      1.67  christos ums_intr(struct uhidev *addr, void *ibuf, u_int len)
    384       1.1  augustss {
    385      1.53  augustss 	struct ums_softc *sc = (struct ums_softc *)addr;
    386      1.63  augustss 	int dx, dy, dz, dw;
    387      1.27  augustss 	u_int32_t buttons = 0;
    388      1.77   mbalmer 	int i, flags, s;
    389      1.54  augustss 
    390      1.54  augustss 	DPRINTFN(5,("ums_intr: len=%d\n", len));
    391      1.21  augustss 
    392      1.77   mbalmer 	flags = WSMOUSE_INPUT_DELTA;	/* equals 0 */
    393      1.77   mbalmer 
    394       1.1  augustss 	dx =  hid_get_data(ibuf, &sc->sc_loc_x);
    395      1.77   mbalmer 	if (sc->flags & UMS_ABS) {
    396      1.77   mbalmer 		flags |= (WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
    397      1.77   mbalmer 		dy = hid_get_data(ibuf, &sc->sc_loc_y);
    398      1.77   mbalmer 	} else
    399      1.77   mbalmer 		dy = -hid_get_data(ibuf, &sc->sc_loc_y);
    400       1.6  augustss 	dz =  hid_get_data(ibuf, &sc->sc_loc_z);
    401      1.63  augustss 	dw =  hid_get_data(ibuf, &sc->sc_loc_w);
    402      1.77   mbalmer 
    403      1.35  augustss 	if (sc->flags & UMS_REVZ)
    404      1.24  augustss 		dz = -dz;
    405      1.16  augustss 	for (i = 0; i < sc->nbuttons; i++)
    406      1.16  augustss 		if (hid_get_data(ibuf, &sc->sc_loc_btn[i]))
    407      1.16  augustss 			buttons |= (1 << UMS_BUT(i));
    408       1.4  augustss 
    409      1.63  augustss 	if (dx != 0 || dy != 0 || dz != 0 || dw != 0 ||
    410      1.63  augustss 	    buttons != sc->sc_buttons) {
    411      1.63  augustss 		DPRINTFN(10, ("ums_intr: x:%d y:%d z:%d w:%d buttons:0x%x\n",
    412      1.63  augustss 			dx, dy, dz, dw, buttons));
    413       1.4  augustss 		sc->sc_buttons = buttons;
    414      1.35  augustss 		if (sc->sc_wsmousedev != NULL) {
    415      1.23  augustss 			s = spltty();
    416      1.77   mbalmer 			wsmouse_input(sc->sc_wsmousedev, buttons, dx, dy, dz,
    417      1.77   mbalmer 			    dw, flags);
    418      1.23  augustss 			splx(s);
    419      1.23  augustss 		}
    420       1.1  augustss 	}
    421       1.1  augustss }
    422       1.3  augustss 
    423      1.42  augustss Static int
    424      1.44  augustss ums_enable(void *v)
    425       1.3  augustss {
    426       1.3  augustss 	struct ums_softc *sc = v;
    427      1.16  augustss 
    428      1.25  augustss 	DPRINTFN(1,("ums_enable: sc=%p\n", sc));
    429      1.28  augustss 
    430      1.28  augustss 	if (sc->sc_dying)
    431      1.28  augustss 		return (EIO);
    432      1.28  augustss 
    433       1.3  augustss 	if (sc->sc_enabled)
    434      1.28  augustss 		return (EBUSY);
    435       1.3  augustss 
    436       1.3  augustss 	sc->sc_enabled = 1;
    437       1.4  augustss 	sc->sc_buttons = 0;
    438       1.3  augustss 
    439      1.53  augustss 	return (uhidev_open(&sc->sc_hdev));
    440       1.3  augustss }
    441       1.3  augustss 
    442      1.42  augustss Static void
    443      1.44  augustss ums_disable(void *v)
    444       1.3  augustss {
    445       1.3  augustss 	struct ums_softc *sc = v;
    446      1.25  augustss 
    447      1.25  augustss 	DPRINTFN(1,("ums_disable: sc=%p\n", sc));
    448      1.25  augustss #ifdef DIAGNOSTIC
    449      1.25  augustss 	if (!sc->sc_enabled) {
    450      1.25  augustss 		printf("ums_disable: not enabled\n");
    451      1.25  augustss 		return;
    452      1.25  augustss 	}
    453      1.25  augustss #endif
    454       1.3  augustss 
    455       1.3  augustss 	sc->sc_enabled = 0;
    456      1.59    simonb 	uhidev_close(&sc->sc_hdev);
    457       1.3  augustss }
    458       1.3  augustss 
    459      1.42  augustss Static int
    460      1.68  christos ums_ioctl(void *v, u_long cmd, void *data, int flag,
    461      1.67  christos     struct lwp * p)
    462      1.16  augustss 
    463       1.3  augustss {
    464      1.77   mbalmer 	struct ums_softc *sc = v;
    465      1.77   mbalmer 
    466       1.3  augustss 	switch (cmd) {
    467       1.3  augustss 	case WSMOUSEIO_GTYPE:
    468      1.77   mbalmer 		if (sc->flags & UMS_ABS)
    469      1.77   mbalmer 			*(u_int *)data = WSMOUSE_TYPE_TPANEL;
    470      1.77   mbalmer 		else
    471      1.77   mbalmer 			*(u_int *)data = WSMOUSE_TYPE_USB;
    472       1.3  augustss 		return (0);
    473       1.3  augustss 	}
    474      1.16  augustss 
    475      1.56    atatat 	return (EPASSTHROUGH);
    476       1.3  augustss }
    477