Home | History | Annotate | Line # | Download | only in usb
uep.c revision 1.21.16.2
      1  1.21.16.2    martin /*	$NetBSD: uep.c,v 1.21.16.2 2020/04/08 14:08:13 martin 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  *
     19        1.1    tsarna  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1    tsarna  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1    tsarna  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1    tsarna  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1    tsarna  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1    tsarna  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1    tsarna  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1    tsarna  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1    tsarna  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1    tsarna  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1    tsarna  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1    tsarna  */
     31        1.1    tsarna 
     32        1.2    tsarna /*
     33        1.2    tsarna  *  eGalax USB touchpanel controller driver.
     34        1.2    tsarna  */
     35        1.1    tsarna #include <sys/cdefs.h>
     36  1.21.16.2    martin __KERNEL_RCSID(0, "$NetBSD: uep.c,v 1.21.16.2 2020/04/08 14:08:13 martin Exp $");
     37        1.1    tsarna 
     38        1.1    tsarna #include <sys/param.h>
     39        1.1    tsarna #include <sys/systm.h>
     40        1.1    tsarna #include <sys/kernel.h>
     41       1.20     skrll #include <sys/kmem.h>
     42        1.1    tsarna #include <sys/device.h>
     43        1.1    tsarna #include <sys/ioctl.h>
     44        1.1    tsarna #include <sys/vnode.h>
     45        1.1    tsarna 
     46        1.1    tsarna #include <dev/usb/usb.h>
     47        1.1    tsarna #include <dev/usb/usbdi.h>
     48        1.1    tsarna #include <dev/usb/usbdi_util.h>
     49        1.1    tsarna #include <dev/usb/usbdevs.h>
     50        1.1    tsarna #include <dev/usb/usb_quirks.h>
     51        1.1    tsarna 
     52        1.1    tsarna #include <dev/wscons/wsconsio.h>
     53        1.1    tsarna #include <dev/wscons/wsmousevar.h>
     54        1.2    tsarna #include <dev/wscons/tpcalibvar.h>
     55        1.2    tsarna 
     56        1.2    tsarna #define UIDSTR	"eGalax USB SN000000"
     57       1.21      maya /* calibration - integer values, perhaps sysctls?  */
     58       1.21      maya #define X_RATIO   293
     59       1.21      maya #define X_OFFSET  -28
     60       1.21      maya #define Y_RATIO   -348
     61       1.21      maya #define Y_OFFSET  537
     62       1.21      maya /* an X_RATIO of ``312''  means : reduce by a factor 3.12 x axis amplitude */
     63       1.21      maya /* an Y_RATIO of ``-157'' means : reduce by a factor 1.57 y axis amplitude,
     64       1.21      maya  * and reverse y motion */
     65        1.1    tsarna 
     66        1.1    tsarna struct uep_softc {
     67       1.15    dyoung 	device_t sc_dev;
     68       1.20     skrll 	struct usbd_device *sc_udev;	/* device */
     69       1.20     skrll 	struct usbd_interface *sc_iface;	/* interface */
     70        1.1    tsarna 	int sc_iface_number;
     71        1.1    tsarna 
     72        1.1    tsarna 	int			sc_intr_number; /* interrupt number */
     73       1.20     skrll 	struct usbd_pipe *	sc_intr_pipe;	/* interrupt pipe */
     74        1.1    tsarna 	u_char			*sc_ibuf;
     75        1.1    tsarna 	int			sc_isize;
     76        1.1    tsarna 
     77       1.15    dyoung 	device_t		sc_wsmousedev;	/* wsmouse device */
     78        1.2    tsarna 	struct tpcalib_softc	sc_tpcalib;	/* calibration */
     79        1.1    tsarna 
     80        1.1    tsarna 	u_char sc_enabled;
     81        1.1    tsarna 	u_char sc_dying;
     82        1.1    tsarna };
     83        1.1    tsarna 
     84        1.2    tsarna static struct wsmouse_calibcoords default_calib = {
     85        1.6  christos 	.minx = 0,
     86        1.6  christos 	.miny = 0,
     87        1.6  christos 	.maxx = 2047,
     88        1.6  christos 	.maxy = 2047,
     89        1.6  christos 	.samplelen = WSMOUSE_CALIBCOORDS_RESET,
     90        1.2    tsarna };
     91        1.2    tsarna 
     92       1.20     skrll Static void uep_intr(struct usbd_xfer *, void *, usbd_status);
     93        1.1    tsarna 
     94        1.1    tsarna Static int	uep_enable(void *);
     95        1.1    tsarna Static void	uep_disable(void *);
     96        1.8  christos Static int	uep_ioctl(void *, u_long, void *, int, struct lwp *);
     97        1.1    tsarna 
     98  1.21.16.2    martin static const struct wsmouse_accessops uep_accessops = {
     99        1.1    tsarna 	uep_enable,
    100        1.1    tsarna 	uep_ioctl,
    101        1.1    tsarna 	uep_disable,
    102        1.1    tsarna };
    103        1.1    tsarna 
    104  1.21.16.2    martin static int uep_match(device_t, cfdata_t, void *);
    105  1.21.16.2    martin static void uep_attach(device_t, device_t, void *);
    106  1.21.16.2    martin static void uep_childdet(device_t, device_t);
    107  1.21.16.2    martin static int uep_detach(device_t, int);
    108  1.21.16.2    martin static int uep_activate(device_t, enum devact);
    109  1.21.16.1  christos 
    110       1.12      cube CFATTACH_DECL2_NEW(uep, sizeof(struct uep_softc), uep_match, uep_attach,
    111       1.10    dyoung     uep_detach, uep_activate, NULL, uep_childdet);
    112        1.1    tsarna 
    113  1.21.16.2    martin static int
    114       1.15    dyoung uep_match(device_t parent, cfdata_t match, void *aux)
    115        1.1    tsarna {
    116       1.15    dyoung 	struct usb_attach_arg *uaa = aux;
    117        1.1    tsarna 
    118       1.20     skrll 	if ((uaa->uaa_vendor == USB_VENDOR_EGALAX) && (
    119       1.20     skrll 		(uaa->uaa_product == USB_PRODUCT_EGALAX_TPANEL)
    120       1.20     skrll 		|| (uaa->uaa_product == USB_PRODUCT_EGALAX_TPANEL2)))
    121        1.1    tsarna 		return UMATCH_VENDOR_PRODUCT;
    122        1.1    tsarna 
    123       1.20     skrll 	if ((uaa->uaa_vendor == USB_VENDOR_EGALAX2)
    124       1.20     skrll 	&&  (uaa->uaa_product == USB_PRODUCT_EGALAX2_TPANEL))
    125        1.1    tsarna 		return UMATCH_VENDOR_PRODUCT;
    126        1.1    tsarna 
    127        1.1    tsarna 
    128        1.1    tsarna 	return UMATCH_NONE;
    129        1.1    tsarna }
    130        1.1    tsarna 
    131  1.21.16.2    martin static void
    132       1.15    dyoung uep_attach(device_t parent, device_t self, void *aux)
    133        1.1    tsarna {
    134       1.15    dyoung 	struct uep_softc *sc = device_private(self);
    135       1.15    dyoung 	struct usb_attach_arg *uaa = aux;
    136       1.20     skrll 	struct usbd_device *dev = uaa->uaa_device;
    137        1.1    tsarna 	usb_config_descriptor_t *cdesc;
    138        1.1    tsarna 	usb_interface_descriptor_t *id;
    139        1.1    tsarna 	usb_endpoint_descriptor_t *ed;
    140       1.16   mbalmer 	usb_device_request_t req;
    141       1.16   mbalmer 	uByte act;
    142        1.1    tsarna 	struct wsmousedev_attach_args a;
    143        1.4  augustss 	char *devinfop;
    144        1.1    tsarna 	usbd_status err;
    145       1.19    martin 	int i;
    146        1.1    tsarna 
    147       1.12      cube 	sc->sc_dev = self;
    148       1.13    plunky 
    149       1.13    plunky 	aprint_naive("\n");
    150       1.13    plunky 	aprint_normal("\n");
    151       1.13    plunky 
    152        1.4  augustss 	devinfop = usbd_devinfo_alloc(dev, 0);
    153       1.12      cube 	aprint_normal_dev(self, "%s\n", devinfop);
    154        1.4  augustss 	usbd_devinfo_free(devinfop);
    155        1.1    tsarna 	sc->sc_udev = dev;
    156        1.1    tsarna 	sc->sc_intr_number = -1;
    157        1.1    tsarna 	sc->sc_intr_pipe = NULL;
    158        1.1    tsarna 	sc->sc_enabled = sc->sc_isize = 0;
    159        1.1    tsarna 
    160        1.1    tsarna 	/* Move the device into the configured state. */
    161        1.1    tsarna 	err = usbd_set_config_index(dev, 0, 1);
    162        1.1    tsarna 	if (err) {
    163       1.12      cube 		aprint_error("\n%s: failed to set configuration, err=%s\n",
    164       1.15    dyoung 			device_xname(sc->sc_dev),  usbd_errstr(err));
    165        1.1    tsarna 		sc->sc_dying = 1;
    166       1.15    dyoung 		return;
    167        1.1    tsarna 	}
    168        1.1    tsarna 
    169        1.1    tsarna 	/* get the config descriptor */
    170        1.1    tsarna 	cdesc = usbd_get_config_descriptor(sc->sc_udev);
    171        1.1    tsarna 	if (cdesc == NULL) {
    172       1.12      cube 		aprint_error_dev(self,
    173       1.12      cube 		    "failed to get configuration descriptor\n");
    174        1.1    tsarna 		sc->sc_dying = 1;
    175       1.15    dyoung 		return;
    176        1.1    tsarna 	}
    177        1.1    tsarna 
    178        1.1    tsarna 	/* get the interface */
    179        1.1    tsarna 	err = usbd_device2interface_handle(dev, 0, &sc->sc_iface);
    180        1.1    tsarna 	if (err) {
    181       1.12      cube 		aprint_error("\n%s: failed to get interface, err=%s\n",
    182       1.15    dyoung 			device_xname(sc->sc_dev), usbd_errstr(err));
    183        1.1    tsarna 		sc->sc_dying = 1;
    184       1.15    dyoung 		return;
    185        1.1    tsarna 	}
    186        1.1    tsarna 
    187        1.1    tsarna 	/* Find the interrupt endpoint */
    188        1.1    tsarna 	id = usbd_get_interface_descriptor(sc->sc_iface);
    189        1.1    tsarna 	sc->sc_iface_number = id->bInterfaceNumber;
    190        1.1    tsarna 
    191        1.1    tsarna 	for (i = 0; i < id->bNumEndpoints; i++) {
    192        1.1    tsarna 		ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
    193        1.1    tsarna 		if (ed == NULL) {
    194       1.12      cube 			aprint_error_dev(self,
    195       1.12      cube 			    "no endpoint descriptor for %d\n", i);
    196        1.1    tsarna 			sc->sc_dying = 1;
    197       1.15    dyoung 			return;
    198        1.1    tsarna 		}
    199        1.1    tsarna 
    200        1.1    tsarna 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    201        1.1    tsarna 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
    202        1.1    tsarna 			sc->sc_intr_number = ed->bEndpointAddress;
    203        1.1    tsarna 			sc->sc_isize = UGETW(ed->wMaxPacketSize);
    204        1.1    tsarna 		}
    205        1.1    tsarna 	}
    206        1.1    tsarna 
    207        1.1    tsarna 	if (sc->sc_intr_number== -1) {
    208       1.12      cube 		aprint_error_dev(self, "Could not find interrupt in\n");
    209        1.1    tsarna 		sc->sc_dying = 1;
    210       1.15    dyoung 		return;
    211        1.1    tsarna 	}
    212        1.1    tsarna 
    213       1.16   mbalmer 	/* Newer controllers need an activation command */
    214       1.16   mbalmer 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
    215       1.16   mbalmer 	req.bRequest = 0x0a;
    216       1.16   mbalmer 	USETW(req.wValue, 'A');
    217       1.16   mbalmer 	USETW(req.wIndex, 0);
    218       1.16   mbalmer 	USETW(req.wLength, 1);
    219       1.16   mbalmer 	usbd_do_request(dev, &req, &act);
    220       1.16   mbalmer 
    221       1.16   mbalmer 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev);
    222        1.1    tsarna 
    223        1.1    tsarna 	a.accessops = &uep_accessops;
    224        1.1    tsarna 	a.accesscookie = sc;
    225        1.1    tsarna 
    226        1.1    tsarna 	sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
    227        1.3     perry 
    228        1.2    tsarna 	tpcalib_init(&sc->sc_tpcalib);
    229        1.2    tsarna 	tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
    230        1.8  christos 		(void *)&default_calib, 0, 0);
    231        1.1    tsarna 
    232       1.15    dyoung 	return;
    233        1.1    tsarna }
    234        1.1    tsarna 
    235  1.21.16.2    martin static int
    236       1.15    dyoung uep_detach(device_t self, int flags)
    237        1.1    tsarna {
    238       1.15    dyoung 	struct uep_softc *sc = device_private(self);
    239        1.1    tsarna 	int rv = 0;
    240        1.1    tsarna 
    241        1.1    tsarna 	if (sc->sc_intr_pipe != NULL) {
    242        1.1    tsarna 		usbd_abort_pipe(sc->sc_intr_pipe);
    243        1.1    tsarna 		usbd_close_pipe(sc->sc_intr_pipe);
    244        1.1    tsarna 		sc->sc_intr_pipe = NULL;
    245        1.1    tsarna 	}
    246        1.1    tsarna 	sc->sc_dying = 1;
    247        1.1    tsarna 
    248        1.2    tsarna 	/* save current calib as defaults */
    249        1.2    tsarna 	default_calib = sc->sc_tpcalib.sc_saved;
    250        1.3     perry 
    251       1.10    dyoung 	if (sc->sc_wsmousedev != NULL)
    252        1.1    tsarna 		rv = config_detach(sc->sc_wsmousedev, flags);
    253        1.1    tsarna 
    254       1.16   mbalmer 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
    255        1.1    tsarna 	return rv;
    256        1.1    tsarna }
    257        1.1    tsarna 
    258  1.21.16.2    martin static void
    259       1.10    dyoung uep_childdet(device_t self, device_t child)
    260       1.10    dyoung {
    261       1.10    dyoung 	struct uep_softc *sc = device_private(self);
    262       1.10    dyoung 
    263       1.10    dyoung 	KASSERT(sc->sc_wsmousedev == child);
    264       1.10    dyoung 	sc->sc_wsmousedev = NULL;
    265       1.10    dyoung }
    266       1.10    dyoung 
    267  1.21.16.2    martin static int
    268       1.10    dyoung uep_activate(device_t self, enum devact act)
    269        1.1    tsarna {
    270       1.10    dyoung 	struct uep_softc *sc = device_private(self);
    271        1.1    tsarna 
    272        1.1    tsarna 	switch (act) {
    273        1.1    tsarna 	case DVACT_DEACTIVATE:
    274        1.1    tsarna 		sc->sc_dying = 1;
    275       1.14    dyoung 		return 0;
    276       1.14    dyoung 	default:
    277       1.14    dyoung 		return EOPNOTSUPP;
    278        1.1    tsarna 	}
    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.16   mbalmer 
    296       1.20     skrll 	sc->sc_ibuf = kmem_alloc(sc->sc_isize, KM_SLEEP);
    297        1.1    tsarna 	err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_intr_number,
    298        1.1    tsarna 		USBD_SHORT_XFER_OK, &sc->sc_intr_pipe, sc, sc->sc_ibuf,
    299        1.1    tsarna 		sc->sc_isize, uep_intr, USBD_DEFAULT_INTERVAL);
    300        1.1    tsarna 	if (err) {
    301       1.20     skrll 		kmem_free(sc->sc_ibuf, sc->sc_isize);
    302        1.1    tsarna 		sc->sc_intr_pipe = NULL;
    303        1.1    tsarna 		return EIO;
    304        1.1    tsarna 	}
    305        1.1    tsarna 
    306        1.1    tsarna 	sc->sc_enabled = 1;
    307        1.1    tsarna 
    308        1.1    tsarna 	return 0;
    309        1.1    tsarna }
    310        1.1    tsarna 
    311        1.1    tsarna Static void
    312        1.1    tsarna uep_disable(void *v)
    313        1.1    tsarna {
    314        1.1    tsarna 	struct uep_softc *sc = v;
    315        1.1    tsarna 
    316        1.1    tsarna 	if (!sc->sc_enabled) {
    317        1.1    tsarna 		printf("uep_disable: already disabled!\n");
    318        1.1    tsarna 		return;
    319        1.1    tsarna 	}
    320        1.1    tsarna 
    321        1.1    tsarna 	/* Disable interrupts. */
    322        1.1    tsarna 	if (sc->sc_intr_pipe != NULL) {
    323        1.1    tsarna 		usbd_abort_pipe(sc->sc_intr_pipe);
    324        1.1    tsarna 		usbd_close_pipe(sc->sc_intr_pipe);
    325        1.1    tsarna 		sc->sc_intr_pipe = NULL;
    326        1.1    tsarna 	}
    327        1.1    tsarna 
    328        1.1    tsarna 	if (sc->sc_ibuf != NULL) {
    329       1.20     skrll 		kmem_free(sc->sc_ibuf, sc->sc_isize);
    330        1.1    tsarna 		sc->sc_ibuf = NULL;
    331        1.1    tsarna 	}
    332        1.1    tsarna 
    333        1.1    tsarna 	sc->sc_enabled = 0;
    334        1.1    tsarna }
    335        1.1    tsarna 
    336        1.1    tsarna Static int
    337        1.8  christos uep_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
    338        1.1    tsarna {
    339        1.2    tsarna 	struct uep_softc *sc = v;
    340        1.2    tsarna 	struct wsmouse_id *id;
    341        1.2    tsarna 
    342        1.1    tsarna 	switch (cmd) {
    343        1.1    tsarna 	case WSMOUSEIO_GTYPE:
    344        1.1    tsarna 		*(u_int *)data = WSMOUSE_TYPE_TPANEL;
    345        1.2    tsarna 		return 0;
    346        1.2    tsarna 
    347        1.2    tsarna 	case WSMOUSEIO_GETID:
    348        1.2    tsarna 		/*
    349        1.2    tsarna 		 * return unique ID string
    350        1.2    tsarna 		 * "<vendor> <model> <serial number>"
    351        1.2    tsarna 		 * unfortunately we have no serial number...
    352        1.2    tsarna 		 */
    353        1.2    tsarna 		 id = (struct wsmouse_id *)data;
    354        1.2    tsarna 		 if (id->type != WSMOUSE_ID_TYPE_UIDSTR)
    355       1.18  jakllsch 		 	return EINVAL;
    356        1.3     perry 
    357        1.2    tsarna 		strcpy(id->data, UIDSTR);
    358        1.2    tsarna 		id->length = strlen(UIDSTR);
    359        1.2    tsarna 		return 0;
    360        1.2    tsarna 
    361        1.2    tsarna 	case WSMOUSEIO_SCALIBCOORDS:
    362        1.2    tsarna 	case WSMOUSEIO_GCALIBCOORDS:
    363        1.5  christos 		return tpcalib_ioctl(&sc->sc_tpcalib, cmd, data, flag, l);
    364        1.1    tsarna 	}
    365        1.1    tsarna 
    366        1.1    tsarna 	return EPASSTHROUGH;
    367        1.1    tsarna }
    368        1.1    tsarna 
    369       1.21      maya static int
    370       1.21      maya uep_adjust(int v, int off, int rat)
    371       1.21      maya {
    372       1.21      maya 	int num = 100 * v;
    373       1.21      maya 	int quot = num / rat;
    374       1.21      maya 	int rem = num % rat;
    375       1.21      maya 	if (num >= 0 && rem < 0)
    376       1.21      maya 		quot++;
    377       1.21      maya 	return quot + off;
    378       1.21      maya }
    379       1.21      maya 
    380        1.1    tsarna void
    381       1.20     skrll uep_intr(struct usbd_xfer *xfer, void *addr, usbd_status status)
    382        1.1    tsarna {
    383        1.1    tsarna 	struct uep_softc *sc = addr;
    384        1.1    tsarna 	u_char *p = sc->sc_ibuf;
    385       1.16   mbalmer 	u_char msk;
    386       1.20     skrll 	uint32_t len;
    387        1.1    tsarna 	int x = 0, y = 0, s;
    388        1.1    tsarna 
    389        1.1    tsarna 	usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL);
    390        1.1    tsarna 
    391        1.1    tsarna 	if (status == USBD_CANCELLED)
    392        1.1    tsarna 		return;
    393        1.1    tsarna 
    394        1.1    tsarna 	if (status != USBD_NORMAL_COMPLETION) {
    395       1.12      cube 		aprint_error_dev(sc->sc_dev, "status %d\n", status);
    396        1.1    tsarna 		usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
    397        1.1    tsarna 		return;
    398        1.1    tsarna 	}
    399        1.1    tsarna 
    400       1.16   mbalmer 	/* First bit is always set to 1 */
    401       1.16   mbalmer 	if ((p[0] & 0x80) != 0x80) {
    402       1.16   mbalmer 		aprint_error_dev(sc->sc_dev, "bad input packet format\n");
    403        1.1    tsarna 		return;
    404        1.1    tsarna 	}
    405        1.1    tsarna 
    406        1.1    tsarna 	if (sc->sc_wsmousedev != NULL) {
    407       1.16   mbalmer 		/*
    408       1.16   mbalmer 		 * Each report package may contain 5 or 6 bytes as below:
    409       1.16   mbalmer 		 *
    410       1.16   mbalmer 		 * Byte 0	1ZM00HLT
    411       1.16   mbalmer 		 * Byte 1	0AAAAAAA
    412       1.16   mbalmer 		 * Byte 2	0AAAAAAA
    413       1.16   mbalmer 		 * Byte 3	0BBBBBBB
    414       1.16   mbalmer 		 * Byte 4	0BBBBBBB
    415       1.16   mbalmer 		 * Byte 5	0PPPPPPP
    416       1.16   mbalmer 		 *
    417       1.16   mbalmer 		 * Z: 1=byte 5 is pressure information, 0=no pressure
    418       1.16   mbalmer 		 * M: 1=byte 5 is play id, 0=no player id
    419       1.16   mbalmer 		 * T: 1=touched, 0=not touched
    420       1.16   mbalmer 		 * H,L: Resolution
    421       1.16   mbalmer 		 *	0,0: 11 bits
    422       1.16   mbalmer 		 *	0,1: 12 bits
    423       1.16   mbalmer 		 *	1,0: 13 bits
    424       1.16   mbalmer 		 *	1,1: 14 bits
    425       1.16   mbalmer 		 * A: bits of axis A position, MSB to LSB
    426       1.16   mbalmer 		 * B: bits of axis B position, MSB to LSB
    427       1.16   mbalmer 		 *
    428       1.16   mbalmer 		 * The packet has six bytes only if Z or M is set.
    429       1.16   mbalmer 		 * Byte 5, if sent, is ignored.
    430       1.16   mbalmer 		 *
    431       1.16   mbalmer 		 * For the unit I have, A = Y and B = X.
    432       1.16   mbalmer 		 * I don't know if units exist with A=X and B=Y,
    433       1.16   mbalmer 		 * if so we'll cross that bridge when we come to it.
    434       1.16   mbalmer 		 *
    435       1.16   mbalmer 		 * The controller sends a stream of T=1 events while the
    436       1.16   mbalmer 		 * panel is touched, followed by a single T=0 event.
    437       1.16   mbalmer 		 */
    438       1.16   mbalmer 		switch (p[0] & 0x06) {
    439       1.16   mbalmer 		case 0x02:
    440       1.16   mbalmer 			msk = 0x1f;
    441       1.16   mbalmer 			break;
    442       1.16   mbalmer 		case 0x04:
    443       1.16   mbalmer 			msk = 0x3f;
    444       1.16   mbalmer 			break;
    445       1.16   mbalmer 		case 0x06:
    446       1.16   mbalmer 			msk = 0x7f;
    447       1.16   mbalmer 			break;
    448       1.16   mbalmer 		default:
    449       1.16   mbalmer 			msk = 0x0f;	/* H=0, L=0 */
    450       1.16   mbalmer 		}
    451       1.21      maya 		x = uep_adjust(((p[3] & msk) << 7) | p[4], X_OFFSET, X_RATIO);
    452       1.21      maya 		y = uep_adjust(((p[1] & msk) << 7) | p[2], Y_OFFSET, Y_RATIO);
    453        1.3     perry 
    454        1.2    tsarna 		tpcalib_trans(&sc->sc_tpcalib, x, y, &x, &y);
    455        1.1    tsarna 
    456        1.1    tsarna 		s = spltty();
    457        1.7    plunky 		wsmouse_input(sc->sc_wsmousedev, p[0] & 0x01, x, y, 0, 0,
    458        1.1    tsarna 			WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
    459        1.1    tsarna 		splx(s);
    460        1.1    tsarna 	}
    461        1.1    tsarna }
    462