hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/include/linux/clk.h
....@@ -1,13 +1,10 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * linux/include/linux/clk.h
34 *
45 * Copyright (C) 2004 ARM Limited.
56 * Written by Deep Blue Solutions Limited.
67 * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129 #ifndef __LINUX_CLK_H
1310 #define __LINUX_CLK_H
....@@ -113,6 +110,17 @@
113110 int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb);
114111
115112 /**
113
+ * devm_clk_notifier_register - register a managed rate-change notifier callback
114
+ * @dev: device for clock "consumer"
115
+ * @clk: clock whose rate we are interested in
116
+ * @nb: notifier block with callback function pointer
117
+ *
118
+ * Returns 0 on success, -EERROR otherwise
119
+ */
120
+int devm_clk_notifier_register(struct device *dev, struct clk *clk,
121
+ struct notifier_block *nb);
122
+
123
+/**
116124 * clk_get_accuracy - obtain the clock accuracy in ppb (parts per billion)
117125 * for a clock source.
118126 * @clk: clock source
....@@ -175,6 +183,39 @@
175183 */
176184 bool clk_is_match(const struct clk *p, const struct clk *q);
177185
186
+/**
187
+ * clk_rate_exclusive_get - get exclusivity over the rate control of a
188
+ * producer
189
+ * @clk: clock source
190
+ *
191
+ * This function allows drivers to get exclusive control over the rate of a
192
+ * provider. It prevents any other consumer to execute, even indirectly,
193
+ * opereation which could alter the rate of the provider or cause glitches
194
+ *
195
+ * If exlusivity is claimed more than once on clock, even by the same driver,
196
+ * the rate effectively gets locked as exclusivity can't be preempted.
197
+ *
198
+ * Must not be called from within atomic context.
199
+ *
200
+ * Returns success (0) or negative errno.
201
+ */
202
+int clk_rate_exclusive_get(struct clk *clk);
203
+
204
+/**
205
+ * clk_rate_exclusive_put - release exclusivity over the rate control of a
206
+ * producer
207
+ * @clk: clock source
208
+ *
209
+ * This function allows drivers to release the exclusivity it previously got
210
+ * from clk_rate_exclusive_get()
211
+ *
212
+ * The caller must balance the number of clk_rate_exclusive_get() and
213
+ * clk_rate_exclusive_put() calls.
214
+ *
215
+ * Must not be called from within atomic context.
216
+ */
217
+void clk_rate_exclusive_put(struct clk *clk);
218
+
178219 #else
179220
180221 static inline int clk_notifier_register(struct clk *clk,
....@@ -185,6 +226,13 @@
185226
186227 static inline int clk_notifier_unregister(struct clk *clk,
187228 struct notifier_block *nb)
229
+{
230
+ return -ENOTSUPP;
231
+}
232
+
233
+static inline int devm_clk_notifier_register(struct device *dev,
234
+ struct clk *clk,
235
+ struct notifier_block *nb)
188236 {
189237 return -ENOTSUPP;
190238 }
....@@ -221,6 +269,13 @@
221269 return p == q;
222270 }
223271
272
+static inline int clk_rate_exclusive_get(struct clk *clk)
273
+{
274
+ return 0;
275
+}
276
+
277
+static inline void clk_rate_exclusive_put(struct clk *clk) {}
278
+
224279 #endif
225280
226281 /**
....@@ -242,7 +297,8 @@
242297 return 0;
243298 }
244299
245
-static inline int __must_check clk_bulk_prepare(int num_clks, struct clk_bulk_data *clks)
300
+static inline int __must_check
301
+clk_bulk_prepare(int num_clks, const struct clk_bulk_data *clks)
246302 {
247303 might_sleep();
248304 return 0;
....@@ -266,7 +322,8 @@
266322 {
267323 might_sleep();
268324 }
269
-static inline void clk_bulk_unprepare(int num_clks, struct clk_bulk_data *clks)
325
+static inline void clk_bulk_unprepare(int num_clks,
326
+ const struct clk_bulk_data *clks)
270327 {
271328 might_sleep();
272329 }
....@@ -362,6 +419,7 @@
362419 /**
363420 * devm_clk_bulk_get_optional - managed get multiple optional consumer clocks
364421 * @dev: device for clock "consumer"
422
+ * @num_clks: the number of clk_bulk_data
365423 * @clks: pointer to the clk_bulk_data table of consumer
366424 *
367425 * Behaves the same as devm_clk_bulk_get() except where there is no clock
....@@ -419,6 +477,47 @@
419477 struct clk *devm_clk_get(struct device *dev, const char *id);
420478
421479 /**
480
+ * devm_clk_get_prepared - devm_clk_get() + clk_prepare()
481
+ * @dev: device for clock "consumer"
482
+ * @id: clock consumer ID
483
+ *
484
+ * Context: May sleep.
485
+ *
486
+ * Return: a struct clk corresponding to the clock producer, or
487
+ * valid IS_ERR() condition containing errno. The implementation
488
+ * uses @dev and @id to determine the clock consumer, and thereby
489
+ * the clock producer. (IOW, @id may be identical strings, but
490
+ * clk_get may return different clock producers depending on @dev.)
491
+ *
492
+ * The returned clk (if valid) is prepared. Drivers must however assume
493
+ * that the clock is not enabled.
494
+ *
495
+ * The clock will automatically be unprepared and freed when the device
496
+ * is unbound from the bus.
497
+ */
498
+struct clk *devm_clk_get_prepared(struct device *dev, const char *id);
499
+
500
+/**
501
+ * devm_clk_get_enabled - devm_clk_get() + clk_prepare_enable()
502
+ * @dev: device for clock "consumer"
503
+ * @id: clock consumer ID
504
+ *
505
+ * Context: May sleep.
506
+ *
507
+ * Return: a struct clk corresponding to the clock producer, or
508
+ * valid IS_ERR() condition containing errno. The implementation
509
+ * uses @dev and @id to determine the clock consumer, and thereby
510
+ * the clock producer. (IOW, @id may be identical strings, but
511
+ * clk_get may return different clock producers depending on @dev.)
512
+ *
513
+ * The returned clk (if valid) is prepared and enabled.
514
+ *
515
+ * The clock will automatically be disabled, unprepared and freed
516
+ * when the device is unbound from the bus.
517
+ */
518
+struct clk *devm_clk_get_enabled(struct device *dev, const char *id);
519
+
520
+/**
422521 * devm_clk_get_optional - lookup and obtain a managed reference to an optional
423522 * clock producer.
424523 * @dev: device for clock "consumer"
....@@ -428,6 +527,50 @@
428527 * In this case, instead of returning -ENOENT, the function returns NULL.
429528 */
430529 struct clk *devm_clk_get_optional(struct device *dev, const char *id);
530
+
531
+/**
532
+ * devm_clk_get_optional_prepared - devm_clk_get_optional() + clk_prepare()
533
+ * @dev: device for clock "consumer"
534
+ * @id: clock consumer ID
535
+ *
536
+ * Context: May sleep.
537
+ *
538
+ * Return: a struct clk corresponding to the clock producer, or
539
+ * valid IS_ERR() condition containing errno. The implementation
540
+ * uses @dev and @id to determine the clock consumer, and thereby
541
+ * the clock producer. If no such clk is found, it returns NULL
542
+ * which serves as a dummy clk. That's the only difference compared
543
+ * to devm_clk_get_prepared().
544
+ *
545
+ * The returned clk (if valid) is prepared. Drivers must however
546
+ * assume that the clock is not enabled.
547
+ *
548
+ * The clock will automatically be unprepared and freed when the
549
+ * device is unbound from the bus.
550
+ */
551
+struct clk *devm_clk_get_optional_prepared(struct device *dev, const char *id);
552
+
553
+/**
554
+ * devm_clk_get_optional_enabled - devm_clk_get_optional() +
555
+ * clk_prepare_enable()
556
+ * @dev: device for clock "consumer"
557
+ * @id: clock consumer ID
558
+ *
559
+ * Context: May sleep.
560
+ *
561
+ * Return: a struct clk corresponding to the clock producer, or
562
+ * valid IS_ERR() condition containing errno. The implementation
563
+ * uses @dev and @id to determine the clock consumer, and thereby
564
+ * the clock producer. If no such clk is found, it returns NULL
565
+ * which serves as a dummy clk. That's the only difference compared
566
+ * to devm_clk_get_enabled().
567
+ *
568
+ * The returned clk (if valid) is prepared and enabled.
569
+ *
570
+ * The clock will automatically be disabled, unprepared and freed
571
+ * when the device is unbound from the bus.
572
+ */
573
+struct clk *devm_clk_get_optional_enabled(struct device *dev, const char *id);
431574
432575 /**
433576 * devm_get_clk_from_child - lookup and obtain a managed reference to a
....@@ -445,38 +588,6 @@
445588 */
446589 struct clk *devm_get_clk_from_child(struct device *dev,
447590 struct device_node *np, const char *con_id);
448
-/**
449
- * clk_rate_exclusive_get - get exclusivity over the rate control of a
450
- * producer
451
- * @clk: clock source
452
- *
453
- * This function allows drivers to get exclusive control over the rate of a
454
- * provider. It prevents any other consumer to execute, even indirectly,
455
- * opereation which could alter the rate of the provider or cause glitches
456
- *
457
- * If exlusivity is claimed more than once on clock, even by the same driver,
458
- * the rate effectively gets locked as exclusivity can't be preempted.
459
- *
460
- * Must not be called from within atomic context.
461
- *
462
- * Returns success (0) or negative errno.
463
- */
464
-int clk_rate_exclusive_get(struct clk *clk);
465
-
466
-/**
467
- * clk_rate_exclusive_put - release exclusivity over the rate control of a
468
- * producer
469
- * @clk: clock source
470
- *
471
- * This function allows drivers to release the exclusivity it previously got
472
- * from clk_rate_exclusive_get()
473
- *
474
- * The caller must balance the number of clk_rate_exclusive_get() and
475
- * clk_rate_exclusive_put() calls.
476
- *
477
- * Must not be called from within atomic context.
478
- */
479
-void clk_rate_exclusive_put(struct clk *clk);
480591
481592 /**
482593 * clk_enable - inform the system when the clock source should be running.
....@@ -627,6 +738,9 @@
627738 * @clk: clock source
628739 * @rate: desired clock rate in Hz
629740 *
741
+ * Updating the rate starts at the top-most affected clock and then
742
+ * walks the tree down to the bottom-most clock that needs updating.
743
+ *
630744 * Returns success (0) or negative errno.
631745 */
632746 int clk_set_rate(struct clk *clk, unsigned long rate);
....@@ -723,6 +837,23 @@
723837 */
724838 struct clk *clk_get_sys(const char *dev_id, const char *con_id);
725839
840
+/**
841
+ * clk_save_context - save clock context for poweroff
842
+ *
843
+ * Saves the context of the clock register for powerstates in which the
844
+ * contents of the registers will be lost. Occurs deep within the suspend
845
+ * code so locking is not necessary.
846
+ */
847
+int clk_save_context(void);
848
+
849
+/**
850
+ * clk_restore_context - restore clock context after poweroff
851
+ *
852
+ * This occurs with all clocks enabled. Occurs deep within the resume code
853
+ * so locking is not necessary.
854
+ */
855
+void clk_restore_context(void);
856
+
726857 #else /* !CONFIG_HAVE_CLK */
727858
728859 static inline struct clk *clk_get(struct device *dev, const char *id)
....@@ -753,8 +884,32 @@
753884 return NULL;
754885 }
755886
887
+static inline struct clk *devm_clk_get_prepared(struct device *dev,
888
+ const char *id)
889
+{
890
+ return NULL;
891
+}
892
+
893
+static inline struct clk *devm_clk_get_enabled(struct device *dev,
894
+ const char *id)
895
+{
896
+ return NULL;
897
+}
898
+
756899 static inline struct clk *devm_clk_get_optional(struct device *dev,
757900 const char *id)
901
+{
902
+ return NULL;
903
+}
904
+
905
+static inline struct clk *devm_clk_get_optional_prepared(struct device *dev,
906
+ const char *id)
907
+{
908
+ return NULL;
909
+}
910
+
911
+static inline struct clk *devm_clk_get_optional_enabled(struct device *dev,
912
+ const char *id)
758913 {
759914 return NULL;
760915 }
....@@ -792,20 +947,13 @@
792947
793948 static inline void devm_clk_put(struct device *dev, struct clk *clk) {}
794949
795
-
796
-static inline int clk_rate_exclusive_get(struct clk *clk)
797
-{
798
- return 0;
799
-}
800
-
801
-static inline void clk_rate_exclusive_put(struct clk *clk) {}
802
-
803950 static inline int clk_enable(struct clk *clk)
804951 {
805952 return 0;
806953 }
807954
808
-static inline int __must_check clk_bulk_enable(int num_clks, struct clk_bulk_data *clks)
955
+static inline int __must_check clk_bulk_enable(int num_clks,
956
+ const struct clk_bulk_data *clks)
809957 {
810958 return 0;
811959 }
....@@ -814,7 +962,7 @@
814962
815963
816964 static inline void clk_bulk_disable(int num_clks,
817
- struct clk_bulk_data *clks) {}
965
+ const struct clk_bulk_data *clks) {}
818966
819967 static inline unsigned long clk_get_rate(struct clk *clk)
820968 {
....@@ -841,6 +989,22 @@
841989 return true;
842990 }
843991
992
+static inline int clk_set_rate_range(struct clk *clk, unsigned long min,
993
+ unsigned long max)
994
+{
995
+ return 0;
996
+}
997
+
998
+static inline int clk_set_min_rate(struct clk *clk, unsigned long rate)
999
+{
1000
+ return 0;
1001
+}
1002
+
1003
+static inline int clk_set_max_rate(struct clk *clk, unsigned long rate)
1004
+{
1005
+ return 0;
1006
+}
1007
+
8441008 static inline int clk_set_parent(struct clk *clk, struct clk *parent)
8451009 {
8461010 return 0;
....@@ -855,6 +1019,14 @@
8551019 {
8561020 return NULL;
8571021 }
1022
+
1023
+static inline int clk_save_context(void)
1024
+{
1025
+ return 0;
1026
+}
1027
+
1028
+static inline void clk_restore_context(void) {}
1029
+
8581030 #endif
8591031
8601032 /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
....@@ -879,8 +1051,8 @@
8791051 clk_unprepare(clk);
8801052 }
8811053
882
-static inline int __must_check clk_bulk_prepare_enable(int num_clks,
883
- struct clk_bulk_data *clks)
1054
+static inline int __must_check
1055
+clk_bulk_prepare_enable(int num_clks, const struct clk_bulk_data *clks)
8841056 {
8851057 int ret;
8861058
....@@ -895,7 +1067,7 @@
8951067 }
8961068
8971069 static inline void clk_bulk_disable_unprepare(int num_clks,
898
- struct clk_bulk_data *clks)
1070
+ const struct clk_bulk_data *clks)
8991071 {
9001072 clk_bulk_disable(num_clks, clks);
9011073 clk_bulk_unprepare(num_clks, clks);