options.c 19 KB

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