ddr_defs.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * ddr_defs.h
  3. *
  4. * ddr specific header
  5. *
  6. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #ifndef _DDR_DEFS_H
  19. #define _DDR_DEFS_H
  20. #include <asm/arch/hardware.h>
  21. #include <asm/emif.h>
  22. /* AM335X EMIF Register values */
  23. #define VTP_CTRL_READY (0x1 << 5)
  24. #define VTP_CTRL_ENABLE (0x1 << 6)
  25. #define VTP_CTRL_START_EN (0x1)
  26. #define PHY_DLL_LOCK_DIFF 0x0
  27. #define DDR_CKE_CTRL_NORMAL 0x1
  28. #define PHY_EN_DYN_PWRDN (0x1 << 20)
  29. /* Micron MT47H128M16RT-25E */
  30. #define MT47H128M16RT25E_EMIF_READ_LATENCY 0x100005
  31. #define MT47H128M16RT25E_EMIF_TIM1 0x0666B3C9
  32. #define MT47H128M16RT25E_EMIF_TIM2 0x243631CA
  33. #define MT47H128M16RT25E_EMIF_TIM3 0x0000033F
  34. #define MT47H128M16RT25E_EMIF_SDCFG 0x41805332
  35. #define MT47H128M16RT25E_EMIF_SDREF 0x0000081a
  36. #define MT47H128M16RT25E_DLL_LOCK_DIFF 0x0
  37. #define MT47H128M16RT25E_RATIO 0x80
  38. #define MT47H128M16RT25E_INVERT_CLKOUT 0x00
  39. #define MT47H128M16RT25E_RD_DQS 0x12
  40. #define MT47H128M16RT25E_WR_DQS 0x00
  41. #define MT47H128M16RT25E_PHY_WRLVL 0x00
  42. #define MT47H128M16RT25E_PHY_GATELVL 0x00
  43. #define MT47H128M16RT25E_PHY_WR_DATA 0x40
  44. #define MT47H128M16RT25E_PHY_FIFO_WE 0x80
  45. #define MT47H128M16RT25E_PHY_RANK0_DELAY 0x1
  46. #define MT47H128M16RT25E_IOCTRL_VALUE 0x18B
  47. /* Micron MT41J128M16JT-125 */
  48. #define MT41J128MJT125_EMIF_READ_LATENCY 0x06
  49. #define MT41J128MJT125_EMIF_TIM1 0x0888A39B
  50. #define MT41J128MJT125_EMIF_TIM2 0x26337FDA
  51. #define MT41J128MJT125_EMIF_TIM3 0x501F830F
  52. #define MT41J128MJT125_EMIF_SDCFG 0x61C04AB2
  53. #define MT41J128MJT125_EMIF_SDREF 0x0000093B
  54. #define MT41J128MJT125_ZQ_CFG 0x50074BE4
  55. #define MT41J128MJT125_DLL_LOCK_DIFF 0x1
  56. #define MT41J128MJT125_RATIO 0x40
  57. #define MT41J128MJT125_INVERT_CLKOUT 0x1
  58. #define MT41J128MJT125_RD_DQS 0x3B
  59. #define MT41J128MJT125_WR_DQS 0x85
  60. #define MT41J128MJT125_PHY_WR_DATA 0xC1
  61. #define MT41J128MJT125_PHY_FIFO_WE 0x100
  62. #define MT41J128MJT125_IOCTRL_VALUE 0x18B
  63. /* Micron MT41J256M8HX-15E */
  64. #define MT41J256M8HX15E_EMIF_READ_LATENCY 0x06
  65. #define MT41J256M8HX15E_EMIF_TIM1 0x0888A39B
  66. #define MT41J256M8HX15E_EMIF_TIM2 0x26337FDA
  67. #define MT41J256M8HX15E_EMIF_TIM3 0x501F830F
  68. #define MT41J256M8HX15E_EMIF_SDCFG 0x61C04B32
  69. #define MT41J256M8HX15E_EMIF_SDREF 0x0000093B
  70. #define MT41J256M8HX15E_ZQ_CFG 0x50074BE4
  71. #define MT41J256M8HX15E_DLL_LOCK_DIFF 0x1
  72. #define MT41J256M8HX15E_RATIO 0x40
  73. #define MT41J256M8HX15E_INVERT_CLKOUT 0x1
  74. #define MT41J256M8HX15E_RD_DQS 0x3B
  75. #define MT41J256M8HX15E_WR_DQS 0x85
  76. #define MT41J256M8HX15E_PHY_WR_DATA 0xC1
  77. #define MT41J256M8HX15E_PHY_FIFO_WE 0x100
  78. #define MT41J256M8HX15E_IOCTRL_VALUE 0x18B
  79. /* Micron MT41J512M8RH-125 on EVM v1.5 */
  80. #define MT41J512M8RH125_EMIF_READ_LATENCY 0x06
  81. #define MT41J512M8RH125_EMIF_TIM1 0x0888A39B
  82. #define MT41J512M8RH125_EMIF_TIM2 0x26517FDA
  83. #define MT41J512M8RH125_EMIF_TIM3 0x501F84EF
  84. #define MT41J512M8RH125_EMIF_SDCFG 0x61C04BB2
  85. #define MT41J512M8RH125_EMIF_SDREF 0x0000093B
  86. #define MT41J512M8RH125_ZQ_CFG 0x50074BE4
  87. #define MT41J512M8RH125_DLL_LOCK_DIFF 0x1
  88. #define MT41J512M8RH125_RATIO 0x80
  89. #define MT41J512M8RH125_INVERT_CLKOUT 0x0
  90. #define MT41J512M8RH125_RD_DQS 0x3B
  91. #define MT41J512M8RH125_WR_DQS 0x3C
  92. #define MT41J512M8RH125_PHY_FIFO_WE 0xA5
  93. #define MT41J512M8RH125_PHY_WR_DATA 0x74
  94. #define MT41J512M8RH125_IOCTRL_VALUE 0x18B
  95. /**
  96. * Configure SDRAM
  97. */
  98. void config_sdram(const struct emif_regs *regs, int nr);
  99. /**
  100. * Set SDRAM timings
  101. */
  102. void set_sdram_timings(const struct emif_regs *regs, int nr);
  103. /**
  104. * Configure DDR PHY
  105. */
  106. void config_ddr_phy(const struct emif_regs *regs, int nr);
  107. struct ddr_cmd_regs {
  108. unsigned int resv0[7];
  109. unsigned int cm0csratio; /* offset 0x01C */
  110. unsigned int resv1[2];
  111. unsigned int cm0dldiff; /* offset 0x028 */
  112. unsigned int cm0iclkout; /* offset 0x02C */
  113. unsigned int resv2[8];
  114. unsigned int cm1csratio; /* offset 0x050 */
  115. unsigned int resv3[2];
  116. unsigned int cm1dldiff; /* offset 0x05C */
  117. unsigned int cm1iclkout; /* offset 0x060 */
  118. unsigned int resv4[8];
  119. unsigned int cm2csratio; /* offset 0x084 */
  120. unsigned int resv5[2];
  121. unsigned int cm2dldiff; /* offset 0x090 */
  122. unsigned int cm2iclkout; /* offset 0x094 */
  123. unsigned int resv6[3];
  124. };
  125. struct ddr_data_regs {
  126. unsigned int dt0rdsratio0; /* offset 0x0C8 */
  127. unsigned int resv1[4];
  128. unsigned int dt0wdsratio0; /* offset 0x0DC */
  129. unsigned int resv2[4];
  130. unsigned int dt0wiratio0; /* offset 0x0F0 */
  131. unsigned int resv3;
  132. unsigned int dt0wimode0; /* offset 0x0F8 */
  133. unsigned int dt0giratio0; /* offset 0x0FC */
  134. unsigned int resv4;
  135. unsigned int dt0gimode0; /* offset 0x104 */
  136. unsigned int dt0fwsratio0; /* offset 0x108 */
  137. unsigned int resv5[4];
  138. unsigned int dt0dqoffset; /* offset 0x11C */
  139. unsigned int dt0wrsratio0; /* offset 0x120 */
  140. unsigned int resv6[4];
  141. unsigned int dt0rdelays0; /* offset 0x134 */
  142. unsigned int dt0dldiff0; /* offset 0x138 */
  143. unsigned int resv7[12];
  144. };
  145. /**
  146. * This structure represents the DDR registers on AM33XX devices.
  147. * We make use of DDR_PHY_BASE_ADDR2 to address the DATA1 registers that
  148. * correspond to DATA1 registers defined here.
  149. */
  150. struct ddr_regs {
  151. unsigned int resv0[7];
  152. unsigned int cm0csratio; /* offset 0x01C */
  153. unsigned int resv1[2];
  154. unsigned int cm0dldiff; /* offset 0x028 */
  155. unsigned int cm0iclkout; /* offset 0x02C */
  156. unsigned int resv2[8];
  157. unsigned int cm1csratio; /* offset 0x050 */
  158. unsigned int resv3[2];
  159. unsigned int cm1dldiff; /* offset 0x05C */
  160. unsigned int cm1iclkout; /* offset 0x060 */
  161. unsigned int resv4[8];
  162. unsigned int cm2csratio; /* offset 0x084 */
  163. unsigned int resv5[2];
  164. unsigned int cm2dldiff; /* offset 0x090 */
  165. unsigned int cm2iclkout; /* offset 0x094 */
  166. unsigned int resv6[12];
  167. unsigned int dt0rdsratio0; /* offset 0x0C8 */
  168. unsigned int resv7[4];
  169. unsigned int dt0wdsratio0; /* offset 0x0DC */
  170. unsigned int resv8[4];
  171. unsigned int dt0wiratio0; /* offset 0x0F0 */
  172. unsigned int resv9;
  173. unsigned int dt0wimode0; /* offset 0x0F8 */
  174. unsigned int dt0giratio0; /* offset 0x0FC */
  175. unsigned int resv10;
  176. unsigned int dt0gimode0; /* offset 0x104 */
  177. unsigned int dt0fwsratio0; /* offset 0x108 */
  178. unsigned int resv11[4];
  179. unsigned int dt0dqoffset; /* offset 0x11C */
  180. unsigned int dt0wrsratio0; /* offset 0x120 */
  181. unsigned int resv12[4];
  182. unsigned int dt0rdelays0; /* offset 0x134 */
  183. unsigned int dt0dldiff0; /* offset 0x138 */
  184. };
  185. /**
  186. * Encapsulates DDR CMD control registers.
  187. */
  188. struct cmd_control {
  189. unsigned long cmd0csratio;
  190. unsigned long cmd0csforce;
  191. unsigned long cmd0csdelay;
  192. unsigned long cmd0dldiff;
  193. unsigned long cmd0iclkout;
  194. unsigned long cmd1csratio;
  195. unsigned long cmd1csforce;
  196. unsigned long cmd1csdelay;
  197. unsigned long cmd1dldiff;
  198. unsigned long cmd1iclkout;
  199. unsigned long cmd2csratio;
  200. unsigned long cmd2csforce;
  201. unsigned long cmd2csdelay;
  202. unsigned long cmd2dldiff;
  203. unsigned long cmd2iclkout;
  204. };
  205. /**
  206. * Encapsulates DDR DATA registers.
  207. */
  208. struct ddr_data {
  209. unsigned long datardsratio0;
  210. unsigned long datawdsratio0;
  211. unsigned long datawiratio0;
  212. unsigned long datagiratio0;
  213. unsigned long datafwsratio0;
  214. unsigned long datawrsratio0;
  215. unsigned long datauserank0delay;
  216. unsigned long datadldiff0;
  217. };
  218. /**
  219. * Configure DDR CMD control registers
  220. */
  221. void config_cmd_ctrl(const struct cmd_control *cmd, int nr);
  222. /**
  223. * Configure DDR DATA registers
  224. */
  225. void config_ddr_data(const struct ddr_data *data, int nr);
  226. /**
  227. * This structure represents the DDR io control on AM33XX devices.
  228. */
  229. struct ddr_cmdtctrl {
  230. unsigned int resv1[1];
  231. unsigned int cm0ioctl;
  232. unsigned int cm1ioctl;
  233. unsigned int cm2ioctl;
  234. unsigned int resv2[12];
  235. unsigned int dt0ioctl;
  236. unsigned int dt1ioctl;
  237. };
  238. /**
  239. * Configure DDR io control registers
  240. */
  241. void config_io_ctrl(unsigned long val);
  242. struct ddr_ctrl {
  243. unsigned int ddrioctrl;
  244. unsigned int resv1[325];
  245. unsigned int ddrckectrl;
  246. };
  247. void config_ddr(unsigned int pll, unsigned int ioctrl,
  248. const struct ddr_data *data, const struct cmd_control *ctrl,
  249. const struct emif_regs *regs, int nr);
  250. #endif /* _DDR_DEFS_H */