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_hsspi.h>
27 #include <bcm63xx_dev_pcmcia.h>
28 #include <bcm63xx_dev_spi.h>
29 #include <bcm63xx_dev_usb_usbd.h>
30 #include <board_bcm963xx.h>
32 #include <uapi/linux/bcm933xx_hcs.h>
34 #define PFX "board_bcm963xx: "
36 #define HCS_OFFSET_128K 0x20000
38 static struct board_info board
;
43 #ifdef CONFIG_BCM63XX_CPU_3368
44 static struct board_info __initdata board_cvg834g
= {
45 .name
= "CVG834G_E15R3921",
46 .expected_cpu_id
= 0x3368,
56 .use_internal_phy
= 1,
61 .name
= "CVG834G:green:power",
63 .default_trigger
= "default-on",
67 .ephy_reset_gpio
= 36,
68 .ephy_reset_gpio_flags
= GPIOF_INIT_HIGH
,
75 #ifdef CONFIG_BCM63XX_CPU_6328
76 static struct board_info __initdata board_96328avng
= {
78 .expected_cpu_id
= 0x6328,
91 .name
= "96328avng::ppp-fail",
96 .name
= "96328avng::power",
99 .default_trigger
= "default-on",
102 .name
= "96328avng::power-fail",
107 .name
= "96328avng::wps",
112 .name
= "96328avng::ppp",
123 #ifdef CONFIG_BCM63XX_CPU_6338
124 static struct board_info __initdata board_96338gw
= {
126 .expected_cpu_id
= 0x6338,
131 .force_speed_100
= 1,
132 .force_duplex_full
= 1,
157 .default_trigger
= "default-on",
167 static struct board_info __initdata board_96338w
= {
169 .expected_cpu_id
= 0x6338,
174 .force_speed_100
= 1,
175 .force_duplex_full
= 1,
198 .default_trigger
= "default-on",
212 #ifdef CONFIG_BCM63XX_CPU_6345
213 static struct board_info __initdata board_96345gw2
= {
215 .expected_cpu_id
= 0x6345,
224 #ifdef CONFIG_BCM63XX_CPU_6348
225 static struct board_info __initdata board_96348r
= {
227 .expected_cpu_id
= 0x6348,
235 .use_internal_phy
= 1,
258 .default_trigger
= "default-on",
269 static struct board_info __initdata board_96348gw_10
= {
270 .name
= "96348GW-10",
271 .expected_cpu_id
= 0x6348,
280 .use_internal_phy
= 1,
283 .force_speed_100
= 1,
284 .force_duplex_full
= 1,
319 .default_trigger
= "default-on",
329 static struct board_info __initdata board_96348gw_11
= {
330 .name
= "96348GW-11",
331 .expected_cpu_id
= 0x6348,
340 .use_internal_phy
= 1,
344 .force_speed_100
= 1,
345 .force_duplex_full
= 1,
373 .default_trigger
= "default-on",
383 static struct board_info __initdata board_96348gw
= {
385 .expected_cpu_id
= 0x6348,
394 .use_internal_phy
= 1,
397 .force_speed_100
= 1,
398 .force_duplex_full
= 1,
431 .default_trigger
= "default-on",
441 static struct board_info __initdata board_FAST2404
= {
443 .expected_cpu_id
= 0x6348,
452 .use_internal_phy
= 1,
456 .force_speed_100
= 1,
457 .force_duplex_full
= 1,
465 static struct board_info __initdata board_rta1025w_16
= {
466 .name
= "RTA1025W_16",
467 .expected_cpu_id
= 0x6348,
475 .use_internal_phy
= 1,
478 .force_speed_100
= 1,
479 .force_duplex_full
= 1,
484 static struct board_info __initdata board_DV201AMR
= {
486 .expected_cpu_id
= 0x6348,
496 .use_internal_phy
= 1,
499 .force_speed_100
= 1,
500 .force_duplex_full
= 1,
504 static struct board_info __initdata board_96348gw_a
= {
506 .expected_cpu_id
= 0x6348,
515 .use_internal_phy
= 1,
518 .force_speed_100
= 1,
519 .force_duplex_full
= 1,
529 #ifdef CONFIG_BCM63XX_CPU_6358
530 static struct board_info __initdata board_96358vw
= {
532 .expected_cpu_id
= 0x6358,
541 .use_internal_phy
= 1,
545 .force_speed_100
= 1,
546 .force_duplex_full
= 1,
573 .default_trigger
= "default-on",
582 static struct board_info __initdata board_96358vw2
= {
584 .expected_cpu_id
= 0x6358,
593 .use_internal_phy
= 1,
597 .force_speed_100
= 1,
598 .force_duplex_full
= 1,
620 .default_trigger
= "default-on",
630 static struct board_info __initdata board_AGPFS0
= {
632 .expected_cpu_id
= 0x6358,
641 .use_internal_phy
= 1,
645 .force_speed_100
= 1,
646 .force_duplex_full
= 1,
653 static struct board_info __initdata board_DWVS0
= {
655 .expected_cpu_id
= 0x6358,
663 .use_internal_phy
= 1,
667 .force_speed_100
= 1,
668 .force_duplex_full
= 1,
678 static const struct board_info __initconst
*bcm963xx_boards
[] = {
679 #ifdef CONFIG_BCM63XX_CPU_3368
682 #ifdef CONFIG_BCM63XX_CPU_6328
685 #ifdef CONFIG_BCM63XX_CPU_6338
689 #ifdef CONFIG_BCM63XX_CPU_6345
692 #ifdef CONFIG_BCM63XX_CPU_6348
703 #ifdef CONFIG_BCM63XX_CPU_6358
712 * Register a sane SPROMv2 to make the on-board
715 #ifdef CONFIG_SSB_PCIHOST
716 static struct ssb_sprom bcm63xx_sprom
= {
720 .ant_available_bg
= 0x3,
733 .boardflags_lo
= 0x2848,
734 .boardflags_hi
= 0x0000,
737 int bcm63xx_get_fallback_sprom(struct ssb_bus
*bus
, struct ssb_sprom
*out
)
739 if (bus
->bustype
== SSB_BUSTYPE_PCI
) {
740 memcpy(out
, &bcm63xx_sprom
, sizeof(struct ssb_sprom
));
743 printk(KERN_ERR PFX
"unable to fill SPROM for given bustype.\n");
750 * return board name for /proc/cpuinfo
752 const char *board_get_name(void)
758 * early init callback, read nvram data from flash and checksum it
760 void __init
board_prom_init(void)
764 char cfe_version
[32];
765 char *board_name
= NULL
;
769 /* read base address of boot chip select (0)
770 * 6328/6362 do not have MPI but boot from a fixed address
772 if (BCMCPU_IS_6328() || BCMCPU_IS_6362()) {
775 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
776 val
&= MPI_CSBASE_BASE_MASK
;
778 boot_addr
= (u8
*)KSEG1ADDR(val
);
780 /* dump cfe version */
781 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
782 if (!memcmp(cfe
, "cfe-v", 5))
783 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
784 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
786 strcpy(cfe_version
, "unknown");
787 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
789 bcm63xx_nvram_init(boot_addr
+ BCM963XX_NVRAM_OFFSET
);
791 if (BCMCPU_IS_3368()) {
792 hcs
= (struct bcm_hcs
*)boot_addr
;
793 board_name
= hcs
->filename
;
795 board_name
= bcm63xx_nvram_get_name();
797 /* find board by name */
798 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
799 if (strncmp(board_name
, bcm963xx_boards
[i
]->name
, 16))
801 /* copy, board desc array is marked initdata */
802 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
806 /* bail out if board is not found, will complain later */
807 if (!board
.name
[0]) {
809 memcpy(name
, board_name
, 16);
811 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
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 printk(KERN_INFO PFX
"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(PFX
"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");