sdram.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. * Timing and Organization details of the ddr device parts used in OMAP5
  3. * EVM
  4. *
  5. * (C) Copyright 2010
  6. * Texas Instruments, <www.ti.com>
  7. *
  8. * Aneesh V <aneesh@ti.com>
  9. * Sricharan R <r.sricharan@ti.com>
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <asm/emif.h>
  30. #include <asm/arch/sys_proto.h>
  31. /*
  32. * This file provides details of the LPDDR2 SDRAM parts used on OMAP5
  33. * EVM. Since the parts used and geometry are identical for
  34. * evm for a given OMAP5 revision, this information is kept
  35. * here instead of being in board directory. However the key functions
  36. * exported are weakly linked so that they can be over-ridden in the board
  37. * directory if there is a OMAP5 board in the future that uses a different
  38. * memory device or geometry.
  39. *
  40. * For any new board with different memory devices over-ride one or more
  41. * of the following functions as per the CONFIG flags you intend to enable:
  42. * - emif_get_reg_dump()
  43. * - emif_get_dmm_regs()
  44. * - emif_get_device_details()
  45. * - emif_get_device_timings()
  46. */
  47. #ifdef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS
  48. const struct emif_regs emif_regs_532_mhz_2cs = {
  49. .sdram_config_init = 0x80800EBA,
  50. .sdram_config = 0x808022BA,
  51. .ref_ctrl = 0x0000081A,
  52. .sdram_tim1 = 0x772F6873,
  53. .sdram_tim2 = 0x304a129a,
  54. .sdram_tim3 = 0x02f7e45f,
  55. .read_idle_ctrl = 0x00050000,
  56. .zq_config = 0x000b3215,
  57. .temp_alert_config = 0x08000a05,
  58. .emif_ddr_phy_ctlr_1_init = 0x0E28420d,
  59. .emif_ddr_phy_ctlr_1 = 0x0E28420d,
  60. .emif_ddr_ext_phy_ctrl_1 = 0x04020080,
  61. .emif_ddr_ext_phy_ctrl_2 = 0x28C518A3,
  62. .emif_ddr_ext_phy_ctrl_3 = 0x518A3146,
  63. .emif_ddr_ext_phy_ctrl_4 = 0x0014628C,
  64. .emif_ddr_ext_phy_ctrl_5 = 0x04010040
  65. };
  66. const struct emif_regs emif_regs_266_mhz_2cs = {
  67. .sdram_config_init = 0x80800EBA,
  68. .sdram_config = 0x808022BA,
  69. .ref_ctrl = 0x0000040D,
  70. .sdram_tim1 = 0x2A86B419,
  71. .sdram_tim2 = 0x1025094A,
  72. .sdram_tim3 = 0x026BA22F,
  73. .read_idle_ctrl = 0x00050000,
  74. .zq_config = 0x000b3215,
  75. .temp_alert_config = 0x08000a05,
  76. .emif_ddr_phy_ctlr_1_init = 0x0E28420d,
  77. .emif_ddr_phy_ctlr_1 = 0x0E28420d,
  78. .emif_ddr_ext_phy_ctrl_1 = 0x04020080,
  79. .emif_ddr_ext_phy_ctrl_2 = 0x0A414829,
  80. .emif_ddr_ext_phy_ctrl_3 = 0x14829052,
  81. .emif_ddr_ext_phy_ctrl_4 = 0x000520A4,
  82. .emif_ddr_ext_phy_ctrl_5 = 0x04010040
  83. };
  84. const struct emif_regs emif_regs_ddr3_532_mhz_1cs = {
  85. .sdram_config_init = 0x61851B32,
  86. .sdram_config = 0x61851B32,
  87. .ref_ctrl = 0x00001035,
  88. .sdram_tim1 = 0xCCCF36B3,
  89. .sdram_tim2 = 0x308F7FDA,
  90. .sdram_tim3 = 0x027F88A8,
  91. .read_idle_ctrl = 0x00050000,
  92. .zq_config = 0x0007190B,
  93. .temp_alert_config = 0x00000000,
  94. .emif_ddr_phy_ctlr_1_init = 0x0020420A,
  95. .emif_ddr_phy_ctlr_1 = 0x0024420A,
  96. .emif_ddr_ext_phy_ctrl_1 = 0x04040100,
  97. .emif_ddr_ext_phy_ctrl_2 = 0x00000000,
  98. .emif_ddr_ext_phy_ctrl_3 = 0x00000000,
  99. .emif_ddr_ext_phy_ctrl_4 = 0x00000000,
  100. .emif_ddr_ext_phy_ctrl_5 = 0x04010040,
  101. .emif_rd_wr_lvl_rmp_win = 0x00000000,
  102. .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
  103. .emif_rd_wr_lvl_ctl = 0x00000000,
  104. .emif_rd_wr_exec_thresh = 0x00000305
  105. };
  106. const struct dmm_lisa_map_regs lisa_map_4G_x_2_x_2 = {
  107. .dmm_lisa_map_0 = 0x0,
  108. .dmm_lisa_map_1 = 0x0,
  109. .dmm_lisa_map_2 = 0x80740300,
  110. .dmm_lisa_map_3 = 0xFF020100
  111. };
  112. const u32 ext_phy_ctrl_const_base[EMIF_EXT_PHY_CTRL_CONST_REG] = {
  113. 0x01004010,
  114. 0x00001004,
  115. 0x04010040,
  116. 0x01004010,
  117. 0x00001004,
  118. 0x00000000,
  119. 0x00000000,
  120. 0x00000000,
  121. 0x80080080,
  122. 0x00800800,
  123. 0x08102040,
  124. 0x00000001,
  125. 0x540A8150,
  126. 0xA81502a0,
  127. 0x002A0540,
  128. 0x00000000,
  129. 0x00000000,
  130. 0x00000000,
  131. 0x00000077
  132. };
  133. const u32 ddr3_ext_phy_ctrl_const_base[EMIF_EXT_PHY_CTRL_CONST_REG] = {
  134. 0x01004010,
  135. 0x00001004,
  136. 0x04010040,
  137. 0x01004010,
  138. 0x00001004,
  139. 0x00000000,
  140. 0x00000000,
  141. 0x00000000,
  142. 0x80080080,
  143. 0x00800800,
  144. 0x08102040,
  145. 0x00000002,
  146. 0x0,
  147. 0x0,
  148. 0x0,
  149. 0x00000000,
  150. 0x00000000,
  151. 0x00000000,
  152. 0x00000057
  153. };
  154. static void emif_get_reg_dump_sdp(u32 emif_nr, const struct emif_regs **regs)
  155. {
  156. if (omap_revision() == OMAP5432_ES1_0)
  157. *regs = &emif_regs_ddr3_532_mhz_1cs;
  158. else
  159. *regs = &emif_regs_532_mhz_2cs;
  160. }
  161. void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
  162. __attribute__((weak, alias("emif_get_reg_dump_sdp")));
  163. static void emif_get_dmm_regs_sdp(const struct dmm_lisa_map_regs
  164. **dmm_lisa_regs)
  165. {
  166. *dmm_lisa_regs = &lisa_map_4G_x_2_x_2;
  167. }
  168. void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
  169. __attribute__((weak, alias("emif_get_dmm_regs_sdp")));
  170. #else
  171. static const struct lpddr2_device_details dev_4G_S4_details = {
  172. .type = LPDDR2_TYPE_S4,
  173. .density = LPDDR2_DENSITY_4Gb,
  174. .io_width = LPDDR2_IO_WIDTH_32,
  175. .manufacturer = LPDDR2_MANUFACTURER_SAMSUNG
  176. };
  177. static void emif_get_device_details_sdp(u32 emif_nr,
  178. struct lpddr2_device_details *cs0_device_details,
  179. struct lpddr2_device_details *cs1_device_details)
  180. {
  181. /* EMIF1 & EMIF2 have identical configuration */
  182. *cs0_device_details = dev_4G_S4_details;
  183. *cs1_device_details = dev_4G_S4_details;
  184. }
  185. void emif_get_device_details(u32 emif_nr,
  186. struct lpddr2_device_details *cs0_device_details,
  187. struct lpddr2_device_details *cs1_device_details)
  188. __attribute__((weak, alias("emif_get_device_details_sdp")));
  189. #endif /* CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS */
  190. void do_ext_phy_settings(u32 base, const struct emif_regs *regs)
  191. {
  192. u32 *ext_phy_ctrl_base = 0;
  193. u32 *emif_ext_phy_ctrl_base = 0;
  194. u32 i = 0;
  195. struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
  196. ext_phy_ctrl_base = (u32 *) &(regs->emif_ddr_ext_phy_ctrl_1);
  197. emif_ext_phy_ctrl_base = (u32 *) &(emif->emif_ddr_ext_phy_ctrl_1);
  198. /* Configure external phy control timing registers */
  199. for (i = 0; i < EMIF_EXT_PHY_CTRL_TIMING_REG; i++) {
  200. writel(*ext_phy_ctrl_base, emif_ext_phy_ctrl_base++);
  201. /* Update shadow registers */
  202. writel(*ext_phy_ctrl_base++, emif_ext_phy_ctrl_base++);
  203. }
  204. /*
  205. * external phy 6-24 registers do not change with
  206. * ddr frequency
  207. */
  208. for (i = 0; i < EMIF_EXT_PHY_CTRL_CONST_REG; i++) {
  209. writel(ext_phy_ctrl_const_base[i],
  210. emif_ext_phy_ctrl_base++);
  211. /* Update shadow registers */
  212. writel(ext_phy_ctrl_const_base[i],
  213. emif_ext_phy_ctrl_base++);
  214. }
  215. }
  216. #ifndef CONFIG_SYS_DEFAULT_LPDDR2_TIMINGS
  217. static const struct lpddr2_ac_timings timings_jedec_532_mhz = {
  218. .max_freq = 532000000,
  219. .RL = 8,
  220. .tRPab = 21,
  221. .tRCD = 18,
  222. .tWR = 15,
  223. .tRASmin = 42,
  224. .tRRD = 10,
  225. .tWTRx2 = 15,
  226. .tXSR = 140,
  227. .tXPx2 = 15,
  228. .tRFCab = 130,
  229. .tRTPx2 = 15,
  230. .tCKE = 3,
  231. .tCKESR = 15,
  232. .tZQCS = 90,
  233. .tZQCL = 360,
  234. .tZQINIT = 1000,
  235. .tDQSCKMAXx2 = 11,
  236. .tRASmax = 70,
  237. .tFAW = 50
  238. };
  239. static const struct lpddr2_min_tck min_tck = {
  240. .tRL = 3,
  241. .tRP_AB = 3,
  242. .tRCD = 3,
  243. .tWR = 3,
  244. .tRAS_MIN = 3,
  245. .tRRD = 2,
  246. .tWTR = 2,
  247. .tXP = 2,
  248. .tRTP = 2,
  249. .tCKE = 3,
  250. .tCKESR = 3,
  251. .tFAW = 8
  252. };
  253. static const struct lpddr2_ac_timings *ac_timings[MAX_NUM_SPEEDBINS] = {
  254. &timings_jedec_532_mhz
  255. };
  256. static const struct lpddr2_device_timings dev_4G_S4_timings = {
  257. .ac_timings = ac_timings,
  258. .min_tck = &min_tck,
  259. };
  260. void emif_get_device_timings_sdp(u32 emif_nr,
  261. const struct lpddr2_device_timings **cs0_device_timings,
  262. const struct lpddr2_device_timings **cs1_device_timings)
  263. {
  264. /* Identical devices on EMIF1 & EMIF2 */
  265. *cs0_device_timings = &dev_4G_S4_timings;
  266. *cs1_device_timings = &dev_4G_S4_timings;
  267. }
  268. void emif_get_device_timings(u32 emif_nr,
  269. const struct lpddr2_device_timings **cs0_device_timings,
  270. const struct lpddr2_device_timings **cs1_device_timings)
  271. __attribute__((weak, alias("emif_get_device_timings_sdp")));
  272. #endif /* CONFIG_SYS_DEFAULT_LPDDR2_TIMINGS */