dmc_common.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Mem setup common file for different types of DDR present on SMDK5250 boards.
  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 <common.h>
  25. #include <asm/arch/spl.h>
  26. #include "clock_init.h"
  27. #include "common_setup.h"
  28. #include "exynos5_setup.h"
  29. #define ZQ_INIT_TIMEOUT 10000
  30. int dmc_config_zq(struct mem_timings *mem,
  31. struct exynos5_phy_control *phy0_ctrl,
  32. struct exynos5_phy_control *phy1_ctrl)
  33. {
  34. unsigned long val = 0;
  35. int i;
  36. /*
  37. * ZQ Calibration:
  38. * Select Driver Strength,
  39. * long calibration for manual calibration
  40. */
  41. val = PHY_CON16_RESET_VAL;
  42. val |= mem->zq_mode_dds << PHY_CON16_ZQ_MODE_DDS_SHIFT;
  43. val |= mem->zq_mode_term << PHY_CON16_ZQ_MODE_TERM_SHIFT;
  44. val |= ZQ_CLK_DIV_EN;
  45. writel(val, &phy0_ctrl->phy_con16);
  46. writel(val, &phy1_ctrl->phy_con16);
  47. /* Disable termination */
  48. if (mem->zq_mode_noterm)
  49. val |= PHY_CON16_ZQ_MODE_NOTERM_MASK;
  50. writel(val, &phy0_ctrl->phy_con16);
  51. writel(val, &phy1_ctrl->phy_con16);
  52. /* ZQ_MANUAL_START: Enable */
  53. val |= ZQ_MANUAL_STR;
  54. writel(val, &phy0_ctrl->phy_con16);
  55. writel(val, &phy1_ctrl->phy_con16);
  56. /* ZQ_MANUAL_START: Disable */
  57. val &= ~ZQ_MANUAL_STR;
  58. /*
  59. * Since we are manaully calibrating the ZQ values,
  60. * we are looping for the ZQ_init to complete.
  61. */
  62. i = ZQ_INIT_TIMEOUT;
  63. while ((readl(&phy0_ctrl->phy_con17) & ZQ_DONE) != ZQ_DONE && i > 0) {
  64. sdelay(100);
  65. i--;
  66. }
  67. if (!i)
  68. return -1;
  69. writel(val, &phy0_ctrl->phy_con16);
  70. i = ZQ_INIT_TIMEOUT;
  71. while ((readl(&phy1_ctrl->phy_con17) & ZQ_DONE) != ZQ_DONE && i > 0) {
  72. sdelay(100);
  73. i--;
  74. }
  75. if (!i)
  76. return -1;
  77. writel(val, &phy1_ctrl->phy_con16);
  78. return 0;
  79. }
  80. void update_reset_dll(struct exynos5_dmc *dmc, enum ddr_mode mode)
  81. {
  82. unsigned long val;
  83. if (mode == DDR_MODE_DDR3) {
  84. val = MEM_TERM_EN | PHY_TERM_EN | DMC_CTRL_SHGATE;
  85. writel(val, &dmc->phycontrol0);
  86. }
  87. /* Update DLL Information: Force DLL Resyncronization */
  88. val = readl(&dmc->phycontrol0);
  89. val |= FP_RSYNC;
  90. writel(val, &dmc->phycontrol0);
  91. /* Reset Force DLL Resyncronization */
  92. val = readl(&dmc->phycontrol0);
  93. val &= ~FP_RSYNC;
  94. writel(val, &dmc->phycontrol0);
  95. }
  96. void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc)
  97. {
  98. int channel, chip;
  99. for (channel = 0; channel < mem->dmc_channels; channel++) {
  100. unsigned long mask;
  101. mask = channel << DIRECT_CMD_CHANNEL_SHIFT;
  102. for (chip = 0; chip < mem->chips_to_configure; chip++) {
  103. int i;
  104. mask |= chip << DIRECT_CMD_CHIP_SHIFT;
  105. /* Sending NOP command */
  106. writel(DIRECT_CMD_NOP | mask, &dmc->directcmd);
  107. /*
  108. * TODO(alim.akhtar@samsung.com): Do we need these
  109. * delays? This one and the next were not there for
  110. * DDR3.
  111. */
  112. sdelay(0x10000);
  113. /* Sending EMRS/MRS commands */
  114. for (i = 0; i < MEM_TIMINGS_MSR_COUNT; i++) {
  115. writel(mem->direct_cmd_msr[i] | mask,
  116. &dmc->directcmd);
  117. sdelay(0x10000);
  118. }
  119. if (mem->send_zq_init) {
  120. /* Sending ZQINIT command */
  121. writel(DIRECT_CMD_ZQINIT | mask,
  122. &dmc->directcmd);
  123. sdelay(10000);
  124. }
  125. }
  126. }
  127. }
  128. void dmc_config_prech(struct mem_timings *mem, struct exynos5_dmc *dmc)
  129. {
  130. int channel, chip;
  131. for (channel = 0; channel < mem->dmc_channels; channel++) {
  132. unsigned long mask;
  133. mask = channel << DIRECT_CMD_CHANNEL_SHIFT;
  134. for (chip = 0; chip < mem->chips_per_channel; chip++) {
  135. mask |= chip << DIRECT_CMD_CHIP_SHIFT;
  136. /* PALL (all banks precharge) CMD */
  137. writel(DIRECT_CMD_PALL | mask, &dmc->directcmd);
  138. sdelay(0x10000);
  139. }
  140. }
  141. }
  142. void dmc_config_memory(struct mem_timings *mem, struct exynos5_dmc *dmc)
  143. {
  144. writel(mem->memconfig, &dmc->memconfig0);
  145. writel(mem->memconfig, &dmc->memconfig1);
  146. writel(DMC_MEMBASECONFIG0_VAL, &dmc->membaseconfig0);
  147. writel(DMC_MEMBASECONFIG1_VAL, &dmc->membaseconfig1);
  148. }
  149. void mem_ctrl_init(int reset)
  150. {
  151. struct spl_machine_param *param = spl_get_machine_params();
  152. struct mem_timings *mem;
  153. int ret;
  154. mem = clock_get_mem_timings();
  155. /* If there are any other memory variant, add their init call below */
  156. if (param->mem_type == DDR_MODE_DDR3) {
  157. ret = ddr3_mem_ctrl_init(mem, param->mem_iv_size, reset);
  158. if (ret) {
  159. /* will hang if failed to init memory control */
  160. while (1)
  161. ;
  162. }
  163. } else {
  164. /* will hang if unknow memory type */
  165. while (1)
  166. ;
  167. }
  168. }