blob: d964184ddc8d070588158591d355c29ac494fbcb [file] [log] [blame]
Jacky Baid62ddc12019-08-08 09:59:08 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2018-2019 NXP
4 */
5
6#include <common.h>
7#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Jacky Baid62ddc12019-08-08 09:59:08 +00009#include <asm/io.h>
10#include <asm/arch/ddr.h>
11#include <asm/arch/clock.h>
12#include <asm/arch/sys_proto.h>
13
Ye Lib2cfc422022-07-26 16:41:07 +080014static unsigned int g_cdd_rr_max[4];
15static unsigned int g_cdd_rw_max[4];
16static unsigned int g_cdd_wr_max[4];
17static unsigned int g_cdd_ww_max[4];
18
Jacky Baid62ddc12019-08-08 09:59:08 +000019void ddr_cfg_umctl2(struct dram_cfg_param *ddrc_cfg, int num)
20{
21 int i = 0;
22
23 for (i = 0; i < num; i++) {
24 reg32_write(ddrc_cfg->reg, ddrc_cfg->val);
25 ddrc_cfg++;
26 }
27}
28
Sherry Sun7957bd62020-01-20 11:13:14 +080029#ifdef CONFIG_IMX8M_DRAM_INLINE_ECC
30void ddrc_inline_ecc_scrub(unsigned int start_address,
31 unsigned int range_address)
32{
33 unsigned int tmp;
34
35 /* Step1: Enable quasi-dynamic programming */
36 reg32_write(DDRC_SWCTL(0), 0x00000000);
37 /* Step2: Set ECCCFG1.ecc_parity_region_lock to 1 */
38 reg32setbit(DDRC_ECCCFG1(0), 0x4);
39 /* Step3: Block the AXI ports from taking the transaction */
40 reg32_write(DDRC_PCTRL_0(0), 0x0);
41 /* Step4: Set scrub start address */
42 reg32_write(DDRC_SBRSTART0(0), start_address);
43 /* Step5: Set scrub range address */
44 reg32_write(DDRC_SBRRANGE0(0), range_address);
45 /* Step6: Set scrub_mode to write */
46 reg32_write(DDRC_SBRCTL(0), 0x00000014);
47 /* Step7: Set the desired pattern through SBRWDATA0 registers */
48 reg32_write(DDRC_SBRWDATA0(0), 0x55aa55aa);
49 /* Step8: Enable the SBR by programming SBRCTL.scrub_en=1 */
50 reg32setbit(DDRC_SBRCTL(0), 0x0);
51 /* Step9: Poll SBRSTAT.scrub_done=1 */
52 tmp = reg32_read(DDRC_SBRSTAT(0));
53 while (tmp != 0x00000002)
54 tmp = reg32_read(DDRC_SBRSTAT(0)) & 0x2;
55 /* Step10: Poll SBRSTAT.scrub_busy=0 */
56 tmp = reg32_read(DDRC_SBRSTAT(0));
57 while (tmp != 0x0)
58 tmp = reg32_read(DDRC_SBRSTAT(0)) & 0x1;
59 /* Step11: Disable SBR by programming SBRCTL.scrub_en=0 */
60 clrbits_le32(DDRC_SBRCTL(0), 0x1);
61 /* Step12: Prepare for normal scrub operation(Read) and set scrub_interval*/
62 reg32_write(DDRC_SBRCTL(0), 0x100);
63 /* Step13: Enable the SBR by programming SBRCTL.scrub_en=1 */
64 reg32_write(DDRC_SBRCTL(0), 0x101);
65 /* Step14: Enable AXI ports by programming */
66 reg32_write(DDRC_PCTRL_0(0), 0x1);
67 /* Step15: Disable quasi-dynamic programming */
68 reg32_write(DDRC_SWCTL(0), 0x00000001);
69}
70
71void ddrc_inline_ecc_scrub_end(unsigned int start_address,
72 unsigned int range_address)
73{
74 /* Step1: Enable quasi-dynamic programming */
75 reg32_write(DDRC_SWCTL(0), 0x00000000);
76 /* Step2: Block the AXI ports from taking the transaction */
77 reg32_write(DDRC_PCTRL_0(0), 0x0);
78 /* Step3: Set scrub start address */
79 reg32_write(DDRC_SBRSTART0(0), start_address);
80 /* Step4: Set scrub range address */
81 reg32_write(DDRC_SBRRANGE0(0), range_address);
82 /* Step5: Disable SBR by programming SBRCTL.scrub_en=0 */
83 clrbits_le32(DDRC_SBRCTL(0), 0x1);
84 /* Step6: Prepare for normal scrub operation(Read) and set scrub_interval */
85 reg32_write(DDRC_SBRCTL(0), 0x100);
86 /* Step7: Enable the SBR by programming SBRCTL.scrub_en=1 */
87 reg32_write(DDRC_SBRCTL(0), 0x101);
88 /* Step8: Enable AXI ports by programming */
89 reg32_write(DDRC_PCTRL_0(0), 0x1);
90 /* Step9: Disable quasi-dynamic programming */
91 reg32_write(DDRC_SWCTL(0), 0x00000001);
92}
93#endif
94
95void __weak board_dram_ecc_scrub(void)
96{
Ye Lib2cfc422022-07-26 16:41:07 +080097}
98
99void lpddr4_mr_write(unsigned int mr_rank, unsigned int mr_addr,
100 unsigned int mr_data)
101{
102 unsigned int tmp;
103 /*
104 * 1. Poll MRSTAT.mr_wr_busy until it is 0.
105 * This checks that there is no outstanding MR transaction.
106 * No writes should be performed to MRCTRL0 and MRCTRL1 if
107 * MRSTAT.mr_wr_busy = 1.
108 */
109 do {
110 tmp = reg32_read(DDRC_MRSTAT(0));
111 } while (tmp & 0x1);
112 /*
113 * 2. Write the MRCTRL0.mr_type, MRCTRL0.mr_addr, MRCTRL0.mr_rank and
114 * (for MRWs) MRCTRL1.mr_data to define the MR transaction.
115 */
116 reg32_write(DDRC_MRCTRL0(0), (mr_rank << 4));
117 reg32_write(DDRC_MRCTRL1(0), (mr_addr << 8) | mr_data);
118 reg32setbit(DDRC_MRCTRL0(0), 31);
119}
120
121unsigned int lpddr4_mr_read(unsigned int mr_rank, unsigned int mr_addr)
122{
123 unsigned int tmp;
124
125 reg32_write(DRC_PERF_MON_MRR0_DAT(0), 0x1);
126 do {
127 tmp = reg32_read(DDRC_MRSTAT(0));
128 } while (tmp & 0x1);
129
130 reg32_write(DDRC_MRCTRL0(0), (mr_rank << 4) | 0x1);
131 reg32_write(DDRC_MRCTRL1(0), (mr_addr << 8));
132 reg32setbit(DDRC_MRCTRL0(0), 31);
133 do {
134 tmp = reg32_read(DRC_PERF_MON_MRR0_DAT(0));
135 } while ((tmp & 0x8) == 0);
136 tmp = reg32_read(DRC_PERF_MON_MRR1_DAT(0));
137 tmp = tmp & 0xff;
138 reg32_write(DRC_PERF_MON_MRR0_DAT(0), 0x4);
139
140 return tmp;
141}
142
143static unsigned int look_for_max(unsigned int data[], unsigned int addr_start,
144 unsigned int addr_end)
145{
146 unsigned int i, imax = 0;
147
148 for (i = addr_start; i <= addr_end; i++) {
149 if (((data[i] >> 7) == 0) && data[i] > imax)
150 imax = data[i];
151 }
152
153 return imax;
Sherry Sun7957bd62020-01-20 11:13:14 +0800154}
155
Ye Lib2cfc422022-07-26 16:41:07 +0800156void get_trained_CDD(u32 fsp)
157{
158 unsigned int i, ddr_type, tmp;
159 unsigned int cdd_cha[12], cdd_chb[12];
160 unsigned int cdd_cha_rr_max, cdd_cha_rw_max, cdd_cha_wr_max, cdd_cha_ww_max;
161 unsigned int cdd_chb_rr_max, cdd_chb_rw_max, cdd_chb_wr_max, cdd_chb_ww_max;
162
163 ddr_type = reg32_read(DDRC_MSTR(0)) & 0x3f;
164 if (ddr_type == 0x20) {
165 for (i = 0; i < 6; i++) {
166 tmp = reg32_read(IP2APB_DDRPHY_IPS_BASE_ADDR(0) + (0x54013 + i) * 4);
167 cdd_cha[i * 2] = tmp & 0xff;
168 cdd_cha[i * 2 + 1] = (tmp >> 8) & 0xff;
169 }
170
171 for (i = 0; i < 7; i++) {
172 tmp = reg32_read(IP2APB_DDRPHY_IPS_BASE_ADDR(0) + (0x5402c + i) * 4);
173 if (i == 0) {
174 cdd_cha[0] = (tmp >> 8) & 0xff;
175 } else if (i == 6) {
176 cdd_cha[11] = tmp & 0xff;
177 } else {
178 cdd_chb[i * 2 - 1] = tmp & 0xff;
179 cdd_chb[i * 2] = (tmp >> 8) & 0xff;
180 }
181 }
182
183 cdd_cha_rr_max = look_for_max(cdd_cha, 0, 1);
184 cdd_cha_rw_max = look_for_max(cdd_cha, 2, 5);
185 cdd_cha_wr_max = look_for_max(cdd_cha, 6, 9);
186 cdd_cha_ww_max = look_for_max(cdd_cha, 10, 11);
187 cdd_chb_rr_max = look_for_max(cdd_chb, 0, 1);
188 cdd_chb_rw_max = look_for_max(cdd_chb, 2, 5);
189 cdd_chb_wr_max = look_for_max(cdd_chb, 6, 9);
190 cdd_chb_ww_max = look_for_max(cdd_chb, 10, 11);
191 g_cdd_rr_max[fsp] =
192 cdd_cha_rr_max > cdd_chb_rr_max ? cdd_cha_rr_max : cdd_chb_rr_max;
193 g_cdd_rw_max[fsp] =
194 cdd_cha_rw_max > cdd_chb_rw_max ? cdd_cha_rw_max : cdd_chb_rw_max;
195 g_cdd_wr_max[fsp] =
196 cdd_cha_wr_max > cdd_chb_wr_max ? cdd_cha_wr_max : cdd_chb_wr_max;
197 g_cdd_ww_max[fsp] =
198 cdd_cha_ww_max > cdd_chb_ww_max ? cdd_cha_ww_max : cdd_chb_ww_max;
199 } else {
200 unsigned int ddr4_cdd[64];
201
202 for (i = 0; i < 29; i++) {
203 tmp = reg32_read(IP2APB_DDRPHY_IPS_BASE_ADDR(0) + (0x54012 + i) * 4);
204 ddr4_cdd[i * 2] = tmp & 0xff;
205 ddr4_cdd[i * 2 + 1] = (tmp >> 8) & 0xff;
206 }
207
208 g_cdd_rr_max[fsp] = look_for_max(ddr4_cdd, 1, 12);
209 g_cdd_ww_max[fsp] = look_for_max(ddr4_cdd, 13, 24);
210 g_cdd_rw_max[fsp] = look_for_max(ddr4_cdd, 25, 40);
211 g_cdd_wr_max[fsp] = look_for_max(ddr4_cdd, 41, 56);
212 }
213}
214
215void update_umctl2_rank_space_setting(unsigned int pstat_num)
216{
217 unsigned int i, ddr_type;
218 unsigned int addr_slot, rdata, tmp, tmp_t;
219 unsigned int ddrc_w2r, ddrc_r2w, ddrc_wr_gap, ddrc_rd_gap;
220
221 ddr_type = reg32_read(DDRC_MSTR(0)) & 0x3f;
222 for (i = 0; i < pstat_num; i++) {
223 addr_slot = i ? (i + 1) * 0x1000 : 0;
224 if (ddr_type == 0x20) {
225 /* update r2w:[13:8], w2r:[5:0] */
226 rdata = reg32_read(DDRC_DRAMTMG2(0) + addr_slot);
227 ddrc_w2r = rdata & 0x3f;
228 if (is_imx8mp())
229 tmp = ddrc_w2r + (g_cdd_wr_max[i] >> 1);
230 else
231 tmp = ddrc_w2r + (g_cdd_wr_max[i] >> 1) + 1;
232 ddrc_w2r = (tmp > 0x3f) ? 0x3f : tmp;
233
234 ddrc_r2w = (rdata >> 8) & 0x3f;
235 if (is_imx8mp())
236 tmp = ddrc_r2w + (g_cdd_rw_max[i] >> 1);
237 else
238 tmp = ddrc_r2w + (g_cdd_rw_max[i] >> 1) + 1;
239 ddrc_r2w = (tmp > 0x3f) ? 0x3f : tmp;
240
241 tmp_t = (rdata & 0xffffc0c0) | (ddrc_r2w << 8) | ddrc_w2r;
242 reg32_write((DDRC_DRAMTMG2(0) + addr_slot), tmp_t);
243 } else {
244 /* update w2r:[5:0] */
245 rdata = reg32_read(DDRC_DRAMTMG9(0) + addr_slot);
246 ddrc_w2r = rdata & 0x3f;
247 if (is_imx8mp())
248 tmp = ddrc_w2r + (g_cdd_wr_max[i] >> 1);
249 else
250 tmp = ddrc_w2r + (g_cdd_wr_max[i] >> 1) + 1;
251 ddrc_w2r = (tmp > 0x3f) ? 0x3f : tmp;
252 tmp_t = (rdata & 0xffffffc0) | ddrc_w2r;
253 reg32_write((DDRC_DRAMTMG9(0) + addr_slot), tmp_t);
254
255 /* update r2w:[13:8] */
256 rdata = reg32_read(DDRC_DRAMTMG2(0) + addr_slot);
257 ddrc_r2w = (rdata >> 8) & 0x3f;
258 if (is_imx8mp())
259 tmp = ddrc_r2w + (g_cdd_rw_max[i] >> 1);
260 else
261 tmp = ddrc_r2w + (g_cdd_rw_max[i] >> 1) + 1;
262 ddrc_r2w = (tmp > 0x3f) ? 0x3f : tmp;
263
264 tmp_t = (rdata & 0xffffc0ff) | (ddrc_r2w << 8);
265 reg32_write((DDRC_DRAMTMG2(0) + addr_slot), tmp_t);
266 }
267
268 if (!is_imx8mq()) {
269 /*
270 * update rankctl: wr_gap:11:8; rd:gap:7:4; quasi-dymic, doc wrong(static)
271 */
272 rdata = reg32_read(DDRC_RANKCTL(0) + addr_slot);
273 ddrc_wr_gap = (rdata >> 8) & 0xf;
274 if (is_imx8mp())
275 tmp = ddrc_wr_gap + (g_cdd_ww_max[i] >> 1);
276 else
277 tmp = ddrc_wr_gap + (g_cdd_ww_max[i] >> 1) + 1;
278 ddrc_wr_gap = (tmp > 0xf) ? 0xf : tmp;
279
280 ddrc_rd_gap = (rdata >> 4) & 0xf;
281 if (is_imx8mp())
282 tmp = ddrc_rd_gap + (g_cdd_rr_max[i] >> 1);
283 else
284 tmp = ddrc_rd_gap + (g_cdd_rr_max[i] >> 1) + 1;
285 ddrc_rd_gap = (tmp > 0xf) ? 0xf : tmp;
286
287 tmp_t = (rdata & 0xfffff00f) | (ddrc_wr_gap << 8) | (ddrc_rd_gap << 4);
288 reg32_write((DDRC_RANKCTL(0) + addr_slot), tmp_t);
289 }
290 }
291
292 if (is_imx8mq()) {
293 /* update rankctl: wr_gap:11:8; rd:gap:7:4; quasi-dymic, doc wrong(static) */
294 rdata = reg32_read(DDRC_RANKCTL(0));
295 ddrc_wr_gap = (rdata >> 8) & 0xf;
296 tmp = ddrc_wr_gap + (g_cdd_ww_max[0] >> 1) + 1;
297 ddrc_wr_gap = (tmp > 0xf) ? 0xf : tmp;
298
299 ddrc_rd_gap = (rdata >> 4) & 0xf;
300 tmp = ddrc_rd_gap + (g_cdd_rr_max[0] >> 1) + 1;
301 ddrc_rd_gap = (tmp > 0xf) ? 0xf : tmp;
302
303 tmp_t = (rdata & 0xfffff00f) | (ddrc_wr_gap << 8) | (ddrc_rd_gap << 4);
304 reg32_write(DDRC_RANKCTL(0), tmp_t);
305 }
306}
307
Frieder Schrempf2a9b1f52019-12-11 10:01:19 +0000308int ddr_init(struct dram_timing_info *dram_timing)
Jacky Baid62ddc12019-08-08 09:59:08 +0000309{
310 unsigned int tmp, initial_drate, target_freq;
Frieder Schrempf2a9b1f52019-12-11 10:01:19 +0000311 int ret;
Jacky Baid62ddc12019-08-08 09:59:08 +0000312
Fabio Estevam9f7ee332019-12-11 17:37:09 -0300313 debug("DDRINFO: start DRAM init\n");
Jacky Baid62ddc12019-08-08 09:59:08 +0000314
315 /* Step1: Follow the power up procedure */
316 if (is_imx8mq()) {
317 reg32_write(SRC_DDRC_RCR_ADDR + 0x04, 0x8F00000F);
318 reg32_write(SRC_DDRC_RCR_ADDR, 0x8F00000F);
319 reg32_write(SRC_DDRC_RCR_ADDR + 0x04, 0x8F000000);
320 } else {
321 reg32_write(SRC_DDRC_RCR_ADDR, 0x8F00001F);
322 reg32_write(SRC_DDRC_RCR_ADDR, 0x8F00000F);
323 }
324
325 debug("DDRINFO: cfg clk\n");
326 /* change the clock source of dram_apb_clk_root: source 4 800MHz /4 = 200MHz */
327 clock_set_target_val(DRAM_APB_CLK_ROOT, CLK_ROOT_ON | CLK_ROOT_SOURCE_SEL(4) |
328 CLK_ROOT_PRE_DIV(CLK_ROOT_PRE_DIV4));
329
Jacky Baid62ddc12019-08-08 09:59:08 +0000330 /* disable iso */
331 reg32_write(0x303A00EC, 0x0000ffff); /* PGC_CPU_MAPPING */
332 reg32setbit(0x303A00F8, 5); /* PU_PGC_SW_PUP_REQ */
333
Jacky Bai828d41b2019-08-08 09:59:11 +0000334 initial_drate = dram_timing->fsp_msg[0].drate;
335 /* default to the frequency point 0 clock */
336 ddrphy_init_set_dfi_clk(initial_drate);
337
Jacky Baid62ddc12019-08-08 09:59:08 +0000338 /* D-aasert the presetn */
339 reg32_write(SRC_DDRC_RCR_ADDR, 0x8F000006);
340
341 /* Step2: Program the dwc_ddr_umctl2 registers */
342 debug("DDRINFO: ddrc config start\n");
343 ddr_cfg_umctl2(dram_timing->ddrc_cfg, dram_timing->ddrc_cfg_num);
344 debug("DDRINFO: ddrc config done\n");
345
346 /* Step3: De-assert reset signal(core_ddrc_rstn & aresetn_n) */
347 reg32_write(SRC_DDRC_RCR_ADDR, 0x8F000004);
348 reg32_write(SRC_DDRC_RCR_ADDR, 0x8F000000);
349
350 /*
351 * Step4: Disable auto-refreshes, self-refresh, powerdown, and
352 * assertion of dfi_dram_clk_disable by setting RFSHCTL3.dis_auto_refresh = 1,
353 * PWRCTL.powerdown_en = 0, and PWRCTL.selfref_en = 0, PWRCTL.en_dfi_dram_clk_disable = 0
354 */
355 reg32_write(DDRC_DBG1(0), 0x00000000);
356 reg32_write(DDRC_RFSHCTL3(0), 0x0000001);
357 reg32_write(DDRC_PWRCTL(0), 0xa0);
358
359 /* if ddr type is LPDDR4, do it */
360 tmp = reg32_read(DDRC_MSTR(0));
Jacky Baiedae3662019-06-05 11:26:12 +0800361 if (tmp & (0x1 << 5) && !is_imx8mn())
Jacky Baid62ddc12019-08-08 09:59:08 +0000362 reg32_write(DDRC_DDR_SS_GPR0, 0x01); /* LPDDR4 mode */
363
364 /* determine the initial boot frequency */
365 target_freq = reg32_read(DDRC_MSTR2(0)) & 0x3;
366 target_freq = (tmp & (0x1 << 29)) ? target_freq : 0x0;
367
368 /* Step5: Set SWCT.sw_done to 0 */
369 reg32_write(DDRC_SWCTL(0), 0x00000000);
370
371 /* Set the default boot frequency point */
372 clrsetbits_le32(DDRC_DFIMISC(0), (0x1f << 8), target_freq << 8);
373 /* Step6: Set DFIMISC.dfi_init_complete_en to 0 */
374 clrbits_le32(DDRC_DFIMISC(0), 0x1);
375
376 /* Step7: Set SWCTL.sw_done to 1; need to polling SWSTAT.sw_done_ack */
377 reg32_write(DDRC_SWCTL(0), 0x00000001);
378 do {
379 tmp = reg32_read(DDRC_SWSTAT(0));
380 } while ((tmp & 0x1) == 0x0);
381
382 /*
383 * Step8 ~ Step13: Start PHY initialization and training by
384 * accessing relevant PUB registers
385 */
386 debug("DDRINFO:ddrphy config start\n");
Frieder Schrempf2a9b1f52019-12-11 10:01:19 +0000387
388 ret = ddr_cfg_phy(dram_timing);
389 if (ret)
390 return ret;
391
Jacky Baid62ddc12019-08-08 09:59:08 +0000392 debug("DDRINFO: ddrphy config done\n");
393
394 /*
395 * step14 CalBusy.0 =1, indicates the calibrator is actively
396 * calibrating. Wait Calibrating done.
397 */
398 do {
399 tmp = reg32_read(DDRPHY_CalBusy(0));
400 } while ((tmp & 0x1));
401
Fabio Estevam9f7ee332019-12-11 17:37:09 -0300402 debug("DDRINFO:ddrphy calibration done\n");
Jacky Baid62ddc12019-08-08 09:59:08 +0000403
404 /* Step15: Set SWCTL.sw_done to 0 */
405 reg32_write(DDRC_SWCTL(0), 0x00000000);
406
Oliver Chen42eda3a2020-04-21 14:48:09 +0800407 /* Apply rank-to-rank workaround */
408 update_umctl2_rank_space_setting(dram_timing->fsp_msg_num - 1);
409
Jacky Baid62ddc12019-08-08 09:59:08 +0000410 /* Step16: Set DFIMISC.dfi_init_start to 1 */
411 setbits_le32(DDRC_DFIMISC(0), (0x1 << 5));
412
413 /* Step17: Set SWCTL.sw_done to 1; need to polling SWSTAT.sw_done_ack */
414 reg32_write(DDRC_SWCTL(0), 0x00000001);
415 do {
416 tmp = reg32_read(DDRC_SWSTAT(0));
417 } while ((tmp & 0x1) == 0x0);
418
419 /* Step18: Polling DFISTAT.dfi_init_complete = 1 */
420 do {
421 tmp = reg32_read(DDRC_DFISTAT(0));
422 } while ((tmp & 0x1) == 0x0);
423
424 /* Step19: Set SWCTL.sw_done to 0 */
425 reg32_write(DDRC_SWCTL(0), 0x00000000);
426
427 /* Step20: Set DFIMISC.dfi_init_start to 0 */
428 clrbits_le32(DDRC_DFIMISC(0), (0x1 << 5));
429
430 /* Step21: optional */
431
432 /* Step22: Set DFIMISC.dfi_init_complete_en to 1 */
433 setbits_le32(DDRC_DFIMISC(0), 0x1);
434
435 /* Step23: Set PWRCTL.selfref_sw to 0 */
436 clrbits_le32(DDRC_PWRCTL(0), (0x1 << 5));
437
438 /* Step24: Set SWCTL.sw_done to 1; need polling SWSTAT.sw_done_ack */
439 reg32_write(DDRC_SWCTL(0), 0x00000001);
440 do {
441 tmp = reg32_read(DDRC_SWSTAT(0));
442 } while ((tmp & 0x1) == 0x0);
443
444 /* Step25: Wait for dwc_ddr_umctl2 to move to normal operating mode by monitoring
445 * STAT.operating_mode signal */
446 do {
447 tmp = reg32_read(DDRC_STAT(0));
448 } while ((tmp & 0x3) != 0x1);
449
450 /* Step26: Set back register in Step4 to the original values if desired */
451 reg32_write(DDRC_RFSHCTL3(0), 0x0000000);
Jacky Baid62ddc12019-08-08 09:59:08 +0000452
453 /* enable port 0 */
454 reg32_write(DDRC_PCTRL_0(0), 0x00000001);
Fabio Estevam9f7ee332019-12-11 17:37:09 -0300455 debug("DDRINFO: ddrmix config done\n");
Jacky Baid62ddc12019-08-08 09:59:08 +0000456
Sherry Sun7957bd62020-01-20 11:13:14 +0800457 board_dram_ecc_scrub();
458
Ye Li36fcf112020-09-29 21:55:32 -0700459 /* enable selfref_en by default */
460 setbits_le32(DDRC_PWRCTL(0), 0x1);
461
Jacky Baid62ddc12019-08-08 09:59:08 +0000462 /* save the dram timing config into memory */
463 dram_config_save(dram_timing, CONFIG_SAVED_DRAM_TIMING_BASE);
Frieder Schrempf2a9b1f52019-12-11 10:01:19 +0000464
465 return 0;
Jacky Baid62ddc12019-08-08 09:59:08 +0000466}
Ye Lib2cfc422022-07-26 16:41:07 +0800467
468ulong ddrphy_addr_remap(uint32_t paddr_apb_from_ctlr)
469{
470 return 4 * paddr_apb_from_ctlr;
471}