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