Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Rework uslsa(4) based on publicly-available Sili...



details:   https://anonhg.NetBSD.org/src/rev/9ced9b5c2dd4
branches:  trunk
changeset: 772737:9ced9b5c2dd4
user:      jakllsch <jakllsch%NetBSD.org@localhost>
date:      Sat Jan 14 21:06:01 2012 +0000

description:
Rework uslsa(4) based on publicly-available Silicon Labs AN571 document.

diffstat:

 sys/dev/usb/files.usb  |    4 +-
 sys/dev/usb/uslsa.c    |  513 ++++++++++++++++++++++--------------------------
 sys/dev/usb/uslsareg.h |  240 ++++++++++++++++++++++
 3 files changed, 476 insertions(+), 281 deletions(-)

diffs (truncated from 1019 to 300 lines):

diff -r 48354beb0844 -r 9ced9b5c2dd4 sys/dev/usb/files.usb
--- a/sys/dev/usb/files.usb     Sat Jan 14 20:51:00 2012 +0000
+++ b/sys/dev/usb/files.usb     Sat Jan 14 21:06:01 2012 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.usb,v 1.117 2011/12/31 00:08:48 christos Exp $
+#      $NetBSD: files.usb,v 1.118 2012/01/14 21:06:01 jakllsch Exp $
 #
 # Config file and device description for machine-independent USB code.
 # Included by ports that need it.  Ports that use it must provide
@@ -339,7 +339,7 @@
 
 # Silicon Labs CP210x serial driver
 device uslsa: ucombus
-attach uslsa at usbdevif
+attach uslsa at usbifif
 file   dev/usb/uslsa.c                 uslsa
 
 # WinChipHead CH341/340 serial driver
diff -r 48354beb0844 -r 9ced9b5c2dd4 sys/dev/usb/uslsa.c
--- a/sys/dev/usb/uslsa.c       Sat Jan 14 20:51:00 2012 +0000
+++ b/sys/dev/usb/uslsa.c       Sat Jan 14 21:06:01 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uslsa.c,v 1.16 2011/12/23 00:51:49 jakllsch Exp $ */
+/* $NetBSD: uslsa.c,v 1.17 2012/01/14 21:06:01 jakllsch Exp $ */
 
 /* from ugensa.c */
 
@@ -57,12 +57,8 @@
  *
  */
 
-/*
- * Craig Shelley's Linux driver was used for documentation.
- */
-
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uslsa.c,v 1.16 2011/12/23 00:51:49 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uslsa.c,v 1.17 2012/01/14 21:06:01 jakllsch Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -79,102 +75,45 @@
 
 #include <dev/usb/ucomvar.h>
 
-#ifdef DEBUG
-#define USLSA_DEBUG
-#endif
+#include <dev/usb/uslsareg.h>
+
+#include <fs/unicode.h>
 
 #ifdef USLSA_DEBUG
-#define DPRINTF(x)     if (uslsadebug) printf x
-#define DPRINTFN(n,x)  if (uslsadebug>(n)) printf x
+#define DPRINTF(x)     if (uslsadebug) device_printf x
 int uslsadebug = 0;
 #else
 #define DPRINTF(x)
-#define DPRINTFN(n,x)
 #endif
 
-#define USLSA_REQ_SET_STATE    0x00
-
-#define USLSA_REQ_SET_BPS      0x01
-#define USLSA_REQ_GET_BPS      0x02
-
-#define USLSA_REQ_SET_DPS      0x03
-#define USLSA_REQ_GET_DPS      0x04
-
-#define USLSA_REQ_SET_BREAK    0x05
-
-#define USLSA_REQ_SET_FLOW     0x07
-#define USLSA_REQ_GET_FLOW     0x08
-
-#define USLSA_REQ_SET_MODEM    0x13
-#define USLSA_REQ_GET_MODEM    0x14
-
-#define USLSA_REQ_SET_MISC     0x19
-#define USLSA_REQ_GET_MISC     0x20
-
-#define USLSA_STATE_DISABLE    0x0000
-#define USLSA_STATE_ENABLE     0x0001
-
-#define USLSA_BPS(b)   (3686400/b)
-
-#define USLSA_DPS_DATA_MASK            0x0f00
-#define        USLSA_DPS_DATA_FIVE             0x0500
-#define        USLSA_DPS_DATA_SIX              0x0600
-#define        USLSA_DPS_DATA_SEVEN            0x0700
-#define        USLSA_DPS_DATA_EIGHT            0x0800
-#define        USLSA_DPS_DATA_NINE             0x0900
-
-#define USLSA_DPS_PARITY_MASK          0x00f0
-#define USLSA_DPS_PARITY_SPACE         0x0040
-#define USLSA_DPS_PARITY_MARK          0x0030
-#define USLSA_DPS_PARITY_EVEN          0x0020
-#define USLSA_DPS_PARITY_ODD           0x0010
-#define USLSA_DPS_PARITY_NONE          0x0000
-
-#define USLSA_DPS_STOP_MASK            0x000f
-#define USLSA_DPS_STOP_TWO             0x0002
-#define USLSA_DPS_STOP_ONE_FIVE                0x0001
-#define USLSA_DPS_STOP_ONE             0x0000
-
-#define USLSA_BREAK_DISABLE    0x0000
-#define USLSA_BREAK_ENABLE     0x0001
-
-#define USLSA_FLOW_SET_RTS     0x0200
-#define USLSA_FLOW_SET_DTR     0x0100
-#define USLSA_FLOW_MSR_MASK    0x00f0
-#define USLSA_FLOW_MSR_DCD     0x0080
-#define USLSA_FLOW_MSR_RI      0x0040
-#define USLSA_FLOW_MSR_DSR     0x0020
-#define USLSA_FLOW_MSR_CTS     0x0010
-#define USLSA_FLOW_RTS         0x0002
-#define USLSA_FLOW_DTR         0x0001
-
 struct uslsa_softc {
        device_t                sc_dev;         /* base device */
-       usbd_device_handle      sc_udev;        /* device */
+       device_t                sc_subdev;      /* ucom device */
+       usbd_device_handle      sc_udev;        /* usb device */
        usbd_interface_handle   sc_iface;       /* interface */
-
-       device_t                sc_subdev;      /* ucom device */
-
-       u_char                  sc_dying;       /* disconnecting */
-
-       u_char                  sc_lsr;         /* local status register */
-       u_char                  sc_msr;         /* uslsa status register */
+       uint8_t                 sc_ifnum;       /* interface number */
+       bool                    sc_dying;       /* disconnecting */
 };
 
 static void uslsa_get_status(void *sc, int, u_char *, u_char *);
 static void uslsa_set(void *, int, int, int);
 static int uslsa_param(void *, int, struct termios *);
+static int uslsa_ioctl(void *, int, u_long, void *, int, proc_t *);
+
 static int uslsa_open(void *, int);
 static void uslsa_close(void *, int);
 
+static int uslsa_usbd_errno(usbd_status);
 static int uslsa_request_set(struct uslsa_softc *, uint8_t, uint16_t);
-static void uslsa_set_flow(struct uslsa_softc *, tcflag_t, tcflag_t);
+static int uslsa_set_flow(struct uslsa_softc *, tcflag_t, tcflag_t);
+
+static void uslsa_props(struct uslsa_softc *);
 
 static const struct ucom_methods uslsa_methods = {
        uslsa_get_status,
        uslsa_set,
        uslsa_param,
-       NULL,
+       uslsa_ioctl,
        uslsa_open,
        uslsa_close,
        NULL,
@@ -204,7 +143,6 @@
         { USB_VENDOR_SILABS2,           USB_PRODUCT_SILABS2_DCU11CLONE },
         { USB_VENDOR_USI,               USB_PRODUCT_USI_MC60 }
 };
-#define uslsa_lookup(v, p) usb_lookup(uslsa_devs, v, p)
 
 static int uslsa_match(device_t, cfdata_t, void *);
 static void uslsa_attach(device_t, device_t, void *);
@@ -215,59 +153,48 @@
 CFATTACH_DECL2_NEW(uslsa, sizeof(struct uslsa_softc), uslsa_match,
     uslsa_attach, uslsa_detach, uslsa_activate, NULL, uslsa_childdet);
 
-static int 
+static int
 uslsa_match(device_t parent, cfdata_t match, void *aux)
 {
-       struct usb_attach_arg *uaa = aux;
+       const struct usbif_attach_arg *uaa;
+
+       uaa = aux;
 
-       return (uslsa_lookup(uaa->vendor, uaa->product) != NULL ?
-               UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
+       if (usb_lookup(uslsa_devs, uaa->vendor, uaa->product) != NULL) {
+               return UMATCH_VENDOR_PRODUCT;
+       } else {
+               return UMATCH_NONE;
+       }
 }
 
-static void 
+static void
 uslsa_attach(device_t parent, device_t self, void *aux)
 {
-       struct uslsa_softc *sc = device_private(self);
-       struct usb_attach_arg *uaa = aux;
-       usbd_device_handle dev = uaa->device;
-       usbd_interface_handle iface;
-       usb_interface_descriptor_t *id;
-       usb_endpoint_descriptor_t *ed;
+       struct uslsa_softc *sc;
+       const struct usbif_attach_arg *uaa;
+       const usb_interface_descriptor_t *id;
+       const usb_endpoint_descriptor_t *ed;
        char *devinfop;
-       usbd_status err;
        struct ucom_attach_args uca;
        int i;
 
-       sc->sc_dev = self;
+       sc = device_private(self);
+       uaa = aux;
 
-       DPRINTFN(10, ("\nuslsa_attach: sc=%p\n", sc));
+       sc->sc_dev = self;
+       sc->sc_udev = uaa->device;
+       sc->sc_iface = uaa->iface;
 
        aprint_naive("\n");
        aprint_normal("\n");
 
-       devinfop = usbd_devinfo_alloc(dev, 0);
+       devinfop = usbd_devinfo_alloc(sc->sc_udev, 0);
        aprint_normal_dev(self, "%s\n", devinfop);
        usbd_devinfo_free(devinfop);
 
-       /* Move the device into the configured state. */
-       err = usbd_set_config_index(dev, USLSA_CONFIG_INDEX, 1);
-       if (err) {
-               aprint_error_dev(self, "failed to set configuration, err=%s\n",
-                  usbd_errstr(err));
-               goto bad;
-       }
+       id = usbd_get_interface_descriptor(sc->sc_iface);
 
-       err = usbd_device2interface_handle(dev, USLSA_IFACE_INDEX, &iface);
-       if (err) {
-               aprint_error_dev(self, "failed to get interface, err=%s\n",
-                  usbd_errstr(err));
-               goto bad;
-       }
-
-       id = usbd_get_interface_descriptor(iface);
-
-       sc->sc_udev = dev;
-       sc->sc_iface = iface;
+       sc->sc_ifnum = id->bInterfaceNumber;
 
        uca.info = "Silicon Labs CP210x";
        uca.portno = UCOM_UNK_PORTNO;
@@ -275,8 +202,8 @@
        uca.obufsize = USLSA_BUFSIZE;
        uca.ibufsizepad = USLSA_BUFSIZE;
        uca.opkthdrlen = 0;
-       uca.device = dev;
-       uca.iface = iface;
+       uca.device = sc->sc_udev;
+       uca.iface = sc->sc_iface;
        uca.methods = &uslsa_methods;
        uca.arg = sc;
 
@@ -287,42 +214,36 @@
        for (i = 0; i < id->bNumEndpoints; i++) {
                int addr, dir, attr;
 
-               ed = usbd_interface2endpoint_descriptor(iface, i);
+               ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
                if (ed == NULL) {
                        aprint_error_dev(self,
-                           "could not read endpoint descriptor: %s\n",
-                           usbd_errstr(err));
-                       goto bad;
+                           "could not read endpoint descriptor\n");
+                       sc->sc_dying = true;
+                       return;
                }
                addr = ed->bEndpointAddress;
                dir = UE_GET_DIR(ed->bEndpointAddress);
                attr = ed->bmAttributes & UE_XFERTYPE;
-               if (dir == UE_DIR_IN && attr == UE_BULK)
+               if (dir == UE_DIR_IN && attr == UE_BULK) {
                        uca.bulkin = addr;
-               else if (dir == UE_DIR_OUT && attr == UE_BULK)
+               } else if (dir == UE_DIR_OUT && attr == UE_BULK) {
                        uca.bulkout = addr;
-               else
+               } else {
                        aprint_error_dev(self, "unexpected endpoint\n");
+               }
        }
-       if (uca.bulkin == -1) {
-               aprint_error_dev(self, "Could not find data bulk in\n");
-               goto bad;
-       }
-       if (uca.bulkout == -1) {
-               aprint_error_dev(self, "Could not find data bulk out\n");
-               goto bad;
+       aprint_debug_dev(sc->sc_dev, "EPs: in=%#x out=%#x\n",
+               uca.bulkin, uca.bulkout);
+       if ((uca.bulkin == -1) || (uca.bulkout == -1)) {
+               aprint_error_dev(self, "could not find endpoints\n");



Home | Main Index | Thread Index | Old Index