xref: /openbmc/linux/include/linux/clk.h (revision d2912cb15bdda8ba4a5dd73396ad62641af2f520)
1*d2912cb1SThomas 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 <mturquette@linaro.org>
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 /**
9586bcfa2eSMike Turquette  * 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 /**
10686bcfa2eSMike Turquette  * 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 /**
1135279fc40SBoris BREZILLON  * clk_get_accuracy - obtain the clock accuracy in ppb (parts per billion)
1145279fc40SBoris BREZILLON  *		      for a clock source.
1155279fc40SBoris BREZILLON  * @clk: clock source
1165279fc40SBoris BREZILLON  *
1175279fc40SBoris BREZILLON  * This gets the clock source accuracy expressed in ppb.
1185279fc40SBoris BREZILLON  * A perfect clock returns 0.
1195279fc40SBoris BREZILLON  */
1205279fc40SBoris BREZILLON long clk_get_accuracy(struct clk *clk);
1215279fc40SBoris BREZILLON 
122e59c5371SMike Turquette /**
123e59c5371SMike Turquette  * clk_set_phase - adjust the phase shift of a clock signal
124e59c5371SMike Turquette  * @clk: clock signal source
125e59c5371SMike Turquette  * @degrees: number of degrees the signal is shifted
126e59c5371SMike Turquette  *
127e59c5371SMike Turquette  * Shifts the phase of a clock signal by the specified degrees. Returns 0 on
128e59c5371SMike Turquette  * success, -EERROR otherwise.
129e59c5371SMike Turquette  */
130e59c5371SMike Turquette int clk_set_phase(struct clk *clk, int degrees);
131e59c5371SMike Turquette 
132e59c5371SMike Turquette /**
133e59c5371SMike Turquette  * clk_get_phase - return the phase shift of a clock signal
134e59c5371SMike Turquette  * @clk: clock signal source
135e59c5371SMike Turquette  *
136e59c5371SMike Turquette  * Returns the phase shift of a clock node in degrees, otherwise returns
137e59c5371SMike Turquette  * -EERROR.
138e59c5371SMike Turquette  */
139e59c5371SMike Turquette int clk_get_phase(struct clk *clk);
140e59c5371SMike Turquette 
1413d3801efSMichael Turquette /**
1429fba738aSJerome Brunet  * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal
1439fba738aSJerome Brunet  * @clk: clock signal source
1449fba738aSJerome Brunet  * @num: numerator of the duty cycle ratio to be applied
1459fba738aSJerome Brunet  * @den: denominator of the duty cycle ratio to be applied
1469fba738aSJerome Brunet  *
1479fba738aSJerome Brunet  * Adjust the duty cycle of a clock signal by the specified ratio. Returns 0 on
1489fba738aSJerome Brunet  * success, -EERROR otherwise.
1499fba738aSJerome Brunet  */
1509fba738aSJerome Brunet int clk_set_duty_cycle(struct clk *clk, unsigned int num, unsigned int den);
1519fba738aSJerome Brunet 
1529fba738aSJerome Brunet /**
1539fba738aSJerome Brunet  * clk_get_duty_cycle - return the duty cycle ratio of a clock signal
1549fba738aSJerome Brunet  * @clk: clock signal source
1559fba738aSJerome Brunet  * @scale: scaling factor to be applied to represent the ratio as an integer
1569fba738aSJerome Brunet  *
1579fba738aSJerome Brunet  * Returns the duty cycle ratio multiplied by the scale provided, otherwise
1589fba738aSJerome Brunet  * returns -EERROR.
1599fba738aSJerome Brunet  */
1609fba738aSJerome Brunet int clk_get_scaled_duty_cycle(struct clk *clk, unsigned int scale);
1619fba738aSJerome Brunet 
1629fba738aSJerome Brunet /**
1633d3801efSMichael Turquette  * clk_is_match - check if two clk's point to the same hardware clock
1643d3801efSMichael Turquette  * @p: clk compared against q
1653d3801efSMichael Turquette  * @q: clk compared against p
1663d3801efSMichael Turquette  *
1673d3801efSMichael Turquette  * Returns true if the two struct clk pointers both point to the same hardware
1680e056eb5Smchehab@s-opensource.com  * clock node. Put differently, returns true if @p and @q
1690e056eb5Smchehab@s-opensource.com  * share the same &struct clk_core object.
1703d3801efSMichael Turquette  *
1713d3801efSMichael Turquette  * Returns false otherwise. Note that two NULL clks are treated as matching.
1723d3801efSMichael Turquette  */
1733d3801efSMichael Turquette bool clk_is_match(const struct clk *p, const struct clk *q);
1743d3801efSMichael Turquette 
1755279fc40SBoris BREZILLON #else
1765279fc40SBoris BREZILLON 
177e81b87d2SKrzysztof Kozlowski static inline int clk_notifier_register(struct clk *clk,
178e81b87d2SKrzysztof Kozlowski 					struct notifier_block *nb)
179e81b87d2SKrzysztof Kozlowski {
180e81b87d2SKrzysztof Kozlowski 	return -ENOTSUPP;
181e81b87d2SKrzysztof Kozlowski }
182e81b87d2SKrzysztof Kozlowski 
183e81b87d2SKrzysztof Kozlowski static inline int clk_notifier_unregister(struct clk *clk,
184e81b87d2SKrzysztof Kozlowski 					  struct notifier_block *nb)
185e81b87d2SKrzysztof Kozlowski {
186e81b87d2SKrzysztof Kozlowski 	return -ENOTSUPP;
187e81b87d2SKrzysztof Kozlowski }
188e81b87d2SKrzysztof Kozlowski 
1895279fc40SBoris BREZILLON static inline long clk_get_accuracy(struct clk *clk)
1905279fc40SBoris BREZILLON {
1915279fc40SBoris BREZILLON 	return -ENOTSUPP;
1925279fc40SBoris BREZILLON }
1935279fc40SBoris BREZILLON 
194e59c5371SMike Turquette static inline long clk_set_phase(struct clk *clk, int phase)
195e59c5371SMike Turquette {
196e59c5371SMike Turquette 	return -ENOTSUPP;
197e59c5371SMike Turquette }
198e59c5371SMike Turquette 
199e59c5371SMike Turquette static inline long clk_get_phase(struct clk *clk)
200e59c5371SMike Turquette {
201e59c5371SMike Turquette 	return -ENOTSUPP;
202e59c5371SMike Turquette }
203e59c5371SMike Turquette 
2049fba738aSJerome Brunet static inline int clk_set_duty_cycle(struct clk *clk, unsigned int num,
2059fba738aSJerome Brunet 				     unsigned int den)
2069fba738aSJerome Brunet {
2079fba738aSJerome Brunet 	return -ENOTSUPP;
2089fba738aSJerome Brunet }
2099fba738aSJerome Brunet 
2109fba738aSJerome Brunet static inline unsigned int clk_get_scaled_duty_cycle(struct clk *clk,
2119fba738aSJerome Brunet 						     unsigned int scale)
2129fba738aSJerome Brunet {
2139fba738aSJerome Brunet 	return 0;
2149fba738aSJerome Brunet }
2159fba738aSJerome Brunet 
2163d3801efSMichael Turquette static inline bool clk_is_match(const struct clk *p, const struct clk *q)
2173d3801efSMichael Turquette {
2183d3801efSMichael Turquette 	return p == q;
2193d3801efSMichael Turquette }
2203d3801efSMichael Turquette 
2217e87aed9SMark Brown #endif
222b2476490SMike Turquette 
223f8ce2547SRussell King /**
22493abe8e4SViresh Kumar  * clk_prepare - prepare a clock source
22593abe8e4SViresh Kumar  * @clk: clock source
22693abe8e4SViresh Kumar  *
22793abe8e4SViresh Kumar  * This prepares the clock source for use.
22893abe8e4SViresh Kumar  *
22993abe8e4SViresh Kumar  * Must not be called from within atomic context.
23093abe8e4SViresh Kumar  */
23193abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE
23293abe8e4SViresh Kumar int clk_prepare(struct clk *clk);
233266e4e9dSDong Aisheng int __must_check clk_bulk_prepare(int num_clks,
234266e4e9dSDong Aisheng 				  const struct clk_bulk_data *clks);
23593abe8e4SViresh Kumar #else
23693abe8e4SViresh Kumar static inline int clk_prepare(struct clk *clk)
23793abe8e4SViresh Kumar {
23893abe8e4SViresh Kumar 	might_sleep();
23993abe8e4SViresh Kumar 	return 0;
24093abe8e4SViresh Kumar }
241266e4e9dSDong Aisheng 
2426e0d4ff4SDong Aisheng static inline int __must_check clk_bulk_prepare(int num_clks, struct clk_bulk_data *clks)
243266e4e9dSDong Aisheng {
244266e4e9dSDong Aisheng 	might_sleep();
245266e4e9dSDong Aisheng 	return 0;
246266e4e9dSDong Aisheng }
24793abe8e4SViresh Kumar #endif
24893abe8e4SViresh Kumar 
24993abe8e4SViresh Kumar /**
25093abe8e4SViresh Kumar  * clk_unprepare - undo preparation of a clock source
25193abe8e4SViresh Kumar  * @clk: clock source
25293abe8e4SViresh Kumar  *
25393abe8e4SViresh Kumar  * This undoes a previously prepared clock.  The caller must balance
25493abe8e4SViresh Kumar  * the number of prepare and unprepare calls.
25593abe8e4SViresh Kumar  *
25693abe8e4SViresh Kumar  * Must not be called from within atomic context.
25793abe8e4SViresh Kumar  */
25893abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE
25993abe8e4SViresh Kumar void clk_unprepare(struct clk *clk);
260266e4e9dSDong Aisheng void clk_bulk_unprepare(int num_clks, const struct clk_bulk_data *clks);
26193abe8e4SViresh Kumar #else
26293abe8e4SViresh Kumar static inline void clk_unprepare(struct clk *clk)
26393abe8e4SViresh Kumar {
26493abe8e4SViresh Kumar 	might_sleep();
26593abe8e4SViresh Kumar }
266266e4e9dSDong Aisheng static inline void clk_bulk_unprepare(int num_clks, struct clk_bulk_data *clks)
267266e4e9dSDong Aisheng {
268266e4e9dSDong Aisheng 	might_sleep();
269266e4e9dSDong Aisheng }
27093abe8e4SViresh Kumar #endif
27193abe8e4SViresh Kumar 
27293abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK
27393abe8e4SViresh Kumar /**
274f8ce2547SRussell King  * clk_get - lookup and obtain a reference to a clock producer.
275f8ce2547SRussell King  * @dev: device for clock "consumer"
276a58b3a4aSJan-Simon Möller  * @id: clock consumer ID
277f8ce2547SRussell King  *
278f8ce2547SRussell King  * Returns a struct clk corresponding to the clock producer, or
279f8ce2547SRussell King  * valid IS_ERR() condition containing errno.  The implementation
280f8ce2547SRussell King  * uses @dev and @id to determine the clock consumer, and thereby
281f8ce2547SRussell King  * the clock producer.  (IOW, @id may be identical strings, but
282f8ce2547SRussell King  * clk_get may return different clock producers depending on @dev.)
283f8ce2547SRussell King  *
284f8ce2547SRussell King  * Drivers must assume that the clock source is not enabled.
285f7ad160bSAlex Raimondi  *
286f7ad160bSAlex Raimondi  * clk_get should not be called from within interrupt context.
287f8ce2547SRussell King  */
288f8ce2547SRussell King struct clk *clk_get(struct device *dev, const char *id);
289f8ce2547SRussell King 
290f8ce2547SRussell King /**
291266e4e9dSDong Aisheng  * clk_bulk_get - lookup and obtain a number of references to clock producer.
292266e4e9dSDong Aisheng  * @dev: device for clock "consumer"
293266e4e9dSDong Aisheng  * @num_clks: the number of clk_bulk_data
294266e4e9dSDong Aisheng  * @clks: the clk_bulk_data table of consumer
295266e4e9dSDong Aisheng  *
296266e4e9dSDong Aisheng  * This helper function allows drivers to get several clk consumers in one
297266e4e9dSDong Aisheng  * operation. If any of the clk cannot be acquired then any clks
298266e4e9dSDong Aisheng  * that were obtained will be freed before returning to the caller.
299266e4e9dSDong Aisheng  *
300266e4e9dSDong Aisheng  * Returns 0 if all clocks specified in clk_bulk_data table are obtained
301266e4e9dSDong Aisheng  * successfully, or valid IS_ERR() condition containing errno.
302266e4e9dSDong Aisheng  * The implementation uses @dev and @clk_bulk_data.id to determine the
303266e4e9dSDong Aisheng  * clock consumer, and thereby the clock producer.
304266e4e9dSDong Aisheng  * The clock returned is stored in each @clk_bulk_data.clk field.
305266e4e9dSDong Aisheng  *
306266e4e9dSDong Aisheng  * Drivers must assume that the clock source is not enabled.
307266e4e9dSDong Aisheng  *
308266e4e9dSDong Aisheng  * clk_bulk_get should not be called from within interrupt context.
309266e4e9dSDong Aisheng  */
310266e4e9dSDong Aisheng int __must_check clk_bulk_get(struct device *dev, int num_clks,
311266e4e9dSDong Aisheng 			      struct clk_bulk_data *clks);
312616e45dfSDong Aisheng /**
313616e45dfSDong Aisheng  * clk_bulk_get_all - lookup and obtain all available references to clock
314616e45dfSDong Aisheng  *		      producer.
315616e45dfSDong Aisheng  * @dev: device for clock "consumer"
316616e45dfSDong Aisheng  * @clks: pointer to the clk_bulk_data table of consumer
317616e45dfSDong Aisheng  *
318616e45dfSDong Aisheng  * This helper function allows drivers to get all clk consumers in one
319616e45dfSDong Aisheng  * operation. If any of the clk cannot be acquired then any clks
320616e45dfSDong Aisheng  * that were obtained will be freed before returning to the caller.
321616e45dfSDong Aisheng  *
322616e45dfSDong Aisheng  * Returns a positive value for the number of clocks obtained while the
323616e45dfSDong Aisheng  * clock references are stored in the clk_bulk_data table in @clks field.
324616e45dfSDong Aisheng  * Returns 0 if there're none and a negative value if something failed.
325616e45dfSDong Aisheng  *
326616e45dfSDong Aisheng  * Drivers must assume that the clock source is not enabled.
327616e45dfSDong Aisheng  *
328616e45dfSDong Aisheng  * clk_bulk_get should not be called from within interrupt context.
329616e45dfSDong Aisheng  */
330616e45dfSDong Aisheng int __must_check clk_bulk_get_all(struct device *dev,
331616e45dfSDong Aisheng 				  struct clk_bulk_data **clks);
332266e4e9dSDong Aisheng /**
333618aee02SDong Aisheng  * devm_clk_bulk_get - managed get multiple clk consumers
334618aee02SDong Aisheng  * @dev: device for clock "consumer"
335618aee02SDong Aisheng  * @num_clks: the number of clk_bulk_data
336618aee02SDong Aisheng  * @clks: the clk_bulk_data table of consumer
337618aee02SDong Aisheng  *
338618aee02SDong Aisheng  * Return 0 on success, an errno on failure.
339618aee02SDong Aisheng  *
340618aee02SDong Aisheng  * This helper function allows drivers to get several clk
341618aee02SDong Aisheng  * consumers in one operation with management, the clks will
342618aee02SDong Aisheng  * automatically be freed when the device is unbound.
343618aee02SDong Aisheng  */
344618aee02SDong Aisheng int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
345618aee02SDong Aisheng 				   struct clk_bulk_data *clks);
346f08c2e28SDong Aisheng /**
347f08c2e28SDong Aisheng  * devm_clk_bulk_get_all - managed get multiple clk consumers
348f08c2e28SDong Aisheng  * @dev: device for clock "consumer"
349f08c2e28SDong Aisheng  * @clks: pointer to the clk_bulk_data table of consumer
350f08c2e28SDong Aisheng  *
351f08c2e28SDong Aisheng  * Returns a positive value for the number of clocks obtained while the
352f08c2e28SDong Aisheng  * clock references are stored in the clk_bulk_data table in @clks field.
353f08c2e28SDong Aisheng  * Returns 0 if there're none and a negative value if something failed.
354f08c2e28SDong Aisheng  *
355f08c2e28SDong Aisheng  * This helper function allows drivers to get several clk
356f08c2e28SDong Aisheng  * consumers in one operation with management, the clks will
357f08c2e28SDong Aisheng  * automatically be freed when the device is unbound.
358f08c2e28SDong Aisheng  */
359f08c2e28SDong Aisheng 
360f08c2e28SDong Aisheng int __must_check devm_clk_bulk_get_all(struct device *dev,
361f08c2e28SDong Aisheng 				       struct clk_bulk_data **clks);
362618aee02SDong Aisheng 
363618aee02SDong Aisheng /**
364a8a97db9SMark Brown  * devm_clk_get - lookup and obtain a managed reference to a clock producer.
365a8a97db9SMark Brown  * @dev: device for clock "consumer"
366a58b3a4aSJan-Simon Möller  * @id: clock consumer ID
367a8a97db9SMark Brown  *
368a8a97db9SMark Brown  * Returns a struct clk corresponding to the clock producer, or
369a8a97db9SMark Brown  * valid IS_ERR() condition containing errno.  The implementation
370a8a97db9SMark Brown  * uses @dev and @id to determine the clock consumer, and thereby
371a8a97db9SMark Brown  * the clock producer.  (IOW, @id may be identical strings, but
372a8a97db9SMark Brown  * clk_get may return different clock producers depending on @dev.)
373a8a97db9SMark Brown  *
374a8a97db9SMark Brown  * Drivers must assume that the clock source is not enabled.
375a8a97db9SMark Brown  *
376a8a97db9SMark Brown  * devm_clk_get should not be called from within interrupt context.
377a8a97db9SMark Brown  *
378a8a97db9SMark Brown  * The clock will automatically be freed when the device is unbound
379a8a97db9SMark Brown  * from the bus.
380a8a97db9SMark Brown  */
381a8a97db9SMark Brown struct clk *devm_clk_get(struct device *dev, const char *id);
382a8a97db9SMark Brown 
383a8a97db9SMark Brown /**
38460b8f0ddSPhil Edworthy  * devm_clk_get_optional - lookup and obtain a managed reference to an optional
38560b8f0ddSPhil Edworthy  *			   clock producer.
38660b8f0ddSPhil Edworthy  * @dev: device for clock "consumer"
38760b8f0ddSPhil Edworthy  * @id: clock consumer ID
38860b8f0ddSPhil Edworthy  *
38960b8f0ddSPhil Edworthy  * Behaves the same as devm_clk_get() except where there is no clock producer.
39060b8f0ddSPhil Edworthy  * In this case, instead of returning -ENOENT, the function returns NULL.
39160b8f0ddSPhil Edworthy  */
39260b8f0ddSPhil Edworthy struct clk *devm_clk_get_optional(struct device *dev, const char *id);
39360b8f0ddSPhil Edworthy 
39460b8f0ddSPhil Edworthy /**
39571a2f115SKuninori Morimoto  * devm_get_clk_from_child - lookup and obtain a managed reference to a
39671a2f115SKuninori Morimoto  *			     clock producer from child node.
39771a2f115SKuninori Morimoto  * @dev: device for clock "consumer"
39871a2f115SKuninori Morimoto  * @np: pointer to clock consumer node
39971a2f115SKuninori Morimoto  * @con_id: clock consumer ID
40071a2f115SKuninori Morimoto  *
40171a2f115SKuninori Morimoto  * This function parses the clocks, and uses them to look up the
40271a2f115SKuninori Morimoto  * struct clk from the registered list of clock providers by using
40371a2f115SKuninori Morimoto  * @np and @con_id
40471a2f115SKuninori Morimoto  *
40571a2f115SKuninori Morimoto  * The clock will automatically be freed when the device is unbound
40671a2f115SKuninori Morimoto  * from the bus.
40771a2f115SKuninori Morimoto  */
40871a2f115SKuninori Morimoto struct clk *devm_get_clk_from_child(struct device *dev,
40971a2f115SKuninori Morimoto 				    struct device_node *np, const char *con_id);
41055e9b8b7SJerome Brunet /**
41155e9b8b7SJerome Brunet  * clk_rate_exclusive_get - get exclusivity over the rate control of a
41255e9b8b7SJerome Brunet  *                          producer
41355e9b8b7SJerome Brunet  * @clk: clock source
41455e9b8b7SJerome Brunet  *
41555e9b8b7SJerome Brunet  * This function allows drivers to get exclusive control over the rate of a
41655e9b8b7SJerome Brunet  * provider. It prevents any other consumer to execute, even indirectly,
41755e9b8b7SJerome Brunet  * opereation which could alter the rate of the provider or cause glitches
41855e9b8b7SJerome Brunet  *
41955e9b8b7SJerome Brunet  * If exlusivity is claimed more than once on clock, even by the same driver,
42055e9b8b7SJerome Brunet  * the rate effectively gets locked as exclusivity can't be preempted.
42155e9b8b7SJerome Brunet  *
42255e9b8b7SJerome Brunet  * Must not be called from within atomic context.
42355e9b8b7SJerome Brunet  *
42455e9b8b7SJerome Brunet  * Returns success (0) or negative errno.
42555e9b8b7SJerome Brunet  */
42655e9b8b7SJerome Brunet int clk_rate_exclusive_get(struct clk *clk);
42755e9b8b7SJerome Brunet 
42855e9b8b7SJerome Brunet /**
42955e9b8b7SJerome Brunet  * clk_rate_exclusive_put - release exclusivity over the rate control of a
43055e9b8b7SJerome Brunet  *                          producer
43155e9b8b7SJerome Brunet  * @clk: clock source
43255e9b8b7SJerome Brunet  *
43355e9b8b7SJerome Brunet  * This function allows drivers to release the exclusivity it previously got
43455e9b8b7SJerome Brunet  * from clk_rate_exclusive_get()
43555e9b8b7SJerome Brunet  *
43655e9b8b7SJerome Brunet  * The caller must balance the number of clk_rate_exclusive_get() and
43755e9b8b7SJerome Brunet  * clk_rate_exclusive_put() calls.
43855e9b8b7SJerome Brunet  *
43955e9b8b7SJerome Brunet  * Must not be called from within atomic context.
44055e9b8b7SJerome Brunet  */
44155e9b8b7SJerome Brunet void clk_rate_exclusive_put(struct clk *clk);
44271a2f115SKuninori Morimoto 
44371a2f115SKuninori Morimoto /**
444f8ce2547SRussell King  * clk_enable - inform the system when the clock source should be running.
445f8ce2547SRussell King  * @clk: clock source
446f8ce2547SRussell King  *
447f8ce2547SRussell King  * If the clock can not be enabled/disabled, this should return success.
448f8ce2547SRussell King  *
44940d3e0f4SRussell King  * May be called from atomic contexts.
45040d3e0f4SRussell King  *
451f8ce2547SRussell King  * Returns success (0) or negative errno.
452f8ce2547SRussell King  */
453f8ce2547SRussell King int clk_enable(struct clk *clk);
454f8ce2547SRussell King 
455f8ce2547SRussell King /**
456266e4e9dSDong Aisheng  * clk_bulk_enable - inform the system when the set of clks should be running.
457266e4e9dSDong Aisheng  * @num_clks: the number of clk_bulk_data
458266e4e9dSDong Aisheng  * @clks: the clk_bulk_data table of consumer
459266e4e9dSDong Aisheng  *
460266e4e9dSDong Aisheng  * May be called from atomic contexts.
461266e4e9dSDong Aisheng  *
462266e4e9dSDong Aisheng  * Returns success (0) or negative errno.
463266e4e9dSDong Aisheng  */
464266e4e9dSDong Aisheng int __must_check clk_bulk_enable(int num_clks,
465266e4e9dSDong Aisheng 				 const struct clk_bulk_data *clks);
466266e4e9dSDong Aisheng 
467266e4e9dSDong Aisheng /**
468f8ce2547SRussell King  * clk_disable - inform the system when the clock source is no longer required.
469f8ce2547SRussell King  * @clk: clock source
470f8ce2547SRussell King  *
471f8ce2547SRussell King  * Inform the system that a clock source is no longer required by
472f8ce2547SRussell King  * a driver and may be shut down.
473f8ce2547SRussell King  *
47440d3e0f4SRussell King  * May be called from atomic contexts.
47540d3e0f4SRussell King  *
476f8ce2547SRussell King  * Implementation detail: if the clock source is shared between
477f8ce2547SRussell King  * multiple drivers, clk_enable() calls must be balanced by the
478f8ce2547SRussell King  * same number of clk_disable() calls for the clock source to be
479f8ce2547SRussell King  * disabled.
480f8ce2547SRussell King  */
481f8ce2547SRussell King void clk_disable(struct clk *clk);
482f8ce2547SRussell King 
483f8ce2547SRussell King /**
484266e4e9dSDong Aisheng  * clk_bulk_disable - inform the system when the set of clks is no
485266e4e9dSDong Aisheng  *		      longer required.
486266e4e9dSDong Aisheng  * @num_clks: the number of clk_bulk_data
487266e4e9dSDong Aisheng  * @clks: the clk_bulk_data table of consumer
488266e4e9dSDong Aisheng  *
489266e4e9dSDong Aisheng  * Inform the system that a set of clks is no longer required by
490266e4e9dSDong Aisheng  * a driver and may be shut down.
491266e4e9dSDong Aisheng  *
492266e4e9dSDong Aisheng  * May be called from atomic contexts.
493266e4e9dSDong Aisheng  *
494266e4e9dSDong Aisheng  * Implementation detail: if the set of clks is shared between
495266e4e9dSDong Aisheng  * multiple drivers, clk_bulk_enable() calls must be balanced by the
496266e4e9dSDong Aisheng  * same number of clk_bulk_disable() calls for the clock source to be
497266e4e9dSDong Aisheng  * disabled.
498266e4e9dSDong Aisheng  */
499266e4e9dSDong Aisheng void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks);
500266e4e9dSDong Aisheng 
501266e4e9dSDong Aisheng /**
502f8ce2547SRussell King  * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
503f8ce2547SRussell King  *		  This is only valid once the clock source has been enabled.
504f8ce2547SRussell King  * @clk: clock source
505f8ce2547SRussell King  */
506f8ce2547SRussell King unsigned long clk_get_rate(struct clk *clk);
507f8ce2547SRussell King 
508f8ce2547SRussell King /**
509f8ce2547SRussell King  * clk_put	- "free" the clock source
510f8ce2547SRussell King  * @clk: clock source
511f8ce2547SRussell King  *
512f8ce2547SRussell King  * Note: drivers must ensure that all clk_enable calls made on this
513f8ce2547SRussell King  * clock source are balanced by clk_disable calls prior to calling
514f8ce2547SRussell King  * this function.
515f7ad160bSAlex Raimondi  *
516f7ad160bSAlex Raimondi  * clk_put should not be called from within interrupt context.
517f8ce2547SRussell King  */
518f8ce2547SRussell King void clk_put(struct clk *clk);
519f8ce2547SRussell King 
520a8a97db9SMark Brown /**
521266e4e9dSDong Aisheng  * clk_bulk_put	- "free" the clock source
522266e4e9dSDong Aisheng  * @num_clks: the number of clk_bulk_data
523266e4e9dSDong Aisheng  * @clks: the clk_bulk_data table of consumer
524266e4e9dSDong Aisheng  *
525266e4e9dSDong Aisheng  * Note: drivers must ensure that all clk_bulk_enable calls made on this
526266e4e9dSDong Aisheng  * clock source are balanced by clk_bulk_disable calls prior to calling
527266e4e9dSDong Aisheng  * this function.
528266e4e9dSDong Aisheng  *
529266e4e9dSDong Aisheng  * clk_bulk_put should not be called from within interrupt context.
530266e4e9dSDong Aisheng  */
531266e4e9dSDong Aisheng void clk_bulk_put(int num_clks, struct clk_bulk_data *clks);
532266e4e9dSDong Aisheng 
533266e4e9dSDong Aisheng /**
534616e45dfSDong Aisheng  * clk_bulk_put_all - "free" all the clock source
535616e45dfSDong Aisheng  * @num_clks: the number of clk_bulk_data
536616e45dfSDong Aisheng  * @clks: the clk_bulk_data table of consumer
537616e45dfSDong Aisheng  *
538616e45dfSDong Aisheng  * Note: drivers must ensure that all clk_bulk_enable calls made on this
539616e45dfSDong Aisheng  * clock source are balanced by clk_bulk_disable calls prior to calling
540616e45dfSDong Aisheng  * this function.
541616e45dfSDong Aisheng  *
542616e45dfSDong Aisheng  * clk_bulk_put_all should not be called from within interrupt context.
543616e45dfSDong Aisheng  */
544616e45dfSDong Aisheng void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks);
545616e45dfSDong Aisheng 
546616e45dfSDong Aisheng /**
547a8a97db9SMark Brown  * devm_clk_put	- "free" a managed clock source
548da3dae54SMasanari Iida  * @dev: device used to acquire the clock
549a8a97db9SMark Brown  * @clk: clock source acquired with devm_clk_get()
550a8a97db9SMark Brown  *
551a8a97db9SMark Brown  * Note: drivers must ensure that all clk_enable calls made on this
552a8a97db9SMark Brown  * clock source are balanced by clk_disable calls prior to calling
553a8a97db9SMark Brown  * this function.
554a8a97db9SMark Brown  *
555a8a97db9SMark Brown  * clk_put should not be called from within interrupt context.
556a8a97db9SMark Brown  */
557a8a97db9SMark Brown void devm_clk_put(struct device *dev, struct clk *clk);
558f8ce2547SRussell King 
559f8ce2547SRussell King /*
560f8ce2547SRussell King  * The remaining APIs are optional for machine class support.
561f8ce2547SRussell King  */
562f8ce2547SRussell King 
563f8ce2547SRussell King 
564f8ce2547SRussell King /**
565f8ce2547SRussell King  * clk_round_rate - adjust a rate to the exact rate a clock can provide
566f8ce2547SRussell King  * @clk: clock source
567f8ce2547SRussell King  * @rate: desired clock rate in Hz
568f8ce2547SRussell King  *
569d2d14a77SRussell King  * This answers the question "if I were to pass @rate to clk_set_rate(),
570d2d14a77SRussell King  * what clock rate would I end up with?" without changing the hardware
571d2d14a77SRussell King  * in any way.  In other words:
572d2d14a77SRussell King  *
573d2d14a77SRussell King  *   rate = clk_round_rate(clk, r);
574d2d14a77SRussell King  *
575d2d14a77SRussell King  * and:
576d2d14a77SRussell King  *
577d2d14a77SRussell King  *   clk_set_rate(clk, r);
578d2d14a77SRussell King  *   rate = clk_get_rate(clk);
579d2d14a77SRussell King  *
580d2d14a77SRussell King  * are equivalent except the former does not modify the clock hardware
581d2d14a77SRussell King  * in any way.
582d2d14a77SRussell King  *
583f8ce2547SRussell King  * Returns rounded clock rate in Hz, or negative errno.
584f8ce2547SRussell King  */
585f8ce2547SRussell King long clk_round_rate(struct clk *clk, unsigned long rate);
586f8ce2547SRussell King 
587f8ce2547SRussell King /**
588f8ce2547SRussell King  * clk_set_rate - set the clock rate for a clock source
589f8ce2547SRussell King  * @clk: clock source
590f8ce2547SRussell King  * @rate: desired clock rate in Hz
591f8ce2547SRussell King  *
592f8ce2547SRussell King  * Returns success (0) or negative errno.
593f8ce2547SRussell King  */
594f8ce2547SRussell King int clk_set_rate(struct clk *clk, unsigned long rate);
595f8ce2547SRussell King 
596f8ce2547SRussell King /**
59755e9b8b7SJerome Brunet  * clk_set_rate_exclusive- set the clock rate and claim exclusivity over
59855e9b8b7SJerome Brunet  *                         clock source
59955e9b8b7SJerome Brunet  * @clk: clock source
60055e9b8b7SJerome Brunet  * @rate: desired clock rate in Hz
60155e9b8b7SJerome Brunet  *
60255e9b8b7SJerome Brunet  * This helper function allows drivers to atomically set the rate of a producer
60355e9b8b7SJerome Brunet  * and claim exclusivity over the rate control of the producer.
60455e9b8b7SJerome Brunet  *
60555e9b8b7SJerome Brunet  * It is essentially a combination of clk_set_rate() and
60655e9b8b7SJerome Brunet  * clk_rate_exclusite_get(). Caller must balance this call with a call to
60755e9b8b7SJerome Brunet  * clk_rate_exclusive_put()
60855e9b8b7SJerome Brunet  *
60955e9b8b7SJerome Brunet  * Returns success (0) or negative errno.
61055e9b8b7SJerome Brunet  */
61155e9b8b7SJerome Brunet int clk_set_rate_exclusive(struct clk *clk, unsigned long rate);
61255e9b8b7SJerome Brunet 
61355e9b8b7SJerome Brunet /**
6144e88f3deSThierry Reding  * clk_has_parent - check if a clock is a possible parent for another
6154e88f3deSThierry Reding  * @clk: clock source
6164e88f3deSThierry Reding  * @parent: parent clock source
6174e88f3deSThierry Reding  *
6184e88f3deSThierry Reding  * This function can be used in drivers that need to check that a clock can be
6194e88f3deSThierry Reding  * the parent of another without actually changing the parent.
6204e88f3deSThierry Reding  *
6214e88f3deSThierry Reding  * Returns true if @parent is a possible parent for @clk, false otherwise.
6224e88f3deSThierry Reding  */
6234e88f3deSThierry Reding bool clk_has_parent(struct clk *clk, struct clk *parent);
6244e88f3deSThierry Reding 
6254e88f3deSThierry Reding /**
6261c8e6004STomeu Vizoso  * clk_set_rate_range - set a rate range for a clock source
6271c8e6004STomeu Vizoso  * @clk: clock source
6281c8e6004STomeu Vizoso  * @min: desired minimum clock rate in Hz, inclusive
6291c8e6004STomeu Vizoso  * @max: desired maximum clock rate in Hz, inclusive
6301c8e6004STomeu Vizoso  *
6311c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
6321c8e6004STomeu Vizoso  */
6331c8e6004STomeu Vizoso int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max);
6341c8e6004STomeu Vizoso 
6351c8e6004STomeu Vizoso /**
6361c8e6004STomeu Vizoso  * clk_set_min_rate - set a minimum clock rate for a clock source
6371c8e6004STomeu Vizoso  * @clk: clock source
6381c8e6004STomeu Vizoso  * @rate: desired minimum clock rate in Hz, inclusive
6391c8e6004STomeu Vizoso  *
6401c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
6411c8e6004STomeu Vizoso  */
6421c8e6004STomeu Vizoso int clk_set_min_rate(struct clk *clk, unsigned long rate);
6431c8e6004STomeu Vizoso 
6441c8e6004STomeu Vizoso /**
6451c8e6004STomeu Vizoso  * clk_set_max_rate - set a maximum clock rate for a clock source
6461c8e6004STomeu Vizoso  * @clk: clock source
6471c8e6004STomeu Vizoso  * @rate: desired maximum clock rate in Hz, inclusive
6481c8e6004STomeu Vizoso  *
6491c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
6501c8e6004STomeu Vizoso  */
6511c8e6004STomeu Vizoso int clk_set_max_rate(struct clk *clk, unsigned long rate);
6521c8e6004STomeu Vizoso 
6531c8e6004STomeu Vizoso /**
654f8ce2547SRussell King  * clk_set_parent - set the parent clock source for this clock
655f8ce2547SRussell King  * @clk: clock source
656f8ce2547SRussell King  * @parent: parent clock source
657f8ce2547SRussell King  *
658f8ce2547SRussell King  * Returns success (0) or negative errno.
659f8ce2547SRussell King  */
660f8ce2547SRussell King int clk_set_parent(struct clk *clk, struct clk *parent);
661f8ce2547SRussell King 
662f8ce2547SRussell King /**
663f8ce2547SRussell King  * clk_get_parent - get the parent clock source for this clock
664f8ce2547SRussell King  * @clk: clock source
665f8ce2547SRussell King  *
666f8ce2547SRussell King  * Returns struct clk corresponding to parent clock source, or
667f8ce2547SRussell King  * valid IS_ERR() condition containing errno.
668f8ce2547SRussell King  */
669f8ce2547SRussell King struct clk *clk_get_parent(struct clk *clk);
670f8ce2547SRussell King 
67105fd8e73SSascha Hauer /**
67205fd8e73SSascha Hauer  * clk_get_sys - get a clock based upon the device name
67305fd8e73SSascha Hauer  * @dev_id: device name
67405fd8e73SSascha Hauer  * @con_id: connection ID
67505fd8e73SSascha Hauer  *
67605fd8e73SSascha Hauer  * Returns a struct clk corresponding to the clock producer, or
67705fd8e73SSascha Hauer  * valid IS_ERR() condition containing errno.  The implementation
67805fd8e73SSascha Hauer  * uses @dev_id and @con_id to determine the clock consumer, and
67905fd8e73SSascha Hauer  * thereby the clock producer. In contrast to clk_get() this function
68005fd8e73SSascha Hauer  * takes the device name instead of the device itself for identification.
68105fd8e73SSascha Hauer  *
68205fd8e73SSascha Hauer  * Drivers must assume that the clock source is not enabled.
68305fd8e73SSascha Hauer  *
68405fd8e73SSascha Hauer  * clk_get_sys should not be called from within interrupt context.
68505fd8e73SSascha Hauer  */
68605fd8e73SSascha Hauer struct clk *clk_get_sys(const char *dev_id, const char *con_id);
68705fd8e73SSascha Hauer 
6888b95d1ceSRuss Dill /**
6898b95d1ceSRuss Dill  * clk_save_context - save clock context for poweroff
6908b95d1ceSRuss Dill  *
6918b95d1ceSRuss Dill  * Saves the context of the clock register for powerstates in which the
6928b95d1ceSRuss Dill  * contents of the registers will be lost. Occurs deep within the suspend
6938b95d1ceSRuss Dill  * code so locking is not necessary.
6948b95d1ceSRuss Dill  */
6958b95d1ceSRuss Dill int clk_save_context(void);
6968b95d1ceSRuss Dill 
6978b95d1ceSRuss Dill /**
6988b95d1ceSRuss Dill  * clk_restore_context - restore clock context after poweroff
6998b95d1ceSRuss Dill  *
7008b95d1ceSRuss Dill  * This occurs with all clocks enabled. Occurs deep within the resume code
7018b95d1ceSRuss Dill  * so locking is not necessary.
7028b95d1ceSRuss Dill  */
7038b95d1ceSRuss Dill void clk_restore_context(void);
7048b95d1ceSRuss Dill 
70593abe8e4SViresh Kumar #else /* !CONFIG_HAVE_CLK */
70693abe8e4SViresh Kumar 
70793abe8e4SViresh Kumar static inline struct clk *clk_get(struct device *dev, const char *id)
70893abe8e4SViresh Kumar {
70993abe8e4SViresh Kumar 	return NULL;
71093abe8e4SViresh Kumar }
71193abe8e4SViresh Kumar 
7126e0d4ff4SDong Aisheng static inline int __must_check clk_bulk_get(struct device *dev, int num_clks,
713266e4e9dSDong Aisheng 					    struct clk_bulk_data *clks)
714266e4e9dSDong Aisheng {
715266e4e9dSDong Aisheng 	return 0;
716266e4e9dSDong Aisheng }
717266e4e9dSDong Aisheng 
718616e45dfSDong Aisheng static inline int __must_check clk_bulk_get_all(struct device *dev,
719616e45dfSDong Aisheng 					 struct clk_bulk_data **clks)
720616e45dfSDong Aisheng {
721616e45dfSDong Aisheng 	return 0;
722616e45dfSDong Aisheng }
723616e45dfSDong Aisheng 
72493abe8e4SViresh Kumar static inline struct clk *devm_clk_get(struct device *dev, const char *id)
72593abe8e4SViresh Kumar {
72693abe8e4SViresh Kumar 	return NULL;
72793abe8e4SViresh Kumar }
72893abe8e4SViresh Kumar 
72960b8f0ddSPhil Edworthy static inline struct clk *devm_clk_get_optional(struct device *dev,
73060b8f0ddSPhil Edworthy 						const char *id)
73160b8f0ddSPhil Edworthy {
73260b8f0ddSPhil Edworthy 	return NULL;
73360b8f0ddSPhil Edworthy }
73460b8f0ddSPhil Edworthy 
7356e0d4ff4SDong Aisheng static inline int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
736618aee02SDong Aisheng 						 struct clk_bulk_data *clks)
737618aee02SDong Aisheng {
738618aee02SDong Aisheng 	return 0;
739618aee02SDong Aisheng }
740618aee02SDong Aisheng 
741f08c2e28SDong Aisheng static inline int __must_check devm_clk_bulk_get_all(struct device *dev,
742f08c2e28SDong Aisheng 						     struct clk_bulk_data **clks)
743f08c2e28SDong Aisheng {
744f08c2e28SDong Aisheng 
745f08c2e28SDong Aisheng 	return 0;
746f08c2e28SDong Aisheng }
747f08c2e28SDong Aisheng 
74871a2f115SKuninori Morimoto static inline struct clk *devm_get_clk_from_child(struct device *dev,
74971a2f115SKuninori Morimoto 				struct device_node *np, const char *con_id)
75071a2f115SKuninori Morimoto {
75171a2f115SKuninori Morimoto 	return NULL;
75271a2f115SKuninori Morimoto }
75371a2f115SKuninori Morimoto 
75493abe8e4SViresh Kumar static inline void clk_put(struct clk *clk) {}
75593abe8e4SViresh Kumar 
756266e4e9dSDong Aisheng static inline void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) {}
757266e4e9dSDong Aisheng 
758616e45dfSDong Aisheng static inline void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks) {}
759616e45dfSDong Aisheng 
76093abe8e4SViresh Kumar static inline void devm_clk_put(struct device *dev, struct clk *clk) {}
76193abe8e4SViresh Kumar 
76255e9b8b7SJerome Brunet 
76355e9b8b7SJerome Brunet static inline int clk_rate_exclusive_get(struct clk *clk)
76455e9b8b7SJerome Brunet {
76555e9b8b7SJerome Brunet 	return 0;
76655e9b8b7SJerome Brunet }
76755e9b8b7SJerome Brunet 
76855e9b8b7SJerome Brunet static inline void clk_rate_exclusive_put(struct clk *clk) {}
76955e9b8b7SJerome Brunet 
77093abe8e4SViresh Kumar static inline int clk_enable(struct clk *clk)
77193abe8e4SViresh Kumar {
77293abe8e4SViresh Kumar 	return 0;
77393abe8e4SViresh Kumar }
77493abe8e4SViresh Kumar 
7756e0d4ff4SDong Aisheng static inline int __must_check clk_bulk_enable(int num_clks, struct clk_bulk_data *clks)
776266e4e9dSDong Aisheng {
777266e4e9dSDong Aisheng 	return 0;
778266e4e9dSDong Aisheng }
779266e4e9dSDong Aisheng 
78093abe8e4SViresh Kumar static inline void clk_disable(struct clk *clk) {}
78193abe8e4SViresh Kumar 
782266e4e9dSDong Aisheng 
783266e4e9dSDong Aisheng static inline void clk_bulk_disable(int num_clks,
784266e4e9dSDong Aisheng 				    struct clk_bulk_data *clks) {}
785266e4e9dSDong Aisheng 
78693abe8e4SViresh Kumar static inline unsigned long clk_get_rate(struct clk *clk)
78793abe8e4SViresh Kumar {
78893abe8e4SViresh Kumar 	return 0;
78993abe8e4SViresh Kumar }
79093abe8e4SViresh Kumar 
79193abe8e4SViresh Kumar static inline int clk_set_rate(struct clk *clk, unsigned long rate)
79293abe8e4SViresh Kumar {
79393abe8e4SViresh Kumar 	return 0;
79493abe8e4SViresh Kumar }
79593abe8e4SViresh Kumar 
79655e9b8b7SJerome Brunet static inline int clk_set_rate_exclusive(struct clk *clk, unsigned long rate)
79755e9b8b7SJerome Brunet {
79855e9b8b7SJerome Brunet 	return 0;
79955e9b8b7SJerome Brunet }
80055e9b8b7SJerome Brunet 
80193abe8e4SViresh Kumar static inline long clk_round_rate(struct clk *clk, unsigned long rate)
80293abe8e4SViresh Kumar {
80393abe8e4SViresh Kumar 	return 0;
80493abe8e4SViresh Kumar }
80593abe8e4SViresh Kumar 
8064e88f3deSThierry Reding static inline bool clk_has_parent(struct clk *clk, struct clk *parent)
8074e88f3deSThierry Reding {
8084e88f3deSThierry Reding 	return true;
8094e88f3deSThierry Reding }
8104e88f3deSThierry Reding 
811b88c9f41SDmitry Osipenko static inline int clk_set_rate_range(struct clk *clk, unsigned long min,
812b88c9f41SDmitry Osipenko 				     unsigned long max)
813b88c9f41SDmitry Osipenko {
814b88c9f41SDmitry Osipenko 	return 0;
815b88c9f41SDmitry Osipenko }
816b88c9f41SDmitry Osipenko 
817b88c9f41SDmitry Osipenko static inline int clk_set_min_rate(struct clk *clk, unsigned long rate)
818b88c9f41SDmitry Osipenko {
819b88c9f41SDmitry Osipenko 	return 0;
820b88c9f41SDmitry Osipenko }
821b88c9f41SDmitry Osipenko 
822b88c9f41SDmitry Osipenko static inline int clk_set_max_rate(struct clk *clk, unsigned long rate)
823b88c9f41SDmitry Osipenko {
824b88c9f41SDmitry Osipenko 	return 0;
825b88c9f41SDmitry Osipenko }
826b88c9f41SDmitry Osipenko 
82793abe8e4SViresh Kumar static inline int clk_set_parent(struct clk *clk, struct clk *parent)
82893abe8e4SViresh Kumar {
82993abe8e4SViresh Kumar 	return 0;
83093abe8e4SViresh Kumar }
83193abe8e4SViresh Kumar 
83293abe8e4SViresh Kumar static inline struct clk *clk_get_parent(struct clk *clk)
83393abe8e4SViresh Kumar {
83493abe8e4SViresh Kumar 	return NULL;
83593abe8e4SViresh Kumar }
83693abe8e4SViresh Kumar 
837b81ea968SDaniel Lezcano static inline struct clk *clk_get_sys(const char *dev_id, const char *con_id)
838b81ea968SDaniel Lezcano {
839b81ea968SDaniel Lezcano 	return NULL;
840b81ea968SDaniel Lezcano }
8418b95d1ceSRuss Dill 
8428b95d1ceSRuss Dill static inline int clk_save_context(void)
8438b95d1ceSRuss Dill {
8448b95d1ceSRuss Dill 	return 0;
8458b95d1ceSRuss Dill }
8468b95d1ceSRuss Dill 
8478b95d1ceSRuss Dill static inline void clk_restore_context(void) {}
8488b95d1ceSRuss Dill 
84993abe8e4SViresh Kumar #endif
85093abe8e4SViresh Kumar 
85193abe8e4SViresh Kumar /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
85293abe8e4SViresh Kumar static inline int clk_prepare_enable(struct clk *clk)
85393abe8e4SViresh Kumar {
85493abe8e4SViresh Kumar 	int ret;
85593abe8e4SViresh Kumar 
85693abe8e4SViresh Kumar 	ret = clk_prepare(clk);
85793abe8e4SViresh Kumar 	if (ret)
85893abe8e4SViresh Kumar 		return ret;
85993abe8e4SViresh Kumar 	ret = clk_enable(clk);
86093abe8e4SViresh Kumar 	if (ret)
86193abe8e4SViresh Kumar 		clk_unprepare(clk);
86293abe8e4SViresh Kumar 
86393abe8e4SViresh Kumar 	return ret;
86493abe8e4SViresh Kumar }
86593abe8e4SViresh Kumar 
86693abe8e4SViresh Kumar /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */
86793abe8e4SViresh Kumar static inline void clk_disable_unprepare(struct clk *clk)
86893abe8e4SViresh Kumar {
86993abe8e4SViresh Kumar 	clk_disable(clk);
87093abe8e4SViresh Kumar 	clk_unprepare(clk);
87193abe8e4SViresh Kumar }
87293abe8e4SViresh Kumar 
8736e0d4ff4SDong Aisheng static inline int __must_check clk_bulk_prepare_enable(int num_clks,
8743c48d86cSBjorn Andersson 					struct clk_bulk_data *clks)
8753c48d86cSBjorn Andersson {
8763c48d86cSBjorn Andersson 	int ret;
8773c48d86cSBjorn Andersson 
8783c48d86cSBjorn Andersson 	ret = clk_bulk_prepare(num_clks, clks);
8793c48d86cSBjorn Andersson 	if (ret)
8803c48d86cSBjorn Andersson 		return ret;
8813c48d86cSBjorn Andersson 	ret = clk_bulk_enable(num_clks, clks);
8823c48d86cSBjorn Andersson 	if (ret)
8833c48d86cSBjorn Andersson 		clk_bulk_unprepare(num_clks, clks);
8843c48d86cSBjorn Andersson 
8853c48d86cSBjorn Andersson 	return ret;
8863c48d86cSBjorn Andersson }
8873c48d86cSBjorn Andersson 
8883c48d86cSBjorn Andersson static inline void clk_bulk_disable_unprepare(int num_clks,
8893c48d86cSBjorn Andersson 					      struct clk_bulk_data *clks)
8903c48d86cSBjorn Andersson {
8913c48d86cSBjorn Andersson 	clk_bulk_disable(num_clks, clks);
8923c48d86cSBjorn Andersson 	clk_bulk_unprepare(num_clks, clks);
8933c48d86cSBjorn Andersson }
8943c48d86cSBjorn Andersson 
89560b8f0ddSPhil Edworthy /**
89660b8f0ddSPhil Edworthy  * clk_get_optional - lookup and obtain a reference to an optional clock
89760b8f0ddSPhil Edworthy  *		      producer.
89860b8f0ddSPhil Edworthy  * @dev: device for clock "consumer"
89960b8f0ddSPhil Edworthy  * @id: clock consumer ID
90060b8f0ddSPhil Edworthy  *
90160b8f0ddSPhil Edworthy  * Behaves the same as clk_get() except where there is no clock producer. In
90260b8f0ddSPhil Edworthy  * this case, instead of returning -ENOENT, the function returns NULL.
90360b8f0ddSPhil Edworthy  */
90460b8f0ddSPhil Edworthy static inline struct clk *clk_get_optional(struct device *dev, const char *id)
90560b8f0ddSPhil Edworthy {
90660b8f0ddSPhil Edworthy 	struct clk *clk = clk_get(dev, id);
90760b8f0ddSPhil Edworthy 
90860b8f0ddSPhil Edworthy 	if (clk == ERR_PTR(-ENOENT))
90960b8f0ddSPhil Edworthy 		return NULL;
91060b8f0ddSPhil Edworthy 
91160b8f0ddSPhil Edworthy 	return clk;
91260b8f0ddSPhil Edworthy }
91360b8f0ddSPhil Edworthy 
914137f8a72SRob Herring #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
915766e6a4eSGrant Likely struct clk *of_clk_get(struct device_node *np, int index);
916766e6a4eSGrant Likely struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
917766e6a4eSGrant Likely struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
918766e6a4eSGrant Likely #else
919766e6a4eSGrant Likely static inline struct clk *of_clk_get(struct device_node *np, int index)
920766e6a4eSGrant Likely {
9219f1612d3SShawn Guo 	return ERR_PTR(-ENOENT);
922766e6a4eSGrant Likely }
923766e6a4eSGrant Likely static inline struct clk *of_clk_get_by_name(struct device_node *np,
924766e6a4eSGrant Likely 					     const char *name)
925766e6a4eSGrant Likely {
9269f1612d3SShawn Guo 	return ERR_PTR(-ENOENT);
927766e6a4eSGrant Likely }
928428c9de5SGeert Uytterhoeven static inline struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
929428c9de5SGeert Uytterhoeven {
930428c9de5SGeert Uytterhoeven 	return ERR_PTR(-ENOENT);
931428c9de5SGeert Uytterhoeven }
932766e6a4eSGrant Likely #endif
933766e6a4eSGrant Likely 
934f8ce2547SRussell King #endif
935