[PATCH v2] fixup! usb: dwc2: Add support for optional usb phy

Jules Maselbas jmaselbas at kalray.eu
Mon Dec 14 06:03:57 EST 2020


In this fixup I've changed to call order for phy initialisation:
phy_init and then phy_power_on. Same for the deinitiailisation:
phy_power_off then phy_exit. Which seems to be the correct way.

Also fix the exit path.

Signed-off-by: Jules Maselbas <jmaselbas at kalray.eu>
---
 drivers/usb/dwc2/dwc2.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
index 5e95e8b22..98f9b30b6 100644
--- a/drivers/usb/dwc2/dwc2.c
+++ b/drivers/usb/dwc2/dwc2.c
@@ -56,13 +56,12 @@ static int dwc2_probe(struct device_d *dev)
 		return ret;
 	}
 
-	if (dwc2->phy) {
-		ret = phy_power_on(dwc2->phy);
-		if (ret == 0)
-			ret = phy_init(dwc2->phy);
-		if (ret)
-			goto error;
-	}
+	ret = phy_init(dwc2->phy);
+	if (ret)
+		goto err_phy_init;
+	ret = phy_power_on(dwc2->phy);
+	if (ret)
+		goto err_phy_power;
 
 	ret = dwc2_check_core_version(dwc2);
 	if (ret)
@@ -93,9 +92,15 @@ static int dwc2_probe(struct device_d *dev)
 	else
 		ret = dwc2_set_mode(dwc2, dwc2->dr_mode);
 
+	if (ret)
+		goto error;
+
+	return 0;
 error:
-	if (dwc2->phy)
-		phy_power_off(dwc2->phy);
+	phy_power_off(dwc2->phy);
+err_phy_power:
+	phy_exit(dwc2->phy);
+err_phy_init:
 
 	return ret;
 }
@@ -103,16 +108,12 @@ error:
 static void dwc2_remove(struct device_d *dev)
 {
 	struct dwc2 *dwc2 = dev->priv;
-	int ret;
 
 	dwc2_host_uninit(dwc2);
 	dwc2_gadget_uninit(dwc2);
 
-	if (dwc2->phy) {
-		ret = phy_exit(dwc2->phy);
-		if (ret == 0)
-			phy_power_off(dwc2->phy);
-	}
+	phy_power_off(dwc2->phy);
+	phy_exit(dwc2->phy);
 }
 
 static const struct of_device_id dwc2_platform_dt_ids[] = {
-- 
2.17.1





More information about the barebox mailing list