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;
35 ath5k_ahb_eeprom_read(struct ath_common
*common
, u32 off
, u16
*data
)
37 struct ath5k_softc
*sc
= common
->priv
;
38 struct platform_device
*pdev
= to_platform_device(sc
->dev
);
39 struct ar231x_board_config
*bcfg
= pdev
->dev
.platform_data
;
40 u16
*eeprom
, *eeprom_end
;
44 bcfg
= pdev
->dev
.platform_data
;
45 eeprom
= (u16
*) bcfg
->radio
;
46 eeprom_end
= ((void *) bcfg
->config
) + BOARD_CONFIG_BUFSZ
;
49 if (eeprom
> eeprom_end
)
56 int ath5k_hw_read_srev(struct ath5k_hw
*ah
)
58 struct ath5k_softc
*sc
= ah
->ah_sc
;
59 struct platform_device
*pdev
= to_platform_device(sc
->dev
);
60 struct ar231x_board_config
*bcfg
= pdev
->dev
.platform_data
;
61 ah
->ah_mac_srev
= bcfg
->devid
;
65 static const struct ath_bus_ops ath_ahb_bus_ops
= {
66 .ath_bus_type
= ATH_AHB
,
67 .read_cachesize
= ath5k_ahb_read_cachesize
,
68 .eeprom_read
= ath5k_ahb_eeprom_read
,
72 static int ath_ahb_probe(struct platform_device
*pdev
)
74 struct ar231x_board_config
*bcfg
= pdev
->dev
.platform_data
;
75 struct ath5k_softc
*sc
;
76 struct ieee80211_hw
*hw
;
83 if (!pdev
->dev
.platform_data
) {
84 dev_err(&pdev
->dev
, "no platform data specified\n");
89 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
91 dev_err(&pdev
->dev
, "no memory resource found\n");
96 mem
= ioremap_nocache(res
->start
, resource_size(res
));
98 dev_err(&pdev
->dev
, "ioremap failed\n");
103 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
105 dev_err(&pdev
->dev
, "no IRQ resource found\n");
112 hw
= ieee80211_alloc_hw(sizeof(struct ath5k_softc
), &ath5k_hw_ops
);
114 dev_err(&pdev
->dev
, "no memory for ieee80211_hw\n");
121 sc
->dev
= &pdev
->dev
;
124 sc
->devid
= bcfg
->devid
;
126 if (bcfg
->devid
>= AR5K_SREV_AR2315_R6
) {
127 /* Enable WMAC AHB arbitration */
128 reg
= __raw_readl((void __iomem
*) AR5K_AR2315_AHB_ARB_CTL
);
129 reg
|= AR5K_AR2315_AHB_ARB_CTL_WLAN
;
130 __raw_writel(reg
, (void __iomem
*) AR5K_AR2315_AHB_ARB_CTL
);
132 /* Enable global WMAC swapping */
133 reg
= __raw_readl((void __iomem
*) AR5K_AR2315_BYTESWAP
);
134 reg
|= AR5K_AR2315_BYTESWAP_WMAC
;
135 __raw_writel(reg
, (void __iomem
*) AR5K_AR2315_BYTESWAP
);
137 /* Enable WMAC DMA access (assuming 5312 or 231x*/
138 /* TODO: check other platforms */
139 reg
= __raw_readl((void __iomem
*) AR5K_AR5312_ENABLE
);
140 if (to_platform_device(sc
->dev
)->id
== 0)
141 reg
|= AR5K_AR5312_ENABLE_WLAN0
;
143 reg
|= AR5K_AR5312_ENABLE_WLAN1
;
144 __raw_writel(reg
, (void __iomem
*) AR5K_AR5312_ENABLE
);
147 ret
= ath5k_init_softc(sc
, &ath_ahb_bus_ops
);
149 dev_err(&pdev
->dev
, "failed to attach device, err=%d\n", ret
);
154 platform_set_drvdata(pdev
, hw
);
159 ieee80211_free_hw(hw
);
160 platform_set_drvdata(pdev
, NULL
);
165 static int ath_ahb_remove(struct platform_device
*pdev
)
167 struct ar231x_board_config
*bcfg
= pdev
->dev
.platform_data
;
168 struct ieee80211_hw
*hw
= platform_get_drvdata(pdev
);
169 struct ath5k_softc
*sc
;
177 if (bcfg
->devid
>= AR5K_SREV_AR2315_R6
) {
178 /* Disable WMAC AHB arbitration */
179 reg
= __raw_readl((void __iomem
*) AR5K_AR2315_AHB_ARB_CTL
);
180 reg
&= ~AR5K_AR2315_AHB_ARB_CTL_WLAN
;
181 __raw_writel(reg
, (void __iomem
*) AR5K_AR2315_AHB_ARB_CTL
);
184 reg
= __raw_readl((void __iomem
*) AR5K_AR5312_ENABLE
);
185 if (to_platform_device(sc
->dev
)->id
== 0)
186 reg
&= ~AR5K_AR5312_ENABLE_WLAN0
;
188 reg
&= ~AR5K_AR5312_ENABLE_WLAN1
;
189 __raw_writel(reg
, (void __iomem
*) AR5K_AR5312_ENABLE
);
192 ath5k_deinit_softc(sc
);
193 platform_set_drvdata(pdev
, NULL
);
198 static struct platform_driver ath_ahb_driver
= {
199 .probe
= ath_ahb_probe
,
200 .remove
= ath_ahb_remove
,
202 .name
= "ar231x-wmac",
203 .owner
= THIS_MODULE
,
210 return platform_driver_register(&ath_ahb_driver
);
216 platform_driver_unregister(&ath_ahb_driver
);
219 module_init(ath5k_ahb_init
);
220 module_exit(ath5k_ahb_exit
);