lantiq: Tune the XWAY subtarget cflags
[openwrt/staging/yousong.git] / package / mac80211 / patches / 617-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 @@ -71,6 +71,7 @@ config RT2800PCI
16 select RT2X00_LIB_FIRMWARE
17 select RT2X00_LIB_EEPROM
18 select RT2X00_LIB_CRYPTO
19 + select MTD if SOC_RT288X || SOC_RT305X
20 depends on CRC_CCITT
21 depends on EEPROM_93CX6
22 ---help---
23 --- a/drivers/net/wireless/rt2x00/rt2x00eeprom.c
24 +++ b/drivers/net/wireless/rt2x00/rt2x00eeprom.c
25 @@ -30,12 +30,77 @@
26 #include "rt2x00.h"
27 #include "rt2x00lib.h"
28
29 +#ifdef CONFIG_OF
30 +#include <linux/of.h>
31 +#include <linux/mtd/mtd.h>
32 +#include <linux/mtd/partitions.h>
33 +
34 +static struct firmware mtd_fw;
35 +
36 +static int rt2800pci_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev)
37 +{
38 + struct device_node *np = rt2x00dev->dev->of_node, *mtd_np = NULL;
39 + size_t retlen, len = rt2x00dev->ops->eeprom_size;
40 + int ret, size, offset = 0;
41 + struct mtd_info *mtd;
42 + const char *part;
43 + const __be32 *list;
44 + phandle phandle;
45 +
46 + list = of_get_property(np, "ralink,mtd-eeprom", &size);
47 + if (!list) {
48 + dev_err(rt2x00dev->dev, "failed to load eeprom property\n");
49 + return -ENOENT;
50 + }
51 +
52 + phandle = be32_to_cpup(list++);
53 + if (phandle)
54 + mtd_np = of_find_node_by_phandle(phandle);
55 + if (!mtd_np) {
56 + dev_err(rt2x00dev->dev, "failed to load mtd phandle\n");
57 + return -EINVAL;
58 + }
59 +
60 + part = of_get_property(mtd_np, "label", NULL);
61 + if (!part)
62 + part = mtd_np->name;
63 +
64 + mtd = get_mtd_device_nm(part);
65 + if (IS_ERR(mtd)) {
66 + dev_err(rt2x00dev->dev, "failed to get mtd device \"%s\"\n", part);
67 + return PTR_ERR(mtd);
68 + }
69 +
70 + if (size > sizeof(*list))
71 + offset = be32_to_cpup(list);
72 +
73 + ret = mtd_read(mtd, offset, len, &retlen, (u_char *) rt2x00dev->eeprom);
74 + put_mtd_device(mtd);
75 +
76 + if (!ret) {
77 + rt2x00dev->eeprom_file = &mtd_fw;
78 + mtd_fw.size = len;
79 + mtd_fw.data = rt2x00dev->eeprom;
80 + }
81 +
82 + return ret;
83 +}
84 +#else
85 +static inline int rt2800pci_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev)
86 +{
87 + return -EINVAL;
88 +}
89 +#endif
90 +
91 static int rt2x00lib_request_eeprom_file(struct rt2x00_dev *rt2x00dev)
92 {
93 const struct firmware *ee;
94 char *ee_name;
95 int retval;
96
97 + if (!rt2800pci_read_eeprom_mtd(rt2x00dev))
98 + return 0;
99 +
100 ee_name = rt2x00dev->ops->lib->get_eeprom_file_name(rt2x00dev);
101 if (!ee_name) {
102 rt2x00_err(rt2x00dev,