On 30/01/13(Wed) 13:19, Raphael Graf wrote:
> On Wed, January 30, 2013 10:52 am, Martin Pieuchot wrote:
> > On 27/01/13(Sun) 16:13, Raphael Graf wrote:
> >> The diff below makes the jtag and serial interfaces of the beaglebone 
> >> (FT2232H)
> >> work simultaneously.
> >> This is how the beaglebone shows up:
> >>
> >> uhub8 at uhub0 port 1 "Standard Microsystems product 0x2412" rev 2.00/b.b2 
> >> addr 3
> >> uftdi0 at uhub8 port 1 configuration 1 interface 1 "FTDI 
> >> BeagleBone/XDS100V2" rev 2.00/7.00 addr 4
> >> ucom0 at uftdi0 portno 2
> >> ugen0 at uhub8 port 1 configuration 1 "FTDI BeagleBone/XDS100V2" rev 
> >> 2.00/7.00 addr 4
> >>
> >> Like this, openocd (using ugen) and cu both work.
> >>
> >> It is just assumed that interface 0 is used for jtag, not sure if this is
> >> always true. I'm also unsure if the diff would break other devices.
> >> Can someone comment on this?
> >
> > Your diff looks correct and after looking at how the USB drivers are
> > matched it seems obvious to me that changing the configuration in this
> > function is not the right thing to do.
> >
> > I just rewrote your diff to keep only one (iface == NULL) check, I think
> > it is clearer like that. Are you ok with this version?
> 
> Yes, thanks.
> Could you take a quick look at the uftdi_attach function?
> I think some 'if (uaa->iface == NULL)' code could be removed there.

Right, here's an updated diff, is it still ok for you?

M.

Index: uftdi.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/usb/uftdi.c,v
retrieving revision 1.63
diff -u -p -r1.63 uftdi.c
--- uftdi.c     11 Sep 2012 16:04:44 -0000      1.63
+++ uftdi.c     31 Jan 2013 08:59:50 -0000
@@ -748,39 +748,29 @@ int
 uftdi_match(struct device *parent, void *match, void *aux)
 {
        struct usb_attach_arg *uaa = aux;
-       usbd_status err;
-       u_int8_t nifaces;
 
-       if (usb_lookup(uftdi_devs, uaa->vendor, uaa->product) == NULL)
+       /*
+        * Only match when looping against interfaces to allow ugen(4)
+        * to take over the interface 0, JTAG on USB, on some models.
+        */
+       if (uaa->iface == NULL)
                return (UMATCH_NONE);
 
-       /* Get the number of interfaces. */
-       if (uaa->iface != NULL) {
-               nifaces = uaa->nifaces;
-       } else {
-               err = usbd_set_config_index(uaa->device, UFTDI_CONFIG_INDEX, 1);
-               if (err)
-                       return (UMATCH_NONE);
-               err = usbd_interface_count(uaa->device, &nifaces);
-               if (err)
-                       return (UMATCH_NONE);
-               usbd_set_config_index(uaa->device, USB_UNCONFIG_INDEX, 1);
-       }
+       if (usb_lookup(uftdi_devs, uaa->vendor, uaa->product) == NULL)
+               return (UMATCH_NONE);
 
        /* JTAG on USB interface 0 */
        if (uaa->vendor == USB_VENDOR_FTDI &&
-           uaa->product == USB_PRODUCT_FTDI_OPENRD &&
+           (uaa->product == USB_PRODUCT_FTDI_OPENRD ||
+           uaa->product == USB_PRODUCT_FTDI_SERIAL_2232C) &&
            uaa->ifaceno == 0)
                return (UMATCH_NONE);
 
-       if (nifaces <= 1)
+       if (uaa->nifaces <= 1)
                return (UMATCH_VENDOR_PRODUCT);
 
        /* Dual UART chip */
-       if (uaa->iface != NULL)
-               return (UMATCH_VENDOR_IFACESUBCLASS);
-       else
-               return (UMATCH_NONE);
+       return (UMATCH_VENDOR_IFACESUBCLASS);
 }
 
 void
@@ -789,34 +779,15 @@ uftdi_attach(struct device *parent, stru
        struct uftdi_softc *sc = (struct uftdi_softc *)self;
        struct usb_attach_arg *uaa = aux;
        usbd_device_handle dev = uaa->device;
-       usbd_interface_handle iface;
+       usbd_interface_handle iface = uaa->iface;
        usb_interface_descriptor_t *id;
        usb_endpoint_descriptor_t *ed;
        char *devname = sc->sc_dev.dv_xname;
        int i;
-       usbd_status err;
        struct ucom_attach_args uca;
 
        DPRINTFN(10,("\nuftdi_attach: sc=%p\n", sc));
 
-       if (uaa->iface == NULL) {
-               /* Move the device into the configured state. */
-               err = usbd_set_config_index(dev, UFTDI_CONFIG_INDEX, 1);
-               if (err) {
-                       printf("%s: failed to set configuration, err=%s\n",
-                           sc->sc_dev.dv_xname, usbd_errstr(err));
-                       goto bad;
-               }
-
-               err = usbd_device2interface_handle(dev, UFTDI_IFACE_INDEX, 
&iface);
-               if (err) {
-                       printf("%s: failed to get interface, err=%s\n",
-                           sc->sc_dev.dv_xname, usbd_errstr(err));
-                       goto bad;
-               }
-       } else
-               iface = uaa->iface;
-
        id = usbd_get_interface_descriptor(iface);
 
        sc->sc_udev = dev;
@@ -871,10 +842,7 @@ uftdi_attach(struct device *parent, stru
                goto bad;
        }
 
-       if (uaa->iface == NULL)
-               uca.portno = FTDI_PIT_SIOA;
-       else
-               uca.portno = FTDI_PIT_SIOA + id->bInterfaceNumber;
+       uca.portno = FTDI_PIT_SIOA + id->bInterfaceNumber;
        /* bulkin, bulkout set above */
        uca.ibufsizepad = uca.ibufsize;
        uca.opkthdrlen = sc->sc_hdrlen;

Reply via email to