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.
14 #include <linux/config.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
19 #include <asm/mach/map.h>
21 #include <asm/cacheflush.h>
23 #include <asm/arch/sram.h>
25 #define OMAP1_SRAM_PA 0x20000000
26 #define OMAP1_SRAM_VA 0xd0000000
27 #define OMAP2_SRAM_PA 0x40200000
28 #define OMAP2_SRAM_VA 0xd0000000
30 #define SRAM_BOOTLOADER_SZ 0x80
32 static unsigned long omap_sram_base;
33 static unsigned long omap_sram_size;
34 static unsigned long omap_sram_ceil;
37 * The amount of SRAM depends on the core type.
38 * Note that we cannot try to test for SRAM here because writes
39 * to secure SRAM will hang the system. Also the SRAM is not
40 * yet mapped at this point.
42 void __init omap_detect_sram(void)
44 if (!cpu_is_omap24xx())
45 omap_sram_base = OMAP1_SRAM_VA;
47 omap_sram_base = OMAP2_SRAM_VA;
50 omap_sram_size = 0x32000; /* 200K */
51 else if (cpu_is_omap15xx())
52 omap_sram_size = 0x30000; /* 192K */
53 else if (cpu_is_omap1610() || cpu_is_omap1621() || cpu_is_omap1710())
54 omap_sram_size = 0x4000; /* 16K */
55 else if (cpu_is_omap1611())
56 omap_sram_size = 0x3e800; /* 250K */
57 else if (cpu_is_omap2420())
58 omap_sram_size = 0xa0014; /* 640K */
60 printk(KERN_ERR "Could not detect SRAM size\n");
61 omap_sram_size = 0x4000;
64 omap_sram_ceil = omap_sram_base + omap_sram_size;
67 static struct map_desc omap_sram_io_desc[] __initdata = {
68 { /* .length gets filled in at runtime */
69 .virtual = OMAP1_SRAM_VA,
70 .pfn = __phys_to_pfn(OMAP1_SRAM_PA),
76 * In order to use last 2kB of SRAM on 1611b, we must round the size
77 * up to multiple of PAGE_SIZE. We cannot use ioremap for SRAM, as
78 * clock init needs SRAM early.
80 void __init omap_map_sram(void)
82 if (omap_sram_size == 0)
85 if (cpu_is_omap24xx()) {
86 omap_sram_io_desc[0].virtual = OMAP2_SRAM_VA;
87 omap_sram_io_desc[0].pfn = __phys_to_pfn(OMAP2_SRAM_PA);
90 omap_sram_io_desc[0].length = (omap_sram_size + PAGE_SIZE-1)/PAGE_SIZE;
91 omap_sram_io_desc[0].length *= PAGE_SIZE;
92 iotable_init(omap_sram_io_desc, ARRAY_SIZE(omap_sram_io_desc));
94 printk(KERN_INFO "SRAM: Mapped pa 0x%08lx to va 0x%08lx size: 0x%lx\n",
95 omap_sram_io_desc[0].pfn, omap_sram_io_desc[0].virtual,
96 omap_sram_io_desc[0].length);
99 * Looks like we need to preserve some bootloader code at the
100 * beginning of SRAM for jumping to flash for reboot to work...
102 memset((void *)omap_sram_base + SRAM_BOOTLOADER_SZ, 0,
103 omap_sram_size - SRAM_BOOTLOADER_SZ);
106 void * omap_sram_push(void * start, unsigned long size)
108 if (size > (omap_sram_ceil - (omap_sram_base + SRAM_BOOTLOADER_SZ))) {
109 printk(KERN_ERR "Not enough space in SRAM\n");
112 omap_sram_ceil -= size;
113 omap_sram_ceil &= ~0x3;
114 memcpy((void *)omap_sram_ceil, start, size);
116 return (void *)omap_sram_ceil;
119 static void omap_sram_error(void)
121 panic("Uninitialized SRAM function\n");
124 #ifdef CONFIG_ARCH_OMAP1
126 static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl);
128 void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
130 if (!_omap_sram_reprogram_clock)
133 return _omap_sram_reprogram_clock(dpllctl, ckctl);
136 int __init omap1_sram_init(void)
138 _omap_sram_reprogram_clock = omap_sram_push(sram_reprogram_clock,
139 sram_reprogram_clock_sz);
145 #define omap1_sram_init() do {} while (0)
148 #ifdef CONFIG_ARCH_OMAP2
150 static void (*_omap2_sram_ddr_init)(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
151 u32 base_cs, u32 force_unlock);
153 void omap2_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
154 u32 base_cs, u32 force_unlock)
156 if (!_omap2_sram_ddr_init)
159 return _omap2_sram_ddr_init(slow_dll_ctrl, fast_dll_ctrl,
160 base_cs, force_unlock);
163 static void (*_omap2_sram_reprogram_sdrc)(u32 perf_level, u32 dll_val,
166 void omap2_sram_reprogram_sdrc(u32 perf_level, u32 dll_val, u32 mem_type)
168 if (!_omap2_sram_reprogram_sdrc)
171 return _omap2_sram_reprogram_sdrc(perf_level, dll_val, mem_type);
174 static u32 (*_omap2_set_prcm)(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
176 u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass)
178 if (!_omap2_set_prcm)
181 return _omap2_set_prcm(dpll_ctrl_val, sdrc_rfr_val, bypass);
184 int __init omap2_sram_init(void)
186 _omap2_sram_ddr_init = omap_sram_push(sram_ddr_init, sram_ddr_init_sz);
188 _omap2_sram_reprogram_sdrc = omap_sram_push(sram_reprogram_sdrc,
189 sram_reprogram_sdrc_sz);
190 _omap2_set_prcm = omap_sram_push(sram_set_prcm, sram_set_prcm_sz);
195 #define omap2_sram_init() do {} while (0)
198 int __init omap_sram_init(void)
203 if (!cpu_is_omap24xx())