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 187176 2009-01-13 19:03:47Z 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#define UPLCOM_N_TRANSFER 6
125
126#define UPLCOM_SET_REQUEST 0x01
127#define UPLCOM_SET_CRTSCTS 0x41
128#define UPLCOM_SET_CRTSCTS_PL2303X 0x61
129#define RSAQ_STATUS_CTS 0x80
130#define RSAQ_STATUS_DSR 0x02
131#define RSAQ_STATUS_DCD 0x01
132
133#define TYPE_PL2303 0
134#define TYPE_PL2303X 1
135
136struct uplcom_softc {
137 struct usb2_com_super_softc sc_super_ucom;
138 struct usb2_com_softc sc_ucom;
139
140 struct usb2_xfer *sc_xfer[UPLCOM_N_TRANSFER];
141 struct usb2_device *sc_udev;
142
143 uint16_t sc_line;

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

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

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

712}
713
714static void
715uplcom_start_read(struct usb2_com_softc *ucom)
716{
717 struct uplcom_softc *sc = ucom->sc_parent;
718
719 /* start interrupt endpoint */
720 usb2_transfer_start(sc->sc_xfer[4]);
721
722 /* start read endpoint */
723 usb2_transfer_start(sc->sc_xfer[1]);
724}
725
726static void
727uplcom_stop_read(struct usb2_com_softc *ucom)
728{
729 struct uplcom_softc *sc = ucom->sc_parent;
730
731 /* stop interrupt endpoint */
732 usb2_transfer_stop(sc->sc_xfer[4]);
733
734 /* stop read endpoint */
735 usb2_transfer_stop(sc->sc_xfer[3]);
736 usb2_transfer_stop(sc->sc_xfer[1]);
737}
738
739static void
740uplcom_start_write(struct usb2_com_softc *ucom)
741{
742 struct uplcom_softc *sc = ucom->sc_parent;
743
744 usb2_transfer_start(sc->sc_xfer[0]);
745}
746
747static void
748uplcom_stop_write(struct usb2_com_softc *ucom)
749{
750 struct uplcom_softc *sc = ucom->sc_parent;
751
752 usb2_transfer_stop(sc->sc_xfer[2]);
753 usb2_transfer_stop(sc->sc_xfer[0]);
754}
755
756static void
757uplcom_cfg_get_status(struct usb2_com_softc *ucom, uint8_t *lsr, uint8_t *msr)
758{
759 struct uplcom_softc *sc = ucom->sc_parent;
760
761 DPRINTF("\n");

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

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

--- 26 unchanged lines hidden ---