ccu_div.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_DIV_H_
  14. #define _CCU_DIV_H_
  15. #include <linux/clk-provider.h>
  16. #include "ccu_common.h"
  17. #include "ccu_mux.h"
  18. struct _ccu_div {
  19. u8 shift;
  20. u8 width;
  21. u32 flags;
  22. struct clk_div_table *table;
  23. };
  24. #define _SUNXI_CCU_DIV_TABLE_FLAGS(_shift, _width, _table, _flags) \
  25. { \
  26. .shift = _shift, \
  27. .width = _width, \
  28. .flags = _flags, \
  29. .table = _table, \
  30. }
  31. #define _SUNXI_CCU_DIV_FLAGS(_shift, _width, _flags) \
  32. _SUNXI_CCU_DIV_TABLE_FLAGS(_shift, _width, NULL, _flags)
  33. #define _SUNXI_CCU_DIV_TABLE(_shift, _width, _table) \
  34. _SUNXI_CCU_DIV_TABLE_FLAGS(_shift, _width, _table, 0)
  35. #define _SUNXI_CCU_DIV(_shift, _width) \
  36. _SUNXI_CCU_DIV_TABLE_FLAGS(_shift, _width, NULL, 0)
  37. struct ccu_div {
  38. u32 enable;
  39. struct _ccu_div div;
  40. struct ccu_mux_internal mux;
  41. struct ccu_common common;
  42. };
  43. #define SUNXI_CCU_DIV_TABLE_WITH_GATE(_struct, _name, _parent, _reg, \
  44. _shift, _width, \
  45. _table, _gate, _flags) \
  46. struct ccu_div _struct = { \
  47. .div = _SUNXI_CCU_DIV_TABLE(_shift, _width, \
  48. _table), \
  49. .enable = _gate, \
  50. .common = { \
  51. .reg = _reg, \
  52. .hw.init = CLK_HW_INIT(_name, \
  53. _parent, \
  54. &ccu_div_ops, \
  55. _flags), \
  56. } \
  57. }
  58. #define SUNXI_CCU_DIV_TABLE(_struct, _name, _parent, _reg, \
  59. _shift, _width, \
  60. _table, _flags) \
  61. SUNXI_CCU_DIV_TABLE_WITH_GATE(_struct, _name, _parent, _reg, \
  62. _shift, _width, _table, 0, \
  63. _flags)
  64. #define SUNXI_CCU_M_WITH_MUX_GATE(_struct, _name, _parents, _reg, \
  65. _mshift, _mwidth, _muxshift, _muxwidth, \
  66. _gate, _flags) \
  67. struct ccu_div _struct = { \
  68. .enable = _gate, \
  69. .div = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  70. .mux = SUNXI_CLK_MUX(_muxshift, _muxwidth), \
  71. .common = { \
  72. .reg = _reg, \
  73. .hw.init = CLK_HW_INIT_PARENTS(_name, \
  74. _parents, \
  75. &ccu_div_ops, \
  76. _flags), \
  77. }, \
  78. }
  79. #define SUNXI_CCU_M_WITH_MUX(_struct, _name, _parents, _reg, \
  80. _mshift, _mwidth, _muxshift, _muxwidth, \
  81. _flags) \
  82. SUNXI_CCU_M_WITH_MUX_GATE(_struct, _name, _parents, _reg, \
  83. _mshift, _mwidth, _muxshift, _muxwidth, \
  84. 0, _flags)
  85. #define SUNXI_CCU_M_WITH_GATE(_struct, _name, _parent, _reg, \
  86. _mshift, _mwidth, _gate, \
  87. _flags) \
  88. struct ccu_div _struct = { \
  89. .enable = _gate, \
  90. .div = _SUNXI_CCU_DIV(_mshift, _mwidth), \
  91. .common = { \
  92. .reg = _reg, \
  93. .hw.init = CLK_HW_INIT(_name, \
  94. _parent, \
  95. &ccu_div_ops, \
  96. _flags), \
  97. }, \
  98. }
  99. #define SUNXI_CCU_M(_struct, _name, _parent, _reg, _mshift, _mwidth, \
  100. _flags) \
  101. SUNXI_CCU_M_WITH_GATE(_struct, _name, _parent, _reg, \
  102. _mshift, _mwidth, 0, _flags)
  103. static inline struct ccu_div *hw_to_ccu_div(struct clk_hw *hw)
  104. {
  105. struct ccu_common *common = hw_to_ccu_common(hw);
  106. return container_of(common, struct ccu_div, common);
  107. }
  108. extern const struct clk_ops ccu_div_ops;
  109. #endif /* _CCU_DIV_H_ */