ddr_init.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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(0x01020307), U(0x08090b06)},
  23. };
  24. int ddr_board_options(struct ddr_info *priv)
  25. {
  26. int ret;
  27. struct memctl_opt *popts = &priv->opt;
  28. if (popts->rdimm != 0) {
  29. debug("RDIMM parameters not set.\n");
  30. return -EINVAL;
  31. }
  32. ret = cal_board_params(priv, udimm, ARRAY_SIZE(udimm));
  33. if (ret != 0) {
  34. return ret;
  35. }
  36. popts->addr_hash = 1;
  37. popts->cpo_sample = U(0x7b);
  38. popts->ddr_cdr1 = DDR_CDR1_DHC_EN |
  39. DDR_CDR1_ODT(DDR_CDR_ODT_60ohm);
  40. popts->ddr_cdr2 = DDR_CDR2_ODT(DDR_CDR_ODT_60ohm) |
  41. DDR_CDR2_VREF_TRAIN_EN |
  42. DDR_CDR2_VREF_RANGE_2;
  43. return 0;
  44. }
  45. long long init_ddr(void)
  46. {
  47. int spd_addr[] = { NXP_SPD_EEPROM0 };
  48. struct ddr_info info;
  49. struct sysinfo sys;
  50. long long dram_size;
  51. zeromem(&sys, sizeof(sys));
  52. get_clocks(&sys);
  53. debug("platform clock %lu\n", sys.freq_platform);
  54. debug("DDR PLL %lu\n", sys.freq_ddr_pll0);
  55. zeromem(&info, sizeof(struct ddr_info));
  56. info.num_ctlrs = NUM_OF_DDRC;
  57. info.dimm_on_ctlr = DDRC_NUM_DIMM;
  58. info.clk = get_ddr_freq(&sys, 0);
  59. info.spd_addr = spd_addr;
  60. info.ddr[0] = (void *)NXP_DDR_ADDR;
  61. dram_size = dram_init(&info);
  62. if (dram_size < 0) {
  63. ERROR("DDR init failed.\n");
  64. }
  65. return dram_size;
  66. }