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) 2009 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_board.h>
24 #include <bcm63xx_dev_pci.h>
25 #include <bcm63xx_dev_uart.h>
26 #include <bcm63xx_dev_wdt.h>
27 #include <bcm63xx_dev_enet.h>
28 #include <bcm63xx_dev_dsp.h>
29 #include <bcm63xx_dev_pcmcia.h>
30 #include <bcm63xx_dev_usb_ohci.h>
31 #include <bcm63xx_dev_usb_ehci.h>
32 #include <bcm63xx_dev_usb_udc.h>
33 #include <bcm63xx_dev_spi.h>
34 #include <board_bcm963xx.h>
36 #define PFX "board_bcm963xx: "
38 static struct bcm963xx_nvram nvram
;
39 static unsigned int mac_addr_used
= 0;
40 static struct board_info board
;
46 #ifdef CONFIG_BCM63XX_CPU_6338
47 static struct board_info __initdata board_96338gw
= {
49 .expected_cpu_id
= 0x6338,
54 .force_duplex_full
= 1,
79 .default_trigger
= "default-on",
89 static struct board_info __initdata board_96338w
= {
91 .expected_cpu_id
= 0x6338,
96 .force_duplex_full
= 1,
119 .default_trigger
= "default-on",
133 #ifdef CONFIG_BCM63XX_CPU_6345
134 static struct board_info __initdata board_96345gw2
= {
136 .expected_cpu_id
= 0x6345,
143 #ifdef CONFIG_BCM63XX_CPU_6348
144 static struct board_info __initdata board_96348r
= {
146 .expected_cpu_id
= 0x6348,
153 .use_internal_phy
= 1,
176 .default_trigger
= "default-on",
187 static struct board_info __initdata board_96348gw_10
= {
188 .name
= "96348GW-10",
189 .expected_cpu_id
= 0x6348,
197 .use_internal_phy
= 1,
200 .force_speed_100
= 1,
201 .force_duplex_full
= 1,
236 .default_trigger
= "default-on",
246 static struct board_info __initdata board_96348gw_11
= {
247 .name
= "96348GW-11",
248 .expected_cpu_id
= 0x6348,
256 .use_internal_phy
= 1,
260 .force_speed_100
= 1,
261 .force_duplex_full
= 1,
289 .default_trigger
= "default-on",
299 static struct board_info __initdata board_96348gw
= {
301 .expected_cpu_id
= 0x6348,
309 .use_internal_phy
= 1,
312 .force_speed_100
= 1,
313 .force_duplex_full
= 1,
346 .default_trigger
= "default-on",
356 static struct board_info __initdata board_FAST2404
= {
358 .expected_cpu_id
= 0x6348,
366 .use_internal_phy
= 1,
370 .force_speed_100
= 1,
371 .force_duplex_full
= 1,
380 static struct board_info __initdata board_DV201AMR
= {
382 .expected_cpu_id
= 0x6348,
392 .use_internal_phy
= 1,
395 .force_speed_100
= 1,
396 .force_duplex_full
= 1,
400 static struct board_info __initdata board_96348gw_a
= {
402 .expected_cpu_id
= 0x6348,
410 .use_internal_phy
= 1,
413 .force_speed_100
= 1,
414 .force_duplex_full
= 1,
426 #ifdef CONFIG_BCM63XX_CPU_6358
427 static struct board_info __initdata board_96358vw
= {
429 .expected_cpu_id
= 0x6358,
437 .use_internal_phy
= 1,
441 .force_speed_100
= 1,
442 .force_duplex_full
= 1,
469 .default_trigger
= "default-on",
478 static struct board_info __initdata board_96358vw2
= {
480 .expected_cpu_id
= 0x6358,
488 .use_internal_phy
= 1,
492 .force_speed_100
= 1,
493 .force_duplex_full
= 1,
515 .default_trigger
= "default-on",
525 static struct board_info __initdata board_AGPFS0
= {
527 .expected_cpu_id
= 0x6358,
535 .use_internal_phy
= 1,
539 .force_speed_100
= 1,
540 .force_duplex_full
= 1,
547 static struct board_info __initdata board_DWVS0
= {
549 .expected_cpu_id
= 0x6358,
557 .use_internal_phy
= 1,
561 .force_speed_100
= 1,
562 .force_duplex_full
= 1,
572 static const struct board_info __initdata
*bcm963xx_boards
[] = {
573 #ifdef CONFIG_BCM63XX_CPU_6338
577 #ifdef CONFIG_BCM63XX_CPU_6345
580 #ifdef CONFIG_BCM63XX_CPU_6348
590 #ifdef CONFIG_BCM63XX_CPU_6358
599 * early init callback, read nvram data from flash and checksum it
601 void __init
board_prom_init(void)
603 unsigned int check_len
, i
;
604 u8
*boot_addr
, *cfe
, *p
;
605 char cfe_version
[32];
608 /* read base address of boot chip select (0)
609 * 6345 does not have MPI but boots from standard
610 * MIPS Flash address */
611 if (BCMCPU_IS_6345())
614 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
615 val
&= MPI_CSBASE_BASE_MASK
;
617 boot_addr
= (u8
*)KSEG1ADDR(val
);
619 /* dump cfe version */
620 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
621 if (!memcmp(cfe
, "cfe-v", 5))
622 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
623 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
625 strcpy(cfe_version
, "unknown");
626 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
628 /* extract nvram data */
629 memcpy(&nvram
, boot_addr
+ BCM963XX_NVRAM_OFFSET
, sizeof(nvram
));
631 /* check checksum before using data */
632 if (nvram
.version
<= 4)
633 check_len
= offsetof(struct bcm963xx_nvram
, checksum_old
);
635 check_len
= sizeof(nvram
);
641 printk(KERN_ERR PFX
"invalid nvram checksum\n");
645 /* find board by name */
646 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
647 if (strncmp(nvram
.name
, bcm963xx_boards
[i
]->name
,
650 /* copy, board desc array is marked initdata */
651 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
655 /* bail out if board is not found, will complain later */
656 if (!board
.name
[0]) {
658 memcpy(name
, nvram
.name
, 16);
660 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
665 /* setup pin multiplexing depending on board enabled device,
666 * this has to be done this early since PCI init is done
667 * inside arch_initcall */
671 bcm63xx_pci_enabled
= 1;
672 if (BCMCPU_IS_6348())
673 val
|= GPIO_MODE_6348_G2_PCI
;
676 if (board
.has_pccard
) {
677 if (BCMCPU_IS_6348())
678 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
681 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
682 if (BCMCPU_IS_6348())
683 val
|= GPIO_MODE_6348_G3_EXT_MII
|
684 GPIO_MODE_6348_G0_EXT_MII
;
687 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
688 if (BCMCPU_IS_6348())
689 val
|= GPIO_MODE_6348_G3_EXT_MII
|
690 GPIO_MODE_6348_G0_EXT_MII
;
693 bcm_gpio_writel(val
, GPIO_MODE_REG
);
697 * second stage init callback, good time to panic if we couldn't
698 * identify on which board we're running since early printk is working
700 void __init
board_setup(void)
703 panic("unable to detect bcm963xx board");
704 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
706 /* make sure we're running on expected cpu */
707 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
708 panic("unexpected CPU for bcm963xx board");
712 * return board name for /proc/cpuinfo
714 const char *board_get_name(void)
720 * register & return a new board mac address
722 static int board_get_mac_address(u8
*mac
)
727 if (mac_addr_used
>= nvram
.mac_addr_count
) {
728 printk(KERN_ERR PFX
"not enough mac address\n");
732 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
733 p
= mac
+ ETH_ALEN
- 1;
734 count
= mac_addr_used
;
746 printk(KERN_ERR PFX
"unable to fetch mac address\n");
754 static struct resource mtd_resources
[] = {
756 .start
= 0, /* filled at runtime */
757 .end
= 0, /* filled at runtime */
758 .flags
= IORESOURCE_MEM
,
762 static struct platform_device mtd_dev
= {
763 .name
= "bcm963xx-flash",
764 .resource
= mtd_resources
,
765 .num_resources
= ARRAY_SIZE(mtd_resources
),
769 * Register a sane SPROMv2 to make the on-board
772 static struct ssb_sprom bcm63xx_sprom
= {
776 .ant_available_bg
= 0x3,
789 .boardflags_lo
= 0x2848,
790 .boardflags_hi
= 0x0000,
793 static struct resource gpiodev_resource
= {
797 static struct gpio_led_platform_data bcm63xx_led_data
;
799 static struct platform_device bcm63xx_gpio_leds
= {
802 .dev
.platform_data
= &bcm63xx_led_data
,
806 * third stage init callback, register all board devices.
808 int __init
board_register_devices(void)
812 bcm63xx_uart_register();
813 bcm63xx_wdt_register();
815 if (!BCMCPU_IS_6345())
816 bcm63xx_spi_register();
818 if (board
.has_pccard
)
819 bcm63xx_pcmcia_register();
821 if (board
.has_enet0
&&
822 !board_get_mac_address(board
.enet0
.mac_addr
))
823 bcm63xx_enet_register(0, &board
.enet0
);
825 if (board
.has_enet1
&&
826 !board_get_mac_address(board
.enet1
.mac_addr
))
827 bcm63xx_enet_register(1, &board
.enet1
);
830 bcm63xx_ohci_register();
833 bcm63xx_ehci_register();
836 bcm63xx_udc_register();
839 bcm63xx_dsp_register(&board
.dsp
);
841 /* Generate MAC address for WLAN and
842 * register our SPROM */
844 if (!board_get_mac_address(bcm63xx_sprom
.il0mac
)) {
845 memcpy(bcm63xx_sprom
.et0mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
846 memcpy(bcm63xx_sprom
.et1mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
847 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom
) < 0)
848 printk(KERN_ERR
"failed to register fallback SPROM\n");
852 /* read base address of boot chip select (0) */
853 if (BCMCPU_IS_6345())
856 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
857 val
&= MPI_CSBASE_BASE_MASK
;
859 mtd_resources
[0].start
= val
;
860 mtd_resources
[0].end
= 0x1FFFFFFF;
862 platform_device_register(&mtd_dev
);
864 /* Register GPIODEV */
865 platform_device_register_simple("GPIODEV", 0, &gpiodev_resource
, 1);
867 bcm63xx_led_data
.num_leds
= ARRAY_SIZE(board
.leds
);
868 bcm63xx_led_data
.leds
= board
.leds
;
870 platform_device_register(&bcm63xx_gpio_leds
);