clk-mt7986-apmixed.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2021 MediaTek Inc.
  4. * Author: Sam Shih <sam.shih@mediatek.com>
  5. * Author: Wenzhen Yu <wenzhen.yu@mediatek.com>
  6. */
  7. #include <linux/clk-provider.h>
  8. #include <linux/mod_devicetable.h>
  9. #include <linux/platform_device.h>
  10. #include "clk-gate.h"
  11. #include "clk-mtk.h"
  12. #include "clk-mux.h"
  13. #include "clk-pll.h"
  14. #include <dt-bindings/clock/mt7986-clk.h>
  15. #include <linux/clk.h>
  16. #define MT7986_PLL_FMAX (2500UL * MHZ)
  17. #define CON0_MT7986_RST_BAR BIT(27)
  18. #define PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  19. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
  20. _div_table, _parent_name) \
  21. { \
  22. .id = _id, .name = _name, .reg = _reg, .pwr_reg = _pwr_reg, \
  23. .en_mask = _en_mask, .flags = _flags, \
  24. .rst_bar_mask = CON0_MT7986_RST_BAR, .fmax = MT7986_PLL_FMAX, \
  25. .pcwbits = _pcwbits, .pd_reg = _pd_reg, .pd_shift = _pd_shift, \
  26. .tuner_reg = _tuner_reg, .pcw_reg = _pcw_reg, \
  27. .pcw_shift = _pcw_shift, .div_table = _div_table, \
  28. .parent_name = _parent_name, \
  29. }
  30. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, _pd_reg, \
  31. _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift) \
  32. PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  33. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, NULL, \
  34. "clkxtal")
  35. static const struct mtk_pll_data plls[] = {
  36. PLL(CLK_APMIXED_ARMPLL, "armpll", 0x0200, 0x020C, 0x0, PLL_AO, 32,
  37. 0x0200, 4, 0, 0x0204, 0),
  38. PLL(CLK_APMIXED_NET2PLL, "net2pll", 0x0210, 0x021C, 0x0, 0, 32,
  39. 0x0210, 4, 0, 0x0214, 0),
  40. PLL(CLK_APMIXED_MMPLL, "mmpll", 0x0220, 0x022C, 0x0, 0, 32,
  41. 0x0220, 4, 0, 0x0224, 0),
  42. PLL(CLK_APMIXED_SGMPLL, "sgmpll", 0x0230, 0x023c, 0x0, 0, 32,
  43. 0x0230, 4, 0, 0x0234, 0),
  44. PLL(CLK_APMIXED_WEDMCUPLL, "wedmcupll", 0x0240, 0x024c, 0x0, 0,
  45. 32, 0x0240, 4, 0, 0x0244, 0),
  46. PLL(CLK_APMIXED_NET1PLL, "net1pll", 0x0250, 0x025c, 0x0, 0, 32,
  47. 0x0250, 4, 0, 0x0254, 0),
  48. PLL(CLK_APMIXED_MPLL, "mpll", 0x0260, 0x0270, 0x0, 0, 32, 0x0260,
  49. 4, 0, 0x0264, 0),
  50. PLL(CLK_APMIXED_APLL2, "apll2", 0x0278, 0x0288, 0x0, 0, 32,
  51. 0x0278, 4, 0, 0x027c, 0),
  52. };
  53. static const struct of_device_id of_match_clk_mt7986_apmixed[] = {
  54. { .compatible = "mediatek,mt7986-apmixedsys", },
  55. { }
  56. };
  57. MODULE_DEVICE_TABLE(of, of_match_clk_mt7986_apmixed);
  58. static int clk_mt7986_apmixed_probe(struct platform_device *pdev)
  59. {
  60. struct clk_hw_onecell_data *clk_data;
  61. struct device_node *node = pdev->dev.of_node;
  62. int r;
  63. clk_data = mtk_alloc_clk_data(ARRAY_SIZE(plls));
  64. if (!clk_data)
  65. return -ENOMEM;
  66. mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  67. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  68. if (r) {
  69. pr_err("%s(): could not register clock provider: %d\n",
  70. __func__, r);
  71. goto free_apmixed_data;
  72. }
  73. return r;
  74. free_apmixed_data:
  75. mtk_free_clk_data(clk_data);
  76. return r;
  77. }
  78. static struct platform_driver clk_mt7986_apmixed_drv = {
  79. .probe = clk_mt7986_apmixed_probe,
  80. .driver = {
  81. .name = "clk-mt7986-apmixed",
  82. .of_match_table = of_match_clk_mt7986_apmixed,
  83. },
  84. };
  85. builtin_platform_driver(clk_mt7986_apmixed_drv);
  86. MODULE_DESCRIPTION("MediaTek MT7986 apmixedsys clocks driver");
  87. MODULE_LICENSE("GPL");