1 From 9456893748c407d9fed06046308177edaca38450 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Fri, 2 Jan 2009 16:12:30 +0100
4 Subject: [RFC 07/12] ath9k: introduce platform driver for AHB bus support
6 This patch adds the platform_driver itself, and modifies the main driver
9 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
10 Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
12 drivers/net/wireless/ath9k/Makefile | 1 +
13 drivers/net/wireless/ath9k/ahb.c | 258 +++++++++++++++++++++++++++++++++++
14 drivers/net/wireless/ath9k/core.h | 8 +
15 drivers/net/wireless/ath9k/main.c | 10 ++
16 4 files changed, 277 insertions(+), 0 deletions(-)
18 --- a/drivers/net/wireless/ath9k/Makefile
19 +++ b/drivers/net/wireless/ath9k/Makefile
20 @@ -12,6 +12,7 @@ ath9k-y += hw.o \
23 ath9k-$(CONFIG_PCI) += pci.o
24 +ath9k-$(CONFIG_ATHEROS_AR71XX) += ahb.o
25 ath9k-$(CONFIG_ATH9K_DEBUG) += debug.o
27 obj-$(CONFIG_ATH9K) += ath9k.o
29 +++ b/drivers/net/wireless/ath9k/ahb.c
32 + * Copyright (c) 2008 Atheros Communications Inc.
33 + * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
34 + * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
36 + * Permission to use, copy, modify, and/or distribute this software for any
37 + * purpose with or without fee is hereby granted, provided that the above
38 + * copyright notice and this permission notice appear in all copies.
40 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
41 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
42 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
43 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
44 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
45 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
46 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
49 +#include <linux/nl80211.h>
50 +#include <linux/platform_device.h>
55 +static dma_addr_t ath_ahb_map_single_to_device(struct ath_softc *sc,
56 + void *p, size_t size)
58 + return dma_map_single(NULL, p, size, DMA_TO_DEVICE);
61 +static void ath_ahb_unmap_single_to_device(struct ath_softc *sc,
62 + dma_addr_t da, size_t size)
64 + dma_unmap_single(NULL, da, size, DMA_TO_DEVICE);
67 +static dma_addr_t ath_ahb_map_single_from_device(struct ath_softc *sc,
68 + void *p, size_t size)
70 + return dma_map_single(NULL, p, size, DMA_FROM_DEVICE);
73 +static void ath_ahb_unmap_single_from_device(struct ath_softc *sc,
74 + dma_addr_t da, size_t size)
76 + dma_unmap_single(NULL, da, size, DMA_FROM_DEVICE);
79 +static int ath_ahb_dma_mapping_error(struct ath_softc *sc, dma_addr_t da)
81 + return dma_mapping_error(NULL, da);
84 +static void ath_ahb_sync_single_for_cpu(struct ath_softc *sc, dma_addr_t da,
87 + dma_sync_single_for_cpu(NULL, da, size, DMA_FROM_DEVICE);
90 +static void *ath_ahb_dma_alloc(struct ath_softc *sc, size_t size,
93 + return dma_alloc_coherent(NULL, size, pda, GFP_KERNEL);
96 +static void ath_ahb_dma_free(struct ath_softc *sc, size_t size, void *p,
99 + dma_free_coherent(NULL, size, p, da);
102 +static void ath_ahb_reg_write(struct ath_hal *ah, unsigned reg, u32 val)
104 + __raw_writel(val, ah->ah_sh + reg);
107 +static u32 ath_ahb_reg_read(struct ath_hal *ah, unsigned reg)
109 + return __raw_readl(ah->ah_sh + reg);
112 +/* return bus cachesize in 4B word units */
113 +static void ath_ahb_read_cachesize(struct ath_softc *sc, int *csz)
115 + *csz = L1_CACHE_BYTES >> 2;
118 +static void ath_ahb_cleanup(struct ath_softc *sc)
120 + struct platform_device *pdev = to_platform_device(sc->dev);
121 + struct ieee80211_hw *hw = sc->hw;
122 + struct resource *res;
124 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
126 + free_irq(res->start, sc);
130 + ieee80211_free_hw(hw);
131 + platform_set_drvdata(pdev, NULL);
134 +static struct ath_bus_ops ath_ahb_bus_ops = {
135 + .dma_map_single_to_device = ath_ahb_map_single_to_device,
136 + .dma_unmap_single_to_device = ath_ahb_unmap_single_to_device,
137 + .dma_map_single_from_device = ath_ahb_map_single_from_device,
138 + .dma_unmap_single_from_device = ath_ahb_unmap_single_from_device,
139 + .dma_map_single_to_device = ath_ahb_map_single_to_device,
140 + .dma_mapping_error = ath_ahb_dma_mapping_error,
141 + .dma_sync_single_for_cpu = ath_ahb_sync_single_for_cpu,
142 + .dma_alloc = ath_ahb_dma_alloc,
143 + .dma_free = ath_ahb_dma_free,
145 + .reg_read = ath_ahb_reg_read,
146 + .reg_write = ath_ahb_reg_write,
148 + .read_cachesize = ath_ahb_read_cachesize,
150 + .cleanup = ath_ahb_cleanup,
153 +static int ath_ahb_probe(struct platform_device *pdev)
156 + struct ath_softc *sc;
157 + struct ieee80211_hw *hw;
158 + struct resource *res;
161 + struct ath_hal *ah;
163 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
165 + dev_err(&pdev->dev, "no memory resource found\n");
170 + mem = ioremap_nocache(res->start, res->end - res->start + 1);
172 + dev_err(&pdev->dev, "ioremap failed\n");
177 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
179 + dev_err(&pdev->dev, "no IRQ resource found\n");
186 + hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
188 + dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
193 + hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
194 + IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
195 + IEEE80211_HW_SIGNAL_DBM |
196 + IEEE80211_HW_NOISE_DBM;
198 + hw->wiphy->interface_modes =
199 + BIT(NL80211_IFTYPE_AP) |
200 + BIT(NL80211_IFTYPE_STATION) |
201 + BIT(NL80211_IFTYPE_ADHOC);
203 + SET_IEEE80211_DEV(hw, &pdev->dev);
204 + platform_set_drvdata(pdev, hw);
208 + sc->dev = &pdev->dev;
210 + sc->bus_ops = &ath_ahb_bus_ops;
212 + ret = ath_attach(AR5416_AR9100_DEVID, sc);
214 + dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
219 + ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
221 + dev_err(&pdev->dev, "request_irq failed, err=%d\n", ret);
228 + "%s: Atheros AR%s MAC/BB Rev:%x, "
229 + "AR%s RF Rev:%x, mem=0x%lx, irq=%d\n",
230 + wiphy_name(hw->wiphy),
231 + ath_mac_bb_name(ah->ah_macVersion),
233 + ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
235 + (unsigned long)mem, irq);
242 + ieee80211_free_hw(hw);
243 + platform_set_drvdata(pdev, NULL);
250 +static int ath_ahb_remove(struct platform_device *pdev)
252 + struct ieee80211_hw *hw = platform_get_drvdata(pdev);
255 + struct resource *res;
256 + struct ath_softc *sc = hw->priv;
258 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
260 + free_irq(res->start, sc);
264 + ieee80211_free_hw(hw);
265 + platform_set_drvdata(pdev, NULL);
271 +static struct platform_driver ath_ahb_driver = {
272 + .probe = ath_ahb_probe,
273 + .remove = ath_ahb_remove,
276 + .owner = THIS_MODULE,
280 +int ath_ahb_init(void)
282 + return platform_driver_register(&ath_ahb_driver);
285 +void ath_ahb_exit(void)
287 + platform_driver_register(&ath_ahb_driver);
289 --- a/drivers/net/wireless/ath9k/core.h
290 +++ b/drivers/net/wireless/ath9k/core.h
291 @@ -874,4 +874,12 @@ static inline int ath_pci_init(void) { r
292 static inline void ath_pci_exit(void) {};
295 +#ifdef CONFIG_ATHEROS_AR71XX
296 +int ath_ahb_init(void);
297 +void ath_ahb_exit(void);
299 +static inline int ath_ahb_init(void) { return 0; };
300 +static inline void ath_ahb_exit(void) {};
304 --- a/drivers/net/wireless/ath9k/main.c
305 +++ b/drivers/net/wireless/ath9k/main.c
306 @@ -2533,8 +2533,17 @@ static int __init ath9k_init(void)
307 goto err_rate_unregister;
310 + error = ath_ahb_init();
322 ath_rate_control_unregister();
324 @@ -2544,6 +2553,7 @@ module_init(ath9k_init);
326 static void __exit ath9k_exit(void)
330 ath_rate_control_unregister();
331 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);