clk-mtk.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #define MUX_GATE(_id, _name, _parents, _reg, _shift, _width, _gate) { \
  70. .id = _id, \
  71. .name = _name, \
  72. .mux_reg = _reg, \
  73. .mux_shift = _shift, \
  74. .mux_width = _width, \
  75. .gate_reg = _reg, \
  76. .gate_shift = _gate, \
  77. .divider_shift = -1, \
  78. .parent_names = _parents, \
  79. .num_parents = ARRAY_SIZE(_parents), \
  80. .flags = CLK_SET_RATE_PARENT, \
  81. }
  82. #define MUX(_id, _name, _parents, _reg, _shift, _width) { \
  83. .id = _id, \
  84. .name = _name, \
  85. .mux_reg = _reg, \
  86. .mux_shift = _shift, \
  87. .mux_width = _width, \
  88. .gate_shift = -1, \
  89. .divider_shift = -1, \
  90. .parent_names = _parents, \
  91. .num_parents = ARRAY_SIZE(_parents), \
  92. .flags = CLK_SET_RATE_PARENT, \
  93. }
  94. #define DIV_GATE(_id, _name, _parent, _gate_reg, _gate_shift, _div_reg, _div_width, _div_shift) { \
  95. .id = _id, \
  96. .parent = _parent, \
  97. .name = _name, \
  98. .divider_reg = _div_reg, \
  99. .divider_shift = _div_shift, \
  100. .divider_width = _div_width, \
  101. .gate_reg = _gate_reg, \
  102. .gate_shift = _gate_shift, \
  103. .mux_shift = -1, \
  104. .flags = 0, \
  105. }
  106. struct clk *mtk_clk_register_composite(const struct mtk_composite *mc,
  107. void __iomem *base, spinlock_t *lock);
  108. void mtk_clk_register_composites(const struct mtk_composite *mcs,
  109. int num, void __iomem *base, spinlock_t *lock,
  110. struct clk_onecell_data *clk_data);
  111. struct mtk_gate_regs {
  112. u32 sta_ofs;
  113. u32 clr_ofs;
  114. u32 set_ofs;
  115. };
  116. struct mtk_gate {
  117. int id;
  118. const char *name;
  119. const char *parent_name;
  120. const struct mtk_gate_regs *regs;
  121. int shift;
  122. const struct clk_ops *ops;
  123. };
  124. int mtk_clk_register_gates(struct device_node *node, const struct mtk_gate *clks,
  125. int num, struct clk_onecell_data *clk_data);
  126. struct clk_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
  127. #define HAVE_RST_BAR BIT(0)
  128. struct mtk_pll_div_table {
  129. u32 div;
  130. unsigned long freq;
  131. };
  132. struct mtk_pll_data {
  133. int id;
  134. const char *name;
  135. uint32_t reg;
  136. uint32_t pwr_reg;
  137. uint32_t en_mask;
  138. uint32_t pd_reg;
  139. uint32_t tuner_reg;
  140. int pd_shift;
  141. unsigned int flags;
  142. const struct clk_ops *ops;
  143. u32 rst_bar_mask;
  144. unsigned long fmax;
  145. int pcwbits;
  146. uint32_t pcw_reg;
  147. int pcw_shift;
  148. const struct mtk_pll_div_table *div_table;
  149. const char *parent_name;
  150. };
  151. void mtk_clk_register_plls(struct device_node *node,
  152. const struct mtk_pll_data *plls, int num_plls,
  153. struct clk_onecell_data *clk_data);
  154. struct clk *mtk_clk_register_ref2usb_tx(const char *name,
  155. const char *parent_name, void __iomem *reg);
  156. #ifdef CONFIG_RESET_CONTROLLER
  157. void mtk_register_reset_controller(struct device_node *np,
  158. unsigned int num_regs, int regofs);
  159. #else
  160. static inline void mtk_register_reset_controller(struct device_node *np,
  161. unsigned int num_regs, int regofs)
  162. {
  163. }
  164. #endif
  165. #endif /* __DRV_CLK_MTK_H */