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,
551 static const struct board_info __initdata
*bcm963xx_boards
[] = {
552 #ifdef CONFIG_BCM63XX_CPU_6338
556 #ifdef CONFIG_BCM63XX_CPU_6345
559 #ifdef CONFIG_BCM63XX_CPU_6348
569 #ifdef CONFIG_BCM63XX_CPU_6358
577 * early init callback, read nvram data from flash and checksum it
579 void __init
board_prom_init(void)
581 unsigned int check_len
, i
;
582 u8
*boot_addr
, *cfe
, *p
;
583 char cfe_version
[32];
586 /* read base address of boot chip select (0)
587 * 6345 does not have MPI but boots from standard
588 * MIPS Flash address */
589 if (BCMCPU_IS_6345())
592 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
593 val
&= MPI_CSBASE_BASE_MASK
;
595 boot_addr
= (u8
*)KSEG1ADDR(val
);
597 /* dump cfe version */
598 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
599 if (!memcmp(cfe
, "cfe-v", 5))
600 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
601 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
603 strcpy(cfe_version
, "unknown");
604 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
606 /* extract nvram data */
607 memcpy(&nvram
, boot_addr
+ BCM963XX_NVRAM_OFFSET
, sizeof(nvram
));
609 /* check checksum before using data */
610 if (nvram
.version
<= 4)
611 check_len
= offsetof(struct bcm963xx_nvram
, checksum_old
);
613 check_len
= sizeof(nvram
);
619 printk(KERN_ERR PFX
"invalid nvram checksum\n");
623 /* find board by name */
624 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
625 if (strncmp(nvram
.name
, bcm963xx_boards
[i
]->name
,
628 /* copy, board desc array is marked initdata */
629 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
633 /* bail out if board is not found, will complain later */
634 if (!board
.name
[0]) {
636 memcpy(name
, nvram
.name
, 16);
638 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
643 /* setup pin multiplexing depending on board enabled device,
644 * this has to be done this early since PCI init is done
645 * inside arch_initcall */
649 bcm63xx_pci_enabled
= 1;
650 if (BCMCPU_IS_6348())
651 val
|= GPIO_MODE_6348_G2_PCI
;
654 if (board
.has_pccard
) {
655 if (BCMCPU_IS_6348())
656 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
659 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
660 if (BCMCPU_IS_6348())
661 val
|= GPIO_MODE_6348_G3_EXT_MII
|
662 GPIO_MODE_6348_G0_EXT_MII
;
665 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
666 if (BCMCPU_IS_6348())
667 val
|= GPIO_MODE_6348_G3_EXT_MII
|
668 GPIO_MODE_6348_G0_EXT_MII
;
671 bcm_gpio_writel(val
, GPIO_MODE_REG
);
675 * second stage init callback, good time to panic if we couldn't
676 * identify on which board we're running since early printk is working
678 void __init
board_setup(void)
681 panic("unable to detect bcm963xx board");
682 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
684 /* make sure we're running on expected cpu */
685 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
686 panic("unexpected CPU for bcm963xx board");
690 * return board name for /proc/cpuinfo
692 const char *board_get_name(void)
698 * register & return a new board mac address
700 static int board_get_mac_address(u8
*mac
)
705 if (mac_addr_used
>= nvram
.mac_addr_count
) {
706 printk(KERN_ERR PFX
"not enough mac address\n");
710 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
711 p
= mac
+ ETH_ALEN
- 1;
712 count
= mac_addr_used
;
724 printk(KERN_ERR PFX
"unable to fetch mac address\n");
732 static struct resource mtd_resources
[] = {
734 .start
= 0, /* filled at runtime */
735 .end
= 0, /* filled at runtime */
736 .flags
= IORESOURCE_MEM
,
740 static struct platform_device mtd_dev
= {
741 .name
= "bcm963xx-flash",
742 .resource
= mtd_resources
,
743 .num_resources
= ARRAY_SIZE(mtd_resources
),
747 * Register a sane SPROMv2 to make the on-board
750 static struct ssb_sprom bcm63xx_sprom
= {
754 .ant_available_bg
= 0x3,
767 .boardflags_lo
= 0x2848,
768 .boardflags_hi
= 0x0000,
771 static struct resource gpiodev_resource
= {
775 static struct gpio_led_platform_data bcm63xx_led_data
;
777 static struct platform_device bcm63xx_gpio_leds
= {
780 .dev
.platform_data
= &bcm63xx_led_data
,
784 * third stage init callback, register all board devices.
786 int __init
board_register_devices(void)
790 bcm63xx_uart_register();
791 bcm63xx_wdt_register();
793 if (!BCMCPU_IS_6345())
794 bcm63xx_spi_register();
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_ohci_register();
811 bcm63xx_ehci_register();
814 bcm63xx_udc_register();
817 bcm63xx_dsp_register(&board
.dsp
);
819 /* Generate MAC address for WLAN and
820 * register our SPROM */
822 if (!board_get_mac_address(bcm63xx_sprom
.il0mac
)) {
823 memcpy(bcm63xx_sprom
.et0mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
824 memcpy(bcm63xx_sprom
.et1mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
825 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom
) < 0)
826 printk(KERN_ERR
"failed to register fallback SPROM\n");
830 /* read base address of boot chip select (0) */
831 if (BCMCPU_IS_6345())
834 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
835 val
&= MPI_CSBASE_BASE_MASK
;
837 mtd_resources
[0].start
= val
;
838 mtd_resources
[0].end
= 0x1FFFFFFF;
840 platform_device_register(&mtd_dev
);
842 /* Register GPIODEV */
843 platform_device_register_simple("GPIODEV", 0, &gpiodev_resource
, 1);
845 bcm63xx_led_data
.num_leds
= ARRAY_SIZE(board
.leds
);
846 bcm63xx_led_data
.leds
= board
.leds
;
848 platform_device_register(&bcm63xx_gpio_leds
);