dram.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright 2019-2023 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef DRAM_H
  7. #define DRAM_H
  8. #include <assert.h>
  9. #include <arch_helpers.h>
  10. #include <lib/utils_def.h>
  11. #include <ddrc.h>
  12. #include <platform_def.h>
  13. #define DDRC_LPDDR4 BIT(5)
  14. #define DDRC_DDR4 BIT(4)
  15. #define DDRC_DDR3L BIT(0)
  16. #define DDR_TYPE_MASK U(0x3f)
  17. #define ACTIVE_RANK_MASK U(0x3)
  18. #define DDRC_ACTIVE_ONE_RANK U(0x1)
  19. #define DDRC_ACTIVE_TWO_RANK U(0x2)
  20. #define MR12 U(12)
  21. #define MR14 U(14)
  22. #define MAX_FSP_NUM U(3)
  23. /* reg & config param */
  24. struct dram_cfg_param {
  25. unsigned int reg;
  26. unsigned int val;
  27. };
  28. struct dram_timing_info {
  29. /* umctl2 config */
  30. struct dram_cfg_param *ddrc_cfg;
  31. unsigned int ddrc_cfg_num;
  32. /* ddrphy config */
  33. struct dram_cfg_param *ddrphy_cfg;
  34. unsigned int ddrphy_cfg_num;
  35. /* ddr fsp train info */
  36. struct dram_fsp_msg *fsp_msg;
  37. unsigned int fsp_msg_num;
  38. /* ddr phy trained CSR */
  39. struct dram_cfg_param *ddrphy_trained_csr;
  40. unsigned int ddrphy_trained_csr_num;
  41. /* ddr phy PIE */
  42. struct dram_cfg_param *ddrphy_pie;
  43. unsigned int ddrphy_pie_num;
  44. /* initialized fsp table */
  45. unsigned int fsp_table[4];
  46. };
  47. struct dram_info {
  48. int dram_type;
  49. unsigned int num_rank;
  50. uint32_t num_fsp;
  51. int current_fsp;
  52. int boot_fsp;
  53. bool bypass_mode;
  54. struct dram_timing_info *timing_info;
  55. /* mr, emr, emr2, emr3, mr11, mr12, mr22, mr14 */
  56. uint32_t mr_table[3][8];
  57. /* used for workaround for rank to rank issue */
  58. uint32_t rank_setting[3][3];
  59. };
  60. extern struct dram_info dram_info;
  61. void dram_umctl2_init(struct dram_timing_info *timing);
  62. void dram_phy_init(struct dram_timing_info *timing);
  63. /* dram retention */
  64. #if IMX_DRAM_RETENTION
  65. void dram_info_init(unsigned long dram_timing_base);
  66. void dram_enter_retention(void);
  67. void dram_exit_retention(void);
  68. #else
  69. static inline void dram_info_init(unsigned long dram_timing_base) {}
  70. static inline void dram_enter_retention(void) {}
  71. static inline void dram_exit_retention(void) {}
  72. #endif
  73. void dram_clock_switch(unsigned int target_drate, bool bypass_mode);
  74. /* dram frequency change */
  75. void lpddr4_swffc(struct dram_info *info, unsigned int init_fsp, unsigned int fsp_index);
  76. void ddr4_swffc(struct dram_info *dram_info, unsigned int pstate);
  77. #endif /* DRAM_H */