Skip to contentSkip to conversation

Add StarFive JHB100 host field USB device controller driver

PATCH Superseded Minda Chen 4 participants 11 messages Sep 18 – Oct 13

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Minda Chen

author maintainer
#0 lore raw

cover Add StarFive JHB100 host field USB device controller driver

JHB100 is a Starfive new RISC-V SoC for datacenter BMC (BaseBoard Managent Controller). Similar with Aspeed 27x0.

The JHB100 basic driver upstream is in progress:
https://patchwork.kernel.org/project/linux-riscv/cover/[email protected]/

JHB100 BMC soc contains Synopsys dwc3 multi-port host controller. And export its xhci controller to host server through PCIe. xhci contains 8 ports and each connect with one dwc3 device controller through an PHY adapter. Server host USB subsystem includes one multi-port dwc3 USB host, multiple dwc3 device controllers and their adapters.

The simple arch graph is below.

|-----------------------------------------
|Server PCIe field                       |
|(usb xhci working in server but it      |
| located in BMC soc)			 |
|   --------------------------------     |
|   |    multi-port xhci controller|     |
|   |       .....      port7 port8 |     |
|   --------------------^-----^-----     |
------------------------|-----|-----------
------------------------|-----|-----------
|        .....    --------- ---------    |
|                 |adapter| |adapter|    |
|                 -----^--- -----^---    |
|                      |         |       |
|               ------------ ------------|
|    ......     | device   | |device    ||
|               |controller| |controller||
|               ------------ ------------|
|   BMC field				 |

------------------------------------------

The patch base on kernel v7.3-rc1

Minda Chen (3):
dt-bindings: usb: dwc3: Add JHB100 device controller PHY adapter
dt-bindings: usb: dwc3: Add JHB100 USB device clock number limit
usb: dwc3-generic: Add Starfive JHB100 USB 2.0 device controller and
adapter

 .../bindings/usb/starfive,jhb100-dwc3.yaml    | 13 ++++-
 drivers/usb/dwc3/dwc3-generic-plat.c          | 47 ++++++++++++++++++-
 2 files changed, 58 insertions(+), 2 deletions(-)

base-commit: 89a312991dc6e638a36adc43ccb91dbc25504c04

Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH 1/3 dt-bindings: usb: dwc3: Add JHB100 device controller PHY adapter

Add dt-binding of JHB100 server host field USB device controller PHY adapter register IO region and its regs-name.

---
 .../devicetree/bindings/usb/starfive,jhb100-dwc3.yaml | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml +10 -1
index fbabe99e9d5c..b2fd98c06ba0 100644
@@ -20,7 +20,16 @@ properties:
     const: starfive,jhb100-dwc3
 
   reg:
-    maxItems: 1
+    minItems: 1
+    items:
+      - description: Core DWC3 region
+      - description: DWC3 device controller adapter region
+
+  reg-names:
+    minItems: 1
+    items:
+      - const: core
+      - const: adapter
 
   interrupts:
     maxItems: 1
Signature · 1 line
2.17.1
author maintainer
#6 lore raw

PATCH 2/3 dt-bindings: usb: dwc3: Add JHB100 USB device clock number limit

In reply to Minda Chen

StarFive JHB100 server host virtual device controller do not connect with PHY but connect with digital adapter module. So it do not contain core reference clock. So the minimal clock number is 2 (glue layer main enable clock and dwc3 core bus clk). So Add minItem 2 to clock and clock-names items.

---
 Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml +2 -0
index b2fd98c06ba0..3d0c248dee71 100644
@@ -35,12 +35,14 @@ properties:
     maxItems: 1
 
   clocks:
+    minItems: 2
     items:
       - description: USB main enable clk
       - description: DWC3 bus early clock
       - description: DWC3 ref clock
 
   clock-names:
+    minItems: 2
     items:
       - const: main
       - const: bus_early
Signature · 1 line
2.17.1
author maintainer
#7 lore raw

PATCH 3/3 usb: dwc3-generic: Add Starfive JHB100 USB 2.0 device controller and adapter

In reply to Minda Chen

Add PHY or PHY adapter iomem field in struct dwc3_gerneric for dwc3 generic platform to add PHY/PHY adapter setting.

Also Add Starfive JHB100 USB 2.0 device controller generic init function to remap PHY adapter io memory region and add adapter pre-run/stop function.

JHB100 BMC soc contains Synopsys dwc3 multi-port host controller. And export its xhci controller to host server through PCIe. xhci contains 8 ports and each connect with one dwc3 device controller through an PHY adapter. Server host USB subsystem includes one multi-port dwc3 USB host, multiple dwc3 device controllers and their adapters.

While USB adapter 2.0 enable bit is set, the connect status bit of xhci port stat register will be asserted. If the usb enumeration is not ready for USB gadget, The xhci will fail with enumerate usb device. So The JHB100 USB device controller adapter require to set/clear USB 2.0 port enable while usb gadget start/stop usb device enumeration. This can be treated as a hardware quirk.

---
 drivers/usb/dwc3/dwc3-generic-plat.c | 47 +++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-generic-plat.c +46 -1
index ca69ac0eb07c..e3394205a519 100644
@@ -22,12 +22,15 @@
 #define EIC7700_HSP_AXI_LP_XM_CSYSREQ	BIT(0)
 #define EIC7700_HSP_AXI_LP_XS_CSYSREQ	BIT(16)
 
+#define JHB100_ADAPTER_PORT_EN		BIT(20)
+
 struct dwc3_generic {
 	struct device		*dev;
 	struct dwc3		dwc;
 	struct clk_bulk_data	*clks;
 	int			num_clocks;
 	struct reset_control	*resets;
+	void __iomem		*phy_regs; /* PHY or PHY adapter regs */
 };
 
 struct dwc3_generic_config {
@@ -42,6 +45,43 @@ static void dwc3_generic_reset_control_assert(void *data)
 	reset_control_assert(data);
 }
 
+static void dwc3_jhb100_pre_run_stop(struct dwc3 *dwc3, bool start)
+{
+	struct dwc3_generic *data = to_dwc3_generic(dwc3);
+	u32	val;
+
+	if (start) {
+		val = readl(data->phy_regs);
+		val |= JHB100_ADAPTER_PORT_EN;
+		writel(val, data->phy_regs);
+	} else {
+		val = readl(data->phy_regs);
+		val &= ~JHB100_ADAPTER_PORT_EN;
+		writel(val, data->phy_regs);
+	}
+}
+
+struct dwc3_glue_ops jhb100_glue_ops = {
+	.pre_run_stop = dwc3_jhb100_pre_run_stop,
+};
+
+static int dwc3_jhb100_init(struct dwc3_generic *dwc3g)
+{
+	struct platform_device *pdev = to_platform_device(dwc3g->dev);
+
+	dwc3g->phy_regs = devm_platform_ioremap_resource_byname(pdev, "adapter");
+	if (IS_ERR(dwc3g->phy_regs)) {
+		dwc3g->phy_regs = NULL;
+		/* Generic bmc USB with PHY*/
+		return 0;
+	}
+
+	/* usb device controller with adapter */
+	dwc3g->dwc.glue_ops = &jhb100_glue_ops;
+
+	return 0;
+}
+
 static int dwc3_eic7700_init(struct dwc3_generic *dwc3g)
 {
 	struct device *dev = dwc3g->dev;
@@ -231,12 +271,17 @@ static const struct dwc3_generic_config eic7700_dwc3 =  {
 	.properties = DWC3_DEFAULT_PROPERTIES,
 };
 
+static const struct dwc3_generic_config jhb100_dwc3 =  {
+	.init = dwc3_jhb100_init,
+	.properties = DWC3_DEFAULT_PROPERTIES,
+};
+
 static const struct of_device_id dwc3_generic_of_match[] = {
 	{ .compatible = "spacemit,k1-dwc3", &spacemit_k1_dwc3},
 	{ .compatible = "spacemit,k3-dwc3", },
 	{ .compatible = "fsl,ls1028a-dwc3", &fsl_ls1028_dwc3},
 	{ .compatible = "eswin,eic7700-dwc3", &eic7700_dwc3},
-	{ .compatible = "starfive,jhb100-dwc3", },
+	{ .compatible = "starfive,jhb100-dwc3", &jhb100_dwc3},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, dwc3_generic_of_match);
Signature · 1 line
2.17.1
#8 lore raw

Re: [PATCH v1 3/3] usb: dwc3-generic: Add Starfive JHB100 USB 2.0 device controller and adapter

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] usb: improper handling of optional adapter resource masks legitimate errors - [Low] usb: missing…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] usb: improper handling of optional adapter resource masks legitimate errors
- [Low] usb: missing static keyword on jhb100_glue_ops causes namespace pollution --

commit e26d59375d5e4555d239557e241788e437655348
Author: Minda Chen <[email protected]>

usb: dwc3-generic: Add Starfive JHB100 USB 2.0 device controller and adapter

This patch introduces the Starfive JHB100 USB 2.0 device controller and its associated PHY adapter settings to the generic DWC3 driver. It adds io memory mappings for the adapter and implements pre-run/stop operations to appropriately toggle the adapter port enable bit during gadget enumeration.

drivers/usb/dwc3/dwc3-generic-plat.c +0 -0
index ca69ac0eb07ce..e3394205a5197 100644

[ ... ]

Quoted 7 lines
(quoted diff) +7 -0
+static void dwc3_jhb100_pre_run_stop(struct dwc3 *dwc3, bool start)
+{
+	struct dwc3_generic *data = to_dwc3_generic(dwc3);
+	u32	val;
+
+	if (start) {
+		val = readl(data->phy_regs);

Review

Quoted 10 lines
(quoted diff) +10 -0
+		val |= JHB100_ADAPTER_PORT_EN;
+		writel(val, data->phy_regs);
+	} else {
+		val = readl(data->phy_regs);
+		val &= ~JHB100_ADAPTER_PORT_EN;
+		writel(val, data->phy_regs);
+	}
+}
+
+struct dwc3_glue_ops jhb100_glue_ops = {

[Severity: Low]
Could this struct be marked static and const?

Since jhb100_glue_ops is only assigned to dwc3g->dwc.glue_ops locally within drivers/usb/dwc3/dwc3-generic-plat.c, leaving it globally exposed might lead to link-time symbol collisions or sparse warnings.

Review

Quoted 9 lines
(quoted diff) +9 -0
+	.pre_run_stop = dwc3_jhb100_pre_run_stop,
+};
+
+static int dwc3_jhb100_init(struct dwc3_generic *dwc3g)
+{
+	struct platform_device *pdev = to_platform_device(dwc3g->dev);
+
+	dwc3g->phy_regs = devm_platform_ioremap_resource_byname(pdev, "adapter");
+	if (IS_ERR(dwc3g->phy_regs)) {

[Severity: Medium]
Will this error handling mask legitimate failures?

The adapter resource appears to be optional here since dwc3_jhb100_init() falls back to generic behavior when it is missing. However, using devm_platform_ioremap_resource_byname() on an absent resource will unconditionally log an invalid resource error via dev_err_probe(), potentially spamming the kernel log on platforms where it is intentionally omitted.

Additionally, checking IS_ERR() here will catch all other errors like -ENOMEM or -EBUSY and silently downgrade capabilities by returning 0, instead of propagating the real failure to the caller.

Quoted 10 lines
(quoted diff) +10 -0
+		dwc3g->phy_regs = NULL;
+		/* Generic bmc USB with PHY*/
+		return 0;
+	}
+
+	/* usb device controller with adapter */
+	dwc3g->dwc.glue_ops = &jhb100_glue_ops;
+
+	return 0;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#2 lore raw

Re: [PATCH v1 1/3] dt-bindings: usb: dwc3: Add JHB100 device controller PHY adapter

In reply to Minda Chen
Quoted 2 lines · Minda Chen

Add dt-binding of JHB100 server host field USB device controller PHY adapter register IO region and its regs-name.

I don't understand the rationale here or the other binding patch. Why is it not always 2 regs? Either the device has 2 or it has 1, there shouldn't be variability unless there's more than one instance and the dfferent instances have different numbers?

Cheers,
Conor.

Quoted 31 lines
---
 .../devicetree/bindings/usb/starfive,jhb100-dwc3.yaml | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml +10 -1
index fbabe99e9d5c..b2fd98c06ba0 100644
@@ -20,7 +20,16 @@ properties:
     const: starfive,jhb100-dwc3
 
   reg:
-    maxItems: 1
+    minItems: 1
+    items:
+      - description: Core DWC3 region
+      - description: DWC3 device controller adapter region
+
+  reg-names:
+    minItems: 1
+    items:
+      - const: core
+      - const: adapter
 
   interrupts:
     maxItems: 1
Signature · 1 line
2.17.1
author maintainer
#3 lore raw

Re: [PATCH v1 1/3] dt-bindings: usb: dwc3: Add JHB100 device controller PHY adapter

Quoted 13 lines · Minda Chen
Quoted 2 lines

Add dt-binding of JHB100 server host field USB device controller PHY adapter register IO region and its regs-name.

I don't understand the rationale here or the other binding patch. Why is it not always 2 regs? Either the device has 2 or it has 1, there shouldn't be variability unless there's more than one instance and the dfferent instances have different numbers?

Cheers,
Conor.

Thanks for reviewing. The virtual device controller do not contain PHY but need to add PHY adapter setting(self-develop by StarFive). So have 2 regs. Previous is BMC USB module do not contain it. But if PHY adapter be moved to PHY related driver can remove this . But Thinh still no review the patch3.

Quoted 34 lines
Quoted 34 lines
---
 .../devicetree/bindings/usb/starfive,jhb100-dwc3.yaml | 11
++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml b/Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml index fbabe99e9d5c..b2fd98c06ba0 100644

Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml +10 -2
@@ -20,7 +20,16 @@ properties:
     const: starfive,jhb100-dwc3
 
   reg:
-    maxItems: 1
+    minItems: 1
+    items:
+      - description: Core DWC3 region
+      - description: DWC3 device controller adapter region
+
+  reg-names:
+    minItems: 1
+    items:
+      - const: core
+      - const: adapter
 
   interrupts:
     maxItems: 1
--

2.17.1

#4 lore raw

Re: [PATCH v1 1/3] dt-bindings: usb: dwc3: Add JHB100 device controller PHY adapter

Quoted 10 lines · Minda Chen
Quoted 10 lines · Minda Chen
Quoted 2 lines

Add dt-binding of JHB100 server host field USB device controller PHY adapter register IO region and its regs-name.

I don't understand the rationale here or the other binding patch. Why is it not always 2 regs? Either the device has 2 or it has 1, there shouldn't be variability unless there's more than one instance and the dfferent instances have different numbers?

Quoted 4 lines
Quoted 3 lines

Cheers,
Conor.

Thanks for reviewing. The virtual device controller do not contain PHY

I don't know what a "virtual device controller" is, or how it relates to usb3. I'm a binding reviewer, not usb, so you'll need to explain this more clearly.

Quoted 2 lines

but need to add PHY adapter setting(self-develop by StarFive). So have 2 regs. Previous is BMC USB module do not contain it. But if PHY adapter be moved

Are you trying to say that the jhb100 has two different usb3 controllers on it, one of which has extra logic implemented by StarFive?

Quoted 36 lines

to PHY related driver can remove this . But Thinh still no review the patch3.

Quoted 34 lines
Quoted 34 lines
---
 .../devicetree/bindings/usb/starfive,jhb100-dwc3.yaml | 11
++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml b/Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml index fbabe99e9d5c..b2fd98c06ba0 100644

Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml +10 -2
@@ -20,7 +20,16 @@ properties:
     const: starfive,jhb100-dwc3
 
   reg:
-    maxItems: 1
+    minItems: 1
+    items:
+      - description: Core DWC3 region
+      - description: DWC3 device controller adapter region
+
+  reg-names:
+    minItems: 1
+    items:
+      - const: core
+      - const: adapter
 
   interrupts:
     maxItems: 1
--

2.17.1

maintainer
#9 lore raw

Re: [PATCH v1 3/3] usb: dwc3-generic: Add Starfive JHB100 USB 2.0 device controller and adapter

In reply to Minda Chen

(sorry for the delay)

Quoted 33 lines · Minda Chen

Add PHY or PHY adapter iomem field in struct dwc3_gerneric for dwc3 generic platform to add PHY/PHY adapter setting.

Also Add Starfive JHB100 USB 2.0 device controller generic init function to remap PHY adapter io memory region and add adapter pre-run/stop function.

JHB100 BMC soc contains Synopsys dwc3 multi-port host controller. And export its xhci controller to host server through PCIe. xhci contains 8 ports and each connect with one dwc3 device controller through an PHY adapter. Server host USB subsystem includes one multi-port dwc3 USB host, multiple dwc3 device controllers and their adapters.

While USB adapter 2.0 enable bit is set, the connect status bit of xhci port stat register will be asserted. If the usb enumeration is not ready for USB gadget, The xhci will fail with enumerate usb device. So The JHB100 USB device controller adapter require to set/clear USB 2.0 port enable while usb gadget start/stop usb device enumeration. This can be treated as a hardware quirk.

---
 drivers/usb/dwc3/dwc3-generic-plat.c | 47 +++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-generic-plat.c +0 -0
index ca69ac0eb07c..e3394205a519 100644
@@ -22,12 +22,15 @@
 #define EIC7700_HSP_AXI_LP_XM_CSYSREQ	BIT(0)
 #define EIC7700_HSP_AXI_LP_XS_CSYSREQ	BIT(16)

drivers/usb/dwc3/dwc3-generic-plat.c line 33

Quoted 10 lines
drivers/usb/dwc3/dwc3-generic-plat.c +3 -0
 
+#define JHB100_ADAPTER_PORT_EN		BIT(20)
+
 struct dwc3_generic {
 	struct device		*dev;
 	struct dwc3		dwc;
 	struct clk_bulk_data	*clks;
 	int			num_clocks;
 	struct reset_control	*resets;
+	void __iomem		*phy_regs; /* PHY or PHY adapter regs */

The name should be generic. Can we just use "regs" and drop the comment?

drivers/usb/dwc3/dwc3-generic-plat.c static void dwc3_generic_reset_control_assert(void *data) · line 48

Quoted 8 lines
drivers/usb/dwc3/dwc3-generic-plat.c +1 -0
 };
 
 struct dwc3_generic_config {
@@ -42,6 +45,43 @@ static void dwc3_generic_reset_control_assert(void *data)
 	reset_control_assert(data);
 }
 
+static void dwc3_jhb100_pre_run_stop(struct dwc3 *dwc3, bool start)

Can we keep the dwc parameter name consistent with the rest of the dwc3 code.

drivers/usb/dwc3/dwc3-generic-plat.c static void dwc3_generic_reset_control_assert(void *data) · line 61

Quoted 13 lines
drivers/usb/dwc3/dwc3-generic-plat.c +13 -0
+{
+	struct dwc3_generic *data = to_dwc3_generic(dwc3);
+	u32	val;
+
+	if (start) {
+		val = readl(data->phy_regs);
+		val |= JHB100_ADAPTER_PORT_EN;
+		writel(val, data->phy_regs);
+	} else {
+		val = readl(data->phy_regs);
+		val &= ~JHB100_ADAPTER_PORT_EN;
+		writel(val, data->phy_regs);
+	}

Minor nit, simplify to this:

	val = readl(data->phy_regs);
	if (start)
		val |= JHB100_ADAPTER_PORT_EN;
	else
		val &= ~JHB100_ADAPTER_PORT_EN;

	writel(val, data->phy_regs);

drivers/usb/dwc3/dwc3-generic-plat.c static void dwc3_generic_reset_control_assert(void *data) · line 64

Quoted 3 lines
drivers/usb/dwc3/dwc3-generic-plat.c +3 -0
+}
+
+struct dwc3_glue_ops jhb100_glue_ops = {

Should this be static?

static struct dwc3_glue_ops jhb100_glue_ops

drivers/usb/dwc3/dwc3-generic-plat.c static void dwc3_generic_reset_control_assert(void *data) · line 73

Quoted 9 lines
drivers/usb/dwc3/dwc3-generic-plat.c +9 -0
+	.pre_run_stop = dwc3_jhb100_pre_run_stop,
+};
+
+static int dwc3_jhb100_init(struct dwc3_generic *dwc3g)
+{
+	struct platform_device *pdev = to_platform_device(dwc3g->dev);
+
+	dwc3g->phy_regs = devm_platform_ioremap_resource_byname(pdev, "adapter");
+	if (IS_ERR(dwc3g->phy_regs)) {

What if this fails for reasons other than resource not found? Please properly check for error code.

drivers/usb/dwc3/dwc3-generic-plat.c static void dwc3_generic_reset_control_assert(void *data) · line 75

Quoted 2 lines
drivers/usb/dwc3/dwc3-generic-plat.c +2 -0
+		dwc3g->phy_regs = NULL;
+		/* Generic bmc USB with PHY*/

Fix the comment missing space.

Quoted 34 lines
drivers/usb/dwc3/dwc3-generic-plat.c +15 -1
+		return 0;
+	}
+
+	/* usb device controller with adapter */
+	dwc3g->dwc.glue_ops = &jhb100_glue_ops;
+
+	return 0;
+}
+
 static int dwc3_eic7700_init(struct dwc3_generic *dwc3g)
 {
 	struct device *dev = dwc3g->dev;
@@ -231,12 +271,17 @@ static const struct dwc3_generic_config eic7700_dwc3 =  {
 	.properties = DWC3_DEFAULT_PROPERTIES,
 };
 
+static const struct dwc3_generic_config jhb100_dwc3 =  {
+	.init = dwc3_jhb100_init,
+	.properties = DWC3_DEFAULT_PROPERTIES,
+};
+
 static const struct of_device_id dwc3_generic_of_match[] = {
 	{ .compatible = "spacemit,k1-dwc3", &spacemit_k1_dwc3},
 	{ .compatible = "spacemit,k3-dwc3", },
 	{ .compatible = "fsl,ls1028a-dwc3", &fsl_ls1028_dwc3},
 	{ .compatible = "eswin,eic7700-dwc3", &eic7700_dwc3},
-	{ .compatible = "starfive,jhb100-dwc3", },
+	{ .compatible = "starfive,jhb100-dwc3", &jhb100_dwc3},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, dwc3_generic_of_match);
Signature · 1 line
2.17.1

The rest looks good to me.

Thanks,
Thinh

author maintainer
#5 lore raw

Re: [PATCH v1 1/3] dt-bindings: usb: dwc3: Add JHB100 device controller PHY adapter

In reply to Conor Dooley
Quoted 14 lines · Minda Chen
Quoted 10 lines
Quoted 10 lines · Minda Chen
Quoted 2 lines

Add dt-binding of JHB100 server host field USB device controller PHY adapter register IO region and its regs-name.

I don't understand the rationale here or the other binding patch. Why is it not always 2 regs? Either the device has 2 or it has 1, there shouldn't be variability unless there's more than one instance and the dfferent instances have different numbers?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

Cheers,
Conor.

Thanks for reviewing. The virtual device controller do not contain PHY

I don't know what a "virtual device controller" is, or how it relates to usb3. I'm a binding reviewer, not usb, so you'll need to explain this more clearly.

Okay

Quoted 7 lines
Quoted 3 lines

but need to add PHY adapter setting(self-develop by StarFive). So have 2 regs. Previous is BMC USB module do not contain it. But if PHY adapter be moved

Are you trying to say that the jhb100 has two different usb3 controllers on it, one of which has extra logic implemented by StarFive?

Thanks,I will add this to commit message in next version.

Quoted 38 lines
Quoted 38 lines

to PHY related driver can remove this . But Thinh still no review the patch3.

Quoted 36 lines
Quoted 36 lines
---
 .../devicetree/bindings/usb/starfive,jhb100-dwc3.yaml | 11
++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml b/Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml index fbabe99e9d5c..b2fd98c06ba0 100644
---
a/Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml +++ b/Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.y +++ aml

Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml +10 -2
@@ -20,7 +20,16 @@ properties:
     const: starfive,jhb100-dwc3
 
   reg:
-    maxItems: 1
+    minItems: 1
+    items:
+      - description: Core DWC3 region
+      - description: DWC3 device controller adapter region
+
+  reg-names:
+    minItems: 1
+    items:
+      - const: core
+      - const: adapter
 
   interrupts:
     maxItems: 1
--

2.17.1

author maintainer
#10 lore raw

Re: [PATCH v1 3/3] usb: dwc3-generic: Add Starfive JHB100 USB 2.0 device controller and adapter

In reply to Thinh Nguyen
Quoted 149 lines

(sorry for the delay)

Quoted 35 lines · Minda Chen

Add PHY or PHY adapter iomem field in struct dwc3_gerneric for dwc3 generic platform to add PHY/PHY adapter setting.

Also Add Starfive JHB100 USB 2.0 device controller generic init function to remap PHY adapter io memory region and add adapter pre-run/stop function.

JHB100 BMC soc contains Synopsys dwc3 multi-port host controller. And export its xhci controller to host server through PCIe. xhci contains 8 ports and each connect with one dwc3 device controller through an PHY adapter. Server host USB subsystem includes one multi-port dwc3 USB host, multiple dwc3 device controllers and their adapters.

While USB adapter 2.0 enable bit is set, the connect status bit of xhci port stat register will be asserted. If the usb enumeration is not ready for USB gadget, The xhci will fail with enumerate usb device. So The JHB100 USB device controller adapter require to set/clear USB 2.0 port enable while usb gadget start/stop usb device enumeration. This can be treated as a hardware quirk.

---
 drivers/usb/dwc3/dwc3-generic-plat.c | 47
+++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-generic-plat.c +0 -0
index ca69ac0eb07c..e3394205a519 100644
@@ -22,12 +22,15 @@
 #define EIC7700_HSP_AXI_LP_XM_CSYSREQ	BIT(0)
 #define EIC7700_HSP_AXI_LP_XS_CSYSREQ	BIT(16)

drivers/usb/dwc3/dwc3-generic-plat.c line 33

Quoted 10 lines
drivers/usb/dwc3/dwc3-generic-plat.c +3 -0
 
+#define JHB100_ADAPTER_PORT_EN		BIT(20)
+
 struct dwc3_generic {
 	struct device		*dev;
 	struct dwc3		dwc;
 	struct clk_bulk_data	*clks;
 	int			num_clocks;
 	struct reset_control	*resets;
+	void __iomem		*phy_regs; /* PHY or PHY adapter regs */

The name should be generic. Can we just use "regs" and drop the comment?

drivers/usb/dwc3/dwc3-generic-plat.c static void dwc3_generic_reset_control_assert(void

Quoted 4 lines
drivers/usb/dwc3/dwc3-generic-plat.c +0 -0
 };
 
 struct dwc3_generic_config {
@@ -42,6 +45,43 @@ static void dwc3_generic_reset_control_assert(void

*data)

drivers/usb/dwc3/dwc3-generic-plat.c static void dwc3_generic_reset_control_assert(void *data) · line 48

Quoted 4 lines
drivers/usb/dwc3/dwc3-generic-plat.c +1 -0
 	reset_control_assert(data);
 }
 
+static void dwc3_jhb100_pre_run_stop(struct dwc3 *dwc3, bool start)

Can we keep the dwc parameter name consistent with the rest of the dwc3 code.

drivers/usb/dwc3/dwc3-generic-plat.c static void dwc3_generic_reset_control_assert(void *data) · line 61

Quoted 13 lines
drivers/usb/dwc3/dwc3-generic-plat.c +13 -0
+{
+	struct dwc3_generic *data = to_dwc3_generic(dwc3);
+	u32	val;
+
+	if (start) {
+		val = readl(data->phy_regs);
+		val |= JHB100_ADAPTER_PORT_EN;
+		writel(val, data->phy_regs);
+	} else {
+		val = readl(data->phy_regs);
+		val &= ~JHB100_ADAPTER_PORT_EN;
+		writel(val, data->phy_regs);
+	}

Minor nit, simplify to this:

	val = readl(data->phy_regs);
	if (start)
		val |= JHB100_ADAPTER_PORT_EN;
	else
		val &= ~JHB100_ADAPTER_PORT_EN;

	writel(val, data->phy_regs);

drivers/usb/dwc3/dwc3-generic-plat.c static void dwc3_generic_reset_control_assert(void *data) · line 64

Quoted 3 lines
drivers/usb/dwc3/dwc3-generic-plat.c +3 -0
+}
+
+struct dwc3_glue_ops jhb100_glue_ops = {

Should this be static?

static struct dwc3_glue_ops jhb100_glue_ops

drivers/usb/dwc3/dwc3-generic-plat.c static void dwc3_generic_reset_control_assert(void *data)

Quoted 6 lines
drivers/usb/dwc3/dwc3-generic-plat.c +6 -0
+	.pre_run_stop = dwc3_jhb100_pre_run_stop, };
+
+static int dwc3_jhb100_init(struct dwc3_generic *dwc3g) {
+	struct platform_device *pdev = to_platform_device(dwc3g->dev);
+
+	dwc3g->phy_regs = devm_platform_ioremap_resource_byname(pdev,

"adapter");

drivers/usb/dwc3/dwc3-generic-plat.c static void dwc3_generic_reset_control_assert(void *data) · line 73

Quoted 1 line
drivers/usb/dwc3/dwc3-generic-plat.c +1 -0
+	if (IS_ERR(dwc3g->phy_regs)) {

What if this fails for reasons other than resource not found? Please properly check for error code.

drivers/usb/dwc3/dwc3-generic-plat.c static void dwc3_generic_reset_control_assert(void *data) · line 75

Quoted 2 lines
drivers/usb/dwc3/dwc3-generic-plat.c +2 -0
+		dwc3g->phy_regs = NULL;
+		/* Generic bmc USB with PHY*/

Fix the comment missing space.

drivers/usb/dwc3/dwc3-generic-plat.c static const struct dwc3_generic_config

Quoted 12 lines
drivers/usb/dwc3/dwc3-generic-plat.c +9 -0
+		return 0;
+	}
+
+	/* usb device controller with adapter */
+	dwc3g->dwc.glue_ops = &jhb100_glue_ops;
+
+	return 0;
+}
+
 static int dwc3_eic7700_init(struct dwc3_generic *dwc3g)  {
 	struct device *dev = dwc3g->dev;
@@ -231,12 +271,17 @@ static const struct dwc3_generic_config

eic7700_dwc3 = {

Quoted 17 lines
drivers/usb/dwc3/dwc3-generic-plat.c +5 -2
 	.properties = DWC3_DEFAULT_PROPERTIES,  };
 
+static const struct dwc3_generic_config jhb100_dwc3 =  {
+	.init = dwc3_jhb100_init,
+	.properties = DWC3_DEFAULT_PROPERTIES, };
+
 static const struct of_device_id dwc3_generic_of_match[] = {
 	{ .compatible = "spacemit,k1-dwc3", &spacemit_k1_dwc3},
 	{ .compatible = "spacemit,k3-dwc3", },
 	{ .compatible = "fsl,ls1028a-dwc3", &fsl_ls1028_dwc3},
 	{ .compatible = "eswin,eic7700-dwc3", &eic7700_dwc3},
-	{ .compatible = "starfive,jhb100-dwc3", },
+	{ .compatible = "starfive,jhb100-dwc3", &jhb100_dwc3},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, dwc3_generic_of_match);
--
Quoted 2 lines

2.17.1

The rest looks good to me.

Quoted 2 lines

Thanks,
Thinh

Thanks for review! I will follow the comments to modify and sent v2!