From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: JohnTheCoolingFan <ivan8215145640@gmail.com>
Date: Fri, 9 Aug 2024 07:14:37 +0000
Subject: Allwinner H616 DTS: Enable internal PHY (EMAC1)

Signed-off-by: JohnTheCoolingFan <ivan8215145640@gmail.com>
---
 arch/arm/dts/sun50i-h616.dtsi         | 27 +++++++++
 drivers/net/sun8i_emac.c              |  7 +++
 drivers/pinctrl/sunxi/pinctrl-sunxi.c |  1 +
 3 files changed, 35 insertions(+)

diff --git a/arch/arm/dts/sun50i-h616.dtsi b/arch/arm/dts/sun50i-h616.dtsi
index 46651703e9b..87d62cb1d3f 100644
--- a/arch/arm/dts/sun50i-h616.dtsi
+++ b/arch/arm/dts/sun50i-h616.dtsi
@@ -207,10 +207,18 @@
 				function = "mmc2";
 				drive-strength = <40>;
 				bias-pull-up;
 			};
 
+	        /omit-if-no-ref/
+	        rmii_pins: rmii-pins {
+	            pins = "PA0", "PA1", "PA2", "PA3", "PA4",
+			   "PA5", "PA6", "PA7", "PA8", "PA9";
+	            function = "emac1";
+	            drive-strength = <40>;
+	        };
+
 			/omit-if-no-ref/
 			spi0_pins: spi0-pins {
 				pins = "PC0", "PC2", "PC4";
 				function = "spi0";
 			};
@@ -502,10 +510,29 @@
 				#address-cells = <1>;
 				#size-cells = <0>;
 			};
 		};
 
+		emac1: ethernet@5030000 {
+			compatible = "allwinner,sun50i-h616-emac1";
+			syscon = <&syscon 1>;
+			reg = <0x05030000 0x10000>;
+			interrupts = <GIC_SPI 15 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "macirq";
+			resets = <&ccu RST_BUS_EMAC1>;
+			reset-names = "stmmaceth";
+			clocks = <&ccu CLK_BUS_EMAC1>;
+			clock-names = "stmmaceth";
+			status = "disabled";
+
+			mdio1: mdio {
+				compatible = "snps,dwmac-mdio";
+				#address-cells = <1>;
+				#size-cells = <0>;
+			};
+		};
+
 		usbotg: usb@5100000 {
 			compatible = "allwinner,sun50i-h616-musb",
 				     "allwinner,sun8i-h3-musb";
 			reg = <0x05100000 0x0400>;
 			clocks = <&ccu CLK_BUS_OTG>;
diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c
index a12f7e32e8f..98804029719 100644
--- a/drivers/net/sun8i_emac.c
+++ b/drivers/net/sun8i_emac.c
@@ -904,10 +904,15 @@ static const struct emac_variant emac_variant_a64 = {
 static const struct emac_variant emac_variant_h6 = {
 	.syscon_offset		= 0x30,
 	.support_rmii		= true,
 };
 
+static const struct emac_variant emac_variant_h616_1 = {
+	.syscon_offset      = 0x34,
+	.support_rmii       = true,
+};
+
 static const struct udevice_id sun8i_emac_eth_ids[] = {
 	{ .compatible = "allwinner,sun8i-a83t-emac",
 	  .data = (ulong)&emac_variant_a83t },
 	{ .compatible = "allwinner,sun8i-h3-emac",
 	  .data = (ulong)&emac_variant_h3 },
@@ -915,10 +920,12 @@ static const struct udevice_id sun8i_emac_eth_ids[] = {
 	  .data = (ulong)&emac_variant_r40 },
 	{ .compatible = "allwinner,sun50i-a64-emac",
 	  .data = (ulong)&emac_variant_a64 },
 	{ .compatible = "allwinner,sun50i-h6-emac",
 	  .data = (ulong)&emac_variant_h6 },
+	{ .compatible = "allwinner,sun50i-h616-emac1",
+	  .data = (ulong)&emac_variant_h616_1 },
 	{ }
 };
 
 U_BOOT_DRIVER(eth_sun8i_emac) = {
 	.name   = "eth_sun8i_emac",
diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index 37ea93715d1..a9c3bf05702 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -735,10 +735,11 @@ static const struct sunxi_pinctrl_desc __maybe_unused sun50i_h6_r_pinctrl_desc =
 	.num_banks	= 2,
 };
 
 static const struct sunxi_pinctrl_function sun50i_h616_pinctrl_functions[] = {
 	{ "emac0",	2 },	/* PI0-PI16 */
+	{ "emac1",  2 },    /* PA0-PA9 */
 	{ "gpio_in",	0 },
 	{ "gpio_out",	1 },
 	{ "mmc0",	2 },	/* PF0-PF5 */
 	{ "mmc1",	2 },	/* PG0-PG5 */
 	{ "mmc2",	3 },	/* PC0-PC16 */
-- 
Created with Armbian build tools https://github.com/armbian/build

