clk-mt8516-apmixedsys.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2019 MediaTek Inc.
  4. * James Liao <jamesjj.liao@mediatek.com>
  5. * Fabien Parent <fparent@baylibre.com>
  6. *
  7. * Copyright (c) 2023 Collabora, Ltd.
  8. * AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
  9. */
  10. #include <dt-bindings/clock/mt8516-clk.h>
  11. #include <linux/clk.h>
  12. #include <linux/of.h>
  13. #include <linux/platform_device.h>
  14. #include "clk-mtk.h"
  15. #include "clk-pll.h"
  16. #define MT8516_PLL_FMAX (1502UL * MHZ)
  17. #define CON0_MT8516_RST_BAR BIT(27)
  18. #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  19. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  20. _pcw_shift, _div_table) { \
  21. .id = _id, \
  22. .name = _name, \
  23. .reg = _reg, \
  24. .pwr_reg = _pwr_reg, \
  25. .en_mask = _en_mask, \
  26. .flags = _flags, \
  27. .rst_bar_mask = CON0_MT8516_RST_BAR, \
  28. .fmax = MT8516_PLL_FMAX, \
  29. .pcwbits = _pcwbits, \
  30. .pd_reg = _pd_reg, \
  31. .pd_shift = _pd_shift, \
  32. .tuner_reg = _tuner_reg, \
  33. .pcw_reg = _pcw_reg, \
  34. .pcw_shift = _pcw_shift, \
  35. .div_table = _div_table, \
  36. }
  37. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  38. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  39. _pcw_shift) \
  40. PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  41. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
  42. NULL)
  43. static const struct mtk_pll_div_table mmpll_div_table[] = {
  44. { .div = 0, .freq = MT8516_PLL_FMAX },
  45. { .div = 1, .freq = 1000000000 },
  46. { .div = 2, .freq = 604500000 },
  47. { .div = 3, .freq = 253500000 },
  48. { .div = 4, .freq = 126750000 },
  49. { } /* sentinel */
  50. };
  51. static const struct mtk_pll_data plls[] = {
  52. PLL(CLK_APMIXED_ARMPLL, "armpll", 0x0100, 0x0110, 0, 0,
  53. 21, 0x0104, 24, 0, 0x0104, 0),
  54. PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0120, 0x0130, 0,
  55. HAVE_RST_BAR, 21, 0x0124, 24, 0, 0x0124, 0),
  56. PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x0140, 0x0150, 0x30000000,
  57. HAVE_RST_BAR, 7, 0x0144, 24, 0, 0x0144, 0),
  58. PLL_B(CLK_APMIXED_MMPLL, "mmpll", 0x0160, 0x0170, 0, 0,
  59. 21, 0x0164, 24, 0, 0x0164, 0, mmpll_div_table),
  60. PLL(CLK_APMIXED_APLL1, "apll1", 0x0180, 0x0190, 0, 0,
  61. 31, 0x0180, 1, 0x0194, 0x0184, 0),
  62. PLL(CLK_APMIXED_APLL2, "apll2", 0x01A0, 0x01B0, 0, 0,
  63. 31, 0x01A0, 1, 0x01B4, 0x01A4, 0),
  64. };
  65. static int clk_mt8516_apmixed_probe(struct platform_device *pdev)
  66. {
  67. void __iomem *base;
  68. struct clk_hw_onecell_data *clk_data;
  69. struct device_node *node = pdev->dev.of_node;
  70. struct device *dev = &pdev->dev;
  71. int ret;
  72. base = devm_platform_ioremap_resource(pdev, 0);
  73. if (IS_ERR(base))
  74. return PTR_ERR(base);
  75. clk_data = mtk_devm_alloc_clk_data(dev, CLK_APMIXED_NR_CLK);
  76. if (!clk_data)
  77. return -ENOMEM;
  78. ret = mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  79. if (ret)
  80. return ret;
  81. ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  82. if (ret)
  83. goto unregister_plls;
  84. return 0;
  85. unregister_plls:
  86. mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
  87. return ret;
  88. }
  89. static const struct of_device_id of_match_clk_mt8516_apmixed[] = {
  90. { .compatible = "mediatek,mt8516-apmixedsys" },
  91. { /* sentinel */ }
  92. };
  93. MODULE_DEVICE_TABLE(of, of_match_clk_mt8516_apmixed);
  94. static struct platform_driver clk_mt8516_apmixed_drv = {
  95. .probe = clk_mt8516_apmixed_probe,
  96. .driver = {
  97. .name = "clk-mt8516-apmixed",
  98. .of_match_table = of_match_clk_mt8516_apmixed,
  99. },
  100. };
  101. builtin_platform_driver(clk_mt8516_apmixed_drv)
  102. MODULE_DESCRIPTION("MediaTek MT8516 apmixedsys clocks driver");
  103. MODULE_LICENSE("GPL");