Skip to contentSkip to conversation

Add USB support for Sophgo CV1800/SG200x SoCs

PATCH In review Yao Zi 4 participants 9 messages Jul 8, 2024 – Jul 9, 2024

Subsystems (4)
lore
Share & tools
lore

Yao Zi

author
#0 lore raw

cover Add USB support for Sophgo CV1800/SG200x SoCs

Sophgo CV1800/SG200x SoCs integrate a USB 2.0 phy and a USB 2.0 controller based on dwc2 IP. This series implements a basic driver for the USB phy and add USB-related device tree nodes.

Yao Zi (3):
dt-bindings: phy: add YAML schema for cv1800-usb-phy driver bindings
riscv: dts: sophgo: add nodes for USB phy and controller
phy: sophgo: add usb phy driver for Sophgo CV1800 SoCs

 .../bindings/phy/sophgo,cv1800-usb-phy.yaml   |  67 ++++++
 arch/riscv/boot/dts/sophgo/cv18xx.dtsi        |  23 ++
 drivers/phy/Kconfig                           |   1 +
 drivers/phy/Makefile                          |   1 +
 drivers/phy/sophgo/Kconfig                    |  10 +
 drivers/phy/sophgo/Makefile                   |   2 +
 drivers/phy/sophgo/phy-cv1800-usb.c           | 213 ++++++++++++++++++
 7 files changed, 317 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml
 create mode 100644 drivers/phy/sophgo/Kconfig
 create mode 100644 drivers/phy/sophgo/Makefile
 create mode 100644 drivers/phy/sophgo/phy-cv1800-usb.c
Signature · 1 line
2.45.2
author
#1 lore raw

PATCH 1/3 dt-bindings: phy: add YAML schema for cv1800-usb-phy driver bindings

cv1800-usb-phy driver supports USB 2.0 phys integrated in Sophgo Cv1800/SG200x SoCs. Add YAML schema for its binding.

---
 .../bindings/phy/sophgo,cv1800-usb-phy.yaml   | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +67 -0
new file mode 100644
index 000000000000..0403d899e23b
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2019 BayLibre, SAS
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/sophgo,cv1800-usb-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sophgo CV1800 USB PHY
+
+maintainers:
+  - Yao Zi <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - sophgo,cv1800-usb-phy
+
+  reg:
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: phy
+      - const: pin
+
+  clocks:
+    maxItems: 4
+
+  clock-names:
+    items:
+      - const: apb
+      - const: 125m
+      - const: 33k
+      - const: 12m
+
+  "#phy-cells":
+    const: 0
+
+  dr_role:
+    enum:
+      - host
+      - device
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - clocks
+  - clock-names
+  - "#phy-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/sophgo,cv1800.h>
+    usb_phy: usb-phy@3006000 {
+        compatible = "sophgo,cv1800-usb-phy";
+        reg = <0x300600 0x60>, <0x3000048 0x4>;
+        reg-names = "phy", "pin";
+        clocks = <&clk CLK_APB_USB>,
+                 <&clk CLK_USB_125M>,
+                 <&clk CLK_USB_33K>,
+                 <&clk CLK_USB_12M>;
+        clock-names = "apb", "125m", "33k", "12m";
+        #phy-cells = <0>;
+    };
Signature · 1 line
2.45.2
#2 lore raw

Re: [PATCH 1/3] dt-bindings: phy: add YAML schema for cv1800-usb-phy driver bindings

Quoted 4 lines · Yao Zi

cv1800-usb-phy driver supports USB 2.0 phys integrated in Sophgo Cv1800/SG200x SoCs. Add YAML schema for its binding.

A nit, subject: drop second/last, redundant "bindings". The "dt-bindings" prefix is already stating that these are bindings. See also:
https://elixir.bootlin.com/linux/v6.7-rc8/source/Documentation/devicetree/bindings/submitting-patches.rst#L18

Quoted 12 lines
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +12 -0
+properties:
+  compatible:
+    enum:
+      - sophgo,cv1800-usb-phy
+
+  reg:
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: phy
+      - const: pin

Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml line 34

Quoted 10 lines
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +10 -0
+
+  clocks:
+    maxItems: 4
+
+  clock-names:
+    items:
+      - const: apb
+      - const: 125m
+      - const: 33k
+      - const: 12m

All these three should have rather some logical name, not frequency.

Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml line 39

Quoted 5 lines
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +5 -0
+
+  "#phy-cells":
+    const: 0
+
+  dr_role:

No underscores in node names, missing vendor prefix (unless it is generic property), missing description.

Please do not invent new properties like this. You probably wanted to reference usb-drd?

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH 1/3] dt-bindings: phy: add YAML schema for cv1800-usb-phy driver bindings

In reply to Yao Zi
Quoted 29 lines · Yao Zi

cv1800-usb-phy driver supports USB 2.0 phys integrated in Sophgo Cv1800/SG200x SoCs. Add YAML schema for its binding.

---
 .../bindings/phy/sophgo,cv1800-usb-phy.yaml   | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +14 -0
new file mode 100644
index 000000000000..0403d899e23b
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2019 BayLibre, SAS
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/sophgo,cv1800-usb-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sophgo CV1800 USB PHY
+
+maintainers:
+  - Yao Zi <[email protected]>
+
+properties:
+  compatible:

Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml line 24

Quoted 10 lines
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +10 -0
+    enum:
+      - sophgo,cv1800-usb-phy
+
+  reg:
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: phy
+      - const: pin

drop pin, cv1800 series does not support this.

Quoted 8 lines
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +8 -0
+
+  clocks:
+    maxItems: 4
+
+  clock-names:
+    items:
+      - const: apb
+      - const: 125m

Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml line 42

Quoted 10 lines
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +10 -0
+      - const: 33k
+      - const: 12m
+
+  "#phy-cells":
+    const: 0
+
+  dr_role:
+    enum:
+      - host
+      - device

cv181x series have otg support. For board with OTG, it should be properly handled.

Quoted 28 lines
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +25 -0
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - clocks
+  - clock-names
+  - "#phy-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/sophgo,cv1800.h>
+    usb_phy: usb-phy@3006000 {
+        compatible = "sophgo,cv1800-usb-phy";
+        reg = <0x300600 0x60>, <0x3000048 0x4>;
+        reg-names = "phy", "pin";
+        clocks = <&clk CLK_APB_USB>,
+                 <&clk CLK_USB_125M>,
+                 <&clk CLK_USB_33K>,
+                 <&clk CLK_USB_12M>;
+        clock-names = "apb", "125m", "33k", "12m";
+        #phy-cells = <0>;
+    };
Signature · 1 line
2.45.2

You patch is duplicated, I have sumbitted patches month ago and still needs some time to figure out the best topology. Phy driver belongs to syscon, which make things kind of complex.

https://lore.kernel.org/all/IA1PR20MB4953C1876484E149AA390DD5BB1D2@IA1PR20MB4953.namprd20.prod.outlook.com/#t

Regards,
Inochi

#4 lore raw

Re: [PATCH 1/3] dt-bindings: phy: add YAML schema for cv1800-usb-phy driver bindings

On 2024/7/9 6:23, Inochi Amaoto wrote:
[......]

Quoted 9 lines

You patch is duplicated, I have sumbitted patches month ago and still needs some time to figure out the best topology. Phy driver belongs to syscon, which make things kind of complex.

https://lore.kernel.org/all/IA1PR20MB4953C1876484E149AA390DD5BB1D2@IA1PR20MB4953.namprd20.prod.outlook.com/#t

Regards,
Inochi

hi, Yao,

Thanks for your contribution.

Just FYI, we are archiving and tracking all PR status about sophgo products at https://github.com/sophgo/linux/wiki.

Regards,

Chen

author
#5 lore raw

Re: [PATCH 1/3] dt-bindings: phy: add YAML schema for cv1800-usb-phy driver bindings

In reply to Inochi Amaoto
Quoted 99 lines · Inochi Amaoto
Quoted 29 lines · Yao Zi

cv1800-usb-phy driver supports USB 2.0 phys integrated in Sophgo Cv1800/SG200x SoCs. Add YAML schema for its binding.

---
 .../bindings/phy/sophgo,cv1800-usb-phy.yaml   | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +14 -0
new file mode 100644
index 000000000000..0403d899e23b
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2019 BayLibre, SAS
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/sophgo,cv1800-usb-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sophgo CV1800 USB PHY
+
+maintainers:
+  - Yao Zi <[email protected]>
+
+properties:
+  compatible:

Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml line 24

Quoted 10 lines
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +10 -0
+    enum:
+      - sophgo,cv1800-usb-phy
+
+  reg:
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: phy
+      - const: pin

drop pin, cv1800 series does not support this.

Quoted 8 lines
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +8 -0
+
+  clocks:
+    maxItems: 4
+
+  clock-names:
+    items:
+      - const: apb
+      - const: 125m

Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml line 42

Quoted 10 lines
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +10 -0
+      - const: 33k
+      - const: 12m
+
+  "#phy-cells":
+    const: 0
+
+  dr_role:
+    enum:
+      - host
+      - device

cv181x series have otg support. For board with OTG, it should be properly handled.

Quoted 28 lines
Documentation/devicetree/bindings/phy/sophgo,cv1800-usb-phy.yaml new file +25 -0
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - clocks
+  - clock-names
+  - "#phy-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/sophgo,cv1800.h>
+    usb_phy: usb-phy@3006000 {
+        compatible = "sophgo,cv1800-usb-phy";
+        reg = <0x300600 0x60>, <0x3000048 0x4>;
+        reg-names = "phy", "pin";
+        clocks = <&clk CLK_APB_USB>,
+                 <&clk CLK_USB_125M>,
+                 <&clk CLK_USB_33K>,
+                 <&clk CLK_USB_12M>;
+        clock-names = "apb", "125m", "33k", "12m";
+        #phy-cells = <0>;
+    };
Signature · 1 line
2.45.2

You patch is duplicated, I have sumbitted patches month ago and still needs some time to figure out the best topology. Phy driver belongs to syscon, which make things kind of complex.

Quoted 1 line

https://lore.kernel.org/all/IA1PR20MB4953C1876484E149AA390DD5BB1D2@IA1PR20MB4953.namprd20.prod.outlook.com/#t

I didn't check that, sorry for the noise.

Best regards,
Yao Zi

author
#6 lore raw

PATCH 2/3 riscv: dts: sophgo: add nodes for USB phy and controller

In reply to Yao Zi

CV1800/SG200x SoCs integrate a USB 2.0 phy and a USB controller based on dwc2 IP. Add device tree nodes for these peripherals.

---
 arch/riscv/boot/dts/sophgo/cv18xx.dtsi | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
arch/riscv/boot/dts/sophgo/cv18xx.dtsi +23 -0
index 891932ae470f..06461f1f1986 100644
@@ -61,6 +61,18 @@ clk: clock-controller@3002000 {
 			#clock-cells = <1>;
 		};
 
+		usb_phy: usb-phy@3006000 {
+			compatible = "sophgo,cv1800-usb-phy";
+			reg = <0x3006000 0x60>, <0x3000048 0x4>;
+			reg-names = "phy", "pin";
+			clocks = <&clk CLK_APB_USB>,
+				 <&clk CLK_USB_125M>,
+				 <&clk CLK_USB_33K>,
+				 <&clk CLK_USB_12M>;
+			clock-names = "apb", "125m", "33k", "12m";
+			#phy-cells = <0>;
+		};
+
 		gpio0: gpio@3020000 {
 			compatible = "snps,dw-apb-gpio";
 			reg = <0x3020000 0x1000>;
@@ -297,6 +309,17 @@ sdhci0: mmc@4310000 {
 			status = "disabled";
 		};
 
+		usb_otg: usb@4340000 {
+			compatible = "sophgo,cv1800-usb";
+			reg = <0x4340000 0x10000>;
+			clocks = <&clk CLK_AXI4_USB>;
+			clock-names = "otg";
+			dr_mode = "otg";
+			interrupts = <30 IRQ_TYPE_LEVEL_HIGH>;
+			phys = <&usb_phy>;
+			phy-names = "usb2-phy";
+		};
+
 		plic: interrupt-controller@70000000 {
 			reg = <0x70000000 0x4000000>;
 			interrupts-extended = <&cpu0_intc 11>, <&cpu0_intc 9>;
Signature · 1 line
2.45.2
#7 lore raw

Re: [PATCH 2/3] riscv: dts: sophgo: add nodes for USB phy and controller

arch/riscv/boot/dts/sophgo/cv18xx.dtsi clk: clock-controller@3002000 { · line 72

Quoted 10 lines · Yao Zi
arch/riscv/boot/dts/sophgo/cv18xx.dtsi +9 -0
+		usb_phy: usb-phy@3006000 {
+			compatible = "sophgo,cv1800-usb-phy";
+			reg = <0x3006000 0x60>, <0x3000048 0x4>;
+			reg-names = "phy", "pin";
+			clocks = <&clk CLK_APB_USB>,
+				 <&clk CLK_USB_125M>,
+				 <&clk CLK_USB_33K>,
+				 <&clk CLK_USB_12M>;
+			clock-names = "apb", "125m", "33k", "12m";

Why are not you using dr_role property here?

Best regards,
Krzysztof

author
#8 lore raw

PATCH 3/3 phy: sophgo: add usb phy driver for Sophgo CV1800 SoCs

In reply to Yao Zi

This adds a new driver for USB2 phys integrated in Sophgo CV1800 and SG200x SoCs, which have the same design.

Most CV1800/SG200x boards have broken VBUS/ID detection, so we force ID status to be specified in the device tree. This phy also supports charger detection, which could be implemented later.

Unfortunately, there is no description about the phy in the public datasheet. The driver was written by reading Sophgo GPL kernel source and dumping registers on actual SG2002 devices.

---
 drivers/phy/Kconfig                 |   1 +
 drivers/phy/Makefile                |   1 +
 drivers/phy/sophgo/Kconfig          |  10 ++
 drivers/phy/sophgo/Makefile         |   2 +
 drivers/phy/sophgo/phy-cv1800-usb.c | 213 ++++++++++++++++++++++++++++
 5 files changed, 227 insertions(+)
 create mode 100644 drivers/phy/sophgo/Kconfig
 create mode 100644 drivers/phy/sophgo/Makefile
 create mode 100644 drivers/phy/sophgo/phy-cv1800-usb.c
drivers/phy/Kconfig +1 -0
index 787354b849c7..596b37ab3191 100644
@@ -92,6 +92,7 @@ source "drivers/phy/renesas/Kconfig"
 source "drivers/phy/rockchip/Kconfig"
 source "drivers/phy/samsung/Kconfig"
 source "drivers/phy/socionext/Kconfig"
+source "drivers/phy/sophgo/Kconfig"
 source "drivers/phy/st/Kconfig"
 source "drivers/phy/starfive/Kconfig"
 source "drivers/phy/sunplus/Kconfig"
drivers/phy/Makefile +1 -0
index 868a220ed0f6..7ff32f0ae08a 100644
@@ -31,6 +31,7 @@ obj-y					+= allwinner/	\
 					   rockchip/	\
 					   samsung/	\
 					   socionext/	\
+					   sophgo/	\
 					   st/		\
 					   starfive/	\
 					   sunplus/	\
drivers/phy/sophgo/Kconfig new file +10 -0
new file mode 100644
index 000000000000..6feb5795f1fc
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config PHY_SOPHGO_CV1800_USB
+	tristate "SOPHGO CV1800 USB 2.0 PHY driver"
+	depends on OF && (ARCH_SOPHGO || COMPILE_TEST)
+	select GENERIC_PHY
+	help
+	  Enable this to support the USB 2.0 PHY on Sophgo CV1800
+	  and SG200x SoCs.
+	  If unsure, say N.
drivers/phy/sophgo/Makefile new file +2 -0
new file mode 100644
index 000000000000..b4b9de0697e7
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_PHY_SOPHGO_CV1800_USB)	+= phy-cv1800-usb.o
drivers/phy/sophgo/phy-cv1800-usb.c new file +213 -0

213 lines not on this page · raw message

Signature · 1 line
2.45.2