Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 1 | /* |
| 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 Cross | cd8ce15 | 2012-10-18 12:20:08 +0300 | [diff] [blame] | 17 | #include <linux/irq.h> |
Rob Herring | 0529e315 | 2012-11-05 16:18:28 -0600 | [diff] [blame] | 18 | #include <linux/irqchip.h> |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 20 | #include <linux/memblock.h> |
Tony Lindgren | 7d7e1eb | 2012-08-27 17:43:01 -0700 | [diff] [blame] | 21 | #include <linux/of_irq.h> |
| 22 | #include <linux/of_platform.h> |
| 23 | #include <linux/export.h> |
Rob Herring | 520f7bd | 2012-12-27 13:10:24 -0600 | [diff] [blame] | 24 | #include <linux/irqchip/arm-gic.h> |
Sricharan R | 5c61e61 | 2013-12-03 15:57:25 +0530 | [diff] [blame] | 25 | #include <linux/irqchip/irq-crossbar.h> |
Santosh Shilimkar | fd1c078 | 2013-02-25 14:12:58 +0530 | [diff] [blame] | 26 | #include <linux/of_address.h> |
Robin Holt | 7b6d864 | 2013-07-08 16:01:40 -0700 | [diff] [blame] | 27 | #include <linux/reboot.h> |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 28 | |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 29 | #include <asm/hardware/cache-l2x0.h> |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 30 | #include <asm/mach/map.h> |
Russell King | 716a3dc | 2012-01-13 15:00:51 +0000 | [diff] [blame] | 31 | #include <asm/memblock.h> |
Colin Cross | cd8ce15 | 2012-10-18 12:20:08 +0300 | [diff] [blame] | 32 | #include <asm/smp_twd.h> |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 33 | |
Tony Lindgren | 732231a | 2012-09-20 11:41:16 -0700 | [diff] [blame] | 34 | #include "omap-wakeupgen.h" |
Tony Lindgren | dbc0416 | 2012-08-31 10:59:07 -0700 | [diff] [blame] | 35 | #include "soc.h" |
Paul Walmsley | b6a4226 | 2012-10-29 20:50:21 -0600 | [diff] [blame] | 36 | #include "iomap.h" |
Tony Lindgren | 4e65331 | 2011-11-10 22:45:17 +0100 | [diff] [blame] | 37 | #include "common.h" |
Tony Lindgren | 68f39e7 | 2012-10-15 12:09:43 -0700 | [diff] [blame] | 38 | #include "mmc.h" |
Paul Walmsley | 2f334a3 | 2012-10-29 20:56:07 -0600 | [diff] [blame] | 39 | #include "prminst44xx.h" |
Paul Walmsley | d9a16f9 | 2012-10-29 20:57:39 -0600 | [diff] [blame] | 40 | #include "prcm_mpu44xx.h" |
Santosh Shilimkar | 501f0c7 | 2011-01-01 19:56:04 +0530 | [diff] [blame] | 41 | #include "omap4-sar-layout.h" |
Lokesh Vutla | f7a9b8a | 2012-10-02 00:17:06 +0530 | [diff] [blame] | 42 | #include "omap-secure.h" |
Tony Lindgren | bb77209 | 2012-10-29 09:35:35 -0700 | [diff] [blame] | 43 | #include "sram.h" |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 44 | |
| 45 | #ifdef CONFIG_CACHE_L2X0 |
Santosh Shilimkar | 02afe8a | 2011-03-03 18:03:25 +0530 | [diff] [blame] | 46 | static void __iomem *l2cache_base; |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 47 | #endif |
| 48 | |
Santosh Shilimkar | 501f0c7 | 2011-01-01 19:56:04 +0530 | [diff] [blame] | 49 | static void __iomem *sar_ram_base; |
Santosh Shilimkar | ff999b8 | 2012-10-18 12:20:05 +0300 | [diff] [blame] | 50 | static void __iomem *gic_dist_base_addr; |
Colin Cross | cd8ce15 | 2012-10-18 12:20:08 +0300 | [diff] [blame] | 51 | static void __iomem *twd_base; |
| 52 | |
| 53 | #define IRQ_LOCALTIMER 29 |
Santosh Shilimkar | 501f0c7 | 2011-01-01 19:56:04 +0530 | [diff] [blame] | 54 | |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 55 | #ifdef CONFIG_OMAP4_ERRATA_I688 |
| 56 | /* Used to implement memory barrier on DRAM path */ |
| 57 | #define OMAP4_DRAM_BARRIER_VA 0xfe600000 |
| 58 | |
| 59 | void __iomem *dram_sync, *sram_sync; |
| 60 | |
Santosh Shilimkar | 2ec1fc4 | 2012-02-02 19:33:55 +0530 | [diff] [blame] | 61 | static phys_addr_t paddr; |
| 62 | static u32 size; |
| 63 | |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 64 | void 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 Sricharan | cc4ad90 | 2012-03-02 16:31:18 +0530 | [diff] [blame] | 72 | EXPORT_SYMBOL(omap_bus_sync); |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 73 | |
Santosh Shilimkar | 2ec1fc4 | 2012-02-02 19:33:55 +0530 | [diff] [blame] | 74 | /* Steal one page physical memory for barrier implementation */ |
| 75 | int __init omap_barrier_reserve_memblock(void) |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 76 | { |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 77 | |
| 78 | size = ALIGN(PAGE_SIZE, SZ_1M); |
Russell King | 716a3dc | 2012-01-13 15:00:51 +0000 | [diff] [blame] | 79 | paddr = arm_memblock_steal(size, SZ_1M); |
| 80 | |
Santosh Shilimkar | 2ec1fc4 | 2012-02-02 19:33:55 +0530 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | void __init omap_barriers_init(void) |
| 85 | { |
| 86 | struct map_desc dram_io_desc[1]; |
| 87 | |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 88 | 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 King | 2e2c9de | 2013-10-24 10:26:40 +0100 | [diff] [blame] | 91 | dram_io_desc[0].type = MT_MEMORY_RW_SO; |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 92 | 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 Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 99 | } |
Santosh Shilimkar | 2ec1fc4 | 2012-02-02 19:33:55 +0530 | [diff] [blame] | 100 | #else |
| 101 | void __init omap_barriers_init(void) |
| 102 | {} |
Santosh Shilimkar | 137d105 | 2011-06-25 18:04:31 -0700 | [diff] [blame] | 103 | #endif |
| 104 | |
Santosh Shilimkar | ff999b8 | 2012-10-18 12:20:05 +0300 | [diff] [blame] | 105 | void gic_dist_disable(void) |
| 106 | { |
| 107 | if (gic_dist_base_addr) |
Victor Kamensky | edfaf05 | 2014-04-15 20:37:46 +0300 | [diff] [blame] | 108 | writel_relaxed(0x0, gic_dist_base_addr + GIC_DIST_CTRL); |
Santosh Shilimkar | ff999b8 | 2012-10-18 12:20:05 +0300 | [diff] [blame] | 109 | } |
| 110 | |
Strashko, Grygorii | 74ed7bd | 2013-10-22 22:07:15 +0300 | [diff] [blame] | 111 | void gic_dist_enable(void) |
| 112 | { |
| 113 | if (gic_dist_base_addr) |
Victor Kamensky | edfaf05 | 2014-04-15 20:37:46 +0300 | [diff] [blame] | 114 | writel_relaxed(0x1, gic_dist_base_addr + GIC_DIST_CTRL); |
Strashko, Grygorii | 74ed7bd | 2013-10-22 22:07:15 +0300 | [diff] [blame] | 115 | } |
| 116 | |
Colin Cross | cd8ce15 | 2012-10-18 12:20:08 +0300 | [diff] [blame] | 117 | bool gic_dist_disabled(void) |
| 118 | { |
Victor Kamensky | edfaf05 | 2014-04-15 20:37:46 +0300 | [diff] [blame] | 119 | return !(readl_relaxed(gic_dist_base_addr + GIC_DIST_CTRL) & 0x1); |
Colin Cross | cd8ce15 | 2012-10-18 12:20:08 +0300 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | void gic_timer_retrigger(void) |
| 123 | { |
Victor Kamensky | edfaf05 | 2014-04-15 20:37:46 +0300 | [diff] [blame] | 124 | 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 Cross | cd8ce15 | 2012-10-18 12:20:08 +0300 | [diff] [blame] | 127 | |
| 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 Kamensky | edfaf05 | 2014-04-15 20:37:46 +0300 | [diff] [blame] | 134 | writel_relaxed(1, twd_base + TWD_TIMER_INTSTAT); |
Colin Cross | cd8ce15 | 2012-10-18 12:20:08 +0300 | [diff] [blame] | 135 | if (!(twd_ctrl & TWD_TIMER_CONTROL_PERIODIC)) { |
Victor Kamensky | edfaf05 | 2014-04-15 20:37:46 +0300 | [diff] [blame] | 136 | writel_relaxed(1, twd_base + TWD_TIMER_COUNTER); |
Colin Cross | cd8ce15 | 2012-10-18 12:20:08 +0300 | [diff] [blame] | 137 | twd_ctrl |= TWD_TIMER_CONTROL_ENABLE; |
Victor Kamensky | edfaf05 | 2014-04-15 20:37:46 +0300 | [diff] [blame] | 138 | writel_relaxed(twd_ctrl, twd_base + TWD_TIMER_CONTROL); |
Colin Cross | cd8ce15 | 2012-10-18 12:20:08 +0300 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 143 | #ifdef CONFIG_CACHE_L2X0 |
Santosh Shilimkar | 4e803c4 | 2010-07-31 21:40:10 +0530 | [diff] [blame] | 144 | |
Santosh Shilimkar | 02afe8a | 2011-03-03 18:03:25 +0530 | [diff] [blame] | 145 | void __iomem *omap4_get_l2cache_base(void) |
| 146 | { |
| 147 | return l2cache_base; |
| 148 | } |
| 149 | |
Russell King | 36827ed | 2014-03-16 17:45:56 +0000 | [diff] [blame] | 150 | static void omap4_l2c310_write_sec(unsigned long val, unsigned reg) |
Santosh Shilimkar | 4e803c4 | 2010-07-31 21:40:10 +0530 | [diff] [blame] | 151 | { |
Russell King | 36827ed | 2014-03-16 17:45:56 +0000 | [diff] [blame] | 152 | unsigned smc_op; |
Santosh Shilimkar | 4e803c4 | 2010-07-31 21:40:10 +0530 | [diff] [blame] | 153 | |
Russell King | 36827ed | 2014-03-16 17:45:56 +0000 | [diff] [blame] | 154 | 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 Nori | ba394f0 | 2014-07-14 18:43:46 +0530 | [diff] [blame] | 171 | case L310_POWER_CTRL: |
| 172 | pr_info_once("OMAP L2C310: ROM does not support power control setting\n"); |
| 173 | return; |
| 174 | |
Russell King | 36827ed | 2014-03-16 17:45:56 +0000 | [diff] [blame] | 175 | 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 Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Sekhar Nori | b39b14e | 2014-04-22 13:58:01 +0530 | [diff] [blame] | 183 | int __init omap_l2_cache_init(void) |
Santosh Shilimkar | 4bdb157 | 2011-02-22 10:00:44 +0100 | [diff] [blame] | 184 | { |
Russell King | cef3d92 | 2014-03-19 13:38:10 +0000 | [diff] [blame] | 185 | u32 aux_ctrl; |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 186 | |
| 187 | /* Static mapping, never released */ |
| 188 | l2cache_base = ioremap(OMAP44XX_L2CACHE_BASE, SZ_4K); |
Santosh Shilimkar | 0db1803 | 2011-03-03 17:36:52 +0530 | [diff] [blame] | 189 | if (WARN_ON(!l2cache_base)) |
| 190 | return -ENOMEM; |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 191 | |
Russell King | cef3d92 | 2014-03-19 13:38:10 +0000 | [diff] [blame] | 192 | /* 16-way associativity, parity disabled, way size - 64KB (es2.0 +) */ |
Sekhar Nori | d196483 | 2014-04-22 13:58:02 +0530 | [diff] [blame] | 193 | aux_ctrl = L2C_AUX_CTRL_SHARED_OVERRIDE | |
Russell King | 1a5a954 | 2014-03-16 20:52:25 +0000 | [diff] [blame] | 194 | L310_AUX_CTRL_DATA_PREFETCH | |
Russell King | 36bccb1 | 2014-03-19 12:44:41 +0000 | [diff] [blame] | 195 | L310_AUX_CTRL_INSTR_PREFETCH; |
Santosh Shilimkar | 1773e60 | 2010-11-19 23:01:03 +0530 | [diff] [blame] | 196 | |
Russell King | 36827ed | 2014-03-16 17:45:56 +0000 | [diff] [blame] | 197 | outer_cache.write_sec = omap4_l2c310_write_sec; |
Santosh Shilimkar | 926fd45 | 2012-07-04 17:57:34 +0530 | [diff] [blame] | 198 | if (of_have_populated_dt()) |
Sekhar Nori | d196483 | 2014-04-22 13:58:02 +0530 | [diff] [blame] | 199 | l2x0_of_init(aux_ctrl, 0xcf9fffff); |
Santosh Shilimkar | 926fd45 | 2012-07-04 17:57:34 +0530 | [diff] [blame] | 200 | else |
Sekhar Nori | d196483 | 2014-04-22 13:58:02 +0530 | [diff] [blame] | 201 | l2x0_init(l2cache_base, aux_ctrl, 0xcf9fffff); |
Santosh Shilimkar | 4e803c4 | 2010-07-31 21:40:10 +0530 | [diff] [blame] | 202 | |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 203 | return 0; |
| 204 | } |
Santosh Shilimkar | fbc9be1 | 2010-05-14 12:05:26 -0700 | [diff] [blame] | 205 | #endif |
Santosh Shilimkar | 501f0c7 | 2011-01-01 19:56:04 +0530 | [diff] [blame] | 206 | |
| 207 | void __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 | */ |
| 216 | static int __init omap4_sar_ram_init(void) |
| 217 | { |
Santosh Shilimkar | da0e02a | 2013-02-06 17:54:39 +0530 | [diff] [blame] | 218 | unsigned long sar_base; |
| 219 | |
Santosh Shilimkar | 501f0c7 | 2011-01-01 19:56:04 +0530 | [diff] [blame] | 220 | /* |
| 221 | * To avoid code running on other OMAPs in |
| 222 | * multi-omap builds |
| 223 | */ |
Santosh Shilimkar | da0e02a | 2013-02-06 17:54:39 +0530 | [diff] [blame] | 224 | 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 Shilimkar | 501f0c7 | 2011-01-01 19:56:04 +0530 | [diff] [blame] | 229 | return -ENOMEM; |
| 230 | |
| 231 | /* Static mapping, never released */ |
Santosh Shilimkar | da0e02a | 2013-02-06 17:54:39 +0530 | [diff] [blame] | 232 | sar_ram_base = ioremap(sar_base, SZ_16K); |
Santosh Shilimkar | 501f0c7 | 2011-01-01 19:56:04 +0530 | [diff] [blame] | 233 | if (WARN_ON(!sar_ram_base)) |
| 234 | return -ENOMEM; |
| 235 | |
| 236 | return 0; |
| 237 | } |
Tony Lindgren | b76c8b1 | 2013-01-11 11:24:18 -0800 | [diff] [blame] | 238 | omap_early_initcall(omap4_sar_ram_init); |
Balaji T K | 1ee47b0 | 2012-04-25 17:27:46 +0530 | [diff] [blame] | 239 | |
R Sricharan | c4082d4 | 2012-06-05 16:31:06 +0530 | [diff] [blame] | 240 | void __init omap_gic_of_init(void) |
| 241 | { |
Santosh Shilimkar | fd1c078 | 2013-02-25 14:12:58 +0530 | [diff] [blame] | 242 | 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 | |
| 256 | skip_errata_init: |
R Sricharan | c4082d4 | 2012-06-05 16:31:06 +0530 | [diff] [blame] | 257 | omap_wakeupgen_init(); |
Sricharan R | 5c61e61 | 2013-12-03 15:57:25 +0530 | [diff] [blame] | 258 | #ifdef CONFIG_IRQ_CROSSBAR |
| 259 | irqcrossbar_init(); |
| 260 | #endif |
Rob Herring | 0529e315 | 2012-11-05 16:18:28 -0600 | [diff] [blame] | 261 | irqchip_init(); |
R Sricharan | c4082d4 | 2012-06-05 16:31:06 +0530 | [diff] [blame] | 262 | } |