pm_pd_regs.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. /*
  2. * Copyright (c) 2024, Rockchip, Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <arch_helpers.h>
  9. #include <bl31/bl31.h>
  10. #include <common/debug.h>
  11. #include <drivers/console.h>
  12. #include <drivers/delay_timer.h>
  13. #include <lib/mmio.h>
  14. #include <platform.h>
  15. #include <platform_def.h>
  16. #include <pmu.h>
  17. #include <plat_pm_helpers.h>
  18. #include <plat_private.h>
  19. #include <pm_pd_regs.h>
  20. #include <soc.h>
  21. #define WMSK_VAL 0xffff0000
  22. static struct reg_region qos_reg_rgns[] = {
  23. [QOS_ISP0_MWO] = REG_REGION(0x08, 0x18, 4, 0xfdf40500, 0),
  24. [QOS_ISP0_MRO] = REG_REGION(0x08, 0x18, 4, 0xfdf40400, 0),
  25. [QOS_ISP1_MWO] = REG_REGION(0x08, 0x18, 4, 0xfdf41000, 0),
  26. [QOS_ISP1_MRO] = REG_REGION(0x08, 0x18, 4, 0xfdf41100, 0),
  27. [QOS_VICAP_M0] = REG_REGION(0x08, 0x18, 4, 0xfdf40600, 0),
  28. [QOS_VICAP_M1] = REG_REGION(0x08, 0x18, 4, 0xfdf40800, 0),
  29. [QOS_FISHEYE0] = REG_REGION(0x08, 0x18, 4, 0xfdf40000, 0),
  30. [QOS_FISHEYE1] = REG_REGION(0x08, 0x18, 4, 0xfdf40200, 0),
  31. [QOS_VOP_M0] = REG_REGION(0x08, 0x18, 4, 0xfdf82000, 0),
  32. [QOS_VOP_M1] = REG_REGION(0x08, 0x18, 4, 0xfdf82200, 0),
  33. [QOS_RKVDEC0] = REG_REGION(0x08, 0x18, 4, 0xfdf62000, 0),
  34. [QOS_RKVDEC1] = REG_REGION(0x08, 0x18, 4, 0xfdf63000, 0),
  35. [QOS_AV1] = REG_REGION(0x08, 0x18, 4, 0xfdf64000, 0),
  36. [QOS_RKVENC0_M0RO] = REG_REGION(0x08, 0x18, 4, 0xfdf60000, 0),
  37. [QOS_RKVENC0_M1RO] = REG_REGION(0x08, 0x18, 4, 0xfdf60200, 0),
  38. [QOS_RKVENC0_M2WO] = REG_REGION(0x08, 0x18, 4, 0xfdf60400, 0),
  39. [QOS_RKVENC1_M0RO] = REG_REGION(0x08, 0x18, 4, 0xfdf61000, 0),
  40. [QOS_RKVENC1_M1RO] = REG_REGION(0x08, 0x18, 4, 0xfdf61200, 0),
  41. [QOS_RKVENC1_M2WO] = REG_REGION(0x08, 0x18, 4, 0xfdf61400, 0),
  42. [QOS_DSU_M0] = REG_REGION(0x08, 0x18, 4, 0xfe008000, 0),
  43. [QOS_DSU_M1] = REG_REGION(0x08, 0x18, 4, 0xfe008800, 0),
  44. [QOS_DSU_MP] = REG_REGION(0x08, 0x18, 4, 0xfdf34200, 0),
  45. [QOS_DEBUG] = REG_REGION(0x08, 0x18, 4, 0xfdf34400, 0),
  46. [QOS_GPU_M0] = REG_REGION(0x08, 0x18, 4, 0xfdf35000, 0),
  47. [QOS_GPU_M1] = REG_REGION(0x08, 0x18, 4, 0xfdf35200, 0),
  48. [QOS_GPU_M2] = REG_REGION(0x08, 0x18, 4, 0xfdf35400, 0),
  49. [QOS_GPU_M3] = REG_REGION(0x08, 0x18, 4, 0xfdf35600, 0),
  50. [QOS_NPU1] = REG_REGION(0x08, 0x18, 4, 0xfdf70000, 0),
  51. [QOS_NPU0_MRO] = REG_REGION(0x08, 0x18, 4, 0xfdf72200, 0),
  52. [QOS_NPU2] = REG_REGION(0x08, 0x18, 4, 0xfdf71000, 0),
  53. [QOS_NPU0_MWR] = REG_REGION(0x08, 0x18, 4, 0xfdf72000, 0),
  54. [QOS_MCU_NPU] = REG_REGION(0x08, 0x18, 4, 0xfdf72400, 0),
  55. [QOS_JPEG_DEC] = REG_REGION(0x08, 0x18, 4, 0xfdf66200, 0),
  56. [QOS_JPEG_ENC0] = REG_REGION(0x08, 0x18, 4, 0xfdf66400, 0),
  57. [QOS_JPEG_ENC1] = REG_REGION(0x08, 0x18, 4, 0xfdf66600, 0),
  58. [QOS_JPEG_ENC2] = REG_REGION(0x08, 0x18, 4, 0xfdf66800, 0),
  59. [QOS_JPEG_ENC3] = REG_REGION(0x08, 0x18, 4, 0xfdf66a00, 0),
  60. [QOS_RGA2_MRO] = REG_REGION(0x08, 0x18, 4, 0xfdf66c00, 0),
  61. [QOS_RGA2_MWO] = REG_REGION(0x08, 0x18, 4, 0xfdf66e00, 0),
  62. [QOS_RGA3_0] = REG_REGION(0x08, 0x18, 4, 0xfdf67000, 0),
  63. [QOS_RGA3_1] = REG_REGION(0x08, 0x18, 4, 0xfdf36000, 0),
  64. [QOS_VDPU] = REG_REGION(0x08, 0x18, 4, 0xfdf67200, 0),
  65. [QOS_IEP] = REG_REGION(0x08, 0x18, 4, 0xfdf66000, 0),
  66. [QOS_HDCP0] = REG_REGION(0x08, 0x18, 4, 0xfdf80000, 0),
  67. [QOS_HDCP1] = REG_REGION(0x08, 0x18, 4, 0xfdf81000, 0),
  68. [QOS_HDMIRX] = REG_REGION(0x08, 0x18, 4, 0xfdf81200, 0),
  69. [QOS_GIC600_M0] = REG_REGION(0x08, 0x18, 4, 0xfdf3a000, 0),
  70. [QOS_GIC600_M1] = REG_REGION(0x08, 0x18, 4, 0xfdf3a200, 0),
  71. [QOS_MMU600PCIE_TCU] = REG_REGION(0x08, 0x18, 4, 0xfdf3a400, 0),
  72. [QOS_MMU600PHP_TBU] = REG_REGION(0x08, 0x18, 4, 0xfdf3a600, 0),
  73. [QOS_MMU600PHP_TCU] = REG_REGION(0x08, 0x18, 4, 0xfdf3a800, 0),
  74. [QOS_USB3_0] = REG_REGION(0x08, 0x18, 4, 0xfdf3e200, 0),
  75. [QOS_USB3_1] = REG_REGION(0x08, 0x18, 4, 0xfdf3e000, 0),
  76. [QOS_USBHOST_0] = REG_REGION(0x08, 0x18, 4, 0xfdf3e400, 0),
  77. [QOS_USBHOST_1] = REG_REGION(0x08, 0x18, 4, 0xfdf3e600, 0),
  78. [QOS_EMMC] = REG_REGION(0x08, 0x18, 4, 0xfdf38200, 0),
  79. [QOS_FSPI] = REG_REGION(0x08, 0x18, 4, 0xfdf38000, 0),
  80. [QOS_SDIO] = REG_REGION(0x08, 0x18, 4, 0xfdf39000, 0),
  81. [QOS_DECOM] = REG_REGION(0x08, 0x18, 4, 0xfdf32000, 0),
  82. [QOS_DMAC0] = REG_REGION(0x08, 0x18, 4, 0xfdf32200, 0),
  83. [QOS_DMAC1] = REG_REGION(0x08, 0x18, 4, 0xfdf32400, 0),
  84. [QOS_DMAC2] = REG_REGION(0x08, 0x18, 4, 0xfdf32600, 0),
  85. [QOS_GIC600M] = REG_REGION(0x08, 0x18, 4, 0xfdf32800, 0),
  86. [QOS_DMA2DDR] = REG_REGION(0x08, 0x18, 4, 0xfdf52000, 0),
  87. [QOS_MCU_DDR] = REG_REGION(0x08, 0x18, 4, 0xfdf52200, 0),
  88. [QOS_VAD] = REG_REGION(0x08, 0x18, 4, 0xfdf3b200, 0),
  89. [QOS_MCU_PMU] = REG_REGION(0x08, 0x18, 4, 0xfdf3b000, 0),
  90. [QOS_CRYPTOS] = REG_REGION(0x08, 0x18, 4, 0xfdf3d200, 0),
  91. [QOS_CRYPTONS] = REG_REGION(0x08, 0x18, 4, 0xfdf3d000, 0),
  92. [QOS_DCF] = REG_REGION(0x08, 0x18, 4, 0xfdf3d400, 0),
  93. [QOS_SDMMC] = REG_REGION(0x08, 0x18, 4, 0xfdf3d800, 0),
  94. };
  95. static struct reg_region pd_crypto_reg_rgns[] = {
  96. /* SECURE CRU */
  97. REG_REGION(0x300, 0x30c, 4, SCRU_BASE, WMSK_VAL),
  98. REG_REGION(0x800, 0x80c, 4, SCRU_BASE, WMSK_VAL),
  99. REG_REGION(0xa00, 0xa0c, 4, SCRU_BASE, WMSK_VAL),
  100. REG_REGION(0xd00, 0xd20, 8, SCRU_BASE, 0),
  101. REG_REGION(0xd04, 0xd24, 8, SCRU_BASE, WMSK_VAL),
  102. /* S TIMER0 6 channel */
  103. REG_REGION(0x00, 0x04, 4, STIMER0_BASE + 0x00, 0),
  104. REG_REGION(0x10, 0x10, 4, STIMER0_BASE + 0x00, 0),
  105. REG_REGION(0x00, 0x04, 4, STIMER0_BASE + 0x20, 0),
  106. REG_REGION(0x10, 0x10, 4, STIMER0_BASE + 0x20, 0),
  107. REG_REGION(0x00, 0x04, 4, STIMER0_BASE + 0x40, 0),
  108. REG_REGION(0x10, 0x10, 4, STIMER0_BASE + 0x40, 0),
  109. REG_REGION(0x00, 0x04, 4, STIMER0_BASE + 0x60, 0),
  110. REG_REGION(0x10, 0x10, 4, STIMER0_BASE + 0x60, 0),
  111. REG_REGION(0x00, 0x04, 4, STIMER0_BASE + 0x80, 0),
  112. REG_REGION(0x10, 0x10, 4, STIMER0_BASE + 0x80, 0),
  113. REG_REGION(0x00, 0x04, 4, STIMER0_BASE + 0xa0, 0),
  114. REG_REGION(0x10, 0x10, 4, STIMER0_BASE + 0xa0, 0),
  115. /* S TIMER1 6 channel */
  116. REG_REGION(0x00, 0x04, 4, STIMER1_BASE + 0x00, 0),
  117. REG_REGION(0x10, 0x10, 4, STIMER1_BASE + 0x00, 0),
  118. REG_REGION(0x00, 0x04, 4, STIMER1_BASE + 0x20, 0),
  119. REG_REGION(0x10, 0x10, 4, STIMER1_BASE + 0x20, 0),
  120. REG_REGION(0x00, 0x04, 4, STIMER1_BASE + 0x40, 0),
  121. REG_REGION(0x10, 0x10, 4, STIMER1_BASE + 0x40, 0),
  122. REG_REGION(0x00, 0x04, 4, STIMER1_BASE + 0x60, 0),
  123. REG_REGION(0x10, 0x10, 4, STIMER1_BASE + 0x60, 0),
  124. REG_REGION(0x00, 0x04, 4, STIMER1_BASE + 0x80, 0),
  125. REG_REGION(0x10, 0x10, 4, STIMER1_BASE + 0x80, 0),
  126. REG_REGION(0x00, 0x04, 4, STIMER1_BASE + 0xa0, 0),
  127. REG_REGION(0x10, 0x10, 4, STIMER1_BASE + 0xa0, 0),
  128. /* wdt_s */
  129. REG_REGION(0x04, 0x04, 4, WDT_S_BASE, 0),
  130. REG_REGION(0x00, 0x00, 4, WDT_S_BASE, 0),
  131. };
  132. static struct reg_region pd_dsu_reg_rgns[] = {
  133. /* dsucru */
  134. REG_REGION(0x040, 0x054, 4, DSUCRU_BASE, WMSK_VAL),
  135. REG_REGION(0x300, 0x31c, 4, DSUCRU_BASE, WMSK_VAL),
  136. REG_REGION(0x800, 0x80c, 4, DSUCRU_BASE, WMSK_VAL),
  137. REG_REGION(0xa00, 0xa0c, 4, DSUCRU_BASE, WMSK_VAL),
  138. REG_REGION(0xd00, 0xd20, 8, DSUCRU_BASE, 0),
  139. REG_REGION(0xd04, 0xd24, 8, DSUCRU_BASE, WMSK_VAL),
  140. REG_REGION(0xf00, 0xf00, 4, DSUCRU_BASE, WMSK_VAL),
  141. REG_REGION(0xf10, 0xf1c, 4, DSUCRU_BASE, 0),
  142. /* bcore0cru */
  143. REG_REGION(0x000, 0x014, 4, BIGCORE0CRU_BASE, WMSK_VAL),
  144. REG_REGION(0x300, 0x304, 4, BIGCORE0CRU_BASE, WMSK_VAL),
  145. REG_REGION(0x800, 0x804, 4, BIGCORE0CRU_BASE, WMSK_VAL),
  146. REG_REGION(0xa00, 0xa04, 4, BIGCORE0CRU_BASE, WMSK_VAL),
  147. REG_REGION(0xcc0, 0xcc4, 4, BIGCORE0CRU_BASE, 0),
  148. REG_REGION(0xd00, 0xd00, 4, BIGCORE0CRU_BASE, 0),
  149. REG_REGION(0xd04, 0xd04, 4, BIGCORE0CRU_BASE, WMSK_VAL),
  150. /* bcore1cru */
  151. REG_REGION(0x020, 0x034, 4, BIGCORE1CRU_BASE, WMSK_VAL),
  152. REG_REGION(0x300, 0x304, 4, BIGCORE1CRU_BASE, WMSK_VAL),
  153. REG_REGION(0x800, 0x804, 4, BIGCORE1CRU_BASE, WMSK_VAL),
  154. REG_REGION(0xa00, 0xa04, 4, BIGCORE1CRU_BASE, WMSK_VAL),
  155. REG_REGION(0xcc0, 0xcc4, 4, BIGCORE1CRU_BASE, 0),
  156. REG_REGION(0xd00, 0xd00, 4, BIGCORE1CRU_BASE, 0),
  157. REG_REGION(0xd04, 0xd04, 4, BIGCORE1CRU_BASE, WMSK_VAL),
  158. /* dsugrf */
  159. REG_REGION(0x00, 0x18, 4, DSUGRF_BASE, WMSK_VAL),
  160. REG_REGION(0x20, 0x20, 4, DSUGRF_BASE, WMSK_VAL),
  161. REG_REGION(0x28, 0x30, 4, DSUGRF_BASE, WMSK_VAL),
  162. REG_REGION(0x38, 0x38, 4, DSUGRF_BASE, WMSK_VAL),
  163. /* lcore_grf */
  164. REG_REGION(0x20, 0x20, 4, LITCOREGRF_BASE, WMSK_VAL),
  165. REG_REGION(0x28, 0x30, 4, LITCOREGRF_BASE, WMSK_VAL),
  166. /* bcore0_grf */
  167. REG_REGION(0x20, 0x20, 4, BIGCORE0GRF_BASE, WMSK_VAL),
  168. REG_REGION(0x28, 0x30, 4, BIGCORE0GRF_BASE, WMSK_VAL),
  169. /* bcore1_grf */
  170. REG_REGION(0x20, 0x20, 4, BIGCORE1GRF_BASE, WMSK_VAL),
  171. REG_REGION(0x28, 0x28, 4, BIGCORE1GRF_BASE, WMSK_VAL),
  172. };
  173. static struct reg_region pd_php_reg_rgns[] = {
  174. /* php_grf */
  175. REG_REGION(0x000, 0x008, 4, PHPGRF_BASE, WMSK_VAL),
  176. REG_REGION(0x014, 0x024, 4, PHPGRF_BASE, WMSK_VAL),
  177. REG_REGION(0x028, 0x02c, 4, PHPGRF_BASE, 0),
  178. REG_REGION(0x030, 0x03c, 4, PHPGRF_BASE, WMSK_VAL),
  179. REG_REGION(0x05c, 0x060, 4, PHPGRF_BASE, WMSK_VAL),
  180. REG_REGION(0x064, 0x068, 4, PHPGRF_BASE, 0),
  181. REG_REGION(0x070, 0x070, 4, PHPGRF_BASE, WMSK_VAL),
  182. REG_REGION(0x074, 0x0d0, 4, PHPGRF_BASE, 0),
  183. REG_REGION(0x0d4, 0x0d4, 4, PHPGRF_BASE, WMSK_VAL),
  184. REG_REGION(0x0e0, 0x0e0, 4, PHPGRF_BASE, 0),
  185. REG_REGION(0x0e4, 0x0ec, 4, PHPGRF_BASE, WMSK_VAL),
  186. REG_REGION(0x100, 0x104, 4, PHPGRF_BASE, WMSK_VAL),
  187. REG_REGION(0x10c, 0x130, 4, PHPGRF_BASE, 0),
  188. REG_REGION(0x138, 0x138, 4, PHPGRF_BASE, WMSK_VAL),
  189. REG_REGION(0x144, 0x168, 4, PHPGRF_BASE, 0),
  190. REG_REGION(0x16c, 0x174, 4, PHPGRF_BASE, WMSK_VAL),
  191. /* php_cru */
  192. REG_REGION(0x200, 0x218, 4, PHP_CRU_BASE, WMSK_VAL),
  193. REG_REGION(0x800, 0x800, 4, PHP_CRU_BASE, WMSK_VAL),
  194. REG_REGION(0xa00, 0xa00, 4, PHP_CRU_BASE, WMSK_VAL),
  195. /* pcie3phy_grf_cmn_con0 */
  196. REG_REGION(0x00, 0x00, 4, PCIE3PHYGRF_BASE, WMSK_VAL),
  197. };
  198. void qos_save(void)
  199. {
  200. uint32_t pmu_pd_st0 = mmio_read_32(PMU_BASE + PMU2_PWR_GATE_ST(0));
  201. if ((pmu_pd_st0 & BIT(PD_GPU)) == 0) {
  202. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_GPU_M0], 1);
  203. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_GPU_M1], 1);
  204. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_GPU_M2], 1);
  205. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_GPU_M3], 1);
  206. }
  207. if ((pmu_pd_st0 & BIT(PD_NPU1)) == 0)
  208. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_NPU1], 1);
  209. if ((pmu_pd_st0 & BIT(PD_NPU2)) == 0)
  210. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_NPU2], 1);
  211. if ((pmu_pd_st0 & BIT(PD_NPUTOP)) == 0) {
  212. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_NPU0_MRO], 1);
  213. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_NPU0_MWR], 1);
  214. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_MCU_NPU], 1);
  215. }
  216. if ((pmu_pd_st0 & BIT(PD_RKVDEC1)) == 0)
  217. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_RKVDEC1], 1);
  218. if ((pmu_pd_st0 & BIT(PD_RKVDEC0)) == 0)
  219. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_RKVDEC0], 1);
  220. if ((pmu_pd_st0 & BIT(PD_VENC1)) == 0) {
  221. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_RKVENC1_M0RO], 1);
  222. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_RKVENC1_M1RO], 1);
  223. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_RKVENC1_M2WO], 1);
  224. }
  225. if ((pmu_pd_st0 & BIT(PD_VENC0)) == 0) {
  226. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_RKVENC0_M0RO], 1);
  227. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_RKVENC0_M1RO], 1);
  228. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_RKVENC0_M2WO], 1);
  229. }
  230. if ((pmu_pd_st0 & BIT(PD_RGA30)) == 0)
  231. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_RGA3_0], 1);
  232. if ((pmu_pd_st0 & BIT(PD_AV1)) == 0)
  233. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_AV1], 1);
  234. if ((pmu_pd_st0 & BIT(PD_VDPU)) == 0) {
  235. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_JPEG_DEC], 1);
  236. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_JPEG_ENC0], 1);
  237. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_JPEG_ENC1], 1);
  238. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_JPEG_ENC2], 1);
  239. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_JPEG_ENC3], 1);
  240. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_RGA2_MRO], 1);
  241. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_RGA2_MWO], 1);
  242. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_VDPU], 1);
  243. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_IEP], 1);
  244. }
  245. if ((pmu_pd_st0 & BIT(PD_VO0)) == 0)
  246. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_HDCP0], 1);
  247. if ((pmu_pd_st0 & BIT(PD_VO1)) == 0) {
  248. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_HDCP1], 1);
  249. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_HDMIRX], 1);
  250. }
  251. if ((pmu_pd_st0 & BIT(PD_VOP)) == 0) {
  252. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_VOP_M0], 1);
  253. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_VOP_M1], 1);
  254. }
  255. if ((pmu_pd_st0 & BIT(PD_FEC)) == 0) {
  256. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_FISHEYE0], 1);
  257. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_FISHEYE1], 1);
  258. }
  259. if ((pmu_pd_st0 & BIT(PD_ISP1)) == 0) {
  260. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_ISP1_MWO], 1);
  261. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_ISP1_MRO], 1);
  262. }
  263. if ((pmu_pd_st0 & BIT(PD_VI)) == 0) {
  264. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_ISP0_MWO], 1);
  265. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_ISP0_MRO], 1);
  266. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_VICAP_M0], 1);
  267. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_VICAP_M1], 1);
  268. }
  269. if ((pmu_pd_st0 & BIT(PD_RGA31)) == 0)
  270. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_RGA3_1], 1);
  271. if ((pmu_pd_st0 & BIT(PD_USB)) == 0) {
  272. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_USB3_0], 1);
  273. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_USB3_1], 1);
  274. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_USBHOST_0], 1);
  275. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_USBHOST_1], 1);
  276. }
  277. if ((pmu_pd_st0 & BIT(PD_PHP)) == 0) {
  278. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_GIC600_M0], 1);
  279. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_GIC600_M1], 1);
  280. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_MMU600PCIE_TCU], 1);
  281. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_MMU600PHP_TBU], 1);
  282. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_MMU600PHP_TCU], 1);
  283. }
  284. if ((pmu_pd_st0 & BIT(PD_SDIO)) == 0)
  285. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_SDIO], 1);
  286. if ((pmu_pd_st0 & BIT(PD_NVM0)) == 0) {
  287. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_FSPI], 1);
  288. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_EMMC], 1);
  289. }
  290. if ((pmu_pd_st0 & BIT(PD_SDMMC)) == 0)
  291. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_SDMMC], 1);
  292. if ((pmu_pd_st0 & BIT(PD_CRYPTO)) == 0) {
  293. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_CRYPTONS], 1);
  294. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_CRYPTOS], 1);
  295. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_DCF], 1);
  296. }
  297. /* PD_DSU */
  298. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_DSU_M0], 1);
  299. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_DSU_M1], 1);
  300. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_DSU_MP], 1);
  301. rockchip_reg_rgn_save(&qos_reg_rgns[QOS_DEBUG], 1);
  302. }
  303. void qos_restore(void)
  304. {
  305. uint32_t pmu_pd_st0 = mmio_read_32(PMU_BASE + PMU2_PWR_GATE_ST(0));
  306. if ((pmu_pd_st0 & BIT(PD_GPU)) == 0) {
  307. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_GPU_M0], 1);
  308. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_GPU_M1], 1);
  309. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_GPU_M2], 1);
  310. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_GPU_M3], 1);
  311. }
  312. if ((pmu_pd_st0 & BIT(PD_NPU1)) == 0)
  313. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_NPU1], 1);
  314. if ((pmu_pd_st0 & BIT(PD_NPU2)) == 0)
  315. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_NPU2], 1);
  316. if ((pmu_pd_st0 & BIT(PD_NPUTOP)) == 0) {
  317. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_NPU0_MRO], 1);
  318. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_NPU0_MWR], 1);
  319. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_MCU_NPU], 1);
  320. }
  321. if ((pmu_pd_st0 & BIT(PD_RKVDEC1)) == 0)
  322. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_RKVDEC1], 1);
  323. if ((pmu_pd_st0 & BIT(PD_RKVDEC0)) == 0)
  324. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_RKVDEC0], 1);
  325. if ((pmu_pd_st0 & BIT(PD_VENC1)) == 0) {
  326. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_RKVENC1_M0RO], 1);
  327. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_RKVENC1_M1RO], 1);
  328. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_RKVENC1_M2WO], 1);
  329. }
  330. if ((pmu_pd_st0 & BIT(PD_VENC0)) == 0) {
  331. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_RKVENC0_M0RO], 1);
  332. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_RKVENC0_M1RO], 1);
  333. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_RKVENC0_M2WO], 1);
  334. }
  335. if ((pmu_pd_st0 & BIT(PD_RGA30)) == 0)
  336. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_RGA3_0], 1);
  337. if ((pmu_pd_st0 & BIT(PD_AV1)) == 0)
  338. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_AV1], 1);
  339. if ((pmu_pd_st0 & BIT(PD_VDPU)) == 0) {
  340. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_JPEG_DEC], 1);
  341. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_JPEG_ENC0], 1);
  342. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_JPEG_ENC1], 1);
  343. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_JPEG_ENC2], 1);
  344. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_JPEG_ENC3], 1);
  345. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_RGA2_MRO], 1);
  346. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_RGA2_MWO], 1);
  347. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_VDPU], 1);
  348. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_IEP], 1);
  349. }
  350. if ((pmu_pd_st0 & BIT(PD_VO0)) == 0)
  351. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_HDCP0], 1);
  352. if ((pmu_pd_st0 & BIT(PD_VO1)) == 0) {
  353. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_HDCP1], 1);
  354. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_HDMIRX], 1);
  355. }
  356. if ((pmu_pd_st0 & BIT(PD_VOP)) == 0) {
  357. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_VOP_M0], 1);
  358. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_VOP_M1], 1);
  359. }
  360. if ((pmu_pd_st0 & BIT(PD_FEC)) == 0) {
  361. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_FISHEYE0], 1);
  362. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_FISHEYE1], 1);
  363. }
  364. if ((pmu_pd_st0 & BIT(PD_ISP1)) == 0) {
  365. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_ISP1_MWO], 1);
  366. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_ISP1_MRO], 1);
  367. }
  368. if ((pmu_pd_st0 & BIT(PD_VI)) == 0) {
  369. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_ISP0_MWO], 1);
  370. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_ISP0_MRO], 1);
  371. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_VICAP_M0], 1);
  372. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_VICAP_M1], 1);
  373. }
  374. if ((pmu_pd_st0 & BIT(PD_RGA31)) == 0)
  375. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_RGA3_1], 1);
  376. if ((pmu_pd_st0 & BIT(PD_USB)) == 0) {
  377. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_USB3_0], 1);
  378. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_USB3_1], 1);
  379. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_USBHOST_0], 1);
  380. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_USBHOST_1], 1);
  381. }
  382. if ((pmu_pd_st0 & BIT(PD_PHP)) == 0) {
  383. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_GIC600_M0], 1);
  384. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_GIC600_M1], 1);
  385. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_MMU600PCIE_TCU], 1);
  386. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_MMU600PHP_TBU], 1);
  387. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_MMU600PHP_TCU], 1);
  388. }
  389. if ((pmu_pd_st0 & BIT(PD_SDIO)) == 0)
  390. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_SDIO], 1);
  391. if ((pmu_pd_st0 & BIT(PD_NVM0)) == 0) {
  392. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_FSPI], 1);
  393. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_EMMC], 1);
  394. }
  395. if ((pmu_pd_st0 & BIT(PD_SDMMC)) == 0)
  396. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_SDMMC], 1);
  397. if ((pmu_pd_st0 & BIT(PD_CRYPTO)) == 0) {
  398. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_CRYPTONS], 1);
  399. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_CRYPTOS], 1);
  400. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_DCF], 1);
  401. }
  402. /* PD_DSU */
  403. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_DSU_M0], 1);
  404. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_DSU_M1], 1);
  405. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_DSU_MP], 1);
  406. rockchip_reg_rgn_restore(&qos_reg_rgns[QOS_DEBUG], 1);
  407. }
  408. void pd_crypto_save(void)
  409. {
  410. rockchip_reg_rgn_save(pd_crypto_reg_rgns, ARRAY_SIZE(pd_crypto_reg_rgns));
  411. }
  412. void pd_crypto_restore(void)
  413. {
  414. rockchip_reg_rgn_restore(pd_crypto_reg_rgns, ARRAY_SIZE(pd_crypto_reg_rgns));
  415. }
  416. static uint32_t b0_cru_mode;
  417. static uint32_t b1_cru_mode;
  418. static uint32_t dsu_cru_mode;
  419. static uint32_t bcore0_cru_sel_con2, bcore1_cru_sel_con2;
  420. void pd_dsu_core_save(void)
  421. {
  422. b0_cru_mode = mmio_read_32(BIGCORE0CRU_BASE + 0x280);
  423. b1_cru_mode = mmio_read_32(BIGCORE1CRU_BASE + 0x280);
  424. dsu_cru_mode = mmio_read_32(DSUCRU_BASE + 0x280);
  425. bcore0_cru_sel_con2 = mmio_read_32(BIGCORE0CRU_BASE + CRU_CLKSEL_CON(2));
  426. bcore1_cru_sel_con2 = mmio_read_32(BIGCORE1CRU_BASE + CRU_CLKSEL_CON(2));
  427. rockchip_reg_rgn_save(pd_dsu_reg_rgns, ARRAY_SIZE(pd_dsu_reg_rgns));
  428. }
  429. void pd_dsu_core_restore(void)
  430. {
  431. /* switch bcore0/1 pclk root to 24M */
  432. mmio_write_32(BIGCORE0CRU_BASE + CRU_CLKSEL_CON(2),
  433. BITS_WITH_WMASK(2, 0x3, 0));
  434. mmio_write_32(BIGCORE1CRU_BASE + CRU_CLKSEL_CON(2),
  435. BITS_WITH_WMASK(2, 0x3, 0));
  436. /* slow mode */
  437. mmio_write_32(BIGCORE0CRU_BASE + 0x280, 0x00030000);
  438. mmio_write_32(BIGCORE1CRU_BASE + 0x280, 0x00030000);
  439. mmio_write_32(DSUCRU_BASE + 0x280, 0x00030000);
  440. rockchip_reg_rgn_restore(pd_dsu_reg_rgns, ARRAY_SIZE(pd_dsu_reg_rgns));
  441. /* trigger dsu/lcore/bcore mem_cfg */
  442. mmio_write_32(DSUGRF_BASE + 0x18, BITS_WITH_WMASK(1, 0x1, 14));
  443. mmio_write_32(LITCOREGRF_BASE + 0x30, BITS_WITH_WMASK(1, 0x1, 5));
  444. mmio_write_32(BIGCORE0GRF_BASE + 0x30, BITS_WITH_WMASK(1, 0x1, 5));
  445. mmio_write_32(BIGCORE1GRF_BASE + 0x30, BITS_WITH_WMASK(1, 0x1, 5));
  446. udelay(1);
  447. mmio_write_32(DSUGRF_BASE + 0x18, BITS_WITH_WMASK(0, 0x1, 14));
  448. mmio_write_32(LITCOREGRF_BASE + 0x30, BITS_WITH_WMASK(0, 0x1, 5));
  449. mmio_write_32(BIGCORE0GRF_BASE + 0x30, BITS_WITH_WMASK(0, 0x1, 5));
  450. mmio_write_32(BIGCORE1GRF_BASE + 0x30, BITS_WITH_WMASK(0, 0x1, 5));
  451. /* wait lock */
  452. pm_pll_wait_lock(BIGCORE0CRU_BASE + 0x00);
  453. pm_pll_wait_lock(BIGCORE1CRU_BASE + 0x20);
  454. pm_pll_wait_lock(DSUCRU_BASE + 0x40);
  455. /* restore mode */
  456. mmio_write_32(BIGCORE0CRU_BASE + 0x280, WITH_16BITS_WMSK(b0_cru_mode));
  457. mmio_write_32(BIGCORE1CRU_BASE + 0x280, WITH_16BITS_WMSK(b1_cru_mode));
  458. mmio_write_32(DSUCRU_BASE + 0x280, WITH_16BITS_WMSK(dsu_cru_mode));
  459. mmio_write_32(BIGCORE0CRU_BASE + CRU_CLKSEL_CON(2),
  460. WITH_16BITS_WMSK(bcore0_cru_sel_con2));
  461. mmio_write_32(BIGCORE1CRU_BASE + CRU_CLKSEL_CON(2),
  462. WITH_16BITS_WMSK(bcore1_cru_sel_con2));
  463. }
  464. static uint32_t php_ppll_con0;
  465. void pd_php_save(void)
  466. {
  467. php_ppll_con0 = mmio_read_32(PHP_CRU_BASE + 0x200);
  468. /* php_ppll bypass */
  469. mmio_write_32(PHP_CRU_BASE + 0x200, BITS_WITH_WMASK(1u, 1u, 15));
  470. dsb();
  471. isb();
  472. rockchip_reg_rgn_save(pd_php_reg_rgns, ARRAY_SIZE(pd_php_reg_rgns));
  473. }
  474. void pd_php_restore(void)
  475. {
  476. rockchip_reg_rgn_restore(pd_php_reg_rgns, ARRAY_SIZE(pd_php_reg_rgns));
  477. pm_pll_wait_lock(PHP_CRU_BASE + 0x200);
  478. /* restore php_ppll bypass */
  479. mmio_write_32(PHP_CRU_BASE + 0x200, WITH_16BITS_WMSK(php_ppll_con0));
  480. }
  481. void pm_reg_rgns_init(void)
  482. {
  483. rockchip_alloc_region_mem(qos_reg_rgns, ARRAY_SIZE(qos_reg_rgns));
  484. rockchip_alloc_region_mem(pd_crypto_reg_rgns, ARRAY_SIZE(pd_crypto_reg_rgns));
  485. rockchip_alloc_region_mem(pd_dsu_reg_rgns, ARRAY_SIZE(pd_dsu_reg_rgns));
  486. rockchip_alloc_region_mem(pd_php_reg_rgns, ARRAY_SIZE(pd_php_reg_rgns));
  487. }