clk-private.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. #define DEFINE_CLK_FIXED_RATE(_name, _flags, _rate, \
  53. _fixed_rate_flags) \
  54. static struct clk _name; \
  55. static char *_name##_parent_names[] = {}; \
  56. static struct clk_fixed_rate _name##_hw = { \
  57. .hw = { \
  58. .clk = &_name, \
  59. }, \
  60. .fixed_rate = _rate, \
  61. .flags = _fixed_rate_flags, \
  62. }; \
  63. static struct clk _name = { \
  64. .name = #_name, \
  65. .ops = &clk_fixed_rate_ops, \
  66. .hw = &_name##_hw.hw, \
  67. .parent_names = _name##_parent_names, \
  68. .num_parents = \
  69. ARRAY_SIZE(_name##_parent_names), \
  70. .flags = _flags, \
  71. };
  72. #define DEFINE_CLK_GATE(_name, _parent_name, _parent_ptr, \
  73. _flags, _reg, _bit_idx, \
  74. _gate_flags, _lock) \
  75. static struct clk _name; \
  76. static char *_name##_parent_names[] = { \
  77. _parent_name, \
  78. }; \
  79. static struct clk *_name##_parents[] = { \
  80. _parent_ptr, \
  81. }; \
  82. static struct clk_gate _name##_hw = { \
  83. .hw = { \
  84. .clk = &_name, \
  85. }, \
  86. .reg = _reg, \
  87. .bit_idx = _bit_idx, \
  88. .flags = _gate_flags, \
  89. .lock = _lock, \
  90. }; \
  91. static struct clk _name = { \
  92. .name = #_name, \
  93. .ops = &clk_gate_ops, \
  94. .hw = &_name##_hw.hw, \
  95. .parent_names = _name##_parent_names, \
  96. .num_parents = \
  97. ARRAY_SIZE(_name##_parent_names), \
  98. .parents = _name##_parents, \
  99. .flags = _flags, \
  100. };
  101. #define DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
  102. _flags, _reg, _shift, _width, \
  103. _divider_flags, _lock) \
  104. static struct clk _name; \
  105. static char *_name##_parent_names[] = { \
  106. _parent_name, \
  107. }; \
  108. static struct clk *_name##_parents[] = { \
  109. _parent_ptr, \
  110. }; \
  111. static struct clk_divider _name##_hw = { \
  112. .hw = { \
  113. .clk = &_name, \
  114. }, \
  115. .reg = _reg, \
  116. .shift = _shift, \
  117. .width = _width, \
  118. .flags = _divider_flags, \
  119. .lock = _lock, \
  120. }; \
  121. static struct clk _name = { \
  122. .name = #_name, \
  123. .ops = &clk_divider_ops, \
  124. .hw = &_name##_hw.hw, \
  125. .parent_names = _name##_parent_names, \
  126. .num_parents = \
  127. ARRAY_SIZE(_name##_parent_names), \
  128. .parents = _name##_parents, \
  129. .flags = _flags, \
  130. };
  131. #define DEFINE_CLK_MUX(_name, _parent_names, _parents, _flags, \
  132. _reg, _shift, _width, \
  133. _mux_flags, _lock) \
  134. static struct clk _name; \
  135. static struct clk_mux _name##_hw = { \
  136. .hw = { \
  137. .clk = &_name, \
  138. }, \
  139. .reg = _reg, \
  140. .shift = _shift, \
  141. .width = _width, \
  142. .flags = _mux_flags, \
  143. .lock = _lock, \
  144. }; \
  145. static struct clk _name = { \
  146. .name = #_name, \
  147. .ops = &clk_mux_ops, \
  148. .hw = &_name##_hw.hw, \
  149. .parent_names = _parent_names, \
  150. .num_parents = \
  151. ARRAY_SIZE(_parent_names), \
  152. .parents = _parents, \
  153. .flags = _flags, \
  154. };
  155. /**
  156. * __clk_init - initialize the data structures in a struct clk
  157. * @dev: device initializing this clk, placeholder for now
  158. * @clk: clk being initialized
  159. *
  160. * Initializes the lists in struct clk, queries the hardware for the
  161. * parent and rate and sets them both.
  162. *
  163. * Any struct clk passed into __clk_init must have the following members
  164. * populated:
  165. * .name
  166. * .ops
  167. * .hw
  168. * .parent_names
  169. * .num_parents
  170. * .flags
  171. *
  172. * It is not necessary to call clk_register if __clk_init is used directly with
  173. * statically initialized clock data.
  174. */
  175. void __clk_init(struct device *dev, struct clk *clk);
  176. #endif /* CONFIG_COMMON_CLK */
  177. #endif /* CLK_PRIVATE_H */