ddr3_init.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) Marvell International Ltd. and its affiliates
  4. */
  5. #ifndef __DDR3_INIT_H
  6. #define __DDR3_INIT_H
  7. /*
  8. * Debug
  9. */
  10. /*
  11. * MV_DEBUG_INIT need to be defines, otherwise the output of the
  12. * DDR2 training code is not complete and misleading
  13. */
  14. #define MV_DEBUG_INIT
  15. #ifdef MV_DEBUG_INIT
  16. #define DEBUG_INIT_S(s) puts(s)
  17. #define DEBUG_INIT_D(d, l) printf("%x", d)
  18. #define DEBUG_INIT_D_10(d, l) printf("%d", d)
  19. #else
  20. #define DEBUG_INIT_S(s)
  21. #define DEBUG_INIT_D(d, l)
  22. #define DEBUG_INIT_D_10(d, l)
  23. #endif
  24. #ifdef MV_DEBUG_INIT_FULL
  25. #define DEBUG_INIT_FULL_S(s) puts(s)
  26. #define DEBUG_INIT_FULL_D(d, l) printf("%x", d)
  27. #define DEBUG_INIT_FULL_D_10(d, l) printf("%d", d)
  28. #define DEBUG_WR_REG(reg, val) \
  29. { DEBUG_INIT_S("Write Reg: 0x"); DEBUG_INIT_D((reg), 8); \
  30. DEBUG_INIT_S("= "); DEBUG_INIT_D((val), 8); DEBUG_INIT_S("\n"); }
  31. #define DEBUG_RD_REG(reg, val) \
  32. { DEBUG_INIT_S("Read Reg: 0x"); DEBUG_INIT_D((reg), 8); \
  33. DEBUG_INIT_S("= "); DEBUG_INIT_D((val), 8); DEBUG_INIT_S("\n"); }
  34. #else
  35. #define DEBUG_INIT_FULL_S(s)
  36. #define DEBUG_INIT_FULL_D(d, l)
  37. #define DEBUG_INIT_FULL_D_10(d, l)
  38. #define DEBUG_WR_REG(reg, val)
  39. #define DEBUG_RD_REG(reg, val)
  40. #endif
  41. #define DEBUG_INIT_FULL_C(s, d, l) \
  42. { DEBUG_INIT_FULL_S(s); DEBUG_INIT_FULL_D(d, l); DEBUG_INIT_FULL_S("\n"); }
  43. #define DEBUG_INIT_C(s, d, l) \
  44. { DEBUG_INIT_S(s); DEBUG_INIT_D(d, l); DEBUG_INIT_S("\n"); }
  45. #define MV_MBUS_REGS_OFFSET (0x20000)
  46. #include "ddr3_hw_training.h"
  47. #define MAX_DIMM_NUM 2
  48. #define SPD_SIZE 128
  49. #ifdef MV88F78X60
  50. #include "ddr3_axp.h"
  51. #elif defined(MV88F67XX)
  52. #include "ddr3_a370.h"
  53. #elif defined(MV88F672X)
  54. #include "ddr3_a375.h"
  55. #endif
  56. /* DRR training Error codes */
  57. /* Stage 0 errors */
  58. #define MV_DDR3_TRAINING_ERR_BAD_SAR 0xDD300001
  59. /* Stage 1 errors */
  60. #define MV_DDR3_TRAINING_ERR_TWSI_FAIL 0xDD301001
  61. #define MV_DDR3_TRAINING_ERR_DIMM_TYPE_NO_MATCH 0xDD301001
  62. #define MV_DDR3_TRAINING_ERR_TWSI_BAD_TYPE 0xDD301003
  63. #define MV_DDR3_TRAINING_ERR_BUS_WIDTH_NOT_MATCH 0xDD301004
  64. #define MV_DDR3_TRAINING_ERR_BAD_DIMM_SETUP 0xDD301005
  65. #define MV_DDR3_TRAINING_ERR_MAX_CS_LIMIT 0xDD301006
  66. #define MV_DDR3_TRAINING_ERR_MAX_ENA_CS_LIMIT 0xDD301007
  67. #define MV_DDR3_TRAINING_ERR_BAD_R_DIMM_SETUP 0xDD301008
  68. /* Stage 2 errors */
  69. #define MV_DDR3_TRAINING_ERR_HW_FAIL_BASE 0xDD302000
  70. typedef enum config_type {
  71. CONFIG_ECC,
  72. CONFIG_MULTI_CS,
  73. CONFIG_BUS_WIDTH
  74. } MV_CONFIG_TYPE;
  75. enum log_level {
  76. MV_LOG_LEVEL_0,
  77. MV_LOG_LEVEL_1,
  78. MV_LOG_LEVEL_2,
  79. MV_LOG_LEVEL_3
  80. };
  81. int ddr3_hw_training(u32 target_freq, u32 ddr_width,
  82. int xor_bypass, u32 scrub_offs, u32 scrub_size,
  83. int dqs_clk_aligned, int debug_mode, int reg_dimm_skip_wl);
  84. void ddr3_print_version(void);
  85. void fix_pll_val(u8 target_fab);
  86. u8 ddr3_get_eprom_fabric(void);
  87. u32 ddr3_get_fab_opt(void);
  88. u32 ddr3_get_cpu_freq(void);
  89. u32 ddr3_get_vco_freq(void);
  90. int ddr3_check_config(u32 addr, MV_CONFIG_TYPE config_type);
  91. u32 ddr3_get_static_mc_value(u32 reg_addr, u32 offset1, u32 mask1, u32 offset2,
  92. u32 mask2);
  93. u32 ddr3_cl_to_valid_cl(u32 cl);
  94. u32 ddr3_valid_cl_to_cl(u32 ui_valid_cl);
  95. u32 ddr3_get_cs_num_from_reg(void);
  96. u32 ddr3_get_cs_ena_from_reg(void);
  97. u8 mv_ctrl_rev_get(void);
  98. u32 ddr3_get_log_level(void);
  99. /* SPD */
  100. int ddr3_dunit_setup(u32 ecc_ena, u32 hclk_time, u32 *ddr_width);
  101. /*
  102. * Accessor functions for the registers
  103. */
  104. static inline void reg_write(u32 addr, u32 val)
  105. {
  106. writel(val, INTER_REGS_BASE + addr);
  107. }
  108. static inline u32 reg_read(u32 addr)
  109. {
  110. return readl(INTER_REGS_BASE + addr);
  111. }
  112. static inline void reg_bit_set(u32 addr, u32 mask)
  113. {
  114. setbits_le32(INTER_REGS_BASE + addr, mask);
  115. }
  116. static inline void reg_bit_clr(u32 addr, u32 mask)
  117. {
  118. clrbits_le32(INTER_REGS_BASE + addr, mask);
  119. }
  120. #endif /* __DDR3_INIT_H */