rk_cru.h revision 1.8 1 1.8 jmcneill /* $NetBSD: rk_cru.h,v 1.8 2021/11/12 22:02:08 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2018 Jared McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jmcneill * SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.1 jmcneill #ifndef _ARM_RK_CRU_H
30 1.1 jmcneill #define _ARM_RK_CRU_H
31 1.1 jmcneill
32 1.1 jmcneill #include <dev/clk/clk_backend.h>
33 1.2 jmcneill #include <dev/fdt/syscon.h>
34 1.1 jmcneill
35 1.1 jmcneill struct rk_cru_softc;
36 1.1 jmcneill struct rk_cru_clk;
37 1.1 jmcneill
38 1.1 jmcneill /*
39 1.1 jmcneill * Clocks
40 1.1 jmcneill */
41 1.1 jmcneill
42 1.1 jmcneill enum rk_cru_clktype {
43 1.1 jmcneill RK_CRU_UNKNOWN,
44 1.1 jmcneill RK_CRU_PLL,
45 1.1 jmcneill RK_CRU_ARM,
46 1.1 jmcneill RK_CRU_COMPOSITE,
47 1.1 jmcneill RK_CRU_GATE,
48 1.1 jmcneill RK_CRU_MUX,
49 1.1 jmcneill };
50 1.1 jmcneill
51 1.1 jmcneill /* PLL clocks */
52 1.1 jmcneill
53 1.1 jmcneill struct rk_cru_pll_rate {
54 1.1 jmcneill u_int rate;
55 1.1 jmcneill u_int refdiv;
56 1.1 jmcneill u_int fbdiv;
57 1.1 jmcneill u_int postdiv1;
58 1.1 jmcneill u_int postdiv2;
59 1.1 jmcneill u_int dsmpd;
60 1.1 jmcneill u_int fracdiv;
61 1.1 jmcneill };
62 1.1 jmcneill
63 1.1 jmcneill #define RK_PLL_RATE(_rate, _refdiv, _fbdiv, _postdiv1, _postdiv2, _dsmpd, _fracdiv) \
64 1.1 jmcneill { \
65 1.1 jmcneill .rate = (_rate), \
66 1.1 jmcneill .refdiv = (_refdiv), \
67 1.1 jmcneill .fbdiv = (_fbdiv), \
68 1.1 jmcneill .postdiv1 = (_postdiv1), \
69 1.1 jmcneill .postdiv2 = (_postdiv2), \
70 1.1 jmcneill .dsmpd = (_dsmpd), \
71 1.1 jmcneill .fracdiv = (_fracdiv), \
72 1.1 jmcneill }
73 1.1 jmcneill
74 1.1 jmcneill struct rk_cru_pll {
75 1.1 jmcneill bus_size_t con_base;
76 1.1 jmcneill bus_size_t mode_reg;
77 1.1 jmcneill uint32_t mode_mask;
78 1.1 jmcneill uint32_t lock_mask;
79 1.1 jmcneill const struct rk_cru_pll_rate *rates;
80 1.1 jmcneill u_int nrates;
81 1.3 jmcneill const char **parents;
82 1.3 jmcneill u_int nparents;
83 1.8 jmcneill u_int flags;
84 1.8 jmcneill #define RK_PLL_RK3288 0x01
85 1.1 jmcneill };
86 1.1 jmcneill
87 1.1 jmcneill u_int rk_cru_pll_get_rate(struct rk_cru_softc *, struct rk_cru_clk *);
88 1.1 jmcneill int rk_cru_pll_set_rate(struct rk_cru_softc *, struct rk_cru_clk *, u_int);
89 1.1 jmcneill const char *rk_cru_pll_get_parent(struct rk_cru_softc *, struct rk_cru_clk *);
90 1.1 jmcneill
91 1.3 jmcneill #define RK_PLL(_id, _name, _parents, _con_base, _mode_reg, _mode_mask, _lock_mask, _rates) \
92 1.1 jmcneill { \
93 1.1 jmcneill .id = (_id), \
94 1.1 jmcneill .type = RK_CRU_PLL, \
95 1.1 jmcneill .base.name = (_name), \
96 1.1 jmcneill .base.flags = 0, \
97 1.3 jmcneill .u.pll.parents = (_parents), \
98 1.3 jmcneill .u.pll.nparents = __arraycount(_parents), \
99 1.1 jmcneill .u.pll.con_base = (_con_base), \
100 1.1 jmcneill .u.pll.mode_reg = (_mode_reg), \
101 1.1 jmcneill .u.pll.mode_mask = (_mode_mask), \
102 1.1 jmcneill .u.pll.lock_mask = (_lock_mask), \
103 1.1 jmcneill .u.pll.rates = (_rates), \
104 1.1 jmcneill .u.pll.nrates = __arraycount(_rates), \
105 1.8 jmcneill .u.pll.flags = 0, \
106 1.8 jmcneill .get_rate = rk_cru_pll_get_rate, \
107 1.8 jmcneill .set_rate = rk_cru_pll_set_rate, \
108 1.8 jmcneill .get_parent = rk_cru_pll_get_parent, \
109 1.8 jmcneill }
110 1.8 jmcneill
111 1.8 jmcneill #define RK3288_PLL(_id, _name, _parents, _con_base, _mode_reg, _mode_mask, _lock_mask, _rates) \
112 1.8 jmcneill { \
113 1.8 jmcneill .id = (_id), \
114 1.8 jmcneill .type = RK_CRU_PLL, \
115 1.8 jmcneill .base.name = (_name), \
116 1.8 jmcneill .base.flags = 0, \
117 1.8 jmcneill .u.pll.parents = (_parents), \
118 1.8 jmcneill .u.pll.nparents = __arraycount(_parents), \
119 1.8 jmcneill .u.pll.con_base = (_con_base), \
120 1.8 jmcneill .u.pll.mode_reg = (_mode_reg), \
121 1.8 jmcneill .u.pll.mode_mask = (_mode_mask), \
122 1.8 jmcneill .u.pll.lock_mask = (_lock_mask), \
123 1.8 jmcneill .u.pll.rates = (_rates), \
124 1.8 jmcneill .u.pll.nrates = __arraycount(_rates), \
125 1.8 jmcneill .u.pll.flags = RK_PLL_RK3288, \
126 1.1 jmcneill .get_rate = rk_cru_pll_get_rate, \
127 1.1 jmcneill .set_rate = rk_cru_pll_set_rate, \
128 1.1 jmcneill .get_parent = rk_cru_pll_get_parent, \
129 1.1 jmcneill }
130 1.1 jmcneill
131 1.1 jmcneill /* ARM clocks */
132 1.1 jmcneill
133 1.1 jmcneill struct rk_cru_arm_rate {
134 1.1 jmcneill u_int rate;
135 1.1 jmcneill u_int div;
136 1.1 jmcneill };
137 1.1 jmcneill
138 1.1 jmcneill #define RK_ARM_RATE(_rate, _div) \
139 1.1 jmcneill { \
140 1.1 jmcneill .rate = (_rate), \
141 1.1 jmcneill .div = (_div), \
142 1.1 jmcneill }
143 1.1 jmcneill
144 1.4 jmcneill struct rk_cru_cpu_rate {
145 1.4 jmcneill u_int rate;
146 1.4 jmcneill u_int reg1, reg1_mask, reg1_val;
147 1.4 jmcneill u_int reg2, reg2_mask, reg2_val;
148 1.4 jmcneill };
149 1.4 jmcneill
150 1.4 jmcneill #define RK_CPU_RATE(_rate, _reg1, _reg1_mask, _reg1_val, _reg2, _reg2_mask, _reg2_val) \
151 1.4 jmcneill { \
152 1.4 jmcneill .rate = (_rate), \
153 1.4 jmcneill .reg1 = (_reg1), .reg1_mask = (_reg1_mask), .reg1_val = (_reg1_val), \
154 1.4 jmcneill .reg2 = (_reg2), .reg2_mask = (_reg2_mask), .reg2_val = (_reg2_val), \
155 1.4 jmcneill }
156 1.4 jmcneill
157 1.1 jmcneill struct rk_cru_arm {
158 1.1 jmcneill bus_size_t reg;
159 1.1 jmcneill uint32_t mux_mask;
160 1.1 jmcneill u_int mux_main;
161 1.1 jmcneill u_int mux_alt;
162 1.1 jmcneill uint32_t div_mask;
163 1.1 jmcneill const char **parents;
164 1.1 jmcneill u_int nparents;
165 1.1 jmcneill const struct rk_cru_arm_rate *rates;
166 1.4 jmcneill const struct rk_cru_cpu_rate *cpurates;
167 1.1 jmcneill u_int nrates;
168 1.1 jmcneill };
169 1.1 jmcneill
170 1.1 jmcneill u_int rk_cru_arm_get_rate(struct rk_cru_softc *, struct rk_cru_clk *);
171 1.1 jmcneill int rk_cru_arm_set_rate(struct rk_cru_softc *, struct rk_cru_clk *, u_int);
172 1.4 jmcneill int rk_cru_arm_set_rate(struct rk_cru_softc *, struct rk_cru_clk *, u_int);
173 1.1 jmcneill const char *rk_cru_arm_get_parent(struct rk_cru_softc *, struct rk_cru_clk *);
174 1.1 jmcneill int rk_cru_arm_set_parent(struct rk_cru_softc *, struct rk_cru_clk *, const char *);
175 1.1 jmcneill
176 1.1 jmcneill #define RK_ARM(_id, _name, _parents, _reg, _mux_mask, _mux_main, _mux_alt, _div_mask, _rates) \
177 1.1 jmcneill { \
178 1.1 jmcneill .id = (_id), \
179 1.1 jmcneill .type = RK_CRU_ARM, \
180 1.1 jmcneill .base.name = (_name), \
181 1.1 jmcneill .base.flags = 0, \
182 1.1 jmcneill .u.arm.parents = (_parents), \
183 1.1 jmcneill .u.arm.nparents = __arraycount(_parents), \
184 1.1 jmcneill .u.arm.reg = (_reg), \
185 1.1 jmcneill .u.arm.mux_mask = (_mux_mask), \
186 1.1 jmcneill .u.arm.mux_main = (_mux_main), \
187 1.1 jmcneill .u.arm.mux_alt = (_mux_alt), \
188 1.1 jmcneill .u.arm.div_mask = (_div_mask), \
189 1.1 jmcneill .u.arm.rates = (_rates), \
190 1.1 jmcneill .u.arm.nrates = __arraycount(_rates), \
191 1.1 jmcneill .get_rate = rk_cru_arm_get_rate, \
192 1.1 jmcneill .set_rate = rk_cru_arm_set_rate, \
193 1.1 jmcneill .get_parent = rk_cru_arm_get_parent, \
194 1.1 jmcneill .set_parent = rk_cru_arm_set_parent, \
195 1.1 jmcneill }
196 1.1 jmcneill
197 1.4 jmcneill #define RK_CPU(_id, _name, _parents, _reg, _mux_mask, _mux_main, _mux_alt, _div_mask, _cpurates) \
198 1.4 jmcneill { \
199 1.4 jmcneill .id = (_id), \
200 1.4 jmcneill .type = RK_CRU_ARM, \
201 1.4 jmcneill .base.name = (_name), \
202 1.4 jmcneill .base.flags = 0, \
203 1.4 jmcneill .u.arm.parents = (_parents), \
204 1.4 jmcneill .u.arm.nparents = __arraycount(_parents), \
205 1.4 jmcneill .u.arm.reg = (_reg), \
206 1.4 jmcneill .u.arm.mux_mask = (_mux_mask), \
207 1.4 jmcneill .u.arm.mux_main = (_mux_main), \
208 1.4 jmcneill .u.arm.mux_alt = (_mux_alt), \
209 1.4 jmcneill .u.arm.div_mask = (_div_mask), \
210 1.4 jmcneill .u.arm.cpurates = (_cpurates), \
211 1.4 jmcneill .u.arm.nrates = __arraycount(_cpurates), \
212 1.4 jmcneill .get_rate = rk_cru_arm_get_rate, \
213 1.4 jmcneill .set_rate = rk_cru_arm_set_rate, \
214 1.4 jmcneill .get_parent = rk_cru_arm_get_parent, \
215 1.4 jmcneill .set_parent = rk_cru_arm_set_parent, \
216 1.4 jmcneill }
217 1.4 jmcneill
218 1.1 jmcneill /* Composite clocks */
219 1.1 jmcneill
220 1.1 jmcneill struct rk_cru_composite {
221 1.1 jmcneill bus_size_t muxdiv_reg;
222 1.1 jmcneill uint32_t mux_mask;
223 1.1 jmcneill uint32_t div_mask;
224 1.1 jmcneill bus_size_t gate_reg;
225 1.1 jmcneill uint32_t gate_mask;
226 1.7 jmcneill bus_size_t frac_reg;
227 1.1 jmcneill const char **parents;
228 1.1 jmcneill u_int nparents;
229 1.1 jmcneill u_int flags;
230 1.1 jmcneill #define RK_COMPOSITE_ROUND_DOWN 0x01
231 1.6 jmcneill #define RK_COMPOSITE_SET_RATE_PARENT 0x02
232 1.7 jmcneill #define RK_COMPOSITE_FRACDIV 0x04
233 1.8 jmcneill #define RK_COMPOSITE_POW2 0x08
234 1.1 jmcneill };
235 1.1 jmcneill
236 1.1 jmcneill int rk_cru_composite_enable(struct rk_cru_softc *, struct rk_cru_clk *, int);
237 1.1 jmcneill u_int rk_cru_composite_get_rate(struct rk_cru_softc *, struct rk_cru_clk *);
238 1.1 jmcneill int rk_cru_composite_set_rate(struct rk_cru_softc *, struct rk_cru_clk *, u_int);
239 1.1 jmcneill const char *rk_cru_composite_get_parent(struct rk_cru_softc *, struct rk_cru_clk *);
240 1.1 jmcneill int rk_cru_composite_set_parent(struct rk_cru_softc *, struct rk_cru_clk *, const char *);
241 1.1 jmcneill
242 1.7 jmcneill #define _RK_COMPOSITE_INIT(_id, _name, _parents, _muxdiv_reg, _mux_mask, _div_mask, _gate_reg, _gate_mask, _frac_reg, _flags) \
243 1.1 jmcneill { \
244 1.1 jmcneill .id = (_id), \
245 1.1 jmcneill .type = RK_CRU_COMPOSITE, \
246 1.1 jmcneill .base.name = (_name), \
247 1.1 jmcneill .base.flags = 0, \
248 1.1 jmcneill .u.composite.parents = (_parents), \
249 1.1 jmcneill .u.composite.nparents = __arraycount(_parents), \
250 1.1 jmcneill .u.composite.muxdiv_reg = (_muxdiv_reg), \
251 1.1 jmcneill .u.composite.mux_mask = (_mux_mask), \
252 1.1 jmcneill .u.composite.div_mask = (_div_mask), \
253 1.1 jmcneill .u.composite.gate_reg = (_gate_reg), \
254 1.1 jmcneill .u.composite.gate_mask = (_gate_mask), \
255 1.7 jmcneill .u.composite.frac_reg = (_frac_reg), \
256 1.1 jmcneill .u.composite.flags = (_flags), \
257 1.1 jmcneill .enable = rk_cru_composite_enable, \
258 1.1 jmcneill .get_rate = rk_cru_composite_get_rate, \
259 1.1 jmcneill .set_rate = rk_cru_composite_set_rate, \
260 1.1 jmcneill .get_parent = rk_cru_composite_get_parent, \
261 1.1 jmcneill .set_parent = rk_cru_composite_set_parent, \
262 1.1 jmcneill }
263 1.1 jmcneill
264 1.7 jmcneill #define RK_COMPOSITE(_id, _name, _parents, _muxdiv_reg, _mux_mask, _div_mask, _gate_reg, _gate_mask, _flags) \
265 1.7 jmcneill _RK_COMPOSITE_INIT(_id, _name, _parents, _muxdiv_reg, _mux_mask, _div_mask, _gate_reg, _gate_mask, 0, _flags)
266 1.7 jmcneill
267 1.3 jmcneill #define RK_COMPOSITE_NOMUX(_id, _name, _parent, _div_reg, _div_mask, _gate_reg, _gate_mask, _flags) \
268 1.7 jmcneill _RK_COMPOSITE_INIT(_id, _name, (const char *[]){ _parent }, _div_reg, 0, _div_mask, _gate_reg, _gate_mask, 0, _flags)
269 1.3 jmcneill
270 1.3 jmcneill #define RK_COMPOSITE_NOGATE(_id, _name, _parents, _muxdiv_reg, _mux_mask, _div_mask, _flags) \
271 1.7 jmcneill _RK_COMPOSITE_INIT(_id, _name, _parents, _muxdiv_reg, _mux_mask, _div_mask, 0, 0, 0, _flags)
272 1.7 jmcneill
273 1.7 jmcneill #define RK_COMPOSITE_FRAC(_id, _name, _parent, _frac_reg, _flags) \
274 1.7 jmcneill _RK_COMPOSITE_INIT(_id, _name, (const char *[]){ _parent }, 0, 0, 0, 0, 0, _frac_reg, (_flags) | RK_COMPOSITE_FRACDIV)
275 1.3 jmcneill
276 1.3 jmcneill #define RK_DIV(_id, _name, _parent, _div_reg, _div_mask, _flags) \
277 1.7 jmcneill _RK_COMPOSITE_INIT(_id, _name, (const char *[]){ _parent }, _div_reg, 0, _div_mask, 0, 0, 0, _flags)
278 1.3 jmcneill
279 1.1 jmcneill /* Gate clocks */
280 1.1 jmcneill
281 1.1 jmcneill struct rk_cru_gate {
282 1.1 jmcneill bus_size_t reg;
283 1.1 jmcneill uint32_t mask;
284 1.1 jmcneill const char *parent;
285 1.1 jmcneill };
286 1.1 jmcneill
287 1.1 jmcneill int rk_cru_gate_enable(struct rk_cru_softc *,
288 1.1 jmcneill struct rk_cru_clk *, int);
289 1.1 jmcneill const char *rk_cru_gate_get_parent(struct rk_cru_softc *,
290 1.1 jmcneill struct rk_cru_clk *);
291 1.1 jmcneill
292 1.1 jmcneill #define RK_GATE(_id, _name, _pname, _reg, _bit) \
293 1.1 jmcneill { \
294 1.1 jmcneill .id = (_id), \
295 1.1 jmcneill .type = RK_CRU_GATE, \
296 1.1 jmcneill .base.name = (_name), \
297 1.1 jmcneill .base.flags = CLK_SET_RATE_PARENT, \
298 1.1 jmcneill .u.gate.parent = (_pname), \
299 1.1 jmcneill .u.gate.reg = (_reg), \
300 1.1 jmcneill .u.gate.mask = __BIT(_bit), \
301 1.1 jmcneill .enable = rk_cru_gate_enable, \
302 1.1 jmcneill .get_parent = rk_cru_gate_get_parent, \
303 1.1 jmcneill }
304 1.1 jmcneill
305 1.5 tnn #define RK_SECURE_GATE(_id, _name, _pname) \
306 1.5 tnn { \
307 1.5 tnn .id = (_id), \
308 1.5 tnn .type = RK_CRU_GATE, \
309 1.5 tnn .base.name = (_name), \
310 1.5 tnn .u.gate.parent = (_pname), \
311 1.5 tnn .get_parent = rk_cru_gate_get_parent, \
312 1.5 tnn }
313 1.5 tnn
314 1.1 jmcneill /* Mux clocks */
315 1.1 jmcneill
316 1.1 jmcneill struct rk_cru_mux {
317 1.1 jmcneill bus_size_t reg;
318 1.1 jmcneill uint32_t mask;
319 1.1 jmcneill const char **parents;
320 1.1 jmcneill u_int nparents;
321 1.1 jmcneill u_int flags;
322 1.1 jmcneill #define RK_MUX_GRF 0x01
323 1.1 jmcneill };
324 1.1 jmcneill
325 1.1 jmcneill const char *rk_cru_mux_get_parent(struct rk_cru_softc *, struct rk_cru_clk *);
326 1.1 jmcneill int rk_cru_mux_set_parent(struct rk_cru_softc *, struct rk_cru_clk *, const char *);
327 1.1 jmcneill
328 1.1 jmcneill #define RK_MUX_FLAGS(_id, _name, _parents, _reg, _mask, _flags) \
329 1.1 jmcneill { \
330 1.1 jmcneill .id = (_id), \
331 1.1 jmcneill .type = RK_CRU_MUX, \
332 1.1 jmcneill .base.name = (_name), \
333 1.1 jmcneill .base.flags = CLK_SET_RATE_PARENT, \
334 1.1 jmcneill .u.mux.parents = (_parents), \
335 1.1 jmcneill .u.mux.nparents = __arraycount(_parents), \
336 1.1 jmcneill .u.mux.reg = (_reg), \
337 1.1 jmcneill .u.mux.mask = (_mask), \
338 1.1 jmcneill .u.mux.flags = (_flags), \
339 1.1 jmcneill .set_parent = rk_cru_mux_set_parent, \
340 1.1 jmcneill .get_parent = rk_cru_mux_get_parent, \
341 1.1 jmcneill }
342 1.1 jmcneill #define RK_MUX(_id, _name, _parents, _reg, _mask) \
343 1.1 jmcneill RK_MUX_FLAGS(_id, _name, _parents, _reg, _mask, 0)
344 1.1 jmcneill #define RK_MUXGRF(_id, _name, _parents, _reg, _mask) \
345 1.1 jmcneill RK_MUX_FLAGS(_id, _name, _parents, _reg, _mask, RK_MUX_GRF)
346 1.1 jmcneill
347 1.1 jmcneill /*
348 1.1 jmcneill * Rockchip clock definition
349 1.1 jmcneill */
350 1.1 jmcneill
351 1.1 jmcneill struct rk_cru_clk {
352 1.1 jmcneill struct clk base;
353 1.1 jmcneill u_int id;
354 1.1 jmcneill enum rk_cru_clktype type;
355 1.1 jmcneill union {
356 1.1 jmcneill struct rk_cru_pll pll;
357 1.1 jmcneill struct rk_cru_arm arm;
358 1.1 jmcneill struct rk_cru_composite composite;
359 1.1 jmcneill struct rk_cru_gate gate;
360 1.1 jmcneill struct rk_cru_mux mux;
361 1.1 jmcneill } u;
362 1.1 jmcneill
363 1.1 jmcneill int (*enable)(struct rk_cru_softc *,
364 1.1 jmcneill struct rk_cru_clk *, int);
365 1.1 jmcneill u_int (*get_rate)(struct rk_cru_softc *,
366 1.1 jmcneill struct rk_cru_clk *);
367 1.1 jmcneill int (*set_rate)(struct rk_cru_softc *,
368 1.1 jmcneill struct rk_cru_clk *, u_int);
369 1.1 jmcneill u_int (*round_rate)(struct rk_cru_softc *,
370 1.1 jmcneill struct rk_cru_clk *, u_int);
371 1.1 jmcneill const char * (*get_parent)(struct rk_cru_softc *,
372 1.1 jmcneill struct rk_cru_clk *);
373 1.1 jmcneill int (*set_parent)(struct rk_cru_softc *,
374 1.1 jmcneill struct rk_cru_clk *,
375 1.1 jmcneill const char *);
376 1.1 jmcneill };
377 1.1 jmcneill
378 1.1 jmcneill /*
379 1.1 jmcneill * Driver state
380 1.1 jmcneill */
381 1.1 jmcneill
382 1.1 jmcneill struct rk_cru_softc {
383 1.1 jmcneill device_t sc_dev;
384 1.1 jmcneill int sc_phandle;
385 1.1 jmcneill bus_space_tag_t sc_bst;
386 1.1 jmcneill bus_space_handle_t sc_bsh;
387 1.2 jmcneill struct syscon *sc_grf;
388 1.1 jmcneill
389 1.1 jmcneill struct clk_domain sc_clkdom;
390 1.1 jmcneill
391 1.1 jmcneill struct rk_cru_clk *sc_clks;
392 1.1 jmcneill u_int sc_nclks;
393 1.3 jmcneill
394 1.8 jmcneill bus_size_t sc_grf_soc_status; /* for PLL lock */
395 1.3 jmcneill bus_size_t sc_softrst_base;
396 1.1 jmcneill };
397 1.1 jmcneill
398 1.1 jmcneill int rk_cru_attach(struct rk_cru_softc *);
399 1.1 jmcneill struct rk_cru_clk *rk_cru_clock_find(struct rk_cru_softc *,
400 1.1 jmcneill const char *);
401 1.1 jmcneill void rk_cru_print(struct rk_cru_softc *);
402 1.1 jmcneill
403 1.1 jmcneill #define CRU_READ(sc, reg) \
404 1.1 jmcneill bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
405 1.1 jmcneill #define CRU_WRITE(sc, reg, val) \
406 1.1 jmcneill bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
407 1.1 jmcneill
408 1.2 jmcneill #define HAS_GRF(sc) ((sc)->sc_grf != NULL)
409 1.1 jmcneill
410 1.1 jmcneill #endif /* _ARM_RK_CRU_H */
411