clk-mtk.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.h>
  19. #include <linux/clk-provider.h>
  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_factor {
  24. int id;
  25. const char *name;
  26. const char *parent_name;
  27. int mult;
  28. int div;
  29. };
  30. #define FACTOR(_id, _name, _parent, _mult, _div) { \
  31. .id = _id, \
  32. .name = _name, \
  33. .parent_name = _parent, \
  34. .mult = _mult, \
  35. .div = _div, \
  36. }
  37. extern void mtk_clk_register_factors(const struct mtk_fixed_factor *clks,
  38. int num, struct clk_onecell_data *clk_data);
  39. struct mtk_composite {
  40. int id;
  41. const char *name;
  42. const char * const *parent_names;
  43. const char *parent;
  44. unsigned flags;
  45. uint32_t mux_reg;
  46. uint32_t divider_reg;
  47. uint32_t gate_reg;
  48. signed char mux_shift;
  49. signed char mux_width;
  50. signed char gate_shift;
  51. signed char divider_shift;
  52. signed char divider_width;
  53. signed char num_parents;
  54. };
  55. #define MUX_GATE(_id, _name, _parents, _reg, _shift, _width, _gate) { \
  56. .id = _id, \
  57. .name = _name, \
  58. .mux_reg = _reg, \
  59. .mux_shift = _shift, \
  60. .mux_width = _width, \
  61. .gate_reg = _reg, \
  62. .gate_shift = _gate, \
  63. .divider_shift = -1, \
  64. .parent_names = _parents, \
  65. .num_parents = ARRAY_SIZE(_parents), \
  66. .flags = CLK_SET_RATE_PARENT, \
  67. }
  68. #define MUX(_id, _name, _parents, _reg, _shift, _width) { \
  69. .id = _id, \
  70. .name = _name, \
  71. .mux_reg = _reg, \
  72. .mux_shift = _shift, \
  73. .mux_width = _width, \
  74. .gate_shift = -1, \
  75. .divider_shift = -1, \
  76. .parent_names = _parents, \
  77. .num_parents = ARRAY_SIZE(_parents), \
  78. .flags = CLK_SET_RATE_PARENT, \
  79. }
  80. #define DIV_GATE(_id, _name, _parent, _gate_reg, _gate_shift, _div_reg, _div_width, _div_shift) { \
  81. .id = _id, \
  82. .parent = _parent, \
  83. .name = _name, \
  84. .divider_reg = _div_reg, \
  85. .divider_shift = _div_shift, \
  86. .divider_width = _div_width, \
  87. .gate_reg = _gate_reg, \
  88. .gate_shift = _gate_shift, \
  89. .mux_shift = -1, \
  90. .flags = 0, \
  91. }
  92. struct clk *mtk_clk_register_composite(const struct mtk_composite *mc,
  93. void __iomem *base, spinlock_t *lock);
  94. void mtk_clk_register_composites(const struct mtk_composite *mcs,
  95. int num, void __iomem *base, spinlock_t *lock,
  96. struct clk_onecell_data *clk_data);
  97. struct mtk_gate_regs {
  98. u32 sta_ofs;
  99. u32 clr_ofs;
  100. u32 set_ofs;
  101. };
  102. struct mtk_gate {
  103. int id;
  104. const char *name;
  105. const char *parent_name;
  106. const struct mtk_gate_regs *regs;
  107. int shift;
  108. const struct clk_ops *ops;
  109. };
  110. int mtk_clk_register_gates(struct device_node *node, const struct mtk_gate *clks,
  111. int num, struct clk_onecell_data *clk_data);
  112. struct clk_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
  113. #define HAVE_RST_BAR BIT(0)
  114. struct mtk_pll_data {
  115. int id;
  116. const char *name;
  117. uint32_t reg;
  118. uint32_t pwr_reg;
  119. uint32_t en_mask;
  120. uint32_t pd_reg;
  121. uint32_t tuner_reg;
  122. int pd_shift;
  123. unsigned int flags;
  124. const struct clk_ops *ops;
  125. u32 rst_bar_mask;
  126. unsigned long fmax;
  127. int pcwbits;
  128. uint32_t pcw_reg;
  129. int pcw_shift;
  130. };
  131. void __init mtk_clk_register_plls(struct device_node *node,
  132. const struct mtk_pll_data *plls, int num_plls,
  133. struct clk_onecell_data *clk_data);
  134. #ifdef CONFIG_RESET_CONTROLLER
  135. void mtk_register_reset_controller(struct device_node *np,
  136. unsigned int num_regs, int regofs);
  137. #else
  138. static inline void mtk_register_reset_controller(struct device_node *np,
  139. unsigned int num_regs, int regofs)
  140. {
  141. }
  142. #endif
  143. #endif /* __DRV_CLK_MTK_H */