uplcom.c (194228) | uplcom.c (194677) |
---|---|
1/* $NetBSD: uplcom.c,v 1.21 2001/11/13 06:24:56 lukem Exp $ */ 2 3#include <sys/cdefs.h> | 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/usb/serial/uplcom.c 194228 2009-06-15 01:02:43Z thompsa $"); | 4__FBSDID("$FreeBSD: head/sys/dev/usb/serial/uplcom.c 194677 2009-06-23 02:19:59Z 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: --- 66 unchanged lines hidden (view full) --- 79 * 80 * There are several differences between PL-2303 and PL-2303(H)X. 81 * PL-2303(H)X can do higher bitrate in bulk mode, has _probably_ 82 * different command for controlling CRTSCTS and needs special 83 * sequence of commands for initialization which aren't also 84 * documented in the datasheet. 85 */ 86 | 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: --- 66 unchanged lines hidden (view full) --- 79 * 80 * There are several differences between PL-2303 and PL-2303(H)X. 81 * PL-2303(H)X can do higher bitrate in bulk mode, has _probably_ 82 * different command for controlling CRTSCTS and needs special 83 * sequence of commands for initialization which aren't also 84 * documented in the datasheet. 85 */ 86 |
87#include "usbdevs.h" | 87#include <sys/stdint.h> 88#include <sys/stddef.h> 89#include <sys/param.h> 90#include <sys/queue.h> 91#include <sys/types.h> 92#include <sys/systm.h> 93#include <sys/kernel.h> 94#include <sys/bus.h> 95#include <sys/linker_set.h> 96#include <sys/module.h> 97#include <sys/lock.h> 98#include <sys/mutex.h> 99#include <sys/condvar.h> 100#include <sys/sysctl.h> 101#include <sys/sx.h> 102#include <sys/unistd.h> 103#include <sys/callout.h> 104#include <sys/malloc.h> 105#include <sys/priv.h> 106 |
88#include <dev/usb/usb.h> | 107#include <dev/usb/usb.h> |
89#include <dev/usb/usb_mfunc.h> 90#include <dev/usb/usb_error.h> | 108#include <dev/usb/usbdi.h> 109#include <dev/usb/usbdi_util.h> |
91#include <dev/usb/usb_cdc.h> | 110#include <dev/usb/usb_cdc.h> |
111#include "usbdevs.h" |
|
92 93#define USB_DEBUG_VAR uplcom_debug | 112 113#define USB_DEBUG_VAR uplcom_debug |
94 95#include <dev/usb/usb_core.h> | |
96#include <dev/usb/usb_debug.h> 97#include <dev/usb/usb_process.h> | 114#include <dev/usb/usb_debug.h> 115#include <dev/usb/usb_process.h> |
98#include <dev/usb/usb_request.h> 99#include <dev/usb/usb_lookup.h> 100#include <dev/usb/usb_util.h> 101#include <dev/usb/usb_busdma.h> | |
102 103#include <dev/usb/serial/usb_serial.h> 104 105#if USB_DEBUG 106static int uplcom_debug = 0; 107 108SYSCTL_NODE(_hw_usb, OID_AUTO, uplcom, CTLFLAG_RW, 0, "USB uplcom"); 109SYSCTL_INT(_hw_usb_uplcom, OID_AUTO, debug, CTLFLAG_RW, --- 274 unchanged lines hidden (view full) --- 384 error = uplcom_reset(sc, uaa->device); 385 if (error) { 386 device_printf(dev, "reset failed, error=%s\n", 387 usbd_errstr(error)); 388 goto detach; 389 } 390 /* clear stall at first run */ 391 mtx_lock(&sc->sc_mtx); | 116 117#include <dev/usb/serial/usb_serial.h> 118 119#if USB_DEBUG 120static int uplcom_debug = 0; 121 122SYSCTL_NODE(_hw_usb, OID_AUTO, uplcom, CTLFLAG_RW, 0, "USB uplcom"); 123SYSCTL_INT(_hw_usb_uplcom, OID_AUTO, debug, CTLFLAG_RW, --- 274 unchanged lines hidden (view full) --- 398 error = uplcom_reset(sc, uaa->device); 399 if (error) { 400 device_printf(dev, "reset failed, error=%s\n", 401 usbd_errstr(error)); 402 goto detach; 403 } 404 /* clear stall at first run */ 405 mtx_lock(&sc->sc_mtx); |
392 usbd_transfer_set_stall(sc->sc_xfer[UPLCOM_BULK_DT_WR]); 393 usbd_transfer_set_stall(sc->sc_xfer[UPLCOM_BULK_DT_RD]); | 406 usbd_xfer_set_stall(sc->sc_xfer[UPLCOM_BULK_DT_WR]); 407 usbd_xfer_set_stall(sc->sc_xfer[UPLCOM_BULK_DT_RD]); |
394 mtx_unlock(&sc->sc_mtx); 395 396 error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc, 397 &uplcom_callback, &sc->sc_mtx); 398 if (error) { 399 goto detach; 400 } 401 /* --- 329 unchanged lines hidden (view full) --- 731 732 DPRINTF("\n"); 733 734 *lsr = sc->sc_lsr; 735 *msr = sc->sc_msr; 736} 737 738static void | 408 mtx_unlock(&sc->sc_mtx); 409 410 error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc, 411 &uplcom_callback, &sc->sc_mtx); 412 if (error) { 413 goto detach; 414 } 415 /* --- 329 unchanged lines hidden (view full) --- 745 746 DPRINTF("\n"); 747 748 *lsr = sc->sc_lsr; 749 *msr = sc->sc_msr; 750} 751 752static void |
739uplcom_intr_callback(struct usb_xfer *xfer) | 753uplcom_intr_callback(struct usb_xfer *xfer, usb_error_t error) |
740{ | 754{ |
741 struct uplcom_softc *sc = xfer->priv_sc; | 755 struct uplcom_softc *sc = usbd_xfer_softc(xfer); 756 struct usb_page_cache *pc; |
742 uint8_t buf[9]; | 757 uint8_t buf[9]; |
758 int actlen; |
|
743 | 759 |
760 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); 761 |
|
744 switch (USB_GET_STATE(xfer)) { 745 case USB_ST_TRANSFERRED: 746 | 762 switch (USB_GET_STATE(xfer)) { 763 case USB_ST_TRANSFERRED: 764 |
747 DPRINTF("actlen = %u\n", xfer->actlen); | 765 DPRINTF("actlen = %u\n", actlen); |
748 | 766 |
749 if (xfer->actlen >= 9) { | 767 if (actlen >= 9) { |
750 | 768 |
751 usbd_copy_out(xfer->frbuffers, 0, buf, sizeof(buf)); | 769 pc = usbd_xfer_get_frame(xfer, 0); 770 usbd_copy_out(pc, 0, buf, sizeof(buf)); |
752 753 DPRINTF("status = 0x%02x\n", buf[8]); 754 755 sc->sc_lsr = 0; 756 sc->sc_msr = 0; 757 758 if (buf[8] & RSAQ_STATUS_CTS) { 759 sc->sc_msr |= SER_CTS; 760 } 761 if (buf[8] & RSAQ_STATUS_DSR) { 762 sc->sc_msr |= SER_DSR; 763 } 764 if (buf[8] & RSAQ_STATUS_DCD) { 765 sc->sc_msr |= SER_DCD; 766 } 767 ucom_status_change(&sc->sc_ucom); 768 } 769 case USB_ST_SETUP: 770tr_setup: | 771 772 DPRINTF("status = 0x%02x\n", buf[8]); 773 774 sc->sc_lsr = 0; 775 sc->sc_msr = 0; 776 777 if (buf[8] & RSAQ_STATUS_CTS) { 778 sc->sc_msr |= SER_CTS; 779 } 780 if (buf[8] & RSAQ_STATUS_DSR) { 781 sc->sc_msr |= SER_DSR; 782 } 783 if (buf[8] & RSAQ_STATUS_DCD) { 784 sc->sc_msr |= SER_DCD; 785 } 786 ucom_status_change(&sc->sc_ucom); 787 } 788 case USB_ST_SETUP: 789tr_setup: |
771 xfer->frlengths[0] = xfer->max_data_length; | 790 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); |
772 usbd_transfer_submit(xfer); 773 return; 774 775 default: /* Error */ | 791 usbd_transfer_submit(xfer); 792 return; 793 794 default: /* Error */ |
776 if (xfer->error != USB_ERR_CANCELLED) { | 795 if (error != USB_ERR_CANCELLED) { |
777 /* try to clear stall first */ | 796 /* try to clear stall first */ |
778 xfer->flags.stall_pipe = 1; | 797 usbd_xfer_set_stall(xfer); |
779 goto tr_setup; 780 } 781 return; 782 } 783} 784 785static void | 798 goto tr_setup; 799 } 800 return; 801 } 802} 803 804static void |
786uplcom_write_callback(struct usb_xfer *xfer) | 805uplcom_write_callback(struct usb_xfer *xfer, usb_error_t error) |
787{ | 806{ |
788 struct uplcom_softc *sc = xfer->priv_sc; | 807 struct uplcom_softc *sc = usbd_xfer_softc(xfer); 808 struct usb_page_cache *pc; |
789 uint32_t actlen; 790 791 switch (USB_GET_STATE(xfer)) { 792 case USB_ST_SETUP: 793 case USB_ST_TRANSFERRED: 794tr_setup: | 809 uint32_t actlen; 810 811 switch (USB_GET_STATE(xfer)) { 812 case USB_ST_SETUP: 813 case USB_ST_TRANSFERRED: 814tr_setup: |
795 if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers, 0, | 815 pc = usbd_xfer_get_frame(xfer, 0); 816 if (ucom_get_data(&sc->sc_ucom, pc, 0, |
796 UPLCOM_BULK_BUF_SIZE, &actlen)) { 797 798 DPRINTF("actlen = %d\n", actlen); 799 | 817 UPLCOM_BULK_BUF_SIZE, &actlen)) { 818 819 DPRINTF("actlen = %d\n", actlen); 820 |
800 xfer->frlengths[0] = actlen; | 821 usbd_xfer_set_frame_len(xfer, 0, actlen); |
801 usbd_transfer_submit(xfer); 802 } 803 return; 804 805 default: /* Error */ | 822 usbd_transfer_submit(xfer); 823 } 824 return; 825 826 default: /* Error */ |
806 if (xfer->error != USB_ERR_CANCELLED) { | 827 if (error != USB_ERR_CANCELLED) { |
807 /* try to clear stall first */ | 828 /* try to clear stall first */ |
808 xfer->flags.stall_pipe = 1; | 829 usbd_xfer_set_stall(xfer); |
809 goto tr_setup; 810 } 811 return; 812 } 813} 814 815static void | 830 goto tr_setup; 831 } 832 return; 833 } 834} 835 836static void |
816uplcom_read_callback(struct usb_xfer *xfer) | 837uplcom_read_callback(struct usb_xfer *xfer, usb_error_t error) |
817{ | 838{ |
818 struct uplcom_softc *sc = xfer->priv_sc; | 839 struct uplcom_softc *sc = usbd_xfer_softc(xfer); 840 struct usb_page_cache *pc; 841 int actlen; |
819 | 842 |
843 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); 844 |
|
820 switch (USB_GET_STATE(xfer)) { 821 case USB_ST_TRANSFERRED: | 845 switch (USB_GET_STATE(xfer)) { 846 case USB_ST_TRANSFERRED: |
822 ucom_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen); | 847 pc = usbd_xfer_get_frame(xfer, 0); 848 ucom_put_data(&sc->sc_ucom, pc, 0, actlen); |
823 824 case USB_ST_SETUP: 825tr_setup: | 849 850 case USB_ST_SETUP: 851tr_setup: |
826 xfer->frlengths[0] = xfer->max_data_length; | 852 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); |
827 usbd_transfer_submit(xfer); 828 return; 829 830 default: /* Error */ | 853 usbd_transfer_submit(xfer); 854 return; 855 856 default: /* Error */ |
831 if (xfer->error != USB_ERR_CANCELLED) { | 857 if (error != USB_ERR_CANCELLED) { |
832 /* try to clear stall first */ | 858 /* try to clear stall first */ |
833 xfer->flags.stall_pipe = 1; | 859 usbd_xfer_set_stall(xfer); |
834 goto tr_setup; 835 } 836 return; 837 } 838} | 860 goto tr_setup; 861 } 862 return; 863 } 864} |