diff mbox series

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

Message ID 20201210231109.15752-2-hongweiz@ami.com
State Accepted
Delegated to: Tom Rini
Headers show
Series net: ftgmac100: Read and retain MAC address | expand

Commit Message

Hongwei Zhang Dec. 10, 2020, 11:11 p.m. UTC
Read and retain MAC address across flash and QEMU support.

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

Comments

Tom Rini Jan. 19, 2021, 8:01 p.m. UTC | #1
On Thu, Dec 10, 2020 at 06:11:09PM -0500, Hongwei Zhang wrote:

> Read and retain MAC address across flash and QEMU support.
> 
> Signed-off-by: Hongwei Zhang <hongweiz@ami.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

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)) {