options.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  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. const struct dynamic_odt *pdodt = odt_unknown;
  456. ulong ddr_freq;
  457. /*
  458. * Extract hwconfig from environment since we have not properly setup
  459. * the environment but need it for ddr config params
  460. */
  461. if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0)
  462. buf = buffer;
  463. /* Chip select options. */
  464. if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) {
  465. switch (pdimm[0].n_ranks) {
  466. case 1:
  467. pdodt = single_S;
  468. break;
  469. case 2:
  470. pdodt = single_D;
  471. break;
  472. case 4:
  473. pdodt = single_Q;
  474. break;
  475. }
  476. } else if (CONFIG_DIMM_SLOTS_PER_CTLR == 2) {
  477. switch (pdimm[0].n_ranks) {
  478. case 2:
  479. switch (pdimm[1].n_ranks) {
  480. case 2:
  481. pdodt = dual_DD;
  482. break;
  483. case 1:
  484. pdodt = dual_DS;
  485. break;
  486. case 0:
  487. pdodt = dual_D0;
  488. break;
  489. }
  490. break;
  491. case 1:
  492. switch (pdimm[1].n_ranks) {
  493. case 2:
  494. pdodt = dual_SD;
  495. break;
  496. case 1:
  497. pdodt = dual_SS;
  498. break;
  499. case 0:
  500. pdodt = dual_S0;
  501. break;
  502. }
  503. break;
  504. case 0:
  505. switch (pdimm[1].n_ranks) {
  506. case 2:
  507. pdodt = dual_0D;
  508. break;
  509. case 1:
  510. pdodt = dual_0S;
  511. break;
  512. }
  513. break;
  514. }
  515. }
  516. /* Pick chip-select local options. */
  517. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  518. #if defined(CONFIG_FSL_DDR3) || defined(CONFIG_FSL_DDR2)
  519. popts->cs_local_opts[i].odt_rd_cfg = pdodt[i].odt_rd_cfg;
  520. popts->cs_local_opts[i].odt_wr_cfg = pdodt[i].odt_wr_cfg;
  521. popts->cs_local_opts[i].odt_rtt_norm = pdodt[i].odt_rtt_norm;
  522. popts->cs_local_opts[i].odt_rtt_wr = pdodt[i].odt_rtt_wr;
  523. #else
  524. popts->cs_local_opts[i].odt_rd_cfg = FSL_DDR_ODT_NEVER;
  525. popts->cs_local_opts[i].odt_wr_cfg = FSL_DDR_ODT_CS;
  526. #endif
  527. popts->cs_local_opts[i].auto_precharge = 0;
  528. }
  529. /* Pick interleaving mode. */
  530. /*
  531. * 0 = no interleaving
  532. * 1 = interleaving between 2 controllers
  533. */
  534. popts->memctl_interleaving = 0;
  535. /*
  536. * 0 = cacheline
  537. * 1 = page
  538. * 2 = (logical) bank
  539. * 3 = superbank (only if CS interleaving is enabled)
  540. */
  541. popts->memctl_interleaving_mode = 0;
  542. /*
  543. * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
  544. * 1: page: bit to the left of the column bits selects the memctl
  545. * 2: bank: bit to the left of the bank bits selects the memctl
  546. * 3: superbank: bit to the left of the chip select selects the memctl
  547. *
  548. * NOTE: ba_intlv (rank interleaving) is independent of memory
  549. * controller interleaving; it is only within a memory controller.
  550. * Must use superbank interleaving if rank interleaving is used and
  551. * memory controller interleaving is enabled.
  552. */
  553. /*
  554. * 0 = no
  555. * 0x40 = CS0,CS1
  556. * 0x20 = CS2,CS3
  557. * 0x60 = CS0,CS1 + CS2,CS3
  558. * 0x04 = CS0,CS1,CS2,CS3
  559. */
  560. popts->ba_intlv_ctl = 0;
  561. /* Memory Organization Parameters */
  562. popts->registered_dimm_en = all_DIMMs_registered;
  563. /* Operational Mode Paramters */
  564. /* Pick ECC modes */
  565. popts->ECC_mode = 0; /* 0 = disabled, 1 = enabled */
  566. #ifdef CONFIG_DDR_ECC
  567. if (hwconfig_sub_f("fsl_ddr", "ecc", buf)) {
  568. if (hwconfig_subarg_cmp_f("fsl_ddr", "ecc", "on", buf))
  569. popts->ECC_mode = 1;
  570. } else
  571. popts->ECC_mode = 1;
  572. #endif
  573. popts->ECC_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */
  574. /*
  575. * Choose DQS config
  576. * 0 for DDR1
  577. * 1 for DDR2
  578. */
  579. #if defined(CONFIG_FSL_DDR1)
  580. popts->DQS_config = 0;
  581. #elif defined(CONFIG_FSL_DDR2) || defined(CONFIG_FSL_DDR3)
  582. popts->DQS_config = 1;
  583. #endif
  584. /* Choose self-refresh during sleep. */
  585. popts->self_refresh_in_sleep = 1;
  586. /* Choose dynamic power management mode. */
  587. popts->dynamic_power = 0;
  588. /*
  589. * check first dimm for primary sdram width
  590. * presuming all dimms are similar
  591. * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit
  592. */
  593. #if defined(CONFIG_FSL_DDR1) || defined(CONFIG_FSL_DDR2)
  594. if (pdimm[0].n_ranks != 0) {
  595. if ((pdimm[0].data_width >= 64) && \
  596. (pdimm[0].data_width <= 72))
  597. popts->data_bus_width = 0;
  598. else if ((pdimm[0].data_width >= 32) || \
  599. (pdimm[0].data_width <= 40))
  600. popts->data_bus_width = 1;
  601. else {
  602. panic("Error: data width %u is invalid!\n",
  603. pdimm[0].data_width);
  604. }
  605. }
  606. #else
  607. if (pdimm[0].n_ranks != 0) {
  608. if (pdimm[0].primary_sdram_width == 64)
  609. popts->data_bus_width = 0;
  610. else if (pdimm[0].primary_sdram_width == 32)
  611. popts->data_bus_width = 1;
  612. else if (pdimm[0].primary_sdram_width == 16)
  613. popts->data_bus_width = 2;
  614. else {
  615. panic("Error: primary sdram width %u is invalid!\n",
  616. pdimm[0].primary_sdram_width);
  617. }
  618. }
  619. #endif
  620. /* Choose burst length. */
  621. #if defined(CONFIG_FSL_DDR3)
  622. #if defined(CONFIG_E500MC)
  623. popts->OTF_burst_chop_en = 0; /* on-the-fly burst chop disable */
  624. popts->burst_length = DDR_BL8; /* Fixed 8-beat burst len */
  625. #else
  626. if ((popts->data_bus_width == 1) || (popts->data_bus_width == 2)) {
  627. /* 32-bit or 16-bit bus */
  628. popts->OTF_burst_chop_en = 0;
  629. popts->burst_length = DDR_BL8;
  630. } else {
  631. popts->OTF_burst_chop_en = 1; /* on-the-fly burst chop */
  632. popts->burst_length = DDR_OTF; /* on-the-fly BC4 and BL8 */
  633. }
  634. #endif
  635. #else
  636. popts->burst_length = DDR_BL4; /* has to be 4 for DDR2 */
  637. #endif
  638. /* Choose ddr controller address mirror mode */
  639. #if defined(CONFIG_FSL_DDR3)
  640. popts->mirrored_dimm = pdimm[0].mirrored_dimm;
  641. #endif
  642. /* Global Timing Parameters. */
  643. debug("mclk_ps = %u ps\n", get_memory_clk_period_ps());
  644. /* Pick a caslat override. */
  645. popts->cas_latency_override = 0;
  646. popts->cas_latency_override_value = 3;
  647. if (popts->cas_latency_override) {
  648. debug("using caslat override value = %u\n",
  649. popts->cas_latency_override_value);
  650. }
  651. /* Decide whether to use the computed derated latency */
  652. popts->use_derated_caslat = 0;
  653. /* Choose an additive latency. */
  654. popts->additive_latency_override = 0;
  655. popts->additive_latency_override_value = 3;
  656. if (popts->additive_latency_override) {
  657. debug("using additive latency override value = %u\n",
  658. popts->additive_latency_override_value);
  659. }
  660. /*
  661. * 2T_EN setting
  662. *
  663. * Factors to consider for 2T_EN:
  664. * - number of DIMMs installed
  665. * - number of components, number of active ranks
  666. * - how much time you want to spend playing around
  667. */
  668. popts->twoT_en = 0;
  669. popts->threeT_en = 0;
  670. /* for RDIMM, address parity enable */
  671. popts->ap_en = 1;
  672. /*
  673. * BSTTOPRE precharge interval
  674. *
  675. * Set this to 0 for global auto precharge
  676. *
  677. * FIXME: Should this be configured in picoseconds?
  678. * Why it should be in ps: better understanding of this
  679. * relative to actual DRAM timing parameters such as tRAS.
  680. * e.g. tRAS(min) = 40 ns
  681. */
  682. popts->bstopre = 0x100;
  683. /* Minimum CKE pulse width -- tCKE(MIN) */
  684. popts->tCKE_clock_pulse_width_ps
  685. = mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR);
  686. /*
  687. * Window for four activates -- tFAW
  688. *
  689. * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
  690. * FIXME: varies depending upon number of column addresses or data
  691. * FIXME: width, was considering looking at pdimm->primary_sdram_width
  692. */
  693. #if defined(CONFIG_FSL_DDR1)
  694. popts->tFAW_window_four_activates_ps = mclk_to_picos(1);
  695. #elif defined(CONFIG_FSL_DDR2)
  696. /*
  697. * x4/x8; some datasheets have 35000
  698. * x16 wide columns only? Use 50000?
  699. */
  700. popts->tFAW_window_four_activates_ps = 37500;
  701. #elif defined(CONFIG_FSL_DDR3)
  702. popts->tFAW_window_four_activates_ps = pdimm[0].tFAW_ps;
  703. #endif
  704. popts->zq_en = 0;
  705. popts->wrlvl_en = 0;
  706. #if defined(CONFIG_FSL_DDR3)
  707. /*
  708. * due to ddr3 dimm is fly-by topology
  709. * we suggest to enable write leveling to
  710. * meet the tQDSS under different loading.
  711. */
  712. popts->wrlvl_en = 1;
  713. popts->zq_en = 1;
  714. popts->wrlvl_override = 0;
  715. #endif
  716. /*
  717. * Check interleaving configuration from environment.
  718. * Please refer to doc/README.fsl-ddr for the detail.
  719. *
  720. * If memory controller interleaving is enabled, then the data
  721. * bus widths must be programmed identically for all memory controllers.
  722. *
  723. * XXX: Attempt to set all controllers to the same chip select
  724. * interleaving mode. It will do a best effort to get the
  725. * requested ranks interleaved together such that the result
  726. * should be a subset of the requested configuration.
  727. */
  728. #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
  729. if (hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf)) {
  730. if (pdimm[0].n_ranks == 0) {
  731. printf("There is no rank on CS0 for controller %d. Because only"
  732. " rank on CS0 and ranks chip-select interleaved with CS0"
  733. " are controller interleaved, force non memory "
  734. "controller interleaving\n", ctrl_num);
  735. popts->memctl_interleaving = 0;
  736. } else {
  737. popts->memctl_interleaving = 1;
  738. /*
  739. * test null first. if CONFIG_HWCONFIG is not defined
  740. * hwconfig_arg_cmp returns non-zero
  741. */
  742. if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  743. "null", buf)) {
  744. popts->memctl_interleaving = 0;
  745. debug("memory controller interleaving disabled.\n");
  746. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  747. "ctlr_intlv",
  748. "cacheline", buf))
  749. popts->memctl_interleaving_mode =
  750. FSL_DDR_CACHE_LINE_INTERLEAVING;
  751. else if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  752. "page", buf))
  753. popts->memctl_interleaving_mode =
  754. FSL_DDR_PAGE_INTERLEAVING;
  755. else if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  756. "bank", buf))
  757. popts->memctl_interleaving_mode =
  758. FSL_DDR_BANK_INTERLEAVING;
  759. else if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  760. "superbank", buf))
  761. popts->memctl_interleaving_mode =
  762. FSL_DDR_SUPERBANK_INTERLEAVING;
  763. else {
  764. popts->memctl_interleaving = 0;
  765. printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
  766. }
  767. }
  768. }
  769. #endif
  770. if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) &&
  771. (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) {
  772. /* test null first. if CONFIG_HWCONFIG is not defined,
  773. * hwconfig_subarg_cmp_f returns non-zero */
  774. if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  775. "null", buf))
  776. debug("bank interleaving disabled.\n");
  777. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  778. "cs0_cs1", buf))
  779. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
  780. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  781. "cs2_cs3", buf))
  782. popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
  783. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  784. "cs0_cs1_and_cs2_cs3", buf))
  785. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
  786. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  787. "cs0_cs1_cs2_cs3", buf))
  788. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
  789. else
  790. printf("hwconfig has unrecognized parameter for bank_intlv.\n");
  791. switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
  792. case FSL_DDR_CS0_CS1_CS2_CS3:
  793. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  794. if (pdimm[0].n_ranks < 4) {
  795. popts->ba_intlv_ctl = 0;
  796. printf("Not enough bank(chip-select) for "
  797. "CS0+CS1+CS2+CS3 on controller %d, "
  798. "force non-interleaving!\n", ctrl_num);
  799. }
  800. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  801. if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) {
  802. popts->ba_intlv_ctl = 0;
  803. printf("Not enough bank(chip-select) for "
  804. "CS0+CS1+CS2+CS3 on controller %d, "
  805. "force non-interleaving!\n", ctrl_num);
  806. }
  807. if (pdimm[0].capacity != pdimm[1].capacity) {
  808. popts->ba_intlv_ctl = 0;
  809. printf("Not identical DIMM size for "
  810. "CS0+CS1+CS2+CS3 on controller %d, "
  811. "force non-interleaving!\n", ctrl_num);
  812. }
  813. #endif
  814. break;
  815. case FSL_DDR_CS0_CS1:
  816. if (pdimm[0].n_ranks < 2) {
  817. popts->ba_intlv_ctl = 0;
  818. printf("Not enough bank(chip-select) for "
  819. "CS0+CS1 on controller %d, "
  820. "force non-interleaving!\n", ctrl_num);
  821. }
  822. break;
  823. case FSL_DDR_CS2_CS3:
  824. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  825. if (pdimm[0].n_ranks < 4) {
  826. popts->ba_intlv_ctl = 0;
  827. printf("Not enough bank(chip-select) for CS2+CS3 "
  828. "on controller %d, force non-interleaving!\n", ctrl_num);
  829. }
  830. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  831. if (pdimm[1].n_ranks < 2) {
  832. popts->ba_intlv_ctl = 0;
  833. printf("Not enough bank(chip-select) for CS2+CS3 "
  834. "on controller %d, force non-interleaving!\n", ctrl_num);
  835. }
  836. #endif
  837. break;
  838. case FSL_DDR_CS0_CS1_AND_CS2_CS3:
  839. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  840. if (pdimm[0].n_ranks < 4) {
  841. popts->ba_intlv_ctl = 0;
  842. printf("Not enough bank(CS) for CS0+CS1 and "
  843. "CS2+CS3 on controller %d, "
  844. "force non-interleaving!\n", ctrl_num);
  845. }
  846. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  847. if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) {
  848. popts->ba_intlv_ctl = 0;
  849. printf("Not enough bank(CS) for CS0+CS1 and "
  850. "CS2+CS3 on controller %d, "
  851. "force non-interleaving!\n", ctrl_num);
  852. }
  853. #endif
  854. break;
  855. default:
  856. popts->ba_intlv_ctl = 0;
  857. break;
  858. }
  859. }
  860. if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf)) {
  861. if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf))
  862. popts->addr_hash = 0;
  863. else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash",
  864. "true", buf))
  865. popts->addr_hash = 1;
  866. }
  867. if (pdimm[0].n_ranks == 4)
  868. popts->quad_rank_present = 1;
  869. ddr_freq = get_ddr_freq(0) / 1000000;
  870. if (popts->registered_dimm_en) {
  871. popts->rcw_override = 1;
  872. popts->rcw_1 = 0x000a5a00;
  873. if (ddr_freq <= 800)
  874. popts->rcw_2 = 0x00000000;
  875. else if (ddr_freq <= 1066)
  876. popts->rcw_2 = 0x00100000;
  877. else if (ddr_freq <= 1333)
  878. popts->rcw_2 = 0x00200000;
  879. else
  880. popts->rcw_2 = 0x00300000;
  881. }
  882. fsl_ddr_board_options(popts, pdimm, ctrl_num);
  883. return 0;
  884. }
  885. void check_interleaving_options(fsl_ddr_info_t *pinfo)
  886. {
  887. int i, j, check_n_ranks, intlv_fixed = 0;
  888. unsigned long long check_rank_density;
  889. /*
  890. * Check if all controllers are configured for memory
  891. * controller interleaving. Identical dimms are recommended. At least
  892. * the size should be checked.
  893. */
  894. j = 0;
  895. check_n_ranks = pinfo->dimm_params[0][0].n_ranks;
  896. check_rank_density = pinfo->dimm_params[0][0].rank_density;
  897. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  898. if ((pinfo->memctl_opts[i].memctl_interleaving) && \
  899. (check_rank_density == pinfo->dimm_params[i][0].rank_density) && \
  900. (check_n_ranks == pinfo->dimm_params[i][0].n_ranks)) {
  901. j++;
  902. }
  903. }
  904. if (j != CONFIG_NUM_DDR_CONTROLLERS) {
  905. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
  906. if (pinfo->memctl_opts[i].memctl_interleaving) {
  907. pinfo->memctl_opts[i].memctl_interleaving = 0;
  908. intlv_fixed = 1;
  909. }
  910. if (intlv_fixed)
  911. printf("Not all DIMMs are identical in size. "
  912. "Memory controller interleaving disabled.\n");
  913. }
  914. }
  915. int fsl_use_spd(void)
  916. {
  917. int use_spd = 0;
  918. #ifdef CONFIG_DDR_SPD
  919. char buffer[HWCONFIG_BUFFER_SIZE];
  920. char *buf = NULL;
  921. /*
  922. * Extract hwconfig from environment since we have not properly setup
  923. * the environment but need it for ddr config params
  924. */
  925. if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0)
  926. buf = buffer;
  927. /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
  928. if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) {
  929. if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf))
  930. use_spd = 1;
  931. else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram",
  932. "fixed", buf))
  933. use_spd = 0;
  934. else
  935. use_spd = 1;
  936. } else
  937. use_spd = 1;
  938. #endif
  939. return use_spd;
  940. }