blob: bc16c818c6b72e77ae276976c887b7a85647a9df [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>
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070023
Tony Lindgren741e3a82011-05-17 03:51:26 -070024#include <plat/irqs.h>
Santosh Shilimkar137d1052011-06-25 18:04:31 -070025#include <plat/sram.h>
Tony Lindgren741e3a82011-05-17 03:51:26 -070026
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070027#include <mach/hardware.h>
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +053028#include <mach/omap-wakeupgen.h>
Tony Lindgren4e653312011-11-10 22:45:17 +010029
30#include "common.h"
Santosh Shilimkar501f0c72011-01-01 19:56:04 +053031#include "omap4-sar-layout.h"
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070032
33#ifdef CONFIG_CACHE_L2X0
Santosh Shilimkar02afe8a2011-03-03 18:03:25 +053034static void __iomem *l2cache_base;
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070035#endif
36
Santosh Shilimkar501f0c72011-01-01 19:56:04 +053037static void __iomem *sar_ram_base;
38
Santosh Shilimkar137d1052011-06-25 18:04:31 -070039#ifdef CONFIG_OMAP4_ERRATA_I688
40/* Used to implement memory barrier on DRAM path */
41#define OMAP4_DRAM_BARRIER_VA 0xfe600000
42
43void __iomem *dram_sync, *sram_sync;
44
45void omap_bus_sync(void)
46{
47 if (dram_sync && sram_sync) {
48 writel_relaxed(readl_relaxed(dram_sync), dram_sync);
49 writel_relaxed(readl_relaxed(sram_sync), sram_sync);
50 isb();
51 }
52}
53
54static int __init omap_barriers_init(void)
55{
56 struct map_desc dram_io_desc[1];
57 phys_addr_t paddr;
58 u32 size;
59
60 if (!cpu_is_omap44xx())
61 return -ENODEV;
62
63 size = ALIGN(PAGE_SIZE, SZ_1M);
64 paddr = memblock_alloc(size, SZ_1M);
65 if (!paddr) {
66 pr_err("%s: failed to reserve 4 Kbytes\n", __func__);
67 return -ENOMEM;
68 }
69 memblock_free(paddr, size);
70 memblock_remove(paddr, size);
71 dram_io_desc[0].virtual = OMAP4_DRAM_BARRIER_VA;
72 dram_io_desc[0].pfn = __phys_to_pfn(paddr);
73 dram_io_desc[0].length = size;
74 dram_io_desc[0].type = MT_MEMORY_SO;
75 iotable_init(dram_io_desc, ARRAY_SIZE(dram_io_desc));
76 dram_sync = (void __iomem *) dram_io_desc[0].virtual;
77 sram_sync = (void __iomem *) OMAP4_SRAM_VA;
78
79 pr_info("OMAP4: Map 0x%08llx to 0x%08lx for dram barrier\n",
80 (long long) paddr, dram_io_desc[0].virtual);
81
82 return 0;
83}
84core_initcall(omap_barriers_init);
85#endif
86
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070087void __init gic_init_irq(void)
88{
Marc Zyngierab65be22011-11-15 17:22:45 +000089 void __iomem *omap_irq_base;
90 void __iomem *gic_dist_base_addr;
91
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070092 /* Static mapping, never released */
93 gic_dist_base_addr = ioremap(OMAP44XX_GIC_DIST_BASE, SZ_4K);
94 BUG_ON(!gic_dist_base_addr);
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -070095
96 /* Static mapping, never released */
Tony Lindgren741e3a82011-05-17 03:51:26 -070097 omap_irq_base = ioremap(OMAP44XX_GIC_CPU_BASE, SZ_512);
98 BUG_ON(!omap_irq_base);
Russell Kingb580b892010-12-04 15:55:14 +000099
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530100 omap_wakeupgen_init();
101
Tony Lindgren741e3a82011-05-17 03:51:26 -0700102 gic_init(0, 29, gic_dist_base_addr, omap_irq_base);
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700103}
104
105#ifdef CONFIG_CACHE_L2X0
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530106
Santosh Shilimkar02afe8a2011-03-03 18:03:25 +0530107void __iomem *omap4_get_l2cache_base(void)
108{
109 return l2cache_base;
110}
111
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530112static void omap4_l2x0_disable(void)
113{
114 /* Disable PL310 L2 Cache controller */
115 omap_smc1(0x102, 0x0);
116}
117
Santosh Shilimkar4bdb1572011-02-22 10:00:44 +0100118static void omap4_l2x0_set_debug(unsigned long val)
119{
120 /* Program PL310 L2 Cache controller debug register */
121 omap_smc1(0x100, val);
122}
123
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700124static int __init omap_l2_cache_init(void)
125{
Santosh Shilimkar1773e602010-11-19 23:01:03 +0530126 u32 aux_ctrl = 0;
127
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700128 /*
129 * To avoid code running on other OMAPs in
130 * multi-omap builds
131 */
132 if (!cpu_is_omap44xx())
133 return -ENODEV;
134
135 /* Static mapping, never released */
136 l2cache_base = ioremap(OMAP44XX_L2CACHE_BASE, SZ_4K);
Santosh Shilimkar0db18032011-03-03 17:36:52 +0530137 if (WARN_ON(!l2cache_base))
138 return -ENOMEM;
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700139
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700140 /*
Santosh Shilimkara777b722010-09-16 18:44:47 +0530141 * 16-way associativity, parity disabled
142 * Way size - 32KB (es1.0)
143 * Way size - 64KB (es2.0 +)
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700144 */
Santosh Shilimkar1773e602010-11-19 23:01:03 +0530145 aux_ctrl = ((1 << L2X0_AUX_CTRL_ASSOCIATIVITY_SHIFT) |
146 (0x1 << 25) |
147 (0x1 << L2X0_AUX_CTRL_NS_LOCKDOWN_SHIFT) |
148 (0x1 << L2X0_AUX_CTRL_NS_INT_CTRL_SHIFT));
149
Mans Rullgard11e02642010-11-19 23:01:04 +0530150 if (omap_rev() == OMAP4430_REV_ES1_0) {
Santosh Shilimkar1773e602010-11-19 23:01:03 +0530151 aux_ctrl |= 0x2 << L2X0_AUX_CTRL_WAY_SIZE_SHIFT;
Mans Rullgard11e02642010-11-19 23:01:04 +0530152 } else {
153 aux_ctrl |= ((0x3 << L2X0_AUX_CTRL_WAY_SIZE_SHIFT) |
Santosh Shilimkarb0f20ff2010-11-19 23:01:05 +0530154 (1 << L2X0_AUX_CTRL_SHARE_OVERRIDE_SHIFT) |
Mans Rullgard11e02642010-11-19 23:01:04 +0530155 (1 << L2X0_AUX_CTRL_DATA_PREFETCH_SHIFT) |
Santosh Shilimkarb89cd712010-11-19 23:01:06 +0530156 (1 << L2X0_AUX_CTRL_INSTR_PREFETCH_SHIFT) |
157 (1 << L2X0_AUX_CTRL_EARLY_BRESP_SHIFT));
Mans Rullgard11e02642010-11-19 23:01:04 +0530158 }
159 if (omap_rev() != OMAP4430_REV_ES1_0)
160 omap_smc1(0x109, aux_ctrl);
161
162 /* Enable PL310 L2 Cache controller */
163 omap_smc1(0x102, 0x1);
Santosh Shilimkar1773e602010-11-19 23:01:03 +0530164
165 l2x0_init(l2cache_base, aux_ctrl, L2X0_AUX_CTRL_MASK);
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700166
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530167 /*
168 * Override default outer_cache.disable with a OMAP4
169 * specific one
170 */
171 outer_cache.disable = omap4_l2x0_disable;
Santosh Shilimkar4bdb1572011-02-22 10:00:44 +0100172 outer_cache.set_debug = omap4_l2x0_set_debug;
Santosh Shilimkar4e803c42010-07-31 21:40:10 +0530173
Santosh Shilimkarfbc9be12010-05-14 12:05:26 -0700174 return 0;
175}
176early_initcall(omap_l2_cache_init);
177#endif
Santosh Shilimkar501f0c72011-01-01 19:56:04 +0530178
179void __iomem *omap4_get_sar_ram_base(void)
180{
181 return sar_ram_base;
182}
183
184/*
185 * SAR RAM used to save and restore the HW
186 * context in low power modes
187 */
188static int __init omap4_sar_ram_init(void)
189{
190 /*
191 * To avoid code running on other OMAPs in
192 * multi-omap builds
193 */
194 if (!cpu_is_omap44xx())
195 return -ENOMEM;
196
197 /* Static mapping, never released */
198 sar_ram_base = ioremap(OMAP44XX_SAR_RAM_BASE, SZ_16K);
199 if (WARN_ON(!sar_ram_base))
200 return -ENOMEM;
201
202 return 0;
203}
204early_initcall(omap4_sar_ram_init);