Skip to contentSkip to conversation

rockchip: rk3568: Use dwc3-generic driver

PATCH Superseded Jonas Karlman 3 participants 17 messages May 30, 2023 – Jul 13, 2023

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

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.

This series is also available at [1]

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

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              | 27 ++++++++++++++++----
 5 files changed, 24 insertions(+), 19 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH 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 commit c57e0dcd9384 "phy: add support for phy-supply".

This reverts commit 7911f409ff20dce5995cc1b703a6e30c94022f6b.

---
 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.40.1
#2 lore raw

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

In reply to Jonas Karlman

The call to device_find_first_child always return 0, change to return early when there is no child node.

---
 drivers/usb/dwc3/dwc3-generic.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +3 -3
index 66da5a8d6f8c..c28ad47bddd8 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.40.1
#3 lore raw

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

Quoted 3 lines · Jonas Karlman

The call to device_find_first_child always return 0, change to return early when there is no child node.

Can you explain a little more about this? Maybe adding device-tree pipeline will give a better understanding of the issue.

Jagan.

#4 lore raw

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

Hi Jagan,

Quoted 7 lines · Jagan Teki
Quoted 3 lines · Jonas Karlman

The call to device_find_first_child always return 0, change to return early when there is no child node.

Can you explain a little more about this? Maybe adding device-tree pipeline will give a better understanding of the issue.

The docs for device_find_first_child mention:

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

And the function does exactly this, always return 0.
So, the current check for return value of this call is unnecessary.

The following possible call to dwc3_glue_clk_init or dwc3_glue_reset_init may trigger a null pointer dereference further down the call chain.

Looking closer this patch may have been more related to my rk3328 testing, where usb@ff600000 in rk3328.dtsi is missing child nodes and resets prop.

For RK3568 this patch should not be needed, however it still fixes a possible null pointer dereference issue.

Regards,
Jonas

Quoted 2 lines

Jagan.

#5 lore raw

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

In reply to Jonas Karlman
Quoted 15 lines · Jonas Karlman

The call to device_find_first_child always return 0, change to return early when there is no child node.

---
  drivers/usb/dwc3/dwc3-generic.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +0 -0
index 66da5a8d6f8c..c28ad47bddd8 100644
@@ -558,9 +558,9 @@ int dwc3_glue_probe(struct udevice *dev)
  			return ret;
  	}

drivers/usb/dwc3/dwc3-generic.c int dwc3_glue_probe(struct udevice *dev) · line 566

Quoted 10 lines
drivers/usb/dwc3/dwc3-generic.c +3 -3
 
-	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);

If this is a fix, then please send this separately, so I can pick it for current release.

#6 lore raw

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

Hi Marek,

Sorry for a late reply.

Quoted 24 lines · Marek Vasut
Quoted 23 lines · Jonas Karlman

The call to device_find_first_child always return 0, change to return early when there is no child node.

---
  drivers/usb/dwc3/dwc3-generic.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +3 -3
index 66da5a8d6f8c..c28ad47bddd8 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;
 
Quoted 5 lines

drivers/usb/dwc3/dwc3-generic.c int dwc3_glue_probe(struct udevice *dev) · line 566

Quoted 2 lines
drivers/usb/dwc3/dwc3-generic.c +0 -0
  	if (glue->clks.count == 0) {
  		ret = dwc3_glue_clk_init(child, glue);

If this is a fix, then please send this separately, so I can pick it for current release.

Current boards using this driver is not affected by this. To my knowledge only RK3328 may have been affected by this, DT does not have any resets.

Adding support for RK3328 in this driver is part of the series "rockchip:
Fix RK3328 USB support" by Jagan, a series that depend on patches in this series.

Should I still re-send this patch as a separate patch?

Regards,
Jonas

#7 lore raw

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

Quoted 35 lines · Jonas Karlman

Hi Marek,

Sorry for a late reply.

Quoted 24 lines · Marek Vasut
Quoted 23 lines · Jonas Karlman

The call to device_find_first_child always return 0, change to return early when there is no child node.

---
   drivers/usb/dwc3/dwc3-generic.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +3 -3
index 66da5a8d6f8c..c28ad47bddd8 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;
 
Quoted 5 lines

drivers/usb/dwc3/dwc3-generic.c int dwc3_glue_probe(struct udevice *dev) · line 566

Quoted 2 lines
drivers/usb/dwc3/dwc3-generic.c +0 -0
   	if (glue->clks.count == 0) {
   		ret = dwc3_glue_clk_init(child, glue);

If this is a fix, then please send this separately, so I can pick it for current release.

Quoted 8 lines

Current boards using this driver is not affected by this. To my knowledge only RK3328 may have been affected by this, DT does not have any resets.

Adding support for RK3328 in this driver is part of the series "rockchip:
Fix RK3328 USB support" by Jagan, a series that depend on patches in this series.

Should I still re-send this patch as a separate patch?

Release is already out, so, no need.

#8 lore raw

PATCH 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

---
 drivers/usb/dwc3/dwc3-generic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +2 -2
index c28ad47bddd8..f7859a530280 100644
@@ -422,13 +422,13 @@ static int dwc3_glue_bind_common(struct udevice *parent, ofnode node)
 		dr_mode = usb_get_dr_mode(node);
 
 	switch (dr_mode) {
+#if CONFIG_IS_ENABLED(DM_USB_GADGET)
 	case USB_DR_MODE_PERIPHERAL:
 	case USB_DR_MODE_OTG:
-#if CONFIG_IS_ENABLED(DM_USB_GADGET)
 		debug("%s: dr_mode: OTG or Peripheral\n", __func__);
 		driver = "dwc3-generic-peripheral";
-#endif
 		break;
+#endif
 #if defined(CONFIG_SPL_USB_HOST) || !defined(CONFIG_SPL_BUILD)
 	case USB_DR_MODE_HOST:
 		debug("%s: dr_mode: HOST\n", __func__);
Signature · 1 line
2.40.1
#9 lore raw

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

Quoted 24 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

---
  drivers/usb/dwc3/dwc3-generic.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +0 -0
index c28ad47bddd8..f7859a530280 100644

drivers/usb/dwc3/dwc3-generic.c static int dwc3_glue_bind_common(struct udevice *parent, ofnode node) · line 427

Quoted 7 lines
drivers/usb/dwc3/dwc3-generic.c +1 -1
@@ -422,13 +422,13 @@ static int dwc3_glue_bind_common(struct udevice *parent, ofnode node)
  		dr_mode = usb_get_dr_mode(node);
 
  	switch (dr_mode) {
+#if CONFIG_IS_ENABLED(DM_USB_GADGET)
  	case USB_DR_MODE_PERIPHERAL:
  	case USB_DR_MODE_OTG:
-#if CONFIG_IS_ENABLED(DM_USB_GADGET)

Why not just do

#else
return -ENODEV
#endif

here ?

Quoted 5 lines
drivers/usb/dwc3/dwc3-generic.c +1 -1
  		debug("%s: dr_mode: OTG or Peripheral\n", __func__);
  		driver = "dwc3-generic-peripheral";
-#endif
  		break;
+#endif
#10 lore raw

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

Hi Marek,

Sorry for late reply.

Quoted 35 lines · Marek Vasut
Quoted 24 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

---
  drivers/usb/dwc3/dwc3-generic.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +0 -0
index c28ad47bddd8..f7859a530280 100644

drivers/usb/dwc3/dwc3-generic.c static int dwc3_glue_bind_common(struct udevice *parent, ofnode node) · line 427

Quoted 7 lines
drivers/usb/dwc3/dwc3-generic.c +1 -1
@@ -422,13 +422,13 @@ static int dwc3_glue_bind_common(struct udevice *parent, ofnode node)
  		dr_mode = usb_get_dr_mode(node);
 
  	switch (dr_mode) {
+#if CONFIG_IS_ENABLED(DM_USB_GADGET)
  	case USB_DR_MODE_PERIPHERAL:
  	case USB_DR_MODE_OTG:
-#if CONFIG_IS_ENABLED(DM_USB_GADGET)

Why not just do

Quoted 5 lines

#else
return -ENODEV
#endif

here ?

The code was changed to closer match how host mode is already handled, and the default switch case already return -ENODEV.

Regards,
Jonas

Quoted 8 lines
Quoted 6 lines
drivers/usb/dwc3/dwc3-generic.c +1 -1
  		debug("%s: dr_mode: OTG or Peripheral\n", __func__);
  		driver = "dwc3-generic-peripheral";
-#endif
  		break;
+#endif
#11 lore raw

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

Quoted 39 lines · Jonas Karlman

Hi Marek,

Sorry for late reply.

Quoted 35 lines · Marek Vasut
Quoted 24 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

---
   drivers/usb/dwc3/dwc3-generic.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +0 -0
index c28ad47bddd8..f7859a530280 100644

drivers/usb/dwc3/dwc3-generic.c static int dwc3_glue_bind_common(struct udevice *parent, ofnode node) · line 427

Quoted 7 lines
drivers/usb/dwc3/dwc3-generic.c +1 -1
@@ -422,13 +422,13 @@ static int dwc3_glue_bind_common(struct udevice *parent, ofnode node)
   		dr_mode = usb_get_dr_mode(node);
 
   	switch (dr_mode) {
+#if CONFIG_IS_ENABLED(DM_USB_GADGET)
   	case USB_DR_MODE_PERIPHERAL:
   	case USB_DR_MODE_OTG:
-#if CONFIG_IS_ENABLED(DM_USB_GADGET)

Why not just do

Quoted 8 lines
Quoted 5 lines

#else
return -ENODEV
#endif

here ?

The code was changed to closer match how host mode is already handled, and the default switch case already return -ENODEV.

Let's try the above and see if that makes the code more readable.

Also, you might want to try

if (!CONFIG_IS_ENABLED(DM_USB_GADGET))

	return -ENODEV;

To improve build coverage.

#12 lore raw

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

Quoted 49 lines · Marek Vasut
Quoted 39 lines · Jonas Karlman

Hi Marek,

Sorry for late reply.

Quoted 35 lines · Marek Vasut
Quoted 24 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

---
   drivers/usb/dwc3/dwc3-generic.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +0 -0
index c28ad47bddd8..f7859a530280 100644

drivers/usb/dwc3/dwc3-generic.c static int dwc3_glue_bind_common(struct udevice *parent, ofnode node) · line 427

Quoted 7 lines
drivers/usb/dwc3/dwc3-generic.c +1 -1
@@ -422,13 +422,13 @@ static int dwc3_glue_bind_common(struct udevice *parent, ofnode node)
   		dr_mode = usb_get_dr_mode(node);
 
   	switch (dr_mode) {
+#if CONFIG_IS_ENABLED(DM_USB_GADGET)
   	case USB_DR_MODE_PERIPHERAL:
   	case USB_DR_MODE_OTG:
-#if CONFIG_IS_ENABLED(DM_USB_GADGET)

Why not just do

Quoted 8 lines
Quoted 5 lines

#else
return -ENODEV
#endif

here ?

The code was changed to closer match how host mode is already handled, and the default switch case already return -ENODEV.

Quoted 8 lines

Let's try the above and see if that makes the code more readable.

Also, you might want to try

if (!CONFIG_IS_ENABLED(DM_USB_GADGET))

	return -ENODEV;

To improve build coverage.

In my opinion this (after this patch as-is) is more readable and has the benefit of the debug message when DM_USB_GADGET is disabled.

	switch (dr_mode) {
#if CONFIG_IS_ENABLED(DM_USB_GADGET)
	case USB_DR_MODE_PERIPHERAL:
	case USB_DR_MODE_OTG:
		debug("%s: dr_mode: OTG or Peripheral\n", __func__);
		driver = "dwc3-generic-peripheral";
		break;
#endif
#if defined(CONFIG_SPL_USB_HOST) || !defined(CONFIG_SPL_BUILD)
	case 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__);
		return -ENODEV;
	};

Compared to the following:

	switch (dr_mode) {
	case USB_DR_MODE_PERIPHERAL:
	case USB_DR_MODE_OTG:
		if (!CONFIG_IS_ENABLED(DM_USB_GADGET))
			return -ENODEV;

		debug("%s: dr_mode: OTG or Peripheral\n", __func__);
		driver = "dwc3-generic-peripheral";
		break;
#if defined(CONFIG_SPL_USB_HOST) || !defined(CONFIG_SPL_BUILD)
	case 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__);
		return -ENODEV;
	};

Any suggestion on how this could otherwise be refactored?

The original intent with the patch is to fix a non-booting config to a booting config with minimal code changes :-)

Regards,
Jonas

#13 lore raw

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

Quoted 83 lines · Jonas Karlman
Quoted 49 lines · Marek Vasut
Quoted 39 lines · Jonas Karlman

Hi Marek,

Sorry for late reply.

Quoted 35 lines · Marek Vasut
Quoted 24 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

---
    drivers/usb/dwc3/dwc3-generic.c | 4 ++--
    1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +0 -0
index c28ad47bddd8..f7859a530280 100644

drivers/usb/dwc3/dwc3-generic.c static int dwc3_glue_bind_common(struct udevice *parent, ofnode node) · line 427

Quoted 7 lines
drivers/usb/dwc3/dwc3-generic.c +1 -1
@@ -422,13 +422,13 @@ static int dwc3_glue_bind_common(struct udevice *parent, ofnode node)
    		dr_mode = usb_get_dr_mode(node);
 
    	switch (dr_mode) {
+#if CONFIG_IS_ENABLED(DM_USB_GADGET)
    	case USB_DR_MODE_PERIPHERAL:
    	case USB_DR_MODE_OTG:
-#if CONFIG_IS_ENABLED(DM_USB_GADGET)

Why not just do

Quoted 8 lines
Quoted 5 lines

#else
return -ENODEV
#endif

here ?

The code was changed to closer match how host mode is already handled, and the default switch case already return -ENODEV.

Quoted 8 lines

Let's try the above and see if that makes the code more readable.

Also, you might want to try

if (!CONFIG_IS_ENABLED(DM_USB_GADGET))

	return -ENODEV;

To improve build coverage.

In my opinion this (after this patch as-is) is more readable and has the benefit of the debug message when DM_USB_GADGET is disabled.

	switch (dr_mode) {
#if CONFIG_IS_ENABLED(DM_USB_GADGET)
	case USB_DR_MODE_PERIPHERAL:
	case USB_DR_MODE_OTG:
		debug("%s: dr_mode: OTG or Peripheral\n", __func__);
		driver = "dwc3-generic-peripheral";
		break;
#endif
#if defined(CONFIG_SPL_USB_HOST) || !defined(CONFIG_SPL_BUILD)
	case 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__);
		return -ENODEV;
	};
Quoted 8 lines

Compared to the following:

	switch (dr_mode) {
	case USB_DR_MODE_PERIPHERAL:
	case USB_DR_MODE_OTG:
		if (!CONFIG_IS_ENABLED(DM_USB_GADGET))
			return -ENODEV;

Maybe drop the switch-case and try:

if (CONFIG_IS_ENABLED(DM_USB_GADGET) &&

    (dr_mode == USB_DR_MODE_PERIPHERAL || dr_mode == USB_DR_MODE_OTG))

{

Quoted 4 lines
		debug("%s: dr_mode: OTG or Peripheral\n", __func__);
		driver = "dwc3-generic-peripheral";
		break;

#if defined(CONFIG_SPL_USB_HOST) || !defined(CONFIG_SPL_BUILD)

else if ((CONFIG_IS_ENABLED(USB_HOST) || !IS_ENABLED(SPL_BUILD)) && dr_mode == host) {

Quoted 5 lines
	case USB_DR_MODE_HOST:
		debug("%s: dr_mode: HOST\n", __func__);
		driver = "dwc3-generic-host";
		break;

#endif

} else {

Quoted 4 lines
	default:
		debug("%s: unsupported dr_mode\n", __func__);
		return -ENODEV;
	};

}

Quoted 5 lines

Any suggestion on how this could otherwise be refactored?

The original intent with the patch is to fix a non-booting config to a booting config with minimal code changes :-)

It's awful either way, but at least with the CONFIG_IS_ENABLED() stuff, we avoid bitrot of ifdef'd out code, since all the code is compiled in any case.

#14 lore raw

PATCH 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 the glue node as the ctrl node.

---
 drivers/usb/dwc3/dwc3-generic.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/usb/dwc3/dwc3-generic.c +17 -0
index f7859a530280..0d30657da319 100644
@@ -406,6 +406,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);
@@ -607,6 +623,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.40.1
#16 lore raw

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

---
 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 56802d85cc25..e1b3602d24db 100644
@@ -74,8 +74,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 616499f2f82b..ea72a8c9f6b3 100644
@@ -84,10 +84,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.40.1