kernel: backport ssb changes from 4.4-rc1
[openwrt/staging/chunkeey.git] / package / kernel / mac80211 / patches / 315-ssb-pick-PCMCIA-host-code-support-from-b43-driver.patch
1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
2 Date: Thu, 15 Oct 2015 07:23:25 +0200
3 Subject: [PATCH] ssb: pick PCMCIA host code support from b43 driver
4 MIME-Version: 1.0
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
7
8 ssb bus can be found on various "host" devices like PCI/PCMCIA/SDIO.
9 Every ssb bus contains cores AKA devices.
10 The main idea is to have ssb driver scan/initialize bus and register
11 ready-to-use cores. This way ssb drivers can operate on a single core
12 mostly ignoring underlaying details.
13
14 For some reason PCMCIA support was split between ssb and b43. We got
15 PCMCIA host device probing in b43, then bus scanning in ssb and then
16 wireless core probing back in b43. The truth is it's very unlikely we
17 will ever see PCMCIA ssb device with no 802.11 core but I still don't
18 see any advantage of the current architecture.
19
20 With proposed change we get the same functionality with a simpler
21 architecture, less Kconfig symbols, one killed EXPORT and hopefully
22 cleaner b43. Since b43 supports both: ssb & bcma I prefer to keep ssb
23 specific code in ssb driver.
24
25 This mostly moves code from b43's pcmcia.c to bridge_pcmcia_80211.c. We
26 already use similar solution with b43_pci_bridge.c. I didn't use "b43"
27 in name of this new file as in theory any driver can operate on wireless
28 core.
29
30 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
31 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
32 ---
33 delete mode 100644 drivers/net/wireless/b43/pcmcia.c
34 delete mode 100644 drivers/net/wireless/b43/pcmcia.h
35 create mode 100644 drivers/ssb/bridge_pcmcia_80211.c
36
37 --- a/drivers/net/wireless/b43/Kconfig
38 +++ b/drivers/net/wireless/b43/Kconfig
39 @@ -72,26 +72,6 @@ config B43_PCICORE_AUTOSELECT
40 select SSB_DRIVER_PCICORE
41 default y
42
43 -config B43_PCMCIA
44 - bool "Broadcom 43xx PCMCIA device support"
45 - depends on B43 && B43_SSB && SSB_PCMCIAHOST_POSSIBLE
46 - select SSB_PCMCIAHOST
47 - ---help---
48 - Broadcom 43xx PCMCIA device support.
49 -
50 - Support for 16bit PCMCIA devices.
51 - Please note that most PC-CARD devices are _NOT_ 16bit PCMCIA
52 - devices, but 32bit CardBUS devices. CardBUS devices are supported
53 - out of the box by b43.
54 -
55 - With this config option you can drive b43 cards in
56 - CompactFlash formfactor in a PCMCIA adaptor.
57 - CF b43 cards can sometimes be found in handheld PCs.
58 -
59 - It's safe to select Y here, even if you don't have a B43 PCMCIA device.
60 -
61 - If unsure, say N.
62 -
63 config B43_SDIO
64 bool "Broadcom 43xx SDIO device support"
65 depends on B43 && B43_SSB && SSB_SDIOHOST_POSSIBLE
66 --- a/drivers/net/wireless/b43/Makefile
67 +++ b/drivers/net/wireless/b43/Makefile
68 @@ -21,7 +21,6 @@ b43-y += pio.o
69 b43-y += rfkill.o
70 b43-y += ppr.o
71 b43-$(CPTCFG_B43_LEDS) += leds.o
72 -b43-$(CPTCFG_B43_PCMCIA) += pcmcia.o
73 b43-$(CPTCFG_B43_SDIO) += sdio.o
74 b43-$(CPTCFG_B43_DEBUG) += debugfs.o
75
76 --- a/drivers/net/wireless/b43/main.c
77 +++ b/drivers/net/wireless/b43/main.c
78 @@ -56,7 +56,6 @@
79 #include "sysfs.h"
80 #include "xmit.h"
81 #include "lo.h"
82 -#include "pcmcia.h"
83 #include "sdio.h"
84 #include <linux/mmc/sdio_func.h>
85
86 @@ -5850,12 +5849,9 @@ static int __init b43_init(void)
87 int err;
88
89 b43_debugfs_init();
90 - err = b43_pcmcia_init();
91 - if (err)
92 - goto err_dfs_exit;
93 err = b43_sdio_init();
94 if (err)
95 - goto err_pcmcia_exit;
96 + goto err_dfs_exit;
97 #ifdef CPTCFG_B43_BCMA
98 err = bcma_driver_register(&b43_bcma_driver);
99 if (err)
100 @@ -5878,8 +5874,6 @@ err_bcma_driver_exit:
101 err_sdio_exit:
102 #endif
103 b43_sdio_exit();
104 -err_pcmcia_exit:
105 - b43_pcmcia_exit();
106 err_dfs_exit:
107 b43_debugfs_exit();
108 return err;
109 @@ -5894,7 +5888,6 @@ static void __exit b43_exit(void)
110 bcma_driver_unregister(&b43_bcma_driver);
111 #endif
112 b43_sdio_exit();
113 - b43_pcmcia_exit();
114 b43_debugfs_exit();
115 }
116
117 --- a/drivers/net/wireless/b43/pcmcia.h
118 +++ /dev/null
119 @@ -1,20 +0,0 @@
120 -#ifndef B43_PCMCIA_H_
121 -#define B43_PCMCIA_H_
122 -
123 -#ifdef CPTCFG_B43_PCMCIA
124 -
125 -int b43_pcmcia_init(void);
126 -void b43_pcmcia_exit(void);
127 -
128 -#else /* CPTCFG_B43_PCMCIA */
129 -
130 -static inline int b43_pcmcia_init(void)
131 -{
132 - return 0;
133 -}
134 -static inline void b43_pcmcia_exit(void)
135 -{
136 -}
137 -
138 -#endif /* CPTCFG_B43_PCMCIA */
139 -#endif /* B43_PCMCIA_H_ */
140 --- a/drivers/ssb/Makefile
141 +++ b/drivers/ssb/Makefile
142 @@ -5,7 +5,7 @@ ssb-$(CPTCFG_SSB_SPROM) += sprom.o
143
144 # host support
145 ssb-$(CPTCFG_SSB_PCIHOST) += pci.o pcihost_wrapper.o
146 -ssb-$(CPTCFG_SSB_PCMCIAHOST) += pcmcia.o
147 +ssb-$(CPTCFG_SSB_PCMCIAHOST) += pcmcia.o bridge_pcmcia_80211.o
148 ssb-$(CPTCFG_SSB_SDIOHOST) += sdio.o
149
150 # built-in drivers
151 --- /dev/null
152 +++ b/drivers/ssb/bridge_pcmcia_80211.c
153 @@ -0,0 +1,128 @@
154 +/*
155 + * Broadcom 43xx PCMCIA-SSB bridge module
156 + *
157 + * Copyright (c) 2007 Michael Buesch <m@bues.ch>
158 + *
159 + * Licensed under the GNU/GPL. See COPYING for details.
160 + */
161 +
162 +#include <linux/ssb/ssb.h>
163 +#include <linux/slab.h>
164 +#include <linux/module.h>
165 +
166 +#include <pcmcia/cistpl.h>
167 +#include <pcmcia/ciscode.h>
168 +#include <pcmcia/ds.h>
169 +#include <pcmcia/cisreg.h>
170 +
171 +#include "ssb_private.h"
172 +
173 +static const struct pcmcia_device_id ssb_host_pcmcia_tbl[] = {
174 + PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x448),
175 + PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x476),
176 + PCMCIA_DEVICE_NULL,
177 +};
178 +
179 +MODULE_DEVICE_TABLE(pcmcia, ssb_host_pcmcia_tbl);
180 +
181 +static int ssb_host_pcmcia_probe(struct pcmcia_device *dev)
182 +{
183 + struct ssb_bus *ssb;
184 + int err = -ENOMEM;
185 + int res = 0;
186 +
187 + ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
188 + if (!ssb)
189 + goto out_error;
190 +
191 + err = -ENODEV;
192 +
193 + dev->config_flags |= CONF_ENABLE_IRQ;
194 +
195 + dev->resource[2]->flags |= WIN_ENABLE | WIN_DATA_WIDTH_16 |
196 + WIN_USE_WAIT;
197 + dev->resource[2]->start = 0;
198 + dev->resource[2]->end = SSB_CORE_SIZE;
199 + res = pcmcia_request_window(dev, dev->resource[2], 250);
200 + if (res != 0)
201 + goto err_kfree_ssb;
202 +
203 + res = pcmcia_map_mem_page(dev, dev->resource[2], 0);
204 + if (res != 0)
205 + goto err_disable;
206 +
207 + if (!dev->irq)
208 + goto err_disable;
209 +
210 + res = pcmcia_enable_device(dev);
211 + if (res != 0)
212 + goto err_disable;
213 +
214 + err = ssb_bus_pcmciabus_register(ssb, dev, dev->resource[2]->start);
215 + if (err)
216 + goto err_disable;
217 + dev->priv = ssb;
218 +
219 + return 0;
220 +
221 +err_disable:
222 + pcmcia_disable_device(dev);
223 +err_kfree_ssb:
224 + kfree(ssb);
225 +out_error:
226 + ssb_err("Initialization failed (%d, %d)\n", res, err);
227 + return err;
228 +}
229 +
230 +static void ssb_host_pcmcia_remove(struct pcmcia_device *dev)
231 +{
232 + struct ssb_bus *ssb = dev->priv;
233 +
234 + ssb_bus_unregister(ssb);
235 + pcmcia_disable_device(dev);
236 + kfree(ssb);
237 + dev->priv = NULL;
238 +}
239 +
240 +#ifdef CPTCFG_PM
241 +static int ssb_host_pcmcia_suspend(struct pcmcia_device *dev)
242 +{
243 + struct ssb_bus *ssb = dev->priv;
244 +
245 + return ssb_bus_suspend(ssb);
246 +}
247 +
248 +static int ssb_host_pcmcia_resume(struct pcmcia_device *dev)
249 +{
250 + struct ssb_bus *ssb = dev->priv;
251 +
252 + return ssb_bus_resume(ssb);
253 +}
254 +#else /* CPTCFG_PM */
255 +# define ssb_host_pcmcia_suspend NULL
256 +# define ssb_host_pcmcia_resume NULL
257 +#endif /* CPTCFG_PM */
258 +
259 +static struct pcmcia_driver ssb_host_pcmcia_driver = {
260 + .owner = THIS_MODULE,
261 + .name = "ssb-pcmcia",
262 + .id_table = ssb_host_pcmcia_tbl,
263 + .probe = ssb_host_pcmcia_probe,
264 + .remove = ssb_host_pcmcia_remove,
265 + .suspend = ssb_host_pcmcia_suspend,
266 + .resume = ssb_host_pcmcia_resume,
267 +};
268 +
269 +/*
270 + * These are not module init/exit functions!
271 + * The module_pcmcia_driver() helper cannot be used here.
272 + */
273 +int ssb_host_pcmcia_init(void)
274 +{
275 + return pcmcia_register_driver(&ssb_host_pcmcia_driver);
276 +}
277 +
278 +void ssb_host_pcmcia_exit(void)
279 +{
280 + pcmcia_unregister_driver(&ssb_host_pcmcia_driver);
281 +}
282 --- a/drivers/ssb/main.c
283 +++ b/drivers/ssb/main.c
284 @@ -906,7 +906,6 @@ int ssb_bus_pcmciabus_register(struct ss
285
286 return err;
287 }
288 -EXPORT_SYMBOL(ssb_bus_pcmciabus_register);
289 #endif /* CPTCFG_SSB_PCMCIAHOST */
290
291 #ifdef CPTCFG_SSB_SDIOHOST
292 @@ -1474,6 +1473,12 @@ static int __init ssb_modinit(void)
293 /* don't fail SSB init because of this */
294 err = 0;
295 }
296 + err = ssb_host_pcmcia_init();
297 + if (err) {
298 + ssb_err("PCMCIA host initialization failed\n");
299 + /* don't fail SSB init because of this */
300 + err = 0;
301 + }
302 err = ssb_gige_init();
303 if (err) {
304 ssb_err("SSB Broadcom Gigabit Ethernet driver initialization failed\n");
305 @@ -1491,6 +1496,7 @@ fs_initcall(ssb_modinit);
306 static void __exit ssb_modexit(void)
307 {
308 ssb_gige_exit();
309 + ssb_host_pcmcia_exit();
310 b43_pci_ssb_bridge_exit();
311 bus_unregister(&ssb_bustype);
312 }
313 --- a/drivers/ssb/ssb_private.h
314 +++ b/drivers/ssb/ssb_private.h
315 @@ -94,6 +94,8 @@ extern int ssb_pcmcia_get_invariants(str
316 extern int ssb_pcmcia_hardware_setup(struct ssb_bus *bus);
317 extern void ssb_pcmcia_exit(struct ssb_bus *bus);
318 extern int ssb_pcmcia_init(struct ssb_bus *bus);
319 +extern int ssb_host_pcmcia_init(void);
320 +extern void ssb_host_pcmcia_exit(void);
321 extern const struct ssb_bus_ops ssb_pcmcia_ops;
322 #else /* CPTCFG_SSB_PCMCIAHOST */
323 static inline int ssb_pcmcia_switch_coreidx(struct ssb_bus *bus,
324 @@ -117,6 +119,13 @@ static inline int ssb_pcmcia_init(struct
325 {
326 return 0;
327 }
328 +static inline int ssb_host_pcmcia_init(void)
329 +{
330 + return 0;
331 +}
332 +static inline void ssb_host_pcmcia_exit(void)
333 +{
334 +}
335 #endif /* CPTCFG_SSB_PCMCIAHOST */
336
337 /* sdio.c */
338 --- a/drivers/net/wireless/b43/pcmcia.c
339 +++ /dev/null
340 @@ -1,145 +0,0 @@
341 -/*
342 -
343 - Broadcom B43 wireless driver
344 -
345 - Copyright (c) 2007 Michael Buesch <m@bues.ch>
346 -
347 - This program is free software; you can redistribute it and/or modify
348 - it under the terms of the GNU General Public License as published by
349 - the Free Software Foundation; either version 2 of the License, or
350 - (at your option) any later version.
351 -
352 - This program is distributed in the hope that it will be useful,
353 - but WITHOUT ANY WARRANTY; without even the implied warranty of
354 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
355 - GNU General Public License for more details.
356 -
357 - You should have received a copy of the GNU General Public License
358 - along with this program; see the file COPYING. If not, write to
359 - the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
360 - Boston, MA 02110-1301, USA.
361 -
362 -*/
363 -
364 -#include "pcmcia.h"
365 -
366 -#include <linux/ssb/ssb.h>
367 -#include <linux/slab.h>
368 -#include <linux/module.h>
369 -
370 -#include <pcmcia/cistpl.h>
371 -#include <pcmcia/ciscode.h>
372 -#include <pcmcia/ds.h>
373 -#include <pcmcia/cisreg.h>
374 -
375 -
376 -static const struct pcmcia_device_id b43_pcmcia_tbl[] = {
377 - PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x448),
378 - PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x476),
379 - PCMCIA_DEVICE_NULL,
380 -};
381 -
382 -MODULE_DEVICE_TABLE(pcmcia, b43_pcmcia_tbl);
383 -
384 -#ifdef CONFIG_PM
385 -static int b43_pcmcia_suspend(struct pcmcia_device *dev)
386 -{
387 - struct ssb_bus *ssb = dev->priv;
388 -
389 - return ssb_bus_suspend(ssb);
390 -}
391 -
392 -static int b43_pcmcia_resume(struct pcmcia_device *dev)
393 -{
394 - struct ssb_bus *ssb = dev->priv;
395 -
396 - return ssb_bus_resume(ssb);
397 -}
398 -#else /* CONFIG_PM */
399 -# define b43_pcmcia_suspend NULL
400 -# define b43_pcmcia_resume NULL
401 -#endif /* CONFIG_PM */
402 -
403 -static int b43_pcmcia_probe(struct pcmcia_device *dev)
404 -{
405 - struct ssb_bus *ssb;
406 - int err = -ENOMEM;
407 - int res = 0;
408 -
409 - ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
410 - if (!ssb)
411 - goto out_error;
412 -
413 - err = -ENODEV;
414 -
415 - dev->config_flags |= CONF_ENABLE_IRQ;
416 -
417 - dev->resource[2]->flags |= WIN_ENABLE | WIN_DATA_WIDTH_16 |
418 - WIN_USE_WAIT;
419 - dev->resource[2]->start = 0;
420 - dev->resource[2]->end = SSB_CORE_SIZE;
421 - res = pcmcia_request_window(dev, dev->resource[2], 250);
422 - if (res != 0)
423 - goto err_kfree_ssb;
424 -
425 - res = pcmcia_map_mem_page(dev, dev->resource[2], 0);
426 - if (res != 0)
427 - goto err_disable;
428 -
429 - if (!dev->irq)
430 - goto err_disable;
431 -
432 - res = pcmcia_enable_device(dev);
433 - if (res != 0)
434 - goto err_disable;
435 -
436 - err = ssb_bus_pcmciabus_register(ssb, dev, dev->resource[2]->start);
437 - if (err)
438 - goto err_disable;
439 - dev->priv = ssb;
440 -
441 - return 0;
442 -
443 -err_disable:
444 - pcmcia_disable_device(dev);
445 -err_kfree_ssb:
446 - kfree(ssb);
447 -out_error:
448 - printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n",
449 - res, err);
450 - return err;
451 -}
452 -
453 -static void b43_pcmcia_remove(struct pcmcia_device *dev)
454 -{
455 - struct ssb_bus *ssb = dev->priv;
456 -
457 - ssb_bus_unregister(ssb);
458 - pcmcia_disable_device(dev);
459 - kfree(ssb);
460 - dev->priv = NULL;
461 -}
462 -
463 -static struct pcmcia_driver b43_pcmcia_driver = {
464 - .owner = THIS_MODULE,
465 - .name = "b43-pcmcia",
466 - .id_table = b43_pcmcia_tbl,
467 - .probe = b43_pcmcia_probe,
468 - .remove = b43_pcmcia_remove,
469 - .suspend = b43_pcmcia_suspend,
470 - .resume = b43_pcmcia_resume,
471 -};
472 -
473 -/*
474 - * These are not module init/exit functions!
475 - * The module_pcmcia_driver() helper cannot be used here.
476 - */
477 -int b43_pcmcia_init(void)
478 -{
479 - return pcmcia_register_driver(&b43_pcmcia_driver);
480 -}
481 -
482 -void b43_pcmcia_exit(void)
483 -{
484 - pcmcia_unregister_driver(&b43_pcmcia_driver);
485 -}