1*e37e8677SEmmanuel Vadot /*-
2*e37e8677SEmmanuel Vadot * Copyright (c) 2017 Emmanuel Vadot <manu@freebsd.org>
3*e37e8677SEmmanuel Vadot *
4*e37e8677SEmmanuel Vadot * Redistribution and use in source and binary forms, with or without
5*e37e8677SEmmanuel Vadot * modification, are permitted provided that the following conditions
6*e37e8677SEmmanuel Vadot * are met:
7*e37e8677SEmmanuel Vadot * 1. Redistributions of source code must retain the above copyright
8*e37e8677SEmmanuel Vadot * notice, this list of conditions and the following disclaimer.
9*e37e8677SEmmanuel Vadot * 2. Redistributions in binary form must reproduce the above copyright
10*e37e8677SEmmanuel Vadot * notice, this list of conditions and the following disclaimer in the
11*e37e8677SEmmanuel Vadot * documentation and/or other materials provided with the distribution.
12*e37e8677SEmmanuel Vadot *
13*e37e8677SEmmanuel Vadot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14*e37e8677SEmmanuel Vadot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15*e37e8677SEmmanuel Vadot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16*e37e8677SEmmanuel Vadot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17*e37e8677SEmmanuel Vadot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18*e37e8677SEmmanuel Vadot * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19*e37e8677SEmmanuel Vadot * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
20*e37e8677SEmmanuel Vadot * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21*e37e8677SEmmanuel Vadot * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22*e37e8677SEmmanuel Vadot * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23*e37e8677SEmmanuel Vadot * SUCH DAMAGE.
24*e37e8677SEmmanuel Vadot */
25*e37e8677SEmmanuel Vadot
26*e37e8677SEmmanuel Vadot #ifndef __AW_CLK_H__
27*e37e8677SEmmanuel Vadot #define __AW_CLK_H__
28*e37e8677SEmmanuel Vadot
29*e37e8677SEmmanuel Vadot /*
30*e37e8677SEmmanuel Vadot Allwinner clocks formula :
31*e37e8677SEmmanuel Vadot
32*e37e8677SEmmanuel Vadot PLLs:
33*e37e8677SEmmanuel Vadot
34*e37e8677SEmmanuel Vadot (24MHz*N*K)/(M*P)
35*e37e8677SEmmanuel Vadot (24MHz*N)/(M*P)
36*e37e8677SEmmanuel Vadot (24MHz*N*2)/M
37*e37e8677SEmmanuel Vadot (24MHz*N)/M
38*e37e8677SEmmanuel Vadot (24MHz*N*K)/M
39*e37e8677SEmmanuel Vadot (24MHz*N*K/2)
40*e37e8677SEmmanuel Vadot (24MHz*N)/M
41*e37e8677SEmmanuel Vadot (24MHz*N*K/2)
42*e37e8677SEmmanuel Vadot (24MHz*N)/M
43*e37e8677SEmmanuel Vadot
44*e37e8677SEmmanuel Vadot Periph clocks:
45*e37e8677SEmmanuel Vadot
46*e37e8677SEmmanuel Vadot Clock Source/Divider N/Divider M
47*e37e8677SEmmanuel Vadot Clock Source/Divider N/Divider M/2
48*e37e8677SEmmanuel Vadot Clock Source*N/(Divider M+1)/(Divider P+1)
49*e37e8677SEmmanuel Vadot
50*e37e8677SEmmanuel Vadot */
51*e37e8677SEmmanuel Vadot
52*e37e8677SEmmanuel Vadot struct aw_clk_init {
53*e37e8677SEmmanuel Vadot const char *name;
54*e37e8677SEmmanuel Vadot const char *parent_name;
55*e37e8677SEmmanuel Vadot uint64_t default_freq;
56*e37e8677SEmmanuel Vadot bool enable;
57*e37e8677SEmmanuel Vadot };
58*e37e8677SEmmanuel Vadot
59*e37e8677SEmmanuel Vadot #define AW_CLK_HAS_GATE 0x0001
60*e37e8677SEmmanuel Vadot #define AW_CLK_HAS_LOCK 0x0002
61*e37e8677SEmmanuel Vadot #define AW_CLK_HAS_MUX 0x0004
62*e37e8677SEmmanuel Vadot #define AW_CLK_REPARENT 0x0008
63*e37e8677SEmmanuel Vadot #define AW_CLK_SCALE_CHANGE 0x0010
64*e37e8677SEmmanuel Vadot #define AW_CLK_HAS_UPDATE 0x0040
65*e37e8677SEmmanuel Vadot #define AW_CLK_HAS_PREDIV 0x0080
66*e37e8677SEmmanuel Vadot #define AW_CLK_SET_PARENT 0x0100
67*e37e8677SEmmanuel Vadot
68*e37e8677SEmmanuel Vadot #define AW_CLK_FACTOR_POWER_OF_TWO 0x0001
69*e37e8677SEmmanuel Vadot #define AW_CLK_FACTOR_ZERO_BASED 0x0002
70*e37e8677SEmmanuel Vadot #define AW_CLK_FACTOR_HAS_COND 0x0004
71*e37e8677SEmmanuel Vadot #define AW_CLK_FACTOR_FIXED 0x0008
72*e37e8677SEmmanuel Vadot #define AW_CLK_FACTOR_ZERO_IS_ONE 0x0010
73*e37e8677SEmmanuel Vadot #define AW_CLK_FACTOR_MIN_VALUE 0x0020
74*e37e8677SEmmanuel Vadot #define AW_CLK_FACTOR_MAX_VALUE 0x0040
75*e37e8677SEmmanuel Vadot
76*e37e8677SEmmanuel Vadot struct aw_clk_factor {
77*e37e8677SEmmanuel Vadot uint32_t shift; /* Shift bits for the factor */
78*e37e8677SEmmanuel Vadot uint32_t mask; /* Mask to get the factor, will be override by the clk methods */
79*e37e8677SEmmanuel Vadot uint32_t width; /* Number of bits for the factor */
80*e37e8677SEmmanuel Vadot uint32_t value; /* Fixed value, depends on AW_CLK_FACTOR_FIXED */
81*e37e8677SEmmanuel Vadot
82*e37e8677SEmmanuel Vadot uint32_t cond_shift;
83*e37e8677SEmmanuel Vadot uint32_t cond_mask;
84*e37e8677SEmmanuel Vadot uint32_t cond_width;
85*e37e8677SEmmanuel Vadot uint32_t cond_value;
86*e37e8677SEmmanuel Vadot
87*e37e8677SEmmanuel Vadot uint32_t min_value;
88*e37e8677SEmmanuel Vadot uint32_t max_value;
89*e37e8677SEmmanuel Vadot
90*e37e8677SEmmanuel Vadot uint32_t flags; /* Flags */
91*e37e8677SEmmanuel Vadot };
92*e37e8677SEmmanuel Vadot
93*e37e8677SEmmanuel Vadot struct aw_clk_frac {
94*e37e8677SEmmanuel Vadot uint64_t freq0;
95*e37e8677SEmmanuel Vadot uint64_t freq1;
96*e37e8677SEmmanuel Vadot uint32_t mode_sel;
97*e37e8677SEmmanuel Vadot uint32_t freq_sel;
98*e37e8677SEmmanuel Vadot };
99*e37e8677SEmmanuel Vadot
100*e37e8677SEmmanuel Vadot static inline uint32_t
aw_clk_get_factor(uint32_t val,struct aw_clk_factor * factor)101*e37e8677SEmmanuel Vadot aw_clk_get_factor(uint32_t val, struct aw_clk_factor *factor)
102*e37e8677SEmmanuel Vadot {
103*e37e8677SEmmanuel Vadot uint32_t factor_val;
104*e37e8677SEmmanuel Vadot uint32_t cond;
105*e37e8677SEmmanuel Vadot
106*e37e8677SEmmanuel Vadot if (factor->flags & AW_CLK_FACTOR_HAS_COND) {
107*e37e8677SEmmanuel Vadot cond = (val & factor->cond_mask) >> factor->cond_shift;
108*e37e8677SEmmanuel Vadot if (cond != factor->cond_value)
109*e37e8677SEmmanuel Vadot return (1);
110*e37e8677SEmmanuel Vadot }
111*e37e8677SEmmanuel Vadot
112*e37e8677SEmmanuel Vadot if (factor->flags & AW_CLK_FACTOR_FIXED)
113*e37e8677SEmmanuel Vadot return (factor->value);
114*e37e8677SEmmanuel Vadot
115*e37e8677SEmmanuel Vadot factor_val = (val & factor->mask) >> factor->shift;
116*e37e8677SEmmanuel Vadot if (factor_val == 0 && (factor->flags & AW_CLK_FACTOR_ZERO_IS_ONE))
117*e37e8677SEmmanuel Vadot factor_val = 1;
118*e37e8677SEmmanuel Vadot
119*e37e8677SEmmanuel Vadot if (factor->flags & AW_CLK_FACTOR_POWER_OF_TWO)
120*e37e8677SEmmanuel Vadot factor_val = 1 << factor_val;
121*e37e8677SEmmanuel Vadot else if (!(factor->flags & AW_CLK_FACTOR_ZERO_BASED))
122*e37e8677SEmmanuel Vadot factor_val += 1;
123*e37e8677SEmmanuel Vadot
124*e37e8677SEmmanuel Vadot return (factor_val);
125*e37e8677SEmmanuel Vadot }
126*e37e8677SEmmanuel Vadot
127*e37e8677SEmmanuel Vadot static inline uint32_t
aw_clk_factor_get_max(struct aw_clk_factor * factor)128*e37e8677SEmmanuel Vadot aw_clk_factor_get_max(struct aw_clk_factor *factor)
129*e37e8677SEmmanuel Vadot {
130*e37e8677SEmmanuel Vadot uint32_t max;
131*e37e8677SEmmanuel Vadot
132*e37e8677SEmmanuel Vadot if (factor->flags & AW_CLK_FACTOR_FIXED)
133*e37e8677SEmmanuel Vadot max = factor->value;
134*e37e8677SEmmanuel Vadot else if (factor->flags & AW_CLK_FACTOR_POWER_OF_TWO)
135*e37e8677SEmmanuel Vadot max = 1 << ((1 << factor->width) - 1);
136*e37e8677SEmmanuel Vadot else {
137*e37e8677SEmmanuel Vadot max = (1 << factor->width);
138*e37e8677SEmmanuel Vadot }
139*e37e8677SEmmanuel Vadot
140*e37e8677SEmmanuel Vadot return (max);
141*e37e8677SEmmanuel Vadot }
142*e37e8677SEmmanuel Vadot
143*e37e8677SEmmanuel Vadot static inline uint32_t
aw_clk_factor_get_min(struct aw_clk_factor * factor)144*e37e8677SEmmanuel Vadot aw_clk_factor_get_min(struct aw_clk_factor *factor)
145*e37e8677SEmmanuel Vadot {
146*e37e8677SEmmanuel Vadot uint32_t min;
147*e37e8677SEmmanuel Vadot
148*e37e8677SEmmanuel Vadot if (factor->flags & AW_CLK_FACTOR_FIXED)
149*e37e8677SEmmanuel Vadot min = factor->value;
150*e37e8677SEmmanuel Vadot else if (factor->flags & AW_CLK_FACTOR_ZERO_BASED)
151*e37e8677SEmmanuel Vadot min = 0;
152*e37e8677SEmmanuel Vadot else if (factor->flags & AW_CLK_FACTOR_MIN_VALUE)
153*e37e8677SEmmanuel Vadot min = factor->min_value;
154*e37e8677SEmmanuel Vadot else
155*e37e8677SEmmanuel Vadot min = 1;
156*e37e8677SEmmanuel Vadot
157*e37e8677SEmmanuel Vadot return (min);
158*e37e8677SEmmanuel Vadot }
159*e37e8677SEmmanuel Vadot
160*e37e8677SEmmanuel Vadot static inline uint32_t
aw_clk_factor_get_value(struct aw_clk_factor * factor,uint32_t raw)161*e37e8677SEmmanuel Vadot aw_clk_factor_get_value(struct aw_clk_factor *factor, uint32_t raw)
162*e37e8677SEmmanuel Vadot {
163*e37e8677SEmmanuel Vadot uint32_t val;
164*e37e8677SEmmanuel Vadot
165*e37e8677SEmmanuel Vadot if (factor->flags & AW_CLK_FACTOR_FIXED)
166*e37e8677SEmmanuel Vadot return (factor->value);
167*e37e8677SEmmanuel Vadot
168*e37e8677SEmmanuel Vadot if (factor->flags & AW_CLK_FACTOR_ZERO_BASED)
169*e37e8677SEmmanuel Vadot val = raw;
170*e37e8677SEmmanuel Vadot else if (factor->flags & AW_CLK_FACTOR_POWER_OF_TWO) {
171*e37e8677SEmmanuel Vadot for (val = 0; raw != 1; val++)
172*e37e8677SEmmanuel Vadot raw >>= 1;
173*e37e8677SEmmanuel Vadot } else if (factor->flags & AW_CLK_FACTOR_MAX_VALUE)
174*e37e8677SEmmanuel Vadot val = factor->max_value;
175*e37e8677SEmmanuel Vadot else
176*e37e8677SEmmanuel Vadot val = raw - 1;
177*e37e8677SEmmanuel Vadot
178*e37e8677SEmmanuel Vadot return (val);
179*e37e8677SEmmanuel Vadot }
180*e37e8677SEmmanuel Vadot
181*e37e8677SEmmanuel Vadot #define CCU_RESET(idx, o, s) \
182*e37e8677SEmmanuel Vadot [idx] = { \
183*e37e8677SEmmanuel Vadot .offset = o, \
184*e37e8677SEmmanuel Vadot .shift = s, \
185*e37e8677SEmmanuel Vadot },
186*e37e8677SEmmanuel Vadot
187*e37e8677SEmmanuel Vadot #define CCU_GATE(idx, clkname, pname, o, s) \
188*e37e8677SEmmanuel Vadot [idx] = { \
189*e37e8677SEmmanuel Vadot .name = clkname, \
190*e37e8677SEmmanuel Vadot .parent_name = pname, \
191*e37e8677SEmmanuel Vadot .offset = o, \
192*e37e8677SEmmanuel Vadot .shift = s, \
193*e37e8677SEmmanuel Vadot },
194*e37e8677SEmmanuel Vadot
195*e37e8677SEmmanuel Vadot #define NKMP_CLK(_clkname, _id, _name, _pnames, \
196*e37e8677SEmmanuel Vadot _offset, \
197*e37e8677SEmmanuel Vadot _n_shift, _n_width, _n_value, _n_flags, \
198*e37e8677SEmmanuel Vadot _k_shift, _k_width, _k_value, _k_flags, \
199*e37e8677SEmmanuel Vadot _m_shift, _m_width, _m_value, _m_flags, \
200*e37e8677SEmmanuel Vadot _p_shift, _p_width, _p_value, _p_flags, \
201*e37e8677SEmmanuel Vadot _gate, \
202*e37e8677SEmmanuel Vadot _lock, _lock_retries, \
203*e37e8677SEmmanuel Vadot _flags) \
204*e37e8677SEmmanuel Vadot static struct aw_clk_nkmp_def _clkname = { \
205*e37e8677SEmmanuel Vadot .clkdef = { \
206*e37e8677SEmmanuel Vadot .id = _id, \
207*e37e8677SEmmanuel Vadot .name = _name, \
208*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
209*e37e8677SEmmanuel Vadot .parent_cnt = nitems(_pnames), \
210*e37e8677SEmmanuel Vadot }, \
211*e37e8677SEmmanuel Vadot .offset = _offset, \
212*e37e8677SEmmanuel Vadot .n.shift = _n_shift, \
213*e37e8677SEmmanuel Vadot .n.width = _n_width, \
214*e37e8677SEmmanuel Vadot .n.value = _n_value, \
215*e37e8677SEmmanuel Vadot .n.flags = _n_flags, \
216*e37e8677SEmmanuel Vadot .k.shift = _k_shift, \
217*e37e8677SEmmanuel Vadot .k.width = _k_width, \
218*e37e8677SEmmanuel Vadot .k.value = _k_value, \
219*e37e8677SEmmanuel Vadot .k.flags = _k_flags, \
220*e37e8677SEmmanuel Vadot .m.shift = _m_shift, \
221*e37e8677SEmmanuel Vadot .m.width = _m_width, \
222*e37e8677SEmmanuel Vadot .m.value = _m_value, \
223*e37e8677SEmmanuel Vadot .m.flags = _m_flags, \
224*e37e8677SEmmanuel Vadot .p.shift = _p_shift, \
225*e37e8677SEmmanuel Vadot .p.width = _p_width, \
226*e37e8677SEmmanuel Vadot .p.value = _p_value, \
227*e37e8677SEmmanuel Vadot .p.flags = _p_flags, \
228*e37e8677SEmmanuel Vadot .gate_shift = _gate, \
229*e37e8677SEmmanuel Vadot .lock_shift = _lock, \
230*e37e8677SEmmanuel Vadot .lock_retries = _lock_retries, \
231*e37e8677SEmmanuel Vadot .flags = _flags, \
232*e37e8677SEmmanuel Vadot }
233*e37e8677SEmmanuel Vadot
234*e37e8677SEmmanuel Vadot #define NKMP_CLK_WITH_MUX(_clkname, \
235*e37e8677SEmmanuel Vadot _id, _name, _pnames, \
236*e37e8677SEmmanuel Vadot _offset, \
237*e37e8677SEmmanuel Vadot _n_shift, _n_width, _n_value, _n_flags, \
238*e37e8677SEmmanuel Vadot _k_shift, _k_width, _k_value, _k_flags, \
239*e37e8677SEmmanuel Vadot _m_shift, _m_width, _m_value, _m_flags, \
240*e37e8677SEmmanuel Vadot _p_shift, _p_width, _p_value, _p_flags, \
241*e37e8677SEmmanuel Vadot _mux_shift, _mux_width, _gate, \
242*e37e8677SEmmanuel Vadot _lock, _lock_retries, \
243*e37e8677SEmmanuel Vadot _flags) \
244*e37e8677SEmmanuel Vadot static struct aw_clk_nkmp_def _clkname = { \
245*e37e8677SEmmanuel Vadot .clkdef = { \
246*e37e8677SEmmanuel Vadot .id = _id, \
247*e37e8677SEmmanuel Vadot .name = _name, \
248*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
249*e37e8677SEmmanuel Vadot .parent_cnt = nitems(_pnames), \
250*e37e8677SEmmanuel Vadot }, \
251*e37e8677SEmmanuel Vadot .offset = _offset, \
252*e37e8677SEmmanuel Vadot .n.shift = _n_shift, \
253*e37e8677SEmmanuel Vadot .n.width = _n_width, \
254*e37e8677SEmmanuel Vadot .n.value = _n_value, \
255*e37e8677SEmmanuel Vadot .n.flags = _n_flags, \
256*e37e8677SEmmanuel Vadot .k.shift = _k_shift, \
257*e37e8677SEmmanuel Vadot .k.width = _k_width, \
258*e37e8677SEmmanuel Vadot .k.value = _k_value, \
259*e37e8677SEmmanuel Vadot .k.flags = _k_flags, \
260*e37e8677SEmmanuel Vadot .m.shift = _m_shift, \
261*e37e8677SEmmanuel Vadot .m.width = _m_width, \
262*e37e8677SEmmanuel Vadot .m.value = _m_value, \
263*e37e8677SEmmanuel Vadot .m.flags = _m_flags, \
264*e37e8677SEmmanuel Vadot .p.shift = _p_shift, \
265*e37e8677SEmmanuel Vadot .p.width = _p_width, \
266*e37e8677SEmmanuel Vadot .p.value = _p_value, \
267*e37e8677SEmmanuel Vadot .p.flags = _p_flags, \
268*e37e8677SEmmanuel Vadot .mux_shift = _mux_shift, \
269*e37e8677SEmmanuel Vadot .mux_width = _mux_width, \
270*e37e8677SEmmanuel Vadot .gate_shift = _gate, \
271*e37e8677SEmmanuel Vadot .lock_shift = _lock, \
272*e37e8677SEmmanuel Vadot .lock_retries = _lock_retries, \
273*e37e8677SEmmanuel Vadot .flags = _flags, \
274*e37e8677SEmmanuel Vadot }
275*e37e8677SEmmanuel Vadot
276*e37e8677SEmmanuel Vadot #define NKMP_CLK_WITH_UPDATE(_clkname, \
277*e37e8677SEmmanuel Vadot _id, _name, _pnames, \
278*e37e8677SEmmanuel Vadot _offset, \
279*e37e8677SEmmanuel Vadot _n_shift, _n_width, _n_value, _n_flags, \
280*e37e8677SEmmanuel Vadot _k_shift, _k_width, _k_value, _k_flags, \
281*e37e8677SEmmanuel Vadot _m_shift, _m_width, _m_value, _m_flags, \
282*e37e8677SEmmanuel Vadot _p_shift, _p_width, _p_value, _p_flags, \
283*e37e8677SEmmanuel Vadot _gate, \
284*e37e8677SEmmanuel Vadot _lock, _lock_retries, \
285*e37e8677SEmmanuel Vadot _update, \
286*e37e8677SEmmanuel Vadot _flags) \
287*e37e8677SEmmanuel Vadot static struct aw_clk_nkmp_def _clkname = { \
288*e37e8677SEmmanuel Vadot .clkdef = { \
289*e37e8677SEmmanuel Vadot .id = _id, \
290*e37e8677SEmmanuel Vadot .name = _name, \
291*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
292*e37e8677SEmmanuel Vadot .parent_cnt = nitems(_pnames), \
293*e37e8677SEmmanuel Vadot }, \
294*e37e8677SEmmanuel Vadot .offset = _offset, \
295*e37e8677SEmmanuel Vadot .n.shift = _n_shift, \
296*e37e8677SEmmanuel Vadot .n.width = _n_width, \
297*e37e8677SEmmanuel Vadot .n.value = _n_value, \
298*e37e8677SEmmanuel Vadot .n.flags = _n_flags, \
299*e37e8677SEmmanuel Vadot .k.shift = _k_shift, \
300*e37e8677SEmmanuel Vadot .k.width = _k_width, \
301*e37e8677SEmmanuel Vadot .k.value = _k_value, \
302*e37e8677SEmmanuel Vadot .k.flags = _k_flags, \
303*e37e8677SEmmanuel Vadot .m.shift = _m_shift, \
304*e37e8677SEmmanuel Vadot .m.width = _m_width, \
305*e37e8677SEmmanuel Vadot .m.value = _m_value, \
306*e37e8677SEmmanuel Vadot .m.flags = _m_flags, \
307*e37e8677SEmmanuel Vadot .p.shift = _p_shift, \
308*e37e8677SEmmanuel Vadot .p.width = _p_width, \
309*e37e8677SEmmanuel Vadot .p.value = _p_value, \
310*e37e8677SEmmanuel Vadot .p.flags = _p_flags, \
311*e37e8677SEmmanuel Vadot .gate_shift = _gate, \
312*e37e8677SEmmanuel Vadot .lock_shift = _lock, \
313*e37e8677SEmmanuel Vadot .lock_retries = _lock_retries, \
314*e37e8677SEmmanuel Vadot .update_shift = _update, \
315*e37e8677SEmmanuel Vadot .flags = _flags | AW_CLK_HAS_UPDATE, \
316*e37e8677SEmmanuel Vadot }
317*e37e8677SEmmanuel Vadot
318*e37e8677SEmmanuel Vadot #define FRAC_CLK(_clkname, _id, _name, _pnames, \
319*e37e8677SEmmanuel Vadot _offset, \
320*e37e8677SEmmanuel Vadot _nshift, _nwidth, _nvalue, _nflags, \
321*e37e8677SEmmanuel Vadot _mshift, _mwidth, _mvalue, _mflags, \
322*e37e8677SEmmanuel Vadot _gate_shift, _lock_shift,_lock_retries, \
323*e37e8677SEmmanuel Vadot _flags, _freq0, _freq1, _mode_sel, _freq_sel, \
324*e37e8677SEmmanuel Vadot _min_freq, _max_freq) \
325*e37e8677SEmmanuel Vadot static struct aw_clk_frac_def _clkname = { \
326*e37e8677SEmmanuel Vadot .clkdef = { \
327*e37e8677SEmmanuel Vadot .id = _id, \
328*e37e8677SEmmanuel Vadot .name = _name, \
329*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
330*e37e8677SEmmanuel Vadot .parent_cnt = nitems(_pnames), \
331*e37e8677SEmmanuel Vadot .flags = CLK_NODE_GLITCH_FREE, \
332*e37e8677SEmmanuel Vadot }, \
333*e37e8677SEmmanuel Vadot .offset = _offset, \
334*e37e8677SEmmanuel Vadot .n.shift = _nshift, \
335*e37e8677SEmmanuel Vadot .n.width = _nwidth, \
336*e37e8677SEmmanuel Vadot .n.value = _nvalue, \
337*e37e8677SEmmanuel Vadot .n.flags = _nflags, \
338*e37e8677SEmmanuel Vadot .m.shift = _mshift, \
339*e37e8677SEmmanuel Vadot .m.width = _mwidth, \
340*e37e8677SEmmanuel Vadot .m.value = _mvalue, \
341*e37e8677SEmmanuel Vadot .m.flags = _mflags, \
342*e37e8677SEmmanuel Vadot .gate_shift = _gate_shift, \
343*e37e8677SEmmanuel Vadot .lock_shift = _lock_shift, \
344*e37e8677SEmmanuel Vadot .lock_retries = _lock_retries, \
345*e37e8677SEmmanuel Vadot .flags = _flags, \
346*e37e8677SEmmanuel Vadot .frac.freq0 = _freq0, \
347*e37e8677SEmmanuel Vadot .frac.freq1 = _freq1, \
348*e37e8677SEmmanuel Vadot .frac.mode_sel = _mode_sel, \
349*e37e8677SEmmanuel Vadot .frac.freq_sel = _freq_sel, \
350*e37e8677SEmmanuel Vadot .min_freq = _min_freq, \
351*e37e8677SEmmanuel Vadot .max_freq = _max_freq, \
352*e37e8677SEmmanuel Vadot }
353*e37e8677SEmmanuel Vadot
354*e37e8677SEmmanuel Vadot #define M_CLK(_clkname, _id, _name, _pnames, \
355*e37e8677SEmmanuel Vadot _offset, \
356*e37e8677SEmmanuel Vadot _mshift, _mwidth, _mvalue, _mflags, \
357*e37e8677SEmmanuel Vadot _mux_shift, _mux_width, \
358*e37e8677SEmmanuel Vadot _gate_shift, \
359*e37e8677SEmmanuel Vadot _flags) \
360*e37e8677SEmmanuel Vadot static struct aw_clk_m_def _clkname = { \
361*e37e8677SEmmanuel Vadot .clkdef = { \
362*e37e8677SEmmanuel Vadot .id = _id, \
363*e37e8677SEmmanuel Vadot .name = _name, \
364*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
365*e37e8677SEmmanuel Vadot .parent_cnt = nitems(_pnames), \
366*e37e8677SEmmanuel Vadot }, \
367*e37e8677SEmmanuel Vadot .offset = _offset, \
368*e37e8677SEmmanuel Vadot .mux_shift = _mux_shift, \
369*e37e8677SEmmanuel Vadot .m.shift = _mshift, \
370*e37e8677SEmmanuel Vadot .m.width = _mwidth, \
371*e37e8677SEmmanuel Vadot .m.value = _mvalue, \
372*e37e8677SEmmanuel Vadot .m.flags = _mflags, \
373*e37e8677SEmmanuel Vadot .mux_width = _mux_width, \
374*e37e8677SEmmanuel Vadot .gate_shift = _gate_shift, \
375*e37e8677SEmmanuel Vadot .flags = _flags, \
376*e37e8677SEmmanuel Vadot }
377*e37e8677SEmmanuel Vadot
378*e37e8677SEmmanuel Vadot #define NM_CLK(_clkname, _id, _name, _pnames, \
379*e37e8677SEmmanuel Vadot _offset, \
380*e37e8677SEmmanuel Vadot _nshift, _nwidth, _nvalue, _nflags, \
381*e37e8677SEmmanuel Vadot _mshift, _mwidth, _mvalue, _mflags, \
382*e37e8677SEmmanuel Vadot _mux_shift, _mux_width, \
383*e37e8677SEmmanuel Vadot _gate_shift, \
384*e37e8677SEmmanuel Vadot _flags) \
385*e37e8677SEmmanuel Vadot static struct aw_clk_nm_def _clkname = { \
386*e37e8677SEmmanuel Vadot .clkdef = { \
387*e37e8677SEmmanuel Vadot .id = _id, \
388*e37e8677SEmmanuel Vadot .name = _name, \
389*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
390*e37e8677SEmmanuel Vadot .parent_cnt = nitems(_pnames), \
391*e37e8677SEmmanuel Vadot }, \
392*e37e8677SEmmanuel Vadot .offset = _offset, \
393*e37e8677SEmmanuel Vadot .n.shift = _nshift, \
394*e37e8677SEmmanuel Vadot .n.width = _nwidth, \
395*e37e8677SEmmanuel Vadot .n.value = _nvalue, \
396*e37e8677SEmmanuel Vadot .n.flags = _nflags, \
397*e37e8677SEmmanuel Vadot .mux_shift = _mux_shift, \
398*e37e8677SEmmanuel Vadot .m.shift = _mshift, \
399*e37e8677SEmmanuel Vadot .m.width = _mwidth, \
400*e37e8677SEmmanuel Vadot .m.value = _mvalue, \
401*e37e8677SEmmanuel Vadot .m.flags = _mflags, \
402*e37e8677SEmmanuel Vadot .mux_width = _mux_width, \
403*e37e8677SEmmanuel Vadot .gate_shift = _gate_shift, \
404*e37e8677SEmmanuel Vadot .flags = _flags, \
405*e37e8677SEmmanuel Vadot }
406*e37e8677SEmmanuel Vadot
407*e37e8677SEmmanuel Vadot #define NMM_CLK(_clkname, _id, _name, _pnames, \
408*e37e8677SEmmanuel Vadot _offset, \
409*e37e8677SEmmanuel Vadot _nshift, _nwidth, _nvalue, _nflags, \
410*e37e8677SEmmanuel Vadot _m0shift, _m0width, _m0value, _m0flags, \
411*e37e8677SEmmanuel Vadot _m1shift, _m1width, _m1value, _m1flags, \
412*e37e8677SEmmanuel Vadot _gate_shift, \
413*e37e8677SEmmanuel Vadot _lock, _lock_retries, \
414*e37e8677SEmmanuel Vadot _flags) \
415*e37e8677SEmmanuel Vadot static struct aw_clk_nmm_def _clkname = { \
416*e37e8677SEmmanuel Vadot .clkdef = { \
417*e37e8677SEmmanuel Vadot .id = _id, \
418*e37e8677SEmmanuel Vadot .name = _name, \
419*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
420*e37e8677SEmmanuel Vadot .parent_cnt = nitems(_pnames), \
421*e37e8677SEmmanuel Vadot }, \
422*e37e8677SEmmanuel Vadot .offset = _offset, \
423*e37e8677SEmmanuel Vadot .n.shift = _nshift, \
424*e37e8677SEmmanuel Vadot .n.width = _nwidth, \
425*e37e8677SEmmanuel Vadot .n.value = _nvalue, \
426*e37e8677SEmmanuel Vadot .n.flags = _nflags, \
427*e37e8677SEmmanuel Vadot .m0.shift = _m0shift, \
428*e37e8677SEmmanuel Vadot .m0.width = _m0width, \
429*e37e8677SEmmanuel Vadot .m0.value = _m0value, \
430*e37e8677SEmmanuel Vadot .m0.flags = _m0flags, \
431*e37e8677SEmmanuel Vadot .m1.shift = _m1shift, \
432*e37e8677SEmmanuel Vadot .m1.width = _m1width, \
433*e37e8677SEmmanuel Vadot .m1.value = _m1value, \
434*e37e8677SEmmanuel Vadot .m1.flags = _m1flags, \
435*e37e8677SEmmanuel Vadot .gate_shift = _gate_shift, \
436*e37e8677SEmmanuel Vadot .lock_shift = _lock, \
437*e37e8677SEmmanuel Vadot .lock_retries = _lock_retries, \
438*e37e8677SEmmanuel Vadot .flags = _flags, \
439*e37e8677SEmmanuel Vadot }
440*e37e8677SEmmanuel Vadot
441*e37e8677SEmmanuel Vadot #define NP_CLK(_clkname, _id, _name, _pnames, \
442*e37e8677SEmmanuel Vadot _offset, \
443*e37e8677SEmmanuel Vadot _nshift, _nwidth, _nvalue, _nflags, \
444*e37e8677SEmmanuel Vadot _pshift, _pwidth, _pvalue, _pflags, \
445*e37e8677SEmmanuel Vadot _gate_shift, \
446*e37e8677SEmmanuel Vadot _lock, _lock_retries, \
447*e37e8677SEmmanuel Vadot _flags) \
448*e37e8677SEmmanuel Vadot static struct aw_clk_np_def _clkname = { \
449*e37e8677SEmmanuel Vadot .clkdef = { \
450*e37e8677SEmmanuel Vadot .id = _id, \
451*e37e8677SEmmanuel Vadot .name = _name, \
452*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
453*e37e8677SEmmanuel Vadot .parent_cnt = nitems(_pnames), \
454*e37e8677SEmmanuel Vadot }, \
455*e37e8677SEmmanuel Vadot .offset = _offset, \
456*e37e8677SEmmanuel Vadot .n.shift = _nshift, \
457*e37e8677SEmmanuel Vadot .n.width = _nwidth, \
458*e37e8677SEmmanuel Vadot .n.value = _nvalue, \
459*e37e8677SEmmanuel Vadot .n.flags = _nflags, \
460*e37e8677SEmmanuel Vadot .p.shift = _pshift, \
461*e37e8677SEmmanuel Vadot .p.width = _pwidth, \
462*e37e8677SEmmanuel Vadot .p.value = _pvalue, \
463*e37e8677SEmmanuel Vadot .p.flags = _pflags, \
464*e37e8677SEmmanuel Vadot .gate_shift = _gate_shift, \
465*e37e8677SEmmanuel Vadot .lock_shift = _lock, \
466*e37e8677SEmmanuel Vadot .lock_retries = _lock_retries, \
467*e37e8677SEmmanuel Vadot .flags = _flags, \
468*e37e8677SEmmanuel Vadot }
469*e37e8677SEmmanuel Vadot
470*e37e8677SEmmanuel Vadot #define PREDIV_CLK(_clkname, _id, _name, _pnames, \
471*e37e8677SEmmanuel Vadot _offset, \
472*e37e8677SEmmanuel Vadot _mux_shift, _mux_width, \
473*e37e8677SEmmanuel Vadot _div_shift, _div_width, _div_value, _div_flags, \
474*e37e8677SEmmanuel Vadot _prediv_shift, _prediv_width, _prediv_value, _prediv_flags, \
475*e37e8677SEmmanuel Vadot _prediv_cond_shift, _prediv_cond_width, _prediv_cond_value) \
476*e37e8677SEmmanuel Vadot static struct aw_clk_prediv_mux_def _clkname = { \
477*e37e8677SEmmanuel Vadot .clkdef = { \
478*e37e8677SEmmanuel Vadot .id = _id, \
479*e37e8677SEmmanuel Vadot .name = _name, \
480*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
481*e37e8677SEmmanuel Vadot .parent_cnt = nitems(_pnames), \
482*e37e8677SEmmanuel Vadot }, \
483*e37e8677SEmmanuel Vadot .offset = _offset, \
484*e37e8677SEmmanuel Vadot .mux_shift = _mux_shift, \
485*e37e8677SEmmanuel Vadot .mux_width = _mux_width, \
486*e37e8677SEmmanuel Vadot .div.shift = _div_shift, \
487*e37e8677SEmmanuel Vadot .div.width = _div_width, \
488*e37e8677SEmmanuel Vadot .div.value = _div_value, \
489*e37e8677SEmmanuel Vadot .div.flags = _div_flags, \
490*e37e8677SEmmanuel Vadot .prediv.shift = _prediv_shift, \
491*e37e8677SEmmanuel Vadot .prediv.width = _prediv_width, \
492*e37e8677SEmmanuel Vadot .prediv.value = _prediv_value, \
493*e37e8677SEmmanuel Vadot .prediv.flags = _prediv_flags, \
494*e37e8677SEmmanuel Vadot .prediv.cond_shift = _prediv_cond_shift, \
495*e37e8677SEmmanuel Vadot .prediv.cond_width = _prediv_cond_width, \
496*e37e8677SEmmanuel Vadot .prediv.cond_value = _prediv_cond_value, \
497*e37e8677SEmmanuel Vadot }
498*e37e8677SEmmanuel Vadot
499*e37e8677SEmmanuel Vadot #define PREDIV_CLK_WITH_MASK(_clkname, _id, _name, _pnames, \
500*e37e8677SEmmanuel Vadot _offset, \
501*e37e8677SEmmanuel Vadot _mux_shift, _mux_width, \
502*e37e8677SEmmanuel Vadot _div_shift, _div_width, _div_value, _div_flags, \
503*e37e8677SEmmanuel Vadot _prediv_shift, _prediv_width, _prediv_value, _prediv_flags, \
504*e37e8677SEmmanuel Vadot _prediv_cond_mask, _prediv_cond_value) \
505*e37e8677SEmmanuel Vadot static struct aw_clk_prediv_mux_def _clkname = { \
506*e37e8677SEmmanuel Vadot .clkdef = { \
507*e37e8677SEmmanuel Vadot .id = _id, \
508*e37e8677SEmmanuel Vadot .name = _name, \
509*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
510*e37e8677SEmmanuel Vadot .parent_cnt = nitems(_pnames), \
511*e37e8677SEmmanuel Vadot }, \
512*e37e8677SEmmanuel Vadot .offset = _offset, \
513*e37e8677SEmmanuel Vadot .mux_shift = _mux_shift, \
514*e37e8677SEmmanuel Vadot .mux_width = _mux_width, \
515*e37e8677SEmmanuel Vadot .div.shift = _div_shift, \
516*e37e8677SEmmanuel Vadot .div.width = _div_width, \
517*e37e8677SEmmanuel Vadot .div.value = _div_value, \
518*e37e8677SEmmanuel Vadot .div.flags = _div_flags, \
519*e37e8677SEmmanuel Vadot .prediv.shift = _prediv_shift, \
520*e37e8677SEmmanuel Vadot .prediv.width = _prediv_width, \
521*e37e8677SEmmanuel Vadot .prediv.value = _prediv_value, \
522*e37e8677SEmmanuel Vadot .prediv.flags = _prediv_flags, \
523*e37e8677SEmmanuel Vadot .prediv.cond_shift = 0, \
524*e37e8677SEmmanuel Vadot .prediv.cond_width = 0, \
525*e37e8677SEmmanuel Vadot .prediv.cond_mask = _prediv_cond_mask, \
526*e37e8677SEmmanuel Vadot .prediv.cond_value = _prediv_cond_value, \
527*e37e8677SEmmanuel Vadot }
528*e37e8677SEmmanuel Vadot
529*e37e8677SEmmanuel Vadot #define MIPI_CLK(_clkname, _id, _name, _pnames, \
530*e37e8677SEmmanuel Vadot _offset, \
531*e37e8677SEmmanuel Vadot _kshift, _kwidth, _kflags, _kmin, \
532*e37e8677SEmmanuel Vadot _mshift, _mwidth, \
533*e37e8677SEmmanuel Vadot _nshift, _nwidth, \
534*e37e8677SEmmanuel Vadot _gate_shift, _lock_shift) \
535*e37e8677SEmmanuel Vadot static struct aw_clk_mipi_def _clkname = { \
536*e37e8677SEmmanuel Vadot .clkdef = { \
537*e37e8677SEmmanuel Vadot .id = _id, \
538*e37e8677SEmmanuel Vadot .name = _name, \
539*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
540*e37e8677SEmmanuel Vadot .parent_cnt = nitems(_pnames) \
541*e37e8677SEmmanuel Vadot }, \
542*e37e8677SEmmanuel Vadot .offset = _offset, \
543*e37e8677SEmmanuel Vadot .k.shift = _kshift, \
544*e37e8677SEmmanuel Vadot .k.width = _kwidth, \
545*e37e8677SEmmanuel Vadot .k.flags = _kflags, \
546*e37e8677SEmmanuel Vadot .k.min_value = _kmin, \
547*e37e8677SEmmanuel Vadot .m.shift = _mshift, \
548*e37e8677SEmmanuel Vadot .m.width = _mwidth, \
549*e37e8677SEmmanuel Vadot .n.shift = _nshift, \
550*e37e8677SEmmanuel Vadot .n.width = _nwidth, \
551*e37e8677SEmmanuel Vadot .gate_shift = _gate_shift, \
552*e37e8677SEmmanuel Vadot .lock_shift = _lock_shift, \
553*e37e8677SEmmanuel Vadot }
554*e37e8677SEmmanuel Vadot
555*e37e8677SEmmanuel Vadot #define MUX_CLK(_clkname, _id, _name, _pnames, \
556*e37e8677SEmmanuel Vadot _offset, _shift, _width) \
557*e37e8677SEmmanuel Vadot static struct clk_mux_def _clkname = { \
558*e37e8677SEmmanuel Vadot .clkdef = { \
559*e37e8677SEmmanuel Vadot .id = _id, \
560*e37e8677SEmmanuel Vadot .name = _name, \
561*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
562*e37e8677SEmmanuel Vadot .parent_cnt = nitems(_pnames) \
563*e37e8677SEmmanuel Vadot }, \
564*e37e8677SEmmanuel Vadot .offset = _offset, \
565*e37e8677SEmmanuel Vadot .shift = _shift, \
566*e37e8677SEmmanuel Vadot .width = _width, \
567*e37e8677SEmmanuel Vadot }
568*e37e8677SEmmanuel Vadot
569*e37e8677SEmmanuel Vadot #define DIV_CLK(_clkname, _id, _name, _pnames, \
570*e37e8677SEmmanuel Vadot _offset, \
571*e37e8677SEmmanuel Vadot _i_shift, _i_width, \
572*e37e8677SEmmanuel Vadot _div_flags, _div_table) \
573*e37e8677SEmmanuel Vadot static struct clk_div_def _clkname = { \
574*e37e8677SEmmanuel Vadot .clkdef = { \
575*e37e8677SEmmanuel Vadot .id = _id, \
576*e37e8677SEmmanuel Vadot .name = _name, \
577*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
578*e37e8677SEmmanuel Vadot .parent_cnt = nitems(_pnames) \
579*e37e8677SEmmanuel Vadot }, \
580*e37e8677SEmmanuel Vadot .offset = _offset, \
581*e37e8677SEmmanuel Vadot .i_shift = _i_shift, \
582*e37e8677SEmmanuel Vadot .i_width = _i_width, \
583*e37e8677SEmmanuel Vadot .div_flags = _div_flags, \
584*e37e8677SEmmanuel Vadot .div_table = _div_table, \
585*e37e8677SEmmanuel Vadot }
586*e37e8677SEmmanuel Vadot
587*e37e8677SEmmanuel Vadot #define FIXED_CLK(_clkname, _id, _name, _pnames, \
588*e37e8677SEmmanuel Vadot _freq, _mult, _div, _flags) \
589*e37e8677SEmmanuel Vadot static struct clk_fixed_def _clkname = { \
590*e37e8677SEmmanuel Vadot .clkdef = { \
591*e37e8677SEmmanuel Vadot .id = _id, \
592*e37e8677SEmmanuel Vadot .name = _name, \
593*e37e8677SEmmanuel Vadot .parent_names = _pnames, \
594*e37e8677SEmmanuel Vadot .parent_cnt = 1, \
595*e37e8677SEmmanuel Vadot }, \
596*e37e8677SEmmanuel Vadot .freq = _freq, \
597*e37e8677SEmmanuel Vadot .mult = _mult, \
598*e37e8677SEmmanuel Vadot .div = _div, \
599*e37e8677SEmmanuel Vadot .fixed_flags = _flags, \
600*e37e8677SEmmanuel Vadot }
601*e37e8677SEmmanuel Vadot
602*e37e8677SEmmanuel Vadot #endif /* __AW_CLK_H__ */
603