Skip to contentSkip to conversation

xhci-dwc3: Couple of fixes for USB3 support

PATCH New Vignesh R 3 participants 7 messages Mar 7, 2018 – Mar 17, 2018

Subsystems (2)
lore
Share & tools
lore

Vignesh R

author
#0 lore raw

v2 cover xhci-dwc3: Couple of fixes for USB3 support

This series has couple of fixes needed to get DWC3 USB3 controller to talk to USB3 devices on AM57xx SoCs.

v2:
* Refractor PHY operations into separate functions.

Vignesh R (3):
usb: xhci-dwc3: Power on USB PHY before using
usb: xhc-dwc3: Refractor PHY operations into separate function
ubs: xhci-dwc3: Enable USB3 PHY when available

 drivers/usb/host/xhci-dwc3.c | 80 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 62 insertions(+), 18 deletions(-)
Signature · 1 line
2.16.2
author
#1 lore raw

PATCH v2 1/3 usb: xhci-dwc3: Power on USB PHY before using

It is wrong that expect .phy_init() to also power on the PHY. Therefore, explicitly, call generic_phy_power_on() after generic_phy_power_init() in order to power on PHY before using it.

---
 drivers/usb/host/xhci-dwc3.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/usb/host/xhci-dwc3.c +12 -0
index 258d1cd00a08..cf1986bebd07 100644
@@ -137,6 +137,12 @@ static int xhci_dwc3_probe(struct udevice *dev)
 			pr_err("Can't init USB PHY for %s\n", dev->name);
 			return ret;
 		}
+
+		ret = generic_phy_power_on(&plat->usb_phy);
+		if (ret) {
+			pr_err("Can't power on USB PHY for %s\n", dev->name);
+			return ret;
+		}
 	}
 
 	dwc3_reg = (struct dwc3 *)((char *)(hccr) + DWC3_REG_OFFSET);
@@ -159,6 +165,12 @@ static int xhci_dwc3_remove(struct udevice *dev)
 	int ret;
 
 	if (generic_phy_valid(&plat->usb_phy)) {
+		ret = generic_phy_power_off(&plat->usb_phy);
+		if (ret) {
+			pr_err("Can't poweroff USB PHY for %s\n", dev->name);
+			return ret;
+		}
+
 		ret = generic_phy_exit(&plat->usb_phy);
 		if (ret) {
 			pr_err("Can't deinit USB PHY for %s\n", dev->name);
Signature · 1 line
2.16.2
Applied
#2 lore raw

PATCH v2 1/3 usb: xhci-dwc3: Power on USB PHY before using

Quoted 6 lines · Vignesh R

It is wrong that expect .phy_init() to also power on the PHY. Therefore, explicitly, call generic_phy_power_on() after generic_phy_power_init() in order to power on PHY before using it.

Applied all three, thanks

Quoted 35 lines
---
 drivers/usb/host/xhci-dwc3.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/usb/host/xhci-dwc3.c +12 -0
index 258d1cd00a08..cf1986bebd07 100644
@@ -137,6 +137,12 @@ static int xhci_dwc3_probe(struct udevice *dev)
 			pr_err("Can't init USB PHY for %s\n", dev->name);
 			return ret;
 		}
+
+		ret = generic_phy_power_on(&plat->usb_phy);
+		if (ret) {
+			pr_err("Can't power on USB PHY for %s\n", dev->name);
+			return ret;
+		}
 	}
 
 	dwc3_reg = (struct dwc3 *)((char *)(hccr) + DWC3_REG_OFFSET);
@@ -159,6 +165,12 @@ static int xhci_dwc3_remove(struct udevice *dev)
 	int ret;
 
 	if (generic_phy_valid(&plat->usb_phy)) {
+		ret = generic_phy_power_off(&plat->usb_phy);
+		if (ret) {
+			pr_err("Can't poweroff USB PHY for %s\n", dev->name);
+			return ret;
+		}
+
 		ret = generic_phy_exit(&plat->usb_phy);
 		if (ret) {
 			pr_err("Can't deinit USB PHY for %s\n", dev->name);
Signature · 2 lines
Best regards,
Marek Vasut
author
#3 lore raw

PATCH v2 2/3 usb: xhci-dwc3: Refractor PHY operations into separate function

In reply to Vignesh R

Refractor PHY get/init/poweron and PHY poweroff/exit operations into separate function so that its easy to support multiple PHYs.

---
 drivers/usb/host/xhci-dwc3.c | 75 ++++++++++++++++++++++++++++----------------
 1 file changed, 48 insertions(+), 27 deletions(-)
drivers/usb/host/xhci-dwc3.c +48 -27
index cf1986bebd07..e61a04eeb8a8 100644
@@ -112,39 +112,69 @@ void dwc3_set_fladj(struct dwc3 *dwc3_reg, u32 val)
 }
 
 #ifdef CONFIG_DM_USB
-static int xhci_dwc3_probe(struct udevice *dev)
+static int xhci_dwc3_setup_phy(struct udevice *dev, int index, struct phy *phy)
 {
-	struct xhci_dwc3_platdata *plat = dev_get_platdata(dev);
-	struct xhci_hcor *hcor;
-	struct xhci_hccr *hccr;
-	struct dwc3 *dwc3_reg;
-	enum usb_dr_mode dr_mode;
-	int ret;
-
-	hccr = (struct xhci_hccr *)((uintptr_t)dev_read_addr(dev));
-	hcor = (struct xhci_hcor *)((uintptr_t)hccr +
-			HC_LENGTH(xhci_readl(&(hccr)->cr_capbase)));
+	int ret = 0;
 
-	ret = generic_phy_get_by_index(dev, 0, &plat->usb_phy);
+	ret = generic_phy_get_by_index(dev, index, phy);
 	if (ret) {
 		if (ret != -ENOENT) {
 			pr_err("Failed to get USB PHY for %s\n", dev->name);
 			return ret;
 		}
 	} else {
-		ret = generic_phy_init(&plat->usb_phy);
+		ret = generic_phy_init(phy);
 		if (ret) {
 			pr_err("Can't init USB PHY for %s\n", dev->name);
 			return ret;
 		}
-
-		ret = generic_phy_power_on(&plat->usb_phy);
+		ret = generic_phy_power_on(phy);
 		if (ret) {
 			pr_err("Can't power on USB PHY for %s\n", dev->name);
+			generic_phy_exit(phy);
 			return ret;
 		}
 	}
 
+	return 0;
+}
+
+static int xhci_dwc3_shutdown_phy(struct phy *phy)
+{
+	int ret = 0;
+
+	if (generic_phy_valid(phy)) {
+		ret = generic_phy_power_off(phy);
+		if (ret)
+			return ret;
+
+		ret = generic_phy_exit(phy);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int xhci_dwc3_probe(struct udevice *dev)
+{
+	struct xhci_dwc3_platdata *plat = dev_get_platdata(dev);
+	struct xhci_hcor *hcor;
+	struct xhci_hccr *hccr;
+	struct dwc3 *dwc3_reg;
+	enum usb_dr_mode dr_mode;
+	int ret;
+
+	hccr = (struct xhci_hccr *)((uintptr_t)dev_read_addr(dev));
+	hcor = (struct xhci_hcor *)((uintptr_t)hccr +
+			HC_LENGTH(xhci_readl(&(hccr)->cr_capbase)));
+
+	ret = xhci_dwc3_setup_phy(dev, 0, &plat->usb_phy);
+	if (ret) {
+		pr_err("Failed to setup USB PHY for %s\n", dev->name);
+		return ret;
+	}
+
 	dwc3_reg = (struct dwc3 *)((char *)(hccr) + DWC3_REG_OFFSET);
 
 	dwc3_core_init(dwc3_reg);
@@ -164,19 +194,10 @@ static int xhci_dwc3_remove(struct udevice *dev)
 	struct xhci_dwc3_platdata *plat = dev_get_platdata(dev);
 	int ret;
 
-	if (generic_phy_valid(&plat->usb_phy)) {
-		ret = generic_phy_power_off(&plat->usb_phy);
-		if (ret) {
-			pr_err("Can't poweroff USB PHY for %s\n", dev->name);
-			return ret;
-		}
+	ret = xhci_dwc3_shutdown_phy(&plat->usb_phy);
+	if (ret)
+		pr_err("Can't shutdown USB PHY for %s\n", dev->name);
 
-		ret = generic_phy_exit(&plat->usb_phy);
-		if (ret) {
-			pr_err("Can't deinit USB PHY for %s\n", dev->name);
-			return ret;
-		}
-	}
 
 	return xhci_deregister(dev);
 }
Signature · 1 line
2.16.2
#4 lore raw

PATCH v2 2/3 usb: xhci-dwc3: Refractor PHY operations into separate function

Quoted 8 lines · Vignesh R

Refractor PHY get/init/poweron and PHY poweroff/exit operations into separate function so that its easy to support multiple PHYs.

---
 drivers/usb/host/xhci-dwc3.c | 75 ++++++++++++++++++++++++++++----------------
 1 file changed, 48 insertions(+), 27 deletions(-)
author
#5 lore raw

PATCH v2 3/3 ubs: xhci-dwc3: Enable USB3 PHY when available

In reply to Vignesh R

DWC3 USB3 controllers will need USB3 PHY to be enabled, in addition to USB2 PHY, to be functional. Therefore enable USB3 PHY when available.

---
 drivers/usb/host/xhci-dwc3.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/usb/host/xhci-dwc3.c +11 -0
index e61a04eeb8a8..1022dd551241 100644
@@ -23,6 +23,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 struct xhci_dwc3_platdata {
 	struct phy usb_phy;
+	struct phy usb3_phy;
 };
 
 void dwc3_set_mode(struct dwc3 *dwc3_reg, u32 mode)
@@ -175,6 +176,13 @@ static int xhci_dwc3_probe(struct udevice *dev)
 		return ret;
 	}
 
+	ret = xhci_dwc3_setup_phy(dev, 1, &plat->usb3_phy);
+	if (ret) {
+		pr_err("Failed to setup USB3 PHY for %s\n", dev->name);
+		xhci_dwc3_shutdown_phy(&plat->usb_phy);
+		return ret;
+	}
+
 	dwc3_reg = (struct dwc3 *)((char *)(hccr) + DWC3_REG_OFFSET);
 
 	dwc3_core_init(dwc3_reg);
@@ -198,6 +206,9 @@ static int xhci_dwc3_remove(struct udevice *dev)
 	if (ret)
 		pr_err("Can't shutdown USB PHY for %s\n", dev->name);
 
+	ret = xhci_dwc3_shutdown_phy(&plat->usb3_phy);
+	if (ret)
+		pr_err("Can't shutdown USB3 PHY for %s\n", dev->name);
 
 	return xhci_deregister(dev);
 }
Signature · 1 line
2.16.2
#6 lore raw

PATCH v2 3/3 ubs: xhci-dwc3: Enable USB3 PHY when available

Quoted 8 lines · Vignesh R

DWC3 USB3 controllers will need USB3 PHY to be enabled, in addition to USB2 PHY, to be functional. Therefore enable USB3 PHY when available.

---
 drivers/usb/host/xhci-dwc3.c | 11 +++++++++++
 1 file changed, 11 insertions(+)