mpc85xx: add support for 3.8
[openwrt/svn-archive/archive.git] / target / linux / mpc85xx / patches-3.8 / 140-powerpc-85xx-tl-wdr4900-v1-support.patch
1 From 406d86e5990ac171f18ef6e2973672d8fbfe1556 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Wed, 20 Feb 2013 08:40:33 +0100
4 Subject: [PATCH] powerpc: 85xx: add support for the TP-Link TL-WDR4900 v1
5 board
6
7 This patch adds support for the TP-Link TL-WDR4900 v1
8 concurrent dual-band wireless router. The devices uses
9 the Freescale P1014 SoC.
10
11 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
12 ---
13 arch/powerpc/boot/Makefile | 3 +
14 arch/powerpc/boot/cuboot-tl-wdr4900-v1.c | 164 ++++++++++++++++++++++++++
15 arch/powerpc/boot/dts/tl-wdr4900-v1.dts | 166 +++++++++++++++++++++++++++
16 arch/powerpc/boot/wrapper | 4 +
17 arch/powerpc/platforms/85xx/Kconfig | 11 ++
18 arch/powerpc/platforms/85xx/Makefile | 1 +
19 arch/powerpc/platforms/85xx/tl_wdr4900_v1.c | 145 +++++++++++++++++++++++
20 7 files changed, 494 insertions(+)
21 create mode 100644 arch/powerpc/boot/cuboot-tl-wdr4900-v1.c
22 create mode 100644 arch/powerpc/boot/dts/tl-wdr4900-v1.dts
23 create mode 100644 arch/powerpc/platforms/85xx/tl_wdr4900_v1.c
24
25 --- a/arch/powerpc/boot/Makefile
26 +++ b/arch/powerpc/boot/Makefile
27 @@ -98,6 +98,8 @@ src-plat-$(CONFIG_EMBEDDED6xx) += cuboot
28 src-plat-$(CONFIG_AMIGAONE) += cuboot-amigaone.c
29 src-plat-$(CONFIG_PPC_PS3) += ps3-head.S ps3-hvcall.S ps3.c
30 src-plat-$(CONFIG_EPAPR_BOOT) += epapr.c
31 +src-plat-$(CONFIG_TL_WDR4900_V1) += cuboot-tl-wdr4900-v1.c
32 +
33
34 src-wlib := $(sort $(src-wlib-y))
35 src-plat := $(sort $(src-plat-y))
36 @@ -278,6 +280,7 @@ image-$(CONFIG_TQM8555) += cuImage.tqm
37 image-$(CONFIG_TQM8560) += cuImage.tqm8560
38 image-$(CONFIG_SBC8548) += cuImage.sbc8548
39 image-$(CONFIG_KSI8560) += cuImage.ksi8560
40 +image-$(CONFIG_TL_WDR4900_V1) += cuImage.tl-wdr4900-v1
41
42 # Board ports in arch/powerpc/platform/embedded6xx/Kconfig
43 image-$(CONFIG_STORCENTER) += cuImage.storcenter
44 --- /dev/null
45 +++ b/arch/powerpc/boot/cuboot-tl-wdr4900-v1.c
46 @@ -0,0 +1,164 @@
47 +/*
48 + * U-Boot compatibility wrapper for the TP-Link TL-WDR4900 v1 board
49 + *
50 + * Copyright (c) 2013 Gabor Juhos <juhosg@openwrt.org>
51 + *
52 + * Based on:
53 + * cuboot-85xx.c
54 + * Author: Scott Wood <scottwood@freescale.com>
55 + * Copyright (c) 2007 Freescale Semiconductor, Inc.
56 + *
57 + * simpleboot.c
58 + * Authors: Scott Wood <scottwood@freescale.com>
59 + * Grant Likely <grant.likely@secretlab.ca>
60 + * Copyright (c) 2007 Freescale Semiconductor, Inc.
61 + * Copyright (c) 2008 Secret Lab Technologies Ltd.
62 + *
63 + * This program is free software; you can redistribute it and/or modify it
64 + * under the terms of the GNU General Public License version 2 as published
65 + * by the Free Software Foundation.
66 + */
67 +
68 +#include "ops.h"
69 +#include "types.h"
70 +#include "io.h"
71 +#include "stdio.h"
72 +#include <libfdt.h>
73 +
74 +BSS_STACK(4*1024);
75 +
76 +static unsigned long bus_freq;
77 +static unsigned long int_freq;
78 +static u64 mem_size;
79 +static unsigned char enetaddr[6];
80 +
81 +static void process_boot_dtb(void *boot_dtb)
82 +{
83 + const u32 *na, *ns, *reg, *val32;
84 + const char *path;
85 + u64 memsize64;
86 + int node, size, i;
87 +
88 + /* Make sure FDT blob is sane */
89 + if (fdt_check_header(boot_dtb) != 0)
90 + fatal("Invalid device tree blob\n");
91 +
92 + /* Find the #address-cells and #size-cells properties */
93 + node = fdt_path_offset(boot_dtb, "/");
94 + if (node < 0)
95 + fatal("Cannot find root node\n");
96 + na = fdt_getprop(boot_dtb, node, "#address-cells", &size);
97 + if (!na || (size != 4))
98 + fatal("Cannot find #address-cells property");
99 +
100 + ns = fdt_getprop(boot_dtb, node, "#size-cells", &size);
101 + if (!ns || (size != 4))
102 + fatal("Cannot find #size-cells property");
103 +
104 + /* Find the memory range */
105 + node = fdt_node_offset_by_prop_value(boot_dtb, -1, "device_type",
106 + "memory", sizeof("memory"));
107 + if (node < 0)
108 + fatal("Cannot find memory node\n");
109 + reg = fdt_getprop(boot_dtb, node, "reg", &size);
110 + if (size < (*na+*ns) * sizeof(u32))
111 + fatal("cannot get memory range\n");
112 +
113 + /* Only interested in memory based at 0 */
114 + for (i = 0; i < *na; i++)
115 + if (*reg++ != 0)
116 + fatal("Memory range is not based at address 0\n");
117 +
118 + /* get the memsize and trucate it to under 4G on 32 bit machines */
119 + memsize64 = 0;
120 + for (i = 0; i < *ns; i++)
121 + memsize64 = (memsize64 << 32) | *reg++;
122 + if (sizeof(void *) == 4 && memsize64 >= 0x100000000ULL)
123 + memsize64 = 0xffffffff;
124 +
125 + mem_size = memsize64;
126 +
127 + /* get clock frequencies */
128 + node = fdt_node_offset_by_prop_value(boot_dtb, -1, "device_type",
129 + "cpu", sizeof("cpu"));
130 + if (!node)
131 + fatal("Cannot find cpu node\n");
132 +
133 + val32 = fdt_getprop(boot_dtb, node, "clock-frequency", &size);
134 + if (!val32 || (size != 4))
135 + fatal("Cannot get clock frequency");
136 +
137 + int_freq = *val32;
138 +
139 + val32 = fdt_getprop(boot_dtb, node, "bus-frequency", &size);
140 + if (!val32 || (size != 4))
141 + fatal("Cannot get bus frequency");
142 +
143 + bus_freq = *val32;
144 +
145 + path = fdt_get_alias(boot_dtb, "ethernet0");
146 + if (path) {
147 + const void *p;
148 +
149 + node = fdt_path_offset(boot_dtb, path);
150 + if (node < 0)
151 + fatal("Cannot find ethernet0 node");
152 +
153 + p = fdt_getprop(boot_dtb, node, "mac-address", &size);
154 + if (!p || (size < 6)) {
155 + printf("no mac-address property, finding local\n\r");
156 + p = fdt_getprop(boot_dtb, node, "local-mac-address", &size);
157 + }
158 +
159 + if (!p || (size < 6))
160 + fatal("cannot get MAC addres");
161 +
162 + memcpy(enetaddr, p, sizeof(enetaddr));
163 + }
164 +}
165 +
166 +static void platform_fixups(void)
167 +{
168 + void *soc;
169 +
170 + dt_fixup_memory(0, mem_size);
171 +
172 + dt_fixup_mac_address_by_alias("ethernet0", enetaddr);
173 + dt_fixup_cpu_clocks(int_freq, bus_freq / 8, bus_freq);
174 +
175 + /* Unfortunately, the specific model number is encoded in the
176 + * soc node name in existing dts files -- once that is fixed,
177 + * this can do a simple path lookup.
178 + */
179 + soc = find_node_by_devtype(NULL, "soc");
180 + if (soc) {
181 + void *serial = NULL;
182 +
183 + setprop(soc, "bus-frequency", &bus_freq, sizeof(bus_freq));
184 +
185 + while ((serial = find_node_by_devtype(serial, "serial"))) {
186 + if (get_parent(serial) != soc)
187 + continue;
188 +
189 + setprop(serial, "clock-frequency", &bus_freq,
190 + sizeof(bus_freq));
191 + }
192 + }
193 +}
194 +
195 +void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
196 + unsigned long r6, unsigned long r7)
197 +{
198 + mem_size = 64 * 1024 * 1024;
199 +
200 + simple_alloc_init(_end, mem_size - (u32)_end - 1024*1024, 32, 64);
201 +
202 + fdt_init(_dtb_start);
203 + serial_console_init();
204 +
205 + printf("\n\r-- TL-WDR4900 v1 boot wrapper --\n\r");
206 +
207 + process_boot_dtb((void *) r3);
208 +
209 + platform_ops.fixups = platform_fixups;
210 +}
211 --- /dev/null
212 +++ b/arch/powerpc/boot/dts/tl-wdr4900-v1.dts
213 @@ -0,0 +1,198 @@
214 +/*
215 + * TP-Link TL-WDR4900 v1 Device Tree Source
216 + *
217 + * Copyright 2013 Gabor Juhos <juhosg@openwrt.org>
218 + *
219 + * This program is free software; you can redistribute it and/or modify it
220 + * under the terms of the GNU General Public License as published by the
221 + * Free Software Foundation; either version 2 of the License, or (at your
222 + * option) any later version.
223 + */
224 +
225 +/include/ "fsl/p1010si-pre.dtsi"
226 +
227 +/ {
228 + model = "TP-Link TL-WDR4900 v1";
229 + compatible = "tp-link,TL-WDR4900v1";
230 +
231 + chosen {
232 + bootargs = "console=ttyS0,115200";
233 +/*
234 + linux,stdout-path = "/soc@ffe00000/serial@4500";
235 +*/
236 + };
237 +
238 + memory {
239 + device_type = "memory";
240 + };
241 +
242 + soc: soc@ffe00000 {
243 + ranges = <0x0 0x0 0xffe00000 0x100000>;
244 +
245 + spi0: spi@7000 {
246 + flash@0 {
247 + #address-cells = <1>;
248 + #size-cells = <1>;
249 + compatible = "spansion,s25fl129p1";
250 + reg = <0>;
251 + spi-max-frequency = <25000000>;
252 +
253 + u-boot@0 {
254 + reg = <0x0 0x0050000>;
255 + label = "u-boot";
256 + read-only;
257 + };
258 +
259 + dtb@50000 {
260 + reg = <0x00050000 0x00010000>;
261 + label = "dtb";
262 + read-only;
263 + };
264 +
265 + kernel@60000 {
266 + reg = <0x00060000 0x002a0000>;
267 + label = "kernel";
268 + };
269 +
270 + rootfs@300000 {
271 + reg = <0x00300000 0x00ce0000>;
272 + label = "rootfs";
273 + };
274 +
275 + config@fe0000 {
276 + reg = <0x00fe0000 0x00010000>;
277 + label = "config";
278 + read-only;
279 + };
280 +
281 + caldata@ff0000 {
282 + reg = <0x00ff0000 0x00010000>;
283 + label = "caldata";
284 + read-only;
285 + };
286 +
287 + firmware@60000 {
288 + reg = <0x00060000 0x00f80000>;
289 + label = "firmware";
290 + };
291 + };
292 + };
293 +
294 + gpio0: gpio-controller@f000 {
295 + };
296 +
297 + usb@22000 {
298 + phy_type = "utmi";
299 + dr_mode = "host";
300 + };
301 +
302 + mdio@24000 {
303 + phy0: ethernet-phy@0 {
304 + /* interrupts = <3 1 0 0>; */
305 + reg = <0x0>;
306 + };
307 + };
308 +
309 + mdio@25000 {
310 + status = "disabled";
311 + };
312 +
313 + mdio@26000 {
314 + status = "disabled";
315 + };
316 +
317 + enet0: ethernet@b0000 {
318 + phy-handle = <&phy0>;
319 + phy-connection-type = "rgmii-id";
320 + };
321 +
322 + enet1: ethernet@b1000 {
323 + status = "disabled";
324 + };
325 +
326 + enet2: ethernet@b2000 {
327 + status = "disabled";
328 + };
329 +
330 + sdhc@2e000 {
331 + status = "disabled";
332 + };
333 +
334 + serial1: serial@4600 {
335 + status = "disabled";
336 + };
337 +
338 + can0: can@1c000 {
339 + status = "disabled";
340 + };
341 +
342 + can1: can@1d000 {
343 + status = "disabled";
344 + };
345 + };
346 +
347 + pci0: pcie@ffe09000 {
348 + reg = <0 0xffe09000 0 0x1000>;
349 + ranges = <0x2000000 0x0 0xa0000000 0 0xa0000000 0x0 0x20000000
350 + 0x1000000 0x0 0x00000000 0 0xffc10000 0x0 0x10000>;
351 + pcie@0 {
352 + ranges = <0x2000000 0x0 0xa0000000
353 + 0x2000000 0x0 0xa0000000
354 + 0x0 0x20000000
355 +
356 + 0x1000000 0x0 0x0
357 + 0x1000000 0x0 0x0
358 + 0x0 0x100000>;
359 + };
360 + };
361 +
362 + pci1: pcie@ffe0a000 {
363 + reg = <0 0xffe0a000 0 0x1000>;
364 + ranges = <0x2000000 0x0 0x80000000 0 0x80000000 0x0 0x20000000
365 + 0x1000000 0x0 0x00000000 0 0xffc00000 0x0 0x10000>;
366 + pcie@0 {
367 + ranges = <0x2000000 0x0 0x80000000
368 + 0x2000000 0x0 0x80000000
369 + 0x0 0x20000000
370 +
371 + 0x1000000 0x0 0x0
372 + 0x1000000 0x0 0x0
373 + 0x0 0x100000>;
374 + };
375 + };
376 +
377 + ifc: ifc@ffe1e000 {
378 + status = "disabled";
379 + };
380 +
381 + leds {
382 + compatible = "gpio-leds";
383 +
384 + system {
385 + gpios = <&gpio0 2 1>; /* active low */
386 + label = "tp-link:blue:system";
387 + };
388 +
389 + usb1 {
390 + gpios = <&gpio0 3 1>; /* active low */
391 + label = "tp-link:green:usb1";
392 + };
393 +
394 + usb2 {
395 + gpios = <&gpio0 4 1>; /* active low */
396 + label = "tp-link:green:usb2";
397 + };
398 + };
399 +
400 + buttons {
401 + compatible = "gpio-keys";
402 +
403 + reset {
404 + label = "Reset button";
405 + gpios = <&gpio0 5 1>; /* active low */
406 + linux,code = <0x198>; /* KEY_RESTART */
407 + };
408 + };
409 +};
410 +
411 +/include/ "fsl/p1010si-post.dtsi"
412 --- a/arch/powerpc/boot/wrapper
413 +++ b/arch/powerpc/boot/wrapper
414 @@ -197,6 +197,10 @@ cuboot*)
415 *-mpc85*|*-tqm85*|*-sbc85*)
416 platformo=$object/cuboot-85xx.o
417 ;;
418 + *-tl-wdr4900-v1)
419 + platformo=$object/cuboot-tl-wdr4900-v1.o
420 + link_address='0x1000000'
421 + ;;
422 *-amigaone)
423 link_address='0x800000'
424 ;;
425 --- a/arch/powerpc/platforms/85xx/Kconfig
426 +++ b/arch/powerpc/platforms/85xx/Kconfig
427 @@ -147,6 +147,17 @@ config STX_GP3
428 select CPM2
429 select DEFAULT_UIMAGE
430
431 +config TL_WDR4900_V1
432 + bool "TP-Link TL-WDR4900 v1"
433 + select DEFAULT_UIMAGE
434 + select ARCH_REQUIRE_GPIOLIB
435 + select GPIO_MPC8XXX
436 + help
437 + This option enables support for the TP-Link TL-WDR4900 v1 board.
438 +
439 + This board is a Concurrent Dual-Band wireless router with a
440 + Freescale P1014 SoC.
441 +
442 config TQM8540
443 bool "TQ Components TQM8540"
444 help
445 --- a/arch/powerpc/platforms/85xx/Makefile
446 +++ b/arch/powerpc/platforms/85xx/Makefile
447 @@ -24,6 +24,7 @@ obj-$(CONFIG_P5020_DS) += p5020_ds.o
448 obj-$(CONFIG_P5040_DS) += p5040_ds.o corenet_ds.o
449 obj-$(CONFIG_STX_GP3) += stx_gp3.o
450 obj-$(CONFIG_TQM85xx) += tqm85xx.o
451 +obj-$(CONFIG_TL_WDR4900_V1) += tl_wdr4900_v1.o
452 obj-$(CONFIG_SBC8548) += sbc8548.o
453 obj-$(CONFIG_SOCRATES) += socrates.o socrates_fpga_pic.o
454 obj-$(CONFIG_KSI8560) += ksi8560.o
455 --- /dev/null
456 +++ b/arch/powerpc/platforms/85xx/tl_wdr4900_v1.c
457 @@ -0,0 +1,145 @@
458 +/*
459 + * TL-WDR4900 v1 board setup
460 + *
461 + * Copyright (c) 2013 Gabor Juhos <juhosg@openwrt.org>
462 + *
463 + * Based on:
464 + * p1010rdb.c:
465 + * P1010RDB Board Setup
466 + * Copyright 2011 Freescale Semiconductor Inc.
467 + *
468 + * This program is free software; you can redistribute it and/or modify it
469 + * under the terms of the GNU General Public License as published by the
470 + * Free Software Foundation; either version 2 of the License, or (at your
471 + * option) any later version.
472 + */
473 +
474 +#include <linux/stddef.h>
475 +#include <linux/kernel.h>
476 +#include <linux/pci.h>
477 +#include <linux/delay.h>
478 +#include <linux/interrupt.h>
479 +#include <linux/of_platform.h>
480 +#include <linux/ath9k_platform.h>
481 +#include <linux/leds.h>
482 +
483 +#include <asm/time.h>
484 +#include <asm/machdep.h>
485 +#include <asm/pci-bridge.h>
486 +#include <mm/mmu_decl.h>
487 +#include <asm/prom.h>
488 +#include <asm/udbg.h>
489 +#include <asm/mpic.h>
490 +
491 +#include <sysdev/fsl_soc.h>
492 +#include <sysdev/fsl_pci.h>
493 +
494 +#include "mpc85xx.h"
495 +
496 +void __init tl_wdr4900_v1_pic_init(void)
497 +{
498 + struct mpic *mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN |
499 + MPIC_SINGLE_DEST_CPU,
500 + 0, 256, " OpenPIC ");
501 +
502 + BUG_ON(mpic == NULL);
503 +
504 + mpic_init(mpic);
505 +}
506 +
507 +#ifdef CONFIG_PCI
508 +static struct gpio_led tl_wdr4900_v1_wmac_leds_gpio[] = {
509 + {
510 + .name = "tp-link:blue:wps",
511 + .gpio = 1,
512 + .active_low = 1,
513 + },
514 +};
515 +
516 +static struct ath9k_platform_data tl_wdr4900_v1_wmac0_data = {
517 + .led_pin = 0,
518 + .eeprom_name = "pci_wmac0.eeprom",
519 + .leds = tl_wdr4900_v1_wmac_leds_gpio,
520 + .num_leds = ARRAY_SIZE(tl_wdr4900_v1_wmac_leds_gpio),
521 +};
522 +
523 +static struct ath9k_platform_data tl_wdr4900_v1_wmac1_data = {
524 + .led_pin = 0,
525 + .eeprom_name = "pci_wmac1.eeprom",
526 +};
527 +
528 +static void tl_wdr4900_v1_pci_wmac_fixup(struct pci_dev *dev)
529 +{
530 + if (!machine_is(tl_wdr4900_v1))
531 + return;
532 +
533 + if (dev->bus->number == 1 &&
534 + PCI_SLOT(dev->devfn) == 0) {
535 + dev->dev.platform_data = &tl_wdr4900_v1_wmac0_data;
536 + return;
537 + }
538 +
539 + if (dev->bus->number == 3 &&
540 + PCI_SLOT(dev->devfn) == 0 &&
541 + dev->device == 0xabcd) {
542 + dev->dev.platform_data = &tl_wdr4900_v1_wmac1_data;
543 +
544 + /*
545 + * The PCI header of the AR9381 chip is not programmed
546 + * correctly by the bootloader and the device uses wrong
547 + * data due to that. Replace the broken values with the
548 + * correct ones.
549 + */
550 + dev->device = 0x30;
551 + dev->class = 0x028000;
552 +
553 + pr_info("pci %s: AR9381 fixup applied\n", pci_name(dev));
554 + }
555 +}
556 +
557 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID,
558 + tl_wdr4900_v1_pci_wmac_fixup);
559 +#endif /* CONFIG_PCI */
560 +
561 +/*
562 + * Setup the architecture
563 + */
564 +static void __init tl_wdr4900_v1_setup_arch(void)
565 +{
566 + if (ppc_md.progress)
567 + ppc_md.progress("tl_wdr4900_v1_setup_arch()", 0);
568 +
569 + fsl_pci_assign_primary();
570 +
571 + printk(KERN_INFO "TL-WDR4900 v1 board from TP-Link\n");
572 +}
573 +
574 +machine_arch_initcall(tl_wdr4900_v1, mpc85xx_common_publish_devices);
575 +machine_arch_initcall(tl_wdr4900_v1, swiotlb_setup_bus_notifier);
576 +
577 +/*
578 + * Called very early, device-tree isn't unflattened
579 + */
580 +static int __init tl_wdr4900_v1_probe(void)
581 +{
582 + unsigned long root = of_get_flat_dt_root();
583 +
584 + if (of_flat_dt_is_compatible(root, "tp-link,TL-WDR4900v1"))
585 + return 1;
586 +
587 + return 0;
588 +}
589 +
590 +define_machine(tl_wdr4900_v1) {
591 + .name = "Freescale P1014",
592 + .probe = tl_wdr4900_v1_probe,
593 + .setup_arch = tl_wdr4900_v1_setup_arch,
594 + .init_IRQ = tl_wdr4900_v1_pic_init,
595 +#ifdef CONFIG_PCI
596 + .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
597 +#endif
598 + .get_irq = mpic_get_irq,
599 + .restart = fsl_rstcr_restart,
600 + .calibrate_decr = generic_calibrate_decr,
601 + .progress = udbg_progress,
602 +};