ti816x_emif4.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * ti816x_emif4.c
  4. *
  5. * TI816x emif4 configuration file
  6. *
  7. * Copyright (C) 2017, Konsulko Group
  8. */
  9. #include <common.h>
  10. #include <asm/arch/cpu.h>
  11. #include <asm/arch/ddr_defs.h>
  12. #include <asm/arch/hardware.h>
  13. #include <asm/arch/clock.h>
  14. #include <asm/arch/sys_proto.h>
  15. #include <asm/io.h>
  16. #include <asm/emif.h>
  17. #include <linux/delay.h>
  18. /*********************************************************************
  19. * Init DDR3 on TI816X EVM
  20. *********************************************************************/
  21. static void ddr_init_settings(const struct cmd_control *ctrl, int emif)
  22. {
  23. /*
  24. * setup use_rank_delays to 1. This is only necessary when
  25. * multiple ranks are in use. Though the EVM does not have
  26. * multiple ranks, this is a good value to set.
  27. */
  28. writel(1, DDRPHY_CONFIG_BASE + 0x134); // DATA0_REG_PHY_USE_RANK0_DELAYS
  29. writel(1, DDRPHY_CONFIG_BASE + 0x1d8); // DATA1_REG_PHY_USE_RANK0_DELAYS
  30. writel(1, DDRPHY_CONFIG_BASE + 0x27c); // DATA2_REG_PHY_USE_RANK0_DELAYS
  31. writel(1, DDRPHY_CONFIG_BASE + 0x320); // DATA3_REG_PHY_USE_RANK0_DELAYS
  32. config_cmd_ctrl(ctrl, emif);
  33. /* for ddr3 this needs to be set to 1 */
  34. writel(0x1, DDRPHY_CONFIG_BASE + 0x0F8); /* init mode */
  35. writel(0x1, DDRPHY_CONFIG_BASE + 0x104);
  36. writel(0x1, DDRPHY_CONFIG_BASE + 0x19C);
  37. writel(0x1, DDRPHY_CONFIG_BASE + 0x1A8);
  38. writel(0x1, DDRPHY_CONFIG_BASE + 0x240);
  39. writel(0x1, DDRPHY_CONFIG_BASE + 0x24C);
  40. writel(0x1, DDRPHY_CONFIG_BASE + 0x2E4);
  41. writel(0x1, DDRPHY_CONFIG_BASE + 0x2F0);
  42. /*
  43. * This represents the initial value for the leveling process. The
  44. * value is a ratio - so 0x100 represents one cycle. The real delay
  45. * is determined through the leveling process.
  46. *
  47. * During the leveling process, 0x20 is subtracted from the value, so
  48. * we have added that to the value we want to set. We also set the
  49. * values such that byte3 completes leveling after byte2 and byte1
  50. * after byte0.
  51. */
  52. writel((0x20 << 10) | 0x20, DDRPHY_CONFIG_BASE + 0x0F0); /* data0 writelvl init ratio */
  53. writel(0x0, DDRPHY_CONFIG_BASE + 0x0F4); /* */
  54. writel((0x20 << 10) | 0x20, DDRPHY_CONFIG_BASE + 0x194); /* data1 writelvl init ratio */
  55. writel(0x0, DDRPHY_CONFIG_BASE + 0x198); /* */
  56. writel((0x20 << 10) | 0x20, DDRPHY_CONFIG_BASE + 0x238); /* data2 writelvl init ratio */
  57. writel(0x0, DDRPHY_CONFIG_BASE + 0x23c); /* */
  58. writel((0x20 << 10) | 0x20, DDRPHY_CONFIG_BASE + 0x2dc); /* data3 writelvl init ratio */
  59. writel(0x0, DDRPHY_CONFIG_BASE + 0x2e0); /* */
  60. writel((0x20 << 10) | 0x20, DDRPHY_CONFIG_BASE + 0x0FC); /* data0 gatelvl init ratio */
  61. writel(0x0, DDRPHY_CONFIG_BASE + 0x100);
  62. writel((0x20 << 10) | 0x20, DDRPHY_CONFIG_BASE + 0x1A0); /* data1 gatelvl init ratio */
  63. writel(0x0, DDRPHY_CONFIG_BASE + 0x1A4);
  64. writel((0x20 << 10) | 0x20, DDRPHY_CONFIG_BASE + 0x244); /* data2 gatelvl init ratio */
  65. writel(0x0, DDRPHY_CONFIG_BASE + 0x248);
  66. writel((0x20 << 10) | 0x20, DDRPHY_CONFIG_BASE + 0x2E8); /* data3 gatelvl init ratio */
  67. writel(0x0, DDRPHY_CONFIG_BASE + 0x2EC);
  68. writel(0x5, DDRPHY_CONFIG_BASE + 0x00C); /* cmd0 io config - output impedance of pad */
  69. writel(0x5, DDRPHY_CONFIG_BASE + 0x010); /* cmd0 io clk config - output impedance of pad */
  70. writel(0x5, DDRPHY_CONFIG_BASE + 0x040); /* cmd1 io config - output impedance of pad */
  71. writel(0x5, DDRPHY_CONFIG_BASE + 0x044); /* cmd1 io clk config - output impedance of pad */
  72. writel(0x5, DDRPHY_CONFIG_BASE + 0x074); /* cmd2 io config - output impedance of pad */
  73. writel(0x5, DDRPHY_CONFIG_BASE + 0x078); /* cmd2 io clk config - output impedance of pad */
  74. writel(0x4, DDRPHY_CONFIG_BASE + 0x0A8); /* data0 io config - output impedance of pad */
  75. writel(0x4, DDRPHY_CONFIG_BASE + 0x0AC); /* data0 io clk config - output impedance of pad */
  76. writel(0x4, DDRPHY_CONFIG_BASE + 0x14C); /* data1 io config - output impedance of pa */
  77. writel(0x4, DDRPHY_CONFIG_BASE + 0x150); /* data1 io clk config - output impedance of pad */
  78. writel(0x4, DDRPHY_CONFIG_BASE + 0x1F0); /* data2 io config - output impedance of pa */
  79. writel(0x4, DDRPHY_CONFIG_BASE + 0x1F4); /* data2 io clk config - output impedance of pad */
  80. writel(0x4, DDRPHY_CONFIG_BASE + 0x294); /* data3 io config - output impedance of pa */
  81. writel(0x4, DDRPHY_CONFIG_BASE + 0x298); /* data3 io clk config - output impedance of pad */
  82. }
  83. static void ddr3_sw_levelling(const struct ddr_data *data, int emif)
  84. {
  85. /* Set the correct value to DDR_VTP_CTRL_0 */
  86. writel(0x6, (DDRPHY_CONFIG_BASE + 0x358));
  87. writel(data->datafwsratio0, (DDRPHY_CONFIG_BASE + 0x108));
  88. writel(data->datafwsratio0, (DDRPHY_CONFIG_BASE + 0x1AC));
  89. writel(data->datafwsratio0, (DDRPHY_CONFIG_BASE + 0x250));
  90. writel(data->datafwsratio0, (DDRPHY_CONFIG_BASE + 0x2F4));
  91. writel(data->datawdsratio0, (DDRPHY_CONFIG_BASE + 0x0DC));
  92. writel(data->datawdsratio0, (DDRPHY_CONFIG_BASE + 0x180));
  93. writel(data->datawdsratio0, (DDRPHY_CONFIG_BASE + 0x224));
  94. writel(data->datawdsratio0, (DDRPHY_CONFIG_BASE + 0x2C8));
  95. writel(data->datawrsratio0, (DDRPHY_CONFIG_BASE + 0x120));
  96. writel(data->datawrsratio0, (DDRPHY_CONFIG_BASE + 0x1C4));
  97. writel(data->datawrsratio0, (DDRPHY_CONFIG_BASE + 0x268));
  98. writel(data->datawrsratio0, (DDRPHY_CONFIG_BASE + 0x30C));
  99. writel(data->datardsratio0, (DDRPHY_CONFIG_BASE + 0x0C8));
  100. writel(data->datardsratio0, (DDRPHY_CONFIG_BASE + 0x16C));
  101. writel(data->datardsratio0, (DDRPHY_CONFIG_BASE + 0x210));
  102. writel(data->datardsratio0, (DDRPHY_CONFIG_BASE + 0x2B4));
  103. }
  104. static struct dmm_lisa_map_regs *hw_lisa_map_regs =
  105. (struct dmm_lisa_map_regs *)DMM_BASE;
  106. #define DMM_PAT_BASE_ADDR (DMM_BASE + 0x420)
  107. void config_dmm(const struct dmm_lisa_map_regs *regs)
  108. {
  109. writel(0, &hw_lisa_map_regs->dmm_lisa_map_3);
  110. writel(0, &hw_lisa_map_regs->dmm_lisa_map_2);
  111. writel(0, &hw_lisa_map_regs->dmm_lisa_map_1);
  112. writel(0, &hw_lisa_map_regs->dmm_lisa_map_0);
  113. writel(regs->dmm_lisa_map_3, &hw_lisa_map_regs->dmm_lisa_map_3);
  114. writel(regs->dmm_lisa_map_2, &hw_lisa_map_regs->dmm_lisa_map_2);
  115. writel(regs->dmm_lisa_map_1, &hw_lisa_map_regs->dmm_lisa_map_1);
  116. writel(regs->dmm_lisa_map_0, &hw_lisa_map_regs->dmm_lisa_map_0);
  117. /* Enable Tiled Access */
  118. writel(0x80000000, DMM_PAT_BASE_ADDR);
  119. }
  120. void config_ddr(const struct ddr_data *data, const struct cmd_control *ctrl,
  121. const struct emif_regs *regs,
  122. const struct dmm_lisa_map_regs *lisa_regs, int nrs)
  123. {
  124. int i;
  125. enable_emif_clocks();
  126. for (i = 0; i < nrs; i++)
  127. ddr_init_settings(ctrl, i);
  128. enable_dmm_clocks();
  129. /* Program the DMM to for non-interleaved configuration */
  130. config_dmm(lisa_regs);
  131. /* Program EMIF CFG Registers */
  132. for (i = 0; i < nrs; i++) {
  133. set_sdram_timings(regs, i);
  134. config_sdram(regs, i);
  135. }
  136. udelay(1000);
  137. for (i = 0; i < nrs; i++)
  138. ddr3_sw_levelling(data, i);
  139. udelay(50000); /* Some delay needed */
  140. }