clk.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (C) 2014 Google, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. */
  8. #ifndef __PISTACHIO_CLK_H
  9. #define __PISTACHIO_CLK_H
  10. #include <linux/clk-provider.h>
  11. struct pistachio_gate {
  12. unsigned int id;
  13. unsigned long reg;
  14. unsigned int shift;
  15. const char *name;
  16. const char *parent;
  17. };
  18. #define GATE(_id, _name, _pname, _reg, _shift) \
  19. { \
  20. .id = _id, \
  21. .reg = _reg, \
  22. .shift = _shift, \
  23. .name = _name, \
  24. .parent = _pname, \
  25. }
  26. struct pistachio_mux {
  27. unsigned int id;
  28. unsigned long reg;
  29. unsigned int shift;
  30. unsigned int num_parents;
  31. const char *name;
  32. const char **parents;
  33. };
  34. #define PNAME(x) static const char *x[] __initconst
  35. #define MUX(_id, _name, _pnames, _reg, _shift) \
  36. { \
  37. .id = _id, \
  38. .reg = _reg, \
  39. .shift = _shift, \
  40. .name = _name, \
  41. .parents = _pnames, \
  42. .num_parents = ARRAY_SIZE(_pnames) \
  43. }
  44. struct pistachio_div {
  45. unsigned int id;
  46. unsigned long reg;
  47. unsigned int width;
  48. unsigned int div_flags;
  49. const char *name;
  50. const char *parent;
  51. };
  52. #define DIV(_id, _name, _pname, _reg, _width) \
  53. { \
  54. .id = _id, \
  55. .reg = _reg, \
  56. .width = _width, \
  57. .div_flags = 0, \
  58. .name = _name, \
  59. .parent = _pname, \
  60. }
  61. #define DIV_F(_id, _name, _pname, _reg, _width, _div_flags) \
  62. { \
  63. .id = _id, \
  64. .reg = _reg, \
  65. .width = _width, \
  66. .div_flags = _div_flags, \
  67. .name = _name, \
  68. .parent = _pname, \
  69. }
  70. struct pistachio_fixed_factor {
  71. unsigned int id;
  72. unsigned int div;
  73. const char *name;
  74. const char *parent;
  75. };
  76. #define FIXED_FACTOR(_id, _name, _pname, _div) \
  77. { \
  78. .id = _id, \
  79. .div = _div, \
  80. .name = _name, \
  81. .parent = _pname, \
  82. }
  83. struct pistachio_pll_rate_table {
  84. unsigned long long fref;
  85. unsigned long long fout;
  86. unsigned long long refdiv;
  87. unsigned long long fbdiv;
  88. unsigned long long postdiv1;
  89. unsigned long long postdiv2;
  90. unsigned long long frac;
  91. };
  92. enum pistachio_pll_type {
  93. PLL_GF40LP_LAINT,
  94. PLL_GF40LP_FRAC,
  95. };
  96. struct pistachio_pll {
  97. unsigned int id;
  98. unsigned long reg_base;
  99. enum pistachio_pll_type type;
  100. struct pistachio_pll_rate_table *rates;
  101. unsigned int nr_rates;
  102. const char *name;
  103. const char *parent;
  104. };
  105. #define PLL(_id, _name, _pname, _type, _reg, _rates) \
  106. { \
  107. .id = _id, \
  108. .reg_base = _reg, \
  109. .type = _type, \
  110. .rates = _rates, \
  111. .nr_rates = ARRAY_SIZE(_rates), \
  112. .name = _name, \
  113. .parent = _pname, \
  114. }
  115. #define PLL_FIXED(_id, _name, _pname, _type, _reg) \
  116. { \
  117. .id = _id, \
  118. .reg_base = _reg, \
  119. .type = _type, \
  120. .rates = NULL, \
  121. .nr_rates = 0, \
  122. .name = _name, \
  123. .parent = _pname, \
  124. }
  125. struct pistachio_clk_provider {
  126. struct device_node *node;
  127. void __iomem *base;
  128. struct clk_onecell_data clk_data;
  129. };
  130. extern struct pistachio_clk_provider *
  131. pistachio_clk_alloc_provider(struct device_node *node, unsigned int num_clks);
  132. extern void pistachio_clk_register_provider(struct pistachio_clk_provider *p);
  133. extern void pistachio_clk_register_gate(struct pistachio_clk_provider *p,
  134. struct pistachio_gate *gate,
  135. unsigned int num);
  136. extern void pistachio_clk_register_mux(struct pistachio_clk_provider *p,
  137. struct pistachio_mux *mux,
  138. unsigned int num);
  139. extern void pistachio_clk_register_div(struct pistachio_clk_provider *p,
  140. struct pistachio_div *div,
  141. unsigned int num);
  142. extern void
  143. pistachio_clk_register_fixed_factor(struct pistachio_clk_provider *p,
  144. struct pistachio_fixed_factor *ff,
  145. unsigned int num);
  146. extern void pistachio_clk_register_pll(struct pistachio_clk_provider *p,
  147. struct pistachio_pll *pll,
  148. unsigned int num);
  149. extern void pistachio_clk_force_enable(struct pistachio_clk_provider *p,
  150. unsigned int *clk_ids, unsigned int num);
  151. #endif