mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>,
	Chris Healy <cphealy@gmail.com>
Subject: [PATCH 8/8] ARM: zii-common: Share MAC address configuration between RDU2/3
Date: Fri, 13 Sep 2019 23:19:43 -0700	[thread overview]
Message-ID: <20190914061943.4715-8-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20190914061943.4715-1-andrew.smirnov@gmail.com>

Both RDU2 and RDU3 share the same MAC address configuration
mechanism. Reflect that by moving that code into zii-common and
changing it to be executed on both platforms.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
---
 arch/arm/boards/zii-common/board.c     | 58 ++++++++++++++++++++++++++
 arch/arm/boards/zii-imx6q-rdu2/board.c | 55 ------------------------
 arch/arm/dts/imx8mq-zii-ultra.dtsi     | 26 ++++++++++++
 3 files changed, 84 insertions(+), 55 deletions(-)

diff --git a/arch/arm/boards/zii-common/board.c b/arch/arm/boards/zii-common/board.c
index 20ec64d2d4..9a9564e6d1 100644
--- a/arch/arm/boards/zii-common/board.c
+++ b/arch/arm/boards/zii-common/board.c
@@ -16,6 +16,64 @@
 #include <globalvar.h>
 #include <init.h>
 #include <fs.h>
+#include <net.h>
+#include <linux/nvmem-consumer.h>
+
+static int rdu_eth_register_ethaddr(struct device_node *np)
+{
+	u8 mac[ETH_ALEN];
+	u8 *data;
+	int i;
+
+	data = nvmem_cell_get_and_read(np, "mac-address", ETH_ALEN);
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+	/*
+	 * EEPROM stores MAC address in reverse (to what we expect it
+	 * to be) byte order.
+	 */
+	for (i = 0; i < ETH_ALEN; i++)
+		mac[i] = data[ETH_ALEN - i - 1];
+
+	free(data);
+
+	of_eth_register_ethaddr(np, mac);
+
+	return 0;
+}
+
+static int rdu_ethernet_init(void)
+{
+	static const char * const aliases[] = { "ethernet0", "ethernet1" };
+	struct device_node *np, *root;
+	int i, ret;
+
+	if (!of_machine_is_compatible("zii,imx6q-zii-rdu2") &&
+	    !of_machine_is_compatible("zii,imx6qp-zii-rdu2") &&
+	    !of_machine_is_compatible("zii,imx8mq-ultra"))
+		return 0;
+
+	root = of_get_root_node();
+
+	for (i = 0; i < ARRAY_SIZE(aliases); i++) {
+		const char *alias = aliases[i];
+
+		np = of_find_node_by_alias(root, alias);
+		if (!np) {
+			pr_warn("Failed to find %s\n", alias);
+			continue;
+		}
+
+		ret = rdu_eth_register_ethaddr(np);
+		if (ret) {
+			pr_warn("Failed to register MAC for %s\n", alias);
+			continue;
+		}
+	}
+
+	return 0;
+}
+late_initcall(rdu_ethernet_init);
 
 static int rdu_networkconfig(void)
 {
diff --git a/arch/arm/boards/zii-imx6q-rdu2/board.c b/arch/arm/boards/zii-imx6q-rdu2/board.c
index 6adb0b1c6f..63367a419a 100644
--- a/arch/arm/boards/zii-imx6q-rdu2/board.c
+++ b/arch/arm/boards/zii-imx6q-rdu2/board.c
@@ -159,61 +159,6 @@ static int rdu2_devices_init(void)
 }
 device_initcall(rdu2_devices_init);
 
-static int rdu2_eth_register_ethaddr(struct device_node *np)
-{
-	u8 mac[ETH_ALEN];
-	u8 *data;
-	int i;
-
-	data = nvmem_cell_get_and_read(np, "mac-address", ETH_ALEN);
-	if (IS_ERR(data))
-		return PTR_ERR(data);
-	/*
-	 * EEPROM stores MAC address in reverse (to what we expect it
-	 * to be) byte order.
-	 */
-	for (i = 0; i < ETH_ALEN; i++)
-		mac[i] = data[ETH_ALEN - i - 1];
-
-	free(data);
-
-	of_eth_register_ethaddr(np, mac);
-
-	return 0;
-}
-
-static int rdu2_ethernet_init(void)
-{
-	const char *aliases[] = { "ethernet0", "ethernet1" };
-	struct device_node *np, *root;
-	int i, ret;
-
-	if (!of_machine_is_compatible("zii,imx6q-zii-rdu2") &&
-	    !of_machine_is_compatible("zii,imx6qp-zii-rdu2"))
-		return 0;
-
-	root = of_get_root_node();
-
-	for (i = 0; i < ARRAY_SIZE(aliases); i++) {
-		const char *alias = aliases[i];
-
-		np = of_find_node_by_alias(root, alias);
-		if (!np) {
-			pr_warn("Failed to find %s\n", alias);
-			continue;
-		}
-
-		ret = rdu2_eth_register_ethaddr(np);
-		if (ret) {
-			pr_warn("Failed to register MAC for %s\n", alias);
-			continue;
-		}
-	}
-
-	return 0;
-}
-late_initcall(rdu2_ethernet_init);
-
 static int rdu2_fixup_egalax_ts(struct device_node *root, void *context)
 {
 	struct device_node *np;
diff --git a/arch/arm/dts/imx8mq-zii-ultra.dtsi b/arch/arm/dts/imx8mq-zii-ultra.dtsi
index 1a9ba160a3..6180f21ab0 100644
--- a/arch/arm/dts/imx8mq-zii-ultra.dtsi
+++ b/arch/arm/dts/imx8mq-zii-ultra.dtsi
@@ -23,6 +23,8 @@
 	};
 
 	aliases {
+		ethernet0 = &fec1;
+		ethernet1 = &i210;
 		/*
 		 * NVMEM device corresponding to EEPROM attached to
 		 * the switch shared DT node with it, so we use that
@@ -32,6 +34,11 @@
 	};
 };
 
+&fec1 {
+	nvmem-cells = <&mac_address_0>;
+	nvmem-cell-names = "mac-address";
+};
+
 &ocotp {
 	barebox,provide-mac-address = <&fec1 0x640>;
 };
@@ -49,6 +56,25 @@
 	};
 };
 
+&i210 {
+	nvmem-cells = <&mac_address_1>;
+	nvmem-cell-names = "mac-address";
+};
+
+&uart2 {
+	rave-sp {
+		eeprom@a4 {
+			mac_address_0: mac-address@180 {
+				reg = <0x180 6>;
+			};
+
+			mac_address_1: mac-address@190 {
+				reg = <0x190 6>;
+			};
+		};
+	};
+};
+
 &usdhc1 {
 	#address-cells = <1>;
 	#size-cells = <1>;
-- 
2.21.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2019-09-14  6:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-14  6:19 [PATCH 1/8] ARM: zii-imx8mq-dev: Drop extra relocation code Andrey Smirnov
2019-09-14  6:19 ` [PATCH 2/8] ARM: zii-imx8mq-dev: Switch to using compressed DTB Andrey Smirnov
2019-09-14  6:19 ` [PATCH 3/8] ARM: zii-vf610-dev: Swith " Andrey Smirnov
2019-09-14  6:19 ` [PATCH 4/8] ARM: zii-imx6-rdu2: " Andrey Smirnov
2019-09-14  6:19 ` [PATCH 5/8] ARM: zii-imx7d-dev: " Andrey Smirnov
2019-09-14  6:19 ` [PATCH 6/8] ARM: zii-imx51-rdu1: " Andrey Smirnov
2019-09-14  6:19 ` [PATCH 7/8] ARM: imx8mq-zii-ultra: Use upstream DTS Andrey Smirnov
2019-09-14  6:19 ` Andrey Smirnov [this message]
2019-09-16  7:28 ` [PATCH 1/8] ARM: zii-imx8mq-dev: Drop extra relocation code 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=20190914061943.4715-8-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=cphealy@gmail.com \
    /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