options.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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. typedef struct {
  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. } dynamic_odt_t;
  30. static const dynamic_odt_t 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 dynamic_odt_t 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 dynamic_odt_t 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 dynamic_odt_t 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 dynamic_odt_t 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 dynamic_odt_t 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 dynamic_odt_t 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 dynamic_odt_t 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 dynamic_odt_t 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 dynamic_odt_t 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 dynamic_odt_t 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 dynamic_odt_t 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. unsigned int populate_memctl_options(int all_DIMMs_registered,
  248. memctl_options_t *popts,
  249. dimm_params_t *pdimm,
  250. unsigned int ctrl_num)
  251. {
  252. unsigned int i;
  253. char buffer[HWCONFIG_BUFFER_SIZE];
  254. char *buf = NULL;
  255. const dynamic_odt_t *pdodt = odt_unknown;
  256. /*
  257. * Extract hwconfig from environment since we have not properly setup
  258. * the environment but need it for ddr config params
  259. */
  260. if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0)
  261. buf = buffer;
  262. /* Chip select options. */
  263. if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) {
  264. switch (pdimm[0].n_ranks) {
  265. case 1:
  266. pdodt = single_S;
  267. break;
  268. case 2:
  269. pdodt = single_D;
  270. break;
  271. case 4:
  272. pdodt = single_Q;
  273. break;
  274. }
  275. } else if (CONFIG_DIMM_SLOTS_PER_CTLR == 2) {
  276. switch (pdimm[0].n_ranks) {
  277. case 2:
  278. switch (pdimm[1].n_ranks) {
  279. case 2:
  280. pdodt = dual_DD;
  281. break;
  282. case 1:
  283. pdodt = dual_DS;
  284. break;
  285. case 0:
  286. pdodt = dual_D0;
  287. break;
  288. }
  289. break;
  290. case 1:
  291. switch (pdimm[1].n_ranks) {
  292. case 2:
  293. pdodt = dual_SD;
  294. break;
  295. case 1:
  296. pdodt = dual_SS;
  297. break;
  298. case 0:
  299. pdodt = dual_S0;
  300. break;
  301. }
  302. break;
  303. case 0:
  304. switch (pdimm[1].n_ranks) {
  305. case 2:
  306. pdodt = dual_0D;
  307. break;
  308. case 1:
  309. pdodt = dual_0S;
  310. break;
  311. }
  312. break;
  313. }
  314. }
  315. /* Pick chip-select local options. */
  316. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  317. #if defined(CONFIG_FSL_DDR3)
  318. popts->cs_local_opts[i].odt_rd_cfg = pdodt[i].odt_rd_cfg;
  319. popts->cs_local_opts[i].odt_wr_cfg = pdodt[i].odt_wr_cfg;
  320. popts->cs_local_opts[i].odt_rtt_norm = pdodt[i].odt_rtt_norm;
  321. popts->cs_local_opts[i].odt_rtt_wr = pdodt[i].odt_rtt_wr;
  322. #else
  323. popts->cs_local_opts[i].odt_rd_cfg = FSL_DDR_ODT_NEVER;
  324. popts->cs_local_opts[i].odt_wr_cfg = FSL_DDR_ODT_CS;
  325. #endif
  326. popts->cs_local_opts[i].auto_precharge = 0;
  327. }
  328. /* Pick interleaving mode. */
  329. /*
  330. * 0 = no interleaving
  331. * 1 = interleaving between 2 controllers
  332. */
  333. popts->memctl_interleaving = 0;
  334. /*
  335. * 0 = cacheline
  336. * 1 = page
  337. * 2 = (logical) bank
  338. * 3 = superbank (only if CS interleaving is enabled)
  339. */
  340. popts->memctl_interleaving_mode = 0;
  341. /*
  342. * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
  343. * 1: page: bit to the left of the column bits selects the memctl
  344. * 2: bank: bit to the left of the bank bits selects the memctl
  345. * 3: superbank: bit to the left of the chip select selects the memctl
  346. *
  347. * NOTE: ba_intlv (rank interleaving) is independent of memory
  348. * controller interleaving; it is only within a memory controller.
  349. * Must use superbank interleaving if rank interleaving is used and
  350. * memory controller interleaving is enabled.
  351. */
  352. /*
  353. * 0 = no
  354. * 0x40 = CS0,CS1
  355. * 0x20 = CS2,CS3
  356. * 0x60 = CS0,CS1 + CS2,CS3
  357. * 0x04 = CS0,CS1,CS2,CS3
  358. */
  359. popts->ba_intlv_ctl = 0;
  360. /* Memory Organization Parameters */
  361. popts->registered_dimm_en = all_DIMMs_registered;
  362. /* Operational Mode Paramters */
  363. /* Pick ECC modes */
  364. popts->ECC_mode = 0; /* 0 = disabled, 1 = enabled */
  365. #ifdef CONFIG_DDR_ECC
  366. if (hwconfig_sub_f("fsl_ddr", "ecc", buf)) {
  367. if (hwconfig_subarg_cmp_f("fsl_ddr", "ecc", "on", buf))
  368. popts->ECC_mode = 1;
  369. } else
  370. popts->ECC_mode = 1;
  371. #endif
  372. popts->ECC_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */
  373. /*
  374. * Choose DQS config
  375. * 0 for DDR1
  376. * 1 for DDR2
  377. */
  378. #if defined(CONFIG_FSL_DDR1)
  379. popts->DQS_config = 0;
  380. #elif defined(CONFIG_FSL_DDR2) || defined(CONFIG_FSL_DDR3)
  381. popts->DQS_config = 1;
  382. #endif
  383. /* Choose self-refresh during sleep. */
  384. popts->self_refresh_in_sleep = 1;
  385. /* Choose dynamic power management mode. */
  386. popts->dynamic_power = 0;
  387. /* 0 = 64-bit, 1 = 32-bit, 2 = 16-bit */
  388. popts->data_bus_width = 0;
  389. /* Choose burst length. */
  390. #if defined(CONFIG_FSL_DDR3)
  391. #if defined(CONFIG_E500MC)
  392. popts->OTF_burst_chop_en = 0; /* on-the-fly burst chop disable */
  393. popts->burst_length = DDR_BL8; /* Fixed 8-beat burst len */
  394. #else
  395. popts->OTF_burst_chop_en = 1; /* on-the-fly burst chop */
  396. popts->burst_length = DDR_OTF; /* on-the-fly BC4 and BL8 */
  397. #endif
  398. #else
  399. popts->burst_length = DDR_BL4; /* has to be 4 for DDR2 */
  400. #endif
  401. /* Choose ddr controller address mirror mode */
  402. #if defined(CONFIG_FSL_DDR3)
  403. popts->mirrored_dimm = pdimm[0].mirrored_dimm;
  404. #endif
  405. /* Global Timing Parameters. */
  406. debug("mclk_ps = %u ps\n", get_memory_clk_period_ps());
  407. /* Pick a caslat override. */
  408. popts->cas_latency_override = 0;
  409. popts->cas_latency_override_value = 3;
  410. if (popts->cas_latency_override) {
  411. debug("using caslat override value = %u\n",
  412. popts->cas_latency_override_value);
  413. }
  414. /* Decide whether to use the computed derated latency */
  415. popts->use_derated_caslat = 0;
  416. /* Choose an additive latency. */
  417. popts->additive_latency_override = 0;
  418. popts->additive_latency_override_value = 3;
  419. if (popts->additive_latency_override) {
  420. debug("using additive latency override value = %u\n",
  421. popts->additive_latency_override_value);
  422. }
  423. /*
  424. * 2T_EN setting
  425. *
  426. * Factors to consider for 2T_EN:
  427. * - number of DIMMs installed
  428. * - number of components, number of active ranks
  429. * - how much time you want to spend playing around
  430. */
  431. popts->twoT_en = 0;
  432. popts->threeT_en = 0;
  433. /* for RDIMM, address parity enable */
  434. popts->ap_en = 1;
  435. /*
  436. * BSTTOPRE precharge interval
  437. *
  438. * Set this to 0 for global auto precharge
  439. *
  440. * FIXME: Should this be configured in picoseconds?
  441. * Why it should be in ps: better understanding of this
  442. * relative to actual DRAM timing parameters such as tRAS.
  443. * e.g. tRAS(min) = 40 ns
  444. */
  445. popts->bstopre = 0x100;
  446. /* Minimum CKE pulse width -- tCKE(MIN) */
  447. popts->tCKE_clock_pulse_width_ps
  448. = mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR);
  449. /*
  450. * Window for four activates -- tFAW
  451. *
  452. * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
  453. * FIXME: varies depending upon number of column addresses or data
  454. * FIXME: width, was considering looking at pdimm->primary_sdram_width
  455. */
  456. #if defined(CONFIG_FSL_DDR1)
  457. popts->tFAW_window_four_activates_ps = mclk_to_picos(1);
  458. #elif defined(CONFIG_FSL_DDR2)
  459. /*
  460. * x4/x8; some datasheets have 35000
  461. * x16 wide columns only? Use 50000?
  462. */
  463. popts->tFAW_window_four_activates_ps = 37500;
  464. #elif defined(CONFIG_FSL_DDR3)
  465. popts->tFAW_window_four_activates_ps = pdimm[0].tFAW_ps;
  466. #endif
  467. popts->zq_en = 0;
  468. popts->wrlvl_en = 0;
  469. #if defined(CONFIG_FSL_DDR3)
  470. /*
  471. * due to ddr3 dimm is fly-by topology
  472. * we suggest to enable write leveling to
  473. * meet the tQDSS under different loading.
  474. */
  475. popts->wrlvl_en = 1;
  476. popts->zq_en = 1;
  477. popts->wrlvl_override = 0;
  478. #endif
  479. /*
  480. * Check interleaving configuration from environment.
  481. * Please refer to doc/README.fsl-ddr for the detail.
  482. *
  483. * If memory controller interleaving is enabled, then the data
  484. * bus widths must be programmed identically for all memory controllers.
  485. *
  486. * XXX: Attempt to set all controllers to the same chip select
  487. * interleaving mode. It will do a best effort to get the
  488. * requested ranks interleaved together such that the result
  489. * should be a subset of the requested configuration.
  490. */
  491. #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
  492. if (hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf)) {
  493. if (pdimm[0].n_ranks == 0) {
  494. printf("There is no rank on CS0 for controller %d. Because only"
  495. " rank on CS0 and ranks chip-select interleaved with CS0"
  496. " are controller interleaved, force non memory "
  497. "controller interleaving\n", ctrl_num);
  498. popts->memctl_interleaving = 0;
  499. } else {
  500. popts->memctl_interleaving = 1;
  501. /*
  502. * test null first. if CONFIG_HWCONFIG is not defined
  503. * hwconfig_arg_cmp returns non-zero
  504. */
  505. if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  506. "null", buf)) {
  507. popts->memctl_interleaving = 0;
  508. debug("memory controller interleaving disabled.\n");
  509. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  510. "ctlr_intlv",
  511. "cacheline", buf))
  512. popts->memctl_interleaving_mode =
  513. FSL_DDR_CACHE_LINE_INTERLEAVING;
  514. else if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  515. "page", buf))
  516. popts->memctl_interleaving_mode =
  517. FSL_DDR_PAGE_INTERLEAVING;
  518. else if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  519. "bank", buf))
  520. popts->memctl_interleaving_mode =
  521. FSL_DDR_BANK_INTERLEAVING;
  522. else if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  523. "superbank", buf))
  524. popts->memctl_interleaving_mode =
  525. FSL_DDR_SUPERBANK_INTERLEAVING;
  526. else {
  527. popts->memctl_interleaving = 0;
  528. printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
  529. }
  530. }
  531. }
  532. #endif
  533. if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) &&
  534. (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) {
  535. /* test null first. if CONFIG_HWCONFIG is not defined,
  536. * hwconfig_subarg_cmp_f returns non-zero */
  537. if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  538. "null", buf))
  539. debug("bank interleaving disabled.\n");
  540. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  541. "cs0_cs1", buf))
  542. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
  543. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  544. "cs2_cs3", buf))
  545. popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
  546. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  547. "cs0_cs1_and_cs2_cs3", buf))
  548. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
  549. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  550. "cs0_cs1_cs2_cs3", buf))
  551. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
  552. else
  553. printf("hwconfig has unrecognized parameter for bank_intlv.\n");
  554. switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
  555. case FSL_DDR_CS0_CS1_CS2_CS3:
  556. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  557. if (pdimm[0].n_ranks < 4) {
  558. popts->ba_intlv_ctl = 0;
  559. printf("Not enough bank(chip-select) for "
  560. "CS0+CS1+CS2+CS3 on controller %d, "
  561. "force non-interleaving!\n", ctrl_num);
  562. }
  563. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  564. if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) {
  565. popts->ba_intlv_ctl = 0;
  566. printf("Not enough bank(chip-select) for "
  567. "CS0+CS1+CS2+CS3 on controller %d, "
  568. "force non-interleaving!\n", ctrl_num);
  569. }
  570. if (pdimm[0].capacity != pdimm[1].capacity) {
  571. popts->ba_intlv_ctl = 0;
  572. printf("Not identical DIMM size for "
  573. "CS0+CS1+CS2+CS3 on controller %d, "
  574. "force non-interleaving!\n", ctrl_num);
  575. }
  576. #endif
  577. break;
  578. case FSL_DDR_CS0_CS1:
  579. if (pdimm[0].n_ranks < 2) {
  580. popts->ba_intlv_ctl = 0;
  581. printf("Not enough bank(chip-select) for "
  582. "CS0+CS1 on controller %d, "
  583. "force non-interleaving!\n", ctrl_num);
  584. }
  585. break;
  586. case FSL_DDR_CS2_CS3:
  587. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  588. if (pdimm[0].n_ranks < 4) {
  589. popts->ba_intlv_ctl = 0;
  590. printf("Not enough bank(chip-select) for CS2+CS3 "
  591. "on controller %d, force non-interleaving!\n", ctrl_num);
  592. }
  593. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  594. if (pdimm[1].n_ranks < 2) {
  595. popts->ba_intlv_ctl = 0;
  596. printf("Not enough bank(chip-select) for CS2+CS3 "
  597. "on controller %d, force non-interleaving!\n", ctrl_num);
  598. }
  599. #endif
  600. break;
  601. case FSL_DDR_CS0_CS1_AND_CS2_CS3:
  602. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  603. if (pdimm[0].n_ranks < 4) {
  604. popts->ba_intlv_ctl = 0;
  605. printf("Not enough bank(CS) for CS0+CS1 and "
  606. "CS2+CS3 on controller %d, "
  607. "force non-interleaving!\n", ctrl_num);
  608. }
  609. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  610. if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) {
  611. popts->ba_intlv_ctl = 0;
  612. printf("Not enough bank(CS) for CS0+CS1 and "
  613. "CS2+CS3 on controller %d, "
  614. "force non-interleaving!\n", ctrl_num);
  615. }
  616. #endif
  617. break;
  618. default:
  619. popts->ba_intlv_ctl = 0;
  620. break;
  621. }
  622. }
  623. if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf)) {
  624. if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf))
  625. popts->addr_hash = 0;
  626. else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash",
  627. "true", buf))
  628. popts->addr_hash = 1;
  629. }
  630. if (pdimm[0].n_ranks == 4)
  631. popts->quad_rank_present = 1;
  632. fsl_ddr_board_options(popts, pdimm, ctrl_num);
  633. return 0;
  634. }
  635. void check_interleaving_options(fsl_ddr_info_t *pinfo)
  636. {
  637. int i, j, check_n_ranks, intlv_fixed = 0;
  638. unsigned long long check_rank_density;
  639. /*
  640. * Check if all controllers are configured for memory
  641. * controller interleaving. Identical dimms are recommended. At least
  642. * the size should be checked.
  643. */
  644. j = 0;
  645. check_n_ranks = pinfo->dimm_params[0][0].n_ranks;
  646. check_rank_density = pinfo->dimm_params[0][0].rank_density;
  647. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  648. if ((pinfo->memctl_opts[i].memctl_interleaving) && \
  649. (check_rank_density == pinfo->dimm_params[i][0].rank_density) && \
  650. (check_n_ranks == pinfo->dimm_params[i][0].n_ranks)) {
  651. j++;
  652. }
  653. }
  654. if (j != CONFIG_NUM_DDR_CONTROLLERS) {
  655. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
  656. if (pinfo->memctl_opts[i].memctl_interleaving) {
  657. pinfo->memctl_opts[i].memctl_interleaving = 0;
  658. intlv_fixed = 1;
  659. }
  660. if (intlv_fixed)
  661. printf("Not all DIMMs are identical in size. "
  662. "Memory controller interleaving disabled.\n");
  663. }
  664. }
  665. int fsl_use_spd(void)
  666. {
  667. int use_spd = 0;
  668. #ifdef CONFIG_DDR_SPD
  669. char buffer[HWCONFIG_BUFFER_SIZE];
  670. char *buf = NULL;
  671. /*
  672. * Extract hwconfig from environment since we have not properly setup
  673. * the environment but need it for ddr config params
  674. */
  675. if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0)
  676. buf = buffer;
  677. /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
  678. if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) {
  679. if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf))
  680. use_spd = 1;
  681. else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram",
  682. "fixed", buf))
  683. use_spd = 0;
  684. else
  685. use_spd = 1;
  686. } else
  687. use_spd = 1;
  688. #endif
  689. return use_spd;
  690. }