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_6328
43 static struct board_info __initdata board_96328avng = {
45 .expected_cpu_id = 0x6328,
58 .name = "96328avng::ppp-fail",
63 .name = "96328avng::power",
66 .default_trigger = "default-on",
69 .name = "96328avng::power-fail",
74 .name = "96328avng::wps",
79 .name = "96328avng::ppp",
90 #ifdef CONFIG_BCM63XX_CPU_6338
91 static struct board_info __initdata board_96338gw = {
93 .expected_cpu_id = 0x6338,
99 .force_duplex_full = 1,
124 .default_trigger = "default-on",
134 static struct board_info __initdata board_96338w = {
136 .expected_cpu_id = 0x6338,
141 .force_speed_100 = 1,
142 .force_duplex_full = 1,
165 .default_trigger = "default-on",
179 #ifdef CONFIG_BCM63XX_CPU_6345
180 static struct board_info __initdata board_96345gw2 = {
182 .expected_cpu_id = 0x6345,
191 #ifdef CONFIG_BCM63XX_CPU_6348
192 static struct board_info __initdata board_96348r = {
194 .expected_cpu_id = 0x6348,
202 .use_internal_phy = 1,
225 .default_trigger = "default-on",
236 static struct board_info __initdata board_96348gw_10 = {
237 .name = "96348GW-10",
238 .expected_cpu_id = 0x6348,
247 .use_internal_phy = 1,
250 .force_speed_100 = 1,
251 .force_duplex_full = 1,
286 .default_trigger = "default-on",
296 static struct board_info __initdata board_96348gw_11 = {
297 .name = "96348GW-11",
298 .expected_cpu_id = 0x6348,
307 .use_internal_phy = 1,
311 .force_speed_100 = 1,
312 .force_duplex_full = 1,
340 .default_trigger = "default-on",
350 static struct board_info __initdata board_96348gw = {
352 .expected_cpu_id = 0x6348,
361 .use_internal_phy = 1,
364 .force_speed_100 = 1,
365 .force_duplex_full = 1,
398 .default_trigger = "default-on",
408 static struct board_info __initdata board_FAST2404 = {
410 .expected_cpu_id = 0x6348,
419 .use_internal_phy = 1,
423 .force_speed_100 = 1,
424 .force_duplex_full = 1,
432 static struct board_info __initdata board_rta1025w_16 = {
433 .name = "RTA1025W_16",
434 .expected_cpu_id = 0x6348,
442 .use_internal_phy = 1,
445 .force_speed_100 = 1,
446 .force_duplex_full = 1,
451 static struct board_info __initdata board_DV201AMR = {
453 .expected_cpu_id = 0x6348,
463 .use_internal_phy = 1,
466 .force_speed_100 = 1,
467 .force_duplex_full = 1,
471 static struct board_info __initdata board_96348gw_a = {
473 .expected_cpu_id = 0x6348,
482 .use_internal_phy = 1,
485 .force_speed_100 = 1,
486 .force_duplex_full = 1,
496 #ifdef CONFIG_BCM63XX_CPU_6358
497 static struct board_info __initdata board_96358vw = {
499 .expected_cpu_id = 0x6358,
508 .use_internal_phy = 1,
512 .force_speed_100 = 1,
513 .force_duplex_full = 1,
540 .default_trigger = "default-on",
549 static struct board_info __initdata board_96358vw2 = {
551 .expected_cpu_id = 0x6358,
560 .use_internal_phy = 1,
564 .force_speed_100 = 1,
565 .force_duplex_full = 1,
587 .default_trigger = "default-on",
597 static struct board_info __initdata board_AGPFS0 = {
599 .expected_cpu_id = 0x6358,
608 .use_internal_phy = 1,
612 .force_speed_100 = 1,
613 .force_duplex_full = 1,
620 static struct board_info __initdata board_DWVS0 = {
622 .expected_cpu_id = 0x6358,
630 .use_internal_phy = 1,
634 .force_speed_100 = 1,
635 .force_duplex_full = 1,
645 static const struct board_info __initconst *bcm963xx_boards[] = {
646 #ifdef CONFIG_BCM63XX_CPU_6328
649 #ifdef CONFIG_BCM63XX_CPU_6338
653 #ifdef CONFIG_BCM63XX_CPU_6345
656 #ifdef CONFIG_BCM63XX_CPU_6348
667 #ifdef CONFIG_BCM63XX_CPU_6358
676 * Register a sane SPROMv2 to make the on-board
679 #ifdef CONFIG_SSB_PCIHOST
680 static struct ssb_sprom bcm63xx_sprom = {
684 .ant_available_bg = 0x3,
697 .boardflags_lo = 0x2848,
698 .boardflags_hi = 0x0000,
701 int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
703 if (bus->bustype == SSB_BUSTYPE_PCI) {
704 memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
707 printk(KERN_ERR PFX "unable to fill SPROM for given bustype.\n");
714 * return board name for /proc/cpuinfo
716 const char *board_get_name(void)
722 * early init callback, read nvram data from flash and checksum it
724 void __init board_prom_init(void)
728 char cfe_version[32];
729 char *board_name = NULL;
733 /* read base address of boot chip select (0)
734 * 6328/6362 do not have MPI but boot from a fixed address
736 if (BCMCPU_IS_6328() || BCMCPU_IS_6362()) {
739 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
740 val &= MPI_CSBASE_BASE_MASK;
742 boot_addr = (u8 *)KSEG1ADDR(val);
744 /* dump cfe version */
745 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
746 if (!memcmp(cfe, "cfe-v", 5))
747 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
748 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
750 strcpy(cfe_version, "unknown");
751 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
753 bcm63xx_nvram_init(boot_addr + BCM963XX_NVRAM_OFFSET);
755 if (BCMCPU_IS_3368()) {
756 hcs = (struct bcm_hcs *)boot_addr;
757 board_name = hcs->filename;
759 board_name = bcm63xx_nvram_get_name();
761 /* find board by name */
762 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
763 if (strncmp(board_name, bcm963xx_boards[i]->name, 16))
765 /* copy, board desc array is marked initdata */
766 memcpy(&board, bcm963xx_boards[i], sizeof(board));
770 /* bail out if board is not found, will complain later */
771 if (!board.name[0]) {
773 memcpy(name, board_name, 16);
775 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
780 /* setup pin multiplexing depending on board enabled device,
781 * this has to be done this early since PCI init is done
782 * inside arch_initcall */
787 bcm63xx_pci_enabled = 1;
788 if (BCMCPU_IS_6348())
789 val |= GPIO_MODE_6348_G2_PCI;
793 if (board.has_pccard) {
794 if (BCMCPU_IS_6348())
795 val |= GPIO_MODE_6348_G1_MII_PCCARD;
798 if (board.has_enet0 && !board.enet0.use_internal_phy) {
799 if (BCMCPU_IS_6348())
800 val |= GPIO_MODE_6348_G3_EXT_MII |
801 GPIO_MODE_6348_G0_EXT_MII;
804 if (board.has_enet1 && !board.enet1.use_internal_phy) {
805 if (BCMCPU_IS_6348())
806 val |= GPIO_MODE_6348_G3_EXT_MII |
807 GPIO_MODE_6348_G0_EXT_MII;
810 bcm_gpio_writel(val, GPIO_MODE_REG);
814 * second stage init callback, good time to panic if we couldn't
815 * identify on which board we're running since early printk is working
817 void __init board_setup(void)
820 panic("unable to detect bcm963xx board");
821 printk(KERN_INFO PFX "board name: %s\n", board.name);
823 /* make sure we're running on expected cpu */
824 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
825 panic("unexpected CPU for bcm963xx board");
828 static struct gpio_led_platform_data bcm63xx_led_data;
830 static struct platform_device bcm63xx_gpio_leds = {
833 .dev.platform_data = &bcm63xx_led_data,
837 * third stage init callback, register all board devices.
839 int __init board_register_devices(void)
842 bcm63xx_uart_register(0);
845 bcm63xx_uart_register(1);
847 if (board.has_pccard)
848 bcm63xx_pcmcia_register();
850 if (board.has_enet0 &&
851 !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
852 bcm63xx_enet_register(0, &board.enet0);
854 if (board.has_enet1 &&
855 !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
856 bcm63xx_enet_register(1, &board.enet1);
859 bcm63xx_usbd_register(&board.usbd);
862 bcm63xx_dsp_register(&board.dsp);
864 /* Generate MAC address for WLAN and register our SPROM,
865 * do this after registering enet devices
867 #ifdef CONFIG_SSB_PCIHOST
868 if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
869 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
870 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
871 if (ssb_arch_register_fallback_sprom(
872 &bcm63xx_get_fallback_sprom) < 0)
873 pr_err(PFX "failed to register fallback SPROM\n");
877 bcm63xx_spi_register();
879 bcm63xx_flash_register();
881 bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
882 bcm63xx_led_data.leds = board.leds;
884 platform_device_register(&bcm63xx_gpio_leds);
886 if (board.ephy_reset_gpio && board.ephy_reset_gpio_flags)
887 gpio_request_one(board.ephy_reset_gpio,
888 board.ephy_reset_gpio_flags, "ephy-reset");