Home | History | Annotate | Line # | Download | only in usb
uep.c revision 1.19.6.3
      1  1.19.6.3     skrll /*	$NetBSD: uep.c,v 1.19.6.3 2015/03/19 17:26:43 skrll 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.19.6.3     skrll __KERNEL_RCSID(0, "$NetBSD: uep.c,v 1.19.6.3 2015/03/19 17:26:43 skrll 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.19.6.2     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.1    tsarna 
     58       1.1    tsarna struct uep_softc {
     59      1.15    dyoung 	device_t sc_dev;
     60  1.19.6.3     skrll 	struct usbd_device *sc_udev;	/* device */
     61  1.19.6.3     skrll 	struct usbd_interface *sc_iface;	/* interface */
     62       1.1    tsarna 	int sc_iface_number;
     63       1.1    tsarna 
     64       1.1    tsarna 	int			sc_intr_number; /* interrupt number */
     65  1.19.6.3     skrll 	struct usbd_pipe *	sc_intr_pipe;	/* interrupt pipe */
     66       1.1    tsarna 	u_char			*sc_ibuf;
     67       1.1    tsarna 	int			sc_isize;
     68       1.1    tsarna 
     69      1.15    dyoung 	device_t		sc_wsmousedev;	/* wsmouse device */
     70       1.2    tsarna 	struct tpcalib_softc	sc_tpcalib;	/* calibration */
     71       1.1    tsarna 
     72       1.1    tsarna 	u_char sc_enabled;
     73       1.1    tsarna 	u_char sc_dying;
     74       1.1    tsarna };
     75       1.1    tsarna 
     76       1.2    tsarna static struct wsmouse_calibcoords default_calib = {
     77       1.6  christos 	.minx = 0,
     78       1.6  christos 	.miny = 0,
     79       1.6  christos 	.maxx = 2047,
     80       1.6  christos 	.maxy = 2047,
     81       1.6  christos 	.samplelen = WSMOUSE_CALIBCOORDS_RESET,
     82       1.2    tsarna };
     83       1.2    tsarna 
     84  1.19.6.3     skrll Static void uep_intr(struct usbd_xfer *, void *, usbd_status);
     85       1.1    tsarna 
     86       1.1    tsarna Static int	uep_enable(void *);
     87       1.1    tsarna Static void	uep_disable(void *);
     88       1.8  christos Static int	uep_ioctl(void *, u_long, void *, int, struct lwp *);
     89       1.1    tsarna 
     90       1.1    tsarna const struct wsmouse_accessops uep_accessops = {
     91       1.1    tsarna 	uep_enable,
     92       1.1    tsarna 	uep_ioctl,
     93       1.1    tsarna 	uep_disable,
     94       1.1    tsarna };
     95       1.1    tsarna 
     96      1.12      cube int uep_match(device_t, cfdata_t, void *);
     97      1.10    dyoung void uep_attach(device_t, device_t, void *);
     98      1.10    dyoung void uep_childdet(device_t, device_t);
     99      1.10    dyoung int uep_detach(device_t, int);
    100      1.10    dyoung int uep_activate(device_t, enum devact);
    101      1.10    dyoung extern struct cfdriver uep_cd;
    102      1.12      cube CFATTACH_DECL2_NEW(uep, sizeof(struct uep_softc), uep_match, uep_attach,
    103      1.10    dyoung     uep_detach, uep_activate, NULL, uep_childdet);
    104       1.1    tsarna 
    105      1.16   mbalmer int
    106      1.15    dyoung uep_match(device_t parent, cfdata_t match, void *aux)
    107       1.1    tsarna {
    108      1.15    dyoung 	struct usb_attach_arg *uaa = aux;
    109       1.1    tsarna 
    110       1.1    tsarna 	if ((uaa->vendor == USB_VENDOR_EGALAX) && (
    111       1.1    tsarna 		(uaa->product == USB_PRODUCT_EGALAX_TPANEL)
    112      1.16   mbalmer 		|| (uaa->product == USB_PRODUCT_EGALAX_TPANEL2)))
    113       1.1    tsarna 		return UMATCH_VENDOR_PRODUCT;
    114       1.1    tsarna 
    115       1.1    tsarna 	if ((uaa->vendor == USB_VENDOR_EGALAX2)
    116       1.1    tsarna 	&&  (uaa->product == USB_PRODUCT_EGALAX2_TPANEL))
    117       1.1    tsarna 		return UMATCH_VENDOR_PRODUCT;
    118       1.1    tsarna 
    119       1.1    tsarna 
    120       1.1    tsarna 	return UMATCH_NONE;
    121       1.1    tsarna }
    122       1.1    tsarna 
    123      1.16   mbalmer void
    124      1.15    dyoung uep_attach(device_t parent, device_t self, void *aux)
    125       1.1    tsarna {
    126      1.15    dyoung 	struct uep_softc *sc = device_private(self);
    127      1.15    dyoung 	struct usb_attach_arg *uaa = aux;
    128  1.19.6.3     skrll 	struct usbd_device *dev = uaa->device;
    129       1.1    tsarna 	usb_config_descriptor_t *cdesc;
    130       1.1    tsarna 	usb_interface_descriptor_t *id;
    131       1.1    tsarna 	usb_endpoint_descriptor_t *ed;
    132      1.16   mbalmer 	usb_device_request_t req;
    133      1.16   mbalmer 	uByte act;
    134       1.1    tsarna 	struct wsmousedev_attach_args a;
    135       1.4  augustss 	char *devinfop;
    136       1.1    tsarna 	usbd_status err;
    137      1.19    martin 	int i;
    138       1.1    tsarna 
    139      1.12      cube 	sc->sc_dev = self;
    140      1.13    plunky 
    141      1.13    plunky 	aprint_naive("\n");
    142      1.13    plunky 	aprint_normal("\n");
    143      1.13    plunky 
    144       1.4  augustss 	devinfop = usbd_devinfo_alloc(dev, 0);
    145      1.12      cube 	aprint_normal_dev(self, "%s\n", devinfop);
    146       1.4  augustss 	usbd_devinfo_free(devinfop);
    147       1.1    tsarna 	sc->sc_udev = dev;
    148       1.1    tsarna 	sc->sc_intr_number = -1;
    149       1.1    tsarna 	sc->sc_intr_pipe = NULL;
    150       1.1    tsarna 	sc->sc_enabled = sc->sc_isize = 0;
    151       1.1    tsarna 
    152       1.1    tsarna 	/* Move the device into the configured state. */
    153       1.1    tsarna 	err = usbd_set_config_index(dev, 0, 1);
    154       1.1    tsarna 	if (err) {
    155      1.12      cube 		aprint_error("\n%s: failed to set configuration, err=%s\n",
    156      1.15    dyoung 			device_xname(sc->sc_dev),  usbd_errstr(err));
    157       1.1    tsarna 		sc->sc_dying = 1;
    158      1.15    dyoung 		return;
    159       1.1    tsarna 	}
    160       1.1    tsarna 
    161       1.1    tsarna 	/* get the config descriptor */
    162       1.1    tsarna 	cdesc = usbd_get_config_descriptor(sc->sc_udev);
    163       1.1    tsarna 	if (cdesc == NULL) {
    164      1.12      cube 		aprint_error_dev(self,
    165      1.12      cube 		    "failed to get configuration descriptor\n");
    166       1.1    tsarna 		sc->sc_dying = 1;
    167      1.15    dyoung 		return;
    168       1.1    tsarna 	}
    169       1.1    tsarna 
    170       1.1    tsarna 	/* get the interface */
    171       1.1    tsarna 	err = usbd_device2interface_handle(dev, 0, &sc->sc_iface);
    172       1.1    tsarna 	if (err) {
    173      1.12      cube 		aprint_error("\n%s: failed to get interface, err=%s\n",
    174      1.15    dyoung 			device_xname(sc->sc_dev), usbd_errstr(err));
    175       1.1    tsarna 		sc->sc_dying = 1;
    176      1.15    dyoung 		return;
    177       1.1    tsarna 	}
    178       1.1    tsarna 
    179       1.1    tsarna 	/* Find the interrupt endpoint */
    180       1.1    tsarna 	id = usbd_get_interface_descriptor(sc->sc_iface);
    181       1.1    tsarna 	sc->sc_iface_number = id->bInterfaceNumber;
    182       1.1    tsarna 
    183       1.1    tsarna 	for (i = 0; i < id->bNumEndpoints; i++) {
    184       1.1    tsarna 		ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
    185       1.1    tsarna 		if (ed == NULL) {
    186      1.12      cube 			aprint_error_dev(self,
    187      1.12      cube 			    "no endpoint descriptor for %d\n", i);
    188       1.1    tsarna 			sc->sc_dying = 1;
    189      1.15    dyoung 			return;
    190       1.1    tsarna 		}
    191       1.1    tsarna 
    192       1.1    tsarna 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    193       1.1    tsarna 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
    194       1.1    tsarna 			sc->sc_intr_number = ed->bEndpointAddress;
    195       1.1    tsarna 			sc->sc_isize = UGETW(ed->wMaxPacketSize);
    196       1.1    tsarna 		}
    197       1.1    tsarna 	}
    198       1.1    tsarna 
    199       1.1    tsarna 	if (sc->sc_intr_number== -1) {
    200      1.12      cube 		aprint_error_dev(self, "Could not find interrupt in\n");
    201       1.1    tsarna 		sc->sc_dying = 1;
    202      1.15    dyoung 		return;
    203       1.1    tsarna 	}
    204       1.1    tsarna 
    205      1.16   mbalmer 	/* Newer controllers need an activation command */
    206      1.16   mbalmer 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
    207      1.16   mbalmer 	req.bRequest = 0x0a;
    208      1.16   mbalmer 	USETW(req.wValue, 'A');
    209      1.16   mbalmer 	USETW(req.wIndex, 0);
    210      1.16   mbalmer 	USETW(req.wLength, 1);
    211      1.16   mbalmer 	usbd_do_request(dev, &req, &act);
    212      1.16   mbalmer 
    213      1.16   mbalmer 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, 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.8  christos 		(void *)&default_calib, 0, 0);
    223       1.1    tsarna 
    224      1.15    dyoung 	return;
    225       1.1    tsarna }
    226       1.1    tsarna 
    227      1.16   mbalmer int
    228      1.15    dyoung uep_detach(device_t self, int flags)
    229       1.1    tsarna {
    230      1.15    dyoung 	struct uep_softc *sc = device_private(self);
    231       1.1    tsarna 	int rv = 0;
    232       1.1    tsarna 
    233       1.1    tsarna 	if (sc->sc_intr_pipe != NULL) {
    234       1.1    tsarna 		usbd_abort_pipe(sc->sc_intr_pipe);
    235       1.1    tsarna 		usbd_close_pipe(sc->sc_intr_pipe);
    236       1.1    tsarna 		sc->sc_intr_pipe = NULL;
    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.10    dyoung 	if (sc->sc_wsmousedev != NULL)
    244       1.1    tsarna 		rv = config_detach(sc->sc_wsmousedev, flags);
    245       1.1    tsarna 
    246      1.16   mbalmer 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
    247       1.1    tsarna 	return rv;
    248       1.1    tsarna }
    249       1.1    tsarna 
    250      1.10    dyoung void
    251      1.10    dyoung uep_childdet(device_t self, device_t child)
    252      1.10    dyoung {
    253      1.10    dyoung 	struct uep_softc *sc = device_private(self);
    254      1.10    dyoung 
    255      1.10    dyoung 	KASSERT(sc->sc_wsmousedev == child);
    256      1.10    dyoung 	sc->sc_wsmousedev = NULL;
    257      1.10    dyoung }
    258      1.10    dyoung 
    259       1.1    tsarna int
    260      1.10    dyoung uep_activate(device_t self, enum devact act)
    261       1.1    tsarna {
    262      1.10    dyoung 	struct uep_softc *sc = device_private(self);
    263       1.1    tsarna 
    264       1.1    tsarna 	switch (act) {
    265       1.1    tsarna 	case DVACT_DEACTIVATE:
    266       1.1    tsarna 		sc->sc_dying = 1;
    267      1.14    dyoung 		return 0;
    268      1.14    dyoung 	default:
    269      1.14    dyoung 		return EOPNOTSUPP;
    270       1.1    tsarna 	}
    271       1.1    tsarna }
    272       1.1    tsarna 
    273       1.1    tsarna Static int
    274       1.1    tsarna uep_enable(void *v)
    275       1.1    tsarna {
    276       1.1    tsarna 	struct uep_softc *sc = v;
    277       1.1    tsarna 	int err;
    278       1.1    tsarna 
    279       1.1    tsarna 	if (sc->sc_dying)
    280       1.1    tsarna 		return EIO;
    281       1.1    tsarna 
    282       1.1    tsarna 	if (sc->sc_enabled)
    283       1.1    tsarna 		return EBUSY;
    284       1.1    tsarna 
    285       1.1    tsarna 	if (sc->sc_isize == 0)
    286       1.1    tsarna 		return 0;
    287      1.16   mbalmer 
    288  1.19.6.2     skrll 	sc->sc_ibuf = kmem_alloc(sc->sc_isize, KM_SLEEP);
    289       1.1    tsarna 	err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_intr_number,
    290       1.1    tsarna 		USBD_SHORT_XFER_OK, &sc->sc_intr_pipe, sc, sc->sc_ibuf,
    291       1.1    tsarna 		sc->sc_isize, uep_intr, USBD_DEFAULT_INTERVAL);
    292       1.1    tsarna 	if (err) {
    293  1.19.6.2     skrll 		kmem_free(sc->sc_ibuf, sc->sc_isize);
    294       1.1    tsarna 		sc->sc_intr_pipe = NULL;
    295       1.1    tsarna 		return EIO;
    296       1.1    tsarna 	}
    297       1.1    tsarna 
    298       1.1    tsarna 	sc->sc_enabled = 1;
    299       1.1    tsarna 
    300       1.1    tsarna 	return 0;
    301       1.1    tsarna }
    302       1.1    tsarna 
    303       1.1    tsarna Static void
    304       1.1    tsarna uep_disable(void *v)
    305       1.1    tsarna {
    306       1.1    tsarna 	struct uep_softc *sc = v;
    307       1.1    tsarna 
    308       1.1    tsarna 	if (!sc->sc_enabled) {
    309       1.1    tsarna 		printf("uep_disable: already disabled!\n");
    310       1.1    tsarna 		return;
    311       1.1    tsarna 	}
    312       1.1    tsarna 
    313       1.1    tsarna 	/* Disable interrupts. */
    314       1.1    tsarna 	if (sc->sc_intr_pipe != NULL) {
    315       1.1    tsarna 		usbd_abort_pipe(sc->sc_intr_pipe);
    316       1.1    tsarna 		usbd_close_pipe(sc->sc_intr_pipe);
    317       1.1    tsarna 		sc->sc_intr_pipe = NULL;
    318       1.1    tsarna 	}
    319       1.1    tsarna 
    320       1.1    tsarna 	if (sc->sc_ibuf != NULL) {
    321  1.19.6.2     skrll 		kmem_free(sc->sc_ibuf, sc->sc_isize);
    322       1.1    tsarna 		sc->sc_ibuf = NULL;
    323       1.1    tsarna 	}
    324       1.1    tsarna 
    325       1.1    tsarna 	sc->sc_enabled = 0;
    326       1.1    tsarna }
    327       1.1    tsarna 
    328       1.1    tsarna Static int
    329       1.8  christos uep_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
    330       1.1    tsarna {
    331       1.2    tsarna 	struct uep_softc *sc = v;
    332       1.2    tsarna 	struct wsmouse_id *id;
    333       1.2    tsarna 
    334       1.1    tsarna 	switch (cmd) {
    335       1.1    tsarna 	case WSMOUSEIO_GTYPE:
    336       1.1    tsarna 		*(u_int *)data = WSMOUSE_TYPE_TPANEL;
    337       1.2    tsarna 		return 0;
    338       1.2    tsarna 
    339       1.2    tsarna 	case WSMOUSEIO_GETID:
    340       1.2    tsarna 		/*
    341       1.2    tsarna 		 * return unique ID string
    342       1.2    tsarna 		 * "<vendor> <model> <serial number>"
    343       1.2    tsarna 		 * unfortunately we have no serial number...
    344       1.2    tsarna 		 */
    345       1.2    tsarna 		 id = (struct wsmouse_id *)data;
    346       1.2    tsarna 		 if (id->type != WSMOUSE_ID_TYPE_UIDSTR)
    347      1.18  jakllsch 		 	return EINVAL;
    348       1.3     perry 
    349       1.2    tsarna 		strcpy(id->data, UIDSTR);
    350       1.2    tsarna 		id->length = strlen(UIDSTR);
    351       1.2    tsarna 		return 0;
    352       1.2    tsarna 
    353       1.2    tsarna 	case WSMOUSEIO_SCALIBCOORDS:
    354       1.2    tsarna 	case WSMOUSEIO_GCALIBCOORDS:
    355       1.5  christos 		return tpcalib_ioctl(&sc->sc_tpcalib, cmd, data, flag, l);
    356       1.1    tsarna 	}
    357       1.1    tsarna 
    358       1.1    tsarna 	return EPASSTHROUGH;
    359       1.1    tsarna }
    360       1.1    tsarna 
    361       1.1    tsarna void
    362  1.19.6.3     skrll uep_intr(struct usbd_xfer *xfer, void *addr, usbd_status status)
    363       1.1    tsarna {
    364       1.1    tsarna 	struct uep_softc *sc = addr;
    365       1.1    tsarna 	u_char *p = sc->sc_ibuf;
    366      1.16   mbalmer 	u_char msk;
    367  1.19.6.1     skrll 	uint32_t len;
    368       1.1    tsarna 	int x = 0, y = 0, s;
    369       1.1    tsarna 
    370       1.1    tsarna 	usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL);
    371       1.1    tsarna 
    372       1.1    tsarna 	if (status == USBD_CANCELLED)
    373       1.1    tsarna 		return;
    374       1.1    tsarna 
    375       1.1    tsarna 	if (status != USBD_NORMAL_COMPLETION) {
    376      1.12      cube 		aprint_error_dev(sc->sc_dev, "status %d\n", status);
    377       1.1    tsarna 		usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
    378       1.1    tsarna 		return;
    379       1.1    tsarna 	}
    380       1.1    tsarna 
    381      1.16   mbalmer 	/* First bit is always set to 1 */
    382      1.16   mbalmer 	if ((p[0] & 0x80) != 0x80) {
    383      1.16   mbalmer 		aprint_error_dev(sc->sc_dev, "bad input packet format\n");
    384       1.1    tsarna 		return;
    385       1.1    tsarna 	}
    386       1.1    tsarna 
    387       1.1    tsarna 	if (sc->sc_wsmousedev != NULL) {
    388      1.16   mbalmer 		/*
    389      1.16   mbalmer 		 * Each report package may contain 5 or 6 bytes as below:
    390      1.16   mbalmer 		 *
    391      1.16   mbalmer 		 * Byte 0	1ZM00HLT
    392      1.16   mbalmer 		 * Byte 1	0AAAAAAA
    393      1.16   mbalmer 		 * Byte 2	0AAAAAAA
    394      1.16   mbalmer 		 * Byte 3	0BBBBBBB
    395      1.16   mbalmer 		 * Byte 4	0BBBBBBB
    396      1.16   mbalmer 		 * Byte 5	0PPPPPPP
    397      1.16   mbalmer 		 *
    398      1.16   mbalmer 		 * Z: 1=byte 5 is pressure information, 0=no pressure
    399      1.16   mbalmer 		 * M: 1=byte 5 is play id, 0=no player id
    400      1.16   mbalmer 		 * T: 1=touched, 0=not touched
    401      1.16   mbalmer 		 * H,L: Resolution
    402      1.16   mbalmer 		 *	0,0: 11 bits
    403      1.16   mbalmer 		 *	0,1: 12 bits
    404      1.16   mbalmer 		 *	1,0: 13 bits
    405      1.16   mbalmer 		 *	1,1: 14 bits
    406      1.16   mbalmer 		 * A: bits of axis A position, MSB to LSB
    407      1.16   mbalmer 		 * B: bits of axis B position, MSB to LSB
    408      1.16   mbalmer 		 *
    409      1.16   mbalmer 		 * The packet has six bytes only if Z or M is set.
    410      1.16   mbalmer 		 * Byte 5, if sent, is ignored.
    411      1.16   mbalmer 		 *
    412      1.16   mbalmer 		 * For the unit I have, A = Y and B = X.
    413      1.16   mbalmer 		 * I don't know if units exist with A=X and B=Y,
    414      1.16   mbalmer 		 * if so we'll cross that bridge when we come to it.
    415      1.16   mbalmer 		 *
    416      1.16   mbalmer 		 * The controller sends a stream of T=1 events while the
    417      1.16   mbalmer 		 * panel is touched, followed by a single T=0 event.
    418      1.16   mbalmer 		 */
    419      1.16   mbalmer 		switch (p[0] & 0x06) {
    420      1.16   mbalmer 		case 0x02:
    421      1.16   mbalmer 			msk = 0x1f;
    422      1.16   mbalmer 			break;
    423      1.16   mbalmer 		case 0x04:
    424      1.16   mbalmer 			msk = 0x3f;
    425      1.16   mbalmer 			break;
    426      1.16   mbalmer 		case 0x06:
    427      1.16   mbalmer 			msk = 0x7f;
    428      1.16   mbalmer 			break;
    429      1.16   mbalmer 		default:
    430      1.16   mbalmer 			msk = 0x0f;	/* H=0, L=0 */
    431      1.16   mbalmer 		}
    432      1.16   mbalmer 		x = ((p[3] & msk) << 7) | p[4];
    433      1.16   mbalmer 		y = ((p[1] & msk) << 7) | p[2];
    434       1.3     perry 
    435       1.2    tsarna 		tpcalib_trans(&sc->sc_tpcalib, x, y, &x, &y);
    436       1.1    tsarna 
    437       1.1    tsarna 		s = spltty();
    438       1.7    plunky 		wsmouse_input(sc->sc_wsmousedev, p[0] & 0x01, x, y, 0, 0,
    439       1.1    tsarna 			WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
    440       1.1    tsarna 		splx(s);
    441       1.1    tsarna 	}
    442       1.1    tsarna }
    443