blob: 4573ffa11517c11a5df24248cbd2903126a7559d [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
7#include <common.h>
Kumar Gala64042092010-07-14 10:04:21 -05008#include <hwconfig.h>
York Sunf0626592013-09-30 09:22:09 -07009#include <fsl_ddr_sdram.h>
Kumar Gala124b0822008-08-26 15:01:29 -050010
York Sunf0626592013-09-30 09:22:09 -070011#include <fsl_ddr.h>
Simon Glass89e0a3a2017-05-17 08:23:10 -060012#if defined(CONFIG_FSL_LSCH2) || defined(CONFIG_FSL_LSCH3) || \
13 defined(CONFIG_ARM)
Simon Glass243182c2017-05-17 08:23:06 -060014#include <asm/arch/clock.h>
15#endif
Kumar Gala124b0822008-08-26 15:01:29 -050016
Kumar Gala72301602011-01-09 11:37:00 -060017/*
18 * Use our own stack based buffer before relocation to allow accessing longer
19 * hwconfig strings that might be in the environment before we've relocated.
20 * This is pretty fragile on both the use of stack and if the buffer is big
Simon Glass64b723f2017-08-03 12:22:12 -060021 * enough. However we will get a warning from env_get_f() for the latter.
Kumar Gala72301602011-01-09 11:37:00 -060022 */
Kumar Gala72301602011-01-09 11:37:00 -060023
Kumar Gala124b0822008-08-26 15:01:29 -050024/* Board-specific functions defined in each board's ddr.c */
Priyanka Jain419ffc92018-10-29 09:37:36 +000025void __weak fsl_ddr_board_options(memctl_options_t *popts,
26 dimm_params_t *pdimm,
27 unsigned int ctrl_num)
28{
29 return;
30}
Kumar Gala124b0822008-08-26 15:01:29 -050031
York Sun454f5072011-08-26 11:32:43 -070032struct dynamic_odt {
York Sunba0c2eb2011-01-10 12:03:00 +000033 unsigned int odt_rd_cfg;
34 unsigned int odt_wr_cfg;
35 unsigned int odt_rtt_norm;
36 unsigned int odt_rtt_wr;
York Sun454f5072011-08-26 11:32:43 -070037};
York Sunba0c2eb2011-01-10 12:03:00 +000038
York Sun5cb12f62015-11-04 10:03:17 -080039#ifdef CONFIG_SYS_FSL_DDR4
40/* Quad rank is not verified yet due availability.
41 * Replacing 20 OHM with 34 OHM since DDR4 doesn't have 20 OHM option
42 */
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -070043static __maybe_unused const struct dynamic_odt single_Q[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +000044 { /* cs0 */
45 FSL_DDR_ODT_NEVER,
46 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
York Sun5cb12f62015-11-04 10:03:17 -080047 DDR4_RTT_34_OHM, /* unverified */
48 DDR4_RTT_120_OHM
49 },
50 { /* cs1 */
51 FSL_DDR_ODT_NEVER,
52 FSL_DDR_ODT_NEVER,
53 DDR4_RTT_OFF,
54 DDR4_RTT_120_OHM
55 },
56 { /* cs2 */
57 FSL_DDR_ODT_NEVER,
58 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
59 DDR4_RTT_34_OHM,
60 DDR4_RTT_120_OHM
61 },
62 { /* cs3 */
63 FSL_DDR_ODT_NEVER,
64 FSL_DDR_ODT_NEVER, /* tied high */
65 DDR4_RTT_OFF,
66 DDR4_RTT_120_OHM
67 }
68};
69
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -070070static __maybe_unused const struct dynamic_odt single_D[4] = {
York Sun5cb12f62015-11-04 10:03:17 -080071 { /* cs0 */
72 FSL_DDR_ODT_NEVER,
73 FSL_DDR_ODT_ALL,
74 DDR4_RTT_40_OHM,
75 DDR4_RTT_OFF
76 },
77 { /* cs1 */
78 FSL_DDR_ODT_NEVER,
79 FSL_DDR_ODT_NEVER,
80 DDR4_RTT_OFF,
81 DDR4_RTT_OFF
82 },
83 {0, 0, 0, 0},
84 {0, 0, 0, 0}
85};
86
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -070087static __maybe_unused const struct dynamic_odt single_S[4] = {
York Sun5cb12f62015-11-04 10:03:17 -080088 { /* cs0 */
89 FSL_DDR_ODT_NEVER,
90 FSL_DDR_ODT_ALL,
91 DDR4_RTT_40_OHM,
92 DDR4_RTT_OFF
93 },
94 {0, 0, 0, 0},
95 {0, 0, 0, 0},
96 {0, 0, 0, 0},
97};
98
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -070099static __maybe_unused const struct dynamic_odt dual_DD[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800100 { /* cs0 */
101 FSL_DDR_ODT_NEVER,
102 FSL_DDR_ODT_SAME_DIMM,
103 DDR4_RTT_120_OHM,
104 DDR4_RTT_OFF
105 },
106 { /* cs1 */
107 FSL_DDR_ODT_OTHER_DIMM,
108 FSL_DDR_ODT_OTHER_DIMM,
109 DDR4_RTT_34_OHM,
110 DDR4_RTT_OFF
111 },
112 { /* cs2 */
113 FSL_DDR_ODT_NEVER,
114 FSL_DDR_ODT_SAME_DIMM,
115 DDR4_RTT_120_OHM,
116 DDR4_RTT_OFF
117 },
118 { /* cs3 */
119 FSL_DDR_ODT_OTHER_DIMM,
120 FSL_DDR_ODT_OTHER_DIMM,
121 DDR4_RTT_34_OHM,
122 DDR4_RTT_OFF
123 }
124};
125
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700126static __maybe_unused const struct dynamic_odt dual_DS[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800127 { /* cs0 */
128 FSL_DDR_ODT_NEVER,
129 FSL_DDR_ODT_SAME_DIMM,
130 DDR4_RTT_120_OHM,
131 DDR4_RTT_OFF
132 },
133 { /* cs1 */
134 FSL_DDR_ODT_OTHER_DIMM,
135 FSL_DDR_ODT_OTHER_DIMM,
136 DDR4_RTT_34_OHM,
137 DDR4_RTT_OFF
138 },
139 { /* cs2 */
140 FSL_DDR_ODT_OTHER_DIMM,
141 FSL_DDR_ODT_ALL,
142 DDR4_RTT_34_OHM,
143 DDR4_RTT_120_OHM
144 },
145 {0, 0, 0, 0}
146};
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700147static __maybe_unused const struct dynamic_odt dual_SD[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800148 { /* cs0 */
149 FSL_DDR_ODT_OTHER_DIMM,
150 FSL_DDR_ODT_ALL,
151 DDR4_RTT_34_OHM,
152 DDR4_RTT_120_OHM
153 },
154 {0, 0, 0, 0},
155 { /* cs2 */
156 FSL_DDR_ODT_NEVER,
157 FSL_DDR_ODT_SAME_DIMM,
158 DDR4_RTT_120_OHM,
159 DDR4_RTT_OFF
160 },
161 { /* cs3 */
162 FSL_DDR_ODT_OTHER_DIMM,
163 FSL_DDR_ODT_OTHER_DIMM,
164 DDR4_RTT_34_OHM,
165 DDR4_RTT_OFF
166 }
167};
168
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700169static __maybe_unused const struct dynamic_odt dual_SS[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800170 { /* cs0 */
171 FSL_DDR_ODT_OTHER_DIMM,
172 FSL_DDR_ODT_ALL,
173 DDR4_RTT_34_OHM,
174 DDR4_RTT_120_OHM
175 },
176 {0, 0, 0, 0},
177 { /* cs2 */
178 FSL_DDR_ODT_OTHER_DIMM,
179 FSL_DDR_ODT_ALL,
180 DDR4_RTT_34_OHM,
181 DDR4_RTT_120_OHM
182 },
183 {0, 0, 0, 0}
184};
185
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700186static __maybe_unused const struct dynamic_odt dual_D0[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800187 { /* cs0 */
188 FSL_DDR_ODT_NEVER,
189 FSL_DDR_ODT_SAME_DIMM,
190 DDR4_RTT_40_OHM,
191 DDR4_RTT_OFF
192 },
193 { /* cs1 */
194 FSL_DDR_ODT_NEVER,
195 FSL_DDR_ODT_NEVER,
196 DDR4_RTT_OFF,
197 DDR4_RTT_OFF
198 },
199 {0, 0, 0, 0},
200 {0, 0, 0, 0}
201};
202
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700203static __maybe_unused const struct dynamic_odt dual_0D[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800204 {0, 0, 0, 0},
205 {0, 0, 0, 0},
206 { /* cs2 */
207 FSL_DDR_ODT_NEVER,
208 FSL_DDR_ODT_SAME_DIMM,
209 DDR4_RTT_40_OHM,
210 DDR4_RTT_OFF
211 },
212 { /* cs3 */
213 FSL_DDR_ODT_NEVER,
214 FSL_DDR_ODT_NEVER,
215 DDR4_RTT_OFF,
216 DDR4_RTT_OFF
217 }
218};
219
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700220static __maybe_unused const struct dynamic_odt dual_S0[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800221 { /* cs0 */
222 FSL_DDR_ODT_NEVER,
223 FSL_DDR_ODT_CS,
224 DDR4_RTT_40_OHM,
225 DDR4_RTT_OFF
226 },
227 {0, 0, 0, 0},
228 {0, 0, 0, 0},
229 {0, 0, 0, 0}
230
231};
232
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700233static __maybe_unused const struct dynamic_odt dual_0S[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800234 {0, 0, 0, 0},
235 {0, 0, 0, 0},
236 { /* cs2 */
237 FSL_DDR_ODT_NEVER,
238 FSL_DDR_ODT_CS,
239 DDR4_RTT_40_OHM,
240 DDR4_RTT_OFF
241 },
242 {0, 0, 0, 0}
243
244};
245
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700246static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800247 { /* cs0 */
248 FSL_DDR_ODT_NEVER,
249 FSL_DDR_ODT_CS,
250 DDR4_RTT_120_OHM,
251 DDR4_RTT_OFF
252 },
253 { /* cs1 */
254 FSL_DDR_ODT_NEVER,
255 FSL_DDR_ODT_CS,
256 DDR4_RTT_120_OHM,
257 DDR4_RTT_OFF
258 },
259 { /* cs2 */
260 FSL_DDR_ODT_NEVER,
261 FSL_DDR_ODT_CS,
262 DDR4_RTT_120_OHM,
263 DDR4_RTT_OFF
264 },
265 { /* cs3 */
266 FSL_DDR_ODT_NEVER,
267 FSL_DDR_ODT_CS,
268 DDR4_RTT_120_OHM,
269 DDR4_RTT_OFF
270 }
271};
272#elif defined(CONFIG_SYS_FSL_DDR3)
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700273static __maybe_unused const struct dynamic_odt single_Q[4] = {
York Sun5cb12f62015-11-04 10:03:17 -0800274 { /* cs0 */
275 FSL_DDR_ODT_NEVER,
276 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
York Sunba0c2eb2011-01-10 12:03:00 +0000277 DDR3_RTT_20_OHM,
278 DDR3_RTT_120_OHM
279 },
280 { /* cs1 */
281 FSL_DDR_ODT_NEVER,
282 FSL_DDR_ODT_NEVER, /* tied high */
283 DDR3_RTT_OFF,
284 DDR3_RTT_120_OHM
285 },
286 { /* cs2 */
287 FSL_DDR_ODT_NEVER,
288 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
289 DDR3_RTT_20_OHM,
290 DDR3_RTT_120_OHM
291 },
292 { /* cs3 */
293 FSL_DDR_ODT_NEVER,
294 FSL_DDR_ODT_NEVER, /* tied high */
295 DDR3_RTT_OFF,
296 DDR3_RTT_120_OHM
297 }
298};
299
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700300static __maybe_unused const struct dynamic_odt single_D[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000301 { /* cs0 */
302 FSL_DDR_ODT_NEVER,
303 FSL_DDR_ODT_ALL,
304 DDR3_RTT_40_OHM,
305 DDR3_RTT_OFF
306 },
307 { /* cs1 */
308 FSL_DDR_ODT_NEVER,
309 FSL_DDR_ODT_NEVER,
310 DDR3_RTT_OFF,
311 DDR3_RTT_OFF
312 },
313 {0, 0, 0, 0},
314 {0, 0, 0, 0}
315};
316
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700317static __maybe_unused const struct dynamic_odt single_S[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000318 { /* cs0 */
319 FSL_DDR_ODT_NEVER,
320 FSL_DDR_ODT_ALL,
321 DDR3_RTT_40_OHM,
322 DDR3_RTT_OFF
323 },
324 {0, 0, 0, 0},
325 {0, 0, 0, 0},
326 {0, 0, 0, 0},
327};
328
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700329static __maybe_unused const struct dynamic_odt dual_DD[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000330 { /* cs0 */
331 FSL_DDR_ODT_NEVER,
332 FSL_DDR_ODT_SAME_DIMM,
333 DDR3_RTT_120_OHM,
334 DDR3_RTT_OFF
335 },
336 { /* cs1 */
337 FSL_DDR_ODT_OTHER_DIMM,
338 FSL_DDR_ODT_OTHER_DIMM,
339 DDR3_RTT_30_OHM,
340 DDR3_RTT_OFF
341 },
342 { /* cs2 */
343 FSL_DDR_ODT_NEVER,
344 FSL_DDR_ODT_SAME_DIMM,
345 DDR3_RTT_120_OHM,
346 DDR3_RTT_OFF
347 },
348 { /* cs3 */
349 FSL_DDR_ODT_OTHER_DIMM,
350 FSL_DDR_ODT_OTHER_DIMM,
351 DDR3_RTT_30_OHM,
352 DDR3_RTT_OFF
353 }
354};
355
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700356static __maybe_unused const struct dynamic_odt dual_DS[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000357 { /* cs0 */
358 FSL_DDR_ODT_NEVER,
359 FSL_DDR_ODT_SAME_DIMM,
360 DDR3_RTT_120_OHM,
361 DDR3_RTT_OFF
362 },
363 { /* cs1 */
364 FSL_DDR_ODT_OTHER_DIMM,
365 FSL_DDR_ODT_OTHER_DIMM,
366 DDR3_RTT_30_OHM,
367 DDR3_RTT_OFF
368 },
369 { /* cs2 */
370 FSL_DDR_ODT_OTHER_DIMM,
371 FSL_DDR_ODT_ALL,
372 DDR3_RTT_20_OHM,
373 DDR3_RTT_120_OHM
374 },
375 {0, 0, 0, 0}
376};
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700377static __maybe_unused const struct dynamic_odt dual_SD[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000378 { /* cs0 */
379 FSL_DDR_ODT_OTHER_DIMM,
380 FSL_DDR_ODT_ALL,
381 DDR3_RTT_20_OHM,
382 DDR3_RTT_120_OHM
383 },
384 {0, 0, 0, 0},
385 { /* cs2 */
386 FSL_DDR_ODT_NEVER,
387 FSL_DDR_ODT_SAME_DIMM,
388 DDR3_RTT_120_OHM,
389 DDR3_RTT_OFF
390 },
391 { /* cs3 */
392 FSL_DDR_ODT_OTHER_DIMM,
393 FSL_DDR_ODT_OTHER_DIMM,
394 DDR3_RTT_20_OHM,
395 DDR3_RTT_OFF
396 }
397};
398
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700399static __maybe_unused const struct dynamic_odt dual_SS[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000400 { /* cs0 */
401 FSL_DDR_ODT_OTHER_DIMM,
402 FSL_DDR_ODT_ALL,
403 DDR3_RTT_30_OHM,
404 DDR3_RTT_120_OHM
405 },
406 {0, 0, 0, 0},
407 { /* cs2 */
408 FSL_DDR_ODT_OTHER_DIMM,
409 FSL_DDR_ODT_ALL,
410 DDR3_RTT_30_OHM,
411 DDR3_RTT_120_OHM
412 },
413 {0, 0, 0, 0}
414};
415
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700416static __maybe_unused const struct dynamic_odt dual_D0[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000417 { /* cs0 */
418 FSL_DDR_ODT_NEVER,
419 FSL_DDR_ODT_SAME_DIMM,
420 DDR3_RTT_40_OHM,
421 DDR3_RTT_OFF
422 },
423 { /* cs1 */
424 FSL_DDR_ODT_NEVER,
425 FSL_DDR_ODT_NEVER,
426 DDR3_RTT_OFF,
427 DDR3_RTT_OFF
428 },
429 {0, 0, 0, 0},
430 {0, 0, 0, 0}
431};
432
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700433static __maybe_unused const struct dynamic_odt dual_0D[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000434 {0, 0, 0, 0},
435 {0, 0, 0, 0},
436 { /* cs2 */
437 FSL_DDR_ODT_NEVER,
438 FSL_DDR_ODT_SAME_DIMM,
439 DDR3_RTT_40_OHM,
440 DDR3_RTT_OFF
441 },
442 { /* cs3 */
443 FSL_DDR_ODT_NEVER,
444 FSL_DDR_ODT_NEVER,
445 DDR3_RTT_OFF,
446 DDR3_RTT_OFF
447 }
448};
449
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700450static __maybe_unused const struct dynamic_odt dual_S0[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000451 { /* cs0 */
452 FSL_DDR_ODT_NEVER,
453 FSL_DDR_ODT_CS,
454 DDR3_RTT_40_OHM,
455 DDR3_RTT_OFF
456 },
457 {0, 0, 0, 0},
458 {0, 0, 0, 0},
459 {0, 0, 0, 0}
460
461};
462
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700463static __maybe_unused const struct dynamic_odt dual_0S[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000464 {0, 0, 0, 0},
465 {0, 0, 0, 0},
466 { /* cs2 */
467 FSL_DDR_ODT_NEVER,
468 FSL_DDR_ODT_CS,
469 DDR3_RTT_40_OHM,
470 DDR3_RTT_OFF
471 },
472 {0, 0, 0, 0}
473
474};
475
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700476static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
York Sunba0c2eb2011-01-10 12:03:00 +0000477 { /* cs0 */
478 FSL_DDR_ODT_NEVER,
479 FSL_DDR_ODT_CS,
480 DDR3_RTT_120_OHM,
481 DDR3_RTT_OFF
482 },
483 { /* cs1 */
484 FSL_DDR_ODT_NEVER,
485 FSL_DDR_ODT_CS,
486 DDR3_RTT_120_OHM,
487 DDR3_RTT_OFF
488 },
489 { /* cs2 */
490 FSL_DDR_ODT_NEVER,
491 FSL_DDR_ODT_CS,
492 DDR3_RTT_120_OHM,
493 DDR3_RTT_OFF
494 },
495 { /* cs3 */
496 FSL_DDR_ODT_NEVER,
497 FSL_DDR_ODT_CS,
498 DDR3_RTT_120_OHM,
499 DDR3_RTT_OFF
500 }
501};
York Sun5cb12f62015-11-04 10:03:17 -0800502#else /* CONFIG_SYS_FSL_DDR3 */
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700503static __maybe_unused const struct dynamic_odt single_Q[4] = {
York Sun454f5072011-08-26 11:32:43 -0700504 {0, 0, 0, 0},
505 {0, 0, 0, 0},
506 {0, 0, 0, 0},
507 {0, 0, 0, 0}
508};
509
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700510static __maybe_unused const struct dynamic_odt single_D[4] = {
York Sun454f5072011-08-26 11:32:43 -0700511 { /* cs0 */
512 FSL_DDR_ODT_NEVER,
513 FSL_DDR_ODT_ALL,
514 DDR2_RTT_150_OHM,
515 DDR2_RTT_OFF
516 },
517 { /* cs1 */
518 FSL_DDR_ODT_NEVER,
519 FSL_DDR_ODT_NEVER,
520 DDR2_RTT_OFF,
521 DDR2_RTT_OFF
522 },
523 {0, 0, 0, 0},
524 {0, 0, 0, 0}
525};
526
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700527static __maybe_unused const struct dynamic_odt single_S[4] = {
York Sun454f5072011-08-26 11:32:43 -0700528 { /* cs0 */
529 FSL_DDR_ODT_NEVER,
530 FSL_DDR_ODT_ALL,
531 DDR2_RTT_150_OHM,
532 DDR2_RTT_OFF
533 },
534 {0, 0, 0, 0},
535 {0, 0, 0, 0},
536 {0, 0, 0, 0},
537};
538
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700539static __maybe_unused const struct dynamic_odt dual_DD[4] = {
York Sun454f5072011-08-26 11:32:43 -0700540 { /* cs0 */
541 FSL_DDR_ODT_OTHER_DIMM,
542 FSL_DDR_ODT_OTHER_DIMM,
543 DDR2_RTT_75_OHM,
544 DDR2_RTT_OFF
545 },
546 { /* cs1 */
547 FSL_DDR_ODT_NEVER,
548 FSL_DDR_ODT_NEVER,
549 DDR2_RTT_OFF,
550 DDR2_RTT_OFF
551 },
552 { /* cs2 */
553 FSL_DDR_ODT_OTHER_DIMM,
554 FSL_DDR_ODT_OTHER_DIMM,
555 DDR2_RTT_75_OHM,
556 DDR2_RTT_OFF
557 },
558 { /* cs3 */
559 FSL_DDR_ODT_NEVER,
560 FSL_DDR_ODT_NEVER,
561 DDR2_RTT_OFF,
562 DDR2_RTT_OFF
563 }
564};
565
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700566static __maybe_unused const struct dynamic_odt dual_DS[4] = {
York Sun454f5072011-08-26 11:32:43 -0700567 { /* cs0 */
568 FSL_DDR_ODT_OTHER_DIMM,
569 FSL_DDR_ODT_OTHER_DIMM,
570 DDR2_RTT_75_OHM,
571 DDR2_RTT_OFF
572 },
573 { /* cs1 */
574 FSL_DDR_ODT_NEVER,
575 FSL_DDR_ODT_NEVER,
576 DDR2_RTT_OFF,
577 DDR2_RTT_OFF
578 },
579 { /* cs2 */
580 FSL_DDR_ODT_OTHER_DIMM,
581 FSL_DDR_ODT_OTHER_DIMM,
582 DDR2_RTT_75_OHM,
583 DDR2_RTT_OFF
584 },
585 {0, 0, 0, 0}
586};
587
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700588static __maybe_unused const struct dynamic_odt dual_SD[4] = {
York Sun454f5072011-08-26 11:32:43 -0700589 { /* cs0 */
590 FSL_DDR_ODT_OTHER_DIMM,
591 FSL_DDR_ODT_OTHER_DIMM,
592 DDR2_RTT_75_OHM,
593 DDR2_RTT_OFF
594 },
595 {0, 0, 0, 0},
596 { /* cs2 */
597 FSL_DDR_ODT_OTHER_DIMM,
598 FSL_DDR_ODT_OTHER_DIMM,
599 DDR2_RTT_75_OHM,
600 DDR2_RTT_OFF
601 },
602 { /* cs3 */
603 FSL_DDR_ODT_NEVER,
604 FSL_DDR_ODT_NEVER,
605 DDR2_RTT_OFF,
606 DDR2_RTT_OFF
607 }
608};
609
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700610static __maybe_unused const struct dynamic_odt dual_SS[4] = {
York Sun454f5072011-08-26 11:32:43 -0700611 { /* cs0 */
612 FSL_DDR_ODT_OTHER_DIMM,
613 FSL_DDR_ODT_OTHER_DIMM,
614 DDR2_RTT_75_OHM,
615 DDR2_RTT_OFF
616 },
617 {0, 0, 0, 0},
618 { /* cs2 */
619 FSL_DDR_ODT_OTHER_DIMM,
620 FSL_DDR_ODT_OTHER_DIMM,
621 DDR2_RTT_75_OHM,
622 DDR2_RTT_OFF
623 },
624 {0, 0, 0, 0}
625};
626
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700627static __maybe_unused const struct dynamic_odt dual_D0[4] = {
York Sun454f5072011-08-26 11:32:43 -0700628 { /* cs0 */
629 FSL_DDR_ODT_NEVER,
630 FSL_DDR_ODT_ALL,
631 DDR2_RTT_150_OHM,
632 DDR2_RTT_OFF
633 },
634 { /* cs1 */
635 FSL_DDR_ODT_NEVER,
636 FSL_DDR_ODT_NEVER,
637 DDR2_RTT_OFF,
638 DDR2_RTT_OFF
639 },
640 {0, 0, 0, 0},
641 {0, 0, 0, 0}
642};
643
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700644static __maybe_unused const struct dynamic_odt dual_0D[4] = {
York Sun454f5072011-08-26 11:32:43 -0700645 {0, 0, 0, 0},
646 {0, 0, 0, 0},
647 { /* cs2 */
648 FSL_DDR_ODT_NEVER,
649 FSL_DDR_ODT_ALL,
650 DDR2_RTT_150_OHM,
651 DDR2_RTT_OFF
652 },
653 { /* cs3 */
654 FSL_DDR_ODT_NEVER,
655 FSL_DDR_ODT_NEVER,
656 DDR2_RTT_OFF,
657 DDR2_RTT_OFF
658 }
659};
York Sunba0c2eb2011-01-10 12:03:00 +0000660
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700661static __maybe_unused const struct dynamic_odt dual_S0[4] = {
York Sun454f5072011-08-26 11:32:43 -0700662 { /* cs0 */
663 FSL_DDR_ODT_NEVER,
664 FSL_DDR_ODT_CS,
665 DDR2_RTT_150_OHM,
666 DDR2_RTT_OFF
667 },
668 {0, 0, 0, 0},
669 {0, 0, 0, 0},
670 {0, 0, 0, 0}
671
672};
673
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700674static __maybe_unused const struct dynamic_odt dual_0S[4] = {
York Sun454f5072011-08-26 11:32:43 -0700675 {0, 0, 0, 0},
676 {0, 0, 0, 0},
677 { /* cs2 */
678 FSL_DDR_ODT_NEVER,
679 FSL_DDR_ODT_CS,
680 DDR2_RTT_150_OHM,
681 DDR2_RTT_OFF
682 },
683 {0, 0, 0, 0}
684
685};
686
Thomas Schaefer7d2e8e42017-03-28 11:29:56 -0700687static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
York Sun454f5072011-08-26 11:32:43 -0700688 { /* cs0 */
689 FSL_DDR_ODT_NEVER,
690 FSL_DDR_ODT_CS,
691 DDR2_RTT_75_OHM,
692 DDR2_RTT_OFF
693 },
694 { /* cs1 */
695 FSL_DDR_ODT_NEVER,
696 FSL_DDR_ODT_NEVER,
697 DDR2_RTT_OFF,
698 DDR2_RTT_OFF
699 },
700 { /* cs2 */
701 FSL_DDR_ODT_NEVER,
702 FSL_DDR_ODT_CS,
703 DDR2_RTT_75_OHM,
704 DDR2_RTT_OFF
705 },
706 { /* cs3 */
707 FSL_DDR_ODT_NEVER,
708 FSL_DDR_ODT_NEVER,
709 DDR2_RTT_OFF,
710 DDR2_RTT_OFF
711 }
712};
713#endif
York Sund01babd2012-10-08 07:44:27 +0000714
715/*
716 * Automatically seleect bank interleaving mode based on DIMMs
717 * in this order: cs0_cs1_cs2_cs3, cs0_cs1, null.
718 * This function only deal with one or two slots per controller.
719 */
720static inline unsigned int auto_bank_intlv(dimm_params_t *pdimm)
721{
722#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
723 if (pdimm[0].n_ranks == 4)
724 return FSL_DDR_CS0_CS1_CS2_CS3;
725 else if (pdimm[0].n_ranks == 2)
726 return FSL_DDR_CS0_CS1;
727#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
728#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
729 if (pdimm[0].n_ranks == 4)
730 return FSL_DDR_CS0_CS1_CS2_CS3;
731#endif
732 if (pdimm[0].n_ranks == 2) {
733 if (pdimm[1].n_ranks == 2)
734 return FSL_DDR_CS0_CS1_CS2_CS3;
735 else
736 return FSL_DDR_CS0_CS1;
737 }
738#endif
739 return 0;
740}
741
York Sun999273f2015-07-23 14:04:48 -0700742unsigned int populate_memctl_options(const common_timing_params_t *common_dimm,
Kumar Gala124b0822008-08-26 15:01:29 -0500743 memctl_options_t *popts,
Haiying Wangfa440362008-10-03 12:36:55 -0400744 dimm_params_t *pdimm,
Kumar Gala124b0822008-08-26 15:01:29 -0500745 unsigned int ctrl_num)
746{
747 unsigned int i;
Jeremy Gebben1a491e82018-07-20 16:00:36 -0600748 char buf[HWCONFIG_BUFFER_SIZE];
York Sun2896cb72014-03-27 17:54:47 -0700749#if defined(CONFIG_SYS_FSL_DDR3) || \
750 defined(CONFIG_SYS_FSL_DDR2) || \
751 defined(CONFIG_SYS_FSL_DDR4)
York Sun454f5072011-08-26 11:32:43 -0700752 const struct dynamic_odt *pdodt = odt_unknown;
Kumar Gala59cb44c2011-11-09 10:05:21 -0600753#endif
York Sunbc2f32a2018-01-29 10:24:08 -0800754#if (CONFIG_FSL_SDRAM_TYPE != SDRAM_TYPE_DDR4)
York Sunf0345e22011-08-24 09:40:26 -0700755 ulong ddr_freq;
York Sunbc2f32a2018-01-29 10:24:08 -0800756#endif
Kumar Gala72301602011-01-09 11:37:00 -0600757
758 /*
759 * Extract hwconfig from environment since we have not properly setup
760 * the environment but need it for ddr config params
761 */
Jeremy Gebben1a491e82018-07-20 16:00:36 -0600762 if (env_get_f("hwconfig", buf, sizeof(buf)) < 0)
763 buf[0] = '\0';
Kumar Gala124b0822008-08-26 15:01:29 -0500764
York Sun2896cb72014-03-27 17:54:47 -0700765#if defined(CONFIG_SYS_FSL_DDR3) || \
766 defined(CONFIG_SYS_FSL_DDR2) || \
767 defined(CONFIG_SYS_FSL_DDR4)
Kumar Gala124b0822008-08-26 15:01:29 -0500768 /* Chip select options. */
York Sunedbeee12014-04-01 14:20:49 -0700769#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
770 switch (pdimm[0].n_ranks) {
771 case 1:
772 pdodt = single_S;
773 break;
774 case 2:
775 pdodt = single_D;
776 break;
777 case 4:
778 pdodt = single_Q;
779 break;
780 }
781#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
782 switch (pdimm[0].n_ranks) {
783#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
784 case 4:
785 pdodt = single_Q;
786 if (pdimm[1].n_ranks)
787 printf("Error: Quad- and Dual-rank DIMMs cannot be used together\n");
788 break;
789#endif
790 case 2:
791 switch (pdimm[1].n_ranks) {
York Sunba0c2eb2011-01-10 12:03:00 +0000792 case 2:
York Sunedbeee12014-04-01 14:20:49 -0700793 pdodt = dual_DD;
York Sunba0c2eb2011-01-10 12:03:00 +0000794 break;
York Sunedbeee12014-04-01 14:20:49 -0700795 case 1:
796 pdodt = dual_DS;
York Sunba0c2eb2011-01-10 12:03:00 +0000797 break;
York Sunedbeee12014-04-01 14:20:49 -0700798 case 0:
799 pdodt = dual_D0;
York Sun98df4d12012-10-08 07:44:23 +0000800 break;
York Sunedbeee12014-04-01 14:20:49 -0700801 }
802 break;
803 case 1:
804 switch (pdimm[1].n_ranks) {
York Sunba0c2eb2011-01-10 12:03:00 +0000805 case 2:
York Sunedbeee12014-04-01 14:20:49 -0700806 pdodt = dual_SD;
York Sunba0c2eb2011-01-10 12:03:00 +0000807 break;
808 case 1:
York Sunedbeee12014-04-01 14:20:49 -0700809 pdodt = dual_SS;
York Sunba0c2eb2011-01-10 12:03:00 +0000810 break;
811 case 0:
York Sunedbeee12014-04-01 14:20:49 -0700812 pdodt = dual_S0;
York Sunba0c2eb2011-01-10 12:03:00 +0000813 break;
814 }
York Sunedbeee12014-04-01 14:20:49 -0700815 break;
816 case 0:
817 switch (pdimm[1].n_ranks) {
818 case 2:
819 pdodt = dual_0D;
820 break;
821 case 1:
822 pdodt = dual_0S;
823 break;
824 }
825 break;
York Sunba0c2eb2011-01-10 12:03:00 +0000826 }
York Sunedbeee12014-04-01 14:20:49 -0700827#endif /* CONFIG_DIMM_SLOTS_PER_CTLR */
828#endif /* CONFIG_SYS_FSL_DDR2, 3, 4 */
Kumar Gala124b0822008-08-26 15:01:29 -0500829
830 /* Pick chip-select local options. */
831 for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
York Sun2896cb72014-03-27 17:54:47 -0700832#if defined(CONFIG_SYS_FSL_DDR3) || \
833 defined(CONFIG_SYS_FSL_DDR2) || \
834 defined(CONFIG_SYS_FSL_DDR4)
York Sunba0c2eb2011-01-10 12:03:00 +0000835 popts->cs_local_opts[i].odt_rd_cfg = pdodt[i].odt_rd_cfg;
836 popts->cs_local_opts[i].odt_wr_cfg = pdodt[i].odt_wr_cfg;
837 popts->cs_local_opts[i].odt_rtt_norm = pdodt[i].odt_rtt_norm;
838 popts->cs_local_opts[i].odt_rtt_wr = pdodt[i].odt_rtt_wr;
839#else
840 popts->cs_local_opts[i].odt_rd_cfg = FSL_DDR_ODT_NEVER;
841 popts->cs_local_opts[i].odt_wr_cfg = FSL_DDR_ODT_CS;
842#endif
Kumar Gala124b0822008-08-26 15:01:29 -0500843 popts->cs_local_opts[i].auto_precharge = 0;
844 }
845
846 /* Pick interleaving mode. */
847
848 /*
849 * 0 = no interleaving
850 * 1 = interleaving between 2 controllers
851 */
852 popts->memctl_interleaving = 0;
853
854 /*
855 * 0 = cacheline
856 * 1 = page
857 * 2 = (logical) bank
858 * 3 = superbank (only if CS interleaving is enabled)
859 */
860 popts->memctl_interleaving_mode = 0;
861
862 /*
863 * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
864 * 1: page: bit to the left of the column bits selects the memctl
865 * 2: bank: bit to the left of the bank bits selects the memctl
866 * 3: superbank: bit to the left of the chip select selects the memctl
867 *
868 * NOTE: ba_intlv (rank interleaving) is independent of memory
869 * controller interleaving; it is only within a memory controller.
870 * Must use superbank interleaving if rank interleaving is used and
871 * memory controller interleaving is enabled.
872 */
873
874 /*
875 * 0 = no
876 * 0x40 = CS0,CS1
877 * 0x20 = CS2,CS3
878 * 0x60 = CS0,CS1 + CS2,CS3
879 * 0x04 = CS0,CS1,CS2,CS3
880 */
881 popts->ba_intlv_ctl = 0;
882
883 /* Memory Organization Parameters */
York Sun999273f2015-07-23 14:04:48 -0700884 popts->registered_dimm_en = common_dimm->all_dimms_registered;
Kumar Gala124b0822008-08-26 15:01:29 -0500885
886 /* Operational Mode Paramters */
887
888 /* Pick ECC modes */
Priyanka Jain4a717412013-09-25 10:41:19 +0530889 popts->ecc_mode = 0; /* 0 = disabled, 1 = enabled */
York Sun0ac71ea2011-01-10 12:02:57 +0000890#ifdef CONFIG_DDR_ECC
891 if (hwconfig_sub_f("fsl_ddr", "ecc", buf)) {
892 if (hwconfig_subarg_cmp_f("fsl_ddr", "ecc", "on", buf))
Priyanka Jain4a717412013-09-25 10:41:19 +0530893 popts->ecc_mode = 1;
York Sun0ac71ea2011-01-10 12:02:57 +0000894 } else
Priyanka Jain4a717412013-09-25 10:41:19 +0530895 popts->ecc_mode = 1;
Kumar Gala124b0822008-08-26 15:01:29 -0500896#endif
York Sun2a77a122016-05-26 12:19:03 -0700897 /* 1 = use memory controler to init data */
898 popts->ecc_init_using_memctl = popts->ecc_mode ? 1 : 0;
Kumar Gala124b0822008-08-26 15:01:29 -0500899
900 /*
901 * Choose DQS config
902 * 0 for DDR1
903 * 1 for DDR2
904 */
York Sunf0626592013-09-30 09:22:09 -0700905#if defined(CONFIG_SYS_FSL_DDR1)
Priyanka Jain4a717412013-09-25 10:41:19 +0530906 popts->dqs_config = 0;
York Sunf0626592013-09-30 09:22:09 -0700907#elif defined(CONFIG_SYS_FSL_DDR2) || defined(CONFIG_SYS_FSL_DDR3)
Priyanka Jain4a717412013-09-25 10:41:19 +0530908 popts->dqs_config = 1;
Kumar Gala124b0822008-08-26 15:01:29 -0500909#endif
910
911 /* Choose self-refresh during sleep. */
912 popts->self_refresh_in_sleep = 1;
913
914 /* Choose dynamic power management mode. */
915 popts->dynamic_power = 0;
916
York Sun5fb9f6f2011-05-27 07:25:48 +0800917 /*
918 * check first dimm for primary sdram width
919 * presuming all dimms are similar
920 * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit
921 */
York Sunf0626592013-09-30 09:22:09 -0700922#if defined(CONFIG_SYS_FSL_DDR1) || defined(CONFIG_SYS_FSL_DDR2)
York Sun3c5ffd42011-06-27 13:35:25 -0700923 if (pdimm[0].n_ranks != 0) {
924 if ((pdimm[0].data_width >= 64) && \
925 (pdimm[0].data_width <= 72))
926 popts->data_bus_width = 0;
xypron.glpk@gmx.de5fecf832017-04-15 15:23:49 +0200927 else if ((pdimm[0].data_width >= 32) && \
York Sun3c5ffd42011-06-27 13:35:25 -0700928 (pdimm[0].data_width <= 40))
929 popts->data_bus_width = 1;
930 else {
931 panic("Error: data width %u is invalid!\n",
932 pdimm[0].data_width);
933 }
934 }
935#else
936 if (pdimm[0].n_ranks != 0) {
937 if (pdimm[0].primary_sdram_width == 64)
938 popts->data_bus_width = 0;
939 else if (pdimm[0].primary_sdram_width == 32)
940 popts->data_bus_width = 1;
941 else if (pdimm[0].primary_sdram_width == 16)
942 popts->data_bus_width = 2;
943 else {
944 panic("Error: primary sdram width %u is invalid!\n",
945 pdimm[0].primary_sdram_width);
946 }
947 }
948#endif
Kumar Gala124b0822008-08-26 15:01:29 -0500949
York Sun4889c982013-06-25 11:37:47 -0700950 popts->x4_en = (pdimm[0].device_width == 4) ? 1 : 0;
951
Kumar Gala124b0822008-08-26 15:01:29 -0500952 /* Choose burst length. */
York Sun2896cb72014-03-27 17:54:47 -0700953#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
Dave Liu707aa5c2010-03-05 12:22:00 +0800954#if defined(CONFIG_E500MC)
Priyanka Jain4a717412013-09-25 10:41:19 +0530955 popts->otf_burst_chop_en = 0; /* on-the-fly burst chop disable */
Dave Liu707aa5c2010-03-05 12:22:00 +0800956 popts->burst_length = DDR_BL8; /* Fixed 8-beat burst len */
957#else
York Sundd803dd2011-05-27 07:25:51 +0800958 if ((popts->data_bus_width == 1) || (popts->data_bus_width == 2)) {
959 /* 32-bit or 16-bit bus */
Priyanka Jain4a717412013-09-25 10:41:19 +0530960 popts->otf_burst_chop_en = 0;
York Sun5fb9f6f2011-05-27 07:25:48 +0800961 popts->burst_length = DDR_BL8;
962 } else {
Priyanka Jain4a717412013-09-25 10:41:19 +0530963 popts->otf_burst_chop_en = 1; /* on-the-fly burst chop */
York Sun5fb9f6f2011-05-27 07:25:48 +0800964 popts->burst_length = DDR_OTF; /* on-the-fly BC4 and BL8 */
965 }
Dave Liu707aa5c2010-03-05 12:22:00 +0800966#endif
Dave Liu4be87b22009-03-14 12:48:30 +0800967#else
968 popts->burst_length = DDR_BL4; /* has to be 4 for DDR2 */
969#endif
970
971 /* Choose ddr controller address mirror mode */
York Sun2896cb72014-03-27 17:54:47 -0700972#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
York Sunfc63b282015-03-19 09:30:27 -0700973 for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
974 if (pdimm[i].n_ranks) {
975 popts->mirrored_dimm = pdimm[i].mirrored_dimm;
976 break;
977 }
978 }
Dave Liu4be87b22009-03-14 12:48:30 +0800979#endif
Kumar Gala124b0822008-08-26 15:01:29 -0500980
981 /* Global Timing Parameters. */
York Sun2c0b62d2015-01-06 13:18:50 -0800982 debug("mclk_ps = %u ps\n", get_memory_clk_period_ps(ctrl_num));
Kumar Gala124b0822008-08-26 15:01:29 -0500983
984 /* Pick a caslat override. */
985 popts->cas_latency_override = 0;
986 popts->cas_latency_override_value = 3;
987 if (popts->cas_latency_override) {
988 debug("using caslat override value = %u\n",
989 popts->cas_latency_override_value);
990 }
991
992 /* Decide whether to use the computed derated latency */
993 popts->use_derated_caslat = 0;
994
995 /* Choose an additive latency. */
996 popts->additive_latency_override = 0;
997 popts->additive_latency_override_value = 3;
998 if (popts->additive_latency_override) {
999 debug("using additive latency override value = %u\n",
1000 popts->additive_latency_override_value);
1001 }
1002
1003 /*
1004 * 2T_EN setting
1005 *
1006 * Factors to consider for 2T_EN:
1007 * - number of DIMMs installed
1008 * - number of components, number of active ranks
1009 * - how much time you want to spend playing around
1010 */
Priyanka Jain4a717412013-09-25 10:41:19 +05301011 popts->twot_en = 0;
1012 popts->threet_en = 0;
Kumar Gala124b0822008-08-26 15:01:29 -05001013
Shengzhou Liu52199442016-03-10 17:36:56 +08001014 /* for RDIMM and DDR4 UDIMM/discrete memory, address parity enable */
1015 if (popts->registered_dimm_en)
1016 popts->ap_en = 1; /* 0 = disable, 1 = enable */
1017 else
1018 popts->ap_en = 0; /* disabled for DDR4 UDIMM/discrete default */
1019
1020 if (hwconfig_sub_f("fsl_ddr", "parity", buf)) {
1021 if (hwconfig_subarg_cmp_f("fsl_ddr", "parity", "on", buf)) {
1022 if (popts->registered_dimm_en ||
1023 (CONFIG_FSL_SDRAM_TYPE == SDRAM_TYPE_DDR4))
1024 popts->ap_en = 1;
1025 }
1026 }
York Sunba0c2eb2011-01-10 12:03:00 +00001027
Kumar Gala124b0822008-08-26 15:01:29 -05001028 /*
1029 * BSTTOPRE precharge interval
1030 *
1031 * Set this to 0 for global auto precharge
York Sun2896cb72014-03-27 17:54:47 -07001032 * The value of 0x100 has been used for DDR1, DDR2, DDR3.
1033 * It is not wrong. Any value should be OK. The performance depends on
York Sun999273f2015-07-23 14:04:48 -07001034 * applications. There is no one good value for all. One way to set
1035 * is to use 1/4 of refint value.
Kumar Gala124b0822008-08-26 15:01:29 -05001036 */
York Sun999273f2015-07-23 14:04:48 -07001037 popts->bstopre = picos_to_mclk(ctrl_num, common_dimm->refresh_rate_ps)
1038 >> 2;
Kumar Gala124b0822008-08-26 15:01:29 -05001039
Kumar Gala124b0822008-08-26 15:01:29 -05001040 /*
1041 * Window for four activates -- tFAW
1042 *
1043 * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
1044 * FIXME: varies depending upon number of column addresses or data
1045 * FIXME: width, was considering looking at pdimm->primary_sdram_width
1046 */
York Sunf0626592013-09-30 09:22:09 -07001047#if defined(CONFIG_SYS_FSL_DDR1)
York Sun2c0b62d2015-01-06 13:18:50 -08001048 popts->tfaw_window_four_activates_ps = mclk_to_picos(ctrl_num, 1);
Kumar Gala124b0822008-08-26 15:01:29 -05001049
York Sunf0626592013-09-30 09:22:09 -07001050#elif defined(CONFIG_SYS_FSL_DDR2)
Kumar Gala124b0822008-08-26 15:01:29 -05001051 /*
1052 * x4/x8; some datasheets have 35000
1053 * x16 wide columns only? Use 50000?
1054 */
Priyanka Jain4a717412013-09-25 10:41:19 +05301055 popts->tfaw_window_four_activates_ps = 37500;
Kumar Gala124b0822008-08-26 15:01:29 -05001056
York Sun2896cb72014-03-27 17:54:47 -07001057#else
Priyanka Jain4a717412013-09-25 10:41:19 +05301058 popts->tfaw_window_four_activates_ps = pdimm[0].tfaw_ps;
Dave Liu4be87b22009-03-14 12:48:30 +08001059#endif
1060 popts->zq_en = 0;
1061 popts->wrlvl_en = 0;
York Sun2896cb72014-03-27 17:54:47 -07001062#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
Dave Liu4be87b22009-03-14 12:48:30 +08001063 /*
1064 * due to ddr3 dimm is fly-by topology
1065 * we suggest to enable write leveling to
1066 * meet the tQDSS under different loading.
1067 */
1068 popts->wrlvl_en = 1;
york1714e492010-07-02 22:25:56 +00001069 popts->zq_en = 1;
Dave Liu64ee7df2009-12-16 10:24:37 -06001070 popts->wrlvl_override = 0;
Kumar Gala124b0822008-08-26 15:01:29 -05001071#endif
1072
Kumar Gala124b0822008-08-26 15:01:29 -05001073 /*
Haiying Wangb834f922008-10-03 12:37:10 -04001074 * Check interleaving configuration from environment.
1075 * Please refer to doc/README.fsl-ddr for the detail.
Kumar Gala124b0822008-08-26 15:01:29 -05001076 *
1077 * If memory controller interleaving is enabled, then the data
york93799ca2010-07-02 22:25:52 +00001078 * bus widths must be programmed identically for all memory controllers.
Haiying Wangb834f922008-10-03 12:37:10 -04001079 *
York Sunc459ae62014-02-10 13:59:44 -08001080 * Attempt to set all controllers to the same chip select
Haiying Wangb834f922008-10-03 12:37:10 -04001081 * interleaving mode. It will do a best effort to get the
1082 * requested ranks interleaved together such that the result
1083 * should be a subset of the requested configuration.
York Sunc459ae62014-02-10 13:59:44 -08001084 *
1085 * if CONFIG_SYS_FSL_DDR_INTLV_256B is defined, mandatory interleaving
1086 * with 256 Byte is enabled.
Kumar Gala124b0822008-08-26 15:01:29 -05001087 */
York Sunfe845072016-12-28 08:43:45 -08001088#if (CONFIG_SYS_NUM_DDR_CTLRS > 1)
York Sune8dc17b2012-08-17 08:22:39 +00001089 if (!hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf))
York Sunc459ae62014-02-10 13:59:44 -08001090#ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
1091 ;
1092#else
York Sune8dc17b2012-08-17 08:22:39 +00001093 goto done;
York Sunc459ae62014-02-10 13:59:44 -08001094#endif
York Sune8dc17b2012-08-17 08:22:39 +00001095 if (pdimm[0].n_ranks == 0) {
1096 printf("There is no rank on CS0 for controller %d.\n", ctrl_num);
1097 popts->memctl_interleaving = 0;
1098 goto done;
1099 }
1100 popts->memctl_interleaving = 1;
York Sunc459ae62014-02-10 13:59:44 -08001101#ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
1102 popts->memctl_interleaving_mode = FSL_DDR_256B_INTERLEAVING;
1103 popts->memctl_interleaving = 1;
1104 debug("256 Byte interleaving\n");
York Sunedbeee12014-04-01 14:20:49 -07001105#else
York Sune8dc17b2012-08-17 08:22:39 +00001106 /*
1107 * test null first. if CONFIG_HWCONFIG is not defined
1108 * hwconfig_arg_cmp returns non-zero
1109 */
1110 if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
1111 "null", buf)) {
1112 popts->memctl_interleaving = 0;
1113 debug("memory controller interleaving disabled.\n");
1114 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1115 "ctlr_intlv",
1116 "cacheline", buf)) {
1117 popts->memctl_interleaving_mode =
York Sunfe845072016-12-28 08:43:45 -08001118 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001119 0 : FSL_DDR_CACHE_LINE_INTERLEAVING;
1120 popts->memctl_interleaving =
York Sunfe845072016-12-28 08:43:45 -08001121 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001122 0 : 1;
1123 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1124 "ctlr_intlv",
1125 "page", buf)) {
1126 popts->memctl_interleaving_mode =
York Sunfe845072016-12-28 08:43:45 -08001127 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001128 0 : FSL_DDR_PAGE_INTERLEAVING;
1129 popts->memctl_interleaving =
York Sunfe845072016-12-28 08:43:45 -08001130 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001131 0 : 1;
1132 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1133 "ctlr_intlv",
1134 "bank", buf)) {
1135 popts->memctl_interleaving_mode =
York Sunfe845072016-12-28 08:43:45 -08001136 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001137 0 : FSL_DDR_BANK_INTERLEAVING;
1138 popts->memctl_interleaving =
York Sunfe845072016-12-28 08:43:45 -08001139 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001140 0 : 1;
1141 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1142 "ctlr_intlv",
1143 "superbank", buf)) {
1144 popts->memctl_interleaving_mode =
York Sunfe845072016-12-28 08:43:45 -08001145 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001146 0 : FSL_DDR_SUPERBANK_INTERLEAVING;
1147 popts->memctl_interleaving =
York Sunfe845072016-12-28 08:43:45 -08001148 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Sune8dc17b2012-08-17 08:22:39 +00001149 0 : 1;
York Sunfe845072016-12-28 08:43:45 -08001150#if (CONFIG_SYS_NUM_DDR_CTLRS == 3)
York Sune8dc17b2012-08-17 08:22:39 +00001151 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1152 "ctlr_intlv",
1153 "3way_1KB", buf)) {
1154 popts->memctl_interleaving_mode =
1155 FSL_DDR_3WAY_1KB_INTERLEAVING;
1156 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1157 "ctlr_intlv",
1158 "3way_4KB", buf)) {
1159 popts->memctl_interleaving_mode =
1160 FSL_DDR_3WAY_4KB_INTERLEAVING;
1161 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1162 "ctlr_intlv",
1163 "3way_8KB", buf)) {
1164 popts->memctl_interleaving_mode =
1165 FSL_DDR_3WAY_8KB_INTERLEAVING;
York Sunfe845072016-12-28 08:43:45 -08001166#elif (CONFIG_SYS_NUM_DDR_CTLRS == 4)
York Sune8dc17b2012-08-17 08:22:39 +00001167 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1168 "ctlr_intlv",
1169 "4way_1KB", buf)) {
1170 popts->memctl_interleaving_mode =
1171 FSL_DDR_4WAY_1KB_INTERLEAVING;
1172 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1173 "ctlr_intlv",
1174 "4way_4KB", buf)) {
1175 popts->memctl_interleaving_mode =
1176 FSL_DDR_4WAY_4KB_INTERLEAVING;
1177 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1178 "ctlr_intlv",
1179 "4way_8KB", buf)) {
1180 popts->memctl_interleaving_mode =
1181 FSL_DDR_4WAY_8KB_INTERLEAVING;
1182#endif
1183 } else {
1184 popts->memctl_interleaving = 0;
1185 printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
Haiying Wangb834f922008-10-03 12:37:10 -04001186 }
York Sunedbeee12014-04-01 14:20:49 -07001187#endif /* CONFIG_SYS_FSL_DDR_INTLV_256B */
York Sune8dc17b2012-08-17 08:22:39 +00001188done:
York Sunfe845072016-12-28 08:43:45 -08001189#endif /* CONFIG_SYS_NUM_DDR_CTLRS > 1 */
Kumar Gala72301602011-01-09 11:37:00 -06001190 if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) &&
Dave Liu0f9318f2009-11-12 07:26:37 +08001191 (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) {
Kumar Gala64042092010-07-14 10:04:21 -05001192 /* test null first. if CONFIG_HWCONFIG is not defined,
Kumar Gala72301602011-01-09 11:37:00 -06001193 * hwconfig_subarg_cmp_f returns non-zero */
1194 if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1195 "null", buf))
york93799ca2010-07-02 22:25:52 +00001196 debug("bank interleaving disabled.\n");
Kumar Gala72301602011-01-09 11:37:00 -06001197 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1198 "cs0_cs1", buf))
Haiying Wangb834f922008-10-03 12:37:10 -04001199 popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
Kumar Gala72301602011-01-09 11:37:00 -06001200 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1201 "cs2_cs3", buf))
Haiying Wangb834f922008-10-03 12:37:10 -04001202 popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
Kumar Gala72301602011-01-09 11:37:00 -06001203 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1204 "cs0_cs1_and_cs2_cs3", buf))
Haiying Wangb834f922008-10-03 12:37:10 -04001205 popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
Kumar Gala72301602011-01-09 11:37:00 -06001206 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1207 "cs0_cs1_cs2_cs3", buf))
Haiying Wangb834f922008-10-03 12:37:10 -04001208 popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
York Sund01babd2012-10-08 07:44:27 +00001209 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1210 "auto", buf))
1211 popts->ba_intlv_ctl = auto_bank_intlv(pdimm);
Haiying Wangb834f922008-10-03 12:37:10 -04001212 else
york93799ca2010-07-02 22:25:52 +00001213 printf("hwconfig has unrecognized parameter for bank_intlv.\n");
Haiying Wangb834f922008-10-03 12:37:10 -04001214 switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
1215 case FSL_DDR_CS0_CS1_CS2_CS3:
york93799ca2010-07-02 22:25:52 +00001216#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
yorkf4f93c62010-07-02 22:25:53 +00001217 if (pdimm[0].n_ranks < 4) {
york93799ca2010-07-02 22:25:52 +00001218 popts->ba_intlv_ctl = 0;
1219 printf("Not enough bank(chip-select) for "
1220 "CS0+CS1+CS2+CS3 on controller %d, "
York Sune8dc17b2012-08-17 08:22:39 +00001221 "interleaving disabled!\n", ctrl_num);
york93799ca2010-07-02 22:25:52 +00001222 }
1223#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
York Sun98df4d12012-10-08 07:44:23 +00001224#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
1225 if (pdimm[0].n_ranks == 4)
1226 break;
1227#endif
yorkf4f93c62010-07-02 22:25:53 +00001228 if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) {
york93799ca2010-07-02 22:25:52 +00001229 popts->ba_intlv_ctl = 0;
1230 printf("Not enough bank(chip-select) for "
1231 "CS0+CS1+CS2+CS3 on controller %d, "
York Sune8dc17b2012-08-17 08:22:39 +00001232 "interleaving disabled!\n", ctrl_num);
york93799ca2010-07-02 22:25:52 +00001233 }
1234 if (pdimm[0].capacity != pdimm[1].capacity) {
1235 popts->ba_intlv_ctl = 0;
1236 printf("Not identical DIMM size for "
1237 "CS0+CS1+CS2+CS3 on controller %d, "
York Sune8dc17b2012-08-17 08:22:39 +00001238 "interleaving disabled!\n", ctrl_num);
york93799ca2010-07-02 22:25:52 +00001239 }
1240#endif
1241 break;
Haiying Wangb834f922008-10-03 12:37:10 -04001242 case FSL_DDR_CS0_CS1:
yorkf4f93c62010-07-02 22:25:53 +00001243 if (pdimm[0].n_ranks < 2) {
Haiying Wangb834f922008-10-03 12:37:10 -04001244 popts->ba_intlv_ctl = 0;
Ed Swarthoutb135d932008-10-29 09:21:44 -05001245 printf("Not enough bank(chip-select) for "
york93799ca2010-07-02 22:25:52 +00001246 "CS0+CS1 on controller %d, "
York Sune8dc17b2012-08-17 08:22:39 +00001247 "interleaving disabled!\n", ctrl_num);
Haiying Wangb834f922008-10-03 12:37:10 -04001248 }
1249 break;
1250 case FSL_DDR_CS2_CS3:
york93799ca2010-07-02 22:25:52 +00001251#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
yorkf4f93c62010-07-02 22:25:53 +00001252 if (pdimm[0].n_ranks < 4) {
Haiying Wangb834f922008-10-03 12:37:10 -04001253 popts->ba_intlv_ctl = 0;
york93799ca2010-07-02 22:25:52 +00001254 printf("Not enough bank(chip-select) for CS2+CS3 "
York Sune8dc17b2012-08-17 08:22:39 +00001255 "on controller %d, interleaving disabled!\n", ctrl_num);
Haiying Wangb834f922008-10-03 12:37:10 -04001256 }
york93799ca2010-07-02 22:25:52 +00001257#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
yorkf4f93c62010-07-02 22:25:53 +00001258 if (pdimm[1].n_ranks < 2) {
york93799ca2010-07-02 22:25:52 +00001259 popts->ba_intlv_ctl = 0;
1260 printf("Not enough bank(chip-select) for CS2+CS3 "
York Sune8dc17b2012-08-17 08:22:39 +00001261 "on controller %d, interleaving disabled!\n", ctrl_num);
york93799ca2010-07-02 22:25:52 +00001262 }
1263#endif
Haiying Wangb834f922008-10-03 12:37:10 -04001264 break;
1265 case FSL_DDR_CS0_CS1_AND_CS2_CS3:
york93799ca2010-07-02 22:25:52 +00001266#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
yorkf4f93c62010-07-02 22:25:53 +00001267 if (pdimm[0].n_ranks < 4) {
york93799ca2010-07-02 22:25:52 +00001268 popts->ba_intlv_ctl = 0;
1269 printf("Not enough bank(CS) for CS0+CS1 and "
1270 "CS2+CS3 on controller %d, "
York Sune8dc17b2012-08-17 08:22:39 +00001271 "interleaving disabled!\n", ctrl_num);
york93799ca2010-07-02 22:25:52 +00001272 }
1273#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
yorkf4f93c62010-07-02 22:25:53 +00001274 if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) {
Haiying Wangb834f922008-10-03 12:37:10 -04001275 popts->ba_intlv_ctl = 0;
york93799ca2010-07-02 22:25:52 +00001276 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);
Haiying Wangb834f922008-10-03 12:37:10 -04001279 }
york93799ca2010-07-02 22:25:52 +00001280#endif
Haiying Wangb834f922008-10-03 12:37:10 -04001281 break;
1282 default:
1283 popts->ba_intlv_ctl = 0;
1284 break;
1285 }
1286 }
Kumar Gala124b0822008-08-26 15:01:29 -05001287
Kumar Gala72301602011-01-09 11:37:00 -06001288 if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf)) {
1289 if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf))
york42603722010-07-02 22:25:54 +00001290 popts->addr_hash = 0;
Kumar Gala72301602011-01-09 11:37:00 -06001291 else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash",
1292 "true", buf))
york42603722010-07-02 22:25:54 +00001293 popts->addr_hash = 1;
1294 }
1295
yorkf4f93c62010-07-02 22:25:53 +00001296 if (pdimm[0].n_ranks == 4)
1297 popts->quad_rank_present = 1;
1298
York Sun6db4fdd2018-01-29 09:44:35 -08001299 popts->package_3ds = pdimm->package_3ds;
1300
York Sunbc2f32a2018-01-29 10:24:08 -08001301#if (CONFIG_FSL_SDRAM_TYPE != SDRAM_TYPE_DDR4)
York Sun2c0b62d2015-01-06 13:18:50 -08001302 ddr_freq = get_ddr_freq(ctrl_num) / 1000000;
York Sunf0345e22011-08-24 09:40:26 -07001303 if (popts->registered_dimm_en) {
1304 popts->rcw_override = 1;
1305 popts->rcw_1 = 0x000a5a00;
1306 if (ddr_freq <= 800)
1307 popts->rcw_2 = 0x00000000;
1308 else if (ddr_freq <= 1066)
1309 popts->rcw_2 = 0x00100000;
1310 else if (ddr_freq <= 1333)
1311 popts->rcw_2 = 0x00200000;
1312 else
1313 popts->rcw_2 = 0x00300000;
1314 }
York Sunbc2f32a2018-01-29 10:24:08 -08001315#endif
York Sunf0345e22011-08-24 09:40:26 -07001316
Haiying Wangfa440362008-10-03 12:36:55 -04001317 fsl_ddr_board_options(popts, pdimm, ctrl_num);
Kumar Gala124b0822008-08-26 15:01:29 -05001318
1319 return 0;
1320}
york93799ca2010-07-02 22:25:52 +00001321
1322void check_interleaving_options(fsl_ddr_info_t *pinfo)
1323{
York Sune8dc17b2012-08-17 08:22:39 +00001324 int i, j, k, check_n_ranks, intlv_invalid = 0;
1325 unsigned int check_intlv, check_n_row_addr, check_n_col_addr;
york93799ca2010-07-02 22:25:52 +00001326 unsigned long long check_rank_density;
York Sune8dc17b2012-08-17 08:22:39 +00001327 struct dimm_params_s *dimm;
York Sun79a779b2014-08-01 15:51:00 -07001328 int first_ctrl = pinfo->first_ctrl;
1329 int last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
1330
york93799ca2010-07-02 22:25:52 +00001331 /*
1332 * Check if all controllers are configured for memory
1333 * controller interleaving. Identical dimms are recommended. At least
York Sune8dc17b2012-08-17 08:22:39 +00001334 * the size, row and col address should be checked.
york93799ca2010-07-02 22:25:52 +00001335 */
1336 j = 0;
York Sun79a779b2014-08-01 15:51:00 -07001337 check_n_ranks = pinfo->dimm_params[first_ctrl][0].n_ranks;
1338 check_rank_density = pinfo->dimm_params[first_ctrl][0].rank_density;
1339 check_n_row_addr = pinfo->dimm_params[first_ctrl][0].n_row_addr;
1340 check_n_col_addr = pinfo->dimm_params[first_ctrl][0].n_col_addr;
1341 check_intlv = pinfo->memctl_opts[first_ctrl].memctl_interleaving_mode;
1342 for (i = first_ctrl; i <= last_ctrl; i++) {
York Sune8dc17b2012-08-17 08:22:39 +00001343 dimm = &pinfo->dimm_params[i][0];
1344 if (!pinfo->memctl_opts[i].memctl_interleaving) {
1345 continue;
1346 } else if (((check_rank_density != dimm->rank_density) ||
1347 (check_n_ranks != dimm->n_ranks) ||
1348 (check_n_row_addr != dimm->n_row_addr) ||
1349 (check_n_col_addr != dimm->n_col_addr) ||
1350 (check_intlv !=
1351 pinfo->memctl_opts[i].memctl_interleaving_mode))){
1352 intlv_invalid = 1;
1353 break;
1354 } else {
york93799ca2010-07-02 22:25:52 +00001355 j++;
1356 }
York Sune8dc17b2012-08-17 08:22:39 +00001357
york93799ca2010-07-02 22:25:52 +00001358 }
York Sune8dc17b2012-08-17 08:22:39 +00001359 if (intlv_invalid) {
York Sun79a779b2014-08-01 15:51:00 -07001360 for (i = first_ctrl; i <= last_ctrl; i++)
York Sune8dc17b2012-08-17 08:22:39 +00001361 pinfo->memctl_opts[i].memctl_interleaving = 0;
1362 printf("Not all DIMMs are identical. "
1363 "Memory controller interleaving disabled.\n");
1364 } else {
1365 switch (check_intlv) {
York Sunc459ae62014-02-10 13:59:44 -08001366 case FSL_DDR_256B_INTERLEAVING:
York Sune8dc17b2012-08-17 08:22:39 +00001367 case FSL_DDR_CACHE_LINE_INTERLEAVING:
1368 case FSL_DDR_PAGE_INTERLEAVING:
1369 case FSL_DDR_BANK_INTERLEAVING:
1370 case FSL_DDR_SUPERBANK_INTERLEAVING:
York Sunfe845072016-12-28 08:43:45 -08001371#if (3 == CONFIG_SYS_NUM_DDR_CTLRS)
York Sune8dc17b2012-08-17 08:22:39 +00001372 k = 2;
York Sunedbeee12014-04-01 14:20:49 -07001373#else
York Sunfe845072016-12-28 08:43:45 -08001374 k = CONFIG_SYS_NUM_DDR_CTLRS;
York Sunedbeee12014-04-01 14:20:49 -07001375#endif
York Sune8dc17b2012-08-17 08:22:39 +00001376 break;
1377 case FSL_DDR_3WAY_1KB_INTERLEAVING:
1378 case FSL_DDR_3WAY_4KB_INTERLEAVING:
1379 case FSL_DDR_3WAY_8KB_INTERLEAVING:
1380 case FSL_DDR_4WAY_1KB_INTERLEAVING:
1381 case FSL_DDR_4WAY_4KB_INTERLEAVING:
1382 case FSL_DDR_4WAY_8KB_INTERLEAVING:
1383 default:
York Sunfe845072016-12-28 08:43:45 -08001384 k = CONFIG_SYS_NUM_DDR_CTLRS;
York Sune8dc17b2012-08-17 08:22:39 +00001385 break;
1386 }
1387 debug("%d of %d controllers are interleaving.\n", j, k);
York Sund01babd2012-10-08 07:44:27 +00001388 if (j && (j != k)) {
York Sun79a779b2014-08-01 15:51:00 -07001389 for (i = first_ctrl; i <= last_ctrl; i++)
york93799ca2010-07-02 22:25:52 +00001390 pinfo->memctl_opts[i].memctl_interleaving = 0;
York Sun79a779b2014-08-01 15:51:00 -07001391 if ((last_ctrl - first_ctrl) > 1)
1392 puts("Not all controllers have compatible interleaving mode. All disabled.\n");
York Sune8dc17b2012-08-17 08:22:39 +00001393 }
york93799ca2010-07-02 22:25:52 +00001394 }
York Sune8dc17b2012-08-17 08:22:39 +00001395 debug("Checking interleaving options completed\n");
york93799ca2010-07-02 22:25:52 +00001396}
Kumar Galaf582d982011-01-09 14:06:28 -06001397
1398int fsl_use_spd(void)
1399{
1400 int use_spd = 0;
1401
1402#ifdef CONFIG_DDR_SPD
Jeremy Gebben1a491e82018-07-20 16:00:36 -06001403 char buf[HWCONFIG_BUFFER_SIZE];
Kumar Gala72301602011-01-09 11:37:00 -06001404
1405 /*
1406 * Extract hwconfig from environment since we have not properly setup
1407 * the environment but need it for ddr config params
1408 */
Jeremy Gebben1a491e82018-07-20 16:00:36 -06001409 if (env_get_f("hwconfig", buf, sizeof(buf)) < 0)
1410 buf[0] = '\0';
Kumar Gala72301602011-01-09 11:37:00 -06001411
Kumar Galaf582d982011-01-09 14:06:28 -06001412 /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
Kumar Gala72301602011-01-09 11:37:00 -06001413 if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) {
1414 if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf))
Kumar Galaf582d982011-01-09 14:06:28 -06001415 use_spd = 1;
Kumar Gala72301602011-01-09 11:37:00 -06001416 else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram",
1417 "fixed", buf))
Kumar Galaf582d982011-01-09 14:06:28 -06001418 use_spd = 0;
1419 else
1420 use_spd = 1;
1421 } else
1422 use_spd = 1;
1423#endif
1424
1425 return use_spd;
1426}