Home | History | Annotate | Line # | Download | only in usb
ubsa_common.c revision 1.4.26.1
      1  1.4.26.1  bouyer /*	$NetBSD: ubsa_common.c,v 1.4.26.1 2013/01/13 16:30:17 bouyer Exp $	*/
      2       1.1  ichiro /*-
      3       1.1  ichiro  * Copyright (c) 2002, Alexander Kabaev <kan.FreeBSD.org>.
      4       1.1  ichiro  * All rights reserved.
      5       1.1  ichiro  *
      6       1.1  ichiro  * Redistribution and use in source and binary forms, with or without
      7       1.1  ichiro  * modification, are permitted provided that the following conditions
      8       1.1  ichiro  * are met:
      9       1.1  ichiro  * 1. Redistributions of source code must retain the above copyright
     10       1.1  ichiro  *    notice, this list of conditions and the following disclaimer.
     11       1.1  ichiro  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1  ichiro  *    notice, this list of conditions and the following disclaimer in the
     13       1.1  ichiro  *    documentation and/or other materials provided with the distribution.
     14       1.1  ichiro  *
     15       1.1  ichiro  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16       1.1  ichiro  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17       1.1  ichiro  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18       1.1  ichiro  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19       1.1  ichiro  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20       1.1  ichiro  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21       1.1  ichiro  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22       1.1  ichiro  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23       1.1  ichiro  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24       1.1  ichiro  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25       1.1  ichiro  * SUCH DAMAGE.
     26       1.1  ichiro  */
     27       1.1  ichiro /*
     28       1.1  ichiro  * Copyright (c) 2001 The NetBSD Foundation, Inc.
     29       1.1  ichiro  * All rights reserved.
     30       1.1  ichiro  *
     31       1.1  ichiro  * This code is derived from software contributed to The NetBSD Foundation
     32       1.1  ichiro  * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
     33       1.1  ichiro  *
     34       1.1  ichiro  * Redistribution and use in source and binary forms, with or without
     35       1.1  ichiro  * modification, are permitted provided that the following conditions
     36       1.1  ichiro  * are met:
     37       1.1  ichiro  * 1. Redistributions of source code must retain the above copyright
     38       1.1  ichiro  *    notice, this list of conditions and the following disclaimer.
     39       1.1  ichiro  * 2. Redistributions in binary form must reproduce the above copyright
     40       1.1  ichiro  *    notice, this list of conditions and the following disclaimer in the
     41       1.1  ichiro  *    documentation and/or other materials provided with the distribution.
     42       1.1  ichiro  *
     43       1.1  ichiro  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     44       1.1  ichiro  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     45       1.1  ichiro  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     46       1.1  ichiro  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     47       1.1  ichiro  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     48       1.1  ichiro  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     49       1.1  ichiro  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     50       1.1  ichiro  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     51       1.1  ichiro  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     52       1.1  ichiro  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     53       1.1  ichiro  * POSSIBILITY OF SUCH DAMAGE.
     54       1.1  ichiro  */
     55       1.1  ichiro 
     56       1.1  ichiro #include <sys/cdefs.h>
     57  1.4.26.1  bouyer __KERNEL_RCSID(0, "$NetBSD: ubsa_common.c,v 1.4.26.1 2013/01/13 16:30:17 bouyer Exp $");
     58       1.1  ichiro 
     59       1.1  ichiro #include <sys/param.h>
     60       1.1  ichiro #include <sys/systm.h>
     61       1.1  ichiro #include <sys/kernel.h>
     62       1.1  ichiro #include <sys/malloc.h>
     63       1.1  ichiro #ifdef __FreeBSD__
     64       1.1  ichiro #include <sys/bus.h>
     65       1.1  ichiro #endif
     66       1.1  ichiro #include <sys/ioccom.h>
     67       1.1  ichiro #include <sys/fcntl.h>
     68       1.1  ichiro #include <sys/conf.h>
     69       1.1  ichiro #include <sys/tty.h>
     70       1.1  ichiro #include <sys/file.h>
     71       1.1  ichiro #if __FreeBSD_version >= 500014
     72       1.1  ichiro #include <sys/selinfo.h>
     73       1.1  ichiro #else
     74       1.1  ichiro #include <sys/select.h>
     75       1.1  ichiro #endif
     76       1.1  ichiro #include <sys/proc.h>
     77       1.1  ichiro #include <sys/device.h>
     78       1.1  ichiro #include <sys/poll.h>
     79       1.1  ichiro #include <sys/sysctl.h>
     80       1.1  ichiro #include <sys/bus.h>
     81       1.1  ichiro 
     82       1.1  ichiro #include <dev/usb/usb.h>
     83       1.1  ichiro #include <dev/usb/usbdi.h>
     84       1.1  ichiro #include <dev/usb/usbdi_util.h>
     85       1.1  ichiro #include <dev/usb/usbdivar.h>
     86       1.1  ichiro 
     87       1.1  ichiro #include <dev/usb/usbcdc.h>
     88       1.1  ichiro #include <dev/usb/usbdevs.h>
     89       1.1  ichiro #include <dev/usb/usb_quirks.h>
     90       1.1  ichiro #include <dev/usb/ucomvar.h>
     91       1.1  ichiro #include <dev/usb/ubsavar.h>
     92       1.1  ichiro 
     93       1.1  ichiro #ifdef UBSA_DEBUG
     94       1.1  ichiro extern	int	ubsadebug;
     95       1.1  ichiro #define	DPRINTFN(n, x)	do { \
     96       1.1  ichiro 				if (ubsadebug > (n)) \
     97       1.1  ichiro 					logprintf x; \
     98       1.1  ichiro 			} while (0)
     99       1.1  ichiro #else
    100       1.1  ichiro #define	DPRINTFN(n, x)
    101       1.1  ichiro #endif
    102       1.1  ichiro #define	DPRINTF(x) DPRINTFN(0, x)
    103       1.1  ichiro 
    104       1.2  ichiro int
    105       1.1  ichiro ubsa_request(struct ubsa_softc *sc, int portno, u_int8_t request, u_int16_t value)
    106       1.1  ichiro {
    107       1.1  ichiro 	usb_device_request_t req;
    108       1.1  ichiro 	usbd_status err;
    109       1.1  ichiro 
    110       1.1  ichiro 	if (sc->sc_quadumts)
    111       1.1  ichiro 		req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    112       1.1  ichiro 	else
    113       1.1  ichiro 		req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
    114       1.1  ichiro 
    115  1.4.26.1  bouyer 	if (portno >= UBSA_MAXCONN) {
    116       1.1  ichiro 		printf("%s: ubsa_request: invalid port(%d)#\n",
    117       1.1  ichiro 			USBDEVNAME(sc->sc_dev), portno);
    118       1.1  ichiro 		return USBD_INVAL;
    119       1.1  ichiro 	}
    120       1.1  ichiro 
    121       1.1  ichiro 	req.bRequest = request;
    122       1.1  ichiro 	USETW(req.wValue, value);
    123       1.1  ichiro 	USETW(req.wIndex, sc->sc_iface_number[portno]);
    124       1.1  ichiro 	USETW(req.wLength, 0);
    125       1.1  ichiro 
    126       1.1  ichiro 	err = usbd_do_request(sc->sc_udev, &req, 0);
    127       1.1  ichiro 	if (err)
    128       1.1  ichiro 		printf("%s: ubsa_request: %s\n",
    129       1.1  ichiro 		    USBDEVNAME(sc->sc_dev), usbd_errstr(err));
    130       1.1  ichiro 	return (err);
    131       1.1  ichiro }
    132       1.1  ichiro 
    133       1.2  ichiro void
    134       1.1  ichiro ubsa_dtr(struct ubsa_softc *sc, int portno, int onoff)
    135       1.1  ichiro {
    136       1.1  ichiro 
    137       1.1  ichiro 	DPRINTF(("ubsa_dtr: onoff = %d\n", onoff));
    138       1.1  ichiro 
    139       1.1  ichiro 	if (sc->sc_dtr == onoff)
    140       1.1  ichiro 		return;
    141       1.1  ichiro 	sc->sc_dtr = onoff;
    142       1.1  ichiro 
    143       1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_DTR, onoff ? 1 : 0);
    144       1.1  ichiro }
    145       1.1  ichiro 
    146       1.2  ichiro void
    147       1.1  ichiro ubsa_rts(struct ubsa_softc *sc, int portno, int onoff)
    148       1.1  ichiro {
    149       1.1  ichiro 
    150       1.1  ichiro 	DPRINTF(("ubsa_rts: onoff = %d\n", onoff));
    151       1.1  ichiro 
    152       1.1  ichiro 	if (sc->sc_rts == onoff)
    153       1.1  ichiro 		return;
    154       1.1  ichiro 	sc->sc_rts = onoff;
    155       1.1  ichiro 
    156       1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_RTS, onoff ? 1 : 0);
    157       1.1  ichiro }
    158       1.1  ichiro 
    159       1.2  ichiro void
    160       1.1  ichiro ubsa_quadumts_dtr(struct ubsa_softc *sc, int portno, int onoff)
    161       1.1  ichiro {
    162       1.1  ichiro 
    163       1.1  ichiro 	DPRINTF(("ubsa_dtr: onoff = %d\n", onoff));
    164       1.1  ichiro 
    165       1.1  ichiro 	if (sc->sc_dtr == onoff)
    166       1.1  ichiro 		return;
    167       1.1  ichiro 	sc->sc_dtr = onoff;
    168       1.1  ichiro 
    169       1.1  ichiro 	ubsa_request(sc, portno, UBSA_QUADUMTS_SET_PIN,
    170       1.1  ichiro 		 (sc->sc_rts ? 2 : 0)+(sc->sc_dtr ? 1 : 0));
    171       1.1  ichiro }
    172       1.1  ichiro 
    173       1.2  ichiro void
    174       1.1  ichiro ubsa_quadumts_rts(struct ubsa_softc *sc, int portno, int onoff)
    175       1.1  ichiro {
    176       1.1  ichiro 
    177       1.1  ichiro 	DPRINTF(("ubsa_rts: onoff = %d\n", onoff));
    178       1.1  ichiro 
    179       1.1  ichiro 	if (sc->sc_rts == onoff)
    180       1.1  ichiro 		return;
    181       1.1  ichiro 	sc->sc_rts = onoff;
    182       1.1  ichiro 
    183       1.1  ichiro 	ubsa_request(sc, portno, UBSA_QUADUMTS_SET_PIN,
    184       1.1  ichiro 		 (sc->sc_rts ? 2 : 0)+(sc->sc_dtr ? 1 : 0));
    185       1.1  ichiro }
    186       1.1  ichiro 
    187       1.2  ichiro void
    188       1.1  ichiro ubsa_break(struct ubsa_softc *sc, int portno, int onoff)
    189       1.1  ichiro {
    190       1.1  ichiro 	DPRINTF(("ubsa_rts: onoff = %d\n", onoff));
    191       1.1  ichiro 
    192       1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_BREAK, onoff ? 1 : 0);
    193       1.1  ichiro }
    194       1.1  ichiro 
    195       1.2  ichiro void
    196       1.1  ichiro ubsa_set(void *addr, int portno, int reg, int onoff)
    197       1.1  ichiro {
    198       1.1  ichiro 	struct ubsa_softc *sc;
    199       1.1  ichiro 
    200       1.1  ichiro 	sc = addr;
    201       1.1  ichiro 	switch (reg) {
    202       1.1  ichiro 	case UCOM_SET_DTR:
    203       1.1  ichiro 		if (sc->sc_quadumts)
    204       1.1  ichiro 			ubsa_quadumts_dtr(sc, portno, onoff);
    205       1.1  ichiro 		else
    206       1.1  ichiro 			ubsa_dtr(sc, portno, onoff);
    207       1.1  ichiro 		break;
    208       1.1  ichiro 	case UCOM_SET_RTS:
    209       1.1  ichiro 		if (sc->sc_quadumts)
    210       1.1  ichiro 			ubsa_quadumts_rts(sc, portno, onoff);
    211       1.1  ichiro 		else
    212       1.1  ichiro 			ubsa_rts(sc, portno, onoff);
    213       1.1  ichiro 		break;
    214       1.1  ichiro 	case UCOM_SET_BREAK:
    215       1.1  ichiro 		if (!sc->sc_quadumts)
    216       1.1  ichiro 			ubsa_break(sc, portno, onoff);
    217       1.1  ichiro 		break;
    218       1.1  ichiro 	default:
    219       1.1  ichiro 		break;
    220       1.1  ichiro 	}
    221       1.1  ichiro }
    222       1.1  ichiro 
    223       1.2  ichiro void
    224       1.1  ichiro ubsa_baudrate(struct ubsa_softc *sc, int portno, speed_t speed)
    225       1.1  ichiro {
    226       1.1  ichiro 	u_int16_t value = 0;
    227       1.1  ichiro 
    228       1.1  ichiro 	DPRINTF(("ubsa_baudrate: speed = %d\n", speed));
    229       1.1  ichiro 
    230       1.1  ichiro 	switch(speed) {
    231       1.1  ichiro 	case B0:
    232       1.1  ichiro 		break;
    233       1.1  ichiro 	case B300:
    234       1.1  ichiro 	case B600:
    235       1.1  ichiro 	case B1200:
    236       1.1  ichiro 	case B2400:
    237       1.1  ichiro 	case B4800:
    238       1.1  ichiro 	case B9600:
    239       1.1  ichiro 	case B19200:
    240       1.1  ichiro 	case B38400:
    241       1.1  ichiro 	case B57600:
    242       1.1  ichiro 	case B115200:
    243       1.1  ichiro 	case B230400:
    244       1.1  ichiro 		value = B230400 / speed;
    245       1.1  ichiro 		break;
    246       1.1  ichiro 	default:
    247       1.1  ichiro 		printf("%s: ubsa_param: unsupported baudrate, "
    248       1.1  ichiro 		    "forcing default of 9600\n",
    249       1.1  ichiro 		    USBDEVNAME(sc->sc_dev));
    250       1.1  ichiro 		value = B230400 / B9600;
    251       1.1  ichiro 		break;
    252       1.1  ichiro 	};
    253       1.1  ichiro 
    254       1.1  ichiro 	if (speed == B0) {
    255       1.1  ichiro 		ubsa_flow(sc, portno, 0, 0);
    256       1.1  ichiro 		ubsa_dtr(sc, portno, 0);
    257       1.1  ichiro 		ubsa_rts(sc, portno, 0);
    258       1.1  ichiro 	} else
    259       1.1  ichiro 		ubsa_request(sc, portno, UBSA_SET_BAUDRATE, value);
    260       1.1  ichiro }
    261       1.1  ichiro 
    262       1.2  ichiro void
    263       1.1  ichiro ubsa_parity(struct ubsa_softc *sc, int portno, tcflag_t cflag)
    264       1.1  ichiro {
    265       1.1  ichiro 	int value;
    266       1.1  ichiro 
    267       1.1  ichiro 	DPRINTF(("ubsa_parity: cflag = 0x%x\n", cflag));
    268       1.1  ichiro 
    269       1.1  ichiro 	if (cflag & PARENB)
    270       1.1  ichiro 		value = (cflag & PARODD) ? UBSA_PARITY_ODD : UBSA_PARITY_EVEN;
    271       1.1  ichiro 	else
    272       1.1  ichiro 		value = UBSA_PARITY_NONE;
    273       1.1  ichiro 
    274       1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_PARITY, value);
    275       1.1  ichiro }
    276       1.1  ichiro 
    277       1.2  ichiro void
    278       1.1  ichiro ubsa_databits(struct ubsa_softc *sc, int portno, tcflag_t cflag)
    279       1.1  ichiro {
    280       1.1  ichiro 	int value;
    281       1.1  ichiro 
    282       1.1  ichiro 	DPRINTF(("ubsa_databits: cflag = 0x%x\n", cflag));
    283       1.1  ichiro 
    284       1.1  ichiro 	switch (cflag & CSIZE) {
    285       1.1  ichiro 	case CS5: value = 0; break;
    286       1.1  ichiro 	case CS6: value = 1; break;
    287       1.1  ichiro 	case CS7: value = 2; break;
    288       1.1  ichiro 	case CS8: value = 3; break;
    289       1.1  ichiro 	default:
    290       1.1  ichiro 		printf("%s: ubsa_param: unsupported databits requested, "
    291       1.1  ichiro 		    "forcing default of 8\n",
    292       1.1  ichiro 		    USBDEVNAME(sc->sc_dev));
    293       1.1  ichiro 		value = 3;
    294       1.1  ichiro 	}
    295       1.1  ichiro 
    296       1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_DATA_BITS, value);
    297       1.1  ichiro }
    298       1.1  ichiro 
    299       1.2  ichiro void
    300       1.1  ichiro ubsa_stopbits(struct ubsa_softc *sc, int portno, tcflag_t cflag)
    301       1.1  ichiro {
    302       1.1  ichiro 	int value;
    303       1.1  ichiro 
    304       1.1  ichiro 	DPRINTF(("ubsa_stopbits: cflag = 0x%x\n", cflag));
    305       1.1  ichiro 
    306       1.1  ichiro 	value = (cflag & CSTOPB) ? 1 : 0;
    307       1.1  ichiro 
    308       1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_STOP_BITS, value);
    309       1.1  ichiro }
    310       1.1  ichiro 
    311       1.2  ichiro void
    312       1.1  ichiro ubsa_flow(struct ubsa_softc *sc, int portno, tcflag_t cflag, tcflag_t iflag)
    313       1.1  ichiro {
    314       1.1  ichiro 	int value;
    315       1.1  ichiro 
    316       1.1  ichiro 	DPRINTF(("ubsa_flow: cflag = 0x%x, iflag = 0x%x\n", cflag, iflag));
    317       1.1  ichiro 
    318       1.1  ichiro 	value = 0;
    319       1.1  ichiro 	if (cflag & CRTSCTS)
    320       1.1  ichiro 		value |= UBSA_FLOW_OCTS | UBSA_FLOW_IRTS;
    321       1.1  ichiro 	if (iflag & (IXON|IXOFF))
    322       1.1  ichiro 		value |= UBSA_FLOW_OXON | UBSA_FLOW_IXON;
    323       1.1  ichiro 
    324       1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_FLOW_CTRL, value);
    325       1.1  ichiro }
    326       1.1  ichiro 
    327       1.2  ichiro int
    328       1.1  ichiro ubsa_param(void *addr, int portno, struct termios *ti)
    329       1.1  ichiro {
    330       1.1  ichiro 	struct ubsa_softc *sc = addr;
    331       1.1  ichiro 
    332       1.1  ichiro 	DPRINTF(("ubsa_param: sc = %p\n", sc));
    333       1.1  ichiro 
    334       1.1  ichiro 	if (!sc->sc_quadumts) {
    335       1.1  ichiro 		ubsa_baudrate(sc, portno, ti->c_ospeed);
    336       1.1  ichiro 		ubsa_parity(sc, portno, ti->c_cflag);
    337       1.1  ichiro 		ubsa_databits(sc, portno, ti->c_cflag);
    338       1.1  ichiro 		ubsa_stopbits(sc, portno, ti->c_cflag);
    339       1.1  ichiro 		ubsa_flow(sc, portno, ti->c_cflag, ti->c_iflag);
    340       1.1  ichiro 	}
    341       1.1  ichiro 
    342       1.1  ichiro 	return (0);
    343       1.1  ichiro }
    344       1.1  ichiro 
    345       1.2  ichiro int
    346       1.1  ichiro ubsa_open(void *addr, int portno)
    347       1.1  ichiro {
    348       1.1  ichiro 	struct ubsa_softc *sc = addr;
    349       1.1  ichiro 	int err;
    350       1.1  ichiro 
    351       1.1  ichiro 	if (sc->sc_dying)
    352       1.1  ichiro 		return (ENXIO);
    353       1.1  ichiro 
    354       1.1  ichiro 	if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
    355       1.1  ichiro 		sc->sc_intr_buf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK);
    356       1.1  ichiro 		/* XXX only iface# = 0 has intr line */
    357       1.1  ichiro 		/* XXX E220 specific? need to check */
    358       1.1  ichiro 		err = usbd_open_pipe_intr(sc->sc_iface[0],
    359       1.1  ichiro 		    sc->sc_intr_number,
    360       1.1  ichiro 		    USBD_SHORT_XFER_OK,
    361       1.1  ichiro 		    &sc->sc_intr_pipe,
    362       1.1  ichiro 		    sc,
    363       1.1  ichiro 		    sc->sc_intr_buf,
    364       1.1  ichiro 		    sc->sc_isize,
    365       1.1  ichiro 		    ubsa_intr,
    366       1.1  ichiro 		    UBSA_INTR_INTERVAL);
    367       1.1  ichiro 		if (err) {
    368       1.1  ichiro 			printf("%s: cannot open interrupt pipe (addr %d)\n",
    369       1.1  ichiro 			    USBDEVNAME(sc->sc_dev),
    370       1.1  ichiro 			    sc->sc_intr_number);
    371       1.1  ichiro 			return (EIO);
    372       1.1  ichiro 		}
    373       1.1  ichiro 	}
    374       1.1  ichiro 
    375       1.1  ichiro 	return (0);
    376       1.1  ichiro }
    377       1.1  ichiro 
    378       1.2  ichiro void
    379       1.1  ichiro ubsa_close(void *addr, int portno)
    380       1.1  ichiro {
    381       1.1  ichiro 	struct ubsa_softc *sc = addr;
    382       1.1  ichiro 	int err;
    383       1.1  ichiro 
    384       1.1  ichiro 	if (sc->sc_dying)
    385       1.1  ichiro 		return;
    386       1.1  ichiro 
    387       1.1  ichiro 	DPRINTF(("ubsa_close: close\n"));
    388       1.1  ichiro 
    389       1.1  ichiro 	if (sc->sc_intr_pipe != NULL) {
    390       1.1  ichiro 		err = usbd_abort_pipe(sc->sc_intr_pipe);
    391       1.1  ichiro 		if (err)
    392       1.1  ichiro 			printf("%s: abort interrupt pipe failed: %s\n",
    393       1.1  ichiro 			    USBDEVNAME(sc->sc_dev),
    394       1.1  ichiro 			    usbd_errstr(err));
    395       1.1  ichiro 		err = usbd_close_pipe(sc->sc_intr_pipe);
    396       1.1  ichiro 		if (err)
    397       1.1  ichiro 			printf("%s: close interrupt pipe failed: %s\n",
    398       1.1  ichiro 			    USBDEVNAME(sc->sc_dev),
    399       1.1  ichiro 			    usbd_errstr(err));
    400       1.1  ichiro 		free(sc->sc_intr_buf, M_USBDEV);
    401       1.1  ichiro 		sc->sc_intr_pipe = NULL;
    402       1.1  ichiro 	}
    403       1.1  ichiro }
    404       1.1  ichiro 
    405       1.2  ichiro void
    406       1.1  ichiro ubsa_intr(usbd_xfer_handle xfer, usbd_private_handle priv,
    407       1.1  ichiro     usbd_status status)
    408       1.1  ichiro {
    409       1.1  ichiro 	struct ubsa_softc *sc = priv;
    410       1.1  ichiro 	u_char *buf;
    411       1.1  ichiro 	int i;
    412       1.1  ichiro 
    413       1.1  ichiro 	buf = sc->sc_intr_buf;
    414       1.1  ichiro 	if (sc->sc_dying)
    415       1.1  ichiro 		return;
    416       1.1  ichiro 
    417       1.1  ichiro 	if (status != USBD_NORMAL_COMPLETION) {
    418       1.1  ichiro 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
    419       1.1  ichiro 			return;
    420       1.1  ichiro 
    421       1.1  ichiro 		DPRINTF(("%s: ubsa_intr: abnormal status: %s\n",
    422       1.1  ichiro 		    USBDEVNAME(sc->sc_dev), usbd_errstr(status)));
    423       1.1  ichiro 		usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
    424       1.1  ichiro 		return;
    425       1.1  ichiro 	}
    426       1.1  ichiro 
    427       1.1  ichiro 	/* incidentally, Belkin adapter status bits match UART 16550 bits */
    428       1.1  ichiro 	sc->sc_lsr = buf[2];
    429       1.1  ichiro 	sc->sc_msr = buf[3];
    430       1.1  ichiro 
    431       1.1  ichiro 	DPRINTF(("%s: ubsa lsr = 0x%02x, msr = 0x%02x\n",
    432       1.1  ichiro 	    USBDEVNAME(sc->sc_dev), sc->sc_lsr, sc->sc_msr));
    433       1.1  ichiro 
    434       1.1  ichiro 	for (i = 0; i < sc->sc_numif; i++) {
    435       1.4    cube 		ucom_status_change(device_private(sc->sc_subdevs[i]));
    436       1.1  ichiro 	}
    437       1.1  ichiro }
    438       1.1  ichiro 
    439       1.2  ichiro void
    440       1.1  ichiro ubsa_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
    441       1.1  ichiro {
    442       1.1  ichiro 	struct ubsa_softc *sc = addr;
    443       1.1  ichiro 
    444       1.1  ichiro 	DPRINTF(("ubsa_get_status\n"));
    445       1.1  ichiro 
    446       1.1  ichiro 	if (lsr != NULL)
    447       1.1  ichiro 		*lsr = sc->sc_lsr;
    448       1.1  ichiro 	if (msr != NULL)
    449       1.1  ichiro 		*msr = sc->sc_msr;
    450       1.1  ichiro }
    451       1.1  ichiro 
    452