options.c 32 KB

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