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,
372 static struct board_info __initdata board_DV201AMR
= {
374 .expected_cpu_id
= 0x6348,
383 .use_internal_phy
= 1,
386 .force_speed_100
= 1,
387 .force_duplex_full
= 1,
391 static struct board_info __initdata board_96348gw_a
= {
393 .expected_cpu_id
= 0x6348,
401 .use_internal_phy
= 1,
404 .force_speed_100
= 1,
405 .force_duplex_full
= 1,
415 #ifdef CONFIG_BCM63XX_CPU_6358
416 static struct board_info __initdata board_96358vw
= {
418 .expected_cpu_id
= 0x6358,
426 .use_internal_phy
= 1,
430 .force_speed_100
= 1,
431 .force_duplex_full
= 1,
458 .default_trigger
= "default-on",
467 static struct board_info __initdata board_96358vw2
= {
469 .expected_cpu_id
= 0x6358,
477 .use_internal_phy
= 1,
481 .force_speed_100
= 1,
482 .force_duplex_full
= 1,
504 .default_trigger
= "default-on",
514 static struct board_info __initdata board_AGPFS0
= {
516 .expected_cpu_id
= 0x6358,
524 .use_internal_phy
= 1,
528 .force_speed_100
= 1,
529 .force_duplex_full
= 1,
540 static const struct board_info __initdata
*bcm963xx_boards
[] = {
541 #ifdef CONFIG_BCM63XX_CPU_6338
545 #ifdef CONFIG_BCM63XX_CPU_6345
548 #ifdef CONFIG_BCM63XX_CPU_6348
558 #ifdef CONFIG_BCM63XX_CPU_6358
566 * early init callback, read nvram data from flash and checksum it
568 void __init
board_prom_init(void)
570 unsigned int check_len
, i
;
571 u8
*boot_addr
, *cfe
, *p
;
572 char cfe_version
[32];
575 /* read base address of boot chip select (0)
576 * 6345 does not have MPI but boots from standard
577 * MIPS Flash address */
578 if (BCMCPU_IS_6345())
581 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
582 val
&= MPI_CSBASE_BASE_MASK
;
584 boot_addr
= (u8
*)KSEG1ADDR(val
);
586 /* dump cfe version */
587 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
588 if (!memcmp(cfe
, "cfe-v", 5))
589 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
590 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
592 strcpy(cfe_version
, "unknown");
593 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
595 /* extract nvram data */
596 memcpy(&nvram
, boot_addr
+ BCM963XX_NVRAM_OFFSET
, sizeof(nvram
));
598 /* check checksum before using data */
599 if (nvram
.version
<= 4)
600 check_len
= offsetof(struct bcm963xx_nvram
, checksum_old
);
602 check_len
= sizeof(nvram
);
608 printk(KERN_ERR PFX
"invalid nvram checksum\n");
612 /* find board by name */
613 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
614 if (strncmp(nvram
.name
, bcm963xx_boards
[i
]->name
,
617 /* copy, board desc array is marked initdata */
618 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
622 /* bail out if board is not found, will complain later */
623 if (!board
.name
[0]) {
625 memcpy(name
, nvram
.name
, 16);
627 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
632 /* setup pin multiplexing depending on board enabled device,
633 * this has to be done this early since PCI init is done
634 * inside arch_initcall */
639 bcm63xx_pci_enabled
= 1;
640 if (BCMCPU_IS_6348())
641 val
|= GPIO_MODE_6348_G2_PCI
;
645 if (board
.has_pccard
) {
646 if (BCMCPU_IS_6348())
647 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
650 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
651 if (BCMCPU_IS_6348())
652 val
|= GPIO_MODE_6348_G3_EXT_MII
|
653 GPIO_MODE_6348_G0_EXT_MII
;
656 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
657 if (BCMCPU_IS_6348())
658 val
|= GPIO_MODE_6348_G3_EXT_MII
|
659 GPIO_MODE_6348_G0_EXT_MII
;
662 bcm_gpio_writel(val
, GPIO_MODE_REG
);
666 * second stage init callback, good time to panic if we couldn't
667 * identify on which board we're running since early printk is working
669 void __init
board_setup(void)
672 panic("unable to detect bcm963xx board");
673 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
675 /* make sure we're running on expected cpu */
676 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
677 panic("unexpected CPU for bcm963xx board");
681 * return board name for /proc/cpuinfo
683 const char *board_get_name(void)
689 * register & return a new board mac address
691 static int board_get_mac_address(u8
*mac
)
696 if (mac_addr_used
>= nvram
.mac_addr_count
) {
697 printk(KERN_ERR PFX
"not enough mac address\n");
701 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
702 p
= mac
+ ETH_ALEN
- 1;
703 count
= mac_addr_used
;
715 printk(KERN_ERR PFX
"unable to fetch mac address\n");
723 static struct mtd_partition mtd_partitions
[] = {
731 static struct physmap_flash_data flash_data
= {
733 .nr_parts
= ARRAY_SIZE(mtd_partitions
),
734 .parts
= mtd_partitions
,
737 static struct resource mtd_resources
[] = {
739 .start
= 0, /* filled at runtime */
740 .end
= 0, /* filled at runtime */
741 .flags
= IORESOURCE_MEM
,
745 static struct platform_device mtd_dev
= {
746 .name
= "physmap-flash",
747 .resource
= mtd_resources
,
748 .num_resources
= ARRAY_SIZE(mtd_resources
),
750 .platform_data
= &flash_data
,
755 * Register a sane SPROMv2 to make the on-board
758 #ifdef CONFIG_SSB_PCIHOST
759 static struct ssb_sprom bcm63xx_sprom
= {
763 .ant_available_bg
= 0x3,
776 .boardflags_lo
= 0x2848,
777 .boardflags_hi
= 0x0000,
781 static struct gpio_led_platform_data bcm63xx_led_data
;
783 static struct platform_device bcm63xx_gpio_leds
= {
786 .dev
.platform_data
= &bcm63xx_led_data
,
790 * third stage init callback, register all board devices.
792 int __init
board_register_devices(void)
796 if (board
.has_pccard
)
797 bcm63xx_pcmcia_register();
799 if (board
.has_enet0
&&
800 !board_get_mac_address(board
.enet0
.mac_addr
))
801 bcm63xx_enet_register(0, &board
.enet0
);
803 if (board
.has_enet1
&&
804 !board_get_mac_address(board
.enet1
.mac_addr
))
805 bcm63xx_enet_register(1, &board
.enet1
);
808 bcm63xx_dsp_register(&board
.dsp
);
810 /* Generate MAC address for WLAN and
811 * register our SPROM */
812 #ifdef CONFIG_SSB_PCIHOST
813 if (!board_get_mac_address(bcm63xx_sprom
.il0mac
)) {
814 memcpy(bcm63xx_sprom
.et0mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
815 memcpy(bcm63xx_sprom
.et1mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
816 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom
) < 0)
817 printk(KERN_ERR
"failed to register fallback SPROM\n");
821 /* read base address of boot chip select (0) */
822 if (BCMCPU_IS_6345())
825 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
826 val
&= MPI_CSBASE_BASE_MASK
;
828 mtd_resources
[0].start
= val
;
829 mtd_resources
[0].end
= 0x1FFFFFFF;
831 platform_device_register(&mtd_dev
);
833 bcm63xx_led_data
.num_leds
= ARRAY_SIZE(board
.leds
);
834 bcm63xx_led_data
.leds
= board
.leds
;
836 platform_device_register(&bcm63xx_gpio_leds
);