clk-pll.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2014 MediaTek Inc.
  4. * Author: James Liao <jamesjj.liao@mediatek.com>
  5. */
  6. #ifndef __DRV_CLK_MTK_PLL_H
  7. #define __DRV_CLK_MTK_PLL_H
  8. #include <linux/clk-provider.h>
  9. #include <linux/types.h>
  10. struct device;
  11. struct mtk_pll_div_table {
  12. u32 div;
  13. unsigned long freq;
  14. };
  15. #define HAVE_RST_BAR BIT(0)
  16. #define PLL_AO BIT(1)
  17. #define PLL_PARENT_EN BIT(2)
  18. #define POSTDIV_MASK GENMASK(2, 0)
  19. struct mtk_pll_data {
  20. int id;
  21. const char *name;
  22. u32 reg;
  23. u32 pwr_reg;
  24. u32 en_mask;
  25. u32 fenc_sta_ofs;
  26. u32 pd_reg;
  27. u32 tuner_reg;
  28. u32 tuner_en_reg;
  29. u8 tuner_en_bit;
  30. int pd_shift;
  31. unsigned int flags;
  32. const struct clk_ops *ops;
  33. u32 rst_bar_mask;
  34. unsigned long fmin;
  35. unsigned long fmax;
  36. int pcwbits;
  37. int pcwibits;
  38. u32 pcw_reg;
  39. int pcw_shift;
  40. u32 pcw_chg_reg;
  41. const struct mtk_pll_div_table *div_table;
  42. const char *parent_name;
  43. u32 en_reg;
  44. u32 en_set_reg;
  45. u32 en_clr_reg;
  46. u8 pll_en_bit; /* Assume 0, indicates BIT(0) by default */
  47. u8 pcw_chg_bit;
  48. u8 fenc_sta_bit;
  49. };
  50. /*
  51. * MediaTek PLLs are configured through their pcw value. The pcw value describes
  52. * a divider in the PLL feedback loop which consists of 7 bits for the integer
  53. * part and the remaining bits (if present) for the fractional part. Also they
  54. * have a 3 bit power-of-two post divider.
  55. */
  56. struct mtk_clk_pll {
  57. struct device *dev;
  58. struct clk_hw hw;
  59. void __iomem *base_addr;
  60. void __iomem *pd_addr;
  61. void __iomem *pwr_addr;
  62. void __iomem *tuner_addr;
  63. void __iomem *tuner_en_addr;
  64. void __iomem *pcw_addr;
  65. void __iomem *pcw_chg_addr;
  66. void __iomem *en_addr;
  67. void __iomem *en_set_addr;
  68. void __iomem *en_clr_addr;
  69. void __iomem *fenc_addr;
  70. const struct mtk_pll_data *data;
  71. };
  72. int mtk_clk_register_plls(struct device *dev, const struct mtk_pll_data *plls,
  73. int num_plls, struct clk_hw_onecell_data *clk_data);
  74. void mtk_clk_unregister_plls(const struct mtk_pll_data *plls, int num_plls,
  75. struct clk_hw_onecell_data *clk_data);
  76. extern const struct clk_ops mtk_pll_ops;
  77. extern const struct clk_ops mtk_pll_fenc_clr_set_ops;
  78. static inline struct mtk_clk_pll *to_mtk_clk_pll(struct clk_hw *hw)
  79. {
  80. return container_of(hw, struct mtk_clk_pll, hw);
  81. }
  82. int mtk_pll_is_prepared(struct clk_hw *hw);
  83. int mtk_pll_prepare(struct clk_hw *hw);
  84. void mtk_pll_unprepare(struct clk_hw *hw);
  85. unsigned long mtk_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate);
  86. void mtk_pll_calc_values(struct mtk_clk_pll *pll, u32 *pcw, u32 *postdiv,
  87. u32 freq, u32 fin);
  88. int mtk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
  89. unsigned long parent_rate);
  90. int mtk_pll_determine_rate(struct clk_hw *hw, struct clk_rate_request *req);
  91. struct clk_hw *mtk_clk_register_pll_ops(struct mtk_clk_pll *pll,
  92. const struct mtk_pll_data *data,
  93. void __iomem *base,
  94. const struct clk_ops *pll_ops);
  95. struct clk_hw *mtk_clk_register_pll(struct device *dev,
  96. const struct mtk_pll_data *data,
  97. void __iomem *base);
  98. void mtk_clk_unregister_pll(struct clk_hw *hw);
  99. __iomem void *mtk_clk_pll_get_base(struct clk_hw *hw,
  100. const struct mtk_pll_data *data);
  101. #endif /* __DRV_CLK_MTK_PLL_H */