blob: b50ba9878c4fa4391df9dee10553ee23aa7068a3 [file] [log] [blame]
wdenk3d3befa2004-03-14 15:06:13 +00001/*
2 * Board specific setup info
3 *
4 * (C) Copyright 2004, ARM Ltd.
5 * Philippe Robin, <philippe.robin@arm.com>
6 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02007 * SPDX-License-Identifier: GPL-2.0+
wdenk3d3befa2004-03-14 15:06:13 +00008 */
9
10#include <config.h>
wdenk3d3befa2004-03-14 15:06:13 +000011
Wolfgang Denk74f43042005-09-25 01:48:28 +020012 /* Reset using CM control register */
13.global reset_cpu
14reset_cpu:
15 mov r0, #CM_BASE
16 ldr r1,[r0,#OS_CTRL]
17 orr r1,r1,#CMMASK_RESET
Wolfgang Denk9b880bd2005-10-04 23:10:28 +020018 str r1,[r0,#OS_CTRL]
Wolfgang Denk74f43042005-09-25 01:48:28 +020019
20reset_failed:
21 b reset_failed
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020022
Wolfgang Denk87cb6862005-10-06 17:08:18 +020023/* Set up the platform, once the cpu has been initialized */
24.globl lowlevel_init
25lowlevel_init:
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020026 /* If U-Boot has been run after the ARM boot monitor
27 * then all the necessary actions have been done
28 * otherwise we are running from user flash mapped to 0x00000000
29 * --- DO NOT REMAP BEFORE THE CODE HAS BEEN RELOCATED --
30 * Changes to the (possibly soft) reset defaults of the processor
31 * itself should be performed in cpu/arm<>/start.S
32 * This function affects only the core module or board settings
33 */
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020034
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020035#ifdef CONFIG_CM_INIT
36 /* CM has an initialization register
37 * - bits in it are wired into test-chip pins to force
38 * reset defaults
39 * - may need to change its contents for U-Boot
40 */
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020041
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020042 /* set the desired CM specific value */
43 mov r2,#CMMASK_LOWVEC /* Vectors at 0x00000000 for all */
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020044
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020045#if defined (CONFIG_CM10200E) || defined (CONFIG_CM10220E)
46 orr r2,r2,#CMMASK_INIT_102
47#else
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020048
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020049#if !defined (CONFIG_CM920T) && !defined (CONFIG_CM920T_ETM) && \
50 !defined (CONFIG_CM940T)
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020051
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020052#ifdef CONFIG_CM_MULTIPLE_SSRAM
Wolfgang Denk96782c62005-10-09 00:22:48 +020053 /* set simple mapping */
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020054 and r2,r2,#CMMASK_MAP_SIMPLE
Wolfgang Denk96782c62005-10-09 00:22:48 +020055#endif /* #ifdef CONFIG_CM_MULTIPLE_SSRAM */
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020056
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020057#ifdef CONFIG_CM_TCRAM
Wolfgang Denk96782c62005-10-09 00:22:48 +020058 /* disable TCRAM */
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020059 and r2,r2,#CMMASK_TCRAM_DISABLE
Wolfgang Denk96782c62005-10-09 00:22:48 +020060#endif /* #ifdef CONFIG_CM_TCRAM */
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020061
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020062#if defined (CONFIG_CM926EJ_S) || defined (CONFIG_CM1026EJ_S) || \
Wolfgang Denk96782c62005-10-09 00:22:48 +020063 defined (CONFIG_CM1136JF_S)
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020064
65 and r2,r2,#CMMASK_LE
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020066
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020067#endif /* cpu with little endian initialization */
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020068
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020069 orr r2,r2,#CMMASK_CMxx6_COMMON
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020070
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020071#endif /* CMxx6 code */
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020072
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020073#endif /* ARM102xxE value */
74
Wolfgang Denk96782c62005-10-09 00:22:48 +020075 /* read CM_INIT */
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020076 mov r0, #CM_BASE
77 ldr r1, [r0, #OS_INIT]
78 /* check against desired bit setting */
79 and r3,r1,r2
80 cmp r3,r2
81 beq init_reg_OK
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020082
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020083 /* lock for change */
Wolfgang Denk9b880bd2005-10-04 23:10:28 +020084 mov r3, #CMVAL_LOCK1
85 add r3,r3,#CMVAL_LOCK2
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020086 str r3, [r0, #OS_LOCK]
87 /* set desired value */
88 orr r1,r1,r2
89 /* write & relock CM_INIT */
90 str r1, [r0, #OS_INIT]
91 mov r1, #CMVAL_UNLOCK
92 str r1, [r0, #OS_LOCK]
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020093
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020094 /* soft reset so new values used */
95 b reset_cpu
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020096
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020097init_reg_OK:
Wolfgang Denk716c1dc2005-09-25 18:49:35 +020098
Wolfgang Denk0148e8c2005-09-25 16:22:14 +020099#endif /* CONFIG_CM_INIT */
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200100
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200101 mov pc, lr
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200102
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200103#ifdef CONFIG_CM_SPD_DETECT
104 /* Fast memory is available for the DRAM data
105 * - ensure it has been transferred, then summarize the data
106 * into a CM register
107 */
108.globl dram_query
109dram_query:
110 stmfd r13!,{r4-r6,lr}
Wolfgang Denk96782c62005-10-09 00:22:48 +0200111 /* set up SDRAM info */
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200112 /* - based on example code from the CM User Guide */
113 mov r0, #CM_BASE
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200114
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200115readspdbit:
Wolfgang Denk96782c62005-10-09 00:22:48 +0200116 ldr r1, [r0, #OS_SDRAM] /* read the SDRAM register */
117 and r1, r1, #0x20 /* mask SPD bit (5) */
118 cmp r1, #0x20 /* test if set */
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200119 bne readspdbit
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200120
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200121setupsdram:
Wolfgang Denk96782c62005-10-09 00:22:48 +0200122 add r0, r0, #OS_SPD /* address the copy of the SDP data */
123 ldrb r1, [r0, #3] /* number of row address lines */
124 ldrb r2, [r0, #4] /* number of column address lines */
125 ldrb r3, [r0, #5] /* number of banks */
126 ldrb r4, [r0, #31] /* module bank density */
127 mul r5, r4, r3 /* size of SDRAM (MB divided by 4) */
128 mov r5, r5, ASL#2 /* size in MB */
129 mov r0, #CM_BASE /* reload for later code */
130 cmp r5, #0x10 /* is it 16MB? */
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200131 bne not16
Wolfgang Denk96782c62005-10-09 00:22:48 +0200132 mov r6, #0x2 /* store size and CAS latency of 2 */
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200133 b writesize
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200134
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200135not16:
136 cmp r5, #0x20 /* is it 32MB? */
137 bne not32
138 mov r6, #0x6
139 b writesize
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200140
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200141not32:
142 cmp r5, #0x40 /* is it 64MB? */
143 bne not64
144 mov r6, #0xa
145 b writesize
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200146
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200147not64:
148 cmp r5, #0x80 /* is it 128MB? */
149 bne not128
150 mov r6, #0xe
151 b writesize
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200152
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200153not128:
154 /* if it is none of these sizes then it is either 256MB, or
155 * there is no SDRAM fitted so default to 256MB
156 */
157 mov r6, #0x12
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200158
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200159writesize:
160 mov r1, r1, ASL#8 /* row addr lines from SDRAM reg */
161 orr r2, r1, r2, ASL#12 /* OR in column address lines */
162 orr r3, r2, r3, ASL#16 /* OR in number of banks */
163 orr r6, r6, r3 /* OR in size and CAS latency */
164 str r6, [r0, #OS_SDRAM] /* store SDRAM parameters */
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200165
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200166#endif /* #ifdef CONFIG_CM_SPD_DETECT */
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200167
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200168 ldmfd r13!,{r4-r6,pc} /* back to caller */
169
170#ifdef CONFIG_CM_REMAP
171 /* CM remap bit is operational
172 * - use it to map writeable memory at 0x00000000, in place of flash
173 */
174.globl cm_remap
175cm_remap:
176 stmfd r13!,{r4-r10,lr}
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200177
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200178 mov r0, #CM_BASE
179 ldr r1, [r0, #OS_CTRL]
180 orr r1, r1, #CMMASK_REMAP /* set remap and led bits */
181 str r1, [r0, #OS_CTRL]
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200182
Wolfgang Denk96782c62005-10-09 00:22:48 +0200183 /* Now 0x00000000 is writeable, replace the vectors */
184 ldr r0, =_start /* r0 <- start of vectors */
Albert ARIBAUDb60eff32014-02-22 17:53:43 +0100185 add r2, r0, #64 /* r2 <- past vectors */
Wolfgang Denk96782c62005-10-09 00:22:48 +0200186 sub r1,r1,r1 /* destination 0x00000000 */
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200187
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200188copy_vec:
Wolfgang Denk96782c62005-10-09 00:22:48 +0200189 ldmia r0!, {r3-r10} /* copy from source address [r0] */
190 stmia r1!, {r3-r10} /* copy to target address [r1] */
191 cmp r0, r2 /* until source end address [r2] */
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200192 ble copy_vec
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200193
Wolfgang Denk96782c62005-10-09 00:22:48 +0200194 ldmfd r13!,{r4-r10,pc} /* back to caller */
Wolfgang Denk716c1dc2005-09-25 18:49:35 +0200195
Wolfgang Denk0148e8c2005-09-25 16:22:14 +0200196#endif /* #ifdef CONFIG_CM_REMAP */