18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2008-2009 ST-Ericsson SA
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Author: Srinidhi KASAGAR <srinidhi.kasagar@stericsson.com>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci#include <linux/types.h>
88c2ecf20Sopenharmony_ci#include <linux/init.h>
98c2ecf20Sopenharmony_ci#include <linux/device.h>
108c2ecf20Sopenharmony_ci#include <linux/amba/bus.h>
118c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
128c2ecf20Sopenharmony_ci#include <linux/irq.h>
138c2ecf20Sopenharmony_ci#include <linux/irqchip.h>
148c2ecf20Sopenharmony_ci#include <linux/irqchip/arm-gic.h>
158c2ecf20Sopenharmony_ci#include <linux/mfd/dbx500-prcmu.h>
168c2ecf20Sopenharmony_ci#include <linux/platform_data/arm-ux500-pm.h>
178c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
188c2ecf20Sopenharmony_ci#include <linux/io.h>
198c2ecf20Sopenharmony_ci#include <linux/of.h>
208c2ecf20Sopenharmony_ci#include <linux/of_address.h>
218c2ecf20Sopenharmony_ci#include <linux/of_platform.h>
228c2ecf20Sopenharmony_ci#include <linux/regulator/machine.h>
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#include <asm/outercache.h>
258c2ecf20Sopenharmony_ci#include <asm/hardware/cache-l2x0.h>
268c2ecf20Sopenharmony_ci#include <asm/mach/map.h>
278c2ecf20Sopenharmony_ci#include <asm/mach/arch.h>
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#include "db8500-regs.h"
308c2ecf20Sopenharmony_ci#include "pm_domains.h"
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistatic int __init ux500_l2x0_unlock(void)
338c2ecf20Sopenharmony_ci{
348c2ecf20Sopenharmony_ci	int i;
358c2ecf20Sopenharmony_ci	struct device_node *np;
368c2ecf20Sopenharmony_ci	void __iomem *l2x0_base;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	np = of_find_compatible_node(NULL, NULL, "arm,pl310-cache");
398c2ecf20Sopenharmony_ci	l2x0_base = of_iomap(np, 0);
408c2ecf20Sopenharmony_ci	of_node_put(np);
418c2ecf20Sopenharmony_ci	if (!l2x0_base)
428c2ecf20Sopenharmony_ci		return -ENODEV;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	/*
458c2ecf20Sopenharmony_ci	 * Unlock Data and Instruction Lock if locked. Ux500 U-Boot versions
468c2ecf20Sopenharmony_ci	 * apparently locks both caches before jumping to the kernel. The
478c2ecf20Sopenharmony_ci	 * l2x0 core will not touch the unlock registers if the l2x0 is
488c2ecf20Sopenharmony_ci	 * already enabled, so we do it right here instead. The PL310 has
498c2ecf20Sopenharmony_ci	 * 8 sets of registers, one per possible CPU.
508c2ecf20Sopenharmony_ci	 */
518c2ecf20Sopenharmony_ci	for (i = 0; i < 8; i++) {
528c2ecf20Sopenharmony_ci		writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_D_BASE +
538c2ecf20Sopenharmony_ci			       i * L2X0_LOCKDOWN_STRIDE);
548c2ecf20Sopenharmony_ci		writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_I_BASE +
558c2ecf20Sopenharmony_ci			       i * L2X0_LOCKDOWN_STRIDE);
568c2ecf20Sopenharmony_ci	}
578c2ecf20Sopenharmony_ci	iounmap(l2x0_base);
588c2ecf20Sopenharmony_ci	return 0;
598c2ecf20Sopenharmony_ci}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistatic void ux500_l2c310_write_sec(unsigned long val, unsigned reg)
628c2ecf20Sopenharmony_ci{
638c2ecf20Sopenharmony_ci	/*
648c2ecf20Sopenharmony_ci	 * We can't write to secure registers as we are in non-secure
658c2ecf20Sopenharmony_ci	 * mode, until we have some SMI service available.
668c2ecf20Sopenharmony_ci	 */
678c2ecf20Sopenharmony_ci}
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/*
708c2ecf20Sopenharmony_ci * FIXME: Should we set up the GPIO domain here?
718c2ecf20Sopenharmony_ci *
728c2ecf20Sopenharmony_ci * The problem is that we cannot put the interrupt resources into the platform
738c2ecf20Sopenharmony_ci * device until the irqdomain has been added. Right now, we set the GIC interrupt
748c2ecf20Sopenharmony_ci * domain from init_irq(), then load the gpio driver from
758c2ecf20Sopenharmony_ci * core_initcall(nmk_gpio_init) and add the platform devices from
768c2ecf20Sopenharmony_ci * arch_initcall(customize_machine).
778c2ecf20Sopenharmony_ci *
788c2ecf20Sopenharmony_ci * This feels fragile because it depends on the gpio device getting probed
798c2ecf20Sopenharmony_ci * _before_ any device uses the gpio interrupts.
808c2ecf20Sopenharmony_ci*/
818c2ecf20Sopenharmony_cistatic void __init ux500_init_irq(void)
828c2ecf20Sopenharmony_ci{
838c2ecf20Sopenharmony_ci	struct device_node *np;
848c2ecf20Sopenharmony_ci	struct resource r;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	irqchip_init();
878c2ecf20Sopenharmony_ci	prcmu_early_init();
888c2ecf20Sopenharmony_ci	np = of_find_compatible_node(NULL, NULL, "stericsson,db8500-prcmu");
898c2ecf20Sopenharmony_ci	of_address_to_resource(np, 0, &r);
908c2ecf20Sopenharmony_ci	of_node_put(np);
918c2ecf20Sopenharmony_ci	if (!r.start) {
928c2ecf20Sopenharmony_ci		pr_err("could not find PRCMU base resource\n");
938c2ecf20Sopenharmony_ci		return;
948c2ecf20Sopenharmony_ci	}
958c2ecf20Sopenharmony_ci	ux500_pm_init(r.start, r.end-r.start);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	/* Unlock before init */
988c2ecf20Sopenharmony_ci	ux500_l2x0_unlock();
998c2ecf20Sopenharmony_ci	outer_cache.write_sec = ux500_l2c310_write_sec;
1008c2ecf20Sopenharmony_ci}
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistatic void ux500_restart(enum reboot_mode mode, const char *cmd)
1038c2ecf20Sopenharmony_ci{
1048c2ecf20Sopenharmony_ci	local_irq_disable();
1058c2ecf20Sopenharmony_ci	local_fiq_disable();
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	prcmu_system_reset(0);
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistatic const struct of_device_id u8500_local_bus_nodes[] = {
1118c2ecf20Sopenharmony_ci	/* only create devices below soc node */
1128c2ecf20Sopenharmony_ci	{ .compatible = "stericsson,db8500", },
1138c2ecf20Sopenharmony_ci	{ .compatible = "simple-bus"},
1148c2ecf20Sopenharmony_ci	{ },
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistatic void __init u8500_init_machine(void)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	/* Initialize ux500 power domains */
1208c2ecf20Sopenharmony_ci	ux500_pm_domains_init();
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	of_platform_populate(NULL, u8500_local_bus_nodes,
1238c2ecf20Sopenharmony_ci			     NULL, NULL);
1248c2ecf20Sopenharmony_ci}
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistatic const char * stericsson_dt_platform_compat[] = {
1278c2ecf20Sopenharmony_ci	"st-ericsson,u8500",
1288c2ecf20Sopenharmony_ci	"st-ericsson,u9500",
1298c2ecf20Sopenharmony_ci	NULL,
1308c2ecf20Sopenharmony_ci};
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ciDT_MACHINE_START(U8500_DT, "ST-Ericsson Ux5x0 platform (Device Tree Support)")
1338c2ecf20Sopenharmony_ci	.l2c_aux_val    = 0,
1348c2ecf20Sopenharmony_ci	.l2c_aux_mask	= ~0,
1358c2ecf20Sopenharmony_ci	.init_irq	= ux500_init_irq,
1368c2ecf20Sopenharmony_ci	.init_machine	= u8500_init_machine,
1378c2ecf20Sopenharmony_ci	.dt_compat      = stericsson_dt_platform_compat,
1388c2ecf20Sopenharmony_ci	.restart        = ux500_restart,
1398c2ecf20Sopenharmony_ciMACHINE_END
140