[PATCH v5 3/3] usb: ohci-at91: Add USB PHY functionality

Eugen Hristev eugen.hristev at collabora.com
Tue Jul 25 17:43:17 CEST 2023


From: Sergiu Moga <sergiu.moga at microchip.com>

Add the ability to enable/disable whatever USB PHY's are
passed to the AT91 OHCI driver through DT.

Signed-off-by: Sergiu Moga <sergiu.moga at microchip.com>
[eugen.hristev at collabora.com: rewrite error paths according to Marek's review]
Signed-off-by: Eugen Hristev <eugen.hristev at collabora.com>
---

v1 -> v2:
- use *_bulk API's


v2 -> v3:
- use if (CONFIG_IS_ENABLED(...))

v3 -> v4
[eugen.hristev at collabora.com: disable PHYs in at91_start_clock if
clk_enable_bulk fails]

v4->v5:
[eugen.hristev at collabora.com: rewrite error paths according to Marek's review]

 drivers/usb/host/ohci-at91.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 92d0ab7184c4..4f4689745896 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -73,6 +73,7 @@ int usb_cpu_init_fail(void)
 #include <asm/gpio.h>
 #include <usb.h>
 #include "ohci.h"
+#include <generic-phy.h>
 
 #define AT91_MAX_USBH_PORTS        3
 
@@ -90,15 +91,36 @@ struct at91_usbh_data {
 struct ohci_at91_priv {
 	ohci_t ohci;
 	struct clk_bulk clks;
+	struct phy_bulk phys;
 };
 
 static int at91_start_clock(struct ohci_at91_priv *ohci_at91)
 {
-	return clk_enable_bulk(&ohci_at91->clks);
+	int ret;
+
+	if (CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)) {
+		ret = generic_phy_power_on_bulk(&ohci_at91->phys);
+		if (ret)
+			return ret;
+	}
+
+	ret = clk_enable_bulk(&ohci_at91->clks);
+	if (ret)
+		goto at91_start_clock_err;
+
+	return 0;
+
+at91_start_clock_err:
+	generic_phy_power_off_bulk(&ohci_at91->phys);
+
+	return ret;
 }
 
 static int at91_stop_clock(struct ohci_at91_priv *ohci_at91)
 {
+	if (CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB))
+		generic_phy_power_off_bulk(&ohci_at91->phys);
+
 	return clk_disable_bulk(&ohci_at91->clks);
 }
 
@@ -185,6 +207,16 @@ static int ohci_atmel_probe(struct udevice *dev)
 	if (ret)
 		goto fail;
 
+	if (CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)) {
+		ret = generic_phy_get_bulk(dev, &ohci_at91->phys);
+		if (ret)
+			goto fail;
+
+		ret = generic_phy_init_bulk(&ohci_at91->phys);
+		if (ret)
+			goto fail;
+	}
+
 	ret = at91_start_hc(dev);
 	if (ret)
 		goto fail;
-- 
2.34.1



More information about the U-Boot mailing list