2 * Copyright (c) 2001-2002, Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $NetBSD: usb/uvscom.c,v 1.1 2002/03/19 15:08:42 augustss Exp $
27 * $FreeBSD: src/sys/dev/usb/uvscom.c,v 1.19 2003/11/16 12:26:10 akiyama Exp $
31 * uvscom: SUNTAC Slipper U VS-10U driver.
32 * Slipper U is a PC card to USB converter for data communication card
33 * adapter. It supports DDI Pocket's Air H" C@rd, C@rd H" 64, NTT's P-in,
34 * P-in m@ater and various data communication card adapters.
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/malloc.h>
41 #include <sys/fcntl.h>
46 #include <sys/select.h>
49 #include <sys/sysctl.h>
51 #include <bus/usb/usb.h>
52 #include <bus/usb/usbcdc.h>
54 #include <bus/usb/usbdi.h>
55 #include <bus/usb/usbdi_util.h>
56 #include <bus/usb/usb_quirks.h>
58 #include "../ucom/ucomvar.h"
61 static int uvscomdebug = 0;
62 SYSCTL_NODE(_hw_usb, OID_AUTO, uvscom, CTLFLAG_RW, 0, "USB uvscom");
63 SYSCTL_INT(_hw_usb_uvscom, OID_AUTO, debug, CTLFLAG_RW,
64 &uvscomdebug, 0, "uvscom debug level");
66 #define DPRINTFN(n, x) do { \
67 if (uvscomdebug > (n)) \
71 #define DPRINTFN(n, x)
73 #define DPRINTF(x) DPRINTFN(0, x)
75 #define UVSCOM_MODVER 1 /* module version */
77 #define UVSCOM_CONFIG_INDEX 0
78 #define UVSCOM_IFACE_INDEX 0
80 #define UVSCOM_INTR_INTERVAL 100 /* mS */
82 #define UVSCOM_UNIT_WAIT 5
85 #define UVSCOM_SET_SPEED 0x10
86 #define UVSCOM_LINE_CTL 0x11
87 #define UVSCOM_SET_PARAM 0x12
88 #define UVSCOM_READ_STATUS 0xd0
89 #define UVSCOM_SHUTDOWN 0xe0
91 /* UVSCOM_SET_SPEED parameters */
92 #define UVSCOM_SPEED_150BPS 0x00
93 #define UVSCOM_SPEED_300BPS 0x01
94 #define UVSCOM_SPEED_600BPS 0x02
95 #define UVSCOM_SPEED_1200BPS 0x03
96 #define UVSCOM_SPEED_2400BPS 0x04
97 #define UVSCOM_SPEED_4800BPS 0x05
98 #define UVSCOM_SPEED_9600BPS 0x06
99 #define UVSCOM_SPEED_19200BPS 0x07
100 #define UVSCOM_SPEED_38400BPS 0x08
101 #define UVSCOM_SPEED_57600BPS 0x09
102 #define UVSCOM_SPEED_115200BPS 0x0a
104 /* UVSCOM_LINE_CTL parameters */
105 #define UVSCOM_BREAK 0x40
106 #define UVSCOM_RTS 0x02
107 #define UVSCOM_DTR 0x01
108 #define UVSCOM_LINE_INIT 0x08
110 /* UVSCOM_SET_PARAM parameters */
111 #define UVSCOM_DATA_MASK 0x03
112 #define UVSCOM_DATA_BIT_8 0x03
113 #define UVSCOM_DATA_BIT_7 0x02
114 #define UVSCOM_DATA_BIT_6 0x01
115 #define UVSCOM_DATA_BIT_5 0x00
117 #define UVSCOM_STOP_MASK 0x04
118 #define UVSCOM_STOP_BIT_2 0x04
119 #define UVSCOM_STOP_BIT_1 0x00
121 #define UVSCOM_PARITY_MASK 0x18
122 #define UVSCOM_PARITY_EVEN 0x18
124 #define UVSCOM_PARITY_UNK 0x10
126 #define UVSCOM_PARITY_ODD 0x08
127 #define UVSCOM_PARITY_NONE 0x00
130 #define UVSCOM_TXRDY 0x04
131 #define UVSCOM_RXRDY 0x01
133 #define UVSCOM_DCD 0x08
134 #define UVSCOM_NOCARD 0x04
135 #define UVSCOM_DSR 0x02
136 #define UVSCOM_CTS 0x01
137 #define UVSCOM_USTAT_MASK (UVSCOM_NOCARD | UVSCOM_DSR | UVSCOM_CTS)
139 struct uvscom_softc {
140 struct ucom_softc sc_ucom;
142 int sc_iface_number;/* interface number */
144 usbd_interface_handle sc_intr_iface; /* interrupt interface */
145 int sc_intr_number; /* interrupt number */
146 usbd_pipe_handle sc_intr_pipe; /* interrupt pipe */
147 u_char *sc_intr_buf; /* interrupt buffer */
150 u_char sc_dtr; /* current DTR state */
151 u_char sc_rts; /* current RTS state */
153 u_char sc_lsr; /* Local status register */
154 u_char sc_msr; /* uvscom status register */
156 uint16_t sc_lcr; /* Line control */
157 u_char sc_usr; /* unit status */
161 * These are the maximum number of bytes transferred per frame.
162 * The output buffer size cannot be increased due to the size encoding.
164 #define UVSCOMIBUFSIZE 512
165 #define UVSCOMOBUFSIZE 64
167 static usbd_status uvscom_shutdown(struct uvscom_softc *);
168 static usbd_status uvscom_reset(struct uvscom_softc *);
169 static usbd_status uvscom_set_line_coding(struct uvscom_softc *,
171 static usbd_status uvscom_set_line(struct uvscom_softc *, uint16_t);
172 static usbd_status uvscom_set_crtscts(struct uvscom_softc *);
173 static void uvscom_get_status(void *, int, u_char *, u_char *);
174 static void uvscom_dtr(struct uvscom_softc *, int);
175 static void uvscom_rts(struct uvscom_softc *, int);
176 static void uvscom_break(struct uvscom_softc *, int);
178 static void uvscom_set(void *, int, int, int);
179 static void uvscom_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
181 static int uvscom_ioctl(void *, int, u_long, caddr_t, int, struct thread *);
183 static int uvscom_param(void *, int, struct termios *);
184 static int uvscom_open(void *, int);
185 static void uvscom_close(void *, int);
187 struct ucom_callback uvscom_callback = {
191 NULL, /* uvscom_ioctl, TODO */
198 static const struct usb_devno uvscom_devs [] = {
199 { USB_DEVICE(0x05db, 0x0003) }, /* SUNTAC U-Cable type D2 */
200 { USB_DEVICE(0x05db, 0x0005) }, /* SUNTAC U-Cable type P1 */
201 { USB_DEVICE(0x05db, 0x0009) }, /* SUNTAC Slipper U */
202 { USB_DEVICE(0x05db, 0x000a) }, /* SUNTAC Ir-Trinity */
203 { USB_DEVICE(0x05db, 0x0011) }, /* SUNTAC U-Cable type */
206 static device_probe_t uvscom_match;
207 static device_attach_t uvscom_attach;
208 static device_detach_t uvscom_detach;
210 static device_method_t uvscom_methods[] = {
211 /* Device interface */
212 DEVMETHOD(device_probe, uvscom_match),
213 DEVMETHOD(device_attach, uvscom_attach),
214 DEVMETHOD(device_detach, uvscom_detach),
218 static driver_t uvscom_driver = {
221 sizeof (struct uvscom_softc)
224 DRIVER_MODULE(uvscom, uhub, uvscom_driver, ucom_devclass, usbd_driver_load, NULL);
225 MODULE_DEPEND(uvscom, ucom, UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);
226 MODULE_VERSION(uvscom, UVSCOM_MODVER);
229 uvscom_match(device_t self)
231 struct usb_attach_arg *uaa = device_get_ivars(self);
233 if (uaa->iface != NULL)
234 return (UMATCH_NONE);
236 return (usb_lookup(uvscom_devs, uaa->vendor, uaa->product) != NULL ?
237 UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
241 uvscom_attach(device_t self)
243 struct uvscom_softc *sc = device_get_softc(self);
244 struct usb_attach_arg *uaa = device_get_ivars(self);
245 usbd_device_handle dev = uaa->device;
246 struct ucom_softc *ucom;
247 usb_config_descriptor_t *cdesc;
248 usb_interface_descriptor_t *id;
249 usb_endpoint_descriptor_t *ed;
256 bzero(sc, sizeof (struct uvscom_softc));
260 ucom->sc_iface = uaa->iface;
262 devname = device_get_nameunit(ucom->sc_dev);
264 DPRINTF(("uvscom attach: sc = %p\n", sc));
266 /* initialize endpoints */
267 ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
268 sc->sc_intr_number = -1;
269 sc->sc_intr_pipe = NULL;
271 /* Move the device into the configured state. */
272 err = usbd_set_config_index(dev, UVSCOM_CONFIG_INDEX, 1);
274 kprintf("%s: failed to set configuration, err=%s\n",
275 devname, usbd_errstr(err));
279 /* get the config descriptor */
280 cdesc = usbd_get_config_descriptor(ucom->sc_udev);
283 kprintf("%s: failed to get configuration descriptor\n",
284 device_get_nameunit(ucom->sc_dev));
288 /* get the common interface */
289 err = usbd_device2interface_handle(dev, UVSCOM_IFACE_INDEX,
292 kprintf("%s: failed to get interface, err=%s\n",
293 devname, usbd_errstr(err));
297 id = usbd_get_interface_descriptor(ucom->sc_iface);
298 sc->sc_iface_number = id->bInterfaceNumber;
301 for (i = 0; i < id->bNumEndpoints; i++) {
302 ed = usbd_interface2endpoint_descriptor(ucom->sc_iface, i);
304 kprintf("%s: no endpoint descriptor for %d\n",
305 device_get_nameunit(ucom->sc_dev), i);
309 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
310 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
311 ucom->sc_bulkin_no = ed->bEndpointAddress;
312 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
313 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
314 ucom->sc_bulkout_no = ed->bEndpointAddress;
315 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
316 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
317 sc->sc_intr_number = ed->bEndpointAddress;
318 sc->sc_isize = UGETW(ed->wMaxPacketSize);
322 if (ucom->sc_bulkin_no == -1) {
323 kprintf("%s: Could not find data bulk in\n",
324 device_get_nameunit(ucom->sc_dev));
327 if (ucom->sc_bulkout_no == -1) {
328 kprintf("%s: Could not find data bulk out\n",
329 device_get_nameunit(ucom->sc_dev));
332 if (sc->sc_intr_number == -1) {
333 kprintf("%s: Could not find interrupt in\n",
334 device_get_nameunit(ucom->sc_dev));
338 sc->sc_dtr = sc->sc_rts = 0;
339 sc->sc_lcr = UVSCOM_LINE_INIT;
341 ucom->sc_parent = sc;
342 ucom->sc_portno = UCOM_UNK_PORTNO;
343 /* bulkin, bulkout set above */
344 ucom->sc_ibufsize = UVSCOMIBUFSIZE;
345 ucom->sc_obufsize = UVSCOMOBUFSIZE;
346 ucom->sc_ibufsizepad = UVSCOMIBUFSIZE;
347 ucom->sc_opkthdrlen = 0;
348 ucom->sc_callback = &uvscom_callback;
350 err = uvscom_reset(sc);
353 kprintf("%s: reset failed, %s\n", device_get_nameunit(ucom->sc_dev),
358 DPRINTF(("uvscom: in = 0x%x out = 0x%x intr = 0x%x\n",
359 ucom->sc_bulkin_no, ucom->sc_bulkout_no, sc->sc_intr_number));
361 ucom_attach(&sc->sc_ucom);
371 uvscom_detach(device_t self)
373 struct uvscom_softc *sc = device_get_softc(self);
376 DPRINTF(("uvscom_detach: sc = %p\n", sc));
378 sc->sc_ucom.sc_dying = 1;
380 if (sc->sc_intr_pipe != NULL) {
381 usbd_abort_pipe(sc->sc_intr_pipe);
382 usbd_close_pipe(sc->sc_intr_pipe);
383 kfree(sc->sc_intr_buf, M_USBDEV);
384 sc->sc_intr_pipe = NULL;
387 rv = ucom_detach(&sc->sc_ucom);
393 uvscom_readstat(struct uvscom_softc *sc)
395 usb_device_request_t req;
399 DPRINTF(("%s: send readstat\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
401 req.bmRequestType = UT_READ_VENDOR_DEVICE;
402 req.bRequest = UVSCOM_READ_STATUS;
403 USETW(req.wValue, 0);
404 USETW(req.wIndex, 0);
405 USETW(req.wLength, 2);
407 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, &r);
409 kprintf("%s: uvscom_readstat: %s\n",
410 device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
414 DPRINTF(("%s: uvscom_readstat: r = %d\n",
415 device_get_nameunit(sc->sc_ucom.sc_dev), r));
417 return (USBD_NORMAL_COMPLETION);
421 uvscom_shutdown(struct uvscom_softc *sc)
423 usb_device_request_t req;
426 DPRINTF(("%s: send shutdown\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
428 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
429 req.bRequest = UVSCOM_SHUTDOWN;
430 USETW(req.wValue, 0);
431 USETW(req.wIndex, 0);
432 USETW(req.wLength, 0);
434 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
436 kprintf("%s: uvscom_shutdown: %s\n",
437 device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
441 return (USBD_NORMAL_COMPLETION);
445 uvscom_reset(struct uvscom_softc *sc)
447 DPRINTF(("%s: uvscom_reset\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
449 return (USBD_NORMAL_COMPLETION);
453 uvscom_set_crtscts(struct uvscom_softc *sc)
455 DPRINTF(("%s: uvscom_set_crtscts\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
457 return (USBD_NORMAL_COMPLETION);
461 uvscom_set_line(struct uvscom_softc *sc, uint16_t line)
463 usb_device_request_t req;
466 DPRINTF(("%s: uvscom_set_line: %04x\n",
467 device_get_nameunit(sc->sc_ucom.sc_dev), line));
469 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
470 req.bRequest = UVSCOM_LINE_CTL;
471 USETW(req.wValue, line);
472 USETW(req.wIndex, 0);
473 USETW(req.wLength, 0);
475 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
477 kprintf("%s: uvscom_set_line: %s\n",
478 device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
482 return (USBD_NORMAL_COMPLETION);
486 uvscom_set_line_coding(struct uvscom_softc *sc, uint16_t lsp, uint16_t ls)
488 usb_device_request_t req;
491 DPRINTF(("%s: uvscom_set_line_coding: %02x %02x\n",
492 device_get_nameunit(sc->sc_ucom.sc_dev), lsp, ls));
494 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
495 req.bRequest = UVSCOM_SET_SPEED;
496 USETW(req.wValue, lsp);
497 USETW(req.wIndex, 0);
498 USETW(req.wLength, 0);
500 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
502 kprintf("%s: uvscom_set_line_coding: %s\n",
503 device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
507 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
508 req.bRequest = UVSCOM_SET_PARAM;
509 USETW(req.wValue, ls);
510 USETW(req.wIndex, 0);
511 USETW(req.wLength, 0);
513 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
515 kprintf("%s: uvscom_set_line_coding: %s\n",
516 device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
520 return (USBD_NORMAL_COMPLETION);
524 uvscom_dtr(struct uvscom_softc *sc, int onoff)
526 DPRINTF(("%s: uvscom_dtr: onoff = %d\n",
527 device_get_nameunit(sc->sc_ucom.sc_dev), onoff));
529 if (sc->sc_dtr == onoff)
530 return; /* no change */
535 SET(sc->sc_lcr, UVSCOM_DTR);
537 CLR(sc->sc_lcr, UVSCOM_DTR);
539 uvscom_set_line(sc, sc->sc_lcr);
543 uvscom_rts(struct uvscom_softc *sc, int onoff)
545 DPRINTF(("%s: uvscom_rts: onoff = %d\n",
546 device_get_nameunit(sc->sc_ucom.sc_dev), onoff));
548 if (sc->sc_rts == onoff)
549 return; /* no change */
554 SET(sc->sc_lcr, UVSCOM_RTS);
556 CLR(sc->sc_lcr, UVSCOM_RTS);
558 uvscom_set_line(sc, sc->sc_lcr);
562 uvscom_break(struct uvscom_softc *sc, int onoff)
564 DPRINTF(("%s: uvscom_break: onoff = %d\n",
565 device_get_nameunit(sc->sc_ucom.sc_dev), onoff));
568 uvscom_set_line(sc, SET(sc->sc_lcr, UVSCOM_BREAK));
572 uvscom_set(void *addr, int portno, int reg, int onoff)
574 struct uvscom_softc *sc = addr;
578 uvscom_dtr(sc, onoff);
581 uvscom_rts(sc, onoff);
584 uvscom_break(sc, onoff);
592 uvscom_param(void *addr, int portno, struct termios *t)
594 struct uvscom_softc *sc = addr;
599 DPRINTF(("%s: uvscom_param: sc = %p\n",
600 device_get_nameunit(sc->sc_ucom.sc_dev), sc));
604 switch (t->c_ospeed) {
606 lsp = UVSCOM_SPEED_150BPS;
609 lsp = UVSCOM_SPEED_300BPS;
612 lsp = UVSCOM_SPEED_600BPS;
615 lsp = UVSCOM_SPEED_1200BPS;
618 lsp = UVSCOM_SPEED_2400BPS;
621 lsp = UVSCOM_SPEED_4800BPS;
624 lsp = UVSCOM_SPEED_9600BPS;
627 lsp = UVSCOM_SPEED_19200BPS;
630 lsp = UVSCOM_SPEED_38400BPS;
633 lsp = UVSCOM_SPEED_57600BPS;
636 lsp = UVSCOM_SPEED_115200BPS;
642 if (ISSET(t->c_cflag, CSTOPB))
643 SET(ls, UVSCOM_STOP_BIT_2);
645 SET(ls, UVSCOM_STOP_BIT_1);
647 if (ISSET(t->c_cflag, PARENB)) {
648 if (ISSET(t->c_cflag, PARODD))
649 SET(ls, UVSCOM_PARITY_ODD);
651 SET(ls, UVSCOM_PARITY_EVEN);
653 SET(ls, UVSCOM_PARITY_NONE);
655 switch (ISSET(t->c_cflag, CSIZE)) {
657 SET(ls, UVSCOM_DATA_BIT_5);
660 SET(ls, UVSCOM_DATA_BIT_6);
663 SET(ls, UVSCOM_DATA_BIT_7);
666 SET(ls, UVSCOM_DATA_BIT_8);
672 err = uvscom_set_line_coding(sc, lsp, ls);
676 if (ISSET(t->c_cflag, CRTSCTS)) {
677 err = uvscom_set_crtscts(sc);
686 uvscom_open(void *addr, int portno)
688 struct uvscom_softc *sc = addr;
692 if (sc->sc_ucom.sc_dying)
695 DPRINTF(("uvscom_open: sc = %p\n", sc));
697 if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
698 DPRINTF(("uvscom_open: open interrupt pipe.\n"));
700 sc->sc_usr = 0; /* clear unit status */
702 err = uvscom_readstat(sc);
704 DPRINTF(("%s: uvscom_open: readstat faild\n",
705 device_get_nameunit(sc->sc_ucom.sc_dev)));
709 sc->sc_intr_buf = kmalloc(sc->sc_isize, M_USBDEV, M_WAITOK);
710 err = usbd_open_pipe_intr(sc->sc_ucom.sc_iface,
718 UVSCOM_INTR_INTERVAL);
720 kprintf("%s: cannot open interrupt pipe (addr %d)\n",
721 device_get_nameunit(sc->sc_ucom.sc_dev),
726 DPRINTF(("uvscom_open: did not open interrupt pipe.\n"));
729 if ((sc->sc_usr & UVSCOM_USTAT_MASK) == 0) {
730 /* unit is not ready */
732 for (i = UVSCOM_UNIT_WAIT; i > 0; --i) {
733 tsleep(&err, 0, "uvsop", hz); /* XXX */
734 if (ISSET(sc->sc_usr, UVSCOM_USTAT_MASK))
738 DPRINTF(("%s: unit is not ready\n",
739 device_get_nameunit(sc->sc_ucom.sc_dev)));
743 /* check PC card was inserted */
744 if (ISSET(sc->sc_usr, UVSCOM_NOCARD)) {
745 DPRINTF(("%s: no card\n",
746 device_get_nameunit(sc->sc_ucom.sc_dev)));
755 uvscom_close(void *addr, int portno)
757 struct uvscom_softc *sc = addr;
760 if (sc->sc_ucom.sc_dying)
763 DPRINTF(("uvscom_close: close\n"));
767 if (sc->sc_intr_pipe != NULL) {
768 err = usbd_abort_pipe(sc->sc_intr_pipe);
770 kprintf("%s: abort interrupt pipe failed: %s\n",
771 device_get_nameunit(sc->sc_ucom.sc_dev),
773 err = usbd_close_pipe(sc->sc_intr_pipe);
775 kprintf("%s: close interrupt pipe failed: %s\n",
776 device_get_nameunit(sc->sc_ucom.sc_dev),
778 kfree(sc->sc_intr_buf, M_USBDEV);
779 sc->sc_intr_pipe = NULL;
784 uvscom_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
786 struct uvscom_softc *sc = priv;
787 u_char *buf = sc->sc_intr_buf;
790 if (sc->sc_ucom.sc_dying)
793 if (status != USBD_NORMAL_COMPLETION) {
794 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
797 kprintf("%s: uvscom_intr: abnormal status: %s\n",
798 device_get_nameunit(sc->sc_ucom.sc_dev),
799 usbd_errstr(status));
800 usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
804 DPRINTFN(2, ("%s: uvscom status = %02x %02x\n",
805 device_get_nameunit(sc->sc_ucom.sc_dev), buf[0], buf[1]));
807 sc->sc_lsr = sc->sc_msr = 0;
811 if (ISSET(pstatus, UVSCOM_TXRDY))
812 SET(sc->sc_lsr, ULSR_TXRDY);
813 if (ISSET(pstatus, UVSCOM_RXRDY))
814 SET(sc->sc_lsr, ULSR_RXRDY);
817 if (ISSET(pstatus, UVSCOM_CTS))
818 SET(sc->sc_msr, UMSR_CTS);
819 if (ISSET(pstatus, UVSCOM_DSR))
820 SET(sc->sc_msr, UMSR_DSR);
821 if (ISSET(pstatus, UVSCOM_DCD))
822 SET(sc->sc_msr, UMSR_DCD);
824 ucom_status_change(&sc->sc_ucom);
828 uvscom_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
830 struct uvscom_softc *sc = addr;
840 uvscom_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
843 struct uvscom_softc *sc = addr;
846 if (sc->sc_ucom.sc_dying)
849 DPRINTF(("uvscom_ioctl: cmd = 0x%08lx\n", cmd));
858 DPRINTF(("uvscom_ioctl: unknown\n"));