ddr_rk3368.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef DDR_RK3368_H
  7. #define DDR_RK3368_H
  8. #define DDR_PCTL_SCFG 0x0
  9. #define DDR_PCTL_SCTL 0x4
  10. #define DDR_PCTL_STAT 0x8
  11. #define DDR_PCTL_INTRSTAT 0xc
  12. #define DDR_PCTL_MCMD 0x40
  13. #define DDR_PCTL_POWCTL 0x44
  14. #define DDR_PCTL_POWSTAT 0x48
  15. #define DDR_PCTL_CMDTSTAT 0x4c
  16. #define DDR_PCTL_CMDTSTATEN 0x50
  17. #define DDR_PCTL_MRRCFG0 0x60
  18. #define DDR_PCTL_MRRSTAT0 0x64
  19. #define DDR_PCTL_MRRSTAT1 0x68
  20. #define DDR_PCTL_MCFG1 0x7c
  21. #define DDR_PCTL_MCFG 0x80
  22. #define DDR_PCTL_PPCFG 0x84
  23. #define DDR_PCTL_MSTAT 0x88
  24. #define DDR_PCTL_LPDDR2ZQCFG 0x8c
  25. #define DDR_PCTL_DTUPDES 0x94
  26. #define DDR_PCTL_DTUNA 0x98
  27. #define DDR_PCTL_DTUNE 0x9c
  28. #define DDR_PCTL_DTUPRD0 0xa0
  29. #define DDR_PCTL_DTUPRD1 0xa4
  30. #define DDR_PCTL_DTUPRD2 0xa8
  31. #define DDR_PCTL_DTUPRD3 0xac
  32. #define DDR_PCTL_DTUAWDT 0xb0
  33. #define DDR_PCTL_TOGCNT1U 0xc0
  34. #define DDR_PCTL_TINIT 0xc4
  35. #define DDR_PCTL_TRSTH 0xc8
  36. #define DDR_PCTL_TOGCNT100N 0xcc
  37. #define DDR_PCTL_TREFI 0xd0
  38. #define DDR_PCTL_TMRD 0xd4
  39. #define DDR_PCTL_TRFC 0xd8
  40. #define DDR_PCTL_TRP 0xdc
  41. #define DDR_PCTL_TRTW 0xe0
  42. #define DDR_PCTL_TAL 0xe4
  43. #define DDR_PCTL_TCL 0xe8
  44. #define DDR_PCTL_TCWL 0xec
  45. #define DDR_PCTL_TRAS 0xf0
  46. #define DDR_PCTL_TRC 0xf4
  47. #define DDR_PCTL_TRCD 0xf8
  48. #define DDR_PCTL_TRRD 0xfc
  49. #define DDR_PCTL_TRTP 0x100
  50. #define DDR_PCTL_TWR 0x104
  51. #define DDR_PCTL_TWTR 0x108
  52. #define DDR_PCTL_TEXSR 0x10c
  53. #define DDR_PCTL_TXP 0x110
  54. #define DDR_PCTL_TXPDLL 0x114
  55. #define DDR_PCTL_TZQCS 0x118
  56. #define DDR_PCTL_TZQCSI 0x11c
  57. #define DDR_PCTL_TDQS 0x120
  58. #define DDR_PCTL_TCKSRE 0x124
  59. #define DDR_PCTL_TCKSRX 0x128
  60. #define DDR_PCTL_TCKE 0x12c
  61. #define DDR_PCTL_TMOD 0x130
  62. #define DDR_PCTL_TRSTL 0x134
  63. #define DDR_PCTL_TZQCL 0x138
  64. #define DDR_PCTL_TMRR 0x13c
  65. #define DDR_PCTL_TCKESR 0x140
  66. #define DDR_PCTL_TDPD 0x144
  67. #define DDR_PCTL_TREFI_MEM_DDR3 0x148
  68. #define DDR_PCTL_ECCCFG 0x180
  69. #define DDR_PCTL_ECCTST 0x184
  70. #define DDR_PCTL_ECCCLR 0x188
  71. #define DDR_PCTL_ECCLOG 0x18c
  72. #define DDR_PCTL_DTUWACTL 0x200
  73. #define DDR_PCTL_DTURACTL 0x204
  74. #define DDR_PCTL_DTUCFG 0x208
  75. #define DDR_PCTL_DTUECTL 0x20c
  76. #define DDR_PCTL_DTUWD0 0x210
  77. #define DDR_PCTL_DTUWD1 0x214
  78. #define DDR_PCTL_DTUWD2 0x218
  79. #define DDR_PCTL_DTUWD3 0x21c
  80. #define DDR_PCTL_DTUWDM 0x220
  81. #define DDR_PCTL_DTURD0 0x224
  82. #define DDR_PCTL_DTURD1 0x228
  83. #define DDR_PCTL_DTURD2 0x22c
  84. #define DDR_PCTL_DTURD3 0x230
  85. #define DDR_PCTL_DTULFSRWD 0x234
  86. #define DDR_PCTL_DTULFSRRD 0x238
  87. #define DDR_PCTL_DTUEAF 0x23c
  88. #define DDR_PCTL_DFITCTRLDELAY 0x240
  89. #define DDR_PCTL_DFIODTCFG 0x244
  90. #define DDR_PCTL_DFIODTCFG1 0x248
  91. #define DDR_PCTL_DFIODTRANKMAP 0x24c
  92. #define DDR_PCTL_DFITPHYWRDATA 0x250
  93. #define DDR_PCTL_DFITPHYWRLAT 0x254
  94. #define DDR_PCTL_DFITPHYWRDATALAT 0x258
  95. #define DDR_PCTL_DFITRDDATAEN 0x260
  96. #define DDR_PCTL_DFITPHYRDLAT 0x264
  97. #define DDR_PCTL_DFITPHYUPDTYPE0 0x270
  98. #define DDR_PCTL_DFITPHYUPDTYPE1 0x274
  99. #define DDR_PCTL_DFITPHYUPDTYPE2 0x278
  100. #define DDR_PCTL_DFITPHYUPDTYPE3 0x27c
  101. #define DDR_PCTL_DFITCTRLUPDMIN 0x280
  102. #define DDR_PCTL_DFITCTRLUPDMAX 0x284
  103. #define DDR_PCTL_DFITCTRLUPDDLY 0x288
  104. #define DDR_PCTL_DFIUPDCFG 0x290
  105. #define DDR_PCTL_DFITREFMSKI 0x294
  106. #define DDR_PCTL_DFITCTRLUPDI 0x298
  107. #define DDR_PCTL_DFITRCFG0 0x2ac
  108. #define DDR_PCTL_DFITRSTAT0 0x2b0
  109. #define DDR_PCTL_DFITRWRLVLEN 0x2b4
  110. #define DDR_PCTL_DFITRRDLVLEN 0x2b8
  111. #define DDR_PCTL_DFITRRDLVLGATEEN 0x2bc
  112. #define DDR_PCTL_DFISTSTAT0 0x2c0
  113. #define DDR_PCTL_DFISTCFG0 0x2c4
  114. #define DDR_PCTL_DFISTCFG1 0x2c8
  115. #define DDR_PCTL_DFITDRAMCLKEN 0x2d0
  116. #define DDR_PCTL_DFITDRAMCLKDIS 0x2d4
  117. #define DDR_PCTL_DFISTCFG2 0x2d8
  118. #define DDR_PCTL_DFISTPARCLR 0x2dc
  119. #define DDR_PCTL_DFISTPARLOG 0x2e0
  120. #define DDR_PCTL_DFILPCFG0 0x2f0
  121. #define DDR_PCTL_DFITRWRLVLRESP0 0x300
  122. #define DDR_PCTL_DFITRWRLVLRESP1 0x304
  123. #define DDR_PCTL_DFITRWRLVLRESP2 0x308
  124. #define DDR_PCTL_DFITRRDLVLRESP0 0x30c
  125. #define DDR_PCTL_DFITRRDLVLRESP1 0x310
  126. #define DDR_PCTL_DFITRRDLVLRESP2 0x314
  127. #define DDR_PCTL_DFITRWRLVLDELAY0 0x318
  128. #define DDR_PCTL_DFITRWRLVLDELAY1 0x31c
  129. #define DDR_PCTL_DFITRWRLVLDELAY2 0x320
  130. #define DDR_PCTL_DFITRRDLVLDELAY0 0x324
  131. #define DDR_PCTL_DFITRRDLVLDELAY1 0x328
  132. #define DDR_PCTL_DFITRRDLVLDELAY2 0x32c
  133. #define DDR_PCTL_DFITRRDLVLGATEDELAY0 0x330
  134. #define DDR_PCTL_DFITRRDLVLGATEDELAY1 0x334
  135. #define DDR_PCTL_DFITRRDLVLGATEDELAY2 0x338
  136. #define DDR_PCTL_DFITRCMD 0x33c
  137. #define DDR_PCTL_IPVR 0x3f8
  138. #define DDR_PCTL_IPTR 0x3fc
  139. /* DDR PHY REG */
  140. #define DDR_PHY_REG0 0x0
  141. #define DDR_PHY_REG1 0x4
  142. #define DDR_PHY_REG2 0x8
  143. #define DDR_PHY_REG3 0xc
  144. #define DDR_PHY_REG4 0x10
  145. #define DDR_PHY_REG5 0x14
  146. #define DDR_PHY_REG6 0x18
  147. #define DDR_PHY_REGB 0x2c
  148. #define DDR_PHY_REGC 0x30
  149. #define DDR_PHY_REG11 0x44
  150. #define DDR_PHY_REG12 0x48
  151. #define DDR_PHY_REG13 0x4c
  152. #define DDR_PHY_REG14 0x50
  153. #define DDR_PHY_REG16 0x58
  154. #define DDR_PHY_REG20 0x80
  155. #define DDR_PHY_REG21 0x84
  156. #define DDR_PHY_REG26 0x98
  157. #define DDR_PHY_REG27 0x9c
  158. #define DDR_PHY_REG28 0xa0
  159. #define DDR_PHY_REG2C 0xb0
  160. #define DDR_PHY_REG30 0xc0
  161. #define DDR_PHY_REG31 0xc4
  162. #define DDR_PHY_REG36 0xd8
  163. #define DDR_PHY_REG37 0xdc
  164. #define DDR_PHY_REG38 0xe0
  165. #define DDR_PHY_REG3C 0xf0
  166. #define DDR_PHY_REG40 0x100
  167. #define DDR_PHY_REG41 0x104
  168. #define DDR_PHY_REG46 0x118
  169. #define DDR_PHY_REG47 0x11c
  170. #define DDR_PHY_REG48 0x120
  171. #define DDR_PHY_REG4C 0x130
  172. #define DDR_PHY_REG50 0x140
  173. #define DDR_PHY_REG51 0x144
  174. #define DDR_PHY_REG56 0x158
  175. #define DDR_PHY_REG57 0x15c
  176. #define DDR_PHY_REG58 0x160
  177. #define DDR_PHY_REG5C 0x170
  178. #define DDR_PHY_REGDLL 0x290
  179. #define DDR_PHY_REGEC 0x3b0
  180. #define DDR_PHY_REGED 0x3b4
  181. #define DDR_PHY_REGEE 0x3b8
  182. #define DDR_PHY_REGEF 0x3bc
  183. #define DDR_PHY_REGF0 0x3c0
  184. #define DDR_PHY_REGF1 0x3c4
  185. #define DDR_PHY_REGF2 0x3c8
  186. #define DDR_PHY_REGFA 0x3e8
  187. #define DDR_PHY_REGFB 0x3ec
  188. #define DDR_PHY_REGFC 0x3f0
  189. #define DDR_PHY_REGFD 0x3f4
  190. #define DDR_PHY_REGFE 0x3f8
  191. #define DDR_PHY_REGFF 0x3fc
  192. /* MSCH REG define */
  193. #define MSCH_COREID 0x0
  194. #define MSCH_DDRCONF 0x8
  195. #define MSCH_DDRTIMING 0xc
  196. #define MSCH_DDRMODE 0x10
  197. #define MSCH_READLATENCY 0x14
  198. #define MSCH_ACTIVATE 0x38
  199. #define MSCH_DEVTODEV 0x3c
  200. #define SET_NR(n) ((0x3f << (8 + 16)) | ((n - 1) << 8))
  201. #define SET_NO(n) ((0xf << (0 + 16)) | ((n - 1) << 0))
  202. #define SET_NF(n) ((n - 1) & 0x1fff)
  203. #define SET_NB(n) ((n - 1) & 0xfff)
  204. #define PLLMODE(n) ((0x3 << (8 + 16)) | (n << 8))
  205. /* GRF REG define */
  206. #define GRF_SOC_STATUS0 0x480
  207. #define GRF_DDRPHY_LOCK (0x1 << 15)
  208. #define GRF_DDRC0_CON0 0x600
  209. /* CRU softreset ddr pctl, phy */
  210. #define DDRMSCH0_SRSTN_REQ(n) (((0x1 << 10) << 16) | (n << 10))
  211. #define DDRCTRL0_PSRSTN_REQ(n) (((0x1 << 3) << 16) | (n << 3))
  212. #define DDRCTRL0_SRSTN_REQ(n) (((0x1 << 2) << 16) | (n << 2))
  213. #define DDRPHY0_PSRSTN_REQ(n) (((0x1 << 1) << 16) | (n << 1))
  214. #define DDRPHY0_SRSTN_REQ(n) (((0x1 << 0) << 16) | (n << 0))
  215. /* CRU_DPLL_CON2 */
  216. #define DPLL_STATUS_LOCK (1U << 31)
  217. /* CRU_DPLL_CON3 */
  218. #define DPLL_POWER_DOWN ((0x1 << (1 + 16)) | (0 << 1))
  219. #define DPLL_WORK_NORMAL_MODE ((0x3 << (8 + 16)) | (0 << 8))
  220. #define DPLL_WORK_SLOW_MODE ((0x3 << (8 + 16)) | (1 << 8))
  221. #define DPLL_RESET_CONTROL_NORMAL ((0x1 << (5 + 16)) | (0x0 << 5))
  222. #define DPLL_RESET_CONTROL_RESET ((0x1 << (5 + 16)) | (0x1 << 5))
  223. /* PMU_PWRDN_CON */
  224. #define PD_PERI_PWRDN_ENABLE (1 << 13)
  225. #define DDR_PLL_SRC_MASK 0x13
  226. /* DDR_PCTL_TREFI */
  227. #define DDR_UPD_REF_ENABLE (0X1u << 31)
  228. uint32_t ddr_get_resume_code_size(void);
  229. uint32_t ddr_get_resume_data_size(void);
  230. uint32_t *ddr_get_resume_code_base(void);
  231. void ddr_reg_save(uint32_t pllpdstat, uint64_t base_addr);
  232. #endif /* DDR_RK3368_H */