ccu_gate.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016 Maxime Ripard. All rights reserved.
  4. */
  5. #ifndef _CCU_GATE_H_
  6. #define _CCU_GATE_H_
  7. #include <linux/clk-provider.h>
  8. #include "ccu_common.h"
  9. struct ccu_gate {
  10. u32 enable;
  11. struct ccu_common common;
  12. };
  13. #define SUNXI_CCU_GATE(_struct, _name, _parent, _reg, _gate, _flags) \
  14. struct ccu_gate _struct = { \
  15. .enable = _gate, \
  16. .common = { \
  17. .reg = _reg, \
  18. .hw.init = CLK_HW_INIT(_name, \
  19. _parent, \
  20. &ccu_gate_ops, \
  21. _flags), \
  22. } \
  23. }
  24. #define SUNXI_CCU_GATE_HW(_struct, _name, _parent, _reg, _gate, _flags) \
  25. struct ccu_gate _struct = { \
  26. .enable = _gate, \
  27. .common = { \
  28. .reg = _reg, \
  29. .hw.init = CLK_HW_INIT_HW(_name, \
  30. _parent, \
  31. &ccu_gate_ops, \
  32. _flags), \
  33. } \
  34. }
  35. #define SUNXI_CCU_GATE_FW(_struct, _name, _parent, _reg, _gate, _flags) \
  36. struct ccu_gate _struct = { \
  37. .enable = _gate, \
  38. .common = { \
  39. .reg = _reg, \
  40. .hw.init = CLK_HW_INIT_FW_NAME(_name, \
  41. _parent, \
  42. &ccu_gate_ops, \
  43. _flags), \
  44. } \
  45. }
  46. /*
  47. * The following macros allow the re-use of the data structure
  48. * holding the parent info.
  49. */
  50. #define SUNXI_CCU_GATE_HWS(_struct, _name, _parent, _reg, _gate, _flags) \
  51. struct ccu_gate _struct = { \
  52. .enable = _gate, \
  53. .common = { \
  54. .reg = _reg, \
  55. .hw.init = CLK_HW_INIT_HWS(_name, \
  56. _parent, \
  57. &ccu_gate_ops, \
  58. _flags), \
  59. } \
  60. }
  61. #define SUNXI_CCU_GATE_HWS_WITH_PREDIV(_struct, _name, _parent, _reg, \
  62. _gate, _prediv, _flags) \
  63. struct ccu_gate _struct = { \
  64. .enable = _gate, \
  65. .common = { \
  66. .reg = _reg, \
  67. .prediv = _prediv, \
  68. .features = CCU_FEATURE_ALL_PREDIV, \
  69. .hw.init = CLK_HW_INIT_HWS(_name, \
  70. _parent, \
  71. &ccu_gate_ops, \
  72. _flags), \
  73. } \
  74. }
  75. #define SUNXI_CCU_GATE_DATA(_struct, _name, _data, _reg, _gate, _flags) \
  76. struct ccu_gate _struct = { \
  77. .enable = _gate, \
  78. .common = { \
  79. .reg = _reg, \
  80. .hw.init = \
  81. CLK_HW_INIT_PARENTS_DATA(_name, \
  82. _data, \
  83. &ccu_gate_ops, \
  84. _flags), \
  85. } \
  86. }
  87. #define SUNXI_CCU_GATE_DATA_WITH_PREDIV(_struct, _name, _parent, _reg, \
  88. _gate, _prediv, _flags) \
  89. struct ccu_gate _struct = { \
  90. .enable = _gate, \
  91. .common = { \
  92. .reg = _reg, \
  93. .prediv = _prediv, \
  94. .features = CCU_FEATURE_ALL_PREDIV, \
  95. .hw.init = CLK_HW_INIT_PARENTS_DATA(_name, \
  96. _parent, \
  97. &ccu_gate_ops, \
  98. _flags), \
  99. } \
  100. }
  101. static inline struct ccu_gate *hw_to_ccu_gate(struct clk_hw *hw)
  102. {
  103. struct ccu_common *common = hw_to_ccu_common(hw);
  104. return container_of(common, struct ccu_gate, common);
  105. }
  106. void ccu_gate_helper_disable(struct ccu_common *common, u32 gate);
  107. int ccu_gate_helper_enable(struct ccu_common *common, u32 gate);
  108. int ccu_gate_helper_is_enabled(struct ccu_common *common, u32 gate);
  109. extern const struct clk_ops ccu_gate_ops;
  110. #endif /* _CCU_GATE_H_ */