2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7 * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/string.h>
15 #include <linux/platform_device.h>
16 #include <linux/ssb/ssb.h>
17 #include <asm/addrspace.h>
18 #include <bcm63xx_board.h>
19 #include <bcm63xx_cpu.h>
20 #include <bcm63xx_dev_uart.h>
21 #include <bcm63xx_regs.h>
22 #include <bcm63xx_io.h>
23 #include <bcm63xx_nvram.h>
24 #include <bcm63xx_dev_pci.h>
25 #include <bcm63xx_dev_enet.h>
26 #include <bcm63xx_dev_flash.h>
27 #include <bcm63xx_dev_hsspi.h>
28 #include <bcm63xx_dev_pcmcia.h>
29 #include <bcm63xx_dev_spi.h>
30 #include <bcm63xx_dev_usb_usbd.h>
31 #include <board_bcm963xx.h>
33 #include <uapi/linux/bcm933xx_hcs.h>
36 #define HCS_OFFSET_128K 0x20000
38 static struct board_info board;
43 #ifdef CONFIG_BCM63XX_CPU_3368
44 static struct board_info __initdata board_cvg834g = {
45 .name = "CVG834G_E15R3921",
46 .expected_cpu_id = 0x3368,
56 .use_internal_phy = 1,
61 .name = "CVG834G:green:power",
63 .default_trigger= "default-on",
67 .ephy_reset_gpio = 36,
68 .ephy_reset_gpio_flags = GPIOF_INIT_HIGH,
75 #ifdef CONFIG_BCM63XX_CPU_6328
76 static struct board_info __initdata board_96328avng = {
78 .expected_cpu_id = 0x6328,
91 .name = "96328avng::ppp-fail",
96 .name = "96328avng::power",
99 .default_trigger = "default-on",
102 .name = "96328avng::power-fail",
107 .name = "96328avng::wps",
112 .name = "96328avng::ppp",
123 #ifdef CONFIG_BCM63XX_CPU_6338
124 static struct board_info __initdata board_96338gw = {
126 .expected_cpu_id = 0x6338,
131 .force_speed_100 = 1,
132 .force_duplex_full = 1,
157 .default_trigger = "default-on",
167 static struct board_info __initdata board_96338w = {
169 .expected_cpu_id = 0x6338,
174 .force_speed_100 = 1,
175 .force_duplex_full = 1,
198 .default_trigger = "default-on",
212 #ifdef CONFIG_BCM63XX_CPU_6345
213 static struct board_info __initdata board_96345gw2 = {
215 .expected_cpu_id = 0x6345,
224 #ifdef CONFIG_BCM63XX_CPU_6348
225 static struct board_info __initdata board_96348r = {
227 .expected_cpu_id = 0x6348,
235 .use_internal_phy = 1,
258 .default_trigger = "default-on",
269 static struct board_info __initdata board_96348gw_10 = {
270 .name = "96348GW-10",
271 .expected_cpu_id = 0x6348,
280 .use_internal_phy = 1,
283 .force_speed_100 = 1,
284 .force_duplex_full = 1,
311 .default_trigger = "default-on",
321 static struct board_info __initdata board_96348gw_11 = {
322 .name = "96348GW-11",
323 .expected_cpu_id = 0x6348,
332 .use_internal_phy = 1,
336 .force_speed_100 = 1,
337 .force_duplex_full = 1,
365 .default_trigger = "default-on",
375 static struct board_info __initdata board_96348gw = {
377 .expected_cpu_id = 0x6348,
386 .use_internal_phy = 1,
389 .force_speed_100 = 1,
390 .force_duplex_full = 1,
415 .default_trigger = "default-on",
425 static struct board_info __initdata board_FAST2404 = {
427 .expected_cpu_id = 0x6348,
436 .use_internal_phy = 1,
440 .force_speed_100 = 1,
441 .force_duplex_full = 1,
449 static struct board_info __initdata board_rta1025w_16 = {
450 .name = "RTA1025W_16",
451 .expected_cpu_id = 0x6348,
459 .use_internal_phy = 1,
462 .force_speed_100 = 1,
463 .force_duplex_full = 1,
468 static struct board_info __initdata board_DV201AMR = {
470 .expected_cpu_id = 0x6348,
480 .use_internal_phy = 1,
483 .force_speed_100 = 1,
484 .force_duplex_full = 1,
488 static struct board_info __initdata board_96348gw_a = {
490 .expected_cpu_id = 0x6348,
499 .use_internal_phy = 1,
502 .force_speed_100 = 1,
503 .force_duplex_full = 1,
513 #ifdef CONFIG_BCM63XX_CPU_6358
514 static struct board_info __initdata board_96358vw = {
516 .expected_cpu_id = 0x6358,
525 .use_internal_phy = 1,
529 .force_speed_100 = 1,
530 .force_duplex_full = 1,
557 .default_trigger = "default-on",
566 static struct board_info __initdata board_96358vw2 = {
568 .expected_cpu_id = 0x6358,
577 .use_internal_phy = 1,
581 .force_speed_100 = 1,
582 .force_duplex_full = 1,
604 .default_trigger = "default-on",
614 static struct board_info __initdata board_AGPFS0 = {
616 .expected_cpu_id = 0x6358,
625 .use_internal_phy = 1,
629 .force_speed_100 = 1,
630 .force_duplex_full = 1,
637 static struct board_info __initdata board_DWVS0 = {
639 .expected_cpu_id = 0x6358,
647 .use_internal_phy = 1,
651 .force_speed_100 = 1,
652 .force_duplex_full = 1,
662 static const struct board_info __initconst *bcm963xx_boards[] = {
663 #ifdef CONFIG_BCM63XX_CPU_3368
666 #ifdef CONFIG_BCM63XX_CPU_6328
669 #ifdef CONFIG_BCM63XX_CPU_6338
673 #ifdef CONFIG_BCM63XX_CPU_6345
676 #ifdef CONFIG_BCM63XX_CPU_6348
687 #ifdef CONFIG_BCM63XX_CPU_6358
696 * Register a sane SPROMv2 to make the on-board
699 #ifdef CONFIG_SSB_PCIHOST
700 static struct ssb_sprom bcm63xx_sprom = {
704 .ant_available_bg = 0x3,
717 .boardflags_lo = 0x2848,
718 .boardflags_hi = 0x0000,
721 int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
723 if (bus->bustype == SSB_BUSTYPE_PCI) {
724 memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
727 pr_err("unable to fill SPROM for given bustype\n");
734 * return board name for /proc/cpuinfo
736 const char *board_get_name(void)
742 * early init callback, read nvram data from flash and checksum it
744 void __init board_prom_init(void)
748 char cfe_version[32];
749 char *board_name = NULL;
753 /* read base address of boot chip select (0)
754 * 6328/6362 do not have MPI but boot from a fixed address
756 if (BCMCPU_IS_6328() || BCMCPU_IS_6362()) {
759 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
760 val &= MPI_CSBASE_BASE_MASK;
762 boot_addr = (u8 *)KSEG1ADDR(val);
764 /* dump cfe version */
765 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
766 if (!memcmp(cfe, "cfe-v", 5))
767 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
768 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
770 strcpy(cfe_version, "unknown");
771 pr_info("CFE version: %s\n", cfe_version);
773 bcm63xx_nvram_init(boot_addr + BCM963XX_NVRAM_OFFSET);
775 if (BCMCPU_IS_3368()) {
776 hcs = (struct bcm_hcs *)boot_addr;
777 board_name = hcs->filename;
779 board_name = bcm63xx_nvram_get_name();
781 /* find board by name */
782 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
783 if (strncmp(board_name, bcm963xx_boards[i]->name, 16))
785 /* copy, board desc array is marked initdata */
786 memcpy(&board, bcm963xx_boards[i], sizeof(board));
790 /* bail out if board is not found, will complain later */
791 if (!board.name[0]) {
793 memcpy(name, board_name, 16);
795 pr_err("unknown bcm963xx board: %s\n", name);
799 /* setup pin multiplexing depending on board enabled device,
800 * this has to be done this early since PCI init is done
801 * inside arch_initcall */
806 bcm63xx_pci_enabled = 1;
807 if (BCMCPU_IS_6348())
808 val |= GPIO_MODE_6348_G2_PCI;
812 if (board.has_pccard) {
813 if (BCMCPU_IS_6348())
814 val |= GPIO_MODE_6348_G1_MII_PCCARD;
817 if (board.has_enet0 && !board.enet0.use_internal_phy) {
818 if (BCMCPU_IS_6348())
819 val |= GPIO_MODE_6348_G3_EXT_MII |
820 GPIO_MODE_6348_G0_EXT_MII;
823 if (board.has_enet1 && !board.enet1.use_internal_phy) {
824 if (BCMCPU_IS_6348())
825 val |= GPIO_MODE_6348_G3_EXT_MII |
826 GPIO_MODE_6348_G0_EXT_MII;
829 bcm_gpio_writel(val, GPIO_MODE_REG);
833 * second stage init callback, good time to panic if we couldn't
834 * identify on which board we're running since early printk is working
836 void __init board_setup(void)
839 panic("unable to detect bcm963xx board");
840 pr_info("board name: %s\n", board.name);
842 /* make sure we're running on expected cpu */
843 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
844 panic("unexpected CPU for bcm963xx board");
847 static struct gpio_led_platform_data bcm63xx_led_data;
849 static struct platform_device bcm63xx_gpio_leds = {
852 .dev.platform_data = &bcm63xx_led_data,
856 * third stage init callback, register all board devices.
858 int __init board_register_devices(void)
861 bcm63xx_uart_register(0);
864 bcm63xx_uart_register(1);
866 if (board.has_pccard)
867 bcm63xx_pcmcia_register();
869 if (board.has_enet0 &&
870 !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
871 bcm63xx_enet_register(0, &board.enet0);
873 if (board.has_enet1 &&
874 !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
875 bcm63xx_enet_register(1, &board.enet1);
877 if (board.has_enetsw &&
878 !bcm63xx_nvram_get_mac_address(board.enetsw.mac_addr))
879 bcm63xx_enetsw_register(&board.enetsw);
882 bcm63xx_usbd_register(&board.usbd);
884 /* Generate MAC address for WLAN and register our SPROM,
885 * do this after registering enet devices
887 #ifdef CONFIG_SSB_PCIHOST
888 if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
889 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
890 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
891 if (ssb_arch_register_fallback_sprom(
892 &bcm63xx_get_fallback_sprom) < 0)
893 pr_err("failed to register fallback SPROM\n");
897 bcm63xx_spi_register();
899 bcm63xx_hsspi_register();
901 bcm63xx_flash_register();
903 bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
904 bcm63xx_led_data.leds = board.leds;
906 platform_device_register(&bcm63xx_gpio_leds);
908 if (board.ephy_reset_gpio && board.ephy_reset_gpio_flags)
909 gpio_request_one(board.ephy_reset_gpio,
910 board.ephy_reset_gpio_flags, "ephy-reset");