1 From 92f38460229a8816404408f036f0a374f1013d0e Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sun, 27 Jul 2014 09:40:01 +0100
4 Subject: [PATCH 34/57] NET: add of_get_mac_address_mtd()
6 Many embedded devices have information such as mac addresses stored inside mtd
7 devices. This patch allows us to add a property inside a node describing a
8 network interface. The new property points at a mtd partition with an offset
9 where the mac address can be found.
11 Signed-off-by: John Crispin <blogic@openwrt.org>
13 drivers/of/of_net.c | 37 +++++++++++++++++++++++++++++++++++++
14 include/linux/of_net.h | 1 +
15 2 files changed, 38 insertions(+)
17 --- a/drivers/of/of_net.c
18 +++ b/drivers/of/of_net.c
20 #include <linux/of_net.h>
21 #include <linux/phy.h>
22 #include <linux/export.h>
23 +#include <linux/mtd/mtd.h>
26 * of_get_phy_mode - Get phy mode for given device_node
27 @@ -75,3 +76,39 @@ const void *of_get_mac_address(struct de
30 EXPORT_SYMBOL(of_get_mac_address);
32 +int of_get_mac_address_mtd(struct device_node *np, void *mac)
34 + struct device_node *mtd_np = NULL;
37 + struct mtd_info *mtd;
42 + list = of_get_property(np, "mtd-mac-address", &size);
43 + if (!list || (size != (2 * sizeof(*list))))
46 + phandle = be32_to_cpup(list++);
48 + mtd_np = of_find_node_by_phandle(phandle);
53 + part = of_get_property(mtd_np, "label", NULL);
55 + part = mtd_np->name;
57 + mtd = get_mtd_device_nm(part);
59 + return PTR_ERR(mtd);
61 + ret = mtd_read(mtd, be32_to_cpup(list), 6, &retlen, (u_char *) mac);
62 + put_mtd_device(mtd);
66 +EXPORT_SYMBOL_GPL(of_get_mac_address_mtd);
67 --- a/include/linux/of_net.h
68 +++ b/include/linux/of_net.h
71 extern int of_get_phy_mode(struct device_node *np);
72 extern const void *of_get_mac_address(struct device_node *np);
73 +extern int of_get_mac_address_mtd(struct device_node *np, void *mac);
75 static inline int of_get_phy_mode(struct device_node *np)