mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/4] ARM: boards: polyhex-debix: add support to read MAC addresses
Date: Tue, 29 Aug 2023 14:43:55 +0200	[thread overview]
Message-ID: <20230829124356.4178308-3-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20230829124356.4178308-1-m.felsch@pengutronix.de>

For the Debix SoM/Baseboard combination the MAC addresses are stored on
a baseboard EEPROM in ASCII format. This commit adds the support to read
the MAC addresses from the EEPROM and set it accordingly.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 arch/arm/boards/polyhex-debix/board.c | 66 ++++++++++++++++++++++++++-
 1 file changed, 65 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/polyhex-debix/board.c b/arch/arm/boards/polyhex-debix/board.c
index f81666ce0c93..ea4fc26a0ceb 100644
--- a/arch/arm/boards/polyhex-debix/board.c
+++ b/arch/arm/boards/polyhex-debix/board.c
@@ -6,11 +6,67 @@
 #include <envfs.h>
 #include <init.h>
 #include <io.h>
+#include <linux/nvmem-consumer.h>
 #include <mach/imx/bbu.h>
 #include <mach/imx/iomux-mx8mp.h>
+#include <net.h>
+
+struct debix_polyhex_machine_data {
+	void (*ethernet_setup)(void);
+};
+
+#define ETH_ALEN_ASCII	12
+
+static int polyhex_debix_eth_register_ethaddr(struct device_node *np)
+{
+	u8 mac[ETH_ALEN];
+	u8 *data;
+	int ret;
+
+	data = nvmem_cell_get_and_read(np, "mac-address", ETH_ALEN_ASCII);
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	ret = hex2bin(mac, data, ETH_ALEN);
+	if (ret)
+		goto err;
+
+	of_eth_register_ethaddr(np, mac);
+err:
+	free(data);
+
+	return ret;
+}
+
+static void polyhex_debix_ethernet_init(void)
+{
+	static const char * const aliases[] = { "ethernet0", "ethernet1" };
+	struct device_node *np, *root;
+	unsigned int i;
+
+	root = of_get_root_node();
+
+	for (i = 0; i < ARRAY_SIZE(aliases); i++) {
+		const char *alias = aliases[i];
+		int ret;
+
+		np = of_find_node_by_alias(root, alias);
+		if (!np) {
+			pr_warn("Failed to find %s\n", alias);
+			continue;
+		}
+
+		ret = polyhex_debix_eth_register_ethaddr(np);
+		if (ret) {
+			pr_warn("Failed to register MAC for %s\n", alias);
+			continue;
+		}
+	}
+}
 
 static int polyhex_debix_probe(struct device *dev)
 {
+	const struct debix_polyhex_machine_data *machine_data;
 	int emmc_bbu_flag = 0;
 	int sd_bbu_flag = 0;
 	u32 val;
@@ -32,12 +88,20 @@ static int polyhex_debix_probe(struct device *dev)
 	       MX8MP_IOMUXC_GPR1_ENET_QOS_RGMII_EN;
 	writel(val, MX8MP_IOMUXC_GPR_BASE_ADDR + MX8MP_IOMUXC_GPR1);
 
+	machine_data = device_get_match_data(dev);
+	if (machine_data && machine_data->ethernet_setup)
+		machine_data->ethernet_setup();
+
 	return 0;
 }
 
+static const struct debix_polyhex_machine_data debix_som_a_bmb_08 = {
+	.ethernet_setup = polyhex_debix_ethernet_init,
+};
+
 static const struct of_device_id polyhex_debix_of_match[] = {
 	{ .compatible = "polyhex,imx8mp-debix" },
-	{ .compatible = "polyhex,imx8mp-debix-som-a-bmb-08" },
+	{ .compatible = "polyhex,imx8mp-debix-som-a-bmb-08", .data = &debix_som_a_bmb_08 },
 	{ /* Sentinel */ }
 };
 BAREBOX_DEEP_PROBE_ENABLE(polyhex_debix_of_match);
-- 
2.39.2




  parent reply	other threads:[~2023-08-29 12:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-29 12:43 [PATCH 1/4] ARM: boards: polyhex-debix: fix RGMII pin setup Marco Felsch
2023-08-29 12:43 ` [PATCH 2/4] ARM: boards: polyhex-debix: add SoM/Baseboard combination compatible Marco Felsch
2023-08-29 12:43 ` Marco Felsch [this message]
2023-08-29 12:43 ` [PATCH 4/4] ARM: dts: imx8mp-debix-som-a-bmb-08-upstream: sync with mainlined kernel version Marco Felsch
2023-09-05 12:23 ` [PATCH 1/4] ARM: boards: polyhex-debix: fix RGMII pin setup Sascha Hauer

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=20230829124356.4178308-3-m.felsch@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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