xref: /openbmc/linux/arch/arm/mach-mvebu/board-v7.c (revision bc2d7a58b9a48e4c1f35fadb30223ca87c59d50f)
199b3d294SThomas Petazzoni /*
299b3d294SThomas Petazzoni  * Device Tree support for Armada 370 and XP platforms.
399b3d294SThomas Petazzoni  *
499b3d294SThomas Petazzoni  * Copyright (C) 2012 Marvell
599b3d294SThomas Petazzoni  *
699b3d294SThomas Petazzoni  * Lior Amsalem <alior@marvell.com>
799b3d294SThomas Petazzoni  * Gregory CLEMENT <gregory.clement@free-electrons.com>
899b3d294SThomas Petazzoni  * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
999b3d294SThomas Petazzoni  *
1099b3d294SThomas Petazzoni  * This file is licensed under the terms of the GNU General Public
1199b3d294SThomas Petazzoni  * License version 2.  This program is licensed "as is" without any
1299b3d294SThomas Petazzoni  * warranty of any kind, whether express or implied.
1399b3d294SThomas Petazzoni  */
1499b3d294SThomas Petazzoni 
1599b3d294SThomas Petazzoni #include <linux/kernel.h>
1699b3d294SThomas Petazzoni #include <linux/init.h>
1799b3d294SThomas Petazzoni #include <linux/clk-provider.h>
1899b3d294SThomas Petazzoni #include <linux/of_address.h>
198da2b2f7SThomas Petazzoni #include <linux/of_fdt.h>
2099b3d294SThomas Petazzoni #include <linux/of_platform.h>
2199b3d294SThomas Petazzoni #include <linux/io.h>
2299b3d294SThomas Petazzoni #include <linux/clocksource.h>
2399b3d294SThomas Petazzoni #include <linux/dma-mapping.h>
248da2b2f7SThomas Petazzoni #include <linux/memblock.h>
2599b3d294SThomas Petazzoni #include <linux/mbus.h>
26ff050ad1SLinus Torvalds #include <linux/signal.h>
2799b3d294SThomas Petazzoni #include <linux/slab.h>
2801178890SThomas Petazzoni #include <linux/irqchip.h>
2999b3d294SThomas Petazzoni #include <asm/hardware/cache-l2x0.h>
3099b3d294SThomas Petazzoni #include <asm/mach/arch.h>
3199b3d294SThomas Petazzoni #include <asm/mach/map.h>
3299b3d294SThomas Petazzoni #include <asm/mach/time.h>
338e6ac203SThomas Petazzoni #include <asm/smp_scu.h>
3499b3d294SThomas Petazzoni #include "armada-370-xp.h"
3599b3d294SThomas Petazzoni #include "common.h"
3699b3d294SThomas Petazzoni #include "coherency.h"
3799b3d294SThomas Petazzoni #include "mvebu-soc-id.h"
3899b3d294SThomas Petazzoni 
396a2b5343SGregory CLEMENT static void __iomem *scu_base;
406a2b5343SGregory CLEMENT 
41ca4a6f87SThomas Petazzoni /*
428e6ac203SThomas Petazzoni  * Enables the SCU when available. Obviously, this is only useful on
438e6ac203SThomas Petazzoni  * Cortex-A based SOCs, not on PJ4B based ones.
448e6ac203SThomas Petazzoni  */
458e6ac203SThomas Petazzoni static void __init mvebu_scu_enable(void)
468e6ac203SThomas Petazzoni {
478e6ac203SThomas Petazzoni 	struct device_node *np =
488e6ac203SThomas Petazzoni 		of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
498e6ac203SThomas Petazzoni 	if (np) {
508e6ac203SThomas Petazzoni 		scu_base = of_iomap(np, 0);
518e6ac203SThomas Petazzoni 		scu_enable(scu_base);
528e6ac203SThomas Petazzoni 		of_node_put(np);
538e6ac203SThomas Petazzoni 	}
548e6ac203SThomas Petazzoni }
558e6ac203SThomas Petazzoni 
566a2b5343SGregory CLEMENT void __iomem *mvebu_get_scu_base(void)
576a2b5343SGregory CLEMENT {
586a2b5343SGregory CLEMENT 	return scu_base;
596a2b5343SGregory CLEMENT }
606a2b5343SGregory CLEMENT 
618e6ac203SThomas Petazzoni /*
628da2b2f7SThomas Petazzoni  * When returning from suspend, the platform goes through the
638da2b2f7SThomas Petazzoni  * bootloader, which executes its DDR3 training code. This code has
648da2b2f7SThomas Petazzoni  * the unfortunate idea of using the first 10 KB of each DRAM bank to
658da2b2f7SThomas Petazzoni  * exercise the RAM and calculate the optimal timings. Therefore, this
668da2b2f7SThomas Petazzoni  * area of RAM is overwritten, and shouldn't be used by the kernel if
678da2b2f7SThomas Petazzoni  * suspend/resume is supported.
688da2b2f7SThomas Petazzoni  */
698da2b2f7SThomas Petazzoni 
708da2b2f7SThomas Petazzoni #ifdef CONFIG_SUSPEND
718da2b2f7SThomas Petazzoni #define MVEBU_DDR_TRAINING_AREA_SZ (10 * SZ_1K)
728da2b2f7SThomas Petazzoni static int __init mvebu_scan_mem(unsigned long node, const char *uname,
738da2b2f7SThomas Petazzoni 				 int depth, void *data)
748da2b2f7SThomas Petazzoni {
758da2b2f7SThomas Petazzoni 	const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
768da2b2f7SThomas Petazzoni 	const __be32 *reg, *endp;
778da2b2f7SThomas Petazzoni 	int l;
788da2b2f7SThomas Petazzoni 
798da2b2f7SThomas Petazzoni 	if (type == NULL || strcmp(type, "memory"))
808da2b2f7SThomas Petazzoni 		return 0;
818da2b2f7SThomas Petazzoni 
828da2b2f7SThomas Petazzoni 	reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
838da2b2f7SThomas Petazzoni 	if (reg == NULL)
848da2b2f7SThomas Petazzoni 		reg = of_get_flat_dt_prop(node, "reg", &l);
858da2b2f7SThomas Petazzoni 	if (reg == NULL)
868da2b2f7SThomas Petazzoni 		return 0;
878da2b2f7SThomas Petazzoni 
888da2b2f7SThomas Petazzoni 	endp = reg + (l / sizeof(__be32));
898da2b2f7SThomas Petazzoni 	while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
908da2b2f7SThomas Petazzoni 		u64 base, size;
918da2b2f7SThomas Petazzoni 
928da2b2f7SThomas Petazzoni 		base = dt_mem_next_cell(dt_root_addr_cells, &reg);
938da2b2f7SThomas Petazzoni 		size = dt_mem_next_cell(dt_root_size_cells, &reg);
948da2b2f7SThomas Petazzoni 
958da2b2f7SThomas Petazzoni 		memblock_reserve(base, MVEBU_DDR_TRAINING_AREA_SZ);
968da2b2f7SThomas Petazzoni 	}
978da2b2f7SThomas Petazzoni 
988da2b2f7SThomas Petazzoni 	return 0;
998da2b2f7SThomas Petazzoni }
1008da2b2f7SThomas Petazzoni 
1018da2b2f7SThomas Petazzoni static void __init mvebu_memblock_reserve(void)
1028da2b2f7SThomas Petazzoni {
1038da2b2f7SThomas Petazzoni 	of_scan_flat_dt(mvebu_scan_mem, NULL);
1048da2b2f7SThomas Petazzoni }
1058da2b2f7SThomas Petazzoni #else
1068da2b2f7SThomas Petazzoni static void __init mvebu_memblock_reserve(void) {}
1078da2b2f7SThomas Petazzoni #endif
1088da2b2f7SThomas Petazzoni 
1098da2b2f7SThomas Petazzoni /*
110ca4a6f87SThomas Petazzoni  * Early versions of Armada 375 SoC have a bug where the BootROM
111ca4a6f87SThomas Petazzoni  * leaves an external data abort pending. The kernel is hit by this
112ca4a6f87SThomas Petazzoni  * data abort as soon as it enters userspace, because it unmasks the
113ca4a6f87SThomas Petazzoni  * data aborts at this moment. We register a custom abort handler
114ca4a6f87SThomas Petazzoni  * below to ignore the first data abort to work around this
115ca4a6f87SThomas Petazzoni  * problem.
116ca4a6f87SThomas Petazzoni  */
117ca4a6f87SThomas Petazzoni static int armada_375_external_abort_wa(unsigned long addr, unsigned int fsr,
118ca4a6f87SThomas Petazzoni 					struct pt_regs *regs)
119ca4a6f87SThomas Petazzoni {
120ca4a6f87SThomas Petazzoni 	static int ignore_first;
121ca4a6f87SThomas Petazzoni 
122ca4a6f87SThomas Petazzoni 	if (!ignore_first && fsr == 0x1406) {
123ca4a6f87SThomas Petazzoni 		ignore_first = 1;
124ca4a6f87SThomas Petazzoni 		return 0;
125ca4a6f87SThomas Petazzoni 	}
126ca4a6f87SThomas Petazzoni 
127ca4a6f87SThomas Petazzoni 	return 1;
128ca4a6f87SThomas Petazzoni }
129ca4a6f87SThomas Petazzoni 
13001178890SThomas Petazzoni static void __init mvebu_init_irq(void)
13199b3d294SThomas Petazzoni {
13201178890SThomas Petazzoni 	irqchip_init();
1338e6ac203SThomas Petazzoni 	mvebu_scu_enable();
13499b3d294SThomas Petazzoni 	coherency_init();
1355686a1e5SThomas Petazzoni 	BUG_ON(mvebu_mbus_dt_init(coherency_available()));
136752ef800SThomas Petazzoni }
137ca4a6f87SThomas Petazzoni 
138752ef800SThomas Petazzoni static void __init external_abort_quirk(void)
139752ef800SThomas Petazzoni {
140752ef800SThomas Petazzoni 	u32 dev, rev;
141752ef800SThomas Petazzoni 
142752ef800SThomas Petazzoni 	if (mvebu_get_soc_id(&dev, &rev) == 0 && rev > ARMADA_375_Z1_REV)
143752ef800SThomas Petazzoni 		return;
144752ef800SThomas Petazzoni 
145ca4a6f87SThomas Petazzoni 	hook_fault_code(16 + 6, armada_375_external_abort_wa, SIGBUS, 0,
146ca4a6f87SThomas Petazzoni 			"imprecise external abort");
14799b3d294SThomas Petazzoni }
14899b3d294SThomas Petazzoni 
14999b3d294SThomas Petazzoni static void __init i2c_quirk(void)
15099b3d294SThomas Petazzoni {
15199b3d294SThomas Petazzoni 	struct device_node *np;
15299b3d294SThomas Petazzoni 	u32 dev, rev;
15399b3d294SThomas Petazzoni 
15499b3d294SThomas Petazzoni 	/*
15599b3d294SThomas Petazzoni 	 * Only revisons more recent than A0 support the offload
15699b3d294SThomas Petazzoni 	 * mechanism. We can exit only if we are sure that we can
15799b3d294SThomas Petazzoni 	 * get the SoC revision and it is more recent than A0.
15899b3d294SThomas Petazzoni 	 */
1598eee0f81SGregory CLEMENT 	if (mvebu_get_soc_id(&dev, &rev) == 0 && rev > MV78XX0_A0_REV)
16099b3d294SThomas Petazzoni 		return;
16199b3d294SThomas Petazzoni 
16299b3d294SThomas Petazzoni 	for_each_compatible_node(np, NULL, "marvell,mv78230-i2c") {
16399b3d294SThomas Petazzoni 		struct property *new_compat;
16499b3d294SThomas Petazzoni 
16599b3d294SThomas Petazzoni 		new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
16699b3d294SThomas Petazzoni 
16799b3d294SThomas Petazzoni 		new_compat->name = kstrdup("compatible", GFP_KERNEL);
16899b3d294SThomas Petazzoni 		new_compat->length = sizeof("marvell,mv78230-a0-i2c");
16999b3d294SThomas Petazzoni 		new_compat->value = kstrdup("marvell,mv78230-a0-i2c",
17099b3d294SThomas Petazzoni 						GFP_KERNEL);
17199b3d294SThomas Petazzoni 
17299b3d294SThomas Petazzoni 		of_update_property(np, new_compat);
17399b3d294SThomas Petazzoni 	}
17499b3d294SThomas Petazzoni 	return;
17599b3d294SThomas Petazzoni }
17699b3d294SThomas Petazzoni 
17799b3d294SThomas Petazzoni static void __init mvebu_dt_init(void)
17899b3d294SThomas Petazzoni {
1795129ee22SAndrew Lunn 	if (of_machine_is_compatible("marvell,armadaxp"))
18099b3d294SThomas Petazzoni 		i2c_quirk();
181172ed82cSEzequiel Garcia 	if (of_machine_is_compatible("marvell,a375-db"))
182752ef800SThomas Petazzoni 		external_abort_quirk();
1835fd62066SEzequiel Garcia 
18499b3d294SThomas Petazzoni 	of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
18599b3d294SThomas Petazzoni }
18699b3d294SThomas Petazzoni 
187*bc2d7a58SThomas Petazzoni static const char * const armada_370_xp_dt_compat[] __initconst = {
18899b3d294SThomas Petazzoni 	"marvell,armada-370-xp",
18999b3d294SThomas Petazzoni 	NULL,
19099b3d294SThomas Petazzoni };
19199b3d294SThomas Petazzoni 
192a017dbb6SThomas Petazzoni DT_MACHINE_START(ARMADA_370_XP_DT, "Marvell Armada 370/XP (Device Tree)")
1939847cf04SRussell King 	.l2c_aux_val	= 0,
1949847cf04SRussell King 	.l2c_aux_mask	= ~0,
195316fbbc4SGregory CLEMENT /*
196316fbbc4SGregory CLEMENT  * The following field (.smp) is still needed to ensure backward
197316fbbc4SGregory CLEMENT  * compatibility with old Device Trees that were not specifying the
198316fbbc4SGregory CLEMENT  * cpus enable-method property.
199316fbbc4SGregory CLEMENT  */
20099b3d294SThomas Petazzoni 	.smp		= smp_ops(armada_xp_smp_ops),
20199b3d294SThomas Petazzoni 	.init_machine	= mvebu_dt_init,
20201178890SThomas Petazzoni 	.init_irq       = mvebu_init_irq,
20399b3d294SThomas Petazzoni 	.restart	= mvebu_restart,
2048da2b2f7SThomas Petazzoni 	.reserve        = mvebu_memblock_reserve,
20599b3d294SThomas Petazzoni 	.dt_compat	= armada_370_xp_dt_compat,
20699b3d294SThomas Petazzoni MACHINE_END
207d3ce7f25SGregory CLEMENT 
208*bc2d7a58SThomas Petazzoni static const char * const armada_375_dt_compat[] __initconst = {
209d3ce7f25SGregory CLEMENT 	"marvell,armada375",
210d3ce7f25SGregory CLEMENT 	NULL,
211d3ce7f25SGregory CLEMENT };
212d3ce7f25SGregory CLEMENT 
213d3ce7f25SGregory CLEMENT DT_MACHINE_START(ARMADA_375_DT, "Marvell Armada 375 (Device Tree)")
2149847cf04SRussell King 	.l2c_aux_val	= 0,
2159847cf04SRussell King 	.l2c_aux_mask	= ~0,
21601178890SThomas Petazzoni 	.init_irq       = mvebu_init_irq,
2175fd62066SEzequiel Garcia 	.init_machine	= mvebu_dt_init,
218d3ce7f25SGregory CLEMENT 	.restart	= mvebu_restart,
219d3ce7f25SGregory CLEMENT 	.dt_compat	= armada_375_dt_compat,
220d3ce7f25SGregory CLEMENT MACHINE_END
2219aa30f1cSThomas Petazzoni 
222*bc2d7a58SThomas Petazzoni static const char * const armada_38x_dt_compat[] __initconst = {
2239aa30f1cSThomas Petazzoni 	"marvell,armada380",
2249aa30f1cSThomas Petazzoni 	"marvell,armada385",
2259aa30f1cSThomas Petazzoni 	NULL,
2269aa30f1cSThomas Petazzoni };
2279aa30f1cSThomas Petazzoni 
2289aa30f1cSThomas Petazzoni DT_MACHINE_START(ARMADA_38X_DT, "Marvell Armada 380/385 (Device Tree)")
2299847cf04SRussell King 	.l2c_aux_val	= 0,
2309847cf04SRussell King 	.l2c_aux_mask	= ~0,
23101178890SThomas Petazzoni 	.init_irq       = mvebu_init_irq,
2329aa30f1cSThomas Petazzoni 	.restart	= mvebu_restart,
2339aa30f1cSThomas Petazzoni 	.dt_compat	= armada_38x_dt_compat,
2349aa30f1cSThomas Petazzoni MACHINE_END
235