Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
clk.h
Go to the documentation of this file.
1 /*
2  * linux/include/linux/clk.h
3  *
4  * Copyright (C) 2004 ARM Limited.
5  * Written by Deep Blue Solutions Limited.
6  * Copyright (C) 2011-2012 Linaro Ltd <[email protected]>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12 #ifndef __LINUX_CLK_H
13 #define __LINUX_CLK_H
14 
15 #include <linux/err.h>
16 #include <linux/kernel.h>
17 #include <linux/notifier.h>
18 
19 struct device;
20 
21 struct clk;
22 
23 #ifdef CONFIG_COMMON_CLK
24 
43 #define PRE_RATE_CHANGE BIT(0)
44 #define POST_RATE_CHANGE BIT(1)
45 #define ABORT_RATE_CHANGE BIT(2)
46 
58 struct clk_notifier {
59  struct clk *clk;
60  struct srcu_notifier_head notifier_head;
61  struct list_head node;
62 };
63 
75 struct clk_notifier_data {
76  struct clk *clk;
77  unsigned long old_rate;
78  unsigned long new_rate;
79 };
80 
81 int clk_notifier_register(struct clk *clk, struct notifier_block *nb);
82 
83 int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb);
84 
85 #endif
86 
95 #ifdef CONFIG_HAVE_CLK_PREPARE
96 int clk_prepare(struct clk *clk);
97 #else
98 static inline int clk_prepare(struct clk *clk)
99 {
100  might_sleep();
101  return 0;
102 }
103 #endif
104 
114 #ifdef CONFIG_HAVE_CLK_PREPARE
115 void clk_unprepare(struct clk *clk);
116 #else
117 static inline void clk_unprepare(struct clk *clk)
118 {
119  might_sleep();
120 }
121 #endif
122 
123 #ifdef CONFIG_HAVE_CLK
124 
139 struct clk *clk_get(struct device *dev, const char *id);
140 
159 struct clk *devm_clk_get(struct device *dev, const char *id);
160 
171 int clk_enable(struct clk *clk);
172 
187 void clk_disable(struct clk *clk);
188 
194 unsigned long clk_get_rate(struct clk *clk);
195 
206 void clk_put(struct clk *clk);
207 
219 void devm_clk_put(struct device *dev, struct clk *clk);
220 
221 /*
222  * The remaining APIs are optional for machine class support.
223  */
224 
225 
233 long clk_round_rate(struct clk *clk, unsigned long rate);
234 
242 int clk_set_rate(struct clk *clk, unsigned long rate);
243 
251 int clk_set_parent(struct clk *clk, struct clk *parent);
252 
260 struct clk *clk_get_parent(struct clk *clk);
261 
277 struct clk *clk_get_sys(const char *dev_id, const char *con_id);
278 
279 #else /* !CONFIG_HAVE_CLK */
280 
281 static inline struct clk *clk_get(struct device *dev, const char *id)
282 {
283  return NULL;
284 }
285 
286 static inline struct clk *devm_clk_get(struct device *dev, const char *id)
287 {
288  return NULL;
289 }
290 
291 static inline void clk_put(struct clk *clk) {}
292 
293 static inline void devm_clk_put(struct device *dev, struct clk *clk) {}
294 
295 static inline int clk_enable(struct clk *clk)
296 {
297  return 0;
298 }
299 
300 static inline void clk_disable(struct clk *clk) {}
301 
302 static inline unsigned long clk_get_rate(struct clk *clk)
303 {
304  return 0;
305 }
306 
307 static inline int clk_set_rate(struct clk *clk, unsigned long rate)
308 {
309  return 0;
310 }
311 
312 static inline long clk_round_rate(struct clk *clk, unsigned long rate)
313 {
314  return 0;
315 }
316 
317 static inline int clk_set_parent(struct clk *clk, struct clk *parent)
318 {
319  return 0;
320 }
321 
322 static inline struct clk *clk_get_parent(struct clk *clk)
323 {
324  return NULL;
325 }
326 
327 #endif
328 
329 /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
330 static inline int clk_prepare_enable(struct clk *clk)
331 {
332  int ret;
333 
334  ret = clk_prepare(clk);
335  if (ret)
336  return ret;
337  ret = clk_enable(clk);
338  if (ret)
339  clk_unprepare(clk);
340 
341  return ret;
342 }
343 
344 /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */
345 static inline void clk_disable_unprepare(struct clk *clk)
346 {
347  clk_disable(clk);
348  clk_unprepare(clk);
349 }
350 
361 int clk_add_alias(const char *alias, const char *alias_dev_name, char *id,
362  struct device *dev);
363 
364 struct device_node;
365 struct of_phandle_args;
366 
367 #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
368 struct clk *of_clk_get(struct device_node *np, int index);
369 struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
370 struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
371 #else
372 static inline struct clk *of_clk_get(struct device_node *np, int index)
373 {
374  return ERR_PTR(-ENOENT);
375 }
376 static inline struct clk *of_clk_get_by_name(struct device_node *np,
377  const char *name)
378 {
379  return ERR_PTR(-ENOENT);
380 }
381 #endif
382 
383 #endif