ddr_init.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Copyright 2018-2021 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <string.h>
  7. #include <common/debug.h>
  8. #include <ddr.h>
  9. #include <lib/utils.h>
  10. #include <platform_def.h>
  11. #ifdef CONFIG_STATIC_DDR
  12. const struct ddr_cfg_regs static_1600 = {
  13. .cs[0].config = U(0x80040422),
  14. .cs[0].bnds = U(0xFF),
  15. .sdram_cfg[0] = U(0xE50C0004),
  16. .sdram_cfg[1] = U(0x401100),
  17. .timing_cfg[0] = U(0x91550018),
  18. .timing_cfg[1] = U(0xBAB40C42),
  19. .timing_cfg[2] = U(0x48C111),
  20. .timing_cfg[3] = U(0x1111000),
  21. .timing_cfg[4] = U(0x2),
  22. .timing_cfg[5] = U(0x3401400),
  23. .timing_cfg[7] = U(0x23300000),
  24. .timing_cfg[8] = U(0x2114600),
  25. .sdram_mode[0] = U(0x3010210),
  26. .sdram_mode[9] = U(0x4000000),
  27. .sdram_mode[8] = U(0x500),
  28. .sdram_mode[2] = U(0x10210),
  29. .sdram_mode[10] = U(0x400),
  30. .sdram_mode[11] = U(0x4000000),
  31. .sdram_mode[4] = U(0x10210),
  32. .sdram_mode[12] = U(0x400),
  33. .sdram_mode[13] = U(0x4000000),
  34. .sdram_mode[6] = U(0x10210),
  35. .sdram_mode[14] = U(0x400),
  36. .sdram_mode[15] = U(0x4000000),
  37. .interval = U(0x18600618),
  38. .data_init = U(0xdeadbeef),
  39. .zq_cntl = U(0x8A090705),
  40. .clk_cntl = U(0x2000000),
  41. .cdr[0] = U(0x80040000),
  42. .cdr[1] = U(0xA181),
  43. .wrlvl_cntl[0] = U(0x8675F605),
  44. .wrlvl_cntl[1] = U(0x6070700),
  45. .wrlvl_cntl[2] = U(0x0000008),
  46. .dq_map[0] = U(0x5b65b658),
  47. .dq_map[1] = U(0xd96d8000),
  48. .dq_map[2] = U(0),
  49. .dq_map[3] = U(0x1600000),
  50. .debug[28] = U(0x00700046),
  51. };
  52. unsigned long long board_static_ddr(struct ddr_info *priv)
  53. {
  54. memcpy(&priv->ddr_reg, &static_1600, sizeof(static_1600));
  55. return ULL(0x100000000);
  56. }
  57. #else
  58. static const struct rc_timing rcz[] = {
  59. {1600, 8, 5},
  60. {}
  61. };
  62. static const struct board_timing ram[] = {
  63. {0x1f, rcz, 0x1020200, 0x00000003},
  64. };
  65. int ddr_board_options(struct ddr_info *priv)
  66. {
  67. int ret;
  68. struct memctl_opt *popts = &priv->opt;
  69. ret = cal_board_params(priv, ram, ARRAY_SIZE(ram));
  70. if (ret != 0) {
  71. return ret;
  72. }
  73. popts->bstopre = U(0x40); /* precharge value */
  74. popts->half_strength_drive_en = 1;
  75. popts->cpo_sample = U(0x46);
  76. popts->ddr_cdr1 = DDR_CDR1_DHC_EN |
  77. DDR_CDR1_ODT(DDR_CDR_ODT_80ohm);
  78. popts->ddr_cdr2 = DDR_CDR2_ODT(DDR_CDR_ODT_80ohm) |
  79. DDR_CDR2_VREF_OVRD(70); /* Vref = 70% */
  80. popts->addr_hash = 1; /* address hashing */
  81. return 0;
  82. }
  83. /* DDR model number: MT40A1G8SA-075:E */
  84. struct dimm_params ddr_raw_timing = {
  85. .n_ranks = U(1),
  86. .rank_density = ULL(4294967296),
  87. .capacity = ULL(4294967296),
  88. .primary_sdram_width = U(32),
  89. .ec_sdram_width = U(4),
  90. .rdimm = U(0),
  91. .mirrored_dimm = U(0),
  92. .n_row_addr = U(16),
  93. .n_col_addr = U(10),
  94. .bank_group_bits = U(2),
  95. .edc_config = U(2),
  96. .burst_lengths_bitmask = U(0x0c),
  97. .tckmin_x_ps = 750,
  98. .tckmax_ps = 1900,
  99. .caslat_x = U(0x0001FFE00),
  100. .taa_ps = 13500,
  101. .trcd_ps = 13500,
  102. .trp_ps = 13500,
  103. .tras_ps = 32000,
  104. .trc_ps = 45500,
  105. .twr_ps = 15000,
  106. .trfc1_ps = 350000,
  107. .trfc2_ps = 260000,
  108. .trfc4_ps = 160000,
  109. .tfaw_ps = 21000,
  110. .trrds_ps = 3000,
  111. .trrdl_ps = 4900,
  112. .tccdl_ps = 5000,
  113. .refresh_rate_ps = U(7800000),
  114. .dq_mapping[0] = U(0x16),
  115. .dq_mapping[1] = U(0x36),
  116. .dq_mapping[2] = U(0x16),
  117. .dq_mapping[3] = U(0x36),
  118. .dq_mapping[4] = U(0x16),
  119. .dq_mapping[5] = U(0x36),
  120. .dq_mapping[6] = U(0x16),
  121. .dq_mapping[7] = U(0x36),
  122. .dq_mapping[8] = U(0x16),
  123. .dq_mapping[9] = U(0x0),
  124. .dq_mapping[10] = U(0x0),
  125. .dq_mapping[11] = U(0x0),
  126. .dq_mapping[12] = U(0x0),
  127. .dq_mapping[13] = U(0x0),
  128. .dq_mapping[14] = U(0x0),
  129. .dq_mapping[15] = U(0x0),
  130. .dq_mapping[16] = U(0x0),
  131. .dq_mapping[17] = U(0x0),
  132. .dq_mapping_ors = U(0),
  133. .rc = U(0x1f),
  134. };
  135. int ddr_get_ddr_params(struct dimm_params *pdimm,
  136. struct ddr_conf *conf)
  137. {
  138. static const char dimm_model[] = "Fixed DDR on board";
  139. conf->dimm_in_use[0] = 1;
  140. memcpy(pdimm, &ddr_raw_timing, sizeof(struct dimm_params));
  141. memcpy(pdimm->mpart, dimm_model, sizeof(dimm_model) - 1);
  142. return 1;
  143. }
  144. #endif
  145. int64_t init_ddr(void)
  146. {
  147. struct ddr_info info;
  148. struct sysinfo sys;
  149. int64_t dram_size;
  150. zeromem(&sys, sizeof(sys));
  151. get_clocks(&sys);
  152. debug("platform clock %lu\n", sys.freq_platform);
  153. debug("DDR PLL1 %lu\n", sys.freq_ddr_pll0);
  154. zeromem(&info, sizeof(struct ddr_info));
  155. info.num_ctlrs = 1;
  156. info.dimm_on_ctlr = 1;
  157. info.clk = get_ddr_freq(&sys, 0);
  158. info.ddr[0] = (void *)NXP_DDR_ADDR;
  159. dram_size = dram_init(&info);
  160. if (dram_size < 0) {
  161. ERROR("DDR init failed.\n");
  162. }
  163. return dram_size;
  164. }