blob: 852a5d0eca41e4ec21610ea2606cf7d3c39dba98 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kumar Gala124b0822008-08-26 15:01:29 -05002/*
York Sun6db4fdd2018-01-29 09:44:35 -08003 * Copyright 2008, 2010-2016 Freescale Semiconductor, Inc.
4 * Copyright 2017-2018 NXP Semiconductor
Kumar Gala124b0822008-08-26 15:01:29 -05005 */
6
Tom Rinidec7ea02024-05-20 13:35:03 -06007#include <config.h>
Simon Glassdb229612019-08-01 09:46:42 -06008#include <env.h>
Kumar Gala64042092010-07-14 10:04:21 -05009#include <hwconfig.h>
York Sunf0626592013-09-30 09:22:09 -070010#include <fsl_ddr_sdram.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060012#include <vsprintf.h>
Kumar Gala124b0822008-08-26 15:01:29 -050013
York Sunf0626592013-09-30 09:22:09 -070014#include <fsl_ddr.h>
Simon Glass89e0a3a2017-05-17 08:23:10 -060015#if defined(CONFIG_FSL_LSCH2) || defined(CONFIG_FSL_LSCH3) || \
16 defined(CONFIG_ARM)
Simon Glass243182c2017-05-17 08:23:06 -060017#include <asm/arch/clock.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060018#else
19#include <asm/ppc.h>
Simon Glass243182c2017-05-17 08:23:06 -060020#endif
Kumar Gala124b0822008-08-26 15:01:29 -050021
Kumar Gala72301602011-01-09 11:37:00 -060022/*
23 * Use our own stack based buffer before relocation to allow accessing longer
24 * hwconfig strings that might be in the environment before we've relocated.
25 * This is pretty fragile on both the use of stack and if the buffer is big
Simon Glass64b723f2017-08-03 12:22:12 -060026 * enough. However we will get a warning from env_get_f() for the latter.
Kumar Gala72301602011-01-09 11:37:00 -060027 */
Kumar Gala72301602011-01-09 11:37:00 -060028
Kumar Gala124b0822008-08-26 15:01:29 -050029/* Board-specific functions defined in each board's ddr.c */
Priyanka Jain419ffc92018-10-29 09:37:36 +000030void __weak fsl_ddr_board_options(memctl_options_t *popts,
31 dimm_params_t *pdimm,
32 unsigned int ctrl_num)
33{
34 return;
35}
Kumar Gala124b0822008-08-26 15:01:29 -050036
York Sun454f5072011-08-26 11:32:43 -070037struct dynamic_odt {
York Sunba0c2eb2011-01-10 12:03:00 +000038 unsigned int odt_rd_cfg;
39 unsigned int odt_wr_cfg;
40 unsigned int odt_rtt_norm;
41 unsigned int odt_rtt_wr;
York Sun454f5072011-08-26 11:32:43 -070042};
York Sunba0c2eb2011-01-10 12:03:00 +000043
York Sun5cb12f62015-11-04 10:03:17 -080044#ifdef CONFIG_SYS_FSL_DDR4
45/* Quad rank is not verified yet due availability.
46 * Replacing 20 OHM with 34 OHM since DDR4 doesn't have 20 OHM option
47 */
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -070048static __maybe_unused const struct dynamic_odt single_Q[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +000049 { /* cs0 */
50 FSL_DDR_ODT_NEVER,
51 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
York Sun5cb12f62015-11-04 10:03:17 -080052 DDR4_RTT_34_OHM, /* unverified */
53 DDR4_RTT_120_OHM
54 },
55 { /* cs1 */
56 FSL_DDR_ODT_NEVER,
57 FSL_DDR_ODT_NEVER,
58 DDR4_RTT_OFF,
59 DDR4_RTT_120_OHM
60 },
61 { /* cs2 */
62 FSL_DDR_ODT_NEVER,
63 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
64 DDR4_RTT_34_OHM,
65 DDR4_RTT_120_OHM
66 },
67 { /* cs3 */
68 FSL_DDR_ODT_NEVER,
69 FSL_DDR_ODT_NEVER, /* tied high */
70 DDR4_RTT_OFF,
71 DDR4_RTT_120_OHM
72 }
73};
74
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -070075static __maybe_unused const struct dynamic_odt single_D[4] = {
York Sun5cb12f62015-11-04 10:03:17 -080076 { /* cs0 */
77 FSL_DDR_ODT_NEVER,
78 FSL_DDR_ODT_ALL,
79 DDR4_RTT_40_OHM,
80 DDR4_RTT_OFF
81 },
82 { /* cs1 */
83 FSL_DDR_ODT_NEVER,
84 FSL_DDR_ODT_NEVER,
85 DDR4_RTT_OFF,
86 DDR4_RTT_OFF
87 },
88 {0, 0, 0, 0},
89 {0, 0, 0, 0}
90};
91
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -070092static __maybe_unused const struct dynamic_odt single_S[4] = {
York Sun5cb12f62015-11-04 10:03:17 -080093 { /* cs0 */
94 FSL_DDR_ODT_NEVER,
95 FSL_DDR_ODT_ALL,
96 DDR4_RTT_40_OHM,
97 DDR4_RTT_OFF
98 },
99 {0, 0, 0, 0},
100 {0, 0, 0, 0},
101 {0, 0, 0, 0},
102};
103
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700104static __maybe_unused const struct dynamic_odt dual_DD[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800105 { /* cs0 */
106 FSL_DDR_ODT_NEVER,
107 FSL_DDR_ODT_SAME_DIMM,
108 DDR4_RTT_120_OHM,
109 DDR4_RTT_OFF
110 },
111 { /* cs1 */
112 FSL_DDR_ODT_OTHER_DIMM,
113 FSL_DDR_ODT_OTHER_DIMM,
114 DDR4_RTT_34_OHM,
115 DDR4_RTT_OFF
116 },
117 { /* cs2 */
118 FSL_DDR_ODT_NEVER,
119 FSL_DDR_ODT_SAME_DIMM,
120 DDR4_RTT_120_OHM,
121 DDR4_RTT_OFF
122 },
123 { /* cs3 */
124 FSL_DDR_ODT_OTHER_DIMM,
125 FSL_DDR_ODT_OTHER_DIMM,
126 DDR4_RTT_34_OHM,
127 DDR4_RTT_OFF
128 }
129};
130
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700131static __maybe_unused const struct dynamic_odt dual_DS[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800132 { /* cs0 */
133 FSL_DDR_ODT_NEVER,
134 FSL_DDR_ODT_SAME_DIMM,
135 DDR4_RTT_120_OHM,
136 DDR4_RTT_OFF
137 },
138 { /* cs1 */
139 FSL_DDR_ODT_OTHER_DIMM,
140 FSL_DDR_ODT_OTHER_DIMM,
141 DDR4_RTT_34_OHM,
142 DDR4_RTT_OFF
143 },
144 { /* cs2 */
145 FSL_DDR_ODT_OTHER_DIMM,
146 FSL_DDR_ODT_ALL,
147 DDR4_RTT_34_OHM,
148 DDR4_RTT_120_OHM
149 },
150 {0, 0, 0, 0}
151};
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700152static __maybe_unused const struct dynamic_odt dual_SD[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800153 { /* cs0 */
154 FSL_DDR_ODT_OTHER_DIMM,
155 FSL_DDR_ODT_ALL,
156 DDR4_RTT_34_OHM,
157 DDR4_RTT_120_OHM
158 },
159 {0, 0, 0, 0},
160 { /* cs2 */
161 FSL_DDR_ODT_NEVER,
162 FSL_DDR_ODT_SAME_DIMM,
163 DDR4_RTT_120_OHM,
164 DDR4_RTT_OFF
165 },
166 { /* cs3 */
167 FSL_DDR_ODT_OTHER_DIMM,
168 FSL_DDR_ODT_OTHER_DIMM,
169 DDR4_RTT_34_OHM,
170 DDR4_RTT_OFF
171 }
172};
173
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700174static __maybe_unused const struct dynamic_odt dual_SS[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800175 { /* cs0 */
176 FSL_DDR_ODT_OTHER_DIMM,
177 FSL_DDR_ODT_ALL,
178 DDR4_RTT_34_OHM,
179 DDR4_RTT_120_OHM
180 },
181 {0, 0, 0, 0},
182 { /* cs2 */
183 FSL_DDR_ODT_OTHER_DIMM,
184 FSL_DDR_ODT_ALL,
185 DDR4_RTT_34_OHM,
186 DDR4_RTT_120_OHM
187 },
188 {0, 0, 0, 0}
189};
190
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700191static __maybe_unused const struct dynamic_odt dual_D0[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800192 { /* cs0 */
193 FSL_DDR_ODT_NEVER,
194 FSL_DDR_ODT_SAME_DIMM,
195 DDR4_RTT_40_OHM,
196 DDR4_RTT_OFF
197 },
198 { /* cs1 */
199 FSL_DDR_ODT_NEVER,
200 FSL_DDR_ODT_NEVER,
201 DDR4_RTT_OFF,
202 DDR4_RTT_OFF
203 },
204 {0, 0, 0, 0},
205 {0, 0, 0, 0}
206};
207
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700208static __maybe_unused const struct dynamic_odt dual_0D[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800209 {0, 0, 0, 0},
210 {0, 0, 0, 0},
211 { /* cs2 */
212 FSL_DDR_ODT_NEVER,
213 FSL_DDR_ODT_SAME_DIMM,
214 DDR4_RTT_40_OHM,
215 DDR4_RTT_OFF
216 },
217 { /* cs3 */
218 FSL_DDR_ODT_NEVER,
219 FSL_DDR_ODT_NEVER,
220 DDR4_RTT_OFF,
221 DDR4_RTT_OFF
222 }
223};
224
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700225static __maybe_unused const struct dynamic_odt dual_S0[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800226 { /* cs0 */
227 FSL_DDR_ODT_NEVER,
228 FSL_DDR_ODT_CS,
229 DDR4_RTT_40_OHM,
230 DDR4_RTT_OFF
231 },
232 {0, 0, 0, 0},
233 {0, 0, 0, 0},
234 {0, 0, 0, 0}
235
236};
237
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700238static __maybe_unused const struct dynamic_odt dual_0S[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800239 {0, 0, 0, 0},
240 {0, 0, 0, 0},
241 { /* cs2 */
242 FSL_DDR_ODT_NEVER,
243 FSL_DDR_ODT_CS,
244 DDR4_RTT_40_OHM,
245 DDR4_RTT_OFF
246 },
247 {0, 0, 0, 0}
248
249};
250
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700251static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800252 { /* cs0 */
253 FSL_DDR_ODT_NEVER,
254 FSL_DDR_ODT_CS,
255 DDR4_RTT_120_OHM,
256 DDR4_RTT_OFF
257 },
258 { /* cs1 */
259 FSL_DDR_ODT_NEVER,
260 FSL_DDR_ODT_CS,
261 DDR4_RTT_120_OHM,
262 DDR4_RTT_OFF
263 },
264 { /* cs2 */
265 FSL_DDR_ODT_NEVER,
266 FSL_DDR_ODT_CS,
267 DDR4_RTT_120_OHM,
268 DDR4_RTT_OFF
269 },
270 { /* cs3 */
271 FSL_DDR_ODT_NEVER,
272 FSL_DDR_ODT_CS,
273 DDR4_RTT_120_OHM,
274 DDR4_RTT_OFF
275 }
276};
277#elif defined(CONFIG_SYS_FSL_DDR3)
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700278static __maybe_unused const struct dynamic_odt single_Q[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800279 { /* cs0 */
280 FSL_DDR_ODT_NEVER,
281 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
York Sunba0c2eb2011-01-10 12:03:00 +0000282 DDR3_RTT_20_OHM,
283 DDR3_RTT_120_OHM
284 },
285 { /* cs1 */
286 FSL_DDR_ODT_NEVER,
287 FSL_DDR_ODT_NEVER, /* tied high */
288 DDR3_RTT_OFF,
289 DDR3_RTT_120_OHM
290 },
291 { /* cs2 */
292 FSL_DDR_ODT_NEVER,
293 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
294 DDR3_RTT_20_OHM,
295 DDR3_RTT_120_OHM
296 },
297 { /* cs3 */
298 FSL_DDR_ODT_NEVER,
299 FSL_DDR_ODT_NEVER, /* tied high */
300 DDR3_RTT_OFF,
301 DDR3_RTT_120_OHM
302 }
303};
304
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700305static __maybe_unused const struct dynamic_odt single_D[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000306 { /* cs0 */
307 FSL_DDR_ODT_NEVER,
308 FSL_DDR_ODT_ALL,
309 DDR3_RTT_40_OHM,
310 DDR3_RTT_OFF
311 },
312 { /* cs1 */
313 FSL_DDR_ODT_NEVER,
314 FSL_DDR_ODT_NEVER,
315 DDR3_RTT_OFF,
316 DDR3_RTT_OFF
317 },
318 {0, 0, 0, 0},
319 {0, 0, 0, 0}
320};
321
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700322static __maybe_unused const struct dynamic_odt single_S[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000323 { /* cs0 */
324 FSL_DDR_ODT_NEVER,
325 FSL_DDR_ODT_ALL,
326 DDR3_RTT_40_OHM,
327 DDR3_RTT_OFF
328 },
329 {0, 0, 0, 0},
330 {0, 0, 0, 0},
331 {0, 0, 0, 0},
332};
333
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700334static __maybe_unused const struct dynamic_odt dual_DD[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000335 { /* cs0 */
336 FSL_DDR_ODT_NEVER,
337 FSL_DDR_ODT_SAME_DIMM,
338 DDR3_RTT_120_OHM,
339 DDR3_RTT_OFF
340 },
341 { /* cs1 */
342 FSL_DDR_ODT_OTHER_DIMM,
343 FSL_DDR_ODT_OTHER_DIMM,
344 DDR3_RTT_30_OHM,
345 DDR3_RTT_OFF
346 },
347 { /* cs2 */
348 FSL_DDR_ODT_NEVER,
349 FSL_DDR_ODT_SAME_DIMM,
350 DDR3_RTT_120_OHM,
351 DDR3_RTT_OFF
352 },
353 { /* cs3 */
354 FSL_DDR_ODT_OTHER_DIMM,
355 FSL_DDR_ODT_OTHER_DIMM,
356 DDR3_RTT_30_OHM,
357 DDR3_RTT_OFF
358 }
359};
360
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700361static __maybe_unused const struct dynamic_odt dual_DS[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000362 { /* cs0 */
363 FSL_DDR_ODT_NEVER,
364 FSL_DDR_ODT_SAME_DIMM,
365 DDR3_RTT_120_OHM,
366 DDR3_RTT_OFF
367 },
368 { /* cs1 */
369 FSL_DDR_ODT_OTHER_DIMM,
370 FSL_DDR_ODT_OTHER_DIMM,
371 DDR3_RTT_30_OHM,
372 DDR3_RTT_OFF
373 },
374 { /* cs2 */
375 FSL_DDR_ODT_OTHER_DIMM,
376 FSL_DDR_ODT_ALL,
377 DDR3_RTT_20_OHM,
378 DDR3_RTT_120_OHM
379 },
380 {0, 0, 0, 0}
381};
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700382static __maybe_unused const struct dynamic_odt dual_SD[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000383 { /* cs0 */
384 FSL_DDR_ODT_OTHER_DIMM,
385 FSL_DDR_ODT_ALL,
386 DDR3_RTT_20_OHM,
387 DDR3_RTT_120_OHM
388 },
389 {0, 0, 0, 0},
390 { /* cs2 */
391 FSL_DDR_ODT_NEVER,
392 FSL_DDR_ODT_SAME_DIMM,
393 DDR3_RTT_120_OHM,
394 DDR3_RTT_OFF
395 },
396 { /* cs3 */
397 FSL_DDR_ODT_OTHER_DIMM,
398 FSL_DDR_ODT_OTHER_DIMM,
399 DDR3_RTT_20_OHM,
400 DDR3_RTT_OFF
401 }
402};
403
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700404static __maybe_unused const struct dynamic_odt dual_SS[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000405 { /* cs0 */
406 FSL_DDR_ODT_OTHER_DIMM,
407 FSL_DDR_ODT_ALL,
408 DDR3_RTT_30_OHM,
409 DDR3_RTT_120_OHM
410 },
411 {0, 0, 0, 0},
412 { /* cs2 */
413 FSL_DDR_ODT_OTHER_DIMM,
414 FSL_DDR_ODT_ALL,
415 DDR3_RTT_30_OHM,
416 DDR3_RTT_120_OHM
417 },
418 {0, 0, 0, 0}
419};
420
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700421static __maybe_unused const struct dynamic_odt dual_D0[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000422 { /* cs0 */
423 FSL_DDR_ODT_NEVER,
424 FSL_DDR_ODT_SAME_DIMM,
425 DDR3_RTT_40_OHM,
426 DDR3_RTT_OFF
427 },
428 { /* cs1 */
429 FSL_DDR_ODT_NEVER,
430 FSL_DDR_ODT_NEVER,
431 DDR3_RTT_OFF,
432 DDR3_RTT_OFF
433 },
434 {0, 0, 0, 0},
435 {0, 0, 0, 0}
436};
437
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700438static __maybe_unused const struct dynamic_odt dual_0D[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000439 {0, 0, 0, 0},
440 {0, 0, 0, 0},
441 { /* cs2 */
442 FSL_DDR_ODT_NEVER,
443 FSL_DDR_ODT_SAME_DIMM,
444 DDR3_RTT_40_OHM,
445 DDR3_RTT_OFF
446 },
447 { /* cs3 */
448 FSL_DDR_ODT_NEVER,
449 FSL_DDR_ODT_NEVER,
450 DDR3_RTT_OFF,
451 DDR3_RTT_OFF
452 }
453};
454
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700455static __maybe_unused const struct dynamic_odt dual_S0[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000456 { /* cs0 */
457 FSL_DDR_ODT_NEVER,
458 FSL_DDR_ODT_CS,
459 DDR3_RTT_40_OHM,
460 DDR3_RTT_OFF
461 },
462 {0, 0, 0, 0},
463 {0, 0, 0, 0},
464 {0, 0, 0, 0}
465
466};
467
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700468static __maybe_unused const struct dynamic_odt dual_0S[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000469 {0, 0, 0, 0},
470 {0, 0, 0, 0},
471 { /* cs2 */
472 FSL_DDR_ODT_NEVER,
473 FSL_DDR_ODT_CS,
474 DDR3_RTT_40_OHM,
475 DDR3_RTT_OFF
476 },
477 {0, 0, 0, 0}
478
479};
480
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700481static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000482 { /* cs0 */
483 FSL_DDR_ODT_NEVER,
484 FSL_DDR_ODT_CS,
485 DDR3_RTT_120_OHM,
486 DDR3_RTT_OFF
487 },
488 { /* cs1 */
489 FSL_DDR_ODT_NEVER,
490 FSL_DDR_ODT_CS,
491 DDR3_RTT_120_OHM,
492 DDR3_RTT_OFF
493 },
494 { /* cs2 */
495 FSL_DDR_ODT_NEVER,
496 FSL_DDR_ODT_CS,
497 DDR3_RTT_120_OHM,
498 DDR3_RTT_OFF
499 },
500 { /* cs3 */
501 FSL_DDR_ODT_NEVER,
502 FSL_DDR_ODT_CS,
503 DDR3_RTT_120_OHM,
504 DDR3_RTT_OFF
505 }
506};
York Sun5cb12f62015-11-04 10:03:17 -0800507#else /* CONFIG_SYS_FSL_DDR3 */
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700508static __maybe_unused const struct dynamic_odt single_Q[4] = {
York Sun454f5072011-08-26 11:32:43 -0700509 {0, 0, 0, 0},
510 {0, 0, 0, 0},
511 {0, 0, 0, 0},
512 {0, 0, 0, 0}
513};
514
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700515static __maybe_unused const struct dynamic_odt single_D[4] = {
York Sun454f5072011-08-26 11:32:43 -0700516 { /* cs0 */
517 FSL_DDR_ODT_NEVER,
518 FSL_DDR_ODT_ALL,
519 DDR2_RTT_150_OHM,
520 DDR2_RTT_OFF
521 },
522 { /* cs1 */
523 FSL_DDR_ODT_NEVER,
524 FSL_DDR_ODT_NEVER,
525 DDR2_RTT_OFF,
526 DDR2_RTT_OFF
527 },
528 {0, 0, 0, 0},
529 {0, 0, 0, 0}
530};
531
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700532static __maybe_unused const struct dynamic_odt single_S[4] = {
York Sun454f5072011-08-26 11:32:43 -0700533 { /* cs0 */
534 FSL_DDR_ODT_NEVER,
535 FSL_DDR_ODT_ALL,
536 DDR2_RTT_150_OHM,
537 DDR2_RTT_OFF
538 },
539 {0, 0, 0, 0},
540 {0, 0, 0, 0},
541 {0, 0, 0, 0},
542};
543
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700544static __maybe_unused const struct dynamic_odt dual_DD[4] = {
York Sun454f5072011-08-26 11:32:43 -0700545 { /* cs0 */
546 FSL_DDR_ODT_OTHER_DIMM,
547 FSL_DDR_ODT_OTHER_DIMM,
548 DDR2_RTT_75_OHM,
549 DDR2_RTT_OFF
550 },
551 { /* cs1 */
552 FSL_DDR_ODT_NEVER,
553 FSL_DDR_ODT_NEVER,
554 DDR2_RTT_OFF,
555 DDR2_RTT_OFF
556 },
557 { /* cs2 */
558 FSL_DDR_ODT_OTHER_DIMM,
559 FSL_DDR_ODT_OTHER_DIMM,
560 DDR2_RTT_75_OHM,
561 DDR2_RTT_OFF
562 },
563 { /* cs3 */
564 FSL_DDR_ODT_NEVER,
565 FSL_DDR_ODT_NEVER,
566 DDR2_RTT_OFF,
567 DDR2_RTT_OFF
568 }
569};
570
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700571static __maybe_unused const struct dynamic_odt dual_DS[4] = {
York Sun454f5072011-08-26 11:32:43 -0700572 { /* cs0 */
573 FSL_DDR_ODT_OTHER_DIMM,
574 FSL_DDR_ODT_OTHER_DIMM,
575 DDR2_RTT_75_OHM,
576 DDR2_RTT_OFF
577 },
578 { /* cs1 */
579 FSL_DDR_ODT_NEVER,
580 FSL_DDR_ODT_NEVER,
581 DDR2_RTT_OFF,
582 DDR2_RTT_OFF
583 },
584 { /* cs2 */
585 FSL_DDR_ODT_OTHER_DIMM,
586 FSL_DDR_ODT_OTHER_DIMM,
587 DDR2_RTT_75_OHM,
588 DDR2_RTT_OFF
589 },
590 {0, 0, 0, 0}
591};
592
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700593static __maybe_unused const struct dynamic_odt dual_SD[4] = {
York Sun454f5072011-08-26 11:32:43 -0700594 { /* cs0 */
595 FSL_DDR_ODT_OTHER_DIMM,
596 FSL_DDR_ODT_OTHER_DIMM,
597 DDR2_RTT_75_OHM,
598 DDR2_RTT_OFF
599 },
600 {0, 0, 0, 0},
601 { /* cs2 */
602 FSL_DDR_ODT_OTHER_DIMM,
603 FSL_DDR_ODT_OTHER_DIMM,
604 DDR2_RTT_75_OHM,
605 DDR2_RTT_OFF
606 },
607 { /* cs3 */
608 FSL_DDR_ODT_NEVER,
609 FSL_DDR_ODT_NEVER,
610 DDR2_RTT_OFF,
611 DDR2_RTT_OFF
612 }
613};
614
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700615static __maybe_unused const struct dynamic_odt dual_SS[4] = {
York Sun454f5072011-08-26 11:32:43 -0700616 { /* cs0 */
617 FSL_DDR_ODT_OTHER_DIMM,
618 FSL_DDR_ODT_OTHER_DIMM,
619 DDR2_RTT_75_OHM,
620 DDR2_RTT_OFF
621 },
622 {0, 0, 0, 0},
623 { /* cs2 */
624 FSL_DDR_ODT_OTHER_DIMM,
625 FSL_DDR_ODT_OTHER_DIMM,
626 DDR2_RTT_75_OHM,
627 DDR2_RTT_OFF
628 },
629 {0, 0, 0, 0}
630};
631
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700632static __maybe_unused const struct dynamic_odt dual_D0[4] = {
York Sun454f5072011-08-26 11:32:43 -0700633 { /* cs0 */
634 FSL_DDR_ODT_NEVER,
635 FSL_DDR_ODT_ALL,
636 DDR2_RTT_150_OHM,
637 DDR2_RTT_OFF
638 },
639 { /* cs1 */
640 FSL_DDR_ODT_NEVER,
641 FSL_DDR_ODT_NEVER,
642 DDR2_RTT_OFF,
643 DDR2_RTT_OFF
644 },
645 {0, 0, 0, 0},
646 {0, 0, 0, 0}
647};
648
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700649static __maybe_unused const struct dynamic_odt dual_0D[4] = {
York Sun454f5072011-08-26 11:32:43 -0700650 {0, 0, 0, 0},
651 {0, 0, 0, 0},
652 { /* cs2 */
653 FSL_DDR_ODT_NEVER,
654 FSL_DDR_ODT_ALL,
655 DDR2_RTT_150_OHM,
656 DDR2_RTT_OFF
657 },
658 { /* cs3 */
659 FSL_DDR_ODT_NEVER,
660 FSL_DDR_ODT_NEVER,
661 DDR2_RTT_OFF,
662 DDR2_RTT_OFF
663 }
664};
York Sunba0c2eb2011-01-10 12:03:00 +0000665
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700666static __maybe_unused const struct dynamic_odt dual_S0[4] = {
York Sun454f5072011-08-26 11:32:43 -0700667 { /* cs0 */
668 FSL_DDR_ODT_NEVER,
669 FSL_DDR_ODT_CS,
670 DDR2_RTT_150_OHM,
671 DDR2_RTT_OFF
672 },
673 {0, 0, 0, 0},
674 {0, 0, 0, 0},
675 {0, 0, 0, 0}
676
677};
678
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700679static __maybe_unused const struct dynamic_odt dual_0S[4] = {
York Sun454f5072011-08-26 11:32:43 -0700680 {0, 0, 0, 0},
681 {0, 0, 0, 0},
682 { /* cs2 */
683 FSL_DDR_ODT_NEVER,
684 FSL_DDR_ODT_CS,
685 DDR2_RTT_150_OHM,
686 DDR2_RTT_OFF
687 },
688 {0, 0, 0, 0}
689
690};
691
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700692static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
York Sun454f5072011-08-26 11:32:43 -0700693 { /* cs0 */
694 FSL_DDR_ODT_NEVER,
695 FSL_DDR_ODT_CS,
696 DDR2_RTT_75_OHM,
697 DDR2_RTT_OFF
698 },
699 { /* cs1 */
700 FSL_DDR_ODT_NEVER,
701 FSL_DDR_ODT_NEVER,
702 DDR2_RTT_OFF,
703 DDR2_RTT_OFF
704 },
705 { /* cs2 */
706 FSL_DDR_ODT_NEVER,
707 FSL_DDR_ODT_CS,
708 DDR2_RTT_75_OHM,
709 DDR2_RTT_OFF
710 },
711 { /* cs3 */
712 FSL_DDR_ODT_NEVER,
713 FSL_DDR_ODT_NEVER,
714 DDR2_RTT_OFF,
715 DDR2_RTT_OFF
716 }
717};
718#endif
York Sund01babd2012-10-08 07:44:27 +0000719
720/*
721 * Automatically seleect bank interleaving mode based on DIMMs
722 * in this order: cs0_cs1_cs2_cs3, cs0_cs1, null.
723 * This function only deal with one or two slots per controller.
724 */
725static inline unsigned int auto_bank_intlv(dimm_params_t *pdimm)
726{
727#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
728 if (pdimm[0].n_ranks == 4)
729 return FSL_DDR_CS0_CS1_CS2_CS3;
730 else if (pdimm[0].n_ranks == 2)
731 return FSL_DDR_CS0_CS1;
732#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
733#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
734 if (pdimm[0].n_ranks == 4)
735 return FSL_DDR_CS0_CS1_CS2_CS3;
736#endif
737 if (pdimm[0].n_ranks == 2) {
738 if (pdimm[1].n_ranks == 2)
739 return FSL_DDR_CS0_CS1_CS2_CS3;
740 else
741 return FSL_DDR_CS0_CS1;
742 }
743#endif
744 return 0;
745}
746
York Sun999273f2015-07-23 14:04:48 -0700747unsigned int populate_memctl_options(const common_timing_params_t *common_dimm,
Kumar Gala124b0822008-08-26 15:01:29 -0500748 memctl_options_t *popts,
Haiying Wangfa440362008-10-03 12:36:55 -0400749 dimm_params_t *pdimm,
Kumar Gala124b0822008-08-26 15:01:29 -0500750 unsigned int ctrl_num)
751{
752 unsigned int i;
Jeremy Gebben1a491e82018-07-20 16:00:36 -0600753 char buf[HWCONFIG_BUFFER_SIZE];
York Sun2896cb72014-03-27 17:54:47 -0700754#if defined(CONFIG_SYS_FSL_DDR3) || \
755 defined(CONFIG_SYS_FSL_DDR2) || \
756 defined(CONFIG_SYS_FSL_DDR4)
York Sun454f5072011-08-26 11:32:43 -0700757 const struct dynamic_odt *pdodt = odt_unknown;
Kumar Gala59cb44c2011-11-09 10:05:21 -0600758#endif
Tom Rini364d0022023-01-10 11:19:45 -0500759#if (CFG_FSL_SDRAM_TYPE != SDRAM_TYPE_DDR4)
York Sunf0345e22011-08-24 09:40:26 -0700760 ulong ddr_freq;
York Sunbc2f32a2018-01-29 10:24:08 -0800761#endif
Kumar Gala72301602011-01-09 11:37:00 -0600762
763 /*
764 * Extract hwconfig from environment since we have not properly setup
765 * the environment but need it for ddr config params
766 */
Pali Rohár654ec602022-04-03 00:24:26 +0200767#if CONFIG_IS_ENABLED(ENV_SUPPORT)
Jeremy Gebben1a491e82018-07-20 16:00:36 -0600768 if (env_get_f("hwconfig", buf, sizeof(buf)) < 0)
Pali Rohár654ec602022-04-03 00:24:26 +0200769#endif
Jeremy Gebben1a491e82018-07-20 16:00:36 -0600770 buf[0] = '\0';
Kumar Gala124b0822008-08-26 15:01:29 -0500771
York Sun2896cb72014-03-27 17:54:47 -0700772#if defined(CONFIG_SYS_FSL_DDR3) || \
773 defined(CONFIG_SYS_FSL_DDR2) || \
774 defined(CONFIG_SYS_FSL_DDR4)
Kumar Gala124b0822008-08-26 15:01:29 -0500775 /* Chip select options. */
York Sunedbeee12014-04-01 14:20:49 -0700776#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
777 switch (pdimm[0].n_ranks) {
778 case 1:
779 pdodt = single_S;
780 break;
781 case 2:
782 pdodt = single_D;
783 break;
784 case 4:
785 pdodt = single_Q;
786 break;
787 }
788#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
789 switch (pdimm[0].n_ranks) {
790#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
791 case 4:
792 pdodt = single_Q;
793 if (pdimm[1].n_ranks)
794 printf("Error: Quad- and Dual-rank DIMMs cannot be used together\n");
795 break;
796#endif
797 case 2:
798 switch (pdimm[1].n_ranks) {
York Sunba0c2eb2011-01-10 12:03:00 +0000799 case 2:
York Sunedbeee12014-04-01 14:20:49 -0700800 pdodt = dual_DD;
York Sunba0c2eb2011-01-10 12:03:00 +0000801 break;
York Sunedbeee12014-04-01 14:20:49 -0700802 case 1:
803 pdodt = dual_DS;
York Sunba0c2eb2011-01-10 12:03:00 +0000804 break;
York Sunedbeee12014-04-01 14:20:49 -0700805 case 0:
806 pdodt = dual_D0;
York Sun98df4d12012-10-08 07:44:23 +0000807 break;
York Sunedbeee12014-04-01 14:20:49 -0700808 }
809 break;
810 case 1:
811 switch (pdimm[1].n_ranks) {
York Sunba0c2eb2011-01-10 12:03:00 +0000812 case 2:
York Sunedbeee12014-04-01 14:20:49 -0700813 pdodt = dual_SD;
York Sunba0c2eb2011-01-10 12:03:00 +0000814 break;
815 case 1:
York Sunedbeee12014-04-01 14:20:49 -0700816 pdodt = dual_SS;
York Sunba0c2eb2011-01-10 12:03:00 +0000817 break;
818 case 0:
York Sunedbeee12014-04-01 14:20:49 -0700819 pdodt = dual_S0;
York Sunba0c2eb2011-01-10 12:03:00 +0000820 break;
821 }
York Sunedbeee12014-04-01 14:20:49 -0700822 break;
823 case 0:
824 switch (pdimm[1].n_ranks) {
825 case 2:
826 pdodt = dual_0D;
827 break;
828 case 1:
829 pdodt = dual_0S;
830 break;
831 }
832 break;
York Sunba0c2eb2011-01-10 12:03:00 +0000833 }
York Sunedbeee12014-04-01 14:20:49 -0700834#endif /* CONFIG_DIMM_SLOTS_PER_CTLR */
835#endif /* CONFIG_SYS_FSL_DDR2, 3, 4 */
Kumar Gala124b0822008-08-26 15:01:29 -0500836
837 /* Pick chip-select local options. */
838 for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
York Sun2896cb72014-03-27 17:54:47 -0700839#if defined(CONFIG_SYS_FSL_DDR3) || \
840 defined(CONFIG_SYS_FSL_DDR2) || \
841 defined(CONFIG_SYS_FSL_DDR4)
York Sunba0c2eb2011-01-10 12:03:00 +0000842 popts->cs_local_opts[i].odt_rd_cfg = pdodt[i].odt_rd_cfg;
843 popts->cs_local_opts[i].odt_wr_cfg = pdodt[i].odt_wr_cfg;
844 popts->cs_local_opts[i].odt_rtt_norm = pdodt[i].odt_rtt_norm;
845 popts->cs_local_opts[i].odt_rtt_wr = pdodt[i].odt_rtt_wr;
846#else
847 popts->cs_local_opts[i].odt_rd_cfg = FSL_DDR_ODT_NEVER;
848 popts->cs_local_opts[i].odt_wr_cfg = FSL_DDR_ODT_CS;
849#endif
Kumar Gala124b0822008-08-26 15:01:29 -0500850 popts->cs_local_opts[i].auto_precharge = 0;
851 }
852
853 /* Pick interleaving mode. */
854
855 /*
856 * 0 = no interleaving
857 * 1 = interleaving between 2 controllers
858 */
859 popts->memctl_interleaving = 0;
860
861 /*
862 * 0 = cacheline
863 * 1 = page
864 * 2 = (logical) bank
865 * 3 = superbank (only if CS interleaving is enabled)
866 */
867 popts->memctl_interleaving_mode = 0;
868
869 /*
870 * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
871 * 1: page: bit to the left of the column bits selects the memctl
872 * 2: bank: bit to the left of the bank bits selects the memctl
873 * 3: superbank: bit to the left of the chip select selects the memctl
874 *
875 * NOTE: ba_intlv (rank interleaving) is independent of memory
876 * controller interleaving; it is only within a memory controller.
877 * Must use superbank interleaving if rank interleaving is used and
878 * memory controller interleaving is enabled.
879 */
880
881 /*
882 * 0 = no
883 * 0x40 = CS0,CS1
884 * 0x20 = CS2,CS3
885 * 0x60 = CS0,CS1 + CS2,CS3
886 * 0x04 = CS0,CS1,CS2,CS3
887 */
888 popts->ba_intlv_ctl = 0;
889
890 /* Memory Organization Parameters */
York Sun999273f2015-07-23 14:04:48 -0700891 popts->registered_dimm_en = common_dimm->all_dimms_registered;
Kumar Gala124b0822008-08-26 15:01:29 -0500892
893 /* Operational Mode Paramters */
894
895 /* Pick ECC modes */
Priyanka Jain4a717412013-09-25 10:41:19 +0530896 popts->ecc_mode = 0; /* 0 = disabled, 1 = enabled */
York Sun0ac71ea2011-01-10 12:02:57 +0000897#ifdef CONFIG_DDR_ECC
898 if (hwconfig_sub_f("fsl_ddr", "ecc", buf)) {
899 if (hwconfig_subarg_cmp_f("fsl_ddr", "ecc", "on", buf))
Priyanka Jain4a717412013-09-25 10:41:19 +0530900 popts->ecc_mode = 1;
York Sun0ac71ea2011-01-10 12:02:57 +0000901 } else
Priyanka Jain4a717412013-09-25 10:41:19 +0530902 popts->ecc_mode = 1;
Kumar Gala124b0822008-08-26 15:01:29 -0500903#endif
York Sun2a77a122016-05-26 12:19:03 -0700904 /* 1 = use memory controler to init data */
905 popts->ecc_init_using_memctl = popts->ecc_mode ? 1 : 0;
Kumar Gala124b0822008-08-26 15:01:29 -0500906
907 /*
908 * Choose DQS config
909 * 0 for DDR1
910 * 1 for DDR2
911 */
York Sunf0626592013-09-30 09:22:09 -0700912#if defined(CONFIG_SYS_FSL_DDR1)
Priyanka Jain4a717412013-09-25 10:41:19 +0530913 popts->dqs_config = 0;
York Sunf0626592013-09-30 09:22:09 -0700914#elif defined(CONFIG_SYS_FSL_DDR2) || defined(CONFIG_SYS_FSL_DDR3)
Priyanka Jain4a717412013-09-25 10:41:19 +0530915 popts->dqs_config = 1;
Kumar Gala124b0822008-08-26 15:01:29 -0500916#endif
917
918 /* Choose self-refresh during sleep. */
919 popts->self_refresh_in_sleep = 1;
920
921 /* Choose dynamic power management mode. */
922 popts->dynamic_power = 0;
923
York Sun5fb9f6f2011-05-27 07:25:48 +0800924 /*
925 * check first dimm for primary sdram width
926 * presuming all dimms are similar
927 * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit
928 */
York Sunf0626592013-09-30 09:22:09 -0700929#if defined(CONFIG_SYS_FSL_DDR1) || defined(CONFIG_SYS_FSL_DDR2)
York Sun3c5ffd42011-06-27 13:35:25 -0700930 if (pdimm[0].n_ranks != 0) {
931 if ((pdimm[0].data_width >= 64) && \
932 (pdimm[0].data_width <= 72))
933 popts->data_bus_width = 0;
xypron.glpk@gmx.de5fecf832017-04-15 15:23:49 +0200934 else if ((pdimm[0].data_width >= 32) && \
York Sun3c5ffd42011-06-27 13:35:25 -0700935 (pdimm[0].data_width <= 40))
936 popts->data_bus_width = 1;
937 else {
938 panic("Error: data width %u is invalid!\n",
939 pdimm[0].data_width);
940 }
941 }
942#else
943 if (pdimm[0].n_ranks != 0) {
944 if (pdimm[0].primary_sdram_width == 64)
945 popts->data_bus_width = 0;
946 else if (pdimm[0].primary_sdram_width == 32)
947 popts->data_bus_width = 1;
948 else if (pdimm[0].primary_sdram_width == 16)
949 popts->data_bus_width = 2;
950 else {
951 panic("Error: primary sdram width %u is invalid!\n",
952 pdimm[0].primary_sdram_width);
953 }
954 }
955#endif
Kumar Gala124b0822008-08-26 15:01:29 -0500956
York Sun4889c982013-06-25 11:37:47 -0700957 popts->x4_en = (pdimm[0].device_width == 4) ? 1 : 0;
958
Kumar Gala124b0822008-08-26 15:01:29 -0500959 /* Choose burst length. */
York Sun2896cb72014-03-27 17:54:47 -0700960#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
Dave Liu707aa5c2010-03-05 12:22:00 +0800961#if defined(CONFIG_E500MC)
Priyanka Jain4a717412013-09-25 10:41:19 +0530962 popts->otf_burst_chop_en = 0; /* on-the-fly burst chop disable */
Dave Liu707aa5c2010-03-05 12:22:00 +0800963 popts->burst_length = DDR_BL8; /* Fixed 8-beat burst len */
964#else
York Sundd803dd2011-05-27 07:25:51 +0800965 if ((popts->data_bus_width == 1) || (popts->data_bus_width == 2)) {
966 /* 32-bit or 16-bit bus */
Priyanka Jain4a717412013-09-25 10:41:19 +0530967 popts->otf_burst_chop_en = 0;
York Sun5fb9f6f2011-05-27 07:25:48 +0800968 popts->burst_length = DDR_BL8;
969 } else {
Priyanka Jain4a717412013-09-25 10:41:19 +0530970 popts->otf_burst_chop_en = 1; /* on-the-fly burst chop */
York Sun5fb9f6f2011-05-27 07:25:48 +0800971 popts->burst_length = DDR_OTF; /* on-the-fly BC4 and BL8 */
972 }
Dave Liu707aa5c2010-03-05 12:22:00 +0800973#endif
Dave Liu4be87b22009-03-14 12:48:30 +0800974#else
975 popts->burst_length = DDR_BL4; /* has to be 4 for DDR2 */
976#endif
977
978 /* Choose ddr controller address mirror mode */
York Sun2896cb72014-03-27 17:54:47 -0700979#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
York Sunfc63b282015-03-19 09:30:27 -0700980 for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
981 if (pdimm[i].n_ranks) {
982 popts->mirrored_dimm = pdimm[i].mirrored_dimm;
983 break;
984 }
985 }
Dave Liu4be87b22009-03-14 12:48:30 +0800986#endif
Kumar Gala124b0822008-08-26 15:01:29 -0500987
988 /* Global Timing Parameters. */
York Sun2c0b62d2015-01-06 13:18:50 -0800989 debug("mclk_ps = %u ps\n", get_memory_clk_period_ps(ctrl_num));
Kumar Gala124b0822008-08-26 15:01:29 -0500990
991 /* Pick a caslat override. */
992 popts->cas_latency_override = 0;
993 popts->cas_latency_override_value = 3;
994 if (popts->cas_latency_override) {
995 debug("using caslat override value = %u\n",
996 popts->cas_latency_override_value);
997 }
998
999 /* Decide whether to use the computed derated latency */
1000 popts->use_derated_caslat = 0;
1001
1002 /* Choose an additive latency. */
1003 popts->additive_latency_override = 0;
1004 popts->additive_latency_override_value = 3;
1005 if (popts->additive_latency_override) {
1006 debug("using additive latency override value = %u\n",
1007 popts->additive_latency_override_value);
1008 }
1009
1010 /*
1011 * 2T_EN setting
1012 *
1013 * Factors to consider for 2T_EN:
1014 * - number of DIMMs installed
1015 * - number of components, number of active ranks
1016 * - how much time you want to spend playing around
1017 */
Priyanka Jain4a717412013-09-25 10:41:19 +05301018 popts->twot_en = 0;
1019 popts->threet_en = 0;
Kumar Gala124b0822008-08-26 15:01:29 -05001020
Shengzhou Liu52199442016-03-10 17:36:56 +08001021 /* for RDIMM and DDR4 UDIMM/discrete memory, address parity enable */
1022 if (popts->registered_dimm_en)
1023 popts->ap_en = 1; /* 0 = disable, 1 = enable */
1024 else
1025 popts->ap_en = 0; /* disabled for DDR4 UDIMM/discrete default */
1026
1027 if (hwconfig_sub_f("fsl_ddr", "parity", buf)) {
1028 if (hwconfig_subarg_cmp_f("fsl_ddr", "parity", "on", buf)) {
1029 if (popts->registered_dimm_en ||
Tom Rini364d0022023-01-10 11:19:45 -05001030 (CFG_FSL_SDRAM_TYPE == SDRAM_TYPE_DDR4))
Shengzhou Liu52199442016-03-10 17:36:56 +08001031 popts->ap_en = 1;
1032 }
1033 }
York Sunba0c2eb2011-01-10 12:03:00 +00001034
Kumar Gala124b0822008-08-26 15:01:29 -05001035 /*
1036 * BSTTOPRE precharge interval
1037 *
1038 * Set this to 0 for global auto precharge
York Sun2896cb72014-03-27 17:54:47 -07001039 * The value of 0x100 has been used for DDR1, DDR2, DDR3.
1040 * It is not wrong. Any value should be OK. The performance depends on
York Sun999273f2015-07-23 14:04:48 -07001041 * applications. There is no one good value for all. One way to set
1042 * is to use 1/4 of refint value.
Kumar Gala124b0822008-08-26 15:01:29 -05001043 */
York Sun999273f2015-07-23 14:04:48 -07001044 popts->bstopre = picos_to_mclk(ctrl_num, common_dimm->refresh_rate_ps)
1045 >> 2;
Kumar Gala124b0822008-08-26 15:01:29 -05001046
Kumar Gala124b0822008-08-26 15:01:29 -05001047 /*
1048 * Window for four activates -- tFAW
1049 *
1050 * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
1051 * FIXME: varies depending upon number of column addresses or data
1052 * FIXME: width, was considering looking at pdimm->primary_sdram_width
1053 */
York Sunf0626592013-09-30 09:22:09 -07001054#if defined(CONFIG_SYS_FSL_DDR1)
York Sun2c0b62d2015-01-06 13:18:50 -08001055 popts->tfaw_window_four_activates_ps = mclk_to_picos(ctrl_num, 1);
Kumar Gala124b0822008-08-26 15:01:29 -05001056
York Sunf0626592013-09-30 09:22:09 -07001057#elif defined(CONFIG_SYS_FSL_DDR2)
Kumar Gala124b0822008-08-26 15:01:29 -05001058 /*
1059 * x4/x8; some datasheets have 35000
1060 * x16 wide columns only? Use 50000?
1061 */
Priyanka Jain4a717412013-09-25 10:41:19 +05301062 popts->tfaw_window_four_activates_ps = 37500;
Kumar Gala124b0822008-08-26 15:01:29 -05001063
York Sun2896cb72014-03-27 17:54:47 -07001064#else
Priyanka Jain4a717412013-09-25 10:41:19 +05301065 popts->tfaw_window_four_activates_ps = pdimm[0].tfaw_ps;
Dave Liu4be87b22009-03-14 12:48:30 +08001066#endif
1067 popts->zq_en = 0;
1068 popts->wrlvl_en = 0;
York Sun2896cb72014-03-27 17:54:47 -07001069#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
Dave Liu4be87b22009-03-14 12:48:30 +08001070 /*
1071 * due to ddr3 dimm is fly-by topology
1072 * we suggest to enable write leveling to
1073 * meet the tQDSS under different loading.
1074 */
1075 popts->wrlvl_en = 1;
york1714e492010-07-02 22:25:56 +00001076 popts->zq_en = 1;
Dave Liu64ee7df2009-12-16 10:24:37 -06001077 popts->wrlvl_override = 0;
Kumar Gala124b0822008-08-26 15:01:29 -05001078#endif
1079
Kumar Gala124b0822008-08-26 15:01:29 -05001080 /*
Haiying Wangb834f922008-10-03 12:37:10 -04001081 * Check interleaving configuration from environment.
1082 * Please refer to doc/README.fsl-ddr for the detail.
Kumar Gala124b0822008-08-26 15:01:29 -05001083 *
1084 * If memory controller interleaving is enabled, then the data
york93799ca2010-07-02 22:25:52 +00001085 * bus widths must be programmed identically for all memory controllers.
Haiying Wangb834f922008-10-03 12:37:10 -04001086 *
York Sunc459ae62014-02-10 13:59:44 -08001087 * Attempt to set all controllers to the same chip select
Haiying Wangb834f922008-10-03 12:37:10 -04001088 * interleaving mode. It will do a best effort to get the
1089 * requested ranks interleaved together such that the result
1090 * should be a subset of the requested configuration.
York Sunc459ae62014-02-10 13:59:44 -08001091 *
1092 * if CONFIG_SYS_FSL_DDR_INTLV_256B is defined, mandatory interleaving
1093 * with 256 Byte is enabled.
Kumar Gala124b0822008-08-26 15:01:29 -05001094 */
York Sunfe845072016-12-28 08:43:45 -08001095#if (CONFIG_SYS_NUM_DDR_CTLRS > 1)
York Sune8dc17b2012-08-17 08:22:39 +00001096 if (!hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf))
York Sunc459ae62014-02-10 13:59:44 -08001097#ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
1098 ;
1099#else
York Sune8dc17b2012-08-17 08:22:39 +00001100 goto done;
York Sunc459ae62014-02-10 13:59:44 -08001101#endif
York Sune8dc17b2012-08-17 08:22:39 +00001102 if (pdimm[0].n_ranks == 0) {
1103 printf("There is no rank on CS0 for controller %d.\n", ctrl_num);
1104 popts->memctl_interleaving = 0;
1105 goto done;
1106 }
1107 popts->memctl_interleaving = 1;
York Sunc459ae62014-02-10 13:59:44 -08001108#ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
1109 popts->memctl_interleaving_mode = FSL_DDR_256B_INTERLEAVING;
1110 popts->memctl_interleaving = 1;
1111 debug("256 Byte interleaving\n");
York Sunedbeee12014-04-01 14:20:49 -07001112#else
York Sune8dc17b2012-08-17 08:22:39 +00001113 /*
1114 * test null first. if CONFIG_HWCONFIG is not defined
1115 * hwconfig_arg_cmp returns non-zero
1116 */
1117 if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
1118 "null", buf)) {
1119 popts->memctl_interleaving = 0;
1120 debug("memory controller interleaving disabled.\n");
1121 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1122 "ctlr_intlv",
1123 "cacheline", buf)) {
1124 popts->memctl_interleaving_mode =
York Sunfe845072016-12-28 08:43:45 -08001125 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001126 0 : FSL_DDR_CACHE_LINE_INTERLEAVING;
1127 popts->memctl_interleaving =
York Sunfe845072016-12-28 08:43:45 -08001128 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001129 0 : 1;
1130 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1131 "ctlr_intlv",
1132 "page", buf)) {
1133 popts->memctl_interleaving_mode =
York Sunfe845072016-12-28 08:43:45 -08001134 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001135 0 : FSL_DDR_PAGE_INTERLEAVING;
1136 popts->memctl_interleaving =
York Sunfe845072016-12-28 08:43:45 -08001137 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001138 0 : 1;
1139 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1140 "ctlr_intlv",
1141 "bank", buf)) {
1142 popts->memctl_interleaving_mode =
York Sunfe845072016-12-28 08:43:45 -08001143 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001144 0 : FSL_DDR_BANK_INTERLEAVING;
1145 popts->memctl_interleaving =
York Sunfe845072016-12-28 08:43:45 -08001146 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001147 0 : 1;
1148 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1149 "ctlr_intlv",
1150 "superbank", buf)) {
1151 popts->memctl_interleaving_mode =
York Sunfe845072016-12-28 08:43:45 -08001152 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001153 0 : FSL_DDR_SUPERBANK_INTERLEAVING;
1154 popts->memctl_interleaving =
York Sunfe845072016-12-28 08:43:45 -08001155 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001156 0 : 1;
York Sunfe845072016-12-28 08:43:45 -08001157#if (CONFIG_SYS_NUM_DDR_CTLRS == 3)
York Sune8dc17b2012-08-17 08:22:39 +00001158 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1159 "ctlr_intlv",
1160 "3way_1KB", buf)) {
1161 popts->memctl_interleaving_mode =
1162 FSL_DDR_3WAY_1KB_INTERLEAVING;
1163 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1164 "ctlr_intlv",
1165 "3way_4KB", buf)) {
1166 popts->memctl_interleaving_mode =
1167 FSL_DDR_3WAY_4KB_INTERLEAVING;
1168 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1169 "ctlr_intlv",
1170 "3way_8KB", buf)) {
1171 popts->memctl_interleaving_mode =
1172 FSL_DDR_3WAY_8KB_INTERLEAVING;
York Sunfe845072016-12-28 08:43:45 -08001173#elif (CONFIG_SYS_NUM_DDR_CTLRS == 4)
York Sune8dc17b2012-08-17 08:22:39 +00001174 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1175 "ctlr_intlv",
1176 "4way_1KB", buf)) {
1177 popts->memctl_interleaving_mode =
1178 FSL_DDR_4WAY_1KB_INTERLEAVING;
1179 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1180 "ctlr_intlv",
1181 "4way_4KB", buf)) {
1182 popts->memctl_interleaving_mode =
1183 FSL_DDR_4WAY_4KB_INTERLEAVING;
1184 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1185 "ctlr_intlv",
1186 "4way_8KB", buf)) {
1187 popts->memctl_interleaving_mode =
1188 FSL_DDR_4WAY_8KB_INTERLEAVING;
1189#endif
1190 } else {
1191 popts->memctl_interleaving = 0;
1192 printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
Haiying Wangb834f922008-10-03 12:37:10 -04001193 }
York Sunedbeee12014-04-01 14:20:49 -07001194#endif /* CONFIG_SYS_FSL_DDR_INTLV_256B */
York Sune8dc17b2012-08-17 08:22:39 +00001195done:
York Sunfe845072016-12-28 08:43:45 -08001196#endif /* CONFIG_SYS_NUM_DDR_CTLRS > 1 */
Kumar Gala72301602011-01-09 11:37:00 -06001197 if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) &&
Dave Liu0f9318f2009-11-12 07:26:37 +08001198 (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) {
Kumar Gala64042092010-07-14 10:04:21 -05001199 /* test null first. if CONFIG_HWCONFIG is not defined,
Kumar Gala72301602011-01-09 11:37:00 -06001200 * hwconfig_subarg_cmp_f returns non-zero */
1201 if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1202 "null", buf))
york93799ca2010-07-02 22:25:52 +00001203 debug("bank interleaving disabled.\n");
Kumar Gala72301602011-01-09 11:37:00 -06001204 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1205 "cs0_cs1", buf))
Haiying Wangb834f922008-10-03 12:37:10 -04001206 popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
Kumar Gala72301602011-01-09 11:37:00 -06001207 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1208 "cs2_cs3", buf))
Haiying Wangb834f922008-10-03 12:37:10 -04001209 popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
Kumar Gala72301602011-01-09 11:37:00 -06001210 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1211 "cs0_cs1_and_cs2_cs3", buf))
Haiying Wangb834f922008-10-03 12:37:10 -04001212 popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
Kumar Gala72301602011-01-09 11:37:00 -06001213 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1214 "cs0_cs1_cs2_cs3", buf))
Haiying Wangb834f922008-10-03 12:37:10 -04001215 popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
York Sund01babd2012-10-08 07:44:27 +00001216 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1217 "auto", buf))
1218 popts->ba_intlv_ctl = auto_bank_intlv(pdimm);
Haiying Wangb834f922008-10-03 12:37:10 -04001219 else
york93799ca2010-07-02 22:25:52 +00001220 printf("hwconfig has unrecognized parameter for bank_intlv.\n");
Haiying Wangb834f922008-10-03 12:37:10 -04001221 switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
1222 case FSL_DDR_CS0_CS1_CS2_CS3:
york93799ca2010-07-02 22:25:52 +00001223#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
yorkf4f93c62010-07-02 22:25:53 +00001224 if (pdimm[0].n_ranks < 4) {
york93799ca2010-07-02 22:25:52 +00001225 popts->ba_intlv_ctl = 0;
1226 printf("Not enough bank(chip-select) for "
1227 "CS0+CS1+CS2+CS3 on controller %d, "
York Sune8dc17b2012-08-17 08:22:39 +00001228 "interleaving disabled!\n", ctrl_num);
york93799ca2010-07-02 22:25:52 +00001229 }
1230#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
York Sun98df4d12012-10-08 07:44:23 +00001231#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
1232 if (pdimm[0].n_ranks == 4)
1233 break;
1234#endif
yorkf4f93c62010-07-02 22:25:53 +00001235 if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) {
york93799ca2010-07-02 22:25:52 +00001236 popts->ba_intlv_ctl = 0;
1237 printf("Not enough bank(chip-select) for "
1238 "CS0+CS1+CS2+CS3 on controller %d, "
York Sune8dc17b2012-08-17 08:22:39 +00001239 "interleaving disabled!\n", ctrl_num);
york93799ca2010-07-02 22:25:52 +00001240 }
1241 if (pdimm[0].capacity != pdimm[1].capacity) {
1242 popts->ba_intlv_ctl = 0;
1243 printf("Not identical DIMM size for "
1244 "CS0+CS1+CS2+CS3 on controller %d, "
York Sune8dc17b2012-08-17 08:22:39 +00001245 "interleaving disabled!\n", ctrl_num);
york93799ca2010-07-02 22:25:52 +00001246 }
1247#endif
1248 break;
Haiying Wangb834f922008-10-03 12:37:10 -04001249 case FSL_DDR_CS0_CS1:
yorkf4f93c62010-07-02 22:25:53 +00001250 if (pdimm[0].n_ranks < 2) {
Haiying Wangb834f922008-10-03 12:37:10 -04001251 popts->ba_intlv_ctl = 0;
Ed Swarthoutb135d932008-10-29 09:21:44 -05001252 printf("Not enough bank(chip-select) for "
york93799ca2010-07-02 22:25:52 +00001253 "CS0+CS1 on controller %d, "
York Sune8dc17b2012-08-17 08:22:39 +00001254 "interleaving disabled!\n", ctrl_num);
Haiying Wangb834f922008-10-03 12:37:10 -04001255 }
1256 break;
1257 case FSL_DDR_CS2_CS3:
york93799ca2010-07-02 22:25:52 +00001258#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
yorkf4f93c62010-07-02 22:25:53 +00001259 if (pdimm[0].n_ranks < 4) {
Haiying Wangb834f922008-10-03 12:37:10 -04001260 popts->ba_intlv_ctl = 0;
york93799ca2010-07-02 22:25:52 +00001261 printf("Not enough bank(chip-select) for CS2+CS3 "
York Sune8dc17b2012-08-17 08:22:39 +00001262 "on controller %d, interleaving disabled!\n", ctrl_num);
Haiying Wangb834f922008-10-03 12:37:10 -04001263 }
york93799ca2010-07-02 22:25:52 +00001264#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
yorkf4f93c62010-07-02 22:25:53 +00001265 if (pdimm[1].n_ranks < 2) {
york93799ca2010-07-02 22:25:52 +00001266 popts->ba_intlv_ctl = 0;
1267 printf("Not enough bank(chip-select) for CS2+CS3 "
York Sune8dc17b2012-08-17 08:22:39 +00001268 "on controller %d, interleaving disabled!\n", ctrl_num);
york93799ca2010-07-02 22:25:52 +00001269 }
1270#endif
Haiying Wangb834f922008-10-03 12:37:10 -04001271 break;
1272 case FSL_DDR_CS0_CS1_AND_CS2_CS3:
york93799ca2010-07-02 22:25:52 +00001273#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
yorkf4f93c62010-07-02 22:25:53 +00001274 if (pdimm[0].n_ranks < 4) {
york93799ca2010-07-02 22:25:52 +00001275 popts->ba_intlv_ctl = 0;
1276 printf("Not enough bank(CS) for CS0+CS1 and "
1277 "CS2+CS3 on controller %d, "
York Sune8dc17b2012-08-17 08:22:39 +00001278 "interleaving disabled!\n", ctrl_num);
york93799ca2010-07-02 22:25:52 +00001279 }
1280#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
yorkf4f93c62010-07-02 22:25:53 +00001281 if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) {
Haiying Wangb834f922008-10-03 12:37:10 -04001282 popts->ba_intlv_ctl = 0;
york93799ca2010-07-02 22:25:52 +00001283 printf("Not enough bank(CS) for CS0+CS1 and "
1284 "CS2+CS3 on controller %d, "
York Sune8dc17b2012-08-17 08:22:39 +00001285 "interleaving disabled!\n", ctrl_num);
Haiying Wangb834f922008-10-03 12:37:10 -04001286 }
york93799ca2010-07-02 22:25:52 +00001287#endif
Haiying Wangb834f922008-10-03 12:37:10 -04001288 break;
1289 default:
1290 popts->ba_intlv_ctl = 0;
1291 break;
1292 }
1293 }
Kumar Gala124b0822008-08-26 15:01:29 -05001294
Kumar Gala72301602011-01-09 11:37:00 -06001295 if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf)) {
1296 if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf))
york42603722010-07-02 22:25:54 +00001297 popts->addr_hash = 0;
Kumar Gala72301602011-01-09 11:37:00 -06001298 else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash",
1299 "true", buf))
york42603722010-07-02 22:25:54 +00001300 popts->addr_hash = 1;
1301 }
1302
yorkf4f93c62010-07-02 22:25:53 +00001303 if (pdimm[0].n_ranks == 4)
1304 popts->quad_rank_present = 1;
1305
York Sun6db4fdd2018-01-29 09:44:35 -08001306 popts->package_3ds = pdimm->package_3ds;
1307
Tom Rini364d0022023-01-10 11:19:45 -05001308#if (CFG_FSL_SDRAM_TYPE != SDRAM_TYPE_DDR4)
York Sun2c0b62d2015-01-06 13:18:50 -08001309 ddr_freq = get_ddr_freq(ctrl_num) / 1000000;
York Sunf0345e22011-08-24 09:40:26 -07001310 if (popts->registered_dimm_en) {
1311 popts->rcw_override = 1;
1312 popts->rcw_1 = 0x000a5a00;
1313 if (ddr_freq <= 800)
1314 popts->rcw_2 = 0x00000000;
1315 else if (ddr_freq <= 1066)
1316 popts->rcw_2 = 0x00100000;
1317 else if (ddr_freq <= 1333)
1318 popts->rcw_2 = 0x00200000;
1319 else
1320 popts->rcw_2 = 0x00300000;
1321 }
York Sunbc2f32a2018-01-29 10:24:08 -08001322#endif
York Sunf0345e22011-08-24 09:40:26 -07001323
Haiying Wangfa440362008-10-03 12:36:55 -04001324 fsl_ddr_board_options(popts, pdimm, ctrl_num);
Kumar Gala124b0822008-08-26 15:01:29 -05001325
1326 return 0;
1327}
york93799ca2010-07-02 22:25:52 +00001328
1329void check_interleaving_options(fsl_ddr_info_t *pinfo)
1330{
York Sune8dc17b2012-08-17 08:22:39 +00001331 int i, j, k, check_n_ranks, intlv_invalid = 0;
1332 unsigned int check_intlv, check_n_row_addr, check_n_col_addr;
york93799ca2010-07-02 22:25:52 +00001333 unsigned long long check_rank_density;
York Sune8dc17b2012-08-17 08:22:39 +00001334 struct dimm_params_s *dimm;
York Sun79a779b2014-08-01 15:51:00 -07001335 int first_ctrl = pinfo->first_ctrl;
1336 int last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
1337
york93799ca2010-07-02 22:25:52 +00001338 /*
1339 * Check if all controllers are configured for memory
1340 * controller interleaving. Identical dimms are recommended. At least
York Sune8dc17b2012-08-17 08:22:39 +00001341 * the size, row and col address should be checked.
york93799ca2010-07-02 22:25:52 +00001342 */
1343 j = 0;
York Sun79a779b2014-08-01 15:51:00 -07001344 check_n_ranks = pinfo->dimm_params[first_ctrl][0].n_ranks;
1345 check_rank_density = pinfo->dimm_params[first_ctrl][0].rank_density;
1346 check_n_row_addr = pinfo->dimm_params[first_ctrl][0].n_row_addr;
1347 check_n_col_addr = pinfo->dimm_params[first_ctrl][0].n_col_addr;
1348 check_intlv = pinfo->memctl_opts[first_ctrl].memctl_interleaving_mode;
1349 for (i = first_ctrl; i <= last_ctrl; i++) {
York Sune8dc17b2012-08-17 08:22:39 +00001350 dimm = &pinfo->dimm_params[i][0];
1351 if (!pinfo->memctl_opts[i].memctl_interleaving) {
1352 continue;
1353 } else if (((check_rank_density != dimm->rank_density) ||
1354 (check_n_ranks != dimm->n_ranks) ||
1355 (check_n_row_addr != dimm->n_row_addr) ||
1356 (check_n_col_addr != dimm->n_col_addr) ||
1357 (check_intlv !=
1358 pinfo->memctl_opts[i].memctl_interleaving_mode))){
1359 intlv_invalid = 1;
1360 break;
1361 } else {
york93799ca2010-07-02 22:25:52 +00001362 j++;
1363 }
York Sune8dc17b2012-08-17 08:22:39 +00001364
york93799ca2010-07-02 22:25:52 +00001365 }
York Sune8dc17b2012-08-17 08:22:39 +00001366 if (intlv_invalid) {
York Sun79a779b2014-08-01 15:51:00 -07001367 for (i = first_ctrl; i <= last_ctrl; i++)
York Sune8dc17b2012-08-17 08:22:39 +00001368 pinfo->memctl_opts[i].memctl_interleaving = 0;
1369 printf("Not all DIMMs are identical. "
1370 "Memory controller interleaving disabled.\n");
1371 } else {
1372 switch (check_intlv) {
York Sunc459ae62014-02-10 13:59:44 -08001373 case FSL_DDR_256B_INTERLEAVING:
York Sune8dc17b2012-08-17 08:22:39 +00001374 case FSL_DDR_CACHE_LINE_INTERLEAVING:
1375 case FSL_DDR_PAGE_INTERLEAVING:
1376 case FSL_DDR_BANK_INTERLEAVING:
1377 case FSL_DDR_SUPERBANK_INTERLEAVING:
York Sunfe845072016-12-28 08:43:45 -08001378#if (3 == CONFIG_SYS_NUM_DDR_CTLRS)
York Sune8dc17b2012-08-17 08:22:39 +00001379 k = 2;
York Sunedbeee12014-04-01 14:20:49 -07001380#else
York Sunfe845072016-12-28 08:43:45 -08001381 k = CONFIG_SYS_NUM_DDR_CTLRS;
York Sunedbeee12014-04-01 14:20:49 -07001382#endif
York Sune8dc17b2012-08-17 08:22:39 +00001383 break;
1384 case FSL_DDR_3WAY_1KB_INTERLEAVING:
1385 case FSL_DDR_3WAY_4KB_INTERLEAVING:
1386 case FSL_DDR_3WAY_8KB_INTERLEAVING:
1387 case FSL_DDR_4WAY_1KB_INTERLEAVING:
1388 case FSL_DDR_4WAY_4KB_INTERLEAVING:
1389 case FSL_DDR_4WAY_8KB_INTERLEAVING:
1390 default:
York Sunfe845072016-12-28 08:43:45 -08001391 k = CONFIG_SYS_NUM_DDR_CTLRS;
York Sune8dc17b2012-08-17 08:22:39 +00001392 break;
1393 }
1394 debug("%d of %d controllers are interleaving.\n", j, k);
York Sund01babd2012-10-08 07:44:27 +00001395 if (j && (j != k)) {
York Sun79a779b2014-08-01 15:51:00 -07001396 for (i = first_ctrl; i <= last_ctrl; i++)
york93799ca2010-07-02 22:25:52 +00001397 pinfo->memctl_opts[i].memctl_interleaving = 0;
York Sun79a779b2014-08-01 15:51:00 -07001398 if ((last_ctrl - first_ctrl) > 1)
1399 puts("Not all controllers have compatible interleaving mode. All disabled.\n");
York Sune8dc17b2012-08-17 08:22:39 +00001400 }
york93799ca2010-07-02 22:25:52 +00001401 }
York Sune8dc17b2012-08-17 08:22:39 +00001402 debug("Checking interleaving options completed\n");
york93799ca2010-07-02 22:25:52 +00001403}
Kumar Galaf582d982011-01-09 14:06:28 -06001404
1405int fsl_use_spd(void)
1406{
1407 int use_spd = 0;
1408
1409#ifdef CONFIG_DDR_SPD
Jeremy Gebben1a491e82018-07-20 16:00:36 -06001410 char buf[HWCONFIG_BUFFER_SIZE];
Kumar Gala72301602011-01-09 11:37:00 -06001411
1412 /*
1413 * Extract hwconfig from environment since we have not properly setup
1414 * the environment but need it for ddr config params
1415 */
Pali Rohár654ec602022-04-03 00:24:26 +02001416#if CONFIG_IS_ENABLED(ENV_SUPPORT)
Jeremy Gebben1a491e82018-07-20 16:00:36 -06001417 if (env_get_f("hwconfig", buf, sizeof(buf)) < 0)
Pali Rohár654ec602022-04-03 00:24:26 +02001418#endif
Jeremy Gebben1a491e82018-07-20 16:00:36 -06001419 buf[0] = '\0';
Kumar Gala72301602011-01-09 11:37:00 -06001420
Kumar Galaf582d982011-01-09 14:06:28 -06001421 /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
Kumar Gala72301602011-01-09 11:37:00 -06001422 if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) {
1423 if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf))
Kumar Galaf582d982011-01-09 14:06:28 -06001424 use_spd = 1;
Kumar Gala72301602011-01-09 11:37:00 -06001425 else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram",
1426 "fixed", buf))
Kumar Galaf582d982011-01-09 14:06:28 -06001427 use_spd = 0;
1428 else
1429 use_spd = 1;
1430 } else
1431 use_spd = 1;
1432#endif
1433
1434 return use_spd;
1435}