options.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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. /*
  388. * check first dimm for primary sdram width
  389. * presuming all dimms are similar
  390. * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit
  391. */
  392. if (pdimm[0].primary_sdram_width == 64)
  393. popts->data_bus_width = 0;
  394. else if (pdimm[0].primary_sdram_width == 32)
  395. popts->data_bus_width = 1;
  396. else if (pdimm[0].primary_sdram_width == 16)
  397. popts->data_bus_width = 2;
  398. else
  399. panic("Error: invalid primary sdram width!\n");
  400. /* Choose burst length. */
  401. #if defined(CONFIG_FSL_DDR3)
  402. #if defined(CONFIG_E500MC)
  403. popts->OTF_burst_chop_en = 0; /* on-the-fly burst chop disable */
  404. popts->burst_length = DDR_BL8; /* Fixed 8-beat burst len */
  405. #else
  406. if ((popts->data_bus_width == 1) || (popts->data_bus_width == 2)) {
  407. /* 32-bit or 16-bit bus */
  408. popts->OTF_burst_chop_en = 0;
  409. popts->burst_length = DDR_BL8;
  410. } else {
  411. popts->OTF_burst_chop_en = 1; /* on-the-fly burst chop */
  412. popts->burst_length = DDR_OTF; /* on-the-fly BC4 and BL8 */
  413. }
  414. #endif
  415. #else
  416. popts->burst_length = DDR_BL4; /* has to be 4 for DDR2 */
  417. #endif
  418. /* Choose ddr controller address mirror mode */
  419. #if defined(CONFIG_FSL_DDR3)
  420. popts->mirrored_dimm = pdimm[0].mirrored_dimm;
  421. #endif
  422. /* Global Timing Parameters. */
  423. debug("mclk_ps = %u ps\n", get_memory_clk_period_ps());
  424. /* Pick a caslat override. */
  425. popts->cas_latency_override = 0;
  426. popts->cas_latency_override_value = 3;
  427. if (popts->cas_latency_override) {
  428. debug("using caslat override value = %u\n",
  429. popts->cas_latency_override_value);
  430. }
  431. /* Decide whether to use the computed derated latency */
  432. popts->use_derated_caslat = 0;
  433. /* Choose an additive latency. */
  434. popts->additive_latency_override = 0;
  435. popts->additive_latency_override_value = 3;
  436. if (popts->additive_latency_override) {
  437. debug("using additive latency override value = %u\n",
  438. popts->additive_latency_override_value);
  439. }
  440. /*
  441. * 2T_EN setting
  442. *
  443. * Factors to consider for 2T_EN:
  444. * - number of DIMMs installed
  445. * - number of components, number of active ranks
  446. * - how much time you want to spend playing around
  447. */
  448. popts->twoT_en = 0;
  449. popts->threeT_en = 0;
  450. /* for RDIMM, address parity enable */
  451. popts->ap_en = 1;
  452. /*
  453. * BSTTOPRE precharge interval
  454. *
  455. * Set this to 0 for global auto precharge
  456. *
  457. * FIXME: Should this be configured in picoseconds?
  458. * Why it should be in ps: better understanding of this
  459. * relative to actual DRAM timing parameters such as tRAS.
  460. * e.g. tRAS(min) = 40 ns
  461. */
  462. popts->bstopre = 0x100;
  463. /* Minimum CKE pulse width -- tCKE(MIN) */
  464. popts->tCKE_clock_pulse_width_ps
  465. = mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR);
  466. /*
  467. * Window for four activates -- tFAW
  468. *
  469. * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
  470. * FIXME: varies depending upon number of column addresses or data
  471. * FIXME: width, was considering looking at pdimm->primary_sdram_width
  472. */
  473. #if defined(CONFIG_FSL_DDR1)
  474. popts->tFAW_window_four_activates_ps = mclk_to_picos(1);
  475. #elif defined(CONFIG_FSL_DDR2)
  476. /*
  477. * x4/x8; some datasheets have 35000
  478. * x16 wide columns only? Use 50000?
  479. */
  480. popts->tFAW_window_four_activates_ps = 37500;
  481. #elif defined(CONFIG_FSL_DDR3)
  482. popts->tFAW_window_four_activates_ps = pdimm[0].tFAW_ps;
  483. #endif
  484. popts->zq_en = 0;
  485. popts->wrlvl_en = 0;
  486. #if defined(CONFIG_FSL_DDR3)
  487. /*
  488. * due to ddr3 dimm is fly-by topology
  489. * we suggest to enable write leveling to
  490. * meet the tQDSS under different loading.
  491. */
  492. popts->wrlvl_en = 1;
  493. popts->zq_en = 1;
  494. popts->wrlvl_override = 0;
  495. #endif
  496. /*
  497. * Check interleaving configuration from environment.
  498. * Please refer to doc/README.fsl-ddr for the detail.
  499. *
  500. * If memory controller interleaving is enabled, then the data
  501. * bus widths must be programmed identically for all memory controllers.
  502. *
  503. * XXX: Attempt to set all controllers to the same chip select
  504. * interleaving mode. It will do a best effort to get the
  505. * requested ranks interleaved together such that the result
  506. * should be a subset of the requested configuration.
  507. */
  508. #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
  509. if (hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf)) {
  510. if (pdimm[0].n_ranks == 0) {
  511. printf("There is no rank on CS0 for controller %d. Because only"
  512. " rank on CS0 and ranks chip-select interleaved with CS0"
  513. " are controller interleaved, force non memory "
  514. "controller interleaving\n", ctrl_num);
  515. popts->memctl_interleaving = 0;
  516. } else {
  517. popts->memctl_interleaving = 1;
  518. /*
  519. * test null first. if CONFIG_HWCONFIG is not defined
  520. * hwconfig_arg_cmp returns non-zero
  521. */
  522. if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  523. "null", buf)) {
  524. popts->memctl_interleaving = 0;
  525. debug("memory controller interleaving disabled.\n");
  526. } else if (hwconfig_subarg_cmp_f("fsl_ddr",
  527. "ctlr_intlv",
  528. "cacheline", buf))
  529. popts->memctl_interleaving_mode =
  530. FSL_DDR_CACHE_LINE_INTERLEAVING;
  531. else if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  532. "page", buf))
  533. popts->memctl_interleaving_mode =
  534. FSL_DDR_PAGE_INTERLEAVING;
  535. else if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  536. "bank", buf))
  537. popts->memctl_interleaving_mode =
  538. FSL_DDR_BANK_INTERLEAVING;
  539. else if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
  540. "superbank", buf))
  541. popts->memctl_interleaving_mode =
  542. FSL_DDR_SUPERBANK_INTERLEAVING;
  543. else {
  544. popts->memctl_interleaving = 0;
  545. printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
  546. }
  547. }
  548. }
  549. #endif
  550. if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) &&
  551. (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) {
  552. /* test null first. if CONFIG_HWCONFIG is not defined,
  553. * hwconfig_subarg_cmp_f returns non-zero */
  554. if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  555. "null", buf))
  556. debug("bank interleaving disabled.\n");
  557. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  558. "cs0_cs1", buf))
  559. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
  560. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  561. "cs2_cs3", buf))
  562. popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
  563. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  564. "cs0_cs1_and_cs2_cs3", buf))
  565. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
  566. else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
  567. "cs0_cs1_cs2_cs3", buf))
  568. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
  569. else
  570. printf("hwconfig has unrecognized parameter for bank_intlv.\n");
  571. switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
  572. case FSL_DDR_CS0_CS1_CS2_CS3:
  573. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  574. if (pdimm[0].n_ranks < 4) {
  575. popts->ba_intlv_ctl = 0;
  576. printf("Not enough bank(chip-select) for "
  577. "CS0+CS1+CS2+CS3 on controller %d, "
  578. "force non-interleaving!\n", ctrl_num);
  579. }
  580. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  581. if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) {
  582. popts->ba_intlv_ctl = 0;
  583. printf("Not enough bank(chip-select) for "
  584. "CS0+CS1+CS2+CS3 on controller %d, "
  585. "force non-interleaving!\n", ctrl_num);
  586. }
  587. if (pdimm[0].capacity != pdimm[1].capacity) {
  588. popts->ba_intlv_ctl = 0;
  589. printf("Not identical DIMM size for "
  590. "CS0+CS1+CS2+CS3 on controller %d, "
  591. "force non-interleaving!\n", ctrl_num);
  592. }
  593. #endif
  594. break;
  595. case FSL_DDR_CS0_CS1:
  596. if (pdimm[0].n_ranks < 2) {
  597. popts->ba_intlv_ctl = 0;
  598. printf("Not enough bank(chip-select) for "
  599. "CS0+CS1 on controller %d, "
  600. "force non-interleaving!\n", ctrl_num);
  601. }
  602. break;
  603. case FSL_DDR_CS2_CS3:
  604. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  605. if (pdimm[0].n_ranks < 4) {
  606. popts->ba_intlv_ctl = 0;
  607. printf("Not enough bank(chip-select) for CS2+CS3 "
  608. "on controller %d, force non-interleaving!\n", ctrl_num);
  609. }
  610. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  611. if (pdimm[1].n_ranks < 2) {
  612. popts->ba_intlv_ctl = 0;
  613. printf("Not enough bank(chip-select) for CS2+CS3 "
  614. "on controller %d, force non-interleaving!\n", ctrl_num);
  615. }
  616. #endif
  617. break;
  618. case FSL_DDR_CS0_CS1_AND_CS2_CS3:
  619. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  620. if (pdimm[0].n_ranks < 4) {
  621. popts->ba_intlv_ctl = 0;
  622. printf("Not enough bank(CS) for CS0+CS1 and "
  623. "CS2+CS3 on controller %d, "
  624. "force non-interleaving!\n", ctrl_num);
  625. }
  626. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  627. if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) {
  628. popts->ba_intlv_ctl = 0;
  629. printf("Not enough bank(CS) for CS0+CS1 and "
  630. "CS2+CS3 on controller %d, "
  631. "force non-interleaving!\n", ctrl_num);
  632. }
  633. #endif
  634. break;
  635. default:
  636. popts->ba_intlv_ctl = 0;
  637. break;
  638. }
  639. }
  640. if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf)) {
  641. if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf))
  642. popts->addr_hash = 0;
  643. else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash",
  644. "true", buf))
  645. popts->addr_hash = 1;
  646. }
  647. if (pdimm[0].n_ranks == 4)
  648. popts->quad_rank_present = 1;
  649. fsl_ddr_board_options(popts, pdimm, ctrl_num);
  650. return 0;
  651. }
  652. void check_interleaving_options(fsl_ddr_info_t *pinfo)
  653. {
  654. int i, j, check_n_ranks, intlv_fixed = 0;
  655. unsigned long long check_rank_density;
  656. /*
  657. * Check if all controllers are configured for memory
  658. * controller interleaving. Identical dimms are recommended. At least
  659. * the size should be checked.
  660. */
  661. j = 0;
  662. check_n_ranks = pinfo->dimm_params[0][0].n_ranks;
  663. check_rank_density = pinfo->dimm_params[0][0].rank_density;
  664. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  665. if ((pinfo->memctl_opts[i].memctl_interleaving) && \
  666. (check_rank_density == pinfo->dimm_params[i][0].rank_density) && \
  667. (check_n_ranks == pinfo->dimm_params[i][0].n_ranks)) {
  668. j++;
  669. }
  670. }
  671. if (j != CONFIG_NUM_DDR_CONTROLLERS) {
  672. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
  673. if (pinfo->memctl_opts[i].memctl_interleaving) {
  674. pinfo->memctl_opts[i].memctl_interleaving = 0;
  675. intlv_fixed = 1;
  676. }
  677. if (intlv_fixed)
  678. printf("Not all DIMMs are identical in size. "
  679. "Memory controller interleaving disabled.\n");
  680. }
  681. }
  682. int fsl_use_spd(void)
  683. {
  684. int use_spd = 0;
  685. #ifdef CONFIG_DDR_SPD
  686. char buffer[HWCONFIG_BUFFER_SIZE];
  687. char *buf = NULL;
  688. /*
  689. * Extract hwconfig from environment since we have not properly setup
  690. * the environment but need it for ddr config params
  691. */
  692. if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0)
  693. buf = buffer;
  694. /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
  695. if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) {
  696. if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf))
  697. use_spd = 1;
  698. else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram",
  699. "fixed", buf))
  700. use_spd = 0;
  701. else
  702. use_spd = 1;
  703. } else
  704. use_spd = 1;
  705. #endif
  706. return use_spd;
  707. }