Add StarFive JHB100 host field USB device controller driver
Minda Chen
maintainerv3 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.
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.4-rc1
previous verions link:
v1:
https://patchwork.kernel.org/project/linux-usb/patch/[email protected]/
v2:
https://patchwork.kernel.org/project/linux-usb/cover/[email protected]/
changes:
v1:
patch1 and patch2: Correct the title and add more descriptions.
patch3: Correct the get iomem code and follow the comments by Thinh v2:
All modify commit message.
patch1: Add new descriptions and add new property branch
patch2: Add new usb device-only dts example.
Minda Chen (3):
dt-bindings: usb: starfive,jhb100-dwc3: Add adapter register region
dt-bindings: usb: starfive,jhb100-dwc3: Add clock number limit
usb: dwc3: starfive: Add JHB100 USB device adapter port enable quirk
.../bindings/usb/starfive,jhb100-dwc3.yaml | 59 ++++++++++++++++++- drivers/usb/dwc3/dwc3-generic-plat.c | 48 ++++++++++++++- 2 files changed, 104 insertions(+), 3 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.17.1
Minda Chen
maintainerPATCH v3 1/3 dt-bindings: usb: starfive,jhb100-dwc3: Add adapter register region
Besides the DRD controllers, the JHB100 BMC SoC has DWC3 device-only controllers which are not connected to a USB PHY. Each of them is connected through a PHY adapter to a port of an xHCI controller that is exported to the server host over PCIe. The adapter has its own register region that software has to program.
Describe the adapter register region as an optional second "reg" entry and add "reg-names". The DRD controllers keep a single register region.
The adapter is only present on the device-only controllers, so restrict dr_mode to "peripheral" when the adapter region is described.
--- .../bindings/usb/starfive,jhb100-dwc3.yaml | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml +35 -2
@@ -10,17 +10,50 @@ maintainers: - Minda Chen <[email protected]> description: - The USB DRD controller on JHB100 BMC SoC. + The USB DRD controllers and the USB device-only controllers on the + JHB100 BMC SoC. The device-only controllers are not connected to a USB + PHY. Each one is connected through a PHY adapter to an xHCI port that + is exported to the server host. allOf: - $ref: snps,dwc3-common.yaml# + - if: + required: + - reg-names + properties: + reg-names: + contains: + const: adapter + then: + properties: + reg: + minItems: 2 + reg-names: + minItems: 2 + dr_mode: + const: peripheral + else: + properties: + reg: + maxItems: 1 + reg-names: + maxItems: 1 properties: compatible: const: starfive,jhb100-dwc3 reg: - maxItems: 1 + minItems: 1 + items: + - description: DWC3 core registers + - description: DWC3 device controller PHY adapter registers + + reg-names: + minItems: 1 + items: + - const: core + - const: adapter interrupts: maxItems: 1
Signature · 1 line
2.17.1
Minda Chen
maintainerPATCH v3 2/3 dt-bindings: usb: starfive,jhb100-dwc3: Add clock number limit
In reply to Minda ChenThe JHB100 device-only controllers are connected to a digital PHY adapter instead of a USB PHY, so they have no reference clock. Only the "main" and "bus_early" clocks are present.
Allow two clocks for the controllers with the adapter region, keep requiring all three clocks for the DRD controllers, and add an example of a device-only controller.
--- .../bindings/usb/starfive,jhb100-dwc3.yaml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+)
Documentation/devicetree/bindings/usb/starfive,jhb100-dwc3.yaml +22 -0
@@ -30,6 +30,10 @@ allOf: minItems: 2 reg-names: minItems: 2 + clocks: + maxItems: 2 + clock-names: + maxItems: 2 dr_mode: const: peripheral else:
@@ -38,6 +42,10 @@ allOf: maxItems: 1 reg-names: maxItems: 1 + clocks: + minItems: 3 + clock-names: + minItems: 3 properties: compatible:
@@ -59,12 +67,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
@@ -95,3 +105,15 @@ examples: interrupts = <105>; dr_mode = "host"; }; + - | + usb@10600000 { + compatible = "starfive,jhb100-dwc3"; + reg = <0x10600000 0x10000>, <0x10695800 0x100>; + reg-names = "core", "adapter"; + clocks = <&usbdcrg 30>, + <&usbdcrg 31>; + clock-names = "main", "bus_early"; + resets = <&usbdcrg 12>; + interrupts = <106>; + dr_mode = "peripheral"; + };
Signature · 1 line
2.17.1
Minda Chen
maintainerPATCH v3 3/3 usb: dwc3: starfive: Add JHB100 USB device adapter port enable quirk
In reply to Minda ChenOn the JHB100 BMC SoC, each DWC3 device controller is connected to a port of the xHCI controller that is exported to the server host over PCIe, through a PHY adapter. Setting the adapter USB 2.0 port enable bit asserts the connect status in the xHCI PORTSC register, so it must only be set once the gadget is ready to be enumerated, otherwise the host fails to enumerate the device.
Map the optional "adapter" register region from the JHB100 init callback, and set or clear the port enable bit from the pre_run_stop glue callback.
--- drivers/usb/dwc3/dwc3-generic-plat.c | 48 +++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-generic-plat.c +47 -1
@@ -22,12 +22,15 @@#define EIC7700_HSP_AXI_LP_XM_CSYSREQ BIT(0)#define EIC7700_HSP_AXI_LP_XS_CSYSREQ BIT(16) +#define STARFIVE_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 *regs; };struct dwc3_generic_config {
@@ -42,6 +45,44 @@ static void dwc3_generic_reset_control_assert(void *data)reset_control_assert (data); } +static void dwc3_starfive_jhb100_pre_run_stop (struct dwc3 *dwc3,bool start) +{ +struct dwc3_generic *data =to_dwc3_generic (dwc3); +u32 val; + + val =readl (data->regs); + +if (start) + val |=STARFIVE_JHB100_ADAPTER_PORT_EN ; +else + val &= ~STARFIVE_JHB100_ADAPTER_PORT_EN ; + +writel (val, data->regs); +} + +static const struct dwc3_glue_ops starfive_jhb100_glue_ops = { + .pre_run_stop = dwc3_starfive_jhb100_pre_run_stop, +}; + +static int starfive_dwc3_jhb100_init (struct dwc3_generic *dwc3g) +{ +struct platform_device *pdev =to_platform_device (dwc3g->dev); +struct resource *res; + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"adapter" ); +if (res) { +/* usb device controller with adapter */ + dwc3g->regs =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (dwc3g->regs)) +return dev_err_probe (&pdev->dev,PTR_ERR (dwc3g->regs), +"failed to get adapter regs\n" ); + + dwc3g->dwc.glue_ops = &starfive_jhb100_glue_ops; + } + +return 0 ; +} +static int dwc3_eic7700_init (struct dwc3_generic *dwc3g) {struct device *dev = dwc3g->dev;
@@ -231,12 +272,17 @@ static const struct dwc3_generic_config eic7700_dwc3 = { .properties = DWC3_DEFAULT_PROPERTIES, }; +static const struct dwc3_generic_config starfive_jhb100_dwc3 = { + .init = starfive_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" , &starfive_jhb100_dwc3}, {/* sentinel */ } };MODULE_DEVICE_TABLE (of, dwc3_generic_of_match);
Signature · 1 line
2.17.1
[email protected]
AI reviewSashiko has reviewed this 3-patch series and found no issues.
Sashiko has reviewed this 3-patch series and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]