options.c 32 KB

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