On Mon, Feb 18, 2019 at 03:31:45AM -0500, James Hastings wrote:
> On 17/02/19(Sun) 15:07, Martin Pieuchot wrote:
> > On 15/02/19(Fri) 01:47, James Hastings wrote:
> > > I settled on a patch providing an additional 250ms powerdelay in
> uhub(4).
> > > mue(4) reliably attaches now, but hotplugging devices in the left two
> > > ports is still an issue.
> >
> > Interesting.  Could you build a kernel with UHUB_DEBUG enable and
> > compare the status of the ports?  I'm wondering if your increased delay
> > will change the value returned by usbd_get_port_status() line 376.
> 
> Before:
> uhub2: port 1 status=0x0100 change=0x0000
> 
> With delay:
> uhub2: port 1 status=0x0101 change=0x0001
> uhub2: port 1 status=0x0503 change=0x0000
> mue0 at uhub2 port 1 configuration 1 interface 0 "Standard Microsystems
> LAN7800" rev 2.10/3.00 addr 4
> mue0: LAN7800, address
> ukphy0 at mue0 phy 1: Generic IEEE 802.3u media interface, rev. 2: OUI
> 0x0001f0, model 0x0013
> 
> > Why did you decide to increase the delay?   Did you find some doc or
> > code saying this is necessary?
> 
> No code or docs, just thought the device might be slow to wake up
> and need extra delay to be attached on initial bus exploration.
> 

so it seems, and i came up with a diff to limit the workaround a bit :]

this is what i currently use, while just
        s/USB_EXTRA_POWER_UP_TIME/USB_PORT_POWERUP_DELAY/
would also work, and still 'look ok' given the comment above delay, but..

-Artturi

ps. we use bPwrOn2PwrGood = 200 in ie. ehci, and = 10 in xhci, but netbsd
uses = 200 in both, fwiw.


diff --git a/sys/dev/usb/uhub.c b/sys/dev/usb/uhub.c
index 272569798c9..072bc2c5312 100644
--- a/sys/dev/usb/uhub.c
+++ b/sys/dev/usb/uhub.c
@@ -126,6 +126,7 @@ uhub_attach(struct device *parent, struct device *self, 
void *aux)
                usb_hub_ss_descriptor_t ss;
        } hd;
        int p, port, nports, powerdelay;
+       int minpwrdly = USB_EXTRA_POWER_UP_TIME;
        struct usbd_interface *iface = uaa->iface;
        usb_endpoint_descriptor_t *ed;
        struct usbd_tt *tts = NULL;
@@ -169,6 +170,8 @@ uhub_attach(struct device *parent, struct device *self, 
void *aux)
                err = usbd_get_hub_descriptor(dev, &hd.hs, 1);
                nports = hd.hs.bNbrPorts;
                powerdelay = (hd.hs.bPwrOn2PwrGood * UHD_PWRON_FACTOR);
+               if (hd.hs.bPwrOn2PwrGood <= 50) /* workaround for RPI3B+ */
+                       minpwrdly += 200 * UHD_PWRON_FACTOR - powerdelay;
                ttthink = UGETW(hd.hs.wHubCharacteristics) & UHD_TT_THINK;
                if (!err && nports > 7)
                        usbd_get_hub_descriptor(dev, &hd.hs, nports);
@@ -324,8 +327,8 @@ uhub_attach(struct device *parent, struct device *self, 
void *aux)
        }
 
        /* Wait for stable power. */
-        if (dev->powersrc->parent != NULL)
-               usbd_delay_ms(dev, powerdelay + USB_EXTRA_POWER_UP_TIME);
+       if (dev->powersrc->parent != NULL)
+               usbd_delay_ms(dev, powerdelay + minpwrdly);
 
        /* The usual exploration will finish the setup. */
 

Reply via email to