1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
4 * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
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;
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_INIT_HIGH,
53 .use_internal_phy = 1,
58 .name = "CVG834G:green:power",
60 .default_trigger= "default-on",
64 #endif /* CONFIG_BCM63XX_CPU_3368 */
69 #ifdef CONFIG_BCM63XX_CPU_6328
70 static struct board_info __initdata board_96328avng = {
72 .expected_cpu_id = 0x6328,
85 .name = "96328avng::ppp-fail",
90 .name = "96328avng::power",
93 .default_trigger = "default-on",
96 .name = "96328avng::power-fail",
101 .name = "96328avng::wps",
106 .name = "96328avng::ppp",
112 #endif /* CONFIG_BCM63XX_CPU_6328 */
117 #ifdef CONFIG_BCM63XX_CPU_6338
118 static struct board_info __initdata board_96338gw = {
120 .expected_cpu_id = 0x6338,
127 .force_speed_100 = 1,
128 .force_duplex_full = 1,
151 .default_trigger = "default-on",
161 static struct board_info __initdata board_96338w = {
163 .expected_cpu_id = 0x6338,
169 .force_speed_100 = 1,
170 .force_duplex_full = 1,
193 .default_trigger = "default-on",
202 #endif /* CONFIG_BCM63XX_CPU_6338 */
207 #ifdef CONFIG_BCM63XX_CPU_6345
208 static struct board_info __initdata board_96345gw2 = {
210 .expected_cpu_id = 0x6345,
214 #endif /* CONFIG_BCM63XX_CPU_6345 */
219 #ifdef CONFIG_BCM63XX_CPU_6348
220 static struct board_info __initdata board_96348r = {
222 .expected_cpu_id = 0x6348,
230 .use_internal_phy = 1,
253 .default_trigger = "default-on",
264 static struct board_info __initdata board_96348gw_10 = {
265 .name = "96348GW-10",
266 .expected_cpu_id = 0x6348,
276 .use_internal_phy = 1,
281 .force_speed_100 = 1,
282 .force_duplex_full = 1,
305 .default_trigger = "default-on",
315 static struct board_info __initdata board_96348gw_11 = {
316 .name = "96348GW-11",
317 .expected_cpu_id = 0x6348,
327 .use_internal_phy = 1,
332 .force_speed_100 = 1,
333 .force_duplex_full = 1,
356 .default_trigger = "default-on",
366 static struct board_info __initdata board_96348gw = {
368 .expected_cpu_id = 0x6348,
377 .use_internal_phy = 1,
382 .force_speed_100 = 1,
383 .force_duplex_full = 1,
406 .default_trigger = "default-on",
416 static struct board_info __initdata board_FAST2404 = {
418 .expected_cpu_id = 0x6348,
428 .use_internal_phy = 1,
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,
447 .use_internal_phy = 1,
452 .force_speed_100 = 1,
453 .force_duplex_full = 1,
457 static struct board_info __initdata board_DV201AMR = {
459 .expected_cpu_id = 0x6348,
468 .use_internal_phy = 1,
473 .force_speed_100 = 1,
474 .force_duplex_full = 1,
478 static struct board_info __initdata board_96348gw_a = {
480 .expected_cpu_id = 0x6348,
489 .use_internal_phy = 1,
494 .force_speed_100 = 1,
495 .force_duplex_full = 1,
498 #endif /* CONFIG_BCM63XX_CPU_6348 */
503 #ifdef CONFIG_BCM63XX_CPU_6358
504 static struct board_info __initdata board_96358vw = {
506 .expected_cpu_id = 0x6358,
517 .use_internal_phy = 1,
522 .force_speed_100 = 1,
523 .force_duplex_full = 1,
545 .default_trigger = "default-on",
554 static struct board_info __initdata board_96358vw2 = {
556 .expected_cpu_id = 0x6358,
567 .use_internal_phy = 1,
572 .force_speed_100 = 1,
573 .force_duplex_full = 1,
590 .default_trigger = "default-on",
600 static struct board_info __initdata board_AGPFS0 = {
602 .expected_cpu_id = 0x6358,
612 .use_internal_phy = 1,
617 .force_speed_100 = 1,
618 .force_duplex_full = 1,
622 static struct board_info __initdata board_DWVS0 = {
624 .expected_cpu_id = 0x6358,
633 .use_internal_phy = 1,
638 .force_speed_100 = 1,
639 .force_duplex_full = 1,
642 #endif /* CONFIG_BCM63XX_CPU_6358 */
647 static const struct board_info __initconst *bcm963xx_boards[] = {
648 #ifdef CONFIG_BCM63XX_CPU_3368
650 #endif /* CONFIG_BCM63XX_CPU_3368 */
651 #ifdef CONFIG_BCM63XX_CPU_6328
653 #endif /* CONFIG_BCM63XX_CPU_6328 */
654 #ifdef CONFIG_BCM63XX_CPU_6338
657 #endif /* CONFIG_BCM63XX_CPU_6338 */
658 #ifdef CONFIG_BCM63XX_CPU_6345
660 #endif /* CONFIG_BCM63XX_CPU_6345 */
661 #ifdef CONFIG_BCM63XX_CPU_6348
670 #endif /* CONFIG_BCM63XX_CPU_6348 */
671 #ifdef CONFIG_BCM63XX_CPU_6358
676 #endif /* CONFIG_BCM63XX_CPU_6358 */
680 * Register a sane SPROMv2 to make the on-board
683 #ifdef CONFIG_SSB_PCIHOST
684 static struct ssb_sprom bcm63xx_sprom = {
688 .ant_available_bg = 0x3,
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));
711 pr_err("unable to fill SPROM for given bustype\n");
715 #endif /* CONFIG_SSB_PCIHOST */
718 * return board name for /proc/cpuinfo
720 const char *board_get_name(void)
726 * early init callback, read nvram data from flash and checksum it
728 void __init board_prom_init(void)
732 char cfe_version[32];
733 char *board_name = NULL;
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()) {
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-")) {
753 snprintf(cfe_version, 11, "%s",
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]);
760 snprintf(cfe_version, sizeof(cfe_version),
761 "%u.%u.%u-%u.%u", cfe[5], cfe[6],
762 cfe[7], cfe[8], cfe[9]);
764 snprintf(cfe_version, 12, "%s", (char *) &cfe[4]);
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;
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))
783 /* copy, board desc array is marked initdata */
784 memcpy(&board, bcm963xx_boards[i], sizeof(board));
788 /* bail out if board is not found, will complain later */
789 if (!board.name[0]) {
791 memcpy(name, board_name, 16);
793 pr_err("unknown bcm963xx board: %s\n", name);
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 */
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)
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 = {
850 .dev.platform_data = &bcm63xx_led_data,
854 * third stage init callback, register all board devices.
856 int __init board_register_devices(void)
859 bcm63xx_uart_register(0);
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);
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");