xref: /openbmc/linux/include/linux/clk.h (revision 2f25528e4edddc6eddd42c8d41c9c9e341c8b9da)
1f8ce2547SRussell King /*
2f8ce2547SRussell King  *  linux/include/linux/clk.h
3f8ce2547SRussell King  *
4f8ce2547SRussell King  *  Copyright (C) 2004 ARM Limited.
5f8ce2547SRussell King  *  Written by Deep Blue Solutions Limited.
6b2476490SMike Turquette  *  Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
7f8ce2547SRussell King  *
8f8ce2547SRussell King  * This program is free software; you can redistribute it and/or modify
9f8ce2547SRussell King  * it under the terms of the GNU General Public License version 2 as
10f8ce2547SRussell King  * published by the Free Software Foundation.
11f8ce2547SRussell King  */
12686f8c5dSTodd Poynor #ifndef __LINUX_CLK_H
13686f8c5dSTodd Poynor #define __LINUX_CLK_H
14f8ce2547SRussell King 
159f1612d3SShawn Guo #include <linux/err.h>
1640d3e0f4SRussell King #include <linux/kernel.h>
17b2476490SMike Turquette #include <linux/notifier.h>
1840d3e0f4SRussell King 
19f8ce2547SRussell King struct device;
20f8ce2547SRussell King struct clk;
2171a2f115SKuninori Morimoto struct device_node;
2271a2f115SKuninori Morimoto struct of_phandle_args;
23f8ce2547SRussell King 
24b2476490SMike Turquette /**
25b2476490SMike Turquette  * DOC: clk notifier callback types
26b2476490SMike Turquette  *
27b2476490SMike Turquette  * PRE_RATE_CHANGE - called immediately before the clk rate is changed,
28b2476490SMike Turquette  *     to indicate that the rate change will proceed.  Drivers must
29b2476490SMike Turquette  *     immediately terminate any operations that will be affected by the
30fb72a059SSoren Brinkmann  *     rate change.  Callbacks may either return NOTIFY_DONE, NOTIFY_OK,
31fb72a059SSoren Brinkmann  *     NOTIFY_STOP or NOTIFY_BAD.
32b2476490SMike Turquette  *
33b2476490SMike Turquette  * ABORT_RATE_CHANGE: called if the rate change failed for some reason
34b2476490SMike Turquette  *     after PRE_RATE_CHANGE.  In this case, all registered notifiers on
35b2476490SMike Turquette  *     the clk will be called with ABORT_RATE_CHANGE. Callbacks must
36fb72a059SSoren Brinkmann  *     always return NOTIFY_DONE or NOTIFY_OK.
37b2476490SMike Turquette  *
38b2476490SMike Turquette  * POST_RATE_CHANGE - called after the clk rate change has successfully
39fb72a059SSoren Brinkmann  *     completed.  Callbacks must always return NOTIFY_DONE or NOTIFY_OK.
40b2476490SMike Turquette  *
41b2476490SMike Turquette  */
42b2476490SMike Turquette #define PRE_RATE_CHANGE			BIT(0)
43b2476490SMike Turquette #define POST_RATE_CHANGE		BIT(1)
44b2476490SMike Turquette #define ABORT_RATE_CHANGE		BIT(2)
45b2476490SMike Turquette 
46b2476490SMike Turquette /**
47b2476490SMike Turquette  * struct clk_notifier - associate a clk with a notifier
48b2476490SMike Turquette  * @clk: struct clk * to associate the notifier with
49b2476490SMike Turquette  * @notifier_head: a blocking_notifier_head for this clk
50b2476490SMike Turquette  * @node: linked list pointers
51b2476490SMike Turquette  *
52b2476490SMike Turquette  * A list of struct clk_notifier is maintained by the notifier code.
53b2476490SMike Turquette  * An entry is created whenever code registers the first notifier on a
54b2476490SMike Turquette  * particular @clk.  Future notifiers on that @clk are added to the
55b2476490SMike Turquette  * @notifier_head.
56b2476490SMike Turquette  */
57b2476490SMike Turquette struct clk_notifier {
58b2476490SMike Turquette 	struct clk			*clk;
59b2476490SMike Turquette 	struct srcu_notifier_head	notifier_head;
60b2476490SMike Turquette 	struct list_head		node;
61b2476490SMike Turquette };
62b2476490SMike Turquette 
63b2476490SMike Turquette /**
64b2476490SMike Turquette  * struct clk_notifier_data - rate data to pass to the notifier callback
65b2476490SMike Turquette  * @clk: struct clk * being changed
66b2476490SMike Turquette  * @old_rate: previous rate of this clk
67b2476490SMike Turquette  * @new_rate: new rate of this clk
68b2476490SMike Turquette  *
69b2476490SMike Turquette  * For a pre-notifier, old_rate is the clk's rate before this rate
70b2476490SMike Turquette  * change, and new_rate is what the rate will be in the future.  For a
71b2476490SMike Turquette  * post-notifier, old_rate and new_rate are both set to the clk's
72b2476490SMike Turquette  * current rate (this was done to optimize the implementation).
73b2476490SMike Turquette  */
74b2476490SMike Turquette struct clk_notifier_data {
75b2476490SMike Turquette 	struct clk		*clk;
76b2476490SMike Turquette 	unsigned long		old_rate;
77b2476490SMike Turquette 	unsigned long		new_rate;
78b2476490SMike Turquette };
79b2476490SMike Turquette 
80266e4e9dSDong Aisheng /**
81266e4e9dSDong Aisheng  * struct clk_bulk_data - Data used for bulk clk operations.
82266e4e9dSDong Aisheng  *
83266e4e9dSDong Aisheng  * @id: clock consumer ID
84266e4e9dSDong Aisheng  * @clk: struct clk * to store the associated clock
85266e4e9dSDong Aisheng  *
86266e4e9dSDong Aisheng  * The CLK APIs provide a series of clk_bulk_() API calls as
87266e4e9dSDong Aisheng  * a convenience to consumers which require multiple clks.  This
88266e4e9dSDong Aisheng  * structure is used to manage data for these calls.
89266e4e9dSDong Aisheng  */
90266e4e9dSDong Aisheng struct clk_bulk_data {
91266e4e9dSDong Aisheng 	const char		*id;
92266e4e9dSDong Aisheng 	struct clk		*clk;
93266e4e9dSDong Aisheng };
94266e4e9dSDong Aisheng 
95e81b87d2SKrzysztof Kozlowski #ifdef CONFIG_COMMON_CLK
96e81b87d2SKrzysztof Kozlowski 
9786bcfa2eSMike Turquette /**
9886bcfa2eSMike Turquette  * clk_notifier_register: register a clock rate-change notifier callback
9986bcfa2eSMike Turquette  * @clk: clock whose rate we are interested in
10086bcfa2eSMike Turquette  * @nb: notifier block with callback function pointer
10186bcfa2eSMike Turquette  *
10286bcfa2eSMike Turquette  * ProTip: debugging across notifier chains can be frustrating. Make sure that
10386bcfa2eSMike Turquette  * your notifier callback function prints a nice big warning in case of
10486bcfa2eSMike Turquette  * failure.
10586bcfa2eSMike Turquette  */
106b2476490SMike Turquette int clk_notifier_register(struct clk *clk, struct notifier_block *nb);
107b2476490SMike Turquette 
10886bcfa2eSMike Turquette /**
10986bcfa2eSMike Turquette  * clk_notifier_unregister: unregister a clock rate-change notifier callback
11086bcfa2eSMike Turquette  * @clk: clock whose rate we are no longer interested in
11186bcfa2eSMike Turquette  * @nb: notifier block which will be unregistered
11286bcfa2eSMike Turquette  */
113b2476490SMike Turquette int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb);
114b2476490SMike Turquette 
1155279fc40SBoris BREZILLON /**
1165279fc40SBoris BREZILLON  * clk_get_accuracy - obtain the clock accuracy in ppb (parts per billion)
1175279fc40SBoris BREZILLON  *		      for a clock source.
1185279fc40SBoris BREZILLON  * @clk: clock source
1195279fc40SBoris BREZILLON  *
1205279fc40SBoris BREZILLON  * This gets the clock source accuracy expressed in ppb.
1215279fc40SBoris BREZILLON  * A perfect clock returns 0.
1225279fc40SBoris BREZILLON  */
1235279fc40SBoris BREZILLON long clk_get_accuracy(struct clk *clk);
1245279fc40SBoris BREZILLON 
125e59c5371SMike Turquette /**
126e59c5371SMike Turquette  * clk_set_phase - adjust the phase shift of a clock signal
127e59c5371SMike Turquette  * @clk: clock signal source
128e59c5371SMike Turquette  * @degrees: number of degrees the signal is shifted
129e59c5371SMike Turquette  *
130e59c5371SMike Turquette  * Shifts the phase of a clock signal by the specified degrees. Returns 0 on
131e59c5371SMike Turquette  * success, -EERROR otherwise.
132e59c5371SMike Turquette  */
133e59c5371SMike Turquette int clk_set_phase(struct clk *clk, int degrees);
134e59c5371SMike Turquette 
135e59c5371SMike Turquette /**
136e59c5371SMike Turquette  * clk_get_phase - return the phase shift of a clock signal
137e59c5371SMike Turquette  * @clk: clock signal source
138e59c5371SMike Turquette  *
139e59c5371SMike Turquette  * Returns the phase shift of a clock node in degrees, otherwise returns
140e59c5371SMike Turquette  * -EERROR.
141e59c5371SMike Turquette  */
142e59c5371SMike Turquette int clk_get_phase(struct clk *clk);
143e59c5371SMike Turquette 
1443d3801efSMichael Turquette /**
1459fba738aSJerome Brunet  * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal
1469fba738aSJerome Brunet  * @clk: clock signal source
1479fba738aSJerome Brunet  * @num: numerator of the duty cycle ratio to be applied
1489fba738aSJerome Brunet  * @den: denominator of the duty cycle ratio to be applied
1499fba738aSJerome Brunet  *
1509fba738aSJerome Brunet  * Adjust the duty cycle of a clock signal by the specified ratio. Returns 0 on
1519fba738aSJerome Brunet  * success, -EERROR otherwise.
1529fba738aSJerome Brunet  */
1539fba738aSJerome Brunet int clk_set_duty_cycle(struct clk *clk, unsigned int num, unsigned int den);
1549fba738aSJerome Brunet 
1559fba738aSJerome Brunet /**
1569fba738aSJerome Brunet  * clk_get_duty_cycle - return the duty cycle ratio of a clock signal
1579fba738aSJerome Brunet  * @clk: clock signal source
1589fba738aSJerome Brunet  * @scale: scaling factor to be applied to represent the ratio as an integer
1599fba738aSJerome Brunet  *
1609fba738aSJerome Brunet  * Returns the duty cycle ratio multiplied by the scale provided, otherwise
1619fba738aSJerome Brunet  * returns -EERROR.
1629fba738aSJerome Brunet  */
1639fba738aSJerome Brunet int clk_get_scaled_duty_cycle(struct clk *clk, unsigned int scale);
1649fba738aSJerome Brunet 
1659fba738aSJerome Brunet /**
1663d3801efSMichael Turquette  * clk_is_match - check if two clk's point to the same hardware clock
1673d3801efSMichael Turquette  * @p: clk compared against q
1683d3801efSMichael Turquette  * @q: clk compared against p
1693d3801efSMichael Turquette  *
1703d3801efSMichael Turquette  * Returns true if the two struct clk pointers both point to the same hardware
1710e056eb5Smchehab@s-opensource.com  * clock node. Put differently, returns true if @p and @q
1720e056eb5Smchehab@s-opensource.com  * share the same &struct clk_core object.
1733d3801efSMichael Turquette  *
1743d3801efSMichael Turquette  * Returns false otherwise. Note that two NULL clks are treated as matching.
1753d3801efSMichael Turquette  */
1763d3801efSMichael Turquette bool clk_is_match(const struct clk *p, const struct clk *q);
1773d3801efSMichael Turquette 
1785279fc40SBoris BREZILLON #else
1795279fc40SBoris BREZILLON 
180e81b87d2SKrzysztof Kozlowski static inline int clk_notifier_register(struct clk *clk,
181e81b87d2SKrzysztof Kozlowski 					struct notifier_block *nb)
182e81b87d2SKrzysztof Kozlowski {
183e81b87d2SKrzysztof Kozlowski 	return -ENOTSUPP;
184e81b87d2SKrzysztof Kozlowski }
185e81b87d2SKrzysztof Kozlowski 
186e81b87d2SKrzysztof Kozlowski static inline int clk_notifier_unregister(struct clk *clk,
187e81b87d2SKrzysztof Kozlowski 					  struct notifier_block *nb)
188e81b87d2SKrzysztof Kozlowski {
189e81b87d2SKrzysztof Kozlowski 	return -ENOTSUPP;
190e81b87d2SKrzysztof Kozlowski }
191e81b87d2SKrzysztof Kozlowski 
1925279fc40SBoris BREZILLON static inline long clk_get_accuracy(struct clk *clk)
1935279fc40SBoris BREZILLON {
1945279fc40SBoris BREZILLON 	return -ENOTSUPP;
1955279fc40SBoris BREZILLON }
1965279fc40SBoris BREZILLON 
197e59c5371SMike Turquette static inline long clk_set_phase(struct clk *clk, int phase)
198e59c5371SMike Turquette {
199e59c5371SMike Turquette 	return -ENOTSUPP;
200e59c5371SMike Turquette }
201e59c5371SMike Turquette 
202e59c5371SMike Turquette static inline long clk_get_phase(struct clk *clk)
203e59c5371SMike Turquette {
204e59c5371SMike Turquette 	return -ENOTSUPP;
205e59c5371SMike Turquette }
206e59c5371SMike Turquette 
2079fba738aSJerome Brunet static inline int clk_set_duty_cycle(struct clk *clk, unsigned int num,
2089fba738aSJerome Brunet 				     unsigned int den)
2099fba738aSJerome Brunet {
2109fba738aSJerome Brunet 	return -ENOTSUPP;
2119fba738aSJerome Brunet }
2129fba738aSJerome Brunet 
2139fba738aSJerome Brunet static inline unsigned int clk_get_scaled_duty_cycle(struct clk *clk,
2149fba738aSJerome Brunet 						     unsigned int scale)
2159fba738aSJerome Brunet {
2169fba738aSJerome Brunet 	return 0;
2179fba738aSJerome Brunet }
2189fba738aSJerome Brunet 
2193d3801efSMichael Turquette static inline bool clk_is_match(const struct clk *p, const struct clk *q)
2203d3801efSMichael Turquette {
2213d3801efSMichael Turquette 	return p == q;
2223d3801efSMichael Turquette }
2233d3801efSMichael Turquette 
2247e87aed9SMark Brown #endif
225b2476490SMike Turquette 
226f8ce2547SRussell King /**
22793abe8e4SViresh Kumar  * clk_prepare - prepare a clock source
22893abe8e4SViresh Kumar  * @clk: clock source
22993abe8e4SViresh Kumar  *
23093abe8e4SViresh Kumar  * This prepares the clock source for use.
23193abe8e4SViresh Kumar  *
23293abe8e4SViresh Kumar  * Must not be called from within atomic context.
23393abe8e4SViresh Kumar  */
23493abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE
23593abe8e4SViresh Kumar int clk_prepare(struct clk *clk);
236266e4e9dSDong Aisheng int __must_check clk_bulk_prepare(int num_clks,
237266e4e9dSDong Aisheng 				  const struct clk_bulk_data *clks);
23893abe8e4SViresh Kumar #else
23993abe8e4SViresh Kumar static inline int clk_prepare(struct clk *clk)
24093abe8e4SViresh Kumar {
24193abe8e4SViresh Kumar 	might_sleep();
24293abe8e4SViresh Kumar 	return 0;
24393abe8e4SViresh Kumar }
244266e4e9dSDong Aisheng 
2456e0d4ff4SDong Aisheng static inline int __must_check clk_bulk_prepare(int num_clks, struct clk_bulk_data *clks)
246266e4e9dSDong Aisheng {
247266e4e9dSDong Aisheng 	might_sleep();
248266e4e9dSDong Aisheng 	return 0;
249266e4e9dSDong Aisheng }
25093abe8e4SViresh Kumar #endif
25193abe8e4SViresh Kumar 
25293abe8e4SViresh Kumar /**
25393abe8e4SViresh Kumar  * clk_unprepare - undo preparation of a clock source
25493abe8e4SViresh Kumar  * @clk: clock source
25593abe8e4SViresh Kumar  *
25693abe8e4SViresh Kumar  * This undoes a previously prepared clock.  The caller must balance
25793abe8e4SViresh Kumar  * the number of prepare and unprepare calls.
25893abe8e4SViresh Kumar  *
25993abe8e4SViresh Kumar  * Must not be called from within atomic context.
26093abe8e4SViresh Kumar  */
26193abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE
26293abe8e4SViresh Kumar void clk_unprepare(struct clk *clk);
263266e4e9dSDong Aisheng void clk_bulk_unprepare(int num_clks, const struct clk_bulk_data *clks);
26493abe8e4SViresh Kumar #else
26593abe8e4SViresh Kumar static inline void clk_unprepare(struct clk *clk)
26693abe8e4SViresh Kumar {
26793abe8e4SViresh Kumar 	might_sleep();
26893abe8e4SViresh Kumar }
269266e4e9dSDong Aisheng static inline void clk_bulk_unprepare(int num_clks, struct clk_bulk_data *clks)
270266e4e9dSDong Aisheng {
271266e4e9dSDong Aisheng 	might_sleep();
272266e4e9dSDong Aisheng }
27393abe8e4SViresh Kumar #endif
27493abe8e4SViresh Kumar 
27593abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK
27693abe8e4SViresh Kumar /**
277f8ce2547SRussell King  * clk_get - lookup and obtain a reference to a clock producer.
278f8ce2547SRussell King  * @dev: device for clock "consumer"
279a58b3a4aSJan-Simon Möller  * @id: clock consumer ID
280f8ce2547SRussell King  *
281f8ce2547SRussell King  * Returns a struct clk corresponding to the clock producer, or
282f8ce2547SRussell King  * valid IS_ERR() condition containing errno.  The implementation
283f8ce2547SRussell King  * uses @dev and @id to determine the clock consumer, and thereby
284f8ce2547SRussell King  * the clock producer.  (IOW, @id may be identical strings, but
285f8ce2547SRussell King  * clk_get may return different clock producers depending on @dev.)
286f8ce2547SRussell King  *
287f8ce2547SRussell King  * Drivers must assume that the clock source is not enabled.
288f7ad160bSAlex Raimondi  *
289f7ad160bSAlex Raimondi  * clk_get should not be called from within interrupt context.
290f8ce2547SRussell King  */
291f8ce2547SRussell King struct clk *clk_get(struct device *dev, const char *id);
292f8ce2547SRussell King 
293f8ce2547SRussell King /**
294266e4e9dSDong Aisheng  * clk_bulk_get - lookup and obtain a number of references to clock producer.
295266e4e9dSDong Aisheng  * @dev: device for clock "consumer"
296266e4e9dSDong Aisheng  * @num_clks: the number of clk_bulk_data
297266e4e9dSDong Aisheng  * @clks: the clk_bulk_data table of consumer
298266e4e9dSDong Aisheng  *
299266e4e9dSDong Aisheng  * This helper function allows drivers to get several clk consumers in one
300266e4e9dSDong Aisheng  * operation. If any of the clk cannot be acquired then any clks
301266e4e9dSDong Aisheng  * that were obtained will be freed before returning to the caller.
302266e4e9dSDong Aisheng  *
303266e4e9dSDong Aisheng  * Returns 0 if all clocks specified in clk_bulk_data table are obtained
304266e4e9dSDong Aisheng  * successfully, or valid IS_ERR() condition containing errno.
305266e4e9dSDong Aisheng  * The implementation uses @dev and @clk_bulk_data.id to determine the
306266e4e9dSDong Aisheng  * clock consumer, and thereby the clock producer.
307266e4e9dSDong Aisheng  * The clock returned is stored in each @clk_bulk_data.clk field.
308266e4e9dSDong Aisheng  *
309266e4e9dSDong Aisheng  * Drivers must assume that the clock source is not enabled.
310266e4e9dSDong Aisheng  *
311266e4e9dSDong Aisheng  * clk_bulk_get should not be called from within interrupt context.
312266e4e9dSDong Aisheng  */
313266e4e9dSDong Aisheng int __must_check clk_bulk_get(struct device *dev, int num_clks,
314266e4e9dSDong Aisheng 			      struct clk_bulk_data *clks);
315616e45dfSDong Aisheng /**
316616e45dfSDong Aisheng  * clk_bulk_get_all - lookup and obtain all available references to clock
317616e45dfSDong Aisheng  *		      producer.
318616e45dfSDong Aisheng  * @dev: device for clock "consumer"
319616e45dfSDong Aisheng  * @clks: pointer to the clk_bulk_data table of consumer
320616e45dfSDong Aisheng  *
321616e45dfSDong Aisheng  * This helper function allows drivers to get all clk consumers in one
322616e45dfSDong Aisheng  * operation. If any of the clk cannot be acquired then any clks
323616e45dfSDong Aisheng  * that were obtained will be freed before returning to the caller.
324616e45dfSDong Aisheng  *
325616e45dfSDong Aisheng  * Returns a positive value for the number of clocks obtained while the
326616e45dfSDong Aisheng  * clock references are stored in the clk_bulk_data table in @clks field.
327616e45dfSDong Aisheng  * Returns 0 if there're none and a negative value if something failed.
328616e45dfSDong Aisheng  *
329616e45dfSDong Aisheng  * Drivers must assume that the clock source is not enabled.
330616e45dfSDong Aisheng  *
331616e45dfSDong Aisheng  * clk_bulk_get should not be called from within interrupt context.
332616e45dfSDong Aisheng  */
333616e45dfSDong Aisheng int __must_check clk_bulk_get_all(struct device *dev,
334616e45dfSDong Aisheng 				  struct clk_bulk_data **clks);
335*2f25528eSSylwester Nawrocki 
336*2f25528eSSylwester Nawrocki /**
337*2f25528eSSylwester Nawrocki  * clk_bulk_get_optional - lookup and obtain a number of references to clock producer
338*2f25528eSSylwester Nawrocki  * @dev: device for clock "consumer"
339*2f25528eSSylwester Nawrocki  * @num_clks: the number of clk_bulk_data
340*2f25528eSSylwester Nawrocki  * @clks: the clk_bulk_data table of consumer
341*2f25528eSSylwester Nawrocki  *
342*2f25528eSSylwester Nawrocki  * Behaves the same as clk_bulk_get() except where there is no clock producer.
343*2f25528eSSylwester Nawrocki  * In this case, instead of returning -ENOENT, the function returns 0 and
344*2f25528eSSylwester Nawrocki  * NULL for a clk for which a clock producer could not be determined.
345*2f25528eSSylwester Nawrocki  */
346*2f25528eSSylwester Nawrocki int __must_check clk_bulk_get_optional(struct device *dev, int num_clks,
347*2f25528eSSylwester Nawrocki 				       struct clk_bulk_data *clks);
348266e4e9dSDong Aisheng /**
349618aee02SDong Aisheng  * devm_clk_bulk_get - managed get multiple clk consumers
350618aee02SDong Aisheng  * @dev: device for clock "consumer"
351618aee02SDong Aisheng  * @num_clks: the number of clk_bulk_data
352618aee02SDong Aisheng  * @clks: the clk_bulk_data table of consumer
353618aee02SDong Aisheng  *
354618aee02SDong Aisheng  * Return 0 on success, an errno on failure.
355618aee02SDong Aisheng  *
356618aee02SDong Aisheng  * This helper function allows drivers to get several clk
357618aee02SDong Aisheng  * consumers in one operation with management, the clks will
358618aee02SDong Aisheng  * automatically be freed when the device is unbound.
359618aee02SDong Aisheng  */
360618aee02SDong Aisheng int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
361618aee02SDong Aisheng 				   struct clk_bulk_data *clks);
362f08c2e28SDong Aisheng /**
363f08c2e28SDong Aisheng  * devm_clk_bulk_get_all - managed get multiple clk consumers
364f08c2e28SDong Aisheng  * @dev: device for clock "consumer"
365f08c2e28SDong Aisheng  * @clks: pointer to the clk_bulk_data table of consumer
366f08c2e28SDong Aisheng  *
367f08c2e28SDong Aisheng  * Returns a positive value for the number of clocks obtained while the
368f08c2e28SDong Aisheng  * clock references are stored in the clk_bulk_data table in @clks field.
369f08c2e28SDong Aisheng  * Returns 0 if there're none and a negative value if something failed.
370f08c2e28SDong Aisheng  *
371f08c2e28SDong Aisheng  * This helper function allows drivers to get several clk
372f08c2e28SDong Aisheng  * consumers in one operation with management, the clks will
373f08c2e28SDong Aisheng  * automatically be freed when the device is unbound.
374f08c2e28SDong Aisheng  */
375f08c2e28SDong Aisheng 
376f08c2e28SDong Aisheng int __must_check devm_clk_bulk_get_all(struct device *dev,
377f08c2e28SDong Aisheng 				       struct clk_bulk_data **clks);
378618aee02SDong Aisheng 
379618aee02SDong Aisheng /**
380a8a97db9SMark Brown  * devm_clk_get - lookup and obtain a managed reference to a clock producer.
381a8a97db9SMark Brown  * @dev: device for clock "consumer"
382a58b3a4aSJan-Simon Möller  * @id: clock consumer ID
383a8a97db9SMark Brown  *
384a8a97db9SMark Brown  * Returns a struct clk corresponding to the clock producer, or
385a8a97db9SMark Brown  * valid IS_ERR() condition containing errno.  The implementation
386a8a97db9SMark Brown  * uses @dev and @id to determine the clock consumer, and thereby
387a8a97db9SMark Brown  * the clock producer.  (IOW, @id may be identical strings, but
388a8a97db9SMark Brown  * clk_get may return different clock producers depending on @dev.)
389a8a97db9SMark Brown  *
390a8a97db9SMark Brown  * Drivers must assume that the clock source is not enabled.
391a8a97db9SMark Brown  *
392a8a97db9SMark Brown  * devm_clk_get should not be called from within interrupt context.
393a8a97db9SMark Brown  *
394a8a97db9SMark Brown  * The clock will automatically be freed when the device is unbound
395a8a97db9SMark Brown  * from the bus.
396a8a97db9SMark Brown  */
397a8a97db9SMark Brown struct clk *devm_clk_get(struct device *dev, const char *id);
398a8a97db9SMark Brown 
399a8a97db9SMark Brown /**
40060b8f0ddSPhil Edworthy  * devm_clk_get_optional - lookup and obtain a managed reference to an optional
40160b8f0ddSPhil Edworthy  *			   clock producer.
40260b8f0ddSPhil Edworthy  * @dev: device for clock "consumer"
40360b8f0ddSPhil Edworthy  * @id: clock consumer ID
40460b8f0ddSPhil Edworthy  *
40560b8f0ddSPhil Edworthy  * Behaves the same as devm_clk_get() except where there is no clock producer.
40660b8f0ddSPhil Edworthy  * In this case, instead of returning -ENOENT, the function returns NULL.
40760b8f0ddSPhil Edworthy  */
40860b8f0ddSPhil Edworthy struct clk *devm_clk_get_optional(struct device *dev, const char *id);
40960b8f0ddSPhil Edworthy 
41060b8f0ddSPhil Edworthy /**
41171a2f115SKuninori Morimoto  * devm_get_clk_from_child - lookup and obtain a managed reference to a
41271a2f115SKuninori Morimoto  *			     clock producer from child node.
41371a2f115SKuninori Morimoto  * @dev: device for clock "consumer"
41471a2f115SKuninori Morimoto  * @np: pointer to clock consumer node
41571a2f115SKuninori Morimoto  * @con_id: clock consumer ID
41671a2f115SKuninori Morimoto  *
41771a2f115SKuninori Morimoto  * This function parses the clocks, and uses them to look up the
41871a2f115SKuninori Morimoto  * struct clk from the registered list of clock providers by using
41971a2f115SKuninori Morimoto  * @np and @con_id
42071a2f115SKuninori Morimoto  *
42171a2f115SKuninori Morimoto  * The clock will automatically be freed when the device is unbound
42271a2f115SKuninori Morimoto  * from the bus.
42371a2f115SKuninori Morimoto  */
42471a2f115SKuninori Morimoto struct clk *devm_get_clk_from_child(struct device *dev,
42571a2f115SKuninori Morimoto 				    struct device_node *np, const char *con_id);
42655e9b8b7SJerome Brunet /**
42755e9b8b7SJerome Brunet  * clk_rate_exclusive_get - get exclusivity over the rate control of a
42855e9b8b7SJerome Brunet  *                          producer
42955e9b8b7SJerome Brunet  * @clk: clock source
43055e9b8b7SJerome Brunet  *
43155e9b8b7SJerome Brunet  * This function allows drivers to get exclusive control over the rate of a
43255e9b8b7SJerome Brunet  * provider. It prevents any other consumer to execute, even indirectly,
43355e9b8b7SJerome Brunet  * opereation which could alter the rate of the provider or cause glitches
43455e9b8b7SJerome Brunet  *
43555e9b8b7SJerome Brunet  * If exlusivity is claimed more than once on clock, even by the same driver,
43655e9b8b7SJerome Brunet  * the rate effectively gets locked as exclusivity can't be preempted.
43755e9b8b7SJerome Brunet  *
43855e9b8b7SJerome Brunet  * Must not be called from within atomic context.
43955e9b8b7SJerome Brunet  *
44055e9b8b7SJerome Brunet  * Returns success (0) or negative errno.
44155e9b8b7SJerome Brunet  */
44255e9b8b7SJerome Brunet int clk_rate_exclusive_get(struct clk *clk);
44355e9b8b7SJerome Brunet 
44455e9b8b7SJerome Brunet /**
44555e9b8b7SJerome Brunet  * clk_rate_exclusive_put - release exclusivity over the rate control of a
44655e9b8b7SJerome Brunet  *                          producer
44755e9b8b7SJerome Brunet  * @clk: clock source
44855e9b8b7SJerome Brunet  *
44955e9b8b7SJerome Brunet  * This function allows drivers to release the exclusivity it previously got
45055e9b8b7SJerome Brunet  * from clk_rate_exclusive_get()
45155e9b8b7SJerome Brunet  *
45255e9b8b7SJerome Brunet  * The caller must balance the number of clk_rate_exclusive_get() and
45355e9b8b7SJerome Brunet  * clk_rate_exclusive_put() calls.
45455e9b8b7SJerome Brunet  *
45555e9b8b7SJerome Brunet  * Must not be called from within atomic context.
45655e9b8b7SJerome Brunet  */
45755e9b8b7SJerome Brunet void clk_rate_exclusive_put(struct clk *clk);
45871a2f115SKuninori Morimoto 
45971a2f115SKuninori Morimoto /**
460f8ce2547SRussell King  * clk_enable - inform the system when the clock source should be running.
461f8ce2547SRussell King  * @clk: clock source
462f8ce2547SRussell King  *
463f8ce2547SRussell King  * If the clock can not be enabled/disabled, this should return success.
464f8ce2547SRussell King  *
46540d3e0f4SRussell King  * May be called from atomic contexts.
46640d3e0f4SRussell King  *
467f8ce2547SRussell King  * Returns success (0) or negative errno.
468f8ce2547SRussell King  */
469f8ce2547SRussell King int clk_enable(struct clk *clk);
470f8ce2547SRussell King 
471f8ce2547SRussell King /**
472266e4e9dSDong Aisheng  * clk_bulk_enable - inform the system when the set of clks should be running.
473266e4e9dSDong Aisheng  * @num_clks: the number of clk_bulk_data
474266e4e9dSDong Aisheng  * @clks: the clk_bulk_data table of consumer
475266e4e9dSDong Aisheng  *
476266e4e9dSDong Aisheng  * May be called from atomic contexts.
477266e4e9dSDong Aisheng  *
478266e4e9dSDong Aisheng  * Returns success (0) or negative errno.
479266e4e9dSDong Aisheng  */
480266e4e9dSDong Aisheng int __must_check clk_bulk_enable(int num_clks,
481266e4e9dSDong Aisheng 				 const struct clk_bulk_data *clks);
482266e4e9dSDong Aisheng 
483266e4e9dSDong Aisheng /**
484f8ce2547SRussell King  * clk_disable - inform the system when the clock source is no longer required.
485f8ce2547SRussell King  * @clk: clock source
486f8ce2547SRussell King  *
487f8ce2547SRussell King  * Inform the system that a clock source is no longer required by
488f8ce2547SRussell King  * a driver and may be shut down.
489f8ce2547SRussell King  *
49040d3e0f4SRussell King  * May be called from atomic contexts.
49140d3e0f4SRussell King  *
492f8ce2547SRussell King  * Implementation detail: if the clock source is shared between
493f8ce2547SRussell King  * multiple drivers, clk_enable() calls must be balanced by the
494f8ce2547SRussell King  * same number of clk_disable() calls for the clock source to be
495f8ce2547SRussell King  * disabled.
496f8ce2547SRussell King  */
497f8ce2547SRussell King void clk_disable(struct clk *clk);
498f8ce2547SRussell King 
499f8ce2547SRussell King /**
500266e4e9dSDong Aisheng  * clk_bulk_disable - inform the system when the set of clks is no
501266e4e9dSDong Aisheng  *		      longer required.
502266e4e9dSDong Aisheng  * @num_clks: the number of clk_bulk_data
503266e4e9dSDong Aisheng  * @clks: the clk_bulk_data table of consumer
504266e4e9dSDong Aisheng  *
505266e4e9dSDong Aisheng  * Inform the system that a set of clks is no longer required by
506266e4e9dSDong Aisheng  * a driver and may be shut down.
507266e4e9dSDong Aisheng  *
508266e4e9dSDong Aisheng  * May be called from atomic contexts.
509266e4e9dSDong Aisheng  *
510266e4e9dSDong Aisheng  * Implementation detail: if the set of clks is shared between
511266e4e9dSDong Aisheng  * multiple drivers, clk_bulk_enable() calls must be balanced by the
512266e4e9dSDong Aisheng  * same number of clk_bulk_disable() calls for the clock source to be
513266e4e9dSDong Aisheng  * disabled.
514266e4e9dSDong Aisheng  */
515266e4e9dSDong Aisheng void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks);
516266e4e9dSDong Aisheng 
517266e4e9dSDong Aisheng /**
518f8ce2547SRussell King  * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
519f8ce2547SRussell King  *		  This is only valid once the clock source has been enabled.
520f8ce2547SRussell King  * @clk: clock source
521f8ce2547SRussell King  */
522f8ce2547SRussell King unsigned long clk_get_rate(struct clk *clk);
523f8ce2547SRussell King 
524f8ce2547SRussell King /**
525f8ce2547SRussell King  * clk_put	- "free" the clock source
526f8ce2547SRussell King  * @clk: clock source
527f8ce2547SRussell King  *
528f8ce2547SRussell King  * Note: drivers must ensure that all clk_enable calls made on this
529f8ce2547SRussell King  * clock source are balanced by clk_disable calls prior to calling
530f8ce2547SRussell King  * this function.
531f7ad160bSAlex Raimondi  *
532f7ad160bSAlex Raimondi  * clk_put should not be called from within interrupt context.
533f8ce2547SRussell King  */
534f8ce2547SRussell King void clk_put(struct clk *clk);
535f8ce2547SRussell King 
536a8a97db9SMark Brown /**
537266e4e9dSDong Aisheng  * clk_bulk_put	- "free" the clock source
538266e4e9dSDong Aisheng  * @num_clks: the number of clk_bulk_data
539266e4e9dSDong Aisheng  * @clks: the clk_bulk_data table of consumer
540266e4e9dSDong Aisheng  *
541266e4e9dSDong Aisheng  * Note: drivers must ensure that all clk_bulk_enable calls made on this
542266e4e9dSDong Aisheng  * clock source are balanced by clk_bulk_disable calls prior to calling
543266e4e9dSDong Aisheng  * this function.
544266e4e9dSDong Aisheng  *
545266e4e9dSDong Aisheng  * clk_bulk_put should not be called from within interrupt context.
546266e4e9dSDong Aisheng  */
547266e4e9dSDong Aisheng void clk_bulk_put(int num_clks, struct clk_bulk_data *clks);
548266e4e9dSDong Aisheng 
549266e4e9dSDong Aisheng /**
550616e45dfSDong Aisheng  * clk_bulk_put_all - "free" all the clock source
551616e45dfSDong Aisheng  * @num_clks: the number of clk_bulk_data
552616e45dfSDong Aisheng  * @clks: the clk_bulk_data table of consumer
553616e45dfSDong Aisheng  *
554616e45dfSDong Aisheng  * Note: drivers must ensure that all clk_bulk_enable calls made on this
555616e45dfSDong Aisheng  * clock source are balanced by clk_bulk_disable calls prior to calling
556616e45dfSDong Aisheng  * this function.
557616e45dfSDong Aisheng  *
558616e45dfSDong Aisheng  * clk_bulk_put_all should not be called from within interrupt context.
559616e45dfSDong Aisheng  */
560616e45dfSDong Aisheng void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks);
561616e45dfSDong Aisheng 
562616e45dfSDong Aisheng /**
563a8a97db9SMark Brown  * devm_clk_put	- "free" a managed clock source
564da3dae54SMasanari Iida  * @dev: device used to acquire the clock
565a8a97db9SMark Brown  * @clk: clock source acquired with devm_clk_get()
566a8a97db9SMark Brown  *
567a8a97db9SMark Brown  * Note: drivers must ensure that all clk_enable calls made on this
568a8a97db9SMark Brown  * clock source are balanced by clk_disable calls prior to calling
569a8a97db9SMark Brown  * this function.
570a8a97db9SMark Brown  *
571a8a97db9SMark Brown  * clk_put should not be called from within interrupt context.
572a8a97db9SMark Brown  */
573a8a97db9SMark Brown void devm_clk_put(struct device *dev, struct clk *clk);
574f8ce2547SRussell King 
575f8ce2547SRussell King /*
576f8ce2547SRussell King  * The remaining APIs are optional for machine class support.
577f8ce2547SRussell King  */
578f8ce2547SRussell King 
579f8ce2547SRussell King 
580f8ce2547SRussell King /**
581f8ce2547SRussell King  * clk_round_rate - adjust a rate to the exact rate a clock can provide
582f8ce2547SRussell King  * @clk: clock source
583f8ce2547SRussell King  * @rate: desired clock rate in Hz
584f8ce2547SRussell King  *
585d2d14a77SRussell King  * This answers the question "if I were to pass @rate to clk_set_rate(),
586d2d14a77SRussell King  * what clock rate would I end up with?" without changing the hardware
587d2d14a77SRussell King  * in any way.  In other words:
588d2d14a77SRussell King  *
589d2d14a77SRussell King  *   rate = clk_round_rate(clk, r);
590d2d14a77SRussell King  *
591d2d14a77SRussell King  * and:
592d2d14a77SRussell King  *
593d2d14a77SRussell King  *   clk_set_rate(clk, r);
594d2d14a77SRussell King  *   rate = clk_get_rate(clk);
595d2d14a77SRussell King  *
596d2d14a77SRussell King  * are equivalent except the former does not modify the clock hardware
597d2d14a77SRussell King  * in any way.
598d2d14a77SRussell King  *
599f8ce2547SRussell King  * Returns rounded clock rate in Hz, or negative errno.
600f8ce2547SRussell King  */
601f8ce2547SRussell King long clk_round_rate(struct clk *clk, unsigned long rate);
602f8ce2547SRussell King 
603f8ce2547SRussell King /**
604f8ce2547SRussell King  * clk_set_rate - set the clock rate for a clock source
605f8ce2547SRussell King  * @clk: clock source
606f8ce2547SRussell King  * @rate: desired clock rate in Hz
607f8ce2547SRussell King  *
608f8ce2547SRussell King  * Returns success (0) or negative errno.
609f8ce2547SRussell King  */
610f8ce2547SRussell King int clk_set_rate(struct clk *clk, unsigned long rate);
611f8ce2547SRussell King 
612f8ce2547SRussell King /**
61355e9b8b7SJerome Brunet  * clk_set_rate_exclusive- set the clock rate and claim exclusivity over
61455e9b8b7SJerome Brunet  *                         clock source
61555e9b8b7SJerome Brunet  * @clk: clock source
61655e9b8b7SJerome Brunet  * @rate: desired clock rate in Hz
61755e9b8b7SJerome Brunet  *
61855e9b8b7SJerome Brunet  * This helper function allows drivers to atomically set the rate of a producer
61955e9b8b7SJerome Brunet  * and claim exclusivity over the rate control of the producer.
62055e9b8b7SJerome Brunet  *
62155e9b8b7SJerome Brunet  * It is essentially a combination of clk_set_rate() and
62255e9b8b7SJerome Brunet  * clk_rate_exclusite_get(). Caller must balance this call with a call to
62355e9b8b7SJerome Brunet  * clk_rate_exclusive_put()
62455e9b8b7SJerome Brunet  *
62555e9b8b7SJerome Brunet  * Returns success (0) or negative errno.
62655e9b8b7SJerome Brunet  */
62755e9b8b7SJerome Brunet int clk_set_rate_exclusive(struct clk *clk, unsigned long rate);
62855e9b8b7SJerome Brunet 
62955e9b8b7SJerome Brunet /**
6304e88f3deSThierry Reding  * clk_has_parent - check if a clock is a possible parent for another
6314e88f3deSThierry Reding  * @clk: clock source
6324e88f3deSThierry Reding  * @parent: parent clock source
6334e88f3deSThierry Reding  *
6344e88f3deSThierry Reding  * This function can be used in drivers that need to check that a clock can be
6354e88f3deSThierry Reding  * the parent of another without actually changing the parent.
6364e88f3deSThierry Reding  *
6374e88f3deSThierry Reding  * Returns true if @parent is a possible parent for @clk, false otherwise.
6384e88f3deSThierry Reding  */
6394e88f3deSThierry Reding bool clk_has_parent(struct clk *clk, struct clk *parent);
6404e88f3deSThierry Reding 
6414e88f3deSThierry Reding /**
6421c8e6004STomeu Vizoso  * clk_set_rate_range - set a rate range for a clock source
6431c8e6004STomeu Vizoso  * @clk: clock source
6441c8e6004STomeu Vizoso  * @min: desired minimum clock rate in Hz, inclusive
6451c8e6004STomeu Vizoso  * @max: desired maximum clock rate in Hz, inclusive
6461c8e6004STomeu Vizoso  *
6471c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
6481c8e6004STomeu Vizoso  */
6491c8e6004STomeu Vizoso int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max);
6501c8e6004STomeu Vizoso 
6511c8e6004STomeu Vizoso /**
6521c8e6004STomeu Vizoso  * clk_set_min_rate - set a minimum clock rate for a clock source
6531c8e6004STomeu Vizoso  * @clk: clock source
6541c8e6004STomeu Vizoso  * @rate: desired minimum clock rate in Hz, inclusive
6551c8e6004STomeu Vizoso  *
6561c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
6571c8e6004STomeu Vizoso  */
6581c8e6004STomeu Vizoso int clk_set_min_rate(struct clk *clk, unsigned long rate);
6591c8e6004STomeu Vizoso 
6601c8e6004STomeu Vizoso /**
6611c8e6004STomeu Vizoso  * clk_set_max_rate - set a maximum clock rate for a clock source
6621c8e6004STomeu Vizoso  * @clk: clock source
6631c8e6004STomeu Vizoso  * @rate: desired maximum clock rate in Hz, inclusive
6641c8e6004STomeu Vizoso  *
6651c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
6661c8e6004STomeu Vizoso  */
6671c8e6004STomeu Vizoso int clk_set_max_rate(struct clk *clk, unsigned long rate);
6681c8e6004STomeu Vizoso 
6691c8e6004STomeu Vizoso /**
670f8ce2547SRussell King  * clk_set_parent - set the parent clock source for this clock
671f8ce2547SRussell King  * @clk: clock source
672f8ce2547SRussell King  * @parent: parent clock source
673f8ce2547SRussell King  *
674f8ce2547SRussell King  * Returns success (0) or negative errno.
675f8ce2547SRussell King  */
676f8ce2547SRussell King int clk_set_parent(struct clk *clk, struct clk *parent);
677f8ce2547SRussell King 
678f8ce2547SRussell King /**
679f8ce2547SRussell King  * clk_get_parent - get the parent clock source for this clock
680f8ce2547SRussell King  * @clk: clock source
681f8ce2547SRussell King  *
682f8ce2547SRussell King  * Returns struct clk corresponding to parent clock source, or
683f8ce2547SRussell King  * valid IS_ERR() condition containing errno.
684f8ce2547SRussell King  */
685f8ce2547SRussell King struct clk *clk_get_parent(struct clk *clk);
686f8ce2547SRussell King 
68705fd8e73SSascha Hauer /**
68805fd8e73SSascha Hauer  * clk_get_sys - get a clock based upon the device name
68905fd8e73SSascha Hauer  * @dev_id: device name
69005fd8e73SSascha Hauer  * @con_id: connection ID
69105fd8e73SSascha Hauer  *
69205fd8e73SSascha Hauer  * Returns a struct clk corresponding to the clock producer, or
69305fd8e73SSascha Hauer  * valid IS_ERR() condition containing errno.  The implementation
69405fd8e73SSascha Hauer  * uses @dev_id and @con_id to determine the clock consumer, and
69505fd8e73SSascha Hauer  * thereby the clock producer. In contrast to clk_get() this function
69605fd8e73SSascha Hauer  * takes the device name instead of the device itself for identification.
69705fd8e73SSascha Hauer  *
69805fd8e73SSascha Hauer  * Drivers must assume that the clock source is not enabled.
69905fd8e73SSascha Hauer  *
70005fd8e73SSascha Hauer  * clk_get_sys should not be called from within interrupt context.
70105fd8e73SSascha Hauer  */
70205fd8e73SSascha Hauer struct clk *clk_get_sys(const char *dev_id, const char *con_id);
70305fd8e73SSascha Hauer 
7048b95d1ceSRuss Dill /**
7058b95d1ceSRuss Dill  * clk_save_context - save clock context for poweroff
7068b95d1ceSRuss Dill  *
7078b95d1ceSRuss Dill  * Saves the context of the clock register for powerstates in which the
7088b95d1ceSRuss Dill  * contents of the registers will be lost. Occurs deep within the suspend
7098b95d1ceSRuss Dill  * code so locking is not necessary.
7108b95d1ceSRuss Dill  */
7118b95d1ceSRuss Dill int clk_save_context(void);
7128b95d1ceSRuss Dill 
7138b95d1ceSRuss Dill /**
7148b95d1ceSRuss Dill  * clk_restore_context - restore clock context after poweroff
7158b95d1ceSRuss Dill  *
7168b95d1ceSRuss Dill  * This occurs with all clocks enabled. Occurs deep within the resume code
7178b95d1ceSRuss Dill  * so locking is not necessary.
7188b95d1ceSRuss Dill  */
7198b95d1ceSRuss Dill void clk_restore_context(void);
7208b95d1ceSRuss Dill 
72193abe8e4SViresh Kumar #else /* !CONFIG_HAVE_CLK */
72293abe8e4SViresh Kumar 
72393abe8e4SViresh Kumar static inline struct clk *clk_get(struct device *dev, const char *id)
72493abe8e4SViresh Kumar {
72593abe8e4SViresh Kumar 	return NULL;
72693abe8e4SViresh Kumar }
72793abe8e4SViresh Kumar 
7286e0d4ff4SDong Aisheng static inline int __must_check clk_bulk_get(struct device *dev, int num_clks,
729266e4e9dSDong Aisheng 					    struct clk_bulk_data *clks)
730266e4e9dSDong Aisheng {
731266e4e9dSDong Aisheng 	return 0;
732266e4e9dSDong Aisheng }
733266e4e9dSDong Aisheng 
734*2f25528eSSylwester Nawrocki static inline int __must_check clk_bulk_get_optional(struct device *dev,
735*2f25528eSSylwester Nawrocki 				int num_clks, struct clk_bulk_data *clks)
736*2f25528eSSylwester Nawrocki {
737*2f25528eSSylwester Nawrocki 	return 0;
738*2f25528eSSylwester Nawrocki }
739*2f25528eSSylwester Nawrocki 
740616e45dfSDong Aisheng static inline int __must_check clk_bulk_get_all(struct device *dev,
741616e45dfSDong Aisheng 					 struct clk_bulk_data **clks)
742616e45dfSDong Aisheng {
743616e45dfSDong Aisheng 	return 0;
744616e45dfSDong Aisheng }
745616e45dfSDong Aisheng 
74693abe8e4SViresh Kumar static inline struct clk *devm_clk_get(struct device *dev, const char *id)
74793abe8e4SViresh Kumar {
74893abe8e4SViresh Kumar 	return NULL;
74993abe8e4SViresh Kumar }
75093abe8e4SViresh Kumar 
75160b8f0ddSPhil Edworthy static inline struct clk *devm_clk_get_optional(struct device *dev,
75260b8f0ddSPhil Edworthy 						const char *id)
75360b8f0ddSPhil Edworthy {
75460b8f0ddSPhil Edworthy 	return NULL;
75560b8f0ddSPhil Edworthy }
75660b8f0ddSPhil Edworthy 
7576e0d4ff4SDong Aisheng static inline int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
758618aee02SDong Aisheng 						 struct clk_bulk_data *clks)
759618aee02SDong Aisheng {
760618aee02SDong Aisheng 	return 0;
761618aee02SDong Aisheng }
762618aee02SDong Aisheng 
763f08c2e28SDong Aisheng static inline int __must_check devm_clk_bulk_get_all(struct device *dev,
764f08c2e28SDong Aisheng 						     struct clk_bulk_data **clks)
765f08c2e28SDong Aisheng {
766f08c2e28SDong Aisheng 
767f08c2e28SDong Aisheng 	return 0;
768f08c2e28SDong Aisheng }
769f08c2e28SDong Aisheng 
77071a2f115SKuninori Morimoto static inline struct clk *devm_get_clk_from_child(struct device *dev,
77171a2f115SKuninori Morimoto 				struct device_node *np, const char *con_id)
77271a2f115SKuninori Morimoto {
77371a2f115SKuninori Morimoto 	return NULL;
77471a2f115SKuninori Morimoto }
77571a2f115SKuninori Morimoto 
77693abe8e4SViresh Kumar static inline void clk_put(struct clk *clk) {}
77793abe8e4SViresh Kumar 
778266e4e9dSDong Aisheng static inline void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) {}
779266e4e9dSDong Aisheng 
780616e45dfSDong Aisheng static inline void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks) {}
781616e45dfSDong Aisheng 
78293abe8e4SViresh Kumar static inline void devm_clk_put(struct device *dev, struct clk *clk) {}
78393abe8e4SViresh Kumar 
78455e9b8b7SJerome Brunet 
78555e9b8b7SJerome Brunet static inline int clk_rate_exclusive_get(struct clk *clk)
78655e9b8b7SJerome Brunet {
78755e9b8b7SJerome Brunet 	return 0;
78855e9b8b7SJerome Brunet }
78955e9b8b7SJerome Brunet 
79055e9b8b7SJerome Brunet static inline void clk_rate_exclusive_put(struct clk *clk) {}
79155e9b8b7SJerome Brunet 
79293abe8e4SViresh Kumar static inline int clk_enable(struct clk *clk)
79393abe8e4SViresh Kumar {
79493abe8e4SViresh Kumar 	return 0;
79593abe8e4SViresh Kumar }
79693abe8e4SViresh Kumar 
7976e0d4ff4SDong Aisheng static inline int __must_check clk_bulk_enable(int num_clks, struct clk_bulk_data *clks)
798266e4e9dSDong Aisheng {
799266e4e9dSDong Aisheng 	return 0;
800266e4e9dSDong Aisheng }
801266e4e9dSDong Aisheng 
80293abe8e4SViresh Kumar static inline void clk_disable(struct clk *clk) {}
80393abe8e4SViresh Kumar 
804266e4e9dSDong Aisheng 
805266e4e9dSDong Aisheng static inline void clk_bulk_disable(int num_clks,
806266e4e9dSDong Aisheng 				    struct clk_bulk_data *clks) {}
807266e4e9dSDong Aisheng 
80893abe8e4SViresh Kumar static inline unsigned long clk_get_rate(struct clk *clk)
80993abe8e4SViresh Kumar {
81093abe8e4SViresh Kumar 	return 0;
81193abe8e4SViresh Kumar }
81293abe8e4SViresh Kumar 
81393abe8e4SViresh Kumar static inline int clk_set_rate(struct clk *clk, unsigned long rate)
81493abe8e4SViresh Kumar {
81593abe8e4SViresh Kumar 	return 0;
81693abe8e4SViresh Kumar }
81793abe8e4SViresh Kumar 
81855e9b8b7SJerome Brunet static inline int clk_set_rate_exclusive(struct clk *clk, unsigned long rate)
81955e9b8b7SJerome Brunet {
82055e9b8b7SJerome Brunet 	return 0;
82155e9b8b7SJerome Brunet }
82255e9b8b7SJerome Brunet 
82393abe8e4SViresh Kumar static inline long clk_round_rate(struct clk *clk, unsigned long rate)
82493abe8e4SViresh Kumar {
82593abe8e4SViresh Kumar 	return 0;
82693abe8e4SViresh Kumar }
82793abe8e4SViresh Kumar 
8284e88f3deSThierry Reding static inline bool clk_has_parent(struct clk *clk, struct clk *parent)
8294e88f3deSThierry Reding {
8304e88f3deSThierry Reding 	return true;
8314e88f3deSThierry Reding }
8324e88f3deSThierry Reding 
833b88c9f41SDmitry Osipenko static inline int clk_set_rate_range(struct clk *clk, unsigned long min,
834b88c9f41SDmitry Osipenko 				     unsigned long max)
835b88c9f41SDmitry Osipenko {
836b88c9f41SDmitry Osipenko 	return 0;
837b88c9f41SDmitry Osipenko }
838b88c9f41SDmitry Osipenko 
839b88c9f41SDmitry Osipenko static inline int clk_set_min_rate(struct clk *clk, unsigned long rate)
840b88c9f41SDmitry Osipenko {
841b88c9f41SDmitry Osipenko 	return 0;
842b88c9f41SDmitry Osipenko }
843b88c9f41SDmitry Osipenko 
844b88c9f41SDmitry Osipenko static inline int clk_set_max_rate(struct clk *clk, unsigned long rate)
845b88c9f41SDmitry Osipenko {
846b88c9f41SDmitry Osipenko 	return 0;
847b88c9f41SDmitry Osipenko }
848b88c9f41SDmitry Osipenko 
84993abe8e4SViresh Kumar static inline int clk_set_parent(struct clk *clk, struct clk *parent)
85093abe8e4SViresh Kumar {
85193abe8e4SViresh Kumar 	return 0;
85293abe8e4SViresh Kumar }
85393abe8e4SViresh Kumar 
85493abe8e4SViresh Kumar static inline struct clk *clk_get_parent(struct clk *clk)
85593abe8e4SViresh Kumar {
85693abe8e4SViresh Kumar 	return NULL;
85793abe8e4SViresh Kumar }
85893abe8e4SViresh Kumar 
859b81ea968SDaniel Lezcano static inline struct clk *clk_get_sys(const char *dev_id, const char *con_id)
860b81ea968SDaniel Lezcano {
861b81ea968SDaniel Lezcano 	return NULL;
862b81ea968SDaniel Lezcano }
8638b95d1ceSRuss Dill 
8648b95d1ceSRuss Dill static inline int clk_save_context(void)
8658b95d1ceSRuss Dill {
8668b95d1ceSRuss Dill 	return 0;
8678b95d1ceSRuss Dill }
8688b95d1ceSRuss Dill 
8698b95d1ceSRuss Dill static inline void clk_restore_context(void) {}
8708b95d1ceSRuss Dill 
87193abe8e4SViresh Kumar #endif
87293abe8e4SViresh Kumar 
87393abe8e4SViresh Kumar /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
87493abe8e4SViresh Kumar static inline int clk_prepare_enable(struct clk *clk)
87593abe8e4SViresh Kumar {
87693abe8e4SViresh Kumar 	int ret;
87793abe8e4SViresh Kumar 
87893abe8e4SViresh Kumar 	ret = clk_prepare(clk);
87993abe8e4SViresh Kumar 	if (ret)
88093abe8e4SViresh Kumar 		return ret;
88193abe8e4SViresh Kumar 	ret = clk_enable(clk);
88293abe8e4SViresh Kumar 	if (ret)
88393abe8e4SViresh Kumar 		clk_unprepare(clk);
88493abe8e4SViresh Kumar 
88593abe8e4SViresh Kumar 	return ret;
88693abe8e4SViresh Kumar }
88793abe8e4SViresh Kumar 
88893abe8e4SViresh Kumar /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */
88993abe8e4SViresh Kumar static inline void clk_disable_unprepare(struct clk *clk)
89093abe8e4SViresh Kumar {
89193abe8e4SViresh Kumar 	clk_disable(clk);
89293abe8e4SViresh Kumar 	clk_unprepare(clk);
89393abe8e4SViresh Kumar }
89493abe8e4SViresh Kumar 
8956e0d4ff4SDong Aisheng static inline int __must_check clk_bulk_prepare_enable(int num_clks,
8963c48d86cSBjorn Andersson 					struct clk_bulk_data *clks)
8973c48d86cSBjorn Andersson {
8983c48d86cSBjorn Andersson 	int ret;
8993c48d86cSBjorn Andersson 
9003c48d86cSBjorn Andersson 	ret = clk_bulk_prepare(num_clks, clks);
9013c48d86cSBjorn Andersson 	if (ret)
9023c48d86cSBjorn Andersson 		return ret;
9033c48d86cSBjorn Andersson 	ret = clk_bulk_enable(num_clks, clks);
9043c48d86cSBjorn Andersson 	if (ret)
9053c48d86cSBjorn Andersson 		clk_bulk_unprepare(num_clks, clks);
9063c48d86cSBjorn Andersson 
9073c48d86cSBjorn Andersson 	return ret;
9083c48d86cSBjorn Andersson }
9093c48d86cSBjorn Andersson 
9103c48d86cSBjorn Andersson static inline void clk_bulk_disable_unprepare(int num_clks,
9113c48d86cSBjorn Andersson 					      struct clk_bulk_data *clks)
9123c48d86cSBjorn Andersson {
9133c48d86cSBjorn Andersson 	clk_bulk_disable(num_clks, clks);
9143c48d86cSBjorn Andersson 	clk_bulk_unprepare(num_clks, clks);
9153c48d86cSBjorn Andersson }
9163c48d86cSBjorn Andersson 
91760b8f0ddSPhil Edworthy /**
91860b8f0ddSPhil Edworthy  * clk_get_optional - lookup and obtain a reference to an optional clock
91960b8f0ddSPhil Edworthy  *		      producer.
92060b8f0ddSPhil Edworthy  * @dev: device for clock "consumer"
92160b8f0ddSPhil Edworthy  * @id: clock consumer ID
92260b8f0ddSPhil Edworthy  *
92360b8f0ddSPhil Edworthy  * Behaves the same as clk_get() except where there is no clock producer. In
92460b8f0ddSPhil Edworthy  * this case, instead of returning -ENOENT, the function returns NULL.
92560b8f0ddSPhil Edworthy  */
92660b8f0ddSPhil Edworthy static inline struct clk *clk_get_optional(struct device *dev, const char *id)
92760b8f0ddSPhil Edworthy {
92860b8f0ddSPhil Edworthy 	struct clk *clk = clk_get(dev, id);
92960b8f0ddSPhil Edworthy 
93060b8f0ddSPhil Edworthy 	if (clk == ERR_PTR(-ENOENT))
93160b8f0ddSPhil Edworthy 		return NULL;
93260b8f0ddSPhil Edworthy 
93360b8f0ddSPhil Edworthy 	return clk;
93460b8f0ddSPhil Edworthy }
93560b8f0ddSPhil Edworthy 
936137f8a72SRob Herring #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
937766e6a4eSGrant Likely struct clk *of_clk_get(struct device_node *np, int index);
938766e6a4eSGrant Likely struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
939766e6a4eSGrant Likely struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
940766e6a4eSGrant Likely #else
941766e6a4eSGrant Likely static inline struct clk *of_clk_get(struct device_node *np, int index)
942766e6a4eSGrant Likely {
9439f1612d3SShawn Guo 	return ERR_PTR(-ENOENT);
944766e6a4eSGrant Likely }
945766e6a4eSGrant Likely static inline struct clk *of_clk_get_by_name(struct device_node *np,
946766e6a4eSGrant Likely 					     const char *name)
947766e6a4eSGrant Likely {
9489f1612d3SShawn Guo 	return ERR_PTR(-ENOENT);
949766e6a4eSGrant Likely }
950428c9de5SGeert Uytterhoeven static inline struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
951428c9de5SGeert Uytterhoeven {
952428c9de5SGeert Uytterhoeven 	return ERR_PTR(-ENOENT);
953428c9de5SGeert Uytterhoeven }
954766e6a4eSGrant Likely #endif
955766e6a4eSGrant Likely 
956f8ce2547SRussell King #endif
957