clk-mt2712-apmixedsys.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017 MediaTek Inc.
  4. * Weiyi Lu <weiyi.lu@mediatek.com>
  5. * Copyright (c) 2023 Collabora Ltd.
  6. * AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
  7. */
  8. #include <linux/clk.h>
  9. #include <linux/of.h>
  10. #include <linux/platform_device.h>
  11. #include "clk-pll.h"
  12. #include "clk-mtk.h"
  13. #include <dt-bindings/clock/mt2712-clk.h>
  14. #define MT2712_PLL_FMAX (3000UL * MHZ)
  15. #define CON0_MT2712_RST_BAR BIT(24)
  16. #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  17. _pd_reg, _pd_shift, _tuner_reg, _tuner_en_reg, \
  18. _tuner_en_bit, _pcw_reg, _pcw_shift, \
  19. _div_table) { \
  20. .id = _id, \
  21. .name = _name, \
  22. .reg = _reg, \
  23. .pwr_reg = _pwr_reg, \
  24. .en_mask = _en_mask, \
  25. .flags = _flags, \
  26. .rst_bar_mask = CON0_MT2712_RST_BAR, \
  27. .fmax = MT2712_PLL_FMAX, \
  28. .pcwbits = _pcwbits, \
  29. .pd_reg = _pd_reg, \
  30. .pd_shift = _pd_shift, \
  31. .tuner_reg = _tuner_reg, \
  32. .tuner_en_reg = _tuner_en_reg, \
  33. .tuner_en_bit = _tuner_en_bit, \
  34. .pcw_reg = _pcw_reg, \
  35. .pcw_shift = _pcw_shift, \
  36. .div_table = _div_table, \
  37. }
  38. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  39. _pd_reg, _pd_shift, _tuner_reg, _tuner_en_reg, \
  40. _tuner_en_bit, _pcw_reg, _pcw_shift) \
  41. PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
  42. _pcwbits, _pd_reg, _pd_shift, _tuner_reg, \
  43. _tuner_en_reg, _tuner_en_bit, _pcw_reg, \
  44. _pcw_shift, NULL)
  45. static const struct mtk_pll_div_table armca35pll_div_table[] = {
  46. { .div = 0, .freq = MT2712_PLL_FMAX },
  47. { .div = 1, .freq = 1202500000 },
  48. { .div = 2, .freq = 500500000 },
  49. { .div = 3, .freq = 315250000 },
  50. { .div = 4, .freq = 157625000 },
  51. { /* sentinel */ }
  52. };
  53. static const struct mtk_pll_div_table armca72pll_div_table[] = {
  54. { .div = 0, .freq = MT2712_PLL_FMAX },
  55. { .div = 1, .freq = 994500000 },
  56. { .div = 2, .freq = 520000000 },
  57. { .div = 3, .freq = 315250000 },
  58. { .div = 4, .freq = 157625000 },
  59. { /* sentinel */ }
  60. };
  61. static const struct mtk_pll_div_table mmpll_div_table[] = {
  62. { .div = 0, .freq = MT2712_PLL_FMAX },
  63. { .div = 1, .freq = 1001000000 },
  64. { .div = 2, .freq = 601250000 },
  65. { .div = 3, .freq = 250250000 },
  66. { .div = 4, .freq = 125125000 },
  67. { /* sentinel */ }
  68. };
  69. static const struct mtk_pll_data plls[] = {
  70. PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0230, 0x023C, 0xf0000100,
  71. HAVE_RST_BAR, 31, 0x0230, 4, 0, 0, 0, 0x0234, 0),
  72. PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x0240, 0x024C, 0xfe000100,
  73. HAVE_RST_BAR, 31, 0x0240, 4, 0, 0, 0, 0x0244, 0),
  74. PLL(CLK_APMIXED_VCODECPLL, "vcodecpll", 0x0320, 0x032C, 0xc0000100,
  75. 0, 31, 0x0320, 4, 0, 0, 0, 0x0324, 0),
  76. PLL(CLK_APMIXED_VENCPLL, "vencpll", 0x0280, 0x028C, 0x00000100,
  77. 0, 31, 0x0280, 4, 0, 0, 0, 0x0284, 0),
  78. PLL(CLK_APMIXED_APLL1, "apll1", 0x0330, 0x0340, 0x00000100,
  79. 0, 31, 0x0330, 4, 0x0338, 0x0014, 0, 0x0334, 0),
  80. PLL(CLK_APMIXED_APLL2, "apll2", 0x0350, 0x0360, 0x00000100,
  81. 0, 31, 0x0350, 4, 0x0358, 0x0014, 1, 0x0354, 0),
  82. PLL(CLK_APMIXED_LVDSPLL, "lvdspll", 0x0370, 0x037c, 0x00000100,
  83. 0, 31, 0x0370, 4, 0, 0, 0, 0x0374, 0),
  84. PLL(CLK_APMIXED_LVDSPLL2, "lvdspll2", 0x0390, 0x039C, 0x00000100,
  85. 0, 31, 0x0390, 4, 0, 0, 0, 0x0394, 0),
  86. PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0270, 0x027C, 0x00000100,
  87. 0, 31, 0x0270, 4, 0, 0, 0, 0x0274, 0),
  88. PLL(CLK_APMIXED_MSDCPLL2, "msdcpll2", 0x0410, 0x041C, 0x00000100,
  89. 0, 31, 0x0410, 4, 0, 0, 0, 0x0414, 0),
  90. PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x0290, 0x029C, 0xc0000100,
  91. 0, 31, 0x0290, 4, 0, 0, 0, 0x0294, 0),
  92. PLL_B(CLK_APMIXED_MMPLL, "mmpll", 0x0250, 0x0260, 0x00000100,
  93. 0, 31, 0x0250, 4, 0, 0, 0, 0x0254, 0, mmpll_div_table),
  94. PLL_B(CLK_APMIXED_ARMCA35PLL, "armca35pll", 0x0100, 0x0110, 0xf0000100,
  95. HAVE_RST_BAR, 31, 0x0100, 4, 0, 0, 0, 0x0104, 0, armca35pll_div_table),
  96. PLL_B(CLK_APMIXED_ARMCA72PLL, "armca72pll", 0x0210, 0x0220, 0x00000100,
  97. 0, 31, 0x0210, 4, 0, 0, 0, 0x0214, 0, armca72pll_div_table),
  98. PLL(CLK_APMIXED_ETHERPLL, "etherpll", 0x0300, 0x030C, 0xc0000100,
  99. 0, 31, 0x0300, 4, 0, 0, 0, 0x0304, 0),
  100. };
  101. static int clk_mt2712_apmixed_probe(struct platform_device *pdev)
  102. {
  103. struct clk_hw_onecell_data *clk_data;
  104. int r;
  105. struct device_node *node = pdev->dev.of_node;
  106. clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
  107. if (!clk_data)
  108. return -ENOMEM;
  109. r = mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  110. if (r)
  111. goto free_clk_data;
  112. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  113. if (r) {
  114. dev_err(&pdev->dev, "Cannot register clock provider: %d\n", r);
  115. goto unregister_plls;
  116. }
  117. return 0;
  118. unregister_plls:
  119. mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
  120. free_clk_data:
  121. mtk_free_clk_data(clk_data);
  122. return r;
  123. }
  124. static void clk_mt2712_apmixed_remove(struct platform_device *pdev)
  125. {
  126. struct device_node *node = pdev->dev.of_node;
  127. struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
  128. of_clk_del_provider(node);
  129. mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
  130. mtk_free_clk_data(clk_data);
  131. }
  132. static const struct of_device_id of_match_clk_mt2712_apmixed[] = {
  133. { .compatible = "mediatek,mt2712-apmixedsys" },
  134. { /* sentinel */ }
  135. };
  136. MODULE_DEVICE_TABLE(of, of_match_clk_mt2712_apmixed);
  137. static struct platform_driver clk_mt2712_apmixed_drv = {
  138. .probe = clk_mt2712_apmixed_probe,
  139. .remove = clk_mt2712_apmixed_remove,
  140. .driver = {
  141. .name = "clk-mt2712-apmixed",
  142. .of_match_table = of_match_clk_mt2712_apmixed,
  143. },
  144. };
  145. module_platform_driver(clk_mt2712_apmixed_drv)
  146. MODULE_DESCRIPTION("MediaTek MT2712 apmixedsys clocks driver");
  147. MODULE_LICENSE("GPL");