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/mtd/mtd.h>
15 #include <linux/mtd/partitions.h>
16 #include <linux/mtd/physmap.h>
17 #include <linux/ssb/ssb.h>
18 #include <asm/addrspace.h>
19 #include <bcm63xx_board.h>
20 #include <bcm63xx_cpu.h>
21 #include <bcm63xx_regs.h>
22 #include <bcm63xx_io.h>
23 #include <bcm63xx_dev_pci.h>
24 #include <bcm63xx_dev_enet.h>
25 #include <bcm63xx_dev_dsp.h>
26 #include <bcm63xx_dev_pcmcia.h>
27 #include <board_bcm963xx.h>
29 #define PFX "board_bcm963xx: "
31 static struct bcm963xx_nvram nvram;
32 static unsigned int mac_addr_used;
33 static struct board_info board;
38 #ifdef CONFIG_BCM63XX_CPU_6338
39 static struct board_info __initdata board_96338gw = {
41 .expected_cpu_id = 0x6338,
46 .force_duplex_full = 1,
71 .default_trigger = "default-on",
81 static struct board_info __initdata board_96338w = {
83 .expected_cpu_id = 0x6338,
88 .force_duplex_full = 1,
111 .default_trigger = "default-on",
125 #ifdef CONFIG_BCM63XX_CPU_6345
126 static struct board_info __initdata board_96345gw2 = {
128 .expected_cpu_id = 0x6345,
135 #ifdef CONFIG_BCM63XX_CPU_6348
136 static struct board_info __initdata board_96348r = {
138 .expected_cpu_id = 0x6348,
145 .use_internal_phy = 1,
168 .default_trigger = "default-on",
179 static struct board_info __initdata board_96348gw_10 = {
180 .name = "96348GW-10",
181 .expected_cpu_id = 0x6348,
189 .use_internal_phy = 1,
192 .force_speed_100 = 1,
193 .force_duplex_full = 1,
228 .default_trigger = "default-on",
238 static struct board_info __initdata board_96348gw_11 = {
239 .name = "96348GW-11",
240 .expected_cpu_id = 0x6348,
248 .use_internal_phy = 1,
252 .force_speed_100 = 1,
253 .force_duplex_full = 1,
281 .default_trigger = "default-on",
291 static struct board_info __initdata board_96348gw = {
293 .expected_cpu_id = 0x6348,
301 .use_internal_phy = 1,
304 .force_speed_100 = 1,
305 .force_duplex_full = 1,
338 .default_trigger = "default-on",
348 static struct board_info __initdata board_FAST2404 = {
350 .expected_cpu_id = 0x6348,
358 .use_internal_phy = 1,
362 .force_speed_100 = 1,
363 .force_duplex_full = 1,
371 static struct board_info __initdata board_rta1025w_16 = {
372 .name = "RTA1025W_16",
373 .expected_cpu_id = 0x6348,
381 .use_internal_phy = 1,
384 .force_speed_100 = 1,
385 .force_duplex_full = 1,
390 static struct board_info __initdata board_DV201AMR = {
392 .expected_cpu_id = 0x6348,
401 .use_internal_phy = 1,
404 .force_speed_100 = 1,
405 .force_duplex_full = 1,
409 static struct board_info __initdata board_96348gw_a = {
411 .expected_cpu_id = 0x6348,
419 .use_internal_phy = 1,
422 .force_speed_100 = 1,
423 .force_duplex_full = 1,
433 #ifdef CONFIG_BCM63XX_CPU_6358
434 static struct board_info __initdata board_96358vw = {
436 .expected_cpu_id = 0x6358,
444 .use_internal_phy = 1,
448 .force_speed_100 = 1,
449 .force_duplex_full = 1,
476 .default_trigger = "default-on",
485 static struct board_info __initdata board_96358vw2 = {
487 .expected_cpu_id = 0x6358,
495 .use_internal_phy = 1,
499 .force_speed_100 = 1,
500 .force_duplex_full = 1,
522 .default_trigger = "default-on",
532 static struct board_info __initdata board_AGPFS0 = {
534 .expected_cpu_id = 0x6358,
542 .use_internal_phy = 1,
546 .force_speed_100 = 1,
547 .force_duplex_full = 1,
554 static struct board_info __initdata board_DWVS0 = {
556 .expected_cpu_id = 0x6358,
564 .use_internal_phy = 1,
568 .force_speed_100 = 1,
569 .force_duplex_full = 1,
579 static const struct board_info __initdata *bcm963xx_boards[] = {
580 #ifdef CONFIG_BCM63XX_CPU_6338
584 #ifdef CONFIG_BCM63XX_CPU_6345
587 #ifdef CONFIG_BCM63XX_CPU_6348
598 #ifdef CONFIG_BCM63XX_CPU_6358
607 * early init callback, read nvram data from flash and checksum it
609 void __init board_prom_init(void)
611 unsigned int check_len, i;
612 u8 *boot_addr, *cfe, *p;
613 char cfe_version[32];
616 /* read base address of boot chip select (0)
617 * 6345 does not have MPI but boots from standard
618 * MIPS Flash address */
619 if (BCMCPU_IS_6345())
622 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
623 val &= MPI_CSBASE_BASE_MASK;
625 boot_addr = (u8 *)KSEG1ADDR(val);
627 /* dump cfe version */
628 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
629 if (!memcmp(cfe, "cfe-v", 5))
630 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
631 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
633 strcpy(cfe_version, "unknown");
634 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
636 /* extract nvram data */
637 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
639 /* check checksum before using data */
640 if (nvram.version <= 4)
641 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
643 check_len = sizeof(nvram);
649 printk(KERN_ERR PFX "invalid nvram checksum\n");
653 /* find board by name */
654 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
655 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
658 /* copy, board desc array is marked initdata */
659 memcpy(&board, bcm963xx_boards[i], sizeof(board));
663 /* bail out if board is not found, will complain later */
664 if (!board.name[0]) {
666 memcpy(name, nvram.name, 16);
668 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
673 /* setup pin multiplexing depending on board enabled device,
674 * this has to be done this early since PCI init is done
675 * inside arch_initcall */
680 bcm63xx_pci_enabled = 1;
681 if (BCMCPU_IS_6348())
682 val |= GPIO_MODE_6348_G2_PCI;
686 if (board.has_pccard) {
687 if (BCMCPU_IS_6348())
688 val |= GPIO_MODE_6348_G1_MII_PCCARD;
691 if (board.has_enet0 && !board.enet0.use_internal_phy) {
692 if (BCMCPU_IS_6348())
693 val |= GPIO_MODE_6348_G3_EXT_MII |
694 GPIO_MODE_6348_G0_EXT_MII;
697 if (board.has_enet1 && !board.enet1.use_internal_phy) {
698 if (BCMCPU_IS_6348())
699 val |= GPIO_MODE_6348_G3_EXT_MII |
700 GPIO_MODE_6348_G0_EXT_MII;
703 bcm_gpio_writel(val, GPIO_MODE_REG);
707 * second stage init callback, good time to panic if we couldn't
708 * identify on which board we're running since early printk is working
710 void __init board_setup(void)
713 panic("unable to detect bcm963xx board");
714 printk(KERN_INFO PFX "board name: %s\n", board.name);
716 /* make sure we're running on expected cpu */
717 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
718 panic("unexpected CPU for bcm963xx board");
722 * return board name for /proc/cpuinfo
724 const char *board_get_name(void)
730 * register & return a new board mac address
732 static int board_get_mac_address(u8 *mac)
737 if (mac_addr_used >= nvram.mac_addr_count) {
738 printk(KERN_ERR PFX "not enough mac address\n");
742 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
743 p = mac + ETH_ALEN - 1;
744 count = mac_addr_used;
756 printk(KERN_ERR PFX "unable to fetch mac address\n");
764 static struct mtd_partition mtd_partitions[] = {
772 static struct physmap_flash_data flash_data = {
774 .nr_parts = ARRAY_SIZE(mtd_partitions),
775 .parts = mtd_partitions,
778 static struct resource mtd_resources[] = {
780 .start = 0, /* filled at runtime */
781 .end = 0, /* filled at runtime */
782 .flags = IORESOURCE_MEM,
786 static struct platform_device mtd_dev = {
787 .name = "physmap-flash",
788 .resource = mtd_resources,
789 .num_resources = ARRAY_SIZE(mtd_resources),
791 .platform_data = &flash_data,
796 * Register a sane SPROMv2 to make the on-board
799 #ifdef CONFIG_SSB_PCIHOST
800 static struct ssb_sprom bcm63xx_sprom = {
804 .ant_available_bg = 0x3,
817 .boardflags_lo = 0x2848,
818 .boardflags_hi = 0x0000,
822 static struct gpio_led_platform_data bcm63xx_led_data;
824 static struct platform_device bcm63xx_gpio_leds = {
827 .dev.platform_data = &bcm63xx_led_data,
831 * third stage init callback, register all board devices.
833 int __init board_register_devices(void)
837 if (board.has_pccard)
838 bcm63xx_pcmcia_register();
840 if (board.has_enet0 &&
841 !board_get_mac_address(board.enet0.mac_addr))
842 bcm63xx_enet_register(0, &board.enet0);
844 if (board.has_enet1 &&
845 !board_get_mac_address(board.enet1.mac_addr))
846 bcm63xx_enet_register(1, &board.enet1);
849 bcm63xx_dsp_register(&board.dsp);
851 /* Generate MAC address for WLAN and
852 * register our SPROM */
853 #ifdef CONFIG_SSB_PCIHOST
854 if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
855 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
856 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
857 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom) < 0)
858 printk(KERN_ERR "failed to register fallback SPROM\n");
862 /* read base address of boot chip select (0) */
863 if (BCMCPU_IS_6345())
866 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
867 val &= MPI_CSBASE_BASE_MASK;
869 mtd_resources[0].start = val;
870 mtd_resources[0].end = 0x1FFFFFFF;
872 platform_device_register(&mtd_dev);
874 bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
875 bcm63xx_led_data.leds = board.leds;
877 platform_device_register(&bcm63xx_gpio_leds);