1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2014 MediaTek Inc.
4 * Author: James Liao <jamesjj.liao@mediatek.com>
7 #ifndef __DRV_CLK_MTK_PLL_H
8 #define __DRV_CLK_MTK_PLL_H
10 #include <linux/clk-provider.h>
11 #include <linux/types.h>
14 struct clk_hw_onecell_data;
17 struct mtk_pll_div_table {
22 #define HAVE_RST_BAR BIT(0)
24 #define POSTDIV_MASK GENMASK(2, 0)
38 const struct clk_ops *ops;
47 const struct mtk_pll_div_table *div_table;
48 const char *parent_name;
50 u8 pll_en_bit; /* Assume 0, indicates BIT(0) by default */
55 * MediaTek PLLs are configured through their pcw value. The pcw value describes
56 * a divider in the PLL feedback loop which consists of 7 bits for the integer
57 * part and the remaining bits (if present) for the fractional part. Also they
58 * have a 3 bit power-of-two post divider.
63 void __iomem *base_addr;
64 void __iomem *pd_addr;
65 void __iomem *pwr_addr;
66 void __iomem *tuner_addr;
67 void __iomem *tuner_en_addr;
68 void __iomem *pcw_addr;
69 void __iomem *pcw_chg_addr;
70 void __iomem *en_addr;
71 const struct mtk_pll_data *data;
74 int mtk_clk_register_plls(struct device_node *node,
75 const struct mtk_pll_data *plls, int num_plls,
76 struct clk_hw_onecell_data *clk_data);
77 void mtk_clk_unregister_plls(const struct mtk_pll_data *plls, int num_plls,
78 struct clk_hw_onecell_data *clk_data);
80 extern const struct clk_ops mtk_pll_ops;
82 static inline struct mtk_clk_pll *to_mtk_clk_pll(struct clk_hw *hw)
84 return container_of(hw, struct mtk_clk_pll, hw);
87 int mtk_pll_is_prepared(struct clk_hw *hw);
89 int mtk_pll_prepare(struct clk_hw *hw);
91 void mtk_pll_unprepare(struct clk_hw *hw);
93 unsigned long mtk_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate);
95 void mtk_pll_calc_values(struct mtk_clk_pll *pll, u32 *pcw, u32 *postdiv,
97 int mtk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
98 unsigned long parent_rate);
99 long mtk_pll_round_rate(struct clk_hw *hw, unsigned long rate,
100 unsigned long *prate);
102 struct clk_hw *mtk_clk_register_pll_ops(struct mtk_clk_pll *pll,
103 const struct mtk_pll_data *data,
105 const struct clk_ops *pll_ops);
106 struct clk_hw *mtk_clk_register_pll(const struct mtk_pll_data *data,
108 void mtk_clk_unregister_pll(struct clk_hw *hw);
110 __iomem void *mtk_clk_pll_get_base(struct clk_hw *hw,
111 const struct mtk_pll_data *data);
113 #endif /* __DRV_CLK_MTK_PLL_H */