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_dev_uart.h>
22 #include <bcm63xx_regs.h>
23 #include <bcm63xx_io.h>
24 #include <bcm63xx_dev_pci.h>
25 #include <bcm63xx_dev_enet.h>
26 #include <bcm63xx_dev_dsp.h>
27 #include <bcm63xx_dev_pcmcia.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,
48 .force_duplex_full
= 1,
73 .default_trigger
= "default-on",
83 static struct board_info __initdata board_96338w
= {
85 .expected_cpu_id
= 0x6338,
91 .force_duplex_full
= 1,
114 .default_trigger
= "default-on",
128 #ifdef CONFIG_BCM63XX_CPU_6345
129 static struct board_info __initdata board_96345gw2
= {
131 .expected_cpu_id
= 0x6345,
140 #ifdef CONFIG_BCM63XX_CPU_6348
141 static struct board_info __initdata board_96348r
= {
143 .expected_cpu_id
= 0x6348,
151 .use_internal_phy
= 1,
174 .default_trigger
= "default-on",
185 static struct board_info __initdata board_96348gw_10
= {
186 .name
= "96348GW-10",
187 .expected_cpu_id
= 0x6348,
196 .use_internal_phy
= 1,
199 .force_speed_100
= 1,
200 .force_duplex_full
= 1,
235 .default_trigger
= "default-on",
245 static struct board_info __initdata board_96348gw_11
= {
246 .name
= "96348GW-11",
247 .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,
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,
368 .use_internal_phy
= 1,
372 .force_speed_100
= 1,
373 .force_duplex_full
= 1,
381 static struct board_info __initdata board_rta1025w_16
= {
382 .name
= "RTA1025W_16",
383 .expected_cpu_id
= 0x6348,
391 .use_internal_phy
= 1,
394 .force_speed_100
= 1,
395 .force_duplex_full
= 1,
400 static struct board_info __initdata board_DV201AMR
= {
402 .expected_cpu_id
= 0x6348,
412 .use_internal_phy
= 1,
415 .force_speed_100
= 1,
416 .force_duplex_full
= 1,
420 static struct board_info __initdata board_96348gw_a
= {
422 .expected_cpu_id
= 0x6348,
431 .use_internal_phy
= 1,
434 .force_speed_100
= 1,
435 .force_duplex_full
= 1,
445 #ifdef CONFIG_BCM63XX_CPU_6358
446 static struct board_info __initdata board_96358vw
= {
448 .expected_cpu_id
= 0x6358,
457 .use_internal_phy
= 1,
461 .force_speed_100
= 1,
462 .force_duplex_full
= 1,
489 .default_trigger
= "default-on",
498 static struct board_info __initdata board_96358vw2
= {
500 .expected_cpu_id
= 0x6358,
509 .use_internal_phy
= 1,
513 .force_speed_100
= 1,
514 .force_duplex_full
= 1,
536 .default_trigger
= "default-on",
546 static struct board_info __initdata board_AGPFS0
= {
548 .expected_cpu_id
= 0x6358,
557 .use_internal_phy
= 1,
561 .force_speed_100
= 1,
562 .force_duplex_full
= 1,
569 static struct board_info __initdata board_DWVS0
= {
571 .expected_cpu_id
= 0x6358,
579 .use_internal_phy
= 1,
583 .force_speed_100
= 1,
584 .force_duplex_full
= 1,
594 static const struct board_info __initdata
*bcm963xx_boards
[] = {
595 #ifdef CONFIG_BCM63XX_CPU_6338
599 #ifdef CONFIG_BCM63XX_CPU_6345
602 #ifdef CONFIG_BCM63XX_CPU_6348
613 #ifdef CONFIG_BCM63XX_CPU_6358
622 * Register a sane SPROMv2 to make the on-board
625 #ifdef CONFIG_SSB_PCIHOST
626 static struct ssb_sprom bcm63xx_sprom
= {
630 .ant_available_bg
= 0x3,
643 .boardflags_lo
= 0x2848,
644 .boardflags_hi
= 0x0000,
647 int bcm63xx_get_fallback_sprom(struct ssb_bus
*bus
, struct ssb_sprom
*out
)
649 if (bus
->bustype
== SSB_BUSTYPE_PCI
) {
650 memcpy(out
, &bcm63xx_sprom
, sizeof(struct ssb_sprom
));
653 printk(KERN_ERR PFX
"unable to fill SPROM for given bustype.\n");
660 * return board name for /proc/cpuinfo
662 const char *board_get_name(void)
668 * register & return a new board mac address
670 static int board_get_mac_address(u8
*mac
)
675 if (mac_addr_used
>= nvram
.mac_addr_count
) {
676 printk(KERN_ERR PFX
"not enough mac address\n");
680 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
681 p
= mac
+ ETH_ALEN
- 1;
682 count
= mac_addr_used
;
694 printk(KERN_ERR PFX
"unable to fetch mac address\n");
703 * early init callback, read nvram data from flash and checksum it
705 void __init
board_prom_init(void)
707 unsigned int check_len
, i
;
708 u8
*boot_addr
, *cfe
, *p
;
709 char cfe_version
[32];
712 /* read base address of boot chip select (0)
713 * 6345 does not have MPI but boots from standard
714 * MIPS Flash address */
715 if (BCMCPU_IS_6345())
718 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
719 val
&= MPI_CSBASE_BASE_MASK
;
721 boot_addr
= (u8
*)KSEG1ADDR(val
);
723 /* dump cfe version */
724 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
725 if (!memcmp(cfe
, "cfe-v", 5))
726 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
727 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
729 strcpy(cfe_version
, "unknown");
730 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
732 /* extract nvram data */
733 memcpy(&nvram
, boot_addr
+ BCM963XX_NVRAM_OFFSET
, sizeof(nvram
));
735 /* check checksum before using data */
736 if (nvram
.version
<= 4)
737 check_len
= offsetof(struct bcm963xx_nvram
, checksum_old
);
739 check_len
= sizeof(nvram
);
745 printk(KERN_ERR PFX
"invalid nvram checksum\n");
749 /* find board by name */
750 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
751 if (strncmp(nvram
.name
, bcm963xx_boards
[i
]->name
,
754 /* copy, board desc array is marked initdata */
755 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
759 /* bail out if board is not found, will complain later */
760 if (!board
.name
[0]) {
762 memcpy(name
, nvram
.name
, 16);
764 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
769 /* setup pin multiplexing depending on board enabled device,
770 * this has to be done this early since PCI init is done
771 * inside arch_initcall */
776 bcm63xx_pci_enabled
= 1;
777 if (BCMCPU_IS_6348())
778 val
|= GPIO_MODE_6348_G2_PCI
;
782 if (board
.has_pccard
) {
783 if (BCMCPU_IS_6348())
784 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
787 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
788 if (BCMCPU_IS_6348())
789 val
|= GPIO_MODE_6348_G3_EXT_MII
|
790 GPIO_MODE_6348_G0_EXT_MII
;
793 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
794 if (BCMCPU_IS_6348())
795 val
|= GPIO_MODE_6348_G3_EXT_MII
|
796 GPIO_MODE_6348_G0_EXT_MII
;
799 bcm_gpio_writel(val
, GPIO_MODE_REG
);
801 /* Generate MAC address for WLAN and
802 * register our SPROM */
803 #ifdef CONFIG_SSB_PCIHOST
804 if (!board_get_mac_address(bcm63xx_sprom
.il0mac
)) {
805 memcpy(bcm63xx_sprom
.et0mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
806 memcpy(bcm63xx_sprom
.et1mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
807 if (ssb_arch_register_fallback_sprom(
808 &bcm63xx_get_fallback_sprom
) < 0)
809 printk(KERN_ERR PFX
"failed to register fallback SPROM\n");
815 * second stage init callback, good time to panic if we couldn't
816 * identify on which board we're running since early printk is working
818 void __init
board_setup(void)
821 panic("unable to detect bcm963xx board");
822 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
824 /* make sure we're running on expected cpu */
825 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
826 panic("unexpected CPU for bcm963xx board");
829 static struct mtd_partition mtd_partitions
[] = {
837 static struct physmap_flash_data flash_data
= {
839 .nr_parts
= ARRAY_SIZE(mtd_partitions
),
840 .parts
= mtd_partitions
,
843 static struct resource mtd_resources
[] = {
845 .start
= 0, /* filled at runtime */
846 .end
= 0, /* filled at runtime */
847 .flags
= IORESOURCE_MEM
,
851 static struct platform_device mtd_dev
= {
852 .name
= "physmap-flash",
853 .resource
= mtd_resources
,
854 .num_resources
= ARRAY_SIZE(mtd_resources
),
856 .platform_data
= &flash_data
,
860 static struct gpio_led_platform_data bcm63xx_led_data
;
862 static struct platform_device bcm63xx_gpio_leds
= {
865 .dev
.platform_data
= &bcm63xx_led_data
,
869 * third stage init callback, register all board devices.
871 int __init
board_register_devices(void)
876 bcm63xx_uart_register(0);
879 bcm63xx_uart_register(1);
881 if (board
.has_pccard
)
882 bcm63xx_pcmcia_register();
884 if (board
.has_enet0
&&
885 !board_get_mac_address(board
.enet0
.mac_addr
))
886 bcm63xx_enet_register(0, &board
.enet0
);
888 if (board
.has_enet1
&&
889 !board_get_mac_address(board
.enet1
.mac_addr
))
890 bcm63xx_enet_register(1, &board
.enet1
);
893 bcm63xx_dsp_register(&board
.dsp
);
895 /* read base address of boot chip select (0) */
896 if (BCMCPU_IS_6345())
899 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
900 val
&= MPI_CSBASE_BASE_MASK
;
902 mtd_resources
[0].start
= val
;
903 mtd_resources
[0].end
= 0x1FFFFFFF;
905 platform_device_register(&mtd_dev
);
907 bcm63xx_led_data
.num_leds
= ARRAY_SIZE(board
.leds
);
908 bcm63xx_led_data
.leds
= board
.leds
;
910 platform_device_register(&bcm63xx_gpio_leds
);