[v2019.04-aspeed, v1 1/1] net: ftgmac100: Read and retain MAC address

Hongwei Zhang hongweiz at ami.com
Fri Dec 11 00:11:09 CET 2020


Read and retain MAC address across flash and QEMU support.

Signed-off-by: Hongwei Zhang <hongweiz at ami.com>
---
 drivers/net/ftgmac100.c | 32 ++++++++++++++++++++++++++++++++
 net/eth-uclass.c        |  2 +-
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ftgmac100.c b/drivers/net/ftgmac100.c
index 999941de14..951d99cfe0 100644
--- a/drivers/net/ftgmac100.c
+++ b/drivers/net/ftgmac100.c
@@ -275,6 +275,28 @@ static int ftgmac100_set_mac(struct ftgmac100_data *priv,
 	return 0;
 }
 
+/*
+ * Get MAC address
+ */
+static int ftgmac100_get_mac(struct ftgmac100_data *priv,
+				unsigned char *mac)
+{
+	struct ftgmac100 *ftgmac100 = priv->iobase;
+	unsigned int maddr = readl(&ftgmac100->mac_madr);
+	unsigned int laddr = readl(&ftgmac100->mac_ladr);
+
+	debug("%s(%x %x)\n", __func__, maddr, laddr);
+
+	mac[0] = (maddr >> 8) & 0xff;
+	mac[1] =  maddr & 0xff;
+	mac[2] = (laddr >> 24) & 0xff;
+	mac[3] = (laddr >> 16) & 0xff;
+	mac[4] = (laddr >> 8) & 0xff;
+	mac[5] =  laddr & 0xff;
+
+	return 0;
+}
+
 /*
  * disable transmitter, receiver
  */
@@ -532,6 +554,14 @@ static int ftgmac100_write_hwaddr(struct udevice *dev)
 	return ftgmac100_set_mac(priv, pdata->enetaddr);
 }
 
+static int ftgmac_read_hwaddr(struct udevice *dev)
+{
+	struct eth_pdata *pdata = dev_get_platdata(dev);
+	struct ftgmac100_data *priv = dev_get_priv(dev);
+
+	return ftgmac100_get_mac(priv, pdata->enetaddr);
+}
+
 static int ftgmac100_ofdata_to_platdata(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_platdata(dev);
@@ -613,6 +643,8 @@ static int ftgmac100_probe(struct udevice *dev)
 		goto out;
 	}
 
+	ftgmac_read_hwaddr(dev);
+
 out:
 	if (ret)
 		clk_release_bulk(&priv->clks);
diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index a7f8792710..19d7e0cb3b 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -514,7 +514,7 @@ static int eth_post_probe(struct udevice *dev)
 		memcpy(pdata->enetaddr, env_enetaddr, ARP_HLEN);
 	} else if (is_valid_ethaddr(pdata->enetaddr)) {
 		eth_env_set_enetaddr_by_index("eth", dev->seq, pdata->enetaddr);
-		printf("\nWarning: %s using MAC address from ROM\n",
+		printf("\nWarning: %s using MAC address from ROM/MAC Reg\n",
 		       dev->name);
 	} else if (is_zero_ethaddr(pdata->enetaddr) ||
 		   !is_valid_ethaddr(pdata->enetaddr)) {
-- 
2.17.1



More information about the U-Boot mailing list