blob: f9c02f9f1c92199027cecf15f6a4567027b82d02 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -07002/*
3 * OMAP4 specific common source file.
4 *
5 * Copyright (C) 2010 Texas Instruments, Inc.
6 * Author:
7 * Santosh Shilimkar <santosh.shilimkar@ti.com>
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -07008 */
9
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/io.h>
Colin Crosscd8ce152012-10-18 12:20:08 +030013#include <linux/irq.h>
Rob Herring0529e3152012-11-05 16:18:28 -060014#include <linux/irqchip.h>
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070015#include <linux/platform_device.h>
Santosh Shilimkar137d1052011-06-25 18:04:31 -070016#include <linux/memblock.h>
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070017#include <linux/of_irq.h>
18#include <linux/of_platform.h>
19#include <linux/export.h>
Rob Herring520f7bd2012-12-27 13:10:24 -060020#include <linux/irqchip/arm-gic.h>
Santosh Shilimkarfd1c0782013-02-25 14:12:58 +053021#include <linux/of_address.h>
Robin Holt7b6d8642013-07-08 16:01:40 -070022#include <linux/reboot.h>
Rajendra Nayak1306c082014-09-10 11:04:04 -050023#include <linux/genalloc.h>
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070024
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070025#include <asm/hardware/cache-l2x0.h>
Santosh Shilimkar137d1052011-06-25 18:04:31 -070026#include <asm/mach/map.h>
Russell King716a3dc2012-01-13 15:00:51 +000027#include <asm/memblock.h>
Colin Crosscd8ce152012-10-18 12:20:08 +030028#include <asm/smp_twd.h>
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070029
Tony Lindgren732231a2012-09-20 11:41:16 -070030#include "omap-wakeupgen.h"
Tony Lindgrendbc04162012-08-31 10:59:07 -070031#include "soc.h"
Paul Walmsleyb6a42262012-10-29 20:50:21 -060032#include "iomap.h"
Tony Lindgren4e653312011-11-10 22:45:17 +010033#include "common.h"
Paul Walmsley2f334a32012-10-29 20:56:07 -060034#include "prminst44xx.h"
Paul Walmsleyd9a16f92012-10-29 20:57:39 -060035#include "prcm_mpu44xx.h"
Santosh Shilimkar501f0c72011-01-01 19:56:04 +053036#include "omap4-sar-layout.h"
Lokesh Vutlaf7a9b8a2012-10-02 00:17:06 +053037#include "omap-secure.h"
Tony Lindgrenbb772092012-10-29 09:35:35 -070038#include "sram.h"
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070039
40#ifdef CONFIG_CACHE_L2X0
Santosh Shilimkar02afe8a2011-03-03 18:03:25 +053041static void __iomem *l2cache_base;
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070042#endif
43
Santosh Shilimkar501f0c72011-01-01 19:56:04 +053044static void __iomem *sar_ram_base;
Santosh Shilimkarff999b82012-10-18 12:20:05 +030045static void __iomem *gic_dist_base_addr;
Colin Crosscd8ce152012-10-18 12:20:08 +030046static void __iomem *twd_base;
47
48#define IRQ_LOCALTIMER 29
Santosh Shilimkar501f0c72011-01-01 19:56:04 +053049
Russell King3fa609752015-06-06 00:38:08 +010050#ifdef CONFIG_OMAP_INTERCONNECT_BARRIER
51
Russell Kingf7469292015-06-06 00:13:40 +010052/* Used to implement memory barrier on DRAM path */
53#define OMAP4_DRAM_BARRIER_VA 0xfe600000
54
Russell King3fa609752015-06-06 00:38:08 +010055static void __iomem *dram_sync, *sram_sync;
56static phys_addr_t dram_sync_paddr;
57static u32 dram_sync_size;
Russell Kingf7469292015-06-06 00:13:40 +010058
Russell King3fa609752015-06-06 00:38:08 +010059/*
Andrea Gelmini6eedfcb2016-05-21 13:50:19 +020060 * The OMAP4 bus structure contains asynchronous bridges which can buffer
Russell King3fa609752015-06-06 00:38:08 +010061 * data writes from the MPU. These asynchronous bridges can be found on
62 * paths between the MPU to EMIF, and the MPU to L3 interconnects.
63 *
64 * We need to be careful about re-ordering which can happen as a result
65 * of different accesses being performed via different paths, and
66 * therefore different asynchronous bridges.
67 */
Russell Kingf7469292015-06-06 00:13:40 +010068
Russell King3fa609752015-06-06 00:38:08 +010069/*
70 * OMAP4 interconnect barrier which is called for each mb() and wmb().
71 * This is to ensure that normal paths to DRAM (normal memory, cacheable
72 * accesses) are properly synchronised with writes to DMA coherent memory
73 * (normal memory, uncacheable) and device writes.
74 *
75 * The mb() and wmb() barriers only operate only on the MPU->MA->EMIF
76 * path, as we need to ensure that data is visible to other system
77 * masters prior to writes to those system masters being seen.
78 *
79 * Note: the SRAM path is not synchronised via mb() and wmb().
80 */
81static void omap4_mb(void)
82{
83 if (dram_sync)
84 writel_relaxed(0, dram_sync);
85}
86
87/*
88 * OMAP4 Errata i688 - asynchronous bridge corruption when entering WFI.
89 *
90 * If a data is stalled inside asynchronous bridge because of back
91 * pressure, it may be accepted multiple times, creating pointer
92 * misalignment that will corrupt next transfers on that data path until
93 * next reset of the system. No recovery procedure once the issue is hit,
94 * the path remains consistently broken.
95 *
96 * Async bridges can be found on paths between MPU to EMIF and MPU to L3
97 * interconnects.
98 *
99 * This situation can happen only when the idle is initiated by a Master
100 * Request Disconnection (which is trigged by software when executing WFI
101 * on the CPU).
102 *
103 * The work-around for this errata needs all the initiators connected
104 * through an async bridge to ensure that data path is properly drained
105 * before issuing WFI. This condition will be met if one Strongly ordered
106 * access is performed to the target right before executing the WFI.
107 *
108 * In MPU case, L3 T2ASYNC FIFO and DDR T2ASYNC FIFO needs to be drained.
109 * IO barrier ensure that there is no synchronisation loss on initiators
110 * operating on both interconnect port simultaneously.
111 *
112 * This is a stronger version of the OMAP4 memory barrier below, and
113 * operates on both the MPU->MA->EMIF path but also the MPU->OCP path
114 * as well, and is necessary prior to executing a WFI.
115 */
116void omap_interconnect_sync(void)
Russell Kingf7469292015-06-06 00:13:40 +0100117{
118 if (dram_sync && sram_sync) {
119 writel_relaxed(readl_relaxed(dram_sync), dram_sync);
120 writel_relaxed(readl_relaxed(sram_sync), sram_sync);
121 isb();
122 }
123}
Russell Kingf7469292015-06-06 00:13:40 +0100124
125static int __init omap4_sram_init(void)
126{
127 struct device_node *np;
128 struct gen_pool *sram_pool;
129
130 np = of_find_compatible_node(NULL, NULL, "ti,omap4-mpu");
131 if (!np)
132 pr_warn("%s:Unable to allocate sram needed to handle errata I688\n",
133 __func__);
Russell King3fa609752015-06-06 00:38:08 +0100134 sram_pool = of_gen_pool_get(np, "sram", 0);
Russell Kingf7469292015-06-06 00:13:40 +0100135 if (!sram_pool)
136 pr_warn("%s:Unable to get sram pool needed to handle errata I688\n",
137 __func__);
138 else
139 sram_sync = (void *)gen_pool_alloc(sram_pool, PAGE_SIZE);
140
141 return 0;
142}
143omap_arch_initcall(omap4_sram_init);
144
145/* Steal one page physical memory for barrier implementation */
Russell King3fa609752015-06-06 00:38:08 +0100146void __init omap_barrier_reserve_memblock(void)
Russell Kingf7469292015-06-06 00:13:40 +0100147{
Russell King3fa609752015-06-06 00:38:08 +0100148 dram_sync_size = ALIGN(PAGE_SIZE, SZ_1M);
149 dram_sync_paddr = arm_memblock_steal(dram_sync_size, SZ_1M);
Russell Kingf7469292015-06-06 00:13:40 +0100150}
151
152void __init omap_barriers_init(void)
153{
154 struct map_desc dram_io_desc[1];
155
156 dram_io_desc[0].virtual = OMAP4_DRAM_BARRIER_VA;
Russell King3fa609752015-06-06 00:38:08 +0100157 dram_io_desc[0].pfn = __phys_to_pfn(dram_sync_paddr);
158 dram_io_desc[0].length = dram_sync_size;
Russell Kingf7469292015-06-06 00:13:40 +0100159 dram_io_desc[0].type = MT_MEMORY_RW_SO;
160 iotable_init(dram_io_desc, ARRAY_SIZE(dram_io_desc));
161 dram_sync = (void __iomem *) dram_io_desc[0].virtual;
162
Russell King3fa609752015-06-06 00:38:08 +0100163 pr_info("OMAP4: Map %pa to %p for dram barrier\n",
164 &dram_sync_paddr, dram_sync);
Russell Kingf7469292015-06-06 00:13:40 +0100165
Russell King3fa609752015-06-06 00:38:08 +0100166 soc_mb = omap4_mb;
Russell Kingf7469292015-06-06 00:13:40 +0100167}
Russell King3fa609752015-06-06 00:38:08 +0100168
Russell Kingf7469292015-06-06 00:13:40 +0100169#endif
170
Santosh Shilimkarff999b82012-10-18 12:20:05 +0300171void gic_dist_disable(void)
172{
173 if (gic_dist_base_addr)
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300174 writel_relaxed(0x0, gic_dist_base_addr + GIC_DIST_CTRL);
Santosh Shilimkarff999b82012-10-18 12:20:05 +0300175}
176
Strashko, Grygorii74ed7bd2013-10-22 22:07:15 +0300177void gic_dist_enable(void)
178{
179 if (gic_dist_base_addr)
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300180 writel_relaxed(0x1, gic_dist_base_addr + GIC_DIST_CTRL);
Strashko, Grygorii74ed7bd2013-10-22 22:07:15 +0300181}
182
Colin Crosscd8ce152012-10-18 12:20:08 +0300183bool gic_dist_disabled(void)
184{
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300185 return !(readl_relaxed(gic_dist_base_addr + GIC_DIST_CTRL) & 0x1);
Colin Crosscd8ce152012-10-18 12:20:08 +0300186}
187
188void gic_timer_retrigger(void)
189{
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300190 u32 twd_int = readl_relaxed(twd_base + TWD_TIMER_INTSTAT);
191 u32 gic_int = readl_relaxed(gic_dist_base_addr + GIC_DIST_PENDING_SET);
192 u32 twd_ctrl = readl_relaxed(twd_base + TWD_TIMER_CONTROL);
Colin Crosscd8ce152012-10-18 12:20:08 +0300193
194 if (twd_int && !(gic_int & BIT(IRQ_LOCALTIMER))) {
195 /*
196 * The local timer interrupt got lost while the distributor was
197 * disabled. Ack the pending interrupt, and retrigger it.
198 */
199 pr_warn("%s: lost localtimer interrupt\n", __func__);
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300200 writel_relaxed(1, twd_base + TWD_TIMER_INTSTAT);
Colin Crosscd8ce152012-10-18 12:20:08 +0300201 if (!(twd_ctrl & TWD_TIMER_CONTROL_PERIODIC)) {
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300202 writel_relaxed(1, twd_base + TWD_TIMER_COUNTER);
Colin Crosscd8ce152012-10-18 12:20:08 +0300203 twd_ctrl |= TWD_TIMER_CONTROL_ENABLE;
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300204 writel_relaxed(twd_ctrl, twd_base + TWD_TIMER_CONTROL);
Colin Crosscd8ce152012-10-18 12:20:08 +0300205 }
206 }
207}
208
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700209#ifdef CONFIG_CACHE_L2X0
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530210
Santosh Shilimkar02afe8a2011-03-03 18:03:25 +0530211void __iomem *omap4_get_l2cache_base(void)
212{
213 return l2cache_base;
214}
215
Marek Szyprowski944e9df2015-01-08 07:48:58 +0100216void omap4_l2c310_write_sec(unsigned long val, unsigned reg)
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530217{
Russell King36827ed2014-03-16 17:45:56 +0000218 unsigned smc_op;
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530219
Russell King36827ed2014-03-16 17:45:56 +0000220 switch (reg) {
221 case L2X0_CTRL:
222 smc_op = OMAP4_MON_L2X0_CTRL_INDEX;
223 break;
224
225 case L2X0_AUX_CTRL:
226 smc_op = OMAP4_MON_L2X0_AUXCTRL_INDEX;
227 break;
228
229 case L2X0_DEBUG_CTRL:
230 smc_op = OMAP4_MON_L2X0_DBG_CTRL_INDEX;
231 break;
232
233 case L310_PREFETCH_CTRL:
234 smc_op = OMAP4_MON_L2X0_PREFETCH_INDEX;
235 break;
236
Sekhar Noriba394f02014-07-14 18:43:46 +0530237 case L310_POWER_CTRL:
238 pr_info_once("OMAP L2C310: ROM does not support power control setting\n");
239 return;
240
Russell King36827ed2014-03-16 17:45:56 +0000241 default:
242 WARN_ONCE(1, "OMAP L2C310: ignoring write to reg 0x%x\n", reg);
243 return;
244 }
245
246 omap_smc1(smc_op, val);
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700247}
248
Sekhar Norib39b14e2014-04-22 13:58:01 +0530249int __init omap_l2_cache_init(void)
Santosh Shilimkar4bdb1572011-02-22 10:00:44 +0100250{
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700251 /* Static mapping, never released */
252 l2cache_base = ioremap(OMAP44XX_L2CACHE_BASE, SZ_4K);
Santosh Shilimkar0db18032011-03-03 17:36:52 +0530253 if (WARN_ON(!l2cache_base))
254 return -ENOMEM;
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700255 return 0;
256}
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700257#endif
Santosh Shilimkar501f0c72011-01-01 19:56:04 +0530258
259void __iomem *omap4_get_sar_ram_base(void)
260{
261 return sar_ram_base;
262}
263
264/*
Tony Lindgrenf4b9f402016-06-22 01:59:39 -0700265 * SAR RAM used to save and restore the HW context in low power modes.
266 * Note that we need to initialize this very early for kexec. See
267 * omap4_mpuss_early_init().
Santosh Shilimkar501f0c72011-01-01 19:56:04 +0530268 */
Tony Lindgrenf4b9f402016-06-22 01:59:39 -0700269void __init omap4_sar_ram_init(void)
Santosh Shilimkar501f0c72011-01-01 19:56:04 +0530270{
Santosh Shilimkarda0e02a2013-02-06 17:54:39 +0530271 unsigned long sar_base;
272
Santosh Shilimkar501f0c72011-01-01 19:56:04 +0530273 /*
274 * To avoid code running on other OMAPs in
275 * multi-omap builds
276 */
Santosh Shilimkarda0e02a2013-02-06 17:54:39 +0530277 if (cpu_is_omap44xx())
278 sar_base = OMAP44XX_SAR_RAM_BASE;
279 else if (soc_is_omap54xx())
280 sar_base = OMAP54XX_SAR_RAM_BASE;
281 else
Tony Lindgrenf4b9f402016-06-22 01:59:39 -0700282 return;
Santosh Shilimkar501f0c72011-01-01 19:56:04 +0530283
284 /* Static mapping, never released */
Santosh Shilimkarda0e02a2013-02-06 17:54:39 +0530285 sar_ram_base = ioremap(sar_base, SZ_16K);
Santosh Shilimkar501f0c72011-01-01 19:56:04 +0530286 if (WARN_ON(!sar_ram_base))
Tony Lindgrenf4b9f402016-06-22 01:59:39 -0700287 return;
Santosh Shilimkar501f0c72011-01-01 19:56:04 +0530288}
Balaji T K1ee47b02012-04-25 17:27:46 +0530289
Marc Zyngier7136d452015-03-11 15:43:49 +0000290static const struct of_device_id intc_match[] = {
291 { .compatible = "ti,omap4-wugen-mpu", },
292 { .compatible = "ti,omap5-wugen-mpu", },
Marc Zyngier0fb22a82015-01-17 10:21:08 +0000293 { },
294};
295
Marc Zyngier7136d452015-03-11 15:43:49 +0000296static struct device_node *intc_node;
Marc Zyngier0fb22a82015-01-17 10:21:08 +0000297
R Sricharanc4082d42012-06-05 16:31:06 +0530298void __init omap_gic_of_init(void)
299{
Santosh Shilimkarfd1c0782013-02-25 14:12:58 +0530300 struct device_node *np;
301
Marc Zyngier7136d452015-03-11 15:43:49 +0000302 intc_node = of_find_matching_node(NULL, intc_match);
303 if (WARN_ON(!intc_node)) {
304 pr_err("No WUGEN found in DT, system will misbehave.\n");
305 pr_err("UPDATE YOUR DEVICE TREE!\n");
306 }
307
Santosh Shilimkarfd1c0782013-02-25 14:12:58 +0530308 /* Extract GIC distributor and TWD bases for OMAP4460 ROM Errata WA */
309 if (!cpu_is_omap446x())
310 goto skip_errata_init;
311
312 np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
313 gic_dist_base_addr = of_iomap(np, 0);
314 WARN_ON(!gic_dist_base_addr);
315
316 np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-twd-timer");
317 twd_base = of_iomap(np, 0);
318 WARN_ON(!twd_base);
319
320skip_errata_init:
Rob Herring0529e3152012-11-05 16:18:28 -0600321 irqchip_init();
R Sricharanc4082d42012-06-05 16:31:06 +0530322}