spl.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2022-2023 StarFive Technology Co., Ltd.
  4. * Author: yanhong <yanhong.wang@starfivetech.com>
  5. *
  6. */
  7. #include <common.h>
  8. #include <init.h>
  9. #include <asm/arch/spl.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/gpio.h>
  12. #include <asm/arch/jh7110-regs.h>
  13. #include <asm/arch/clk.h>
  14. #include <image.h>
  15. #include <log.h>
  16. #include <spl.h>
  17. #define MODE_SELECT_REG 0x1702002c
  18. int spl_board_init_f(void)
  19. {
  20. int ret;
  21. ret = spl_soc_init();
  22. if (ret) {
  23. debug("JH7110 SPL init failed: %d\n", ret);
  24. return ret;
  25. }
  26. return 0;
  27. }
  28. u32 spl_boot_device(void)
  29. {
  30. int boot_mode = 0;
  31. boot_mode = readl((const volatile void *)MODE_SELECT_REG) & 0x3;
  32. switch (boot_mode) {
  33. case 0:
  34. return BOOT_DEVICE_SPI;
  35. case 1:
  36. return BOOT_DEVICE_MMC2;
  37. case 2:
  38. return BOOT_DEVICE_MMC1;
  39. case 3:
  40. return BOOT_DEVICE_UART;
  41. default:
  42. debug("Unsupported boot device 0x%x.\n",
  43. boot_mode);
  44. return BOOT_DEVICE_NONE;
  45. }
  46. }
  47. struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
  48. {
  49. return (struct image_header *)(STARFIVE_SPL_BOOT_LOAD_ADDR);
  50. }
  51. void board_init_f(ulong dummy)
  52. {
  53. int ret;
  54. /* Adjust cpu frequency, the default is 1.0GHz */
  55. starfive_jh7110_pll_set_rate(PLL0, 1000000000);
  56. /*change pll2 to 1188MHz*/
  57. starfive_jh7110_pll_set_rate(PLL2, 1188000000);
  58. /*DDR control depend clk init*/
  59. clrsetbits_le32(SYS_CRG_BASE, CLK_CPU_ROOT_SW_MASK,
  60. BIT(CLK_CPU_ROOT_SW_SHIFT) & CLK_CPU_ROOT_SW_MASK);
  61. clrsetbits_le32(SYS_CRG_BASE + CLK_BUS_ROOT_OFFSET,
  62. CLK_BUS_ROOT_SW_MASK,
  63. BIT(CLK_BUS_ROOT_SW_SHIFT) & CLK_BUS_ROOT_SW_MASK);
  64. /*Set clk_perh_root clk default mux sel to pll2*/
  65. clrsetbits_le32(SYS_CRG_BASE + CLK_PERH_ROOT_OFFSET,
  66. CLK_PERH_ROOT_MASK,
  67. BIT(CLK_PERH_ROOT_SHIFT) & CLK_PERH_ROOT_MASK);
  68. clrsetbits_le32(SYS_CRG_BASE + CLK_NOC_BUS_STG_AXI_OFFSET,
  69. CLK_NOC_BUS_STG_AXI_EN_MASK,
  70. BIT(CLK_NOC_BUS_STG_AXI_EN_SHIFT)
  71. & CLK_NOC_BUS_STG_AXI_EN_MASK);
  72. clrsetbits_le32(AON_CRG_BASE + CLK_AON_APB_FUNC_OFFSET,
  73. CLK_AON_APB_FUNC_SW_MASK,
  74. BIT(CLK_AON_APB_FUNC_SW_SHIFT) & CLK_AON_APB_FUNC_SW_MASK);
  75. /* switch qspi clk to pll0 */
  76. clrsetbits_le32(SYS_CRG_BASE + CLK_QSPI_REF_OFFSET,
  77. CLK_QSPI_REF_SW_MASK,
  78. BIT(CLK_QSPI_REF_SW_SHIFT) & CLK_QSPI_REF_SW_MASK);
  79. /*set GPIO to 3.3v*/
  80. setbits_le32(SYS_SYSCON_BASE + 0xC, 0x0);
  81. /* Improved GMAC0 TX I/O PAD capability */
  82. clrsetbits_le32(AON_IOMUX_BASE + 0x78, 0x3, BIT(0) & 0x3);
  83. clrsetbits_le32(AON_IOMUX_BASE + 0x7c, 0x3, BIT(0) & 0x3);
  84. clrsetbits_le32(AON_IOMUX_BASE + 0x80, 0x3, BIT(0) & 0x3);
  85. clrsetbits_le32(AON_IOMUX_BASE + 0x84, 0x3, BIT(0) & 0x3);
  86. clrsetbits_le32(AON_IOMUX_BASE + 0x88, 0x3, BIT(0) & 0x3);
  87. /* Improved GMAC1 TX I/O PAD capability */
  88. clrsetbits_le32(SYS_IOMUX_BASE + 0x26c, 0x3, BIT(0) & 0x3);
  89. clrsetbits_le32(SYS_IOMUX_BASE + 0x270, 0x3, BIT(0) & 0x3);
  90. clrsetbits_le32(SYS_IOMUX_BASE + 0x274, 0x3, BIT(0) & 0x3);
  91. clrsetbits_le32(SYS_IOMUX_BASE + 0x278, 0x3, BIT(0) & 0x3);
  92. clrsetbits_le32(SYS_IOMUX_BASE + 0x27c, 0x3, BIT(0) & 0x3);
  93. SYS_IOMUX_DOEN(62, LOW);
  94. SYS_IOMUX_DOUT(62, 19);
  95. SYS_IOMUX_SET_DS(64, 2);
  96. SYS_IOMUX_SET_SLEW(64, 1);
  97. SYS_IOMUX_SET_DS(65, 1);
  98. SYS_IOMUX_SET_DS(66, 1);
  99. SYS_IOMUX_SET_DS(67, 1);
  100. SYS_IOMUX_SET_DS(68, 1);
  101. SYS_IOMUX_SET_DS(69, 1);
  102. SYS_IOMUX_SET_DS(70, 1);
  103. SYS_IOMUX_SET_DS(71, 1);
  104. SYS_IOMUX_SET_DS(72, 1);
  105. SYS_IOMUX_SET_DS(73, 1);
  106. SYS_IOMUX_DOEN(10, LOW);
  107. SYS_IOMUX_DOUT(10, 55);
  108. SYS_IOMUX_SET_SLEW(10, 1);
  109. SYS_IOMUX_SET_DS(10, 2);
  110. SYS_IOMUX_COMPLEX(9, 44, 57, 19);
  111. SYS_IOMUX_SET_DS(9, 1);
  112. SYS_IOMUX_COMPLEX(11, 45, 58, 20);
  113. SYS_IOMUX_SET_DS(11, 1);
  114. SYS_IOMUX_COMPLEX(12, 46, 59, 21);
  115. SYS_IOMUX_SET_DS(12, 1);
  116. SYS_IOMUX_COMPLEX(7, 47, 60, 22);
  117. SYS_IOMUX_SET_DS(7, 1);
  118. SYS_IOMUX_COMPLEX(8, 48, 61, 23);
  119. SYS_IOMUX_SET_DS(8, 1);
  120. ret = spl_early_init();
  121. if (ret)
  122. panic("spl_early_init() failed: %d\n", ret);
  123. arch_cpu_init_dm();
  124. preloader_console_init();
  125. ret = spl_board_init_f();
  126. if (ret) {
  127. debug("spl_board_init_f init failed: %d\n", ret);
  128. return;
  129. }
  130. }
  131. #ifdef CONFIG_SPL_LOAD_FIT
  132. int board_fit_config_name_match(const char *name)
  133. {
  134. /* boot using first FIT config */
  135. return 0;
  136. }
  137. #endif