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
;
40 #ifdef CONFIG_BCM63XX_CPU_6348
41 static struct board_info __initdata board_96348r
= {
43 .expected_cpu_id
= 0x6348,
50 .use_internal_phy
= 1,
54 static struct board_info __initdata board_96348gw_10
= {
56 .expected_cpu_id
= 0x6348,
64 .use_internal_phy
= 1,
68 .force_duplex_full
= 1,
76 static struct board_info __initdata board_96348gw_11
= {
78 .expected_cpu_id
= 0x6348,
86 .use_internal_phy
= 1,
91 .force_duplex_full
= 1,
100 static struct board_info __initdata board_96348gw
= {
102 .expected_cpu_id
= 0x6348,
110 .use_internal_phy
= 1,
113 .force_speed_100
= 1,
114 .force_duplex_full
= 1,
120 static struct board_info __initdata board_FAST2404
= {
122 .expected_cpu_id
= 0x6348,
130 .use_internal_phy
= 1,
134 .force_speed_100
= 1,
135 .force_duplex_full
= 1,
149 #ifdef CONFIG_BCM63XX_CPU_6358
150 static struct board_info __initdata board_96358vw
= {
152 .expected_cpu_id
= 0x6358,
160 .use_internal_phy
= 1,
164 .force_speed_100
= 1,
165 .force_duplex_full
= 1,
174 static struct board_info __initdata board_96358vw2
= {
176 .expected_cpu_id
= 0x6358,
184 .use_internal_phy
= 1,
188 .force_speed_100
= 1,
189 .force_duplex_full
= 1,
202 static const struct board_info __initdata
*bcm963xx_boards
[] = {
203 #ifdef CONFIG_BCM63XX_CPU_6348
211 #ifdef CONFIG_BCM63XX_CPU_6358
218 * early init callback, read nvram data from flash and checksum it
220 void __init
board_prom_init(void)
222 unsigned int check_len
, i
;
223 u8
*boot_addr
, *cfe
, *p
;
224 char cfe_version
[32];
227 /* read base address of boot chip select (0) */
228 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
229 val
&= MPI_CSBASE_BASE_MASK
;
230 boot_addr
= (u8
*)KSEG1ADDR(val
);
232 /* dump cfe version */
233 cfe
= boot_addr
+ BCM963XX_CFE_VERSION_OFFSET
;
234 if (!memcmp(cfe
, "cfe-v", 5))
235 snprintf(cfe_version
, sizeof(cfe_version
), "%u.%u.%u-%u.%u",
236 cfe
[5], cfe
[6], cfe
[7], cfe
[8], cfe
[9]);
238 strcpy(cfe_version
, "unknown");
239 printk(KERN_INFO PFX
"CFE version: %s\n", cfe_version
);
241 /* extract nvram data */
242 memcpy(&nvram
, boot_addr
+ BCM963XX_NVRAM_OFFSET
, sizeof(nvram
));
244 /* check checksum before using data */
245 if (nvram
.version
<= 4)
246 check_len
= offsetof(struct bcm963xx_nvram
, checksum_old
);
248 check_len
= sizeof(nvram
);
254 printk(KERN_ERR PFX
"invalid nvram checksum\n");
258 /* find board by name */
259 for (i
= 0; i
< ARRAY_SIZE(bcm963xx_boards
); i
++) {
260 if (strncmp(nvram
.name
, bcm963xx_boards
[i
]->name
,
263 /* copy, board desc array is marked initdata */
264 memcpy(&board
, bcm963xx_boards
[i
], sizeof(board
));
268 /* bail out if board is not found, will complain later */
269 if (!board
.name
[0]) {
271 memcpy(name
, nvram
.name
, 16);
273 printk(KERN_ERR PFX
"unknown bcm963xx board: %s\n",
278 /* setup pin multiplexing depending on board enabled device,
279 * this has to be done this early since PCI init is done
280 * inside arch_initcall */
284 bcm63xx_pci_enabled
= 1;
285 if (BCMCPU_IS_6348())
286 val
|= GPIO_MODE_6348_G2_PCI
;
289 if (board
.has_pccard
) {
290 if (BCMCPU_IS_6348())
291 val
|= GPIO_MODE_6348_G1_MII_PCCARD
;
294 if (board
.has_enet0
&& !board
.enet0
.use_internal_phy
) {
295 if (BCMCPU_IS_6348())
296 val
|= GPIO_MODE_6348_G3_EXT_MII
|
297 GPIO_MODE_6348_G0_EXT_MII
;
300 if (board
.has_enet1
&& !board
.enet1
.use_internal_phy
) {
301 if (BCMCPU_IS_6348())
302 val
|= GPIO_MODE_6348_G3_EXT_MII
|
303 GPIO_MODE_6348_G0_EXT_MII
;
306 bcm_gpio_writel(val
, GPIO_MODE_REG
);
310 * second stage init callback, good time to panic if we couldn't
311 * identify on which board we're running since early printk is working
313 void __init
board_setup(void)
316 panic("unable to detect bcm963xx board");
317 printk(KERN_INFO PFX
"board name: %s\n", board
.name
);
319 /* make sure we're running on expected cpu */
320 if (bcm63xx_get_cpu_id() != board
.expected_cpu_id
)
321 panic("unexpected CPU for bcm963xx board");
325 * return board name for /proc/cpuinfo
327 const char *board_get_name(void)
333 * register & return a new board mac address
335 static int board_get_mac_address(u8
*mac
)
340 if (mac_addr_used
>= nvram
.mac_addr_count
) {
341 printk(KERN_ERR PFX
"not enough mac address\n");
345 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
346 p
= mac
+ ETH_ALEN
- 1;
347 count
= mac_addr_used
;
359 printk(KERN_ERR PFX
"unable to fetch mac address\n");
367 static struct resource mtd_resources
[] = {
369 .start
= 0, /* filled at runtime */
370 .end
= 0, /* filled at runtime */
371 .flags
= IORESOURCE_MEM
,
375 static struct platform_device mtd_dev
= {
376 .name
= "bcm963xx-flash",
377 .resource
= mtd_resources
,
378 .num_resources
= ARRAY_SIZE(mtd_resources
),
382 * third stage init callback, register all board devices.
384 int __init
board_register_devices(void)
388 bcm63xx_uart_register();
389 bcm63xx_wdt_register();
391 if (board
.has_pccard
)
392 bcm63xx_pcmcia_register();
394 if (board
.has_enet0
&&
395 !board_get_mac_address(board
.enet0
.mac_addr
))
396 bcm63xx_enet_register(0, &board
.enet0
);
398 if (board
.has_enet1
&&
399 !board_get_mac_address(board
.enet1
.mac_addr
))
400 bcm63xx_enet_register(1, &board
.enet1
);
403 bcm63xx_ohci_register();
406 bcm63xx_ehci_register();
409 /* read base address of boot chip select (0) */
410 val
= bcm_mpi_readl(MPI_CSBASE_REG(0));
411 val
&= MPI_CSBASE_BASE_MASK
;
412 mtd_resources
[0].start
= val
;
413 mtd_resources
[0].end
= 0x1FFFFFFF;
415 platform_device_register(&mtd_dev
);