1 From 16dc080062a37c21642bc77fde5391a3416729a4 Mon Sep 17 00:00:00 2001
2 From: Maxime Bizon <mbizon@freebox.fr>
3 Date: Wed, 17 Sep 2008 15:55:36 +0200
4 Subject: [PATCH] [MIPS] BCM63XX: Add preliminary board support.
6 Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
8 arch/mips/bcm63xx/Kconfig | 2 +
9 arch/mips/bcm63xx/Makefile | 2 +
10 arch/mips/bcm63xx/boards/Kconfig | 10 +
11 arch/mips/bcm63xx/boards/Makefile | 1 +
12 arch/mips/bcm63xx/boards/board_bcm963xx.c | 328 ++++++++++++++++++++++++
13 arch/mips/bcm63xx/prom.c | 4 +
14 arch/mips/bcm63xx/setup.c | 16 +-
15 include/asm-mips/mach-bcm63xx/bcm63xx_board.h | 12 +
16 include/asm-mips/mach-bcm63xx/board_bcm963xx.h | 50 ++++
17 9 files changed, 423 insertions(+), 2 deletions(-)
18 create mode 100644 arch/mips/bcm63xx/boards/Kconfig
19 create mode 100644 arch/mips/bcm63xx/boards/Makefile
20 create mode 100644 arch/mips/bcm63xx/boards/board_bcm963xx.c
21 create mode 100644 include/asm-mips/mach-bcm63xx/bcm63xx_board.h
22 create mode 100644 include/asm-mips/mach-bcm63xx/board_bcm963xx.h
24 --- a/arch/mips/bcm63xx/Kconfig
25 +++ b/arch/mips/bcm63xx/Kconfig
26 @@ -17,3 +17,5 @@ config BCM63XX_CPU_6358
27 select USB_ARCH_HAS_EHCI
28 select USB_EHCI_BIG_ENDIAN_MMIO
31 +source "arch/mips/bcm63xx/boards/Kconfig"
32 --- a/arch/mips/bcm63xx/Makefile
33 +++ b/arch/mips/bcm63xx/Makefile
34 @@ -5,3 +5,5 @@ obj-y += dev-usb-ohci.o
35 obj-y += dev-usb-ehci.o
37 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
41 +++ b/arch/mips/bcm63xx/boards/Kconfig
44 + prompt "Board support"
46 + default BOARD_BCM963XX
48 +config BOARD_BCM963XX
49 + bool "Generic Broadcom 963xx boards"
54 +++ b/arch/mips/bcm63xx/boards/Makefile
56 +obj-$(CONFIG_BOARD_BCM963XX) += board_bcm963xx.o
58 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
61 + * This file is subject to the terms and conditions of the GNU General Public
62 + * License. See the file "COPYING" in the main directory of this archive
65 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
68 +#include <linux/init.h>
69 +#include <linux/kernel.h>
70 +#include <linux/string.h>
71 +#include <linux/platform_device.h>
72 +#include <linux/mtd/mtd.h>
73 +#include <linux/mtd/partitions.h>
74 +#include <linux/mtd/physmap.h>
75 +#include <asm/addrspace.h>
76 +#include <bcm63xx_board.h>
77 +#include <bcm63xx_cpu.h>
78 +#include <bcm63xx_regs.h>
79 +#include <bcm63xx_io.h>
80 +#include <bcm63xx_board.h>
81 +#include <bcm63xx_dev_pci.h>
82 +#include <bcm63xx_dev_uart.h>
83 +#include <bcm63xx_dev_enet.h>
84 +#include <bcm63xx_dev_pcmcia.h>
85 +#include <bcm63xx_dev_usb_ohci.h>
86 +#include <bcm63xx_dev_usb_ehci.h>
87 +#include <board_bcm963xx.h>
89 +#define PFX "board_bcm963xx: "
91 +static struct bcm963xx_nvram nvram;
92 +static unsigned int mac_addr_used = 0;
93 +static struct board_info board;
98 +#ifdef CONFIG_BCM63XX_CPU_6348
99 +static struct board_info __initdata board_96348r = {
101 + .expected_cpu_id = 0x6348,
108 + .use_internal_phy = 1,
112 +static struct board_info __initdata board_96348gw_11 = {
113 + .name = "96348GW-11",
114 + .expected_cpu_id = 0x6348,
122 + .use_internal_phy = 1,
126 + .force_speed_100 = 1,
127 + .force_duplex_full = 1,
136 +static struct board_info __initdata board_96348gw = {
138 + .expected_cpu_id = 0x6348,
146 + .use_internal_phy = 1,
149 + .force_speed_100 = 1,
150 + .force_duplex_full = 1,
156 + * known 6358 boards
158 +#ifdef CONFIG_BCM63XX_CPU_6358
159 +static struct board_info __initdata board_96358vw2 = {
160 + .name = "96358VW2",
161 + .expected_cpu_id = 0x6358,
169 + .use_internal_phy = 1,
173 + .force_speed_100 = 1,
174 + .force_duplex_full = 1,
187 +static const struct board_info __initdata *bcm963xx_boards[] = {
188 +#ifdef CONFIG_BCM63XX_CPU_6348
194 +#ifdef CONFIG_BCM63XX_CPU_6358
200 + * early init callback, read nvram data from flash and checksum it
202 +void __init board_prom_init(void)
204 + unsigned int check_len, i;
205 + u8 *boot_addr, *cfe, *p;
206 + char cfe_version[32];
209 + /* read base address of boot chip select (0) */
210 + val = bcm_mpi_readl(MPI_CSBASE_REG(0));
211 + val &= MPI_CSBASE_BASE_MASK;
212 + boot_addr = (u8 *)KSEG1ADDR(val);
214 + /* dump cfe version */
215 + cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
216 + if (!memcmp(cfe, "cfe-v", 5))
217 + snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
218 + cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
220 + strcpy(cfe_version, "unknown");
221 + printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
223 + /* extract nvram data */
224 + memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
226 + /* check checksum before using data */
227 + if (nvram.version <= 4)
228 + check_len = offsetof(struct bcm963xx_nvram, checksum_old);
230 + check_len = sizeof(nvram);
233 + while (check_len--)
236 + printk(KERN_ERR PFX "invalid nvram checksum\n");
240 + /* find board by name */
241 + for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
242 + if (strncmp(nvram.name, bcm963xx_boards[i]->name,
243 + sizeof(nvram.name)))
245 + /* copy, board desc array is marked initdata */
246 + memcpy(&board, bcm963xx_boards[i], sizeof(board));
250 + /* bail out if board is not found, will complain later */
251 + if (!board.name[0]) {
253 + memcpy(name, nvram.name, 16);
255 + printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
260 + /* setup pin multiplexing depending on board enabled device,
261 + * this has to be done this early since PCI init is done
262 + * inside arch_initcall */
265 + if (board.has_pci) {
266 + bcm63xx_pci_enabled = 1;
267 + if (BCMCPU_IS_6348())
268 + val |= GPIO_MODE_6348_G2_PCI;
271 + if (board.has_pccard) {
272 + if (BCMCPU_IS_6348())
273 + val |= GPIO_MODE_6348_G1_MII_PCCARD;
276 + if (board.has_enet0 && !board.enet0.use_internal_phy) {
277 + if (BCMCPU_IS_6348())
278 + val |= GPIO_MODE_6348_G3_EXT_MII |
279 + GPIO_MODE_6348_G0_EXT_MII;
282 + if (board.has_enet1 && !board.enet1.use_internal_phy) {
283 + if (BCMCPU_IS_6348())
284 + val |= GPIO_MODE_6348_G3_EXT_MII |
285 + GPIO_MODE_6348_G0_EXT_MII;
288 + bcm_gpio_writel(val, GPIO_MODE_REG);
292 + * second stage init callback, good time to panic if we couldn't
293 + * identify on which board we're running since early printk is working
295 +void __init board_setup(void)
297 + if (!board.name[0])
298 + panic("unable to detect bcm963xx board");
299 + printk(KERN_INFO PFX "board name: %s\n", board.name);
301 + /* make sure we're running on expected cpu */
302 + if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
303 + panic("unexpected CPU for bcm963xx board");
307 + * return board name for /proc/cpuinfo
309 +const char *board_get_name(void)
315 + * register & return a new board mac address
317 +static int board_get_mac_address(u8 *mac)
322 + if (mac_addr_used >= nvram.mac_addr_count) {
323 + printk(KERN_ERR PFX "not enough mac address\n");
327 + memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
328 + p = mac + ETH_ALEN - 1;
329 + count = mac_addr_used;
337 + } while (p != mac);
341 + printk(KERN_ERR PFX "unable to fetch mac address\n");
349 +static struct mtd_partition mtd_partitions[] = {
357 +static struct physmap_flash_data flash_data = {
359 + .nr_parts = ARRAY_SIZE(mtd_partitions),
360 + .parts = mtd_partitions,
363 +static struct resource mtd_resources[] = {
365 + .start = 0, /* filled at runtime */
366 + .end = 0, /* filled at runtime */
367 + .flags = IORESOURCE_MEM,
371 +static struct platform_device mtd_dev = {
372 + .name = "physmap-flash",
373 + .resource = mtd_resources,
374 + .num_resources = ARRAY_SIZE(mtd_resources),
376 + .platform_data = &flash_data,
381 + * third stage init callback, register all board devices.
383 +int __init board_register_devices(void)
387 + bcm63xx_uart_register();
389 + if (board.has_pccard)
390 + bcm63xx_pcmcia_register();
392 + if (board.has_enet0 &&
393 + !board_get_mac_address(board.enet0.mac_addr))
394 + bcm63xx_enet_register(0, &board.enet0);
396 + if (board.has_enet1 &&
397 + !board_get_mac_address(board.enet1.mac_addr))
398 + bcm63xx_enet_register(1, &board.enet1);
400 + if (board.has_ohci0)
401 + bcm63xx_ohci_register();
403 + if (board.has_ehci0)
404 + bcm63xx_ehci_register();
407 + /* read base address of boot chip select (0) */
408 + val = bcm_mpi_readl(MPI_CSBASE_REG(0));
409 + val &= MPI_CSBASE_BASE_MASK;
410 + mtd_resources[0].start = val;
411 + mtd_resources[0].end = 0x1FFFFFFF;
413 + platform_device_register(&mtd_dev);
418 --- a/arch/mips/bcm63xx/prom.c
419 +++ b/arch/mips/bcm63xx/prom.c
421 #include <linux/init.h>
422 #include <linux/bootmem.h>
423 #include <asm/bootinfo.h>
424 +#include <bcm63xx_board.h>
425 #include <bcm63xx_cpu.h>
426 #include <bcm63xx_io.h>
427 #include <bcm63xx_regs.h>
428 @@ -36,6 +37,9 @@ void __init prom_init(void)
430 /* assign command line from kernel config */
431 strcpy(arcs_cmdline, CONFIG_CMDLINE);
433 + /* do low level board init */
437 void __init prom_free_prom_memory(void)
438 --- a/arch/mips/bcm63xx/setup.c
439 +++ b/arch/mips/bcm63xx/setup.c
441 #include <asm/time.h>
442 #include <asm/reboot.h>
443 #include <asm/cacheflush.h>
444 +#include <bcm63xx_board.h>
445 #include <bcm63xx_cpu.h>
446 #include <bcm63xx_regs.h>
447 #include <bcm63xx_io.h>
448 @@ -87,8 +88,9 @@ static void __bcm63xx_machine_reboot(cha
449 const char *get_system_type(void)
451 static char buf[128];
452 - sprintf(buf, "bcm963xx (0x%04x/0x%04X)",
453 - bcm63xx_get_cpu_id(), bcm63xx_get_cpu_rev());
454 + snprintf(buf, sizeof (buf), "bcm63xx/%s (0x%04x/0x%04X)",
456 + bcm63xx_get_cpu_id(), bcm63xx_get_cpu_rev());
460 @@ -96,6 +98,7 @@ void __init plat_time_init(void)
462 mips_hpt_frequency = bcm63xx_get_cpu_freq() / 2;
465 void __init plat_mem_setup(void)
467 add_memory_region(0, bcm63xx_get_memory_size(), BOOT_MEM_RAM);
468 @@ -107,4 +110,13 @@ void __init plat_mem_setup(void)
470 ioport_resource.start = 0;
471 ioport_resource.end = ~0;
476 +int __init bcm63xx_register_devices(void)
478 + return board_register_devices();
481 +device_initcall(bcm63xx_register_devices);
483 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_board.h
485 +#ifndef BCM63XX_BOARD_H_
486 +#define BCM63XX_BOARD_H_
488 +const char *board_get_name(void);
490 +void board_prom_init(void);
492 +void board_setup(void);
494 +int board_register_devices(void);
496 +#endif /* ! BCM63XX_BOARD_H_ */
498 +++ b/include/asm-mips/mach-bcm63xx/board_bcm963xx.h
500 +#ifndef BOARD_BCM963XX_H_
501 +#define BOARD_BCM963XX_H_
503 +#include <linux/types.h>
504 +#include <bcm63xx_dev_enet.h>
509 +#define BCM963XX_CFE_VERSION_OFFSET 0x570
510 +#define BCM963XX_NVRAM_OFFSET 0x580
515 +struct bcm963xx_nvram {
519 + u32 main_tp_number;
521 + u32 mac_addr_count;
522 + u8 mac_addr_base[6];
534 + unsigned int expected_cpu_id;
536 + /* enabled feature/device */
537 + unsigned int has_enet0:1;
538 + unsigned int has_enet1:1;
539 + unsigned int has_pci:1;
540 + unsigned int has_pccard:1;
541 + unsigned int has_ohci0:1;
542 + unsigned int has_ehci0:1;
544 + /* ethernet config */
545 + struct bcm63xx_enet_platform_data enet0;
546 + struct bcm63xx_enet_platform_data enet1;
549 +#endif /* ! BOARD_BCM963XX_H_ */