75f0415b73f71e35f9b9b4ac0891e9c1e03412df
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / 605-rt2x00-load-eeprom-on-SoC-from-a-mtd-device-defines-.patch
1 From 339fe73f340161a624cc08e738d2244814852c3e Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sun, 17 Mar 2013 00:55:04 +0100
4 Subject: [PATCH] rt2x00: load eeprom on SoC from a mtd device defines inside
5 OF
6
7 Signed-off-by: John Crispin <blogic@openwrt.org>
8 ---
9 drivers/net/wireless/rt2x00/Kconfig | 1 +
10 drivers/net/wireless/rt2x00/rt2800pci.c | 44 ++++++++++++++++++++++++++-----
11 2 files changed, 39 insertions(+), 6 deletions(-)
12
13 --- a/drivers/net/wireless/rt2x00/Kconfig
14 +++ b/drivers/net/wireless/rt2x00/Kconfig
15 @@ -219,6 +219,7 @@ config RT2800SOC
16 select RT2X00_LIB_EEPROM
17 select RT2800_LIB
18 select RT2800_LIB_MMIO
19 + select MTD if SOC_RT288X || SOC_RT305X
20 ---help---
21 This adds support for Ralink WiSoC devices.
22 Supported chips: RT2880, RT3050, RT3052, RT3350, RT3352.
23 --- a/drivers/net/wireless/rt2x00/rt2x00eeprom.c
24 +++ b/drivers/net/wireless/rt2x00/rt2x00eeprom.c
25 @@ -26,11 +26,66 @@
26
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 +#include <linux/mtd/mtd.h>
30 +#include <linux/mtd/partitions.h>
31 #include <linux/of.h>
32
33 #include "rt2x00.h"
34 #include "rt2x00lib.h"
35
36 +static int rt2800lib_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev)
37 +{
38 + int ret = -EINVAL;
39 +#ifdef CONFIG_OF
40 + static struct firmware mtd_fw;
41 + struct device_node *np = rt2x00dev->dev->of_node, *mtd_np = NULL;
42 + size_t retlen, len = rt2x00dev->ops->eeprom_size;
43 + int size, offset = 0;
44 + struct mtd_info *mtd;
45 + const char *part;
46 + const __be32 *list;
47 + phandle phandle;
48 +
49 + list = of_get_property(np, "ralink,mtd-eeprom", &size);
50 + if (!list) {
51 + dev_err(rt2x00dev->dev, "failed to load eeprom property\n");
52 + return -ENOENT;
53 + }
54 +
55 + phandle = be32_to_cpup(list++);
56 + if (phandle)
57 + mtd_np = of_find_node_by_phandle(phandle);
58 + if (!mtd_np) {
59 + dev_err(rt2x00dev->dev, "failed to load mtd phandle\n");
60 + return -EINVAL;
61 + }
62 +
63 + part = of_get_property(mtd_np, "label", NULL);
64 + if (!part)
65 + part = mtd_np->name;
66 +
67 + mtd = get_mtd_device_nm(part);
68 + if (IS_ERR(mtd)) {
69 + dev_err(rt2x00dev->dev, "failed to get mtd device \"%s\"\n", part);
70 + return PTR_ERR(mtd);
71 + }
72 +
73 + if (size > sizeof(*list))
74 + offset = be32_to_cpup(list);
75 +
76 + ret = mtd_read(mtd, offset, len, &retlen, (u_char *) rt2x00dev->eeprom);
77 + put_mtd_device(mtd);
78 +
79 + if (!ret) {
80 + rt2x00dev->eeprom_file = &mtd_fw;
81 + mtd_fw.size = len;
82 + mtd_fw.data = rt2x00dev->eeprom;
83 + }
84 +#endif
85 +
86 + return ret;
87 +}
88 +
89 static const char *
90 rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
91 {
92 @@ -58,6 +113,9 @@ static int rt2x00lib_request_eeprom_file
93 const char *ee_name;
94 int retval;
95
96 + if (!rt2800lib_read_eeprom_mtd(rt2x00dev))
97 + return 0;
98 +
99 ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
100 if (!ee_name) {
101 rt2x00_err(rt2x00dev,