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 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/string.h>
13 #include <linux/platform_device.h>
14 #include <linux/ssb/ssb.h>
15 #include <asm/addrspace.h>
16 #include <bcm63xx_board.h>
17 #include <bcm63xx_cpu.h>
18 #include <bcm63xx_dev_uart.h>
19 #include <bcm63xx_regs.h>
20 #include <bcm63xx_io.h>
21 #include <bcm63xx_nvram.h>
22 #include <bcm63xx_dev_pci.h>
23 #include <bcm63xx_dev_enet.h>
24 #include <bcm63xx_dev_dsp.h>
25 #include <bcm63xx_dev_flash.h>
26 #include <bcm63xx_dev_pcmcia.h>
27 #include <bcm63xx_dev_spi.h>
28 #include <bcm63xx_dev_usb_usbd.h>
29 #include <board_bcm963xx.h>
31 #define PFX "board_bcm963xx: "
33 static struct board_info board;
38 #ifdef CONFIG_BCM63XX_CPU_6328
39 static struct board_info __initdata board_96328avng = {
41 .expected_cpu_id = 0x6328,
54 .name = "96328avng::ppp-fail",
59 .name = "96328avng::power",
62 .default_trigger = "default-on",
65 .name = "96328avng::power-fail",
70 .name = "96328avng::wps",
75 .name = "96328avng::ppp",
86 #ifdef CONFIG_BCM63XX_CPU_6338
87 static struct board_info __initdata board_96338gw = {
89 .expected_cpu_id = 0x6338,
95 .force_duplex_full = 1,
120 .default_trigger = "default-on",
130 static struct board_info __initdata board_96338w = {
132 .expected_cpu_id = 0x6338,
137 .force_speed_100 = 1,
138 .force_duplex_full = 1,
161 .default_trigger = "default-on",
175 #ifdef CONFIG_BCM63XX_CPU_6345
176 static struct board_info __initdata board_96345gw2 = {
178 .expected_cpu_id = 0x6345,
187 #ifdef CONFIG_BCM63XX_CPU_6348
188 static struct board_info __initdata board_96348r = {
190 .expected_cpu_id = 0x6348,
198 .use_internal_phy = 1,
221 .default_trigger = "default-on",
232 static struct board_info __initdata board_96348gw_10 = {
233 .name = "96348GW-10",
234 .expected_cpu_id = 0x6348,
243 .use_internal_phy = 1,
246 .force_speed_100 = 1,
247 .force_duplex_full = 1,
282 .default_trigger = "default-on",
292 static struct board_info __initdata board_96348gw_11 = {
293 .name = "96348GW-11",
294 .expected_cpu_id = 0x6348,
303 .use_internal_phy = 1,
307 .force_speed_100 = 1,
308 .force_duplex_full = 1,
336 .default_trigger = "default-on",
346 static struct board_info __initdata board_96348gw = {
348 .expected_cpu_id = 0x6348,
357 .use_internal_phy = 1,
360 .force_speed_100 = 1,
361 .force_duplex_full = 1,
394 .default_trigger = "default-on",
404 static struct board_info __initdata board_FAST2404 = {
406 .expected_cpu_id = 0x6348,
415 .use_internal_phy = 1,
419 .force_speed_100 = 1,
420 .force_duplex_full = 1,
428 static struct board_info __initdata board_rta1025w_16 = {
429 .name = "RTA1025W_16",
430 .expected_cpu_id = 0x6348,
438 .use_internal_phy = 1,
441 .force_speed_100 = 1,
442 .force_duplex_full = 1,
447 static struct board_info __initdata board_DV201AMR = {
449 .expected_cpu_id = 0x6348,
459 .use_internal_phy = 1,
462 .force_speed_100 = 1,
463 .force_duplex_full = 1,
467 static struct board_info __initdata board_96348gw_a = {
469 .expected_cpu_id = 0x6348,
478 .use_internal_phy = 1,
481 .force_speed_100 = 1,
482 .force_duplex_full = 1,
492 #ifdef CONFIG_BCM63XX_CPU_6358
493 static struct board_info __initdata board_96358vw = {
495 .expected_cpu_id = 0x6358,
504 .use_internal_phy = 1,
508 .force_speed_100 = 1,
509 .force_duplex_full = 1,
536 .default_trigger = "default-on",
545 static struct board_info __initdata board_96358vw2 = {
547 .expected_cpu_id = 0x6358,
556 .use_internal_phy = 1,
560 .force_speed_100 = 1,
561 .force_duplex_full = 1,
583 .default_trigger = "default-on",
593 static struct board_info __initdata board_AGPFS0 = {
595 .expected_cpu_id = 0x6358,
604 .use_internal_phy = 1,
608 .force_speed_100 = 1,
609 .force_duplex_full = 1,
616 static struct board_info __initdata board_DWVS0 = {
618 .expected_cpu_id = 0x6358,
626 .use_internal_phy = 1,
630 .force_speed_100 = 1,
631 .force_duplex_full = 1,
641 static const struct board_info __initconst *bcm963xx_boards[] = {
642 #ifdef CONFIG_BCM63XX_CPU_6328
645 #ifdef CONFIG_BCM63XX_CPU_6338
649 #ifdef CONFIG_BCM63XX_CPU_6345
652 #ifdef CONFIG_BCM63XX_CPU_6348
663 #ifdef CONFIG_BCM63XX_CPU_6358
672 * Register a sane SPROMv2 to make the on-board
675 #ifdef CONFIG_SSB_PCIHOST
676 static struct ssb_sprom bcm63xx_sprom = {
680 .ant_available_bg = 0x3,
693 .boardflags_lo = 0x2848,
694 .boardflags_hi = 0x0000,
697 int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
699 if (bus->bustype == SSB_BUSTYPE_PCI) {
700 memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
703 printk(KERN_ERR PFX "unable to fill SPROM for given bustype.\n");
710 * return board name for /proc/cpuinfo
712 const char *board_get_name(void)
718 * early init callback, read nvram data from flash and checksum it
720 void __init board_prom_init(void)
724 char cfe_version[32];
728 /* read base address of boot chip select (0)
729 * 6328/6362 do not have MPI but boot from a fixed address
731 if (BCMCPU_IS_6328() || BCMCPU_IS_6362()) {
734 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
735 val &= MPI_CSBASE_BASE_MASK;
737 boot_addr = (u8 *)KSEG1ADDR(val);
739 /* dump cfe version */
740 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
741 if (!memcmp(cfe, "cfe-v", 5))
742 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
743 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
745 strcpy(cfe_version, "unknown");
746 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
748 bcm63xx_nvram_init(boot_addr + BCM963XX_NVRAM_OFFSET);
750 board_name = bcm63xx_nvram_get_name();
751 /* find board by name */
752 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
753 if (strncmp(board_name, bcm963xx_boards[i]->name, 16))
755 /* copy, board desc array is marked initdata */
756 memcpy(&board, bcm963xx_boards[i], sizeof(board));
760 /* bail out if board is not found, will complain later */
761 if (!board.name[0]) {
763 memcpy(name, board_name, 16);
765 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
770 /* setup pin multiplexing depending on board enabled device,
771 * this has to be done this early since PCI init is done
772 * inside arch_initcall */
777 bcm63xx_pci_enabled = 1;
778 if (BCMCPU_IS_6348())
779 val |= GPIO_MODE_6348_G2_PCI;
783 if (board.has_pccard) {
784 if (BCMCPU_IS_6348())
785 val |= GPIO_MODE_6348_G1_MII_PCCARD;
788 if (board.has_enet0 && !board.enet0.use_internal_phy) {
789 if (BCMCPU_IS_6348())
790 val |= GPIO_MODE_6348_G3_EXT_MII |
791 GPIO_MODE_6348_G0_EXT_MII;
794 if (board.has_enet1 && !board.enet1.use_internal_phy) {
795 if (BCMCPU_IS_6348())
796 val |= GPIO_MODE_6348_G3_EXT_MII |
797 GPIO_MODE_6348_G0_EXT_MII;
800 bcm_gpio_writel(val, GPIO_MODE_REG);
804 * second stage init callback, good time to panic if we couldn't
805 * identify on which board we're running since early printk is working
807 void __init board_setup(void)
810 panic("unable to detect bcm963xx board");
811 printk(KERN_INFO PFX "board name: %s\n", board.name);
813 /* make sure we're running on expected cpu */
814 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
815 panic("unexpected CPU for bcm963xx board");
818 static struct gpio_led_platform_data bcm63xx_led_data;
820 static struct platform_device bcm63xx_gpio_leds = {
823 .dev.platform_data = &bcm63xx_led_data,
827 * third stage init callback, register all board devices.
829 int __init board_register_devices(void)
832 bcm63xx_uart_register(0);
835 bcm63xx_uart_register(1);
837 if (board.has_pccard)
838 bcm63xx_pcmcia_register();
840 if (board.has_enet0 &&
841 !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
842 bcm63xx_enet_register(0, &board.enet0);
844 if (board.has_enet1 &&
845 !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
846 bcm63xx_enet_register(1, &board.enet1);
848 if (board.has_enetsw &&
849 !bcm63xx_nvram_get_mac_address(board.enetsw.mac_addr))
850 bcm63xx_enetsw_register(&board.enetsw);
853 bcm63xx_usbd_register(&board.usbd);
856 bcm63xx_dsp_register(&board.dsp);
858 /* Generate MAC address for WLAN and register our SPROM,
859 * do this after registering enet devices
861 #ifdef CONFIG_SSB_PCIHOST
862 if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
863 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
864 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
865 if (ssb_arch_register_fallback_sprom(
866 &bcm63xx_get_fallback_sprom) < 0)
867 pr_err(PFX "failed to register fallback SPROM\n");
871 bcm63xx_spi_register();
873 bcm63xx_flash_register();
875 bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
876 bcm63xx_led_data.leds = board.leds;
878 platform_device_register(&bcm63xx_gpio_leds);