build/patch/kernel/archive/meson64-5.10/0100-ETH-setup-mac-address-from-command-line.patch

75 lines
2.1 KiB
Diff

From d714aa2f0b8cb6265beb0d15f99d4c87fb934c15 Mon Sep 17 00:00:00 2001
From: Nick Xie <nick@khadas.com>
Date: Wed, 25 Dec 2019 13:41:52 +0800
Subject: [PATCH 100/101] ETH: setup mac address from command line
Signed-off-by: Nick Xie <nick@khadas.com>
---
.../ethernet/stmicro/stmmac/stmmac_platform.c | 42 +++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 13fafd905db8..2b2dccd04cbf 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -21,6 +21,40 @@
#ifdef CONFIG_OF
+#if defined (CONFIG_DWMAC_MESON) || defined (CONFIG_DWMAC_ROCKCHIP)
+static u8 DEFMAC[] = {0, 0, 0, 0, 0, 0};
+static unsigned int g_mac_addr_setup;
+static unsigned char chartonum(char c)
+{
+ if (c >= '0' && c <= '9')
+ return c - '0';
+ if (c >= 'A' && c <= 'F')
+ return (c - 'A') + 10;
+ if (c >= 'a' && c <= 'f')
+ return (c - 'a') + 10;
+
+ return 0;
+}
+
+static int __init mac_addr_set(char *line)
+{
+ unsigned char mac[6];
+ int i = 0;
+
+ for (i = 0; i < 6 && line[0] != '\0' && line[1] != '\0'; i++) {
+ mac[i] = chartonum(line[0]) << 4 | chartonum(line[1]);
+ line += 3;
+ }
+ memcpy(DEFMAC, mac, 6);
+ pr_info("uboot setup mac-addr: %02x:%02x:%02x:%02x:%02x:%02x\n",
+ DEFMAC[0], DEFMAC[1], DEFMAC[2], DEFMAC[3], DEFMAC[4], DEFMAC[5]);
+ g_mac_addr_setup++;
+ return 0;
+}
+__setup("mac=", mac_addr_set);
+#endif
+
+
/**
* dwmac1000_validate_mcast_bins - validates the number of Multicast filter bins
* @dev: struct device of the platform device
@@ -404,7 +438,15 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
if (!plat)
return ERR_PTR(-ENOMEM);
+#if defined (CONFIG_DWMAC_MESON) || defined (CONFIG_DWMAC_ROCKCHIP)
+ if (g_mac_addr_setup) /*so uboot mac= is first priority.*/
+ *mac = DEFMAC;
+ else
+ *mac = of_get_mac_address(np);
+#else
*mac = of_get_mac_address(np);
+#endif
+
if (IS_ERR(*mac)) {
if (PTR_ERR(*mac) == -EPROBE_DEFER)
return ERR_CAST(*mac);
--
2.17.1