1
2
3
4
5
6
7
8
9
10
11#ifndef __LINUX_CLK_PROVIDER_H
12#define __LINUX_CLK_PROVIDER_H
13
14#include <linux/io.h>
15#include <linux/of.h>
16
17#ifdef CONFIG_COMMON_CLK
18
19
20
21
22
23
24#define CLK_SET_RATE_GATE BIT(0)
25#define CLK_SET_PARENT_GATE BIT(1)
26#define CLK_SET_RATE_PARENT BIT(2)
27#define CLK_IGNORE_UNUSED BIT(3)
28
29#define CLK_IS_BASIC BIT(5)
30#define CLK_GET_RATE_NOCACHE BIT(6)
31#define CLK_SET_RATE_NO_REPARENT BIT(7)
32#define CLK_GET_ACCURACY_NOCACHE BIT(8)
33#define CLK_RECALC_NEW_RATES BIT(9)
34#define CLK_SET_RATE_UNGATE BIT(10)
35#define CLK_IS_CRITICAL BIT(11)
36
37#define CLK_OPS_PARENT_ENABLE BIT(12)
38
39struct clk;
40struct clk_hw;
41struct clk_core;
42struct dentry;
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58struct clk_rate_request {
59 unsigned long rate;
60 unsigned long min_rate;
61 unsigned long max_rate;
62 unsigned long best_parent_rate;
63 struct clk_hw *best_parent_hw;
64};
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192struct clk_ops {
193 int (*prepare)(struct clk_hw *hw);
194 void (*unprepare)(struct clk_hw *hw);
195 int (*is_prepared)(struct clk_hw *hw);
196 void (*unprepare_unused)(struct clk_hw *hw);
197 int (*enable)(struct clk_hw *hw);
198 void (*disable)(struct clk_hw *hw);
199 int (*is_enabled)(struct clk_hw *hw);
200 void (*disable_unused)(struct clk_hw *hw);
201 unsigned long (*recalc_rate)(struct clk_hw *hw,
202 unsigned long parent_rate);
203 long (*round_rate)(struct clk_hw *hw, unsigned long rate,
204 unsigned long *parent_rate);
205 int (*determine_rate)(struct clk_hw *hw,
206 struct clk_rate_request *req);
207 int (*set_parent)(struct clk_hw *hw, u8 index);
208 u8 (*get_parent)(struct clk_hw *hw);
209 int (*set_rate)(struct clk_hw *hw, unsigned long rate,
210 unsigned long parent_rate);
211 int (*set_rate_and_parent)(struct clk_hw *hw,
212 unsigned long rate,
213 unsigned long parent_rate, u8 index);
214 unsigned long (*recalc_accuracy)(struct clk_hw *hw,
215 unsigned long parent_accuracy);
216 int (*get_phase)(struct clk_hw *hw);
217 int (*set_phase)(struct clk_hw *hw, int degrees);
218 void (*init)(struct clk_hw *hw);
219 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
220};
221
222
223
224
225
226
227
228
229
230
231
232struct clk_init_data {
233 const char *name;
234 const struct clk_ops *ops;
235 const char * const *parent_names;
236 u8 num_parents;
237 unsigned long flags;
238};
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255struct clk_hw {
256 struct clk_core *core;
257 struct clk *clk;
258 const struct clk_init_data *init;
259};
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275struct clk_fixed_rate {
276 struct clk_hw hw;
277 unsigned long fixed_rate;
278 unsigned long fixed_accuracy;
279 u8 flags;
280};
281
282#define to_clk_fixed_rate(_hw) container_of(_hw, struct clk_fixed_rate, hw)
283
284extern const struct clk_ops clk_fixed_rate_ops;
285struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
286 const char *parent_name, unsigned long flags,
287 unsigned long fixed_rate);
288struct clk_hw *clk_hw_register_fixed_rate(struct device *dev, const char *name,
289 const char *parent_name, unsigned long flags,
290 unsigned long fixed_rate);
291struct clk *clk_register_fixed_rate_with_accuracy(struct device *dev,
292 const char *name, const char *parent_name, unsigned long flags,
293 unsigned long fixed_rate, unsigned long fixed_accuracy);
294void clk_unregister_fixed_rate(struct clk *clk);
295struct clk_hw *clk_hw_register_fixed_rate_with_accuracy(struct device *dev,
296 const char *name, const char *parent_name, unsigned long flags,
297 unsigned long fixed_rate, unsigned long fixed_accuracy);
298void clk_hw_unregister_fixed_rate(struct clk_hw *hw);
299
300void of_fixed_clk_setup(struct device_node *np);
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322struct clk_gate {
323 struct clk_hw hw;
324 void __iomem *reg;
325 u8 bit_idx;
326 u8 flags;
327 spinlock_t *lock;
328};
329
330#define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
331
332#define CLK_GATE_SET_TO_DISABLE BIT(0)
333#define CLK_GATE_HIWORD_MASK BIT(1)
334
335extern const struct clk_ops clk_gate_ops;
336struct clk *clk_register_gate(struct device *dev, const char *name,
337 const char *parent_name, unsigned long flags,
338 void __iomem *reg, u8 bit_idx,
339 u8 clk_gate_flags, spinlock_t *lock);
340struct clk_hw *clk_hw_register_gate(struct device *dev, const char *name,
341 const char *parent_name, unsigned long flags,
342 void __iomem *reg, u8 bit_idx,
343 u8 clk_gate_flags, spinlock_t *lock);
344void clk_unregister_gate(struct clk *clk);
345void clk_hw_unregister_gate(struct clk_hw *hw);
346
347struct clk_div_table {
348 unsigned int val;
349 unsigned int div;
350};
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389struct clk_divider {
390 struct clk_hw hw;
391 void __iomem *reg;
392 u8 shift;
393 u8 width;
394 u8 flags;
395 const struct clk_div_table *table;
396 spinlock_t *lock;
397};
398
399#define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
400
401#define CLK_DIVIDER_ONE_BASED BIT(0)
402#define CLK_DIVIDER_POWER_OF_TWO BIT(1)
403#define CLK_DIVIDER_ALLOW_ZERO BIT(2)
404#define CLK_DIVIDER_HIWORD_MASK BIT(3)
405#define CLK_DIVIDER_ROUND_CLOSEST BIT(4)
406#define CLK_DIVIDER_READ_ONLY BIT(5)
407#define CLK_DIVIDER_MAX_AT_ZERO BIT(6)
408
409extern const struct clk_ops clk_divider_ops;
410extern const struct clk_ops clk_divider_ro_ops;
411
412unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate,
413 unsigned int val, const struct clk_div_table *table,
414 unsigned long flags);
415long divider_round_rate(struct clk_hw *hw, unsigned long rate,
416 unsigned long *prate, const struct clk_div_table *table,
417 u8 width, unsigned long flags);
418int divider_get_val(unsigned long rate, unsigned long parent_rate,
419 const struct clk_div_table *table, u8 width,
420 unsigned long flags);
421
422struct clk *clk_register_divider(struct device *dev, const char *name,
423 const char *parent_name, unsigned long flags,
424 void __iomem *reg, u8 shift, u8 width,
425 u8 clk_divider_flags, spinlock_t *lock);
426struct clk_hw *clk_hw_register_divider(struct device *dev, const char *name,
427 const char *parent_name, unsigned long flags,
428 void __iomem *reg, u8 shift, u8 width,
429 u8 clk_divider_flags, spinlock_t *lock);
430struct clk *clk_register_divider_table(struct device *dev, const char *name,
431 const char *parent_name, unsigned long flags,
432 void __iomem *reg, u8 shift, u8 width,
433 u8 clk_divider_flags, const struct clk_div_table *table,
434 spinlock_t *lock);
435struct clk_hw *clk_hw_register_divider_table(struct device *dev,
436 const char *name, const char *parent_name, unsigned long flags,
437 void __iomem *reg, u8 shift, u8 width,
438 u8 clk_divider_flags, const struct clk_div_table *table,
439 spinlock_t *lock);
440void clk_unregister_divider(struct clk *clk);
441void clk_hw_unregister_divider(struct clk_hw *hw);
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466struct clk_mux {
467 struct clk_hw hw;
468 void __iomem *reg;
469 u32 *table;
470 u32 mask;
471 u8 shift;
472 u8 flags;
473 spinlock_t *lock;
474};
475
476#define to_clk_mux(_hw) container_of(_hw, struct clk_mux, hw)
477
478#define CLK_MUX_INDEX_ONE BIT(0)
479#define CLK_MUX_INDEX_BIT BIT(1)
480#define CLK_MUX_HIWORD_MASK BIT(2)
481#define CLK_MUX_READ_ONLY BIT(3)
482#define CLK_MUX_ROUND_CLOSEST BIT(4)
483
484extern const struct clk_ops clk_mux_ops;
485extern const struct clk_ops clk_mux_ro_ops;
486
487struct clk *clk_register_mux(struct device *dev, const char *name,
488 const char * const *parent_names, u8 num_parents,
489 unsigned long flags,
490 void __iomem *reg, u8 shift, u8 width,
491 u8 clk_mux_flags, spinlock_t *lock);
492struct clk_hw *clk_hw_register_mux(struct device *dev, const char *name,
493 const char * const *parent_names, u8 num_parents,
494 unsigned long flags,
495 void __iomem *reg, u8 shift, u8 width,
496 u8 clk_mux_flags, spinlock_t *lock);
497
498struct clk *clk_register_mux_table(struct device *dev, const char *name,
499 const char * const *parent_names, u8 num_parents,
500 unsigned long flags,
501 void __iomem *reg, u8 shift, u32 mask,
502 u8 clk_mux_flags, u32 *table, spinlock_t *lock);
503struct clk_hw *clk_hw_register_mux_table(struct device *dev, const char *name,
504 const char * const *parent_names, u8 num_parents,
505 unsigned long flags,
506 void __iomem *reg, u8 shift, u32 mask,
507 u8 clk_mux_flags, u32 *table, spinlock_t *lock);
508
509void clk_unregister_mux(struct clk *clk);
510void clk_hw_unregister_mux(struct clk_hw *hw);
511
512void of_fixed_factor_clk_setup(struct device_node *node);
513
514
515
516
517
518
519
520
521
522
523
524
525
526struct clk_fixed_factor {
527 struct clk_hw hw;
528 unsigned int mult;
529 unsigned int div;
530};
531
532#define to_clk_fixed_factor(_hw) container_of(_hw, struct clk_fixed_factor, hw)
533
534extern const struct clk_ops clk_fixed_factor_ops;
535struct clk *clk_register_fixed_factor(struct device *dev, const char *name,
536 const char *parent_name, unsigned long flags,
537 unsigned int mult, unsigned int div);
538void clk_unregister_fixed_factor(struct clk *clk);
539struct clk_hw *clk_hw_register_fixed_factor(struct device *dev,
540 const char *name, const char *parent_name, unsigned long flags,
541 unsigned int mult, unsigned int div);
542void clk_hw_unregister_fixed_factor(struct clk_hw *hw);
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557struct clk_fractional_divider {
558 struct clk_hw hw;
559 void __iomem *reg;
560 u8 mshift;
561 u8 mwidth;
562 u32 mmask;
563 u8 nshift;
564 u8 nwidth;
565 u32 nmask;
566 u8 flags;
567 spinlock_t *lock;
568};
569
570#define to_clk_fd(_hw) container_of(_hw, struct clk_fractional_divider, hw)
571
572extern const struct clk_ops clk_fractional_divider_ops;
573struct clk *clk_register_fractional_divider(struct device *dev,
574 const char *name, const char *parent_name, unsigned long flags,
575 void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth,
576 u8 clk_divider_flags, spinlock_t *lock);
577struct clk_hw *clk_hw_register_fractional_divider(struct device *dev,
578 const char *name, const char *parent_name, unsigned long flags,
579 void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth,
580 u8 clk_divider_flags, spinlock_t *lock);
581void clk_hw_unregister_fractional_divider(struct clk_hw *hw);
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604struct clk_multiplier {
605 struct clk_hw hw;
606 void __iomem *reg;
607 u8 shift;
608 u8 width;
609 u8 flags;
610 spinlock_t *lock;
611};
612
613#define to_clk_multiplier(_hw) container_of(_hw, struct clk_multiplier, hw)
614
615#define CLK_MULTIPLIER_ZERO_BYPASS BIT(0)
616#define CLK_MULTIPLIER_ROUND_CLOSEST BIT(1)
617
618extern const struct clk_ops clk_multiplier_ops;
619
620
621
622
623
624
625
626
627
628
629
630
631struct clk_composite {
632 struct clk_hw hw;
633 struct clk_ops ops;
634
635 struct clk_hw *mux_hw;
636 struct clk_hw *rate_hw;
637 struct clk_hw *gate_hw;
638
639 const struct clk_ops *mux_ops;
640 const struct clk_ops *rate_ops;
641 const struct clk_ops *gate_ops;
642};
643
644#define to_clk_composite(_hw) container_of(_hw, struct clk_composite, hw)
645
646struct clk *clk_register_composite(struct device *dev, const char *name,
647 const char * const *parent_names, int num_parents,
648 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
649 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
650 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
651 unsigned long flags);
652void clk_unregister_composite(struct clk *clk);
653struct clk_hw *clk_hw_register_composite(struct device *dev, const char *name,
654 const char * const *parent_names, int num_parents,
655 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
656 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
657 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
658 unsigned long flags);
659void clk_hw_unregister_composite(struct clk_hw *hw);
660
661
662
663
664
665
666
667
668
669
670
671struct clk_gpio {
672 struct clk_hw hw;
673 struct gpio_desc *gpiod;
674};
675
676#define to_clk_gpio(_hw) container_of(_hw, struct clk_gpio, hw)
677
678extern const struct clk_ops clk_gpio_gate_ops;
679struct clk *clk_register_gpio_gate(struct device *dev, const char *name,
680 const char *parent_name, unsigned gpio, bool active_low,
681 unsigned long flags);
682struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name,
683 const char *parent_name, unsigned gpio, bool active_low,
684 unsigned long flags);
685void clk_hw_unregister_gpio_gate(struct clk_hw *hw);
686
687
688
689
690
691
692
693
694
695
696
697extern const struct clk_ops clk_gpio_mux_ops;
698struct clk *clk_register_gpio_mux(struct device *dev, const char *name,
699 const char * const *parent_names, u8 num_parents, unsigned gpio,
700 bool active_low, unsigned long flags);
701struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name,
702 const char * const *parent_names, u8 num_parents, unsigned gpio,
703 bool active_low, unsigned long flags);
704void clk_hw_unregister_gpio_mux(struct clk_hw *hw);
705
706
707
708
709
710
711
712
713
714
715
716
717struct clk *clk_register(struct device *dev, struct clk_hw *hw);
718struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw);
719
720int __must_check clk_hw_register(struct device *dev, struct clk_hw *hw);
721int __must_check devm_clk_hw_register(struct device *dev, struct clk_hw *hw);
722
723void clk_unregister(struct clk *clk);
724void devm_clk_unregister(struct device *dev, struct clk *clk);
725
726void clk_hw_unregister(struct clk_hw *hw);
727void devm_clk_hw_unregister(struct device *dev, struct clk_hw *hw);
728
729
730const char *__clk_get_name(const struct clk *clk);
731const char *clk_hw_get_name(const struct clk_hw *hw);
732struct clk_hw *__clk_get_hw(struct clk *clk);
733unsigned int clk_hw_get_num_parents(const struct clk_hw *hw);
734struct clk_hw *clk_hw_get_parent(const struct clk_hw *hw);
735struct clk_hw *clk_hw_get_parent_by_index(const struct clk_hw *hw,
736 unsigned int index);
737unsigned int __clk_get_enable_count(struct clk *clk);
738unsigned long clk_hw_get_rate(const struct clk_hw *hw);
739unsigned long __clk_get_flags(struct clk *clk);
740unsigned long clk_hw_get_flags(const struct clk_hw *hw);
741unsigned int clk_get_children(char *name);
742bool clk_hw_is_prepared(const struct clk_hw *hw);
743bool clk_hw_is_enabled(const struct clk_hw *hw);
744bool __clk_is_enabled(struct clk *clk);
745struct clk *__clk_lookup(const char *name);
746int __clk_mux_determine_rate(struct clk_hw *hw,
747 struct clk_rate_request *req);
748int __clk_determine_rate(struct clk_hw *core, struct clk_rate_request *req);
749int __clk_mux_determine_rate_closest(struct clk_hw *hw,
750 struct clk_rate_request *req);
751void clk_hw_reparent(struct clk_hw *hw, struct clk_hw *new_parent);
752void clk_hw_set_rate_range(struct clk_hw *hw, unsigned long min_rate,
753 unsigned long max_rate);
754
755static inline void __clk_hw_set_clk(struct clk_hw *dst, struct clk_hw *src)
756{
757 dst->clk = src->clk;
758 dst->core = src->core;
759}
760
761
762
763
764unsigned long clk_hw_round_rate(struct clk_hw *hw, unsigned long rate);
765
766struct of_device_id;
767
768typedef void (*of_clk_init_cb_t)(struct device_node *);
769
770struct clk_onecell_data {
771 struct clk **clks;
772 unsigned int clk_num;
773};
774
775struct clk_hw_onecell_data {
776 unsigned int num;
777 struct clk_hw *hws[];
778};
779
780extern struct of_device_id __clk_of_table;
781
782#define CLK_OF_DECLARE(name, compat, fn) OF_DECLARE_1(clk, name, compat, fn)
783
784
785
786
787
788#define CLK_OF_DECLARE_DRIVER(name, compat, fn) \
789 static void __init name##_of_clk_init_driver(struct device_node *np) \
790 { \
791 of_node_clear_flag(np, OF_POPULATED); \
792 fn(np); \
793 } \
794 OF_DECLARE_1(clk, name, compat, name##_of_clk_init_driver)
795
796#ifdef CONFIG_OF
797int of_clk_add_provider(struct device_node *np,
798 struct clk *(*clk_src_get)(struct of_phandle_args *args,
799 void *data),
800 void *data);
801int of_clk_add_hw_provider(struct device_node *np,
802 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
803 void *data),
804 void *data);
805void of_clk_del_provider(struct device_node *np);
806struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
807 void *data);
808struct clk_hw *of_clk_hw_simple_get(struct of_phandle_args *clkspec,
809 void *data);
810struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
811struct clk_hw *of_clk_hw_onecell_get(struct of_phandle_args *clkspec,
812 void *data);
813unsigned int of_clk_get_parent_count(struct device_node *np);
814int of_clk_parent_fill(struct device_node *np, const char **parents,
815 unsigned int size);
816const char *of_clk_get_parent_name(struct device_node *np, int index);
817int of_clk_detect_critical(struct device_node *np, int index,
818 unsigned long *flags);
819void of_clk_init(const struct of_device_id *matches);
820
821#else
822
823static inline int of_clk_add_provider(struct device_node *np,
824 struct clk *(*clk_src_get)(struct of_phandle_args *args,
825 void *data),
826 void *data)
827{
828 return 0;
829}
830static inline int of_clk_add_hw_provider(struct device_node *np,
831 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
832 void *data),
833 void *data)
834{
835 return 0;
836}
837static inline void of_clk_del_provider(struct device_node *np) {}
838static inline struct clk *of_clk_src_simple_get(
839 struct of_phandle_args *clkspec, void *data)
840{
841 return ERR_PTR(-ENOENT);
842}
843static inline struct clk_hw *
844of_clk_hw_simple_get(struct of_phandle_args *clkspec, void *data)
845{
846 return ERR_PTR(-ENOENT);
847}
848static inline struct clk *of_clk_src_onecell_get(
849 struct of_phandle_args *clkspec, void *data)
850{
851 return ERR_PTR(-ENOENT);
852}
853static inline struct clk_hw *
854of_clk_hw_onecell_get(struct of_phandle_args *clkspec, void *data)
855{
856 return ERR_PTR(-ENOENT);
857}
858static inline unsigned int of_clk_get_parent_count(struct device_node *np)
859{
860 return 0;
861}
862static inline int of_clk_parent_fill(struct device_node *np,
863 const char **parents, unsigned int size)
864{
865 return 0;
866}
867static inline const char *of_clk_get_parent_name(struct device_node *np,
868 int index)
869{
870 return NULL;
871}
872static inline int of_clk_detect_critical(struct device_node *np, int index,
873 unsigned long *flags)
874{
875 return 0;
876}
877static inline void of_clk_init(const struct of_device_id *matches) {}
878#endif
879
880
881
882
883
884
885#if IS_ENABLED(CONFIG_PPC)
886
887static inline u32 clk_readl(u32 __iomem *reg)
888{
889 return ioread32be(reg);
890}
891
892static inline void clk_writel(u32 val, u32 __iomem *reg)
893{
894 iowrite32be(val, reg);
895}
896
897#else
898
899static inline u32 clk_readl(u32 __iomem *reg)
900{
901 return readl(reg);
902}
903
904static inline void clk_writel(u32 val, u32 __iomem *reg)
905{
906 writel(val, reg);
907}
908
909#endif
910
911#ifdef CONFIG_DEBUG_FS
912struct dentry *clk_debugfs_add_file(struct clk_hw *hw, char *name, umode_t mode,
913 void *data, const struct file_operations *fops);
914#endif
915
916#endif
917#endif
918