clk-private.h 5.2 KB

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