options.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. /*
  2. * Copyright 2008, 2010-2014 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <hwconfig.h>
  8. #include <fsl_ddr_sdram.h>
  9. #include <fsl_ddr.h>
  10. /*
  11. * Use our own stack based buffer before relocation to allow accessing longer
  12. * hwconfig strings that might be in the environment before we've relocated.
  13. * This is pretty fragile on both the use of stack and if the buffer is big
  14. * enough. However we will get a warning from getenv_f for the later.
  15. */
  16. /* Board-specific functions defined in each board's ddr.c */
  17. extern void fsl_ddr_board_options(memctl_options_t *popts,
  18. dimm_params_t *pdimm,
  19. unsigned int ctrl_num);
  20. struct dynamic_odt {
  21. unsigned int odt_rd_cfg;
  22. unsigned int odt_wr_cfg;
  23. unsigned int odt_rtt_norm;
  24. unsigned int odt_rtt_wr;
  25. };
  26. #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
  27. static const struct dynamic_odt single_Q[4] = {
  28. { /* cs0 */
  29. FSL_DDR_ODT_NEVER,
  30. FSL_DDR_ODT_CS_AND_OTHER_DIMM,
  31. DDR3_RTT_20_OHM,
  32. DDR3_RTT_120_OHM
  33. },
  34. { /* cs1 */
  35. FSL_DDR_ODT_NEVER,
  36. FSL_DDR_ODT_NEVER, /* tied high */
  37. DDR3_RTT_OFF,
  38. DDR3_RTT_120_OHM
  39. },
  40. { /* cs2 */
  41. FSL_DDR_ODT_NEVER,
  42. FSL_DDR_ODT_CS_AND_OTHER_DIMM,
  43. DDR3_RTT_20_OHM,
  44. DDR3_RTT_120_OHM
  45. },
  46. { /* cs3 */
  47. FSL_DDR_ODT_NEVER,
  48. FSL_DDR_ODT_NEVER, /* tied high */
  49. DDR3_RTT_OFF,
  50. DDR3_RTT_120_OHM
  51. }
  52. };
  53. static const struct dynamic_odt single_D[4] = {
  54. { /* cs0 */
  55. FSL_DDR_ODT_NEVER,
  56. FSL_DDR_ODT_ALL,
  57. DDR3_RTT_40_OHM,
  58. DDR3_RTT_OFF
  59. },
  60. { /* cs1 */
  61. FSL_DDR_ODT_NEVER,
  62. FSL_DDR_ODT_NEVER,
  63. DDR3_RTT_OFF,
  64. DDR3_RTT_OFF
  65. },
  66. {0, 0, 0, 0},
  67. {0, 0, 0, 0}
  68. };
  69. static const struct dynamic_odt single_S[4] = {
  70. { /* cs0 */
  71. FSL_DDR_ODT_NEVER,
  72. FSL_DDR_ODT_ALL,
  73. DDR3_RTT_40_OHM,
  74. DDR3_RTT_OFF
  75. },
  76. {0, 0, 0, 0},
  77. {0, 0, 0, 0},
  78. {0, 0, 0, 0},
  79. };
  80. static const struct dynamic_odt dual_DD[4] = {
  81. { /* cs0 */
  82. FSL_DDR_ODT_NEVER,
  83. FSL_DDR_ODT_SAME_DIMM,
  84. DDR3_RTT_120_OHM,
  85. DDR3_RTT_OFF
  86. },
  87. { /* cs1 */
  88. FSL_DDR_ODT_OTHER_DIMM,
  89. FSL_DDR_ODT_OTHER_DIMM,
  90. DDR3_RTT_30_OHM,
  91. DDR3_RTT_OFF
  92. },
  93. { /* cs2 */
  94. FSL_DDR_ODT_NEVER,
  95. FSL_DDR_ODT_SAME_DIMM,
  96. DDR3_RTT_120_OHM,
  97. DDR3_RTT_OFF
  98. },
  99. { /* cs3 */
  100. FSL_DDR_ODT_OTHER_DIMM,
  101. FSL_DDR_ODT_OTHER_DIMM,
  102. DDR3_RTT_30_OHM,
  103. DDR3_RTT_OFF
  104. }
  105. };
  106. static const struct dynamic_odt dual_DS[4] = {
  107. { /* cs0 */
  108. FSL_DDR_ODT_NEVER,
  109. FSL_DDR_ODT_SAME_DIMM,
  110. DDR3_RTT_120_OHM,
  111. DDR3_RTT_OFF
  112. },
  113. { /* cs1 */
  114. FSL_DDR_ODT_OTHER_DIMM,
  115. FSL_DDR_ODT_OTHER_DIMM,
  116. DDR3_RTT_30_OHM,
  117. DDR3_RTT_OFF
  118. },
  119. { /* cs2 */
  120. FSL_DDR_ODT_OTHER_DIMM,
  121. FSL_DDR_ODT_ALL,
  122. DDR3_RTT_20_OHM,
  123. DDR3_RTT_120_OHM
  124. },
  125. {0, 0, 0, 0}
  126. };
  127. static const struct dynamic_odt dual_SD[4] = {
  128. { /* cs0 */
  129. FSL_DDR_ODT_OTHER_DIMM,
  130. FSL_DDR_ODT_ALL,
  131. DDR3_RTT_20_OHM,
  132. DDR3_RTT_120_OHM
  133. },
  134. {0, 0, 0, 0},
  135. { /* cs2 */
  136. FSL_DDR_ODT_NEVER,
  137. FSL_DDR_ODT_SAME_DIMM,
  138. DDR3_RTT_120_OHM,
  139. DDR3_RTT_OFF
  140. },
  141. { /* cs3 */
  142. FSL_DDR_ODT_OTHER_DIMM,
  143. FSL_DDR_ODT_OTHER_DIMM,
  144. DDR3_RTT_20_OHM,
  145. DDR3_RTT_OFF
  146. }
  147. };
  148. static const struct dynamic_odt dual_SS[4] = {
  149. { /* cs0 */
  150. FSL_DDR_ODT_OTHER_DIMM,
  151. FSL_DDR_ODT_ALL,
  152. DDR3_RTT_30_OHM,
  153. DDR3_RTT_120_OHM
  154. },
  155. {0, 0, 0, 0},
  156. { /* cs2 */
  157. FSL_DDR_ODT_OTHER_DIMM,
  158. FSL_DDR_ODT_ALL,
  159. DDR3_RTT_30_OHM,
  160. DDR3_RTT_120_OHM
  161. },
  162. {0, 0, 0, 0}
  163. };
  164. static const struct dynamic_odt dual_D0[4] = {
  165. { /* cs0 */
  166. FSL_DDR_ODT_NEVER,
  167. FSL_DDR_ODT_SAME_DIMM,
  168. DDR3_RTT_40_OHM,
  169. DDR3_RTT_OFF
  170. },
  171. { /* cs1 */
  172. FSL_DDR_ODT_NEVER,
  173. FSL_DDR_ODT_NEVER,
  174. DDR3_RTT_OFF,
  175. DDR3_RTT_OFF
  176. },
  177. {0, 0, 0, 0},
  178. {0, 0, 0, 0}
  179. };
  180. static const struct dynamic_odt dual_0D[4] = {
  181. {0, 0, 0, 0},
  182. {0, 0, 0, 0},
  183. { /* cs2 */
  184. FSL_DDR_ODT_NEVER,
  185. FSL_DDR_ODT_SAME_DIMM,
  186. DDR3_RTT_40_OHM,
  187. DDR3_RTT_OFF
  188. },
  189. { /* cs3 */
  190. FSL_DDR_ODT_NEVER,
  191. FSL_DDR_ODT_NEVER,
  192. DDR3_RTT_OFF,
  193. DDR3_RTT_OFF
  194. }
  195. };
  196. static const struct dynamic_odt dual_S0[4] = {
  197. { /* cs0 */
  198. FSL_DDR_ODT_NEVER,
  199. FSL_DDR_ODT_CS,
  200. DDR3_RTT_40_OHM,
  201. DDR3_RTT_OFF
  202. },
  203. {0, 0, 0, 0},
  204. {0, 0, 0, 0},
  205. {0, 0, 0, 0}
  206. };
  207. static const struct dynamic_odt dual_0S[4] = {
  208. {0, 0, 0, 0},
  209. {0, 0, 0, 0},
  210. { /* cs2 */
  211. FSL_DDR_ODT_NEVER,
  212. FSL_DDR_ODT_CS,
  213. DDR3_RTT_40_OHM,
  214. DDR3_RTT_OFF
  215. },
  216. {0, 0, 0, 0}
  217. };
  218. static const struct dynamic_odt odt_unknown[4] = {
  219. { /* cs0 */
  220. FSL_DDR_ODT_NEVER,
  221. FSL_DDR_ODT_CS,
  222. DDR3_RTT_120_OHM,
  223. DDR3_RTT_OFF
  224. },
  225. { /* cs1 */
  226. FSL_DDR_ODT_NEVER,
  227. FSL_DDR_ODT_CS,
  228. DDR3_RTT_120_OHM,
  229. DDR3_RTT_OFF
  230. },
  231. { /* cs2 */
  232. FSL_DDR_ODT_NEVER,
  233. FSL_DDR_ODT_CS,
  234. DDR3_RTT_120_OHM,
  235. DDR3_RTT_OFF
  236. },
  237. { /* cs3 */
  238. FSL_DDR_ODT_NEVER,
  239. FSL_DDR_ODT_CS,
  240. DDR3_RTT_120_OHM,
  241. DDR3_RTT_OFF
  242. }
  243. };
  244. #else /* CONFIG_SYS_FSL_DDR3 || CONFIG_SYS_FSL_DDR4 */
  245. static const struct dynamic_odt single_Q[4] = {
  246. {0, 0, 0, 0},
  247. {0, 0, 0, 0},
  248. {0, 0, 0, 0},
  249. {0, 0, 0, 0}
  250. };
  251. static const struct dynamic_odt single_D[4] = {
  252. { /* cs0 */
  253. FSL_DDR_ODT_NEVER,
  254. FSL_DDR_ODT_ALL,
  255. DDR2_RTT_150_OHM,
  256. DDR2_RTT_OFF
  257. },
  258. { /* cs1 */
  259. FSL_DDR_ODT_NEVER,
  260. FSL_DDR_ODT_NEVER,
  261. DDR2_RTT_OFF,
  262. DDR2_RTT_OFF
  263. },
  264. {0, 0, 0, 0},
  265. {0, 0, 0, 0}
  266. };
  267. static const struct dynamic_odt single_S[4] = {
  268. { /* cs0 */
  269. FSL_DDR_ODT_NEVER,
  270. FSL_DDR_ODT_ALL,
  271. DDR2_RTT_150_OHM,
  272. DDR2_RTT_OFF
  273. },
  274. {0, 0, 0, 0},
  275. {0, 0, 0, 0},
  276. {0, 0, 0, 0},
  277. };
  278. static const struct dynamic_odt dual_DD[4] = {
  279. { /* cs0 */
  280. FSL_DDR_ODT_OTHER_DIMM,
  281. FSL_DDR_ODT_OTHER_DIMM,
  282. DDR2_RTT_75_OHM,
  283. DDR2_RTT_OFF
  284. },
  285. { /* cs1 */
  286. FSL_DDR_ODT_NEVER,
  287. FSL_DDR_ODT_NEVER,
  288. DDR2_RTT_OFF,
  289. DDR2_RTT_OFF
  290. },
  291. { /* cs2 */
  292. FSL_DDR_ODT_OTHER_DIMM,
  293. FSL_DDR_ODT_OTHER_DIMM,
  294. DDR2_RTT_75_OHM,
  295. DDR2_RTT_OFF
  296. },
  297. { /* cs3 */
  298. FSL_DDR_ODT_NEVER,
  299. FSL_DDR_ODT_NEVER,
  300. DDR2_RTT_OFF,
  301. DDR2_RTT_OFF
  302. }
  303. };
  304. static const struct dynamic_odt dual_DS[4] = {
  305. { /* cs0 */
  306. FSL_DDR_ODT_OTHER_DIMM,
  307. FSL_DDR_ODT_OTHER_DIMM,
  308. DDR2_RTT_75_OHM,
  309. DDR2_RTT_OFF
  310. },
  311. { /* cs1 */
  312. FSL_DDR_ODT_NEVER,
  313. FSL_DDR_ODT_NEVER,
  314. DDR2_RTT_OFF,
  315. DDR2_RTT_OFF
  316. },
  317. { /* cs2 */
  318. FSL_DDR_ODT_OTHER_DIMM,
  319. FSL_DDR_ODT_OTHER_DIMM,
  320. DDR2_RTT_75_OHM,
  321. DDR2_RTT_OFF
  322. },
  323. {0, 0, 0, 0}
  324. };
  325. static const struct dynamic_odt dual_SD[4] = {
  326. { /* cs0 */
  327. FSL_DDR_ODT_OTHER_DIMM,
  328. FSL_DDR_ODT_OTHER_DIMM,
  329. DDR2_RTT_75_OHM,
  330. DDR2_RTT_OFF
  331. },
  332. {0, 0, 0, 0},
  333. { /* cs2 */
  334. FSL_DDR_ODT_OTHER_DIMM,
  335. FSL_DDR_ODT_OTHER_DIMM,
  336. DDR2_RTT_75_OHM,
  337. DDR2_RTT_OFF
  338. },
  339. { /* cs3 */
  340. FSL_DDR_ODT_NEVER,
  341. FSL_DDR_ODT_NEVER,
  342. DDR2_RTT_OFF,
  343. DDR2_RTT_OFF
  344. }
  345. };
  346. static const struct dynamic_odt dual_SS[4] = {
  347. { /* cs0 */
  348. FSL_DDR_ODT_OTHER_DIMM,
  349. FSL_DDR_ODT_OTHER_DIMM,
  350. DDR2_RTT_75_OHM,
  351. DDR2_RTT_OFF
  352. },
  353. {0, 0, 0, 0},
  354. { /* cs2 */
  355. FSL_DDR_ODT_OTHER_DIMM,
  356. FSL_DDR_ODT_OTHER_DIMM,
  357. DDR2_RTT_75_OHM,
  358. DDR2_RTT_OFF
  359. },
  360. {0, 0, 0, 0}
  361. };
  362. static const struct dynamic_odt dual_D0[4] = {
  363. { /* cs0 */
  364. FSL_DDR_ODT_NEVER,
  365. FSL_DDR_ODT_ALL,
  366. DDR2_RTT_150_OHM,
  367. DDR2_RTT_OFF
  368. },
  369. { /* cs1 */
  370. FSL_DDR_ODT_NEVER,
  371. FSL_DDR_ODT_NEVER,
  372. DDR2_RTT_OFF,
  373. DDR2_RTT_OFF
  374. },
  375. {0, 0, 0, 0},
  376. {0, 0, 0, 0}
  377. };
  378. static const struct dynamic_odt dual_0D[4] = {
  379. {0, 0, 0, 0},
  380. {0, 0, 0, 0},
  381. { /* cs2 */
  382. FSL_DDR_ODT_NEVER,
  383. FSL_DDR_ODT_ALL,
  384. DDR2_RTT_150_OHM,
  385. DDR2_RTT_OFF
  386. },
  387. { /* cs3 */
  388. FSL_DDR_ODT_NEVER,
  389. FSL_DDR_ODT_NEVER,
  390. DDR2_RTT_OFF,
  391. DDR2_RTT_OFF
  392. }
  393. };
  394. static const struct dynamic_odt dual_S0[4] = {
  395. { /* cs0 */
  396. FSL_DDR_ODT_NEVER,
  397. FSL_DDR_ODT_CS,
  398. DDR2_RTT_150_OHM,
  399. DDR2_RTT_OFF
  400. },
  401. {0, 0, 0, 0},
  402. {0, 0, 0, 0},
  403. {0, 0, 0, 0}
  404. };
  405. static const struct dynamic_odt dual_0S[4] = {
  406. {0, 0, 0, 0},
  407. {0, 0, 0, 0},
  408. { /* cs2 */
  409. FSL_DDR_ODT_NEVER,
  410. FSL_DDR_ODT_CS,
  411. DDR2_RTT_150_OHM,
  412. DDR2_RTT_OFF
  413. },
  414. {0, 0, 0, 0}
  415. };
  416. static const struct dynamic_odt odt_unknown[4] = {
  417. { /* cs0 */
  418. FSL_DDR_ODT_NEVER,
  419. FSL_DDR_ODT_CS,
  420. DDR2_RTT_75_OHM,
  421. DDR2_RTT_OFF
  422. },
  423. { /* cs1 */
  424. FSL_DDR_ODT_NEVER,
  425. FSL_DDR_ODT_NEVER,
  426. DDR2_RTT_OFF,
  427. DDR2_RTT_OFF
  428. },
  429. { /* cs2 */
  430. FSL_DDR_ODT_NEVER,
  431. FSL_DDR_ODT_CS,
  432. DDR2_RTT_75_OHM,
  433. DDR2_RTT_OFF
  434. },
  435. { /* cs3 */
  436. FSL_DDR_ODT_NEVER,
  437. FSL_DDR_ODT_NEVER,
  438. DDR2_RTT_OFF,
  439. DDR2_RTT_OFF
  440. }
  441. };
  442. #endif
  443. /*
  444. * Automatically seleect bank interleaving mode based on DIMMs
  445. * in this order: cs0_cs1_cs2_cs3, cs0_cs1, null.
  446. * This function only deal with one or two slots per controller.
  447. */
  448. static inline unsigned int auto_bank_intlv(dimm_params_t *pdimm)
  449. {
  450. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  451. if (pdimm[0].n_ranks == 4)
  452. return FSL_DDR_CS0_CS1_CS2_CS3;
  453. else if (pdimm[0].n_ranks == 2)
  454. return FSL_DDR_CS0_CS1;
  455. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  456. #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
  457. if (pdimm[0].n_ranks == 4)
  458. return FSL_DDR_CS0_CS1_CS2_CS3;
  459. #endif
  460. if (pdimm[0].n_ranks == 2) {
  461. if (pdimm[1].n_ranks == 2)
  462. return FSL_DDR_CS0_CS1_CS2_CS3;
  463. else
  464. return FSL_DDR_CS0_CS1;
  465. }
  466. #endif
  467. return 0;
  468. }
  469. unsigned int populate_memctl_options(int all_dimms_registered,
  470. memctl_options_t *popts,
  471. dimm_params_t *pdimm,
  472. unsigned int ctrl_num)
  473. {
  474. unsigned int i;
  475. char buffer[HWCONFIG_BUFFER_SIZE];
  476. char *buf = NULL;
  477. #if defined(CONFIG_SYS_FSL_DDR3) || \
  478. defined(CONFIG_SYS_FSL_DDR2) || \
  479. defined(CONFIG_SYS_FSL_DDR4)
  480. const struct dynamic_odt *pdodt = odt_unknown;
  481. #endif
  482. ulong ddr_freq;
  483. /*
  484. * Extract hwconfig from environment since we have not properly setup
  485. * the environment but need it for ddr config params
  486. */
  487. if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0)
  488. buf = buffer;
  489. #if defined(CONFIG_SYS_FSL_DDR3) || \
  490. defined(CONFIG_SYS_FSL_DDR2) || \
  491. defined(CONFIG_SYS_FSL_DDR4)
  492. /* Chip select options. */
  493. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  494. switch (pdimm[0].n_ranks) {
  495. case 1:
  496. pdodt = single_S;
  497. break;
  498. case 2:
  499. pdodt = single_D;
  500. break;
  501. case 4:
  502. pdodt = single_Q;
  503. break;
  504. }
  505. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  506. switch (pdimm[0].n_ranks) {
  507. #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
  508. case 4:
  509. pdodt = single_Q;
  510. if (pdimm[1].n_ranks)
  511. printf("Error: Quad- and Dual-rank DIMMs cannot be used together\n");
  512. break;
  513. #endif
  514. case 2:
  515. switch (pdimm[1].n_ranks) {
  516. case 2:
  517. pdodt = dual_DD;
  518. break;
  519. case 1:
  520. pdodt = dual_DS;
  521. break;
  522. case 0:
  523. pdodt = dual_D0;
  524. break;
  525. }
  526. break;
  527. case 1:
  528. switch (pdimm[1].n_ranks) {
  529. case 2:
  530. pdodt = dual_SD;
  531. break;
  532. case 1:
  533. pdodt = dual_SS;
  534. break;
  535. case 0:
  536. pdodt = dual_S0;
  537. break;
  538. }
  539. break;
  540. case 0:
  541. switch (pdimm[1].n_ranks) {
  542. case 2:
  543. pdodt = dual_0D;
  544. break;
  545. case 1:
  546. pdodt = dual_0S;
  547. break;
  548. }
  549. break;
  550. }
  551. #endif /* CONFIG_DIMM_SLOTS_PER_CTLR */
  552. #endif /* CONFIG_SYS_FSL_DDR2, 3, 4 */
  553. /* Pick chip-select local options. */
  554. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  555. #if defined(CONFIG_SYS_FSL_DDR3) || \
  556. defined(CONFIG_SYS_FSL_DDR2) || \
  557. defined(CONFIG_SYS_FSL_DDR4)
  558. popts->cs_local_opts[i].odt_rd_cfg = pdodt[i].odt_rd_cfg;
  559. popts->cs_local_opts[i].odt_wr_cfg = pdodt[i].odt_wr_cfg;
  560. popts->cs_local_opts[i].odt_rtt_norm = pdodt[i].odt_rtt_norm;
  561. popts->cs_local_opts[i].odt_rtt_wr = pdodt[i].odt_rtt_wr;
  562. #else
  563. popts->cs_local_opts[i].odt_rd_cfg = FSL_DDR_ODT_NEVER;
  564. popts->cs_local_opts[i].odt_wr_cfg = FSL_DDR_ODT_CS;
  565. #endif
  566. popts->cs_local_opts[i].auto_precharge = 0;
  567. }
  568. /* Pick interleaving mode. */
  569. /*
  570. * 0 = no interleaving
  571. * 1 = interleaving between 2 controllers
  572. */
  573. popts->memctl_interleaving = 0;
  574. /*
  575. * 0 = cacheline
  576. * 1 = page
  577. * 2 = (logical) bank
  578. * 3 = superbank (only if CS interleaving is enabled)
  579. */
  580. popts->memctl_interleaving_mode = 0;
  581. /*
  582. * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
  583. * 1: page: bit to the left of the column bits selects the memctl
  584. * 2: bank: bit to the left of the bank bits selects the memctl
  585. * 3: superbank: bit to the left of the chip select selects the memctl
  586. *
  587. * NOTE: ba_intlv (rank interleaving) is independent of memory
  588. * controller interleaving; it is only within a memory controller.
  589. * Must use superbank interleaving if rank interleaving is used and
  590. * memory controller interleaving is enabled.
  591. */
  592. /*
  593. * 0 = no
  594. * 0x40 = CS0,CS1
  595. * 0x20 = CS2,CS3
  596. * 0x60 = CS0,CS1 + CS2,CS3
  597. * 0x04 = CS0,CS1,CS2,CS3
  598. */
  599. popts->ba_intlv_ctl = 0;
  600. /* Memory Organization Parameters */
  601. popts->registered_dimm_en = all_dimms_registered;
  602. /* Operational Mode Paramters */
  603. /* Pick ECC modes */
  604. popts->ecc_mode = 0; /* 0 = disabled, 1 = enabled */
  605. #ifdef CONFIG_DDR_ECC
  606. if (hwconfig_sub_f("fsl_ddr", "ecc", buf)) {
  607. if (hwconfig_subarg_cmp_f("fsl_ddr", "ecc", "on", buf))
  608. popts->ecc_mode = 1;
  609. } else
  610. popts->ecc_mode = 1;
  611. #endif
  612. popts->ecc_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */
  613. /*
  614. * Choose DQS config
  615. * 0 for DDR1
  616. * 1 for DDR2
  617. */
  618. #if defined(CONFIG_SYS_FSL_DDR1)
  619. popts->dqs_config = 0;
  620. #elif defined(CONFIG_SYS_FSL_DDR2) || defined(CONFIG_SYS_FSL_DDR3)
  621. popts->dqs_config = 1;
  622. #endif
  623. /* Choose self-refresh during sleep. */
  624. popts->self_refresh_in_sleep = 1;
  625. /* Choose dynamic power management mode. */
  626. popts->dynamic_power = 0;
  627. /*
  628. * check first dimm for primary sdram width
  629. * presuming all dimms are similar
  630. * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit
  631. */
  632. #if defined(CONFIG_SYS_FSL_DDR1) || defined(CONFIG_SYS_FSL_DDR2)
  633. if (pdimm[0].n_ranks != 0) {
  634. if ((pdimm[0].data_width >= 64) && \
  635. (pdimm[0].data_width <= 72))
  636. popts->data_bus_width = 0;
  637. else if ((pdimm[0].data_width >= 32) || \
  638. (pdimm[0].data_width <= 40))
  639. popts->data_bus_width = 1;
  640. else {
  641. panic("Error: data width %u is invalid!\n",
  642. pdimm[0].data_width);
  643. }
  644. }
  645. #else
  646. if (pdimm[0].n_ranks != 0) {
  647. if (pdimm[0].primary_sdram_width == 64)
  648. popts->data_bus_width = 0;
  649. else if (pdimm[0].primary_sdram_width == 32)
  650. popts->data_bus_width = 1;
  651. else if (pdimm[0].primary_sdram_width == 16)
  652. popts->data_bus_width = 2;
  653. else {
  654. panic("Error: primary sdram width %u is invalid!\n",
  655. pdimm[0].primary_sdram_width);
  656. }
  657. }
  658. #endif
  659. popts->x4_en = (pdimm[0].device_width == 4) ? 1 : 0;
  660. /* Choose burst length. */
  661. #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
  662. #if defined(CONFIG_E500MC)
  663. popts->otf_burst_chop_en = 0; /* on-the-fly burst chop disable */
  664. popts->burst_length = DDR_BL8; /* Fixed 8-beat burst len */
  665. #else
  666. if ((popts->data_bus_width == 1) || (popts->data_bus_width == 2)) {
  667. /* 32-bit or 16-bit bus */
  668. popts->otf_burst_chop_en = 0;
  669. popts->burst_length = DDR_BL8;
  670. } else {
  671. popts->otf_burst_chop_en = 1; /* on-the-fly burst chop */
  672. popts->burst_length = DDR_OTF; /* on-the-fly BC4 and BL8 */
  673. }
  674. #endif
  675. #else
  676. popts->burst_length = DDR_BL4; /* has to be 4 for DDR2 */
  677. #endif
  678. /* Choose ddr controller address mirror mode */
  679. #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
  680. for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
  681. if (pdimm[i].n_ranks) {
  682. popts->mirrored_dimm = pdimm[i].mirrored_dimm;
  683. break;
  684. }
  685. }
  686. #endif
  687. /* Global Timing Parameters. */
  688. debug("mclk_ps = %u ps\n", get_memory_clk_period_ps(ctrl_num));
  689. /* Pick a caslat override. */
  690. popts->cas_latency_override = 0;
  691. popts->cas_latency_override_value = 3;
  692. if (popts->cas_latency_override) {
  693. debug("using caslat override value = %u\n",
  694. popts->cas_latency_override_value);
  695. }
  696. /* Decide whether to use the computed derated latency */
  697. popts->use_derated_caslat = 0;
  698. /* Choose an additive latency. */
  699. popts->additive_latency_override = 0;
  700. popts->additive_latency_override_value = 3;
  701. if (popts->additive_latency_override) {
  702. debug("using additive latency override value = %u\n",
  703. popts->additive_latency_override_value);
  704. }
  705. /*
  706. * 2T_EN setting
  707. *
  708. * Factors to consider for 2T_EN:
  709. * - number of DIMMs installed
  710. * - number of components, number of active ranks
  711. * - how much time you want to spend playing around
  712. */
  713. popts->twot_en = 0;
  714. popts->threet_en = 0;
  715. /* for RDIMM, address parity enable */
  716. popts->ap_en = 1;
  717. /*
  718. * BSTTOPRE precharge interval
  719. *
  720. * Set this to 0 for global auto precharge
  721. * The value of 0x100 has been used for DDR1, DDR2, DDR3.
  722. * It is not wrong. Any value should be OK. The performance depends on
  723. * applications. There is no one good value for all.
  724. */
  725. popts->bstopre = 0x100;
  726. /*
  727. * Window for four activates -- tFAW
  728. *
  729. * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
  730. * FIXME: varies depending upon number of column addresses or data
  731. * FIXME: width, was considering looking at pdimm->primary_sdram_width
  732. */
  733. #if defined(CONFIG_SYS_FSL_DDR1)
  734. popts->tfaw_window_four_activates_ps = mclk_to_picos(ctrl_num, 1);
  735. #elif defined(CONFIG_SYS_FSL_DDR2)
  736. /*
  737. * x4/x8; some datasheets have 35000
  738. * x16 wide columns only? Use 50000?
  739. */
  740. popts->tfaw_window_four_activates_ps = 37500;
  741. #else
  742. popts->tfaw_window_four_activates_ps = pdimm[0].tfaw_ps;
  743. #endif
  744. popts->zq_en = 0;
  745. popts->wrlvl_en = 0;
  746. #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
  747. /*
  748. * due to ddr3 dimm is fly-by topology
  749. * we suggest to enable write leveling to
  750. * meet the tQDSS under different loading.
  751. */
  752. popts->wrlvl_en = 1;
  753. popts->zq_en = 1;
  754. popts->wrlvl_override = 0;
  755. #endif
  756. /*
  757. * Check interleaving configuration from environment.
  758. * Please refer to doc/README.fsl-ddr for the detail.
  759. *
  760. * If memory controller interleaving is enabled, then the data
  761. * bus widths must be programmed identically for all memory controllers.
  762. *
  763. * Attempt to set all controllers to the same chip select
  764. * interleaving mode. It will do a best effort to get the
  765. * requested ranks interleaved together such that the result
  766. * should be a subset of the requested configuration.
  767. *
  768. * if CONFIG_SYS_FSL_DDR_INTLV_256B is defined, mandatory interleaving
  769. * with 256 Byte is enabled.
  770. */
  771. #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
  772. if (!hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf))
  773. #ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
  774. ;
  775. #else
  776. goto done;
  777. #endif
  778. if (pdimm[0].n_ranks == 0) {
  779. printf("There is no rank on CS0 for controller %d.\n", ctrl_num);
  780. popts->memctl_interleaving = 0;
  781. goto done;
  782. }
  783. popts->memctl_interleaving = 1;
  784. #ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
  785. popts->memctl_interleaving_mode = FSL_DDR_256B_INTERLEAVING;
  786. popts->memctl_interleaving = 1;
  787. debug("256 Byte interleaving\n");
  788. #else
  789. /*
  790. * test null first. if CONFIG_HWCONFIG is not defined
  791. * hwconfig_arg_cmp returns non-zero
  792. */
  793. if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  794. "null", buf)) {
  795. popts->memctl_interleaving = 0;
  796. debug("memory controller interleaving disabled.\n");
  797. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  798. "ctlr_intlv",
  799. "cacheline", buf)) {
  800. popts->memctl_interleaving_mode =
  801. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  802. 0 : FSL_DDR_CACHE_LINE_INTERLEAVING;
  803. popts->memctl_interleaving =
  804. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  805. 0 : 1;
  806. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  807. "ctlr_intlv",
  808. "page", buf)) {
  809. popts->memctl_interleaving_mode =
  810. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  811. 0 : FSL_DDR_PAGE_INTERLEAVING;
  812. popts->memctl_interleaving =
  813. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  814. 0 : 1;
  815. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  816. "ctlr_intlv",
  817. "bank", buf)) {
  818. popts->memctl_interleaving_mode =
  819. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  820. 0 : FSL_DDR_BANK_INTERLEAVING;
  821. popts->memctl_interleaving =
  822. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  823. 0 : 1;
  824. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  825. "ctlr_intlv",
  826. "superbank", buf)) {
  827. popts->memctl_interleaving_mode =
  828. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  829. 0 : FSL_DDR_SUPERBANK_INTERLEAVING;
  830. popts->memctl_interleaving =
  831. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  832. 0 : 1;
  833. #if (CONFIG_NUM_DDR_CONTROLLERS == 3)
  834. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  835. "ctlr_intlv",
  836. "3way_1KB", buf)) {
  837. popts->memctl_interleaving_mode =
  838. FSL_DDR_3WAY_1KB_INTERLEAVING;
  839. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  840. "ctlr_intlv",
  841. "3way_4KB", buf)) {
  842. popts->memctl_interleaving_mode =
  843. FSL_DDR_3WAY_4KB_INTERLEAVING;
  844. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  845. "ctlr_intlv",
  846. "3way_8KB", buf)) {
  847. popts->memctl_interleaving_mode =
  848. FSL_DDR_3WAY_8KB_INTERLEAVING;
  849. #elif (CONFIG_NUM_DDR_CONTROLLERS == 4)
  850. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  851. "ctlr_intlv",
  852. "4way_1KB", buf)) {
  853. popts->memctl_interleaving_mode =
  854. FSL_DDR_4WAY_1KB_INTERLEAVING;
  855. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  856. "ctlr_intlv",
  857. "4way_4KB", buf)) {
  858. popts->memctl_interleaving_mode =
  859. FSL_DDR_4WAY_4KB_INTERLEAVING;
  860. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  861. "ctlr_intlv",
  862. "4way_8KB", buf)) {
  863. popts->memctl_interleaving_mode =
  864. FSL_DDR_4WAY_8KB_INTERLEAVING;
  865. #endif
  866. } else {
  867. popts->memctl_interleaving = 0;
  868. printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
  869. }
  870. #endif /* CONFIG_SYS_FSL_DDR_INTLV_256B */
  871. done:
  872. #endif /* CONFIG_NUM_DDR_CONTROLLERS > 1 */
  873. if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) &&
  874. (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) {
  875. /* test null first. if CONFIG_HWCONFIG is not defined,
  876. * hwconfig_subarg_cmp_f returns non-zero */
  877. if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  878. "null", buf))
  879. debug("bank interleaving disabled.\n");
  880. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  881. "cs0_cs1", buf))
  882. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
  883. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  884. "cs2_cs3", buf))
  885. popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
  886. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  887. "cs0_cs1_and_cs2_cs3", buf))
  888. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
  889. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  890. "cs0_cs1_cs2_cs3", buf))
  891. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
  892. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  893. "auto", buf))
  894. popts->ba_intlv_ctl = auto_bank_intlv(pdimm);
  895. else
  896. printf("hwconfig has unrecognized parameter for bank_intlv.\n");
  897. switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
  898. case FSL_DDR_CS0_CS1_CS2_CS3:
  899. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  900. if (pdimm[0].n_ranks < 4) {
  901. popts->ba_intlv_ctl = 0;
  902. printf("Not enough bank(chip-select) for "
  903. "CS0+CS1+CS2+CS3 on controller %d, "
  904. "interleaving disabled!\n", ctrl_num);
  905. }
  906. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  907. #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
  908. if (pdimm[0].n_ranks == 4)
  909. break;
  910. #endif
  911. if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) {
  912. popts->ba_intlv_ctl = 0;
  913. printf("Not enough bank(chip-select) for "
  914. "CS0+CS1+CS2+CS3 on controller %d, "
  915. "interleaving disabled!\n", ctrl_num);
  916. }
  917. if (pdimm[0].capacity != pdimm[1].capacity) {
  918. popts->ba_intlv_ctl = 0;
  919. printf("Not identical DIMM size for "
  920. "CS0+CS1+CS2+CS3 on controller %d, "
  921. "interleaving disabled!\n", ctrl_num);
  922. }
  923. #endif
  924. break;
  925. case FSL_DDR_CS0_CS1:
  926. if (pdimm[0].n_ranks < 2) {
  927. popts->ba_intlv_ctl = 0;
  928. printf("Not enough bank(chip-select) for "
  929. "CS0+CS1 on controller %d, "
  930. "interleaving disabled!\n", ctrl_num);
  931. }
  932. break;
  933. case FSL_DDR_CS2_CS3:
  934. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  935. if (pdimm[0].n_ranks < 4) {
  936. popts->ba_intlv_ctl = 0;
  937. printf("Not enough bank(chip-select) for CS2+CS3 "
  938. "on controller %d, interleaving disabled!\n", ctrl_num);
  939. }
  940. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  941. if (pdimm[1].n_ranks < 2) {
  942. popts->ba_intlv_ctl = 0;
  943. printf("Not enough bank(chip-select) for CS2+CS3 "
  944. "on controller %d, interleaving disabled!\n", ctrl_num);
  945. }
  946. #endif
  947. break;
  948. case FSL_DDR_CS0_CS1_AND_CS2_CS3:
  949. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  950. if (pdimm[0].n_ranks < 4) {
  951. popts->ba_intlv_ctl = 0;
  952. printf("Not enough bank(CS) for CS0+CS1 and "
  953. "CS2+CS3 on controller %d, "
  954. "interleaving disabled!\n", ctrl_num);
  955. }
  956. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  957. if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) {
  958. popts->ba_intlv_ctl = 0;
  959. printf("Not enough bank(CS) for CS0+CS1 and "
  960. "CS2+CS3 on controller %d, "
  961. "interleaving disabled!\n", ctrl_num);
  962. }
  963. #endif
  964. break;
  965. default:
  966. popts->ba_intlv_ctl = 0;
  967. break;
  968. }
  969. }
  970. if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf)) {
  971. if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf))
  972. popts->addr_hash = 0;
  973. else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash",
  974. "true", buf))
  975. popts->addr_hash = 1;
  976. }
  977. if (pdimm[0].n_ranks == 4)
  978. popts->quad_rank_present = 1;
  979. ddr_freq = get_ddr_freq(ctrl_num) / 1000000;
  980. if (popts->registered_dimm_en) {
  981. popts->rcw_override = 1;
  982. popts->rcw_1 = 0x000a5a00;
  983. if (ddr_freq <= 800)
  984. popts->rcw_2 = 0x00000000;
  985. else if (ddr_freq <= 1066)
  986. popts->rcw_2 = 0x00100000;
  987. else if (ddr_freq <= 1333)
  988. popts->rcw_2 = 0x00200000;
  989. else
  990. popts->rcw_2 = 0x00300000;
  991. }
  992. fsl_ddr_board_options(popts, pdimm, ctrl_num);
  993. return 0;
  994. }
  995. void check_interleaving_options(fsl_ddr_info_t *pinfo)
  996. {
  997. int i, j, k, check_n_ranks, intlv_invalid = 0;
  998. unsigned int check_intlv, check_n_row_addr, check_n_col_addr;
  999. unsigned long long check_rank_density;
  1000. struct dimm_params_s *dimm;
  1001. int first_ctrl = pinfo->first_ctrl;
  1002. int last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
  1003. /*
  1004. * Check if all controllers are configured for memory
  1005. * controller interleaving. Identical dimms are recommended. At least
  1006. * the size, row and col address should be checked.
  1007. */
  1008. j = 0;
  1009. check_n_ranks = pinfo->dimm_params[first_ctrl][0].n_ranks;
  1010. check_rank_density = pinfo->dimm_params[first_ctrl][0].rank_density;
  1011. check_n_row_addr = pinfo->dimm_params[first_ctrl][0].n_row_addr;
  1012. check_n_col_addr = pinfo->dimm_params[first_ctrl][0].n_col_addr;
  1013. check_intlv = pinfo->memctl_opts[first_ctrl].memctl_interleaving_mode;
  1014. for (i = first_ctrl; i <= last_ctrl; i++) {
  1015. dimm = &pinfo->dimm_params[i][0];
  1016. if (!pinfo->memctl_opts[i].memctl_interleaving) {
  1017. continue;
  1018. } else if (((check_rank_density != dimm->rank_density) ||
  1019. (check_n_ranks != dimm->n_ranks) ||
  1020. (check_n_row_addr != dimm->n_row_addr) ||
  1021. (check_n_col_addr != dimm->n_col_addr) ||
  1022. (check_intlv !=
  1023. pinfo->memctl_opts[i].memctl_interleaving_mode))){
  1024. intlv_invalid = 1;
  1025. break;
  1026. } else {
  1027. j++;
  1028. }
  1029. }
  1030. if (intlv_invalid) {
  1031. for (i = first_ctrl; i <= last_ctrl; i++)
  1032. pinfo->memctl_opts[i].memctl_interleaving = 0;
  1033. printf("Not all DIMMs are identical. "
  1034. "Memory controller interleaving disabled.\n");
  1035. } else {
  1036. switch (check_intlv) {
  1037. case FSL_DDR_256B_INTERLEAVING:
  1038. case FSL_DDR_CACHE_LINE_INTERLEAVING:
  1039. case FSL_DDR_PAGE_INTERLEAVING:
  1040. case FSL_DDR_BANK_INTERLEAVING:
  1041. case FSL_DDR_SUPERBANK_INTERLEAVING:
  1042. #if (3 == CONFIG_NUM_DDR_CONTROLLERS)
  1043. k = 2;
  1044. #else
  1045. k = CONFIG_NUM_DDR_CONTROLLERS;
  1046. #endif
  1047. break;
  1048. case FSL_DDR_3WAY_1KB_INTERLEAVING:
  1049. case FSL_DDR_3WAY_4KB_INTERLEAVING:
  1050. case FSL_DDR_3WAY_8KB_INTERLEAVING:
  1051. case FSL_DDR_4WAY_1KB_INTERLEAVING:
  1052. case FSL_DDR_4WAY_4KB_INTERLEAVING:
  1053. case FSL_DDR_4WAY_8KB_INTERLEAVING:
  1054. default:
  1055. k = CONFIG_NUM_DDR_CONTROLLERS;
  1056. break;
  1057. }
  1058. debug("%d of %d controllers are interleaving.\n", j, k);
  1059. if (j && (j != k)) {
  1060. for (i = first_ctrl; i <= last_ctrl; i++)
  1061. pinfo->memctl_opts[i].memctl_interleaving = 0;
  1062. if ((last_ctrl - first_ctrl) > 1)
  1063. puts("Not all controllers have compatible interleaving mode. All disabled.\n");
  1064. }
  1065. }
  1066. debug("Checking interleaving options completed\n");
  1067. }
  1068. int fsl_use_spd(void)
  1069. {
  1070. int use_spd = 0;
  1071. #ifdef CONFIG_DDR_SPD
  1072. char buffer[HWCONFIG_BUFFER_SIZE];
  1073. char *buf = NULL;
  1074. /*
  1075. * Extract hwconfig from environment since we have not properly setup
  1076. * the environment but need it for ddr config params
  1077. */
  1078. if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0)
  1079. buf = buffer;
  1080. /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
  1081. if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) {
  1082. if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf))
  1083. use_spd = 1;
  1084. else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram",
  1085. "fixed", buf))
  1086. use_spd = 0;
  1087. else
  1088. use_spd = 1;
  1089. } else
  1090. use_spd = 1;
  1091. #endif
  1092. return use_spd;
  1093. }