USB: xhci-plat: fix legacy PHY double init
Subsystems (3)
PATCH 1/1 USB: xhci-plat: fix legacy PHY double init
Commits 7b8ef22ea547 ("usb: xhci: plat: Add USB phy support") and 9134c1fd0503 ("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.
--- drivers/usb/host/xhci-plat.c | 50 +++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 20 deletions(-)
drivers/usb/host/xhci-plat.c +30 -20
@@ -13,6 +13,7 @@#include <linux/module.h> #include <linux/pci.h> #include <linux/of.h> +#include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/usb/phy.h> #include <linux/slab.h>
@@ -148,7 +149,7 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const sint ret;int irq;struct xhci_plat_priv *priv =NULL ; - +bool of_match;if (usb_disabled ())return -ENODEV ;
@@ -253,16 +254,23 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s &xhci->imod_interval); } - hcd->usb_phy =devm_usb_get_phy_by_phandle (sysdev,"usb-phy" ,0 ); -if (IS_ERR (hcd->usb_phy)) { - ret =PTR_ERR (hcd->usb_phy); -if (ret == -EPROBE_DEFER ) - goto disable_clk; - hcd->usb_phy =NULL ; - }else { - ret =usb_phy_init (hcd->usb_phy); -if (ret) - goto disable_clk; +/* +* Drivers such as dwc3 manages PHYs themself (and rely on driver name +* matching for the xhci platform device). +*/ + of_match =of_match_device (pdev->dev.driver->of_match_table, &pdev->dev); +if (of_match) { + hcd->usb_phy =devm_usb_get_phy_by_phandle (sysdev,"usb-phy" ,0 ); +if (IS_ERR (hcd->usb_phy)) { + ret =PTR_ERR (hcd->usb_phy); +if (ret == -EPROBE_DEFER ) + goto disable_clk; + hcd->usb_phy =NULL ; + }else { + ret =usb_phy_init (hcd->usb_phy); +if (ret) + goto disable_clk; + } } 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 goto dealloc_usb2_hcd; } - xhci->shared_hcd->usb_phy =devm_usb_get_phy_by_phandle (sysdev, -"usb-phy" ,1 ); -if (IS_ERR (xhci->shared_hcd->usb_phy)) { - xhci->shared_hcd->usb_phy =NULL ; - }else { - ret =usb_phy_init (xhci->shared_hcd->usb_phy); -if (ret) -dev_err (sysdev,"%s init usb3phy fail (ret=%d)\n" , - __func__, ret); +if (of_match) { + xhci->shared_hcd->usb_phy =devm_usb_get_phy_by_phandle (sysdev, +"usb-phy" ,1 ); +if (IS_ERR (xhci->shared_hcd->usb_phy)) { + xhci->shared_hcd->usb_phy =NULL ; + }else { + ret =usb_phy_init (xhci->shared_hcd->usb_phy); +if (ret) +dev_err (sysdev,"%s init usb3phy fail (ret=%d)\n" , + __func__, ret); + } } xhci->shared_hcd->tpl_support = hcd->tpl_support;
Signature · 1 line
2.41.0
Re: [PATCH] USB: xhci-plat: fix legacy PHY double inity
Quoted 18 lines · Johan Hovold
Commits
7b8ef22ea547("usb: xhci: plat: Add USB phy support") and9134c1fd0503("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_genericPHY 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.
Quoted 6 lines
Fixes 7b8ef22ea547 ("usb: xhci: plat: Add USB phy support")Fixes 9134c1fd0503 ("usb: xhci: plat: Add USB 3.0 phy support")Cc [email protected] # 4.1Cc Maxime Ripard <[email protected]>Cc Stanley Chang <[email protected]>Signed-off-by Johan Hovold <[email protected]>
Stanley Chang[昌育德]
Tested-byRE: [PATCH] USB: xhci-plat: fix legacy PHY double inity
Quoted 20 lines · Johan Hovold
Quoted 18 lines
Commits
7b8ef22ea547("usb: xhci: plat: Add USB phy support") and9134c1fd0503("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_genericPHY 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.
Quoted 8 lines
Quoted 6 lines
Fixes 7b8ef22ea547 ("usb: xhci: plat: Add USB phy support")Fixes 9134c1fd0503 ("usb: xhci: plat: Add USB 3.0 phy support")Cc [email protected] # 4.1Cc Maxime Ripard <[email protected]>Cc Stanley Chang <[email protected]>Signed-off-by Johan Hovold <[email protected]>Tested-by Stefan Eichenberger <[email protected]>
RE: [PATCH] USB: xhci-plat: fix legacy PHY double inity
In reply to Stefan EichenbergerHi Johan,
Quoted 26 lines
Quoted 26 lines · Johan Hovold
Quoted 24 lines
Commits
7b8ef22ea547("usb: xhci: plat: Add USB phy support") and9134c1fd0503("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_genericPHY 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 7b8ef22ea547 ("usb: xhci: plat: Add USB phy support")Fixes 9134c1fd0503 ("usb: xhci: plat: Add USB 3.0 phy support")Cc [email protected] # 4.1Cc Maxime Ripard <[email protected]>Cc Stanley Chang <[email protected]>Signed-off-by Johan Hovold <[email protected]>
Quoted 4 lines
Quoted 1 line
Tested-by Stefan Eichenberger <[email protected]>Tested-by Stanley Chang <[email protected]>
I am sorry to notify you this patch is tested fail.
I test the Realtek phy driver at drivers/phy/Realtek/phy-rtk-usb2.c again. But I can't get the phy in xhci.
It is a dwc3 generic phy driver, and it is also a usb phy driver.
Base on you modified, I can't run on callback rtk_phy->phy.notify_port_status = rtk_phy_notify_port_status; Thanks,
Stanley.
Re: [PATCH] USB: xhci-plat: fix legacy PHY double inity
Quoted 11 lines · Stanley Chang[昌育德]
Quoted 11 lines
Quoted 11 lines · Johan Hovold
Quoted 10 lines
Commits
7b8ef22ea547("usb: xhci: plat: Add USB phy support") and9134c1fd0503("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_genericPHY driver).
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
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.
Tested-by Stanley Chang <[email protected]>I am sorry to notify you this patch is tested fail.
Hmm. Thanks for testing.
Quoted 4 lines
I test the Realtek phy driver at
drivers/phy/Realtek/phy-rtk-usb2.cagain. But I can't get the phy in xhci.It is a dwc3 generic phy driver, and it is also a usb phy driver.
That sounds broken (i.e. to be relying on both frameworks), but indeed that seems to be the current state of the generic and legacy USB PHY implementations.
What a mess.
Quoted 2 lines
Base on you modified, I can't run on callback
rtk_phy->phy.notify_port_status=rtk_phy_notify_port_status;
Which dwc3 driver are you using? Unless I'm missing something this would not be an issue unless you are doing something crazy like describing the same PHY twice in the devicetree (i.e. both as a generic and legacy PHY).
Apparently, there are no in-tree users of this particular realtek PHY so I can't check the devicetree, but we do have other instances of such abuse since at least a decade:
6747caa76cab ("usb: phy: twl4030: use the new generic PHY framework")
And, yes, then this is sort of expected. The dwc3 driver has always managed its own PHYs, but functionality has now been bolted on top so that people may have started relying on it being managed *also* by xhci, well at least for notifications like the one you just added:
a08799cf17c2 ("usb: phy: add usb phy notify port status API")
Johan
RE: [PATCH] USB: xhci-plat: fix legacy PHY double inity
Hi Johan,
Quoted 33 lines · Stanley Chang[昌育德]
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines · Johan Hovold
Quoted 11 lines
Commits
7b8ef22ea547("usb: xhci: plat: Add USB phy support") and9134c1fd0503("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_genericPHY driver).Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
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.
Tested-by Stanley Chang <[email protected]>I am sorry to notify you this patch is tested fail.
Hmm. Thanks for testing.
Quoted 4 lines
I test the Realtek phy driver at
drivers/phy/Realtek/phy-rtk-usb2.cagain. But I can't get the phy in xhci.It is a dwc3 generic phy driver, and it is also a usb phy driver.
That sounds broken (i.e. to be relying on both frameworks), but indeed that seems to be the current state of the generic and legacy USB PHY implementations.
Quoted 8 lines
What a mess.
Quoted 2 lines
Base on you modified, I can't run on callback
rtk_phy->phy.notify_port_status=rtk_phy_notify_port_status;Which dwc3 driver are you using? Unless I'm missing something this would not be an issue unless you are doing something crazy like describing the same PHY twice in the devicetree (i.e. both as a generic and legacy PHY).
I use drivers/usb/dwc3/core.c and drivers/usb/dwc3/dwc3-rtk.c
I describe the PHY as generic and legacy PHY in device tree.
Our driver needs the API base on a08799cf17c2 ("usb: phy: add usb phy notify port status API"). But generic PHY driver is not support this.
Thanks,
Stanley
Quoted 15 lines
Apparently, there are no in-tree users of this particular realtek PHY so I can't check the devicetree, but we do have other instances of such abuse since at least a decade:
6747caa76cab ("usb: phy: twl4030: use the new generic PHYframework")
And, yes, then this is sort of expected. The dwc3 driver has always managed its own PHYs, but functionality has now been bolted on top so that people may have started relying on it being managed *also* by xhci, well at least for notifications like the one you just added:
a08799cf17c2("usb: phy: add usb phy notify port status API")Johan
Re: [PATCH] USB: xhci-plat: fix legacy PHY double inity
Quoted 16 lines · Stanley Chang[昌育德]
Quoted 16 lines · Stanley Chang[昌育德]
Quoted 5 lines
I test the Realtek phy driver at
drivers/phy/Realtek/phy-rtk-usb2.cagain. But I can't get the phy in xhci.It is a dwc3 generic phy driver, and it is also a usb phy driver.
That sounds broken (i.e. to be relying on both frameworks), but indeed that seems to be the current state of the generic and legacy USB PHY implementations.
What a mess.
Quoted 2 lines
Base on you modified, I can't run on callback
rtk_phy->phy.notify_port_status=rtk_phy_notify_port_status;
Quoted 6 lines
Quoted 3 lines
Which dwc3 driver are you using? Unless I'm missing something this would not be an issue unless you are doing something crazy like describing the same PHY twice in the devicetree (i.e. both as a generic and legacy PHY).
I use
drivers/usb/dwc3/core.canddrivers/usb/dwc3/dwc3-rtk.cI describe the PHY as generic and legacy PHY in device tree.
That's not right. You should just use the generic PHY binding for new platforms.
Quoted 2 lines
Our driver needs the API base on
a08799cf17c2("usb: phy: add usb phy notify port status API"). But generic PHY driver is not support this.
Yes, but you added that interface yourself, and that I think merging that was a mistake.
We should not be building functionality on top of the legacy USB PHY implementation which is stuck in some transitional limbo.
Apparently, your PHY drivers which were merged for 6.6 are the only users of this interface, and there are no upstream devicetrees that use these PHYs.
I think we should revert this mess before we dig ourselves into an even deeper hole.
Johan
RE: [PATCH] USB: xhci-plat: fix legacy PHY double inity
Hi Johan,
Quoted 36 lines · Stanley Chang[昌育德]
Quoted 1 line
Quoted 1 line
On Mon, Nov 06, 2023 at 06:53:23AM +0000, Stanley Chang[昌育德]
Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 4 lines
I test the Realtek phy driver at
drivers/phy/Realtek/phy-rtk-usb2.cagain. But I can't get the phy in xhci.It is a dwc3 generic phy driver, and it is also a usb phy driver.
That sounds broken (i.e. to be relying on both frameworks), but indeed that seems to be the current state of the generic and legacy USB PHY implementations.
Quoted 8 lines
Quoted 8 lines
What a mess.
Quoted 2 lines
Base on you modified, I can't run on callback
rtk_phy->phy.notify_port_status=rtk_phy_notify_port_status;Which dwc3 driver are you using? Unless I'm missing something this would not be an issue unless you are doing something crazy like describing the same PHY twice in the devicetree (i.e. both as a generic and
legacy PHY).
Quoted 3 lines
I use
drivers/usb/dwc3/core.canddrivers/usb/dwc3/dwc3-rtk.cI describe the PHY as generic and legacy PHY in device tree.That's not right. You should just use the generic PHY binding for new platforms.
Quoted 1 line
Our driver needs the API base on
a08799cf17c2("usb: phy: add usb phynotify port status API").
Quoted 1 line
But generic PHY driver is not support this.
Yes, but you added that interface yourself, and that I think merging that was a mistake.
Quoted 9 lines
We should not be building functionality on top of the legacy USB PHY implementation which is stuck in some transitional limbo.
Apparently, your PHY drivers which were merged for 6.6 are the only users of this interface, and there are no upstream devicetrees that use these PHYs.
I think we should revert this mess before we dig ourselves into an even deeper hole.
This is an interim method, as the current generic PHY framework does not support special operations on USB PHY. Now the generic PHY can't instead USB PHY in this stage.
For example,drivers/phy/ti/phy-twl4030-usb.cdrivers/phy/qualcomm/phy-qcom-ipq806x-usb.cdrivers/phy/ti/phy-omap-usb2.c
Thanks,
Stanley
Re: [PATCH] USB: xhci-plat: fix legacy PHY double inity
Quoted 15 lines · Stanley Chang[昌育德]
Quoted 15 lines
Quoted 2 lines
I use
drivers/usb/dwc3/core.canddrivers/usb/dwc3/dwc3-rtk.cI describe the PHY as generic and legacy PHY in device tree.That's not right. You should just use the generic PHY binding for new platforms.
Quoted 1 line
Our driver needs the API base on
a08799cf17c2("usb: phy: add usb phynotify port status API").
Quoted 1 line
But generic PHY driver is not support this.
Yes, but you added that interface yourself, and that I think merging that was a mistake.
We should not be building functionality on top of the legacy USB PHY implementation which is stuck in some transitional limbo.
Quoted 8 lines
Quoted 5 lines
Apparently, your PHY drivers which were merged for 6.6 are the only users of this interface, and there are no upstream devicetrees that use these PHYs.
I think we should revert this mess before we dig ourselves into an even deeper hole.
This is an interim method, as the current generic PHY framework does not support special operations on USB PHY.
Then you need to add that.
You can't add a new interface which is broken by design and can't be used unless you abuse the devicetree and describe your PHYs using *both* the generic 'phy' property and the *deprecated* 'usb-phy' property.
That's just broken.
Quoted 5 lines
Now the generic PHY can't instead USB PHY in this stage. For example,
drivers/phy/ti/phy-twl4030-usb.cdrivers/phy/qualcomm/phy-qcom-ipq806x-usb.cdrivers/phy/ti/phy-omap-usb2.c
These should be fixed as well eventually.
Johan
RE: [PATCH] USB: xhci-plat: fix legacy PHY double inity
Hi Johan,
Quoted 30 lines · Stanley Chang[昌育德]
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
I use
drivers/usb/dwc3/core.canddrivers/usb/dwc3/dwc3-rtk.cI describe the PHY as generic and legacy PHY in device tree.That's not right. You should just use the generic PHY binding for new
platforms.
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Our driver needs the API base on
a08799cf17c2("usb: phy: add usb phynotify port status API").
Quoted 1 line
But generic PHY driver is not support this.
Quoted 8 lines
Quoted 8 lines
Yes, but you added that interface yourself, and that I think merging that was a mistake.
We should not be building functionality on top of the legacy USB PHY implementation which is stuck in some transitional limbo.
Apparently, your PHY drivers which were merged for 6.6 are the only users of this interface, and there are no upstream devicetrees that use
these PHYs.
Quoted 6 lines
Quoted 3 lines
I think we should revert this mess before we dig ourselves into an even deeper hole.
This is an interim method, as the current generic PHY framework does not support special operations on USB PHY.
Quoted 7 lines
Then you need to add that.
You can't add a new interface which is broken by design and can't be used unless you abuse the devicetree and describe your PHYs using *both* the generic 'phy' property and the *deprecated* 'usb-phy' property.
That's just broken.
I will modify the Realtek phy to solve this problem and just use the generic PHY.
I don't think this patch on a08799cf17c2 ("usb:phy: New usb phy notification port status API") needs to be reverted. I will submit fixes based on these patches.
Thanks,
Stanley
Quoted 9 lines
Quoted 5 lines
Now the generic PHY can't instead USB PHY in this stage. For example,
drivers/phy/ti/phy-twl4030-usb.cdrivers/phy/qualcomm/phy-qcom-ipq806x-usb.cdrivers/phy/ti/phy-omap-usb2.cThese should be fixed as well eventually.
Johan