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>
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/mtd/physmap.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_regs.h>
21 #include <bcm63xx_io.h>
22 #include <bcm63xx_board.h>
23 #include <bcm63xx_dev_pci.h>
24 #include <bcm63xx_dev_uart.h>
25 #include <bcm63xx_dev_wdt.h>
26 #include <bcm63xx_dev_enet.h>
27 #include <bcm63xx_dev_pcmcia.h>
28 #include <bcm63xx_dev_usb_ohci.h>
29 #include <bcm63xx_dev_usb_ehci.h>
30 #include <bcm63xx_dev_usb_udc.h>
31 #include <bcm63xx_dev_spi.h>
32 #include <board_bcm963xx.h>
34 #define PFX "board_bcm963xx: "
36 static struct bcm963xx_nvram nvram;
37 static unsigned int mac_addr_used = 0;
38 static struct board_info board;
44 #ifdef CONFIG_BCM63XX_CPU_6338
45 static struct board_info __initdata board_96338gw = {
47 .expected_cpu_id = 0x6338,
52 .force_duplex_full = 1,
58 static struct board_info __initdata board_96338w = {
60 .expected_cpu_id = 0x6338,
65 .force_duplex_full = 1,
73 #ifdef CONFIG_BCM63XX_CPU_6348
74 static struct board_info __initdata board_96348r = {
76 .expected_cpu_id = 0x6348,
83 .use_internal_phy = 1,
87 static struct board_info __initdata board_96348gw_10 = {
89 .expected_cpu_id = 0x6348,
97 .use_internal_phy = 1,
100 .force_speed_100 = 1,
101 .force_duplex_full = 1,
109 static struct board_info __initdata board_96348gw_11 = {
110 .name = "96348GW-11",
111 .expected_cpu_id = 0x6348,
119 .use_internal_phy = 1,
123 .force_speed_100 = 1,
124 .force_duplex_full = 1,
133 static struct board_info __initdata board_96348gw = {
135 .expected_cpu_id = 0x6348,
143 .use_internal_phy = 1,
146 .force_speed_100 = 1,
147 .force_duplex_full = 1,
153 static struct board_info __initdata board_FAST2404 = {
155 .expected_cpu_id = 0x6348,
163 .use_internal_phy = 1,
167 .force_speed_100 = 1,
168 .force_duplex_full = 1,
177 static struct board_info __initdata board_DV201AMR = {
179 .expected_cpu_id = 0x6348,
189 .use_internal_phy = 1,
192 .force_speed_100 = 1,
193 .force_duplex_full = 1,
197 static struct board_info __initdata board_96348gw_a = {
199 .expected_cpu_id = 0x6348,
207 .use_internal_phy = 1,
210 .force_speed_100 = 1,
211 .force_duplex_full = 1,
223 #ifdef CONFIG_BCM63XX_CPU_6358
224 static struct board_info __initdata board_96358vw = {
226 .expected_cpu_id = 0x6358,
234 .use_internal_phy = 1,
238 .force_speed_100 = 1,
239 .force_duplex_full = 1,
248 static struct board_info __initdata board_96358vw2 = {
250 .expected_cpu_id = 0x6358,
258 .use_internal_phy = 1,
262 .force_speed_100 = 1,
263 .force_duplex_full = 1,
272 static struct board_info __initdata board_AGPFS0 = {
274 .expected_cpu_id = 0x6358,
282 .use_internal_phy = 1,
286 .force_speed_100 = 1,
287 .force_duplex_full = 1,
298 static const struct board_info __initdata *bcm963xx_boards[] = {
299 #ifdef CONFIG_BCM63XX_CPU_6338
303 #ifdef CONFIG_BCM63XX_CPU_6348
313 #ifdef CONFIG_BCM63XX_CPU_6358
321 * early init callback, read nvram data from flash and checksum it
323 void __init board_prom_init(void)
325 unsigned int check_len, i;
326 u8 *boot_addr, *cfe, *p;
327 char cfe_version[32];
330 /* read base address of boot chip select (0)
331 * 6338/6345 does not have MPI but boots from standard
332 * MIPS Flash address */
333 if (BCMCPU_IS_6345())
336 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
337 val &= MPI_CSBASE_BASE_MASK;
339 boot_addr = (u8 *)KSEG1ADDR(val);
341 /* dump cfe version */
342 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
343 if (!memcmp(cfe, "cfe-v", 5))
344 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
345 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
347 strcpy(cfe_version, "unknown");
348 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
350 /* extract nvram data */
351 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
353 /* check checksum before using data */
354 if (nvram.version <= 4)
355 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
357 check_len = sizeof(nvram);
363 printk(KERN_ERR PFX "invalid nvram checksum\n");
367 /* find board by name */
368 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
369 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
372 /* copy, board desc array is marked initdata */
373 memcpy(&board, bcm963xx_boards[i], sizeof(board));
377 /* bail out if board is not found, will complain later */
378 if (!board.name[0]) {
380 memcpy(name, nvram.name, 16);
382 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
387 /* setup pin multiplexing depending on board enabled device,
388 * this has to be done this early since PCI init is done
389 * inside arch_initcall */
393 bcm63xx_pci_enabled = 1;
394 if (BCMCPU_IS_6348())
395 val |= GPIO_MODE_6348_G2_PCI;
398 if (board.has_pccard) {
399 if (BCMCPU_IS_6348())
400 val |= GPIO_MODE_6348_G1_MII_PCCARD;
403 if (board.has_enet0 && !board.enet0.use_internal_phy) {
404 if (BCMCPU_IS_6348())
405 val |= GPIO_MODE_6348_G3_EXT_MII |
406 GPIO_MODE_6348_G0_EXT_MII;
409 if (board.has_enet1 && !board.enet1.use_internal_phy) {
410 if (BCMCPU_IS_6348())
411 val |= GPIO_MODE_6348_G3_EXT_MII |
412 GPIO_MODE_6348_G0_EXT_MII;
415 bcm_gpio_writel(val, GPIO_MODE_REG);
419 * second stage init callback, good time to panic if we couldn't
420 * identify on which board we're running since early printk is working
422 void __init board_setup(void)
425 panic("unable to detect bcm963xx board");
426 printk(KERN_INFO PFX "board name: %s\n", board.name);
428 /* make sure we're running on expected cpu */
429 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
430 panic("unexpected CPU for bcm963xx board");
434 * return board name for /proc/cpuinfo
436 const char *board_get_name(void)
442 * register & return a new board mac address
444 static int board_get_mac_address(u8 *mac)
449 if (mac_addr_used >= nvram.mac_addr_count) {
450 printk(KERN_ERR PFX "not enough mac address\n");
454 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
455 p = mac + ETH_ALEN - 1;
456 count = mac_addr_used;
468 printk(KERN_ERR PFX "unable to fetch mac address\n");
476 static struct resource mtd_resources[] = {
478 .start = 0, /* filled at runtime */
479 .end = 0, /* filled at runtime */
480 .flags = IORESOURCE_MEM,
484 static struct platform_device mtd_dev = {
485 .name = "bcm963xx-flash",
486 .resource = mtd_resources,
487 .num_resources = ARRAY_SIZE(mtd_resources),
491 * Register a sane SPROMv2 to make the on-board
494 static struct ssb_sprom bcm63xx_sprom = {
498 .ant_available_bg = 0x3,
511 .boardflags_lo = 0x2848,
512 .boardflags_hi = 0x0000,
515 static struct resource gpiodev_resource = {
520 * third stage init callback, register all board devices.
522 int __init board_register_devices(void)
526 bcm63xx_uart_register();
527 bcm63xx_wdt_register();
528 bcm63xx_spi_register();
530 if (board.has_pccard)
531 bcm63xx_pcmcia_register();
533 if (board.has_enet0 &&
534 !board_get_mac_address(board.enet0.mac_addr))
535 bcm63xx_enet_register(0, &board.enet0);
537 if (board.has_enet1 &&
538 !board_get_mac_address(board.enet1.mac_addr))
539 bcm63xx_enet_register(1, &board.enet1);
542 bcm63xx_ohci_register();
545 bcm63xx_ehci_register();
548 bcm63xx_udc_register();
549 /* Generate MAC address for WLAN and
550 * register our SPROM */
552 if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
553 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
554 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
555 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom) < 0)
556 printk(KERN_ERR "failed to register fallback SPROM\n");
560 /* read base address of boot chip select (0) */
561 if (BCMCPU_IS_6345())
564 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
565 val &= MPI_CSBASE_BASE_MASK;
567 mtd_resources[0].start = val;
568 mtd_resources[0].end = 0x1FFFFFFF;
570 platform_device_register(&mtd_dev);
572 /* Register GPIODEV */
573 platform_device_register_simple("GPIODEV", 0, &gpiodev_resource, 1);