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_DV201AMR = {
373 .expected_cpu_id = 0x6348,
382 .use_internal_phy = 1,
385 .force_speed_100 = 1,
386 .force_duplex_full = 1,
390 static struct board_info __initdata board_96348gw_a = {
392 .expected_cpu_id = 0x6348,
400 .use_internal_phy = 1,
403 .force_speed_100 = 1,
404 .force_duplex_full = 1,
414 #ifdef CONFIG_BCM63XX_CPU_6358
415 static struct board_info __initdata board_96358vw = {
417 .expected_cpu_id = 0x6358,
425 .use_internal_phy = 1,
429 .force_speed_100 = 1,
430 .force_duplex_full = 1,
457 .default_trigger = "default-on",
466 static struct board_info __initdata board_96358vw2 = {
468 .expected_cpu_id = 0x6358,
476 .use_internal_phy = 1,
480 .force_speed_100 = 1,
481 .force_duplex_full = 1,
503 .default_trigger = "default-on",
513 static struct board_info __initdata board_AGPFS0 = {
515 .expected_cpu_id = 0x6358,
523 .use_internal_phy = 1,
527 .force_speed_100 = 1,
528 .force_duplex_full = 1,
539 static const struct board_info __initdata *bcm963xx_boards[] = {
540 #ifdef CONFIG_BCM63XX_CPU_6338
544 #ifdef CONFIG_BCM63XX_CPU_6345
547 #ifdef CONFIG_BCM63XX_CPU_6348
557 #ifdef CONFIG_BCM63XX_CPU_6358
565 * early init callback, read nvram data from flash and checksum it
567 void __init board_prom_init(void)
569 unsigned int check_len, i;
570 u8 *boot_addr, *cfe, *p;
571 char cfe_version[32];
574 /* read base address of boot chip select (0)
575 * 6345 does not have MPI but boots from standard
576 * MIPS Flash address */
577 if (BCMCPU_IS_6345())
580 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
581 val &= MPI_CSBASE_BASE_MASK;
583 boot_addr = (u8 *)KSEG1ADDR(val);
585 /* dump cfe version */
586 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
587 if (!memcmp(cfe, "cfe-v", 5))
588 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
589 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
591 strcpy(cfe_version, "unknown");
592 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
594 /* extract nvram data */
595 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
597 /* check checksum before using data */
598 if (nvram.version <= 4)
599 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
601 check_len = sizeof(nvram);
607 printk(KERN_ERR PFX "invalid nvram checksum\n");
611 /* find board by name */
612 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
613 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
616 /* copy, board desc array is marked initdata */
617 memcpy(&board, bcm963xx_boards[i], sizeof(board));
621 /* bail out if board is not found, will complain later */
622 if (!board.name[0]) {
624 memcpy(name, nvram.name, 16);
626 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
631 /* setup pin multiplexing depending on board enabled device,
632 * this has to be done this early since PCI init is done
633 * inside arch_initcall */
638 bcm63xx_pci_enabled = 1;
639 if (BCMCPU_IS_6348())
640 val |= GPIO_MODE_6348_G2_PCI;
644 if (board.has_pccard) {
645 if (BCMCPU_IS_6348())
646 val |= GPIO_MODE_6348_G1_MII_PCCARD;
649 if (board.has_enet0 && !board.enet0.use_internal_phy) {
650 if (BCMCPU_IS_6348())
651 val |= GPIO_MODE_6348_G3_EXT_MII |
652 GPIO_MODE_6348_G0_EXT_MII;
655 if (board.has_enet1 && !board.enet1.use_internal_phy) {
656 if (BCMCPU_IS_6348())
657 val |= GPIO_MODE_6348_G3_EXT_MII |
658 GPIO_MODE_6348_G0_EXT_MII;
661 bcm_gpio_writel(val, GPIO_MODE_REG);
665 * second stage init callback, good time to panic if we couldn't
666 * identify on which board we're running since early printk is working
668 void __init board_setup(void)
671 panic("unable to detect bcm963xx board");
672 printk(KERN_INFO PFX "board name: %s\n", board.name);
674 /* make sure we're running on expected cpu */
675 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
676 panic("unexpected CPU for bcm963xx board");
680 * return board name for /proc/cpuinfo
682 const char *board_get_name(void)
688 * register & return a new board mac address
690 static int board_get_mac_address(u8 *mac)
695 if (mac_addr_used >= nvram.mac_addr_count) {
696 printk(KERN_ERR PFX "not enough mac address\n");
700 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
701 p = mac + ETH_ALEN - 1;
702 count = mac_addr_used;
714 printk(KERN_ERR PFX "unable to fetch mac address\n");
722 static struct mtd_partition mtd_partitions[] = {
730 static struct physmap_flash_data flash_data = {
732 .nr_parts = ARRAY_SIZE(mtd_partitions),
733 .parts = mtd_partitions,
736 static struct resource mtd_resources[] = {
738 .start = 0, /* filled at runtime */
739 .end = 0, /* filled at runtime */
740 .flags = IORESOURCE_MEM,
744 static struct platform_device mtd_dev = {
745 .name = "physmap-flash",
746 .resource = mtd_resources,
747 .num_resources = ARRAY_SIZE(mtd_resources),
749 .platform_data = &flash_data,
754 * Register a sane SPROMv2 to make the on-board
757 #ifdef CONFIG_SSB_PCIHOST
758 static struct ssb_sprom bcm63xx_sprom = {
762 .ant_available_bg = 0x3,
775 .boardflags_lo = 0x2848,
776 .boardflags_hi = 0x0000,
780 static struct gpio_led_platform_data bcm63xx_led_data;
782 static struct platform_device bcm63xx_gpio_leds = {
785 .dev.platform_data = &bcm63xx_led_data,
789 * third stage init callback, register all board devices.
791 int __init board_register_devices(void)
795 if (board.has_pccard)
796 bcm63xx_pcmcia_register();
798 if (board.has_enet0 &&
799 !board_get_mac_address(board.enet0.mac_addr))
800 bcm63xx_enet_register(0, &board.enet0);
802 if (board.has_enet1 &&
803 !board_get_mac_address(board.enet1.mac_addr))
804 bcm63xx_enet_register(1, &board.enet1);
807 bcm63xx_dsp_register(&board.dsp);
809 /* Generate MAC address for WLAN and
810 * register our SPROM */
811 #ifdef CONFIG_SSB_PCIHOST
812 if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
813 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
814 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
815 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom) < 0)
816 printk(KERN_ERR "failed to register fallback SPROM\n");
820 /* read base address of boot chip select (0) */
821 if (BCMCPU_IS_6345())
824 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
825 val &= MPI_CSBASE_BASE_MASK;
827 mtd_resources[0].start = val;
828 mtd_resources[0].end = 0x1FFFFFFF;
830 platform_device_register(&mtd_dev);
832 bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
833 bcm63xx_led_data.leds = board.leds;
835 platform_device_register(&bcm63xx_gpio_leds);