options.c 27 KB

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