blob: 1a1cb580be6341aabb385d4838d89eab82478aa4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
wdenk4989f872004-03-14 15:06:13 +00002/*
3 * Board specific setup info
4 *
5 * (C) Copyright 2004, ARM Ltd.
6 * Philippe Robin, <philippe.robin@arm.com>
wdenk4989f872004-03-14 15:06:13 +00007 */
8
9#include <config.h>
wdenk4989f872004-03-14 15:06:13 +000010
Wolfgang Denkadf20a12005-09-25 01:48:28 +020011 /* Reset using CM control register */
12.global reset_cpu
13reset_cpu:
14 mov r0, #CM_BASE
15 ldr r1,[r0,#OS_CTRL]
16 orr r1,r1,#CMMASK_RESET
Wolfgang Denk03f9ba32005-10-04 23:10:28 +020017 str r1,[r0,#OS_CTRL]
Wolfgang Denkadf20a12005-09-25 01:48:28 +020018
19reset_failed:
20 b reset_failed
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020021
Wolfgang Denk7f88a5e2005-10-06 17:08:18 +020022/* Set up the platform, once the cpu has been initialized */
23.globl lowlevel_init
24lowlevel_init:
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020025 /* If U-Boot has been run after the ARM boot monitor
26 * then all the necessary actions have been done
27 * otherwise we are running from user flash mapped to 0x00000000
28 * --- DO NOT REMAP BEFORE THE CODE HAS BEEN RELOCATED --
29 * Changes to the (possibly soft) reset defaults of the processor
30 * itself should be performed in cpu/arm<>/start.S
31 * This function affects only the core module or board settings
32 */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020033
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020034#ifdef CONFIG_CM_INIT
35 /* CM has an initialization register
36 * - bits in it are wired into test-chip pins to force
37 * reset defaults
38 * - may need to change its contents for U-Boot
39 */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020040
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020041 /* set the desired CM specific value */
42 mov r2,#CMMASK_LOWVEC /* Vectors at 0x00000000 for all */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020043
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020044#if defined (CONFIG_CM10200E) || defined (CONFIG_CM10220E)
45 orr r2,r2,#CMMASK_INIT_102
46#else
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020047
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020048#if !defined (CONFIG_CM920T) && !defined (CONFIG_CM920T_ETM) && \
49 !defined (CONFIG_CM940T)
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020050
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020051#ifdef CONFIG_CM_MULTIPLE_SSRAM
Wolfgang Denk88bd7432005-10-09 00:22:48 +020052 /* set simple mapping */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020053 and r2,r2,#CMMASK_MAP_SIMPLE
Wolfgang Denk88bd7432005-10-09 00:22:48 +020054#endif /* #ifdef CONFIG_CM_MULTIPLE_SSRAM */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020055
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020056#ifdef CONFIG_CM_TCRAM
Wolfgang Denk88bd7432005-10-09 00:22:48 +020057 /* disable TCRAM */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020058 and r2,r2,#CMMASK_TCRAM_DISABLE
Wolfgang Denk88bd7432005-10-09 00:22:48 +020059#endif /* #ifdef CONFIG_CM_TCRAM */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020060
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020061#if defined (CONFIG_CM926EJ_S) || defined (CONFIG_CM1026EJ_S) || \
Wolfgang Denk88bd7432005-10-09 00:22:48 +020062 defined (CONFIG_CM1136JF_S)
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020063
64 and r2,r2,#CMMASK_LE
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020065
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020066#endif /* cpu with little endian initialization */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020067
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020068 orr r2,r2,#CMMASK_CMxx6_COMMON
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020069
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020070#endif /* CMxx6 code */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020071
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020072#endif /* ARM102xxE value */
73
Wolfgang Denk88bd7432005-10-09 00:22:48 +020074 /* read CM_INIT */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020075 mov r0, #CM_BASE
76 ldr r1, [r0, #OS_INIT]
77 /* check against desired bit setting */
78 and r3,r1,r2
79 cmp r3,r2
80 beq init_reg_OK
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020081
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020082 /* lock for change */
Wolfgang Denk03f9ba32005-10-04 23:10:28 +020083 mov r3, #CMVAL_LOCK1
84 add r3,r3,#CMVAL_LOCK2
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020085 str r3, [r0, #OS_LOCK]
86 /* set desired value */
87 orr r1,r1,r2
88 /* write & relock CM_INIT */
89 str r1, [r0, #OS_INIT]
90 mov r1, #CMVAL_UNLOCK
91 str r1, [r0, #OS_LOCK]
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020092
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020093 /* soft reset so new values used */
94 b reset_cpu
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020095
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020096init_reg_OK:
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020097
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020098#endif /* CONFIG_CM_INIT */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020099
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200100 mov pc, lr
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200101
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200102#ifdef CONFIG_CM_SPD_DETECT
103 /* Fast memory is available for the DRAM data
104 * - ensure it has been transferred, then summarize the data
105 * into a CM register
106 */
107.globl dram_query
108dram_query:
109 stmfd r13!,{r4-r6,lr}
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200110 /* set up SDRAM info */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200111 /* - based on example code from the CM User Guide */
112 mov r0, #CM_BASE
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200113
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200114readspdbit:
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200115 ldr r1, [r0, #OS_SDRAM] /* read the SDRAM register */
116 and r1, r1, #0x20 /* mask SPD bit (5) */
117 cmp r1, #0x20 /* test if set */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200118 bne readspdbit
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200119
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200120setupsdram:
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200121 add r0, r0, #OS_SPD /* address the copy of the SDP data */
122 ldrb r1, [r0, #3] /* number of row address lines */
123 ldrb r2, [r0, #4] /* number of column address lines */
124 ldrb r3, [r0, #5] /* number of banks */
125 ldrb r4, [r0, #31] /* module bank density */
126 mul r5, r4, r3 /* size of SDRAM (MB divided by 4) */
127 mov r5, r5, ASL#2 /* size in MB */
128 mov r0, #CM_BASE /* reload for later code */
129 cmp r5, #0x10 /* is it 16MB? */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200130 bne not16
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200131 mov r6, #0x2 /* store size and CAS latency of 2 */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200132 b writesize
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200133
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200134not16:
135 cmp r5, #0x20 /* is it 32MB? */
136 bne not32
137 mov r6, #0x6
138 b writesize
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200139
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200140not32:
141 cmp r5, #0x40 /* is it 64MB? */
142 bne not64
143 mov r6, #0xa
144 b writesize
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200145
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200146not64:
147 cmp r5, #0x80 /* is it 128MB? */
148 bne not128
149 mov r6, #0xe
150 b writesize
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200151
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200152not128:
153 /* if it is none of these sizes then it is either 256MB, or
154 * there is no SDRAM fitted so default to 256MB
155 */
156 mov r6, #0x12
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200157
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200158writesize:
159 mov r1, r1, ASL#8 /* row addr lines from SDRAM reg */
160 orr r2, r1, r2, ASL#12 /* OR in column address lines */
161 orr r3, r2, r3, ASL#16 /* OR in number of banks */
162 orr r6, r6, r3 /* OR in size and CAS latency */
163 str r6, [r0, #OS_SDRAM] /* store SDRAM parameters */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200164
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200165#endif /* #ifdef CONFIG_CM_SPD_DETECT */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200166
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200167 ldmfd r13!,{r4-r6,pc} /* back to caller */
168
169#ifdef CONFIG_CM_REMAP
170 /* CM remap bit is operational
171 * - use it to map writeable memory at 0x00000000, in place of flash
172 */
173.globl cm_remap
174cm_remap:
175 stmfd r13!,{r4-r10,lr}
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200176
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200177 mov r0, #CM_BASE
178 ldr r1, [r0, #OS_CTRL]
179 orr r1, r1, #CMMASK_REMAP /* set remap and led bits */
180 str r1, [r0, #OS_CTRL]
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200181
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200182 /* Now 0x00000000 is writeable, replace the vectors */
183 ldr r0, =_start /* r0 <- start of vectors */
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100184 add r2, r0, #64 /* r2 <- past vectors */
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200185 sub r1,r1,r1 /* destination 0x00000000 */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200186
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200187copy_vec:
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200188 ldmia r0!, {r3-r10} /* copy from source address [r0] */
189 stmia r1!, {r3-r10} /* copy to target address [r1] */
190 cmp r0, r2 /* until source end address [r2] */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200191 ble copy_vec
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200192
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200193 ldmfd r13!,{r4-r10,pc} /* back to caller */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200194
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200195#endif /* #ifdef CONFIG_CM_REMAP */