lantiq: add v3.10 patches
[openwrt/svn-archive/archive.git] / target / linux / lantiq / patches-3.10 / 0023-NET-add-of_get_mac_address_mtd.patch
1 From d79fd47eb2d2d865a433db0b8d0e4b48cac17846 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sun, 14 Jul 2013 23:26:15 +0200
4 Subject: [PATCH 23/34] NET: add of_get_mac_address_mtd()
5
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.
10
11 Signed-off-by: John Crispin <blogic@openwrt.org>
12 ---
13 drivers/of/of_net.c | 37 +++++++++++++++++++++++++++++++++++++
14 include/linux/of_net.h | 1 +
15 2 files changed, 38 insertions(+)
16
17 diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
18 index ffab033..15f4a71 100644
19 --- a/drivers/of/of_net.c
20 +++ b/drivers/of/of_net.c
21 @@ -10,6 +10,7 @@
22 #include <linux/of_net.h>
23 #include <linux/phy.h>
24 #include <linux/export.h>
25 +#include <linux/mtd/mtd.h>
26
27 /**
28 * It maps 'enum phy_interface_t' found in include/linux/phy.h
29 @@ -92,3 +93,39 @@ const void *of_get_mac_address(struct device_node *np)
30 return NULL;
31 }
32 EXPORT_SYMBOL(of_get_mac_address);
33 +
34 +int of_get_mac_address_mtd(struct device_node *np, void *mac)
35 +{
36 + struct device_node *mtd_np = NULL;
37 + size_t retlen;
38 + int size, ret;
39 + struct mtd_info *mtd;
40 + const char *part;
41 + const __be32 *list;
42 + phandle phandle;
43 +
44 + list = of_get_property(np, "mtd-mac-address", &size);
45 + if (!list || (size != (2 * sizeof(*list))))
46 + return -ENOENT;
47 +
48 + phandle = be32_to_cpup(list++);
49 + if (phandle)
50 + mtd_np = of_find_node_by_phandle(phandle);
51 +
52 + if (!mtd_np)
53 + return -ENOENT;
54 +
55 + part = of_get_property(mtd_np, "label", NULL);
56 + if (!part)
57 + part = mtd_np->name;
58 +
59 + mtd = get_mtd_device_nm(part);
60 + if (IS_ERR(mtd))
61 + return PTR_ERR(mtd);
62 +
63 + ret = mtd_read(mtd, be32_to_cpup(list), 6, &retlen, (u_char *) mac);
64 + put_mtd_device(mtd);
65 +
66 + return ret;
67 +}
68 +EXPORT_SYMBOL_GPL(of_get_mac_address_mtd);
69 diff --git a/include/linux/of_net.h b/include/linux/of_net.h
70 index 61bf53b..6e6b4a9 100644
71 --- a/include/linux/of_net.h
72 +++ b/include/linux/of_net.h
73 @@ -11,6 +11,7 @@
74 #include <linux/of.h>
75 extern const int of_get_phy_mode(struct device_node *np);
76 extern const void *of_get_mac_address(struct device_node *np);
77 +extern int of_get_mac_address_mtd(struct device_node *np, void *mac);
78 #else
79 static inline const int of_get_phy_mode(struct device_node *np)
80 {
81 --
82 1.7.10.4
83