99eec34ba0f6ccc1e6ff2891a33a0c8ed8b11a6e
[openwrt.git] / package / mac80211 / patches / 406-ath9k-introduce-platform-driver-for-AHB-bus-support.patch
1 From 9b3c1b50a35455e28c5b2fede615a304df42e758 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 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    |  179 +++++++++++++++++++++++++++++++++++
14  drivers/net/wireless/ath9k/core.h   |    9 ++
15  drivers/net/wireless/ath9k/main.c   |   10 ++
16  4 files changed, 199 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,179 @@
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 +       struct ieee80211_hw *hw = sc->hw;
64 +
65 +       free_irq(sc->irq, sc);
66 +
67 +       ath_detach(sc);
68 +       iounmap(sc->mem);
69 +       ieee80211_free_hw(hw);
70 +}
71 +
72 +static struct ath_bus_ops ath_ahb_bus_ops  = {
73 +       .read_cachesize = ath_ahb_read_cachesize,
74 +       .cleanup = ath_ahb_cleanup,
75 +};
76 +
77 +static int ath_ahb_probe(struct platform_device *pdev)
78 +{
79 +       void __iomem *mem;
80 +       struct ath_softc *sc;
81 +       struct ieee80211_hw *hw;
82 +       struct resource *res;
83 +       int irq;
84 +       int ret = 0;
85 +       struct ath_hal *ah;
86 +
87 +       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
88 +       if (res == NULL) {
89 +               dev_err(&pdev->dev, "no memory resource found\n");
90 +               ret = -ENXIO;
91 +               goto err_out;
92 +       }
93 +
94 +       mem = ioremap_nocache(res->start, res->end - res->start + 1);
95 +       if (mem == NULL) {
96 +               dev_err(&pdev->dev, "ioremap failed\n");
97 +               ret = -ENOMEM;
98 +               goto err_out;
99 +       }
100 +
101 +       res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
102 +       if (res == NULL) {
103 +               dev_err(&pdev->dev, "no IRQ resource found\n");
104 +               ret = -ENXIO;
105 +               goto err_iounmap;
106 +       }
107 +
108 +       irq = res->start;
109 +
110 +       hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
111 +       if (hw == NULL) {
112 +               dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
113 +               ret = -ENOMEM;
114 +               goto err_iounmap;
115 +       }
116 +
117 +       hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
118 +               IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
119 +               IEEE80211_HW_SIGNAL_DBM |
120 +               IEEE80211_HW_NOISE_DBM;
121 +
122 +       hw->wiphy->interface_modes =
123 +               BIT(NL80211_IFTYPE_AP) |
124 +               BIT(NL80211_IFTYPE_STATION) |
125 +               BIT(NL80211_IFTYPE_ADHOC);
126 +
127 +       SET_IEEE80211_DEV(hw, &pdev->dev);
128 +       platform_set_drvdata(pdev, hw);
129 +
130 +       sc = hw->priv;
131 +       sc->hw = hw;
132 +       sc->dev = &pdev->dev;
133 +       sc->mem = mem;
134 +       sc->bus_ops = &ath_ahb_bus_ops;
135 +       sc->irq = irq;
136 +
137 +       ret = ath_attach(AR5416_AR9100_DEVID, sc);
138 +       if (ret != 0) {
139 +               dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
140 +               ret = -ENODEV;
141 +               goto err_free_hw;
142 +       }
143 +
144 +       ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
145 +       if (ret) {
146 +               dev_err(&pdev->dev, "request_irq failed, err=%d\n", ret);
147 +               ret = -EIO;
148 +               goto err_detach;
149 +       }
150 +
151 +       ah = sc->sc_ah;
152 +       printk(KERN_INFO
153 +              "%s: Atheros AR%s MAC/BB Rev:%x, "
154 +              "AR%s RF Rev:%x, mem=0x%lx, irq=%d\n",
155 +              wiphy_name(hw->wiphy),
156 +              ath_mac_bb_name(ah->ah_macVersion),
157 +              ah->ah_macRev,
158 +              ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
159 +              ah->ah_phyRev,
160 +              (unsigned long)mem, irq);
161 +
162 +       return 0;
163 +
164 + err_detach:
165 +       ath_detach(sc);
166 + err_free_hw:
167 +       ieee80211_free_hw(hw);
168 +       platform_set_drvdata(pdev, NULL);
169 + err_iounmap:
170 +       iounmap(mem);
171 + err_out:
172 +       return ret;
173 +}
174 +
175 +static int ath_ahb_remove(struct platform_device *pdev)
176 +{
177 +       struct ieee80211_hw *hw = platform_get_drvdata(pdev);
178 +
179 +       if (hw) {
180 +               struct ath_softc *sc = hw->priv;
181 +
182 +               free_irq(sc->irq, sc);
183 +               ath_detach(sc);
184 +               iounmap(sc->mem);
185 +               ieee80211_free_hw(hw);
186 +               platform_set_drvdata(pdev, NULL);
187 +       }
188 +
189 +       return 0;
190 +}
191 +
192 +static struct platform_driver ath_ahb_driver = {
193 +       .probe      = ath_ahb_probe,
194 +       .remove     = ath_ahb_remove,
195 +       .driver         = {
196 +               .name   = "ath9k",
197 +               .owner  = THIS_MODULE,
198 +       },
199 +};
200 +
201 +int ath_ahb_init(void)
202 +{
203 +       return platform_driver_register(&ath_ahb_driver);
204 +}
205 +
206 +void ath_ahb_exit(void)
207 +{
208 +       platform_driver_register(&ath_ahb_driver);
209 +}
210 --- a/drivers/net/wireless/ath9k/core.h
211 +++ b/drivers/net/wireless/ath9k/core.h
212 @@ -705,6 +705,7 @@ struct ath_softc {
213         struct tasklet_struct bcon_tasklet;
214         struct ath_hal *sc_ah;
215         void __iomem *mem;
216 +       int irq;
217         spinlock_t sc_resetlock;
218         struct mutex mutex;
219  
220 @@ -782,4 +783,12 @@ static inline int ath_pci_init(void) { r
221  static inline void ath_pci_exit(void) {};
222  #endif
223  
224 +#ifdef CONFIG_ATHEROS_AR71XX
225 +int ath_ahb_init(void);
226 +void ath_ahb_exit(void);
227 +#else
228 +static inline int ath_ahb_init(void) { return 0; };
229 +static inline void ath_ahb_exit(void) {};
230 +#endif
231 +
232  #endif /* CORE_H */
233 --- a/drivers/net/wireless/ath9k/main.c
234 +++ b/drivers/net/wireless/ath9k/main.c
235 @@ -2514,8 +2514,17 @@ static int __init ath9k_init(void)
236                 goto err_rate_unregister;
237         }
238  
239 +       error = ath_ahb_init();
240 +       if (error < 0) {
241 +               error = -ENODEV;
242 +               goto err_pci_exit;
243 +       }
244 +
245         return 0;
246  
247 + err_pci_exit:
248 +       ath_pci_exit();
249 +
250   err_rate_unregister:
251         ath_rate_control_unregister();
252   err_out:
253 @@ -2525,6 +2534,7 @@ module_init(ath9k_init);
254  
255  static void __exit ath9k_exit(void)
256  {
257 +       ath_ahb_exit();
258         ath_pci_exit();
259         ath_rate_control_unregister();
260         printk(KERN_INFO "%s: Driver unloaded\n", dev_info);