rk3399-board-spl.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2016 Rockchip Electronics Co., Ltd
  4. * (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
  5. */
  6. #include <common.h>
  7. #include <asm/arch/bootrom.h>
  8. #include <asm/arch/clock.h>
  9. #include <asm/arch/grf_rk3399.h>
  10. #include <asm/arch/hardware.h>
  11. #include <asm/arch/periph.h>
  12. #include <asm/io.h>
  13. #include <debug_uart.h>
  14. #include <dm.h>
  15. #include <dm/pinctrl.h>
  16. #include <ram.h>
  17. #include <spl.h>
  18. #include <syscon.h>
  19. void board_return_to_bootrom(void)
  20. {
  21. back_to_bootrom(BROM_BOOT_NEXTSTAGE);
  22. }
  23. static const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
  24. [BROM_BOOTSOURCE_EMMC] = "/sdhci@fe330000",
  25. [BROM_BOOTSOURCE_SPINOR] = "/spi@ff1d0000",
  26. [BROM_BOOTSOURCE_SD] = "/dwmmc@fe320000",
  27. };
  28. const char *board_spl_was_booted_from(void)
  29. {
  30. u32 bootdevice_brom_id = readl(RK3399_BROM_BOOTSOURCE_ID_ADDR);
  31. const char *bootdevice_ofpath = NULL;
  32. if (bootdevice_brom_id < ARRAY_SIZE(boot_devices))
  33. bootdevice_ofpath = boot_devices[bootdevice_brom_id];
  34. if (bootdevice_ofpath)
  35. debug("%s: brom_bootdevice_id %x maps to '%s'\n",
  36. __func__, bootdevice_brom_id, bootdevice_ofpath);
  37. else
  38. debug("%s: failed to resolve brom_bootdevice_id %x\n",
  39. __func__, bootdevice_brom_id);
  40. return bootdevice_ofpath;
  41. }
  42. u32 spl_boot_device(void)
  43. {
  44. u32 boot_device = BOOT_DEVICE_MMC1;
  45. if (CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM))
  46. return BOOT_DEVICE_BOOTROM;
  47. return boot_device;
  48. }
  49. const char *spl_decode_boot_device(u32 boot_device)
  50. {
  51. int i;
  52. static const struct {
  53. u32 boot_device;
  54. const char *ofpath;
  55. } spl_boot_devices_tbl[] = {
  56. { BOOT_DEVICE_MMC1, "/dwmmc@fe320000" },
  57. { BOOT_DEVICE_MMC2, "/sdhci@fe330000" },
  58. { BOOT_DEVICE_SPI, "/spi@ff1d0000" },
  59. };
  60. for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i)
  61. if (spl_boot_devices_tbl[i].boot_device == boot_device)
  62. return spl_boot_devices_tbl[i].ofpath;
  63. return NULL;
  64. }
  65. void spl_perform_fixups(struct spl_image_info *spl_image)
  66. {
  67. void *blob = spl_image->fdt_addr;
  68. const char *boot_ofpath;
  69. int chosen;
  70. /*
  71. * Inject the ofpath of the device the full U-Boot (or Linux in
  72. * Falcon-mode) was booted from into the FDT, if a FDT has been
  73. * loaded at the same time.
  74. */
  75. if (!blob)
  76. return;
  77. boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
  78. if (!boot_ofpath) {
  79. pr_err("%s: could not map boot_device to ofpath\n", __func__);
  80. return;
  81. }
  82. chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
  83. if (chosen < 0) {
  84. pr_err("%s: could not find/create '/chosen'\n", __func__);
  85. return;
  86. }
  87. fdt_setprop_string(blob, chosen,
  88. "u-boot,spl-boot-device", boot_ofpath);
  89. }
  90. #define TIMER_CHN10_BASE 0xff8680a0
  91. #define TIMER_END_COUNT_L 0x00
  92. #define TIMER_END_COUNT_H 0x04
  93. #define TIMER_INIT_COUNT_L 0x10
  94. #define TIMER_INIT_COUNT_H 0x14
  95. #define TIMER_CONTROL_REG 0x1c
  96. #define TIMER_EN 0x1
  97. #define TIMER_FMODE (0 << 1)
  98. #define TIMER_RMODE (1 << 1)
  99. void secure_timer_init(void)
  100. {
  101. writel(0xffffffff, TIMER_CHN10_BASE + TIMER_END_COUNT_L);
  102. writel(0xffffffff, TIMER_CHN10_BASE + TIMER_END_COUNT_H);
  103. writel(0, TIMER_CHN10_BASE + TIMER_INIT_COUNT_L);
  104. writel(0, TIMER_CHN10_BASE + TIMER_INIT_COUNT_H);
  105. writel(TIMER_EN | TIMER_FMODE, TIMER_CHN10_BASE + TIMER_CONTROL_REG);
  106. }
  107. void board_debug_uart_init(void)
  108. {
  109. #define GRF_BASE 0xff770000
  110. struct rk3399_grf_regs * const grf = (void *)GRF_BASE;
  111. #if defined(CONFIG_DEBUG_UART_BASE) && (CONFIG_DEBUG_UART_BASE == 0xff180000)
  112. /* Enable early UART0 on the RK3399 */
  113. rk_clrsetreg(&grf->gpio2c_iomux,
  114. GRF_GPIO2C0_SEL_MASK,
  115. GRF_UART0BT_SIN << GRF_GPIO2C0_SEL_SHIFT);
  116. rk_clrsetreg(&grf->gpio2c_iomux,
  117. GRF_GPIO2C1_SEL_MASK,
  118. GRF_UART0BT_SOUT << GRF_GPIO2C1_SEL_SHIFT);
  119. #else
  120. /* Enable early UART2 channel C on the RK3399 */
  121. rk_clrsetreg(&grf->gpio4c_iomux,
  122. GRF_GPIO4C3_SEL_MASK,
  123. GRF_UART2DGBC_SIN << GRF_GPIO4C3_SEL_SHIFT);
  124. rk_clrsetreg(&grf->gpio4c_iomux,
  125. GRF_GPIO4C4_SEL_MASK,
  126. GRF_UART2DBGC_SOUT << GRF_GPIO4C4_SEL_SHIFT);
  127. /* Set channel C as UART2 input */
  128. rk_clrsetreg(&grf->soc_con7,
  129. GRF_UART_DBG_SEL_MASK,
  130. GRF_UART_DBG_SEL_C << GRF_UART_DBG_SEL_SHIFT);
  131. #endif
  132. }
  133. void board_init_f(ulong dummy)
  134. {
  135. struct udevice *pinctrl;
  136. struct udevice *dev;
  137. struct rk3399_pmusgrf_regs *sgrf;
  138. struct rk3399_grf_regs *grf;
  139. int ret;
  140. #define EARLY_UART
  141. #ifdef EARLY_UART
  142. /*
  143. * Debug UART can be used from here if required:
  144. *
  145. * debug_uart_init();
  146. * printch('a');
  147. * printhex8(0x1234);
  148. * printascii("string");
  149. */
  150. debug_uart_init();
  151. printascii("U-Boot SPL board init\n");
  152. #endif
  153. ret = spl_early_init();
  154. if (ret) {
  155. debug("spl_early_init() failed: %d\n", ret);
  156. hang();
  157. }
  158. /*
  159. * Disable DDR and SRAM security regions.
  160. *
  161. * As we are entered from the BootROM, the region from
  162. * 0x0 through 0xfffff (i.e. the first MB of memory) will
  163. * be protected. This will cause issues with the DW_MMC
  164. * driver, which tries to DMA from/to the stack (likely)
  165. * located in this range.
  166. */
  167. sgrf = syscon_get_first_range(ROCKCHIP_SYSCON_PMUSGRF);
  168. rk_clrsetreg(&sgrf->ddr_rgn_con[16], 0x1ff, 0);
  169. rk_clrreg(&sgrf->slv_secure_con4, 0x2000);
  170. /* eMMC clock generator: disable the clock multipilier */
  171. grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
  172. rk_clrreg(&grf->emmccore_con[11], 0x0ff);
  173. secure_timer_init();
  174. ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
  175. if (ret) {
  176. debug("Pinctrl init failed: %d\n", ret);
  177. return;
  178. }
  179. ret = uclass_get_device(UCLASS_RAM, 0, &dev);
  180. if (ret) {
  181. debug("DRAM init failed: %d\n", ret);
  182. return;
  183. }
  184. }
  185. #ifdef CONFIG_SPL_LOAD_FIT
  186. int board_fit_config_name_match(const char *name)
  187. {
  188. /* Just empty function now - can't decide what to choose */
  189. debug("%s: %s\n", __func__, name);
  190. return 0;
  191. }
  192. #endif