b3e1220b601ab1d449f1237c1366e8776cb3d89f
[openwrt/staging/blogic.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 @@ -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/ralink/rt2x00/rt2x00eeprom.c
24 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
25 @@ -26,11 +26,72 @@
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 i, 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 + return -ENOENT;
52 +
53 + phandle = be32_to_cpup(list++);
54 + if (phandle)
55 + mtd_np = of_find_node_by_phandle(phandle);
56 + if (!mtd_np) {
57 + dev_err(rt2x00dev->dev, "failed to load mtd phandle\n");
58 + return -EINVAL;
59 + }
60 +
61 + part = of_get_property(mtd_np, "label", NULL);
62 + if (!part)
63 + part = mtd_np->name;
64 +
65 + mtd = get_mtd_device_nm(part);
66 + if (IS_ERR(mtd)) {
67 + dev_err(rt2x00dev->dev, "failed to get mtd device \"%s\"\n", part);
68 + return PTR_ERR(mtd);
69 + }
70 +
71 + if (size > sizeof(*list))
72 + offset = be32_to_cpup(list);
73 +
74 + ret = mtd_read(mtd, offset, len, &retlen, (u_char *) rt2x00dev->eeprom);
75 + put_mtd_device(mtd);
76 +
77 + if ((retlen != rt2x00dev->ops->eeprom_size) || ret) {
78 + dev_err(rt2x00dev->dev, "failed to load eeprom from device \"%s\"\n", part);
79 + return ret;
80 + }
81 +
82 + if (of_find_property(np, "ralink,mtd-eeprom-swap", NULL))
83 + for (i = 0; i < len/sizeof(u16); i++)
84 + rt2x00dev->eeprom[i] = swab16(rt2x00dev->eeprom[i]);
85 +
86 + rt2x00dev->eeprom_file = &mtd_fw;
87 + mtd_fw.data = (const u8 *) rt2x00dev->eeprom;
88 +
89 + dev_info(rt2x00dev->dev, "loaded eeprom from mtd device \"%s\"\n", part);
90 +#endif
91 +
92 + return ret;
93 +}
94 +
95 static const char *
96 rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
97 {
98 @@ -58,6 +119,9 @@ static int rt2x00lib_request_eeprom_file
99 const char *ee_name;
100 int retval;
101
102 + if (!rt2800lib_read_eeprom_mtd(rt2x00dev))
103 + return 0;
104 +
105 ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
106 if (!ee_name && test_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags)) {
107 rt2x00_err(rt2x00dev, "Required EEPROM name is missing.");