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