blob: b6cf6a996006c5b9cd5eb26704e885d0a208bb88 [file] [log] [blame]
wdenkbb1b8262003-03-27 12:09:35 +00001/*
2 * Memory sub-system initialization code for INCA-IP development board.
3 *
4 * Copyright (c) 2003 Wolfgang Denk <wd@denx.de>
5 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02006 * SPDX-License-Identifier: GPL-2.0+
wdenkbb1b8262003-03-27 12:09:35 +00007 */
8
9#include <config.h>
wdenkbb1b8262003-03-27 12:09:35 +000010#include <asm/regdef.h>
11
12
wdenk1ebf41e2004-01-02 14:00:00 +000013#define EBU_MODUL_BASE 0xB8000200
14#define EBU_CLC(value) 0x0000(value)
15#define EBU_CON(value) 0x0010(value)
16#define EBU_ADDSEL0(value) 0x0020(value)
17#define EBU_ADDSEL1(value) 0x0024(value)
18#define EBU_ADDSEL2(value) 0x0028(value)
19#define EBU_BUSCON0(value) 0x0060(value)
20#define EBU_BUSCON1(value) 0x0064(value)
21#define EBU_BUSCON2(value) 0x0068(value)
wdenkbb1b8262003-03-27 12:09:35 +000022
wdenk1ebf41e2004-01-02 14:00:00 +000023#define MC_MODUL_BASE 0xBF800000
24#define MC_ERRCAUSE(value) 0x0100(value)
25#define MC_ERRADDR(value) 0x0108(value)
26#define MC_IOGP(value) 0x0800(value)
27#define MC_SELFRFSH(value) 0x0A00(value)
28#define MC_CTRLENA(value) 0x1000(value)
29#define MC_MRSCODE(value) 0x1008(value)
30#define MC_CFGDW(value) 0x1010(value)
31#define MC_CFGPB0(value) 0x1018(value)
32#define MC_LATENCY(value) 0x1038(value)
33#define MC_TREFRESH(value) 0x1040(value)
wdenkbb1b8262003-03-27 12:09:35 +000034
wdenk1ebf41e2004-01-02 14:00:00 +000035#define CGU_MODUL_BASE 0xBF107000
36#define CGU_PLL1CR(value) 0x0008(value)
37#define CGU_DIVCR(value) 0x0010(value)
38#define CGU_MUXCR(value) 0x0014(value)
39#define CGU_PLL1SR(value) 0x000C(value)
wdenkbb1b8262003-03-27 12:09:35 +000040
wdenk1ebf41e2004-01-02 14:00:00 +000041 .set noreorder
wdenkbb1b8262003-03-27 12:09:35 +000042
wdenkbb1b8262003-03-27 12:09:35 +000043
wdenk67f13362003-12-27 19:24:54 +000044/*
45 * void ebu_init(long)
46 *
47 * a0 has the clock value we are going to run at
48 */
49 .globl ebu_init
50 .ent ebu_init
51ebu_init:
Wolfgang Denkf6a692b2005-12-04 00:40:34 +010052__ebu_init:
wdenkbb1b8262003-03-27 12:09:35 +000053
wdenk67f13362003-12-27 19:24:54 +000054 li t1, EBU_MODUL_BASE
55 li t2, 0xA0000041
56 sw t2, EBU_ADDSEL0(t1)
57 li t2, 0xA0800041
58 sw t2, EBU_ADDSEL2(t1)
59 li t2, 0xBE0000F1
60 sw t2, EBU_ADDSEL1(t1)
wdenkbb1b8262003-03-27 12:09:35 +000061
wdenk67f13362003-12-27 19:24:54 +000062 li t3, 100000000
63 beq a0, t3, 1f
64 nop
65 li t3, 133000000
66 beq a0, t3, 2f
67 nop
68 li t3, 150000000
69 beq a0, t3, 2f
70 nop
71 b 3f
72 nop
wdenkbb1b8262003-03-27 12:09:35 +000073
wdenk67f13362003-12-27 19:24:54 +000074 /* 100 MHz */
751:
76 li t2, 0x8841417D
77 sw t2, EBU_BUSCON0(t1)
78 sw t2, EBU_BUSCON2(t1)
79 li t2, 0x684142BD
80 b 3f
81 sw t2, EBU_BUSCON1(t1) /* delay slot */
82
83 /* 133 or 150 MHz */
842:
85 li t2, 0x8841417E
86 sw t2, EBU_BUSCON0(t1)
87 sw t2, EBU_BUSCON2(t1)
88 li t2, 0x684143FD
89 sw t2, EBU_BUSCON1(t1)
903:
Shinya Kuribayashi9dabea12008-04-17 23:35:13 +090091 jr ra
wdenk67f13362003-12-27 19:24:54 +000092 nop
93
94 .end ebu_init
95
96
97/*
98 * void cgu_init(long)
99 *
100 * a0 has the clock value
101 */
102 .globl cgu_init
103 .ent cgu_init
104cgu_init:
Wolfgang Denkf6a692b2005-12-04 00:40:34 +0100105__cgu_init:
wdenk67f13362003-12-27 19:24:54 +0000106
107 li t1, CGU_MODUL_BASE
108
109 li t3, 100000000
110 beq a0, t3, 1f
111 nop
112 li t3, 133000000
113 beq a0, t3, 2f
114 nop
115 li t3, 150000000
116 beq a0, t3, 3f
117 nop
118 b 5f
119 nop
120
121 /* 100 MHz clock */
1221:
123 li t2, 0x80000014
124 sw t2, CGU_DIVCR(t1)
125 li t2, 0x80000000
126 sw t2, CGU_MUXCR(t1)
127 li t2, 0x800B0001
128 b 5f
129 sw t2, CGU_PLL1CR(t1) /* delay slot */
130
131 /* 133 MHz clock */
1322:
133 li t2, 0x80000054
134 sw t2, CGU_DIVCR(t1)
135 li t2, 0x80000000
136 sw t2, CGU_MUXCR(t1)
137 li t2, 0x800B0001
138 b 5f
139 sw t2, CGU_PLL1CR(t1) /* delay slot */
140
141 /* 150 MHz clock */
1423:
143 li t2, 0x80000017
144 sw t2, CGU_DIVCR(t1)
145 li t2, 0xC00B0001
146 sw t2, CGU_PLL1CR(t1)
147 li t3, 0x80000000
1484:
149 lw t2, CGU_PLL1SR(t1)
150 and t2, t2, t3
151 beq t2, zero, 4b
152 nop
153 li t2, 0x80000001
154 sw t2, CGU_MUXCR(t1)
1555:
Shinya Kuribayashi9dabea12008-04-17 23:35:13 +0900156 jr ra
wdenk67f13362003-12-27 19:24:54 +0000157 nop
158
159 .end cgu_init
wdenkbb1b8262003-03-27 12:09:35 +0000160
wdenkbb1b8262003-03-27 12:09:35 +0000161
wdenk433feff2004-01-29 09:22:58 +0000162/*
163 * void sdram_init(long)
164 *
165 * a0 has the clock value
166 */
167 .globl sdram_init
168 .ent sdram_init
169sdram_init:
Wolfgang Denkf6a692b2005-12-04 00:40:34 +0100170__sdram_init:
wdenk67f13362003-12-27 19:24:54 +0000171
wdenk433feff2004-01-29 09:22:58 +0000172 li t1, MC_MODUL_BASE
wdenk67f13362003-12-27 19:24:54 +0000173
wdenk4dd56e52004-02-20 22:02:48 +0000174#if 0
wdenk433feff2004-01-29 09:22:58 +0000175 /* Disable memory controller before changing any of its registers */
176 sw zero, MC_CTRLENA(t1)
wdenk4dd56e52004-02-20 22:02:48 +0000177#endif
wdenk433feff2004-01-29 09:22:58 +0000178
179 li t2, 100000000
180 beq a0, t2, 1f
wdenk67f13362003-12-27 19:24:54 +0000181 nop
wdenk433feff2004-01-29 09:22:58 +0000182 li t2, 133000000
183 beq a0, t2, 2f
wdenk67f13362003-12-27 19:24:54 +0000184 nop
wdenk433feff2004-01-29 09:22:58 +0000185 li t2, 150000000
186 beq a0, t2, 3f
187 nop
188 b 5f
189 nop
wdenkbb1b8262003-03-27 12:09:35 +0000190
wdenk433feff2004-01-29 09:22:58 +0000191 /* 100 MHz clock */
1921:
193 /* Set clock ratio (clkrat=1:1, rddel=3) */
194 li t2, 0x00000003
195 sw t2, MC_IOGP(t1)
wdenkbb1b8262003-03-27 12:09:35 +0000196
wdenk433feff2004-01-29 09:22:58 +0000197 /* Set sdram refresh rate (4K/64ms @ 100MHz) */
198 li t2, 0x0000061A
199 b 4f
200 sw t2, MC_TREFRESH(t1)
201
202 /* 133 MHz clock */
2032:
204 /* Set clock ratio (clkrat=1:1, rddel=3) */
205 li t2, 0x00000003
206 sw t2, MC_IOGP(t1)
wdenkbb1b8262003-03-27 12:09:35 +0000207
wdenk433feff2004-01-29 09:22:58 +0000208 /* Set sdram refresh rate (4K/64ms @ 133MHz) */
209 li t2, 0x00000822
210 b 4f
211 sw t2, MC_TREFRESH(t1)
212
213 /* 150 MHz clock */
2143:
215 /* Set clock ratio (clkrat=3:2, rddel=4) */
216 li t2, 0x00000014
217 sw t2, MC_IOGP(t1)
218
219 /* Set sdram refresh rate (4K/64ms @ 150MHz) */
220 li t2, 0x00000927
221 sw t2, MC_TREFRESH(t1)
222
2234:
224 /* Clear Error log registers */
225 sw zero, MC_ERRCAUSE(t1)
226 sw zero, MC_ERRADDR(t1)
wdenkbb1b8262003-03-27 12:09:35 +0000227
228 /* Clear Power-down registers */
wdenk433feff2004-01-29 09:22:58 +0000229 sw zero, MC_SELFRFSH(t1)
wdenkbb1b8262003-03-27 12:09:35 +0000230
231 /* Set CAS Latency */
wdenk433feff2004-01-29 09:22:58 +0000232 li t2, 0x00000020 /* CL = 2 */
233 sw t2, MC_MRSCODE(t1)
wdenkbb1b8262003-03-27 12:09:35 +0000234
235 /* Set word width to 16 bit */
wdenk433feff2004-01-29 09:22:58 +0000236 li t2, 0x2
237 sw t2, MC_CFGDW(t1)
wdenkbb1b8262003-03-27 12:09:35 +0000238
239 /* Set CS0 to SDRAM parameters */
wdenk433feff2004-01-29 09:22:58 +0000240 li t2, 0x000014C9
241 sw t2, MC_CFGPB0(t1)
wdenkbb1b8262003-03-27 12:09:35 +0000242
243 /* Set SDRAM latency parameters */
wdenk433feff2004-01-29 09:22:58 +0000244 li t2, 0x00026325 /* BC PC100 */
245 sw t2, MC_LATENCY(t1)
wdenkbb1b8262003-03-27 12:09:35 +0000246
wdenk433feff2004-01-29 09:22:58 +00002475:
wdenkbb1b8262003-03-27 12:09:35 +0000248 /* Finally enable the controller */
wdenk433feff2004-01-29 09:22:58 +0000249 li t2, 0x00000001
250 sw t2, MC_CTRLENA(t1)
wdenkbb1b8262003-03-27 12:09:35 +0000251
Shinya Kuribayashi9dabea12008-04-17 23:35:13 +0900252 jr ra
wdenkbb1b8262003-03-27 12:09:35 +0000253 nop
wdenk433feff2004-01-29 09:22:58 +0000254
255 .end sdram_init
256
257
wdenk336b2bc2005-04-02 23:52:25 +0000258 .globl lowlevel_init
259 .ent lowlevel_init
260lowlevel_init:
wdenk433feff2004-01-29 09:22:58 +0000261
Shinya Kuribayashib5876f62008-03-25 21:30:07 +0900262 /* Disable Watchdog.
263 */
264 la t9, disable_incaip_wdt
265 jalr t9
266 nop
267
wdenk433feff2004-01-29 09:22:58 +0000268 /* EBU, CGU and SDRAM Initialization.
269 */
Shinya Kuribayashi9b844372011-02-05 18:33:36 +0900270 li a0, CONFIG_CPU_CLOCK_RATE
wdenk433feff2004-01-29 09:22:58 +0000271 move t0, ra
272
273 /* We rely on the fact that neither ebu_init() nor cgu_init() nor sdram_init()
274 * modify t0 and a0.
275 */
Wolfgang Denkf6a692b2005-12-04 00:40:34 +0100276 bal __cgu_init
wdenk433feff2004-01-29 09:22:58 +0000277 nop
Wolfgang Denkf6a692b2005-12-04 00:40:34 +0100278 bal __ebu_init
wdenk433feff2004-01-29 09:22:58 +0000279 nop
Wolfgang Denkf6a692b2005-12-04 00:40:34 +0100280 bal __sdram_init
wdenk433feff2004-01-29 09:22:58 +0000281 nop
282 move ra, t0
283
Shinya Kuribayashi9dabea12008-04-17 23:35:13 +0900284 jr ra
wdenk433feff2004-01-29 09:22:58 +0000285 nop
286
wdenk336b2bc2005-04-02 23:52:25 +0000287 .end lowlevel_init