clk-mt8167-apmixedsys.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2020 MediaTek Inc.
  4. * Copyright (c) 2020 BayLibre, SAS
  5. * Copyright (c) 2023 Collabora, Ltd.
  6. */
  7. #include <dt-bindings/clock/mt8167-clk.h>
  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. static DEFINE_SPINLOCK(mt8167_apmixed_clk_lock);
  14. #define MT8167_PLL_FMAX (2500UL * MHZ)
  15. #define CON0_MT8167_RST_BAR BIT(27)
  16. #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  17. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  18. _pcw_shift, _div_table) { \
  19. .id = _id, \
  20. .name = _name, \
  21. .reg = _reg, \
  22. .pwr_reg = _pwr_reg, \
  23. .en_mask = _en_mask, \
  24. .flags = _flags, \
  25. .rst_bar_mask = CON0_MT8167_RST_BAR, \
  26. .fmax = MT8167_PLL_FMAX, \
  27. .pcwbits = _pcwbits, \
  28. .pd_reg = _pd_reg, \
  29. .pd_shift = _pd_shift, \
  30. .tuner_reg = _tuner_reg, \
  31. .pcw_reg = _pcw_reg, \
  32. .pcw_shift = _pcw_shift, \
  33. .div_table = _div_table, \
  34. }
  35. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  36. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  37. _pcw_shift) \
  38. PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  39. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
  40. NULL)
  41. static const struct mtk_pll_div_table mmpll_div_table[] = {
  42. { .div = 0, .freq = MT8167_PLL_FMAX },
  43. { .div = 1, .freq = 1000000000 },
  44. { .div = 2, .freq = 604500000 },
  45. { .div = 3, .freq = 253500000 },
  46. { .div = 4, .freq = 126750000 },
  47. { /* sentinel */ }
  48. };
  49. static const struct mtk_pll_data plls[] = {
  50. PLL(CLK_APMIXED_ARMPLL, "armpll", 0x0100, 0x0110, 0, 0,
  51. 21, 0x0104, 24, 0, 0x0104, 0),
  52. PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0120, 0x0130, 0,
  53. HAVE_RST_BAR, 21, 0x0124, 24, 0, 0x0124, 0),
  54. PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x0140, 0x0150, 0x30000000,
  55. HAVE_RST_BAR, 7, 0x0144, 24, 0, 0x0144, 0),
  56. PLL_B(CLK_APMIXED_MMPLL, "mmpll", 0x0160, 0x0170, 0, 0,
  57. 21, 0x0164, 24, 0, 0x0164, 0, mmpll_div_table),
  58. PLL(CLK_APMIXED_APLL1, "apll1", 0x0180, 0x0190, 0, 0,
  59. 31, 0x0180, 1, 0x0194, 0x0184, 0),
  60. PLL(CLK_APMIXED_APLL2, "apll2", 0x01A0, 0x01B0, 0, 0,
  61. 31, 0x01A0, 1, 0x01B4, 0x01A4, 0),
  62. PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x01C0, 0x01D0, 0, 0,
  63. 21, 0x01C4, 24, 0, 0x01C4, 0),
  64. PLL(CLK_APMIXED_LVDSPLL, "lvdspll", 0x01E0, 0x01F0, 0, 0,
  65. 21, 0x01E4, 24, 0, 0x01E4, 0),
  66. };
  67. #define DIV_ADJ_FLAG(_id, _name, _parent, _reg, _shift, _width, _flag) { \
  68. .id = _id, \
  69. .name = _name, \
  70. .parent_name = _parent, \
  71. .div_reg = _reg, \
  72. .div_shift = _shift, \
  73. .div_width = _width, \
  74. .clk_divider_flags = _flag, \
  75. }
  76. static const struct mtk_clk_divider adj_divs[] = {
  77. DIV_ADJ_FLAG(CLK_APMIXED_HDMI_REF, "hdmi_ref", "tvdpll",
  78. 0x1c4, 24, 3, CLK_DIVIDER_POWER_OF_TWO),
  79. };
  80. static int clk_mt8167_apmixed_probe(struct platform_device *pdev)
  81. {
  82. void __iomem *base;
  83. struct clk_hw_onecell_data *clk_data;
  84. struct device_node *node = pdev->dev.of_node;
  85. struct device *dev = &pdev->dev;
  86. int ret;
  87. base = devm_platform_ioremap_resource(pdev, 0);
  88. if (IS_ERR(base))
  89. return PTR_ERR(base);
  90. clk_data = mtk_devm_alloc_clk_data(dev, MT8167_CLK_APMIXED_NR_CLK);
  91. if (!clk_data)
  92. return -ENOMEM;
  93. ret = mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  94. if (ret)
  95. return ret;
  96. ret = mtk_clk_register_dividers(dev, adj_divs, ARRAY_SIZE(adj_divs), base,
  97. &mt8167_apmixed_clk_lock, clk_data);
  98. if (ret)
  99. goto unregister_plls;
  100. ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  101. if (ret)
  102. goto unregister_dividers;
  103. return 0;
  104. unregister_dividers:
  105. mtk_clk_unregister_dividers(adj_divs, ARRAY_SIZE(adj_divs), clk_data);
  106. unregister_plls:
  107. mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
  108. return ret;
  109. }
  110. static const struct of_device_id of_match_clk_mt8167_apmixed[] = {
  111. { .compatible = "mediatek,mt8167-apmixedsys" },
  112. { /* sentinel */ }
  113. };
  114. MODULE_DEVICE_TABLE(of, of_match_clk_mt8167_apmixed);
  115. static struct platform_driver clk_mt8167_apmixed_drv = {
  116. .probe = clk_mt8167_apmixed_probe,
  117. .driver = {
  118. .name = "clk-mt8167-apmixed",
  119. .of_match_table = of_match_clk_mt8167_apmixed,
  120. },
  121. };
  122. builtin_platform_driver(clk_mt8167_apmixed_drv)
  123. MODULE_DESCRIPTION("MediaTek MT8167 apmixedsys clocks driver");
  124. MODULE_LICENSE("GPL");