spl_ark1668ed.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include <common.h>
  3. #include <linux/delay.h>
  4. #include <init.h>
  5. #include <spl.h>
  6. #include <asm/arch/timer.h>
  7. #include <asm/arch/ark1668ed-sysreg.h>
  8. #include <asm/arch/ark-common.h>
  9. #include <asm-generic/gpio.h>
  10. #if CONFIG_IS_ENABLED(BANNER_PRINT)
  11. #include <timestamp.h>
  12. #endif
  13. #include <version.h>
  14. #define BOOT_SAMPLE_CPUPLL_LOCK (1 << 30)
  15. #define BOOT_SAMPLE_SYSPLL_LOCK (1 << 29)
  16. #define BOOT_SAMPLE_VPUPLL_LOCK (1 << 28)
  17. #define BOOT_SAMPLE_DDRPLL_LOCK (1 << 27)
  18. #define BOOT_SAMPLE_MFCPLL_LOCK (1 << 26)
  19. #define BOOT_SAMPLE_AHBPLL_LOCK (1 << 25)
  20. #define BOOT_SAMPLE_GPUPLL_LOCK (1 << 24)
  21. #define BOOT_SAMPLE_DSPPLL_LOCK (1 << 23)
  22. #define BOOT_SAMPLE_TVPLL_LOCK (1 << 22)
  23. #define DDR_CTL1_CPUPLL_EN (1 << 1)
  24. #define DDR_CTL1_SYSPLL_EN (1 << 3)
  25. #define DDR_CTL1_DDRPLL_EN (1 << 5)
  26. #define DDR_CTL1_VPUPLL_EN (1 << 7)
  27. #define DDR_CTL1_MFCPLL_EN (1 << 9)
  28. #define DDR_CTL1_AHBPLL_EN (1 << 11)
  29. void clk_init(void)
  30. {
  31. uint32_t timeout = 1000;
  32. rSYS_BUS_CLK_CFG &= ~0x3F;
  33. rSYS_DDR_CTL1_CFG &= ~0x1ff;
  34. rSYS_CPUPLL_CFG |= 0xf << 26;
  35. rSYS_SYSPLL_CFG |= 0xf << 26;
  36. rSYS_VPUPLL_CFG |= 0xf << 26;
  37. rSYS_DDRPLL_CFG |= 0xf << 26;
  38. rSYS_MFCPLL_CFG |= 0xf << 26;
  39. rSYS_TVPLL_CFG |= 0xf << 26;
  40. rSYS_AHBPLL_CFG |= 0xf << 26;
  41. rSYS_GPUPLL_CFG |= 0xf << 26;
  42. udelay(100);
  43. /* cpu pll (注:硬件不支持扩频,DSMPD位无效)*/
  44. rSYS_CPUPLL_CFG = (1 << 27) | (1 << 23) | (1 << 20) | (100 << 8) | 3; //800M
  45. /* sys pll (注:硬件支持扩频。 DSMPD位有效,需要延时配置)*/
  46. rSYS_SYSPLL_SPRD_CTL |= (1 << 30);// 扩频器bypass
  47. rSYS_SYSPLL_CFG = (1 << 23) | (2 << 20) | (90 << 8) | (3 << 0);
  48. udelay(100);
  49. rSYS_SYSPLL_CFG |= 1 << 27;
  50. /* vpu pll (注:硬件支持扩频。 DSMPD位有效,需要延时配置)*/
  51. rSYS_VPUPLL_SPRD_CTL |= (1 << 30);// 扩频器bypass
  52. rSYS_VPUPLL_CFG = (1 << 23) | (2 << 20) | (100 << 8) | (4 << 0);
  53. udelay(100);
  54. rSYS_VPUPLL_CFG |= 1 << 27;
  55. // ddr pll (注:硬件不支持扩频,DSMPD位无效)*/
  56. rSYS_DDRPLL_CFG = (1 << 27) | (1 << 23) | (3 << 20) | (200 << 8) | 4; // 300M
  57. // mfc pll (注:硬件不支持扩频,DSMPD位无效)
  58. rSYS_MFCPLL_CFG = (1 << 27) | (1 << 23) | (2 << 20) | (500<< 8) | 6; //1000M
  59. // tv pll (注:硬件不支持扩频,DSMPD位无效)
  60. //rSYS_TVPLL_CFG = (1 << 27) | (1 << 23) | (6 << 20) | (297 << 8) | 4; //297M
  61. rSYS_TVPLL_CFG = (1 << 27) | (1 << 23) | (2 << 20) | (144 << 8) | 4; //432M
  62. // ahb pll (注:硬件支持扩频。 DSMPD位有效,需要延时配置)
  63. rSYS_AHBPLL_SPRD_CTL |= (1 << 30);// 扩频器bypass
  64. rSYS_AHBPLL_CFG = (1 << 23) | (4 << 20) | (135 << 8) | 3;
  65. udelay(100);
  66. rSYS_AHBPLL_CFG |= 1 << 27;
  67. // gpu pll (注:硬件不支持扩频,DSMPD位无效)
  68. rSYS_GPUPLL_CFG = (1 << 27) | (1 << 23) | (2 << 20) | (200 << 8) | 3;
  69. // wait cpupll lock
  70. while (!(rSYS_BOOT_SAMPLE & BOOT_SAMPLE_CPUPLL_LOCK) && timeout--)
  71. udelay(1);
  72. //wait syspll lock
  73. timeout = 1000;
  74. while (!(rSYS_BOOT_SAMPLE & BOOT_SAMPLE_SYSPLL_LOCK) && timeout--)
  75. udelay(1);
  76. //wait vpupll lock
  77. timeout = 1000;
  78. while (!(rSYS_BOOT_SAMPLE & BOOT_SAMPLE_VPUPLL_LOCK) && timeout--)
  79. udelay(1);
  80. // wait ddrpll lock
  81. timeout = 1000;
  82. while (!(rSYS_BOOT_SAMPLE & BOOT_SAMPLE_DDRPLL_LOCK) && timeout--)
  83. udelay(1);
  84. //wait mfcpll lock
  85. timeout = 1000;
  86. while (!(rSYS_BOOT_SAMPLE & BOOT_SAMPLE_MFCPLL_LOCK) && timeout--)
  87. udelay(1);
  88. // wait ahbpll lock
  89. timeout = 1000;
  90. while (!(rSYS_BOOT_SAMPLE & BOOT_SAMPLE_AHBPLL_LOCK) && timeout--)
  91. udelay(1);
  92. //wait gpupll lock
  93. timeout = 1000;
  94. while (!(rSYS_BOOT_SAMPLE & BOOT_SAMPLE_GPUPLL_LOCK) && timeout--)
  95. udelay(1);
  96. //wait tvpll lock
  97. timeout = 1000;
  98. while (!(rSYS_BOOT_SAMPLE & BOOT_SAMPLE_TVPLL_LOCK) && timeout--)
  99. udelay(1);
  100. udelay(1000);
  101. //clk gate enable
  102. rSYS_DDR_CTL1_CFG |=
  103. (1 << 8) | //TVPLL enable
  104. (1 << 7) | //GPUPLL enable
  105. (1 << 6) | //AHBPLL enable
  106. (1 << 5) | //MFCPLL enable
  107. (1 << 4) | //VPUPLL enable
  108. (1 << 3) | //DDRPLL enable
  109. (1 << 2) | //SYSPLL enable
  110. (1 << 1) | //DSPPLL enable
  111. (1 << 0); //CPUPLL enable
  112. udelay(1);
  113. rSYS_BUS_CLK_CFG |=
  114. (1 << 4) | //pclk to hclk/2
  115. (1 << 3) | //hclk to AHBPLL
  116. (1 << 2) | //xclk to SYSPLL
  117. (1 << 1) | //dclk to DDRPLL
  118. (1 << 0); //cclk to CPUPLL
  119. printf("rSYS_BOOT_SAMPLE = 0x%x\n", rSYS_BOOT_SAMPLE);
  120. }
  121. static void switch_to_main_crystal_osc(void)
  122. {
  123. clk_init();
  124. return;
  125. }
  126. void board_init_f(ulong dummy)
  127. {
  128. timer_init();
  129. board_early_init_f();
  130. puts("\nU-Boot " SPL_TPL_NAME " " PLAIN_VERSION " (" U_BOOT_DATE " - "U_BOOT_TIME " " U_BOOT_TZ ")\n");
  131. switch_to_main_crystal_osc();
  132. ddr3_sdramc_init();
  133. }
  134. #ifndef CONFIG_SPL_LIBCOMMON_SUPPORT
  135. void puts(const char *s)
  136. {
  137. serial_puts(s);
  138. }
  139. void putc(const char c)
  140. {
  141. serial_putc(c);
  142. }
  143. #endif
  144. #ifndef CONFIG_SPL_LIBGENERIC_SUPPORT
  145. void udelay(unsigned long usec)
  146. {
  147. timer_delay_us(usec);
  148. }
  149. void hang(void)
  150. {
  151. for (;;)
  152. ;
  153. }
  154. uint32_t __div64_32(uint64_t *n, uint32_t base)
  155. {
  156. uint64_t rem = *n;
  157. uint64_t b = base;
  158. uint64_t res, d = 1;
  159. uint32_t high = rem >> 32;
  160. /* Reduce the thing a bit first */
  161. res = 0;
  162. if (high >= base) {
  163. high /= base;
  164. res = (uint64_t) high << 32;
  165. rem -= (uint64_t) (high*base) << 32;
  166. }
  167. while ((int64_t)b > 0 && b < rem) {
  168. b = b+b;
  169. d = d+d;
  170. }
  171. do {
  172. if (rem >= b) {
  173. rem -= b;
  174. res += d;
  175. }
  176. b >>= 1;
  177. d >>= 1;
  178. } while (d);
  179. *n = res;
  180. return rem;
  181. }
  182. void * memmove(void * dest, const void *src, size_t count)
  183. {
  184. char *tmp, *s;
  185. if (dest <= src) {
  186. memcpy(dest, src, count);
  187. } else {
  188. tmp = (char *) dest + count;
  189. s = (char *) src + count;
  190. while (count--)
  191. *--tmp = *--s;
  192. }
  193. return dest;
  194. }
  195. #endif