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>
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;
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;
50 if (eeprom > eeprom_end)
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;
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;
73 if (to_platform_device(sc->dev)->id == 0)
74 cfg_mac = bcfg->config->wlan0_mac;
76 cfg_mac = bcfg->config->wlan1_mac;
78 memcpy(mac, cfg_mac, ETH_ALEN);
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,
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;
101 if (!pdev->dev.platform_data) {
102 dev_err(&pdev->dev, "no platform data specified\n");
107 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
109 dev_err(&pdev->dev, "no memory resource found\n");
114 mem = ioremap_nocache(res->start, resource_size(res));
116 dev_err(&pdev->dev, "ioremap failed\n");
121 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
123 dev_err(&pdev->dev, "no IRQ resource found\n");
130 hw = ieee80211_alloc_hw(sizeof(struct ath5k_softc), &ath5k_hw_ops);
132 dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
139 sc->dev = &pdev->dev;
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);
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;
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
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);
177 dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
182 platform_set_drvdata(pdev, hw);
187 ieee80211_free_hw(hw);
188 platform_set_drvdata(pdev, NULL);
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;
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);
212 reg = __raw_readl((void __iomem *) AR5K_AR5312_ENABLE);
213 if (to_platform_device(sc->dev)->id == 0)
214 reg &= ~AR5K_AR5312_ENABLE_WLAN0;
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);
222 ieee80211_free_hw(hw);
227 static struct platform_driver ath_ahb_driver = {
228 .probe = ath_ahb_probe,
229 .remove = ath_ahb_remove,
231 .name = "ar231x-wmac",
232 .owner = THIS_MODULE,
239 return platform_driver_register(&ath_ahb_driver);
245 platform_driver_unregister(&ath_ahb_driver);
248 module_init(ath5k_ahb_init);
249 module_exit(ath5k_ahb_exit);