[PATCH 1/2] usb: dwc2: Make having a phy optional

Daniel Brát danek.brat at gmail.com
Wed Sep 8 00:46:21 PDT 2021


Despite using 'phy_optional_get' to get a 'usb2_phy' inside its probe,
the driver would fail if it didnt find it. Also, there is no Kconfig
dependency on 'CONFIG_GENERIC_PHY', so without it defined te phy
functions are unimplemented and always return -ENOSYS making dwc2 probe
always fail too. Since the 'dwc2->phy' is optional, the driver was
modified to reflect this.
Tested working on Raspberry Pi 3B+.

Signed-off-by: Daniel Brát <danek.brat at gmail.com>
---
 drivers/usb/dwc2/dwc2.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
index 9893977b8..8f3f8da00 100644
--- a/drivers/usb/dwc2/dwc2.c
+++ b/drivers/usb/dwc2/dwc2.c
@@ -72,20 +72,22 @@ static int dwc2_probe(struct device_d *dev)
 	if (ret)
 		goto clk_disable;
 
-	dwc2->phy = phy_optional_get(dev, "usb2-phy");
-	if (IS_ERR(dwc2->phy)) {
-		ret = PTR_ERR(dwc2->phy);
-		goto clk_disable;
+	if (IS_ENABLED(CONFIG_GENERIC_PHY)) {
+		dwc2->phy = phy_optional_get(dev, "usb2-phy");
+		if (!dwc2->phy || IS_ERR(dwc2->phy)) {
+			dev_warn(dev, "Didnt find any 'usb2-phy'\n");
+			dwc2->phy = NULL;
+		} else {
+			ret = phy_power_on(dwc2->phy);
+			if (ret)
+				goto clk_disable;
+
+			ret = phy_init(dwc2->phy);
+			if (ret)
+				goto phy_power_off;
+		}
 	}
 
-	ret = phy_power_on(dwc2->phy);
-	if (ret)
-		goto clk_disable;
-
-	ret = phy_init(dwc2->phy);
-	if (ret)
-		goto phy_power_off;
-
 	ret = dwc2_check_core_version(dwc2);
 	if (ret)
 		goto error;
@@ -120,9 +122,11 @@ static int dwc2_probe(struct device_d *dev)
 
 	return 0;
 error:
-	phy_exit(dwc2->phy);
+	if (dwc2->phy)
+		phy_exit(dwc2->phy);
 phy_power_off:
-	phy_power_off(dwc2->phy);
+	if (dwc2->phy)
+		phy_power_off(dwc2->phy);
 clk_disable:
 	clk_disable(dwc2->clk);
 clk_put:
@@ -140,8 +144,10 @@ static void dwc2_remove(struct device_d *dev)
 	dwc2_host_uninit(dwc2);
 	dwc2_gadget_uninit(dwc2);
 
-	phy_exit(dwc2->phy);
-	phy_power_off(dwc2->phy);
+	if (dwc2->phy) {
+		phy_exit(dwc2->phy);
+		phy_power_off(dwc2->phy);
+	}
 }
 
 static const struct of_device_id dwc2_platform_dt_ids[] = {
-- 
2.17.1




More information about the barebox mailing list