blob: ea5b654ed527bb80fc0c129d068863c3671c0e46 [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>
Tom Rini7d1e60d2022-03-30 18:07:15 -040010#include <armcoremodule.h>
wdenk4989f872004-03-14 15:06:13 +000011
Wolfgang Denkadf20a12005-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 Denk03f9ba32005-10-04 23:10:28 +020018 str r1,[r0,#OS_CTRL]
Wolfgang Denkadf20a12005-09-25 01:48:28 +020019
20reset_failed:
21 b reset_failed
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020022
Wolfgang Denk7f88a5e2005-10-06 17:08:18 +020023/* Set up the platform, once the cpu has been initialized */
24.globl lowlevel_init
25lowlevel_init:
Wolfgang Denk5d6879c2005-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 Denk34ca9d32005-09-25 18:49:35 +020034
Wolfgang Denk5d6879c2005-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 Denk34ca9d32005-09-25 18:49:35 +020041
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020042 /* set the desired CM specific value */
43 mov r2,#CMMASK_LOWVEC /* Vectors at 0x00000000 for all */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020044
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020045#if !defined (CONFIG_CM920T) && !defined (CONFIG_CM920T_ETM) && \
46 !defined (CONFIG_CM940T)
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020047
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020048#ifdef CONFIG_CM_MULTIPLE_SSRAM
Wolfgang Denk88bd7432005-10-09 00:22:48 +020049 /* set simple mapping */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020050 and r2,r2,#CMMASK_MAP_SIMPLE
Wolfgang Denk88bd7432005-10-09 00:22:48 +020051#endif /* #ifdef CONFIG_CM_MULTIPLE_SSRAM */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020052
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020053#ifdef CONFIG_CM_TCRAM
Wolfgang Denk88bd7432005-10-09 00:22:48 +020054 /* disable TCRAM */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020055 and r2,r2,#CMMASK_TCRAM_DISABLE
Wolfgang Denk88bd7432005-10-09 00:22:48 +020056#endif /* #ifdef CONFIG_CM_TCRAM */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020057
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020058#if defined (CONFIG_CM926EJ_S) || defined (CONFIG_CM1026EJ_S) || \
Wolfgang Denk88bd7432005-10-09 00:22:48 +020059 defined (CONFIG_CM1136JF_S)
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020060
61 and r2,r2,#CMMASK_LE
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020062
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020063#endif /* cpu with little endian initialization */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020064
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020065 orr r2,r2,#CMMASK_CMxx6_COMMON
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020066
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020067#endif /* CMxx6 code */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020068
Wolfgang Denk88bd7432005-10-09 00:22:48 +020069 /* read CM_INIT */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020070 mov r0, #CM_BASE
71 ldr r1, [r0, #OS_INIT]
72 /* check against desired bit setting */
73 and r3,r1,r2
74 cmp r3,r2
75 beq init_reg_OK
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020076
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020077 /* lock for change */
Wolfgang Denk03f9ba32005-10-04 23:10:28 +020078 mov r3, #CMVAL_LOCK1
79 add r3,r3,#CMVAL_LOCK2
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020080 str r3, [r0, #OS_LOCK]
81 /* set desired value */
82 orr r1,r1,r2
83 /* write & relock CM_INIT */
84 str r1, [r0, #OS_INIT]
85 mov r1, #CMVAL_UNLOCK
86 str r1, [r0, #OS_LOCK]
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020087
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020088 /* soft reset so new values used */
89 b reset_cpu
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020090
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020091init_reg_OK:
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020092
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020093#endif /* CONFIG_CM_INIT */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020094
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020095 mov pc, lr
Wolfgang Denk34ca9d32005-09-25 18:49:35 +020096
Wolfgang Denk5d6879c2005-09-25 16:22:14 +020097#ifdef CONFIG_CM_SPD_DETECT
98 /* Fast memory is available for the DRAM data
99 * - ensure it has been transferred, then summarize the data
100 * into a CM register
101 */
102.globl dram_query
103dram_query:
104 stmfd r13!,{r4-r6,lr}
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200105 /* set up SDRAM info */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200106 /* - based on example code from the CM User Guide */
107 mov r0, #CM_BASE
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200108
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200109readspdbit:
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200110 ldr r1, [r0, #OS_SDRAM] /* read the SDRAM register */
111 and r1, r1, #0x20 /* mask SPD bit (5) */
112 cmp r1, #0x20 /* test if set */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200113 bne readspdbit
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200114
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200115setupsdram:
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200116 add r0, r0, #OS_SPD /* address the copy of the SDP data */
117 ldrb r1, [r0, #3] /* number of row address lines */
118 ldrb r2, [r0, #4] /* number of column address lines */
119 ldrb r3, [r0, #5] /* number of banks */
120 ldrb r4, [r0, #31] /* module bank density */
121 mul r5, r4, r3 /* size of SDRAM (MB divided by 4) */
122 mov r5, r5, ASL#2 /* size in MB */
123 mov r0, #CM_BASE /* reload for later code */
124 cmp r5, #0x10 /* is it 16MB? */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200125 bne not16
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200126 mov r6, #0x2 /* store size and CAS latency of 2 */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200127 b writesize
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200128
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200129not16:
130 cmp r5, #0x20 /* is it 32MB? */
131 bne not32
132 mov r6, #0x6
133 b writesize
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200134
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200135not32:
136 cmp r5, #0x40 /* is it 64MB? */
137 bne not64
138 mov r6, #0xa
139 b writesize
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200140
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200141not64:
142 cmp r5, #0x80 /* is it 128MB? */
143 bne not128
144 mov r6, #0xe
145 b writesize
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200146
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200147not128:
148 /* if it is none of these sizes then it is either 256MB, or
149 * there is no SDRAM fitted so default to 256MB
150 */
151 mov r6, #0x12
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200152
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200153writesize:
154 mov r1, r1, ASL#8 /* row addr lines from SDRAM reg */
155 orr r2, r1, r2, ASL#12 /* OR in column address lines */
156 orr r3, r2, r3, ASL#16 /* OR in number of banks */
157 orr r6, r6, r3 /* OR in size and CAS latency */
158 str r6, [r0, #OS_SDRAM] /* store SDRAM parameters */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200159
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200160#endif /* #ifdef CONFIG_CM_SPD_DETECT */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200161
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200162 ldmfd r13!,{r4-r6,pc} /* back to caller */
163
164#ifdef CONFIG_CM_REMAP
165 /* CM remap bit is operational
166 * - use it to map writeable memory at 0x00000000, in place of flash
167 */
168.globl cm_remap
169cm_remap:
170 stmfd r13!,{r4-r10,lr}
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200171
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200172 mov r0, #CM_BASE
173 ldr r1, [r0, #OS_CTRL]
174 orr r1, r1, #CMMASK_REMAP /* set remap and led bits */
175 str r1, [r0, #OS_CTRL]
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200176
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200177 /* Now 0x00000000 is writeable, replace the vectors */
178 ldr r0, =_start /* r0 <- start of vectors */
Albert ARIBAUD6e294722014-02-22 17:53:43 +0100179 add r2, r0, #64 /* r2 <- past vectors */
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200180 sub r1,r1,r1 /* destination 0x00000000 */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200181
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200182copy_vec:
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200183 ldmia r0!, {r3-r10} /* copy from source address [r0] */
184 stmia r1!, {r3-r10} /* copy to target address [r1] */
185 cmp r0, r2 /* until source end address [r2] */
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200186 ble copy_vec
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200187
Wolfgang Denk88bd7432005-10-09 00:22:48 +0200188 ldmfd r13!,{r4-r10,pc} /* back to caller */
Wolfgang Denk34ca9d32005-09-25 18:49:35 +0200189
Wolfgang Denk5d6879c2005-09-25 16:22:14 +0200190#endif /* #ifdef CONFIG_CM_REMAP */