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/ssb/ssb.h>
15 #include <asm/addrspace.h>
16 #include <bcm63xx_board.h>
17 #include <bcm63xx_cpu.h>
18 #include <bcm63xx_dev_uart.h>
19 #include <bcm63xx_regs.h>
20 #include <bcm63xx_io.h>
21 #include <bcm63xx_nvram.h>
22 #include <bcm63xx_dev_pci.h>
23 #include <bcm63xx_dev_enet.h>
24 #include <bcm63xx_dev_dsp.h>
25 #include <bcm63xx_dev_flash.h>
26 #include <bcm63xx_dev_pcmcia.h>
27 #include <bcm63xx_dev_spi.h>
28 #include <bcm63xx_dev_usb_usbd.h>
29 #include <board_bcm963xx.h>
31 #include <uapi/linux/bcm933xx_hcs.h>
33 #define PFX "board_bcm963xx: "
35 #define HCS_OFFSET_128K 0x20000
37 static struct board_info board
;
42 #ifdef CONFIG_BCM63XX_CPU_3368
43 static struct board_info __initdata board_cvg834g
= {
44 .name
= "CVG834G_E15R3921",
45 .expected_cpu_id
= 0x3368,
55 .use_internal_phy
= 1,
60 .name
= "CVG834G:green:power",
62 .default_trigger
= "default-on",
66 .ephy_reset_gpio
= 36,
67 .ephy_reset_gpio_flags
= GPIOF_INIT_HIGH
,
74 #ifdef CONFIG_BCM63XX_CPU_6328
75 static struct board_info __initdata board_96328avng
= {
77 .expected_cpu_id
= 0x6328,
90 .name
= "96328avng::ppp-fail",
95 .name
= "96328avng::power",
98 .default_trigger
= "default-on",
101 .name
= "96328avng::power-fail",
106 .name
= "96328avng::wps",
111 .name
= "96328avng::ppp",
122 #ifdef CONFIG_BCM63XX_CPU_6338
123 static struct board_info __initdata board_96338gw
= {
125 .expected_cpu_id
= 0x6338,
130 .force_speed_100
= 1,
131 .force_duplex_full
= 1,
156 .default_trigger
= "default-on",
166 static struct board_info __initdata board_96338w
= {
168 .expected_cpu_id
= 0x6338,
173 .force_speed_100
= 1,
174 .force_duplex_full
= 1,
197 .default_trigger
= "default-on",
211 #ifdef CONFIG_BCM63XX_CPU_6345
212 static struct board_info __initdata board_96345gw2
= {
214 .expected_cpu_id
= 0x6345,
223 #ifdef CONFIG_BCM63XX_CPU_6348
224 static struct board_info __initdata board_96348r
= {
226 .expected_cpu_id
= 0x6348,
234 .use_internal_phy
= 1,
257 .default_trigger
= "default-on",
268 static struct board_info __initdata board_96348gw_10
= {
269 .name
= "96348GW-10",
270 .expected_cpu_id
= 0x6348,
279 .use_internal_phy
= 1,
282 .force_speed_100
= 1,
283 .force_duplex_full
= 1,
318 .default_trigger
= "default-on",
328 static struct board_info __initdata board_96348gw_11
= {
329 .name
= "96348GW-11",
330 .expected_cpu_id
= 0x6348,
339 .use_internal_phy
= 1,
343 .force_speed_100
= 1,
344 .force_duplex_full
= 1,
372 .default_trigger
= "default-on",
382 static struct board_info __initdata board_96348gw
= {
384 .expected_cpu_id
= 0x6348,
393 .use_internal_phy
= 1,
396 .force_speed_100
= 1,
397 .force_duplex_full
= 1,
430 .default_trigger
= "default-on",
440 static struct board_info __initdata board_FAST2404
= {
442 .expected_cpu_id
= 0x6348,
451 .use_internal_phy
= 1,
455 .force_speed_100
= 1,
456 .force_duplex_full
= 1,
464 static struct board_info __initdata board_rta1025w_16
= {
465 .name
= "RTA1025W_16",
466 .expected_cpu_id
= 0x6348,
474 .use_internal_phy
= 1,
477 .force_speed_100
= 1,
478 .force_duplex_full
= 1,
483 static struct board_info __initdata board_DV201AMR
= {
485 .expected_cpu_id
= 0x6348,
495 .use_internal_phy
= 1,
498 .force_speed_100
= 1,
499 .force_duplex_full
= 1,
503 static struct board_info __initdata board_96348gw_a
= {
505 .expected_cpu_id
= 0x6348,
514 .use_internal_phy
= 1,
517 .force_speed_100
= 1,
518 .force_duplex_full
= 1,
528 #ifdef CONFIG_BCM63XX_CPU_6358
529 static struct board_info __initdata board_96358vw
= {
531 .expected_cpu_id
= 0x6358,
540 .use_internal_phy
= 1,
544 .force_speed_100
= 1,
545 .force_duplex_full
= 1,
572 .default_trigger
= "default-on",
581 static struct board_info __initdata board_96358vw2
= {
583 .expected_cpu_id
= 0x6358,
592 .use_internal_phy
= 1,
596 .force_speed_100
= 1,
597 .force_duplex_full
= 1,
619 .default_trigger
= "default-on",
629 static struct board_info __initdata board_AGPFS0
= {
631 .expected_cpu_id
= 0x6358,
640 .use_internal_phy
= 1,
644 .force_speed_100
= 1,
645 .force_duplex_full
= 1,
652 static struct board_info __initdata board_DWVS0
= {
654 .expected_cpu_id
= 0x6358,
662 .use_internal_phy
= 1,
666 .force_speed_100
= 1,
667 .force_duplex_full
= 1,
677 static const struct board_info __initconst
*bcm963xx_boards
[] = {
678 #ifdef CONFIG_BCM63XX_CPU_3368
681 #ifdef CONFIG_BCM63XX_CPU_6328
684 #ifdef CONFIG_BCM63XX_CPU_6338
688 #ifdef CONFIG_BCM63XX_CPU_6345
691 #ifdef CONFIG_BCM63XX_CPU_6348
702 #ifdef CONFIG_BCM63XX_CPU_6358
711 * Register a sane SPROMv2 to make the on-board
714 #ifdef CONFIG_SSB_PCIHOST
715 static struct ssb_sprom bcm63xx_sprom
= {
719 .ant_available_bg
= 0x3,
732 .boardflags_lo
= 0x2848,
733 .boardflags_hi
= 0x0000,
736 int bcm63xx_get_fallback_sprom(struct ssb_bus
*bus
, struct ssb_sprom
*out
)
738 if (bus
->bustype
== SSB_BUSTYPE_PCI
) {
739 memcpy(out
, &bcm63xx_sprom
, sizeof(struct ssb_sprom
));
742 printk(KERN_ERR PFX
"unable to fill SPROM for given bustype.\n");
749 * return board name for /proc/cpuinfo
751 const char *board_get_name(void)
757 * early init callback, read nvram data from flash and checksum it
759 void __init
board_prom_init(void)
763 char cfe_version
[32];
764 char *board_name
= NULL
;
768 /* read base address of boot chip select (0)
769 * 6328/6362 do not have MPI but boot from a fixed address
771 if (BCMCPU_IS_6328() || BCMCPU_IS_6362()) {
774 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
775 val
&= MPI_CSBASE_BASE_MASK
;
777 boot_addr
= (u8
*)KSEG1ADDR(val
);
779 /* dump cfe version */
780 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
781 if (!memcmp(cfe
, "cfe-v", 5))
782 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
783 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
785 strcpy(cfe_version
, "unknown");
786 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
788 bcm63xx_nvram_init(boot_addr
+ BCM963XX_NVRAM_OFFSET
);
790 if (BCMCPU_IS_3368()) {
791 hcs
= (struct bcm_hcs
*)boot_addr
;
792 board_name
= hcs
->filename
;
794 board_name
= bcm63xx_nvram_get_name();
796 /* find board by name */
797 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
798 if (strncmp(board_name
, bcm963xx_boards
[i
]->name
, 16))
800 /* copy, board desc array is marked initdata */
801 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
805 /* bail out if board is not found, will complain later */
806 if (!board
.name
[0]) {
808 memcpy(name
, board_name
, 16);
810 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
815 /* setup pin multiplexing depending on board enabled device,
816 * this has to be done this early since PCI init is done
817 * inside arch_initcall */
822 bcm63xx_pci_enabled
= 1;
823 if (BCMCPU_IS_6348())
824 val
|= GPIO_MODE_6348_G2_PCI
;
828 if (board
.has_pccard
) {
829 if (BCMCPU_IS_6348())
830 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
833 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
834 if (BCMCPU_IS_6348())
835 val
|= GPIO_MODE_6348_G3_EXT_MII
|
836 GPIO_MODE_6348_G0_EXT_MII
;
839 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
840 if (BCMCPU_IS_6348())
841 val
|= GPIO_MODE_6348_G3_EXT_MII
|
842 GPIO_MODE_6348_G0_EXT_MII
;
845 bcm_gpio_writel(val
, GPIO_MODE_REG
);
849 * second stage init callback, good time to panic if we couldn't
850 * identify on which board we're running since early printk is working
852 void __init
board_setup(void)
855 panic("unable to detect bcm963xx board");
856 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
858 /* make sure we're running on expected cpu */
859 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
860 panic("unexpected CPU for bcm963xx board");
863 static struct gpio_led_platform_data bcm63xx_led_data
;
865 static struct platform_device bcm63xx_gpio_leds
= {
868 .dev
.platform_data
= &bcm63xx_led_data
,
872 * third stage init callback, register all board devices.
874 int __init
board_register_devices(void)
877 bcm63xx_uart_register(0);
880 bcm63xx_uart_register(1);
882 if (board
.has_pccard
)
883 bcm63xx_pcmcia_register();
885 if (board
.has_enet0
&&
886 !bcm63xx_nvram_get_mac_address(board
.enet0
.mac_addr
))
887 bcm63xx_enet_register(0, &board
.enet0
);
889 if (board
.has_enet1
&&
890 !bcm63xx_nvram_get_mac_address(board
.enet1
.mac_addr
))
891 bcm63xx_enet_register(1, &board
.enet1
);
893 if (board
.has_enetsw
&&
894 !bcm63xx_nvram_get_mac_address(board
.enetsw
.mac_addr
))
895 bcm63xx_enetsw_register(&board
.enetsw
);
898 bcm63xx_usbd_register(&board
.usbd
);
901 bcm63xx_dsp_register(&board
.dsp
);
903 /* Generate MAC address for WLAN and register our SPROM,
904 * do this after registering enet devices
906 #ifdef CONFIG_SSB_PCIHOST
907 if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom
.il0mac
)) {
908 memcpy(bcm63xx_sprom
.et0mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
909 memcpy(bcm63xx_sprom
.et1mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
910 if (ssb_arch_register_fallback_sprom(
911 &bcm63xx_get_fallback_sprom
) < 0)
912 pr_err(PFX
"failed to register fallback SPROM\n");
916 bcm63xx_spi_register();
918 bcm63xx_flash_register();
920 bcm63xx_led_data
.num_leds
= ARRAY_SIZE(board
.leds
);
921 bcm63xx_led_data
.leds
= board
.leds
;
923 platform_device_register(&bcm63xx_gpio_leds
);
925 if (board
.ephy_reset_gpio
&& board
.ephy_reset_gpio_flags
)
926 gpio_request_one(board
.ephy_reset_gpio
,
927 board
.ephy_reset_gpio_flags
, "ephy-reset");