Skip to content

Commit 16b7e0c

Browse files
jhovoldgregkh
authored andcommitted
USB: xhci-plat: fix legacy PHY double init
Commits 7b8ef22 ("usb: xhci: plat: Add USB phy support") and 9134c1f ("usb: xhci: plat: Add USB 3.0 phy support") added support for looking up legacy PHYs from the sysdev devicetree node and initialising them. This broke drivers such as dwc3 which manages PHYs themself as the PHYs would now be initialised twice, something which specifically can lead to resources being left enabled during suspend (e.g. with the usb_phy_generic PHY driver). As the dwc3 driver uses driver-name matching for the xhci platform device, fix this by only looking up and initialising PHYs for devices that have been matched using OF. Note that checking that the platform device has a devicetree node would currently be sufficient, but that could lead to subtle breakages in case anyone ever tries to reuse an ancestor's node. Fixes: 7b8ef22 ("usb: xhci: plat: Add USB phy support") Fixes: 9134c1f ("usb: xhci: plat: Add USB 3.0 phy support") Cc: [email protected] # 4.1 Cc: Maxime Ripard <[email protected]> Cc: Stanley Chang <[email protected]> Signed-off-by: Johan Hovold <[email protected]> Tested-by: Stefan Eichenberger <[email protected]> Tested-by: Stanley Chang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4b43576 commit 16b7e0c

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

drivers/usb/host/xhci-plat.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/module.h>
1414
#include <linux/pci.h>
1515
#include <linux/of.h>
16+
#include <linux/of_device.h>
1617
#include <linux/platform_device.h>
1718
#include <linux/usb/phy.h>
1819
#include <linux/slab.h>
@@ -148,7 +149,7 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s
148149
int ret;
149150
int irq;
150151
struct xhci_plat_priv *priv = NULL;
151-
152+
bool of_match;
152153

153154
if (usb_disabled())
154155
return -ENODEV;
@@ -253,16 +254,23 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s
253254
&xhci->imod_interval);
254255
}
255256

256-
hcd->usb_phy = devm_usb_get_phy_by_phandle(sysdev, "usb-phy", 0);
257-
if (IS_ERR(hcd->usb_phy)) {
258-
ret = PTR_ERR(hcd->usb_phy);
259-
if (ret == -EPROBE_DEFER)
260-
goto disable_clk;
261-
hcd->usb_phy = NULL;
262-
} else {
263-
ret = usb_phy_init(hcd->usb_phy);
264-
if (ret)
265-
goto disable_clk;
257+
/*
258+
* Drivers such as dwc3 manages PHYs themself (and rely on driver name
259+
* matching for the xhci platform device).
260+
*/
261+
of_match = of_match_device(pdev->dev.driver->of_match_table, &pdev->dev);
262+
if (of_match) {
263+
hcd->usb_phy = devm_usb_get_phy_by_phandle(sysdev, "usb-phy", 0);
264+
if (IS_ERR(hcd->usb_phy)) {
265+
ret = PTR_ERR(hcd->usb_phy);
266+
if (ret == -EPROBE_DEFER)
267+
goto disable_clk;
268+
hcd->usb_phy = NULL;
269+
} else {
270+
ret = usb_phy_init(hcd->usb_phy);
271+
if (ret)
272+
goto disable_clk;
273+
}
266274
}
267275

268276
hcd->tpl_support = of_usb_host_tpl_support(sysdev->of_node);
@@ -285,15 +293,17 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s
285293
goto dealloc_usb2_hcd;
286294
}
287295

288-
xhci->shared_hcd->usb_phy = devm_usb_get_phy_by_phandle(sysdev,
289-
"usb-phy", 1);
290-
if (IS_ERR(xhci->shared_hcd->usb_phy)) {
291-
xhci->shared_hcd->usb_phy = NULL;
292-
} else {
293-
ret = usb_phy_init(xhci->shared_hcd->usb_phy);
294-
if (ret)
295-
dev_err(sysdev, "%s init usb3phy fail (ret=%d)\n",
296-
__func__, ret);
296+
if (of_match) {
297+
xhci->shared_hcd->usb_phy = devm_usb_get_phy_by_phandle(sysdev,
298+
"usb-phy", 1);
299+
if (IS_ERR(xhci->shared_hcd->usb_phy)) {
300+
xhci->shared_hcd->usb_phy = NULL;
301+
} else {
302+
ret = usb_phy_init(xhci->shared_hcd->usb_phy);
303+
if (ret)
304+
dev_err(sysdev, "%s init usb3phy fail (ret=%d)\n",
305+
__func__, ret);
306+
}
297307
}
298308

299309
xhci->shared_hcd->tpl_support = hcd->tpl_support;

0 commit comments

Comments
 (0)