2 * Copyright (c) 2008-2009 Atheros Communications Inc.
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/module.h>
20 #include <linux/nl80211.h>
21 #include <linux/platform_device.h>
22 #include <linux/etherdevice.h>
23 #include <ath25_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_hw *ah = common->priv;
39 struct platform_device *pdev = to_platform_device(ah->dev);
40 struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
41 u16 *eeprom, *eeprom_end;
43 eeprom = (u16 *) bcfg->radio;
44 eeprom_end = ((void *) bcfg->config) + BOARD_CONFIG_BUFSZ;
47 if (eeprom > eeprom_end)
54 int ath5k_hw_read_srev(struct ath5k_hw *ah)
56 struct platform_device *pdev = to_platform_device(ah->dev);
57 struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
58 ah->ah_mac_srev = bcfg->devid;
62 static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
64 struct platform_device *pdev = to_platform_device(ah->dev);
65 struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
68 if (to_platform_device(ah->dev)->id == 0)
69 cfg_mac = bcfg->config->wlan0_mac;
71 cfg_mac = bcfg->config->wlan1_mac;
73 memcpy(mac, cfg_mac, ETH_ALEN);
77 static const struct ath_bus_ops ath_ahb_bus_ops = {
78 .ath_bus_type = ATH_AHB,
79 .read_cachesize = ath5k_ahb_read_cachesize,
80 .eeprom_read = ath5k_ahb_eeprom_read,
81 .eeprom_read_mac = ath5k_ahb_eeprom_read_mac,
85 static int ath_ahb_probe(struct platform_device *pdev)
87 struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
89 struct ieee80211_hw *hw;
96 if (!dev_get_platdata(&pdev->dev)) {
97 dev_err(&pdev->dev, "no platform data specified\n");
102 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
104 dev_err(&pdev->dev, "no memory resource found\n");
109 mem = ioremap(res->start, resource_size(res));
111 dev_err(&pdev->dev, "ioremap failed\n");
116 irq = platform_get_irq(pdev, 0);
122 hw = ieee80211_alloc_hw(sizeof(struct ath5k_hw), &ath5k_hw_ops);
124 dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
131 ah->dev = &pdev->dev;
134 ah->devid = bcfg->devid;
136 if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
137 /* Enable WMAC AHB arbitration */
138 reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
139 reg |= AR5K_AR2315_AHB_ARB_CTL_WLAN;
140 iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
142 /* Enable global WMAC swapping */
143 reg = ioread32((void __iomem *) AR5K_AR2315_BYTESWAP);
144 reg |= AR5K_AR2315_BYTESWAP_WMAC;
145 iowrite32(reg, (void __iomem *) AR5K_AR2315_BYTESWAP);
147 /* Enable WMAC DMA access (assuming 5312 or 231x*/
148 /* TODO: check other platforms */
149 reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
150 if (to_platform_device(ah->dev)->id == 0)
151 reg |= AR5K_AR5312_ENABLE_WLAN0;
153 reg |= AR5K_AR5312_ENABLE_WLAN1;
154 iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
157 * On a dual-band AR5312, the multiband radio is only
158 * used as pass-through. Disable 2 GHz support in the
161 if (to_platform_device(ah->dev)->id == 0 &&
162 (bcfg->config->flags & (BD_WLAN0 | BD_WLAN1)) ==
163 (BD_WLAN1 | BD_WLAN0))
164 ah->ah_capabilities.cap_needs_2GHz_ovr = true;
166 ah->ah_capabilities.cap_needs_2GHz_ovr = false;
169 ret = ath5k_init_ah(ah, &ath_ahb_bus_ops);
171 dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
176 platform_set_drvdata(pdev, hw);
181 ieee80211_free_hw(hw);
188 static void ath_ahb_remove(struct platform_device *pdev)
190 struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
191 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
200 if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
201 /* Disable WMAC AHB arbitration */
202 reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
203 reg &= ~AR5K_AR2315_AHB_ARB_CTL_WLAN;
204 iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
207 reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
208 if (to_platform_device(ah->dev)->id == 0)
209 reg &= ~AR5K_AR5312_ENABLE_WLAN0;
211 reg &= ~AR5K_AR5312_ENABLE_WLAN1;
212 iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
217 ieee80211_free_hw(hw);
220 static struct platform_driver ath_ahb_driver = {
221 .probe = ath_ahb_probe,
222 .remove = ath_ahb_remove,
224 .name = "ar231x-wmac",
228 module_platform_driver(ath_ahb_driver);