ralink: update patches
[openwrt.git] / target / linux / ramips / patches-3.8 / 0006-MIPS-ralink-adds-OF-code.patch
1 From 4b2f9abbbaf3463a0fc1a65afeb0d12f890ada35 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sun, 20 Jan 2013 22:02:01 +0100
4 Subject: [PATCH 06/79] MIPS: ralink: adds OF code
5
6 Until there is a generic MIPS way of handing the DTB over from bootloader to
7 kernel we rely on a built in devicetrees. The OF code also remaps those register
8 ranges that we use global in our drivers.
9
10 Signed-off-by: John Crispin <blogic@openwrt.org>
11 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
12 Patchwork: http://patchwork.linux-mips.org/patch/4895/
13 ---
14  arch/mips/ralink/of.c |  107 +++++++++++++++++++++++++++++++++++++++++++++++++
15  1 file changed, 107 insertions(+)
16  create mode 100644 arch/mips/ralink/of.c
17
18 diff --git a/arch/mips/ralink/of.c b/arch/mips/ralink/of.c
19 new file mode 100644
20 index 0000000..4165e70
21 --- /dev/null
22 +++ b/arch/mips/ralink/of.c
23 @@ -0,0 +1,107 @@
24 +/*
25 + * This program is free software; you can redistribute it and/or modify it
26 + * under the terms of the GNU General Public License version 2 as published
27 + * by the Free Software Foundation.
28 + *
29 + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
30 + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
31 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
32 + */
33 +
34 +#include <linux/io.h>
35 +#include <linux/clk.h>
36 +#include <linux/init.h>
37 +#include <linux/of_fdt.h>
38 +#include <linux/kernel.h>
39 +#include <linux/bootmem.h>
40 +#include <linux/of_platform.h>
41 +#include <linux/of_address.h>
42 +
43 +#include <asm/reboot.h>
44 +#include <asm/bootinfo.h>
45 +#include <asm/addrspace.h>
46 +
47 +#include "common.h"
48 +
49 +__iomem void *rt_sysc_membase;
50 +__iomem void *rt_memc_membase;
51 +
52 +extern struct boot_param_header __dtb_start;
53 +
54 +__iomem void *plat_of_remap_node(const char *node)
55 +{
56 +       struct resource res;
57 +       struct device_node *np;
58 +
59 +       np = of_find_compatible_node(NULL, NULL, node);
60 +       if (!np)
61 +               panic("Failed to find %s node", node);
62 +
63 +       if (of_address_to_resource(np, 0, &res))
64 +               panic("Failed to get resource for %s", node);
65 +
66 +       if ((request_mem_region(res.start,
67 +                               resource_size(&res),
68 +                               res.name) < 0))
69 +               panic("Failed to request resources for %s", node);
70 +
71 +       return ioremap_nocache(res.start, resource_size(&res));
72 +}
73 +
74 +void __init device_tree_init(void)
75 +{
76 +       unsigned long base, size;
77 +       void *fdt_copy;
78 +
79 +       if (!initial_boot_params)
80 +               return;
81 +
82 +       base = virt_to_phys((void *)initial_boot_params);
83 +       size = be32_to_cpu(initial_boot_params->totalsize);
84 +
85 +       /* Before we do anything, lets reserve the dt blob */
86 +       reserve_bootmem(base, size, BOOTMEM_DEFAULT);
87 +
88 +       /* The strings in the flattened tree are referenced directly by the
89 +        * device tree, so copy the flattened device tree from init memory
90 +        * to regular memory.
91 +        */
92 +       fdt_copy = alloc_bootmem(size);
93 +       memcpy(fdt_copy, initial_boot_params, size);
94 +       initial_boot_params = fdt_copy;
95 +
96 +       unflatten_device_tree();
97 +
98 +       /* free the space reserved for the dt blob */
99 +       free_bootmem(base, size);
100 +}
101 +
102 +void __init plat_mem_setup(void)
103 +{
104 +       set_io_port_base(KSEG1);
105 +
106 +       /*
107 +        * Load the builtin devicetree. This causes the chosen node to be
108 +        * parsed resulting in our memory appearing
109 +        */
110 +       __dt_setup_arch(&__dtb_start);
111 +}
112 +
113 +static int __init plat_of_setup(void)
114 +{
115 +       static struct of_device_id of_ids[3];
116 +       int len = sizeof(of_ids[0].compatible);
117 +
118 +       if (!of_have_populated_dt())
119 +               panic("device tree not present");
120 +
121 +       strncpy(of_ids[0].compatible, soc_info.compatible, len);
122 +       strncpy(of_ids[1].compatible, "palmbus", len);
123 +
124 +       if (of_platform_populate(NULL, of_ids, NULL, NULL))
125 +               panic("failed to populate DT\n");
126 +
127 +       return 0;
128 +}
129 +
130 +arch_initcall(plat_of_setup);
131 -- 
132 1.7.10.4
133