ddr_init.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2022 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <errno.h>
  7. #include <common/debug.h>
  8. #include <ddr.h>
  9. #include <utils.h>
  10. #include <errata.h>
  11. #include <platform_def.h>
  12. #ifdef CONFIG_STATIC_DDR
  13. #error No static value defined
  14. #endif
  15. static const struct rc_timing rce[] = {
  16. {U(1600), U(8), U(8)},
  17. {U(1867), U(8), U(8)},
  18. {U(2134), U(8), U(9)},
  19. {}
  20. };
  21. static const struct board_timing udimm[] = {
  22. {U(0x04), rce, U(0x01030508), U(0x090b0d06)},
  23. {U(0x1f), rce, U(0x01030508), U(0x090b0d06)},
  24. };
  25. int ddr_board_options(struct ddr_info *priv)
  26. {
  27. int ret;
  28. struct memctl_opt *popts = &priv->opt;
  29. if (popts->rdimm != 0) {
  30. debug("RDIMM parameters not set.\n");
  31. return -EINVAL;
  32. }
  33. ret = cal_board_params(priv, udimm, ARRAY_SIZE(udimm));
  34. if (ret != 0) {
  35. return ret;
  36. }
  37. popts->addr_hash = 1;
  38. popts->cpo_sample = U(0x7b);
  39. popts->ddr_cdr1 = DDR_CDR1_DHC_EN |
  40. DDR_CDR1_ODT(DDR_CDR_ODT_60ohm);
  41. popts->ddr_cdr2 = DDR_CDR2_ODT(DDR_CDR_ODT_60ohm) |
  42. DDR_CDR2_VREF_TRAIN_EN |
  43. DDR_CDR2_VREF_RANGE_2;
  44. return 0;
  45. }
  46. long long init_ddr(void)
  47. {
  48. int spd_addr[] = { NXP_SPD_EEPROM0 };
  49. struct ddr_info info;
  50. struct sysinfo sys;
  51. long long dram_size;
  52. zeromem(&sys, sizeof(sys));
  53. get_clocks(&sys);
  54. debug("platform clock %lu\n", sys.freq_platform);
  55. debug("DDR PLL %lu\n", sys.freq_ddr_pll0);
  56. zeromem(&info, sizeof(struct ddr_info));
  57. info.num_ctlrs = NUM_OF_DDRC;
  58. info.dimm_on_ctlr = DDRC_NUM_DIMM;
  59. info.clk = get_ddr_freq(&sys, 0);
  60. info.spd_addr = spd_addr;
  61. info.ddr[0] = (void *)NXP_DDR_ADDR;
  62. dram_size = dram_init(&info);
  63. if (dram_size < 0) {
  64. ERROR("DDR init failed.\n");
  65. }
  66. return dram_size;
  67. }