ccu_nkm.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_NKM_H_
  14. #define _CCU_NKM_H_
  15. #include <linux/clk-provider.h>
  16. #include "ccu_common.h"
  17. #include "ccu_div.h"
  18. #include "ccu_mult.h"
  19. /*
  20. * struct ccu_nkm - Definition of an N-K-M clock
  21. *
  22. * Clocks based on the formula parent * N * K / M
  23. */
  24. struct ccu_nkm {
  25. u32 enable;
  26. u32 lock;
  27. struct ccu_mult_internal n;
  28. struct ccu_mult_internal k;
  29. struct ccu_div_internal m;
  30. struct ccu_mux_internal mux;
  31. unsigned int fixed_post_div;
  32. struct ccu_common common;
  33. };
  34. #define SUNXI_CCU_NKM_WITH_MUX_GATE_LOCK(_struct, _name, _parents, _reg, \
  35. _nshift, _nwidth, \
  36. _kshift, _kwidth, \
  37. _mshift, _mwidth, \
  38. _muxshift, _muxwidth, \
  39. _gate, _lock, _flags) \
  40. struct ccu_nkm _struct = { \
  41. .enable = _gate, \
  42. .lock = _lock, \
  43. .k = _SUNXI_CCU_MULT(_kshift, _kwidth), \
  44. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  45. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  46. .mux = _SUNXI_CCU_MUX(_muxshift, _muxwidth), \
  47. .common = { \
  48. .reg = _reg, \
  49. .hw.init = CLK_HW_INIT_PARENTS(_name, \
  50. _parents, \
  51. &ccu_nkm_ops, \
  52. _flags), \
  53. }, \
  54. }
  55. #define SUNXI_CCU_NKM_WITH_GATE_LOCK(_struct, _name, _parent, _reg, \
  56. _nshift, _nwidth, \
  57. _kshift, _kwidth, \
  58. _mshift, _mwidth, \
  59. _gate, _lock, _flags) \
  60. struct ccu_nkm _struct = { \
  61. .enable = _gate, \
  62. .lock = _lock, \
  63. .k = _SUNXI_CCU_MULT(_kshift, _kwidth), \
  64. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  65. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  66. .common = { \
  67. .reg = _reg, \
  68. .hw.init = CLK_HW_INIT(_name, \
  69. _parent, \
  70. &ccu_nkm_ops, \
  71. _flags), \
  72. }, \
  73. }
  74. static inline struct ccu_nkm *hw_to_ccu_nkm(struct clk_hw *hw)
  75. {
  76. struct ccu_common *common = hw_to_ccu_common(hw);
  77. return container_of(common, struct ccu_nkm, common);
  78. }
  79. extern const struct clk_ops ccu_nkm_ops;
  80. #endif /* _CCU_NKM_H_ */