ccu_nm.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (c) 2016 Maxime Ripard. All rights reserved.
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _CCU_NM_H_
  14. #define _CCU_NM_H_
  15. #include <linux/clk-provider.h>
  16. #include "ccu_common.h"
  17. #include "ccu_div.h"
  18. #include "ccu_frac.h"
  19. #include "ccu_mult.h"
  20. #include "ccu_sdm.h"
  21. /*
  22. * struct ccu_nm - Definition of an N-M clock
  23. *
  24. * Clocks based on the formula parent * N / M
  25. */
  26. struct ccu_nm {
  27. u32 enable;
  28. u32 lock;
  29. struct ccu_mult_internal n;
  30. struct ccu_div_internal m;
  31. struct ccu_frac_internal frac;
  32. struct ccu_sdm_internal sdm;
  33. unsigned int fixed_post_div;
  34. unsigned int min_rate;
  35. unsigned int max_rate;
  36. struct ccu_common common;
  37. };
  38. #define SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(_struct, _name, _parent, _reg, \
  39. _nshift, _nwidth, \
  40. _mshift, _mwidth, \
  41. _sdm_table, _sdm_en, \
  42. _sdm_reg, _sdm_reg_en, \
  43. _gate, _lock, _flags) \
  44. struct ccu_nm _struct = { \
  45. .enable = _gate, \
  46. .lock = _lock, \
  47. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  48. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  49. .sdm = _SUNXI_CCU_SDM(_sdm_table, _sdm_en, \
  50. _sdm_reg, _sdm_reg_en),\
  51. .common = { \
  52. .reg = _reg, \
  53. .features = CCU_FEATURE_SIGMA_DELTA_MOD, \
  54. .hw.init = CLK_HW_INIT(_name, \
  55. _parent, \
  56. &ccu_nm_ops, \
  57. _flags), \
  58. }, \
  59. }
  60. #define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(_struct, _name, _parent, _reg, \
  61. _nshift, _nwidth, \
  62. _mshift, _mwidth, \
  63. _frac_en, _frac_sel, \
  64. _frac_rate_0, _frac_rate_1, \
  65. _gate, _lock, _flags) \
  66. struct ccu_nm _struct = { \
  67. .enable = _gate, \
  68. .lock = _lock, \
  69. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  70. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  71. .frac = _SUNXI_CCU_FRAC(_frac_en, _frac_sel, \
  72. _frac_rate_0, \
  73. _frac_rate_1), \
  74. .common = { \
  75. .reg = _reg, \
  76. .features = CCU_FEATURE_FRACTIONAL, \
  77. .hw.init = CLK_HW_INIT(_name, \
  78. _parent, \
  79. &ccu_nm_ops, \
  80. _flags), \
  81. }, \
  82. }
  83. #define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN(_struct, _name, _parent, \
  84. _reg, _min_rate, \
  85. _nshift, _nwidth, \
  86. _mshift, _mwidth, \
  87. _frac_en, _frac_sel, \
  88. _frac_rate_0, _frac_rate_1,\
  89. _gate, _lock, _flags) \
  90. struct ccu_nm _struct = { \
  91. .enable = _gate, \
  92. .lock = _lock, \
  93. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  94. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  95. .frac = _SUNXI_CCU_FRAC(_frac_en, _frac_sel, \
  96. _frac_rate_0, \
  97. _frac_rate_1), \
  98. .min_rate = _min_rate, \
  99. .common = { \
  100. .reg = _reg, \
  101. .features = CCU_FEATURE_FRACTIONAL, \
  102. .hw.init = CLK_HW_INIT(_name, \
  103. _parent, \
  104. &ccu_nm_ops, \
  105. _flags), \
  106. }, \
  107. }
  108. #define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(_struct, _name, \
  109. _parent, _reg, \
  110. _min_rate, _max_rate, \
  111. _nshift, _nwidth, \
  112. _mshift, _mwidth, \
  113. _frac_en, _frac_sel, \
  114. _frac_rate_0, \
  115. _frac_rate_1, \
  116. _gate, _lock, _flags) \
  117. struct ccu_nm _struct = { \
  118. .enable = _gate, \
  119. .lock = _lock, \
  120. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  121. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  122. .frac = _SUNXI_CCU_FRAC(_frac_en, _frac_sel, \
  123. _frac_rate_0, \
  124. _frac_rate_1), \
  125. .min_rate = _min_rate, \
  126. .max_rate = _max_rate, \
  127. .common = { \
  128. .reg = _reg, \
  129. .features = CCU_FEATURE_FRACTIONAL, \
  130. .hw.init = CLK_HW_INIT(_name, \
  131. _parent, \
  132. &ccu_nm_ops, \
  133. _flags), \
  134. }, \
  135. }
  136. #define SUNXI_CCU_NM_WITH_GATE_LOCK(_struct, _name, _parent, _reg, \
  137. _nshift, _nwidth, \
  138. _mshift, _mwidth, \
  139. _gate, _lock, _flags) \
  140. struct ccu_nm _struct = { \
  141. .enable = _gate, \
  142. .lock = _lock, \
  143. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  144. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  145. .common = { \
  146. .reg = _reg, \
  147. .hw.init = CLK_HW_INIT(_name, \
  148. _parent, \
  149. &ccu_nm_ops, \
  150. _flags), \
  151. }, \
  152. }
  153. static inline struct ccu_nm *hw_to_ccu_nm(struct clk_hw *hw)
  154. {
  155. struct ccu_common *common = hw_to_ccu_common(hw);
  156. return container_of(common, struct ccu_nm, common);
  157. }
  158. extern const struct clk_ops ccu_nm_ops;
  159. #endif /* _CCU_NM_H_ */