Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb Add support for FTDI USB->Serial adapters based ...



details:   https://anonhg.NetBSD.org/src/rev/c421dad946f3
branches:  trunk
changeset: 526692:c421dad946f3
user:      scw <scw%NetBSD.org@localhost>
date:      Wed May 08 18:10:19 2002 +0000

description:
Add support for FTDI USB->Serial adapters based on the FT8U232AM chip.
Changes inspired by the latest linux version of the driver.

This gets the dongle supplied with my HP Omnibook working (it has no
legacy com(4) ports).

diffstat:

 sys/dev/usb/uftdi.c    |  89 ++++++++++++++++++++++++++++++++++++++-----------
 sys/dev/usb/uftdireg.h |  22 +++++++++++-
 2 files changed, 89 insertions(+), 22 deletions(-)

diffs (193 lines):

diff -r c73d2f2e11e6 -r c421dad946f3 sys/dev/usb/uftdi.c
--- a/sys/dev/usb/uftdi.c       Wed May 08 18:06:47 2002 +0000
+++ b/sys/dev/usb/uftdi.c       Wed May 08 18:10:19 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uftdi.c,v 1.9 2001/12/17 14:34:37 ichiro Exp $ */
+/*     $NetBSD: uftdi.c,v 1.10 2002/05/08 18:10:19 scw Exp $   */
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uftdi.c,v 1.9 2001/12/17 14:34:37 ichiro Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uftdi.c,v 1.10 2002/05/08 18:10:19 scw Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -91,6 +91,9 @@
        usbd_device_handle      sc_udev;        /* device */
        usbd_interface_handle   sc_iface;       /* interface */
 
+       enum uftdi_type         sc_type;
+       u_int                   sc_hdrlen;
+
        u_char                  sc_msr;
        u_char                  sc_lsr;
 
@@ -134,7 +137,8 @@
                     uaa->vendor, uaa->product));
 
        if (uaa->vendor == USB_VENDOR_FTDI &&
-           uaa->product == USB_PRODUCT_FTDI_SERIAL)
+           (uaa->product == USB_PRODUCT_FTDI_SERIAL_8U100AX ||
+            uaa->product == USB_PRODUCT_FTDI_SERIAL_8U232AM))
                return (UMATCH_VENDOR_PRODUCT);
 
        return (UMATCH_NONE);
@@ -179,6 +183,21 @@
        sc->sc_udev = dev;
        sc->sc_iface = iface;
 
+       switch (uaa->product) {
+       case USB_PRODUCT_FTDI_SERIAL_8U100AX:
+               sc->sc_type = UFTDI_TYPE_SIO;
+               sc->sc_hdrlen = 1;
+               break;
+
+       case USB_PRODUCT_FTDI_SERIAL_8U232AM:
+               sc->sc_type = UFTDI_TYPE_8U232AM;
+               sc->sc_hdrlen = 0;
+               break;
+
+       default:                /* Can't happen */
+               goto bad;
+       }
+
        uca.bulkin = uca.bulkout = -1;
        for (i = 0; i < id->bNumEndpoints; i++) {
                int addr, dir, attr;
@@ -215,9 +234,9 @@
        uca.portno = FTDI_PIT_SIOA;
        /* bulkin, bulkout set above */
        uca.ibufsize = UFTDIIBUFSIZE;
-       uca.obufsize = UFTDIOBUFSIZE - 1;
+       uca.obufsize = UFTDIOBUFSIZE - sc->sc_hdrlen;
        uca.ibufsizepad = UFTDIIBUFSIZE;
-       uca.opkthdrlen = 1;
+       uca.opkthdrlen = sc->sc_hdrlen;
        uca.device = dev;
        uca.iface = iface;
        uca.methods = &uftdi_methods;
@@ -354,13 +373,17 @@
 Static void
 uftdi_write(void *vsc, int portno, u_char *to, u_char *from, u_int32_t *count)
 {
+       struct uftdi_softc *sc = vsc;
+
        DPRINTFN(10,("uftdi_write: sc=%p, port=%d count=%u data[0]=0x%02x\n",
                     vsc, portno, *count, from[0]));
 
        /* Make length tag and copy data */
-       *to = FTDI_OUT_TAG(*count, portno);
-       memcpy(to+1, from, *count);
-       ++*count;
+       if (sc->sc_hdrlen > 0)
+               *to = FTDI_OUT_TAG(*count, portno);
+
+       memcpy(to + sc->sc_hdrlen, from, *count);
+       *count += sc->sc_hdrlen;
 }
 
 Static void
@@ -410,19 +433,43 @@
        if (sc->sc_dying)
                return (EIO);
 
-       switch (t->c_ospeed) {
-       case 300: rate = ftdi_sio_b300; break;
-       case 600: rate = ftdi_sio_b600; break;
-       case 1200: rate = ftdi_sio_b1200; break;
-       case 2400: rate = ftdi_sio_b2400; break;
-       case 4800: rate = ftdi_sio_b4800; break;
-       case 9600: rate = ftdi_sio_b9600; break;
-       case 19200: rate = ftdi_sio_b19200; break;
-       case 38400: rate = ftdi_sio_b38400; break;
-       case 57600: rate = ftdi_sio_b57600; break;
-       case 115200: rate = ftdi_sio_b115200; break;
-       default:
-               return (EINVAL);
+       switch (sc->sc_type) {
+       case UFTDI_TYPE_SIO:
+               switch (t->c_ospeed) {
+               case 300: rate = ftdi_sio_b300; break;
+               case 600: rate = ftdi_sio_b600; break;
+               case 1200: rate = ftdi_sio_b1200; break;
+               case 2400: rate = ftdi_sio_b2400; break;
+               case 4800: rate = ftdi_sio_b4800; break;
+               case 9600: rate = ftdi_sio_b9600; break;
+               case 19200: rate = ftdi_sio_b19200; break;
+               case 38400: rate = ftdi_sio_b38400; break;
+               case 57600: rate = ftdi_sio_b57600; break;
+               case 115200: rate = ftdi_sio_b115200; break;
+               default:
+                       return (EINVAL);
+               }
+               break;
+
+       case UFTDI_TYPE_8U232AM:
+               switch(t->c_ospeed) {
+               case 300: rate = ftdi_8u232am_b300; break;
+               case 600: rate = ftdi_8u232am_b600; break;
+               case 1200: rate = ftdi_8u232am_b1200; break;
+               case 2400: rate = ftdi_8u232am_b2400; break;
+               case 4800: rate = ftdi_8u232am_b4800; break;
+               case 9600: rate = ftdi_8u232am_b9600; break;
+               case 19200: rate = ftdi_8u232am_b19200; break;
+               case 38400: rate = ftdi_8u232am_b38400; break;
+               case 57600: rate = ftdi_8u232am_b57600; break;
+               case 115200: rate = ftdi_8u232am_b115200; break;
+               case 230400: rate = ftdi_8u232am_b230400; break;
+               case 460800: rate = ftdi_8u232am_b460800; break;
+               case 921600: rate = ftdi_8u232am_b921600; break;
+               default:
+                       return (EINVAL);
+               }
+               break;
        }
        req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
        req.bRequest = FTDI_SIO_SET_BAUD_RATE;
diff -r c73d2f2e11e6 -r c421dad946f3 sys/dev/usb/uftdireg.h
--- a/sys/dev/usb/uftdireg.h    Wed May 08 18:06:47 2002 +0000
+++ b/sys/dev/usb/uftdireg.h    Wed May 08 18:10:19 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uftdireg.h,v 1.4 2001/12/17 14:31:02 ichiro Exp $ */
+/*     $NetBSD: uftdireg.h,v 1.5 2002/05/08 18:10:19 scw Exp $ */
 
 /*
  * Definitions for the FTDI USB Single Port Serial Converter - 
@@ -32,6 +32,11 @@
 #define FTDI_PIT_SIOB          2 /* SIOB */
 #define FTDI_PIT_PARALLEL      3 /* Parallel */
 
+enum uftdi_type {
+       UFTDI_TYPE_SIO,
+       UFTDI_TYPE_8U232AM
+};
+
 /*
  * BmRequestType:  0100 0000B
  * bRequest:       FTDI_SIO_RESET
@@ -85,6 +90,21 @@
        ftdi_sio_b115200 = 9
 };
 
+enum {
+       ftdi_8u232am_b300 = 0x2710,
+       ftdi_8u232am_b600 = 0x1388,
+       ftdi_8u232am_b1200 = 0x09c4,
+       ftdi_8u232am_b2400 = 0x04e2,
+       ftdi_8u232am_b4800 = 0x0271,
+       ftdi_8u232am_b9600 = 0x4138,
+       ftdi_8u232am_b19200 = 0x809c,
+       ftdi_8u232am_b38400 = 0xc04e,
+       ftdi_8u232am_b57600 = 0x0034,
+       ftdi_8u232am_b115200 = 0x001a,
+       ftdi_8u232am_b230400 = 0x000d,
+       ftdi_8u232am_b460800 = 0x4006,
+       ftdi_8u232am_b921600 = 0x8003
+};
 
 /*
  * BmRequestType:  0100 0000B 



Home | Main Index | Thread Index | Old Index