xref: /openbmc/linux/include/linux/clk.h (revision 0e056eb5530da802c07f080d6bbd43c50e799efd)
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 
80e81b87d2SKrzysztof Kozlowski #ifdef CONFIG_COMMON_CLK
81e81b87d2SKrzysztof Kozlowski 
8286bcfa2eSMike Turquette /**
8386bcfa2eSMike Turquette  * clk_notifier_register: register a clock rate-change notifier callback
8486bcfa2eSMike Turquette  * @clk: clock whose rate we are interested in
8586bcfa2eSMike Turquette  * @nb: notifier block with callback function pointer
8686bcfa2eSMike Turquette  *
8786bcfa2eSMike Turquette  * ProTip: debugging across notifier chains can be frustrating. Make sure that
8886bcfa2eSMike Turquette  * your notifier callback function prints a nice big warning in case of
8986bcfa2eSMike Turquette  * failure.
9086bcfa2eSMike Turquette  */
91b2476490SMike Turquette int clk_notifier_register(struct clk *clk, struct notifier_block *nb);
92b2476490SMike Turquette 
9386bcfa2eSMike Turquette /**
9486bcfa2eSMike Turquette  * clk_notifier_unregister: unregister a clock rate-change notifier callback
9586bcfa2eSMike Turquette  * @clk: clock whose rate we are no longer interested in
9686bcfa2eSMike Turquette  * @nb: notifier block which will be unregistered
9786bcfa2eSMike Turquette  */
98b2476490SMike Turquette int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb);
99b2476490SMike Turquette 
1005279fc40SBoris BREZILLON /**
1015279fc40SBoris BREZILLON  * clk_get_accuracy - obtain the clock accuracy in ppb (parts per billion)
1025279fc40SBoris BREZILLON  *		      for a clock source.
1035279fc40SBoris BREZILLON  * @clk: clock source
1045279fc40SBoris BREZILLON  *
1055279fc40SBoris BREZILLON  * This gets the clock source accuracy expressed in ppb.
1065279fc40SBoris BREZILLON  * A perfect clock returns 0.
1075279fc40SBoris BREZILLON  */
1085279fc40SBoris BREZILLON long clk_get_accuracy(struct clk *clk);
1095279fc40SBoris BREZILLON 
110e59c5371SMike Turquette /**
111e59c5371SMike Turquette  * clk_set_phase - adjust the phase shift of a clock signal
112e59c5371SMike Turquette  * @clk: clock signal source
113e59c5371SMike Turquette  * @degrees: number of degrees the signal is shifted
114e59c5371SMike Turquette  *
115e59c5371SMike Turquette  * Shifts the phase of a clock signal by the specified degrees. Returns 0 on
116e59c5371SMike Turquette  * success, -EERROR otherwise.
117e59c5371SMike Turquette  */
118e59c5371SMike Turquette int clk_set_phase(struct clk *clk, int degrees);
119e59c5371SMike Turquette 
120e59c5371SMike Turquette /**
121e59c5371SMike Turquette  * clk_get_phase - return the phase shift of a clock signal
122e59c5371SMike Turquette  * @clk: clock signal source
123e59c5371SMike Turquette  *
124e59c5371SMike Turquette  * Returns the phase shift of a clock node in degrees, otherwise returns
125e59c5371SMike Turquette  * -EERROR.
126e59c5371SMike Turquette  */
127e59c5371SMike Turquette int clk_get_phase(struct clk *clk);
128e59c5371SMike Turquette 
1293d3801efSMichael Turquette /**
1303d3801efSMichael Turquette  * clk_is_match - check if two clk's point to the same hardware clock
1313d3801efSMichael Turquette  * @p: clk compared against q
1323d3801efSMichael Turquette  * @q: clk compared against p
1333d3801efSMichael Turquette  *
1343d3801efSMichael Turquette  * Returns true if the two struct clk pointers both point to the same hardware
135*0e056eb5Smchehab@s-opensource.com  * clock node. Put differently, returns true if @p and @q
136*0e056eb5Smchehab@s-opensource.com  * share the same &struct clk_core object.
1373d3801efSMichael Turquette  *
1383d3801efSMichael Turquette  * Returns false otherwise. Note that two NULL clks are treated as matching.
1393d3801efSMichael Turquette  */
1403d3801efSMichael Turquette bool clk_is_match(const struct clk *p, const struct clk *q);
1413d3801efSMichael Turquette 
1425279fc40SBoris BREZILLON #else
1435279fc40SBoris BREZILLON 
144e81b87d2SKrzysztof Kozlowski static inline int clk_notifier_register(struct clk *clk,
145e81b87d2SKrzysztof Kozlowski 					struct notifier_block *nb)
146e81b87d2SKrzysztof Kozlowski {
147e81b87d2SKrzysztof Kozlowski 	return -ENOTSUPP;
148e81b87d2SKrzysztof Kozlowski }
149e81b87d2SKrzysztof Kozlowski 
150e81b87d2SKrzysztof Kozlowski static inline int clk_notifier_unregister(struct clk *clk,
151e81b87d2SKrzysztof Kozlowski 					  struct notifier_block *nb)
152e81b87d2SKrzysztof Kozlowski {
153e81b87d2SKrzysztof Kozlowski 	return -ENOTSUPP;
154e81b87d2SKrzysztof Kozlowski }
155e81b87d2SKrzysztof Kozlowski 
1565279fc40SBoris BREZILLON static inline long clk_get_accuracy(struct clk *clk)
1575279fc40SBoris BREZILLON {
1585279fc40SBoris BREZILLON 	return -ENOTSUPP;
1595279fc40SBoris BREZILLON }
1605279fc40SBoris BREZILLON 
161e59c5371SMike Turquette static inline long clk_set_phase(struct clk *clk, int phase)
162e59c5371SMike Turquette {
163e59c5371SMike Turquette 	return -ENOTSUPP;
164e59c5371SMike Turquette }
165e59c5371SMike Turquette 
166e59c5371SMike Turquette static inline long clk_get_phase(struct clk *clk)
167e59c5371SMike Turquette {
168e59c5371SMike Turquette 	return -ENOTSUPP;
169e59c5371SMike Turquette }
170e59c5371SMike Turquette 
1713d3801efSMichael Turquette static inline bool clk_is_match(const struct clk *p, const struct clk *q)
1723d3801efSMichael Turquette {
1733d3801efSMichael Turquette 	return p == q;
1743d3801efSMichael Turquette }
1753d3801efSMichael Turquette 
1767e87aed9SMark Brown #endif
177b2476490SMike Turquette 
178f8ce2547SRussell King /**
17993abe8e4SViresh Kumar  * clk_prepare - prepare a clock source
18093abe8e4SViresh Kumar  * @clk: clock source
18193abe8e4SViresh Kumar  *
18293abe8e4SViresh Kumar  * This prepares the clock source for use.
18393abe8e4SViresh Kumar  *
18493abe8e4SViresh Kumar  * Must not be called from within atomic context.
18593abe8e4SViresh Kumar  */
18693abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE
18793abe8e4SViresh Kumar int clk_prepare(struct clk *clk);
18893abe8e4SViresh Kumar #else
18993abe8e4SViresh Kumar static inline int clk_prepare(struct clk *clk)
19093abe8e4SViresh Kumar {
19193abe8e4SViresh Kumar 	might_sleep();
19293abe8e4SViresh Kumar 	return 0;
19393abe8e4SViresh Kumar }
19493abe8e4SViresh Kumar #endif
19593abe8e4SViresh Kumar 
19693abe8e4SViresh Kumar /**
19793abe8e4SViresh Kumar  * clk_unprepare - undo preparation of a clock source
19893abe8e4SViresh Kumar  * @clk: clock source
19993abe8e4SViresh Kumar  *
20093abe8e4SViresh Kumar  * This undoes a previously prepared clock.  The caller must balance
20193abe8e4SViresh Kumar  * the number of prepare and unprepare calls.
20293abe8e4SViresh Kumar  *
20393abe8e4SViresh Kumar  * Must not be called from within atomic context.
20493abe8e4SViresh Kumar  */
20593abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE
20693abe8e4SViresh Kumar void clk_unprepare(struct clk *clk);
20793abe8e4SViresh Kumar #else
20893abe8e4SViresh Kumar static inline void clk_unprepare(struct clk *clk)
20993abe8e4SViresh Kumar {
21093abe8e4SViresh Kumar 	might_sleep();
21193abe8e4SViresh Kumar }
21293abe8e4SViresh Kumar #endif
21393abe8e4SViresh Kumar 
21493abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK
21593abe8e4SViresh Kumar /**
216f8ce2547SRussell King  * clk_get - lookup and obtain a reference to a clock producer.
217f8ce2547SRussell King  * @dev: device for clock "consumer"
218a58b3a4aSJan-Simon Möller  * @id: clock consumer ID
219f8ce2547SRussell King  *
220f8ce2547SRussell King  * Returns a struct clk corresponding to the clock producer, or
221f8ce2547SRussell King  * valid IS_ERR() condition containing errno.  The implementation
222f8ce2547SRussell King  * uses @dev and @id to determine the clock consumer, and thereby
223f8ce2547SRussell King  * the clock producer.  (IOW, @id may be identical strings, but
224f8ce2547SRussell King  * clk_get may return different clock producers depending on @dev.)
225f8ce2547SRussell King  *
226f8ce2547SRussell King  * Drivers must assume that the clock source is not enabled.
227f7ad160bSAlex Raimondi  *
228f7ad160bSAlex Raimondi  * clk_get should not be called from within interrupt context.
229f8ce2547SRussell King  */
230f8ce2547SRussell King struct clk *clk_get(struct device *dev, const char *id);
231f8ce2547SRussell King 
232f8ce2547SRussell King /**
233a8a97db9SMark Brown  * devm_clk_get - lookup and obtain a managed reference to a clock producer.
234a8a97db9SMark Brown  * @dev: device for clock "consumer"
235a58b3a4aSJan-Simon Möller  * @id: clock consumer ID
236a8a97db9SMark Brown  *
237a8a97db9SMark Brown  * Returns a struct clk corresponding to the clock producer, or
238a8a97db9SMark Brown  * valid IS_ERR() condition containing errno.  The implementation
239a8a97db9SMark Brown  * uses @dev and @id to determine the clock consumer, and thereby
240a8a97db9SMark Brown  * the clock producer.  (IOW, @id may be identical strings, but
241a8a97db9SMark Brown  * clk_get may return different clock producers depending on @dev.)
242a8a97db9SMark Brown  *
243a8a97db9SMark Brown  * Drivers must assume that the clock source is not enabled.
244a8a97db9SMark Brown  *
245a8a97db9SMark Brown  * devm_clk_get should not be called from within interrupt context.
246a8a97db9SMark Brown  *
247a8a97db9SMark Brown  * The clock will automatically be freed when the device is unbound
248a8a97db9SMark Brown  * from the bus.
249a8a97db9SMark Brown  */
250a8a97db9SMark Brown struct clk *devm_clk_get(struct device *dev, const char *id);
251a8a97db9SMark Brown 
252a8a97db9SMark Brown /**
25371a2f115SKuninori Morimoto  * devm_get_clk_from_child - lookup and obtain a managed reference to a
25471a2f115SKuninori Morimoto  *			     clock producer from child node.
25571a2f115SKuninori Morimoto  * @dev: device for clock "consumer"
25671a2f115SKuninori Morimoto  * @np: pointer to clock consumer node
25771a2f115SKuninori Morimoto  * @con_id: clock consumer ID
25871a2f115SKuninori Morimoto  *
25971a2f115SKuninori Morimoto  * This function parses the clocks, and uses them to look up the
26071a2f115SKuninori Morimoto  * struct clk from the registered list of clock providers by using
26171a2f115SKuninori Morimoto  * @np and @con_id
26271a2f115SKuninori Morimoto  *
26371a2f115SKuninori Morimoto  * The clock will automatically be freed when the device is unbound
26471a2f115SKuninori Morimoto  * from the bus.
26571a2f115SKuninori Morimoto  */
26671a2f115SKuninori Morimoto struct clk *devm_get_clk_from_child(struct device *dev,
26771a2f115SKuninori Morimoto 				    struct device_node *np, const char *con_id);
26871a2f115SKuninori Morimoto 
26971a2f115SKuninori Morimoto /**
270f8ce2547SRussell King  * clk_enable - inform the system when the clock source should be running.
271f8ce2547SRussell King  * @clk: clock source
272f8ce2547SRussell King  *
273f8ce2547SRussell King  * If the clock can not be enabled/disabled, this should return success.
274f8ce2547SRussell King  *
27540d3e0f4SRussell King  * May be called from atomic contexts.
27640d3e0f4SRussell King  *
277f8ce2547SRussell King  * Returns success (0) or negative errno.
278f8ce2547SRussell King  */
279f8ce2547SRussell King int clk_enable(struct clk *clk);
280f8ce2547SRussell King 
281f8ce2547SRussell King /**
282f8ce2547SRussell King  * clk_disable - inform the system when the clock source is no longer required.
283f8ce2547SRussell King  * @clk: clock source
284f8ce2547SRussell King  *
285f8ce2547SRussell King  * Inform the system that a clock source is no longer required by
286f8ce2547SRussell King  * a driver and may be shut down.
287f8ce2547SRussell King  *
28840d3e0f4SRussell King  * May be called from atomic contexts.
28940d3e0f4SRussell King  *
290f8ce2547SRussell King  * Implementation detail: if the clock source is shared between
291f8ce2547SRussell King  * multiple drivers, clk_enable() calls must be balanced by the
292f8ce2547SRussell King  * same number of clk_disable() calls for the clock source to be
293f8ce2547SRussell King  * disabled.
294f8ce2547SRussell King  */
295f8ce2547SRussell King void clk_disable(struct clk *clk);
296f8ce2547SRussell King 
297f8ce2547SRussell King /**
298f8ce2547SRussell King  * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
299f8ce2547SRussell King  *		  This is only valid once the clock source has been enabled.
300f8ce2547SRussell King  * @clk: clock source
301f8ce2547SRussell King  */
302f8ce2547SRussell King unsigned long clk_get_rate(struct clk *clk);
303f8ce2547SRussell King 
304f8ce2547SRussell King /**
305f8ce2547SRussell King  * clk_put	- "free" the clock source
306f8ce2547SRussell King  * @clk: clock source
307f8ce2547SRussell King  *
308f8ce2547SRussell King  * Note: drivers must ensure that all clk_enable calls made on this
309f8ce2547SRussell King  * clock source are balanced by clk_disable calls prior to calling
310f8ce2547SRussell King  * this function.
311f7ad160bSAlex Raimondi  *
312f7ad160bSAlex Raimondi  * clk_put should not be called from within interrupt context.
313f8ce2547SRussell King  */
314f8ce2547SRussell King void clk_put(struct clk *clk);
315f8ce2547SRussell King 
316a8a97db9SMark Brown /**
317a8a97db9SMark Brown  * devm_clk_put	- "free" a managed clock source
318da3dae54SMasanari Iida  * @dev: device used to acquire the clock
319a8a97db9SMark Brown  * @clk: clock source acquired with devm_clk_get()
320a8a97db9SMark Brown  *
321a8a97db9SMark Brown  * Note: drivers must ensure that all clk_enable calls made on this
322a8a97db9SMark Brown  * clock source are balanced by clk_disable calls prior to calling
323a8a97db9SMark Brown  * this function.
324a8a97db9SMark Brown  *
325a8a97db9SMark Brown  * clk_put should not be called from within interrupt context.
326a8a97db9SMark Brown  */
327a8a97db9SMark Brown void devm_clk_put(struct device *dev, struct clk *clk);
328f8ce2547SRussell King 
329f8ce2547SRussell King /*
330f8ce2547SRussell King  * The remaining APIs are optional for machine class support.
331f8ce2547SRussell King  */
332f8ce2547SRussell King 
333f8ce2547SRussell King 
334f8ce2547SRussell King /**
335f8ce2547SRussell King  * clk_round_rate - adjust a rate to the exact rate a clock can provide
336f8ce2547SRussell King  * @clk: clock source
337f8ce2547SRussell King  * @rate: desired clock rate in Hz
338f8ce2547SRussell King  *
339d2d14a77SRussell King  * This answers the question "if I were to pass @rate to clk_set_rate(),
340d2d14a77SRussell King  * what clock rate would I end up with?" without changing the hardware
341d2d14a77SRussell King  * in any way.  In other words:
342d2d14a77SRussell King  *
343d2d14a77SRussell King  *   rate = clk_round_rate(clk, r);
344d2d14a77SRussell King  *
345d2d14a77SRussell King  * and:
346d2d14a77SRussell King  *
347d2d14a77SRussell King  *   clk_set_rate(clk, r);
348d2d14a77SRussell King  *   rate = clk_get_rate(clk);
349d2d14a77SRussell King  *
350d2d14a77SRussell King  * are equivalent except the former does not modify the clock hardware
351d2d14a77SRussell King  * in any way.
352d2d14a77SRussell King  *
353f8ce2547SRussell King  * Returns rounded clock rate in Hz, or negative errno.
354f8ce2547SRussell King  */
355f8ce2547SRussell King long clk_round_rate(struct clk *clk, unsigned long rate);
356f8ce2547SRussell King 
357f8ce2547SRussell King /**
358f8ce2547SRussell King  * clk_set_rate - set the clock rate for a clock source
359f8ce2547SRussell King  * @clk: clock source
360f8ce2547SRussell King  * @rate: desired clock rate in Hz
361f8ce2547SRussell King  *
362f8ce2547SRussell King  * Returns success (0) or negative errno.
363f8ce2547SRussell King  */
364f8ce2547SRussell King int clk_set_rate(struct clk *clk, unsigned long rate);
365f8ce2547SRussell King 
366f8ce2547SRussell King /**
3674e88f3deSThierry Reding  * clk_has_parent - check if a clock is a possible parent for another
3684e88f3deSThierry Reding  * @clk: clock source
3694e88f3deSThierry Reding  * @parent: parent clock source
3704e88f3deSThierry Reding  *
3714e88f3deSThierry Reding  * This function can be used in drivers that need to check that a clock can be
3724e88f3deSThierry Reding  * the parent of another without actually changing the parent.
3734e88f3deSThierry Reding  *
3744e88f3deSThierry Reding  * Returns true if @parent is a possible parent for @clk, false otherwise.
3754e88f3deSThierry Reding  */
3764e88f3deSThierry Reding bool clk_has_parent(struct clk *clk, struct clk *parent);
3774e88f3deSThierry Reding 
3784e88f3deSThierry Reding /**
3791c8e6004STomeu Vizoso  * clk_set_rate_range - set a rate range for a clock source
3801c8e6004STomeu Vizoso  * @clk: clock source
3811c8e6004STomeu Vizoso  * @min: desired minimum clock rate in Hz, inclusive
3821c8e6004STomeu Vizoso  * @max: desired maximum clock rate in Hz, inclusive
3831c8e6004STomeu Vizoso  *
3841c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
3851c8e6004STomeu Vizoso  */
3861c8e6004STomeu Vizoso int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max);
3871c8e6004STomeu Vizoso 
3881c8e6004STomeu Vizoso /**
3891c8e6004STomeu Vizoso  * clk_set_min_rate - set a minimum clock rate for a clock source
3901c8e6004STomeu Vizoso  * @clk: clock source
3911c8e6004STomeu Vizoso  * @rate: desired minimum clock rate in Hz, inclusive
3921c8e6004STomeu Vizoso  *
3931c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
3941c8e6004STomeu Vizoso  */
3951c8e6004STomeu Vizoso int clk_set_min_rate(struct clk *clk, unsigned long rate);
3961c8e6004STomeu Vizoso 
3971c8e6004STomeu Vizoso /**
3981c8e6004STomeu Vizoso  * clk_set_max_rate - set a maximum clock rate for a clock source
3991c8e6004STomeu Vizoso  * @clk: clock source
4001c8e6004STomeu Vizoso  * @rate: desired maximum clock rate in Hz, inclusive
4011c8e6004STomeu Vizoso  *
4021c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
4031c8e6004STomeu Vizoso  */
4041c8e6004STomeu Vizoso int clk_set_max_rate(struct clk *clk, unsigned long rate);
4051c8e6004STomeu Vizoso 
4061c8e6004STomeu Vizoso /**
407f8ce2547SRussell King  * clk_set_parent - set the parent clock source for this clock
408f8ce2547SRussell King  * @clk: clock source
409f8ce2547SRussell King  * @parent: parent clock source
410f8ce2547SRussell King  *
411f8ce2547SRussell King  * Returns success (0) or negative errno.
412f8ce2547SRussell King  */
413f8ce2547SRussell King int clk_set_parent(struct clk *clk, struct clk *parent);
414f8ce2547SRussell King 
415f8ce2547SRussell King /**
416f8ce2547SRussell King  * clk_get_parent - get the parent clock source for this clock
417f8ce2547SRussell King  * @clk: clock source
418f8ce2547SRussell King  *
419f8ce2547SRussell King  * Returns struct clk corresponding to parent clock source, or
420f8ce2547SRussell King  * valid IS_ERR() condition containing errno.
421f8ce2547SRussell King  */
422f8ce2547SRussell King struct clk *clk_get_parent(struct clk *clk);
423f8ce2547SRussell King 
42405fd8e73SSascha Hauer /**
42505fd8e73SSascha Hauer  * clk_get_sys - get a clock based upon the device name
42605fd8e73SSascha Hauer  * @dev_id: device name
42705fd8e73SSascha Hauer  * @con_id: connection ID
42805fd8e73SSascha Hauer  *
42905fd8e73SSascha Hauer  * Returns a struct clk corresponding to the clock producer, or
43005fd8e73SSascha Hauer  * valid IS_ERR() condition containing errno.  The implementation
43105fd8e73SSascha Hauer  * uses @dev_id and @con_id to determine the clock consumer, and
43205fd8e73SSascha Hauer  * thereby the clock producer. In contrast to clk_get() this function
43305fd8e73SSascha Hauer  * takes the device name instead of the device itself for identification.
43405fd8e73SSascha Hauer  *
43505fd8e73SSascha Hauer  * Drivers must assume that the clock source is not enabled.
43605fd8e73SSascha Hauer  *
43705fd8e73SSascha Hauer  * clk_get_sys should not be called from within interrupt context.
43805fd8e73SSascha Hauer  */
43905fd8e73SSascha Hauer struct clk *clk_get_sys(const char *dev_id, const char *con_id);
44005fd8e73SSascha Hauer 
44193abe8e4SViresh Kumar #else /* !CONFIG_HAVE_CLK */
44293abe8e4SViresh Kumar 
44393abe8e4SViresh Kumar static inline struct clk *clk_get(struct device *dev, const char *id)
44493abe8e4SViresh Kumar {
44593abe8e4SViresh Kumar 	return NULL;
44693abe8e4SViresh Kumar }
44793abe8e4SViresh Kumar 
44893abe8e4SViresh Kumar static inline struct clk *devm_clk_get(struct device *dev, const char *id)
44993abe8e4SViresh Kumar {
45093abe8e4SViresh Kumar 	return NULL;
45193abe8e4SViresh Kumar }
45293abe8e4SViresh Kumar 
45371a2f115SKuninori Morimoto static inline struct clk *devm_get_clk_from_child(struct device *dev,
45471a2f115SKuninori Morimoto 				struct device_node *np, const char *con_id)
45571a2f115SKuninori Morimoto {
45671a2f115SKuninori Morimoto 	return NULL;
45771a2f115SKuninori Morimoto }
45871a2f115SKuninori Morimoto 
45993abe8e4SViresh Kumar static inline void clk_put(struct clk *clk) {}
46093abe8e4SViresh Kumar 
46193abe8e4SViresh Kumar static inline void devm_clk_put(struct device *dev, struct clk *clk) {}
46293abe8e4SViresh Kumar 
46393abe8e4SViresh Kumar static inline int clk_enable(struct clk *clk)
46493abe8e4SViresh Kumar {
46593abe8e4SViresh Kumar 	return 0;
46693abe8e4SViresh Kumar }
46793abe8e4SViresh Kumar 
46893abe8e4SViresh Kumar static inline void clk_disable(struct clk *clk) {}
46993abe8e4SViresh Kumar 
47093abe8e4SViresh Kumar static inline unsigned long clk_get_rate(struct clk *clk)
47193abe8e4SViresh Kumar {
47293abe8e4SViresh Kumar 	return 0;
47393abe8e4SViresh Kumar }
47493abe8e4SViresh Kumar 
47593abe8e4SViresh Kumar static inline int clk_set_rate(struct clk *clk, unsigned long rate)
47693abe8e4SViresh Kumar {
47793abe8e4SViresh Kumar 	return 0;
47893abe8e4SViresh Kumar }
47993abe8e4SViresh Kumar 
48093abe8e4SViresh Kumar static inline long clk_round_rate(struct clk *clk, unsigned long rate)
48193abe8e4SViresh Kumar {
48293abe8e4SViresh Kumar 	return 0;
48393abe8e4SViresh Kumar }
48493abe8e4SViresh Kumar 
4854e88f3deSThierry Reding static inline bool clk_has_parent(struct clk *clk, struct clk *parent)
4864e88f3deSThierry Reding {
4874e88f3deSThierry Reding 	return true;
4884e88f3deSThierry Reding }
4894e88f3deSThierry Reding 
49093abe8e4SViresh Kumar static inline int clk_set_parent(struct clk *clk, struct clk *parent)
49193abe8e4SViresh Kumar {
49293abe8e4SViresh Kumar 	return 0;
49393abe8e4SViresh Kumar }
49493abe8e4SViresh Kumar 
49593abe8e4SViresh Kumar static inline struct clk *clk_get_parent(struct clk *clk)
49693abe8e4SViresh Kumar {
49793abe8e4SViresh Kumar 	return NULL;
49893abe8e4SViresh Kumar }
49993abe8e4SViresh Kumar 
500b81ea968SDaniel Lezcano static inline struct clk *clk_get_sys(const char *dev_id, const char *con_id)
501b81ea968SDaniel Lezcano {
502b81ea968SDaniel Lezcano 	return NULL;
503b81ea968SDaniel Lezcano }
50493abe8e4SViresh Kumar #endif
50593abe8e4SViresh Kumar 
50693abe8e4SViresh Kumar /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
50793abe8e4SViresh Kumar static inline int clk_prepare_enable(struct clk *clk)
50893abe8e4SViresh Kumar {
50993abe8e4SViresh Kumar 	int ret;
51093abe8e4SViresh Kumar 
51193abe8e4SViresh Kumar 	ret = clk_prepare(clk);
51293abe8e4SViresh Kumar 	if (ret)
51393abe8e4SViresh Kumar 		return ret;
51493abe8e4SViresh Kumar 	ret = clk_enable(clk);
51593abe8e4SViresh Kumar 	if (ret)
51693abe8e4SViresh Kumar 		clk_unprepare(clk);
51793abe8e4SViresh Kumar 
51893abe8e4SViresh Kumar 	return ret;
51993abe8e4SViresh Kumar }
52093abe8e4SViresh Kumar 
52193abe8e4SViresh Kumar /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */
52293abe8e4SViresh Kumar static inline void clk_disable_unprepare(struct clk *clk)
52393abe8e4SViresh Kumar {
52493abe8e4SViresh Kumar 	clk_disable(clk);
52593abe8e4SViresh Kumar 	clk_unprepare(clk);
52693abe8e4SViresh Kumar }
52793abe8e4SViresh Kumar 
528137f8a72SRob Herring #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
529766e6a4eSGrant Likely struct clk *of_clk_get(struct device_node *np, int index);
530766e6a4eSGrant Likely struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
531766e6a4eSGrant Likely struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
532766e6a4eSGrant Likely #else
533766e6a4eSGrant Likely static inline struct clk *of_clk_get(struct device_node *np, int index)
534766e6a4eSGrant Likely {
5359f1612d3SShawn Guo 	return ERR_PTR(-ENOENT);
536766e6a4eSGrant Likely }
537766e6a4eSGrant Likely static inline struct clk *of_clk_get_by_name(struct device_node *np,
538766e6a4eSGrant Likely 					     const char *name)
539766e6a4eSGrant Likely {
5409f1612d3SShawn Guo 	return ERR_PTR(-ENOENT);
541766e6a4eSGrant Likely }
542766e6a4eSGrant Likely #endif
543766e6a4eSGrant Likely 
544f8ce2547SRussell King #endif
545