Skip to contentSkip to conversation

net: add SpacemiT K1 EMAC support

PATCH New Zixian Zeng 1 participant 3 messages Nov 30

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover net: add SpacemiT K1 EMAC support

This series adds support for the Ethernet MACs integrated in the SpacemiT K1 SoC, which includes adding a k1_emac driver with MDIO and PHYLIB support for RGMII and RMII operation, enabling it in the k1 defconfig.

The k1_emac driver in series draws upon Vivian Wang's work [1]. To make it simple and working, driver which using small ring-buffers operates primarily on polling and only implements basic functions.

Tested on both Banana Pi F3 Ethernet ports with RTL8211F PHYs at 1000 Mbps full duplex, and tested command: dhcp, ping, tftp, etc.

[1]: https://lore.kernel.org/all/[email protected]/

---
Changes in v4:
- Use direct descriptor indexing and remove redundant cache barriers.
- Drop initial packet buffer zeroing and bulk flushes; document why RX buffers are flushed before being returned to DMA.
- Use a fixed TX completion retry count rather than timeout.
- Drop return value checks for MMIO regmap updates and duplicate interrupt masking in stop().
- Return -EOPNOTSUPP for recognized but unsupported PHY modes.
- Link to v3: https://patch.msgid.link/[email protected]

Changes in v3:
- Add the "spacemit" keyword in both patch subjects.
- Patch 1: Remove PHY_GIGE dependency of SPACEMIT_K1_EMAC (suggested by Yixun Lan).
- Patch 1: Add Tested-by from Yixun Lan.
- Patch 2: Enable CONFIG_PHY_GIGE explicitly.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Patch 1: Validate the full DMA range, not only the start address, in k1_emac_dma32() (suggested by Dave Klotz)
- Patch 1: Add Tested-by from Dave Klotz
- Drop the MAINTAINERS patch, as the top-level "RISC-V SPACEMIT" entry already covers the driver via its N:/K: patterns (suggested by Yixun Lan)
- Link to v1: https://patch.msgid.link/[email protected]

To: [email protected]
To: Hung-Chun Tseng <[email protected]>
To: [email protected]
Cc: Tom Rini <[email protected]>
Cc: Jerome Forissier <[email protected]>
Cc: Yixun Lan <[email protected]>
Cc: Julien Stephan <[email protected]>
Cc: David Lechner <[email protected]>
Cc: Johan Jonker <[email protected]>
Cc: James Hilliard <[email protected]>
Cc: Zixian Zeng <[email protected]>
Cc: Eric Chung <[email protected]>
Cc: Guodong Xu <[email protected]>
Cc: Raymond Mao <[email protected]>
Cc: Yao Zi <[email protected]>

---
Zixian Zeng (2):
net: spacemit: k1: add Ethernet MAC driver
configs: spacemit: k1: enable Ethernet support

 configs/spacemit_k1_defconfig  |   7 +
 drivers/net/Kconfig            |   1 +
 drivers/net/Makefile           |   1 +
 drivers/net/spacemit/Kconfig   |  14 +
 drivers/net/spacemit/Makefile  |   3 +
 drivers/net/spacemit/k1_emac.c | 920 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 946 insertions(+)

---
base-commit: ffdf122644c936510b74a26390b694ed4cdfa1c6
change-id: 20260926-b4-k1-emac-fa5f2b146f38

Best regards,

Signature · 1 line
Zixian Zeng <[email protected]>
#1 lore raw

PATCH v4 1/2 net: spacemit: k1: add Ethernet MAC driver

Add Ethernet MAC driver support for the SpacemiT K1 SoC. The driver supports RGMII and RMII interfaces, synchronous transmission, and exposes the integrated MDIO controller through the MDIO uclass.

The register definitions, descriptor layout, MDIO protocol, RGMII delay line handling and hardware initialisation sequences are derived from the mainline Linux commit bfec6d7f2001 (net: spacemit: Add K1 Ethernet MAC).

---
 drivers/net/Kconfig            |   1 +
 drivers/net/Makefile           |   1 +
 drivers/net/spacemit/Kconfig   |  14 +
 drivers/net/spacemit/Makefile  |   3 +
 drivers/net/spacemit/k1_emac.c | 920 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 939 insertions(+)
drivers/net/Kconfig +1 -0
index 72b77064638..6d71f2df01a 100644
@@ -1157,6 +1157,7 @@ config MDIO_MUX_MESON_GXL
 source "drivers/net/phy/Kconfig"
 source "drivers/net/pfe_eth/Kconfig"
 source "drivers/net/fsl-mc/Kconfig"
+source "drivers/net/spacemit/Kconfig"
 
 endif # NETDEVICES
 
drivers/net/Makefile +1 -0
index b4076206e34..bb60ce8db3c 100644
@@ -109,6 +109,7 @@ obj-$(CONFIG_SJA1105) += sja1105.o
 obj-$(CONFIG_SMC911X) += smc911x.o
 obj-$(CONFIG_SNI_AVE) += sni_ave.o
 obj-$(CONFIG_SNI_NETSEC) += sni_netsec.o
+obj-$(CONFIG_SPACEMIT_K1_EMAC) += spacemit/
 obj-$(CONFIG_SUN4I_EMAC) += sunxi_emac.o
 obj-$(CONFIG_SUN8I_EMAC) += sun8i_emac.o
 obj-$(CONFIG_TSEC_ENET) += tsec.o fsl_mdio.o
drivers/net/spacemit/Kconfig new file +14 -0
new file mode 100644
index 00000000000..76784eff269
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+config SPACEMIT_K1_EMAC
+	bool "SpacemiT K1 Ethernet MAC support"
+	depends on TARGET_SPACEMIT_K1
+	select DM_DMA
+	select DM_ETH_PHY
+	select DM_MDIO
+	select PHYLIB
+	help
+	  Enable support for the Ethernet MAC integrated in the SpacemiT K1.
+	  The controller supports 10/100/1000 Mbps links through RGMII and
+	  10/100 Mbps links through RMII. Its internal MDIO controller is
+	  exposed through the driver-model MDIO uclass.
drivers/net/spacemit/Makefile new file +3 -0
new file mode 100644
index 00000000000..ca595ddfc9a
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+obj-$(CONFIG_SPACEMIT_K1_EMAC) += k1_emac.o
drivers/net/spacemit/k1_emac.c new file +920 -0

920 lines not on this page · raw message

Signature · 1 line
2.56.0
#2 lore raw

PATCH v4 2/2 configs: spacemit: k1: enable Ethernet support

In reply to Zixian Zeng

Enable the K1 Ethernet MAC, Realtek PHY driver, and network commands.

---
 configs/spacemit_k1_defconfig | 7 +++++++
 1 file changed, 7 insertions(+)
configs/spacemit_k1_defconfig +7 -0
index d9cb6c8cebc..ce0ec4e80f7 100644
@@ -53,6 +53,7 @@ CONFIG_SPL_POWER=y
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_SYS_SPI_U_BOOT_OFFS=0x000a0000
 CONFIG_HUSH_PARSER=y
+CONFIG_ID_EEPROM=y
 CONFIG_CMD_TLV_EEPROM=y
 CONFIG_SPL_CMD_TLV_EEPROM=y
 CONFIG_CMD_MEMINFO=y
@@ -64,6 +65,12 @@ CONFIG_CMD_SPI=y
 CONFIG_CMD_USB=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_FAT=y
+CONFIG_CMD_DHCP=y
+CONFIG_CMD_MII=y
+CONFIG_CMD_PING=y
+CONFIG_SPACEMIT_K1_EMAC=y
+CONFIG_PHY_REALTEK=y
+CONFIG_PHY_GIGE=y
 CONFIG_EFI_PARTITION=y
 CONFIG_OF_UPSTREAM=y
 CONFIG_OF_LIST="spacemit/k1-bananapi-f3 spacemit/k1-musepi-pro"
Signature · 1 line
2.56.0