apusys_devapc.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. * Copyright (c) 2024, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/debug.h>
  7. #include <lib/utils_def.h>
  8. #include <platform_def.h>
  9. #include <apusys_devapc.h>
  10. #include <apusys_devapc_def.h>
  11. #include <mtk_mmap_pool.h>
  12. /* AO CONTROL DEVAPC - apu_rcx_ao_infra_dapc_con */
  13. static const struct apc_dom_16 APUSYS_CTRL_DAPC_AO[] = {
  14. /* ctrl index = 0 */
  15. SLAVE_RCX_BULK0("apu_ao_ctl_o-0"),
  16. SLAVE_MD32_APB("apu_ao_ctl_o-1"),
  17. SLAVE_ACP_TCU_SSC("apu_ao_ctl_o-2"),
  18. SLAVE_PTP_THM("apu_ao_ctl_o-3"),
  19. SLAVE_VCORE("apu_ao_ctl_o-4"),
  20. SLAVE_IOMMU0_BANK0("apu_ao_ctl_o-5"),
  21. SLAVE_IOMMU0_BANK1("apu_ao_ctl_o-6"),
  22. SLAVE_IOMMU0_BANK2("apu_ao_ctl_o-7"),
  23. SLAVE_IOMMU0_BANK3("apu_ao_ctl_o-8"),
  24. SLAVE_IOMMU0_BANK4("apu_ao_ctl_o-9"),
  25. /* ctrl index = 10 */
  26. SLAVE_IOMMU1_BANK0("apu_ao_ctl_o-10"),
  27. SLAVE_IOMMU1_BANK1("apu_ao_ctl_o-11"),
  28. SLAVE_IOMMU1_BANK2("apu_ao_ctl_o-12"),
  29. SLAVE_IOMMU1_BANK3("apu_ao_ctl_o-13"),
  30. SLAVE_IOMMU1_BANK4("apu_ao_ctl_o-14"),
  31. SLAVE_S0_SSC("apu_ao_ctl_o-15"),
  32. SLAVE_N0_SSC("apu_ao_ctl_o-16"),
  33. SLAVE_S1_SSC("apu_ao_ctl_o-17"),
  34. SLAVE_N1_SSC("apu_ao_ctl_o-18"),
  35. SLAVE_ACP_SSC("apu_ao_ctl_o-19"),
  36. /* ctrl index = 20 */
  37. SLAVE_WDEC("apu_ao_ctl_o-20"),
  38. SLAVE_SMMU_IP_REG("apu_ao_ctl_o-21"),
  39. SLAVE_SMMU_NSEC("apu_ao_ctl_o-22"),
  40. SLAVE_SMMU_SEC("apu_ao_ctl_o-23"),
  41. SLAVE_ARE0("apu_ao_ctl_o-24"),
  42. SLAVE_ARE1("apu_ao_ctl_o-25"),
  43. SLAVE_SONC("apu_ao_ctl_o-26"),
  44. SLAVE_RPC("apu_ao_ctl_o-28"),
  45. SLAVE_PCU("apu_ao_ctl_o-29"),
  46. SLAVE_AO_CTRL("apu_ao_ctl_o-30"),
  47. /* ctrl index = 30 */
  48. SLAVE_AO_CTRL("apu_ao_ctl_o-31"),
  49. SLAVE_ACC("apu_ao_ctl_o-32"),
  50. SLAVE_SEC("apu_ao_ctl_o-33"),
  51. SLAVE_PLL("apu_ao_ctl_o-34"),
  52. SLAVE_RPC_MDLA("apu_ao_ctl_o-35"),
  53. SLAVE_TOP_PMU("apu_ao_ctl_o-36"),
  54. SLAVE_AO_BCRM("apu_ao_ctl_o-37"),
  55. SLAVE_AO_DAPC_WRAP("apu_ao_ctl_o-38"),
  56. SLAVE_AO_DAPC_CON("apu_ao_ctl_o-39"),
  57. SLAVE_UNDEFINE0("apu_ao_ctl_o-40"),
  58. /* ctrl index = 40 */
  59. SLAVE_UNDEFINE1("apu_ao_ctl_o-41"),
  60. SLAVE_RCX_BULK0("apu_ao_ctl_o-42"),
  61. SLAVE_UNDEFINE2("apu_ao_ctl_o-43"),
  62. SLAVE_UNDEFINE3("apu_ao_ctl_o-44"),
  63. SLAVE_UNDEFINE4("apu_ao_ctl_o-45"),
  64. SLAVE_UNDEFINE5("apu_ao_ctl_o-46"),
  65. SLAVE_UNDEFINE6("apu_ao_ctl_o-47"),
  66. SLAVE_UNDEFINE7("apu_ao_ctl_o-48"),
  67. SLAVE_DATA_BULK("apu_ao_ctl_o-49"),
  68. SLAVE_ACX0_BULK("apu_ao_ctl_o-50"),
  69. /* ctrl index = 50 */
  70. SLAVE_ACX0_AO("apu_ao_ctl_o-51"),
  71. SLAVE_ACX1_BULK("apu_ao_ctl_o-52"),
  72. SLAVE_ACX1_AO("apu_ao_ctl_o-53"),
  73. SLAVE_NCX_BULK("apu_ao_ctl_o-54"),
  74. SLAVE_NCX_AO("apu_ao_ctl_o-55"),
  75. SLAVE_ACX0_BULK("apu_rcx2acx0_o-0"),
  76. SLAVE_ACX0_AO("apu_rcx2acx0_o-1"),
  77. SLAVE_ACX0_BULK("apu_sae2acx0_o-0"),
  78. SLAVE_ACX0_AO("apu_sae2acx0_o-1"),
  79. SLAVE_ACX1_BULK("apu_rcx2acx1_o-0"),
  80. /* ctrl index = 60 */
  81. SLAVE_ACX1_AO("apu_rcx2acx1_o-1"),
  82. SLAVE_ACX1_BULK("apu_sae2acx1_o-0"),
  83. SLAVE_ACX1_AO("apu_sae2acx1_o-1"),
  84. SLAVE_NCX_BULK("apu_rcx2ncx_o-0"),
  85. SLAVE_NCX_AO("apu_rcx2ncx_o-1"),
  86. SLAVE_NCX_BULK("apu_sae2ncx_o-0"),
  87. SLAVE_NCX_AO("apu_sae2ncx_o-1"),
  88. };
  89. /* RCX CONTROL DEVAPC - apu_rcx_infra_dapc_con */
  90. static const struct apc_dom_16 APUSYS_CTRL_DAPC_RCX[] = {
  91. /* ctrl index = 0 */
  92. SLAVE_ACX0_BULK("acx0_apbs-0"),
  93. SLAVE_ACX0_RPC("acx0_apbs-1"),
  94. SLAVE_ACX0_AO_CTRL("acx0_apbs-2"),
  95. SLAVE_UNDEFINE8("acx0_apbs-3"),
  96. SLAVE_ACX1_BULK("acx1_apbs-0"),
  97. SLAVE_ACX1_RPC("acx1_apbs-1"),
  98. SLAVE_ACX1_AO_CTRL("acx1_apbs-2"),
  99. SLAVE_UNDEFINE9("acx1_apbs-3"),
  100. SLAVE_NCX_BULK("ncx_apbs-0"),
  101. SLAVE_NCX_RPC("ncx_apbs-1"),
  102. /* ctrl index = 10 */
  103. SLAVE_NCX_AO_CTRL("ncx_apbs-2"),
  104. SLAVE_UNDEFINE10("ncx_apbs-3"),
  105. SLAVE_MD32_SYSCTRL("md32_apb_s-0"),
  106. SLAVE_MD32_PMU("md32_apb_s-1"),
  107. SLAVE_MD32_WDT("md32_apb_s-2"),
  108. SLAVE_MD32_CACHE("md32_apb_s-3"),
  109. SLAVE_ARE0("apusys_ao-0"),
  110. SLAVE_ARE1("apusys_ao-1"),
  111. SLAVE_SONC("apusys_ao-2"),
  112. SLAVE_RPC("apusys_ao-3"),
  113. /* ctrl index = 20 */
  114. SLAVE_PCU("apusys_ao-4"),
  115. SLAVE_AO_CTRL("apusys_ao-5"),
  116. SLAVE_AO_CTRL("apusys_ao-6"),
  117. SLAVE_SEC("apusys_ao-7"),
  118. SLAVE_PLL("apusys_ao-8"),
  119. SLAVE_RPC_MDLA("apusys_ao-9"),
  120. SLAVE_TOP_PMU("apusys_ao-10"),
  121. SLAVE_AO_BCRM("apusys_ao-11"),
  122. SLAVE_AO_DAPC_WRAP("apusys_ao-12"),
  123. SLAVE_AO_DAPC_CON("apusys_ao-13"),
  124. /* ctrl index = 30 */
  125. SLAVE_VCORE("apusys_ao-14"),
  126. SLAVE_IOMMU0_BANK0("apusys_ao-15"),
  127. SLAVE_IOMMU0_BANK1("apusys_ao-16"),
  128. SLAVE_IOMMU0_BANK2("apusys_ao-17"),
  129. SLAVE_IOMMU0_BANK3("apusys_ao-18"),
  130. SLAVE_IOMMU0_BANK4("apusys_ao-19"),
  131. SLAVE_IOMMU1_BANK0("apu_ao_ctl_o-20"),
  132. SLAVE_IOMMU1_BANK1("apu_ao_ctl_o-21"),
  133. SLAVE_IOMMU1_BANK2("apu_ao_ctl_o-22"),
  134. SLAVE_IOMMU1_BANK3("apu_ao_ctl_o-23"),
  135. /* ctrl index = 40 */
  136. SLAVE_IOMMU1_BANK4("apu_ao_ctl_o-24"),
  137. SLAVE_S0_SSC("apu_ao_ctl_o-25"),
  138. SLAVE_N0_SSC("apu_ao_ctl_o-26"),
  139. SLAVE_S1_SSC("apu_ao_ctl_o-27"),
  140. SLAVE_N1_SSC("apu_ao_ctl_o-28"),
  141. SLAVE_ACP_SSC("apu_ao_ctl_o-29"),
  142. SLAVE_ACP_TCU_SSC("apu_ao_ctl_o-30"),
  143. SLAVE_PTP_THM("apu_ao_ctl_o-31"),
  144. SLAVE_WDEC("apu_ao_ctl_o-32"),
  145. SLAVE_SMMU_IP_REG("apu_ao_ctl_o-33"),
  146. /* ctrl index = 50 */
  147. SLAVE_SMMU_NSEC("apu_ao_ctl_o-34"),
  148. SLAVE_SMMU_SEC("apu_ao_ctl_o-35"),
  149. SLAVE_DATA_BULK("noc_axi"),
  150. SLAVE_MD32_DBG("md32_dbg"),
  151. SLAVE_MDLA_DBG("mdla_dbg"),
  152. SLAVE_INFRA_DBG("apb_infra_dbg"),
  153. SLAVE_LOG_TOP0("apu_logtop-0"),
  154. SLAVE_LOG_TOP1("apu_logtop-1"),
  155. SLAVE_RCX_CFG("apu_rcx_cfg"),
  156. SLAVE_ACX_IPS("apu_acx_ips"),
  157. /* ctrl index = 60 */
  158. SLAVE_SEMA_STIMER("apu_sema_stimer"),
  159. SLAVE_EMI_CFG("apu_emi_cfg"),
  160. SLAVE_CPE_SENSOR("apu_cpe_sensor"),
  161. SLAVE_CPE_COEF("apu_cpe_coef"),
  162. SLAVE_CPE_CTRL("apu_cpe_ctrl"),
  163. SLAVE_TPPA("apu_dfd"),
  164. SLAVE_SENSOR_ACX0_DLA0("apu_sen_acx0_dla0"),
  165. SLAVE_SENSOR_ACX0_VPU("apu_sen_acx0_vpu"),
  166. SLAVE_SENSOR_ACX1_DLA0("apu_sen_acx1_dla0"),
  167. SLAVE_SENSOR_ACX1_VPU("apu_sen_acx1_vpu"),
  168. /* ctrl index = 70 */
  169. SLAVE_SENSOR_NCX_DLA0("apu_sen_ncx_dla0"),
  170. SLAVE_SENSOR_NCX_NVE("apu_sen_ncx_nve"),
  171. SLAVE_RCX_TCU0("noc_cfg-0"),
  172. SLAVE_RCX_TCU1("noc_cfg-1"),
  173. SLAVE_RCX_TCU2("noc_cfg-2"),
  174. SLAVE_RCX_TCU3("noc_cfg-3"),
  175. SLAVE_RCX_TCU4("noc_cfg-4"),
  176. SLAVE_RCX_TCU5("noc_cfg-5"),
  177. SLAVE_RCX_TCU6("noc_cfg-6"),
  178. SLAVE_RCX_NOC_CFG("noc_cfg-7"),
  179. /* ctrl index = 80 */
  180. SLAVE_SCMDQ("apu_hse-0"),
  181. SLAVE_HSE("apu_hse-1"),
  182. SLAVE_MDLA_CORE_CTRL("mdla_cfg-0"),
  183. SLAVE_MDLA_BIU("mdla_cfg-1"),
  184. SLAVE_MDLA_PMU("mdla_cfg-2"),
  185. SLAVE_MDLA_CMDE("mdla_cfg-3"),
  186. SLAVE_EDPA0("apu_edpa-0"),
  187. SLAVE_EDPA1("apu_edpa-1"),
  188. SLAVE_RCX_BCRM("infra_bcrm"),
  189. SLAVE_RCX_DAPC_WRAP("infra_dpac_wrap"),
  190. /* ctrl index = 90 */
  191. SLAVE_RCX_DAPC_CON("infra_dapc_con"),
  192. SLAVE_RCX_CMU("rcx_cmu"),
  193. SLAVE_RCX_ACS("apu_rcx_acs"),
  194. SLAVE_RCX_CBFC("rcx_cbfc"),
  195. SLAVE_ACC("acc"),
  196. };
  197. static enum apusys_apc_err_status set_slave_ctrl_apc(uint32_t slave,
  198. enum apusys_apc_type type,
  199. enum apusys_apc_domain_id domain_id,
  200. enum apusys_apc_perm_type perm)
  201. {
  202. uint32_t apc_register_index;
  203. uint32_t apc_set_index;
  204. uint32_t base = 0;
  205. uint32_t clr_bit;
  206. uint32_t set_bit;
  207. uint32_t slave_num_in_1_dom;
  208. uint32_t slave_num, dom_num;
  209. uint32_t dapc_base;
  210. if (perm >= PERM_NUM) {
  211. ERROR("%s: permission type:0x%x is not supported!\n", __func__, perm);
  212. return APUSYS_APC_ERR_PERMISSION_NOT_SUPPORTED;
  213. }
  214. switch (type) {
  215. case DAPC_AO:
  216. slave_num_in_1_dom = APUSYS_CTRL_DAPC_AO_SLAVE_NUM_IN_1_DOM;
  217. slave_num = APUSYS_CTRL_DAPC_AO_SLAVE_NUM;
  218. dom_num = APUSYS_CTRL_DAPC_AO_DOM_NUM;
  219. dapc_base = APUSYS_CTRL_DAPC_AO_BASE;
  220. break;
  221. case DAPC_RCX:
  222. slave_num_in_1_dom = APUSYS_CTRL_DAPC_RCX_SLAVE_NUM_IN_1_DOM;
  223. slave_num = APUSYS_CTRL_DAPC_RCX_SLAVE_NUM;
  224. dom_num = APUSYS_CTRL_DAPC_RCX_DOM_NUM;
  225. dapc_base = APUSYS_CTRL_DAPC_RCX_BASE;
  226. break;
  227. default:
  228. ERROR("%s: unsupported devapc type: %u\n", __func__, type);
  229. return APUSYS_APC_ERR_GENERIC;
  230. }
  231. apc_register_index = slave / slave_num_in_1_dom;
  232. apc_set_index = slave % slave_num_in_1_dom;
  233. clr_bit = DEVAPC_MASK << (apc_set_index * DEVAPC_DOM_SHIFT);
  234. set_bit = (uint32_t)perm << (apc_set_index * DEVAPC_DOM_SHIFT);
  235. if (slave < slave_num && domain_id < dom_num) {
  236. base = dapc_base + domain_id * DEVAPC_DOM_SIZE
  237. + apc_register_index * DEVAPC_REG_SIZE;
  238. } else {
  239. ERROR("%s: out of boundary, devapc type: %d, slave: 0x%x, domain_id: 0x%x\n",
  240. __func__, type, slave, domain_id);
  241. return APUSYS_APC_ERR_OUT_OF_BOUNDARY;
  242. }
  243. if (!base)
  244. return APUSYS_APC_ERR_GENERIC;
  245. mmio_clrsetbits_32(base, clr_bit, set_bit);
  246. return APUSYS_APC_OK;
  247. }
  248. static enum apusys_apc_err_status set_slave_ao_ctrl_apc(uint32_t slave,
  249. enum apusys_apc_domain_id domain_id,
  250. enum apusys_apc_perm_type perm)
  251. {
  252. return set_slave_ctrl_apc(slave, DAPC_AO, domain_id, perm);
  253. }
  254. static enum apusys_apc_err_status set_slave_rcx_ctrl_apc(uint32_t slave,
  255. enum apusys_apc_domain_id domain_id,
  256. enum apusys_apc_perm_type perm)
  257. {
  258. return set_slave_ctrl_apc(slave, DAPC_RCX, domain_id, perm);
  259. }
  260. static void apusys_devapc_init(uint32_t base)
  261. {
  262. mmio_write_32(APUSYS_DAPC_CON(base), APUSYS_DAPC_CON_VIO_MASK);
  263. }
  264. int apusys_devapc_ao_init(void)
  265. {
  266. int32_t ret = APUSYS_APC_OK;
  267. apusys_devapc_init(APUSYS_CTRL_DAPC_AO_BASE);
  268. ret = SET_APUSYS_DAPC_V1(APUSYS_CTRL_DAPC_AO, set_slave_ao_ctrl_apc);
  269. if (ret) {
  270. ERROR("[APUAPC_AO] %s: set_apusys_ao_ctrl_dapc failed\n", __func__);
  271. return ret;
  272. }
  273. #ifdef DUMP_CFG
  274. DUMP_APUSYS_DAPC_V1(APUSYS_CTRL_DAPC_AO);
  275. #endif
  276. INFO("[APUAPC_AO] %s done\n", __func__);
  277. return ret;
  278. }
  279. int apusys_devapc_rcx_init(void)
  280. {
  281. int32_t ret = APUSYS_APC_OK;
  282. apusys_devapc_init(APUSYS_CTRL_DAPC_RCX_BASE);
  283. ret = SET_APUSYS_DAPC_V1(APUSYS_CTRL_DAPC_RCX, set_slave_rcx_ctrl_apc);
  284. if (ret) {
  285. ERROR("[APUAPC_RCX] %s: set_slave_rcx_ctrl_apc failed\n", __func__);
  286. return ret;
  287. }
  288. #ifdef DUMP_CFG
  289. DUMP_APUSYS_DAPC_V1(APUSYS_CTRL_DAPC_RCX);
  290. #endif
  291. INFO("[APUAPC_RCX] %s done\n", __func__);
  292. return ret;
  293. }