options.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  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. popts->mirrored_dimm = pdimm[0].mirrored_dimm;
  681. #endif
  682. /* Global Timing Parameters. */
  683. debug("mclk_ps = %u ps\n", get_memory_clk_period_ps());
  684. /* Pick a caslat override. */
  685. popts->cas_latency_override = 0;
  686. popts->cas_latency_override_value = 3;
  687. if (popts->cas_latency_override) {
  688. debug("using caslat override value = %u\n",
  689. popts->cas_latency_override_value);
  690. }
  691. /* Decide whether to use the computed derated latency */
  692. popts->use_derated_caslat = 0;
  693. /* Choose an additive latency. */
  694. popts->additive_latency_override = 0;
  695. popts->additive_latency_override_value = 3;
  696. if (popts->additive_latency_override) {
  697. debug("using additive latency override value = %u\n",
  698. popts->additive_latency_override_value);
  699. }
  700. /*
  701. * 2T_EN setting
  702. *
  703. * Factors to consider for 2T_EN:
  704. * - number of DIMMs installed
  705. * - number of components, number of active ranks
  706. * - how much time you want to spend playing around
  707. */
  708. popts->twot_en = 0;
  709. popts->threet_en = 0;
  710. /* for RDIMM, address parity enable */
  711. popts->ap_en = 1;
  712. /*
  713. * BSTTOPRE precharge interval
  714. *
  715. * Set this to 0 for global auto precharge
  716. * The value of 0x100 has been used for DDR1, DDR2, DDR3.
  717. * It is not wrong. Any value should be OK. The performance depends on
  718. * applications. There is no one good value for all.
  719. */
  720. popts->bstopre = 0x100;
  721. /* Minimum CKE pulse width -- tCKE(MIN) */
  722. popts->tcke_clock_pulse_width_ps
  723. = mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR);
  724. /*
  725. * Window for four activates -- tFAW
  726. *
  727. * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
  728. * FIXME: varies depending upon number of column addresses or data
  729. * FIXME: width, was considering looking at pdimm->primary_sdram_width
  730. */
  731. #if defined(CONFIG_SYS_FSL_DDR1)
  732. popts->tfaw_window_four_activates_ps = mclk_to_picos(1);
  733. #elif defined(CONFIG_SYS_FSL_DDR2)
  734. /*
  735. * x4/x8; some datasheets have 35000
  736. * x16 wide columns only? Use 50000?
  737. */
  738. popts->tfaw_window_four_activates_ps = 37500;
  739. #else
  740. popts->tfaw_window_four_activates_ps = pdimm[0].tfaw_ps;
  741. #endif
  742. popts->zq_en = 0;
  743. popts->wrlvl_en = 0;
  744. #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
  745. /*
  746. * due to ddr3 dimm is fly-by topology
  747. * we suggest to enable write leveling to
  748. * meet the tQDSS under different loading.
  749. */
  750. popts->wrlvl_en = 1;
  751. popts->zq_en = 1;
  752. popts->wrlvl_override = 0;
  753. #endif
  754. /*
  755. * Check interleaving configuration from environment.
  756. * Please refer to doc/README.fsl-ddr for the detail.
  757. *
  758. * If memory controller interleaving is enabled, then the data
  759. * bus widths must be programmed identically for all memory controllers.
  760. *
  761. * Attempt to set all controllers to the same chip select
  762. * interleaving mode. It will do a best effort to get the
  763. * requested ranks interleaved together such that the result
  764. * should be a subset of the requested configuration.
  765. *
  766. * if CONFIG_SYS_FSL_DDR_INTLV_256B is defined, mandatory interleaving
  767. * with 256 Byte is enabled.
  768. */
  769. #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
  770. if (!hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf))
  771. #ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
  772. ;
  773. #else
  774. goto done;
  775. #endif
  776. if (pdimm[0].n_ranks == 0) {
  777. printf("There is no rank on CS0 for controller %d.\n", ctrl_num);
  778. popts->memctl_interleaving = 0;
  779. goto done;
  780. }
  781. popts->memctl_interleaving = 1;
  782. #ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
  783. popts->memctl_interleaving_mode = FSL_DDR_256B_INTERLEAVING;
  784. popts->memctl_interleaving = 1;
  785. debug("256 Byte interleaving\n");
  786. #else
  787. /*
  788. * test null first. if CONFIG_HWCONFIG is not defined
  789. * hwconfig_arg_cmp returns non-zero
  790. */
  791. if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  792. "null", buf)) {
  793. popts->memctl_interleaving = 0;
  794. debug("memory controller interleaving disabled.\n");
  795. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  796. "ctlr_intlv",
  797. "cacheline", buf)) {
  798. popts->memctl_interleaving_mode =
  799. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  800. 0 : FSL_DDR_CACHE_LINE_INTERLEAVING;
  801. popts->memctl_interleaving =
  802. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  803. 0 : 1;
  804. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  805. "ctlr_intlv",
  806. "page", buf)) {
  807. popts->memctl_interleaving_mode =
  808. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  809. 0 : FSL_DDR_PAGE_INTERLEAVING;
  810. popts->memctl_interleaving =
  811. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  812. 0 : 1;
  813. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  814. "ctlr_intlv",
  815. "bank", buf)) {
  816. popts->memctl_interleaving_mode =
  817. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  818. 0 : FSL_DDR_BANK_INTERLEAVING;
  819. popts->memctl_interleaving =
  820. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  821. 0 : 1;
  822. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  823. "ctlr_intlv",
  824. "superbank", buf)) {
  825. popts->memctl_interleaving_mode =
  826. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  827. 0 : FSL_DDR_SUPERBANK_INTERLEAVING;
  828. popts->memctl_interleaving =
  829. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  830. 0 : 1;
  831. #if (CONFIG_NUM_DDR_CONTROLLERS == 3)
  832. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  833. "ctlr_intlv",
  834. "3way_1KB", buf)) {
  835. popts->memctl_interleaving_mode =
  836. FSL_DDR_3WAY_1KB_INTERLEAVING;
  837. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  838. "ctlr_intlv",
  839. "3way_4KB", buf)) {
  840. popts->memctl_interleaving_mode =
  841. FSL_DDR_3WAY_4KB_INTERLEAVING;
  842. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  843. "ctlr_intlv",
  844. "3way_8KB", buf)) {
  845. popts->memctl_interleaving_mode =
  846. FSL_DDR_3WAY_8KB_INTERLEAVING;
  847. #elif (CONFIG_NUM_DDR_CONTROLLERS == 4)
  848. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  849. "ctlr_intlv",
  850. "4way_1KB", buf)) {
  851. popts->memctl_interleaving_mode =
  852. FSL_DDR_4WAY_1KB_INTERLEAVING;
  853. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  854. "ctlr_intlv",
  855. "4way_4KB", buf)) {
  856. popts->memctl_interleaving_mode =
  857. FSL_DDR_4WAY_4KB_INTERLEAVING;
  858. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  859. "ctlr_intlv",
  860. "4way_8KB", buf)) {
  861. popts->memctl_interleaving_mode =
  862. FSL_DDR_4WAY_8KB_INTERLEAVING;
  863. #endif
  864. } else {
  865. popts->memctl_interleaving = 0;
  866. printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
  867. }
  868. #endif /* CONFIG_SYS_FSL_DDR_INTLV_256B */
  869. done:
  870. #endif /* CONFIG_NUM_DDR_CONTROLLERS > 1 */
  871. if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) &&
  872. (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) {
  873. /* test null first. if CONFIG_HWCONFIG is not defined,
  874. * hwconfig_subarg_cmp_f returns non-zero */
  875. if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  876. "null", buf))
  877. debug("bank interleaving disabled.\n");
  878. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  879. "cs0_cs1", buf))
  880. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
  881. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  882. "cs2_cs3", buf))
  883. popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
  884. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  885. "cs0_cs1_and_cs2_cs3", buf))
  886. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
  887. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  888. "cs0_cs1_cs2_cs3", buf))
  889. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
  890. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  891. "auto", buf))
  892. popts->ba_intlv_ctl = auto_bank_intlv(pdimm);
  893. else
  894. printf("hwconfig has unrecognized parameter for bank_intlv.\n");
  895. switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
  896. case FSL_DDR_CS0_CS1_CS2_CS3:
  897. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  898. if (pdimm[0].n_ranks < 4) {
  899. popts->ba_intlv_ctl = 0;
  900. printf("Not enough bank(chip-select) for "
  901. "CS0+CS1+CS2+CS3 on controller %d, "
  902. "interleaving disabled!\n", ctrl_num);
  903. }
  904. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  905. #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
  906. if (pdimm[0].n_ranks == 4)
  907. break;
  908. #endif
  909. if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) {
  910. popts->ba_intlv_ctl = 0;
  911. printf("Not enough bank(chip-select) for "
  912. "CS0+CS1+CS2+CS3 on controller %d, "
  913. "interleaving disabled!\n", ctrl_num);
  914. }
  915. if (pdimm[0].capacity != pdimm[1].capacity) {
  916. popts->ba_intlv_ctl = 0;
  917. printf("Not identical DIMM size for "
  918. "CS0+CS1+CS2+CS3 on controller %d, "
  919. "interleaving disabled!\n", ctrl_num);
  920. }
  921. #endif
  922. break;
  923. case FSL_DDR_CS0_CS1:
  924. if (pdimm[0].n_ranks < 2) {
  925. popts->ba_intlv_ctl = 0;
  926. printf("Not enough bank(chip-select) for "
  927. "CS0+CS1 on controller %d, "
  928. "interleaving disabled!\n", ctrl_num);
  929. }
  930. break;
  931. case FSL_DDR_CS2_CS3:
  932. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  933. if (pdimm[0].n_ranks < 4) {
  934. popts->ba_intlv_ctl = 0;
  935. printf("Not enough bank(chip-select) for CS2+CS3 "
  936. "on controller %d, interleaving disabled!\n", ctrl_num);
  937. }
  938. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  939. if (pdimm[1].n_ranks < 2) {
  940. popts->ba_intlv_ctl = 0;
  941. printf("Not enough bank(chip-select) for CS2+CS3 "
  942. "on controller %d, interleaving disabled!\n", ctrl_num);
  943. }
  944. #endif
  945. break;
  946. case FSL_DDR_CS0_CS1_AND_CS2_CS3:
  947. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  948. if (pdimm[0].n_ranks < 4) {
  949. popts->ba_intlv_ctl = 0;
  950. printf("Not enough bank(CS) for CS0+CS1 and "
  951. "CS2+CS3 on controller %d, "
  952. "interleaving disabled!\n", ctrl_num);
  953. }
  954. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  955. if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) {
  956. popts->ba_intlv_ctl = 0;
  957. printf("Not enough bank(CS) for CS0+CS1 and "
  958. "CS2+CS3 on controller %d, "
  959. "interleaving disabled!\n", ctrl_num);
  960. }
  961. #endif
  962. break;
  963. default:
  964. popts->ba_intlv_ctl = 0;
  965. break;
  966. }
  967. }
  968. if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf)) {
  969. if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf))
  970. popts->addr_hash = 0;
  971. else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash",
  972. "true", buf))
  973. popts->addr_hash = 1;
  974. }
  975. if (pdimm[0].n_ranks == 4)
  976. popts->quad_rank_present = 1;
  977. ddr_freq = get_ddr_freq(0) / 1000000;
  978. if (popts->registered_dimm_en) {
  979. popts->rcw_override = 1;
  980. popts->rcw_1 = 0x000a5a00;
  981. if (ddr_freq <= 800)
  982. popts->rcw_2 = 0x00000000;
  983. else if (ddr_freq <= 1066)
  984. popts->rcw_2 = 0x00100000;
  985. else if (ddr_freq <= 1333)
  986. popts->rcw_2 = 0x00200000;
  987. else
  988. popts->rcw_2 = 0x00300000;
  989. }
  990. fsl_ddr_board_options(popts, pdimm, ctrl_num);
  991. return 0;
  992. }
  993. void check_interleaving_options(fsl_ddr_info_t *pinfo)
  994. {
  995. int i, j, k, check_n_ranks, intlv_invalid = 0;
  996. unsigned int check_intlv, check_n_row_addr, check_n_col_addr;
  997. unsigned long long check_rank_density;
  998. struct dimm_params_s *dimm;
  999. int first_ctrl = pinfo->first_ctrl;
  1000. int last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
  1001. /*
  1002. * Check if all controllers are configured for memory
  1003. * controller interleaving. Identical dimms are recommended. At least
  1004. * the size, row and col address should be checked.
  1005. */
  1006. j = 0;
  1007. check_n_ranks = pinfo->dimm_params[first_ctrl][0].n_ranks;
  1008. check_rank_density = pinfo->dimm_params[first_ctrl][0].rank_density;
  1009. check_n_row_addr = pinfo->dimm_params[first_ctrl][0].n_row_addr;
  1010. check_n_col_addr = pinfo->dimm_params[first_ctrl][0].n_col_addr;
  1011. check_intlv = pinfo->memctl_opts[first_ctrl].memctl_interleaving_mode;
  1012. for (i = first_ctrl; i <= last_ctrl; i++) {
  1013. dimm = &pinfo->dimm_params[i][0];
  1014. if (!pinfo->memctl_opts[i].memctl_interleaving) {
  1015. continue;
  1016. } else if (((check_rank_density != dimm->rank_density) ||
  1017. (check_n_ranks != dimm->n_ranks) ||
  1018. (check_n_row_addr != dimm->n_row_addr) ||
  1019. (check_n_col_addr != dimm->n_col_addr) ||
  1020. (check_intlv !=
  1021. pinfo->memctl_opts[i].memctl_interleaving_mode))){
  1022. intlv_invalid = 1;
  1023. break;
  1024. } else {
  1025. j++;
  1026. }
  1027. }
  1028. if (intlv_invalid) {
  1029. for (i = first_ctrl; i <= last_ctrl; i++)
  1030. pinfo->memctl_opts[i].memctl_interleaving = 0;
  1031. printf("Not all DIMMs are identical. "
  1032. "Memory controller interleaving disabled.\n");
  1033. } else {
  1034. switch (check_intlv) {
  1035. case FSL_DDR_256B_INTERLEAVING:
  1036. case FSL_DDR_CACHE_LINE_INTERLEAVING:
  1037. case FSL_DDR_PAGE_INTERLEAVING:
  1038. case FSL_DDR_BANK_INTERLEAVING:
  1039. case FSL_DDR_SUPERBANK_INTERLEAVING:
  1040. #if (3 == CONFIG_NUM_DDR_CONTROLLERS)
  1041. k = 2;
  1042. #else
  1043. k = CONFIG_NUM_DDR_CONTROLLERS;
  1044. #endif
  1045. break;
  1046. case FSL_DDR_3WAY_1KB_INTERLEAVING:
  1047. case FSL_DDR_3WAY_4KB_INTERLEAVING:
  1048. case FSL_DDR_3WAY_8KB_INTERLEAVING:
  1049. case FSL_DDR_4WAY_1KB_INTERLEAVING:
  1050. case FSL_DDR_4WAY_4KB_INTERLEAVING:
  1051. case FSL_DDR_4WAY_8KB_INTERLEAVING:
  1052. default:
  1053. k = CONFIG_NUM_DDR_CONTROLLERS;
  1054. break;
  1055. }
  1056. debug("%d of %d controllers are interleaving.\n", j, k);
  1057. if (j && (j != k)) {
  1058. for (i = first_ctrl; i <= last_ctrl; i++)
  1059. pinfo->memctl_opts[i].memctl_interleaving = 0;
  1060. if ((last_ctrl - first_ctrl) > 1)
  1061. puts("Not all controllers have compatible interleaving mode. All disabled.\n");
  1062. }
  1063. }
  1064. debug("Checking interleaving options completed\n");
  1065. }
  1066. int fsl_use_spd(void)
  1067. {
  1068. int use_spd = 0;
  1069. #ifdef CONFIG_DDR_SPD
  1070. char buffer[HWCONFIG_BUFFER_SIZE];
  1071. char *buf = NULL;
  1072. /*
  1073. * Extract hwconfig from environment since we have not properly setup
  1074. * the environment but need it for ddr config params
  1075. */
  1076. if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0)
  1077. buf = buffer;
  1078. /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
  1079. if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) {
  1080. if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf))
  1081. use_spd = 1;
  1082. else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram",
  1083. "fixed", buf))
  1084. use_spd = 0;
  1085. else
  1086. use_spd = 1;
  1087. } else
  1088. use_spd = 1;
  1089. #endif
  1090. return use_spd;
  1091. }