[ar71xx] add EON en25p32 support, and enable redboot partition parser in the m25p80...
[openwrt.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 --- 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
29 endmenu
30 +
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
36 obj-y += dev-enet.o
37 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
38 +
39 +obj-y += boards/
40 --- /dev/null
41 +++ b/arch/mips/bcm63xx/boards/Kconfig
42 @@ -0,0 +1,10 @@
43 +choice
44 + prompt "Board support"
45 + depends on BCM63XX
46 + default BOARD_BCM963XX
47 +
48 +config BOARD_BCM963XX
49 + bool "Generic Broadcom 963xx boards"
50 + help
51 +
52 +endchoice
53 --- /dev/null
54 +++ b/arch/mips/bcm63xx/boards/Makefile
55 @@ -0,0 +1 @@
56 +obj-$(CONFIG_BOARD_BCM963XX) += board_bcm963xx.o
57 --- /dev/null
58 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
59 @@ -0,0 +1,353 @@
60 +/*
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
63 + * for more details.
64 + *
65 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
66 + */
67 +
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>
88 +
89 +#define PFX "board_bcm963xx: "
90 +
91 +static struct bcm963xx_nvram nvram;
92 +static unsigned int mac_addr_used = 0;
93 +static struct board_info board;
94 +
95 +/*
96 + * known 6348 boards
97 + */
98 +#ifdef CONFIG_BCM63XX_CPU_6348
99 +static struct board_info __initdata board_96348r = {
100 + .name = "96348R",
101 + .expected_cpu_id = 0x6348,
102 +
103 + .has_enet0 = 1,
104 + .has_pci = 1,
105 +
106 + .enet0 = {
107 + .has_phy = 1,
108 + .use_internal_phy = 1,
109 + },
110 +};
111 +
112 +static struct board_info __initdata board_96348gw_11 = {
113 + .name = "96348GW-11",
114 + .expected_cpu_id = 0x6348,
115 +
116 + .has_enet0 = 1,
117 + .has_enet1 = 1,
118 + .has_pci = 1,
119 +
120 + .enet0 = {
121 + .has_phy = 1,
122 + .use_internal_phy = 1,
123 + },
124 +
125 + .enet1 = {
126 + .force_speed_100 = 1,
127 + .force_duplex_full = 1,
128 + },
129 +
130 +
131 + .has_ohci0 = 1,
132 + .has_pccard = 1,
133 + .has_ehci0 = 1,
134 +};
135 +
136 +static struct board_info __initdata board_96348gw = {
137 + .name = "96348GW",
138 + .expected_cpu_id = 0x6348,
139 +
140 + .has_enet0 = 1,
141 + .has_pci = 1,
142 +
143 + .enet0 = {
144 + .has_phy = 1,
145 + .use_internal_phy = 1,
146 + },
147 +};
148 +#endif
149 +
150 +/*
151 + * known 6358 boards
152 + */
153 +#ifdef CONFIG_BCM63XX_CPU_6358
154 +static struct board_info __initdata board_96358vw2 = {
155 + .name = "96358VW2",
156 + .expected_cpu_id = 0x6358,
157 +
158 + .has_enet0 = 1,
159 + .has_enet1 = 1,
160 + .has_pci = 1,
161 +
162 + .enet0 = {
163 + .has_phy = 1,
164 + .use_internal_phy = 1,
165 + },
166 +
167 + .enet1 = {
168 + .force_speed_100 = 1,
169 + .force_duplex_full = 1,
170 + },
171 +
172 +
173 + .has_ohci0 = 1,
174 + .has_pccard = 1,
175 + .has_ehci0 = 1,
176 +};
177 +#endif
178 +
179 +/*
180 + * all boards
181 + */
182 +static const struct board_info __initdata *bcm963xx_boards[] = {
183 +#ifdef CONFIG_BCM63XX_CPU_6348
184 + &board_96348r,
185 + &board_96348gw,
186 + &board_96348gw_11,
187 +#endif
188 +
189 +#ifdef CONFIG_BCM63XX_CPU_6358
190 + &board_96358vw2,
191 +#endif
192 +};
193 +
194 +/*
195 + * early init callback, read nvram data from flash and checksum it
196 + */
197 +void __init board_prom_init(void)
198 +{
199 + unsigned int check_len, i;
200 + u8 *boot_addr, *cfe, *p;
201 + char cfe_version[32];
202 + u32 val;
203 +
204 + /* read base address of boot chip select (0) */
205 + val = bcm_mpi_readl(MPI_CSBASE_REG(0));
206 + val &= MPI_CSBASE_BASE_MASK;
207 + boot_addr = (u8 *)KSEG1ADDR(val);
208 +
209 + /* dump cfe version */
210 + cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
211 + if (!memcmp(cfe, "cfe-v", 5))
212 + snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
213 + cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
214 + else
215 + strcpy(cfe_version, "unknown");
216 + printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
217 +
218 + /* extract nvram data */
219 + memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
220 +
221 + /* check checksum before using data */
222 + if (nvram.version <= 4)
223 + check_len = offsetof(struct bcm963xx_nvram, checksum_old);
224 + else
225 + check_len = sizeof(nvram);
226 + val = 0;
227 + p = (u8 *)&nvram;
228 + while (check_len--)
229 + val += *p;
230 + if (val) {
231 + printk(KERN_ERR PFX "invalid nvram checksum\n");
232 + return;
233 + }
234 +
235 + /* find board by name */
236 + for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
237 + if (strncmp(nvram.name, bcm963xx_boards[i]->name,
238 + sizeof(nvram.name)))
239 + continue;
240 + /* copy, board desc array is marked initdata */
241 + memcpy(&board, bcm963xx_boards[i], sizeof(board));
242 + break;
243 + }
244 +
245 + /* bail out if board is not found, will complain later */
246 + if (!board.name[0]) {
247 + char name[17];
248 + memcpy(name, nvram.name, 16);
249 + name[16] = 0;
250 + printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
251 + name);
252 + return;
253 + }
254 +
255 + /* setup pin multiplexing depending on board enabled device,
256 + * this has to be done this early since PCI init is done
257 + * inside arch_initcall */
258 + val = 0;
259 +
260 + if (board.has_pci) {
261 + bcm63xx_pci_enabled = 1;
262 + if (BCMCPU_IS_6348())
263 + val |= GPIO_MODE_6348_G2_PCI;
264 + }
265 +
266 + if (board.has_pccard) {
267 + if (BCMCPU_IS_6348())
268 + val |= GPIO_MODE_6348_G1_MII_PCCARD;
269 + }
270 +
271 + if (board.has_enet0 && !board.enet0.use_internal_phy) {
272 + if (BCMCPU_IS_6348())
273 + val |= GPIO_MODE_6348_G3_EXT_MII |
274 + GPIO_MODE_6348_G0_EXT_MII;
275 + }
276 +
277 + if (board.has_enet1 && !board.enet1.use_internal_phy) {
278 + if (BCMCPU_IS_6348())
279 + val |= GPIO_MODE_6348_G3_EXT_MII |
280 + GPIO_MODE_6348_G0_EXT_MII;
281 + }
282 +
283 + bcm_gpio_writel(val, GPIO_MODE_REG);
284 +}
285 +
286 +/*
287 + * second stage init callback, good time to panic if we couldn't
288 + * identify on which board we're running since early printk is working
289 + */
290 +void __init board_setup(void)
291 +{
292 + if (!board.name[0])
293 + panic("unable to detect bcm963xx board");
294 + printk(KERN_INFO PFX "board name: %s\n", board.name);
295 +
296 + /* make sure we're running on expected cpu */
297 + if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
298 + panic("unexpected CPU for bcm963xx board");
299 +}
300 +
301 +/*
302 + * return board name for /proc/cpuinfo
303 + */
304 +const char *board_get_name(void)
305 +{
306 + return board.name;
307 +}
308 +
309 +/*
310 + * register & return a new board mac address
311 + */
312 +static int board_get_mac_address(u8 *mac)
313 +{
314 + u8 *p;
315 + int count;
316 +
317 + if (mac_addr_used >= nvram.mac_addr_count) {
318 + printk(KERN_ERR PFX "not enough mac address\n");
319 + return -ENODEV;
320 + }
321 +
322 + memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
323 + p = mac + ETH_ALEN - 1;
324 + count = mac_addr_used;
325 +
326 + while (count--) {
327 + do {
328 + (*p)++;
329 + if (*p != 0)
330 + break;
331 + p--;
332 + } while (p != mac);
333 + }
334 +
335 + if (p == mac) {
336 + printk(KERN_ERR PFX "unable to fetch mac address\n");
337 + return -ENODEV;
338 + }
339 +
340 + mac_addr_used++;
341 + return 0;
342 +}
343 +
344 +static struct mtd_partition mtd_partitions[] = {
345 + {
346 + .name = "cfe",
347 + .offset = 0x0,
348 + .size = 0x40000,
349 + }
350 +};
351 +
352 +static struct physmap_flash_data flash_data = {
353 + .width = 2,
354 + .nr_parts = ARRAY_SIZE(mtd_partitions),
355 + .parts = mtd_partitions,
356 +};
357 +
358 +static struct resource mtd_resources[] = {
359 + {
360 + .start = 0, /* filled at runtime */
361 + .end = 0, /* filled at runtime */
362 + .flags = IORESOURCE_MEM,
363 + }
364 +};
365 +
366 +static struct platform_device mtd_dev = {
367 + .name = "physmap-flash",
368 + .resource = mtd_resources,
369 + .num_resources = ARRAY_SIZE(mtd_resources),
370 + .dev = {
371 + .platform_data = &flash_data,
372 + },
373 +};
374 +
375 +/*
376 + * third stage init callback, register all board devices.
377 + */
378 +int __init board_register_devices(void)
379 +{
380 + u32 val;
381 +
382 + bcm63xx_uart_register();
383 +
384 + if (board.has_pccard)
385 + bcm63xx_pcmcia_register();
386 +
387 + if (board.has_enet0 &&
388 + !board_get_mac_address(board.enet0.mac_addr))
389 + bcm63xx_enet_register(0, &board.enet0);
390 +
391 + if (board.has_enet1 &&
392 + !board_get_mac_address(board.enet1.mac_addr))
393 + bcm63xx_enet_register(1, &board.enet1);
394 +
395 + if (board.has_ohci0)
396 + bcm63xx_ohci_register();
397 +
398 + if (board.has_ehci0)
399 + bcm63xx_ehci_register();
400 +
401 +
402 + /* read base address of boot chip select (0) */
403 + val = bcm_mpi_readl(MPI_CSBASE_REG(0));
404 + val &= MPI_CSBASE_BASE_MASK;
405 + mtd_resources[0].start = val;
406 + mtd_resources[0].end = 0x1FFFFFFF;
407 +
408 + platform_device_register(&mtd_dev);
409 +
410 + return 0;
411 +}
412 +
413 --- a/arch/mips/bcm63xx/prom.c
414 +++ b/arch/mips/bcm63xx/prom.c
415 @@ -9,6 +9,7 @@
416 #include <linux/init.h>
417 #include <linux/bootmem.h>
418 #include <asm/bootinfo.h>
419 +#include <bcm63xx_board.h>
420 #include <bcm63xx_cpu.h>
421 #include <bcm63xx_io.h>
422 #include <bcm63xx_regs.h>
423 @@ -36,6 +37,9 @@ void __init prom_init(void)
424
425 /* assign command line from kernel config */
426 strcpy(arcs_cmdline, CONFIG_CMDLINE);
427 +
428 + /* do low level board init */
429 + board_prom_init();
430 }
431
432 void __init prom_free_prom_memory(void)
433 --- a/arch/mips/bcm63xx/setup.c
434 +++ b/arch/mips/bcm63xx/setup.c
435 @@ -16,6 +16,7 @@
436 #include <asm/time.h>
437 #include <asm/reboot.h>
438 #include <asm/cacheflush.h>
439 +#include <bcm63xx_board.h>
440 #include <bcm63xx_cpu.h>
441 #include <bcm63xx_regs.h>
442 #include <bcm63xx_io.h>
443 @@ -87,8 +88,9 @@ static void __bcm63xx_machine_reboot(cha
444 const char *get_system_type(void)
445 {
446 static char buf[128];
447 - sprintf(buf, "bcm963xx (0x%04x/0x%04X)",
448 - bcm63xx_get_cpu_id(), bcm63xx_get_cpu_rev());
449 + snprintf(buf, sizeof (buf), "bcm63xx/%s (0x%04x/0x%04X)",
450 + board_get_name(),
451 + bcm63xx_get_cpu_id(), bcm63xx_get_cpu_rev());
452 return buf;
453 }
454
455 @@ -96,6 +98,7 @@ void __init plat_time_init(void)
456 {
457 mips_hpt_frequency = bcm63xx_get_cpu_freq() / 2;
458 }
459 +
460 void __init plat_mem_setup(void)
461 {
462 add_memory_region(0, bcm63xx_get_memory_size(), BOOT_MEM_RAM);
463 @@ -107,4 +110,13 @@ void __init plat_mem_setup(void)
464 set_io_port_base(0);
465 ioport_resource.start = 0;
466 ioport_resource.end = ~0;
467 +
468 + board_setup();
469 +}
470 +
471 +int __init bcm63xx_register_devices(void)
472 +{
473 + return board_register_devices();
474 }
475 +
476 +device_initcall(bcm63xx_register_devices);
477 --- /dev/null
478 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_board.h
479 @@ -0,0 +1,12 @@
480 +#ifndef BCM63XX_BOARD_H_
481 +#define BCM63XX_BOARD_H_
482 +
483 +const char *board_get_name(void);
484 +
485 +void board_prom_init(void);
486 +
487 +void board_setup(void);
488 +
489 +int board_register_devices(void);
490 +
491 +#endif /* ! BCM63XX_BOARD_H_ */
492 --- /dev/null
493 +++ b/include/asm-mips/mach-bcm63xx/board_bcm963xx.h
494 @@ -0,0 +1,50 @@
495 +#ifndef BOARD_BCM963XX_H_
496 +#define BOARD_BCM963XX_H_
497 +
498 +#include <linux/types.h>
499 +#include <bcm63xx_dev_enet.h>
500 +
501 +/*
502 + * flash mapping
503 + */
504 +#define BCM963XX_CFE_VERSION_OFFSET 0x570
505 +#define BCM963XX_NVRAM_OFFSET 0x580
506 +
507 +/*
508 + * nvram structure
509 + */
510 +struct bcm963xx_nvram {
511 + u32 version;
512 + u8 reserved1[256];
513 + u8 name[16];
514 + u32 main_tp_number;
515 + u32 psi_size;
516 + u32 mac_addr_count;
517 + u8 mac_addr_base[6];
518 + u8 reserved2[2];
519 + u32 checksum_old;
520 + u8 reserved3[720];
521 + u32 checksum_high;
522 +};
523 +
524 +/*
525 + * board definition
526 + */
527 +struct board_info {
528 + u8 name[16];
529 + unsigned int expected_cpu_id;
530 +
531 + /* enabled feature/device */
532 + unsigned int has_enet0:1;
533 + unsigned int has_enet1:1;
534 + unsigned int has_pci:1;
535 + unsigned int has_pccard:1;
536 + unsigned int has_ohci0:1;
537 + unsigned int has_ehci0:1;
538 +
539 + /* ethernet config */
540 + struct bcm63xx_enet_platform_data enet0;
541 + struct bcm63xx_enet_platform_data enet1;
542 +};
543 +
544 +#endif /* ! BOARD_BCM963XX_H_ */
This page took 0.081727 seconds and 5 git commands to generate.