board: technexion: Add support for TAM3517 SoM.
[pandora-x-loader.git] / board / tam3517 / platform.S
1 /*
2  * Board specific setup info
3  *
4  * (C) Copyright 2009
5  * Texas Instruments, <www.ti.com>
6  * Manikandan Pillai <mani.pillai@ti.com>
7  * This file is copied from board/omap3evm/platform.S
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  */
27
28 #include <config.h>
29 #include <asm/arch/cpu.h>
30 #include <asm/arch/mem.h>
31 #include <asm/arch/clocks.h>
32
33 _TEXT_BASE:
34         .word   TEXT_BASE       /* sdram load addr from config.mk */
35
36 #if !defined(CFG_NAND_BOOT) && !defined(CFG_NAND_BOOT)
37 /**************************************************************************
38  * cpy_clk_code: relocates clock code into SRAM where its safer to execute
39  * R1 = SRAM destination address.
40  *************************************************************************/
41 .global cpy_clk_code
42  cpy_clk_code:
43         /* Copy DPLL code into SRAM */
44         adr     r0, go_to_speed         /* get addr of clock setting code */
45         mov     r2, #384                /* r2 size to copy (div by 32 bytes) */
46         mov     r1, r1                  /* r1 <- dest address (passed in) */
47         add     r2, r2, r0              /* r2 <- source end address */
48 next2:
49         ldmia   r0!, {r3-r10}           /* copy from source address [r0]    */
50         stmia   r1!, {r3-r10}           /* copy to   target address [r1]    */
51         cmp     r0, r2                  /* until source end address [r2]    */
52         bne     next2
53         mov     pc, lr                  /* back to caller */
54
55 /* ****************************************************************************
56  * NOTE: 3430 X-loader currently does not use this code.
57 *   It could be removed its is kept for compatabily with u-boot.
58  *
59  *  go_to_speed: -Moves to bypass, -Commits clock dividers, -puts dpll at speed
60  *               -executed from SRAM.
61  *  R0 = CM_CLKEN_PLL-bypass value
62  *  R1 = CM_CLKSEL1_PLL-m, n, and divider values
63  *  R2 = CM_CLKSEL_CORE-divider values
64  *  R3 = CM_IDLEST_CKGEN - addr dpll lock wait
65  *
66  *  Note: If core unlocks/relocks and SDRAM is running fast already it gets
67  *        confused.  A reset of the controller gets it back.  Taking away its
68  *        L3 when its not in self refresh seems bad for it.  Normally, this code
69  *        runs from flash before SDR is init so that should be ok.
70  ******************************************************************************/
71 .global go_to_speed
72  go_to_speed:
73         stmfd sp!, {r4-r6}
74
75         /* move into fast relock bypass */
76         ldr     r4, pll_ctl_add
77         str     r0, [r4]
78 wait1:
79         ldr     r5, [r3]       /* get status */
80         and     r5, r5, #0x1   /* isolate core status */
81         cmp     r5, #0x1       /* still locked? */
82         beq     wait1          /* if lock, loop */
83
84         /* set new dpll dividers _after_ in bypass */
85         ldr     r5, pll_div_add1
86         str     r1, [r5]          /* set m, n, m2 */
87         ldr     r5, pll_div_add2
88         str     r2, [r5]          /* set l3/l4/.. dividers*/
89         ldr     r5, pll_div_add3  /* wkup */
90         ldr     r2, pll_div_val3  /* rsm val */
91         str     r2, [r5]
92         ldr     r5, pll_div_add4  /* gfx */
93         ldr     r2, pll_div_val4
94         str     r2, [r5]
95         ldr     r5, pll_div_add5  /* emu */
96         ldr     r2, pll_div_val5
97         str     r2, [r5]
98
99         /* now prepare GPMC (flash) for new dpll speed */
100         /* flash needs to be stable when we jump back to it */
101         ldr     r5, flash_cfg3_addr
102         ldr     r2, flash_cfg3_val
103         str     r2, [r5]
104         ldr     r5, flash_cfg4_addr
105         ldr     r2, flash_cfg4_val
106         str     r2, [r5]
107         ldr     r5, flash_cfg5_addr
108         ldr     r2, flash_cfg5_val
109         str     r2, [r5]
110         ldr     r5, flash_cfg1_addr
111         ldr     r2, [r5]
112         orr     r2, r2, #0x3     /* up gpmc divider */
113         str     r2, [r5]
114
115         /* lock DPLL3 and wait a bit */
116         orr     r0, r0, #0x7   /* set up for lock mode */
117         str     r0, [r4]       /* lock */
118         nop                    /* ARM slow at this point working at sys_clk */
119         nop
120         nop
121         nop
122 wait2:
123         ldr     r5, [r3]       /* get status */
124         and     r5, r5, #0x1   /* isolate core status */
125         cmp     r5, #0x1       /* still locked? */
126         bne     wait2          /* if lock, loop */
127         nop
128         nop
129         nop
130         nop
131         ldmfd sp!, {r4-r6}
132         mov     pc, lr           /* back to caller, locked */
133
134 _go_to_speed: .word go_to_speed
135
136 /* these constants need to be close for PIC code */
137 /* The Nor has to be in the Flash Base CS0 for this condition to happen */
138 flash_cfg1_addr:
139     .word (GPMC_CONFIG_CS0 + GPMC_CONFIG1)
140 flash_cfg3_addr:
141     .word  (GPMC_CONFIG_CS0 + GPMC_CONFIG3)
142 flash_cfg3_val:
143     .word  STNOR_GPMC_CONFIG3
144 flash_cfg4_addr:
145     .word (GPMC_CONFIG_CS0 + GPMC_CONFIG4)
146 flash_cfg4_val:
147     .word  STNOR_GPMC_CONFIG4
148 flash_cfg5_val:
149     .word  STNOR_GPMC_CONFIG5
150 flash_cfg5_addr:
151     .word (GPMC_CONFIG_CS0 + GPMC_CONFIG5)
152 pll_ctl_add:
153     .word CM_CLKEN_PLL
154 pll_div_add1:
155     .word CM_CLKSEL1_PLL
156 pll_div_add2:
157     .word CM_CLKSEL_CORE
158 pll_div_add3:
159     .word CM_CLKSEL_WKUP
160 pll_div_val3:
161     .word (WKUP_RSM << 1)
162 pll_div_add4:
163     .word CM_CLKSEL_GFX
164 pll_div_val4:
165     .word (GFX_DIV << 0)
166 pll_div_add5:
167     .word CM_CLKSEL1_EMU
168 pll_div_val5:
169     .word CLSEL1_EMU_VAL
170
171 #endif
172
173 .globl lowlevel_init
174 lowlevel_init:
175         ldr     sp,     SRAM_STACK
176         str     ip,     [sp]    /* stash old link register */
177         mov     ip,     lr      /* save link reg across call */
178         bl      s_init          /* go setup pll,mux,memory */
179         ldr     ip,     [sp]    /* restore save ip */
180         mov     lr,     ip      /* restore link reg */
181
182         /* back to arch calling code */
183         mov     pc,     lr
184
185         /* the literal pools origin */
186         .ltorg
187
188 REG_CONTROL_STATUS:
189         .word CONTROL_STATUS
190 SRAM_STACK:
191         .word LOW_LEVEL_SRAM_STACK
192
193
194 /* DPLL(1-4) PARAM TABLES */
195 /* Each of the tables has M, N, FREQSEL, M2 values defined for nominal
196  * OPP (1.2V). The fields are defined according to dpll_param struct(clock.c).
197  * The values are defined for all possible sysclk and for ES1 and ES2.
198  */
199
200 mpu_dpll_param:
201 /* 12MHz */
202 /* ES1 */
203 .word 0x0FE
204 .word 0x07
205 .word 0x05
206 .word 0x01
207 /* ES2 */
208 .word 0x0FA
209 .word 0x05
210 .word 0x07
211 .word 0x01
212
213 /* 13MHz */
214 /* ES1 */
215 .word 0x17D
216 .word 0x0C
217 .word 0x03
218 .word 0x01
219 /* ES2 */
220 .word 0x1F4
221 .word 0x0C
222 .word 0x03
223 .word 0x01
224
225 /* 19.2MHz */
226 /* ES1 */
227 .word 0x179
228 .word 0x12
229 .word 0x04
230 .word 0x01
231 /* ES2 */
232 .word 0x271
233 .word 0x17
234 .word 0x03
235 .word 0x01
236
237 /* 26MHz */
238 /* ES1 */
239 .word 0x17D
240 .word 0x19
241 .word 0x03
242 .word 0x01
243 /* ES2 */
244 .word 0x0FA
245 .word 0x0C
246 .word 0x07
247 .word 0x01
248
249 /* 38.4MHz */
250 /* ES1 */
251 .word 0x1FA
252 .word 0x32
253 .word 0x03
254 .word 0x01
255 /* ES2 */
256 .word 0x271
257 .word 0x2F
258 .word 0x03
259 .word 0x01
260
261
262 .globl get_mpu_dpll_param
263 get_mpu_dpll_param:
264         adr r0, mpu_dpll_param
265         mov pc, lr
266
267 iva_dpll_param:
268 /* 12MHz */
269 /* ES1 */
270 .word 0x07D
271 .word 0x05
272 .word 0x07
273 .word 0x01
274 /* ES2 */
275 .word 0x0B4
276 .word 0x05
277 .word 0x07
278 .word 0x01
279
280 /* 13MHz */
281 /* ES1 */
282 .word 0x0FA
283 .word 0x0C
284 .word 0x03
285 .word 0x01
286 /* ES2 */
287 .word 0x168
288 .word 0x0C
289 .word 0x03
290 .word 0x01
291
292 /* 19.2MHz */
293 /* ES1 */
294 .word 0x082
295 .word 0x09
296 .word 0x07
297 .word 0x01
298 /* ES2 */
299 .word 0x0E1
300 .word 0x0B
301 .word 0x06
302 .word 0x01
303
304 /* 26MHz */
305 /* ES1 */
306 .word 0x07D
307 .word 0x0C
308 .word 0x07
309 .word 0x01
310 /* ES2 */
311 .word 0x0B4
312 .word 0x0C
313 .word 0x07
314 .word 0x01
315
316 /* 38.4MHz */
317 /* ES1 */
318 .word 0x13F
319 .word 0x30
320 .word 0x03
321 .word 0x01
322 /* ES2 */
323 .word 0x0E1
324 .word 0x17
325 .word 0x06
326 .word 0x01
327
328
329 .globl get_iva_dpll_param
330 get_iva_dpll_param:
331         adr r0, iva_dpll_param
332         mov pc, lr
333
334 core_dpll_param:
335 /* 12MHz */
336 /* ES1 */
337 .word 0x19F
338 .word 0x0E
339 .word 0x03
340 .word 0x01
341 /* ES2 */
342 .word 0x0A6
343 .word 0x05
344 .word 0x07
345 .word 0x01
346
347 /* 13MHz */
348 /* ES1 */
349 .word 0x1B2
350 .word 0x10
351 .word 0x03
352 .word 0x01
353 /* ES2 */
354 .word 0x14C
355 .word 0x0C
356 .word 0x03
357 .word 0x01
358
359 /* 19.2MHz */
360 /* ES1 */
361 .word 0x19F
362 .word 0x17
363 .word 0x03
364 .word 0x01
365 /* ES2 */
366 .word 0x19F
367 .word 0x17
368 .word 0x03
369 .word 0x01
370
371 /* 26MHz */
372 /* ES1 */
373 .word 0x1B2
374 .word 0x21
375 .word 0x03
376 .word 0x01
377 /* ES2 */
378 .word 0x0A6
379 .word 0x0C
380 .word 0x07
381 .word 0x01
382
383 /* 38.4MHz */
384 /* ES1 */
385 .word 0x19F
386 .word 0x2F
387 .word 0x03
388 .word 0x01
389 /* ES2 */
390 .word 0x19F
391 .word 0x2F
392 .word 0x03
393 .word 0x01
394
395 .globl get_core_dpll_param
396 get_core_dpll_param:
397         adr r0, core_dpll_param
398         mov pc, lr
399
400 /* PER DPLL values are same for both ES1 and ES2 */
401 per_dpll_param:
402 /* 12MHz */
403 .word 0xD8
404 .word 0x05
405 .word 0x07
406 .word 0x09
407
408 /* 13MHz */
409 .word 0x1B0
410 .word 0x0C
411 .word 0x03
412 .word 0x09
413
414 /* 19.2MHz */
415 .word 0xE1
416 .word 0x09
417 .word 0x07
418 .word 0x09
419
420 /* 26MHz */
421 .word 0xD8
422 .word 0x0C
423 .word 0x07
424 .word 0x09
425
426 /* 38.4MHz */
427 .word 0xE1
428 .word 0x13
429 .word 0x07
430 .word 0x09
431
432 .globl get_per_dpll_param
433 get_per_dpll_param:
434         adr r0, per_dpll_param
435         mov pc, lr