hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/include/linux/clk.h
....@@ -183,6 +183,39 @@
183183 */
184184 bool clk_is_match(const struct clk *p, const struct clk *q);
185185
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
+
186219 #else
187220
188221 static inline int clk_notifier_register(struct clk *clk,
....@@ -235,6 +268,13 @@
235268 {
236269 return p == q;
237270 }
271
+
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) {}
238278
239279 #endif
240280
....@@ -437,6 +477,47 @@
437477 struct clk *devm_clk_get(struct device *dev, const char *id);
438478
439479 /**
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
+/**
440521 * devm_clk_get_optional - lookup and obtain a managed reference to an optional
441522 * clock producer.
442523 * @dev: device for clock "consumer"
....@@ -446,6 +527,50 @@
446527 * In this case, instead of returning -ENOENT, the function returns NULL.
447528 */
448529 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);
449574
450575 /**
451576 * devm_get_clk_from_child - lookup and obtain a managed reference to a
....@@ -463,38 +588,6 @@
463588 */
464589 struct clk *devm_get_clk_from_child(struct device *dev,
465590 struct device_node *np, const char *con_id);
466
-/**
467
- * clk_rate_exclusive_get - get exclusivity over the rate control of a
468
- * producer
469
- * @clk: clock source
470
- *
471
- * This function allows drivers to get exclusive control over the rate of a
472
- * provider. It prevents any other consumer to execute, even indirectly,
473
- * opereation which could alter the rate of the provider or cause glitches
474
- *
475
- * If exlusivity is claimed more than once on clock, even by the same driver,
476
- * the rate effectively gets locked as exclusivity can't be preempted.
477
- *
478
- * Must not be called from within atomic context.
479
- *
480
- * Returns success (0) or negative errno.
481
- */
482
-int clk_rate_exclusive_get(struct clk *clk);
483
-
484
-/**
485
- * clk_rate_exclusive_put - release exclusivity over the rate control of a
486
- * producer
487
- * @clk: clock source
488
- *
489
- * This function allows drivers to release the exclusivity it previously got
490
- * from clk_rate_exclusive_get()
491
- *
492
- * The caller must balance the number of clk_rate_exclusive_get() and
493
- * clk_rate_exclusive_put() calls.
494
- *
495
- * Must not be called from within atomic context.
496
- */
497
-void clk_rate_exclusive_put(struct clk *clk);
498591
499592 /**
500593 * clk_enable - inform the system when the clock source should be running.
....@@ -791,8 +884,32 @@
791884 return NULL;
792885 }
793886
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
+
794899 static inline struct clk *devm_clk_get_optional(struct device *dev,
795900 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)
796913 {
797914 return NULL;
798915 }
....@@ -829,14 +946,6 @@
829946 static inline void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks) {}
830947
831948 static inline void devm_clk_put(struct device *dev, struct clk *clk) {}
832
-
833
-
834
-static inline int clk_rate_exclusive_get(struct clk *clk)
835
-{
836
- return 0;
837
-}
838
-
839
-static inline void clk_rate_exclusive_put(struct clk *clk) {}
840949
841950 static inline int clk_enable(struct clk *clk)
842951 {