]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/mx5/lowlevel_init.S
improve register utilisation
[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 #else
186         ldr r1, =0x3FFFFFFF
187         str r1, [r0, #CLKCTL_CCGR0]
188         ldr r1, =0x0
189         str r1, [r0, #CLKCTL_CCGR1]
190         str r1, [r0, #CLKCTL_CCGR2]
191         str r1, [r0, #CLKCTL_CCGR3]
192         str r1, [r0, #CLKCTL_CCGR7]
193
194         ldr r1, =0x00030000
195         str r1, [r0, #CLKCTL_CCGR4]
196         ldr r1, =0x00FFF030
197         str r1, [r0, #CLKCTL_CCGR5]
198         ldr r1, =0x0F00030F
199         str r1, [r0, #CLKCTL_CCGR6]
200 #endif
201
202         /* Switch ARM to step clock */
203         mov r1, #0x4
204         str r1, [r0, #CLKCTL_CCSR]
205
206 #if defined(CONFIG_MX51_PLL_ERRATA)
207         setup_pll PLL1_BASE_ADDR, 864
208         setup_pll_errata PLL1_BASE_ADDR, W_DP_MFN_800_DIT
209 #else
210 #if !defined(CONFIG_SYS_CPU_CLK) || CONFIG_SYS_CPU_CLK == 800
211         setup_pll PLL1_BASE_ADDR, 800
212 #elif CONFIG_SYS_CPU_CLK == 600
213         setup_pll PLL1_BASE_ADDR, 600
214 #else
215 #error Unsupported CONFIG_SYS_CPU_CLK value
216 #endif
217 #endif
218
219 #if defined(CONFIG_MX51)
220         setup_pll PLL3_BASE_ADDR, 665
221
222         /* Switch peripheral to PLL 3 */
223         ldr r1, =0x000010C0
224         orr r1, r1, #CONFIG_SYS_DDR_CLKSEL
225         str r1, [r0, #CLKCTL_CBCMR]
226         ldr r1, =0x13239145
227         str r1, [r0, #CLKCTL_CBCDR]
228         setup_pll PLL2_BASE_ADDR, 665
229
230         /* Switch peripheral to PLL2 */
231         ldr r1, =0x19239145
232         str r1, [r0, #CLKCTL_CBCDR]
233         ldr r1, =0x000020C0
234         orr r1,r1,#CONFIG_SYS_DDR_CLKSEL
235         str r1, [r0, #CLKCTL_CBCMR]
236 #endif
237         setup_pll PLL3_BASE_ADDR, 216
238
239         /* Set the platform clock dividers */
240         ldr r0, =ARM_BASE_ADDR
241         ldr r1, =0x00000725
242         str r1, [r0, #0x14]
243
244         ldr r0, =CCM_BASE_ADDR
245
246 #if defined(CONFIG_MX51)
247         /* Run 3.0 at Full speed, for other TO's wait till we increase VDDGP */
248         ldr r1, =0x0
249         ldr r3, [r1, #ROM_SI_REV]
250         cmp r3, #0x10
251         movls r1, #0x1
252         movhi r1, #0
253 #else
254         mov r1, #0
255 #endif
256         str r1, [r0, #CLKCTL_CACRR]
257         /* Switch ARM back to PLL 1 */
258         mov r1, #0
259         str r1, [r0, #CLKCTL_CCSR]
260
261 #if defined(CONFIG_MX51)
262         /* setup the rest */
263         /* Use lp_apm (24MHz) source for perclk */
264         ldr r1, =0x000020C2
265         orr r1,r1,#CONFIG_SYS_DDR_CLKSEL
266         str r1, [r0, #CLKCTL_CBCMR]
267         /* ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz */
268         ldr r1, =CONFIG_SYS_CLKTL_CBCDR
269         str r1, [r0, #CLKCTL_CBCDR]
270 #endif
271
272         /* Restore the default values in the Gate registers */
273         ldr r1, =0xFFFFFFFF
274         str r1, [r0, #CLKCTL_CCGR0]
275         str r1, [r0, #CLKCTL_CCGR1]
276         str r1, [r0, #CLKCTL_CCGR2]
277         str r1, [r0, #CLKCTL_CCGR3]
278         str r1, [r0, #CLKCTL_CCGR4]
279         str r1, [r0, #CLKCTL_CCGR5]
280         str r1, [r0, #CLKCTL_CCGR6]
281 #if defined(CONFIG_MX53)
282         str r1, [r0, #CLKCTL_CCGR7]
283 #endif
284
285 #if defined(CONFIG_MX51)
286         /* Use PLL 2 for UART's, get 66.5MHz from it */
287         ldr r1, =0xA5A2A020
288         str r1, [r0, #CLKCTL_CSCMR1]
289         ldr r1, =0x00C30321
290         str r1, [r0, #CLKCTL_CSCDR1]
291 #elif defined(CONFIG_MX53)
292         /* Switch peripheral to PLL2 */
293         ldr r1, =0x00808145
294         orr r1, r1, #(2 << 10)
295         orr r1, r1, #(0 << 16)
296         orr r1, r1, #(1 << 19)
297         str r1, [r0, #CLKCTL_CBCDR]
298
299         ldr r1, =0x00016154
300         str r1, [r0, #CLKCTL_CBCMR]
301         /* Change uart clk parent to pll2*/
302         ldr r1, [r0, #CLKCTL_CSCMR1]
303         bic r1, #(0x3 << 24)
304         orr r1, r1, #(0x1 << 24)
305         str r1, [r0, #CLKCTL_CSCMR1]
306         ldr r1, [r0, #CLKCTL_CSCDR1]
307         bic r1, #(0x3f << 0)
308         orr r1, r1, #0x0a
309         str r1, [r0, #CLKCTL_CSCDR1]
310 #endif
311         /* make sure divider effective */
312 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
313         cmp r1, #0x0
314         bne 1b
315
316         mov r1, #0x0
317         str r1, [r0, #CLKCTL_CCDR]
318
319         /* for cko - for ARM div by 8 */
320         mov r1, #0x000A0000
321         add r1, r1, #0x00000F0
322         str r1, [r0, #CLKCTL_CCOSR]
323 .endm
324
325 .macro setup_wdog
326         ldr r0, =WDOG1_BASE_ADDR
327         mov r1, #0x30
328         strh r1, [r0]
329 .endm
330
331 .section ".text.init", "x"
332
333 ENTRY(lowlevel_init)
334 #if defined(CONFIG_MX51)
335         ldr r0, =GPIO1_BASE_ADDR
336         ldr r1, [r0, #0x0]
337         orr r1, r1, #(1 << 23)
338         str r1, [r0, #0x0]
339         ldr r1, [r0, #0x4]
340         orr r1, r1, #(1 << 23)
341         str r1, [r0, #0x4]
342 #endif
343
344         init_l2cc
345
346         init_aips
347
348         init_m4if
349
350         init_clock
351
352         /* r12 saved upper lr*/
353         mov pc,lr
354 ENDPROC(lowlevel_init)
355
356 /* Board level setting value */
357 W_DP_OP_864:              .word DP_OP_864
358 W_DP_MFD_864:             .word DP_MFD_864
359 W_DP_MFN_864:             .word DP_MFN_864
360 W_DP_MFN_800_DIT:         .word DP_MFN_800_DIT
361 W_DP_OP_800:              .word DP_OP_800
362 W_DP_MFD_800:             .word DP_MFD_800
363 W_DP_MFN_800:             .word DP_MFN_800
364 W_DP_OP_665:              .word DP_OP_665
365 W_DP_MFD_665:             .word DP_MFD_665
366 W_DP_MFN_665:             .word DP_MFN_665
367 W_DP_OP_600:              .word DP_OP_600
368 W_DP_MFD_600:             .word DP_MFD_600
369 W_DP_MFN_600:             .word DP_MFN_600
370 W_DP_OP_216:              .word DP_OP_216
371 W_DP_MFD_216:             .word DP_MFD_216
372 W_DP_MFN_216:             .word DP_MFN_216