spl_ark1668ed_fpga.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include <common.h>
  3. #include <spl.h>
  4. #include <asm/arch/timer.h>
  5. #include <asm/arch/ark1668-sysreg.h>
  6. #include <asm/arch/ark-common.h>
  7. #include <asm-generic/gpio.h>
  8. //#define SYSPLL_CLK 330
  9. //#define CPUPLL_CLK 696
  10. //#define AUDPLL_CLK 426
  11. #define PAD_CTL8_TMP *((volatile unsigned int *)(0x50000160))
  12. #define PAD_CTL9_TMP *((volatile unsigned int *)(0x50000164))
  13. #define PAD_CTLA_TMP *((volatile unsigned int *)(0x50000168))
  14. /* static void switch_to_main_crystal_osc(void)
  15. {
  16. return;
  17. } */
  18. void board_init_f(ulong dummy)
  19. {
  20. u32 val;
  21. timer_init();
  22. board_early_init_f();
  23. printascii("<debug_uart0000> ");
  24. preloader_console_init();
  25. printascii("<debug_uart0001> ");
  26. #if 1
  27. /* nand pad enable */
  28. /* cle */
  29. val = PAD_CTL8_TMP;
  30. val &= ~(0x7<<27);
  31. val |= (0x5<<27);
  32. PAD_CTL8_TMP = val;
  33. /*
  34. ale [2:0]
  35. ren [5:3]
  36. wen [8:6]
  37. rb0 [11:9]
  38. cen0[14:12]
  39. */
  40. val = PAD_CTL9_TMP;
  41. val &= ~((0x7<<12)|(0x7<<9)|(0x7<<6)|(0x7<<3)|(0x7<<0));
  42. val |= ((0x5<<12)|(0x5<<9)|(0x5<<6)|(0x5<<3)|(0x5<<0));
  43. PAD_CTL9_TMP = val;
  44. val = PAD_CTL9_TMP;
  45. val &= ~((0x7<<27)|(0x7<<24)|(0x7<<21)|(0x7<<18)|(0x7<<15));
  46. val |= ((0x5<<27)|(0x5<<24)|(0x5<<21)|(0x5<<18)|(0x5<<15));
  47. PAD_CTL9_TMP = val;
  48. val = PAD_CTLA_TMP;
  49. val &= ~((0x7<<6)|(0x7<<3)|(0x7<<0));
  50. val |= ((0x5<<6)|(0x5<<3)|(0x5<<0));
  51. PAD_CTLA_TMP = val;
  52. #endif
  53. printascii("<debug_uart0002> ");
  54. mem_init();
  55. }
  56. #ifndef CONFIG_SPL_LIBCOMMON_SUPPORT
  57. void puts(const char *s)
  58. {
  59. serial_puts(s);
  60. }
  61. void putc(const char c)
  62. {
  63. serial_putc(c);
  64. }
  65. #endif
  66. #ifndef CONFIG_SPL_LIBGENERIC_SUPPORT
  67. void udelay(unsigned long usec)
  68. {
  69. timer_delay_us(usec);
  70. }
  71. void hang(void)
  72. {
  73. for (;;);
  74. }
  75. uint32_t __div64_32(uint64_t *n, uint32_t base)
  76. {
  77. uint64_t rem = *n;
  78. uint64_t b = base;
  79. uint64_t res, d = 1;
  80. uint32_t high = rem >> 32;
  81. /* Reduce the thing a bit first */
  82. res = 0;
  83. if (high >= base) {
  84. high /= base;
  85. res = (uint64_t) high << 32;
  86. rem -= (uint64_t) (high*base) << 32;
  87. }
  88. while ((int64_t)b > 0 && b < rem) {
  89. b = b+b;
  90. d = d+d;
  91. }
  92. do {
  93. if (rem >= b) {
  94. rem -= b;
  95. res += d;
  96. }
  97. b >>= 1;
  98. d >>= 1;
  99. } while (d);
  100. *n = res;
  101. return rem;
  102. }
  103. void * memmove(void * dest,const void *src,size_t count)
  104. {
  105. char *tmp, *s;
  106. if (dest <= src) {
  107. memcpy(dest, src, count);
  108. } else {
  109. tmp = (char *) dest + count;
  110. s = (char *) src + count;
  111. while (count--)
  112. *--tmp = *--s;
  113. }
  114. return dest;
  115. }
  116. #endif