ddr_init.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright 2018-2022 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <string.h>
  9. #include <common/debug.h>
  10. #include <ddr.h>
  11. #include <lib/utils.h>
  12. #include <errata.h>
  13. #include <platform_def.h>
  14. #ifdef CONFIG_STATIC_DDR
  15. const struct ddr_cfg_regs static_1600 = {
  16. .cs[0].config = U(0x80010412),
  17. .cs[0].bnds = U(0x7F),
  18. .sdram_cfg[0] = U(0xE50C0008),
  19. .sdram_cfg[1] = U(0x00401010),
  20. .sdram_cfg[2] = U(0x1),
  21. .timing_cfg[0] = U(0xFA550018),
  22. .timing_cfg[1] = U(0xBAB40C52),
  23. .timing_cfg[2] = U(0x0048C11C),
  24. .timing_cfg[3] = U(0x01111000),
  25. .timing_cfg[4] = U(0x00000002),
  26. .timing_cfg[5] = U(0x03401400),
  27. .timing_cfg[6] = U(0x0),
  28. .timing_cfg[7] = U(0x23300000),
  29. .timing_cfg[8] = U(0x02116600),
  30. .timing_cfg[9] = U(0x0),
  31. .dq_map[0] = U(0x0),
  32. .dq_map[1] = U(0x0),
  33. .dq_map[2] = U(0x0),
  34. .dq_map[3] = U(0x0),
  35. .sdram_mode[0] = U(0x01010210),
  36. .sdram_mode[1] = U(0x0),
  37. .sdram_mode[8] = U(0x00000500),
  38. .sdram_mode[9] = U(0x04000000),
  39. .interval = U(0x18600618),
  40. .zq_cntl = U(0x8A090705),
  41. .ddr_sr_cntr = U(0x0),
  42. .clk_cntl = U(0x2000000),
  43. .cdr[0] = U(0x80040000),
  44. .cdr[1] = U(0xC1),
  45. .wrlvl_cntl[0] = U(0x86550607),
  46. .wrlvl_cntl[1] = U(0x07070708),
  47. .wrlvl_cntl[2] = U(0x0808088),
  48. };
  49. long long board_static_ddr(struct ddr_info *priv)
  50. {
  51. memcpy(&priv->ddr_reg, &static_1600, sizeof(static_1600));
  52. return 0x80000000ULL;
  53. }
  54. #else /* ifndef CONFIG_STATIC_DDR */
  55. static const struct rc_timing rcz[] = {
  56. {U(1600), U(8), U(7)},
  57. {U(2100), U(8), U(7)},
  58. {}
  59. };
  60. static const struct board_timing ram[] = {
  61. {U(0x1f), rcz, U(0x01010101), U(0x01010101)},
  62. };
  63. int ddr_board_options(struct ddr_info *priv)
  64. {
  65. int ret;
  66. struct memctl_opt *popts = &priv->opt;
  67. ret = cal_board_params(priv, ram, ARRAY_SIZE(ram));
  68. if (ret != 0) {
  69. return ret;
  70. }
  71. popts->bstopre = 0;
  72. popts->half_strength_drive_en = 1;
  73. popts->cpo_sample = U(0x46);
  74. popts->ddr_cdr1 = DDR_CDR1_DHC_EN | DDR_CDR1_ODT(DDR_CDR_ODT_50ohm);
  75. popts->ddr_cdr2 = DDR_CDR2_ODT(DDR_CDR_ODT_50ohm) |
  76. DDR_CDR2_VREF_TRAIN_EN;
  77. popts->output_driver_impedance = 1;
  78. return 0;
  79. }
  80. /* DDR model number: MT40A512M16JY-083E:B */
  81. struct dimm_params ddr_raw_timing = {
  82. .n_ranks = U(1),
  83. .rank_density = ULL(4294967296),
  84. .capacity = ULL(4294967296),
  85. .primary_sdram_width = U(64),
  86. .ec_sdram_width = U(8),
  87. .rdimm = U(0),
  88. .mirrored_dimm = U(0),
  89. .n_row_addr = U(16),
  90. .n_col_addr = U(10),
  91. .bank_group_bits = U(1),
  92. .edc_config = U(2),
  93. .burst_lengths_bitmask = U(0x0c),
  94. .tckmin_x_ps = 750,
  95. .tckmax_ps = 1900,
  96. .caslat_x = U(0x0001FFE00),
  97. .taa_ps = 13500,
  98. .trcd_ps = 13500,
  99. .trp_ps = 13500,
  100. .tras_ps = 33000,
  101. .trc_ps = 46500,
  102. .twr_ps = 15000,
  103. .trfc1_ps = 350000,
  104. .trfc2_ps = 260000,
  105. .trfc4_ps = 160000,
  106. .tfaw_ps = 30000,
  107. .trrds_ps = 5300,
  108. .trrdl_ps = 6400,
  109. .tccdl_ps = 5355,
  110. .refresh_rate_ps = U(7800000),
  111. .dq_mapping[0] = U(0x0),
  112. .dq_mapping[1] = U(0x0),
  113. .dq_mapping[2] = U(0x0),
  114. .dq_mapping[3] = U(0x0),
  115. .dq_mapping[4] = U(0x0),
  116. .dq_mapping_ors = U(0),
  117. .rc = U(0x1f),
  118. };
  119. int ddr_get_ddr_params(struct dimm_params *pdimm, struct ddr_conf *conf)
  120. {
  121. static const char dimm_model[] = "Fixed DDR on board";
  122. conf->dimm_in_use[0] = 1;
  123. memcpy(pdimm, &ddr_raw_timing, sizeof(struct dimm_params));
  124. memcpy(pdimm->mpart, dimm_model, sizeof(dimm_model) - 1);
  125. return 1;
  126. }
  127. #endif /* ifdef CONFIG_STATIC_DDR */
  128. long long init_ddr(void)
  129. {
  130. int spd_addr[] = {NXP_SPD_EEPROM0};
  131. struct ddr_info info;
  132. struct sysinfo sys;
  133. long long dram_size;
  134. zeromem(&sys, sizeof(sys));
  135. if (get_clocks(&sys)) {
  136. ERROR("System clocks are not set\n");
  137. assert(0);
  138. }
  139. debug("platform clock %lu\n", sys.freq_platform);
  140. debug("DDR PLL1 %lu\n", sys.freq_ddr_pll0);
  141. debug("DDR PLL2 %lu\n", sys.freq_ddr_pll1);
  142. zeromem(&info, sizeof(struct ddr_info));
  143. info.num_ctlrs = 1;
  144. info.dimm_on_ctlr = 1;
  145. info.clk = get_ddr_freq(&sys, 0);
  146. info.spd_addr = spd_addr;
  147. info.ddr[0] = (void *)NXP_DDR_ADDR;
  148. dram_size = dram_init(&info);
  149. if (dram_size < 0) {
  150. ERROR("DDR init failed.\n");
  151. }
  152. #ifdef ERRATA_SOC_A008850
  153. erratum_a008850_post();
  154. #endif
  155. return dram_size;
  156. }