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_enet.h>
25 #include <bcm63xx_dev_pcmcia.h>
26 #include <bcm63xx_dev_usb_ohci.h>
27 #include <bcm63xx_dev_usb_ehci.h>
28 #include <board_bcm963xx.h>
30 #define PFX "board_bcm963xx: "
32 static struct bcm963xx_nvram nvram;
33 static unsigned int mac_addr_used = 0;
34 static struct board_info board;
39 #ifdef CONFIG_BCM63XX_CPU_6348
40 static struct board_info __initdata board_96348r = {
42 .expected_cpu_id = 0x6348,
49 .use_internal_phy = 1,
53 static struct board_info __initdata board_96348gw_10 = {
55 .expected_cpu_id = 0x6348,
63 .use_internal_phy = 1,
67 .force_duplex_full = 1,
75 static struct board_info __initdata board_96348gw_11 = {
77 .expected_cpu_id = 0x6348,
85 .use_internal_phy = 1,
90 .force_duplex_full = 1,
99 static struct board_info __initdata board_96348gw = {
101 .expected_cpu_id = 0x6348,
109 .use_internal_phy = 1,
112 .force_speed_100 = 1,
113 .force_duplex_full = 1,
123 #ifdef CONFIG_BCM63XX_CPU_6358
124 static struct board_info __initdata board_96358vw = {
126 .expected_cpu_id = 0x6358,
134 .use_internal_phy = 1,
138 .force_speed_100 = 1,
139 .force_duplex_full = 1,
148 static struct board_info __initdata board_96358vw2 = {
150 .expected_cpu_id = 0x6358,
158 .use_internal_phy = 1,
162 .force_speed_100 = 1,
163 .force_duplex_full = 1,
176 static const struct board_info __initdata *bcm963xx_boards[] = {
177 #ifdef CONFIG_BCM63XX_CPU_6348
184 #ifdef CONFIG_BCM63XX_CPU_6358
191 * early init callback, read nvram data from flash and checksum it
193 void __init board_prom_init(void)
195 unsigned int check_len, i;
196 u8 *boot_addr, *cfe, *p;
197 char cfe_version[32];
200 /* read base address of boot chip select (0) */
201 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
202 val &= MPI_CSBASE_BASE_MASK;
203 boot_addr = (u8 *)KSEG1ADDR(val);
205 /* dump cfe version */
206 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
207 if (!memcmp(cfe, "cfe-v", 5))
208 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
209 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
211 strcpy(cfe_version, "unknown");
212 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
214 /* extract nvram data */
215 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
217 /* check checksum before using data */
218 if (nvram.version <= 4)
219 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
221 check_len = sizeof(nvram);
227 printk(KERN_ERR PFX "invalid nvram checksum\n");
231 /* find board by name */
232 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
233 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
236 /* copy, board desc array is marked initdata */
237 memcpy(&board, bcm963xx_boards[i], sizeof(board));
241 /* bail out if board is not found, will complain later */
242 if (!board.name[0]) {
244 memcpy(name, nvram.name, 16);
246 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
251 /* setup pin multiplexing depending on board enabled device,
252 * this has to be done this early since PCI init is done
253 * inside arch_initcall */
257 bcm63xx_pci_enabled = 1;
258 if (BCMCPU_IS_6348())
259 val |= GPIO_MODE_6348_G2_PCI;
262 if (board.has_pccard) {
263 if (BCMCPU_IS_6348())
264 val |= GPIO_MODE_6348_G1_MII_PCCARD;
267 if (board.has_enet0 && !board.enet0.use_internal_phy) {
268 if (BCMCPU_IS_6348())
269 val |= GPIO_MODE_6348_G3_EXT_MII |
270 GPIO_MODE_6348_G0_EXT_MII;
273 if (board.has_enet1 && !board.enet1.use_internal_phy) {
274 if (BCMCPU_IS_6348())
275 val |= GPIO_MODE_6348_G3_EXT_MII |
276 GPIO_MODE_6348_G0_EXT_MII;
279 bcm_gpio_writel(val, GPIO_MODE_REG);
283 * second stage init callback, good time to panic if we couldn't
284 * identify on which board we're running since early printk is working
286 void __init board_setup(void)
289 panic("unable to detect bcm963xx board");
290 printk(KERN_INFO PFX "board name: %s\n", board.name);
292 /* make sure we're running on expected cpu */
293 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
294 panic("unexpected CPU for bcm963xx board");
298 * return board name for /proc/cpuinfo
300 const char *board_get_name(void)
306 * register & return a new board mac address
308 static int board_get_mac_address(u8 *mac)
313 if (mac_addr_used >= nvram.mac_addr_count) {
314 printk(KERN_ERR PFX "not enough mac address\n");
318 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
319 p = mac + ETH_ALEN - 1;
320 count = mac_addr_used;
332 printk(KERN_ERR PFX "unable to fetch mac address\n");
340 static struct resource mtd_resources[] = {
342 .start = 0, /* filled at runtime */
343 .end = 0, /* filled at runtime */
344 .flags = IORESOURCE_MEM,
348 static struct platform_device mtd_dev = {
349 .name = "bcm963xx-flash",
350 .resource = mtd_resources,
351 .num_resources = ARRAY_SIZE(mtd_resources),
355 * third stage init callback, register all board devices.
357 int __init board_register_devices(void)
361 bcm63xx_uart_register();
363 if (board.has_pccard)
364 bcm63xx_pcmcia_register();
366 if (board.has_enet0 &&
367 !board_get_mac_address(board.enet0.mac_addr))
368 bcm63xx_enet_register(0, &board.enet0);
370 if (board.has_enet1 &&
371 !board_get_mac_address(board.enet1.mac_addr))
372 bcm63xx_enet_register(1, &board.enet1);
375 bcm63xx_ohci_register();
378 bcm63xx_ehci_register();
381 /* read base address of boot chip select (0) */
382 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
383 val &= MPI_CSBASE_BASE_MASK;
384 mtd_resources[0].start = val;
385 mtd_resources[0].end = 0x1FFFFFFF;
387 platform_device_register(&mtd_dev);