Home | History | Annotate | Line # | Download | only in usb
uvisor.c revision 1.11.2.6
      1  1.11.2.5   nathanw /*	$NetBSD: uvisor.c,v 1.11.2.6 2002/08/27 23:47:19 nathanw Exp $	*/
      2       1.1  augustss 
      3       1.1  augustss /*
      4       1.1  augustss  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5       1.1  augustss  * All rights reserved.
      6       1.1  augustss  *
      7       1.1  augustss  * This code is derived from software contributed to The NetBSD Foundation
      8       1.6  augustss  * by Lennart Augustsson (lennart (at) augustsson.net) at
      9       1.1  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.1  augustss  */
     39       1.1  augustss 
     40       1.1  augustss /*
     41       1.2   hubertf  * Handspring Visor (Palmpilot compatible PDA) driver
     42       1.1  augustss  */
     43  1.11.2.1   nathanw 
     44  1.11.2.1   nathanw #include <sys/cdefs.h>
     45  1.11.2.5   nathanw __KERNEL_RCSID(0, "$NetBSD: uvisor.c,v 1.11.2.6 2002/08/27 23:47:19 nathanw Exp $");
     46       1.1  augustss 
     47       1.1  augustss #include <sys/param.h>
     48       1.1  augustss #include <sys/systm.h>
     49       1.1  augustss #include <sys/kernel.h>
     50       1.1  augustss #include <sys/device.h>
     51       1.1  augustss #include <sys/conf.h>
     52       1.1  augustss #include <sys/tty.h>
     53       1.1  augustss 
     54       1.1  augustss #include <dev/usb/usb.h>
     55       1.1  augustss #include <dev/usb/usbhid.h>
     56       1.1  augustss 
     57       1.1  augustss #include <dev/usb/usbdi.h>
     58       1.1  augustss #include <dev/usb/usbdi_util.h>
     59       1.1  augustss #include <dev/usb/usbdevs.h>
     60       1.1  augustss 
     61       1.1  augustss #include <dev/usb/ucomvar.h>
     62       1.1  augustss 
     63       1.1  augustss #ifdef UVISOR_DEBUG
     64       1.1  augustss #define DPRINTF(x)	if (uvisordebug) printf x
     65       1.1  augustss #define DPRINTFN(n,x)	if (uvisordebug>(n)) printf x
     66       1.3  augustss int uvisordebug = 0;
     67       1.1  augustss #else
     68       1.1  augustss #define DPRINTF(x)
     69       1.1  augustss #define DPRINTFN(n,x)
     70       1.1  augustss #endif
     71       1.1  augustss 
     72       1.1  augustss #define UVISOR_CONFIG_INDEX	0
     73       1.1  augustss #define UVISOR_IFACE_INDEX	0
     74       1.1  augustss 
     75       1.1  augustss /* From the Linux driver */
     76       1.1  augustss /*
     77       1.1  augustss  * UVISOR_REQUEST_BYTES_AVAILABLE asks the visor for the number of bytes that
     78       1.1  augustss  * are available to be transfered to the host for the specified endpoint.
     79       1.1  augustss  * Currently this is not used, and always returns 0x0001
     80       1.1  augustss  */
     81       1.1  augustss #define UVISOR_REQUEST_BYTES_AVAILABLE		0x01
     82       1.1  augustss 
     83       1.1  augustss /*
     84       1.1  augustss  * UVISOR_CLOSE_NOTIFICATION is set to the device to notify it that the host
     85       1.1  augustss  * is now closing the pipe. An empty packet is sent in response.
     86       1.1  augustss  */
     87       1.1  augustss #define UVISOR_CLOSE_NOTIFICATION		0x02
     88       1.1  augustss 
     89       1.1  augustss /*
     90       1.1  augustss  * UVISOR_GET_CONNECTION_INFORMATION is sent by the host during enumeration to
     91       1.1  augustss  * get the endpoints used by the connection.
     92       1.1  augustss  */
     93       1.1  augustss #define UVISOR_GET_CONNECTION_INFORMATION	0x03
     94       1.1  augustss 
     95       1.1  augustss 
     96       1.1  augustss /*
     97       1.1  augustss  * UVISOR_GET_CONNECTION_INFORMATION returns data in the following format
     98       1.1  augustss  */
     99      1.10  augustss #define UVISOR_MAX_CONN 8
    100       1.1  augustss struct uvisor_connection_info {
    101       1.1  augustss 	uWord	num_ports;
    102       1.1  augustss 	struct {
    103       1.1  augustss 		uByte	port_function_id;
    104       1.1  augustss 		uByte	port;
    105      1.10  augustss 	} connections[UVISOR_MAX_CONN];
    106       1.1  augustss };
    107       1.1  augustss #define UVISOR_CONNECTION_INFO_SIZE 18
    108       1.1  augustss 
    109       1.1  augustss /* struct uvisor_connection_info.connection[x].port_function_id defines: */
    110       1.1  augustss #define UVISOR_FUNCTION_GENERIC		0x00
    111       1.1  augustss #define UVISOR_FUNCTION_DEBUGGER	0x01
    112       1.1  augustss #define UVISOR_FUNCTION_HOTSYNC		0x02
    113       1.1  augustss #define UVISOR_FUNCTION_CONSOLE		0x03
    114       1.1  augustss #define UVISOR_FUNCTION_REMOTE_FILE_SYS	0x04
    115       1.1  augustss 
    116  1.11.2.3   nathanw /*
    117  1.11.2.3   nathanw  * Unknown PalmOS stuff.
    118  1.11.2.3   nathanw  */
    119  1.11.2.3   nathanw #define UVISOR_GET_PALM_INFORMATION		0x04
    120  1.11.2.3   nathanw #define UVISOR_GET_PALM_INFORMATION_LEN		0x14
    121  1.11.2.3   nathanw 
    122       1.1  augustss 
    123       1.4  augustss #define UVISORIBUFSIZE 1024
    124       1.4  augustss #define UVISOROBUFSIZE 1024
    125       1.4  augustss 
    126       1.1  augustss struct uvisor_softc {
    127       1.1  augustss 	USBBASEDEVICE		sc_dev;		/* base device */
    128       1.1  augustss 	usbd_device_handle	sc_udev;	/* device */
    129       1.1  augustss 	usbd_interface_handle	sc_iface;	/* interface */
    130       1.1  augustss 
    131      1.10  augustss 	device_ptr_t		sc_subdevs[UVISOR_MAX_CONN];
    132      1.10  augustss 	int			sc_numcon;
    133       1.1  augustss 
    134  1.11.2.3   nathanw 	u_int16_t		sc_flags;
    135  1.11.2.3   nathanw 
    136       1.1  augustss 	u_char			sc_dying;
    137       1.1  augustss };
    138       1.1  augustss 
    139  1.11.2.5   nathanw Static usbd_status uvisor_init(struct uvisor_softc *,
    140      1.10  augustss 			       struct uvisor_connection_info *);
    141       1.1  augustss 
    142       1.7  augustss Static void uvisor_close(void *, int);
    143       1.1  augustss 
    144       1.1  augustss 
    145       1.1  augustss struct ucom_methods uvisor_methods = {
    146       1.1  augustss 	NULL,
    147       1.1  augustss 	NULL,
    148       1.1  augustss 	NULL,
    149       1.1  augustss 	NULL,
    150       1.1  augustss 	NULL,
    151       1.1  augustss 	uvisor_close,
    152       1.5  augustss 	NULL,
    153       1.5  augustss 	NULL,
    154       1.1  augustss };
    155       1.1  augustss 
    156  1.11.2.3   nathanw struct uvisor_type {
    157  1.11.2.3   nathanw 	struct usb_devno	uv_dev;
    158  1.11.2.3   nathanw 	u_int16_t		uv_flags;
    159  1.11.2.3   nathanw #define PALM4	0x0001
    160  1.11.2.3   nathanw };
    161  1.11.2.3   nathanw static const struct uvisor_type uvisor_devs[] = {
    162  1.11.2.3   nathanw 	{{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_VISOR }, 0 },
    163  1.11.2.3   nathanw 	{{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M500 }, PALM4 },
    164  1.11.2.3   nathanw 	{{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M505 }, PALM4 },
    165  1.11.2.6   nathanw 	{{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M515 }, PALM4 },
    166  1.11.2.3   nathanw 	{{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M125 }, PALM4 },
    167  1.11.2.3   nathanw 	{{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40 }, PALM4 },
    168  1.11.2.4   nathanw 	{{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_41 }, 0 },
    169  1.11.2.3   nathanw /*	{{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_25 }, PALM4 },*/
    170  1.11.2.3   nathanw };
    171  1.11.2.3   nathanw #define uvisor_lookup(v, p) ((struct uvisor_type *)usb_lookup(uvisor_devs, v, p))
    172  1.11.2.3   nathanw 
    173       1.1  augustss USB_DECLARE_DRIVER(uvisor);
    174       1.1  augustss 
    175       1.1  augustss USB_MATCH(uvisor)
    176       1.1  augustss {
    177       1.1  augustss 	USB_MATCH_START(uvisor, uaa);
    178  1.11.2.5   nathanw 
    179       1.1  augustss 	if (uaa->iface != NULL)
    180       1.1  augustss 		return (UMATCH_NONE);
    181       1.1  augustss 
    182       1.1  augustss 	DPRINTFN(20,("uvisor: vendor=0x%x, product=0x%x\n",
    183       1.1  augustss 		     uaa->vendor, uaa->product));
    184       1.1  augustss 
    185  1.11.2.3   nathanw 	return (uvisor_lookup(uaa->vendor, uaa->product) != NULL ?
    186  1.11.2.3   nathanw 		UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
    187       1.1  augustss }
    188       1.1  augustss 
    189       1.1  augustss USB_ATTACH(uvisor)
    190       1.1  augustss {
    191       1.1  augustss 	USB_ATTACH_START(uvisor, sc, uaa);
    192       1.1  augustss 	usbd_device_handle dev = uaa->device;
    193       1.1  augustss 	usbd_interface_handle iface;
    194       1.1  augustss 	usb_interface_descriptor_t *id;
    195      1.10  augustss 	struct uvisor_connection_info coninfo;
    196       1.1  augustss 	usb_endpoint_descriptor_t *ed;
    197       1.1  augustss 	char devinfo[1024];
    198       1.1  augustss 	char *devname = USBDEVNAME(sc->sc_dev);
    199      1.10  augustss 	int i, j, hasin, hasout, port;
    200       1.1  augustss 	usbd_status err;
    201       1.1  augustss 	struct ucom_attach_args uca;
    202       1.1  augustss 
    203       1.1  augustss 	DPRINTFN(10,("\nuvisor_attach: sc=%p\n", sc));
    204       1.1  augustss 
    205       1.1  augustss 	/* Move the device into the configured state. */
    206       1.1  augustss 	err = usbd_set_config_index(dev, UVISOR_CONFIG_INDEX, 1);
    207       1.1  augustss 	if (err) {
    208       1.1  augustss 		printf("\n%s: failed to set configuration, err=%s\n",
    209       1.1  augustss 		       devname, usbd_errstr(err));
    210       1.1  augustss 		goto bad;
    211       1.1  augustss 	}
    212       1.1  augustss 
    213       1.1  augustss 	err = usbd_device2interface_handle(dev, UVISOR_IFACE_INDEX, &iface);
    214       1.1  augustss 	if (err) {
    215       1.1  augustss 		printf("\n%s: failed to get interface, err=%s\n",
    216       1.1  augustss 		       devname, usbd_errstr(err));
    217       1.1  augustss 		goto bad;
    218       1.1  augustss 	}
    219       1.1  augustss 
    220       1.1  augustss 	usbd_devinfo(dev, 0, devinfo);
    221       1.1  augustss 	USB_ATTACH_SETUP;
    222       1.1  augustss 	printf("%s: %s\n", devname, devinfo);
    223       1.1  augustss 
    224  1.11.2.3   nathanw 	sc->sc_flags = uvisor_lookup(uaa->vendor, uaa->product)->uv_flags;
    225  1.11.2.3   nathanw 
    226       1.1  augustss 	id = usbd_get_interface_descriptor(iface);
    227       1.3  augustss 
    228       1.3  augustss 	sc->sc_udev = dev;
    229       1.1  augustss 	sc->sc_iface = iface;
    230       1.1  augustss 
    231       1.4  augustss 	uca.ibufsize = UVISORIBUFSIZE;
    232       1.4  augustss 	uca.obufsize = UVISOROBUFSIZE;
    233       1.5  augustss 	uca.ibufsizepad = UVISORIBUFSIZE;
    234       1.8  augustss 	uca.opkthdrlen = 0;
    235       1.4  augustss 	uca.device = dev;
    236       1.4  augustss 	uca.iface = iface;
    237       1.4  augustss 	uca.methods = &uvisor_methods;
    238       1.4  augustss 	uca.arg = sc;
    239       1.4  augustss 
    240      1.10  augustss 	err = uvisor_init(sc, &coninfo);
    241       1.1  augustss 	if (err) {
    242       1.1  augustss 		printf("%s: init failed, %s\n", USBDEVNAME(sc->sc_dev),
    243       1.1  augustss 		       usbd_errstr(err));
    244       1.1  augustss 		goto bad;
    245       1.1  augustss 	}
    246       1.1  augustss 
    247       1.9  augustss 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
    248       1.9  augustss 			   USBDEV(sc->sc_dev));
    249       1.9  augustss 
    250      1.10  augustss 	sc->sc_numcon = UGETW(coninfo.num_ports);
    251      1.11  augustss 	if (sc->sc_numcon > UVISOR_MAX_CONN)
    252      1.11  augustss 		sc->sc_numcon = UVISOR_MAX_CONN;
    253      1.11  augustss 
    254      1.11  augustss 	/* Attach a ucom for each connection. */
    255      1.10  augustss 	for (i = 0; i < sc->sc_numcon; ++i) {
    256      1.10  augustss 		switch (coninfo.connections[i].port_function_id) {
    257      1.10  augustss 		case UVISOR_FUNCTION_GENERIC:
    258      1.11  augustss 			uca.info = "Generic";
    259      1.10  augustss 			break;
    260      1.10  augustss 		case UVISOR_FUNCTION_DEBUGGER:
    261      1.11  augustss 			uca.info = "Debugger";
    262      1.10  augustss 			break;
    263      1.10  augustss 		case UVISOR_FUNCTION_HOTSYNC:
    264      1.11  augustss 			uca.info = "HotSync";
    265      1.10  augustss 			break;
    266      1.10  augustss 		case UVISOR_FUNCTION_REMOTE_FILE_SYS:
    267      1.11  augustss 			uca.info = "Remote File System";
    268      1.10  augustss 			break;
    269      1.10  augustss 		default:
    270      1.11  augustss 			uca.info = "unknown";
    271  1.11.2.5   nathanw 			break;
    272      1.10  augustss 		}
    273      1.10  augustss 		port = coninfo.connections[i].port;
    274      1.10  augustss 		uca.portno = port;
    275      1.10  augustss 		uca.bulkin = port | UE_DIR_IN;
    276      1.10  augustss 		uca.bulkout = port | UE_DIR_OUT;
    277      1.10  augustss 		/* Verify that endpoints exist. */
    278      1.10  augustss 		for (hasin = hasout = j = 0; j < id->bNumEndpoints; j++) {
    279      1.10  augustss 			ed = usbd_interface2endpoint_descriptor(iface, j);
    280      1.10  augustss 			if (ed == NULL)
    281      1.10  augustss 				break;
    282      1.10  augustss 			if (UE_GET_ADDR(ed->bEndpointAddress) == port &&
    283      1.10  augustss 			    (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
    284      1.10  augustss 				if (UE_GET_DIR(ed->bEndpointAddress)
    285      1.10  augustss 				    == UE_DIR_IN)
    286      1.10  augustss 					hasin++;
    287      1.10  augustss 				else
    288      1.10  augustss 					hasout++;
    289      1.10  augustss 			}
    290      1.10  augustss 		}
    291      1.10  augustss 		if (hasin == 1 && hasout == 1)
    292      1.10  augustss 			sc->sc_subdevs[i] = config_found_sm(self, &uca,
    293      1.10  augustss 			    ucomprint, ucomsubmatch);
    294      1.10  augustss 		else
    295      1.10  augustss 			printf("%s: no proper endpoints for port %d (%d,%d)\n",
    296      1.10  augustss 			    USBDEVNAME(sc->sc_dev), port, hasin, hasout);
    297      1.10  augustss 	}
    298  1.11.2.5   nathanw 
    299       1.1  augustss 	USB_ATTACH_SUCCESS_RETURN;
    300       1.1  augustss 
    301       1.1  augustss bad:
    302       1.1  augustss 	DPRINTF(("uvisor_attach: ATTACH ERROR\n"));
    303       1.1  augustss 	sc->sc_dying = 1;
    304       1.1  augustss 	USB_ATTACH_ERROR_RETURN;
    305       1.1  augustss }
    306       1.1  augustss 
    307       1.1  augustss int
    308       1.7  augustss uvisor_activate(device_ptr_t self, enum devact act)
    309       1.1  augustss {
    310       1.1  augustss 	struct uvisor_softc *sc = (struct uvisor_softc *)self;
    311       1.1  augustss 	int rv = 0;
    312      1.10  augustss 	int i;
    313       1.1  augustss 
    314       1.1  augustss 	switch (act) {
    315       1.1  augustss 	case DVACT_ACTIVATE:
    316       1.1  augustss 		return (EOPNOTSUPP);
    317       1.1  augustss 		break;
    318       1.1  augustss 
    319       1.1  augustss 	case DVACT_DEACTIVATE:
    320      1.10  augustss 		for (i = 0; i < sc->sc_numcon; i++)
    321      1.10  augustss 			if (sc->sc_subdevs[i] != NULL)
    322      1.10  augustss 				rv = config_deactivate(sc->sc_subdevs[i]);
    323       1.1  augustss 		sc->sc_dying = 1;
    324       1.1  augustss 		break;
    325       1.1  augustss 	}
    326       1.1  augustss 	return (rv);
    327       1.1  augustss }
    328       1.1  augustss 
    329       1.1  augustss int
    330       1.7  augustss uvisor_detach(device_ptr_t self, int flags)
    331       1.1  augustss {
    332       1.1  augustss 	struct uvisor_softc *sc = (struct uvisor_softc *)self;
    333       1.1  augustss 	int rv = 0;
    334      1.10  augustss 	int i;
    335       1.1  augustss 
    336       1.1  augustss 	DPRINTF(("uvisor_detach: sc=%p flags=%d\n", sc, flags));
    337       1.1  augustss 	sc->sc_dying = 1;
    338      1.10  augustss 	for (i = 0; i < sc->sc_numcon; i++) {
    339      1.10  augustss 		if (sc->sc_subdevs[i] != NULL) {
    340      1.10  augustss 			rv |= config_detach(sc->sc_subdevs[i], flags);
    341      1.10  augustss 			sc->sc_subdevs[i] = NULL;
    342      1.10  augustss 		}
    343       1.1  augustss 	}
    344       1.9  augustss 
    345       1.9  augustss 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
    346       1.9  augustss 			   USBDEV(sc->sc_dev));
    347       1.9  augustss 
    348       1.9  augustss 
    349      1.10  augustss 	return (rv);
    350       1.1  augustss }
    351       1.1  augustss 
    352       1.1  augustss usbd_status
    353      1.10  augustss uvisor_init(struct uvisor_softc *sc, struct uvisor_connection_info *ci)
    354       1.1  augustss {
    355       1.1  augustss 	usbd_status err;
    356       1.1  augustss 	usb_device_request_t req;
    357       1.1  augustss 	int actlen;
    358       1.1  augustss 	uWord avail;
    359  1.11.2.3   nathanw 	char buffer[256];
    360       1.1  augustss 
    361       1.1  augustss 	DPRINTF(("uvisor_init: getting connection info\n"));
    362       1.1  augustss 	req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
    363       1.1  augustss 	req.bRequest = UVISOR_GET_CONNECTION_INFORMATION;
    364       1.1  augustss 	USETW(req.wValue, 0);
    365       1.1  augustss 	USETW(req.wIndex, 0);
    366       1.1  augustss 	USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
    367      1.10  augustss 	err = usbd_do_request_flags(sc->sc_udev, &req, ci,
    368  1.11.2.2   nathanw 		  USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
    369       1.1  augustss 	if (err)
    370       1.1  augustss 		return (err);
    371  1.11.2.3   nathanw 
    372  1.11.2.3   nathanw 	if (sc->sc_flags & PALM4) {
    373  1.11.2.3   nathanw 		/* Palm OS 4.0 Hack */
    374  1.11.2.3   nathanw 		req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
    375  1.11.2.3   nathanw 		req.bRequest = UVISOR_GET_PALM_INFORMATION;
    376  1.11.2.3   nathanw 		USETW(req.wValue, 0);
    377  1.11.2.3   nathanw 		USETW(req.wIndex, 0);
    378  1.11.2.3   nathanw 		USETW(req.wLength, UVISOR_GET_PALM_INFORMATION_LEN);
    379  1.11.2.3   nathanw 		err = usbd_do_request(sc->sc_udev, &req, buffer);
    380  1.11.2.3   nathanw 		if (err)
    381  1.11.2.3   nathanw 			return (err);
    382  1.11.2.3   nathanw 		req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
    383  1.11.2.3   nathanw 		req.bRequest = UVISOR_GET_PALM_INFORMATION;
    384  1.11.2.3   nathanw 		USETW(req.wValue, 0);
    385  1.11.2.3   nathanw 		USETW(req.wIndex, 0);
    386  1.11.2.3   nathanw 		USETW(req.wLength, UVISOR_GET_PALM_INFORMATION_LEN);
    387  1.11.2.3   nathanw 		err = usbd_do_request(sc->sc_udev, &req, buffer);
    388  1.11.2.3   nathanw 		if (err)
    389  1.11.2.3   nathanw 			return (err);
    390  1.11.2.3   nathanw 	}
    391       1.1  augustss 
    392       1.1  augustss 	DPRINTF(("uvisor_init: getting available bytes\n"));
    393       1.1  augustss 	req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
    394       1.1  augustss 	req.bRequest = UVISOR_REQUEST_BYTES_AVAILABLE;
    395       1.1  augustss 	USETW(req.wValue, 0);
    396       1.1  augustss 	USETW(req.wIndex, 5);
    397       1.1  augustss 	USETW(req.wLength, sizeof avail);
    398       1.1  augustss 	err = usbd_do_request(sc->sc_udev, &req, &avail);
    399       1.1  augustss 	if (err)
    400       1.1  augustss 		return (err);
    401       1.1  augustss 	DPRINTF(("uvisor_init: avail=%d\n", UGETW(avail)));
    402       1.1  augustss 
    403       1.1  augustss 	DPRINTF(("uvisor_init: done\n"));
    404       1.1  augustss 	return (err);
    405       1.1  augustss }
    406       1.1  augustss 
    407       1.1  augustss void
    408       1.7  augustss uvisor_close(void *addr, int portno)
    409       1.1  augustss {
    410       1.1  augustss 	struct uvisor_softc *sc = addr;
    411       1.1  augustss 	usb_device_request_t req;
    412       1.1  augustss 	struct uvisor_connection_info coninfo; /* XXX ? */
    413       1.1  augustss 	int actlen;
    414       1.3  augustss 
    415       1.3  augustss 	if (sc->sc_dying)
    416       1.3  augustss 		return;
    417       1.1  augustss 
    418       1.1  augustss 	req.bmRequestType = UT_READ_VENDOR_ENDPOINT; /* XXX read? */
    419       1.1  augustss 	req.bRequest = UVISOR_CLOSE_NOTIFICATION;
    420       1.1  augustss 	USETW(req.wValue, 0);
    421       1.1  augustss 	USETW(req.wIndex, 0);
    422       1.1  augustss 	USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
    423  1.11.2.5   nathanw 	(void)usbd_do_request_flags(sc->sc_udev, &req, &coninfo,
    424  1.11.2.2   nathanw 		  USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
    425       1.1  augustss }
    426