rk3368-board-tpl.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
  4. */
  5. #include <common.h>
  6. #include <asm/arch/clock.h>
  7. #include <debug_uart.h>
  8. #include <dm.h>
  9. #include <ram.h>
  10. #include <spl.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/bootrom.h>
  13. #include <asm/arch/cru_rk3368.h>
  14. #include <asm/arch/grf_rk3368.h>
  15. #include <asm/arch/hardware.h>
  16. #include <asm/arch/timer.h>
  17. #include <syscon.h>
  18. /*
  19. * The SPL (and also the full U-Boot stage on the RK3368) will run in
  20. * secure mode (i.e. EL3) and an ATF will eventually be booted before
  21. * starting up the operating system... so we can initialize the SGRF
  22. * here and rely on the ATF installing the final (secure) policy
  23. * later.
  24. */
  25. static inline uintptr_t sgrf_soc_con_addr(unsigned no)
  26. {
  27. const uintptr_t SGRF_BASE =
  28. (uintptr_t)syscon_get_first_range(ROCKCHIP_SYSCON_SGRF);
  29. return SGRF_BASE + sizeof(u32) * no;
  30. }
  31. static inline uintptr_t sgrf_busdmac_addr(unsigned no)
  32. {
  33. const uintptr_t SGRF_BASE =
  34. (uintptr_t)syscon_get_first_range(ROCKCHIP_SYSCON_SGRF);
  35. const uintptr_t SGRF_BUSDMAC_OFFSET = 0x100;
  36. const uintptr_t SGRF_BUSDMAC_BASE = SGRF_BASE + SGRF_BUSDMAC_OFFSET;
  37. return SGRF_BUSDMAC_BASE + sizeof(u32) * no;
  38. }
  39. static void sgrf_init(void)
  40. {
  41. struct rk3368_cru * const cru =
  42. (struct rk3368_cru * const)rockchip_get_cru();
  43. const u16 SGRF_SOC_CON_SEC = GENMASK(15, 0);
  44. const u16 SGRF_BUSDMAC_CON0_SEC = BIT(2);
  45. const u16 SGRF_BUSDMAC_CON1_SEC = GENMASK(15, 12);
  46. /* Set all configurable IP to 'non secure'-mode */
  47. rk_setreg(sgrf_soc_con_addr(5), SGRF_SOC_CON_SEC);
  48. rk_setreg(sgrf_soc_con_addr(6), SGRF_SOC_CON_SEC);
  49. rk_setreg(sgrf_soc_con_addr(7), SGRF_SOC_CON_SEC);
  50. /*
  51. * From rockchip-uboot/arch/arm/cpu/armv8/rk33xx/cpu.c
  52. * Original comment: "ddr space set no secure mode"
  53. */
  54. rk_clrreg(sgrf_soc_con_addr(8), SGRF_SOC_CON_SEC);
  55. rk_clrreg(sgrf_soc_con_addr(9), SGRF_SOC_CON_SEC);
  56. rk_clrreg(sgrf_soc_con_addr(10), SGRF_SOC_CON_SEC);
  57. /* Set 'secure dma' to 'non secure'-mode */
  58. rk_setreg(sgrf_busdmac_addr(0), SGRF_BUSDMAC_CON0_SEC);
  59. rk_setreg(sgrf_busdmac_addr(1), SGRF_BUSDMAC_CON1_SEC);
  60. dsb(); /* barrier */
  61. rk_setreg(&cru->softrst_con[1], DMA1_SRST_REQ);
  62. rk_setreg(&cru->softrst_con[4], DMA2_SRST_REQ);
  63. dsb(); /* barrier */
  64. udelay(10);
  65. rk_clrreg(&cru->softrst_con[1], DMA1_SRST_REQ);
  66. rk_clrreg(&cru->softrst_con[4], DMA2_SRST_REQ);
  67. }
  68. void board_debug_uart_init(void)
  69. {
  70. /*
  71. * N.B.: This is called before the device-model has been
  72. * initialised. For this reason, we can not access
  73. * the GRF address range using the syscon API.
  74. */
  75. struct rk3368_grf * const grf =
  76. (struct rk3368_grf * const)0xff770000;
  77. enum {
  78. GPIO2D1_MASK = GENMASK(3, 2),
  79. GPIO2D1_GPIO = 0,
  80. GPIO2D1_UART0_SOUT = (1 << 2),
  81. GPIO2D0_MASK = GENMASK(1, 0),
  82. GPIO2D0_GPIO = 0,
  83. GPIO2D0_UART0_SIN = (1 << 0),
  84. };
  85. #if defined(CONFIG_DEBUG_UART_BASE) && (CONFIG_DEBUG_UART_BASE == 0xff180000)
  86. /* Enable early UART0 on the RK3368 */
  87. rk_clrsetreg(&grf->gpio2d_iomux,
  88. GPIO2D0_MASK, GPIO2D0_UART0_SIN);
  89. rk_clrsetreg(&grf->gpio2d_iomux,
  90. GPIO2D1_MASK, GPIO2D1_UART0_SOUT);
  91. #endif
  92. }
  93. void board_init_f(ulong dummy)
  94. {
  95. struct udevice *dev;
  96. int ret;
  97. #define EARLY_UART
  98. #ifdef EARLY_UART
  99. /*
  100. * Debug UART can be used from here if required:
  101. *
  102. * debug_uart_init();
  103. * printch('a');
  104. * printhex8(0x1234);
  105. * printascii("string");
  106. */
  107. debug_uart_init();
  108. printascii("U-Boot TPL board init\n");
  109. #endif
  110. ret = spl_early_init();
  111. if (ret) {
  112. debug("spl_early_init() failed: %d\n", ret);
  113. hang();
  114. }
  115. /* Reset security, so we can use DMA in the MMC drivers */
  116. sgrf_init();
  117. ret = uclass_get_device(UCLASS_RAM, 0, &dev);
  118. if (ret) {
  119. debug("DRAM init failed: %d\n", ret);
  120. return;
  121. }
  122. }
  123. void board_return_to_bootrom(void)
  124. {
  125. back_to_bootrom(BROM_BOOT_NEXTSTAGE);
  126. }
  127. u32 spl_boot_device(void)
  128. {
  129. return BOOT_DEVICE_BOOTROM;
  130. }