Home | History | Annotate | Line # | Download | only in usb
uep.c revision 1.4.2.4
      1  1.4.2.4      yamt /*	$NetBSD: uep.c,v 1.4.2.4 2008/02/27 08:36:47 yamt Exp $	*/
      2      1.1    tsarna 
      3      1.1    tsarna /*
      4      1.1    tsarna  * Copyright (c) 2004 The NetBSD Foundation, Inc.
      5      1.1    tsarna  * All rights reserved.
      6      1.1    tsarna  *
      7      1.1    tsarna  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1    tsarna  * by Tyler C. Sarna (tsarna (at) netbsd.org).
      9      1.1    tsarna  *
     10      1.1    tsarna  * Redistribution and use in source and binary forms, with or without
     11      1.1    tsarna  * modification, are permitted provided that the following conditions
     12      1.1    tsarna  * are met:
     13      1.1    tsarna  * 1. Redistributions of source code must retain the above copyright
     14      1.1    tsarna  *    notice, this list of conditions and the following disclaimer.
     15      1.1    tsarna  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1    tsarna  *    notice, this list of conditions and the following disclaimer in the
     17      1.1    tsarna  *    documentation and/or other materials provided with the distribution.
     18      1.1    tsarna  * 3. All advertising materials mentioning features or use of this software
     19      1.1    tsarna  *    must display the following acknowledgement:
     20      1.1    tsarna  *	  This product includes software developed by the NetBSD
     21      1.1    tsarna  *	  Foundation, Inc. and its contributors.
     22      1.1    tsarna  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1    tsarna  *    contributors may be used to endorse or promote products derived
     24      1.1    tsarna  *    from this software without specific prior written permission.
     25      1.1    tsarna  *
     26      1.1    tsarna  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1    tsarna  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1    tsarna  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1    tsarna  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1    tsarna  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1    tsarna  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1    tsarna  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1    tsarna  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1    tsarna  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1    tsarna  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1    tsarna  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1    tsarna  */
     38      1.1    tsarna 
     39      1.2    tsarna /*
     40      1.2    tsarna  *  eGalax USB touchpanel controller driver.
     41      1.2    tsarna  *
     42      1.2    tsarna  *  For Programming Documentation, see:
     43      1.2    tsarna  *
     44      1.2    tsarna  *  http://www.egalax.com/SoftwareProgrammingGuide_1.1.pdf
     45      1.2    tsarna  */
     46      1.3     perry 
     47      1.1    tsarna #include <sys/cdefs.h>
     48  1.4.2.4      yamt __KERNEL_RCSID(0, "$NetBSD: uep.c,v 1.4.2.4 2008/02/27 08:36:47 yamt Exp $");
     49      1.1    tsarna 
     50      1.1    tsarna #include <sys/param.h>
     51      1.1    tsarna #include <sys/systm.h>
     52      1.1    tsarna #include <sys/kernel.h>
     53      1.1    tsarna #include <sys/malloc.h>
     54      1.1    tsarna #include <sys/device.h>
     55      1.1    tsarna #include <sys/ioctl.h>
     56      1.1    tsarna #include <sys/vnode.h>
     57      1.1    tsarna 
     58      1.1    tsarna #include <dev/usb/usb.h>
     59      1.1    tsarna #include <dev/usb/usbdi.h>
     60      1.1    tsarna #include <dev/usb/usbdi_util.h>
     61      1.1    tsarna #include <dev/usb/usbdevs.h>
     62      1.1    tsarna #include <dev/usb/usb_quirks.h>
     63      1.1    tsarna 
     64      1.1    tsarna #include <dev/wscons/wsconsio.h>
     65      1.1    tsarna #include <dev/wscons/wsmousevar.h>
     66      1.2    tsarna #include <dev/wscons/tpcalibvar.h>
     67      1.2    tsarna 
     68      1.2    tsarna #define UIDSTR	"eGalax USB SN000000"
     69      1.1    tsarna 
     70      1.1    tsarna struct uep_softc {
     71      1.1    tsarna 	USBBASEDEVICE sc_dev;
     72      1.1    tsarna 	usbd_device_handle sc_udev;	/* device */
     73      1.1    tsarna 	usbd_interface_handle sc_iface;	/* interface */
     74      1.1    tsarna 	int sc_iface_number;
     75      1.1    tsarna 
     76      1.1    tsarna 	int			sc_intr_number; /* interrupt number */
     77      1.1    tsarna 	usbd_pipe_handle	sc_intr_pipe;	/* interrupt pipe */
     78      1.1    tsarna 	u_char			*sc_ibuf;
     79      1.1    tsarna 	int			sc_isize;
     80      1.1    tsarna 
     81      1.1    tsarna 	device_ptr_t		sc_wsmousedev;	/* wsmouse device */
     82      1.2    tsarna 	struct tpcalib_softc	sc_tpcalib;	/* calibration */
     83      1.1    tsarna 
     84      1.1    tsarna 	u_char sc_enabled;
     85      1.1    tsarna 	u_char sc_dying;
     86      1.1    tsarna };
     87      1.1    tsarna 
     88      1.2    tsarna static struct wsmouse_calibcoords default_calib = {
     89  1.4.2.2      yamt 	.minx = 0,
     90  1.4.2.2      yamt 	.miny = 0,
     91  1.4.2.2      yamt 	.maxx = 2047,
     92  1.4.2.2      yamt 	.maxy = 2047,
     93  1.4.2.2      yamt 	.samplelen = WSMOUSE_CALIBCOORDS_RESET,
     94      1.2    tsarna };
     95      1.2    tsarna 
     96      1.1    tsarna Static void uep_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
     97      1.1    tsarna 
     98      1.1    tsarna Static int	uep_enable(void *);
     99      1.1    tsarna Static void	uep_disable(void *);
    100  1.4.2.3      yamt Static int	uep_ioctl(void *, u_long, void *, int, struct lwp *);
    101      1.1    tsarna 
    102      1.1    tsarna const struct wsmouse_accessops uep_accessops = {
    103      1.1    tsarna 	uep_enable,
    104      1.1    tsarna 	uep_ioctl,
    105      1.1    tsarna 	uep_disable,
    106      1.1    tsarna };
    107      1.1    tsarna 
    108  1.4.2.4      yamt int uep_match(device_t, struct cfdata *, void *);
    109  1.4.2.4      yamt void uep_attach(device_t, device_t, void *);
    110  1.4.2.4      yamt void uep_childdet(device_t, device_t);
    111  1.4.2.4      yamt int uep_detach(device_t, int);
    112  1.4.2.4      yamt int uep_activate(device_t, enum devact);
    113  1.4.2.4      yamt extern struct cfdriver uep_cd;
    114  1.4.2.4      yamt CFATTACH_DECL2(uep, sizeof(struct uep_softc), uep_match, uep_attach,
    115  1.4.2.4      yamt     uep_detach, uep_activate, NULL, uep_childdet);
    116      1.1    tsarna 
    117      1.1    tsarna USB_MATCH(uep)
    118      1.1    tsarna {
    119      1.1    tsarna 	USB_MATCH_START(uep, uaa);
    120      1.1    tsarna 
    121      1.1    tsarna 	if ((uaa->vendor == USB_VENDOR_EGALAX) && (
    122      1.1    tsarna 		(uaa->product == USB_PRODUCT_EGALAX_TPANEL)
    123      1.1    tsarna 		|| (uaa->product == USB_PRODUCT_EGALAX_TPANEL2)
    124      1.1    tsarna 	))
    125      1.1    tsarna 		return UMATCH_VENDOR_PRODUCT;
    126      1.1    tsarna 
    127      1.1    tsarna 	if ((uaa->vendor == USB_VENDOR_EGALAX2)
    128      1.1    tsarna 	&&  (uaa->product == USB_PRODUCT_EGALAX2_TPANEL))
    129      1.1    tsarna 		return UMATCH_VENDOR_PRODUCT;
    130      1.1    tsarna 
    131      1.1    tsarna 
    132      1.1    tsarna 	return UMATCH_NONE;
    133      1.1    tsarna }
    134      1.1    tsarna 
    135      1.1    tsarna USB_ATTACH(uep)
    136      1.1    tsarna {
    137      1.1    tsarna 	USB_ATTACH_START(uep, sc, uaa);
    138      1.1    tsarna 	usbd_device_handle dev = uaa->device;
    139      1.1    tsarna 	usb_config_descriptor_t *cdesc;
    140      1.1    tsarna 	usb_interface_descriptor_t *id;
    141      1.1    tsarna 	usb_endpoint_descriptor_t *ed;
    142      1.1    tsarna 	struct wsmousedev_attach_args a;
    143      1.4  augustss 	char *devinfop;
    144      1.1    tsarna 	usbd_status err;
    145      1.1    tsarna 	int i, found;
    146      1.1    tsarna 
    147      1.4  augustss 	devinfop = usbd_devinfo_alloc(dev, 0);
    148      1.1    tsarna 	USB_ATTACH_SETUP;
    149      1.4  augustss 	printf("%s: %s\n", USBDEVNAME(sc->sc_dev), devinfop);
    150      1.4  augustss 	usbd_devinfo_free(devinfop);
    151      1.1    tsarna 
    152      1.1    tsarna 	sc->sc_udev = dev;
    153      1.1    tsarna 	sc->sc_intr_number = -1;
    154      1.1    tsarna 	sc->sc_intr_pipe = NULL;
    155      1.1    tsarna 	sc->sc_enabled = sc->sc_isize = 0;
    156      1.1    tsarna 
    157      1.1    tsarna 	/* Move the device into the configured state. */
    158      1.1    tsarna 	err = usbd_set_config_index(dev, 0, 1);
    159      1.1    tsarna 	if (err) {
    160      1.1    tsarna 		printf("\n%s: failed to set configuration, err=%s\n",
    161      1.1    tsarna 			USBDEVNAME(sc->sc_dev),  usbd_errstr(err));
    162      1.1    tsarna 		sc->sc_dying = 1;
    163      1.1    tsarna 		USB_ATTACH_ERROR_RETURN;
    164      1.1    tsarna 	}
    165      1.1    tsarna 
    166      1.1    tsarna 	/* get the config descriptor */
    167      1.1    tsarna 	cdesc = usbd_get_config_descriptor(sc->sc_udev);
    168      1.1    tsarna 	if (cdesc == NULL) {
    169      1.1    tsarna 		printf("%s: failed to get configuration descriptor\n",
    170      1.1    tsarna 			USBDEVNAME(sc->sc_dev));
    171      1.1    tsarna 		sc->sc_dying = 1;
    172      1.1    tsarna 		USB_ATTACH_ERROR_RETURN;
    173      1.1    tsarna 	}
    174      1.1    tsarna 
    175      1.1    tsarna 	/* get the interface */
    176      1.1    tsarna 	err = usbd_device2interface_handle(dev, 0, &sc->sc_iface);
    177      1.1    tsarna 	if (err) {
    178      1.1    tsarna 		printf("\n%s: failed to get interface, err=%s\n",
    179      1.1    tsarna 			USBDEVNAME(sc->sc_dev), usbd_errstr(err));
    180      1.1    tsarna 		sc->sc_dying = 1;
    181      1.1    tsarna 		USB_ATTACH_ERROR_RETURN;
    182      1.1    tsarna 	}
    183      1.1    tsarna 
    184      1.1    tsarna 	/* Find the interrupt endpoint */
    185      1.1    tsarna 	id = usbd_get_interface_descriptor(sc->sc_iface);
    186      1.1    tsarna 	sc->sc_iface_number = id->bInterfaceNumber;
    187      1.1    tsarna 	found = 0;
    188      1.1    tsarna 
    189      1.1    tsarna 	for (i = 0; i < id->bNumEndpoints; i++) {
    190      1.1    tsarna 		ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
    191      1.1    tsarna 		if (ed == NULL) {
    192      1.1    tsarna 			printf("%s: no endpoint descriptor for %d\n",
    193      1.1    tsarna 				USBDEVNAME(sc->sc_dev), i);
    194      1.1    tsarna 			sc->sc_dying = 1;
    195      1.1    tsarna 			USB_ATTACH_ERROR_RETURN;
    196      1.1    tsarna 		}
    197      1.1    tsarna 
    198      1.1    tsarna 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    199      1.1    tsarna 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
    200      1.1    tsarna 			sc->sc_intr_number = ed->bEndpointAddress;
    201      1.1    tsarna 			sc->sc_isize = UGETW(ed->wMaxPacketSize);
    202      1.1    tsarna 		}
    203      1.1    tsarna 	}
    204      1.1    tsarna 
    205      1.1    tsarna 	if (sc->sc_intr_number== -1) {
    206      1.1    tsarna 		printf("%s: Could not find interrupt in\n",
    207      1.1    tsarna 			USBDEVNAME(sc->sc_dev));
    208      1.1    tsarna 		sc->sc_dying = 1;
    209      1.1    tsarna 		USB_ATTACH_ERROR_RETURN;
    210      1.1    tsarna 	}
    211      1.1    tsarna 
    212      1.1    tsarna 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
    213      1.1    tsarna 			   USBDEV(sc->sc_dev));
    214      1.1    tsarna 
    215      1.1    tsarna 	a.accessops = &uep_accessops;
    216      1.1    tsarna 	a.accesscookie = sc;
    217      1.1    tsarna 
    218      1.1    tsarna 	sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
    219      1.3     perry 
    220      1.2    tsarna 	tpcalib_init(&sc->sc_tpcalib);
    221      1.2    tsarna 	tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
    222  1.4.2.3      yamt 		(void *)&default_calib, 0, 0);
    223      1.1    tsarna 
    224      1.1    tsarna 	USB_ATTACH_SUCCESS_RETURN;
    225      1.1    tsarna }
    226      1.1    tsarna 
    227      1.1    tsarna USB_DETACH(uep)
    228      1.1    tsarna {
    229      1.1    tsarna 	USB_DETACH_START(uep, sc);
    230      1.1    tsarna 	int rv = 0;
    231      1.1    tsarna 
    232      1.1    tsarna 	if (sc->sc_intr_pipe != NULL) {
    233      1.1    tsarna 		usbd_abort_pipe(sc->sc_intr_pipe);
    234      1.1    tsarna 		usbd_close_pipe(sc->sc_intr_pipe);
    235      1.1    tsarna 		sc->sc_intr_pipe = NULL;
    236      1.1    tsarna 	}
    237      1.1    tsarna 
    238      1.1    tsarna 	sc->sc_dying = 1;
    239      1.1    tsarna 
    240      1.2    tsarna 	/* save current calib as defaults */
    241      1.2    tsarna 	default_calib = sc->sc_tpcalib.sc_saved;
    242      1.3     perry 
    243  1.4.2.4      yamt 	if (sc->sc_wsmousedev != NULL)
    244      1.1    tsarna 		rv = config_detach(sc->sc_wsmousedev, flags);
    245      1.1    tsarna 
    246      1.1    tsarna 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
    247      1.1    tsarna 			   USBDEV(sc->sc_dev));
    248      1.1    tsarna 
    249      1.1    tsarna 	return rv;
    250      1.1    tsarna }
    251      1.1    tsarna 
    252  1.4.2.4      yamt void
    253  1.4.2.4      yamt uep_childdet(device_t self, device_t child)
    254  1.4.2.4      yamt {
    255  1.4.2.4      yamt 	struct uep_softc *sc = device_private(self);
    256  1.4.2.4      yamt 
    257  1.4.2.4      yamt 	KASSERT(sc->sc_wsmousedev == child);
    258  1.4.2.4      yamt 	sc->sc_wsmousedev = NULL;
    259  1.4.2.4      yamt }
    260  1.4.2.4      yamt 
    261      1.1    tsarna int
    262  1.4.2.4      yamt uep_activate(device_t self, enum devact act)
    263      1.1    tsarna {
    264  1.4.2.4      yamt 	struct uep_softc *sc = device_private(self);
    265      1.1    tsarna 	int rv = 0;
    266      1.1    tsarna 
    267      1.1    tsarna 	switch (act) {
    268      1.1    tsarna 	case DVACT_ACTIVATE:
    269      1.1    tsarna 		return EOPNOTSUPP;
    270      1.1    tsarna 
    271      1.1    tsarna 	case DVACT_DEACTIVATE:
    272      1.1    tsarna 		if (sc->sc_wsmousedev != NULL)
    273      1.1    tsarna 			rv = config_deactivate(sc->sc_wsmousedev);
    274      1.1    tsarna 		sc->sc_dying = 1;
    275      1.1    tsarna 		break;
    276      1.1    tsarna 	}
    277      1.1    tsarna 
    278      1.1    tsarna 	return rv;
    279      1.1    tsarna }
    280      1.1    tsarna 
    281      1.1    tsarna Static int
    282      1.1    tsarna uep_enable(void *v)
    283      1.1    tsarna {
    284      1.1    tsarna 	struct uep_softc *sc = v;
    285      1.1    tsarna 	int err;
    286      1.1    tsarna 
    287      1.1    tsarna 	if (sc->sc_dying)
    288      1.1    tsarna 		return EIO;
    289      1.1    tsarna 
    290      1.1    tsarna 	if (sc->sc_enabled)
    291      1.1    tsarna 		return EBUSY;
    292      1.1    tsarna 
    293      1.1    tsarna 	if (sc->sc_isize == 0)
    294      1.1    tsarna 		return 0;
    295      1.1    tsarna 	sc->sc_ibuf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK);
    296      1.1    tsarna 	err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_intr_number,
    297      1.1    tsarna 		USBD_SHORT_XFER_OK, &sc->sc_intr_pipe, sc, sc->sc_ibuf,
    298      1.1    tsarna 		sc->sc_isize, uep_intr, USBD_DEFAULT_INTERVAL);
    299      1.1    tsarna 	if (err) {
    300      1.1    tsarna 		free(sc->sc_ibuf, M_USBDEV);
    301      1.1    tsarna 		sc->sc_intr_pipe = NULL;
    302      1.1    tsarna 		return EIO;
    303      1.1    tsarna 	}
    304      1.1    tsarna 
    305      1.1    tsarna 	sc->sc_enabled = 1;
    306      1.1    tsarna 
    307      1.1    tsarna 	return 0;
    308      1.1    tsarna }
    309      1.1    tsarna 
    310      1.1    tsarna Static void
    311      1.1    tsarna uep_disable(void *v)
    312      1.1    tsarna {
    313      1.1    tsarna 	struct uep_softc *sc = v;
    314      1.1    tsarna 
    315      1.1    tsarna 	if (!sc->sc_enabled) {
    316      1.1    tsarna 		printf("uep_disable: already disabled!\n");
    317      1.1    tsarna 		return;
    318      1.1    tsarna 	}
    319      1.1    tsarna 
    320      1.1    tsarna 	/* Disable interrupts. */
    321      1.1    tsarna 	if (sc->sc_intr_pipe != NULL) {
    322      1.1    tsarna 		usbd_abort_pipe(sc->sc_intr_pipe);
    323      1.1    tsarna 		usbd_close_pipe(sc->sc_intr_pipe);
    324      1.1    tsarna 		sc->sc_intr_pipe = NULL;
    325      1.1    tsarna 	}
    326      1.1    tsarna 
    327      1.1    tsarna 	if (sc->sc_ibuf != NULL) {
    328      1.1    tsarna 		free(sc->sc_ibuf, M_USBDEV);
    329      1.1    tsarna 		sc->sc_ibuf = NULL;
    330      1.1    tsarna 	}
    331      1.1    tsarna 
    332      1.1    tsarna 	sc->sc_enabled = 0;
    333      1.1    tsarna }
    334      1.1    tsarna 
    335      1.1    tsarna Static int
    336  1.4.2.3      yamt uep_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
    337      1.1    tsarna {
    338      1.2    tsarna 	struct uep_softc *sc = v;
    339      1.2    tsarna 	struct wsmouse_id *id;
    340      1.2    tsarna 
    341      1.1    tsarna 	switch (cmd) {
    342      1.1    tsarna 	case WSMOUSEIO_GTYPE:
    343      1.1    tsarna 		*(u_int *)data = WSMOUSE_TYPE_TPANEL;
    344      1.2    tsarna 		return 0;
    345      1.2    tsarna 
    346      1.2    tsarna 	case WSMOUSEIO_GETID:
    347      1.2    tsarna 		/*
    348      1.2    tsarna 		 * return unique ID string
    349      1.2    tsarna 		 * "<vendor> <model> <serial number>"
    350      1.2    tsarna 		 * unfortunately we have no serial number...
    351      1.2    tsarna 		 */
    352      1.2    tsarna 		 id = (struct wsmouse_id *)data;
    353      1.2    tsarna 		 if (id->type != WSMOUSE_ID_TYPE_UIDSTR)
    354      1.2    tsarna 		 	return EINVAL;
    355      1.3     perry 
    356      1.2    tsarna 		strcpy(id->data, UIDSTR);
    357      1.2    tsarna 		id->length = strlen(UIDSTR);
    358      1.2    tsarna 		return 0;
    359      1.2    tsarna 
    360      1.2    tsarna 	case WSMOUSEIO_SCALIBCOORDS:
    361      1.2    tsarna 	case WSMOUSEIO_GCALIBCOORDS:
    362  1.4.2.1      yamt 		return tpcalib_ioctl(&sc->sc_tpcalib, cmd, data, flag, l);
    363      1.1    tsarna 	}
    364      1.1    tsarna 
    365      1.1    tsarna 	return EPASSTHROUGH;
    366      1.1    tsarna }
    367      1.1    tsarna 
    368      1.1    tsarna void
    369      1.1    tsarna uep_intr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status)
    370      1.1    tsarna {
    371      1.1    tsarna 	struct uep_softc *sc = addr;
    372      1.1    tsarna 	u_char *p = sc->sc_ibuf;
    373      1.1    tsarna 	u_int32_t len;
    374      1.1    tsarna 	int x = 0, y = 0, s;
    375      1.1    tsarna 
    376      1.1    tsarna 	usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL);
    377      1.1    tsarna 
    378      1.1    tsarna 	if (status == USBD_CANCELLED)
    379      1.1    tsarna 		return;
    380      1.1    tsarna 
    381      1.1    tsarna 	if (status != USBD_NORMAL_COMPLETION) {
    382      1.1    tsarna 		printf("%s: status %d\n", USBDEVNAME(sc->sc_dev), status);
    383      1.1    tsarna 		usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
    384      1.1    tsarna 		return;
    385      1.1    tsarna 	}
    386      1.1    tsarna 
    387      1.1    tsarna 	if (len != 5) {
    388      1.1    tsarna #if 0
    389      1.1    tsarna 		printf("%s: bad input length %d != %d\n",
    390      1.1    tsarna 			USBDEVNAME(sc->sc_dev), len, sc->sc_isize);
    391      1.1    tsarna #endif
    392      1.1    tsarna 		return;
    393      1.1    tsarna 	}
    394      1.1    tsarna 
    395      1.1    tsarna 	if ((p[0] & 0xFE) != 0x80) {
    396      1.1    tsarna 		printf("%s: bad input packet format\n", USBDEVNAME(sc->sc_dev));
    397      1.1    tsarna 		return;
    398      1.1    tsarna 	}
    399      1.1    tsarna 
    400      1.1    tsarna 	if (sc->sc_wsmousedev != NULL) {
    401      1.2    tsarna                 /*
    402      1.2    tsarna                  * Packet format is 5 bytes:
    403      1.2    tsarna                  *
    404      1.2    tsarna                  * 1000000T
    405      1.2    tsarna                  * 0000AAAA
    406      1.2    tsarna                  * 0AAAAAAA
    407      1.2    tsarna                  * 0000BBBB
    408      1.2    tsarna                  * 0BBBBBBB
    409      1.2    tsarna                  *
    410      1.3     perry                  * T: 1=touched 0=not touched
    411      1.2    tsarna                  * A: bits of axis A position, MSB to LSB
    412      1.2    tsarna                  * B: bits of axis B position, MSB to LSB
    413      1.2    tsarna                  *
    414      1.2    tsarna                  * For the unit I have, A = Y and B = X.
    415      1.2    tsarna                  * I don't know if units exist with A=X and B=Y,
    416      1.2    tsarna                  * if so we'll cross that bridge when we come to it.
    417      1.2    tsarna                  *
    418      1.2    tsarna                  * The controller sends a stream of T=1 events while the
    419      1.2    tsarna                  * panel is touched, followed by a single T=0 event.
    420      1.3     perry                  *
    421      1.2    tsarna                  */
    422      1.2    tsarna 
    423      1.1    tsarna 		x = (p[3] << 7) | p[4];
    424      1.1    tsarna 		y = (p[1] << 7) | p[2];
    425      1.3     perry 
    426      1.2    tsarna 		tpcalib_trans(&sc->sc_tpcalib, x, y, &x, &y);
    427      1.1    tsarna 
    428      1.1    tsarna 		s = spltty();
    429  1.4.2.2      yamt 		wsmouse_input(sc->sc_wsmousedev, p[0] & 0x01, x, y, 0, 0,
    430      1.1    tsarna 			WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
    431      1.1    tsarna 		splx(s);
    432      1.1    tsarna 	}
    433      1.1    tsarna }
    434