blob: ef33adbf2941308296130b1d49e9d0a18e3c4ac9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Kever Yangc5ccc322017-06-23 17:17:49 +08002/*
3 * (C) Copyright 2017 Rockchip Electronics Co., Ltd
Kever Yangc5ccc322017-06-23 17:17:49 +08004 */
5
6#include <common.h>
7#include <clk-uclass.h>
8#include <dm.h>
9#include <errno.h>
Simon Glass9bc15642020-02-03 07:36:16 -070010#include <malloc.h>
Kever Yangc5ccc322017-06-23 17:17:49 +080011#include <syscon.h>
12#include <asm/io.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080013#include <asm/arch-rockchip/clock.h>
14#include <asm/arch-rockchip/cru_rk322x.h>
15#include <asm/arch-rockchip/hardware.h>
Kever Yangc5ccc322017-06-23 17:17:49 +080016#include <dm/lists.h>
17#include <dt-bindings/clock/rk3228-cru.h>
18#include <linux/log2.h>
19
Kever Yangc5ccc322017-06-23 17:17:49 +080020enum {
21 VCO_MAX_HZ = 3200U * 1000000,
22 VCO_MIN_HZ = 800 * 1000000,
23 OUTPUT_MAX_HZ = 3200U * 1000000,
24 OUTPUT_MIN_HZ = 24 * 1000000,
25};
26
Kever Yangc5ccc322017-06-23 17:17:49 +080027#define DIV_TO_RATE(input_rate, div) ((input_rate) / ((div) + 1))
28
29#define PLL_DIVISORS(hz, _refdiv, _postdiv1, _postdiv2) {\
30 .refdiv = _refdiv,\
31 .fbdiv = (u32)((u64)hz * _refdiv * _postdiv1 * _postdiv2 / OSC_HZ), \
32 .postdiv1 = _postdiv1, .postdiv2 = _postdiv2};\
33 _Static_assert(((u64)hz * _refdiv * _postdiv1 * _postdiv2 / OSC_HZ) * \
34 OSC_HZ / (_refdiv * _postdiv1 * _postdiv2) == hz, \
35 #hz "Hz cannot be hit with PLL "\
36 "divisors on line " __stringify(__LINE__));
37
38/* use integer mode*/
39static const struct pll_div apll_init_cfg = PLL_DIVISORS(APLL_HZ, 1, 3, 1);
40static const struct pll_div gpll_init_cfg = PLL_DIVISORS(GPLL_HZ, 2, 2, 1);
41
42static int rkclk_set_pll(struct rk322x_cru *cru, enum rk_clk_id clk_id,
43 const struct pll_div *div)
44{
45 int pll_id = rk_pll_id(clk_id);
46 struct rk322x_pll *pll = &cru->pll[pll_id];
47
48 /* All PLLs have same VCO and output frequency range restrictions. */
49 uint vco_hz = OSC_HZ / 1000 * div->fbdiv / div->refdiv * 1000;
50 uint output_hz = vco_hz / div->postdiv1 / div->postdiv2;
51
52 debug("PLL at %p: fb=%d, ref=%d, pst1=%d, pst2=%d, vco=%u Hz, output=%u Hz\n",
53 pll, div->fbdiv, div->refdiv, div->postdiv1,
54 div->postdiv2, vco_hz, output_hz);
55 assert(vco_hz >= VCO_MIN_HZ && vco_hz <= VCO_MAX_HZ &&
56 output_hz >= OUTPUT_MIN_HZ && output_hz <= OUTPUT_MAX_HZ);
57
58 /* use integer mode */
59 rk_setreg(&pll->con1, 1 << PLL_DSMPD_SHIFT);
60 /* Power down */
61 rk_setreg(&pll->con1, 1 << PLL_PD_SHIFT);
62
63 rk_clrsetreg(&pll->con0,
64 PLL_POSTDIV1_MASK | PLL_FBDIV_MASK,
65 (div->postdiv1 << PLL_POSTDIV1_SHIFT) | div->fbdiv);
66 rk_clrsetreg(&pll->con1, PLL_POSTDIV2_MASK | PLL_REFDIV_MASK,
67 (div->postdiv2 << PLL_POSTDIV2_SHIFT |
68 div->refdiv << PLL_REFDIV_SHIFT));
69
70 /* Power Up */
71 rk_clrreg(&pll->con1, 1 << PLL_PD_SHIFT);
72
73 /* waiting for pll lock */
74 while (readl(&pll->con1) & (1 << PLL_LOCK_STATUS_SHIFT))
75 udelay(1);
76
77 return 0;
78}
79
80static void rkclk_init(struct rk322x_cru *cru)
81{
82 u32 aclk_div;
83 u32 hclk_div;
84 u32 pclk_div;
85
86 /* pll enter slow-mode */
87 rk_clrsetreg(&cru->cru_mode_con,
88 GPLL_MODE_MASK | APLL_MODE_MASK,
89 GPLL_MODE_SLOW << GPLL_MODE_SHIFT |
90 APLL_MODE_SLOW << APLL_MODE_SHIFT);
91
92 /* init pll */
93 rkclk_set_pll(cru, CLK_ARM, &apll_init_cfg);
94 rkclk_set_pll(cru, CLK_GENERAL, &gpll_init_cfg);
95
96 /*
97 * select apll as cpu/core clock pll source and
98 * set up dependent divisors for PERI and ACLK clocks.
99 * core hz : apll = 1:1
100 */
101 aclk_div = APLL_HZ / CORE_ACLK_HZ - 1;
102 assert((aclk_div + 1) * CORE_ACLK_HZ == APLL_HZ && aclk_div < 0x7);
103
104 pclk_div = APLL_HZ / CORE_PERI_HZ - 1;
105 assert((pclk_div + 1) * CORE_PERI_HZ == APLL_HZ && pclk_div < 0xf);
106
107 rk_clrsetreg(&cru->cru_clksel_con[0],
108 CORE_CLK_PLL_SEL_MASK | CORE_DIV_CON_MASK,
109 CORE_CLK_PLL_SEL_APLL << CORE_CLK_PLL_SEL_SHIFT |
110 0 << CORE_DIV_CON_SHIFT);
111
112 rk_clrsetreg(&cru->cru_clksel_con[1],
113 CORE_ACLK_DIV_MASK | CORE_PERI_DIV_MASK,
114 aclk_div << CORE_ACLK_DIV_SHIFT |
115 pclk_div << CORE_PERI_DIV_SHIFT);
116
117 /*
Kever Yang180fded2017-09-28 18:24:03 +0800118 * select gpll as pd_bus bus clock source and
Kever Yangc5ccc322017-06-23 17:17:49 +0800119 * set up dependent divisors for PCLK/HCLK and ACLK clocks.
120 */
121 aclk_div = GPLL_HZ / BUS_ACLK_HZ - 1;
122 assert((aclk_div + 1) * BUS_ACLK_HZ == GPLL_HZ && aclk_div <= 0x1f);
123
Kever Yang180fded2017-09-28 18:24:03 +0800124 pclk_div = BUS_ACLK_HZ / BUS_PCLK_HZ - 1;
Kever Yang55fabb32019-04-02 20:41:23 +0800125 assert((pclk_div + 1) * BUS_PCLK_HZ == BUS_ACLK_HZ && pclk_div <= 0x7);
Kever Yangc5ccc322017-06-23 17:17:49 +0800126
Kever Yang180fded2017-09-28 18:24:03 +0800127 hclk_div = BUS_ACLK_HZ / BUS_HCLK_HZ - 1;
Kever Yang55fabb32019-04-02 20:41:23 +0800128 assert((hclk_div + 1) * BUS_HCLK_HZ == BUS_ACLK_HZ && hclk_div <= 0x3);
Kever Yangc5ccc322017-06-23 17:17:49 +0800129
130 rk_clrsetreg(&cru->cru_clksel_con[0],
131 BUS_ACLK_PLL_SEL_MASK | BUS_ACLK_DIV_MASK,
132 BUS_ACLK_PLL_SEL_GPLL << BUS_ACLK_PLL_SEL_SHIFT |
133 aclk_div << BUS_ACLK_DIV_SHIFT);
134
135 rk_clrsetreg(&cru->cru_clksel_con[1],
136 BUS_PCLK_DIV_MASK | BUS_HCLK_DIV_MASK,
137 pclk_div << BUS_PCLK_DIV_SHIFT |
138 hclk_div << BUS_HCLK_DIV_SHIFT);
139
140 /*
141 * select gpll as pd_peri bus clock source and
142 * set up dependent divisors for PCLK/HCLK and ACLK clocks.
143 */
144 aclk_div = GPLL_HZ / PERI_ACLK_HZ - 1;
145 assert((aclk_div + 1) * PERI_ACLK_HZ == GPLL_HZ && aclk_div < 0x1f);
146
147 hclk_div = ilog2(PERI_ACLK_HZ / PERI_HCLK_HZ);
148 assert((1 << hclk_div) * PERI_HCLK_HZ ==
149 PERI_ACLK_HZ && (hclk_div < 0x4));
150
151 pclk_div = ilog2(PERI_ACLK_HZ / PERI_PCLK_HZ);
152 assert((1 << pclk_div) * PERI_PCLK_HZ ==
153 PERI_ACLK_HZ && pclk_div < 0x8);
154
155 rk_clrsetreg(&cru->cru_clksel_con[10],
156 PERI_PLL_SEL_MASK | PERI_PCLK_DIV_MASK |
157 PERI_HCLK_DIV_MASK | PERI_ACLK_DIV_MASK,
158 PERI_PLL_GPLL << PERI_PLL_SEL_SHIFT |
159 pclk_div << PERI_PCLK_DIV_SHIFT |
160 hclk_div << PERI_HCLK_DIV_SHIFT |
161 aclk_div << PERI_ACLK_DIV_SHIFT);
162
163 /* PLL enter normal-mode */
164 rk_clrsetreg(&cru->cru_mode_con,
165 GPLL_MODE_MASK | APLL_MODE_MASK,
166 GPLL_MODE_NORM << GPLL_MODE_SHIFT |
167 APLL_MODE_NORM << APLL_MODE_SHIFT);
168}
169
170/* Get pll rate by id */
171static uint32_t rkclk_pll_get_rate(struct rk322x_cru *cru,
172 enum rk_clk_id clk_id)
173{
174 uint32_t refdiv, fbdiv, postdiv1, postdiv2;
175 uint32_t con;
176 int pll_id = rk_pll_id(clk_id);
177 struct rk322x_pll *pll = &cru->pll[pll_id];
178 static u8 clk_shift[CLK_COUNT] = {
179 0xff, APLL_MODE_SHIFT, DPLL_MODE_SHIFT, 0xff,
180 GPLL_MODE_SHIFT, 0xff
181 };
182 static u32 clk_mask[CLK_COUNT] = {
183 0xff, APLL_MODE_MASK, DPLL_MODE_MASK, 0xff,
184 GPLL_MODE_MASK, 0xff
185 };
186 uint shift;
187 uint mask;
188
189 con = readl(&cru->cru_mode_con);
190 shift = clk_shift[clk_id];
191 mask = clk_mask[clk_id];
192
193 switch ((con & mask) >> shift) {
194 case GPLL_MODE_SLOW:
195 return OSC_HZ;
196 case GPLL_MODE_NORM:
197
198 /* normal mode */
199 con = readl(&pll->con0);
200 postdiv1 = (con & PLL_POSTDIV1_MASK) >> PLL_POSTDIV1_SHIFT;
201 fbdiv = (con & PLL_FBDIV_MASK) >> PLL_FBDIV_SHIFT;
202 con = readl(&pll->con1);
203 postdiv2 = (con & PLL_POSTDIV2_MASK) >> PLL_POSTDIV2_SHIFT;
204 refdiv = (con & PLL_REFDIV_MASK) >> PLL_REFDIV_SHIFT;
205 return (24 * fbdiv / (refdiv * postdiv1 * postdiv2)) * 1000000;
206 default:
207 return 32768;
208 }
209}
210
211static ulong rockchip_mmc_get_clk(struct rk322x_cru *cru, uint clk_general_rate,
212 int periph)
213{
214 uint src_rate;
215 uint div, mux;
216 u32 con;
217
218 switch (periph) {
219 case HCLK_EMMC:
220 case SCLK_EMMC:
Kever Yang62207412019-04-02 20:41:22 +0800221 case SCLK_EMMC_SAMPLE:
Kever Yangc5ccc322017-06-23 17:17:49 +0800222 con = readl(&cru->cru_clksel_con[11]);
223 mux = (con & EMMC_PLL_MASK) >> EMMC_PLL_SHIFT;
224 con = readl(&cru->cru_clksel_con[12]);
225 div = (con & EMMC_DIV_MASK) >> EMMC_DIV_SHIFT;
226 break;
227 case HCLK_SDMMC:
228 case SCLK_SDMMC:
229 con = readl(&cru->cru_clksel_con[11]);
230 mux = (con & MMC0_PLL_MASK) >> MMC0_PLL_SHIFT;
231 div = (con & MMC0_DIV_MASK) >> MMC0_DIV_SHIFT;
232 break;
233 default:
234 return -EINVAL;
235 }
236
237 src_rate = mux == EMMC_SEL_24M ? OSC_HZ : clk_general_rate;
Kever Yang99b546d2017-07-27 12:54:01 +0800238 return DIV_TO_RATE(src_rate, div) / 2;
Kever Yangc5ccc322017-06-23 17:17:49 +0800239}
240
David Wu0bfebea2018-01-13 14:05:12 +0800241static ulong rk322x_mac_set_clk(struct rk322x_cru *cru, uint freq)
242{
243 ulong ret;
244
245 /*
246 * The gmac clock can be derived either from an external clock
247 * or can be generated from internally by a divider from SCLK_MAC.
248 */
249 if (readl(&cru->cru_clksel_con[5]) & BIT(5)) {
250 /* An external clock will always generate the right rate... */
251 ret = freq;
252 } else {
253 u32 con = readl(&cru->cru_clksel_con[5]);
254 ulong pll_rate;
255 u8 div;
256
257 if ((con >> MAC_PLL_SEL_SHIFT) & MAC_PLL_SEL_MASK)
258 pll_rate = GPLL_HZ;
259 else
260 /* CPLL is not set */
261 return -EPERM;
262
263 div = DIV_ROUND_UP(pll_rate, freq) - 1;
264 if (div <= 0x1f)
265 rk_clrsetreg(&cru->cru_clksel_con[5], CLK_MAC_DIV_MASK,
266 div << CLK_MAC_DIV_SHIFT);
267 else
268 debug("Unsupported div for gmac:%d\n", div);
269
270 return DIV_TO_RATE(pll_rate, div);
271 }
272
273 return ret;
274}
275
Kever Yangc5ccc322017-06-23 17:17:49 +0800276static ulong rockchip_mmc_set_clk(struct rk322x_cru *cru, uint clk_general_rate,
277 int periph, uint freq)
278{
279 int src_clk_div;
280 int mux;
281
282 debug("%s: clk_general_rate=%u\n", __func__, clk_general_rate);
283
Kever Yang99b546d2017-07-27 12:54:01 +0800284 /* mmc clock defaulg div 2 internal, need provide double in cru */
285 src_clk_div = DIV_ROUND_UP(clk_general_rate / 2, freq);
Kever Yangc5ccc322017-06-23 17:17:49 +0800286
Kever Yangf20995b2017-07-27 12:54:02 +0800287 if (src_clk_div > 128) {
Kever Yang99b546d2017-07-27 12:54:01 +0800288 src_clk_div = DIV_ROUND_UP(OSC_HZ / 2, freq);
Kever Yangf20995b2017-07-27 12:54:02 +0800289 assert(src_clk_div - 1 < 128);
Kever Yangc5ccc322017-06-23 17:17:49 +0800290 mux = EMMC_SEL_24M;
291 } else {
292 mux = EMMC_SEL_GPLL;
293 }
294
295 switch (periph) {
296 case HCLK_EMMC:
297 case SCLK_EMMC:
Kever Yang62207412019-04-02 20:41:22 +0800298 case SCLK_EMMC_SAMPLE:
Kever Yangc5ccc322017-06-23 17:17:49 +0800299 rk_clrsetreg(&cru->cru_clksel_con[11],
300 EMMC_PLL_MASK,
301 mux << EMMC_PLL_SHIFT);
302 rk_clrsetreg(&cru->cru_clksel_con[12],
303 EMMC_DIV_MASK,
304 (src_clk_div - 1) << EMMC_DIV_SHIFT);
305 break;
306 case HCLK_SDMMC:
307 case SCLK_SDMMC:
308 rk_clrsetreg(&cru->cru_clksel_con[11],
309 MMC0_PLL_MASK | MMC0_DIV_MASK,
310 mux << MMC0_PLL_SHIFT |
311 (src_clk_div - 1) << MMC0_DIV_SHIFT);
312 break;
313 default:
314 return -EINVAL;
315 }
316
317 return rockchip_mmc_get_clk(cru, clk_general_rate, periph);
318}
319
320static int rk322x_ddr_set_clk(struct rk322x_cru *cru, unsigned int set_rate)
321{
322 struct pll_div dpll_cfg;
323
324 /* clk_ddrc == DPLL = 24MHz / refdiv * fbdiv / postdiv1 / postdiv2 */
325 switch (set_rate) {
326 case 400*MHz:
327 dpll_cfg = (struct pll_div)
328 {.refdiv = 1, .fbdiv = 50, .postdiv1 = 3, .postdiv2 = 1};
329 break;
330 case 600*MHz:
331 dpll_cfg = (struct pll_div)
332 {.refdiv = 1, .fbdiv = 75, .postdiv1 = 3, .postdiv2 = 1};
333 break;
334 case 800*MHz:
335 dpll_cfg = (struct pll_div)
336 {.refdiv = 1, .fbdiv = 100, .postdiv1 = 3, .postdiv2 = 1};
337 break;
338 }
339
340 /* pll enter slow-mode */
341 rk_clrsetreg(&cru->cru_mode_con, DPLL_MODE_MASK,
342 DPLL_MODE_SLOW << DPLL_MODE_SHIFT);
343 rkclk_set_pll(cru, CLK_DDR, &dpll_cfg);
344 /* PLL enter normal-mode */
345 rk_clrsetreg(&cru->cru_mode_con, DPLL_MODE_MASK,
346 DPLL_MODE_NORM << DPLL_MODE_SHIFT);
347
348 return set_rate;
349}
350static ulong rk322x_clk_get_rate(struct clk *clk)
351{
352 struct rk322x_clk_priv *priv = dev_get_priv(clk->dev);
353 ulong rate, gclk_rate;
354
355 gclk_rate = rkclk_pll_get_rate(priv->cru, CLK_GENERAL);
356 switch (clk->id) {
357 case 0 ... 63:
358 rate = rkclk_pll_get_rate(priv->cru, clk->id);
359 break;
360 case HCLK_EMMC:
361 case SCLK_EMMC:
362 case HCLK_SDMMC:
363 case SCLK_SDMMC:
364 rate = rockchip_mmc_get_clk(priv->cru, gclk_rate, clk->id);
365 break;
366 default:
367 return -ENOENT;
368 }
369
370 return rate;
371}
372
373static ulong rk322x_clk_set_rate(struct clk *clk, ulong rate)
374{
375 struct rk322x_clk_priv *priv = dev_get_priv(clk->dev);
376 ulong new_rate, gclk_rate;
377
378 gclk_rate = rkclk_pll_get_rate(priv->cru, CLK_GENERAL);
379 switch (clk->id) {
380 case HCLK_EMMC:
381 case SCLK_EMMC:
382 case HCLK_SDMMC:
383 case SCLK_SDMMC:
384 new_rate = rockchip_mmc_set_clk(priv->cru, gclk_rate,
385 clk->id, rate);
386 break;
387 case CLK_DDR:
388 new_rate = rk322x_ddr_set_clk(priv->cru, rate);
389 break;
David Wu0bfebea2018-01-13 14:05:12 +0800390 case SCLK_MAC:
391 new_rate = rk322x_mac_set_clk(priv->cru, rate);
392 break;
393 case PLL_GPLL:
394 return 0;
Kever Yangc5ccc322017-06-23 17:17:49 +0800395 default:
396 return -ENOENT;
397 }
398
399 return new_rate;
400}
401
David Wu0bfebea2018-01-13 14:05:12 +0800402static int rk322x_gmac_set_parent(struct clk *clk, struct clk *parent)
403{
404 struct rk322x_clk_priv *priv = dev_get_priv(clk->dev);
405 struct rk322x_cru *cru = priv->cru;
406
407 /*
408 * If the requested parent is in the same clock-controller and the id
409 * is SCLK_MAC_SRC ("sclk_gmac_src"), switch to the internal clock.
410 */
411 if ((parent->dev == clk->dev) && (parent->id == SCLK_MAC_SRC)) {
412 debug("%s: switching RGMII to SCLK_MAC_SRC\n", __func__);
413 rk_clrsetreg(&cru->cru_clksel_con[5], BIT(5), 0);
414 return 0;
415 }
416
417 /*
418 * If the requested parent is in the same clock-controller and the id
419 * is SCLK_MAC_EXTCLK (sclk_mac_extclk), switch to the external clock.
420 */
421 if ((parent->dev == clk->dev) && (parent->id == SCLK_MAC_EXTCLK)) {
422 debug("%s: switching RGMII to SCLK_MAC_EXTCLK\n", __func__);
423 rk_clrsetreg(&cru->cru_clksel_con[5], BIT(5), BIT(5));
424 return 0;
425 }
426
427 return -EINVAL;
428}
429
430static int rk322x_gmac_extclk_set_parent(struct clk *clk, struct clk *parent)
431{
432 struct rk322x_clk_priv *priv = dev_get_priv(clk->dev);
433 const char *clock_output_name;
434 struct rk322x_cru *cru = priv->cru;
435 int ret;
436
437 ret = dev_read_string_index(parent->dev, "clock-output-names",
438 parent->id, &clock_output_name);
439 if (ret < 0)
440 return -ENODATA;
441
442 if (!strcmp(clock_output_name, "ext_gmac")) {
443 debug("%s: switching gmac extclk to ext_gmac\n", __func__);
444 rk_clrsetreg(&cru->cru_clksel_con[29], BIT(10), 0);
445 return 0;
446 } else if (!strcmp(clock_output_name, "phy_50m_out")) {
447 debug("%s: switching gmac extclk to phy_50m_out\n", __func__);
448 rk_clrsetreg(&cru->cru_clksel_con[29], BIT(10), BIT(10));
449 return 0;
450 }
451
452 return -EINVAL;
453}
454
455static int rk322x_clk_set_parent(struct clk *clk, struct clk *parent)
456{
457 switch (clk->id) {
458 case SCLK_MAC:
459 return rk322x_gmac_set_parent(clk, parent);
460 case SCLK_MAC_EXTCLK:
461 return rk322x_gmac_extclk_set_parent(clk, parent);
462 }
463
464 debug("%s: unsupported clk %ld\n", __func__, clk->id);
465 return -ENOENT;
466}
467
Kever Yangc5ccc322017-06-23 17:17:49 +0800468static struct clk_ops rk322x_clk_ops = {
469 .get_rate = rk322x_clk_get_rate,
470 .set_rate = rk322x_clk_set_rate,
David Wu0bfebea2018-01-13 14:05:12 +0800471 .set_parent = rk322x_clk_set_parent,
Kever Yangc5ccc322017-06-23 17:17:49 +0800472};
473
474static int rk322x_clk_ofdata_to_platdata(struct udevice *dev)
475{
476 struct rk322x_clk_priv *priv = dev_get_priv(dev);
477
Kever Yang1a10d2e2018-02-11 11:53:07 +0800478 priv->cru = dev_read_addr_ptr(dev);
Kever Yangc5ccc322017-06-23 17:17:49 +0800479
480 return 0;
481}
482
483static int rk322x_clk_probe(struct udevice *dev)
484{
485 struct rk322x_clk_priv *priv = dev_get_priv(dev);
486
487 rkclk_init(priv->cru);
488
489 return 0;
490}
491
492static int rk322x_clk_bind(struct udevice *dev)
493{
494 int ret;
Kever Yang4fbb6c22017-11-03 15:16:13 +0800495 struct udevice *sys_child;
496 struct sysreset_reg *priv;
Kever Yangc5ccc322017-06-23 17:17:49 +0800497
498 /* The reset driver does not have a device node, so bind it here */
Kever Yang4fbb6c22017-11-03 15:16:13 +0800499 ret = device_bind_driver(dev, "rockchip_sysreset", "sysreset",
500 &sys_child);
501 if (ret) {
502 debug("Warning: No sysreset driver: ret=%d\n", ret);
503 } else {
504 priv = malloc(sizeof(struct sysreset_reg));
505 priv->glb_srst_fst_value = offsetof(struct rk322x_cru,
506 cru_glb_srst_fst_value);
507 priv->glb_srst_snd_value = offsetof(struct rk322x_cru,
508 cru_glb_srst_snd_value);
509 sys_child->priv = priv;
510 }
Kever Yangc5ccc322017-06-23 17:17:49 +0800511
Heiko Stuebner416f8d32019-11-09 00:06:30 +0100512#if CONFIG_IS_ENABLED(RESET_ROCKCHIP)
Elaine Zhang432976f2017-12-19 18:22:38 +0800513 ret = offsetof(struct rk322x_cru, cru_softrst_con[0]);
514 ret = rockchip_reset_bind(dev, ret, 9);
515 if (ret)
516 debug("Warning: software reset driver bind faile\n");
517#endif
518
Kever Yangc5ccc322017-06-23 17:17:49 +0800519 return 0;
520}
521
522static const struct udevice_id rk322x_clk_ids[] = {
523 { .compatible = "rockchip,rk3228-cru" },
524 { }
525};
526
527U_BOOT_DRIVER(rockchip_rk322x_cru) = {
528 .name = "clk_rk322x",
529 .id = UCLASS_CLK,
530 .of_match = rk322x_clk_ids,
531 .priv_auto_alloc_size = sizeof(struct rk322x_clk_priv),
532 .ofdata_to_platdata = rk322x_clk_ofdata_to_platdata,
533 .ops = &rk322x_clk_ops,
534 .bind = rk322x_clk_bind,
535 .probe = rk322x_clk_probe,
536};