soc.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 <rk3288_def.h>
  12. #include <soc.h>
  13. #include <secure.h>
  14. /* sleep data for pll suspend */
  15. static struct deepsleep_data_s slp_data;
  16. /* Table of regions to map using the MMU. */
  17. const mmap_region_t plat_rk_mmap[] = {
  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(TZPC_BASE, TZPC_SIZE,
  25. MT_DEVICE | MT_RW | MT_SECURE),
  26. MAP_REGION_FLAT(PMUSRAM_BASE, PMUSRAM_SIZE,
  27. MT_MEMORY | MT_RW | MT_SECURE),
  28. MAP_REGION_FLAT(SRAM_BASE, SRAM_SIZE,
  29. MT_DEVICE | MT_RW | MT_SECURE),
  30. MAP_REGION_FLAT(PMU_BASE, PMU_SIZE,
  31. MT_DEVICE | MT_RW | MT_SECURE),
  32. MAP_REGION_FLAT(UART0_BASE, UART0_SIZE,
  33. MT_DEVICE | MT_RW | MT_SECURE),
  34. MAP_REGION_FLAT(UART1_BASE, UART1_SIZE,
  35. MT_DEVICE | MT_RW | MT_SECURE),
  36. MAP_REGION_FLAT(UART2_BASE, UART2_SIZE,
  37. MT_DEVICE | MT_RW | MT_SECURE),
  38. MAP_REGION_FLAT(UART3_BASE, UART3_SIZE,
  39. MT_DEVICE | MT_RW | MT_SECURE),
  40. MAP_REGION_FLAT(UART4_BASE, UART4_SIZE,
  41. MT_DEVICE | MT_RW | MT_SECURE),
  42. MAP_REGION_FLAT(CRU_BASE, CRU_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(DDR_PCTL0_BASE, DDR_PCTL0_SIZE,
  47. MT_DEVICE | MT_RW | MT_SECURE),
  48. MAP_REGION_FLAT(DDR_PHY0_BASE, DDR_PHY0_SIZE,
  49. MT_DEVICE | MT_RW | MT_SECURE),
  50. MAP_REGION_FLAT(DDR_PCTL1_BASE, DDR_PCTL1_SIZE,
  51. MT_DEVICE | MT_RW | MT_SECURE),
  52. MAP_REGION_FLAT(DDR_PHY1_BASE, DDR_PHY1_SIZE,
  53. MT_DEVICE | MT_RW | MT_SECURE),
  54. MAP_REGION_FLAT(SERVICE_BUS_BASE, SERVICE_BUS_SIZE,
  55. MT_DEVICE | MT_RW | MT_SECURE),
  56. MAP_REGION_FLAT(CORE_AXI_BUS_BASE, CORE_AXI_BUS_SIZE,
  57. MT_DEVICE | MT_RW | MT_SECURE),
  58. { 0 }
  59. };
  60. /* The RockChip power domain tree descriptor */
  61. const unsigned char rockchip_power_domain_tree_desc[] = {
  62. /* No of root nodes */
  63. PLATFORM_SYSTEM_COUNT,
  64. /* No of children for the root node */
  65. PLATFORM_CLUSTER_COUNT,
  66. /* No of children for the first cluster node */
  67. PLATFORM_CLUSTER0_CORE_COUNT,
  68. };
  69. void plat_rockchip_soc_init(void)
  70. {
  71. secure_timer_init();
  72. secure_sgrf_init();
  73. /*
  74. * We cannot enable ddr security at this point, as the kernel
  75. * seems to have an issue with it even living in the same 128MB
  76. * memory block. Only when moving the kernel to the second
  77. * 128MB block does it not conflict, but then we'd loose this
  78. * memory area for use. Late maybe enable
  79. * secure_sgrf_ddr_rgn_init();
  80. */
  81. }
  82. void regs_update_bits(uintptr_t addr, uint32_t val,
  83. uint32_t mask, uint32_t shift)
  84. {
  85. uint32_t tmp, orig;
  86. orig = mmio_read_32(addr);
  87. tmp = orig & ~(mask << shift);
  88. tmp |= (val & mask) << shift;
  89. if (tmp != orig)
  90. mmio_write_32(addr, tmp);
  91. dsb();
  92. }
  93. static void pll_save(uint32_t pll_id)
  94. {
  95. uint32_t *pll = slp_data.pll_con[pll_id];
  96. pll[0] = mmio_read_32(CRU_BASE + PLL_CONS((pll_id), 0));
  97. pll[1] = mmio_read_32(CRU_BASE + PLL_CONS((pll_id), 1));
  98. pll[2] = mmio_read_32(CRU_BASE + PLL_CONS((pll_id), 2));
  99. pll[3] = mmio_read_32(CRU_BASE + PLL_CONS((pll_id), 3));
  100. }
  101. void clk_plls_suspend(void)
  102. {
  103. pll_save(NPLL_ID);
  104. pll_save(CPLL_ID);
  105. pll_save(GPLL_ID);
  106. pll_save(APLL_ID);
  107. slp_data.pll_mode = mmio_read_32(CRU_BASE + PLL_MODE_CON);
  108. /*
  109. * Switch PLLs other than DPLL (for SDRAM) to slow mode to
  110. * avoid crashes on resume. The Mask ROM on the system will
  111. * put APLL, CPLL, and GPLL into slow mode at resume time
  112. * anyway (which is why we restore them), but we might not
  113. * even make it to the Mask ROM if this isn't done at suspend
  114. * time.
  115. *
  116. * NOTE: only APLL truly matters here, but we'll do them all.
  117. */
  118. mmio_write_32(CRU_BASE + PLL_MODE_CON, 0xf3030000);
  119. }
  120. void clk_plls_resume(void)
  121. {
  122. /* restore pll-modes */
  123. mmio_write_32(CRU_BASE + PLL_MODE_CON,
  124. slp_data.pll_mode | REG_SOC_WMSK);
  125. }
  126. void clk_gate_con_save(void)
  127. {
  128. uint32_t i = 0;
  129. for (i = 0; i < CRU_CLKGATES_CON_CNT; i++)
  130. slp_data.cru_gate_con[i] =
  131. mmio_read_32(CRU_BASE + CRU_CLKGATES_CON(i));
  132. }
  133. void clk_gate_con_disable(void)
  134. {
  135. uint32_t i;
  136. for (i = 0; i < CRU_CLKGATES_CON_CNT; i++)
  137. mmio_write_32(CRU_BASE + CRU_CLKGATES_CON(i), REG_SOC_WMSK);
  138. }
  139. void clk_gate_con_restore(void)
  140. {
  141. uint32_t i;
  142. for (i = 0; i < CRU_CLKGATES_CON_CNT; i++)
  143. mmio_write_32(CRU_BASE + CRU_CLKGATES_CON(i),
  144. REG_SOC_WMSK | slp_data.cru_gate_con[i]);
  145. }
  146. void clk_sel_con_save(void)
  147. {
  148. uint32_t i = 0;
  149. for (i = 0; i < CRU_CLKSELS_CON_CNT; i++)
  150. slp_data.cru_sel_con[i] =
  151. mmio_read_32(CRU_BASE + CRU_CLKSELS_CON(i));
  152. }
  153. void clk_sel_con_restore(void)
  154. {
  155. uint32_t i, val;
  156. for (i = 0; i < CRU_CLKSELS_CON_CNT; i++) {
  157. /* fractional dividers don't have write-masks */
  158. if ((i >= 7 && i <= 9) ||
  159. (i >= 17 && i <= 20) ||
  160. (i == 23) || (i == 41))
  161. val = slp_data.cru_sel_con[i];
  162. else
  163. val = slp_data.cru_sel_con[i] | REG_SOC_WMSK;
  164. mmio_write_32(CRU_BASE + CRU_CLKSELS_CON(i), val);
  165. }
  166. }
  167. void __dead2 rockchip_soc_soft_reset(void)
  168. {
  169. uint32_t temp_val;
  170. /*
  171. * Switch PLLs other than DPLL (for SDRAM) to slow mode to
  172. * avoid crashes on resume. The Mask ROM on the system will
  173. * put APLL, CPLL, and GPLL into slow mode at resume time
  174. * anyway (which is why we restore them), but we might not
  175. * even make it to the Mask ROM if this isn't done at suspend
  176. * time.
  177. *
  178. * NOTE: only APLL truly matters here, but we'll do them all.
  179. */
  180. mmio_write_32(CRU_BASE + PLL_MODE_CON, 0xf3030000);
  181. temp_val = mmio_read_32(CRU_BASE + CRU_GLB_RST_CON);
  182. temp_val &= ~PMU_RST_MASK;
  183. temp_val |= PMU_RST_BY_SECOND_SFT;
  184. mmio_write_32(CRU_BASE + CRU_GLB_RST_CON, temp_val);
  185. mmio_write_32(CRU_BASE + CRU_GLB_SRST_SND, 0xeca8);
  186. /*
  187. * Maybe the HW needs some times to reset the system,
  188. * so we do not hope the core to execute valid codes.
  189. */
  190. while (1)
  191. ;
  192. }