clk-private.h 4.7 KB

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