blob: 5158ea2089951320f2d1e3c33cf698fb246b7701 [file] [log] [blame]
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001/*
York Sunc0c32af2018-01-29 09:44:35 -08002 * Copyright 2008, 2010-2016 Freescale Semiconductor, Inc.
3 * Copyright 2017-2018 NXP Semiconductor
Kumar Gala58e5e9a2008-08-26 15:01:29 -05004 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Kumar Gala58e5e9a2008-08-26 15:01:29 -05006 */
7
8#include <common.h>
Kumar Gala79e4e642010-07-14 10:04:21 -05009#include <hwconfig.h>
York Sun5614e712013-09-30 09:22:09 -070010#include <fsl_ddr_sdram.h>
Kumar Gala58e5e9a2008-08-26 15:01:29 -050011
York Sun5614e712013-09-30 09:22:09 -070012#include <fsl_ddr.h>
Simon Glass457e51c2017-05-17 08:23:10 -060013#if defined(CONFIG_FSL_LSCH2) || defined(CONFIG_FSL_LSCH3) || \
14 defined(CONFIG_ARM)
Simon Glass6e2941d2017-05-17 08:23:06 -060015#include <asm/arch/clock.h>
16#endif
Kumar Gala58e5e9a2008-08-26 15:01:29 -050017
Kumar Galadd50af22011-01-09 11:37:00 -060018/*
19 * Use our own stack based buffer before relocation to allow accessing longer
20 * hwconfig strings that might be in the environment before we've relocated.
21 * This is pretty fragile on both the use of stack and if the buffer is big
Simon Glass00caae62017-08-03 12:22:12 -060022 * enough. However we will get a warning from env_get_f() for the latter.
Kumar Galadd50af22011-01-09 11:37:00 -060023 */
Kumar Galadd50af22011-01-09 11:37:00 -060024
Kumar Gala58e5e9a2008-08-26 15:01:29 -050025/* Board-specific functions defined in each board's ddr.c */
26extern void fsl_ddr_board_options(memctl_options_t *popts,
Haiying Wangdfb49102008-10-03 12:36:55 -040027 dimm_params_t *pdimm,
Kumar Gala58e5e9a2008-08-26 15:01:29 -050028 unsigned int ctrl_num);
29
York Sun4e573822011-08-26 11:32:43 -070030struct dynamic_odt {
York Sune1fd16b2011-01-10 12:03:00 +000031 unsigned int odt_rd_cfg;
32 unsigned int odt_wr_cfg;
33 unsigned int odt_rtt_norm;
34 unsigned int odt_rtt_wr;
York Sun4e573822011-08-26 11:32:43 -070035};
York Sune1fd16b2011-01-10 12:03:00 +000036
York Sun19601dd2015-11-04 10:03:17 -080037#ifdef CONFIG_SYS_FSL_DDR4
38/* Quad rank is not verified yet due availability.
39 * Replacing 20 OHM with 34 OHM since DDR4 doesn't have 20 OHM option
40 */
Thomas Schaefer97fbf262017-03-28 11:29:56 -070041static __maybe_unused const struct dynamic_odt single_Q[4] = {
York Sun19601dd2015-11-04 10:03:17 -080042 { /* cs0 */
43 FSL_DDR_ODT_NEVER,
44 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
45 DDR4_RTT_34_OHM, /* unverified */
46 DDR4_RTT_120_OHM
47 },
48 { /* cs1 */
49 FSL_DDR_ODT_NEVER,
50 FSL_DDR_ODT_NEVER,
51 DDR4_RTT_OFF,
52 DDR4_RTT_120_OHM
53 },
54 { /* cs2 */
55 FSL_DDR_ODT_NEVER,
56 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
57 DDR4_RTT_34_OHM,
58 DDR4_RTT_120_OHM
59 },
60 { /* cs3 */
61 FSL_DDR_ODT_NEVER,
62 FSL_DDR_ODT_NEVER, /* tied high */
63 DDR4_RTT_OFF,
64 DDR4_RTT_120_OHM
65 }
66};
67
Thomas Schaefer97fbf262017-03-28 11:29:56 -070068static __maybe_unused const struct dynamic_odt single_D[4] = {
York Sun19601dd2015-11-04 10:03:17 -080069 { /* cs0 */
70 FSL_DDR_ODT_NEVER,
71 FSL_DDR_ODT_ALL,
72 DDR4_RTT_40_OHM,
73 DDR4_RTT_OFF
74 },
75 { /* cs1 */
76 FSL_DDR_ODT_NEVER,
77 FSL_DDR_ODT_NEVER,
78 DDR4_RTT_OFF,
79 DDR4_RTT_OFF
80 },
81 {0, 0, 0, 0},
82 {0, 0, 0, 0}
83};
84
Thomas Schaefer97fbf262017-03-28 11:29:56 -070085static __maybe_unused const struct dynamic_odt single_S[4] = {
York Sun19601dd2015-11-04 10:03:17 -080086 { /* cs0 */
87 FSL_DDR_ODT_NEVER,
88 FSL_DDR_ODT_ALL,
89 DDR4_RTT_40_OHM,
90 DDR4_RTT_OFF
91 },
92 {0, 0, 0, 0},
93 {0, 0, 0, 0},
94 {0, 0, 0, 0},
95};
96
Thomas Schaefer97fbf262017-03-28 11:29:56 -070097static __maybe_unused const struct dynamic_odt dual_DD[4] = {
York Sun19601dd2015-11-04 10:03:17 -080098 { /* cs0 */
99 FSL_DDR_ODT_NEVER,
100 FSL_DDR_ODT_SAME_DIMM,
101 DDR4_RTT_120_OHM,
102 DDR4_RTT_OFF
103 },
104 { /* cs1 */
105 FSL_DDR_ODT_OTHER_DIMM,
106 FSL_DDR_ODT_OTHER_DIMM,
107 DDR4_RTT_34_OHM,
108 DDR4_RTT_OFF
109 },
110 { /* cs2 */
111 FSL_DDR_ODT_NEVER,
112 FSL_DDR_ODT_SAME_DIMM,
113 DDR4_RTT_120_OHM,
114 DDR4_RTT_OFF
115 },
116 { /* cs3 */
117 FSL_DDR_ODT_OTHER_DIMM,
118 FSL_DDR_ODT_OTHER_DIMM,
119 DDR4_RTT_34_OHM,
120 DDR4_RTT_OFF
121 }
122};
123
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700124static __maybe_unused const struct dynamic_odt dual_DS[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800125 { /* cs0 */
126 FSL_DDR_ODT_NEVER,
127 FSL_DDR_ODT_SAME_DIMM,
128 DDR4_RTT_120_OHM,
129 DDR4_RTT_OFF
130 },
131 { /* cs1 */
132 FSL_DDR_ODT_OTHER_DIMM,
133 FSL_DDR_ODT_OTHER_DIMM,
134 DDR4_RTT_34_OHM,
135 DDR4_RTT_OFF
136 },
137 { /* cs2 */
138 FSL_DDR_ODT_OTHER_DIMM,
139 FSL_DDR_ODT_ALL,
140 DDR4_RTT_34_OHM,
141 DDR4_RTT_120_OHM
142 },
143 {0, 0, 0, 0}
144};
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700145static __maybe_unused const struct dynamic_odt dual_SD[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800146 { /* cs0 */
147 FSL_DDR_ODT_OTHER_DIMM,
148 FSL_DDR_ODT_ALL,
149 DDR4_RTT_34_OHM,
150 DDR4_RTT_120_OHM
151 },
152 {0, 0, 0, 0},
153 { /* cs2 */
154 FSL_DDR_ODT_NEVER,
155 FSL_DDR_ODT_SAME_DIMM,
156 DDR4_RTT_120_OHM,
157 DDR4_RTT_OFF
158 },
159 { /* cs3 */
160 FSL_DDR_ODT_OTHER_DIMM,
161 FSL_DDR_ODT_OTHER_DIMM,
162 DDR4_RTT_34_OHM,
163 DDR4_RTT_OFF
164 }
165};
166
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700167static __maybe_unused const struct dynamic_odt dual_SS[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800168 { /* cs0 */
169 FSL_DDR_ODT_OTHER_DIMM,
170 FSL_DDR_ODT_ALL,
171 DDR4_RTT_34_OHM,
172 DDR4_RTT_120_OHM
173 },
174 {0, 0, 0, 0},
175 { /* cs2 */
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};
183
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700184static __maybe_unused const struct dynamic_odt dual_D0[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800185 { /* cs0 */
186 FSL_DDR_ODT_NEVER,
187 FSL_DDR_ODT_SAME_DIMM,
188 DDR4_RTT_40_OHM,
189 DDR4_RTT_OFF
190 },
191 { /* cs1 */
192 FSL_DDR_ODT_NEVER,
193 FSL_DDR_ODT_NEVER,
194 DDR4_RTT_OFF,
195 DDR4_RTT_OFF
196 },
197 {0, 0, 0, 0},
198 {0, 0, 0, 0}
199};
200
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700201static __maybe_unused const struct dynamic_odt dual_0D[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800202 {0, 0, 0, 0},
203 {0, 0, 0, 0},
204 { /* cs2 */
205 FSL_DDR_ODT_NEVER,
206 FSL_DDR_ODT_SAME_DIMM,
207 DDR4_RTT_40_OHM,
208 DDR4_RTT_OFF
209 },
210 { /* cs3 */
211 FSL_DDR_ODT_NEVER,
212 FSL_DDR_ODT_NEVER,
213 DDR4_RTT_OFF,
214 DDR4_RTT_OFF
215 }
216};
217
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700218static __maybe_unused const struct dynamic_odt dual_S0[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800219 { /* cs0 */
220 FSL_DDR_ODT_NEVER,
221 FSL_DDR_ODT_CS,
222 DDR4_RTT_40_OHM,
223 DDR4_RTT_OFF
224 },
225 {0, 0, 0, 0},
226 {0, 0, 0, 0},
227 {0, 0, 0, 0}
228
229};
230
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700231static __maybe_unused const struct dynamic_odt dual_0S[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800232 {0, 0, 0, 0},
233 {0, 0, 0, 0},
234 { /* cs2 */
235 FSL_DDR_ODT_NEVER,
236 FSL_DDR_ODT_CS,
237 DDR4_RTT_40_OHM,
238 DDR4_RTT_OFF
239 },
240 {0, 0, 0, 0}
241
242};
243
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700244static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800245 { /* cs0 */
246 FSL_DDR_ODT_NEVER,
247 FSL_DDR_ODT_CS,
248 DDR4_RTT_120_OHM,
249 DDR4_RTT_OFF
250 },
251 { /* cs1 */
252 FSL_DDR_ODT_NEVER,
253 FSL_DDR_ODT_CS,
254 DDR4_RTT_120_OHM,
255 DDR4_RTT_OFF
256 },
257 { /* cs2 */
258 FSL_DDR_ODT_NEVER,
259 FSL_DDR_ODT_CS,
260 DDR4_RTT_120_OHM,
261 DDR4_RTT_OFF
262 },
263 { /* cs3 */
264 FSL_DDR_ODT_NEVER,
265 FSL_DDR_ODT_CS,
266 DDR4_RTT_120_OHM,
267 DDR4_RTT_OFF
268 }
269};
270#elif defined(CONFIG_SYS_FSL_DDR3)
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700271static __maybe_unused const struct dynamic_odt single_Q[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000272 { /* cs0 */
273 FSL_DDR_ODT_NEVER,
274 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
275 DDR3_RTT_20_OHM,
276 DDR3_RTT_120_OHM
277 },
278 { /* cs1 */
279 FSL_DDR_ODT_NEVER,
280 FSL_DDR_ODT_NEVER, /* tied high */
281 DDR3_RTT_OFF,
282 DDR3_RTT_120_OHM
283 },
284 { /* cs2 */
285 FSL_DDR_ODT_NEVER,
286 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
287 DDR3_RTT_20_OHM,
288 DDR3_RTT_120_OHM
289 },
290 { /* cs3 */
291 FSL_DDR_ODT_NEVER,
292 FSL_DDR_ODT_NEVER, /* tied high */
293 DDR3_RTT_OFF,
294 DDR3_RTT_120_OHM
295 }
296};
297
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700298static __maybe_unused const struct dynamic_odt single_D[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000299 { /* cs0 */
300 FSL_DDR_ODT_NEVER,
301 FSL_DDR_ODT_ALL,
302 DDR3_RTT_40_OHM,
303 DDR3_RTT_OFF
304 },
305 { /* cs1 */
306 FSL_DDR_ODT_NEVER,
307 FSL_DDR_ODT_NEVER,
308 DDR3_RTT_OFF,
309 DDR3_RTT_OFF
310 },
311 {0, 0, 0, 0},
312 {0, 0, 0, 0}
313};
314
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700315static __maybe_unused const struct dynamic_odt single_S[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000316 { /* cs0 */
317 FSL_DDR_ODT_NEVER,
318 FSL_DDR_ODT_ALL,
319 DDR3_RTT_40_OHM,
320 DDR3_RTT_OFF
321 },
322 {0, 0, 0, 0},
323 {0, 0, 0, 0},
324 {0, 0, 0, 0},
325};
326
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700327static __maybe_unused const struct dynamic_odt dual_DD[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000328 { /* cs0 */
329 FSL_DDR_ODT_NEVER,
330 FSL_DDR_ODT_SAME_DIMM,
331 DDR3_RTT_120_OHM,
332 DDR3_RTT_OFF
333 },
334 { /* cs1 */
335 FSL_DDR_ODT_OTHER_DIMM,
336 FSL_DDR_ODT_OTHER_DIMM,
337 DDR3_RTT_30_OHM,
338 DDR3_RTT_OFF
339 },
340 { /* cs2 */
341 FSL_DDR_ODT_NEVER,
342 FSL_DDR_ODT_SAME_DIMM,
343 DDR3_RTT_120_OHM,
344 DDR3_RTT_OFF
345 },
346 { /* cs3 */
347 FSL_DDR_ODT_OTHER_DIMM,
348 FSL_DDR_ODT_OTHER_DIMM,
349 DDR3_RTT_30_OHM,
350 DDR3_RTT_OFF
351 }
352};
353
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700354static __maybe_unused const struct dynamic_odt dual_DS[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000355 { /* cs0 */
356 FSL_DDR_ODT_NEVER,
357 FSL_DDR_ODT_SAME_DIMM,
358 DDR3_RTT_120_OHM,
359 DDR3_RTT_OFF
360 },
361 { /* cs1 */
362 FSL_DDR_ODT_OTHER_DIMM,
363 FSL_DDR_ODT_OTHER_DIMM,
364 DDR3_RTT_30_OHM,
365 DDR3_RTT_OFF
366 },
367 { /* cs2 */
368 FSL_DDR_ODT_OTHER_DIMM,
369 FSL_DDR_ODT_ALL,
370 DDR3_RTT_20_OHM,
371 DDR3_RTT_120_OHM
372 },
373 {0, 0, 0, 0}
374};
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700375static __maybe_unused const struct dynamic_odt dual_SD[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000376 { /* cs0 */
377 FSL_DDR_ODT_OTHER_DIMM,
378 FSL_DDR_ODT_ALL,
379 DDR3_RTT_20_OHM,
380 DDR3_RTT_120_OHM
381 },
382 {0, 0, 0, 0},
383 { /* cs2 */
384 FSL_DDR_ODT_NEVER,
385 FSL_DDR_ODT_SAME_DIMM,
386 DDR3_RTT_120_OHM,
387 DDR3_RTT_OFF
388 },
389 { /* cs3 */
390 FSL_DDR_ODT_OTHER_DIMM,
391 FSL_DDR_ODT_OTHER_DIMM,
392 DDR3_RTT_20_OHM,
393 DDR3_RTT_OFF
394 }
395};
396
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700397static __maybe_unused const struct dynamic_odt dual_SS[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000398 { /* cs0 */
399 FSL_DDR_ODT_OTHER_DIMM,
400 FSL_DDR_ODT_ALL,
401 DDR3_RTT_30_OHM,
402 DDR3_RTT_120_OHM
403 },
404 {0, 0, 0, 0},
405 { /* cs2 */
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};
413
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700414static __maybe_unused const struct dynamic_odt dual_D0[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000415 { /* cs0 */
416 FSL_DDR_ODT_NEVER,
417 FSL_DDR_ODT_SAME_DIMM,
418 DDR3_RTT_40_OHM,
419 DDR3_RTT_OFF
420 },
421 { /* cs1 */
422 FSL_DDR_ODT_NEVER,
423 FSL_DDR_ODT_NEVER,
424 DDR3_RTT_OFF,
425 DDR3_RTT_OFF
426 },
427 {0, 0, 0, 0},
428 {0, 0, 0, 0}
429};
430
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700431static __maybe_unused const struct dynamic_odt dual_0D[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000432 {0, 0, 0, 0},
433 {0, 0, 0, 0},
434 { /* cs2 */
435 FSL_DDR_ODT_NEVER,
436 FSL_DDR_ODT_SAME_DIMM,
437 DDR3_RTT_40_OHM,
438 DDR3_RTT_OFF
439 },
440 { /* cs3 */
441 FSL_DDR_ODT_NEVER,
442 FSL_DDR_ODT_NEVER,
443 DDR3_RTT_OFF,
444 DDR3_RTT_OFF
445 }
446};
447
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700448static __maybe_unused const struct dynamic_odt dual_S0[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000449 { /* cs0 */
450 FSL_DDR_ODT_NEVER,
451 FSL_DDR_ODT_CS,
452 DDR3_RTT_40_OHM,
453 DDR3_RTT_OFF
454 },
455 {0, 0, 0, 0},
456 {0, 0, 0, 0},
457 {0, 0, 0, 0}
458
459};
460
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700461static __maybe_unused const struct dynamic_odt dual_0S[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000462 {0, 0, 0, 0},
463 {0, 0, 0, 0},
464 { /* cs2 */
465 FSL_DDR_ODT_NEVER,
466 FSL_DDR_ODT_CS,
467 DDR3_RTT_40_OHM,
468 DDR3_RTT_OFF
469 },
470 {0, 0, 0, 0}
471
472};
473
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700474static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000475 { /* cs0 */
476 FSL_DDR_ODT_NEVER,
477 FSL_DDR_ODT_CS,
478 DDR3_RTT_120_OHM,
479 DDR3_RTT_OFF
480 },
481 { /* cs1 */
482 FSL_DDR_ODT_NEVER,
483 FSL_DDR_ODT_CS,
484 DDR3_RTT_120_OHM,
485 DDR3_RTT_OFF
486 },
487 { /* cs2 */
488 FSL_DDR_ODT_NEVER,
489 FSL_DDR_ODT_CS,
490 DDR3_RTT_120_OHM,
491 DDR3_RTT_OFF
492 },
493 { /* cs3 */
494 FSL_DDR_ODT_NEVER,
495 FSL_DDR_ODT_CS,
496 DDR3_RTT_120_OHM,
497 DDR3_RTT_OFF
498 }
499};
York Sun19601dd2015-11-04 10:03:17 -0800500#else /* CONFIG_SYS_FSL_DDR3 */
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700501static __maybe_unused const struct dynamic_odt single_Q[4] = {
York Sun4e573822011-08-26 11:32:43 -0700502 {0, 0, 0, 0},
503 {0, 0, 0, 0},
504 {0, 0, 0, 0},
505 {0, 0, 0, 0}
506};
York Sune1fd16b2011-01-10 12:03:00 +0000507
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700508static __maybe_unused const struct dynamic_odt single_D[4] = {
York Sun4e573822011-08-26 11:32:43 -0700509 { /* cs0 */
510 FSL_DDR_ODT_NEVER,
511 FSL_DDR_ODT_ALL,
512 DDR2_RTT_150_OHM,
513 DDR2_RTT_OFF
514 },
515 { /* cs1 */
516 FSL_DDR_ODT_NEVER,
517 FSL_DDR_ODT_NEVER,
518 DDR2_RTT_OFF,
519 DDR2_RTT_OFF
520 },
521 {0, 0, 0, 0},
522 {0, 0, 0, 0}
523};
524
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700525static __maybe_unused const struct dynamic_odt single_S[4] = {
York Sun4e573822011-08-26 11:32:43 -0700526 { /* cs0 */
527 FSL_DDR_ODT_NEVER,
528 FSL_DDR_ODT_ALL,
529 DDR2_RTT_150_OHM,
530 DDR2_RTT_OFF
531 },
532 {0, 0, 0, 0},
533 {0, 0, 0, 0},
534 {0, 0, 0, 0},
535};
536
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700537static __maybe_unused const struct dynamic_odt dual_DD[4] = {
York Sun4e573822011-08-26 11:32:43 -0700538 { /* cs0 */
539 FSL_DDR_ODT_OTHER_DIMM,
540 FSL_DDR_ODT_OTHER_DIMM,
541 DDR2_RTT_75_OHM,
542 DDR2_RTT_OFF
543 },
544 { /* cs1 */
545 FSL_DDR_ODT_NEVER,
546 FSL_DDR_ODT_NEVER,
547 DDR2_RTT_OFF,
548 DDR2_RTT_OFF
549 },
550 { /* cs2 */
551 FSL_DDR_ODT_OTHER_DIMM,
552 FSL_DDR_ODT_OTHER_DIMM,
553 DDR2_RTT_75_OHM,
554 DDR2_RTT_OFF
555 },
556 { /* cs3 */
557 FSL_DDR_ODT_NEVER,
558 FSL_DDR_ODT_NEVER,
559 DDR2_RTT_OFF,
560 DDR2_RTT_OFF
561 }
562};
563
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700564static __maybe_unused const struct dynamic_odt dual_DS[4] = {
York Sun4e573822011-08-26 11:32:43 -0700565 { /* cs0 */
566 FSL_DDR_ODT_OTHER_DIMM,
567 FSL_DDR_ODT_OTHER_DIMM,
568 DDR2_RTT_75_OHM,
569 DDR2_RTT_OFF
570 },
571 { /* cs1 */
572 FSL_DDR_ODT_NEVER,
573 FSL_DDR_ODT_NEVER,
574 DDR2_RTT_OFF,
575 DDR2_RTT_OFF
576 },
577 { /* cs2 */
578 FSL_DDR_ODT_OTHER_DIMM,
579 FSL_DDR_ODT_OTHER_DIMM,
580 DDR2_RTT_75_OHM,
581 DDR2_RTT_OFF
582 },
583 {0, 0, 0, 0}
584};
585
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700586static __maybe_unused const struct dynamic_odt dual_SD[4] = {
York Sun4e573822011-08-26 11:32:43 -0700587 { /* cs0 */
588 FSL_DDR_ODT_OTHER_DIMM,
589 FSL_DDR_ODT_OTHER_DIMM,
590 DDR2_RTT_75_OHM,
591 DDR2_RTT_OFF
592 },
593 {0, 0, 0, 0},
594 { /* cs2 */
595 FSL_DDR_ODT_OTHER_DIMM,
596 FSL_DDR_ODT_OTHER_DIMM,
597 DDR2_RTT_75_OHM,
598 DDR2_RTT_OFF
599 },
600 { /* cs3 */
601 FSL_DDR_ODT_NEVER,
602 FSL_DDR_ODT_NEVER,
603 DDR2_RTT_OFF,
604 DDR2_RTT_OFF
605 }
606};
607
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700608static __maybe_unused const struct dynamic_odt dual_SS[4] = {
York Sun4e573822011-08-26 11:32:43 -0700609 { /* cs0 */
610 FSL_DDR_ODT_OTHER_DIMM,
611 FSL_DDR_ODT_OTHER_DIMM,
612 DDR2_RTT_75_OHM,
613 DDR2_RTT_OFF
614 },
615 {0, 0, 0, 0},
616 { /* cs2 */
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};
624
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700625static __maybe_unused const struct dynamic_odt dual_D0[4] = {
York Sun4e573822011-08-26 11:32:43 -0700626 { /* cs0 */
627 FSL_DDR_ODT_NEVER,
628 FSL_DDR_ODT_ALL,
629 DDR2_RTT_150_OHM,
630 DDR2_RTT_OFF
631 },
632 { /* cs1 */
633 FSL_DDR_ODT_NEVER,
634 FSL_DDR_ODT_NEVER,
635 DDR2_RTT_OFF,
636 DDR2_RTT_OFF
637 },
638 {0, 0, 0, 0},
639 {0, 0, 0, 0}
640};
641
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700642static __maybe_unused const struct dynamic_odt dual_0D[4] = {
York Sun4e573822011-08-26 11:32:43 -0700643 {0, 0, 0, 0},
644 {0, 0, 0, 0},
645 { /* cs2 */
646 FSL_DDR_ODT_NEVER,
647 FSL_DDR_ODT_ALL,
648 DDR2_RTT_150_OHM,
649 DDR2_RTT_OFF
650 },
651 { /* cs3 */
652 FSL_DDR_ODT_NEVER,
653 FSL_DDR_ODT_NEVER,
654 DDR2_RTT_OFF,
655 DDR2_RTT_OFF
656 }
657};
658
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700659static __maybe_unused const struct dynamic_odt dual_S0[4] = {
York Sun4e573822011-08-26 11:32:43 -0700660 { /* cs0 */
661 FSL_DDR_ODT_NEVER,
662 FSL_DDR_ODT_CS,
663 DDR2_RTT_150_OHM,
664 DDR2_RTT_OFF
665 },
666 {0, 0, 0, 0},
667 {0, 0, 0, 0},
668 {0, 0, 0, 0}
669
670};
671
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700672static __maybe_unused const struct dynamic_odt dual_0S[4] = {
York Sun4e573822011-08-26 11:32:43 -0700673 {0, 0, 0, 0},
674 {0, 0, 0, 0},
675 { /* cs2 */
676 FSL_DDR_ODT_NEVER,
677 FSL_DDR_ODT_CS,
678 DDR2_RTT_150_OHM,
679 DDR2_RTT_OFF
680 },
681 {0, 0, 0, 0}
682
683};
684
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700685static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
York Sun4e573822011-08-26 11:32:43 -0700686 { /* cs0 */
687 FSL_DDR_ODT_NEVER,
688 FSL_DDR_ODT_CS,
689 DDR2_RTT_75_OHM,
690 DDR2_RTT_OFF
691 },
692 { /* cs1 */
693 FSL_DDR_ODT_NEVER,
694 FSL_DDR_ODT_NEVER,
695 DDR2_RTT_OFF,
696 DDR2_RTT_OFF
697 },
698 { /* cs2 */
699 FSL_DDR_ODT_NEVER,
700 FSL_DDR_ODT_CS,
701 DDR2_RTT_75_OHM,
702 DDR2_RTT_OFF
703 },
704 { /* cs3 */
705 FSL_DDR_ODT_NEVER,
706 FSL_DDR_ODT_NEVER,
707 DDR2_RTT_OFF,
708 DDR2_RTT_OFF
709 }
710};
711#endif
York Sun89b78092012-10-08 07:44:27 +0000712
713/*
714 * Automatically seleect bank interleaving mode based on DIMMs
715 * in this order: cs0_cs1_cs2_cs3, cs0_cs1, null.
716 * This function only deal with one or two slots per controller.
717 */
718static inline unsigned int auto_bank_intlv(dimm_params_t *pdimm)
719{
720#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
721 if (pdimm[0].n_ranks == 4)
722 return FSL_DDR_CS0_CS1_CS2_CS3;
723 else if (pdimm[0].n_ranks == 2)
724 return FSL_DDR_CS0_CS1;
725#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
726#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
727 if (pdimm[0].n_ranks == 4)
728 return FSL_DDR_CS0_CS1_CS2_CS3;
729#endif
730 if (pdimm[0].n_ranks == 2) {
731 if (pdimm[1].n_ranks == 2)
732 return FSL_DDR_CS0_CS1_CS2_CS3;
733 else
734 return FSL_DDR_CS0_CS1;
735 }
736#endif
737 return 0;
738}
739
York Sun56848422015-07-23 14:04:48 -0700740unsigned int populate_memctl_options(const common_timing_params_t *common_dimm,
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500741 memctl_options_t *popts,
Haiying Wangdfb49102008-10-03 12:36:55 -0400742 dimm_params_t *pdimm,
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500743 unsigned int ctrl_num)
744{
745 unsigned int i;
Kumar Galadd50af22011-01-09 11:37:00 -0600746 char buffer[HWCONFIG_BUFFER_SIZE];
747 char *buf = NULL;
York Sun34e026f2014-03-27 17:54:47 -0700748#if defined(CONFIG_SYS_FSL_DDR3) || \
749 defined(CONFIG_SYS_FSL_DDR2) || \
750 defined(CONFIG_SYS_FSL_DDR4)
York Sun4e573822011-08-26 11:32:43 -0700751 const struct dynamic_odt *pdodt = odt_unknown;
Kumar Gala667bc172011-11-09 10:05:21 -0600752#endif
York Suncda1de22011-08-24 09:40:26 -0700753 ulong ddr_freq;
Kumar Galadd50af22011-01-09 11:37:00 -0600754
755 /*
756 * Extract hwconfig from environment since we have not properly setup
757 * the environment but need it for ddr config params
758 */
Simon Glass00caae62017-08-03 12:22:12 -0600759 if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
Kumar Galadd50af22011-01-09 11:37:00 -0600760 buf = buffer;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500761
York Sun34e026f2014-03-27 17:54:47 -0700762#if defined(CONFIG_SYS_FSL_DDR3) || \
763 defined(CONFIG_SYS_FSL_DDR2) || \
764 defined(CONFIG_SYS_FSL_DDR4)
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500765 /* Chip select options. */
York Sun349689b2014-04-01 14:20:49 -0700766#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
767 switch (pdimm[0].n_ranks) {
768 case 1:
769 pdodt = single_S;
770 break;
771 case 2:
772 pdodt = single_D;
773 break;
774 case 4:
775 pdodt = single_Q;
776 break;
777 }
778#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
779 switch (pdimm[0].n_ranks) {
York Sun123922b2012-10-08 07:44:23 +0000780#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
York Sun349689b2014-04-01 14:20:49 -0700781 case 4:
782 pdodt = single_Q;
783 if (pdimm[1].n_ranks)
784 printf("Error: Quad- and Dual-rank DIMMs cannot be used together\n");
785 break;
York Sun123922b2012-10-08 07:44:23 +0000786#endif
York Sun349689b2014-04-01 14:20:49 -0700787 case 2:
788 switch (pdimm[1].n_ranks) {
York Sune1fd16b2011-01-10 12:03:00 +0000789 case 2:
York Sun349689b2014-04-01 14:20:49 -0700790 pdodt = dual_DD;
York Sune1fd16b2011-01-10 12:03:00 +0000791 break;
792 case 1:
York Sun349689b2014-04-01 14:20:49 -0700793 pdodt = dual_DS;
York Sune1fd16b2011-01-10 12:03:00 +0000794 break;
795 case 0:
York Sun349689b2014-04-01 14:20:49 -0700796 pdodt = dual_D0;
York Sune1fd16b2011-01-10 12:03:00 +0000797 break;
798 }
York Sun349689b2014-04-01 14:20:49 -0700799 break;
800 case 1:
801 switch (pdimm[1].n_ranks) {
802 case 2:
803 pdodt = dual_SD;
804 break;
805 case 1:
806 pdodt = dual_SS;
807 break;
808 case 0:
809 pdodt = dual_S0;
810 break;
811 }
812 break;
813 case 0:
814 switch (pdimm[1].n_ranks) {
815 case 2:
816 pdodt = dual_0D;
817 break;
818 case 1:
819 pdodt = dual_0S;
820 break;
821 }
822 break;
York Sune1fd16b2011-01-10 12:03:00 +0000823 }
York Sun349689b2014-04-01 14:20:49 -0700824#endif /* CONFIG_DIMM_SLOTS_PER_CTLR */
825#endif /* CONFIG_SYS_FSL_DDR2, 3, 4 */
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500826
827 /* Pick chip-select local options. */
828 for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
York Sun34e026f2014-03-27 17:54:47 -0700829#if defined(CONFIG_SYS_FSL_DDR3) || \
830 defined(CONFIG_SYS_FSL_DDR2) || \
831 defined(CONFIG_SYS_FSL_DDR4)
York Sune1fd16b2011-01-10 12:03:00 +0000832 popts->cs_local_opts[i].odt_rd_cfg = pdodt[i].odt_rd_cfg;
833 popts->cs_local_opts[i].odt_wr_cfg = pdodt[i].odt_wr_cfg;
834 popts->cs_local_opts[i].odt_rtt_norm = pdodt[i].odt_rtt_norm;
835 popts->cs_local_opts[i].odt_rtt_wr = pdodt[i].odt_rtt_wr;
836#else
837 popts->cs_local_opts[i].odt_rd_cfg = FSL_DDR_ODT_NEVER;
838 popts->cs_local_opts[i].odt_wr_cfg = FSL_DDR_ODT_CS;
839#endif
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500840 popts->cs_local_opts[i].auto_precharge = 0;
841 }
842
843 /* Pick interleaving mode. */
844
845 /*
846 * 0 = no interleaving
847 * 1 = interleaving between 2 controllers
848 */
849 popts->memctl_interleaving = 0;
850
851 /*
852 * 0 = cacheline
853 * 1 = page
854 * 2 = (logical) bank
855 * 3 = superbank (only if CS interleaving is enabled)
856 */
857 popts->memctl_interleaving_mode = 0;
858
859 /*
860 * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
861 * 1: page: bit to the left of the column bits selects the memctl
862 * 2: bank: bit to the left of the bank bits selects the memctl
863 * 3: superbank: bit to the left of the chip select selects the memctl
864 *
865 * NOTE: ba_intlv (rank interleaving) is independent of memory
866 * controller interleaving; it is only within a memory controller.
867 * Must use superbank interleaving if rank interleaving is used and
868 * memory controller interleaving is enabled.
869 */
870
871 /*
872 * 0 = no
873 * 0x40 = CS0,CS1
874 * 0x20 = CS2,CS3
875 * 0x60 = CS0,CS1 + CS2,CS3
876 * 0x04 = CS0,CS1,CS2,CS3
877 */
878 popts->ba_intlv_ctl = 0;
879
880 /* Memory Organization Parameters */
York Sun56848422015-07-23 14:04:48 -0700881 popts->registered_dimm_en = common_dimm->all_dimms_registered;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500882
883 /* Operational Mode Paramters */
884
885 /* Pick ECC modes */
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530886 popts->ecc_mode = 0; /* 0 = disabled, 1 = enabled */
York Sun47df8f02011-01-10 12:02:57 +0000887#ifdef CONFIG_DDR_ECC
888 if (hwconfig_sub_f("fsl_ddr", "ecc", buf)) {
889 if (hwconfig_subarg_cmp_f("fsl_ddr", "ecc", "on", buf))
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530890 popts->ecc_mode = 1;
York Sun47df8f02011-01-10 12:02:57 +0000891 } else
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530892 popts->ecc_mode = 1;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500893#endif
York Sunb06f6f22016-05-26 12:19:03 -0700894 /* 1 = use memory controler to init data */
895 popts->ecc_init_using_memctl = popts->ecc_mode ? 1 : 0;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500896
897 /*
898 * Choose DQS config
899 * 0 for DDR1
900 * 1 for DDR2
901 */
York Sun5614e712013-09-30 09:22:09 -0700902#if defined(CONFIG_SYS_FSL_DDR1)
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530903 popts->dqs_config = 0;
York Sun5614e712013-09-30 09:22:09 -0700904#elif defined(CONFIG_SYS_FSL_DDR2) || defined(CONFIG_SYS_FSL_DDR3)
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530905 popts->dqs_config = 1;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500906#endif
907
908 /* Choose self-refresh during sleep. */
909 popts->self_refresh_in_sleep = 1;
910
911 /* Choose dynamic power management mode. */
912 popts->dynamic_power = 0;
913
York Sune090aa72011-05-27 07:25:48 +0800914 /*
915 * check first dimm for primary sdram width
916 * presuming all dimms are similar
917 * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit
918 */
York Sun5614e712013-09-30 09:22:09 -0700919#if defined(CONFIG_SYS_FSL_DDR1) || defined(CONFIG_SYS_FSL_DDR2)
York Sun4c99cb92011-06-27 13:35:25 -0700920 if (pdimm[0].n_ranks != 0) {
921 if ((pdimm[0].data_width >= 64) && \
922 (pdimm[0].data_width <= 72))
923 popts->data_bus_width = 0;
xypron.glpk@gmx.de0e0de242017-04-15 15:23:49 +0200924 else if ((pdimm[0].data_width >= 32) && \
York Sun4c99cb92011-06-27 13:35:25 -0700925 (pdimm[0].data_width <= 40))
926 popts->data_bus_width = 1;
927 else {
928 panic("Error: data width %u is invalid!\n",
929 pdimm[0].data_width);
930 }
931 }
932#else
933 if (pdimm[0].n_ranks != 0) {
934 if (pdimm[0].primary_sdram_width == 64)
935 popts->data_bus_width = 0;
936 else if (pdimm[0].primary_sdram_width == 32)
937 popts->data_bus_width = 1;
938 else if (pdimm[0].primary_sdram_width == 16)
939 popts->data_bus_width = 2;
940 else {
941 panic("Error: primary sdram width %u is invalid!\n",
942 pdimm[0].primary_sdram_width);
943 }
944 }
945#endif
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500946
York Sunb61e0612013-06-25 11:37:47 -0700947 popts->x4_en = (pdimm[0].device_width == 4) ? 1 : 0;
948
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500949 /* Choose burst length. */
York Sun34e026f2014-03-27 17:54:47 -0700950#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
Dave Liu22c9de02010-03-05 12:22:00 +0800951#if defined(CONFIG_E500MC)
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530952 popts->otf_burst_chop_en = 0; /* on-the-fly burst chop disable */
Dave Liu22c9de02010-03-05 12:22:00 +0800953 popts->burst_length = DDR_BL8; /* Fixed 8-beat burst len */
954#else
York Sun51d498f2011-05-27 07:25:51 +0800955 if ((popts->data_bus_width == 1) || (popts->data_bus_width == 2)) {
956 /* 32-bit or 16-bit bus */
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530957 popts->otf_burst_chop_en = 0;
York Sune090aa72011-05-27 07:25:48 +0800958 popts->burst_length = DDR_BL8;
959 } else {
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530960 popts->otf_burst_chop_en = 1; /* on-the-fly burst chop */
York Sune090aa72011-05-27 07:25:48 +0800961 popts->burst_length = DDR_OTF; /* on-the-fly BC4 and BL8 */
962 }
Dave Liu22c9de02010-03-05 12:22:00 +0800963#endif
Dave Liuc360cea2009-03-14 12:48:30 +0800964#else
965 popts->burst_length = DDR_BL4; /* has to be 4 for DDR2 */
966#endif
967
968 /* Choose ddr controller address mirror mode */
York Sun34e026f2014-03-27 17:54:47 -0700969#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
York Sun6b95be22015-03-19 09:30:27 -0700970 for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
971 if (pdimm[i].n_ranks) {
972 popts->mirrored_dimm = pdimm[i].mirrored_dimm;
973 break;
974 }
975 }
Dave Liuc360cea2009-03-14 12:48:30 +0800976#endif
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500977
978 /* Global Timing Parameters. */
York Sun03e664d2015-01-06 13:18:50 -0800979 debug("mclk_ps = %u ps\n", get_memory_clk_period_ps(ctrl_num));
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500980
981 /* Pick a caslat override. */
982 popts->cas_latency_override = 0;
983 popts->cas_latency_override_value = 3;
984 if (popts->cas_latency_override) {
985 debug("using caslat override value = %u\n",
986 popts->cas_latency_override_value);
987 }
988
989 /* Decide whether to use the computed derated latency */
990 popts->use_derated_caslat = 0;
991
992 /* Choose an additive latency. */
993 popts->additive_latency_override = 0;
994 popts->additive_latency_override_value = 3;
995 if (popts->additive_latency_override) {
996 debug("using additive latency override value = %u\n",
997 popts->additive_latency_override_value);
998 }
999
1000 /*
1001 * 2T_EN setting
1002 *
1003 * Factors to consider for 2T_EN:
1004 * - number of DIMMs installed
1005 * - number of components, number of active ranks
1006 * - how much time you want to spend playing around
1007 */
Priyanka Jain0dd38a32013-09-25 10:41:19 +05301008 popts->twot_en = 0;
1009 popts->threet_en = 0;
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001010
Shengzhou Liueb118802016-03-10 17:36:56 +08001011 /* for RDIMM and DDR4 UDIMM/discrete memory, address parity enable */
1012 if (popts->registered_dimm_en)
1013 popts->ap_en = 1; /* 0 = disable, 1 = enable */
1014 else
1015 popts->ap_en = 0; /* disabled for DDR4 UDIMM/discrete default */
1016
1017 if (hwconfig_sub_f("fsl_ddr", "parity", buf)) {
1018 if (hwconfig_subarg_cmp_f("fsl_ddr", "parity", "on", buf)) {
1019 if (popts->registered_dimm_en ||
1020 (CONFIG_FSL_SDRAM_TYPE == SDRAM_TYPE_DDR4))
1021 popts->ap_en = 1;
1022 }
1023 }
York Sune1fd16b2011-01-10 12:03:00 +00001024
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001025 /*
1026 * BSTTOPRE precharge interval
1027 *
1028 * Set this to 0 for global auto precharge
York Sun34e026f2014-03-27 17:54:47 -07001029 * The value of 0x100 has been used for DDR1, DDR2, DDR3.
1030 * It is not wrong. Any value should be OK. The performance depends on
York Sun56848422015-07-23 14:04:48 -07001031 * applications. There is no one good value for all. One way to set
1032 * is to use 1/4 of refint value.
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001033 */
York Sun56848422015-07-23 14:04:48 -07001034 popts->bstopre = picos_to_mclk(ctrl_num, common_dimm->refresh_rate_ps)
1035 >> 2;
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001036
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001037 /*
1038 * Window for four activates -- tFAW
1039 *
1040 * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
1041 * FIXME: varies depending upon number of column addresses or data
1042 * FIXME: width, was considering looking at pdimm->primary_sdram_width
1043 */
York Sun5614e712013-09-30 09:22:09 -07001044#if defined(CONFIG_SYS_FSL_DDR1)
York Sun03e664d2015-01-06 13:18:50 -08001045 popts->tfaw_window_four_activates_ps = mclk_to_picos(ctrl_num, 1);
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001046
York Sun5614e712013-09-30 09:22:09 -07001047#elif defined(CONFIG_SYS_FSL_DDR2)
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001048 /*
1049 * x4/x8; some datasheets have 35000
1050 * x16 wide columns only? Use 50000?
1051 */
Priyanka Jain0dd38a32013-09-25 10:41:19 +05301052 popts->tfaw_window_four_activates_ps = 37500;
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001053
York Sun34e026f2014-03-27 17:54:47 -07001054#else
Priyanka Jain0dd38a32013-09-25 10:41:19 +05301055 popts->tfaw_window_four_activates_ps = pdimm[0].tfaw_ps;
Dave Liuc360cea2009-03-14 12:48:30 +08001056#endif
1057 popts->zq_en = 0;
1058 popts->wrlvl_en = 0;
York Sun34e026f2014-03-27 17:54:47 -07001059#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
Dave Liuc360cea2009-03-14 12:48:30 +08001060 /*
1061 * due to ddr3 dimm is fly-by topology
1062 * we suggest to enable write leveling to
1063 * meet the tQDSS under different loading.
1064 */
1065 popts->wrlvl_en = 1;
york5fb8a8a2010-07-02 22:25:56 +00001066 popts->zq_en = 1;
Dave Liubdc9f7b2009-12-16 10:24:37 -06001067 popts->wrlvl_override = 0;
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001068#endif
1069
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001070 /*
Haiying Wangc9ffd832008-10-03 12:37:10 -04001071 * Check interleaving configuration from environment.
1072 * Please refer to doc/README.fsl-ddr for the detail.
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001073 *
1074 * If memory controller interleaving is enabled, then the data
york076bff82010-07-02 22:25:52 +00001075 * bus widths must be programmed identically for all memory controllers.
Haiying Wangc9ffd832008-10-03 12:37:10 -04001076 *
York Sun6b1e1252014-02-10 13:59:44 -08001077 * Attempt to set all controllers to the same chip select
Haiying Wangc9ffd832008-10-03 12:37:10 -04001078 * interleaving mode. It will do a best effort to get the
1079 * requested ranks interleaved together such that the result
1080 * should be a subset of the requested configuration.
York Sun6b1e1252014-02-10 13:59:44 -08001081 *
1082 * if CONFIG_SYS_FSL_DDR_INTLV_256B is defined, mandatory interleaving
1083 * with 256 Byte is enabled.
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001084 */
York Sun51370d52016-12-28 08:43:45 -08001085#if (CONFIG_SYS_NUM_DDR_CTLRS > 1)
York Suna4c66502012-08-17 08:22:39 +00001086 if (!hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf))
York Sun6b1e1252014-02-10 13:59:44 -08001087#ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
1088 ;
1089#else
York Suna4c66502012-08-17 08:22:39 +00001090 goto done;
York Sun6b1e1252014-02-10 13:59:44 -08001091#endif
York Suna4c66502012-08-17 08:22:39 +00001092 if (pdimm[0].n_ranks == 0) {
1093 printf("There is no rank on CS0 for controller %d.\n", ctrl_num);
1094 popts->memctl_interleaving = 0;
1095 goto done;
Haiying Wangc9ffd832008-10-03 12:37:10 -04001096 }
York Suna4c66502012-08-17 08:22:39 +00001097 popts->memctl_interleaving = 1;
York Sun6b1e1252014-02-10 13:59:44 -08001098#ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
1099 popts->memctl_interleaving_mode = FSL_DDR_256B_INTERLEAVING;
1100 popts->memctl_interleaving = 1;
1101 debug("256 Byte interleaving\n");
York Sun349689b2014-04-01 14:20:49 -07001102#else
York Suna4c66502012-08-17 08:22:39 +00001103 /*
1104 * test null first. if CONFIG_HWCONFIG is not defined
1105 * hwconfig_arg_cmp returns non-zero
1106 */
1107 if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
1108 "null", buf)) {
1109 popts->memctl_interleaving = 0;
1110 debug("memory controller interleaving disabled.\n");
1111 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1112 "ctlr_intlv",
1113 "cacheline", buf)) {
1114 popts->memctl_interleaving_mode =
York Sun51370d52016-12-28 08:43:45 -08001115 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001116 0 : FSL_DDR_CACHE_LINE_INTERLEAVING;
1117 popts->memctl_interleaving =
York Sun51370d52016-12-28 08:43:45 -08001118 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001119 0 : 1;
1120 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1121 "ctlr_intlv",
1122 "page", buf)) {
1123 popts->memctl_interleaving_mode =
York Sun51370d52016-12-28 08:43:45 -08001124 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001125 0 : FSL_DDR_PAGE_INTERLEAVING;
1126 popts->memctl_interleaving =
York Sun51370d52016-12-28 08:43:45 -08001127 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001128 0 : 1;
1129 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1130 "ctlr_intlv",
1131 "bank", buf)) {
1132 popts->memctl_interleaving_mode =
York Sun51370d52016-12-28 08:43:45 -08001133 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001134 0 : FSL_DDR_BANK_INTERLEAVING;
1135 popts->memctl_interleaving =
York Sun51370d52016-12-28 08:43:45 -08001136 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001137 0 : 1;
1138 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1139 "ctlr_intlv",
1140 "superbank", buf)) {
1141 popts->memctl_interleaving_mode =
York Sun51370d52016-12-28 08:43:45 -08001142 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001143 0 : FSL_DDR_SUPERBANK_INTERLEAVING;
1144 popts->memctl_interleaving =
York Sun51370d52016-12-28 08:43:45 -08001145 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001146 0 : 1;
York Sun51370d52016-12-28 08:43:45 -08001147#if (CONFIG_SYS_NUM_DDR_CTLRS == 3)
York Suna4c66502012-08-17 08:22:39 +00001148 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1149 "ctlr_intlv",
1150 "3way_1KB", buf)) {
1151 popts->memctl_interleaving_mode =
1152 FSL_DDR_3WAY_1KB_INTERLEAVING;
1153 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1154 "ctlr_intlv",
1155 "3way_4KB", buf)) {
1156 popts->memctl_interleaving_mode =
1157 FSL_DDR_3WAY_4KB_INTERLEAVING;
1158 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1159 "ctlr_intlv",
1160 "3way_8KB", buf)) {
1161 popts->memctl_interleaving_mode =
1162 FSL_DDR_3WAY_8KB_INTERLEAVING;
York Sun51370d52016-12-28 08:43:45 -08001163#elif (CONFIG_SYS_NUM_DDR_CTLRS == 4)
York Suna4c66502012-08-17 08:22:39 +00001164 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1165 "ctlr_intlv",
1166 "4way_1KB", buf)) {
1167 popts->memctl_interleaving_mode =
1168 FSL_DDR_4WAY_1KB_INTERLEAVING;
1169 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1170 "ctlr_intlv",
1171 "4way_4KB", buf)) {
1172 popts->memctl_interleaving_mode =
1173 FSL_DDR_4WAY_4KB_INTERLEAVING;
1174 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1175 "ctlr_intlv",
1176 "4way_8KB", buf)) {
1177 popts->memctl_interleaving_mode =
1178 FSL_DDR_4WAY_8KB_INTERLEAVING;
1179#endif
1180 } else {
1181 popts->memctl_interleaving = 0;
1182 printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
1183 }
York Sun349689b2014-04-01 14:20:49 -07001184#endif /* CONFIG_SYS_FSL_DDR_INTLV_256B */
York Suna4c66502012-08-17 08:22:39 +00001185done:
York Sun51370d52016-12-28 08:43:45 -08001186#endif /* CONFIG_SYS_NUM_DDR_CTLRS > 1 */
Kumar Galadd50af22011-01-09 11:37:00 -06001187 if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) &&
Dave Liu3ad95de2009-11-12 07:26:37 +08001188 (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) {
Kumar Gala79e4e642010-07-14 10:04:21 -05001189 /* test null first. if CONFIG_HWCONFIG is not defined,
Kumar Galadd50af22011-01-09 11:37:00 -06001190 * hwconfig_subarg_cmp_f returns non-zero */
1191 if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1192 "null", buf))
york076bff82010-07-02 22:25:52 +00001193 debug("bank interleaving disabled.\n");
Kumar Galadd50af22011-01-09 11:37:00 -06001194 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1195 "cs0_cs1", buf))
Haiying Wangc9ffd832008-10-03 12:37:10 -04001196 popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
Kumar Galadd50af22011-01-09 11:37:00 -06001197 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1198 "cs2_cs3", buf))
Haiying Wangc9ffd832008-10-03 12:37:10 -04001199 popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
Kumar Galadd50af22011-01-09 11:37:00 -06001200 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1201 "cs0_cs1_and_cs2_cs3", buf))
Haiying Wangc9ffd832008-10-03 12:37:10 -04001202 popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
Kumar Galadd50af22011-01-09 11:37:00 -06001203 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1204 "cs0_cs1_cs2_cs3", buf))
Haiying Wangc9ffd832008-10-03 12:37:10 -04001205 popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
York Sun89b78092012-10-08 07:44:27 +00001206 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1207 "auto", buf))
1208 popts->ba_intlv_ctl = auto_bank_intlv(pdimm);
Haiying Wangc9ffd832008-10-03 12:37:10 -04001209 else
york076bff82010-07-02 22:25:52 +00001210 printf("hwconfig has unrecognized parameter for bank_intlv.\n");
Haiying Wangc9ffd832008-10-03 12:37:10 -04001211 switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
1212 case FSL_DDR_CS0_CS1_CS2_CS3:
york076bff82010-07-02 22:25:52 +00001213#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
york5800e7a2010-07-02 22:25:53 +00001214 if (pdimm[0].n_ranks < 4) {
york076bff82010-07-02 22:25:52 +00001215 popts->ba_intlv_ctl = 0;
1216 printf("Not enough bank(chip-select) for "
1217 "CS0+CS1+CS2+CS3 on controller %d, "
York Suna4c66502012-08-17 08:22:39 +00001218 "interleaving disabled!\n", ctrl_num);
york076bff82010-07-02 22:25:52 +00001219 }
1220#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
York Sun123922b2012-10-08 07:44:23 +00001221#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
1222 if (pdimm[0].n_ranks == 4)
1223 break;
1224#endif
york5800e7a2010-07-02 22:25:53 +00001225 if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) {
york076bff82010-07-02 22:25:52 +00001226 popts->ba_intlv_ctl = 0;
1227 printf("Not enough bank(chip-select) for "
1228 "CS0+CS1+CS2+CS3 on controller %d, "
York Suna4c66502012-08-17 08:22:39 +00001229 "interleaving disabled!\n", ctrl_num);
york076bff82010-07-02 22:25:52 +00001230 }
1231 if (pdimm[0].capacity != pdimm[1].capacity) {
1232 popts->ba_intlv_ctl = 0;
1233 printf("Not identical DIMM size for "
1234 "CS0+CS1+CS2+CS3 on controller %d, "
York Suna4c66502012-08-17 08:22:39 +00001235 "interleaving disabled!\n", ctrl_num);
york076bff82010-07-02 22:25:52 +00001236 }
1237#endif
1238 break;
Haiying Wangc9ffd832008-10-03 12:37:10 -04001239 case FSL_DDR_CS0_CS1:
york5800e7a2010-07-02 22:25:53 +00001240 if (pdimm[0].n_ranks < 2) {
Haiying Wangc9ffd832008-10-03 12:37:10 -04001241 popts->ba_intlv_ctl = 0;
Ed Swarthout7008d262008-10-29 09:21:44 -05001242 printf("Not enough bank(chip-select) for "
york076bff82010-07-02 22:25:52 +00001243 "CS0+CS1 on controller %d, "
York Suna4c66502012-08-17 08:22:39 +00001244 "interleaving disabled!\n", ctrl_num);
Haiying Wangc9ffd832008-10-03 12:37:10 -04001245 }
1246 break;
1247 case FSL_DDR_CS2_CS3:
york076bff82010-07-02 22:25:52 +00001248#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
york5800e7a2010-07-02 22:25:53 +00001249 if (pdimm[0].n_ranks < 4) {
Haiying Wangc9ffd832008-10-03 12:37:10 -04001250 popts->ba_intlv_ctl = 0;
york076bff82010-07-02 22:25:52 +00001251 printf("Not enough bank(chip-select) for CS2+CS3 "
York Suna4c66502012-08-17 08:22:39 +00001252 "on controller %d, interleaving disabled!\n", ctrl_num);
Haiying Wangc9ffd832008-10-03 12:37:10 -04001253 }
york076bff82010-07-02 22:25:52 +00001254#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
york5800e7a2010-07-02 22:25:53 +00001255 if (pdimm[1].n_ranks < 2) {
york076bff82010-07-02 22:25:52 +00001256 popts->ba_intlv_ctl = 0;
1257 printf("Not enough bank(chip-select) for CS2+CS3 "
York Suna4c66502012-08-17 08:22:39 +00001258 "on controller %d, interleaving disabled!\n", ctrl_num);
york076bff82010-07-02 22:25:52 +00001259 }
1260#endif
Haiying Wangc9ffd832008-10-03 12:37:10 -04001261 break;
1262 case FSL_DDR_CS0_CS1_AND_CS2_CS3:
york076bff82010-07-02 22:25:52 +00001263#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
york5800e7a2010-07-02 22:25:53 +00001264 if (pdimm[0].n_ranks < 4) {
york076bff82010-07-02 22:25:52 +00001265 popts->ba_intlv_ctl = 0;
1266 printf("Not enough bank(CS) for CS0+CS1 and "
1267 "CS2+CS3 on controller %d, "
York Suna4c66502012-08-17 08:22:39 +00001268 "interleaving disabled!\n", ctrl_num);
york076bff82010-07-02 22:25:52 +00001269 }
1270#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
york5800e7a2010-07-02 22:25:53 +00001271 if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) {
Haiying Wangc9ffd832008-10-03 12:37:10 -04001272 popts->ba_intlv_ctl = 0;
york076bff82010-07-02 22:25:52 +00001273 printf("Not enough bank(CS) for CS0+CS1 and "
1274 "CS2+CS3 on controller %d, "
York Suna4c66502012-08-17 08:22:39 +00001275 "interleaving disabled!\n", ctrl_num);
Haiying Wangc9ffd832008-10-03 12:37:10 -04001276 }
york076bff82010-07-02 22:25:52 +00001277#endif
Haiying Wangc9ffd832008-10-03 12:37:10 -04001278 break;
1279 default:
1280 popts->ba_intlv_ctl = 0;
1281 break;
1282 }
1283 }
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001284
Kumar Galadd50af22011-01-09 11:37:00 -06001285 if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf)) {
1286 if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf))
york7fd101c2010-07-02 22:25:54 +00001287 popts->addr_hash = 0;
Kumar Galadd50af22011-01-09 11:37:00 -06001288 else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash",
1289 "true", buf))
york7fd101c2010-07-02 22:25:54 +00001290 popts->addr_hash = 1;
1291 }
1292
york5800e7a2010-07-02 22:25:53 +00001293 if (pdimm[0].n_ranks == 4)
1294 popts->quad_rank_present = 1;
1295
York Sunc0c32af2018-01-29 09:44:35 -08001296 popts->package_3ds = pdimm->package_3ds;
1297
York Sun03e664d2015-01-06 13:18:50 -08001298 ddr_freq = get_ddr_freq(ctrl_num) / 1000000;
York Suncda1de22011-08-24 09:40:26 -07001299 if (popts->registered_dimm_en) {
1300 popts->rcw_override = 1;
1301 popts->rcw_1 = 0x000a5a00;
1302 if (ddr_freq <= 800)
1303 popts->rcw_2 = 0x00000000;
1304 else if (ddr_freq <= 1066)
1305 popts->rcw_2 = 0x00100000;
1306 else if (ddr_freq <= 1333)
1307 popts->rcw_2 = 0x00200000;
1308 else
1309 popts->rcw_2 = 0x00300000;
1310 }
1311
Haiying Wangdfb49102008-10-03 12:36:55 -04001312 fsl_ddr_board_options(popts, pdimm, ctrl_num);
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001313
1314 return 0;
1315}
york076bff82010-07-02 22:25:52 +00001316
1317void check_interleaving_options(fsl_ddr_info_t *pinfo)
1318{
York Suna4c66502012-08-17 08:22:39 +00001319 int i, j, k, check_n_ranks, intlv_invalid = 0;
1320 unsigned int check_intlv, check_n_row_addr, check_n_col_addr;
york076bff82010-07-02 22:25:52 +00001321 unsigned long long check_rank_density;
York Suna4c66502012-08-17 08:22:39 +00001322 struct dimm_params_s *dimm;
York Sun1d71efb2014-08-01 15:51:00 -07001323 int first_ctrl = pinfo->first_ctrl;
1324 int last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
1325
york076bff82010-07-02 22:25:52 +00001326 /*
1327 * Check if all controllers are configured for memory
1328 * controller interleaving. Identical dimms are recommended. At least
York Suna4c66502012-08-17 08:22:39 +00001329 * the size, row and col address should be checked.
york076bff82010-07-02 22:25:52 +00001330 */
1331 j = 0;
York Sun1d71efb2014-08-01 15:51:00 -07001332 check_n_ranks = pinfo->dimm_params[first_ctrl][0].n_ranks;
1333 check_rank_density = pinfo->dimm_params[first_ctrl][0].rank_density;
1334 check_n_row_addr = pinfo->dimm_params[first_ctrl][0].n_row_addr;
1335 check_n_col_addr = pinfo->dimm_params[first_ctrl][0].n_col_addr;
1336 check_intlv = pinfo->memctl_opts[first_ctrl].memctl_interleaving_mode;
1337 for (i = first_ctrl; i <= last_ctrl; i++) {
York Suna4c66502012-08-17 08:22:39 +00001338 dimm = &pinfo->dimm_params[i][0];
1339 if (!pinfo->memctl_opts[i].memctl_interleaving) {
1340 continue;
1341 } else if (((check_rank_density != dimm->rank_density) ||
1342 (check_n_ranks != dimm->n_ranks) ||
1343 (check_n_row_addr != dimm->n_row_addr) ||
1344 (check_n_col_addr != dimm->n_col_addr) ||
1345 (check_intlv !=
1346 pinfo->memctl_opts[i].memctl_interleaving_mode))){
1347 intlv_invalid = 1;
1348 break;
1349 } else {
york076bff82010-07-02 22:25:52 +00001350 j++;
1351 }
York Suna4c66502012-08-17 08:22:39 +00001352
york076bff82010-07-02 22:25:52 +00001353 }
York Suna4c66502012-08-17 08:22:39 +00001354 if (intlv_invalid) {
York Sun1d71efb2014-08-01 15:51:00 -07001355 for (i = first_ctrl; i <= last_ctrl; i++)
York Suna4c66502012-08-17 08:22:39 +00001356 pinfo->memctl_opts[i].memctl_interleaving = 0;
1357 printf("Not all DIMMs are identical. "
1358 "Memory controller interleaving disabled.\n");
1359 } else {
1360 switch (check_intlv) {
York Sun6b1e1252014-02-10 13:59:44 -08001361 case FSL_DDR_256B_INTERLEAVING:
York Suna4c66502012-08-17 08:22:39 +00001362 case FSL_DDR_CACHE_LINE_INTERLEAVING:
1363 case FSL_DDR_PAGE_INTERLEAVING:
1364 case FSL_DDR_BANK_INTERLEAVING:
1365 case FSL_DDR_SUPERBANK_INTERLEAVING:
York Sun51370d52016-12-28 08:43:45 -08001366#if (3 == CONFIG_SYS_NUM_DDR_CTLRS)
York Suna4c66502012-08-17 08:22:39 +00001367 k = 2;
York Sun349689b2014-04-01 14:20:49 -07001368#else
York Sun51370d52016-12-28 08:43:45 -08001369 k = CONFIG_SYS_NUM_DDR_CTLRS;
York Sun349689b2014-04-01 14:20:49 -07001370#endif
York Suna4c66502012-08-17 08:22:39 +00001371 break;
1372 case FSL_DDR_3WAY_1KB_INTERLEAVING:
1373 case FSL_DDR_3WAY_4KB_INTERLEAVING:
1374 case FSL_DDR_3WAY_8KB_INTERLEAVING:
1375 case FSL_DDR_4WAY_1KB_INTERLEAVING:
1376 case FSL_DDR_4WAY_4KB_INTERLEAVING:
1377 case FSL_DDR_4WAY_8KB_INTERLEAVING:
1378 default:
York Sun51370d52016-12-28 08:43:45 -08001379 k = CONFIG_SYS_NUM_DDR_CTLRS;
York Suna4c66502012-08-17 08:22:39 +00001380 break;
1381 }
1382 debug("%d of %d controllers are interleaving.\n", j, k);
York Sun89b78092012-10-08 07:44:27 +00001383 if (j && (j != k)) {
York Sun1d71efb2014-08-01 15:51:00 -07001384 for (i = first_ctrl; i <= last_ctrl; i++)
york076bff82010-07-02 22:25:52 +00001385 pinfo->memctl_opts[i].memctl_interleaving = 0;
York Sun1d71efb2014-08-01 15:51:00 -07001386 if ((last_ctrl - first_ctrl) > 1)
1387 puts("Not all controllers have compatible interleaving mode. All disabled.\n");
York Suna4c66502012-08-17 08:22:39 +00001388 }
york076bff82010-07-02 22:25:52 +00001389 }
York Suna4c66502012-08-17 08:22:39 +00001390 debug("Checking interleaving options completed\n");
york076bff82010-07-02 22:25:52 +00001391}
Kumar Gala3dbd5d72011-01-09 14:06:28 -06001392
1393int fsl_use_spd(void)
1394{
1395 int use_spd = 0;
1396
1397#ifdef CONFIG_DDR_SPD
Kumar Galadd50af22011-01-09 11:37:00 -06001398 char buffer[HWCONFIG_BUFFER_SIZE];
1399 char *buf = NULL;
1400
1401 /*
1402 * Extract hwconfig from environment since we have not properly setup
1403 * the environment but need it for ddr config params
1404 */
Simon Glass00caae62017-08-03 12:22:12 -06001405 if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
Kumar Galadd50af22011-01-09 11:37:00 -06001406 buf = buffer;
1407
Kumar Gala3dbd5d72011-01-09 14:06:28 -06001408 /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
Kumar Galadd50af22011-01-09 11:37:00 -06001409 if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) {
1410 if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf))
Kumar Gala3dbd5d72011-01-09 14:06:28 -06001411 use_spd = 1;
Kumar Galadd50af22011-01-09 11:37:00 -06001412 else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram",
1413 "fixed", buf))
Kumar Gala3dbd5d72011-01-09 14:06:28 -06001414 use_spd = 0;
1415 else
1416 use_spd = 1;
1417 } else
1418 use_spd = 1;
1419#endif
1420
1421 return use_spd;
1422}