xref: /rk3399_rockchip-uboot/board/armltd/integrator/lowlevel_init.S (revision b60eff31f3bd71a6f14b6c6efc8ad5fb3705de6d)
1576afd4fSJean-Christophe PLAGNIOL-VILLARD/*
2576afd4fSJean-Christophe PLAGNIOL-VILLARD * Board specific setup info
3576afd4fSJean-Christophe PLAGNIOL-VILLARD *
4576afd4fSJean-Christophe PLAGNIOL-VILLARD * (C) Copyright 2004, ARM Ltd.
5576afd4fSJean-Christophe PLAGNIOL-VILLARD * Philippe Robin, <philippe.robin@arm.com>
6576afd4fSJean-Christophe PLAGNIOL-VILLARD *
71a459660SWolfgang Denk * SPDX-License-Identifier:	GPL-2.0+
8576afd4fSJean-Christophe PLAGNIOL-VILLARD */
9576afd4fSJean-Christophe PLAGNIOL-VILLARD
10576afd4fSJean-Christophe PLAGNIOL-VILLARD#include <config.h>
11576afd4fSJean-Christophe PLAGNIOL-VILLARD#include <version.h>
12576afd4fSJean-Christophe PLAGNIOL-VILLARD
13576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* Reset using CM control register */
14576afd4fSJean-Christophe PLAGNIOL-VILLARD.global reset_cpu
15576afd4fSJean-Christophe PLAGNIOL-VILLARDreset_cpu:
16576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r0, #CM_BASE
17576afd4fSJean-Christophe PLAGNIOL-VILLARD	ldr	r1,[r0,#OS_CTRL]
18576afd4fSJean-Christophe PLAGNIOL-VILLARD	orr	r1,r1,#CMMASK_RESET
19576afd4fSJean-Christophe PLAGNIOL-VILLARD	str	r1,[r0,#OS_CTRL]
20576afd4fSJean-Christophe PLAGNIOL-VILLARD
21576afd4fSJean-Christophe PLAGNIOL-VILLARDreset_failed:
22576afd4fSJean-Christophe PLAGNIOL-VILLARD	b	reset_failed
23576afd4fSJean-Christophe PLAGNIOL-VILLARD
24576afd4fSJean-Christophe PLAGNIOL-VILLARD/* Set up the platform, once the cpu has been initialized */
25576afd4fSJean-Christophe PLAGNIOL-VILLARD.globl lowlevel_init
26576afd4fSJean-Christophe PLAGNIOL-VILLARDlowlevel_init:
27576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* If U-Boot has been run after the ARM boot monitor
28576afd4fSJean-Christophe PLAGNIOL-VILLARD	 * then all the necessary actions have been done
29576afd4fSJean-Christophe PLAGNIOL-VILLARD	 * otherwise we are running from user flash mapped to 0x00000000
30576afd4fSJean-Christophe PLAGNIOL-VILLARD	 * --- DO NOT REMAP BEFORE THE CODE HAS BEEN RELOCATED --
31576afd4fSJean-Christophe PLAGNIOL-VILLARD	 * Changes to the (possibly soft) reset defaults of the processor
32576afd4fSJean-Christophe PLAGNIOL-VILLARD	 * itself should be performed in cpu/arm<>/start.S
33576afd4fSJean-Christophe PLAGNIOL-VILLARD	 * This function affects only the core module or board settings
34576afd4fSJean-Christophe PLAGNIOL-VILLARD	 */
35576afd4fSJean-Christophe PLAGNIOL-VILLARD
36576afd4fSJean-Christophe PLAGNIOL-VILLARD#ifdef CONFIG_CM_INIT
37576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* CM has an initialization register
38576afd4fSJean-Christophe PLAGNIOL-VILLARD	 * - bits in it are wired into test-chip pins to force
39576afd4fSJean-Christophe PLAGNIOL-VILLARD	 *   reset defaults
40576afd4fSJean-Christophe PLAGNIOL-VILLARD	 * - may need to change its contents for U-Boot
41576afd4fSJean-Christophe PLAGNIOL-VILLARD	 */
42576afd4fSJean-Christophe PLAGNIOL-VILLARD
43576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* set the desired CM specific value */
44576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r2,#CMMASK_LOWVEC	/* Vectors at 0x00000000 for all */
45576afd4fSJean-Christophe PLAGNIOL-VILLARD
46576afd4fSJean-Christophe PLAGNIOL-VILLARD#if defined (CONFIG_CM10200E) || defined (CONFIG_CM10220E)
47576afd4fSJean-Christophe PLAGNIOL-VILLARD	orr	r2,r2,#CMMASK_INIT_102
48576afd4fSJean-Christophe PLAGNIOL-VILLARD#else
49576afd4fSJean-Christophe PLAGNIOL-VILLARD
50576afd4fSJean-Christophe PLAGNIOL-VILLARD#if !defined (CONFIG_CM920T) && !defined (CONFIG_CM920T_ETM) && \
51576afd4fSJean-Christophe PLAGNIOL-VILLARD     !defined (CONFIG_CM940T)
52576afd4fSJean-Christophe PLAGNIOL-VILLARD
53576afd4fSJean-Christophe PLAGNIOL-VILLARD#ifdef	CONFIG_CM_MULTIPLE_SSRAM
54576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* set simple mapping			*/
55576afd4fSJean-Christophe PLAGNIOL-VILLARD	and	r2,r2,#CMMASK_MAP_SIMPLE
56576afd4fSJean-Christophe PLAGNIOL-VILLARD#endif /* #ifdef CONFIG_CM_MULTIPLE_SSRAM	*/
57576afd4fSJean-Christophe PLAGNIOL-VILLARD
58576afd4fSJean-Christophe PLAGNIOL-VILLARD#ifdef	CONFIG_CM_TCRAM
59576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* disable TCRAM			*/
60576afd4fSJean-Christophe PLAGNIOL-VILLARD	and	r2,r2,#CMMASK_TCRAM_DISABLE
61576afd4fSJean-Christophe PLAGNIOL-VILLARD#endif /* #ifdef CONFIG_CM_TCRAM		*/
62576afd4fSJean-Christophe PLAGNIOL-VILLARD
63576afd4fSJean-Christophe PLAGNIOL-VILLARD#if defined (CONFIG_CM926EJ_S) || defined (CONFIG_CM1026EJ_S) || \
64576afd4fSJean-Christophe PLAGNIOL-VILLARD     defined (CONFIG_CM1136JF_S)
65576afd4fSJean-Christophe PLAGNIOL-VILLARD
66576afd4fSJean-Christophe PLAGNIOL-VILLARD	and	r2,r2,#CMMASK_LE
67576afd4fSJean-Christophe PLAGNIOL-VILLARD
68576afd4fSJean-Christophe PLAGNIOL-VILLARD#endif /* cpu with little endian initialization */
69576afd4fSJean-Christophe PLAGNIOL-VILLARD
70576afd4fSJean-Christophe PLAGNIOL-VILLARD	orr	r2,r2,#CMMASK_CMxx6_COMMON
71576afd4fSJean-Christophe PLAGNIOL-VILLARD
72576afd4fSJean-Christophe PLAGNIOL-VILLARD#endif /* CMxx6 code */
73576afd4fSJean-Christophe PLAGNIOL-VILLARD
74576afd4fSJean-Christophe PLAGNIOL-VILLARD#endif /* ARM102xxE value */
75576afd4fSJean-Christophe PLAGNIOL-VILLARD
76576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* read CM_INIT		 */
77576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r0, #CM_BASE
78576afd4fSJean-Christophe PLAGNIOL-VILLARD	ldr	r1, [r0, #OS_INIT]
79576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* check against desired bit setting */
80576afd4fSJean-Christophe PLAGNIOL-VILLARD	and	r3,r1,r2
81576afd4fSJean-Christophe PLAGNIOL-VILLARD	cmp	r3,r2
82576afd4fSJean-Christophe PLAGNIOL-VILLARD	beq	init_reg_OK
83576afd4fSJean-Christophe PLAGNIOL-VILLARD
84576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* lock for change */
85576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r3, #CMVAL_LOCK1
86576afd4fSJean-Christophe PLAGNIOL-VILLARD	add	r3,r3,#CMVAL_LOCK2
87576afd4fSJean-Christophe PLAGNIOL-VILLARD	str	r3, [r0, #OS_LOCK]
88576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* set desired value */
89576afd4fSJean-Christophe PLAGNIOL-VILLARD	orr	r1,r1,r2
90576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* write & relock CM_INIT */
91576afd4fSJean-Christophe PLAGNIOL-VILLARD	str	r1, [r0, #OS_INIT]
92576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r1, #CMVAL_UNLOCK
93576afd4fSJean-Christophe PLAGNIOL-VILLARD	str	r1, [r0, #OS_LOCK]
94576afd4fSJean-Christophe PLAGNIOL-VILLARD
95576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* soft reset so new values used */
96576afd4fSJean-Christophe PLAGNIOL-VILLARD	b	reset_cpu
97576afd4fSJean-Christophe PLAGNIOL-VILLARD
98576afd4fSJean-Christophe PLAGNIOL-VILLARDinit_reg_OK:
99576afd4fSJean-Christophe PLAGNIOL-VILLARD
100576afd4fSJean-Christophe PLAGNIOL-VILLARD#endif /* CONFIG_CM_INIT */
101576afd4fSJean-Christophe PLAGNIOL-VILLARD
102576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	pc, lr
103576afd4fSJean-Christophe PLAGNIOL-VILLARD
104576afd4fSJean-Christophe PLAGNIOL-VILLARD#ifdef	CONFIG_CM_SPD_DETECT
105576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* Fast memory is available for the DRAM data
106576afd4fSJean-Christophe PLAGNIOL-VILLARD	 * - ensure it has been transferred, then summarize the data
107576afd4fSJean-Christophe PLAGNIOL-VILLARD	 *   into a CM register
108576afd4fSJean-Christophe PLAGNIOL-VILLARD	 */
109576afd4fSJean-Christophe PLAGNIOL-VILLARD.globl dram_query
110576afd4fSJean-Christophe PLAGNIOL-VILLARDdram_query:
111576afd4fSJean-Christophe PLAGNIOL-VILLARD	stmfd	r13!,{r4-r6,lr}
112576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* set up SDRAM info					*/
113576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* - based on example code from the CM User Guide */
114576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r0, #CM_BASE
115576afd4fSJean-Christophe PLAGNIOL-VILLARD
116576afd4fSJean-Christophe PLAGNIOL-VILLARDreadspdbit:
117576afd4fSJean-Christophe PLAGNIOL-VILLARD	ldr	r1, [r0, #OS_SDRAM]	/* read the SDRAM register	*/
118576afd4fSJean-Christophe PLAGNIOL-VILLARD	and	r1, r1, #0x20		/* mask SPD bit (5)		*/
119576afd4fSJean-Christophe PLAGNIOL-VILLARD	cmp	r1, #0x20		/* test if set			*/
120576afd4fSJean-Christophe PLAGNIOL-VILLARD	bne	readspdbit
121576afd4fSJean-Christophe PLAGNIOL-VILLARD
122576afd4fSJean-Christophe PLAGNIOL-VILLARDsetupsdram:
123576afd4fSJean-Christophe PLAGNIOL-VILLARD	add	r0, r0, #OS_SPD		/* address the copy of the SDP data	*/
124576afd4fSJean-Christophe PLAGNIOL-VILLARD	ldrb	r1, [r0, #3]		/* number of row address lines		*/
125576afd4fSJean-Christophe PLAGNIOL-VILLARD	ldrb	r2, [r0, #4]		/* number of column address lines	*/
126576afd4fSJean-Christophe PLAGNIOL-VILLARD	ldrb	r3, [r0, #5]		/* number of banks			*/
127576afd4fSJean-Christophe PLAGNIOL-VILLARD	ldrb	r4, [r0, #31]		/* module bank density			*/
128576afd4fSJean-Christophe PLAGNIOL-VILLARD	mul	r5, r4, r3		/* size of SDRAM (MB divided by 4)	*/
129576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r5, r5, ASL#2		/* size in MB				*/
130576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r0, #CM_BASE		/* reload for later code		*/
131576afd4fSJean-Christophe PLAGNIOL-VILLARD	cmp	r5, #0x10		/* is it 16MB?				*/
132576afd4fSJean-Christophe PLAGNIOL-VILLARD	bne	not16
133576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r6, #0x2		/* store size and CAS latency of 2	*/
134576afd4fSJean-Christophe PLAGNIOL-VILLARD	b	writesize
135576afd4fSJean-Christophe PLAGNIOL-VILLARD
136576afd4fSJean-Christophe PLAGNIOL-VILLARDnot16:
137576afd4fSJean-Christophe PLAGNIOL-VILLARD	cmp	r5, #0x20		/* is it  32MB? */
138576afd4fSJean-Christophe PLAGNIOL-VILLARD	bne	not32
139576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r6, #0x6
140576afd4fSJean-Christophe PLAGNIOL-VILLARD	b	writesize
141576afd4fSJean-Christophe PLAGNIOL-VILLARD
142576afd4fSJean-Christophe PLAGNIOL-VILLARDnot32:
143576afd4fSJean-Christophe PLAGNIOL-VILLARD	cmp	r5, #0x40		/* is it  64MB? */
144576afd4fSJean-Christophe PLAGNIOL-VILLARD	bne	not64
145576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r6, #0xa
146576afd4fSJean-Christophe PLAGNIOL-VILLARD	b	writesize
147576afd4fSJean-Christophe PLAGNIOL-VILLARD
148576afd4fSJean-Christophe PLAGNIOL-VILLARDnot64:
149576afd4fSJean-Christophe PLAGNIOL-VILLARD	cmp	r5, #0x80		/* is it 128MB? */
150576afd4fSJean-Christophe PLAGNIOL-VILLARD	bne	not128
151576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r6, #0xe
152576afd4fSJean-Christophe PLAGNIOL-VILLARD	b	writesize
153576afd4fSJean-Christophe PLAGNIOL-VILLARD
154576afd4fSJean-Christophe PLAGNIOL-VILLARDnot128:
155576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* if it is none of these sizes then it is either 256MB, or
156576afd4fSJean-Christophe PLAGNIOL-VILLARD	 * there is no SDRAM fitted so default to 256MB
157576afd4fSJean-Christophe PLAGNIOL-VILLARD	 */
158576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r6, #0x12
159576afd4fSJean-Christophe PLAGNIOL-VILLARD
160576afd4fSJean-Christophe PLAGNIOL-VILLARDwritesize:
161576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r1, r1, ASL#8		/* row addr lines from SDRAM reg */
162576afd4fSJean-Christophe PLAGNIOL-VILLARD	orr	r2, r1, r2, ASL#12	/* OR in column address lines	 */
163576afd4fSJean-Christophe PLAGNIOL-VILLARD	orr	r3, r2, r3, ASL#16	/* OR in number of banks	 */
164576afd4fSJean-Christophe PLAGNIOL-VILLARD	orr	r6, r6, r3		/* OR in size and CAS latency	 */
165576afd4fSJean-Christophe PLAGNIOL-VILLARD	str	r6, [r0, #OS_SDRAM]	/* store SDRAM parameters	 */
166576afd4fSJean-Christophe PLAGNIOL-VILLARD
167576afd4fSJean-Christophe PLAGNIOL-VILLARD#endif /* #ifdef CONFIG_CM_SPD_DETECT */
168576afd4fSJean-Christophe PLAGNIOL-VILLARD
169576afd4fSJean-Christophe PLAGNIOL-VILLARD	ldmfd	r13!,{r4-r6,pc}			/* back to caller */
170576afd4fSJean-Christophe PLAGNIOL-VILLARD
171576afd4fSJean-Christophe PLAGNIOL-VILLARD#ifdef	CONFIG_CM_REMAP
172576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* CM remap bit is operational
173576afd4fSJean-Christophe PLAGNIOL-VILLARD	 * - use it to map writeable memory at 0x00000000, in place of flash
174576afd4fSJean-Christophe PLAGNIOL-VILLARD	 */
175576afd4fSJean-Christophe PLAGNIOL-VILLARD.globl cm_remap
176576afd4fSJean-Christophe PLAGNIOL-VILLARDcm_remap:
177576afd4fSJean-Christophe PLAGNIOL-VILLARD	stmfd	r13!,{r4-r10,lr}
178576afd4fSJean-Christophe PLAGNIOL-VILLARD
179576afd4fSJean-Christophe PLAGNIOL-VILLARD	mov	r0, #CM_BASE
180576afd4fSJean-Christophe PLAGNIOL-VILLARD	ldr	r1, [r0, #OS_CTRL]
181576afd4fSJean-Christophe PLAGNIOL-VILLARD	orr	r1, r1, #CMMASK_REMAP	/* set remap and led bits */
182576afd4fSJean-Christophe PLAGNIOL-VILLARD	str	r1, [r0, #OS_CTRL]
183576afd4fSJean-Christophe PLAGNIOL-VILLARD
184576afd4fSJean-Christophe PLAGNIOL-VILLARD	/* Now 0x00000000 is writeable, replace the vectors	*/
185576afd4fSJean-Christophe PLAGNIOL-VILLARD	ldr	r0, =_start	/* r0 <- start of vectors	*/
186*b60eff31SAlbert ARIBAUD	add	r2, r0, #64	/* r2 <- past vectors	*/
187576afd4fSJean-Christophe PLAGNIOL-VILLARD	sub	r1,r1,r1		/* destination 0x00000000	*/
188576afd4fSJean-Christophe PLAGNIOL-VILLARD
189576afd4fSJean-Christophe PLAGNIOL-VILLARDcopy_vec:
190576afd4fSJean-Christophe PLAGNIOL-VILLARD	ldmia	r0!, {r3-r10}		/* copy from source address [r0]	*/
191576afd4fSJean-Christophe PLAGNIOL-VILLARD	stmia	r1!, {r3-r10}		/* copy to	 target address [r1]	*/
192576afd4fSJean-Christophe PLAGNIOL-VILLARD	cmp	r0, r2			/* until source end address [r2]	*/
193576afd4fSJean-Christophe PLAGNIOL-VILLARD	ble	copy_vec
194576afd4fSJean-Christophe PLAGNIOL-VILLARD
195576afd4fSJean-Christophe PLAGNIOL-VILLARD	ldmfd	r13!,{r4-r10,pc}	/* back to caller			*/
196576afd4fSJean-Christophe PLAGNIOL-VILLARD
197576afd4fSJean-Christophe PLAGNIOL-VILLARD#endif /* #ifdef CONFIG_CM_REMAP */
198