a738bcc7ced3d026fb4020ed04464a128829ba3d
[openwrt.git] / target / linux / brcm63xx / patches-2.6.27 / 011-add_preliminary_board_support.patch
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.
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 | 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
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..de52a2a
70 --- /dev/null
71 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
72 @@ -0,0 +1,322 @@
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)
235 + return;
236 +
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 */
240 + val = 0;
241 +
242 + if (board.has_pci) {
243 + bcm63xx_pci_enabled = 1;
244 + if (BCMCPU_IS_6348())
245 + val |= GPIO_MODE_6348_G2_PCI;
246 + }
247 +
248 + if (board.has_pccard) {
249 + if (BCMCPU_IS_6348())
250 + val |= GPIO_MODE_6348_G1_MII_PCCARD;
251 + }
252 +
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;
257 + }
258 +
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;
263 + }
264 +
265 + bcm_gpio_writel(val, GPIO_MODE_REG);
266 +}
267 +
268 +/*
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
271 + */
272 +void __init board_setup(void)
273 +{
274 + if (!board.name)
275 + panic("unable to detect bcm963xx board");
276 + printk(KERN_INFO PFX "board name: %s\n", board.name);
277 +
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");
281 +}
282 +
283 +/*
284 + * return board name for /proc/cpuinfo
285 + */
286 +const char *board_get_name(void)
287 +{
288 + return board.name;
289 +}
290 +
291 +/*
292 + * register & return a new board mac address
293 + */
294 +static int board_get_mac_address(u8 *mac)
295 +{
296 + u8 *p;
297 + int count;
298 +
299 + if (mac_addr_used >= nvram.mac_addr_count) {
300 + printk(KERN_ERR PFX "not enough mac address\n");
301 + return -ENODEV;
302 + }
303 +
304 + memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
305 + p = mac + ETH_ALEN - 1;
306 + count = mac_addr_used;
307 +
308 + while (count--) {
309 + do {
310 + (*p)++;
311 + if (*p != 0)
312 + break;
313 + p--;
314 + } while (p != mac);
315 + }
316 +
317 + if (p == mac) {
318 + printk(KERN_ERR PFX "unable to fetch mac address\n");
319 + return -ENODEV;
320 + }
321 +
322 + mac_addr_used++;
323 + return 0;
324 +}
325 +
326 +static struct mtd_partition mtd_partitions[] = {
327 + {
328 + .name = "cfe",
329 + .offset = 0x0,
330 + .size = 0x40000,
331 + }
332 +};
333 +
334 +static struct physmap_flash_data flash_data = {
335 + .width = 2,
336 + .nr_parts = ARRAY_SIZE(mtd_partitions),
337 + .parts = mtd_partitions,
338 +};
339 +
340 +static struct resource mtd_resources[] = {
341 + {
342 + .start = 0, /* filled at runtime */
343 + .end = 0, /* filled at runtime */
344 + .flags = IORESOURCE_MEM,
345 + }
346 +};
347 +
348 +static struct platform_device mtd_dev = {
349 + .name = "physmap-flash",
350 + .resource = mtd_resources,
351 + .num_resources = ARRAY_SIZE(mtd_resources),
352 + .dev = {
353 + .platform_data = &flash_data,
354 + },
355 +};
356 +
357 +/*
358 + * third stage init callback, register all board devices.
359 + */
360 +int __init board_register_devices(void)
361 +{
362 + u32 val;
363 +
364 + bcm63xx_uart_register();
365 +
366 + if (board.has_pccard)
367 + bcm63xx_pcmcia_register();
368 +
369 + if (board.has_enet0 &&
370 + !board_get_mac_address(board.enet0.mac_addr))
371 + bcm63xx_enet_register(0, &board.enet0);
372 +
373 + if (board.has_enet1 &&
374 + !board_get_mac_address(board.enet1.mac_addr))
375 + bcm63xx_enet_register(1, &board.enet1);
376 +
377 + if (board.has_ohci0)
378 + bcm63xx_ohci_register();
379 +
380 + if (board.has_ehci0)
381 + bcm63xx_ehci_register();
382 +
383 +
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;
389 +
390 + platform_device_register(&mtd_dev);
391 +
392 + return 0;
393 +}
394 +
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
399 @@ -9,6 +9,7 @@
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)
408
409 /* assign command line from kernel config */
410 strcpy(arcs_cmdline, CONFIG_CMDLINE);
411 +
412 + /* do low level board init */
413 + board_prom_init();
414 }
415
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
421 @@ -16,6 +16,7 @@
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)
431 {
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)",
436 + board_get_name(),
437 + bcm63xx_get_cpu_id(), bcm63xx_get_cpu_rev());
438 return buf;
439 }
440
441 @@ -96,6 +98,7 @@ void __init plat_time_init(void)
442 {
443 mips_hpt_frequency = bcm63xx_get_cpu_freq() / 2;
444 }
445 +
446 void __init plat_mem_setup(void)
447 {
448 add_memory_region(0, bcm63xx_get_memory_size(), BOOT_MEM_RAM);
449 @@ -107,4 +110,13 @@ void __init plat_mem_setup(void)
450 set_io_port_base(0);
451 ioport_resource.start = 0;
452 ioport_resource.end = ~0;
453 +
454 + board_setup();
455 +}
456 +
457 +int __init bcm63xx_register_devices(void)
458 +{
459 + return board_register_devices();
460 }
461 +
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
464 new file mode 100644
465 index 0000000..fa3e7e6
466 --- /dev/null
467 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_board.h
468 @@ -0,0 +1,12 @@
469 +#ifndef BCM63XX_BOARD_H_
470 +#define BCM63XX_BOARD_H_
471 +
472 +const char *board_get_name(void);
473 +
474 +void board_prom_init(void);
475 +
476 +void board_setup(void);
477 +
478 +int board_register_devices(void);
479 +
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
482 new file mode 100644
483 index 0000000..17e4e7e
484 --- /dev/null
485 +++ b/include/asm-mips/mach-bcm63xx/board_bcm963xx.h
486 @@ -0,0 +1,50 @@
487 +#ifndef BOARD_BCM963XX_H_
488 +#define BOARD_BCM963XX_H_
489 +
490 +#include <linux/types.h>
491 +#include <bcm63xx_dev_enet.h>
492 +
493 +/*
494 + * flash mapping
495 + */
496 +#define BCM963XX_CFE_VERSION_OFFSET 0x570
497 +#define BCM963XX_NVRAM_OFFSET 0x580
498 +
499 +/*
500 + * nvram structure
501 + */
502 +struct bcm963xx_nvram {
503 + u32 version;
504 + u8 reserved1[256];
505 + u8 name[16];
506 + u32 main_tp_number;
507 + u32 psi_size;
508 + u32 mac_addr_count;
509 + u8 mac_addr_base[6];
510 + u8 reserved2[2];
511 + u32 checksum_old;
512 + u8 reserved3[720];
513 + u32 checksum_high;
514 +};
515 +
516 +/*
517 + * board definition
518 + */
519 +struct board_info {
520 + u8 name[16];
521 + unsigned int expected_cpu_id;
522 +
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;
530 +
531 + /* ethernet config */
532 + struct bcm63xx_enet_platform_data enet0;
533 + struct bcm63xx_enet_platform_data enet1;
534 +};
535 +
536 +#endif /* ! BOARD_BCM963XX_H_ */
537 --
538 1.5.4.3
539
This page took 0.061561 seconds and 3 git commands to generate.