blob: c7dc980861eb844f2e2e5926e1a9105375d7767f [file] [log] [blame]
Ryder Lee0bd7dc72018-11-15 10:07:54 +08001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2018 MediaTek Inc.
4 * Author: Ryder Lee <ryder.lee@mediatek.com>
5 */
6
7#ifndef __DRV_CLK_MTK_H
8#define __DRV_CLK_MTK_H
9
10#define CLK_XTAL 0
11#define MHZ (1000 * 1000)
12
13#define HAVE_RST_BAR BIT(0)
14#define CLK_DOMAIN_SCPSYS BIT(0)
mingming leef62168d2019-12-31 11:29:21 +080015#define CLK_MUX_SETCLR_UPD BIT(1)
Ryder Lee0bd7dc72018-11-15 10:07:54 +080016
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)
22
23#define CLK_PARENT_APMIXED BIT(4)
24#define CLK_PARENT_TOPCKGEN BIT(5)
25#define CLK_PARENT_MASK GENMASK(5, 4)
26
Ryder Lee2d88b5a2019-07-29 22:17:48 +080027#define ETHSYS_HIFSYS_RST_CTRL_OFS 0x34
Weijie Gao2dca3cc2018-12-20 16:12:52 +080028
Ryder Lee0bd7dc72018-11-15 10:07:54 +080029/* struct mtk_pll_data - hardware-specific PLLs data */
30struct mtk_pll_data {
31 const int id;
32 u32 reg;
33 u32 pwr_reg;
34 u32 en_mask;
35 u32 pd_reg;
36 int pd_shift;
37 u32 flags;
38 u32 rst_bar_mask;
39 u64 fmax;
mingming lee0670adb2019-12-31 11:29:22 +080040 u64 fmin;
Ryder Lee0bd7dc72018-11-15 10:07:54 +080041 int pcwbits;
mingming lee0670adb2019-12-31 11:29:22 +080042 int pcwibits;
Ryder Lee0bd7dc72018-11-15 10:07:54 +080043 u32 pcw_reg;
44 int pcw_shift;
mingming lee0670adb2019-12-31 11:29:22 +080045 u32 pcw_chg_reg;
Ryder Lee0bd7dc72018-11-15 10:07:54 +080046};
47
48/**
49 * struct mtk_fixed_clk - fixed clocks
50 *
51 * @id: index of clocks
52 * @parent: index of parnet clocks
53 * @rate: fixed rate
54 */
55struct mtk_fixed_clk {
56 const int id;
57 const int parent;
58 unsigned long rate;
59};
60
61#define FIXED_CLK(_id, _parent, _rate) { \
62 .id = _id, \
63 .parent = _parent, \
64 .rate = _rate, \
65 }
66
67/**
68 * struct mtk_fixed_factor - fixed multiplier and divider clocks
69 *
70 * @id: index of clocks
71 * @parent: index of parnet clocks
72 * @mult: multiplier
73 * @div: divider
74 * @flag: hardware-specific flags
75 */
76struct mtk_fixed_factor {
77 const int id;
78 const int parent;
79 u32 mult;
80 u32 div;
81 u32 flags;
82};
83
84#define FACTOR(_id, _parent, _mult, _div, _flags) { \
85 .id = _id, \
86 .parent = _parent, \
87 .mult = _mult, \
88 .div = _div, \
89 .flags = _flags, \
90 }
91
92/**
93 * struct mtk_composite - aggregate clock of mux, divider and gate clocks
94 *
95 * @id: index of clocks
96 * @parent: index of parnet clocks
97 * @mux_reg: hardware-specific mux register
98 * @gate_reg: hardware-specific gate register
99 * @mux_mask: mask to the mux bit field
100 * @mux_shift: shift to the mux bit field
101 * @gate_shift: shift to the gate bit field
102 * @num_parents: number of parent clocks
103 * @flags: hardware-specific flags
104 */
105struct mtk_composite {
106 const int id;
107 const int *parent;
108 u32 mux_reg;
mingming leef62168d2019-12-31 11:29:21 +0800109 u32 mux_set_reg;
110 u32 mux_clr_reg;
111 u32 upd_reg;
Ryder Lee0bd7dc72018-11-15 10:07:54 +0800112 u32 gate_reg;
113 u32 mux_mask;
114 signed char mux_shift;
mingming leef62168d2019-12-31 11:29:21 +0800115 signed char upd_shift;
Ryder Lee0bd7dc72018-11-15 10:07:54 +0800116 signed char gate_shift;
117 signed char num_parents;
118 u16 flags;
119};
120
121#define MUX_GATE_FLAGS(_id, _parents, _reg, _shift, _width, _gate, \
122 _flags) { \
123 .id = _id, \
124 .mux_reg = _reg, \
125 .mux_shift = _shift, \
126 .mux_mask = BIT(_width) - 1, \
127 .gate_reg = _reg, \
128 .gate_shift = _gate, \
129 .parent = _parents, \
130 .num_parents = ARRAY_SIZE(_parents), \
131 .flags = _flags, \
132 }
133
134#define MUX_GATE(_id, _parents, _reg, _shift, _width, _gate) \
135 MUX_GATE_FLAGS(_id, _parents, _reg, _shift, _width, _gate, 0)
136
137#define MUX(_id, _parents, _reg, _shift, _width) { \
138 .id = _id, \
139 .mux_reg = _reg, \
140 .mux_shift = _shift, \
141 .mux_mask = BIT(_width) - 1, \
142 .gate_shift = -1, \
143 .parent = _parents, \
144 .num_parents = ARRAY_SIZE(_parents), \
145 .flags = 0, \
146 }
147
mingming leef62168d2019-12-31 11:29:21 +0800148#define MUX_CLR_SET_UPD_FLAGS(_id, _parents, _mux_ofs, _mux_set_ofs,\
149 _mux_clr_ofs, _shift, _width, _gate, \
150 _upd_ofs, _upd, _flags) { \
151 .id = _id, \
152 .mux_reg = _mux_ofs, \
153 .mux_set_reg = _mux_set_ofs, \
154 .mux_clr_reg = _mux_clr_ofs, \
155 .upd_reg = _upd_ofs, \
156 .upd_shift = _upd, \
157 .mux_shift = _shift, \
158 .mux_mask = BIT(_width) - 1, \
159 .gate_reg = _mux_ofs, \
160 .gate_shift = _gate, \
161 .parent = _parents, \
162 .num_parents = ARRAY_SIZE(_parents), \
163 .flags = _flags, \
164 }
165
Ryder Lee0bd7dc72018-11-15 10:07:54 +0800166struct mtk_gate_regs {
167 u32 sta_ofs;
168 u32 clr_ofs;
169 u32 set_ofs;
170};
171
172/**
173 * struct mtk_gate - gate clocks
174 *
175 * @id: index of gate clocks
176 * @parent: index of parnet clocks
177 * @regs: hardware-specific mux register
178 * @shift: shift to the gate bit field
179 * @flags: hardware-specific flags
180 */
181struct mtk_gate {
182 const int id;
183 const int parent;
184 const struct mtk_gate_regs *regs;
185 int shift;
186 u32 flags;
187};
188
189/* struct mtk_clk_tree - clock tree */
190struct mtk_clk_tree {
191 unsigned long xtal_rate;
192 unsigned long xtal2_rate;
193 const int fdivs_offs;
194 const int muxes_offs;
195 const struct mtk_pll_data *plls;
196 const struct mtk_fixed_clk *fclks;
197 const struct mtk_fixed_factor *fdivs;
198 const struct mtk_composite *muxes;
199};
200
201struct mtk_clk_priv {
202 void __iomem *base;
203 const struct mtk_clk_tree *tree;
204};
205
206struct mtk_cg_priv {
207 void __iomem *base;
208 const struct mtk_clk_tree *tree;
209 const struct mtk_gate *gates;
210};
211
212extern const struct clk_ops mtk_clk_apmixedsys_ops;
213extern const struct clk_ops mtk_clk_topckgen_ops;
214extern const struct clk_ops mtk_clk_gate_ops;
215
216int mtk_common_clk_init(struct udevice *dev,
217 const struct mtk_clk_tree *tree);
218int mtk_common_clk_gate_init(struct udevice *dev,
219 const struct mtk_clk_tree *tree,
220 const struct mtk_gate *gates);
221
222#endif /* __DRV_CLK_MTK_H */