soc.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <platform_def.h>
  7. #include <arch_helpers.h>
  8. #include <common/debug.h>
  9. #include <lib/mmio.h>
  10. #include <plat_private.h>
  11. #include <rk3368_def.h>
  12. #include <soc.h>
  13. static uint32_t plls_con[END_PLL_ID][4];
  14. /* Table of regions to map using the MMU. */
  15. const mmap_region_t plat_rk_mmap[] = {
  16. MAP_REGION_FLAT(CCI400_BASE, CCI400_SIZE,
  17. MT_DEVICE | MT_RW | MT_SECURE),
  18. MAP_REGION_FLAT(GIC400_BASE, GIC400_SIZE,
  19. MT_DEVICE | MT_RW | MT_SECURE),
  20. MAP_REGION_FLAT(STIME_BASE, STIME_SIZE,
  21. MT_DEVICE | MT_RW | MT_SECURE),
  22. MAP_REGION_FLAT(SGRF_BASE, SGRF_SIZE,
  23. MT_DEVICE | MT_RW | MT_SECURE),
  24. MAP_REGION_FLAT(PMUSRAM_BASE, PMUSRAM_SIZE,
  25. MT_MEMORY | MT_RW | MT_SECURE),
  26. MAP_REGION_FLAT(PMU_BASE, PMU_SIZE,
  27. MT_DEVICE | MT_RW | MT_SECURE),
  28. MAP_REGION_FLAT(UART0_BASE, UART0_SIZE,
  29. MT_DEVICE | MT_RW | MT_SECURE),
  30. MAP_REGION_FLAT(UART1_BASE, UART1_SIZE,
  31. MT_DEVICE | MT_RW | MT_SECURE),
  32. MAP_REGION_FLAT(UART2_BASE, UART2_SIZE,
  33. MT_DEVICE | MT_RW | MT_SECURE),
  34. MAP_REGION_FLAT(UART3_BASE, UART3_SIZE,
  35. MT_DEVICE | MT_RW | MT_SECURE),
  36. MAP_REGION_FLAT(UART4_BASE, UART4_SIZE,
  37. MT_DEVICE | MT_RW | MT_SECURE),
  38. MAP_REGION_FLAT(CRU_BASE, CRU_SIZE,
  39. MT_DEVICE | MT_RW | MT_SECURE),
  40. MAP_REGION_FLAT(DDR_PCTL_BASE, DDR_PCTL_SIZE,
  41. MT_DEVICE | MT_RW | MT_SECURE),
  42. MAP_REGION_FLAT(DDR_PHY_BASE, DDR_PHY_SIZE,
  43. MT_DEVICE | MT_RW | MT_SECURE),
  44. MAP_REGION_FLAT(GRF_BASE, GRF_SIZE,
  45. MT_DEVICE | MT_RW | MT_SECURE),
  46. MAP_REGION_FLAT(SERVICE_BUS_BASE, SERVICE_BUS_SISE,
  47. MT_DEVICE | MT_RW | MT_SECURE),
  48. { 0 }
  49. };
  50. /* The RockChip power domain tree descriptor */
  51. const unsigned char rockchip_power_domain_tree_desc[] = {
  52. /* No of root nodes */
  53. PLATFORM_SYSTEM_COUNT,
  54. /* No of children for the root node */
  55. PLATFORM_CLUSTER_COUNT,
  56. /* No of children for the first cluster node */
  57. PLATFORM_CLUSTER0_CORE_COUNT,
  58. /* No of children for the second cluster node */
  59. PLATFORM_CLUSTER1_CORE_COUNT
  60. };
  61. void secure_timer_init(void)
  62. {
  63. mmio_write_32(STIMER1_BASE + TIMER_LOADE_COUNT0, 0xffffffff);
  64. mmio_write_32(STIMER1_BASE + TIMER_LOADE_COUNT1, 0xffffffff);
  65. /* auto reload & enable the timer */
  66. mmio_write_32(STIMER1_BASE + TIMER_CONTROL_REG, TIMER_EN);
  67. }
  68. void sgrf_init(void)
  69. {
  70. /* setting all configurable ip into no-secure */
  71. mmio_write_32(SGRF_BASE + SGRF_SOC_CON(5), SGRF_SOC_CON_NS);
  72. mmio_write_32(SGRF_BASE + SGRF_SOC_CON(6), SGRF_SOC_CON7_BITS);
  73. mmio_write_32(SGRF_BASE + SGRF_SOC_CON(7), SGRF_SOC_CON_NS);
  74. /* secure dma to no sesure */
  75. mmio_write_32(SGRF_BASE + SGRF_BUSDMAC_CON(0), SGRF_BUSDMAC_CON0_NS);
  76. mmio_write_32(SGRF_BASE + SGRF_BUSDMAC_CON(1), SGRF_BUSDMAC_CON1_NS);
  77. dsb();
  78. /* rst dma1 */
  79. mmio_write_32(CRU_BASE + CRU_SOFTRSTS_CON(1),
  80. RST_DMA1_MSK | (RST_DMA1_MSK << 16));
  81. /* rst dma2 */
  82. mmio_write_32(CRU_BASE + CRU_SOFTRSTS_CON(4),
  83. RST_DMA2_MSK | (RST_DMA2_MSK << 16));
  84. dsb();
  85. /* release dma1 rst*/
  86. mmio_write_32(CRU_BASE + CRU_SOFTRSTS_CON(1), (RST_DMA1_MSK << 16));
  87. /* release dma2 rst*/
  88. mmio_write_32(CRU_BASE + CRU_SOFTRSTS_CON(4), (RST_DMA2_MSK << 16));
  89. }
  90. void plat_rockchip_soc_init(void)
  91. {
  92. secure_timer_init();
  93. sgrf_init();
  94. }
  95. void regs_updata_bits(uintptr_t addr, uint32_t val,
  96. uint32_t mask, uint32_t shift)
  97. {
  98. uint32_t tmp, orig;
  99. orig = mmio_read_32(addr);
  100. tmp = orig & ~(mask << shift);
  101. tmp |= (val & mask) << shift;
  102. if (tmp != orig)
  103. mmio_write_32(addr, tmp);
  104. dsb();
  105. }
  106. static void plls_suspend(uint32_t pll_id)
  107. {
  108. plls_con[pll_id][0] = mmio_read_32(CRU_BASE + PLL_CONS((pll_id), 0));
  109. plls_con[pll_id][1] = mmio_read_32(CRU_BASE + PLL_CONS((pll_id), 1));
  110. plls_con[pll_id][2] = mmio_read_32(CRU_BASE + PLL_CONS((pll_id), 2));
  111. plls_con[pll_id][3] = mmio_read_32(CRU_BASE + PLL_CONS((pll_id), 3));
  112. mmio_write_32(CRU_BASE + PLL_CONS((pll_id), 3), PLL_SLOW_BITS);
  113. mmio_write_32(CRU_BASE + PLL_CONS((pll_id), 3), PLL_BYPASS);
  114. }
  115. static void pm_plls_suspend(void)
  116. {
  117. plls_suspend(NPLL_ID);
  118. plls_suspend(CPLL_ID);
  119. plls_suspend(GPLL_ID);
  120. plls_suspend(ABPLL_ID);
  121. plls_suspend(ALPLL_ID);
  122. }
  123. static inline void plls_resume(void)
  124. {
  125. mmio_write_32(CRU_BASE + PLL_CONS(ABPLL_ID, 3),
  126. plls_con[ABPLL_ID][3] | PLL_BYPASS_W_MSK);
  127. mmio_write_32(CRU_BASE + PLL_CONS(ALPLL_ID, 3),
  128. plls_con[ALPLL_ID][3] | PLL_BYPASS_W_MSK);
  129. mmio_write_32(CRU_BASE + PLL_CONS(GPLL_ID, 3),
  130. plls_con[GPLL_ID][3] | PLL_BYPASS_W_MSK);
  131. mmio_write_32(CRU_BASE + PLL_CONS(CPLL_ID, 3),
  132. plls_con[CPLL_ID][3] | PLL_BYPASS_W_MSK);
  133. mmio_write_32(CRU_BASE + PLL_CONS(NPLL_ID, 3),
  134. plls_con[NPLL_ID][3] | PLL_BYPASS_W_MSK);
  135. }
  136. void soc_sleep_config(void)
  137. {
  138. int i = 0;
  139. for (i = 0; i < CRU_CLKGATES_CON_CNT; i++)
  140. mmio_write_32(CRU_BASE + CRU_CLKGATES_CON(i), 0xffff0000);
  141. pm_plls_suspend();
  142. for (i = 0; i < CRU_CLKGATES_CON_CNT; i++)
  143. mmio_write_32(CRU_BASE + CRU_CLKGATES_CON(i), 0xffff0000);
  144. }
  145. void pm_plls_resume(void)
  146. {
  147. plls_resume();
  148. mmio_write_32(CRU_BASE + PLL_CONS(ABPLL_ID, 3),
  149. plls_con[ABPLL_ID][3] | PLLS_MODE_WMASK);
  150. mmio_write_32(CRU_BASE + PLL_CONS(ALPLL_ID, 3),
  151. plls_con[ALPLL_ID][3] | PLLS_MODE_WMASK);
  152. mmio_write_32(CRU_BASE + PLL_CONS(GPLL_ID, 3),
  153. plls_con[GPLL_ID][3] | PLLS_MODE_WMASK);
  154. mmio_write_32(CRU_BASE + PLL_CONS(CPLL_ID, 3),
  155. plls_con[CPLL_ID][3] | PLLS_MODE_WMASK);
  156. mmio_write_32(CRU_BASE + PLL_CONS(NPLL_ID, 3),
  157. plls_con[NPLL_ID][3] | PLLS_MODE_WMASK);
  158. }
  159. void __dead2 rockchip_soc_soft_reset(void)
  160. {
  161. uint32_t temp_val;
  162. mmio_write_32(CRU_BASE + PLL_CONS((GPLL_ID), 3), PLL_SLOW_BITS);
  163. mmio_write_32(CRU_BASE + PLL_CONS((CPLL_ID), 3), PLL_SLOW_BITS);
  164. mmio_write_32(CRU_BASE + PLL_CONS((NPLL_ID), 3), PLL_SLOW_BITS);
  165. mmio_write_32(CRU_BASE + PLL_CONS((ABPLL_ID), 3), PLL_SLOW_BITS);
  166. mmio_write_32(CRU_BASE + PLL_CONS((ALPLL_ID), 3), PLL_SLOW_BITS);
  167. temp_val = mmio_read_32(CRU_BASE + CRU_GLB_RST_CON) |
  168. PMU_RST_BY_SECOND_SFT;
  169. mmio_write_32(CRU_BASE + CRU_GLB_RST_CON, temp_val);
  170. mmio_write_32(CRU_BASE + CRU_GLB_SRST_SND, 0xeca8);
  171. /*
  172. * Maybe the HW needs some times to reset the system,
  173. * so we do not hope the core to execute valid codes.
  174. */
  175. while (1)
  176. ;
  177. }