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 <linux/export.h>
23 #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_hw
*ah
= common
->priv
;
39 struct platform_device
*pdev
= to_platform_device(ah
->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 platform_device
*pdev
= to_platform_device(ah
->dev
);
60 struct ar231x_board_config
*bcfg
= pdev
->dev
.platform_data
;
61 ah
->ah_mac_srev
= bcfg
->devid
;
65 static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw
*ah
, u8
*mac
)
67 struct platform_device
*pdev
= to_platform_device(ah
->dev
);
68 struct ar231x_board_config
*bcfg
= pdev
->dev
.platform_data
;
71 if (to_platform_device(ah
->dev
)->id
== 0)
72 cfg_mac
= bcfg
->config
->wlan0_mac
;
74 cfg_mac
= bcfg
->config
->wlan1_mac
;
76 memcpy(mac
, cfg_mac
, ETH_ALEN
);
80 static const struct ath_bus_ops ath_ahb_bus_ops
= {
81 .ath_bus_type
= ATH_AHB
,
82 .read_cachesize
= ath5k_ahb_read_cachesize
,
83 .eeprom_read
= ath5k_ahb_eeprom_read
,
84 .eeprom_read_mac
= ath5k_ahb_eeprom_read_mac
,
88 static int ath_ahb_probe(struct platform_device
*pdev
)
90 struct ar231x_board_config
*bcfg
= pdev
->dev
.platform_data
;
92 struct ieee80211_hw
*hw
;
99 if (!pdev
->dev
.platform_data
) {
100 dev_err(&pdev
->dev
, "no platform data specified\n");
105 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
107 dev_err(&pdev
->dev
, "no memory resource found\n");
112 mem
= ioremap_nocache(res
->start
, resource_size(res
));
114 dev_err(&pdev
->dev
, "ioremap failed\n");
119 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
121 dev_err(&pdev
->dev
, "no IRQ resource found\n");
128 hw
= ieee80211_alloc_hw(sizeof(struct ath5k_hw
), &ath5k_hw_ops
);
130 dev_err(&pdev
->dev
, "no memory for ieee80211_hw\n");
137 ah
->dev
= &pdev
->dev
;
140 ah
->devid
= bcfg
->devid
;
142 if (bcfg
->devid
>= AR5K_SREV_AR2315_R6
) {
143 /* Enable WMAC AHB arbitration */
144 reg
= ioread32((void __iomem
*) AR5K_AR2315_AHB_ARB_CTL
);
145 reg
|= AR5K_AR2315_AHB_ARB_CTL_WLAN
;
146 iowrite32(reg
, (void __iomem
*) AR5K_AR2315_AHB_ARB_CTL
);
148 /* Enable global WMAC swapping */
149 reg
= ioread32((void __iomem
*) AR5K_AR2315_BYTESWAP
);
150 reg
|= AR5K_AR2315_BYTESWAP_WMAC
;
151 iowrite32(reg
, (void __iomem
*) AR5K_AR2315_BYTESWAP
);
153 /* Enable WMAC DMA access (assuming 5312 or 231x*/
154 /* TODO: check other platforms */
155 reg
= ioread32((void __iomem
*) AR5K_AR5312_ENABLE
);
156 if (to_platform_device(ah
->dev
)->id
== 0)
157 reg
|= AR5K_AR5312_ENABLE_WLAN0
;
159 reg
|= AR5K_AR5312_ENABLE_WLAN1
;
160 iowrite32(reg
, (void __iomem
*) AR5K_AR5312_ENABLE
);
163 * On a dual-band AR5312, the multiband radio is only
164 * used as pass-through. Disable 2 GHz support in the
167 if (to_platform_device(ah
->dev
)->id
== 0 &&
168 (bcfg
->config
->flags
& (BD_WLAN0
| BD_WLAN1
)) ==
169 (BD_WLAN1
| BD_WLAN0
))
170 ah
->ah_capabilities
.cap_needs_2GHz_ovr
= true;
172 ah
->ah_capabilities
.cap_needs_2GHz_ovr
= false;
175 ret
= ath5k_init_ah(ah
, &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
);
194 static int ath_ahb_remove(struct platform_device
*pdev
)
196 struct ar231x_board_config
*bcfg
= pdev
->dev
.platform_data
;
197 struct ieee80211_hw
*hw
= platform_get_drvdata(pdev
);
206 if (bcfg
->devid
>= AR5K_SREV_AR2315_R6
) {
207 /* Disable WMAC AHB arbitration */
208 reg
= ioread32((void __iomem
*) AR5K_AR2315_AHB_ARB_CTL
);
209 reg
&= ~AR5K_AR2315_AHB_ARB_CTL_WLAN
;
210 iowrite32(reg
, (void __iomem
*) AR5K_AR2315_AHB_ARB_CTL
);
213 reg
= ioread32((void __iomem
*) AR5K_AR5312_ENABLE
);
214 if (to_platform_device(ah
->dev
)->id
== 0)
215 reg
&= ~AR5K_AR5312_ENABLE_WLAN0
;
217 reg
&= ~AR5K_AR5312_ENABLE_WLAN1
;
218 iowrite32(reg
, (void __iomem
*) AR5K_AR5312_ENABLE
);
223 ieee80211_free_hw(hw
);
228 static struct platform_driver ath_ahb_driver
= {
229 .probe
= ath_ahb_probe
,
230 .remove
= ath_ahb_remove
,
232 .name
= "ar231x-wmac",
233 .owner
= THIS_MODULE
,
237 module_platform_driver(ath_ahb_driver
);