clk-mtk.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2014 MediaTek Inc.
  4. * Author: James Liao <[email protected]>
  5. */
  6. #ifndef __DRV_CLK_MTK_H
  7. #define __DRV_CLK_MTK_H
  8. #include <linux/clk-provider.h>
  9. #include <linux/io.h>
  10. #include <linux/kernel.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/types.h>
  13. #include "reset.h"
  14. #define MAX_MUX_GATE_BIT 31
  15. #define INVALID_MUX_GATE_BIT (MAX_MUX_GATE_BIT + 1)
  16. #define MHZ (1000 * 1000)
  17. struct platform_device;
  18. struct mtk_fixed_clk {
  19. int id;
  20. const char *name;
  21. const char *parent;
  22. unsigned long rate;
  23. };
  24. #define FIXED_CLK(_id, _name, _parent, _rate) { \
  25. .id = _id, \
  26. .name = _name, \
  27. .parent = _parent, \
  28. .rate = _rate, \
  29. }
  30. int mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, int num,
  31. struct clk_hw_onecell_data *clk_data);
  32. void mtk_clk_unregister_fixed_clks(const struct mtk_fixed_clk *clks, int num,
  33. struct clk_hw_onecell_data *clk_data);
  34. struct mtk_fixed_factor {
  35. int id;
  36. const char *name;
  37. const char *parent_name;
  38. int mult;
  39. int div;
  40. };
  41. #define FACTOR(_id, _name, _parent, _mult, _div) { \
  42. .id = _id, \
  43. .name = _name, \
  44. .parent_name = _parent, \
  45. .mult = _mult, \
  46. .div = _div, \
  47. }
  48. int mtk_clk_register_factors(const struct mtk_fixed_factor *clks, int num,
  49. struct clk_hw_onecell_data *clk_data);
  50. void mtk_clk_unregister_factors(const struct mtk_fixed_factor *clks, int num,
  51. struct clk_hw_onecell_data *clk_data);
  52. struct mtk_composite {
  53. int id;
  54. const char *name;
  55. const char * const *parent_names;
  56. const char *parent;
  57. unsigned flags;
  58. uint32_t mux_reg;
  59. uint32_t divider_reg;
  60. uint32_t gate_reg;
  61. signed char mux_shift;
  62. signed char mux_width;
  63. signed char gate_shift;
  64. signed char divider_shift;
  65. signed char divider_width;
  66. u8 mux_flags;
  67. signed char num_parents;
  68. };
  69. #define MUX_GATE_FLAGS_2(_id, _name, _parents, _reg, _shift, \
  70. _width, _gate, _flags, _muxflags) { \
  71. .id = _id, \
  72. .name = _name, \
  73. .mux_reg = _reg, \
  74. .mux_shift = _shift, \
  75. .mux_width = _width, \
  76. .gate_reg = _reg, \
  77. .gate_shift = _gate, \
  78. .divider_shift = -1, \
  79. .parent_names = _parents, \
  80. .num_parents = ARRAY_SIZE(_parents), \
  81. .flags = _flags, \
  82. .mux_flags = _muxflags, \
  83. }
  84. /*
  85. * In case the rate change propagation to parent clocks is undesirable,
  86. * this macro allows to specify the clock flags manually.
  87. */
  88. #define MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
  89. _gate, _flags) \
  90. MUX_GATE_FLAGS_2(_id, _name, _parents, _reg, \
  91. _shift, _width, _gate, _flags, 0)
  92. /*
  93. * Unless necessary, all MUX_GATE clocks propagate rate changes to their
  94. * parent clock by default.
  95. */
  96. #define MUX_GATE(_id, _name, _parents, _reg, _shift, _width, _gate) \
  97. MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
  98. _gate, CLK_SET_RATE_PARENT)
  99. #define MUX(_id, _name, _parents, _reg, _shift, _width) \
  100. MUX_FLAGS(_id, _name, _parents, _reg, \
  101. _shift, _width, CLK_SET_RATE_PARENT)
  102. #define MUX_FLAGS(_id, _name, _parents, _reg, _shift, _width, _flags) { \
  103. .id = _id, \
  104. .name = _name, \
  105. .mux_reg = _reg, \
  106. .mux_shift = _shift, \
  107. .mux_width = _width, \
  108. .gate_shift = -1, \
  109. .divider_shift = -1, \
  110. .parent_names = _parents, \
  111. .num_parents = ARRAY_SIZE(_parents), \
  112. .flags = _flags, \
  113. }
  114. #define DIV_GATE(_id, _name, _parent, _gate_reg, _gate_shift, _div_reg, \
  115. _div_width, _div_shift) { \
  116. .id = _id, \
  117. .parent = _parent, \
  118. .name = _name, \
  119. .divider_reg = _div_reg, \
  120. .divider_shift = _div_shift, \
  121. .divider_width = _div_width, \
  122. .gate_reg = _gate_reg, \
  123. .gate_shift = _gate_shift, \
  124. .mux_shift = -1, \
  125. .flags = 0, \
  126. }
  127. int mtk_clk_register_composites(const struct mtk_composite *mcs, int num,
  128. void __iomem *base, spinlock_t *lock,
  129. struct clk_hw_onecell_data *clk_data);
  130. void mtk_clk_unregister_composites(const struct mtk_composite *mcs, int num,
  131. struct clk_hw_onecell_data *clk_data);
  132. struct mtk_clk_divider {
  133. int id;
  134. const char *name;
  135. const char *parent_name;
  136. unsigned long flags;
  137. u32 div_reg;
  138. unsigned char div_shift;
  139. unsigned char div_width;
  140. unsigned char clk_divider_flags;
  141. const struct clk_div_table *clk_div_table;
  142. };
  143. #define DIV_ADJ(_id, _name, _parent, _reg, _shift, _width) { \
  144. .id = _id, \
  145. .name = _name, \
  146. .parent_name = _parent, \
  147. .div_reg = _reg, \
  148. .div_shift = _shift, \
  149. .div_width = _width, \
  150. }
  151. int mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, int num,
  152. void __iomem *base, spinlock_t *lock,
  153. struct clk_hw_onecell_data *clk_data);
  154. void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num,
  155. struct clk_hw_onecell_data *clk_data);
  156. struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
  157. struct clk_hw_onecell_data *mtk_devm_alloc_clk_data(struct device *dev,
  158. unsigned int clk_num);
  159. void mtk_free_clk_data(struct clk_hw_onecell_data *clk_data);
  160. struct clk_hw *mtk_clk_register_ref2usb_tx(const char *name,
  161. const char *parent_name, void __iomem *reg);
  162. void mtk_clk_unregister_ref2usb_tx(struct clk_hw *hw);
  163. struct mtk_clk_desc {
  164. const struct mtk_gate *clks;
  165. size_t num_clks;
  166. const struct mtk_clk_rst_desc *rst_desc;
  167. };
  168. int mtk_clk_simple_probe(struct platform_device *pdev);
  169. int mtk_clk_simple_remove(struct platform_device *pdev);
  170. #endif /* __DRV_CLK_MTK_H */