clk-mtk.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. struct clk_onecell_data;
  21. #define MAX_MUX_GATE_BIT 31
  22. #define INVALID_MUX_GATE_BIT (MAX_MUX_GATE_BIT + 1)
  23. #define MHZ (1000 * 1000)
  24. struct mtk_fixed_clk {
  25. int id;
  26. const char *name;
  27. const char *parent;
  28. unsigned long rate;
  29. };
  30. #define FIXED_CLK(_id, _name, _parent, _rate) { \
  31. .id = _id, \
  32. .name = _name, \
  33. .parent = _parent, \
  34. .rate = _rate, \
  35. }
  36. void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks,
  37. int num, struct clk_onecell_data *clk_data);
  38. struct mtk_fixed_factor {
  39. int id;
  40. const char *name;
  41. const char *parent_name;
  42. int mult;
  43. int div;
  44. };
  45. #define FACTOR(_id, _name, _parent, _mult, _div) { \
  46. .id = _id, \
  47. .name = _name, \
  48. .parent_name = _parent, \
  49. .mult = _mult, \
  50. .div = _div, \
  51. }
  52. void mtk_clk_register_factors(const struct mtk_fixed_factor *clks,
  53. int num, struct clk_onecell_data *clk_data);
  54. struct mtk_composite {
  55. int id;
  56. const char *name;
  57. const char * const *parent_names;
  58. const char *parent;
  59. unsigned flags;
  60. uint32_t mux_reg;
  61. uint32_t divider_reg;
  62. uint32_t gate_reg;
  63. signed char mux_shift;
  64. signed char mux_width;
  65. signed char gate_shift;
  66. signed char divider_shift;
  67. signed char divider_width;
  68. signed char num_parents;
  69. };
  70. /*
  71. * In case the rate change propagation to parent clocks is undesirable,
  72. * this macro allows to specify the clock flags manually.
  73. */
  74. #define MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
  75. _gate, _flags) { \
  76. .id = _id, \
  77. .name = _name, \
  78. .mux_reg = _reg, \
  79. .mux_shift = _shift, \
  80. .mux_width = _width, \
  81. .gate_reg = _reg, \
  82. .gate_shift = _gate, \
  83. .divider_shift = -1, \
  84. .parent_names = _parents, \
  85. .num_parents = ARRAY_SIZE(_parents), \
  86. .flags = _flags, \
  87. }
  88. /*
  89. * Unless necessary, all MUX_GATE clocks propagate rate changes to their
  90. * parent clock by default.
  91. */
  92. #define MUX_GATE(_id, _name, _parents, _reg, _shift, _width, _gate) \
  93. MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
  94. _gate, CLK_SET_RATE_PARENT)
  95. #define MUX(_id, _name, _parents, _reg, _shift, _width) { \
  96. .id = _id, \
  97. .name = _name, \
  98. .mux_reg = _reg, \
  99. .mux_shift = _shift, \
  100. .mux_width = _width, \
  101. .gate_shift = -1, \
  102. .divider_shift = -1, \
  103. .parent_names = _parents, \
  104. .num_parents = ARRAY_SIZE(_parents), \
  105. .flags = CLK_SET_RATE_PARENT, \
  106. }
  107. #define DIV_GATE(_id, _name, _parent, _gate_reg, _gate_shift, _div_reg, \
  108. _div_width, _div_shift) { \
  109. .id = _id, \
  110. .parent = _parent, \
  111. .name = _name, \
  112. .divider_reg = _div_reg, \
  113. .divider_shift = _div_shift, \
  114. .divider_width = _div_width, \
  115. .gate_reg = _gate_reg, \
  116. .gate_shift = _gate_shift, \
  117. .mux_shift = -1, \
  118. .flags = 0, \
  119. }
  120. struct clk *mtk_clk_register_composite(const struct mtk_composite *mc,
  121. void __iomem *base, spinlock_t *lock);
  122. void mtk_clk_register_composites(const struct mtk_composite *mcs,
  123. int num, void __iomem *base, spinlock_t *lock,
  124. struct clk_onecell_data *clk_data);
  125. struct mtk_gate_regs {
  126. u32 sta_ofs;
  127. u32 clr_ofs;
  128. u32 set_ofs;
  129. };
  130. struct mtk_gate {
  131. int id;
  132. const char *name;
  133. const char *parent_name;
  134. const struct mtk_gate_regs *regs;
  135. int shift;
  136. const struct clk_ops *ops;
  137. };
  138. int mtk_clk_register_gates(struct device_node *node,
  139. const struct mtk_gate *clks, int num,
  140. struct clk_onecell_data *clk_data);
  141. struct mtk_clk_divider {
  142. int id;
  143. const char *name;
  144. const char *parent_name;
  145. unsigned long flags;
  146. u32 div_reg;
  147. unsigned char div_shift;
  148. unsigned char div_width;
  149. unsigned char clk_divider_flags;
  150. const struct clk_div_table *clk_div_table;
  151. };
  152. #define DIV_ADJ(_id, _name, _parent, _reg, _shift, _width) { \
  153. .id = _id, \
  154. .name = _name, \
  155. .parent_name = _parent, \
  156. .div_reg = _reg, \
  157. .div_shift = _shift, \
  158. .div_width = _width, \
  159. }
  160. void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds,
  161. int num, void __iomem *base, spinlock_t *lock,
  162. struct clk_onecell_data *clk_data);
  163. struct clk_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
  164. #define HAVE_RST_BAR BIT(0)
  165. #define PLL_AO BIT(1)
  166. struct mtk_pll_div_table {
  167. u32 div;
  168. unsigned long freq;
  169. };
  170. struct mtk_pll_data {
  171. int id;
  172. const char *name;
  173. uint32_t reg;
  174. uint32_t pwr_reg;
  175. uint32_t en_mask;
  176. uint32_t pd_reg;
  177. uint32_t tuner_reg;
  178. uint32_t tuner_en_reg;
  179. uint8_t tuner_en_bit;
  180. int pd_shift;
  181. unsigned int flags;
  182. const struct clk_ops *ops;
  183. u32 rst_bar_mask;
  184. unsigned long fmax;
  185. int pcwbits;
  186. uint32_t pcw_reg;
  187. int pcw_shift;
  188. const struct mtk_pll_div_table *div_table;
  189. const char *parent_name;
  190. };
  191. void mtk_clk_register_plls(struct device_node *node,
  192. const struct mtk_pll_data *plls, int num_plls,
  193. struct clk_onecell_data *clk_data);
  194. struct clk *mtk_clk_register_ref2usb_tx(const char *name,
  195. const char *parent_name, void __iomem *reg);
  196. void mtk_register_reset_controller(struct device_node *np,
  197. unsigned int num_regs, int regofs);
  198. #endif /* __DRV_CLK_MTK_H */