clk-mt8192-apmixedsys.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021 MediaTek Inc.
  4. * Chun-Jie Chen <chun-jie.chen@mediatek.com>
  5. * Copyright (c) 2023 Collabora Ltd.
  6. * AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
  7. */
  8. #include <dt-bindings/clock/mt8192-clk.h>
  9. #include <linux/module.h>
  10. #include <linux/platform_device.h>
  11. #include "clk-fhctl.h"
  12. #include "clk-gate.h"
  13. #include "clk-mtk.h"
  14. #include "clk-pll.h"
  15. #include "clk-pllfh.h"
  16. static const struct mtk_gate_regs apmixed_cg_regs = {
  17. .set_ofs = 0x14,
  18. .clr_ofs = 0x14,
  19. .sta_ofs = 0x14,
  20. };
  21. #define GATE_APMIXED(_id, _name, _parent, _shift) \
  22. GATE_MTK(_id, _name, _parent, &apmixed_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  23. static const struct mtk_gate apmixed_clks[] = {
  24. GATE_APMIXED(CLK_APMIXED_MIPID26M, "mipid26m", "clk26m", 16),
  25. };
  26. #define MT8192_PLL_FMAX (3800UL * MHZ)
  27. #define MT8192_PLL_FMIN (1500UL * MHZ)
  28. #define MT8192_INTEGER_BITS 8
  29. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
  30. _rst_bar_mask, _pcwbits, _pd_reg, _pd_shift, \
  31. _tuner_reg, _tuner_en_reg, _tuner_en_bit, \
  32. _pcw_reg, _pcw_shift, _pcw_chg_reg, \
  33. _en_reg, _pll_en_bit) { \
  34. .id = _id, \
  35. .name = _name, \
  36. .reg = _reg, \
  37. .pwr_reg = _pwr_reg, \
  38. .en_mask = _en_mask, \
  39. .flags = _flags, \
  40. .rst_bar_mask = _rst_bar_mask, \
  41. .fmax = MT8192_PLL_FMAX, \
  42. .fmin = MT8192_PLL_FMIN, \
  43. .pcwbits = _pcwbits, \
  44. .pcwibits = MT8192_INTEGER_BITS, \
  45. .pd_reg = _pd_reg, \
  46. .pd_shift = _pd_shift, \
  47. .tuner_reg = _tuner_reg, \
  48. .tuner_en_reg = _tuner_en_reg, \
  49. .tuner_en_bit = _tuner_en_bit, \
  50. .pcw_reg = _pcw_reg, \
  51. .pcw_shift = _pcw_shift, \
  52. .pcw_chg_reg = _pcw_chg_reg, \
  53. .en_reg = _en_reg, \
  54. .pll_en_bit = _pll_en_bit, \
  55. }
  56. #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
  57. _rst_bar_mask, _pcwbits, _pd_reg, _pd_shift, \
  58. _tuner_reg, _tuner_en_reg, _tuner_en_bit, \
  59. _pcw_reg, _pcw_shift) \
  60. PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
  61. _rst_bar_mask, _pcwbits, _pd_reg, _pd_shift, \
  62. _tuner_reg, _tuner_en_reg, _tuner_en_bit, \
  63. _pcw_reg, _pcw_shift, 0, 0, 0)
  64. static const struct mtk_pll_data plls[] = {
  65. PLL_B(CLK_APMIXED_MAINPLL, "mainpll", 0x0340, 0x034c, 0xff000000,
  66. HAVE_RST_BAR, BIT(23), 22, 0x0344, 24, 0, 0, 0, 0x0344, 0),
  67. PLL_B(CLK_APMIXED_UNIVPLL, "univpll", 0x0308, 0x0314, 0xff000000,
  68. HAVE_RST_BAR, BIT(23), 22, 0x030c, 24, 0, 0, 0, 0x030c, 0),
  69. PLL(CLK_APMIXED_USBPLL, "usbpll", 0x03c4, 0x03cc, 0x00000000,
  70. 0, 0, 22, 0x03c4, 24, 0, 0, 0, 0x03c4, 0, 0x03c4, 0x03cc, 2),
  71. PLL_B(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0350, 0x035c, 0x00000000,
  72. 0, 0, 22, 0x0354, 24, 0, 0, 0, 0x0354, 0),
  73. PLL_B(CLK_APMIXED_MMPLL, "mmpll", 0x0360, 0x036c, 0xff000000,
  74. HAVE_RST_BAR, BIT(23), 22, 0x0364, 24, 0, 0, 0, 0x0364, 0),
  75. PLL_B(CLK_APMIXED_ADSPPLL, "adsppll", 0x0370, 0x037c, 0xff000000,
  76. HAVE_RST_BAR, BIT(23), 22, 0x0374, 24, 0, 0, 0, 0x0374, 0),
  77. PLL_B(CLK_APMIXED_MFGPLL, "mfgpll", 0x0268, 0x0274, 0x00000000,
  78. 0, 0, 22, 0x026c, 24, 0, 0, 0, 0x026c, 0),
  79. PLL_B(CLK_APMIXED_TVDPLL, "tvdpll", 0x0380, 0x038c, 0x00000000,
  80. 0, 0, 22, 0x0384, 24, 0, 0, 0, 0x0384, 0),
  81. PLL_B(CLK_APMIXED_APLL1, "apll1", 0x0318, 0x0328, 0x00000000,
  82. 0, 0, 32, 0x031c, 24, 0x0040, 0x000c, 0, 0x0320, 0),
  83. PLL_B(CLK_APMIXED_APLL2, "apll2", 0x032c, 0x033c, 0x00000000,
  84. 0, 0, 32, 0x0330, 24, 0, 0, 0, 0x0334, 0),
  85. };
  86. enum fh_pll_id {
  87. FH_ARMPLL_LL,
  88. FH_ARMPLL_BL0,
  89. FH_ARMPLL_BL1,
  90. FH_ARMPLL_BL2,
  91. FH_ARMPLL_BL3,
  92. FH_CCIPLL,
  93. FH_MFGPLL,
  94. FH_MEMPLL,
  95. FH_MPLL,
  96. FH_MMPLL,
  97. FH_MAINPLL,
  98. FH_MSDCPLL,
  99. FH_ADSPPLL,
  100. FH_APUPLL,
  101. FH_TVDPLL,
  102. FH_NR_FH,
  103. };
  104. #define FH(_pllid, _fhid, _offset) { \
  105. .data = { \
  106. .pll_id = _pllid, \
  107. .fh_id = _fhid, \
  108. .fh_ver = FHCTL_PLLFH_V2, \
  109. .fhx_offset = _offset, \
  110. .dds_mask = GENMASK(21, 0), \
  111. .slope0_value = 0x6003c97, \
  112. .slope1_value = 0x6003c97, \
  113. .sfstrx_en = BIT(2), \
  114. .frddsx_en = BIT(1), \
  115. .fhctlx_en = BIT(0), \
  116. .tgl_org = BIT(31), \
  117. .dvfs_tri = BIT(31), \
  118. .pcwchg = BIT(31), \
  119. .dt_val = 0x0, \
  120. .df_val = 0x9, \
  121. .updnlmt_shft = 16, \
  122. .msk_frddsx_dys = GENMASK(23, 20), \
  123. .msk_frddsx_dts = GENMASK(19, 16), \
  124. }, \
  125. }
  126. static struct mtk_pllfh_data pllfhs[] = {
  127. FH(CLK_APMIXED_MFGPLL, FH_MFGPLL, 0xb4),
  128. FH(CLK_APMIXED_MMPLL, FH_MMPLL, 0xf0),
  129. FH(CLK_APMIXED_MAINPLL, FH_MAINPLL, 0x104),
  130. FH(CLK_APMIXED_MSDCPLL, FH_MSDCPLL, 0x118),
  131. FH(CLK_APMIXED_ADSPPLL, FH_ADSPPLL, 0x12c),
  132. FH(CLK_APMIXED_TVDPLL, FH_TVDPLL, 0x154),
  133. };
  134. static const struct of_device_id of_match_clk_mt8192_apmixed[] = {
  135. { .compatible = "mediatek,mt8192-apmixedsys" },
  136. { /* sentinel */ }
  137. };
  138. MODULE_DEVICE_TABLE(of, of_match_clk_mt8192_apmixed);
  139. static int clk_mt8192_apmixed_probe(struct platform_device *pdev)
  140. {
  141. struct clk_hw_onecell_data *clk_data;
  142. struct device_node *node = pdev->dev.of_node;
  143. const u8 *fhctl_node = "mediatek,mt8192-fhctl";
  144. int r;
  145. clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
  146. if (!clk_data)
  147. return -ENOMEM;
  148. fhctl_parse_dt(fhctl_node, pllfhs, ARRAY_SIZE(pllfhs));
  149. r = mtk_clk_register_pllfhs(&pdev->dev, plls, ARRAY_SIZE(plls),
  150. pllfhs, ARRAY_SIZE(pllfhs), clk_data);
  151. if (r)
  152. goto free_clk_data;
  153. r = mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
  154. ARRAY_SIZE(apmixed_clks), clk_data);
  155. if (r)
  156. goto unregister_plls;
  157. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  158. if (r)
  159. goto unregister_gates;
  160. return r;
  161. unregister_gates:
  162. mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
  163. unregister_plls:
  164. mtk_clk_unregister_pllfhs(plls, ARRAY_SIZE(plls), pllfhs,
  165. ARRAY_SIZE(pllfhs), clk_data);
  166. free_clk_data:
  167. mtk_free_clk_data(clk_data);
  168. return r;
  169. }
  170. static void clk_mt8192_apmixed_remove(struct platform_device *pdev)
  171. {
  172. struct device_node *node = pdev->dev.of_node;
  173. struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
  174. of_clk_del_provider(node);
  175. mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
  176. mtk_clk_unregister_pllfhs(plls, ARRAY_SIZE(plls), pllfhs,
  177. ARRAY_SIZE(pllfhs), clk_data);
  178. mtk_free_clk_data(clk_data);
  179. }
  180. static struct platform_driver clk_mt8192_apmixed_drv = {
  181. .driver = {
  182. .name = "clk-mt8192-apmixed",
  183. .of_match_table = of_match_clk_mt8192_apmixed,
  184. },
  185. .probe = clk_mt8192_apmixed_probe,
  186. .remove = clk_mt8192_apmixed_remove,
  187. };
  188. module_platform_driver(clk_mt8192_apmixed_drv);
  189. MODULE_DESCRIPTION("MediaTek MT8192 apmixed clocks driver");
  190. MODULE_LICENSE("GPL");