Skip to contentSkip to conversation

riscv: spacemit: Add ethernet support for K3

PATCH Superseded Inochi Amaoto 2 participants 8 messages Mar 12 – Mar 13

Subsystems (8)

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Inochi Amaoto

author maintainer
#0 lore raw

v9 cover riscv: spacemit: Add ethernet support for K3

Add initial support for ethernet controller of the Spacemit K3 SoC. This ethernet controller is almost a standard Synopsys DesignWare MAC (version 5.40a). This controller require a syscon device to configure some basic features, like interface type and internal delay.

Change from v8:
- https://lore.kernel.org/netdev/[email protected]
patch 2:
1. Apply Russell's tag.
patch 3:
1. reverse the order of the local variable to make it "reverse christmas tree" for function spacemit_dwmac_update_irq_config() and function spacemit_set_phy_intf_sel()
2. Apply Russell's tag
patch 4:
1. Add MAINTAINERS entry

Change from v7:
- https://lore.kernel.org/netdev/[email protected]
patch 3:
1. Remove unused parameter in spacemit_dwmac_fix_delay().

Change from v6:
- https://lore.kernel.org/netdev/[email protected]
patch 1:
1. Drop the extra blank line at the last

Change from v5:
- https://lore.kernel.org/netdev/[email protected]
patch 3:
1. fix error from checkpatch

Change from v4:
- https://lore.kernel.org/netdev/[email protected]
patch 1:
1 Apply Rob's tag.
2 Adjust clock description according to Russell's suggestion. patch 3:
1. Add set_phy_intf_sel() and get_interfaces() hook, suggested by Russell.

Change from v3:
- https://lore.kernel.org/netdev/[email protected]
patch 1:
1. fix the uncorrect compatible string postion
patch 3:
1. add "CTRL_" prefix to all ctrl register definition
2. only use delay config 0 to calculate delay code.
3. fix typo in the comment

Change from v2:
- https://lore.kernel.org/netdev/[email protected]
patch 1:
1. remove not needed compatible for select
2. drop empty line in "spacemit,apmu" properties
3. add spacemit,apmu properties to required.
patch 3:
1. remove misused phy_fix_phy_mode_for_mac_delays.
2. use local tx clock instead of the clk_tx_i in the dwmac.

Change from v1:
- https://lore.kernel.org/netdev/[email protected]
patch 1:
1. remove phy clock
patch 3:
1. improve comment and include something special about Spacmit K3 dwmac
2. reorder the included file
3. fix wrong delay macro used in spacemit_dwmac_set_delay.
4. add check for maximum supported delay.
5. use DIV_ROUND_CLOSEST to calculate best delay configuration.
6. use assign for the ctrl register initial value.
7. fix input when calling of_property_read_u32().

Inochi Amaoto (4):
dt-bindings: net: Add support for Spacemit K3 dwmac
net: stmmac: platform: Add snps,dwmac-5.40a IP compatible string
net: stmmac: Add glue layer for Spacemit K3 SoC
MAINTAINERS: add entry for SpacemiT DWMAC glue layer

 .../devicetree/bindings/net/snps,dwmac.yaml   |   2 +
 .../bindings/net/spacemit,k3-dwmac.yaml       | 102 ++++++++
 MAINTAINERS                                   |   6 +
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  12 +
 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 .../ethernet/stmicro/stmmac/dwmac-spacemit.c  | 227 ++++++++++++++++++
 .../ethernet/stmicro/stmmac/stmmac_platform.c |   1 +
 7 files changed, 351 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c

--
2.53.0

author maintainer
#1 lore raw

PATCH v9 1/4 dt-bindings: net: Add support for Spacemit K3 dwmac

The GMAC IP on Spacemit K3 is almost a standard Synopsys DesignWare MAC (version 5.40a) with some extra clock.

Add necessary compatible string for this device.

---
 .../devicetree/bindings/net/snps,dwmac.yaml   |   2 +
 .../bindings/net/spacemit,k3-dwmac.yaml       | 102 ++++++++++++++++++
 2 files changed, 104 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml
Documentation/devicetree/bindings/net/snps,dwmac.yaml +2 -0
index 38bc34dc4f09..98ebb6276bc6 100644
@@ -109,6 +109,7 @@ properties:
         - snps,dwmac-5.10a
         - snps,dwmac-5.20
         - snps,dwmac-5.30a
+        - snps,dwmac-5.40a
         - snps,dwxgmac
         - snps,dwxgmac-2.10
         - sophgo,sg2042-dwmac
@@ -656,6 +657,7 @@ allOf:
                 - snps,dwmac-5.10a
                 - snps,dwmac-5.20
                 - snps,dwmac-5.30a
+                - snps,dwmac-5.40a
                 - snps,dwxgmac
                 - snps,dwxgmac-2.10
                 - st,spear600-gmac
Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml new file +102 -0

102 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#2 lore raw

Re: [net-next,v9,1/4] dt-bindings: net: Add support for Spacemit K3 dwmac

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
dt-bindings: net: Add support for Spacemit K3 dwmac

The GMAC IP on Spacemit K3 is almost a standard Synopsys DesignWare MAC (version 5.40a) with some extra clock. This patch adds the necessary compatible string for this device, along with a new binding document defining the required properties.

Quoted 12 lines
Documentation/devicetree/bindings/net/snps,dwmac.yaml +1 -0
index 38bc34dc4f09..98ebb6276bc6 100644
@@ -109,6 +109,7 @@ properties:
         - snps,dwmac-5.10a
         - snps,dwmac-5.20
         - snps,dwmac-5.30a
+        - snps,dwmac-5.40a
         - snps,dwxgmac
         - snps,dwxgmac-2.10
         - sophgo,sg2042-dwmac

[ ... ]

Documentation/devicetree/bindings/net/snps,dwmac.yaml allOf: · line 663

Quoted 8 lines
Documentation/devicetree/bindings/net/snps,dwmac.yaml +1 -0
@@ -656,6 +657,7 @@ allOf:
                 - snps,dwmac-5.10a
                 - snps,dwmac-5.20
                 - snps,dwmac-5.30a
+                - snps,dwmac-5.40a
                 - snps,dwxgmac
                 - snps,dwxgmac-2.10
                 - st,spear600-gmac

Is snps,dwmac-5.40a missing from the select block? The binding document has a comment at lines 14-17 stating:

# Select every compatible, including the deprecated ones. This way, we # will be able to report a warning when we have that compatible, since # we will validate the node thanks to the select.

Every other snps,dwmac-* version from 3.40a through 5.30a appears in all three
locations: the select block (lines 19-43), the properties.compatible enum (lines 95-118), and the allOf conditional block (lines 643-673). However, snps,dwmac-5.40a only appears in the properties.compatible enum and the allOf block.

Without the entry in the select block, a device tree node using 'snps,dwmac-5.40a' as a standalone compatible (without a vendor-specific first entry like 'spacemit,k3-dwmac') would not be selected by this schema for validation.

[ ... ]

author maintainer
#3 lore raw

PATCH v9 2/4 net: stmmac: platform: Add snps,dwmac-5.40a IP compatible string

In reply to Inochi Amaoto

Add compatible string for 5.40a 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 5c9fd91a1db9..02303a808fb5 100644
@@ -396,6 +396,7 @@ static const char * const stmmac_gmac4_compats[] = {
 	"snps,dwmac-5.10a",
 	"snps,dwmac-5.20",
 	"snps,dwmac-5.30a",
+	"snps,dwmac-5.40a",
 	NULL
 };
 
Signature · 1 line
2.53.0
author maintainer
#4 lore raw

PATCH v9 3/4 net: stmmac: Add glue layer for Spacemit K3 SoC

In reply to Inochi Amaoto

The ethernet controller on Spacemit K3 SoC is Synopsys DesignWare MAC (version 5.40a), with the following special points:
1. The rate of the tx clock line is auto changed when the mac speed rate is changed, and no need for changing the input tx clock.
2. This controller require a extra syscon device to configure the interface type, enable wake up interrupt and delay configuration if needed.

Add Spacemit dwmac driver support on the Spacemit K3 SoC.

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  12 +
 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 .../ethernet/stmicro/stmmac/dwmac-spacemit.c  | 227 ++++++++++++++++++
 3 files changed, 240 insertions(+)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c
drivers/net/ethernet/stmicro/stmmac/Kconfig +12 -0
index 07088d03dbab..d3a6ab7383fc 100644
@@ -216,6 +216,18 @@ config DWMAC_SOPHGO
 	  for the stmmac device driver. This driver is used for the
 	  ethernet controllers on various Sophgo SoCs.
 
+config DWMAC_SPACEMIT
+	tristate "Spacemit dwmac support"
+	depends on OF && (ARCH_SPACEMIT || COMPILE_TEST)
+	select MFD_SYSCON
+	default m if ARCH_SPACEMIT
+	help
+	  Support for ethernet controllers on Spacemit RISC-V SoCs
+
+	  This selects the Spacemit platform specific glue layer support
+	  for the stmmac device driver. This driver is used for the
+	  Spacemit K3 ethernet controllers.
+
 config DWMAC_STARFIVE
 	tristate "StarFive dwmac support"
 	depends on OF && (ARCH_STARFIVE || COMPILE_TEST)
drivers/net/ethernet/stmicro/stmmac/Makefile +1 -0
index c9263987ef8d..945c5354eced 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_DWMAC_RZN1)	+= dwmac-rzn1.o
 obj-$(CONFIG_DWMAC_S32)		+= dwmac-s32.o
 obj-$(CONFIG_DWMAC_SOCFPGA)	+= dwmac-altr-socfpga.o
 obj-$(CONFIG_DWMAC_SOPHGO)	+= dwmac-sophgo.o
+obj-$(CONFIG_DWMAC_SPACEMIT)	+= dwmac-spacemit.o
 obj-$(CONFIG_DWMAC_STARFIVE)	+= dwmac-starfive.o
 obj-$(CONFIG_DWMAC_STI)		+= dwmac-sti.o
 obj-$(CONFIG_DWMAC_STM32)	+= dwmac-stm32.o
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +227 -0

227 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#5 lore raw

Re: [PATCH net-next v9 3/4] net: stmmac: Add glue layer for Spacemit K3 SoC

Some nit picks only to be addressed in case the AI complaint on patch 1 is legit..

drivers/net/ethernet/stmicro/stmmac/Kconfig config DWMAC_SOPHGO · line 223

Quoted 5 lines · On Thu, 12 Mar 2026 09:22:25 +0800 Inochi Amaoto wrote:
drivers/net/ethernet/stmicro/stmmac/Kconfig +5 -0
+config DWMAC_SPACEMIT
+	tristate "Spacemit dwmac support"
+	depends on OF && (ARCH_SPACEMIT || COMPILE_TEST)
+	select MFD_SYSCON
+	default m if ARCH_SPACEMIT

I know other STMMAC sub-drivers do it but isn't the defconfig for the platform the right place to add this sort of default?

drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 182

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +6 -0
+	apmu = syscon_regmap_lookup_by_phandle_args(pdev->dev.of_node,
+						    "spacemit,apmu", 2,
+						    offset);
+	if (IS_ERR(apmu))
+		return dev_err_probe(dev, PTR_ERR(apmu),
+				"Failed to get apmu regmap\n");

looks mis-aligned

author maintainer
#6 lore raw

Re: [PATCH net-next v9 3/4] net: stmmac: Add glue layer for Spacemit K3 SoC

Quoted 13 lines · Jakub Kicinski

Some nit picks only to be addressed in case the AI complaint on patch 1 is legit..

drivers/net/ethernet/stmicro/stmmac/Kconfig config DWMAC_SOPHGO · line 223

Quoted 5 lines · On Thu, 12 Mar 2026 09:22:25 +0800 Inochi Amaoto wrote:
drivers/net/ethernet/stmicro/stmmac/Kconfig +5 -0
+config DWMAC_SPACEMIT
+	tristate "Spacemit dwmac support"
+	depends on OF && (ARCH_SPACEMIT || COMPILE_TEST)
+	select MFD_SYSCON
+	default m if ARCH_SPACEMIT

I know other STMMAC sub-drivers do it but isn't the defconfig for the platform the right place to add this sort of default?

Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 182

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +6 -0
+	apmu = syscon_regmap_lookup_by_phandle_args(pdev->dev.of_node,
+						    "spacemit,apmu", 2,
+						    offset);
+	if (IS_ERR(apmu))
+		return dev_err_probe(dev, PTR_ERR(apmu),
+				"Failed to get apmu regmap\n");

looks mis-aligned

Yes, that's true. I will fix this.

Regards,
Inochi

author maintainer
#7 lore raw

PATCH v9 4/4 MAINTAINERS: add entry for SpacemiT DWMAC glue layer

In reply to Inochi Amaoto

Add a MAINTAINERS entry for the SpacemiT DWMAC glue layer driver and its DT binding.

---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
index 2265e2c9bfbe..dd72d26ac837 100644
@@ -24834,6 +24834,12 @@ W:	https://linuxtv.org
 Q:	http://patchwork.linuxtv.org/project/linux-media/list/
 F:	drivers/media/dvb-frontends/sp2*
 
+SPACEMIT DWMAC GLUE LAYER
+M:	Inochi Amaoto <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml
+F:	drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c
+
 SPACEMIT K1 I2C DRIVER
 M:	Troy Mitchell <[email protected]>
 S:	Maintained
Signature · 1 line
2.53.0