1
2
3
4
5
6#ifndef __LINUX_CLK_PROVIDER_H
7#define __LINUX_CLK_PROVIDER_H
8
9#include <linux/of.h>
10#include <linux/of_clk.h>
11
12
13
14
15
16
17
18
19#define CLK_SET_RATE_GATE BIT(0)
20#define CLK_SET_PARENT_GATE BIT(1)
21#define CLK_SET_RATE_PARENT BIT(2)
22#define CLK_IGNORE_UNUSED BIT(3)
23
24
25#define CLK_GET_RATE_NOCACHE BIT(6)
26#define CLK_SET_RATE_NO_REPARENT BIT(7)
27#define CLK_GET_ACCURACY_NOCACHE BIT(8)
28#define CLK_RECALC_NEW_RATES BIT(9)
29#define CLK_SET_RATE_UNGATE BIT(10)
30#define CLK_IS_CRITICAL BIT(11)
31
32#define CLK_OPS_PARENT_ENABLE BIT(12)
33
34#define CLK_DUTY_CYCLE_PARENT BIT(13)
35
36struct clk;
37struct clk_hw;
38struct clk_core;
39struct dentry;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55struct clk_rate_request {
56 unsigned long rate;
57 unsigned long min_rate;
58 unsigned long max_rate;
59 unsigned long best_parent_rate;
60 struct clk_hw *best_parent_hw;
61};
62
63
64
65
66
67
68
69struct clk_duty {
70 unsigned int num;
71 unsigned int den;
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220struct clk_ops {
221 int (*prepare)(struct clk_hw *hw);
222 void (*unprepare)(struct clk_hw *hw);
223 int (*is_prepared)(struct clk_hw *hw);
224 void (*unprepare_unused)(struct clk_hw *hw);
225 int (*enable)(struct clk_hw *hw);
226 void (*disable)(struct clk_hw *hw);
227 int (*is_enabled)(struct clk_hw *hw);
228 void (*disable_unused)(struct clk_hw *hw);
229 int (*save_context)(struct clk_hw *hw);
230 void (*restore_context)(struct clk_hw *hw);
231 unsigned long (*recalc_rate)(struct clk_hw *hw,
232 unsigned long parent_rate);
233 long (*round_rate)(struct clk_hw *hw, unsigned long rate,
234 unsigned long *parent_rate);
235 int (*determine_rate)(struct clk_hw *hw,
236 struct clk_rate_request *req);
237 int (*set_parent)(struct clk_hw *hw, u8 index);
238 u8 (*get_parent)(struct clk_hw *hw);
239 int (*set_rate)(struct clk_hw *hw, unsigned long rate,
240 unsigned long parent_rate);
241 int (*set_rate_and_parent)(struct clk_hw *hw,
242 unsigned long rate,
243 unsigned long parent_rate, u8 index);
244 unsigned long (*recalc_accuracy)(struct clk_hw *hw,
245 unsigned long parent_accuracy);
246 int (*get_phase)(struct clk_hw *hw);
247 int (*set_phase)(struct clk_hw *hw, int degrees);
248 int (*get_duty_cycle)(struct clk_hw *hw,
249 struct clk_duty *duty);
250 int (*set_duty_cycle)(struct clk_hw *hw,
251 struct clk_duty *duty);
252 int (*init)(struct clk_hw *hw);
253 void (*terminate)(struct clk_hw *hw);
254 void (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
255};
256
257
258
259
260
261
262
263
264struct clk_parent_data {
265 const struct clk_hw *hw;
266 const char *fw_name;
267 const char *name;
268 int index;
269};
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285struct clk_init_data {
286 const char *name;
287 const struct clk_ops *ops;
288
289 const char * const *parent_names;
290 const struct clk_parent_data *parent_data;
291 const struct clk_hw **parent_hws;
292 u8 num_parents;
293 unsigned long flags;
294};
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312struct clk_hw {
313 struct clk_core *core;
314 struct clk *clk;
315 const struct clk_init_data *init;
316};
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338struct clk_fixed_rate {
339 struct clk_hw hw;
340 unsigned long fixed_rate;
341 unsigned long fixed_accuracy;
342 unsigned long flags;
343};
344
345#define CLK_FIXED_RATE_PARENT_ACCURACY BIT(0)
346
347extern const struct clk_ops clk_fixed_rate_ops;
348struct clk_hw *__clk_hw_register_fixed_rate(struct device *dev,
349 struct device_node *np, const char *name,
350 const char *parent_name, const struct clk_hw *parent_hw,
351 const struct clk_parent_data *parent_data, unsigned long flags,
352 unsigned long fixed_rate, unsigned long fixed_accuracy,
353 unsigned long clk_fixed_flags);
354struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
355 const char *parent_name, unsigned long flags,
356 unsigned long fixed_rate);
357
358
359
360
361
362
363
364
365
366#define clk_hw_register_fixed_rate(dev, name, parent_name, flags, fixed_rate) \
367 __clk_hw_register_fixed_rate((dev), NULL, (name), (parent_name), NULL, \
368 NULL, (flags), (fixed_rate), 0, 0)
369
370
371
372
373
374
375
376
377
378#define clk_hw_register_fixed_rate_parent_hw(dev, name, parent_hw, flags, \
379 fixed_rate) \
380 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, (parent_hw), \
381 NULL, (flags), (fixed_rate), 0, 0)
382
383
384
385
386
387
388
389
390
391#define clk_hw_register_fixed_rate_parent_data(dev, name, parent_hw, flags, \
392 fixed_rate) \
393 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, NULL, \
394 (parent_data), (flags), (fixed_rate), 0, \
395 0)
396
397
398
399
400
401
402
403
404
405
406#define clk_hw_register_fixed_rate_with_accuracy(dev, name, parent_name, \
407 flags, fixed_rate, \
408 fixed_accuracy) \
409 __clk_hw_register_fixed_rate((dev), NULL, (name), (parent_name), \
410 NULL, NULL, (flags), (fixed_rate), \
411 (fixed_accuracy), 0)
412
413
414
415
416
417
418
419
420
421
422#define clk_hw_register_fixed_rate_with_accuracy_parent_hw(dev, name, \
423 parent_hw, flags, fixed_rate, fixed_accuracy) \
424 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, (parent_hw) \
425 NULL, NULL, (flags), (fixed_rate), \
426 (fixed_accuracy), 0)
427
428
429
430
431
432
433
434
435
436
437#define clk_hw_register_fixed_rate_with_accuracy_parent_data(dev, name, \
438 parent_data, flags, fixed_rate, fixed_accuracy) \
439 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, NULL, \
440 (parent_data), NULL, (flags), \
441 (fixed_rate), (fixed_accuracy), 0)
442
443void clk_unregister_fixed_rate(struct clk *clk);
444void clk_hw_unregister_fixed_rate(struct clk_hw *hw);
445
446void of_fixed_clk_setup(struct device_node *np);
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471struct clk_gate {
472 struct clk_hw hw;
473 void __iomem *reg;
474 u8 bit_idx;
475 u8 flags;
476 spinlock_t *lock;
477};
478
479#define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
480
481#define CLK_GATE_SET_TO_DISABLE BIT(0)
482#define CLK_GATE_HIWORD_MASK BIT(1)
483#define CLK_GATE_BIG_ENDIAN BIT(2)
484
485extern const struct clk_ops clk_gate_ops;
486struct clk_hw *__clk_hw_register_gate(struct device *dev,
487 struct device_node *np, const char *name,
488 const char *parent_name, const struct clk_hw *parent_hw,
489 const struct clk_parent_data *parent_data,
490 unsigned long flags,
491 void __iomem *reg, u8 bit_idx,
492 u8 clk_gate_flags, spinlock_t *lock);
493struct clk *clk_register_gate(struct device *dev, const char *name,
494 const char *parent_name, unsigned long flags,
495 void __iomem *reg, u8 bit_idx,
496 u8 clk_gate_flags, spinlock_t *lock);
497
498
499
500
501
502
503
504
505
506
507
508#define clk_hw_register_gate(dev, name, parent_name, flags, reg, bit_idx, \
509 clk_gate_flags, lock) \
510 __clk_hw_register_gate((dev), NULL, (name), (parent_name), NULL, \
511 NULL, (flags), (reg), (bit_idx), \
512 (clk_gate_flags), (lock))
513
514
515
516
517
518
519
520
521
522
523
524
525#define clk_hw_register_gate_parent_hw(dev, name, parent_hw, flags, reg, \
526 bit_idx, clk_gate_flags, lock) \
527 __clk_hw_register_gate((dev), NULL, (name), NULL, (parent_hw), \
528 NULL, (flags), (reg), (bit_idx), \
529 (clk_gate_flags), (lock))
530
531
532
533
534
535
536
537
538
539
540
541
542#define clk_hw_register_gate_parent_data(dev, name, parent_data, flags, reg, \
543 bit_idx, clk_gate_flags, lock) \
544 __clk_hw_register_gate((dev), NULL, (name), NULL, NULL, (parent_data), \
545 (flags), (reg), (bit_idx), \
546 (clk_gate_flags), (lock))
547void clk_unregister_gate(struct clk *clk);
548void clk_hw_unregister_gate(struct clk_hw *hw);
549int clk_gate_is_enabled(struct clk_hw *hw);
550
551struct clk_div_table {
552 unsigned int val;
553 unsigned int div;
554};
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596struct clk_divider {
597 struct clk_hw hw;
598 void __iomem *reg;
599 u8 shift;
600 u8 width;
601 u8 flags;
602 const struct clk_div_table *table;
603 spinlock_t *lock;
604};
605
606#define clk_div_mask(width) ((1 << (width)) - 1)
607#define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
608
609#define CLK_DIVIDER_ONE_BASED BIT(0)
610#define CLK_DIVIDER_POWER_OF_TWO BIT(1)
611#define CLK_DIVIDER_ALLOW_ZERO BIT(2)
612#define CLK_DIVIDER_HIWORD_MASK BIT(3)
613#define CLK_DIVIDER_ROUND_CLOSEST BIT(4)
614#define CLK_DIVIDER_READ_ONLY BIT(5)
615#define CLK_DIVIDER_MAX_AT_ZERO BIT(6)
616#define CLK_DIVIDER_BIG_ENDIAN BIT(7)
617
618extern const struct clk_ops clk_divider_ops;
619extern const struct clk_ops clk_divider_ro_ops;
620
621unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate,
622 unsigned int val, const struct clk_div_table *table,
623 unsigned long flags, unsigned long width);
624long divider_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
625 unsigned long rate, unsigned long *prate,
626 const struct clk_div_table *table,
627 u8 width, unsigned long flags);
628long divider_ro_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
629 unsigned long rate, unsigned long *prate,
630 const struct clk_div_table *table, u8 width,
631 unsigned long flags, unsigned int val);
632int divider_get_val(unsigned long rate, unsigned long parent_rate,
633 const struct clk_div_table *table, u8 width,
634 unsigned long flags);
635
636struct clk_hw *__clk_hw_register_divider(struct device *dev,
637 struct device_node *np, const char *name,
638 const char *parent_name, const struct clk_hw *parent_hw,
639 const struct clk_parent_data *parent_data, unsigned long flags,
640 void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
641 const struct clk_div_table *table, spinlock_t *lock);
642struct clk_hw *__devm_clk_hw_register_divider(struct device *dev,
643 struct device_node *np, const char *name,
644 const char *parent_name, const struct clk_hw *parent_hw,
645 const struct clk_parent_data *parent_data, unsigned long flags,
646 void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
647 const struct clk_div_table *table, spinlock_t *lock);
648struct clk *clk_register_divider_table(struct device *dev, const char *name,
649 const char *parent_name, unsigned long flags,
650 void __iomem *reg, u8 shift, u8 width,
651 u8 clk_divider_flags, const struct clk_div_table *table,
652 spinlock_t *lock);
653
654
655
656
657
658
659
660
661
662
663
664
665#define clk_register_divider(dev, name, parent_name, flags, reg, shift, width, \
666 clk_divider_flags, lock) \
667 clk_register_divider_table((dev), (name), (parent_name), (flags), \
668 (reg), (shift), (width), \
669 (clk_divider_flags), NULL, (lock))
670
671
672
673
674
675
676
677
678
679
680
681
682#define clk_hw_register_divider(dev, name, parent_name, flags, reg, shift, \
683 width, clk_divider_flags, lock) \
684 __clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL, \
685 NULL, (flags), (reg), (shift), (width), \
686 (clk_divider_flags), NULL, (lock))
687
688
689
690
691
692
693
694
695
696
697
698
699
700#define clk_hw_register_divider_parent_hw(dev, name, parent_hw, flags, reg, \
701 shift, width, clk_divider_flags, \
702 lock) \
703 __clk_hw_register_divider((dev), NULL, (name), NULL, (parent_hw), \
704 NULL, (flags), (reg), (shift), (width), \
705 (clk_divider_flags), NULL, (lock))
706
707
708
709
710
711
712
713
714
715
716
717
718
719#define clk_hw_register_divider_parent_data(dev, name, parent_data, flags, \
720 reg, shift, width, \
721 clk_divider_flags, lock) \
722 __clk_hw_register_divider((dev), NULL, (name), NULL, NULL, \
723 (parent_data), (flags), (reg), (shift), \
724 (width), (clk_divider_flags), NULL, (lock))
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739#define clk_hw_register_divider_table(dev, name, parent_name, flags, reg, \
740 shift, width, clk_divider_flags, table, \
741 lock) \
742 __clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL, \
743 NULL, (flags), (reg), (shift), (width), \
744 (clk_divider_flags), (table), (lock))
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759#define clk_hw_register_divider_table_parent_hw(dev, name, parent_hw, flags, \
760 reg, shift, width, \
761 clk_divider_flags, table, \
762 lock) \
763 __clk_hw_register_divider((dev), NULL, (name), NULL, (parent_hw), \
764 NULL, (flags), (reg), (shift), (width), \
765 (clk_divider_flags), (table), (lock))
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780#define clk_hw_register_divider_table_parent_data(dev, name, parent_data, \
781 flags, reg, shift, width, \
782 clk_divider_flags, table, \
783 lock) \
784 __clk_hw_register_divider((dev), NULL, (name), NULL, NULL, \
785 (parent_data), (flags), (reg), (shift), \
786 (width), (clk_divider_flags), (table), \
787 (lock))
788
789
790
791
792
793
794
795
796
797
798
799
800#define devm_clk_hw_register_divider(dev, name, parent_name, flags, reg, shift, \
801 width, clk_divider_flags, lock) \
802 __devm_clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL, \
803 NULL, (flags), (reg), (shift), (width), \
804 (clk_divider_flags), NULL, (lock))
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819#define devm_clk_hw_register_divider_table(dev, name, parent_name, flags, \
820 reg, shift, width, \
821 clk_divider_flags, table, lock) \
822 __devm_clk_hw_register_divider((dev), NULL, (name), (parent_name), \
823 NULL, NULL, (flags), (reg), (shift), \
824 (width), (clk_divider_flags), (table), \
825 (lock))
826
827void clk_unregister_divider(struct clk *clk);
828void clk_hw_unregister_divider(struct clk_hw *hw);
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859struct clk_mux {
860 struct clk_hw hw;
861 void __iomem *reg;
862 u32 *table;
863 u32 mask;
864 u8 shift;
865 u8 flags;
866 spinlock_t *lock;
867};
868
869#define to_clk_mux(_hw) container_of(_hw, struct clk_mux, hw)
870
871#define CLK_MUX_INDEX_ONE BIT(0)
872#define CLK_MUX_INDEX_BIT BIT(1)
873#define CLK_MUX_HIWORD_MASK BIT(2)
874#define CLK_MUX_READ_ONLY BIT(3)
875#define CLK_MUX_ROUND_CLOSEST BIT(4)
876#define CLK_MUX_BIG_ENDIAN BIT(5)
877
878extern const struct clk_ops clk_mux_ops;
879extern const struct clk_ops clk_mux_ro_ops;
880
881struct clk_hw *__clk_hw_register_mux(struct device *dev, struct device_node *np,
882 const char *name, u8 num_parents,
883 const char * const *parent_names,
884 const struct clk_hw **parent_hws,
885 const struct clk_parent_data *parent_data,
886 unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
887 u8 clk_mux_flags, u32 *table, spinlock_t *lock);
888struct clk_hw *__devm_clk_hw_register_mux(struct device *dev, struct device_node *np,
889 const char *name, u8 num_parents,
890 const char * const *parent_names,
891 const struct clk_hw **parent_hws,
892 const struct clk_parent_data *parent_data,
893 unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
894 u8 clk_mux_flags, u32 *table, spinlock_t *lock);
895struct clk *clk_register_mux_table(struct device *dev, const char *name,
896 const char * const *parent_names, u8 num_parents,
897 unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
898 u8 clk_mux_flags, u32 *table, spinlock_t *lock);
899
900#define clk_register_mux(dev, name, parent_names, num_parents, flags, reg, \
901 shift, width, clk_mux_flags, lock) \
902 clk_register_mux_table((dev), (name), (parent_names), (num_parents), \
903 (flags), (reg), (shift), BIT((width)) - 1, \
904 (clk_mux_flags), NULL, (lock))
905#define clk_hw_register_mux_table(dev, name, parent_names, num_parents, \
906 flags, reg, shift, mask, clk_mux_flags, \
907 table, lock) \
908 __clk_hw_register_mux((dev), NULL, (name), (num_parents), \
909 (parent_names), NULL, NULL, (flags), (reg), \
910 (shift), (mask), (clk_mux_flags), (table), \
911 (lock))
912#define clk_hw_register_mux(dev, name, parent_names, num_parents, flags, reg, \
913 shift, width, clk_mux_flags, lock) \
914 __clk_hw_register_mux((dev), NULL, (name), (num_parents), \
915 (parent_names), NULL, NULL, (flags), (reg), \
916 (shift), BIT((width)) - 1, (clk_mux_flags), \
917 NULL, (lock))
918#define clk_hw_register_mux_hws(dev, name, parent_hws, num_parents, flags, \
919 reg, shift, width, clk_mux_flags, lock) \
920 __clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, \
921 (parent_hws), NULL, (flags), (reg), (shift), \
922 BIT((width)) - 1, (clk_mux_flags), NULL, (lock))
923#define clk_hw_register_mux_parent_data(dev, name, parent_data, num_parents, \
924 flags, reg, shift, width, \
925 clk_mux_flags, lock) \
926 __clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, NULL, \
927 (parent_data), (flags), (reg), (shift), \
928 BIT((width)) - 1, (clk_mux_flags), NULL, (lock))
929#define devm_clk_hw_register_mux(dev, name, parent_names, num_parents, flags, reg, \
930 shift, width, clk_mux_flags, lock) \
931 __devm_clk_hw_register_mux((dev), NULL, (name), (num_parents), \
932 (parent_names), NULL, NULL, (flags), (reg), \
933 (shift), BIT((width)) - 1, (clk_mux_flags), \
934 NULL, (lock))
935
936int clk_mux_val_to_index(struct clk_hw *hw, u32 *table, unsigned int flags,
937 unsigned int val);
938unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index);
939
940void clk_unregister_mux(struct clk *clk);
941void clk_hw_unregister_mux(struct clk_hw *hw);
942
943void of_fixed_factor_clk_setup(struct device_node *node);
944
945
946
947
948
949
950
951
952
953
954
955
956
957struct clk_fixed_factor {
958 struct clk_hw hw;
959 unsigned int mult;
960 unsigned int div;
961};
962
963#define to_clk_fixed_factor(_hw) container_of(_hw, struct clk_fixed_factor, hw)
964
965extern const struct clk_ops clk_fixed_factor_ops;
966struct clk *clk_register_fixed_factor(struct device *dev, const char *name,
967 const char *parent_name, unsigned long flags,
968 unsigned int mult, unsigned int div);
969void clk_unregister_fixed_factor(struct clk *clk);
970struct clk_hw *clk_hw_register_fixed_factor(struct device *dev,
971 const char *name, const char *parent_name, unsigned long flags,
972 unsigned int mult, unsigned int div);
973void clk_hw_unregister_fixed_factor(struct clk_hw *hw);
974struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev,
975 const char *name, const char *parent_name, unsigned long flags,
976 unsigned int mult, unsigned int div);
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999struct clk_fractional_divider {
1000 struct clk_hw hw;
1001 void __iomem *reg;
1002 u8 mshift;
1003 u8 mwidth;
1004 u32 mmask;
1005 u8 nshift;
1006 u8 nwidth;
1007 u32 nmask;
1008 u8 flags;
1009 void (*approximation)(struct clk_hw *hw,
1010 unsigned long rate, unsigned long *parent_rate,
1011 unsigned long *m, unsigned long *n);
1012 spinlock_t *lock;
1013};
1014
1015#define to_clk_fd(_hw) container_of(_hw, struct clk_fractional_divider, hw)
1016
1017#define CLK_FRAC_DIVIDER_ZERO_BASED BIT(0)
1018#define CLK_FRAC_DIVIDER_BIG_ENDIAN BIT(1)
1019
1020extern const struct clk_ops clk_fractional_divider_ops;
1021struct clk *clk_register_fractional_divider(struct device *dev,
1022 const char *name, const char *parent_name, unsigned long flags,
1023 void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth,
1024 u8 clk_divider_flags, spinlock_t *lock);
1025struct clk_hw *clk_hw_register_fractional_divider(struct device *dev,
1026 const char *name, const char *parent_name, unsigned long flags,
1027 void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth,
1028 u8 clk_divider_flags, spinlock_t *lock);
1029void clk_hw_unregister_fractional_divider(struct clk_hw *hw);
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055struct clk_multiplier {
1056 struct clk_hw hw;
1057 void __iomem *reg;
1058 u8 shift;
1059 u8 width;
1060 u8 flags;
1061 spinlock_t *lock;
1062};
1063
1064#define to_clk_multiplier(_hw) container_of(_hw, struct clk_multiplier, hw)
1065
1066#define CLK_MULTIPLIER_ZERO_BYPASS BIT(0)
1067#define CLK_MULTIPLIER_ROUND_CLOSEST BIT(1)
1068#define CLK_MULTIPLIER_BIG_ENDIAN BIT(2)
1069
1070extern const struct clk_ops clk_multiplier_ops;
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083struct clk_composite {
1084 struct clk_hw hw;
1085 struct clk_ops ops;
1086
1087 struct clk_hw *mux_hw;
1088 struct clk_hw *rate_hw;
1089 struct clk_hw *gate_hw;
1090
1091 const struct clk_ops *mux_ops;
1092 const struct clk_ops *rate_ops;
1093 const struct clk_ops *gate_ops;
1094};
1095
1096#define to_clk_composite(_hw) container_of(_hw, struct clk_composite, hw)
1097
1098struct clk *clk_register_composite(struct device *dev, const char *name,
1099 const char * const *parent_names, int num_parents,
1100 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1101 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1102 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1103 unsigned long flags);
1104struct clk *clk_register_composite_pdata(struct device *dev, const char *name,
1105 const struct clk_parent_data *parent_data, int num_parents,
1106 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1107 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1108 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1109 unsigned long flags);
1110void clk_unregister_composite(struct clk *clk);
1111struct clk_hw *clk_hw_register_composite(struct device *dev, const char *name,
1112 const char * const *parent_names, int num_parents,
1113 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1114 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1115 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1116 unsigned long flags);
1117struct clk_hw *clk_hw_register_composite_pdata(struct device *dev,
1118 const char *name,
1119 const struct clk_parent_data *parent_data, int num_parents,
1120 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1121 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1122 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1123 unsigned long flags);
1124struct clk_hw *devm_clk_hw_register_composite_pdata(struct device *dev,
1125 const char *name, const struct clk_parent_data *parent_data,
1126 int num_parents,
1127 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1128 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1129 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1130 unsigned long flags);
1131void clk_hw_unregister_composite(struct clk_hw *hw);
1132
1133struct clk *clk_register(struct device *dev, struct clk_hw *hw);
1134struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw);
1135
1136int __must_check clk_hw_register(struct device *dev, struct clk_hw *hw);
1137int __must_check devm_clk_hw_register(struct device *dev, struct clk_hw *hw);
1138int __must_check of_clk_hw_register(struct device_node *node, struct clk_hw *hw);
1139
1140void clk_unregister(struct clk *clk);
1141void devm_clk_unregister(struct device *dev, struct clk *clk);
1142
1143void clk_hw_unregister(struct clk_hw *hw);
1144void devm_clk_hw_unregister(struct device *dev, struct clk_hw *hw);
1145
1146
1147const char *__clk_get_name(const struct clk *clk);
1148const char *clk_hw_get_name(const struct clk_hw *hw);
1149#ifdef CONFIG_COMMON_CLK
1150struct clk_hw *__clk_get_hw(struct clk *clk);
1151#else
1152static inline struct clk_hw *__clk_get_hw(struct clk *clk)
1153{
1154 return (struct clk_hw *)clk;
1155}
1156#endif
1157
1158struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *con_id);
1159struct clk *devm_clk_hw_get_clk(struct device *dev, struct clk_hw *hw,
1160 const char *con_id);
1161
1162unsigned int clk_hw_get_num_parents(const struct clk_hw *hw);
1163struct clk_hw *clk_hw_get_parent(const struct clk_hw *hw);
1164struct clk_hw *clk_hw_get_parent_by_index(const struct clk_hw *hw,
1165 unsigned int index);
1166int clk_hw_get_parent_index(struct clk_hw *hw);
1167int clk_hw_set_parent(struct clk_hw *hw, struct clk_hw *new_parent);
1168unsigned int __clk_get_enable_count(struct clk *clk);
1169unsigned long clk_hw_get_rate(const struct clk_hw *hw);
1170unsigned long clk_hw_get_flags(const struct clk_hw *hw);
1171#define clk_hw_can_set_rate_parent(hw) \
1172 (clk_hw_get_flags((hw)) & CLK_SET_RATE_PARENT)
1173
1174bool clk_hw_is_prepared(const struct clk_hw *hw);
1175bool clk_hw_rate_is_protected(const struct clk_hw *hw);
1176bool clk_hw_is_enabled(const struct clk_hw *hw);
1177bool __clk_is_enabled(struct clk *clk);
1178struct clk *__clk_lookup(const char *name);
1179int __clk_mux_determine_rate(struct clk_hw *hw,
1180 struct clk_rate_request *req);
1181int __clk_determine_rate(struct clk_hw *core, struct clk_rate_request *req);
1182int __clk_mux_determine_rate_closest(struct clk_hw *hw,
1183 struct clk_rate_request *req);
1184int clk_mux_determine_rate_flags(struct clk_hw *hw,
1185 struct clk_rate_request *req,
1186 unsigned long flags);
1187void clk_hw_reparent(struct clk_hw *hw, struct clk_hw *new_parent);
1188void clk_hw_set_rate_range(struct clk_hw *hw, unsigned long min_rate,
1189 unsigned long max_rate);
1190
1191static inline void __clk_hw_set_clk(struct clk_hw *dst, struct clk_hw *src)
1192{
1193 dst->clk = src->clk;
1194 dst->core = src->core;
1195}
1196
1197static inline long divider_round_rate(struct clk_hw *hw, unsigned long rate,
1198 unsigned long *prate,
1199 const struct clk_div_table *table,
1200 u8 width, unsigned long flags)
1201{
1202 return divider_round_rate_parent(hw, clk_hw_get_parent(hw),
1203 rate, prate, table, width, flags);
1204}
1205
1206static inline long divider_ro_round_rate(struct clk_hw *hw, unsigned long rate,
1207 unsigned long *prate,
1208 const struct clk_div_table *table,
1209 u8 width, unsigned long flags,
1210 unsigned int val)
1211{
1212 return divider_ro_round_rate_parent(hw, clk_hw_get_parent(hw),
1213 rate, prate, table, width, flags,
1214 val);
1215}
1216
1217
1218
1219
1220unsigned long clk_hw_round_rate(struct clk_hw *hw, unsigned long rate);
1221
1222struct clk_onecell_data {
1223 struct clk **clks;
1224 unsigned int clk_num;
1225};
1226
1227struct clk_hw_onecell_data {
1228 unsigned int num;
1229 struct clk_hw *hws[];
1230};
1231
1232#define CLK_OF_DECLARE(name, compat, fn) OF_DECLARE_1(clk, name, compat, fn)
1233
1234
1235
1236
1237
1238#define CLK_OF_DECLARE_DRIVER(name, compat, fn) \
1239 static void __init name##_of_clk_init_driver(struct device_node *np) \
1240 { \
1241 of_node_clear_flag(np, OF_POPULATED); \
1242 fn(np); \
1243 } \
1244 OF_DECLARE_1(clk, name, compat, name##_of_clk_init_driver)
1245
1246#define CLK_HW_INIT(_name, _parent, _ops, _flags) \
1247 (&(struct clk_init_data) { \
1248 .flags = _flags, \
1249 .name = _name, \
1250 .parent_names = (const char *[]) { _parent }, \
1251 .num_parents = 1, \
1252 .ops = _ops, \
1253 })
1254
1255#define CLK_HW_INIT_HW(_name, _parent, _ops, _flags) \
1256 (&(struct clk_init_data) { \
1257 .flags = _flags, \
1258 .name = _name, \
1259 .parent_hws = (const struct clk_hw*[]) { _parent }, \
1260 .num_parents = 1, \
1261 .ops = _ops, \
1262 })
1263
1264
1265
1266
1267
1268
1269#define CLK_HW_INIT_HWS(_name, _parent, _ops, _flags) \
1270 (&(struct clk_init_data) { \
1271 .flags = _flags, \
1272 .name = _name, \
1273 .parent_hws = _parent, \
1274 .num_parents = 1, \
1275 .ops = _ops, \
1276 })
1277
1278#define CLK_HW_INIT_FW_NAME(_name, _parent, _ops, _flags) \
1279 (&(struct clk_init_data) { \
1280 .flags = _flags, \
1281 .name = _name, \
1282 .parent_data = (const struct clk_parent_data[]) { \
1283 { .fw_name = _parent }, \
1284 }, \
1285 .num_parents = 1, \
1286 .ops = _ops, \
1287 })
1288
1289#define CLK_HW_INIT_PARENTS(_name, _parents, _ops, _flags) \
1290 (&(struct clk_init_data) { \
1291 .flags = _flags, \
1292 .name = _name, \
1293 .parent_names = _parents, \
1294 .num_parents = ARRAY_SIZE(_parents), \
1295 .ops = _ops, \
1296 })
1297
1298#define CLK_HW_INIT_PARENTS_HW(_name, _parents, _ops, _flags) \
1299 (&(struct clk_init_data) { \
1300 .flags = _flags, \
1301 .name = _name, \
1302 .parent_hws = _parents, \
1303 .num_parents = ARRAY_SIZE(_parents), \
1304 .ops = _ops, \
1305 })
1306
1307#define CLK_HW_INIT_PARENTS_DATA(_name, _parents, _ops, _flags) \
1308 (&(struct clk_init_data) { \
1309 .flags = _flags, \
1310 .name = _name, \
1311 .parent_data = _parents, \
1312 .num_parents = ARRAY_SIZE(_parents), \
1313 .ops = _ops, \
1314 })
1315
1316#define CLK_HW_INIT_NO_PARENT(_name, _ops, _flags) \
1317 (&(struct clk_init_data) { \
1318 .flags = _flags, \
1319 .name = _name, \
1320 .parent_names = NULL, \
1321 .num_parents = 0, \
1322 .ops = _ops, \
1323 })
1324
1325#define CLK_FIXED_FACTOR(_struct, _name, _parent, \
1326 _div, _mult, _flags) \
1327 struct clk_fixed_factor _struct = { \
1328 .div = _div, \
1329 .mult = _mult, \
1330 .hw.init = CLK_HW_INIT(_name, \
1331 _parent, \
1332 &clk_fixed_factor_ops, \
1333 _flags), \
1334 }
1335
1336#define CLK_FIXED_FACTOR_HW(_struct, _name, _parent, \
1337 _div, _mult, _flags) \
1338 struct clk_fixed_factor _struct = { \
1339 .div = _div, \
1340 .mult = _mult, \
1341 .hw.init = CLK_HW_INIT_HW(_name, \
1342 _parent, \
1343 &clk_fixed_factor_ops, \
1344 _flags), \
1345 }
1346
1347
1348
1349
1350
1351#define CLK_FIXED_FACTOR_HWS(_struct, _name, _parent, \
1352 _div, _mult, _flags) \
1353 struct clk_fixed_factor _struct = { \
1354 .div = _div, \
1355 .mult = _mult, \
1356 .hw.init = CLK_HW_INIT_HWS(_name, \
1357 _parent, \
1358 &clk_fixed_factor_ops, \
1359 _flags), \
1360 }
1361
1362#define CLK_FIXED_FACTOR_FW_NAME(_struct, _name, _parent, \
1363 _div, _mult, _flags) \
1364 struct clk_fixed_factor _struct = { \
1365 .div = _div, \
1366 .mult = _mult, \
1367 .hw.init = CLK_HW_INIT_FW_NAME(_name, \
1368 _parent, \
1369 &clk_fixed_factor_ops, \
1370 _flags), \
1371 }
1372
1373#ifdef CONFIG_OF
1374int of_clk_add_provider(struct device_node *np,
1375 struct clk *(*clk_src_get)(struct of_phandle_args *args,
1376 void *data),
1377 void *data);
1378int of_clk_add_hw_provider(struct device_node *np,
1379 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1380 void *data),
1381 void *data);
1382int devm_of_clk_add_hw_provider(struct device *dev,
1383 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1384 void *data),
1385 void *data);
1386void of_clk_del_provider(struct device_node *np);
1387void devm_of_clk_del_provider(struct device *dev);
1388struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
1389 void *data);
1390struct clk_hw *of_clk_hw_simple_get(struct of_phandle_args *clkspec,
1391 void *data);
1392struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
1393struct clk_hw *of_clk_hw_onecell_get(struct of_phandle_args *clkspec,
1394 void *data);
1395int of_clk_parent_fill(struct device_node *np, const char **parents,
1396 unsigned int size);
1397int of_clk_detect_critical(struct device_node *np, int index,
1398 unsigned long *flags);
1399
1400#else
1401
1402static inline int of_clk_add_provider(struct device_node *np,
1403 struct clk *(*clk_src_get)(struct of_phandle_args *args,
1404 void *data),
1405 void *data)
1406{
1407 return 0;
1408}
1409static inline int of_clk_add_hw_provider(struct device_node *np,
1410 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1411 void *data),
1412 void *data)
1413{
1414 return 0;
1415}
1416static inline int devm_of_clk_add_hw_provider(struct device *dev,
1417 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1418 void *data),
1419 void *data)
1420{
1421 return 0;
1422}
1423static inline void of_clk_del_provider(struct device_node *np) {}
1424static inline void devm_of_clk_del_provider(struct device *dev) {}
1425static inline struct clk *of_clk_src_simple_get(
1426 struct of_phandle_args *clkspec, void *data)
1427{
1428 return ERR_PTR(-ENOENT);
1429}
1430static inline struct clk_hw *
1431of_clk_hw_simple_get(struct of_phandle_args *clkspec, void *data)
1432{
1433 return ERR_PTR(-ENOENT);
1434}
1435static inline struct clk *of_clk_src_onecell_get(
1436 struct of_phandle_args *clkspec, void *data)
1437{
1438 return ERR_PTR(-ENOENT);
1439}
1440static inline struct clk_hw *
1441of_clk_hw_onecell_get(struct of_phandle_args *clkspec, void *data)
1442{
1443 return ERR_PTR(-ENOENT);
1444}
1445static inline int of_clk_parent_fill(struct device_node *np,
1446 const char **parents, unsigned int size)
1447{
1448 return 0;
1449}
1450static inline int of_clk_detect_critical(struct device_node *np, int index,
1451 unsigned long *flags)
1452{
1453 return 0;
1454}
1455#endif
1456
1457void clk_gate_restore_context(struct clk_hw *hw);
1458
1459#endif
1460