ARM: MM: Add DT binding for Feroceon L2 cache
[linux-2.6-block.git] / arch / arm / mach-kirkwood / board-dt.c
CommitLineData
3d468b6d
JC
1/*
2 * Copyright 2012 (C), Jason Cooper <jason@lakedaemon.net>
3 *
4 * arch/arm/mach-kirkwood/board-dt.c
5 *
6fa6b878 6 * Flattened Device Tree board initialization
3d468b6d
JC
7 *
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
11 */
12
e3e8e588 13#include <linux/clk.h>
3d468b6d
JC
14#include <linux/kernel.h>
15#include <linux/init.h>
3d468b6d 16#include <linux/of.h>
ebd7d3ab
SH
17#include <linux/of_address.h>
18#include <linux/of_net.h>
3d468b6d 19#include <linux/of_platform.h>
2326f043
SH
20#include <linux/dma-mapping.h>
21#include <linux/irqchip.h>
a7ac56de 22#include <linux/kexec.h>
3c317d00 23#include <asm/hardware/cache-feroceon-l2.h>
3d468b6d 24#include <asm/mach/arch.h>
dab7dfb6 25#include <asm/mach/map.h>
2b45e05f 26#include <mach/bridge-regs.h>
1611f872 27#include <plat/common.h>
dab7dfb6 28#include <plat/pcie.h>
c3b6144a 29#include "pm.h"
3d468b6d 30
dab7dfb6
AL
31static struct map_desc kirkwood_io_desc[] __initdata = {
32 {
33 .virtual = (unsigned long) KIRKWOOD_REGS_VIRT_BASE,
34 .pfn = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
35 .length = KIRKWOOD_REGS_SIZE,
36 .type = MT_DEVICE,
37 },
38};
39
40static void __init kirkwood_map_io(void)
41{
42 iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc));
43}
44
dab7dfb6
AL
45static struct resource kirkwood_cpufreq_resources[] = {
46 [0] = {
47 .start = CPU_CONTROL_PHYS,
48 .end = CPU_CONTROL_PHYS + 3,
49 .flags = IORESOURCE_MEM,
50 },
51};
52
53static struct platform_device kirkwood_cpufreq_device = {
54 .name = "kirkwood-cpufreq",
55 .id = -1,
56 .num_resources = ARRAY_SIZE(kirkwood_cpufreq_resources),
57 .resource = kirkwood_cpufreq_resources,
58};
59
60static void __init kirkwood_cpufreq_init(void)
61{
62 platform_device_register(&kirkwood_cpufreq_device);
63}
64
65static struct resource kirkwood_cpuidle_resource[] = {
66 {
67 .flags = IORESOURCE_MEM,
68 .start = DDR_OPERATION_BASE,
69 .end = DDR_OPERATION_BASE + 3,
70 },
71};
72
73static struct platform_device kirkwood_cpuidle = {
74 .name = "kirkwood_cpuidle",
75 .id = -1,
76 .resource = kirkwood_cpuidle_resource,
77 .num_resources = 1,
78};
79
80static void __init kirkwood_cpuidle_init(void)
81{
82 platform_device_register(&kirkwood_cpuidle);
83}
84
85/* Temporary here since mach-mvebu has a function we can use */
86static void kirkwood_restart(enum reboot_mode mode, const char *cmd)
87{
88 /*
89 * Enable soft reset to assert RSTOUTn.
90 */
91 writel(SOFT_RESET_OUT_EN, RSTOUTn_MASK);
92
93 /*
94 * Assert soft reset.
95 */
96 writel(SOFT_RESET, SYSTEM_SOFT_RESET);
97
98 while (1)
99 ;
100}
101
ebd7d3ab
SH
102#define MV643XX_ETH_MAC_ADDR_LOW 0x0414
103#define MV643XX_ETH_MAC_ADDR_HIGH 0x0418
104
105static void __init kirkwood_dt_eth_fixup(void)
106{
107 struct device_node *np;
108
109 /*
110 * The ethernet interfaces forget the MAC address assigned by u-boot
111 * if the clocks are turned off. Usually, u-boot on kirkwood boards
112 * has no DT support to properly set local-mac-address property.
113 * As a workaround, we get the MAC address from mv643xx_eth registers
114 * and update the port device node if no valid MAC address is set.
115 */
116 for_each_compatible_node(np, NULL, "marvell,kirkwood-eth-port") {
117 struct device_node *pnp = of_get_parent(np);
118 struct clk *clk;
119 struct property *pmac;
120 void __iomem *io;
121 u8 *macaddr;
122 u32 reg;
123
124 if (!pnp)
125 continue;
126
127 /* skip disabled nodes or nodes with valid MAC address*/
128 if (!of_device_is_available(pnp) || of_get_mac_address(np))
129 goto eth_fixup_skip;
130
131 clk = of_clk_get(pnp, 0);
132 if (IS_ERR(clk))
133 goto eth_fixup_skip;
134
135 io = of_iomap(pnp, 0);
136 if (!io)
137 goto eth_fixup_no_map;
138
139 /* ensure port clock is not gated to not hang CPU */
140 clk_prepare_enable(clk);
141
142 /* store MAC address register contents in local-mac-address */
143 pr_err(FW_INFO "%s: local-mac-address is not set\n",
144 np->full_name);
145
146 pmac = kzalloc(sizeof(*pmac) + 6, GFP_KERNEL);
147 if (!pmac)
148 goto eth_fixup_no_mem;
149
150 pmac->value = pmac + 1;
151 pmac->length = 6;
152 pmac->name = kstrdup("local-mac-address", GFP_KERNEL);
153 if (!pmac->name) {
154 kfree(pmac);
155 goto eth_fixup_no_mem;
156 }
157
158 macaddr = pmac->value;
159 reg = readl(io + MV643XX_ETH_MAC_ADDR_HIGH);
160 macaddr[0] = (reg >> 24) & 0xff;
161 macaddr[1] = (reg >> 16) & 0xff;
162 macaddr[2] = (reg >> 8) & 0xff;
163 macaddr[3] = reg & 0xff;
164
165 reg = readl(io + MV643XX_ETH_MAC_ADDR_LOW);
166 macaddr[4] = (reg >> 8) & 0xff;
167 macaddr[5] = reg & 0xff;
168
169 of_update_property(np, pmac);
170
171eth_fixup_no_mem:
172 iounmap(io);
173 clk_disable_unprepare(clk);
174eth_fixup_no_map:
175 clk_put(clk);
176eth_fixup_skip:
177 of_node_put(pnp);
178 }
179}
180
7f28fd6e
AL
181/*
182 * Disable propagation of mbus errors to the CPU local bus, as this
183 * causes mbus errors (which can occur for example for PCI aborts) to
184 * throw CPU aborts, which we're not set up to deal with.
185 */
186static void __init kirkwood_disable_mbus_error_propagation(void)
187{
188 void __iomem *cpu_config;
189
190 cpu_config = ioremap(CPU_CONFIG_PHYS, 4);
191 writel(readl(cpu_config) & ~CPU_CONFIG_ERROR_PROP, cpu_config);
192 iounmap(cpu_config);
193}
194
3d468b6d
JC
195static void __init kirkwood_dt_init(void)
196{
7f28fd6e 197 kirkwood_disable_mbus_error_propagation();
2b45e05f 198
0789d0b2 199 BUG_ON(mvebu_mbus_dt_init());
2b45e05f 200
4b8f7a11
AL
201#ifdef CONFIG_CACHE_FEROCEON_L2
202 feroceon_of_init();
203#endif
0e2ee0c0 204 kirkwood_cpufreq_init();
ebd7d3ab 205 kirkwood_cpuidle_init();
2b45e05f 206
e1cb367d 207 kirkwood_pm_init();
ebd7d3ab 208 kirkwood_dt_eth_fixup();
9cfc94eb 209
2b45e05f
JC
210#ifdef CONFIG_KEXEC
211 kexec_reinit = kirkwood_enable_pcie;
212#endif
3d468b6d 213
3207792e 214 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
3d468b6d
JC
215}
216
98adf932 217static const char * const kirkwood_dt_board_compat[] = {
a977e18e 218 "marvell,kirkwood",
3d468b6d
JC
219 NULL
220};
221
222DT_MACHINE_START(KIRKWOOD_DT, "Marvell Kirkwood (Flattened Device Tree)")
223 /* Maintainer: Jason Cooper <jason@lakedaemon.net> */
224 .map_io = kirkwood_map_io,
3d468b6d
JC
225 .init_machine = kirkwood_dt_init,
226 .restart = kirkwood_restart,
227 .dt_compat = kirkwood_dt_board_compat,
228MACHINE_END