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,
421 static struct board_info __initdata board_rta1025w_16
= {
422 .name
= "RTA1025W_16",
423 .expected_cpu_id
= 0x6348,
431 .use_internal_phy
= 1,
434 .force_speed_100
= 1,
435 .force_duplex_full
= 1,
443 #ifdef CONFIG_BCM63XX_CPU_6358
444 static struct board_info __initdata board_96358vw
= {
446 .expected_cpu_id
= 0x6358,
454 .use_internal_phy
= 1,
458 .force_speed_100
= 1,
459 .force_duplex_full
= 1,
486 .default_trigger
= "default-on",
495 static struct board_info __initdata board_96358vw2
= {
497 .expected_cpu_id
= 0x6358,
505 .use_internal_phy
= 1,
509 .force_speed_100
= 1,
510 .force_duplex_full
= 1,
532 .default_trigger
= "default-on",
542 static struct board_info __initdata board_AGPFS0
= {
544 .expected_cpu_id
= 0x6358,
552 .use_internal_phy
= 1,
556 .force_speed_100
= 1,
557 .force_duplex_full
= 1,
564 static struct board_info __initdata board_DWVS0
= {
566 .expected_cpu_id
= 0x6358,
574 .use_internal_phy
= 1,
578 .force_speed_100
= 1,
579 .force_duplex_full
= 1,
589 static const struct board_info __initdata
*bcm963xx_boards
[] = {
590 #ifdef CONFIG_BCM63XX_CPU_6338
594 #ifdef CONFIG_BCM63XX_CPU_6345
597 #ifdef CONFIG_BCM63XX_CPU_6348
608 #ifdef CONFIG_BCM63XX_CPU_6358
617 * early init callback, read nvram data from flash and checksum it
619 void __init
board_prom_init(void)
621 unsigned int check_len
, i
;
622 u8
*boot_addr
, *cfe
, *p
;
623 char cfe_version
[32];
626 /* read base address of boot chip select (0)
627 * 6345 does not have MPI but boots from standard
628 * MIPS Flash address */
629 if (BCMCPU_IS_6345())
632 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
633 val
&= MPI_CSBASE_BASE_MASK
;
635 boot_addr
= (u8
*)KSEG1ADDR(val
);
637 /* dump cfe version */
638 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
639 if (!memcmp(cfe
, "cfe-v", 5))
640 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
641 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
643 strcpy(cfe_version
, "unknown");
644 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
646 /* extract nvram data */
647 memcpy(&nvram
, boot_addr
+ BCM963XX_NVRAM_OFFSET
, sizeof(nvram
));
649 /* check checksum before using data */
650 if (nvram
.version
<= 4)
651 check_len
= offsetof(struct bcm963xx_nvram
, checksum_old
);
653 check_len
= sizeof(nvram
);
659 printk(KERN_ERR PFX
"invalid nvram checksum\n");
663 /* find board by name */
664 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
665 if (strncmp(nvram
.name
, bcm963xx_boards
[i
]->name
,
668 /* copy, board desc array is marked initdata */
669 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
673 /* bail out if board is not found, will complain later */
674 if (!board
.name
[0]) {
676 memcpy(name
, nvram
.name
, 16);
678 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
683 /* setup pin multiplexing depending on board enabled device,
684 * this has to be done this early since PCI init is done
685 * inside arch_initcall */
689 bcm63xx_pci_enabled
= 1;
690 if (BCMCPU_IS_6348())
691 val
|= GPIO_MODE_6348_G2_PCI
;
694 if (board
.has_pccard
) {
695 if (BCMCPU_IS_6348())
696 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
699 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
700 if (BCMCPU_IS_6348())
701 val
|= GPIO_MODE_6348_G3_EXT_MII
|
702 GPIO_MODE_6348_G0_EXT_MII
;
705 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
706 if (BCMCPU_IS_6348())
707 val
|= GPIO_MODE_6348_G3_EXT_MII
|
708 GPIO_MODE_6348_G0_EXT_MII
;
711 bcm_gpio_writel(val
, GPIO_MODE_REG
);
715 * second stage init callback, good time to panic if we couldn't
716 * identify on which board we're running since early printk is working
718 void __init
board_setup(void)
721 panic("unable to detect bcm963xx board");
722 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
724 /* make sure we're running on expected cpu */
725 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
726 panic("unexpected CPU for bcm963xx board");
730 * return board name for /proc/cpuinfo
732 const char *board_get_name(void)
738 * register & return a new board mac address
740 static int board_get_mac_address(u8
*mac
)
745 if (mac_addr_used
>= nvram
.mac_addr_count
) {
746 printk(KERN_ERR PFX
"not enough mac address\n");
750 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
751 p
= mac
+ ETH_ALEN
- 1;
752 count
= mac_addr_used
;
764 printk(KERN_ERR PFX
"unable to fetch mac address\n");
772 static struct resource mtd_resources
[] = {
774 .start
= 0, /* filled at runtime */
775 .end
= 0, /* filled at runtime */
776 .flags
= IORESOURCE_MEM
,
780 static struct platform_device mtd_dev
= {
781 .name
= "bcm963xx-flash",
782 .resource
= mtd_resources
,
783 .num_resources
= ARRAY_SIZE(mtd_resources
),
787 * Register a sane SPROMv2 to make the on-board
790 static struct ssb_sprom bcm63xx_sprom
= {
794 .ant_available_bg
= 0x3,
807 .boardflags_lo
= 0x2848,
808 .boardflags_hi
= 0x0000,
811 static struct resource gpiodev_resource
= {
815 static struct gpio_led_platform_data bcm63xx_led_data
;
817 static struct platform_device bcm63xx_gpio_leds
= {
820 .dev
.platform_data
= &bcm63xx_led_data
,
823 struct gpio_buttons_platform_data bcm63xx_gpio_buttons_data
= {
827 struct platform_device bcm63xx_gpio_buttons_device
= {
828 .name
= "gpio-buttons",
830 .dev
.platform_data
= &bcm63xx_gpio_buttons_data
,
835 * third stage init callback, register all board devices.
837 int __init
board_register_devices(void)
841 bcm63xx_uart_register();
842 bcm63xx_wdt_register();
844 if (!BCMCPU_IS_6345())
845 bcm63xx_spi_register();
847 if (board
.has_pccard
)
848 bcm63xx_pcmcia_register();
850 if (board
.has_enet0
&&
851 !board_get_mac_address(board
.enet0
.mac_addr
))
852 bcm63xx_enet_register(0, &board
.enet0
);
854 if (board
.has_enet1
&&
855 !board_get_mac_address(board
.enet1
.mac_addr
))
856 bcm63xx_enet_register(1, &board
.enet1
);
859 bcm63xx_ohci_register();
862 bcm63xx_ehci_register();
865 bcm63xx_udc_register();
868 bcm63xx_dsp_register(&board
.dsp
);
870 /* Generate MAC address for WLAN and
871 * register our SPROM */
873 if (!board_get_mac_address(bcm63xx_sprom
.il0mac
)) {
874 memcpy(bcm63xx_sprom
.et0mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
875 memcpy(bcm63xx_sprom
.et1mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
876 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom
) < 0)
877 printk(KERN_ERR
"failed to register fallback SPROM\n");
881 /* read base address of boot chip select (0) */
882 if (BCMCPU_IS_6345())
885 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
886 val
&= MPI_CSBASE_BASE_MASK
;
888 mtd_resources
[0].start
= val
;
889 mtd_resources
[0].end
= 0x1FFFFFFF;
891 platform_device_register(&mtd_dev
);
893 /* Register GPIODEV */
894 platform_device_register_simple("GPIODEV", 0, &gpiodev_resource
, 1);
896 bcm63xx_led_data
.num_leds
= ARRAY_SIZE(board
.leds
);
897 bcm63xx_led_data
.leds
= board
.leds
;
899 platform_device_register(&bcm63xx_gpio_leds
);
901 if (board
.reset_btn
) {
902 bcm63xx_gpio_buttons_data
.nbuttons
= 1,
903 bcm63xx_gpio_buttons_data
.buttons
= board
.reset_btn
;
905 platform_device_register(&bcm63xx_gpio_buttons_device
);