clk-uniphier.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (C) 2016 Socionext Inc.
  3. * Author: Masahiro Yamada <yamada.masahiro@socionext.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 as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #ifndef __CLK_UNIPHIER_H__
  16. #define __CLK_UNIPHIER_H__
  17. struct clk_hw;
  18. struct device;
  19. struct regmap;
  20. #define UNIPHIER_CLK_CPUGEAR_MAX_PARENTS 16
  21. #define UNIPHIER_CLK_MUX_MAX_PARENTS 8
  22. enum uniphier_clk_type {
  23. UNIPHIER_CLK_TYPE_CPUGEAR,
  24. UNIPHIER_CLK_TYPE_FIXED_FACTOR,
  25. UNIPHIER_CLK_TYPE_FIXED_RATE,
  26. UNIPHIER_CLK_TYPE_GATE,
  27. UNIPHIER_CLK_TYPE_MUX,
  28. };
  29. struct uniphier_clk_cpugear_data {
  30. const char *parent_names[UNIPHIER_CLK_CPUGEAR_MAX_PARENTS];
  31. unsigned int num_parents;
  32. unsigned int regbase;
  33. unsigned int mask;
  34. };
  35. struct uniphier_clk_fixed_factor_data {
  36. const char *parent_name;
  37. unsigned int mult;
  38. unsigned int div;
  39. };
  40. struct uniphier_clk_fixed_rate_data {
  41. unsigned long fixed_rate;
  42. };
  43. struct uniphier_clk_gate_data {
  44. const char *parent_name;
  45. unsigned int reg;
  46. unsigned int bit;
  47. };
  48. struct uniphier_clk_mux_data {
  49. const char *parent_names[UNIPHIER_CLK_MUX_MAX_PARENTS];
  50. unsigned int num_parents;
  51. unsigned int reg;
  52. unsigned int masks[UNIPHIER_CLK_MUX_MAX_PARENTS];
  53. unsigned int vals[UNIPHIER_CLK_MUX_MAX_PARENTS];
  54. };
  55. struct uniphier_clk_data {
  56. const char *name;
  57. enum uniphier_clk_type type;
  58. int idx;
  59. union {
  60. struct uniphier_clk_cpugear_data cpugear;
  61. struct uniphier_clk_fixed_factor_data factor;
  62. struct uniphier_clk_fixed_rate_data rate;
  63. struct uniphier_clk_gate_data gate;
  64. struct uniphier_clk_mux_data mux;
  65. } data;
  66. };
  67. #define UNIPHIER_CLK_CPUGEAR(_name, _idx, _regbase, _mask, \
  68. _num_parents, ...) \
  69. { \
  70. .name = (_name), \
  71. .type = UNIPHIER_CLK_TYPE_CPUGEAR, \
  72. .idx = (_idx), \
  73. .data.cpugear = { \
  74. .parent_names = { __VA_ARGS__ }, \
  75. .num_parents = (_num_parents), \
  76. .regbase = (_regbase), \
  77. .mask = (_mask) \
  78. }, \
  79. }
  80. #define UNIPHIER_CLK_FACTOR(_name, _idx, _parent, _mult, _div) \
  81. { \
  82. .name = (_name), \
  83. .type = UNIPHIER_CLK_TYPE_FIXED_FACTOR, \
  84. .idx = (_idx), \
  85. .data.factor = { \
  86. .parent_name = (_parent), \
  87. .mult = (_mult), \
  88. .div = (_div), \
  89. }, \
  90. }
  91. #define UNIPHIER_CLK_GATE(_name, _idx, _parent, _reg, _bit) \
  92. { \
  93. .name = (_name), \
  94. .type = UNIPHIER_CLK_TYPE_GATE, \
  95. .idx = (_idx), \
  96. .data.gate = { \
  97. .parent_name = (_parent), \
  98. .reg = (_reg), \
  99. .bit = (_bit), \
  100. }, \
  101. }
  102. #define UNIPHIER_CLK_DIV(parent, div) \
  103. UNIPHIER_CLK_FACTOR(parent "/" #div, -1, parent, 1, div)
  104. #define UNIPHIER_CLK_DIV2(parent, div0, div1) \
  105. UNIPHIER_CLK_DIV(parent, div0), \
  106. UNIPHIER_CLK_DIV(parent, div1)
  107. #define UNIPHIER_CLK_DIV3(parent, div0, div1, div2) \
  108. UNIPHIER_CLK_DIV2(parent, div0, div1), \
  109. UNIPHIER_CLK_DIV(parent, div2)
  110. #define UNIPHIER_CLK_DIV4(parent, div0, div1, div2, div3) \
  111. UNIPHIER_CLK_DIV2(parent, div0, div1), \
  112. UNIPHIER_CLK_DIV2(parent, div2, div3)
  113. struct clk_hw *uniphier_clk_register_cpugear(struct device *dev,
  114. struct regmap *regmap,
  115. const char *name,
  116. const struct uniphier_clk_cpugear_data *data);
  117. struct clk_hw *uniphier_clk_register_fixed_factor(struct device *dev,
  118. const char *name,
  119. const struct uniphier_clk_fixed_factor_data *data);
  120. struct clk_hw *uniphier_clk_register_fixed_rate(struct device *dev,
  121. const char *name,
  122. const struct uniphier_clk_fixed_rate_data *data);
  123. struct clk_hw *uniphier_clk_register_gate(struct device *dev,
  124. struct regmap *regmap,
  125. const char *name,
  126. const struct uniphier_clk_gate_data *data);
  127. struct clk_hw *uniphier_clk_register_mux(struct device *dev,
  128. struct regmap *regmap,
  129. const char *name,
  130. const struct uniphier_clk_mux_data *data);
  131. extern const struct uniphier_clk_data uniphier_ld4_sys_clk_data[];
  132. extern const struct uniphier_clk_data uniphier_pro4_sys_clk_data[];
  133. extern const struct uniphier_clk_data uniphier_sld8_sys_clk_data[];
  134. extern const struct uniphier_clk_data uniphier_pro5_sys_clk_data[];
  135. extern const struct uniphier_clk_data uniphier_pxs2_sys_clk_data[];
  136. extern const struct uniphier_clk_data uniphier_ld11_sys_clk_data[];
  137. extern const struct uniphier_clk_data uniphier_ld20_sys_clk_data[];
  138. extern const struct uniphier_clk_data uniphier_pxs3_sys_clk_data[];
  139. extern const struct uniphier_clk_data uniphier_ld4_mio_clk_data[];
  140. extern const struct uniphier_clk_data uniphier_pro5_sd_clk_data[];
  141. extern const struct uniphier_clk_data uniphier_ld4_peri_clk_data[];
  142. extern const struct uniphier_clk_data uniphier_pro4_peri_clk_data[];
  143. #endif /* __CLK_UNIPHIER_H__ */