Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 1 | /* |
| 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> |
Thomas Petazzoni | d834d26 | 2013-06-05 09:04:59 +0200 | [diff] [blame] | 17 | #include <linux/of_address.h> |
Thomas Petazzoni | 8da2b2f | 2014-11-21 17:00:07 +0100 | [diff] [blame] | 18 | #include <linux/of_fdt.h> |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 19 | #include <linux/of_platform.h> |
| 20 | #include <linux/io.h> |
Ezequiel Garcia | 573145f | 2013-08-13 11:43:12 -0300 | [diff] [blame] | 21 | #include <linux/clocksource.h> |
Gregory CLEMENT | 53d2f88 | 2012-10-26 14:30:46 +0200 | [diff] [blame] | 22 | #include <linux/dma-mapping.h> |
Thomas Petazzoni | 8da2b2f | 2014-11-21 17:00:07 +0100 | [diff] [blame] | 23 | #include <linux/memblock.h> |
Thomas Petazzoni | 87e1bed | 2013-03-21 17:59:15 +0100 | [diff] [blame] | 24 | #include <linux/mbus.h> |
Linus Torvalds | ff050ad | 2014-04-05 14:19:54 -0700 | [diff] [blame] | 25 | #include <linux/signal.h> |
Gregory CLEMENT | 85e618a | 2014-01-07 16:26:01 +0100 | [diff] [blame] | 26 | #include <linux/slab.h> |
Thomas Petazzoni | 0117889 | 2014-06-12 17:09:32 +0200 | [diff] [blame] | 27 | #include <linux/irqchip.h> |
Thomas Petazzoni | e33369c | 2013-04-09 23:26:14 +0200 | [diff] [blame] | 28 | #include <asm/hardware/cache-l2x0.h> |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 29 | #include <asm/mach/arch.h> |
| 30 | #include <asm/mach/map.h> |
| 31 | #include <asm/mach/time.h> |
Thomas Petazzoni | 8e6ac20 | 2014-04-14 15:47:03 +0200 | [diff] [blame] | 32 | #include <asm/smp_scu.h> |
Rob Herring | 6eb5be3 | 2012-09-02 14:57:33 -0500 | [diff] [blame] | 33 | #include "armada-370-xp.h" |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 34 | #include "common.h" |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 35 | #include "coherency.h" |
Gregory CLEMENT | 85e618a | 2014-01-07 16:26:01 +0100 | [diff] [blame] | 36 | #include "mvebu-soc-id.h" |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 37 | |
Gregory CLEMENT | 6a2b534 | 2014-07-23 15:00:46 +0200 | [diff] [blame] | 38 | static void __iomem *scu_base; |
| 39 | |
Thomas Petazzoni | ca4a6f8 | 2014-02-17 15:23:24 +0100 | [diff] [blame] | 40 | /* |
Thomas Petazzoni | 8e6ac20 | 2014-04-14 15:47:03 +0200 | [diff] [blame] | 41 | * Enables the SCU when available. Obviously, this is only useful on |
| 42 | * Cortex-A based SOCs, not on PJ4B based ones. |
| 43 | */ |
| 44 | static void __init mvebu_scu_enable(void) |
| 45 | { |
Thomas Petazzoni | 8e6ac20 | 2014-04-14 15:47:03 +0200 | [diff] [blame] | 46 | struct device_node *np = |
| 47 | of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu"); |
| 48 | if (np) { |
| 49 | scu_base = of_iomap(np, 0); |
| 50 | scu_enable(scu_base); |
| 51 | of_node_put(np); |
| 52 | } |
| 53 | } |
| 54 | |
Gregory CLEMENT | 6a2b534 | 2014-07-23 15:00:46 +0200 | [diff] [blame] | 55 | void __iomem *mvebu_get_scu_base(void) |
| 56 | { |
| 57 | return scu_base; |
| 58 | } |
| 59 | |
Thomas Petazzoni | 8e6ac20 | 2014-04-14 15:47:03 +0200 | [diff] [blame] | 60 | /* |
Thomas Petazzoni | 8da2b2f | 2014-11-21 17:00:07 +0100 | [diff] [blame] | 61 | * When returning from suspend, the platform goes through the |
| 62 | * bootloader, which executes its DDR3 training code. This code has |
| 63 | * the unfortunate idea of using the first 10 KB of each DRAM bank to |
| 64 | * exercise the RAM and calculate the optimal timings. Therefore, this |
| 65 | * area of RAM is overwritten, and shouldn't be used by the kernel if |
| 66 | * suspend/resume is supported. |
| 67 | */ |
| 68 | |
| 69 | #ifdef CONFIG_SUSPEND |
| 70 | #define MVEBU_DDR_TRAINING_AREA_SZ (10 * SZ_1K) |
| 71 | static int __init mvebu_scan_mem(unsigned long node, const char *uname, |
| 72 | int depth, void *data) |
| 73 | { |
| 74 | const char *type = of_get_flat_dt_prop(node, "device_type", NULL); |
| 75 | const __be32 *reg, *endp; |
| 76 | int l; |
| 77 | |
| 78 | if (type == NULL || strcmp(type, "memory")) |
| 79 | return 0; |
| 80 | |
| 81 | reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); |
| 82 | if (reg == NULL) |
| 83 | reg = of_get_flat_dt_prop(node, "reg", &l); |
| 84 | if (reg == NULL) |
| 85 | return 0; |
| 86 | |
| 87 | endp = reg + (l / sizeof(__be32)); |
| 88 | while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { |
| 89 | u64 base, size; |
| 90 | |
| 91 | base = dt_mem_next_cell(dt_root_addr_cells, ®); |
| 92 | size = dt_mem_next_cell(dt_root_size_cells, ®); |
| 93 | |
| 94 | memblock_reserve(base, MVEBU_DDR_TRAINING_AREA_SZ); |
| 95 | } |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static void __init mvebu_memblock_reserve(void) |
| 101 | { |
| 102 | of_scan_flat_dt(mvebu_scan_mem, NULL); |
| 103 | } |
| 104 | #else |
| 105 | static void __init mvebu_memblock_reserve(void) {} |
| 106 | #endif |
| 107 | |
| 108 | /* |
Thomas Petazzoni | ca4a6f8 | 2014-02-17 15:23:24 +0100 | [diff] [blame] | 109 | * Early versions of Armada 375 SoC have a bug where the BootROM |
| 110 | * leaves an external data abort pending. The kernel is hit by this |
| 111 | * data abort as soon as it enters userspace, because it unmasks the |
| 112 | * data aborts at this moment. We register a custom abort handler |
| 113 | * below to ignore the first data abort to work around this |
| 114 | * problem. |
| 115 | */ |
| 116 | static int armada_375_external_abort_wa(unsigned long addr, unsigned int fsr, |
| 117 | struct pt_regs *regs) |
| 118 | { |
| 119 | static int ignore_first; |
| 120 | |
| 121 | if (!ignore_first && fsr == 0x1406) { |
| 122 | ignore_first = 1; |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | return 1; |
| 127 | } |
| 128 | |
Thomas Petazzoni | 0117889 | 2014-06-12 17:09:32 +0200 | [diff] [blame] | 129 | static void __init mvebu_init_irq(void) |
Thomas Petazzoni | d834d26 | 2013-06-05 09:04:59 +0200 | [diff] [blame] | 130 | { |
Thomas Petazzoni | 0117889 | 2014-06-12 17:09:32 +0200 | [diff] [blame] | 131 | irqchip_init(); |
Thomas Petazzoni | 8e6ac20 | 2014-04-14 15:47:03 +0200 | [diff] [blame] | 132 | mvebu_scu_enable(); |
Thomas Petazzoni | d834d26 | 2013-06-05 09:04:59 +0200 | [diff] [blame] | 133 | coherency_init(); |
Thomas Petazzoni | 5686a1e | 2014-04-14 15:47:01 +0200 | [diff] [blame] | 134 | BUG_ON(mvebu_mbus_dt_init(coherency_available())); |
Thomas Petazzoni | 752ef80 | 2014-06-12 17:09:31 +0200 | [diff] [blame] | 135 | } |
Thomas Petazzoni | ca4a6f8 | 2014-02-17 15:23:24 +0100 | [diff] [blame] | 136 | |
Thomas Petazzoni | 752ef80 | 2014-06-12 17:09:31 +0200 | [diff] [blame] | 137 | static void __init external_abort_quirk(void) |
| 138 | { |
| 139 | u32 dev, rev; |
| 140 | |
| 141 | if (mvebu_get_soc_id(&dev, &rev) == 0 && rev > ARMADA_375_Z1_REV) |
| 142 | return; |
| 143 | |
| 144 | hook_fault_code(16 + 6, armada_375_external_abort_wa, SIGBUS, 0, |
| 145 | "imprecise external abort"); |
Gregory CLEMENT | 53d2f88 | 2012-10-26 14:30:46 +0200 | [diff] [blame] | 146 | } |
| 147 | |
Gregory CLEMENT | 85e618a | 2014-01-07 16:26:01 +0100 | [diff] [blame] | 148 | static void __init i2c_quirk(void) |
| 149 | { |
| 150 | struct device_node *np; |
| 151 | u32 dev, rev; |
| 152 | |
| 153 | /* |
| 154 | * Only revisons more recent than A0 support the offload |
| 155 | * mechanism. We can exit only if we are sure that we can |
| 156 | * get the SoC revision and it is more recent than A0. |
| 157 | */ |
Gregory CLEMENT | 8eee0f8 | 2014-04-19 18:32:50 +0200 | [diff] [blame] | 158 | if (mvebu_get_soc_id(&dev, &rev) == 0 && rev > MV78XX0_A0_REV) |
Gregory CLEMENT | 85e618a | 2014-01-07 16:26:01 +0100 | [diff] [blame] | 159 | return; |
| 160 | |
| 161 | for_each_compatible_node(np, NULL, "marvell,mv78230-i2c") { |
| 162 | struct property *new_compat; |
| 163 | |
| 164 | new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL); |
| 165 | |
| 166 | new_compat->name = kstrdup("compatible", GFP_KERNEL); |
| 167 | new_compat->length = sizeof("marvell,mv78230-a0-i2c"); |
| 168 | new_compat->value = kstrdup("marvell,mv78230-a0-i2c", |
| 169 | GFP_KERNEL); |
| 170 | |
| 171 | of_update_property(np, new_compat); |
| 172 | } |
| 173 | return; |
| 174 | } |
| 175 | |
Thomas Petazzoni | 99b3d29 | 2014-02-17 15:23:19 +0100 | [diff] [blame] | 176 | static void __init mvebu_dt_init(void) |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 177 | { |
Andrew Lunn | 5129ee2 | 2014-07-26 19:20:37 +0200 | [diff] [blame] | 178 | if (of_machine_is_compatible("marvell,armadaxp")) |
Gregory CLEMENT | 85e618a | 2014-01-07 16:26:01 +0100 | [diff] [blame] | 179 | i2c_quirk(); |
Ezequiel Garcia | 172ed82 | 2014-11-04 13:00:39 -0300 | [diff] [blame] | 180 | if (of_machine_is_compatible("marvell,a375-db")) |
Thomas Petazzoni | 752ef80 | 2014-06-12 17:09:31 +0200 | [diff] [blame] | 181 | external_abort_quirk(); |
Ezequiel Garcia | 5fd6206 | 2014-04-24 17:23:22 -0300 | [diff] [blame] | 182 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 183 | of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); |
| 184 | } |
| 185 | |
Thomas Petazzoni | bc2d7a5 | 2015-03-03 15:40:56 +0100 | [diff] [blame] | 186 | static const char * const armada_370_xp_dt_compat[] __initconst = { |
Thomas Petazzoni | 61505e1 | 2012-11-09 16:26:26 +0100 | [diff] [blame] | 187 | "marvell,armada-370-xp", |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 188 | NULL, |
| 189 | }; |
| 190 | |
Thomas Petazzoni | a017dbb | 2014-02-17 15:23:20 +0100 | [diff] [blame] | 191 | DT_MACHINE_START(ARMADA_370_XP_DT, "Marvell Armada 370/XP (Device Tree)") |
Russell King | 9847cf0 | 2014-04-28 15:44:47 +0100 | [diff] [blame] | 192 | .l2c_aux_val = 0, |
| 193 | .l2c_aux_mask = ~0, |
Gregory CLEMENT | 316fbbc | 2014-10-30 12:39:41 +0100 | [diff] [blame] | 194 | /* |
| 195 | * The following field (.smp) is still needed to ensure backward |
| 196 | * compatibility with old Device Trees that were not specifying the |
| 197 | * cpus enable-method property. |
| 198 | */ |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 199 | .smp = smp_ops(armada_xp_smp_ops), |
Thomas Petazzoni | 99b3d29 | 2014-02-17 15:23:19 +0100 | [diff] [blame] | 200 | .init_machine = mvebu_dt_init, |
Thomas Petazzoni | 0117889 | 2014-06-12 17:09:32 +0200 | [diff] [blame] | 201 | .init_irq = mvebu_init_irq, |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 202 | .restart = mvebu_restart, |
Thomas Petazzoni | 8da2b2f | 2014-11-21 17:00:07 +0100 | [diff] [blame] | 203 | .reserve = mvebu_memblock_reserve, |
Thomas Petazzoni | 61505e1 | 2012-11-09 16:26:26 +0100 | [diff] [blame] | 204 | .dt_compat = armada_370_xp_dt_compat, |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 205 | MACHINE_END |
Gregory CLEMENT | d3ce7f2 | 2014-02-17 15:23:23 +0100 | [diff] [blame] | 206 | |
Thomas Petazzoni | bc2d7a5 | 2015-03-03 15:40:56 +0100 | [diff] [blame] | 207 | static const char * const armada_375_dt_compat[] __initconst = { |
Gregory CLEMENT | d3ce7f2 | 2014-02-17 15:23:23 +0100 | [diff] [blame] | 208 | "marvell,armada375", |
| 209 | NULL, |
| 210 | }; |
| 211 | |
| 212 | DT_MACHINE_START(ARMADA_375_DT, "Marvell Armada 375 (Device Tree)") |
Russell King | 9847cf0 | 2014-04-28 15:44:47 +0100 | [diff] [blame] | 213 | .l2c_aux_val = 0, |
| 214 | .l2c_aux_mask = ~0, |
Thomas Petazzoni | 0117889 | 2014-06-12 17:09:32 +0200 | [diff] [blame] | 215 | .init_irq = mvebu_init_irq, |
Ezequiel Garcia | 5fd6206 | 2014-04-24 17:23:22 -0300 | [diff] [blame] | 216 | .init_machine = mvebu_dt_init, |
Gregory CLEMENT | d3ce7f2 | 2014-02-17 15:23:23 +0100 | [diff] [blame] | 217 | .restart = mvebu_restart, |
| 218 | .dt_compat = armada_375_dt_compat, |
| 219 | MACHINE_END |
Thomas Petazzoni | 9aa30f1 | 2014-02-17 15:23:27 +0100 | [diff] [blame] | 220 | |
Thomas Petazzoni | bc2d7a5 | 2015-03-03 15:40:56 +0100 | [diff] [blame] | 221 | static const char * const armada_38x_dt_compat[] __initconst = { |
Thomas Petazzoni | 9aa30f1 | 2014-02-17 15:23:27 +0100 | [diff] [blame] | 222 | "marvell,armada380", |
| 223 | "marvell,armada385", |
| 224 | NULL, |
| 225 | }; |
| 226 | |
| 227 | DT_MACHINE_START(ARMADA_38X_DT, "Marvell Armada 380/385 (Device Tree)") |
Russell King | 9847cf0 | 2014-04-28 15:44:47 +0100 | [diff] [blame] | 228 | .l2c_aux_val = 0, |
| 229 | .l2c_aux_mask = ~0, |
Thomas Petazzoni | 0117889 | 2014-06-12 17:09:32 +0200 | [diff] [blame] | 230 | .init_irq = mvebu_init_irq, |
Thomas Petazzoni | 9aa30f1 | 2014-02-17 15:23:27 +0100 | [diff] [blame] | 231 | .restart = mvebu_restart, |
| 232 | .dt_compat = armada_38x_dt_compat, |
| 233 | MACHINE_END |
Thomas Petazzoni | 242ede0 | 2015-03-03 15:41:11 +0100 | [diff] [blame] | 234 | |
| 235 | static const char * const armada_39x_dt_compat[] __initconst = { |
| 236 | "marvell,armada390", |
| 237 | "marvell,armada398", |
| 238 | NULL, |
| 239 | }; |
| 240 | |
| 241 | DT_MACHINE_START(ARMADA_39X_DT, "Marvell Armada 39x (Device Tree)") |
| 242 | .l2c_aux_val = 0, |
| 243 | .l2c_aux_mask = ~0, |
| 244 | .init_irq = mvebu_init_irq, |
| 245 | .restart = mvebu_restart, |
| 246 | .dt_compat = armada_39x_dt_compat, |
| 247 | MACHINE_END |