0001
0002
0003
0004
0005
0006 #ifndef __LINUX_CLK_PROVIDER_H
0007 #define __LINUX_CLK_PROVIDER_H
0008
0009 #include <linux/of.h>
0010 #include <linux/of_clk.h>
0011
0012
0013
0014
0015
0016
0017
0018
0019 #define CLK_SET_RATE_GATE BIT(0)
0020 #define CLK_SET_PARENT_GATE BIT(1)
0021 #define CLK_SET_RATE_PARENT BIT(2)
0022 #define CLK_IGNORE_UNUSED BIT(3)
0023
0024
0025 #define CLK_GET_RATE_NOCACHE BIT(6)
0026 #define CLK_SET_RATE_NO_REPARENT BIT(7)
0027 #define CLK_GET_ACCURACY_NOCACHE BIT(8)
0028 #define CLK_RECALC_NEW_RATES BIT(9)
0029 #define CLK_SET_RATE_UNGATE BIT(10)
0030 #define CLK_IS_CRITICAL BIT(11)
0031
0032 #define CLK_OPS_PARENT_ENABLE BIT(12)
0033
0034 #define CLK_DUTY_CYCLE_PARENT BIT(13)
0035
0036 struct clk;
0037 struct clk_hw;
0038 struct clk_core;
0039 struct dentry;
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 struct clk_rate_request {
0056 unsigned long rate;
0057 unsigned long min_rate;
0058 unsigned long max_rate;
0059 unsigned long best_parent_rate;
0060 struct clk_hw *best_parent_hw;
0061 };
0062
0063
0064
0065
0066
0067
0068
0069 struct clk_duty {
0070 unsigned int num;
0071 unsigned int den;
0072 };
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220 struct clk_ops {
0221 int (*prepare)(struct clk_hw *hw);
0222 void (*unprepare)(struct clk_hw *hw);
0223 int (*is_prepared)(struct clk_hw *hw);
0224 void (*unprepare_unused)(struct clk_hw *hw);
0225 int (*enable)(struct clk_hw *hw);
0226 void (*disable)(struct clk_hw *hw);
0227 int (*is_enabled)(struct clk_hw *hw);
0228 void (*disable_unused)(struct clk_hw *hw);
0229 int (*save_context)(struct clk_hw *hw);
0230 void (*restore_context)(struct clk_hw *hw);
0231 unsigned long (*recalc_rate)(struct clk_hw *hw,
0232 unsigned long parent_rate);
0233 long (*round_rate)(struct clk_hw *hw, unsigned long rate,
0234 unsigned long *parent_rate);
0235 int (*determine_rate)(struct clk_hw *hw,
0236 struct clk_rate_request *req);
0237 int (*set_parent)(struct clk_hw *hw, u8 index);
0238 u8 (*get_parent)(struct clk_hw *hw);
0239 int (*set_rate)(struct clk_hw *hw, unsigned long rate,
0240 unsigned long parent_rate);
0241 int (*set_rate_and_parent)(struct clk_hw *hw,
0242 unsigned long rate,
0243 unsigned long parent_rate, u8 index);
0244 unsigned long (*recalc_accuracy)(struct clk_hw *hw,
0245 unsigned long parent_accuracy);
0246 int (*get_phase)(struct clk_hw *hw);
0247 int (*set_phase)(struct clk_hw *hw, int degrees);
0248 int (*get_duty_cycle)(struct clk_hw *hw,
0249 struct clk_duty *duty);
0250 int (*set_duty_cycle)(struct clk_hw *hw,
0251 struct clk_duty *duty);
0252 int (*init)(struct clk_hw *hw);
0253 void (*terminate)(struct clk_hw *hw);
0254 void (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
0255 };
0256
0257
0258
0259
0260
0261
0262
0263
0264 struct clk_parent_data {
0265 const struct clk_hw *hw;
0266 const char *fw_name;
0267 const char *name;
0268 int index;
0269 };
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285 struct clk_init_data {
0286 const char *name;
0287 const struct clk_ops *ops;
0288
0289 const char * const *parent_names;
0290 const struct clk_parent_data *parent_data;
0291 const struct clk_hw **parent_hws;
0292 u8 num_parents;
0293 unsigned long flags;
0294 };
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312 struct clk_hw {
0313 struct clk_core *core;
0314 struct clk *clk;
0315 const struct clk_init_data *init;
0316 };
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338 struct clk_fixed_rate {
0339 struct clk_hw hw;
0340 unsigned long fixed_rate;
0341 unsigned long fixed_accuracy;
0342 unsigned long flags;
0343 };
0344
0345 #define CLK_FIXED_RATE_PARENT_ACCURACY BIT(0)
0346
0347 extern const struct clk_ops clk_fixed_rate_ops;
0348 struct clk_hw *__clk_hw_register_fixed_rate(struct device *dev,
0349 struct device_node *np, const char *name,
0350 const char *parent_name, const struct clk_hw *parent_hw,
0351 const struct clk_parent_data *parent_data, unsigned long flags,
0352 unsigned long fixed_rate, unsigned long fixed_accuracy,
0353 unsigned long clk_fixed_flags);
0354 struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
0355 const char *parent_name, unsigned long flags,
0356 unsigned long fixed_rate);
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366 #define clk_hw_register_fixed_rate(dev, name, parent_name, flags, fixed_rate) \
0367 __clk_hw_register_fixed_rate((dev), NULL, (name), (parent_name), NULL, \
0368 NULL, (flags), (fixed_rate), 0, 0)
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378 #define clk_hw_register_fixed_rate_parent_hw(dev, name, parent_hw, flags, \
0379 fixed_rate) \
0380 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, (parent_hw), \
0381 NULL, (flags), (fixed_rate), 0, 0)
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391 #define clk_hw_register_fixed_rate_parent_data(dev, name, parent_hw, flags, \
0392 fixed_rate) \
0393 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, NULL, \
0394 (parent_data), (flags), (fixed_rate), 0, \
0395 0)
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406 #define clk_hw_register_fixed_rate_with_accuracy(dev, name, parent_name, \
0407 flags, fixed_rate, \
0408 fixed_accuracy) \
0409 __clk_hw_register_fixed_rate((dev), NULL, (name), (parent_name), \
0410 NULL, NULL, (flags), (fixed_rate), \
0411 (fixed_accuracy), 0)
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422 #define clk_hw_register_fixed_rate_with_accuracy_parent_hw(dev, name, \
0423 parent_hw, flags, fixed_rate, fixed_accuracy) \
0424 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, (parent_hw) \
0425 NULL, NULL, (flags), (fixed_rate), \
0426 (fixed_accuracy), 0)
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437 #define clk_hw_register_fixed_rate_with_accuracy_parent_data(dev, name, \
0438 parent_data, flags, fixed_rate, fixed_accuracy) \
0439 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, NULL, \
0440 (parent_data), NULL, (flags), \
0441 (fixed_rate), (fixed_accuracy), 0)
0442
0443 void clk_unregister_fixed_rate(struct clk *clk);
0444 void clk_hw_unregister_fixed_rate(struct clk_hw *hw);
0445
0446 void of_fixed_clk_setup(struct device_node *np);
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471 struct clk_gate {
0472 struct clk_hw hw;
0473 void __iomem *reg;
0474 u8 bit_idx;
0475 u8 flags;
0476 spinlock_t *lock;
0477 };
0478
0479 #define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
0480
0481 #define CLK_GATE_SET_TO_DISABLE BIT(0)
0482 #define CLK_GATE_HIWORD_MASK BIT(1)
0483 #define CLK_GATE_BIG_ENDIAN BIT(2)
0484
0485 extern const struct clk_ops clk_gate_ops;
0486 struct clk_hw *__clk_hw_register_gate(struct device *dev,
0487 struct device_node *np, const char *name,
0488 const char *parent_name, const struct clk_hw *parent_hw,
0489 const struct clk_parent_data *parent_data,
0490 unsigned long flags,
0491 void __iomem *reg, u8 bit_idx,
0492 u8 clk_gate_flags, spinlock_t *lock);
0493 struct clk_hw *__devm_clk_hw_register_gate(struct device *dev,
0494 struct device_node *np, const char *name,
0495 const char *parent_name, const struct clk_hw *parent_hw,
0496 const struct clk_parent_data *parent_data,
0497 unsigned long flags,
0498 void __iomem *reg, u8 bit_idx,
0499 u8 clk_gate_flags, spinlock_t *lock);
0500 struct clk *clk_register_gate(struct device *dev, const char *name,
0501 const char *parent_name, unsigned long flags,
0502 void __iomem *reg, u8 bit_idx,
0503 u8 clk_gate_flags, spinlock_t *lock);
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515 #define clk_hw_register_gate(dev, name, parent_name, flags, reg, bit_idx, \
0516 clk_gate_flags, lock) \
0517 __clk_hw_register_gate((dev), NULL, (name), (parent_name), NULL, \
0518 NULL, (flags), (reg), (bit_idx), \
0519 (clk_gate_flags), (lock))
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532 #define clk_hw_register_gate_parent_hw(dev, name, parent_hw, flags, reg, \
0533 bit_idx, clk_gate_flags, lock) \
0534 __clk_hw_register_gate((dev), NULL, (name), NULL, (parent_hw), \
0535 NULL, (flags), (reg), (bit_idx), \
0536 (clk_gate_flags), (lock))
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549 #define clk_hw_register_gate_parent_data(dev, name, parent_data, flags, reg, \
0550 bit_idx, clk_gate_flags, lock) \
0551 __clk_hw_register_gate((dev), NULL, (name), NULL, NULL, (parent_data), \
0552 (flags), (reg), (bit_idx), \
0553 (clk_gate_flags), (lock))
0554
0555
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565 #define devm_clk_hw_register_gate(dev, name, parent_name, flags, reg, bit_idx,\
0566 clk_gate_flags, lock) \
0567 __devm_clk_hw_register_gate((dev), NULL, (name), (parent_name), NULL, \
0568 NULL, (flags), (reg), (bit_idx), \
0569 (clk_gate_flags), (lock))
0570 void clk_unregister_gate(struct clk *clk);
0571 void clk_hw_unregister_gate(struct clk_hw *hw);
0572 int clk_gate_is_enabled(struct clk_hw *hw);
0573
0574 struct clk_div_table {
0575 unsigned int val;
0576 unsigned int div;
0577 };
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601
0602
0603
0604
0605
0606
0607
0608
0609
0610
0611
0612
0613
0614
0615
0616
0617
0618
0619 struct clk_divider {
0620 struct clk_hw hw;
0621 void __iomem *reg;
0622 u8 shift;
0623 u8 width;
0624 u8 flags;
0625 const struct clk_div_table *table;
0626 spinlock_t *lock;
0627 };
0628
0629 #define clk_div_mask(width) ((1 << (width)) - 1)
0630 #define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
0631
0632 #define CLK_DIVIDER_ONE_BASED BIT(0)
0633 #define CLK_DIVIDER_POWER_OF_TWO BIT(1)
0634 #define CLK_DIVIDER_ALLOW_ZERO BIT(2)
0635 #define CLK_DIVIDER_HIWORD_MASK BIT(3)
0636 #define CLK_DIVIDER_ROUND_CLOSEST BIT(4)
0637 #define CLK_DIVIDER_READ_ONLY BIT(5)
0638 #define CLK_DIVIDER_MAX_AT_ZERO BIT(6)
0639 #define CLK_DIVIDER_BIG_ENDIAN BIT(7)
0640
0641 extern const struct clk_ops clk_divider_ops;
0642 extern const struct clk_ops clk_divider_ro_ops;
0643
0644 unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate,
0645 unsigned int val, const struct clk_div_table *table,
0646 unsigned long flags, unsigned long width);
0647 long divider_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
0648 unsigned long rate, unsigned long *prate,
0649 const struct clk_div_table *table,
0650 u8 width, unsigned long flags);
0651 long divider_ro_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
0652 unsigned long rate, unsigned long *prate,
0653 const struct clk_div_table *table, u8 width,
0654 unsigned long flags, unsigned int val);
0655 int divider_determine_rate(struct clk_hw *hw, struct clk_rate_request *req,
0656 const struct clk_div_table *table, u8 width,
0657 unsigned long flags);
0658 int divider_ro_determine_rate(struct clk_hw *hw, struct clk_rate_request *req,
0659 const struct clk_div_table *table, u8 width,
0660 unsigned long flags, unsigned int val);
0661 int divider_get_val(unsigned long rate, unsigned long parent_rate,
0662 const struct clk_div_table *table, u8 width,
0663 unsigned long flags);
0664
0665 struct clk_hw *__clk_hw_register_divider(struct device *dev,
0666 struct device_node *np, const char *name,
0667 const char *parent_name, const struct clk_hw *parent_hw,
0668 const struct clk_parent_data *parent_data, unsigned long flags,
0669 void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
0670 const struct clk_div_table *table, spinlock_t *lock);
0671 struct clk_hw *__devm_clk_hw_register_divider(struct device *dev,
0672 struct device_node *np, const char *name,
0673 const char *parent_name, const struct clk_hw *parent_hw,
0674 const struct clk_parent_data *parent_data, unsigned long flags,
0675 void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
0676 const struct clk_div_table *table, spinlock_t *lock);
0677 struct clk *clk_register_divider_table(struct device *dev, const char *name,
0678 const char *parent_name, unsigned long flags,
0679 void __iomem *reg, u8 shift, u8 width,
0680 u8 clk_divider_flags, const struct clk_div_table *table,
0681 spinlock_t *lock);
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691
0692
0693
0694 #define clk_register_divider(dev, name, parent_name, flags, reg, shift, width, \
0695 clk_divider_flags, lock) \
0696 clk_register_divider_table((dev), (name), (parent_name), (flags), \
0697 (reg), (shift), (width), \
0698 (clk_divider_flags), NULL, (lock))
0699
0700
0701
0702
0703
0704
0705
0706
0707
0708
0709
0710
0711 #define clk_hw_register_divider(dev, name, parent_name, flags, reg, shift, \
0712 width, clk_divider_flags, lock) \
0713 __clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL, \
0714 NULL, (flags), (reg), (shift), (width), \
0715 (clk_divider_flags), NULL, (lock))
0716
0717
0718
0719
0720
0721
0722
0723
0724
0725
0726
0727
0728
0729 #define clk_hw_register_divider_parent_hw(dev, name, parent_hw, flags, reg, \
0730 shift, width, clk_divider_flags, \
0731 lock) \
0732 __clk_hw_register_divider((dev), NULL, (name), NULL, (parent_hw), \
0733 NULL, (flags), (reg), (shift), (width), \
0734 (clk_divider_flags), NULL, (lock))
0735
0736
0737
0738
0739
0740
0741
0742
0743
0744
0745
0746
0747
0748 #define clk_hw_register_divider_parent_data(dev, name, parent_data, flags, \
0749 reg, shift, width, \
0750 clk_divider_flags, lock) \
0751 __clk_hw_register_divider((dev), NULL, (name), NULL, NULL, \
0752 (parent_data), (flags), (reg), (shift), \
0753 (width), (clk_divider_flags), NULL, (lock))
0754
0755
0756
0757
0758
0759
0760
0761
0762
0763
0764
0765
0766
0767
0768 #define clk_hw_register_divider_table(dev, name, parent_name, flags, reg, \
0769 shift, width, clk_divider_flags, table, \
0770 lock) \
0771 __clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL, \
0772 NULL, (flags), (reg), (shift), (width), \
0773 (clk_divider_flags), (table), (lock))
0774
0775
0776
0777
0778
0779
0780
0781
0782
0783
0784
0785
0786
0787
0788 #define clk_hw_register_divider_table_parent_hw(dev, name, parent_hw, flags, \
0789 reg, shift, width, \
0790 clk_divider_flags, table, \
0791 lock) \
0792 __clk_hw_register_divider((dev), NULL, (name), NULL, (parent_hw), \
0793 NULL, (flags), (reg), (shift), (width), \
0794 (clk_divider_flags), (table), (lock))
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809 #define clk_hw_register_divider_table_parent_data(dev, name, parent_data, \
0810 flags, reg, shift, width, \
0811 clk_divider_flags, table, \
0812 lock) \
0813 __clk_hw_register_divider((dev), NULL, (name), NULL, NULL, \
0814 (parent_data), (flags), (reg), (shift), \
0815 (width), (clk_divider_flags), (table), \
0816 (lock))
0817
0818
0819
0820
0821
0822
0823
0824
0825
0826
0827
0828
0829 #define devm_clk_hw_register_divider(dev, name, parent_name, flags, reg, shift, \
0830 width, clk_divider_flags, lock) \
0831 __devm_clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL, \
0832 NULL, (flags), (reg), (shift), (width), \
0833 (clk_divider_flags), NULL, (lock))
0834
0835
0836
0837
0838
0839
0840
0841
0842
0843
0844
0845
0846 #define devm_clk_hw_register_divider_parent_hw(dev, name, parent_hw, flags, \
0847 reg, shift, width, \
0848 clk_divider_flags, lock) \
0849 __devm_clk_hw_register_divider((dev), NULL, (name), NULL, \
0850 (parent_hw), NULL, (flags), (reg), \
0851 (shift), (width), (clk_divider_flags), \
0852 NULL, (lock))
0853
0854
0855
0856
0857
0858
0859
0860
0861
0862
0863
0864
0865
0866
0867 #define devm_clk_hw_register_divider_table(dev, name, parent_name, flags, \
0868 reg, shift, width, \
0869 clk_divider_flags, table, lock) \
0870 __devm_clk_hw_register_divider((dev), NULL, (name), (parent_name), \
0871 NULL, NULL, (flags), (reg), (shift), \
0872 (width), (clk_divider_flags), (table), \
0873 (lock))
0874
0875 void clk_unregister_divider(struct clk *clk);
0876 void clk_hw_unregister_divider(struct clk_hw *hw);
0877
0878
0879
0880
0881
0882
0883
0884
0885
0886
0887
0888
0889
0890
0891
0892
0893
0894
0895
0896
0897
0898
0899
0900
0901
0902
0903
0904
0905
0906
0907 struct clk_mux {
0908 struct clk_hw hw;
0909 void __iomem *reg;
0910 const u32 *table;
0911 u32 mask;
0912 u8 shift;
0913 u8 flags;
0914 spinlock_t *lock;
0915 };
0916
0917 #define to_clk_mux(_hw) container_of(_hw, struct clk_mux, hw)
0918
0919 #define CLK_MUX_INDEX_ONE BIT(0)
0920 #define CLK_MUX_INDEX_BIT BIT(1)
0921 #define CLK_MUX_HIWORD_MASK BIT(2)
0922 #define CLK_MUX_READ_ONLY BIT(3)
0923 #define CLK_MUX_ROUND_CLOSEST BIT(4)
0924 #define CLK_MUX_BIG_ENDIAN BIT(5)
0925
0926 extern const struct clk_ops clk_mux_ops;
0927 extern const struct clk_ops clk_mux_ro_ops;
0928
0929 struct clk_hw *__clk_hw_register_mux(struct device *dev, struct device_node *np,
0930 const char *name, u8 num_parents,
0931 const char * const *parent_names,
0932 const struct clk_hw **parent_hws,
0933 const struct clk_parent_data *parent_data,
0934 unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
0935 u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
0936 struct clk_hw *__devm_clk_hw_register_mux(struct device *dev, struct device_node *np,
0937 const char *name, u8 num_parents,
0938 const char * const *parent_names,
0939 const struct clk_hw **parent_hws,
0940 const struct clk_parent_data *parent_data,
0941 unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
0942 u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
0943 struct clk *clk_register_mux_table(struct device *dev, const char *name,
0944 const char * const *parent_names, u8 num_parents,
0945 unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
0946 u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
0947
0948 #define clk_register_mux(dev, name, parent_names, num_parents, flags, reg, \
0949 shift, width, clk_mux_flags, lock) \
0950 clk_register_mux_table((dev), (name), (parent_names), (num_parents), \
0951 (flags), (reg), (shift), BIT((width)) - 1, \
0952 (clk_mux_flags), NULL, (lock))
0953 #define clk_hw_register_mux_table(dev, name, parent_names, num_parents, \
0954 flags, reg, shift, mask, clk_mux_flags, \
0955 table, lock) \
0956 __clk_hw_register_mux((dev), NULL, (name), (num_parents), \
0957 (parent_names), NULL, NULL, (flags), (reg), \
0958 (shift), (mask), (clk_mux_flags), (table), \
0959 (lock))
0960 #define clk_hw_register_mux(dev, name, parent_names, num_parents, flags, reg, \
0961 shift, width, clk_mux_flags, lock) \
0962 __clk_hw_register_mux((dev), NULL, (name), (num_parents), \
0963 (parent_names), NULL, NULL, (flags), (reg), \
0964 (shift), BIT((width)) - 1, (clk_mux_flags), \
0965 NULL, (lock))
0966 #define clk_hw_register_mux_hws(dev, name, parent_hws, num_parents, flags, \
0967 reg, shift, width, clk_mux_flags, lock) \
0968 __clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, \
0969 (parent_hws), NULL, (flags), (reg), (shift), \
0970 BIT((width)) - 1, (clk_mux_flags), NULL, (lock))
0971 #define clk_hw_register_mux_parent_data(dev, name, parent_data, num_parents, \
0972 flags, reg, shift, width, \
0973 clk_mux_flags, lock) \
0974 __clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, NULL, \
0975 (parent_data), (flags), (reg), (shift), \
0976 BIT((width)) - 1, (clk_mux_flags), NULL, (lock))
0977 #define devm_clk_hw_register_mux(dev, name, parent_names, num_parents, flags, reg, \
0978 shift, width, clk_mux_flags, lock) \
0979 __devm_clk_hw_register_mux((dev), NULL, (name), (num_parents), \
0980 (parent_names), NULL, NULL, (flags), (reg), \
0981 (shift), BIT((width)) - 1, (clk_mux_flags), \
0982 NULL, (lock))
0983 #define devm_clk_hw_register_mux_parent_hws(dev, name, parent_hws, \
0984 num_parents, flags, reg, shift, \
0985 width, clk_mux_flags, lock) \
0986 __devm_clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, \
0987 (parent_hws), NULL, (flags), (reg), \
0988 (shift), BIT((width)) - 1, \
0989 (clk_mux_flags), NULL, (lock))
0990
0991 int clk_mux_val_to_index(struct clk_hw *hw, const u32 *table, unsigned int flags,
0992 unsigned int val);
0993 unsigned int clk_mux_index_to_val(const u32 *table, unsigned int flags, u8 index);
0994
0995 void clk_unregister_mux(struct clk *clk);
0996 void clk_hw_unregister_mux(struct clk_hw *hw);
0997
0998 void of_fixed_factor_clk_setup(struct device_node *node);
0999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012 struct clk_fixed_factor {
1013 struct clk_hw hw;
1014 unsigned int mult;
1015 unsigned int div;
1016 };
1017
1018 #define to_clk_fixed_factor(_hw) container_of(_hw, struct clk_fixed_factor, hw)
1019
1020 extern const struct clk_ops clk_fixed_factor_ops;
1021 struct clk *clk_register_fixed_factor(struct device *dev, const char *name,
1022 const char *parent_name, unsigned long flags,
1023 unsigned int mult, unsigned int div);
1024 void clk_unregister_fixed_factor(struct clk *clk);
1025 struct clk_hw *clk_hw_register_fixed_factor(struct device *dev,
1026 const char *name, const char *parent_name, unsigned long flags,
1027 unsigned int mult, unsigned int div);
1028 void clk_hw_unregister_fixed_factor(struct clk_hw *hw);
1029 struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev,
1030 const char *name, const char *parent_name, unsigned long flags,
1031 unsigned int mult, unsigned int div);
1032 struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev,
1033 const char *name, unsigned int index, unsigned long flags,
1034 unsigned int mult, unsigned int div);
1035
1036 struct clk_hw *devm_clk_hw_register_fixed_factor_parent_hw(struct device *dev,
1037 const char *name, const struct clk_hw *parent_hw,
1038 unsigned long flags, unsigned int mult, unsigned int div);
1039
1040 struct clk_hw *clk_hw_register_fixed_factor_parent_hw(struct device *dev,
1041 const char *name, const struct clk_hw *parent_hw,
1042 unsigned long flags, unsigned int mult, unsigned int div);
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071 struct clk_fractional_divider {
1072 struct clk_hw hw;
1073 void __iomem *reg;
1074 u8 mshift;
1075 u8 mwidth;
1076 u32 mmask;
1077 u8 nshift;
1078 u8 nwidth;
1079 u32 nmask;
1080 u8 flags;
1081 void (*approximation)(struct clk_hw *hw,
1082 unsigned long rate, unsigned long *parent_rate,
1083 unsigned long *m, unsigned long *n);
1084 spinlock_t *lock;
1085 };
1086
1087 #define to_clk_fd(_hw) container_of(_hw, struct clk_fractional_divider, hw)
1088
1089 #define CLK_FRAC_DIVIDER_ZERO_BASED BIT(0)
1090 #define CLK_FRAC_DIVIDER_BIG_ENDIAN BIT(1)
1091 #define CLK_FRAC_DIVIDER_POWER_OF_TWO_PS BIT(2)
1092
1093 struct clk *clk_register_fractional_divider(struct device *dev,
1094 const char *name, const char *parent_name, unsigned long flags,
1095 void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth,
1096 u8 clk_divider_flags, spinlock_t *lock);
1097 struct clk_hw *clk_hw_register_fractional_divider(struct device *dev,
1098 const char *name, const char *parent_name, unsigned long flags,
1099 void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth,
1100 u8 clk_divider_flags, spinlock_t *lock);
1101 void clk_hw_unregister_fractional_divider(struct clk_hw *hw);
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127 struct clk_multiplier {
1128 struct clk_hw hw;
1129 void __iomem *reg;
1130 u8 shift;
1131 u8 width;
1132 u8 flags;
1133 spinlock_t *lock;
1134 };
1135
1136 #define to_clk_multiplier(_hw) container_of(_hw, struct clk_multiplier, hw)
1137
1138 #define CLK_MULTIPLIER_ZERO_BYPASS BIT(0)
1139 #define CLK_MULTIPLIER_ROUND_CLOSEST BIT(1)
1140 #define CLK_MULTIPLIER_BIG_ENDIAN BIT(2)
1141
1142 extern const struct clk_ops clk_multiplier_ops;
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155 struct clk_composite {
1156 struct clk_hw hw;
1157 struct clk_ops ops;
1158
1159 struct clk_hw *mux_hw;
1160 struct clk_hw *rate_hw;
1161 struct clk_hw *gate_hw;
1162
1163 const struct clk_ops *mux_ops;
1164 const struct clk_ops *rate_ops;
1165 const struct clk_ops *gate_ops;
1166 };
1167
1168 #define to_clk_composite(_hw) container_of(_hw, struct clk_composite, hw)
1169
1170 struct clk *clk_register_composite(struct device *dev, const char *name,
1171 const char * const *parent_names, int num_parents,
1172 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1173 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1174 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1175 unsigned long flags);
1176 struct clk *clk_register_composite_pdata(struct device *dev, const char *name,
1177 const struct clk_parent_data *parent_data, int num_parents,
1178 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1179 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1180 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1181 unsigned long flags);
1182 void clk_unregister_composite(struct clk *clk);
1183 struct clk_hw *clk_hw_register_composite(struct device *dev, const char *name,
1184 const char * const *parent_names, int num_parents,
1185 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1186 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1187 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1188 unsigned long flags);
1189 struct clk_hw *clk_hw_register_composite_pdata(struct device *dev,
1190 const char *name,
1191 const struct clk_parent_data *parent_data, int num_parents,
1192 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1193 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1194 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1195 unsigned long flags);
1196 struct clk_hw *devm_clk_hw_register_composite_pdata(struct device *dev,
1197 const char *name, const struct clk_parent_data *parent_data,
1198 int num_parents,
1199 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1200 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1201 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1202 unsigned long flags);
1203 void clk_hw_unregister_composite(struct clk_hw *hw);
1204
1205 struct clk *clk_register(struct device *dev, struct clk_hw *hw);
1206 struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw);
1207
1208 int __must_check clk_hw_register(struct device *dev, struct clk_hw *hw);
1209 int __must_check devm_clk_hw_register(struct device *dev, struct clk_hw *hw);
1210 int __must_check of_clk_hw_register(struct device_node *node, struct clk_hw *hw);
1211
1212 void clk_unregister(struct clk *clk);
1213
1214 void clk_hw_unregister(struct clk_hw *hw);
1215
1216
1217 const char *__clk_get_name(const struct clk *clk);
1218 const char *clk_hw_get_name(const struct clk_hw *hw);
1219 #ifdef CONFIG_COMMON_CLK
1220 struct clk_hw *__clk_get_hw(struct clk *clk);
1221 #else
1222 static inline struct clk_hw *__clk_get_hw(struct clk *clk)
1223 {
1224 return (struct clk_hw *)clk;
1225 }
1226 #endif
1227
1228 struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *con_id);
1229 struct clk *devm_clk_hw_get_clk(struct device *dev, struct clk_hw *hw,
1230 const char *con_id);
1231
1232 unsigned int clk_hw_get_num_parents(const struct clk_hw *hw);
1233 struct clk_hw *clk_hw_get_parent(const struct clk_hw *hw);
1234 struct clk_hw *clk_hw_get_parent_by_index(const struct clk_hw *hw,
1235 unsigned int index);
1236 int clk_hw_get_parent_index(struct clk_hw *hw);
1237 int clk_hw_set_parent(struct clk_hw *hw, struct clk_hw *new_parent);
1238 unsigned int __clk_get_enable_count(struct clk *clk);
1239 unsigned long clk_hw_get_rate(const struct clk_hw *hw);
1240 unsigned long clk_hw_get_flags(const struct clk_hw *hw);
1241 #define clk_hw_can_set_rate_parent(hw) \
1242 (clk_hw_get_flags((hw)) & CLK_SET_RATE_PARENT)
1243
1244 bool clk_hw_is_prepared(const struct clk_hw *hw);
1245 bool clk_hw_rate_is_protected(const struct clk_hw *hw);
1246 bool clk_hw_is_enabled(const struct clk_hw *hw);
1247 bool __clk_is_enabled(struct clk *clk);
1248 struct clk *__clk_lookup(const char *name);
1249 int __clk_mux_determine_rate(struct clk_hw *hw,
1250 struct clk_rate_request *req);
1251 int __clk_determine_rate(struct clk_hw *core, struct clk_rate_request *req);
1252 int __clk_mux_determine_rate_closest(struct clk_hw *hw,
1253 struct clk_rate_request *req);
1254 int clk_mux_determine_rate_flags(struct clk_hw *hw,
1255 struct clk_rate_request *req,
1256 unsigned long flags);
1257 void clk_hw_reparent(struct clk_hw *hw, struct clk_hw *new_parent);
1258 void clk_hw_set_rate_range(struct clk_hw *hw, unsigned long min_rate,
1259 unsigned long max_rate);
1260
1261 static inline void __clk_hw_set_clk(struct clk_hw *dst, struct clk_hw *src)
1262 {
1263 dst->clk = src->clk;
1264 dst->core = src->core;
1265 }
1266
1267 static inline long divider_round_rate(struct clk_hw *hw, unsigned long rate,
1268 unsigned long *prate,
1269 const struct clk_div_table *table,
1270 u8 width, unsigned long flags)
1271 {
1272 return divider_round_rate_parent(hw, clk_hw_get_parent(hw),
1273 rate, prate, table, width, flags);
1274 }
1275
1276 static inline long divider_ro_round_rate(struct clk_hw *hw, unsigned long rate,
1277 unsigned long *prate,
1278 const struct clk_div_table *table,
1279 u8 width, unsigned long flags,
1280 unsigned int val)
1281 {
1282 return divider_ro_round_rate_parent(hw, clk_hw_get_parent(hw),
1283 rate, prate, table, width, flags,
1284 val);
1285 }
1286
1287
1288
1289
1290 unsigned long clk_hw_round_rate(struct clk_hw *hw, unsigned long rate);
1291
1292 struct clk_onecell_data {
1293 struct clk **clks;
1294 unsigned int clk_num;
1295 };
1296
1297 struct clk_hw_onecell_data {
1298 unsigned int num;
1299 struct clk_hw *hws[];
1300 };
1301
1302 #define CLK_OF_DECLARE(name, compat, fn) OF_DECLARE_1(clk, name, compat, fn)
1303
1304
1305
1306
1307
1308 #define CLK_OF_DECLARE_DRIVER(name, compat, fn) \
1309 static void __init name##_of_clk_init_driver(struct device_node *np) \
1310 { \
1311 of_node_clear_flag(np, OF_POPULATED); \
1312 fn(np); \
1313 } \
1314 OF_DECLARE_1(clk, name, compat, name##_of_clk_init_driver)
1315
1316 #define CLK_HW_INIT(_name, _parent, _ops, _flags) \
1317 (&(struct clk_init_data) { \
1318 .flags = _flags, \
1319 .name = _name, \
1320 .parent_names = (const char *[]) { _parent }, \
1321 .num_parents = 1, \
1322 .ops = _ops, \
1323 })
1324
1325 #define CLK_HW_INIT_HW(_name, _parent, _ops, _flags) \
1326 (&(struct clk_init_data) { \
1327 .flags = _flags, \
1328 .name = _name, \
1329 .parent_hws = (const struct clk_hw*[]) { _parent }, \
1330 .num_parents = 1, \
1331 .ops = _ops, \
1332 })
1333
1334
1335
1336
1337
1338
1339 #define CLK_HW_INIT_HWS(_name, _parent, _ops, _flags) \
1340 (&(struct clk_init_data) { \
1341 .flags = _flags, \
1342 .name = _name, \
1343 .parent_hws = _parent, \
1344 .num_parents = 1, \
1345 .ops = _ops, \
1346 })
1347
1348 #define CLK_HW_INIT_FW_NAME(_name, _parent, _ops, _flags) \
1349 (&(struct clk_init_data) { \
1350 .flags = _flags, \
1351 .name = _name, \
1352 .parent_data = (const struct clk_parent_data[]) { \
1353 { .fw_name = _parent }, \
1354 }, \
1355 .num_parents = 1, \
1356 .ops = _ops, \
1357 })
1358
1359 #define CLK_HW_INIT_PARENTS(_name, _parents, _ops, _flags) \
1360 (&(struct clk_init_data) { \
1361 .flags = _flags, \
1362 .name = _name, \
1363 .parent_names = _parents, \
1364 .num_parents = ARRAY_SIZE(_parents), \
1365 .ops = _ops, \
1366 })
1367
1368 #define CLK_HW_INIT_PARENTS_HW(_name, _parents, _ops, _flags) \
1369 (&(struct clk_init_data) { \
1370 .flags = _flags, \
1371 .name = _name, \
1372 .parent_hws = _parents, \
1373 .num_parents = ARRAY_SIZE(_parents), \
1374 .ops = _ops, \
1375 })
1376
1377 #define CLK_HW_INIT_PARENTS_DATA(_name, _parents, _ops, _flags) \
1378 (&(struct clk_init_data) { \
1379 .flags = _flags, \
1380 .name = _name, \
1381 .parent_data = _parents, \
1382 .num_parents = ARRAY_SIZE(_parents), \
1383 .ops = _ops, \
1384 })
1385
1386 #define CLK_HW_INIT_NO_PARENT(_name, _ops, _flags) \
1387 (&(struct clk_init_data) { \
1388 .flags = _flags, \
1389 .name = _name, \
1390 .parent_names = NULL, \
1391 .num_parents = 0, \
1392 .ops = _ops, \
1393 })
1394
1395 #define CLK_FIXED_FACTOR(_struct, _name, _parent, \
1396 _div, _mult, _flags) \
1397 struct clk_fixed_factor _struct = { \
1398 .div = _div, \
1399 .mult = _mult, \
1400 .hw.init = CLK_HW_INIT(_name, \
1401 _parent, \
1402 &clk_fixed_factor_ops, \
1403 _flags), \
1404 }
1405
1406 #define CLK_FIXED_FACTOR_HW(_struct, _name, _parent, \
1407 _div, _mult, _flags) \
1408 struct clk_fixed_factor _struct = { \
1409 .div = _div, \
1410 .mult = _mult, \
1411 .hw.init = CLK_HW_INIT_HW(_name, \
1412 _parent, \
1413 &clk_fixed_factor_ops, \
1414 _flags), \
1415 }
1416
1417
1418
1419
1420
1421 #define CLK_FIXED_FACTOR_HWS(_struct, _name, _parent, \
1422 _div, _mult, _flags) \
1423 struct clk_fixed_factor _struct = { \
1424 .div = _div, \
1425 .mult = _mult, \
1426 .hw.init = CLK_HW_INIT_HWS(_name, \
1427 _parent, \
1428 &clk_fixed_factor_ops, \
1429 _flags), \
1430 }
1431
1432 #define CLK_FIXED_FACTOR_FW_NAME(_struct, _name, _parent, \
1433 _div, _mult, _flags) \
1434 struct clk_fixed_factor _struct = { \
1435 .div = _div, \
1436 .mult = _mult, \
1437 .hw.init = CLK_HW_INIT_FW_NAME(_name, \
1438 _parent, \
1439 &clk_fixed_factor_ops, \
1440 _flags), \
1441 }
1442
1443 #ifdef CONFIG_OF
1444 int of_clk_add_provider(struct device_node *np,
1445 struct clk *(*clk_src_get)(struct of_phandle_args *args,
1446 void *data),
1447 void *data);
1448 int of_clk_add_hw_provider(struct device_node *np,
1449 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1450 void *data),
1451 void *data);
1452 int devm_of_clk_add_hw_provider(struct device *dev,
1453 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1454 void *data),
1455 void *data);
1456 void of_clk_del_provider(struct device_node *np);
1457 void devm_of_clk_del_provider(struct device *dev);
1458 struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
1459 void *data);
1460 struct clk_hw *of_clk_hw_simple_get(struct of_phandle_args *clkspec,
1461 void *data);
1462 struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
1463 struct clk_hw *of_clk_hw_onecell_get(struct of_phandle_args *clkspec,
1464 void *data);
1465 int of_clk_parent_fill(struct device_node *np, const char **parents,
1466 unsigned int size);
1467 int of_clk_detect_critical(struct device_node *np, int index,
1468 unsigned long *flags);
1469
1470 #else
1471
1472 static inline int of_clk_add_provider(struct device_node *np,
1473 struct clk *(*clk_src_get)(struct of_phandle_args *args,
1474 void *data),
1475 void *data)
1476 {
1477 return 0;
1478 }
1479 static inline int of_clk_add_hw_provider(struct device_node *np,
1480 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1481 void *data),
1482 void *data)
1483 {
1484 return 0;
1485 }
1486 static inline int devm_of_clk_add_hw_provider(struct device *dev,
1487 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1488 void *data),
1489 void *data)
1490 {
1491 return 0;
1492 }
1493 static inline void of_clk_del_provider(struct device_node *np) {}
1494 static inline void devm_of_clk_del_provider(struct device *dev) {}
1495 static inline struct clk *of_clk_src_simple_get(
1496 struct of_phandle_args *clkspec, void *data)
1497 {
1498 return ERR_PTR(-ENOENT);
1499 }
1500 static inline struct clk_hw *
1501 of_clk_hw_simple_get(struct of_phandle_args *clkspec, void *data)
1502 {
1503 return ERR_PTR(-ENOENT);
1504 }
1505 static inline struct clk *of_clk_src_onecell_get(
1506 struct of_phandle_args *clkspec, void *data)
1507 {
1508 return ERR_PTR(-ENOENT);
1509 }
1510 static inline struct clk_hw *
1511 of_clk_hw_onecell_get(struct of_phandle_args *clkspec, void *data)
1512 {
1513 return ERR_PTR(-ENOENT);
1514 }
1515 static inline int of_clk_parent_fill(struct device_node *np,
1516 const char **parents, unsigned int size)
1517 {
1518 return 0;
1519 }
1520 static inline int of_clk_detect_critical(struct device_node *np, int index,
1521 unsigned long *flags)
1522 {
1523 return 0;
1524 }
1525 #endif
1526
1527 void clk_gate_restore_context(struct clk_hw *hw);
1528
1529 #endif