clk.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Hisilicon Hi3620 clock gate driver
  3. *
  4. * Copyright (c) 2012-2013 Hisilicon Limited.
  5. * Copyright (c) 2012-2013 Linaro Limited.
  6. *
  7. * Author: Haojian Zhuang <haojian.zhuang@linaro.org>
  8. * Xin Li <li.xin@linaro.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #ifndef __HISI_CLK_H
  26. #define __HISI_CLK_H
  27. #include <linux/clk-provider.h>
  28. #include <linux/io.h>
  29. #include <linux/spinlock.h>
  30. struct platform_device;
  31. struct hisi_clock_data {
  32. struct clk_onecell_data clk_data;
  33. void __iomem *base;
  34. };
  35. struct hisi_fixed_rate_clock {
  36. unsigned int id;
  37. char *name;
  38. const char *parent_name;
  39. unsigned long flags;
  40. unsigned long fixed_rate;
  41. };
  42. struct hisi_fixed_factor_clock {
  43. unsigned int id;
  44. char *name;
  45. const char *parent_name;
  46. unsigned long mult;
  47. unsigned long div;
  48. unsigned long flags;
  49. };
  50. struct hisi_mux_clock {
  51. unsigned int id;
  52. const char *name;
  53. const char *const *parent_names;
  54. u8 num_parents;
  55. unsigned long flags;
  56. unsigned long offset;
  57. u8 shift;
  58. u8 width;
  59. u8 mux_flags;
  60. u32 *table;
  61. const char *alias;
  62. };
  63. struct hisi_phase_clock {
  64. unsigned int id;
  65. const char *name;
  66. const char *parent_names;
  67. unsigned long flags;
  68. unsigned long offset;
  69. u8 shift;
  70. u8 width;
  71. u32 *phase_degrees;
  72. u32 *phase_regvals;
  73. u8 phase_num;
  74. };
  75. struct hisi_divider_clock {
  76. unsigned int id;
  77. const char *name;
  78. const char *parent_name;
  79. unsigned long flags;
  80. unsigned long offset;
  81. u8 shift;
  82. u8 width;
  83. u8 div_flags;
  84. struct clk_div_table *table;
  85. const char *alias;
  86. };
  87. struct hi6220_divider_clock {
  88. unsigned int id;
  89. const char *name;
  90. const char *parent_name;
  91. unsigned long flags;
  92. unsigned long offset;
  93. u8 shift;
  94. u8 width;
  95. u32 mask_bit;
  96. const char *alias;
  97. };
  98. struct hisi_gate_clock {
  99. unsigned int id;
  100. const char *name;
  101. const char *parent_name;
  102. unsigned long flags;
  103. unsigned long offset;
  104. u8 bit_idx;
  105. u8 gate_flags;
  106. const char *alias;
  107. };
  108. struct clk *hisi_register_clkgate_sep(struct device *, const char *,
  109. const char *, unsigned long,
  110. void __iomem *, u8,
  111. u8, spinlock_t *);
  112. struct clk *hi6220_register_clkdiv(struct device *dev, const char *name,
  113. const char *parent_name, unsigned long flags, void __iomem *reg,
  114. u8 shift, u8 width, u32 mask_bit, spinlock_t *lock);
  115. struct hisi_clock_data *hisi_clk_alloc(struct platform_device *, int);
  116. struct hisi_clock_data *hisi_clk_init(struct device_node *, int);
  117. int hisi_clk_register_fixed_rate(const struct hisi_fixed_rate_clock *,
  118. int, struct hisi_clock_data *);
  119. int hisi_clk_register_fixed_factor(const struct hisi_fixed_factor_clock *,
  120. int, struct hisi_clock_data *);
  121. int hisi_clk_register_mux(const struct hisi_mux_clock *, int,
  122. struct hisi_clock_data *);
  123. struct clk *clk_register_hisi_phase(struct device *dev,
  124. const struct hisi_phase_clock *clks,
  125. void __iomem *base, spinlock_t *lock);
  126. int hisi_clk_register_phase(struct device *dev,
  127. const struct hisi_phase_clock *clks,
  128. int nums, struct hisi_clock_data *data);
  129. int hisi_clk_register_divider(const struct hisi_divider_clock *,
  130. int, struct hisi_clock_data *);
  131. int hisi_clk_register_gate(const struct hisi_gate_clock *,
  132. int, struct hisi_clock_data *);
  133. void hisi_clk_register_gate_sep(const struct hisi_gate_clock *,
  134. int, struct hisi_clock_data *);
  135. void hi6220_clk_register_divider(const struct hi6220_divider_clock *,
  136. int, struct hisi_clock_data *);
  137. #define hisi_clk_unregister(type) \
  138. static inline \
  139. void hisi_clk_unregister_##type(const struct hisi_##type##_clock *clks, \
  140. int nums, struct hisi_clock_data *data) \
  141. { \
  142. struct clk **clocks = data->clk_data.clks; \
  143. int i; \
  144. for (i = 0; i < nums; i++) { \
  145. int id = clks[i].id; \
  146. if (clocks[id]) \
  147. clk_unregister_##type(clocks[id]); \
  148. } \
  149. }
  150. hisi_clk_unregister(fixed_rate)
  151. hisi_clk_unregister(fixed_factor)
  152. hisi_clk_unregister(mux)
  153. hisi_clk_unregister(divider)
  154. hisi_clk_unregister(gate)
  155. #endif /* __HISI_CLK_H */