options.c 23 KB

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