ccu_nm.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. struct ccu_common common;
  36. };
  37. #define SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(_struct, _name, _parent, _reg, \
  38. _nshift, _nwidth, \
  39. _mshift, _mwidth, \
  40. _sdm_table, _sdm_en, \
  41. _sdm_reg, _sdm_reg_en, \
  42. _gate, _lock, _flags) \
  43. struct ccu_nm _struct = { \
  44. .enable = _gate, \
  45. .lock = _lock, \
  46. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  47. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  48. .sdm = _SUNXI_CCU_SDM(_sdm_table, _sdm_en, \
  49. _sdm_reg, _sdm_reg_en),\
  50. .common = { \
  51. .reg = _reg, \
  52. .features = CCU_FEATURE_SIGMA_DELTA_MOD, \
  53. .hw.init = CLK_HW_INIT(_name, \
  54. _parent, \
  55. &ccu_nm_ops, \
  56. _flags), \
  57. }, \
  58. }
  59. #define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(_struct, _name, _parent, _reg, \
  60. _nshift, _nwidth, \
  61. _mshift, _mwidth, \
  62. _frac_en, _frac_sel, \
  63. _frac_rate_0, _frac_rate_1, \
  64. _gate, _lock, _flags) \
  65. struct ccu_nm _struct = { \
  66. .enable = _gate, \
  67. .lock = _lock, \
  68. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  69. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  70. .frac = _SUNXI_CCU_FRAC(_frac_en, _frac_sel, \
  71. _frac_rate_0, \
  72. _frac_rate_1), \
  73. .common = { \
  74. .reg = _reg, \
  75. .features = CCU_FEATURE_FRACTIONAL, \
  76. .hw.init = CLK_HW_INIT(_name, \
  77. _parent, \
  78. &ccu_nm_ops, \
  79. _flags), \
  80. }, \
  81. }
  82. #define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN(_struct, _name, _parent, \
  83. _reg, _min_rate, \
  84. _nshift, _nwidth, \
  85. _mshift, _mwidth, \
  86. _frac_en, _frac_sel, \
  87. _frac_rate_0, _frac_rate_1,\
  88. _gate, _lock, _flags) \
  89. struct ccu_nm _struct = { \
  90. .enable = _gate, \
  91. .lock = _lock, \
  92. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  93. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  94. .frac = _SUNXI_CCU_FRAC(_frac_en, _frac_sel, \
  95. _frac_rate_0, \
  96. _frac_rate_1), \
  97. .min_rate = _min_rate, \
  98. .common = { \
  99. .reg = _reg, \
  100. .features = CCU_FEATURE_FRACTIONAL, \
  101. .hw.init = CLK_HW_INIT(_name, \
  102. _parent, \
  103. &ccu_nm_ops, \
  104. _flags), \
  105. }, \
  106. }
  107. #define SUNXI_CCU_NM_WITH_GATE_LOCK(_struct, _name, _parent, _reg, \
  108. _nshift, _nwidth, \
  109. _mshift, _mwidth, \
  110. _gate, _lock, _flags) \
  111. struct ccu_nm _struct = { \
  112. .enable = _gate, \
  113. .lock = _lock, \
  114. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  115. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  116. .common = { \
  117. .reg = _reg, \
  118. .hw.init = CLK_HW_INIT(_name, \
  119. _parent, \
  120. &ccu_nm_ops, \
  121. _flags), \
  122. }, \
  123. }
  124. static inline struct ccu_nm *hw_to_ccu_nm(struct clk_hw *hw)
  125. {
  126. struct ccu_common *common = hw_to_ccu_common(hw);
  127. return container_of(common, struct ccu_nm, common);
  128. }
  129. extern const struct clk_ops ccu_nm_ops;
  130. #endif /* _CCU_NM_H_ */