1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <common.h>
23#include <asm/arch/omap2420.h>
24#include <asm/io.h>
25#include <asm/arch/bits.h>
26#include <asm/arch/mux.h>
27#include <asm/arch/mem.h>
28#include <asm/arch/clocks.h>
29#include <asm/arch/sys_proto.h>
30#include <asm/arch/sys_info.h>
31
32
33
34
35
36
37
38
39void sdelay (unsigned long loops)
40{
41 __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
42 "bne 1b":"=r" (loops):"0" (loops));
43}
44
45
46
47
48
49void prcm_init(void)
50{
51 u32 div;
52 void (*f_lock_pll) (u32, u32, u32, u32);
53 extern void *_end_vect, *_start;
54
55 f_lock_pll = (void *)((u32)&_end_vect - (u32)&_start + SRAM_VECT_CODE);
56
57 __raw_writel(0, CM_FCLKEN1_CORE);
58 __raw_writel(0, CM_FCLKEN2_CORE);
59 __raw_writel(0, CM_ICLKEN1_CORE);
60 __raw_writel(0, CM_ICLKEN2_CORE);
61
62 __raw_writel(DPLL_OUT, CM_CLKSEL2_PLL);
63 __raw_writel(MPU_DIV, CM_CLKSEL_MPU);
64 __raw_writel(DSP_DIV, CM_CLKSEL_DSP);
65 __raw_writel(GFX_DIV, CM_CLKSEL_GFX);
66
67 div = BUS_DIV;
68 __raw_writel(div, CM_CLKSEL1_CORE);
69 sdelay(1000);
70
71 if(running_in_sram()){
72
73
74
75
76 __raw_writel(MODE_BYPASS_FAST, CM_CLKEN_PLL);
77 wait_on_value(BIT0|BIT1, BIT0, CM_IDLEST_CKGEN, LDELAY);
78 sdelay(1000);
79
80 __raw_writel(DPLL_VAL, CM_CLKSEL1_PLL);
81 __raw_writel(COMMIT_DIVIDERS, PRCM_CLKCFG_CTRL);
82 sdelay(10000);
83 __raw_writel(DPLL_LOCK, CM_CLKEN_PLL);
84 sdelay(10000);
85 wait_on_value(BIT0|BIT1, BIT1, CM_IDLEST_CKGEN, LDELAY);
86 }else if(running_in_flash()){
87
88
89
90 (*f_lock_pll)(PRCM_CLKCFG_CTRL, CM_CLKEN_PLL, DPLL_LOCK, CM_IDLEST_CKGEN);
91 }
92
93 __raw_writel(DPLL_LOCK|APLL_LOCK, CM_CLKEN_PLL);
94 wait_on_value(BIT8, BIT8, CM_IDLEST_CKGEN, LDELAY);
95 sdelay(1000);
96}
97
98
99
100
101
102
103
104void make_cs1_contiguous(void)
105{
106 u32 size, a_add_low, a_add_high;
107
108 size = get_sdr_cs_size(SDRC_CS0_OSET);
109 size /= SZ_32M;
110 a_add_high = (size & 3) << 8;
111 a_add_low = (size & 0x3C) >> 2;
112 __raw_writel((a_add_high|a_add_low),SDRC_CS_CFG);
113
114}
115
116
117
118
119
120
121u32 mem_ok(void)
122{
123 u32 val1, val2;
124 u32 pattern = 0x12345678;
125
126 __raw_writel(0x0,OMAP2420_SDRC_CS0+0x400);
127 __raw_writel(pattern, OMAP2420_SDRC_CS0);
128 __raw_writel(0x0,OMAP2420_SDRC_CS0+4);
129 val1 = __raw_readl(OMAP2420_SDRC_CS0+0x400);
130 val2 = __raw_readl(OMAP2420_SDRC_CS0);
131
132 if ((val1 != 0) || (val2 != pattern))
133 return(0);
134 else
135 return(1);
136}
137
138
139
140
141
142
143
144void sdrc_init(void)
145{
146 #define EARLY_INIT 1
147 do_sdrc_init(SDRC_CS0_OSET, EARLY_INIT);
148}
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163void do_sdrc_init(u32 offset, u32 early)
164{
165 u32 cpu, dllen=0, rev, common=0, cs0=0, pmask=0, pass_type, mtype;
166 sdrc_data_t *sdata;
167 u32 a, b, r;
168
169 static const sdrc_data_t sdrc_2422 =
170 {
171 H4_2422_SDRC_SHARING, H4_2422_SDRC_MDCFG_0_DDR, 0 , H4_2422_SDRC_ACTIM_CTRLA_0,
172 H4_2422_SDRC_ACTIM_CTRLB_0, H4_2422_SDRC_RFR_CTRL, H4_2422_SDRC_MR_0_DDR,
173 0, H4_2422_SDRC_DLLAB_CTRL
174 };
175 static const sdrc_data_t sdrc_2420 =
176 {
177 H4_2420_SDRC_SHARING, H4_2420_SDRC_MDCFG_0_DDR, H4_2420_SDRC_MDCFG_0_SDR,
178 H4_2420_SDRC_ACTIM_CTRLA_0, H4_2420_SDRC_ACTIM_CTRLB_0,
179 H4_2420_SDRC_RFR_CTRL, H4_2420_SDRC_MR_0_DDR, H4_2420_SDRC_MR_0_SDR,
180 H4_2420_SDRC_DLLAB_CTRL
181 };
182
183 if (offset == SDRC_CS0_OSET)
184 cs0 = common = 1;
185
186 cpu = get_cpu_type();
187 rev = get_cpu_rev();
188
189
190
191
192
193 if (cpu == CPU_2422){
194 sdata = (sdrc_data_t *)&sdrc_2422;
195 pass_type = STACKED;
196 } else{
197 sdata = (sdrc_data_t *)&sdrc_2420;
198 pass_type = IP_DDR;
199 }
200
201 __asm__ __volatile__("": : :"memory");
202
203
204
205
206
207
208
209 if((early) && running_in_flash()){
210 sdata = (sdrc_data_t *)(((u32)sdata & 0x0003FFFF) | get_gpmc0_base());
211
212 if(running_from_internal_boot())
213 sdata = (sdrc_data_t *)((u32)sdata + 0x4000);
214 }
215
216 if (!early && (((mtype = get_mem_type()) == DDR_COMBO)||(mtype == DDR_STACKED))) {
217 if(mtype == DDR_COMBO){
218 pmask = BIT2;
219 pass_type = COMBO_DDR;
220 __raw_writel((__raw_readl(SDRC_POWER)) & ~pmask, SDRC_POWER);
221 }
222 if(rev != CPU_2420_2422_ES1)
223 make_cs1_contiguous();
224 }
225
226next_mem_type:
227 if (common) {
228 __raw_writel(SOFTRESET, SDRC_SYSCONFIG);
229 wait_on_value(BIT0, BIT0, SDRC_STATUS, 12000000);
230 __raw_writel(0, SDRC_SYSCONFIG);
231 __raw_writel(sdata->sdrc_sharing, SDRC_SHARING);
232#ifdef POWER_SAVE
233 __raw_writel(__raw_readl(SMS_SYSCONFIG)|SMART_IDLE, SMS_SYSCONFIG);
234 __raw_writel(sdata->sdrc_sharing|SMART_IDLE, SDRC_SHARING);
235 __raw_writel((__raw_readl(SDRC_POWER)|BIT6), SDRC_POWER);
236#endif
237 }
238
239 if ((pass_type == IP_DDR) || (pass_type == STACKED))
240 __raw_writel(sdata->sdrc_mdcfg_0_ddr, SDRC_MCFG_0+offset);
241 else if (pass_type == COMBO_DDR){
242 __raw_writel(H4_2420_COMBO_MDCFG_0_DDR,SDRC_MCFG_0+offset);
243 } else if (pass_type == IP_SDR){
244 __raw_writel(sdata->sdrc_mdcfg_0_sdr, SDRC_MCFG_0+offset);
245 }
246
247 a = sdata->sdrc_actim_ctrla_0;
248 b = sdata->sdrc_actim_ctrlb_0;
249 r = sdata->sdrc_dllab_ctrl;
250
251
252 if((pass_type != IP_SDR) && (rev == CPU_2420_2422_ES1)){
253 a = H4_242x_SDRC_ACTIM_CTRLA_0_ES1;
254 b = H4_242x_SDRC_ACTIM_CTRLB_0_ES1;
255 r = H4_242x_SDRC_RFR_CTRL_ES1;
256 }
257
258 if (cs0) {
259 __raw_writel(a, SDRC_ACTIM_CTRLA_0);
260 __raw_writel(b, SDRC_ACTIM_CTRLB_0);
261 } else {
262 __raw_writel(a, SDRC_ACTIM_CTRLA_1);
263 __raw_writel(b, SDRC_ACTIM_CTRLB_1);
264 }
265 __raw_writel(r, SDRC_RFR_CTRL+offset);
266
267
268 __raw_writel(CMD_NOP, SDRC_MANUAL_0+offset);
269 sdelay(5000);
270 __raw_writel(CMD_PRECHARGE, SDRC_MANUAL_0+offset);
271 __raw_writel(CMD_AUTOREFRESH, SDRC_MANUAL_0+offset);
272 __raw_writel(CMD_AUTOREFRESH, SDRC_MANUAL_0+offset);
273
274
275
276
277
278
279
280 if(pass_type == IP_SDR)
281 __raw_writel(sdata->sdrc_mr_0_sdr, SDRC_MR_0+offset);
282 else
283 __raw_writel(sdata->sdrc_mr_0_ddr, SDRC_MR_0+offset);
284
285
286 if (rev == CPU_2420_2422_ES1){
287 dllen = (BIT0|BIT3);
288 __raw_writel((__raw_readl(SMS_CLASS_ARB0)|BURSTCOMPLETE_GROUP7)
289 ,SMS_CLASS_ARB0);
290 }
291 else
292 dllen = BIT0|BIT1;
293
294
295
296
297 if (common && (pass_type != IP_SDR)) {
298 __raw_writel(sdata->sdrc_dllab_ctrl, SDRC_DLLA_CTRL);
299 __raw_writel(sdata->sdrc_dllab_ctrl & ~(BIT2|dllen), SDRC_DLLA_CTRL);
300 __raw_writel(sdata->sdrc_dllab_ctrl, SDRC_DLLB_CTRL);
301 __raw_writel(sdata->sdrc_dllab_ctrl & ~(BIT2|dllen) , SDRC_DLLB_CTRL);
302 }
303 sdelay(90000);
304
305 if(mem_ok())
306 return;
307 ++pass_type;
308 goto next_mem_type;
309}
310
311
312
313
314
315
316void gpmc_init(void)
317{
318 u32 mux=0, mtype, mwidth, rev, tval;
319
320 rev = get_cpu_rev();
321 if (rev == CPU_2420_2422_ES1)
322 tval = 1;
323 else
324 tval = 0;
325
326
327 __raw_writel(0x10, GPMC_SYSCONFIG);
328 __raw_writel(0x0, GPMC_IRQENABLE);
329 __raw_writel(tval, GPMC_TIMEOUT_CONTROL);
330#ifdef CONFIG_SYS_NAND_BOOT
331 __raw_writel(0x001, GPMC_CONFIG);
332#else
333 __raw_writel(0x111, GPMC_CONFIG);
334#endif
335
336
337 if (is_gpmc_muxed() == GPMC_MUXED)
338 mux = BIT9;
339 mtype = get_gpmc0_type();
340 mwidth = get_gpmc0_width();
341
342
343 __raw_writel(0x0, GPMC_CONFIG7_0);
344 sdelay(1000);
345
346#ifdef CONFIG_SYS_NAND_BOOT
347 __raw_writel(H4_24XX_GPMC_CONFIG1_0|mtype|mwidth, GPMC_CONFIG1_0);
348#else
349 __raw_writel(H4_24XX_GPMC_CONFIG1_0|mux|mtype|mwidth, GPMC_CONFIG1_0);
350#endif
351
352#ifdef PRCM_CONFIG_III
353 __raw_writel(H4_24XX_GPMC_CONFIG2_0, GPMC_CONFIG2_0);
354#endif
355 __raw_writel(H4_24XX_GPMC_CONFIG3_0, GPMC_CONFIG3_0);
356 __raw_writel(H4_24XX_GPMC_CONFIG4_0, GPMC_CONFIG4_0);
357#ifdef PRCM_CONFIG_III
358 __raw_writel(H4_24XX_GPMC_CONFIG5_0, GPMC_CONFIG5_0);
359 __raw_writel(H4_24XX_GPMC_CONFIG6_0, GPMC_CONFIG6_0);
360#endif
361 __raw_writel(H4_24XX_GPMC_CONFIG7_0, GPMC_CONFIG7_0);
362 sdelay(2000);
363
364
365 __raw_writel(0, GPMC_CONFIG7_1);
366 sdelay(1000);
367 __raw_writel(H4_24XX_GPMC_CONFIG1_1|mux, GPMC_CONFIG1_1);
368 __raw_writel(H4_24XX_GPMC_CONFIG2_1, GPMC_CONFIG2_1);
369 __raw_writel(H4_24XX_GPMC_CONFIG3_1, GPMC_CONFIG3_1);
370 __raw_writel(H4_24XX_GPMC_CONFIG4_1, GPMC_CONFIG4_1);
371 __raw_writel(H4_24XX_GPMC_CONFIG5_1, GPMC_CONFIG5_1);
372 __raw_writel(H4_24XX_GPMC_CONFIG6_1, GPMC_CONFIG6_1);
373 __raw_writel(H4_24XX_GPMC_CONFIG7_1, GPMC_CONFIG7_1);
374 sdelay(2000);
375}
376