mbox series

[0/7] Add USB3.0 PHY and host controller support for SpacemiT K1 SoC

Message ID 20250407-b4-k1-usb3-v3-2-v1-0-bf0bcc41c9ba@whut.edu.cn
Headers show
Series Add USB3.0 PHY and host controller support for SpacemiT K1 SoC | expand

Message

Ze Huang April 7, 2025, 12:38 p.m. UTC
This patch series introduces support for the USB on the SpacemiT K1 SoC,
including DWC3 host controller, PCIe/USB3.0 combo PHY and the USB2.0 PHY.
The implementation has been tested on the Milk-V Jupiter and BananaPi-f3.

USB3.0 PHY for usb2 is shared with PCIe port A, meaning that only one of
these interfaces (PCIe or USB3.0) can be active at a given time.

Overview of USB controllers on K1 SoC[1]:

Link: https://developer.spacemit.com/documentation?token=AjHDwrW78igAAEkiHracBI9HnTb#part5 [1]
---
Ze Huang (7):
      dt-bindings: phy: spacemit: add K1 USB2 PHY
      dt-bindings: phy: spacemit: add K1 PCIe/USB3 combo PHY
      dt-bindings: usb: add SpacemiT K1 DWC3 glue
      phy: spacemit: support K1 USB2.0 PHY controller
      phy: spacemit: add USB3 support for K1 PCIe/USB3 combo PHY
      usb: dwc3: add spacemit dwc3 glue layer driver
      riscv: dts: spacemit: add usb3.0 support for K1

 .../bindings/phy/spacemit,k1-combphy.yaml          |  53 +++++
 .../devicetree/bindings/phy/spacemit,usb2-phy.yaml |  40 ++++
 .../devicetree/bindings/usb/spacemit,k1-dwc3.yaml  |  78 +++++++
 arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts    |  55 +++++
 arch/riscv/boot/dts/spacemit/k1.dtsi               |  52 +++++
 drivers/phy/Kconfig                                |   1 +
 drivers/phy/Makefile                               |   1 +
 drivers/phy/spacemit/Kconfig                       |  20 ++
 drivers/phy/spacemit/Makefile                      |   3 +
 drivers/phy/spacemit/phy-k1-combphy.c              | 229 +++++++++++++++++++++
 drivers/phy/spacemit/phy-k1-usb2.c                 | 132 ++++++++++++
 drivers/usb/dwc3/Kconfig                           |   7 +
 drivers/usb/dwc3/Makefile                          |   1 +
 drivers/usb/dwc3/dwc3-spacemit.c                   | 127 ++++++++++++
 14 files changed, 799 insertions(+)
---
base-commit: 64e9fdfc89a76fed38d8ddeed72d42ec71957ed9
change-id: 20250407-b4-k1-usb3-v3-2-1682aa492559
prerequisite-message-id: <20250306175750.22480-2-heylenay@4d2.org>
prerequisite-patch-id: e0f9037d659502b7f10588f15b80505724eb9e35
prerequisite-patch-id: 4414e37b16b1bc0039239f07da8c35935efb1601
prerequisite-patch-id: 1e65bc4c0c0d41baef743819c311ad53f6696094
prerequisite-patch-id: 43ef72522e30620f0244e0e22bd844884d89b0cd
prerequisite-patch-id: 73008ee7c04e90cd4e825a3f5bd2e44ec24d8ad3
prerequisite-message-id: <20250328210233.1077035-1-elder@riscstar.com>
prerequisite-patch-id: 9b026005eb6ee1430ab7ca67edfc21de85a19dd2
prerequisite-patch-id: 8ee238181e50c76d92458b149b72fa4909e0fede
prerequisite-patch-id: 66f3ee8eb1cc016112dace699bce292b617a3186
prerequisite-patch-id: c2deec49fc0308a08908fd9badadc10f921af348
prerequisite-patch-id: 99afc2efdffc0fffe47a31e7b07b72af9d1d2e18
prerequisite-patch-id: d06e8cd0fae4c405dbb56832a1fe48bfaa4e0fab
prerequisite-patch-id: 5f53f8bf16fb067628092daebc4831293261aa01
prerequisite-message-id: <20250226115957-GYA45508@gentoo>
prerequisite-patch-id: 82dd2631d36c3fafb82768d3d89022ed956020c6
prerequisite-patch-id: 5cc63738ba2d463e1840a91a94357f43199bd68f
prerequisite-patch-id: f44247679d46a51c242703eca370ce0e3db2e61f
prerequisite-patch-id: 9d4cd8be42a37798815d0aaae21d3c022f815414

Best regards,

Comments

Ze Huang April 9, 2025, 8:01 a.m. UTC | #1
On 4/7/25 9:18 PM, Krzysztof Kozlowski wrote:
> On 07/04/2025 14:38, Ze Huang wrote:
>> +
>> +properties:
>> +  compatible:
>> +    const: spacemit,k1-usb2-phy
>> +
>> +  reg:
>> +    maxItems: 1
>> +
>> +  clocks:
>> +    maxItems: 1
>> +
>> +  "#phy-cells":
>> +    const: 0
>> +
> No supplies? No resets? Are you sure hardware does not use them?

No resets are used for the USB 2.0 PHY, but there is a VBUS supply, which
I included in the DWC3 glue nodes.

>
> Best regards,
> Krzysztof
>
>
Ze Huang April 9, 2025, 8:16 a.m. UTC | #2
On 4/7/25 9:22 PM, Krzysztof Kozlowski wrote:
> On 07/04/2025 14:38, Ze Huang wrote:
>> Add support for SpacemiT DWC3 glue driver, which manages interrupt,
>> reset and clock resource.
>>
>> Signed-off-by: Ze Huang <huangze@whut.edu.cn>
>> ---
>>   .../devicetree/bindings/usb/spacemit,k1-dwc3.yaml  | 78 ++++++++++++++++++++++
>>   1 file changed, 78 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/usb/spacemit,k1-dwc3.yaml b/Documentation/devicetree/bindings/usb/spacemit,k1-dwc3.yaml
> Combining 3 subsystems into one patchset is a poor idea.

Acknowledged, will split into two sets in next version
1. usb2 phy and combo phy
2. dwc3 glue driver and dts

>
>> new file mode 100644
>> index 0000000000000000000000000000000000000000..40ce3fd1330d5f371ec69155c237e10a65a9d8f4
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/usb/spacemit,k1-dwc3.yaml
>> @@ -0,0 +1,78 @@
>> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
>> +%YAML 1.2
>> +---
>> +$id: http://devicetree.org/schemas/usb/spacemit,k1-dwc3.yaml#
>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>> +
>> +title: SpacemiT K1 SuperSpeed DWC3 USB SoC Controller Glue
>> +
>> +maintainers:
>> +  - Ze Huang <huangze@whut.edu.cn>
>> +
>> +properties:
>> +  compatible:
>> +    const: spacemit,k1-dwc3
>> +
>> +  ranges:
>> +    maxItems: 1
>> +
>> +  clocks:
>> +    maxItems: 1
>> +
>> +  resets:
>> +    maxItems: 1
>> +
>> +  interrupts:
>> +    maxItems: 1
>> +
>> +  interconnects:
> Missing maxItems

Will fix

>
>> +    description:
>> +      On SpacemiT K1, USB performs DMA through bus other than parent DT node.
>> +      The 'interconnects' property explicitly describes this path, ensuring
>> +      correct address translation.
>> +
>> +  interconnect-names:
>> +    const: dma-mem
>> +
>> +  # optional
> Drop, Don't repeat constraints in free form text.

Will do

>
>> +  vbus-supply:
>> +    description: A phandle to the regulator supplying the VBUS voltage.
>> +
>> +patternProperties:
>> +  '^usb@':
>> +    $ref: snps,dwc3.yaml#
> No, rather fold child into the parent.

I’m not entirely sure I understand your suggestion. Could you please provide
an example? Thanks!

>
>> +
>> +additionalProperties: false
> This goes after required:, always.

OK

>
>> +
>> +required:
>> +  - compatible
>> +  - ranges
>> +  - clocks
>> +  - resets
>> +  - interrupts
>> +  - interconnects
>> +  - interconnect-names
>> +
>> +examples:
>> +  - |
>> +    usb@c0a00000 {
>> +        compatible = "spacemit,k1-dwc3";
>> +        clocks = <&syscon_apmu 16>;
>> +        interrupts = <149>;
>> +        interconnects = <&dram_range0>;
>> +        interconnect-names = "dma-mem";
>> +        ranges = <0x0 0xc0a00000 0x10000>;
>> +        resets = <&syscon_apmu 8>;
>> +        #address-cells = <1>;
>> +        #size-cells = <1>;
>> +        status = "disabled";
> Nope, drop.

Will drop 'status'

>
>
>
> Best regards,
> Krzysztof
>
>
Ze Huang April 9, 2025, 8:30 a.m. UTC | #3
On 4/7/25 9:51 PM, Rob Herring (Arm) wrote:
> On Mon, 07 Apr 2025 20:38:48 +0800, Ze Huang wrote:
>> Add support for SpacemiT DWC3 glue driver, which manages interrupt,
>> reset and clock resource.
>>
>> Signed-off-by: Ze Huang <huangze@whut.edu.cn>
>> ---
>>   .../devicetree/bindings/usb/spacemit,k1-dwc3.yaml  | 78 ++++++++++++++++++++++
>>   1 file changed, 78 insertions(+)
>>
> My bot found errors running 'make dt_binding_check' on your patch:
>
> yamllint warnings/errors:
>
> dtschema/dtc warnings/errors:
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/usb/spacemit,k1-dwc3.example.dtb: usb@c0a00000 (spacemit,k1-dwc3): '#address-cells', '#size-cells' do not match any of the regexes: '^usb@', 'pinctrl-[0-9]+'
> 	from schema $id: http://devicetree.org/schemas/usb/spacemit,k1-dwc3.yaml#
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/usb/spacemit,k1-dwc3.example.dtb: usb@c0a00000 (spacemit,k1-dwc3): usb@0:reg: [[0, 0], [0, 65536]] is too long
> 	from schema $id: http://devicetree.org/schemas/usb/spacemit,k1-dwc3.yaml#
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/usb/spacemit,k1-dwc3.example.dtb: usb@0 (snps,dwc3): reg: [[0, 0], [0, 65536]] is too long
> 	from schema $id: http://devicetree.org/schemas/usb/snps,dwc3.yaml#

Thanks for the report!
I’ll add '#address-cells' and '#size-cells' under properties to resolve 
the error.
because if I drop them from the example, I get warnings like:

Warning (avoid_default_addr_size): /example-0/usb@c0a00000/usb@0: 
Relying on default #address-cells value

>
> doc reference errors (make refcheckdocs):
>
> See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20250407-b4-k1-usb3-v3-2-v1-3-bf0bcc41c9ba@whut.edu.cn
>
> The base for the series is generally the latest rc1. A different dependency
> should be noted in *this* patch.
>
> If you already ran 'make dt_binding_check' and didn't see the above
> error(s), then make sure 'yamllint' is installed and dt-schema is up to
> date:
>
> pip3 install dtschema --upgrade
>
> Please check and re-submit after running the above command yourself. Note
> that DT_SCHEMA_FILES can be set to your schema file to speed up checking
> your schema. However, it must be unset to test all examples with your schema.
>
>
>
Ze Huang April 9, 2025, 9:43 a.m. UTC | #4
On 4/7/25 9:28 PM, Krzysztof Kozlowski wrote:
> On 07/04/2025 14:38, Ze Huang wrote:
>> Add support for USB 3.0 mode on the K1 PCIe/USB3 combo PHY. Currently,
>> only USB mode is supported; PCIe support is not included in this change.
>>
>> Signed-off-by: Ze Huang <huangze@whut.edu.cn>
>> ---
>>   drivers/phy/spacemit/Kconfig          |   8 ++
>>   drivers/phy/spacemit/Makefile         |   1 +
>>   drivers/phy/spacemit/phy-k1-combphy.c | 229 ++++++++++++++++++++++++++++++++++
>>   3 files changed, 238 insertions(+)
>>
>> diff --git a/drivers/phy/spacemit/Kconfig b/drivers/phy/spacemit/Kconfig
>> index f0c2a33f53cc810e71c6140ae957aa68a2b6ff0c..12749aba756329cf64fb9199055ba484fe05f3ab 100644
>> --- a/drivers/phy/spacemit/Kconfig
>> +++ b/drivers/phy/spacemit/Kconfig
>> @@ -10,3 +10,11 @@ config PHY_SPACEMIT_K1_USB2
>>   	help
>>   	  Enable this to support K1 USB 2.0 PHY driver. This driver takes care of
>>   	  enabling and clock setup and will be used by K1 udc/ehci/otg driver.
>> +
>> +config PHY_SPACEMIT_K1_COMBPHY
>> +	tristate "SpacemiT K1 PCIe/USB3 combo PHY support"
>> +	depends on OF
>> +	select GENERIC_PHY
>> +	default ARCH_SPACEMIT && USB_DWC3_SPACEMIT
>> +	help
>> +	  USB3/PCIe Combo PHY Support for SpacemiT K1 SoC
> Missing depends on ARCH_SPACEMIT || COMPILE_TEST

Will fix, thanks!

>
> ...
>
>
>> +	priv->phy = devm_phy_create(dev, NULL, &spacemit_combphy_ops);
>> +	if (IS_ERR(priv->phy))
>> +		return dev_err_probe(dev, PTR_ERR(priv->phy),
>> +				     "failed to create combphy\n");
>> +
>> +	dev_set_drvdata(dev, priv);
>> +	phy_set_drvdata(priv->phy, priv);
> Both make no sense. Look what this function does.

It does seem redundant at first glance, but pdev->dev is the parent of 
phy->dev.
pdev->dev->driver_data will be used in spacemit_combphy_xlate()
phy->dev->driver_data  will be used in phy_ops functions

I've checked some other drivers that did the same:
     - phy-zynqmp.c at lines 990 and 1026
     - phy-rockchip-samsung-hdptx.c at lines 1989 and 2000

>
> Best regards,
> Krzysztof
>
>
Krzysztof Kozlowski April 9, 2025, 10:08 a.m. UTC | #5
On 09/04/2025 10:16, Ze Huang wrote:
>>
>>> +  vbus-supply:
>>> +    description: A phandle to the regulator supplying the VBUS voltage.
>>> +
>>> +patternProperties:
>>> +  '^usb@':
>>> +    $ref: snps,dwc3.yaml#
>> No, rather fold child into the parent.
> 
> I’m not entirely sure I understand your suggestion. Could you please provide
> an example? Thanks!
Do not create glue node, but only one node for entire DWC. All new DWC
USB bindings are supposed to follow this new approach. There are some
examples in the tree and some on the lists.

Best regards,
Krzysztof
Krzysztof Kozlowski April 9, 2025, 10:10 a.m. UTC | #6
On 09/04/2025 11:43, Ze Huang wrote:
>>> +	priv->phy = devm_phy_create(dev, NULL, &spacemit_combphy_ops);
>>> +	if (IS_ERR(priv->phy))
>>> +		return dev_err_probe(dev, PTR_ERR(priv->phy),
>>> +				     "failed to create combphy\n");
>>> +
>>> +	dev_set_drvdata(dev, priv);
>>> +	phy_set_drvdata(priv->phy, priv);
>> Both make no sense. Look what this function does.
> 
> It does seem redundant at first glance, but pdev->dev is the parent of 
> phy->dev.
> pdev->dev->driver_data will be used in spacemit_combphy_xlate()
> phy->dev->driver_data  will be used in phy_ops functions
> 
> I've checked some other drivers that did the same:
>      - phy-zynqmp.c at lines 990 and 1026
>      - phy-rockchip-samsung-hdptx.c at lines 1989 and 2000

Indeed, right. It's fine.

Best regards,
Krzysztof
Pan Junzhong April 9, 2025, 11:38 a.m. UTC | #7
Hi Ze,

> +static int spacemit_combphy_init_usb(struct spacemit_combphy_priv *priv)

The USB3 phy driver is updated in the vendor's tree. 
https://gitee.com/bianbu-linux/linux-6.6/commit/1c0b3b4b9c77d22ca886c8a4c44e62b5891f8abc

You can submit v2 together with the change of lfps_thres (writes 0x58 register)
without adding new properties for dt node.

B.R.


This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
 
本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
Ze Huang April 9, 2025, 11:42 a.m. UTC | #8
On 4/9/25 7:38 PM, Pan Junzhong wrote:
> Hi Ze,
>
>> +static int spacemit_combphy_init_usb(struct spacemit_combphy_priv *priv)
> The USB3 phy driver is updated in the vendor's tree.
> https://gitee.com/bianbu-linux/linux-6.6/commit/1c0b3b4b9c77d22ca886c8a4c44e62b5891f8abc
>
> You can submit v2 together with the change of lfps_thres (writes 0x58 register)
> without adding new properties for dt node.

OK, thanks!

> B.R.
>
>
> This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking.
>   
> 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
Rob Herring April 10, 2025, 8:53 p.m. UTC | #9
On Mon, 07 Apr 2025 20:38:46 +0800, Ze Huang wrote:
> Add support for USB2 PHY found on SpacemiT K1 SoC.
> 
> Signed-off-by: Ze Huang <huangze@whut.edu.cn>
> ---
>  .../devicetree/bindings/phy/spacemit,usb2-phy.yaml | 40 ++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>