dmc_init_ddr3.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 "common_setup.h"
  30. #include "exynos5_setup.h"
  31. #include "clock_init.h"
  32. #define RDLVL_COMPLETE_TIMEOUT 10000
  33. static void reset_phy_ctrl(void)
  34. {
  35. struct exynos5_clock *clk =
  36. (struct exynos5_clock *)samsung_get_base_clock();
  37. writel(DDR3PHY_CTRL_PHY_RESET_OFF, &clk->lpddr3phy_ctrl);
  38. writel(DDR3PHY_CTRL_PHY_RESET, &clk->lpddr3phy_ctrl);
  39. }
  40. int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long mem_iv_size,
  41. int reset)
  42. {
  43. unsigned int val;
  44. struct exynos5_phy_control *phy0_ctrl, *phy1_ctrl;
  45. struct exynos5_dmc *dmc;
  46. int i;
  47. phy0_ctrl = (struct exynos5_phy_control *)samsung_get_base_dmc_phy();
  48. phy1_ctrl = (struct exynos5_phy_control *)(samsung_get_base_dmc_phy()
  49. + DMC_OFFSET);
  50. dmc = (struct exynos5_dmc *)samsung_get_base_dmc_ctrl();
  51. if (reset)
  52. reset_phy_ctrl();
  53. /* Set Impedance Output Driver */
  54. val = (mem->impedance << CA_CK_DRVR_DS_OFFSET) |
  55. (mem->impedance << CA_CKE_DRVR_DS_OFFSET) |
  56. (mem->impedance << CA_CS_DRVR_DS_OFFSET) |
  57. (mem->impedance << CA_ADR_DRVR_DS_OFFSET);
  58. writel(val, &phy0_ctrl->phy_con39);
  59. writel(val, &phy1_ctrl->phy_con39);
  60. /* Set Read Latency and Burst Length for PHY0 and PHY1 */
  61. val = (mem->ctrl_bstlen << PHY_CON42_CTRL_BSTLEN_SHIFT) |
  62. (mem->ctrl_rdlat << PHY_CON42_CTRL_RDLAT_SHIFT);
  63. writel(val, &phy0_ctrl->phy_con42);
  64. writel(val, &phy1_ctrl->phy_con42);
  65. /* ZQ Calibration */
  66. if (dmc_config_zq(mem, phy0_ctrl, phy1_ctrl))
  67. return SETUP_ERR_ZQ_CALIBRATION_FAILURE;
  68. /* DQ Signal */
  69. writel(mem->phy0_pulld_dqs, &phy0_ctrl->phy_con14);
  70. writel(mem->phy1_pulld_dqs, &phy1_ctrl->phy_con14);
  71. writel(mem->concontrol | (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)
  72. | (mem->dfi_init_start << CONCONTROL_DFI_INIT_START_SHIFT),
  73. &dmc->concontrol);
  74. update_reset_dll(dmc, DDR_MODE_DDR3);
  75. /* DQS Signal */
  76. writel(mem->phy0_dqs, &phy0_ctrl->phy_con4);
  77. writel(mem->phy1_dqs, &phy1_ctrl->phy_con4);
  78. writel(mem->phy0_dq, &phy0_ctrl->phy_con6);
  79. writel(mem->phy1_dq, &phy1_ctrl->phy_con6);
  80. writel(mem->phy0_tFS, &phy0_ctrl->phy_con10);
  81. writel(mem->phy1_tFS, &phy1_ctrl->phy_con10);
  82. val = (mem->ctrl_start_point << PHY_CON12_CTRL_START_POINT_SHIFT) |
  83. (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
  84. (mem->ctrl_dll_on << PHY_CON12_CTRL_DLL_ON_SHIFT) |
  85. (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
  86. writel(val, &phy0_ctrl->phy_con12);
  87. writel(val, &phy1_ctrl->phy_con12);
  88. /* Start DLL locking */
  89. writel(val | (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
  90. &phy0_ctrl->phy_con12);
  91. writel(val | (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
  92. &phy1_ctrl->phy_con12);
  93. update_reset_dll(dmc, DDR_MODE_DDR3);
  94. writel(mem->concontrol | (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT),
  95. &dmc->concontrol);
  96. /* Memory Channel Inteleaving Size */
  97. writel(mem->iv_size, &dmc->ivcontrol);
  98. writel(mem->memconfig, &dmc->memconfig0);
  99. writel(mem->memconfig, &dmc->memconfig1);
  100. writel(mem->membaseconfig0, &dmc->membaseconfig0);
  101. writel(mem->membaseconfig1, &dmc->membaseconfig1);
  102. /* Precharge Configuration */
  103. writel(mem->prechconfig_tp_cnt << PRECHCONFIG_TP_CNT_SHIFT,
  104. &dmc->prechconfig);
  105. /* Power Down mode Configuration */
  106. writel(mem->dpwrdn_cyc << PWRDNCONFIG_DPWRDN_CYC_SHIFT |
  107. mem->dsref_cyc << PWRDNCONFIG_DSREF_CYC_SHIFT,
  108. &dmc->pwrdnconfig);
  109. /* TimingRow, TimingData, TimingPower and Timingaref
  110. * values as per Memory AC parameters
  111. */
  112. writel(mem->timing_ref, &dmc->timingref);
  113. writel(mem->timing_row, &dmc->timingrow);
  114. writel(mem->timing_data, &dmc->timingdata);
  115. writel(mem->timing_power, &dmc->timingpower);
  116. /* Send PALL command */
  117. dmc_config_prech(mem, dmc);
  118. /* Send NOP, MRS and ZQINIT commands */
  119. dmc_config_mrs(mem, dmc);
  120. if (mem->gate_leveling_enable) {
  121. val = PHY_CON0_RESET_VAL;
  122. val |= P0_CMD_EN;
  123. writel(val, &phy0_ctrl->phy_con0);
  124. writel(val, &phy1_ctrl->phy_con0);
  125. val = PHY_CON2_RESET_VAL;
  126. val |= INIT_DESKEW_EN;
  127. writel(val, &phy0_ctrl->phy_con2);
  128. writel(val, &phy1_ctrl->phy_con2);
  129. val = PHY_CON0_RESET_VAL;
  130. val |= P0_CMD_EN;
  131. val |= BYTE_RDLVL_EN;
  132. writel(val, &phy0_ctrl->phy_con0);
  133. writel(val, &phy1_ctrl->phy_con0);
  134. val = (mem->ctrl_start_point <<
  135. PHY_CON12_CTRL_START_POINT_SHIFT) |
  136. (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
  137. (mem->ctrl_force << PHY_CON12_CTRL_FORCE_SHIFT) |
  138. (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT) |
  139. (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
  140. writel(val, &phy0_ctrl->phy_con12);
  141. writel(val, &phy1_ctrl->phy_con12);
  142. val = PHY_CON2_RESET_VAL;
  143. val |= INIT_DESKEW_EN;
  144. val |= RDLVL_GATE_EN;
  145. writel(val, &phy0_ctrl->phy_con2);
  146. writel(val, &phy1_ctrl->phy_con2);
  147. val = PHY_CON0_RESET_VAL;
  148. val |= P0_CMD_EN;
  149. val |= BYTE_RDLVL_EN;
  150. val |= CTRL_SHGATE;
  151. writel(val, &phy0_ctrl->phy_con0);
  152. writel(val, &phy1_ctrl->phy_con0);
  153. val = PHY_CON1_RESET_VAL;
  154. val &= ~(CTRL_GATEDURADJ_MASK);
  155. writel(val, &phy0_ctrl->phy_con1);
  156. writel(val, &phy1_ctrl->phy_con1);
  157. writel(CTRL_RDLVL_GATE_ENABLE, &dmc->rdlvl_config);
  158. i = RDLVL_COMPLETE_TIMEOUT;
  159. while ((readl(&dmc->phystatus) &
  160. (RDLVL_COMPLETE_CHO | RDLVL_COMPLETE_CH1)) !=
  161. (RDLVL_COMPLETE_CHO | RDLVL_COMPLETE_CH1) && i > 0) {
  162. /*
  163. * TODO(waihong): Comment on how long this take to
  164. * timeout
  165. */
  166. sdelay(100);
  167. i--;
  168. }
  169. if (!i)
  170. return SETUP_ERR_RDLV_COMPLETE_TIMEOUT;
  171. writel(CTRL_RDLVL_GATE_DISABLE, &dmc->rdlvl_config);
  172. writel(0, &phy0_ctrl->phy_con14);
  173. writel(0, &phy1_ctrl->phy_con14);
  174. val = (mem->ctrl_start_point <<
  175. PHY_CON12_CTRL_START_POINT_SHIFT) |
  176. (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
  177. (mem->ctrl_force << PHY_CON12_CTRL_FORCE_SHIFT) |
  178. (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT) |
  179. (mem->ctrl_dll_on << PHY_CON12_CTRL_DLL_ON_SHIFT) |
  180. (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
  181. writel(val, &phy0_ctrl->phy_con12);
  182. writel(val, &phy1_ctrl->phy_con12);
  183. update_reset_dll(dmc, DDR_MODE_DDR3);
  184. }
  185. /* Send PALL command */
  186. dmc_config_prech(mem, dmc);
  187. writel(mem->memcontrol, &dmc->memcontrol);
  188. /* Set DMC Concontrol and enable auto-refresh counter */
  189. writel(mem->concontrol | (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)
  190. | (mem->aref_en << CONCONTROL_AREF_EN_SHIFT), &dmc->concontrol);
  191. return 0;
  192. }