Home | History | Annotate | Line # | Download | only in usb
ubsa_common.c revision 1.10.18.1
      1  1.10.18.1  christos /*	$NetBSD: ubsa_common.c,v 1.10.18.1 2019/06/10 22:07:34 christos 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.10.18.1  christos __KERNEL_RCSID(0, "$NetBSD: ubsa_common.c,v 1.10.18.1 2019/06/10 22:07:34 christos 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.10     skrll #include <sys/kmem.h>
     63        1.1    ichiro #include <sys/ioccom.h>
     64        1.1    ichiro #include <sys/fcntl.h>
     65        1.1    ichiro #include <sys/conf.h>
     66        1.1    ichiro #include <sys/tty.h>
     67        1.1    ichiro #include <sys/file.h>
     68        1.1    ichiro #include <sys/select.h>
     69        1.1    ichiro #include <sys/proc.h>
     70        1.1    ichiro #include <sys/device.h>
     71        1.1    ichiro #include <sys/poll.h>
     72        1.1    ichiro #include <sys/sysctl.h>
     73        1.1    ichiro #include <sys/bus.h>
     74        1.1    ichiro 
     75        1.1    ichiro #include <dev/usb/usb.h>
     76        1.1    ichiro #include <dev/usb/usbdi.h>
     77        1.1    ichiro #include <dev/usb/usbdi_util.h>
     78        1.1    ichiro #include <dev/usb/usbdivar.h>
     79        1.1    ichiro 
     80        1.1    ichiro #include <dev/usb/usbcdc.h>
     81        1.1    ichiro #include <dev/usb/usbdevs.h>
     82        1.1    ichiro #include <dev/usb/usb_quirks.h>
     83        1.1    ichiro #include <dev/usb/ucomvar.h>
     84        1.1    ichiro #include <dev/usb/ubsavar.h>
     85        1.1    ichiro 
     86        1.1    ichiro #ifdef UBSA_DEBUG
     87        1.1    ichiro extern	int	ubsadebug;
     88        1.1    ichiro #define	DPRINTFN(n, x)	do { \
     89        1.1    ichiro 				if (ubsadebug > (n)) \
     90        1.5    dyoung 					printf x; \
     91        1.1    ichiro 			} while (0)
     92        1.1    ichiro #else
     93        1.1    ichiro #define	DPRINTFN(n, x)
     94        1.1    ichiro #endif
     95        1.1    ichiro #define	DPRINTF(x) DPRINTFN(0, x)
     96        1.1    ichiro 
     97        1.2    ichiro int
     98       1.10     skrll ubsa_request(struct ubsa_softc *sc, int portno, uint8_t request, uint16_t value)
     99        1.1    ichiro {
    100        1.1    ichiro 	usb_device_request_t req;
    101        1.1    ichiro 	usbd_status err;
    102        1.1    ichiro 
    103        1.1    ichiro 	if (sc->sc_quadumts)
    104        1.1    ichiro 		req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    105        1.1    ichiro 	else
    106        1.1    ichiro 		req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
    107        1.1    ichiro 
    108        1.9   msaitoh 	if (portno >= UBSA_MAXCONN) {
    109        1.1    ichiro 		printf("%s: ubsa_request: invalid port(%d)#\n",
    110        1.5    dyoung 			device_xname(sc->sc_dev), portno);
    111       1.10     skrll 		return USBD_INVAL;
    112        1.1    ichiro 	}
    113        1.1    ichiro 
    114        1.1    ichiro 	req.bRequest = request;
    115        1.1    ichiro 	USETW(req.wValue, value);
    116        1.1    ichiro 	USETW(req.wIndex, sc->sc_iface_number[portno]);
    117        1.1    ichiro 	USETW(req.wLength, 0);
    118        1.1    ichiro 
    119        1.1    ichiro 	err = usbd_do_request(sc->sc_udev, &req, 0);
    120        1.1    ichiro 	if (err)
    121        1.1    ichiro 		printf("%s: ubsa_request: %s\n",
    122        1.5    dyoung 		    device_xname(sc->sc_dev), usbd_errstr(err));
    123       1.10     skrll 	return err;
    124        1.1    ichiro }
    125        1.1    ichiro 
    126        1.2    ichiro void
    127        1.1    ichiro ubsa_dtr(struct ubsa_softc *sc, int portno, int onoff)
    128        1.1    ichiro {
    129        1.1    ichiro 
    130        1.1    ichiro 	DPRINTF(("ubsa_dtr: onoff = %d\n", onoff));
    131        1.1    ichiro 
    132        1.1    ichiro 	if (sc->sc_dtr == onoff)
    133        1.1    ichiro 		return;
    134        1.1    ichiro 	sc->sc_dtr = onoff;
    135        1.1    ichiro 
    136        1.1    ichiro 	ubsa_request(sc, portno, UBSA_SET_DTR, onoff ? 1 : 0);
    137        1.1    ichiro }
    138        1.1    ichiro 
    139        1.2    ichiro void
    140        1.1    ichiro ubsa_rts(struct ubsa_softc *sc, int portno, int onoff)
    141        1.1    ichiro {
    142        1.1    ichiro 
    143        1.1    ichiro 	DPRINTF(("ubsa_rts: onoff = %d\n", onoff));
    144        1.1    ichiro 
    145        1.1    ichiro 	if (sc->sc_rts == onoff)
    146        1.1    ichiro 		return;
    147        1.1    ichiro 	sc->sc_rts = onoff;
    148        1.1    ichiro 
    149        1.1    ichiro 	ubsa_request(sc, portno, UBSA_SET_RTS, onoff ? 1 : 0);
    150        1.1    ichiro }
    151        1.1    ichiro 
    152        1.2    ichiro void
    153        1.1    ichiro ubsa_quadumts_dtr(struct ubsa_softc *sc, int portno, int onoff)
    154        1.1    ichiro {
    155        1.1    ichiro 
    156        1.1    ichiro 	DPRINTF(("ubsa_dtr: onoff = %d\n", onoff));
    157        1.1    ichiro 
    158        1.1    ichiro 	if (sc->sc_dtr == onoff)
    159        1.1    ichiro 		return;
    160        1.1    ichiro 	sc->sc_dtr = onoff;
    161        1.1    ichiro 
    162        1.1    ichiro 	ubsa_request(sc, portno, UBSA_QUADUMTS_SET_PIN,
    163        1.1    ichiro 		 (sc->sc_rts ? 2 : 0)+(sc->sc_dtr ? 1 : 0));
    164        1.1    ichiro }
    165        1.1    ichiro 
    166        1.2    ichiro void
    167        1.1    ichiro ubsa_quadumts_rts(struct ubsa_softc *sc, int portno, int onoff)
    168        1.1    ichiro {
    169        1.1    ichiro 
    170        1.1    ichiro 	DPRINTF(("ubsa_rts: onoff = %d\n", onoff));
    171        1.1    ichiro 
    172        1.1    ichiro 	if (sc->sc_rts == onoff)
    173        1.1    ichiro 		return;
    174        1.1    ichiro 	sc->sc_rts = onoff;
    175        1.1    ichiro 
    176        1.1    ichiro 	ubsa_request(sc, portno, UBSA_QUADUMTS_SET_PIN,
    177        1.1    ichiro 		 (sc->sc_rts ? 2 : 0)+(sc->sc_dtr ? 1 : 0));
    178        1.1    ichiro }
    179        1.1    ichiro 
    180        1.2    ichiro void
    181        1.1    ichiro ubsa_break(struct ubsa_softc *sc, int portno, int onoff)
    182        1.1    ichiro {
    183        1.1    ichiro 	DPRINTF(("ubsa_rts: onoff = %d\n", onoff));
    184        1.1    ichiro 
    185  1.10.18.1  christos 	if (sc->sc_dying)
    186  1.10.18.1  christos 		return;
    187  1.10.18.1  christos 
    188        1.1    ichiro 	ubsa_request(sc, portno, UBSA_SET_BREAK, onoff ? 1 : 0);
    189        1.1    ichiro }
    190        1.1    ichiro 
    191        1.2    ichiro void
    192        1.1    ichiro ubsa_set(void *addr, int portno, int reg, int onoff)
    193        1.1    ichiro {
    194  1.10.18.1  christos 	struct ubsa_softc *sc = addr;
    195  1.10.18.1  christos 
    196  1.10.18.1  christos 	if (sc->sc_dying)
    197  1.10.18.1  christos 		return;
    198        1.1    ichiro 
    199        1.1    ichiro 	switch (reg) {
    200        1.1    ichiro 	case UCOM_SET_DTR:
    201        1.1    ichiro 		if (sc->sc_quadumts)
    202        1.1    ichiro 			ubsa_quadumts_dtr(sc, portno, onoff);
    203        1.1    ichiro 		else
    204        1.1    ichiro 			ubsa_dtr(sc, portno, onoff);
    205        1.1    ichiro 		break;
    206        1.1    ichiro 	case UCOM_SET_RTS:
    207        1.1    ichiro 		if (sc->sc_quadumts)
    208        1.1    ichiro 			ubsa_quadumts_rts(sc, portno, onoff);
    209        1.1    ichiro 		else
    210        1.1    ichiro 			ubsa_rts(sc, portno, onoff);
    211        1.1    ichiro 		break;
    212        1.1    ichiro 	case UCOM_SET_BREAK:
    213        1.1    ichiro 		if (!sc->sc_quadumts)
    214        1.1    ichiro 			ubsa_break(sc, portno, onoff);
    215        1.1    ichiro 		break;
    216        1.1    ichiro 	default:
    217        1.1    ichiro 		break;
    218        1.1    ichiro 	}
    219        1.1    ichiro }
    220        1.1    ichiro 
    221        1.2    ichiro void
    222        1.1    ichiro ubsa_baudrate(struct ubsa_softc *sc, int portno, speed_t speed)
    223        1.1    ichiro {
    224       1.10     skrll 	uint16_t value = 0;
    225        1.1    ichiro 
    226        1.1    ichiro 	DPRINTF(("ubsa_baudrate: speed = %d\n", speed));
    227        1.1    ichiro 
    228        1.1    ichiro 	switch(speed) {
    229        1.1    ichiro 	case B0:
    230        1.1    ichiro 		break;
    231        1.1    ichiro 	case B300:
    232        1.1    ichiro 	case B600:
    233        1.1    ichiro 	case B1200:
    234        1.1    ichiro 	case B2400:
    235        1.1    ichiro 	case B4800:
    236        1.1    ichiro 	case B9600:
    237        1.1    ichiro 	case B19200:
    238        1.1    ichiro 	case B38400:
    239        1.1    ichiro 	case B57600:
    240        1.1    ichiro 	case B115200:
    241        1.1    ichiro 	case B230400:
    242        1.1    ichiro 		value = B230400 / speed;
    243        1.1    ichiro 		break;
    244        1.1    ichiro 	default:
    245        1.1    ichiro 		printf("%s: ubsa_param: unsupported baudrate, "
    246        1.1    ichiro 		    "forcing default of 9600\n",
    247        1.5    dyoung 		    device_xname(sc->sc_dev));
    248        1.1    ichiro 		value = B230400 / B9600;
    249        1.1    ichiro 		break;
    250        1.1    ichiro 	};
    251        1.1    ichiro 
    252        1.1    ichiro 	if (speed == B0) {
    253        1.1    ichiro 		ubsa_flow(sc, portno, 0, 0);
    254        1.1    ichiro 		ubsa_dtr(sc, portno, 0);
    255        1.1    ichiro 		ubsa_rts(sc, portno, 0);
    256        1.1    ichiro 	} else
    257        1.1    ichiro 		ubsa_request(sc, portno, UBSA_SET_BAUDRATE, value);
    258        1.1    ichiro }
    259        1.1    ichiro 
    260        1.2    ichiro void
    261        1.1    ichiro ubsa_parity(struct ubsa_softc *sc, int portno, tcflag_t cflag)
    262        1.1    ichiro {
    263        1.1    ichiro 	int value;
    264        1.1    ichiro 
    265        1.1    ichiro 	DPRINTF(("ubsa_parity: cflag = 0x%x\n", cflag));
    266        1.1    ichiro 
    267        1.1    ichiro 	if (cflag & PARENB)
    268        1.1    ichiro 		value = (cflag & PARODD) ? UBSA_PARITY_ODD : UBSA_PARITY_EVEN;
    269        1.1    ichiro 	else
    270        1.1    ichiro 		value = UBSA_PARITY_NONE;
    271        1.1    ichiro 
    272        1.1    ichiro 	ubsa_request(sc, portno, UBSA_SET_PARITY, value);
    273        1.1    ichiro }
    274        1.1    ichiro 
    275        1.2    ichiro void
    276        1.1    ichiro ubsa_databits(struct ubsa_softc *sc, int portno, tcflag_t cflag)
    277        1.1    ichiro {
    278        1.1    ichiro 	int value;
    279        1.1    ichiro 
    280        1.1    ichiro 	DPRINTF(("ubsa_databits: cflag = 0x%x\n", cflag));
    281        1.1    ichiro 
    282        1.1    ichiro 	switch (cflag & CSIZE) {
    283        1.1    ichiro 	case CS5: value = 0; break;
    284        1.1    ichiro 	case CS6: value = 1; break;
    285        1.1    ichiro 	case CS7: value = 2; break;
    286        1.1    ichiro 	case CS8: value = 3; break;
    287        1.1    ichiro 	default:
    288        1.1    ichiro 		printf("%s: ubsa_param: unsupported databits requested, "
    289        1.1    ichiro 		    "forcing default of 8\n",
    290        1.5    dyoung 		    device_xname(sc->sc_dev));
    291        1.1    ichiro 		value = 3;
    292        1.1    ichiro 	}
    293        1.1    ichiro 
    294        1.1    ichiro 	ubsa_request(sc, portno, UBSA_SET_DATA_BITS, value);
    295        1.1    ichiro }
    296        1.1    ichiro 
    297        1.2    ichiro void
    298        1.1    ichiro ubsa_stopbits(struct ubsa_softc *sc, int portno, tcflag_t cflag)
    299        1.1    ichiro {
    300        1.1    ichiro 	int value;
    301        1.1    ichiro 
    302        1.1    ichiro 	DPRINTF(("ubsa_stopbits: cflag = 0x%x\n", cflag));
    303        1.1    ichiro 
    304        1.1    ichiro 	value = (cflag & CSTOPB) ? 1 : 0;
    305        1.1    ichiro 
    306        1.1    ichiro 	ubsa_request(sc, portno, UBSA_SET_STOP_BITS, value);
    307        1.1    ichiro }
    308        1.1    ichiro 
    309        1.2    ichiro void
    310        1.1    ichiro ubsa_flow(struct ubsa_softc *sc, int portno, tcflag_t cflag, tcflag_t iflag)
    311        1.1    ichiro {
    312        1.1    ichiro 	int value;
    313        1.1    ichiro 
    314        1.1    ichiro 	DPRINTF(("ubsa_flow: cflag = 0x%x, iflag = 0x%x\n", cflag, iflag));
    315        1.1    ichiro 
    316        1.1    ichiro 	value = 0;
    317        1.1    ichiro 	if (cflag & CRTSCTS)
    318        1.1    ichiro 		value |= UBSA_FLOW_OCTS | UBSA_FLOW_IRTS;
    319        1.1    ichiro 	if (iflag & (IXON|IXOFF))
    320        1.1    ichiro 		value |= UBSA_FLOW_OXON | UBSA_FLOW_IXON;
    321        1.1    ichiro 
    322        1.1    ichiro 	ubsa_request(sc, portno, UBSA_SET_FLOW_CTRL, value);
    323        1.1    ichiro }
    324        1.1    ichiro 
    325        1.2    ichiro int
    326        1.1    ichiro ubsa_param(void *addr, int portno, struct termios *ti)
    327        1.1    ichiro {
    328        1.1    ichiro 	struct ubsa_softc *sc = addr;
    329        1.1    ichiro 
    330  1.10.18.1  christos 	if (sc->sc_dying)
    331  1.10.18.1  christos 		return EIO;
    332  1.10.18.1  christos 
    333        1.1    ichiro 	DPRINTF(("ubsa_param: sc = %p\n", sc));
    334        1.1    ichiro 
    335        1.1    ichiro 	if (!sc->sc_quadumts) {
    336        1.1    ichiro 		ubsa_baudrate(sc, portno, ti->c_ospeed);
    337        1.1    ichiro 		ubsa_parity(sc, portno, ti->c_cflag);
    338        1.1    ichiro 		ubsa_databits(sc, portno, ti->c_cflag);
    339        1.1    ichiro 		ubsa_stopbits(sc, portno, ti->c_cflag);
    340        1.1    ichiro 		ubsa_flow(sc, portno, ti->c_cflag, ti->c_iflag);
    341        1.1    ichiro 	}
    342        1.1    ichiro 
    343       1.10     skrll 	return 0;
    344        1.1    ichiro }
    345        1.1    ichiro 
    346        1.2    ichiro int
    347        1.1    ichiro ubsa_open(void *addr, int portno)
    348        1.1    ichiro {
    349        1.1    ichiro 	struct ubsa_softc *sc = addr;
    350        1.1    ichiro 	int err;
    351        1.1    ichiro 
    352        1.1    ichiro 	if (sc->sc_dying)
    353  1.10.18.1  christos 		return EIO;
    354        1.1    ichiro 
    355        1.1    ichiro 	if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
    356       1.10     skrll 		sc->sc_intr_buf = kmem_alloc(sc->sc_isize, KM_SLEEP);
    357        1.1    ichiro 		/* XXX only iface# = 0 has intr line */
    358        1.1    ichiro 		/* XXX E220 specific? need to check */
    359        1.1    ichiro 		err = usbd_open_pipe_intr(sc->sc_iface[0],
    360        1.1    ichiro 		    sc->sc_intr_number,
    361        1.1    ichiro 		    USBD_SHORT_XFER_OK,
    362        1.1    ichiro 		    &sc->sc_intr_pipe,
    363        1.1    ichiro 		    sc,
    364        1.1    ichiro 		    sc->sc_intr_buf,
    365        1.1    ichiro 		    sc->sc_isize,
    366        1.1    ichiro 		    ubsa_intr,
    367        1.1    ichiro 		    UBSA_INTR_INTERVAL);
    368        1.1    ichiro 		if (err) {
    369        1.1    ichiro 			printf("%s: cannot open interrupt pipe (addr %d)\n",
    370        1.5    dyoung 			    device_xname(sc->sc_dev),
    371        1.1    ichiro 			    sc->sc_intr_number);
    372       1.10     skrll 			return EIO;
    373        1.1    ichiro 		}
    374        1.1    ichiro 	}
    375        1.1    ichiro 
    376       1.10     skrll 	return 0;
    377        1.1    ichiro }
    378        1.1    ichiro 
    379        1.2    ichiro void
    380  1.10.18.1  christos ubsa_close_pipe(struct ubsa_softc *sc)
    381  1.10.18.1  christos {
    382  1.10.18.1  christos 
    383  1.10.18.1  christos 	if (sc->sc_intr_pipe != NULL) {
    384  1.10.18.1  christos 		usbd_abort_pipe(sc->sc_intr_pipe);
    385  1.10.18.1  christos 		usbd_close_pipe(sc->sc_intr_pipe);
    386  1.10.18.1  christos 		sc->sc_intr_pipe = NULL;
    387  1.10.18.1  christos 	}
    388  1.10.18.1  christos 	if (sc->sc_intr_buf) {
    389  1.10.18.1  christos 		kmem_free(sc->sc_intr_buf, sc->sc_isize);
    390  1.10.18.1  christos 		sc->sc_intr_buf = NULL;
    391  1.10.18.1  christos 	}
    392  1.10.18.1  christos }
    393  1.10.18.1  christos 
    394  1.10.18.1  christos void
    395        1.1    ichiro ubsa_close(void *addr, int portno)
    396        1.1    ichiro {
    397        1.1    ichiro 	struct ubsa_softc *sc = addr;
    398  1.10.18.1  christos 
    399  1.10.18.1  christos 	DPRINTF(("ubsa_close: close\n"));
    400        1.1    ichiro 
    401        1.1    ichiro 	if (sc->sc_dying)
    402        1.1    ichiro 		return;
    403        1.1    ichiro 
    404  1.10.18.1  christos 	ubsa_close_pipe(sc);
    405        1.1    ichiro }
    406        1.1    ichiro 
    407        1.2    ichiro void
    408       1.10     skrll ubsa_intr(struct usbd_xfer *xfer, void *priv,
    409        1.1    ichiro     usbd_status status)
    410        1.1    ichiro {
    411        1.1    ichiro 	struct ubsa_softc *sc = priv;
    412        1.1    ichiro 	u_char *buf;
    413        1.1    ichiro 	int i;
    414        1.1    ichiro 
    415        1.1    ichiro 	buf = sc->sc_intr_buf;
    416        1.1    ichiro 	if (sc->sc_dying)
    417        1.1    ichiro 		return;
    418        1.1    ichiro 
    419        1.1    ichiro 	if (status != USBD_NORMAL_COMPLETION) {
    420        1.1    ichiro 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
    421        1.1    ichiro 			return;
    422        1.1    ichiro 
    423        1.1    ichiro 		DPRINTF(("%s: ubsa_intr: abnormal status: %s\n",
    424        1.5    dyoung 		    device_xname(sc->sc_dev), usbd_errstr(status)));
    425        1.1    ichiro 		usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
    426        1.1    ichiro 		return;
    427        1.1    ichiro 	}
    428        1.1    ichiro 
    429        1.1    ichiro 	/* incidentally, Belkin adapter status bits match UART 16550 bits */
    430        1.1    ichiro 	sc->sc_lsr = buf[2];
    431        1.1    ichiro 	sc->sc_msr = buf[3];
    432        1.1    ichiro 
    433        1.1    ichiro 	DPRINTF(("%s: ubsa lsr = 0x%02x, msr = 0x%02x\n",
    434        1.5    dyoung 	    device_xname(sc->sc_dev), sc->sc_lsr, sc->sc_msr));
    435        1.1    ichiro 
    436        1.1    ichiro 	for (i = 0; i < sc->sc_numif; i++) {
    437        1.4      cube 		ucom_status_change(device_private(sc->sc_subdevs[i]));
    438        1.1    ichiro 	}
    439        1.1    ichiro }
    440        1.1    ichiro 
    441        1.2    ichiro void
    442        1.1    ichiro ubsa_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
    443        1.1    ichiro {
    444        1.1    ichiro 	struct ubsa_softc *sc = addr;
    445        1.1    ichiro 
    446        1.1    ichiro 	DPRINTF(("ubsa_get_status\n"));
    447        1.1    ichiro 
    448  1.10.18.1  christos 	*lsr = sc->sc_lsr;
    449  1.10.18.1  christos 	*msr = sc->sc_msr;
    450        1.1    ichiro }
    451        1.1    ichiro 
    452