options.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  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. } else if (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 "
  512. "cannot be used together\n");
  513. break;
  514. #endif
  515. case 2:
  516. switch (pdimm[1].n_ranks) {
  517. case 2:
  518. pdodt = dual_DD;
  519. break;
  520. case 1:
  521. pdodt = dual_DS;
  522. break;
  523. case 0:
  524. pdodt = dual_D0;
  525. break;
  526. }
  527. break;
  528. case 1:
  529. switch (pdimm[1].n_ranks) {
  530. case 2:
  531. pdodt = dual_SD;
  532. break;
  533. case 1:
  534. pdodt = dual_SS;
  535. break;
  536. case 0:
  537. pdodt = dual_S0;
  538. break;
  539. }
  540. break;
  541. case 0:
  542. switch (pdimm[1].n_ranks) {
  543. case 2:
  544. pdodt = dual_0D;
  545. break;
  546. case 1:
  547. pdodt = dual_0S;
  548. break;
  549. }
  550. break;
  551. }
  552. }
  553. #endif
  554. /* Pick chip-select local options. */
  555. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  556. #if defined(CONFIG_SYS_FSL_DDR3) || \
  557. defined(CONFIG_SYS_FSL_DDR2) || \
  558. defined(CONFIG_SYS_FSL_DDR4)
  559. popts->cs_local_opts[i].odt_rd_cfg = pdodt[i].odt_rd_cfg;
  560. popts->cs_local_opts[i].odt_wr_cfg = pdodt[i].odt_wr_cfg;
  561. popts->cs_local_opts[i].odt_rtt_norm = pdodt[i].odt_rtt_norm;
  562. popts->cs_local_opts[i].odt_rtt_wr = pdodt[i].odt_rtt_wr;
  563. #else
  564. popts->cs_local_opts[i].odt_rd_cfg = FSL_DDR_ODT_NEVER;
  565. popts->cs_local_opts[i].odt_wr_cfg = FSL_DDR_ODT_CS;
  566. #endif
  567. popts->cs_local_opts[i].auto_precharge = 0;
  568. }
  569. /* Pick interleaving mode. */
  570. /*
  571. * 0 = no interleaving
  572. * 1 = interleaving between 2 controllers
  573. */
  574. popts->memctl_interleaving = 0;
  575. /*
  576. * 0 = cacheline
  577. * 1 = page
  578. * 2 = (logical) bank
  579. * 3 = superbank (only if CS interleaving is enabled)
  580. */
  581. popts->memctl_interleaving_mode = 0;
  582. /*
  583. * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
  584. * 1: page: bit to the left of the column bits selects the memctl
  585. * 2: bank: bit to the left of the bank bits selects the memctl
  586. * 3: superbank: bit to the left of the chip select selects the memctl
  587. *
  588. * NOTE: ba_intlv (rank interleaving) is independent of memory
  589. * controller interleaving; it is only within a memory controller.
  590. * Must use superbank interleaving if rank interleaving is used and
  591. * memory controller interleaving is enabled.
  592. */
  593. /*
  594. * 0 = no
  595. * 0x40 = CS0,CS1
  596. * 0x20 = CS2,CS3
  597. * 0x60 = CS0,CS1 + CS2,CS3
  598. * 0x04 = CS0,CS1,CS2,CS3
  599. */
  600. popts->ba_intlv_ctl = 0;
  601. /* Memory Organization Parameters */
  602. popts->registered_dimm_en = all_dimms_registered;
  603. /* Operational Mode Paramters */
  604. /* Pick ECC modes */
  605. popts->ecc_mode = 0; /* 0 = disabled, 1 = enabled */
  606. #ifdef CONFIG_DDR_ECC
  607. if (hwconfig_sub_f("fsl_ddr", "ecc", buf)) {
  608. if (hwconfig_subarg_cmp_f("fsl_ddr", "ecc", "on", buf))
  609. popts->ecc_mode = 1;
  610. } else
  611. popts->ecc_mode = 1;
  612. #endif
  613. popts->ecc_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */
  614. /*
  615. * Choose DQS config
  616. * 0 for DDR1
  617. * 1 for DDR2
  618. */
  619. #if defined(CONFIG_SYS_FSL_DDR1)
  620. popts->dqs_config = 0;
  621. #elif defined(CONFIG_SYS_FSL_DDR2) || defined(CONFIG_SYS_FSL_DDR3)
  622. popts->dqs_config = 1;
  623. #endif
  624. /* Choose self-refresh during sleep. */
  625. popts->self_refresh_in_sleep = 1;
  626. /* Choose dynamic power management mode. */
  627. popts->dynamic_power = 0;
  628. /*
  629. * check first dimm for primary sdram width
  630. * presuming all dimms are similar
  631. * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit
  632. */
  633. #if defined(CONFIG_SYS_FSL_DDR1) || defined(CONFIG_SYS_FSL_DDR2)
  634. if (pdimm[0].n_ranks != 0) {
  635. if ((pdimm[0].data_width >= 64) && \
  636. (pdimm[0].data_width <= 72))
  637. popts->data_bus_width = 0;
  638. else if ((pdimm[0].data_width >= 32) || \
  639. (pdimm[0].data_width <= 40))
  640. popts->data_bus_width = 1;
  641. else {
  642. panic("Error: data width %u is invalid!\n",
  643. pdimm[0].data_width);
  644. }
  645. }
  646. #else
  647. if (pdimm[0].n_ranks != 0) {
  648. if (pdimm[0].primary_sdram_width == 64)
  649. popts->data_bus_width = 0;
  650. else if (pdimm[0].primary_sdram_width == 32)
  651. popts->data_bus_width = 1;
  652. else if (pdimm[0].primary_sdram_width == 16)
  653. popts->data_bus_width = 2;
  654. else {
  655. panic("Error: primary sdram width %u is invalid!\n",
  656. pdimm[0].primary_sdram_width);
  657. }
  658. }
  659. #endif
  660. popts->x4_en = (pdimm[0].device_width == 4) ? 1 : 0;
  661. /* Choose burst length. */
  662. #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
  663. #if defined(CONFIG_E500MC)
  664. popts->otf_burst_chop_en = 0; /* on-the-fly burst chop disable */
  665. popts->burst_length = DDR_BL8; /* Fixed 8-beat burst len */
  666. #else
  667. if ((popts->data_bus_width == 1) || (popts->data_bus_width == 2)) {
  668. /* 32-bit or 16-bit bus */
  669. popts->otf_burst_chop_en = 0;
  670. popts->burst_length = DDR_BL8;
  671. } else {
  672. popts->otf_burst_chop_en = 1; /* on-the-fly burst chop */
  673. popts->burst_length = DDR_OTF; /* on-the-fly BC4 and BL8 */
  674. }
  675. #endif
  676. #else
  677. popts->burst_length = DDR_BL4; /* has to be 4 for DDR2 */
  678. #endif
  679. /* Choose ddr controller address mirror mode */
  680. #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
  681. popts->mirrored_dimm = pdimm[0].mirrored_dimm;
  682. #endif
  683. /* Global Timing Parameters. */
  684. debug("mclk_ps = %u ps\n", get_memory_clk_period_ps());
  685. /* Pick a caslat override. */
  686. popts->cas_latency_override = 0;
  687. popts->cas_latency_override_value = 3;
  688. if (popts->cas_latency_override) {
  689. debug("using caslat override value = %u\n",
  690. popts->cas_latency_override_value);
  691. }
  692. /* Decide whether to use the computed derated latency */
  693. popts->use_derated_caslat = 0;
  694. /* Choose an additive latency. */
  695. popts->additive_latency_override = 0;
  696. popts->additive_latency_override_value = 3;
  697. if (popts->additive_latency_override) {
  698. debug("using additive latency override value = %u\n",
  699. popts->additive_latency_override_value);
  700. }
  701. /*
  702. * 2T_EN setting
  703. *
  704. * Factors to consider for 2T_EN:
  705. * - number of DIMMs installed
  706. * - number of components, number of active ranks
  707. * - how much time you want to spend playing around
  708. */
  709. popts->twot_en = 0;
  710. popts->threet_en = 0;
  711. /* for RDIMM, address parity enable */
  712. popts->ap_en = 1;
  713. /*
  714. * BSTTOPRE precharge interval
  715. *
  716. * Set this to 0 for global auto precharge
  717. * The value of 0x100 has been used for DDR1, DDR2, DDR3.
  718. * It is not wrong. Any value should be OK. The performance depends on
  719. * applications. There is no one good value for all.
  720. */
  721. popts->bstopre = 0x100;
  722. /* Minimum CKE pulse width -- tCKE(MIN) */
  723. popts->tcke_clock_pulse_width_ps
  724. = mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR);
  725. /*
  726. * Window for four activates -- tFAW
  727. *
  728. * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
  729. * FIXME: varies depending upon number of column addresses or data
  730. * FIXME: width, was considering looking at pdimm->primary_sdram_width
  731. */
  732. #if defined(CONFIG_SYS_FSL_DDR1)
  733. popts->tfaw_window_four_activates_ps = mclk_to_picos(1);
  734. #elif defined(CONFIG_SYS_FSL_DDR2)
  735. /*
  736. * x4/x8; some datasheets have 35000
  737. * x16 wide columns only? Use 50000?
  738. */
  739. popts->tfaw_window_four_activates_ps = 37500;
  740. #else
  741. popts->tfaw_window_four_activates_ps = pdimm[0].tfaw_ps;
  742. #endif
  743. popts->zq_en = 0;
  744. popts->wrlvl_en = 0;
  745. #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
  746. /*
  747. * due to ddr3 dimm is fly-by topology
  748. * we suggest to enable write leveling to
  749. * meet the tQDSS under different loading.
  750. */
  751. popts->wrlvl_en = 1;
  752. popts->zq_en = 1;
  753. popts->wrlvl_override = 0;
  754. #endif
  755. /*
  756. * Check interleaving configuration from environment.
  757. * Please refer to doc/README.fsl-ddr for the detail.
  758. *
  759. * If memory controller interleaving is enabled, then the data
  760. * bus widths must be programmed identically for all memory controllers.
  761. *
  762. * Attempt to set all controllers to the same chip select
  763. * interleaving mode. It will do a best effort to get the
  764. * requested ranks interleaved together such that the result
  765. * should be a subset of the requested configuration.
  766. *
  767. * if CONFIG_SYS_FSL_DDR_INTLV_256B is defined, mandatory interleaving
  768. * with 256 Byte is enabled.
  769. */
  770. #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
  771. if (!hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf))
  772. #ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
  773. ;
  774. #else
  775. goto done;
  776. #endif
  777. if (pdimm[0].n_ranks == 0) {
  778. printf("There is no rank on CS0 for controller %d.\n", ctrl_num);
  779. popts->memctl_interleaving = 0;
  780. goto done;
  781. }
  782. popts->memctl_interleaving = 1;
  783. #ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
  784. popts->memctl_interleaving_mode = FSL_DDR_256B_INTERLEAVING;
  785. popts->memctl_interleaving = 1;
  786. debug("256 Byte interleaving\n");
  787. goto done;
  788. #endif
  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. done:
  871. #endif
  872. if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) &&
  873. (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) {
  874. /* test null first. if CONFIG_HWCONFIG is not defined,
  875. * hwconfig_subarg_cmp_f returns non-zero */
  876. if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  877. "null", buf))
  878. debug("bank interleaving disabled.\n");
  879. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  880. "cs0_cs1", buf))
  881. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
  882. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  883. "cs2_cs3", buf))
  884. popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
  885. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  886. "cs0_cs1_and_cs2_cs3", buf))
  887. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
  888. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  889. "cs0_cs1_cs2_cs3", buf))
  890. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
  891. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  892. "auto", buf))
  893. popts->ba_intlv_ctl = auto_bank_intlv(pdimm);
  894. else
  895. printf("hwconfig has unrecognized parameter for bank_intlv.\n");
  896. switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
  897. case FSL_DDR_CS0_CS1_CS2_CS3:
  898. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  899. if (pdimm[0].n_ranks < 4) {
  900. popts->ba_intlv_ctl = 0;
  901. printf("Not enough bank(chip-select) for "
  902. "CS0+CS1+CS2+CS3 on controller %d, "
  903. "interleaving disabled!\n", ctrl_num);
  904. }
  905. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  906. #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
  907. if (pdimm[0].n_ranks == 4)
  908. break;
  909. #endif
  910. if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) {
  911. popts->ba_intlv_ctl = 0;
  912. printf("Not enough bank(chip-select) for "
  913. "CS0+CS1+CS2+CS3 on controller %d, "
  914. "interleaving disabled!\n", ctrl_num);
  915. }
  916. if (pdimm[0].capacity != pdimm[1].capacity) {
  917. popts->ba_intlv_ctl = 0;
  918. printf("Not identical DIMM size for "
  919. "CS0+CS1+CS2+CS3 on controller %d, "
  920. "interleaving disabled!\n", ctrl_num);
  921. }
  922. #endif
  923. break;
  924. case FSL_DDR_CS0_CS1:
  925. if (pdimm[0].n_ranks < 2) {
  926. popts->ba_intlv_ctl = 0;
  927. printf("Not enough bank(chip-select) for "
  928. "CS0+CS1 on controller %d, "
  929. "interleaving disabled!\n", ctrl_num);
  930. }
  931. break;
  932. case FSL_DDR_CS2_CS3:
  933. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  934. if (pdimm[0].n_ranks < 4) {
  935. popts->ba_intlv_ctl = 0;
  936. printf("Not enough bank(chip-select) for CS2+CS3 "
  937. "on controller %d, interleaving disabled!\n", ctrl_num);
  938. }
  939. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  940. if (pdimm[1].n_ranks < 2) {
  941. popts->ba_intlv_ctl = 0;
  942. printf("Not enough bank(chip-select) for CS2+CS3 "
  943. "on controller %d, interleaving disabled!\n", ctrl_num);
  944. }
  945. #endif
  946. break;
  947. case FSL_DDR_CS0_CS1_AND_CS2_CS3:
  948. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  949. if (pdimm[0].n_ranks < 4) {
  950. popts->ba_intlv_ctl = 0;
  951. printf("Not enough bank(CS) for CS0+CS1 and "
  952. "CS2+CS3 on controller %d, "
  953. "interleaving disabled!\n", ctrl_num);
  954. }
  955. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  956. if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) {
  957. popts->ba_intlv_ctl = 0;
  958. printf("Not enough bank(CS) for CS0+CS1 and "
  959. "CS2+CS3 on controller %d, "
  960. "interleaving disabled!\n", ctrl_num);
  961. }
  962. #endif
  963. break;
  964. default:
  965. popts->ba_intlv_ctl = 0;
  966. break;
  967. }
  968. }
  969. if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf)) {
  970. if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf))
  971. popts->addr_hash = 0;
  972. else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash",
  973. "true", buf))
  974. popts->addr_hash = 1;
  975. }
  976. if (pdimm[0].n_ranks == 4)
  977. popts->quad_rank_present = 1;
  978. ddr_freq = get_ddr_freq(0) / 1000000;
  979. if (popts->registered_dimm_en) {
  980. popts->rcw_override = 1;
  981. popts->rcw_1 = 0x000a5a00;
  982. if (ddr_freq <= 800)
  983. popts->rcw_2 = 0x00000000;
  984. else if (ddr_freq <= 1066)
  985. popts->rcw_2 = 0x00100000;
  986. else if (ddr_freq <= 1333)
  987. popts->rcw_2 = 0x00200000;
  988. else
  989. popts->rcw_2 = 0x00300000;
  990. }
  991. fsl_ddr_board_options(popts, pdimm, ctrl_num);
  992. return 0;
  993. }
  994. void check_interleaving_options(fsl_ddr_info_t *pinfo)
  995. {
  996. int i, j, k, check_n_ranks, intlv_invalid = 0;
  997. unsigned int check_intlv, check_n_row_addr, check_n_col_addr;
  998. unsigned long long check_rank_density;
  999. struct dimm_params_s *dimm;
  1000. /*
  1001. * Check if all controllers are configured for memory
  1002. * controller interleaving. Identical dimms are recommended. At least
  1003. * the size, row and col address should be checked.
  1004. */
  1005. j = 0;
  1006. check_n_ranks = pinfo->dimm_params[0][0].n_ranks;
  1007. check_rank_density = pinfo->dimm_params[0][0].rank_density;
  1008. check_n_row_addr = pinfo->dimm_params[0][0].n_row_addr;
  1009. check_n_col_addr = pinfo->dimm_params[0][0].n_col_addr;
  1010. check_intlv = pinfo->memctl_opts[0].memctl_interleaving_mode;
  1011. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  1012. dimm = &pinfo->dimm_params[i][0];
  1013. if (!pinfo->memctl_opts[i].memctl_interleaving) {
  1014. continue;
  1015. } else if (((check_rank_density != dimm->rank_density) ||
  1016. (check_n_ranks != dimm->n_ranks) ||
  1017. (check_n_row_addr != dimm->n_row_addr) ||
  1018. (check_n_col_addr != dimm->n_col_addr) ||
  1019. (check_intlv !=
  1020. pinfo->memctl_opts[i].memctl_interleaving_mode))){
  1021. intlv_invalid = 1;
  1022. break;
  1023. } else {
  1024. j++;
  1025. }
  1026. }
  1027. if (intlv_invalid) {
  1028. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
  1029. pinfo->memctl_opts[i].memctl_interleaving = 0;
  1030. printf("Not all DIMMs are identical. "
  1031. "Memory controller interleaving disabled.\n");
  1032. } else {
  1033. switch (check_intlv) {
  1034. case FSL_DDR_256B_INTERLEAVING:
  1035. case FSL_DDR_CACHE_LINE_INTERLEAVING:
  1036. case FSL_DDR_PAGE_INTERLEAVING:
  1037. case FSL_DDR_BANK_INTERLEAVING:
  1038. case FSL_DDR_SUPERBANK_INTERLEAVING:
  1039. if (3 == CONFIG_NUM_DDR_CONTROLLERS)
  1040. k = 2;
  1041. else
  1042. k = CONFIG_NUM_DDR_CONTROLLERS;
  1043. break;
  1044. case FSL_DDR_3WAY_1KB_INTERLEAVING:
  1045. case FSL_DDR_3WAY_4KB_INTERLEAVING:
  1046. case FSL_DDR_3WAY_8KB_INTERLEAVING:
  1047. case FSL_DDR_4WAY_1KB_INTERLEAVING:
  1048. case FSL_DDR_4WAY_4KB_INTERLEAVING:
  1049. case FSL_DDR_4WAY_8KB_INTERLEAVING:
  1050. default:
  1051. k = CONFIG_NUM_DDR_CONTROLLERS;
  1052. break;
  1053. }
  1054. debug("%d of %d controllers are interleaving.\n", j, k);
  1055. if (j && (j != k)) {
  1056. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
  1057. pinfo->memctl_opts[i].memctl_interleaving = 0;
  1058. printf("Not all controllers have compatible "
  1059. "interleaving mode. All disabled.\n");
  1060. }
  1061. }
  1062. debug("Checking interleaving options completed\n");
  1063. }
  1064. int fsl_use_spd(void)
  1065. {
  1066. int use_spd = 0;
  1067. #ifdef CONFIG_DDR_SPD
  1068. char buffer[HWCONFIG_BUFFER_SIZE];
  1069. char *buf = NULL;
  1070. /*
  1071. * Extract hwconfig from environment since we have not properly setup
  1072. * the environment but need it for ddr config params
  1073. */
  1074. if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0)
  1075. buf = buffer;
  1076. /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
  1077. if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) {
  1078. if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf))
  1079. use_spd = 1;
  1080. else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram",
  1081. "fixed", buf))
  1082. use_spd = 0;
  1083. else
  1084. use_spd = 1;
  1085. } else
  1086. use_spd = 1;
  1087. #endif
  1088. return use_spd;
  1089. }