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 <bcm63xx_dev_usb_usbd.h>
28 #include <board_bcm963xx.h>
30 #define PFX "board_bcm963xx: "
32 static struct bcm963xx_nvram nvram;
33 static unsigned int mac_addr_used;
34 static struct board_info board;
39 #ifdef CONFIG_BCM63XX_CPU_6328
40 static struct board_info __initdata board_96328avng = {
42 .expected_cpu_id = 0x6328,
55 .name = "96328avng::ppp-fail",
60 .name = "96328avng::power",
63 .default_trigger = "default-on",
66 .name = "96328avng::power-fail",
71 .name = "96328avng::wps",
76 .name = "96328avng::ppp",
87 #ifdef CONFIG_BCM63XX_CPU_6338
88 static struct board_info __initdata board_96338gw = {
90 .expected_cpu_id = 0x6338,
96 .force_duplex_full = 1,
121 .default_trigger = "default-on",
131 static struct board_info __initdata board_96338w = {
133 .expected_cpu_id = 0x6338,
138 .force_speed_100 = 1,
139 .force_duplex_full = 1,
162 .default_trigger = "default-on",
176 #ifdef CONFIG_BCM63XX_CPU_6345
177 static struct board_info __initdata board_96345gw2 = {
179 .expected_cpu_id = 0x6345,
188 #ifdef CONFIG_BCM63XX_CPU_6348
189 static struct board_info __initdata board_96348r = {
191 .expected_cpu_id = 0x6348,
199 .use_internal_phy = 1,
222 .default_trigger = "default-on",
233 static struct board_info __initdata board_96348gw_10 = {
234 .name = "96348GW-10",
235 .expected_cpu_id = 0x6348,
244 .use_internal_phy = 1,
247 .force_speed_100 = 1,
248 .force_duplex_full = 1,
283 .default_trigger = "default-on",
293 static struct board_info __initdata board_96348gw_11 = {
294 .name = "96348GW-11",
295 .expected_cpu_id = 0x6348,
304 .use_internal_phy = 1,
308 .force_speed_100 = 1,
309 .force_duplex_full = 1,
337 .default_trigger = "default-on",
347 static struct board_info __initdata board_96348gw = {
349 .expected_cpu_id = 0x6348,
358 .use_internal_phy = 1,
361 .force_speed_100 = 1,
362 .force_duplex_full = 1,
395 .default_trigger = "default-on",
405 static struct board_info __initdata board_FAST2404 = {
407 .expected_cpu_id = 0x6348,
416 .use_internal_phy = 1,
420 .force_speed_100 = 1,
421 .force_duplex_full = 1,
429 static struct board_info __initdata board_rta1025w_16 = {
430 .name = "RTA1025W_16",
431 .expected_cpu_id = 0x6348,
439 .use_internal_phy = 1,
442 .force_speed_100 = 1,
443 .force_duplex_full = 1,
448 static struct board_info __initdata board_DV201AMR = {
450 .expected_cpu_id = 0x6348,
460 .use_internal_phy = 1,
463 .force_speed_100 = 1,
464 .force_duplex_full = 1,
468 static struct board_info __initdata board_96348gw_a = {
470 .expected_cpu_id = 0x6348,
479 .use_internal_phy = 1,
482 .force_speed_100 = 1,
483 .force_duplex_full = 1,
493 #ifdef CONFIG_BCM63XX_CPU_6358
494 static struct board_info __initdata board_96358vw = {
496 .expected_cpu_id = 0x6358,
505 .use_internal_phy = 1,
509 .force_speed_100 = 1,
510 .force_duplex_full = 1,
537 .default_trigger = "default-on",
546 static struct board_info __initdata board_96358vw2 = {
548 .expected_cpu_id = 0x6358,
557 .use_internal_phy = 1,
561 .force_speed_100 = 1,
562 .force_duplex_full = 1,
584 .default_trigger = "default-on",
594 static struct board_info __initdata board_AGPFS0 = {
596 .expected_cpu_id = 0x6358,
605 .use_internal_phy = 1,
609 .force_speed_100 = 1,
610 .force_duplex_full = 1,
617 static struct board_info __initdata board_DWVS0 = {
619 .expected_cpu_id = 0x6358,
627 .use_internal_phy = 1,
631 .force_speed_100 = 1,
632 .force_duplex_full = 1,
642 static const struct board_info __initconst *bcm963xx_boards[] = {
643 #ifdef CONFIG_BCM63XX_CPU_6328
646 #ifdef CONFIG_BCM63XX_CPU_6338
650 #ifdef CONFIG_BCM63XX_CPU_6345
653 #ifdef CONFIG_BCM63XX_CPU_6348
664 #ifdef CONFIG_BCM63XX_CPU_6358
673 * Register a sane SPROMv2 to make the on-board
676 #ifdef CONFIG_SSB_PCIHOST
677 static struct ssb_sprom bcm63xx_sprom = {
681 .ant_available_bg = 0x3,
694 .boardflags_lo = 0x2848,
695 .boardflags_hi = 0x0000,
698 int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
700 if (bus->bustype == SSB_BUSTYPE_PCI) {
701 memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
704 printk(KERN_ERR PFX "unable to fill SPROM for given bustype.\n");
711 * return board name for /proc/cpuinfo
713 const char *board_get_name(void)
719 * register & return a new board mac address
721 static int board_get_mac_address(u8 *mac)
726 if (mac_addr_used >= nvram.mac_addr_count) {
727 printk(KERN_ERR PFX "not enough mac address\n");
731 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
732 oui = mac + ETH_ALEN/2 - 1;
733 count = mac_addr_used;
736 u8 *p = mac + ETH_ALEN - 1;
746 printk(KERN_ERR PFX "unable to fetch mac address\n");
756 * early init callback, read nvram data from flash and checksum it
758 void __init board_prom_init(void)
760 unsigned int check_len, i;
761 u8 *boot_addr, *cfe, *p;
762 char cfe_version[32];
765 /* read base address of boot chip select (0)
766 * 6328 does not have MPI but boots from a fixed address
768 if (BCMCPU_IS_6328())
771 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
772 val &= MPI_CSBASE_BASE_MASK;
774 boot_addr = (u8 *)KSEG1ADDR(val);
776 /* dump cfe version */
777 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
778 if (!memcmp(cfe, "cfe-v", 5))
779 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
780 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
782 strcpy(cfe_version, "unknown");
783 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
785 /* extract nvram data */
786 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
788 /* check checksum before using data */
789 if (nvram.version <= 4)
790 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
792 check_len = sizeof(nvram);
798 printk(KERN_ERR PFX "invalid nvram checksum\n");
802 /* find board by name */
803 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
804 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
807 /* copy, board desc array is marked initdata */
808 memcpy(&board, bcm963xx_boards[i], sizeof(board));
812 /* bail out if board is not found, will complain later */
813 if (!board.name[0]) {
815 memcpy(name, nvram.name, 16);
817 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
822 /* setup pin multiplexing depending on board enabled device,
823 * this has to be done this early since PCI init is done
824 * inside arch_initcall */
829 bcm63xx_pci_enabled = 1;
830 if (BCMCPU_IS_6348())
831 val |= GPIO_MODE_6348_G2_PCI;
835 if (board.has_pccard) {
836 if (BCMCPU_IS_6348())
837 val |= GPIO_MODE_6348_G1_MII_PCCARD;
840 if (board.has_enet0 && !board.enet0.use_internal_phy) {
841 if (BCMCPU_IS_6348())
842 val |= GPIO_MODE_6348_G3_EXT_MII |
843 GPIO_MODE_6348_G0_EXT_MII;
846 if (board.has_enet1 && !board.enet1.use_internal_phy) {
847 if (BCMCPU_IS_6348())
848 val |= GPIO_MODE_6348_G3_EXT_MII |
849 GPIO_MODE_6348_G0_EXT_MII;
852 bcm_gpio_writel(val, GPIO_MODE_REG);
856 * second stage init callback, good time to panic if we couldn't
857 * identify on which board we're running since early printk is working
859 void __init board_setup(void)
862 panic("unable to detect bcm963xx board");
863 printk(KERN_INFO PFX "board name: %s\n", board.name);
865 /* make sure we're running on expected cpu */
866 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
867 panic("unexpected CPU for bcm963xx board");
870 static struct gpio_led_platform_data bcm63xx_led_data;
872 static struct platform_device bcm63xx_gpio_leds = {
875 .dev.platform_data = &bcm63xx_led_data,
879 * third stage init callback, register all board devices.
881 int __init board_register_devices(void)
884 bcm63xx_uart_register(0);
887 bcm63xx_uart_register(1);
889 if (board.has_pccard)
890 bcm63xx_pcmcia_register();
892 if (board.has_enet0 &&
893 !board_get_mac_address(board.enet0.mac_addr))
894 bcm63xx_enet_register(0, &board.enet0);
896 if (board.has_enet1 &&
897 !board_get_mac_address(board.enet1.mac_addr))
898 bcm63xx_enet_register(1, &board.enet1);
901 bcm63xx_usbd_register(&board.usbd);
904 bcm63xx_dsp_register(&board.dsp);
906 /* Generate MAC address for WLAN and register our SPROM,
907 * do this after registering enet devices
909 #ifdef CONFIG_SSB_PCIHOST
910 if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
911 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
912 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
913 if (ssb_arch_register_fallback_sprom(
914 &bcm63xx_get_fallback_sprom) < 0)
915 pr_err(PFX "failed to register fallback SPROM\n");
919 bcm63xx_spi_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);