blob: 358d2a49fbb469a58090e3562e8eb19a5f8eaa2d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Albert Aribaudac2ba9e2010-06-17 19:36:07 +05302/*
Albert ARIBAUD340983d2011-04-22 19:41:02 +02003 * Copyright (C) 2010 Albert ARIBAUD <albert.u.boot@aribaud.net>
Albert Aribaudac2ba9e2010-06-17 19:36:07 +05304 *
5 * (C) Copyright 2009
6 * Marvell Semiconductor <www.marvell.com>
7 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
Albert Aribaudac2ba9e2010-06-17 19:36:07 +05308 */
9
10#include <config.h>
11#include "asm/arch/orion5x.h"
12
13/*
14 * Configuration values for SDRAM access setup
15 */
16
17#define SDRAM_CONFIG 0x3148400
18#define SDRAM_MODE 0x62
19#define SDRAM_CONTROL 0x4041000
20#define SDRAM_TIME_CTRL_LOW 0x11602220
21#define SDRAM_TIME_CTRL_HI 0x40c
22#define SDRAM_OPEN_PAGE_EN 0x0
23/* DDR 1 2x 32M NANYA NT5DS16M16CS-6K ==> 64MB */
24#define SDRAM_BANK0_SIZE 0x3ff0001
25#define SDRAM_ADDR_CTRL 0x10
26
27#define SDRAM_OP_NOP 0x05
28#define SDRAM_OP_SETMODE 0x03
29
30#define SDRAM_PAD_CTRL_WR_EN 0x80000000
31#define SDRAM_PAD_CTRL_TUNE_EN 0x00010000
32#define SDRAM_PAD_CTRL_DRVN_MASK 0x0000003f
33#define SDRAM_PAD_CTRL_DRVP_MASK 0x00000fc0
34
35/*
36 * For Guideline MEM-3 - Drive Strength value
37 */
38
39#define DDR1_PAD_STRENGTH_DEFAULT 0x00001000
40#define SDRAM_PAD_CTRL_DRV_STR_MASK 0x00003000
41
42/*
43 * For Guideline MEM-4 - DQS Reference Delay Tuning
44 */
45
46#define MSAR_ARMDDRCLCK_MASK 0x000000f0
47#define MSAR_ARMDDRCLCK_H_MASK 0x00000100
48
49#define MSAR_ARMDDRCLCK_333_167 0x00000000
50#define MSAR_ARMDDRCLCK_500_167 0x00000030
51#define MSAR_ARMDDRCLCK_667_167 0x00000060
52#define MSAR_ARMDDRCLCK_400_200_1 0x000001E0
53#define MSAR_ARMDDRCLCK_400_200 0x00000010
54#define MSAR_ARMDDRCLCK_600_200 0x00000050
55#define MSAR_ARMDDRCLCK_800_200 0x00000070
56
57#define FTDLL_DDR1_166MHZ 0x0047F001
58
59#define FTDLL_DDR1_200MHZ 0x0044D001
60
61/*
62 * Low-level init happens right after start.S has switched to SVC32,
63 * flushed and disabled caches and disabled MMU. We're still running
Albert ARIBAUD2ac37922015-01-31 22:55:38 +010064 * from the boot chip select, so the first thing SPL should do is to
65 * set up the RAM to copy U-Boot into.
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053066 */
67
68.globl lowlevel_init
69
70lowlevel_init:
71
Simon Glass85ed77d2024-09-29 19:49:46 -060072#ifdef CONFIG_XPL_BUILD
Albert ARIBAUD2ac37922015-01-31 22:55:38 +010073
Mans Rullgard74493aa2018-05-07 11:10:47 +010074 /* Use 'r2 as the base for internal register accesses */
75 ldr r2, =ORION5X_REGS_PHY_BASE
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053076
77 /* move internal registers from the default 0xD0000000
78 * to their intended location, defined by SoC */
79 ldr r3, =0xD0000000
80 add r3, r3, #0x20000
Mans Rullgard74493aa2018-05-07 11:10:47 +010081 str r2, [r3, #0x80]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053082
83 /* Use R3 as the base for DRAM registers */
Mans Rullgard74493aa2018-05-07 11:10:47 +010084 add r3, r2, #0x01000
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053085
86 /*DDR SDRAM Initialization Control */
Mans Rullgard74493aa2018-05-07 11:10:47 +010087 ldr r0, =0x00000001
88 str r0, [r3, #0x480]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053089
90 /* Use R3 as the base for PCI registers */
Mans Rullgard74493aa2018-05-07 11:10:47 +010091 add r3, r2, #0x31000
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053092
93 /* Disable arbiter */
Mans Rullgard74493aa2018-05-07 11:10:47 +010094 ldr r0, =0x00000030
95 str r0, [r3, #0xd00]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053096
97 /* Use R3 as the base for DRAM registers */
Mans Rullgard74493aa2018-05-07 11:10:47 +010098 add r3, r2, #0x01000
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053099
100 /* set all dram windows to 0 */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100101 mov r0, #0
102 str r0, [r3, #0x504]
103 str r0, [r3, #0x50C]
104 str r0, [r3, #0x514]
105 str r0, [r3, #0x51C]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530106
107 /* 1) Configure SDRAM */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100108 ldr r0, =SDRAM_CONFIG
109 str r0, [r3, #0x400]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530110
111 /* 2) Set SDRAM Control reg */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100112 ldr r0, =SDRAM_CONTROL
113 str r0, [r3, #0x404]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530114
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200115 /* 3) Write SDRAM address control register */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100116 ldr r0, =SDRAM_ADDR_CTRL
117 str r0, [r3, #0x410]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530118
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200119 /* 4) Write SDRAM bank 0 size register */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100120 ldr r0, =SDRAM_BANK0_SIZE
121 str r0, [r3, #0x504]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530122 /* keep other banks disabled */
123
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200124 /* 5) Write SDRAM open pages control register */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100125 ldr r0, =SDRAM_OPEN_PAGE_EN
126 str r0, [r3, #0x414]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530127
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200128 /* 6) Write SDRAM timing Low register */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100129 ldr r0, =SDRAM_TIME_CTRL_LOW
130 str r0, [r3, #0x408]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530131
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200132 /* 7) Write SDRAM timing High register */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100133 ldr r0, =SDRAM_TIME_CTRL_HI
134 str r0, [r3, #0x40C]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530135
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200136 /* 8) Write SDRAM mode register */
137 /* The CPU must not attempt to change the SDRAM Mode register setting */
138 /* prior to DRAM controller completion of the DRAM initialization */
139 /* sequence. To guarantee this restriction, it is recommended that */
140 /* the CPU sets the SDRAM Operation register to NOP command, performs */
141 /* read polling until the register is back in Normal operation value, */
142 /* and then sets SDRAM Mode register to its new value. */
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530143
144 /* 8.1 write 'nop' to SDRAM operation */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100145 ldr r0, =SDRAM_OP_NOP
146 str r0, [r3, #0x418]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530147
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200148 /* 8.2 poll SDRAM operation until back in 'normal' mode. */
Albert Aribaudac2ba9e2010-06-17 19:36:07 +05301491:
Mans Rullgard74493aa2018-05-07 11:10:47 +0100150 ldr r0, [r3, #0x418]
151 cmp r0, #0
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530152 bne 1b
153
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200154 /* 8.3 Now its safe to write new value to SDRAM Mode register */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100155 ldr r0, =SDRAM_MODE
156 str r0, [r3, #0x41C]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530157
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200158 /* 8.4 Set new mode */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100159 ldr r0, =SDRAM_OP_SETMODE
160 str r0, [r3, #0x418]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530161
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200162 /* 8.5 poll SDRAM operation until back in 'normal' mode. */
Albert Aribaudac2ba9e2010-06-17 19:36:07 +05301632:
Mans Rullgard74493aa2018-05-07 11:10:47 +0100164 ldr r0, [r3, #0x418]
165 cmp r0, #0
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530166 bne 2b
167
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200168 /* DDR SDRAM Address/Control Pads Calibration */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100169 ldr r0, [r3, #0x4C0]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530170
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200171 /* Set Bit [31] to make the register writable */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100172 orr r0, r0, #SDRAM_PAD_CTRL_WR_EN
173 str r0, [r3, #0x4C0]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530174
Mans Rullgard74493aa2018-05-07 11:10:47 +0100175 bic r0, r0, #SDRAM_PAD_CTRL_WR_EN
176 bic r0, r0, #SDRAM_PAD_CTRL_TUNE_EN
177 bic r0, r0, #SDRAM_PAD_CTRL_DRVN_MASK
178 bic r0, r0, #SDRAM_PAD_CTRL_DRVP_MASK
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530179
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200180 /* Get the final N locked value of driving strength [22:17] */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100181 mov r1, r0
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200182 mov r1, r1, LSL #9
183 mov r1, r1, LSR #26 /* r1[5:0]<DrvN> = r3[22:17]<LockN> */
184 orr r1, r1, r1, LSL #6 /* r1[11:6]<DrvP> = r1[5:0]<DrvN> */
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530185
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200186 /* Write to both <DrvN> bits [5:0] and <DrvP> bits [11:6] */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100187 orr r0, r0, r1
188 str r0, [r3, #0x4C0]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530189
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200190 /* DDR SDRAM Data Pads Calibration */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100191 ldr r0, [r3, #0x4C4]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530192
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200193 /* Set Bit [31] to make the register writable */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100194 orr r0, r0, #SDRAM_PAD_CTRL_WR_EN
195 str r0, [r3, #0x4C4]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530196
Mans Rullgard74493aa2018-05-07 11:10:47 +0100197 bic r0, r0, #SDRAM_PAD_CTRL_WR_EN
198 bic r0, r0, #SDRAM_PAD_CTRL_TUNE_EN
199 bic r0, r0, #SDRAM_PAD_CTRL_DRVN_MASK
200 bic r0, r0, #SDRAM_PAD_CTRL_DRVP_MASK
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530201
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200202 /* Get the final N locked value of driving strength [22:17] */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100203 mov r1, r0
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200204 mov r1, r1, LSL #9
205 mov r1, r1, LSR #26
206 orr r1, r1, r1, LSL #6 /* r1[5:0] = r3[22:17]<LockN> */
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530207
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200208 /* Write to both <DrvN> bits [5:0] and <DrvP> bits [11:6] */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100209 orr r0, r0, r1
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530210
Mans Rullgard74493aa2018-05-07 11:10:47 +0100211 str r0, [r3, #0x4C4]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530212
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200213 /* Implement Guideline (GL# MEM-3) Drive Strength Value */
214 /* Relevant for: 88F5181-A1/B0/B1 and 88F5281-A0/B0 */
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530215
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200216 ldr r1, =DDR1_PAD_STRENGTH_DEFAULT
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530217
218 /* Enable writes to DDR SDRAM Addr/Ctrl Pads Calibration register */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100219 ldr r0, [r3, #0x4C0]
220 orr r0, r0, #SDRAM_PAD_CTRL_WR_EN
221 str r0, [r3, #0x4C0]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530222
223 /* Correct strength and disable writes again */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100224 bic r0, r0, #SDRAM_PAD_CTRL_WR_EN
225 bic r0, r0, #SDRAM_PAD_CTRL_DRV_STR_MASK
226 orr r0, r0, r1
227 str r0, [r3, #0x4C0]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530228
229 /* Enable writes to DDR SDRAM Data Pads Calibration register */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100230 ldr r0, [r3, #0x4C4]
231 orr r0, r0, #SDRAM_PAD_CTRL_WR_EN
232 str r0, [r3, #0x4C4]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530233
234 /* Correct strength and disable writes again */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100235 bic r0, r0, #SDRAM_PAD_CTRL_DRV_STR_MASK
236 bic r0, r0, #SDRAM_PAD_CTRL_WR_EN
237 orr r0, r0, r1
238 str r0, [r3, #0x4C4]
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530239
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200240 /* Implement Guideline (GL# MEM-4) DQS Reference Delay Tuning */
241 /* Relevant for: 88F5181-A1/B0/B1 and 88F5281-A0/B0 */
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530242
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200243 /* Get the "sample on reset" register for the DDR frequancy */
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530244 ldr r3, =0x10000
Mans Rullgard74493aa2018-05-07 11:10:47 +0100245 ldr r0, [r3, #0x010]
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200246 ldr r1, =MSAR_ARMDDRCLCK_MASK
Mans Rullgard74493aa2018-05-07 11:10:47 +0100247 and r1, r0, r1
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530248
Mans Rullgard74493aa2018-05-07 11:10:47 +0100249 ldr r0, =FTDLL_DDR1_166MHZ
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200250 cmp r1, #MSAR_ARMDDRCLCK_333_167
251 beq 3f
252 cmp r1, #MSAR_ARMDDRCLCK_500_167
253 beq 3f
254 cmp r1, #MSAR_ARMDDRCLCK_667_167
255 beq 3f
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530256
Mans Rullgard74493aa2018-05-07 11:10:47 +0100257 ldr r0, =FTDLL_DDR1_200MHZ
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200258 cmp r1, #MSAR_ARMDDRCLCK_400_200_1
259 beq 3f
260 cmp r1, #MSAR_ARMDDRCLCK_400_200
261 beq 3f
262 cmp r1, #MSAR_ARMDDRCLCK_600_200
263 beq 3f
264 cmp r1, #MSAR_ARMDDRCLCK_800_200
265 beq 3f
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530266
Mans Rullgard74493aa2018-05-07 11:10:47 +0100267 ldr r0, =0
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530268
2693:
270 /* Use R3 as the base for DRAM registers */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100271 add r3, r2, #0x01000
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530272
273 ldr r2, [r3, #0x484]
Mans Rullgard74493aa2018-05-07 11:10:47 +0100274 orr r2, r2, r0
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530275 str r2, [r3, #0x484]
276
Albert ARIBAUD2ac37922015-01-31 22:55:38 +0100277 /* enable for 2 GB DDR; detection should find out real amount */
Mans Rullgard74493aa2018-05-07 11:10:47 +0100278 sub r0, r0, r0
279 str r0, [r3, #0x500]
280 ldr r0, =0x7fff0001
281 str r0, [r3, #0x504]
Albert ARIBAUD2ac37922015-01-31 22:55:38 +0100282
Simon Glass85ed77d2024-09-29 19:49:46 -0600283#endif /* CONFIG_XPL_BUILD */
Albert ARIBAUD2ac37922015-01-31 22:55:38 +0100284
Bin Meng75574052016-02-05 19:30:11 -0800285 /* Return to U-Boot via saved link register */
Wolfgang Denk9a183d22010-06-23 20:50:54 +0200286 mov pc, lr