brcm47xx: extract TRX from image on the fly
[openwrt.git] / target / linux / brcm47xx / patches-3.18 / 030-04-MIPS-BCM47XX-Move-SPROM-fallback-code-into-sprom.c.patch
1 From a59da8fb3b2a1f2df5f871464e43cd5b6ca6ceb1 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Tue, 28 Oct 2014 12:52:02 +0100
4 Subject: [PATCH 157/158] MIPS: BCM47XX: Move SPROM fallback code into sprom.c
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 This is some general cleanup as well as preparing sprom.c to become a
10 standalone driver. We will need this for bcm53xx ARM arch support.
11
12 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
13 Acked-by: Hauke Mehrtens <hauke@hauke-m.de>
14 Cc: linux-mips@linux-mips.org
15 Patchwork: https://patchwork.linux-mips.org/patch/8232/
16 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
17 ---
18  arch/mips/bcm47xx/bcm47xx_private.h |  3 ++
19  arch/mips/bcm47xx/setup.c           | 58 ++-----------------------------
20  arch/mips/bcm47xx/sprom.c           | 68 +++++++++++++++++++++++++++++++++++++
21  3 files changed, 73 insertions(+), 56 deletions(-)
22
23 --- a/arch/mips/bcm47xx/bcm47xx_private.h
24 +++ b/arch/mips/bcm47xx/bcm47xx_private.h
25 @@ -6,6 +6,9 @@
26  /* prom.c */
27  void __init bcm47xx_prom_highmem_init(void);
28  
29 +/* sprom.c */
30 +void bcm47xx_sprom_register_fallbacks(void);
31 +
32  /* buttons.c */
33  int __init bcm47xx_buttons_register(void);
34  
35 --- a/arch/mips/bcm47xx/setup.c
36 +++ b/arch/mips/bcm47xx/setup.c
37 @@ -102,23 +102,6 @@ static void bcm47xx_machine_halt(void)
38  }
39  
40  #ifdef CONFIG_BCM47XX_SSB
41 -static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out)
42 -{
43 -       char prefix[10];
44 -
45 -       if (bus->bustype == SSB_BUSTYPE_PCI) {
46 -               memset(out, 0, sizeof(struct ssb_sprom));
47 -               snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
48 -                        bus->host_pci->bus->number + 1,
49 -                        PCI_SLOT(bus->host_pci->devfn));
50 -               bcm47xx_fill_sprom(out, prefix, false);
51 -               return 0;
52 -       } else {
53 -               printk(KERN_WARNING "bcm47xx: unable to fill SPROM for given bustype.\n");
54 -               return -EINVAL;
55 -       }
56 -}
57 -
58  static int bcm47xx_get_invariants(struct ssb_bus *bus,
59                                   struct ssb_init_invariants *iv)
60  {
61 @@ -144,11 +127,6 @@ static void __init bcm47xx_register_ssb(
62         char buf[100];
63         struct ssb_mipscore *mcore;
64  
65 -       err = ssb_arch_register_fallback_sprom(&bcm47xx_get_sprom_ssb);
66 -       if (err)
67 -               printk(KERN_WARNING "bcm47xx: someone else already registered"
68 -                       " a ssb SPROM callback handler (err %d)\n", err);
69 -
70         err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE,
71                                       bcm47xx_get_invariants);
72         if (err)
73 @@ -171,44 +149,10 @@ static void __init bcm47xx_register_ssb(
74  #endif
75  
76  #ifdef CONFIG_BCM47XX_BCMA
77 -static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out)
78 -{
79 -       char prefix[10];
80 -       struct bcma_device *core;
81 -
82 -       switch (bus->hosttype) {
83 -       case BCMA_HOSTTYPE_PCI:
84 -               memset(out, 0, sizeof(struct ssb_sprom));
85 -               snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
86 -                        bus->host_pci->bus->number + 1,
87 -                        PCI_SLOT(bus->host_pci->devfn));
88 -               bcm47xx_fill_sprom(out, prefix, false);
89 -               return 0;
90 -       case BCMA_HOSTTYPE_SOC:
91 -               memset(out, 0, sizeof(struct ssb_sprom));
92 -               core = bcma_find_core(bus, BCMA_CORE_80211);
93 -               if (core) {
94 -                       snprintf(prefix, sizeof(prefix), "sb/%u/",
95 -                                core->core_index);
96 -                       bcm47xx_fill_sprom(out, prefix, true);
97 -               } else {
98 -                       bcm47xx_fill_sprom(out, NULL, false);
99 -               }
100 -               return 0;
101 -       default:
102 -               pr_warn("bcm47xx: unable to fill SPROM for given bustype.\n");
103 -               return -EINVAL;
104 -       }
105 -}
106 -
107  static void __init bcm47xx_register_bcma(void)
108  {
109         int err;
110  
111 -       err = bcma_arch_register_fallback_sprom(&bcm47xx_get_sprom_bcma);
112 -       if (err)
113 -               pr_warn("bcm47xx: someone else already registered a bcma SPROM callback handler (err %d)\n", err);
114 -
115         err = bcma_host_soc_register(&bcm47xx_bus.bcma);
116         if (err)
117                 panic("Failed to register BCMA bus (err %d)", err);
118 @@ -229,6 +173,7 @@ void __init plat_mem_setup(void)
119                 printk(KERN_INFO "bcm47xx: using bcma bus\n");
120  #ifdef CONFIG_BCM47XX_BCMA
121                 bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
122 +               bcm47xx_sprom_register_fallbacks();
123                 bcm47xx_register_bcma();
124                 bcm47xx_set_system_type(bcm47xx_bus.bcma.bus.chipinfo.id);
125  #ifdef CONFIG_HIGHMEM
126 @@ -239,6 +184,7 @@ void __init plat_mem_setup(void)
127                 printk(KERN_INFO "bcm47xx: using ssb bus\n");
128  #ifdef CONFIG_BCM47XX_SSB
129                 bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
130 +               bcm47xx_sprom_register_fallbacks();
131                 bcm47xx_register_ssb();
132                 bcm47xx_set_system_type(bcm47xx_bus.ssb.chip_id);
133  #endif
134 --- a/arch/mips/bcm47xx/sprom.c
135 +++ b/arch/mips/bcm47xx/sprom.c
136 @@ -801,3 +801,71 @@ void bcm47xx_fill_bcma_boardinfo(struct
137         nvram_read_u16(prefix, NULL, "boardtype", &boardinfo->type, 0, true);
138  }
139  #endif
140 +
141 +#if defined(CONFIG_BCM47XX_SSB)
142 +static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out)
143 +{
144 +       char prefix[10];
145 +
146 +       if (bus->bustype == SSB_BUSTYPE_PCI) {
147 +               memset(out, 0, sizeof(struct ssb_sprom));
148 +               snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
149 +                        bus->host_pci->bus->number + 1,
150 +                        PCI_SLOT(bus->host_pci->devfn));
151 +               bcm47xx_fill_sprom(out, prefix, false);
152 +               return 0;
153 +       } else {
154 +               pr_warn("bcm47xx: unable to fill SPROM for given bustype.\n");
155 +               return -EINVAL;
156 +       }
157 +}
158 +#endif
159 +
160 +#if defined(CONFIG_BCM47XX_BCMA)
161 +static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out)
162 +{
163 +       char prefix[10];
164 +       struct bcma_device *core;
165 +
166 +       switch (bus->hosttype) {
167 +       case BCMA_HOSTTYPE_PCI:
168 +               memset(out, 0, sizeof(struct ssb_sprom));
169 +               snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
170 +                        bus->host_pci->bus->number + 1,
171 +                        PCI_SLOT(bus->host_pci->devfn));
172 +               bcm47xx_fill_sprom(out, prefix, false);
173 +               return 0;
174 +       case BCMA_HOSTTYPE_SOC:
175 +               memset(out, 0, sizeof(struct ssb_sprom));
176 +               core = bcma_find_core(bus, BCMA_CORE_80211);
177 +               if (core) {
178 +                       snprintf(prefix, sizeof(prefix), "sb/%u/",
179 +                                core->core_index);
180 +                       bcm47xx_fill_sprom(out, prefix, true);
181 +               } else {
182 +                       bcm47xx_fill_sprom(out, NULL, false);
183 +               }
184 +               return 0;
185 +       default:
186 +               pr_warn("bcm47xx: unable to fill SPROM for given bustype.\n");
187 +               return -EINVAL;
188 +       }
189 +}
190 +#endif
191 +
192 +/*
193 + * On bcm47xx we need to register SPROM fallback handler very early, so we can't
194 + * use anything like platform device / driver for this.
195 + */
196 +void bcm47xx_sprom_register_fallbacks(void)
197 +{
198 +#if defined(CONFIG_BCM47XX_SSB)
199 +       if (ssb_arch_register_fallback_sprom(&bcm47xx_get_sprom_ssb))
200 +               pr_warn("Failed to registered ssb SPROM handler\n");
201 +#endif
202 +
203 +#if defined(CONFIG_BCM47XX_BCMA)
204 +       if (bcma_arch_register_fallback_sprom(&bcm47xx_get_sprom_bcma))
205 +               pr_warn("Failed to registered bcma SPROM handler\n");
206 +#endif
207 +}