ath5k: disable 5 GHz support for the dualband PHY chip on dual-radio AR5312
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / wireless / ath / ath5k / ahb.c
blobea99827815599e9028682de9b4c2276d2d7939f3
1 /*
2 * Copyright (c) 2008-2009 Atheros Communications Inc.
3 * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
4 * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <linux/nl80211.h>
20 #include <linux/platform_device.h>
21 #include <linux/etherdevice.h>
22 #include <ar231x_platform.h>
23 #include "ath5k.h"
24 #include "debug.h"
25 #include "base.h"
26 #include "reg.h"
27 #include "debug.h"
29 /* return bus cachesize in 4B word units */
30 static void ath5k_ahb_read_cachesize(struct ath_common *common, int *csz)
32 *csz = L1_CACHE_BYTES >> 2;
35 static bool
36 ath5k_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
38 struct ath5k_softc *sc = common->priv;
39 struct platform_device *pdev = to_platform_device(sc->dev);
40 struct ar231x_board_config *bcfg = pdev->dev.platform_data;
41 u16 *eeprom, *eeprom_end;
45 bcfg = pdev->dev.platform_data;
46 eeprom = (u16 *) bcfg->radio;
47 eeprom_end = ((void *) bcfg->config) + BOARD_CONFIG_BUFSZ;
49 eeprom += off;
50 if (eeprom > eeprom_end)
51 return false;
53 *data = *eeprom;
54 return true;
57 int ath5k_hw_read_srev(struct ath5k_hw *ah)
59 struct ath5k_softc *sc = ah->ah_sc;
60 struct platform_device *pdev = to_platform_device(sc->dev);
61 struct ar231x_board_config *bcfg = pdev->dev.platform_data;
62 ah->ah_mac_srev = bcfg->devid;
63 return 0;
66 static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
68 struct ath5k_softc *sc = ah->ah_sc;
69 struct platform_device *pdev = to_platform_device(sc->dev);
70 struct ar231x_board_config *bcfg = pdev->dev.platform_data;
71 u8 *cfg_mac;
73 if (to_platform_device(sc->dev)->id == 0)
74 cfg_mac = bcfg->config->wlan0_mac;
75 else
76 cfg_mac = bcfg->config->wlan1_mac;
78 memcpy(mac, cfg_mac, ETH_ALEN);
79 return 0;
82 static const struct ath_bus_ops ath_ahb_bus_ops = {
83 .ath_bus_type = ATH_AHB,
84 .read_cachesize = ath5k_ahb_read_cachesize,
85 .eeprom_read = ath5k_ahb_eeprom_read,
86 .eeprom_read_mac = ath5k_ahb_eeprom_read_mac,
89 /*Initialization*/
90 static int ath_ahb_probe(struct platform_device *pdev)
92 struct ar231x_board_config *bcfg = pdev->dev.platform_data;
93 struct ath5k_softc *sc;
94 struct ieee80211_hw *hw;
95 struct resource *res;
96 void __iomem *mem;
97 int irq;
98 int ret = 0;
99 u32 reg;
101 if (!pdev->dev.platform_data) {
102 dev_err(&pdev->dev, "no platform data specified\n");
103 ret = -EINVAL;
104 goto err_out;
107 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
108 if (res == NULL) {
109 dev_err(&pdev->dev, "no memory resource found\n");
110 ret = -ENXIO;
111 goto err_out;
114 mem = ioremap_nocache(res->start, resource_size(res));
115 if (mem == NULL) {
116 dev_err(&pdev->dev, "ioremap failed\n");
117 ret = -ENOMEM;
118 goto err_out;
121 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
122 if (res == NULL) {
123 dev_err(&pdev->dev, "no IRQ resource found\n");
124 ret = -ENXIO;
125 goto err_out;
128 irq = res->start;
130 hw = ieee80211_alloc_hw(sizeof(struct ath5k_softc), &ath5k_hw_ops);
131 if (hw == NULL) {
132 dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
133 ret = -ENOMEM;
134 goto err_out;
137 sc = hw->priv;
138 sc->hw = hw;
139 sc->dev = &pdev->dev;
140 sc->iobase = mem;
141 sc->irq = irq;
142 sc->devid = bcfg->devid;
144 if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
145 /* Enable WMAC AHB arbitration */
146 reg = __raw_readl((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
147 reg |= AR5K_AR2315_AHB_ARB_CTL_WLAN;
148 __raw_writel(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
150 /* Enable global WMAC swapping */
151 reg = __raw_readl((void __iomem *) AR5K_AR2315_BYTESWAP);
152 reg |= AR5K_AR2315_BYTESWAP_WMAC;
153 __raw_writel(reg, (void __iomem *) AR5K_AR2315_BYTESWAP);
154 } else {
155 /* Enable WMAC DMA access (assuming 5312 or 231x*/
156 /* TODO: check other platforms */
157 reg = __raw_readl((void __iomem *) AR5K_AR5312_ENABLE);
158 if (to_platform_device(sc->dev)->id == 0)
159 reg |= AR5K_AR5312_ENABLE_WLAN0;
160 else
161 reg |= AR5K_AR5312_ENABLE_WLAN1;
162 __raw_writel(reg, (void __iomem *) AR5K_AR5312_ENABLE);
165 * On a dual-band AR5312, the multiband radio is only
166 * used as pass-through. Disable 2 GHz support in the
167 * driver for it
169 if (to_platform_device(sc->dev)->id == 0 &&
170 (bcfg->config->flags & (BD_WLAN0|BD_WLAN1)) ==
171 (BD_WLAN1|BD_WLAN0))
172 __set_bit(ATH_STAT_2G_DISABLED, sc->status);
175 ret = ath5k_init_softc(sc, &ath_ahb_bus_ops);
176 if (ret != 0) {
177 dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
178 ret = -ENODEV;
179 goto err_free_hw;
182 platform_set_drvdata(pdev, hw);
184 return 0;
186 err_free_hw:
187 ieee80211_free_hw(hw);
188 platform_set_drvdata(pdev, NULL);
189 err_out:
190 return ret;
193 static int ath_ahb_remove(struct platform_device *pdev)
195 struct ar231x_board_config *bcfg = pdev->dev.platform_data;
196 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
197 struct ath5k_softc *sc;
198 u32 reg;
200 if (!hw)
201 return 0;
203 sc = hw->priv;
205 if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
206 /* Disable WMAC AHB arbitration */
207 reg = __raw_readl((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
208 reg &= ~AR5K_AR2315_AHB_ARB_CTL_WLAN;
209 __raw_writel(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
210 } else {
211 /*Stop DMA access */
212 reg = __raw_readl((void __iomem *) AR5K_AR5312_ENABLE);
213 if (to_platform_device(sc->dev)->id == 0)
214 reg &= ~AR5K_AR5312_ENABLE_WLAN0;
215 else
216 reg &= ~AR5K_AR5312_ENABLE_WLAN1;
217 __raw_writel(reg, (void __iomem *) AR5K_AR5312_ENABLE);
220 ath5k_deinit_softc(sc);
221 platform_set_drvdata(pdev, NULL);
223 return 0;
226 static struct platform_driver ath_ahb_driver = {
227 .probe = ath_ahb_probe,
228 .remove = ath_ahb_remove,
229 .driver = {
230 .name = "ar231x-wmac",
231 .owner = THIS_MODULE,
235 static int __init
236 ath5k_ahb_init(void)
238 return platform_driver_register(&ath_ahb_driver);
241 static void __exit
242 ath5k_ahb_exit(void)
244 platform_driver_unregister(&ath_ahb_driver);
247 module_init(ath5k_ahb_init);
248 module_exit(ath5k_ahb_exit);