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