options.c 19 KB

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