xref: /openbmc/linux/include/linux/clk.h (revision e59c5371fb9d8268d1c043172e88cecab9dc934f)
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 
109*e59c5371SMike Turquette /**
110*e59c5371SMike Turquette  * clk_set_phase - adjust the phase shift of a clock signal
111*e59c5371SMike Turquette  * @clk: clock signal source
112*e59c5371SMike Turquette  * @degrees: number of degrees the signal is shifted
113*e59c5371SMike Turquette  *
114*e59c5371SMike Turquette  * Shifts the phase of a clock signal by the specified degrees. Returns 0 on
115*e59c5371SMike Turquette  * success, -EERROR otherwise.
116*e59c5371SMike Turquette  */
117*e59c5371SMike Turquette int clk_set_phase(struct clk *clk, int degrees);
118*e59c5371SMike Turquette 
119*e59c5371SMike Turquette /**
120*e59c5371SMike Turquette  * clk_get_phase - return the phase shift of a clock signal
121*e59c5371SMike Turquette  * @clk: clock signal source
122*e59c5371SMike Turquette  *
123*e59c5371SMike Turquette  * Returns the phase shift of a clock node in degrees, otherwise returns
124*e59c5371SMike Turquette  * -EERROR.
125*e59c5371SMike Turquette  */
126*e59c5371SMike Turquette int clk_get_phase(struct clk *clk);
127*e59c5371SMike Turquette 
1285279fc40SBoris BREZILLON #else
1295279fc40SBoris BREZILLON 
1305279fc40SBoris BREZILLON static inline long clk_get_accuracy(struct clk *clk)
1315279fc40SBoris BREZILLON {
1325279fc40SBoris BREZILLON 	return -ENOTSUPP;
1335279fc40SBoris BREZILLON }
1345279fc40SBoris BREZILLON 
135*e59c5371SMike Turquette static inline long clk_set_phase(struct clk *clk, int phase)
136*e59c5371SMike Turquette {
137*e59c5371SMike Turquette 	return -ENOTSUPP;
138*e59c5371SMike Turquette }
139*e59c5371SMike Turquette 
140*e59c5371SMike Turquette static inline long clk_get_phase(struct clk *clk)
141*e59c5371SMike Turquette {
142*e59c5371SMike Turquette 	return -ENOTSUPP;
143*e59c5371SMike Turquette }
144*e59c5371SMike Turquette 
1457e87aed9SMark Brown #endif
146b2476490SMike Turquette 
147f8ce2547SRussell King /**
14893abe8e4SViresh Kumar  * clk_prepare - prepare a clock source
14993abe8e4SViresh Kumar  * @clk: clock source
15093abe8e4SViresh Kumar  *
15193abe8e4SViresh Kumar  * This prepares the clock source for use.
15293abe8e4SViresh Kumar  *
15393abe8e4SViresh Kumar  * Must not be called from within atomic context.
15493abe8e4SViresh Kumar  */
15593abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE
15693abe8e4SViresh Kumar int clk_prepare(struct clk *clk);
15793abe8e4SViresh Kumar #else
15893abe8e4SViresh Kumar static inline int clk_prepare(struct clk *clk)
15993abe8e4SViresh Kumar {
16093abe8e4SViresh Kumar 	might_sleep();
16193abe8e4SViresh Kumar 	return 0;
16293abe8e4SViresh Kumar }
16393abe8e4SViresh Kumar #endif
16493abe8e4SViresh Kumar 
16593abe8e4SViresh Kumar /**
16693abe8e4SViresh Kumar  * clk_unprepare - undo preparation of a clock source
16793abe8e4SViresh Kumar  * @clk: clock source
16893abe8e4SViresh Kumar  *
16993abe8e4SViresh Kumar  * This undoes a previously prepared clock.  The caller must balance
17093abe8e4SViresh Kumar  * the number of prepare and unprepare calls.
17193abe8e4SViresh Kumar  *
17293abe8e4SViresh Kumar  * Must not be called from within atomic context.
17393abe8e4SViresh Kumar  */
17493abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE
17593abe8e4SViresh Kumar void clk_unprepare(struct clk *clk);
17693abe8e4SViresh Kumar #else
17793abe8e4SViresh Kumar static inline void clk_unprepare(struct clk *clk)
17893abe8e4SViresh Kumar {
17993abe8e4SViresh Kumar 	might_sleep();
18093abe8e4SViresh Kumar }
18193abe8e4SViresh Kumar #endif
18293abe8e4SViresh Kumar 
18393abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK
18493abe8e4SViresh Kumar /**
185f8ce2547SRussell King  * clk_get - lookup and obtain a reference to a clock producer.
186f8ce2547SRussell King  * @dev: device for clock "consumer"
187a58b3a4aSJan-Simon Möller  * @id: clock consumer ID
188f8ce2547SRussell King  *
189f8ce2547SRussell King  * Returns a struct clk corresponding to the clock producer, or
190f8ce2547SRussell King  * valid IS_ERR() condition containing errno.  The implementation
191f8ce2547SRussell King  * uses @dev and @id to determine the clock consumer, and thereby
192f8ce2547SRussell King  * the clock producer.  (IOW, @id may be identical strings, but
193f8ce2547SRussell King  * clk_get may return different clock producers depending on @dev.)
194f8ce2547SRussell King  *
195f8ce2547SRussell King  * Drivers must assume that the clock source is not enabled.
196f7ad160bSAlex Raimondi  *
197f7ad160bSAlex Raimondi  * clk_get should not be called from within interrupt context.
198f8ce2547SRussell King  */
199f8ce2547SRussell King struct clk *clk_get(struct device *dev, const char *id);
200f8ce2547SRussell King 
201f8ce2547SRussell King /**
202a8a97db9SMark Brown  * devm_clk_get - lookup and obtain a managed reference to a clock producer.
203a8a97db9SMark Brown  * @dev: device for clock "consumer"
204a58b3a4aSJan-Simon Möller  * @id: clock consumer ID
205a8a97db9SMark Brown  *
206a8a97db9SMark Brown  * Returns a struct clk corresponding to the clock producer, or
207a8a97db9SMark Brown  * valid IS_ERR() condition containing errno.  The implementation
208a8a97db9SMark Brown  * uses @dev and @id to determine the clock consumer, and thereby
209a8a97db9SMark Brown  * the clock producer.  (IOW, @id may be identical strings, but
210a8a97db9SMark Brown  * clk_get may return different clock producers depending on @dev.)
211a8a97db9SMark Brown  *
212a8a97db9SMark Brown  * Drivers must assume that the clock source is not enabled.
213a8a97db9SMark Brown  *
214a8a97db9SMark Brown  * devm_clk_get should not be called from within interrupt context.
215a8a97db9SMark Brown  *
216a8a97db9SMark Brown  * The clock will automatically be freed when the device is unbound
217a8a97db9SMark Brown  * from the bus.
218a8a97db9SMark Brown  */
219a8a97db9SMark Brown struct clk *devm_clk_get(struct device *dev, const char *id);
220a8a97db9SMark Brown 
221a8a97db9SMark Brown /**
222f8ce2547SRussell King  * clk_enable - inform the system when the clock source should be running.
223f8ce2547SRussell King  * @clk: clock source
224f8ce2547SRussell King  *
225f8ce2547SRussell King  * If the clock can not be enabled/disabled, this should return success.
226f8ce2547SRussell King  *
22740d3e0f4SRussell King  * May be called from atomic contexts.
22840d3e0f4SRussell King  *
229f8ce2547SRussell King  * Returns success (0) or negative errno.
230f8ce2547SRussell King  */
231f8ce2547SRussell King int clk_enable(struct clk *clk);
232f8ce2547SRussell King 
233f8ce2547SRussell King /**
234f8ce2547SRussell King  * clk_disable - inform the system when the clock source is no longer required.
235f8ce2547SRussell King  * @clk: clock source
236f8ce2547SRussell King  *
237f8ce2547SRussell King  * Inform the system that a clock source is no longer required by
238f8ce2547SRussell King  * a driver and may be shut down.
239f8ce2547SRussell King  *
24040d3e0f4SRussell King  * May be called from atomic contexts.
24140d3e0f4SRussell King  *
242f8ce2547SRussell King  * Implementation detail: if the clock source is shared between
243f8ce2547SRussell King  * multiple drivers, clk_enable() calls must be balanced by the
244f8ce2547SRussell King  * same number of clk_disable() calls for the clock source to be
245f8ce2547SRussell King  * disabled.
246f8ce2547SRussell King  */
247f8ce2547SRussell King void clk_disable(struct clk *clk);
248f8ce2547SRussell King 
249f8ce2547SRussell King /**
250f8ce2547SRussell King  * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
251f8ce2547SRussell King  *		  This is only valid once the clock source has been enabled.
252f8ce2547SRussell King  * @clk: clock source
253f8ce2547SRussell King  */
254f8ce2547SRussell King unsigned long clk_get_rate(struct clk *clk);
255f8ce2547SRussell King 
256f8ce2547SRussell King /**
257f8ce2547SRussell King  * clk_put	- "free" the clock source
258f8ce2547SRussell King  * @clk: clock source
259f8ce2547SRussell King  *
260f8ce2547SRussell King  * Note: drivers must ensure that all clk_enable calls made on this
261f8ce2547SRussell King  * clock source are balanced by clk_disable calls prior to calling
262f8ce2547SRussell King  * this function.
263f7ad160bSAlex Raimondi  *
264f7ad160bSAlex Raimondi  * clk_put should not be called from within interrupt context.
265f8ce2547SRussell King  */
266f8ce2547SRussell King void clk_put(struct clk *clk);
267f8ce2547SRussell King 
268a8a97db9SMark Brown /**
269a8a97db9SMark Brown  * devm_clk_put	- "free" a managed clock source
270a8a97db9SMark Brown  * @dev: device used to acuqire the clock
271a8a97db9SMark Brown  * @clk: clock source acquired with devm_clk_get()
272a8a97db9SMark Brown  *
273a8a97db9SMark Brown  * Note: drivers must ensure that all clk_enable calls made on this
274a8a97db9SMark Brown  * clock source are balanced by clk_disable calls prior to calling
275a8a97db9SMark Brown  * this function.
276a8a97db9SMark Brown  *
277a8a97db9SMark Brown  * clk_put should not be called from within interrupt context.
278a8a97db9SMark Brown  */
279a8a97db9SMark Brown void devm_clk_put(struct device *dev, struct clk *clk);
280f8ce2547SRussell King 
281f8ce2547SRussell King /*
282f8ce2547SRussell King  * The remaining APIs are optional for machine class support.
283f8ce2547SRussell King  */
284f8ce2547SRussell King 
285f8ce2547SRussell King 
286f8ce2547SRussell King /**
287f8ce2547SRussell King  * clk_round_rate - adjust a rate to the exact rate a clock can provide
288f8ce2547SRussell King  * @clk: clock source
289f8ce2547SRussell King  * @rate: desired clock rate in Hz
290f8ce2547SRussell King  *
291f8ce2547SRussell King  * Returns rounded clock rate in Hz, or negative errno.
292f8ce2547SRussell King  */
293f8ce2547SRussell King long clk_round_rate(struct clk *clk, unsigned long rate);
294f8ce2547SRussell King 
295f8ce2547SRussell King /**
296f8ce2547SRussell King  * clk_set_rate - set the clock rate for a clock source
297f8ce2547SRussell King  * @clk: clock source
298f8ce2547SRussell King  * @rate: desired clock rate in Hz
299f8ce2547SRussell King  *
300f8ce2547SRussell King  * Returns success (0) or negative errno.
301f8ce2547SRussell King  */
302f8ce2547SRussell King int clk_set_rate(struct clk *clk, unsigned long rate);
303f8ce2547SRussell King 
304f8ce2547SRussell King /**
305f8ce2547SRussell King  * clk_set_parent - set the parent clock source for this clock
306f8ce2547SRussell King  * @clk: clock source
307f8ce2547SRussell King  * @parent: parent clock source
308f8ce2547SRussell King  *
309f8ce2547SRussell King  * Returns success (0) or negative errno.
310f8ce2547SRussell King  */
311f8ce2547SRussell King int clk_set_parent(struct clk *clk, struct clk *parent);
312f8ce2547SRussell King 
313f8ce2547SRussell King /**
314f8ce2547SRussell King  * clk_get_parent - get the parent clock source for this clock
315f8ce2547SRussell King  * @clk: clock source
316f8ce2547SRussell King  *
317f8ce2547SRussell King  * Returns struct clk corresponding to parent clock source, or
318f8ce2547SRussell King  * valid IS_ERR() condition containing errno.
319f8ce2547SRussell King  */
320f8ce2547SRussell King struct clk *clk_get_parent(struct clk *clk);
321f8ce2547SRussell King 
32205fd8e73SSascha Hauer /**
32305fd8e73SSascha Hauer  * clk_get_sys - get a clock based upon the device name
32405fd8e73SSascha Hauer  * @dev_id: device name
32505fd8e73SSascha Hauer  * @con_id: connection ID
32605fd8e73SSascha Hauer  *
32705fd8e73SSascha Hauer  * Returns a struct clk corresponding to the clock producer, or
32805fd8e73SSascha Hauer  * valid IS_ERR() condition containing errno.  The implementation
32905fd8e73SSascha Hauer  * uses @dev_id and @con_id to determine the clock consumer, and
33005fd8e73SSascha Hauer  * thereby the clock producer. In contrast to clk_get() this function
33105fd8e73SSascha Hauer  * takes the device name instead of the device itself for identification.
33205fd8e73SSascha Hauer  *
33305fd8e73SSascha Hauer  * Drivers must assume that the clock source is not enabled.
33405fd8e73SSascha Hauer  *
33505fd8e73SSascha Hauer  * clk_get_sys should not be called from within interrupt context.
33605fd8e73SSascha Hauer  */
33705fd8e73SSascha Hauer struct clk *clk_get_sys(const char *dev_id, const char *con_id);
33805fd8e73SSascha Hauer 
33993abe8e4SViresh Kumar #else /* !CONFIG_HAVE_CLK */
34093abe8e4SViresh Kumar 
34193abe8e4SViresh Kumar static inline struct clk *clk_get(struct device *dev, const char *id)
34293abe8e4SViresh Kumar {
34393abe8e4SViresh Kumar 	return NULL;
34493abe8e4SViresh Kumar }
34593abe8e4SViresh Kumar 
34693abe8e4SViresh Kumar static inline struct clk *devm_clk_get(struct device *dev, const char *id)
34793abe8e4SViresh Kumar {
34893abe8e4SViresh Kumar 	return NULL;
34993abe8e4SViresh Kumar }
35093abe8e4SViresh Kumar 
35193abe8e4SViresh Kumar static inline void clk_put(struct clk *clk) {}
35293abe8e4SViresh Kumar 
35393abe8e4SViresh Kumar static inline void devm_clk_put(struct device *dev, struct clk *clk) {}
35493abe8e4SViresh Kumar 
35593abe8e4SViresh Kumar static inline int clk_enable(struct clk *clk)
35693abe8e4SViresh Kumar {
35793abe8e4SViresh Kumar 	return 0;
35893abe8e4SViresh Kumar }
35993abe8e4SViresh Kumar 
36093abe8e4SViresh Kumar static inline void clk_disable(struct clk *clk) {}
36193abe8e4SViresh Kumar 
36293abe8e4SViresh Kumar static inline unsigned long clk_get_rate(struct clk *clk)
36393abe8e4SViresh Kumar {
36493abe8e4SViresh Kumar 	return 0;
36593abe8e4SViresh Kumar }
36693abe8e4SViresh Kumar 
36793abe8e4SViresh Kumar static inline int clk_set_rate(struct clk *clk, unsigned long rate)
36893abe8e4SViresh Kumar {
36993abe8e4SViresh Kumar 	return 0;
37093abe8e4SViresh Kumar }
37193abe8e4SViresh Kumar 
37293abe8e4SViresh Kumar static inline long clk_round_rate(struct clk *clk, unsigned long rate)
37393abe8e4SViresh Kumar {
37493abe8e4SViresh Kumar 	return 0;
37593abe8e4SViresh Kumar }
37693abe8e4SViresh Kumar 
37793abe8e4SViresh Kumar static inline int clk_set_parent(struct clk *clk, struct clk *parent)
37893abe8e4SViresh Kumar {
37993abe8e4SViresh Kumar 	return 0;
38093abe8e4SViresh Kumar }
38193abe8e4SViresh Kumar 
38293abe8e4SViresh Kumar static inline struct clk *clk_get_parent(struct clk *clk)
38393abe8e4SViresh Kumar {
38493abe8e4SViresh Kumar 	return NULL;
38593abe8e4SViresh Kumar }
38693abe8e4SViresh Kumar 
38793abe8e4SViresh Kumar #endif
38893abe8e4SViresh Kumar 
38993abe8e4SViresh Kumar /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
39093abe8e4SViresh Kumar static inline int clk_prepare_enable(struct clk *clk)
39193abe8e4SViresh Kumar {
39293abe8e4SViresh Kumar 	int ret;
39393abe8e4SViresh Kumar 
39493abe8e4SViresh Kumar 	ret = clk_prepare(clk);
39593abe8e4SViresh Kumar 	if (ret)
39693abe8e4SViresh Kumar 		return ret;
39793abe8e4SViresh Kumar 	ret = clk_enable(clk);
39893abe8e4SViresh Kumar 	if (ret)
39993abe8e4SViresh Kumar 		clk_unprepare(clk);
40093abe8e4SViresh Kumar 
40193abe8e4SViresh Kumar 	return ret;
40293abe8e4SViresh Kumar }
40393abe8e4SViresh Kumar 
40493abe8e4SViresh Kumar /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */
40593abe8e4SViresh Kumar static inline void clk_disable_unprepare(struct clk *clk)
40693abe8e4SViresh Kumar {
40793abe8e4SViresh Kumar 	clk_disable(clk);
40893abe8e4SViresh Kumar 	clk_unprepare(clk);
40993abe8e4SViresh Kumar }
41093abe8e4SViresh Kumar 
411c0683039STony Lindgren /**
412c0683039STony Lindgren  * clk_add_alias - add a new clock alias
413c0683039STony Lindgren  * @alias: name for clock alias
414c0683039STony Lindgren  * @alias_dev_name: device name
415c0683039STony Lindgren  * @id: platform specific clock name
416c0683039STony Lindgren  * @dev: device
417c0683039STony Lindgren  *
418c0683039STony Lindgren  * Allows using generic clock names for drivers by adding a new alias.
419c0683039STony Lindgren  * Assumes clkdev, see clkdev.h for more info.
420c0683039STony Lindgren  */
421c0683039STony Lindgren int clk_add_alias(const char *alias, const char *alias_dev_name, char *id,
422c0683039STony Lindgren 			struct device *dev);
423c0683039STony Lindgren 
424766e6a4eSGrant Likely struct device_node;
425766e6a4eSGrant Likely struct of_phandle_args;
426766e6a4eSGrant Likely 
427137f8a72SRob Herring #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
428766e6a4eSGrant Likely struct clk *of_clk_get(struct device_node *np, int index);
429766e6a4eSGrant Likely struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
430766e6a4eSGrant Likely struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
431766e6a4eSGrant Likely #else
432766e6a4eSGrant Likely static inline struct clk *of_clk_get(struct device_node *np, int index)
433766e6a4eSGrant Likely {
4349f1612d3SShawn Guo 	return ERR_PTR(-ENOENT);
435766e6a4eSGrant Likely }
436766e6a4eSGrant Likely static inline struct clk *of_clk_get_by_name(struct device_node *np,
437766e6a4eSGrant Likely 					     const char *name)
438766e6a4eSGrant Likely {
4399f1612d3SShawn Guo 	return ERR_PTR(-ENOENT);
440766e6a4eSGrant Likely }
441766e6a4eSGrant Likely #endif
442766e6a4eSGrant Likely 
443f8ce2547SRussell King #endif
444