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"
5 This reverts commit 093ec3c5337434f40d77c1af06c139da3e5ba6dc.
7 create mode 100644 drivers/net/wireless/ath/ath5k/ahb.c
9 --- a/drivers/net/wireless/ath/ath5k/Kconfig
10 +++ b/drivers/net/wireless/ath/ath5k/Kconfig
13 tristate "Atheros 5xxx wireless cards support"
15 - depends on PCI && MAC80211
16 + depends on (PCI || ATHEROS_AR231X) && MAC80211
19 select BACKPORT_LEDS_CLASS
20 select BACKPORT_NEW_LEDS
21 select BACKPORT_AVERAGE
23 + select ATH5K_AHB if (ATHEROS_AR231X && !PCI)
24 + select ATH5K_PCI if (!ATHEROS_AR231X && PCI)
26 This module adds support for wireless adapters based on
28 @@ -52,9 +53,16 @@ config ATH5K_TRACER
33 + bool "Atheros 5xxx AHB bus support"
34 + depends on (ATHEROS_AR231X && !PCI)
36 + This adds support for WiSoC type chipsets of the 5xxx Atheros
40 bool "Atheros 5xxx PCI bus support"
42 + depends on (!ATHEROS_AR231X && PCI)
44 This adds support for PCI type chipsets of the 5xxx Atheros
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
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
56 +++ b/drivers/net/wireless/ath/ath5k/ahb.c
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>
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.
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.
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>
86 +/* return bus cachesize in 4B word units */
87 +static void ath5k_ahb_read_cachesize(struct ath_common *common, int *csz)
89 + *csz = L1_CACHE_BYTES >> 2;
93 +ath5k_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
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;
100 + eeprom = (u16 *) bcfg->radio;
101 + eeprom_end = ((void *) bcfg->config) + BOARD_CONFIG_BUFSZ;
104 + if (eeprom > eeprom_end)
111 +int ath5k_hw_read_srev(struct ath5k_hw *ah)
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;
119 +static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
121 + struct platform_device *pdev = to_platform_device(ah->dev);
122 + struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
125 + if (to_platform_device(ah->dev)->id == 0)
126 + cfg_mac = bcfg->config->wlan0_mac;
128 + cfg_mac = bcfg->config->wlan1_mac;
130 + memcpy(mac, cfg_mac, ETH_ALEN);
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,
142 +static int ath_ahb_probe(struct platform_device *pdev)
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;
153 + if (!dev_get_platdata(&pdev->dev)) {
154 + dev_err(&pdev->dev, "no platform data specified\n");
159 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
161 + dev_err(&pdev->dev, "no memory resource found\n");
166 + mem = ioremap_nocache(res->start, resource_size(res));
168 + dev_err(&pdev->dev, "ioremap failed\n");
173 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
175 + dev_err(&pdev->dev, "no IRQ resource found\n");
182 + hw = ieee80211_alloc_hw(sizeof(struct ath5k_hw), &ath5k_hw_ops);
184 + dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
191 + ah->dev = &pdev->dev;
194 + ah->devid = bcfg->devid;
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);
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);
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;
213 + reg |= AR5K_AR5312_ENABLE_WLAN1;
214 + iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
217 + * On a dual-band AR5312, the multiband radio is only
218 + * used as pass-through. Disable 2 GHz support in the
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;
226 + ah->ah_capabilities.cap_needs_2GHz_ovr = false;
229 + ret = ath5k_init_ah(ah, &ath_ahb_bus_ops);
231 + dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
236 + platform_set_drvdata(pdev, hw);
241 + ieee80211_free_hw(hw);
248 +static int ath_ahb_remove(struct platform_device *pdev)
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;
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);
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;
271 + reg &= ~AR5K_AR5312_ENABLE_WLAN1;
272 + iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
275 + ath5k_deinit_ah(ah);
276 + iounmap(ah->iobase);
277 + ieee80211_free_hw(hw);
282 +static struct platform_driver ath_ahb_driver = {
283 + .probe = ath_ahb_probe,
284 + .remove = ath_ahb_remove,
286 + .name = "ar231x-wmac",
287 + .owner = THIS_MODULE,
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);
298 +#ifdef CONFIG_ATHEROS_AR231X
299 +#define AR5K_AR2315_PCI_BASE ((void __iomem *)0xb0100000)
301 +static inline void __iomem *ath5k_ahb_reg(struct ath5k_hw *ah, u16 reg)
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;
309 + return ah->iobase + reg;
312 +static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
314 + return ioread32(ath5k_ahb_reg(ah, reg));
317 +static inline void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
319 + iowrite32(val, ath5k_ahb_reg(ah, reg));
324 static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
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);
333 static inline enum ath_bus_type ath5k_get_bus_type(struct ath5k_hw *ah)
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 *
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 },
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 },
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 },
370 { "xxxxx", AR5K_VERSION_RAD, AR5K_SREV_UNKNOWN },
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)
378 struct ieee80211_hw *hw = ah->hw;
379 +#ifndef CONFIG_ATHEROS_AR231X
380 struct pci_dev *pdev = ah->pdev;
382 char name[ATH5K_LED_MAX_NAME_LEN + 1];
383 const struct pci_device_id *match;
388 +#ifdef CONFIG_ATHEROS_AR231X
391 match = pci_match_id(&ath5k_led_devices[0], pdev);
394 __set_bit(ATH_STAT_LEDSOFT, ah->status);
395 ah->led_pin = ATH_PIN(match->driver_data);