dram_sun4i.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2007-2012
  4. * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
  5. * Berg Xing <bergxing@allwinnertech.com>
  6. * Tom Cubie <tangliang@allwinnertech.com>
  7. *
  8. * Sunxi platform dram register definition.
  9. */
  10. #ifndef _SUNXI_DRAM_SUN4I_H
  11. #define _SUNXI_DRAM_SUN4I_H
  12. struct sunxi_dram_reg {
  13. u32 ccr; /* 0x00 controller configuration register */
  14. u32 dcr; /* 0x04 dram configuration register */
  15. u32 iocr; /* 0x08 i/o configuration register */
  16. u32 csr; /* 0x0c controller status register */
  17. u32 drr; /* 0x10 dram refresh register */
  18. u32 tpr0; /* 0x14 dram timing parameters register 0 */
  19. u32 tpr1; /* 0x18 dram timing parameters register 1 */
  20. u32 tpr2; /* 0x1c dram timing parameters register 2 */
  21. u32 gdllcr; /* 0x20 global dll control register */
  22. u8 res0[0x28];
  23. u32 rslr0; /* 0x4c rank system latency register */
  24. u32 rslr1; /* 0x50 rank system latency register */
  25. u8 res1[0x8];
  26. u32 rdgr0; /* 0x5c rank dqs gating register */
  27. u32 rdgr1; /* 0x60 rank dqs gating register */
  28. u8 res2[0x34];
  29. u32 odtcr; /* 0x98 odt configuration register */
  30. u32 dtr0; /* 0x9c data training register 0 */
  31. u32 dtr1; /* 0xa0 data training register 1 */
  32. u32 dtar; /* 0xa4 data training address register */
  33. u32 zqcr0; /* 0xa8 zq control register 0 */
  34. u32 zqcr1; /* 0xac zq control register 1 */
  35. u32 zqsr; /* 0xb0 zq status register */
  36. u32 idcr; /* 0xb4 initializaton delay configure reg */
  37. u8 res3[0x138];
  38. u32 mr; /* 0x1f0 mode register */
  39. u32 emr; /* 0x1f4 extended mode register */
  40. u32 emr2; /* 0x1f8 extended mode register */
  41. u32 emr3; /* 0x1fc extended mode register */
  42. u32 dllctr; /* 0x200 dll control register */
  43. u32 dllcr[5]; /* 0x204 dll control register 0(byte 0) */
  44. /* 0x208 dll control register 1(byte 1) */
  45. /* 0x20c dll control register 2(byte 2) */
  46. /* 0x210 dll control register 3(byte 3) */
  47. /* 0x214 dll control register 4(byte 4) */
  48. u32 dqtr0; /* 0x218 dq timing register */
  49. u32 dqtr1; /* 0x21c dq timing register */
  50. u32 dqtr2; /* 0x220 dq timing register */
  51. u32 dqtr3; /* 0x224 dq timing register */
  52. u32 dqstr; /* 0x228 dqs timing register */
  53. u32 dqsbtr; /* 0x22c dqsb timing register */
  54. u32 mcr; /* 0x230 mode configure register */
  55. u8 res[0x8];
  56. u32 ppwrsctl; /* 0x23c pad power save control */
  57. u32 apr; /* 0x240 arbiter period register */
  58. u32 pldtr; /* 0x244 priority level data threshold reg */
  59. u8 res5[0x8];
  60. u32 hpcr[32]; /* 0x250 host port configure register */
  61. u8 res6[0x10];
  62. u32 csel; /* 0x2e0 controller select register */
  63. };
  64. struct dram_para {
  65. u32 clock;
  66. u32 mbus_clock;
  67. u32 type;
  68. u32 rank_num;
  69. u32 density;
  70. u32 io_width;
  71. u32 bus_width;
  72. u32 cas;
  73. u32 zq;
  74. u32 odt_en;
  75. u32 size; /* For compat with dram.c files from u-boot-sunxi, unused */
  76. u32 tpr0;
  77. u32 tpr1;
  78. u32 tpr2;
  79. u32 tpr3;
  80. u32 tpr4;
  81. u32 tpr5;
  82. u32 emr1;
  83. u32 emr2;
  84. u32 emr3;
  85. u32 dqs_gating_delay;
  86. u32 active_windowing;
  87. };
  88. #define DRAM_CCR_COMMAND_RATE_1T (0x1 << 5)
  89. #define DRAM_CCR_DQS_GATE (0x1 << 14)
  90. #define DRAM_CCR_DQS_DRIFT_COMP (0x1 << 17)
  91. #define DRAM_CCR_ITM_OFF (0x1 << 28)
  92. #define DRAM_CCR_DATA_TRAINING (0x1 << 30)
  93. #define DRAM_CCR_INIT (0x1 << 31)
  94. #define DRAM_MEMORY_TYPE_DDR1 1
  95. #define DRAM_MEMORY_TYPE_DDR2 2
  96. #define DRAM_MEMORY_TYPE_DDR3 3
  97. #define DRAM_MEMORY_TYPE_LPDDR2 4
  98. #define DRAM_MEMORY_TYPE_LPDDR 5
  99. #define DRAM_DCR_TYPE (0x1 << 0)
  100. #define DRAM_DCR_TYPE_DDR2 0x0
  101. #define DRAM_DCR_TYPE_DDR3 0x1
  102. #define DRAM_DCR_IO_WIDTH(n) (((n) & 0x3) << 1)
  103. #define DRAM_DCR_IO_WIDTH_MASK DRAM_DCR_IO_WIDTH(0x3)
  104. #define DRAM_DCR_IO_WIDTH_8BIT 0x0
  105. #define DRAM_DCR_IO_WIDTH_16BIT 0x1
  106. #define DRAM_DCR_CHIP_DENSITY(n) (((n) & 0x7) << 3)
  107. #define DRAM_DCR_CHIP_DENSITY_MASK DRAM_DCR_CHIP_DENSITY(0x7)
  108. #define DRAM_DCR_CHIP_DENSITY_256M 0x0
  109. #define DRAM_DCR_CHIP_DENSITY_512M 0x1
  110. #define DRAM_DCR_CHIP_DENSITY_1024M 0x2
  111. #define DRAM_DCR_CHIP_DENSITY_2048M 0x3
  112. #define DRAM_DCR_CHIP_DENSITY_4096M 0x4
  113. #define DRAM_DCR_CHIP_DENSITY_8192M 0x5
  114. #define DRAM_DCR_BUS_WIDTH(n) (((n) & 0x7) << 6)
  115. #define DRAM_DCR_BUS_WIDTH_MASK DRAM_DCR_BUS_WIDTH(0x7)
  116. #define DRAM_DCR_BUS_WIDTH_32BIT 0x3
  117. #define DRAM_DCR_BUS_WIDTH_16BIT 0x1
  118. #define DRAM_DCR_BUS_WIDTH_8BIT 0x0
  119. #define DRAM_DCR_RANK_SEL(n) (((n) & 0x3) << 10)
  120. #define DRAM_DCR_RANK_SEL_MASK DRAM_DCR_CMD_RANK(0x3)
  121. #define DRAM_DCR_CMD_RANK_ALL (0x1 << 12)
  122. #define DRAM_DCR_MODE(n) (((n) & 0x3) << 13)
  123. #define DRAM_DCR_MODE_MASK DRAM_DCR_MODE(0x3)
  124. #define DRAM_DCR_MODE_SEQ 0x0
  125. #define DRAM_DCR_MODE_INTERLEAVE 0x1
  126. #define DRAM_CSR_DTERR (0x1 << 20)
  127. #define DRAM_CSR_DTIERR (0x1 << 21)
  128. #define DRAM_CSR_FAILED (DRAM_CSR_DTERR | DRAM_CSR_DTIERR)
  129. #define DRAM_DRR_TRFC(n) ((n) & 0xff)
  130. #define DRAM_DRR_TREFI(n) (((n) & 0xffff) << 8)
  131. #define DRAM_DRR_BURST(n) ((((n) - 1) & 0xf) << 24)
  132. #define DRAM_MCR_MODE_NORM(n) (((n) & 0x3) << 0)
  133. #define DRAM_MCR_MODE_NORM_MASK DRAM_MCR_MOD_NORM(0x3)
  134. #define DRAM_MCR_MODE_DQ_OUT(n) (((n) & 0x3) << 2)
  135. #define DRAM_MCR_MODE_DQ_OUT_MASK DRAM_MCR_MODE_DQ_OUT(0x3)
  136. #define DRAM_MCR_MODE_ADDR_OUT(n) (((n) & 0x3) << 4)
  137. #define DRAM_MCR_MODE_ADDR_OUT_MASK DRAM_MCR_MODE_ADDR_OUT(0x3)
  138. #define DRAM_MCR_MODE_DQ_IN_OUT(n) (((n) & 0x3) << 6)
  139. #define DRAM_MCR_MODE_DQ_IN_OUT_MASK DRAM_MCR_MODE_DQ_IN_OUT(0x3)
  140. #define DRAM_MCR_MODE_DQ_TURNON_DELAY(n) (((n) & 0x7) << 8)
  141. #define DRAM_MCR_MODE_DQ_TURNON_DELAY_MASK DRAM_MCR_MODE_DQ_TURNON_DELAY(0x7)
  142. #define DRAM_MCR_MODE_ADDR_IN (0x1 << 11)
  143. #define DRAM_MCR_RESET (0x1 << 12)
  144. #define DRAM_MCR_MODE_EN(n) (((n) & 0x3) << 13)
  145. #define DRAM_MCR_MODE_EN_MASK DRAM_MCR_MOD_EN(0x3)
  146. #define DRAM_MCR_DCLK_OUT (0x1 << 16)
  147. #define DRAM_DLLCR_NRESET (0x1 << 30)
  148. #define DRAM_DLLCR_DISABLE (0x1 << 31)
  149. #define DRAM_ZQCR0_IMP_DIV(n) (((n) & 0xff) << 20)
  150. #define DRAM_ZQCR0_IMP_DIV_MASK DRAM_ZQCR0_IMP_DIV(0xff)
  151. #define DRAM_ZQCR0_ZCAL (1 << 31) /* Starts ZQ calibration when set to 1 */
  152. #define DRAM_ZQCR0_ZDEN (1 << 28) /* Uses ZDATA instead of doing calibration */
  153. #define DRAM_ZQSR_ZDONE (1 << 31) /* ZQ calibration completion flag */
  154. #define DRAM_IOCR_ODT_EN ((3 << 30) | (3 << 0))
  155. #define DRAM_MR_BURST_LENGTH(n) (((n) & 0x7) << 0)
  156. #define DRAM_MR_BURST_LENGTH_MASK DRAM_MR_BURST_LENGTH(0x7)
  157. #define DRAM_MR_CAS_LAT(n) (((n) & 0x7) << 4)
  158. #define DRAM_MR_CAS_LAT_MASK DRAM_MR_CAS_LAT(0x7)
  159. #define DRAM_MR_WRITE_RECOVERY(n) (((n) & 0x7) << 9)
  160. #define DRAM_MR_WRITE_RECOVERY_MASK DRAM_MR_WRITE_RECOVERY(0x7)
  161. #define DRAM_MR_POWER_DOWN (0x1 << 12)
  162. #define DRAM_CSEL_MAGIC 0x16237495
  163. unsigned long dramc_init(struct dram_para *para);
  164. #endif /* _SUNXI_DRAM_SUN4I_H */