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 $
28 * $DragonFly: src/sys/dev/usbmisc/uvscom/uvscom.c,v 1.17 2007/11/05 13:32:28 hasso Exp $
32 * uvscom: SUNTAC Slipper U VS-10U driver.
33 * Slipper U is a PC card to USB converter for data communication card
34 * adapter. It supports DDI Pocket's Air H" C@rd, C@rd H" 64, NTT's P-in,
35 * P-in m@ater and various data communication card adapters.
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/malloc.h>
42 #include <sys/fcntl.h>
47 #include <sys/ioccom.h>
48 #include <sys/select.h>
51 #include <sys/sysctl.h>
53 #include <bus/usb/usb.h>
54 #include <bus/usb/usbcdc.h>
56 #include <bus/usb/usbdi.h>
57 #include <bus/usb/usbdi_util.h>
58 #include <bus/usb/usbdevs.h>
59 #include <bus/usb/usb_quirks.h>
61 #include "../ucom/ucomvar.h"
64 static int uvscomdebug = 0;
65 SYSCTL_NODE(_hw_usb, OID_AUTO, uvscom, CTLFLAG_RW, 0, "USB uvscom");
66 SYSCTL_INT(_hw_usb_uvscom, OID_AUTO, debug, CTLFLAG_RW,
67 &uvscomdebug, 0, "uvscom debug level");
69 #define DPRINTFN(n, x) do { \
70 if (uvscomdebug > (n)) \
74 #define DPRINTFN(n, x)
76 #define DPRINTF(x) DPRINTFN(0, x)
78 #define UVSCOM_MODVER 1 /* module version */
80 #define UVSCOM_CONFIG_INDEX 0
81 #define UVSCOM_IFACE_INDEX 0
83 #define UVSCOM_INTR_INTERVAL 100 /* mS */
85 #define UVSCOM_UNIT_WAIT 5
88 #define UVSCOM_SET_SPEED 0x10
89 #define UVSCOM_LINE_CTL 0x11
90 #define UVSCOM_SET_PARAM 0x12
91 #define UVSCOM_READ_STATUS 0xd0
92 #define UVSCOM_SHUTDOWN 0xe0
94 /* UVSCOM_SET_SPEED parameters */
95 #define UVSCOM_SPEED_150BPS 0x00
96 #define UVSCOM_SPEED_300BPS 0x01
97 #define UVSCOM_SPEED_600BPS 0x02
98 #define UVSCOM_SPEED_1200BPS 0x03
99 #define UVSCOM_SPEED_2400BPS 0x04
100 #define UVSCOM_SPEED_4800BPS 0x05
101 #define UVSCOM_SPEED_9600BPS 0x06
102 #define UVSCOM_SPEED_19200BPS 0x07
103 #define UVSCOM_SPEED_38400BPS 0x08
104 #define UVSCOM_SPEED_57600BPS 0x09
105 #define UVSCOM_SPEED_115200BPS 0x0a
107 /* UVSCOM_LINE_CTL parameters */
108 #define UVSCOM_BREAK 0x40
109 #define UVSCOM_RTS 0x02
110 #define UVSCOM_DTR 0x01
111 #define UVSCOM_LINE_INIT 0x08
113 /* UVSCOM_SET_PARAM parameters */
114 #define UVSCOM_DATA_MASK 0x03
115 #define UVSCOM_DATA_BIT_8 0x03
116 #define UVSCOM_DATA_BIT_7 0x02
117 #define UVSCOM_DATA_BIT_6 0x01
118 #define UVSCOM_DATA_BIT_5 0x00
120 #define UVSCOM_STOP_MASK 0x04
121 #define UVSCOM_STOP_BIT_2 0x04
122 #define UVSCOM_STOP_BIT_1 0x00
124 #define UVSCOM_PARITY_MASK 0x18
125 #define UVSCOM_PARITY_EVEN 0x18
127 #define UVSCOM_PARITY_UNK 0x10
129 #define UVSCOM_PARITY_ODD 0x08
130 #define UVSCOM_PARITY_NONE 0x00
133 #define UVSCOM_TXRDY 0x04
134 #define UVSCOM_RXRDY 0x01
136 #define UVSCOM_DCD 0x08
137 #define UVSCOM_NOCARD 0x04
138 #define UVSCOM_DSR 0x02
139 #define UVSCOM_CTS 0x01
140 #define UVSCOM_USTAT_MASK (UVSCOM_NOCARD | UVSCOM_DSR | UVSCOM_CTS)
142 struct uvscom_softc {
143 struct ucom_softc sc_ucom;
145 int sc_iface_number;/* interface number */
147 usbd_interface_handle sc_intr_iface; /* interrupt interface */
148 int sc_intr_number; /* interrupt number */
149 usbd_pipe_handle sc_intr_pipe; /* interrupt pipe */
150 u_char *sc_intr_buf; /* interrupt buffer */
153 u_char sc_dtr; /* current DTR state */
154 u_char sc_rts; /* current RTS state */
156 u_char sc_lsr; /* Local status register */
157 u_char sc_msr; /* uvscom status register */
159 uint16_t sc_lcr; /* Line control */
160 u_char sc_usr; /* unit status */
164 * These are the maximum number of bytes transferred per frame.
165 * The output buffer size cannot be increased due to the size encoding.
167 #define UVSCOMIBUFSIZE 512
168 #define UVSCOMOBUFSIZE 64
170 static usbd_status uvscom_shutdown(struct uvscom_softc *);
171 static usbd_status uvscom_reset(struct uvscom_softc *);
172 static usbd_status uvscom_set_line_coding(struct uvscom_softc *,
174 static usbd_status uvscom_set_line(struct uvscom_softc *, uint16_t);
175 static usbd_status uvscom_set_crtscts(struct uvscom_softc *);
176 static void uvscom_get_status(void *, int, u_char *, u_char *);
177 static void uvscom_dtr(struct uvscom_softc *, int);
178 static void uvscom_rts(struct uvscom_softc *, int);
179 static void uvscom_break(struct uvscom_softc *, int);
181 static void uvscom_set(void *, int, int, int);
182 static void uvscom_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
184 static int uvscom_ioctl(void *, int, u_long, caddr_t, int, struct thread *);
186 static int uvscom_param(void *, int, struct termios *);
187 static int uvscom_open(void *, int);
188 static void uvscom_close(void *, int);
190 struct ucom_callback uvscom_callback = {
194 NULL, /* uvscom_ioctl, TODO */
201 static const struct usb_devno uvscom_devs [] = {
202 { USB_DEVICE(0x05db, 0x0003) }, /* SUNTAC U-Cable type D2 */
203 { USB_DEVICE(0x05db, 0x0005) }, /* SUNTAC U-Cable type P1 */
204 { USB_DEVICE(0x05db, 0x0009) }, /* SUNTAC Slipper U */
205 { USB_DEVICE(0x05db, 0x000a) }, /* SUNTAC Ir-Trinity */
208 static device_probe_t uvscom_match;
209 static device_attach_t uvscom_attach;
210 static device_detach_t uvscom_detach;
212 static device_method_t uvscom_methods[] = {
213 /* Device interface */
214 DEVMETHOD(device_probe, uvscom_match),
215 DEVMETHOD(device_attach, uvscom_attach),
216 DEVMETHOD(device_detach, uvscom_detach),
220 static driver_t uvscom_driver = {
223 sizeof (struct uvscom_softc)
226 DRIVER_MODULE(uvscom, uhub, uvscom_driver, ucom_devclass, usbd_driver_load, 0);
227 MODULE_DEPEND(uvscom, ucom, UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);
228 MODULE_VERSION(uvscom, UVSCOM_MODVER);
231 uvscom_match(device_t self)
233 struct usb_attach_arg *uaa = device_get_ivars(self);
235 if (uaa->iface != NULL)
236 return (UMATCH_NONE);
238 return (usb_lookup(uvscom_devs, uaa->vendor, uaa->product) != NULL ?
239 UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
243 uvscom_attach(device_t self)
245 struct uvscom_softc *sc = device_get_softc(self);
246 struct usb_attach_arg *uaa = device_get_ivars(self);
247 usbd_device_handle dev = uaa->device;
248 struct ucom_softc *ucom;
249 usb_config_descriptor_t *cdesc;
250 usb_interface_descriptor_t *id;
251 usb_endpoint_descriptor_t *ed;
257 devinfo = kmalloc(1024, M_USBDEV, M_INTWAIT);
260 bzero(sc, sizeof (struct uvscom_softc));
262 usbd_devinfo(dev, 0, devinfo);
264 device_set_desc_copy(self, devinfo);
267 ucom->sc_iface = uaa->iface;
269 devname = device_get_nameunit(ucom->sc_dev);
270 kprintf("%s: %s\n", devname, devinfo);
272 DPRINTF(("uvscom attach: sc = %p\n", sc));
274 /* initialize endpoints */
275 ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
276 sc->sc_intr_number = -1;
277 sc->sc_intr_pipe = NULL;
279 /* Move the device into the configured state. */
280 err = usbd_set_config_index(dev, UVSCOM_CONFIG_INDEX, 1);
282 kprintf("%s: failed to set configuration, err=%s\n",
283 devname, usbd_errstr(err));
287 /* get the config descriptor */
288 cdesc = usbd_get_config_descriptor(ucom->sc_udev);
291 kprintf("%s: failed to get configuration descriptor\n",
292 device_get_nameunit(ucom->sc_dev));
296 /* get the common interface */
297 err = usbd_device2interface_handle(dev, UVSCOM_IFACE_INDEX,
300 kprintf("%s: failed to get interface, err=%s\n",
301 devname, usbd_errstr(err));
305 id = usbd_get_interface_descriptor(ucom->sc_iface);
306 sc->sc_iface_number = id->bInterfaceNumber;
309 for (i = 0; i < id->bNumEndpoints; i++) {
310 ed = usbd_interface2endpoint_descriptor(ucom->sc_iface, i);
312 kprintf("%s: no endpoint descriptor for %d\n",
313 device_get_nameunit(ucom->sc_dev), i);
317 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
318 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
319 ucom->sc_bulkin_no = ed->bEndpointAddress;
320 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
321 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
322 ucom->sc_bulkout_no = ed->bEndpointAddress;
323 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
324 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
325 sc->sc_intr_number = ed->bEndpointAddress;
326 sc->sc_isize = UGETW(ed->wMaxPacketSize);
330 if (ucom->sc_bulkin_no == -1) {
331 kprintf("%s: Could not find data bulk in\n",
332 device_get_nameunit(ucom->sc_dev));
335 if (ucom->sc_bulkout_no == -1) {
336 kprintf("%s: Could not find data bulk out\n",
337 device_get_nameunit(ucom->sc_dev));
340 if (sc->sc_intr_number == -1) {
341 kprintf("%s: Could not find interrupt in\n",
342 device_get_nameunit(ucom->sc_dev));
346 sc->sc_dtr = sc->sc_rts = 0;
347 sc->sc_lcr = UVSCOM_LINE_INIT;
349 ucom->sc_parent = sc;
350 ucom->sc_portno = UCOM_UNK_PORTNO;
351 /* bulkin, bulkout set above */
352 ucom->sc_ibufsize = UVSCOMIBUFSIZE;
353 ucom->sc_obufsize = UVSCOMOBUFSIZE;
354 ucom->sc_ibufsizepad = UVSCOMIBUFSIZE;
355 ucom->sc_opkthdrlen = 0;
356 ucom->sc_callback = &uvscom_callback;
358 err = uvscom_reset(sc);
361 kprintf("%s: reset failed, %s\n", device_get_nameunit(ucom->sc_dev),
366 DPRINTF(("uvscom: in = 0x%x out = 0x%x intr = 0x%x\n",
367 ucom->sc_bulkin_no, ucom->sc_bulkout_no, sc->sc_intr_number));
369 ucom_attach(&sc->sc_ucom);
371 kfree(devinfo, M_USBDEV);
376 kfree(devinfo, M_USBDEV);
381 uvscom_detach(device_t self)
383 struct uvscom_softc *sc = device_get_softc(self);
386 DPRINTF(("uvscom_detach: sc = %p\n", sc));
388 sc->sc_ucom.sc_dying = 1;
390 if (sc->sc_intr_pipe != NULL) {
391 usbd_abort_pipe(sc->sc_intr_pipe);
392 usbd_close_pipe(sc->sc_intr_pipe);
393 kfree(sc->sc_intr_buf, M_USBDEV);
394 sc->sc_intr_pipe = NULL;
397 rv = ucom_detach(&sc->sc_ucom);
403 uvscom_readstat(struct uvscom_softc *sc)
405 usb_device_request_t req;
409 DPRINTF(("%s: send readstat\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
411 req.bmRequestType = UT_READ_VENDOR_DEVICE;
412 req.bRequest = UVSCOM_READ_STATUS;
413 USETW(req.wValue, 0);
414 USETW(req.wIndex, 0);
415 USETW(req.wLength, 2);
417 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, &r);
419 kprintf("%s: uvscom_readstat: %s\n",
420 device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
424 DPRINTF(("%s: uvscom_readstat: r = %d\n",
425 device_get_nameunit(sc->sc_ucom.sc_dev), r));
427 return (USBD_NORMAL_COMPLETION);
431 uvscom_shutdown(struct uvscom_softc *sc)
433 usb_device_request_t req;
436 DPRINTF(("%s: send shutdown\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
438 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
439 req.bRequest = UVSCOM_SHUTDOWN;
440 USETW(req.wValue, 0);
441 USETW(req.wIndex, 0);
442 USETW(req.wLength, 0);
444 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
446 kprintf("%s: uvscom_shutdown: %s\n",
447 device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
451 return (USBD_NORMAL_COMPLETION);
455 uvscom_reset(struct uvscom_softc *sc)
457 DPRINTF(("%s: uvscom_reset\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
459 return (USBD_NORMAL_COMPLETION);
463 uvscom_set_crtscts(struct uvscom_softc *sc)
465 DPRINTF(("%s: uvscom_set_crtscts\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
467 return (USBD_NORMAL_COMPLETION);
471 uvscom_set_line(struct uvscom_softc *sc, uint16_t line)
473 usb_device_request_t req;
476 DPRINTF(("%s: uvscom_set_line: %04x\n",
477 device_get_nameunit(sc->sc_ucom.sc_dev), line));
479 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
480 req.bRequest = UVSCOM_LINE_CTL;
481 USETW(req.wValue, line);
482 USETW(req.wIndex, 0);
483 USETW(req.wLength, 0);
485 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
487 kprintf("%s: uvscom_set_line: %s\n",
488 device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
492 return (USBD_NORMAL_COMPLETION);
496 uvscom_set_line_coding(struct uvscom_softc *sc, uint16_t lsp, uint16_t ls)
498 usb_device_request_t req;
501 DPRINTF(("%s: uvscom_set_line_coding: %02x %02x\n",
502 device_get_nameunit(sc->sc_ucom.sc_dev), lsp, ls));
504 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
505 req.bRequest = UVSCOM_SET_SPEED;
506 USETW(req.wValue, lsp);
507 USETW(req.wIndex, 0);
508 USETW(req.wLength, 0);
510 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
512 kprintf("%s: uvscom_set_line_coding: %s\n",
513 device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
517 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
518 req.bRequest = UVSCOM_SET_PARAM;
519 USETW(req.wValue, ls);
520 USETW(req.wIndex, 0);
521 USETW(req.wLength, 0);
523 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
525 kprintf("%s: uvscom_set_line_coding: %s\n",
526 device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
530 return (USBD_NORMAL_COMPLETION);
534 uvscom_dtr(struct uvscom_softc *sc, int onoff)
536 DPRINTF(("%s: uvscom_dtr: onoff = %d\n",
537 device_get_nameunit(sc->sc_ucom.sc_dev), onoff));
539 if (sc->sc_dtr == onoff)
540 return; /* no change */
545 SET(sc->sc_lcr, UVSCOM_DTR);
547 CLR(sc->sc_lcr, UVSCOM_DTR);
549 uvscom_set_line(sc, sc->sc_lcr);
553 uvscom_rts(struct uvscom_softc *sc, int onoff)
555 DPRINTF(("%s: uvscom_rts: onoff = %d\n",
556 device_get_nameunit(sc->sc_ucom.sc_dev), onoff));
558 if (sc->sc_rts == onoff)
559 return; /* no change */
564 SET(sc->sc_lcr, UVSCOM_RTS);
566 CLR(sc->sc_lcr, UVSCOM_RTS);
568 uvscom_set_line(sc, sc->sc_lcr);
572 uvscom_break(struct uvscom_softc *sc, int onoff)
574 DPRINTF(("%s: uvscom_break: onoff = %d\n",
575 device_get_nameunit(sc->sc_ucom.sc_dev), onoff));
578 uvscom_set_line(sc, SET(sc->sc_lcr, UVSCOM_BREAK));
582 uvscom_set(void *addr, int portno, int reg, int onoff)
584 struct uvscom_softc *sc = addr;
588 uvscom_dtr(sc, onoff);
591 uvscom_rts(sc, onoff);
594 uvscom_break(sc, onoff);
602 uvscom_param(void *addr, int portno, struct termios *t)
604 struct uvscom_softc *sc = addr;
609 DPRINTF(("%s: uvscom_param: sc = %p\n",
610 device_get_nameunit(sc->sc_ucom.sc_dev), sc));
614 switch (t->c_ospeed) {
616 lsp = UVSCOM_SPEED_150BPS;
619 lsp = UVSCOM_SPEED_300BPS;
622 lsp = UVSCOM_SPEED_600BPS;
625 lsp = UVSCOM_SPEED_1200BPS;
628 lsp = UVSCOM_SPEED_2400BPS;
631 lsp = UVSCOM_SPEED_4800BPS;
634 lsp = UVSCOM_SPEED_9600BPS;
637 lsp = UVSCOM_SPEED_19200BPS;
640 lsp = UVSCOM_SPEED_38400BPS;
643 lsp = UVSCOM_SPEED_57600BPS;
646 lsp = UVSCOM_SPEED_115200BPS;
652 if (ISSET(t->c_cflag, CSTOPB))
653 SET(ls, UVSCOM_STOP_BIT_2);
655 SET(ls, UVSCOM_STOP_BIT_1);
657 if (ISSET(t->c_cflag, PARENB)) {
658 if (ISSET(t->c_cflag, PARODD))
659 SET(ls, UVSCOM_PARITY_ODD);
661 SET(ls, UVSCOM_PARITY_EVEN);
663 SET(ls, UVSCOM_PARITY_NONE);
665 switch (ISSET(t->c_cflag, CSIZE)) {
667 SET(ls, UVSCOM_DATA_BIT_5);
670 SET(ls, UVSCOM_DATA_BIT_6);
673 SET(ls, UVSCOM_DATA_BIT_7);
676 SET(ls, UVSCOM_DATA_BIT_8);
682 err = uvscom_set_line_coding(sc, lsp, ls);
686 if (ISSET(t->c_cflag, CRTSCTS)) {
687 err = uvscom_set_crtscts(sc);
696 uvscom_open(void *addr, int portno)
698 struct uvscom_softc *sc = addr;
702 if (sc->sc_ucom.sc_dying)
705 DPRINTF(("uvscom_open: sc = %p\n", sc));
707 if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
708 DPRINTF(("uvscom_open: open interrupt pipe.\n"));
710 sc->sc_usr = 0; /* clear unit status */
712 err = uvscom_readstat(sc);
714 DPRINTF(("%s: uvscom_open: readstat faild\n",
715 device_get_nameunit(sc->sc_ucom.sc_dev)));
719 sc->sc_intr_buf = kmalloc(sc->sc_isize, M_USBDEV, M_WAITOK);
720 err = usbd_open_pipe_intr(sc->sc_ucom.sc_iface,
728 UVSCOM_INTR_INTERVAL);
730 kprintf("%s: cannot open interrupt pipe (addr %d)\n",
731 device_get_nameunit(sc->sc_ucom.sc_dev),
736 DPRINTF(("uvscom_open: did not open interrupt pipe.\n"));
739 if ((sc->sc_usr & UVSCOM_USTAT_MASK) == 0) {
740 /* unit is not ready */
742 for (i = UVSCOM_UNIT_WAIT; i > 0; --i) {
743 tsleep(&err, 0, "uvsop", hz); /* XXX */
744 if (ISSET(sc->sc_usr, UVSCOM_USTAT_MASK))
748 DPRINTF(("%s: unit is not ready\n",
749 device_get_nameunit(sc->sc_ucom.sc_dev)));
753 /* check PC card was inserted */
754 if (ISSET(sc->sc_usr, UVSCOM_NOCARD)) {
755 DPRINTF(("%s: no card\n",
756 device_get_nameunit(sc->sc_ucom.sc_dev)));
765 uvscom_close(void *addr, int portno)
767 struct uvscom_softc *sc = addr;
770 if (sc->sc_ucom.sc_dying)
773 DPRINTF(("uvscom_close: close\n"));
777 if (sc->sc_intr_pipe != NULL) {
778 err = usbd_abort_pipe(sc->sc_intr_pipe);
780 kprintf("%s: abort interrupt pipe failed: %s\n",
781 device_get_nameunit(sc->sc_ucom.sc_dev),
783 err = usbd_close_pipe(sc->sc_intr_pipe);
785 kprintf("%s: close interrupt pipe failed: %s\n",
786 device_get_nameunit(sc->sc_ucom.sc_dev),
788 kfree(sc->sc_intr_buf, M_USBDEV);
789 sc->sc_intr_pipe = NULL;
794 uvscom_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
796 struct uvscom_softc *sc = priv;
797 u_char *buf = sc->sc_intr_buf;
800 if (sc->sc_ucom.sc_dying)
803 if (status != USBD_NORMAL_COMPLETION) {
804 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
807 kprintf("%s: uvscom_intr: abnormal status: %s\n",
808 device_get_nameunit(sc->sc_ucom.sc_dev),
809 usbd_errstr(status));
810 usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
814 DPRINTFN(2, ("%s: uvscom status = %02x %02x\n",
815 device_get_nameunit(sc->sc_ucom.sc_dev), buf[0], buf[1]));
817 sc->sc_lsr = sc->sc_msr = 0;
821 if (ISSET(pstatus, UVSCOM_TXRDY))
822 SET(sc->sc_lsr, ULSR_TXRDY);
823 if (ISSET(pstatus, UVSCOM_RXRDY))
824 SET(sc->sc_lsr, ULSR_RXRDY);
827 if (ISSET(pstatus, UVSCOM_CTS))
828 SET(sc->sc_msr, UMSR_CTS);
829 if (ISSET(pstatus, UVSCOM_DSR))
830 SET(sc->sc_msr, UMSR_DSR);
831 if (ISSET(pstatus, UVSCOM_DCD))
832 SET(sc->sc_msr, UMSR_DCD);
834 ucom_status_change(&sc->sc_ucom);
838 uvscom_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
840 struct uvscom_softc *sc = addr;
850 uvscom_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
853 struct uvscom_softc *sc = addr;
856 if (sc->sc_ucom.sc_dying)
859 DPRINTF(("uvscom_ioctl: cmd = 0x%08lx\n", cmd));
868 DPRINTF(("uvscom_ioctl: unknown\n"));