2 * linux/arch/arm/plat-omap/sram.c
4 * OMAP SRAM detection and management
6 * Copyright (C) 2005 Nokia Corporation
7 * Written by Tony Lindgren <tony@atomide.com>
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.
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
21 #include <asm/cacheflush.h>
23 #include <asm/mach/map.h>
25 #include <asm/arch/sram.h>
26 #include <asm/arch/board.h>
28 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
29 # include "../mach-omap2/prm.h"
30 # include "../mach-omap2/cm.h"
31 # include "../mach-omap2/sdrc.h"
34 #define OMAP1_SRAM_PA 0x20000000
35 #define OMAP1_SRAM_VA 0xd0000000
36 #define OMAP2_SRAM_PA 0x40200000
37 #define OMAP2_SRAM_PUB_PA 0x4020f800
38 #define OMAP2_SRAM_VA 0xd0000000
39 #define OMAP2_SRAM_PUB_VA 0xd0000800
41 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
42 #define SRAM_BOOTLOADER_SZ 0x00
44 #define SRAM_BOOTLOADER_SZ 0x80
47 #define VA_REQINFOPERM0 IO_ADDRESS(0x68005048)
48 #define VA_READPERM0 IO_ADDRESS(0x68005050)
49 #define VA_WRITEPERM0 IO_ADDRESS(0x68005058)
50 #define VA_CONTROL_STAT IO_ADDRESS(0x480002F8)
51 #define GP_DEVICE 0x300
52 #define TYPE_MASK 0x700
54 #define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
56 static unsigned long omap_sram_start;
57 static unsigned long omap_sram_base;
58 static unsigned long omap_sram_size;
59 static unsigned long omap_sram_ceil;
61 extern unsigned long omapfb_reserve_sram(unsigned long sram_pstart,
62 unsigned long sram_vstart,
63 unsigned long sram_size,
64 unsigned long pstart_avail,
65 unsigned long size_avail);
67 /* Global symbols in sram-fn.S to be patched with omap_sram_patch_va() */
68 extern void *omap2_sdi_cm_clksel2_pll;
69 extern void *omap2_sdi_sdrc_dlla_ctrl;
70 extern void *omap2_sdi_prcm_voltctrl;
71 extern void *omap2_sdi_timer_32ksynct_cr;
72 extern void *omap2_srs_cm_clksel2_pll;
73 extern void *omap2_srs_sdrc_dlla_ctrl;
74 extern void *omap2_srs_sdrc_rfr_ctrl;
75 extern void *omap2_srs_prcm_voltctrl;
76 extern void *omap2_srs_timer_32ksynct;
77 extern void *omap2_ssp_set_config;
78 extern void *omap2_ssp_pll_ctl;
79 extern void *omap2_ssp_pll_stat;
80 extern void *omap2_ssp_pll_div;
81 extern void *omap2_ssp_sdrc_rfr;
82 extern void *omap2_ssp_dlla_ctrl;
86 * Depending on the target RAMFS firewall setup, the public usable amount of
87 * SRAM varies. The default accessible size for all device types is 2k. A GP
88 * device allows ARM11 but not other initiators for full size. This
89 * functionality seems ok until some nice security API happens.
91 static int is_sram_locked(void)
95 if (cpu_is_omap242x())
96 type = __raw_readl(VA_CONTROL_STAT) & TYPE_MASK;
98 if (type == GP_DEVICE) {
99 /* RAMFW: R/W access to all initiators for all qualifier sets */
100 if (cpu_is_omap242x()) {
101 __raw_writel(0xFF, VA_REQINFOPERM0); /* all q-vects */
102 __raw_writel(0xCFDE, VA_READPERM0); /* all i-read */
103 __raw_writel(0xCFDE, VA_WRITEPERM0); /* all i-write */
107 return 1; /* assume locked with no PPA or security driver */
111 * The amount of SRAM depends on the core type.
112 * Note that we cannot try to test for SRAM here because writes
113 * to secure SRAM will hang the system. Also the SRAM is not
114 * yet mapped at this point.
116 void __init omap_detect_sram(void)
118 unsigned long reserved;
120 if (cpu_class_is_omap2()) {
121 if (is_sram_locked()) {
122 omap_sram_base = OMAP2_SRAM_PUB_VA;
123 omap_sram_start = OMAP2_SRAM_PUB_PA;
124 omap_sram_size = 0x800; /* 2K */
126 omap_sram_base = OMAP2_SRAM_VA;
127 omap_sram_start = OMAP2_SRAM_PA;
128 if (cpu_is_omap242x())
129 omap_sram_size = 0xa0000; /* 640K */
130 else if (cpu_is_omap243x() || cpu_is_omap34xx())
131 omap_sram_size = 0x10000; /* 64K */
134 omap_sram_base = OMAP1_SRAM_VA;
135 omap_sram_start = OMAP1_SRAM_PA;
137 if (cpu_is_omap730())
138 omap_sram_size = 0x32000; /* 200K */
139 else if (cpu_is_omap15xx())
140 omap_sram_size = 0x30000; /* 192K */
141 else if (cpu_is_omap1610() || cpu_is_omap1621() ||
143 omap_sram_size = 0x4000; /* 16K */
144 else if (cpu_is_omap1611())
145 omap_sram_size = 0x3e800; /* 250K */
147 printk(KERN_ERR "Could not detect SRAM size\n");
148 omap_sram_size = 0x4000;
151 reserved = omapfb_reserve_sram(omap_sram_start, omap_sram_base,
153 omap_sram_start + SRAM_BOOTLOADER_SZ,
154 omap_sram_size - SRAM_BOOTLOADER_SZ);
155 omap_sram_size -= reserved;
156 omap_sram_ceil = omap_sram_base + omap_sram_size;
159 static struct map_desc omap_sram_io_desc[] __initdata = {
160 { /* .length gets filled in at runtime */
161 .virtual = OMAP1_SRAM_VA,
162 .pfn = __phys_to_pfn(OMAP1_SRAM_PA),
168 * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
170 void __init omap_map_sram(void)
174 if (omap_sram_size == 0)
177 if (cpu_class_is_omap2()) {
178 omap_sram_io_desc[0].virtual = OMAP2_SRAM_VA;
180 base = OMAP2_SRAM_PA;
181 base = ROUND_DOWN(base, PAGE_SIZE);
182 omap_sram_io_desc[0].pfn = __phys_to_pfn(base);
185 omap_sram_io_desc[0].length = 1024 * 1024; /* Use section desc */
186 iotable_init(omap_sram_io_desc, ARRAY_SIZE(omap_sram_io_desc));
188 printk(KERN_INFO "SRAM: Mapped pa 0x%08lx to va 0x%08lx size: 0x%lx\n",
189 __pfn_to_phys(omap_sram_io_desc[0].pfn),
190 omap_sram_io_desc[0].virtual,
191 omap_sram_io_desc[0].length);
194 * Normally devicemaps_init() would flush caches and tlb after
195 * mdesc->map_io(), but since we're called from map_io(), we
198 local_flush_tlb_all();
202 * Looks like we need to preserve some bootloader code at the
203 * beginning of SRAM for jumping to flash for reboot to work...
205 memset((void *)omap_sram_base + SRAM_BOOTLOADER_SZ, 0,
206 omap_sram_size - SRAM_BOOTLOADER_SZ);
209 void * omap_sram_push(void * start, unsigned long size)
211 if (size > (omap_sram_ceil - (omap_sram_base + SRAM_BOOTLOADER_SZ))) {
212 printk(KERN_ERR "Not enough space in SRAM\n");
216 omap_sram_ceil -= size;
217 omap_sram_ceil = ROUND_DOWN(omap_sram_ceil, sizeof(void *));
218 memcpy((void *)omap_sram_ceil, start, size);
220 return (void *)omap_sram_ceil;
224 * omap_sram_patch_va - patch a virtual address into SRAM code
225 * @srcfn: original start address (in DRAM) of function to patch
226 * @srcd: original address (in DRAM) of location to patch
227 * @sramfn: start address (in SRAM) of function to patch
228 * @d: virtual address to insert
230 * Replace a location in SRAM containing a magic number
231 * (SRAM_VA_MAGIC) with a caller-specified virtual address. Used to
232 * dynamically patch SRAM code at runtime for multiboot, since some
233 * register addresses change depending on the OMAP chip in use.
234 * Returns 1 upon success, 0 upon failure.
236 int omap_sram_patch_va(void *srcfn, void *srcd, void *sramfn, void __iomem *d)
238 unsigned long sram_addr;
241 offs = (unsigned long)srcd - (unsigned long)srcfn;
242 sram_addr = (unsigned long)sramfn + offs;
244 #ifdef CONFIG_OMAP_DEBUG_SRAM_PATCH
246 printk(KERN_ERR "sram: patch address 0x%0lx < function start "
247 "address 0x%0lx\n", (unsigned long)srcd,
248 (unsigned long)srcfn);
254 * REVISIT: We should probably pass in the function's size also,
255 * so we can verify that the address to patch exists within
258 if (sram_addr > omap_sram_base + omap_sram_size ||
259 sram_addr < omap_sram_base + SRAM_BOOTLOADER_SZ) {
260 printk(KERN_ERR "sram: invalid patch address 0x%0lx\n",
266 if (*(typeof(SRAM_VA_MAGIC) *)sram_addr != SRAM_VA_MAGIC) {
267 printk(KERN_ERR "sram: will not patch address 0x%0lx: "
268 "no magic\n", sram_addr);
272 #endif /* CONFIG_OMAP_DEBUG_SRAM_PATCH */
274 pr_debug("sram: patching 0x%0lx with 0x%0lx\n", sram_addr,
277 *(unsigned long *)sram_addr = (unsigned long)d;
283 static void omap_sram_error(void)
285 panic("Uninitialized SRAM function\n");
288 #ifdef CONFIG_ARCH_OMAP1
290 static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl);
292 void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
294 if (!_omap_sram_reprogram_clock)
297 return _omap_sram_reprogram_clock(dpllctl, ckctl);
300 int __init omap1_sram_init(void)
302 _omap_sram_reprogram_clock = omap_sram_push(sram_reprogram_clock,
303 sram_reprogram_clock_sz);
309 #define omap1_sram_init() do {} while (0)
312 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
314 static void (*_omap2_sram_ddr_init)(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
315 u32 base_cs, u32 force_unlock);
317 void omap2_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
318 u32 base_cs, u32 force_unlock)
320 if (!_omap2_sram_ddr_init)
323 return _omap2_sram_ddr_init(slow_dll_ctrl, fast_dll_ctrl,
324 base_cs, force_unlock);
327 static void (*_omap2_sram_reprogram_sdrc)(u32 perf_level, u32 dll_val,
330 void omap2_sram_reprogram_sdrc(u32 perf_level, u32 dll_val, u32 mem_type)
332 if (!_omap2_sram_reprogram_sdrc)
335 return _omap2_sram_reprogram_sdrc(perf_level, dll_val, mem_type);
338 static u32 (*_omap2_set_prcm)(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
340 u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass)
342 if (!_omap2_set_prcm)
345 return _omap2_set_prcm(dpll_ctrl_val, sdrc_rfr_val, bypass);
348 int __init omap2_sram_init(void)
350 _omap2_sram_ddr_init = omap_sram_push(sram_ddr_init, sram_ddr_init_sz);
352 /* Patch in the correct register addresses for multiboot */
353 omap_sram_patch_va(sram_ddr_init, &omap2_sdi_cm_clksel2_pll,
354 _omap2_sram_ddr_init,
355 OMAP_CM_REGADDR(PLL_MOD, CM_CLKSEL2));
356 omap_sram_patch_va(sram_ddr_init, &omap2_sdi_sdrc_dlla_ctrl,
357 _omap2_sram_ddr_init,
358 OMAP_SDRC_REGADDR(SDRC_DLLA_CTRL));
359 omap_sram_patch_va(sram_ddr_init, &omap2_sdi_prcm_voltctrl,
360 _omap2_sram_ddr_init, OMAP24XX_PRCM_VOLTCTRL);
361 omap_sram_patch_va(sram_ddr_init, &omap2_sdi_timer_32ksynct_cr,
362 _omap2_sram_ddr_init,
363 (void __iomem *)IO_ADDRESS(OMAP2_32KSYNCT_BASE + 0x010));
365 _omap2_sram_reprogram_sdrc = omap_sram_push(sram_reprogram_sdrc,
366 sram_reprogram_sdrc_sz);
368 omap_sram_patch_va(sram_reprogram_sdrc, &omap2_srs_cm_clksel2_pll,
369 _omap2_sram_reprogram_sdrc,
370 OMAP_CM_REGADDR(PLL_MOD, CM_CLKSEL2));
371 omap_sram_patch_va(sram_reprogram_sdrc, &omap2_srs_sdrc_dlla_ctrl,
372 _omap2_sram_reprogram_sdrc,
373 OMAP_SDRC_REGADDR(SDRC_DLLA_CTRL));
374 omap_sram_patch_va(sram_reprogram_sdrc, &omap2_srs_sdrc_rfr_ctrl,
375 _omap2_sram_reprogram_sdrc,
376 OMAP_SDRC_REGADDR(SDRC_RFR_CTRL_0));
377 omap_sram_patch_va(sram_reprogram_sdrc, &omap2_srs_prcm_voltctrl,
378 _omap2_sram_reprogram_sdrc,
379 OMAP24XX_PRCM_VOLTCTRL);
380 omap_sram_patch_va(sram_reprogram_sdrc, &omap2_srs_timer_32ksynct,
381 _omap2_sram_reprogram_sdrc,
382 (void __iomem *)IO_ADDRESS(OMAP2_32KSYNCT_BASE + 0x010));
384 _omap2_set_prcm = omap_sram_push(sram_set_prcm, sram_set_prcm_sz);
386 /* REVISIT: prefix all these symbols with omap2_sram_ */
387 omap_sram_patch_va(sram_set_prcm, &omap2_ssp_set_config,
389 OMAP24XX_PRCM_CLKCFG_CTRL);
390 omap_sram_patch_va(sram_set_prcm, &omap2_ssp_pll_ctl,
392 OMAP_CM_REGADDR(PLL_MOD, CM_CLKEN));
393 omap_sram_patch_va(sram_set_prcm, &omap2_ssp_pll_stat,
395 OMAP_CM_REGADDR(PLL_MOD, CM_IDLEST));
396 omap_sram_patch_va(sram_set_prcm, &omap2_ssp_pll_div,
398 OMAP_CM_REGADDR(PLL_MOD, CM_CLKSEL1));
399 omap_sram_patch_va(sram_set_prcm, &omap2_ssp_sdrc_rfr,
401 OMAP_SDRC_REGADDR(SDRC_RFR_CTRL_0));
402 omap_sram_patch_va(sram_set_prcm, &omap2_ssp_dlla_ctrl,
404 OMAP_SDRC_REGADDR(SDRC_DLLA_CTRL));
409 #define omap2_sram_init() do {} while (0)
412 int __init omap_sram_init(void)
417 if (!(cpu_class_is_omap2()))