public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Hongwei Zhang <hongweiz@ami.com>
To: u-boot@lists.denx.de
Subject: [v2019.04-aspeed, v1 1/1] net: ftgmac100: Read and retain MAC address
Date: Thu, 10 Dec 2020 18:11:09 -0500	[thread overview]
Message-ID: <20201210231109.15752-2-hongweiz@ami.com> (raw)
In-Reply-To: <20201210231109.15752-1-hongweiz@ami.com>

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

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

  reply	other threads:[~2020-12-10 23:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-10 23:11 [v2019.04-aspeed, v1 0/1] net: ftgmac100: Read and retain MAC address Hongwei Zhang
2020-12-10 23:11 ` Hongwei Zhang [this message]
2021-01-19 20:01   ` [v2019.04-aspeed, v1 1/1] " Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201210231109.15752-2-hongweiz@ami.com \
    --to=hongweiz@ami.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox