kernel: backport bcma patches queued for 3.20
[openwrt/openwrt.git] / target / linux / bcm53xx / patches-3.14 / 800-bcma-use-two-different-initcalls-if-built-in.patch
1 From 666bdfc027cde41a171862dc698987a378c8b66a Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Mon, 9 Feb 2015 18:00:42 +0100
4 Subject: [PATCH RFC] bcma: use two different initcalls if built-in
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 This is needed as we can't initialize bus during fs_initcall.
10 Initialization requires SPROM which depends on NVRAM which depends on
11 mtd. Since mtd, spi, nand, spi-nor use standard module_init, we have to
12 do the same in bcma.
13 Without this we'll try to initialize SPROM without having a ready SPROM
14 proviver registered using bcma_arch_register_fallback_sprom.
15
16 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
17 ---
18 While this patch seems to work and I can compile bcma as built-in and
19 module, I'm not too proud of it. I don't really like these #if(n)def
20 tricks and I'm afraid bcma_modinit may be called even if
21 bcma_modinit_early failed.
22
23 Do you see any better idea of solving this?
24 ---
25 drivers/bcma/main.c | 16 ++++++++++++++--
26 1 file changed, 14 insertions(+), 2 deletions(-)
27
28 diff --git a/drivers/bcma/main.c b/drivers/bcma/main.c
29 index 9635f10..c394207 100644
30 --- a/drivers/bcma/main.c
31 +++ b/drivers/bcma/main.c
32 @@ -637,13 +637,25 @@ static int bcma_device_uevent(struct device *dev, struct kobj_uevent_env *env)
33 core->id.rev, core->id.class);
34 }
35
36 +/* Bus has to be registered early, before any bcma driver */
37 +static int __init bcma_modinit_early(void)
38 +{
39 + return bus_register(&bcma_bus_type);
40 +}
41 +#ifndef MODULE
42 +fs_initcall(bcma_modinit_early);
43 +#endif
44 +
45 +/* Initialization has to be done later with SPI/mtd/NAND/SPROM available */
46 static int __init bcma_modinit(void)
47 {
48 int err;
49
50 - err = bus_register(&bcma_bus_type);
51 +#ifdef MODULE
52 + err = bcma_modinit_early();
53 if (err)
54 return err;
55 +#endif
56
57 err = bcma_host_soc_register_driver();
58 if (err) {
59 @@ -660,7 +672,7 @@ static int __init bcma_modinit(void)
60
61 return err;
62 }
63 -fs_initcall(bcma_modinit);
64 +module_init(bcma_modinit);
65
66 static void __exit bcma_modexit(void)
67 {
68 --
69 1.8.4.5
70