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 <asm/addrspace.h>
17 #include <bcm63xx_board.h>
18 #include <bcm63xx_cpu.h>
19 #include <bcm63xx_regs.h>
20 #include <bcm63xx_io.h>
21 #include <bcm63xx_board.h>
22 #include <bcm63xx_dev_pci.h>
23 #include <bcm63xx_dev_uart.h>
24 #include <bcm63xx_dev_wdt.h>
25 #include <bcm63xx_dev_enet.h>
26 #include <bcm63xx_dev_pcmcia.h>
27 #include <bcm63xx_dev_usb_ohci.h>
28 #include <bcm63xx_dev_usb_ehci.h>
29 #include <board_bcm963xx.h>
31 #define PFX "board_bcm963xx: "
33 static struct bcm963xx_nvram nvram
;
34 static unsigned int mac_addr_used
= 0;
35 static struct board_info board
;
41 #ifdef CONFIG_BCM63XX_CPU_6338
42 static struct board_info __initdata board_96338gw
= {
44 .expected_cpu_id
= 0x6338,
49 .use_internal_phy
= 1,
59 #ifdef CONFIG_BCM63XX_CPU_6348
60 static struct board_info __initdata board_96348r
= {
62 .expected_cpu_id
= 0x6348,
69 .use_internal_phy
= 1,
73 static struct board_info __initdata board_96348gw_10
= {
75 .expected_cpu_id
= 0x6348,
83 .use_internal_phy
= 1,
87 .force_duplex_full
= 1,
95 static struct board_info __initdata board_96348gw_11
= {
97 .expected_cpu_id
= 0x6348,
105 .use_internal_phy
= 1,
109 .force_speed_100
= 1,
110 .force_duplex_full
= 1,
119 static struct board_info __initdata board_96348gw
= {
121 .expected_cpu_id
= 0x6348,
129 .use_internal_phy
= 1,
132 .force_speed_100
= 1,
133 .force_duplex_full
= 1,
139 static struct board_info __initdata board_FAST2404
= {
141 .expected_cpu_id
= 0x6348,
149 .use_internal_phy
= 1,
153 .force_speed_100
= 1,
154 .force_duplex_full
= 1,
163 static struct board_info __initdata board_DV201AMR
= {
165 .expected_cpu_id
= 0x6348,
173 .use_internal_phy
= 1,
177 .force_speed_100
= 1,
178 .force_duplex_full
= 1,
192 #ifdef CONFIG_BCM63XX_CPU_6358
193 static struct board_info __initdata board_96358vw
= {
195 .expected_cpu_id
= 0x6358,
203 .use_internal_phy
= 1,
207 .force_speed_100
= 1,
208 .force_duplex_full
= 1,
217 static struct board_info __initdata board_96358vw2
= {
219 .expected_cpu_id
= 0x6358,
227 .use_internal_phy
= 1,
231 .force_speed_100
= 1,
232 .force_duplex_full
= 1,
245 static const struct board_info __initdata
*bcm963xx_boards
[] = {
246 #ifdef CONFIG_BCM63XX_CPU_6338
249 #ifdef CONFIG_BCM63XX_CPU_6348
258 #ifdef CONFIG_BCM63XX_CPU_6358
265 * early init callback, read nvram data from flash and checksum it
267 void __init
board_prom_init(void)
269 unsigned int check_len
, i
;
270 u8
*boot_addr
, *cfe
, *p
;
271 char cfe_version
[32];
274 /* read base address of boot chip select (0) */
275 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
276 val
&= MPI_CSBASE_BASE_MASK
;
277 boot_addr
= (u8
*)KSEG1ADDR(val
);
279 /* dump cfe version */
280 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
281 if (!memcmp(cfe
, "cfe-v", 5))
282 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
283 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
285 strcpy(cfe_version
, "unknown");
286 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
288 /* extract nvram data */
289 memcpy(&nvram
, boot_addr
+ BCM963XX_NVRAM_OFFSET
, sizeof(nvram
));
291 /* check checksum before using data */
292 if (nvram
.version
<= 4)
293 check_len
= offsetof(struct bcm963xx_nvram
, checksum_old
);
295 check_len
= sizeof(nvram
);
301 printk(KERN_ERR PFX
"invalid nvram checksum\n");
305 /* find board by name */
306 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
307 if (strncmp(nvram
.name
, bcm963xx_boards
[i
]->name
,
310 /* copy, board desc array is marked initdata */
311 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
315 /* bail out if board is not found, will complain later */
316 if (!board
.name
[0]) {
318 memcpy(name
, nvram
.name
, 16);
320 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
325 /* setup pin multiplexing depending on board enabled device,
326 * this has to be done this early since PCI init is done
327 * inside arch_initcall */
331 bcm63xx_pci_enabled
= 1;
332 if (BCMCPU_IS_6348())
333 val
|= GPIO_MODE_6348_G2_PCI
;
336 if (board
.has_pccard
) {
337 if (BCMCPU_IS_6348())
338 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
341 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
342 if (BCMCPU_IS_6348())
343 val
|= GPIO_MODE_6348_G3_EXT_MII
|
344 GPIO_MODE_6348_G0_EXT_MII
;
347 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
348 if (BCMCPU_IS_6348())
349 val
|= GPIO_MODE_6348_G3_EXT_MII
|
350 GPIO_MODE_6348_G0_EXT_MII
;
353 bcm_gpio_writel(val
, GPIO_MODE_REG
);
357 * second stage init callback, good time to panic if we couldn't
358 * identify on which board we're running since early printk is working
360 void __init
board_setup(void)
363 panic("unable to detect bcm963xx board");
364 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
366 /* make sure we're running on expected cpu */
367 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
368 panic("unexpected CPU for bcm963xx board");
372 * return board name for /proc/cpuinfo
374 const char *board_get_name(void)
380 * register & return a new board mac address
382 static int board_get_mac_address(u8
*mac
)
387 if (mac_addr_used
>= nvram
.mac_addr_count
) {
388 printk(KERN_ERR PFX
"not enough mac address\n");
392 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
393 p
= mac
+ ETH_ALEN
- 1;
394 count
= mac_addr_used
;
406 printk(KERN_ERR PFX
"unable to fetch mac address\n");
414 static struct resource mtd_resources
[] = {
416 .start
= 0, /* filled at runtime */
417 .end
= 0, /* filled at runtime */
418 .flags
= IORESOURCE_MEM
,
422 static struct platform_device mtd_dev
= {
423 .name
= "bcm963xx-flash",
424 .resource
= mtd_resources
,
425 .num_resources
= ARRAY_SIZE(mtd_resources
),
429 * third stage init callback, register all board devices.
431 int __init
board_register_devices(void)
435 bcm63xx_uart_register();
436 bcm63xx_wdt_register();
438 if (board
.has_pccard
)
439 bcm63xx_pcmcia_register();
441 if (board
.has_enet0
&&
442 !board_get_mac_address(board
.enet0
.mac_addr
))
443 bcm63xx_enet_register(0, &board
.enet0
);
445 if (board
.has_enet1
&&
446 !board_get_mac_address(board
.enet1
.mac_addr
))
447 bcm63xx_enet_register(1, &board
.enet1
);
450 bcm63xx_ohci_register();
453 bcm63xx_ehci_register();
456 /* read base address of boot chip select (0) */
457 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
458 val
&= MPI_CSBASE_BASE_MASK
;
459 mtd_resources
[0].start
= val
;
460 mtd_resources
[0].end
= 0x1FFFFFFF;
462 platform_device_register(&mtd_dev
);