1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2018 MediaTek Inc.
4 * Author: Ryder Lee <ryder.lee@mediatek.com>
7 #ifndef __DRV_CLK_MTK_H
8 #define __DRV_CLK_MTK_H
10 #include <linux/bitops.h>
12 #define MHZ (1000 * 1000)
14 /* flags in struct mtk_clk_tree */
16 /* clk id == 0 doesn't mean it's xtal clk */
17 #define CLK_BYPASS_XTAL BIT(0)
19 #define HAVE_RST_BAR BIT(0)
20 #define CLK_DOMAIN_SCPSYS BIT(0)
21 #define CLK_MUX_SETCLR_UPD BIT(1)
23 #define CLK_GATE_SETCLR BIT(0)
24 #define CLK_GATE_SETCLR_INV BIT(1)
25 #define CLK_GATE_NO_SETCLR BIT(2)
26 #define CLK_GATE_NO_SETCLR_INV BIT(3)
27 #define CLK_GATE_MASK GENMASK(3, 0)
29 #define CLK_PARENT_APMIXED BIT(4)
30 #define CLK_PARENT_TOPCKGEN BIT(5)
31 #define CLK_PARENT_INFRASYS BIT(6)
32 #define CLK_PARENT_MASK GENMASK(6, 4)
34 #define ETHSYS_HIFSYS_RST_CTRL_OFS 0x34
36 /* struct mtk_pll_data - hardware-specific PLLs data */
56 * struct mtk_fixed_clk - fixed clocks
58 * @id: index of clocks
59 * @parent: index of parnet clocks
62 struct mtk_fixed_clk {
68 #define FIXED_CLK(_id, _parent, _rate) { \
75 * struct mtk_fixed_factor - fixed multiplier and divider clocks
77 * @id: index of clocks
78 * @parent: index of parnet clocks
81 * @flag: hardware-specific flags
83 struct mtk_fixed_factor {
91 #define FACTOR(_id, _parent, _mult, _div, _flags) { \
100 * struct mtk_composite - aggregate clock of mux, divider and gate clocks
102 * @id: index of clocks
103 * @parent: index of parnet clocks
104 * @mux_reg: hardware-specific mux register
105 * @gate_reg: hardware-specific gate register
106 * @mux_mask: mask to the mux bit field
107 * @mux_shift: shift to the mux bit field
108 * @gate_shift: shift to the gate bit field
109 * @num_parents: number of parent clocks
110 * @flags: hardware-specific flags
112 struct mtk_composite {
121 signed char mux_shift;
122 signed char upd_shift;
123 signed char gate_shift;
124 signed char num_parents;
128 #define MUX_GATE_FLAGS(_id, _parents, _reg, _shift, _width, _gate, \
132 .mux_shift = _shift, \
133 .mux_mask = BIT(_width) - 1, \
135 .gate_shift = _gate, \
136 .parent = _parents, \
137 .num_parents = ARRAY_SIZE(_parents), \
141 #define MUX_GATE(_id, _parents, _reg, _shift, _width, _gate) \
142 MUX_GATE_FLAGS(_id, _parents, _reg, _shift, _width, _gate, 0)
144 #define MUX(_id, _parents, _reg, _shift, _width) { \
147 .mux_shift = _shift, \
148 .mux_mask = BIT(_width) - 1, \
150 .parent = _parents, \
151 .num_parents = ARRAY_SIZE(_parents), \
155 #define MUX_CLR_SET_UPD_FLAGS(_id, _parents, _mux_ofs, _mux_set_ofs,\
156 _mux_clr_ofs, _shift, _width, _gate, \
157 _upd_ofs, _upd, _flags) { \
159 .mux_reg = _mux_ofs, \
160 .mux_set_reg = _mux_set_ofs, \
161 .mux_clr_reg = _mux_clr_ofs, \
162 .upd_reg = _upd_ofs, \
164 .mux_shift = _shift, \
165 .mux_mask = BIT(_width) - 1, \
166 .gate_reg = _mux_ofs, \
167 .gate_shift = _gate, \
168 .parent = _parents, \
169 .num_parents = ARRAY_SIZE(_parents), \
173 struct mtk_gate_regs {
180 * struct mtk_gate - gate clocks
182 * @id: index of gate clocks
183 * @parent: index of parnet clocks
184 * @regs: hardware-specific mux register
185 * @shift: shift to the gate bit field
186 * @flags: hardware-specific flags
191 const struct mtk_gate_regs *regs;
196 /* struct mtk_clk_tree - clock tree */
197 struct mtk_clk_tree {
198 unsigned long xtal_rate;
199 unsigned long xtal2_rate;
200 const int fdivs_offs;
201 const int muxes_offs;
202 const struct mtk_pll_data *plls;
203 const struct mtk_fixed_clk *fclks;
204 const struct mtk_fixed_factor *fdivs;
205 const struct mtk_composite *muxes;
209 struct mtk_clk_priv {
210 struct udevice *parent;
212 const struct mtk_clk_tree *tree;
216 struct udevice *parent;
218 const struct mtk_clk_tree *tree;
219 const struct mtk_gate *gates;
222 extern const struct clk_ops mtk_clk_apmixedsys_ops;
223 extern const struct clk_ops mtk_clk_topckgen_ops;
224 extern const struct clk_ops mtk_clk_infrasys_ops;
225 extern const struct clk_ops mtk_clk_gate_ops;
227 int mtk_common_clk_init(struct udevice *dev,
228 const struct mtk_clk_tree *tree);
229 int mtk_common_clk_gate_init(struct udevice *dev,
230 const struct mtk_clk_tree *tree,
231 const struct mtk_gate *gates);
233 #endif /* __DRV_CLK_MTK_H */