dram_sunxi_dw.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * sun8i H3 platform dram controller register and constant defines
  4. *
  5. * (C) Copyright 2007-2015 Allwinner Technology Co.
  6. * Jerry Wang <wangflord@allwinnertech.com>
  7. * (C) Copyright 2015 Vishnu Patekar <vishnupatekar0510@gmail.com>
  8. * (C) Copyright 2014-2015 Hans de Goede <hdegoede@redhat.com>
  9. * (C) Copyright 2015 Jens Kuske <jenskuske@gmail.com>
  10. */
  11. #ifndef _SUNXI_DRAM_SUN8I_H3_H
  12. #define _SUNXI_DRAM_SUN8I_H3_H
  13. #include <linux/bitops.h>
  14. struct sunxi_mctl_com_reg {
  15. u32 cr; /* 0x00 control register */
  16. u32 cr_r1; /* 0x04 rank 1 control register (R40 only) */
  17. u8 res0[0x4]; /* 0x08 */
  18. u32 tmr; /* 0x0c (unused on H3) */
  19. u32 mcr[16][2]; /* 0x10 */
  20. u32 bwcr; /* 0x90 bandwidth control register */
  21. u32 maer; /* 0x94 master enable register */
  22. u32 mapr; /* 0x98 master priority register */
  23. u32 mcgcr; /* 0x9c */
  24. u32 cpu_bwcr; /* 0xa0 */
  25. u32 gpu_bwcr; /* 0xa4 */
  26. u32 ve_bwcr; /* 0xa8 */
  27. u32 disp_bwcr; /* 0xac */
  28. u32 other_bwcr; /* 0xb0 */
  29. u32 total_bwcr; /* 0xb4 */
  30. u8 res1[0x8]; /* 0xb8 */
  31. u32 swonr; /* 0xc0 */
  32. u32 swoffr; /* 0xc4 */
  33. u8 res2[0x8]; /* 0xc8 */
  34. u32 cccr; /* 0xd0 */
  35. u8 res3[0x54]; /* 0xd4 */
  36. u32 mdfs_bwlr[3]; /* 0x128 (unused on H3) */
  37. u8 res4[0x6cc]; /* 0x134 */
  38. u32 protect; /* 0x800 */
  39. };
  40. #define MCTL_CR_BL8 (0x4 << 20)
  41. #define MCTL_CR_1T (0x1 << 19)
  42. #define MCTL_CR_2T (0x0 << 19)
  43. #define MCTL_CR_LPDDR3 (0x7 << 16)
  44. #define MCTL_CR_LPDDR2 (0x6 << 16)
  45. #define MCTL_CR_DDR3 (0x3 << 16)
  46. #define MCTL_CR_DDR2 (0x2 << 16)
  47. #define MCTL_CR_SEQUENTIAL (0x1 << 15)
  48. #define MCTL_CR_INTERLEAVED (0x0 << 15)
  49. #define MCTL_CR_FULL_WIDTH (0x1 << 12)
  50. #define MCTL_CR_HALF_WIDTH (0x0 << 12)
  51. #define MCTL_CR_BUS_FULL_WIDTH(x) ((x) << 12)
  52. #define MCTL_CR_PAGE_SIZE(x) ((fls(x) - 4) << 8)
  53. #define MCTL_CR_ROW_BITS(x) (((x) - 1) << 4)
  54. #define MCTL_CR_EIGHT_BANKS (0x1 << 2)
  55. #define MCTL_CR_FOUR_BANKS (0x0 << 2)
  56. #define MCTL_CR_DUAL_RANK (0x1 << 0)
  57. #define MCTL_CR_SINGLE_RANK (0x0 << 0)
  58. /*
  59. * CR_R1 is a register found in the R40's DRAM controller. It sets various
  60. * parameters for rank 1. Bits [11:0] have the same meaning as the bits in
  61. * MCTL_CR, but they apply to rank 1 only. This implies we can have
  62. * different chips for rank 1 than rank 0.
  63. *
  64. * As address line A15 and CS1 chip select for rank 1 are muxed on the same
  65. * pin, if single rank is used, A15 must be muxed in.
  66. */
  67. #define MCTL_CR_R1_MUX_A15 (0x1 << 21)
  68. #define PROTECT_MAGIC (0x94be6fa3)
  69. struct sunxi_mctl_ctl_reg {
  70. u32 pir; /* 0x00 PHY initialization register */
  71. u32 pwrctl; /* 0x04 */
  72. u32 mrctrl; /* 0x08 */
  73. u32 clken; /* 0x0c */
  74. u32 pgsr[2]; /* 0x10 PHY general status registers */
  75. u32 statr; /* 0x18 */
  76. u8 res1[0x10]; /* 0x1c */
  77. u32 lp3mr11; /* 0x2c */
  78. u32 mr[4]; /* 0x30 mode registers */
  79. u32 pllgcr; /* 0x40 */
  80. u32 ptr[5]; /* 0x44 PHY timing registers */
  81. u32 dramtmg[9]; /* 0x58 DRAM timing registers */
  82. u32 odtcfg; /* 0x7c */
  83. u32 pitmg[2]; /* 0x80 PHY interface timing registers */
  84. u8 res2[0x4]; /* 0x88 */
  85. u32 rfshctl0; /* 0x8c */
  86. u32 rfshtmg; /* 0x90 refresh timing */
  87. u32 rfshctl1; /* 0x94 */
  88. u32 pwrtmg; /* 0x98 */
  89. u8 res3[0x1c]; /* 0x9c */
  90. u32 vtfcr; /* 0xb8 (unused on H3) */
  91. u32 dqsgmr; /* 0xbc */
  92. u32 dtcr; /* 0xc0 */
  93. u32 dtar[4]; /* 0xc4 */
  94. u32 dtdr[2]; /* 0xd4 */
  95. u32 dtmr[2]; /* 0xdc */
  96. u32 dtbmr; /* 0xe4 */
  97. u32 catr[2]; /* 0xe8 */
  98. u32 dtedr[2]; /* 0xf0 */
  99. u8 res4[0x8]; /* 0xf8 */
  100. u32 pgcr[4]; /* 0x100 PHY general configuration registers */
  101. u32 iovcr[2]; /* 0x110 */
  102. u32 dqsdr; /* 0x118 */
  103. u32 dxccr; /* 0x11c */
  104. u32 odtmap; /* 0x120 */
  105. u32 zqctl[2]; /* 0x124 */
  106. u8 res6[0x14]; /* 0x12c */
  107. u32 zqcr; /* 0x140 ZQ control register */
  108. u32 zqsr; /* 0x144 ZQ status register */
  109. u32 zqdr[3]; /* 0x148 ZQ data registers */
  110. u8 res7[0x6c]; /* 0x154 */
  111. u32 sched; /* 0x1c0 */
  112. u32 perfhpr[2]; /* 0x1c4 */
  113. u32 perflpr[2]; /* 0x1cc */
  114. u32 perfwr[2]; /* 0x1d4 */
  115. u8 res8[0x24]; /* 0x1dc */
  116. u32 acmdlr; /* 0x200 AC master delay line register */
  117. u32 aclcdlr; /* 0x204 AC local calibrated delay line register */
  118. u32 aciocr; /* 0x208 AC I/O configuration register */
  119. u8 res9[0x4]; /* 0x20c */
  120. u32 acbdlr[31]; /* 0x210 AC bit delay line registers */
  121. u8 res10[0x74]; /* 0x28c */
  122. struct { /* 0x300 DATX8 modules*/
  123. u32 mdlr; /* 0x00 master delay line register */
  124. u32 lcdlr[3]; /* 0x04 local calibrated delay line registers */
  125. u32 bdlr[11]; /* 0x10 bit delay line registers */
  126. u32 sdlr; /* 0x3c output enable bit delay registers */
  127. u32 gtr; /* 0x40 general timing register */
  128. u32 gcr; /* 0x44 general configuration register */
  129. u32 gsr[3]; /* 0x48 general status registers */
  130. u8 res0[0x2c]; /* 0x54 */
  131. } dx[4];
  132. u8 res11[0x388]; /* 0x500 */
  133. u32 upd2; /* 0x888 */
  134. };
  135. #define PTR3_TDINIT1(x) ((x) << 20)
  136. #define PTR3_TDINIT0(x) ((x) << 0)
  137. #define PTR4_TDINIT3(x) ((x) << 20)
  138. #define PTR4_TDINIT2(x) ((x) << 0)
  139. #define DRAMTMG0_TWTP(x) ((x) << 24)
  140. #define DRAMTMG0_TFAW(x) ((x) << 16)
  141. #define DRAMTMG0_TRAS_MAX(x) ((x) << 8)
  142. #define DRAMTMG0_TRAS(x) ((x) << 0)
  143. #define DRAMTMG1_TXP(x) ((x) << 16)
  144. #define DRAMTMG1_TRTP(x) ((x) << 8)
  145. #define DRAMTMG1_TRC(x) ((x) << 0)
  146. #define DRAMTMG2_TCWL(x) ((x) << 24)
  147. #define DRAMTMG2_TCL(x) ((x) << 16)
  148. #define DRAMTMG2_TRD2WR(x) ((x) << 8)
  149. #define DRAMTMG2_TWR2RD(x) ((x) << 0)
  150. #define DRAMTMG3_TMRW(x) ((x) << 16)
  151. #define DRAMTMG3_TMRD(x) ((x) << 12)
  152. #define DRAMTMG3_TMOD(x) ((x) << 0)
  153. #define DRAMTMG4_TRCD(x) ((x) << 24)
  154. #define DRAMTMG4_TCCD(x) ((x) << 16)
  155. #define DRAMTMG4_TRRD(x) ((x) << 8)
  156. #define DRAMTMG4_TRP(x) ((x) << 0)
  157. #define DRAMTMG5_TCKSRX(x) ((x) << 24)
  158. #define DRAMTMG5_TCKSRE(x) ((x) << 16)
  159. #define DRAMTMG5_TCKESR(x) ((x) << 8)
  160. #define DRAMTMG5_TCKE(x) ((x) << 0)
  161. #define RFSHTMG_TREFI(x) ((x) << 16)
  162. #define RFSHTMG_TRFC(x) ((x) << 0)
  163. #define PIR_CLRSR (0x1 << 27) /* clear status registers */
  164. #define PIR_QSGATE (0x1 << 10) /* Read DQS gate training */
  165. #define PIR_DRAMINIT (0x1 << 8) /* DRAM initialization */
  166. #define PIR_DRAMRST (0x1 << 7) /* DRAM reset */
  167. #define PIR_PHYRST (0x1 << 6) /* PHY reset */
  168. #define PIR_DCAL (0x1 << 5) /* DDL calibration */
  169. #define PIR_PLLINIT (0x1 << 4) /* PLL initialization */
  170. #define PIR_ZCAL (0x1 << 1) /* ZQ calibration */
  171. #define PIR_INIT (0x1 << 0) /* PHY initialization trigger */
  172. #define PGSR_INIT_DONE (0x1 << 0) /* PHY init done */
  173. #define ZQCR_PWRDOWN (1U << 31) /* ZQ power down */
  174. #define ACBDLR_WRITE_DELAY(x) ((x) << 8)
  175. #define DXBDLR_DQ(x) (x) /* DQ0-7 BDLR index */
  176. #define DXBDLR_DM 8 /* DM BDLR index */
  177. #define DXBDLR_DQS 9 /* DQS BDLR index */
  178. #define DXBDLR_DQSN 10 /* DQSN BDLR index */
  179. #define DXBDLR_WRITE_DELAY(x) ((x) << 8)
  180. #define DXBDLR_READ_DELAY(x) ((x) << 0)
  181. /*
  182. * The delay parameters below allow to allegedly specify delay times of some
  183. * unknown unit for each individual bit trace in each of the four data bytes
  184. * the 32-bit wide access consists of. Also three control signals can be
  185. * adjusted individually.
  186. */
  187. #define NR_OF_BYTE_LANES (32 / BITS_PER_BYTE)
  188. /* The eight data lines (DQn) plus DM, DQS and DQSN */
  189. #define LINES_PER_BYTE_LANE (BITS_PER_BYTE + 3)
  190. struct dram_para {
  191. u16 page_size;
  192. u8 bus_full_width;
  193. u8 dual_rank;
  194. u8 row_bits;
  195. u8 bank_bits;
  196. const u8 dx_read_delays[NR_OF_BYTE_LANES][LINES_PER_BYTE_LANE];
  197. const u8 dx_write_delays[NR_OF_BYTE_LANES][LINES_PER_BYTE_LANE];
  198. const u8 ac_delays[31];
  199. };
  200. static inline int ns_to_t(int nanoseconds)
  201. {
  202. const unsigned int ctrl_freq = CONFIG_DRAM_CLK / 2;
  203. return DIV_ROUND_UP(ctrl_freq * nanoseconds, 1000);
  204. }
  205. void mctl_set_timing_params(uint16_t socid, struct dram_para *para);
  206. #endif /* _SUNXI_DRAM_SUN8I_H3_H */