blob: a0fe747634c1ff56d280159dafc78b9f2cd687ce [file] [log] [blame]
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -07001/*
2 * OMAP4 specific common source file.
3 *
4 * Copyright (C) 2010 Texas Instruments, Inc.
5 * Author:
6 * Santosh Shilimkar <santosh.shilimkar@ti.com>
7 *
8 *
9 * This program is free software,you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/io.h>
Colin Crosscd8ce152012-10-18 12:20:08 +030017#include <linux/irq.h>
Rob Herring0529e3152012-11-05 16:18:28 -060018#include <linux/irqchip.h>
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070019#include <linux/platform_device.h>
Santosh Shilimkar137d1052011-06-25 18:04:31 -070020#include <linux/memblock.h>
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070021#include <linux/of_irq.h>
22#include <linux/of_platform.h>
23#include <linux/export.h>
Rob Herring520f7bd2012-12-27 13:10:24 -060024#include <linux/irqchip/arm-gic.h>
Sricharan R5c61e612013-12-03 15:57:25 +053025#include <linux/irqchip/irq-crossbar.h>
Santosh Shilimkarfd1c0782013-02-25 14:12:58 +053026#include <linux/of_address.h>
Robin Holt7b6d8642013-07-08 16:01:40 -070027#include <linux/reboot.h>
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070028
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070029#include <asm/hardware/cache-l2x0.h>
Santosh Shilimkar137d1052011-06-25 18:04:31 -070030#include <asm/mach/map.h>
Russell King716a3dc2012-01-13 15:00:51 +000031#include <asm/memblock.h>
Colin Crosscd8ce152012-10-18 12:20:08 +030032#include <asm/smp_twd.h>
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070033
Tony Lindgren732231a2012-09-20 11:41:16 -070034#include "omap-wakeupgen.h"
Tony Lindgrendbc04162012-08-31 10:59:07 -070035#include "soc.h"
Paul Walmsleyb6a42262012-10-29 20:50:21 -060036#include "iomap.h"
Tony Lindgren4e653312011-11-10 22:45:17 +010037#include "common.h"
Tony Lindgren68f39e72012-10-15 12:09:43 -070038#include "mmc.h"
Paul Walmsley2f334a32012-10-29 20:56:07 -060039#include "prminst44xx.h"
Paul Walmsleyd9a16f92012-10-29 20:57:39 -060040#include "prcm_mpu44xx.h"
Santosh Shilimkar501f0c72011-01-01 19:56:04 +053041#include "omap4-sar-layout.h"
Lokesh Vutlaf7a9b8a2012-10-02 00:17:06 +053042#include "omap-secure.h"
Tony Lindgrenbb772092012-10-29 09:35:35 -070043#include "sram.h"
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070044
45#ifdef CONFIG_CACHE_L2X0
Santosh Shilimkar02afe8a2011-03-03 18:03:25 +053046static void __iomem *l2cache_base;
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070047#endif
48
Santosh Shilimkar501f0c72011-01-01 19:56:04 +053049static void __iomem *sar_ram_base;
Santosh Shilimkarff999b82012-10-18 12:20:05 +030050static void __iomem *gic_dist_base_addr;
Colin Crosscd8ce152012-10-18 12:20:08 +030051static void __iomem *twd_base;
52
53#define IRQ_LOCALTIMER 29
Santosh Shilimkar501f0c72011-01-01 19:56:04 +053054
Santosh Shilimkar137d1052011-06-25 18:04:31 -070055#ifdef CONFIG_OMAP4_ERRATA_I688
56/* Used to implement memory barrier on DRAM path */
57#define OMAP4_DRAM_BARRIER_VA 0xfe600000
58
59void __iomem *dram_sync, *sram_sync;
60
Santosh Shilimkar2ec1fc42012-02-02 19:33:55 +053061static phys_addr_t paddr;
62static u32 size;
63
Santosh Shilimkar137d1052011-06-25 18:04:31 -070064void omap_bus_sync(void)
65{
66 if (dram_sync && sram_sync) {
67 writel_relaxed(readl_relaxed(dram_sync), dram_sync);
68 writel_relaxed(readl_relaxed(sram_sync), sram_sync);
69 isb();
70 }
71}
R Sricharancc4ad902012-03-02 16:31:18 +053072EXPORT_SYMBOL(omap_bus_sync);
Santosh Shilimkar137d1052011-06-25 18:04:31 -070073
Santosh Shilimkar2ec1fc42012-02-02 19:33:55 +053074/* Steal one page physical memory for barrier implementation */
75int __init omap_barrier_reserve_memblock(void)
Santosh Shilimkar137d1052011-06-25 18:04:31 -070076{
Santosh Shilimkar137d1052011-06-25 18:04:31 -070077
78 size = ALIGN(PAGE_SIZE, SZ_1M);
Russell King716a3dc2012-01-13 15:00:51 +000079 paddr = arm_memblock_steal(size, SZ_1M);
80
Santosh Shilimkar2ec1fc42012-02-02 19:33:55 +053081 return 0;
82}
83
84void __init omap_barriers_init(void)
85{
86 struct map_desc dram_io_desc[1];
87
Santosh Shilimkar137d1052011-06-25 18:04:31 -070088 dram_io_desc[0].virtual = OMAP4_DRAM_BARRIER_VA;
89 dram_io_desc[0].pfn = __phys_to_pfn(paddr);
90 dram_io_desc[0].length = size;
Russell King2e2c9de2013-10-24 10:26:40 +010091 dram_io_desc[0].type = MT_MEMORY_RW_SO;
Santosh Shilimkar137d1052011-06-25 18:04:31 -070092 iotable_init(dram_io_desc, ARRAY_SIZE(dram_io_desc));
93 dram_sync = (void __iomem *) dram_io_desc[0].virtual;
94 sram_sync = (void __iomem *) OMAP4_SRAM_VA;
95
96 pr_info("OMAP4: Map 0x%08llx to 0x%08lx for dram barrier\n",
97 (long long) paddr, dram_io_desc[0].virtual);
98
Santosh Shilimkar137d1052011-06-25 18:04:31 -070099}
Santosh Shilimkar2ec1fc42012-02-02 19:33:55 +0530100#else
101void __init omap_barriers_init(void)
102{}
Santosh Shilimkar137d1052011-06-25 18:04:31 -0700103#endif
104
Santosh Shilimkarff999b82012-10-18 12:20:05 +0300105void gic_dist_disable(void)
106{
107 if (gic_dist_base_addr)
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300108 writel_relaxed(0x0, gic_dist_base_addr + GIC_DIST_CTRL);
Santosh Shilimkarff999b82012-10-18 12:20:05 +0300109}
110
Strashko, Grygorii74ed7bd2013-10-22 22:07:15 +0300111void gic_dist_enable(void)
112{
113 if (gic_dist_base_addr)
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300114 writel_relaxed(0x1, gic_dist_base_addr + GIC_DIST_CTRL);
Strashko, Grygorii74ed7bd2013-10-22 22:07:15 +0300115}
116
Colin Crosscd8ce152012-10-18 12:20:08 +0300117bool gic_dist_disabled(void)
118{
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300119 return !(readl_relaxed(gic_dist_base_addr + GIC_DIST_CTRL) & 0x1);
Colin Crosscd8ce152012-10-18 12:20:08 +0300120}
121
122void gic_timer_retrigger(void)
123{
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300124 u32 twd_int = readl_relaxed(twd_base + TWD_TIMER_INTSTAT);
125 u32 gic_int = readl_relaxed(gic_dist_base_addr + GIC_DIST_PENDING_SET);
126 u32 twd_ctrl = readl_relaxed(twd_base + TWD_TIMER_CONTROL);
Colin Crosscd8ce152012-10-18 12:20:08 +0300127
128 if (twd_int && !(gic_int & BIT(IRQ_LOCALTIMER))) {
129 /*
130 * The local timer interrupt got lost while the distributor was
131 * disabled. Ack the pending interrupt, and retrigger it.
132 */
133 pr_warn("%s: lost localtimer interrupt\n", __func__);
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300134 writel_relaxed(1, twd_base + TWD_TIMER_INTSTAT);
Colin Crosscd8ce152012-10-18 12:20:08 +0300135 if (!(twd_ctrl & TWD_TIMER_CONTROL_PERIODIC)) {
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300136 writel_relaxed(1, twd_base + TWD_TIMER_COUNTER);
Colin Crosscd8ce152012-10-18 12:20:08 +0300137 twd_ctrl |= TWD_TIMER_CONTROL_ENABLE;
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300138 writel_relaxed(twd_ctrl, twd_base + TWD_TIMER_CONTROL);
Colin Crosscd8ce152012-10-18 12:20:08 +0300139 }
140 }
141}
142
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700143#ifdef CONFIG_CACHE_L2X0
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530144
Santosh Shilimkar02afe8a2011-03-03 18:03:25 +0530145void __iomem *omap4_get_l2cache_base(void)
146{
147 return l2cache_base;
148}
149
Russell King36827ed2014-03-16 17:45:56 +0000150static void omap4_l2c310_write_sec(unsigned long val, unsigned reg)
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530151{
Russell King36827ed2014-03-16 17:45:56 +0000152 unsigned smc_op;
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530153
Russell King36827ed2014-03-16 17:45:56 +0000154 switch (reg) {
155 case L2X0_CTRL:
156 smc_op = OMAP4_MON_L2X0_CTRL_INDEX;
157 break;
158
159 case L2X0_AUX_CTRL:
160 smc_op = OMAP4_MON_L2X0_AUXCTRL_INDEX;
161 break;
162
163 case L2X0_DEBUG_CTRL:
164 smc_op = OMAP4_MON_L2X0_DBG_CTRL_INDEX;
165 break;
166
167 case L310_PREFETCH_CTRL:
168 smc_op = OMAP4_MON_L2X0_PREFETCH_INDEX;
169 break;
170
Sekhar Noriba394f02014-07-14 18:43:46 +0530171 case L310_POWER_CTRL:
172 pr_info_once("OMAP L2C310: ROM does not support power control setting\n");
173 return;
174
Russell King36827ed2014-03-16 17:45:56 +0000175 default:
176 WARN_ONCE(1, "OMAP L2C310: ignoring write to reg 0x%x\n", reg);
177 return;
178 }
179
180 omap_smc1(smc_op, val);
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700181}
182
Sekhar Norib39b14e2014-04-22 13:58:01 +0530183int __init omap_l2_cache_init(void)
Santosh Shilimkar4bdb1572011-02-22 10:00:44 +0100184{
Russell Kingcef3d922014-03-19 13:38:10 +0000185 u32 aux_ctrl;
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700186
187 /* Static mapping, never released */
188 l2cache_base = ioremap(OMAP44XX_L2CACHE_BASE, SZ_4K);
Santosh Shilimkar0db18032011-03-03 17:36:52 +0530189 if (WARN_ON(!l2cache_base))
190 return -ENOMEM;
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700191
Russell Kingcef3d922014-03-19 13:38:10 +0000192 /* 16-way associativity, parity disabled, way size - 64KB (es2.0 +) */
Sekhar Norid1964832014-04-22 13:58:02 +0530193 aux_ctrl = L2C_AUX_CTRL_SHARED_OVERRIDE |
Russell King1a5a9542014-03-16 20:52:25 +0000194 L310_AUX_CTRL_DATA_PREFETCH |
Russell King36bccb12014-03-19 12:44:41 +0000195 L310_AUX_CTRL_INSTR_PREFETCH;
Santosh Shilimkar1773e602010-11-19 23:01:03 +0530196
Russell King36827ed2014-03-16 17:45:56 +0000197 outer_cache.write_sec = omap4_l2c310_write_sec;
Santosh Shilimkar926fd452012-07-04 17:57:34 +0530198 if (of_have_populated_dt())
Sekhar Norid1964832014-04-22 13:58:02 +0530199 l2x0_of_init(aux_ctrl, 0xcf9fffff);
Santosh Shilimkar926fd452012-07-04 17:57:34 +0530200 else
Sekhar Norid1964832014-04-22 13:58:02 +0530201 l2x0_init(l2cache_base, aux_ctrl, 0xcf9fffff);
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530202
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700203 return 0;
204}
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700205#endif
Santosh Shilimkar501f0c72011-01-01 19:56:04 +0530206
207void __iomem *omap4_get_sar_ram_base(void)
208{
209 return sar_ram_base;
210}
211
212/*
213 * SAR RAM used to save and restore the HW
214 * context in low power modes
215 */
216static int __init omap4_sar_ram_init(void)
217{
Santosh Shilimkarda0e02a2013-02-06 17:54:39 +0530218 unsigned long sar_base;
219
Santosh Shilimkar501f0c72011-01-01 19:56:04 +0530220 /*
221 * To avoid code running on other OMAPs in
222 * multi-omap builds
223 */
Santosh Shilimkarda0e02a2013-02-06 17:54:39 +0530224 if (cpu_is_omap44xx())
225 sar_base = OMAP44XX_SAR_RAM_BASE;
226 else if (soc_is_omap54xx())
227 sar_base = OMAP54XX_SAR_RAM_BASE;
228 else
Santosh Shilimkar501f0c72011-01-01 19:56:04 +0530229 return -ENOMEM;
230
231 /* Static mapping, never released */
Santosh Shilimkarda0e02a2013-02-06 17:54:39 +0530232 sar_ram_base = ioremap(sar_base, SZ_16K);
Santosh Shilimkar501f0c72011-01-01 19:56:04 +0530233 if (WARN_ON(!sar_ram_base))
234 return -ENOMEM;
235
236 return 0;
237}
Tony Lindgrenb76c8b12013-01-11 11:24:18 -0800238omap_early_initcall(omap4_sar_ram_init);
Balaji T K1ee47b02012-04-25 17:27:46 +0530239
R Sricharanc4082d42012-06-05 16:31:06 +0530240void __init omap_gic_of_init(void)
241{
Santosh Shilimkarfd1c0782013-02-25 14:12:58 +0530242 struct device_node *np;
243
244 /* Extract GIC distributor and TWD bases for OMAP4460 ROM Errata WA */
245 if (!cpu_is_omap446x())
246 goto skip_errata_init;
247
248 np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
249 gic_dist_base_addr = of_iomap(np, 0);
250 WARN_ON(!gic_dist_base_addr);
251
252 np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-twd-timer");
253 twd_base = of_iomap(np, 0);
254 WARN_ON(!twd_base);
255
256skip_errata_init:
R Sricharanc4082d42012-06-05 16:31:06 +0530257 omap_wakeupgen_init();
Sricharan R5c61e612013-12-03 15:57:25 +0530258#ifdef CONFIG_IRQ_CROSSBAR
259 irqcrossbar_init();
260#endif
Rob Herring0529e3152012-11-05 16:18:28 -0600261 irqchip_init();
R Sricharanc4082d42012-06-05 16:31:06 +0530262}