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)
16 #define CLK_GATE_SETCLR BIT(0)
17 #define CLK_GATE_SETCLR_INV BIT(1)
18 #define CLK_GATE_NO_SETCLR BIT(2)
19 #define CLK_GATE_NO_SETCLR_INV BIT(3)
20 #define CLK_GATE_MASK GENMASK(3, 0)
22 #define CLK_PARENT_APMIXED BIT(4)
23 #define CLK_PARENT_TOPCKGEN BIT(5)
24 #define CLK_PARENT_MASK GENMASK(5, 4)
26 #define ETHSYS_RST_CTRL_OFS 0x34
28 /* struct mtk_pll_data - hardware-specific PLLs data */
45 * struct mtk_fixed_clk - fixed clocks
47 * @id: index of clocks
48 * @parent: index of parnet clocks
51 struct mtk_fixed_clk {
57 #define FIXED_CLK(_id, _parent, _rate) { \
64 * struct mtk_fixed_factor - fixed multiplier and divider clocks
66 * @id: index of clocks
67 * @parent: index of parnet clocks
70 * @flag: hardware-specific flags
72 struct mtk_fixed_factor {
80 #define FACTOR(_id, _parent, _mult, _div, _flags) { \
89 * struct mtk_composite - aggregate clock of mux, divider and gate clocks
91 * @id: index of clocks
92 * @parent: index of parnet clocks
93 * @mux_reg: hardware-specific mux register
94 * @gate_reg: hardware-specific gate register
95 * @mux_mask: mask to the mux bit field
96 * @mux_shift: shift to the mux bit field
97 * @gate_shift: shift to the gate bit field
98 * @num_parents: number of parent clocks
99 * @flags: hardware-specific flags
101 struct mtk_composite {
107 signed char mux_shift;
108 signed char gate_shift;
109 signed char num_parents;
113 #define MUX_GATE_FLAGS(_id, _parents, _reg, _shift, _width, _gate, \
117 .mux_shift = _shift, \
118 .mux_mask = BIT(_width) - 1, \
120 .gate_shift = _gate, \
121 .parent = _parents, \
122 .num_parents = ARRAY_SIZE(_parents), \
126 #define MUX_GATE(_id, _parents, _reg, _shift, _width, _gate) \
127 MUX_GATE_FLAGS(_id, _parents, _reg, _shift, _width, _gate, 0)
129 #define MUX(_id, _parents, _reg, _shift, _width) { \
132 .mux_shift = _shift, \
133 .mux_mask = BIT(_width) - 1, \
135 .parent = _parents, \
136 .num_parents = ARRAY_SIZE(_parents), \
140 struct mtk_gate_regs {
147 * struct mtk_gate - gate clocks
149 * @id: index of gate clocks
150 * @parent: index of parnet clocks
151 * @regs: hardware-specific mux register
152 * @shift: shift to the gate bit field
153 * @flags: hardware-specific flags
158 const struct mtk_gate_regs *regs;
163 /* struct mtk_clk_tree - clock tree */
164 struct mtk_clk_tree {
165 unsigned long xtal_rate;
166 unsigned long xtal2_rate;
167 const int fdivs_offs;
168 const int muxes_offs;
169 const struct mtk_pll_data *plls;
170 const struct mtk_fixed_clk *fclks;
171 const struct mtk_fixed_factor *fdivs;
172 const struct mtk_composite *muxes;
175 struct mtk_clk_priv {
177 const struct mtk_clk_tree *tree;
182 const struct mtk_clk_tree *tree;
183 const struct mtk_gate *gates;
186 extern const struct clk_ops mtk_clk_apmixedsys_ops;
187 extern const struct clk_ops mtk_clk_topckgen_ops;
188 extern const struct clk_ops mtk_clk_gate_ops;
190 int mtk_common_clk_init(struct udevice *dev,
191 const struct mtk_clk_tree *tree);
192 int mtk_common_clk_gate_init(struct udevice *dev,
193 const struct mtk_clk_tree *tree,
194 const struct mtk_gate *gates);
196 #endif /* __DRV_CLK_MTK_H */