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