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