clk-private.h 6.1 KB

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