Deleted Added
sdiff udiff text old ( 187176 ) new ( 187259 )
full compact
1/* $FreeBSD: head/sys/dev/usb2/serial/umoscom2.c 187176 2009-01-13 19:03:47Z thompsa $ */
2/* $OpenBSD: umoscom.c,v 1.2 2006/10/26 06:02:43 jsg Exp $ */
3
4/*
5 * Copyright (c) 2006 Jonathan Gray <jsg@openbsd.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.

--- 29 unchanged lines hidden (view full) ---

39static int umoscom_debug = 0;
40
41SYSCTL_NODE(_hw_usb2, OID_AUTO, umoscom, CTLFLAG_RW, 0, "USB umoscom");
42SYSCTL_INT(_hw_usb2_umoscom, OID_AUTO, debug, CTLFLAG_RW,
43 &umoscom_debug, 0, "Debug level");
44#endif
45
46#define UMOSCOM_BUFSIZE 1024 /* bytes */
47#define UMOSCOM_N_DATA_TRANSFER 6 /* units */
48
49#define UMOSCOM_CONFIG_INDEX 0
50#define UMOSCOM_IFACE_INDEX 0
51
52/* interrupt packet */
53#define UMOSCOM_IIR_RLS 0x06
54#define UMOSCOM_IIR_RDA 0x04
55#define UMOSCOM_IIR_CTI 0x0c

--- 93 unchanged lines hidden (view full) ---

149#define UMOSCOM_MSR_CD_CHG 0x08
150#define UMOSCOM_MSR_CTS 0x10
151#define UMOSCOM_MSR_RTS 0x20
152#define UMOSCOM_MSR_RI 0x40
153#define UMOSCOM_MSR_CD 0x80
154
155#define UMOSCOM_BAUD_REF 115200
156
157struct umoscom_softc {
158 struct usb2_com_super_softc sc_super_ucom;
159 struct usb2_com_softc sc_ucom;
160
161 struct usb2_xfer *sc_xfer_data[UMOSCOM_N_DATA_TRANSFER];
162 struct usb2_device *sc_udev;
163
164 uint8_t sc_mcr;
165 uint8_t sc_lcr;
166 uint8_t sc_flags;
167#define UMOSCOM_FLAG_READ_STALL 0x01
168#define UMOSCOM_FLAG_WRITE_STALL 0x02
169#define UMOSCOM_FLAG_INTR_STALL 0x04

--- 25 unchanged lines hidden (view full) ---

195static uint8_t umoscom_cfg_read(struct umoscom_softc *, uint16_t);
196static void umoscom_cfg_do_request(struct umoscom_softc *,
197 struct usb2_device_request *, void *);
198static void umoscom_start_read(struct usb2_com_softc *);
199static void umoscom_stop_read(struct usb2_com_softc *);
200static void umoscom_start_write(struct usb2_com_softc *);
201static void umoscom_stop_write(struct usb2_com_softc *);
202
203static const struct usb2_config umoscom_config_data[UMOSCOM_N_DATA_TRANSFER] = {
204
205 [0] = {
206 .type = UE_BULK,
207 .endpoint = UE_ADDR_ANY,
208 .direction = UE_DIR_OUT,
209 .mh.bufsize = UMOSCOM_BUFSIZE,
210 .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,},
211 .mh.callback = &umoscom_write_callback,
212 },
213
214 [1] = {
215 .type = UE_BULK,
216 .endpoint = UE_ADDR_ANY,
217 .direction = UE_DIR_IN,
218 .mh.bufsize = UMOSCOM_BUFSIZE,
219 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
220 .mh.callback = &umoscom_read_callback,
221 },
222
223 [2] = {
224 .type = UE_CONTROL,
225 .endpoint = 0x00, /* Control pipe */
226 .direction = UE_DIR_ANY,
227 .mh.bufsize = sizeof(struct usb2_device_request),
228 .mh.callback = &umoscom_write_clear_stall_callback,
229 .mh.timeout = 1000, /* 1 second */
230 .mh.interval = 50, /* 50ms */
231 },
232
233 [3] = {
234 .type = UE_CONTROL,
235 .endpoint = 0x00, /* Control pipe */
236 .direction = UE_DIR_ANY,
237 .mh.bufsize = sizeof(struct usb2_device_request),
238 .mh.callback = &umoscom_read_clear_stall_callback,
239 .mh.timeout = 1000, /* 1 second */
240 .mh.interval = 50, /* 50ms */
241 },
242
243 [4] = {
244 .type = UE_INTERRUPT,
245 .endpoint = UE_ADDR_ANY,
246 .direction = UE_DIR_IN,
247 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
248 .mh.bufsize = 0, /* use wMaxPacketSize */
249 .mh.callback = &umoscom_intr_callback,
250 },
251
252 [5] = {
253 .type = UE_CONTROL,
254 .endpoint = 0x00, /* Control pipe */
255 .direction = UE_DIR_ANY,
256 .mh.bufsize = sizeof(struct usb2_device_request),
257 .mh.callback = &umoscom_intr_clear_stall_callback,
258 .mh.timeout = 1000, /* 1 second */
259 .mh.interval = 50, /* 50ms */
260 },

--- 72 unchanged lines hidden (view full) ---

333 sc->sc_mcr = 0x08; /* enable interrupts */
334
335 /* XXX the device doesn't provide any ID string, so set a static one */
336 device_set_desc(dev, "MOSCHIP USB Serial Port Adapter");
337 device_printf(dev, "<MOSCHIP USB Serial Port Adapter>\n");
338
339 iface_index = UMOSCOM_IFACE_INDEX;
340 error = usb2_transfer_setup(uaa->device, &iface_index,
341 sc->sc_xfer_data, umoscom_config_data,
342 UMOSCOM_N_DATA_TRANSFER, sc, &Giant);
343
344 if (error) {
345 goto detach;
346 }
347 /* clear stall at first run */
348 sc->sc_flags |= (UMOSCOM_FLAG_READ_STALL |
349 UMOSCOM_FLAG_WRITE_STALL);
350

--- 16 unchanged lines hidden (view full) ---

367 struct umoscom_softc *sc = device_get_softc(dev);
368
369 mtx_lock(&Giant);
370
371 mtx_unlock(&Giant);
372
373 usb2_com_detach(&sc->sc_super_ucom, &sc->sc_ucom, 1);
374
375 usb2_transfer_unsetup(sc->sc_xfer_data, UMOSCOM_N_DATA_TRANSFER);
376
377 return (0);
378}
379
380static void
381umoscom_cfg_open(struct usb2_com_softc *ucom)
382{
383 struct umoscom_softc *sc = ucom->sc_parent;

--- 217 unchanged lines hidden (view full) ---

601
602static void
603umoscom_start_read(struct usb2_com_softc *ucom)
604{
605 struct umoscom_softc *sc = ucom->sc_parent;
606
607#if 0
608 /* start interrupt endpoint */
609 usb2_transfer_start(sc->sc_xfer_data[4]);
610#endif
611 /* start read endpoint */
612 usb2_transfer_start(sc->sc_xfer_data[1]);
613}
614
615static void
616umoscom_stop_read(struct usb2_com_softc *ucom)
617{
618 struct umoscom_softc *sc = ucom->sc_parent;
619
620 /* stop interrupt transfer */
621 usb2_transfer_stop(sc->sc_xfer_data[5]);
622 usb2_transfer_stop(sc->sc_xfer_data[4]);
623
624 /* stop read endpoint */
625 usb2_transfer_stop(sc->sc_xfer_data[3]);
626 usb2_transfer_stop(sc->sc_xfer_data[1]);
627}
628
629static void
630umoscom_start_write(struct usb2_com_softc *ucom)
631{
632 struct umoscom_softc *sc = ucom->sc_parent;
633
634 usb2_transfer_start(sc->sc_xfer_data[0]);
635}
636
637static void
638umoscom_stop_write(struct usb2_com_softc *ucom)
639{
640 struct umoscom_softc *sc = ucom->sc_parent;
641
642 usb2_transfer_stop(sc->sc_xfer_data[2]);
643 usb2_transfer_stop(sc->sc_xfer_data[0]);
644}
645
646static void
647umoscom_write_callback(struct usb2_xfer *xfer)
648{
649 struct umoscom_softc *sc = xfer->priv_sc;
650 uint32_t actlen;
651
652 switch (USB_GET_STATE(xfer)) {
653 case USB_ST_SETUP:
654 case USB_ST_TRANSFERRED:
655 DPRINTF("\n");
656
657 if (sc->sc_flags & UMOSCOM_FLAG_WRITE_STALL) {
658 usb2_transfer_start(sc->sc_xfer_data[2]);
659 return;
660 }
661 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
662 UMOSCOM_BUFSIZE, &actlen)) {
663
664 xfer->frlengths[0] = actlen;
665 usb2_start_hardware(xfer);
666 }
667 return;
668
669 default: /* Error */
670 if (xfer->error != USB_ERR_CANCELLED) {
671 DPRINTFN(0, "transfer failed\n");
672 sc->sc_flags |= UMOSCOM_FLAG_WRITE_STALL;
673 usb2_transfer_start(sc->sc_xfer_data[2]);
674 }
675 return;
676 }
677}
678
679static void
680umoscom_write_clear_stall_callback(struct usb2_xfer *xfer)
681{
682 struct umoscom_softc *sc = xfer->priv_sc;
683 struct usb2_xfer *xfer_other = sc->sc_xfer_data[0];
684
685 if (usb2_clear_stall_callback(xfer, xfer_other)) {
686 DPRINTF("stall cleared\n");
687 sc->sc_flags &= ~UMOSCOM_FLAG_WRITE_STALL;
688 usb2_transfer_start(xfer_other);
689 }
690}
691

--- 6 unchanged lines hidden (view full) ---

698 case USB_ST_TRANSFERRED:
699 DPRINTF("got %d bytes\n", xfer->actlen);
700 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
701
702 case USB_ST_SETUP:
703 DPRINTF("\n");
704
705 if (sc->sc_flags & UMOSCOM_FLAG_READ_STALL) {
706 usb2_transfer_start(sc->sc_xfer_data[3]);
707 } else {
708 xfer->frlengths[0] = xfer->max_data_length;
709 usb2_start_hardware(xfer);
710 }
711 return;
712
713 default: /* Error */
714 if (xfer->error != USB_ERR_CANCELLED) {
715 DPRINTFN(0, "transfer failed\n");
716 sc->sc_flags |= UMOSCOM_FLAG_READ_STALL;
717 usb2_transfer_start(sc->sc_xfer_data[3]);
718 }
719 return;
720
721 }
722}
723
724static void
725umoscom_read_clear_stall_callback(struct usb2_xfer *xfer)
726{
727 struct umoscom_softc *sc = xfer->priv_sc;
728 struct usb2_xfer *xfer_other = sc->sc_xfer_data[1];
729
730 if (usb2_clear_stall_callback(xfer, xfer_other)) {
731 DPRINTF("stall cleared\n");
732 sc->sc_flags &= ~UMOSCOM_FLAG_READ_STALL;
733 usb2_transfer_start(xfer_other);
734 }
735}
736

--- 8 unchanged lines hidden (view full) ---

745 DPRINTF("too short message\n");
746 goto tr_setup;
747 }
748 usb2_com_status_change(&sc->sc_ucom);
749
750 case USB_ST_SETUP:
751tr_setup:
752 if (sc->sc_flags & UMOSCOM_FLAG_INTR_STALL) {
753 usb2_transfer_start(sc->sc_xfer_data[5]);
754 } else {
755 xfer->frlengths[0] = xfer->max_data_length;
756 usb2_start_hardware(xfer);
757 }
758 return;
759
760 default: /* Error */
761 if (xfer->error != USB_ERR_CANCELLED) {
762 DPRINTFN(0, "transfer failed\n");
763 sc->sc_flags |= UMOSCOM_FLAG_INTR_STALL;
764 usb2_transfer_start(sc->sc_xfer_data[5]);
765 }
766 return;
767 }
768}
769
770static void
771umoscom_intr_clear_stall_callback(struct usb2_xfer *xfer)
772{
773 struct umoscom_softc *sc = xfer->priv_sc;
774 struct usb2_xfer *xfer_other = sc->sc_xfer_data[4];
775
776 if (usb2_clear_stall_callback(xfer, xfer_other)) {
777 DPRINTF("stall cleared\n");
778 sc->sc_flags &= ~UMOSCOM_FLAG_INTR_STALL;
779 usb2_transfer_start(xfer_other);
780 }
781}