Update patches and rename board 9 stands for development board
[openwrt/svn-archive/archive.git] / target / linux / brcm63xx / patches-2.6.27 / 011-add_preliminary_board_support.patch
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.
5
6 Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
7 ---
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
23
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
31 endmenu
32 +
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
40 obj-y += dev-enet.o
41 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
42 +
43 +obj-y += boards/
44 diff --git a/arch/mips/bcm63xx/boards/Kconfig b/arch/mips/bcm63xx/boards/Kconfig
45 new file mode 100644
46 index 0000000..da5eeaa
47 --- /dev/null
48 +++ b/arch/mips/bcm63xx/boards/Kconfig
49 @@ -0,0 +1,10 @@
50 +choice
51 + prompt "Board support"
52 + depends on BCM63XX
53 + default BOARD_BCM963XX
54 +
55 +config BOARD_BCM963XX
56 + bool "Generic Broadcom 963xx boards"
57 + help
58 +
59 +endchoice
60 diff --git a/arch/mips/bcm63xx/boards/Makefile b/arch/mips/bcm63xx/boards/Makefile
61 new file mode 100644
62 index 0000000..af07c1a
63 --- /dev/null
64 +++ b/arch/mips/bcm63xx/boards/Makefile
65 @@ -0,0 +1 @@
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
68 new file mode 100644
69 index 0000000..6e2b4ae
70 --- /dev/null
71 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
72 @@ -0,0 +1,328 @@
73 +/*
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
76 + * for more details.
77 + *
78 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
79 + */
80 +
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>
101 +
102 +#define PFX "board_bcm963xx: "
103 +
104 +static struct bcm963xx_nvram nvram;
105 +static unsigned int mac_addr_used = 0;
106 +static struct board_info board;
107 +
108 +/*
109 + * known 6348 boards
110 + */
111 +#ifdef CONFIG_BCM63XX_CPU_6348
112 +static struct board_info __initdata board_96348r = {
113 + .name = "96348R",
114 + .expected_cpu_id = 0x6348,
115 +
116 + .has_enet0 = 1,
117 + .has_pci = 1,
118 +
119 + .enet0 = {
120 + .has_phy = 1,
121 + .use_internal_phy = 1,
122 + },
123 +};
124 +
125 +static struct board_info __initdata board_96348gw = {
126 + .name = "96348GW",
127 + .expected_cpu_id = 0x6348,
128 +
129 + .has_enet0 = 1,
130 + .has_pci = 1,
131 +
132 + .enet0 = {
133 + .has_phy = 1,
134 + .use_internal_phy = 1,
135 + },
136 +};
137 +#endif
138 +
139 +/*
140 + * known 6358 boards
141 + */
142 +#ifdef CONFIG_BCM63XX_CPU_6358
143 +static struct board_info __initdata board_96358vw2 = {
144 + .name = "96358VW2",
145 + .expected_cpu_id = 0x6358,
146 +
147 + .has_enet0 = 1,
148 + .has_enet1 = 1,
149 + .has_pci = 1,
150 +
151 + .enet0 = {
152 + .has_phy = 1,
153 + .use_internal_phy = 1,
154 + },
155 +
156 + .enet1 = {
157 + .force_speed_100 = 1,
158 + .force_duplex_full = 1,
159 + },
160 +
161 +
162 + .has_ohci0 = 1,
163 + .has_pccard = 1,
164 + .has_ehci0 = 1,
165 +};
166 +#endif
167 +
168 +/*
169 + * all boards
170 + */
171 +static const struct board_info __initdata *bcm963xx_boards[] = {
172 +#ifdef CONFIG_BCM63XX_CPU_6348
173 + &board_96348r,
174 + &board_96348gw,
175 +#endif
176 +
177 +#ifdef CONFIG_BCM63XX_CPU_6358
178 + &board_96358vw2,
179 +#endif
180 +};
181 +
182 +/*
183 + * early init callback, read nvram data from flash and checksum it
184 + */
185 +void __init board_prom_init(void)
186 +{
187 + unsigned int check_len, i;
188 + u8 *boot_addr, *cfe, *p;
189 + char cfe_version[32];
190 + u32 val;
191 +
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);
196 +
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]);
202 + else
203 + strcpy(cfe_version, "unknown");
204 + printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
205 +
206 + /* extract nvram data */
207 + memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
208 +
209 + /* check checksum before using data */
210 + if (nvram.version <= 4)
211 + check_len = offsetof(struct bcm963xx_nvram, checksum_old);
212 + else
213 + check_len = sizeof(nvram);
214 + val = 0;
215 + p = (u8 *)&nvram;
216 + while (check_len--)
217 + val += *p;
218 + if (val) {
219 + printk(KERN_ERR PFX "invalid nvram checksum\n");
220 + return;
221 + }
222 +
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)))
227 + continue;
228 + /* copy, board desc array is marked initdata */
229 + memcpy(&board, bcm963xx_boards[i], sizeof(board));
230 + break;
231 + }
232 +
233 + /* bail out if board is not found, will complain later */
234 + if (!board.name[0]) {
235 + char name[17];
236 + memcpy(name, nvram.name, 16);
237 + name[16] = 0;
238 + printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
239 + name);
240 + return;
241 + }
242 +
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 */
246 + val = 0;
247 +
248 + if (board.has_pci) {
249 + bcm63xx_pci_enabled = 1;
250 + if (BCMCPU_IS_6348())
251 + val |= GPIO_MODE_6348_G2_PCI;
252 + }
253 +
254 + if (board.has_pccard) {
255 + if (BCMCPU_IS_6348())
256 + val |= GPIO_MODE_6348_G1_MII_PCCARD;
257 + }
258 +
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;
263 + }
264 +
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;
269 + }
270 +
271 + bcm_gpio_writel(val, GPIO_MODE_REG);
272 +}
273 +
274 +/*
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
277 + */
278 +void __init board_setup(void)
279 +{
280 + if (!board.name[0])
281 + panic("unable to detect bcm963xx board");
282 + printk(KERN_INFO PFX "board name: %s\n", board.name);
283 +
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");
287 +}
288 +
289 +/*
290 + * return board name for /proc/cpuinfo
291 + */
292 +const char *board_get_name(void)
293 +{
294 + return board.name;
295 +}
296 +
297 +/*
298 + * register & return a new board mac address
299 + */
300 +static int board_get_mac_address(u8 *mac)
301 +{
302 + u8 *p;
303 + int count;
304 +
305 + if (mac_addr_used >= nvram.mac_addr_count) {
306 + printk(KERN_ERR PFX "not enough mac address\n");
307 + return -ENODEV;
308 + }
309 +
310 + memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
311 + p = mac + ETH_ALEN - 1;
312 + count = mac_addr_used;
313 +
314 + while (count--) {
315 + do {
316 + (*p)++;
317 + if (*p != 0)
318 + break;
319 + p--;
320 + } while (p != mac);
321 + }
322 +
323 + if (p == mac) {
324 + printk(KERN_ERR PFX "unable to fetch mac address\n");
325 + return -ENODEV;
326 + }
327 +
328 + mac_addr_used++;
329 + return 0;
330 +}
331 +
332 +static struct mtd_partition mtd_partitions[] = {
333 + {
334 + .name = "cfe",
335 + .offset = 0x0,
336 + .size = 0x40000,
337 + }
338 +};
339 +
340 +static struct physmap_flash_data flash_data = {
341 + .width = 2,
342 + .nr_parts = ARRAY_SIZE(mtd_partitions),
343 + .parts = mtd_partitions,
344 +};
345 +
346 +static struct resource mtd_resources[] = {
347 + {
348 + .start = 0, /* filled at runtime */
349 + .end = 0, /* filled at runtime */
350 + .flags = IORESOURCE_MEM,
351 + }
352 +};
353 +
354 +static struct platform_device mtd_dev = {
355 + .name = "physmap-flash",
356 + .resource = mtd_resources,
357 + .num_resources = ARRAY_SIZE(mtd_resources),
358 + .dev = {
359 + .platform_data = &flash_data,
360 + },
361 +};
362 +
363 +/*
364 + * third stage init callback, register all board devices.
365 + */
366 +int __init board_register_devices(void)
367 +{
368 + u32 val;
369 +
370 + bcm63xx_uart_register();
371 +
372 + if (board.has_pccard)
373 + bcm63xx_pcmcia_register();
374 +
375 + if (board.has_enet0 &&
376 + !board_get_mac_address(board.enet0.mac_addr))
377 + bcm63xx_enet_register(0, &board.enet0);
378 +
379 + if (board.has_enet1 &&
380 + !board_get_mac_address(board.enet1.mac_addr))
381 + bcm63xx_enet_register(1, &board.enet1);
382 +
383 + if (board.has_ohci0)
384 + bcm63xx_ohci_register();
385 +
386 + if (board.has_ehci0)
387 + bcm63xx_ehci_register();
388 +
389 +
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;
395 +
396 + platform_device_register(&mtd_dev);
397 +
398 + return 0;
399 +}
400 +
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
405 @@ -9,6 +9,7 @@
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)
414
415 /* assign command line from kernel config */
416 strcpy(arcs_cmdline, CONFIG_CMDLINE);
417 +
418 + /* do low level board init */
419 + board_prom_init();
420 }
421
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
427 @@ -16,6 +16,7 @@
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)
437 {
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)",
442 + board_get_name(),
443 + bcm63xx_get_cpu_id(), bcm63xx_get_cpu_rev());
444 return buf;
445 }
446
447 @@ -96,6 +98,7 @@ void __init plat_time_init(void)
448 {
449 mips_hpt_frequency = bcm63xx_get_cpu_freq() / 2;
450 }
451 +
452 void __init plat_mem_setup(void)
453 {
454 add_memory_region(0, bcm63xx_get_memory_size(), BOOT_MEM_RAM);
455 @@ -107,4 +110,13 @@ void __init plat_mem_setup(void)
456 set_io_port_base(0);
457 ioport_resource.start = 0;
458 ioport_resource.end = ~0;
459 +
460 + board_setup();
461 +}
462 +
463 +int __init bcm63xx_register_devices(void)
464 +{
465 + return board_register_devices();
466 }
467 +
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
470 new file mode 100644
471 index 0000000..fa3e7e6
472 --- /dev/null
473 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_board.h
474 @@ -0,0 +1,12 @@
475 +#ifndef BCM63XX_BOARD_H_
476 +#define BCM63XX_BOARD_H_
477 +
478 +const char *board_get_name(void);
479 +
480 +void board_prom_init(void);
481 +
482 +void board_setup(void);
483 +
484 +int board_register_devices(void);
485 +
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
488 new file mode 100644
489 index 0000000..17e4e7e
490 --- /dev/null
491 +++ b/include/asm-mips/mach-bcm63xx/board_bcm963xx.h
492 @@ -0,0 +1,50 @@
493 +#ifndef BOARD_BCM963XX_H_
494 +#define BOARD_BCM963XX_H_
495 +
496 +#include <linux/types.h>
497 +#include <bcm63xx_dev_enet.h>
498 +
499 +/*
500 + * flash mapping
501 + */
502 +#define BCM963XX_CFE_VERSION_OFFSET 0x570
503 +#define BCM963XX_NVRAM_OFFSET 0x580
504 +
505 +/*
506 + * nvram structure
507 + */
508 +struct bcm963xx_nvram {
509 + u32 version;
510 + u8 reserved1[256];
511 + u8 name[16];
512 + u32 main_tp_number;
513 + u32 psi_size;
514 + u32 mac_addr_count;
515 + u8 mac_addr_base[6];
516 + u8 reserved2[2];
517 + u32 checksum_old;
518 + u8 reserved3[720];
519 + u32 checksum_high;
520 +};
521 +
522 +/*
523 + * board definition
524 + */
525 +struct board_info {
526 + u8 name[16];
527 + unsigned int expected_cpu_id;
528 +
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;
536 +
537 + /* ethernet config */
538 + struct bcm63xx_enet_platform_data enet0;
539 + struct bcm63xx_enet_platform_data enet1;
540 +};
541 +
542 +#endif /* ! BOARD_BCM963XX_H_ */
543 --
544 1.5.4.3
545