blob: 18f7d2eaebe7ef796f817a14032cb2bd79bf0388 [file] [log] [blame]
wdenk4989f872004-03-14 15:06:13 +00001/*
2 * Board specific setup info
3 *
4 * (C) Copyright 2003, ARM Ltd.
5 * Philippe Robin, <philippe.robin@arm.com>
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Wolfgang Denkc856ccc2005-09-25 02:00:47 +020017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenk4989f872004-03-14 15:06:13 +000018 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26#include <config.h>
27#include <version.h>
28
Wolfgang Denkadf20a12005-09-25 01:48:28 +020029/* Reset using CM control register */
30.global reset_cpu
31reset_cpu:
32 mov r0, #CM_BASE
33 ldr r1,[r0,#OS_CTRL]
34 orr r1,r1,#CMMASK_RESET
Wolfgang Denk03f9ba32005-10-04 23:10:28 +020035 str r1,[r0,#OS_CTRL]
Wolfgang Denkadf20a12005-09-25 01:48:28 +020036
37reset_failed:
38 b reset_failed
39
Wolfgang Denk7f88a5e2005-10-06 17:08:18 +020040/* Set up the platform, once the cpu has been initialized */
41.globl lowlevel_init
42lowlevel_init:
Wolfgang Denkadf20a12005-09-25 01:48:28 +020043 /* If U-Boot has been run after the ARM boot monitor
44 * then all the necessary actions have been done
45 * otherwise we are running from user flash mapped to 0x00000000
46 * --- DO NOT REMAP BEFORE THE CODE HAS BEEN RELOCATED --
47 * Changes to the (possibly soft) reset defaults of the processor
48 * itself should be performed in cpu/arm<>/start.S
49 * This function affects only the core module or board settings
50 */
51
52#ifdef CONFIG_CM_INIT
53 /* CM has an initialization register
54 * - bits in it are wired into test-chip pins to force
Wolfgang Denkc856ccc2005-09-25 02:00:47 +020055 * reset defaults
56 * - may need to change its contents for U-Boot
Wolfgang Denkadf20a12005-09-25 01:48:28 +020057 */
58
59 /* set the desired CM specific value */
60 mov r2,#CMMASK_LOWVEC /* Vectors at 0x00000000 for all */
61
62#if defined (CONFIG_CM10200E) || defined (CONFIG_CM10220E)
63 orr r2,r2,#CMMASK_INIT_102
64#else
65
Wolfgang Denk88bd7432005-10-09 00:22:48 +020066#if !defined (CONFIG_CM920T) && !defined (CONFIG_CM920T_ETM) && \
67 !defined (CONFIG_CM940T)
68 /* CMxx6 code */
Wolfgang Denkc856ccc2005-09-25 02:00:47 +020069
70#ifdef CONFIG_CM_MULTIPLE_SSRAM
Wolfgang Denk88bd7432005-10-09 00:22:48 +020071 /* set simple mapping */
Wolfgang Denkadf20a12005-09-25 01:48:28 +020072 and r2,r2,#CMMASK_MAP_SIMPLE
Wolfgang Denk88bd7432005-10-09 00:22:48 +020073#endif /* #ifdef CONFIG_CM_MULTIPLE_SSRAM */
Wolfgang Denkadf20a12005-09-25 01:48:28 +020074
Wolfgang Denkc856ccc2005-09-25 02:00:47 +020075#ifdef CONFIG_CM_TCRAM
Wolfgang Denk88bd7432005-10-09 00:22:48 +020076 /* disable TCRAM */
Wolfgang Denkadf20a12005-09-25 01:48:28 +020077 and r2,r2,#CMMASK_TCRAM_DISABLE
Wolfgang Denk88bd7432005-10-09 00:22:48 +020078#endif /* #ifdef CONFIG_CM_TCRAM */
Wolfgang Denkadf20a12005-09-25 01:48:28 +020079
80#if defined (CONFIG_CM926EJ_S) || defined (CONFIG_CM1026EJ_S) || \
Wolfgang Denk88bd7432005-10-09 00:22:48 +020081 defined (CONFIG_CM1136JF_S)
Wolfgang Denkadf20a12005-09-25 01:48:28 +020082
83 and r2,r2,#CMMASK_LE
Wolfgang Denkc856ccc2005-09-25 02:00:47 +020084
Wolfgang Denkadf20a12005-09-25 01:48:28 +020085#endif /* cpu with little endian initialization */
86
87 orr r2,r2,#CMMASK_CMxx6_COMMON
88
89#endif /* CMxx6 code */
Wolfgang Denkc856ccc2005-09-25 02:00:47 +020090
Wolfgang Denkadf20a12005-09-25 01:48:28 +020091#endif /* ARM102xxE value */
Wolfgang Denkc856ccc2005-09-25 02:00:47 +020092
Wolfgang Denk88bd7432005-10-09 00:22:48 +020093 /* read CM_INIT */
Wolfgang Denkadf20a12005-09-25 01:48:28 +020094 mov r0, #CM_BASE
95 ldr r1, [r0, #OS_INIT]
96 /* check against desired bit setting */
97 and r3,r1,r2
98 cmp r3,r2
99 beq init_reg_OK
Wolfgang Denkc856ccc2005-09-25 02:00:47 +0200100
101 /* lock for change */
Wolfgang Denk03f9ba32005-10-04 23:10:28 +0200102 mov r3, #CMVAL_LOCK1
103 and r3, r3, #CMVAL_LOCK2
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200104 str r3, [r0, #OS_LOCK]
105 /* set desired value */
106 orr r1,r1,r2
107 /* write & relock CM_INIT */
108 str r1, [r0, #OS_INIT]
109 mov r1, #CMVAL_UNLOCK
110 str r1, [r0, #OS_LOCK]
111
112 /* soft reset so new values used */
113 b reset_cpu
114
115init_reg_OK:
Wolfgang Denkc856ccc2005-09-25 02:00:47 +0200116
117#endif /* CONFIG_CM_INIT */
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200118
119 mov pc, lr
120
Wolfgang Denkc856ccc2005-09-25 02:00:47 +0200121#ifdef CONFIG_CM_SPD_DETECT
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200122 /* Fast memory is available for the DRAM data
Wolfgang Denkc856ccc2005-09-25 02:00:47 +0200123 * - ensure it has been transferred, then summarize the data
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200124 * into a CM register
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200125 */
126.globl dram_query
127dram_query:
128 stmfd r13!,{r4-r6,lr}
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200129 /* set up SDRAM info */
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200130 /* - based on example code from the CM User Guide */
131 mov r0, #CM_BASE
Wolfgang Denkc856ccc2005-09-25 02:00:47 +0200132
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200133readspdbit:
Wolfgang Denkc856ccc2005-09-25 02:00:47 +0200134 ldr r1, [r0, #OS_SDRAM] /* read the SDRAM register */
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200135 and r1, r1, #0x20 /* mask SPD bit (5) */
136 cmp r1, #0x20 /* test if set */
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200137 bne readspdbit
138
139setupsdram:
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200140 add r0, r0, #OS_SPD /* address the copy of the SDP data */
141 ldrb r1, [r0, #3] /* number of row address lines */
142 ldrb r2, [r0, #4] /* number of column address lines */
143 ldrb r3, [r0, #5] /* number of banks */
144 ldrb r4, [r0, #31] /* module bank density */
145 mul r5, r4, r3 /* size of SDRAM (MB divided by 4) */
146 mov r5, r5, ASL#2 /* size in MB */
147 mov r0, #CM_BASE /* reload for later code */
148 cmp r5, #0x10 /* is it 16MB? */
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200149 bne not16
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200150 mov r6, #0x2 /* store size and CAS latency of 2 */
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200151 b writesize
152
153not16:
154 cmp r5, #0x20 /* is it 32MB? */
155 bne not32
156 mov r6, #0x6
157 b writesize
158
159not32:
160 cmp r5, #0x40 /* is it 64MB? */
161 bne not64
162 mov r6, #0xa
163 b writesize
164
165not64:
166 cmp r5, #0x80 /* is it 128MB? */
167 bne not128
168 mov r6, #0xe
169 b writesize
170
171not128:
172 /* if it is none of these sizes then it is either 256MB, or
173 * there is no SDRAM fitted so default to 256MB
174 */
175 mov r6, #0x12
176
177writesize:
178 mov r1, r1, ASL#8 /* row addr lines from SDRAM reg */
Wolfgang Denkc856ccc2005-09-25 02:00:47 +0200179 orr r2, r1, r2, ASL#12 /* OR in column address lines */
180 orr r3, r2, r3, ASL#16 /* OR in number of banks */
181 orr r6, r6, r3 /* OR in size and CAS latency */
182 str r6, [r0, #OS_SDRAM] /* store SDRAM parameters */
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200183
184#endif /* #ifdef CONFIG_CM_SPD_DETECT */
185
186 ldmfd r13!,{r4-r6,pc} /* back to caller */
187
Wolfgang Denkc856ccc2005-09-25 02:00:47 +0200188#ifdef CONFIG_CM_REMAP
189 /* CM remap bit is operational
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200190 * - use it to map writeable memory at 0x00000000, in place of flash
191 */
192.globl cm_remap
Wolfgang Denkc856ccc2005-09-25 02:00:47 +0200193cm_remap:
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200194 stmfd r13!,{r4-r10,lr}
195
196 mov r0, #CM_BASE
197 ldr r1, [r0, #OS_CTRL]
198 orr r1, r1, #CMMASK_REMAP /* set remap and led bits */
199 str r1, [r0, #OS_CTRL]
200
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200201 /* Now 0x00000000 is writeable, replace the vectors */
202 ldr r0, =_start /* r0 <- start of vectors */
203 ldr r2, =_armboot_start /* r2 <- past vectors */
204 sub r1,r1,r1 /* destination 0x00000000 */
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200205
206copy_vec:
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200207 ldmia r0!, {r3-r10} /* copy from source address [r0] */
208 stmia r1!, {r3-r10} /* copy to target address [r1] */
209 cmp r0, r2 /* until source end address [r2] */
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200210 ble copy_vec
211
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200212 ldmfd r13!,{r4-r10,pc} /* back to caller */
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200213
214#endif /* #ifdef CONFIG_CM_REMAP */