Deleted Added
sdiff udiff text old ( 187176 ) new ( 187259 )
full compact
1#include <sys/cdefs.h>
2__FBSDID("$FreeBSD: head/sys/dev/usb2/serial/umct2.c 187259 2009-01-15 02:35:40Z thompsa $");
3
4/*-
5 * Copyright (c) 2003 Scott Long
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:

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

75#define UMCT_SET_LCR_SIZE 1
76#define UMCT_SET_MCR 10 /* Set Modem Control Register */
77#define UMCT_SET_MCR_SIZE 1
78
79#define UMCT_INTR_INTERVAL 100
80#define UMCT_IFACE_INDEX 0
81#define UMCT_CONFIG_INDEX 1
82
83enum {
84 UMCT_BULK_DT_WR,
85 UMCT_BULK_DT_RD,
86 UMCT_BULK_CS_WR,
87 UMCT_BULK_CS_RD,
88 UMCT_INTR_DT_RD,
89 UMCT_INTR_CS_RD,
90 UMCT_N_TRANSFER = 6,
91};
92
93struct umct_softc {
94 struct usb2_com_super_softc sc_super_ucom;
95 struct usb2_com_softc sc_ucom;
96
97 struct usb2_device *sc_udev;
98 struct usb2_xfer *sc_xfer[UMCT_N_TRANSFER];
99
100 uint32_t sc_unit;
101
102 uint16_t sc_obufsize;
103
104 uint8_t sc_lsr;
105 uint8_t sc_msr;
106 uint8_t sc_lcr;

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

137static uint8_t umct_calc_baud(uint32_t);
138static int umct_pre_param(struct usb2_com_softc *, struct termios *);
139static void umct_cfg_param(struct usb2_com_softc *, struct termios *);
140static void umct_start_read(struct usb2_com_softc *);
141static void umct_stop_read(struct usb2_com_softc *);
142static void umct_start_write(struct usb2_com_softc *);
143static void umct_stop_write(struct usb2_com_softc *);
144
145static const struct usb2_config umct_config[UMCT_N_TRANSFER] = {
146
147 [UMCT_BULK_DT_WR] = {
148 .type = UE_BULK,
149 .endpoint = UE_ADDR_ANY,
150 .direction = UE_DIR_OUT,
151 .mh.bufsize = 0, /* use wMaxPacketSize */
152 .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,},
153 .mh.callback = &umct_write_callback,
154 },
155
156 [UMCT_BULK_DT_RD] = {
157 .type = UE_INTERRUPT,
158 .endpoint = UE_ADDR_ANY,
159 .direction = UE_DIR_IN,
160 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
161 .mh.bufsize = 0, /* use wMaxPacketSize */
162 .mh.callback = &umct_read_callback,
163 .ep_index = 0, /* first interrupt endpoint */
164 },
165
166 [UMCT_BULK_CS_WR] = {
167 .type = UE_CONTROL,
168 .endpoint = 0x00, /* Control pipe */
169 .direction = UE_DIR_ANY,
170 .mh.bufsize = sizeof(struct usb2_device_request),
171 .mh.flags = {},
172 .mh.callback = &umct_write_clear_stall_callback,
173 .mh.timeout = 1000, /* 1 second */
174 .mh.interval = 50, /* 50ms */
175 },
176
177 [UMCT_BULK_CS_RD] = {
178 .type = UE_CONTROL,
179 .endpoint = 0x00, /* Control pipe */
180 .direction = UE_DIR_ANY,
181 .mh.bufsize = sizeof(struct usb2_device_request),
182 .mh.flags = {},
183 .mh.callback = &umct_read_clear_stall_callback,
184 .mh.timeout = 1000, /* 1 second */
185 .mh.interval = 50, /* 50ms */
186 },
187
188 [UMCT_INTR_DT_RD] = {
189 .type = UE_INTERRUPT,
190 .endpoint = UE_ADDR_ANY,
191 .direction = UE_DIR_IN,
192 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
193 .mh.bufsize = 0, /* use wMaxPacketSize */
194 .mh.callback = &umct_intr_callback,
195 .ep_index = 1, /* second interrupt endpoint */
196 },
197
198 [UMCT_INTR_CS_RD] = {
199 .type = UE_CONTROL,
200 .endpoint = 0x00, /* Control pipe */
201 .direction = UE_DIR_ANY,
202 .mh.bufsize = sizeof(struct usb2_device_request),
203 .mh.flags = {},
204 .mh.callback = &umct_intr_clear_stall_callback,
205 .mh.timeout = 1000, /* 1 second */
206 .mh.interval = 50, /* 50ms */

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

283
284 snprintf(sc->sc_name, sizeof(sc->sc_name),
285 "%s", device_get_nameunit(dev));
286
287 sc->sc_iface_no = uaa->info.bIfaceNum;
288
289 iface_index = UMCT_IFACE_INDEX;
290 error = usb2_transfer_setup(uaa->device, &iface_index,
291 sc->sc_xfer, umct_config, UMCT_N_TRANSFER, sc, &Giant);
292
293 if (error) {
294 device_printf(dev, "allocating USB "
295 "transfers failed!\n");
296 goto detach;
297 }
298 /*
299 * The real bulk-in endpoint is also marked as an interrupt.
300 * The only way to differentiate it from the real interrupt
301 * endpoint is to look at the wMaxPacketSize field.
302 */
303 maxp = UGETW(sc->sc_xfer[UMCT_BULK_DT_RD]->pipe->edesc->wMaxPacketSize);
304 if (maxp == 0x2) {
305
306 /* guessed wrong - switch around endpoints */
307
308 struct usb2_xfer *temp = sc->sc_xfer[UMCT_INTR_DT_RD];
309
310 sc->sc_xfer[UMCT_INTR_DT_RD] = sc->sc_xfer[UMCT_BULK_DT_RD];
311 sc->sc_xfer[UMCT_BULK_DT_RD] = temp;
312
313 sc->sc_xfer[UMCT_BULK_DT_RD]->callback = &umct_read_callback;
314 sc->sc_xfer[UMCT_INTR_DT_RD]->callback = &umct_intr_callback;
315 }
316 sc->sc_obufsize = sc->sc_xfer[UMCT_BULK_DT_WR]->max_data_length;
317
318 if (uaa->info.idProduct == USB_PRODUCT_MCT_SITECOM_USB232) {
319 if (sc->sc_obufsize > 16) {
320 sc->sc_obufsize = 16;
321 }
322 }
323 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
324 &umct_callback, &Giant);

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

334
335static int
336umct_detach(device_t dev)
337{
338 struct umct_softc *sc = device_get_softc(dev);
339
340 usb2_com_detach(&sc->sc_super_ucom, &sc->sc_ucom, 1);
341
342 usb2_transfer_unsetup(sc->sc_xfer, UMCT_N_TRANSFER);
343
344 return (0);
345}
346
347static void
348umct_cfg_do_request(struct umct_softc *sc, uint8_t request,
349 uint16_t len, uint32_t value)
350{

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

376done:
377 return;
378}
379
380static void
381umct_intr_clear_stall_callback(struct usb2_xfer *xfer)
382{
383 struct umct_softc *sc = xfer->priv_sc;
384 struct usb2_xfer *xfer_other = sc->sc_xfer[UMCT_INTR_DT_RD];
385
386 if (usb2_clear_stall_callback(xfer, xfer_other)) {
387 DPRINTF("stall cleared\n");
388 sc->sc_flags &= ~UMCT_FLAG_INTR_STALL;
389 usb2_transfer_start(xfer_other);
390 }
391}
392

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

407 sc->sc_msr = buf[0];
408 sc->sc_lsr = buf[1];
409
410 usb2_com_status_change(&sc->sc_ucom);
411
412 case USB_ST_SETUP:
413tr_setup:
414 if (sc->sc_flags & UMCT_FLAG_INTR_STALL) {
415 usb2_transfer_start(sc->sc_xfer[UMCT_INTR_CS_RD]);
416 } else {
417 xfer->frlengths[0] = xfer->max_data_length;
418 usb2_start_hardware(xfer);
419 }
420 return;
421
422 default: /* Error */
423 if (xfer->error != USB_ERR_CANCELLED) {
424 /* start clear stall */
425 sc->sc_flags |= UMCT_FLAG_INTR_STALL;
426 usb2_transfer_start(sc->sc_xfer[UMCT_INTR_CS_RD]);
427 }
428 return;
429
430 }
431}
432
433static void
434umct_cfg_get_status(struct usb2_com_softc *ucom, uint8_t *lsr, uint8_t *msr)

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

556}
557
558static void
559umct_start_read(struct usb2_com_softc *ucom)
560{
561 struct umct_softc *sc = ucom->sc_parent;
562
563 /* start interrupt endpoint */
564 usb2_transfer_start(sc->sc_xfer[UMCT_INTR_DT_RD]);
565
566 /* start read endpoint */
567 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_DT_RD]);
568}
569
570static void
571umct_stop_read(struct usb2_com_softc *ucom)
572{
573 struct umct_softc *sc = ucom->sc_parent;
574
575 /* stop interrupt endpoint */
576 usb2_transfer_stop(sc->sc_xfer[UMCT_INTR_CS_RD]);
577 usb2_transfer_stop(sc->sc_xfer[UMCT_INTR_DT_RD]);
578
579 /* stop read endpoint */
580 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_CS_RD]);
581 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_DT_RD]);
582}
583
584static void
585umct_start_write(struct usb2_com_softc *ucom)
586{
587 struct umct_softc *sc = ucom->sc_parent;
588
589 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_DT_WR]);
590}
591
592static void
593umct_stop_write(struct usb2_com_softc *ucom)
594{
595 struct umct_softc *sc = ucom->sc_parent;
596
597 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_CS_WR]);
598 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_DT_WR]);
599}
600
601static void
602umct_write_callback(struct usb2_xfer *xfer)
603{
604 struct umct_softc *sc = xfer->priv_sc;
605 uint32_t actlen;
606
607 switch (USB_GET_STATE(xfer)) {
608 case USB_ST_SETUP:
609 case USB_ST_TRANSFERRED:
610 if (sc->sc_flags & UMCT_FLAG_WRITE_STALL) {
611 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_CS_WR]);
612 return;
613 }
614 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
615 sc->sc_obufsize, &actlen)) {
616
617 xfer->frlengths[0] = actlen;
618 usb2_start_hardware(xfer);
619 }
620 return;
621
622 default: /* Error */
623 if (xfer->error != USB_ERR_CANCELLED) {
624 sc->sc_flags |= UMCT_FLAG_WRITE_STALL;
625 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_CS_WR]);
626 }
627 return;
628
629 }
630}
631
632static void
633umct_write_clear_stall_callback(struct usb2_xfer *xfer)
634{
635 struct umct_softc *sc = xfer->priv_sc;
636 struct usb2_xfer *xfer_other = sc->sc_xfer[UMCT_BULK_DT_WR];
637
638 if (usb2_clear_stall_callback(xfer, xfer_other)) {
639 DPRINTF("stall cleared\n");
640 sc->sc_flags &= ~UMCT_FLAG_WRITE_STALL;
641 usb2_transfer_start(xfer_other);
642 }
643}
644

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

649
650 switch (USB_GET_STATE(xfer)) {
651 case USB_ST_TRANSFERRED:
652 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers,
653 0, xfer->actlen);
654
655 case USB_ST_SETUP:
656 if (sc->sc_flags & UMCT_FLAG_READ_STALL) {
657 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_CS_RD]);
658 } else {
659 xfer->frlengths[0] = xfer->max_data_length;
660 usb2_start_hardware(xfer);
661 }
662 return;
663
664 default: /* Error */
665 if (xfer->error != USB_ERR_CANCELLED) {
666 sc->sc_flags |= UMCT_FLAG_READ_STALL;
667 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_CS_RD]);
668 }
669 return;
670
671 }
672}
673
674static void
675umct_read_clear_stall_callback(struct usb2_xfer *xfer)
676{
677 struct umct_softc *sc = xfer->priv_sc;
678 struct usb2_xfer *xfer_other = sc->sc_xfer[UMCT_BULK_DT_RD];
679
680 if (usb2_clear_stall_callback(xfer, xfer_other)) {
681 DPRINTF("stall cleared\n");
682 sc->sc_flags &= ~UMCT_FLAG_READ_STALL;
683 usb2_transfer_start(xfer_other);
684 }
685}