2
2
/*
3
3
* PLL clock driver for the Mobileye EyeQ5, EyeQ6L and EyeQ6H platforms.
4
4
*
5
- * This controller handles read-only PLLs, all derived from the same main
6
- * crystal clock. It also exposes divider clocks, those are children to PLLs.
7
- * Parent clock is expected to be constant. This driver's registers live in
8
- * a shared region called OLB. Some PLLs are initialised early by of_clk_init();
9
- * if so, two clk providers are registered.
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.
10
13
*
11
14
* We use eqc_ as prefix, as-in "EyeQ Clock", but way shorter.
12
15
*
@@ -86,13 +89,24 @@ struct eqc_div {
86
89
u8 width ;
87
90
};
88
91
92
+ struct eqc_fixed_factor {
93
+ unsigned int index ;
94
+ const char * name ;
95
+ unsigned int mult ;
96
+ unsigned int div ;
97
+ unsigned int parent ;
98
+ };
99
+
89
100
struct eqc_match_data {
90
101
unsigned int pll_count ;
91
102
const struct eqc_pll * plls ;
92
103
93
104
unsigned int div_count ;
94
105
const struct eqc_div * divs ;
95
106
107
+ unsigned int fixed_factor_count ;
108
+ const struct eqc_fixed_factor * fixed_factors ;
109
+
96
110
const char * reset_auxdev_name ;
97
111
const char * pinctrl_auxdev_name ;
98
112
@@ -103,6 +117,9 @@ struct eqc_early_match_data {
103
117
unsigned int early_pll_count ;
104
118
const struct eqc_pll * early_plls ;
105
119
120
+ unsigned int early_fixed_factor_count ;
121
+ const struct eqc_fixed_factor * early_fixed_factors ;
122
+
106
123
/*
107
124
* We want our of_xlate callback to EPROBE_DEFER instead of dev_err()
108
125
* and EINVAL. For that, we must know the total clock count.
@@ -276,6 +293,35 @@ static void eqc_probe_init_divs(struct device *dev, const struct eqc_match_data
276
293
}
277
294
}
278
295
296
+ static void eqc_probe_init_fixed_factors (struct device * dev ,
297
+ const struct eqc_match_data * data ,
298
+ struct clk_hw_onecell_data * cells )
299
+ {
300
+ const struct eqc_fixed_factor * ff ;
301
+ struct clk_hw * hw , * parent_hw ;
302
+ unsigned int i ;
303
+
304
+ for (i = 0 ; i < data -> fixed_factor_count ; i ++ ) {
305
+ ff = & data -> fixed_factors [i ];
306
+ parent_hw = cells -> hws [ff -> parent ];
307
+
308
+ if (IS_ERR (parent_hw )) {
309
+ /* Parent is in early clk provider. */
310
+ hw = clk_hw_register_fixed_factor_index (dev , ff -> name ,
311
+ ff -> parent , 0 , ff -> mult , ff -> div );
312
+ } else {
313
+ /* Avoid clock lookup when we already have the hw reference. */
314
+ hw = clk_hw_register_fixed_factor_parent_hw (dev , ff -> name ,
315
+ parent_hw , 0 , ff -> mult , ff -> div );
316
+ }
317
+
318
+ cells -> hws [ff -> index ] = hw ;
319
+ if (IS_ERR (hw ))
320
+ dev_warn (dev , "failed registering %s: %pe\n" ,
321
+ ff -> name , hw );
322
+ }
323
+ }
324
+
279
325
static void eqc_auxdev_release (struct device * dev )
280
326
{
281
327
struct auxiliary_device * adev = to_auxiliary_dev (dev );
@@ -349,10 +395,11 @@ static int eqc_probe(struct platform_device *pdev)
349
395
KBUILD_MODNAME , data -> pinctrl_auxdev_name , ret );
350
396
}
351
397
352
- if (data -> pll_count + data -> div_count == 0 )
398
+ if (data -> pll_count + data -> div_count + data -> fixed_factor_count == 0 )
353
399
return 0 ; /* Zero clocks, we are done. */
354
400
355
- clk_count = data -> pll_count + data -> div_count + data -> early_clk_count ;
401
+ clk_count = data -> pll_count + data -> div_count +
402
+ data -> fixed_factor_count + data -> early_clk_count ;
356
403
cells = kzalloc (struct_size (cells , hws , clk_count ), GFP_KERNEL );
357
404
if (!cells )
358
405
return - ENOMEM ;
@@ -367,6 +414,8 @@ static int eqc_probe(struct platform_device *pdev)
367
414
368
415
eqc_probe_init_divs (dev , data , base , cells );
369
416
417
+ eqc_probe_init_fixed_factors (dev , data , cells );
418
+
370
419
return of_clk_add_hw_provider (np , of_clk_hw_onecell_get , cells );
371
420
}
372
421
@@ -580,7 +629,8 @@ static void __init eqc_early_init(struct device_node *np,
580
629
void __iomem * base ;
581
630
int ret ;
582
631
583
- clk_count = early_data -> early_pll_count + early_data -> late_clk_count ;
632
+ clk_count = early_data -> early_pll_count + early_data -> early_fixed_factor_count +
633
+ early_data -> late_clk_count ;
584
634
cells = kzalloc (struct_size (cells , hws , clk_count ), GFP_KERNEL );
585
635
if (!cells ) {
586
636
ret = - ENOMEM ;
@@ -633,6 +683,21 @@ static void __init eqc_early_init(struct device_node *np,
633
683
}
634
684
}
635
685
686
+ for (i = 0 ; i < early_data -> early_fixed_factor_count ; i ++ ) {
687
+ const struct eqc_fixed_factor * ff = & early_data -> early_fixed_factors [i ];
688
+ struct clk_hw * parent_hw = cells -> hws [ff -> parent ];
689
+ struct clk_hw * hw ;
690
+
691
+ hw = clk_hw_register_fixed_factor_parent_hw (NULL , ff -> name ,
692
+ parent_hw , 0 , ff -> mult , ff -> div );
693
+ cells -> hws [ff -> index ] = hw ;
694
+ if (IS_ERR (hw )) {
695
+ pr_err ("failed registering %s: %pe\n" , ff -> name , hw );
696
+ ret = PTR_ERR (hw );
697
+ goto err ;
698
+ }
699
+ }
700
+
636
701
ret = of_clk_add_hw_provider (np , of_clk_hw_onecell_get , cells );
637
702
if (ret ) {
638
703
pr_err ("failed registering clk provider: %d\n" , ret );
0 commit comments