clk-uniphier.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2016 Socionext Inc.
  4. * Author: Masahiro Yamada <[email protected]>
  5. */
  6. #ifndef __CLK_UNIPHIER_H__
  7. #define __CLK_UNIPHIER_H__
  8. struct clk_hw;
  9. struct device;
  10. struct regmap;
  11. #define UNIPHIER_CLK_CPUGEAR_MAX_PARENTS 16
  12. #define UNIPHIER_CLK_MUX_MAX_PARENTS 8
  13. enum uniphier_clk_type {
  14. UNIPHIER_CLK_TYPE_CPUGEAR,
  15. UNIPHIER_CLK_TYPE_FIXED_FACTOR,
  16. UNIPHIER_CLK_TYPE_FIXED_RATE,
  17. UNIPHIER_CLK_TYPE_GATE,
  18. UNIPHIER_CLK_TYPE_MUX,
  19. };
  20. struct uniphier_clk_cpugear_data {
  21. const char *parent_names[UNIPHIER_CLK_CPUGEAR_MAX_PARENTS];
  22. unsigned int num_parents;
  23. unsigned int regbase;
  24. unsigned int mask;
  25. };
  26. struct uniphier_clk_fixed_factor_data {
  27. const char *parent_name;
  28. unsigned int mult;
  29. unsigned int div;
  30. };
  31. struct uniphier_clk_fixed_rate_data {
  32. unsigned long fixed_rate;
  33. };
  34. struct uniphier_clk_gate_data {
  35. const char *parent_name;
  36. unsigned int reg;
  37. unsigned int bit;
  38. };
  39. struct uniphier_clk_mux_data {
  40. const char *parent_names[UNIPHIER_CLK_MUX_MAX_PARENTS];
  41. unsigned int num_parents;
  42. unsigned int reg;
  43. unsigned int masks[UNIPHIER_CLK_MUX_MAX_PARENTS];
  44. unsigned int vals[UNIPHIER_CLK_MUX_MAX_PARENTS];
  45. };
  46. struct uniphier_clk_data {
  47. const char *name;
  48. enum uniphier_clk_type type;
  49. int idx;
  50. union {
  51. struct uniphier_clk_cpugear_data cpugear;
  52. struct uniphier_clk_fixed_factor_data factor;
  53. struct uniphier_clk_fixed_rate_data rate;
  54. struct uniphier_clk_gate_data gate;
  55. struct uniphier_clk_mux_data mux;
  56. } data;
  57. };
  58. #define UNIPHIER_CLK_CPUGEAR(_name, _idx, _regbase, _mask, \
  59. _num_parents, ...) \
  60. { \
  61. .name = (_name), \
  62. .type = UNIPHIER_CLK_TYPE_CPUGEAR, \
  63. .idx = (_idx), \
  64. .data.cpugear = { \
  65. .parent_names = { __VA_ARGS__ }, \
  66. .num_parents = (_num_parents), \
  67. .regbase = (_regbase), \
  68. .mask = (_mask) \
  69. }, \
  70. }
  71. #define UNIPHIER_CLK_FACTOR(_name, _idx, _parent, _mult, _div) \
  72. { \
  73. .name = (_name), \
  74. .type = UNIPHIER_CLK_TYPE_FIXED_FACTOR, \
  75. .idx = (_idx), \
  76. .data.factor = { \
  77. .parent_name = (_parent), \
  78. .mult = (_mult), \
  79. .div = (_div), \
  80. }, \
  81. }
  82. #define UNIPHIER_CLK_GATE(_name, _idx, _parent, _reg, _bit) \
  83. { \
  84. .name = (_name), \
  85. .type = UNIPHIER_CLK_TYPE_GATE, \
  86. .idx = (_idx), \
  87. .data.gate = { \
  88. .parent_name = (_parent), \
  89. .reg = (_reg), \
  90. .bit = (_bit), \
  91. }, \
  92. }
  93. #define UNIPHIER_CLK_DIV(parent, div) \
  94. UNIPHIER_CLK_FACTOR(parent "/" #div, -1, parent, 1, div)
  95. #define UNIPHIER_CLK_DIV2(parent, div0, div1) \
  96. UNIPHIER_CLK_DIV(parent, div0), \
  97. UNIPHIER_CLK_DIV(parent, div1)
  98. #define UNIPHIER_CLK_DIV3(parent, div0, div1, div2) \
  99. UNIPHIER_CLK_DIV2(parent, div0, div1), \
  100. UNIPHIER_CLK_DIV(parent, div2)
  101. #define UNIPHIER_CLK_DIV4(parent, div0, div1, div2, div3) \
  102. UNIPHIER_CLK_DIV2(parent, div0, div1), \
  103. UNIPHIER_CLK_DIV2(parent, div2, div3)
  104. #define UNIPHIER_CLK_DIV5(parent, div0, div1, div2, div3, div4) \
  105. UNIPHIER_CLK_DIV4(parent, div0, div1, div2, div3), \
  106. UNIPHIER_CLK_DIV(parent, div4)
  107. struct clk_hw *uniphier_clk_register_cpugear(struct device *dev,
  108. struct regmap *regmap,
  109. const char *name,
  110. const struct uniphier_clk_cpugear_data *data);
  111. struct clk_hw *uniphier_clk_register_fixed_factor(struct device *dev,
  112. const char *name,
  113. const struct uniphier_clk_fixed_factor_data *data);
  114. struct clk_hw *uniphier_clk_register_fixed_rate(struct device *dev,
  115. const char *name,
  116. const struct uniphier_clk_fixed_rate_data *data);
  117. struct clk_hw *uniphier_clk_register_gate(struct device *dev,
  118. struct regmap *regmap,
  119. const char *name,
  120. const struct uniphier_clk_gate_data *data);
  121. struct clk_hw *uniphier_clk_register_mux(struct device *dev,
  122. struct regmap *regmap,
  123. const char *name,
  124. const struct uniphier_clk_mux_data *data);
  125. extern const struct uniphier_clk_data uniphier_ld4_sys_clk_data[];
  126. extern const struct uniphier_clk_data uniphier_pro4_sys_clk_data[];
  127. extern const struct uniphier_clk_data uniphier_sld8_sys_clk_data[];
  128. extern const struct uniphier_clk_data uniphier_pro5_sys_clk_data[];
  129. extern const struct uniphier_clk_data uniphier_pxs2_sys_clk_data[];
  130. extern const struct uniphier_clk_data uniphier_ld11_sys_clk_data[];
  131. extern const struct uniphier_clk_data uniphier_ld20_sys_clk_data[];
  132. extern const struct uniphier_clk_data uniphier_pxs3_sys_clk_data[];
  133. extern const struct uniphier_clk_data uniphier_nx1_sys_clk_data[];
  134. extern const struct uniphier_clk_data uniphier_ld4_mio_clk_data[];
  135. extern const struct uniphier_clk_data uniphier_pro5_sd_clk_data[];
  136. extern const struct uniphier_clk_data uniphier_ld4_peri_clk_data[];
  137. extern const struct uniphier_clk_data uniphier_pro4_peri_clk_data[];
  138. extern const struct uniphier_clk_data uniphier_pro4_sg_clk_data[];
  139. #endif /* __CLK_UNIPHIER_H__ */