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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/string.h>
15 #include <linux/platform_device.h>
16 #include <linux/ssb/ssb.h>
17 #include <asm/addrspace.h>
18 #include <bcm63xx_board.h>
19 #include <bcm63xx_cpu.h>
20 #include <bcm63xx_dev_uart.h>
21 #include <bcm63xx_regs.h>
22 #include <bcm63xx_io.h>
23 #include <bcm63xx_nvram.h>
24 #include <bcm63xx_dev_pci.h>
25 #include <bcm63xx_dev_enet.h>
26 #include <bcm63xx_dev_dsp.h>
27 #include <bcm63xx_dev_flash.h>
28 #include <bcm63xx_dev_hsspi.h>
29 #include <bcm63xx_dev_pcmcia.h>
30 #include <bcm63xx_dev_spi.h>
31 #include <bcm63xx_dev_usb_usbd.h>
32 #include <board_bcm963xx.h>
34 #include <uapi/linux/bcm933xx_hcs.h>
37 #define HCS_OFFSET_128K 0x20000
39 static struct board_info board
;
44 #ifdef CONFIG_BCM63XX_CPU_3368
45 static struct board_info __initdata board_cvg834g
= {
46 .name
= "CVG834G_E15R3921",
47 .expected_cpu_id
= 0x3368,
57 .use_internal_phy
= 1,
62 .name
= "CVG834G:green:power",
64 .default_trigger
= "default-on",
68 .ephy_reset_gpio
= 36,
69 .ephy_reset_gpio_flags
= GPIOF_INIT_HIGH
,
76 #ifdef CONFIG_BCM63XX_CPU_6328
77 static struct board_info __initdata board_96328avng
= {
79 .expected_cpu_id
= 0x6328,
92 .name
= "96328avng::ppp-fail",
97 .name
= "96328avng::power",
100 .default_trigger
= "default-on",
103 .name
= "96328avng::power-fail",
108 .name
= "96328avng::wps",
113 .name
= "96328avng::ppp",
124 #ifdef CONFIG_BCM63XX_CPU_6338
125 static struct board_info __initdata board_96338gw
= {
127 .expected_cpu_id
= 0x6338,
132 .force_speed_100
= 1,
133 .force_duplex_full
= 1,
158 .default_trigger
= "default-on",
168 static struct board_info __initdata board_96338w
= {
170 .expected_cpu_id
= 0x6338,
175 .force_speed_100
= 1,
176 .force_duplex_full
= 1,
199 .default_trigger
= "default-on",
213 #ifdef CONFIG_BCM63XX_CPU_6345
214 static struct board_info __initdata board_96345gw2
= {
216 .expected_cpu_id
= 0x6345,
225 #ifdef CONFIG_BCM63XX_CPU_6348
226 static struct board_info __initdata board_96348r
= {
228 .expected_cpu_id
= 0x6348,
236 .use_internal_phy
= 1,
259 .default_trigger
= "default-on",
270 static struct board_info __initdata board_96348gw_10
= {
271 .name
= "96348GW-10",
272 .expected_cpu_id
= 0x6348,
281 .use_internal_phy
= 1,
284 .force_speed_100
= 1,
285 .force_duplex_full
= 1,
320 .default_trigger
= "default-on",
330 static struct board_info __initdata board_96348gw_11
= {
331 .name
= "96348GW-11",
332 .expected_cpu_id
= 0x6348,
341 .use_internal_phy
= 1,
345 .force_speed_100
= 1,
346 .force_duplex_full
= 1,
374 .default_trigger
= "default-on",
384 static struct board_info __initdata board_96348gw
= {
386 .expected_cpu_id
= 0x6348,
395 .use_internal_phy
= 1,
398 .force_speed_100
= 1,
399 .force_duplex_full
= 1,
432 .default_trigger
= "default-on",
442 static struct board_info __initdata board_FAST2404
= {
444 .expected_cpu_id
= 0x6348,
453 .use_internal_phy
= 1,
457 .force_speed_100
= 1,
458 .force_duplex_full
= 1,
466 static struct board_info __initdata board_rta1025w_16
= {
467 .name
= "RTA1025W_16",
468 .expected_cpu_id
= 0x6348,
476 .use_internal_phy
= 1,
479 .force_speed_100
= 1,
480 .force_duplex_full
= 1,
485 static struct board_info __initdata board_DV201AMR
= {
487 .expected_cpu_id
= 0x6348,
497 .use_internal_phy
= 1,
500 .force_speed_100
= 1,
501 .force_duplex_full
= 1,
505 static struct board_info __initdata board_96348gw_a
= {
507 .expected_cpu_id
= 0x6348,
516 .use_internal_phy
= 1,
519 .force_speed_100
= 1,
520 .force_duplex_full
= 1,
530 #ifdef CONFIG_BCM63XX_CPU_6358
531 static struct board_info __initdata board_96358vw
= {
533 .expected_cpu_id
= 0x6358,
542 .use_internal_phy
= 1,
546 .force_speed_100
= 1,
547 .force_duplex_full
= 1,
574 .default_trigger
= "default-on",
583 static struct board_info __initdata board_96358vw2
= {
585 .expected_cpu_id
= 0x6358,
594 .use_internal_phy
= 1,
598 .force_speed_100
= 1,
599 .force_duplex_full
= 1,
621 .default_trigger
= "default-on",
631 static struct board_info __initdata board_AGPFS0
= {
633 .expected_cpu_id
= 0x6358,
642 .use_internal_phy
= 1,
646 .force_speed_100
= 1,
647 .force_duplex_full
= 1,
654 static struct board_info __initdata board_DWVS0
= {
656 .expected_cpu_id
= 0x6358,
664 .use_internal_phy
= 1,
668 .force_speed_100
= 1,
669 .force_duplex_full
= 1,
679 static const struct board_info __initconst
*bcm963xx_boards
[] = {
680 #ifdef CONFIG_BCM63XX_CPU_3368
683 #ifdef CONFIG_BCM63XX_CPU_6328
686 #ifdef CONFIG_BCM63XX_CPU_6338
690 #ifdef CONFIG_BCM63XX_CPU_6345
693 #ifdef CONFIG_BCM63XX_CPU_6348
704 #ifdef CONFIG_BCM63XX_CPU_6358
713 * Register a sane SPROMv2 to make the on-board
716 #ifdef CONFIG_SSB_PCIHOST
717 static struct ssb_sprom bcm63xx_sprom
= {
721 .ant_available_bg
= 0x3,
734 .boardflags_lo
= 0x2848,
735 .boardflags_hi
= 0x0000,
738 int bcm63xx_get_fallback_sprom(struct ssb_bus
*bus
, struct ssb_sprom
*out
)
740 if (bus
->bustype
== SSB_BUSTYPE_PCI
) {
741 memcpy(out
, &bcm63xx_sprom
, sizeof(struct ssb_sprom
));
744 pr_err("unable to fill SPROM for given bustype\n");
751 * return board name for /proc/cpuinfo
753 const char *board_get_name(void)
759 * early init callback, read nvram data from flash and checksum it
761 void __init
board_prom_init(void)
765 char cfe_version
[32];
766 char *board_name
= NULL
;
770 /* read base address of boot chip select (0)
771 * 6328/6362 do not have MPI but boot from a fixed address
773 if (BCMCPU_IS_6328() || BCMCPU_IS_6362()) {
776 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
777 val
&= MPI_CSBASE_BASE_MASK
;
779 boot_addr
= (u8
*)KSEG1ADDR(val
);
781 /* dump cfe version */
782 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
783 if (!memcmp(cfe
, "cfe-v", 5))
784 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
785 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
787 strcpy(cfe_version
, "unknown");
788 pr_info("CFE version: %s\n", cfe_version
);
790 bcm63xx_nvram_init(boot_addr
+ BCM963XX_NVRAM_OFFSET
);
792 if (BCMCPU_IS_3368()) {
793 hcs
= (struct bcm_hcs
*)boot_addr
;
794 board_name
= hcs
->filename
;
796 board_name
= bcm63xx_nvram_get_name();
798 /* find board by name */
799 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
800 if (strncmp(board_name
, bcm963xx_boards
[i
]->name
, 16))
802 /* copy, board desc array is marked initdata */
803 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
807 /* bail out if board is not found, will complain later */
808 if (!board
.name
[0]) {
810 memcpy(name
, board_name
, 16);
812 pr_err("unknown bcm963xx board: %s\n", name
);
816 /* setup pin multiplexing depending on board enabled device,
817 * this has to be done this early since PCI init is done
818 * inside arch_initcall */
823 bcm63xx_pci_enabled
= 1;
824 if (BCMCPU_IS_6348())
825 val
|= GPIO_MODE_6348_G2_PCI
;
829 if (board
.has_pccard
) {
830 if (BCMCPU_IS_6348())
831 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
834 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
835 if (BCMCPU_IS_6348())
836 val
|= GPIO_MODE_6348_G3_EXT_MII
|
837 GPIO_MODE_6348_G0_EXT_MII
;
840 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
841 if (BCMCPU_IS_6348())
842 val
|= GPIO_MODE_6348_G3_EXT_MII
|
843 GPIO_MODE_6348_G0_EXT_MII
;
846 bcm_gpio_writel(val
, GPIO_MODE_REG
);
850 * second stage init callback, good time to panic if we couldn't
851 * identify on which board we're running since early printk is working
853 void __init
board_setup(void)
856 panic("unable to detect bcm963xx board");
857 pr_info("board name: %s\n", board
.name
);
859 /* make sure we're running on expected cpu */
860 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
861 panic("unexpected CPU for bcm963xx board");
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
,
873 * third stage init callback, register all board devices.
875 int __init
board_register_devices(void)
878 bcm63xx_uart_register(0);
881 bcm63xx_uart_register(1);
883 if (board
.has_pccard
)
884 bcm63xx_pcmcia_register();
886 if (board
.has_enet0
&&
887 !bcm63xx_nvram_get_mac_address(board
.enet0
.mac_addr
))
888 bcm63xx_enet_register(0, &board
.enet0
);
890 if (board
.has_enet1
&&
891 !bcm63xx_nvram_get_mac_address(board
.enet1
.mac_addr
))
892 bcm63xx_enet_register(1, &board
.enet1
);
894 if (board
.has_enetsw
&&
895 !bcm63xx_nvram_get_mac_address(board
.enetsw
.mac_addr
))
896 bcm63xx_enetsw_register(&board
.enetsw
);
899 bcm63xx_usbd_register(&board
.usbd
);
902 bcm63xx_dsp_register(&board
.dsp
);
904 /* Generate MAC address for WLAN and register our SPROM,
905 * do this after registering enet devices
907 #ifdef CONFIG_SSB_PCIHOST
908 if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom
.il0mac
)) {
909 memcpy(bcm63xx_sprom
.et0mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
910 memcpy(bcm63xx_sprom
.et1mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
911 if (ssb_arch_register_fallback_sprom(
912 &bcm63xx_get_fallback_sprom
) < 0)
913 pr_err("failed to register fallback SPROM\n");
917 bcm63xx_spi_register();
919 bcm63xx_hsspi_register();
921 bcm63xx_flash_register();
923 bcm63xx_led_data
.num_leds
= ARRAY_SIZE(board
.leds
);
924 bcm63xx_led_data
.leds
= board
.leds
;
926 platform_device_register(&bcm63xx_gpio_leds
);
928 if (board
.ephy_reset_gpio
&& board
.ephy_reset_gpio_flags
)
929 gpio_request_one(board
.ephy_reset_gpio
,
930 board
.ephy_reset_gpio_flags
, "ephy-reset");