Home | History | Annotate | Line # | Download | only in usb
uhmodem.c revision 1.3.2.2
      1  1.3.2.2  mjf /*	$NetBSD: uhmodem.c,v 1.3.2.2 2008/02/18 21:06:26 mjf Exp $	*/
      2  1.3.2.2  mjf 
      3  1.3.2.2  mjf /*
      4  1.3.2.2  mjf  * Copyright (c) 2008 Yojiro UO <yuo (at) nui.org>.
      5  1.3.2.2  mjf  * All rights reserved.
      6  1.3.2.2  mjf  *
      7  1.3.2.2  mjf  * Permission to use, copy, modify, and distribute this software for any
      8  1.3.2.2  mjf  * purpose with or without fee is hereby granted, provided that the above
      9  1.3.2.2  mjf  * copyright notice and this permission notice appear in all copies.
     10  1.3.2.2  mjf  *
     11  1.3.2.2  mjf  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12  1.3.2.2  mjf  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13  1.3.2.2  mjf  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14  1.3.2.2  mjf  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15  1.3.2.2  mjf  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
     16  1.3.2.2  mjf  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
     17  1.3.2.2  mjf  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18  1.3.2.2  mjf  */
     19  1.3.2.2  mjf /*-
     20  1.3.2.2  mjf  * Copyright (c) 2002, Alexander Kabaev <kan.FreeBSD.org>.
     21  1.3.2.2  mjf  * All rights reserved.
     22  1.3.2.2  mjf  *
     23  1.3.2.2  mjf  * Redistribution and use in source and binary forms, with or without
     24  1.3.2.2  mjf  * modification, are permitted provided that the following conditions
     25  1.3.2.2  mjf  * are met:
     26  1.3.2.2  mjf  * 1. Redistributions of source code must retain the above copyright
     27  1.3.2.2  mjf  *    notice, this list of conditions and the following disclaimer.
     28  1.3.2.2  mjf  * 2. Redistributions in binary form must reproduce the above copyright
     29  1.3.2.2  mjf  *    notice, this list of conditions and the following disclaimer in the
     30  1.3.2.2  mjf  *    documentation and/or other materials provided with the distribution.
     31  1.3.2.2  mjf  *
     32  1.3.2.2  mjf  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     33  1.3.2.2  mjf  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34  1.3.2.2  mjf  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35  1.3.2.2  mjf  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     36  1.3.2.2  mjf  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  1.3.2.2  mjf  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  1.3.2.2  mjf  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  1.3.2.2  mjf  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40  1.3.2.2  mjf  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41  1.3.2.2  mjf  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42  1.3.2.2  mjf  * SUCH DAMAGE.
     43  1.3.2.2  mjf  */
     44  1.3.2.2  mjf /*
     45  1.3.2.2  mjf  * Copyright (c) 2001 The NetBSD Foundation, Inc.
     46  1.3.2.2  mjf  * All rights reserved.
     47  1.3.2.2  mjf  *
     48  1.3.2.2  mjf  * This code is derived from software contributed to The NetBSD Foundation
     49  1.3.2.2  mjf  * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
     50  1.3.2.2  mjf  *
     51  1.3.2.2  mjf  * Redistribution and use in source and binary forms, with or without
     52  1.3.2.2  mjf  * modification, are permitted provided that the following conditions
     53  1.3.2.2  mjf  * are met:
     54  1.3.2.2  mjf  * 1. Redistributions of source code must retain the above copyright
     55  1.3.2.2  mjf  *    notice, this list of conditions and the following disclaimer.
     56  1.3.2.2  mjf  * 2. Redistributions in binary form must reproduce the above copyright
     57  1.3.2.2  mjf  *    notice, this list of conditions and the following disclaimer in the
     58  1.3.2.2  mjf  *    documentation and/or other materials provided with the distribution.
     59  1.3.2.2  mjf  * 3. All advertising materials mentioning features or use of this software
     60  1.3.2.2  mjf  *    must display the following acknowledgement:
     61  1.3.2.2  mjf  *        This product includes software developed by the NetBSD
     62  1.3.2.2  mjf  *        Foundation, Inc. and its contributors.
     63  1.3.2.2  mjf  * 4. Neither the name of The NetBSD Foundation nor the names of its
     64  1.3.2.2  mjf  *    contributors may be used to endorse or promote products derived
     65  1.3.2.2  mjf  *    from this software without specific prior written permission.
     66  1.3.2.2  mjf  *
     67  1.3.2.2  mjf  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     68  1.3.2.2  mjf  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     69  1.3.2.2  mjf  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     70  1.3.2.2  mjf  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     71  1.3.2.2  mjf  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     72  1.3.2.2  mjf  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     73  1.3.2.2  mjf  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     74  1.3.2.2  mjf  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     75  1.3.2.2  mjf  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     76  1.3.2.2  mjf  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     77  1.3.2.2  mjf  * POSSIBILITY OF SUCH DAMAGE.
     78  1.3.2.2  mjf  */
     79  1.3.2.2  mjf 
     80  1.3.2.2  mjf #include <sys/cdefs.h>
     81  1.3.2.2  mjf __KERNEL_RCSID(0, "$NetBSD: uhmodem.c,v 1.3.2.2 2008/02/18 21:06:26 mjf Exp $");
     82  1.3.2.2  mjf 
     83  1.3.2.2  mjf #include <sys/param.h>
     84  1.3.2.2  mjf #include <sys/systm.h>
     85  1.3.2.2  mjf #include <sys/kernel.h>
     86  1.3.2.2  mjf #include <sys/malloc.h>
     87  1.3.2.2  mjf #include <sys/ioccom.h>
     88  1.3.2.2  mjf #include <sys/fcntl.h>
     89  1.3.2.2  mjf #include <sys/conf.h>
     90  1.3.2.2  mjf #include <sys/tty.h>
     91  1.3.2.2  mjf #include <sys/file.h>
     92  1.3.2.2  mjf #include <sys/select.h>
     93  1.3.2.2  mjf #include <sys/proc.h>
     94  1.3.2.2  mjf #include <sys/device.h>
     95  1.3.2.2  mjf #include <sys/poll.h>
     96  1.3.2.2  mjf #include <sys/sysctl.h>
     97  1.3.2.2  mjf #include <sys/bus.h>
     98  1.3.2.2  mjf 
     99  1.3.2.2  mjf #include <dev/usb/usb.h>
    100  1.3.2.2  mjf #include <dev/usb/usbdi.h>
    101  1.3.2.2  mjf #include <dev/usb/usbdi_util.h>
    102  1.3.2.2  mjf #include <dev/usb/usbdivar.h>
    103  1.3.2.2  mjf 
    104  1.3.2.2  mjf #include <dev/usb/usbcdc.h>
    105  1.3.2.2  mjf #include <dev/usb/usbdevs.h>
    106  1.3.2.2  mjf #include <dev/usb/usb_quirks.h>
    107  1.3.2.2  mjf #include <dev/usb/ucomvar.h>
    108  1.3.2.2  mjf #include <dev/usb/ubsavar.h>
    109  1.3.2.2  mjf 
    110  1.3.2.2  mjf /* vendor specific bRequest */
    111  1.3.2.2  mjf #define	UHMODEM_REGWRITE	0x20
    112  1.3.2.2  mjf #define	UHMODEM_REGREAD		0x21
    113  1.3.2.2  mjf #define UHMODEM_SETUP		0x22
    114  1.3.2.2  mjf 
    115  1.3.2.2  mjf #define UHMODEMIBUFSIZE	4096
    116  1.3.2.2  mjf #define UHMODEMOBUFSIZE	4096
    117  1.3.2.2  mjf 
    118  1.3.2.2  mjf #ifdef UHMODEM_DEBUG
    119  1.3.2.2  mjf Static int	uhmodemdebug = 0;
    120  1.3.2.2  mjf #define DPRINTFN(n, x)  do { \
    121  1.3.2.2  mjf 				if (uhmodemdebug > (n)) \
    122  1.3.2.2  mjf 					logprintf x; \
    123  1.3.2.2  mjf 			} while (0)
    124  1.3.2.2  mjf #else
    125  1.3.2.2  mjf #define DPRINTFN(n, x)
    126  1.3.2.2  mjf #endif
    127  1.3.2.2  mjf #define DPRINTF(x) DPRINTFN(0, x)
    128  1.3.2.2  mjf 
    129  1.3.2.2  mjf Static int uhmodem_open(void *, int);
    130  1.3.2.2  mjf Static  usbd_status e220_modechange_request(usbd_device_handle);
    131  1.3.2.2  mjf Static	usbd_status uhmodem_endpointhalt(struct ubsa_softc *, int);
    132  1.3.2.2  mjf Static	usbd_status uhmodem_regwrite(usbd_device_handle, uint8_t *, size_t);
    133  1.3.2.2  mjf Static	usbd_status uhmodem_regread(usbd_device_handle, uint8_t *, size_t);
    134  1.3.2.2  mjf Static  usbd_status a2502_init(usbd_device_handle);
    135  1.3.2.2  mjf #if 0
    136  1.3.2.2  mjf Static	usbd_status uhmodem_regsetup(usbd_device_handle, uint16_t);
    137  1.3.2.2  mjf Static  usbd_status e220_init(usbd_device_handle);
    138  1.3.2.2  mjf #endif
    139  1.3.2.2  mjf 
    140  1.3.2.2  mjf struct	uhmodem_softc {
    141  1.3.2.2  mjf 	struct ubsa_softc	sc_ubsa;
    142  1.3.2.2  mjf };
    143  1.3.2.2  mjf 
    144  1.3.2.2  mjf struct	ucom_methods uhmodem_methods = {
    145  1.3.2.2  mjf 	ubsa_get_status,
    146  1.3.2.2  mjf 	ubsa_set,
    147  1.3.2.2  mjf 	ubsa_param,
    148  1.3.2.2  mjf 	NULL,
    149  1.3.2.2  mjf 	uhmodem_open,
    150  1.3.2.2  mjf 	ubsa_close,
    151  1.3.2.2  mjf 	NULL,
    152  1.3.2.2  mjf 	NULL
    153  1.3.2.2  mjf };
    154  1.3.2.2  mjf 
    155  1.3.2.2  mjf struct uhmodem_type {
    156  1.3.2.2  mjf 	struct usb_devno	uhmodem_dev;
    157  1.3.2.2  mjf 	u_int16_t		uhmodem_coms;	/* number of serial interfaces on the device */
    158  1.3.2.2  mjf 	u_int16_t		uhmodem_flags;
    159  1.3.2.2  mjf #define	E220	0x0001
    160  1.3.2.2  mjf #define	A2502	0x0002
    161  1.3.2.2  mjf };
    162  1.3.2.2  mjf 
    163  1.3.2.2  mjf Static const struct uhmodem_type uhmodem_devs[] = {
    164  1.3.2.2  mjf 	/* HUAWEI E220 / Emobile D0[12]HW */
    165  1.3.2.2  mjf 	{{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E220 }, 2,	E220},
    166  1.3.2.2  mjf 	/* ANYDATA / NTT DoCoMo A2502 */
    167  1.3.2.2  mjf 	{{ USB_VENDOR_ANYDATA, USB_PRODUCT_ANYDATA_A2502 }, 3,	A2502},
    168  1.3.2.2  mjf };
    169  1.3.2.2  mjf #define uhmodem_lookup(v, p) ((const struct uhmodem_type *)usb_lookup(uhmodem_devs, v, p))
    170  1.3.2.2  mjf 
    171  1.3.2.2  mjf int uhmodem_match(device_t, struct cfdata *, void *);
    172  1.3.2.2  mjf void uhmodem_attach(device_t, device_t, void *);
    173  1.3.2.2  mjf void uhmodem_childdet(device_t, device_t);
    174  1.3.2.2  mjf int uhmodem_detach(device_t, int);
    175  1.3.2.2  mjf int uhmodem_activate(device_t, enum devact);
    176  1.3.2.2  mjf extern struct cfdriver uhmodem_cd;
    177  1.3.2.2  mjf CFATTACH_DECL2(uhmodem, sizeof(struct uhmodem_softc), uhmodem_match,
    178  1.3.2.2  mjf     uhmodem_attach, uhmodem_detach, uhmodem_activate, NULL, uhmodem_childdet);
    179  1.3.2.2  mjf 
    180  1.3.2.2  mjf USB_MATCH(uhmodem)
    181  1.3.2.2  mjf {
    182  1.3.2.2  mjf 	USB_IFMATCH_START(uhmodem, uaa);
    183  1.3.2.2  mjf 
    184  1.3.2.2  mjf 	if (uhmodem_lookup(uaa->vendor, uaa->product) != NULL)
    185  1.3.2.2  mjf 		/* XXX interface# 0,1 provide modem function, but this driver
    186  1.3.2.2  mjf 		   handles all modem in single device.  */
    187  1.3.2.2  mjf 		if (uaa->ifaceno == 0)
    188  1.3.2.2  mjf 			return (UMATCH_VENDOR_PRODUCT);
    189  1.3.2.2  mjf 	return (UMATCH_NONE);
    190  1.3.2.2  mjf }
    191  1.3.2.2  mjf 
    192  1.3.2.2  mjf USB_ATTACH(uhmodem)
    193  1.3.2.2  mjf {
    194  1.3.2.2  mjf 	USB_IFATTACH_START(uhmodem, sc, uaa);
    195  1.3.2.2  mjf 	usbd_device_handle dev = uaa->device;
    196  1.3.2.2  mjf 	usb_config_descriptor_t *cdesc;
    197  1.3.2.2  mjf 	usb_interface_descriptor_t *id;
    198  1.3.2.2  mjf 	usb_endpoint_descriptor_t *ed;
    199  1.3.2.2  mjf 	char *devinfop;
    200  1.3.2.2  mjf 	const char *devname = USBDEVNAME(sc->sc_ubsa.sc_dev);
    201  1.3.2.2  mjf 	usbd_status err;
    202  1.3.2.2  mjf 	struct ucom_attach_args uca;
    203  1.3.2.2  mjf 	int i;
    204  1.3.2.2  mjf 	int j;
    205  1.3.2.2  mjf 	char comname[16];
    206  1.3.2.2  mjf 
    207  1.3.2.2  mjf 	devinfop = usbd_devinfo_alloc(dev, 0);
    208  1.3.2.2  mjf 	USB_ATTACH_SETUP;
    209  1.3.2.2  mjf 	printf("%s: %s\n", devname, devinfop);
    210  1.3.2.2  mjf 	usbd_devinfo_free(devinfop);
    211  1.3.2.2  mjf 
    212  1.3.2.2  mjf         sc->sc_ubsa.sc_udev = dev;
    213  1.3.2.2  mjf 	sc->sc_ubsa.sc_config_index = UBSA_DEFAULT_CONFIG_INDEX;
    214  1.3.2.2  mjf 	sc->sc_ubsa.sc_numif = 1; /* defaut device has one interface */
    215  1.3.2.2  mjf 
    216  1.3.2.2  mjf 	/* Hauwei E220 need special request to change its mode to modem */
    217  1.3.2.2  mjf 	if ((uaa->ifaceno == 0) && (uaa->class != 255)) {
    218  1.3.2.2  mjf 		err = e220_modechange_request(dev);
    219  1.3.2.2  mjf 		if (err) {
    220  1.3.2.2  mjf 			printf("%s: failed to change mode: %s\n",
    221  1.3.2.2  mjf 				devname, usbd_errstr(err));
    222  1.3.2.2  mjf 			sc->sc_ubsa.sc_dying = 1;
    223  1.3.2.2  mjf 			goto error;
    224  1.3.2.2  mjf 		}
    225  1.3.2.2  mjf 		printf("%s: mass storage only mode, reattach to enable modem\n",
    226  1.3.2.2  mjf 			devname);
    227  1.3.2.2  mjf 		sc->sc_ubsa.sc_dying = 1;
    228  1.3.2.2  mjf 		goto error;
    229  1.3.2.2  mjf 	}
    230  1.3.2.2  mjf 
    231  1.3.2.2  mjf 	/*
    232  1.3.2.2  mjf 	 * initialize rts, dtr variables to something
    233  1.3.2.2  mjf 	 * different from boolean 0, 1
    234  1.3.2.2  mjf 	 */
    235  1.3.2.2  mjf 	sc->sc_ubsa.sc_dtr = -1;
    236  1.3.2.2  mjf 	sc->sc_ubsa.sc_rts = -1;
    237  1.3.2.2  mjf 
    238  1.3.2.2  mjf 	sc->sc_ubsa.sc_quadumts = 1;
    239  1.3.2.2  mjf 	sc->sc_ubsa.sc_config_index = 0;
    240  1.3.2.2  mjf 	sc->sc_ubsa.sc_numif = uhmodem_lookup(uaa->vendor, uaa->product)->uhmodem_coms;
    241  1.3.2.2  mjf 	sc->sc_ubsa.sc_devflags = uhmodem_lookup(uaa->vendor, uaa->product)->uhmodem_flags;
    242  1.3.2.2  mjf 
    243  1.3.2.2  mjf 	DPRINTF(("uhmodem attach: sc = %p\n", sc));
    244  1.3.2.2  mjf 
    245  1.3.2.2  mjf 	/* Move the device into the configured state. */
    246  1.3.2.2  mjf 	err = usbd_set_config_index(dev, sc->sc_ubsa.sc_config_index, 1);
    247  1.3.2.2  mjf 	if (err) {
    248  1.3.2.2  mjf 		printf("%s: failed to set configuration: %s\n",
    249  1.3.2.2  mjf 		    devname, usbd_errstr(err));
    250  1.3.2.2  mjf 		sc->sc_ubsa.sc_dying = 1;
    251  1.3.2.2  mjf 		goto error;
    252  1.3.2.2  mjf 	}
    253  1.3.2.2  mjf 
    254  1.3.2.2  mjf 	/* get the config descriptor */
    255  1.3.2.2  mjf 	cdesc = usbd_get_config_descriptor(sc->sc_ubsa.sc_udev);
    256  1.3.2.2  mjf 	if (cdesc == NULL) {
    257  1.3.2.2  mjf 		printf("%s: failed to get configuration descriptor\n",
    258  1.3.2.2  mjf 		    devname);
    259  1.3.2.2  mjf 		sc->sc_ubsa.sc_dying = 1;
    260  1.3.2.2  mjf 		goto error;
    261  1.3.2.2  mjf 	}
    262  1.3.2.2  mjf 
    263  1.3.2.2  mjf 	sc->sc_ubsa.sc_intr_number = -1;
    264  1.3.2.2  mjf 	sc->sc_ubsa.sc_intr_pipe = NULL;
    265  1.3.2.2  mjf 
    266  1.3.2.2  mjf 	/* get the interfaces */
    267  1.3.2.2  mjf 	for (i = 0; i < sc->sc_ubsa.sc_numif; i++) {
    268  1.3.2.2  mjf 		err = usbd_device2interface_handle(dev, UBSA_IFACE_INDEX_OFFSET+i,
    269  1.3.2.2  mjf 				 &sc->sc_ubsa.sc_iface[i]);
    270  1.3.2.2  mjf 		if (err) {
    271  1.3.2.2  mjf 			if (i == 0){
    272  1.3.2.2  mjf 				/* can not get main interface */
    273  1.3.2.2  mjf 				sc->sc_ubsa.sc_dying = 1;
    274  1.3.2.2  mjf 				goto error;
    275  1.3.2.2  mjf 			} else
    276  1.3.2.2  mjf 				break;
    277  1.3.2.2  mjf 		}
    278  1.3.2.2  mjf 
    279  1.3.2.2  mjf 		/* Find the endpoints */
    280  1.3.2.2  mjf 		id = usbd_get_interface_descriptor(sc->sc_ubsa.sc_iface[i]);
    281  1.3.2.2  mjf 		sc->sc_ubsa.sc_iface_number[i] = id->bInterfaceNumber;
    282  1.3.2.2  mjf 
    283  1.3.2.2  mjf 		/* initialize endpoints */
    284  1.3.2.2  mjf 		uca.bulkin = uca.bulkout = -1;
    285  1.3.2.2  mjf 
    286  1.3.2.2  mjf 		for (j = 0; j < id->bNumEndpoints; j++) {
    287  1.3.2.2  mjf 			ed = usbd_interface2endpoint_descriptor(
    288  1.3.2.2  mjf 				sc->sc_ubsa.sc_iface[i], j);
    289  1.3.2.2  mjf 			if (ed == NULL) {
    290  1.3.2.2  mjf 				printf("%s: no endpoint descriptor for %d (interface: %d)\n",
    291  1.3.2.2  mjf 			    		devname, j, i);
    292  1.3.2.2  mjf 				break;
    293  1.3.2.2  mjf 			}
    294  1.3.2.2  mjf 
    295  1.3.2.2  mjf 			if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    296  1.3.2.2  mjf 			    UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
    297  1.3.2.2  mjf 				sc->sc_ubsa.sc_intr_number = ed->bEndpointAddress;
    298  1.3.2.2  mjf 				sc->sc_ubsa.sc_isize = UGETW(ed->wMaxPacketSize);
    299  1.3.2.2  mjf 			} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    300  1.3.2.2  mjf 			    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
    301  1.3.2.2  mjf 				uca.bulkin = ed->bEndpointAddress;
    302  1.3.2.2  mjf 			} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
    303  1.3.2.2  mjf 			    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
    304  1.3.2.2  mjf 				uca.bulkout = ed->bEndpointAddress;
    305  1.3.2.2  mjf 			}
    306  1.3.2.2  mjf 		} /* end of Endpoint loop */
    307  1.3.2.2  mjf 
    308  1.3.2.2  mjf 		if (sc->sc_ubsa.sc_intr_number == -1) {
    309  1.3.2.2  mjf 			printf("%s: HUAWEI E220 need to re-attach to enable modem function\n", devname);
    310  1.3.2.2  mjf 			if (i == 0) {
    311  1.3.2.2  mjf 				/* could not get intr for main tty */
    312  1.3.2.2  mjf 				sc->sc_ubsa.sc_dying = 1;
    313  1.3.2.2  mjf 				goto error;
    314  1.3.2.2  mjf 			} else
    315  1.3.2.2  mjf 				break;
    316  1.3.2.2  mjf 		}
    317  1.3.2.2  mjf 		if (uca.bulkin == -1) {
    318  1.3.2.2  mjf 			printf("%s: Could not find data bulk in\n", devname);
    319  1.3.2.2  mjf 			sc->sc_ubsa.sc_dying = 1;
    320  1.3.2.2  mjf 			goto error;
    321  1.3.2.2  mjf 		}
    322  1.3.2.2  mjf 
    323  1.3.2.2  mjf 		if (uca.bulkout == -1) {
    324  1.3.2.2  mjf 			printf("%s: Could not find data bulk out\n", devname);
    325  1.3.2.2  mjf 			sc->sc_ubsa.sc_dying = 1;
    326  1.3.2.2  mjf 			goto error;
    327  1.3.2.2  mjf 		}
    328  1.3.2.2  mjf 
    329  1.3.2.2  mjf 		switch (i) {
    330  1.3.2.2  mjf 		case 0:
    331  1.3.2.2  mjf 			sprintf(comname, "modem");
    332  1.3.2.2  mjf 			break;
    333  1.3.2.2  mjf 		case 1:
    334  1.3.2.2  mjf 			sprintf(comname, "alt#1");
    335  1.3.2.2  mjf 			break;
    336  1.3.2.2  mjf 		case 2:
    337  1.3.2.2  mjf 			sprintf(comname, "alt#2");
    338  1.3.2.2  mjf 			break;
    339  1.3.2.2  mjf 		default:
    340  1.3.2.2  mjf 			sprintf(comname, "int#%d", i);
    341  1.3.2.2  mjf 		}
    342  1.3.2.2  mjf 
    343  1.3.2.2  mjf 		uca.portno = i;
    344  1.3.2.2  mjf 		/* bulkin, bulkout set above */
    345  1.3.2.2  mjf 		uca.ibufsize = UHMODEMIBUFSIZE;
    346  1.3.2.2  mjf 		uca.obufsize = UHMODEMOBUFSIZE;
    347  1.3.2.2  mjf 		uca.ibufsizepad = UHMODEMIBUFSIZE;
    348  1.3.2.2  mjf 		uca.opkthdrlen = 0;
    349  1.3.2.2  mjf 		uca.device = dev;
    350  1.3.2.2  mjf 		uca.iface = sc->sc_ubsa.sc_iface[i];
    351  1.3.2.2  mjf 		uca.methods = &uhmodem_methods;
    352  1.3.2.2  mjf 		uca.arg = &sc->sc_ubsa;
    353  1.3.2.2  mjf 		uca.info = comname;
    354  1.3.2.2  mjf 		DPRINTF(("uhmodem: int#=%d, in = 0x%x, out = 0x%x, intr = 0x%x\n",
    355  1.3.2.2  mjf 	    		i, uca.bulkin, uca.bulkout, sc->sc_ubsa.sc_intr_number));
    356  1.3.2.2  mjf 		sc->sc_ubsa.sc_subdevs[i] = config_found_sm_loc(self, "ucombus", NULL,
    357  1.3.2.2  mjf 				 &uca, ucomprint, ucomsubmatch);
    358  1.3.2.2  mjf 
    359  1.3.2.2  mjf 		/* issue endpoint halt to each interface */
    360  1.3.2.2  mjf 		err = uhmodem_endpointhalt(&sc->sc_ubsa, i);
    361  1.3.2.2  mjf 		if (err)
    362  1.3.2.2  mjf 			printf("%s: endpointhalt fail\n", __func__);
    363  1.3.2.2  mjf 		else
    364  1.3.2.2  mjf 			usbd_delay_ms(sc->sc_ubsa.sc_udev, 50);
    365  1.3.2.2  mjf 	} /* end of Interface loop */
    366  1.3.2.2  mjf 
    367  1.3.2.2  mjf 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_ubsa.sc_udev,
    368  1.3.2.2  mjf 			   USBDEV(sc->sc_ubsa.sc_dev));
    369  1.3.2.2  mjf 
    370  1.3.2.2  mjf 	USB_ATTACH_SUCCESS_RETURN;
    371  1.3.2.2  mjf 
    372  1.3.2.2  mjf error:
    373  1.3.2.2  mjf 	USB_ATTACH_ERROR_RETURN;
    374  1.3.2.2  mjf }
    375  1.3.2.2  mjf 
    376  1.3.2.2  mjf void
    377  1.3.2.2  mjf uhmodem_childdet(device_t self, device_t child)
    378  1.3.2.2  mjf {
    379  1.3.2.2  mjf 	int i;
    380  1.3.2.2  mjf 	struct uhmodem_softc *sc = device_private(self);
    381  1.3.2.2  mjf 
    382  1.3.2.2  mjf 	for (i = 0; i < sc->sc_ubsa.sc_numif; i++) {
    383  1.3.2.2  mjf 		if (sc->sc_ubsa.sc_subdevs[i] == child)
    384  1.3.2.2  mjf 			break;
    385  1.3.2.2  mjf 	}
    386  1.3.2.2  mjf 	KASSERT(i < sc->sc_ubsa.sc_numif);
    387  1.3.2.2  mjf 	sc->sc_ubsa.sc_subdevs[i] = NULL;
    388  1.3.2.2  mjf }
    389  1.3.2.2  mjf 
    390  1.3.2.2  mjf USB_DETACH(uhmodem)
    391  1.3.2.2  mjf {
    392  1.3.2.2  mjf 	USB_DETACH_START(uhmodem, sc);
    393  1.3.2.2  mjf 	int i;
    394  1.3.2.2  mjf 	int rv = 0;
    395  1.3.2.2  mjf 
    396  1.3.2.2  mjf 	DPRINTF(("uhmodem_detach: sc = %p\n", sc));
    397  1.3.2.2  mjf 
    398  1.3.2.2  mjf 	if (sc->sc_ubsa.sc_intr_pipe != NULL) {
    399  1.3.2.2  mjf 		usbd_abort_pipe(sc->sc_ubsa.sc_intr_pipe);
    400  1.3.2.2  mjf 		usbd_close_pipe(sc->sc_ubsa.sc_intr_pipe);
    401  1.3.2.2  mjf 		free(sc->sc_ubsa.sc_intr_buf, M_USBDEV);
    402  1.3.2.2  mjf 		sc->sc_ubsa.sc_intr_pipe = NULL;
    403  1.3.2.2  mjf 	}
    404  1.3.2.2  mjf 
    405  1.3.2.2  mjf 	sc->sc_ubsa.sc_dying = 1;
    406  1.3.2.2  mjf 	for (i = 0; i < sc->sc_ubsa.sc_numif; i++) {
    407  1.3.2.2  mjf 		if (sc->sc_ubsa.sc_subdevs[i] != NULL)
    408  1.3.2.2  mjf 			rv |= config_detach(sc->sc_ubsa.sc_subdevs[i], flags);
    409  1.3.2.2  mjf 	}
    410  1.3.2.2  mjf 
    411  1.3.2.2  mjf 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_ubsa.sc_udev,
    412  1.3.2.2  mjf 			   USBDEV(sc->sc_ubsa.sc_dev));
    413  1.3.2.2  mjf 
    414  1.3.2.2  mjf 	return (rv);
    415  1.3.2.2  mjf }
    416  1.3.2.2  mjf 
    417  1.3.2.2  mjf int
    418  1.3.2.2  mjf uhmodem_activate(device_t self, enum devact act)
    419  1.3.2.2  mjf {
    420  1.3.2.2  mjf 	struct uhmodem_softc *sc = device_private(self);
    421  1.3.2.2  mjf 	int rv = 0;
    422  1.3.2.2  mjf 	int i;
    423  1.3.2.2  mjf 
    424  1.3.2.2  mjf 	switch (act) {
    425  1.3.2.2  mjf 	case DVACT_ACTIVATE:
    426  1.3.2.2  mjf 		return (EOPNOTSUPP);
    427  1.3.2.2  mjf 
    428  1.3.2.2  mjf 	case DVACT_DEACTIVATE:
    429  1.3.2.2  mjf 		for (i = 0; i < sc->sc_ubsa.sc_numif; i++) {
    430  1.3.2.2  mjf 			if (sc->sc_ubsa.sc_subdevs[i] != NULL)
    431  1.3.2.2  mjf 				rv |= config_deactivate(sc->sc_ubsa.sc_subdevs[i]);
    432  1.3.2.2  mjf 		}
    433  1.3.2.2  mjf 		sc->sc_ubsa.sc_dying = 1;
    434  1.3.2.2  mjf 		break;
    435  1.3.2.2  mjf 	}
    436  1.3.2.2  mjf 	return (rv);
    437  1.3.2.2  mjf }
    438  1.3.2.2  mjf 
    439  1.3.2.2  mjf Static int
    440  1.3.2.2  mjf uhmodem_open(void *addr, int portno)
    441  1.3.2.2  mjf {
    442  1.3.2.2  mjf 	struct ubsa_softc *sc = addr;
    443  1.3.2.2  mjf 	usbd_status err;
    444  1.3.2.2  mjf 
    445  1.3.2.2  mjf 	if (sc->sc_dying)
    446  1.3.2.2  mjf 		return (ENXIO);
    447  1.3.2.2  mjf 
    448  1.3.2.2  mjf 	DPRINTF(("%s: sc = %p\n", __func__, sc));
    449  1.3.2.2  mjf 
    450  1.3.2.2  mjf 	err = uhmodem_endpointhalt(sc, 0);
    451  1.3.2.2  mjf 	if (err)
    452  1.3.2.2  mjf 		printf("%s: endpointhalt fail\n", __func__);
    453  1.3.2.2  mjf 	else
    454  1.3.2.2  mjf 		usbd_delay_ms(sc->sc_udev, 50);
    455  1.3.2.2  mjf 
    456  1.3.2.2  mjf 	if (sc->sc_devflags & A2502) {
    457  1.3.2.2  mjf 		err = a2502_init(sc->sc_udev);
    458  1.3.2.2  mjf 		if (err)
    459  1.3.2.2  mjf 			printf("%s: a2502init fail\n", __func__);
    460  1.3.2.2  mjf 		else
    461  1.3.2.2  mjf 			usbd_delay_ms(sc->sc_udev, 50);
    462  1.3.2.2  mjf 	}
    463  1.3.2.2  mjf #if 0 /* currently disabled */
    464  1.3.2.2  mjf 	if (sc->sc_devflags & E220) {
    465  1.3.2.2  mjf 		err = e220_init(sc->sc_udev);
    466  1.3.2.2  mjf 		if (err)
    467  1.3.2.2  mjf 			printf("%s: e220init fail\n", __func__);
    468  1.3.2.2  mjf 		else
    469  1.3.2.2  mjf 			usbd_delay_ms(sc->sc_udev, 50);
    470  1.3.2.2  mjf 	}
    471  1.3.2.2  mjf #endif
    472  1.3.2.2  mjf 	if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
    473  1.3.2.2  mjf 		sc->sc_intr_buf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK);
    474  1.3.2.2  mjf 		/* XXX only iface# = 0 has intr line */
    475  1.3.2.2  mjf 		/* XXX E220 specific? need to check */
    476  1.3.2.2  mjf 		err = usbd_open_pipe_intr(sc->sc_iface[0],
    477  1.3.2.2  mjf 		    sc->sc_intr_number,
    478  1.3.2.2  mjf 		    USBD_SHORT_XFER_OK,
    479  1.3.2.2  mjf 		    &sc->sc_intr_pipe,
    480  1.3.2.2  mjf 		    sc,
    481  1.3.2.2  mjf 		    sc->sc_intr_buf,
    482  1.3.2.2  mjf 		    sc->sc_isize,
    483  1.3.2.2  mjf 		    ubsa_intr,
    484  1.3.2.2  mjf 		    UBSA_INTR_INTERVAL);
    485  1.3.2.2  mjf 		if (err) {
    486  1.3.2.2  mjf 			printf("%s: cannot open interrupt pipe (addr %d)\n",
    487  1.3.2.2  mjf 			    USBDEVNAME(sc->sc_dev),
    488  1.3.2.2  mjf 			    sc->sc_intr_number);
    489  1.3.2.2  mjf 			return (EIO);
    490  1.3.2.2  mjf 		}
    491  1.3.2.2  mjf 	}
    492  1.3.2.2  mjf 
    493  1.3.2.2  mjf 	return (0);
    494  1.3.2.2  mjf }
    495  1.3.2.2  mjf 
    496  1.3.2.2  mjf /*
    497  1.3.2.2  mjf  * Hauwei E220 needs special request to enable modem function.
    498  1.3.2.2  mjf  * -- DEVICE_REMOTE_WAKEUP ruquest to endpoint 2.
    499  1.3.2.2  mjf  */
    500  1.3.2.2  mjf Static  usbd_status
    501  1.3.2.2  mjf e220_modechange_request(usbd_device_handle dev)
    502  1.3.2.2  mjf {
    503  1.3.2.2  mjf #define E220_MODE_CHANGE_REQUEST 0x2
    504  1.3.2.2  mjf 	usb_device_request_t req;
    505  1.3.2.2  mjf 	usbd_status err;
    506  1.3.2.2  mjf 
    507  1.3.2.2  mjf 	req.bmRequestType = UT_WRITE_DEVICE;
    508  1.3.2.2  mjf 	req.bRequest = UR_SET_FEATURE;
    509  1.3.2.2  mjf 	USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP);
    510  1.3.2.2  mjf 	USETW(req.wIndex, E220_MODE_CHANGE_REQUEST);
    511  1.3.2.2  mjf 	USETW(req.wLength, 0);
    512  1.3.2.2  mjf 
    513  1.3.2.2  mjf 	DPRINTF(("%s: send e220 mode change request\n", __func__));
    514  1.3.2.2  mjf 	err = usbd_do_request(dev, &req, 0);
    515  1.3.2.2  mjf 	if (err) {
    516  1.3.2.2  mjf 		DPRINTF(("%s: E220 mode change fail\n", __func__));
    517  1.3.2.2  mjf 		return (EIO);
    518  1.3.2.2  mjf 	}
    519  1.3.2.2  mjf 
    520  1.3.2.2  mjf 	return (0);
    521  1.3.2.2  mjf #undef E220_MODE_CHANGE_REQUEST
    522  1.3.2.2  mjf }
    523  1.3.2.2  mjf 
    524  1.3.2.2  mjf Static  usbd_status
    525  1.3.2.2  mjf uhmodem_endpointhalt(struct ubsa_softc *sc, int iface)
    526  1.3.2.2  mjf {
    527  1.3.2.2  mjf 	usb_device_request_t req;
    528  1.3.2.2  mjf 	usb_endpoint_descriptor_t *ed;
    529  1.3.2.2  mjf 	usb_interface_descriptor_t *id;
    530  1.3.2.2  mjf 	usbd_status err;
    531  1.3.2.2  mjf 	int i;
    532  1.3.2.2  mjf 
    533  1.3.2.2  mjf 	/* Find the endpoints */
    534  1.3.2.2  mjf 	id = usbd_get_interface_descriptor(sc->sc_iface[iface]);
    535  1.3.2.2  mjf 
    536  1.3.2.2  mjf 	for (i = 0; i < id->bNumEndpoints; i++) {
    537  1.3.2.2  mjf 		ed = usbd_interface2endpoint_descriptor(sc->sc_iface[iface], i);
    538  1.3.2.2  mjf 		if (ed == NULL)
    539  1.3.2.2  mjf 			return (EIO);
    540  1.3.2.2  mjf 
    541  1.3.2.2  mjf 		if (UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
    542  1.3.2.2  mjf 			/* issue ENDPOINT_HALT request */
    543  1.3.2.2  mjf 			req.bmRequestType = UT_WRITE_ENDPOINT;
    544  1.3.2.2  mjf 			req.bRequest = UR_CLEAR_FEATURE;
    545  1.3.2.2  mjf 			USETW(req.wValue, UF_ENDPOINT_HALT);
    546  1.3.2.2  mjf 			USETW(req.wIndex, ed->bEndpointAddress);
    547  1.3.2.2  mjf 			USETW(req.wLength, 0);
    548  1.3.2.2  mjf 			err = usbd_do_request(sc->sc_udev, &req, 0);
    549  1.3.2.2  mjf 			if (err) {
    550  1.3.2.2  mjf 				DPRINTF(("%s: ENDPOINT_HALT to EP:%d fail\n",
    551  1.3.2.2  mjf 					__func__, ed->bEndpointAddress));
    552  1.3.2.2  mjf 				return (EIO);
    553  1.3.2.2  mjf 			}
    554  1.3.2.2  mjf 
    555  1.3.2.2  mjf 		}
    556  1.3.2.2  mjf 	} /* end of Endpoint loop */
    557  1.3.2.2  mjf 
    558  1.3.2.2  mjf 	return (0);
    559  1.3.2.2  mjf }
    560  1.3.2.2  mjf 
    561  1.3.2.2  mjf Static usbd_status
    562  1.3.2.2  mjf uhmodem_regwrite(usbd_device_handle dev, uint8_t *data, size_t len)
    563  1.3.2.2  mjf {
    564  1.3.2.2  mjf 	usb_device_request_t req;
    565  1.3.2.2  mjf 	usbd_status err;
    566  1.3.2.2  mjf 
    567  1.3.2.2  mjf 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    568  1.3.2.2  mjf 	req.bRequest = UHMODEM_REGWRITE;
    569  1.3.2.2  mjf 	USETW(req.wValue, 0x0000);
    570  1.3.2.2  mjf 	USETW(req.wIndex, 0x0000);
    571  1.3.2.2  mjf 	USETW(req.wLength, len);
    572  1.3.2.2  mjf 	err = usbd_do_request(dev, &req, data);
    573  1.3.2.2  mjf 	if (err)
    574  1.3.2.2  mjf 		return err;
    575  1.3.2.2  mjf 
    576  1.3.2.2  mjf 	return 0;
    577  1.3.2.2  mjf }
    578  1.3.2.2  mjf 
    579  1.3.2.2  mjf Static usbd_status
    580  1.3.2.2  mjf uhmodem_regread(usbd_device_handle dev, uint8_t *data, size_t len)
    581  1.3.2.2  mjf {
    582  1.3.2.2  mjf 	usb_device_request_t req;
    583  1.3.2.2  mjf 	usbd_status err;
    584  1.3.2.2  mjf 
    585  1.3.2.2  mjf 	req.bmRequestType = UT_READ_CLASS_INTERFACE;
    586  1.3.2.2  mjf 	req.bRequest = UHMODEM_REGREAD;
    587  1.3.2.2  mjf 	USETW(req.wValue, 0x0000);
    588  1.3.2.2  mjf 	USETW(req.wIndex, 0x0000);
    589  1.3.2.2  mjf 	USETW(req.wLength, len);
    590  1.3.2.2  mjf 	err = usbd_do_request(dev, &req, data);
    591  1.3.2.2  mjf 
    592  1.3.2.2  mjf 	if (err)
    593  1.3.2.2  mjf 		return err;
    594  1.3.2.2  mjf 
    595  1.3.2.2  mjf 	return 0;
    596  1.3.2.2  mjf }
    597  1.3.2.2  mjf 
    598  1.3.2.2  mjf #if 0
    599  1.3.2.2  mjf Static usbd_status
    600  1.3.2.2  mjf uhmodem_regsetup(usbd_device_handle dev, uint16_t cmd)
    601  1.3.2.2  mjf {
    602  1.3.2.2  mjf 	usb_device_request_t req;
    603  1.3.2.2  mjf 	usbd_status err;
    604  1.3.2.2  mjf 
    605  1.3.2.2  mjf 	req.bmRequestType = UT_READ_CLASS_INTERFACE;
    606  1.3.2.2  mjf 	req.bRequest = UHMODEM_SETUP;
    607  1.3.2.2  mjf 	USETW(req.wValue, cmd);
    608  1.3.2.2  mjf 	USETW(req.wIndex, 0x0000);
    609  1.3.2.2  mjf 	USETW(req.wLength, 0);
    610  1.3.2.2  mjf 	err = usbd_do_request(dev, &req, 0);
    611  1.3.2.2  mjf 
    612  1.3.2.2  mjf 	if (err)
    613  1.3.2.2  mjf 		return err;
    614  1.3.2.2  mjf 
    615  1.3.2.2  mjf 	return 0;
    616  1.3.2.2  mjf }
    617  1.3.2.2  mjf #endif
    618  1.3.2.2  mjf 
    619  1.3.2.2  mjf Static  usbd_status
    620  1.3.2.2  mjf a2502_init(usbd_device_handle dev)
    621  1.3.2.2  mjf {
    622  1.3.2.2  mjf 	uint8_t data[8];
    623  1.3.2.2  mjf 	static uint8_t init_cmd[] = {0x00, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x08};
    624  1.3.2.2  mjf #ifdef UHMODEM_DEBUG
    625  1.3.2.2  mjf 	int i;
    626  1.3.2.2  mjf #endif
    627  1.3.2.2  mjf 	if (uhmodem_regread(dev, data, 7)) {
    628  1.3.2.2  mjf 		DPRINTF(("%s: read fail\n", __func__));
    629  1.3.2.2  mjf 		return EIO;
    630  1.3.2.2  mjf 	}
    631  1.3.2.2  mjf #ifdef UHMODEM_DEBUG
    632  1.3.2.2  mjf 	printf("%s: readdata: ", __func__);
    633  1.3.2.2  mjf 	for (i = 0; i < 7; i++)
    634  1.3.2.2  mjf 		printf("0x%x ", data[i]);
    635  1.3.2.2  mjf #endif
    636  1.3.2.2  mjf 	if (uhmodem_regwrite(dev, init_cmd, sizeof(init_cmd)) ) {
    637  1.3.2.2  mjf 		DPRINTF(("%s: write fail\n", __func__));
    638  1.3.2.2  mjf 		return EIO;
    639  1.3.2.2  mjf 	}
    640  1.3.2.2  mjf 
    641  1.3.2.2  mjf 	if (uhmodem_regread(dev, data, 7)) {
    642  1.3.2.2  mjf 		DPRINTF(("%s: read fail\n", __func__));
    643  1.3.2.2  mjf 		return EIO;
    644  1.3.2.2  mjf 	}
    645  1.3.2.2  mjf #ifdef UHMODEM_DEBUG
    646  1.3.2.2  mjf 	printf("%s: readdata: ", __func__);
    647  1.3.2.2  mjf 	printf(" => ");
    648  1.3.2.2  mjf 	for (i = 0; i < 7; i++)
    649  1.3.2.2  mjf 		printf("0x%x ", data[i]);
    650  1.3.2.2  mjf 	printf("\n");
    651  1.3.2.2  mjf #endif
    652  1.3.2.2  mjf 	return 0;
    653  1.3.2.2  mjf }
    654  1.3.2.2  mjf 
    655  1.3.2.2  mjf 
    656  1.3.2.2  mjf #if 0
    657  1.3.2.2  mjf /*
    658  1.3.2.2  mjf  * Windows device driver send these sequens of USB requests.
    659  1.3.2.2  mjf  * However currently I can't understand what the messege is,
    660  1.3.2.2  mjf  * disable this code when I get more information about it.
    661  1.3.2.2  mjf  */
    662  1.3.2.2  mjf Static  usbd_status
    663  1.3.2.2  mjf e220_init(usbd_device_handle dev)
    664  1.3.2.2  mjf {
    665  1.3.2.2  mjf 	uint8_t data[8];
    666  1.3.2.2  mjf 	usb_device_request_t req;
    667  1.3.2.2  mjf 	int i;
    668  1.3.2.2  mjf 
    669  1.3.2.2  mjf 	/* vendor specific unknown request */
    670  1.3.2.2  mjf 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    671  1.3.2.2  mjf 	req.bRequest = 0x02;
    672  1.3.2.2  mjf 	USETW(req.wValue, 0x0001);
    673  1.3.2.2  mjf 	USETW(req.wIndex, 0x0000);
    674  1.3.2.2  mjf 	USETW(req.wLength, 2);
    675  1.3.2.2  mjf 	data[0] = 0x0;
    676  1.3.2.2  mjf 	data[1] = 0x0;
    677  1.3.2.2  mjf 	if (usbd_do_request(dev, &req, data))
    678  1.3.2.2  mjf 		goto error;
    679  1.3.2.2  mjf 
    680  1.3.2.2  mjf 	/* vendor specific unknown sequence */
    681  1.3.2.2  mjf 	if(uhmodem_regsetup(dev, 0x1))
    682  1.3.2.2  mjf 		goto error;
    683  1.3.2.2  mjf 
    684  1.3.2.2  mjf 	if (uhmodem_regread(dev, data, 7))
    685  1.3.2.2  mjf 		goto error;
    686  1.3.2.2  mjf 
    687  1.3.2.2  mjf 	data[1] = 0x8;
    688  1.3.2.2  mjf 	data[2] = 0x7;
    689  1.3.2.2  mjf 	if (uhmodem_regwrite(dev, data, sizeof(data)) )
    690  1.3.2.2  mjf 		goto error;
    691  1.3.2.2  mjf 
    692  1.3.2.2  mjf 	if (uhmodem_regread(dev, data, 7))
    693  1.3.2.2  mjf 		goto error;
    694  1.3.2.2  mjf 		/* XXX should verify the read data ? */
    695  1.3.2.2  mjf 
    696  1.3.2.2  mjf 	if (uhmodem_regsetup(dev, 0x3))
    697  1.3.2.2  mjf 		goto error;
    698  1.3.2.2  mjf 
    699  1.3.2.2  mjf 	return (0);
    700  1.3.2.2  mjf error:
    701  1.3.2.2  mjf 	DPRINTF(("%s: E220 init request fail\n", __func__));
    702  1.3.2.2  mjf 	return (EIO);
    703  1.3.2.2  mjf }
    704  1.3.2.2  mjf #endif
    705  1.3.2.2  mjf 
    706