umc-ld4.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright (C) 2011-2014 Panasonic Corporation
  3. * Copyright (C) 2015-2016 Socionext Inc.
  4. * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <linux/err.h>
  10. #include <linux/io.h>
  11. #include <linux/sizes.h>
  12. #include <asm/processor.h>
  13. #include "../init.h"
  14. #include "ddrphy-init.h"
  15. #include "umc-regs.h"
  16. #define DRAM_CH_NR 2
  17. enum dram_freq {
  18. DRAM_FREQ_1333M,
  19. DRAM_FREQ_1600M,
  20. DRAM_FREQ_NR,
  21. };
  22. enum dram_size {
  23. DRAM_SZ_128M,
  24. DRAM_SZ_256M,
  25. DRAM_SZ_NR,
  26. };
  27. static u32 umc_cmdctla_plus[DRAM_FREQ_NR] = {0x45990b11, 0x36bb0f17};
  28. static u32 umc_cmdctlb_plus[DRAM_FREQ_NR] = {0x16958924, 0x18c6aa24};
  29. static u32 umc_spcctla[DRAM_FREQ_NR][DRAM_SZ_NR] = {
  30. {0x00240512, 0x00350512},
  31. {0x002b0617, 0x003f0617},
  32. };
  33. static u32 umc_spcctlb[DRAM_FREQ_NR] = {0x00ff0006, 0x00ff0008};
  34. static u32 umc_rdatactl[DRAM_FREQ_NR] = {0x000a00ac, 0x000c00ae};
  35. static int umc_get_rank(int ch)
  36. {
  37. return ch; /* ch0: rank0, ch1: rank1 for this SoC */
  38. }
  39. static void umc_start_ssif(void __iomem *ssif_base)
  40. {
  41. writel(0x00000000, ssif_base + 0x0000b004);
  42. writel(0xffffffff, ssif_base + 0x0000c004);
  43. writel(0x000fffcf, ssif_base + 0x0000c008);
  44. writel(0x00000001, ssif_base + 0x0000b000);
  45. writel(0x00000001, ssif_base + 0x0000c000);
  46. writel(0x03010101, ssif_base + UMC_MDMCHSEL);
  47. writel(0x03010100, ssif_base + UMC_DMDCHSEL);
  48. writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_FETCH);
  49. writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE0);
  50. writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC0);
  51. writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC0);
  52. writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE1);
  53. writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC1);
  54. writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC1);
  55. writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_WC);
  56. writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_RC);
  57. writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_DST);
  58. writel(0x00000001, ssif_base + UMC_CPURST);
  59. writel(0x00000001, ssif_base + UMC_IDSRST);
  60. writel(0x00000001, ssif_base + UMC_IXMRST);
  61. writel(0x00000001, ssif_base + UMC_MDMRST);
  62. writel(0x00000001, ssif_base + UMC_MDDRST);
  63. writel(0x00000001, ssif_base + UMC_SIORST);
  64. writel(0x00000001, ssif_base + UMC_VIORST);
  65. writel(0x00000001, ssif_base + UMC_FRCRST);
  66. writel(0x00000001, ssif_base + UMC_RGLRST);
  67. writel(0x00000001, ssif_base + UMC_AIORST);
  68. writel(0x00000001, ssif_base + UMC_DMDRST);
  69. }
  70. static int umc_dramcont_init(void __iomem *dc_base, void __iomem *ca_base,
  71. int freq, unsigned long size, bool ddr3plus)
  72. {
  73. enum dram_freq freq_e;
  74. enum dram_size size_e;
  75. if (!ddr3plus) {
  76. pr_err("DDR3 standard is not supported\n");
  77. return -EINVAL;
  78. }
  79. switch (freq) {
  80. case 1333:
  81. freq_e = DRAM_FREQ_1333M;
  82. break;
  83. case 1600:
  84. freq_e = DRAM_FREQ_1600M;
  85. break;
  86. default:
  87. pr_err("unsupported DRAM frequency %d MHz\n", freq);
  88. return -EINVAL;
  89. }
  90. switch (size) {
  91. case 0:
  92. return 0;
  93. case SZ_128M:
  94. size_e = DRAM_SZ_128M;
  95. break;
  96. case SZ_256M:
  97. size_e = DRAM_SZ_256M;
  98. break;
  99. default:
  100. pr_err("unsupported DRAM size 0x%08lx\n", size);
  101. return -EINVAL;
  102. }
  103. writel(umc_cmdctla_plus[freq_e], dc_base + UMC_CMDCTLA);
  104. writel(umc_cmdctlb_plus[freq_e], dc_base + UMC_CMDCTLB);
  105. writel(umc_spcctla[freq_e][size_e], dc_base + UMC_SPCCTLA);
  106. writel(umc_spcctlb[freq_e], dc_base + UMC_SPCCTLB);
  107. writel(umc_rdatactl[freq_e], dc_base + UMC_RDATACTL_D0);
  108. writel(0x04060806, dc_base + UMC_WDATACTL_D0);
  109. writel(0x04a02000, dc_base + UMC_DATASET);
  110. writel(0x00000000, ca_base + 0x2300);
  111. writel(0x00400020, dc_base + UMC_DCCGCTL);
  112. writel(0x00000003, dc_base + 0x7000);
  113. writel(0x0000000f, dc_base + 0x8000);
  114. writel(0x000000c3, dc_base + 0x8004);
  115. writel(0x00000071, dc_base + 0x8008);
  116. writel(0x0000003b, dc_base + UMC_DICGCTLA);
  117. writel(0x020a0808, dc_base + UMC_DICGCTLB);
  118. writel(0x00000004, dc_base + UMC_FLOWCTLG);
  119. writel(0x80000201, ca_base + 0xc20);
  120. writel(0x0801e01e, dc_base + UMC_FLOWCTLA);
  121. writel(0x00200000, dc_base + UMC_FLOWCTLB);
  122. writel(0x00004444, dc_base + UMC_FLOWCTLC);
  123. writel(0x200a0a00, dc_base + UMC_SPCSETB);
  124. writel(0x00000000, dc_base + UMC_SPCSETD);
  125. writel(0x00000520, dc_base + UMC_DFICUPDCTLA);
  126. return 0;
  127. }
  128. static int umc_ch_init(void __iomem *dc_base, void __iomem *ca_base,
  129. int freq, unsigned long size, bool ddr3plus, int ch)
  130. {
  131. void __iomem *phy_base = dc_base + 0x00001000;
  132. int ret;
  133. writel(UMC_INITSET_INIT1EN, dc_base + UMC_INITSET);
  134. while (readl(dc_base + UMC_INITSTAT) & UMC_INITSTAT_INIT1ST)
  135. cpu_relax();
  136. writel(0x00000101, dc_base + UMC_DIOCTLA);
  137. ret = uniphier_ld4_ddrphy_init(phy_base, freq, ddr3plus);
  138. if (ret)
  139. return ret;
  140. ddrphy_prepare_training(phy_base, umc_get_rank(ch));
  141. ret = ddrphy_training(phy_base);
  142. if (ret)
  143. return ret;
  144. return umc_dramcont_init(dc_base, ca_base, freq, size, ddr3plus);
  145. }
  146. int uniphier_ld4_umc_init(const struct uniphier_board_data *bd)
  147. {
  148. void __iomem *umc_base = (void __iomem *)0x5b800000;
  149. void __iomem *ca_base = umc_base + 0x00001000;
  150. void __iomem *dc_base = umc_base + 0x00400000;
  151. void __iomem *ssif_base = umc_base;
  152. int ch, ret;
  153. for (ch = 0; ch < DRAM_CH_NR; ch++) {
  154. ret = umc_ch_init(dc_base, ca_base, bd->dram_freq,
  155. bd->dram_ch[ch].size,
  156. !!(bd->flags & UNIPHIER_BD_DDR3PLUS), ch);
  157. if (ret) {
  158. pr_err("failed to initialize UMC ch%d\n", ch);
  159. return ret;
  160. }
  161. ca_base += 0x00001000;
  162. dc_base += 0x00200000;
  163. }
  164. umc_start_ssif(ssif_base);
  165. return 0;
  166. }