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