blob: ebc595091312f325cff5638263dd72a09de9962e [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>
17#include <linux/platform_device.h>
Santosh Shilimkar137d1052011-06-25 18:04:31 -070018#include <linux/memblock.h>
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070019
20#include <asm/hardware/gic.h>
21#include <asm/hardware/cache-l2x0.h>
Santosh Shilimkar137d1052011-06-25 18:04:31 -070022#include <asm/mach/map.h>
Russell King716a3dc2012-01-13 15:00:51 +000023#include <asm/memblock.h>
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070024
Tony Lindgren741e3a82011-05-17 03:51:26 -070025#include <plat/irqs.h>
Santosh Shilimkar137d1052011-06-25 18:04:31 -070026#include <plat/sram.h>
Santosh Shilimkar2ec1fc42012-02-02 19:33:55 +053027#include <plat/omap-secure.h>
Tony Lindgren741e3a82011-05-17 03:51:26 -070028
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070029#include <mach/hardware.h>
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +053030#include <mach/omap-wakeupgen.h>
Tony Lindgren4e653312011-11-10 22:45:17 +010031
32#include "common.h"
Santosh Shilimkar501f0c72011-01-01 19:56:04 +053033#include "omap4-sar-layout.h"
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070034
35#ifdef CONFIG_CACHE_L2X0
Santosh Shilimkar02afe8a2011-03-03 18:03:25 +053036static void __iomem *l2cache_base;
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070037#endif
38
Santosh Shilimkar501f0c72011-01-01 19:56:04 +053039static void __iomem *sar_ram_base;
40
Santosh Shilimkar137d1052011-06-25 18:04:31 -070041#ifdef CONFIG_OMAP4_ERRATA_I688
42/* Used to implement memory barrier on DRAM path */
43#define OMAP4_DRAM_BARRIER_VA 0xfe600000
44
45void __iomem *dram_sync, *sram_sync;
46
Santosh Shilimkar2ec1fc42012-02-02 19:33:55 +053047static phys_addr_t paddr;
48static u32 size;
49
Santosh Shilimkar137d1052011-06-25 18:04:31 -070050void omap_bus_sync(void)
51{
52 if (dram_sync && sram_sync) {
53 writel_relaxed(readl_relaxed(dram_sync), dram_sync);
54 writel_relaxed(readl_relaxed(sram_sync), sram_sync);
55 isb();
56 }
57}
58
Santosh Shilimkar2ec1fc42012-02-02 19:33:55 +053059/* Steal one page physical memory for barrier implementation */
60int __init omap_barrier_reserve_memblock(void)
Santosh Shilimkar137d1052011-06-25 18:04:31 -070061{
Santosh Shilimkar137d1052011-06-25 18:04:31 -070062
63 size = ALIGN(PAGE_SIZE, SZ_1M);
Russell King716a3dc2012-01-13 15:00:51 +000064 paddr = arm_memblock_steal(size, SZ_1M);
65
Santosh Shilimkar2ec1fc42012-02-02 19:33:55 +053066 return 0;
67}
68
69void __init omap_barriers_init(void)
70{
71 struct map_desc dram_io_desc[1];
72
Santosh Shilimkar137d1052011-06-25 18:04:31 -070073 dram_io_desc[0].virtual = OMAP4_DRAM_BARRIER_VA;
74 dram_io_desc[0].pfn = __phys_to_pfn(paddr);
75 dram_io_desc[0].length = size;
76 dram_io_desc[0].type = MT_MEMORY_SO;
77 iotable_init(dram_io_desc, ARRAY_SIZE(dram_io_desc));
78 dram_sync = (void __iomem *) dram_io_desc[0].virtual;
79 sram_sync = (void __iomem *) OMAP4_SRAM_VA;
80
81 pr_info("OMAP4: Map 0x%08llx to 0x%08lx for dram barrier\n",
82 (long long) paddr, dram_io_desc[0].virtual);
83
Santosh Shilimkar137d1052011-06-25 18:04:31 -070084}
Santosh Shilimkar2ec1fc42012-02-02 19:33:55 +053085#else
86void __init omap_barriers_init(void)
87{}
Santosh Shilimkar137d1052011-06-25 18:04:31 -070088#endif
89
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070090void __init gic_init_irq(void)
91{
Marc Zyngierab65be22011-11-15 17:22:45 +000092 void __iomem *omap_irq_base;
93 void __iomem *gic_dist_base_addr;
94
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070095 /* Static mapping, never released */
96 gic_dist_base_addr = ioremap(OMAP44XX_GIC_DIST_BASE, SZ_4K);
97 BUG_ON(!gic_dist_base_addr);
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070098
99 /* Static mapping, never released */
Tony Lindgren741e3a82011-05-17 03:51:26 -0700100 omap_irq_base = ioremap(OMAP44XX_GIC_CPU_BASE, SZ_512);
101 BUG_ON(!omap_irq_base);
Russell Kingb580b892010-12-04 15:55:14 +0000102
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530103 omap_wakeupgen_init();
104
Tony Lindgren741e3a82011-05-17 03:51:26 -0700105 gic_init(0, 29, gic_dist_base_addr, omap_irq_base);
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700106}
107
108#ifdef CONFIG_CACHE_L2X0
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530109
Santosh Shilimkar02afe8a2011-03-03 18:03:25 +0530110void __iomem *omap4_get_l2cache_base(void)
111{
112 return l2cache_base;
113}
114
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530115static void omap4_l2x0_disable(void)
116{
117 /* Disable PL310 L2 Cache controller */
118 omap_smc1(0x102, 0x0);
119}
120
Santosh Shilimkar4bdb1572011-02-22 10:00:44 +0100121static void omap4_l2x0_set_debug(unsigned long val)
122{
123 /* Program PL310 L2 Cache controller debug register */
124 omap_smc1(0x100, val);
125}
126
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700127static int __init omap_l2_cache_init(void)
128{
Santosh Shilimkar1773e602010-11-19 23:01:03 +0530129 u32 aux_ctrl = 0;
130
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700131 /*
132 * To avoid code running on other OMAPs in
133 * multi-omap builds
134 */
135 if (!cpu_is_omap44xx())
136 return -ENODEV;
137
138 /* Static mapping, never released */
139 l2cache_base = ioremap(OMAP44XX_L2CACHE_BASE, SZ_4K);
Santosh Shilimkar0db18032011-03-03 17:36:52 +0530140 if (WARN_ON(!l2cache_base))
141 return -ENOMEM;
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700142
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700143 /*
Santosh Shilimkara777b722010-09-16 18:44:47 +0530144 * 16-way associativity, parity disabled
145 * Way size - 32KB (es1.0)
146 * Way size - 64KB (es2.0 +)
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700147 */
Santosh Shilimkar1773e602010-11-19 23:01:03 +0530148 aux_ctrl = ((1 << L2X0_AUX_CTRL_ASSOCIATIVITY_SHIFT) |
149 (0x1 << 25) |
150 (0x1 << L2X0_AUX_CTRL_NS_LOCKDOWN_SHIFT) |
151 (0x1 << L2X0_AUX_CTRL_NS_INT_CTRL_SHIFT));
152
Mans Rullgard11e02642010-11-19 23:01:04 +0530153 if (omap_rev() == OMAP4430_REV_ES1_0) {
Santosh Shilimkar1773e602010-11-19 23:01:03 +0530154 aux_ctrl |= 0x2 << L2X0_AUX_CTRL_WAY_SIZE_SHIFT;
Mans Rullgard11e02642010-11-19 23:01:04 +0530155 } else {
156 aux_ctrl |= ((0x3 << L2X0_AUX_CTRL_WAY_SIZE_SHIFT) |
Santosh Shilimkarb0f20ff2010-11-19 23:01:05 +0530157 (1 << L2X0_AUX_CTRL_SHARE_OVERRIDE_SHIFT) |
Mans Rullgard11e02642010-11-19 23:01:04 +0530158 (1 << L2X0_AUX_CTRL_DATA_PREFETCH_SHIFT) |
Santosh Shilimkarb89cd712010-11-19 23:01:06 +0530159 (1 << L2X0_AUX_CTRL_INSTR_PREFETCH_SHIFT) |
160 (1 << L2X0_AUX_CTRL_EARLY_BRESP_SHIFT));
Mans Rullgard11e02642010-11-19 23:01:04 +0530161 }
162 if (omap_rev() != OMAP4430_REV_ES1_0)
163 omap_smc1(0x109, aux_ctrl);
164
165 /* Enable PL310 L2 Cache controller */
166 omap_smc1(0x102, 0x1);
Santosh Shilimkar1773e602010-11-19 23:01:03 +0530167
168 l2x0_init(l2cache_base, aux_ctrl, L2X0_AUX_CTRL_MASK);
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700169
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530170 /*
171 * Override default outer_cache.disable with a OMAP4
172 * specific one
173 */
174 outer_cache.disable = omap4_l2x0_disable;
Santosh Shilimkar4bdb1572011-02-22 10:00:44 +0100175 outer_cache.set_debug = omap4_l2x0_set_debug;
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530176
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700177 return 0;
178}
179early_initcall(omap_l2_cache_init);
180#endif
Santosh Shilimkar501f0c72011-01-01 19:56:04 +0530181
182void __iomem *omap4_get_sar_ram_base(void)
183{
184 return sar_ram_base;
185}
186
187/*
188 * SAR RAM used to save and restore the HW
189 * context in low power modes
190 */
191static int __init omap4_sar_ram_init(void)
192{
193 /*
194 * To avoid code running on other OMAPs in
195 * multi-omap builds
196 */
197 if (!cpu_is_omap44xx())
198 return -ENOMEM;
199
200 /* Static mapping, never released */
201 sar_ram_base = ioremap(OMAP44XX_SAR_RAM_BASE, SZ_16K);
202 if (WARN_ON(!sar_ram_base))
203 return -ENOMEM;
204
205 return 0;
206}
207early_initcall(omap4_sar_ram_init);