clk-mtk.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright (c) 2014 MediaTek Inc.
  3. * Author: James Liao <jamesjj.liao@mediatek.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __DRV_CLK_MTK_H
  15. #define __DRV_CLK_MTK_H
  16. #include <linux/regmap.h>
  17. #include <linux/bitops.h>
  18. #include <linux/clk-provider.h>
  19. struct clk;
  20. #define MAX_MUX_GATE_BIT 31
  21. #define INVALID_MUX_GATE_BIT (MAX_MUX_GATE_BIT + 1)
  22. #define MHZ (1000 * 1000)
  23. struct mtk_fixed_clk {
  24. int id;
  25. const char *name;
  26. const char *parent;
  27. unsigned long rate;
  28. };
  29. #define FIXED_CLK(_id, _name, _parent, _rate) { \
  30. .id = _id, \
  31. .name = _name, \
  32. .parent = _parent, \
  33. .rate = _rate, \
  34. }
  35. void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks,
  36. int num, struct clk_onecell_data *clk_data);
  37. struct mtk_fixed_factor {
  38. int id;
  39. const char *name;
  40. const char *parent_name;
  41. int mult;
  42. int div;
  43. };
  44. #define FACTOR(_id, _name, _parent, _mult, _div) { \
  45. .id = _id, \
  46. .name = _name, \
  47. .parent_name = _parent, \
  48. .mult = _mult, \
  49. .div = _div, \
  50. }
  51. void mtk_clk_register_factors(const struct mtk_fixed_factor *clks,
  52. int num, struct clk_onecell_data *clk_data);
  53. struct mtk_composite {
  54. int id;
  55. const char *name;
  56. const char * const *parent_names;
  57. const char *parent;
  58. unsigned flags;
  59. uint32_t mux_reg;
  60. uint32_t divider_reg;
  61. uint32_t gate_reg;
  62. signed char mux_shift;
  63. signed char mux_width;
  64. signed char gate_shift;
  65. signed char divider_shift;
  66. signed char divider_width;
  67. signed char num_parents;
  68. };
  69. /*
  70. * In case the rate change propagation to parent clocks is undesirable,
  71. * this macro allows to specify the clock flags manually.
  72. */
  73. #define MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, _gate, _flags) { \
  74. .id = _id, \
  75. .name = _name, \
  76. .mux_reg = _reg, \
  77. .mux_shift = _shift, \
  78. .mux_width = _width, \
  79. .gate_reg = _reg, \
  80. .gate_shift = _gate, \
  81. .divider_shift = -1, \
  82. .parent_names = _parents, \
  83. .num_parents = ARRAY_SIZE(_parents), \
  84. .flags = _flags, \
  85. }
  86. /*
  87. * Unless necessary, all MUX_GATE clocks propagate rate changes to their
  88. * parent clock by default.
  89. */
  90. #define MUX_GATE(_id, _name, _parents, _reg, _shift, _width, _gate) \
  91. MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, _gate, CLK_SET_RATE_PARENT)
  92. #define MUX(_id, _name, _parents, _reg, _shift, _width) { \
  93. .id = _id, \
  94. .name = _name, \
  95. .mux_reg = _reg, \
  96. .mux_shift = _shift, \
  97. .mux_width = _width, \
  98. .gate_shift = -1, \
  99. .divider_shift = -1, \
  100. .parent_names = _parents, \
  101. .num_parents = ARRAY_SIZE(_parents), \
  102. .flags = CLK_SET_RATE_PARENT, \
  103. }
  104. #define DIV_GATE(_id, _name, _parent, _gate_reg, _gate_shift, _div_reg, _div_width, _div_shift) { \
  105. .id = _id, \
  106. .parent = _parent, \
  107. .name = _name, \
  108. .divider_reg = _div_reg, \
  109. .divider_shift = _div_shift, \
  110. .divider_width = _div_width, \
  111. .gate_reg = _gate_reg, \
  112. .gate_shift = _gate_shift, \
  113. .mux_shift = -1, \
  114. .flags = 0, \
  115. }
  116. struct clk *mtk_clk_register_composite(const struct mtk_composite *mc,
  117. void __iomem *base, spinlock_t *lock);
  118. void mtk_clk_register_composites(const struct mtk_composite *mcs,
  119. int num, void __iomem *base, spinlock_t *lock,
  120. struct clk_onecell_data *clk_data);
  121. struct mtk_gate_regs {
  122. u32 sta_ofs;
  123. u32 clr_ofs;
  124. u32 set_ofs;
  125. };
  126. struct mtk_gate {
  127. int id;
  128. const char *name;
  129. const char *parent_name;
  130. const struct mtk_gate_regs *regs;
  131. int shift;
  132. const struct clk_ops *ops;
  133. };
  134. int mtk_clk_register_gates(struct device_node *node, const struct mtk_gate *clks,
  135. int num, struct clk_onecell_data *clk_data);
  136. struct clk_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
  137. #define HAVE_RST_BAR BIT(0)
  138. struct mtk_pll_div_table {
  139. u32 div;
  140. unsigned long freq;
  141. };
  142. struct mtk_pll_data {
  143. int id;
  144. const char *name;
  145. uint32_t reg;
  146. uint32_t pwr_reg;
  147. uint32_t en_mask;
  148. uint32_t pd_reg;
  149. uint32_t tuner_reg;
  150. int pd_shift;
  151. unsigned int flags;
  152. const struct clk_ops *ops;
  153. u32 rst_bar_mask;
  154. unsigned long fmax;
  155. int pcwbits;
  156. uint32_t pcw_reg;
  157. int pcw_shift;
  158. const struct mtk_pll_div_table *div_table;
  159. const char *parent_name;
  160. };
  161. void mtk_clk_register_plls(struct device_node *node,
  162. const struct mtk_pll_data *plls, int num_plls,
  163. struct clk_onecell_data *clk_data);
  164. struct clk *mtk_clk_register_ref2usb_tx(const char *name,
  165. const char *parent_name, void __iomem *reg);
  166. #ifdef CONFIG_RESET_CONTROLLER
  167. void mtk_register_reset_controller(struct device_node *np,
  168. unsigned int num_regs, int regofs);
  169. #else
  170. static inline void mtk_register_reset_controller(struct device_node *np,
  171. unsigned int num_regs, int regofs)
  172. {
  173. }
  174. #endif
  175. #endif /* __DRV_CLK_MTK_H */