xref: /openbmc/linux/arch/arm/mach-mvebu/board-v7.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1*0fdebc5eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
299b3d294SThomas Petazzoni /*
399b3d294SThomas Petazzoni  * Device Tree support for Armada 370 and XP platforms.
499b3d294SThomas Petazzoni  *
599b3d294SThomas Petazzoni  * Copyright (C) 2012 Marvell
699b3d294SThomas Petazzoni  *
799b3d294SThomas Petazzoni  * Lior Amsalem <alior@marvell.com>
899b3d294SThomas Petazzoni  * Gregory CLEMENT <gregory.clement@free-electrons.com>
999b3d294SThomas Petazzoni  * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
1099b3d294SThomas Petazzoni  */
1199b3d294SThomas Petazzoni 
1299b3d294SThomas Petazzoni #include <linux/kernel.h>
1399b3d294SThomas Petazzoni #include <linux/init.h>
1499b3d294SThomas Petazzoni #include <linux/of_address.h>
158da2b2f7SThomas Petazzoni #include <linux/of_fdt.h>
1699b3d294SThomas Petazzoni #include <linux/io.h>
1799b3d294SThomas Petazzoni #include <linux/clocksource.h>
1899b3d294SThomas Petazzoni #include <linux/dma-mapping.h>
198da2b2f7SThomas Petazzoni #include <linux/memblock.h>
2099b3d294SThomas Petazzoni #include <linux/mbus.h>
2199b3d294SThomas Petazzoni #include <linux/slab.h>
2201178890SThomas Petazzoni #include <linux/irqchip.h>
2399b3d294SThomas Petazzoni #include <asm/hardware/cache-l2x0.h>
2499b3d294SThomas Petazzoni #include <asm/mach/arch.h>
2599b3d294SThomas Petazzoni #include <asm/mach/map.h>
2699b3d294SThomas Petazzoni #include <asm/mach/time.h>
278e6ac203SThomas Petazzoni #include <asm/smp_scu.h>
2899b3d294SThomas Petazzoni #include "armada-370-xp.h"
2999b3d294SThomas Petazzoni #include "common.h"
3099b3d294SThomas Petazzoni #include "coherency.h"
3199b3d294SThomas Petazzoni #include "mvebu-soc-id.h"
3299b3d294SThomas Petazzoni 
336a2b5343SGregory CLEMENT static void __iomem *scu_base;
346a2b5343SGregory CLEMENT 
35ca4a6f87SThomas Petazzoni /*
368e6ac203SThomas Petazzoni  * Enables the SCU when available. Obviously, this is only useful on
378e6ac203SThomas Petazzoni  * Cortex-A based SOCs, not on PJ4B based ones.
388e6ac203SThomas Petazzoni  */
mvebu_scu_enable(void)398e6ac203SThomas Petazzoni static void __init mvebu_scu_enable(void)
408e6ac203SThomas Petazzoni {
418e6ac203SThomas Petazzoni 	struct device_node *np =
428e6ac203SThomas Petazzoni 		of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
438e6ac203SThomas Petazzoni 	if (np) {
448e6ac203SThomas Petazzoni 		scu_base = of_iomap(np, 0);
458e6ac203SThomas Petazzoni 		scu_enable(scu_base);
468e6ac203SThomas Petazzoni 		of_node_put(np);
478e6ac203SThomas Petazzoni 	}
488e6ac203SThomas Petazzoni }
498e6ac203SThomas Petazzoni 
mvebu_get_scu_base(void)506a2b5343SGregory CLEMENT void __iomem *mvebu_get_scu_base(void)
516a2b5343SGregory CLEMENT {
526a2b5343SGregory CLEMENT 	return scu_base;
536a2b5343SGregory CLEMENT }
546a2b5343SGregory CLEMENT 
558e6ac203SThomas Petazzoni /*
568da2b2f7SThomas Petazzoni  * When returning from suspend, the platform goes through the
578da2b2f7SThomas Petazzoni  * bootloader, which executes its DDR3 training code. This code has
588da2b2f7SThomas Petazzoni  * the unfortunate idea of using the first 10 KB of each DRAM bank to
598da2b2f7SThomas Petazzoni  * exercise the RAM and calculate the optimal timings. Therefore, this
608da2b2f7SThomas Petazzoni  * area of RAM is overwritten, and shouldn't be used by the kernel if
618da2b2f7SThomas Petazzoni  * suspend/resume is supported.
628da2b2f7SThomas Petazzoni  */
638da2b2f7SThomas Petazzoni 
648da2b2f7SThomas Petazzoni #ifdef CONFIG_SUSPEND
658da2b2f7SThomas Petazzoni #define MVEBU_DDR_TRAINING_AREA_SZ (10 * SZ_1K)
mvebu_scan_mem(unsigned long node,const char * uname,int depth,void * data)668da2b2f7SThomas Petazzoni static int __init mvebu_scan_mem(unsigned long node, const char *uname,
678da2b2f7SThomas Petazzoni 				 int depth, void *data)
688da2b2f7SThomas Petazzoni {
698da2b2f7SThomas Petazzoni 	const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
708da2b2f7SThomas Petazzoni 	const __be32 *reg, *endp;
718da2b2f7SThomas Petazzoni 	int l;
728da2b2f7SThomas Petazzoni 
738da2b2f7SThomas Petazzoni 	if (type == NULL || strcmp(type, "memory"))
748da2b2f7SThomas Petazzoni 		return 0;
758da2b2f7SThomas Petazzoni 
768da2b2f7SThomas Petazzoni 	reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
778da2b2f7SThomas Petazzoni 	if (reg == NULL)
788da2b2f7SThomas Petazzoni 		reg = of_get_flat_dt_prop(node, "reg", &l);
798da2b2f7SThomas Petazzoni 	if (reg == NULL)
808da2b2f7SThomas Petazzoni 		return 0;
818da2b2f7SThomas Petazzoni 
828da2b2f7SThomas Petazzoni 	endp = reg + (l / sizeof(__be32));
838da2b2f7SThomas Petazzoni 	while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
848da2b2f7SThomas Petazzoni 		u64 base, size;
858da2b2f7SThomas Petazzoni 
868da2b2f7SThomas Petazzoni 		base = dt_mem_next_cell(dt_root_addr_cells, &reg);
878da2b2f7SThomas Petazzoni 		size = dt_mem_next_cell(dt_root_size_cells, &reg);
888da2b2f7SThomas Petazzoni 
898da2b2f7SThomas Petazzoni 		memblock_reserve(base, MVEBU_DDR_TRAINING_AREA_SZ);
908da2b2f7SThomas Petazzoni 	}
918da2b2f7SThomas Petazzoni 
928da2b2f7SThomas Petazzoni 	return 0;
938da2b2f7SThomas Petazzoni }
948da2b2f7SThomas Petazzoni 
mvebu_memblock_reserve(void)958da2b2f7SThomas Petazzoni static void __init mvebu_memblock_reserve(void)
968da2b2f7SThomas Petazzoni {
978da2b2f7SThomas Petazzoni 	of_scan_flat_dt(mvebu_scan_mem, NULL);
988da2b2f7SThomas Petazzoni }
998da2b2f7SThomas Petazzoni #else
mvebu_memblock_reserve(void)1008da2b2f7SThomas Petazzoni static void __init mvebu_memblock_reserve(void) {}
1018da2b2f7SThomas Petazzoni #endif
1028da2b2f7SThomas Petazzoni 
mvebu_init_irq(void)10301178890SThomas Petazzoni static void __init mvebu_init_irq(void)
10499b3d294SThomas Petazzoni {
10501178890SThomas Petazzoni 	irqchip_init();
1068e6ac203SThomas Petazzoni 	mvebu_scu_enable();
10799b3d294SThomas Petazzoni 	coherency_init();
1085686a1e5SThomas Petazzoni 	BUG_ON(mvebu_mbus_dt_init(coherency_available()));
109752ef800SThomas Petazzoni }
110ca4a6f87SThomas Petazzoni 
i2c_quirk(void)11199b3d294SThomas Petazzoni static void __init i2c_quirk(void)
11299b3d294SThomas Petazzoni {
11399b3d294SThomas Petazzoni 	struct device_node *np;
11499b3d294SThomas Petazzoni 	u32 dev, rev;
11599b3d294SThomas Petazzoni 
11699b3d294SThomas Petazzoni 	/*
11799b3d294SThomas Petazzoni 	 * Only revisons more recent than A0 support the offload
11899b3d294SThomas Petazzoni 	 * mechanism. We can exit only if we are sure that we can
11999b3d294SThomas Petazzoni 	 * get the SoC revision and it is more recent than A0.
12099b3d294SThomas Petazzoni 	 */
1218eee0f81SGregory CLEMENT 	if (mvebu_get_soc_id(&dev, &rev) == 0 && rev > MV78XX0_A0_REV)
12299b3d294SThomas Petazzoni 		return;
12399b3d294SThomas Petazzoni 
12499b3d294SThomas Petazzoni 	for_each_compatible_node(np, NULL, "marvell,mv78230-i2c") {
12599b3d294SThomas Petazzoni 		struct property *new_compat;
12699b3d294SThomas Petazzoni 
12799b3d294SThomas Petazzoni 		new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
12899b3d294SThomas Petazzoni 
12999b3d294SThomas Petazzoni 		new_compat->name = kstrdup("compatible", GFP_KERNEL);
13099b3d294SThomas Petazzoni 		new_compat->length = sizeof("marvell,mv78230-a0-i2c");
13199b3d294SThomas Petazzoni 		new_compat->value = kstrdup("marvell,mv78230-a0-i2c",
13299b3d294SThomas Petazzoni 						GFP_KERNEL);
13399b3d294SThomas Petazzoni 
13499b3d294SThomas Petazzoni 		of_update_property(np, new_compat);
13599b3d294SThomas Petazzoni 	}
13699b3d294SThomas Petazzoni }
13799b3d294SThomas Petazzoni 
mvebu_dt_init(void)13899b3d294SThomas Petazzoni static void __init mvebu_dt_init(void)
13999b3d294SThomas Petazzoni {
1405129ee22SAndrew Lunn 	if (of_machine_is_compatible("marvell,armadaxp"))
14199b3d294SThomas Petazzoni 		i2c_quirk();
14299b3d294SThomas Petazzoni }
14399b3d294SThomas Petazzoni 
armada_370_xp_dt_fixup(void)1443972863aSChris Packham static void __init armada_370_xp_dt_fixup(void)
1453972863aSChris Packham {
1463972863aSChris Packham #ifdef CONFIG_SMP
1473972863aSChris Packham 	smp_set_ops(smp_ops(armada_xp_smp_ops));
1483972863aSChris Packham #endif
1493972863aSChris Packham }
1503972863aSChris Packham 
151bc2d7a58SThomas Petazzoni static const char * const armada_370_xp_dt_compat[] __initconst = {
15299b3d294SThomas Petazzoni 	"marvell,armada-370-xp",
15399b3d294SThomas Petazzoni 	NULL,
15499b3d294SThomas Petazzoni };
15599b3d294SThomas Petazzoni 
156a017dbb6SThomas Petazzoni DT_MACHINE_START(ARMADA_370_XP_DT, "Marvell Armada 370/XP (Device Tree)")
1579847cf04SRussell King 	.l2c_aux_val	= 0,
1589847cf04SRussell King 	.l2c_aux_mask	= ~0,
15999b3d294SThomas Petazzoni 	.init_machine	= mvebu_dt_init,
16001178890SThomas Petazzoni 	.init_irq       = mvebu_init_irq,
16199b3d294SThomas Petazzoni 	.restart	= mvebu_restart,
1628da2b2f7SThomas Petazzoni 	.reserve        = mvebu_memblock_reserve,
16399b3d294SThomas Petazzoni 	.dt_compat	= armada_370_xp_dt_compat,
1643972863aSChris Packham 	.dt_fixup	= armada_370_xp_dt_fixup,
16599b3d294SThomas Petazzoni MACHINE_END
166d3ce7f25SGregory CLEMENT 
167bc2d7a58SThomas Petazzoni static const char * const armada_375_dt_compat[] __initconst = {
168d3ce7f25SGregory CLEMENT 	"marvell,armada375",
169d3ce7f25SGregory CLEMENT 	NULL,
170d3ce7f25SGregory CLEMENT };
171d3ce7f25SGregory CLEMENT 
172d3ce7f25SGregory CLEMENT DT_MACHINE_START(ARMADA_375_DT, "Marvell Armada 375 (Device Tree)")
1739847cf04SRussell King 	.l2c_aux_val	= 0,
1749847cf04SRussell King 	.l2c_aux_mask	= ~0,
17501178890SThomas Petazzoni 	.init_irq       = mvebu_init_irq,
1765fd62066SEzequiel Garcia 	.init_machine	= mvebu_dt_init,
177d3ce7f25SGregory CLEMENT 	.restart	= mvebu_restart,
178d3ce7f25SGregory CLEMENT 	.dt_compat	= armada_375_dt_compat,
179d3ce7f25SGregory CLEMENT MACHINE_END
1809aa30f1cSThomas Petazzoni 
181bc2d7a58SThomas Petazzoni static const char * const armada_38x_dt_compat[] __initconst = {
1829aa30f1cSThomas Petazzoni 	"marvell,armada380",
1839aa30f1cSThomas Petazzoni 	"marvell,armada385",
1849aa30f1cSThomas Petazzoni 	NULL,
1859aa30f1cSThomas Petazzoni };
1869aa30f1cSThomas Petazzoni 
1879aa30f1cSThomas Petazzoni DT_MACHINE_START(ARMADA_38X_DT, "Marvell Armada 380/385 (Device Tree)")
1889847cf04SRussell King 	.l2c_aux_val	= 0,
1899847cf04SRussell King 	.l2c_aux_mask	= ~0,
19001178890SThomas Petazzoni 	.init_irq       = mvebu_init_irq,
1919aa30f1cSThomas Petazzoni 	.restart	= mvebu_restart,
1929aa30f1cSThomas Petazzoni 	.dt_compat	= armada_38x_dt_compat,
1939aa30f1cSThomas Petazzoni MACHINE_END
194242ede0bSThomas Petazzoni 
195242ede0bSThomas Petazzoni static const char * const armada_39x_dt_compat[] __initconst = {
196242ede0bSThomas Petazzoni 	"marvell,armada390",
197242ede0bSThomas Petazzoni 	"marvell,armada398",
198242ede0bSThomas Petazzoni 	NULL,
199242ede0bSThomas Petazzoni };
200242ede0bSThomas Petazzoni 
201242ede0bSThomas Petazzoni DT_MACHINE_START(ARMADA_39X_DT, "Marvell Armada 39x (Device Tree)")
202242ede0bSThomas Petazzoni 	.l2c_aux_val	= 0,
203242ede0bSThomas Petazzoni 	.l2c_aux_mask	= ~0,
204242ede0bSThomas Petazzoni 	.init_irq       = mvebu_init_irq,
205242ede0bSThomas Petazzoni 	.restart	= mvebu_restart,
206242ede0bSThomas Petazzoni 	.dt_compat	= armada_39x_dt_compat,
207242ede0bSThomas Petazzoni MACHINE_END
208