1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/include/linux/clk.h
5 * Copyright (C) 2004 ARM Limited.
6 * Written by Deep Blue Solutions Limited.
7 * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
12 #include <linux/err.h>
13 #include <linux/kernel.h>
14 #include <linux/notifier.h>
19 struct of_phandle_args;
22 * DOC: clk notifier callback types
24 * PRE_RATE_CHANGE - called immediately before the clk rate is changed,
25 * to indicate that the rate change will proceed. Drivers must
26 * immediately terminate any operations that will be affected by the
27 * rate change. Callbacks may either return NOTIFY_DONE, NOTIFY_OK,
28 * NOTIFY_STOP or NOTIFY_BAD.
30 * ABORT_RATE_CHANGE: called if the rate change failed for some reason
31 * after PRE_RATE_CHANGE. In this case, all registered notifiers on
32 * the clk will be called with ABORT_RATE_CHANGE. Callbacks must
33 * always return NOTIFY_DONE or NOTIFY_OK.
35 * POST_RATE_CHANGE - called after the clk rate change has successfully
36 * completed. Callbacks must always return NOTIFY_DONE or NOTIFY_OK.
39 #define PRE_RATE_CHANGE BIT(0)
40 #define POST_RATE_CHANGE BIT(1)
41 #define ABORT_RATE_CHANGE BIT(2)
44 * struct clk_notifier - associate a clk with a notifier
45 * @clk: struct clk * to associate the notifier with
46 * @notifier_head: a blocking_notifier_head for this clk
47 * @node: linked list pointers
49 * A list of struct clk_notifier is maintained by the notifier code.
50 * An entry is created whenever code registers the first notifier on a
51 * particular @clk. Future notifiers on that @clk are added to the
56 struct srcu_notifier_head notifier_head;
57 struct list_head node;
61 * struct clk_notifier_data - rate data to pass to the notifier callback
62 * @clk: struct clk * being changed
63 * @old_rate: previous rate of this clk
64 * @new_rate: new rate of this clk
66 * For a pre-notifier, old_rate is the clk's rate before this rate
67 * change, and new_rate is what the rate will be in the future. For a
68 * post-notifier, old_rate and new_rate are both set to the clk's
69 * current rate (this was done to optimize the implementation).
71 struct clk_notifier_data {
73 unsigned long old_rate;
74 unsigned long new_rate;
78 * struct clk_bulk_data - Data used for bulk clk operations.
80 * @id: clock consumer ID
81 * @clk: struct clk * to store the associated clock
83 * The CLK APIs provide a series of clk_bulk_() API calls as
84 * a convenience to consumers which require multiple clks. This
85 * structure is used to manage data for these calls.
87 struct clk_bulk_data {
92 #ifdef CONFIG_COMMON_CLK
95 * clk_notifier_register - register a clock rate-change notifier callback
96 * @clk: clock whose rate we are interested in
97 * @nb: notifier block with callback function pointer
99 * ProTip: debugging across notifier chains can be frustrating. Make sure that
100 * your notifier callback function prints a nice big warning in case of
103 int clk_notifier_register(struct clk *clk, struct notifier_block *nb);
106 * clk_notifier_unregister - unregister a clock rate-change notifier callback
107 * @clk: clock whose rate we are no longer interested in
108 * @nb: notifier block which will be unregistered
110 int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb);
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
118 * Returns 0 on success, -EERROR otherwise
120 int devm_clk_notifier_register(struct device *dev, struct clk *clk,
121 struct notifier_block *nb);
124 * clk_get_accuracy - obtain the clock accuracy in ppb (parts per billion)
125 * for a clock source.
128 * This gets the clock source accuracy expressed in ppb.
129 * A perfect clock returns 0.
131 long clk_get_accuracy(struct clk *clk);
134 * clk_set_phase - adjust the phase shift of a clock signal
135 * @clk: clock signal source
136 * @degrees: number of degrees the signal is shifted
138 * Shifts the phase of a clock signal by the specified degrees. Returns 0 on
139 * success, -EERROR otherwise.
141 int clk_set_phase(struct clk *clk, int degrees);
144 * clk_get_phase - return the phase shift of a clock signal
145 * @clk: clock signal source
147 * Returns the phase shift of a clock node in degrees, otherwise returns
150 int clk_get_phase(struct clk *clk);
153 * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal
154 * @clk: clock signal source
155 * @num: numerator of the duty cycle ratio to be applied
156 * @den: denominator of the duty cycle ratio to be applied
158 * Adjust the duty cycle of a clock signal by the specified ratio. Returns 0 on
159 * success, -EERROR otherwise.
161 int clk_set_duty_cycle(struct clk *clk, unsigned int num, unsigned int den);
164 * clk_get_scaled_duty_cycle - return the duty cycle ratio of a clock signal
165 * @clk: clock signal source
166 * @scale: scaling factor to be applied to represent the ratio as an integer
168 * Returns the duty cycle ratio multiplied by the scale provided, otherwise
171 int clk_get_scaled_duty_cycle(struct clk *clk, unsigned int scale);
174 * clk_is_match - check if two clk's point to the same hardware clock
175 * @p: clk compared against q
176 * @q: clk compared against p
178 * Returns true if the two struct clk pointers both point to the same hardware
179 * clock node. Put differently, returns true if @p and @q
180 * share the same &struct clk_core object.
182 * Returns false otherwise. Note that two NULL clks are treated as matching.
184 bool clk_is_match(const struct clk *p, const struct clk *q);
187 * clk_rate_exclusive_get - get exclusivity over the rate control of a
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
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.
198 * Must not be called from within atomic context.
200 * Returns success (0) or negative errno.
202 int clk_rate_exclusive_get(struct clk *clk);
205 * devm_clk_rate_exclusive_get - devm variant of clk_rate_exclusive_get
206 * @dev: device the exclusivity is bound to
209 * Calls clk_rate_exclusive_get() on @clk and registers a devm cleanup handler
210 * on @dev to call clk_rate_exclusive_put().
212 * Must not be called from within atomic context.
214 int devm_clk_rate_exclusive_get(struct device *dev, struct clk *clk);
217 * clk_rate_exclusive_put - release exclusivity over the rate control of a
221 * This function allows drivers to release the exclusivity it previously got
222 * from clk_rate_exclusive_get()
224 * The caller must balance the number of clk_rate_exclusive_get() and
225 * clk_rate_exclusive_put() calls.
227 * Must not be called from within atomic context.
229 void clk_rate_exclusive_put(struct clk *clk);
233 static inline int clk_notifier_register(struct clk *clk,
234 struct notifier_block *nb)
239 static inline int clk_notifier_unregister(struct clk *clk,
240 struct notifier_block *nb)
245 static inline int devm_clk_notifier_register(struct device *dev,
247 struct notifier_block *nb)
252 static inline long clk_get_accuracy(struct clk *clk)
257 static inline long clk_set_phase(struct clk *clk, int phase)
262 static inline long clk_get_phase(struct clk *clk)
267 static inline int clk_set_duty_cycle(struct clk *clk, unsigned int num,
273 static inline unsigned int clk_get_scaled_duty_cycle(struct clk *clk,
279 static inline bool clk_is_match(const struct clk *p, const struct clk *q)
284 static inline int clk_rate_exclusive_get(struct clk *clk)
289 static inline int devm_clk_rate_exclusive_get(struct device *dev, struct clk *clk)
294 static inline void clk_rate_exclusive_put(struct clk *clk) {}
298 #ifdef CONFIG_HAVE_CLK_PREPARE
300 * clk_prepare - prepare a clock source
303 * This prepares the clock source for use.
305 * Must not be called from within atomic context.
307 int clk_prepare(struct clk *clk);
308 int __must_check clk_bulk_prepare(int num_clks,
309 const struct clk_bulk_data *clks);
312 * clk_is_enabled_when_prepared - indicate if preparing a clock also enables it.
315 * Returns true if clk_prepare() implicitly enables the clock, effectively
316 * making clk_enable()/clk_disable() no-ops, false otherwise.
318 * This is of interest mainly to the power management code where actually
319 * disabling the clock also requires unpreparing it to have any material
322 * Regardless of the value returned here, the caller must always invoke
323 * clk_enable() or clk_prepare_enable() and counterparts for usage counts
326 bool clk_is_enabled_when_prepared(struct clk *clk);
328 static inline int clk_prepare(struct clk *clk)
334 static inline int __must_check
335 clk_bulk_prepare(int num_clks, const struct clk_bulk_data *clks)
341 static inline bool clk_is_enabled_when_prepared(struct clk *clk)
348 * clk_unprepare - undo preparation of a clock source
351 * This undoes a previously prepared clock. The caller must balance
352 * the number of prepare and unprepare calls.
354 * Must not be called from within atomic context.
356 #ifdef CONFIG_HAVE_CLK_PREPARE
357 void clk_unprepare(struct clk *clk);
358 void clk_bulk_unprepare(int num_clks, const struct clk_bulk_data *clks);
360 static inline void clk_unprepare(struct clk *clk)
364 static inline void clk_bulk_unprepare(int num_clks,
365 const struct clk_bulk_data *clks)
371 #ifdef CONFIG_HAVE_CLK
373 * clk_get - lookup and obtain a reference to a clock producer.
374 * @dev: device for clock "consumer"
375 * @id: clock consumer ID
377 * Returns a struct clk corresponding to the clock producer, or
378 * valid IS_ERR() condition containing errno. The implementation
379 * uses @dev and @id to determine the clock consumer, and thereby
380 * the clock producer. (IOW, @id may be identical strings, but
381 * clk_get may return different clock producers depending on @dev.)
383 * Drivers must assume that the clock source is not enabled.
385 * clk_get should not be called from within interrupt context.
387 struct clk *clk_get(struct device *dev, const char *id);
390 * clk_bulk_get - lookup and obtain a number of references to clock producer.
391 * @dev: device for clock "consumer"
392 * @num_clks: the number of clk_bulk_data
393 * @clks: the clk_bulk_data table of consumer
395 * This helper function allows drivers to get several clk consumers in one
396 * operation. If any of the clk cannot be acquired then any clks
397 * that were obtained will be freed before returning to the caller.
399 * Returns 0 if all clocks specified in clk_bulk_data table are obtained
400 * successfully, or valid IS_ERR() condition containing errno.
401 * The implementation uses @dev and @clk_bulk_data.id to determine the
402 * clock consumer, and thereby the clock producer.
403 * The clock returned is stored in each @clk_bulk_data.clk field.
405 * Drivers must assume that the clock source is not enabled.
407 * clk_bulk_get should not be called from within interrupt context.
409 int __must_check clk_bulk_get(struct device *dev, int num_clks,
410 struct clk_bulk_data *clks);
412 * clk_bulk_get_all - lookup and obtain all available references to clock
414 * @dev: device for clock "consumer"
415 * @clks: pointer to the clk_bulk_data table of consumer
417 * This helper function allows drivers to get all clk consumers in one
418 * operation. If any of the clk cannot be acquired then any clks
419 * that were obtained will be freed before returning to the caller.
421 * Returns a positive value for the number of clocks obtained while the
422 * clock references are stored in the clk_bulk_data table in @clks field.
423 * Returns 0 if there're none and a negative value if something failed.
425 * Drivers must assume that the clock source is not enabled.
427 * clk_bulk_get should not be called from within interrupt context.
429 int __must_check clk_bulk_get_all(struct device *dev,
430 struct clk_bulk_data **clks);
433 * clk_bulk_get_optional - lookup and obtain a number of references to clock producer
434 * @dev: device for clock "consumer"
435 * @num_clks: the number of clk_bulk_data
436 * @clks: the clk_bulk_data table of consumer
438 * Behaves the same as clk_bulk_get() except where there is no clock producer.
439 * In this case, instead of returning -ENOENT, the function returns 0 and
440 * NULL for a clk for which a clock producer could not be determined.
442 int __must_check clk_bulk_get_optional(struct device *dev, int num_clks,
443 struct clk_bulk_data *clks);
445 * devm_clk_bulk_get - managed get multiple clk consumers
446 * @dev: device for clock "consumer"
447 * @num_clks: the number of clk_bulk_data
448 * @clks: the clk_bulk_data table of consumer
450 * Return 0 on success, an errno on failure.
452 * This helper function allows drivers to get several clk
453 * consumers in one operation with management, the clks will
454 * automatically be freed when the device is unbound.
456 int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
457 struct clk_bulk_data *clks);
459 * devm_clk_bulk_get_optional - managed get multiple optional consumer clocks
460 * @dev: device for clock "consumer"
461 * @num_clks: the number of clk_bulk_data
462 * @clks: pointer to the clk_bulk_data table of consumer
464 * Behaves the same as devm_clk_bulk_get() except where there is no clock
465 * producer. In this case, instead of returning -ENOENT, the function returns
466 * NULL for given clk. It is assumed all clocks in clk_bulk_data are optional.
468 * Returns 0 if all clocks specified in clk_bulk_data table are obtained
469 * successfully or for any clk there was no clk provider available, otherwise
470 * returns valid IS_ERR() condition containing errno.
471 * The implementation uses @dev and @clk_bulk_data.id to determine the
472 * clock consumer, and thereby the clock producer.
473 * The clock returned is stored in each @clk_bulk_data.clk field.
475 * Drivers must assume that the clock source is not enabled.
477 * clk_bulk_get should not be called from within interrupt context.
479 int __must_check devm_clk_bulk_get_optional(struct device *dev, int num_clks,
480 struct clk_bulk_data *clks);
482 * devm_clk_bulk_get_all - managed get multiple clk consumers
483 * @dev: device for clock "consumer"
484 * @clks: pointer to the clk_bulk_data table of consumer
486 * Returns a positive value for the number of clocks obtained while the
487 * clock references are stored in the clk_bulk_data table in @clks field.
488 * Returns 0 if there're none and a negative value if something failed.
490 * This helper function allows drivers to get several clk
491 * consumers in one operation with management, the clks will
492 * automatically be freed when the device is unbound.
495 int __must_check devm_clk_bulk_get_all(struct device *dev,
496 struct clk_bulk_data **clks);
499 * devm_clk_bulk_get_all_enable - Get and enable all clocks of the consumer (managed)
500 * @dev: device for clock "consumer"
501 * @clks: pointer to the clk_bulk_data table of consumer
503 * Returns success (0) or negative errno.
505 * This helper function allows drivers to get all clocks of the
506 * consumer and enables them in one operation with management.
507 * The clks will automatically be disabled and freed when the device
511 int __must_check devm_clk_bulk_get_all_enable(struct device *dev,
512 struct clk_bulk_data **clks);
515 * devm_clk_get - lookup and obtain a managed reference to a clock producer.
516 * @dev: device for clock "consumer"
517 * @id: clock consumer ID
519 * Context: May sleep.
521 * Return: a struct clk corresponding to the clock producer, or
522 * valid IS_ERR() condition containing errno. The implementation
523 * uses @dev and @id to determine the clock consumer, and thereby
524 * the clock producer. (IOW, @id may be identical strings, but
525 * clk_get may return different clock producers depending on @dev.)
527 * Drivers must assume that the clock source is neither prepared nor
530 * The clock will automatically be freed when the device is unbound
533 struct clk *devm_clk_get(struct device *dev, const char *id);
536 * devm_clk_get_prepared - devm_clk_get() + clk_prepare()
537 * @dev: device for clock "consumer"
538 * @id: clock consumer ID
540 * Context: May sleep.
542 * Return: a struct clk corresponding to the clock producer, or
543 * valid IS_ERR() condition containing errno. The implementation
544 * uses @dev and @id to determine the clock consumer, and thereby
545 * the clock producer. (IOW, @id may be identical strings, but
546 * clk_get may return different clock producers depending on @dev.)
548 * The returned clk (if valid) is prepared. Drivers must however assume
549 * that the clock is not enabled.
551 * The clock will automatically be unprepared and freed when the device
552 * is unbound from the bus.
554 struct clk *devm_clk_get_prepared(struct device *dev, const char *id);
557 * devm_clk_get_enabled - devm_clk_get() + clk_prepare_enable()
558 * @dev: device for clock "consumer"
559 * @id: clock consumer ID
561 * Context: May sleep.
563 * Return: a struct clk corresponding to the clock producer, or
564 * valid IS_ERR() condition containing errno. The implementation
565 * uses @dev and @id to determine the clock consumer, and thereby
566 * the clock producer. (IOW, @id may be identical strings, but
567 * clk_get may return different clock producers depending on @dev.)
569 * The returned clk (if valid) is prepared and enabled.
571 * The clock will automatically be disabled, unprepared and freed
572 * when the device is unbound from the bus.
574 struct clk *devm_clk_get_enabled(struct device *dev, const char *id);
577 * devm_clk_get_optional - lookup and obtain a managed reference to an optional
579 * @dev: device for clock "consumer"
580 * @id: clock consumer ID
582 * Context: May sleep.
584 * Return: a struct clk corresponding to the clock producer, or
585 * valid IS_ERR() condition containing errno. The implementation
586 * uses @dev and @id to determine the clock consumer, and thereby
587 * the clock producer. If no such clk is found, it returns NULL
588 * which serves as a dummy clk. That's the only difference compared
591 * Drivers must assume that the clock source is neither prepared nor
594 * The clock will automatically be freed when the device is unbound
597 struct clk *devm_clk_get_optional(struct device *dev, const char *id);
600 * devm_clk_get_optional_prepared - devm_clk_get_optional() + clk_prepare()
601 * @dev: device for clock "consumer"
602 * @id: clock consumer ID
604 * Context: May sleep.
606 * Return: a struct clk corresponding to the clock producer, or
607 * valid IS_ERR() condition containing errno. The implementation
608 * uses @dev and @id to determine the clock consumer, and thereby
609 * the clock producer. If no such clk is found, it returns NULL
610 * which serves as a dummy clk. That's the only difference compared
611 * to devm_clk_get_prepared().
613 * The returned clk (if valid) is prepared. Drivers must however
614 * assume that the clock is not enabled.
616 * The clock will automatically be unprepared and freed when the
617 * device is unbound from the bus.
619 struct clk *devm_clk_get_optional_prepared(struct device *dev, const char *id);
622 * devm_clk_get_optional_enabled - devm_clk_get_optional() +
623 * clk_prepare_enable()
624 * @dev: device for clock "consumer"
625 * @id: clock consumer ID
627 * Context: May sleep.
629 * Return: a struct clk corresponding to the clock producer, or
630 * valid IS_ERR() condition containing errno. The implementation
631 * uses @dev and @id to determine the clock consumer, and thereby
632 * the clock producer. If no such clk is found, it returns NULL
633 * which serves as a dummy clk. That's the only difference compared
634 * to devm_clk_get_enabled().
636 * The returned clk (if valid) is prepared and enabled.
638 * The clock will automatically be disabled, unprepared and freed
639 * when the device is unbound from the bus.
641 struct clk *devm_clk_get_optional_enabled(struct device *dev, const char *id);
644 * devm_get_clk_from_child - lookup and obtain a managed reference to a
645 * clock producer from child node.
646 * @dev: device for clock "consumer"
647 * @np: pointer to clock consumer node
648 * @con_id: clock consumer ID
650 * This function parses the clocks, and uses them to look up the
651 * struct clk from the registered list of clock providers by using
654 * The clock will automatically be freed when the device is unbound
657 struct clk *devm_get_clk_from_child(struct device *dev,
658 struct device_node *np, const char *con_id);
661 * clk_enable - inform the system when the clock source should be running.
664 * If the clock can not be enabled/disabled, this should return success.
666 * May be called from atomic contexts.
668 * Returns success (0) or negative errno.
670 int clk_enable(struct clk *clk);
673 * clk_bulk_enable - inform the system when the set of clks should be running.
674 * @num_clks: the number of clk_bulk_data
675 * @clks: the clk_bulk_data table of consumer
677 * May be called from atomic contexts.
679 * Returns success (0) or negative errno.
681 int __must_check clk_bulk_enable(int num_clks,
682 const struct clk_bulk_data *clks);
685 * clk_disable - inform the system when the clock source is no longer required.
688 * Inform the system that a clock source is no longer required by
689 * a driver and may be shut down.
691 * May be called from atomic contexts.
693 * Implementation detail: if the clock source is shared between
694 * multiple drivers, clk_enable() calls must be balanced by the
695 * same number of clk_disable() calls for the clock source to be
698 void clk_disable(struct clk *clk);
701 * clk_bulk_disable - inform the system when the set of clks is no
703 * @num_clks: the number of clk_bulk_data
704 * @clks: the clk_bulk_data table of consumer
706 * Inform the system that a set of clks is no longer required by
707 * a driver and may be shut down.
709 * May be called from atomic contexts.
711 * Implementation detail: if the set of clks is shared between
712 * multiple drivers, clk_bulk_enable() calls must be balanced by the
713 * same number of clk_bulk_disable() calls for the clock source to be
716 void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks);
719 * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
720 * This is only valid once the clock source has been enabled.
723 unsigned long clk_get_rate(struct clk *clk);
726 * clk_put - "free" the clock source
729 * Note: drivers must ensure that all clk_enable calls made on this
730 * clock source are balanced by clk_disable calls prior to calling
733 * clk_put should not be called from within interrupt context.
735 void clk_put(struct clk *clk);
738 * clk_bulk_put - "free" the clock source
739 * @num_clks: the number of clk_bulk_data
740 * @clks: the clk_bulk_data table of consumer
742 * Note: drivers must ensure that all clk_bulk_enable calls made on this
743 * clock source are balanced by clk_bulk_disable calls prior to calling
746 * clk_bulk_put should not be called from within interrupt context.
748 void clk_bulk_put(int num_clks, struct clk_bulk_data *clks);
751 * clk_bulk_put_all - "free" all the clock source
752 * @num_clks: the number of clk_bulk_data
753 * @clks: the clk_bulk_data table of consumer
755 * Note: drivers must ensure that all clk_bulk_enable calls made on this
756 * clock source are balanced by clk_bulk_disable calls prior to calling
759 * clk_bulk_put_all should not be called from within interrupt context.
761 void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks);
764 * devm_clk_put - "free" a managed clock source
765 * @dev: device used to acquire the clock
766 * @clk: clock source acquired with devm_clk_get()
768 * Note: drivers must ensure that all clk_enable calls made on this
769 * clock source are balanced by clk_disable calls prior to calling
772 * clk_put should not be called from within interrupt context.
774 void devm_clk_put(struct device *dev, struct clk *clk);
777 * The remaining APIs are optional for machine class support.
782 * clk_round_rate - adjust a rate to the exact rate a clock can provide
784 * @rate: desired clock rate in Hz
786 * This answers the question "if I were to pass @rate to clk_set_rate(),
787 * what clock rate would I end up with?" without changing the hardware
788 * in any way. In other words:
790 * rate = clk_round_rate(clk, r);
794 * clk_set_rate(clk, r);
795 * rate = clk_get_rate(clk);
797 * are equivalent except the former does not modify the clock hardware
800 * Returns rounded clock rate in Hz, or negative errno.
802 long clk_round_rate(struct clk *clk, unsigned long rate);
805 * clk_set_rate - set the clock rate for a clock source
807 * @rate: desired clock rate in Hz
809 * Updating the rate starts at the top-most affected clock and then
810 * walks the tree down to the bottom-most clock that needs updating.
812 * Returns success (0) or negative errno.
814 int clk_set_rate(struct clk *clk, unsigned long rate);
817 * clk_set_rate_exclusive- set the clock rate and claim exclusivity over
820 * @rate: desired clock rate in Hz
822 * This helper function allows drivers to atomically set the rate of a producer
823 * and claim exclusivity over the rate control of the producer.
825 * It is essentially a combination of clk_set_rate() and
826 * clk_rate_exclusite_get(). Caller must balance this call with a call to
827 * clk_rate_exclusive_put()
829 * Returns success (0) or negative errno.
831 int clk_set_rate_exclusive(struct clk *clk, unsigned long rate);
834 * clk_has_parent - check if a clock is a possible parent for another
836 * @parent: parent clock source
838 * This function can be used in drivers that need to check that a clock can be
839 * the parent of another without actually changing the parent.
841 * Returns true if @parent is a possible parent for @clk, false otherwise.
843 bool clk_has_parent(const struct clk *clk, const struct clk *parent);
846 * clk_set_rate_range - set a rate range for a clock source
848 * @min: desired minimum clock rate in Hz, inclusive
849 * @max: desired maximum clock rate in Hz, inclusive
851 * Returns success (0) or negative errno.
853 int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max);
856 * clk_set_min_rate - set a minimum clock rate for a clock source
858 * @rate: desired minimum clock rate in Hz, inclusive
860 * Returns success (0) or negative errno.
862 int clk_set_min_rate(struct clk *clk, unsigned long rate);
865 * clk_set_max_rate - set a maximum clock rate for a clock source
867 * @rate: desired maximum clock rate in Hz, inclusive
869 * Returns success (0) or negative errno.
871 int clk_set_max_rate(struct clk *clk, unsigned long rate);
874 * clk_set_parent - set the parent clock source for this clock
876 * @parent: parent clock source
878 * Returns success (0) or negative errno.
880 int clk_set_parent(struct clk *clk, struct clk *parent);
883 * clk_get_parent - get the parent clock source for this clock
886 * Returns struct clk corresponding to parent clock source, or
887 * valid IS_ERR() condition containing errno.
889 struct clk *clk_get_parent(struct clk *clk);
892 * clk_get_sys - get a clock based upon the device name
893 * @dev_id: device name
894 * @con_id: connection ID
896 * Returns a struct clk corresponding to the clock producer, or
897 * valid IS_ERR() condition containing errno. The implementation
898 * uses @dev_id and @con_id to determine the clock consumer, and
899 * thereby the clock producer. In contrast to clk_get() this function
900 * takes the device name instead of the device itself for identification.
902 * Drivers must assume that the clock source is not enabled.
904 * clk_get_sys should not be called from within interrupt context.
906 struct clk *clk_get_sys(const char *dev_id, const char *con_id);
909 * clk_save_context - save clock context for poweroff
911 * Saves the context of the clock register for powerstates in which the
912 * contents of the registers will be lost. Occurs deep within the suspend
913 * code so locking is not necessary.
915 int clk_save_context(void);
918 * clk_restore_context - restore clock context after poweroff
920 * This occurs with all clocks enabled. Occurs deep within the resume code
921 * so locking is not necessary.
923 void clk_restore_context(void);
925 #else /* !CONFIG_HAVE_CLK */
927 static inline struct clk *clk_get(struct device *dev, const char *id)
932 static inline int __must_check clk_bulk_get(struct device *dev, int num_clks,
933 struct clk_bulk_data *clks)
938 static inline int __must_check clk_bulk_get_optional(struct device *dev,
939 int num_clks, struct clk_bulk_data *clks)
944 static inline int __must_check clk_bulk_get_all(struct device *dev,
945 struct clk_bulk_data **clks)
950 static inline struct clk *devm_clk_get(struct device *dev, const char *id)
955 static inline struct clk *devm_clk_get_prepared(struct device *dev,
961 static inline struct clk *devm_clk_get_enabled(struct device *dev,
967 static inline struct clk *devm_clk_get_optional(struct device *dev,
973 static inline struct clk *devm_clk_get_optional_prepared(struct device *dev,
979 static inline struct clk *devm_clk_get_optional_enabled(struct device *dev,
985 static inline int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
986 struct clk_bulk_data *clks)
991 static inline int __must_check devm_clk_bulk_get_optional(struct device *dev,
992 int num_clks, struct clk_bulk_data *clks)
997 static inline int __must_check devm_clk_bulk_get_all(struct device *dev,
998 struct clk_bulk_data **clks)
1004 static inline int __must_check devm_clk_bulk_get_all_enable(struct device *dev,
1005 struct clk_bulk_data **clks)
1010 static inline struct clk *devm_get_clk_from_child(struct device *dev,
1011 struct device_node *np, const char *con_id)
1016 static inline void clk_put(struct clk *clk) {}
1018 static inline void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) {}
1020 static inline void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks) {}
1022 static inline void devm_clk_put(struct device *dev, struct clk *clk) {}
1024 static inline int clk_enable(struct clk *clk)
1029 static inline int __must_check clk_bulk_enable(int num_clks,
1030 const struct clk_bulk_data *clks)
1035 static inline void clk_disable(struct clk *clk) {}
1038 static inline void clk_bulk_disable(int num_clks,
1039 const struct clk_bulk_data *clks) {}
1041 static inline unsigned long clk_get_rate(struct clk *clk)
1046 static inline int clk_set_rate(struct clk *clk, unsigned long rate)
1051 static inline int clk_set_rate_exclusive(struct clk *clk, unsigned long rate)
1056 static inline long clk_round_rate(struct clk *clk, unsigned long rate)
1061 static inline bool clk_has_parent(struct clk *clk, struct clk *parent)
1066 static inline int clk_set_rate_range(struct clk *clk, unsigned long min,
1072 static inline int clk_set_min_rate(struct clk *clk, unsigned long rate)
1077 static inline int clk_set_max_rate(struct clk *clk, unsigned long rate)
1082 static inline int clk_set_parent(struct clk *clk, struct clk *parent)
1087 static inline struct clk *clk_get_parent(struct clk *clk)
1092 static inline struct clk *clk_get_sys(const char *dev_id, const char *con_id)
1097 static inline int clk_save_context(void)
1102 static inline void clk_restore_context(void) {}
1106 /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
1107 static inline int clk_prepare_enable(struct clk *clk)
1111 ret = clk_prepare(clk);
1114 ret = clk_enable(clk);
1121 /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */
1122 static inline void clk_disable_unprepare(struct clk *clk)
1128 static inline int __must_check
1129 clk_bulk_prepare_enable(int num_clks, const struct clk_bulk_data *clks)
1133 ret = clk_bulk_prepare(num_clks, clks);
1136 ret = clk_bulk_enable(num_clks, clks);
1138 clk_bulk_unprepare(num_clks, clks);
1143 static inline void clk_bulk_disable_unprepare(int num_clks,
1144 const struct clk_bulk_data *clks)
1146 clk_bulk_disable(num_clks, clks);
1147 clk_bulk_unprepare(num_clks, clks);
1151 * clk_drop_range - Reset any range set on that clock
1152 * @clk: clock source
1154 * Returns success (0) or negative errno.
1156 static inline int clk_drop_range(struct clk *clk)
1158 return clk_set_rate_range(clk, 0, ULONG_MAX);
1162 * clk_get_optional - lookup and obtain a reference to an optional clock
1164 * @dev: device for clock "consumer"
1165 * @id: clock consumer ID
1167 * Behaves the same as clk_get() except where there is no clock producer. In
1168 * this case, instead of returning -ENOENT, the function returns NULL.
1170 static inline struct clk *clk_get_optional(struct device *dev, const char *id)
1172 struct clk *clk = clk_get(dev, id);
1174 if (clk == ERR_PTR(-ENOENT))
1180 #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
1181 struct clk *of_clk_get(struct device_node *np, int index);
1182 struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
1183 struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
1185 static inline struct clk *of_clk_get(struct device_node *np, int index)
1187 return ERR_PTR(-ENOENT);
1189 static inline struct clk *of_clk_get_by_name(struct device_node *np,
1192 return ERR_PTR(-ENOENT);
1194 static inline struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
1196 return ERR_PTR(-ENOENT);