1 From: John Crispin <blogic@openwrt.org>
2 Date: Sun, 27 Jul 2014 09:40:01 +0100
3 Subject: NET: add of_get_mac_address_mtd()
5 Many embedded devices have information such as mac addresses stored inside mtd
6 devices. This patch allows us to add a property inside a node describing a
7 network interface. The new property points at a mtd partition with an offset
8 where the mac address can be found.
10 Signed-off-by: John Crispin <blogic@openwrt.org>
12 drivers/of/of_net.c | 37 +++++++++++++++++++++++++++++++++++++
13 include/linux/of_net.h | 1 +
14 2 files changed, 38 insertions(+)
16 --- a/drivers/of/of_net.c
17 +++ b/drivers/of/of_net.c
19 #include <linux/of_net.h>
20 #include <linux/phy.h>
21 #include <linux/export.h>
22 +#include <linux/mtd/mtd.h>
25 * of_get_phy_mode - Get phy mode for given device_node
26 @@ -80,3 +81,45 @@ const void *of_get_mac_address(struct de
27 return of_get_mac_addr(np, "address");
29 EXPORT_SYMBOL(of_get_mac_address);
32 +int of_get_mac_address_mtd(struct device_node *np, unsigned char *mac)
34 + struct device_node *mtd_np = NULL;
37 + struct mtd_info *mtd;
43 + list = of_get_property(np, "mtd-mac-address", &size);
44 + if (!list || (size != (2 * sizeof(*list))))
47 + phandle = be32_to_cpup(list++);
49 + mtd_np = of_find_node_by_phandle(phandle);
54 + part = of_get_property(mtd_np, "label", NULL);
56 + part = mtd_np->name;
58 + mtd = get_mtd_device_nm(part);
60 + return PTR_ERR(mtd);
62 + ret = mtd_read(mtd, be32_to_cpup(list), 6, &retlen, mac);
63 + put_mtd_device(mtd);
65 + if (!of_property_read_u32(np, "mtd-mac-address-increment", &mac_inc))
70 +EXPORT_SYMBOL_GPL(of_get_mac_address_mtd);
72 --- a/include/linux/of_net.h
73 +++ b/include/linux/of_net.h
76 extern int of_get_phy_mode(struct device_node *np);
77 extern const void *of_get_mac_address(struct device_node *np);
79 +extern int of_get_mac_address_mtd(struct device_node *np, unsigned char *mac);
81 +static inline int of_get_mac_address_mtd(struct device_node *np, unsigned char *mac)
86 extern struct net_device *of_find_net_device_by_node(struct device_node *np);
88 static inline int of_get_phy_mode(struct device_node *np)