blob: b9179315f2522ac81fe93fa7d5ba4b6a5e11afa8 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kumar Gala58e5e9a2008-08-26 15:01:29 -05002/*
York Sunc0c32af2018-01-29 09:44:35 -08003 * Copyright 2008, 2010-2016 Freescale Semiconductor, Inc.
4 * Copyright 2017-2018 NXP Semiconductor
Kumar Gala58e5e9a2008-08-26 15:01:29 -05005 */
6
7#include <common.h>
Simon Glass3a7d5572019-08-01 09:46:42 -06008#include <env.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 */
Priyanka Jain50dcbd12018-10-29 09:37:36 +000026void __weak fsl_ddr_board_options(memctl_options_t *popts,
27 dimm_params_t *pdimm,
28 unsigned int ctrl_num)
29{
30 return;
31}
Kumar Gala58e5e9a2008-08-26 15:01:29 -050032
York Sun4e573822011-08-26 11:32:43 -070033struct dynamic_odt {
York Sune1fd16b2011-01-10 12:03:00 +000034 unsigned int odt_rd_cfg;
35 unsigned int odt_wr_cfg;
36 unsigned int odt_rtt_norm;
37 unsigned int odt_rtt_wr;
York Sun4e573822011-08-26 11:32:43 -070038};
York Sune1fd16b2011-01-10 12:03:00 +000039
York Sun19601dd2015-11-04 10:03:17 -080040#ifdef CONFIG_SYS_FSL_DDR4
41/* Quad rank is not verified yet due availability.
42 * Replacing 20 OHM with 34 OHM since DDR4 doesn't have 20 OHM option
43 */
Thomas Schaefer97fbf262017-03-28 11:29:56 -070044static __maybe_unused const struct dynamic_odt single_Q[4] = {
York Sun19601dd2015-11-04 10:03:17 -080045 { /* cs0 */
46 FSL_DDR_ODT_NEVER,
47 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
48 DDR4_RTT_34_OHM, /* unverified */
49 DDR4_RTT_120_OHM
50 },
51 { /* cs1 */
52 FSL_DDR_ODT_NEVER,
53 FSL_DDR_ODT_NEVER,
54 DDR4_RTT_OFF,
55 DDR4_RTT_120_OHM
56 },
57 { /* cs2 */
58 FSL_DDR_ODT_NEVER,
59 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
60 DDR4_RTT_34_OHM,
61 DDR4_RTT_120_OHM
62 },
63 { /* cs3 */
64 FSL_DDR_ODT_NEVER,
65 FSL_DDR_ODT_NEVER, /* tied high */
66 DDR4_RTT_OFF,
67 DDR4_RTT_120_OHM
68 }
69};
70
Thomas Schaefer97fbf262017-03-28 11:29:56 -070071static __maybe_unused const struct dynamic_odt single_D[4] = {
York Sun19601dd2015-11-04 10:03:17 -080072 { /* cs0 */
73 FSL_DDR_ODT_NEVER,
74 FSL_DDR_ODT_ALL,
75 DDR4_RTT_40_OHM,
76 DDR4_RTT_OFF
77 },
78 { /* cs1 */
79 FSL_DDR_ODT_NEVER,
80 FSL_DDR_ODT_NEVER,
81 DDR4_RTT_OFF,
82 DDR4_RTT_OFF
83 },
84 {0, 0, 0, 0},
85 {0, 0, 0, 0}
86};
87
Thomas Schaefer97fbf262017-03-28 11:29:56 -070088static __maybe_unused const struct dynamic_odt single_S[4] = {
York Sun19601dd2015-11-04 10:03:17 -080089 { /* cs0 */
90 FSL_DDR_ODT_NEVER,
91 FSL_DDR_ODT_ALL,
92 DDR4_RTT_40_OHM,
93 DDR4_RTT_OFF
94 },
95 {0, 0, 0, 0},
96 {0, 0, 0, 0},
97 {0, 0, 0, 0},
98};
99
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700100static __maybe_unused const struct dynamic_odt dual_DD[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800101 { /* cs0 */
102 FSL_DDR_ODT_NEVER,
103 FSL_DDR_ODT_SAME_DIMM,
104 DDR4_RTT_120_OHM,
105 DDR4_RTT_OFF
106 },
107 { /* cs1 */
108 FSL_DDR_ODT_OTHER_DIMM,
109 FSL_DDR_ODT_OTHER_DIMM,
110 DDR4_RTT_34_OHM,
111 DDR4_RTT_OFF
112 },
113 { /* cs2 */
114 FSL_DDR_ODT_NEVER,
115 FSL_DDR_ODT_SAME_DIMM,
116 DDR4_RTT_120_OHM,
117 DDR4_RTT_OFF
118 },
119 { /* cs3 */
120 FSL_DDR_ODT_OTHER_DIMM,
121 FSL_DDR_ODT_OTHER_DIMM,
122 DDR4_RTT_34_OHM,
123 DDR4_RTT_OFF
124 }
125};
126
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700127static __maybe_unused const struct dynamic_odt dual_DS[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800128 { /* cs0 */
129 FSL_DDR_ODT_NEVER,
130 FSL_DDR_ODT_SAME_DIMM,
131 DDR4_RTT_120_OHM,
132 DDR4_RTT_OFF
133 },
134 { /* cs1 */
135 FSL_DDR_ODT_OTHER_DIMM,
136 FSL_DDR_ODT_OTHER_DIMM,
137 DDR4_RTT_34_OHM,
138 DDR4_RTT_OFF
139 },
140 { /* cs2 */
141 FSL_DDR_ODT_OTHER_DIMM,
142 FSL_DDR_ODT_ALL,
143 DDR4_RTT_34_OHM,
144 DDR4_RTT_120_OHM
145 },
146 {0, 0, 0, 0}
147};
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700148static __maybe_unused const struct dynamic_odt dual_SD[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800149 { /* cs0 */
150 FSL_DDR_ODT_OTHER_DIMM,
151 FSL_DDR_ODT_ALL,
152 DDR4_RTT_34_OHM,
153 DDR4_RTT_120_OHM
154 },
155 {0, 0, 0, 0},
156 { /* cs2 */
157 FSL_DDR_ODT_NEVER,
158 FSL_DDR_ODT_SAME_DIMM,
159 DDR4_RTT_120_OHM,
160 DDR4_RTT_OFF
161 },
162 { /* cs3 */
163 FSL_DDR_ODT_OTHER_DIMM,
164 FSL_DDR_ODT_OTHER_DIMM,
165 DDR4_RTT_34_OHM,
166 DDR4_RTT_OFF
167 }
168};
169
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700170static __maybe_unused const struct dynamic_odt dual_SS[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800171 { /* cs0 */
172 FSL_DDR_ODT_OTHER_DIMM,
173 FSL_DDR_ODT_ALL,
174 DDR4_RTT_34_OHM,
175 DDR4_RTT_120_OHM
176 },
177 {0, 0, 0, 0},
178 { /* cs2 */
179 FSL_DDR_ODT_OTHER_DIMM,
180 FSL_DDR_ODT_ALL,
181 DDR4_RTT_34_OHM,
182 DDR4_RTT_120_OHM
183 },
184 {0, 0, 0, 0}
185};
186
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700187static __maybe_unused const struct dynamic_odt dual_D0[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800188 { /* cs0 */
189 FSL_DDR_ODT_NEVER,
190 FSL_DDR_ODT_SAME_DIMM,
191 DDR4_RTT_40_OHM,
192 DDR4_RTT_OFF
193 },
194 { /* cs1 */
195 FSL_DDR_ODT_NEVER,
196 FSL_DDR_ODT_NEVER,
197 DDR4_RTT_OFF,
198 DDR4_RTT_OFF
199 },
200 {0, 0, 0, 0},
201 {0, 0, 0, 0}
202};
203
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700204static __maybe_unused const struct dynamic_odt dual_0D[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800205 {0, 0, 0, 0},
206 {0, 0, 0, 0},
207 { /* cs2 */
208 FSL_DDR_ODT_NEVER,
209 FSL_DDR_ODT_SAME_DIMM,
210 DDR4_RTT_40_OHM,
211 DDR4_RTT_OFF
212 },
213 { /* cs3 */
214 FSL_DDR_ODT_NEVER,
215 FSL_DDR_ODT_NEVER,
216 DDR4_RTT_OFF,
217 DDR4_RTT_OFF
218 }
219};
220
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700221static __maybe_unused const struct dynamic_odt dual_S0[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800222 { /* cs0 */
223 FSL_DDR_ODT_NEVER,
224 FSL_DDR_ODT_CS,
225 DDR4_RTT_40_OHM,
226 DDR4_RTT_OFF
227 },
228 {0, 0, 0, 0},
229 {0, 0, 0, 0},
230 {0, 0, 0, 0}
231
232};
233
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700234static __maybe_unused const struct dynamic_odt dual_0S[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800235 {0, 0, 0, 0},
236 {0, 0, 0, 0},
237 { /* cs2 */
238 FSL_DDR_ODT_NEVER,
239 FSL_DDR_ODT_CS,
240 DDR4_RTT_40_OHM,
241 DDR4_RTT_OFF
242 },
243 {0, 0, 0, 0}
244
245};
246
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700247static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
York Sun19601dd2015-11-04 10:03:17 -0800248 { /* cs0 */
249 FSL_DDR_ODT_NEVER,
250 FSL_DDR_ODT_CS,
251 DDR4_RTT_120_OHM,
252 DDR4_RTT_OFF
253 },
254 { /* cs1 */
255 FSL_DDR_ODT_NEVER,
256 FSL_DDR_ODT_CS,
257 DDR4_RTT_120_OHM,
258 DDR4_RTT_OFF
259 },
260 { /* cs2 */
261 FSL_DDR_ODT_NEVER,
262 FSL_DDR_ODT_CS,
263 DDR4_RTT_120_OHM,
264 DDR4_RTT_OFF
265 },
266 { /* cs3 */
267 FSL_DDR_ODT_NEVER,
268 FSL_DDR_ODT_CS,
269 DDR4_RTT_120_OHM,
270 DDR4_RTT_OFF
271 }
272};
273#elif defined(CONFIG_SYS_FSL_DDR3)
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700274static __maybe_unused const struct dynamic_odt single_Q[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000275 { /* cs0 */
276 FSL_DDR_ODT_NEVER,
277 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
278 DDR3_RTT_20_OHM,
279 DDR3_RTT_120_OHM
280 },
281 { /* cs1 */
282 FSL_DDR_ODT_NEVER,
283 FSL_DDR_ODT_NEVER, /* tied high */
284 DDR3_RTT_OFF,
285 DDR3_RTT_120_OHM
286 },
287 { /* cs2 */
288 FSL_DDR_ODT_NEVER,
289 FSL_DDR_ODT_CS_AND_OTHER_DIMM,
290 DDR3_RTT_20_OHM,
291 DDR3_RTT_120_OHM
292 },
293 { /* cs3 */
294 FSL_DDR_ODT_NEVER,
295 FSL_DDR_ODT_NEVER, /* tied high */
296 DDR3_RTT_OFF,
297 DDR3_RTT_120_OHM
298 }
299};
300
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700301static __maybe_unused const struct dynamic_odt single_D[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000302 { /* cs0 */
303 FSL_DDR_ODT_NEVER,
304 FSL_DDR_ODT_ALL,
305 DDR3_RTT_40_OHM,
306 DDR3_RTT_OFF
307 },
308 { /* cs1 */
309 FSL_DDR_ODT_NEVER,
310 FSL_DDR_ODT_NEVER,
311 DDR3_RTT_OFF,
312 DDR3_RTT_OFF
313 },
314 {0, 0, 0, 0},
315 {0, 0, 0, 0}
316};
317
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700318static __maybe_unused const struct dynamic_odt single_S[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000319 { /* cs0 */
320 FSL_DDR_ODT_NEVER,
321 FSL_DDR_ODT_ALL,
322 DDR3_RTT_40_OHM,
323 DDR3_RTT_OFF
324 },
325 {0, 0, 0, 0},
326 {0, 0, 0, 0},
327 {0, 0, 0, 0},
328};
329
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700330static __maybe_unused const struct dynamic_odt dual_DD[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000331 { /* cs0 */
332 FSL_DDR_ODT_NEVER,
333 FSL_DDR_ODT_SAME_DIMM,
334 DDR3_RTT_120_OHM,
335 DDR3_RTT_OFF
336 },
337 { /* cs1 */
338 FSL_DDR_ODT_OTHER_DIMM,
339 FSL_DDR_ODT_OTHER_DIMM,
340 DDR3_RTT_30_OHM,
341 DDR3_RTT_OFF
342 },
343 { /* cs2 */
344 FSL_DDR_ODT_NEVER,
345 FSL_DDR_ODT_SAME_DIMM,
346 DDR3_RTT_120_OHM,
347 DDR3_RTT_OFF
348 },
349 { /* cs3 */
350 FSL_DDR_ODT_OTHER_DIMM,
351 FSL_DDR_ODT_OTHER_DIMM,
352 DDR3_RTT_30_OHM,
353 DDR3_RTT_OFF
354 }
355};
356
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700357static __maybe_unused const struct dynamic_odt dual_DS[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000358 { /* cs0 */
359 FSL_DDR_ODT_NEVER,
360 FSL_DDR_ODT_SAME_DIMM,
361 DDR3_RTT_120_OHM,
362 DDR3_RTT_OFF
363 },
364 { /* cs1 */
365 FSL_DDR_ODT_OTHER_DIMM,
366 FSL_DDR_ODT_OTHER_DIMM,
367 DDR3_RTT_30_OHM,
368 DDR3_RTT_OFF
369 },
370 { /* cs2 */
371 FSL_DDR_ODT_OTHER_DIMM,
372 FSL_DDR_ODT_ALL,
373 DDR3_RTT_20_OHM,
374 DDR3_RTT_120_OHM
375 },
376 {0, 0, 0, 0}
377};
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700378static __maybe_unused const struct dynamic_odt dual_SD[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000379 { /* cs0 */
380 FSL_DDR_ODT_OTHER_DIMM,
381 FSL_DDR_ODT_ALL,
382 DDR3_RTT_20_OHM,
383 DDR3_RTT_120_OHM
384 },
385 {0, 0, 0, 0},
386 { /* cs2 */
387 FSL_DDR_ODT_NEVER,
388 FSL_DDR_ODT_SAME_DIMM,
389 DDR3_RTT_120_OHM,
390 DDR3_RTT_OFF
391 },
392 { /* cs3 */
393 FSL_DDR_ODT_OTHER_DIMM,
394 FSL_DDR_ODT_OTHER_DIMM,
395 DDR3_RTT_20_OHM,
396 DDR3_RTT_OFF
397 }
398};
399
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700400static __maybe_unused const struct dynamic_odt dual_SS[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000401 { /* cs0 */
402 FSL_DDR_ODT_OTHER_DIMM,
403 FSL_DDR_ODT_ALL,
404 DDR3_RTT_30_OHM,
405 DDR3_RTT_120_OHM
406 },
407 {0, 0, 0, 0},
408 { /* cs2 */
409 FSL_DDR_ODT_OTHER_DIMM,
410 FSL_DDR_ODT_ALL,
411 DDR3_RTT_30_OHM,
412 DDR3_RTT_120_OHM
413 },
414 {0, 0, 0, 0}
415};
416
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700417static __maybe_unused const struct dynamic_odt dual_D0[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000418 { /* cs0 */
419 FSL_DDR_ODT_NEVER,
420 FSL_DDR_ODT_SAME_DIMM,
421 DDR3_RTT_40_OHM,
422 DDR3_RTT_OFF
423 },
424 { /* cs1 */
425 FSL_DDR_ODT_NEVER,
426 FSL_DDR_ODT_NEVER,
427 DDR3_RTT_OFF,
428 DDR3_RTT_OFF
429 },
430 {0, 0, 0, 0},
431 {0, 0, 0, 0}
432};
433
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700434static __maybe_unused const struct dynamic_odt dual_0D[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000435 {0, 0, 0, 0},
436 {0, 0, 0, 0},
437 { /* cs2 */
438 FSL_DDR_ODT_NEVER,
439 FSL_DDR_ODT_SAME_DIMM,
440 DDR3_RTT_40_OHM,
441 DDR3_RTT_OFF
442 },
443 { /* cs3 */
444 FSL_DDR_ODT_NEVER,
445 FSL_DDR_ODT_NEVER,
446 DDR3_RTT_OFF,
447 DDR3_RTT_OFF
448 }
449};
450
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700451static __maybe_unused const struct dynamic_odt dual_S0[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000452 { /* cs0 */
453 FSL_DDR_ODT_NEVER,
454 FSL_DDR_ODT_CS,
455 DDR3_RTT_40_OHM,
456 DDR3_RTT_OFF
457 },
458 {0, 0, 0, 0},
459 {0, 0, 0, 0},
460 {0, 0, 0, 0}
461
462};
463
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700464static __maybe_unused const struct dynamic_odt dual_0S[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000465 {0, 0, 0, 0},
466 {0, 0, 0, 0},
467 { /* cs2 */
468 FSL_DDR_ODT_NEVER,
469 FSL_DDR_ODT_CS,
470 DDR3_RTT_40_OHM,
471 DDR3_RTT_OFF
472 },
473 {0, 0, 0, 0}
474
475};
476
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700477static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
York Sune1fd16b2011-01-10 12:03:00 +0000478 { /* cs0 */
479 FSL_DDR_ODT_NEVER,
480 FSL_DDR_ODT_CS,
481 DDR3_RTT_120_OHM,
482 DDR3_RTT_OFF
483 },
484 { /* cs1 */
485 FSL_DDR_ODT_NEVER,
486 FSL_DDR_ODT_CS,
487 DDR3_RTT_120_OHM,
488 DDR3_RTT_OFF
489 },
490 { /* cs2 */
491 FSL_DDR_ODT_NEVER,
492 FSL_DDR_ODT_CS,
493 DDR3_RTT_120_OHM,
494 DDR3_RTT_OFF
495 },
496 { /* cs3 */
497 FSL_DDR_ODT_NEVER,
498 FSL_DDR_ODT_CS,
499 DDR3_RTT_120_OHM,
500 DDR3_RTT_OFF
501 }
502};
York Sun19601dd2015-11-04 10:03:17 -0800503#else /* CONFIG_SYS_FSL_DDR3 */
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700504static __maybe_unused const struct dynamic_odt single_Q[4] = {
York Sun4e573822011-08-26 11:32:43 -0700505 {0, 0, 0, 0},
506 {0, 0, 0, 0},
507 {0, 0, 0, 0},
508 {0, 0, 0, 0}
509};
York Sune1fd16b2011-01-10 12:03:00 +0000510
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700511static __maybe_unused const struct dynamic_odt single_D[4] = {
York Sun4e573822011-08-26 11:32:43 -0700512 { /* cs0 */
513 FSL_DDR_ODT_NEVER,
514 FSL_DDR_ODT_ALL,
515 DDR2_RTT_150_OHM,
516 DDR2_RTT_OFF
517 },
518 { /* cs1 */
519 FSL_DDR_ODT_NEVER,
520 FSL_DDR_ODT_NEVER,
521 DDR2_RTT_OFF,
522 DDR2_RTT_OFF
523 },
524 {0, 0, 0, 0},
525 {0, 0, 0, 0}
526};
527
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700528static __maybe_unused const struct dynamic_odt single_S[4] = {
York Sun4e573822011-08-26 11:32:43 -0700529 { /* cs0 */
530 FSL_DDR_ODT_NEVER,
531 FSL_DDR_ODT_ALL,
532 DDR2_RTT_150_OHM,
533 DDR2_RTT_OFF
534 },
535 {0, 0, 0, 0},
536 {0, 0, 0, 0},
537 {0, 0, 0, 0},
538};
539
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700540static __maybe_unused const struct dynamic_odt dual_DD[4] = {
York Sun4e573822011-08-26 11:32:43 -0700541 { /* cs0 */
542 FSL_DDR_ODT_OTHER_DIMM,
543 FSL_DDR_ODT_OTHER_DIMM,
544 DDR2_RTT_75_OHM,
545 DDR2_RTT_OFF
546 },
547 { /* cs1 */
548 FSL_DDR_ODT_NEVER,
549 FSL_DDR_ODT_NEVER,
550 DDR2_RTT_OFF,
551 DDR2_RTT_OFF
552 },
553 { /* cs2 */
554 FSL_DDR_ODT_OTHER_DIMM,
555 FSL_DDR_ODT_OTHER_DIMM,
556 DDR2_RTT_75_OHM,
557 DDR2_RTT_OFF
558 },
559 { /* cs3 */
560 FSL_DDR_ODT_NEVER,
561 FSL_DDR_ODT_NEVER,
562 DDR2_RTT_OFF,
563 DDR2_RTT_OFF
564 }
565};
566
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700567static __maybe_unused const struct dynamic_odt dual_DS[4] = {
York Sun4e573822011-08-26 11:32:43 -0700568 { /* cs0 */
569 FSL_DDR_ODT_OTHER_DIMM,
570 FSL_DDR_ODT_OTHER_DIMM,
571 DDR2_RTT_75_OHM,
572 DDR2_RTT_OFF
573 },
574 { /* cs1 */
575 FSL_DDR_ODT_NEVER,
576 FSL_DDR_ODT_NEVER,
577 DDR2_RTT_OFF,
578 DDR2_RTT_OFF
579 },
580 { /* cs2 */
581 FSL_DDR_ODT_OTHER_DIMM,
582 FSL_DDR_ODT_OTHER_DIMM,
583 DDR2_RTT_75_OHM,
584 DDR2_RTT_OFF
585 },
586 {0, 0, 0, 0}
587};
588
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700589static __maybe_unused const struct dynamic_odt dual_SD[4] = {
York Sun4e573822011-08-26 11:32:43 -0700590 { /* cs0 */
591 FSL_DDR_ODT_OTHER_DIMM,
592 FSL_DDR_ODT_OTHER_DIMM,
593 DDR2_RTT_75_OHM,
594 DDR2_RTT_OFF
595 },
596 {0, 0, 0, 0},
597 { /* cs2 */
598 FSL_DDR_ODT_OTHER_DIMM,
599 FSL_DDR_ODT_OTHER_DIMM,
600 DDR2_RTT_75_OHM,
601 DDR2_RTT_OFF
602 },
603 { /* cs3 */
604 FSL_DDR_ODT_NEVER,
605 FSL_DDR_ODT_NEVER,
606 DDR2_RTT_OFF,
607 DDR2_RTT_OFF
608 }
609};
610
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700611static __maybe_unused const struct dynamic_odt dual_SS[4] = {
York Sun4e573822011-08-26 11:32:43 -0700612 { /* cs0 */
613 FSL_DDR_ODT_OTHER_DIMM,
614 FSL_DDR_ODT_OTHER_DIMM,
615 DDR2_RTT_75_OHM,
616 DDR2_RTT_OFF
617 },
618 {0, 0, 0, 0},
619 { /* cs2 */
620 FSL_DDR_ODT_OTHER_DIMM,
621 FSL_DDR_ODT_OTHER_DIMM,
622 DDR2_RTT_75_OHM,
623 DDR2_RTT_OFF
624 },
625 {0, 0, 0, 0}
626};
627
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700628static __maybe_unused const struct dynamic_odt dual_D0[4] = {
York Sun4e573822011-08-26 11:32:43 -0700629 { /* cs0 */
630 FSL_DDR_ODT_NEVER,
631 FSL_DDR_ODT_ALL,
632 DDR2_RTT_150_OHM,
633 DDR2_RTT_OFF
634 },
635 { /* cs1 */
636 FSL_DDR_ODT_NEVER,
637 FSL_DDR_ODT_NEVER,
638 DDR2_RTT_OFF,
639 DDR2_RTT_OFF
640 },
641 {0, 0, 0, 0},
642 {0, 0, 0, 0}
643};
644
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700645static __maybe_unused const struct dynamic_odt dual_0D[4] = {
York Sun4e573822011-08-26 11:32:43 -0700646 {0, 0, 0, 0},
647 {0, 0, 0, 0},
648 { /* cs2 */
649 FSL_DDR_ODT_NEVER,
650 FSL_DDR_ODT_ALL,
651 DDR2_RTT_150_OHM,
652 DDR2_RTT_OFF
653 },
654 { /* cs3 */
655 FSL_DDR_ODT_NEVER,
656 FSL_DDR_ODT_NEVER,
657 DDR2_RTT_OFF,
658 DDR2_RTT_OFF
659 }
660};
661
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700662static __maybe_unused const struct dynamic_odt dual_S0[4] = {
York Sun4e573822011-08-26 11:32:43 -0700663 { /* cs0 */
664 FSL_DDR_ODT_NEVER,
665 FSL_DDR_ODT_CS,
666 DDR2_RTT_150_OHM,
667 DDR2_RTT_OFF
668 },
669 {0, 0, 0, 0},
670 {0, 0, 0, 0},
671 {0, 0, 0, 0}
672
673};
674
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700675static __maybe_unused const struct dynamic_odt dual_0S[4] = {
York Sun4e573822011-08-26 11:32:43 -0700676 {0, 0, 0, 0},
677 {0, 0, 0, 0},
678 { /* cs2 */
679 FSL_DDR_ODT_NEVER,
680 FSL_DDR_ODT_CS,
681 DDR2_RTT_150_OHM,
682 DDR2_RTT_OFF
683 },
684 {0, 0, 0, 0}
685
686};
687
Thomas Schaefer97fbf262017-03-28 11:29:56 -0700688static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
York Sun4e573822011-08-26 11:32:43 -0700689 { /* cs0 */
690 FSL_DDR_ODT_NEVER,
691 FSL_DDR_ODT_CS,
692 DDR2_RTT_75_OHM,
693 DDR2_RTT_OFF
694 },
695 { /* cs1 */
696 FSL_DDR_ODT_NEVER,
697 FSL_DDR_ODT_NEVER,
698 DDR2_RTT_OFF,
699 DDR2_RTT_OFF
700 },
701 { /* cs2 */
702 FSL_DDR_ODT_NEVER,
703 FSL_DDR_ODT_CS,
704 DDR2_RTT_75_OHM,
705 DDR2_RTT_OFF
706 },
707 { /* cs3 */
708 FSL_DDR_ODT_NEVER,
709 FSL_DDR_ODT_NEVER,
710 DDR2_RTT_OFF,
711 DDR2_RTT_OFF
712 }
713};
714#endif
York Sun89b78092012-10-08 07:44:27 +0000715
716/*
717 * Automatically seleect bank interleaving mode based on DIMMs
718 * in this order: cs0_cs1_cs2_cs3, cs0_cs1, null.
719 * This function only deal with one or two slots per controller.
720 */
721static inline unsigned int auto_bank_intlv(dimm_params_t *pdimm)
722{
723#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
724 if (pdimm[0].n_ranks == 4)
725 return FSL_DDR_CS0_CS1_CS2_CS3;
726 else if (pdimm[0].n_ranks == 2)
727 return FSL_DDR_CS0_CS1;
728#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
729#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
730 if (pdimm[0].n_ranks == 4)
731 return FSL_DDR_CS0_CS1_CS2_CS3;
732#endif
733 if (pdimm[0].n_ranks == 2) {
734 if (pdimm[1].n_ranks == 2)
735 return FSL_DDR_CS0_CS1_CS2_CS3;
736 else
737 return FSL_DDR_CS0_CS1;
738 }
739#endif
740 return 0;
741}
742
York Sun56848422015-07-23 14:04:48 -0700743unsigned int populate_memctl_options(const common_timing_params_t *common_dimm,
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500744 memctl_options_t *popts,
Haiying Wangdfb49102008-10-03 12:36:55 -0400745 dimm_params_t *pdimm,
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500746 unsigned int ctrl_num)
747{
748 unsigned int i;
Jeremy Gebben86b840b2018-07-20 16:00:36 -0600749 char buf[HWCONFIG_BUFFER_SIZE];
York Sun34e026f2014-03-27 17:54:47 -0700750#if defined(CONFIG_SYS_FSL_DDR3) || \
751 defined(CONFIG_SYS_FSL_DDR2) || \
752 defined(CONFIG_SYS_FSL_DDR4)
York Sun4e573822011-08-26 11:32:43 -0700753 const struct dynamic_odt *pdodt = odt_unknown;
Kumar Gala667bc172011-11-09 10:05:21 -0600754#endif
York Sun564e9382018-01-29 10:24:08 -0800755#if (CONFIG_FSL_SDRAM_TYPE != SDRAM_TYPE_DDR4)
York Suncda1de22011-08-24 09:40:26 -0700756 ulong ddr_freq;
York Sun564e9382018-01-29 10:24:08 -0800757#endif
Kumar Galadd50af22011-01-09 11:37:00 -0600758
759 /*
760 * Extract hwconfig from environment since we have not properly setup
761 * the environment but need it for ddr config params
762 */
Jeremy Gebben86b840b2018-07-20 16:00:36 -0600763 if (env_get_f("hwconfig", buf, sizeof(buf)) < 0)
764 buf[0] = '\0';
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500765
York Sun34e026f2014-03-27 17:54:47 -0700766#if defined(CONFIG_SYS_FSL_DDR3) || \
767 defined(CONFIG_SYS_FSL_DDR2) || \
768 defined(CONFIG_SYS_FSL_DDR4)
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500769 /* Chip select options. */
York Sun349689b2014-04-01 14:20:49 -0700770#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
771 switch (pdimm[0].n_ranks) {
772 case 1:
773 pdodt = single_S;
774 break;
775 case 2:
776 pdodt = single_D;
777 break;
778 case 4:
779 pdodt = single_Q;
780 break;
781 }
782#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
783 switch (pdimm[0].n_ranks) {
York Sun123922b2012-10-08 07:44:23 +0000784#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
York Sun349689b2014-04-01 14:20:49 -0700785 case 4:
786 pdodt = single_Q;
787 if (pdimm[1].n_ranks)
788 printf("Error: Quad- and Dual-rank DIMMs cannot be used together\n");
789 break;
York Sun123922b2012-10-08 07:44:23 +0000790#endif
York Sun349689b2014-04-01 14:20:49 -0700791 case 2:
792 switch (pdimm[1].n_ranks) {
York Sune1fd16b2011-01-10 12:03:00 +0000793 case 2:
York Sun349689b2014-04-01 14:20:49 -0700794 pdodt = dual_DD;
York Sune1fd16b2011-01-10 12:03:00 +0000795 break;
796 case 1:
York Sun349689b2014-04-01 14:20:49 -0700797 pdodt = dual_DS;
York Sune1fd16b2011-01-10 12:03:00 +0000798 break;
799 case 0:
York Sun349689b2014-04-01 14:20:49 -0700800 pdodt = dual_D0;
York Sune1fd16b2011-01-10 12:03:00 +0000801 break;
802 }
York Sun349689b2014-04-01 14:20:49 -0700803 break;
804 case 1:
805 switch (pdimm[1].n_ranks) {
806 case 2:
807 pdodt = dual_SD;
808 break;
809 case 1:
810 pdodt = dual_SS;
811 break;
812 case 0:
813 pdodt = dual_S0;
814 break;
815 }
816 break;
817 case 0:
818 switch (pdimm[1].n_ranks) {
819 case 2:
820 pdodt = dual_0D;
821 break;
822 case 1:
823 pdodt = dual_0S;
824 break;
825 }
826 break;
York Sune1fd16b2011-01-10 12:03:00 +0000827 }
York Sun349689b2014-04-01 14:20:49 -0700828#endif /* CONFIG_DIMM_SLOTS_PER_CTLR */
829#endif /* CONFIG_SYS_FSL_DDR2, 3, 4 */
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500830
831 /* Pick chip-select local options. */
832 for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
York Sun34e026f2014-03-27 17:54:47 -0700833#if defined(CONFIG_SYS_FSL_DDR3) || \
834 defined(CONFIG_SYS_FSL_DDR2) || \
835 defined(CONFIG_SYS_FSL_DDR4)
York Sune1fd16b2011-01-10 12:03:00 +0000836 popts->cs_local_opts[i].odt_rd_cfg = pdodt[i].odt_rd_cfg;
837 popts->cs_local_opts[i].odt_wr_cfg = pdodt[i].odt_wr_cfg;
838 popts->cs_local_opts[i].odt_rtt_norm = pdodt[i].odt_rtt_norm;
839 popts->cs_local_opts[i].odt_rtt_wr = pdodt[i].odt_rtt_wr;
840#else
841 popts->cs_local_opts[i].odt_rd_cfg = FSL_DDR_ODT_NEVER;
842 popts->cs_local_opts[i].odt_wr_cfg = FSL_DDR_ODT_CS;
843#endif
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500844 popts->cs_local_opts[i].auto_precharge = 0;
845 }
846
847 /* Pick interleaving mode. */
848
849 /*
850 * 0 = no interleaving
851 * 1 = interleaving between 2 controllers
852 */
853 popts->memctl_interleaving = 0;
854
855 /*
856 * 0 = cacheline
857 * 1 = page
858 * 2 = (logical) bank
859 * 3 = superbank (only if CS interleaving is enabled)
860 */
861 popts->memctl_interleaving_mode = 0;
862
863 /*
864 * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
865 * 1: page: bit to the left of the column bits selects the memctl
866 * 2: bank: bit to the left of the bank bits selects the memctl
867 * 3: superbank: bit to the left of the chip select selects the memctl
868 *
869 * NOTE: ba_intlv (rank interleaving) is independent of memory
870 * controller interleaving; it is only within a memory controller.
871 * Must use superbank interleaving if rank interleaving is used and
872 * memory controller interleaving is enabled.
873 */
874
875 /*
876 * 0 = no
877 * 0x40 = CS0,CS1
878 * 0x20 = CS2,CS3
879 * 0x60 = CS0,CS1 + CS2,CS3
880 * 0x04 = CS0,CS1,CS2,CS3
881 */
882 popts->ba_intlv_ctl = 0;
883
884 /* Memory Organization Parameters */
York Sun56848422015-07-23 14:04:48 -0700885 popts->registered_dimm_en = common_dimm->all_dimms_registered;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500886
887 /* Operational Mode Paramters */
888
889 /* Pick ECC modes */
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530890 popts->ecc_mode = 0; /* 0 = disabled, 1 = enabled */
York Sun47df8f02011-01-10 12:02:57 +0000891#ifdef CONFIG_DDR_ECC
892 if (hwconfig_sub_f("fsl_ddr", "ecc", buf)) {
893 if (hwconfig_subarg_cmp_f("fsl_ddr", "ecc", "on", buf))
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530894 popts->ecc_mode = 1;
York Sun47df8f02011-01-10 12:02:57 +0000895 } else
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530896 popts->ecc_mode = 1;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500897#endif
York Sunb06f6f22016-05-26 12:19:03 -0700898 /* 1 = use memory controler to init data */
899 popts->ecc_init_using_memctl = popts->ecc_mode ? 1 : 0;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500900
901 /*
902 * Choose DQS config
903 * 0 for DDR1
904 * 1 for DDR2
905 */
York Sun5614e712013-09-30 09:22:09 -0700906#if defined(CONFIG_SYS_FSL_DDR1)
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530907 popts->dqs_config = 0;
York Sun5614e712013-09-30 09:22:09 -0700908#elif defined(CONFIG_SYS_FSL_DDR2) || defined(CONFIG_SYS_FSL_DDR3)
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530909 popts->dqs_config = 1;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500910#endif
911
912 /* Choose self-refresh during sleep. */
913 popts->self_refresh_in_sleep = 1;
914
915 /* Choose dynamic power management mode. */
916 popts->dynamic_power = 0;
917
York Sune090aa72011-05-27 07:25:48 +0800918 /*
919 * check first dimm for primary sdram width
920 * presuming all dimms are similar
921 * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit
922 */
York Sun5614e712013-09-30 09:22:09 -0700923#if defined(CONFIG_SYS_FSL_DDR1) || defined(CONFIG_SYS_FSL_DDR2)
York Sun4c99cb92011-06-27 13:35:25 -0700924 if (pdimm[0].n_ranks != 0) {
925 if ((pdimm[0].data_width >= 64) && \
926 (pdimm[0].data_width <= 72))
927 popts->data_bus_width = 0;
xypron.glpk@gmx.de0e0de242017-04-15 15:23:49 +0200928 else if ((pdimm[0].data_width >= 32) && \
York Sun4c99cb92011-06-27 13:35:25 -0700929 (pdimm[0].data_width <= 40))
930 popts->data_bus_width = 1;
931 else {
932 panic("Error: data width %u is invalid!\n",
933 pdimm[0].data_width);
934 }
935 }
936#else
937 if (pdimm[0].n_ranks != 0) {
938 if (pdimm[0].primary_sdram_width == 64)
939 popts->data_bus_width = 0;
940 else if (pdimm[0].primary_sdram_width == 32)
941 popts->data_bus_width = 1;
942 else if (pdimm[0].primary_sdram_width == 16)
943 popts->data_bus_width = 2;
944 else {
945 panic("Error: primary sdram width %u is invalid!\n",
946 pdimm[0].primary_sdram_width);
947 }
948 }
949#endif
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500950
York Sunb61e0612013-06-25 11:37:47 -0700951 popts->x4_en = (pdimm[0].device_width == 4) ? 1 : 0;
952
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500953 /* Choose burst length. */
York Sun34e026f2014-03-27 17:54:47 -0700954#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
Dave Liu22c9de02010-03-05 12:22:00 +0800955#if defined(CONFIG_E500MC)
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530956 popts->otf_burst_chop_en = 0; /* on-the-fly burst chop disable */
Dave Liu22c9de02010-03-05 12:22:00 +0800957 popts->burst_length = DDR_BL8; /* Fixed 8-beat burst len */
958#else
York Sun51d498f2011-05-27 07:25:51 +0800959 if ((popts->data_bus_width == 1) || (popts->data_bus_width == 2)) {
960 /* 32-bit or 16-bit bus */
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530961 popts->otf_burst_chop_en = 0;
York Sune090aa72011-05-27 07:25:48 +0800962 popts->burst_length = DDR_BL8;
963 } else {
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530964 popts->otf_burst_chop_en = 1; /* on-the-fly burst chop */
York Sune090aa72011-05-27 07:25:48 +0800965 popts->burst_length = DDR_OTF; /* on-the-fly BC4 and BL8 */
966 }
Dave Liu22c9de02010-03-05 12:22:00 +0800967#endif
Dave Liuc360cea2009-03-14 12:48:30 +0800968#else
969 popts->burst_length = DDR_BL4; /* has to be 4 for DDR2 */
970#endif
971
972 /* Choose ddr controller address mirror mode */
York Sun34e026f2014-03-27 17:54:47 -0700973#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
York Sun6b95be22015-03-19 09:30:27 -0700974 for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
975 if (pdimm[i].n_ranks) {
976 popts->mirrored_dimm = pdimm[i].mirrored_dimm;
977 break;
978 }
979 }
Dave Liuc360cea2009-03-14 12:48:30 +0800980#endif
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500981
982 /* Global Timing Parameters. */
York Sun03e664d2015-01-06 13:18:50 -0800983 debug("mclk_ps = %u ps\n", get_memory_clk_period_ps(ctrl_num));
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500984
985 /* Pick a caslat override. */
986 popts->cas_latency_override = 0;
987 popts->cas_latency_override_value = 3;
988 if (popts->cas_latency_override) {
989 debug("using caslat override value = %u\n",
990 popts->cas_latency_override_value);
991 }
992
993 /* Decide whether to use the computed derated latency */
994 popts->use_derated_caslat = 0;
995
996 /* Choose an additive latency. */
997 popts->additive_latency_override = 0;
998 popts->additive_latency_override_value = 3;
999 if (popts->additive_latency_override) {
1000 debug("using additive latency override value = %u\n",
1001 popts->additive_latency_override_value);
1002 }
1003
1004 /*
1005 * 2T_EN setting
1006 *
1007 * Factors to consider for 2T_EN:
1008 * - number of DIMMs installed
1009 * - number of components, number of active ranks
1010 * - how much time you want to spend playing around
1011 */
Priyanka Jain0dd38a32013-09-25 10:41:19 +05301012 popts->twot_en = 0;
1013 popts->threet_en = 0;
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001014
Shengzhou Liueb118802016-03-10 17:36:56 +08001015 /* for RDIMM and DDR4 UDIMM/discrete memory, address parity enable */
1016 if (popts->registered_dimm_en)
1017 popts->ap_en = 1; /* 0 = disable, 1 = enable */
1018 else
1019 popts->ap_en = 0; /* disabled for DDR4 UDIMM/discrete default */
1020
1021 if (hwconfig_sub_f("fsl_ddr", "parity", buf)) {
1022 if (hwconfig_subarg_cmp_f("fsl_ddr", "parity", "on", buf)) {
1023 if (popts->registered_dimm_en ||
1024 (CONFIG_FSL_SDRAM_TYPE == SDRAM_TYPE_DDR4))
1025 popts->ap_en = 1;
1026 }
1027 }
York Sune1fd16b2011-01-10 12:03:00 +00001028
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001029 /*
1030 * BSTTOPRE precharge interval
1031 *
1032 * Set this to 0 for global auto precharge
York Sun34e026f2014-03-27 17:54:47 -07001033 * The value of 0x100 has been used for DDR1, DDR2, DDR3.
1034 * It is not wrong. Any value should be OK. The performance depends on
York Sun56848422015-07-23 14:04:48 -07001035 * applications. There is no one good value for all. One way to set
1036 * is to use 1/4 of refint value.
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001037 */
York Sun56848422015-07-23 14:04:48 -07001038 popts->bstopre = picos_to_mclk(ctrl_num, common_dimm->refresh_rate_ps)
1039 >> 2;
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001040
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001041 /*
1042 * Window for four activates -- tFAW
1043 *
1044 * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
1045 * FIXME: varies depending upon number of column addresses or data
1046 * FIXME: width, was considering looking at pdimm->primary_sdram_width
1047 */
York Sun5614e712013-09-30 09:22:09 -07001048#if defined(CONFIG_SYS_FSL_DDR1)
York Sun03e664d2015-01-06 13:18:50 -08001049 popts->tfaw_window_four_activates_ps = mclk_to_picos(ctrl_num, 1);
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001050
York Sun5614e712013-09-30 09:22:09 -07001051#elif defined(CONFIG_SYS_FSL_DDR2)
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001052 /*
1053 * x4/x8; some datasheets have 35000
1054 * x16 wide columns only? Use 50000?
1055 */
Priyanka Jain0dd38a32013-09-25 10:41:19 +05301056 popts->tfaw_window_four_activates_ps = 37500;
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001057
York Sun34e026f2014-03-27 17:54:47 -07001058#else
Priyanka Jain0dd38a32013-09-25 10:41:19 +05301059 popts->tfaw_window_four_activates_ps = pdimm[0].tfaw_ps;
Dave Liuc360cea2009-03-14 12:48:30 +08001060#endif
1061 popts->zq_en = 0;
1062 popts->wrlvl_en = 0;
York Sun34e026f2014-03-27 17:54:47 -07001063#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
Dave Liuc360cea2009-03-14 12:48:30 +08001064 /*
1065 * due to ddr3 dimm is fly-by topology
1066 * we suggest to enable write leveling to
1067 * meet the tQDSS under different loading.
1068 */
1069 popts->wrlvl_en = 1;
york5fb8a8a2010-07-02 22:25:56 +00001070 popts->zq_en = 1;
Dave Liubdc9f7b2009-12-16 10:24:37 -06001071 popts->wrlvl_override = 0;
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001072#endif
1073
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001074 /*
Haiying Wangc9ffd832008-10-03 12:37:10 -04001075 * Check interleaving configuration from environment.
1076 * Please refer to doc/README.fsl-ddr for the detail.
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001077 *
1078 * If memory controller interleaving is enabled, then the data
york076bff82010-07-02 22:25:52 +00001079 * bus widths must be programmed identically for all memory controllers.
Haiying Wangc9ffd832008-10-03 12:37:10 -04001080 *
York Sun6b1e1252014-02-10 13:59:44 -08001081 * Attempt to set all controllers to the same chip select
Haiying Wangc9ffd832008-10-03 12:37:10 -04001082 * interleaving mode. It will do a best effort to get the
1083 * requested ranks interleaved together such that the result
1084 * should be a subset of the requested configuration.
York Sun6b1e1252014-02-10 13:59:44 -08001085 *
1086 * if CONFIG_SYS_FSL_DDR_INTLV_256B is defined, mandatory interleaving
1087 * with 256 Byte is enabled.
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001088 */
York Sun51370d52016-12-28 08:43:45 -08001089#if (CONFIG_SYS_NUM_DDR_CTLRS > 1)
York Suna4c66502012-08-17 08:22:39 +00001090 if (!hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf))
York Sun6b1e1252014-02-10 13:59:44 -08001091#ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
1092 ;
1093#else
York Suna4c66502012-08-17 08:22:39 +00001094 goto done;
York Sun6b1e1252014-02-10 13:59:44 -08001095#endif
York Suna4c66502012-08-17 08:22:39 +00001096 if (pdimm[0].n_ranks == 0) {
1097 printf("There is no rank on CS0 for controller %d.\n", ctrl_num);
1098 popts->memctl_interleaving = 0;
1099 goto done;
Haiying Wangc9ffd832008-10-03 12:37:10 -04001100 }
York Suna4c66502012-08-17 08:22:39 +00001101 popts->memctl_interleaving = 1;
York Sun6b1e1252014-02-10 13:59:44 -08001102#ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
1103 popts->memctl_interleaving_mode = FSL_DDR_256B_INTERLEAVING;
1104 popts->memctl_interleaving = 1;
1105 debug("256 Byte interleaving\n");
York Sun349689b2014-04-01 14:20:49 -07001106#else
York Suna4c66502012-08-17 08:22:39 +00001107 /*
1108 * test null first. if CONFIG_HWCONFIG is not defined
1109 * hwconfig_arg_cmp returns non-zero
1110 */
1111 if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
1112 "null", buf)) {
1113 popts->memctl_interleaving = 0;
1114 debug("memory controller interleaving disabled.\n");
1115 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1116 "ctlr_intlv",
1117 "cacheline", buf)) {
1118 popts->memctl_interleaving_mode =
York Sun51370d52016-12-28 08:43:45 -08001119 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001120 0 : FSL_DDR_CACHE_LINE_INTERLEAVING;
1121 popts->memctl_interleaving =
York Sun51370d52016-12-28 08:43:45 -08001122 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001123 0 : 1;
1124 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1125 "ctlr_intlv",
1126 "page", buf)) {
1127 popts->memctl_interleaving_mode =
York Sun51370d52016-12-28 08:43:45 -08001128 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001129 0 : FSL_DDR_PAGE_INTERLEAVING;
1130 popts->memctl_interleaving =
York Sun51370d52016-12-28 08:43:45 -08001131 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001132 0 : 1;
1133 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1134 "ctlr_intlv",
1135 "bank", buf)) {
1136 popts->memctl_interleaving_mode =
York Sun51370d52016-12-28 08:43:45 -08001137 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001138 0 : FSL_DDR_BANK_INTERLEAVING;
1139 popts->memctl_interleaving =
York Sun51370d52016-12-28 08:43:45 -08001140 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001141 0 : 1;
1142 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1143 "ctlr_intlv",
1144 "superbank", buf)) {
1145 popts->memctl_interleaving_mode =
York Sun51370d52016-12-28 08:43:45 -08001146 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001147 0 : FSL_DDR_SUPERBANK_INTERLEAVING;
1148 popts->memctl_interleaving =
York Sun51370d52016-12-28 08:43:45 -08001149 ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
York Suna4c66502012-08-17 08:22:39 +00001150 0 : 1;
York Sun51370d52016-12-28 08:43:45 -08001151#if (CONFIG_SYS_NUM_DDR_CTLRS == 3)
York Suna4c66502012-08-17 08:22:39 +00001152 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1153 "ctlr_intlv",
1154 "3way_1KB", buf)) {
1155 popts->memctl_interleaving_mode =
1156 FSL_DDR_3WAY_1KB_INTERLEAVING;
1157 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1158 "ctlr_intlv",
1159 "3way_4KB", buf)) {
1160 popts->memctl_interleaving_mode =
1161 FSL_DDR_3WAY_4KB_INTERLEAVING;
1162 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1163 "ctlr_intlv",
1164 "3way_8KB", buf)) {
1165 popts->memctl_interleaving_mode =
1166 FSL_DDR_3WAY_8KB_INTERLEAVING;
York Sun51370d52016-12-28 08:43:45 -08001167#elif (CONFIG_SYS_NUM_DDR_CTLRS == 4)
York Suna4c66502012-08-17 08:22:39 +00001168 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1169 "ctlr_intlv",
1170 "4way_1KB", buf)) {
1171 popts->memctl_interleaving_mode =
1172 FSL_DDR_4WAY_1KB_INTERLEAVING;
1173 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1174 "ctlr_intlv",
1175 "4way_4KB", buf)) {
1176 popts->memctl_interleaving_mode =
1177 FSL_DDR_4WAY_4KB_INTERLEAVING;
1178 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1179 "ctlr_intlv",
1180 "4way_8KB", buf)) {
1181 popts->memctl_interleaving_mode =
1182 FSL_DDR_4WAY_8KB_INTERLEAVING;
1183#endif
1184 } else {
1185 popts->memctl_interleaving = 0;
1186 printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
1187 }
York Sun349689b2014-04-01 14:20:49 -07001188#endif /* CONFIG_SYS_FSL_DDR_INTLV_256B */
York Suna4c66502012-08-17 08:22:39 +00001189done:
York Sun51370d52016-12-28 08:43:45 -08001190#endif /* CONFIG_SYS_NUM_DDR_CTLRS > 1 */
Kumar Galadd50af22011-01-09 11:37:00 -06001191 if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) &&
Dave Liu3ad95de2009-11-12 07:26:37 +08001192 (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) {
Kumar Gala79e4e642010-07-14 10:04:21 -05001193 /* test null first. if CONFIG_HWCONFIG is not defined,
Kumar Galadd50af22011-01-09 11:37:00 -06001194 * hwconfig_subarg_cmp_f returns non-zero */
1195 if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1196 "null", buf))
york076bff82010-07-02 22:25:52 +00001197 debug("bank interleaving disabled.\n");
Kumar Galadd50af22011-01-09 11:37:00 -06001198 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1199 "cs0_cs1", buf))
Haiying Wangc9ffd832008-10-03 12:37:10 -04001200 popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
Kumar Galadd50af22011-01-09 11:37:00 -06001201 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1202 "cs2_cs3", buf))
Haiying Wangc9ffd832008-10-03 12:37:10 -04001203 popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
Kumar Galadd50af22011-01-09 11:37:00 -06001204 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1205 "cs0_cs1_and_cs2_cs3", buf))
Haiying Wangc9ffd832008-10-03 12:37:10 -04001206 popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
Kumar Galadd50af22011-01-09 11:37:00 -06001207 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1208 "cs0_cs1_cs2_cs3", buf))
Haiying Wangc9ffd832008-10-03 12:37:10 -04001209 popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
York Sun89b78092012-10-08 07:44:27 +00001210 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1211 "auto", buf))
1212 popts->ba_intlv_ctl = auto_bank_intlv(pdimm);
Haiying Wangc9ffd832008-10-03 12:37:10 -04001213 else
york076bff82010-07-02 22:25:52 +00001214 printf("hwconfig has unrecognized parameter for bank_intlv.\n");
Haiying Wangc9ffd832008-10-03 12:37:10 -04001215 switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
1216 case FSL_DDR_CS0_CS1_CS2_CS3:
york076bff82010-07-02 22:25:52 +00001217#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
york5800e7a2010-07-02 22:25:53 +00001218 if (pdimm[0].n_ranks < 4) {
york076bff82010-07-02 22:25:52 +00001219 popts->ba_intlv_ctl = 0;
1220 printf("Not enough bank(chip-select) for "
1221 "CS0+CS1+CS2+CS3 on controller %d, "
York Suna4c66502012-08-17 08:22:39 +00001222 "interleaving disabled!\n", ctrl_num);
york076bff82010-07-02 22:25:52 +00001223 }
1224#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
York Sun123922b2012-10-08 07:44:23 +00001225#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
1226 if (pdimm[0].n_ranks == 4)
1227 break;
1228#endif
york5800e7a2010-07-02 22:25:53 +00001229 if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) {
york076bff82010-07-02 22:25:52 +00001230 popts->ba_intlv_ctl = 0;
1231 printf("Not enough bank(chip-select) for "
1232 "CS0+CS1+CS2+CS3 on controller %d, "
York Suna4c66502012-08-17 08:22:39 +00001233 "interleaving disabled!\n", ctrl_num);
york076bff82010-07-02 22:25:52 +00001234 }
1235 if (pdimm[0].capacity != pdimm[1].capacity) {
1236 popts->ba_intlv_ctl = 0;
1237 printf("Not identical DIMM size for "
1238 "CS0+CS1+CS2+CS3 on controller %d, "
York Suna4c66502012-08-17 08:22:39 +00001239 "interleaving disabled!\n", ctrl_num);
york076bff82010-07-02 22:25:52 +00001240 }
1241#endif
1242 break;
Haiying Wangc9ffd832008-10-03 12:37:10 -04001243 case FSL_DDR_CS0_CS1:
york5800e7a2010-07-02 22:25:53 +00001244 if (pdimm[0].n_ranks < 2) {
Haiying Wangc9ffd832008-10-03 12:37:10 -04001245 popts->ba_intlv_ctl = 0;
Ed Swarthout7008d262008-10-29 09:21:44 -05001246 printf("Not enough bank(chip-select) for "
york076bff82010-07-02 22:25:52 +00001247 "CS0+CS1 on controller %d, "
York Suna4c66502012-08-17 08:22:39 +00001248 "interleaving disabled!\n", ctrl_num);
Haiying Wangc9ffd832008-10-03 12:37:10 -04001249 }
1250 break;
1251 case FSL_DDR_CS2_CS3:
york076bff82010-07-02 22:25:52 +00001252#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
york5800e7a2010-07-02 22:25:53 +00001253 if (pdimm[0].n_ranks < 4) {
Haiying Wangc9ffd832008-10-03 12:37:10 -04001254 popts->ba_intlv_ctl = 0;
york076bff82010-07-02 22:25:52 +00001255 printf("Not enough bank(chip-select) for CS2+CS3 "
York Suna4c66502012-08-17 08:22:39 +00001256 "on controller %d, interleaving disabled!\n", ctrl_num);
Haiying Wangc9ffd832008-10-03 12:37:10 -04001257 }
york076bff82010-07-02 22:25:52 +00001258#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
york5800e7a2010-07-02 22:25:53 +00001259 if (pdimm[1].n_ranks < 2) {
york076bff82010-07-02 22:25:52 +00001260 popts->ba_intlv_ctl = 0;
1261 printf("Not enough bank(chip-select) for CS2+CS3 "
York Suna4c66502012-08-17 08:22:39 +00001262 "on controller %d, interleaving disabled!\n", ctrl_num);
york076bff82010-07-02 22:25:52 +00001263 }
1264#endif
Haiying Wangc9ffd832008-10-03 12:37:10 -04001265 break;
1266 case FSL_DDR_CS0_CS1_AND_CS2_CS3:
york076bff82010-07-02 22:25:52 +00001267#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
york5800e7a2010-07-02 22:25:53 +00001268 if (pdimm[0].n_ranks < 4) {
york076bff82010-07-02 22:25:52 +00001269 popts->ba_intlv_ctl = 0;
1270 printf("Not enough bank(CS) for CS0+CS1 and "
1271 "CS2+CS3 on controller %d, "
York Suna4c66502012-08-17 08:22:39 +00001272 "interleaving disabled!\n", ctrl_num);
york076bff82010-07-02 22:25:52 +00001273 }
1274#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
york5800e7a2010-07-02 22:25:53 +00001275 if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) {
Haiying Wangc9ffd832008-10-03 12:37:10 -04001276 popts->ba_intlv_ctl = 0;
york076bff82010-07-02 22:25:52 +00001277 printf("Not enough bank(CS) for CS0+CS1 and "
1278 "CS2+CS3 on controller %d, "
York Suna4c66502012-08-17 08:22:39 +00001279 "interleaving disabled!\n", ctrl_num);
Haiying Wangc9ffd832008-10-03 12:37:10 -04001280 }
york076bff82010-07-02 22:25:52 +00001281#endif
Haiying Wangc9ffd832008-10-03 12:37:10 -04001282 break;
1283 default:
1284 popts->ba_intlv_ctl = 0;
1285 break;
1286 }
1287 }
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001288
Kumar Galadd50af22011-01-09 11:37:00 -06001289 if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf)) {
1290 if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf))
york7fd101c2010-07-02 22:25:54 +00001291 popts->addr_hash = 0;
Kumar Galadd50af22011-01-09 11:37:00 -06001292 else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash",
1293 "true", buf))
york7fd101c2010-07-02 22:25:54 +00001294 popts->addr_hash = 1;
1295 }
1296
york5800e7a2010-07-02 22:25:53 +00001297 if (pdimm[0].n_ranks == 4)
1298 popts->quad_rank_present = 1;
1299
York Sunc0c32af2018-01-29 09:44:35 -08001300 popts->package_3ds = pdimm->package_3ds;
1301
York Sun564e9382018-01-29 10:24:08 -08001302#if (CONFIG_FSL_SDRAM_TYPE != SDRAM_TYPE_DDR4)
York Sun03e664d2015-01-06 13:18:50 -08001303 ddr_freq = get_ddr_freq(ctrl_num) / 1000000;
York Suncda1de22011-08-24 09:40:26 -07001304 if (popts->registered_dimm_en) {
1305 popts->rcw_override = 1;
1306 popts->rcw_1 = 0x000a5a00;
1307 if (ddr_freq <= 800)
1308 popts->rcw_2 = 0x00000000;
1309 else if (ddr_freq <= 1066)
1310 popts->rcw_2 = 0x00100000;
1311 else if (ddr_freq <= 1333)
1312 popts->rcw_2 = 0x00200000;
1313 else
1314 popts->rcw_2 = 0x00300000;
1315 }
York Sun564e9382018-01-29 10:24:08 -08001316#endif
York Suncda1de22011-08-24 09:40:26 -07001317
Haiying Wangdfb49102008-10-03 12:36:55 -04001318 fsl_ddr_board_options(popts, pdimm, ctrl_num);
Kumar Gala58e5e9a2008-08-26 15:01:29 -05001319
1320 return 0;
1321}
york076bff82010-07-02 22:25:52 +00001322
1323void check_interleaving_options(fsl_ddr_info_t *pinfo)
1324{
York Suna4c66502012-08-17 08:22:39 +00001325 int i, j, k, check_n_ranks, intlv_invalid = 0;
1326 unsigned int check_intlv, check_n_row_addr, check_n_col_addr;
york076bff82010-07-02 22:25:52 +00001327 unsigned long long check_rank_density;
York Suna4c66502012-08-17 08:22:39 +00001328 struct dimm_params_s *dimm;
York Sun1d71efb2014-08-01 15:51:00 -07001329 int first_ctrl = pinfo->first_ctrl;
1330 int last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
1331
york076bff82010-07-02 22:25:52 +00001332 /*
1333 * Check if all controllers are configured for memory
1334 * controller interleaving. Identical dimms are recommended. At least
York Suna4c66502012-08-17 08:22:39 +00001335 * the size, row and col address should be checked.
york076bff82010-07-02 22:25:52 +00001336 */
1337 j = 0;
York Sun1d71efb2014-08-01 15:51:00 -07001338 check_n_ranks = pinfo->dimm_params[first_ctrl][0].n_ranks;
1339 check_rank_density = pinfo->dimm_params[first_ctrl][0].rank_density;
1340 check_n_row_addr = pinfo->dimm_params[first_ctrl][0].n_row_addr;
1341 check_n_col_addr = pinfo->dimm_params[first_ctrl][0].n_col_addr;
1342 check_intlv = pinfo->memctl_opts[first_ctrl].memctl_interleaving_mode;
1343 for (i = first_ctrl; i <= last_ctrl; i++) {
York Suna4c66502012-08-17 08:22:39 +00001344 dimm = &pinfo->dimm_params[i][0];
1345 if (!pinfo->memctl_opts[i].memctl_interleaving) {
1346 continue;
1347 } else if (((check_rank_density != dimm->rank_density) ||
1348 (check_n_ranks != dimm->n_ranks) ||
1349 (check_n_row_addr != dimm->n_row_addr) ||
1350 (check_n_col_addr != dimm->n_col_addr) ||
1351 (check_intlv !=
1352 pinfo->memctl_opts[i].memctl_interleaving_mode))){
1353 intlv_invalid = 1;
1354 break;
1355 } else {
york076bff82010-07-02 22:25:52 +00001356 j++;
1357 }
York Suna4c66502012-08-17 08:22:39 +00001358
york076bff82010-07-02 22:25:52 +00001359 }
York Suna4c66502012-08-17 08:22:39 +00001360 if (intlv_invalid) {
York Sun1d71efb2014-08-01 15:51:00 -07001361 for (i = first_ctrl; i <= last_ctrl; i++)
York Suna4c66502012-08-17 08:22:39 +00001362 pinfo->memctl_opts[i].memctl_interleaving = 0;
1363 printf("Not all DIMMs are identical. "
1364 "Memory controller interleaving disabled.\n");
1365 } else {
1366 switch (check_intlv) {
York Sun6b1e1252014-02-10 13:59:44 -08001367 case FSL_DDR_256B_INTERLEAVING:
York Suna4c66502012-08-17 08:22:39 +00001368 case FSL_DDR_CACHE_LINE_INTERLEAVING:
1369 case FSL_DDR_PAGE_INTERLEAVING:
1370 case FSL_DDR_BANK_INTERLEAVING:
1371 case FSL_DDR_SUPERBANK_INTERLEAVING:
York Sun51370d52016-12-28 08:43:45 -08001372#if (3 == CONFIG_SYS_NUM_DDR_CTLRS)
York Suna4c66502012-08-17 08:22:39 +00001373 k = 2;
York Sun349689b2014-04-01 14:20:49 -07001374#else
York Sun51370d52016-12-28 08:43:45 -08001375 k = CONFIG_SYS_NUM_DDR_CTLRS;
York Sun349689b2014-04-01 14:20:49 -07001376#endif
York Suna4c66502012-08-17 08:22:39 +00001377 break;
1378 case FSL_DDR_3WAY_1KB_INTERLEAVING:
1379 case FSL_DDR_3WAY_4KB_INTERLEAVING:
1380 case FSL_DDR_3WAY_8KB_INTERLEAVING:
1381 case FSL_DDR_4WAY_1KB_INTERLEAVING:
1382 case FSL_DDR_4WAY_4KB_INTERLEAVING:
1383 case FSL_DDR_4WAY_8KB_INTERLEAVING:
1384 default:
York Sun51370d52016-12-28 08:43:45 -08001385 k = CONFIG_SYS_NUM_DDR_CTLRS;
York Suna4c66502012-08-17 08:22:39 +00001386 break;
1387 }
1388 debug("%d of %d controllers are interleaving.\n", j, k);
York Sun89b78092012-10-08 07:44:27 +00001389 if (j && (j != k)) {
York Sun1d71efb2014-08-01 15:51:00 -07001390 for (i = first_ctrl; i <= last_ctrl; i++)
york076bff82010-07-02 22:25:52 +00001391 pinfo->memctl_opts[i].memctl_interleaving = 0;
York Sun1d71efb2014-08-01 15:51:00 -07001392 if ((last_ctrl - first_ctrl) > 1)
1393 puts("Not all controllers have compatible interleaving mode. All disabled.\n");
York Suna4c66502012-08-17 08:22:39 +00001394 }
york076bff82010-07-02 22:25:52 +00001395 }
York Suna4c66502012-08-17 08:22:39 +00001396 debug("Checking interleaving options completed\n");
york076bff82010-07-02 22:25:52 +00001397}
Kumar Gala3dbd5d72011-01-09 14:06:28 -06001398
1399int fsl_use_spd(void)
1400{
1401 int use_spd = 0;
1402
1403#ifdef CONFIG_DDR_SPD
Jeremy Gebben86b840b2018-07-20 16:00:36 -06001404 char buf[HWCONFIG_BUFFER_SIZE];
Kumar Galadd50af22011-01-09 11:37:00 -06001405
1406 /*
1407 * Extract hwconfig from environment since we have not properly setup
1408 * the environment but need it for ddr config params
1409 */
Jeremy Gebben86b840b2018-07-20 16:00:36 -06001410 if (env_get_f("hwconfig", buf, sizeof(buf)) < 0)
1411 buf[0] = '\0';
Kumar Galadd50af22011-01-09 11:37:00 -06001412
Kumar Gala3dbd5d72011-01-09 14:06:28 -06001413 /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
Kumar Galadd50af22011-01-09 11:37:00 -06001414 if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) {
1415 if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf))
Kumar Gala3dbd5d72011-01-09 14:06:28 -06001416 use_spd = 1;
Kumar Galadd50af22011-01-09 11:37:00 -06001417 else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram",
1418 "fixed", buf))
Kumar Gala3dbd5d72011-01-09 14:06:28 -06001419 use_spd = 0;
1420 else
1421 use_spd = 1;
1422 } else
1423 use_spd = 1;
1424#endif
1425
1426 return use_spd;
1427}