]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/plat-omap/sram.c
ARM: OMAP: Fix GCC-reported compile time bug
[linux-2.6-omap-h63xx.git] / arch / arm / plat-omap / sram.c
1 /*
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
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17
18 #include <asm/tlb.h>
19 #include <asm/io.h>
20 #include <asm/cacheflush.h>
21
22 #include <asm/mach/map.h>
23
24 #include <asm/arch/sram.h>
25 #include <asm/arch/board.h>
26
27 #define OMAP1_SRAM_PA           0x20000000
28 #define OMAP1_SRAM_VA           0xd0000000
29 #define OMAP2_SRAM_PA           0x40200000
30 #define OMAP2_SRAM_PUB_PA       0x4020f800
31 #define OMAP2_SRAM_VA           0xd0000000
32 #define OMAP2_SRAM_PUB_VA       0xd0000800
33
34 #if defined(CONFIG_ARCH_OMAP24XX)
35 #define SRAM_BOOTLOADER_SZ      0x00
36 #else
37 #define SRAM_BOOTLOADER_SZ      0x80
38 #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)))
48
49 static unsigned long omap_sram_start;
50 static unsigned long omap_sram_base;
51 static unsigned long omap_sram_size;
52 static unsigned long omap_sram_ceil;
53
54 extern unsigned long omapfb_reserve_sram(unsigned long sram_pstart,
55                                          unsigned long sram_vstart,
56                                          unsigned long sram_size,
57                                          unsigned long pstart_avail,
58                                          unsigned long size_avail);
59
60 /* Depending on the target RAMFS firewall setup, the public usable amount of
61  * SRAM varies.  The default accessable size for all device types is 2k. A GP
62  * device allows ARM11 but not other initators for full size. This
63  * functionality seems ok until some nice security API happens.
64  */
65 static int is_sram_locked(void)
66 {
67         int type = 0;
68
69         if (cpu_is_omap242x())
70                 type = __raw_readl(VA_CONTROL_STAT) & TYPE_MASK;
71
72         if (type == GP_DEVICE) {
73                 /* RAMFW: R/W access to all initators for all qualifier sets */
74                 if (cpu_is_omap242x()) {
75                         __raw_writel(0xFF, VA_REQINFOPERM0); /* all q-vects */
76                         __raw_writel(0xCFDE, VA_READPERM0);  /* all i-read */
77                         __raw_writel(0xCFDE, VA_WRITEPERM0); /* all i-write */
78                 }
79                 return 0;
80         } else
81                 return 1; /* assume locked with no PPA or security driver */
82 }
83
84 /*
85  * The amount of SRAM depends on the core type.
86  * Note that we cannot try to test for SRAM here because writes
87  * to secure SRAM will hang the system. Also the SRAM is not
88  * yet mapped at this point.
89  */
90 void __init omap_detect_sram(void)
91 {
92         unsigned long reserved;
93
94         if (cpu_is_omap24xx()) {
95                 if (is_sram_locked()) {
96                         omap_sram_base = OMAP2_SRAM_PUB_VA;
97                         omap_sram_start = OMAP2_SRAM_PUB_PA;
98                         omap_sram_size = 0x800; /* 2K */
99                 } else {
100                         omap_sram_base = OMAP2_SRAM_VA;
101                         omap_sram_start = OMAP2_SRAM_PA;
102                         if (cpu_is_omap242x())
103                                 omap_sram_size = 0xa0000; /* 640K */
104                         else if (cpu_is_omap243x())
105                                 omap_sram_size = 0x10000; /* 64K */
106                 }
107         } else {
108                 omap_sram_base = OMAP1_SRAM_VA;
109                 omap_sram_start = OMAP1_SRAM_PA;
110
111                 if (cpu_is_omap730())
112                         omap_sram_size = 0x32000;       /* 200K */
113                 else if (cpu_is_omap15xx())
114                         omap_sram_size = 0x30000;       /* 192K */
115                 else if (cpu_is_omap1610() || cpu_is_omap1621() ||
116                      cpu_is_omap1710())
117                         omap_sram_size = 0x4000;        /* 16K */
118                 else if (cpu_is_omap1611())
119                         omap_sram_size = 0x3e800;       /* 250K */
120                 else {
121                         printk(KERN_ERR "Could not detect SRAM size\n");
122                         omap_sram_size = 0x4000;
123                 }
124         }
125         reserved = omapfb_reserve_sram(omap_sram_start, omap_sram_base,
126                                        omap_sram_size,
127                                        omap_sram_start + SRAM_BOOTLOADER_SZ,
128                                        omap_sram_size - SRAM_BOOTLOADER_SZ);
129         omap_sram_size -= reserved;
130         omap_sram_ceil = omap_sram_base + omap_sram_size;
131 }
132
133 static struct map_desc omap_sram_io_desc[] __initdata = {
134         {       /* .length gets filled in at runtime */
135                 .virtual        = OMAP1_SRAM_VA,
136                 .pfn            = __phys_to_pfn(OMAP1_SRAM_PA),
137                 .type           = MT_MEMORY
138         }
139 };
140
141 /*
142  * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
143  */
144 void __init omap_map_sram(void)
145 {
146         unsigned long base;
147
148         if (omap_sram_size == 0)
149                 return;
150
151         if (cpu_is_omap24xx()) {
152                 omap_sram_io_desc[0].virtual = OMAP2_SRAM_VA;
153
154                 base = OMAP2_SRAM_PA;
155                 base = ROUND_DOWN(base, PAGE_SIZE);
156                 omap_sram_io_desc[0].pfn = __phys_to_pfn(base);
157         }
158
159         omap_sram_io_desc[0].length = 1024 * 1024;      /* Use section desc */
160         iotable_init(omap_sram_io_desc, ARRAY_SIZE(omap_sram_io_desc));
161
162         printk(KERN_INFO "SRAM: Mapped pa 0x%08lx to va 0x%08lx size: 0x%lx\n",
163         __pfn_to_phys(omap_sram_io_desc[0].pfn),
164         omap_sram_io_desc[0].virtual,
165                omap_sram_io_desc[0].length);
166
167         /*
168          * Normally devicemaps_init() would flush caches and tlb after
169          * mdesc->map_io(), but since we're called from map_io(), we
170          * must do it here.
171          */
172         local_flush_tlb_all();
173         flush_cache_all();
174
175         /*
176          * Looks like we need to preserve some bootloader code at the
177          * beginning of SRAM for jumping to flash for reboot to work...
178          */
179         memset((void *)omap_sram_base + SRAM_BOOTLOADER_SZ, 0,
180                omap_sram_size - SRAM_BOOTLOADER_SZ);
181 }
182
183 void * omap_sram_push(void * start, unsigned long size)
184 {
185         if (size > (omap_sram_ceil - (omap_sram_base + SRAM_BOOTLOADER_SZ))) {
186                 printk(KERN_ERR "Not enough space in SRAM\n");
187                 return NULL;
188         }
189
190         omap_sram_ceil -= size;
191         omap_sram_ceil = ROUND_DOWN(omap_sram_ceil, sizeof(void *));
192         memcpy((void *)omap_sram_ceil, start, size);
193
194         return (void *)omap_sram_ceil;
195 }
196
197 static void omap_sram_error(void)
198 {
199         panic("Uninitialized SRAM function\n");
200 }
201
202 #ifdef CONFIG_ARCH_OMAP1
203
204 static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl);
205
206 void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
207 {
208         if (!_omap_sram_reprogram_clock)
209                 omap_sram_error();
210
211         return _omap_sram_reprogram_clock(dpllctl, ckctl);
212 }
213
214 int __init omap1_sram_init(void)
215 {
216         _omap_sram_reprogram_clock = omap_sram_push(sram_reprogram_clock,
217                                                     sram_reprogram_clock_sz);
218
219         return 0;
220 }
221
222 #else
223 #define omap1_sram_init()       do {} while (0)
224 #endif
225
226 #ifdef CONFIG_ARCH_OMAP2
227
228 static void (*_omap2_sram_ddr_init)(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
229                               u32 base_cs, u32 force_unlock);
230
231 void omap2_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
232                    u32 base_cs, u32 force_unlock)
233 {
234         if (!_omap2_sram_ddr_init)
235                 omap_sram_error();
236
237         return _omap2_sram_ddr_init(slow_dll_ctrl, fast_dll_ctrl,
238                                     base_cs, force_unlock);
239 }
240
241 static void (*_omap2_sram_reprogram_sdrc)(u32 perf_level, u32 dll_val,
242                                           u32 mem_type);
243
244 void omap2_sram_reprogram_sdrc(u32 perf_level, u32 dll_val, u32 mem_type)
245 {
246         if (!_omap2_sram_reprogram_sdrc)
247                 omap_sram_error();
248
249         return _omap2_sram_reprogram_sdrc(perf_level, dll_val, mem_type);
250 }
251
252 static u32 (*_omap2_set_prcm)(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
253
254 u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass)
255 {
256         if (!_omap2_set_prcm)
257                 omap_sram_error();
258
259         return _omap2_set_prcm(dpll_ctrl_val, sdrc_rfr_val, bypass);
260 }
261
262 int __init omap2_sram_init(void)
263 {
264         _omap2_sram_ddr_init = omap_sram_push(sram_ddr_init, sram_ddr_init_sz);
265
266         _omap2_sram_reprogram_sdrc = omap_sram_push(sram_reprogram_sdrc,
267                                                     sram_reprogram_sdrc_sz);
268         _omap2_set_prcm = omap_sram_push(sram_set_prcm, sram_set_prcm_sz);
269
270         return 0;
271 }
272 #else
273 #define omap2_sram_init()       do {} while (0)
274 #endif
275
276 int __init omap_sram_init(void)
277 {
278         omap_detect_sram();
279         omap_map_sram();
280
281         if (!cpu_is_omap24xx())
282                 omap1_sram_init();
283         else
284                 omap2_sram_init();
285
286         return 0;
287 }