[package] mac80211: update ath9k patches
[openwrt.git] / package / mac80211 / patches / 406-ath9k-introduce-platform-driver-for-AHB-bus-support.patch
1 From 23f9e44a18b5a2dfaa1326aa30dd07e1449e8b5f 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 v3 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 Changes-licensed-under: ISC
10
11 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
12 Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
13 ---
14  drivers/net/wireless/ath9k/Makefile |    1 +
15  drivers/net/wireless/ath9k/ahb.c    |  160 +++++++++++++++++++++++++++++++++++
16  drivers/net/wireless/ath9k/core.h   |    8 ++
17  drivers/net/wireless/ath9k/main.c   |   10 ++
18  4 files changed, 179 insertions(+), 0 deletions(-)
19  create mode 100644 drivers/net/wireless/ath9k/ahb.c
20
21 --- a/drivers/net/wireless/ath9k/Makefile
22 +++ b/drivers/net/wireless/ath9k/Makefile
23 @@ -12,6 +12,7 @@ ath9k-y +=    hw.o \
24                 rc.o
25  
26  ath9k-$(CONFIG_PCI) += pci.o
27 +ath9k-$(CONFIG_ATHEROS_AR71XX) += ahb.o
28  ath9k-$(CONFIG_ATH9K_DEBUG) += debug.o
29  
30  obj-$(CONFIG_ATH9K) += ath9k.o
31 --- /dev/null
32 +++ b/drivers/net/wireless/ath9k/ahb.c
33 @@ -0,0 +1,160 @@
34 +/*
35 + * Copyright (c) 2008 Atheros Communications Inc.
36 + * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
37 + * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
38 + *
39 + * Permission to use, copy, modify, and/or distribute this software for any
40 + * purpose with or without fee is hereby granted, provided that the above
41 + * copyright notice and this permission notice appear in all copies.
42 + *
43 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
44 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
45 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
46 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
47 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
48 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
49 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
50 + */
51 +
52 +#include <linux/nl80211.h>
53 +#include <linux/platform_device.h>
54 +#include "core.h"
55 +#include "reg.h"
56 +#include "hw.h"
57 +
58 +/* return bus cachesize in 4B word units */
59 +static void ath_ahb_read_cachesize(struct ath_softc *sc, int *csz)
60 +{
61 +       *csz = L1_CACHE_BYTES >> 2;
62 +}
63 +
64 +static void ath_ahb_cleanup(struct ath_softc *sc)
65 +{
66 +       iounmap(sc->mem);
67 +}
68 +
69 +static struct ath_bus_ops ath_ahb_bus_ops  = {
70 +       .read_cachesize = ath_ahb_read_cachesize,
71 +       .cleanup = ath_ahb_cleanup,
72 +};
73 +
74 +static int ath_ahb_probe(struct platform_device *pdev)
75 +{
76 +       void __iomem *mem;
77 +       struct ath_softc *sc;
78 +       struct ieee80211_hw *hw;
79 +       struct resource *res;
80 +       int irq;
81 +       int ret = 0;
82 +       struct ath_hal *ah;
83 +
84 +       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
85 +       if (res == NULL) {
86 +               dev_err(&pdev->dev, "no memory resource found\n");
87 +               ret = -ENXIO;
88 +               goto err_out;
89 +       }
90 +
91 +       mem = ioremap_nocache(res->start, res->end - res->start + 1);
92 +       if (mem == NULL) {
93 +               dev_err(&pdev->dev, "ioremap failed\n");
94 +               ret = -ENOMEM;
95 +               goto err_out;
96 +       }
97 +
98 +       res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
99 +       if (res == NULL) {
100 +               dev_err(&pdev->dev, "no IRQ resource found\n");
101 +               ret = -ENXIO;
102 +               goto err_iounmap;
103 +       }
104 +
105 +       irq = res->start;
106 +
107 +       hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
108 +       if (hw == NULL) {
109 +               dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
110 +               ret = -ENOMEM;
111 +               goto err_iounmap;
112 +       }
113 +
114 +       SET_IEEE80211_DEV(hw, &pdev->dev);
115 +       platform_set_drvdata(pdev, hw);
116 +
117 +       sc = hw->priv;
118 +       sc->hw = hw;
119 +       sc->dev = &pdev->dev;
120 +       sc->mem = mem;
121 +       sc->bus_ops = &ath_ahb_bus_ops;
122 +       sc->irq = irq;
123 +
124 +       ret = ath_attach(AR5416_AR9100_DEVID, sc);
125 +       if (ret != 0) {
126 +               dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
127 +               ret = -ENODEV;
128 +               goto err_free_hw;
129 +       }
130 +
131 +       ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
132 +       if (ret) {
133 +               dev_err(&pdev->dev, "request_irq failed, err=%d\n", ret);
134 +               ret = -EIO;
135 +               goto err_detach;
136 +       }
137 +
138 +       ah = sc->sc_ah;
139 +       printk(KERN_INFO
140 +              "%s: Atheros AR%s MAC/BB Rev:%x, "
141 +              "AR%s RF Rev:%x, mem=0x%lx, irq=%d\n",
142 +              wiphy_name(hw->wiphy),
143 +              ath_mac_bb_name(ah->ah_macVersion),
144 +              ah->ah_macRev,
145 +              ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
146 +              ah->ah_phyRev,
147 +              (unsigned long)mem, irq);
148 +
149 +       return 0;
150 +
151 + err_detach:
152 +       ath_detach(sc);
153 + err_free_hw:
154 +       ieee80211_free_hw(hw);
155 +       platform_set_drvdata(pdev, NULL);
156 + err_iounmap:
157 +       iounmap(mem);
158 + err_out:
159 +       return ret;
160 +}
161 +
162 +static int ath_ahb_remove(struct platform_device *pdev)
163 +{
164 +       struct ieee80211_hw *hw = platform_get_drvdata(pdev);
165 +
166 +       if (hw) {
167 +               struct ath_softc *sc = hw->priv;
168 +
169 +               ath_cleanup(sc);
170 +               platform_set_drvdata(pdev, NULL);
171 +       }
172 +
173 +       return 0;
174 +}
175 +
176 +static struct platform_driver ath_ahb_driver = {
177 +       .probe      = ath_ahb_probe,
178 +       .remove     = ath_ahb_remove,
179 +       .driver         = {
180 +               .name   = "ath9k",
181 +               .owner  = THIS_MODULE,
182 +       },
183 +};
184 +
185 +int ath_ahb_init(void)
186 +{
187 +       return platform_driver_register(&ath_ahb_driver);
188 +}
189 +
190 +void ath_ahb_exit(void)
191 +{
192 +       platform_driver_unregister(&ath_ahb_driver);
193 +}
194 --- a/drivers/net/wireless/ath9k/core.h
195 +++ b/drivers/net/wireless/ath9k/core.h
196 @@ -784,4 +784,12 @@ static inline int ath_pci_init(void) { r
197  static inline void ath_pci_exit(void) {};
198  #endif
199  
200 +#ifdef CONFIG_ATHEROS_AR71XX
201 +int ath_ahb_init(void);
202 +void ath_ahb_exit(void);
203 +#else
204 +static inline int ath_ahb_init(void) { return 0; };
205 +static inline void ath_ahb_exit(void) {};
206 +#endif
207 +
208  #endif /* CORE_H */
209 --- a/drivers/net/wireless/ath9k/main.c
210 +++ b/drivers/net/wireless/ath9k/main.c
211 @@ -2531,8 +2531,17 @@ static int __init ath9k_init(void)
212                 goto err_rate_unregister;
213         }
214  
215 +       error = ath_ahb_init();
216 +       if (error < 0) {
217 +               error = -ENODEV;
218 +               goto err_pci_exit;
219 +       }
220 +
221         return 0;
222  
223 + err_pci_exit:
224 +       ath_pci_exit();
225 +
226   err_rate_unregister:
227         ath_rate_control_unregister();
228   err_out:
229 @@ -2542,6 +2551,7 @@ module_init(ath9k_init);
230  
231  static void __exit ath9k_exit(void)
232  {
233 +       ath_ahb_exit();
234         ath_pci_exit();
235         ath_rate_control_unregister();
236         printk(KERN_INFO "%s: Driver unloaded\n", dev_info);