spl.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2022 StarFive Technology Co., Ltd.
  4. * Author: Yanhong Wang<yanhong.wang@starfivetech.com>
  5. */
  6. #include <common.h>
  7. #include <asm/arch/eeprom.h>
  8. #include <asm/arch/regs.h>
  9. #include <asm/arch/spl.h>
  10. #include <asm/io.h>
  11. #include <dt-bindings/clock/starfive,jh7110-crg.h>
  12. #include <fdt_support.h>
  13. #include <linux/libfdt.h>
  14. #include <log.h>
  15. #include <spl.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. #define JH7110_CLK_CPU_ROOT_OFFSET 0x0U
  18. #define JH7110_CLK_CPU_ROOT_SHIFT 24
  19. #define JH7110_CLK_CPU_ROOT_MASK GENMASK(29, 24)
  20. struct starfive_vf2_pro {
  21. const char *path;
  22. const char *name;
  23. const char *value;
  24. };
  25. static const struct starfive_vf2_pro starfive_vera[] = {
  26. {"/soc/ethernet@16030000/mdio/ethernet-phy@0", "rx-internal-delay-ps",
  27. "1900"},
  28. {"/soc/ethernet@16030000/mdio/ethernet-phy@0", "tx-internal-delay-ps",
  29. "1350"}
  30. };
  31. static const struct starfive_vf2_pro starfive_verb[] = {
  32. {"/soc/ethernet@16030000", "starfive,tx-use-rgmii-clk", NULL},
  33. {"/soc/ethernet@16040000", "starfive,tx-use-rgmii-clk", NULL},
  34. {"/soc/ethernet@16030000/mdio/ethernet-phy@0",
  35. "motorcomm,tx-clk-adj-enabled", NULL},
  36. {"/soc/ethernet@16030000/mdio/ethernet-phy@0",
  37. "motorcomm,tx-clk-100-inverted", NULL},
  38. {"/soc/ethernet@16030000/mdio/ethernet-phy@0",
  39. "motorcomm,tx-clk-1000-inverted", NULL},
  40. {"/soc/ethernet@16030000/mdio/ethernet-phy@0",
  41. "rx-internal-delay-ps", "1900"},
  42. {"/soc/ethernet@16030000/mdio/ethernet-phy@0",
  43. "tx-internal-delay-ps", "1500"},
  44. {"/soc/ethernet@16040000/mdio/ethernet-phy@1",
  45. "motorcomm,tx-clk-adj-enabled", NULL},
  46. { "/soc/ethernet@16040000/mdio/ethernet-phy@1",
  47. "motorcomm,tx-clk-100-inverted", NULL},
  48. {"/soc/ethernet@16040000/mdio/ethernet-phy@1",
  49. "rx-internal-delay-ps", "0"},
  50. {"/soc/ethernet@16040000/mdio/ethernet-phy@1",
  51. "tx-internal-delay-ps", "0"},
  52. };
  53. void spl_fdt_fixup_version_a(void *fdt)
  54. {
  55. u32 phandle;
  56. u8 i;
  57. int offset;
  58. int ret;
  59. fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model",
  60. "StarFive VisionFive 2 v1.2A");
  61. offset = fdt_path_offset(fdt, "/soc/clock-controller@13020000");
  62. phandle = fdt_get_phandle(fdt, offset);
  63. offset = fdt_path_offset(fdt, "/soc/ethernet@16040000");
  64. fdt_setprop_u32(fdt, offset, "assigned-clocks", phandle);
  65. fdt_appendprop_u32(fdt, offset, "assigned-clocks", JH7110_SYSCLK_GMAC1_TX);
  66. fdt_appendprop_u32(fdt, offset, "assigned-clocks", phandle);
  67. fdt_appendprop_u32(fdt, offset, "assigned-clocks", JH7110_SYSCLK_GMAC1_RX);
  68. fdt_setprop_u32(fdt, offset, "assigned-clock-parents", phandle);
  69. fdt_appendprop_u32(fdt, offset, "assigned-clock-parents",
  70. JH7110_SYSCLK_GMAC1_RMII_RTX);
  71. fdt_appendprop_u32(fdt, offset, "assigned-clock-parents", phandle);
  72. fdt_appendprop_u32(fdt, offset, "assigned-clock-parents",
  73. JH7110_SYSCLK_GMAC1_RMII_RTX);
  74. fdt_setprop_string(fdt, fdt_path_offset(fdt, "/soc/ethernet@16040000"),
  75. "phy-mode", "rmii");
  76. for (i = 0; i < ARRAY_SIZE(starfive_vera); i++) {
  77. offset = fdt_path_offset(fdt, starfive_vera[i].path);
  78. if (starfive_vera[i].value)
  79. ret = fdt_setprop_u32(fdt, offset, starfive_vera[i].name,
  80. dectoul(starfive_vera[i].value, NULL));
  81. else
  82. ret = fdt_setprop_empty(fdt, offset, starfive_vera[i].name);
  83. if (ret) {
  84. pr_err("%s set prop %s fail.\n", __func__, starfive_vera[i].name);
  85. break;
  86. }
  87. }
  88. }
  89. void spl_fdt_fixup_version_b(void *fdt)
  90. {
  91. u32 phandle;
  92. u8 i;
  93. int offset;
  94. int ret;
  95. fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model",
  96. "StarFive VisionFive 2 v1.3B");
  97. /* gmac0 */
  98. offset = fdt_path_offset(fdt, "/soc/clock-controller@17000000");
  99. phandle = fdt_get_phandle(fdt, offset);
  100. offset = fdt_path_offset(fdt, "/soc/ethernet@16030000");
  101. fdt_setprop_u32(fdt, offset, "assigned-clocks", phandle);
  102. fdt_appendprop_u32(fdt, offset, "assigned-clocks", JH7110_AONCLK_GMAC0_TX);
  103. fdt_setprop_u32(fdt, offset, "assigned-clock-parents", phandle);
  104. fdt_appendprop_u32(fdt, offset, "assigned-clock-parents",
  105. JH7110_AONCLK_GMAC0_RMII_RTX);
  106. /* gmac1 */
  107. offset = fdt_path_offset(fdt, "/soc/clock-controller@13020000");
  108. phandle = fdt_get_phandle(fdt, offset);
  109. offset = fdt_path_offset(fdt, "/soc/ethernet@16040000");
  110. fdt_setprop_u32(fdt, offset, "assigned-clocks", phandle);
  111. fdt_appendprop_u32(fdt, offset, "assigned-clocks", JH7110_SYSCLK_GMAC1_TX);
  112. fdt_setprop_u32(fdt, offset, "assigned-clock-parents", phandle);
  113. fdt_appendprop_u32(fdt, offset, "assigned-clock-parents",
  114. JH7110_SYSCLK_GMAC1_RMII_RTX);
  115. for (i = 0; i < ARRAY_SIZE(starfive_verb); i++) {
  116. offset = fdt_path_offset(fdt, starfive_verb[i].path);
  117. if (starfive_verb[i].value)
  118. ret = fdt_setprop_u32(fdt, offset, starfive_verb[i].name,
  119. dectoul(starfive_verb[i].value, NULL));
  120. else
  121. ret = fdt_setprop_empty(fdt, offset, starfive_verb[i].name);
  122. if (ret) {
  123. pr_err("%s set prop %s fail.\n", __func__, starfive_verb[i].name);
  124. break;
  125. }
  126. }
  127. }
  128. void spl_perform_fixups(struct spl_image_info *spl_image)
  129. {
  130. u8 version;
  131. version = get_pcb_revision_from_eeprom();
  132. switch (version) {
  133. case 'a':
  134. case 'A':
  135. spl_fdt_fixup_version_a(spl_image->fdt_addr);
  136. break;
  137. case 'b':
  138. case 'B':
  139. default:
  140. spl_fdt_fixup_version_b(spl_image->fdt_addr);
  141. break;
  142. };
  143. /* Update the memory size which read form eeprom or DT */
  144. fdt_fixup_memory(spl_image->fdt_addr, 0x40000000, gd->ram_size);
  145. }
  146. int spl_board_init_f(void)
  147. {
  148. int ret;
  149. ret = spl_soc_init();
  150. if (ret) {
  151. debug("JH7110 SPL init failed: %d\n", ret);
  152. return ret;
  153. }
  154. return 0;
  155. }
  156. u32 spl_boot_device(void)
  157. {
  158. u32 mode;
  159. mode = in_le32(JH7110_BOOT_MODE_SELECT_REG)
  160. & JH7110_BOOT_MODE_SELECT_MASK;
  161. switch (mode) {
  162. case 0:
  163. return BOOT_DEVICE_SPI;
  164. case 1:
  165. return BOOT_DEVICE_MMC2;
  166. case 2:
  167. return BOOT_DEVICE_MMC1;
  168. case 3:
  169. return BOOT_DEVICE_UART;
  170. default:
  171. debug("Unsupported boot device 0x%x.\n", mode);
  172. return BOOT_DEVICE_NONE;
  173. }
  174. }
  175. void board_init_f(ulong dummy)
  176. {
  177. int ret;
  178. ret = spl_early_init();
  179. if (ret)
  180. panic("spl_early_init() failed: %d\n", ret);
  181. riscv_cpu_setup(NULL, NULL);
  182. preloader_console_init();
  183. /* Set the parent clock of cpu_root clock to pll0,
  184. * it must be initialized here
  185. */
  186. clrsetbits_le32(JH7110_SYS_CRG + JH7110_CLK_CPU_ROOT_OFFSET,
  187. JH7110_CLK_CPU_ROOT_MASK,
  188. BIT(JH7110_CLK_CPU_ROOT_SHIFT));
  189. ret = spl_board_init_f();
  190. if (ret) {
  191. debug("spl_board_init_f init failed: %d\n", ret);
  192. return;
  193. }
  194. }
  195. #if CONFIG_IS_ENABLED(SPL_LOAD_FIT)
  196. int board_fit_config_name_match(const char *name)
  197. {
  198. /* boot using first FIT config */
  199. return 0;
  200. }
  201. #endif