rk3399-board-spl.c 4.5 KB

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