1 /* $NetBSD: usb/uvscom.c,v 1.1 2002/03/19 15:08:42 augustss Exp $ */
3 * Copyright (c) 2001-2003, 2005 Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
33 * uvscom: SUNTAC Slipper U VS-10U driver.
34 * Slipper U is a PC Card to USB converter for data communication card
35 * adapter. It supports DDI Pocket's Air H" C@rd, C@rd H" 64, NTT's P-in,
36 * P-in m@ater and various data communication card adapters.
39 #include "opt_uvscom.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/malloc.h>
45 #include <sys/module.h>
46 #include <sys/fcntl.h>
48 #include <sys/serial.h>
52 #include <sys/ioccom.h>
53 #include <sys/selinfo.h>
56 #include <sys/sysctl.h>
57 #include <sys/taskqueue.h>
59 #include <dev/usb/usb.h>
60 #include <dev/usb/usbcdc.h>
62 #include <dev/usb/usbdi.h>
63 #include <dev/usb/usbdi_util.h>
65 #include <dev/usb/usb_quirks.h>
67 #include <dev/usb/ucomvar.h>
69 SYSCTL_NODE(_hw_usb, OID_AUTO, uvscom, CTLFLAG_RW, 0, "USB uvscom");
71 static int uvscomdebug = 0;
72 SYSCTL_INT(_hw_usb_uvscom, OID_AUTO, debug, CTLFLAG_RW,
73 &uvscomdebug, 0, "uvscom debug level");
75 #define DPRINTFN(n, x) do { \
76 if (uvscomdebug > (n)) \
80 #define DPRINTFN(n, x)
82 #define DPRINTF(x) DPRINTFN(0, x)
84 #define UVSCOM_MODVER 1 /* module version */
86 #define UVSCOM_CONFIG_INDEX 0
87 #define UVSCOM_IFACE_INDEX 0
89 #ifndef UVSCOM_INTR_INTERVAL
90 #define UVSCOM_INTR_INTERVAL 100 /* mS */
93 #define UVSCOM_UNIT_WAIT 5
96 #define UVSCOM_SET_SPEED 0x10
97 #define UVSCOM_LINE_CTL 0x11
98 #define UVSCOM_SET_PARAM 0x12
99 #define UVSCOM_READ_STATUS 0xd0
100 #define UVSCOM_SHUTDOWN 0xe0
102 /* UVSCOM_SET_SPEED parameters */
103 #define UVSCOM_SPEED_150BPS 0x00
104 #define UVSCOM_SPEED_300BPS 0x01
105 #define UVSCOM_SPEED_600BPS 0x02
106 #define UVSCOM_SPEED_1200BPS 0x03
107 #define UVSCOM_SPEED_2400BPS 0x04
108 #define UVSCOM_SPEED_4800BPS 0x05
109 #define UVSCOM_SPEED_9600BPS 0x06
110 #define UVSCOM_SPEED_19200BPS 0x07
111 #define UVSCOM_SPEED_38400BPS 0x08
112 #define UVSCOM_SPEED_57600BPS 0x09
113 #define UVSCOM_SPEED_115200BPS 0x0a
115 /* UVSCOM_LINE_CTL parameters */
116 #define UVSCOM_BREAK 0x40
117 #define UVSCOM_RTS 0x02
118 #define UVSCOM_DTR 0x01
119 #define UVSCOM_LINE_INIT 0x08
121 /* UVSCOM_SET_PARAM parameters */
122 #define UVSCOM_DATA_MASK 0x03
123 #define UVSCOM_DATA_BIT_8 0x03
124 #define UVSCOM_DATA_BIT_7 0x02
125 #define UVSCOM_DATA_BIT_6 0x01
126 #define UVSCOM_DATA_BIT_5 0x00
128 #define UVSCOM_STOP_MASK 0x04
129 #define UVSCOM_STOP_BIT_2 0x04
130 #define UVSCOM_STOP_BIT_1 0x00
132 #define UVSCOM_PARITY_MASK 0x18
133 #define UVSCOM_PARITY_EVEN 0x18
135 #define UVSCOM_PARITY_UNK 0x10
137 #define UVSCOM_PARITY_ODD 0x08
138 #define UVSCOM_PARITY_NONE 0x00
141 #define UVSCOM_TXRDY 0x04
142 #define UVSCOM_RXRDY 0x01
144 #define UVSCOM_DCD 0x08
145 #define UVSCOM_NOCARD 0x04
146 #define UVSCOM_DSR 0x02
147 #define UVSCOM_CTS 0x01
148 #define UVSCOM_USTAT_MASK (UVSCOM_NOCARD | UVSCOM_DSR | UVSCOM_CTS)
150 struct uvscom_softc {
151 struct ucom_softc sc_ucom;
153 int sc_iface_number;/* interface number */
155 usbd_interface_handle sc_intr_iface; /* interrupt interface */
156 int sc_intr_number; /* interrupt number */
157 usbd_pipe_handle sc_intr_pipe; /* interrupt pipe */
158 u_char *sc_intr_buf; /* interrupt buffer */
161 u_char sc_dtr; /* current DTR state */
162 u_char sc_rts; /* current RTS state */
164 u_char sc_lsr; /* Local status register */
165 u_char sc_msr; /* uvscom status register */
167 uint16_t sc_lcr; /* Line control */
168 u_char sc_usr; /* unit status */
174 * These are the maximum number of bytes transferred per frame.
175 * The output buffer size cannot be increased due to the size encoding.
177 #define UVSCOMIBUFSIZE 512
178 #define UVSCOMOBUFSIZE 64
180 #ifndef UVSCOM_DEFAULT_OPKTSIZE
181 #define UVSCOM_DEFAULT_OPKTSIZE 8
184 static usbd_status uvscom_shutdown(struct uvscom_softc *);
185 static usbd_status uvscom_reset(struct uvscom_softc *);
186 static usbd_status uvscom_set_line_coding(struct uvscom_softc *,
188 static usbd_status uvscom_set_line(struct uvscom_softc *, uint16_t);
189 static usbd_status uvscom_set_crtscts(struct uvscom_softc *);
190 static void uvscom_get_status(void *, int, u_char *, u_char *);
191 static void uvscom_dtr(struct uvscom_softc *, int);
192 static void uvscom_rts(struct uvscom_softc *, int);
193 static void uvscom_break(struct uvscom_softc *, int);
195 static void uvscom_set(void *, int, int, int);
196 static void uvscom_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
198 static int uvscom_ioctl(void *, int, u_long, caddr_t, int, usb_proc_ptr);
200 static int uvscom_param(void *, int, struct termios *);
201 static int uvscom_open(void *, int);
202 static void uvscom_close(void *, int);
203 static void uvscom_notify(void *, int);
205 struct ucom_callback uvscom_callback = {
209 NULL, /* uvscom_ioctl, TODO */
216 static const struct usb_devno uvscom_devs [] = {
217 /* SUNTAC U-Cable type A4 */
218 { USB_VENDOR_SUNTAC, USB_PRODUCT_SUNTAC_AS144L4 },
219 /* SUNTAC U-Cable type D2 */
220 { USB_VENDOR_SUNTAC, USB_PRODUCT_SUNTAC_DS96L },
221 /* SUNTAC Ir-Trinity */
222 { USB_VENDOR_SUNTAC, USB_PRODUCT_SUNTAC_IS96U },
223 /* SUNTAC U-Cable type P1 */
224 { USB_VENDOR_SUNTAC, USB_PRODUCT_SUNTAC_PS64P1 },
225 /* SUNTAC Slipper U */
226 { USB_VENDOR_SUNTAC, USB_PRODUCT_SUNTAC_VS10U },
228 #define uvscom_lookup(v, p) usb_lookup(uvscom_devs, v, p)
230 static device_probe_t uvscom_match;
231 static device_attach_t uvscom_attach;
232 static device_detach_t uvscom_detach;
234 static device_method_t uvscom_methods[] = {
235 /* Device interface */
236 DEVMETHOD(device_probe, uvscom_match),
237 DEVMETHOD(device_attach, uvscom_attach),
238 DEVMETHOD(device_detach, uvscom_detach),
242 static driver_t uvscom_driver = {
245 sizeof (struct uvscom_softc)
248 DRIVER_MODULE(uvscom, uhub, uvscom_driver, ucom_devclass, usbd_driver_load, 0);
249 MODULE_DEPEND(uvscom, usb, 1, 1, 1);
250 MODULE_DEPEND(uvscom, ucom, UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);
251 MODULE_VERSION(uvscom, UVSCOM_MODVER);
253 static int uvscomobufsiz = UVSCOM_DEFAULT_OPKTSIZE;
254 static int uvscominterval = UVSCOM_INTR_INTERVAL;
257 sysctl_hw_usb_uvscom_opktsize(SYSCTL_HANDLER_ARGS)
262 err = sysctl_handle_int(oidp, &val, 0, req);
263 if (err != 0 || req->newptr == NULL)
265 if (0 < val && val <= UVSCOMOBUFSIZE)
274 sysctl_hw_usb_uvscom_interval(SYSCTL_HANDLER_ARGS)
278 val = uvscominterval;
279 err = sysctl_handle_int(oidp, &val, 0, req);
280 if (err != 0 || req->newptr == NULL)
282 if (0 < val && val <= 1000)
283 uvscominterval = val;
290 SYSCTL_PROC(_hw_usb_uvscom, OID_AUTO, opktsize, CTLTYPE_INT | CTLFLAG_RW,
291 0, sizeof(int), sysctl_hw_usb_uvscom_opktsize,
292 "I", "uvscom output packet size");
293 SYSCTL_PROC(_hw_usb_uvscom, OID_AUTO, interval, CTLTYPE_INT | CTLFLAG_RW,
294 0, sizeof(int), sysctl_hw_usb_uvscom_interval,
295 "I", "uvscom interrpt pipe interval");
298 uvscom_match(device_t self)
300 struct usb_attach_arg *uaa = device_get_ivars(self);
302 if (uaa->iface != NULL)
303 return (UMATCH_NONE);
305 return (uvscom_lookup(uaa->vendor, uaa->product) != NULL ?
306 UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
310 uvscom_attach(device_t self)
312 struct uvscom_softc *sc = device_get_softc(self);
313 struct usb_attach_arg *uaa = device_get_ivars(self);
314 usbd_device_handle dev = uaa->device;
315 struct ucom_softc *ucom;
316 usb_config_descriptor_t *cdesc;
317 usb_interface_descriptor_t *id;
318 usb_endpoint_descriptor_t *ed;
325 ucom->sc_iface = uaa->iface;
327 DPRINTF(("uvscom attach: sc = %p\n", sc));
329 /* initialize endpoints */
330 ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
331 sc->sc_intr_number = -1;
332 sc->sc_intr_pipe = NULL;
334 /* Move the device into the configured state. */
335 err = usbd_set_config_index(dev, UVSCOM_CONFIG_INDEX, 1);
337 device_printf(self, "failed to set configuration, err=%s\n",
342 /* get the config descriptor */
343 cdesc = usbd_get_config_descriptor(ucom->sc_udev);
346 device_printf(self, "failed to get configuration descriptor\n");
350 /* get the common interface */
351 err = usbd_device2interface_handle(dev, UVSCOM_IFACE_INDEX,
354 device_printf(self, "failed to get interface, err=%s\n",
359 id = usbd_get_interface_descriptor(ucom->sc_iface);
360 sc->sc_iface_number = id->bInterfaceNumber;
363 for (i = 0; i < id->bNumEndpoints; i++) {
364 ed = usbd_interface2endpoint_descriptor(ucom->sc_iface, i);
366 device_printf(self, "no endpoint descriptor for %d\n",
371 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
372 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
373 ucom->sc_bulkin_no = ed->bEndpointAddress;
374 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
375 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
376 ucom->sc_bulkout_no = ed->bEndpointAddress;
377 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
378 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
379 sc->sc_intr_number = ed->bEndpointAddress;
380 sc->sc_isize = UGETW(ed->wMaxPacketSize);
384 if (ucom->sc_bulkin_no == -1) {
385 device_printf(self, "Could not find data bulk in\n");
388 if (ucom->sc_bulkout_no == -1) {
389 device_printf(self, "Could not find data bulk out\n");
392 if (sc->sc_intr_number == -1) {
393 device_printf(self, "Could not find interrupt in\n");
397 sc->sc_dtr = sc->sc_rts = 0;
398 sc->sc_lcr = UVSCOM_LINE_INIT;
400 ucom->sc_parent = sc;
401 ucom->sc_portno = UCOM_UNK_PORTNO;
402 /* bulkin, bulkout set above */
403 ucom->sc_ibufsize = UVSCOMIBUFSIZE;
404 ucom->sc_obufsize = uvscomobufsiz;
405 ucom->sc_ibufsizepad = UVSCOMIBUFSIZE;
406 ucom->sc_opkthdrlen = 0;
407 ucom->sc_callback = &uvscom_callback;
409 err = uvscom_reset(sc);
412 device_printf(self, "reset failed, %s\n", usbd_errstr(err));
416 DPRINTF(("uvscom: in = 0x%x out = 0x%x intr = 0x%x\n",
417 ucom->sc_bulkin_no, ucom->sc_bulkout_no, sc->sc_intr_number));
419 TASK_INIT(&sc->sc_task, 0, uvscom_notify, sc);
420 ucom_attach(&sc->sc_ucom);
429 uvscom_detach(device_t self)
431 struct uvscom_softc *sc = device_get_softc(self);
434 DPRINTF(("uvscom_detach: sc = %p\n", sc));
436 sc->sc_ucom.sc_dying = 1;
438 if (sc->sc_intr_pipe != NULL) {
439 usbd_abort_pipe(sc->sc_intr_pipe);
440 usbd_close_pipe(sc->sc_intr_pipe);
441 free(sc->sc_intr_buf, M_USBDEV);
442 sc->sc_intr_pipe = NULL;
445 rv = ucom_detach(&sc->sc_ucom);
451 uvscom_readstat(struct uvscom_softc *sc)
453 usb_device_request_t req;
457 DPRINTF(("%s: send readstat\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
459 req.bmRequestType = UT_READ_VENDOR_DEVICE;
460 req.bRequest = UVSCOM_READ_STATUS;
461 USETW(req.wValue, 0);
462 USETW(req.wIndex, 0);
463 USETW(req.wLength, 2);
465 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, &r);
467 device_printf(sc->sc_ucom.sc_dev, "uvscom_readstat: %s\n",
472 DPRINTF(("%s: uvscom_readstat: r = %d\n",
473 device_get_nameunit(sc->sc_ucom.sc_dev), r));
475 return (USBD_NORMAL_COMPLETION);
479 uvscom_shutdown(struct uvscom_softc *sc)
481 usb_device_request_t req;
484 DPRINTF(("%s: send shutdown\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
486 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
487 req.bRequest = UVSCOM_SHUTDOWN;
488 USETW(req.wValue, 0);
489 USETW(req.wIndex, 0);
490 USETW(req.wLength, 0);
492 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
494 device_printf(sc->sc_ucom.sc_dev, "uvscom_shutdown: %s\n",
499 return (USBD_NORMAL_COMPLETION);
503 uvscom_reset(struct uvscom_softc *sc)
505 DPRINTF(("%s: uvscom_reset\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
507 return (USBD_NORMAL_COMPLETION);
511 uvscom_set_crtscts(struct uvscom_softc *sc)
513 DPRINTF(("%s: uvscom_set_crtscts\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
515 return (USBD_NORMAL_COMPLETION);
519 uvscom_set_line(struct uvscom_softc *sc, uint16_t line)
521 usb_device_request_t req;
524 DPRINTF(("%s: uvscom_set_line: %04x\n",
525 device_get_nameunit(sc->sc_ucom.sc_dev), line));
527 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
528 req.bRequest = UVSCOM_LINE_CTL;
529 USETW(req.wValue, line);
530 USETW(req.wIndex, 0);
531 USETW(req.wLength, 0);
533 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
535 device_printf(sc->sc_ucom.sc_dev, "uvscom_set_line: %s\n",
540 return (USBD_NORMAL_COMPLETION);
544 uvscom_set_line_coding(struct uvscom_softc *sc, uint16_t lsp, uint16_t ls)
546 usb_device_request_t req;
549 DPRINTF(("%s: uvscom_set_line_coding: %02x %02x\n",
550 device_get_nameunit(sc->sc_ucom.sc_dev), lsp, ls));
552 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
553 req.bRequest = UVSCOM_SET_SPEED;
554 USETW(req.wValue, lsp);
555 USETW(req.wIndex, 0);
556 USETW(req.wLength, 0);
558 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
560 device_printf(sc->sc_ucom.sc_dev, "uvscom_set_line_coding: %s\n",
565 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
566 req.bRequest = UVSCOM_SET_PARAM;
567 USETW(req.wValue, ls);
568 USETW(req.wIndex, 0);
569 USETW(req.wLength, 0);
571 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
573 device_printf(sc->sc_ucom.sc_dev, "uvscom_set_line_coding: %s\n",
578 return (USBD_NORMAL_COMPLETION);
582 uvscom_dtr(struct uvscom_softc *sc, int onoff)
584 DPRINTF(("%s: uvscom_dtr: onoff = %d\n",
585 device_get_nameunit(sc->sc_ucom.sc_dev), onoff));
587 if (sc->sc_dtr == onoff)
588 return; /* no change */
593 SET(sc->sc_lcr, UVSCOM_DTR);
595 CLR(sc->sc_lcr, UVSCOM_DTR);
597 uvscom_set_line(sc, sc->sc_lcr);
601 uvscom_rts(struct uvscom_softc *sc, int onoff)
603 DPRINTF(("%s: uvscom_rts: onoff = %d\n",
604 device_get_nameunit(sc->sc_ucom.sc_dev), onoff));
606 if (sc->sc_rts == onoff)
607 return; /* no change */
612 SET(sc->sc_lcr, UVSCOM_RTS);
614 CLR(sc->sc_lcr, UVSCOM_RTS);
616 uvscom_set_line(sc, sc->sc_lcr);
620 uvscom_break(struct uvscom_softc *sc, int onoff)
622 DPRINTF(("%s: uvscom_break: onoff = %d\n",
623 device_get_nameunit(sc->sc_ucom.sc_dev), onoff));
626 uvscom_set_line(sc, SET(sc->sc_lcr, UVSCOM_BREAK));
630 uvscom_set(void *addr, int portno, int reg, int onoff)
632 struct uvscom_softc *sc = addr;
636 uvscom_dtr(sc, onoff);
639 uvscom_rts(sc, onoff);
642 uvscom_break(sc, onoff);
650 uvscom_param(void *addr, int portno, struct termios *t)
652 struct uvscom_softc *sc = addr;
657 DPRINTF(("%s: uvscom_param: sc = %p\n",
658 device_get_nameunit(sc->sc_ucom.sc_dev), sc));
662 switch (t->c_ospeed) {
664 lsp = UVSCOM_SPEED_150BPS;
667 lsp = UVSCOM_SPEED_300BPS;
670 lsp = UVSCOM_SPEED_600BPS;
673 lsp = UVSCOM_SPEED_1200BPS;
676 lsp = UVSCOM_SPEED_2400BPS;
679 lsp = UVSCOM_SPEED_4800BPS;
682 lsp = UVSCOM_SPEED_9600BPS;
685 lsp = UVSCOM_SPEED_19200BPS;
688 lsp = UVSCOM_SPEED_38400BPS;
691 lsp = UVSCOM_SPEED_57600BPS;
694 lsp = UVSCOM_SPEED_115200BPS;
700 if (ISSET(t->c_cflag, CSTOPB))
701 SET(ls, UVSCOM_STOP_BIT_2);
703 SET(ls, UVSCOM_STOP_BIT_1);
705 if (ISSET(t->c_cflag, PARENB)) {
706 if (ISSET(t->c_cflag, PARODD))
707 SET(ls, UVSCOM_PARITY_ODD);
709 SET(ls, UVSCOM_PARITY_EVEN);
711 SET(ls, UVSCOM_PARITY_NONE);
713 switch (ISSET(t->c_cflag, CSIZE)) {
715 SET(ls, UVSCOM_DATA_BIT_5);
718 SET(ls, UVSCOM_DATA_BIT_6);
721 SET(ls, UVSCOM_DATA_BIT_7);
724 SET(ls, UVSCOM_DATA_BIT_8);
730 err = uvscom_set_line_coding(sc, lsp, ls);
734 if (ISSET(t->c_cflag, CRTSCTS)) {
735 err = uvscom_set_crtscts(sc);
744 uvscom_open(void *addr, int portno)
746 struct uvscom_softc *sc = addr;
750 if (sc->sc_ucom.sc_dying)
753 DPRINTF(("uvscom_open: sc = %p\n", sc));
755 /* change output packet size */
756 sc->sc_ucom.sc_obufsize = uvscomobufsiz;
758 if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
759 DPRINTF(("uvscom_open: open interrupt pipe.\n"));
761 sc->sc_usr = 0; /* clear unit status */
763 err = uvscom_readstat(sc);
765 DPRINTF(("%s: uvscom_open: readstat faild\n",
766 device_get_nameunit(sc->sc_ucom.sc_dev)));
770 sc->sc_intr_buf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK);
771 err = usbd_open_pipe_intr(sc->sc_ucom.sc_iface,
781 device_printf(sc->sc_ucom.sc_dev,
782 "cannot open interrupt pipe (addr %d)\n",
787 DPRINTF(("uvscom_open: did not open interrupt pipe.\n"));
790 if ((sc->sc_usr & UVSCOM_USTAT_MASK) == 0) {
791 /* unit is not ready */
793 for (i = UVSCOM_UNIT_WAIT; i > 0; --i) {
794 pause("uvsop", hz); /* XXX */
795 if (ISSET(sc->sc_usr, UVSCOM_USTAT_MASK))
799 DPRINTF(("%s: unit is not ready\n",
800 device_get_nameunit(sc->sc_ucom.sc_dev)));
804 /* check PC Card was inserted */
805 if (ISSET(sc->sc_usr, UVSCOM_NOCARD)) {
806 DPRINTF(("%s: no card\n",
807 device_get_nameunit(sc->sc_ucom.sc_dev)));
816 uvscom_close(void *addr, int portno)
818 struct uvscom_softc *sc = addr;
821 if (sc->sc_ucom.sc_dying)
824 DPRINTF(("uvscom_close: close\n"));
828 if (sc->sc_intr_pipe != NULL) {
829 err = usbd_abort_pipe(sc->sc_intr_pipe);
831 device_printf(sc->sc_ucom.sc_dev,
832 "abort interrupt pipe failed: %s\n",
834 err = usbd_close_pipe(sc->sc_intr_pipe);
836 device_printf(sc->sc_ucom.sc_dev,
837 "close interrupt pipe failed: %s\n",
839 free(sc->sc_intr_buf, M_USBDEV);
840 sc->sc_intr_pipe = NULL;
845 uvscom_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
847 struct uvscom_softc *sc = priv;
848 u_char *buf = sc->sc_intr_buf;
851 if (sc->sc_ucom.sc_dying)
854 if (status != USBD_NORMAL_COMPLETION) {
855 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
858 device_printf(sc->sc_ucom.sc_dev,
859 "uvscom_intr: abnormal status: %s\n",
860 usbd_errstr(status));
861 usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
865 DPRINTFN(2, ("%s: uvscom status = %02x %02x\n",
866 device_get_nameunit(sc->sc_ucom.sc_dev), buf[0], buf[1]));
868 sc->sc_lsr = sc->sc_msr = 0;
872 if (ISSET(pstatus, UVSCOM_TXRDY))
873 SET(sc->sc_lsr, ULSR_TXRDY);
874 if (ISSET(pstatus, UVSCOM_RXRDY))
875 SET(sc->sc_lsr, ULSR_RXRDY);
878 if (ISSET(pstatus, UVSCOM_CTS))
879 SET(sc->sc_msr, SER_CTS);
880 if (ISSET(pstatus, UVSCOM_DSR))
881 SET(sc->sc_msr, SER_DSR);
882 if (ISSET(pstatus, UVSCOM_DCD))
883 SET(sc->sc_msr, SER_DCD);
885 /* Deferred notifying to the ucom layer */
886 taskqueue_enqueue(taskqueue_swi_giant, &sc->sc_task);
890 uvscom_notify(void *arg, int count)
892 struct uvscom_softc *sc;
894 sc = (struct uvscom_softc *)arg;
895 if (sc->sc_ucom.sc_dying)
897 ucom_status_change(&sc->sc_ucom);
901 uvscom_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
903 struct uvscom_softc *sc = addr;
913 uvscom_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
916 struct uvscom_softc *sc = addr;
919 if (sc->sc_ucom.sc_dying)
922 DPRINTF(("uvscom_ioctl: cmd = 0x%08lx\n", cmd));
931 DPRINTF(("uvscom_ioctl: unknown\n"));