options.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  1. /*
  2. * Copyright 2008, 2010-2012 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 2 of the License, or (at your option)
  7. * any later version.
  8. */
  9. #include <common.h>
  10. #include <hwconfig.h>
  11. #include <asm/fsl_ddr_sdram.h>
  12. #include "ddr.h"
  13. /*
  14. * Use our own stack based buffer before relocation to allow accessing longer
  15. * hwconfig strings that might be in the environment before we've relocated.
  16. * This is pretty fragile on both the use of stack and if the buffer is big
  17. * enough. However we will get a warning from getenv_f for the later.
  18. */
  19. /* Board-specific functions defined in each board's ddr.c */
  20. extern void fsl_ddr_board_options(memctl_options_t *popts,
  21. dimm_params_t *pdimm,
  22. unsigned int ctrl_num);
  23. struct dynamic_odt {
  24. unsigned int odt_rd_cfg;
  25. unsigned int odt_wr_cfg;
  26. unsigned int odt_rtt_norm;
  27. unsigned int odt_rtt_wr;
  28. };
  29. #ifdef CONFIG_FSL_DDR3
  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. DDR3_RTT_20_OHM,
  35. DDR3_RTT_120_OHM
  36. },
  37. { /* cs1 */
  38. FSL_DDR_ODT_NEVER,
  39. FSL_DDR_ODT_NEVER, /* tied high */
  40. DDR3_RTT_OFF,
  41. DDR3_RTT_120_OHM
  42. },
  43. { /* cs2 */
  44. FSL_DDR_ODT_NEVER,
  45. FSL_DDR_ODT_CS_AND_OTHER_DIMM,
  46. DDR3_RTT_20_OHM,
  47. DDR3_RTT_120_OHM
  48. },
  49. { /* cs3 */
  50. FSL_DDR_ODT_NEVER,
  51. FSL_DDR_ODT_NEVER, /* tied high */
  52. DDR3_RTT_OFF,
  53. DDR3_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. DDR3_RTT_40_OHM,
  61. DDR3_RTT_OFF
  62. },
  63. { /* cs1 */
  64. FSL_DDR_ODT_NEVER,
  65. FSL_DDR_ODT_NEVER,
  66. DDR3_RTT_OFF,
  67. DDR3_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. DDR3_RTT_40_OHM,
  77. DDR3_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. DDR3_RTT_120_OHM,
  88. DDR3_RTT_OFF
  89. },
  90. { /* cs1 */
  91. FSL_DDR_ODT_OTHER_DIMM,
  92. FSL_DDR_ODT_OTHER_DIMM,
  93. DDR3_RTT_30_OHM,
  94. DDR3_RTT_OFF
  95. },
  96. { /* cs2 */
  97. FSL_DDR_ODT_NEVER,
  98. FSL_DDR_ODT_SAME_DIMM,
  99. DDR3_RTT_120_OHM,
  100. DDR3_RTT_OFF
  101. },
  102. { /* cs3 */
  103. FSL_DDR_ODT_OTHER_DIMM,
  104. FSL_DDR_ODT_OTHER_DIMM,
  105. DDR3_RTT_30_OHM,
  106. DDR3_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. DDR3_RTT_120_OHM,
  114. DDR3_RTT_OFF
  115. },
  116. { /* cs1 */
  117. FSL_DDR_ODT_OTHER_DIMM,
  118. FSL_DDR_ODT_OTHER_DIMM,
  119. DDR3_RTT_30_OHM,
  120. DDR3_RTT_OFF
  121. },
  122. { /* cs2 */
  123. FSL_DDR_ODT_OTHER_DIMM,
  124. FSL_DDR_ODT_ALL,
  125. DDR3_RTT_20_OHM,
  126. DDR3_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. DDR3_RTT_20_OHM,
  135. DDR3_RTT_120_OHM
  136. },
  137. {0, 0, 0, 0},
  138. { /* cs2 */
  139. FSL_DDR_ODT_NEVER,
  140. FSL_DDR_ODT_SAME_DIMM,
  141. DDR3_RTT_120_OHM,
  142. DDR3_RTT_OFF
  143. },
  144. { /* cs3 */
  145. FSL_DDR_ODT_OTHER_DIMM,
  146. FSL_DDR_ODT_OTHER_DIMM,
  147. DDR3_RTT_20_OHM,
  148. DDR3_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. DDR3_RTT_30_OHM,
  156. DDR3_RTT_120_OHM
  157. },
  158. {0, 0, 0, 0},
  159. { /* cs2 */
  160. FSL_DDR_ODT_OTHER_DIMM,
  161. FSL_DDR_ODT_ALL,
  162. DDR3_RTT_30_OHM,
  163. DDR3_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. DDR3_RTT_40_OHM,
  172. DDR3_RTT_OFF
  173. },
  174. { /* cs1 */
  175. FSL_DDR_ODT_NEVER,
  176. FSL_DDR_ODT_NEVER,
  177. DDR3_RTT_OFF,
  178. DDR3_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. DDR3_RTT_40_OHM,
  190. DDR3_RTT_OFF
  191. },
  192. { /* cs3 */
  193. FSL_DDR_ODT_NEVER,
  194. FSL_DDR_ODT_NEVER,
  195. DDR3_RTT_OFF,
  196. DDR3_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. DDR3_RTT_40_OHM,
  204. DDR3_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. DDR3_RTT_40_OHM,
  217. DDR3_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. DDR3_RTT_120_OHM,
  226. DDR3_RTT_OFF
  227. },
  228. { /* cs1 */
  229. FSL_DDR_ODT_NEVER,
  230. FSL_DDR_ODT_CS,
  231. DDR3_RTT_120_OHM,
  232. DDR3_RTT_OFF
  233. },
  234. { /* cs2 */
  235. FSL_DDR_ODT_NEVER,
  236. FSL_DDR_ODT_CS,
  237. DDR3_RTT_120_OHM,
  238. DDR3_RTT_OFF
  239. },
  240. { /* cs3 */
  241. FSL_DDR_ODT_NEVER,
  242. FSL_DDR_ODT_CS,
  243. DDR3_RTT_120_OHM,
  244. DDR3_RTT_OFF
  245. }
  246. };
  247. #else /* CONFIG_FSL_DDR3 */
  248. static const struct dynamic_odt single_Q[4] = {
  249. {0, 0, 0, 0},
  250. {0, 0, 0, 0},
  251. {0, 0, 0, 0},
  252. {0, 0, 0, 0}
  253. };
  254. static const struct dynamic_odt single_D[4] = {
  255. { /* cs0 */
  256. FSL_DDR_ODT_NEVER,
  257. FSL_DDR_ODT_ALL,
  258. DDR2_RTT_150_OHM,
  259. DDR2_RTT_OFF
  260. },
  261. { /* cs1 */
  262. FSL_DDR_ODT_NEVER,
  263. FSL_DDR_ODT_NEVER,
  264. DDR2_RTT_OFF,
  265. DDR2_RTT_OFF
  266. },
  267. {0, 0, 0, 0},
  268. {0, 0, 0, 0}
  269. };
  270. static const struct dynamic_odt single_S[4] = {
  271. { /* cs0 */
  272. FSL_DDR_ODT_NEVER,
  273. FSL_DDR_ODT_ALL,
  274. DDR2_RTT_150_OHM,
  275. DDR2_RTT_OFF
  276. },
  277. {0, 0, 0, 0},
  278. {0, 0, 0, 0},
  279. {0, 0, 0, 0},
  280. };
  281. static const struct dynamic_odt dual_DD[4] = {
  282. { /* cs0 */
  283. FSL_DDR_ODT_OTHER_DIMM,
  284. FSL_DDR_ODT_OTHER_DIMM,
  285. DDR2_RTT_75_OHM,
  286. DDR2_RTT_OFF
  287. },
  288. { /* cs1 */
  289. FSL_DDR_ODT_NEVER,
  290. FSL_DDR_ODT_NEVER,
  291. DDR2_RTT_OFF,
  292. DDR2_RTT_OFF
  293. },
  294. { /* cs2 */
  295. FSL_DDR_ODT_OTHER_DIMM,
  296. FSL_DDR_ODT_OTHER_DIMM,
  297. DDR2_RTT_75_OHM,
  298. DDR2_RTT_OFF
  299. },
  300. { /* cs3 */
  301. FSL_DDR_ODT_NEVER,
  302. FSL_DDR_ODT_NEVER,
  303. DDR2_RTT_OFF,
  304. DDR2_RTT_OFF
  305. }
  306. };
  307. static const struct dynamic_odt dual_DS[4] = {
  308. { /* cs0 */
  309. FSL_DDR_ODT_OTHER_DIMM,
  310. FSL_DDR_ODT_OTHER_DIMM,
  311. DDR2_RTT_75_OHM,
  312. DDR2_RTT_OFF
  313. },
  314. { /* cs1 */
  315. FSL_DDR_ODT_NEVER,
  316. FSL_DDR_ODT_NEVER,
  317. DDR2_RTT_OFF,
  318. DDR2_RTT_OFF
  319. },
  320. { /* cs2 */
  321. FSL_DDR_ODT_OTHER_DIMM,
  322. FSL_DDR_ODT_OTHER_DIMM,
  323. DDR2_RTT_75_OHM,
  324. DDR2_RTT_OFF
  325. },
  326. {0, 0, 0, 0}
  327. };
  328. static const struct dynamic_odt dual_SD[4] = {
  329. { /* cs0 */
  330. FSL_DDR_ODT_OTHER_DIMM,
  331. FSL_DDR_ODT_OTHER_DIMM,
  332. DDR2_RTT_75_OHM,
  333. DDR2_RTT_OFF
  334. },
  335. {0, 0, 0, 0},
  336. { /* cs2 */
  337. FSL_DDR_ODT_OTHER_DIMM,
  338. FSL_DDR_ODT_OTHER_DIMM,
  339. DDR2_RTT_75_OHM,
  340. DDR2_RTT_OFF
  341. },
  342. { /* cs3 */
  343. FSL_DDR_ODT_NEVER,
  344. FSL_DDR_ODT_NEVER,
  345. DDR2_RTT_OFF,
  346. DDR2_RTT_OFF
  347. }
  348. };
  349. static const struct dynamic_odt dual_SS[4] = {
  350. { /* cs0 */
  351. FSL_DDR_ODT_OTHER_DIMM,
  352. FSL_DDR_ODT_OTHER_DIMM,
  353. DDR2_RTT_75_OHM,
  354. DDR2_RTT_OFF
  355. },
  356. {0, 0, 0, 0},
  357. { /* cs2 */
  358. FSL_DDR_ODT_OTHER_DIMM,
  359. FSL_DDR_ODT_OTHER_DIMM,
  360. DDR2_RTT_75_OHM,
  361. DDR2_RTT_OFF
  362. },
  363. {0, 0, 0, 0}
  364. };
  365. static const struct dynamic_odt dual_D0[4] = {
  366. { /* cs0 */
  367. FSL_DDR_ODT_NEVER,
  368. FSL_DDR_ODT_ALL,
  369. DDR2_RTT_150_OHM,
  370. DDR2_RTT_OFF
  371. },
  372. { /* cs1 */
  373. FSL_DDR_ODT_NEVER,
  374. FSL_DDR_ODT_NEVER,
  375. DDR2_RTT_OFF,
  376. DDR2_RTT_OFF
  377. },
  378. {0, 0, 0, 0},
  379. {0, 0, 0, 0}
  380. };
  381. static const struct dynamic_odt dual_0D[4] = {
  382. {0, 0, 0, 0},
  383. {0, 0, 0, 0},
  384. { /* cs2 */
  385. FSL_DDR_ODT_NEVER,
  386. FSL_DDR_ODT_ALL,
  387. DDR2_RTT_150_OHM,
  388. DDR2_RTT_OFF
  389. },
  390. { /* cs3 */
  391. FSL_DDR_ODT_NEVER,
  392. FSL_DDR_ODT_NEVER,
  393. DDR2_RTT_OFF,
  394. DDR2_RTT_OFF
  395. }
  396. };
  397. static const struct dynamic_odt dual_S0[4] = {
  398. { /* cs0 */
  399. FSL_DDR_ODT_NEVER,
  400. FSL_DDR_ODT_CS,
  401. DDR2_RTT_150_OHM,
  402. DDR2_RTT_OFF
  403. },
  404. {0, 0, 0, 0},
  405. {0, 0, 0, 0},
  406. {0, 0, 0, 0}
  407. };
  408. static const struct dynamic_odt dual_0S[4] = {
  409. {0, 0, 0, 0},
  410. {0, 0, 0, 0},
  411. { /* cs2 */
  412. FSL_DDR_ODT_NEVER,
  413. FSL_DDR_ODT_CS,
  414. DDR2_RTT_150_OHM,
  415. DDR2_RTT_OFF
  416. },
  417. {0, 0, 0, 0}
  418. };
  419. static const struct dynamic_odt odt_unknown[4] = {
  420. { /* cs0 */
  421. FSL_DDR_ODT_NEVER,
  422. FSL_DDR_ODT_CS,
  423. DDR2_RTT_75_OHM,
  424. DDR2_RTT_OFF
  425. },
  426. { /* cs1 */
  427. FSL_DDR_ODT_NEVER,
  428. FSL_DDR_ODT_NEVER,
  429. DDR2_RTT_OFF,
  430. DDR2_RTT_OFF
  431. },
  432. { /* cs2 */
  433. FSL_DDR_ODT_NEVER,
  434. FSL_DDR_ODT_CS,
  435. DDR2_RTT_75_OHM,
  436. DDR2_RTT_OFF
  437. },
  438. { /* cs3 */
  439. FSL_DDR_ODT_NEVER,
  440. FSL_DDR_ODT_NEVER,
  441. DDR2_RTT_OFF,
  442. DDR2_RTT_OFF
  443. }
  444. };
  445. #endif
  446. unsigned int populate_memctl_options(int all_DIMMs_registered,
  447. memctl_options_t *popts,
  448. dimm_params_t *pdimm,
  449. unsigned int ctrl_num)
  450. {
  451. unsigned int i;
  452. char buffer[HWCONFIG_BUFFER_SIZE];
  453. char *buf = NULL;
  454. #if defined(CONFIG_FSL_DDR3) || defined(CONFIG_FSL_DDR2)
  455. const struct dynamic_odt *pdodt = odt_unknown;
  456. #endif
  457. ulong ddr_freq;
  458. /*
  459. * Extract hwconfig from environment since we have not properly setup
  460. * the environment but need it for ddr config params
  461. */
  462. if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0)
  463. buf = buffer;
  464. #if defined(CONFIG_FSL_DDR3) || defined(CONFIG_FSL_DDR2)
  465. /* Chip select options. */
  466. if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) {
  467. switch (pdimm[0].n_ranks) {
  468. case 1:
  469. pdodt = single_S;
  470. break;
  471. case 2:
  472. pdodt = single_D;
  473. break;
  474. case 4:
  475. pdodt = single_Q;
  476. break;
  477. }
  478. } else if (CONFIG_DIMM_SLOTS_PER_CTLR == 2) {
  479. switch (pdimm[0].n_ranks) {
  480. #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
  481. case 4:
  482. pdodt = single_Q;
  483. if (pdimm[1].n_ranks)
  484. printf("Error: Quad- and Dual-rank DIMMs "
  485. "cannot be used together\n");
  486. break;
  487. #endif
  488. case 2:
  489. switch (pdimm[1].n_ranks) {
  490. case 2:
  491. pdodt = dual_DD;
  492. break;
  493. case 1:
  494. pdodt = dual_DS;
  495. break;
  496. case 0:
  497. pdodt = dual_D0;
  498. break;
  499. }
  500. break;
  501. case 1:
  502. switch (pdimm[1].n_ranks) {
  503. case 2:
  504. pdodt = dual_SD;
  505. break;
  506. case 1:
  507. pdodt = dual_SS;
  508. break;
  509. case 0:
  510. pdodt = dual_S0;
  511. break;
  512. }
  513. break;
  514. case 0:
  515. switch (pdimm[1].n_ranks) {
  516. case 2:
  517. pdodt = dual_0D;
  518. break;
  519. case 1:
  520. pdodt = dual_0S;
  521. break;
  522. }
  523. break;
  524. }
  525. }
  526. #endif
  527. /* Pick chip-select local options. */
  528. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  529. #if defined(CONFIG_FSL_DDR3) || defined(CONFIG_FSL_DDR2)
  530. popts->cs_local_opts[i].odt_rd_cfg = pdodt[i].odt_rd_cfg;
  531. popts->cs_local_opts[i].odt_wr_cfg = pdodt[i].odt_wr_cfg;
  532. popts->cs_local_opts[i].odt_rtt_norm = pdodt[i].odt_rtt_norm;
  533. popts->cs_local_opts[i].odt_rtt_wr = pdodt[i].odt_rtt_wr;
  534. #else
  535. popts->cs_local_opts[i].odt_rd_cfg = FSL_DDR_ODT_NEVER;
  536. popts->cs_local_opts[i].odt_wr_cfg = FSL_DDR_ODT_CS;
  537. #endif
  538. popts->cs_local_opts[i].auto_precharge = 0;
  539. }
  540. /* Pick interleaving mode. */
  541. /*
  542. * 0 = no interleaving
  543. * 1 = interleaving between 2 controllers
  544. */
  545. popts->memctl_interleaving = 0;
  546. /*
  547. * 0 = cacheline
  548. * 1 = page
  549. * 2 = (logical) bank
  550. * 3 = superbank (only if CS interleaving is enabled)
  551. */
  552. popts->memctl_interleaving_mode = 0;
  553. /*
  554. * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
  555. * 1: page: bit to the left of the column bits selects the memctl
  556. * 2: bank: bit to the left of the bank bits selects the memctl
  557. * 3: superbank: bit to the left of the chip select selects the memctl
  558. *
  559. * NOTE: ba_intlv (rank interleaving) is independent of memory
  560. * controller interleaving; it is only within a memory controller.
  561. * Must use superbank interleaving if rank interleaving is used and
  562. * memory controller interleaving is enabled.
  563. */
  564. /*
  565. * 0 = no
  566. * 0x40 = CS0,CS1
  567. * 0x20 = CS2,CS3
  568. * 0x60 = CS0,CS1 + CS2,CS3
  569. * 0x04 = CS0,CS1,CS2,CS3
  570. */
  571. popts->ba_intlv_ctl = 0;
  572. /* Memory Organization Parameters */
  573. popts->registered_dimm_en = all_DIMMs_registered;
  574. /* Operational Mode Paramters */
  575. /* Pick ECC modes */
  576. popts->ECC_mode = 0; /* 0 = disabled, 1 = enabled */
  577. #ifdef CONFIG_DDR_ECC
  578. if (hwconfig_sub_f("fsl_ddr", "ecc", buf)) {
  579. if (hwconfig_subarg_cmp_f("fsl_ddr", "ecc", "on", buf))
  580. popts->ECC_mode = 1;
  581. } else
  582. popts->ECC_mode = 1;
  583. #endif
  584. popts->ECC_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */
  585. /*
  586. * Choose DQS config
  587. * 0 for DDR1
  588. * 1 for DDR2
  589. */
  590. #if defined(CONFIG_FSL_DDR1)
  591. popts->DQS_config = 0;
  592. #elif defined(CONFIG_FSL_DDR2) || defined(CONFIG_FSL_DDR3)
  593. popts->DQS_config = 1;
  594. #endif
  595. /* Choose self-refresh during sleep. */
  596. popts->self_refresh_in_sleep = 1;
  597. /* Choose dynamic power management mode. */
  598. popts->dynamic_power = 0;
  599. /*
  600. * check first dimm for primary sdram width
  601. * presuming all dimms are similar
  602. * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit
  603. */
  604. #if defined(CONFIG_FSL_DDR1) || defined(CONFIG_FSL_DDR2)
  605. if (pdimm[0].n_ranks != 0) {
  606. if ((pdimm[0].data_width >= 64) && \
  607. (pdimm[0].data_width <= 72))
  608. popts->data_bus_width = 0;
  609. else if ((pdimm[0].data_width >= 32) || \
  610. (pdimm[0].data_width <= 40))
  611. popts->data_bus_width = 1;
  612. else {
  613. panic("Error: data width %u is invalid!\n",
  614. pdimm[0].data_width);
  615. }
  616. }
  617. #else
  618. if (pdimm[0].n_ranks != 0) {
  619. if (pdimm[0].primary_sdram_width == 64)
  620. popts->data_bus_width = 0;
  621. else if (pdimm[0].primary_sdram_width == 32)
  622. popts->data_bus_width = 1;
  623. else if (pdimm[0].primary_sdram_width == 16)
  624. popts->data_bus_width = 2;
  625. else {
  626. panic("Error: primary sdram width %u is invalid!\n",
  627. pdimm[0].primary_sdram_width);
  628. }
  629. }
  630. #endif
  631. /* Choose burst length. */
  632. #if defined(CONFIG_FSL_DDR3)
  633. #if defined(CONFIG_E500MC)
  634. popts->OTF_burst_chop_en = 0; /* on-the-fly burst chop disable */
  635. popts->burst_length = DDR_BL8; /* Fixed 8-beat burst len */
  636. #else
  637. if ((popts->data_bus_width == 1) || (popts->data_bus_width == 2)) {
  638. /* 32-bit or 16-bit bus */
  639. popts->OTF_burst_chop_en = 0;
  640. popts->burst_length = DDR_BL8;
  641. } else {
  642. popts->OTF_burst_chop_en = 1; /* on-the-fly burst chop */
  643. popts->burst_length = DDR_OTF; /* on-the-fly BC4 and BL8 */
  644. }
  645. #endif
  646. #else
  647. popts->burst_length = DDR_BL4; /* has to be 4 for DDR2 */
  648. #endif
  649. /* Choose ddr controller address mirror mode */
  650. #if defined(CONFIG_FSL_DDR3)
  651. popts->mirrored_dimm = pdimm[0].mirrored_dimm;
  652. #endif
  653. /* Global Timing Parameters. */
  654. debug("mclk_ps = %u ps\n", get_memory_clk_period_ps());
  655. /* Pick a caslat override. */
  656. popts->cas_latency_override = 0;
  657. popts->cas_latency_override_value = 3;
  658. if (popts->cas_latency_override) {
  659. debug("using caslat override value = %u\n",
  660. popts->cas_latency_override_value);
  661. }
  662. /* Decide whether to use the computed derated latency */
  663. popts->use_derated_caslat = 0;
  664. /* Choose an additive latency. */
  665. popts->additive_latency_override = 0;
  666. popts->additive_latency_override_value = 3;
  667. if (popts->additive_latency_override) {
  668. debug("using additive latency override value = %u\n",
  669. popts->additive_latency_override_value);
  670. }
  671. /*
  672. * 2T_EN setting
  673. *
  674. * Factors to consider for 2T_EN:
  675. * - number of DIMMs installed
  676. * - number of components, number of active ranks
  677. * - how much time you want to spend playing around
  678. */
  679. popts->twoT_en = 0;
  680. popts->threeT_en = 0;
  681. /* for RDIMM, address parity enable */
  682. popts->ap_en = 1;
  683. /*
  684. * BSTTOPRE precharge interval
  685. *
  686. * Set this to 0 for global auto precharge
  687. *
  688. * FIXME: Should this be configured in picoseconds?
  689. * Why it should be in ps: better understanding of this
  690. * relative to actual DRAM timing parameters such as tRAS.
  691. * e.g. tRAS(min) = 40 ns
  692. */
  693. popts->bstopre = 0x100;
  694. /* Minimum CKE pulse width -- tCKE(MIN) */
  695. popts->tCKE_clock_pulse_width_ps
  696. = mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR);
  697. /*
  698. * Window for four activates -- tFAW
  699. *
  700. * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
  701. * FIXME: varies depending upon number of column addresses or data
  702. * FIXME: width, was considering looking at pdimm->primary_sdram_width
  703. */
  704. #if defined(CONFIG_FSL_DDR1)
  705. popts->tFAW_window_four_activates_ps = mclk_to_picos(1);
  706. #elif defined(CONFIG_FSL_DDR2)
  707. /*
  708. * x4/x8; some datasheets have 35000
  709. * x16 wide columns only? Use 50000?
  710. */
  711. popts->tFAW_window_four_activates_ps = 37500;
  712. #elif defined(CONFIG_FSL_DDR3)
  713. popts->tFAW_window_four_activates_ps = pdimm[0].tFAW_ps;
  714. #endif
  715. popts->zq_en = 0;
  716. popts->wrlvl_en = 0;
  717. #if defined(CONFIG_FSL_DDR3)
  718. /*
  719. * due to ddr3 dimm is fly-by topology
  720. * we suggest to enable write leveling to
  721. * meet the tQDSS under different loading.
  722. */
  723. popts->wrlvl_en = 1;
  724. popts->zq_en = 1;
  725. popts->wrlvl_override = 0;
  726. #endif
  727. /*
  728. * Check interleaving configuration from environment.
  729. * Please refer to doc/README.fsl-ddr for the detail.
  730. *
  731. * If memory controller interleaving is enabled, then the data
  732. * bus widths must be programmed identically for all memory controllers.
  733. *
  734. * XXX: Attempt to set all controllers to the same chip select
  735. * interleaving mode. It will do a best effort to get the
  736. * requested ranks interleaved together such that the result
  737. * should be a subset of the requested configuration.
  738. */
  739. #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
  740. if (!hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf))
  741. goto done;
  742. if (pdimm[0].n_ranks == 0) {
  743. printf("There is no rank on CS0 for controller %d.\n", ctrl_num);
  744. popts->memctl_interleaving = 0;
  745. goto done;
  746. }
  747. popts->memctl_interleaving = 1;
  748. /*
  749. * test null first. if CONFIG_HWCONFIG is not defined
  750. * hwconfig_arg_cmp returns non-zero
  751. */
  752. if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  753. "null", buf)) {
  754. popts->memctl_interleaving = 0;
  755. debug("memory controller interleaving disabled.\n");
  756. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  757. "ctlr_intlv",
  758. "cacheline", buf)) {
  759. popts->memctl_interleaving_mode =
  760. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  761. 0 : FSL_DDR_CACHE_LINE_INTERLEAVING;
  762. popts->memctl_interleaving =
  763. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  764. 0 : 1;
  765. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  766. "ctlr_intlv",
  767. "page", buf)) {
  768. popts->memctl_interleaving_mode =
  769. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  770. 0 : FSL_DDR_PAGE_INTERLEAVING;
  771. popts->memctl_interleaving =
  772. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  773. 0 : 1;
  774. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  775. "ctlr_intlv",
  776. "bank", buf)) {
  777. popts->memctl_interleaving_mode =
  778. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  779. 0 : FSL_DDR_BANK_INTERLEAVING;
  780. popts->memctl_interleaving =
  781. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  782. 0 : 1;
  783. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  784. "ctlr_intlv",
  785. "superbank", buf)) {
  786. popts->memctl_interleaving_mode =
  787. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  788. 0 : FSL_DDR_SUPERBANK_INTERLEAVING;
  789. popts->memctl_interleaving =
  790. ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
  791. 0 : 1;
  792. #if (CONFIG_NUM_DDR_CONTROLLERS == 3)
  793. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  794. "ctlr_intlv",
  795. "3way_1KB", buf)) {
  796. popts->memctl_interleaving_mode =
  797. FSL_DDR_3WAY_1KB_INTERLEAVING;
  798. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  799. "ctlr_intlv",
  800. "3way_4KB", buf)) {
  801. popts->memctl_interleaving_mode =
  802. FSL_DDR_3WAY_4KB_INTERLEAVING;
  803. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  804. "ctlr_intlv",
  805. "3way_8KB", buf)) {
  806. popts->memctl_interleaving_mode =
  807. FSL_DDR_3WAY_8KB_INTERLEAVING;
  808. #elif (CONFIG_NUM_DDR_CONTROLLERS == 4)
  809. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  810. "ctlr_intlv",
  811. "4way_1KB", buf)) {
  812. popts->memctl_interleaving_mode =
  813. FSL_DDR_4WAY_1KB_INTERLEAVING;
  814. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  815. "ctlr_intlv",
  816. "4way_4KB", buf)) {
  817. popts->memctl_interleaving_mode =
  818. FSL_DDR_4WAY_4KB_INTERLEAVING;
  819. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  820. "ctlr_intlv",
  821. "4way_8KB", buf)) {
  822. popts->memctl_interleaving_mode =
  823. FSL_DDR_4WAY_8KB_INTERLEAVING;
  824. #endif
  825. } else {
  826. popts->memctl_interleaving = 0;
  827. printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
  828. }
  829. done:
  830. #endif
  831. if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) &&
  832. (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) {
  833. /* test null first. if CONFIG_HWCONFIG is not defined,
  834. * hwconfig_subarg_cmp_f returns non-zero */
  835. if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  836. "null", buf))
  837. debug("bank interleaving disabled.\n");
  838. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  839. "cs0_cs1", buf))
  840. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
  841. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  842. "cs2_cs3", buf))
  843. popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
  844. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  845. "cs0_cs1_and_cs2_cs3", buf))
  846. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
  847. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  848. "cs0_cs1_cs2_cs3", buf))
  849. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
  850. else
  851. printf("hwconfig has unrecognized parameter for bank_intlv.\n");
  852. switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
  853. case FSL_DDR_CS0_CS1_CS2_CS3:
  854. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  855. if (pdimm[0].n_ranks < 4) {
  856. popts->ba_intlv_ctl = 0;
  857. printf("Not enough bank(chip-select) for "
  858. "CS0+CS1+CS2+CS3 on controller %d, "
  859. "interleaving disabled!\n", ctrl_num);
  860. }
  861. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  862. #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
  863. if (pdimm[0].n_ranks == 4)
  864. break;
  865. #endif
  866. if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) {
  867. popts->ba_intlv_ctl = 0;
  868. printf("Not enough bank(chip-select) for "
  869. "CS0+CS1+CS2+CS3 on controller %d, "
  870. "interleaving disabled!\n", ctrl_num);
  871. }
  872. if (pdimm[0].capacity != pdimm[1].capacity) {
  873. popts->ba_intlv_ctl = 0;
  874. printf("Not identical DIMM size for "
  875. "CS0+CS1+CS2+CS3 on controller %d, "
  876. "interleaving disabled!\n", ctrl_num);
  877. }
  878. #endif
  879. break;
  880. case FSL_DDR_CS0_CS1:
  881. if (pdimm[0].n_ranks < 2) {
  882. popts->ba_intlv_ctl = 0;
  883. printf("Not enough bank(chip-select) for "
  884. "CS0+CS1 on controller %d, "
  885. "interleaving disabled!\n", ctrl_num);
  886. }
  887. break;
  888. case FSL_DDR_CS2_CS3:
  889. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  890. if (pdimm[0].n_ranks < 4) {
  891. popts->ba_intlv_ctl = 0;
  892. printf("Not enough bank(chip-select) for CS2+CS3 "
  893. "on controller %d, interleaving disabled!\n", ctrl_num);
  894. }
  895. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  896. if (pdimm[1].n_ranks < 2) {
  897. popts->ba_intlv_ctl = 0;
  898. printf("Not enough bank(chip-select) for CS2+CS3 "
  899. "on controller %d, interleaving disabled!\n", ctrl_num);
  900. }
  901. #endif
  902. break;
  903. case FSL_DDR_CS0_CS1_AND_CS2_CS3:
  904. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  905. if (pdimm[0].n_ranks < 4) {
  906. popts->ba_intlv_ctl = 0;
  907. printf("Not enough bank(CS) for CS0+CS1 and "
  908. "CS2+CS3 on controller %d, "
  909. "interleaving disabled!\n", ctrl_num);
  910. }
  911. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  912. if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) {
  913. popts->ba_intlv_ctl = 0;
  914. printf("Not enough bank(CS) for CS0+CS1 and "
  915. "CS2+CS3 on controller %d, "
  916. "interleaving disabled!\n", ctrl_num);
  917. }
  918. #endif
  919. break;
  920. default:
  921. popts->ba_intlv_ctl = 0;
  922. break;
  923. }
  924. }
  925. if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf)) {
  926. if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf))
  927. popts->addr_hash = 0;
  928. else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash",
  929. "true", buf))
  930. popts->addr_hash = 1;
  931. }
  932. if (pdimm[0].n_ranks == 4)
  933. popts->quad_rank_present = 1;
  934. ddr_freq = get_ddr_freq(0) / 1000000;
  935. if (popts->registered_dimm_en) {
  936. popts->rcw_override = 1;
  937. popts->rcw_1 = 0x000a5a00;
  938. if (ddr_freq <= 800)
  939. popts->rcw_2 = 0x00000000;
  940. else if (ddr_freq <= 1066)
  941. popts->rcw_2 = 0x00100000;
  942. else if (ddr_freq <= 1333)
  943. popts->rcw_2 = 0x00200000;
  944. else
  945. popts->rcw_2 = 0x00300000;
  946. }
  947. fsl_ddr_board_options(popts, pdimm, ctrl_num);
  948. return 0;
  949. }
  950. void check_interleaving_options(fsl_ddr_info_t *pinfo)
  951. {
  952. int i, j, k, check_n_ranks, intlv_invalid = 0;
  953. unsigned int check_intlv, check_n_row_addr, check_n_col_addr;
  954. unsigned long long check_rank_density;
  955. struct dimm_params_s *dimm;
  956. /*
  957. * Check if all controllers are configured for memory
  958. * controller interleaving. Identical dimms are recommended. At least
  959. * the size, row and col address should be checked.
  960. */
  961. j = 0;
  962. check_n_ranks = pinfo->dimm_params[0][0].n_ranks;
  963. check_rank_density = pinfo->dimm_params[0][0].rank_density;
  964. check_n_row_addr = pinfo->dimm_params[0][0].n_row_addr;
  965. check_n_col_addr = pinfo->dimm_params[0][0].n_col_addr;
  966. check_intlv = pinfo->memctl_opts[0].memctl_interleaving_mode;
  967. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  968. dimm = &pinfo->dimm_params[i][0];
  969. if (!pinfo->memctl_opts[i].memctl_interleaving) {
  970. continue;
  971. } else if (((check_rank_density != dimm->rank_density) ||
  972. (check_n_ranks != dimm->n_ranks) ||
  973. (check_n_row_addr != dimm->n_row_addr) ||
  974. (check_n_col_addr != dimm->n_col_addr) ||
  975. (check_intlv !=
  976. pinfo->memctl_opts[i].memctl_interleaving_mode))){
  977. intlv_invalid = 1;
  978. break;
  979. } else {
  980. j++;
  981. }
  982. }
  983. if (intlv_invalid) {
  984. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
  985. pinfo->memctl_opts[i].memctl_interleaving = 0;
  986. printf("Not all DIMMs are identical. "
  987. "Memory controller interleaving disabled.\n");
  988. } else {
  989. switch (check_intlv) {
  990. case FSL_DDR_CACHE_LINE_INTERLEAVING:
  991. case FSL_DDR_PAGE_INTERLEAVING:
  992. case FSL_DDR_BANK_INTERLEAVING:
  993. case FSL_DDR_SUPERBANK_INTERLEAVING:
  994. if (3 == CONFIG_NUM_DDR_CONTROLLERS)
  995. k = 2;
  996. else
  997. k = CONFIG_NUM_DDR_CONTROLLERS;
  998. break;
  999. case FSL_DDR_3WAY_1KB_INTERLEAVING:
  1000. case FSL_DDR_3WAY_4KB_INTERLEAVING:
  1001. case FSL_DDR_3WAY_8KB_INTERLEAVING:
  1002. case FSL_DDR_4WAY_1KB_INTERLEAVING:
  1003. case FSL_DDR_4WAY_4KB_INTERLEAVING:
  1004. case FSL_DDR_4WAY_8KB_INTERLEAVING:
  1005. default:
  1006. k = CONFIG_NUM_DDR_CONTROLLERS;
  1007. break;
  1008. }
  1009. debug("%d of %d controllers are interleaving.\n", j, k);
  1010. if (j != k) {
  1011. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
  1012. pinfo->memctl_opts[i].memctl_interleaving = 0;
  1013. printf("Not all controllers have compatible "
  1014. "interleaving mode. All disabled.\n");
  1015. }
  1016. }
  1017. debug("Checking interleaving options completed\n");
  1018. }
  1019. int fsl_use_spd(void)
  1020. {
  1021. int use_spd = 0;
  1022. #ifdef CONFIG_DDR_SPD
  1023. char buffer[HWCONFIG_BUFFER_SIZE];
  1024. char *buf = NULL;
  1025. /*
  1026. * Extract hwconfig from environment since we have not properly setup
  1027. * the environment but need it for ddr config params
  1028. */
  1029. if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0)
  1030. buf = buffer;
  1031. /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
  1032. if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) {
  1033. if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf))
  1034. use_spd = 1;
  1035. else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram",
  1036. "fixed", buf))
  1037. use_spd = 0;
  1038. else
  1039. use_spd = 1;
  1040. } else
  1041. use_spd = 1;
  1042. #endif
  1043. return use_spd;
  1044. }