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_spi.h>
31 #include <board_bcm963xx.h>
33 #define PFX "board_bcm963xx: "
35 static struct bcm963xx_nvram nvram
;
36 static unsigned int mac_addr_used
= 0;
37 static struct board_info board
;
43 #ifdef CONFIG_BCM63XX_CPU_6338
44 static struct board_info __initdata board_96338gw
= {
46 .expected_cpu_id
= 0x6338,
51 .use_internal_phy
= 1,
61 #ifdef CONFIG_BCM63XX_CPU_6348
62 static struct board_info __initdata board_96348r
= {
64 .expected_cpu_id
= 0x6348,
71 .use_internal_phy
= 1,
75 static struct board_info __initdata board_96348gw_10
= {
77 .expected_cpu_id
= 0x6348,
85 .use_internal_phy
= 1,
89 .force_duplex_full
= 1,
97 static struct board_info __initdata board_96348gw_11
= {
99 .expected_cpu_id
= 0x6348,
107 .use_internal_phy
= 1,
111 .force_speed_100
= 1,
112 .force_duplex_full
= 1,
121 static struct board_info __initdata board_96348gw
= {
123 .expected_cpu_id
= 0x6348,
131 .use_internal_phy
= 1,
134 .force_speed_100
= 1,
135 .force_duplex_full
= 1,
141 static struct board_info __initdata board_FAST2404
= {
143 .expected_cpu_id
= 0x6348,
151 .use_internal_phy
= 1,
155 .force_speed_100
= 1,
156 .force_duplex_full
= 1,
165 static struct board_info __initdata board_DV201AMR
= {
167 .expected_cpu_id
= 0x6348,
175 .use_internal_phy
= 1,
179 .force_speed_100
= 1,
180 .force_duplex_full
= 1,
189 static struct board_info __initdata board_96348gw_a
= {
191 .expected_cpu_id
= 0x6348,
199 .use_internal_phy
= 1,
202 .force_speed_100
= 1,
203 .force_duplex_full
= 1,
215 #ifdef CONFIG_BCM63XX_CPU_6358
216 static struct board_info __initdata board_96358vw
= {
218 .expected_cpu_id
= 0x6358,
226 .use_internal_phy
= 1,
230 .force_speed_100
= 1,
231 .force_duplex_full
= 1,
240 static struct board_info __initdata board_96358vw2
= {
242 .expected_cpu_id
= 0x6358,
250 .use_internal_phy
= 1,
254 .force_speed_100
= 1,
255 .force_duplex_full
= 1,
264 static struct board_info __initdata board_AGPFS0
= {
266 .expected_cpu_id
= 0x6358,
274 .use_internal_phy
= 1,
278 .force_speed_100
= 1,
279 .force_duplex_full
= 1,
290 static const struct board_info __initdata
*bcm963xx_boards
[] = {
291 #ifdef CONFIG_BCM63XX_CPU_6338
294 #ifdef CONFIG_BCM63XX_CPU_6348
304 #ifdef CONFIG_BCM63XX_CPU_6358
312 * early init callback, read nvram data from flash and checksum it
314 void __init
board_prom_init(void)
316 unsigned int check_len
, i
;
317 u8
*boot_addr
, *cfe
, *p
;
318 char cfe_version
[32];
321 /* read base address of boot chip select (0) */
322 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
323 val
&= MPI_CSBASE_BASE_MASK
;
324 boot_addr
= (u8
*)KSEG1ADDR(val
);
326 /* dump cfe version */
327 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
328 if (!memcmp(cfe
, "cfe-v", 5))
329 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
330 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
332 strcpy(cfe_version
, "unknown");
333 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
335 /* extract nvram data */
336 memcpy(&nvram
, boot_addr
+ BCM963XX_NVRAM_OFFSET
, sizeof(nvram
));
338 /* check checksum before using data */
339 if (nvram
.version
<= 4)
340 check_len
= offsetof(struct bcm963xx_nvram
, checksum_old
);
342 check_len
= sizeof(nvram
);
348 printk(KERN_ERR PFX
"invalid nvram checksum\n");
352 /* find board by name */
353 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
354 if (strncmp(nvram
.name
, bcm963xx_boards
[i
]->name
,
357 /* copy, board desc array is marked initdata */
358 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
362 /* bail out if board is not found, will complain later */
363 if (!board
.name
[0]) {
365 memcpy(name
, nvram
.name
, 16);
367 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
372 /* setup pin multiplexing depending on board enabled device,
373 * this has to be done this early since PCI init is done
374 * inside arch_initcall */
378 bcm63xx_pci_enabled
= 1;
379 if (BCMCPU_IS_6348())
380 val
|= GPIO_MODE_6348_G2_PCI
;
383 if (board
.has_pccard
) {
384 if (BCMCPU_IS_6348())
385 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
388 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
389 if (BCMCPU_IS_6348())
390 val
|= GPIO_MODE_6348_G3_EXT_MII
|
391 GPIO_MODE_6348_G0_EXT_MII
;
394 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
395 if (BCMCPU_IS_6348())
396 val
|= GPIO_MODE_6348_G3_EXT_MII
|
397 GPIO_MODE_6348_G0_EXT_MII
;
400 bcm_gpio_writel(val
, GPIO_MODE_REG
);
404 * second stage init callback, good time to panic if we couldn't
405 * identify on which board we're running since early printk is working
407 void __init
board_setup(void)
410 panic("unable to detect bcm963xx board");
411 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
413 /* make sure we're running on expected cpu */
414 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
415 panic("unexpected CPU for bcm963xx board");
419 * return board name for /proc/cpuinfo
421 const char *board_get_name(void)
427 * register & return a new board mac address
429 static int board_get_mac_address(u8
*mac
)
434 if (mac_addr_used
>= nvram
.mac_addr_count
) {
435 printk(KERN_ERR PFX
"not enough mac address\n");
439 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
440 p
= mac
+ ETH_ALEN
- 1;
441 count
= mac_addr_used
;
453 printk(KERN_ERR PFX
"unable to fetch mac address\n");
461 static struct resource mtd_resources
[] = {
463 .start
= 0, /* filled at runtime */
464 .end
= 0, /* filled at runtime */
465 .flags
= IORESOURCE_MEM
,
469 static struct platform_device mtd_dev
= {
470 .name
= "bcm963xx-flash",
471 .resource
= mtd_resources
,
472 .num_resources
= ARRAY_SIZE(mtd_resources
),
476 * Register a sane SPROMv2 to make the on-board
479 static struct ssb_sprom bcm63xx_sprom
= {
483 .ant_available_bg
= 0x3,
496 .boardflags_lo
= 0x2848,
497 .boardflags_hi
= 0x0000,
501 * third stage init callback, register all board devices.
503 int __init
board_register_devices(void)
507 bcm63xx_uart_register();
508 bcm63xx_wdt_register();
509 bcm63xx_spi_register();
511 if (board
.has_pccard
)
512 bcm63xx_pcmcia_register();
514 if (board
.has_enet0
&&
515 !board_get_mac_address(board
.enet0
.mac_addr
))
516 bcm63xx_enet_register(0, &board
.enet0
);
518 if (board
.has_enet1
&&
519 !board_get_mac_address(board
.enet1
.mac_addr
))
520 bcm63xx_enet_register(1, &board
.enet1
);
523 bcm63xx_ohci_register();
526 bcm63xx_ehci_register();
528 /* Generate MAC address for WLAN and
529 * register our SPROM */
530 if (!board_get_mac_address(bcm63xx_sprom
.il0mac
)) {
531 memcpy(bcm63xx_sprom
.et0mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
532 memcpy(bcm63xx_sprom
.et1mac
, bcm63xx_sprom
.il0mac
, ETH_ALEN
);
533 if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom
) < 0)
534 printk(KERN_ERR
"failed to register fallback SPROM\n");
537 /* read base address of boot chip select (0) */
538 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
539 val
&= MPI_CSBASE_BASE_MASK
;
540 mtd_resources
[0].start
= val
;
541 mtd_resources
[0].end
= 0x1FFFFFFF;
543 platform_device_register(&mtd_dev
);