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 .use_internal_phy = 1,
58 static struct board_info __initdata board_96338w = {
60 .expected_cpu_id = 0x6338,
69 #ifdef CONFIG_BCM63XX_CPU_6348
70 static struct board_info __initdata board_96348r = {
72 .expected_cpu_id = 0x6348,
79 .use_internal_phy = 1,
83 static struct board_info __initdata board_96348gw_10 = {
85 .expected_cpu_id = 0x6348,
93 .use_internal_phy = 1,
97 .force_duplex_full = 1,
105 static struct board_info __initdata board_96348gw_11 = {
106 .name = "96348GW-11",
107 .expected_cpu_id = 0x6348,
115 .use_internal_phy = 1,
119 .force_speed_100 = 1,
120 .force_duplex_full = 1,
129 static struct board_info __initdata board_96348gw = {
131 .expected_cpu_id = 0x6348,
139 .use_internal_phy = 1,
142 .force_speed_100 = 1,
143 .force_duplex_full = 1,
149 static struct board_info __initdata board_FAST2404 = {
151 .expected_cpu_id = 0x6348,
159 .use_internal_phy = 1,
163 .force_speed_100 = 1,
164 .force_duplex_full = 1,
173 static struct board_info __initdata board_DV201AMR = {
175 .expected_cpu_id = 0x6348,
185 .use_internal_phy = 1,
188 .force_speed_100 = 1,
189 .force_duplex_full = 1,
193 static struct board_info __initdata board_96348gw_a = {
195 .expected_cpu_id = 0x6348,
203 .use_internal_phy = 1,
206 .force_speed_100 = 1,
207 .force_duplex_full = 1,
219 #ifdef CONFIG_BCM63XX_CPU_6358
220 static struct board_info __initdata board_96358vw = {
222 .expected_cpu_id = 0x6358,
230 .use_internal_phy = 1,
234 .force_speed_100 = 1,
235 .force_duplex_full = 1,
244 static struct board_info __initdata board_96358vw2 = {
246 .expected_cpu_id = 0x6358,
254 .use_internal_phy = 1,
258 .force_speed_100 = 1,
259 .force_duplex_full = 1,
268 static struct board_info __initdata board_AGPFS0 = {
270 .expected_cpu_id = 0x6358,
278 .use_internal_phy = 1,
282 .force_speed_100 = 1,
283 .force_duplex_full = 1,
294 static const struct board_info __initdata *bcm963xx_boards[] = {
295 #ifdef CONFIG_BCM63XX_CPU_6338
299 #ifdef CONFIG_BCM63XX_CPU_6348
309 #ifdef CONFIG_BCM63XX_CPU_6358
317 * early init callback, read nvram data from flash and checksum it
319 void __init board_prom_init(void)
321 unsigned int check_len, i;
322 u8 *boot_addr, *cfe, *p;
323 char cfe_version[32];
326 /* read base address of boot chip select (0) */
327 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
328 val &= MPI_CSBASE_BASE_MASK;
329 boot_addr = (u8 *)KSEG1ADDR(val);
331 /* dump cfe version */
332 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
333 if (!memcmp(cfe, "cfe-v", 5))
334 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
335 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
337 strcpy(cfe_version, "unknown");
338 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
340 /* extract nvram data */
341 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
343 /* check checksum before using data */
344 if (nvram.version <= 4)
345 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
347 check_len = sizeof(nvram);
353 printk(KERN_ERR PFX "invalid nvram checksum\n");
357 /* find board by name */
358 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
359 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
362 /* copy, board desc array is marked initdata */
363 memcpy(&board, bcm963xx_boards[i], sizeof(board));
367 /* bail out if board is not found, will complain later */
368 if (!board.name[0]) {
370 memcpy(name, nvram.name, 16);
372 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
377 /* setup pin multiplexing depending on board enabled device,
378 * this has to be done this early since PCI init is done
379 * inside arch_initcall */
383 bcm63xx_pci_enabled = 1;
384 if (BCMCPU_IS_6348())
385 val |= GPIO_MODE_6348_G2_PCI;
388 if (board.has_pccard) {
389 if (BCMCPU_IS_6348())
390 val |= GPIO_MODE_6348_G1_MII_PCCARD;
393 if (board.has_enet0 && !board.enet0.use_internal_phy) {
394 if (BCMCPU_IS_6348())
395 val |= GPIO_MODE_6348_G3_EXT_MII |
396 GPIO_MODE_6348_G0_EXT_MII;
399 if (board.has_enet1 && !board.enet1.use_internal_phy) {
400 if (BCMCPU_IS_6348())
401 val |= GPIO_MODE_6348_G3_EXT_MII |
402 GPIO_MODE_6348_G0_EXT_MII;
405 bcm_gpio_writel(val, GPIO_MODE_REG);
409 * second stage init callback, good time to panic if we couldn't
410 * identify on which board we're running since early printk is working
412 void __init board_setup(void)
415 panic("unable to detect bcm963xx board");
416 printk(KERN_INFO PFX "board name: %s\n", board.name);
418 /* make sure we're running on expected cpu */
419 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
420 panic("unexpected CPU for bcm963xx board");
424 * return board name for /proc/cpuinfo
426 const char *board_get_name(void)
432 * register & return a new board mac address
434 static int board_get_mac_address(u8 *mac)
439 if (mac_addr_used >= nvram.mac_addr_count) {
440 printk(KERN_ERR PFX "not enough mac address\n");
444 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
445 p = mac + ETH_ALEN - 1;
446 count = mac_addr_used;
458 printk(KERN_ERR PFX "unable to fetch mac address\n");
466 static struct resource mtd_resources[] = {
468 .start = 0, /* filled at runtime */
469 .end = 0, /* filled at runtime */
470 .flags = IORESOURCE_MEM,
474 static struct platform_device mtd_dev = {
475 .name = "bcm963xx-flash",
476 .resource = mtd_resources,
477 .num_resources = ARRAY_SIZE(mtd_resources),
481 * Register a sane SPROMv2 to make the on-board
484 static struct ssb_sprom bcm63xx_sprom = {
488 .ant_available_bg = 0x3,
501 .boardflags_lo = 0x2848,
502 .boardflags_hi = 0x0000,
505 static struct resource gpiodev_resource = {
510 * third stage init callback, register all board devices.
512 int __init board_register_devices(void)
516 bcm63xx_uart_register();
517 bcm63xx_wdt_register();
518 bcm63xx_spi_register();
520 if (board.has_pccard)
521 bcm63xx_pcmcia_register();
523 if (board.has_enet0 &&
524 !board_get_mac_address(board.enet0.mac_addr))
525 bcm63xx_enet_register(0, &board.enet0);
527 if (board.has_enet1 &&
528 !board_get_mac_address(board.enet1.mac_addr))
529 bcm63xx_enet_register(1, &board.enet1);
532 bcm63xx_ohci_register();
535 bcm63xx_ehci_register();
538 bcm63xx_udc_register();
539 /* Generate MAC address for WLAN and
540 * register our SPROM */
542 if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
543 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
544 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
545 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom) < 0)
546 printk(KERN_ERR "failed to register fallback SPROM\n");
550 /* read base address of boot chip select (0) */
551 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
552 val &= MPI_CSBASE_BASE_MASK;
553 mtd_resources[0].start = val;
554 mtd_resources[0].end = 0x1FFFFFFF;
556 platform_device_register(&mtd_dev);
558 /* Register GPIODEV */
559 platform_device_register_simple("GPIODEV", 0, &gpiodev_resource, 1);