iw: update to 3.17
[openwrt/svn-archive/archive.git] / package / kernel / mac80211 / patches / 300-Revert-ath5k-Remove-AHB-bus-support.patch
1 From: Felix Fietkau <nbd@openwrt.org>
2 Date: Sat, 27 Sep 2014 15:57:09 +0200
3 Subject: [PATCH] Revert "ath5k: Remove AHB bus support"
4
5 This reverts commit 093ec3c5337434f40d77c1af06c139da3e5ba6dc.
6 ---
7 create mode 100644 drivers/net/wireless/ath/ath5k/ahb.c
8
9 --- a/drivers/net/wireless/ath/ath5k/Kconfig
10 +++ b/drivers/net/wireless/ath/ath5k/Kconfig
11 @@ -1,13 +1,14 @@
12 config ATH5K
13 tristate "Atheros 5xxx wireless cards support"
14 depends on m
15 - depends on PCI && MAC80211
16 + depends on (PCI || ATHEROS_AR231X) && MAC80211
17 select ATH_COMMON
18 select MAC80211_LEDS
19 select BACKPORT_LEDS_CLASS
20 select BACKPORT_NEW_LEDS
21 select BACKPORT_AVERAGE
22 - select ATH5K_PCI
23 + select ATH5K_AHB if (ATHEROS_AR231X && !PCI)
24 + select ATH5K_PCI if (!ATHEROS_AR231X && PCI)
25 ---help---
26 This module adds support for wireless adapters based on
27 Atheros 5xxx chipset.
28 @@ -52,9 +53,16 @@ config ATH5K_TRACER
29
30 If unsure, say N.
31
32 +config ATH5K_AHB
33 + bool "Atheros 5xxx AHB bus support"
34 + depends on (ATHEROS_AR231X && !PCI)
35 + ---help---
36 + This adds support for WiSoC type chipsets of the 5xxx Atheros
37 + family.
38 +
39 config ATH5K_PCI
40 bool "Atheros 5xxx PCI bus support"
41 - depends on PCI
42 + depends on (!ATHEROS_AR231X && PCI)
43 ---help---
44 This adds support for PCI type chipsets of the 5xxx Atheros
45 family.
46 --- a/drivers/net/wireless/ath/ath5k/Makefile
47 +++ b/drivers/net/wireless/ath/ath5k/Makefile
48 @@ -17,5 +17,6 @@ ath5k-y += ani.o
49 ath5k-y += sysfs.o
50 ath5k-y += mac80211-ops.o
51 ath5k-$(CPTCFG_ATH5K_DEBUG) += debug.o
52 +ath5k-$(CPTCFG_ATH5K_AHB) += ahb.o
53 ath5k-$(CPTCFG_ATH5K_PCI) += pci.o
54 obj-$(CPTCFG_ATH5K) += ath5k.o
55 --- /dev/null
56 +++ b/drivers/net/wireless/ath/ath5k/ahb.c
57 @@ -0,0 +1,234 @@
58 +/*
59 + * Copyright (c) 2008-2009 Atheros Communications Inc.
60 + * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
61 + * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
62 + *
63 + * Permission to use, copy, modify, and/or distribute this software for any
64 + * purpose with or without fee is hereby granted, provided that the above
65 + * copyright notice and this permission notice appear in all copies.
66 + *
67 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
68 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
69 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
70 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
71 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
72 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
73 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
74 + */
75 +
76 +#include <linux/nl80211.h>
77 +#include <linux/platform_device.h>
78 +#include <linux/etherdevice.h>
79 +#include <linux/export.h>
80 +#include <ar231x_platform.h>
81 +#include "ath5k.h"
82 +#include "debug.h"
83 +#include "base.h"
84 +#include "reg.h"
85 +
86 +/* return bus cachesize in 4B word units */
87 +static void ath5k_ahb_read_cachesize(struct ath_common *common, int *csz)
88 +{
89 + *csz = L1_CACHE_BYTES >> 2;
90 +}
91 +
92 +static bool
93 +ath5k_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
94 +{
95 + struct ath5k_hw *ah = common->priv;
96 + struct platform_device *pdev = to_platform_device(ah->dev);
97 + struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
98 + u16 *eeprom, *eeprom_end;
99 +
100 + eeprom = (u16 *) bcfg->radio;
101 + eeprom_end = ((void *) bcfg->config) + BOARD_CONFIG_BUFSZ;
102 +
103 + eeprom += off;
104 + if (eeprom > eeprom_end)
105 + return false;
106 +
107 + *data = *eeprom;
108 + return true;
109 +}
110 +
111 +int ath5k_hw_read_srev(struct ath5k_hw *ah)
112 +{
113 + struct platform_device *pdev = to_platform_device(ah->dev);
114 + struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
115 + ah->ah_mac_srev = bcfg->devid;
116 + return 0;
117 +}
118 +
119 +static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
120 +{
121 + struct platform_device *pdev = to_platform_device(ah->dev);
122 + struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
123 + u8 *cfg_mac;
124 +
125 + if (to_platform_device(ah->dev)->id == 0)
126 + cfg_mac = bcfg->config->wlan0_mac;
127 + else
128 + cfg_mac = bcfg->config->wlan1_mac;
129 +
130 + memcpy(mac, cfg_mac, ETH_ALEN);
131 + return 0;
132 +}
133 +
134 +static const struct ath_bus_ops ath_ahb_bus_ops = {
135 + .ath_bus_type = ATH_AHB,
136 + .read_cachesize = ath5k_ahb_read_cachesize,
137 + .eeprom_read = ath5k_ahb_eeprom_read,
138 + .eeprom_read_mac = ath5k_ahb_eeprom_read_mac,
139 +};
140 +
141 +/*Initialization*/
142 +static int ath_ahb_probe(struct platform_device *pdev)
143 +{
144 + struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
145 + struct ath5k_hw *ah;
146 + struct ieee80211_hw *hw;
147 + struct resource *res;
148 + void __iomem *mem;
149 + int irq;
150 + int ret = 0;
151 + u32 reg;
152 +
153 + if (!dev_get_platdata(&pdev->dev)) {
154 + dev_err(&pdev->dev, "no platform data specified\n");
155 + ret = -EINVAL;
156 + goto err_out;
157 + }
158 +
159 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
160 + if (res == NULL) {
161 + dev_err(&pdev->dev, "no memory resource found\n");
162 + ret = -ENXIO;
163 + goto err_out;
164 + }
165 +
166 + mem = ioremap_nocache(res->start, resource_size(res));
167 + if (mem == NULL) {
168 + dev_err(&pdev->dev, "ioremap failed\n");
169 + ret = -ENOMEM;
170 + goto err_out;
171 + }
172 +
173 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
174 + if (res == NULL) {
175 + dev_err(&pdev->dev, "no IRQ resource found\n");
176 + ret = -ENXIO;
177 + goto err_iounmap;
178 + }
179 +
180 + irq = res->start;
181 +
182 + hw = ieee80211_alloc_hw(sizeof(struct ath5k_hw), &ath5k_hw_ops);
183 + if (hw == NULL) {
184 + dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
185 + ret = -ENOMEM;
186 + goto err_iounmap;
187 + }
188 +
189 + ah = hw->priv;
190 + ah->hw = hw;
191 + ah->dev = &pdev->dev;
192 + ah->iobase = mem;
193 + ah->irq = irq;
194 + ah->devid = bcfg->devid;
195 +
196 + if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
197 + /* Enable WMAC AHB arbitration */
198 + reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
199 + reg |= AR5K_AR2315_AHB_ARB_CTL_WLAN;
200 + iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
201 +
202 + /* Enable global WMAC swapping */
203 + reg = ioread32((void __iomem *) AR5K_AR2315_BYTESWAP);
204 + reg |= AR5K_AR2315_BYTESWAP_WMAC;
205 + iowrite32(reg, (void __iomem *) AR5K_AR2315_BYTESWAP);
206 + } else {
207 + /* Enable WMAC DMA access (assuming 5312 or 231x*/
208 + /* TODO: check other platforms */
209 + reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
210 + if (to_platform_device(ah->dev)->id == 0)
211 + reg |= AR5K_AR5312_ENABLE_WLAN0;
212 + else
213 + reg |= AR5K_AR5312_ENABLE_WLAN1;
214 + iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
215 +
216 + /*
217 + * On a dual-band AR5312, the multiband radio is only
218 + * used as pass-through. Disable 2 GHz support in the
219 + * driver for it
220 + */
221 + if (to_platform_device(ah->dev)->id == 0 &&
222 + (bcfg->config->flags & (BD_WLAN0 | BD_WLAN1)) ==
223 + (BD_WLAN1 | BD_WLAN0))
224 + ah->ah_capabilities.cap_needs_2GHz_ovr = true;
225 + else
226 + ah->ah_capabilities.cap_needs_2GHz_ovr = false;
227 + }
228 +
229 + ret = ath5k_init_ah(ah, &ath_ahb_bus_ops);
230 + if (ret != 0) {
231 + dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
232 + ret = -ENODEV;
233 + goto err_free_hw;
234 + }
235 +
236 + platform_set_drvdata(pdev, hw);
237 +
238 + return 0;
239 +
240 + err_free_hw:
241 + ieee80211_free_hw(hw);
242 + err_iounmap:
243 + iounmap(mem);
244 + err_out:
245 + return ret;
246 +}
247 +
248 +static int ath_ahb_remove(struct platform_device *pdev)
249 +{
250 + struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
251 + struct ieee80211_hw *hw = platform_get_drvdata(pdev);
252 + struct ath5k_hw *ah;
253 + u32 reg;
254 +
255 + if (!hw)
256 + return 0;
257 +
258 + ah = hw->priv;
259 +
260 + if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
261 + /* Disable WMAC AHB arbitration */
262 + reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
263 + reg &= ~AR5K_AR2315_AHB_ARB_CTL_WLAN;
264 + iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
265 + } else {
266 + /*Stop DMA access */
267 + reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
268 + if (to_platform_device(ah->dev)->id == 0)
269 + reg &= ~AR5K_AR5312_ENABLE_WLAN0;
270 + else
271 + reg &= ~AR5K_AR5312_ENABLE_WLAN1;
272 + iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
273 + }
274 +
275 + ath5k_deinit_ah(ah);
276 + iounmap(ah->iobase);
277 + ieee80211_free_hw(hw);
278 +
279 + return 0;
280 +}
281 +
282 +static struct platform_driver ath_ahb_driver = {
283 + .probe = ath_ahb_probe,
284 + .remove = ath_ahb_remove,
285 + .driver = {
286 + .name = "ar231x-wmac",
287 + .owner = THIS_MODULE,
288 + },
289 +};
290 +
291 +module_platform_driver(ath_ahb_driver);
292 --- a/drivers/net/wireless/ath/ath5k/ath5k.h
293 +++ b/drivers/net/wireless/ath/ath5k/ath5k.h
294 @@ -1647,6 +1647,32 @@ static inline struct ath_regulatory *ath
295 return &(ath5k_hw_common(ah)->regulatory);
296 }
297
298 +#ifdef CONFIG_ATHEROS_AR231X
299 +#define AR5K_AR2315_PCI_BASE ((void __iomem *)0xb0100000)
300 +
301 +static inline void __iomem *ath5k_ahb_reg(struct ath5k_hw *ah, u16 reg)
302 +{
303 + /* On AR2315 and AR2317 the PCI clock domain registers
304 + * are outside of the WMAC register space */
305 + if (unlikely((reg >= 0x4000) && (reg < 0x5000) &&
306 + (ah->ah_mac_srev >= AR5K_SREV_AR2315_R6)))
307 + return AR5K_AR2315_PCI_BASE + reg;
308 +
309 + return ah->iobase + reg;
310 +}
311 +
312 +static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
313 +{
314 + return ioread32(ath5k_ahb_reg(ah, reg));
315 +}
316 +
317 +static inline void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
318 +{
319 + iowrite32(val, ath5k_ahb_reg(ah, reg));
320 +}
321 +
322 +#else
323 +
324 static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
325 {
326 return ioread32(ah->iobase + reg);
327 @@ -1657,6 +1683,8 @@ static inline void ath5k_hw_reg_write(st
328 iowrite32(val, ah->iobase + reg);
329 }
330
331 +#endif
332 +
333 static inline enum ath_bus_type ath5k_get_bus_type(struct ath5k_hw *ah)
334 {
335 return ath5k_hw_common(ah)->bus_ops->ath_bus_type;
336 --- a/drivers/net/wireless/ath/ath5k/base.c
337 +++ b/drivers/net/wireless/ath/ath5k/base.c
338 @@ -99,6 +99,15 @@ static int ath5k_reset(struct ath5k_hw *
339
340 /* Known SREVs */
341 static const struct ath5k_srev_name srev_names[] = {
342 +#ifdef CONFIG_ATHEROS_AR231X
343 + { "5312", AR5K_VERSION_MAC, AR5K_SREV_AR5312_R2 },
344 + { "5312", AR5K_VERSION_MAC, AR5K_SREV_AR5312_R7 },
345 + { "2313", AR5K_VERSION_MAC, AR5K_SREV_AR2313_R8 },
346 + { "2315", AR5K_VERSION_MAC, AR5K_SREV_AR2315_R6 },
347 + { "2315", AR5K_VERSION_MAC, AR5K_SREV_AR2315_R7 },
348 + { "2317", AR5K_VERSION_MAC, AR5K_SREV_AR2317_R1 },
349 + { "2317", AR5K_VERSION_MAC, AR5K_SREV_AR2317_R2 },
350 +#else
351 { "5210", AR5K_VERSION_MAC, AR5K_SREV_AR5210 },
352 { "5311", AR5K_VERSION_MAC, AR5K_SREV_AR5311 },
353 { "5311A", AR5K_VERSION_MAC, AR5K_SREV_AR5311A },
354 @@ -117,6 +126,7 @@ static const struct ath5k_srev_name srev
355 { "5418", AR5K_VERSION_MAC, AR5K_SREV_AR5418 },
356 { "2425", AR5K_VERSION_MAC, AR5K_SREV_AR2425 },
357 { "2417", AR5K_VERSION_MAC, AR5K_SREV_AR2417 },
358 +#endif
359 { "xxxxx", AR5K_VERSION_MAC, AR5K_SREV_UNKNOWN },
360 { "5110", AR5K_VERSION_RAD, AR5K_SREV_RAD_5110 },
361 { "5111", AR5K_VERSION_RAD, AR5K_SREV_RAD_5111 },
362 @@ -132,6 +142,10 @@ static const struct ath5k_srev_name srev
363 { "5413", AR5K_VERSION_RAD, AR5K_SREV_RAD_5413 },
364 { "5424", AR5K_VERSION_RAD, AR5K_SREV_RAD_5424 },
365 { "5133", AR5K_VERSION_RAD, AR5K_SREV_RAD_5133 },
366 +#ifdef CONFIG_ATHEROS_AR231X
367 + { "2316", AR5K_VERSION_RAD, AR5K_SREV_RAD_2316 },
368 + { "2317", AR5K_VERSION_RAD, AR5K_SREV_RAD_2317 },
369 +#endif
370 { "xxxxx", AR5K_VERSION_RAD, AR5K_SREV_UNKNOWN },
371 };
372
373 --- a/drivers/net/wireless/ath/ath5k/led.c
374 +++ b/drivers/net/wireless/ath/ath5k/led.c
375 @@ -163,14 +163,20 @@ int ath5k_init_leds(struct ath5k_hw *ah)
376 {
377 int ret = 0;
378 struct ieee80211_hw *hw = ah->hw;
379 +#ifndef CONFIG_ATHEROS_AR231X
380 struct pci_dev *pdev = ah->pdev;
381 +#endif
382 char name[ATH5K_LED_MAX_NAME_LEN + 1];
383 const struct pci_device_id *match;
384
385 if (!ah->pdev)
386 return 0;
387
388 +#ifdef CONFIG_ATHEROS_AR231X
389 + match = NULL;
390 +#else
391 match = pci_match_id(&ath5k_led_devices[0], pdev);
392 +#endif
393 if (match) {
394 __set_bit(ATH_STAT_LEDSOFT, ah->status);
395 ah->led_pin = ATH_PIN(match->driver_data);