blob: 20ee9611ba6e3934acc6f62281a8d5a2ce4ca79c [file] [log] [blame]
Thomas Gleixnerfcaf2032019-05-27 08:55:08 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Shawn Guoa3f6b9d2012-04-04 16:02:28 +08002/*
3 * Copyright 2012 Freescale Semiconductor, Inc.
4 * Copyright 2012 Linaro Ltd.
Shawn Guoa3f6b9d2012-04-04 16:02:28 +08005 */
6
Shawn Guoa3f6b9d2012-04-04 16:02:28 +08007#include <linux/clk-provider.h>
Shawn Guo322503a2013-10-30 15:12:55 +08008#include <linux/delay.h>
Shawn Guoa3f6b9d2012-04-04 16:02:28 +08009#include <linux/io.h>
Anson Huang9558b512020-03-20 07:44:03 +080010#include <linux/iopoll.h>
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080011#include <linux/slab.h>
12#include <linux/jiffies.h>
13#include <linux/err.h>
14#include "clk.h"
15
16#define PLL_NUM_OFFSET 0x10
17#define PLL_DENOM_OFFSET 0x20
Anson Huangb4a4cb52019-04-22 08:32:45 +000018#define PLL_IMX7_NUM_OFFSET 0x20
19#define PLL_IMX7_DENOM_OFFSET 0x30
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080020
Nikita Yushchenkoc77cbdd12016-12-19 11:12:09 +030021#define PLL_VF610_NUM_OFFSET 0x20
22#define PLL_VF610_DENOM_OFFSET 0x30
23
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080024#define BM_PLL_POWER (0x1 << 12)
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080025#define BM_PLL_LOCK (0x1 << 31)
Frank Lif5394742015-05-19 02:45:02 +080026#define IMX7_ENET_PLL_POWER (0x1 << 5)
Fabio Estevamad149722017-05-15 08:55:05 -030027#define IMX7_DDR_PLL_POWER (0x1 << 20)
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080028
Anson Huang9558b512020-03-20 07:44:03 +080029#define PLL_LOCK_TIMEOUT 10000
30
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080031/**
32 * struct clk_pllv3 - IMX PLL clock version 3
Krzysztof Kozlowskicca87e52020-09-02 17:02:44 +020033 * @hw: clock source
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080034 * @base: base address of PLL registers
Dong Aishengc6847662016-06-13 20:24:52 +080035 * @power_bit: pll power bit mask
36 * @powerup_set: set power_bit to power up the PLL
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080037 * @div_mask: mask of divider bits
Stefan Agner60ad8462014-12-02 17:59:42 +010038 * @div_shift: shift of divider bits
Krzysztof Kozlowskicca87e52020-09-02 17:02:44 +020039 * @ref_clock: reference clock rate
40 * @num_offset: num register offset
41 * @denom_offset: denom register offset
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080042 *
43 * IMX PLL clock version 3, found on i.MX6 series. Divider for pllv3
44 * is actually a multiplier, and always sits at bit 0.
45 */
46struct clk_pllv3 {
47 struct clk_hw hw;
48 void __iomem *base;
Dong Aishengc6847662016-06-13 20:24:52 +080049 u32 power_bit;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080050 bool powerup_set;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080051 u32 div_mask;
Stefan Agner60ad8462014-12-02 17:59:42 +010052 u32 div_shift;
Stefan Agner585a60f2016-01-29 14:49:24 -080053 unsigned long ref_clock;
Anson Huangb4a4cb52019-04-22 08:32:45 +000054 u32 num_offset;
55 u32 denom_offset;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080056};
57
58#define to_clk_pllv3(_hw) container_of(_hw, struct clk_pllv3, hw)
59
Shawn Guobc3b84d2013-10-30 15:56:22 +080060static int clk_pllv3_wait_lock(struct clk_pllv3 *pll)
61{
Dong Aishengc6847662016-06-13 20:24:52 +080062 u32 val = readl_relaxed(pll->base) & pll->power_bit;
Shawn Guobc3b84d2013-10-30 15:56:22 +080063
64 /* No need to wait for lock when pll is not powered up */
65 if ((pll->powerup_set && !val) || (!pll->powerup_set && val))
66 return 0;
67
Anson Huang9558b512020-03-20 07:44:03 +080068 return readl_relaxed_poll_timeout(pll->base, val, val & BM_PLL_LOCK,
69 500, PLL_LOCK_TIMEOUT);
Shawn Guobc3b84d2013-10-30 15:56:22 +080070}
71
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080072static int clk_pllv3_prepare(struct clk_hw *hw)
73{
74 struct clk_pllv3 *pll = to_clk_pllv3(hw);
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080075 u32 val;
76
77 val = readl_relaxed(pll->base);
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080078 if (pll->powerup_set)
Dong Aishengc6847662016-06-13 20:24:52 +080079 val |= pll->power_bit;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080080 else
Dong Aishengc6847662016-06-13 20:24:52 +080081 val &= ~pll->power_bit;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080082 writel_relaxed(val, pll->base);
83
Dmitry Voytikc400f7a2014-11-06 22:49:32 +040084 return clk_pllv3_wait_lock(pll);
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080085}
86
87static void clk_pllv3_unprepare(struct clk_hw *hw)
88{
89 struct clk_pllv3 *pll = to_clk_pllv3(hw);
90 u32 val;
91
92 val = readl_relaxed(pll->base);
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080093 if (pll->powerup_set)
Dong Aishengc6847662016-06-13 20:24:52 +080094 val &= ~pll->power_bit;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080095 else
Dong Aishengc6847662016-06-13 20:24:52 +080096 val |= pll->power_bit;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +080097 writel_relaxed(val, pll->base);
98}
99
Bai Ping4824b612015-11-25 00:06:53 +0800100static int clk_pllv3_is_prepared(struct clk_hw *hw)
101{
102 struct clk_pllv3 *pll = to_clk_pllv3(hw);
103
104 if (readl_relaxed(pll->base) & BM_PLL_LOCK)
105 return 1;
106
107 return 0;
108}
109
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800110static unsigned long clk_pllv3_recalc_rate(struct clk_hw *hw,
111 unsigned long parent_rate)
112{
113 struct clk_pllv3 *pll = to_clk_pllv3(hw);
Stefan Agner60ad8462014-12-02 17:59:42 +0100114 u32 div = (readl_relaxed(pll->base) >> pll->div_shift) & pll->div_mask;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800115
116 return (div == 1) ? parent_rate * 22 : parent_rate * 20;
117}
118
119static long clk_pllv3_round_rate(struct clk_hw *hw, unsigned long rate,
120 unsigned long *prate)
121{
122 unsigned long parent_rate = *prate;
123
124 return (rate >= parent_rate * 22) ? parent_rate * 22 :
125 parent_rate * 20;
126}
127
128static int clk_pllv3_set_rate(struct clk_hw *hw, unsigned long rate,
129 unsigned long parent_rate)
130{
131 struct clk_pllv3 *pll = to_clk_pllv3(hw);
132 u32 val, div;
133
134 if (rate == parent_rate * 22)
135 div = 1;
136 else if (rate == parent_rate * 20)
137 div = 0;
138 else
139 return -EINVAL;
140
141 val = readl_relaxed(pll->base);
Stefan Agner60ad8462014-12-02 17:59:42 +0100142 val &= ~(pll->div_mask << pll->div_shift);
143 val |= (div << pll->div_shift);
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800144 writel_relaxed(val, pll->base);
145
Shawn Guobc3b84d2013-10-30 15:56:22 +0800146 return clk_pllv3_wait_lock(pll);
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800147}
148
149static const struct clk_ops clk_pllv3_ops = {
150 .prepare = clk_pllv3_prepare,
151 .unprepare = clk_pllv3_unprepare,
Bai Ping4824b612015-11-25 00:06:53 +0800152 .is_prepared = clk_pllv3_is_prepared,
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800153 .recalc_rate = clk_pllv3_recalc_rate,
154 .round_rate = clk_pllv3_round_rate,
155 .set_rate = clk_pllv3_set_rate,
156};
157
158static unsigned long clk_pllv3_sys_recalc_rate(struct clk_hw *hw,
159 unsigned long parent_rate)
160{
161 struct clk_pllv3 *pll = to_clk_pllv3(hw);
162 u32 div = readl_relaxed(pll->base) & pll->div_mask;
163
164 return parent_rate * div / 2;
165}
166
167static long clk_pllv3_sys_round_rate(struct clk_hw *hw, unsigned long rate,
168 unsigned long *prate)
169{
170 unsigned long parent_rate = *prate;
171 unsigned long min_rate = parent_rate * 54 / 2;
172 unsigned long max_rate = parent_rate * 108 / 2;
173 u32 div;
174
175 if (rate > max_rate)
176 rate = max_rate;
177 else if (rate < min_rate)
178 rate = min_rate;
179 div = rate * 2 / parent_rate;
180
181 return parent_rate * div / 2;
182}
183
184static int clk_pllv3_sys_set_rate(struct clk_hw *hw, unsigned long rate,
185 unsigned long parent_rate)
186{
187 struct clk_pllv3 *pll = to_clk_pllv3(hw);
188 unsigned long min_rate = parent_rate * 54 / 2;
189 unsigned long max_rate = parent_rate * 108 / 2;
190 u32 val, div;
191
192 if (rate < min_rate || rate > max_rate)
193 return -EINVAL;
194
195 div = rate * 2 / parent_rate;
196 val = readl_relaxed(pll->base);
197 val &= ~pll->div_mask;
198 val |= div;
199 writel_relaxed(val, pll->base);
200
Shawn Guobc3b84d2013-10-30 15:56:22 +0800201 return clk_pllv3_wait_lock(pll);
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800202}
203
204static const struct clk_ops clk_pllv3_sys_ops = {
205 .prepare = clk_pllv3_prepare,
206 .unprepare = clk_pllv3_unprepare,
Bai Ping4824b612015-11-25 00:06:53 +0800207 .is_prepared = clk_pllv3_is_prepared,
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800208 .recalc_rate = clk_pllv3_sys_recalc_rate,
209 .round_rate = clk_pllv3_sys_round_rate,
210 .set_rate = clk_pllv3_sys_set_rate,
211};
212
213static unsigned long clk_pllv3_av_recalc_rate(struct clk_hw *hw,
214 unsigned long parent_rate)
215{
216 struct clk_pllv3 *pll = to_clk_pllv3(hw);
Anson Huangb4a4cb52019-04-22 08:32:45 +0000217 u32 mfn = readl_relaxed(pll->base + pll->num_offset);
218 u32 mfd = readl_relaxed(pll->base + pll->denom_offset);
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800219 u32 div = readl_relaxed(pll->base) & pll->div_mask;
Anson Huangba7f4f52016-06-08 22:33:31 +0800220 u64 temp64 = (u64)parent_rate;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800221
Anson Huangba7f4f52016-06-08 22:33:31 +0800222 temp64 *= mfn;
223 do_div(temp64, mfd);
224
Emil Lundmark5c2f1172016-10-12 12:31:40 +0200225 return parent_rate * div + (unsigned long)temp64;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800226}
227
228static long clk_pllv3_av_round_rate(struct clk_hw *hw, unsigned long rate,
229 unsigned long *prate)
230{
231 unsigned long parent_rate = *prate;
232 unsigned long min_rate = parent_rate * 27;
233 unsigned long max_rate = parent_rate * 54;
234 u32 div;
235 u32 mfn, mfd = 1000000;
Emil Lundmarkc5a80452016-10-12 12:31:41 +0200236 u32 max_mfd = 0x3FFFFFFF;
Anson Huang7a5568c2015-05-08 00:16:51 +0800237 u64 temp64;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800238
239 if (rate > max_rate)
240 rate = max_rate;
241 else if (rate < min_rate)
242 rate = min_rate;
243
Emil Lundmarkc5a80452016-10-12 12:31:41 +0200244 if (parent_rate <= max_mfd)
245 mfd = parent_rate;
246
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800247 div = rate / parent_rate;
248 temp64 = (u64) (rate - div * parent_rate);
249 temp64 *= mfd;
250 do_div(temp64, parent_rate);
251 mfn = temp64;
252
Emil Lundmark5c2f1172016-10-12 12:31:40 +0200253 temp64 = (u64)parent_rate;
254 temp64 *= mfn;
255 do_div(temp64, mfd);
256
257 return parent_rate * div + (unsigned long)temp64;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800258}
259
260static int clk_pllv3_av_set_rate(struct clk_hw *hw, unsigned long rate,
261 unsigned long parent_rate)
262{
263 struct clk_pllv3 *pll = to_clk_pllv3(hw);
264 unsigned long min_rate = parent_rate * 27;
265 unsigned long max_rate = parent_rate * 54;
266 u32 val, div;
267 u32 mfn, mfd = 1000000;
Emil Lundmarkc5a80452016-10-12 12:31:41 +0200268 u32 max_mfd = 0x3FFFFFFF;
Anson Huang7a5568c2015-05-08 00:16:51 +0800269 u64 temp64;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800270
271 if (rate < min_rate || rate > max_rate)
272 return -EINVAL;
273
Emil Lundmarkc5a80452016-10-12 12:31:41 +0200274 if (parent_rate <= max_mfd)
275 mfd = parent_rate;
276
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800277 div = rate / parent_rate;
278 temp64 = (u64) (rate - div * parent_rate);
279 temp64 *= mfd;
280 do_div(temp64, parent_rate);
281 mfn = temp64;
282
283 val = readl_relaxed(pll->base);
284 val &= ~pll->div_mask;
285 val |= div;
286 writel_relaxed(val, pll->base);
Anson Huangb4a4cb52019-04-22 08:32:45 +0000287 writel_relaxed(mfn, pll->base + pll->num_offset);
288 writel_relaxed(mfd, pll->base + pll->denom_offset);
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800289
Shawn Guobc3b84d2013-10-30 15:56:22 +0800290 return clk_pllv3_wait_lock(pll);
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800291}
292
293static const struct clk_ops clk_pllv3_av_ops = {
294 .prepare = clk_pllv3_prepare,
295 .unprepare = clk_pllv3_unprepare,
Bai Ping4824b612015-11-25 00:06:53 +0800296 .is_prepared = clk_pllv3_is_prepared,
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800297 .recalc_rate = clk_pllv3_av_recalc_rate,
298 .round_rate = clk_pllv3_av_round_rate,
299 .set_rate = clk_pllv3_av_set_rate,
300};
301
Nikita Yushchenkoc77cbdd12016-12-19 11:12:09 +0300302struct clk_pllv3_vf610_mf {
303 u32 mfi; /* integer part, can be 20 or 22 */
304 u32 mfn; /* numerator, 30-bit value */
305 u32 mfd; /* denominator, 30-bit value, must be less than mfn */
306};
307
308static unsigned long clk_pllv3_vf610_mf_to_rate(unsigned long parent_rate,
309 struct clk_pllv3_vf610_mf mf)
310{
311 u64 temp64;
312
313 temp64 = parent_rate;
314 temp64 *= mf.mfn;
315 do_div(temp64, mf.mfd);
316
317 return (parent_rate * mf.mfi) + temp64;
318}
319
320static struct clk_pllv3_vf610_mf clk_pllv3_vf610_rate_to_mf(
321 unsigned long parent_rate, unsigned long rate)
322{
323 struct clk_pllv3_vf610_mf mf;
324 u64 temp64;
325
326 mf.mfi = (rate >= 22 * parent_rate) ? 22 : 20;
327 mf.mfd = 0x3fffffff; /* use max supported value for best accuracy */
328
329 if (rate <= parent_rate * mf.mfi)
330 mf.mfn = 0;
331 else if (rate >= parent_rate * (mf.mfi + 1))
332 mf.mfn = mf.mfd - 1;
333 else {
334 /* rate = parent_rate * (mfi + mfn/mfd) */
335 temp64 = rate - parent_rate * mf.mfi;
336 temp64 *= mf.mfd;
337 do_div(temp64, parent_rate);
338 mf.mfn = temp64;
339 }
340
341 return mf;
342}
343
344static unsigned long clk_pllv3_vf610_recalc_rate(struct clk_hw *hw,
345 unsigned long parent_rate)
346{
347 struct clk_pllv3 *pll = to_clk_pllv3(hw);
348 struct clk_pllv3_vf610_mf mf;
349
Anson Huangb4a4cb52019-04-22 08:32:45 +0000350 mf.mfn = readl_relaxed(pll->base + pll->num_offset);
351 mf.mfd = readl_relaxed(pll->base + pll->denom_offset);
Nikita Yushchenkoc77cbdd12016-12-19 11:12:09 +0300352 mf.mfi = (readl_relaxed(pll->base) & pll->div_mask) ? 22 : 20;
353
354 return clk_pllv3_vf610_mf_to_rate(parent_rate, mf);
355}
356
357static long clk_pllv3_vf610_round_rate(struct clk_hw *hw, unsigned long rate,
358 unsigned long *prate)
359{
360 struct clk_pllv3_vf610_mf mf = clk_pllv3_vf610_rate_to_mf(*prate, rate);
361
362 return clk_pllv3_vf610_mf_to_rate(*prate, mf);
363}
364
365static int clk_pllv3_vf610_set_rate(struct clk_hw *hw, unsigned long rate,
366 unsigned long parent_rate)
367{
368 struct clk_pllv3 *pll = to_clk_pllv3(hw);
369 struct clk_pllv3_vf610_mf mf =
370 clk_pllv3_vf610_rate_to_mf(parent_rate, rate);
371 u32 val;
372
373 val = readl_relaxed(pll->base);
374 if (mf.mfi == 20)
375 val &= ~pll->div_mask; /* clear bit for mfi=20 */
376 else
377 val |= pll->div_mask; /* set bit for mfi=22 */
378 writel_relaxed(val, pll->base);
379
Anson Huangb4a4cb52019-04-22 08:32:45 +0000380 writel_relaxed(mf.mfn, pll->base + pll->num_offset);
381 writel_relaxed(mf.mfd, pll->base + pll->denom_offset);
Nikita Yushchenkoc77cbdd12016-12-19 11:12:09 +0300382
383 return clk_pllv3_wait_lock(pll);
384}
385
386static const struct clk_ops clk_pllv3_vf610_ops = {
387 .prepare = clk_pllv3_prepare,
388 .unprepare = clk_pllv3_unprepare,
389 .is_prepared = clk_pllv3_is_prepared,
390 .recalc_rate = clk_pllv3_vf610_recalc_rate,
391 .round_rate = clk_pllv3_vf610_round_rate,
392 .set_rate = clk_pllv3_vf610_set_rate,
393};
394
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800395static unsigned long clk_pllv3_enet_recalc_rate(struct clk_hw *hw,
396 unsigned long parent_rate)
397{
Stefan Agner585a60f2016-01-29 14:49:24 -0800398 struct clk_pllv3 *pll = to_clk_pllv3(hw);
399
400 return pll->ref_clock;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800401}
402
403static const struct clk_ops clk_pllv3_enet_ops = {
404 .prepare = clk_pllv3_prepare,
405 .unprepare = clk_pllv3_unprepare,
Bai Ping4824b612015-11-25 00:06:53 +0800406 .is_prepared = clk_pllv3_is_prepared,
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800407 .recalc_rate = clk_pllv3_enet_recalc_rate,
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800408};
409
Abel Vesae5674a42019-05-29 12:26:43 +0000410struct clk_hw *imx_clk_hw_pllv3(enum imx_pllv3_type type, const char *name,
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800411 const char *parent_name, void __iomem *base,
Sascha Hauer2b254692012-11-22 10:18:41 +0100412 u32 div_mask)
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800413{
414 struct clk_pllv3 *pll;
415 const struct clk_ops *ops;
Abel Vesae5674a42019-05-29 12:26:43 +0000416 struct clk_hw *hw;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800417 struct clk_init_data init;
Abel Vesae5674a42019-05-29 12:26:43 +0000418 int ret;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800419
420 pll = kzalloc(sizeof(*pll), GFP_KERNEL);
421 if (!pll)
422 return ERR_PTR(-ENOMEM);
423
Dong Aishengc6847662016-06-13 20:24:52 +0800424 pll->power_bit = BM_PLL_POWER;
Anson Huangb4a4cb52019-04-22 08:32:45 +0000425 pll->num_offset = PLL_NUM_OFFSET;
426 pll->denom_offset = PLL_DENOM_OFFSET;
Frank Lif5394742015-05-19 02:45:02 +0800427
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800428 switch (type) {
429 case IMX_PLLV3_SYS:
430 ops = &clk_pllv3_sys_ops;
431 break;
Nikita Yushchenkoc77cbdd12016-12-19 11:12:09 +0300432 case IMX_PLLV3_SYS_VF610:
433 ops = &clk_pllv3_vf610_ops;
Anson Huangb4a4cb52019-04-22 08:32:45 +0000434 pll->num_offset = PLL_VF610_NUM_OFFSET;
435 pll->denom_offset = PLL_VF610_DENOM_OFFSET;
Nikita Yushchenkoc77cbdd12016-12-19 11:12:09 +0300436 break;
Stefan Agner60ad8462014-12-02 17:59:42 +0100437 case IMX_PLLV3_USB_VF610:
438 pll->div_shift = 1;
Gustavo A. R. Silvad388e182020-07-27 15:09:22 -0500439 fallthrough;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800440 case IMX_PLLV3_USB:
441 ops = &clk_pllv3_ops;
442 pll->powerup_set = true;
443 break;
Anson Huangb4a4cb52019-04-22 08:32:45 +0000444 case IMX_PLLV3_AV_IMX7:
445 pll->num_offset = PLL_IMX7_NUM_OFFSET;
446 pll->denom_offset = PLL_IMX7_DENOM_OFFSET;
Gustavo A. R. Silvad388e182020-07-27 15:09:22 -0500447 fallthrough;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800448 case IMX_PLLV3_AV:
449 ops = &clk_pllv3_av_ops;
450 break;
Frank Lif5394742015-05-19 02:45:02 +0800451 case IMX_PLLV3_ENET_IMX7:
Dong Aishengc6847662016-06-13 20:24:52 +0800452 pll->power_bit = IMX7_ENET_PLL_POWER;
Stefan Agner585a60f2016-01-29 14:49:24 -0800453 pll->ref_clock = 1000000000;
454 ops = &clk_pllv3_enet_ops;
455 break;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800456 case IMX_PLLV3_ENET:
Stefan Agner585a60f2016-01-29 14:49:24 -0800457 pll->ref_clock = 500000000;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800458 ops = &clk_pllv3_enet_ops;
459 break;
Fabio Estevamad149722017-05-15 08:55:05 -0300460 case IMX_PLLV3_DDR_IMX7:
Fabio Estevamb608a892017-06-06 12:45:54 -0300461 pll->power_bit = IMX7_DDR_PLL_POWER;
Anson Huangb4a4cb52019-04-22 08:32:45 +0000462 pll->num_offset = PLL_IMX7_NUM_OFFSET;
463 pll->denom_offset = PLL_IMX7_DENOM_OFFSET;
Fabio Estevamad149722017-05-15 08:55:05 -0300464 ops = &clk_pllv3_av_ops;
465 break;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800466 default:
467 ops = &clk_pllv3_ops;
468 }
469 pll->base = base;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800470 pll->div_mask = div_mask;
471
472 init.name = name;
473 init.ops = ops;
474 init.flags = 0;
475 init.parent_names = &parent_name;
476 init.num_parents = 1;
477
478 pll->hw.init = &init;
Abel Vesae5674a42019-05-29 12:26:43 +0000479 hw = &pll->hw;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800480
Abel Vesae5674a42019-05-29 12:26:43 +0000481 ret = clk_hw_register(NULL, hw);
482 if (ret) {
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800483 kfree(pll);
Abel Vesae5674a42019-05-29 12:26:43 +0000484 return ERR_PTR(ret);
485 }
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800486
Abel Vesae5674a42019-05-29 12:26:43 +0000487 return hw;
Shawn Guoa3f6b9d2012-04-04 16:02:28 +0800488}