2 * Memory Setup stuff - taken from blob memsetup.S
4 * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) and
5 * Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
7 * Modified for MPL VCMA9 by
8 * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
9 * (C) Copyright 2002, 2003, 2004, 2005
11 * SPDX-License-Identifier: GPL-2.0+
19 /* register definitions */
21 #define PLD_BASE 0x28000000
22 #define MISC_REG 0x103
23 #define SDRAM_REG 0x106
24 #define BWSCON 0x48000000
25 #define CLKBASE 0x4C000000
29 #define GPIOBASE 0x56000000
33 /* some parameters for the board */
42 #define BURST_EN (0x1<<7)
45 #define B0_Tacs_200 0x0 /* 0clk (or 0x1 1clk) */
46 #define B0_Tcos_200 0x1 /* 1clk (or 0x2 2clk) */
47 #define B0_Tacc_200 0x5 /* 8clk (or 0x6 10clk) */
48 #define B0_Tcoh_200 0x0 /* 0clk */
49 #define B0_Tcah_200 0x3 /* 4clk (or0x01 1clk) */
50 #define B0_Tacp_200 0x0 /* page mode is not used */
51 #define B0_PMC_200 0x0 /* page mode disabled */
54 #define B0_Tacs_250 0x0 /* 0clk (or 0x1 1clk) */
55 #define B0_Tcos_250 0x1 /* 1clk (or 0x2 2clk) */
56 #define B0_Tacc_250 0x5 /* 8clk (or 0x7 14clk) */
57 #define B0_Tcoh_250 0x0 /* 0clk */
58 #define B0_Tcah_250 0x3 /* 4clk (or 0x1 1clk) */
59 #define B0_Tacp_250 0x0 /* page mode is not used */
60 #define B0_PMC_250 0x0 /* page mode disabled */
63 #define B0_Tacs_266 0x0 /* 0clk (or 0x1 1clk) */
64 #define B0_Tcos_266 0x1 /* 1clk (or 0x2 2clk) */
65 #define B0_Tacc_266 0x6 /* 10clk (or 0x7 14clk) */
66 #define B0_Tcoh_266 0x0 /* 0clk */
67 #define B0_Tcah_266 0x3 /* 4clk (or 0x1 1clk) */
68 #define B0_Tacp_266 0x0 /* page mode is not used */
69 #define B0_PMC_266 0x0 /* page mode disabled */
72 #define B1_Tacs_200 0x0 /* 0clk (or 0x1 1clk) */
73 #define B1_Tcos_200 0x1 /* 1clk (or 0x2 2clk) */
74 #define B1_Tacc_200 0x5 /* 8clk (or 0x6 10clk) */
75 #define B1_Tcoh_200 0x0 /* 0clk */
76 #define B1_Tcah_200 0x3 /* 4clk (or 0x1 1clk) */
77 #define B1_Tacp_200 0x0 /* page mode is not used */
78 #define B1_PMC_200 0x0 /* page mode disabled */
81 #define B1_Tacs_250 0x0 /* 0clk (or 0x1 1clk) */
82 #define B1_Tcos_250 0x1 /* 1clk (or 0x2 2clk) */
83 #define B1_Tacc_250 0x5 /* 8clk (or 0x7 14clk) */
84 #define B1_Tcoh_250 0x0 /* 0clk */
85 #define B1_Tcah_250 0x3 /* 4clk (or 0x1 1clk) */
86 #define B1_Tacp_250 0x0 /* page mode is not used */
87 #define B1_PMC_250 0x0 /* page mode disabled */
90 #define B1_Tacs_266 0x0 /* 0clk (or 0x1 1clk) */
91 #define B1_Tcos_266 0x1 /* 1clk (or 0x2 2clk) */
92 #define B1_Tacc_266 0x6 /* 10clk (or 0x7 14clk) */
93 #define B1_Tcoh_266 0x0 /* 0clk */
94 #define B1_Tcah_266 0x3 /* 4clk (or 0x1 1clk) */
95 #define B1_Tacp_266 0x0 /* page mode is not used */
96 #define B1_PMC_266 0x0 /* page mode disabled */
98 /* BANK2CON 200 + 250 + 266 */
99 #define B2_Tacs 0x3 /* 4clk */
100 #define B2_Tcos 0x3 /* 4clk */
101 #define B2_Tacc 0x7 /* 14clk */
102 #define B2_Tcoh 0x3 /* 4clk */
103 #define B2_Tcah 0x3 /* 4clk */
104 #define B2_Tacp 0x0 /* page mode is not used */
105 #define B2_PMC 0x0 /* page mode disabled */
107 /* BANK3CON 200 + 250 + 266 */
108 #define B3_Tacs 0x3 /* 4clk */
109 #define B3_Tcos 0x3 /* 4clk */
110 #define B3_Tacc 0x7 /* 14clk */
111 #define B3_Tcoh 0x3 /* 4clk */
112 #define B3_Tcah 0x3 /* 4clk */
113 #define B3_Tacp 0x0 /* page mode is not used */
114 #define B3_PMC 0x0 /* page mode disabled */
117 #define B4_Tacs_200 0x1 /* 1clk */
118 #define B4_Tcos_200 0x3 /* 4clk */
119 #define B4_Tacc_200 0x7 /* 14clk */
120 #define B4_Tcoh_200 0x3 /* 4clk */
121 #define B4_Tcah_200 0x2 /* 2clk */
122 #define B4_Tacp_200 0x0 /* page mode is not used */
123 #define B4_PMC_200 0x0 /* page mode disabled */
126 #define B4_Tacs_250 0x1 /* 1clk */
127 #define B4_Tcos_250 0x3 /* 4clk */
128 #define B4_Tacc_250 0x7 /* 14clk */
129 #define B4_Tcoh_250 0x3 /* 4clk */
130 #define B4_Tcah_250 0x2 /* 2clk */
131 #define B4_Tacp_250 0x0 /* page mode is not used */
132 #define B4_PMC_250 0x0 /* page mode disabled */
135 #define B4_Tacs_266 0x1 /* 1clk */
136 #define B4_Tcos_266 0x3 /* 4clk */
137 #define B4_Tacc_266 0x7 /* 14clk */
138 #define B4_Tcoh_266 0x3 /* 4clk */
139 #define B4_Tcah_266 0x2 /* 2clk */
140 #define B4_Tacp_266 0x0 /* page mode is not used */
141 #define B4_PMC_266 0x0 /* page mode disabled */
144 #define B5_Tacs_200 0x0 /* 0clk */
145 #define B5_Tcos_200 0x3 /* 4clk */
146 #define B5_Tacc_200 0x4 /* 6clk */
147 #define B5_Tcoh_200 0x3 /* 4clk */
148 #define B5_Tcah_200 0x1 /* 1clk */
149 #define B5_Tacp_200 0x0 /* page mode is not used */
150 #define B5_PMC_200 0x0 /* page mode disabled */
153 #define B5_Tacs_250 0x0 /* 0clk */
154 #define B5_Tcos_250 0x3 /* 4clk */
155 #define B5_Tacc_250 0x5 /* 8clk */
156 #define B5_Tcoh_250 0x3 /* 4clk */
157 #define B5_Tcah_250 0x1 /* 1clk */
158 #define B5_Tacp_250 0x0 /* page mode is not used */
159 #define B5_PMC_250 0x0 /* page mode disabled */
162 #define B5_Tacs_266 0x0 /* 0clk */
163 #define B5_Tcos_266 0x3 /* 4clk */
164 #define B5_Tacc_266 0x5 /* 8clk */
165 #define B5_Tcoh_266 0x3 /* 4clk */
166 #define B5_Tcah_266 0x1 /* 1clk */
167 #define B5_Tacp_266 0x0 /* page mode is not used */
168 #define B5_PMC_266 0x0 /* page mode disabled */
170 #define B6_MT 0x3 /* SDRAM */
171 #define B6_Trcd_200 0x0 /* 2clk */
172 #define B6_Trcd_250 0x1 /* 3clk */
173 #define B6_Trcd_266 0x1 /* 3clk */
174 #define B6_SCAN 0x2 /* 10bit */
176 #define B7_MT 0x3 /* SDRAM */
177 #define B7_Trcd_200 0x0 /* 2clk */
178 #define B7_Trcd_250 0x1 /* 3clk */
179 #define B7_Trcd_266 0x1 /* 3clk */
180 #define B7_SCAN 0x2 /* 10bit */
182 /* REFRESH parameter */
183 #define REFEN 0x1 /* Refresh enable */
184 #define TREFMD 0x0 /* CBR(CAS before RAS)/Auto refresh */
185 #define Trp_200 0x0 /* 2clk */
186 #define Trp_250 0x1 /* 3clk */
187 #define Trp_266 0x1 /* 3clk */
188 #define Tsrc_200 0x1 /* 5clk */
189 #define Tsrc_250 0x2 /* 6clk */
190 #define Tsrc_266 0x3 /* 7clk */
192 /* period=15.6us, HCLK=100Mhz, (2048+1-15.6*100) */
193 #define REFCNT_200 489
194 /* period=15.6us, HCLK=125Mhz, (2048+1-15.6*125) */
195 #define REFCNT_250 99
196 /* period=15.6us, HCLK=133Mhz, (2048+1-15.6*133) */
198 /**************************************/
202 /* use r0 to relocate DATA read/write to flash rather than memory ! */
203 ldr r0, =CONFIG_SYS_TEXT_BASE
206 /* enable minimal access to PLD */
207 ldr r1, [r13] /* load default BWSCON */
208 orr r1, r1, #(DW8 + UBLB) << 20 /* set necessary CS attrs */
209 str r1, [r13] /* set BWSCON */
210 ldr r1, =0x7FF0 /* select slowest timing */
211 str r1, [r13, #0x18] /* set BANKCON5 */
215 ldrb r1, [r1, #MISC_REG]
217 tst r1, #FASTCPU /* FASTCPU available ? */
218 addeq r2, r2, #SETUPENTRY_SIZE
220 /* memory control configuration */
221 /* r2 = pointer into timing table */
222 /* r13 = pointer to MEM controller regs (starting with BWSCON) */
223 add r3, r2, #CSDATA_OFFSET
224 add r4, r3, #CSDATAENTRY_SIZE
231 /* PLD access is now possible */
233 /* r13 = pointer to MEM controller regs */
235 mov r4, #SDRAMENTRY_SIZE
236 ldrb r1, [r1, #SDRAM_REG]
237 /* calculate start and end point */
246 /* setup MPLL registers */
249 add r3, r2, #4 /* r3 points to PLL values */
250 str r4, [r1, #LOCKTIME]
252 str r5, [r1, #UPLLCON] /* writing PLL register */
253 /* !! order seems to be important !! */
260 str r4, [r1, #MPLLCON] /* writing PLL register */
261 /* !! order seems to be important !! */
268 /* everything is fine now */
272 /* the literal pools origin */
274 #define MK_BWSCON(bws1, bws2, bws3, bws4, bws5, bws6, bws7) \
283 #define MK_BANKCON(tacs, tcos, tacc, tcoh, tcah, tacp, pmc) \
292 #define MK_BANKCON_SDRAM(trcd, scan) \
297 #define MK_SDRAM_REFRESH(enable, trefmd, trp, tsrc, cnt) \
306 /* PLL values (MDIV, PDIV, SDIV) for 250 MHz */
307 .word (0x75 << 12) + (0x01 << 4) + (0x01 << 0)
308 /* PLL values for USB clock */
309 .word (0x48 << 12) + (0x03 << 4) + (0x02 << 0)
311 /* timing for 250 MHz*/
313 .equiv CSDATA_OFFSET, (. - SETUPDATA)
314 .word MK_BWSCON(DW16, \
317 DW16 + WAIT + UBLB, \
322 .word MK_BANKCON(B0_Tacs_250, \
330 .word MK_BANKCON(B1_Tacs_250, \
338 .word MK_BANKCON(B2_Tacs, \
346 .word MK_BANKCON(B3_Tacs, \
354 .word MK_BANKCON(B4_Tacs_250, \
362 .word MK_BANKCON(B5_Tacs_250, \
370 .equiv CSDATAENTRY_SIZE, (. - 0b)
373 .word MK_BANKCON_SDRAM(B6_Trcd_250, B6_SCAN)
374 .word MK_BANKCON_SDRAM(B7_Trcd_250, B7_SCAN)
375 .word MK_SDRAM_REFRESH(REFEN, TREFMD, Trp_250, Tsrc_250, REFCNT_250)
376 .word 0x32 + BURST_EN
379 .equiv SDRAMENTRY_SIZE, (. - 0b)
382 .word MK_BANKCON_SDRAM(B6_Trcd_250, B6_SCAN)
383 .word MK_BANKCON_SDRAM(B7_Trcd_250, B7_SCAN)
384 .word MK_SDRAM_REFRESH(REFEN, TREFMD, Trp_250, Tsrc_250, REFCNT_250)
385 .word 0x32 + BURST_EN
390 .word MK_BANKCON_SDRAM(B6_Trcd_250, B6_SCAN)
391 .word MK_BANKCON_SDRAM(B7_Trcd_250, B7_SCAN)
392 .word MK_SDRAM_REFRESH(REFEN, TREFMD, Trp_250, Tsrc_250, REFCNT_250)
393 .word 0x32 + BURST_EN
398 .word MK_BANKCON_SDRAM(B6_Trcd_250, B6_SCAN)
399 .word MK_BANKCON_SDRAM(B7_Trcd_250, B7_SCAN)
400 .word MK_SDRAM_REFRESH(REFEN, TREFMD, Trp_250, Tsrc_250, REFCNT_250)
401 .word 0x32 + BURST_EN
405 .equiv SETUPENTRY_SIZE, (. - SETUPDATA)
408 /* PLL values (MDIV, PDIV, SDIV) for 200 MHz (Fout = 202.8MHz) */
409 .word (0xA1 << 12) + (0x03 << 4) + (0x01 << 0)
410 /* PLL values for USB clock */
411 .word (0x48 << 12) + (0x03 << 4) + (0x02 << 0)
413 /* timing for 200 MHz and default*/
414 .word MK_BWSCON(DW16, \
417 DW16 + WAIT + UBLB, \
422 .word MK_BANKCON(B0_Tacs_200, \
430 .word MK_BANKCON(B1_Tacs_200, \
438 .word MK_BANKCON(B2_Tacs, \
446 .word MK_BANKCON(B3_Tacs, \
454 .word MK_BANKCON(B4_Tacs_200, \
462 .word MK_BANKCON(B5_Tacs_200, \
471 .word MK_BANKCON_SDRAM(B6_Trcd_200, B6_SCAN)
472 .word MK_BANKCON_SDRAM(B7_Trcd_200, B7_SCAN)
473 .word MK_SDRAM_REFRESH(REFEN, TREFMD, Trp_200, Tsrc_200, REFCNT_200)
474 .word 0x32 + BURST_EN
479 .word MK_BANKCON_SDRAM(B6_Trcd_200, B6_SCAN)
480 .word MK_BANKCON_SDRAM(B7_Trcd_200, B7_SCAN)
481 .word MK_SDRAM_REFRESH(REFEN, TREFMD, Trp_200, Tsrc_200, REFCNT_200)
482 .word 0x32 + BURST_EN
487 .word MK_BANKCON_SDRAM(B6_Trcd_200, B6_SCAN)
488 .word MK_BANKCON_SDRAM(B7_Trcd_200, B7_SCAN)
489 .word MK_SDRAM_REFRESH(REFEN, TREFMD, Trp_200, Tsrc_200, REFCNT_200)
490 .word 0x32 + BURST_EN
495 .word MK_BANKCON_SDRAM(B6_Trcd_200, B6_SCAN)
496 .word MK_BANKCON_SDRAM(B7_Trcd_200, B7_SCAN)
497 .word MK_SDRAM_REFRESH(REFEN, TREFMD, Trp_200, Tsrc_200, REFCNT_200)
498 .word 0x32 + BURST_EN
502 .equiv SETUPDATA_SIZE, (. - SETUPDATA)