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 diff --git a/arch/mips/bcm63xx/Kconfig b/arch/mips/bcm63xx/Kconfig
25 index be120f7..8c192e7 100644
26 --- a/arch/mips/bcm63xx/Kconfig
27 +++ b/arch/mips/bcm63xx/Kconfig
28 @@ -17,3 +17,5 @@ config BCM63XX_CPU_6358
29 select USB_ARCH_HAS_EHCI
30 select USB_EHCI_BIG_ENDIAN_MMIO
33 +source "arch/mips/bcm63xx/boards/Kconfig"
34 diff --git a/arch/mips/bcm63xx/Makefile b/arch/mips/bcm63xx/Makefile
35 index 5358093..10462ae 100644
36 --- a/arch/mips/bcm63xx/Makefile
37 +++ b/arch/mips/bcm63xx/Makefile
38 @@ -5,3 +5,5 @@ obj-y += dev-usb-ohci.o
39 obj-y += dev-usb-ehci.o
41 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
44 diff --git a/arch/mips/bcm63xx/boards/Kconfig b/arch/mips/bcm63xx/boards/Kconfig
46 index 0000000..da5eeaa
48 +++ b/arch/mips/bcm63xx/boards/Kconfig
51 + prompt "Board support"
53 + default BOARD_BCM963XX
55 +config BOARD_BCM963XX
56 + bool "Generic Broadcom 963xx boards"
60 diff --git a/arch/mips/bcm63xx/boards/Makefile b/arch/mips/bcm63xx/boards/Makefile
62 index 0000000..af07c1a
64 +++ b/arch/mips/bcm63xx/boards/Makefile
66 +obj-$(CONFIG_BOARD_BCM963XX) += board_bcm963xx.o
67 diff --git a/arch/mips/bcm63xx/boards/board_bcm963xx.c b/arch/mips/bcm63xx/boards/board_bcm963xx.c
69 index 0000000..6e2b4ae
71 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
74 + * This file is subject to the terms and conditions of the GNU General Public
75 + * License. See the file "COPYING" in the main directory of this archive
78 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
81 +#include <linux/init.h>
82 +#include <linux/kernel.h>
83 +#include <linux/string.h>
84 +#include <linux/platform_device.h>
85 +#include <linux/mtd/mtd.h>
86 +#include <linux/mtd/partitions.h>
87 +#include <linux/mtd/physmap.h>
88 +#include <asm/addrspace.h>
89 +#include <bcm63xx_board.h>
90 +#include <bcm63xx_cpu.h>
91 +#include <bcm63xx_regs.h>
92 +#include <bcm63xx_io.h>
93 +#include <bcm63xx_board.h>
94 +#include <bcm63xx_dev_pci.h>
95 +#include <bcm63xx_dev_uart.h>
96 +#include <bcm63xx_dev_enet.h>
97 +#include <bcm63xx_dev_pcmcia.h>
98 +#include <bcm63xx_dev_usb_ohci.h>
99 +#include <bcm63xx_dev_usb_ehci.h>
100 +#include <board_bcm963xx.h>
102 +#define PFX "board_bcm963xx: "
104 +static struct bcm963xx_nvram nvram;
105 +static unsigned int mac_addr_used = 0;
106 +static struct board_info board;
109 + * known 6348 boards
111 +#ifdef CONFIG_BCM63XX_CPU_6348
112 +static struct board_info __initdata board_96348r = {
114 + .expected_cpu_id = 0x6348,
121 + .use_internal_phy = 1,
125 +static struct board_info __initdata board_96348gw = {
127 + .expected_cpu_id = 0x6348,
134 + .use_internal_phy = 1,
140 + * known 6358 boards
142 +#ifdef CONFIG_BCM63XX_CPU_6358
143 +static struct board_info __initdata board_96358vw2 = {
144 + .name = "96358VW2",
145 + .expected_cpu_id = 0x6358,
153 + .use_internal_phy = 1,
157 + .force_speed_100 = 1,
158 + .force_duplex_full = 1,
171 +static const struct board_info __initdata *bcm963xx_boards[] = {
172 +#ifdef CONFIG_BCM63XX_CPU_6348
177 +#ifdef CONFIG_BCM63XX_CPU_6358
183 + * early init callback, read nvram data from flash and checksum it
185 +void __init board_prom_init(void)
187 + unsigned int check_len, i;
188 + u8 *boot_addr, *cfe, *p;
189 + char cfe_version[32];
192 + /* read base address of boot chip select (0) */
193 + val = bcm_mpi_readl(MPI_CSBASE_REG(0));
194 + val &= MPI_CSBASE_BASE_MASK;
195 + boot_addr = (u8 *)KSEG1ADDR(val);
197 + /* dump cfe version */
198 + cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
199 + if (!memcmp(cfe, "cfe-v", 5))
200 + snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
201 + cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
203 + strcpy(cfe_version, "unknown");
204 + printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
206 + /* extract nvram data */
207 + memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
209 + /* check checksum before using data */
210 + if (nvram.version <= 4)
211 + check_len = offsetof(struct bcm963xx_nvram, checksum_old);
213 + check_len = sizeof(nvram);
216 + while (check_len--)
219 + printk(KERN_ERR PFX "invalid nvram checksum\n");
223 + /* find board by name */
224 + for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
225 + if (strncmp(nvram.name, bcm963xx_boards[i]->name,
226 + sizeof(nvram.name)))
228 + /* copy, board desc array is marked initdata */
229 + memcpy(&board, bcm963xx_boards[i], sizeof(board));
233 + /* bail out if board is not found, will complain later */
234 + if (!board.name[0]) {
236 + memcpy(name, nvram.name, 16);
238 + printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
243 + /* setup pin multiplexing depending on board enabled device,
244 + * this has to be done this early since PCI init is done
245 + * inside arch_initcall */
248 + if (board.has_pci) {
249 + bcm63xx_pci_enabled = 1;
250 + if (BCMCPU_IS_6348())
251 + val |= GPIO_MODE_6348_G2_PCI;
254 + if (board.has_pccard) {
255 + if (BCMCPU_IS_6348())
256 + val |= GPIO_MODE_6348_G1_MII_PCCARD;
259 + if (board.has_enet0 && !board.enet0.use_internal_phy) {
260 + if (BCMCPU_IS_6348())
261 + val |= GPIO_MODE_6348_G3_EXT_MII |
262 + GPIO_MODE_6348_G0_EXT_MII;
265 + if (board.has_enet1 && !board.enet1.use_internal_phy) {
266 + if (BCMCPU_IS_6348())
267 + val |= GPIO_MODE_6348_G3_EXT_MII |
268 + GPIO_MODE_6348_G0_EXT_MII;
271 + bcm_gpio_writel(val, GPIO_MODE_REG);
275 + * second stage init callback, good time to panic if we couldn't
276 + * identify on which board we're running since early printk is working
278 +void __init board_setup(void)
280 + if (!board.name[0])
281 + panic("unable to detect bcm963xx board");
282 + printk(KERN_INFO PFX "board name: %s\n", board.name);
284 + /* make sure we're running on expected cpu */
285 + if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
286 + panic("unexpected CPU for bcm963xx board");
290 + * return board name for /proc/cpuinfo
292 +const char *board_get_name(void)
298 + * register & return a new board mac address
300 +static int board_get_mac_address(u8 *mac)
305 + if (mac_addr_used >= nvram.mac_addr_count) {
306 + printk(KERN_ERR PFX "not enough mac address\n");
310 + memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
311 + p = mac + ETH_ALEN - 1;
312 + count = mac_addr_used;
320 + } while (p != mac);
324 + printk(KERN_ERR PFX "unable to fetch mac address\n");
332 +static struct mtd_partition mtd_partitions[] = {
340 +static struct physmap_flash_data flash_data = {
342 + .nr_parts = ARRAY_SIZE(mtd_partitions),
343 + .parts = mtd_partitions,
346 +static struct resource mtd_resources[] = {
348 + .start = 0, /* filled at runtime */
349 + .end = 0, /* filled at runtime */
350 + .flags = IORESOURCE_MEM,
354 +static struct platform_device mtd_dev = {
355 + .name = "physmap-flash",
356 + .resource = mtd_resources,
357 + .num_resources = ARRAY_SIZE(mtd_resources),
359 + .platform_data = &flash_data,
364 + * third stage init callback, register all board devices.
366 +int __init board_register_devices(void)
370 + bcm63xx_uart_register();
372 + if (board.has_pccard)
373 + bcm63xx_pcmcia_register();
375 + if (board.has_enet0 &&
376 + !board_get_mac_address(board.enet0.mac_addr))
377 + bcm63xx_enet_register(0, &board.enet0);
379 + if (board.has_enet1 &&
380 + !board_get_mac_address(board.enet1.mac_addr))
381 + bcm63xx_enet_register(1, &board.enet1);
383 + if (board.has_ohci0)
384 + bcm63xx_ohci_register();
386 + if (board.has_ehci0)
387 + bcm63xx_ehci_register();
390 + /* read base address of boot chip select (0) */
391 + val = bcm_mpi_readl(MPI_CSBASE_REG(0));
392 + val &= MPI_CSBASE_BASE_MASK;
393 + mtd_resources[0].start = val;
394 + mtd_resources[0].end = 0x1FFFFFFF;
396 + platform_device_register(&mtd_dev);
401 diff --git a/arch/mips/bcm63xx/prom.c b/arch/mips/bcm63xx/prom.c
402 index f0b49e8..d97ceed 100644
403 --- a/arch/mips/bcm63xx/prom.c
404 +++ b/arch/mips/bcm63xx/prom.c
406 #include <linux/init.h>
407 #include <linux/bootmem.h>
408 #include <asm/bootinfo.h>
409 +#include <bcm63xx_board.h>
410 #include <bcm63xx_cpu.h>
411 #include <bcm63xx_io.h>
412 #include <bcm63xx_regs.h>
413 @@ -36,6 +37,9 @@ void __init prom_init(void)
415 /* assign command line from kernel config */
416 strcpy(arcs_cmdline, CONFIG_CMDLINE);
418 + /* do low level board init */
422 void __init prom_free_prom_memory(void)
423 diff --git a/arch/mips/bcm63xx/setup.c b/arch/mips/bcm63xx/setup.c
424 index 4d8b127..c4516fb 100644
425 --- a/arch/mips/bcm63xx/setup.c
426 +++ b/arch/mips/bcm63xx/setup.c
428 #include <asm/time.h>
429 #include <asm/reboot.h>
430 #include <asm/cacheflush.h>
431 +#include <bcm63xx_board.h>
432 #include <bcm63xx_cpu.h>
433 #include <bcm63xx_regs.h>
434 #include <bcm63xx_io.h>
435 @@ -87,8 +88,9 @@ static void __bcm63xx_machine_reboot(char *p)
436 const char *get_system_type(void)
438 static char buf[128];
439 - sprintf(buf, "bcm963xx (0x%04x/0x%04X)",
440 - bcm63xx_get_cpu_id(), bcm63xx_get_cpu_rev());
441 + snprintf(buf, sizeof (buf), "bcm63xx/%s (0x%04x/0x%04X)",
443 + bcm63xx_get_cpu_id(), bcm63xx_get_cpu_rev());
447 @@ -96,6 +98,7 @@ void __init plat_time_init(void)
449 mips_hpt_frequency = bcm63xx_get_cpu_freq() / 2;
452 void __init plat_mem_setup(void)
454 add_memory_region(0, bcm63xx_get_memory_size(), BOOT_MEM_RAM);
455 @@ -107,4 +110,13 @@ void __init plat_mem_setup(void)
457 ioport_resource.start = 0;
458 ioport_resource.end = ~0;
463 +int __init bcm63xx_register_devices(void)
465 + return board_register_devices();
468 +device_initcall(bcm63xx_register_devices);
469 diff --git a/include/asm-mips/mach-bcm63xx/bcm63xx_board.h b/include/asm-mips/mach-bcm63xx/bcm63xx_board.h
471 index 0000000..fa3e7e6
473 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_board.h
475 +#ifndef BCM63XX_BOARD_H_
476 +#define BCM63XX_BOARD_H_
478 +const char *board_get_name(void);
480 +void board_prom_init(void);
482 +void board_setup(void);
484 +int board_register_devices(void);
486 +#endif /* ! BCM63XX_BOARD_H_ */
487 diff --git a/include/asm-mips/mach-bcm63xx/board_bcm963xx.h b/include/asm-mips/mach-bcm63xx/board_bcm963xx.h
489 index 0000000..17e4e7e
491 +++ b/include/asm-mips/mach-bcm63xx/board_bcm963xx.h
493 +#ifndef BOARD_BCM963XX_H_
494 +#define BOARD_BCM963XX_H_
496 +#include <linux/types.h>
497 +#include <bcm63xx_dev_enet.h>
502 +#define BCM963XX_CFE_VERSION_OFFSET 0x570
503 +#define BCM963XX_NVRAM_OFFSET 0x580
508 +struct bcm963xx_nvram {
512 + u32 main_tp_number;
514 + u32 mac_addr_count;
515 + u8 mac_addr_base[6];
527 + unsigned int expected_cpu_id;
529 + /* enabled feature/device */
530 + unsigned int has_enet0:1;
531 + unsigned int has_enet1:1;
532 + unsigned int has_pci:1;
533 + unsigned int has_pccard:1;
534 + unsigned int has_ohci0:1;
535 + unsigned int has_ehci0:1;
537 + /* ethernet config */
538 + struct bcm63xx_enet_platform_data enet0;
539 + struct bcm63xx_enet_platform_data enet1;
542 +#endif /* ! BOARD_BCM963XX_H_ */