Skip to contentSkip to conversation

board: sophgo: milkv_duo: Add ethernet support for Milk-V Duo board

PATCH In review Kongyang Liu 2 participants 5 messages Apr 20, 2024 – May 1, 2024

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

v2 cover board: sophgo: milkv_duo: Add ethernet support for Milk-V Duo board

This series add init code for cv1800b ethernet phy and enable ethernet support for Sophgo Milk-V Duo board.

In cv1800b, as the PHY register phy_id being initialized to 0, it is necessary to initialize the PHY before the ethernet driver initialization. Therefore, the initialization code is placed in the board_init function.

For the Linux kernel, due to the presence of a hibernation mechanism, whether the phy id will be reset to 0 after hibernation and how to reassign it thereafter remains an issue to consider. Once this issue is resolved, the Ethernet driver for the Milk-V Duo will be sent to the kernel.

Changes in v2:
- Change compatible
- Add clocks and interrupt properties.

Kongyang Liu (3):
board: milkv_duo: Add init code for Milk-V Duo ethernet
riscv: dts: sophgo: Add ethernet node
configs: milkv_duo: Add ethernet configs

 arch/riscv/dts/cv1800b-milkv-duo.dts |  7 ++-
 arch/riscv/dts/cv18xx.dtsi           | 23 ++++++++
 board/sophgo/milkv_duo/Makefile      |  3 +-
 board/sophgo/milkv_duo/board.c       |  4 ++
 board/sophgo/milkv_duo/ethernet.c    | 79 ++++++++++++++++++++++++++++
 board/sophgo/milkv_duo/ethernet.h    | 11 ++++
 configs/milkv_duo_defconfig          |  4 ++
 drivers/net/designware.c             |  1 +
 8 files changed, 130 insertions(+), 2 deletions(-)
 create mode 100644 board/sophgo/milkv_duo/ethernet.c
 create mode 100644 board/sophgo/milkv_duo/ethernet.h
Signature · 1 line
2.41.0
#1 lore raw

PATCH v2 1/3 board: milkv_duo: Add init code for Milk-V Duo ethernet

Initialize register in cv1800b ethernet phy to make it compatible with generic phy driver

---

(no changes since v1)

 board/sophgo/milkv_duo/Makefile   |  3 +-
 board/sophgo/milkv_duo/board.c    |  4 ++
 board/sophgo/milkv_duo/ethernet.c | 79 +++++++++++++++++++++++++++++++
 board/sophgo/milkv_duo/ethernet.h | 11 +++++
 drivers/net/designware.c          |  1 +
 5 files changed, 97 insertions(+), 1 deletion(-)
 create mode 100644 board/sophgo/milkv_duo/ethernet.c
 create mode 100644 board/sophgo/milkv_duo/ethernet.h
board/sophgo/milkv_duo/Makefile +2 -1
index a087013f5c..d0525eba85 100644
@@ -2,4 +2,5 @@
 #
 # Copyright (c) 2024, Kongyang Liu <[email protected]>
 
-obj-y := board.o
+obj-y += board.o
+obj-$(CONFIG_NET) += ethernet.o
board/sophgo/milkv_duo/board.c +4 -0
index eaa47be173..311576fe1c 100644
@@ -3,7 +3,11 @@
  * Copyright (c) 2024, Kongyang Liu <[email protected]>
  */
 
+#include "ethernet.h"
+
 int board_init(void)
 {
+	if (IS_ENABLED(CONFIG_NET))
+		cv1800b_ephy_init();
 	return 0;
 }
board/sophgo/milkv_duo/ethernet.c new file +79 -0

79 lines not on this page · raw message

board/sophgo/milkv_duo/ethernet.h new file +11 -0
new file mode 100644
index 0000000000..7b21f1b0f6
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2024, Kongyang Liu <[email protected]>
+ */
+
+#ifndef __CV1800B_ETHERNET_H
+#define __CV1800B_ETHERNET_H
+
+void cv1800b_ephy_init(void);
+
+#endif
drivers/net/designware.c +1 -0
index 4c1642b29a..682045cea2 100644
@@ -871,6 +871,7 @@ static const struct udevice_id designware_eth_ids[] = {
 	{ .compatible = "amlogic,meson6-dwmac" },
 	{ .compatible = "st,stm32-dwmac" },
 	{ .compatible = "snps,arc-dwmac-3.70a" },
+	{ .compatible = "sophgo,cv1800b-dwmac" },
 	{ }
 };
 
Signature · 1 line
2.41.0
#2 lore raw

PATCH v2 2/3 riscv: dts: sophgo: Add ethernet node

In reply to Kongyang Liu

Add ethernet node for cv1800b SoC

---

Changes in v2:
- Change compatible
- Add clocks and interrupt properties.

 arch/riscv/dts/cv1800b-milkv-duo.dts |  7 ++++++-
 arch/riscv/dts/cv18xx.dtsi           | 23 +++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
arch/riscv/dts/cv1800b-milkv-duo.dts +6 -1
index 94e64ddce8..c1e6611e33 100644
@@ -29,6 +29,11 @@
 	};
 };
 
+&ethernet0 {
+	status = "okay";
+	phy-mode = "rmii";
+};
+
 &osc {
 	clock-frequency = <25000000>;
 };
@@ -39,7 +44,7 @@
 	no-1-8-v;
 	no-mmc;
 	no-sdio;
-};
+}
 
 &uart0 {
 	status = "okay";
arch/riscv/dts/cv18xx.dtsi +23 -0
index ec99c4deeb..c95bac77be 100644
@@ -50,6 +50,20 @@
 		clock-frequency = <375000000>;
 		clock-output-names = "sdhci_clk";
 		#clock-cells = <0>;
+	}
+
+	eth_csrclk: eth-csrclk {
+		compatible = "fixed-clock";
+		clock-frequency = <250000000>;
+		clock-output-names = "eth_csrclk";
+		#clock-cells = <0x0>;
+	};
+
+	eth_ptpclk: eth-ptpclk {
+		compatible = "fixed-clock";
+		clock-frequency = <50000000>;
+		clock-output-names = "eth_ptpclk";
+		#clock-cells = <0x0>;
 	};
 
 	soc {
@@ -138,6 +152,15 @@
 			};
 		};
 
+		ethernet0: ethernet@4070000 {
+			compatible = "sophgo,cv1800b-dwmac";
+			reg = <0x04070000 0x10000>;
+			interrupts = <31 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&eth_csrclk>, <&eth_ptpclk>;
+			clock-names = "stmmaceth", "ptp_ref";
+			status = "disabled";
+		};
+
 		uart0: serial@4140000 {
 			compatible = "snps,dw-apb-uart";
 			reg = <0x04140000 0x100>;
Signature · 1 line
2.41.0
Reviewed-by on v2 2/3
#3 lore raw

Re: [PATCH v2 2/3] riscv: dts: sophgo: Add ethernet node

Quoted 5 lines · Kongyang Liu

Add ethernet node for cv1800b SoC

---

Quoted 7 lines

Changes in v2:
- Change compatible
- Add clocks and interrupt properties.

 arch/riscv/dts/cv1800b-milkv-duo.dts |  7 ++++++-
 arch/riscv/dts/cv18xx.dtsi           | 23 +++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
#4 lore raw

PATCH v2 3/3 configs: milkv_duo: Add ethernet configs

In reply to Kongyang Liu

Add configs related to ethernet and ethernet boot command for Sophgo Milk-V Duo board

---

(no changes since v1)

 configs/milkv_duo_defconfig | 4 ++++
 1 file changed, 4 insertions(+)
configs/milkv_duo_defconfig +4 -0
index e8413d7aa9..f66c4c5358 100644
@@ -19,14 +19,18 @@ CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="milkv_duo# "
 CONFIG_CMD_MMC=y
 CONFIG_CMD_PART=y
+CONFIG_CMD_DHCP=y
+CONFIG_CMD_PXE=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
 CONFIG_ENV_OVERWRITE=y
+CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_MMC=y
 CONFIG_MMC_IO_VOLTAGE=y
 CONFIG_MMC_UHS_SUPPORT=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_ADMA=y
 CONFIG_MMC_SDHCI_CV1800B=y
+CONFIG_ETH_DESIGNWARE=y
 CONFIG_SYS_NS16550=y
 CONFIG_SYS_NS16550_MEM32=y
Signature · 1 line
2.41.0