90b1640d16af4fde42e184bb355d02b336b175f9
[oweals/openwrt.git] / target / linux / bcm63xx / patches-4.14 / 207-MIPS-BCM63XX-move-device-registration-code-into-its-.patch
1 From 5a50cb0d53344a2429831b00925d6183d4d332e1 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jogo@openwrt.org>
3 Date: Sun, 9 Mar 2014 03:54:05 +0100
4 Subject: [PATCH 40/44] MIPS: BCM63XX: move device registration code into its
5  own file
6
7 Move device registration code into its own file to allow sharing it
8 between board implementations.
9
10 Signed-off-by: Jonas Gorski <jogo@openwrt.org>
11 ---
12  arch/mips/bcm63xx/boards/Makefile         |   1 +
13  arch/mips/bcm63xx/boards/board_bcm963xx.c | 188 +-------------------------
14  arch/mips/bcm63xx/boards/board_common.c   | 215 ++++++++++++++++++++++++++++++
15  arch/mips/bcm63xx/boards/board_common.h   |   8 ++
16  4 files changed, 223 insertions(+), 183 deletions(-)
17  create mode 100644 arch/mips/bcm63xx/boards/board_common.c
18  create mode 100644 arch/mips/bcm63xx/boards/board_common.h
19
20 --- a/arch/mips/bcm63xx/boards/Makefile
21 +++ b/arch/mips/bcm63xx/boards/Makefile
22 @@ -1 +1,2 @@
23 +obj-y                                  += board_common.o
24  obj-$(CONFIG_BOARD_BCM963XX)           += board_bcm963xx.o
25 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
26 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
27 @@ -12,33 +12,21 @@
28  #include <linux/init.h>
29  #include <linux/kernel.h>
30  #include <linux/string.h>
31 -#include <linux/platform_device.h>
32 -#include <linux/ssb/ssb.h>
33  #include <asm/addrspace.h>
34  #include <bcm63xx_board.h>
35  #include <bcm63xx_cpu.h>
36 -#include <bcm63xx_dev_uart.h>
37  #include <bcm63xx_regs.h>
38  #include <bcm63xx_io.h>
39  #include <bcm63xx_nvram.h>
40 -#include <bcm63xx_dev_pci.h>
41 -#include <bcm63xx_dev_enet.h>
42 -#include <bcm63xx_dev_flash.h>
43 -#include <bcm63xx_dev_hsspi.h>
44 -#include <bcm63xx_dev_pcmcia.h>
45 -#include <bcm63xx_dev_spi.h>
46 -#include <bcm63xx_dev_usb_ehci.h>
47 -#include <bcm63xx_dev_usb_ohci.h>
48 -#include <bcm63xx_dev_usb_usbd.h>
49  #include <board_bcm963xx.h>
50  
51 +#include "board_common.h"
52 +
53  #include <uapi/linux/bcm933xx_hcs.h>
54  
55  
56  #define HCS_OFFSET_128K                        0x20000
57  
58 -static struct board_info board;
59 -
60  /*
61   * known 3368 boards
62   */
63 @@ -695,52 +683,6 @@ static const struct board_info __initcon
64  };
65  
66  /*
67 - * Register a sane SPROMv2 to make the on-board
68 - * bcm4318 WLAN work
69 - */
70 -#ifdef CONFIG_SSB_PCIHOST
71 -static struct ssb_sprom bcm63xx_sprom = {
72 -       .revision               = 0x02,
73 -       .board_rev              = 0x17,
74 -       .country_code           = 0x0,
75 -       .ant_available_bg       = 0x3,
76 -       .pa0b0                  = 0x15ae,
77 -       .pa0b1                  = 0xfa85,
78 -       .pa0b2                  = 0xfe8d,
79 -       .pa1b0                  = 0xffff,
80 -       .pa1b1                  = 0xffff,
81 -       .pa1b2                  = 0xffff,
82 -       .gpio0                  = 0xff,
83 -       .gpio1                  = 0xff,
84 -       .gpio2                  = 0xff,
85 -       .gpio3                  = 0xff,
86 -       .maxpwr_bg              = 0x004c,
87 -       .itssi_bg               = 0x00,
88 -       .boardflags_lo          = 0x2848,
89 -       .boardflags_hi          = 0x0000,
90 -};
91 -
92 -int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
93 -{
94 -       if (bus->bustype == SSB_BUSTYPE_PCI) {
95 -               memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
96 -               return 0;
97 -       } else {
98 -               pr_err("unable to fill SPROM for given bustype\n");
99 -               return -EINVAL;
100 -       }
101 -}
102 -#endif
103 -
104 -/*
105 - * return board name for /proc/cpuinfo
106 - */
107 -const char *board_get_name(void)
108 -{
109 -       return board.name;
110 -}
111 -
112 -/*
113   * early init callback, read nvram data from flash and checksum it
114   */
115  void __init board_prom_init(void)
116 @@ -785,137 +727,15 @@ void __init board_prom_init(void)
117                 if (strncmp(board_name, bcm963xx_boards[i]->name, 16))
118                         continue;
119                 /* copy, board desc array is marked initdata */
120 -               memcpy(&board, bcm963xx_boards[i], sizeof(board));
121 +               board_early_setup(bcm963xx_boards[i]);
122                 break;
123         }
124  
125 -       /* bail out if board is not found, will complain later */
126 -       if (!board.name[0]) {
127 +       /* warn if board is not found, will complain later */
128 +       if (i == ARRAY_SIZE(bcm963xx_boards)) {
129                 char name[17];
130                 memcpy(name, board_name, 16);
131                 name[16] = 0;
132                 pr_err("unknown bcm963xx board: %s\n", name);
133 -               return;
134 -       }
135 -
136 -       /* setup pin multiplexing depending on board enabled device,
137 -        * this has to be done this early since PCI init is done
138 -        * inside arch_initcall */
139 -       val = 0;
140 -
141 -#ifdef CONFIG_PCI
142 -       if (board.has_pci) {
143 -               bcm63xx_pci_enabled = 1;
144 -               if (BCMCPU_IS_6348())
145 -                       val |= GPIO_MODE_6348_G2_PCI;
146         }
147 -#endif
148 -
149 -       if (board.has_pccard) {
150 -               if (BCMCPU_IS_6348())
151 -                       val |= GPIO_MODE_6348_G1_MII_PCCARD;
152 -       }
153 -
154 -       if (board.has_enet0 && !board.enet0.use_internal_phy) {
155 -               if (BCMCPU_IS_6348())
156 -                       val |= GPIO_MODE_6348_G3_EXT_MII |
157 -                               GPIO_MODE_6348_G0_EXT_MII;
158 -       }
159 -
160 -       if (board.has_enet1 && !board.enet1.use_internal_phy) {
161 -               if (BCMCPU_IS_6348())
162 -                       val |= GPIO_MODE_6348_G3_EXT_MII |
163 -                               GPIO_MODE_6348_G0_EXT_MII;
164 -       }
165 -
166 -       bcm_gpio_writel(val, GPIO_MODE_REG);
167 -}
168 -
169 -/*
170 - * second stage init callback, good time to panic if we couldn't
171 - * identify on which board we're running since early printk is working
172 - */
173 -void __init board_setup(void)
174 -{
175 -       if (!board.name[0])
176 -               panic("unable to detect bcm963xx board");
177 -       pr_info("board name: %s\n", board.name);
178 -
179 -       /* make sure we're running on expected cpu */
180 -       if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
181 -               panic("unexpected CPU for bcm963xx board");
182 -}
183 -
184 -static struct gpio_led_platform_data bcm63xx_led_data;
185 -
186 -static struct platform_device bcm63xx_gpio_leds = {
187 -       .name                   = "leds-gpio",
188 -       .id                     = 0,
189 -       .dev.platform_data      = &bcm63xx_led_data,
190 -};
191 -
192 -/*
193 - * third stage init callback, register all board devices.
194 - */
195 -int __init board_register_devices(void)
196 -{
197 -       if (board.has_uart0)
198 -               bcm63xx_uart_register(0);
199 -
200 -       if (board.has_uart1)
201 -               bcm63xx_uart_register(1);
202 -
203 -       if (board.has_pccard)
204 -               bcm63xx_pcmcia_register();
205 -
206 -       if (board.has_enet0 &&
207 -           !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
208 -               bcm63xx_enet_register(0, &board.enet0);
209 -
210 -       if (board.has_enet1 &&
211 -           !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
212 -               bcm63xx_enet_register(1, &board.enet1);
213 -
214 -       if (board.has_enetsw &&
215 -           !bcm63xx_nvram_get_mac_address(board.enetsw.mac_addr))
216 -               bcm63xx_enetsw_register(&board.enetsw);
217 -
218 -       if (board.has_usbd)
219 -               bcm63xx_usbd_register(&board.usbd);
220 -
221 -       if (board.has_ehci0)
222 -               bcm63xx_ehci_register();
223 -
224 -       if (board.has_ohci0)
225 -               bcm63xx_ohci_register();
226 -
227 -       /* Generate MAC address for WLAN and register our SPROM,
228 -        * do this after registering enet devices
229 -        */
230 -#ifdef CONFIG_SSB_PCIHOST
231 -       if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
232 -               memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
233 -               memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
234 -               if (ssb_arch_register_fallback_sprom(
235 -                               &bcm63xx_get_fallback_sprom) < 0)
236 -                       pr_err("failed to register fallback SPROM\n");
237 -       }
238 -#endif
239 -
240 -       bcm63xx_spi_register();
241 -
242 -       bcm63xx_hsspi_register();
243 -
244 -       bcm63xx_flash_register();
245 -
246 -       bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
247 -       bcm63xx_led_data.leds = board.leds;
248 -
249 -       platform_device_register(&bcm63xx_gpio_leds);
250 -
251 -       if (board.ephy_reset_gpio && board.ephy_reset_gpio_flags)
252 -               gpio_request_one(board.ephy_reset_gpio,
253 -                               board.ephy_reset_gpio_flags, "ephy-reset");
254 -
255 -       return 0;
256  }
257 --- /dev/null
258 +++ b/arch/mips/bcm63xx/boards/board_common.c
259 @@ -0,0 +1,214 @@
260 +/*
261 + * This file is subject to the terms and conditions of the GNU General Public
262 + * License.  See the file "COPYING" in the main directory of this archive
263 + * for more details.
264 + *
265 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
266 + * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
267 + */
268 +
269 +#include <linux/init.h>
270 +#include <linux/kernel.h>
271 +#include <linux/string.h>
272 +#include <linux/platform_device.h>
273 +#include <linux/ssb/ssb.h>
274 +#include <asm/addrspace.h>
275 +#include <bcm63xx_board.h>
276 +#include <bcm63xx_cpu.h>
277 +#include <bcm63xx_dev_uart.h>
278 +#include <bcm63xx_regs.h>
279 +#include <bcm63xx_io.h>
280 +#include <bcm63xx_nvram.h>
281 +#include <bcm63xx_gpio.h>
282 +#include <bcm63xx_dev_pci.h>
283 +#include <bcm63xx_dev_enet.h>
284 +#include <bcm63xx_dev_flash.h>
285 +#include <bcm63xx_dev_hsspi.h>
286 +#include <bcm63xx_dev_pcmcia.h>
287 +#include <bcm63xx_dev_spi.h>
288 +#include <bcm63xx_dev_usb_ehci.h>
289 +#include <bcm63xx_dev_usb_ohci.h>
290 +#include <bcm63xx_dev_usb_usbd.h>
291 +#include <board_bcm963xx.h>
292 +
293 +#define PFX    "board: "
294 +
295 +static struct board_info board;
296 +
297 +/*
298 + * Register a sane SPROMv2 to make the on-board
299 + * bcm4318 WLAN work
300 + */
301 +#ifdef CONFIG_SSB_PCIHOST
302 +static struct ssb_sprom bcm63xx_sprom = {
303 +       .revision               = 0x02,
304 +       .board_rev              = 0x17,
305 +       .country_code           = 0x0,
306 +       .ant_available_bg       = 0x3,
307 +       .pa0b0                  = 0x15ae,
308 +       .pa0b1                  = 0xfa85,
309 +       .pa0b2                  = 0xfe8d,
310 +       .pa1b0                  = 0xffff,
311 +       .pa1b1                  = 0xffff,
312 +       .pa1b2                  = 0xffff,
313 +       .gpio0                  = 0xff,
314 +       .gpio1                  = 0xff,
315 +       .gpio2                  = 0xff,
316 +       .gpio3                  = 0xff,
317 +       .maxpwr_bg              = 0x004c,
318 +       .itssi_bg               = 0x00,
319 +       .boardflags_lo          = 0x2848,
320 +       .boardflags_hi          = 0x0000,
321 +};
322 +
323 +int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
324 +{
325 +       if (bus->bustype == SSB_BUSTYPE_PCI) {
326 +               memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
327 +               return 0;
328 +       } else {
329 +               printk(KERN_ERR PFX "unable to fill SPROM for given bustype.\n");
330 +               return -EINVAL;
331 +       }
332 +}
333 +#endif
334 +
335 +/*
336 + * return board name for /proc/cpuinfo
337 + */
338 +const char *board_get_name(void)
339 +{
340 +       return board.name;
341 +}
342 +
343 +/*
344 + * setup board for device registration
345 + */
346 +void __init board_early_setup(const struct board_info *target)
347 +{
348 +       u32 val;
349 +
350 +       memcpy(&board, target, sizeof(board));
351 +
352 +       /* setup pin multiplexing depending on board enabled device,
353 +        * this has to be done this early since PCI init is done
354 +        * inside arch_initcall */
355 +       val = 0;
356 +
357 +#ifdef CONFIG_PCI
358 +       if (board.has_pci) {
359 +               bcm63xx_pci_enabled = 1;
360 +               if (BCMCPU_IS_6348())
361 +                       val |= GPIO_MODE_6348_G2_PCI;
362 +       }
363 +#endif
364 +
365 +       if (board.has_pccard) {
366 +               if (BCMCPU_IS_6348())
367 +                       val |= GPIO_MODE_6348_G1_MII_PCCARD;
368 +       }
369 +
370 +       if (board.has_enet0 && !board.enet0.use_internal_phy) {
371 +               if (BCMCPU_IS_6348())
372 +                       val |= GPIO_MODE_6348_G3_EXT_MII |
373 +                               GPIO_MODE_6348_G0_EXT_MII;
374 +       }
375 +
376 +       if (board.has_enet1 && !board.enet1.use_internal_phy) {
377 +               if (BCMCPU_IS_6348())
378 +                       val |= GPIO_MODE_6348_G3_EXT_MII |
379 +                               GPIO_MODE_6348_G0_EXT_MII;
380 +       }
381 +
382 +       bcm_gpio_writel(val, GPIO_MODE_REG);
383 +}
384 +
385 +
386 +/*
387 + * second stage init callback, good time to panic if we couldn't
388 + * identify on which board we're running since early printk is working
389 + */
390 +void __init board_setup(void)
391 +{
392 +       if (!board.name[0])
393 +               panic("unable to detect bcm963xx board");
394 +       printk(KERN_INFO PFX "board name: %s\n", board.name);
395 +
396 +       /* make sure we're running on expected cpu */
397 +       if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
398 +               panic("unexpected CPU for bcm963xx board");
399 +}
400 +
401 +static struct gpio_led_platform_data bcm63xx_led_data;
402 +
403 +static struct platform_device bcm63xx_gpio_leds = {
404 +       .name                   = "leds-gpio",
405 +       .id                     = 0,
406 +       .dev.platform_data      = &bcm63xx_led_data,
407 +};
408 +
409 +/*
410 + * third stage init callback, register all board devices.
411 + */
412 +int __init board_register_devices(void)
413 +{
414 +       if (board.has_uart0)
415 +               bcm63xx_uart_register(0);
416 +
417 +       if (board.has_uart1)
418 +               bcm63xx_uart_register(1);
419 +
420 +       if (board.has_pccard)
421 +               bcm63xx_pcmcia_register();
422 +
423 +       if (board.has_enet0 &&
424 +           !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
425 +               bcm63xx_enet_register(0, &board.enet0);
426 +
427 +       if (board.has_enet1 &&
428 +           !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
429 +               bcm63xx_enet_register(1, &board.enet1);
430 +
431 +       if (board.has_enetsw &&
432 +           !bcm63xx_nvram_get_mac_address(board.enetsw.mac_addr))
433 +               bcm63xx_enetsw_register(&board.enetsw);
434 +
435 +       if (board.has_usbd)
436 +               bcm63xx_usbd_register(&board.usbd);
437 +
438 +       if (board.has_ehci0)
439 +               bcm63xx_ehci_register();
440 +
441 +       if (board.has_ohci0)
442 +               bcm63xx_ohci_register();
443 +
444 +       /* Generate MAC address for WLAN and register our SPROM,
445 +        * do this after registering enet devices
446 +        */
447 +#ifdef CONFIG_SSB_PCIHOST
448 +       if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
449 +               memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
450 +               memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
451 +               if (ssb_arch_register_fallback_sprom(
452 +                               &bcm63xx_get_fallback_sprom) < 0)
453 +                       pr_err(PFX "failed to register fallback SPROM\n");
454 +       }
455 +#endif
456 +
457 +       bcm63xx_spi_register();
458 +
459 +       bcm63xx_hsspi_register();
460 +
461 +       bcm63xx_flash_register();
462 +
463 +       bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
464 +       bcm63xx_led_data.leds = board.leds;
465 +
466 +       platform_device_register(&bcm63xx_gpio_leds);
467 +
468 +       if (board.ephy_reset_gpio && board.ephy_reset_gpio_flags)
469 +               gpio_request_one(board.ephy_reset_gpio,
470 +                               board.ephy_reset_gpio_flags, "ephy-reset");
471 +
472 +       return 0;
473 +}
474 --- /dev/null
475 +++ b/arch/mips/bcm63xx/boards/board_common.h
476 @@ -0,0 +1,8 @@
477 +#ifndef __BOARD_COMMON_H
478 +#define __BOARD_COMMON_H
479 +
480 +#include <board_bcm963xx.h>
481 +
482 +void board_early_setup(const struct board_info *board);
483 +
484 +#endif /* __BOARD_COMMON_H */