options.c 19 KB

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