mac80211: add a bunch of rt2x00 specific changes
[openwrt/svn-archive/archive.git] / package / kernel / mac80211 / patches / 603-rt2x00-introduce-rt2x00eeprom.patch
1 --- /dev/null
2 +++ b/drivers/net/wireless/rt2x00/rt2x00eeprom.c
3 @@ -0,0 +1,98 @@
4 +/*
5 + Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
6 + Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
7 + <http://rt2x00.serialmonkey.com>
8 +
9 + This program is free software; you can redistribute it and/or modify
10 + it under the terms of the GNU General Public License as published by
11 + the Free Software Foundation; either version 2 of the License, or
12 + (at your option) any later version.
13 +
14 + This program is distributed in the hope that it will be useful,
15 + but WITHOUT ANY WARRANTY; without even the implied warranty of
16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 + GNU General Public License for more details.
18 +
19 + You should have received a copy of the GNU General Public License
20 + along with this program; if not, write to the
21 + Free Software Foundation, Inc.,
22 + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 + */
24 +
25 +/*
26 + Module: rt2x00lib
27 + Abstract: rt2x00 eeprom file loading routines.
28 + */
29 +
30 +#include <linux/kernel.h>
31 +#include <linux/module.h>
32 +
33 +#include "rt2x00.h"
34 +#include "rt2x00lib.h"
35 +
36 +static int rt2x00lib_request_eeprom_file(struct rt2x00_dev *rt2x00dev)
37 +{
38 + const struct firmware *ee;
39 + char *ee_name;
40 + int retval;
41 +
42 + ee_name = rt2x00dev->ops->lib->get_eeprom_file_name(rt2x00dev);
43 + if (!ee_name) {
44 + rt2x00_err(rt2x00dev,
45 + "Invalid EEPROM filename.\n"
46 + "Please file bug report to %s.\n", DRV_PROJECT);
47 + return -EINVAL;
48 + }
49 +
50 + rt2x00_info(rt2x00dev, "Loading EEPROM data from '%s'.\n", ee_name);
51 +
52 + retval = request_firmware(&ee, ee_name, rt2x00dev->dev);
53 + if (retval) {
54 + rt2x00_err(rt2x00dev, "Failed to request EEPROM.\n");
55 + return retval;
56 + }
57 +
58 + if (!ee || !ee->size || !ee->data) {
59 + rt2x00_err(rt2x00dev, "Failed to read EEPROM file.\n");
60 + retval = -ENOENT;
61 + goto err_exit;
62 + }
63 +
64 + if (ee->size != rt2x00dev->ops->eeprom_size) {
65 + rt2x00_err(rt2x00dev,
66 + "EEPROM file size is invalid, it should be %d bytes\n",
67 + rt2x00dev->ops->eeprom_size);
68 + retval = -EINVAL;
69 + goto err_release_ee;
70 + }
71 +
72 + rt2x00dev->eeprom_file = ee;
73 + return 0;
74 +
75 +err_release_ee:
76 + release_firmware(ee);
77 +err_exit:
78 + return retval;
79 +}
80 +
81 +int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev)
82 +{
83 + int retval;
84 +
85 + if (!test_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags))
86 + return 0;
87 +
88 + if (!rt2x00dev->eeprom_file) {
89 + retval = rt2x00lib_request_eeprom_file(rt2x00dev);
90 + if (retval)
91 + return retval;
92 + }
93 +
94 + return 0;
95 +}
96 +
97 +void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev)
98 +{
99 + release_firmware(rt2x00dev->eeprom_file);
100 + rt2x00dev->eeprom_file = NULL;
101 +}
102 --- a/drivers/net/wireless/rt2x00/rt2x00.h
103 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
104 @@ -550,6 +550,7 @@ struct rt2x00lib_ops {
105 const u8 *data, const size_t len);
106 int (*load_firmware) (struct rt2x00_dev *rt2x00dev,
107 const u8 *data, const size_t len);
108 + char *(*get_eeprom_file_name) (struct rt2x00_dev *rt2x00dev);
109
110 /*
111 * Device initialization/deinitialization handlers.
112 @@ -706,6 +707,7 @@ enum rt2x00_capability_flags {
113 REQUIRE_SW_SEQNO,
114 REQUIRE_HT_TX_DESC,
115 REQUIRE_PS_AUTOWAKE,
116 + REQUIRE_EEPROM_FILE,
117
118 /*
119 * Capabilities
120 @@ -975,6 +977,11 @@ struct rt2x00_dev {
121 const struct firmware *fw;
122
123 /*
124 + * EEPROM image.
125 + */
126 + const struct firmware *eeprom_file;
127 +
128 + /*
129 * FIFO for storing tx status reports between isr and tasklet.
130 */
131 DECLARE_KFIFO_PTR(txstatus_fifo, u32);
132 --- a/drivers/net/wireless/rt2x00/rt2x00lib.h
133 +++ b/drivers/net/wireless/rt2x00/rt2x00lib.h
134 @@ -322,6 +322,22 @@ static inline void rt2x00lib_free_firmwa
135 #endif /* CPTCFG_RT2X00_LIB_FIRMWARE */
136
137 /*
138 + * EEPROM file handlers.
139 + */
140 +#ifdef CPTCFG_RT2X00_LIB_EEPROM
141 +int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev);
142 +void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev);
143 +#else
144 +static inline int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev)
145 +{
146 + return 0;
147 +}
148 +static inline void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev)
149 +{
150 +}
151 +#endif /* CPTCFG_RT2X00_LIB_EEPROM */
152 +
153 +/*
154 * Debugfs handlers.
155 */
156 #ifdef CPTCFG_RT2X00_LIB_DEBUGFS
157 --- a/drivers/net/wireless/rt2x00/Kconfig
158 +++ b/drivers/net/wireless/rt2x00/Kconfig
159 @@ -69,6 +69,7 @@ config RT2800PCI
160 select RT2X00_LIB_PCI if PCI
161 select RT2X00_LIB_SOC if SOC_RT288X || SOC_RT305X
162 select RT2X00_LIB_FIRMWARE
163 + select RT2X00_LIB_EEPROM
164 select RT2X00_LIB_CRYPTO
165 depends on CRC_CCITT
166 depends on EEPROM_93CX6
167 @@ -244,6 +245,9 @@ config RT2X00_LIB_FIRMWARE
168 config RT2X00_LIB_CRYPTO
169 boolean
170
171 +config RT2X00_LIB_EEPROM
172 + boolean
173 +
174 config RT2X00_LIB_LEDS
175 depends on !BACKPORT_KERNEL_2_6_25
176 boolean
177 --- a/drivers/net/wireless/rt2x00/Makefile
178 +++ b/drivers/net/wireless/rt2x00/Makefile
179 @@ -7,6 +7,7 @@ rt2x00lib-$(CPTCFG_RT2X00_LIB_DEBUGFS) +
180 rt2x00lib-$(CPTCFG_RT2X00_LIB_CRYPTO) += rt2x00crypto.o
181 rt2x00lib-$(CPTCFG_RT2X00_LIB_FIRMWARE) += rt2x00firmware.o
182 rt2x00lib-$(CPTCFG_RT2X00_LIB_LEDS) += rt2x00leds.o
183 +rt2x00lib-$(CPTCFG_RT2X00_LIB_EEPROM) += rt2x00eeprom.o
184
185 obj-$(CPTCFG_RT2X00_LIB) += rt2x00lib.o
186 obj-$(CPTCFG_RT2X00_LIB_MMIO) += rt2x00mmio.o
187 --- a/drivers/net/wireless/rt2x00/rt2800pci.c
188 +++ b/drivers/net/wireless/rt2x00/rt2800pci.c
189 @@ -90,25 +90,11 @@ static void rt2800pci_mcu_status(struct
190 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
191 }
192
193 -#if defined(CONFIG_SOC_RT288X) || defined(CONFIG_SOC_RT305X)
194 static int rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev)
195 {
196 - void __iomem *base_addr = ioremap(0x1F040000, EEPROM_SIZE);
197 -
198 - if (!base_addr)
199 - return -ENOMEM;
200 -
201 - memcpy_fromio(rt2x00dev->eeprom, base_addr, EEPROM_SIZE);
202 -
203 - iounmap(base_addr);
204 + memcpy(rt2x00dev->eeprom, rt2x00dev->eeprom_file->data, EEPROM_SIZE);
205 return 0;
206 }
207 -#else
208 -static inline int rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev)
209 -{
210 - return -ENOMEM;
211 -}
212 -#endif /* CONFIG_SOC_RT288X || CONFIG_SOC_RT305X */
213
214 #ifdef CONFIG_PCI
215 static void rt2800pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
216 @@ -332,6 +318,20 @@ static int rt2800pci_write_firmware(stru
217 }
218
219 /*
220 + * EEPROM file functions.
221 + */
222 +static char *rt2800pci_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
223 +{
224 + struct rt2x00_platform_data *pdata;
225 +
226 + pdata = rt2x00dev->dev->platform_data;
227 + if (pdata)
228 + return pdata->eeprom_file_name;
229 +
230 + return NULL;
231 +}
232 +
233 +/*
234 * Initialization functions.
235 */
236 static bool rt2800pci_get_entry_state(struct queue_entry *entry)
237 @@ -1160,6 +1160,7 @@ static const struct rt2x00lib_ops rt2800
238 .get_firmware_name = rt2800pci_get_firmware_name,
239 .check_firmware = rt2800_check_firmware,
240 .load_firmware = rt2800_load_firmware,
241 + .get_eeprom_file_name = rt2800pci_get_eeprom_file_name,
242 .initialize = rt2x00mmio_initialize,
243 .uninitialize = rt2x00mmio_uninitialize,
244 .get_entry_state = rt2800pci_get_entry_state,
245 --- a/drivers/net/wireless/rt2x00/rt2x00dev.c
246 +++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
247 @@ -1325,6 +1325,10 @@ int rt2x00lib_probe_dev(struct rt2x00_de
248 INIT_DELAYED_WORK(&rt2x00dev->autowakeup_work, rt2x00lib_autowakeup);
249 INIT_WORK(&rt2x00dev->sleep_work, rt2x00lib_sleep);
250
251 + retval = rt2x00lib_load_eeprom_file(rt2x00dev);
252 + if (retval)
253 + goto exit;
254 +
255 /*
256 * Let the driver probe the device to detect the capabilities.
257 */
258 @@ -1455,6 +1459,11 @@ void rt2x00lib_remove_dev(struct rt2x00_
259 */
260 if (rt2x00dev->drv_data)
261 kfree(rt2x00dev->drv_data);
262 +
263 + /*
264 + * Free EEPROM image.
265 + */
266 + rt2x00lib_free_eeprom_file(rt2x00dev);
267 }
268 EXPORT_SYMBOL_GPL(rt2x00lib_remove_dev);
269
270 --- a/drivers/net/wireless/rt2x00/rt2x00soc.c
271 +++ b/drivers/net/wireless/rt2x00/rt2x00soc.c
272 @@ -94,6 +94,7 @@ int rt2x00soc_probe(struct platform_devi
273 rt2x00dev->hw = hw;
274 rt2x00dev->irq = platform_get_irq(pdev, 0);
275 rt2x00dev->name = pdev->dev.driver->name;
276 + set_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags);
277
278 rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
279
280 --- a/.local-symbols
281 +++ b/.local-symbols
282 @@ -272,6 +272,7 @@ RT2X00_LIB_FIRMWARE=
283 RT2X00_LIB_CRYPTO=
284 RT2X00_LIB_LEDS=
285 RT2X00_LIB_DEBUGFS=
286 +RT2X00_LIB_EEPROM=
287 RT2X00_DEBUG=
288 RTLWIFI=
289 RTLWIFI_DEBUG=