dmc_init_ddr3.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * DDR3 mem setup file for SMDK5250 board based on EXYNOS5
  3. *
  4. * Copyright (C) 2012 Samsung Electronics
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <config.h>
  25. #include <asm/io.h>
  26. #include <asm/arch/clock.h>
  27. #include <asm/arch/cpu.h>
  28. #include <asm/arch/dmc.h>
  29. #include "setup.h"
  30. #include "clock_init.h"
  31. #define RDLVL_COMPLETE_TIMEOUT 10000
  32. static void reset_phy_ctrl(void)
  33. {
  34. struct exynos5_clock *clk = (struct exynos5_clock *)EXYNOS5_CLOCK_BASE;
  35. writel(DDR3PHY_CTRL_PHY_RESET_OFF, &clk->lpddr3phy_ctrl);
  36. writel(DDR3PHY_CTRL_PHY_RESET, &clk->lpddr3phy_ctrl);
  37. }
  38. int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long mem_iv_size)
  39. {
  40. unsigned int val;
  41. struct exynos5_phy_control *phy0_ctrl, *phy1_ctrl;
  42. struct exynos5_dmc *dmc;
  43. int i;
  44. phy0_ctrl = (struct exynos5_phy_control *)EXYNOS5_DMC_PHY0_BASE;
  45. phy1_ctrl = (struct exynos5_phy_control *)EXYNOS5_DMC_PHY1_BASE;
  46. dmc = (struct exynos5_dmc *)EXYNOS5_DMC_CTRL_BASE;
  47. reset_phy_ctrl();
  48. /* Set Impedance Output Driver */
  49. val = (mem->impedance << CA_CK_DRVR_DS_OFFSET) |
  50. (mem->impedance << CA_CKE_DRVR_DS_OFFSET) |
  51. (mem->impedance << CA_CS_DRVR_DS_OFFSET) |
  52. (mem->impedance << CA_ADR_DRVR_DS_OFFSET);
  53. writel(val, &phy0_ctrl->phy_con39);
  54. writel(val, &phy1_ctrl->phy_con39);
  55. /* Set Read Latency and Burst Length for PHY0 and PHY1 */
  56. val = (mem->ctrl_bstlen << PHY_CON42_CTRL_BSTLEN_SHIFT) |
  57. (mem->ctrl_rdlat << PHY_CON42_CTRL_RDLAT_SHIFT);
  58. writel(val, &phy0_ctrl->phy_con42);
  59. writel(val, &phy1_ctrl->phy_con42);
  60. /* ZQ Calibration */
  61. if (dmc_config_zq(mem, phy0_ctrl, phy1_ctrl))
  62. return SETUP_ERR_ZQ_CALIBRATION_FAILURE;
  63. /* DQ Signal */
  64. writel(mem->phy0_pulld_dqs, &phy0_ctrl->phy_con14);
  65. writel(mem->phy1_pulld_dqs, &phy1_ctrl->phy_con14);
  66. writel(mem->concontrol | (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)
  67. | (mem->dfi_init_start << CONCONTROL_DFI_INIT_START_SHIFT),
  68. &dmc->concontrol);
  69. update_reset_dll(dmc, DDR_MODE_DDR3);
  70. /* DQS Signal */
  71. writel(mem->phy0_dqs, &phy0_ctrl->phy_con4);
  72. writel(mem->phy1_dqs, &phy1_ctrl->phy_con4);
  73. writel(mem->phy0_dq, &phy0_ctrl->phy_con6);
  74. writel(mem->phy1_dq, &phy1_ctrl->phy_con6);
  75. writel(mem->phy0_tFS, &phy0_ctrl->phy_con10);
  76. writel(mem->phy1_tFS, &phy1_ctrl->phy_con10);
  77. val = (mem->ctrl_start_point << PHY_CON12_CTRL_START_POINT_SHIFT) |
  78. (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
  79. (mem->ctrl_dll_on << PHY_CON12_CTRL_DLL_ON_SHIFT) |
  80. (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
  81. writel(val, &phy0_ctrl->phy_con12);
  82. writel(val, &phy1_ctrl->phy_con12);
  83. /* Start DLL locking */
  84. writel(val | (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
  85. &phy0_ctrl->phy_con12);
  86. writel(val | (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
  87. &phy1_ctrl->phy_con12);
  88. update_reset_dll(dmc, DDR_MODE_DDR3);
  89. writel(mem->concontrol | (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT),
  90. &dmc->concontrol);
  91. /* Memory Channel Inteleaving Size */
  92. writel(mem->iv_size, &dmc->ivcontrol);
  93. writel(mem->memconfig, &dmc->memconfig0);
  94. writel(mem->memconfig, &dmc->memconfig1);
  95. writel(mem->membaseconfig0, &dmc->membaseconfig0);
  96. writel(mem->membaseconfig1, &dmc->membaseconfig1);
  97. /* Precharge Configuration */
  98. writel(mem->prechconfig_tp_cnt << PRECHCONFIG_TP_CNT_SHIFT,
  99. &dmc->prechconfig);
  100. /* Power Down mode Configuration */
  101. writel(mem->dpwrdn_cyc << PWRDNCONFIG_DPWRDN_CYC_SHIFT |
  102. mem->dsref_cyc << PWRDNCONFIG_DSREF_CYC_SHIFT,
  103. &dmc->pwrdnconfig);
  104. /* TimingRow, TimingData, TimingPower and Timingaref
  105. * values as per Memory AC parameters
  106. */
  107. writel(mem->timing_ref, &dmc->timingref);
  108. writel(mem->timing_row, &dmc->timingrow);
  109. writel(mem->timing_data, &dmc->timingdata);
  110. writel(mem->timing_power, &dmc->timingpower);
  111. /* Send PALL command */
  112. dmc_config_prech(mem, dmc);
  113. /* Send NOP, MRS and ZQINIT commands */
  114. dmc_config_mrs(mem, dmc);
  115. if (mem->gate_leveling_enable) {
  116. val = PHY_CON0_RESET_VAL;
  117. val |= P0_CMD_EN;
  118. writel(val, &phy0_ctrl->phy_con0);
  119. writel(val, &phy1_ctrl->phy_con0);
  120. val = PHY_CON2_RESET_VAL;
  121. val |= INIT_DESKEW_EN;
  122. writel(val, &phy0_ctrl->phy_con2);
  123. writel(val, &phy1_ctrl->phy_con2);
  124. val = PHY_CON0_RESET_VAL;
  125. val |= P0_CMD_EN;
  126. val |= BYTE_RDLVL_EN;
  127. writel(val, &phy0_ctrl->phy_con0);
  128. writel(val, &phy1_ctrl->phy_con0);
  129. val = (mem->ctrl_start_point <<
  130. PHY_CON12_CTRL_START_POINT_SHIFT) |
  131. (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
  132. (mem->ctrl_force << PHY_CON12_CTRL_FORCE_SHIFT) |
  133. (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT) |
  134. (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
  135. writel(val, &phy0_ctrl->phy_con12);
  136. writel(val, &phy1_ctrl->phy_con12);
  137. val = PHY_CON2_RESET_VAL;
  138. val |= INIT_DESKEW_EN;
  139. val |= RDLVL_GATE_EN;
  140. writel(val, &phy0_ctrl->phy_con2);
  141. writel(val, &phy1_ctrl->phy_con2);
  142. val = PHY_CON0_RESET_VAL;
  143. val |= P0_CMD_EN;
  144. val |= BYTE_RDLVL_EN;
  145. val |= CTRL_SHGATE;
  146. writel(val, &phy0_ctrl->phy_con0);
  147. writel(val, &phy1_ctrl->phy_con0);
  148. val = PHY_CON1_RESET_VAL;
  149. val &= ~(CTRL_GATEDURADJ_MASK);
  150. writel(val, &phy0_ctrl->phy_con1);
  151. writel(val, &phy1_ctrl->phy_con1);
  152. writel(CTRL_RDLVL_GATE_ENABLE, &dmc->rdlvl_config);
  153. i = RDLVL_COMPLETE_TIMEOUT;
  154. while ((readl(&dmc->phystatus) &
  155. (RDLVL_COMPLETE_CHO | RDLVL_COMPLETE_CH1)) !=
  156. (RDLVL_COMPLETE_CHO | RDLVL_COMPLETE_CH1) && i > 0) {
  157. /*
  158. * TODO(waihong): Comment on how long this take to
  159. * timeout
  160. */
  161. sdelay(100);
  162. i--;
  163. }
  164. if (!i)
  165. return SETUP_ERR_RDLV_COMPLETE_TIMEOUT;
  166. writel(CTRL_RDLVL_GATE_DISABLE, &dmc->rdlvl_config);
  167. writel(0, &phy0_ctrl->phy_con14);
  168. writel(0, &phy1_ctrl->phy_con14);
  169. val = (mem->ctrl_start_point <<
  170. PHY_CON12_CTRL_START_POINT_SHIFT) |
  171. (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
  172. (mem->ctrl_force << PHY_CON12_CTRL_FORCE_SHIFT) |
  173. (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT) |
  174. (mem->ctrl_dll_on << PHY_CON12_CTRL_DLL_ON_SHIFT) |
  175. (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
  176. writel(val, &phy0_ctrl->phy_con12);
  177. writel(val, &phy1_ctrl->phy_con12);
  178. update_reset_dll(dmc, DDR_MODE_DDR3);
  179. }
  180. /* Send PALL command */
  181. dmc_config_prech(mem, dmc);
  182. writel(mem->memcontrol, &dmc->memcontrol);
  183. /* Set DMC Concontrol and enable auto-refresh counter */
  184. writel(mem->concontrol | (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)
  185. | (mem->aref_en << CONCONTROL_AREF_EN_SHIFT), &dmc->concontrol);
  186. return 0;
  187. }