ccu_nkm.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 n;
  28. struct _ccu_mult k;
  29. struct _ccu_div m;
  30. struct ccu_mux_internal mux;
  31. struct ccu_common common;
  32. };
  33. #define SUNXI_CCU_NKM_WITH_MUX_GATE_LOCK(_struct, _name, _parents, _reg, \
  34. _nshift, _nwidth, \
  35. _kshift, _kwidth, \
  36. _mshift, _mwidth, \
  37. _muxshift, _muxwidth, \
  38. _gate, _lock, _flags) \
  39. struct ccu_nkm _struct = { \
  40. .enable = _gate, \
  41. .lock = _lock, \
  42. .k = _SUNXI_CCU_MULT(_kshift, _kwidth), \
  43. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  44. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  45. .mux = _SUNXI_CCU_MUX(_muxshift, _muxwidth), \
  46. .common = { \
  47. .reg = _reg, \
  48. .hw.init = CLK_HW_INIT_PARENTS(_name, \
  49. _parents, \
  50. &ccu_nkm_ops, \
  51. _flags), \
  52. }, \
  53. }
  54. #define SUNXI_CCU_NKM_WITH_GATE_LOCK(_struct, _name, _parent, _reg, \
  55. _nshift, _nwidth, \
  56. _kshift, _kwidth, \
  57. _mshift, _mwidth, \
  58. _gate, _lock, _flags) \
  59. struct ccu_nkm _struct = { \
  60. .enable = _gate, \
  61. .lock = _lock, \
  62. .k = _SUNXI_CCU_MULT(_kshift, _kwidth), \
  63. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  64. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  65. .common = { \
  66. .reg = _reg, \
  67. .hw.init = CLK_HW_INIT(_name, \
  68. _parent, \
  69. &ccu_nkm_ops, \
  70. _flags), \
  71. }, \
  72. }
  73. static inline struct ccu_nkm *hw_to_ccu_nkm(struct clk_hw *hw)
  74. {
  75. struct ccu_common *common = hw_to_ccu_common(hw);
  76. return container_of(common, struct ccu_nkm, common);
  77. }
  78. extern const struct clk_ops ccu_nkm_ops;
  79. #endif /* _CCU_NKM_H_ */