clk-mt8186-infra_ao.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. //
  3. // Copyright (c) 2022 MediaTek Inc.
  4. // Author: Chun-Jie Chen <[email protected]>
  5. #include <linux/clk-provider.h>
  6. #include <linux/platform_device.h>
  7. #include <dt-bindings/clock/mt8186-clk.h>
  8. #include <dt-bindings/reset/mt8186-resets.h>
  9. #include "clk-gate.h"
  10. #include "clk-mtk.h"
  11. static const struct mtk_gate_regs infra_ao0_cg_regs = {
  12. .set_ofs = 0x80,
  13. .clr_ofs = 0x84,
  14. .sta_ofs = 0x90,
  15. };
  16. static const struct mtk_gate_regs infra_ao1_cg_regs = {
  17. .set_ofs = 0x88,
  18. .clr_ofs = 0x8c,
  19. .sta_ofs = 0x94,
  20. };
  21. static const struct mtk_gate_regs infra_ao2_cg_regs = {
  22. .set_ofs = 0xa4,
  23. .clr_ofs = 0xa8,
  24. .sta_ofs = 0xac,
  25. };
  26. static const struct mtk_gate_regs infra_ao3_cg_regs = {
  27. .set_ofs = 0xc0,
  28. .clr_ofs = 0xc4,
  29. .sta_ofs = 0xc8,
  30. };
  31. #define GATE_INFRA_AO0_FLAGS(_id, _name, _parent, _shift, _flag) \
  32. GATE_MTK_FLAGS(_id, _name, _parent, &infra_ao0_cg_regs, _shift, \
  33. &mtk_clk_gate_ops_setclr, _flag)
  34. #define GATE_INFRA_AO0(_id, _name, _parent, _shift) \
  35. GATE_INFRA_AO0_FLAGS(_id, _name, _parent, _shift, 0)
  36. #define GATE_INFRA_AO1_FLAGS(_id, _name, _parent, _shift, _flag) \
  37. GATE_MTK_FLAGS(_id, _name, _parent, &infra_ao1_cg_regs, _shift, \
  38. &mtk_clk_gate_ops_setclr, _flag)
  39. #define GATE_INFRA_AO1(_id, _name, _parent, _shift) \
  40. GATE_INFRA_AO1_FLAGS(_id, _name, _parent, _shift, 0)
  41. #define GATE_INFRA_AO2_FLAGS(_id, _name, _parent, _shift, _flag) \
  42. GATE_MTK_FLAGS(_id, _name, _parent, &infra_ao2_cg_regs, _shift, \
  43. &mtk_clk_gate_ops_setclr, _flag)
  44. #define GATE_INFRA_AO2(_id, _name, _parent, _shift) \
  45. GATE_INFRA_AO2_FLAGS(_id, _name, _parent, _shift, 0)
  46. #define GATE_INFRA_AO3_FLAGS(_id, _name, _parent, _shift, _flag) \
  47. GATE_MTK_FLAGS(_id, _name, _parent, &infra_ao3_cg_regs, _shift, \
  48. &mtk_clk_gate_ops_setclr, _flag)
  49. #define GATE_INFRA_AO3(_id, _name, _parent, _shift) \
  50. GATE_INFRA_AO3_FLAGS(_id, _name, _parent, _shift, 0)
  51. static const struct mtk_gate infra_ao_clks[] = {
  52. /* INFRA_AO0 */
  53. GATE_INFRA_AO0(CLK_INFRA_AO_PMIC_TMR, "infra_ao_pmic_tmr", "top_pwrap_ulposc", 0),
  54. GATE_INFRA_AO0(CLK_INFRA_AO_PMIC_AP, "infra_ao_pmic_ap", "top_pwrap_ulposc", 1),
  55. GATE_INFRA_AO0(CLK_INFRA_AO_PMIC_MD, "infra_ao_pmic_md", "top_pwrap_ulposc", 2),
  56. GATE_INFRA_AO0(CLK_INFRA_AO_PMIC_CONN, "infra_ao_pmic_conn", "top_pwrap_ulposc", 3),
  57. /* infra_ao_scp_core are main clock in always-on co-processor. */
  58. GATE_INFRA_AO0_FLAGS(CLK_INFRA_AO_SCP_CORE,
  59. "infra_ao_scp_core", "top_scp", 4, CLK_IS_CRITICAL),
  60. /* infra_ao_sej is main clock for secure engine with JTAG support */
  61. GATE_INFRA_AO0_FLAGS(CLK_INFRA_AO_SEJ,
  62. "infra_ao_sej", "top_axi", 5, CLK_IS_CRITICAL),
  63. GATE_INFRA_AO0(CLK_INFRA_AO_APXGPT, "infra_ao_apxgpt", "top_axi", 6),
  64. GATE_INFRA_AO0(CLK_INFRA_AO_ICUSB, "infra_ao_icusb", "top_axi", 8),
  65. GATE_INFRA_AO0(CLK_INFRA_AO_GCE, "infra_ao_gce", "top_axi", 9),
  66. GATE_INFRA_AO0(CLK_INFRA_AO_THERM, "infra_ao_therm", "top_axi", 10),
  67. GATE_INFRA_AO0(CLK_INFRA_AO_I2C_AP, "infra_ao_i2c_ap", "top_i2c", 11),
  68. GATE_INFRA_AO0(CLK_INFRA_AO_I2C_CCU, "infra_ao_i2c_ccu", "top_i2c", 12),
  69. GATE_INFRA_AO0(CLK_INFRA_AO_I2C_SSPM, "infra_ao_i2c_sspm", "top_i2c", 13),
  70. GATE_INFRA_AO0(CLK_INFRA_AO_I2C_RSV, "infra_ao_i2c_rsv", "top_i2c", 14),
  71. GATE_INFRA_AO0(CLK_INFRA_AO_PWM_HCLK, "infra_ao_pwm_hclk", "top_axi", 15),
  72. GATE_INFRA_AO0(CLK_INFRA_AO_PWM1, "infra_ao_pwm1", "top_pwm", 16),
  73. GATE_INFRA_AO0(CLK_INFRA_AO_PWM2, "infra_ao_pwm2", "top_pwm", 17),
  74. GATE_INFRA_AO0(CLK_INFRA_AO_PWM3, "infra_ao_pwm3", "top_pwm", 18),
  75. GATE_INFRA_AO0(CLK_INFRA_AO_PWM4, "infra_ao_pwm4", "top_pwm", 19),
  76. GATE_INFRA_AO0(CLK_INFRA_AO_PWM5, "infra_ao_pwm5", "top_pwm", 20),
  77. GATE_INFRA_AO0(CLK_INFRA_AO_PWM, "infra_ao_pwm", "top_pwm", 21),
  78. GATE_INFRA_AO0(CLK_INFRA_AO_UART0, "infra_ao_uart0", "top_uart", 22),
  79. GATE_INFRA_AO0(CLK_INFRA_AO_UART1, "infra_ao_uart1", "top_uart", 23),
  80. GATE_INFRA_AO0(CLK_INFRA_AO_UART2, "infra_ao_uart2", "top_uart", 24),
  81. GATE_INFRA_AO0(CLK_INFRA_AO_GCE_26M, "infra_ao_gce_26m", "clk26m", 27),
  82. GATE_INFRA_AO0(CLK_INFRA_AO_CQ_DMA_FPC, "infra_ao_dma", "top_axi", 28),
  83. GATE_INFRA_AO0(CLK_INFRA_AO_BTIF, "infra_ao_btif", "top_axi", 31),
  84. /* INFRA_AO1 */
  85. GATE_INFRA_AO1(CLK_INFRA_AO_SPI0, "infra_ao_spi0", "top_spi", 1),
  86. GATE_INFRA_AO1(CLK_INFRA_AO_MSDC0, "infra_ao_msdc0", "top_msdc5hclk", 2),
  87. GATE_INFRA_AO1(CLK_INFRA_AO_MSDCFDE, "infra_ao_msdcfde", "top_aes_msdcfde", 3),
  88. GATE_INFRA_AO1(CLK_INFRA_AO_MSDC1, "infra_ao_msdc1", "top_axi", 4),
  89. /* infra_ao_dvfsrc is for internal DVFS usage, should not be handled by Linux */
  90. GATE_INFRA_AO1_FLAGS(CLK_INFRA_AO_DVFSRC,
  91. "infra_ao_dvfsrc", "top_dvfsrc", 7, CLK_IS_CRITICAL),
  92. GATE_INFRA_AO1(CLK_INFRA_AO_GCPU, "infra_ao_gcpu", "top_axi", 8),
  93. GATE_INFRA_AO1(CLK_INFRA_AO_TRNG, "infra_ao_trng", "top_axi", 9),
  94. GATE_INFRA_AO1(CLK_INFRA_AO_AUXADC, "infra_ao_auxadc", "clk26m", 10),
  95. GATE_INFRA_AO1(CLK_INFRA_AO_CPUM, "infra_ao_cpum", "top_axi", 11),
  96. GATE_INFRA_AO1(CLK_INFRA_AO_CCIF1_AP, "infra_ao_ccif1_ap", "top_axi", 12),
  97. GATE_INFRA_AO1(CLK_INFRA_AO_CCIF1_MD, "infra_ao_ccif1_md", "top_axi", 13),
  98. GATE_INFRA_AO1(CLK_INFRA_AO_AUXADC_MD, "infra_ao_auxadc_md", "clk26m", 14),
  99. GATE_INFRA_AO1(CLK_INFRA_AO_AP_DMA, "infra_ao_ap_dma", "top_axi", 18),
  100. GATE_INFRA_AO1(CLK_INFRA_AO_XIU, "infra_ao_xiu", "top_axi", 19),
  101. /* infra_ao_device_apc is for device access permission control module */
  102. GATE_INFRA_AO1_FLAGS(CLK_INFRA_AO_DEVICE_APC,
  103. "infra_ao_dapc", "top_axi", 20, CLK_IS_CRITICAL),
  104. GATE_INFRA_AO1(CLK_INFRA_AO_CCIF_AP, "infra_ao_ccif_ap", "top_axi", 23),
  105. GATE_INFRA_AO1(CLK_INFRA_AO_DEBUGTOP, "infra_ao_debugtop", "top_axi", 24),
  106. GATE_INFRA_AO1(CLK_INFRA_AO_AUDIO, "infra_ao_audio", "top_axi", 25),
  107. GATE_INFRA_AO1(CLK_INFRA_AO_CCIF_MD, "infra_ao_ccif_md", "top_axi", 26),
  108. GATE_INFRA_AO1(CLK_INFRA_AO_DXCC_SEC_CORE, "infra_ao_secore", "top_dxcc", 27),
  109. GATE_INFRA_AO1(CLK_INFRA_AO_DXCC_AO, "infra_ao_dxcc_ao", "top_dxcc", 28),
  110. GATE_INFRA_AO1(CLK_INFRA_AO_IMP_IIC, "infra_ao_imp_iic", "top_axi", 29),
  111. GATE_INFRA_AO1(CLK_INFRA_AO_DRAMC_F26M, "infra_ao_dramc26", "clk26m", 31),
  112. /* INFRA_AO2 */
  113. GATE_INFRA_AO2(CLK_INFRA_AO_RG_PWM_FBCLK6, "infra_ao_pwm_fbclk6", "clk26m", 0),
  114. GATE_INFRA_AO2(CLK_INFRA_AO_SSUSB_TOP_HCLK, "infra_ao_ssusb_hclk", "top_axi", 1),
  115. GATE_INFRA_AO2(CLK_INFRA_AO_DISP_PWM, "infra_ao_disp_pwm", "top_disp_pwm", 2),
  116. GATE_INFRA_AO2(CLK_INFRA_AO_CLDMA_BCLK, "infra_ao_cldmabclk", "top_axi", 3),
  117. GATE_INFRA_AO2(CLK_INFRA_AO_AUDIO_26M_BCLK, "infra_ao_audio26m", "clk26m", 4),
  118. GATE_INFRA_AO2(CLK_INFRA_AO_SSUSB_TOP_P1_HCLK, "infra_ao_ssusb_p1_hclk", "top_axi", 5),
  119. GATE_INFRA_AO2(CLK_INFRA_AO_SPI1, "infra_ao_spi1", "top_spi", 6),
  120. GATE_INFRA_AO2(CLK_INFRA_AO_I2C4, "infra_ao_i2c4", "top_i2c", 7),
  121. GATE_INFRA_AO2(CLK_INFRA_AO_MODEM_TEMP_SHARE, "infra_ao_mdtemp", "clk26m", 8),
  122. GATE_INFRA_AO2(CLK_INFRA_AO_SPI2, "infra_ao_spi2", "top_spi", 9),
  123. GATE_INFRA_AO2(CLK_INFRA_AO_SPI3, "infra_ao_spi3", "top_spi", 10),
  124. GATE_INFRA_AO2(CLK_INFRA_AO_SSUSB_TOP_REF, "infra_ao_ssusb_ref", "clk26m", 11),
  125. GATE_INFRA_AO2(CLK_INFRA_AO_SSUSB_TOP_XHCI, "infra_ao_ssusb_xhci", "top_ssusb_xhci", 12),
  126. GATE_INFRA_AO2(CLK_INFRA_AO_SSUSB_TOP_P1_REF, "infra_ao_ssusb_p1_ref", "clk26m", 13),
  127. GATE_INFRA_AO2(CLK_INFRA_AO_SSUSB_TOP_P1_XHCI,
  128. "infra_ao_ssusb_p1_xhci", "top_ssusb_xhci_1p", 14),
  129. /* infra_ao_sspm is main clock in co-processor, should not be closed in Linux. */
  130. GATE_INFRA_AO2_FLAGS(CLK_INFRA_AO_SSPM, "infra_ao_sspm", "top_sspm", 15, CLK_IS_CRITICAL),
  131. GATE_INFRA_AO2(CLK_INFRA_AO_SSUSB_TOP_P1_SYS,
  132. "infra_ao_ssusb_p1_sys", "top_ssusb_1p", 16),
  133. GATE_INFRA_AO2(CLK_INFRA_AO_I2C5, "infra_ao_i2c5", "top_i2c", 18),
  134. GATE_INFRA_AO2(CLK_INFRA_AO_I2C5_ARBITER, "infra_ao_i2c5a", "top_i2c", 19),
  135. GATE_INFRA_AO2(CLK_INFRA_AO_I2C5_IMM, "infra_ao_i2c5_imm", "top_i2c", 20),
  136. GATE_INFRA_AO2(CLK_INFRA_AO_I2C1_ARBITER, "infra_ao_i2c1a", "top_i2c", 21),
  137. GATE_INFRA_AO2(CLK_INFRA_AO_I2C1_IMM, "infra_ao_i2c1_imm", "top_i2c", 22),
  138. GATE_INFRA_AO2(CLK_INFRA_AO_I2C2_ARBITER, "infra_ao_i2c2a", "top_i2c", 23),
  139. GATE_INFRA_AO2(CLK_INFRA_AO_I2C2_IMM, "infra_ao_i2c2_imm", "top_i2c", 24),
  140. GATE_INFRA_AO2(CLK_INFRA_AO_SPI4, "infra_ao_spi4", "top_spi", 25),
  141. GATE_INFRA_AO2(CLK_INFRA_AO_SPI5, "infra_ao_spi5", "top_spi", 26),
  142. GATE_INFRA_AO2(CLK_INFRA_AO_CQ_DMA, "infra_ao_cq_dma", "top_axi", 27),
  143. GATE_INFRA_AO2(CLK_INFRA_AO_BIST2FPC, "infra_ao_bist2fpc", "f_bist2fpc_ck", 28),
  144. /* INFRA_AO3 */
  145. GATE_INFRA_AO3(CLK_INFRA_AO_MSDC0_SELF, "infra_ao_msdc0sf", "top_msdc50_0", 0),
  146. GATE_INFRA_AO3(CLK_INFRA_AO_SPINOR, "infra_ao_spinor", "top_spinor", 1),
  147. /*
  148. * infra_ao_sspm_26m/infra_ao_sspm_32k are main clocks in co-processor,
  149. * should not be closed in Linux.
  150. */
  151. GATE_INFRA_AO3_FLAGS(CLK_INFRA_AO_SSPM_26M_SELF, "infra_ao_sspm_26m", "clk26m", 3,
  152. CLK_IS_CRITICAL),
  153. GATE_INFRA_AO3_FLAGS(CLK_INFRA_AO_SSPM_32K_SELF, "infra_ao_sspm_32k", "clk32k", 4,
  154. CLK_IS_CRITICAL),
  155. GATE_INFRA_AO3(CLK_INFRA_AO_I2C6, "infra_ao_i2c6", "top_i2c", 6),
  156. GATE_INFRA_AO3(CLK_INFRA_AO_AP_MSDC0, "infra_ao_ap_msdc0", "top_axi", 7),
  157. GATE_INFRA_AO3(CLK_INFRA_AO_MD_MSDC0, "infra_ao_md_msdc0", "top_axi", 8),
  158. GATE_INFRA_AO3(CLK_INFRA_AO_MSDC0_SRC, "infra_ao_msdc0_clk", "top_msdc50_0", 9),
  159. GATE_INFRA_AO3(CLK_INFRA_AO_MSDC1_SRC, "infra_ao_msdc1_clk", "top_msdc30_1", 10),
  160. /* infra_ao_sej_f13m is main clock for secure engine with JTAG support */
  161. GATE_INFRA_AO3_FLAGS(CLK_INFRA_AO_SEJ_F13M,
  162. "infra_ao_sej_f13m", "clk26m", 15, CLK_IS_CRITICAL),
  163. /* infra_ao_aes_top0_bclk is for secure encryption */
  164. GATE_INFRA_AO3_FLAGS(CLK_INFRA_AO_AES_TOP0_BCLK,
  165. "infra_ao_aes_top0_bclk", "top_axi", 16, CLK_IS_CRITICAL),
  166. GATE_INFRA_AO3(CLK_INFRA_AO_MCU_PM_BCLK, "infra_ao_mcu_pm_bclk", "top_axi", 17),
  167. GATE_INFRA_AO3(CLK_INFRA_AO_CCIF2_AP, "infra_ao_ccif2_ap", "top_axi", 18),
  168. GATE_INFRA_AO3(CLK_INFRA_AO_CCIF2_MD, "infra_ao_ccif2_md", "top_axi", 19),
  169. GATE_INFRA_AO3(CLK_INFRA_AO_CCIF3_AP, "infra_ao_ccif3_ap", "top_axi", 20),
  170. GATE_INFRA_AO3(CLK_INFRA_AO_CCIF3_MD, "infra_ao_ccif3_md", "top_axi", 21),
  171. GATE_INFRA_AO3(CLK_INFRA_AO_FADSP_26M, "infra_ao_fadsp_26m", "clk26m", 22),
  172. GATE_INFRA_AO3(CLK_INFRA_AO_FADSP_32K, "infra_ao_fadsp_32k", "clk32k", 23),
  173. GATE_INFRA_AO3(CLK_INFRA_AO_CCIF4_AP, "infra_ao_ccif4_ap", "top_axi", 24),
  174. GATE_INFRA_AO3(CLK_INFRA_AO_CCIF4_MD, "infra_ao_ccif4_md", "top_axi", 25),
  175. GATE_INFRA_AO3(CLK_INFRA_AO_FADSP, "infra_ao_fadsp", "top_audiodsp", 27),
  176. GATE_INFRA_AO3(CLK_INFRA_AO_FLASHIF_133M, "infra_ao_flashif_133m", "top_axi", 28),
  177. GATE_INFRA_AO3(CLK_INFRA_AO_FLASHIF_66M, "infra_ao_flashif_66m", "top_axi", 29),
  178. };
  179. static u16 infra_ao_rst_ofs[] = {
  180. INFRA_RST0_SET_OFFSET,
  181. INFRA_RST1_SET_OFFSET,
  182. INFRA_RST2_SET_OFFSET,
  183. INFRA_RST3_SET_OFFSET,
  184. INFRA_RST4_SET_OFFSET,
  185. };
  186. static u16 infra_ao_idx_map[] = {
  187. [MT8186_INFRA_THERMAL_CTRL_RST] = 0 * RST_NR_PER_BANK + 0,
  188. [MT8186_INFRA_PTP_CTRL_RST] = 1 * RST_NR_PER_BANK + 0,
  189. };
  190. static struct mtk_clk_rst_desc infra_ao_rst_desc = {
  191. .version = MTK_RST_SET_CLR,
  192. .rst_bank_ofs = infra_ao_rst_ofs,
  193. .rst_bank_nr = ARRAY_SIZE(infra_ao_rst_ofs),
  194. .rst_idx_map = infra_ao_idx_map,
  195. .rst_idx_map_nr = ARRAY_SIZE(infra_ao_idx_map),
  196. };
  197. static const struct mtk_clk_desc infra_ao_desc = {
  198. .clks = infra_ao_clks,
  199. .num_clks = ARRAY_SIZE(infra_ao_clks),
  200. .rst_desc = &infra_ao_rst_desc,
  201. };
  202. static const struct of_device_id of_match_clk_mt8186_infra_ao[] = {
  203. {
  204. .compatible = "mediatek,mt8186-infracfg_ao",
  205. .data = &infra_ao_desc,
  206. }, {
  207. /* sentinel */
  208. }
  209. };
  210. static struct platform_driver clk_mt8186_infra_ao_drv = {
  211. .probe = mtk_clk_simple_probe,
  212. .remove = mtk_clk_simple_remove,
  213. .driver = {
  214. .name = "clk-mt8186-infra-ao",
  215. .of_match_table = of_match_clk_mt8186_infra_ao,
  216. },
  217. };
  218. builtin_platform_driver(clk_mt8186_infra_ao_drv);