[PATCH v2 1/8] usb: cdns3: Set USB PHY mode in cdns3_core_init_role()

Minda Chen minda.chen at starfivetech.com
Thu Jul 4 07:50:07 CEST 2024


USB PHY maybe need to set PHY mode in different USB
dr mode. So translate to generic PHY mode and call
generic_phy_set_mode().

Signed-off-by: Minda Chen <minda.chen at starfivetech.com>
---
 drivers/usb/cdns3/core.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index 12a741c6ea..1e863bed89 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -107,6 +107,7 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
 {
 	struct udevice *dev = cdns->dev;
 	enum usb_dr_mode best_dr_mode;
+	int mode = PHY_MODE_INVALID;
 	enum usb_dr_mode dr_mode;
 	int ret = 0;
 
@@ -173,6 +174,30 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
 
 	cdns->dr_mode = dr_mode;
 
+	if (cdns->dr_mode == USB_DR_MODE_HOST) {
+		mode = PHY_MODE_USB_HOST;
+	} else if (cdns->dr_mode == USB_DR_MODE_PERIPHERAL) {
+		mode = PHY_MODE_USB_DEVICE;
+	} else if (cdns->dr_mode == USB_DR_MODE_OTG) {
+		mode = PHY_MODE_USB_OTG;
+	} else {
+		dev_err(dev, "Unknown dr mode %d\n", cdns->dr_mode);
+		ret = -EINVAL;
+		goto err;
+	}
+
+	ret = generic_phy_set_mode(&cdns->usb2_phy, mode, 0);
+	if (ret) {
+		dev_err(dev, "Set usb 2.0 PHY mode failed %d\n", ret);
+		goto err;
+	}
+
+	ret = generic_phy_set_mode(&cdns->usb3_phy, mode, 0);
+	if (ret) {
+		dev_err(dev, "Set usb 3.0 PHY mode failed %d\n", ret);
+		goto err;
+	}
+
 	ret = cdns3_drd_update_mode(cdns);
 	if (ret)
 		goto err;
-- 
2.17.1



More information about the U-Boot mailing list