clk-mt8188-infra_ao.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022 MediaTek Inc.
  4. * Author: Garmin Chang <garmin.chang@mediatek.com>
  5. */
  6. #include <dt-bindings/clock/mediatek,mt8188-clk.h>
  7. #include <dt-bindings/reset/mt8188-resets.h>
  8. #include <linux/clk-provider.h>
  9. #include <linux/platform_device.h>
  10. #include "clk-gate.h"
  11. #include "clk-mtk.h"
  12. static const struct mtk_gate_regs infra_ao0_cg_regs = {
  13. .set_ofs = 0x80,
  14. .clr_ofs = 0x84,
  15. .sta_ofs = 0x90,
  16. };
  17. static const struct mtk_gate_regs infra_ao1_cg_regs = {
  18. .set_ofs = 0x88,
  19. .clr_ofs = 0x8c,
  20. .sta_ofs = 0x94,
  21. };
  22. static const struct mtk_gate_regs infra_ao2_cg_regs = {
  23. .set_ofs = 0xa4,
  24. .clr_ofs = 0xa8,
  25. .sta_ofs = 0xac,
  26. };
  27. static const struct mtk_gate_regs infra_ao3_cg_regs = {
  28. .set_ofs = 0xc0,
  29. .clr_ofs = 0xc4,
  30. .sta_ofs = 0xc8,
  31. };
  32. static const struct mtk_gate_regs infra_ao4_cg_regs = {
  33. .set_ofs = 0xe0,
  34. .clr_ofs = 0xe4,
  35. .sta_ofs = 0xe8,
  36. };
  37. #define GATE_INFRA_AO0_FLAGS(_id, _name, _parent, _shift, _flag) \
  38. GATE_MTK_FLAGS(_id, _name, _parent, &infra_ao0_cg_regs, _shift, \
  39. &mtk_clk_gate_ops_setclr, _flag)
  40. #define GATE_INFRA_AO0(_id, _name, _parent, _shift) \
  41. GATE_INFRA_AO0_FLAGS(_id, _name, _parent, _shift, 0)
  42. #define GATE_INFRA_AO1_FLAGS(_id, _name, _parent, _shift, _flag) \
  43. GATE_MTK_FLAGS(_id, _name, _parent, &infra_ao1_cg_regs, _shift, \
  44. &mtk_clk_gate_ops_setclr, _flag)
  45. #define GATE_INFRA_AO1(_id, _name, _parent, _shift) \
  46. GATE_INFRA_AO1_FLAGS(_id, _name, _parent, _shift, 0)
  47. #define GATE_INFRA_AO2(_id, _name, _parent, _shift) \
  48. GATE_MTK(_id, _name, _parent, &infra_ao2_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  49. #define GATE_INFRA_AO2_FLAGS(_id, _name, _parent, _shift, _flag) \
  50. GATE_MTK_FLAGS(_id, _name, _parent, &infra_ao2_cg_regs, _shift, \
  51. &mtk_clk_gate_ops_setclr, _flag)
  52. #define GATE_INFRA_AO3_FLAGS(_id, _name, _parent, _shift, _flag) \
  53. GATE_MTK_FLAGS(_id, _name, _parent, &infra_ao3_cg_regs, _shift, \
  54. &mtk_clk_gate_ops_setclr, _flag)
  55. #define GATE_INFRA_AO3(_id, _name, _parent, _shift) \
  56. GATE_INFRA_AO3_FLAGS(_id, _name, _parent, _shift, 0)
  57. #define GATE_INFRA_AO4_FLAGS(_id, _name, _parent, _shift, _flag) \
  58. GATE_MTK_FLAGS(_id, _name, _parent, &infra_ao4_cg_regs, _shift, \
  59. &mtk_clk_gate_ops_setclr, _flag)
  60. #define GATE_INFRA_AO4(_id, _name, _parent, _shift) \
  61. GATE_INFRA_AO4_FLAGS(_id, _name, _parent, _shift, 0)
  62. static const struct mtk_gate infra_ao_clks[] = {
  63. /* INFRA_AO0 */
  64. GATE_INFRA_AO0(CLK_INFRA_AO_PMIC_TMR, "infra_ao_pmic_tmr", "top_pwrap_ulposc", 0),
  65. GATE_INFRA_AO0(CLK_INFRA_AO_PMIC_AP, "infra_ao_pmic_ap", "top_pwrap_ulposc", 1),
  66. GATE_INFRA_AO0(CLK_INFRA_AO_PMIC_MD, "infra_ao_pmic_md", "top_pwrap_ulposc", 2),
  67. GATE_INFRA_AO0(CLK_INFRA_AO_PMIC_CONN, "infra_ao_pmic_conn", "top_pwrap_ulposc", 3),
  68. /* infra_ao_sej is main clock is for secure engine with JTAG support */
  69. GATE_INFRA_AO0_FLAGS(CLK_INFRA_AO_SEJ, "infra_ao_sej", "top_axi", 5, CLK_IS_CRITICAL),
  70. GATE_INFRA_AO0(CLK_INFRA_AO_APXGPT, "infra_ao_apxgpt", "top_axi", 6),
  71. GATE_INFRA_AO0(CLK_INFRA_AO_GCE, "infra_ao_gce", "top_axi", 8),
  72. GATE_INFRA_AO0(CLK_INFRA_AO_GCE2, "infra_ao_gce2", "top_axi", 9),
  73. GATE_INFRA_AO0(CLK_INFRA_AO_THERM, "infra_ao_therm", "top_axi", 10),
  74. GATE_INFRA_AO0(CLK_INFRA_AO_PWM_HCLK, "infra_ao_pwm_h", "top_axi", 15),
  75. GATE_INFRA_AO0(CLK_INFRA_AO_PWM1, "infra_ao_pwm1", "top_pwm", 16),
  76. GATE_INFRA_AO0(CLK_INFRA_AO_PWM2, "infra_ao_pwm2", "top_pwm", 17),
  77. GATE_INFRA_AO0(CLK_INFRA_AO_PWM3, "infra_ao_pwm3", "top_pwm", 18),
  78. GATE_INFRA_AO0(CLK_INFRA_AO_PWM4, "infra_ao_pwm4", "top_pwm", 19),
  79. GATE_INFRA_AO0(CLK_INFRA_AO_PWM, "infra_ao_pwm", "top_pwm", 21),
  80. GATE_INFRA_AO0(CLK_INFRA_AO_UART0, "infra_ao_uart0", "top_uart", 22),
  81. GATE_INFRA_AO0(CLK_INFRA_AO_UART1, "infra_ao_uart1", "top_uart", 23),
  82. GATE_INFRA_AO0(CLK_INFRA_AO_UART2, "infra_ao_uart2", "top_uart", 24),
  83. GATE_INFRA_AO0(CLK_INFRA_AO_UART3, "infra_ao_uart3", "top_uart", 25),
  84. GATE_INFRA_AO0(CLK_INFRA_AO_UART4, "infra_ao_uart4", "top_uart", 26),
  85. GATE_INFRA_AO0(CLK_INFRA_AO_GCE_26M, "infra_ao_gce_26m", "clk26m", 27),
  86. GATE_INFRA_AO0(CLK_INFRA_AO_CQ_DMA_FPC, "infra_ao_dma", "pad_fpc_ck", 28),
  87. GATE_INFRA_AO0(CLK_INFRA_AO_UART5, "infra_ao_uart5", "top_uart", 29),
  88. /* INFRA_AO1 */
  89. GATE_INFRA_AO1(CLK_INFRA_AO_HDMI_26M, "infra_ao_hdmi_26m", "clk26m", 0),
  90. GATE_INFRA_AO1(CLK_INFRA_AO_SPI0, "infra_ao_spi0", "top_spi", 1),
  91. GATE_INFRA_AO1(CLK_INFRA_AO_MSDC0, "infra_ao_msdc0", "top_msdc5hclk", 2),
  92. GATE_INFRA_AO1(CLK_INFRA_AO_MSDC1, "infra_ao_msdc1", "top_axi", 4),
  93. GATE_INFRA_AO1(CLK_INFRA_AO_MSDC2, "infra_ao_msdc2", "top_axi", 5),
  94. GATE_INFRA_AO1(CLK_INFRA_AO_MSDC0_SRC, "infra_ao_msdc0_clk", "top_msdc50_0", 6),
  95. /* infra_ao_dvfsrc is for internal DVFS usage, should not be handled by Linux. */
  96. GATE_INFRA_AO1_FLAGS(CLK_INFRA_AO_DVFSRC, "infra_ao_dvfsrc",
  97. "clk26m", 7, CLK_IS_CRITICAL),
  98. GATE_INFRA_AO1(CLK_INFRA_AO_TRNG, "infra_ao_trng", "top_axi", 9),
  99. GATE_INFRA_AO1(CLK_INFRA_AO_AUXADC, "infra_ao_auxadc", "clk26m", 10),
  100. GATE_INFRA_AO1(CLK_INFRA_AO_CPUM, "infra_ao_cpum", "top_axi", 11),
  101. GATE_INFRA_AO1(CLK_INFRA_AO_HDMI_32K, "infra_ao_hdmi_32k", "clk32k", 12),
  102. GATE_INFRA_AO1(CLK_INFRA_AO_CEC_66M_HCLK, "infra_ao_cec_66m_hclk", "top_axi", 13),
  103. GATE_INFRA_AO1(CLK_INFRA_AO_PCIE_TL_26M, "infra_ao_pcie_tl_26m", "clk26m", 15),
  104. GATE_INFRA_AO1(CLK_INFRA_AO_MSDC1_SRC, "infra_ao_msdc1_clk", "top_msdc30_1", 16),
  105. GATE_INFRA_AO1(CLK_INFRA_AO_CEC_66M_BCLK, "infra_ao_cec_66m_bclk", "top_axi", 17),
  106. GATE_INFRA_AO1(CLK_INFRA_AO_PCIE_TL_96M, "infra_ao_pcie_tl_96m", "top_tl", 18),
  107. /* infra_ao_dapc is for device access permission control module */
  108. GATE_INFRA_AO1_FLAGS(CLK_INFRA_AO_DEVICE_APC, "infra_ao_dapc",
  109. "top_axi", 20, CLK_IS_CRITICAL),
  110. GATE_INFRA_AO1(CLK_INFRA_AO_ECC_66M_HCLK, "infra_ao_ecc_66m_hclk", "top_axi", 23),
  111. GATE_INFRA_AO1(CLK_INFRA_AO_DEBUGSYS, "infra_ao_debugsys", "top_axi", 24),
  112. GATE_INFRA_AO1(CLK_INFRA_AO_AUDIO, "infra_ao_audio", "top_axi", 25),
  113. GATE_INFRA_AO1(CLK_INFRA_AO_PCIE_TL_32K, "infra_ao_pcie_tl_32k", "clk32k", 26),
  114. GATE_INFRA_AO1(CLK_INFRA_AO_DBG_TRACE, "infra_ao_dbg_trace", "top_axi", 29),
  115. GATE_INFRA_AO1(CLK_INFRA_AO_DRAMC_F26M, "infra_ao_dramc26", "clk26m", 31),
  116. /* INFRA_AO2 */
  117. GATE_INFRA_AO2(CLK_INFRA_AO_IRTX, "infra_ao_irtx", "top_axi", 0),
  118. GATE_INFRA_AO2(CLK_INFRA_AO_DISP_PWM, "infra_ao_disp_pwm", "top_disp_pwm0", 2),
  119. GATE_INFRA_AO2(CLK_INFRA_AO_CLDMA_BCLK, "infra_ao_cldmabclk", "top_axi", 3),
  120. GATE_INFRA_AO2(CLK_INFRA_AO_AUDIO_26M_BCLK, "infra_ao_audio26m", "clk26m", 4),
  121. GATE_INFRA_AO2(CLK_INFRA_AO_SPI1, "infra_ao_spi1", "top_spi", 6),
  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_FLAGS(CLK_INFRA_AO_FSSPM, "infra_ao_fsspm",
  125. "top_sspm", 15, CLK_IS_CRITICAL),
  126. GATE_INFRA_AO2_FLAGS(CLK_INFRA_AO_SSPM_BUS_HCLK, "infra_ao_sspm_hclk",
  127. "top_axi", 17, CLK_IS_CRITICAL),
  128. GATE_INFRA_AO2(CLK_INFRA_AO_APDMA_BCLK, "infra_ao_apdma_bclk", "top_axi", 18),
  129. GATE_INFRA_AO2(CLK_INFRA_AO_SPI4, "infra_ao_spi4", "top_spi", 25),
  130. GATE_INFRA_AO2(CLK_INFRA_AO_SPI5, "infra_ao_spi5", "top_spi", 26),
  131. GATE_INFRA_AO2(CLK_INFRA_AO_CQ_DMA, "infra_ao_cq_dma", "top_axi", 27),
  132. /* INFRA_AO3 */
  133. GATE_INFRA_AO3(CLK_INFRA_AO_MSDC0_SELF, "infra_ao_msdc0sf", "top_msdc50_0", 0),
  134. GATE_INFRA_AO3(CLK_INFRA_AO_MSDC1_SELF, "infra_ao_msdc1sf", "top_msdc50_0", 1),
  135. GATE_INFRA_AO3(CLK_INFRA_AO_MSDC2_SELF, "infra_ao_msdc2sf", "top_msdc50_0", 2),
  136. GATE_INFRA_AO3(CLK_INFRA_AO_I2S_DMA, "infra_ao_i2s_dma", "top_axi", 5),
  137. GATE_INFRA_AO3(CLK_INFRA_AO_AP_MSDC0, "infra_ao_ap_msdc0", "top_msdc50_0", 7),
  138. GATE_INFRA_AO3(CLK_INFRA_AO_MD_MSDC0, "infra_ao_md_msdc0", "top_msdc50_0", 8),
  139. GATE_INFRA_AO3(CLK_INFRA_AO_MSDC30_2, "infra_ao_msdc30_2", "top_msdc30_2", 9),
  140. GATE_INFRA_AO3(CLK_INFRA_AO_GCPU, "infra_ao_gcpu", "top_gcpu", 10),
  141. GATE_INFRA_AO3(CLK_INFRA_AO_PCIE_PERI_26M, "infra_ao_pcie_peri_26m", "clk26m", 15),
  142. GATE_INFRA_AO3(CLK_INFRA_AO_GCPU_66M_BCLK, "infra_ao_gcpu_66m_bclk", "top_axi", 16),
  143. GATE_INFRA_AO3(CLK_INFRA_AO_GCPU_133M_BCLK, "infra_ao_gcpu_133m_bclk", "top_axi", 17),
  144. GATE_INFRA_AO3(CLK_INFRA_AO_DISP_PWM1, "infra_ao_disp_pwm1", "top_disp_pwm1", 20),
  145. GATE_INFRA_AO3(CLK_INFRA_AO_FBIST2FPC, "infra_ao_fbist2fpc", "top_msdc50_0", 24),
  146. /* infra_ao_dapc_sync is for device access permission control module */
  147. GATE_INFRA_AO3_FLAGS(CLK_INFRA_AO_DEVICE_APC_SYNC, "infra_ao_dapc_sync",
  148. "top_axi", 25, CLK_IS_CRITICAL),
  149. GATE_INFRA_AO3(CLK_INFRA_AO_PCIE_P1_PERI_26M, "infra_ao_pcie_p1_peri_26m", "clk26m", 26),
  150. /* INFRA_AO4 */
  151. /* infra_ao_133m_mclk_set/infra_ao_66m_mclk_set are main clocks of peripheral */
  152. GATE_INFRA_AO4_FLAGS(CLK_INFRA_AO_133M_MCLK_CK, "infra_ao_133m_mclk_set",
  153. "top_axi", 0, CLK_IS_CRITICAL),
  154. GATE_INFRA_AO4_FLAGS(CLK_INFRA_AO_66M_MCLK_CK, "infra_ao_66m_mclk_set",
  155. "top_axi", 1, CLK_IS_CRITICAL),
  156. GATE_INFRA_AO4(CLK_INFRA_AO_PCIE_PL_P_250M_P0, "infra_ao_pcie_pl_p_250m_p0",
  157. "pextp_pipe", 7),
  158. GATE_INFRA_AO4(CLK_INFRA_AO_RG_AES_MSDCFDE_CK_0P,
  159. "infra_ao_aes_msdcfde_0p", "top_aes_msdcfde", 18),
  160. };
  161. static u16 infra_ao_rst_ofs[] = {
  162. INFRA_RST0_SET_OFFSET,
  163. INFRA_RST1_SET_OFFSET,
  164. INFRA_RST2_SET_OFFSET,
  165. INFRA_RST3_SET_OFFSET,
  166. INFRA_RST4_SET_OFFSET,
  167. };
  168. static u16 infra_ao_idx_map[] = {
  169. [MT8188_INFRA_RST1_THERMAL_MCU_RST] = 1 * RST_NR_PER_BANK + 2,
  170. [MT8188_INFRA_RST1_THERMAL_CTRL_RST] = 1 * RST_NR_PER_BANK + 4,
  171. [MT8188_INFRA_RST3_PTP_CTRL_RST] = 3 * RST_NR_PER_BANK + 5,
  172. };
  173. static const struct mtk_clk_rst_desc infra_ao_rst_desc = {
  174. .version = MTK_RST_SET_CLR,
  175. .rst_bank_ofs = infra_ao_rst_ofs,
  176. .rst_bank_nr = ARRAY_SIZE(infra_ao_rst_ofs),
  177. .rst_idx_map = infra_ao_idx_map,
  178. .rst_idx_map_nr = ARRAY_SIZE(infra_ao_idx_map),
  179. };
  180. static const struct mtk_clk_desc infra_ao_desc = {
  181. .clks = infra_ao_clks,
  182. .num_clks = ARRAY_SIZE(infra_ao_clks),
  183. .rst_desc = &infra_ao_rst_desc,
  184. };
  185. static const struct of_device_id of_match_clk_mt8188_infra_ao[] = {
  186. { .compatible = "mediatek,mt8188-infracfg-ao", .data = &infra_ao_desc },
  187. { /* sentinel */ }
  188. };
  189. MODULE_DEVICE_TABLE(of, of_match_clk_mt8188_infra_ao);
  190. static struct platform_driver clk_mt8188_infra_ao_drv = {
  191. .probe = mtk_clk_simple_probe,
  192. .remove = mtk_clk_simple_remove,
  193. .driver = {
  194. .name = "clk-mt8188-infra_ao",
  195. .of_match_table = of_match_clk_mt8188_infra_ao,
  196. },
  197. };
  198. module_platform_driver(clk_mt8188_infra_ao_drv);
  199. MODULE_DESCRIPTION("MediaTek MT8188 infracfg clocks driver");
  200. MODULE_LICENSE("GPL");