From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 2/2] ARM: rdu2: Fetch MAC address info from RAVE SP EEPROM
Date: Tue, 26 Jun 2018 20:58:42 -0700 [thread overview]
Message-ID: <20180627035842.17858-2-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20180627035842.17858-1-andrew.smirnov@gmail.com>
RDU2 stores MAC addresses for its Ethernet interfaces in main RAVE SP
EEPROM. Add code to properly integrate it.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/boards/zii-imx6q-rdu2/board.c | 57 ++++++++++++++++++++++++++
arch/arm/dts/imx6qdl-zii-rdu2.dtsi | 15 +++++++
2 files changed, 72 insertions(+)
diff --git a/arch/arm/boards/zii-imx6q-rdu2/board.c b/arch/arm/boards/zii-imx6q-rdu2/board.c
index 265f97e2f..f6c908c9f 100644
--- a/arch/arm/boards/zii-imx6q-rdu2/board.c
+++ b/arch/arm/boards/zii-imx6q-rdu2/board.c
@@ -19,6 +19,8 @@
#include <init.h>
#include <mach/bbu.h>
#include <mach/imx6.h>
+#include <net.h>
+#include <linux/nvmem-consumer.h>
#define RDU2_DAC1_RESET IMX_GPIO_NR(1, 0)
#define RDU2_DAC2_RESET IMX_GPIO_NR(1, 2)
@@ -151,3 +153,58 @@ static int rdu2_devices_init(void)
return 0;
}
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);
diff --git a/arch/arm/dts/imx6qdl-zii-rdu2.dtsi b/arch/arm/dts/imx6qdl-zii-rdu2.dtsi
index bb5321e62..68ee78002 100644
--- a/arch/arm/dts/imx6qdl-zii-rdu2.dtsi
+++ b/arch/arm/dts/imx6qdl-zii-rdu2.dtsi
@@ -85,6 +85,14 @@
boot_source: boot-source@83 {
reg = <0x83 1>;
};
+
+ mac_address_0: mac-address@180 {
+ reg = <0x180 6>;
+ };
+
+ mac_address_1: mac-address@190 {
+ reg = <0x190 6>;
+ };
};
backlight {
@@ -181,6 +189,11 @@
};
};
+&fec {
+ nvmem-cells = <&mac_address_0>;
+ nvmem-cell-names = "mac-address";
+};
+
&i2c2 {
temp-sense@48 {
barebox,sensor-name = "Temp Sensor 1";
@@ -196,6 +209,8 @@
i210: i210@0 {
reg = <0 0 0 0 0>;
+ nvmem-cells = <&mac_address_1>;
+ nvmem-cell-names = "mac-address";
};
};
};
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2018-06-27 3:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-27 3:58 [PATCH 1/2] nvmem: Introduce nvmem_cell_get_and_read() Andrey Smirnov
2018-06-27 3:58 ` Andrey Smirnov [this message]
2018-06-27 9:05 ` Lucas Stach
2018-06-27 16:57 ` Andrey Smirnov
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=20180627035842.17858-2-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--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