Home | History | Annotate | Line # | Download | only in usb
ums.c revision 1.33.4.1
      1  1.33.4.1      fvdl /*	$NetBSD: ums.c,v 1.33.4.1 1999/11/15 00:41:38 fvdl 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.11  augustss  * by Lennart Augustsson (augustss (at) carlstedt.se) 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  * 3. All advertising materials mentioning features or use of this software
     20       1.1  augustss  *    must display the following acknowledgement:
     21       1.1  augustss  *        This product includes software developed by the NetBSD
     22       1.1  augustss  *        Foundation, Inc. and its contributors.
     23       1.1  augustss  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24       1.1  augustss  *    contributors may be used to endorse or promote products derived
     25       1.1  augustss  *    from this software without specific prior written permission.
     26       1.1  augustss  *
     27       1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28       1.1  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29       1.1  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30       1.1  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31       1.1  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32       1.1  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33       1.1  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34       1.1  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35       1.1  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36       1.1  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37       1.1  augustss  * POSSIBILITY OF SUCH DAMAGE.
     38      1.20  augustss  */
     39      1.20  augustss 
     40      1.20  augustss /*
     41      1.20  augustss  * HID spec: http://www.usb.org/developers/data/usbhid10.pdf
     42       1.1  augustss  */
     43       1.1  augustss 
     44       1.1  augustss #include <sys/param.h>
     45       1.1  augustss #include <sys/systm.h>
     46       1.1  augustss #include <sys/kernel.h>
     47       1.1  augustss #include <sys/malloc.h>
     48       1.1  augustss #include <sys/device.h>
     49       1.1  augustss #include <sys/ioctl.h>
     50       1.1  augustss #include <sys/tty.h>
     51       1.1  augustss #include <sys/file.h>
     52       1.1  augustss #include <sys/select.h>
     53       1.1  augustss #include <sys/proc.h>
     54       1.1  augustss #include <sys/vnode.h>
     55       1.1  augustss #include <sys/poll.h>
     56       1.1  augustss 
     57       1.1  augustss #include <dev/usb/usb.h>
     58       1.1  augustss #include <dev/usb/usbhid.h>
     59       1.1  augustss 
     60       1.1  augustss #include <dev/usb/usbdi.h>
     61       1.1  augustss #include <dev/usb/usbdi_util.h>
     62       1.1  augustss #include <dev/usb/usbdevs.h>
     63       1.1  augustss #include <dev/usb/usb_quirks.h>
     64       1.1  augustss #include <dev/usb/hid.h>
     65       1.1  augustss 
     66       1.3  augustss #include <dev/wscons/wsconsio.h>
     67       1.3  augustss #include <dev/wscons/wsmousevar.h>
     68       1.3  augustss 
     69       1.1  augustss #ifdef USB_DEBUG
     70      1.26  augustss #define DPRINTF(x)	if (umsdebug) logprintf x
     71      1.26  augustss #define DPRINTFN(n,x)	if (umsdebug>(n)) logprintf x
     72       1.1  augustss int	umsdebug = 0;
     73       1.1  augustss #else
     74       1.1  augustss #define DPRINTF(x)
     75       1.1  augustss #define DPRINTFN(n,x)
     76       1.1  augustss #endif
     77       1.1  augustss 
     78      1.27  augustss #define UMS_BUT(i) ((i) == 1 || (i) == 2 ? 3 - (i) : i)
     79      1.27  augustss 
     80      1.27  augustss #define UMSUNIT(s)	(minor(s))
     81      1.16  augustss 
     82      1.16  augustss #define PS2LBUTMASK	x01
     83      1.16  augustss #define PS2RBUTMASK	x02
     84      1.16  augustss #define PS2MBUTMASK	x04
     85       1.1  augustss #define PS2BUTMASK 0x0f
     86       1.1  augustss 
     87       1.1  augustss struct ums_softc {
     88      1.31  augustss 	USBBASEDEVICE sc_dev;		/* base device */
     89       1.1  augustss 	usbd_interface_handle sc_iface;	/* interface */
     90       1.1  augustss 	usbd_pipe_handle sc_intrpipe;	/* interrupt pipe */
     91       1.1  augustss 	int sc_ep_addr;
     92       1.1  augustss 
     93       1.1  augustss 	u_char *sc_ibuf;
     94       1.1  augustss 	u_int8_t sc_iid;
     95       1.1  augustss 	int sc_isize;
     96      1.16  augustss 	struct hid_location sc_loc_x, sc_loc_y, sc_loc_z;
     97      1.16  augustss 	struct hid_location *sc_loc_btn;
     98       1.1  augustss 
     99      1.16  augustss 	int sc_enabled;
    100       1.3  augustss 
    101      1.16  augustss 	int flags;		/* device configuration */
    102      1.16  augustss #define UMS_Z		0x01	/* z direction available */
    103      1.16  augustss 	int nbuttons;
    104      1.27  augustss #define MAX_BUTTONS	31	/* chosen because sc_buttons is u_int32_t */
    105      1.16  augustss 
    106      1.24  augustss 	char revz;		/* Z-axis is reversed */
    107      1.24  augustss 
    108      1.27  augustss 	u_int32_t sc_buttons;	/* mouse button status */
    109       1.3  augustss 	struct device *sc_wsmousedev;
    110      1.28  augustss 
    111      1.28  augustss 	char			sc_dying;
    112       1.1  augustss };
    113       1.1  augustss 
    114       1.2  augustss #define MOUSE_FLAGS_MASK (HIO_CONST|HIO_RELATIVE)
    115       1.2  augustss #define MOUSE_FLAGS (HIO_RELATIVE)
    116       1.2  augustss 
    117  1.33.4.1      fvdl static void ums_intr __P((usbd_xfer_handle, usbd_private_handle,
    118  1.33.4.1      fvdl 			  usbd_status));
    119       1.1  augustss 
    120      1.16  augustss static int	ums_enable __P((void *));
    121      1.16  augustss static void	ums_disable __P((void *));
    122      1.16  augustss static int	ums_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
    123       1.3  augustss 
    124       1.3  augustss const struct wsmouse_accessops ums_accessops = {
    125       1.3  augustss 	ums_enable,
    126       1.3  augustss 	ums_ioctl,
    127       1.3  augustss 	ums_disable,
    128       1.3  augustss };
    129       1.3  augustss 
    130      1.16  augustss USB_DECLARE_DRIVER(ums);
    131       1.1  augustss 
    132      1.16  augustss USB_MATCH(ums)
    133       1.1  augustss {
    134      1.16  augustss 	USB_MATCH_START(ums, uaa);
    135       1.1  augustss 	usb_interface_descriptor_t *id;
    136       1.1  augustss 	int size, ret;
    137       1.1  augustss 	void *desc;
    138  1.33.4.1      fvdl 	usbd_status err;
    139       1.1  augustss 
    140  1.33.4.1      fvdl 	if (uaa->iface == NULL)
    141       1.1  augustss 		return (UMATCH_NONE);
    142       1.1  augustss 	id = usbd_get_interface_descriptor(uaa->iface);
    143  1.33.4.1      fvdl 	if (id == NULL || id->bInterfaceClass != UCLASS_HID)
    144       1.1  augustss 		return (UMATCH_NONE);
    145       1.1  augustss 
    146  1.33.4.1      fvdl 	err = usbd_alloc_report_desc(uaa->iface, &desc, &size, M_TEMP);
    147  1.33.4.1      fvdl 	if (err)
    148       1.1  augustss 		return (UMATCH_NONE);
    149       1.1  augustss 
    150       1.1  augustss 	if (hid_is_collection(desc, size,
    151       1.1  augustss 			      HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE)))
    152       1.1  augustss 		ret = UMATCH_IFACECLASS;
    153       1.1  augustss 	else
    154       1.1  augustss 		ret = UMATCH_NONE;
    155       1.1  augustss 
    156       1.1  augustss 	free(desc, M_TEMP);
    157       1.1  augustss 	return (ret);
    158       1.1  augustss }
    159       1.1  augustss 
    160      1.16  augustss USB_ATTACH(ums)
    161       1.1  augustss {
    162      1.16  augustss 	USB_ATTACH_START(ums, sc, uaa);
    163       1.1  augustss 	usbd_interface_handle iface = uaa->iface;
    164       1.1  augustss 	usb_interface_descriptor_t *id;
    165       1.1  augustss 	usb_endpoint_descriptor_t *ed;
    166       1.3  augustss 	struct wsmousedev_attach_args a;
    167       1.1  augustss 	int size;
    168       1.1  augustss 	void *desc;
    169  1.33.4.1      fvdl 	usbd_status err;
    170       1.1  augustss 	char devinfo[1024];
    171       1.2  augustss 	u_int32_t flags;
    172      1.16  augustss 	int i;
    173      1.16  augustss 	struct hid_location loc_btn;
    174       1.1  augustss 
    175       1.1  augustss 	sc->sc_iface = iface;
    176       1.1  augustss 	id = usbd_get_interface_descriptor(iface);
    177       1.1  augustss 	usbd_devinfo(uaa->device, 0, devinfo);
    178      1.16  augustss 	USB_ATTACH_SETUP;
    179      1.16  augustss 	printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev),
    180      1.12  augustss 	       devinfo, id->bInterfaceClass, id->bInterfaceSubClass);
    181       1.1  augustss 	ed = usbd_interface2endpoint_descriptor(iface, 0);
    182  1.33.4.1      fvdl 	if (ed == NULL) {
    183       1.1  augustss 		printf("%s: could not read endpoint descriptor\n",
    184      1.16  augustss 		       USBDEVNAME(sc->sc_dev));
    185      1.16  augustss 		USB_ATTACH_ERROR_RETURN;
    186       1.1  augustss 	}
    187       1.1  augustss 
    188      1.15  augustss 	DPRINTFN(10,("ums_attach: bLength=%d bDescriptorType=%d "
    189      1.15  augustss 		     "bEndpointAddress=%d-%s bmAttributes=%d wMaxPacketSize=%d"
    190      1.15  augustss 		     " bInterval=%d\n",
    191      1.15  augustss 		     ed->bLength, ed->bDescriptorType,
    192      1.15  augustss 		     ed->bEndpointAddress & UE_ADDR,
    193      1.30  augustss 		     UE_GET_DIR(ed->bEndpointAddress)==UE_DIR_IN? "in" : "out",
    194      1.15  augustss 		     ed->bmAttributes & UE_XFERTYPE,
    195      1.15  augustss 		     UGETW(ed->wMaxPacketSize), ed->bInterval));
    196       1.1  augustss 
    197      1.30  augustss 	if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_IN ||
    198       1.1  augustss 	    (ed->bmAttributes & UE_XFERTYPE) != UE_INTERRUPT) {
    199       1.1  augustss 		printf("%s: unexpected endpoint\n",
    200      1.16  augustss 		       USBDEVNAME(sc->sc_dev));
    201      1.16  augustss 		USB_ATTACH_ERROR_RETURN;
    202       1.1  augustss 	}
    203       1.1  augustss 
    204      1.24  augustss 	sc->revz = (usbd_get_quirks(uaa->device)->uq_flags & UQ_MS_REVZ) != 0;
    205      1.24  augustss 
    206  1.33.4.1      fvdl 	err = usbd_alloc_report_desc(uaa->iface, &desc, &size, M_TEMP);
    207  1.33.4.1      fvdl 	if (err)
    208      1.16  augustss 		USB_ATTACH_ERROR_RETURN;
    209      1.16  augustss 
    210       1.2  augustss 	if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
    211       1.2  augustss 		       hid_input, &sc->sc_loc_x, &flags)) {
    212      1.16  augustss 		printf("%s: mouse has no X report\n", USBDEVNAME(sc->sc_dev));
    213      1.16  augustss 		USB_ATTACH_ERROR_RETURN;
    214      1.16  augustss 	}
    215      1.16  augustss 	if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
    216      1.16  augustss 		printf("%s: X report 0x%04x not supported\n",
    217      1.16  augustss 		       USBDEVNAME(sc->sc_dev), flags);
    218      1.16  augustss 		USB_ATTACH_ERROR_RETURN;
    219       1.1  augustss 	}
    220      1.10  augustss 
    221       1.2  augustss 	if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y),
    222       1.2  augustss 		       hid_input, &sc->sc_loc_y, &flags)) {
    223      1.16  augustss 		printf("%s: mouse has no Y report\n", USBDEVNAME(sc->sc_dev));
    224      1.16  augustss 		USB_ATTACH_ERROR_RETURN;
    225      1.16  augustss 	}
    226      1.16  augustss 	if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
    227      1.16  augustss 		printf("%s: Y report 0x%04x not supported\n",
    228      1.16  augustss 		       USBDEVNAME(sc->sc_dev), flags);
    229      1.16  augustss 		USB_ATTACH_ERROR_RETURN;
    230       1.1  augustss 	}
    231      1.10  augustss 
    232      1.22  augustss 	/* Try to guess the Z activator: first check Z, then WHEEL. */
    233       1.6  augustss 	if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Z),
    234       1.6  augustss 		       hid_input, &sc->sc_loc_z, &flags) ||
    235       1.6  augustss 	    hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL),
    236       1.6  augustss 		       hid_input, &sc->sc_loc_z, &flags)) {
    237      1.16  augustss 		if ((flags & MOUSE_FLAGS_MASK) != MOUSE_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.16  augustss 		}
    242       1.6  augustss 	}
    243       1.6  augustss 
    244      1.21  augustss 	/* figure out the number of buttons */
    245      1.21  augustss 	for (i = 1; i <= MAX_BUTTONS; i++)
    246      1.16  augustss 		if (!hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
    247      1.16  augustss 				hid_input, &loc_btn, 0))
    248      1.16  augustss 			break;
    249      1.16  augustss 	sc->nbuttons = i - 1;
    250      1.16  augustss 	sc->sc_loc_btn = malloc(sizeof(struct hid_location)*sc->nbuttons,
    251      1.16  augustss 				M_USBDEV, M_NOWAIT);
    252      1.22  augustss 	if (!sc->sc_loc_btn) {
    253      1.22  augustss 		printf("%s: no memory\n", USBDEVNAME(sc->sc_dev));
    254      1.16  augustss 		USB_ATTACH_ERROR_RETURN;
    255      1.22  augustss 	}
    256      1.16  augustss 
    257      1.16  augustss 	printf("%s: %d buttons%s\n", USBDEVNAME(sc->sc_dev),
    258      1.22  augustss 	       sc->nbuttons, sc->flags & UMS_Z ? " and Z dir." : "");
    259      1.16  augustss 
    260      1.16  augustss 	for (i = 1; i <= sc->nbuttons; i++)
    261      1.16  augustss 		hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
    262      1.16  augustss 				hid_input, &sc->sc_loc_btn[i-1], 0);
    263       1.1  augustss 
    264       1.1  augustss 	sc->sc_isize = hid_report_size(desc, size, hid_input, &sc->sc_iid);
    265      1.25  augustss 	sc->sc_ibuf = malloc(sc->sc_isize, M_USBDEV, M_NOWAIT);
    266  1.33.4.1      fvdl 	if (sc->sc_ibuf == NULL) {
    267      1.22  augustss 		printf("%s: no memory\n", USBDEVNAME(sc->sc_dev));
    268      1.25  augustss 		free(sc->sc_loc_btn, M_USBDEV);
    269      1.16  augustss 		USB_ATTACH_ERROR_RETURN;
    270      1.16  augustss 	}
    271       1.1  augustss 
    272       1.1  augustss 	sc->sc_ep_addr = ed->bEndpointAddress;
    273       1.1  augustss 	free(desc, M_TEMP);
    274       1.3  augustss 
    275      1.16  augustss #ifdef USB_DEBUG
    276      1.16  augustss 	DPRINTF(("ums_attach: sc=%p\n", sc));
    277      1.16  augustss 	DPRINTF(("ums_attach: X\t%d/%d\n",
    278      1.16  augustss 		 sc->sc_loc_x.pos, sc->sc_loc_x.size));
    279      1.16  augustss 	DPRINTF(("ums_attach: Y\t%d/%d\n",
    280      1.16  augustss 		 sc->sc_loc_x.pos, sc->sc_loc_x.size));
    281      1.16  augustss 	if (sc->flags & UMS_Z)
    282      1.16  augustss 		DPRINTF(("ums_attach: Z\t%d/%d\n",
    283      1.16  augustss 			 sc->sc_loc_z.pos, sc->sc_loc_z.size));
    284      1.16  augustss 	for (i = 1; i <= sc->nbuttons; i++) {
    285      1.16  augustss 		DPRINTF(("ums_attach: B%d\t%d/%d\n",
    286      1.16  augustss 			 i, sc->sc_loc_btn[i-1].pos,sc->sc_loc_btn[i-1].size));
    287      1.16  augustss 	}
    288      1.16  augustss 	DPRINTF(("ums_attach: size=%d, id=%d\n", sc->sc_isize, sc->sc_iid));
    289      1.16  augustss #endif
    290      1.16  augustss 
    291       1.3  augustss 	a.accessops = &ums_accessops;
    292       1.3  augustss 	a.accesscookie = sc;
    293       1.3  augustss 
    294       1.3  augustss 	sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
    295      1.16  augustss 
    296      1.16  augustss 	USB_ATTACH_SUCCESS_RETURN;
    297      1.16  augustss }
    298      1.16  augustss 
    299      1.25  augustss int
    300      1.25  augustss ums_activate(self, act)
    301      1.31  augustss 	device_ptr_t self;
    302      1.25  augustss 	enum devact act;
    303      1.16  augustss {
    304      1.28  augustss 	struct ums_softc *sc = (struct ums_softc *)self;
    305      1.32  augustss 	int rv = 0;
    306      1.28  augustss 
    307      1.28  augustss 	switch (act) {
    308      1.28  augustss 	case DVACT_ACTIVATE:
    309      1.28  augustss 		return (EOPNOTSUPP);
    310      1.28  augustss 		break;
    311      1.28  augustss 
    312      1.28  augustss 	case DVACT_DEACTIVATE:
    313  1.33.4.1      fvdl 		if (sc->sc_wsmousedev != NULL)
    314      1.32  augustss 			rv = config_deactivate(sc->sc_wsmousedev);
    315      1.28  augustss 		sc->sc_dying = 1;
    316      1.28  augustss 		break;
    317      1.28  augustss 	}
    318      1.32  augustss 	return (rv);
    319       1.1  augustss }
    320       1.1  augustss 
    321      1.33  augustss USB_DETACH(ums)
    322       1.1  augustss {
    323      1.33  augustss 	USB_DETACH_START(ums, sc);
    324      1.25  augustss 	int rv = 0;
    325       1.8  augustss 
    326      1.25  augustss 	DPRINTF(("ums_detach: sc=%p flags=%d\n", sc, flags));
    327      1.33  augustss 
    328      1.25  augustss 	/* No need to do reference counting of ums, wsmouse has all the goo. */
    329  1.33.4.1      fvdl 	if (sc->sc_wsmousedev != NULL)
    330      1.25  augustss 		rv = config_detach(sc->sc_wsmousedev, flags);
    331      1.25  augustss 	if (rv == 0) {
    332      1.25  augustss 		free(sc->sc_loc_btn, M_USBDEV);
    333      1.25  augustss 		free(sc->sc_ibuf, M_USBDEV);
    334      1.25  augustss 	}
    335      1.25  augustss 	return (rv);
    336       1.1  augustss }
    337       1.1  augustss 
    338       1.1  augustss void
    339  1.33.4.1      fvdl ums_intr(xfer, addr, status)
    340  1.33.4.1      fvdl 	usbd_xfer_handle xfer;
    341       1.1  augustss 	usbd_private_handle addr;
    342       1.1  augustss 	usbd_status status;
    343       1.1  augustss {
    344       1.1  augustss 	struct ums_softc *sc = addr;
    345       1.1  augustss 	u_char *ibuf;
    346       1.6  augustss 	int dx, dy, dz;
    347      1.27  augustss 	u_int32_t buttons = 0;
    348      1.16  augustss 	int i;
    349      1.23  augustss 	int s;
    350      1.21  augustss 
    351       1.1  augustss 	DPRINTFN(5, ("ums_intr: sc=%p status=%d\n", sc, status));
    352       1.1  augustss 	DPRINTFN(5, ("ums_intr: data = %02x %02x %02x\n",
    353       1.1  augustss 		     sc->sc_ibuf[0], sc->sc_ibuf[1], sc->sc_ibuf[2]));
    354       1.1  augustss 
    355       1.1  augustss 	if (status == USBD_CANCELLED)
    356       1.1  augustss 		return;
    357       1.1  augustss 
    358       1.1  augustss 	if (status != USBD_NORMAL_COMPLETION) {
    359       1.1  augustss 		DPRINTF(("ums_intr: status=%d\n", status));
    360       1.7  augustss 		usbd_clear_endpoint_stall_async(sc->sc_intrpipe);
    361       1.1  augustss 		return;
    362       1.1  augustss 	}
    363       1.1  augustss 
    364       1.1  augustss 	ibuf = sc->sc_ibuf;
    365  1.33.4.1      fvdl 	if (sc->sc_iid != 0) {
    366       1.1  augustss 		if (*ibuf++ != sc->sc_iid)
    367       1.1  augustss 			return;
    368       1.1  augustss 	}
    369       1.1  augustss 	dx =  hid_get_data(ibuf, &sc->sc_loc_x);
    370       1.1  augustss 	dy = -hid_get_data(ibuf, &sc->sc_loc_y);
    371       1.6  augustss 	dz =  hid_get_data(ibuf, &sc->sc_loc_z);
    372      1.24  augustss 	if (sc->revz)
    373      1.24  augustss 		dz = -dz;
    374      1.16  augustss 	for (i = 0; i < sc->nbuttons; i++)
    375      1.16  augustss 		if (hid_get_data(ibuf, &sc->sc_loc_btn[i]))
    376      1.16  augustss 			buttons |= (1 << UMS_BUT(i));
    377       1.4  augustss 
    378      1.22  augustss 	if (dx || dy || dz || buttons != sc->sc_buttons) {
    379      1.16  augustss 		DPRINTFN(10, ("ums_intr: x:%d y:%d z:%d buttons:0x%x\n",
    380      1.16  augustss 			dx, dy, dz, buttons));
    381       1.4  augustss 		sc->sc_buttons = buttons;
    382      1.23  augustss 		if (sc->sc_wsmousedev) {
    383      1.23  augustss 			s = spltty();
    384       1.6  augustss 			wsmouse_input(sc->sc_wsmousedev, buttons, dx, dy, dz);
    385      1.23  augustss 			splx(s);
    386      1.23  augustss 		}
    387       1.1  augustss 	}
    388       1.1  augustss }
    389       1.3  augustss 
    390      1.16  augustss static int
    391       1.3  augustss ums_enable(v)
    392       1.3  augustss 	void *v;
    393       1.3  augustss {
    394       1.3  augustss 	struct ums_softc *sc = v;
    395      1.16  augustss 
    396  1.33.4.1      fvdl 	usbd_status err;
    397       1.3  augustss 
    398      1.25  augustss 	DPRINTFN(1,("ums_enable: sc=%p\n", sc));
    399      1.28  augustss 
    400      1.28  augustss 	if (sc->sc_dying)
    401      1.28  augustss 		return (EIO);
    402      1.28  augustss 
    403       1.3  augustss 	if (sc->sc_enabled)
    404      1.28  augustss 		return (EBUSY);
    405       1.3  augustss 
    406       1.3  augustss 	sc->sc_enabled = 1;
    407       1.4  augustss 	sc->sc_buttons = 0;
    408       1.3  augustss 
    409       1.3  augustss 	/* Set up interrupt pipe. */
    410  1.33.4.1      fvdl 	err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ep_addr,
    411  1.33.4.1      fvdl 		  USBD_SHORT_XFER_OK, &sc->sc_intrpipe, sc,
    412  1.33.4.1      fvdl 		  sc->sc_ibuf, sc->sc_isize, ums_intr);
    413  1.33.4.1      fvdl 	if (err) {
    414       1.3  augustss 		DPRINTF(("ums_enable: usbd_open_pipe_intr failed, error=%d\n",
    415  1.33.4.1      fvdl 			 err));
    416       1.3  augustss 		sc->sc_enabled = 0;
    417       1.3  augustss 		return (EIO);
    418       1.3  augustss 	}
    419       1.3  augustss 	return (0);
    420       1.3  augustss }
    421       1.3  augustss 
    422      1.16  augustss static void
    423       1.3  augustss ums_disable(v)
    424       1.3  augustss 	void *v;
    425       1.3  augustss {
    426       1.3  augustss 	struct ums_softc *sc = v;
    427      1.25  augustss 
    428      1.25  augustss 	DPRINTFN(1,("ums_disable: sc=%p\n", sc));
    429      1.25  augustss #ifdef DIAGNOSTIC
    430      1.25  augustss 	if (!sc->sc_enabled) {
    431      1.25  augustss 		printf("ums_disable: not enabled\n");
    432      1.25  augustss 		return;
    433      1.25  augustss 	}
    434      1.25  augustss #endif
    435       1.3  augustss 
    436       1.3  augustss 	/* Disable interrupts. */
    437       1.3  augustss 	usbd_abort_pipe(sc->sc_intrpipe);
    438       1.3  augustss 	usbd_close_pipe(sc->sc_intrpipe);
    439       1.3  augustss 
    440       1.3  augustss 	sc->sc_enabled = 0;
    441       1.3  augustss }
    442       1.3  augustss 
    443      1.16  augustss static int
    444       1.3  augustss ums_ioctl(v, cmd, data, flag, p)
    445       1.3  augustss 	void *v;
    446       1.3  augustss 	u_long cmd;
    447       1.3  augustss 	caddr_t data;
    448       1.3  augustss 	int flag;
    449       1.3  augustss 	struct proc *p;
    450      1.16  augustss 
    451       1.3  augustss {
    452       1.3  augustss 	switch (cmd) {
    453       1.3  augustss 	case WSMOUSEIO_GTYPE:
    454      1.17  augustss 		*(u_int *)data = WSMOUSE_TYPE_USB;
    455       1.3  augustss 		return (0);
    456       1.3  augustss 	}
    457      1.16  augustss 
    458       1.3  augustss 	return (-1);
    459       1.3  augustss }
    460