xref: /openbmc/linux/include/linux/clk.h (revision d2d14a77886485310ec66e575f00ea5232ac7a14)
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 
21f8ce2547SRussell King struct clk;
22f8ce2547SRussell King 
23b2476490SMike Turquette #ifdef CONFIG_COMMON_CLK
24b2476490SMike Turquette 
25b2476490SMike Turquette /**
26b2476490SMike Turquette  * DOC: clk notifier callback types
27b2476490SMike Turquette  *
28b2476490SMike Turquette  * PRE_RATE_CHANGE - called immediately before the clk rate is changed,
29b2476490SMike Turquette  *     to indicate that the rate change will proceed.  Drivers must
30b2476490SMike Turquette  *     immediately terminate any operations that will be affected by the
31fb72a059SSoren Brinkmann  *     rate change.  Callbacks may either return NOTIFY_DONE, NOTIFY_OK,
32fb72a059SSoren Brinkmann  *     NOTIFY_STOP or NOTIFY_BAD.
33b2476490SMike Turquette  *
34b2476490SMike Turquette  * ABORT_RATE_CHANGE: called if the rate change failed for some reason
35b2476490SMike Turquette  *     after PRE_RATE_CHANGE.  In this case, all registered notifiers on
36b2476490SMike Turquette  *     the clk will be called with ABORT_RATE_CHANGE. Callbacks must
37fb72a059SSoren Brinkmann  *     always return NOTIFY_DONE or NOTIFY_OK.
38b2476490SMike Turquette  *
39b2476490SMike Turquette  * POST_RATE_CHANGE - called after the clk rate change has successfully
40fb72a059SSoren Brinkmann  *     completed.  Callbacks must always return NOTIFY_DONE or NOTIFY_OK.
41b2476490SMike Turquette  *
42b2476490SMike Turquette  */
43b2476490SMike Turquette #define PRE_RATE_CHANGE			BIT(0)
44b2476490SMike Turquette #define POST_RATE_CHANGE		BIT(1)
45b2476490SMike Turquette #define ABORT_RATE_CHANGE		BIT(2)
46b2476490SMike Turquette 
47b2476490SMike Turquette /**
48b2476490SMike Turquette  * struct clk_notifier - associate a clk with a notifier
49b2476490SMike Turquette  * @clk: struct clk * to associate the notifier with
50b2476490SMike Turquette  * @notifier_head: a blocking_notifier_head for this clk
51b2476490SMike Turquette  * @node: linked list pointers
52b2476490SMike Turquette  *
53b2476490SMike Turquette  * A list of struct clk_notifier is maintained by the notifier code.
54b2476490SMike Turquette  * An entry is created whenever code registers the first notifier on a
55b2476490SMike Turquette  * particular @clk.  Future notifiers on that @clk are added to the
56b2476490SMike Turquette  * @notifier_head.
57b2476490SMike Turquette  */
58b2476490SMike Turquette struct clk_notifier {
59b2476490SMike Turquette 	struct clk			*clk;
60b2476490SMike Turquette 	struct srcu_notifier_head	notifier_head;
61b2476490SMike Turquette 	struct list_head		node;
62b2476490SMike Turquette };
63b2476490SMike Turquette 
64b2476490SMike Turquette /**
65b2476490SMike Turquette  * struct clk_notifier_data - rate data to pass to the notifier callback
66b2476490SMike Turquette  * @clk: struct clk * being changed
67b2476490SMike Turquette  * @old_rate: previous rate of this clk
68b2476490SMike Turquette  * @new_rate: new rate of this clk
69b2476490SMike Turquette  *
70b2476490SMike Turquette  * For a pre-notifier, old_rate is the clk's rate before this rate
71b2476490SMike Turquette  * change, and new_rate is what the rate will be in the future.  For a
72b2476490SMike Turquette  * post-notifier, old_rate and new_rate are both set to the clk's
73b2476490SMike Turquette  * current rate (this was done to optimize the implementation).
74b2476490SMike Turquette  */
75b2476490SMike Turquette struct clk_notifier_data {
76b2476490SMike Turquette 	struct clk		*clk;
77b2476490SMike Turquette 	unsigned long		old_rate;
78b2476490SMike Turquette 	unsigned long		new_rate;
79b2476490SMike Turquette };
80b2476490SMike Turquette 
8186bcfa2eSMike Turquette /**
8286bcfa2eSMike Turquette  * clk_notifier_register: register a clock rate-change notifier callback
8386bcfa2eSMike Turquette  * @clk: clock whose rate we are interested in
8486bcfa2eSMike Turquette  * @nb: notifier block with callback function pointer
8586bcfa2eSMike Turquette  *
8686bcfa2eSMike Turquette  * ProTip: debugging across notifier chains can be frustrating. Make sure that
8786bcfa2eSMike Turquette  * your notifier callback function prints a nice big warning in case of
8886bcfa2eSMike Turquette  * failure.
8986bcfa2eSMike Turquette  */
90b2476490SMike Turquette int clk_notifier_register(struct clk *clk, struct notifier_block *nb);
91b2476490SMike Turquette 
9286bcfa2eSMike Turquette /**
9386bcfa2eSMike Turquette  * clk_notifier_unregister: unregister a clock rate-change notifier callback
9486bcfa2eSMike Turquette  * @clk: clock whose rate we are no longer interested in
9586bcfa2eSMike Turquette  * @nb: notifier block which will be unregistered
9686bcfa2eSMike Turquette  */
97b2476490SMike Turquette int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb);
98b2476490SMike Turquette 
995279fc40SBoris BREZILLON /**
1005279fc40SBoris BREZILLON  * clk_get_accuracy - obtain the clock accuracy in ppb (parts per billion)
1015279fc40SBoris BREZILLON  *		      for a clock source.
1025279fc40SBoris BREZILLON  * @clk: clock source
1035279fc40SBoris BREZILLON  *
1045279fc40SBoris BREZILLON  * This gets the clock source accuracy expressed in ppb.
1055279fc40SBoris BREZILLON  * A perfect clock returns 0.
1065279fc40SBoris BREZILLON  */
1075279fc40SBoris BREZILLON long clk_get_accuracy(struct clk *clk);
1085279fc40SBoris BREZILLON 
109e59c5371SMike Turquette /**
110e59c5371SMike Turquette  * clk_set_phase - adjust the phase shift of a clock signal
111e59c5371SMike Turquette  * @clk: clock signal source
112e59c5371SMike Turquette  * @degrees: number of degrees the signal is shifted
113e59c5371SMike Turquette  *
114e59c5371SMike Turquette  * Shifts the phase of a clock signal by the specified degrees. Returns 0 on
115e59c5371SMike Turquette  * success, -EERROR otherwise.
116e59c5371SMike Turquette  */
117e59c5371SMike Turquette int clk_set_phase(struct clk *clk, int degrees);
118e59c5371SMike Turquette 
119e59c5371SMike Turquette /**
120e59c5371SMike Turquette  * clk_get_phase - return the phase shift of a clock signal
121e59c5371SMike Turquette  * @clk: clock signal source
122e59c5371SMike Turquette  *
123e59c5371SMike Turquette  * Returns the phase shift of a clock node in degrees, otherwise returns
124e59c5371SMike Turquette  * -EERROR.
125e59c5371SMike Turquette  */
126e59c5371SMike Turquette int clk_get_phase(struct clk *clk);
127e59c5371SMike Turquette 
1283d3801efSMichael Turquette /**
1293d3801efSMichael Turquette  * clk_is_match - check if two clk's point to the same hardware clock
1303d3801efSMichael Turquette  * @p: clk compared against q
1313d3801efSMichael Turquette  * @q: clk compared against p
1323d3801efSMichael Turquette  *
1333d3801efSMichael Turquette  * Returns true if the two struct clk pointers both point to the same hardware
1343d3801efSMichael Turquette  * clock node. Put differently, returns true if struct clk *p and struct clk *q
1353d3801efSMichael Turquette  * share the same struct clk_core object.
1363d3801efSMichael Turquette  *
1373d3801efSMichael Turquette  * Returns false otherwise. Note that two NULL clks are treated as matching.
1383d3801efSMichael Turquette  */
1393d3801efSMichael Turquette bool clk_is_match(const struct clk *p, const struct clk *q);
1403d3801efSMichael Turquette 
1415279fc40SBoris BREZILLON #else
1425279fc40SBoris BREZILLON 
1435279fc40SBoris BREZILLON static inline long clk_get_accuracy(struct clk *clk)
1445279fc40SBoris BREZILLON {
1455279fc40SBoris BREZILLON 	return -ENOTSUPP;
1465279fc40SBoris BREZILLON }
1475279fc40SBoris BREZILLON 
148e59c5371SMike Turquette static inline long clk_set_phase(struct clk *clk, int phase)
149e59c5371SMike Turquette {
150e59c5371SMike Turquette 	return -ENOTSUPP;
151e59c5371SMike Turquette }
152e59c5371SMike Turquette 
153e59c5371SMike Turquette static inline long clk_get_phase(struct clk *clk)
154e59c5371SMike Turquette {
155e59c5371SMike Turquette 	return -ENOTSUPP;
156e59c5371SMike Turquette }
157e59c5371SMike Turquette 
1583d3801efSMichael Turquette static inline bool clk_is_match(const struct clk *p, const struct clk *q)
1593d3801efSMichael Turquette {
1603d3801efSMichael Turquette 	return p == q;
1613d3801efSMichael Turquette }
1623d3801efSMichael Turquette 
1637e87aed9SMark Brown #endif
164b2476490SMike Turquette 
165f8ce2547SRussell King /**
16693abe8e4SViresh Kumar  * clk_prepare - prepare a clock source
16793abe8e4SViresh Kumar  * @clk: clock source
16893abe8e4SViresh Kumar  *
16993abe8e4SViresh Kumar  * This prepares the clock source for use.
17093abe8e4SViresh Kumar  *
17193abe8e4SViresh Kumar  * Must not be called from within atomic context.
17293abe8e4SViresh Kumar  */
17393abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE
17493abe8e4SViresh Kumar int clk_prepare(struct clk *clk);
17593abe8e4SViresh Kumar #else
17693abe8e4SViresh Kumar static inline int clk_prepare(struct clk *clk)
17793abe8e4SViresh Kumar {
17893abe8e4SViresh Kumar 	might_sleep();
17993abe8e4SViresh Kumar 	return 0;
18093abe8e4SViresh Kumar }
18193abe8e4SViresh Kumar #endif
18293abe8e4SViresh Kumar 
18393abe8e4SViresh Kumar /**
18493abe8e4SViresh Kumar  * clk_unprepare - undo preparation of a clock source
18593abe8e4SViresh Kumar  * @clk: clock source
18693abe8e4SViresh Kumar  *
18793abe8e4SViresh Kumar  * This undoes a previously prepared clock.  The caller must balance
18893abe8e4SViresh Kumar  * the number of prepare and unprepare calls.
18993abe8e4SViresh Kumar  *
19093abe8e4SViresh Kumar  * Must not be called from within atomic context.
19193abe8e4SViresh Kumar  */
19293abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE
19393abe8e4SViresh Kumar void clk_unprepare(struct clk *clk);
19493abe8e4SViresh Kumar #else
19593abe8e4SViresh Kumar static inline void clk_unprepare(struct clk *clk)
19693abe8e4SViresh Kumar {
19793abe8e4SViresh Kumar 	might_sleep();
19893abe8e4SViresh Kumar }
19993abe8e4SViresh Kumar #endif
20093abe8e4SViresh Kumar 
20193abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK
20293abe8e4SViresh Kumar /**
203f8ce2547SRussell King  * clk_get - lookup and obtain a reference to a clock producer.
204f8ce2547SRussell King  * @dev: device for clock "consumer"
205a58b3a4aSJan-Simon Möller  * @id: clock consumer ID
206f8ce2547SRussell King  *
207f8ce2547SRussell King  * Returns a struct clk corresponding to the clock producer, or
208f8ce2547SRussell King  * valid IS_ERR() condition containing errno.  The implementation
209f8ce2547SRussell King  * uses @dev and @id to determine the clock consumer, and thereby
210f8ce2547SRussell King  * the clock producer.  (IOW, @id may be identical strings, but
211f8ce2547SRussell King  * clk_get may return different clock producers depending on @dev.)
212f8ce2547SRussell King  *
213f8ce2547SRussell King  * Drivers must assume that the clock source is not enabled.
214f7ad160bSAlex Raimondi  *
215f7ad160bSAlex Raimondi  * clk_get should not be called from within interrupt context.
216f8ce2547SRussell King  */
217f8ce2547SRussell King struct clk *clk_get(struct device *dev, const char *id);
218f8ce2547SRussell King 
219f8ce2547SRussell King /**
220a8a97db9SMark Brown  * devm_clk_get - lookup and obtain a managed reference to a clock producer.
221a8a97db9SMark Brown  * @dev: device for clock "consumer"
222a58b3a4aSJan-Simon Möller  * @id: clock consumer ID
223a8a97db9SMark Brown  *
224a8a97db9SMark Brown  * Returns a struct clk corresponding to the clock producer, or
225a8a97db9SMark Brown  * valid IS_ERR() condition containing errno.  The implementation
226a8a97db9SMark Brown  * uses @dev and @id to determine the clock consumer, and thereby
227a8a97db9SMark Brown  * the clock producer.  (IOW, @id may be identical strings, but
228a8a97db9SMark Brown  * clk_get may return different clock producers depending on @dev.)
229a8a97db9SMark Brown  *
230a8a97db9SMark Brown  * Drivers must assume that the clock source is not enabled.
231a8a97db9SMark Brown  *
232a8a97db9SMark Brown  * devm_clk_get should not be called from within interrupt context.
233a8a97db9SMark Brown  *
234a8a97db9SMark Brown  * The clock will automatically be freed when the device is unbound
235a8a97db9SMark Brown  * from the bus.
236a8a97db9SMark Brown  */
237a8a97db9SMark Brown struct clk *devm_clk_get(struct device *dev, const char *id);
238a8a97db9SMark Brown 
239a8a97db9SMark Brown /**
240f8ce2547SRussell King  * clk_enable - inform the system when the clock source should be running.
241f8ce2547SRussell King  * @clk: clock source
242f8ce2547SRussell King  *
243f8ce2547SRussell King  * If the clock can not be enabled/disabled, this should return success.
244f8ce2547SRussell King  *
24540d3e0f4SRussell King  * May be called from atomic contexts.
24640d3e0f4SRussell King  *
247f8ce2547SRussell King  * Returns success (0) or negative errno.
248f8ce2547SRussell King  */
249f8ce2547SRussell King int clk_enable(struct clk *clk);
250f8ce2547SRussell King 
251f8ce2547SRussell King /**
252f8ce2547SRussell King  * clk_disable - inform the system when the clock source is no longer required.
253f8ce2547SRussell King  * @clk: clock source
254f8ce2547SRussell King  *
255f8ce2547SRussell King  * Inform the system that a clock source is no longer required by
256f8ce2547SRussell King  * a driver and may be shut down.
257f8ce2547SRussell King  *
25840d3e0f4SRussell King  * May be called from atomic contexts.
25940d3e0f4SRussell King  *
260f8ce2547SRussell King  * Implementation detail: if the clock source is shared between
261f8ce2547SRussell King  * multiple drivers, clk_enable() calls must be balanced by the
262f8ce2547SRussell King  * same number of clk_disable() calls for the clock source to be
263f8ce2547SRussell King  * disabled.
264f8ce2547SRussell King  */
265f8ce2547SRussell King void clk_disable(struct clk *clk);
266f8ce2547SRussell King 
267f8ce2547SRussell King /**
268f8ce2547SRussell King  * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
269f8ce2547SRussell King  *		  This is only valid once the clock source has been enabled.
270f8ce2547SRussell King  * @clk: clock source
271f8ce2547SRussell King  */
272f8ce2547SRussell King unsigned long clk_get_rate(struct clk *clk);
273f8ce2547SRussell King 
274f8ce2547SRussell King /**
275f8ce2547SRussell King  * clk_put	- "free" the clock source
276f8ce2547SRussell King  * @clk: clock source
277f8ce2547SRussell King  *
278f8ce2547SRussell King  * Note: drivers must ensure that all clk_enable calls made on this
279f8ce2547SRussell King  * clock source are balanced by clk_disable calls prior to calling
280f8ce2547SRussell King  * this function.
281f7ad160bSAlex Raimondi  *
282f7ad160bSAlex Raimondi  * clk_put should not be called from within interrupt context.
283f8ce2547SRussell King  */
284f8ce2547SRussell King void clk_put(struct clk *clk);
285f8ce2547SRussell King 
286a8a97db9SMark Brown /**
287a8a97db9SMark Brown  * devm_clk_put	- "free" a managed clock source
288da3dae54SMasanari Iida  * @dev: device used to acquire the clock
289a8a97db9SMark Brown  * @clk: clock source acquired with devm_clk_get()
290a8a97db9SMark Brown  *
291a8a97db9SMark Brown  * Note: drivers must ensure that all clk_enable calls made on this
292a8a97db9SMark Brown  * clock source are balanced by clk_disable calls prior to calling
293a8a97db9SMark Brown  * this function.
294a8a97db9SMark Brown  *
295a8a97db9SMark Brown  * clk_put should not be called from within interrupt context.
296a8a97db9SMark Brown  */
297a8a97db9SMark Brown void devm_clk_put(struct device *dev, struct clk *clk);
298f8ce2547SRussell King 
299f8ce2547SRussell King /*
300f8ce2547SRussell King  * The remaining APIs are optional for machine class support.
301f8ce2547SRussell King  */
302f8ce2547SRussell King 
303f8ce2547SRussell King 
304f8ce2547SRussell King /**
305f8ce2547SRussell King  * clk_round_rate - adjust a rate to the exact rate a clock can provide
306f8ce2547SRussell King  * @clk: clock source
307f8ce2547SRussell King  * @rate: desired clock rate in Hz
308f8ce2547SRussell King  *
309*d2d14a77SRussell King  * This answers the question "if I were to pass @rate to clk_set_rate(),
310*d2d14a77SRussell King  * what clock rate would I end up with?" without changing the hardware
311*d2d14a77SRussell King  * in any way.  In other words:
312*d2d14a77SRussell King  *
313*d2d14a77SRussell King  *   rate = clk_round_rate(clk, r);
314*d2d14a77SRussell King  *
315*d2d14a77SRussell King  * and:
316*d2d14a77SRussell King  *
317*d2d14a77SRussell King  *   clk_set_rate(clk, r);
318*d2d14a77SRussell King  *   rate = clk_get_rate(clk);
319*d2d14a77SRussell King  *
320*d2d14a77SRussell King  * are equivalent except the former does not modify the clock hardware
321*d2d14a77SRussell King  * in any way.
322*d2d14a77SRussell King  *
323f8ce2547SRussell King  * Returns rounded clock rate in Hz, or negative errno.
324f8ce2547SRussell King  */
325f8ce2547SRussell King long clk_round_rate(struct clk *clk, unsigned long rate);
326f8ce2547SRussell King 
327f8ce2547SRussell King /**
328f8ce2547SRussell King  * clk_set_rate - set the clock rate for a clock source
329f8ce2547SRussell King  * @clk: clock source
330f8ce2547SRussell King  * @rate: desired clock rate in Hz
331f8ce2547SRussell King  *
332f8ce2547SRussell King  * Returns success (0) or negative errno.
333f8ce2547SRussell King  */
334f8ce2547SRussell King int clk_set_rate(struct clk *clk, unsigned long rate);
335f8ce2547SRussell King 
336f8ce2547SRussell King /**
3374e88f3deSThierry Reding  * clk_has_parent - check if a clock is a possible parent for another
3384e88f3deSThierry Reding  * @clk: clock source
3394e88f3deSThierry Reding  * @parent: parent clock source
3404e88f3deSThierry Reding  *
3414e88f3deSThierry Reding  * This function can be used in drivers that need to check that a clock can be
3424e88f3deSThierry Reding  * the parent of another without actually changing the parent.
3434e88f3deSThierry Reding  *
3444e88f3deSThierry Reding  * Returns true if @parent is a possible parent for @clk, false otherwise.
3454e88f3deSThierry Reding  */
3464e88f3deSThierry Reding bool clk_has_parent(struct clk *clk, struct clk *parent);
3474e88f3deSThierry Reding 
3484e88f3deSThierry Reding /**
3491c8e6004STomeu Vizoso  * clk_set_rate_range - set a rate range for a clock source
3501c8e6004STomeu Vizoso  * @clk: clock source
3511c8e6004STomeu Vizoso  * @min: desired minimum clock rate in Hz, inclusive
3521c8e6004STomeu Vizoso  * @max: desired maximum clock rate in Hz, inclusive
3531c8e6004STomeu Vizoso  *
3541c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
3551c8e6004STomeu Vizoso  */
3561c8e6004STomeu Vizoso int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max);
3571c8e6004STomeu Vizoso 
3581c8e6004STomeu Vizoso /**
3591c8e6004STomeu Vizoso  * clk_set_min_rate - set a minimum clock rate for a clock source
3601c8e6004STomeu Vizoso  * @clk: clock source
3611c8e6004STomeu Vizoso  * @rate: desired minimum clock rate in Hz, inclusive
3621c8e6004STomeu Vizoso  *
3631c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
3641c8e6004STomeu Vizoso  */
3651c8e6004STomeu Vizoso int clk_set_min_rate(struct clk *clk, unsigned long rate);
3661c8e6004STomeu Vizoso 
3671c8e6004STomeu Vizoso /**
3681c8e6004STomeu Vizoso  * clk_set_max_rate - set a maximum clock rate for a clock source
3691c8e6004STomeu Vizoso  * @clk: clock source
3701c8e6004STomeu Vizoso  * @rate: desired maximum clock rate in Hz, inclusive
3711c8e6004STomeu Vizoso  *
3721c8e6004STomeu Vizoso  * Returns success (0) or negative errno.
3731c8e6004STomeu Vizoso  */
3741c8e6004STomeu Vizoso int clk_set_max_rate(struct clk *clk, unsigned long rate);
3751c8e6004STomeu Vizoso 
3761c8e6004STomeu Vizoso /**
377f8ce2547SRussell King  * clk_set_parent - set the parent clock source for this clock
378f8ce2547SRussell King  * @clk: clock source
379f8ce2547SRussell King  * @parent: parent clock source
380f8ce2547SRussell King  *
381f8ce2547SRussell King  * Returns success (0) or negative errno.
382f8ce2547SRussell King  */
383f8ce2547SRussell King int clk_set_parent(struct clk *clk, struct clk *parent);
384f8ce2547SRussell King 
385f8ce2547SRussell King /**
386f8ce2547SRussell King  * clk_get_parent - get the parent clock source for this clock
387f8ce2547SRussell King  * @clk: clock source
388f8ce2547SRussell King  *
389f8ce2547SRussell King  * Returns struct clk corresponding to parent clock source, or
390f8ce2547SRussell King  * valid IS_ERR() condition containing errno.
391f8ce2547SRussell King  */
392f8ce2547SRussell King struct clk *clk_get_parent(struct clk *clk);
393f8ce2547SRussell King 
39405fd8e73SSascha Hauer /**
39505fd8e73SSascha Hauer  * clk_get_sys - get a clock based upon the device name
39605fd8e73SSascha Hauer  * @dev_id: device name
39705fd8e73SSascha Hauer  * @con_id: connection ID
39805fd8e73SSascha Hauer  *
39905fd8e73SSascha Hauer  * Returns a struct clk corresponding to the clock producer, or
40005fd8e73SSascha Hauer  * valid IS_ERR() condition containing errno.  The implementation
40105fd8e73SSascha Hauer  * uses @dev_id and @con_id to determine the clock consumer, and
40205fd8e73SSascha Hauer  * thereby the clock producer. In contrast to clk_get() this function
40305fd8e73SSascha Hauer  * takes the device name instead of the device itself for identification.
40405fd8e73SSascha Hauer  *
40505fd8e73SSascha Hauer  * Drivers must assume that the clock source is not enabled.
40605fd8e73SSascha Hauer  *
40705fd8e73SSascha Hauer  * clk_get_sys should not be called from within interrupt context.
40805fd8e73SSascha Hauer  */
40905fd8e73SSascha Hauer struct clk *clk_get_sys(const char *dev_id, const char *con_id);
41005fd8e73SSascha Hauer 
41193abe8e4SViresh Kumar #else /* !CONFIG_HAVE_CLK */
41293abe8e4SViresh Kumar 
41393abe8e4SViresh Kumar static inline struct clk *clk_get(struct device *dev, const char *id)
41493abe8e4SViresh Kumar {
41593abe8e4SViresh Kumar 	return NULL;
41693abe8e4SViresh Kumar }
41793abe8e4SViresh Kumar 
41893abe8e4SViresh Kumar static inline struct clk *devm_clk_get(struct device *dev, const char *id)
41993abe8e4SViresh Kumar {
42093abe8e4SViresh Kumar 	return NULL;
42193abe8e4SViresh Kumar }
42293abe8e4SViresh Kumar 
42393abe8e4SViresh Kumar static inline void clk_put(struct clk *clk) {}
42493abe8e4SViresh Kumar 
42593abe8e4SViresh Kumar static inline void devm_clk_put(struct device *dev, struct clk *clk) {}
42693abe8e4SViresh Kumar 
42793abe8e4SViresh Kumar static inline int clk_enable(struct clk *clk)
42893abe8e4SViresh Kumar {
42993abe8e4SViresh Kumar 	return 0;
43093abe8e4SViresh Kumar }
43193abe8e4SViresh Kumar 
43293abe8e4SViresh Kumar static inline void clk_disable(struct clk *clk) {}
43393abe8e4SViresh Kumar 
43493abe8e4SViresh Kumar static inline unsigned long clk_get_rate(struct clk *clk)
43593abe8e4SViresh Kumar {
43693abe8e4SViresh Kumar 	return 0;
43793abe8e4SViresh Kumar }
43893abe8e4SViresh Kumar 
43993abe8e4SViresh Kumar static inline int clk_set_rate(struct clk *clk, unsigned long rate)
44093abe8e4SViresh Kumar {
44193abe8e4SViresh Kumar 	return 0;
44293abe8e4SViresh Kumar }
44393abe8e4SViresh Kumar 
44493abe8e4SViresh Kumar static inline long clk_round_rate(struct clk *clk, unsigned long rate)
44593abe8e4SViresh Kumar {
44693abe8e4SViresh Kumar 	return 0;
44793abe8e4SViresh Kumar }
44893abe8e4SViresh Kumar 
4494e88f3deSThierry Reding static inline bool clk_has_parent(struct clk *clk, struct clk *parent)
4504e88f3deSThierry Reding {
4514e88f3deSThierry Reding 	return true;
4524e88f3deSThierry Reding }
4534e88f3deSThierry Reding 
45493abe8e4SViresh Kumar static inline int clk_set_parent(struct clk *clk, struct clk *parent)
45593abe8e4SViresh Kumar {
45693abe8e4SViresh Kumar 	return 0;
45793abe8e4SViresh Kumar }
45893abe8e4SViresh Kumar 
45993abe8e4SViresh Kumar static inline struct clk *clk_get_parent(struct clk *clk)
46093abe8e4SViresh Kumar {
46193abe8e4SViresh Kumar 	return NULL;
46293abe8e4SViresh Kumar }
46393abe8e4SViresh Kumar 
46493abe8e4SViresh Kumar #endif
46593abe8e4SViresh Kumar 
46693abe8e4SViresh Kumar /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
46793abe8e4SViresh Kumar static inline int clk_prepare_enable(struct clk *clk)
46893abe8e4SViresh Kumar {
46993abe8e4SViresh Kumar 	int ret;
47093abe8e4SViresh Kumar 
47193abe8e4SViresh Kumar 	ret = clk_prepare(clk);
47293abe8e4SViresh Kumar 	if (ret)
47393abe8e4SViresh Kumar 		return ret;
47493abe8e4SViresh Kumar 	ret = clk_enable(clk);
47593abe8e4SViresh Kumar 	if (ret)
47693abe8e4SViresh Kumar 		clk_unprepare(clk);
47793abe8e4SViresh Kumar 
47893abe8e4SViresh Kumar 	return ret;
47993abe8e4SViresh Kumar }
48093abe8e4SViresh Kumar 
48193abe8e4SViresh Kumar /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */
48293abe8e4SViresh Kumar static inline void clk_disable_unprepare(struct clk *clk)
48393abe8e4SViresh Kumar {
48493abe8e4SViresh Kumar 	clk_disable(clk);
48593abe8e4SViresh Kumar 	clk_unprepare(clk);
48693abe8e4SViresh Kumar }
48793abe8e4SViresh Kumar 
488c0683039STony Lindgren /**
489c0683039STony Lindgren  * clk_add_alias - add a new clock alias
490c0683039STony Lindgren  * @alias: name for clock alias
491c0683039STony Lindgren  * @alias_dev_name: device name
492c0683039STony Lindgren  * @id: platform specific clock name
493c0683039STony Lindgren  * @dev: device
494c0683039STony Lindgren  *
495c0683039STony Lindgren  * Allows using generic clock names for drivers by adding a new alias.
496c0683039STony Lindgren  * Assumes clkdev, see clkdev.h for more info.
497c0683039STony Lindgren  */
498c0683039STony Lindgren int clk_add_alias(const char *alias, const char *alias_dev_name, char *id,
499c0683039STony Lindgren 			struct device *dev);
500c0683039STony Lindgren 
501766e6a4eSGrant Likely struct device_node;
502766e6a4eSGrant Likely struct of_phandle_args;
503766e6a4eSGrant Likely 
504137f8a72SRob Herring #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
505766e6a4eSGrant Likely struct clk *of_clk_get(struct device_node *np, int index);
506766e6a4eSGrant Likely struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
507766e6a4eSGrant Likely struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
508766e6a4eSGrant Likely #else
509766e6a4eSGrant Likely static inline struct clk *of_clk_get(struct device_node *np, int index)
510766e6a4eSGrant Likely {
5119f1612d3SShawn Guo 	return ERR_PTR(-ENOENT);
512766e6a4eSGrant Likely }
513766e6a4eSGrant Likely static inline struct clk *of_clk_get_by_name(struct device_node *np,
514766e6a4eSGrant Likely 					     const char *name)
515766e6a4eSGrant Likely {
5169f1612d3SShawn Guo 	return ERR_PTR(-ENOENT);
517766e6a4eSGrant Likely }
518766e6a4eSGrant Likely #endif
519766e6a4eSGrant Likely 
520f8ce2547SRussell King #endif
521