Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / arch / mips / bcm63xx / boards / board_bcm963xx.c
blob9cc8fbf218a596d558c68812c2a52d508a03a278
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
4 * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
5 */
7 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <linux/platform_device.h>
13 #include <linux/ssb/ssb.h>
14 #include <asm/addrspace.h>
15 #include <bcm63xx_board.h>
16 #include <bcm63xx_cpu.h>
17 #include <bcm63xx_dev_uart.h>
18 #include <bcm63xx_regs.h>
19 #include <bcm63xx_io.h>
20 #include <bcm63xx_nvram.h>
21 #include <bcm63xx_dev_pci.h>
22 #include <bcm63xx_dev_enet.h>
23 #include <bcm63xx_dev_flash.h>
24 #include <bcm63xx_dev_hsspi.h>
25 #include <bcm63xx_dev_pcmcia.h>
26 #include <bcm63xx_dev_spi.h>
27 #include <bcm63xx_dev_usb_usbd.h>
28 #include <board_bcm963xx.h>
30 #include <uapi/linux/bcm933xx_hcs.h>
32 #define HCS_OFFSET_128K 0x20000
34 static struct board_info board;
37 * known 3368 boards
39 #ifdef CONFIG_BCM63XX_CPU_3368
40 static struct board_info __initdata board_cvg834g = {
41 .name = "CVG834G_E15R3921",
42 .expected_cpu_id = 0x3368,
44 .ephy_reset_gpio = 36,
45 .ephy_reset_gpio_flags = GPIOF_OUT_INIT_HIGH,
46 .has_pci = 1,
47 .has_uart0 = 1,
48 .has_uart1 = 1,
50 .has_enet0 = 1,
51 .enet0 = {
52 .has_phy = 1,
53 .use_internal_phy = 1,
56 .leds = {
58 .name = "CVG834G:green:power",
59 .gpio = 37,
60 .default_trigger= "default-on",
64 #endif /* CONFIG_BCM63XX_CPU_3368 */
67 * known 6328 boards
69 #ifdef CONFIG_BCM63XX_CPU_6328
70 static struct board_info __initdata board_96328avng = {
71 .name = "96328avng",
72 .expected_cpu_id = 0x6328,
74 .has_pci = 1,
75 .has_uart0 = 1,
77 .has_usbd = 0,
78 .usbd = {
79 .use_fullspeed = 0,
80 .port_no = 0,
83 .leds = {
85 .name = "96328avng::ppp-fail",
86 .gpio = 2,
87 .active_low = 1,
90 .name = "96328avng::power",
91 .gpio = 4,
92 .active_low = 1,
93 .default_trigger = "default-on",
96 .name = "96328avng::power-fail",
97 .gpio = 8,
98 .active_low = 1,
101 .name = "96328avng::wps",
102 .gpio = 9,
103 .active_low = 1,
106 .name = "96328avng::ppp",
107 .gpio = 11,
108 .active_low = 1,
112 #endif /* CONFIG_BCM63XX_CPU_6328 */
115 * known 6338 boards
117 #ifdef CONFIG_BCM63XX_CPU_6338
118 static struct board_info __initdata board_96338gw = {
119 .name = "96338GW",
120 .expected_cpu_id = 0x6338,
122 .has_ohci0 = 1,
123 .has_uart0 = 1,
125 .has_enet0 = 1,
126 .enet0 = {
127 .force_speed_100 = 1,
128 .force_duplex_full = 1,
131 .leds = {
133 .name = "adsl",
134 .gpio = 3,
135 .active_low = 1,
138 .name = "ses",
139 .gpio = 5,
140 .active_low = 1,
143 .name = "ppp-fail",
144 .gpio = 4,
145 .active_low = 1,
148 .name = "power",
149 .gpio = 0,
150 .active_low = 1,
151 .default_trigger = "default-on",
154 .name = "stop",
155 .gpio = 1,
156 .active_low = 1,
161 static struct board_info __initdata board_96338w = {
162 .name = "96338W",
163 .expected_cpu_id = 0x6338,
165 .has_uart0 = 1,
167 .has_enet0 = 1,
168 .enet0 = {
169 .force_speed_100 = 1,
170 .force_duplex_full = 1,
173 .leds = {
175 .name = "adsl",
176 .gpio = 3,
177 .active_low = 1,
180 .name = "ses",
181 .gpio = 5,
182 .active_low = 1,
185 .name = "ppp-fail",
186 .gpio = 4,
187 .active_low = 1,
190 .name = "power",
191 .gpio = 0,
192 .active_low = 1,
193 .default_trigger = "default-on",
196 .name = "stop",
197 .gpio = 1,
198 .active_low = 1,
202 #endif /* CONFIG_BCM63XX_CPU_6338 */
205 * known 6345 boards
207 #ifdef CONFIG_BCM63XX_CPU_6345
208 static struct board_info __initdata board_96345gw2 = {
209 .name = "96345GW2",
210 .expected_cpu_id = 0x6345,
212 .has_uart0 = 1,
214 #endif /* CONFIG_BCM63XX_CPU_6345 */
217 * known 6348 boards
219 #ifdef CONFIG_BCM63XX_CPU_6348
220 static struct board_info __initdata board_96348r = {
221 .name = "96348R",
222 .expected_cpu_id = 0x6348,
224 .has_pci = 1,
225 .has_uart0 = 1,
227 .has_enet0 = 1,
228 .enet0 = {
229 .has_phy = 1,
230 .use_internal_phy = 1,
233 .leds = {
235 .name = "adsl-fail",
236 .gpio = 2,
237 .active_low = 1,
240 .name = "ppp",
241 .gpio = 3,
242 .active_low = 1,
245 .name = "ppp-fail",
246 .gpio = 4,
247 .active_low = 1,
250 .name = "power",
251 .gpio = 0,
252 .active_low = 1,
253 .default_trigger = "default-on",
257 .name = "stop",
258 .gpio = 1,
259 .active_low = 1,
264 static struct board_info __initdata board_96348gw_10 = {
265 .name = "96348GW-10",
266 .expected_cpu_id = 0x6348,
268 .has_ohci0 = 1,
269 .has_pccard = 1,
270 .has_pci = 1,
271 .has_uart0 = 1,
273 .has_enet0 = 1,
274 .enet0 = {
275 .has_phy = 1,
276 .use_internal_phy = 1,
279 .has_enet1 = 1,
280 .enet1 = {
281 .force_speed_100 = 1,
282 .force_duplex_full = 1,
285 .leds = {
287 .name = "adsl-fail",
288 .gpio = 2,
289 .active_low = 1,
292 .name = "ppp",
293 .gpio = 3,
294 .active_low = 1,
297 .name = "ppp-fail",
298 .gpio = 4,
299 .active_low = 1,
302 .name = "power",
303 .gpio = 0,
304 .active_low = 1,
305 .default_trigger = "default-on",
308 .name = "stop",
309 .gpio = 1,
310 .active_low = 1,
315 static struct board_info __initdata board_96348gw_11 = {
316 .name = "96348GW-11",
317 .expected_cpu_id = 0x6348,
319 .has_ohci0 = 1,
320 .has_pccard = 1,
321 .has_pci = 1,
322 .has_uart0 = 1,
324 .has_enet0 = 1,
325 .enet0 = {
326 .has_phy = 1,
327 .use_internal_phy = 1,
330 .has_enet1 = 1,
331 .enet1 = {
332 .force_speed_100 = 1,
333 .force_duplex_full = 1,
336 .leds = {
338 .name = "adsl-fail",
339 .gpio = 2,
340 .active_low = 1,
343 .name = "ppp",
344 .gpio = 3,
345 .active_low = 1,
348 .name = "ppp-fail",
349 .gpio = 4,
350 .active_low = 1,
353 .name = "power",
354 .gpio = 0,
355 .active_low = 1,
356 .default_trigger = "default-on",
359 .name = "stop",
360 .gpio = 1,
361 .active_low = 1,
366 static struct board_info __initdata board_96348gw = {
367 .name = "96348GW",
368 .expected_cpu_id = 0x6348,
370 .has_ohci0 = 1,
371 .has_pci = 1,
372 .has_uart0 = 1,
374 .has_enet0 = 1,
375 .enet0 = {
376 .has_phy = 1,
377 .use_internal_phy = 1,
380 .has_enet1 = 1,
381 .enet1 = {
382 .force_speed_100 = 1,
383 .force_duplex_full = 1,
386 .leds = {
388 .name = "adsl-fail",
389 .gpio = 2,
390 .active_low = 1,
393 .name = "ppp",
394 .gpio = 3,
395 .active_low = 1,
398 .name = "ppp-fail",
399 .gpio = 4,
400 .active_low = 1,
403 .name = "power",
404 .gpio = 0,
405 .active_low = 1,
406 .default_trigger = "default-on",
409 .name = "stop",
410 .gpio = 1,
411 .active_low = 1,
416 static struct board_info __initdata board_FAST2404 = {
417 .name = "F@ST2404",
418 .expected_cpu_id = 0x6348,
420 .has_ohci0 = 1,
421 .has_pccard = 1,
422 .has_pci = 1,
423 .has_uart0 = 1,
425 .has_enet0 = 1,
426 .enet0 = {
427 .has_phy = 1,
428 .use_internal_phy = 1,
431 .has_enet1 = 1,
432 .enet1 = {
433 .force_speed_100 = 1,
434 .force_duplex_full = 1,
438 static struct board_info __initdata board_rta1025w_16 = {
439 .name = "RTA1025W_16",
440 .expected_cpu_id = 0x6348,
442 .has_pci = 1,
444 .has_enet0 = 1,
445 .enet0 = {
446 .has_phy = 1,
447 .use_internal_phy = 1,
450 .has_enet1 = 1,
451 .enet1 = {
452 .force_speed_100 = 1,
453 .force_duplex_full = 1,
457 static struct board_info __initdata board_DV201AMR = {
458 .name = "DV201AMR",
459 .expected_cpu_id = 0x6348,
461 .has_ohci0 = 1,
462 .has_pci = 1,
463 .has_uart0 = 1,
465 .has_enet0 = 1,
466 .enet0 = {
467 .has_phy = 1,
468 .use_internal_phy = 1,
471 .has_enet1 = 1,
472 .enet1 = {
473 .force_speed_100 = 1,
474 .force_duplex_full = 1,
478 static struct board_info __initdata board_96348gw_a = {
479 .name = "96348GW-A",
480 .expected_cpu_id = 0x6348,
482 .has_ohci0 = 1,
483 .has_pci = 1,
484 .has_uart0 = 1,
486 .has_enet0 = 1,
487 .enet0 = {
488 .has_phy = 1,
489 .use_internal_phy = 1,
492 .has_enet1 = 1,
493 .enet1 = {
494 .force_speed_100 = 1,
495 .force_duplex_full = 1,
498 #endif /* CONFIG_BCM63XX_CPU_6348 */
501 * known 6358 boards
503 #ifdef CONFIG_BCM63XX_CPU_6358
504 static struct board_info __initdata board_96358vw = {
505 .name = "96358VW",
506 .expected_cpu_id = 0x6358,
508 .has_ehci0 = 1,
509 .has_ohci0 = 1,
510 .has_pccard = 1,
511 .has_pci = 1,
512 .has_uart0 = 1,
514 .has_enet0 = 1,
515 .enet0 = {
516 .has_phy = 1,
517 .use_internal_phy = 1,
520 .has_enet1 = 1,
521 .enet1 = {
522 .force_speed_100 = 1,
523 .force_duplex_full = 1,
526 .leds = {
528 .name = "adsl-fail",
529 .gpio = 15,
530 .active_low = 1,
533 .name = "ppp",
534 .gpio = 22,
535 .active_low = 1,
538 .name = "ppp-fail",
539 .gpio = 23,
540 .active_low = 1,
543 .name = "power",
544 .gpio = 4,
545 .default_trigger = "default-on",
548 .name = "stop",
549 .gpio = 5,
554 static struct board_info __initdata board_96358vw2 = {
555 .name = "96358VW2",
556 .expected_cpu_id = 0x6358,
558 .has_ehci0 = 1,
559 .has_ohci0 = 1,
560 .has_pccard = 1,
561 .has_pci = 1,
562 .has_uart0 = 1,
564 .has_enet0 = 1,
565 .enet0 = {
566 .has_phy = 1,
567 .use_internal_phy = 1,
570 .has_enet1 = 1,
571 .enet1 = {
572 .force_speed_100 = 1,
573 .force_duplex_full = 1,
576 .leds = {
578 .name = "adsl",
579 .gpio = 22,
580 .active_low = 1,
583 .name = "ppp-fail",
584 .gpio = 23,
587 .name = "power",
588 .gpio = 5,
589 .active_low = 1,
590 .default_trigger = "default-on",
593 .name = "stop",
594 .gpio = 4,
595 .active_low = 1,
600 static struct board_info __initdata board_AGPFS0 = {
601 .name = "AGPF-S0",
602 .expected_cpu_id = 0x6358,
604 .has_ehci0 = 1,
605 .has_ohci0 = 1,
606 .has_pci = 1,
607 .has_uart0 = 1,
609 .has_enet0 = 1,
610 .enet0 = {
611 .has_phy = 1,
612 .use_internal_phy = 1,
615 .has_enet1 = 1,
616 .enet1 = {
617 .force_speed_100 = 1,
618 .force_duplex_full = 1,
622 static struct board_info __initdata board_DWVS0 = {
623 .name = "DWV-S0",
624 .expected_cpu_id = 0x6358,
626 .has_ehci0 = 1,
627 .has_ohci0 = 1,
628 .has_pci = 1,
630 .has_enet0 = 1,
631 .enet0 = {
632 .has_phy = 1,
633 .use_internal_phy = 1,
636 .has_enet1 = 1,
637 .enet1 = {
638 .force_speed_100 = 1,
639 .force_duplex_full = 1,
642 #endif /* CONFIG_BCM63XX_CPU_6358 */
645 * all boards
647 static const struct board_info __initconst *bcm963xx_boards[] = {
648 #ifdef CONFIG_BCM63XX_CPU_3368
649 &board_cvg834g,
650 #endif /* CONFIG_BCM63XX_CPU_3368 */
651 #ifdef CONFIG_BCM63XX_CPU_6328
652 &board_96328avng,
653 #endif /* CONFIG_BCM63XX_CPU_6328 */
654 #ifdef CONFIG_BCM63XX_CPU_6338
655 &board_96338gw,
656 &board_96338w,
657 #endif /* CONFIG_BCM63XX_CPU_6338 */
658 #ifdef CONFIG_BCM63XX_CPU_6345
659 &board_96345gw2,
660 #endif /* CONFIG_BCM63XX_CPU_6345 */
661 #ifdef CONFIG_BCM63XX_CPU_6348
662 &board_96348r,
663 &board_96348gw,
664 &board_96348gw_10,
665 &board_96348gw_11,
666 &board_FAST2404,
667 &board_DV201AMR,
668 &board_96348gw_a,
669 &board_rta1025w_16,
670 #endif /* CONFIG_BCM63XX_CPU_6348 */
671 #ifdef CONFIG_BCM63XX_CPU_6358
672 &board_96358vw,
673 &board_96358vw2,
674 &board_AGPFS0,
675 &board_DWVS0,
676 #endif /* CONFIG_BCM63XX_CPU_6358 */
680 * Register a sane SPROMv2 to make the on-board
681 * bcm4318 WLAN work
683 #ifdef CONFIG_SSB_PCIHOST
684 static struct ssb_sprom bcm63xx_sprom = {
685 .revision = 0x02,
686 .board_rev = 0x17,
687 .country_code = 0x0,
688 .ant_available_bg = 0x3,
689 .pa0b0 = 0x15ae,
690 .pa0b1 = 0xfa85,
691 .pa0b2 = 0xfe8d,
692 .pa1b0 = 0xffff,
693 .pa1b1 = 0xffff,
694 .pa1b2 = 0xffff,
695 .gpio0 = 0xff,
696 .gpio1 = 0xff,
697 .gpio2 = 0xff,
698 .gpio3 = 0xff,
699 .maxpwr_bg = 0x004c,
700 .itssi_bg = 0x00,
701 .boardflags_lo = 0x2848,
702 .boardflags_hi = 0x0000,
705 static int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
707 if (bus->bustype == SSB_BUSTYPE_PCI) {
708 memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
709 return 0;
710 } else {
711 pr_err("unable to fill SPROM for given bustype\n");
712 return -EINVAL;
715 #endif /* CONFIG_SSB_PCIHOST */
718 * return board name for /proc/cpuinfo
720 const char *board_get_name(void)
722 return board.name;
726 * early init callback, read nvram data from flash and checksum it
728 void __init board_prom_init(void)
730 unsigned int i;
731 u8 *boot_addr, *cfe;
732 char cfe_version[32];
733 char *board_name = NULL;
734 u32 val;
735 struct bcm_hcs *hcs;
737 /* read base address of boot chip select (0)
738 * 6328/6362 do not have MPI but boot from a fixed address
740 if (BCMCPU_IS_6328() || BCMCPU_IS_6362()) {
741 val = 0x18000000;
742 } else {
743 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
744 val &= MPI_CSBASE_BASE_MASK;
746 boot_addr = (u8 *)KSEG1ADDR(val);
748 /* dump cfe version */
749 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
750 if (strstarts(cfe, "cfe-")) {
751 if(cfe[4] == 'v') {
752 if(cfe[5] == 'd')
753 snprintf(cfe_version, 11, "%s",
754 (char *) &cfe[5]);
755 else if (cfe[10] > 0)
756 snprintf(cfe_version, sizeof(cfe_version),
757 "%u.%u.%u-%u.%u-%u", cfe[5], cfe[6],
758 cfe[7], cfe[8], cfe[9], cfe[10]);
759 else
760 snprintf(cfe_version, sizeof(cfe_version),
761 "%u.%u.%u-%u.%u", cfe[5], cfe[6],
762 cfe[7], cfe[8], cfe[9]);
763 } else {
764 snprintf(cfe_version, 12, "%s", (char *) &cfe[4]);
766 } else {
767 strcpy(cfe_version, "unknown");
769 pr_info("CFE version: %s\n", cfe_version);
771 bcm63xx_nvram_init(boot_addr + BCM963XX_NVRAM_OFFSET);
773 if (BCMCPU_IS_3368()) {
774 hcs = (struct bcm_hcs *)boot_addr;
775 board_name = hcs->filename;
776 } else {
777 board_name = bcm63xx_nvram_get_name();
779 /* find board by name */
780 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
781 if (strncmp(board_name, bcm963xx_boards[i]->name, 16))
782 continue;
783 /* copy, board desc array is marked initdata */
784 memcpy(&board, bcm963xx_boards[i], sizeof(board));
785 break;
788 /* bail out if board is not found, will complain later */
789 if (!board.name[0]) {
790 char name[17];
791 memcpy(name, board_name, 16);
792 name[16] = 0;
793 pr_err("unknown bcm963xx board: %s\n", name);
794 return;
797 /* setup pin multiplexing depending on board enabled device,
798 * this has to be done this early since PCI init is done
799 * inside arch_initcall */
800 val = 0;
802 #ifdef CONFIG_PCI
803 if (board.has_pci) {
804 bcm63xx_pci_enabled = 1;
805 if (BCMCPU_IS_6348())
806 val |= GPIO_MODE_6348_G2_PCI;
808 #endif /* CONFIG_PCI */
810 if (board.has_pccard) {
811 if (BCMCPU_IS_6348())
812 val |= GPIO_MODE_6348_G1_MII_PCCARD;
815 if (board.has_enet0 && !board.enet0.use_internal_phy) {
816 if (BCMCPU_IS_6348())
817 val |= GPIO_MODE_6348_G3_EXT_MII |
818 GPIO_MODE_6348_G0_EXT_MII;
821 if (board.has_enet1 && !board.enet1.use_internal_phy) {
822 if (BCMCPU_IS_6348())
823 val |= GPIO_MODE_6348_G3_EXT_MII |
824 GPIO_MODE_6348_G0_EXT_MII;
827 bcm_gpio_writel(val, GPIO_MODE_REG);
831 * second stage init callback, good time to panic if we couldn't
832 * identify on which board we're running since early printk is working
834 void __init board_setup(void)
836 if (!board.name[0])
837 panic("unable to detect bcm963xx board");
838 pr_info("board name: %s\n", board.name);
840 /* make sure we're running on expected cpu */
841 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
842 panic("unexpected CPU for bcm963xx board");
845 static struct gpio_led_platform_data bcm63xx_led_data;
847 static struct platform_device bcm63xx_gpio_leds = {
848 .name = "leds-gpio",
849 .id = 0,
850 .dev.platform_data = &bcm63xx_led_data,
854 * third stage init callback, register all board devices.
856 int __init board_register_devices(void)
858 if (board.has_uart0)
859 bcm63xx_uart_register(0);
861 if (board.has_uart1)
862 bcm63xx_uart_register(1);
864 if (board.has_pccard)
865 bcm63xx_pcmcia_register();
867 if (board.has_enet0 &&
868 !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
869 bcm63xx_enet_register(0, &board.enet0);
871 if (board.has_enet1 &&
872 !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
873 bcm63xx_enet_register(1, &board.enet1);
875 if (board.has_enetsw &&
876 !bcm63xx_nvram_get_mac_address(board.enetsw.mac_addr))
877 bcm63xx_enetsw_register(&board.enetsw);
879 if (board.has_usbd)
880 bcm63xx_usbd_register(&board.usbd);
882 /* Generate MAC address for WLAN and register our SPROM,
883 * do this after registering enet devices
885 #ifdef CONFIG_SSB_PCIHOST
886 if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
887 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
888 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
889 if (ssb_arch_register_fallback_sprom(
890 &bcm63xx_get_fallback_sprom) < 0)
891 pr_err("failed to register fallback SPROM\n");
893 #endif /* CONFIG_SSB_PCIHOST */
895 bcm63xx_spi_register();
897 bcm63xx_hsspi_register();
899 bcm63xx_flash_register();
901 bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
902 bcm63xx_led_data.leds = board.leds;
904 platform_device_register(&bcm63xx_gpio_leds);
906 if (board.ephy_reset_gpio && board.ephy_reset_gpio_flags)
907 gpio_request_one(board.ephy_reset_gpio,
908 board.ephy_reset_gpio_flags, "ephy-reset");
910 return 0;