Skip to contentSkip to conversation

riscv: sophgo: Add ethernet support for SG2042

PATCH In review Inochi Amaoto 4 participants 13 messages May 6, 2025 – May 7, 2025

Subsystems (7)
lore
Share & tools
lore

Inochi Amaoto

author maintainer
#0 lore raw

cover riscv: sophgo: Add ethernet support for SG2042

The ethernet controller of SG2042 is Synopsys DesignWare IP with tx clock. Add device id for it.

This patch can only be tested on a SG2042 x4 evb board, as pioneer does not expose this device.

Inochi Amaoto (4):
dt-bindings: net: sophgo,sg2044-dwmac: Add support for Sophgo SG2042
dwmac
net: stmmac: dwmac-sophgo: Add support for Sophgo SG2042 SoC
net: stmmac: platform: Add snps,dwmac-5.00a IP compatible string
riscv: dts: sophgo: add ethernet GMAC device for sg2042

 .../devicetree/bindings/net/snps,dwmac.yaml   |  4 ++
 .../bindings/net/sophgo,sg2044-dwmac.yaml     | 11 +++-
 arch/riscv/boot/dts/sophgo/sg2042.dtsi        | 62 +++++++++++++++++++
 .../ethernet/stmicro/stmmac/dwmac-sophgo.c    |  1 +
 .../ethernet/stmicro/stmmac/stmmac_platform.c |  1 +
 5 files changed, 76 insertions(+), 3 deletions(-)

--
2.49.0

author maintainer
#1 lore raw

PATCH 1/4 dt-bindings: net: sophgo,sg2044-dwmac: Add support for Sophgo SG2042 dwmac

The GMAC IP on SG2042 is a standard Synopsys DesignWare MAC (version 5.00a) with tx clock.

Add necessary compatible string for this device.

---
 Documentation/devicetree/bindings/net/snps,dwmac.yaml |  4 ++++
 .../devicetree/bindings/net/sophgo,sg2044-dwmac.yaml  | 11 ++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/net/snps,dwmac.yaml +4 -0
index 78b3030dc56d..f16b49da6dbf 100644
@@ -30,6 +30,7 @@ select:
           - snps,dwmac-4.00
           - snps,dwmac-4.10a
           - snps,dwmac-4.20a
+          - snps,dwmac-5.00a
           - snps,dwmac-5.10a
           - snps,dwmac-5.20
           - snps,dwmac-5.30a
@@ -97,11 +98,13 @@ properties:
         - snps,dwmac-4.00
         - snps,dwmac-4.10a
         - snps,dwmac-4.20a
+        - snps,dwmac-5.00a
         - snps,dwmac-5.10a
         - snps,dwmac-5.20
         - snps,dwmac-5.30a
         - snps,dwxgmac
         - snps,dwxgmac-2.10
+        - sophgo,sg2042-dwmac
         - sophgo,sg2044-dwmac
         - starfive,jh7100-dwmac
         - starfive,jh7110-dwmac
@@ -634,6 +637,7 @@ allOf:
                 - snps,dwmac-4.00
                 - snps,dwmac-4.10a
                 - snps,dwmac-4.20a
+                - snps,dwmac-5.00a
                 - snps,dwmac-5.10a
                 - snps,dwmac-5.20
                 - snps,dwmac-5.30a
Documentation/devicetree/bindings/net/sophgo,sg2044-dwmac.yaml +8 -3
index 4dd2dc9c678b..112b0b2a1524 100644
@@ -15,14 +15,19 @@ select:
       contains:
         enum:
           - sophgo,sg2044-dwmac
+          - sophgo,sg2042-dwmac
   required:
     - compatible
 
 properties:
   compatible:
-    items:
-      - const: sophgo,sg2044-dwmac
-      - const: snps,dwmac-5.30a
+    oneOf:
+      - items:
+          - const: sophgo,sg2042-dwmac
+          - const: snps,dwmac-5.00a
+      - items:
+          - const: sophgo,sg2044-dwmac
+          - const: snps,dwmac-5.30a
 
   reg:
     maxItems: 1
Signature · 1 line
2.49.0
author maintainer
#3 lore raw

PATCH 2/4 net: stmmac: dwmac-sophgo: Add support for Sophgo SG2042 SoC

In reply to Inochi Amaoto

Adds device id of the ethernet controller on the Sophgo SG2042 SoC.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c +1 -0
index 3303784cbbf8..3b7947a7a7ba 100644
@@ -54,6 +54,7 @@ static int sophgo_dwmac_probe(struct platform_device *pdev)
 }
 
 static const struct of_device_id sophgo_dwmac_match[] = {
+	{ .compatible = "sophgo,sg2042-dwmac" },
 	{ .compatible = "sophgo,sg2044-dwmac" },
 	{ /* sentinel */ }
 };
Signature · 1 line
2.49.0
author maintainer
#4 lore raw

PATCH 3/4 net: stmmac: platform: Add snps,dwmac-5.00a IP compatible string

In reply to Inochi Amaoto

Add "snps,dwmac-5.30a" compatible string for 5.00a version that can avoid to define some platform data in the glue layer.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +1 -0
index c73eff6a56b8..de3098a773ba 100644
@@ -410,6 +410,7 @@ static const char * const stmmac_gmac4_compats[] = {
 	"snps,dwmac-4.00",
 	"snps,dwmac-4.10a",
 	"snps,dwmac-4.20a",
+	"snps,dwmac-5.00a",
 	"snps,dwmac-5.10a",
 	"snps,dwmac-5.20",
 	"snps,dwmac-5.30a",
Signature · 1 line
2.49.0
author maintainer
#5 lore raw

PATCH 4/4 riscv: dts: sophgo: add ethernet GMAC device for sg2042

In reply to Inochi Amaoto

Add ethernet GMAC device node for the sg2042.

---
 arch/riscv/boot/dts/sophgo/sg2042.dtsi | 62 ++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
arch/riscv/boot/dts/sophgo/sg2042.dtsi +62 -0
index f61de4788475..886c13cef6ba 100644
@@ -543,6 +543,68 @@ uart0: serial@7040000000 {
 			status = "disabled";
 		};
 
+		gmac0: ethernet@7040026000 {
+			compatible = "sophgo,sg2042-dwmac", "snps,dwmac-5.00a";
+			reg = <0x70 0x40026000 0x0 0x4000>;
+			clocks = <&clkgen GATE_CLK_AXI_ETH0>,
+				 <&clkgen GATE_CLK_PTP_REF_I_ETH0>,
+				 <&clkgen GATE_CLK_TX_ETH0>;
+			clock-names = "stmmaceth", "ptp_ref", "tx";
+			dma-noncoherent;
+			interrupt-parent = <&intc>;
+			interrupts = <132 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "macirq";
+			resets = <&rstgen RST_ETH0>;
+			reset-names = "stmmaceth";
+			snps,multicast-filter-bins = <0>;
+			snps,perfect-filter-entries = <1>;
+			snps,aal;
+			snps,tso;
+			snps,txpbl = <32>;
+			snps,rxpbl = <32>;
+			snps,mtl-rx-config = <&gmac0_mtl_rx_setup>;
+			snps,mtl-tx-config = <&gmac0_mtl_tx_setup>;
+			snps,axi-config = <&gmac0_stmmac_axi_setup>;
+			status = "disabled";
+
+			mdio {
+				compatible = "snps,dwmac-mdio";
+				#address-cells = <1>;
+				#size-cells = <0>;
+			};
+
+			gmac0_mtl_rx_setup: rx-queues-config {
+				snps,rx-queues-to-use = <8>;
+				snps,rx-sched-wsp;
+				queue0 {};
+				queue1 {};
+				queue2 {};
+				queue3 {};
+				queue4 {};
+				queue5 {};
+				queue6 {};
+				queue7 {};
+			};
+
+			gmac0_mtl_tx_setup: tx-queues-config {
+				snps,tx-queues-to-use = <8>;
+				queue0 {};
+				queue1 {};
+				queue2 {};
+				queue3 {};
+				queue4 {};
+				queue5 {};
+				queue6 {};
+				queue7 {};
+			};
+
+			gmac0_stmmac_axi_setup: stmmac-axi-config {
+				snps,blen = <16 8 4 0 0 0 0>;
+				snps,wr_osr_lmt = <1>;
+				snps,rd_osr_lmt = <2>;
+			};
+		};
+
 		emmc: mmc@704002a000 {
 			compatible = "sophgo,sg2042-dwcmshc";
 			reg = <0x70 0x4002a000 0x0 0x1000>;
Signature · 1 line
2.49.0
Reviewed-by on v1 4/4
#6 lore raw

Re: [PATCH net-next 4/4] riscv: dts: sophgo: add ethernet GMAC device for sg2042

Quoted 68 lines · Inochi Amaoto

Add ethernet GMAC device node for the sg2042.

---
  arch/riscv/boot/dts/sophgo/sg2042.dtsi | 62 ++++++++++++++++++++++++++
  1 file changed, 62 insertions(+)
arch/riscv/boot/dts/sophgo/sg2042.dtsi +52 -0
index f61de4788475..886c13cef6ba 100644
@@ -543,6 +543,68 @@ uart0: serial@7040000000 {
  			status = "disabled";
  		};
 
+		gmac0: ethernet@7040026000 {
+			compatible = "sophgo,sg2042-dwmac", "snps,dwmac-5.00a";
+			reg = <0x70 0x40026000 0x0 0x4000>;
+			clocks = <&clkgen GATE_CLK_AXI_ETH0>,
+				 <&clkgen GATE_CLK_PTP_REF_I_ETH0>,
+				 <&clkgen GATE_CLK_TX_ETH0>;
+			clock-names = "stmmaceth", "ptp_ref", "tx";
+			dma-noncoherent;
+			interrupt-parent = <&intc>;
+			interrupts = <132 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "macirq";
+			resets = <&rstgen RST_ETH0>;
+			reset-names = "stmmaceth";
+			snps,multicast-filter-bins = <0>;
+			snps,perfect-filter-entries = <1>;
+			snps,aal;
+			snps,tso;
+			snps,txpbl = <32>;
+			snps,rxpbl = <32>;
+			snps,mtl-rx-config = <&gmac0_mtl_rx_setup>;
+			snps,mtl-tx-config = <&gmac0_mtl_tx_setup>;
+			snps,axi-config = <&gmac0_stmmac_axi_setup>;
+			status = "disabled";
+
+			mdio {
+				compatible = "snps,dwmac-mdio";
+				#address-cells = <1>;
+				#size-cells = <0>;
+			};
+
+			gmac0_mtl_rx_setup: rx-queues-config {
+				snps,rx-queues-to-use = <8>;
+				snps,rx-sched-wsp;
+				queue0 {};
+				queue1 {};
+				queue2 {};
+				queue3 {};
+				queue4 {};
+				queue5 {};
+				queue6 {};
+				queue7 {};
+			};
+
+			gmac0_mtl_tx_setup: tx-queues-config {
+				snps,tx-queues-to-use = <8>;
+				queue0 {};
+				queue1 {};
+				queue2 {};
+				queue3 {};
+				queue4 {};
+				queue5 {};
+				queue6 {};

arch/riscv/boot/dts/sophgo/sg2042.dtsi uart0: serial@7040000000 { · line 607

Quoted 10 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +10 -0
+				queue7 {};
+			};
+
+			gmac0_stmmac_axi_setup: stmmac-axi-config {
+				snps,blen = <16 8 4 0 0 0 0>;
+				snps,wr_osr_lmt = <1>;
+				snps,rd_osr_lmt = <2>;
+			};
+		};
+

LGTM.

Thanks,

Chen

Quoted 3 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +0 -0
  		emmc: mmc@704002a000 {
  			compatible = "sophgo,sg2042-dwcmshc";
  			reg = <0x70 0x4002a000 0x0 0x1000>;
#7 lore raw
In reply to Inochi Amaoto
Quoted 5 lines · Inochi Amaoto

The ethernet controller of SG2042 is Synopsys DesignWare IP with tx clock. Add device id for it.

This patch can only be tested on a SG2042 x4 evb board, as pioneer does not expose this device.

Do you have a patch for this EVB board? Ideally there should be a user added at the same time as support for a device.

Andrew

author maintainer
#8 lore raw
Quoted 11 lines · Andrew Lunn
Quoted 5 lines · Inochi Amaoto

The ethernet controller of SG2042 is Synopsys DesignWare IP with tx clock. Add device id for it.

This patch can only be tested on a SG2042 x4 evb board, as pioneer does not expose this device.

Do you have a patch for this EVB board? Ideally there should be a user added at the same time as support for a device.

Andrew

Yes, I have one for this device. And Han Gao told me that he will send the board patch for the evb board. So I only send the driver. And the fragment for the evb board is likes below, I think it is kind of trivial:

&gmac0 {
	phy-handle = <&phy0>;
	phy-mode = "rgmii-txid";
	status = "okay";

	mdio {
		phy0: phy@0 {
			compatible = "ethernet-phy-ieee802.3-c22";
			reg = <0>;
			reset-gpios = <&port0a 27 GPIO_ACTIVE_LOW>;
			reset-assert-us = <100000>;
			reset-deassert-us = <100000>;
		};
	};
};

Regards,
Inochi

#9 lore raw
Quoted 13 lines · Inochi Amaoto
Quoted 11 lines · Andrew Lunn
Quoted 5 lines · Inochi Amaoto

The ethernet controller of SG2042 is Synopsys DesignWare IP with tx clock. Add device id for it.

This patch can only be tested on a SG2042 x4 evb board, as pioneer does not expose this device.

Do you have a patch for this EVB board? Ideally there should be a user added at the same time as support for a device.

Andrew

Quoted 8 lines

Yes, I have one for this device. And Han Gao told me that he will send the board patch for the evb board. So I only send the driver. And the fragment for the evb board is likes below, I think it is kind of trivial:

&gmac0 {
	phy-handle = <&phy0>;
	phy-mode = "rgmii-txid";

And this is why i ask, because this is broken. For more information, please see:

https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

Andrew

author maintainer
#10 lore raw
Quoted 23 lines · Andrew Lunn
Quoted 13 lines · Inochi Amaoto
Quoted 11 lines · Andrew Lunn
Quoted 5 lines · Inochi Amaoto

The ethernet controller of SG2042 is Synopsys DesignWare IP with tx clock. Add device id for it.

This patch can only be tested on a SG2042 x4 evb board, as pioneer does not expose this device.

Do you have a patch for this EVB board? Ideally there should be a user added at the same time as support for a device.

Andrew

Quoted 8 lines

Yes, I have one for this device. And Han Gao told me that he will send the board patch for the evb board. So I only send the driver. And the fragment for the evb board is likes below, I think it is kind of trivial:

&gmac0 {
	phy-handle = <&phy0>;
	phy-mode = "rgmii-txid";
Quoted 6 lines

And this is why i ask, because this is broken. For more information, please see:

https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

Andrew

You are right, the right phy-mode is "rgmii-id", the delay is not added by the PCB. It seems to be better to ask for the vendor about the hardware design before copying params for vendor dts. Anyway, thanks for reviewing this.

Regards,
Inochi

#11 lore raw
Quoted 27 lines · Inochi Amaoto
Quoted 26 lines · Andrew Lunn
Quoted 13 lines · Inochi Amaoto
Quoted 11 lines · Andrew Lunn
Quoted 5 lines · Inochi Amaoto

The ethernet controller of SG2042 is Synopsys DesignWare IP with tx clock. Add device id for it.

This patch can only be tested on a SG2042 x4 evb board, as pioneer does not expose this device.

Do you have a patch for this EVB board? Ideally there should be a user added at the same time as support for a device.

Andrew

Quoted 8 lines

Yes, I have one for this device. And Han Gao told me that he will send the board patch for the evb board. So I only send the driver. And the fragment for the evb board is likes below, I think it is kind of trivial:

&gmac0 {
	phy-handle = <&phy0>;
	phy-mode = "rgmii-txid";

And this is why i ask, because this is broken. For more information, please see:

Quoted 8 lines
Quoted 3 lines

https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

Andrew

You are right, the right phy-mode is "rgmii-id", the delay is not added by the PCB. It seems to be better to ask for the vendor about the hardware design before copying params for vendor dts. Anyway, thanks for reviewing this.

Please do figure this out. Since you are adding a new compatible, you have a bit more flexibility. If the MAC driver is doing something wrong, you can change its behaviour based on this new compatible without breaking other users of the driver using other compatibles.

Andrew

author maintainer
#12 lore raw
Quoted 37 lines · Andrew Lunn
Quoted 27 lines · Inochi Amaoto
Quoted 26 lines · Andrew Lunn
Quoted 13 lines · Inochi Amaoto
Quoted 11 lines · Andrew Lunn
Quoted 5 lines · Inochi Amaoto

The ethernet controller of SG2042 is Synopsys DesignWare IP with tx clock. Add device id for it.

This patch can only be tested on a SG2042 x4 evb board, as pioneer does not expose this device.

Do you have a patch for this EVB board? Ideally there should be a user added at the same time as support for a device.

Andrew

Quoted 8 lines

Yes, I have one for this device. And Han Gao told me that he will send the board patch for the evb board. So I only send the driver. And the fragment for the evb board is likes below, I think it is kind of trivial:

&gmac0 {
	phy-handle = <&phy0>;
	phy-mode = "rgmii-txid";

And this is why i ask, because this is broken. For more information, please see:

Quoted 8 lines
Quoted 3 lines

https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

Andrew

You are right, the right phy-mode is "rgmii-id", the delay is not added by the PCB. It seems to be better to ask for the vendor about the hardware design before copying params for vendor dts. Anyway, thanks for reviewing this.

Quoted 5 lines

Please do figure this out. Since you are adding a new compatible, you have a bit more flexibility. If the MAC driver is doing something wrong, you can change its behaviour based on this new compatible without breaking other users of the driver using other compatibles.

Thanks, I will check it out. And adapt the driver if needed.

Regards,
Inochi