clk-mtk.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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, \
  74. _gate, _flags) { \
  75. .id = _id, \
  76. .name = _name, \
  77. .mux_reg = _reg, \
  78. .mux_shift = _shift, \
  79. .mux_width = _width, \
  80. .gate_reg = _reg, \
  81. .gate_shift = _gate, \
  82. .divider_shift = -1, \
  83. .parent_names = _parents, \
  84. .num_parents = ARRAY_SIZE(_parents), \
  85. .flags = _flags, \
  86. }
  87. /*
  88. * Unless necessary, all MUX_GATE clocks propagate rate changes to their
  89. * parent clock by default.
  90. */
  91. #define MUX_GATE(_id, _name, _parents, _reg, _shift, _width, _gate) \
  92. MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
  93. _gate, CLK_SET_RATE_PARENT)
  94. #define MUX(_id, _name, _parents, _reg, _shift, _width) { \
  95. .id = _id, \
  96. .name = _name, \
  97. .mux_reg = _reg, \
  98. .mux_shift = _shift, \
  99. .mux_width = _width, \
  100. .gate_shift = -1, \
  101. .divider_shift = -1, \
  102. .parent_names = _parents, \
  103. .num_parents = ARRAY_SIZE(_parents), \
  104. .flags = CLK_SET_RATE_PARENT, \
  105. }
  106. #define DIV_GATE(_id, _name, _parent, _gate_reg, _gate_shift, _div_reg, \
  107. _div_width, _div_shift) { \
  108. .id = _id, \
  109. .parent = _parent, \
  110. .name = _name, \
  111. .divider_reg = _div_reg, \
  112. .divider_shift = _div_shift, \
  113. .divider_width = _div_width, \
  114. .gate_reg = _gate_reg, \
  115. .gate_shift = _gate_shift, \
  116. .mux_shift = -1, \
  117. .flags = 0, \
  118. }
  119. struct clk *mtk_clk_register_composite(const struct mtk_composite *mc,
  120. void __iomem *base, spinlock_t *lock);
  121. void mtk_clk_register_composites(const struct mtk_composite *mcs,
  122. int num, void __iomem *base, spinlock_t *lock,
  123. struct clk_onecell_data *clk_data);
  124. struct mtk_gate_regs {
  125. u32 sta_ofs;
  126. u32 clr_ofs;
  127. u32 set_ofs;
  128. };
  129. struct mtk_gate {
  130. int id;
  131. const char *name;
  132. const char *parent_name;
  133. const struct mtk_gate_regs *regs;
  134. int shift;
  135. const struct clk_ops *ops;
  136. };
  137. int mtk_clk_register_gates(struct device_node *node,
  138. const struct mtk_gate *clks, int num,
  139. struct clk_onecell_data *clk_data);
  140. struct mtk_clk_divider {
  141. int id;
  142. const char *name;
  143. const char *parent_name;
  144. unsigned long flags;
  145. u32 div_reg;
  146. unsigned char div_shift;
  147. unsigned char div_width;
  148. unsigned char clk_divider_flags;
  149. const struct clk_div_table *clk_div_table;
  150. };
  151. #define DIV_ADJ(_id, _name, _parent, _reg, _shift, _width) { \
  152. .id = _id, \
  153. .name = _name, \
  154. .parent_name = _parent, \
  155. .div_reg = _reg, \
  156. .div_shift = _shift, \
  157. .div_width = _width, \
  158. }
  159. void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds,
  160. int num, void __iomem *base, spinlock_t *lock,
  161. struct clk_onecell_data *clk_data);
  162. struct clk_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
  163. #define HAVE_RST_BAR BIT(0)
  164. #define PLL_AO BIT(1)
  165. struct mtk_pll_div_table {
  166. u32 div;
  167. unsigned long freq;
  168. };
  169. struct mtk_pll_data {
  170. int id;
  171. const char *name;
  172. uint32_t reg;
  173. uint32_t pwr_reg;
  174. uint32_t en_mask;
  175. uint32_t pd_reg;
  176. uint32_t tuner_reg;
  177. int pd_shift;
  178. unsigned int flags;
  179. const struct clk_ops *ops;
  180. u32 rst_bar_mask;
  181. unsigned long fmax;
  182. int pcwbits;
  183. uint32_t pcw_reg;
  184. int pcw_shift;
  185. const struct mtk_pll_div_table *div_table;
  186. };
  187. void mtk_clk_register_plls(struct device_node *node,
  188. const struct mtk_pll_data *plls, int num_plls,
  189. struct clk_onecell_data *clk_data);
  190. struct clk *mtk_clk_register_ref2usb_tx(const char *name,
  191. const char *parent_name, void __iomem *reg);
  192. #ifdef CONFIG_RESET_CONTROLLER
  193. void mtk_register_reset_controller(struct device_node *np,
  194. unsigned int num_regs, int regofs);
  195. #else
  196. static inline void mtk_register_reset_controller(struct device_node *np,
  197. unsigned int num_regs, int regofs)
  198. {
  199. }
  200. #endif
  201. #endif /* __DRV_CLK_MTK_H */