clk-mt6735-apmixedsys.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2022 Yassine Oudjana <y.oudjana@protonmail.com>
  4. */
  5. #include <linux/clk-provider.h>
  6. #include <linux/platform_device.h>
  7. #include "clk-mtk.h"
  8. #include "clk-pll.h"
  9. #include <dt-bindings/clock/mediatek,mt6735-apmixedsys.h>
  10. #define AP_PLL_CON_5 0x014
  11. #define ARMPLL_CON0 0x200
  12. #define ARMPLL_CON1 0x204
  13. #define ARMPLL_PWR_CON0 0x20c
  14. #define MAINPLL_CON0 0x210
  15. #define MAINPLL_CON1 0x214
  16. #define MAINPLL_PWR_CON0 0x21c
  17. #define UNIVPLL_CON0 0x220
  18. #define UNIVPLL_CON1 0x224
  19. #define UNIVPLL_PWR_CON0 0x22c
  20. #define MMPLL_CON0 0x230
  21. #define MMPLL_CON1 0x234
  22. #define MMPLL_PWR_CON0 0x23c
  23. #define MSDCPLL_CON0 0x240
  24. #define MSDCPLL_CON1 0x244
  25. #define MSDCPLL_PWR_CON0 0x24c
  26. #define VENCPLL_CON0 0x250
  27. #define VENCPLL_CON1 0x254
  28. #define VENCPLL_PWR_CON0 0x25c
  29. #define TVDPLL_CON0 0x260
  30. #define TVDPLL_CON1 0x264
  31. #define TVDPLL_PWR_CON0 0x26c
  32. #define APLL1_CON0 0x270
  33. #define APLL1_CON1 0x274
  34. #define APLL1_CON2 0x278
  35. #define APLL1_PWR_CON0 0x280
  36. #define APLL2_CON0 0x284
  37. #define APLL2_CON1 0x288
  38. #define APLL2_CON2 0x28c
  39. #define APLL2_PWR_CON0 0x294
  40. #define CON0_RST_BAR BIT(24)
  41. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _rst_bar_mask, \
  42. _pd_reg, _pd_shift, _tuner_reg, _tuner_en_reg, \
  43. _tuner_en_bit, _pcw_reg, _pcwbits, _flags) { \
  44. .id = _id, \
  45. .name = _name, \
  46. .parent_name = "clk26m", \
  47. .reg = _reg, \
  48. .pwr_reg = _pwr_reg, \
  49. .en_mask = _en_mask, \
  50. .rst_bar_mask = _rst_bar_mask, \
  51. .pd_reg = _pd_reg, \
  52. .pd_shift = _pd_shift, \
  53. .tuner_reg = _tuner_reg, \
  54. .tuner_en_reg = _tuner_en_reg, \
  55. .tuner_en_bit = _tuner_en_bit, \
  56. .pcw_reg = _pcw_reg, \
  57. .pcw_chg_reg = _pcw_reg, \
  58. .pcwbits = _pcwbits, \
  59. .flags = _flags, \
  60. }
  61. static const struct mtk_pll_data apmixedsys_plls[] = {
  62. PLL(CLK_APMIXED_ARMPLL, "armpll", ARMPLL_CON0, ARMPLL_PWR_CON0, 0x00000001, 0, ARMPLL_CON1, 24, 0, 0, 0, ARMPLL_CON1, 21, PLL_AO),
  63. PLL(CLK_APMIXED_MAINPLL, "mainpll", MAINPLL_CON0, MAINPLL_PWR_CON0, 0xf0000101, CON0_RST_BAR, MAINPLL_CON1, 24, 0, 0, 0, MAINPLL_CON1, 21, HAVE_RST_BAR),
  64. PLL(CLK_APMIXED_UNIVPLL, "univpll", UNIVPLL_CON0, UNIVPLL_PWR_CON0, 0xfc000001, CON0_RST_BAR, UNIVPLL_CON1, 24, 0, 0, 0, UNIVPLL_CON1, 21, HAVE_RST_BAR),
  65. PLL(CLK_APMIXED_MMPLL, "mmpll", MMPLL_CON0, MMPLL_PWR_CON0, 0x00000001, 0, MMPLL_CON1, 24, 0, 0, 0, MMPLL_CON1, 21, 0),
  66. PLL(CLK_APMIXED_MSDCPLL, "msdcpll", MSDCPLL_CON0, MSDCPLL_PWR_CON0, 0x00000001, 0, MSDCPLL_CON1, 24, 0, 0, 0, MSDCPLL_CON1, 21, 0),
  67. PLL(CLK_APMIXED_VENCPLL, "vencpll", VENCPLL_CON0, VENCPLL_PWR_CON0, 0x00000001, CON0_RST_BAR, VENCPLL_CON1, 24, 0, 0, 0, VENCPLL_CON1, 21, HAVE_RST_BAR),
  68. PLL(CLK_APMIXED_TVDPLL, "tvdpll", TVDPLL_CON0, TVDPLL_PWR_CON0, 0x00000001, 0, TVDPLL_CON1, 24, 0, 0, 0, TVDPLL_CON1, 21, 0),
  69. PLL(CLK_APMIXED_APLL1, "apll1", APLL1_CON0, APLL1_PWR_CON0, 0x00000001, 0, APLL1_CON0, 4, APLL1_CON2, AP_PLL_CON_5, 0, APLL1_CON1, 31, 0),
  70. PLL(CLK_APMIXED_APLL2, "apll2", APLL2_CON0, APLL2_PWR_CON0, 0x00000001, 0, APLL2_CON0, 4, APLL2_CON2, AP_PLL_CON_5, 1, APLL2_CON1, 31, 0)
  71. };
  72. static int clk_mt6735_apmixed_probe(struct platform_device *pdev)
  73. {
  74. void __iomem *base;
  75. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  76. struct clk_hw_onecell_data *clk_data;
  77. int ret;
  78. base = devm_ioremap_resource(&pdev->dev, res);
  79. if (IS_ERR(base))
  80. return PTR_ERR(base);
  81. clk_data = mtk_devm_alloc_clk_data(&pdev->dev, ARRAY_SIZE(apmixedsys_plls));
  82. if (!clk_data)
  83. return -ENOMEM;
  84. platform_set_drvdata(pdev, clk_data);
  85. ret = mtk_clk_register_plls(&pdev->dev, apmixedsys_plls,
  86. ARRAY_SIZE(apmixedsys_plls), clk_data);
  87. if (ret) {
  88. dev_err(&pdev->dev, "Failed to register PLLs: %d\n", ret);
  89. return ret;
  90. }
  91. ret = devm_of_clk_add_hw_provider(&pdev->dev, of_clk_hw_onecell_get,
  92. clk_data);
  93. if (ret)
  94. dev_err(&pdev->dev,
  95. "Failed to register clock provider: %d\n", ret);
  96. return ret;
  97. }
  98. static void clk_mt6735_apmixed_remove(struct platform_device *pdev)
  99. {
  100. struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
  101. mtk_clk_unregister_plls(apmixedsys_plls, ARRAY_SIZE(apmixedsys_plls), clk_data);
  102. }
  103. static const struct of_device_id of_match_mt6735_apmixedsys[] = {
  104. { .compatible = "mediatek,mt6735-apmixedsys" },
  105. { /* sentinel */ }
  106. };
  107. MODULE_DEVICE_TABLE(of, of_match_mt6735_apmixedsys);
  108. static struct platform_driver clk_mt6735_apmixedsys = {
  109. .probe = clk_mt6735_apmixed_probe,
  110. .remove = clk_mt6735_apmixed_remove,
  111. .driver = {
  112. .name = "clk-mt6735-apmixedsys",
  113. .of_match_table = of_match_mt6735_apmixedsys,
  114. },
  115. };
  116. module_platform_driver(clk_mt6735_apmixedsys);
  117. MODULE_AUTHOR("Yassine Oudjana <y.oudjana@protonmail.com>");
  118. MODULE_DESCRIPTION("MediaTek MT6735 apmixedsys clock driver");
  119. MODULE_LICENSE("GPL");