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>
36 #include <linux/input.h>
38 #define PFX "board_bcm963xx: "
40 static struct bcm963xx_nvram nvram
;
41 static unsigned int mac_addr_used
= 0;
42 static struct board_info board
;
48 #ifdef CONFIG_BCM63XX_CPU_6338
49 static struct board_info __initdata board_96338gw
= {
51 .expected_cpu_id
= 0x6338,
56 .force_duplex_full
= 1,
81 .default_trigger
= "default-on",
91 static struct board_info __initdata board_96338w
= {
93 .expected_cpu_id
= 0x6338,
98 .force_duplex_full
= 1,
121 .default_trigger
= "default-on",
135 #ifdef CONFIG_BCM63XX_CPU_6345
136 static struct board_info __initdata board_96345gw2
= {
138 .expected_cpu_id
= 0x6345,
145 #ifdef CONFIG_BCM63XX_CPU_6348
146 static struct board_info __initdata board_96348r
= {
148 .expected_cpu_id
= 0x6348,
155 .use_internal_phy
= 1,
178 .default_trigger
= "default-on",
189 static struct board_info __initdata board_96348gw_10
= {
190 .name
= "96348GW-10",
191 .expected_cpu_id
= 0x6348,
199 .use_internal_phy
= 1,
202 .force_speed_100
= 1,
203 .force_duplex_full
= 1,
238 .default_trigger
= "default-on",
248 static struct board_info __initdata board_96348gw_11
= {
249 .name
= "96348GW-11",
250 .expected_cpu_id
= 0x6348,
258 .use_internal_phy
= 1,
262 .force_speed_100
= 1,
263 .force_duplex_full
= 1,
291 .default_trigger
= "default-on",
311 static struct board_info __initdata board_96348gw
= {
313 .expected_cpu_id
= 0x6348,
321 .use_internal_phy
= 1,
324 .force_speed_100
= 1,
325 .force_duplex_full
= 1,
348 .default_trigger
= "default-on",
392 static struct board_info __initdata board_FAST2404
= {
394 .expected_cpu_id
= 0x6348,
402 .use_internal_phy
= 1,
406 .force_speed_100
= 1,
407 .force_duplex_full
= 1,
416 static struct board_info __initdata board_DV201AMR
= {
418 .expected_cpu_id
= 0x6348,
428 .use_internal_phy
= 1,
431 .force_speed_100
= 1,
432 .force_duplex_full
= 1,
436 static struct board_info __initdata board_96348gw_a
= {
438 .expected_cpu_id
= 0x6348,
446 .use_internal_phy
= 1,
449 .force_speed_100
= 1,
450 .force_duplex_full
= 1,
456 static struct board_info __initdata board_rta1025w_16
= {
457 .name
= "RTA1025W_16",
458 .expected_cpu_id
= 0x6348,
466 .use_internal_phy
= 1,
469 .force_speed_100
= 1,
470 .force_duplex_full
= 1,
478 #ifdef CONFIG_BCM63XX_CPU_6358
479 static struct board_info __initdata board_96358vw
= {
481 .expected_cpu_id
= 0x6358,
489 .use_internal_phy
= 1,
493 .force_speed_100
= 1,
494 .force_duplex_full
= 1,
521 .default_trigger
= "default-on",
530 static struct board_info __initdata board_96358vw2
= {
532 .expected_cpu_id
= 0x6358,
540 .use_internal_phy
= 1,
544 .force_speed_100
= 1,
545 .force_duplex_full
= 1,
567 .default_trigger
= "default-on",
577 static struct board_info __initdata board_AGPFS0
= {
579 .expected_cpu_id
= 0x6358,
587 .use_internal_phy
= 1,
591 .force_speed_100
= 1,
592 .force_duplex_full
= 1,
599 /*Each led on alice gate is bi-color so final char */
600 /* is r for red and g for green leds */
610 .default_trigger
= "default-on",
654 /* sw1 is connected to gpio34*/
657 static struct board_info __initdata board_DWVS0
= {
659 .expected_cpu_id
= 0x6358,
667 .use_internal_phy
= 1,
671 .force_speed_100
= 1,
672 .force_duplex_full
= 1,
682 static const struct board_info __initdata
*bcm963xx_boards
[] = {
683 #ifdef CONFIG_BCM63XX_CPU_6338
687 #ifdef CONFIG_BCM63XX_CPU_6345
690 #ifdef CONFIG_BCM63XX_CPU_6348
701 #ifdef CONFIG_BCM63XX_CPU_6358
710 * early init callback, read nvram data from flash and checksum it
712 void __init
board_prom_init(void)
714 unsigned int check_len
, i
;
715 u8
*boot_addr
, *cfe
, *p
;
716 char cfe_version
[32];
719 /* read base address of boot chip select (0)
720 * 6345 does not have MPI but boots from standard
721 * MIPS Flash address */
722 if (BCMCPU_IS_6345())
725 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
726 val
&= MPI_CSBASE_BASE_MASK
;
728 boot_addr
= (u8
*)KSEG1ADDR(val
);
730 /* dump cfe version */
731 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
732 if (!memcmp(cfe
, "cfe-v", 5))
733 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
734 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
736 strcpy(cfe_version
, "unknown");
737 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
739 /* extract nvram data */
740 memcpy(&nvram
, boot_addr
+ BCM963XX_NVRAM_OFFSET
, sizeof(nvram
));
742 /* check checksum before using data */
743 if (nvram
.version
<= 4)
744 check_len
= offsetof(struct bcm963xx_nvram
, checksum_old
);
746 check_len
= sizeof(nvram
);
752 printk(KERN_ERR PFX
"invalid nvram checksum\n");
756 /* find board by name */
757 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
758 if (strncmp(nvram
.name
, bcm963xx_boards
[i
]->name
,
761 /* copy, board desc array is marked initdata */
762 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
766 /* bail out if board is not found, will complain later */
767 if (!board
.name
[0]) {
769 memcpy(name
, nvram
.name
, 16);
771 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
776 /* setup pin multiplexing depending on board enabled device,
777 * this has to be done this early since PCI init is done
778 * inside arch_initcall */
782 bcm63xx_pci_enabled
= 1;
783 if (BCMCPU_IS_6348())
784 val
|= GPIO_MODE_6348_G2_PCI
;
787 if (board
.has_pccard
) {
788 if (BCMCPU_IS_6348())
789 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
792 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
793 if (BCMCPU_IS_6348())
794 val
|= GPIO_MODE_6348_G3_EXT_MII
|
795 GPIO_MODE_6348_G0_EXT_MII
;
798 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
799 if (BCMCPU_IS_6348())
800 val
|= GPIO_MODE_6348_G3_EXT_MII
|
801 GPIO_MODE_6348_G0_EXT_MII
;
804 bcm_gpio_writel(val
, GPIO_MODE_REG
);
808 * second stage init callback, good time to panic if we couldn't
809 * identify on which board we're running since early printk is working
811 void __init
board_setup(void)
814 panic("unable to detect bcm963xx board");
815 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
817 /* make sure we're running on expected cpu */
818 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
819 panic("unexpected CPU for bcm963xx board");
823 * return board name for /proc/cpuinfo
825 const char *board_get_name(void)
831 * register & return a new board mac address
833 static int board_get_mac_address(u8
*mac
)
838 if (mac_addr_used
>= nvram
.mac_addr_count
) {
839 printk(KERN_ERR PFX
"not enough mac address\n");
843 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
844 p
= mac
+ ETH_ALEN
- 1;
845 count
= mac_addr_used
;
857 printk(KERN_ERR PFX
"unable to fetch mac address\n");
865 static struct resource mtd_resources
[] = {
867 .start
= 0, /* filled at runtime */
868 .end
= 0, /* filled at runtime */
869 .flags
= IORESOURCE_MEM
,
873 static struct platform_device mtd_dev
= {
874 .name
= "bcm963xx-flash",
875 .resource
= mtd_resources
,
876 .num_resources
= ARRAY_SIZE(mtd_resources
),
880 * Register a sane SPROMv2 to make the on-board
883 static struct ssb_sprom bcm63xx_sprom
= {
887 .ant_available_bg
= 0x3,
900 .boardflags_lo
= 0x2848,
901 .boardflags_hi
= 0x0000,
904 static struct resource gpiodev_resource
= {
908 static struct gpio_led_platform_data bcm63xx_led_data
;
910 static struct platform_device bcm63xx_gpio_leds
= {
913 .dev
.platform_data
= &bcm63xx_led_data
,
916 static struct gpio_buttons_platform_data bcm63xx_gpio_buttons_data
= {
920 static struct platform_device bcm63xx_gpio_buttons_device
= {
921 .name
= "gpio-buttons",
923 .dev
.platform_data
= &bcm63xx_gpio_buttons_data
,
928 * third stage init callback, register all board devices.
930 int __init
board_register_devices(void)
934 bcm63xx_uart_register();
935 bcm63xx_wdt_register();
937 if (!BCMCPU_IS_6345())
938 bcm63xx_spi_register();
940 if (board
.has_pccard
)
941 bcm63xx_pcmcia_register();
943 if (board
.has_enet0
&&
944 !board_get_mac_address(board
.enet0
.mac_addr
))
945 bcm63xx_enet_register(0, &board
.enet0
);
947 if (board
.has_enet1
&&
948 !board_get_mac_address(board
.enet1
.mac_addr
))
949 bcm63xx_enet_register(1, &board
.enet1
);
952 bcm63xx_ohci_register();
955 bcm63xx_ehci_register();
958 bcm63xx_udc_register();
961 bcm63xx_dsp_register(&board
.dsp
);
963 /* Generate MAC address for WLAN and
964 * register our SPROM */
966 if (!board_get_mac_address(bcm63xx_sprom
.il0mac
)) {
967 memcpy(bcm63xx_sprom
.et0mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
968 memcpy(bcm63xx_sprom
.et1mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
969 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom
) < 0)
970 printk(KERN_ERR
"failed to register fallback SPROM\n");
974 /* read base address of boot chip select (0) */
975 if (BCMCPU_IS_6345())
978 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
979 val
&= MPI_CSBASE_BASE_MASK
;
981 mtd_resources
[0].start
= val
;
982 mtd_resources
[0].end
= 0x1FFFFFFF;
984 platform_device_register(&mtd_dev
);
986 /* Register GPIODEV */
987 platform_device_register_simple("GPIODEV", 0, &gpiodev_resource
, 1);
989 bcm63xx_led_data
.num_leds
= ARRAY_SIZE(board
.leds
);
990 bcm63xx_led_data
.leds
= board
.leds
;
992 platform_device_register(&bcm63xx_gpio_leds
);
994 if (board
.reset_buttons
) {
995 bcm63xx_gpio_buttons_data
.nbuttons
= ARRAY_SIZE(board
.reset_buttons
);
996 bcm63xx_gpio_buttons_data
.buttons
= board
.reset_buttons
;
998 platform_device_register(&bcm63xx_gpio_buttons_device
);