clk-mt7988-apmixed.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2023 MediaTek Inc.
  4. * Author: Sam Shih <sam.shih@mediatek.com>
  5. * Author: Xiufeng Li <Xiufeng.Li@mediatek.com>
  6. */
  7. #include <linux/clk-provider.h>
  8. #include <linux/of.h>
  9. #include <linux/of_address.h>
  10. #include <linux/of_device.h>
  11. #include <linux/platform_device.h>
  12. #include "clk-mtk.h"
  13. #include "clk-gate.h"
  14. #include "clk-mux.h"
  15. #include "clk-pll.h"
  16. #include <dt-bindings/clock/mediatek,mt7988-clk.h>
  17. #define MT7988_PLL_FMAX (2500UL * MHZ)
  18. #define MT7988_PCW_CHG_BIT 2
  19. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _rst_bar_mask, _pcwbits, _pd_reg, \
  20. _pd_shift, _tuner_reg, _tuner_en_reg, _tuner_en_bit, _pcw_reg, _pcw_shift, \
  21. _pcw_chg_reg) \
  22. { \
  23. .id = _id, \
  24. .name = _name, \
  25. .reg = _reg, \
  26. .pwr_reg = _pwr_reg, \
  27. .en_mask = _en_mask, \
  28. .flags = _flags, \
  29. .rst_bar_mask = BIT(_rst_bar_mask), \
  30. .fmax = MT7988_PLL_FMAX, \
  31. .pcwbits = _pcwbits, \
  32. .pd_reg = _pd_reg, \
  33. .pd_shift = _pd_shift, \
  34. .tuner_reg = _tuner_reg, \
  35. .tuner_en_reg = _tuner_en_reg, \
  36. .tuner_en_bit = _tuner_en_bit, \
  37. .pcw_reg = _pcw_reg, \
  38. .pcw_shift = _pcw_shift, \
  39. .pcw_chg_reg = _pcw_chg_reg, \
  40. .pcw_chg_bit = MT7988_PCW_CHG_BIT, \
  41. .parent_name = "clkxtal", \
  42. }
  43. static const struct mtk_pll_data plls[] = {
  44. PLL(CLK_APMIXED_NETSYSPLL, "netsyspll", 0x0104, 0x0110, 0x00000001, 0, 0, 32, 0x0104, 4, 0,
  45. 0, 0, 0x0108, 0, 0x0104),
  46. PLL(CLK_APMIXED_MPLL, "mpll", 0x0114, 0x0120, 0xff000001, HAVE_RST_BAR, 23, 32, 0x0114, 4,
  47. 0, 0, 0, 0x0118, 0, 0x0114),
  48. PLL(CLK_APMIXED_MMPLL, "mmpll", 0x0124, 0x0130, 0xff000001, HAVE_RST_BAR, 23, 32, 0x0124, 4,
  49. 0, 0, 0, 0x0128, 0, 0x0124),
  50. PLL(CLK_APMIXED_APLL2, "apll2", 0x0134, 0x0140, 0x00000001, 0, 0, 32, 0x0134, 4, 0x0704,
  51. 0x0700, 1, 0x0138, 0, 0x0134),
  52. PLL(CLK_APMIXED_NET1PLL, "net1pll", 0x0144, 0x0150, 0xff000001, HAVE_RST_BAR, 23, 32,
  53. 0x0144, 4, 0, 0, 0, 0x0148, 0, 0x0144),
  54. PLL(CLK_APMIXED_NET2PLL, "net2pll", 0x0154, 0x0160, 0xff000001, (HAVE_RST_BAR | PLL_AO), 23,
  55. 32, 0x0154, 4, 0, 0, 0, 0x0158, 0, 0x0154),
  56. PLL(CLK_APMIXED_WEDMCUPLL, "wedmcupll", 0x0164, 0x0170, 0x00000001, 0, 0, 32, 0x0164, 4, 0,
  57. 0, 0, 0x0168, 0, 0x0164),
  58. PLL(CLK_APMIXED_SGMPLL, "sgmpll", 0x0174, 0x0180, 0x00000001, 0, 0, 32, 0x0174, 4, 0, 0, 0,
  59. 0x0178, 0, 0x0174),
  60. PLL(CLK_APMIXED_ARM_B, "arm_b", 0x0204, 0x0210, 0xff000001, (HAVE_RST_BAR | PLL_AO), 23, 32,
  61. 0x0204, 4, 0, 0, 0, 0x0208, 0, 0x0204),
  62. PLL(CLK_APMIXED_CCIPLL2_B, "ccipll2_b", 0x0214, 0x0220, 0xff000001, HAVE_RST_BAR, 23, 32,
  63. 0x0214, 4, 0, 0, 0, 0x0218, 0, 0x0214),
  64. PLL(CLK_APMIXED_USXGMIIPLL, "usxgmiipll", 0x0304, 0x0310, 0xff000001, HAVE_RST_BAR, 23, 32,
  65. 0x0304, 4, 0, 0, 0, 0x0308, 0, 0x0304),
  66. PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0314, 0x0320, 0x00000001, 0, 0, 32, 0x0314, 4, 0, 0,
  67. 0, 0x0318, 0, 0x0314),
  68. };
  69. static const struct of_device_id of_match_clk_mt7988_apmixed[] = {
  70. { .compatible = "mediatek,mt7988-apmixedsys" },
  71. { /* sentinel */ }
  72. };
  73. static int clk_mt7988_apmixed_probe(struct platform_device *pdev)
  74. {
  75. struct clk_hw_onecell_data *clk_data;
  76. struct device_node *node = pdev->dev.of_node;
  77. int r;
  78. clk_data = mtk_alloc_clk_data(ARRAY_SIZE(plls));
  79. if (!clk_data)
  80. return -ENOMEM;
  81. r = mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  82. if (r)
  83. goto free_apmixed_data;
  84. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  85. if (r)
  86. goto unregister_plls;
  87. return r;
  88. unregister_plls:
  89. mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
  90. free_apmixed_data:
  91. mtk_free_clk_data(clk_data);
  92. return r;
  93. }
  94. static struct platform_driver clk_mt7988_apmixed_drv = {
  95. .probe = clk_mt7988_apmixed_probe,
  96. .driver = {
  97. .name = "clk-mt7988-apmixed",
  98. .of_match_table = of_match_clk_mt7988_apmixed,
  99. },
  100. };
  101. builtin_platform_driver(clk_mt7988_apmixed_drv);
  102. MODULE_DESCRIPTION("MediaTek MT7988 apmixedsys clocks driver");
  103. MODULE_LICENSE("GPL");