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
11 #define MHZ (1000 * 1000)
13 #define HAVE_RST_BAR BIT(0)
14 #define CLK_DOMAIN_SCPSYS BIT(0)
15 #define CLK_MUX_SETCLR_UPD BIT(1)
17 #define CLK_GATE_SETCLR BIT(0)
18 #define CLK_GATE_SETCLR_INV BIT(1)
19 #define CLK_GATE_NO_SETCLR BIT(2)
20 #define CLK_GATE_NO_SETCLR_INV BIT(3)
21 #define CLK_GATE_MASK GENMASK(3, 0)
23 #define CLK_PARENT_APMIXED BIT(4)
24 #define CLK_PARENT_TOPCKGEN BIT(5)
25 #define CLK_PARENT_MASK GENMASK(5, 4)
27 #define ETHSYS_HIFSYS_RST_CTRL_OFS 0x34
29 /* struct mtk_pll_data - hardware-specific PLLs data */
46 * struct mtk_fixed_clk - fixed clocks
48 * @id: index of clocks
49 * @parent: index of parnet clocks
52 struct mtk_fixed_clk {
58 #define FIXED_CLK(_id, _parent, _rate) { \
65 * struct mtk_fixed_factor - fixed multiplier and divider clocks
67 * @id: index of clocks
68 * @parent: index of parnet clocks
71 * @flag: hardware-specific flags
73 struct mtk_fixed_factor {
81 #define FACTOR(_id, _parent, _mult, _div, _flags) { \
90 * struct mtk_composite - aggregate clock of mux, divider and gate clocks
92 * @id: index of clocks
93 * @parent: index of parnet clocks
94 * @mux_reg: hardware-specific mux register
95 * @gate_reg: hardware-specific gate register
96 * @mux_mask: mask to the mux bit field
97 * @mux_shift: shift to the mux bit field
98 * @gate_shift: shift to the gate bit field
99 * @num_parents: number of parent clocks
100 * @flags: hardware-specific flags
102 struct mtk_composite {
111 signed char mux_shift;
112 signed char upd_shift;
113 signed char gate_shift;
114 signed char num_parents;
118 #define MUX_GATE_FLAGS(_id, _parents, _reg, _shift, _width, _gate, \
122 .mux_shift = _shift, \
123 .mux_mask = BIT(_width) - 1, \
125 .gate_shift = _gate, \
126 .parent = _parents, \
127 .num_parents = ARRAY_SIZE(_parents), \
131 #define MUX_GATE(_id, _parents, _reg, _shift, _width, _gate) \
132 MUX_GATE_FLAGS(_id, _parents, _reg, _shift, _width, _gate, 0)
134 #define MUX(_id, _parents, _reg, _shift, _width) { \
137 .mux_shift = _shift, \
138 .mux_mask = BIT(_width) - 1, \
140 .parent = _parents, \
141 .num_parents = ARRAY_SIZE(_parents), \
145 #define MUX_CLR_SET_UPD_FLAGS(_id, _parents, _mux_ofs, _mux_set_ofs,\
146 _mux_clr_ofs, _shift, _width, _gate, \
147 _upd_ofs, _upd, _flags) { \
149 .mux_reg = _mux_ofs, \
150 .mux_set_reg = _mux_set_ofs, \
151 .mux_clr_reg = _mux_clr_ofs, \
152 .upd_reg = _upd_ofs, \
154 .mux_shift = _shift, \
155 .mux_mask = BIT(_width) - 1, \
156 .gate_reg = _mux_ofs, \
157 .gate_shift = _gate, \
158 .parent = _parents, \
159 .num_parents = ARRAY_SIZE(_parents), \
163 struct mtk_gate_regs {
170 * struct mtk_gate - gate clocks
172 * @id: index of gate clocks
173 * @parent: index of parnet clocks
174 * @regs: hardware-specific mux register
175 * @shift: shift to the gate bit field
176 * @flags: hardware-specific flags
181 const struct mtk_gate_regs *regs;
186 /* struct mtk_clk_tree - clock tree */
187 struct mtk_clk_tree {
188 unsigned long xtal_rate;
189 unsigned long xtal2_rate;
190 const int fdivs_offs;
191 const int muxes_offs;
192 const struct mtk_pll_data *plls;
193 const struct mtk_fixed_clk *fclks;
194 const struct mtk_fixed_factor *fdivs;
195 const struct mtk_composite *muxes;
198 struct mtk_clk_priv {
200 const struct mtk_clk_tree *tree;
205 const struct mtk_clk_tree *tree;
206 const struct mtk_gate *gates;
209 extern const struct clk_ops mtk_clk_apmixedsys_ops;
210 extern const struct clk_ops mtk_clk_topckgen_ops;
211 extern const struct clk_ops mtk_clk_gate_ops;
213 int mtk_common_clk_init(struct udevice *dev,
214 const struct mtk_clk_tree *tree);
215 int mtk_common_clk_gate_init(struct udevice *dev,
216 const struct mtk_clk_tree *tree,
217 const struct mtk_gate *gates);
219 #endif /* __DRV_CLK_MTK_H */