Deleted Added
sdiff udiff text old ( 187176 ) new ( 187259 )
full compact
1/* $NetBSD: uplcom.c,v 1.21 2001/11/13 06:24:56 lukem Exp $ */
2
3#include <sys/cdefs.h>
4__FBSDID("$FreeBSD: head/sys/dev/usb2/serial/uplcom2.c 187259 2009-01-15 02:35:40Z thompsa $");
5
6/*-
7 * Copyright (c) 2001-2003, 2005 Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:

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

116#define UPLCOM_IFACE_INDEX 0
117#define UPLCOM_SECOND_IFACE_INDEX 1
118
119#ifndef UPLCOM_INTR_INTERVAL
120#define UPLCOM_INTR_INTERVAL 0 /* default */
121#endif
122
123#define UPLCOM_BULK_BUF_SIZE 1024 /* bytes */
124
125#define UPLCOM_SET_REQUEST 0x01
126#define UPLCOM_SET_CRTSCTS 0x41
127#define UPLCOM_SET_CRTSCTS_PL2303X 0x61
128#define RSAQ_STATUS_CTS 0x80
129#define RSAQ_STATUS_DSR 0x02
130#define RSAQ_STATUS_DCD 0x01
131
132#define TYPE_PL2303 0
133#define TYPE_PL2303X 1
134
135enum {
136 UPLCOM_BULK_DT_WR,
137 UPLCOM_BULK_DT_RD,
138 UPLCOM_BULK_CS_WR,
139 UPLCOM_BULK_CS_RD,
140 UPLCOM_INTR_DT_RD,
141 UPLCOM_INTR_CS_RD,
142 UPLCOM_N_TRANSFER = 6,
143};
144
145struct uplcom_softc {
146 struct usb2_com_super_softc sc_super_ucom;
147 struct usb2_com_softc sc_ucom;
148
149 struct usb2_xfer *sc_xfer[UPLCOM_N_TRANSFER];
150 struct usb2_device *sc_udev;
151
152 uint16_t sc_line;

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

190static usb2_callback_t uplcom_intr_clear_stall_callback;
191static usb2_callback_t uplcom_write_callback;
192static usb2_callback_t uplcom_write_clear_stall_callback;
193static usb2_callback_t uplcom_read_callback;
194static usb2_callback_t uplcom_read_clear_stall_callback;
195
196static const struct usb2_config uplcom_config_data[UPLCOM_N_TRANSFER] = {
197
198 [UPLCOM_BULK_DT_WR] = {
199 .type = UE_BULK,
200 .endpoint = UE_ADDR_ANY,
201 .direction = UE_DIR_OUT,
202 .mh.bufsize = UPLCOM_BULK_BUF_SIZE,
203 .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,},
204 .mh.callback = &uplcom_write_callback,
205 .if_index = 0,
206 },
207
208 [UPLCOM_BULK_DT_RD] = {
209 .type = UE_BULK,
210 .endpoint = UE_ADDR_ANY,
211 .direction = UE_DIR_IN,
212 .mh.bufsize = UPLCOM_BULK_BUF_SIZE,
213 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
214 .mh.callback = &uplcom_read_callback,
215 .if_index = 0,
216 },
217
218 [UPLCOM_BULK_CS_WR] = {
219 .type = UE_CONTROL,
220 .endpoint = 0x00, /* Control pipe */
221 .direction = UE_DIR_ANY,
222 .mh.bufsize = sizeof(struct usb2_device_request),
223 .mh.callback = &uplcom_write_clear_stall_callback,
224 .mh.timeout = 1000, /* 1 second */
225 .mh.interval = 50, /* 50ms */
226 .if_index = 0,
227 },
228
229 [UPLCOM_BULK_CS_RD] = {
230 .type = UE_CONTROL,
231 .endpoint = 0x00, /* Control pipe */
232 .direction = UE_DIR_ANY,
233 .mh.bufsize = sizeof(struct usb2_device_request),
234 .mh.callback = &uplcom_read_clear_stall_callback,
235 .mh.timeout = 1000, /* 1 second */
236 .mh.interval = 50, /* 50ms */
237 .if_index = 0,
238 },
239
240 [UPLCOM_INTR_DT_RD] = {
241 .type = UE_INTERRUPT,
242 .endpoint = UE_ADDR_ANY,
243 .direction = UE_DIR_IN,
244 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
245 .mh.bufsize = 0, /* use wMaxPacketSize */
246 .mh.callback = &uplcom_intr_callback,
247 .if_index = 1,
248 },
249
250 [UPLCOM_INTR_CS_RD] = {
251 .type = UE_CONTROL,
252 .endpoint = 0x00, /* Control pipe */
253 .direction = UE_DIR_ANY,
254 .mh.bufsize = sizeof(struct usb2_device_request),
255 .mh.callback = &uplcom_intr_clear_stall_callback,
256 .mh.timeout = 1000, /* 1 second */
257 .mh.interval = 50, /* 50ms */
258 .if_index = 1,

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

721}
722
723static void
724uplcom_start_read(struct usb2_com_softc *ucom)
725{
726 struct uplcom_softc *sc = ucom->sc_parent;
727
728 /* start interrupt endpoint */
729 usb2_transfer_start(sc->sc_xfer[UPLCOM_INTR_DT_RD]);
730
731 /* start read endpoint */
732 usb2_transfer_start(sc->sc_xfer[UPLCOM_BULK_DT_RD]);
733}
734
735static void
736uplcom_stop_read(struct usb2_com_softc *ucom)
737{
738 struct uplcom_softc *sc = ucom->sc_parent;
739
740 /* stop interrupt endpoint */
741 usb2_transfer_stop(sc->sc_xfer[UPLCOM_INTR_DT_RD]);
742
743 /* stop read endpoint */
744 usb2_transfer_stop(sc->sc_xfer[UPLCOM_BULK_CS_RD]);
745 usb2_transfer_stop(sc->sc_xfer[UPLCOM_BULK_DT_RD]);
746}
747
748static void
749uplcom_start_write(struct usb2_com_softc *ucom)
750{
751 struct uplcom_softc *sc = ucom->sc_parent;
752
753 usb2_transfer_start(sc->sc_xfer[UPLCOM_BULK_DT_WR]);
754}
755
756static void
757uplcom_stop_write(struct usb2_com_softc *ucom)
758{
759 struct uplcom_softc *sc = ucom->sc_parent;
760
761 usb2_transfer_stop(sc->sc_xfer[UPLCOM_BULK_CS_WR]);
762 usb2_transfer_stop(sc->sc_xfer[UPLCOM_BULK_DT_WR]);
763}
764
765static void
766uplcom_cfg_get_status(struct usb2_com_softc *ucom, uint8_t *lsr, uint8_t *msr)
767{
768 struct uplcom_softc *sc = ucom->sc_parent;
769
770 DPRINTF("\n");

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

801 }
802 if (buf[8] & RSAQ_STATUS_DCD) {
803 sc->sc_msr |= SER_DCD;
804 }
805 usb2_com_status_change(&sc->sc_ucom);
806 }
807 case USB_ST_SETUP:
808 if (sc->sc_flag & UPLCOM_FLAG_INTR_STALL) {
809 usb2_transfer_start(sc->sc_xfer[UPLCOM_INTR_CS_RD]);
810 } else {
811 xfer->frlengths[0] = xfer->max_data_length;
812 usb2_start_hardware(xfer);
813 }
814 return;
815
816 default: /* Error */
817 if (xfer->error != USB_ERR_CANCELLED) {
818 sc->sc_flag |= UPLCOM_FLAG_INTR_STALL;
819 usb2_transfer_start(sc->sc_xfer[UPLCOM_INTR_CS_RD]);
820 }
821 return;
822
823 }
824}
825
826static void
827uplcom_intr_clear_stall_callback(struct usb2_xfer *xfer)
828{
829 struct uplcom_softc *sc = xfer->priv_sc;
830 struct usb2_xfer *xfer_other = sc->sc_xfer[UPLCOM_INTR_DT_RD];
831
832 if (usb2_clear_stall_callback(xfer, xfer_other)) {
833 DPRINTF("stall cleared\n");
834 sc->sc_flag &= ~UPLCOM_FLAG_INTR_STALL;
835 usb2_transfer_start(xfer_other);
836 }
837}
838
839static void
840uplcom_write_callback(struct usb2_xfer *xfer)
841{
842 struct uplcom_softc *sc = xfer->priv_sc;
843 uint32_t actlen;
844
845 switch (USB_GET_STATE(xfer)) {
846 case USB_ST_SETUP:
847 case USB_ST_TRANSFERRED:
848 if (sc->sc_flag & UPLCOM_FLAG_WRITE_STALL) {
849 usb2_transfer_start(sc->sc_xfer[UPLCOM_BULK_CS_WR]);
850 return;
851 }
852 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
853 UPLCOM_BULK_BUF_SIZE, &actlen)) {
854
855 DPRINTF("actlen = %d\n", actlen);
856
857 xfer->frlengths[0] = actlen;
858 usb2_start_hardware(xfer);
859 }
860 return;
861
862 default: /* Error */
863 if (xfer->error != USB_ERR_CANCELLED) {
864 sc->sc_flag |= UPLCOM_FLAG_WRITE_STALL;
865 usb2_transfer_start(sc->sc_xfer[UPLCOM_BULK_CS_WR]);
866 }
867 return;
868
869 }
870}
871
872static void
873uplcom_write_clear_stall_callback(struct usb2_xfer *xfer)
874{
875 struct uplcom_softc *sc = xfer->priv_sc;
876 struct usb2_xfer *xfer_other = sc->sc_xfer[UPLCOM_BULK_DT_WR];
877
878 if (usb2_clear_stall_callback(xfer, xfer_other)) {
879 DPRINTF("stall cleared\n");
880 sc->sc_flag &= ~UPLCOM_FLAG_WRITE_STALL;
881 usb2_transfer_start(xfer_other);
882 }
883}
884
885static void
886uplcom_read_callback(struct usb2_xfer *xfer)
887{
888 struct uplcom_softc *sc = xfer->priv_sc;
889
890 switch (USB_GET_STATE(xfer)) {
891 case USB_ST_TRANSFERRED:
892 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
893
894 case USB_ST_SETUP:
895 if (sc->sc_flag & UPLCOM_FLAG_READ_STALL) {
896 usb2_transfer_start(sc->sc_xfer[UPLCOM_BULK_CS_RD]);
897 } else {
898 xfer->frlengths[0] = xfer->max_data_length;
899 usb2_start_hardware(xfer);
900 }
901 return;
902
903 default: /* Error */
904 if (xfer->error != USB_ERR_CANCELLED) {
905 sc->sc_flag |= UPLCOM_FLAG_READ_STALL;
906 usb2_transfer_start(sc->sc_xfer[UPLCOM_BULK_CS_RD]);
907 }
908 return;
909
910 }
911}
912
913static void
914uplcom_read_clear_stall_callback(struct usb2_xfer *xfer)
915{
916 struct uplcom_softc *sc = xfer->priv_sc;
917 struct usb2_xfer *xfer_other = sc->sc_xfer[UPLCOM_BULK_DT_RD];
918
919 if (usb2_clear_stall_callback(xfer, xfer_other)) {
920 DPRINTF("stall cleared\n");
921 sc->sc_flag &= ~UPLCOM_FLAG_READ_STALL;
922 usb2_transfer_start(xfer_other);
923 }
924}
925

--- 26 unchanged lines hidden ---