xref: /linux-6.15/include/linux/clk.h (revision ef94ea4f)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2f8ce2547SRussell King /*
3f8ce2547SRussell King  *  linux/include/linux/clk.h
4f8ce2547SRussell King  *
5f8ce2547SRussell King  *  Copyright (C) 2004 ARM Limited.
6f8ce2547SRussell King  *  Written by Deep Blue Solutions Limited.
7b2476490SMike Turquette  *  Copyright (C) 2011-2012 Linaro Ltd <[email protected]>
8f8ce2547SRussell King  */
9686f8c5dSTodd Poynor #ifndef __LINUX_CLK_H
10686f8c5dSTodd Poynor #define __LINUX_CLK_H
11f8ce2547SRussell King 
129f1612d3SShawn Guo #include <linux/err.h>
1340d3e0f4SRussell King #include <linux/kernel.h>
14b2476490SMike Turquette #include <linux/notifier.h>
1540d3e0f4SRussell King 
16f8ce2547SRussell King struct device;
17f8ce2547SRussell King struct clk;
1871a2f115SKuninori Morimoto struct device_node;
1971a2f115SKuninori Morimoto struct of_phandle_args;
20f8ce2547SRussell King 
21b2476490SMike Turquette /**
22b2476490SMike Turquette  * DOC: clk notifier callback types
23b2476490SMike Turquette  *
24b2476490SMike Turquette  * PRE_RATE_CHANGE - called immediately before the clk rate is changed,
25b2476490SMike Turquette  *     to indicate that the rate change will proceed.  Drivers must
26b2476490SMike Turquette  *     immediately terminate any operations that will be affected by the
27fb72a059SSoren Brinkmann  *     rate change.  Callbacks may either return NOTIFY_DONE, NOTIFY_OK,
28fb72a059SSoren Brinkmann  *     NOTIFY_STOP or NOTIFY_BAD.
29b2476490SMike Turquette  *
30b2476490SMike Turquette  * ABORT_RATE_CHANGE: called if the rate change failed for some reason
31b2476490SMike Turquette  *     after PRE_RATE_CHANGE.  In this case, all registered notifiers on
32b2476490SMike Turquette  *     the clk will be called with ABORT_RATE_CHANGE. Callbacks must
33fb72a059SSoren Brinkmann  *     always return NOTIFY_DONE or NOTIFY_OK.
34b2476490SMike Turquette  *
35b2476490SMike Turquette  * POST_RATE_CHANGE - called after the clk rate change has successfully
36fb72a059SSoren Brinkmann  *     completed.  Callbacks must always return NOTIFY_DONE or NOTIFY_OK.
37b2476490SMike Turquette  *
38b2476490SMike Turquette  */
39b2476490SMike Turquette #define PRE_RATE_CHANGE			BIT(0)
40b2476490SMike Turquette #define POST_RATE_CHANGE		BIT(1)
41b2476490SMike Turquette #define ABORT_RATE_CHANGE		BIT(2)
42b2476490SMike Turquette 
43b2476490SMike Turquette /**
44b2476490SMike Turquette  * struct clk_notifier - associate a clk with a notifier
45b2476490SMike Turquette  * @clk: struct clk * to associate the notifier with
46b2476490SMike Turquette  * @notifier_head: a blocking_notifier_head for this clk
47b2476490SMike Turquette  * @node: linked list pointers
48b2476490SMike Turquette  *
49b2476490SMike Turquette  * A list of struct clk_notifier is maintained by the notifier code.
50b2476490SMike Turquette  * An entry is created whenever code registers the first notifier on a
51b2476490SMike Turquette  * particular @clk.  Future notifiers on that @clk are added to the
52b2476490SMike Turquette  * @notifier_head.
53b2476490SMike Turquette  */
54b2476490SMike Turquette struct clk_notifier {
55b2476490SMike Turquette 	struct clk			*clk;
56b2476490SMike Turquette 	struct srcu_notifier_head	notifier_head;
57b2476490SMike Turquette 	struct list_head		node;
58b2476490SMike Turquette };
59b2476490SMike Turquette 
60b2476490SMike Turquette /**
61b2476490SMike Turquette  * struct clk_notifier_data - rate data to pass to the notifier callback
62b2476490SMike Turquette  * @clk: struct clk * being changed
63b2476490SMike Turquette  * @old_rate: previous rate of this clk
64b2476490SMike Turquette  * @new_rate: new rate of this clk
65b2476490SMike Turquette  *
66b2476490SMike Turquette  * For a pre-notifier, old_rate is the clk's rate before this rate
67b2476490SMike Turquette  * change, and new_rate is what the rate will be in the future.  For a
68b2476490SMike Turquette  * post-notifier, old_rate and new_rate are both set to the clk's
69b2476490SMike Turquette  * current rate (this was done to optimize the implementation).
70b2476490SMike Turquette  */
71b2476490SMike Turquette struct clk_notifier_data {
72b2476490SMike Turquette 	struct clk		*clk;
73b2476490SMike Turquette 	unsigned long		old_rate;
74b2476490SMike Turquette 	unsigned long		new_rate;
75b2476490SMike Turquette };
76b2476490SMike Turquette 
77266e4e9dSDong Aisheng /**
78266e4e9dSDong Aisheng  * struct clk_bulk_data - Data used for bulk clk operations.
79266e4e9dSDong Aisheng  *
80266e4e9dSDong Aisheng  * @id: clock consumer ID
81266e4e9dSDong Aisheng  * @clk: struct clk * to store the associated clock
82266e4e9dSDong Aisheng  *
83266e4e9dSDong Aisheng  * The CLK APIs provide a series of clk_bulk_() API calls as
84266e4e9dSDong Aisheng  * a convenience to consumers which require multiple clks.  This
85266e4e9dSDong Aisheng  * structure is used to manage data for these calls.
86266e4e9dSDong Aisheng  */
87266e4e9dSDong Aisheng struct clk_bulk_data {
88266e4e9dSDong Aisheng 	const char		*id;
89266e4e9dSDong Aisheng 	struct clk		*clk;
90266e4e9dSDong Aisheng };
91266e4e9dSDong Aisheng 
92e81b87d2SKrzysztof Kozlowski #ifdef CONFIG_COMMON_CLK
93e81b87d2SKrzysztof Kozlowski 
9486bcfa2eSMike Turquette /**
95b90f3726SRandy Dunlap  * clk_notifier_register - register a clock rate-change notifier callback
9686bcfa2eSMike Turquette  * @clk: clock whose rate we are interested in
9786bcfa2eSMike Turquette  * @nb: notifier block with callback function pointer
9886bcfa2eSMike Turquette  *
9986bcfa2eSMike Turquette  * ProTip: debugging across notifier chains can be frustrating. Make sure that
10086bcfa2eSMike Turquette  * your notifier callback function prints a nice big warning in case of
10186bcfa2eSMike Turquette  * failure.
10286bcfa2eSMike Turquette  */
103b2476490SMike Turquette int clk_notifier_register(struct clk *clk, struct notifier_block *nb);
104b2476490SMike Turquette 
10586bcfa2eSMike Turquette /**
106b90f3726SRandy Dunlap  * clk_notifier_unregister - unregister a clock rate-change notifier callback
10786bcfa2eSMike Turquette  * @clk: clock whose rate we are no longer interested in
10886bcfa2eSMike Turquette  * @nb: notifier block which will be unregistered
10986bcfa2eSMike Turquette  */
110b2476490SMike Turquette int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb);
111b2476490SMike Turquette 
1125279fc40SBoris BREZILLON /**
1136d30d50dSJerome Brunet  * devm_clk_notifier_register - register a managed rate-change notifier callback
1146d30d50dSJerome Brunet  * @dev: device for clock "consumer"
1156d30d50dSJerome Brunet  * @clk: clock whose rate we are interested in
1166d30d50dSJerome Brunet  * @nb: notifier block with callback function pointer
1176d30d50dSJerome Brunet  *
1186d30d50dSJerome Brunet  * Returns 0 on success, -EERROR otherwise
1196d30d50dSJerome Brunet  */
120e6fb7aeeSJerome Brunet int devm_clk_notifier_register(struct device *dev, struct clk *clk,
121e6fb7aeeSJerome Brunet 			       struct notifier_block *nb);
1226d30d50dSJerome Brunet 
1236d30d50dSJerome Brunet /**
1245279fc40SBoris BREZILLON  * clk_get_accuracy - obtain the clock accuracy in ppb (parts per billion)
1255279fc40SBoris BREZILLON  *		      for a clock source.
1265279fc40SBoris BREZILLON  * @clk: clock source
1275279fc40SBoris BREZILLON  *
1285279fc40SBoris BREZILLON  * This gets the clock source accuracy expressed in ppb.
1295279fc40SBoris BREZILLON  * A perfect clock returns 0.
1305279fc40SBoris BREZILLON  */
1315279fc40SBoris BREZILLON long clk_get_accuracy(struct clk *clk);
1325279fc40SBoris BREZILLON 
133e59c5371SMike Turquette /**
134e59c5371SMike Turquette  * clk_set_phase - adjust the phase shift of a clock signal
135e59c5371SMike Turquette  * @clk: clock signal source
136e59c5371SMike Turquette  * @degrees: number of degrees the signal is shifted
137e59c5371SMike Turquette  *
138e59c5371SMike Turquette  * Shifts the phase of a clock signal by the specified degrees. Returns 0 on
139e59c5371SMike Turquette  * success, -EERROR otherwise.
140e59c5371SMike Turquette  */
141e59c5371SMike Turquette int clk_set_phase(struct clk *clk, int degrees);
142e59c5371SMike Turquette 
143e59c5371SMike Turquette /**
144e59c5371SMike Turquette  * clk_get_phase - return the phase shift of a clock signal
145e59c5371SMike Turquette  * @clk: clock signal source
146e59c5371SMike Turquette  *
147e59c5371SMike Turquette  * Returns the phase shift of a clock node in degrees, otherwise returns
148e59c5371SMike Turquette  * -EERROR.
149e59c5371SMike Turquette  */
150e59c5371SMike Turquette int clk_get_phase(struct clk *clk);
151e59c5371SMike Turquette 
1523d3801efSMichael Turquette /**
1539fba738aSJerome Brunet  * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal
1549fba738aSJerome Brunet  * @clk: clock signal source
1559fba738aSJerome Brunet  * @num: numerator of the duty cycle ratio to be applied
1569fba738aSJerome Brunet  * @den: denominator of the duty cycle ratio to be applied
1579fba738aSJerome Brunet  *
1589fba738aSJerome Brunet  * Adjust the duty cycle of a clock signal by the specified ratio. Returns 0 on
1599fba738aSJerome Brunet  * success, -EERROR otherwise.
1609fba738aSJerome Brunet  */
1619fba738aSJerome Brunet int clk_set_duty_cycle(struct clk *clk, unsigned int num, unsigned int den);
1629fba738aSJerome Brunet 
1639fba738aSJerome Brunet /**
1649d1c94a6SMauro Carvalho Chehab  * clk_get_scaled_duty_cycle - return the duty cycle ratio of a clock signal
1659fba738aSJerome Brunet  * @clk: clock signal source
1669fba738aSJerome Brunet  * @scale: scaling factor to be applied to represent the ratio as an integer
1679fba738aSJerome Brunet  *
1689fba738aSJerome Brunet  * Returns the duty cycle ratio multiplied by the scale provided, otherwise
1699fba738aSJerome Brunet  * returns -EERROR.
1709fba738aSJerome Brunet  */
1719fba738aSJerome Brunet int clk_get_scaled_duty_cycle(struct clk *clk, unsigned int scale);
1729fba738aSJerome Brunet 
1739fba738aSJerome Brunet /**
1743d3801efSMichael Turquette  * clk_is_match - check if two clk's point to the same hardware clock
1753d3801efSMichael Turquette  * @p: clk compared against q
1763d3801efSMichael Turquette  * @q: clk compared against p
1773d3801efSMichael Turquette  *
1783d3801efSMichael Turquette  * Returns true if the two struct clk pointers both point to the same hardware
1790e056eb5S[email protected]  * clock node. Put differently, returns true if @p and @q
1800e056eb5S[email protected]  * share the same &struct clk_core object.
1813d3801efSMichael Turquette  *
1823d3801efSMichael Turquette  * Returns false otherwise. Note that two NULL clks are treated as matching.
1833d3801efSMichael Turquette  */
1843d3801efSMichael Turquette bool clk_is_match(const struct clk *p, const struct clk *q);
1853d3801efSMichael Turquette 
1862746f13fSBiju Das /**
1872746f13fSBiju Das  * clk_rate_exclusive_get - get exclusivity over the rate control of a
1882746f13fSBiju Das  *                          producer
1892746f13fSBiju Das  * @clk: clock source
1902746f13fSBiju Das  *
1912746f13fSBiju Das  * This function allows drivers to get exclusive control over the rate of a
1922746f13fSBiju Das  * provider. It prevents any other consumer to execute, even indirectly,
1932746f13fSBiju Das  * opereation which could alter the rate of the provider or cause glitches
1942746f13fSBiju Das  *
1952746f13fSBiju Das  * If exlusivity is claimed more than once on clock, even by the same driver,
1962746f13fSBiju Das  * the rate effectively gets locked as exclusivity can't be preempted.
1972746f13fSBiju Das  *
1982746f13fSBiju Das  * Must not be called from within atomic context.
1992746f13fSBiju Das  *
2002746f13fSBiju Das  * Returns success (0) or negative errno.
2012746f13fSBiju Das  */
2022746f13fSBiju Das int clk_rate_exclusive_get(struct clk *clk);
2032746f13fSBiju Das 
2042746f13fSBiju Das /**
205b0cde62eSUwe Kleine-König  * devm_clk_rate_exclusive_get - devm variant of clk_rate_exclusive_get
206b0cde62eSUwe Kleine-König  * @dev: device the exclusivity is bound to
207b0cde62eSUwe Kleine-König  * @clk: clock source
208b0cde62eSUwe Kleine-König  *
209b0cde62eSUwe Kleine-König  * Calls clk_rate_exclusive_get() on @clk and registers a devm cleanup handler
210b0cde62eSUwe Kleine-König  * on @dev to call clk_rate_exclusive_put().
211b0cde62eSUwe Kleine-König  *
212b0cde62eSUwe Kleine-König  * Must not be called from within atomic context.
213b0cde62eSUwe Kleine-König  */
214b0cde62eSUwe Kleine-König int devm_clk_rate_exclusive_get(struct device *dev, struct clk *clk);
215b0cde62eSUwe Kleine-König 
216b0cde62eSUwe Kleine-König /**
2172746f13fSBiju Das  * clk_rate_exclusive_put - release exclusivity over the rate control of a
2182746f13fSBiju Das  *                          producer
2192746f13fSBiju Das  * @clk: clock source
2202746f13fSBiju Das  *
2212746f13fSBiju Das  * This function allows drivers to release the exclusivity it previously got
2222746f13fSBiju Das  * from clk_rate_exclusive_get()
2232746f13fSBiju Das  *
2242746f13fSBiju Das  * The caller must balance the number of clk_rate_exclusive_get() and
2252746f13fSBiju Das  * clk_rate_exclusive_put() calls.
2262746f13fSBiju Das  *
2272746f13fSBiju Das  * Must not be called from within atomic context.
2282746f13fSBiju Das  */
2292746f13fSBiju Das void clk_rate_exclusive_put(struct clk *clk);
2302746f13fSBiju Das 
2315279fc40SBoris BREZILLON #else
2325279fc40SBoris BREZILLON 
clk_notifier_register(struct clk * clk,struct notifier_block * nb)233e81b87d2SKrzysztof Kozlowski static inline int clk_notifier_register(struct clk *clk,
234e81b87d2SKrzysztof Kozlowski 					struct notifier_block *nb)
235e81b87d2SKrzysztof Kozlowski {
236e81b87d2SKrzysztof Kozlowski 	return -ENOTSUPP;
237e81b87d2SKrzysztof Kozlowski }
238e81b87d2SKrzysztof Kozlowski 
clk_notifier_unregister(struct clk * clk,struct notifier_block * nb)239e81b87d2SKrzysztof Kozlowski static inline int clk_notifier_unregister(struct clk *clk,
240e81b87d2SKrzysztof Kozlowski 					  struct notifier_block *nb)
241e81b87d2SKrzysztof Kozlowski {
242e81b87d2SKrzysztof Kozlowski 	return -ENOTSUPP;
243e81b87d2SKrzysztof Kozlowski }
244e81b87d2SKrzysztof Kozlowski 
devm_clk_notifier_register(struct device * dev,struct clk * clk,struct notifier_block * nb)245e6fb7aeeSJerome Brunet static inline int devm_clk_notifier_register(struct device *dev,
246e6fb7aeeSJerome Brunet 					     struct clk *clk,
247e6fb7aeeSJerome Brunet 					     struct notifier_block *nb)
248e6fb7aeeSJerome Brunet {
249e6fb7aeeSJerome Brunet 	return -ENOTSUPP;
250e6fb7aeeSJerome Brunet }
251e6fb7aeeSJerome Brunet 
clk_get_accuracy(struct clk * clk)2525279fc40SBoris BREZILLON static inline long clk_get_accuracy(struct clk *clk)
2535279fc40SBoris BREZILLON {
2545279fc40SBoris BREZILLON 	return -ENOTSUPP;
2555279fc40SBoris BREZILLON }
2565279fc40SBoris BREZILLON 
clk_set_phase(struct clk * clk,int phase)257e59c5371SMike Turquette static inline long clk_set_phase(struct clk *clk, int phase)
258e59c5371SMike Turquette {
259e59c5371SMike Turquette 	return -ENOTSUPP;
260e59c5371SMike Turquette }
261e59c5371SMike Turquette 
clk_get_phase(struct clk * clk)262e59c5371SMike Turquette static inline long clk_get_phase(struct clk *clk)
263e59c5371SMike Turquette {
264e59c5371SMike Turquette 	return -ENOTSUPP;
265e59c5371SMike Turquette }
266e59c5371SMike Turquette 
clk_set_duty_cycle(struct clk * clk,unsigned int num,unsigned int den)2679fba738aSJerome Brunet static inline int clk_set_duty_cycle(struct clk *clk, unsigned int num,
2689fba738aSJerome Brunet 				     unsigned int den)
2699fba738aSJerome Brunet {
2709fba738aSJerome Brunet 	return -ENOTSUPP;
2719fba738aSJerome Brunet }
2729fba738aSJerome Brunet 
clk_get_scaled_duty_cycle(struct clk * clk,unsigned int scale)2739fba738aSJerome Brunet static inline unsigned int clk_get_scaled_duty_cycle(struct clk *clk,
2749fba738aSJerome Brunet 						     unsigned int scale)
2759fba738aSJerome Brunet {
2769fba738aSJerome Brunet 	return 0;
2779fba738aSJerome Brunet }
2789fba738aSJerome Brunet 
clk_is_match(const struct clk * p,const struct clk * q)2793d3801efSMichael Turquette static inline bool clk_is_match(const struct clk *p, const struct clk *q)
2803d3801efSMichael Turquette {
2813d3801efSMichael Turquette 	return p == q;
2823d3801efSMichael Turquette }
2833d3801efSMichael Turquette 
clk_rate_exclusive_get(struct clk * clk)2842746f13fSBiju Das static inline int clk_rate_exclusive_get(struct clk *clk)
2852746f13fSBiju Das {
2862746f13fSBiju Das 	return 0;
2872746f13fSBiju Das }
2882746f13fSBiju Das 
devm_clk_rate_exclusive_get(struct device * dev,struct clk * clk)2897f1dd39aSUwe Kleine-König static inline int devm_clk_rate_exclusive_get(struct device *dev, struct clk *clk)
2907f1dd39aSUwe Kleine-König {
2917f1dd39aSUwe Kleine-König 	return 0;
2927f1dd39aSUwe Kleine-König }
2937f1dd39aSUwe Kleine-König 
clk_rate_exclusive_put(struct clk * clk)2942746f13fSBiju Das static inline void clk_rate_exclusive_put(struct clk *clk) {}
2952746f13fSBiju Das 
2967e87aed9SMark Brown #endif
297b2476490SMike Turquette 
2980bfa0820SNicolas Pitre #ifdef CONFIG_HAVE_CLK_PREPARE
299f8ce2547SRussell King /**
30093abe8e4SViresh Kumar  * clk_prepare - prepare a clock source
30193abe8e4SViresh Kumar  * @clk: clock source
30293abe8e4SViresh Kumar  *
30393abe8e4SViresh Kumar  * This prepares the clock source for use.
30493abe8e4SViresh Kumar  *
30593abe8e4SViresh Kumar  * Must not be called from within atomic context.
30693abe8e4SViresh Kumar  */
30793abe8e4SViresh Kumar int clk_prepare(struct clk *clk);
308266e4e9dSDong Aisheng int __must_check clk_bulk_prepare(int num_clks,
309266e4e9dSDong Aisheng 				  const struct clk_bulk_data *clks);
3100bfa0820SNicolas Pitre 
3110bfa0820SNicolas Pitre /**
3120bfa0820SNicolas Pitre  * clk_is_enabled_when_prepared - indicate if preparing a clock also enables it.
3130bfa0820SNicolas Pitre  * @clk: clock source
3140bfa0820SNicolas Pitre  *
3150bfa0820SNicolas Pitre  * Returns true if clk_prepare() implicitly enables the clock, effectively
3160bfa0820SNicolas Pitre  * making clk_enable()/clk_disable() no-ops, false otherwise.
3170bfa0820SNicolas Pitre  *
3180bfa0820SNicolas Pitre  * This is of interest mainly to the power management code where actually
3190bfa0820SNicolas Pitre  * disabling the clock also requires unpreparing it to have any material
3200bfa0820SNicolas Pitre  * effect.
3210bfa0820SNicolas Pitre  *
3220bfa0820SNicolas Pitre  * Regardless of the value returned here, the caller must always invoke
3230bfa0820SNicolas Pitre  * clk_enable() or clk_prepare_enable()  and counterparts for usage counts
3240bfa0820SNicolas Pitre  * to be right.
3250bfa0820SNicolas Pitre  */
3260bfa0820SNicolas Pitre bool clk_is_enabled_when_prepared(struct clk *clk);
32793abe8e4SViresh Kumar #else
clk_prepare(struct clk * clk)32893abe8e4SViresh Kumar static inline int clk_prepare(struct clk *clk)
32993abe8e4SViresh Kumar {
33093abe8e4SViresh Kumar 	might_sleep();
33193abe8e4SViresh Kumar 	return 0;
33293abe8e4SViresh Kumar }
333266e4e9dSDong Aisheng 
334570aaec7SAndrey Smirnov static inline int __must_check
clk_bulk_prepare(int num_clks,const struct clk_bulk_data * clks)335570aaec7SAndrey Smirnov clk_bulk_prepare(int num_clks, const struct clk_bulk_data *clks)
336266e4e9dSDong Aisheng {
337266e4e9dSDong Aisheng 	might_sleep();
338266e4e9dSDong Aisheng 	return 0;
339266e4e9dSDong Aisheng }
3400bfa0820SNicolas Pitre 
clk_is_enabled_when_prepared(struct clk * clk)3410bfa0820SNicolas Pitre static inline bool clk_is_enabled_when_prepared(struct clk *clk)
3420bfa0820SNicolas Pitre {
3430bfa0820SNicolas Pitre 	return false;
3440bfa0820SNicolas Pitre }
34593abe8e4SViresh Kumar #endif
34693abe8e4SViresh Kumar 
34793abe8e4SViresh Kumar /**
34893abe8e4SViresh Kumar  * clk_unprepare - undo preparation of a clock source
34993abe8e4SViresh Kumar  * @clk: clock source
35093abe8e4SViresh Kumar  *
35193abe8e4SViresh Kumar  * This undoes a previously prepared clock.  The caller must balance
35293abe8e4SViresh Kumar  * the number of prepare and unprepare calls.
35393abe8e4SViresh Kumar  *
35493abe8e4SViresh Kumar  * Must not be called from within atomic context.
35593abe8e4SViresh Kumar  */
35693abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE
35793abe8e4SViresh Kumar void clk_unprepare(struct clk *clk);
358266e4e9dSDong Aisheng void clk_bulk_unprepare(int num_clks, const struct clk_bulk_data *clks);
35993abe8e4SViresh Kumar #else
clk_unprepare(struct clk * clk)36093abe8e4SViresh Kumar static inline void clk_unprepare(struct clk *clk)
36193abe8e4SViresh Kumar {
36293abe8e4SViresh Kumar 	might_sleep();
36393abe8e4SViresh Kumar }
clk_bulk_unprepare(int num_clks,const struct clk_bulk_data * clks)364570aaec7SAndrey Smirnov static inline void clk_bulk_unprepare(int num_clks,
365570aaec7SAndrey Smirnov 				      const struct clk_bulk_data *clks)
366266e4e9dSDong Aisheng {
367266e4e9dSDong Aisheng 	might_sleep();
368266e4e9dSDong Aisheng }
36993abe8e4SViresh Kumar #endif
37093abe8e4SViresh Kumar 
37193abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK
37293abe8e4SViresh Kumar /**
373f8ce2547SRussell King  * clk_get - lookup and obtain a reference to a clock producer.
374f8ce2547SRussell King  * @dev: device for clock "consumer"
375a58b3a4aSJan-Simon Möller  * @id: clock consumer ID
376f8ce2547SRussell King  *
377f8ce2547SRussell King  * Returns a struct clk corresponding to the clock producer, or
378f8ce2547SRussell King  * valid IS_ERR() condition containing errno.  The implementation
379f8ce2547SRussell King  * uses @dev and @id to determine the clock consumer, and thereby
380f8ce2547SRussell King  * the clock producer.  (IOW, @id may be identical strings, but
381f8ce2547SRussell King  * clk_get may return different clock producers depending on @dev.)
382f8ce2547SRussell King  *
383f8ce2547SRussell King  * Drivers must assume that the clock source is not enabled.
384f7ad160bSAlex Raimondi  *
385f7ad160bSAlex Raimondi  * clk_get should not be called from within interrupt context.
386f8ce2547SRussell King  */
387f8ce2547SRussell King struct clk *clk_get(struct device *dev, const char *id);
388f8ce2547SRussell King 
389f8ce2547SRussell King /**
390266e4e9dSDong Aisheng  * clk_bulk_get - lookup and obtain a number of references to clock producer.
391266e4e9dSDong Aisheng  * @dev: device for clock "consumer"
392266e4e9dSDong Aisheng  * @num_clks: the number of clk_bulk_data
393266e4e9dSDong Aisheng  * @clks: the clk_bulk_data table of consumer
394266e4e9dSDong Aisheng  *
395266e4e9dSDong Aisheng  * This helper function allows drivers to get several clk consumers in one
396266e4e9dSDong Aisheng  * operation. If any of the clk cannot be acquired then any clks
397266e4e9dSDong Aisheng  * that were obtained will be freed before returning to the caller.
398266e4e9dSDong Aisheng  *
399266e4e9dSDong Aisheng  * Returns 0 if all clocks specified in clk_bulk_data table are obtained
400266e4e9dSDong Aisheng  * successfully, or valid IS_ERR() condition containing errno.
401266e4e9dSDong Aisheng  * The implementation uses @dev and @clk_bulk_data.id to determine the
402266e4e9dSDong Aisheng  * clock consumer, and thereby the clock producer.
403266e4e9dSDong Aisheng  * The clock returned is stored in each @clk_bulk_data.clk field.
404266e4e9dSDong Aisheng  *
405266e4e9dSDong Aisheng  * Drivers must assume that the clock source is not enabled.
406266e4e9dSDong Aisheng  *
407266e4e9dSDong Aisheng  * clk_bulk_get should not be called from within interrupt context.
408266e4e9dSDong Aisheng  */
409266e4e9dSDong Aisheng int __must_check clk_bulk_get(struct device *dev, int num_clks,
410266e4e9dSDong Aisheng 			      struct clk_bulk_data *clks);
411616e45dfSDong Aisheng /**
412616e45dfSDong Aisheng  * clk_bulk_get_all - lookup and obtain all available references to clock
413616e45dfSDong Aisheng  *		      producer.
414616e45dfSDong Aisheng  * @dev: device for clock "consumer"
415616e45dfSDong Aisheng  * @clks: pointer to the clk_bulk_data table of consumer
416616e45dfSDong Aisheng  *
417616e45dfSDong Aisheng  * This helper function allows drivers to get all clk consumers in one
418616e45dfSDong Aisheng  * operation. If any of the clk cannot be acquired then any clks
419616e45dfSDong Aisheng  * that were obtained will be freed before returning to the caller.
420616e45dfSDong Aisheng  *
421616e45dfSDong Aisheng  * Returns a positive value for the number of clocks obtained while the
422616e45dfSDong Aisheng  * clock references are stored in the clk_bulk_data table in @clks field.
423616e45dfSDong Aisheng  * Returns 0 if there're none and a negative value if something failed.
424616e45dfSDong Aisheng  *
425616e45dfSDong Aisheng  * Drivers must assume that the clock source is not enabled.
426616e45dfSDong Aisheng  *
427616e45dfSDong Aisheng  * clk_bulk_get should not be called from within interrupt context.
428616e45dfSDong Aisheng  */
429616e45dfSDong Aisheng int __must_check clk_bulk_get_all(struct device *dev,
430616e45dfSDong Aisheng 				  struct clk_bulk_data **clks);
4312f25528eSSylwester Nawrocki 
4322f25528eSSylwester Nawrocki /**
4332f25528eSSylwester Nawrocki  * clk_bulk_get_optional - lookup and obtain a number of references to clock producer
4342f25528eSSylwester Nawrocki  * @dev: device for clock "consumer"
4352f25528eSSylwester Nawrocki  * @num_clks: the number of clk_bulk_data
4362f25528eSSylwester Nawrocki  * @clks: the clk_bulk_data table of consumer
4372f25528eSSylwester Nawrocki  *
4382f25528eSSylwester Nawrocki  * Behaves the same as clk_bulk_get() except where there is no clock producer.
4392f25528eSSylwester Nawrocki  * In this case, instead of returning -ENOENT, the function returns 0 and
4402f25528eSSylwester Nawrocki  * NULL for a clk for which a clock producer could not be determined.
4412f25528eSSylwester Nawrocki  */
4422f25528eSSylwester Nawrocki int __must_check clk_bulk_get_optional(struct device *dev, int num_clks,
4432f25528eSSylwester Nawrocki 				       struct clk_bulk_data *clks);
444266e4e9dSDong Aisheng /**
445618aee02SDong Aisheng  * devm_clk_bulk_get - managed get multiple clk consumers
446618aee02SDong Aisheng  * @dev: device for clock "consumer"
447618aee02SDong Aisheng  * @num_clks: the number of clk_bulk_data
448618aee02SDong Aisheng  * @clks: the clk_bulk_data table of consumer
449618aee02SDong Aisheng  *
450618aee02SDong Aisheng  * Return 0 on success, an errno on failure.
451618aee02SDong Aisheng  *
452618aee02SDong Aisheng  * This helper function allows drivers to get several clk
453618aee02SDong Aisheng  * consumers in one operation with management, the clks will
454618aee02SDong Aisheng  * automatically be freed when the device is unbound.
455618aee02SDong Aisheng  */
456618aee02SDong Aisheng int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
457618aee02SDong Aisheng 				   struct clk_bulk_data *clks);
458f08c2e28SDong Aisheng /**
4599bd5ef0bSSylwester Nawrocki  * devm_clk_bulk_get_optional - managed get multiple optional consumer clocks
4609bd5ef0bSSylwester Nawrocki  * @dev: device for clock "consumer"
4616ee82ef0SSylwester Nawrocki  * @num_clks: the number of clk_bulk_data
4629bd5ef0bSSylwester Nawrocki  * @clks: pointer to the clk_bulk_data table of consumer
4639bd5ef0bSSylwester Nawrocki  *
4649bd5ef0bSSylwester Nawrocki  * Behaves the same as devm_clk_bulk_get() except where there is no clock
4659bd5ef0bSSylwester Nawrocki  * producer.  In this case, instead of returning -ENOENT, the function returns
4669bd5ef0bSSylwester Nawrocki  * NULL for given clk. It is assumed all clocks in clk_bulk_data are optional.
4679bd5ef0bSSylwester Nawrocki  *
4689bd5ef0bSSylwester Nawrocki  * Returns 0 if all clocks specified in clk_bulk_data table are obtained
4699bd5ef0bSSylwester Nawrocki  * successfully or for any clk there was no clk provider available, otherwise
4709bd5ef0bSSylwester Nawrocki  * returns valid IS_ERR() condition containing errno.
4719bd5ef0bSSylwester Nawrocki  * The implementation uses @dev and @clk_bulk_data.id to determine the
4729bd5ef0bSSylwester Nawrocki  * clock consumer, and thereby the clock producer.
4739bd5ef0bSSylwester Nawrocki  * The clock returned is stored in each @clk_bulk_data.clk field.
4749bd5ef0bSSylwester Nawrocki  *
4759bd5ef0bSSylwester Nawrocki  * Drivers must assume that the clock source is not enabled.
4769bd5ef0bSSylwester Nawrocki  *
4779bd5ef0bSSylwester Nawrocki  * clk_bulk_get should not be called from within interrupt context.
4789bd5ef0bSSylwester Nawrocki  */
4799bd5ef0bSSylwester Nawrocki int __must_check devm_clk_bulk_get_optional(struct device *dev, int num_clks,
4809bd5ef0bSSylwester Nawrocki 					    struct clk_bulk_data *clks);
4819bd5ef0bSSylwester Nawrocki /**
482f08c2e28SDong Aisheng  * devm_clk_bulk_get_all - managed get multiple clk consumers
483f08c2e28SDong Aisheng  * @dev: device for clock "consumer"
484f08c2e28SDong Aisheng  * @clks: pointer to the clk_bulk_data table of consumer
485f08c2e28SDong Aisheng  *
486f08c2e28SDong Aisheng  * Returns a positive value for the number of clocks obtained while the
487f08c2e28SDong Aisheng  * clock references are stored in the clk_bulk_data table in @clks field.
488f08c2e28SDong Aisheng  * Returns 0 if there're none and a negative value if something failed.
489f08c2e28SDong Aisheng  *
490f08c2e28SDong Aisheng  * This helper function allows drivers to get several clk
491f08c2e28SDong Aisheng  * consumers in one operation with management, the clks will
492f08c2e28SDong Aisheng  * automatically be freed when the device is unbound.
493f08c2e28SDong Aisheng  */
494f08c2e28SDong Aisheng 
495f08c2e28SDong Aisheng int __must_check devm_clk_bulk_get_all(struct device *dev,
496f08c2e28SDong Aisheng 				       struct clk_bulk_data **clks);
497618aee02SDong Aisheng 
498618aee02SDong Aisheng /**
499*51e32e89SCristian Ciocaltea  * devm_clk_bulk_get_all_enabled - Get and enable all clocks of the consumer (managed)
500265b07dfSShradha Todi  * @dev: device for clock "consumer"
501265b07dfSShradha Todi  * @clks: pointer to the clk_bulk_data table of consumer
502265b07dfSShradha Todi  *
503*51e32e89SCristian Ciocaltea  * Returns a positive value for the number of clocks obtained while the
504*51e32e89SCristian Ciocaltea  * clock references are stored in the clk_bulk_data table in @clks field.
505*51e32e89SCristian Ciocaltea  * Returns 0 if there're none and a negative value if something failed.
506265b07dfSShradha Todi  *
507265b07dfSShradha Todi  * This helper function allows drivers to get all clocks of the
508265b07dfSShradha Todi  * consumer and enables them in one operation with management.
509265b07dfSShradha Todi  * The clks will automatically be disabled and freed when the device
510265b07dfSShradha Todi  * is unbound.
511265b07dfSShradha Todi  */
512265b07dfSShradha Todi 
513*51e32e89SCristian Ciocaltea int __must_check devm_clk_bulk_get_all_enabled(struct device *dev,
514265b07dfSShradha Todi 					       struct clk_bulk_data **clks);
515265b07dfSShradha Todi 
516265b07dfSShradha Todi /**
517a8a97db9SMark Brown  * devm_clk_get - lookup and obtain a managed reference to a clock producer.
518a8a97db9SMark Brown  * @dev: device for clock "consumer"
519a58b3a4aSJan-Simon Möller  * @id: clock consumer ID
520a8a97db9SMark Brown  *
521af89cd45SUwe Kleine-König  * Context: May sleep.
522af89cd45SUwe Kleine-König  *
523af89cd45SUwe Kleine-König  * Return: a struct clk corresponding to the clock producer, or
524a8a97db9SMark Brown  * valid IS_ERR() condition containing errno.  The implementation
525a8a97db9SMark Brown  * uses @dev and @id to determine the clock consumer, and thereby
526a8a97db9SMark Brown  * the clock producer.  (IOW, @id may be identical strings, but
527a8a97db9SMark Brown  * clk_get may return different clock producers depending on @dev.)
528a8a97db9SMark Brown  *
529af89cd45SUwe Kleine-König  * Drivers must assume that the clock source is neither prepared nor
530af89cd45SUwe Kleine-König  * enabled.
531a8a97db9SMark Brown  *
532a8a97db9SMark Brown  * The clock will automatically be freed when the device is unbound
533a8a97db9SMark Brown  * from the bus.
534a8a97db9SMark Brown  */
535a8a97db9SMark Brown struct clk *devm_clk_get(struct device *dev, const char *id);
536a8a97db9SMark Brown 
537a8a97db9SMark Brown /**
5387ef9651eSUwe Kleine-König  * devm_clk_get_prepared - devm_clk_get() + clk_prepare()
5397ef9651eSUwe Kleine-König  * @dev: device for clock "consumer"
5407ef9651eSUwe Kleine-König  * @id: clock consumer ID
5417ef9651eSUwe Kleine-König  *
5427ef9651eSUwe Kleine-König  * Context: May sleep.
5437ef9651eSUwe Kleine-König  *
5447ef9651eSUwe Kleine-König  * Return: a struct clk corresponding to the clock producer, or
5457ef9651eSUwe Kleine-König  * valid IS_ERR() condition containing errno.  The implementation
5467ef9651eSUwe Kleine-König  * uses @dev and @id to determine the clock consumer, and thereby
5477ef9651eSUwe Kleine-König  * the clock producer.  (IOW, @id may be identical strings, but
5487ef9651eSUwe Kleine-König  * clk_get may return different clock producers depending on @dev.)
5497ef9651eSUwe Kleine-König  *
5507ef9651eSUwe Kleine-König  * The returned clk (if valid) is prepared. Drivers must however assume
5517ef9651eSUwe Kleine-König  * that the clock is not enabled.
5527ef9651eSUwe Kleine-König  *
5537ef9651eSUwe Kleine-König  * The clock will automatically be unprepared and freed when the device
5547ef9651eSUwe Kleine-König  * is unbound from the bus.
5557ef9651eSUwe Kleine-König  */
5567ef9651eSUwe Kleine-König struct clk *devm_clk_get_prepared(struct device *dev, const char *id);
5577ef9651eSUwe Kleine-König 
5587ef9651eSUwe Kleine-König /**
5597ef9651eSUwe Kleine-König  * devm_clk_get_enabled - devm_clk_get() + clk_prepare_enable()
5607ef9651eSUwe Kleine-König  * @dev: device for clock "consumer"
5617ef9651eSUwe Kleine-König  * @id: clock consumer ID
5627ef9651eSUwe Kleine-König  *
5637ef9651eSUwe Kleine-König  * Context: May sleep.
5647ef9651eSUwe Kleine-König  *
5657ef9651eSUwe Kleine-König  * Return: a struct clk corresponding to the clock producer, or
5667ef9651eSUwe Kleine-König  * valid IS_ERR() condition containing errno.  The implementation
5677ef9651eSUwe Kleine-König  * uses @dev and @id to determine the clock consumer, and thereby
5687ef9651eSUwe Kleine-König  * the clock producer.  (IOW, @id may be identical strings, but
5697ef9651eSUwe Kleine-König  * clk_get may return different clock producers depending on @dev.)
5707ef9651eSUwe Kleine-König  *
5717ef9651eSUwe Kleine-König  * The returned clk (if valid) is prepared and enabled.
5727ef9651eSUwe Kleine-König  *
5737ef9651eSUwe Kleine-König  * The clock will automatically be disabled, unprepared and freed
5747ef9651eSUwe Kleine-König  * when the device is unbound from the bus.
5757ef9651eSUwe Kleine-König  */
5767ef9651eSUwe Kleine-König struct clk *devm_clk_get_enabled(struct device *dev, const char *id);
5777ef9651eSUwe Kleine-König 
5787ef9651eSUwe Kleine-König /**
57960b8f0ddSPhil Edworthy  * devm_clk_get_optional - lookup and obtain a managed reference to an optional
58060b8f0ddSPhil Edworthy  *			   clock producer.
58160b8f0ddSPhil Edworthy  * @dev: device for clock "consumer"
58260b8f0ddSPhil Edworthy  * @id: clock consumer ID
58360b8f0ddSPhil Edworthy  *
584af89cd45SUwe Kleine-König  * Context: May sleep.
585af89cd45SUwe Kleine-König  *
586af89cd45SUwe Kleine-König  * Return: a struct clk corresponding to the clock producer, or
587af89cd45SUwe Kleine-König  * valid IS_ERR() condition containing errno.  The implementation
588af89cd45SUwe Kleine-König  * uses @dev and @id to determine the clock consumer, and thereby
589af89cd45SUwe Kleine-König  * the clock producer.  If no such clk is found, it returns NULL
590af89cd45SUwe Kleine-König  * which serves as a dummy clk.  That's the only difference compared
591af89cd45SUwe Kleine-König  * to devm_clk_get().
592af89cd45SUwe Kleine-König  *
593af89cd45SUwe Kleine-König  * Drivers must assume that the clock source is neither prepared nor
594af89cd45SUwe Kleine-König  * enabled.
595af89cd45SUwe Kleine-König  *
596af89cd45SUwe Kleine-König  * The clock will automatically be freed when the device is unbound
597af89cd45SUwe Kleine-König  * from the bus.
59860b8f0ddSPhil Edworthy  */
59960b8f0ddSPhil Edworthy struct clk *devm_clk_get_optional(struct device *dev, const char *id);
60060b8f0ddSPhil Edworthy 
60160b8f0ddSPhil Edworthy /**
6027ef9651eSUwe Kleine-König  * devm_clk_get_optional_prepared - devm_clk_get_optional() + clk_prepare()
6037ef9651eSUwe Kleine-König  * @dev: device for clock "consumer"
6047ef9651eSUwe Kleine-König  * @id: clock consumer ID
6057ef9651eSUwe Kleine-König  *
6067ef9651eSUwe Kleine-König  * Context: May sleep.
6077ef9651eSUwe Kleine-König  *
6087ef9651eSUwe Kleine-König  * Return: a struct clk corresponding to the clock producer, or
6097ef9651eSUwe Kleine-König  * valid IS_ERR() condition containing errno.  The implementation
6107ef9651eSUwe Kleine-König  * uses @dev and @id to determine the clock consumer, and thereby
6117ef9651eSUwe Kleine-König  * the clock producer.  If no such clk is found, it returns NULL
6127ef9651eSUwe Kleine-König  * which serves as a dummy clk.  That's the only difference compared
6137ef9651eSUwe Kleine-König  * to devm_clk_get_prepared().
6147ef9651eSUwe Kleine-König  *
6157ef9651eSUwe Kleine-König  * The returned clk (if valid) is prepared. Drivers must however
6167ef9651eSUwe Kleine-König  * assume that the clock is not enabled.
6177ef9651eSUwe Kleine-König  *
6187ef9651eSUwe Kleine-König  * The clock will automatically be unprepared and freed when the
6197ef9651eSUwe Kleine-König  * device is unbound from the bus.
6207ef9651eSUwe Kleine-König  */
6217ef9651eSUwe Kleine-König struct clk *devm_clk_get_optional_prepared(struct device *dev, const char *id);
6227ef9651eSUwe Kleine-König 
6237ef9651eSUwe Kleine-König /**
6247ef9651eSUwe Kleine-König  * devm_clk_get_optional_enabled - devm_clk_get_optional() +
6257ef9651eSUwe Kleine-König  *                                 clk_prepare_enable()
6267ef9651eSUwe Kleine-König  * @dev: device for clock "consumer"
6277ef9651eSUwe Kleine-König  * @id: clock consumer ID
6287ef9651eSUwe Kleine-König  *
6297ef9651eSUwe Kleine-König  * Context: May sleep.
6307ef9651eSUwe Kleine-König  *
6317ef9651eSUwe Kleine-König  * Return: a struct clk corresponding to the clock producer, or
6327ef9651eSUwe Kleine-König  * valid IS_ERR() condition containing errno.  The implementation
6337ef9651eSUwe Kleine-König  * uses @dev and @id to determine the clock consumer, and thereby
6347ef9651eSUwe Kleine-König  * the clock producer.  If no such clk is found, it returns NULL
6357ef9651eSUwe Kleine-König  * which serves as a dummy clk.  That's the only difference compared
6367ef9651eSUwe Kleine-König  * to devm_clk_get_enabled().
6377ef9651eSUwe Kleine-König  *
6387ef9651eSUwe Kleine-König  * The returned clk (if valid) is prepared and enabled.
6397ef9651eSUwe Kleine-König  *
6407ef9651eSUwe Kleine-König  * The clock will automatically be disabled, unprepared and freed
6417ef9651eSUwe Kleine-König  * when the device is unbound from the bus.
6427ef9651eSUwe Kleine-König  */
6437ef9651eSUwe Kleine-König struct clk *devm_clk_get_optional_enabled(struct device *dev, const char *id);
6447ef9651eSUwe Kleine-König 
6457ef9651eSUwe Kleine-König /**
6469934a1bdSBartosz Golaszewski  * devm_clk_get_optional_enabled_with_rate - devm_clk_get_optional() +
6479934a1bdSBartosz Golaszewski  *                                           clk_set_rate() +
6489934a1bdSBartosz Golaszewski  *                                           clk_prepare_enable()
6499934a1bdSBartosz Golaszewski  * @dev: device for clock "consumer"
6509934a1bdSBartosz Golaszewski  * @id: clock consumer ID
6519934a1bdSBartosz Golaszewski  * @rate: new clock rate
6529934a1bdSBartosz Golaszewski  *
6539934a1bdSBartosz Golaszewski  * Context: May sleep.
6549934a1bdSBartosz Golaszewski  *
6559934a1bdSBartosz Golaszewski  * Return: a struct clk corresponding to the clock producer, or
6569934a1bdSBartosz Golaszewski  * valid IS_ERR() condition containing errno.  The implementation
6579934a1bdSBartosz Golaszewski  * uses @dev and @id to determine the clock consumer, and thereby
6589934a1bdSBartosz Golaszewski  * the clock producer.  If no such clk is found, it returns NULL
6599934a1bdSBartosz Golaszewski  * which serves as a dummy clk.  That's the only difference compared
6609934a1bdSBartosz Golaszewski  * to devm_clk_get_enabled().
6619934a1bdSBartosz Golaszewski  *
6629934a1bdSBartosz Golaszewski  * The returned clk (if valid) is prepared and enabled and rate was set.
6639934a1bdSBartosz Golaszewski  *
6649934a1bdSBartosz Golaszewski  * The clock will automatically be disabled, unprepared and freed
6659934a1bdSBartosz Golaszewski  * when the device is unbound from the bus.
6669934a1bdSBartosz Golaszewski  */
6679934a1bdSBartosz Golaszewski struct clk *devm_clk_get_optional_enabled_with_rate(struct device *dev,
6689934a1bdSBartosz Golaszewski 						    const char *id,
6699934a1bdSBartosz Golaszewski 						    unsigned long rate);
6709934a1bdSBartosz Golaszewski 
6719934a1bdSBartosz Golaszewski /**
67271a2f115SKuninori Morimoto  * devm_get_clk_from_child - lookup and obtain a managed reference to a
67371a2f115SKuninori Morimoto  *			     clock producer from child node.
67471a2f115SKuninori Morimoto  * @dev: device for clock "consumer"
67571a2f115SKuninori Morimoto  * @np: pointer to clock consumer node
67671a2f115SKuninori Morimoto  * @con_id: clock consumer ID
67771a2f115SKuninori Morimoto  *
67871a2f115SKuninori Morimoto  * This function parses the clocks, and uses them to look up the
67971a2f115SKuninori Morimoto  * struct clk from the registered list of clock providers by using
68071a2f115SKuninori Morimoto  * @np and @con_id
68171a2f115SKuninori Morimoto  *
68271a2f115SKuninori Morimoto  * The clock will automatically be freed when the device is unbound
68371a2f115SKuninori Morimoto  * from the bus.
68471a2f115SKuninori Morimoto  */
68571a2f115SKuninori Morimoto struct clk *devm_get_clk_from_child(struct device *dev,
68671a2f115SKuninori Morimoto 				    struct device_node *np, const char *con_id);
68771a2f115SKuninori Morimoto 
68871a2f115SKuninori Morimoto /**
689f8ce2547SRussell King  * clk_enable - inform the system when the clock source should be running.
690f8ce2547SRussell King  * @clk: clock source
691f8ce2547SRussell King  *
692f8ce2547SRussell King  * If the clock can not be enabled/disabled, this should return success.
693f8ce2547SRussell King  *
69440d3e0f4SRussell King  * May be called from atomic contexts.
69540d3e0f4SRussell King  *
696f8ce2547SRussell King  * Returns success (0) or negative errno.
697f8ce2547SRussell King  */
698f8ce2547SRussell King int clk_enable(struct clk *clk);
699f8ce2547SRussell King 
700f8ce2547SRussell King /**
701266e4e9dSDong Aisheng  * clk_bulk_enable - inform the system when the set of clks should be running.
702266e4e9dSDong Aisheng  * @num_clks: the number of clk_bulk_data
703266e4e9dSDong Aisheng  * @clks: the clk_bulk_data table of consumer
704266e4e9dSDong Aisheng  *
705266e4e9dSDong Aisheng  * May be called from atomic contexts.
706266e4e9dSDong Aisheng  *
707266e4e9dSDong Aisheng  * Returns success (0) or negative errno.
708266e4e9dSDong Aisheng  */
709266e4e9dSDong Aisheng int __must_check clk_bulk_enable(int num_clks,
710266e4e9dSDong Aisheng 				 const struct clk_bulk_data *clks);
711266e4e9dSDong Aisheng 
712266e4e9dSDong Aisheng /**
713f8ce2547SRussell King  * clk_disable - inform the system when the clock source is no longer required.
714f8ce2547SRussell King  * @clk: clock source
715f8ce2547SRussell King  *
716f8ce2547SRussell King  * Inform the system that a clock source is no longer required by
717f8ce2547SRussell King  * a driver and may be shut down.
718f8ce2547SRussell King  *
71940d3e0f4SRussell King  * May be called from atomic contexts.
72040d3e0f4SRussell King  *
721f8ce2547SRussell King  * Implementation detail: if the clock source is shared between
722f8ce2547SRussell King  * multiple drivers, clk_enable() calls must be balanced by the
723f8ce2547SRussell King  * same number of clk_disable() calls for the clock source to be
724f8ce2547SRussell King  * disabled.
725f8ce2547SRussell King  */
726f8ce2547SRussell King void clk_disable(struct clk *clk);
727f8ce2547SRussell King 
728f8ce2547SRussell King /**
729266e4e9dSDong Aisheng  * clk_bulk_disable - inform the system when the set of clks is no
730266e4e9dSDong Aisheng  *		      longer required.
731266e4e9dSDong Aisheng  * @num_clks: the number of clk_bulk_data
732266e4e9dSDong Aisheng  * @clks: the clk_bulk_data table of consumer
733266e4e9dSDong Aisheng  *
734266e4e9dSDong Aisheng  * Inform the system that a set of clks is no longer required by
735266e4e9dSDong Aisheng  * a driver and may be shut down.
736266e4e9dSDong Aisheng  *
737266e4e9dSDong Aisheng  * May be called from atomic contexts.
738266e4e9dSDong Aisheng  *
739266e4e9dSDong Aisheng  * Implementation detail: if the set of clks is shared between
740266e4e9dSDong Aisheng  * multiple drivers, clk_bulk_enable() calls must be balanced by the
741266e4e9dSDong Aisheng  * same number of clk_bulk_disable() calls for the clock source to be
742266e4e9dSDong Aisheng  * disabled.
743266e4e9dSDong Aisheng  */
744266e4e9dSDong Aisheng void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks);
745266e4e9dSDong Aisheng 
746266e4e9dSDong Aisheng /**
747f8ce2547SRussell King  * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
748f8ce2547SRussell King  *		  This is only valid once the clock source has been enabled.
749f8ce2547SRussell King  * @clk: clock source
750f8ce2547SRussell King  */
751f8ce2547SRussell King unsigned long clk_get_rate(struct clk *clk);
752f8ce2547SRussell King 
753f8ce2547SRussell King /**
754f8ce2547SRussell King  * clk_put	- "free" the clock source
755f8ce2547SRussell King  * @clk: clock source
756f8ce2547SRussell King  *
757f8ce2547SRussell King  * Note: drivers must ensure that all clk_enable calls made on this
758f8ce2547SRussell King  * clock source are balanced by clk_disable calls prior to calling
759f8ce2547SRussell King  * this function.
760f7ad160bSAlex Raimondi  *
761f7ad160bSAlex Raimondi  * clk_put should not be called from within interrupt context.
762f8ce2547SRussell King  */
763f8ce2547SRussell King void clk_put(struct clk *clk);
764f8ce2547SRussell King 
765a8a97db9SMark Brown /**
766266e4e9dSDong Aisheng  * clk_bulk_put	- "free" the clock source
767266e4e9dSDong Aisheng  * @num_clks: the number of clk_bulk_data
768266e4e9dSDong Aisheng  * @clks: the clk_bulk_data table of consumer
769266e4e9dSDong Aisheng  *
770266e4e9dSDong Aisheng  * Note: drivers must ensure that all clk_bulk_enable calls made on this
771266e4e9dSDong Aisheng  * clock source are balanced by clk_bulk_disable calls prior to calling
772266e4e9dSDong Aisheng  * this function.
773266e4e9dSDong Aisheng  *
774266e4e9dSDong Aisheng  * clk_bulk_put should not be called from within interrupt context.
775266e4e9dSDong Aisheng  */
776266e4e9dSDong Aisheng void clk_bulk_put(int num_clks, struct clk_bulk_data *clks);
777266e4e9dSDong Aisheng 
778266e4e9dSDong Aisheng /**
779616e45dfSDong Aisheng  * clk_bulk_put_all - "free" all the clock source
780616e45dfSDong Aisheng  * @num_clks: the number of clk_bulk_data
781616e45dfSDong Aisheng  * @clks: the clk_bulk_data table of consumer
782616e45dfSDong Aisheng  *
783616e45dfSDong Aisheng  * Note: drivers must ensure that all clk_bulk_enable calls made on this
784616e45dfSDong Aisheng  * clock source are balanced by clk_bulk_disable calls prior to calling
785616e45dfSDong Aisheng  * this function.
786616e45dfSDong Aisheng  *
787616e45dfSDong Aisheng  * clk_bulk_put_all should not be called from within interrupt context.
788616e45dfSDong Aisheng  */
789616e45dfSDong Aisheng void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks);
790616e45dfSDong Aisheng 
791616e45dfSDong Aisheng /**
792a8a97db9SMark Brown  * devm_clk_put	- "free" a managed clock source
793da3dae54SMasanari Iida  * @dev: device used to acquire the clock
794a8a97db9SMark Brown  * @clk: clock source acquired with devm_clk_get()
795a8a97db9SMark Brown  *
796a8a97db9SMark Brown  * Note: drivers must ensure that all clk_enable calls made on this
797a8a97db9SMark Brown  * clock source are balanced by clk_disable calls prior to calling
798a8a97db9SMark Brown  * this function.
799a8a97db9SMark Brown  *
800a8a97db9SMark Brown  * clk_put should not be called from within interrupt context.
801a8a97db9SMark Brown  */
802a8a97db9SMark Brown void devm_clk_put(struct device *dev, struct clk *clk);
803f8ce2547SRussell King 
804f8ce2547SRussell King /*
805f8ce2547SRussell King  * The remaining APIs are optional for machine class support.
806f8ce2547SRussell King  */
807f8ce2547SRussell King 
808f8ce2547SRussell King 
809f8ce2547SRussell King /**
810f8ce2547SRussell King  * clk_round_rate - adjust a rate to the exact rate a clock can provide
811f8ce2547SRussell King  * @clk: clock source
812f8ce2547SRussell King  * @rate: desired clock rate in Hz
813f8ce2547SRussell King  *
814d2d14a77SRussell King  * This answers the question "if I were to pass @rate to clk_set_rate(),
815d2d14a77SRussell King  * what clock rate would I end up with?" without changing the hardware
816d2d14a77SRussell King  * in any way.  In other words:
817d2d14a77SRussell King  *
818d2d14a77SRussell King  *   rate = clk_round_rate(clk, r);
819d2d14a77SRussell King  *
820d2d14a77SRussell King  * and:
821d2d14a77SRussell King  *
822d2d14a77SRussell King  *   clk_set_rate(clk, r);
823d2d14a77SRussell King  *   rate = clk_get_rate(clk);
824d2d14a77SRussell King  *
825d2d14a77SRussell King  * are equivalent except the former does not modify the clock hardware
826d2d14a77SRussell King  * in any way.
827d2d14a77SRussell King  *
828f8ce2547SRussell King  * Returns rounded clock rate in Hz, or negative errno.
829f8ce2547SRussell King  */
830f8ce2547SRussell King long clk_round_rate(struct clk *clk, unsigned long rate);
831f8ce2547SRussell King 
832f8ce2547SRussell King /**
833f8ce2547SRussell King  * clk_set_rate - set the clock rate for a clock source
834f8ce2547SRussell King  * @clk: clock source
835f8ce2547SRussell King  * @rate: desired clock rate in Hz
836f8ce2547SRussell King  *
83764c76b31SMartin Blumenstingl  * Updating the rate starts at the top-most affected clock and then
83864c76b31SMartin Blumenstingl  * walks the tree down to the bottom-most clock that needs updating.
83964c76b31SMartin Blumenstingl  *
840f8ce2547SRussell King  * Returns success (0) or negative errno.
841f8ce2547SRussell King  */
842f8ce2547SRussell King int clk_set_rate(struct clk *clk, unsigned long rate);
843f8ce2547SRussell King 
844f8ce2547SRussell King /**
84555e9b8b7SJerome Brunet  * clk_set_rate_exclusive- set the clock rate and claim exclusivity over
84655e9b8b7SJerome Brunet  *                         clock source
84755e9b8b7SJerome Brunet  * @clk: clock source
84855e9b8b7SJerome Brunet  * @rate: desired clock rate in Hz
84955e9b8b7SJerome Brunet  *
85055e9b8b7SJerome Brunet  * This helper function allows drivers to atomically set the rate of a producer
85155e9b8b7SJerome Brunet  * and claim exclusivity over the rate control of the producer.
85255e9b8b7SJerome Brunet  *
85355e9b8b7SJerome Brunet  * It is essentially a combination of clk_set_rate() and
85455e9b8b7SJerome Brunet  * clk_rate_exclusite_get(). Caller must balance this call with a call to
85555e9b8b7SJerome Brunet  * clk_rate_exclusive_put()
85655e9b8b7SJerome Brunet  *
85755e9b8b7SJerome Brunet  * Returns success (0) or negative errno.
85855e9b8b7SJerome Brunet  */
85955e9b8b7SJerome Brunet int clk_set_rate_exclusive(struct clk *clk, unsigned long rate);
86055e9b8b7SJerome Brunet 
86155e9b8b7SJerome Brunet /**
8624e88f3deSThierry Reding  * clk_has_parent - check if a clock is a possible parent for another
8634e88f3deSThierry Reding  * @clk: clock source
8644e88f3deSThierry Reding  * @parent: parent clock source
8654e88f3deSThierry Reding  *
8664e88f3deSThierry Reding  * This function can be used in drivers that need to check that a clock can be
8674e88f3deSThierry Reding  * the parent of another without actually changing the parent.
8684e88f3deSThierry Reding  *
8694e88f3deSThierry Reding  * Returns true if @parent is a possible parent for @clk, false otherwise.
8704e88f3deSThierry Reding  */
87122fb0e28SMaxime Ripard bool clk_has_parent(const struct clk *clk, const struct clk *parent);
8724e88f3deSThierry Reding 
8734e88f3deSThierry Reding /**
8741c8e6004STomeu Vizoso  * clk_set_rate_range - set a rate range for a clock source
8751c8e6004STomeu Vizoso  * @clk: clock source
8761c8e6004STomeu Vizoso  * @min: desired minimum clock rate in Hz, inclusive
8771c8e6004STomeu Vizoso  * @max: desired maximum clock rate in Hz, inclusive
8781c8e6004STomeu Vizoso  *
8791c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
8801c8e6004STomeu Vizoso  */
8811c8e6004STomeu Vizoso int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max);
8821c8e6004STomeu Vizoso 
8831c8e6004STomeu Vizoso /**
8841c8e6004STomeu Vizoso  * clk_set_min_rate - set a minimum clock rate for a clock source
8851c8e6004STomeu Vizoso  * @clk: clock source
8861c8e6004STomeu Vizoso  * @rate: desired minimum clock rate in Hz, inclusive
8871c8e6004STomeu Vizoso  *
8881c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
8891c8e6004STomeu Vizoso  */
8901c8e6004STomeu Vizoso int clk_set_min_rate(struct clk *clk, unsigned long rate);
8911c8e6004STomeu Vizoso 
8921c8e6004STomeu Vizoso /**
8931c8e6004STomeu Vizoso  * clk_set_max_rate - set a maximum clock rate for a clock source
8941c8e6004STomeu Vizoso  * @clk: clock source
8951c8e6004STomeu Vizoso  * @rate: desired maximum clock rate in Hz, inclusive
8961c8e6004STomeu Vizoso  *
8971c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
8981c8e6004STomeu Vizoso  */
8991c8e6004STomeu Vizoso int clk_set_max_rate(struct clk *clk, unsigned long rate);
9001c8e6004STomeu Vizoso 
9011c8e6004STomeu Vizoso /**
902f8ce2547SRussell King  * clk_set_parent - set the parent clock source for this clock
903f8ce2547SRussell King  * @clk: clock source
904f8ce2547SRussell King  * @parent: parent clock source
905f8ce2547SRussell King  *
906f8ce2547SRussell King  * Returns success (0) or negative errno.
907f8ce2547SRussell King  */
908f8ce2547SRussell King int clk_set_parent(struct clk *clk, struct clk *parent);
909f8ce2547SRussell King 
910f8ce2547SRussell King /**
911f8ce2547SRussell King  * clk_get_parent - get the parent clock source for this clock
912f8ce2547SRussell King  * @clk: clock source
913f8ce2547SRussell King  *
914f8ce2547SRussell King  * Returns struct clk corresponding to parent clock source, or
915f8ce2547SRussell King  * valid IS_ERR() condition containing errno.
916f8ce2547SRussell King  */
917f8ce2547SRussell King struct clk *clk_get_parent(struct clk *clk);
918f8ce2547SRussell King 
91905fd8e73SSascha Hauer /**
92005fd8e73SSascha Hauer  * clk_get_sys - get a clock based upon the device name
92105fd8e73SSascha Hauer  * @dev_id: device name
92205fd8e73SSascha Hauer  * @con_id: connection ID
92305fd8e73SSascha Hauer  *
92405fd8e73SSascha Hauer  * Returns a struct clk corresponding to the clock producer, or
92505fd8e73SSascha Hauer  * valid IS_ERR() condition containing errno.  The implementation
92605fd8e73SSascha Hauer  * uses @dev_id and @con_id to determine the clock consumer, and
92705fd8e73SSascha Hauer  * thereby the clock producer. In contrast to clk_get() this function
92805fd8e73SSascha Hauer  * takes the device name instead of the device itself for identification.
92905fd8e73SSascha Hauer  *
93005fd8e73SSascha Hauer  * Drivers must assume that the clock source is not enabled.
93105fd8e73SSascha Hauer  *
93205fd8e73SSascha Hauer  * clk_get_sys should not be called from within interrupt context.
93305fd8e73SSascha Hauer  */
93405fd8e73SSascha Hauer struct clk *clk_get_sys(const char *dev_id, const char *con_id);
93505fd8e73SSascha Hauer 
9368b95d1ceSRuss Dill /**
9378b95d1ceSRuss Dill  * clk_save_context - save clock context for poweroff
9388b95d1ceSRuss Dill  *
9398b95d1ceSRuss Dill  * Saves the context of the clock register for powerstates in which the
9408b95d1ceSRuss Dill  * contents of the registers will be lost. Occurs deep within the suspend
9418b95d1ceSRuss Dill  * code so locking is not necessary.
9428b95d1ceSRuss Dill  */
9438b95d1ceSRuss Dill int clk_save_context(void);
9448b95d1ceSRuss Dill 
9458b95d1ceSRuss Dill /**
9468b95d1ceSRuss Dill  * clk_restore_context - restore clock context after poweroff
9478b95d1ceSRuss Dill  *
9488b95d1ceSRuss Dill  * This occurs with all clocks enabled. Occurs deep within the resume code
9498b95d1ceSRuss Dill  * so locking is not necessary.
9508b95d1ceSRuss Dill  */
9518b95d1ceSRuss Dill void clk_restore_context(void);
9528b95d1ceSRuss Dill 
95393abe8e4SViresh Kumar #else /* !CONFIG_HAVE_CLK */
95493abe8e4SViresh Kumar 
clk_get(struct device * dev,const char * id)95593abe8e4SViresh Kumar static inline struct clk *clk_get(struct device *dev, const char *id)
95693abe8e4SViresh Kumar {
95793abe8e4SViresh Kumar 	return NULL;
95893abe8e4SViresh Kumar }
95993abe8e4SViresh Kumar 
clk_bulk_get(struct device * dev,int num_clks,struct clk_bulk_data * clks)9606e0d4ff4SDong Aisheng static inline int __must_check clk_bulk_get(struct device *dev, int num_clks,
961266e4e9dSDong Aisheng 					    struct clk_bulk_data *clks)
962266e4e9dSDong Aisheng {
963266e4e9dSDong Aisheng 	return 0;
964266e4e9dSDong Aisheng }
965266e4e9dSDong Aisheng 
clk_bulk_get_optional(struct device * dev,int num_clks,struct clk_bulk_data * clks)9662f25528eSSylwester Nawrocki static inline int __must_check clk_bulk_get_optional(struct device *dev,
9672f25528eSSylwester Nawrocki 				int num_clks, struct clk_bulk_data *clks)
9682f25528eSSylwester Nawrocki {
9692f25528eSSylwester Nawrocki 	return 0;
9702f25528eSSylwester Nawrocki }
9712f25528eSSylwester Nawrocki 
clk_bulk_get_all(struct device * dev,struct clk_bulk_data ** clks)972616e45dfSDong Aisheng static inline int __must_check clk_bulk_get_all(struct device *dev,
973616e45dfSDong Aisheng 					 struct clk_bulk_data **clks)
974616e45dfSDong Aisheng {
975616e45dfSDong Aisheng 	return 0;
976616e45dfSDong Aisheng }
977616e45dfSDong Aisheng 
devm_clk_get(struct device * dev,const char * id)97893abe8e4SViresh Kumar static inline struct clk *devm_clk_get(struct device *dev, const char *id)
97993abe8e4SViresh Kumar {
98093abe8e4SViresh Kumar 	return NULL;
98193abe8e4SViresh Kumar }
98293abe8e4SViresh Kumar 
devm_clk_get_prepared(struct device * dev,const char * id)9837ef9651eSUwe Kleine-König static inline struct clk *devm_clk_get_prepared(struct device *dev,
9847ef9651eSUwe Kleine-König 						const char *id)
9857ef9651eSUwe Kleine-König {
9867ef9651eSUwe Kleine-König 	return NULL;
9877ef9651eSUwe Kleine-König }
9887ef9651eSUwe Kleine-König 
devm_clk_get_enabled(struct device * dev,const char * id)9897ef9651eSUwe Kleine-König static inline struct clk *devm_clk_get_enabled(struct device *dev,
9907ef9651eSUwe Kleine-König 					       const char *id)
9917ef9651eSUwe Kleine-König {
9927ef9651eSUwe Kleine-König 	return NULL;
9937ef9651eSUwe Kleine-König }
9947ef9651eSUwe Kleine-König 
devm_clk_get_optional(struct device * dev,const char * id)99560b8f0ddSPhil Edworthy static inline struct clk *devm_clk_get_optional(struct device *dev,
99660b8f0ddSPhil Edworthy 						const char *id)
99760b8f0ddSPhil Edworthy {
99860b8f0ddSPhil Edworthy 	return NULL;
99960b8f0ddSPhil Edworthy }
100060b8f0ddSPhil Edworthy 
devm_clk_get_optional_prepared(struct device * dev,const char * id)10017ef9651eSUwe Kleine-König static inline struct clk *devm_clk_get_optional_prepared(struct device *dev,
10027ef9651eSUwe Kleine-König 							 const char *id)
10037ef9651eSUwe Kleine-König {
10047ef9651eSUwe Kleine-König 	return NULL;
10057ef9651eSUwe Kleine-König }
10067ef9651eSUwe Kleine-König 
devm_clk_get_optional_enabled(struct device * dev,const char * id)10077ef9651eSUwe Kleine-König static inline struct clk *devm_clk_get_optional_enabled(struct device *dev,
10087ef9651eSUwe Kleine-König 							const char *id)
10097ef9651eSUwe Kleine-König {
10107ef9651eSUwe Kleine-König 	return NULL;
10117ef9651eSUwe Kleine-König }
10127ef9651eSUwe Kleine-König 
10139934a1bdSBartosz Golaszewski static inline struct clk *
devm_clk_get_optional_enabled_with_rate(struct device * dev,const char * id,unsigned long rate)10149934a1bdSBartosz Golaszewski devm_clk_get_optional_enabled_with_rate(struct device *dev, const char *id,
10159934a1bdSBartosz Golaszewski 					unsigned long rate)
10169934a1bdSBartosz Golaszewski {
10179934a1bdSBartosz Golaszewski 	return NULL;
10189934a1bdSBartosz Golaszewski }
10199934a1bdSBartosz Golaszewski 
devm_clk_bulk_get(struct device * dev,int num_clks,struct clk_bulk_data * clks)10206e0d4ff4SDong Aisheng static inline int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
1021618aee02SDong Aisheng 						 struct clk_bulk_data *clks)
1022618aee02SDong Aisheng {
1023618aee02SDong Aisheng 	return 0;
1024618aee02SDong Aisheng }
1025618aee02SDong Aisheng 
devm_clk_bulk_get_optional(struct device * dev,int num_clks,struct clk_bulk_data * clks)10269bd5ef0bSSylwester Nawrocki static inline int __must_check devm_clk_bulk_get_optional(struct device *dev,
10279bd5ef0bSSylwester Nawrocki 				int num_clks, struct clk_bulk_data *clks)
10289bd5ef0bSSylwester Nawrocki {
10299bd5ef0bSSylwester Nawrocki 	return 0;
10309bd5ef0bSSylwester Nawrocki }
10319bd5ef0bSSylwester Nawrocki 
devm_clk_bulk_get_all(struct device * dev,struct clk_bulk_data ** clks)1032f08c2e28SDong Aisheng static inline int __must_check devm_clk_bulk_get_all(struct device *dev,
1033f08c2e28SDong Aisheng 						     struct clk_bulk_data **clks)
1034f08c2e28SDong Aisheng {
1035f08c2e28SDong Aisheng 
1036f08c2e28SDong Aisheng 	return 0;
1037f08c2e28SDong Aisheng }
1038f08c2e28SDong Aisheng 
devm_clk_bulk_get_all_enabled(struct device * dev,struct clk_bulk_data ** clks)1039*51e32e89SCristian Ciocaltea static inline int __must_check devm_clk_bulk_get_all_enabled(struct device *dev,
1040265b07dfSShradha Todi 						struct clk_bulk_data **clks)
1041265b07dfSShradha Todi {
1042265b07dfSShradha Todi 	return 0;
1043265b07dfSShradha Todi }
1044265b07dfSShradha Todi 
devm_get_clk_from_child(struct device * dev,struct device_node * np,const char * con_id)104571a2f115SKuninori Morimoto static inline struct clk *devm_get_clk_from_child(struct device *dev,
104671a2f115SKuninori Morimoto 				struct device_node *np, const char *con_id)
104771a2f115SKuninori Morimoto {
104871a2f115SKuninori Morimoto 	return NULL;
104971a2f115SKuninori Morimoto }
105071a2f115SKuninori Morimoto 
clk_put(struct clk * clk)105193abe8e4SViresh Kumar static inline void clk_put(struct clk *clk) {}
105293abe8e4SViresh Kumar 
clk_bulk_put(int num_clks,struct clk_bulk_data * clks)1053266e4e9dSDong Aisheng static inline void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) {}
1054266e4e9dSDong Aisheng 
clk_bulk_put_all(int num_clks,struct clk_bulk_data * clks)1055616e45dfSDong Aisheng static inline void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks) {}
1056616e45dfSDong Aisheng 
devm_clk_put(struct device * dev,struct clk * clk)105793abe8e4SViresh Kumar static inline void devm_clk_put(struct device *dev, struct clk *clk) {}
105893abe8e4SViresh Kumar 
clk_enable(struct clk * clk)105993abe8e4SViresh Kumar static inline int clk_enable(struct clk *clk)
106093abe8e4SViresh Kumar {
106193abe8e4SViresh Kumar 	return 0;
106293abe8e4SViresh Kumar }
106393abe8e4SViresh Kumar 
clk_bulk_enable(int num_clks,const struct clk_bulk_data * clks)1064570aaec7SAndrey Smirnov static inline int __must_check clk_bulk_enable(int num_clks,
1065570aaec7SAndrey Smirnov 					       const struct clk_bulk_data *clks)
1066266e4e9dSDong Aisheng {
1067266e4e9dSDong Aisheng 	return 0;
1068266e4e9dSDong Aisheng }
1069266e4e9dSDong Aisheng 
clk_disable(struct clk * clk)107093abe8e4SViresh Kumar static inline void clk_disable(struct clk *clk) {}
107193abe8e4SViresh Kumar 
1072266e4e9dSDong Aisheng 
clk_bulk_disable(int num_clks,const struct clk_bulk_data * clks)1073266e4e9dSDong Aisheng static inline void clk_bulk_disable(int num_clks,
1074570aaec7SAndrey Smirnov 				    const struct clk_bulk_data *clks) {}
1075266e4e9dSDong Aisheng 
clk_get_rate(struct clk * clk)107693abe8e4SViresh Kumar static inline unsigned long clk_get_rate(struct clk *clk)
107793abe8e4SViresh Kumar {
107893abe8e4SViresh Kumar 	return 0;
107993abe8e4SViresh Kumar }
108093abe8e4SViresh Kumar 
clk_set_rate(struct clk * clk,unsigned long rate)108193abe8e4SViresh Kumar static inline int clk_set_rate(struct clk *clk, unsigned long rate)
108293abe8e4SViresh Kumar {
108393abe8e4SViresh Kumar 	return 0;
108493abe8e4SViresh Kumar }
108593abe8e4SViresh Kumar 
clk_set_rate_exclusive(struct clk * clk,unsigned long rate)108655e9b8b7SJerome Brunet static inline int clk_set_rate_exclusive(struct clk *clk, unsigned long rate)
108755e9b8b7SJerome Brunet {
108855e9b8b7SJerome Brunet 	return 0;
108955e9b8b7SJerome Brunet }
109055e9b8b7SJerome Brunet 
clk_round_rate(struct clk * clk,unsigned long rate)109193abe8e4SViresh Kumar static inline long clk_round_rate(struct clk *clk, unsigned long rate)
109293abe8e4SViresh Kumar {
109393abe8e4SViresh Kumar 	return 0;
109493abe8e4SViresh Kumar }
109593abe8e4SViresh Kumar 
clk_has_parent(struct clk * clk,struct clk * parent)10964e88f3deSThierry Reding static inline bool clk_has_parent(struct clk *clk, struct clk *parent)
10974e88f3deSThierry Reding {
10984e88f3deSThierry Reding 	return true;
10994e88f3deSThierry Reding }
11004e88f3deSThierry Reding 
clk_set_rate_range(struct clk * clk,unsigned long min,unsigned long max)1101b88c9f41SDmitry Osipenko static inline int clk_set_rate_range(struct clk *clk, unsigned long min,
1102b88c9f41SDmitry Osipenko 				     unsigned long max)
1103b88c9f41SDmitry Osipenko {
1104b88c9f41SDmitry Osipenko 	return 0;
1105b88c9f41SDmitry Osipenko }
1106b88c9f41SDmitry Osipenko 
clk_set_min_rate(struct clk * clk,unsigned long rate)1107b88c9f41SDmitry Osipenko static inline int clk_set_min_rate(struct clk *clk, unsigned long rate)
1108b88c9f41SDmitry Osipenko {
1109b88c9f41SDmitry Osipenko 	return 0;
1110b88c9f41SDmitry Osipenko }
1111b88c9f41SDmitry Osipenko 
clk_set_max_rate(struct clk * clk,unsigned long rate)1112b88c9f41SDmitry Osipenko static inline int clk_set_max_rate(struct clk *clk, unsigned long rate)
1113b88c9f41SDmitry Osipenko {
1114b88c9f41SDmitry Osipenko 	return 0;
1115b88c9f41SDmitry Osipenko }
1116b88c9f41SDmitry Osipenko 
clk_set_parent(struct clk * clk,struct clk * parent)111793abe8e4SViresh Kumar static inline int clk_set_parent(struct clk *clk, struct clk *parent)
111893abe8e4SViresh Kumar {
111993abe8e4SViresh Kumar 	return 0;
112093abe8e4SViresh Kumar }
112193abe8e4SViresh Kumar 
clk_get_parent(struct clk * clk)112293abe8e4SViresh Kumar static inline struct clk *clk_get_parent(struct clk *clk)
112393abe8e4SViresh Kumar {
112493abe8e4SViresh Kumar 	return NULL;
112593abe8e4SViresh Kumar }
112693abe8e4SViresh Kumar 
clk_get_sys(const char * dev_id,const char * con_id)1127b81ea968SDaniel Lezcano static inline struct clk *clk_get_sys(const char *dev_id, const char *con_id)
1128b81ea968SDaniel Lezcano {
1129b81ea968SDaniel Lezcano 	return NULL;
1130b81ea968SDaniel Lezcano }
11318b95d1ceSRuss Dill 
clk_save_context(void)11328b95d1ceSRuss Dill static inline int clk_save_context(void)
11338b95d1ceSRuss Dill {
11348b95d1ceSRuss Dill 	return 0;
11358b95d1ceSRuss Dill }
11368b95d1ceSRuss Dill 
clk_restore_context(void)11378b95d1ceSRuss Dill static inline void clk_restore_context(void) {}
11388b95d1ceSRuss Dill 
113993abe8e4SViresh Kumar #endif
114093abe8e4SViresh Kumar 
114193abe8e4SViresh Kumar /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
clk_prepare_enable(struct clk * clk)114293abe8e4SViresh Kumar static inline int clk_prepare_enable(struct clk *clk)
114393abe8e4SViresh Kumar {
114493abe8e4SViresh Kumar 	int ret;
114593abe8e4SViresh Kumar 
114693abe8e4SViresh Kumar 	ret = clk_prepare(clk);
114793abe8e4SViresh Kumar 	if (ret)
114893abe8e4SViresh Kumar 		return ret;
114993abe8e4SViresh Kumar 	ret = clk_enable(clk);
115093abe8e4SViresh Kumar 	if (ret)
115193abe8e4SViresh Kumar 		clk_unprepare(clk);
115293abe8e4SViresh Kumar 
115393abe8e4SViresh Kumar 	return ret;
115493abe8e4SViresh Kumar }
115593abe8e4SViresh Kumar 
115693abe8e4SViresh Kumar /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */
clk_disable_unprepare(struct clk * clk)115793abe8e4SViresh Kumar static inline void clk_disable_unprepare(struct clk *clk)
115893abe8e4SViresh Kumar {
115993abe8e4SViresh Kumar 	clk_disable(clk);
116093abe8e4SViresh Kumar 	clk_unprepare(clk);
116193abe8e4SViresh Kumar }
116293abe8e4SViresh Kumar 
1163570aaec7SAndrey Smirnov static inline int __must_check
clk_bulk_prepare_enable(int num_clks,const struct clk_bulk_data * clks)1164570aaec7SAndrey Smirnov clk_bulk_prepare_enable(int num_clks, const struct clk_bulk_data *clks)
11653c48d86cSBjorn Andersson {
11663c48d86cSBjorn Andersson 	int ret;
11673c48d86cSBjorn Andersson 
11683c48d86cSBjorn Andersson 	ret = clk_bulk_prepare(num_clks, clks);
11693c48d86cSBjorn Andersson 	if (ret)
11703c48d86cSBjorn Andersson 		return ret;
11713c48d86cSBjorn Andersson 	ret = clk_bulk_enable(num_clks, clks);
11723c48d86cSBjorn Andersson 	if (ret)
11733c48d86cSBjorn Andersson 		clk_bulk_unprepare(num_clks, clks);
11743c48d86cSBjorn Andersson 
11753c48d86cSBjorn Andersson 	return ret;
11763c48d86cSBjorn Andersson }
11773c48d86cSBjorn Andersson 
clk_bulk_disable_unprepare(int num_clks,const struct clk_bulk_data * clks)11783c48d86cSBjorn Andersson static inline void clk_bulk_disable_unprepare(int num_clks,
1179570aaec7SAndrey Smirnov 					      const struct clk_bulk_data *clks)
11803c48d86cSBjorn Andersson {
11813c48d86cSBjorn Andersson 	clk_bulk_disable(num_clks, clks);
11823c48d86cSBjorn Andersson 	clk_bulk_unprepare(num_clks, clks);
11833c48d86cSBjorn Andersson }
11843c48d86cSBjorn Andersson 
118560b8f0ddSPhil Edworthy /**
1186c9744843SMaxime Ripard  * clk_drop_range - Reset any range set on that clock
1187c9744843SMaxime Ripard  * @clk: clock source
1188c9744843SMaxime Ripard  *
1189c9744843SMaxime Ripard  * Returns success (0) or negative errno.
1190c9744843SMaxime Ripard  */
clk_drop_range(struct clk * clk)1191c9744843SMaxime Ripard static inline int clk_drop_range(struct clk *clk)
1192c9744843SMaxime Ripard {
1193c9744843SMaxime Ripard 	return clk_set_rate_range(clk, 0, ULONG_MAX);
1194c9744843SMaxime Ripard }
1195c9744843SMaxime Ripard 
1196c9744843SMaxime Ripard /**
119760b8f0ddSPhil Edworthy  * clk_get_optional - lookup and obtain a reference to an optional clock
119860b8f0ddSPhil Edworthy  *		      producer.
119960b8f0ddSPhil Edworthy  * @dev: device for clock "consumer"
120060b8f0ddSPhil Edworthy  * @id: clock consumer ID
120160b8f0ddSPhil Edworthy  *
120260b8f0ddSPhil Edworthy  * Behaves the same as clk_get() except where there is no clock producer. In
120360b8f0ddSPhil Edworthy  * this case, instead of returning -ENOENT, the function returns NULL.
120460b8f0ddSPhil Edworthy  */
clk_get_optional(struct device * dev,const char * id)120560b8f0ddSPhil Edworthy static inline struct clk *clk_get_optional(struct device *dev, const char *id)
120660b8f0ddSPhil Edworthy {
120760b8f0ddSPhil Edworthy 	struct clk *clk = clk_get(dev, id);
120860b8f0ddSPhil Edworthy 
120960b8f0ddSPhil Edworthy 	if (clk == ERR_PTR(-ENOENT))
121060b8f0ddSPhil Edworthy 		return NULL;
121160b8f0ddSPhil Edworthy 
121260b8f0ddSPhil Edworthy 	return clk;
121360b8f0ddSPhil Edworthy }
121460b8f0ddSPhil Edworthy 
1215137f8a72SRob Herring #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
1216766e6a4eSGrant Likely struct clk *of_clk_get(struct device_node *np, int index);
1217766e6a4eSGrant Likely struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
1218766e6a4eSGrant Likely struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
1219766e6a4eSGrant Likely #else
of_clk_get(struct device_node * np,int index)1220766e6a4eSGrant Likely static inline struct clk *of_clk_get(struct device_node *np, int index)
1221766e6a4eSGrant Likely {
12229f1612d3SShawn Guo 	return ERR_PTR(-ENOENT);
1223766e6a4eSGrant Likely }
of_clk_get_by_name(struct device_node * np,const char * name)1224766e6a4eSGrant Likely static inline struct clk *of_clk_get_by_name(struct device_node *np,
1225766e6a4eSGrant Likely 					     const char *name)
1226766e6a4eSGrant Likely {
12279f1612d3SShawn Guo 	return ERR_PTR(-ENOENT);
1228766e6a4eSGrant Likely }
of_clk_get_from_provider(struct of_phandle_args * clkspec)1229428c9de5SGeert Uytterhoeven static inline struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
1230428c9de5SGeert Uytterhoeven {
1231428c9de5SGeert Uytterhoeven 	return ERR_PTR(-ENOENT);
1232428c9de5SGeert Uytterhoeven }
1233766e6a4eSGrant Likely #endif
1234766e6a4eSGrant Likely 
1235f8ce2547SRussell King #endif
1236