6a343db9c728d7922749d8903f6b722894403d03
[openwrt/staging/neocturne.git] /
1 From 71261ca81b491a4c3b08690347c12e96a75ad0d0 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 3/5] wifi: rt2x00: Add support for loading EEPROM from MTD
5
6 Add support for loading EEPROM from MTD.
7
8 Signed-off-by: John Crispin <blogic@openwrt.org>
9 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
10 ---
11 drivers/net/wireless/ralink/rt2x00/Kconfig | 1 +
12 .../net/wireless/ralink/rt2x00/rt2x00eeprom.c | 66 +++++++++++++++++++
13 2 files changed, 67 insertions(+)
14
15 --- a/drivers/net/wireless/ralink/rt2x00/Kconfig
16 +++ b/drivers/net/wireless/ralink/rt2x00/Kconfig
17 @@ -220,6 +220,7 @@ config RT2800SOC
18 select RT2X00_LIB_EEPROM
19 select RT2800_LIB
20 select RT2800_LIB_MMIO
21 + select MTD if SOC_RT288X || SOC_RT305X
22 help
23 This adds support for Ralink WiSoC devices.
24 Supported chips: RT2880, RT3050, RT3052, RT3350, RT3352.
25 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
26 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
27 @@ -10,11 +10,69 @@
28
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 +#if IS_ENABLED(CONFIG_MTD)
32 +#include <linux/mtd/mtd.h>
33 +#include <linux/mtd/partitions.h>
34 +#endif
35 #include <linux/of.h>
36
37 #include "rt2x00.h"
38 #include "rt2x00soc.h"
39
40 +#if IS_ENABLED(CONFIG_MTD)
41 +static int rt2800lib_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev)
42 +{
43 + int ret = -EINVAL;
44 +#ifdef CONFIG_OF
45 + struct device_node *np = rt2x00dev->dev->of_node, *mtd_np = NULL;
46 + int size, offset = 0;
47 + struct mtd_info *mtd;
48 + const char *part;
49 + const __be32 *list;
50 + phandle phandle;
51 + size_t retlen;
52 +
53 + list = of_get_property(np, "ralink,mtd-eeprom", &size);
54 + if (!list)
55 + return -ENOENT;
56 +
57 + phandle = be32_to_cpup(list++);
58 + if (phandle)
59 + mtd_np = of_find_node_by_phandle(phandle);
60 + if (!mtd_np) {
61 + dev_err(rt2x00dev->dev, "failed to load mtd phandle\n");
62 + return -EINVAL;
63 + }
64 +
65 + part = of_get_property(mtd_np, "label", NULL);
66 + if (!part)
67 + part = mtd_np->name;
68 +
69 + mtd = get_mtd_device_nm(part);
70 + if (IS_ERR(mtd)) {
71 + dev_err(rt2x00dev->dev, "failed to get mtd device \"%s\"\n", part);
72 + return PTR_ERR(mtd);
73 + }
74 +
75 + if (size > sizeof(*list))
76 + offset = be32_to_cpup(list);
77 +
78 + ret = mtd_read(mtd, offset, rt2x00dev->ops->eeprom_size,
79 + &retlen, (u_char *)rt2x00dev->eeprom);
80 + put_mtd_device(mtd);
81 +
82 + if (retlen != rt2x00dev->ops->eeprom_size || ret) {
83 + dev_err(rt2x00dev->dev, "failed to load eeprom from device \"%s\"\n", part);
84 + return ret;
85 + }
86 +
87 + dev_info(rt2x00dev->dev, "loaded eeprom from mtd device \"%s\"\n", part);
88 +#endif
89 +
90 + return ret;
91 +}
92 +#endif
93 +
94 static const char *
95 rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
96 {
97 @@ -83,5 +141,13 @@ err_exit:
98
99 int rt2x00lib_read_eeprom(struct rt2x00_dev *rt2x00dev)
100 {
101 + int ret;
102 +
103 +#if IS_ENABLED(CONFIG_MTD)
104 + ret = rt2800lib_read_eeprom_mtd(rt2x00dev);
105 + if (!ret)
106 + return 0;
107 +#endif
108 +
109 return rt2x00lib_read_eeprom_file(rt2x00dev);
110 }