clk-mt8188-apmixedsys.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 <linux/mod_devicetable.h>
  8. #include <linux/platform_device.h>
  9. #include "clk-gate.h"
  10. #include "clk-mtk.h"
  11. #include "clk-pll.h"
  12. static const struct mtk_gate_regs apmixed_cg_regs = {
  13. .set_ofs = 0x8,
  14. .clr_ofs = 0x8,
  15. .sta_ofs = 0x8,
  16. };
  17. #define GATE_APMIXED(_id, _name, _parent, _shift) \
  18. GATE_MTK(_id, _name, _parent, &apmixed_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  19. static const struct mtk_gate apmixed_clks[] = {
  20. GATE_APMIXED(CLK_APMIXED_PLL_SSUSB26M_EN, "pll_ssusb26m_en", "clk26m", 1),
  21. };
  22. #define MT8188_PLL_FMAX (3800UL * MHZ)
  23. #define MT8188_PLL_FMIN (1500UL * MHZ)
  24. #define MT8188_INTEGER_BITS 8
  25. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
  26. _rst_bar_mask, _pcwbits, _pd_reg, _pd_shift, \
  27. _tuner_reg, _tuner_en_reg, _tuner_en_bit, \
  28. _pcw_reg, _pcw_shift, _pcw_chg_reg, \
  29. _en_reg, _pll_en_bit) { \
  30. .id = _id, \
  31. .name = _name, \
  32. .reg = _reg, \
  33. .pwr_reg = _pwr_reg, \
  34. .en_mask = _en_mask, \
  35. .flags = _flags, \
  36. .rst_bar_mask = _rst_bar_mask, \
  37. .fmax = MT8188_PLL_FMAX, \
  38. .fmin = MT8188_PLL_FMIN, \
  39. .pcwbits = _pcwbits, \
  40. .pcwibits = MT8188_INTEGER_BITS, \
  41. .pd_reg = _pd_reg, \
  42. .pd_shift = _pd_shift, \
  43. .tuner_reg = _tuner_reg, \
  44. .tuner_en_reg = _tuner_en_reg, \
  45. .tuner_en_bit = _tuner_en_bit, \
  46. .pcw_reg = _pcw_reg, \
  47. .pcw_shift = _pcw_shift, \
  48. .pcw_chg_reg = _pcw_chg_reg, \
  49. .en_reg = _en_reg, \
  50. .pll_en_bit = _pll_en_bit, \
  51. }
  52. static const struct mtk_pll_data plls[] = {
  53. PLL(CLK_APMIXED_ETHPLL, "ethpll", 0x044C, 0x0458, 0,
  54. 0, 0, 22, 0x0450, 24, 0, 0, 0, 0x0450, 0, 0, 0, 9),
  55. PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0514, 0x0520, 0,
  56. 0, 0, 22, 0x0518, 24, 0, 0, 0, 0x0518, 0, 0, 0, 9),
  57. PLL(CLK_APMIXED_TVDPLL1, "tvdpll1", 0x0524, 0x0530, 0,
  58. 0, 0, 22, 0x0528, 24, 0, 0, 0, 0x0528, 0, 0, 0, 9),
  59. PLL(CLK_APMIXED_TVDPLL2, "tvdpll2", 0x0534, 0x0540, 0,
  60. 0, 0, 22, 0x0538, 24, 0, 0, 0, 0x0538, 0, 0, 0, 9),
  61. PLL(CLK_APMIXED_MMPLL, "mmpll", 0x0544, 0x0550, 0xff000000,
  62. HAVE_RST_BAR, BIT(23), 22, 0x0548, 24, 0, 0, 0, 0x0548, 0, 0, 0, 9),
  63. PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x045C, 0x0468, 0xff000000,
  64. HAVE_RST_BAR, BIT(23), 22, 0x0460, 24, 0, 0, 0, 0x0460, 0, 0, 0, 9),
  65. PLL(CLK_APMIXED_IMGPLL, "imgpll", 0x0554, 0x0560, 0,
  66. 0, 0, 22, 0x0558, 24, 0, 0, 0, 0x0558, 0, 0, 0, 9),
  67. PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x0504, 0x0510, 0xff000000,
  68. HAVE_RST_BAR, BIT(23), 22, 0x0508, 24, 0, 0, 0, 0x0508, 0, 0, 0, 9),
  69. PLL(CLK_APMIXED_ADSPPLL, "adsppll", 0x042C, 0x0438, 0,
  70. 0, 0, 22, 0x0430, 24, 0, 0, 0, 0x0430, 0, 0, 0, 9),
  71. PLL(CLK_APMIXED_APLL1, "apll1", 0x0304, 0x0314, 0,
  72. 0, 0, 32, 0x0308, 24, 0x0034, 0x0000, 12, 0x030C, 0, 0, 0, 9),
  73. PLL(CLK_APMIXED_APLL2, "apll2", 0x0318, 0x0328, 0,
  74. 0, 0, 32, 0x031C, 24, 0x0038, 0x0000, 13, 0x0320, 0, 0, 0, 9),
  75. PLL(CLK_APMIXED_APLL3, "apll3", 0x032C, 0x033C, 0,
  76. 0, 0, 32, 0x0330, 24, 0x003C, 0x0000, 14, 0x0334, 0, 0, 0, 9),
  77. PLL(CLK_APMIXED_APLL4, "apll4", 0x0404, 0x0414, 0,
  78. 0, 0, 32, 0x0408, 24, 0x0040, 0x0000, 15, 0x040C, 0, 0, 0, 9),
  79. PLL(CLK_APMIXED_APLL5, "apll5", 0x0418, 0x0428, 0,
  80. 0, 0, 32, 0x041C, 24, 0x0044, 0x0000, 16, 0x0420, 0, 0, 0, 9),
  81. PLL(CLK_APMIXED_MFGPLL, "mfgpll", 0x0340, 0x034C, 0,
  82. 0, 0, 22, 0x0344, 24, 0, 0, 0, 0x0344, 0, 0, 0, 9),
  83. };
  84. static const struct of_device_id of_match_clk_mt8188_apmixed[] = {
  85. { .compatible = "mediatek,mt8188-apmixedsys" },
  86. { /* sentinel */ }
  87. };
  88. MODULE_DEVICE_TABLE(of, of_match_clk_mt8188_apmixed);
  89. static int clk_mt8188_apmixed_probe(struct platform_device *pdev)
  90. {
  91. struct clk_hw_onecell_data *clk_data;
  92. struct device_node *node = pdev->dev.of_node;
  93. int r;
  94. clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
  95. if (!clk_data)
  96. return -ENOMEM;
  97. r = mtk_clk_register_plls(&pdev->dev, plls, ARRAY_SIZE(plls), clk_data);
  98. if (r)
  99. goto free_apmixed_data;
  100. r = mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
  101. ARRAY_SIZE(apmixed_clks), clk_data);
  102. if (r)
  103. goto unregister_plls;
  104. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  105. if (r)
  106. goto unregister_gates;
  107. platform_set_drvdata(pdev, clk_data);
  108. return 0;
  109. unregister_gates:
  110. mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
  111. unregister_plls:
  112. mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
  113. free_apmixed_data:
  114. mtk_free_clk_data(clk_data);
  115. return r;
  116. }
  117. static void clk_mt8188_apmixed_remove(struct platform_device *pdev)
  118. {
  119. struct device_node *node = pdev->dev.of_node;
  120. struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
  121. of_clk_del_provider(node);
  122. mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
  123. mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
  124. mtk_free_clk_data(clk_data);
  125. }
  126. static struct platform_driver clk_mt8188_apmixed_drv = {
  127. .probe = clk_mt8188_apmixed_probe,
  128. .remove = clk_mt8188_apmixed_remove,
  129. .driver = {
  130. .name = "clk-mt8188-apmixed",
  131. .of_match_table = of_match_clk_mt8188_apmixed,
  132. },
  133. };
  134. module_platform_driver(clk_mt8188_apmixed_drv);
  135. MODULE_DESCRIPTION("MediaTek MT8188 apmixedsys clocks driver");
  136. MODULE_LICENSE("GPL");