ddr_defs.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. /* AM335X EMIF Register values */
  22. #define EMIF_SDMGT 0x80000000
  23. #define EMIF_SDRAM 0x00004650
  24. #define EMIF_PHYCFG 0x2
  25. #define DDR_PHY_RESET (0x1 << 10)
  26. #define DDR_FUNCTIONAL_MODE_EN 0x1
  27. #define DDR_PHY_READY (0x1 << 2)
  28. #define VTP_CTRL_READY (0x1 << 5)
  29. #define VTP_CTRL_ENABLE (0x1 << 6)
  30. #define VTP_CTRL_LOCK_EN (0x1 << 4)
  31. #define VTP_CTRL_START_EN (0x1)
  32. #define DDR2_RATIO 0x80
  33. #define CMD_FORCE 0x00
  34. #define CMD_DELAY 0x00
  35. #define EMIF_READ_LATENCY 0x04
  36. #define EMIF_TIM1 0x0666B3D6
  37. #define EMIF_TIM2 0x143731DA
  38. #define EMIF_TIM3 0x00000347
  39. #define EMIF_SDCFG 0x43805332
  40. #define EMIF_SDREF 0x0000081a
  41. #define DDR2_DLL_LOCK_DIFF 0x0
  42. #define DDR2_RD_DQS 0x12
  43. #define DDR2_PHY_FIFO_WE 0x80
  44. #define DDR2_INVERT_CLKOUT 0x00
  45. #define DDR2_WR_DQS 0x00
  46. #define DDR2_PHY_WRLVL 0x00
  47. #define DDR2_PHY_GATELVL 0x00
  48. #define DDR2_PHY_WR_DATA 0x40
  49. #define PHY_RANK0_DELAY 0x01
  50. #define PHY_DLL_LOCK_DIFF 0x0
  51. #define DDR_IOCTRL_VALUE 0x18B
  52. /**
  53. * This structure represents the EMIF registers on AM33XX devices.
  54. */
  55. struct emif_regs {
  56. unsigned int sdrrev; /* offset 0x00 */
  57. unsigned int sdrstat; /* offset 0x04 */
  58. unsigned int sdrcr; /* offset 0x08 */
  59. unsigned int sdrcr2; /* offset 0x0C */
  60. unsigned int sdrrcr; /* offset 0x10 */
  61. unsigned int sdrrcsr; /* offset 0x14 */
  62. unsigned int sdrtim1; /* offset 0x18 */
  63. unsigned int sdrtim1sr; /* offset 0x1C */
  64. unsigned int sdrtim2; /* offset 0x20 */
  65. unsigned int sdrtim2sr; /* offset 0x24 */
  66. unsigned int sdrtim3; /* offset 0x28 */
  67. unsigned int sdrtim3sr; /* offset 0x2C */
  68. unsigned int res1[2];
  69. unsigned int sdrmcr; /* offset 0x38 */
  70. unsigned int sdrmcsr; /* offset 0x3C */
  71. unsigned int res2[8];
  72. unsigned int sdritr; /* offset 0x60 */
  73. unsigned int res3[32];
  74. unsigned int ddrphycr; /* offset 0xE4 */
  75. unsigned int ddrphycsr; /* offset 0xE8 */
  76. unsigned int ddrphycr2; /* offset 0xEC */
  77. };
  78. /**
  79. * Encapsulates DDR PHY control and corresponding shadow registers.
  80. */
  81. struct ddr_phy_control {
  82. unsigned long reg;
  83. unsigned long reg_sh;
  84. unsigned long reg2;
  85. };
  86. /**
  87. * Encapsulates SDRAM timing and corresponding shadow registers.
  88. */
  89. struct sdram_timing {
  90. unsigned long time1;
  91. unsigned long time1_sh;
  92. unsigned long time2;
  93. unsigned long time2_sh;
  94. unsigned long time3;
  95. unsigned long time3_sh;
  96. };
  97. /**
  98. * Encapsulates SDRAM configuration.
  99. * (Includes refresh control registers) */
  100. struct sdram_config {
  101. unsigned long sdrcr;
  102. unsigned long sdrcr2;
  103. unsigned long refresh;
  104. unsigned long refresh_sh;
  105. };
  106. /**
  107. * Configure SDRAM
  108. */
  109. int config_sdram(struct sdram_config *cfg);
  110. /**
  111. * Set SDRAM timings
  112. */
  113. int set_sdram_timings(struct sdram_timing *val);
  114. /**
  115. * Configure DDR PHY
  116. */
  117. int config_ddr_phy(struct ddr_phy_control *cfg);
  118. /**
  119. * This structure represents the DDR registers on AM33XX devices.
  120. */
  121. struct ddr_regs {
  122. unsigned int resv0[7];
  123. unsigned int cm0csratio; /* offset 0x01C */
  124. unsigned int cm0csforce; /* offset 0x020 */
  125. unsigned int cm0csdelay; /* offset 0x024 */
  126. unsigned int cm0dldiff; /* offset 0x028 */
  127. unsigned int cm0iclkout; /* offset 0x02C */
  128. unsigned int resv1[8];
  129. unsigned int cm1csratio; /* offset 0x050 */
  130. unsigned int cm1csforce; /* offset 0x054 */
  131. unsigned int cm1csdelay; /* offset 0x058 */
  132. unsigned int cm1dldiff; /* offset 0x05C */
  133. unsigned int cm1iclkout; /* offset 0x060 */
  134. unsigned int resv2[8];
  135. unsigned int cm2csratio; /* offset 0x084 */
  136. unsigned int cm2csforce; /* offset 0x088 */
  137. unsigned int cm2csdelay; /* offset 0x08C */
  138. unsigned int cm2dldiff; /* offset 0x090 */
  139. unsigned int cm2iclkout; /* offset 0x094 */
  140. unsigned int resv3[12];
  141. unsigned int dt0rdsratio0; /* offset 0x0C8 */
  142. unsigned int dt0rdsratio1; /* offset 0x0CC */
  143. unsigned int resv4[3];
  144. unsigned int dt0wdsratio0; /* offset 0x0DC */
  145. unsigned int dt0wdsratio1; /* offset 0x0E0 */
  146. unsigned int resv5[3];
  147. unsigned int dt0wiratio0; /* offset 0x0F0 */
  148. unsigned int dt0wiratio1; /* offset 0x0F4 */
  149. unsigned int dt0giratio0; /* offset 0x0FC */
  150. unsigned int dt0giratio1; /* offset 0x100 */
  151. unsigned int resv6[1];
  152. unsigned int dt0fwsratio0; /* offset 0x108 */
  153. unsigned int dt0fwsratio1; /* offset 0x10C */
  154. unsigned int resv7[4];
  155. unsigned int dt0wrsratio0; /* offset 0x120 */
  156. unsigned int dt0wrsratio1; /* offset 0x124 */
  157. unsigned int resv8[3];
  158. unsigned int dt0rdelays0; /* offset 0x134 */
  159. unsigned int dt0dldiff0; /* offset 0x138 */
  160. unsigned int resv9[39];
  161. unsigned int dt1rdelays0; /* offset 0x1D8 */
  162. };
  163. /**
  164. * Encapsulates DDR CMD control registers.
  165. */
  166. struct cmd_control {
  167. unsigned long cmd0csratio;
  168. unsigned long cmd0csforce;
  169. unsigned long cmd0csdelay;
  170. unsigned long cmd0dldiff;
  171. unsigned long cmd0iclkout;
  172. unsigned long cmd1csratio;
  173. unsigned long cmd1csforce;
  174. unsigned long cmd1csdelay;
  175. unsigned long cmd1dldiff;
  176. unsigned long cmd1iclkout;
  177. unsigned long cmd2csratio;
  178. unsigned long cmd2csforce;
  179. unsigned long cmd2csdelay;
  180. unsigned long cmd2dldiff;
  181. unsigned long cmd2iclkout;
  182. };
  183. /**
  184. * Encapsulates DDR DATA registers.
  185. */
  186. struct ddr_data {
  187. unsigned long datardsratio0;
  188. unsigned long datardsratio1;
  189. unsigned long datawdsratio0;
  190. unsigned long datawdsratio1;
  191. unsigned long datawiratio0;
  192. unsigned long datawiratio1;
  193. unsigned long datagiratio0;
  194. unsigned long datagiratio1;
  195. unsigned long datafwsratio0;
  196. unsigned long datafwsratio1;
  197. unsigned long datawrsratio0;
  198. unsigned long datawrsratio1;
  199. unsigned long datadldiff0;
  200. };
  201. /**
  202. * Configure DDR CMD control registers
  203. */
  204. int config_cmd_ctrl(struct cmd_control *cmd);
  205. /**
  206. * Configure DDR DATA registers
  207. */
  208. int config_ddr_data(int data_macrono, struct ddr_data *data);
  209. /**
  210. * This structure represents the DDR io control on AM33XX devices.
  211. */
  212. struct ddr_cmdtctrl {
  213. unsigned int resv1[1];
  214. unsigned int cm0ioctl;
  215. unsigned int cm1ioctl;
  216. unsigned int cm2ioctl;
  217. unsigned int resv2[12];
  218. unsigned int dt0ioctl;
  219. unsigned int dt1ioctl;
  220. };
  221. /**
  222. * Encapsulates DDR CMD & DATA io control registers.
  223. */
  224. struct ddr_ioctrl {
  225. unsigned long cmd1ctl;
  226. unsigned long cmd2ctl;
  227. unsigned long cmd3ctl;
  228. unsigned long data1ctl;
  229. unsigned long data2ctl;
  230. };
  231. /**
  232. * Configure DDR io control registers
  233. */
  234. int config_io_ctrl(struct ddr_ioctrl *ioctrl);
  235. struct ddr_ctrl {
  236. unsigned int ddrioctrl;
  237. unsigned int resv1[325];
  238. unsigned int ddrckectrl;
  239. };
  240. void config_ddr(void);
  241. #endif /* _DDR_DEFS_H */