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 = {
114 + .expected_cpu_id = 0x6348,
121 + .use_internal_phy = 1,
127 + * known 6358 boards
129 +#ifdef CONFIG_BCM63XX_CPU_6358
130 +static struct board_info __initdata board_96358vw2 = {
131 + .name = "96358VW2",
132 + .expected_cpu_id = 0x6358,
140 + .use_internal_phy = 1,
144 + .force_speed_100 = 1,
145 + .force_duplex_full = 1,
158 +static const struct board_info __initdata *bcm963xx_boards[] = {
159 +#ifdef CONFIG_BCM63XX_CPU_6348
164 +#ifdef CONFIG_BCM63XX_CPU_6358
170 + * early init callback, read nvram data from flash and checksum it
172 +void __init board_prom_init(void)
174 + unsigned int check_len, i;
175 + u8 *boot_addr, *cfe, *p;
176 + char cfe_version[32];
179 + /* read base address of boot chip select (0) */
180 + val = bcm_mpi_readl(MPI_CSBASE_REG(0));
181 + val &= MPI_CSBASE_BASE_MASK;
182 + boot_addr = (u8 *)KSEG1ADDR(val);
184 + /* dump cfe version */
185 + cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
186 + if (!memcmp(cfe, "cfe-v", 5))
187 + snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
188 + cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
190 + strcpy(cfe_version, "unknown");
191 + printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
193 + /* extract nvram data */
194 + memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
196 + /* check checksum before using data */
197 + if (nvram.version <= 4)
198 + check_len = offsetof(struct bcm963xx_nvram, checksum_old);
200 + check_len = sizeof(nvram);
203 + while (check_len--)
206 + printk(KERN_ERR PFX "invalid nvram checksum\n");
210 + /* find board by name */
211 + for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
212 + if (strncmp(nvram.name, bcm963xx_boards[i]->name,
213 + sizeof(nvram.name)))
215 + /* copy, board desc array is marked initdata */
216 + memcpy(&board, bcm963xx_boards[i], sizeof(board));
220 + /* bail out if board is not found, will complain later */
221 + if (!board.name[0]) {
223 + memcpy(name, nvram.name, 16);
225 + printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
230 + /* setup pin multiplexing depending on board enabled device,
231 + * this has to be done this early since PCI init is done
232 + * inside arch_initcall */
235 + if (board.has_pci) {
236 + bcm63xx_pci_enabled = 1;
237 + if (BCMCPU_IS_6348())
238 + val |= GPIO_MODE_6348_G2_PCI;
241 + if (board.has_pccard) {
242 + if (BCMCPU_IS_6348())
243 + val |= GPIO_MODE_6348_G1_MII_PCCARD;
246 + if (board.has_enet0 && !board.enet0.use_internal_phy) {
247 + if (BCMCPU_IS_6348())
248 + val |= GPIO_MODE_6348_G3_EXT_MII |
249 + GPIO_MODE_6348_G0_EXT_MII;
252 + if (board.has_enet1 && !board.enet1.use_internal_phy) {
253 + if (BCMCPU_IS_6348())
254 + val |= GPIO_MODE_6348_G3_EXT_MII |
255 + GPIO_MODE_6348_G0_EXT_MII;
258 + bcm_gpio_writel(val, GPIO_MODE_REG);
262 + * second stage init callback, good time to panic if we couldn't
263 + * identify on which board we're running since early printk is working
265 +void __init board_setup(void)
267 + if (!board.name[0])
268 + panic("unable to detect bcm963xx board");
269 + printk(KERN_INFO PFX "board name: %s\n", board.name);
271 + /* make sure we're running on expected cpu */
272 + if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
273 + panic("unexpected CPU for bcm963xx board");
277 + * return board name for /proc/cpuinfo
279 +const char *board_get_name(void)
285 + * register & return a new board mac address
287 +static int board_get_mac_address(u8 *mac)
292 + if (mac_addr_used >= nvram.mac_addr_count) {
293 + printk(KERN_ERR PFX "not enough mac address\n");
297 + memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
298 + p = mac + ETH_ALEN - 1;
299 + count = mac_addr_used;
307 + } while (p != mac);
311 + printk(KERN_ERR PFX "unable to fetch mac address\n");
319 +static struct mtd_partition mtd_partitions[] = {
327 +static struct physmap_flash_data flash_data = {
329 + .nr_parts = ARRAY_SIZE(mtd_partitions),
330 + .parts = mtd_partitions,
333 +static struct resource mtd_resources[] = {
335 + .start = 0, /* filled at runtime */
336 + .end = 0, /* filled at runtime */
337 + .flags = IORESOURCE_MEM,
341 +static struct platform_device mtd_dev = {
342 + .name = "physmap-flash",
343 + .resource = mtd_resources,
344 + .num_resources = ARRAY_SIZE(mtd_resources),
346 + .platform_data = &flash_data,
351 + * third stage init callback, register all board devices.
353 +int __init board_register_devices(void)
357 + bcm63xx_uart_register();
359 + if (board.has_pccard)
360 + bcm63xx_pcmcia_register();
362 + if (board.has_enet0 &&
363 + !board_get_mac_address(board.enet0.mac_addr))
364 + bcm63xx_enet_register(0, &board.enet0);
366 + if (board.has_enet1 &&
367 + !board_get_mac_address(board.enet1.mac_addr))
368 + bcm63xx_enet_register(1, &board.enet1);
370 + if (board.has_ohci0)
371 + bcm63xx_ohci_register();
373 + if (board.has_ehci0)
374 + bcm63xx_ehci_register();
377 + /* read base address of boot chip select (0) */
378 + val = bcm_mpi_readl(MPI_CSBASE_REG(0));
379 + val &= MPI_CSBASE_BASE_MASK;
380 + mtd_resources[0].start = val;
381 + mtd_resources[0].end = 0x1FFFFFFF;
383 + platform_device_register(&mtd_dev);
388 --- a/arch/mips/bcm63xx/prom.c
389 +++ b/arch/mips/bcm63xx/prom.c
391 #include <linux/init.h>
392 #include <linux/bootmem.h>
393 #include <asm/bootinfo.h>
394 +#include <bcm63xx_board.h>
395 #include <bcm63xx_cpu.h>
396 #include <bcm63xx_io.h>
397 #include <bcm63xx_regs.h>
398 @@ -36,6 +37,9 @@ void __init prom_init(void)
400 /* assign command line from kernel config */
401 strcpy(arcs_cmdline, CONFIG_CMDLINE);
403 + /* do low level board init */
407 void __init prom_free_prom_memory(void)
408 --- a/arch/mips/bcm63xx/setup.c
409 +++ b/arch/mips/bcm63xx/setup.c
411 #include <asm/time.h>
412 #include <asm/reboot.h>
413 #include <asm/cacheflush.h>
414 +#include <bcm63xx_board.h>
415 #include <bcm63xx_cpu.h>
416 #include <bcm63xx_regs.h>
417 #include <bcm63xx_io.h>
418 @@ -87,8 +88,9 @@ static void __bcm63xx_machine_reboot(cha
419 const char *get_system_type(void)
421 static char buf[128];
422 - sprintf(buf, "bcm963xx (0x%04x/0x%04X)",
423 - bcm63xx_get_cpu_id(), bcm63xx_get_cpu_rev());
424 + snprintf(buf, sizeof (buf), "bcm63xx/%s (0x%04x/0x%04X)",
426 + bcm63xx_get_cpu_id(), bcm63xx_get_cpu_rev());
430 @@ -96,6 +98,7 @@ void __init plat_time_init(void)
432 mips_hpt_frequency = bcm63xx_get_cpu_freq() / 2;
435 void __init plat_mem_setup(void)
437 add_memory_region(0, bcm63xx_get_memory_size(), BOOT_MEM_RAM);
438 @@ -107,4 +110,13 @@ void __init plat_mem_setup(void)
440 ioport_resource.start = 0;
441 ioport_resource.end = ~0;
446 +int __init bcm63xx_register_devices(void)
448 + return board_register_devices();
451 +device_initcall(bcm63xx_register_devices);
453 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_board.h
455 +#ifndef BCM63XX_BOARD_H_
456 +#define BCM63XX_BOARD_H_
458 +const char *board_get_name(void);
460 +void board_prom_init(void);
462 +void board_setup(void);
464 +int board_register_devices(void);
466 +#endif /* ! BCM63XX_BOARD_H_ */
468 +++ b/include/asm-mips/mach-bcm63xx/board_bcm963xx.h
470 +#ifndef BOARD_BCM963XX_H_
471 +#define BOARD_BCM963XX_H_
473 +#include <linux/types.h>
474 +#include <bcm63xx_dev_enet.h>
479 +#define BCM963XX_CFE_VERSION_OFFSET 0x570
480 +#define BCM963XX_NVRAM_OFFSET 0x580
485 +struct bcm963xx_nvram {
489 + u32 main_tp_number;
491 + u32 mac_addr_count;
492 + u8 mac_addr_base[6];
504 + unsigned int expected_cpu_id;
506 + /* enabled feature/device */
507 + unsigned int has_enet0:1;
508 + unsigned int has_enet1:1;
509 + unsigned int has_pci:1;
510 + unsigned int has_pccard:1;
511 + unsigned int has_ohci0:1;
512 + unsigned int has_ehci0:1;
514 + /* ethernet config */
515 + struct bcm63xx_enet_platform_data enet0;
516 + struct bcm63xx_enet_platform_data enet1;
519 +#endif /* ! BOARD_BCM963XX_H_ */