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_6345
74 static struct board_info __initdata board_96345gw2
= {
76 .expected_cpu_id
= 0x6345,
83 #ifdef CONFIG_BCM63XX_CPU_6348
84 static struct board_info __initdata board_96348r
= {
86 .expected_cpu_id
= 0x6348,
93 .use_internal_phy
= 1,
97 static struct board_info __initdata board_96348gw_10
= {
99 .expected_cpu_id
= 0x6348,
107 .use_internal_phy
= 1,
110 .force_speed_100
= 1,
111 .force_duplex_full
= 1,
119 static struct board_info __initdata board_96348gw_11
= {
120 .name
= "96348GW-11",
121 .expected_cpu_id
= 0x6348,
129 .use_internal_phy
= 1,
133 .force_speed_100
= 1,
134 .force_duplex_full
= 1,
143 static struct board_info __initdata board_96348gw
= {
145 .expected_cpu_id
= 0x6348,
153 .use_internal_phy
= 1,
156 .force_speed_100
= 1,
157 .force_duplex_full
= 1,
163 static struct board_info __initdata board_FAST2404
= {
165 .expected_cpu_id
= 0x6348,
173 .use_internal_phy
= 1,
177 .force_speed_100
= 1,
178 .force_duplex_full
= 1,
187 static struct board_info __initdata board_DV201AMR
= {
189 .expected_cpu_id
= 0x6348,
199 .use_internal_phy
= 1,
202 .force_speed_100
= 1,
203 .force_duplex_full
= 1,
207 static struct board_info __initdata board_96348gw_a
= {
209 .expected_cpu_id
= 0x6348,
217 .use_internal_phy
= 1,
220 .force_speed_100
= 1,
221 .force_duplex_full
= 1,
233 #ifdef CONFIG_BCM63XX_CPU_6358
234 static struct board_info __initdata board_96358vw
= {
236 .expected_cpu_id
= 0x6358,
244 .use_internal_phy
= 1,
248 .force_speed_100
= 1,
249 .force_duplex_full
= 1,
258 static struct board_info __initdata board_96358vw2
= {
260 .expected_cpu_id
= 0x6358,
268 .use_internal_phy
= 1,
272 .force_speed_100
= 1,
273 .force_duplex_full
= 1,
282 static struct board_info __initdata board_AGPFS0
= {
284 .expected_cpu_id
= 0x6358,
292 .use_internal_phy
= 1,
296 .force_speed_100
= 1,
297 .force_duplex_full
= 1,
308 static const struct board_info __initdata
*bcm963xx_boards
[] = {
309 #ifdef CONFIG_BCM63XX_CPU_6338
313 #ifdef CONFIG_BCM63XX_CPU_6345
316 #ifdef CONFIG_BCM63XX_CPU_6348
326 #ifdef CONFIG_BCM63XX_CPU_6358
334 * early init callback, read nvram data from flash and checksum it
336 void __init
board_prom_init(void)
338 unsigned int check_len
, i
;
339 u8
*boot_addr
, *cfe
, *p
;
340 char cfe_version
[32];
343 /* read base address of boot chip select (0)
344 * 6338/6345 does not have MPI but boots from standard
345 * MIPS Flash address */
346 if (BCMCPU_IS_6345())
349 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
350 val
&= MPI_CSBASE_BASE_MASK
;
352 boot_addr
= (u8
*)KSEG1ADDR(val
);
354 /* dump cfe version */
355 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
356 if (!memcmp(cfe
, "cfe-v", 5))
357 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
358 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
360 strcpy(cfe_version
, "unknown");
361 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
363 /* extract nvram data */
364 memcpy(&nvram
, boot_addr
+ BCM963XX_NVRAM_OFFSET
, sizeof(nvram
));
366 /* check checksum before using data */
367 if (nvram
.version
<= 4)
368 check_len
= offsetof(struct bcm963xx_nvram
, checksum_old
);
370 check_len
= sizeof(nvram
);
376 printk(KERN_ERR PFX
"invalid nvram checksum\n");
380 /* find board by name */
381 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
382 if (strncmp(nvram
.name
, bcm963xx_boards
[i
]->name
,
385 /* copy, board desc array is marked initdata */
386 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
390 /* bail out if board is not found, will complain later */
391 if (!board
.name
[0]) {
393 memcpy(name
, nvram
.name
, 16);
395 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
400 /* setup pin multiplexing depending on board enabled device,
401 * this has to be done this early since PCI init is done
402 * inside arch_initcall */
406 bcm63xx_pci_enabled
= 1;
407 if (BCMCPU_IS_6348())
408 val
|= GPIO_MODE_6348_G2_PCI
;
411 if (board
.has_pccard
) {
412 if (BCMCPU_IS_6348())
413 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
416 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
417 if (BCMCPU_IS_6348())
418 val
|= GPIO_MODE_6348_G3_EXT_MII
|
419 GPIO_MODE_6348_G0_EXT_MII
;
422 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
423 if (BCMCPU_IS_6348())
424 val
|= GPIO_MODE_6348_G3_EXT_MII
|
425 GPIO_MODE_6348_G0_EXT_MII
;
428 bcm_gpio_writel(val
, GPIO_MODE_REG
);
432 * second stage init callback, good time to panic if we couldn't
433 * identify on which board we're running since early printk is working
435 void __init
board_setup(void)
438 panic("unable to detect bcm963xx board");
439 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
441 /* make sure we're running on expected cpu */
442 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
443 panic("unexpected CPU for bcm963xx board");
447 * return board name for /proc/cpuinfo
449 const char *board_get_name(void)
455 * register & return a new board mac address
457 static int board_get_mac_address(u8
*mac
)
462 if (mac_addr_used
>= nvram
.mac_addr_count
) {
463 printk(KERN_ERR PFX
"not enough mac address\n");
467 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
468 p
= mac
+ ETH_ALEN
- 1;
469 count
= mac_addr_used
;
481 printk(KERN_ERR PFX
"unable to fetch mac address\n");
489 static struct resource mtd_resources
[] = {
491 .start
= 0, /* filled at runtime */
492 .end
= 0, /* filled at runtime */
493 .flags
= IORESOURCE_MEM
,
497 static struct platform_device mtd_dev
= {
498 .name
= "bcm963xx-flash",
499 .resource
= mtd_resources
,
500 .num_resources
= ARRAY_SIZE(mtd_resources
),
504 * Register a sane SPROMv2 to make the on-board
507 static struct ssb_sprom bcm63xx_sprom
= {
511 .ant_available_bg
= 0x3,
524 .boardflags_lo
= 0x2848,
525 .boardflags_hi
= 0x0000,
528 static struct resource gpiodev_resource
= {
533 * third stage init callback, register all board devices.
535 int __init
board_register_devices(void)
539 bcm63xx_uart_register();
540 bcm63xx_wdt_register();
541 bcm63xx_spi_register();
543 if (board
.has_pccard
)
544 bcm63xx_pcmcia_register();
546 if (board
.has_enet0
&&
547 !board_get_mac_address(board
.enet0
.mac_addr
))
548 bcm63xx_enet_register(0, &board
.enet0
);
550 if (board
.has_enet1
&&
551 !board_get_mac_address(board
.enet1
.mac_addr
))
552 bcm63xx_enet_register(1, &board
.enet1
);
555 bcm63xx_ohci_register();
558 bcm63xx_ehci_register();
561 bcm63xx_udc_register();
562 /* Generate MAC address for WLAN and
563 * register our SPROM */
565 if (!board_get_mac_address(bcm63xx_sprom
.il0mac
)) {
566 memcpy(bcm63xx_sprom
.et0mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
567 memcpy(bcm63xx_sprom
.et1mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
568 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom
) < 0)
569 printk(KERN_ERR
"failed to register fallback SPROM\n");
573 /* read base address of boot chip select (0) */
574 if (BCMCPU_IS_6345())
577 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
578 val
&= MPI_CSBASE_BASE_MASK
;
580 mtd_resources
[0].start
= val
;
581 mtd_resources
[0].end
= 0x1FFFFFFF;
583 platform_device_register(&mtd_dev
);
585 /* Register GPIODEV */
586 platform_device_register_simple("GPIODEV", 0, &gpiodev_resource
, 1);