ccu_mux.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _CCU_MUX_H_
  3. #define _CCU_MUX_H_
  4. #include <linux/clk-provider.h>
  5. #include "ccu_common.h"
  6. struct ccu_mux_fixed_prediv {
  7. u8 index;
  8. u16 div;
  9. };
  10. struct ccu_mux_var_prediv {
  11. u8 index;
  12. u8 shift;
  13. u8 width;
  14. };
  15. struct ccu_mux_internal {
  16. u8 shift;
  17. u8 width;
  18. const u8 *table;
  19. const struct ccu_mux_fixed_prediv *fixed_predivs;
  20. u8 n_predivs;
  21. const struct ccu_mux_var_prediv *var_predivs;
  22. u8 n_var_predivs;
  23. };
  24. #define _SUNXI_CCU_MUX_TABLE(_shift, _width, _table) \
  25. { \
  26. .shift = _shift, \
  27. .width = _width, \
  28. .table = _table, \
  29. }
  30. #define _SUNXI_CCU_MUX(_shift, _width) \
  31. _SUNXI_CCU_MUX_TABLE(_shift, _width, NULL)
  32. struct ccu_mux {
  33. u32 enable;
  34. struct ccu_mux_internal mux;
  35. struct ccu_common common;
  36. };
  37. #define SUNXI_CCU_MUX_TABLE_WITH_GATE(_struct, _name, _parents, _table, \
  38. _reg, _shift, _width, _gate, \
  39. _flags) \
  40. struct ccu_mux _struct = { \
  41. .enable = _gate, \
  42. .mux = _SUNXI_CCU_MUX_TABLE(_shift, _width, _table), \
  43. .common = { \
  44. .reg = _reg, \
  45. .hw.init = CLK_HW_INIT_PARENTS(_name, \
  46. _parents, \
  47. &ccu_mux_ops, \
  48. _flags), \
  49. } \
  50. }
  51. #define SUNXI_CCU_MUX_WITH_GATE(_struct, _name, _parents, _reg, \
  52. _shift, _width, _gate, _flags) \
  53. SUNXI_CCU_MUX_TABLE_WITH_GATE(_struct, _name, _parents, NULL, \
  54. _reg, _shift, _width, _gate, \
  55. _flags)
  56. #define SUNXI_CCU_MUX(_struct, _name, _parents, _reg, _shift, _width, \
  57. _flags) \
  58. SUNXI_CCU_MUX_TABLE_WITH_GATE(_struct, _name, _parents, NULL, \
  59. _reg, _shift, _width, 0, _flags)
  60. #define SUNXI_CCU_MUX_DATA_WITH_GATE(_struct, _name, _parents, _reg, \
  61. _shift, _width, _gate, _flags) \
  62. struct ccu_mux _struct = { \
  63. .enable = _gate, \
  64. .mux = _SUNXI_CCU_MUX(_shift, _width), \
  65. .common = { \
  66. .reg = _reg, \
  67. .hw.init = CLK_HW_INIT_PARENTS_DATA(_name, \
  68. _parents, \
  69. &ccu_mux_ops, \
  70. _flags), \
  71. } \
  72. }
  73. #define SUNXI_CCU_MUX_DATA(_struct, _name, _parents, _reg, \
  74. _shift, _width, _flags) \
  75. SUNXI_CCU_MUX_DATA_WITH_GATE(_struct, _name, _parents, _reg, \
  76. _shift, _width, 0, _flags)
  77. #define SUNXI_CCU_MUX_HW_WITH_GATE(_struct, _name, _parents, _reg, \
  78. _shift, _width, _gate, _flags) \
  79. struct ccu_mux _struct = { \
  80. .enable = _gate, \
  81. .mux = _SUNXI_CCU_MUX(_shift, _width), \
  82. .common = { \
  83. .reg = _reg, \
  84. .hw.init = CLK_HW_INIT_PARENTS_HW(_name, \
  85. _parents, \
  86. &ccu_mux_ops, \
  87. _flags), \
  88. } \
  89. }
  90. static inline struct ccu_mux *hw_to_ccu_mux(struct clk_hw *hw)
  91. {
  92. struct ccu_common *common = hw_to_ccu_common(hw);
  93. return container_of(common, struct ccu_mux, common);
  94. }
  95. extern const struct clk_ops ccu_mux_ops;
  96. unsigned long ccu_mux_helper_apply_prediv(struct ccu_common *common,
  97. struct ccu_mux_internal *cm,
  98. int parent_index,
  99. unsigned long parent_rate);
  100. int ccu_mux_helper_determine_rate(struct ccu_common *common,
  101. struct ccu_mux_internal *cm,
  102. struct clk_rate_request *req,
  103. unsigned long (*round)(struct ccu_mux_internal *,
  104. struct clk_hw *,
  105. unsigned long *,
  106. unsigned long,
  107. void *),
  108. void *data);
  109. u8 ccu_mux_helper_get_parent(struct ccu_common *common,
  110. struct ccu_mux_internal *cm);
  111. int ccu_mux_helper_set_parent(struct ccu_common *common,
  112. struct ccu_mux_internal *cm,
  113. u8 index);
  114. struct ccu_mux_nb {
  115. struct notifier_block clk_nb;
  116. struct ccu_common *common;
  117. struct ccu_mux_internal *cm;
  118. u32 delay_us; /* How many us to wait after reparenting */
  119. u8 bypass_index; /* Which parent to temporarily use */
  120. u8 original_index; /* This is set by the notifier callback */
  121. };
  122. #define to_ccu_mux_nb(_nb) container_of(_nb, struct ccu_mux_nb, clk_nb)
  123. int ccu_mux_notifier_register(struct clk *clk, struct ccu_mux_nb *mux_nb);
  124. #endif /* _CCU_MUX_H_ */