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 <linux/gpio_buttons.h>
19 #include <asm/addrspace.h>
20 #include <bcm63xx_board.h>
21 #include <bcm63xx_cpu.h>
22 #include <bcm63xx_regs.h>
23 #include <bcm63xx_io.h>
24 #include <bcm63xx_board.h>
25 #include <bcm63xx_dev_pci.h>
26 #include <bcm63xx_dev_uart.h>
27 #include <bcm63xx_dev_wdt.h>
28 #include <bcm63xx_dev_enet.h>
29 #include <bcm63xx_dev_dsp.h>
30 #include <bcm63xx_dev_pcmcia.h>
31 #include <bcm63xx_dev_usb_ohci.h>
32 #include <bcm63xx_dev_usb_ehci.h>
33 #include <bcm63xx_dev_usb_udc.h>
34 #include <bcm63xx_dev_spi.h>
35 #include <board_bcm963xx.h>
37 #define PFX "board_bcm963xx: "
39 static struct bcm963xx_nvram nvram
;
40 static unsigned int mac_addr_used
= 0;
41 static struct board_info board
;
47 #ifdef CONFIG_BCM63XX_CPU_6338
48 static struct board_info __initdata board_96338gw
= {
50 .expected_cpu_id
= 0x6338,
55 .force_duplex_full
= 1,
80 .default_trigger
= "default-on",
90 static struct board_info __initdata board_96338w
= {
92 .expected_cpu_id
= 0x6338,
97 .force_duplex_full
= 1,
120 .default_trigger
= "default-on",
134 #ifdef CONFIG_BCM63XX_CPU_6345
135 static struct board_info __initdata board_96345gw2
= {
137 .expected_cpu_id
= 0x6345,
144 #ifdef CONFIG_BCM63XX_CPU_6348
145 static struct board_info __initdata board_96348r
= {
147 .expected_cpu_id
= 0x6348,
154 .use_internal_phy
= 1,
177 .default_trigger
= "default-on",
188 static struct board_info __initdata board_96348gw_10
= {
189 .name
= "96348GW-10",
190 .expected_cpu_id
= 0x6348,
198 .use_internal_phy
= 1,
201 .force_speed_100
= 1,
202 .force_duplex_full
= 1,
237 .default_trigger
= "default-on",
247 static struct board_info __initdata board_96348gw_11
= {
248 .name
= "96348GW-11",
249 .expected_cpu_id
= 0x6348,
257 .use_internal_phy
= 1,
261 .force_speed_100
= 1,
262 .force_duplex_full
= 1,
290 .default_trigger
= "default-on",
300 static struct board_info __initdata board_96348gw
= {
302 .expected_cpu_id
= 0x6348,
310 .use_internal_phy
= 1,
313 .force_speed_100
= 1,
314 .force_duplex_full
= 1,
347 .default_trigger
= "default-on",
357 static struct board_info __initdata board_FAST2404
= {
359 .expected_cpu_id
= 0x6348,
367 .use_internal_phy
= 1,
371 .force_speed_100
= 1,
372 .force_duplex_full
= 1,
381 static struct board_info __initdata board_DV201AMR
= {
383 .expected_cpu_id
= 0x6348,
393 .use_internal_phy
= 1,
396 .force_speed_100
= 1,
397 .force_duplex_full
= 1,
401 static struct board_info __initdata board_96348gw_a
= {
403 .expected_cpu_id
= 0x6348,
411 .use_internal_phy
= 1,
414 .force_speed_100
= 1,
415 .force_duplex_full
= 1,
427 #ifdef CONFIG_BCM63XX_CPU_6358
428 static struct board_info __initdata board_96358vw
= {
430 .expected_cpu_id
= 0x6358,
438 .use_internal_phy
= 1,
442 .force_speed_100
= 1,
443 .force_duplex_full
= 1,
470 .default_trigger
= "default-on",
479 static struct board_info __initdata board_96358vw2
= {
481 .expected_cpu_id
= 0x6358,
489 .use_internal_phy
= 1,
493 .force_speed_100
= 1,
494 .force_duplex_full
= 1,
516 .default_trigger
= "default-on",
526 static struct board_info __initdata board_AGPFS0
= {
528 .expected_cpu_id
= 0x6358,
536 .use_internal_phy
= 1,
540 .force_speed_100
= 1,
541 .force_duplex_full
= 1,
548 static struct board_info __initdata board_DWVS0
= {
550 .expected_cpu_id
= 0x6358,
558 .use_internal_phy
= 1,
562 .force_speed_100
= 1,
563 .force_duplex_full
= 1,
573 static const struct board_info __initdata
*bcm963xx_boards
[] = {
574 #ifdef CONFIG_BCM63XX_CPU_6338
578 #ifdef CONFIG_BCM63XX_CPU_6345
581 #ifdef CONFIG_BCM63XX_CPU_6348
591 #ifdef CONFIG_BCM63XX_CPU_6358
600 * early init callback, read nvram data from flash and checksum it
602 void __init
board_prom_init(void)
604 unsigned int check_len
, i
;
605 u8
*boot_addr
, *cfe
, *p
;
606 char cfe_version
[32];
609 /* read base address of boot chip select (0)
610 * 6345 does not have MPI but boots from standard
611 * MIPS Flash address */
612 if (BCMCPU_IS_6345())
615 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
616 val
&= MPI_CSBASE_BASE_MASK
;
618 boot_addr
= (u8
*)KSEG1ADDR(val
);
620 /* dump cfe version */
621 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
622 if (!memcmp(cfe
, "cfe-v", 5))
623 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
624 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
626 strcpy(cfe_version
, "unknown");
627 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
629 /* extract nvram data */
630 memcpy(&nvram
, boot_addr
+ BCM963XX_NVRAM_OFFSET
, sizeof(nvram
));
632 /* check checksum before using data */
633 if (nvram
.version
<= 4)
634 check_len
= offsetof(struct bcm963xx_nvram
, checksum_old
);
636 check_len
= sizeof(nvram
);
642 printk(KERN_ERR PFX
"invalid nvram checksum\n");
646 /* find board by name */
647 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
648 if (strncmp(nvram
.name
, bcm963xx_boards
[i
]->name
,
651 /* copy, board desc array is marked initdata */
652 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
656 /* bail out if board is not found, will complain later */
657 if (!board
.name
[0]) {
659 memcpy(name
, nvram
.name
, 16);
661 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
666 /* setup pin multiplexing depending on board enabled device,
667 * this has to be done this early since PCI init is done
668 * inside arch_initcall */
672 bcm63xx_pci_enabled
= 1;
673 if (BCMCPU_IS_6348())
674 val
|= GPIO_MODE_6348_G2_PCI
;
677 if (board
.has_pccard
) {
678 if (BCMCPU_IS_6348())
679 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
682 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
683 if (BCMCPU_IS_6348())
684 val
|= GPIO_MODE_6348_G3_EXT_MII
|
685 GPIO_MODE_6348_G0_EXT_MII
;
688 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
689 if (BCMCPU_IS_6348())
690 val
|= GPIO_MODE_6348_G3_EXT_MII
|
691 GPIO_MODE_6348_G0_EXT_MII
;
694 bcm_gpio_writel(val
, GPIO_MODE_REG
);
698 * second stage init callback, good time to panic if we couldn't
699 * identify on which board we're running since early printk is working
701 void __init
board_setup(void)
704 panic("unable to detect bcm963xx board");
705 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
707 /* make sure we're running on expected cpu */
708 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
709 panic("unexpected CPU for bcm963xx board");
713 * return board name for /proc/cpuinfo
715 const char *board_get_name(void)
721 * register & return a new board mac address
723 static int board_get_mac_address(u8
*mac
)
728 if (mac_addr_used
>= nvram
.mac_addr_count
) {
729 printk(KERN_ERR PFX
"not enough mac address\n");
733 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
734 p
= mac
+ ETH_ALEN
- 1;
735 count
= mac_addr_used
;
747 printk(KERN_ERR PFX
"unable to fetch mac address\n");
755 static struct resource mtd_resources
[] = {
757 .start
= 0, /* filled at runtime */
758 .end
= 0, /* filled at runtime */
759 .flags
= IORESOURCE_MEM
,
763 static struct platform_device mtd_dev
= {
764 .name
= "bcm963xx-flash",
765 .resource
= mtd_resources
,
766 .num_resources
= ARRAY_SIZE(mtd_resources
),
770 * Register a sane SPROMv2 to make the on-board
773 static struct ssb_sprom bcm63xx_sprom
= {
777 .ant_available_bg
= 0x3,
790 .boardflags_lo
= 0x2848,
791 .boardflags_hi
= 0x0000,
794 static struct resource gpiodev_resource
= {
798 static struct gpio_led_platform_data bcm63xx_led_data
;
800 static struct platform_device bcm63xx_gpio_leds
= {
803 .dev
.platform_data
= &bcm63xx_led_data
,
806 struct gpio_buttons_platform_data bcm63xx_gpio_buttons_data
= {
810 struct platform_device bcm63xx_gpio_buttons_device
= {
811 .name
= "gpio-buttons",
813 .dev
.platform_data
= &bcm63xx_gpio_buttons_data
,
818 * third stage init callback, register all board devices.
820 int __init
board_register_devices(void)
824 bcm63xx_uart_register();
825 bcm63xx_wdt_register();
827 if (!BCMCPU_IS_6345())
828 bcm63xx_spi_register();
830 if (board
.has_pccard
)
831 bcm63xx_pcmcia_register();
833 if (board
.has_enet0
&&
834 !board_get_mac_address(board
.enet0
.mac_addr
))
835 bcm63xx_enet_register(0, &board
.enet0
);
837 if (board
.has_enet1
&&
838 !board_get_mac_address(board
.enet1
.mac_addr
))
839 bcm63xx_enet_register(1, &board
.enet1
);
842 bcm63xx_ohci_register();
845 bcm63xx_ehci_register();
848 bcm63xx_udc_register();
851 bcm63xx_dsp_register(&board
.dsp
);
853 /* Generate MAC address for WLAN and
854 * register our SPROM */
856 if (!board_get_mac_address(bcm63xx_sprom
.il0mac
)) {
857 memcpy(bcm63xx_sprom
.et0mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
858 memcpy(bcm63xx_sprom
.et1mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
859 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom
) < 0)
860 printk(KERN_ERR
"failed to register fallback SPROM\n");
864 /* read base address of boot chip select (0) */
865 if (BCMCPU_IS_6345())
868 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
869 val
&= MPI_CSBASE_BASE_MASK
;
871 mtd_resources
[0].start
= val
;
872 mtd_resources
[0].end
= 0x1FFFFFFF;
874 platform_device_register(&mtd_dev
);
876 /* Register GPIODEV */
877 platform_device_register_simple("GPIODEV", 0, &gpiodev_resource
, 1);
879 bcm63xx_led_data
.num_leds
= ARRAY_SIZE(board
.leds
);
880 bcm63xx_led_data
.leds
= board
.leds
;
882 platform_device_register(&bcm63xx_gpio_leds
);
884 if (board
.reset_btn
) {
885 bcm63xx_gpio_buttons_data
.nbuttons
= 1,
886 bcm63xx_gpio_buttons_data
.buttons
= board
.reset_btn
;
888 platform_device_register(&bcm63xx_gpio_buttons_device
);