2 * Copyright (C) 2010 Albert ARIBAUD <albert.u.boot@aribaud.net>
5 * Marvell Semiconductor <www.marvell.com>
6 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28 #include "asm/arch/orion5x.h"
31 * Configuration values for SDRAM access setup
34 #define SDRAM_CONFIG 0x3148400
35 #define SDRAM_MODE 0x62
36 #define SDRAM_CONTROL 0x4041000
37 #define SDRAM_TIME_CTRL_LOW 0x11602220
38 #define SDRAM_TIME_CTRL_HI 0x40c
39 #define SDRAM_OPEN_PAGE_EN 0x0
40 /* DDR 1 2x 32M NANYA NT5DS16M16CS-6K ==> 64MB */
41 #define SDRAM_BANK0_SIZE 0x3ff0001
42 #define SDRAM_ADDR_CTRL 0x10
44 #define SDRAM_OP_NOP 0x05
45 #define SDRAM_OP_SETMODE 0x03
47 #define SDRAM_PAD_CTRL_WR_EN 0x80000000
48 #define SDRAM_PAD_CTRL_TUNE_EN 0x00010000
49 #define SDRAM_PAD_CTRL_DRVN_MASK 0x0000003f
50 #define SDRAM_PAD_CTRL_DRVP_MASK 0x00000fc0
53 * For Guideline MEM-3 - Drive Strength value
56 #define DDR1_PAD_STRENGTH_DEFAULT 0x00001000
57 #define SDRAM_PAD_CTRL_DRV_STR_MASK 0x00003000
60 * For Guideline MEM-4 - DQS Reference Delay Tuning
63 #define MSAR_ARMDDRCLCK_MASK 0x000000f0
64 #define MSAR_ARMDDRCLCK_H_MASK 0x00000100
66 #define MSAR_ARMDDRCLCK_333_167 0x00000000
67 #define MSAR_ARMDDRCLCK_500_167 0x00000030
68 #define MSAR_ARMDDRCLCK_667_167 0x00000060
69 #define MSAR_ARMDDRCLCK_400_200_1 0x000001E0
70 #define MSAR_ARMDDRCLCK_400_200 0x00000010
71 #define MSAR_ARMDDRCLCK_600_200 0x00000050
72 #define MSAR_ARMDDRCLCK_800_200 0x00000070
74 #define FTDLL_DDR1_166MHZ 0x0047F001
76 #define FTDLL_DDR1_200MHZ 0x0044D001
79 * Low-level init happens right after start.S has switched to SVC32,
80 * flushed and disabled caches and disabled MMU. We're still running
81 * from the boot chip select, so the first thing we should do is set
82 * up RAM for us to relocate into.
89 /* Use 'r4 as the base for internal register accesses */
90 ldr r4, =ORION5X_REGS_PHY_BASE
92 /* move internal registers from the default 0xD0000000
93 * to their intended location, defined by SoC */
98 /* Use R3 as the base for DRAM registers */
101 /*DDR SDRAM Initialization Control */
105 /* Use R3 as the base for PCI registers */
108 /* Disable arbiter */
112 /* Use R3 as the base for DRAM registers */
115 /* set all dram windows to 0 */
122 /* 1) Configure SDRAM */
123 ldr r6, =SDRAM_CONFIG
126 /* 2) Set SDRAM Control reg */
127 ldr r6, =SDRAM_CONTROL
130 /* 3) Write SDRAM address control register */
131 ldr r6, =SDRAM_ADDR_CTRL
134 /* 4) Write SDRAM bank 0 size register */
135 ldr r6, =SDRAM_BANK0_SIZE
137 /* keep other banks disabled */
139 /* 5) Write SDRAM open pages control register */
140 ldr r6, =SDRAM_OPEN_PAGE_EN
143 /* 6) Write SDRAM timing Low register */
144 ldr r6, =SDRAM_TIME_CTRL_LOW
147 /* 7) Write SDRAM timing High register */
148 ldr r6, =SDRAM_TIME_CTRL_HI
151 /* 8) Write SDRAM mode register */
152 /* The CPU must not attempt to change the SDRAM Mode register setting */
153 /* prior to DRAM controller completion of the DRAM initialization */
154 /* sequence. To guarantee this restriction, it is recommended that */
155 /* the CPU sets the SDRAM Operation register to NOP command, performs */
156 /* read polling until the register is back in Normal operation value, */
157 /* and then sets SDRAM Mode register to its new value. */
159 /* 8.1 write 'nop' to SDRAM operation */
160 ldr r6, =SDRAM_OP_NOP
163 /* 8.2 poll SDRAM operation until back in 'normal' mode. */
169 /* 8.3 Now its safe to write new value to SDRAM Mode register */
173 /* 8.4 Set new mode */
174 ldr r6, =SDRAM_OP_SETMODE
177 /* 8.5 poll SDRAM operation until back in 'normal' mode. */
183 /* DDR SDRAM Address/Control Pads Calibration */
186 /* Set Bit [31] to make the register writable */
187 orr r6, r6, #SDRAM_PAD_CTRL_WR_EN
190 bic r6, r6, #SDRAM_PAD_CTRL_WR_EN
191 bic r6, r6, #SDRAM_PAD_CTRL_TUNE_EN
192 bic r6, r6, #SDRAM_PAD_CTRL_DRVN_MASK
193 bic r6, r6, #SDRAM_PAD_CTRL_DRVP_MASK
195 /* Get the final N locked value of driving strength [22:17] */
198 mov r1, r1, LSR #26 /* r1[5:0]<DrvN> = r3[22:17]<LockN> */
199 orr r1, r1, r1, LSL #6 /* r1[11:6]<DrvP> = r1[5:0]<DrvN> */
201 /* Write to both <DrvN> bits [5:0] and <DrvP> bits [11:6] */
205 /* DDR SDRAM Data Pads Calibration */
208 /* Set Bit [31] to make the register writable */
209 orr r6, r6, #SDRAM_PAD_CTRL_WR_EN
212 bic r6, r6, #SDRAM_PAD_CTRL_WR_EN
213 bic r6, r6, #SDRAM_PAD_CTRL_TUNE_EN
214 bic r6, r6, #SDRAM_PAD_CTRL_DRVN_MASK
215 bic r6, r6, #SDRAM_PAD_CTRL_DRVP_MASK
217 /* Get the final N locked value of driving strength [22:17] */
221 orr r1, r1, r1, LSL #6 /* r1[5:0] = r3[22:17]<LockN> */
223 /* Write to both <DrvN> bits [5:0] and <DrvP> bits [11:6] */
228 /* Implement Guideline (GL# MEM-3) Drive Strength Value */
229 /* Relevant for: 88F5181-A1/B0/B1 and 88F5281-A0/B0 */
231 ldr r1, =DDR1_PAD_STRENGTH_DEFAULT
233 /* Enable writes to DDR SDRAM Addr/Ctrl Pads Calibration register */
235 orr r6, r6, #SDRAM_PAD_CTRL_WR_EN
238 /* Correct strength and disable writes again */
239 bic r6, r6, #SDRAM_PAD_CTRL_WR_EN
240 bic r6, r6, #SDRAM_PAD_CTRL_DRV_STR_MASK
244 /* Enable writes to DDR SDRAM Data Pads Calibration register */
246 orr r6, r6, #SDRAM_PAD_CTRL_WR_EN
249 /* Correct strength and disable writes again */
250 bic r6, r6, #SDRAM_PAD_CTRL_DRV_STR_MASK
251 bic r6, r6, #SDRAM_PAD_CTRL_WR_EN
255 /* Implement Guideline (GL# MEM-4) DQS Reference Delay Tuning */
256 /* Relevant for: 88F5181-A1/B0/B1 and 88F5281-A0/B0 */
258 /* Get the "sample on reset" register for the DDR frequancy */
261 ldr r1, =MSAR_ARMDDRCLCK_MASK
264 ldr r6, =FTDLL_DDR1_166MHZ
265 cmp r1, #MSAR_ARMDDRCLCK_333_167
267 cmp r1, #MSAR_ARMDDRCLCK_500_167
269 cmp r1, #MSAR_ARMDDRCLCK_667_167
272 ldr r6, =FTDLL_DDR1_200MHZ
273 cmp r1, #MSAR_ARMDDRCLCK_400_200_1
275 cmp r1, #MSAR_ARMDDRCLCK_400_200
277 cmp r1, #MSAR_ARMDDRCLCK_600_200
279 cmp r1, #MSAR_ARMDDRCLCK_800_200
285 /* Use R3 as the base for DRAM registers */
292 /* Return to U-boot via saved link register */