clk-private.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * linux/include/linux/clk-private.h
  3. *
  4. * Copyright (c) 2010-2011 Jeremy Kerr <jeremy.kerr@canonical.com>
  5. * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef __LINUX_CLK_PRIVATE_H
  12. #define __LINUX_CLK_PRIVATE_H
  13. #include <linux/clk-provider.h>
  14. #include <linux/kref.h>
  15. #include <linux/ktime.h>
  16. #include <linux/list.h>
  17. #include <linux/rbtree.h>
  18. /*
  19. * WARNING: Do not include clk-private.h from any file that implements struct
  20. * clk_ops. Doing so is a layering violation!
  21. *
  22. * This header exists only to allow for statically initialized clock data. Any
  23. * static clock data must be defined in a separate file from the logic that
  24. * implements the clock operations for that same data.
  25. */
  26. #ifdef CONFIG_COMMON_CLK
  27. struct module;
  28. #ifdef CONFIG_COMMON_CLK_FREQ_STATS_ACCOUNTING
  29. struct freq_stats {
  30. ktime_t time_spent;
  31. unsigned long rate;
  32. struct rb_node node;
  33. };
  34. #endif /*CONFIG_COMMON_CLK_FREQ_STATS_ACCOUNTING*/
  35. struct clk {
  36. const char *name;
  37. const struct clk_ops *ops;
  38. struct clk_hw *hw;
  39. struct module *owner;
  40. struct clk *parent;
  41. const char **parent_names;
  42. struct clk **parents;
  43. u8 num_parents;
  44. u8 new_parent_index;
  45. unsigned long rate;
  46. unsigned long new_rate;
  47. struct clk *new_parent;
  48. struct clk *new_child;
  49. unsigned long flags;
  50. unsigned int enable_count;
  51. unsigned int prepare_count;
  52. unsigned long accuracy;
  53. int phase;
  54. struct hlist_head children;
  55. struct hlist_node child_node;
  56. struct hlist_node debug_node;
  57. unsigned int notifier_count;
  58. #ifdef CONFIG_DEBUG_FS
  59. struct dentry *dentry;
  60. #ifdef CONFIG_COMMON_CLK_FREQ_STATS_ACCOUNTING
  61. struct rb_root freq_stats_table;
  62. struct freq_stats *current_freq_stats;
  63. ktime_t default_freq_time;
  64. ktime_t start_time;
  65. #endif /* CONFIG_COMMON_CLK_FREQ_STATS_ACCOUNTING*/
  66. #endif
  67. struct kref ref;
  68. };
  69. /*
  70. * DOC: Basic clock implementations common to many platforms
  71. *
  72. * Each basic clock hardware type is comprised of a structure describing the
  73. * clock hardware, implementations of the relevant callbacks in struct clk_ops,
  74. * unique flags for that hardware type, a registration function and an
  75. * alternative macro for static initialization
  76. */
  77. #define DEFINE_CLK(_name, _ops, _flags, _parent_names, \
  78. _parents) \
  79. static struct clk _name = { \
  80. .name = #_name, \
  81. .ops = &_ops, \
  82. .hw = &_name##_hw.hw, \
  83. .parent_names = _parent_names, \
  84. .num_parents = ARRAY_SIZE(_parent_names), \
  85. .parents = _parents, \
  86. .flags = _flags | CLK_IS_BASIC, \
  87. }
  88. #define DEFINE_CLK_FIXED_RATE(_name, _flags, _rate, \
  89. _fixed_rate_flags) \
  90. static struct clk _name; \
  91. static const char *_name##_parent_names[] = {}; \
  92. static struct clk_fixed_rate _name##_hw = { \
  93. .hw = { \
  94. .clk = &_name, \
  95. }, \
  96. .fixed_rate = _rate, \
  97. .flags = _fixed_rate_flags, \
  98. }; \
  99. DEFINE_CLK(_name, clk_fixed_rate_ops, _flags, \
  100. _name##_parent_names, NULL);
  101. #define DEFINE_CLK_GATE(_name, _parent_name, _parent_ptr, \
  102. _flags, _reg, _bit_idx, \
  103. _gate_flags, _lock) \
  104. static struct clk _name; \
  105. static const char *_name##_parent_names[] = { \
  106. _parent_name, \
  107. }; \
  108. static struct clk *_name##_parents[] = { \
  109. _parent_ptr, \
  110. }; \
  111. static struct clk_gate _name##_hw = { \
  112. .hw = { \
  113. .clk = &_name, \
  114. }, \
  115. .reg = _reg, \
  116. .bit_idx = _bit_idx, \
  117. .flags = _gate_flags, \
  118. .lock = _lock, \
  119. }; \
  120. DEFINE_CLK(_name, clk_gate_ops, _flags, \
  121. _name##_parent_names, _name##_parents);
  122. #define _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
  123. _flags, _reg, _shift, _width, \
  124. _divider_flags, _table, _lock) \
  125. static struct clk _name; \
  126. static const char *_name##_parent_names[] = { \
  127. _parent_name, \
  128. }; \
  129. static struct clk *_name##_parents[] = { \
  130. _parent_ptr, \
  131. }; \
  132. static struct clk_divider _name##_hw = { \
  133. .hw = { \
  134. .clk = &_name, \
  135. }, \
  136. .reg = _reg, \
  137. .shift = _shift, \
  138. .width = _width, \
  139. .flags = _divider_flags, \
  140. .table = _table, \
  141. .lock = _lock, \
  142. }; \
  143. DEFINE_CLK(_name, clk_divider_ops, _flags, \
  144. _name##_parent_names, _name##_parents);
  145. #define DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
  146. _flags, _reg, _shift, _width, \
  147. _divider_flags, _lock) \
  148. _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
  149. _flags, _reg, _shift, _width, \
  150. _divider_flags, NULL, _lock)
  151. #define DEFINE_CLK_DIVIDER_TABLE(_name, _parent_name, \
  152. _parent_ptr, _flags, _reg, \
  153. _shift, _width, _divider_flags, \
  154. _table, _lock) \
  155. _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
  156. _flags, _reg, _shift, _width, \
  157. _divider_flags, _table, _lock) \
  158. #define DEFINE_CLK_MUX(_name, _parent_names, _parents, _flags, \
  159. _reg, _shift, _width, \
  160. _mux_flags, _lock) \
  161. static struct clk _name; \
  162. static struct clk_mux _name##_hw = { \
  163. .hw = { \
  164. .clk = &_name, \
  165. }, \
  166. .reg = _reg, \
  167. .shift = _shift, \
  168. .mask = BIT(_width) - 1, \
  169. .flags = _mux_flags, \
  170. .lock = _lock, \
  171. }; \
  172. DEFINE_CLK(_name, clk_mux_ops, _flags, _parent_names, \
  173. _parents);
  174. #define DEFINE_CLK_FIXED_FACTOR(_name, _parent_name, \
  175. _parent_ptr, _flags, \
  176. _mult, _div) \
  177. static struct clk _name; \
  178. static const char *_name##_parent_names[] = { \
  179. _parent_name, \
  180. }; \
  181. static struct clk *_name##_parents[] = { \
  182. _parent_ptr, \
  183. }; \
  184. static struct clk_fixed_factor _name##_hw = { \
  185. .hw = { \
  186. .clk = &_name, \
  187. }, \
  188. .mult = _mult, \
  189. .div = _div, \
  190. }; \
  191. DEFINE_CLK(_name, clk_fixed_factor_ops, _flags, \
  192. _name##_parent_names, _name##_parents);
  193. /**
  194. * __clk_init - initialize the data structures in a struct clk
  195. * @dev: device initializing this clk, placeholder for now
  196. * @clk: clk being initialized
  197. *
  198. * Initializes the lists in struct clk, queries the hardware for the
  199. * parent and rate and sets them both.
  200. *
  201. * Any struct clk passed into __clk_init must have the following members
  202. * populated:
  203. * .name
  204. * .ops
  205. * .hw
  206. * .parent_names
  207. * .num_parents
  208. * .flags
  209. *
  210. * It is not necessary to call clk_register if __clk_init is used directly with
  211. * statically initialized clock data.
  212. *
  213. * Returns 0 on success, otherwise an error code.
  214. */
  215. int __clk_init(struct device *dev, struct clk *clk);
  216. struct clk *__clk_register(struct device *dev, struct clk_hw *hw);
  217. #endif /* CONFIG_COMMON_CLK */
  218. #endif /* CLK_PRIVATE_H */