ccu_nm.h 3.1 KB

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