Skip to contentSkip to conversation

rockchip: rk3568: Use dwc3-generic driver

PATCH Superseded Jonas Karlman 3 participants 10 messages Jul 16, 2023 – Jul 26, 2023

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 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 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-v3

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/radxa-cm3-io-rk3566_defconfig        |  2 +-
 configs/rock-3a-rk3568_defconfig             |  2 +-
 drivers/usb/dwc3/dwc3-generic.c              | 50 +++++++++++---------
 5 files changed, 30 insertions(+), 36 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH v3 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.

---
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 f91740c1c0c8..57b77151c57c 100644
@@ -77,7 +77,3 @@
 	bootph-all;
 	status = "okay";
 };
-
-&vcc5v0_usb30 {
-	regulator-boot-on;
-};
arch/arm/dts/rk3568-rock-3a-u-boot.dtsi +0 -8
index bbf54f888fa0..ecbbdeee32f8 100644
@@ -110,11 +110,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 v3 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.

---
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
Reviewed-by on v3 2/5
#3 lore raw

Re: [PATCH v3 2/5] usb: dwc3-generic: Return early when there is no child node

Quoted 11 lines · 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.

Thanks,
- Kever

Quoted 26 lines

---
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);
#4 lore raw

PATCH v3 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.

---
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
#5 lore raw

Re: [PATCH v3 3/5] usb: dwc3-generic: Relax unsupported dr_mode check

Hi Marek,

   Could you help to look at this patch, is there any further comment for the change?

Thanks,

- Kever

Quoted 85 lines · 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.

---
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);
#6 lore raw

Re: [PATCH v3 3/5] usb: dwc3-generic: Relax unsupported dr_mode check

Quoted 1 line · Kever Yang

Hi Marek,

Hi,

Quoted 2 lines

   Could you help to look at this patch, is there any further comment
for the change?

It is in the pipeline, yes.

#7 lore raw

PATCH v3 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.

---
v3:
- No change
v2:
- No change
- Collect r-b tag

 drivers/usb/dwc3/dwc3-generic.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/usb/dwc3/dwc3-generic.c +17 -0
index 2331ac453132..f6d087722c9f 100644
@@ -405,6 +405,22 @@ 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)
+{
+	if (!device_is_compatible(dev, "snps,dwc3"))
+		return -EINVAL;
+
+	*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 +612,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
#8 lore raw

PATCH v3 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.

---
v3:
- No change
v2:
- No change

 configs/radxa-cm3-io-rk3566_defconfig | 2 +-
 configs/rock-3a-rk3568_defconfig      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
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 753d03914d90..ddb43249654e 100644
@@ -85,10 +85,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
Reviewed-by on v3 5/5
#9 lore raw
Quoted 4 lines · Jonas Karlman

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

Thanks,
- Kever

Quoted 40 lines

---
v3:
- No change
v2:
- No change

  configs/radxa-cm3-io-rk3566_defconfig | 2 +-
  configs/rock-3a-rk3568_defconfig      | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
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 753d03914d90..ddb43249654e 100644
@@ -85,10 +85,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