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_dsp.h>
28 #include <bcm63xx_dev_pcmcia.h>
29 #include <bcm63xx_dev_usb_ohci.h>
30 #include <bcm63xx_dev_usb_ehci.h>
31 #include <bcm63xx_dev_usb_udc.h>
32 #include <bcm63xx_dev_spi.h>
33 #include <board_bcm963xx.h>
35 #define PFX "board_bcm963xx: "
37 static struct bcm963xx_nvram nvram;
38 static unsigned int mac_addr_used = 0;
39 static struct board_info board;
45 #ifdef CONFIG_BCM63XX_CPU_6338
46 static struct board_info __initdata board_96338gw = {
48 .expected_cpu_id = 0x6338,
53 .force_duplex_full = 1,
59 static struct board_info __initdata board_96338w = {
61 .expected_cpu_id = 0x6338,
66 .force_duplex_full = 1,
74 #ifdef CONFIG_BCM63XX_CPU_6345
75 static struct board_info __initdata board_96345gw2 = {
77 .expected_cpu_id = 0x6345,
84 #ifdef CONFIG_BCM63XX_CPU_6348
85 static struct board_info __initdata board_96348r = {
87 .expected_cpu_id = 0x6348,
94 .use_internal_phy = 1,
98 static struct board_info __initdata board_96348gw_10 = {
100 .expected_cpu_id = 0x6348,
108 .use_internal_phy = 1,
111 .force_speed_100 = 1,
112 .force_duplex_full = 1,
128 static struct board_info __initdata board_96348gw_11 = {
129 .name = "96348GW-11",
130 .expected_cpu_id = 0x6348,
138 .use_internal_phy = 1,
142 .force_speed_100 = 1,
143 .force_duplex_full = 1,
152 static struct board_info __initdata board_96348gw = {
154 .expected_cpu_id = 0x6348,
162 .use_internal_phy = 1,
165 .force_speed_100 = 1,
166 .force_duplex_full = 1,
180 static struct board_info __initdata board_FAST2404 = {
182 .expected_cpu_id = 0x6348,
190 .use_internal_phy = 1,
194 .force_speed_100 = 1,
195 .force_duplex_full = 1,
204 static struct board_info __initdata board_DV201AMR = {
206 .expected_cpu_id = 0x6348,
216 .use_internal_phy = 1,
219 .force_speed_100 = 1,
220 .force_duplex_full = 1,
224 static struct board_info __initdata board_96348gw_a = {
226 .expected_cpu_id = 0x6348,
234 .use_internal_phy = 1,
237 .force_speed_100 = 1,
238 .force_duplex_full = 1,
250 #ifdef CONFIG_BCM63XX_CPU_6358
251 static struct board_info __initdata board_96358vw = {
253 .expected_cpu_id = 0x6358,
261 .use_internal_phy = 1,
265 .force_speed_100 = 1,
266 .force_duplex_full = 1,
275 static struct board_info __initdata board_96358vw2 = {
277 .expected_cpu_id = 0x6358,
285 .use_internal_phy = 1,
289 .force_speed_100 = 1,
290 .force_duplex_full = 1,
299 static struct board_info __initdata board_AGPFS0 = {
301 .expected_cpu_id = 0x6358,
309 .use_internal_phy = 1,
313 .force_speed_100 = 1,
314 .force_duplex_full = 1,
325 static const struct board_info __initdata *bcm963xx_boards[] = {
326 #ifdef CONFIG_BCM63XX_CPU_6338
330 #ifdef CONFIG_BCM63XX_CPU_6345
333 #ifdef CONFIG_BCM63XX_CPU_6348
343 #ifdef CONFIG_BCM63XX_CPU_6358
351 * early init callback, read nvram data from flash and checksum it
353 void __init board_prom_init(void)
355 unsigned int check_len, i;
356 u8 *boot_addr, *cfe, *p;
357 char cfe_version[32];
360 /* read base address of boot chip select (0)
361 * 6345 does not have MPI but boots from standard
362 * MIPS Flash address */
363 if (BCMCPU_IS_6345())
366 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
367 val &= MPI_CSBASE_BASE_MASK;
369 boot_addr = (u8 *)KSEG1ADDR(val);
371 /* dump cfe version */
372 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
373 if (!memcmp(cfe, "cfe-v", 5))
374 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
375 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
377 strcpy(cfe_version, "unknown");
378 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
380 /* extract nvram data */
381 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
383 /* check checksum before using data */
384 if (nvram.version <= 4)
385 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
387 check_len = sizeof(nvram);
393 printk(KERN_ERR PFX "invalid nvram checksum\n");
397 /* find board by name */
398 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
399 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
402 /* copy, board desc array is marked initdata */
403 memcpy(&board, bcm963xx_boards[i], sizeof(board));
407 /* bail out if board is not found, will complain later */
408 if (!board.name[0]) {
410 memcpy(name, nvram.name, 16);
412 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
417 /* setup pin multiplexing depending on board enabled device,
418 * this has to be done this early since PCI init is done
419 * inside arch_initcall */
423 bcm63xx_pci_enabled = 1;
424 if (BCMCPU_IS_6348())
425 val |= GPIO_MODE_6348_G2_PCI;
428 if (board.has_pccard) {
429 if (BCMCPU_IS_6348())
430 val |= GPIO_MODE_6348_G1_MII_PCCARD;
433 if (board.has_enet0 && !board.enet0.use_internal_phy) {
434 if (BCMCPU_IS_6348())
435 val |= GPIO_MODE_6348_G3_EXT_MII |
436 GPIO_MODE_6348_G0_EXT_MII;
439 if (board.has_enet1 && !board.enet1.use_internal_phy) {
440 if (BCMCPU_IS_6348())
441 val |= GPIO_MODE_6348_G3_EXT_MII |
442 GPIO_MODE_6348_G0_EXT_MII;
445 bcm_gpio_writel(val, GPIO_MODE_REG);
449 * second stage init callback, good time to panic if we couldn't
450 * identify on which board we're running since early printk is working
452 void __init board_setup(void)
455 panic("unable to detect bcm963xx board");
456 printk(KERN_INFO PFX "board name: %s\n", board.name);
458 /* make sure we're running on expected cpu */
459 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
460 panic("unexpected CPU for bcm963xx board");
464 * return board name for /proc/cpuinfo
466 const char *board_get_name(void)
472 * register & return a new board mac address
474 static int board_get_mac_address(u8 *mac)
479 if (mac_addr_used >= nvram.mac_addr_count) {
480 printk(KERN_ERR PFX "not enough mac address\n");
484 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
485 p = mac + ETH_ALEN - 1;
486 count = mac_addr_used;
498 printk(KERN_ERR PFX "unable to fetch mac address\n");
506 static struct resource mtd_resources[] = {
508 .start = 0, /* filled at runtime */
509 .end = 0, /* filled at runtime */
510 .flags = IORESOURCE_MEM,
514 static struct platform_device mtd_dev = {
515 .name = "bcm963xx-flash",
516 .resource = mtd_resources,
517 .num_resources = ARRAY_SIZE(mtd_resources),
521 * Register a sane SPROMv2 to make the on-board
524 static struct ssb_sprom bcm63xx_sprom = {
528 .ant_available_bg = 0x3,
541 .boardflags_lo = 0x2848,
542 .boardflags_hi = 0x0000,
545 static struct resource gpiodev_resource = {
550 * third stage init callback, register all board devices.
552 int __init board_register_devices(void)
556 bcm63xx_uart_register();
557 bcm63xx_wdt_register();
558 bcm63xx_spi_register();
560 if (board.has_pccard)
561 bcm63xx_pcmcia_register();
563 if (board.has_enet0 &&
564 !board_get_mac_address(board.enet0.mac_addr))
565 bcm63xx_enet_register(0, &board.enet0);
567 if (board.has_enet1 &&
568 !board_get_mac_address(board.enet1.mac_addr))
569 bcm63xx_enet_register(1, &board.enet1);
572 bcm63xx_ohci_register();
575 bcm63xx_ehci_register();
578 bcm63xx_udc_register();
581 bcm63xx_dsp_register(&board.dsp);
583 /* Generate MAC address for WLAN and
584 * register our SPROM */
586 if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
587 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
588 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
589 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom) < 0)
590 printk(KERN_ERR "failed to register fallback SPROM\n");
594 /* read base address of boot chip select (0) */
595 if (BCMCPU_IS_6345())
598 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
599 val &= MPI_CSBASE_BASE_MASK;
601 mtd_resources[0].start = val;
602 mtd_resources[0].end = 0x1FFFFFFF;
604 platform_device_register(&mtd_dev);
606 /* Register GPIODEV */
607 platform_device_register_simple("GPIODEV", 0, &gpiodev_resource, 1);