43754c43c24ace37975ad7feea8a2c6038bda699
[openwrt/staging/jow.git] /
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/ralink/rt2x00/Kconfig | 1 +
10 drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c | 65 +++++++++++++++++++++++
11 2 files changed, 66 insertions(+)
12
13 --- a/drivers/net/wireless/ralink/rt2x00/Kconfig
14 +++ b/drivers/net/wireless/ralink/rt2x00/Kconfig
15 @@ -220,6 +220,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/ralink/rt2x00/rt2x00eeprom.c
24 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
25 @@ -26,11 +26,76 @@
26
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 +#if IS_ENABLED(CONFIG_MTD)
30 +#include <linux/mtd/mtd.h>
31 +#include <linux/mtd/partitions.h>
32 +#endif
33 #include <linux/of.h>
34
35 #include "rt2x00.h"
36 #include "rt2x00lib.h"
37
38 +#if IS_ENABLED(CONFIG_MTD)
39 +static int rt2800lib_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev)
40 +{
41 + int ret = -EINVAL;
42 +#ifdef CONFIG_OF
43 + static struct firmware mtd_fw;
44 + struct device_node *np = rt2x00dev->dev->of_node, *mtd_np = NULL;
45 + size_t retlen, len = rt2x00dev->ops->eeprom_size;
46 + int i, size, offset = 0;
47 + struct mtd_info *mtd;
48 + const char *part;
49 + const __be32 *list;
50 + phandle phandle;
51 +
52 + list = of_get_property(np, "ralink,mtd-eeprom", &size);
53 + if (!list)
54 + return -ENOENT;
55 +
56 + phandle = be32_to_cpup(list++);
57 + if (phandle)
58 + mtd_np = of_find_node_by_phandle(phandle);
59 + if (!mtd_np) {
60 + dev_err(rt2x00dev->dev, "failed to load mtd phandle\n");
61 + return -EINVAL;
62 + }
63 +
64 + part = of_get_property(mtd_np, "label", NULL);
65 + if (!part)
66 + part = mtd_np->name;
67 +
68 + mtd = get_mtd_device_nm(part);
69 + if (IS_ERR(mtd)) {
70 + dev_err(rt2x00dev->dev, "failed to get mtd device \"%s\"\n", part);
71 + return PTR_ERR(mtd);
72 + }
73 +
74 + if (size > sizeof(*list))
75 + offset = be32_to_cpup(list);
76 +
77 + ret = mtd_read(mtd, offset, len, &retlen, (u_char *) rt2x00dev->eeprom);
78 + put_mtd_device(mtd);
79 +
80 + if ((retlen != rt2x00dev->ops->eeprom_size) || ret) {
81 + dev_err(rt2x00dev->dev, "failed to load eeprom from device \"%s\"\n", part);
82 + return ret;
83 + }
84 +
85 + if (of_find_property(np, "ralink,mtd-eeprom-swap", NULL))
86 + for (i = 0; i < len/sizeof(u16); i++)
87 + rt2x00dev->eeprom[i] = swab16(rt2x00dev->eeprom[i]);
88 +
89 + rt2x00dev->eeprom_file = &mtd_fw;
90 + mtd_fw.data = (const u8 *) rt2x00dev->eeprom;
91 +
92 + dev_info(rt2x00dev->dev, "loaded eeprom from mtd device \"%s\"\n", part);
93 +#endif
94 +
95 + return ret;
96 +}
97 +#endif
98 +
99 static const char *
100 rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
101 {
102 @@ -58,6 +123,11 @@ static int rt2x00lib_request_eeprom_file
103 const char *ee_name;
104 int retval;
105
106 +#if IS_ENABLED(CONFIG_MTD)
107 + if (!rt2800lib_read_eeprom_mtd(rt2x00dev))
108 + return 0;
109 +#endif
110 +
111 ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
112 if (!ee_name && test_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags)) {
113 rt2x00_err(rt2x00dev, "Required EEPROM name is missing.");