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 <bcm63xx_dev_uart.h>
28 #include <board_bcm963xx.h>
30 #define PFX "board_bcm963xx: "
32 static struct bcm963xx_nvram nvram
;
33 static unsigned int mac_addr_used
;
34 static struct board_info board
;
39 #ifdef CONFIG_BCM63XX_CPU_6338
40 static struct board_info __initdata board_96338gw
= {
42 .expected_cpu_id
= 0x6338,
47 .force_duplex_full
= 1,
72 .default_trigger
= "default-on",
82 static struct board_info __initdata board_96338w
= {
84 .expected_cpu_id
= 0x6338,
89 .force_duplex_full
= 1,
112 .default_trigger
= "default-on",
126 #ifdef CONFIG_BCM63XX_CPU_6345
127 static struct board_info __initdata board_96345gw2
= {
129 .expected_cpu_id
= 0x6345,
136 #ifdef CONFIG_BCM63XX_CPU_6348
137 static struct board_info __initdata board_96348r
= {
139 .expected_cpu_id
= 0x6348,
146 .use_internal_phy
= 1,
169 .default_trigger
= "default-on",
180 static struct board_info __initdata board_96348gw_10
= {
181 .name
= "96348GW-10",
182 .expected_cpu_id
= 0x6348,
190 .use_internal_phy
= 1,
193 .force_speed_100
= 1,
194 .force_duplex_full
= 1,
229 .default_trigger
= "default-on",
239 static struct board_info __initdata board_96348gw_11
= {
240 .name
= "96348GW-11",
241 .expected_cpu_id
= 0x6348,
249 .use_internal_phy
= 1,
253 .force_speed_100
= 1,
254 .force_duplex_full
= 1,
282 .default_trigger
= "default-on",
292 static struct board_info __initdata board_96348gw
= {
294 .expected_cpu_id
= 0x6348,
302 .use_internal_phy
= 1,
305 .force_speed_100
= 1,
306 .force_duplex_full
= 1,
339 .default_trigger
= "default-on",
349 static struct board_info __initdata board_FAST2404
= {
351 .expected_cpu_id
= 0x6348,
359 .use_internal_phy
= 1,
363 .force_speed_100
= 1,
364 .force_duplex_full
= 1,
373 static struct board_info __initdata board_DV201AMR
= {
375 .expected_cpu_id
= 0x6348,
384 .use_internal_phy
= 1,
387 .force_speed_100
= 1,
388 .force_duplex_full
= 1,
392 static struct board_info __initdata board_96348gw_a
= {
394 .expected_cpu_id
= 0x6348,
402 .use_internal_phy
= 1,
405 .force_speed_100
= 1,
406 .force_duplex_full
= 1,
416 #ifdef CONFIG_BCM63XX_CPU_6358
417 static struct board_info __initdata board_96358vw
= {
419 .expected_cpu_id
= 0x6358,
427 .use_internal_phy
= 1,
431 .force_speed_100
= 1,
432 .force_duplex_full
= 1,
459 .default_trigger
= "default-on",
468 static struct board_info __initdata board_96358vw2
= {
470 .expected_cpu_id
= 0x6358,
478 .use_internal_phy
= 1,
482 .force_speed_100
= 1,
483 .force_duplex_full
= 1,
505 .default_trigger
= "default-on",
515 static struct board_info __initdata board_AGPFS0
= {
517 .expected_cpu_id
= 0x6358,
525 .use_internal_phy
= 1,
529 .force_speed_100
= 1,
530 .force_duplex_full
= 1,
541 static const struct board_info __initdata
*bcm963xx_boards
[] = {
542 #ifdef CONFIG_BCM63XX_CPU_6338
546 #ifdef CONFIG_BCM63XX_CPU_6345
549 #ifdef CONFIG_BCM63XX_CPU_6348
559 #ifdef CONFIG_BCM63XX_CPU_6358
567 * early init callback, read nvram data from flash and checksum it
569 void __init
board_prom_init(void)
571 unsigned int check_len
, i
;
572 u8
*boot_addr
, *cfe
, *p
;
573 char cfe_version
[32];
576 /* read base address of boot chip select (0)
577 * 6345 does not have MPI but boots from standard
578 * MIPS Flash address */
579 if (BCMCPU_IS_6345())
582 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
583 val
&= MPI_CSBASE_BASE_MASK
;
585 boot_addr
= (u8
*)KSEG1ADDR(val
);
587 /* dump cfe version */
588 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
589 if (!memcmp(cfe
, "cfe-v", 5))
590 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
591 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
593 strcpy(cfe_version
, "unknown");
594 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
596 /* extract nvram data */
597 memcpy(&nvram
, boot_addr
+ BCM963XX_NVRAM_OFFSET
, sizeof(nvram
));
599 /* check checksum before using data */
600 if (nvram
.version
<= 4)
601 check_len
= offsetof(struct bcm963xx_nvram
, checksum_old
);
603 check_len
= sizeof(nvram
);
609 printk(KERN_ERR PFX
"invalid nvram checksum\n");
613 /* find board by name */
614 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
615 if (strncmp(nvram
.name
, bcm963xx_boards
[i
]->name
,
618 /* copy, board desc array is marked initdata */
619 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
623 /* bail out if board is not found, will complain later */
624 if (!board
.name
[0]) {
626 memcpy(name
, nvram
.name
, 16);
628 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
633 /* setup pin multiplexing depending on board enabled device,
634 * this has to be done this early since PCI init is done
635 * inside arch_initcall */
640 bcm63xx_pci_enabled
= 1;
641 if (BCMCPU_IS_6348())
642 val
|= GPIO_MODE_6348_G2_PCI
;
646 if (board
.has_pccard
) {
647 if (BCMCPU_IS_6348())
648 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
651 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
652 if (BCMCPU_IS_6348())
653 val
|= GPIO_MODE_6348_G3_EXT_MII
|
654 GPIO_MODE_6348_G0_EXT_MII
;
657 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
658 if (BCMCPU_IS_6348())
659 val
|= GPIO_MODE_6348_G3_EXT_MII
|
660 GPIO_MODE_6348_G0_EXT_MII
;
663 bcm_gpio_writel(val
, GPIO_MODE_REG
);
667 * second stage init callback, good time to panic if we couldn't
668 * identify on which board we're running since early printk is working
670 void __init
board_setup(void)
673 panic("unable to detect bcm963xx board");
674 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
676 /* make sure we're running on expected cpu */
677 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
678 panic("unexpected CPU for bcm963xx board");
682 * return board name for /proc/cpuinfo
684 const char *board_get_name(void)
690 * register & return a new board mac address
692 static int board_get_mac_address(u8
*mac
)
697 if (mac_addr_used
>= nvram
.mac_addr_count
) {
698 printk(KERN_ERR PFX
"not enough mac address\n");
702 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
703 p
= mac
+ ETH_ALEN
- 1;
704 count
= mac_addr_used
;
716 printk(KERN_ERR PFX
"unable to fetch mac address\n");
724 static struct mtd_partition mtd_partitions
[] = {
732 static struct physmap_flash_data flash_data
= {
734 .nr_parts
= ARRAY_SIZE(mtd_partitions
),
735 .parts
= mtd_partitions
,
738 static struct resource mtd_resources
[] = {
740 .start
= 0, /* filled at runtime */
741 .end
= 0, /* filled at runtime */
742 .flags
= IORESOURCE_MEM
,
746 static struct platform_device mtd_dev
= {
747 .name
= "physmap-flash",
748 .resource
= mtd_resources
,
749 .num_resources
= ARRAY_SIZE(mtd_resources
),
751 .platform_data
= &flash_data
,
756 * Register a sane SPROMv2 to make the on-board
759 #ifdef CONFIG_SSB_PCIHOST
760 static struct ssb_sprom bcm63xx_sprom
= {
764 .ant_available_bg
= 0x3,
777 .boardflags_lo
= 0x2848,
778 .boardflags_hi
= 0x0000,
782 static struct gpio_led_platform_data bcm63xx_led_data
;
784 static struct platform_device bcm63xx_gpio_leds
= {
787 .dev
.platform_data
= &bcm63xx_led_data
,
791 * third stage init callback, register all board devices.
793 int __init
board_register_devices(void)
797 bcm63xx_uart_register();
799 if (board
.has_pccard
)
800 bcm63xx_pcmcia_register();
802 if (board
.has_enet0
&&
803 !board_get_mac_address(board
.enet0
.mac_addr
))
804 bcm63xx_enet_register(0, &board
.enet0
);
806 if (board
.has_enet1
&&
807 !board_get_mac_address(board
.enet1
.mac_addr
))
808 bcm63xx_enet_register(1, &board
.enet1
);
811 bcm63xx_dsp_register(&board
.dsp
);
813 /* Generate MAC address for WLAN and
814 * register our SPROM */
815 #ifdef CONFIG_SSB_PCIHOST
816 if (!board_get_mac_address(bcm63xx_sprom
.il0mac
)) {
817 memcpy(bcm63xx_sprom
.et0mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
818 memcpy(bcm63xx_sprom
.et1mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
819 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom
) < 0)
820 printk(KERN_ERR
"failed to register fallback SPROM\n");
824 /* read base address of boot chip select (0) */
825 if (BCMCPU_IS_6345())
828 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
829 val
&= MPI_CSBASE_BASE_MASK
;
831 mtd_resources
[0].start
= val
;
832 mtd_resources
[0].end
= 0x1FFFFFFF;
834 platform_device_register(&mtd_dev
);
836 bcm63xx_led_data
.num_leds
= ARRAY_SIZE(board
.leds
);
837 bcm63xx_led_data
.leds
= board
.leds
;
839 platform_device_register(&bcm63xx_gpio_leds
);