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 /*Each led on alice gate is bi-color so final char */
565 /* is r for red and g for green leds */
575 .default_trigger
= "default-on",
609 .reset_btn
= 37; /* sw2 */
610 /* sw1 is connected to gpio34*/
613 static struct board_info __initdata board_DWVS0
= {
615 .expected_cpu_id
= 0x6358,
623 .use_internal_phy
= 1,
627 .force_speed_100
= 1,
628 .force_duplex_full
= 1,
638 static const struct board_info __initdata
*bcm963xx_boards
[] = {
639 #ifdef CONFIG_BCM63XX_CPU_6338
643 #ifdef CONFIG_BCM63XX_CPU_6345
646 #ifdef CONFIG_BCM63XX_CPU_6348
657 #ifdef CONFIG_BCM63XX_CPU_6358
666 * early init callback, read nvram data from flash and checksum it
668 void __init
board_prom_init(void)
670 unsigned int check_len
, i
;
671 u8
*boot_addr
, *cfe
, *p
;
672 char cfe_version
[32];
675 /* read base address of boot chip select (0)
676 * 6345 does not have MPI but boots from standard
677 * MIPS Flash address */
678 if (BCMCPU_IS_6345())
681 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
682 val
&= MPI_CSBASE_BASE_MASK
;
684 boot_addr
= (u8
*)KSEG1ADDR(val
);
686 /* dump cfe version */
687 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
688 if (!memcmp(cfe
, "cfe-v", 5))
689 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
690 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
692 strcpy(cfe_version
, "unknown");
693 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
695 /* extract nvram data */
696 memcpy(&nvram
, boot_addr
+ BCM963XX_NVRAM_OFFSET
, sizeof(nvram
));
698 /* check checksum before using data */
699 if (nvram
.version
<= 4)
700 check_len
= offsetof(struct bcm963xx_nvram
, checksum_old
);
702 check_len
= sizeof(nvram
);
708 printk(KERN_ERR PFX
"invalid nvram checksum\n");
712 /* find board by name */
713 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
714 if (strncmp(nvram
.name
, bcm963xx_boards
[i
]->name
,
717 /* copy, board desc array is marked initdata */
718 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
722 /* bail out if board is not found, will complain later */
723 if (!board
.name
[0]) {
725 memcpy(name
, nvram
.name
, 16);
727 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
732 /* setup pin multiplexing depending on board enabled device,
733 * this has to be done this early since PCI init is done
734 * inside arch_initcall */
738 bcm63xx_pci_enabled
= 1;
739 if (BCMCPU_IS_6348())
740 val
|= GPIO_MODE_6348_G2_PCI
;
743 if (board
.has_pccard
) {
744 if (BCMCPU_IS_6348())
745 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
748 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
749 if (BCMCPU_IS_6348())
750 val
|= GPIO_MODE_6348_G3_EXT_MII
|
751 GPIO_MODE_6348_G0_EXT_MII
;
754 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
755 if (BCMCPU_IS_6348())
756 val
|= GPIO_MODE_6348_G3_EXT_MII
|
757 GPIO_MODE_6348_G0_EXT_MII
;
760 bcm_gpio_writel(val
, GPIO_MODE_REG
);
764 * second stage init callback, good time to panic if we couldn't
765 * identify on which board we're running since early printk is working
767 void __init
board_setup(void)
770 panic("unable to detect bcm963xx board");
771 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
773 /* make sure we're running on expected cpu */
774 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
775 panic("unexpected CPU for bcm963xx board");
779 * return board name for /proc/cpuinfo
781 const char *board_get_name(void)
787 * register & return a new board mac address
789 static int board_get_mac_address(u8
*mac
)
794 if (mac_addr_used
>= nvram
.mac_addr_count
) {
795 printk(KERN_ERR PFX
"not enough mac address\n");
799 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
800 p
= mac
+ ETH_ALEN
- 1;
801 count
= mac_addr_used
;
813 printk(KERN_ERR PFX
"unable to fetch mac address\n");
821 static struct resource mtd_resources
[] = {
823 .start
= 0, /* filled at runtime */
824 .end
= 0, /* filled at runtime */
825 .flags
= IORESOURCE_MEM
,
829 static struct platform_device mtd_dev
= {
830 .name
= "bcm963xx-flash",
831 .resource
= mtd_resources
,
832 .num_resources
= ARRAY_SIZE(mtd_resources
),
836 * Register a sane SPROMv2 to make the on-board
839 static struct ssb_sprom bcm63xx_sprom
= {
843 .ant_available_bg
= 0x3,
856 .boardflags_lo
= 0x2848,
857 .boardflags_hi
= 0x0000,
860 static struct resource gpiodev_resource
= {
864 static struct gpio_led_platform_data bcm63xx_led_data
;
866 static struct platform_device bcm63xx_gpio_leds
= {
869 .dev
.platform_data
= &bcm63xx_led_data
,
872 struct gpio_buttons_platform_data bcm63xx_gpio_buttons_data
= {
876 struct platform_device bcm63xx_gpio_buttons_device
= {
877 .name
= "gpio-buttons",
879 .dev
.platform_data
= &bcm63xx_gpio_buttons_data
,
884 * third stage init callback, register all board devices.
886 int __init
board_register_devices(void)
890 bcm63xx_uart_register();
891 bcm63xx_wdt_register();
893 if (!BCMCPU_IS_6345())
894 bcm63xx_spi_register();
896 if (board
.has_pccard
)
897 bcm63xx_pcmcia_register();
899 if (board
.has_enet0
&&
900 !board_get_mac_address(board
.enet0
.mac_addr
))
901 bcm63xx_enet_register(0, &board
.enet0
);
903 if (board
.has_enet1
&&
904 !board_get_mac_address(board
.enet1
.mac_addr
))
905 bcm63xx_enet_register(1, &board
.enet1
);
908 bcm63xx_ohci_register();
911 bcm63xx_ehci_register();
914 bcm63xx_udc_register();
917 bcm63xx_dsp_register(&board
.dsp
);
919 /* Generate MAC address for WLAN and
920 * register our SPROM */
922 if (!board_get_mac_address(bcm63xx_sprom
.il0mac
)) {
923 memcpy(bcm63xx_sprom
.et0mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
924 memcpy(bcm63xx_sprom
.et1mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
925 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom
) < 0)
926 printk(KERN_ERR
"failed to register fallback SPROM\n");
930 /* read base address of boot chip select (0) */
931 if (BCMCPU_IS_6345())
934 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
935 val
&= MPI_CSBASE_BASE_MASK
;
937 mtd_resources
[0].start
= val
;
938 mtd_resources
[0].end
= 0x1FFFFFFF;
940 platform_device_register(&mtd_dev
);
942 /* Register GPIODEV */
943 platform_device_register_simple("GPIODEV", 0, &gpiodev_resource
, 1);
945 bcm63xx_led_data
.num_leds
= ARRAY_SIZE(board
.leds
);
946 bcm63xx_led_data
.leds
= board
.leds
;
948 platform_device_register(&bcm63xx_gpio_leds
);
950 if (board
.reset_btn
) {
951 bcm63xx_gpio_buttons_data
.nbuttons
= 1,
952 bcm63xx_gpio_buttons_data
.buttons
= board
.reset_btn
;
954 platform_device_register(&bcm63xx_gpio_buttons_device
);