blob: 9f0413309407e3771fd3f23e7193f8f829afa563 [file] [log] [blame]
Kumar Galad5a1fb92008-08-26 21:34:55 -05001/*
York Sunb513d9d2012-08-17 08:22:36 +00002 * Copyright 2008-2012 Freescale Semiconductor, Inc.
Kumar Galad5a1fb92008-08-26 21:34:55 -05003 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * Version 2 as published by the Free Software Foundation.
7 */
8
9#include <common.h>
10#include <asm/io.h>
York Sunf0626592013-09-30 09:22:09 -070011#include <fsl_ddr_sdram.h>
York Sun7dda8472011-01-10 12:02:59 +000012#include <asm/processor.h>
Kumar Galad5a1fb92008-08-26 21:34:55 -050013
14#if (CONFIG_CHIP_SELECTS_PER_CTRL > 4)
15#error Invalid setting for CONFIG_CHIP_SELECTS_PER_CTRL
16#endif
17
York Sun5e155552013-06-25 11:37:48 -070018
19/*
20 * regs has the to-be-set values for DDR controller registers
21 * ctrl_num is the DDR controller number
22 * step: 0 goes through the initialization in one pass
23 * 1 sets registers and returns before enabling controller
24 * 2 resumes from step 1 and continues to initialize
25 * Dividing the initialization to two steps to deassert DDR reset signal
26 * to comply with JEDEC specs for RDIMMs.
27 */
Kumar Galad5a1fb92008-08-26 21:34:55 -050028void fsl_ddr_set_memctl_regs(const fsl_ddr_cfg_regs_t *regs,
York Sun5e155552013-06-25 11:37:48 -070029 unsigned int ctrl_num, int step)
Kumar Galad5a1fb92008-08-26 21:34:55 -050030{
York Sun016095d2012-10-08 07:44:24 +000031 unsigned int i, bus_width;
York Suna21803d2013-11-18 10:29:32 -080032 struct ccsr_ddr __iomem *ddr;
Poonam_Aggrwal-b1081230cb1452009-01-04 08:46:38 +053033 u32 temp_sdram_cfg;
York Sun016095d2012-10-08 07:44:24 +000034 u32 total_gb_size_per_controller;
Andy Fleming1bc8b042012-10-22 17:28:18 -050035 int timeout;
York Sunc8fc9592011-01-25 22:05:49 -080036#ifdef CONFIG_SYS_FSL_ERRATUM_DDR111_DDR134
Andy Fleming1bc8b042012-10-22 17:28:18 -050037 int timeout_save;
York Sunc8fc9592011-01-25 22:05:49 -080038 volatile ccsr_local_ecm_t *ecm = (void *)CONFIG_SYS_MPC85xx_ECM_ADDR;
York Sun7d9781b2011-03-17 11:18:13 -070039 unsigned int csn_bnds_backup = 0, cs_sa, cs_ea, *csn_bnds_t;
40 int csn = -1;
York Sunc8fc9592011-01-25 22:05:49 -080041#endif
Kumar Galad5a1fb92008-08-26 21:34:55 -050042
43 switch (ctrl_num) {
44 case 0:
York Sunf0626592013-09-30 09:22:09 -070045 ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
Kumar Galad5a1fb92008-08-26 21:34:55 -050046 break;
York Sunf0626592013-09-30 09:22:09 -070047#if defined(CONFIG_SYS_FSL_DDR2_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 1)
Kumar Galad5a1fb92008-08-26 21:34:55 -050048 case 1:
York Sunf0626592013-09-30 09:22:09 -070049 ddr = (void *)CONFIG_SYS_FSL_DDR2_ADDR;
Kumar Galad5a1fb92008-08-26 21:34:55 -050050 break;
York Sune8dc17b2012-08-17 08:22:39 +000051#endif
York Sunf0626592013-09-30 09:22:09 -070052#if defined(CONFIG_SYS_FSL_DDR3_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 2)
York Sune8dc17b2012-08-17 08:22:39 +000053 case 2:
York Sunf0626592013-09-30 09:22:09 -070054 ddr = (void *)CONFIG_SYS_FSL_DDR3_ADDR;
York Sune8dc17b2012-08-17 08:22:39 +000055 break;
56#endif
York Sunf0626592013-09-30 09:22:09 -070057#if defined(CONFIG_SYS_FSL_DDR4_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 3)
York Sune8dc17b2012-08-17 08:22:39 +000058 case 3:
York Sunf0626592013-09-30 09:22:09 -070059 ddr = (void *)CONFIG_SYS_FSL_DDR4_ADDR;
York Sune8dc17b2012-08-17 08:22:39 +000060 break;
61#endif
Kumar Galad5a1fb92008-08-26 21:34:55 -050062 default:
63 printf("%s unexpected ctrl_num = %u\n", __FUNCTION__, ctrl_num);
64 return;
65 }
66
York Sun5e155552013-06-25 11:37:48 -070067 if (step == 2)
68 goto step2;
69
York Sun016095d2012-10-08 07:44:24 +000070 if (regs->ddr_eor)
71 out_be32(&ddr->eor, regs->ddr_eor);
York Sun7d9781b2011-03-17 11:18:13 -070072#ifdef CONFIG_SYS_FSL_ERRATUM_DDR111_DDR134
York Sunb513d9d2012-08-17 08:22:36 +000073 debug("Workaround for ERRATUM_DDR111_DDR134\n");
York Sun7d9781b2011-03-17 11:18:13 -070074 for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
75 cs_sa = (regs->cs[i].bnds >> 16) & 0xfff;
76 cs_ea = regs->cs[i].bnds & 0xfff;
77 if ((cs_sa <= 0xff) && (cs_ea >= 0xff)) {
78 csn = i;
79 csn_bnds_backup = regs->cs[i].bnds;
80 csn_bnds_t = (unsigned int *) &regs->cs[i].bnds;
York Sun4b736b82012-05-21 08:43:11 +000081 if (cs_ea > 0xeff)
82 *csn_bnds_t = regs->cs[i].bnds + 0x01000000;
83 else
84 *csn_bnds_t = regs->cs[i].bnds + 0x01000100;
York Sun7d9781b2011-03-17 11:18:13 -070085 debug("Found cs%d_bns (0x%08x) covering 0xff000000, "
86 "change it to 0x%x\n",
87 csn, csn_bnds_backup, regs->cs[i].bnds);
88 break;
89 }
90 }
91#endif
Kumar Galad5a1fb92008-08-26 21:34:55 -050092 for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
93 if (i == 0) {
94 out_be32(&ddr->cs0_bnds, regs->cs[i].bnds);
95 out_be32(&ddr->cs0_config, regs->cs[i].config);
96 out_be32(&ddr->cs0_config_2, regs->cs[i].config_2);
97
98 } else if (i == 1) {
99 out_be32(&ddr->cs1_bnds, regs->cs[i].bnds);
100 out_be32(&ddr->cs1_config, regs->cs[i].config);
101 out_be32(&ddr->cs1_config_2, regs->cs[i].config_2);
102
103 } else if (i == 2) {
104 out_be32(&ddr->cs2_bnds, regs->cs[i].bnds);
105 out_be32(&ddr->cs2_config, regs->cs[i].config);
106 out_be32(&ddr->cs2_config_2, regs->cs[i].config_2);
107
108 } else if (i == 3) {
109 out_be32(&ddr->cs3_bnds, regs->cs[i].bnds);
110 out_be32(&ddr->cs3_config, regs->cs[i].config);
111 out_be32(&ddr->cs3_config_2, regs->cs[i].config_2);
112 }
113 }
114
115 out_be32(&ddr->timing_cfg_3, regs->timing_cfg_3);
116 out_be32(&ddr->timing_cfg_0, regs->timing_cfg_0);
117 out_be32(&ddr->timing_cfg_1, regs->timing_cfg_1);
118 out_be32(&ddr->timing_cfg_2, regs->timing_cfg_2);
119 out_be32(&ddr->sdram_cfg_2, regs->ddr_sdram_cfg_2);
120 out_be32(&ddr->sdram_mode, regs->ddr_sdram_mode);
121 out_be32(&ddr->sdram_mode_2, regs->ddr_sdram_mode_2);
York Sunba0c2eb2011-01-10 12:03:00 +0000122 out_be32(&ddr->sdram_mode_3, regs->ddr_sdram_mode_3);
123 out_be32(&ddr->sdram_mode_4, regs->ddr_sdram_mode_4);
124 out_be32(&ddr->sdram_mode_5, regs->ddr_sdram_mode_5);
125 out_be32(&ddr->sdram_mode_6, regs->ddr_sdram_mode_6);
126 out_be32(&ddr->sdram_mode_7, regs->ddr_sdram_mode_7);
127 out_be32(&ddr->sdram_mode_8, regs->ddr_sdram_mode_8);
Kumar Galad5a1fb92008-08-26 21:34:55 -0500128 out_be32(&ddr->sdram_md_cntl, regs->ddr_sdram_md_cntl);
129 out_be32(&ddr->sdram_interval, regs->ddr_sdram_interval);
130 out_be32(&ddr->sdram_data_init, regs->ddr_data_init);
131 out_be32(&ddr->sdram_clk_cntl, regs->ddr_sdram_clk_cntl);
132 out_be32(&ddr->init_addr, regs->ddr_init_addr);
133 out_be32(&ddr->init_ext_addr, regs->ddr_init_ext_addr);
134
135 out_be32(&ddr->timing_cfg_4, regs->timing_cfg_4);
136 out_be32(&ddr->timing_cfg_5, regs->timing_cfg_5);
137 out_be32(&ddr->ddr_zq_cntl, regs->ddr_zq_cntl);
138 out_be32(&ddr->ddr_wrlvl_cntl, regs->ddr_wrlvl_cntl);
York Sun972cc402013-06-25 11:37:41 -0700139#ifndef CONFIG_SYS_FSL_DDR_EMU
140 /*
141 * Skip these two registers if running on emulator
142 * because emulator doesn't have skew between bytes.
143 */
144
York Sun7d69ea32012-10-08 07:44:22 +0000145 if (regs->ddr_wrlvl_cntl_2)
146 out_be32(&ddr->ddr_wrlvl_cntl_2, regs->ddr_wrlvl_cntl_2);
147 if (regs->ddr_wrlvl_cntl_3)
148 out_be32(&ddr->ddr_wrlvl_cntl_3, regs->ddr_wrlvl_cntl_3);
York Sun972cc402013-06-25 11:37:41 -0700149#endif
York Sun7d69ea32012-10-08 07:44:22 +0000150
Kumar Galad5a1fb92008-08-26 21:34:55 -0500151 out_be32(&ddr->ddr_sr_cntr, regs->ddr_sr_cntr);
152 out_be32(&ddr->ddr_sdram_rcw_1, regs->ddr_sdram_rcw_1);
153 out_be32(&ddr->ddr_sdram_rcw_2, regs->ddr_sdram_rcw_2);
York Sun7dda8472011-01-10 12:02:59 +0000154 out_be32(&ddr->ddr_cdr1, regs->ddr_cdr1);
155 out_be32(&ddr->ddr_cdr2, regs->ddr_cdr2);
156 out_be32(&ddr->err_disable, regs->err_disable);
157 out_be32(&ddr->err_int_en, regs->err_int_en);
York Sunb513d9d2012-08-17 08:22:36 +0000158 for (i = 0; i < 32; i++) {
159 if (regs->debug[i]) {
160 debug("Write to debug_%d as %08x\n", i+1, regs->debug[i]);
161 out_be32(&ddr->debug[i], regs->debug[i]);
162 }
163 }
York Sun6995a022012-10-08 07:44:26 +0000164#ifdef CONFIG_SYS_FSL_ERRATUM_A_004934
York Suna2e8e0a2013-03-25 07:39:34 +0000165 out_be32(&ddr->debug[28], 0x30003000);
York Sun6995a022012-10-08 07:44:26 +0000166#endif
Kumar Galad5a1fb92008-08-26 21:34:55 -0500167
York Sundf2be192011-11-20 10:01:35 -0800168#ifdef CONFIG_SYS_FSL_ERRATUM_DDR_A003474
169 out_be32(&ddr->debug[12], 0x00000015);
170 out_be32(&ddr->debug[21], 0x24000000);
171#endif /* CONFIG_SYS_FSL_ERRATUM_DDR_A003474 */
172
York Sun5e155552013-06-25 11:37:48 -0700173 /*
174 * For RDIMMs, JEDEC spec requires clocks to be stable before reset is
175 * deasserted. Clocks start when any chip select is enabled and clock
176 * control register is set. Because all DDR components are connected to
177 * one reset signal, this needs to be done in two steps. Step 1 is to
178 * get the clocks started. Step 2 resumes after reset signal is
179 * deasserted.
180 */
181 if (step == 1) {
182 udelay(200);
183 return;
184 }
185
186step2:
Ed Swarthoute674b832009-02-24 02:37:59 -0600187 /* Set, but do not enable the memory */
188 temp_sdram_cfg = regs->ddr_sdram_cfg;
Poonam_Aggrwal-b1081230cb1452009-01-04 08:46:38 +0530189 temp_sdram_cfg &= ~(SDRAM_CFG_MEM_EN);
190 out_be32(&ddr->sdram_cfg, temp_sdram_cfg);
York Sun922f40f2011-01-10 12:03:01 +0000191#ifdef CONFIG_SYS_FSL_ERRATUM_DDR_A003
York Sunb513d9d2012-08-17 08:22:36 +0000192 debug("Workaround for ERRATUM_DDR_A003\n");
York Sun922f40f2011-01-10 12:03:01 +0000193 if (regs->ddr_sdram_rcw_2 & 0x00f00000) {
194 out_be32(&ddr->timing_cfg_2, regs->timing_cfg_2 & 0xf07fffff);
195 out_be32(&ddr->debug[2], 0x00000400);
196 out_be32(&ddr->ddr_zq_cntl, regs->ddr_zq_cntl & 0x7fffffff);
197 out_be32(&ddr->ddr_wrlvl_cntl, regs->ddr_wrlvl_cntl & 0x7fffffff);
198 out_be32(&ddr->sdram_cfg_2, regs->ddr_sdram_cfg_2 & 0xffffffeb);
199 out_be32(&ddr->mtcr, 0);
200 out_be32(&ddr->debug[12], 0x00000015);
201 out_be32(&ddr->debug[21], 0x24000000);
202 out_be32(&ddr->sdram_interval, regs->ddr_sdram_interval & 0xffff);
203 out_be32(&ddr->sdram_cfg, temp_sdram_cfg | SDRAM_CFG_BI | SDRAM_CFG_MEM_EN);
204
205 asm volatile("sync;isync");
206 while (!(in_be32(&ddr->debug[1]) & 0x2))
207 ;
208
209 switch (regs->ddr_sdram_rcw_2 & 0x00f00000) {
210 case 0x00000000:
211 out_be32(&ddr->sdram_md_cntl,
212 MD_CNTL_MD_EN |
213 MD_CNTL_CS_SEL_CS0_CS1 |
214 0x04000000 |
215 MD_CNTL_WRCW |
216 MD_CNTL_MD_VALUE(0x02));
217 break;
218 case 0x00100000:
219 out_be32(&ddr->sdram_md_cntl,
220 MD_CNTL_MD_EN |
221 MD_CNTL_CS_SEL_CS0_CS1 |
222 0x04000000 |
223 MD_CNTL_WRCW |
224 MD_CNTL_MD_VALUE(0x0a));
225 break;
226 case 0x00200000:
227 out_be32(&ddr->sdram_md_cntl,
228 MD_CNTL_MD_EN |
229 MD_CNTL_CS_SEL_CS0_CS1 |
230 0x04000000 |
231 MD_CNTL_WRCW |
232 MD_CNTL_MD_VALUE(0x12));
233 break;
234 case 0x00300000:
235 out_be32(&ddr->sdram_md_cntl,
236 MD_CNTL_MD_EN |
237 MD_CNTL_CS_SEL_CS0_CS1 |
238 0x04000000 |
239 MD_CNTL_WRCW |
240 MD_CNTL_MD_VALUE(0x1a));
241 break;
242 default:
243 out_be32(&ddr->sdram_md_cntl,
244 MD_CNTL_MD_EN |
245 MD_CNTL_CS_SEL_CS0_CS1 |
246 0x04000000 |
247 MD_CNTL_WRCW |
248 MD_CNTL_MD_VALUE(0x02));
249 printf("Unsupported RC10\n");
250 break;
251 }
252
253 while (in_be32(&ddr->sdram_md_cntl) & 0x80000000)
254 ;
255 udelay(6);
256 out_be32(&ddr->sdram_cfg, temp_sdram_cfg);
257 out_be32(&ddr->timing_cfg_2, regs->timing_cfg_2);
258 out_be32(&ddr->debug[2], 0x0);
259 out_be32(&ddr->ddr_zq_cntl, regs->ddr_zq_cntl);
260 out_be32(&ddr->ddr_wrlvl_cntl, regs->ddr_wrlvl_cntl);
261 out_be32(&ddr->sdram_cfg_2, regs->ddr_sdram_cfg_2);
262 out_be32(&ddr->debug[12], 0x0);
263 out_be32(&ddr->debug[21], 0x0);
264 out_be32(&ddr->sdram_interval, regs->ddr_sdram_interval);
265
266 }
267#endif
Kumar Galad5a1fb92008-08-26 21:34:55 -0500268 /*
Dave Liu7dc79f72008-10-23 21:18:53 +0800269 * For 8572 DDR1 erratum - DDR controller may enter illegal state
270 * when operatiing in 32-bit bus mode with 4-beat bursts,
271 * This erratum does not affect DDR3 mode, only for DDR2 mode.
Kumar Galad5a1fb92008-08-26 21:34:55 -0500272 */
York Sun9aa857b2011-01-25 21:51:27 -0800273#ifdef CONFIG_SYS_FSL_ERRATUM_DDR_115
York Sunb513d9d2012-08-17 08:22:36 +0000274 debug("Workaround for ERRATUM_DDR_115\n");
Kumar Galad5a1fb92008-08-26 21:34:55 -0500275 if ((((in_be32(&ddr->sdram_cfg) >> 24) & 0x7) == SDRAM_TYPE_DDR2)
Dave Liu7dc79f72008-10-23 21:18:53 +0800276 && in_be32(&ddr->sdram_cfg) & 0x80000) {
Kumar Galad5a1fb92008-08-26 21:34:55 -0500277 /* set DEBUG_1[31] */
York Sun7dda8472011-01-10 12:02:59 +0000278 setbits_be32(&ddr->debug[0], 1);
Kumar Galad5a1fb92008-08-26 21:34:55 -0500279 }
Dave Liu7dc79f72008-10-23 21:18:53 +0800280#endif
York Sunc8fc9592011-01-25 22:05:49 -0800281#ifdef CONFIG_SYS_FSL_ERRATUM_DDR111_DDR134
York Sunb513d9d2012-08-17 08:22:36 +0000282 debug("Workaround for ERRATUM_DDR111_DDR134\n");
York Sunc8fc9592011-01-25 22:05:49 -0800283 /*
284 * This is the combined workaround for DDR111 and DDR134
285 * following the published errata for MPC8572
286 */
287
288 /* 1. Set EEBACR[3] */
289 setbits_be32(&ecm->eebacr, 0x10000000);
290 debug("Setting EEBACR[3] to 0x%08x\n", in_be32(&ecm->eebacr));
291
292 /* 2. Set DINIT in SDRAM_CFG_2*/
293 setbits_be32(&ddr->sdram_cfg_2, SDRAM_CFG2_D_INIT);
294 debug("Setting sdram_cfg_2[D_INIT] to 0x%08x\n",
295 in_be32(&ddr->sdram_cfg_2));
296
297 /* 3. Set DEBUG_3[21] */
298 setbits_be32(&ddr->debug[2], 0x400);
299 debug("Setting DEBUG_3[21] to 0x%08x\n", in_be32(&ddr->debug[2]));
300
301#endif /* part 1 of the workaound */
Kumar Galad5a1fb92008-08-26 21:34:55 -0500302
303 /*
Dave Liu4be87b22009-03-14 12:48:30 +0800304 * 500 painful micro-seconds must elapse between
Kumar Galad5a1fb92008-08-26 21:34:55 -0500305 * the DDR clock setup and the DDR config enable.
Dave Liu4be87b22009-03-14 12:48:30 +0800306 * DDR2 need 200 us, and DDR3 need 500 us from spec,
307 * we choose the max, that is 500 us for all of case.
Kumar Galad5a1fb92008-08-26 21:34:55 -0500308 */
Dave Liu4be87b22009-03-14 12:48:30 +0800309 udelay(500);
Kumar Galad5a1fb92008-08-26 21:34:55 -0500310 asm volatile("sync;isync");
311
Poonam_Aggrwal-b1081230cb1452009-01-04 08:46:38 +0530312 /* Let the controller go */
York Sun922f40f2011-01-10 12:03:01 +0000313 temp_sdram_cfg = in_be32(&ddr->sdram_cfg) & ~SDRAM_CFG_BI;
Poonam_Aggrwal-b1081230cb1452009-01-04 08:46:38 +0530314 out_be32(&ddr->sdram_cfg, temp_sdram_cfg | SDRAM_CFG_MEM_EN);
York Sun922f40f2011-01-10 12:03:01 +0000315 asm volatile("sync;isync");
Kumar Galad5a1fb92008-08-26 21:34:55 -0500316
York Sun016095d2012-10-08 07:44:24 +0000317 total_gb_size_per_controller = 0;
318 for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
319 if (!(regs->cs[i].config & 0x80000000))
320 continue;
321 total_gb_size_per_controller += 1 << (
322 ((regs->cs[i].config >> 14) & 0x3) + 2 +
323 ((regs->cs[i].config >> 8) & 0x7) + 12 +
324 ((regs->cs[i].config >> 0) & 0x7) + 8 +
325 3 - ((regs->ddr_sdram_cfg >> 19) & 0x3) -
326 26); /* minus 26 (count of 64M) */
327 }
328 if (fsl_ddr_get_intl3r() & 0x80000000) /* 3-way interleaving */
329 total_gb_size_per_controller *= 3;
330 else if (regs->cs[0].config & 0x20000000) /* 2-way interleaving */
331 total_gb_size_per_controller <<= 1;
332 /*
333 * total memory / bus width = transactions needed
334 * transactions needed / data rate = seconds
335 * to add plenty of buffer, double the time
336 * For example, 2GB on 666MT/s 64-bit bus takes about 402ms
337 * Let's wait for 800ms
338 */
339 bus_width = 3 - ((ddr->sdram_cfg & SDRAM_CFG_DBW_MASK)
340 >> SDRAM_CFG_DBW_SHIFT);
341 timeout = ((total_gb_size_per_controller << (6 - bus_width)) * 100 /
342 (get_ddr_freq(0) >> 20)) << 1;
Andy Fleming1bc8b042012-10-22 17:28:18 -0500343#ifdef CONFIG_SYS_FSL_ERRATUM_DDR111_DDR134
York Sun016095d2012-10-08 07:44:24 +0000344 timeout_save = timeout;
Andy Fleming1bc8b042012-10-22 17:28:18 -0500345#endif
York Sun016095d2012-10-08 07:44:24 +0000346 total_gb_size_per_controller >>= 4; /* shift down to gb size */
347 debug("total %d GB\n", total_gb_size_per_controller);
348 debug("Need to wait up to %d * 10ms\n", timeout);
349
Kumar Galad5a1fb92008-08-26 21:34:55 -0500350 /* Poll DDR_SDRAM_CFG_2[D_INIT] bit until auto-data init is done. */
York Sun016095d2012-10-08 07:44:24 +0000351 while ((in_be32(&ddr->sdram_cfg_2) & SDRAM_CFG2_D_INIT) &&
352 (timeout >= 0)) {
Kumar Galad5a1fb92008-08-26 21:34:55 -0500353 udelay(10000); /* throttle polling rate */
York Sun016095d2012-10-08 07:44:24 +0000354 timeout--;
355 }
356
357 if (timeout <= 0)
358 printf("Waiting for D_INIT timeout. Memory may not work.\n");
York Sunc8fc9592011-01-25 22:05:49 -0800359
360#ifdef CONFIG_SYS_FSL_ERRATUM_DDR111_DDR134
361 /* continue this workaround */
362
363 /* 4. Clear DEBUG3[21] */
364 clrbits_be32(&ddr->debug[2], 0x400);
365 debug("Clearing D3[21] to 0x%08x\n", in_be32(&ddr->debug[2]));
366
367 /* DDR134 workaround starts */
368 /* A: Clear sdram_cfg_2[odt_cfg] */
369 clrbits_be32(&ddr->sdram_cfg_2, SDRAM_CFG2_ODT_CFG_MASK);
370 debug("Clearing SDRAM_CFG2[ODT_CFG] to 0x%08x\n",
371 in_be32(&ddr->sdram_cfg_2));
372
373 /* B: Set DEBUG1[15] */
374 setbits_be32(&ddr->debug[0], 0x10000);
375 debug("Setting D1[15] to 0x%08x\n", in_be32(&ddr->debug[0]));
376
377 /* C: Set timing_cfg_2[cpo] to 0b11111 */
378 setbits_be32(&ddr->timing_cfg_2, TIMING_CFG_2_CPO_MASK);
379 debug("Setting TMING_CFG_2[CPO] to 0x%08x\n",
380 in_be32(&ddr->timing_cfg_2));
381
382 /* D: Set D6 to 0x9f9f9f9f */
383 out_be32(&ddr->debug[5], 0x9f9f9f9f);
384 debug("Setting D6 to 0x%08x\n", in_be32(&ddr->debug[5]));
385
386 /* E: Set D7 to 0x9f9f9f9f */
387 out_be32(&ddr->debug[6], 0x9f9f9f9f);
388 debug("Setting D7 to 0x%08x\n", in_be32(&ddr->debug[6]));
389
390 /* F: Set D2[20] */
391 setbits_be32(&ddr->debug[1], 0x800);
392 debug("Setting D2[20] to 0x%08x\n", in_be32(&ddr->debug[1]));
393
394 /* G: Poll on D2[20] until cleared */
395 while (in_be32(&ddr->debug[1]) & 0x800)
396 udelay(10000); /* throttle polling rate */
397
398 /* H: Clear D1[15] */
399 clrbits_be32(&ddr->debug[0], 0x10000);
400 debug("Setting D1[15] to 0x%08x\n", in_be32(&ddr->debug[0]));
401
402 /* I: Set sdram_cfg_2[odt_cfg] */
403 setbits_be32(&ddr->sdram_cfg_2,
404 regs->ddr_sdram_cfg_2 & SDRAM_CFG2_ODT_CFG_MASK);
405 debug("Setting sdram_cfg_2 to 0x%08x\n", in_be32(&ddr->sdram_cfg_2));
406
407 /* Continuing with the DDR111 workaround */
408 /* 5. Set D2[21] */
409 setbits_be32(&ddr->debug[1], 0x400);
410 debug("Setting D2[21] to 0x%08x\n", in_be32(&ddr->debug[1]));
411
412 /* 6. Poll D2[21] until its cleared */
413 while (in_be32(&ddr->debug[1]) & 0x400)
414 udelay(10000); /* throttle polling rate */
415
York Sun016095d2012-10-08 07:44:24 +0000416 /* 7. Wait for state machine 2nd run, roughly 400ms/GB */
417 debug("Wait for %d * 10ms\n", timeout_save);
418 udelay(timeout_save * 10000);
York Sunc8fc9592011-01-25 22:05:49 -0800419
420 /* 8. Set sdram_cfg_2[dinit] if options requires */
421 setbits_be32(&ddr->sdram_cfg_2,
422 regs->ddr_sdram_cfg_2 & SDRAM_CFG2_D_INIT);
423 debug("Setting sdram_cfg_2 to 0x%08x\n", in_be32(&ddr->sdram_cfg_2));
424
425 /* 9. Poll until dinit is cleared */
York Sun016095d2012-10-08 07:44:24 +0000426 timeout = timeout_save;
427 debug("Need to wait up to %d * 10ms\n", timeout);
428 while ((in_be32(&ddr->sdram_cfg_2) & SDRAM_CFG2_D_INIT) &&
429 (timeout >= 0)) {
430 udelay(10000); /* throttle polling rate */
431 timeout--;
432 }
433
434 if (timeout <= 0)
435 printf("Waiting for D_INIT timeout. Memory may not work.\n");
York Sunc8fc9592011-01-25 22:05:49 -0800436
437 /* 10. Clear EEBACR[3] */
438 clrbits_be32(&ecm->eebacr, 10000000);
439 debug("Clearing EEBACR[3] to 0x%08x\n", in_be32(&ecm->eebacr));
York Sun7d9781b2011-03-17 11:18:13 -0700440
441 if (csn != -1) {
442 csn_bnds_t = (unsigned int *) &regs->cs[csn].bnds;
443 *csn_bnds_t = csn_bnds_backup;
444 debug("Change cs%d_bnds back to 0x%08x\n",
445 csn, regs->cs[csn].bnds);
446 setbits_be32(&ddr->sdram_cfg, 0x2); /* MEM_HALT */
447 switch (csn) {
448 case 0:
449 out_be32(&ddr->cs0_bnds, regs->cs[csn].bnds);
450 break;
451 case 1:
452 out_be32(&ddr->cs1_bnds, regs->cs[csn].bnds);
453 break;
454 case 2:
455 out_be32(&ddr->cs2_bnds, regs->cs[csn].bnds);
456 break;
457 case 3:
458 out_be32(&ddr->cs3_bnds, regs->cs[csn].bnds);
459 break;
460 }
461 clrbits_be32(&ddr->sdram_cfg, 0x2);
462 }
York Sunc8fc9592011-01-25 22:05:49 -0800463#endif /* CONFIG_SYS_FSL_ERRATUM_DDR111_DDR134 */
Kumar Galad5a1fb92008-08-26 21:34:55 -0500464}