Home | History | Annotate | Line # | Download | only in usb
uplcom.c revision 1.12
      1 /*	$NetBSD: uplcom.c,v 1.12 2001/03/14 15:53:01 ichiro Exp $	*/
      2 /*
      3  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to The NetBSD Foundation
      7  * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *        This product includes software developed by the NetBSD
     20  *        Foundation, Inc. and its contributors.
     21  * 4. Neither the name of The NetBSD Foundation nor the names of its
     22  *    contributors may be used to endorse or promote products derived
     23  *    from this software without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 /*
     39  * Simple datasheet
     40  * http://www.prolific.com.tw/download/DataSheet/pl2303_ds11.PDF
     41  * http://www.nisseisg.co.jp/jyouhou/_cp/@gif/2303.pdf
     42  * 	(english)
     43  *
     44  */
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/kernel.h>
     49 #include <sys/malloc.h>
     50 #include <sys/ioctl.h>
     51 #include <sys/conf.h>
     52 #include <sys/tty.h>
     53 #include <sys/file.h>
     54 #include <sys/select.h>
     55 #include <sys/proc.h>
     56 #include <sys/vnode.h>
     57 #include <sys/device.h>
     58 #include <sys/poll.h>
     59 
     60 #include <dev/usb/usb.h>
     61 #include <dev/usb/usbcdc.h>
     62 
     63 #include <dev/usb/usbdi.h>
     64 #include <dev/usb/usbdi_util.h>
     65 #include <dev/usb/usbdevs.h>
     66 #include <dev/usb/usb_quirks.h>
     67 
     68 #include <dev/usb/usbdevs.h>
     69 #include <dev/usb/ucomvar.h>
     70 
     71 #ifdef UPLCOM_DEBUG
     72 #define DPRINTFN(n, x)  if (uplcomdebug > (n)) logprintf x
     73 int	uplcomdebug = 0;
     74 #else
     75 #define DPRINTFN(n, x)
     76 #endif
     77 #define DPRINTF(x) DPRINTFN(0, x)
     78 
     79 #define	UPLCOM_CONFIG_INDEX	0
     80 #define	UPLCOM_IFACE_INDEX	0
     81 #define	UPLCOM_SECOND_IFACE_INDEX	1
     82 #define	UPLCOM_RESET		0
     83 
     84 #define RSAQ_STATUS_DSR		0x02
     85 #define RSAQ_STATUS_DCD		0x01
     86 
     87 struct	uplcom_softc {
     88 	USBBASEDEVICE		sc_dev;		/* base device */
     89 	usbd_device_handle	sc_udev;	/* USB device */
     90 	usbd_interface_handle	sc_iface;	/* first interface */
     91 	usbd_interface_handle	sc_sec_iface;	/* second interface */
     92 	int			sc_iface_number;	/* interface number */
     93 
     94 	int			sc_intr_number;	/* interrupt number */
     95 	usbd_pipe_handle	sc_intr_pipe;	/* interrupt pipe */
     96 	u_char			*sc_intr_buf;	/* interrupt buffer */
     97 	int			sc_isize;
     98 
     99 	usb_cdc_line_state_t	sc_line_state;	/* current line state */
    100 	u_char			sc_dtr;		/* current DTR state */
    101 	u_char			sc_rts;		/* current RTS state */
    102 	u_char			sc_status;
    103 
    104 	device_ptr_t		sc_subdev;	/* ucom device */
    105 
    106 	u_char			sc_dying;
    107 
    108 	u_char			sc_lsr;		/* Local status register */
    109 	u_char			sc_msr;		/* uplcom status register */
    110 };
    111 
    112 /*
    113  * These are the maximum number of bytes transferred per frame.
    114  * The output buffer size cannot be increased due to the size encoding.
    115  */
    116 #define UPLCOMIBUFSIZE 256
    117 #define UPLCOMOBUFSIZE 256
    118 
    119 Static	usbd_status uplcom_reset(struct uplcom_softc *);
    120 Static	usbd_status uplcom_set_line_coding(struct uplcom_softc *sc,
    121 					   usb_cdc_line_state_t *state);
    122 Static	void uplcom_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
    123 
    124 Static	void uplcom_set(void *, int, int, int);
    125 Static	void uplcom_dtr(struct uplcom_softc *, int);
    126 Static	void uplcom_rts(struct uplcom_softc *, int);
    127 Static	void uplcom_break(struct uplcom_softc *, int);
    128 Static	void uplcom_set_line_state(struct uplcom_softc *);
    129 Static	void uplcom_get_status(void *, int portno, u_char *lsr, u_char *msr);
    130 #if TODO
    131 Static	int  uplcom_ioctl(void *, int, u_long, caddr_t, int, struct proc *);
    132 #endif
    133 Static	int  uplcom_param(void *, int, struct termios *);
    134 Static	int  uplcom_open(void *, int);
    135 Static	void uplcom_close(void *, int);
    136 
    137 struct	ucom_methods uplcom_methods = {
    138 	uplcom_get_status,
    139 	uplcom_set,
    140 	uplcom_param,
    141 	NULL, /* uplcom_ioctl, TODO */
    142 	uplcom_open,
    143 	uplcom_close,
    144 	NULL,
    145 	NULL,
    146 };
    147 
    148 static const struct uplcom_product {
    149 	uint16_t	vendor;
    150 	uint16_t	product;
    151 } uplcom_products [] = {
    152 	/* I/O DATA USB-RSAQ2 */
    153 	{ USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303 },
    154 	{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBRSAQ },
    155 
    156 	{ 0, 0 }
    157 };
    158 
    159 USB_DECLARE_DRIVER(uplcom);
    160 
    161 USB_MATCH(uplcom)
    162 {
    163 	USB_MATCH_START(uplcom, uaa);
    164 	int i;
    165 
    166 	if (uaa->iface != NULL)
    167 		return (UMATCH_NONE);
    168 
    169 	for (i = 0; uplcom_products[i].vendor != 0; i++) {
    170 		if (uplcom_products[i].vendor == uaa->vendor &&
    171  		    uplcom_products[i].product == uaa->product) {
    172 			return (UMATCH_VENDOR_PRODUCT);
    173 		}
    174 	}
    175 	return (UMATCH_NONE);
    176 }
    177 
    178 USB_ATTACH(uplcom)
    179 {
    180 	USB_ATTACH_START(uplcom, sc, uaa);
    181 	usbd_device_handle dev = uaa->device;
    182 	usb_config_descriptor_t *cdesc;
    183 	usb_interface_descriptor_t *id;
    184 	usb_endpoint_descriptor_t *ed;
    185 
    186 	char devinfo[1024];
    187 	char *devname = USBDEVNAME(sc->sc_dev);
    188 	usbd_status err;
    189 	int i;
    190 	struct ucom_attach_args uca;
    191 
    192         usbd_devinfo(dev, 0, devinfo);
    193         USB_ATTACH_SETUP;
    194         printf("%s: %s\n", devname, devinfo);
    195 
    196         sc->sc_udev = dev;
    197 
    198 	DPRINTF(("\n\nuplcom attach: sc=%p\n", sc));
    199 
    200 	/* Move the device into the configured state. */
    201 	err = usbd_set_config_index(dev, UPLCOM_CONFIG_INDEX, 1);
    202 	if (err) {
    203 		printf("\n%s: failed to set configuration, err=%s\n",
    204 			devname, usbd_errstr(err));
    205 		USB_ATTACH_ERROR_RETURN;
    206 	}
    207 
    208 	/* get the config descriptor */
    209 	cdesc = usbd_get_config_descriptor(sc->sc_udev);
    210 
    211 	if (cdesc == NULL) {
    212 		printf("%s: failed to get configuration descriptor\n",
    213 			USBDEVNAME(sc->sc_dev));
    214 		USB_ATTACH_ERROR_RETURN;
    215 	}
    216 
    217 	/* get the (first) interface */
    218 	err = usbd_device2interface_handle(dev, UPLCOM_IFACE_INDEX,
    219 							&sc->sc_iface);
    220 	if (err) {
    221 		printf("\n%s: failed to get interface, err=%s\n",
    222 			devname, usbd_errstr(err));
    223 		USB_ATTACH_ERROR_RETURN;
    224 	}
    225 	/*
    226 	 * check second interface
    227 	 * USB-RSAQ has two interface
    228 	 */
    229 	if (cdesc->bNumInterface == 2) {
    230 		err = usbd_device2interface_handle(dev,
    231 				UPLCOM_SECOND_IFACE_INDEX, &sc->sc_sec_iface);
    232 		if (err) {
    233 			printf("\n%s: failed to get second interface, err=%s\n",
    234 							devname, usbd_errstr(err));
    235 			USB_ATTACH_ERROR_RETURN;
    236 		}
    237 		sc->sc_iface = sc->sc_sec_iface;
    238 	}
    239 
    240 	/* Find the bulk endpoints */
    241 
    242 	id = usbd_get_interface_descriptor(sc->sc_iface);
    243 	sc->sc_iface_number = id->bInterfaceNumber;
    244 
    245 	uca.bulkin = uca.bulkout = -1;
    246 	sc->sc_intr_number = -1;
    247 	sc->sc_intr_pipe = NULL;
    248 	for (i = 0; i < id->bNumEndpoints; i++) {
    249 		ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
    250 		if (ed == NULL) {
    251 			printf("%s: no endpoint descriptor for %d\n",
    252 				USBDEVNAME(sc->sc_dev), i);
    253 			USB_ATTACH_ERROR_RETURN;
    254 		}
    255 
    256 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    257 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
    258 			uca.bulkin = ed->bEndpointAddress;
    259 		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    260 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
    261 			sc->sc_intr_number = ed->bEndpointAddress;
    262 			sc->sc_isize = UGETW(ed->wMaxPacketSize);
    263 		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
    264 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
    265 			uca.bulkout = ed->bEndpointAddress;
    266 		}
    267 	}
    268 
    269 	if (uca.bulkin == -1) {
    270 		printf("%s: Could not find data bulk in\n",
    271 			USBDEVNAME(sc->sc_dev));
    272 		USB_ATTACH_ERROR_RETURN;
    273 	}
    274 
    275 	if (uca.bulkout == -1) {
    276 		printf("%s: Could not find data bulk out\n",
    277 			USBDEVNAME(sc->sc_dev));
    278 		USB_ATTACH_ERROR_RETURN;
    279 	}
    280 
    281 	if (sc->sc_intr_number== -1) {
    282 		printf("%s: Could not find interrupt in\n",
    283 			USBDEVNAME(sc->sc_dev));
    284 		USB_ATTACH_ERROR_RETURN;
    285 	}
    286 
    287 	sc->sc_dtr = sc->sc_rts = -1;
    288 	uca.portno = UCOM_UNK_PORTNO;
    289 	/* bulkin, bulkout set above */
    290 	uca.ibufsize = UPLCOMIBUFSIZE;
    291 	uca.obufsize = UPLCOMOBUFSIZE;
    292 	uca.ibufsizepad = UPLCOMIBUFSIZE;
    293 	uca.opkthdrlen = 0;
    294 	uca.device = dev;
    295 	uca.iface = sc->sc_iface;
    296 	uca.methods = &uplcom_methods;
    297 	uca.arg = sc;
    298 	uca.info = NULL;
    299 
    300 	err = uplcom_reset(sc);
    301 
    302 	if (err) {
    303 		printf("%s: reset failed, %s\n", USBDEVNAME(sc->sc_dev),
    304 			usbd_errstr(err));
    305 		USB_ATTACH_ERROR_RETURN;
    306 	}
    307 
    308 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
    309 			   USBDEV(sc->sc_dev));
    310 
    311 	DPRINTF(("uplcom: in=0x%x out=0x%x intr=0x%x\n",
    312 			uca.bulkin, uca.bulkout, sc->sc_intr_number ));
    313 	sc->sc_subdev = config_found_sm(self, &uca, ucomprint, ucomsubmatch);
    314 
    315 	USB_ATTACH_SUCCESS_RETURN;
    316 }
    317 
    318 USB_DETACH(uplcom)
    319 {
    320 	USB_DETACH_START(uplcom, sc);
    321 	int rv = 0;
    322 
    323 	DPRINTF(("uplcom_detach: sc=%p flags=%d\n", sc, flags));
    324 
    325         if (sc->sc_intr_pipe != NULL) {
    326                 usbd_abort_pipe(sc->sc_intr_pipe);
    327                 usbd_close_pipe(sc->sc_intr_pipe);
    328 		free(sc->sc_intr_buf, M_USBDEV);
    329                 sc->sc_intr_pipe = NULL;
    330         }
    331 
    332 	sc->sc_dying = 1;
    333 	if (sc->sc_subdev != NULL) {
    334 		rv = config_detach(sc->sc_subdev, flags);
    335 		sc->sc_subdev = NULL;
    336 	}
    337 
    338 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
    339 			   USBDEV(sc->sc_dev));
    340 
    341 	return (rv);
    342 }
    343 
    344 int
    345 uplcom_activate(device_ptr_t self, enum devact act)
    346 {
    347 	struct uplcom_softc *sc = (struct uplcom_softc *)self;
    348 	int rv = 0;
    349 
    350 	switch (act) {
    351 	case DVACT_ACTIVATE:
    352 		return (EOPNOTSUPP);
    353 		break;
    354 
    355 	case DVACT_DEACTIVATE:
    356 		if (sc->sc_subdev != NULL)
    357 			rv = config_deactivate(sc->sc_subdev);
    358 		sc->sc_dying = 1;
    359 		break;
    360 	}
    361 	return (rv);
    362 }
    363 
    364 
    365 usbd_status
    366 uplcom_reset(struct uplcom_softc *sc)
    367 {
    368         usb_device_request_t req;
    369 	usbd_status err;
    370 
    371         req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    372         req.bRequest = UPLCOM_RESET;
    373         USETW(req.wValue, UPLCOM_RESET);
    374         USETW(req.wIndex, sc->sc_iface_number);
    375         USETW(req.wLength, 0);
    376 
    377         err = usbd_do_request(sc->sc_udev, &req, 0);
    378 	if (err)
    379 		return (EIO);
    380 
    381 	return (0);
    382 }
    383 
    384 void
    385 uplcom_set_line_state(struct uplcom_softc *sc)
    386 {
    387 	usb_device_request_t req;
    388 	int ls;
    389 
    390 	ls = (sc->sc_dtr ? UCDC_LINE_DTR : 0) |
    391 		(sc->sc_rts ? UCDC_LINE_RTS : 0);
    392 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    393 	req.bRequest = UCDC_SET_CONTROL_LINE_STATE;
    394 	USETW(req.wValue, ls);
    395 	USETW(req.wIndex, sc->sc_iface_number);
    396 	USETW(req.wLength, 0);
    397 
    398 	(void)usbd_do_request(sc->sc_udev, &req, 0);
    399 
    400 }
    401 
    402 void
    403 uplcom_set(void *addr, int portno, int reg, int onoff)
    404 {
    405 	struct uplcom_softc *sc = addr;
    406 
    407 	switch (reg) {
    408 	case UCOM_SET_DTR:
    409 		uplcom_dtr(sc, onoff);
    410 		break;
    411 	case UCOM_SET_RTS:
    412 		uplcom_rts(sc, onoff);
    413 		break;
    414 	case UCOM_SET_BREAK:
    415 		uplcom_break(sc, onoff);
    416 		break;
    417 	default:
    418 		break;
    419 	}
    420 }
    421 
    422 void
    423 uplcom_dtr(struct uplcom_softc *sc, int onoff)
    424 {
    425 
    426 	DPRINTF(("uplcom_dtr: onoff=%d\n", onoff));
    427 
    428 	if (sc->sc_dtr == onoff)
    429 		return;
    430 	sc->sc_dtr = onoff;
    431 
    432 	uplcom_set_line_state(sc);
    433 }
    434 
    435 void
    436 uplcom_rts(struct uplcom_softc *sc, int onoff)
    437 {
    438 	DPRINTF(("uplcom_rts: onoff=%d\n", onoff));
    439 
    440 	if (sc->sc_rts == onoff)
    441 		return;
    442 	sc->sc_rts = onoff;
    443 
    444 	uplcom_set_line_state(sc);
    445 }
    446 
    447 void
    448 uplcom_break(struct uplcom_softc *sc, int onoff)
    449 {
    450 	usb_device_request_t req;
    451 
    452 	DPRINTF(("uplcom_break: onoff=%d\n", onoff));
    453 
    454 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    455 	req.bRequest = UCDC_SEND_BREAK;
    456 	USETW(req.wValue, onoff ? UCDC_BREAK_ON : UCDC_BREAK_OFF);
    457 	USETW(req.wIndex, sc->sc_iface_number);
    458 	USETW(req.wLength, 0);
    459 
    460 	(void)usbd_do_request(sc->sc_udev, &req, 0);
    461 }
    462 
    463 usbd_status
    464 uplcom_set_line_coding(struct uplcom_softc *sc, usb_cdc_line_state_t *state)
    465 {
    466 	usb_device_request_t req;
    467 	usbd_status err;
    468 
    469 	DPRINTF(("uplcom_set_line_coding: rate=%d fmt=%d parity=%d bits=%d\n",
    470 		UGETDW(state->dwDTERate), state->bCharFormat,
    471 		state->bParityType, state->bDataBits));
    472 
    473 	if (memcmp(state, &sc->sc_line_state, UCDC_LINE_STATE_LENGTH) == 0) {
    474 		DPRINTF(("uplcom_set_line_coding: already set\n"));
    475 		return (USBD_NORMAL_COMPLETION);
    476 	}
    477 
    478 	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    479 	req.bRequest = UCDC_SET_LINE_CODING;
    480 	USETW(req.wValue, 0);
    481 	USETW(req.wIndex, sc->sc_iface_number);
    482 	USETW(req.wLength, UCDC_LINE_STATE_LENGTH);
    483 
    484 	err = usbd_do_request(sc->sc_udev, &req, state);
    485 	if (err) {
    486 		DPRINTF(("uplcom_set_line_coding: failed, err=%s\n",
    487 			usbd_errstr(err)));
    488 		return (err);
    489 	}
    490 
    491 	sc->sc_line_state = *state;
    492 
    493 	return (USBD_NORMAL_COMPLETION);
    494 }
    495 
    496 int
    497 uplcom_param(void *addr, int portno, struct termios *t)
    498 {
    499 	struct uplcom_softc *sc = addr;
    500 	usbd_status err;
    501 	usb_cdc_line_state_t ls;
    502 
    503 	DPRINTF(("uplcom_param: sc=%p\n", sc));
    504 
    505 	USETDW(ls.dwDTERate, t->c_ospeed);
    506 	if (ISSET(t->c_cflag, CSTOPB))
    507 		ls.bCharFormat = UCDC_STOP_BIT_2;
    508 	else
    509 		ls.bCharFormat = UCDC_STOP_BIT_1;
    510 	if (ISSET(t->c_cflag, PARENB)) {
    511 		if (ISSET(t->c_cflag, PARODD))
    512 			ls.bParityType = UCDC_PARITY_ODD;
    513 		else
    514 			ls.bParityType = UCDC_PARITY_EVEN;
    515 	} else
    516 		ls.bParityType = UCDC_PARITY_NONE;
    517 	switch (ISSET(t->c_cflag, CSIZE)) {
    518 	case CS5:
    519 		ls.bDataBits = 5;
    520 		break;
    521 	case CS6:
    522 		ls.bDataBits = 6;
    523 		break;
    524 	case CS7:
    525 		ls.bDataBits = 7;
    526 		break;
    527 	case CS8:
    528 		ls.bDataBits = 8;
    529 		break;
    530 	}
    531 
    532 	err = uplcom_set_line_coding(sc, &ls);
    533 	if (err) {
    534 		DPRINTF(("uplcom_param: err=%s\n", usbd_errstr(err)));
    535 		return (EIO);
    536 	}
    537 	return (0);
    538 }
    539 
    540 int
    541 uplcom_open(void *addr, int portno)
    542 {
    543 	struct uplcom_softc *sc = addr;
    544 	int err;
    545 
    546 	if (sc->sc_dying)
    547 		return (EIO);
    548 
    549 	DPRINTF(("uplcom_open: sc=%p\n", sc));
    550 
    551 	if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
    552 		sc->sc_status = 0; /* clear status bit */
    553 		sc->sc_intr_buf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK);
    554 		err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_intr_number,
    555 			USBD_SHORT_XFER_OK, &sc->sc_intr_pipe, sc,
    556 			sc->sc_intr_buf, sc->sc_isize,
    557 			uplcom_intr, USBD_DEFAULT_INTERVAL);
    558 		if (err) {
    559 			DPRINTF(("%s: cannot open interrupt pipe (addr %d)\n",
    560 				USBDEVNAME(sc->sc_dev), sc->sc_intr_number));
    561 					return (EIO);
    562 		}
    563 	}
    564 
    565 	return (0);
    566 }
    567 
    568 void
    569 uplcom_close(void *addr, int portno)
    570 {
    571 	struct uplcom_softc *sc = addr;
    572 	int err;
    573 
    574 	if (sc->sc_dying)
    575 		return;
    576 
    577 	DPRINTF(("uplcom_close: close\n"));
    578 
    579 	if (sc->sc_intr_pipe != NULL) {
    580 		err = usbd_abort_pipe(sc->sc_intr_pipe);
    581 		if (err)
    582 			printf("%s: abort interrupt pipe failed: %s\n",
    583 				USBDEVNAME(sc->sc_dev), usbd_errstr(err));
    584 		err = usbd_close_pipe(sc->sc_intr_pipe);
    585 		if (err)
    586 			printf("%s: close interrupt pipe failed: %s\n",
    587 				USBDEVNAME(sc->sc_dev), usbd_errstr(err));
    588 		free(sc->sc_intr_buf, M_USBDEV);
    589 		sc->sc_intr_pipe = NULL;
    590 	}
    591 }
    592 
    593 void
    594 uplcom_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
    595 {
    596 	struct uplcom_softc *sc = priv;
    597 	u_char *buf = sc->sc_intr_buf;
    598 	u_char pstatus;
    599 
    600 	if (sc->sc_dying)
    601 		return;
    602 
    603 	if (status != USBD_NORMAL_COMPLETION) {
    604 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
    605 			return;
    606 
    607 		DPRINTF(("%s: abnormal status: %s\n", USBDEVNAME(sc->sc_dev),
    608 			usbd_errstr(status)));
    609 		usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
    610 		return;
    611 	}
    612 
    613 	DPRINTF(("%s: uplcom status = %02x\n", USBDEVNAME(sc->sc_dev), buf[8]));
    614 
    615 		sc->sc_lsr = sc->sc_msr = 0;
    616 		pstatus = buf[8];
    617 		if (ISSET(pstatus, RSAQ_STATUS_DSR))
    618 			sc->sc_msr |= UMSR_DSR;
    619 		if (ISSET(pstatus, RSAQ_STATUS_DCD))
    620 			sc->sc_msr |= UMSR_DCD;
    621 		ucom_status_change((struct ucom_softc *) sc->sc_subdev);
    622 }
    623 
    624 void
    625 uplcom_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
    626 {
    627 	struct uplcom_softc *sc = addr;
    628 
    629 	DPRINTF(("uplcom_get_status:\n"));
    630 
    631 	if (lsr != NULL)
    632 		*lsr = sc->sc_lsr;
    633 	if (msr != NULL)
    634 		*msr = sc->sc_msr;
    635 }
    636 
    637 #if TODO
    638 int
    639 uplcom_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
    640 	     struct proc *p)
    641 {
    642 	struct uplcom_softc *sc = addr;
    643 	int error = 0;
    644 
    645 	if (sc->sc_dying)
    646 		return (EIO);
    647 
    648 	DPRINTF(("uplcom_ioctl: cmd=0x%08lx\n", cmd));
    649 
    650 	switch (cmd) {
    651 	case TIOCNOTTY:
    652 	case TIOCMGET:
    653 	case TIOCMSET:
    654 	case USB_GET_CM_OVER_DATA:
    655 	case USB_SET_CM_OVER_DATA:
    656 		break;
    657 
    658 	default:
    659 		DPRINTF(("uplcom_ioctl: unknown\n"));
    660 		error = ENOTTY;
    661 		break;
    662 	}
    663 
    664 	return (error);
    665 }
    666 #endif
    667