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 <ar231x_platform.h>
28 /* return bus cachesize in 4B word units */
29 static void ath5k_ahb_read_cachesize(struct ath_common *common, int *csz)
31 *csz = L1_CACHE_BYTES >> 2;
34 bool ath5k_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
36 struct ath5k_softc *sc = common->priv;
37 struct platform_device *pdev = to_platform_device(sc->dev);
38 struct ar231x_board_config *bcfg = pdev->dev.platform_data;
39 u16 *eeprom, *eeprom_end;
43 bcfg = pdev->dev.platform_data;
44 eeprom = (u16 *) bcfg->radio;
45 eeprom_end = ((void *) bcfg->config) + BOARD_CONFIG_BUFSZ;
48 if (eeprom > eeprom_end)
55 int ath5k_hw_read_srev(struct ath5k_hw *ah)
57 struct ath5k_softc *sc = ah->ah_sc;
58 struct platform_device *pdev = to_platform_device(sc->dev);
59 struct ar231x_board_config *bcfg = pdev->dev.platform_data;
60 ah->ah_mac_srev = bcfg->devid;
64 static const struct ath_bus_ops ath_ahb_bus_ops = {
65 .ath_bus_type = ATH_AHB,
66 .read_cachesize = ath5k_ahb_read_cachesize,
67 .eeprom_read = ath5k_ahb_eeprom_read,
71 static int ath_ahb_probe(struct platform_device *pdev)
73 struct ar231x_board_config *bcfg = pdev->dev.platform_data;
74 struct ath5k_softc *sc;
75 struct ieee80211_hw *hw;
82 if (!pdev->dev.platform_data) {
83 dev_err(&pdev->dev, "no platform data specified\n");
88 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
90 dev_err(&pdev->dev, "no memory resource found\n");
95 mem = ioremap_nocache(res->start, res->end - res->start + 1);
97 dev_err(&pdev->dev, "ioremap failed\n");
102 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
104 dev_err(&pdev->dev, "no IRQ resource found\n");
111 hw = ieee80211_alloc_hw(sizeof(struct ath5k_softc), &ath5k_hw_ops);
113 dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
120 sc->dev = &pdev->dev;
123 sc->devid = bcfg->devid;
125 if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
126 /* Enable WMAC AHB arbitration */
127 reg = __raw_readl((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
128 reg |= AR5K_AR2315_AHB_ARB_CTL_WLAN;
129 __raw_writel(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
131 /* Enable global WMAC swapping */
132 reg = __raw_readl((void __iomem *) AR5K_AR2315_BYTESWAP);
133 reg |= AR5K_AR2315_BYTESWAP_WMAC;
134 __raw_writel(reg, (void __iomem *) AR5K_AR2315_BYTESWAP);
136 /* Enable WMAC DMA access (assuming 5312 or 231x*/
137 /* TODO: check other platforms */
138 reg = __raw_readl((void __iomem *) AR5K_AR5312_ENABLE);
139 if (to_platform_device(sc->dev)->id == 0)
140 reg |= AR5K_AR5312_ENABLE_WLAN0;
142 reg |= AR5K_AR5312_ENABLE_WLAN1;
143 __raw_writel(reg, (void __iomem *) AR5K_AR5312_ENABLE);
146 ret = ath5k_init_softc(sc, &ath_ahb_bus_ops);
148 dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
153 platform_set_drvdata(pdev, hw);
158 ieee80211_free_hw(hw);
159 platform_set_drvdata(pdev, NULL);
164 static int ath_ahb_remove(struct platform_device *pdev)
166 struct ar231x_board_config *bcfg = pdev->dev.platform_data;
167 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
168 struct ath5k_softc *sc;
176 if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
177 /* Disable WMAC AHB arbitration */
178 reg = __raw_readl((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
179 reg &= ~AR5K_AR2315_AHB_ARB_CTL_WLAN;
180 __raw_writel(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
183 reg = __raw_readl((void __iomem *) AR5K_AR5312_ENABLE);
184 if (to_platform_device(sc->dev)->id == 0)
185 reg &= ~AR5K_AR5312_ENABLE_WLAN0;
187 reg &= ~AR5K_AR5312_ENABLE_WLAN1;
188 __raw_writel(reg, (void __iomem *) AR5K_AR5312_ENABLE);
191 ath5k_deinit_softc(sc);
192 platform_set_drvdata(pdev, NULL);
197 static struct platform_driver ath_ahb_driver = {
198 .probe = ath_ahb_probe,
199 .remove = ath_ahb_remove,
201 .name = "ar231x-wmac",
202 .owner = THIS_MODULE,
209 return platform_driver_register(&ath_ahb_driver);
215 platform_driver_unregister(&ath_ahb_driver);
218 module_init(ath5k_ahb_init);
219 module_exit(ath5k_ahb_exit);