xref: /openbmc/linux/arch/arm/mach-mvebu/board-v7.c (revision 6a2b5343e23b177e684f97302f30696dfcfe0af4)
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>
1999b3d294SThomas Petazzoni #include <linux/of_platform.h>
2099b3d294SThomas Petazzoni #include <linux/io.h>
2199b3d294SThomas Petazzoni #include <linux/clocksource.h>
2299b3d294SThomas Petazzoni #include <linux/dma-mapping.h>
2399b3d294SThomas Petazzoni #include <linux/mbus.h>
24ff050ad1SLinus Torvalds #include <linux/signal.h>
2599b3d294SThomas Petazzoni #include <linux/slab.h>
2601178890SThomas Petazzoni #include <linux/irqchip.h>
2799b3d294SThomas Petazzoni #include <asm/hardware/cache-l2x0.h>
2899b3d294SThomas Petazzoni #include <asm/mach/arch.h>
2999b3d294SThomas Petazzoni #include <asm/mach/map.h>
3099b3d294SThomas Petazzoni #include <asm/mach/time.h>
318e6ac203SThomas Petazzoni #include <asm/smp_scu.h>
3299b3d294SThomas Petazzoni #include "armada-370-xp.h"
3399b3d294SThomas Petazzoni #include "common.h"
3499b3d294SThomas Petazzoni #include "coherency.h"
3599b3d294SThomas Petazzoni #include "mvebu-soc-id.h"
3699b3d294SThomas Petazzoni 
37*6a2b5343SGregory CLEMENT static void __iomem *scu_base;
38*6a2b5343SGregory CLEMENT 
39ca4a6f87SThomas Petazzoni /*
408e6ac203SThomas Petazzoni  * Enables the SCU when available. Obviously, this is only useful on
418e6ac203SThomas Petazzoni  * Cortex-A based SOCs, not on PJ4B based ones.
428e6ac203SThomas Petazzoni  */
438e6ac203SThomas Petazzoni static void __init mvebu_scu_enable(void)
448e6ac203SThomas Petazzoni {
458e6ac203SThomas Petazzoni 	struct device_node *np =
468e6ac203SThomas Petazzoni 		of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
478e6ac203SThomas Petazzoni 	if (np) {
488e6ac203SThomas Petazzoni 		scu_base = of_iomap(np, 0);
498e6ac203SThomas Petazzoni 		scu_enable(scu_base);
508e6ac203SThomas Petazzoni 		of_node_put(np);
518e6ac203SThomas Petazzoni 	}
528e6ac203SThomas Petazzoni }
538e6ac203SThomas Petazzoni 
54*6a2b5343SGregory CLEMENT void __iomem *mvebu_get_scu_base(void)
55*6a2b5343SGregory CLEMENT {
56*6a2b5343SGregory CLEMENT 	return scu_base;
57*6a2b5343SGregory CLEMENT }
58*6a2b5343SGregory CLEMENT 
598e6ac203SThomas Petazzoni /*
60ca4a6f87SThomas Petazzoni  * Early versions of Armada 375 SoC have a bug where the BootROM
61ca4a6f87SThomas Petazzoni  * leaves an external data abort pending. The kernel is hit by this
62ca4a6f87SThomas Petazzoni  * data abort as soon as it enters userspace, because it unmasks the
63ca4a6f87SThomas Petazzoni  * data aborts at this moment. We register a custom abort handler
64ca4a6f87SThomas Petazzoni  * below to ignore the first data abort to work around this
65ca4a6f87SThomas Petazzoni  * problem.
66ca4a6f87SThomas Petazzoni  */
67ca4a6f87SThomas Petazzoni static int armada_375_external_abort_wa(unsigned long addr, unsigned int fsr,
68ca4a6f87SThomas Petazzoni 					struct pt_regs *regs)
69ca4a6f87SThomas Petazzoni {
70ca4a6f87SThomas Petazzoni 	static int ignore_first;
71ca4a6f87SThomas Petazzoni 
72ca4a6f87SThomas Petazzoni 	if (!ignore_first && fsr == 0x1406) {
73ca4a6f87SThomas Petazzoni 		ignore_first = 1;
74ca4a6f87SThomas Petazzoni 		return 0;
75ca4a6f87SThomas Petazzoni 	}
76ca4a6f87SThomas Petazzoni 
77ca4a6f87SThomas Petazzoni 	return 1;
78ca4a6f87SThomas Petazzoni }
79ca4a6f87SThomas Petazzoni 
8001178890SThomas Petazzoni static void __init mvebu_init_irq(void)
8199b3d294SThomas Petazzoni {
8201178890SThomas Petazzoni 	irqchip_init();
838e6ac203SThomas Petazzoni 	mvebu_scu_enable();
8499b3d294SThomas Petazzoni 	coherency_init();
855686a1e5SThomas Petazzoni 	BUG_ON(mvebu_mbus_dt_init(coherency_available()));
86752ef800SThomas Petazzoni }
87ca4a6f87SThomas Petazzoni 
88752ef800SThomas Petazzoni static void __init external_abort_quirk(void)
89752ef800SThomas Petazzoni {
90752ef800SThomas Petazzoni 	u32 dev, rev;
91752ef800SThomas Petazzoni 
92752ef800SThomas Petazzoni 	if (mvebu_get_soc_id(&dev, &rev) == 0 && rev > ARMADA_375_Z1_REV)
93752ef800SThomas Petazzoni 		return;
94752ef800SThomas Petazzoni 
95ca4a6f87SThomas Petazzoni 	hook_fault_code(16 + 6, armada_375_external_abort_wa, SIGBUS, 0,
96ca4a6f87SThomas Petazzoni 			"imprecise external abort");
9799b3d294SThomas Petazzoni }
9899b3d294SThomas Petazzoni 
9999b3d294SThomas Petazzoni static void __init i2c_quirk(void)
10099b3d294SThomas Petazzoni {
10199b3d294SThomas Petazzoni 	struct device_node *np;
10299b3d294SThomas Petazzoni 	u32 dev, rev;
10399b3d294SThomas Petazzoni 
10499b3d294SThomas Petazzoni 	/*
10599b3d294SThomas Petazzoni 	 * Only revisons more recent than A0 support the offload
10699b3d294SThomas Petazzoni 	 * mechanism. We can exit only if we are sure that we can
10799b3d294SThomas Petazzoni 	 * get the SoC revision and it is more recent than A0.
10899b3d294SThomas Petazzoni 	 */
1098eee0f81SGregory CLEMENT 	if (mvebu_get_soc_id(&dev, &rev) == 0 && rev > MV78XX0_A0_REV)
11099b3d294SThomas Petazzoni 		return;
11199b3d294SThomas Petazzoni 
11299b3d294SThomas Petazzoni 	for_each_compatible_node(np, NULL, "marvell,mv78230-i2c") {
11399b3d294SThomas Petazzoni 		struct property *new_compat;
11499b3d294SThomas Petazzoni 
11599b3d294SThomas Petazzoni 		new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
11699b3d294SThomas Petazzoni 
11799b3d294SThomas Petazzoni 		new_compat->name = kstrdup("compatible", GFP_KERNEL);
11899b3d294SThomas Petazzoni 		new_compat->length = sizeof("marvell,mv78230-a0-i2c");
11999b3d294SThomas Petazzoni 		new_compat->value = kstrdup("marvell,mv78230-a0-i2c",
12099b3d294SThomas Petazzoni 						GFP_KERNEL);
12199b3d294SThomas Petazzoni 
12299b3d294SThomas Petazzoni 		of_update_property(np, new_compat);
12399b3d294SThomas Petazzoni 	}
12499b3d294SThomas Petazzoni 	return;
12599b3d294SThomas Petazzoni }
12699b3d294SThomas Petazzoni 
1275fd62066SEzequiel Garcia #define A375_Z1_THERMAL_FIXUP_OFFSET 0xc
1285fd62066SEzequiel Garcia 
1295fd62066SEzequiel Garcia static void __init thermal_quirk(void)
1305fd62066SEzequiel Garcia {
1315fd62066SEzequiel Garcia 	struct device_node *np;
1325fd62066SEzequiel Garcia 	u32 dev, rev;
1339d637348SEzequiel Garcia 	int res;
1345fd62066SEzequiel Garcia 
1359d637348SEzequiel Garcia 	/*
1369d637348SEzequiel Garcia 	 * The early SoC Z1 revision needs a quirk to be applied in order
1379d637348SEzequiel Garcia 	 * for the thermal controller to work properly. This quirk breaks
1389d637348SEzequiel Garcia 	 * the thermal support if applied on a SoC that doesn't need it,
1399d637348SEzequiel Garcia 	 * so we enforce the SoC revision to be known.
1409d637348SEzequiel Garcia 	 */
1419d637348SEzequiel Garcia 	res = mvebu_get_soc_id(&dev, &rev);
1429d637348SEzequiel Garcia 	if (res < 0 || (res == 0 && rev > ARMADA_375_Z1_REV))
1435fd62066SEzequiel Garcia 		return;
1445fd62066SEzequiel Garcia 
1455fd62066SEzequiel Garcia 	for_each_compatible_node(np, NULL, "marvell,armada375-thermal") {
1465fd62066SEzequiel Garcia 		struct property *prop;
1475fd62066SEzequiel Garcia 		__be32 newval, *newprop, *oldprop;
1485fd62066SEzequiel Garcia 		int len;
1495fd62066SEzequiel Garcia 
1505fd62066SEzequiel Garcia 		/*
1515fd62066SEzequiel Garcia 		 * The register offset is at a wrong location. This quirk
1525fd62066SEzequiel Garcia 		 * creates a new reg property as a clone of the previous
1535fd62066SEzequiel Garcia 		 * one and corrects the offset.
1545fd62066SEzequiel Garcia 		 */
1555fd62066SEzequiel Garcia 		oldprop = (__be32 *)of_get_property(np, "reg", &len);
1565fd62066SEzequiel Garcia 		if (!oldprop)
1575fd62066SEzequiel Garcia 			continue;
1585fd62066SEzequiel Garcia 
1595fd62066SEzequiel Garcia 		/* Create a duplicate of the 'reg' property */
1605fd62066SEzequiel Garcia 		prop = kzalloc(sizeof(*prop), GFP_KERNEL);
1615fd62066SEzequiel Garcia 		prop->length = len;
1625fd62066SEzequiel Garcia 		prop->name = kstrdup("reg", GFP_KERNEL);
1635fd62066SEzequiel Garcia 		prop->value = kzalloc(len, GFP_KERNEL);
1645fd62066SEzequiel Garcia 		memcpy(prop->value, oldprop, len);
1655fd62066SEzequiel Garcia 
1665fd62066SEzequiel Garcia 		/* Fixup the register offset of the second entry */
1675fd62066SEzequiel Garcia 		oldprop += 2;
1685fd62066SEzequiel Garcia 		newprop = (__be32 *)prop->value + 2;
1695fd62066SEzequiel Garcia 		newval = cpu_to_be32(be32_to_cpu(*oldprop) -
1705fd62066SEzequiel Garcia 				     A375_Z1_THERMAL_FIXUP_OFFSET);
1715fd62066SEzequiel Garcia 		*newprop = newval;
1725fd62066SEzequiel Garcia 		of_update_property(np, prop);
1735fd62066SEzequiel Garcia 
1745fd62066SEzequiel Garcia 		/*
1755fd62066SEzequiel Garcia 		 * The thermal controller needs some quirk too, so let's change
1769d637348SEzequiel Garcia 		 * the compatible string to reflect this and allow the driver
1779d637348SEzequiel Garcia 		 * the take the necessary action.
1785fd62066SEzequiel Garcia 		 */
1795fd62066SEzequiel Garcia 		prop = kzalloc(sizeof(*prop), GFP_KERNEL);
1805fd62066SEzequiel Garcia 		prop->name = kstrdup("compatible", GFP_KERNEL);
1815fd62066SEzequiel Garcia 		prop->length = sizeof("marvell,armada375-z1-thermal");
1825fd62066SEzequiel Garcia 		prop->value = kstrdup("marvell,armada375-z1-thermal",
1835fd62066SEzequiel Garcia 						GFP_KERNEL);
1845fd62066SEzequiel Garcia 		of_update_property(np, prop);
1855fd62066SEzequiel Garcia 	}
1865fd62066SEzequiel Garcia 	return;
1875fd62066SEzequiel Garcia }
1885fd62066SEzequiel Garcia 
18999b3d294SThomas Petazzoni static void __init mvebu_dt_init(void)
19099b3d294SThomas Petazzoni {
19199b3d294SThomas Petazzoni 	if (of_machine_is_compatible("plathome,openblocks-ax3-4"))
19299b3d294SThomas Petazzoni 		i2c_quirk();
193752ef800SThomas Petazzoni 	if (of_machine_is_compatible("marvell,a375-db")) {
194752ef800SThomas Petazzoni 		external_abort_quirk();
1955fd62066SEzequiel Garcia 		thermal_quirk();
196752ef800SThomas Petazzoni 	}
1975fd62066SEzequiel Garcia 
19899b3d294SThomas Petazzoni 	of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
19999b3d294SThomas Petazzoni }
20099b3d294SThomas Petazzoni 
20199b3d294SThomas Petazzoni static const char * const armada_370_xp_dt_compat[] = {
20299b3d294SThomas Petazzoni 	"marvell,armada-370-xp",
20399b3d294SThomas Petazzoni 	NULL,
20499b3d294SThomas Petazzoni };
20599b3d294SThomas Petazzoni 
206a017dbb6SThomas Petazzoni DT_MACHINE_START(ARMADA_370_XP_DT, "Marvell Armada 370/XP (Device Tree)")
2079847cf04SRussell King 	.l2c_aux_val	= 0,
2089847cf04SRussell King 	.l2c_aux_mask	= ~0,
20999b3d294SThomas Petazzoni 	.smp		= smp_ops(armada_xp_smp_ops),
21099b3d294SThomas Petazzoni 	.init_machine	= mvebu_dt_init,
21101178890SThomas Petazzoni 	.init_irq       = mvebu_init_irq,
21299b3d294SThomas Petazzoni 	.restart	= mvebu_restart,
21399b3d294SThomas Petazzoni 	.dt_compat	= armada_370_xp_dt_compat,
21499b3d294SThomas Petazzoni MACHINE_END
215d3ce7f25SGregory CLEMENT 
216d3ce7f25SGregory CLEMENT static const char * const armada_375_dt_compat[] = {
217d3ce7f25SGregory CLEMENT 	"marvell,armada375",
218d3ce7f25SGregory CLEMENT 	NULL,
219d3ce7f25SGregory CLEMENT };
220d3ce7f25SGregory CLEMENT 
221d3ce7f25SGregory CLEMENT DT_MACHINE_START(ARMADA_375_DT, "Marvell Armada 375 (Device Tree)")
2229847cf04SRussell King 	.l2c_aux_val	= 0,
2239847cf04SRussell King 	.l2c_aux_mask	= ~0,
22401178890SThomas Petazzoni 	.init_irq       = mvebu_init_irq,
2255fd62066SEzequiel Garcia 	.init_machine	= mvebu_dt_init,
226d3ce7f25SGregory CLEMENT 	.restart	= mvebu_restart,
227d3ce7f25SGregory CLEMENT 	.dt_compat	= armada_375_dt_compat,
228d3ce7f25SGregory CLEMENT MACHINE_END
2299aa30f1cSThomas Petazzoni 
2309aa30f1cSThomas Petazzoni static const char * const armada_38x_dt_compat[] = {
2319aa30f1cSThomas Petazzoni 	"marvell,armada380",
2329aa30f1cSThomas Petazzoni 	"marvell,armada385",
2339aa30f1cSThomas Petazzoni 	NULL,
2349aa30f1cSThomas Petazzoni };
2359aa30f1cSThomas Petazzoni 
2369aa30f1cSThomas Petazzoni DT_MACHINE_START(ARMADA_38X_DT, "Marvell Armada 380/385 (Device Tree)")
2379847cf04SRussell King 	.l2c_aux_val	= 0,
2389847cf04SRussell King 	.l2c_aux_mask	= ~0,
23901178890SThomas Petazzoni 	.init_irq       = mvebu_init_irq,
2409aa30f1cSThomas Petazzoni 	.restart	= mvebu_restart,
2419aa30f1cSThomas Petazzoni 	.dt_compat	= armada_38x_dt_compat,
2429aa30f1cSThomas Petazzoni MACHINE_END
243