xref: /linux/drivers/clk/clk-eyeq.c (revision 2b3e81a40ecf860c107dc47c119412746368591c)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * PLL clock driver for the Mobileye EyeQ platforms.
4  *
5  * This controller handles:
6  *  - Read-only PLLs, all derived from the same main crystal clock.
7  *  - It also exposes divider clocks, those are children to PLLs.
8  *  - Fixed factor clocks, children to PLLs.
9  *
10  * Parent clock is expected to be constant. This driver's registers live in a
11  * shared region called OLB. Some PLLs and fixed-factors are initialised early
12  * by of_clk_init(); if so, two clk providers are registered.
13  *
14  * We use eqc_ as prefix, as-in "EyeQ Clock", but way shorter.
15  *
16  * Copyright (C) 2024 Mobileye Vision Technologies Ltd.
17  */
18 
19 /*
20  * Set pr_fmt() for printing from eqc_early_init().
21  * It is called at of_clk_init() stage (read: really early).
22  */
23 #define pr_fmt(fmt) "clk-eyeq: " fmt
24 
25 #include <linux/array_size.h>
26 #include <linux/auxiliary_bus.h>
27 #include <linux/bitfield.h>
28 #include <linux/bits.h>
29 #include <linux/clk-provider.h>
30 #include <linux/device.h>
31 #include <linux/err.h>
32 #include <linux/errno.h>
33 #include <linux/init.h>
34 #include <linux/io-64-nonatomic-hi-lo.h>
35 #include <linux/io.h>
36 #include <linux/module.h>
37 #include <linux/of.h>
38 #include <linux/of_address.h>
39 #include <linux/overflow.h>
40 #include <linux/platform_device.h>
41 #include <linux/printk.h>
42 #include <linux/slab.h>
43 #include <linux/spinlock.h>
44 #include <linux/types.h>
45 
46 #include <dt-bindings/clock/mobileye,eyeq5-clk.h>
47 #include <dt-bindings/clock/mobileye,eyeq6lplus-clk.h>
48 #include <dt-bindings/clock/mobileye,eyeq7h-clk.h>
49 
50 /* In frac mode, it enables fractional noise canceling DAC. Else, no function. */
51 #define FRACG_PCSR0_DAC_EN			BIT(0)
52 /* Fractional or integer mode */
53 #define FRACG_PCSR0_DSM_EN			BIT(1)
54 #define FRACG_PCSR0_PLL_EN			BIT(2)
55 /* All clocks output held at 0 */
56 #define FRACG_PCSR0_FOUTPOSTDIV_EN		BIT(3)
57 #define FRACG_PCSR0_POST_DIV1			GENMASK(6, 4)
58 #define FRACG_PCSR0_POST_DIV2			GENMASK(9, 7)
59 #define FRACG_PCSR0_REF_DIV			GENMASK(15, 10)
60 #define FRACG_PCSR0_INTIN			GENMASK(27, 16)
61 #define FRACG_PCSR0_BYPASS			BIT(28)
62 /* Bits 30..29 are reserved */
63 #define FRACG_PCSR0_PLL_LOCKED			BIT(31)
64 
65 #define FRACG_PCSR1_RESET			BIT(0)
66 #define FRACG_PCSR1_SSGC_DIV			GENMASK(4, 1)
67 /* Spread amplitude (% = 0.1 * SPREAD[4:0]) */
68 #define FRACG_PCSR1_SPREAD			GENMASK(9, 5)
69 #define FRACG_PCSR1_DIS_SSCG			BIT(10)
70 /* Down-spread or center-spread */
71 #define FRACG_PCSR1_DOWN_SPREAD			BIT(11)
72 #define FRACG_PCSR1_FRAC_IN			GENMASK(31, 12)
73 
74 #define JFRACR_PCSR0_BYPASS			BIT(0)
75 #define JFRACR_PCSR0_PLL_EN			BIT(1)
76 #define JFRACR_PCSR0_FOUTVCO_EN			BIT(2)
77 #define JFRACR_PCSR0_FOUTPOSTDIV_EN		BIT(3)
78 #define JFRACR_PCSR0_POST_DIV1			GENMASK(6, 4)
79 #define JFRACR_PCSR0_POST_DIV2			GENMASK(9, 7)
80 #define JFRACR_PCSR0_REF_DIV			GENMASK(15, 10)
81 #define JFRACR_PCSR0_FB_DIV			GENMASK(27, 16)
82 #define JFRACR_PCSR0_VCO_SEL			GENMASK(29, 28)
83 #define JFRACR_PCSR0_PLL_LOCKED			GENMASK(31, 30)
84 
85 #define JFRACR_PCSR1_FRAC_IN			GENMASK(23, 0)
86 #define JFRACR_PCSR1_FOUT4PHASE_EN		BIT(24)
87 #define JFRACR_PCSR1_DAC_EN			BIT(25)
88 #define JFRACR_PCSR1_DSM_EN			BIT(26)
89 /* Bits 31..27 are reserved */
90 #define JFRACR_PCSR2_RESET			BIT(0)
91 #define JFRACR_PCSR2_DIS_SSCG			BIT(1)
92 #define JFRACR_PCSR2_DOWN_SPREAD		BIT(2)
93 #define JFRACR_PCSR2_SSGC_DIV			GENMASK(7, 4)
94 #define JFRACR_PCSR2_SPREAD			GENMASK(12, 8)
95 /* Bits 31..13 are reserved */
96 
97 #define AINTP_PCSR_BYPASS			BIT(0)
98 #define AINTP_PCSR_PLL_EN			BIT(1)
99 #define AINTP_PCSR_FOUTVCO_EN			BIT(2)
100 #define AINTP_PCSR_FOUTPOSTDIV_EN		BIT(3)
101 #define AINTP_PCSR_POST_DIV1			GENMASK(6, 4)
102 #define AINTP_PCSR_POST_DIV2			GENMASK(9, 7)
103 #define AINTP_PCSR_REF_DIV			GENMASK(15, 10)
104 #define AINTP_PCSR_FB_DIV			GENMASK(27, 16)
105 #define AINTP_PCSR_VCO_SEL			GENMASK(29, 28)
106 /* bit 30 is reserved */
107 #define AINTP_PCSR_PLL_LOCKED			BIT(31)
108 
109 /*
110  * Special index values to lookup a parent clock by its name
111  * from the device tree or by its globally unique name.
112  */
113 #define PARENT_BY_FWNAME			(-1)
114 #define PARENT_BY_NAME				(-2)
115 
116 struct eqc_clock {
117 	int		index;
118 	int		parent_idx;
119 	const char	*name;
120 	const char	*parent_name;
121 	int		(*probe)(struct device *dev, struct device_node *np,
122 				 const struct eqc_clock *clk, void __iomem *base,
123 				 struct clk_hw_onecell_data *cells);
124 	void		(*unregister)(struct clk_hw *hw);
125 	union {
126 		struct {
127 			unsigned int			reg;
128 			u8				shift;
129 			u8				width;
130 			unsigned long			flags;
131 			const struct clk_div_table	*table;
132 		} div;
133 		struct {
134 			unsigned int			mult;
135 			unsigned int			div;
136 		} ff;
137 		struct {
138 			unsigned int			reg;
139 		} pll;
140 	};
141 };
142 
143 struct eqc_match_data {
144 	unsigned int		clk_count;
145 	const struct eqc_clock	*clks;
146 
147 	const char		*reset_auxdev_name;
148 	const char		*pinctrl_auxdev_name;
149 	const char		*eth_phy_auxdev_name;
150 
151 	unsigned int		early_clk_count;
152 };
153 
154 struct eqc_early_match_data {
155 	unsigned int		early_clk_count;
156 	const struct eqc_clock	*early_clks;
157 
158 	/*
159 	 * We want our of_xlate callback to EPROBE_DEFER instead of dev_err()
160 	 * and EINVAL. For that, we must know the total clock count.
161 	 */
162 	unsigned int		late_clk_count;
163 };
164 
165 /*
166  * All Mobileye EyeQ SoC have 64 bits long, but both factors (mult and div)
167  * must fit in 32 bits as clk_fixed_factor uses unsigned int. When an
168  * operation overflows, this function throws away low bits so that
169  * factors still fit in 32 bits.
170  *
171  * Precision loss depends on amplitude of mult and div. Worst theoretical
172  * loss is: (UINT_MAX+1) / UINT_MAX - 1 = 2.3e-10.
173  * This is 1Hz every 4.3GHz.
174  */
175 static void eqc_pll_downshift_factors(unsigned long *mult, unsigned long *div)
176 {
177 	unsigned long biggest;
178 	unsigned int shift;
179 
180 	/* This function can be removed if mult/div switch to unsigned long. */
181 	static_assert(sizeof_field(struct clk_fixed_factor, mult) == sizeof(unsigned int));
182 	static_assert(sizeof_field(struct clk_fixed_factor, div) == sizeof(unsigned int));
183 
184 	/* No overflow, nothing to be done. */
185 	if (*mult <= UINT_MAX && *div <= UINT_MAX)
186 		return;
187 
188 	/*
189 	 * Compute the shift required to bring the biggest factor into unsigned
190 	 * int range. That is, shift its highest set bit to the unsigned int
191 	 * most significant bit.
192 	 */
193 	biggest = max(*mult, *div);
194 	shift = __fls(biggest) - (BITS_PER_BYTE * sizeof(unsigned int)) + 1;
195 
196 	*mult >>= shift;
197 	*div >>= shift;
198 }
199 
200 static int eqc_pll_parse_aintp(void __iomem *base, unsigned long *mult, unsigned long *div)
201 {
202 	u32 r0;
203 
204 	r0 = readl(base);
205 	if (r0 & AINTP_PCSR_BYPASS) {
206 		*mult = 1;
207 		*div = 1;
208 		return 0;
209 	}
210 
211 	if (!(r0 & AINTP_PCSR_PLL_LOCKED))
212 		return -EINVAL;
213 
214 	*mult = FIELD_GET(AINTP_PCSR_FB_DIV, r0);
215 	*div = FIELD_GET(AINTP_PCSR_REF_DIV, r0);
216 
217 	if (!*mult || !*div)
218 		return -EINVAL;
219 
220 	return 0;
221 }
222 
223 static int eqc_pll_parse_fracg(void __iomem *base, unsigned long *mult,
224 			       unsigned long *div, unsigned long *acc)
225 {
226 	unsigned long spread;
227 	u32 r0, r1;
228 	u64 val;
229 
230 	val = readq(base);
231 	r0 = val;
232 	r1 = val >> 32;
233 
234 	if (r0 & FRACG_PCSR0_BYPASS) {
235 		*mult = 1;
236 		*div = 1;
237 		*acc = 0;
238 		return 0;
239 	}
240 
241 	if (!(r0 & FRACG_PCSR0_PLL_LOCKED))
242 		return -EINVAL;
243 
244 	*mult = FIELD_GET(FRACG_PCSR0_INTIN, r0);
245 	*div = FIELD_GET(FRACG_PCSR0_REF_DIV, r0);
246 
247 	/* Fractional mode, in 2^20 (0x100000) parts. */
248 	if (r0 & FRACG_PCSR0_DSM_EN) {
249 		*div *= (1ULL << 20);
250 		*mult = *mult * (1ULL << 20) + FIELD_GET(FRACG_PCSR1_FRAC_IN, r1);
251 	}
252 
253 	if (!*mult || !*div)
254 		return -EINVAL;
255 
256 	if (r1 & (FRACG_PCSR1_RESET | FRACG_PCSR1_DIS_SSCG)) {
257 		*acc = 0;
258 		return 0;
259 	}
260 
261 	/*
262 	 * Spread spectrum.
263 	 *
264 	 * Spread is in 1/1024 parts of frequency. Clock accuracy
265 	 * is half the spread value expressed in parts per billion.
266 	 *
267 	 * accuracy = (spread * 1e9) / (1024 * 2)
268 	 *
269 	 * Care is taken to avoid overflowing or losing precision.
270 	 */
271 	spread = FIELD_GET(FRACG_PCSR1_SPREAD, r1);
272 	*acc = DIV_ROUND_CLOSEST(spread * 1000000000, 1024 * 2);
273 
274 	if (r1 & FRACG_PCSR1_DOWN_SPREAD) {
275 		/*
276 		 * Downspreading: the central frequency is half a
277 		 * spread lower.
278 		 */
279 		*mult *= 2048 - spread;
280 		*div *= 2048;
281 
282 		/*
283 		 * Previous operation might overflow 32 bits. If it
284 		 * does, throw away the least amount of low bits.
285 		 */
286 		eqc_pll_downshift_factors(mult, div);
287 	}
288 
289 	return 0;
290 }
291 
292 static int eqc_pll_parse_jfracr(void __iomem *base, unsigned long *mult,
293 				unsigned long *div, unsigned long *acc)
294 {
295 	unsigned long spread;
296 	u32 r0, r1, r2;
297 	u64 val;
298 
299 	val = readq(base);
300 	r0 = val;
301 	r1 = val >> 32;
302 	r2 = readl(base + 8);
303 
304 	if (r0 & JFRACR_PCSR0_BYPASS) {
305 		*mult = 1;
306 		*div = 1;
307 		*acc = 0;
308 		return 0;
309 	}
310 
311 	/* Consider the PLL locked if either the phase or the frequency is locked */
312 	if (!(r0 & JFRACR_PCSR0_PLL_LOCKED))
313 		return -EINVAL;
314 
315 	*mult = FIELD_GET(JFRACR_PCSR0_FB_DIV, r0);
316 	*div = FIELD_GET(JFRACR_PCSR0_REF_DIV, r0);
317 
318 	/* fractional part on 24 bits */
319 	if (r1 & JFRACR_PCSR1_DSM_EN) {
320 		*div *= (1ULL << 24);
321 		*mult = *mult * (1ULL << 24) + FIELD_GET(JFRACR_PCSR1_FRAC_IN, r1);
322 	}
323 
324 	if (!*mult || !*div)
325 		return -EINVAL;
326 
327 	if (r2 & (JFRACR_PCSR2_RESET | JFRACR_PCSR2_DIS_SSCG)) {
328 		*acc = 0;
329 	} else {
330 		/* spread spectrum is identical to FRACG PLL */
331 		spread = FIELD_GET(JFRACR_PCSR2_SPREAD, r2);
332 		*acc = DIV_ROUND_CLOSEST(spread * 1000000000, 1024 * 2);
333 
334 		if (r2 & JFRACR_PCSR2_DOWN_SPREAD) {
335 			*mult *= 2048 - spread;
336 			*div *= 2048;
337 		}
338 	}
339 
340 	/* make sure mult and div fit in 32 bits */
341 	eqc_pll_downshift_factors(mult, div);
342 
343 	return 0;
344 }
345 
346 static void eqc_auxdev_create_optional(struct device *dev, void __iomem *base,
347 				       const char *name)
348 {
349 	struct auxiliary_device *adev;
350 
351 	if (name) {
352 		adev = devm_auxiliary_device_create(dev, name,
353 						    (void __force *)base);
354 		if (!adev)
355 			dev_warn(dev, "failed creating auxiliary device %s.%s\n",
356 				 KBUILD_MODNAME, name);
357 	}
358 }
359 
360 static int eqc_fill_parent_data(const struct eqc_clock *clk,
361 				struct clk_hw_onecell_data *cells,
362 				struct clk_parent_data *parent_data)
363 {
364 	int pidx = clk->parent_idx;
365 
366 	memset(parent_data, 0, sizeof(struct clk_parent_data));
367 
368 	if (pidx == PARENT_BY_FWNAME) {
369 		/* lookup the parent clock by its fw_name */
370 		parent_data->index = -1;
371 		parent_data->fw_name = clk->parent_name;
372 	} else if (pidx == PARENT_BY_NAME) {
373 		/* lookup the parent clock by its global name */
374 		parent_data->index = -1;
375 		parent_data->name = clk->parent_name;
376 	} else if (pidx >= 0 && pidx < cells->num && !IS_ERR(cells->hws[pidx])) {
377 		/* get the parent hw directly */
378 		parent_data->hw = cells->hws[pidx];
379 	} else {
380 		/* no parent lookup by index: explicitly fail */
381 		return -EINVAL;
382 	}
383 
384 	return 0;
385 }
386 
387 static int eqc_probe_divider(struct device *dev, struct device_node *np,
388 			     const struct eqc_clock *clk, void __iomem *base,
389 			     struct clk_hw_onecell_data *cells)
390 {
391 	struct clk_parent_data parent_data;
392 	struct clk_hw *hw;
393 	int ret;
394 
395 	ret = eqc_fill_parent_data(clk, cells, &parent_data);
396 	if (ret)
397 		return ret;
398 
399 	hw = clk_hw_register_divider_table_parent_data(dev, clk->name,
400 			&parent_data, 0, base + clk->div.reg, clk->div.shift,
401 			clk->div.width, clk->div.flags, clk->div.table, NULL);
402 	if (IS_ERR(hw))
403 		return PTR_ERR(hw);
404 
405 	cells->hws[clk->index] = hw;
406 	return 0;
407 }
408 
409 static int eqc_probe_fixed_factor(struct device *dev, struct device_node *np,
410 				  const struct eqc_clock *clk, void __iomem *base,
411 				  struct clk_hw_onecell_data *cells)
412 {
413 	struct clk_parent_data parent_data;
414 	struct clk_hw *hw;
415 	int ret;
416 
417 	ret = eqc_fill_parent_data(clk, cells, &parent_data);
418 	if (ret)
419 		return ret;
420 
421 	hw = clk_hw_register_fixed_factor_pdata(dev, np, clk->name, &parent_data, 0,
422 						clk->ff.mult, clk->ff.div, 0, 0);
423 	if (IS_ERR(hw))
424 		return PTR_ERR(hw);
425 
426 	cells->hws[clk->index] = hw;
427 	return 0;
428 }
429 
430 static int eqc_probe_pll_aintp(struct device *dev, struct device_node *np,
431 			       const struct eqc_clock *clk, void __iomem *base,
432 			       struct clk_hw_onecell_data *cells)
433 {
434 	struct clk_parent_data parent_data = { };
435 	unsigned long mult, div;
436 	struct clk_hw *hw;
437 	int ret;
438 
439 	ret = eqc_pll_parse_aintp(base + clk->pll.reg, &mult, &div);
440 	if (ret)
441 		return ret;
442 
443 	ret = eqc_fill_parent_data(clk, cells, &parent_data);
444 	if (ret)
445 		return ret;
446 
447 	hw = clk_hw_register_fixed_factor_pdata(dev, np, clk->name, &parent_data,
448 						0, mult, div, 0, 0);
449 
450 	if (IS_ERR(hw))
451 		return PTR_ERR(hw);
452 
453 	cells->hws[clk->index] = hw;
454 	return 0;
455 }
456 
457 static int eqc_probe_pll_fracg(struct device *dev, struct device_node *np,
458 			       const struct eqc_clock *clk, void __iomem *base,
459 			       struct clk_hw_onecell_data *cells)
460 {
461 	struct clk_parent_data parent_data;
462 	unsigned long mult, div, acc;
463 	struct clk_hw *hw;
464 	int ret;
465 
466 	ret = eqc_pll_parse_fracg(base + clk->pll.reg, &mult, &div, &acc);
467 	if (ret)
468 		return ret;
469 
470 	ret = eqc_fill_parent_data(clk, cells, &parent_data);
471 	if (ret)
472 		return ret;
473 
474 	hw = clk_hw_register_fixed_factor_pdata(dev, np, clk->name, &parent_data, 0, mult,
475 						div, acc, CLK_FIXED_FACTOR_FIXED_ACCURACY);
476 	if (IS_ERR(hw))
477 		return PTR_ERR(hw);
478 
479 	cells->hws[clk->index] = hw;
480 	return 0;
481 }
482 
483 static int eqc_probe_pll_jfracr(struct device *dev, struct device_node *np,
484 				const struct eqc_clock *clk, void __iomem *base,
485 				struct clk_hw_onecell_data *cells)
486 {
487 	struct clk_parent_data parent_data = { };
488 	unsigned long mult, div, acc;
489 	struct clk_hw *hw;
490 	int ret;
491 
492 	ret = eqc_pll_parse_jfracr(base + clk->pll.reg, &mult, &div, &acc);
493 	if (ret)
494 		return ret;
495 
496 	ret = eqc_fill_parent_data(clk, cells, &parent_data);
497 	if (ret)
498 		return ret;
499 
500 	hw = clk_hw_register_fixed_factor_pdata(dev, np, clk->name, &parent_data, 0, mult,
501 						div, acc, CLK_FIXED_FACTOR_FIXED_ACCURACY);
502 	if (IS_ERR(hw))
503 		return PTR_ERR(hw);
504 
505 	cells->hws[clk->index] = hw;
506 	return 0;
507 }
508 
509 static int eqc_probe(struct platform_device *pdev)
510 {
511 	struct device *dev = &pdev->dev;
512 	struct device_node *np = dev->of_node;
513 	const struct eqc_match_data *data;
514 	struct clk_hw_onecell_data *cells;
515 	unsigned int i, clk_count;
516 	void __iomem *base;
517 	int ret;
518 
519 	base = devm_platform_ioremap_resource(pdev, 0);
520 	if (IS_ERR(base))
521 		return PTR_ERR(base);
522 
523 	data = device_get_match_data(dev);
524 	if (!data)
525 		return 0; /* No clocks nor auxdevs, stop here but keep resource reserved */
526 
527 	/* Init optional auxiliary devices. */
528 	eqc_auxdev_create_optional(dev, base, data->reset_auxdev_name);
529 	eqc_auxdev_create_optional(dev, base, data->pinctrl_auxdev_name);
530 	eqc_auxdev_create_optional(dev, base, data->eth_phy_auxdev_name);
531 
532 	if (data->clk_count == 0)
533 		return 0; /* Zero clocks, we are done. */
534 
535 	clk_count = data->clk_count + data->early_clk_count;
536 	cells = kzalloc_flex(*cells, hws, clk_count);
537 	if (!cells)
538 		return -ENOMEM;
539 
540 	cells->num = clk_count;
541 
542 	/* Early PLLs are marked as errors: the early provider will get queried. */
543 	for (i = 0; i < clk_count; i++)
544 		cells->hws[i] = ERR_PTR(-EINVAL);
545 
546 	for (i = 0; i < data->clk_count; i++) {
547 		const struct eqc_clock *clk = &data->clks[i];
548 
549 		if (clk->probe)
550 			ret = clk->probe(dev, NULL, clk, base, cells);
551 		else
552 			ret = -EINVAL;
553 		if (ret)
554 			dev_warn(dev, "failed probing clock %s: %d\n", clk->name, ret);
555 	}
556 
557 	ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, cells);
558 	if (ret) {
559 		for (i = 0; i < data->clk_count; i++) {
560 			const struct eqc_clock *clk = &data->clks[i];
561 			struct clk_hw *hw = cells->hws[clk->index];
562 
563 			if (!IS_ERR_OR_NULL(hw) && clk->unregister)
564 				clk->unregister(hw);
565 		}
566 
567 		kfree(cells);
568 	}
569 
570 	return ret;
571 }
572 
573 #define DIV(_index, _parent_idx, _name, _parent_name,			\
574 	    _reg, _shift, _width)					\
575 	{								\
576 		.index = _index,					\
577 		.parent_idx = _parent_idx,				\
578 		.name = _name,						\
579 		.parent_name = _parent_name,				\
580 		.probe = eqc_probe_divider,				\
581 		.unregister = clk_hw_unregister_divider,		\
582 		.div.reg = _reg,					\
583 		.div.shift = _shift,					\
584 		.div.width = _width,					\
585 		.div.flags = CLK_DIVIDER_EVEN_INTEGERS,			\
586 		.div.table = NULL,					\
587 	}
588 
589 #define DIV_TABLE_RO(_index, _parent_idx, _name, _parent_name,		\
590 		     _reg, _shift, _width, _table)			\
591 	{								\
592 		.index = _index,					\
593 		.parent_idx = _parent_idx,				\
594 		.name = _name,						\
595 		.parent_name = _parent_name,				\
596 		.probe = eqc_probe_divider,				\
597 		.unregister = clk_hw_unregister_divider,		\
598 		.div.reg = _reg,					\
599 		.div.shift = _shift,					\
600 		.div.width = _width,					\
601 		.div.flags = CLK_DIVIDER_READ_ONLY,			\
602 		.div.table = _table,					\
603 	}
604 
605 #define FF(_index, _parent_idx, _name, _parent_name, _mult, _div)	\
606 	{								\
607 		.index = _index,					\
608 		.parent_idx = _parent_idx,				\
609 		.name = _name,						\
610 		.parent_name = _parent_name,				\
611 		.probe = eqc_probe_fixed_factor,			\
612 		.unregister = clk_hw_unregister_fixed_factor,		\
613 		.ff.mult = _mult,					\
614 		.ff.div = _div,						\
615 	}
616 
617 #define PLL_AINTP(_index, _parent_idx, _name, _parent_name, _reg)	\
618 	{								\
619 		.index = _index,					\
620 		.parent_idx = _parent_idx,				\
621 		.name = _name,						\
622 		.parent_name = _parent_name,				\
623 		.probe = eqc_probe_pll_aintp,				\
624 		.unregister = clk_hw_unregister_fixed_factor,		\
625 		.pll.reg = _reg,					\
626 	}
627 
628 #define PLL_FRACG(_index, _parent_idx, _name, _parent_name, _reg)	\
629 	{								\
630 		.index = _index,					\
631 		.parent_idx = _parent_idx,				\
632 		.name = _name,						\
633 		.parent_name = _parent_name,				\
634 		.probe = eqc_probe_pll_fracg,				\
635 		.unregister = clk_hw_unregister_fixed_factor,		\
636 		.pll.reg = _reg,					\
637 	}
638 
639 #define PLL_JFRACR(_index, _parent_idx, _name, _parent_name, _reg)	\
640 	{								\
641 		.index = _index,					\
642 		.parent_idx = _parent_idx,				\
643 		.name = _name,						\
644 		.parent_name = _parent_name,				\
645 		.probe = eqc_probe_pll_jfracr,				\
646 		.unregister = clk_hw_unregister_fixed_factor,		\
647 		.pll.reg = _reg,					\
648 	}
649 
650 enum {
651 	/*
652 	 * EQ5C_PLL_CPU children.
653 	 * EQ5C_PER_OCC_PCI is the last clock exposed in dt-bindings.
654 	 */
655 	EQ5C_CPU_OCC = EQ5C_PER_OCC_PCI + 1,
656 	EQ5C_CPU_SI_CSS0,
657 	EQ5C_CPU_CPC,
658 	EQ5C_CPU_CM,
659 	EQ5C_CPU_MEM,
660 	EQ5C_CPU_OCC_ISRAM,
661 	EQ5C_CPU_ISRAM,
662 	EQ5C_CPU_OCC_DBU,
663 	EQ5C_CPU_SI_DBU_TP,
664 
665 	/*
666 	 * EQ5C_PLL_VDI children.
667 	 */
668 	EQ5C_VDI_OCC_VDI,
669 	EQ5C_VDI_VDI,
670 	EQ5C_VDI_OCC_CAN_SER,
671 	EQ5C_VDI_CAN_SER,
672 	EQ5C_VDI_I2C_SER,
673 
674 	/*
675 	 * EQ5C_PLL_PER children.
676 	 */
677 	EQ5C_PER_PERIPH,
678 	EQ5C_PER_CAN,
679 	EQ5C_PER_TIMER,
680 	EQ5C_PER_CCF,
681 	EQ5C_PER_OCC_MJPEG,
682 	EQ5C_PER_HSM,
683 	EQ5C_PER_MJPEG,
684 	EQ5C_PER_FCMU_A,
685 };
686 
687 /* Required early for GIC timer (pll-cpu) and UARTs (pll-per). */
688 static const struct eqc_clock eqc_eyeq5_early_clks[] = {
689 	PLL_FRACG(EQ5C_PLL_CPU, PARENT_BY_FWNAME, "pll-cpu", "ref", 0x02C),
690 	PLL_FRACG(EQ5C_PLL_PER, PARENT_BY_FWNAME, "pll-per", "ref", 0x05C),
691 
692 	FF(EQ5C_CPU_OCC, EQ5C_PLL_CPU, "occ-cpu", NULL, 1, 1),
693 	FF(EQ5C_CPU_SI_CSS0, EQ5C_CPU_OCC, "si-css0", NULL, 1, 1),
694 	FF(EQ5C_CPU_CORE0, EQ5C_CPU_SI_CSS0, "core0", NULL, 1, 1),
695 	FF(EQ5C_CPU_CORE1, EQ5C_CPU_SI_CSS0, "core1", NULL, 1, 1),
696 	FF(EQ5C_CPU_CORE2, EQ5C_CPU_SI_CSS0, "core2", NULL, 1, 1),
697 	FF(EQ5C_CPU_CORE3, EQ5C_CPU_SI_CSS0, "core3", NULL, 1, 1),
698 
699 	FF(EQ5C_PER_OCC, EQ5C_PLL_PER, "occ-periph", NULL, 1, 16),
700 	FF(EQ5C_PER_UART, EQ5C_PER_OCC, "uart", NULL, 1, 1),
701 };
702 
703 static const struct eqc_clock eqc_eyeq5_clks[] = {
704 	PLL_FRACG(EQ5C_PLL_VMP, PARENT_BY_FWNAME, "pll-vmp", "ref", 0x034),
705 	PLL_FRACG(EQ5C_PLL_PMA, PARENT_BY_FWNAME, "pll-pma", "ref", 0x03C),
706 	PLL_FRACG(EQ5C_PLL_VDI, PARENT_BY_FWNAME, "pll-vdi", "ref", 0x044),
707 	PLL_FRACG(EQ5C_PLL_DDR0, PARENT_BY_FWNAME, "pll-ddr0", "ref", 0x04C),
708 	PLL_FRACG(EQ5C_PLL_PCI, PARENT_BY_FWNAME, "pll-pci", "ref", 0x054),
709 	PLL_FRACG(EQ5C_PLL_PMAC, PARENT_BY_FWNAME, "pll-pmac", "ref", 0x064),
710 	PLL_FRACG(EQ5C_PLL_MPC, PARENT_BY_FWNAME, "pll-mpc", "ref", 0x06C),
711 	PLL_FRACG(EQ5C_PLL_DDR1, PARENT_BY_FWNAME, "pll-ddr1", "ref", 0x074),
712 
713 	DIV(EQ5C_DIV_OSPI, PARENT_BY_NAME, "div-ospi", "pll-per", 0x11C, 0, 4),
714 
715 	FF(EQ5C_CPU_CPC, PARENT_BY_NAME, "cpc", "si-css0", 1, 1),
716 	FF(EQ5C_CPU_CM, PARENT_BY_NAME, "cm", "si-css0", 1, 1),
717 	FF(EQ5C_CPU_MEM, PARENT_BY_NAME, "mem", "si-css0", 1, 1),
718 	FF(EQ5C_CPU_OCC_ISRAM, PARENT_BY_NAME, "occ-isram", "pll-cpu", 1, 2),
719 	FF(EQ5C_CPU_ISRAM, EQ5C_CPU_OCC_ISRAM, "isram", NULL, 1, 1),
720 	FF(EQ5C_CPU_OCC_DBU, PARENT_BY_NAME, "occ-dbu", "pll-cpu", 1, 10),
721 	FF(EQ5C_CPU_SI_DBU_TP, EQ5C_CPU_OCC_DBU, "si-dbu-tp", NULL, 1, 1),
722 
723 	FF(EQ5C_VDI_OCC_VDI, PARENT_BY_NAME, "occ-vdi", "pll-vdi", 1, 2),
724 	FF(EQ5C_VDI_VDI, EQ5C_VDI_OCC_VDI, "vdi", NULL, 1, 1),
725 	FF(EQ5C_VDI_OCC_CAN_SER, PARENT_BY_NAME, "occ-can-ser", "pll-vdi", 1, 16),
726 	FF(EQ5C_VDI_CAN_SER, EQ5C_VDI_OCC_CAN_SER, "can-ser", NULL, 1, 1),
727 	FF(EQ5C_VDI_I2C_SER, PARENT_BY_NAME, "i2c-ser", "pll-vdi", 1, 20),
728 
729 	FF(EQ5C_PER_PERIPH, PARENT_BY_NAME, "periph", "occ-periph", 1, 1),
730 	FF(EQ5C_PER_CAN, PARENT_BY_NAME, "can", "occ-periph", 1, 1),
731 	FF(EQ5C_PER_SPI, PARENT_BY_NAME, "spi", "occ-periph", 1, 1),
732 	FF(EQ5C_PER_I2C, PARENT_BY_NAME, "i2c", "occ-periph", 1, 1),
733 	FF(EQ5C_PER_TIMER, PARENT_BY_NAME, "timer", "occ-periph", 1, 1),
734 	FF(EQ5C_PER_GPIO, PARENT_BY_NAME, "gpio", "occ-periph", 1, 1),
735 	FF(EQ5C_PER_EMMC, PARENT_BY_NAME, "emmc-sys", "pll-per", 1, 10),
736 	FF(EQ5C_PER_CCF, PARENT_BY_NAME, "ccf-ctrl", "pll-per", 1, 4),
737 	FF(EQ5C_PER_OCC_MJPEG, PARENT_BY_NAME, "occ-mjpeg", "pll-per", 1, 2),
738 	FF(EQ5C_PER_HSM, EQ5C_PER_OCC_MJPEG, "hsm", NULL, 1, 1),
739 	FF(EQ5C_PER_MJPEG, EQ5C_PER_OCC_MJPEG, "mjpeg", NULL, 1, 1),
740 	FF(EQ5C_PER_FCMU_A, PARENT_BY_NAME, "fcmu-a", "pll-per", 1, 20),
741 	FF(EQ5C_PER_OCC_PCI, PARENT_BY_NAME, "occ-pci-sys", "pll-per", 1, 8),
742 };
743 
744 static const struct eqc_early_match_data eqc_eyeq5_early_match_data __initconst = {
745 	.early_clk_count	= ARRAY_SIZE(eqc_eyeq5_early_clks),
746 	.early_clks		= eqc_eyeq5_early_clks,
747 
748 	.late_clk_count		= ARRAY_SIZE(eqc_eyeq5_clks),
749 };
750 
751 static const struct eqc_match_data eqc_eyeq5_match_data = {
752 	.clk_count	= ARRAY_SIZE(eqc_eyeq5_clks),
753 	.clks		= eqc_eyeq5_clks,
754 
755 	.reset_auxdev_name = "reset",
756 	.pinctrl_auxdev_name = "pinctrl",
757 	.eth_phy_auxdev_name = "phy",
758 
759 	.early_clk_count = ARRAY_SIZE(eqc_eyeq5_early_clks),
760 };
761 
762 static const struct eqc_clock eqc_eyeq6l_clks[] = {
763 	PLL_FRACG(EQ6LC_PLL_DDR, PARENT_BY_FWNAME, "pll-ddr", "ref", 0x02C),
764 	PLL_FRACG(EQ6LC_PLL_CPU, PARENT_BY_FWNAME, "pll-cpu", "ref", 0x034),
765 	PLL_FRACG(EQ6LC_PLL_PER, PARENT_BY_FWNAME, "pll-per", "ref", 0x03C),
766 	PLL_FRACG(EQ6LC_PLL_VDI, PARENT_BY_FWNAME, "pll-vdi", "ref", 0x044),
767 };
768 
769 static const struct eqc_match_data eqc_eyeq6l_match_data = {
770 	.clk_count	= ARRAY_SIZE(eqc_eyeq6l_clks),
771 	.clks		= eqc_eyeq6l_clks,
772 
773 	.reset_auxdev_name = "reset",
774 };
775 
776 static const struct eqc_clock eqc_eyeq6lplus_early_clks[] = {
777 	PLL_FRACG(EQ6LPC_PLL_CPU, PARENT_BY_FWNAME, "pll-cpu", "ref", 0x058),
778 
779 	FF(EQ6LPC_CPU_OCC, EQ6LPC_PLL_CPU, "occ-cpu", NULL, 1, 1),
780 };
781 
782 static const struct eqc_clock eqc_eyeq6lplus_clks[] = {
783 	PLL_FRACG(EQ6LPC_PLL_DDR, PARENT_BY_FWNAME, "pll-ddr", "ref", 0x02C),
784 	PLL_FRACG(EQ6LPC_PLL_ACC, PARENT_BY_FWNAME, "pll-acc", "ref", 0x034),
785 	PLL_FRACG(EQ6LPC_PLL_PER, PARENT_BY_FWNAME, "pll-per", "ref", 0x03C),
786 	PLL_FRACG(EQ6LPC_PLL_VDI, PARENT_BY_FWNAME, "pll-vdi", "ref", 0x044),
787 
788 	FF(EQ6LPC_DDR_OCC, EQ6LPC_PLL_DDR, "occ-ddr", NULL, 1, 1),
789 
790 	FF(EQ6LPC_ACC_VDI, EQ6LPC_PLL_ACC, "vdi-div", NULL, 1, 10),
791 	FF(EQ6LPC_ACC_OCC, EQ6LPC_PLL_ACC, "occ-acc", NULL, 1, 1),
792 	FF(EQ6LPC_ACC_FCMU, EQ6LPC_ACC_OCC, "fcmu-a-clk", NULL, 1, 10),
793 
794 	FF(EQ6LPC_PER_OCC, EQ6LPC_PLL_PER, "occ-per", NULL, 1, 1),
795 	FF(EQ6LPC_PER_I2C_SER, EQ6LPC_PER_OCC, "i2c-ser-clk", NULL, 1, 10),
796 	FF(EQ6LPC_PER_PCLK, EQ6LPC_PER_OCC, "pclk", NULL, 1, 4),
797 	FF(EQ6LPC_PER_TSU, EQ6LPC_PER_OCC, "tsu-clk", NULL, 1, 8),
798 	FF(EQ6LPC_PER_OSPI, EQ6LPC_PER_OCC, "ospi-ref-clk", NULL, 1, 10),
799 	FF(EQ6LPC_PER_GPIO, EQ6LPC_PER_OCC, "gpio-clk", NULL, 1, 4),
800 	FF(EQ6LPC_PER_TIMER, EQ6LPC_PER_OCC, "timer-clk", NULL, 1, 4),
801 	FF(EQ6LPC_PER_I2C, EQ6LPC_PER_OCC, "i2c-clk", NULL, 1, 4),
802 	FF(EQ6LPC_PER_UART, EQ6LPC_PER_OCC, "uart-clk", NULL, 1, 4),
803 	FF(EQ6LPC_PER_SPI, EQ6LPC_PER_OCC, "spi-clk", NULL, 1, 4),
804 	FF(EQ6LPC_PER_PERIPH, EQ6LPC_PER_OCC, "periph-clk", NULL, 1, 1),
805 
806 	FF(EQ6LPC_VDI_OCC, EQ6LPC_PLL_VDI, "occ-vdi", NULL, 1, 1),
807 };
808 
809 static const struct eqc_early_match_data eqc_eyeq6lplus_early_match_data __initconst = {
810 	.early_clk_count	= ARRAY_SIZE(eqc_eyeq6lplus_early_clks),
811 	.early_clks		= eqc_eyeq6lplus_early_clks,
812 
813 	.late_clk_count		= ARRAY_SIZE(eqc_eyeq6lplus_clks),
814 };
815 
816 static const struct eqc_match_data eqc_eyeq6lplus_match_data = {
817 	.clk_count	= ARRAY_SIZE(eqc_eyeq6lplus_clks),
818 	.clks		= eqc_eyeq6lplus_clks,
819 
820 	.reset_auxdev_name = "reset",
821 	.pinctrl_auxdev_name = "pinctrl",
822 
823 	.early_clk_count = ARRAY_SIZE(eqc_eyeq6lplus_early_clks),
824 };
825 
826 static const struct eqc_match_data eqc_eyeq6h_west_match_data = {
827 	.reset_auxdev_name = "reset_west",
828 };
829 
830 static const struct eqc_clock eqc_eyeq6h_east_clks[] = {
831 	PLL_FRACG(0, PARENT_BY_FWNAME, "pll-east", "ref", 0x074),
832 };
833 
834 static const struct eqc_match_data eqc_eyeq6h_east_match_data = {
835 	.clk_count	= ARRAY_SIZE(eqc_eyeq6h_east_clks),
836 	.clks		= eqc_eyeq6h_east_clks,
837 
838 	.reset_auxdev_name = "reset_east",
839 };
840 
841 static const struct eqc_clock eqc_eyeq6h_south_clks[] = {
842 	PLL_FRACG(EQ6HC_SOUTH_PLL_VDI, PARENT_BY_FWNAME, "pll-vdi", "ref", 0x000),
843 	PLL_FRACG(EQ6HC_SOUTH_PLL_PCIE, PARENT_BY_FWNAME, "pll-pcie", "ref", 0x008),
844 	PLL_FRACG(EQ6HC_SOUTH_PLL_PER, PARENT_BY_FWNAME, "pll-per", "ref", 0x010),
845 	PLL_FRACG(EQ6HC_SOUTH_PLL_ISP, PARENT_BY_FWNAME, "pll-isp", "ref", 0x018),
846 
847 	DIV(EQ6HC_SOUTH_DIV_EMMC, EQ6HC_SOUTH_PLL_PER, "div-emmc", NULL, 0x070, 4, 4),
848 	DIV(EQ6HC_SOUTH_DIV_OSPI_REF, EQ6HC_SOUTH_PLL_PER, "div-ospi-ref", NULL, 0x090, 4, 4),
849 	DIV(EQ6HC_SOUTH_DIV_OSPI_SYS, EQ6HC_SOUTH_PLL_PER, "div-ospi-sys", NULL, 0x090, 8, 1),
850 	DIV(EQ6HC_SOUTH_DIV_TSU, EQ6HC_SOUTH_PLL_PCIE, "div-tsu", NULL, 0x098, 4, 8),
851 };
852 
853 static const struct eqc_match_data eqc_eyeq6h_south_match_data = {
854 	.clk_count	= ARRAY_SIZE(eqc_eyeq6h_south_clks),
855 	.clks		= eqc_eyeq6h_south_clks,
856 };
857 
858 static const struct eqc_clock eqc_eyeq6h_ddr0_clks[] = {
859 	PLL_FRACG(0, PARENT_BY_FWNAME, "pll-ddr0", "ref", 0x074),
860 };
861 
862 static const struct eqc_match_data eqc_eyeq6h_ddr0_match_data = {
863 	.clk_count	= ARRAY_SIZE(eqc_eyeq6h_ddr0_clks),
864 	.clks		= eqc_eyeq6h_ddr0_clks,
865 };
866 
867 static const struct eqc_clock eqc_eyeq6h_ddr1_clks[] = {
868 	PLL_FRACG(0, PARENT_BY_FWNAME, "pll-ddr1", "ref", 0x074),
869 };
870 
871 static const struct eqc_match_data eqc_eyeq6h_ddr1_match_data = {
872 	.clk_count	= ARRAY_SIZE(eqc_eyeq6h_ddr1_clks),
873 	.clks		= eqc_eyeq6h_ddr1_clks,
874 };
875 
876 static const struct eqc_clock eqc_eyeq6h_acc_clks[] = {
877 	PLL_FRACG(EQ6HC_ACC_PLL_XNN, PARENT_BY_FWNAME, "pll-xnn", "ref", 0x040),
878 	PLL_FRACG(EQ6HC_ACC_PLL_VMP, PARENT_BY_FWNAME, "pll-vmp", "ref", 0x050),
879 	PLL_FRACG(EQ6HC_ACC_PLL_PMA, PARENT_BY_FWNAME, "pll-pma", "ref", 0x05C),
880 	PLL_FRACG(EQ6HC_ACC_PLL_MPC, PARENT_BY_FWNAME, "pll-mpc", "ref", 0x068),
881 	PLL_FRACG(EQ6HC_ACC_PLL_NOC, PARENT_BY_FWNAME, "pll-noc", "ref", 0x070),
882 };
883 
884 static const struct eqc_match_data eqc_eyeq6h_acc_match_data = {
885 	.clk_count	= ARRAY_SIZE(eqc_eyeq6h_acc_clks),
886 	.clks		= eqc_eyeq6h_acc_clks,
887 
888 	.reset_auxdev_name = "reset_acc",
889 };
890 
891 static const struct eqc_clock eqc_eyeq7h_acc0_clks[] = {
892 	PLL_AINTP(EQ7HC_ACC_PLL_VMP, PARENT_BY_FWNAME, "pll-acc0-vmp", "ref_100p0", 0x400),
893 	PLL_AINTP(EQ7HC_ACC_PLL_MPC, PARENT_BY_FWNAME, "pll-acc0-mpc", "ref_100p0", 0x404),
894 	PLL_AINTP(EQ7HC_ACC_PLL_PMA, PARENT_BY_FWNAME, "pll-acc0-pma", "ref_100p0", 0x408),
895 	PLL_AINTP(EQ7HC_ACC_PLL_NOC, PARENT_BY_FWNAME, "pll-acc0-noc-acc", "ref_106p6", 0x40c),
896 
897 	FF(EQ7HC_ACC_DIV_PMA, EQ7HC_ACC_PLL_PMA, "acc0_pma", NULL, 1, 2),
898 	FF(EQ7HC_ACC_DIV_NCORE, EQ7HC_ACC_PLL_NOC, "acc0_ncore", NULL, 1, 2),
899 	FF(EQ7HC_ACC_DIV_CFG, EQ7HC_ACC_PLL_NOC, "acc0_cfg", NULL, 1, 8),
900 };
901 
902 static const struct eqc_match_data eqc_eyeq7h_acc0_match_data = {
903 	.clk_count	= ARRAY_SIZE(eqc_eyeq7h_acc0_clks),
904 	.clks		= eqc_eyeq7h_acc0_clks,
905 
906 	.reset_auxdev_name = "reset_acc0",
907 };
908 
909 static const struct eqc_clock eqc_eyeq7h_acc1_clks[] = {
910 	PLL_AINTP(EQ7HC_ACC_PLL_VMP, PARENT_BY_FWNAME, "pll-acc1-vmp", "ref_100p0", 0x400),
911 	PLL_AINTP(EQ7HC_ACC_PLL_MPC, PARENT_BY_FWNAME, "pll-acc1-mpc", "ref_100p0", 0x404),
912 	PLL_AINTP(EQ7HC_ACC_PLL_PMA, PARENT_BY_FWNAME, "pll-acc1-pma", "ref_100p0", 0x408),
913 	PLL_AINTP(EQ7HC_ACC_PLL_NOC, PARENT_BY_FWNAME, "pll-acc1-noc-acc", "ref_106p6", 0x40c),
914 };
915 
916 static const struct eqc_match_data eqc_eyeq7h_acc1_match_data = {
917 	.clk_count	= ARRAY_SIZE(eqc_eyeq7h_acc1_clks),
918 	.clks		= eqc_eyeq7h_acc1_clks,
919 
920 	.reset_auxdev_name = "reset_acc1",
921 };
922 
923 static const struct clk_div_table eqc_eyeq7h_ddr_apb_div_table[] = {
924 	{ .val = 0, .div = 8 },
925 	{ .val = 1, .div = 128 },
926 	{ .val = 0, .div = 0 },
927 };
928 
929 static const struct clk_div_table eqc_eyeq7h_ddr_ref_div_table[] = {
930 	{ .val = 0, .div = 2 },
931 	{ .val = 1, .div = 8 },
932 	{ .val = 0, .div = 0 },
933 };
934 
935 static const struct clk_div_table eqc_eyeq7h_ddr_dfi_div_table[] = {
936 	{ .val = 0, .div = 2 },
937 	{ .val = 1, .div = 32 },
938 	{ .val = 0, .div = 0 },
939 };
940 
941 static const struct eqc_clock eqc_eyeq7h_ddr0_clks[] = {
942 	PLL_AINTP(EQ7HC_DDR_PLL, PARENT_BY_FWNAME, "pll-ddr0", "ref", 0x0),
943 
944 	/* A single bit configures the 3 dividers below */
945 	DIV_TABLE_RO(EQ7HC_DDR_DIV_APB, EQ7HC_DDR_PLL, "div-ddr0_apb", NULL,
946 		     0x08, 10, 1, eqc_eyeq7h_ddr_apb_div_table),
947 	DIV_TABLE_RO(EQ7HC_DDR_DIV_PLLREF, EQ7HC_DDR_PLL, "div-ddr0_pllref", NULL,
948 		     0x08, 10, 1, eqc_eyeq7h_ddr_ref_div_table),
949 	DIV_TABLE_RO(EQ7HC_DDR_DIV_DFI, EQ7HC_DDR_PLL, "div-ddr0-dfi", NULL,
950 		     0x08, 10, 1, eqc_eyeq7h_ddr_dfi_div_table),
951 };
952 
953 static const struct eqc_match_data eqc_eyeq7h_ddr0_match_data = {
954 	.clk_count	= ARRAY_SIZE(eqc_eyeq7h_ddr0_clks),
955 	.clks		= eqc_eyeq7h_ddr0_clks,
956 
957 	.reset_auxdev_name = "reset_ddr0",
958 };
959 
960 static const struct eqc_clock eqc_eyeq7h_ddr1_clks[] = {
961 	PLL_AINTP(EQ7HC_DDR_PLL, PARENT_BY_FWNAME, "pll-ddr1", "ref", 0x0),
962 
963 	/* A single bit configures the 3 dividers below */
964 	DIV_TABLE_RO(EQ7HC_DDR_DIV_APB, EQ7HC_DDR_PLL, "div-ddr1_apb", NULL,
965 		     0x08, 10, 1, eqc_eyeq7h_ddr_apb_div_table),
966 	DIV_TABLE_RO(EQ7HC_DDR_DIV_PLLREF, EQ7HC_DDR_PLL, "div-ddr1_pllref", NULL,
967 		     0x08, 10, 1, eqc_eyeq7h_ddr_ref_div_table),
968 	DIV_TABLE_RO(EQ7HC_DDR_DIV_DFI, EQ7HC_DDR_PLL, "div-ddr1-dfi", NULL,
969 		     0x08, 10, 1, eqc_eyeq7h_ddr_dfi_div_table),
970 };
971 
972 static const struct eqc_match_data eqc_eyeq7h_ddr1_match_data = {
973 	.clk_count	= ARRAY_SIZE(eqc_eyeq7h_ddr1_clks),
974 	.clks		= eqc_eyeq7h_ddr1_clks,
975 
976 	.reset_auxdev_name = "reset_ddr1",
977 };
978 
979 static const struct eqc_clock eqc_eyeq7h_east_clocks[] = {
980 	PLL_JFRACR(EQ7HC_EAST_PLL_106P6, PARENT_BY_FWNAME, "pll-106p6-e", "ref", 0x00),
981 
982 	FF(EQ7HC_EAST_DIV_REF_106P6, EQ7HC_EAST_PLL_106P6, "ref_106p6_e", NULL, 1, 40),
983 
984 	PLL_AINTP(EQ7HC_EAST_PLL_NOC, EQ7HC_EAST_DIV_REF_106P6, "pll-noc-e", NULL, 0x30),
985 	PLL_AINTP(EQ7HC_EAST_PLL_ISP, PARENT_BY_FWNAME, "pll-isp", "ref_100p0", 0x38),
986 	PLL_AINTP(EQ7HC_EAST_PLL_VEU, PARENT_BY_FWNAME, "pll-veu", "ref_100p0", 0x40),
987 
988 	FF(EQ7HC_EAST_DIV_REF_DDR_PHY, EQ7HC_EAST_PLL_106P6, "ref_ddr_phy_e", NULL, 1, 2),
989 
990 	FF(EQ7HC_EAST_DIV_CORE, EQ7HC_EAST_PLL_NOC, "core_e", NULL, 1, 2),
991 	FF(EQ7HC_EAST_DIV_CORE_MBIST, EQ7HC_EAST_PLL_NOC, "core_mbist_e", NULL, 1, 2),
992 	FF(EQ7HC_EAST_DIV_ISRAM_MBIST, EQ7HC_EAST_PLL_NOC, "isram_mbist_e", NULL, 1, 2),
993 	FF(EQ7HC_EAST_DIV_CFG, EQ7HC_EAST_PLL_NOC, "cfg_e", NULL, 1, 4),
994 
995 	FF(EQ7HC_EAST_DIV_VEU_CORE, EQ7HC_EAST_PLL_VEU, "veu_core", NULL, 1, 4),
996 	FF(EQ7HC_EAST_DIV_VEU_MBIST, EQ7HC_EAST_PLL_VEU, "veu_mbist", NULL, 1, 4),
997 	FF(EQ7HC_EAST_DIV_VEU_OCP, EQ7HC_EAST_PLL_VEU, "veu_ocp", NULL, 1, 16),
998 
999 	FF(EQ7HC_EAST_DIV_LBITS, EQ7HC_EAST_PLL_ISP, "lbits_e", NULL, 1, 48),
1000 	FF(EQ7HC_EAST_DIV_ISP0_CORE, EQ7HC_EAST_PLL_ISP, "isp0_core", NULL, 1, 2),
1001 };
1002 
1003 static const struct eqc_match_data eqc_eyeq7h_east_match_data = {
1004 	.clk_count = ARRAY_SIZE(eqc_eyeq7h_east_clocks),
1005 	.clks = eqc_eyeq7h_east_clocks,
1006 
1007 	.reset_auxdev_name = "reset_east",
1008 };
1009 
1010 static const struct eqc_clock eqc_eyeq7h_mips0_clks[] = {
1011 	PLL_AINTP(EQ7HC_MIPS_PLL_CPU, PARENT_BY_FWNAME, "pll-cpu0", "ref", 0x0),
1012 
1013 	FF(EQ7HC_MIPS_DIV_CM, EQ7HC_MIPS_PLL_CPU, "mips0_cm", NULL, 1, 2),
1014 };
1015 
1016 static const struct eqc_match_data eqc_eyeq7h_mips0_match_data = {
1017 	.clk_count	= ARRAY_SIZE(eqc_eyeq7h_mips0_clks),
1018 	.clks		= eqc_eyeq7h_mips0_clks,
1019 };
1020 
1021 static const struct eqc_clock eqc_eyeq7h_mips1_clks[] = {
1022 	PLL_AINTP(EQ7HC_MIPS_PLL_CPU, PARENT_BY_FWNAME, "pll-cpu1", "ref", 0x0),
1023 
1024 	FF(EQ7HC_MIPS_DIV_CM, EQ7HC_MIPS_PLL_CPU, "mips1_cm", NULL, 1, 2),
1025 };
1026 
1027 static const struct eqc_match_data eqc_eyeq7h_mips1_match_data = {
1028 	.clk_count	= ARRAY_SIZE(eqc_eyeq7h_mips1_clks),
1029 	.clks		= eqc_eyeq7h_mips1_clks,
1030 };
1031 
1032 static const struct eqc_clock eqc_eyeq7h_mips2_clks[] = {
1033 	PLL_AINTP(EQ7HC_MIPS_PLL_CPU, PARENT_BY_FWNAME, "pll-cpu2", "ref", 0x0),
1034 
1035 	FF(EQ7HC_MIPS_DIV_CM, EQ7HC_MIPS_PLL_CPU, "mips2_cm", NULL, 1, 2),
1036 };
1037 
1038 static const struct eqc_match_data eqc_eyeq7h_mips2_match_data = {
1039 	.clk_count	= ARRAY_SIZE(eqc_eyeq7h_mips2_clks),
1040 	.clks		= eqc_eyeq7h_mips2_clks,
1041 };
1042 
1043 static const struct eqc_clock eqc_eyeq7h_periph_east_clks[] = {
1044 	PLL_AINTP(EQ7HC_PERIPH_EAST_PLL_PER, PARENT_BY_FWNAME, "pll-periph_east_per", "ref", 0x0),
1045 
1046 	FF(EQ7HC_PERIPH_EAST_DIV_PER, EQ7HC_PERIPH_EAST_PLL_PER, "periph_e", NULL, 1, 10),
1047 };
1048 
1049 static const struct eqc_match_data eqc_eyeq7h_periph_east_match_data = {
1050 	.clk_count	= ARRAY_SIZE(eqc_eyeq7h_periph_east_clks),
1051 	.clks		= eqc_eyeq7h_periph_east_clks,
1052 
1053 	.reset_auxdev_name = "reset_periph_east",
1054 };
1055 
1056 static const struct eqc_clock eqc_eyeq7h_periph_west_clks[] = {
1057 	PLL_AINTP(EQ7HC_PERIPH_WEST_PLL_PER, PARENT_BY_FWNAME,
1058 		  "pll-periph_west_per", "ref_100p0", 0x0),
1059 	PLL_AINTP(EQ7HC_PERIPH_WEST_PLL_I2S, PARENT_BY_FWNAME,
1060 		  "pll-periph_west_i2s", "ref_106p6", 0x4),
1061 
1062 	FF(EQ7HC_PERIPH_WEST_DIV_PER, EQ7HC_PERIPH_WEST_PLL_PER, "periph_w", NULL, 1, 10),
1063 	FF(EQ7HC_PERIPH_WEST_DIV_I2S, EQ7HC_PERIPH_WEST_PLL_I2S, "periph_i2s_ser_w", NULL, 1, 100),
1064 };
1065 
1066 static const struct eqc_match_data eqc_eyeq7h_periph_west_match_data = {
1067 	.clk_count	= ARRAY_SIZE(eqc_eyeq7h_periph_west_clks),
1068 	.clks		= eqc_eyeq7h_periph_west_clks,
1069 
1070 	.reset_auxdev_name = "reset_periph_west",
1071 };
1072 
1073 static const struct eqc_clock eqc_eyeq7h_south_clks[] = {
1074 	PLL_JFRACR(EQ7HC_SOUTH_PLL_100P0, PARENT_BY_FWNAME, "pll-100p0", "ref", 0x40),
1075 
1076 	FF(EQ7HC_SOUTH_DIV_REF_100P0, EQ7HC_SOUTH_PLL_100P0, "ref_100p0", NULL, 1, 48),
1077 
1078 	PLL_AINTP(EQ7HC_SOUTH_PLL_XSPI, EQ7HC_SOUTH_DIV_REF_100P0, "pll-xspi", NULL, 0x10),
1079 	PLL_AINTP(EQ7HC_SOUTH_PLL_VDIO, EQ7HC_SOUTH_DIV_REF_100P0, "pll-vdio", NULL, 0x18),
1080 	PLL_AINTP(EQ7HC_SOUTH_PLL_PER, EQ7HC_SOUTH_DIV_REF_100P0, "pll-per-s", NULL, 0x20),
1081 
1082 	FF(EQ7HC_SOUTH_DIV_VDO_DSI_SYS, EQ7HC_SOUTH_PLL_100P0, "vdo_dsi_sys", NULL, 1, 9),
1083 	FF(EQ7HC_SOUTH_DIV_PMA_CMN_REF, EQ7HC_SOUTH_PLL_100P0, "pma_cmn_ref", NULL, 1, 48),
1084 	FF(EQ7HC_SOUTH_DIV_REF_UFS, EQ7HC_SOUTH_PLL_100P0, "ref_ufs", NULL, 1, 250),
1085 	FF(EQ7HC_SOUTH_DIV_XSPI_SYS, EQ7HC_SOUTH_PLL_XSPI, "xspi_sys", NULL, 1, 8),
1086 	FF(EQ7HC_SOUTH_DIV_XSPI_MBIST, EQ7HC_SOUTH_PLL_XSPI, "xspi_mbist", NULL, 1, 8),
1087 	FF(EQ7HC_SOUTH_DIV_NOC_S, EQ7HC_SOUTH_PLL_PER, "noc_s", NULL, 1, 2),
1088 	FF(EQ7HC_SOUTH_DIV_PCIE_SYS, EQ7HC_SOUTH_PLL_PER, "pcie_sys", NULL, 1, 4),
1089 	FF(EQ7HC_SOUTH_DIV_PCIE_SYS_MBIST, EQ7HC_SOUTH_PLL_PER, "pcie_sys_mbist", NULL, 1, 4),
1090 	FF(EQ7HC_SOUTH_DIV_PCIE_GBE_PHY, EQ7HC_SOUTH_PLL_PER, "pcie_gbe_phy_apb", NULL, 1, 16),
1091 	FF(EQ7HC_SOUTH_DIV_UFS_CORE, EQ7HC_SOUTH_PLL_PER, "ufs_core", NULL, 1, 8),
1092 	FF(EQ7HC_SOUTH_DIV_UFS_SMS, EQ7HC_SOUTH_PLL_PER, "ufs_sms", NULL, 1, 5),
1093 	FF(EQ7HC_SOUTH_DIV_UFS_ROM_SMS, EQ7HC_SOUTH_PLL_PER, "ufs_rom_sms", NULL, 1, 5),
1094 	FF(EQ7HC_SOUTH_DIV_ETH_SYS, EQ7HC_SOUTH_PLL_PER, "eth_sys", NULL, 1, 8),
1095 	FF(EQ7HC_SOUTH_DIV_ETH_MBIST, EQ7HC_SOUTH_PLL_PER, "eth_mbist", NULL, 1, 8),
1096 	FF(EQ7HC_SOUTH_DIV_CFG_S, EQ7HC_SOUTH_PLL_PER, "cfg_s", NULL, 1, 8),
1097 	FF(EQ7HC_SOUTH_DIV_TSU, EQ7HC_SOUTH_PLL_PER, "tsu", NULL, 1, 64),
1098 	FF(EQ7HC_SOUTH_DIV_VDIO, EQ7HC_SOUTH_PLL_VDIO, "vdio", NULL, 1, 4),
1099 	FF(EQ7HC_SOUTH_DIV_VDIO_CORE, EQ7HC_SOUTH_PLL_VDIO, "vdio_core", NULL, 1, 4),
1100 	FF(EQ7HC_SOUTH_DIV_VDIO_CORE_MBIST, EQ7HC_SOUTH_PLL_VDIO, "vdio_core_mbist", NULL, 1, 4),
1101 	FF(EQ7HC_SOUTH_DIV_VDO_CORE_MBIST, EQ7HC_SOUTH_PLL_VDIO, "vdo_core_mbist", NULL, 1, 4),
1102 	FF(EQ7HC_SOUTH_DIV_VDO_P, EQ7HC_SOUTH_PLL_VDIO, "vdo_p", NULL, 1, 40),
1103 	FF(EQ7HC_SOUTH_DIV_VDIO_CFG, EQ7HC_SOUTH_PLL_VDIO, "vdio_cfg", NULL, 1, 150),
1104 	FF(EQ7HC_SOUTH_DIV_VDIO_TXCLKESC, EQ7HC_SOUTH_PLL_VDIO, "vdio_txclkesc", NULL, 1, 8),
1105 };
1106 
1107 static const struct eqc_match_data eqc_eyeq7h_south_match_data = {
1108 	.clk_count	= ARRAY_SIZE(eqc_eyeq7h_south_clks),
1109 	.clks		= eqc_eyeq7h_south_clks,
1110 
1111 	.reset_auxdev_name = "reset_south",
1112 };
1113 
1114 static const struct eqc_clock eqc_eyeq7h_west_clks[] = {
1115 	PLL_JFRACR(EQ7HC_WEST_PLL_106P6, PARENT_BY_FWNAME, "pll-106p6-w", "ref", 0x0),
1116 
1117 	FF(EQ7HC_WEST_DIV_REF_106P6, EQ7HC_WEST_PLL_106P6, "ref_106p6_w", NULL, 1, 40),
1118 
1119 	PLL_AINTP(EQ7HC_WEST_PLL_NOC, EQ7HC_WEST_DIV_REF_106P6, "pll-noc-w", NULL, 0x30),
1120 	PLL_AINTP(EQ7HC_WEST_PLL_GPU, PARENT_BY_FWNAME, "pll-gpu", "ref_100p0", 0x38),
1121 	PLL_AINTP(EQ7HC_WEST_PLL_SSI, PARENT_BY_FWNAME, "pll-ssi", "ref_100p0", 0x40),
1122 
1123 	FF(EQ7HC_WEST_DIV_GPU, EQ7HC_WEST_PLL_GPU, "gpu", NULL, 1, 2),
1124 	FF(EQ7HC_WEST_DIV_GPU_MBIST, EQ7HC_WEST_PLL_GPU, "gpu_mbist", NULL, 1, 2),
1125 	FF(EQ7HC_WEST_DIV_LBITS, EQ7HC_WEST_PLL_GPU, "lbits_w", NULL, 1, 40),
1126 	FF(EQ7HC_WEST_DIV_MIPS_TIMER, EQ7HC_WEST_PLL_SSI, "mips_timer", NULL, 1, 24),
1127 	FF(EQ7HC_WEST_DIV_SSI_CORE, EQ7HC_WEST_PLL_SSI, "ssi_core", NULL, 1, 2),
1128 	FF(EQ7HC_WEST_DIV_SSI_CORE_MBIST, EQ7HC_WEST_PLL_SSI, "ssi_core_mbist", NULL, 1, 2),
1129 	FF(EQ7HC_WEST_DIV_SSI_ROM, EQ7HC_WEST_PLL_SSI, "ssi_rom", NULL, 1, 8),
1130 	FF(EQ7HC_WEST_DIV_SSI_ROM_MBIST, EQ7HC_WEST_PLL_SSI, "ssi_rom_mbist", NULL, 1, 8),
1131 	FF(EQ7HC_WEST_DIV_REF_DDR_PHY, EQ7HC_WEST_PLL_106P6, "ref_ddr_phy_w", NULL, 1, 2),
1132 	FF(EQ7HC_WEST_DIV_CORE, EQ7HC_WEST_PLL_NOC, "core_w", NULL, 1, 2),
1133 	FF(EQ7HC_WEST_DIV_CORE_MBIST, EQ7HC_WEST_PLL_NOC, "core_mbist_w", NULL, 1, 2),
1134 	FF(EQ7HC_WEST_DIV_CFG, EQ7HC_WEST_PLL_NOC, "cfg_w", NULL, 1, 4),
1135 	FF(EQ7HC_WEST_DIV_CAU, EQ7HC_WEST_PLL_NOC, "cau_w", NULL, 1, 8),
1136 	FF(EQ7HC_WEST_DIV_CAU_MBIST, EQ7HC_WEST_PLL_NOC, "cau_mbist_w", NULL, 1, 8),
1137 };
1138 
1139 static const struct eqc_match_data eqc_eyeq7h_west_match_data = {
1140 	.clk_count	= ARRAY_SIZE(eqc_eyeq7h_west_clks),
1141 	.clks		= eqc_eyeq7h_west_clks,
1142 
1143 	.reset_auxdev_name = "reset_west",
1144 };
1145 
1146 static const struct eqc_clock eqc_eyeq7h_xnn0_clks[] = {
1147 	PLL_AINTP(EQ7HC_XNN_PLL_XNN0, PARENT_BY_FWNAME, "pll-xnn0-0", "ref_100p0", 0x400),
1148 	PLL_AINTP(EQ7HC_XNN_PLL_XNN1, PARENT_BY_FWNAME, "pll-xnn0-1", "ref_100p0", 0x404),
1149 	PLL_AINTP(EQ7HC_XNN_PLL_XNN2, PARENT_BY_FWNAME, "pll-xnn0-2", "ref_100p0", 0x408),
1150 	PLL_AINTP(EQ7HC_XNN_PLL_CLSTR, PARENT_BY_FWNAME, "pll-xnn0-clstr", "ref_106p6", 0x410),
1151 
1152 	FF(EQ7HC_XNN_DIV_XNN0, EQ7HC_XNN_PLL_XNN0, "xnn0", NULL, 1, 2),
1153 	FF(EQ7HC_XNN_DIV_XNN1, EQ7HC_XNN_PLL_XNN1, "xnn1", NULL, 1, 2),
1154 	FF(EQ7HC_XNN_DIV_XNN2, EQ7HC_XNN_PLL_XNN2, "xnn2", NULL, 1, 2),
1155 	FF(EQ7HC_XNN_DIV_CLSTR, EQ7HC_XNN_PLL_CLSTR, "xnn0_clstr", NULL, 1, 2),
1156 	FF(EQ7HC_XNN_DIV_I2, EQ7HC_XNN_PLL_CLSTR, "xnn0_i2", NULL, 1, 4),
1157 	FF(EQ7HC_XNN_DIV_I2_SMS, EQ7HC_XNN_PLL_CLSTR, "xnn0_i2_sms", NULL, 1, 4),
1158 	FF(EQ7HC_XNN_DIV_CFG, EQ7HC_XNN_PLL_CLSTR, "xnn0_cfg", NULL, 1, 8),
1159 };
1160 
1161 static const struct eqc_match_data eqc_eyeq7h_xnn0_match_data = {
1162 	.clk_count	= ARRAY_SIZE(eqc_eyeq7h_xnn0_clks),
1163 	.clks		= eqc_eyeq7h_xnn0_clks,
1164 
1165 	.reset_auxdev_name = "reset_xnn0",
1166 };
1167 
1168 static const struct eqc_clock eqc_eyeq7h_xnn1_clks[] = {
1169 	PLL_AINTP(EQ7HC_XNN_PLL_XNN0, PARENT_BY_FWNAME, "pll-xnn1-0", "ref_100p0", 0x400),
1170 	PLL_AINTP(EQ7HC_XNN_PLL_XNN1, PARENT_BY_FWNAME, "pll-xnn1-1", "ref_100p0", 0x404),
1171 	PLL_AINTP(EQ7HC_XNN_PLL_XNN2, PARENT_BY_FWNAME, "pll-xnn1-2", "ref_100p0", 0x408),
1172 	PLL_AINTP(EQ7HC_XNN_PLL_CLSTR, PARENT_BY_FWNAME, "pll-xnn1-clstr", "ref_106p6", 0x410),
1173 };
1174 
1175 static const struct eqc_match_data eqc_eyeq7h_xnn1_match_data = {
1176 	.clk_count	= ARRAY_SIZE(eqc_eyeq7h_xnn1_clks),
1177 	.clks		= eqc_eyeq7h_xnn1_clks,
1178 
1179 	.reset_auxdev_name = "reset_xnn1",
1180 };
1181 
1182 static const struct of_device_id eqc_match_table[] = {
1183 	{ .compatible = "mobileye,eyeq5-olb", .data = &eqc_eyeq5_match_data },
1184 	{ .compatible = "mobileye,eyeq6l-olb", .data = &eqc_eyeq6l_match_data },
1185 	{ .compatible = "mobileye,eyeq6lplus-olb", .data = &eqc_eyeq6lplus_match_data },
1186 	{ .compatible = "mobileye,eyeq6h-central-olb" /* no data, early only */ },
1187 	{ .compatible = "mobileye,eyeq6h-west-olb", .data = &eqc_eyeq6h_west_match_data },
1188 	{ .compatible = "mobileye,eyeq6h-east-olb", .data = &eqc_eyeq6h_east_match_data },
1189 	{ .compatible = "mobileye,eyeq6h-south-olb", .data = &eqc_eyeq6h_south_match_data },
1190 	{ .compatible = "mobileye,eyeq6h-ddr0-olb", .data = &eqc_eyeq6h_ddr0_match_data },
1191 	{ .compatible = "mobileye,eyeq6h-ddr1-olb", .data = &eqc_eyeq6h_ddr1_match_data },
1192 	{ .compatible = "mobileye,eyeq6h-acc-olb", .data = &eqc_eyeq6h_acc_match_data },
1193 	{ .compatible = "mobileye,eyeq7h-acc0-olb", .data = &eqc_eyeq7h_acc0_match_data },
1194 	{ .compatible = "mobileye,eyeq7h-acc1-olb", .data = &eqc_eyeq7h_acc1_match_data },
1195 	{ .compatible = "mobileye,eyeq7h-ddr0-olb", .data = &eqc_eyeq7h_ddr0_match_data },
1196 	{ .compatible = "mobileye,eyeq7h-ddr1-olb", .data = &eqc_eyeq7h_ddr1_match_data },
1197 	{ .compatible = "mobileye,eyeq7h-east-olb", .data = &eqc_eyeq7h_east_match_data },
1198 	{ .compatible = "mobileye,eyeq7h-mips0-olb", .data = &eqc_eyeq7h_mips0_match_data },
1199 	{ .compatible = "mobileye,eyeq7h-mips1-olb", .data = &eqc_eyeq7h_mips1_match_data },
1200 	{ .compatible = "mobileye,eyeq7h-mips2-olb", .data = &eqc_eyeq7h_mips2_match_data },
1201 	{ .compatible = "mobileye,eyeq7h-periph-east-olb",
1202 	  .data = &eqc_eyeq7h_periph_east_match_data },
1203 	{ .compatible = "mobileye,eyeq7h-periph-west-olb",
1204 	  .data = &eqc_eyeq7h_periph_west_match_data },
1205 	{ .compatible = "mobileye,eyeq7h-south-olb", .data = &eqc_eyeq7h_south_match_data },
1206 	{ .compatible = "mobileye,eyeq7h-west-olb", .data = &eqc_eyeq7h_west_match_data },
1207 	{ .compatible = "mobileye,eyeq7h-xnn0-olb", .data = &eqc_eyeq7h_xnn0_match_data },
1208 	{ .compatible = "mobileye,eyeq7h-xnn1-olb", .data = &eqc_eyeq7h_xnn1_match_data },
1209 	{}
1210 };
1211 
1212 static struct platform_driver eqc_driver = {
1213 	.probe = eqc_probe,
1214 	.driver = {
1215 		.name = "clk-eyeq",
1216 		.of_match_table = eqc_match_table,
1217 		.suppress_bind_attrs = true,
1218 	},
1219 };
1220 builtin_platform_driver(eqc_driver);
1221 
1222 /* Required early for GIC timer. */
1223 static const struct eqc_clock eqc_eyeq6h_central_early_clks[] = {
1224 	PLL_FRACG(EQ6HC_CENTRAL_PLL_CPU, PARENT_BY_FWNAME, "pll-cpu", "ref", 0x02C),
1225 
1226 	FF(EQ6HC_CENTRAL_CPU_OCC, EQ6HC_CENTRAL_PLL_CPU, "occ-cpu", NULL, 1, 1),
1227 };
1228 
1229 static const struct eqc_early_match_data eqc_eyeq6h_central_early_match_data __initconst = {
1230 	.early_clk_count	= ARRAY_SIZE(eqc_eyeq6h_central_early_clks),
1231 	.early_clks		= eqc_eyeq6h_central_early_clks,
1232 };
1233 
1234 /* Required early for UART. */
1235 static const struct eqc_clock eqc_eyeq6h_west_early_clks[] = {
1236 	PLL_FRACG(EQ6HC_WEST_PLL_PER, PARENT_BY_FWNAME, "pll-west", "ref", 0x074),
1237 
1238 	FF(EQ6HC_WEST_PER_OCC, EQ6HC_WEST_PLL_PER, "west-per-occ", NULL, 1, 10),
1239 	FF(EQ6HC_WEST_PER_UART, EQ6HC_WEST_PER_OCC, "west-per-uart", NULL, 1, 1),
1240 };
1241 
1242 static const struct eqc_early_match_data eqc_eyeq6h_west_early_match_data __initconst = {
1243 	.early_clk_count	= ARRAY_SIZE(eqc_eyeq6h_west_early_clks),
1244 	.early_clks		= eqc_eyeq6h_west_early_clks,
1245 };
1246 
1247 static void __init eqc_early_init(struct device_node *np,
1248 				  const struct eqc_early_match_data *early_data)
1249 {
1250 	struct clk_hw_onecell_data *cells;
1251 	unsigned int i, clk_count;
1252 	void __iomem *base;
1253 	int ret;
1254 
1255 	clk_count = early_data->early_clk_count + early_data->late_clk_count;
1256 	cells = kzalloc_flex(*cells, hws, clk_count);
1257 	if (!cells) {
1258 		ret = -ENOMEM;
1259 		goto err;
1260 	}
1261 
1262 	cells->num = clk_count;
1263 
1264 	/*
1265 	 * Mark all clocks as deferred; some are registered here, the rest at
1266 	 * platform device probe.
1267 	 *
1268 	 * Once the platform device is probed, its provider will take priority
1269 	 * when looking up clocks.
1270 	 */
1271 	for (i = 0; i < clk_count; i++)
1272 		cells->hws[i] = ERR_PTR(-EPROBE_DEFER);
1273 
1274 	/* Offsets (reg64) of early PLLs are relative to OLB block. */
1275 	base = of_iomap(np, 0);
1276 	if (!base) {
1277 		ret = -ENODEV;
1278 		goto err;
1279 	}
1280 
1281 	for (i = 0; i < early_data->early_clk_count; i++) {
1282 		const struct eqc_clock *clk = &early_data->early_clks[i];
1283 
1284 		if (clk->probe)
1285 			ret = clk->probe(NULL, np, clk, base, cells);
1286 		else
1287 			ret = -EINVAL;
1288 		if (ret) {
1289 			pr_err("failed registering %s\n", clk->name);
1290 			goto err;
1291 		}
1292 	}
1293 
1294 	ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, cells);
1295 	if (ret) {
1296 		pr_err("failed registering clk provider: %d\n", ret);
1297 		goto err;
1298 	}
1299 
1300 	return;
1301 
1302 err:
1303 	/*
1304 	 * We are doomed. The system will not be able to boot.
1305 	 *
1306 	 * Let's still try to be good citizens by freeing resources and print
1307 	 * a last error message that might help debugging.
1308 	 */
1309 
1310 	pr_err("failed clk init: %d\n", ret);
1311 
1312 	if (cells) {
1313 		of_clk_del_provider(np);
1314 
1315 		for (i = 0; i < early_data->early_clk_count; i++) {
1316 			const struct eqc_clock *clk = &early_data->early_clks[i];
1317 			struct clk_hw *hw = cells->hws[clk->index];
1318 
1319 			if (!IS_ERR_OR_NULL(hw) && clk->unregister)
1320 				clk->unregister(hw);
1321 		}
1322 
1323 		kfree(cells);
1324 	}
1325 }
1326 
1327 static void __init eqc_eyeq5_early_init(struct device_node *np)
1328 {
1329 	eqc_early_init(np, &eqc_eyeq5_early_match_data);
1330 }
1331 CLK_OF_DECLARE_DRIVER(eqc_eyeq5, "mobileye,eyeq5-olb", eqc_eyeq5_early_init);
1332 
1333 static void __init eqc_eyeq6h_central_early_init(struct device_node *np)
1334 {
1335 	eqc_early_init(np, &eqc_eyeq6h_central_early_match_data);
1336 }
1337 CLK_OF_DECLARE_DRIVER(eqc_eyeq6h_central, "mobileye,eyeq6h-central-olb",
1338 		      eqc_eyeq6h_central_early_init);
1339 
1340 static void __init eqc_eyeq6h_west_early_init(struct device_node *np)
1341 {
1342 	eqc_early_init(np, &eqc_eyeq6h_west_early_match_data);
1343 }
1344 CLK_OF_DECLARE_DRIVER(eqc_eyeq6h_west, "mobileye,eyeq6h-west-olb",
1345 		      eqc_eyeq6h_west_early_init);
1346 
1347 static void __init eqc_eyeq6lplus_early_init(struct device_node *np)
1348 {
1349 	eqc_early_init(np, &eqc_eyeq6lplus_early_match_data);
1350 }
1351 CLK_OF_DECLARE_DRIVER(eqc_eyeq6lplus, "mobileye,eyeq6lplus-olb", eqc_eyeq6lplus_early_init);
1352