clk.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #ifndef __MACH_MMP_CLK_H
  2. #define __MACH_MMP_CLK_H
  3. #include <linux/clk-provider.h>
  4. #include <linux/clkdev.h>
  5. #define APBC_NO_BUS_CTRL BIT(0)
  6. #define APBC_POWER_CTRL BIT(1)
  7. /* Clock type "factor" */
  8. struct mmp_clk_factor_masks {
  9. unsigned int factor;
  10. unsigned int num_mask;
  11. unsigned int den_mask;
  12. unsigned int num_shift;
  13. unsigned int den_shift;
  14. };
  15. struct mmp_clk_factor_tbl {
  16. unsigned int num;
  17. unsigned int den;
  18. };
  19. struct mmp_clk_factor {
  20. struct clk_hw hw;
  21. void __iomem *base;
  22. struct mmp_clk_factor_masks *masks;
  23. struct mmp_clk_factor_tbl *ftbl;
  24. unsigned int ftbl_cnt;
  25. spinlock_t *lock;
  26. };
  27. extern struct clk *mmp_clk_register_factor(const char *name,
  28. const char *parent_name, unsigned long flags,
  29. void __iomem *base, struct mmp_clk_factor_masks *masks,
  30. struct mmp_clk_factor_tbl *ftbl, unsigned int ftbl_cnt,
  31. spinlock_t *lock);
  32. /* Clock type "mix" */
  33. #define MMP_CLK_BITS_MASK(width, shift) \
  34. (((1 << (width)) - 1) << (shift))
  35. #define MMP_CLK_BITS_GET_VAL(data, width, shift) \
  36. ((data & MMP_CLK_BITS_MASK(width, shift)) >> (shift))
  37. #define MMP_CLK_BITS_SET_VAL(val, width, shift) \
  38. (((val) << (shift)) & MMP_CLK_BITS_MASK(width, shift))
  39. enum {
  40. MMP_CLK_MIX_TYPE_V1,
  41. MMP_CLK_MIX_TYPE_V2,
  42. MMP_CLK_MIX_TYPE_V3,
  43. };
  44. /* The register layout */
  45. struct mmp_clk_mix_reg_info {
  46. void __iomem *reg_clk_ctrl;
  47. void __iomem *reg_clk_sel;
  48. u8 width_div;
  49. u8 shift_div;
  50. u8 width_mux;
  51. u8 shift_mux;
  52. u8 bit_fc;
  53. };
  54. /* The suggested clock table from user. */
  55. struct mmp_clk_mix_clk_table {
  56. unsigned long rate;
  57. u8 parent_index;
  58. unsigned int divisor;
  59. unsigned int valid;
  60. };
  61. struct mmp_clk_mix_config {
  62. struct mmp_clk_mix_reg_info reg_info;
  63. struct mmp_clk_mix_clk_table *table;
  64. unsigned int table_size;
  65. u32 *mux_table;
  66. struct clk_div_table *div_table;
  67. u8 div_flags;
  68. u8 mux_flags;
  69. };
  70. struct mmp_clk_mix {
  71. struct clk_hw hw;
  72. struct mmp_clk_mix_reg_info reg_info;
  73. struct mmp_clk_mix_clk_table *table;
  74. u32 *mux_table;
  75. struct clk_div_table *div_table;
  76. unsigned int table_size;
  77. u8 div_flags;
  78. u8 mux_flags;
  79. unsigned int type;
  80. spinlock_t *lock;
  81. };
  82. extern const struct clk_ops mmp_clk_mix_ops;
  83. extern struct clk *mmp_clk_register_mix(struct device *dev,
  84. const char *name,
  85. const char **parent_names,
  86. u8 num_parents,
  87. unsigned long flags,
  88. struct mmp_clk_mix_config *config,
  89. spinlock_t *lock);
  90. /* Clock type "gate". MMP private gate */
  91. #define MMP_CLK_GATE_NEED_DELAY BIT(0)
  92. struct mmp_clk_gate {
  93. struct clk_hw hw;
  94. void __iomem *reg;
  95. u32 mask;
  96. u32 val_enable;
  97. u32 val_disable;
  98. unsigned int flags;
  99. spinlock_t *lock;
  100. };
  101. extern const struct clk_ops mmp_clk_gate_ops;
  102. extern struct clk *mmp_clk_register_gate(struct device *dev, const char *name,
  103. const char *parent_name, unsigned long flags,
  104. void __iomem *reg, u32 mask, u32 val_enable,
  105. u32 val_disable, unsigned int gate_flags,
  106. spinlock_t *lock);
  107. extern struct clk *mmp_clk_register_pll2(const char *name,
  108. const char *parent_name, unsigned long flags);
  109. extern struct clk *mmp_clk_register_apbc(const char *name,
  110. const char *parent_name, void __iomem *base,
  111. unsigned int delay, unsigned int apbc_flags, spinlock_t *lock);
  112. extern struct clk *mmp_clk_register_apmu(const char *name,
  113. const char *parent_name, void __iomem *base, u32 enable_mask,
  114. spinlock_t *lock);
  115. struct mmp_clk_unit {
  116. unsigned int nr_clks;
  117. struct clk **clk_table;
  118. struct clk_onecell_data clk_data;
  119. };
  120. struct mmp_param_fixed_rate_clk {
  121. unsigned int id;
  122. char *name;
  123. const char *parent_name;
  124. unsigned long flags;
  125. unsigned long fixed_rate;
  126. };
  127. void mmp_register_fixed_rate_clks(struct mmp_clk_unit *unit,
  128. struct mmp_param_fixed_rate_clk *clks,
  129. int size);
  130. struct mmp_param_fixed_factor_clk {
  131. unsigned int id;
  132. char *name;
  133. const char *parent_name;
  134. unsigned long mult;
  135. unsigned long div;
  136. unsigned long flags;
  137. };
  138. void mmp_register_fixed_factor_clks(struct mmp_clk_unit *unit,
  139. struct mmp_param_fixed_factor_clk *clks,
  140. int size);
  141. struct mmp_param_general_gate_clk {
  142. unsigned int id;
  143. const char *name;
  144. const char *parent_name;
  145. unsigned long flags;
  146. unsigned long offset;
  147. u8 bit_idx;
  148. u8 gate_flags;
  149. spinlock_t *lock;
  150. };
  151. void mmp_register_general_gate_clks(struct mmp_clk_unit *unit,
  152. struct mmp_param_general_gate_clk *clks,
  153. void __iomem *base, int size);
  154. struct mmp_param_gate_clk {
  155. unsigned int id;
  156. char *name;
  157. const char *parent_name;
  158. unsigned long flags;
  159. unsigned long offset;
  160. u32 mask;
  161. u32 val_enable;
  162. u32 val_disable;
  163. unsigned int gate_flags;
  164. spinlock_t *lock;
  165. };
  166. void mmp_register_gate_clks(struct mmp_clk_unit *unit,
  167. struct mmp_param_gate_clk *clks,
  168. void __iomem *base, int size);
  169. struct mmp_param_mux_clk {
  170. unsigned int id;
  171. char *name;
  172. const char **parent_name;
  173. u8 num_parents;
  174. unsigned long flags;
  175. unsigned long offset;
  176. u8 shift;
  177. u8 width;
  178. u8 mux_flags;
  179. spinlock_t *lock;
  180. };
  181. void mmp_register_mux_clks(struct mmp_clk_unit *unit,
  182. struct mmp_param_mux_clk *clks,
  183. void __iomem *base, int size);
  184. struct mmp_param_div_clk {
  185. unsigned int id;
  186. char *name;
  187. const char *parent_name;
  188. unsigned long flags;
  189. unsigned long offset;
  190. u8 shift;
  191. u8 width;
  192. u8 div_flags;
  193. spinlock_t *lock;
  194. };
  195. void mmp_register_div_clks(struct mmp_clk_unit *unit,
  196. struct mmp_param_div_clk *clks,
  197. void __iomem *base, int size);
  198. #define DEFINE_MIX_REG_INFO(w_d, s_d, w_m, s_m, fc) \
  199. { \
  200. .width_div = (w_d), \
  201. .shift_div = (s_d), \
  202. .width_mux = (w_m), \
  203. .shift_mux = (s_m), \
  204. .bit_fc = (fc), \
  205. }
  206. void mmp_clk_init(struct device_node *np, struct mmp_clk_unit *unit,
  207. int nr_clks);
  208. void mmp_clk_add(struct mmp_clk_unit *unit, unsigned int id,
  209. struct clk *clk);
  210. #endif