Skip to contentSkip to conversation

rockchip: rk3568: Use dwc3-generic driver

PATCH In review Jonas Karlman 2 participants 7 messages Jul 30, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v5 cover rockchip: rk3568: Use dwc3-generic driver

This series add support for rk3568 in dwc3-generic driver and change to use the dwc3-generic driver for rk3568 devices having usb enabled.

After these changes it should be possible to support usb gadget on rk3568 with e.g.:

# CONFIG_USB_FUNCTION_FASTBOOT is not set
CONFIG_DM_USB_GADGET=y
CONFIG_USB_GADGET=y

Patch 1 reverts addition of now unnecessary regulator-boot-on props. Patch 2 improve support for childless glue/ctrl dt node. Patch 3 relax a hard error when usb gadget support is not enabled. Patch 4 add support for the glue/ctrl dt node used by rk3568. Patch 5 change rk3568 devices to use dwc3-generic driver.

Changes in v5:
- Drop device_is_compatible check
- Collect r-b tag

Changes in v4:
- Rebase on u-boot-rockchip/master and v2 of the series "rockchip: rk3568: Device Tree updates"
- Add fixes tag
- Update nanopi-r5c-rk3568 and nanopi-r5s-rk3568
- Collect r-b tag

Changes in v3:
- Update debug message to include dr_mode (Marek Vasut)
- Collect r-b tag

Changes in v2:
- Change to use CONFIG_IS_ENABLED for USB_HOST
- Refactor switch to if statements (Marek Vasut)
- Update commit message
- Collect r-b tag

This series is also available at [1]

[1] https://github.com/Kwiboo/u-boot-rockchip/commits/rk3568-dwc3-generic-v5

Jonas Karlman (5):
Revert "arm: dts: rockchip: radxa-cm3-io, rock-3a: enable regulators
for usb"
usb: dwc3-generic: Return early when there is no child node
usb: dwc3-generic: Relax unsupported dr_mode check
usb: dwc3-generic: Add rk3568 support
rockchip: rk3568: Use dwc3-generic driver

 arch/arm/dts/rk3566-radxa-cm3-io-u-boot.dtsi |  4 --
 arch/arm/dts/rk3568-rock-3a-u-boot.dtsi      |  8 ----
 configs/nanopi-r5c-rk3568_defconfig          |  3 +-
 configs/nanopi-r5s-rk3568_defconfig          |  3 +-
 configs/radxa-cm3-io-rk3566_defconfig        |  2 +-
 configs/rock-3a-rk3568_defconfig             |  2 +-
 drivers/usb/dwc3/dwc3-generic.c              | 47 +++++++++++---------
 7 files changed, 29 insertions(+), 40 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH v5 1/5 Revert "arm: dts: rockchip: radxa-cm3-io, rock-3a: enable regulators for usb"

Remove regulator-boot-on prop from regulators now that the phy core has support for phy-supply after the commit c57e0dcd9384 ("phy: add support for phy-supply").

This reverts commit 7911f409ff20dce5995cc1b703a6e30c94022f6b.

---
v5:
- No change
v4:
- Rebase on u-boot-rockchip/master and v2 of the series "rockchip: rk3568: Device Tree updates"
v3:
- No change
v2:
- No change

 arch/arm/dts/rk3566-radxa-cm3-io-u-boot.dtsi | 4 ----
 arch/arm/dts/rk3568-rock-3a-u-boot.dtsi      | 8 --------
 2 files changed, 12 deletions(-)
arch/arm/dts/rk3566-radxa-cm3-io-u-boot.dtsi +0 -4
index a8c31fecafd8..c925439f71cd 100644
@@ -21,7 +21,3 @@
 	bootph-all;
 	status = "okay";
 };
-
-&vcc5v0_usb30 {
-	regulator-boot-on;
-};
arch/arm/dts/rk3568-rock-3a-u-boot.dtsi +0 -8
index 68d5935348bb..a36a329f59c5 100644
@@ -66,11 +66,3 @@
 	bootph-all;
 	status = "okay";
 };
-
-&vcc5v0_usb_host {
-	regulator-boot-on;
-};
-
-&vcc5v0_usb_hub {
-	regulator-boot-on;
-};
Signature · 1 line
2.41.0
#2 lore raw

PATCH v5 2/5 usb: dwc3-generic: Return early when there is no child node

In reply to Jonas Karlman

The current error check for device_find_first_child is not working as expected, the documentation for device_find_first_child mention:

@devp: Returns first child device, or NULL if none
Return: 0

Change to return early when there is no child node to avoid any possible null pointer dereference.

---
v5:
- No change
v4:
- Collect r-b tag
v3:
- Collect r-b tag
v2:
- Update commit message

 drivers/usb/dwc3/dwc3-generic.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +3 -3
index 35e4b36a695e..4d5d500aefab 100644
@@ -558,9 +558,9 @@ int dwc3_glue_probe(struct udevice *dev)
 			return ret;
 	}
 
-	ret = device_find_first_child(dev, &child);
-	if (ret)
-		return ret;
+	device_find_first_child(dev, &child);
+	if (!child)
+		return 0;
 
 	if (glue->clks.count == 0) {
 		ret = dwc3_glue_clk_init(child, glue);
Signature · 1 line
2.41.0
#3 lore raw

PATCH v5 3/5 usb: dwc3-generic: Relax unsupported dr_mode check

In reply to Jonas Karlman

When dr_mode is peripheral or otg and U-Boot has not been built with DM_USB_GADGET support, booting such device may end up with:

dwc3_glue_bind_common: subnode name: usb@fcc00000
Error binding driver 'dwc3-generic-wrapper': -6
Some drivers failed to bind
initcall sequence 00000000effbca08 failed at call 0000000000a217c8 (err=-6) ### ERROR ### Please RESET the board ###

Instead fail gracfully with ENODEV to allow board continue booting.

dwc3_glue_bind_common: subnode name: usb@fcc00000
dwc3_glue_bind_common: unsupported dr_mode 3

Also use CONFIG_IS_ENABLED(USB_HOST) and change switch to if statements to improve readability of the code.

Fixes 446e3a205b87 ("dwc3-generic: Handle the PHYs, the clocks and the reset lines")

---
v5:
- Collect r-b tag
v4:
- Add fixes tag
v3:
- Update debug message to include dr_mode (Marek Vasut) v2:
- Change to use CONFIG_IS_ENABLED for USB_HOST
- Refactor switch to if statements (Marek Vasut)

 drivers/usb/dwc3/dwc3-generic.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +8 -19
index 4d5d500aefab..2331ac453132 100644
@@ -226,8 +226,7 @@ U_BOOT_DRIVER(dwc3_generic_peripheral) = {
 };
 #endif
 
-#if defined(CONFIG_SPL_USB_HOST) || \
-	!defined(CONFIG_SPL_BUILD) && defined(CONFIG_USB_HOST)
+#if CONFIG_IS_ENABLED(USB_HOST)
 static int dwc3_generic_host_probe(struct udevice *dev)
 {
 	struct xhci_hcor *hcor;
@@ -409,7 +408,7 @@ struct dwc3_glue_ops ti_ops = {
 static int dwc3_glue_bind_common(struct udevice *parent, ofnode node)
 {
 	const char *name = ofnode_get_name(node);
-	const char *driver = NULL;
+	const char *driver;
 	enum usb_dr_mode dr_mode;
 	struct udevice *dev;
 	int ret;
@@ -421,27 +420,17 @@ static int dwc3_glue_bind_common(struct udevice *parent, ofnode node)
 	if (!dr_mode)
 		dr_mode = usb_get_dr_mode(node);
 
-	switch (dr_mode) {
-	case USB_DR_MODE_PERIPHERAL:
-	case USB_DR_MODE_OTG:
-#if CONFIG_IS_ENABLED(DM_USB_GADGET)
+	if (CONFIG_IS_ENABLED(DM_USB_GADGET) &&
+	    (dr_mode == USB_DR_MODE_PERIPHERAL || dr_mode == USB_DR_MODE_OTG)) {
 		debug("%s: dr_mode: OTG or Peripheral\n", __func__);
 		driver = "dwc3-generic-peripheral";
-#endif
-		break;
-#if defined(CONFIG_SPL_USB_HOST) || !defined(CONFIG_SPL_BUILD)
-	case USB_DR_MODE_HOST:
+	} else if (CONFIG_IS_ENABLED(USB_HOST) && dr_mode == USB_DR_MODE_HOST) {
 		debug("%s: dr_mode: HOST\n", __func__);
 		driver = "dwc3-generic-host";
-		break;
-#endif
-	default:
-		debug("%s: unsupported dr_mode\n", __func__);
+	} else {
+		debug("%s: unsupported dr_mode %d\n", __func__, dr_mode);
 		return -ENODEV;
-	};
-
-	if (!driver)
-		return -ENXIO;
+	}
 
 	ret = device_bind_driver_to_node(parent, driver, name,
 					 node, &dev);
Signature · 1 line
2.41.0
#4 lore raw

PATCH v5 4/5 usb: dwc3-generic: Add rk3568 support

In reply to Jonas Karlman

RK3568 share glue and ctrl in a single node. Use glue_get_ctrl_dev to return the glue node as the ctrl node.

---
v5:
- Drop device_is_compatible check
v4:
- No change
v3:
- No change
v2:
- No change
- Collect r-b tag

 drivers/usb/dwc3/dwc3-generic.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/usb/dwc3/dwc3-generic.c +14 -0
index 2331ac453132..79203f820415 100644
@@ -405,6 +405,19 @@ struct dwc3_glue_ops ti_ops = {
 	.glue_configure = dwc3_ti_glue_configure,
 };
 
+static int dwc3_rk_glue_get_ctrl_dev(struct udevice *dev, ofnode *node)
+{
+	*node = dev_ofnode(dev);
+	if (!ofnode_valid(*node))
+		return -EINVAL;
+
+	return 0;
+}
+
+struct dwc3_glue_ops rk_ops = {
+	.glue_get_ctrl_dev = dwc3_rk_glue_get_ctrl_dev,
+};
+
 static int dwc3_glue_bind_common(struct udevice *parent, ofnode node)
 {
 	const char *name = ofnode_get_name(node);
@@ -596,6 +609,7 @@ static const struct udevice_id dwc3_glue_ids[] = {
 	{ .compatible = "ti,am654-dwc3" },
 	{ .compatible = "rockchip,rk3328-dwc3" },
 	{ .compatible = "rockchip,rk3399-dwc3" },
+	{ .compatible = "rockchip,rk3568-dwc3", .data = (ulong)&rk_ops },
 	{ .compatible = "qcom,dwc3" },
 	{ .compatible = "fsl,imx8mp-dwc3", .data = (ulong)&imx8mp_ops },
 	{ .compatible = "fsl,imx8mq-dwc3" },
Signature · 1 line
2.41.0
#6 lore raw

PATCH v5 5/5 rockchip: rk3568: Use dwc3-generic driver

In reply to Jonas Karlman

Change RK3568 devices to use the newer dwc3-generic driver instead of the old xhci-dwc3 driver for USB 3.0 support.

---
v5:
- No change
v4:
- Rebase on u-boot-rockchip/master and include change to nanopi-r5c-rk3568 and nanopi-r5s-rk3568
- Collect r-b tag
v3:
- No change
v2:
- No change

 configs/nanopi-r5c-rk3568_defconfig   | 3 +--
 configs/nanopi-r5s-rk3568_defconfig   | 3 +--
 configs/radxa-cm3-io-rk3566_defconfig | 2 +-
 configs/rock-3a-rk3568_defconfig      | 2 +-
 4 files changed, 4 insertions(+), 6 deletions(-)
configs/nanopi-r5c-rk3568_defconfig +1 -2
index b913ad4494c2..201b21ad77e3 100644
@@ -13,7 +13,6 @@ CONFIG_ROCKCHIP_RK3568=y
 CONFIG_SPL_ROCKCHIP_COMMON_BOARD=y
 CONFIG_SPL_SERIAL=y
 CONFIG_SPL_STACK_R_ADDR=0x600000
-CONFIG_TARGET_EVB_RK3568=y
 CONFIG_SPL_STACK=0x400000
 CONFIG_DEBUG_UART_BASE=0xFE660000
 CONFIG_DEBUG_UART_CLOCK=24000000
@@ -76,10 +75,10 @@ CONFIG_SYSRESET=y
 CONFIG_SYSRESET_PSCI=y
 CONFIG_USB=y
 CONFIG_USB_XHCI_HCD=y
-CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_GENERIC=y
 CONFIG_USB_OHCI_HCD=y
 CONFIG_USB_OHCI_GENERIC=y
 CONFIG_USB_DWC3=y
+CONFIG_USB_DWC3_GENERIC=y
 CONFIG_ERRNO_STR=y
configs/nanopi-r5s-rk3568_defconfig +1 -2
index 0a298c65a76b..67b28430709e 100644
@@ -13,7 +13,6 @@ CONFIG_ROCKCHIP_RK3568=y
 CONFIG_SPL_ROCKCHIP_COMMON_BOARD=y
 CONFIG_SPL_SERIAL=y
 CONFIG_SPL_STACK_R_ADDR=0x600000
-CONFIG_TARGET_EVB_RK3568=y
 CONFIG_SPL_STACK=0x400000
 CONFIG_DEBUG_UART_BASE=0xFE660000
 CONFIG_DEBUG_UART_CLOCK=24000000
@@ -76,10 +75,10 @@ CONFIG_SYSRESET=y
 CONFIG_SYSRESET_PSCI=y
 CONFIG_USB=y
 CONFIG_USB_XHCI_HCD=y
-CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_GENERIC=y
 CONFIG_USB_OHCI_HCD=y
 CONFIG_USB_OHCI_GENERIC=y
 CONFIG_USB_DWC3=y
+CONFIG_USB_DWC3_GENERIC=y
 CONFIG_ERRNO_STR=y
configs/radxa-cm3-io-rk3566_defconfig +1 -1
index 488723dfaa30..f89777184ceb 100644
@@ -75,8 +75,8 @@ CONFIG_SYS_NS16550_MEM32=y
 CONFIG_SYSRESET=y
 CONFIG_USB=y
 CONFIG_USB_XHCI_HCD=y
-CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_GENERIC=y
 CONFIG_USB_DWC3=y
+CONFIG_USB_DWC3_GENERIC=y
 CONFIG_ERRNO_STR=y
configs/rock-3a-rk3568_defconfig +1 -1
index 42fd47eb57be..44ff054df665 100644
@@ -97,10 +97,10 @@ CONFIG_ROCKCHIP_SFC=y
 CONFIG_SYSRESET=y
 CONFIG_USB=y
 CONFIG_USB_XHCI_HCD=y
-CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_GENERIC=y
 CONFIG_USB_OHCI_HCD=y
 CONFIG_USB_OHCI_GENERIC=y
 CONFIG_USB_DWC3=y
+CONFIG_USB_DWC3_GENERIC=y
 CONFIG_ERRNO_STR=y
Signature · 1 line
2.41.0