clk-mt7622-apmixedsys.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017 MediaTek Inc.
  4. * Copyright (c) 2023 Collabora, Ltd.
  5. * AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
  6. */
  7. #include <dt-bindings/clock/mt7622-clk.h>
  8. #include <linux/clk.h>
  9. #include <linux/of.h>
  10. #include <linux/platform_device.h>
  11. #include "clk-gate.h"
  12. #include "clk-mtk.h"
  13. #include "clk-pll.h"
  14. #define MT7622_PLL_FMAX (2500UL * MHZ)
  15. #define CON0_MT7622_RST_BAR BIT(27)
  16. #define PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits,\
  17. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  18. _pcw_shift, _div_table, _parent_name) { \
  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_MT7622_RST_BAR, \
  26. .fmax = MT7622_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. .parent_name = _parent_name, \
  35. }
  36. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  37. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  38. _pcw_shift) \
  39. PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits,\
  40. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
  41. NULL, "clkxtal")
  42. static const struct mtk_gate_regs apmixed_cg_regs = {
  43. .set_ofs = 0x8,
  44. .clr_ofs = 0x8,
  45. .sta_ofs = 0x8,
  46. };
  47. #define GATE_APMIXED_AO(_id, _name, _parent, _shift) \
  48. GATE_MTK_FLAGS(_id, _name, _parent, &apmixed_cg_regs, _shift, \
  49. &mtk_clk_gate_ops_no_setclr_inv, CLK_IS_CRITICAL)
  50. static const struct mtk_pll_data plls[] = {
  51. PLL(CLK_APMIXED_ARMPLL, "armpll", 0x0200, 0x020C, 0,
  52. PLL_AO, 21, 0x0204, 24, 0, 0x0204, 0),
  53. PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0210, 0x021C, 0,
  54. HAVE_RST_BAR, 21, 0x0214, 24, 0, 0x0214, 0),
  55. PLL(CLK_APMIXED_UNIV2PLL, "univ2pll", 0x0220, 0x022C, 0,
  56. HAVE_RST_BAR, 7, 0x0224, 24, 0, 0x0224, 14),
  57. PLL(CLK_APMIXED_ETH1PLL, "eth1pll", 0x0300, 0x0310, 0,
  58. 0, 21, 0x0300, 1, 0, 0x0304, 0),
  59. PLL(CLK_APMIXED_ETH2PLL, "eth2pll", 0x0314, 0x0320, 0,
  60. 0, 21, 0x0314, 1, 0, 0x0318, 0),
  61. PLL(CLK_APMIXED_AUD1PLL, "aud1pll", 0x0324, 0x0330, 0,
  62. 0, 31, 0x0324, 1, 0, 0x0328, 0),
  63. PLL(CLK_APMIXED_AUD2PLL, "aud2pll", 0x0334, 0x0340, 0,
  64. 0, 31, 0x0334, 1, 0, 0x0338, 0),
  65. PLL(CLK_APMIXED_TRGPLL, "trgpll", 0x0344, 0x0354, 0,
  66. 0, 21, 0x0344, 1, 0, 0x0348, 0),
  67. PLL(CLK_APMIXED_SGMIPLL, "sgmipll", 0x0358, 0x0368, 0,
  68. 0, 21, 0x0358, 1, 0, 0x035C, 0),
  69. };
  70. static const struct mtk_gate apmixed_clks[] = {
  71. GATE_APMIXED_AO(CLK_APMIXED_MAIN_CORE_EN, "main_core_en", "mainpll", 5),
  72. };
  73. static int clk_mt7622_apmixed_probe(struct platform_device *pdev)
  74. {
  75. void __iomem *base;
  76. struct clk_hw_onecell_data *clk_data;
  77. struct device_node *node = pdev->dev.of_node;
  78. struct device *dev = &pdev->dev;
  79. int ret;
  80. base = devm_platform_ioremap_resource(pdev, 0);
  81. if (IS_ERR(base))
  82. return PTR_ERR(base);
  83. clk_data = mtk_devm_alloc_clk_data(dev, CLK_APMIXED_NR_CLK);
  84. if (!clk_data)
  85. return -ENOMEM;
  86. ret = mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  87. if (ret)
  88. return ret;
  89. ret = mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
  90. ARRAY_SIZE(apmixed_clks), clk_data);
  91. if (ret)
  92. goto unregister_plls;
  93. ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  94. if (ret)
  95. goto unregister_gates;
  96. return 0;
  97. unregister_gates:
  98. mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
  99. unregister_plls:
  100. mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
  101. return ret;
  102. }
  103. static void clk_mt7622_apmixed_remove(struct platform_device *pdev)
  104. {
  105. struct device_node *node = pdev->dev.of_node;
  106. struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
  107. of_clk_del_provider(node);
  108. mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
  109. mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
  110. }
  111. static const struct of_device_id of_match_clk_mt7622_apmixed[] = {
  112. { .compatible = "mediatek,mt7622-apmixedsys" },
  113. { /* sentinel */ }
  114. };
  115. MODULE_DEVICE_TABLE(of, of_match_clk_mt7622_apmixed);
  116. static struct platform_driver clk_mt7622_apmixed_drv = {
  117. .probe = clk_mt7622_apmixed_probe,
  118. .remove = clk_mt7622_apmixed_remove,
  119. .driver = {
  120. .name = "clk-mt7622-apmixed",
  121. .of_match_table = of_match_clk_mt7622_apmixed,
  122. },
  123. };
  124. module_platform_driver(clk_mt7622_apmixed_drv)
  125. MODULE_DESCRIPTION("MediaTek MT7622 apmixedsys clocks driver");
  126. MODULE_LICENSE("GPL");