Merge branch 'master' of git://git.denx.de/u-boot-nand-flash
[oweals/u-boot.git] / arch / arm / cpu / armv7 / omap3 / lowlevel_init.S
1 /*
2  * Board specific setup info
3  *
4  * (C) Copyright 2008
5  * Texas Instruments, <www.ti.com>
6  *
7  * Initial Code by:
8  * Richard Woodruff <r-woodruff2@ti.com>
9  * Syed Mohammed Khasim <khasim@ti.com>
10  *
11  * See file CREDITS for list of people who contributed to this
12  * project.
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License as
16  * published by the Free Software Foundation; either version 2 of
17  * the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27  * MA 02111-1307 USA
28  */
29
30 #include <config.h>
31 #include <version.h>
32 #include <asm/arch/mem.h>
33 #include <asm/arch/clocks_omap3.h>
34 #include <linux/linkage.h>
35
36 _TEXT_BASE:
37         .word   CONFIG_SYS_TEXT_BASE    /* sdram load addr from config.mk */
38
39 #ifdef CONFIG_SPL_BUILD
40 ENTRY(save_boot_params)
41         ldr     r4, =omap3_boot_device
42         ldr     r5, [r0, #0x4]
43         and     r5, r5, #0xff
44         str     r5, [r4]
45         bx      lr
46 ENDPROC(save_boot_params)
47 #endif
48
49 ENTRY(omap3_gp_romcode_call)
50         PUSH {r4-r12, lr} @ Save all registers from ROM code!
51         MOV r12, r0     @ Copy the Service ID in R12
52         MOV r0, r1      @ Copy parameter to R0
53         mcr     p15, 0, r0, c7, c10, 4  @ DSB
54         mcr     p15, 0, r0, c7, c10, 5  @ DMB
55         .word   0xe1600070      @ SMC #0 to enter monitor - hand assembled
56                                 @ because we use -march=armv5
57         POP {r4-r12, pc}
58 ENDPROC(omap3_gp_romcode_call)
59
60 /*
61  * Funtion for making PPA HAL API calls in secure devices
62  * Input:
63  *      R0 - Service ID
64  *      R1 - paramer list
65  */
66 ENTRY(do_omap3_emu_romcode_call)
67         PUSH {r4-r12, lr} @ Save all registers from ROM code!
68         MOV r12, r0     @ Copy the Secure Service ID in R12
69         MOV r3, r1      @ Copy the pointer to va_list in R3
70         MOV r1, #0      @ Process ID - 0
71         MOV r2, #OMAP3_EMU_HAL_START_HAL_CRITICAL       @ Copy the pointer
72                                                         @ to va_list in R3
73         MOV r6, #0xFF   @ Indicate new Task call
74         mcr     p15, 0, r0, c7, c10, 4  @ DSB
75         mcr     p15, 0, r0, c7, c10, 5  @ DMB
76         .word   0xe1600071      @ SMC #1 to call PPA service - hand assembled
77                                 @ because we use -march=armv5
78         POP {r4-r12, pc}
79 ENDPROC(do_omap3_emu_romcode_call)
80
81 #if !defined(CONFIG_SYS_NAND_BOOT) && !defined(CONFIG_SYS_NAND_BOOT)
82 /**************************************************************************
83  * cpy_clk_code: relocates clock code into SRAM where its safer to execute
84  * R1 = SRAM destination address.
85  *************************************************************************/
86 ENTRY(cpy_clk_code)
87         /* Copy DPLL code into SRAM */
88         adr     r0, go_to_speed         /* get addr of clock setting code */
89         mov     r2, #384                /* r2 size to copy (div by 32 bytes) */
90         mov     r1, r1                  /* r1 <- dest address (passed in) */
91         add     r2, r2, r0              /* r2 <- source end address */
92 next2:
93         ldmia   r0!, {r3 - r10}         /* copy from source address [r0] */
94         stmia   r1!, {r3 - r10}         /* copy to   target address [r1] */
95         cmp     r0, r2                  /* until source end address [r2] */
96         bne     next2
97         mov     pc, lr                  /* back to caller */
98 ENDPROC(cpy_clk_code)
99
100 /* ***************************************************************************
101  *  go_to_speed: -Moves to bypass, -Commits clock dividers, -puts dpll at speed
102  *               -executed from SRAM.
103  *  R0 = CM_CLKEN_PLL-bypass value
104  *  R1 = CM_CLKSEL1_PLL-m, n, and divider values
105  *  R2 = CM_CLKSEL_CORE-divider values
106  *  R3 = CM_IDLEST_CKGEN - addr dpll lock wait
107  *
108  *  Note: If core unlocks/relocks and SDRAM is running fast already it gets
109  *        confused.  A reset of the controller gets it back.  Taking away its
110  *        L3 when its not in self refresh seems bad for it.  Normally, this
111  *        code runs from flash before SDR is init so that should be ok.
112  ****************************************************************************/
113 ENTRY(go_to_speed)
114         stmfd sp!, {r4 - r6}
115
116         /* move into fast relock bypass */
117         ldr     r4, pll_ctl_add
118         str     r0, [r4]
119 wait1:
120         ldr     r5, [r3]                /* get status */
121         and     r5, r5, #0x1            /* isolate core status */
122         cmp     r5, #0x1                /* still locked? */
123         beq     wait1                   /* if lock, loop */
124
125         /* set new dpll dividers _after_ in bypass */
126         ldr     r5, pll_div_add1
127         str     r1, [r5]                /* set m, n, m2 */
128         ldr     r5, pll_div_add2
129         str     r2, [r5]                /* set l3/l4/.. dividers*/
130         ldr     r5, pll_div_add3        /* wkup */
131         ldr     r2, pll_div_val3        /* rsm val */
132         str     r2, [r5]
133         ldr     r5, pll_div_add4        /* gfx */
134         ldr     r2, pll_div_val4
135         str     r2, [r5]
136         ldr     r5, pll_div_add5        /* emu */
137         ldr     r2, pll_div_val5
138         str     r2, [r5]
139
140         /* now prepare GPMC (flash) for new dpll speed */
141         /* flash needs to be stable when we jump back to it */
142         ldr     r5, flash_cfg3_addr
143         ldr     r2, flash_cfg3_val
144         str     r2, [r5]
145         ldr     r5, flash_cfg4_addr
146         ldr     r2, flash_cfg4_val
147         str     r2, [r5]
148         ldr     r5, flash_cfg5_addr
149         ldr     r2, flash_cfg5_val
150         str     r2, [r5]
151         ldr     r5, flash_cfg1_addr
152         ldr     r2, [r5]
153         orr     r2, r2, #0x3            /* up gpmc divider */
154         str     r2, [r5]
155
156         /* lock DPLL3 and wait a bit */
157         orr     r0, r0, #0x7    /* set up for lock mode */
158         str     r0, [r4]        /* lock */
159         nop                     /* ARM slow at this point working at sys_clk */
160         nop
161         nop
162         nop
163 wait2:
164         ldr     r5, [r3]        /* get status */
165         and     r5, r5, #0x1    /* isolate core status */
166         cmp     r5, #0x1        /* still locked? */
167         bne     wait2           /* if lock, loop */
168         nop
169         nop
170         nop
171         nop
172         ldmfd   sp!, {r4 - r6}
173         mov     pc, lr          /* back to caller, locked */
174 ENDPROC(go_to_speed)
175
176 _go_to_speed: .word go_to_speed
177
178 /* these constants need to be close for PIC code */
179 /* The Nor has to be in the Flash Base CS0 for this condition to happen */
180 flash_cfg1_addr:
181         .word (GPMC_CONFIG_CS0_BASE + GPMC_CONFIG1)
182 flash_cfg3_addr:
183         .word (GPMC_CONFIG_CS0_BASE + GPMC_CONFIG3)
184 flash_cfg3_val:
185         .word STNOR_GPMC_CONFIG3
186 flash_cfg4_addr:
187         .word (GPMC_CONFIG_CS0_BASE + GPMC_CONFIG4)
188 flash_cfg4_val:
189         .word STNOR_GPMC_CONFIG4
190 flash_cfg5_val:
191         .word STNOR_GPMC_CONFIG5
192 flash_cfg5_addr:
193         .word (GPMC_CONFIG_CS0_BASE + GPMC_CONFIG5)
194 pll_ctl_add:
195         .word CM_CLKEN_PLL
196 pll_div_add1:
197         .word CM_CLKSEL1_PLL
198 pll_div_add2:
199         .word CM_CLKSEL_CORE
200 pll_div_add3:
201         .word CM_CLKSEL_WKUP
202 pll_div_val3:
203         .word (WKUP_RSM << 1)
204 pll_div_add4:
205         .word CM_CLKSEL_GFX
206 pll_div_val4:
207         .word (GFX_DIV << 0)
208 pll_div_add5:
209         .word CM_CLKSEL1_EMU
210 pll_div_val5:
211         .word CLSEL1_EMU_VAL
212
213 #endif
214
215 ENTRY(lowlevel_init)
216         ldr     sp, SRAM_STACK
217         str     ip, [sp]        /* stash old link register */
218         mov     ip, lr          /* save link reg across call */
219 #if !defined(CONFIG_SYS_NAND_BOOT) && !defined(CONFIG_SYS_ONENAND_BOOT)
220 /*
221  * No need to copy/exec the clock code - DPLL adjust already done
222  * in NAND/oneNAND Boot.
223  */
224         ldr     r1, =SRAM_CLK_CODE
225         bl      cpy_clk_code
226 #endif /* NAND Boot */
227         bl      s_init          /* go setup pll, mux, memory */
228         ldr     ip, [sp]        /* restore save ip */
229         mov     lr, ip          /* restore link reg */
230
231         /* back to arch calling code */
232         mov     pc, lr
233 ENDPROC(lowlevel_init)
234
235         /* the literal pools origin */
236         .ltorg
237
238 REG_CONTROL_STATUS:
239         .word CONTROL_STATUS
240 SRAM_STACK:
241         .word LOW_LEVEL_SRAM_STACK
242
243 /* DPLL(1-4) PARAM TABLES */
244
245 /*
246  * Each of the tables has M, N, FREQSEL, M2 values defined for nominal
247  * OPP (1.2V). The fields are defined according to dpll_param struct (clock.c).
248  * The values are defined for all possible sysclk and for ES1 and ES2.
249  */
250
251 mpu_dpll_param:
252 /* 12MHz */
253 /* ES1 */
254 .word MPU_M_12_ES1, MPU_N_12_ES1, MPU_FSEL_12_ES1, MPU_M2_12_ES1
255 /* ES2 */
256 .word MPU_M_12_ES2, MPU_N_12_ES2, MPU_FSEL_12_ES2, MPU_M2_ES2
257 /* 3410 */
258 .word MPU_M_12, MPU_N_12, MPU_FSEL_12, MPU_M2_12
259
260 /* 13MHz */
261 /* ES1 */
262 .word MPU_M_13_ES1, MPU_N_13_ES1, MPU_FSEL_13_ES1, MPU_M2_13_ES1
263 /* ES2 */
264 .word MPU_M_13_ES2, MPU_N_13_ES2, MPU_FSEL_13_ES2, MPU_M2_13_ES2
265 /* 3410 */
266 .word MPU_M_13, MPU_N_13, MPU_FSEL_13, MPU_M2_13
267
268 /* 19.2MHz */
269 /* ES1 */
270 .word MPU_M_19P2_ES1, MPU_N_19P2_ES1, MPU_FSEL_19P2_ES1, MPU_M2_19P2_ES1
271 /* ES2 */
272 .word MPU_M_19P2_ES2, MPU_N_19P2_ES2, MPU_FSEL_19P2_ES2, MPU_M2_19P2_ES2
273 /* 3410 */
274 .word MPU_M_19P2, MPU_N_19P2, MPU_FSEL_19P2, MPU_M2_19P2
275
276 /* 26MHz */
277 /* ES1 */
278 .word MPU_M_26_ES1, MPU_N_26_ES1, MPU_FSEL_26_ES1, MPU_M2_26_ES1
279 /* ES2 */
280 .word MPU_M_26_ES2, MPU_N_26_ES2, MPU_FSEL_26_ES2, MPU_M2_26_ES2
281 /* 3410 */
282 .word MPU_M_26, MPU_N_26, MPU_FSEL_26, MPU_M2_26
283
284 /* 38.4MHz */
285 /* ES1 */
286 .word MPU_M_38P4_ES1, MPU_N_38P4_ES1, MPU_FSEL_38P4_ES1, MPU_M2_38P4_ES1
287 /* ES2 */
288 .word MPU_M_38P4_ES2, MPU_N_38P4_ES2, MPU_FSEL_38P4_ES2, MPU_M2_38P4_ES2
289 /* 3410 */
290 .word MPU_M_38P4, MPU_N_38P4, MPU_FSEL_38P4, MPU_M2_38P4
291
292
293 .globl get_mpu_dpll_param
294 get_mpu_dpll_param:
295         adr     r0, mpu_dpll_param
296         mov     pc, lr
297
298 iva_dpll_param:
299 /* 12MHz */
300 /* ES1 */
301 .word IVA_M_12_ES1, IVA_N_12_ES1, IVA_FSEL_12_ES1, IVA_M2_12_ES1
302 /* ES2 */
303 .word IVA_M_12_ES2, IVA_N_12_ES2, IVA_FSEL_12_ES2, IVA_M2_12_ES2
304 /* 3410 */
305 .word IVA_M_12, IVA_N_12, IVA_FSEL_12, IVA_M2_12
306
307 /* 13MHz */
308 /* ES1 */
309 .word IVA_M_13_ES1, IVA_N_13_ES1, IVA_FSEL_13_ES1, IVA_M2_13_ES1
310 /* ES2 */
311 .word IVA_M_13_ES2, IVA_N_13_ES2,  IVA_FSEL_13_ES2, IVA_M2_13_ES2
312 /* 3410 */
313 .word IVA_M_13, IVA_N_13, IVA_FSEL_13, IVA_M2_13
314
315 /* 19.2MHz */
316 /* ES1 */
317 .word IVA_M_19P2_ES1, IVA_N_19P2_ES1, IVA_FSEL_19P2_ES1, IVA_M2_19P2_ES1
318 /* ES2 */
319 .word IVA_M_19P2_ES2, IVA_N_19P2_ES2, IVA_FSEL_19P2_ES2, IVA_M2_19P2_ES2
320 /* 3410 */
321 .word IVA_M_19P2, IVA_N_19P2, IVA_FSEL_19P2, IVA_M2_19P2
322
323 /* 26MHz */
324 /* ES1 */
325 .word IVA_M_26_ES1, IVA_N_26_ES1, IVA_FSEL_26_ES1, IVA_M2_26_ES1
326 /* ES2 */
327 .word IVA_M_26_ES2, IVA_N_26_ES2, IVA_FSEL_26_ES2, IVA_M2_26_ES2
328 /* 3410 */
329 .word IVA_M_26, IVA_N_26, IVA_FSEL_26, IVA_M2_26
330
331 /* 38.4MHz */
332 /* ES1 */
333 .word IVA_M_38P4_ES1, IVA_N_38P4_ES1, IVA_FSEL_38P4_ES1, IVA_M2_38P4_ES1
334 /* ES2 */
335 .word IVA_M_38P4_ES2, IVA_N_38P4_ES2, IVA_FSEL_38P4_ES2, IVA_M2_38P4_ES2
336 /* 3410 */
337 .word IVA_M_38P4, IVA_N_38P4, IVA_FSEL_38P4, IVA_M2_38P4
338
339
340 .globl get_iva_dpll_param
341 get_iva_dpll_param:
342         adr     r0, iva_dpll_param
343         mov     pc, lr
344
345 /* Core DPLL targets for L3 at 166 & L133 */
346 core_dpll_param:
347 /* 12MHz */
348 /* ES1 */
349 .word CORE_M_12_ES1, CORE_N_12_ES1, CORE_FSL_12_ES1, CORE_M2_12_ES1
350 /* ES2 */
351 .word CORE_M_12, CORE_N_12, CORE_FSEL_12, CORE_M2_12
352 /* 3410 */
353 .word CORE_M_12, CORE_N_12, CORE_FSEL_12, CORE_M2_12
354
355 /* 13MHz */
356 /* ES1 */
357 .word CORE_M_13_ES1, CORE_N_13_ES1, CORE_FSL_13_ES1, CORE_M2_13_ES1
358 /* ES2 */
359 .word CORE_M_13, CORE_N_13, CORE_FSEL_13, CORE_M2_13
360 /* 3410 */
361 .word CORE_M_13, CORE_N_13, CORE_FSEL_13, CORE_M2_13
362
363 /* 19.2MHz */
364 /* ES1 */
365 .word CORE_M_19P2_ES1, CORE_N_19P2_ES1, CORE_FSL_19P2_ES1, CORE_M2_19P2_ES1
366 /* ES2 */
367 .word CORE_M_19P2, CORE_N_19P2, CORE_FSEL_19P2, CORE_M2_19P2
368 /* 3410 */
369 .word CORE_M_19P2, CORE_N_19P2, CORE_FSEL_19P2, CORE_M2_19P2
370
371 /* 26MHz */
372 /* ES1 */
373 .word CORE_M_26_ES1, CORE_N_26_ES1, CORE_FSL_26_ES1, CORE_M2_26_ES1
374 /* ES2 */
375 .word CORE_M_26, CORE_N_26, CORE_FSEL_26, CORE_M2_26
376 /* 3410 */
377 .word CORE_M_26, CORE_N_26, CORE_FSEL_26, CORE_M2_26
378
379 /* 38.4MHz */
380 /* ES1 */
381 .word CORE_M_38P4_ES1, CORE_N_38P4_ES1, CORE_FSL_38P4_ES1, CORE_M2_38P4_ES1
382 /* ES2 */
383 .word CORE_M_38P4, CORE_N_38P4, CORE_FSEL_38P4, CORE_M2_38P4
384 /* 3410 */
385 .word CORE_M_38P4, CORE_N_38P4, CORE_FSEL_38P4, CORE_M2_38P4
386
387 .globl get_core_dpll_param
388 get_core_dpll_param:
389         adr     r0, core_dpll_param
390         mov     pc, lr
391
392 /* PER DPLL values are same for both ES1 and ES2 */
393 per_dpll_param:
394 /* 12MHz */
395 .word PER_M_12, PER_N_12, PER_FSEL_12, PER_M2_12
396
397 /* 13MHz */
398 .word PER_M_13, PER_N_13, PER_FSEL_13, PER_M2_13
399
400 /* 19.2MHz */
401 .word PER_M_19P2, PER_N_19P2, PER_FSEL_19P2, PER_M2_19P2
402
403 /* 26MHz */
404 .word PER_M_26, PER_N_26, PER_FSEL_26, PER_M2_26
405
406 /* 38.4MHz */
407 .word PER_M_38P4, PER_N_38P4, PER_FSEL_38P4, PER_M2_38P4
408
409 .globl get_per_dpll_param
410 get_per_dpll_param:
411         adr     r0, per_dpll_param
412         mov     pc, lr
413
414 /* PER2 DPLL values */
415 per2_dpll_param:
416 /* 12MHz */
417 .word PER2_M_12, PER2_N_12, PER2_FSEL_12, PER2_M2_12
418
419 /* 13MHz */
420 .word PER2_M_13, PER2_N_13, PER2_FSEL_13, PER2_M2_13
421
422 /* 19.2MHz */
423 .word PER2_M_19P2, PER2_N_19P2, PER2_FSEL_19P2, PER2_M2_19P2
424
425 /* 26MHz */
426 .word PER2_M_26, PER2_N_26, PER2_FSEL_26, PER2_M2_26
427
428 /* 38.4MHz */
429 .word PER2_M_38P4, PER2_N_38P4, PER2_FSEL_38P4, PER2_M2_38P4
430
431 .globl get_per2_dpll_param
432 get_per2_dpll_param:
433         adr     r0, per2_dpll_param
434         mov     pc, lr
435
436 /*
437  * Tables for 36XX/37XX devices
438  *
439  */
440 mpu_36x_dpll_param:
441 /* 12MHz */
442 .word 50, 0, 0, 1
443 /* 13MHz */
444 .word 600, 12, 0, 1
445 /* 19.2MHz */
446 .word 125, 3, 0, 1
447 /* 26MHz */
448 .word 300, 12, 0, 1
449 /* 38.4MHz */
450 .word 125, 7, 0, 1
451
452 iva_36x_dpll_param:
453 /* 12MHz */
454 .word 130, 2, 0, 1
455 /* 13MHz */
456 .word 20, 0, 0, 1
457 /* 19.2MHz */
458 .word 325, 11, 0, 1
459 /* 26MHz */
460 .word 10, 0, 0, 1
461 /* 38.4MHz */
462 .word 325, 23, 0, 1
463
464 core_36x_dpll_param:
465 /* 12MHz */
466 .word 100, 2, 0, 1
467 /* 13MHz */
468 .word 400, 12, 0, 1
469 /* 19.2MHz */
470 .word 375, 17, 0, 1
471 /* 26MHz */
472 .word 200, 12, 0, 1
473 /* 38.4MHz */
474 .word 375, 35, 0, 1
475
476 per_36x_dpll_param:
477 /*    SYSCLK    M       N      M2      M3      M4     M5      M6      m2DIV */
478 .word 12000,    360,    4,     9,      16,     5,     4,      3,      1
479 .word 13000,    864,   12,     9,      16,     9,     4,      3,      1
480 .word 19200,    360,    7,     9,      16,     5,     4,      3,      1
481 .word 26000,    432,   12,     9,      16,     9,     4,      3,      1
482 .word 38400,    360,   15,     9,      16,     5,     4,      3,      1
483
484 ENTRY(get_36x_mpu_dpll_param)
485         adr     r0, mpu_36x_dpll_param
486         mov     pc, lr
487 ENDPROC(get_36x_mpu_dpll_param)
488
489 ENTRY(get_36x_iva_dpll_param)
490         adr     r0, iva_36x_dpll_param
491         mov     pc, lr
492 ENDPROC(get_36x_iva_dpll_param)
493
494 ENTRY(get_36x_core_dpll_param)
495         adr     r0, core_36x_dpll_param
496         mov     pc, lr
497 ENDPROC(get_36x_core_dpll_param)
498
499 ENTRY(get_36x_per_dpll_param)
500         adr     r0, per_36x_dpll_param
501         mov     pc, lr
502 ENDPROC(get_36x_per_dpll_param)