Skip to contentSkip to conversation

Revert "usb: dwc3: pci: Use devm functions to get the phy GPIOs"

DISCUSSION Stephan Gerhold 1 participant 1 message Dec 9, 2018 USB

lore
Share & tools
lore
#0 lore raw
Quoted 48 lines · Andy Shevchenko
Quoted 47 lines · Stephan Gerhold

Commit 211f658b7b40 ("usb: dwc3: pci: Use devm functions to get the phy GPIOs") changed the code to claim the PHY GPIOs permanently for Intel Baytrail devices.

This causes issues when the actual PHY driver attempts to claim the same GPIO descriptors. For example, tusb1210 now fails to probe with:

tusb1210: probe of dwc3.0.auto.ulpi failed with error -16 (EBUSY)

dwc3-pci needs to turn on the PHY once before dwc3 is loaded, but usually the PHY driver will then hold the GPIOs to turn off the PHY when requested (e.g. during suspend).

To fix the problem, this reverts the commit to restore the old behavior to put the GPIOs immediately after usage.

---
 drivers/usb/dwc3/dwc3-pci.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/dwc3/dwc3-pci.c +3 -4
index 842795856bf4..fdc6e4e403e8 100644
@@ -170,20 +170,20 @@ static int dwc3_pci_quirks(struct dwc3_pci *dwc)
                         * put the gpio descriptors again here because the phy driver
                         * might want to grab them, too.
                         */
-                       gpio = devm_gpiod_get_optional(&pdev->dev, "cs",
-                                                      GPIOD_OUT_LOW);
+                       gpio = gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW);
                        if (IS_ERR(gpio))
                                return PTR_ERR(gpio);
 
                        gpiod_set_value_cansleep(gpio, 1);
+                       gpiod_put(gpio);
 
-                       gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
-                                                      GPIOD_OUT_LOW);
+                       gpio = gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW);
                        if (IS_ERR(gpio))
                                return PTR_ERR(gpio);
 
Quoted 8 lines

drivers/usb/dwc3/dwc3-pci.c static int dwc3_pci_quirks(struct dwc3_pci *dwc) · line 188

Quoted 5 lines
drivers/usb/dwc3/dwc3-pci.c +1 -0
                        if (gpio) {
                                gpiod_set_value_cansleep(gpio, 1);
 
+                               gpiod_put(gpio);
                                usleep_range(10000, 11000);

If something happens to GPIO line in between of these lines, the sleep might become obsolete. Shouldn't gpiod_put() be placed after?

That's a good point, but I believe this would be more appropriately fixed in a separate patch, since this is just an exact revert of 211f658b7b40 ("usb: dwc3: pci: Use devm functions to get the phy GPIOs") (This is the way it was written when it was added to mainline 4 years ago...)

I can send a separate patch for this, or would you like to?

Quoted 8 lines
Quoted 3 lines
drivers/usb/dwc3/dwc3-pci.c +0 -0
                        }
                }
Signature · 2 lines
With Best Regards,
Andy Shevchenko