blob: d62093be56f2d47f319498538455598dba7477da [file] [log] [blame]
Stefano Babica521a772010-01-20 18:19:32 +01001/*
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>
Stefano Babic2a1f1ac2011-09-05 04:32:28 +000024#include <generated/asm-offsets.h>
Aneesh Vfd8798b2012-03-08 07:20:18 +000025#include <linux/linkage.h>
Stefano Babica521a772010-01-20 18:19:32 +010026
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +000027.section ".text.init", "x"
28
Stefano Babica521a772010-01-20 18:19:32 +010029/*
30 * L2CC Cache setup/invalidation/disable
31 */
32.macro init_l2cc
33 /* explicitly disable L2 cache */
34 mrc 15, 0, r0, c1, c0, 1
35 bic r0, r0, #0x2
36 mcr 15, 0, r0, c1, c0, 1
37
38 /* reconfigure L2 cache aux control reg */
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +000039 ldr r0, =0xC0 | /* tag RAM */ \
40 0x4 | /* data RAM */ \
41 1 << 24 | /* disable write allocate delay */ \
42 1 << 23 | /* disable write allocate combine */ \
43 1 << 22 /* disable write allocate */
Stefano Babica521a772010-01-20 18:19:32 +010044
David Janderdd6f7872011-07-14 03:58:57 +000045#if defined(CONFIG_MX51)
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +000046 ldr r3, [r4, #ROM_SI_REV]
David Janderdd6f7872011-07-14 03:58:57 +000047 cmp r3, #0x10
Stefano Babica521a772010-01-20 18:19:32 +010048
49 /* disable write combine for TO 2 and lower revs */
Benoît Thébaudeau118e0bc2012-08-14 05:18:43 +000050 orrls r0, r0, #1 << 25
David Janderdd6f7872011-07-14 03:58:57 +000051#endif
Stefano Babica521a772010-01-20 18:19:32 +010052
53 mcr 15, 1, r0, c9, c0, 2
54.endm /* init_l2cc */
55
56/* AIPS setup - Only setup MPROTx registers.
57 * The PACR default values are good.*/
58.macro init_aips
59 /*
60 * Set all MPROTx to be non-bufferable, trusted for R/W,
61 * not forced to user-mode.
62 */
63 ldr r0, =AIPS1_BASE_ADDR
64 ldr r1, =0x77777777
65 str r1, [r0, #0x0]
66 str r1, [r0, #0x4]
67 ldr r0, =AIPS2_BASE_ADDR
68 str r1, [r0, #0x0]
69 str r1, [r0, #0x4]
70 /*
71 * Clear the on and off peripheral modules Supervisor Protect bit
72 * for SDMA to access them. Did not change the AIPS control registers
73 * (offset 0x20) access type
74 */
75.endm /* init_aips */
76
77/* M4IF setup */
78.macro init_m4if
Liu Hui-R64343baa2d782011-01-03 22:27:35 +000079#ifdef CONFIG_MX51
Stefano Babica521a772010-01-20 18:19:32 +010080 /* VPU and IPU given higher priority (0x4)
81 * IPU accesses with ID=0x1 given highest priority (=0xA)
82 */
83 ldr r0, =M4IF_BASE_ADDR
84
85 ldr r1, =0x00000203
86 str r1, [r0, #0x40]
87
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +000088 str r4, [r0, #0x44]
Stefano Babica521a772010-01-20 18:19:32 +010089
90 ldr r1, =0x00120125
91 str r1, [r0, #0x9C]
92
93 ldr r1, =0x001901A3
94 str r1, [r0, #0x48]
95
Liu Hui-R64343baa2d782011-01-03 22:27:35 +000096#endif
Stefano Babica521a772010-01-20 18:19:32 +010097.endm /* init_m4if */
98
99.macro setup_pll pll, freq
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000100 ldr r0, =\pll
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000101 adr r2, W_DP_\freq
102 bl setup_pll_func
103.endm
104
105#define W_DP_OP 0
106#define W_DP_MFD 4
107#define W_DP_MFN 8
108
109setup_pll_func:
Stefano Babica521a772010-01-20 18:19:32 +0100110 ldr r1, =0x00001232
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000111 str r1, [r0, #PLL_DP_CTL] /* Set DPLL ON (set UPEN bit): BRMO=1 */
Stefano Babica521a772010-01-20 18:19:32 +0100112 mov r1, #0x2
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000113 str r1, [r0, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
Stefano Babica521a772010-01-20 18:19:32 +0100114
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000115 ldr r1, [r2, #W_DP_OP]
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000116 str r1, [r0, #PLL_DP_OP]
117 str r1, [r0, #PLL_DP_HFS_OP]
Stefano Babica521a772010-01-20 18:19:32 +0100118
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000119 ldr r1, [r2, #W_DP_MFD]
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000120 str r1, [r0, #PLL_DP_MFD]
121 str r1, [r0, #PLL_DP_HFS_MFD]
Stefano Babica521a772010-01-20 18:19:32 +0100122
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000123 ldr r1, [r2, #W_DP_MFN]
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000124 str r1, [r0, #PLL_DP_MFN]
125 str r1, [r0, #PLL_DP_HFS_MFN]
Stefano Babica521a772010-01-20 18:19:32 +0100126
127 ldr r1, =0x00001232
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000128 str r1, [r0, #PLL_DP_CTL]
1291: ldr r1, [r0, #PLL_DP_CTL]
Stefano Babica521a772010-01-20 18:19:32 +0100130 ands r1, r1, #0x1
131 beq 1b
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000132
133 /* r10 saved upper lr */
134 mov pc, lr
Stefano Babica521a772010-01-20 18:19:32 +0100135
David Jander088b3382011-07-13 21:11:53 +0000136.macro setup_pll_errata pll, freq
137 ldr r2, =\pll
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000138 str r4, [r2, #PLL_DP_CONFIG] /* Disable auto-restart AREN bit */
David Jander088b3382011-07-13 21:11:53 +0000139 ldr r1, =0x00001236
140 str r1, [r2, #PLL_DP_CTL] /* Restart PLL with PLM=1 */
1411: ldr r1, [r2, #PLL_DP_CTL] /* Wait for lock */
142 ands r1, r1, #0x1
143 beq 1b
144
145 ldr r5, \freq
146 str r5, [r2, #PLL_DP_MFN] /* Modify MFN value */
147 str r5, [r2, #PLL_DP_HFS_MFN]
148
149 mov r1, #0x1
150 str r1, [r2, #PLL_DP_CONFIG] /* Reload MFN value */
151
1522: ldr r1, [r2, #PLL_DP_CONFIG]
153 tst r1, #1
154 bne 2b
155
156 ldr r1, =100 /* Wait at least 4 us */
1573: subs r1, r1, #1
158 bge 3b
159
160 mov r1, #0x2
161 str r1, [r2, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
162.endm
163
Stefano Babica521a772010-01-20 18:19:32 +0100164.macro init_clock
Fabio Estevam3ad50f82012-10-15 05:37:15 +0000165#if defined (CONFIG_MX51)
Stefano Babica521a772010-01-20 18:19:32 +0100166 ldr r0, =CCM_BASE_ADDR
167
168 /* Gate of clocks to the peripherals first */
169 ldr r1, =0x3FFFFFFF
170 str r1, [r0, #CLKCTL_CCGR0]
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000171 str r4, [r0, #CLKCTL_CCGR1]
172 str r4, [r0, #CLKCTL_CCGR2]
173 str r4, [r0, #CLKCTL_CCGR3]
Stefano Babica521a772010-01-20 18:19:32 +0100174
175 ldr r1, =0x00030000
176 str r1, [r0, #CLKCTL_CCGR4]
177 ldr r1, =0x00FFF030
178 str r1, [r0, #CLKCTL_CCGR5]
179 ldr r1, =0x00000300
180 str r1, [r0, #CLKCTL_CCGR6]
181
182 /* Disable IPU and HSC dividers */
183 mov r1, #0x60000
184 str r1, [r0, #CLKCTL_CCDR]
185
186 /* Make sure to switch the DDR away from PLL 1 */
187 ldr r1, =0x19239145
188 str r1, [r0, #CLKCTL_CBCDR]
189 /* make sure divider effective */
1901: ldr r1, [r0, #CLKCTL_CDHIPR]
191 cmp r1, #0x0
192 bne 1b
193
194 /* Switch ARM to step clock */
195 mov r1, #0x4
196 str r1, [r0, #CLKCTL_CCSR]
Stefano Babica521a772010-01-20 18:19:32 +0100197
David Jander088b3382011-07-13 21:11:53 +0000198#if defined(CONFIG_MX51_PLL_ERRATA)
199 setup_pll PLL1_BASE_ADDR, 864
200 setup_pll_errata PLL1_BASE_ADDR, W_DP_MFN_800_DIT
201#else
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000202 setup_pll PLL1_BASE_ADDR, 800
David Jander088b3382011-07-13 21:11:53 +0000203#endif
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000204
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000205 setup_pll PLL3_BASE_ADDR, 665
Stefano Babica521a772010-01-20 18:19:32 +0100206
207 /* Switch peripheral to PLL 3 */
208 ldr r0, =CCM_BASE_ADDR
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000209 ldr r1, =0x000010C0 | CONFIG_SYS_DDR_CLKSEL
Stefano Babica521a772010-01-20 18:19:32 +0100210 str r1, [r0, #CLKCTL_CBCMR]
211 ldr r1, =0x13239145
212 str r1, [r0, #CLKCTL_CBCDR]
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000213 setup_pll PLL2_BASE_ADDR, 665
Stefano Babica521a772010-01-20 18:19:32 +0100214
215 /* Switch peripheral to PLL2 */
216 ldr r0, =CCM_BASE_ADDR
217 ldr r1, =0x19239145
218 str r1, [r0, #CLKCTL_CBCDR]
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000219 ldr r1, =0x000020C0 | CONFIG_SYS_DDR_CLKSEL
Stefano Babica521a772010-01-20 18:19:32 +0100220 str r1, [r0, #CLKCTL_CBCMR]
Fabio Estevam3ad50f82012-10-15 05:37:15 +0000221
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000222 setup_pll PLL3_BASE_ADDR, 216
Stefano Babica521a772010-01-20 18:19:32 +0100223
224 /* Set the platform clock dividers */
225 ldr r0, =ARM_BASE_ADDR
226 ldr r1, =0x00000725
227 str r1, [r0, #0x14]
228
229 ldr r0, =CCM_BASE_ADDR
230
231 /* Run 3.0 at Full speed, for other TO's wait till we increase VDDGP */
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000232 ldr r3, [r4, #ROM_SI_REV]
Stefano Babica521a772010-01-20 18:19:32 +0100233 cmp r3, #0x10
234 movls r1, #0x1
235 movhi r1, #0
Fabio Estevam3ad50f82012-10-15 05:37:15 +0000236
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000237 str r1, [r0, #CLKCTL_CACRR]
Benoît Thébaudeau118e0bc2012-08-14 05:18:43 +0000238
Stefano Babica521a772010-01-20 18:19:32 +0100239 /* Switch ARM back to PLL 1 */
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000240 str r4, [r0, #CLKCTL_CCSR]
Stefano Babica521a772010-01-20 18:19:32 +0100241
242 /* setup the rest */
243 /* Use lp_apm (24MHz) source for perclk */
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000244 ldr r1, =0x000020C2 | CONFIG_SYS_DDR_CLKSEL
Stefano Babica521a772010-01-20 18:19:32 +0100245 str r1, [r0, #CLKCTL_CBCMR]
246 /* ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz */
Stefano Babic0c3d8ee2010-03-28 13:43:26 +0200247 ldr r1, =CONFIG_SYS_CLKTL_CBCDR
Stefano Babica521a772010-01-20 18:19:32 +0100248 str r1, [r0, #CLKCTL_CBCDR]
249
250 /* Restore the default values in the Gate registers */
251 ldr r1, =0xFFFFFFFF
252 str r1, [r0, #CLKCTL_CCGR0]
253 str r1, [r0, #CLKCTL_CCGR1]
254 str r1, [r0, #CLKCTL_CCGR2]
255 str r1, [r0, #CLKCTL_CCGR3]
256 str r1, [r0, #CLKCTL_CCGR4]
257 str r1, [r0, #CLKCTL_CCGR5]
258 str r1, [r0, #CLKCTL_CCGR6]
259
260 /* Use PLL 2 for UART's, get 66.5MHz from it */
261 ldr r1, =0xA5A2A020
262 str r1, [r0, #CLKCTL_CSCMR1]
263 ldr r1, =0x00C30321
264 str r1, [r0, #CLKCTL_CSCDR1]
Fabio Estevam3ad50f82012-10-15 05:37:15 +0000265 /* make sure divider effective */
2661: ldr r1, [r0, #CLKCTL_CDHIPR]
267 cmp r1, #0x0
268 bne 1b
269
270 str r4, [r0, #CLKCTL_CCDR]
271
272 /* for cko - for ARM div by 8 */
273 mov r1, #0x000A0000
274 add r1, r1, #0x00000F0
275 str r1, [r0, #CLKCTL_CCOSR]
276#else /* CONFIG_MX53 */
277 ldr r0, =CCM_BASE_ADDR
278
279 /* Gate of clocks to the peripherals first */
280 ldr r1, =0x3FFFFFFF
281 str r1, [r0, #CLKCTL_CCGR0]
282 str r4, [r0, #CLKCTL_CCGR1]
283 str r4, [r0, #CLKCTL_CCGR2]
284 str r4, [r0, #CLKCTL_CCGR3]
285 str r4, [r0, #CLKCTL_CCGR7]
286 ldr r1, =0x00030000
287 str r1, [r0, #CLKCTL_CCGR4]
288 ldr r1, =0x00FFF030
289 str r1, [r0, #CLKCTL_CCGR5]
290 ldr r1, =0x0F00030F
291 str r1, [r0, #CLKCTL_CCGR6]
292
293 /* Switch ARM to step clock */
294 mov r1, #0x4
295 str r1, [r0, #CLKCTL_CCSR]
296
297 setup_pll PLL1_BASE_ADDR, 800
298
Fabio Estevam954f1b22012-10-15 05:37:16 +0000299 setup_pll PLL3_BASE_ADDR, 400
300
301 /* Switch peripheral to PLL3 */
302 ldr r0, =CCM_BASE_ADDR
303 ldr r1, =0x00015154
304 str r1, [r0, #CLKCTL_CBCMR]
305 ldr r1, =0x02888945
306 orr r1, r1, #(1 << 16)
307 str r1, [r0, #CLKCTL_CBCDR]
308 /* make sure change is effective */
3091: ldr r1, [r0, #CLKCTL_CDHIPR]
310 cmp r1, #0x0
311 bne 1b
312
313 setup_pll PLL2_BASE_ADDR, 400
314
315 /* Switch peripheral to PLL2 */
316 ldr r0, =CCM_BASE_ADDR
317 ldr r1, =0x00808145
318 orr r1, r1, #(2 << 10)
319 orr r1, r1, #(0 << 16)
320 orr r1, r1, #(1 << 19)
321 str r1, [r0, #CLKCTL_CBCDR]
322
323 ldr r1, =0x00016154
324 str r1, [r0, #CLKCTL_CBCMR]
325
326 /*change uart clk parent to pll2*/
327 ldr r1, [r0, #CLKCTL_CSCMR1]
328 and r1, r1, #0xfcffffff
329 orr r1, r1, #0x01000000
330 str r1, [r0, #CLKCTL_CSCMR1]
331
332 /* make sure change is effective */
3331: ldr r1, [r0, #CLKCTL_CDHIPR]
334 cmp r1, #0x0
335 bne 1b
336
337 setup_pll PLL3_BASE_ADDR, 216
338
339 setup_pll PLL4_BASE_ADDR, 455
Fabio Estevam3ad50f82012-10-15 05:37:15 +0000340
341 /* Set the platform clock dividers */
342 ldr r0, =ARM_BASE_ADDR
Fabio Estevam954f1b22012-10-15 05:37:16 +0000343 ldr r1, =0x00000124
Fabio Estevam3ad50f82012-10-15 05:37:15 +0000344 str r1, [r0, #0x14]
345
346 ldr r0, =CCM_BASE_ADDR
Fabio Estevam3ad50f82012-10-15 05:37:15 +0000347 mov r1, #0
348 str r1, [r0, #CLKCTL_CACRR]
349
Fabio Estevam954f1b22012-10-15 05:37:16 +0000350 /* Switch ARM back to PLL 1. */
351 mov r1, #0x0
352 str r1, [r0, #CLKCTL_CCSR]
353
354 /* make uart div=6 */
355 ldr r1, [r0, #CLKCTL_CSCDR1]
356 and r1, r1, #0xffffffc0
357 orr r1, r1, #0x0a
358 str r1, [r0, #CLKCTL_CSCDR1]
Fabio Estevam3ad50f82012-10-15 05:37:15 +0000359
360 /* Restore the default values in the Gate registers */
361 ldr r1, =0xFFFFFFFF
362 str r1, [r0, #CLKCTL_CCGR0]
363 str r1, [r0, #CLKCTL_CCGR1]
364 str r1, [r0, #CLKCTL_CCGR2]
365 str r1, [r0, #CLKCTL_CCGR3]
366 str r1, [r0, #CLKCTL_CCGR4]
367 str r1, [r0, #CLKCTL_CCGR5]
368 str r1, [r0, #CLKCTL_CCGR6]
369 str r1, [r0, #CLKCTL_CCGR7]
370
Fabio Estevam954f1b22012-10-15 05:37:16 +0000371 mov r1, #0x00000
372 str r1, [r0, #CLKCTL_CCDR]
Stefano Babica521a772010-01-20 18:19:32 +0100373
Fabio Estevam954f1b22012-10-15 05:37:16 +0000374 /* for cko - for ARM div by 8 */
375 mov r1, #0x000A0000
376 add r1, r1, #0x00000F0
377 str r1, [r0, #CLKCTL_CCOSR]
Stefano Babica521a772010-01-20 18:19:32 +0100378
Fabio Estevam3ad50f82012-10-15 05:37:15 +0000379#endif /* CONFIG_MX53 */
Stefano Babica521a772010-01-20 18:19:32 +0100380.endm
381
382.macro setup_wdog
383 ldr r0, =WDOG1_BASE_ADDR
384 mov r1, #0x30
385 strh r1, [r0]
386.endm
387
Aneesh Vfd8798b2012-03-08 07:20:18 +0000388ENTRY(lowlevel_init)
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000389 mov r10, lr
390 mov r4, #0 /* Fix R4 to 0 */
391
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000392#if defined(CONFIG_MX51)
Stefano Babica521a772010-01-20 18:19:32 +0100393 ldr r0, =GPIO1_BASE_ADDR
394 ldr r1, [r0, #0x0]
Benoît Thébaudeau118e0bc2012-08-14 05:18:43 +0000395 orr r1, r1, #1 << 23
Stefano Babica521a772010-01-20 18:19:32 +0100396 str r1, [r0, #0x0]
397 ldr r1, [r0, #0x4]
Benoît Thébaudeau118e0bc2012-08-14 05:18:43 +0000398 orr r1, r1, #1 << 23
Stefano Babica521a772010-01-20 18:19:32 +0100399 str r1, [r0, #0x4]
Liu Hui-R64343baa2d782011-01-03 22:27:35 +0000400#endif
Stefano Babica521a772010-01-20 18:19:32 +0100401
Stefano Babica521a772010-01-20 18:19:32 +0100402 init_l2cc
403
404 init_aips
405
406 init_m4if
407
408 init_clock
409
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000410 mov pc, r10
Aneesh Vfd8798b2012-03-08 07:20:18 +0000411ENDPROC(lowlevel_init)
Stefano Babica521a772010-01-20 18:19:32 +0100412
413/* Board level setting value */
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000414#if defined(CONFIG_MX51_PLL_ERRATA)
415W_DP_864: .word DP_OP_864
416 .word DP_MFD_864
417 .word DP_MFN_864
Benoît Thébaudeau118e0bc2012-08-14 05:18:43 +0000418W_DP_MFN_800_DIT: .word DP_MFN_800_DIT
Benoît Thébaudeau9d1f2822012-08-14 05:19:12 +0000419#else
420W_DP_800: .word DP_OP_800
421 .word DP_MFD_800
422 .word DP_MFN_800
423#endif
424#if defined(CONFIG_MX51)
425W_DP_665: .word DP_OP_665
426 .word DP_MFD_665
427 .word DP_MFN_665
428#endif
429W_DP_216: .word DP_OP_216
430 .word DP_MFD_216
431 .word DP_MFN_216
Fabio Estevam954f1b22012-10-15 05:37:16 +0000432W_DP_400: .word DP_OP_400
433 .word DP_MFD_400
434 .word DP_MFN_400
435W_DP_455: .word DP_OP_455
436 .word DP_MFD_455
437 .word DP_MFN_455