ddr.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright 2021 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef DDR_H
  8. #define DDR_H
  9. #include "ddr_io.h"
  10. #include "dimm.h"
  11. #include "immap.h"
  12. #ifndef DDRC_NUM_CS
  13. #define DDRC_NUM_CS 4
  14. #endif
  15. /*
  16. * This is irrespective of what is the number of DDR controller,
  17. * number of DIMM used. This is set to maximum
  18. * Max controllers = 2
  19. * Max num of DIMM per controlle = 2
  20. * MAX NUM CS = 4
  21. * Not to be changed.
  22. */
  23. #define MAX_DDRC_NUM 2
  24. #define MAX_DIMM_NUM 2
  25. #define MAX_CS_NUM 4
  26. #include "opts.h"
  27. #include "regs.h"
  28. #include "utility.h"
  29. #ifdef DDR_DEBUG
  30. #define debug(...) INFO(__VA_ARGS__)
  31. #else
  32. #define debug(...) VERBOSE(__VA_ARGS__)
  33. #endif
  34. #ifndef DDRC_NUM_DIMM
  35. #define DDRC_NUM_DIMM 1
  36. #endif
  37. #define CONFIG_CS_PER_SLOT \
  38. (DDRC_NUM_CS / DDRC_NUM_DIMM)
  39. /* Record of register values computed */
  40. struct ddr_cfg_regs {
  41. struct {
  42. unsigned int bnds;
  43. unsigned int config;
  44. unsigned int config_2;
  45. } cs[MAX_CS_NUM];
  46. unsigned int dec[10];
  47. unsigned int timing_cfg[10];
  48. unsigned int sdram_cfg[3];
  49. unsigned int sdram_mode[16];
  50. unsigned int md_cntl;
  51. unsigned int interval;
  52. unsigned int data_init;
  53. unsigned int clk_cntl;
  54. unsigned int init_addr;
  55. unsigned int init_ext_addr;
  56. unsigned int zq_cntl;
  57. unsigned int wrlvl_cntl[3];
  58. unsigned int ddr_sr_cntr;
  59. unsigned int sdram_rcw[6];
  60. unsigned int dq_map[4];
  61. unsigned int eor;
  62. unsigned int cdr[2];
  63. unsigned int err_disable;
  64. unsigned int err_int_en;
  65. unsigned int tx_cfg[4];
  66. unsigned int debug[64];
  67. };
  68. struct ddr_conf {
  69. int dimm_in_use[MAX_DIMM_NUM];
  70. int cs_in_use; /* bitmask, bit 0 for cs0, bit 1 for cs1, etc. */
  71. int cs_on_dimm[MAX_DIMM_NUM]; /* bitmask */
  72. unsigned long long cs_base_addr[MAX_CS_NUM];
  73. unsigned long long cs_size[MAX_CS_NUM];
  74. unsigned long long base_addr;
  75. unsigned long long total_mem;
  76. };
  77. struct ddr_info {
  78. unsigned long clk;
  79. unsigned long long mem_base;
  80. unsigned int num_ctlrs;
  81. unsigned int dimm_on_ctlr;
  82. struct dimm_params dimm;
  83. struct memctl_opt opt;
  84. struct ddr_conf conf;
  85. struct ddr_cfg_regs ddr_reg;
  86. struct ccsr_ddr *ddr[MAX_DDRC_NUM];
  87. uint16_t *phy[MAX_DDRC_NUM];
  88. int *spd_addr;
  89. unsigned int ip_rev;
  90. uintptr_t phy_gen2_fw_img_buf;
  91. void *img_loadr;
  92. int warm_boot_flag;
  93. };
  94. struct rc_timing {
  95. unsigned int speed_bin;
  96. unsigned int clk_adj;
  97. unsigned int wrlvl;
  98. };
  99. struct board_timing {
  100. unsigned int rc;
  101. struct rc_timing const *p;
  102. unsigned int add1;
  103. unsigned int add2;
  104. };
  105. enum warm_boot {
  106. DDR_COLD_BOOT = 0,
  107. DDR_WARM_BOOT = 1,
  108. DDR_WRM_BOOT_NT_SUPPORTED = -1,
  109. };
  110. int disable_unused_ddrc(struct ddr_info *priv, int mask,
  111. uintptr_t nxp_ccn_hn_f0_addr);
  112. int ddr_board_options(struct ddr_info *priv);
  113. int compute_ddrc(const unsigned long clk,
  114. const struct memctl_opt *popts,
  115. const struct ddr_conf *conf,
  116. struct ddr_cfg_regs *ddr,
  117. const struct dimm_params *dimm_params,
  118. const unsigned int ip_rev);
  119. int compute_ddr_phy(struct ddr_info *priv);
  120. int ddrc_set_regs(const unsigned long clk,
  121. const struct ddr_cfg_regs *regs,
  122. const struct ccsr_ddr *ddr,
  123. int twopass);
  124. int cal_board_params(struct ddr_info *priv,
  125. const struct board_timing *dimm,
  126. int len);
  127. /* return bit mask of used DIMM(s) */
  128. int ddr_get_ddr_params(struct dimm_params *pdimm, struct ddr_conf *conf);
  129. long long dram_init(struct ddr_info *priv
  130. #if defined(NXP_HAS_CCN504) || defined(NXP_HAS_CCN508)
  131. , uintptr_t nxp_ccn_hn_f0_addr
  132. #endif
  133. );
  134. long long board_static_ddr(struct ddr_info *info);
  135. #endif /* DDR_H */