1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2cb165c52SRabin Vincent /*
3c15def1cSLinus Walleij * Copyright (C) 2008-2009 ST-Ericsson SA
4cb165c52SRabin Vincent *
5cb165c52SRabin Vincent * Author: Srinidhi KASAGAR <srinidhi.kasagar@stericsson.com>
6cb165c52SRabin Vincent */
7cb165c52SRabin Vincent #include <linux/types.h>
8cb165c52SRabin Vincent #include <linux/init.h>
9cb165c52SRabin Vincent #include <linux/device.h>
10cb165c52SRabin Vincent #include <linux/amba/bus.h>
11aa90eb9dSRabin Vincent #include <linux/interrupt.h>
12cb165c52SRabin Vincent #include <linux/irq.h>
13a16729eaSArnd Bergmann #include <linux/irqchip.h>
14a16729eaSArnd Bergmann #include <linux/irqchip/arm-gic.h>
15a16729eaSArnd Bergmann #include <linux/mfd/dbx500-prcmu.h>
16a16729eaSArnd Bergmann #include <linux/platform_data/arm-ux500-pm.h>
17cb165c52SRabin Vincent #include <linux/platform_device.h>
18cb165c52SRabin Vincent #include <linux/io.h>
19fa86a764SLee Jones #include <linux/of.h>
20a16729eaSArnd Bergmann #include <linux/of_address.h>
21fa86a764SLee Jones #include <linux/of_platform.h>
22fa86a764SLee Jones #include <linux/regulator/machine.h>
23cb165c52SRabin Vincent
24a16729eaSArnd Bergmann #include <asm/outercache.h>
25a16729eaSArnd Bergmann #include <asm/hardware/cache-l2x0.h>
26cb165c52SRabin Vincent #include <asm/mach/map.h>
27a16729eaSArnd Bergmann #include <asm/mach/arch.h>
28b8edf848SLinus Torvalds
ux500_l2x0_unlock(void)29a16729eaSArnd Bergmann static int __init ux500_l2x0_unlock(void)
30a16729eaSArnd Bergmann {
31a16729eaSArnd Bergmann int i;
32a16729eaSArnd Bergmann struct device_node *np;
33a16729eaSArnd Bergmann void __iomem *l2x0_base;
34a16729eaSArnd Bergmann
35a16729eaSArnd Bergmann np = of_find_compatible_node(NULL, NULL, "arm,pl310-cache");
36a16729eaSArnd Bergmann l2x0_base = of_iomap(np, 0);
37a16729eaSArnd Bergmann of_node_put(np);
38a16729eaSArnd Bergmann if (!l2x0_base)
39a16729eaSArnd Bergmann return -ENODEV;
40a16729eaSArnd Bergmann
41a16729eaSArnd Bergmann /*
42a16729eaSArnd Bergmann * Unlock Data and Instruction Lock if locked. Ux500 U-Boot versions
43a16729eaSArnd Bergmann * apparently locks both caches before jumping to the kernel. The
44a16729eaSArnd Bergmann * l2x0 core will not touch the unlock registers if the l2x0 is
45a16729eaSArnd Bergmann * already enabled, so we do it right here instead. The PL310 has
46a16729eaSArnd Bergmann * 8 sets of registers, one per possible CPU.
47a16729eaSArnd Bergmann */
48a16729eaSArnd Bergmann for (i = 0; i < 8; i++) {
49a16729eaSArnd Bergmann writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_D_BASE +
50a16729eaSArnd Bergmann i * L2X0_LOCKDOWN_STRIDE);
51a16729eaSArnd Bergmann writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_I_BASE +
52a16729eaSArnd Bergmann i * L2X0_LOCKDOWN_STRIDE);
53a16729eaSArnd Bergmann }
54a16729eaSArnd Bergmann iounmap(l2x0_base);
55a16729eaSArnd Bergmann return 0;
56a16729eaSArnd Bergmann }
57a16729eaSArnd Bergmann
ux500_l2c310_write_sec(unsigned long val,unsigned reg)58a16729eaSArnd Bergmann static void ux500_l2c310_write_sec(unsigned long val, unsigned reg)
59a16729eaSArnd Bergmann {
60a16729eaSArnd Bergmann /*
61a16729eaSArnd Bergmann * We can't write to secure registers as we are in non-secure
62a16729eaSArnd Bergmann * mode, until we have some SMI service available.
63a16729eaSArnd Bergmann */
64a16729eaSArnd Bergmann }
65a16729eaSArnd Bergmann
66a16729eaSArnd Bergmann /*
67a16729eaSArnd Bergmann * FIXME: Should we set up the GPIO domain here?
68a16729eaSArnd Bergmann *
69a16729eaSArnd Bergmann * The problem is that we cannot put the interrupt resources into the platform
70a16729eaSArnd Bergmann * device until the irqdomain has been added. Right now, we set the GIC interrupt
71a16729eaSArnd Bergmann * domain from init_irq(), then load the gpio driver from
72a16729eaSArnd Bergmann * core_initcall(nmk_gpio_init) and add the platform devices from
73a16729eaSArnd Bergmann * arch_initcall(customize_machine).
74a16729eaSArnd Bergmann *
75a16729eaSArnd Bergmann * This feels fragile because it depends on the gpio device getting probed
76a16729eaSArnd Bergmann * _before_ any device uses the gpio interrupts.
77a16729eaSArnd Bergmann */
ux500_init_irq(void)78a16729eaSArnd Bergmann static void __init ux500_init_irq(void)
79a16729eaSArnd Bergmann {
80a16729eaSArnd Bergmann struct device_node *np;
81a16729eaSArnd Bergmann struct resource r;
82a16729eaSArnd Bergmann
83a16729eaSArnd Bergmann irqchip_init();
8422fb3ad0SLinus Walleij prcmu_early_init();
85a16729eaSArnd Bergmann np = of_find_compatible_node(NULL, NULL, "stericsson,db8500-prcmu");
86a16729eaSArnd Bergmann of_address_to_resource(np, 0, &r);
87a16729eaSArnd Bergmann of_node_put(np);
88a16729eaSArnd Bergmann if (!r.start) {
89a16729eaSArnd Bergmann pr_err("could not find PRCMU base resource\n");
90a16729eaSArnd Bergmann return;
91a16729eaSArnd Bergmann }
92a16729eaSArnd Bergmann ux500_pm_init(r.start, r.end-r.start);
93a16729eaSArnd Bergmann
94a16729eaSArnd Bergmann /* Unlock before init */
95a16729eaSArnd Bergmann ux500_l2x0_unlock();
96a16729eaSArnd Bergmann outer_cache.write_sec = ux500_l2c310_write_sec;
97a16729eaSArnd Bergmann }
98a16729eaSArnd Bergmann
ux500_restart(enum reboot_mode mode,const char * cmd)99a16729eaSArnd Bergmann static void ux500_restart(enum reboot_mode mode, const char *cmd)
100a16729eaSArnd Bergmann {
101a16729eaSArnd Bergmann local_irq_disable();
102a16729eaSArnd Bergmann local_fiq_disable();
103a16729eaSArnd Bergmann
104a16729eaSArnd Bergmann prcmu_system_reset(0);
105a16729eaSArnd Bergmann }
106a16729eaSArnd Bergmann
107fa86a764SLee Jones static const struct of_device_id u8500_local_bus_nodes[] = {
108fa86a764SLee Jones /* only create devices below soc node */
109fa86a764SLee Jones { .compatible = "stericsson,db8500", },
110fa86a764SLee Jones { .compatible = "simple-bus"},
111fa86a764SLee Jones { },
112fa86a764SLee Jones };
113fa86a764SLee Jones
u8500_init_machine(void)114fa86a764SLee Jones static void __init u8500_init_machine(void)
115fa86a764SLee Jones {
116dbe8a9dfSLinus Walleij of_platform_populate(NULL, u8500_local_bus_nodes,
117dbe8a9dfSLinus Walleij NULL, NULL);
118fa86a764SLee Jones }
119fa86a764SLee Jones
12079b40753SLee Jones static const char * stericsson_dt_platform_compat[] = {
12179b40753SLee Jones "st-ericsson,u8500",
12279b40753SLee Jones "st-ericsson,u9500",
123fa86a764SLee Jones NULL,
124fa86a764SLee Jones };
125fa86a764SLee Jones
12646c1bf81SLee Jones DT_MACHINE_START(U8500_DT, "ST-Ericsson Ux5x0 platform (Device Tree Support)")
1271e6cbc06SArnd Bergmann .l2c_aux_val = 0,
1281e6cbc06SArnd Bergmann .l2c_aux_mask = ~0,
129fa86a764SLee Jones .init_irq = ux500_init_irq,
130fa86a764SLee Jones .init_machine = u8500_init_machine,
13179b40753SLee Jones .dt_compat = stericsson_dt_platform_compat,
132bd93ec50SFabio Baltieri .restart = ux500_restart,
133fa86a764SLee Jones MACHINE_END
134