ccu_nm.h 2.3 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_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. /*
  21. * struct ccu_nm - Definition of an N-M clock
  22. *
  23. * Clocks based on the formula parent * N / M
  24. */
  25. struct ccu_nm {
  26. u32 enable;
  27. u32 lock;
  28. struct _ccu_mult n;
  29. struct _ccu_div m;
  30. struct _ccu_frac frac;
  31. struct ccu_common common;
  32. };
  33. #define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(_struct, _name, _parent, _reg, \
  34. _nshift, _nwidth, \
  35. _mshift, _mwidth, \
  36. _frac_en, _frac_sel, \
  37. _frac_rate_0, _frac_rate_1, \
  38. _gate, _lock, _flags) \
  39. struct ccu_nm _struct = { \
  40. .enable = _gate, \
  41. .lock = _lock, \
  42. .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
  43. .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  44. .frac = _SUNXI_CCU_FRAC(_frac_en, _frac_sel, \
  45. _frac_rate_0, \
  46. _frac_rate_1), \
  47. .common = { \
  48. .reg = _reg, \
  49. .features = CCU_FEATURE_FRACTIONAL, \
  50. .hw.init = CLK_HW_INIT(_name, \
  51. _parent, \
  52. &ccu_nm_ops, \
  53. _flags), \
  54. }, \
  55. }
  56. #define SUNXI_CCU_NM_WITH_GATE_LOCK(_struct, _name, _parent, _reg, \
  57. _nshift, _nwidth, \
  58. _mshift, _mwidth, \
  59. _gate, _lock, _flags) \
  60. struct ccu_nm _struct = { \
  61. .enable = _gate, \
  62. .lock = _lock, \
  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_nm_ops, \
  70. _flags), \
  71. }, \
  72. }
  73. static inline struct ccu_nm *hw_to_ccu_nm(struct clk_hw *hw)
  74. {
  75. struct ccu_common *common = hw_to_ccu_common(hw);
  76. return container_of(common, struct ccu_nm, common);
  77. }
  78. extern const struct clk_ops ccu_nm_ops;
  79. #endif /* _CCU_NM_H_ */