clk.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_divider_clock {
  64. unsigned int id;
  65. const char *name;
  66. const char *parent_name;
  67. unsigned long flags;
  68. unsigned long offset;
  69. u8 shift;
  70. u8 width;
  71. u8 div_flags;
  72. struct clk_div_table *table;
  73. const char *alias;
  74. };
  75. struct hi6220_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. u32 mask_bit;
  84. const char *alias;
  85. };
  86. struct hisi_gate_clock {
  87. unsigned int id;
  88. const char *name;
  89. const char *parent_name;
  90. unsigned long flags;
  91. unsigned long offset;
  92. u8 bit_idx;
  93. u8 gate_flags;
  94. const char *alias;
  95. };
  96. struct clk *hisi_register_clkgate_sep(struct device *, const char *,
  97. const char *, unsigned long,
  98. void __iomem *, u8,
  99. u8, spinlock_t *);
  100. struct clk *hi6220_register_clkdiv(struct device *dev, const char *name,
  101. const char *parent_name, unsigned long flags, void __iomem *reg,
  102. u8 shift, u8 width, u32 mask_bit, spinlock_t *lock);
  103. struct hisi_clock_data *hisi_clk_alloc(struct platform_device *, int);
  104. struct hisi_clock_data *hisi_clk_init(struct device_node *, int);
  105. int hisi_clk_register_fixed_rate(const struct hisi_fixed_rate_clock *,
  106. int, struct hisi_clock_data *);
  107. int hisi_clk_register_fixed_factor(const struct hisi_fixed_factor_clock *,
  108. int, struct hisi_clock_data *);
  109. int hisi_clk_register_mux(const struct hisi_mux_clock *, int,
  110. struct hisi_clock_data *);
  111. int hisi_clk_register_divider(const struct hisi_divider_clock *,
  112. int, struct hisi_clock_data *);
  113. int hisi_clk_register_gate(const struct hisi_gate_clock *,
  114. int, struct hisi_clock_data *);
  115. void hisi_clk_register_gate_sep(const struct hisi_gate_clock *,
  116. int, struct hisi_clock_data *);
  117. void hi6220_clk_register_divider(const struct hi6220_divider_clock *,
  118. int, struct hisi_clock_data *);
  119. #define hisi_clk_unregister(type) \
  120. static inline \
  121. void hisi_clk_unregister_##type(const struct hisi_##type##_clock *clks, \
  122. int nums, struct hisi_clock_data *data) \
  123. { \
  124. struct clk **clocks = data->clk_data.clks; \
  125. int i; \
  126. for (i = 0; i < nums; i++) { \
  127. int id = clks[i].id; \
  128. if (clocks[id]) \
  129. clk_unregister_##type(clocks[id]); \
  130. } \
  131. }
  132. hisi_clk_unregister(fixed_rate)
  133. hisi_clk_unregister(fixed_factor)
  134. hisi_clk_unregister(mux)
  135. hisi_clk_unregister(divider)
  136. hisi_clk_unregister(gate)
  137. #endif /* __HISI_CLK_H */