ae42bda1b66b25aeb09344f01f95eba8b02fe666
[openwrt/svn-archive/archive.git] / package / mac80211 / patches / 406-ath9k-introduce-platform-driver-for-AHB-bus-support.patch
1 From ace011bdb2676f594824c81a5a5b5089dc0c3e0b Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Mon, 5 Jan 2009 11:03:17 +0100
4 Subject: [PATCH v2 06/11] ath9k: introduce platform driver for AHB bus support
5
6 This patch adds the platform_driver itself, and modifies the main driver
7 to register it.
8
9 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
10 Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
11 ---
12 drivers/net/wireless/ath9k/Makefile | 1 +
13 drivers/net/wireless/ath9k/ahb.c | 160 +++++++++++++++++++++++++++++++++++
14 drivers/net/wireless/ath9k/core.h | 8 ++
15 drivers/net/wireless/ath9k/main.c | 10 ++
16 4 files changed, 179 insertions(+), 0 deletions(-)
17
18 --- a/drivers/net/wireless/ath9k/Makefile
19 +++ b/drivers/net/wireless/ath9k/Makefile
20 @@ -12,6 +12,7 @@ ath9k-y += hw.o \
21 rc.o
22
23 ath9k-$(CONFIG_PCI) += pci.o
24 +ath9k-$(CONFIG_ATHEROS_AR71XX) += ahb.o
25 ath9k-$(CONFIG_ATH9K_DEBUG) += debug.o
26
27 obj-$(CONFIG_ATH9K) += ath9k.o
28 --- /dev/null
29 +++ b/drivers/net/wireless/ath9k/ahb.c
30 @@ -0,0 +1,160 @@
31 +/*
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>
35 + *
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.
39 + *
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.
47 + */
48 +
49 +#include <linux/nl80211.h>
50 +#include <linux/platform_device.h>
51 +#include "core.h"
52 +#include "reg.h"
53 +#include "hw.h"
54 +
55 +/* return bus cachesize in 4B word units */
56 +static void ath_ahb_read_cachesize(struct ath_softc *sc, int *csz)
57 +{
58 + *csz = L1_CACHE_BYTES >> 2;
59 +}
60 +
61 +static void ath_ahb_cleanup(struct ath_softc *sc)
62 +{
63 + iounmap(sc->mem);
64 +}
65 +
66 +static struct ath_bus_ops ath_ahb_bus_ops = {
67 + .read_cachesize = ath_ahb_read_cachesize,
68 + .cleanup = ath_ahb_cleanup,
69 +};
70 +
71 +static int ath_ahb_probe(struct platform_device *pdev)
72 +{
73 + void __iomem *mem;
74 + struct ath_softc *sc;
75 + struct ieee80211_hw *hw;
76 + struct resource *res;
77 + int irq;
78 + int ret = 0;
79 + struct ath_hal *ah;
80 +
81 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
82 + if (res == NULL) {
83 + dev_err(&pdev->dev, "no memory resource found\n");
84 + ret = -ENXIO;
85 + goto err_out;
86 + }
87 +
88 + mem = ioremap_nocache(res->start, res->end - res->start + 1);
89 + if (mem == NULL) {
90 + dev_err(&pdev->dev, "ioremap failed\n");
91 + ret = -ENOMEM;
92 + goto err_out;
93 + }
94 +
95 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
96 + if (res == NULL) {
97 + dev_err(&pdev->dev, "no IRQ resource found\n");
98 + ret = -ENXIO;
99 + goto err_iounmap;
100 + }
101 +
102 + irq = res->start;
103 +
104 + hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
105 + if (hw == NULL) {
106 + dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
107 + ret = -ENOMEM;
108 + goto err_iounmap;
109 + }
110 +
111 + SET_IEEE80211_DEV(hw, &pdev->dev);
112 + platform_set_drvdata(pdev, hw);
113 +
114 + sc = hw->priv;
115 + sc->hw = hw;
116 + sc->dev = &pdev->dev;
117 + sc->mem = mem;
118 + sc->bus_ops = &ath_ahb_bus_ops;
119 + sc->irq = irq;
120 +
121 + ret = ath_attach(AR5416_AR9100_DEVID, sc);
122 + if (ret != 0) {
123 + dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
124 + ret = -ENODEV;
125 + goto err_free_hw;
126 + }
127 +
128 + ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
129 + if (ret) {
130 + dev_err(&pdev->dev, "request_irq failed, err=%d\n", ret);
131 + ret = -EIO;
132 + goto err_detach;
133 + }
134 +
135 + ah = sc->sc_ah;
136 + printk(KERN_INFO
137 + "%s: Atheros AR%s MAC/BB Rev:%x, "
138 + "AR%s RF Rev:%x, mem=0x%lx, irq=%d\n",
139 + wiphy_name(hw->wiphy),
140 + ath_mac_bb_name(ah->ah_macVersion),
141 + ah->ah_macRev,
142 + ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
143 + ah->ah_phyRev,
144 + (unsigned long)mem, irq);
145 +
146 + return 0;
147 +
148 + err_detach:
149 + ath_detach(sc);
150 + err_free_hw:
151 + ieee80211_free_hw(hw);
152 + platform_set_drvdata(pdev, NULL);
153 + err_iounmap:
154 + iounmap(mem);
155 + err_out:
156 + return ret;
157 +}
158 +
159 +static int ath_ahb_remove(struct platform_device *pdev)
160 +{
161 + struct ieee80211_hw *hw = platform_get_drvdata(pdev);
162 +
163 + if (hw) {
164 + struct ath_softc *sc = hw->priv;
165 +
166 + ath_cleanup(sc);
167 + platform_set_drvdata(pdev, NULL);
168 + }
169 +
170 + return 0;
171 +}
172 +
173 +static struct platform_driver ath_ahb_driver = {
174 + .probe = ath_ahb_probe,
175 + .remove = ath_ahb_remove,
176 + .driver = {
177 + .name = "ath9k",
178 + .owner = THIS_MODULE,
179 + },
180 +};
181 +
182 +int ath_ahb_init(void)
183 +{
184 + return platform_driver_register(&ath_ahb_driver);
185 +}
186 +
187 +void ath_ahb_exit(void)
188 +{
189 + platform_driver_unregister(&ath_ahb_driver);
190 +}
191 --- a/drivers/net/wireless/ath9k/core.h
192 +++ b/drivers/net/wireless/ath9k/core.h
193 @@ -784,4 +784,12 @@ static inline int ath_pci_init(void) { r
194 static inline void ath_pci_exit(void) {};
195 #endif
196
197 +#ifdef CONFIG_ATHEROS_AR71XX
198 +int ath_ahb_init(void);
199 +void ath_ahb_exit(void);
200 +#else
201 +static inline int ath_ahb_init(void) { return 0; };
202 +static inline void ath_ahb_exit(void) {};
203 +#endif
204 +
205 #endif /* CORE_H */
206 --- a/drivers/net/wireless/ath9k/main.c
207 +++ b/drivers/net/wireless/ath9k/main.c
208 @@ -2531,8 +2531,17 @@ static int __init ath9k_init(void)
209 goto err_rate_unregister;
210 }
211
212 + error = ath_ahb_init();
213 + if (error < 0) {
214 + error = -ENODEV;
215 + goto err_pci_exit;
216 + }
217 +
218 return 0;
219
220 + err_pci_exit:
221 + ath_pci_exit();
222 +
223 err_rate_unregister:
224 ath_rate_control_unregister();
225 err_out:
226 @@ -2542,6 +2551,7 @@ module_init(ath9k_init);
227
228 static void __exit ath9k_exit(void)
229 {
230 + ath_ahb_exit();
231 ath_pci_exit();
232 ath_rate_control_unregister();
233 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);