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