]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/mx5/lowlevel_init.S
Unified codebase for TX28, TX48, TX51, TX53
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / mx5 / lowlevel_init.S
1 /*
2  * Copyright (C) 2007, Guennadi Liakhovetski <lg@denx.de>
3  *
4  * (C) Copyright 2009 Freescale Semiconductor, Inc.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307 USA
20  */
21
22 #include <config.h>
23 #include <asm/arch/imx-regs.h>
24 #include <generated/asm-offsets.h>
25 #include <linux/linkage.h>
26
27 /*
28  * L2CC Cache setup/invalidation/disable
29  */
30 .macro init_l2cc
31         /* explicitly disable L2 cache */
32         mrc 15, 0, r0, c1, c0, 1
33         bic r0, r0, #0x2
34         mcr 15, 0, r0, c1, c0, 1
35
36         /* reconfigure L2 cache aux control reg */
37         mov r0, #0xC0                   /* tag RAM */
38         add r0, r0, #0x4                /* data RAM */
39         orr r0, r0, #(1 << 24)          /* disable write allocate delay */
40         orr r0, r0, #(1 << 23)          /* disable write allocate combine */
41         orr r0, r0, #(1 << 22)          /* disable write allocate */
42
43 #if defined(CONFIG_MX51)
44         ldr r1, =0x0
45         ldr r3, [r1, #ROM_SI_REV]
46         cmp r3, #0x10
47
48         /* disable write combine for TO 2 and lower revs */
49         orrls r0, r0, #(1 << 25)
50 #endif
51
52         mcr 15, 1, r0, c9, c0, 2
53 .endm /* init_l2cc */
54
55 /* AIPS setup - Only setup MPROTx registers.
56  * The PACR default values are good.*/
57 .macro init_aips
58         /*
59          * Set all MPROTx to be non-bufferable, trusted for R/W,
60          * not forced to user-mode.
61          */
62         ldr r0, =AIPS1_BASE_ADDR
63         ldr r1, =0x77777777
64         str r1, [r0, #0x0]
65         str r1, [r0, #0x4]
66         ldr r0, =AIPS2_BASE_ADDR
67         str r1, [r0, #0x0]
68         str r1, [r0, #0x4]
69         /*
70          * Clear the on and off peripheral modules Supervisor Protect bit
71          * for SDMA to access them. Did not change the AIPS control registers
72          * (offset 0x20) access type
73          */
74 .endm /* init_aips */
75
76 /* M4IF setup */
77 .macro init_m4if
78 #ifdef CONFIG_MX51
79         /* VPU and IPU given higher priority (0x4)
80          * IPU accesses with ID=0x1 given highest priority (=0xA)
81          */
82         ldr r0, =M4IF_BASE_ADDR
83
84         ldr r1, =0x00000203
85         str r1, [r0, #0x40]
86
87         ldr r1, =0x0
88         str r1, [r0, #0x44]
89
90         ldr r1, =0x00120125
91         str r1, [r0, #0x9C]
92
93         ldr r1, =0x001901A3
94         str r1, [r0, #0x48]
95
96 #endif
97 .endm /* init_m4if */
98
99 .macro setup_pll pll, freq
100         ldr r2, =\pll
101         ldr r1, =0x00001232
102         str r1, [r2, #PLL_DP_CTL] /* Set DPLL ON (set UPEN bit): BRMO=1 */
103         mov r1, #0x2
104         str r1, [r2, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
105
106         ldr r1, W_DP_OP_\freq
107         str r1, [r2, #PLL_DP_OP]
108         str r1, [r2, #PLL_DP_HFS_OP]
109
110         ldr r1, W_DP_MFD_\freq
111         str r1, [r2, #PLL_DP_MFD]
112         str r1, [r2, #PLL_DP_HFS_MFD]
113
114         ldr r1,  W_DP_MFN_\freq
115         str r1, [r2, #PLL_DP_MFN]
116         str r1, [r2, #PLL_DP_HFS_MFN]
117
118         ldr r1, =0x00001232
119         str r1, [r2, #PLL_DP_CTL]
120 101:
121         ldr r1, [r2, #PLL_DP_CTL]
122         ands r1, r1, #0x1
123         beq 101b
124 .endm
125
126 .macro setup_pll_errata pll, freq
127         ldr r2, =\pll
128         mov r1, #0x0
129         str r1, [r2, #PLL_DP_CONFIG] /* Disable auto-restart AREN bit */
130         ldr r1, =0x00001236
131         str r1, [r2, #PLL_DP_CTL]    /* Restart PLL with PLM=1 */
132 1:      ldr r1, [r2, #PLL_DP_CTL]    /* Wait for lock */
133         ands r1, r1, #0x1
134         beq 1b
135
136         ldr r5, \freq
137         str r5, [r2, #PLL_DP_MFN]    /* Modify MFN value */
138         str r5, [r2, #PLL_DP_HFS_MFN]
139
140         mov r1, #0x1
141         str r1, [r2, #PLL_DP_CONFIG] /* Reload MFN value */
142
143 2:      ldr r1, [r2, #PLL_DP_CONFIG]
144         tst r1, #1
145         bne 2b
146
147         ldr r1, =100                 /* Wait at least 4 us */
148 3:      subs r1, r1, #1
149         bge 3b
150
151         mov r1, #0x2
152         str r1, [r2, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
153 .endm
154
155 .macro init_clock
156         ldr r0, =CCM_BASE_ADDR
157
158 #if defined(CONFIG_MX51)
159         /* Gate of clocks to the peripherals first */
160         ldr r1, =0x3FFFFFFF
161         str r1, [r0, #CLKCTL_CCGR0]
162         ldr r1, =0x0
163         str r1, [r0, #CLKCTL_CCGR1]
164         str r1, [r0, #CLKCTL_CCGR2]
165         str r1, [r0, #CLKCTL_CCGR3]
166
167         ldr r1, =0x00030000
168         str r1, [r0, #CLKCTL_CCGR4]
169         ldr r1, =0x00FFF030
170         str r1, [r0, #CLKCTL_CCGR5]
171         ldr r1, =0x00000300
172         str r1, [r0, #CLKCTL_CCGR6]
173
174         /* Disable IPU and HSC dividers */
175         mov r1, #0x60000
176         str r1, [r0, #CLKCTL_CCDR]
177
178         /* Make sure to switch the DDR away from PLL 1 */
179         ldr r1, =0x19239145
180         str r1, [r0, #CLKCTL_CBCDR]
181         /* make sure divider effective */
182 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
183         cmp r1, #0x0
184         bne 1b
185 #elif defined(CONFIG_TX53)
186         @ CCGR registers have been setup via DCD
187 #else
188         ldr r1, =0x3FFFFFFF
189         str r1, [r0, #CLKCTL_CCGR0]
190         ldr r1, =0x0
191         str r1, [r0, #CLKCTL_CCGR1]
192         str r1, [r0, #CLKCTL_CCGR2]
193         str r1, [r0, #CLKCTL_CCGR3]
194         str r1, [r0, #CLKCTL_CCGR7]
195
196         ldr r1, =0x00030000
197         str r1, [r0, #CLKCTL_CCGR4]
198         ldr r1, =0x00FFF030
199         str r1, [r0, #CLKCTL_CCGR5]
200         ldr r1, =0x0F00030F
201         str r1, [r0, #CLKCTL_CCGR6]
202 #endif
203
204         /* Switch ARM to step clock */
205         mov r1, #0x4
206         str r1, [r0, #CLKCTL_CCSR]
207
208 #if defined(CONFIG_MX51_PLL_ERRATA)
209         setup_pll PLL1_BASE_ADDR, 864
210         setup_pll_errata PLL1_BASE_ADDR, W_DP_MFN_800_DIT
211 #else
212 #if !defined(CONFIG_SYS_CPU_CLK) || CONFIG_SYS_CPU_CLK == 800
213         setup_pll PLL1_BASE_ADDR, 800
214 #elif CONFIG_SYS_CPU_CLK == 600
215         setup_pll PLL1_BASE_ADDR, 600
216 #else
217 #error Unsupported CONFIG_SYS_CPU_CLK value
218 #endif
219 #endif
220
221 #if defined(CONFIG_MX51)
222         setup_pll PLL3_BASE_ADDR, 665
223
224         /* Switch peripheral to PLL 3 */
225         ldr r1, =0x000010C0
226         orr r1, r1, #CONFIG_SYS_DDR_CLKSEL
227         str r1, [r0, #CLKCTL_CBCMR]
228         ldr r1, =0x13239145
229         str r1, [r0, #CLKCTL_CBCDR]
230         setup_pll PLL2_BASE_ADDR, 665
231
232         /* Switch peripheral to PLL2 */
233         ldr r1, =0x19239145
234         str r1, [r0, #CLKCTL_CBCDR]
235         ldr r1, =0x000020C0
236         orr r1,r1,#CONFIG_SYS_DDR_CLKSEL
237         str r1, [r0, #CLKCTL_CBCMR]
238 #elif defined(CONFIG_TX53)
239         setup_pll PLL3_BASE_ADDR, 400
240
241         /* Switch peripheral to PLL 3 */
242         ldr r1, [r0, #CLKCTL_CBCMR]
243         bic r1, #(0x3 << 12)
244         orr r1, r1, #(1 << 12)
245         str r1, [r0, #CLKCTL_CBCMR]
246
247         ldr r1, [r0, #CLKCTL_CBCDR]
248         orr r1, r1, #(1 << 25)
249         str r1, [r0, #CLKCTL_CBCDR]
250 1:
251         /* make sure change is effective */
252         ldr     r1, [r0, #CLKCTL_CDHIPR]
253         tst     r1, #0x7f
254         bne     1b
255 #if CONFIG_SYS_SDRAM_CLK == 400
256         setup_pll PLL2_BASE_ADDR, 400
257 #elif CONFIG_SYS_SDRAM_CLK == 333
258         setup_pll PLL2_BASE_ADDR, 333
259 #else
260 #error Unsupported CONFIG_SYS_SDRAM_CLK
261 #endif
262         /* Switch peripheral to PLL2 */
263         ldr r0, =CCM_BASE_ADDR
264         ldr r1, [r0, #CLKCTL_CBCDR]
265         bic r1, #(1 << 25)
266         str r1, [r0, #CLKCTL_CBCDR]
267
268         ldr r1, [r0, #CLKCTL_CBCMR]
269         bic r1, #(3 << 12)
270         orr r1, #(2 << 12)
271         str r1, [r0, #CLKCTL_CBCMR]
272
273         /* make sure change is effective */
274 1:
275         ldr     r1, [r0, #CLKCTL_CDHIPR]
276         cmp     r1, #0x0
277         bne     1b
278 #endif
279         setup_pll PLL3_BASE_ADDR, 216
280
281         /* Set the platform clock dividers */
282         ldr r0, =ARM_BASE_ADDR
283         ldr r1, =0x00000725
284         str r1, [r0, #0x14]
285
286         ldr r0, =CCM_BASE_ADDR
287
288 #if defined(CONFIG_MX51)
289         /* Run 3.0 at Full speed, for other TO's wait till we increase VDDGP */
290         ldr r1, =0x0
291         ldr r3, [r1, #ROM_SI_REV]
292         cmp r3, #0x10
293         movls r1, #0x1
294         movhi r1, #0
295 #else
296         mov r1, #0
297 #endif
298         str r1, [r0, #CLKCTL_CACRR]
299         /* Switch ARM back to PLL 1 */
300         mov r1, #0
301         str r1, [r0, #CLKCTL_CCSR]
302
303 #if defined(CONFIG_MX51)
304         /* setup the rest */
305         /* Use lp_apm (24MHz) source for perclk */
306         ldr r1, =0x000020C2
307         orr r1,r1,#CONFIG_SYS_DDR_CLKSEL
308         str r1, [r0, #CLKCTL_CBCMR]
309         /* ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz */
310         ldr r1, =CONFIG_SYS_CLKTL_CBCDR
311         str r1, [r0, #CLKCTL_CBCDR]
312 #endif
313 #ifndef CONFIG_TX53
314         /* Restore the default values in the Gate registers */
315         ldr r1, =0xFFFFFFFF
316         str r1, [r0, #CLKCTL_CCGR0]
317         str r1, [r0, #CLKCTL_CCGR1]
318         str r1, [r0, #CLKCTL_CCGR2]
319         str r1, [r0, #CLKCTL_CCGR3]
320         str r1, [r0, #CLKCTL_CCGR4]
321         str r1, [r0, #CLKCTL_CCGR5]
322         str r1, [r0, #CLKCTL_CCGR6]
323 #if defined(CONFIG_MX53)
324         str r1, [r0, #CLKCTL_CCGR7]
325 #endif
326 #endif
327
328 #if !defined(CONFIG_TX53)
329 #if defined(CONFIG_MX51)
330         /* Use PLL 2 for UART's, get 66.5MHz from it */
331         ldr r1, =0xA5A2A020
332         str r1, [r0, #CLKCTL_CSCMR1]
333         ldr r1, =0x00C30321
334         str r1, [r0, #CLKCTL_CSCDR1]
335 #elif defined(CONFIG_MX53)
336         /* Switch peripheral to PLL2 */
337         ldr r1, =0x00808145
338         orr r1, r1, #(2 << 10)
339         orr r1, r1, #(0 << 16)
340         orr r1, r1, #(1 << 19)
341         str r1, [r0, #CLKCTL_CBCDR]
342
343         ldr r1, =0x00016154
344         str r1, [r0, #CLKCTL_CBCMR]
345         /* Change uart clk parent to pll2*/
346         ldr r1, [r0, #CLKCTL_CSCMR1]
347         bic r1, #(0x3 << 24)
348         orr r1, r1, #(0x1 << 24)
349         str r1, [r0, #CLKCTL_CSCMR1]
350         ldr r1, [r0, #CLKCTL_CSCDR1]
351         bic r1, #(0x3f << 0)
352         orr r1, r1, #0x0a
353         str r1, [r0, #CLKCTL_CSCDR1]
354 #endif
355         /* make sure divider effective */
356 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
357         cmp r1, #0x0
358         bne 1b
359 #endif
360         mov r1, #0x0
361         str r1, [r0, #CLKCTL_CCDR]
362
363         /* for cko - for ARM div by 8 */
364         mov r1, #0x000A0000
365         add r1, r1, #0x00000F0
366         str r1, [r0, #CLKCTL_CCOSR]
367 .endm
368
369 .macro setup_wdog
370         ldr r0, =WDOG1_BASE_ADDR
371         mov r1, #0x30
372         strh r1, [r0]
373 .endm
374
375 .section ".text.init", "x"
376
377 ENTRY(lowlevel_init)
378 #if defined(CONFIG_MX51)
379         ldr r0, =GPIO1_BASE_ADDR
380         ldr r1, [r0, #0x0]
381         orr r1, r1, #(1 << 23)
382         str r1, [r0, #0x0]
383         ldr r1, [r0, #0x4]
384         orr r1, r1, #(1 << 23)
385         str r1, [r0, #0x4]
386 #endif
387
388         init_l2cc
389
390         init_aips
391
392         init_m4if
393
394         init_clock
395
396         /* r12 saved upper lr*/
397         mov pc,lr
398 ENDPROC(lowlevel_init)
399
400 /* Board level setting value */
401 W_DP_OP_864:              .word DP_OP_864
402 W_DP_MFD_864:             .word DP_MFD_864
403 W_DP_MFN_864:             .word DP_MFN_864
404 W_DP_MFN_800_DIT:         .word DP_MFN_800_DIT
405 W_DP_OP_800:              .word DP_OP_800
406 W_DP_MFD_800:             .word DP_MFD_800
407 W_DP_MFN_800:             .word DP_MFN_800
408 W_DP_OP_665:              .word DP_OP_665
409 W_DP_MFD_665:             .word DP_MFD_665
410 W_DP_MFN_665:             .word DP_MFN_665
411 W_DP_OP_600:              .word DP_OP_600
412 W_DP_MFD_600:             .word DP_MFD_600
413 W_DP_MFN_600:             .word DP_MFN_600
414 W_DP_OP_400:              .word DP_OP_400
415 W_DP_MFD_400:             .word DP_MFD_400
416 W_DP_MFN_400:             .word DP_MFN_400
417 W_DP_OP_333:              .word DP_OP_333
418 W_DP_MFD_333:             .word DP_MFD_333
419 W_DP_MFN_333:             .word DP_MFN_333
420 W_DP_OP_216:              .word DP_OP_216
421 W_DP_MFD_216:             .word DP_MFD_216
422 W_DP_MFN_216:             .word DP_MFN_216