blob: 7e5f8877e05191c69d226d9a6a117be1b0b9da33 [file] [log] [blame]
Tony Lindgren92105bb2005-09-07 17:20:26 +01001/*
2 * linux/arch/arm/plat-omap/sram.c
3 *
4 * OMAP SRAM detection and management
5 *
6 * Copyright (C) 2005 Nokia Corporation
7 * Written by Tony Lindgren <tony@atomide.com>
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
Tony Lindgren92105bb2005-09-07 17:20:26 +010014#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17
Tony Lindgren53d9cc72006-02-08 22:06:45 +000018#include <asm/tlb.h>
Tony Lindgren92105bb2005-09-07 17:20:26 +010019#include <asm/io.h>
20#include <asm/cacheflush.h>
21
Tony Lindgren670c1042006-04-02 17:46:25 +010022#include <asm/mach/map.h>
23
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000024#include <asm/arch/sram.h>
Tony Lindgren670c1042006-04-02 17:46:25 +010025#include <asm/arch/board.h>
Tony Lindgren92105bb2005-09-07 17:20:26 +010026
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000027#define OMAP1_SRAM_PA 0x20000000
28#define OMAP1_SRAM_VA 0xd0000000
29#define OMAP2_SRAM_PA 0x40200000
Tony Lindgren670c1042006-04-02 17:46:25 +010030#define OMAP2_SRAM_PUB_PA 0x4020f800
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000031#define OMAP2_SRAM_VA 0xd0000000
Tony Lindgren670c1042006-04-02 17:46:25 +010032#define OMAP2_SRAM_PUB_VA 0xd0000800
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000033
Tony Lindgren670c1042006-04-02 17:46:25 +010034#if defined(CONFIG_ARCH_OMAP24XX)
35#define SRAM_BOOTLOADER_SZ 0x00
36#else
Tony Lindgren92105bb2005-09-07 17:20:26 +010037#define SRAM_BOOTLOADER_SZ 0x80
Tony Lindgren670c1042006-04-02 17:46:25 +010038#endif
39
40#define VA_REQINFOPERM0 IO_ADDRESS(0x68005048)
41#define VA_READPERM0 IO_ADDRESS(0x68005050)
42#define VA_WRITEPERM0 IO_ADDRESS(0x68005058)
43#define VA_CONTROL_STAT IO_ADDRESS(0x480002F8)
44#define GP_DEVICE 0x300
45#define TYPE_MASK 0x700
46
47#define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
Tony Lindgren92105bb2005-09-07 17:20:26 +010048
Tony Lindgrenc40fae952006-12-07 13:58:10 -080049static unsigned long omap_sram_start;
Tony Lindgren92105bb2005-09-07 17:20:26 +010050static unsigned long omap_sram_base;
51static unsigned long omap_sram_size;
52static unsigned long omap_sram_ceil;
53
Tony Lindgrenc40fae952006-12-07 13:58:10 -080054int omap_fb_sram_plane = -1;
55int omap_fb_sram_valid;
Tony Lindgren670c1042006-04-02 17:46:25 +010056
57/* Depending on the target RAMFS firewall setup, the public usable amount of
58 * SRAM varies. The default accessable size for all device types is 2k. A GP
59 * device allows ARM11 but not other initators for full size. This
60 * functionality seems ok until some nice security API happens.
61 */
62static int is_sram_locked(void)
63{
64 int type = 0;
65
66 if (cpu_is_omap242x())
67 type = __raw_readl(VA_CONTROL_STAT) & TYPE_MASK;
68
69 if (type == GP_DEVICE) {
70 /* RAMFW: R/W access to all initators for all qualifier sets */
71 if (cpu_is_omap242x()) {
72 __raw_writel(0xFF, VA_REQINFOPERM0); /* all q-vects */
73 __raw_writel(0xCFDE, VA_READPERM0); /* all i-read */
74 __raw_writel(0xCFDE, VA_WRITEPERM0); /* all i-write */
75 }
76 return 0;
77 } else
78 return 1; /* assume locked with no PPA or security driver */
79}
80
Tony Lindgrenc40fae952006-12-07 13:58:10 -080081static int get_fb_sram_conf(unsigned long start_avail, unsigned size_avail,
82 unsigned long *start, int *plane_idx)
Tony Lindgren670c1042006-04-02 17:46:25 +010083{
84 const struct omap_fbmem_config *fbmem_conf;
Tony Lindgrenc40fae952006-12-07 13:58:10 -080085 unsigned long size = 0;
86 int i;
Tony Lindgren670c1042006-04-02 17:46:25 +010087
Tony Lindgrenc40fae952006-12-07 13:58:10 -080088 i = 0;
89 *start = 0;
90 *plane_idx = -1;
91 while ((fbmem_conf = omap_get_nr_config(OMAP_TAG_FBMEM,
92 struct omap_fbmem_config, i)) != NULL) {
93 u32 paddr, end;
94
95 paddr = fbmem_conf->start;
96 end = fbmem_conf->start + fbmem_conf->size;
97 if (paddr > omap_sram_start &&
98 paddr < omap_sram_start + omap_sram_size) {
99 if (*plane_idx != -1 || paddr < start_avail ||
100 paddr == end ||
101 end > start_avail + size_avail) {
102 printk(KERN_ERR "invalid FB SRAM configuration");
103 *start = 0;
104 return -1;
105 }
106 *plane_idx = i;
107 *start = fbmem_conf->start;
108 size = fbmem_conf->size;
109 }
110 i++;
Tony Lindgren670c1042006-04-02 17:46:25 +0100111 }
112
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800113 if (*plane_idx >= 0)
114 pr_info("Reserving %lu bytes SRAM frame buffer "
115 "for plane %d\n", size, *plane_idx);
Tony Lindgren670c1042006-04-02 17:46:25 +0100116
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800117 return 0;
Tony Lindgren670c1042006-04-02 17:46:25 +0100118}
119
Tony Lindgren92105bb2005-09-07 17:20:26 +0100120/*
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000121 * The amount of SRAM depends on the core type.
Tony Lindgren92105bb2005-09-07 17:20:26 +0100122 * Note that we cannot try to test for SRAM here because writes
123 * to secure SRAM will hang the system. Also the SRAM is not
124 * yet mapped at this point.
125 */
126void __init omap_detect_sram(void)
127{
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800128 unsigned long fb_sram_start;
Tony Lindgren670c1042006-04-02 17:46:25 +0100129
130 if (cpu_is_omap24xx()) {
131 if (is_sram_locked()) {
132 omap_sram_base = OMAP2_SRAM_PUB_VA;
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800133 omap_sram_start = OMAP2_SRAM_PUB_PA;
Tony Lindgren670c1042006-04-02 17:46:25 +0100134 omap_sram_size = 0x800; /* 2K */
135 } else {
136 omap_sram_base = OMAP2_SRAM_VA;
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800137 omap_sram_start = OMAP2_SRAM_PA;
Tony Lindgren670c1042006-04-02 17:46:25 +0100138 if (cpu_is_omap242x())
139 omap_sram_size = 0xa0000; /* 640K */
140 else if (cpu_is_omap243x())
141 omap_sram_size = 0x10000; /* 64K */
142 }
143 } else {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000144 omap_sram_base = OMAP1_SRAM_VA;
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800145 omap_sram_start = OMAP1_SRAM_PA;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100146
Tony Lindgren670c1042006-04-02 17:46:25 +0100147 if (cpu_is_omap730())
148 omap_sram_size = 0x32000; /* 200K */
149 else if (cpu_is_omap15xx())
150 omap_sram_size = 0x30000; /* 192K */
151 else if (cpu_is_omap1610() || cpu_is_omap1621() ||
152 cpu_is_omap1710())
153 omap_sram_size = 0x4000; /* 16K */
154 else if (cpu_is_omap1611())
155 omap_sram_size = 0x3e800; /* 250K */
156 else {
157 printk(KERN_ERR "Could not detect SRAM size\n");
158 omap_sram_size = 0x4000;
159 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100160 }
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800161 if (get_fb_sram_conf(omap_sram_start + SRAM_BOOTLOADER_SZ,
162 omap_sram_size - SRAM_BOOTLOADER_SZ,
163 &fb_sram_start, &omap_fb_sram_plane) == 0)
164 omap_fb_sram_valid = 1;
165 if (omap_fb_sram_valid && omap_fb_sram_plane >= 0)
166 omap_sram_size -= omap_sram_start + omap_sram_size -
167 fb_sram_start;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100168 omap_sram_ceil = omap_sram_base + omap_sram_size;
169}
170
171static struct map_desc omap_sram_io_desc[] __initdata = {
Deepak Saxena9fe133b2005-10-28 15:19:00 +0100172 { /* .length gets filled in at runtime */
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000173 .virtual = OMAP1_SRAM_VA,
174 .pfn = __phys_to_pfn(OMAP1_SRAM_PA),
Tony Lindgrence2deca2006-06-26 16:16:24 -0700175 .type = MT_MEMORY
Deepak Saxena9fe133b2005-10-28 15:19:00 +0100176 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100177};
178
179/*
Tony Lindgrence2deca2006-06-26 16:16:24 -0700180 * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
Tony Lindgren92105bb2005-09-07 17:20:26 +0100181 */
182void __init omap_map_sram(void)
183{
Tony Lindgren670c1042006-04-02 17:46:25 +0100184 unsigned long base;
185
Tony Lindgren92105bb2005-09-07 17:20:26 +0100186 if (omap_sram_size == 0)
187 return;
188
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000189 if (cpu_is_omap24xx()) {
190 omap_sram_io_desc[0].virtual = OMAP2_SRAM_VA;
Tony Lindgren670c1042006-04-02 17:46:25 +0100191
Kevin Hilmand1284b52006-09-25 12:41:24 +0300192 base = OMAP2_SRAM_PA;
Tony Lindgren670c1042006-04-02 17:46:25 +0100193 base = ROUND_DOWN(base, PAGE_SIZE);
194 omap_sram_io_desc[0].pfn = __phys_to_pfn(base);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000195 }
196
Tony Lindgrence2deca2006-06-26 16:16:24 -0700197 omap_sram_io_desc[0].length = 1024 * 1024; /* Use section desc */
Tony Lindgren92105bb2005-09-07 17:20:26 +0100198 iotable_init(omap_sram_io_desc, ARRAY_SIZE(omap_sram_io_desc));
199
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000200 printk(KERN_INFO "SRAM: Mapped pa 0x%08lx to va 0x%08lx size: 0x%lx\n",
Tony Lindgren670c1042006-04-02 17:46:25 +0100201 __pfn_to_phys(omap_sram_io_desc[0].pfn),
202 omap_sram_io_desc[0].virtual,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000203 omap_sram_io_desc[0].length);
204
Tony Lindgren92105bb2005-09-07 17:20:26 +0100205 /*
Tony Lindgren53d9cc72006-02-08 22:06:45 +0000206 * Normally devicemaps_init() would flush caches and tlb after
207 * mdesc->map_io(), but since we're called from map_io(), we
208 * must do it here.
209 */
210 local_flush_tlb_all();
211 flush_cache_all();
212
213 /*
Tony Lindgren92105bb2005-09-07 17:20:26 +0100214 * Looks like we need to preserve some bootloader code at the
215 * beginning of SRAM for jumping to flash for reboot to work...
216 */
217 memset((void *)omap_sram_base + SRAM_BOOTLOADER_SZ, 0,
218 omap_sram_size - SRAM_BOOTLOADER_SZ);
219}
220
Tony Lindgren92105bb2005-09-07 17:20:26 +0100221void * omap_sram_push(void * start, unsigned long size)
222{
223 if (size > (omap_sram_ceil - (omap_sram_base + SRAM_BOOTLOADER_SZ))) {
224 printk(KERN_ERR "Not enough space in SRAM\n");
225 return NULL;
226 }
Tony Lindgren670c1042006-04-02 17:46:25 +0100227
Tony Lindgren92105bb2005-09-07 17:20:26 +0100228 omap_sram_ceil -= size;
Tony Lindgren670c1042006-04-02 17:46:25 +0100229 omap_sram_ceil = ROUND_DOWN(omap_sram_ceil, sizeof(void *));
Tony Lindgren92105bb2005-09-07 17:20:26 +0100230 memcpy((void *)omap_sram_ceil, start, size);
231
232 return (void *)omap_sram_ceil;
233}
234
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000235static void omap_sram_error(void)
236{
237 panic("Uninitialized SRAM function\n");
238}
239
240#ifdef CONFIG_ARCH_OMAP1
241
242static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl);
243
244void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
245{
246 if (!_omap_sram_reprogram_clock)
247 omap_sram_error();
248
249 return _omap_sram_reprogram_clock(dpllctl, ckctl);
250}
251
252int __init omap1_sram_init(void)
253{
254 _omap_sram_reprogram_clock = omap_sram_push(sram_reprogram_clock,
255 sram_reprogram_clock_sz);
256
257 return 0;
258}
259
260#else
261#define omap1_sram_init() do {} while (0)
262#endif
263
264#ifdef CONFIG_ARCH_OMAP2
265
266static void (*_omap2_sram_ddr_init)(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
267 u32 base_cs, u32 force_unlock);
268
269void omap2_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
270 u32 base_cs, u32 force_unlock)
271{
272 if (!_omap2_sram_ddr_init)
273 omap_sram_error();
274
275 return _omap2_sram_ddr_init(slow_dll_ctrl, fast_dll_ctrl,
276 base_cs, force_unlock);
277}
278
279static void (*_omap2_sram_reprogram_sdrc)(u32 perf_level, u32 dll_val,
280 u32 mem_type);
281
282void omap2_sram_reprogram_sdrc(u32 perf_level, u32 dll_val, u32 mem_type)
283{
284 if (!_omap2_sram_reprogram_sdrc)
285 omap_sram_error();
286
287 return _omap2_sram_reprogram_sdrc(perf_level, dll_val, mem_type);
288}
289
290static u32 (*_omap2_set_prcm)(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
291
292u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass)
293{
294 if (!_omap2_set_prcm)
295 omap_sram_error();
296
297 return _omap2_set_prcm(dpll_ctrl_val, sdrc_rfr_val, bypass);
298}
299
300int __init omap2_sram_init(void)
301{
302 _omap2_sram_ddr_init = omap_sram_push(sram_ddr_init, sram_ddr_init_sz);
303
304 _omap2_sram_reprogram_sdrc = omap_sram_push(sram_reprogram_sdrc,
305 sram_reprogram_sdrc_sz);
306 _omap2_set_prcm = omap_sram_push(sram_set_prcm, sram_set_prcm_sz);
307
308 return 0;
309}
310#else
311#define omap2_sram_init() do {} while (0)
312#endif
313
314int __init omap_sram_init(void)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100315{
316 omap_detect_sram();
317 omap_map_sram();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000318
319 if (!cpu_is_omap24xx())
320 omap1_sram_init();
321 else
322 omap2_sram_init();
323
324 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100325}