1 From b95a2bbbcae5423e5404a7b3c8dd1685e1786f13 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 | 322 ++++++++++++++++++++++++
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, 417 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..de52a2a
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 */
237 + /* setup pin multiplexing depending on board enabled device,
238 + * this has to be done this early since PCI init is done
239 + * inside arch_initcall */
242 + if (board.has_pci) {
243 + bcm63xx_pci_enabled = 1;
244 + if (BCMCPU_IS_6348())
245 + val |= GPIO_MODE_6348_G2_PCI;
248 + if (board.has_pccard) {
249 + if (BCMCPU_IS_6348())
250 + val |= GPIO_MODE_6348_G1_MII_PCCARD;
253 + if (board.has_enet0 && !board.enet0.use_internal_phy) {
254 + if (BCMCPU_IS_6348())
255 + val |= GPIO_MODE_6348_G3_EXT_MII |
256 + GPIO_MODE_6348_G0_EXT_MII;
259 + if (board.has_enet1 && !board.enet1.use_internal_phy) {
260 + if (BCMCPU_IS_6348())
261 + val |= GPIO_MODE_6348_G3_EXT_MII |
262 + GPIO_MODE_6348_G0_EXT_MII;
265 + bcm_gpio_writel(val, GPIO_MODE_REG);
269 + * second stage init callback, good time to panic if we couldn't
270 + * identify on which board we're running since early printk is working
272 +void __init board_setup(void)
275 + panic("unable to detect bcm963xx board");
276 + printk(KERN_INFO PFX "board name: %s\n", board.name);
278 + /* make sure we're running on expected cpu */
279 + if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
280 + panic("unexpected CPU for bcm963xx board");
284 + * return board name for /proc/cpuinfo
286 +const char *board_get_name(void)
292 + * register & return a new board mac address
294 +static int board_get_mac_address(u8 *mac)
299 + if (mac_addr_used >= nvram.mac_addr_count) {
300 + printk(KERN_ERR PFX "not enough mac address\n");
304 + memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
305 + p = mac + ETH_ALEN - 1;
306 + count = mac_addr_used;
314 + } while (p != mac);
318 + printk(KERN_ERR PFX "unable to fetch mac address\n");
326 +static struct mtd_partition mtd_partitions[] = {
334 +static struct physmap_flash_data flash_data = {
336 + .nr_parts = ARRAY_SIZE(mtd_partitions),
337 + .parts = mtd_partitions,
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 = "physmap-flash",
350 + .resource = mtd_resources,
351 + .num_resources = ARRAY_SIZE(mtd_resources),
353 + .platform_data = &flash_data,
358 + * third stage init callback, register all board devices.
360 +int __init board_register_devices(void)
364 + bcm63xx_uart_register();
366 + if (board.has_pccard)
367 + bcm63xx_pcmcia_register();
369 + if (board.has_enet0 &&
370 + !board_get_mac_address(board.enet0.mac_addr))
371 + bcm63xx_enet_register(0, &board.enet0);
373 + if (board.has_enet1 &&
374 + !board_get_mac_address(board.enet1.mac_addr))
375 + bcm63xx_enet_register(1, &board.enet1);
377 + if (board.has_ohci0)
378 + bcm63xx_ohci_register();
380 + if (board.has_ehci0)
381 + bcm63xx_ehci_register();
384 + /* read base address of boot chip select (0) */
385 + val = bcm_mpi_readl(MPI_CSBASE_REG(0));
386 + val &= MPI_CSBASE_BASE_MASK;
387 + mtd_resources[0].start = val;
388 + mtd_resources[0].end = 0x1FFFFFFF;
390 + platform_device_register(&mtd_dev);
395 diff --git a/arch/mips/bcm63xx/prom.c b/arch/mips/bcm63xx/prom.c
396 index f0b49e8..d97ceed 100644
397 --- a/arch/mips/bcm63xx/prom.c
398 +++ b/arch/mips/bcm63xx/prom.c
400 #include <linux/init.h>
401 #include <linux/bootmem.h>
402 #include <asm/bootinfo.h>
403 +#include <bcm63xx_board.h>
404 #include <bcm63xx_cpu.h>
405 #include <bcm63xx_io.h>
406 #include <bcm63xx_regs.h>
407 @@ -36,6 +37,9 @@ void __init prom_init(void)
409 /* assign command line from kernel config */
410 strcpy(arcs_cmdline, CONFIG_CMDLINE);
412 + /* do low level board init */
416 void __init prom_free_prom_memory(void)
417 diff --git a/arch/mips/bcm63xx/setup.c b/arch/mips/bcm63xx/setup.c
418 index 4d8b127..c4516fb 100644
419 --- a/arch/mips/bcm63xx/setup.c
420 +++ b/arch/mips/bcm63xx/setup.c
422 #include <asm/time.h>
423 #include <asm/reboot.h>
424 #include <asm/cacheflush.h>
425 +#include <bcm63xx_board.h>
426 #include <bcm63xx_cpu.h>
427 #include <bcm63xx_regs.h>
428 #include <bcm63xx_io.h>
429 @@ -87,8 +88,9 @@ static void __bcm63xx_machine_reboot(char *p)
430 const char *get_system_type(void)
432 static char buf[128];
433 - sprintf(buf, "bcm963xx (0x%04x/0x%04X)",
434 - bcm63xx_get_cpu_id(), bcm63xx_get_cpu_rev());
435 + snprintf(buf, sizeof (buf), "bcm63xx/%s (0x%04x/0x%04X)",
437 + bcm63xx_get_cpu_id(), bcm63xx_get_cpu_rev());
441 @@ -96,6 +98,7 @@ void __init plat_time_init(void)
443 mips_hpt_frequency = bcm63xx_get_cpu_freq() / 2;
446 void __init plat_mem_setup(void)
448 add_memory_region(0, bcm63xx_get_memory_size(), BOOT_MEM_RAM);
449 @@ -107,4 +110,13 @@ void __init plat_mem_setup(void)
451 ioport_resource.start = 0;
452 ioport_resource.end = ~0;
457 +int __init bcm63xx_register_devices(void)
459 + return board_register_devices();
462 +device_initcall(bcm63xx_register_devices);
463 diff --git a/include/asm-mips/mach-bcm63xx/bcm63xx_board.h b/include/asm-mips/mach-bcm63xx/bcm63xx_board.h
465 index 0000000..fa3e7e6
467 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_board.h
469 +#ifndef BCM63XX_BOARD_H_
470 +#define BCM63XX_BOARD_H_
472 +const char *board_get_name(void);
474 +void board_prom_init(void);
476 +void board_setup(void);
478 +int board_register_devices(void);
480 +#endif /* ! BCM63XX_BOARD_H_ */
481 diff --git a/include/asm-mips/mach-bcm63xx/board_bcm963xx.h b/include/asm-mips/mach-bcm63xx/board_bcm963xx.h
483 index 0000000..17e4e7e
485 +++ b/include/asm-mips/mach-bcm63xx/board_bcm963xx.h
487 +#ifndef BOARD_BCM963XX_H_
488 +#define BOARD_BCM963XX_H_
490 +#include <linux/types.h>
491 +#include <bcm63xx_dev_enet.h>
496 +#define BCM963XX_CFE_VERSION_OFFSET 0x570
497 +#define BCM963XX_NVRAM_OFFSET 0x580
502 +struct bcm963xx_nvram {
506 + u32 main_tp_number;
508 + u32 mac_addr_count;
509 + u8 mac_addr_base[6];
521 + unsigned int expected_cpu_id;
523 + /* enabled feature/device */
524 + unsigned int has_enet0:1;
525 + unsigned int has_enet1:1;
526 + unsigned int has_pci:1;
527 + unsigned int has_pccard:1;
528 + unsigned int has_ohci0:1;
529 + unsigned int has_ehci0:1;
531 + /* ethernet config */
532 + struct bcm63xx_enet_platform_data enet0;
533 + struct bcm63xx_enet_platform_data enet1;
536 +#endif /* ! BOARD_BCM963XX_H_ */