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

Eugen Hristev eugen.hristev at collabora.com
Thu Jun 22 15:07:01 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>
Tested-by: Mihai Sain <mihai.sain at microchip.com>
Reviewed-by: Marek Vasut <marex at denx.de>
[eugen.hristev at collabora.com: disable PHYs in at91_start_clock if
clk_enable_bulk fails]
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]

 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..3d4f31d240aa 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)
+		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)) {
+		int ret;
+
+		ret = generic_phy_power_off_bulk(&ohci_at91->phys);
+		if (ret)
+			return ret;
+	}
+
 	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