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 driver for FTDI FT8U100AX serial adapter.



details:   https://anonhg.NetBSD.org/src/rev/ae1bab4e2172
branches:  trunk
changeset: 484908:ae1bab4e2172
user:      augustss <augustss%NetBSD.org@localhost>
date:      Fri Apr 14 14:51:22 2000 +0000

description:
Add driver for FTDI FT8U100AX serial adapter.
XXX This is still experimental and needs more work.

diffstat:

 sys/dev/usb/files.usb  |    8 +-
 sys/dev/usb/uftdi.c    |  504 +++++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/usb/uftdireg.h |  324 +++++++++++++++++++++++++++++++
 3 files changed, 835 insertions(+), 1 deletions(-)

diffs (truncated from 855 to 300 lines):

diff -r 1f4745d9c010 -r ae1bab4e2172 sys/dev/usb/files.usb
--- a/sys/dev/usb/files.usb     Fri Apr 14 14:48:29 2000 +0000
+++ b/sys/dev/usb/files.usb     Fri Apr 14 14:51:22 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.usb,v 1.20 2000/04/14 14:20:02 augustss Exp $
+#      $NetBSD: files.usb,v 1.21 2000/04/14 14:51:22 augustss Exp $
 #
 # Config file and device description for machine-independent USB code.
 # Included by ports that need it.  Ports that use it must provide
@@ -103,3 +103,9 @@
 device upl: ifnet
 attach upl at uhub
 file   dev/usb/if_upl.c                upl
+
+# Serial drivers
+# FTDI serial driver
+device uftdi: ucombus
+attach uftdi at uhub
+file   dev/usb/uftdi.c                 uftdi
diff -r 1f4745d9c010 -r ae1bab4e2172 sys/dev/usb/uftdi.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/uftdi.c       Fri Apr 14 14:51:22 2000 +0000
@@ -0,0 +1,504 @@
+/*     $NetBSD: uftdi.c,v 1.1 2000/04/14 14:51:22 augustss Exp $       */
+
+/*
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Lennart Augustsson (lennart%augustsson.net@localhost).
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * FTDI FT8U100AX serial adapter driver
+ */
+
+/*
+ * XXX This driver will not support multiple serial ports.
+ * XXX The ucom layer needs to be extended first.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/conf.h>
+#include <sys/tty.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbhid.h>
+
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdi_util.h>
+#include <dev/usb/usbdevs.h>
+
+#include <dev/usb/ucomvar.h>
+
+#include <dev/usb/uftdireg.h>
+
+#ifdef UFTDI_DEBUG
+#define DPRINTF(x)     if (uftdidebug) printf x
+#define DPRINTFN(n,x)  if (uftdidebug>(n)) printf x
+int uftdidebug = 15;
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n,x)
+#endif
+
+#define UFTDI_CONFIG_INDEX     0
+#define UFTDI_IFACE_INDEX      0
+
+
+/*
+ * These are the maximum number of bytes transferred per frame.
+ * The output buffer size cannot be increased due to the size encoding.
+ */
+#define UFTDIIBUFSIZE 64
+#define UFTDIOBUFSIZE 64
+
+struct uftdi_softc {
+       USBBASEDEVICE           sc_dev;         /* base device */
+       usbd_device_handle      sc_udev;        /* device */
+       usbd_interface_handle   sc_iface;       /* interface */
+
+       u_char                  sc_msr;
+       u_char                  sc_lsr;
+
+       device_ptr_t            sc_subdev;
+
+       u_char                  sc_dying;
+};
+
+Static void    uftdi_get_status __P((void *, int portno, u_char *lsr,
+                                     u_char *msr));
+Static void    uftdi_set       __P((void *, int, int, int));
+Static int     uftdi_param     __P((void *, int, struct termios *));
+Static int     uftdi_open      __P((void *sc, int portno));
+Static void    uftdi_read      __P((void *sc, int portno, u_char **ptr,
+                                    u_int32_t *count));
+Static void    uftdi_write     __P((void *sc, int portno, u_char *to,
+                                    u_char *from, u_int32_t *count));
+
+struct ucom_methods uftdi_methods = {
+       uftdi_get_status,
+       uftdi_set,
+       uftdi_param,
+       NULL,
+       uftdi_open,
+       NULL,
+       uftdi_read,
+       uftdi_write,
+};
+
+USB_DECLARE_DRIVER(uftdi);
+
+USB_MATCH(uftdi)
+{
+       USB_MATCH_START(uftdi, uaa);
+       
+       if (uaa->iface != NULL)
+               return (UMATCH_NONE);
+
+       DPRINTFN(20,("uftdi: vendor=0x%x, product=0x%x\n",
+                    uaa->vendor, uaa->product));
+
+       if (uaa->vendor == USB_VENDOR_FTDI &&
+           uaa->product == USB_PRODUCT_FTDI_SERIAL)
+               return (UMATCH_VENDOR_PRODUCT);
+
+       return (UMATCH_NONE);
+}
+
+USB_ATTACH(uftdi)
+{
+       USB_ATTACH_START(uftdi, sc, uaa);
+       usbd_device_handle dev = uaa->device;
+       usbd_interface_handle iface;
+       usb_interface_descriptor_t *id;
+       usb_endpoint_descriptor_t *ed;
+       char devinfo[1024];
+       char *devname = USBDEVNAME(sc->sc_dev);
+       int i;
+       usbd_status err;
+       struct ucom_attach_args uca;
+
+       DPRINTFN(10,("\nuftdi_attach: sc=%p\n", sc));
+
+       /* Move the device into the configured state. */
+       err = usbd_set_config_index(dev, UFTDI_CONFIG_INDEX, 1);
+       if (err) {
+               printf("\n%s: failed to set configuration, err=%s\n",
+                      devname, usbd_errstr(err));
+               goto bad;
+       }
+
+       err = usbd_device2interface_handle(dev, UFTDI_IFACE_INDEX, &iface);
+       if (err) {
+               printf("\n%s: failed to get interface, err=%s\n",
+                      devname, usbd_errstr(err));
+               goto bad;
+       }
+
+       usbd_devinfo(dev, 0, devinfo);
+       USB_ATTACH_SETUP;
+       printf("%s: %s\n", devname, devinfo);
+
+       id = usbd_get_interface_descriptor(iface);
+
+       sc->sc_udev = dev;
+       sc->sc_iface = iface;
+
+       uca.bulkin = uca.bulkout = -1;
+       for (i = 0; i < id->bNumEndpoints; i++) {
+               int addr, dir, attr;
+               ed = usbd_interface2endpoint_descriptor(iface, i);
+               if (ed == NULL) {
+                       printf("%s: could not read endpoint descriptor"
+                              ": %s\n", devname, usbd_errstr(err));
+                       goto bad;
+               }
+               
+               addr = ed->bEndpointAddress;
+               dir = UE_GET_DIR(ed->bEndpointAddress);
+               attr = ed->bmAttributes & UE_XFERTYPE;
+               if (dir == UE_DIR_IN && attr == UE_BULK)
+                       uca.bulkin = addr;
+               else if (dir == UE_DIR_OUT && attr == UE_BULK)
+                       uca.bulkout = addr;
+               else {
+                       printf("%s: unexpected endpoint\n", devname);
+                       goto bad;
+               }
+       }
+       if (uca.bulkin == -1) {
+               printf("%s: Could not find data bulk in\n",
+                      USBDEVNAME(sc->sc_dev));
+               goto bad;
+       }
+       if (uca.bulkout == -1) {
+               printf("%s: Could not find data bulk out\n",
+                      USBDEVNAME(sc->sc_dev));
+               goto bad;
+       }
+       
+       uca.portno = FTDI_PIT_SIOA;
+       /* bulkin, bulkout set above */
+       uca.ibufsize = UFTDIIBUFSIZE;
+       uca.obufsize = UFTDIOBUFSIZE - 1;
+       uca.ibufsizepad = UFTDIIBUFSIZE;
+       uca.obufsizepad = UFTDIOBUFSIZE;
+       uca.device = dev;
+       uca.iface = iface;
+       uca.methods = &uftdi_methods;
+       uca.arg = sc;
+
+       DPRINTF(("uftdi: in=0x%x out=0x%x\n", uca.bulkin, uca.bulkout));
+       sc->sc_subdev = config_found_sm(self, &uca, ucomprint, ucomsubmatch);
+
+       USB_ATTACH_SUCCESS_RETURN;
+
+bad:
+       DPRINTF(("uftdi_attach: ATTACH ERROR\n"));
+       sc->sc_dying = 1;
+       USB_ATTACH_ERROR_RETURN;
+}
+
+int
+uftdi_activate(self, act)
+       device_ptr_t self;
+       enum devact act;
+{
+       struct uftdi_softc *sc = (struct uftdi_softc *)self;
+       int rv = 0;
+
+       switch (act) {
+       case DVACT_ACTIVATE:
+               return (EOPNOTSUPP);
+               break;
+
+       case DVACT_DEACTIVATE:
+               if (sc->sc_subdev != NULL)
+                       rv = config_deactivate(sc->sc_subdev);
+               sc->sc_dying = 1;
+               break;
+       }
+       return (rv);
+}
+
+int
+uftdi_detach(self, flags)
+       device_ptr_t self;
+       int flags;
+{
+       struct uftdi_softc *sc = (struct uftdi_softc *)self;
+       int rv = 0;
+
+       DPRINTF(("uftdi_detach: sc=%p flags=%d\n", sc, flags));
+       sc->sc_dying = 1;
+       if (sc->sc_subdev != NULL) {
+               rv = config_detach(sc->sc_subdev, flags);
+               sc->sc_subdev = NULL;
+       }
+       return (0);
+}
+
+Static int
+uftdi_open(vsc, portno)
+       void *vsc;
+       int portno;
+{
+       struct uftdi_softc *sc = vsc;



Home | Main Index | Thread Index | Old Index