blob: 89a139ed7d5bd3969f04d651d3cb29b122afb3e3 [file] [log] [blame]
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +02001/*
2 * Device Tree support for Armada 370 and XP platforms.
3 *
4 * Copyright (C) 2012 Marvell
5 *
6 * Lior Amsalem <alior@marvell.com>
7 * Gregory CLEMENT <gregory.clement@free-electrons.com>
8 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
9 *
10 * This file is licensed under the terms of the GNU General Public
11 * License version 2. This program is licensed "as is" without any
12 * warranty of any kind, whether express or implied.
13 */
14
15#include <linux/kernel.h>
16#include <linux/init.h>
Sebastian Hesselbarth9cbbc512013-05-11 03:08:09 +020017#include <linux/clk-provider.h>
Thomas Petazzonid834d262013-06-05 09:04:59 +020018#include <linux/of_address.h>
Thomas Petazzoni8da2b2f2014-11-21 17:00:07 +010019#include <linux/of_fdt.h>
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020020#include <linux/of_platform.h>
21#include <linux/io.h>
Ezequiel Garcia573145f2013-08-13 11:43:12 -030022#include <linux/clocksource.h>
Gregory CLEMENT53d2f882012-10-26 14:30:46 +020023#include <linux/dma-mapping.h>
Thomas Petazzoni8da2b2f2014-11-21 17:00:07 +010024#include <linux/memblock.h>
Thomas Petazzoni87e1bed2013-03-21 17:59:15 +010025#include <linux/mbus.h>
Linus Torvaldsff050ad2014-04-05 14:19:54 -070026#include <linux/signal.h>
Gregory CLEMENT85e618a2014-01-07 16:26:01 +010027#include <linux/slab.h>
Thomas Petazzoni01178892014-06-12 17:09:32 +020028#include <linux/irqchip.h>
Thomas Petazzonie33369c2013-04-09 23:26:14 +020029#include <asm/hardware/cache-l2x0.h>
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020030#include <asm/mach/arch.h>
31#include <asm/mach/map.h>
32#include <asm/mach/time.h>
Thomas Petazzoni8e6ac202014-04-14 15:47:03 +020033#include <asm/smp_scu.h>
Rob Herring6eb5be32012-09-02 14:57:33 -050034#include "armada-370-xp.h"
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020035#include "common.h"
Gregory CLEMENT45f59842012-11-14 22:51:08 +010036#include "coherency.h"
Gregory CLEMENT85e618a2014-01-07 16:26:01 +010037#include "mvebu-soc-id.h"
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020038
Gregory CLEMENT6a2b5342014-07-23 15:00:46 +020039static void __iomem *scu_base;
40
Thomas Petazzonica4a6f82014-02-17 15:23:24 +010041/*
Thomas Petazzoni8e6ac202014-04-14 15:47:03 +020042 * Enables the SCU when available. Obviously, this is only useful on
43 * Cortex-A based SOCs, not on PJ4B based ones.
44 */
45static void __init mvebu_scu_enable(void)
46{
Thomas Petazzoni8e6ac202014-04-14 15:47:03 +020047 struct device_node *np =
48 of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
49 if (np) {
50 scu_base = of_iomap(np, 0);
51 scu_enable(scu_base);
52 of_node_put(np);
53 }
54}
55
Gregory CLEMENT6a2b5342014-07-23 15:00:46 +020056void __iomem *mvebu_get_scu_base(void)
57{
58 return scu_base;
59}
60
Thomas Petazzoni8e6ac202014-04-14 15:47:03 +020061/*
Thomas Petazzoni8da2b2f2014-11-21 17:00:07 +010062 * When returning from suspend, the platform goes through the
63 * bootloader, which executes its DDR3 training code. This code has
64 * the unfortunate idea of using the first 10 KB of each DRAM bank to
65 * exercise the RAM and calculate the optimal timings. Therefore, this
66 * area of RAM is overwritten, and shouldn't be used by the kernel if
67 * suspend/resume is supported.
68 */
69
70#ifdef CONFIG_SUSPEND
71#define MVEBU_DDR_TRAINING_AREA_SZ (10 * SZ_1K)
72static int __init mvebu_scan_mem(unsigned long node, const char *uname,
73 int depth, void *data)
74{
75 const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
76 const __be32 *reg, *endp;
77 int l;
78
79 if (type == NULL || strcmp(type, "memory"))
80 return 0;
81
82 reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
83 if (reg == NULL)
84 reg = of_get_flat_dt_prop(node, "reg", &l);
85 if (reg == NULL)
86 return 0;
87
88 endp = reg + (l / sizeof(__be32));
89 while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
90 u64 base, size;
91
92 base = dt_mem_next_cell(dt_root_addr_cells, &reg);
93 size = dt_mem_next_cell(dt_root_size_cells, &reg);
94
95 memblock_reserve(base, MVEBU_DDR_TRAINING_AREA_SZ);
96 }
97
98 return 0;
99}
100
101static void __init mvebu_memblock_reserve(void)
102{
103 of_scan_flat_dt(mvebu_scan_mem, NULL);
104}
105#else
106static void __init mvebu_memblock_reserve(void) {}
107#endif
108
109/*
Thomas Petazzonica4a6f82014-02-17 15:23:24 +0100110 * Early versions of Armada 375 SoC have a bug where the BootROM
111 * leaves an external data abort pending. The kernel is hit by this
112 * data abort as soon as it enters userspace, because it unmasks the
113 * data aborts at this moment. We register a custom abort handler
114 * below to ignore the first data abort to work around this
115 * problem.
116 */
117static int armada_375_external_abort_wa(unsigned long addr, unsigned int fsr,
118 struct pt_regs *regs)
119{
120 static int ignore_first;
121
122 if (!ignore_first && fsr == 0x1406) {
123 ignore_first = 1;
124 return 0;
125 }
126
127 return 1;
128}
129
Thomas Petazzoni01178892014-06-12 17:09:32 +0200130static void __init mvebu_init_irq(void)
Thomas Petazzonid834d262013-06-05 09:04:59 +0200131{
Thomas Petazzoni01178892014-06-12 17:09:32 +0200132 irqchip_init();
Thomas Petazzoni8e6ac202014-04-14 15:47:03 +0200133 mvebu_scu_enable();
Thomas Petazzonid834d262013-06-05 09:04:59 +0200134 coherency_init();
Thomas Petazzoni5686a1e2014-04-14 15:47:01 +0200135 BUG_ON(mvebu_mbus_dt_init(coherency_available()));
Thomas Petazzoni752ef802014-06-12 17:09:31 +0200136}
Thomas Petazzonica4a6f82014-02-17 15:23:24 +0100137
Thomas Petazzoni752ef802014-06-12 17:09:31 +0200138static void __init external_abort_quirk(void)
139{
140 u32 dev, rev;
141
142 if (mvebu_get_soc_id(&dev, &rev) == 0 && rev > ARMADA_375_Z1_REV)
143 return;
144
145 hook_fault_code(16 + 6, armada_375_external_abort_wa, SIGBUS, 0,
146 "imprecise external abort");
Gregory CLEMENT53d2f882012-10-26 14:30:46 +0200147}
148
Gregory CLEMENT85e618a2014-01-07 16:26:01 +0100149static void __init i2c_quirk(void)
150{
151 struct device_node *np;
152 u32 dev, rev;
153
154 /*
155 * Only revisons more recent than A0 support the offload
156 * mechanism. We can exit only if we are sure that we can
157 * get the SoC revision and it is more recent than A0.
158 */
Gregory CLEMENT8eee0f82014-04-19 18:32:50 +0200159 if (mvebu_get_soc_id(&dev, &rev) == 0 && rev > MV78XX0_A0_REV)
Gregory CLEMENT85e618a2014-01-07 16:26:01 +0100160 return;
161
162 for_each_compatible_node(np, NULL, "marvell,mv78230-i2c") {
163 struct property *new_compat;
164
165 new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
166
167 new_compat->name = kstrdup("compatible", GFP_KERNEL);
168 new_compat->length = sizeof("marvell,mv78230-a0-i2c");
169 new_compat->value = kstrdup("marvell,mv78230-a0-i2c",
170 GFP_KERNEL);
171
172 of_update_property(np, new_compat);
173 }
174 return;
175}
176
Thomas Petazzoni99b3d292014-02-17 15:23:19 +0100177static void __init mvebu_dt_init(void)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200178{
Andrew Lunn5129ee22014-07-26 19:20:37 +0200179 if (of_machine_is_compatible("marvell,armadaxp"))
Gregory CLEMENT85e618a2014-01-07 16:26:01 +0100180 i2c_quirk();
Ezequiel Garcia172ed822014-11-04 13:00:39 -0300181 if (of_machine_is_compatible("marvell,a375-db"))
Thomas Petazzoni752ef802014-06-12 17:09:31 +0200182 external_abort_quirk();
Ezequiel Garcia5fd62062014-04-24 17:23:22 -0300183
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200184 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
185}
186
Thomas Petazzoni61505e12012-11-09 16:26:26 +0100187static const char * const armada_370_xp_dt_compat[] = {
188 "marvell,armada-370-xp",
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200189 NULL,
190};
191
Thomas Petazzonia017dbb2014-02-17 15:23:20 +0100192DT_MACHINE_START(ARMADA_370_XP_DT, "Marvell Armada 370/XP (Device Tree)")
Russell King9847cf02014-04-28 15:44:47 +0100193 .l2c_aux_val = 0,
194 .l2c_aux_mask = ~0,
Gregory CLEMENT316fbbc2014-10-30 12:39:41 +0100195/*
196 * The following field (.smp) is still needed to ensure backward
197 * compatibility with old Device Trees that were not specifying the
198 * cpus enable-method property.
199 */
Gregory CLEMENT45f59842012-11-14 22:51:08 +0100200 .smp = smp_ops(armada_xp_smp_ops),
Thomas Petazzoni99b3d292014-02-17 15:23:19 +0100201 .init_machine = mvebu_dt_init,
Thomas Petazzoni01178892014-06-12 17:09:32 +0200202 .init_irq = mvebu_init_irq,
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200203 .restart = mvebu_restart,
Thomas Petazzoni8da2b2f2014-11-21 17:00:07 +0100204 .reserve = mvebu_memblock_reserve,
Thomas Petazzoni61505e12012-11-09 16:26:26 +0100205 .dt_compat = armada_370_xp_dt_compat,
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200206MACHINE_END
Gregory CLEMENTd3ce7f22014-02-17 15:23:23 +0100207
208static const char * const armada_375_dt_compat[] = {
209 "marvell,armada375",
210 NULL,
211};
212
213DT_MACHINE_START(ARMADA_375_DT, "Marvell Armada 375 (Device Tree)")
Russell King9847cf02014-04-28 15:44:47 +0100214 .l2c_aux_val = 0,
215 .l2c_aux_mask = ~0,
Thomas Petazzoni01178892014-06-12 17:09:32 +0200216 .init_irq = mvebu_init_irq,
Ezequiel Garcia5fd62062014-04-24 17:23:22 -0300217 .init_machine = mvebu_dt_init,
Gregory CLEMENTd3ce7f22014-02-17 15:23:23 +0100218 .restart = mvebu_restart,
219 .dt_compat = armada_375_dt_compat,
220MACHINE_END
Thomas Petazzoni9aa30f12014-02-17 15:23:27 +0100221
222static const char * const armada_38x_dt_compat[] = {
223 "marvell,armada380",
224 "marvell,armada385",
225 NULL,
226};
227
228DT_MACHINE_START(ARMADA_38X_DT, "Marvell Armada 380/385 (Device Tree)")
Russell King9847cf02014-04-28 15:44:47 +0100229 .l2c_aux_val = 0,
230 .l2c_aux_mask = ~0,
Thomas Petazzoni01178892014-06-12 17:09:32 +0200231 .init_irq = mvebu_init_irq,
Thomas Petazzoni9aa30f12014-02-17 15:23:27 +0100232 .restart = mvebu_restart,
233 .dt_compat = armada_38x_dt_compat,
234MACHINE_END