clk.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Hisilicon Hi3620 clock gate driver
  4. *
  5. * Copyright (c) 2012-2013 Hisilicon Limited.
  6. * Copyright (c) 2012-2013 Linaro Limited.
  7. *
  8. * Author: Haojian Zhuang <[email protected]>
  9. * Xin Li <[email protected]>
  10. */
  11. #ifndef __HISI_CLK_H
  12. #define __HISI_CLK_H
  13. #include <linux/clk-provider.h>
  14. #include <linux/io.h>
  15. #include <linux/spinlock.h>
  16. struct platform_device;
  17. struct hisi_clock_data {
  18. struct clk_onecell_data clk_data;
  19. void __iomem *base;
  20. };
  21. struct hisi_fixed_rate_clock {
  22. unsigned int id;
  23. char *name;
  24. const char *parent_name;
  25. unsigned long flags;
  26. unsigned long fixed_rate;
  27. };
  28. struct hisi_fixed_factor_clock {
  29. unsigned int id;
  30. char *name;
  31. const char *parent_name;
  32. unsigned long mult;
  33. unsigned long div;
  34. unsigned long flags;
  35. };
  36. struct hisi_mux_clock {
  37. unsigned int id;
  38. const char *name;
  39. const char *const *parent_names;
  40. u8 num_parents;
  41. unsigned long flags;
  42. unsigned long offset;
  43. u8 shift;
  44. u8 width;
  45. u8 mux_flags;
  46. const u32 *table;
  47. const char *alias;
  48. };
  49. struct hisi_phase_clock {
  50. unsigned int id;
  51. const char *name;
  52. const char *parent_names;
  53. unsigned long flags;
  54. unsigned long offset;
  55. u8 shift;
  56. u8 width;
  57. u32 *phase_degrees;
  58. u32 *phase_regvals;
  59. u8 phase_num;
  60. };
  61. struct hisi_divider_clock {
  62. unsigned int id;
  63. const char *name;
  64. const char *parent_name;
  65. unsigned long flags;
  66. unsigned long offset;
  67. u8 shift;
  68. u8 width;
  69. u8 div_flags;
  70. struct clk_div_table *table;
  71. const char *alias;
  72. };
  73. struct hi6220_divider_clock {
  74. unsigned int id;
  75. const char *name;
  76. const char *parent_name;
  77. unsigned long flags;
  78. unsigned long offset;
  79. u8 shift;
  80. u8 width;
  81. u32 mask_bit;
  82. const char *alias;
  83. };
  84. struct hisi_gate_clock {
  85. unsigned int id;
  86. const char *name;
  87. const char *parent_name;
  88. unsigned long flags;
  89. unsigned long offset;
  90. u8 bit_idx;
  91. u8 gate_flags;
  92. const char *alias;
  93. };
  94. struct clk *hisi_register_clkgate_sep(struct device *, const char *,
  95. const char *, unsigned long,
  96. void __iomem *, u8,
  97. u8, spinlock_t *);
  98. struct clk *hi6220_register_clkdiv(struct device *dev, const char *name,
  99. const char *parent_name, unsigned long flags, void __iomem *reg,
  100. u8 shift, u8 width, u32 mask_bit, spinlock_t *lock);
  101. struct hisi_clock_data *hisi_clk_alloc(struct platform_device *, int);
  102. struct hisi_clock_data *hisi_clk_init(struct device_node *, int);
  103. int hisi_clk_register_fixed_rate(const struct hisi_fixed_rate_clock *,
  104. int, struct hisi_clock_data *);
  105. int hisi_clk_register_fixed_factor(const struct hisi_fixed_factor_clock *,
  106. int, struct hisi_clock_data *);
  107. int hisi_clk_register_mux(const struct hisi_mux_clock *, int,
  108. struct hisi_clock_data *);
  109. struct clk *clk_register_hisi_phase(struct device *dev,
  110. const struct hisi_phase_clock *clks,
  111. void __iomem *base, spinlock_t *lock);
  112. int hisi_clk_register_phase(struct device *dev,
  113. const struct hisi_phase_clock *clks,
  114. int nums, struct hisi_clock_data *data);
  115. int hisi_clk_register_divider(const struct hisi_divider_clock *,
  116. int, struct hisi_clock_data *);
  117. int hisi_clk_register_gate(const struct hisi_gate_clock *,
  118. int, struct hisi_clock_data *);
  119. void hisi_clk_register_gate_sep(const struct hisi_gate_clock *,
  120. int, struct hisi_clock_data *);
  121. void hi6220_clk_register_divider(const struct hi6220_divider_clock *,
  122. int, struct hisi_clock_data *);
  123. #define hisi_clk_unregister(type) \
  124. static inline \
  125. void hisi_clk_unregister_##type(const struct hisi_##type##_clock *clks, \
  126. int nums, struct hisi_clock_data *data) \
  127. { \
  128. struct clk **clocks = data->clk_data.clks; \
  129. int i; \
  130. for (i = 0; i < nums; i++) { \
  131. int id = clks[i].id; \
  132. if (clocks[id]) \
  133. clk_unregister_##type(clocks[id]); \
  134. } \
  135. }
  136. hisi_clk_unregister(fixed_rate)
  137. hisi_clk_unregister(fixed_factor)
  138. hisi_clk_unregister(mux)
  139. hisi_clk_unregister(divider)
  140. hisi_clk_unregister(gate)
  141. #endif /* __HISI_CLK_H */