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_dev_pci.h>
22 #include <bcm63xx_dev_enet.h>
23 #include <bcm63xx_dev_dsp.h>
24 #include <bcm63xx_dev_flash.h>
25 #include <bcm63xx_dev_pcmcia.h>
26 #include <bcm63xx_dev_spi.h>
27 #include <board_bcm963xx.h>
29 #define PFX "board_bcm963xx: "
31 static struct bcm963xx_nvram nvram;
32 static unsigned int mac_addr_used;
33 static struct board_info board;
38 #ifdef CONFIG_BCM63XX_CPU_6328
39 static struct board_info __initdata board_96328avng = {
41 .expected_cpu_id = 0x6328,
48 .name = "96328avng::ppp-fail",
53 .name = "96328avng::power",
56 .default_trigger = "default-on",
59 .name = "96328avng::power-fail",
64 .name = "96328avng::wps",
69 .name = "96328avng::ppp",
80 #ifdef CONFIG_BCM63XX_CPU_6338
81 static struct board_info __initdata board_96338gw = {
83 .expected_cpu_id = 0x6338,
89 .force_duplex_full = 1,
114 .default_trigger = "default-on",
124 static struct board_info __initdata board_96338w = {
126 .expected_cpu_id = 0x6338,
131 .force_speed_100 = 1,
132 .force_duplex_full = 1,
155 .default_trigger = "default-on",
169 #ifdef CONFIG_BCM63XX_CPU_6345
170 static struct board_info __initdata board_96345gw2 = {
172 .expected_cpu_id = 0x6345,
181 #ifdef CONFIG_BCM63XX_CPU_6348
182 static struct board_info __initdata board_96348r = {
184 .expected_cpu_id = 0x6348,
192 .use_internal_phy = 1,
215 .default_trigger = "default-on",
226 static struct board_info __initdata board_96348gw_10 = {
227 .name = "96348GW-10",
228 .expected_cpu_id = 0x6348,
237 .use_internal_phy = 1,
240 .force_speed_100 = 1,
241 .force_duplex_full = 1,
276 .default_trigger = "default-on",
286 static struct board_info __initdata board_96348gw_11 = {
287 .name = "96348GW-11",
288 .expected_cpu_id = 0x6348,
297 .use_internal_phy = 1,
301 .force_speed_100 = 1,
302 .force_duplex_full = 1,
330 .default_trigger = "default-on",
340 static struct board_info __initdata board_96348gw = {
342 .expected_cpu_id = 0x6348,
351 .use_internal_phy = 1,
354 .force_speed_100 = 1,
355 .force_duplex_full = 1,
388 .default_trigger = "default-on",
398 static struct board_info __initdata board_FAST2404 = {
400 .expected_cpu_id = 0x6348,
409 .use_internal_phy = 1,
413 .force_speed_100 = 1,
414 .force_duplex_full = 1,
422 static struct board_info __initdata board_rta1025w_16 = {
423 .name = "RTA1025W_16",
424 .expected_cpu_id = 0x6348,
432 .use_internal_phy = 1,
435 .force_speed_100 = 1,
436 .force_duplex_full = 1,
441 static struct board_info __initdata board_DV201AMR = {
443 .expected_cpu_id = 0x6348,
453 .use_internal_phy = 1,
456 .force_speed_100 = 1,
457 .force_duplex_full = 1,
461 static struct board_info __initdata board_96348gw_a = {
463 .expected_cpu_id = 0x6348,
472 .use_internal_phy = 1,
475 .force_speed_100 = 1,
476 .force_duplex_full = 1,
486 #ifdef CONFIG_BCM63XX_CPU_6358
487 static struct board_info __initdata board_96358vw = {
489 .expected_cpu_id = 0x6358,
498 .use_internal_phy = 1,
502 .force_speed_100 = 1,
503 .force_duplex_full = 1,
530 .default_trigger = "default-on",
539 static struct board_info __initdata board_96358vw2 = {
541 .expected_cpu_id = 0x6358,
550 .use_internal_phy = 1,
554 .force_speed_100 = 1,
555 .force_duplex_full = 1,
577 .default_trigger = "default-on",
587 static struct board_info __initdata board_AGPFS0 = {
589 .expected_cpu_id = 0x6358,
598 .use_internal_phy = 1,
602 .force_speed_100 = 1,
603 .force_duplex_full = 1,
610 static struct board_info __initdata board_DWVS0 = {
612 .expected_cpu_id = 0x6358,
620 .use_internal_phy = 1,
624 .force_speed_100 = 1,
625 .force_duplex_full = 1,
635 static const struct board_info __initdata *bcm963xx_boards[] = {
636 #ifdef CONFIG_BCM63XX_CPU_6328
639 #ifdef CONFIG_BCM63XX_CPU_6338
643 #ifdef CONFIG_BCM63XX_CPU_6345
646 #ifdef CONFIG_BCM63XX_CPU_6348
657 #ifdef CONFIG_BCM63XX_CPU_6358
666 * Register a sane SPROMv2 to make the on-board
669 #ifdef CONFIG_SSB_PCIHOST
670 static struct ssb_sprom bcm63xx_sprom = {
674 .ant_available_bg = 0x3,
687 .boardflags_lo = 0x2848,
688 .boardflags_hi = 0x0000,
691 int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
693 if (bus->bustype == SSB_BUSTYPE_PCI) {
694 memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
697 printk(KERN_ERR PFX "unable to fill SPROM for given bustype.\n");
704 * return board name for /proc/cpuinfo
706 const char *board_get_name(void)
712 * register & return a new board mac address
714 static int board_get_mac_address(u8 *mac)
719 if (mac_addr_used >= nvram.mac_addr_count) {
720 printk(KERN_ERR PFX "not enough mac address\n");
724 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
725 p = mac + ETH_ALEN - 1;
726 count = mac_addr_used;
738 printk(KERN_ERR PFX "unable to fetch mac address\n");
747 * early init callback, read nvram data from flash and checksum it
749 void __init board_prom_init(void)
751 unsigned int check_len, i;
752 u8 *boot_addr, *cfe, *p;
753 char cfe_version[32];
756 /* read base address of boot chip select (0)
757 * 6328 does not have MPI but boots from a fixed address
759 if (BCMCPU_IS_6328())
762 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
763 val &= MPI_CSBASE_BASE_MASK;
765 boot_addr = (u8 *)KSEG1ADDR(val);
767 /* dump cfe version */
768 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
769 if (!memcmp(cfe, "cfe-v", 5))
770 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
771 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
773 strcpy(cfe_version, "unknown");
774 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
776 /* extract nvram data */
777 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
779 /* check checksum before using data */
780 if (nvram.version <= 4)
781 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
783 check_len = sizeof(nvram);
789 printk(KERN_ERR PFX "invalid nvram checksum\n");
793 /* find board by name */
794 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
795 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
798 /* copy, board desc array is marked initdata */
799 memcpy(&board, bcm963xx_boards[i], sizeof(board));
803 /* bail out if board is not found, will complain later */
804 if (!board.name[0]) {
806 memcpy(name, nvram.name, 16);
808 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
813 /* setup pin multiplexing depending on board enabled device,
814 * this has to be done this early since PCI init is done
815 * inside arch_initcall */
820 bcm63xx_pci_enabled = 1;
821 if (BCMCPU_IS_6348())
822 val |= GPIO_MODE_6348_G2_PCI;
826 if (board.has_pccard) {
827 if (BCMCPU_IS_6348())
828 val |= GPIO_MODE_6348_G1_MII_PCCARD;
831 if (board.has_enet0 && !board.enet0.use_internal_phy) {
832 if (BCMCPU_IS_6348())
833 val |= GPIO_MODE_6348_G3_EXT_MII |
834 GPIO_MODE_6348_G0_EXT_MII;
837 if (board.has_enet1 && !board.enet1.use_internal_phy) {
838 if (BCMCPU_IS_6348())
839 val |= GPIO_MODE_6348_G3_EXT_MII |
840 GPIO_MODE_6348_G0_EXT_MII;
843 bcm_gpio_writel(val, GPIO_MODE_REG);
847 * second stage init callback, good time to panic if we couldn't
848 * identify on which board we're running since early printk is working
850 void __init board_setup(void)
853 panic("unable to detect bcm963xx board");
854 printk(KERN_INFO PFX "board name: %s\n", board.name);
856 /* make sure we're running on expected cpu */
857 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
858 panic("unexpected CPU for bcm963xx board");
861 static struct gpio_led_platform_data bcm63xx_led_data;
863 static struct platform_device bcm63xx_gpio_leds = {
866 .dev.platform_data = &bcm63xx_led_data,
870 * third stage init callback, register all board devices.
872 int __init board_register_devices(void)
875 bcm63xx_uart_register(0);
878 bcm63xx_uart_register(1);
880 if (board.has_pccard)
881 bcm63xx_pcmcia_register();
883 if (board.has_enet0 &&
884 !board_get_mac_address(board.enet0.mac_addr))
885 bcm63xx_enet_register(0, &board.enet0);
887 if (board.has_enet1 &&
888 !board_get_mac_address(board.enet1.mac_addr))
889 bcm63xx_enet_register(1, &board.enet1);
892 bcm63xx_dsp_register(&board.dsp);
894 /* Generate MAC address for WLAN and register our SPROM,
895 * do this after registering enet devices
897 #ifdef CONFIG_SSB_PCIHOST
898 if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
899 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
900 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
901 if (ssb_arch_register_fallback_sprom(
902 &bcm63xx_get_fallback_sprom) < 0)
903 pr_err(PFX "failed to register fallback SPROM\n");
907 bcm63xx_spi_register();
909 bcm63xx_flash_register();
911 bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
912 bcm63xx_led_data.leds = board.leds;
914 platform_device_register(&bcm63xx_gpio_leds);