ddr_init.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 <errata.h>
  11. #include <platform_def.h>
  12. #ifdef CONFIG_STATIC_DDR
  13. const struct ddr_cfg_regs static_1600 = {
  14. .cs[0].config = U(0x80040322),
  15. .cs[0].bnds = U(0x7F),
  16. .sdram_cfg[0] = U(0xC50C0000),
  17. .sdram_cfg[1] = U(0x401100),
  18. .timing_cfg[0] = U(0x91550018),
  19. .timing_cfg[1] = U(0xBBB48C42),
  20. .timing_cfg[2] = U(0x48C111),
  21. .timing_cfg[3] = U(0x10C1000),
  22. .timing_cfg[4] = U(0x2),
  23. .timing_cfg[5] = U(0x3401400),
  24. .timing_cfg[7] = U(0x13300000),
  25. .timing_cfg[8] = U(0x2115600),
  26. .sdram_mode[0] = U(0x3010210),
  27. .sdram_mode[9] = U(0x4000000),
  28. .sdram_mode[8] = U(0x500),
  29. .sdram_mode[2] = U(0x10210),
  30. .sdram_mode[10] = U(0x400),
  31. .sdram_mode[11] = U(0x4000000),
  32. .sdram_mode[4] = U(0x10210),
  33. .sdram_mode[12] = U(0x400),
  34. .sdram_mode[13] = U(0x4000000),
  35. .sdram_mode[6] = U(0x10210),
  36. .sdram_mode[14] = U(0x400),
  37. .sdram_mode[15] = U(0x4000000),
  38. .interval = U(0x18600618),
  39. .zq_cntl = U(0x8A090705),
  40. .clk_cntl = U(0x3000000),
  41. .cdr[0] = U(0x80040000),
  42. .cdr[1] = U(0xA181),
  43. .wrlvl_cntl[0] = U(0x8675F607),
  44. .wrlvl_cntl[1] = U(0x7090807,
  45. .wrlvl_cntl[2] = U(0x7070707),
  46. .debug[28] = U(0x00700046),
  47. };
  48. uint64_t board_static_ddr(struct ddr_info *priv)
  49. {
  50. memcpy(&priv->ddr_reg, &static_1600, sizeof(static_1600));
  51. return ULL(0x80000000);
  52. }
  53. #else
  54. static const struct rc_timing rcz[] = {
  55. {1600, 12, 7},
  56. {}
  57. };
  58. static const struct board_timing ram[] = {
  59. {0x1f, rcz, 0x00020100, 0},
  60. };
  61. int ddr_board_options(struct ddr_info *priv)
  62. {
  63. int ret;
  64. struct memctl_opt *popts = &priv->opt;
  65. ret = cal_board_params(priv, ram, ARRAY_SIZE(ram));
  66. if (ret)
  67. return ret;
  68. popts->cpo_sample = U(0x46);
  69. popts->ddr_cdr1 = DDR_CDR1_DHC_EN |
  70. DDR_CDR1_ODT(DDR_CDR_ODT_80ohm);
  71. popts->ddr_cdr2 = DDR_CDR2_ODT(DDR_CDR_ODT_80ohm) |
  72. DDR_CDR2_VREF_OVRD(70); /* Vref = 70% */
  73. return 0;
  74. }
  75. /* DDR model number: MT40A1G8SA-062E:R */
  76. struct dimm_params ddr_raw_timing = {
  77. .n_ranks = U(1),
  78. .rank_density = ULL(2147483648),
  79. .capacity = ULL(2147483648),
  80. .primary_sdram_width = U(32),
  81. .ec_sdram_width = U(4),
  82. .rdimm = U(0),
  83. .mirrored_dimm = U(0),
  84. .n_row_addr = U(16),
  85. .n_col_addr = U(10),
  86. .bank_group_bits = U(2),
  87. .edc_config = U(2),
  88. .burst_lengths_bitmask = U(0x0c),
  89. .tckmin_x_ps = 625,
  90. .tckmax_ps = 2200,
  91. .caslat_x = U(0x0001FFE00),
  92. .taa_ps = 13500,
  93. .trcd_ps = 13500,
  94. .trp_ps = 13500,
  95. .tras_ps = 32000,
  96. .trc_ps = 45500,
  97. .twr_ps = 15000,
  98. .trfc1_ps = 350000,
  99. .trfc2_ps = 260000,
  100. .trfc4_ps = 160000,
  101. .tfaw_ps = 21000,
  102. .trrds_ps = 3000,
  103. .trrdl_ps = 4900,
  104. .tccdl_ps = 5000,
  105. .refresh_rate_ps = U(7800000),
  106. .rc = U(0x1f),
  107. };
  108. int ddr_get_ddr_params(struct dimm_params *pdimm,
  109. struct ddr_conf *conf)
  110. {
  111. static const char dimm_model[] = "Fixed DDR on board";
  112. conf->dimm_in_use[0] = 1;
  113. memcpy(pdimm, &ddr_raw_timing, sizeof(struct dimm_params));
  114. memcpy(pdimm->mpart, dimm_model, sizeof(dimm_model) - 1);
  115. return 1;
  116. }
  117. #endif
  118. int64_t init_ddr(void)
  119. {
  120. struct ddr_info info;
  121. struct sysinfo sys;
  122. int64_t dram_size;
  123. zeromem(&sys, sizeof(sys));
  124. get_clocks(&sys);
  125. debug("platform clock %lu\n", sys.freq_platform);
  126. debug("DDR PLL1 %lu\n", sys.freq_ddr_pll0);
  127. debug("DDR PLL2 %lu\n", sys.freq_ddr_pll1);
  128. zeromem(&info, sizeof(struct ddr_info));
  129. info.num_ctlrs = 1;
  130. info.dimm_on_ctlr = 1;
  131. info.clk = get_ddr_freq(&sys, 0);
  132. info.ddr[0] = (void *)NXP_DDR_ADDR;
  133. dram_size = dram_init(&info);
  134. if (dram_size < 0) {
  135. ERROR("DDR init failed\n");
  136. }
  137. #ifdef ERRATA_SOC_A008850
  138. erratum_a008850_post();
  139. #endif
  140. return dram_size;
  141. }