clk-iproc.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (C) 2014 Broadcom Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation version 2.
  7. *
  8. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  9. * kind, whether express or implied; without even the implied warranty
  10. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _CLK_IPROC_H
  14. #define _CLK_IPROC_H
  15. #include <linux/kernel.h>
  16. #include <linux/list.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/slab.h>
  19. #include <linux/device.h>
  20. #include <linux/of.h>
  21. #include <linux/clk-provider.h>
  22. #define IPROC_CLK_NAME_LEN 25
  23. #define IPROC_CLK_INVALID_OFFSET 0xffffffff
  24. #define bit_mask(width) ((1 << (width)) - 1)
  25. /* clocks that should not be disabled at runtime */
  26. #define IPROC_CLK_AON BIT(0)
  27. /* PLL that requires gating through ASIU */
  28. #define IPROC_CLK_PLL_ASIU BIT(1)
  29. /* PLL that has fractional part of the NDIV */
  30. #define IPROC_CLK_PLL_HAS_NDIV_FRAC BIT(2)
  31. /*
  32. * Some of the iProc PLL/clocks may have an ASIC bug that requires read back
  33. * of the same register following the write to flush the write transaction into
  34. * the intended register
  35. */
  36. #define IPROC_CLK_NEEDS_READ_BACK BIT(3)
  37. /*
  38. * Some PLLs require the PLL SW override bit to be set before changes can be
  39. * applied to the PLL
  40. */
  41. #define IPROC_CLK_PLL_NEEDS_SW_CFG BIT(4)
  42. /*
  43. * Some PLLs use a different way to control clock power, via the PWRDWN bit in
  44. * the PLL control register
  45. */
  46. #define IPROC_CLK_EMBED_PWRCTRL BIT(5)
  47. /*
  48. * Some PLLs have separate registers for Status and Control. Identify this to
  49. * let the driver know if additional registers need to be used
  50. */
  51. #define IPROC_CLK_PLL_SPLIT_STAT_CTRL BIT(6)
  52. /*
  53. * Parameters for VCO frequency configuration
  54. *
  55. * VCO frequency =
  56. * ((ndiv_int + ndiv_frac / 2^20) * (ref freqeuncy / pdiv)
  57. */
  58. struct iproc_pll_vco_param {
  59. unsigned long rate;
  60. unsigned int ndiv_int;
  61. unsigned int ndiv_frac;
  62. unsigned int pdiv;
  63. };
  64. struct iproc_clk_reg_op {
  65. unsigned int offset;
  66. unsigned int shift;
  67. unsigned int width;
  68. };
  69. /*
  70. * Clock gating control at the top ASIU level
  71. */
  72. struct iproc_asiu_gate {
  73. unsigned int offset;
  74. unsigned int en_shift;
  75. };
  76. /*
  77. * Control of powering on/off of a PLL
  78. *
  79. * Before powering off a PLL, input isolation (ISO) needs to be enabled
  80. */
  81. struct iproc_pll_aon_pwr_ctrl {
  82. unsigned int offset;
  83. unsigned int pwr_width;
  84. unsigned int pwr_shift;
  85. unsigned int iso_shift;
  86. };
  87. /*
  88. * Control of the PLL reset
  89. */
  90. struct iproc_pll_reset_ctrl {
  91. unsigned int offset;
  92. unsigned int reset_shift;
  93. unsigned int p_reset_shift;
  94. };
  95. /*
  96. * Control of the Ki, Kp, and Ka parameters
  97. */
  98. struct iproc_pll_dig_filter_ctrl {
  99. unsigned int offset;
  100. unsigned int ki_shift;
  101. unsigned int ki_width;
  102. unsigned int kp_shift;
  103. unsigned int kp_width;
  104. unsigned int ka_shift;
  105. unsigned int ka_width;
  106. };
  107. /*
  108. * To enable SW control of the PLL
  109. */
  110. struct iproc_pll_sw_ctrl {
  111. unsigned int offset;
  112. unsigned int shift;
  113. };
  114. struct iproc_pll_vco_ctrl {
  115. unsigned int u_offset;
  116. unsigned int l_offset;
  117. };
  118. /*
  119. * Main PLL control parameters
  120. */
  121. struct iproc_pll_ctrl {
  122. unsigned long flags;
  123. struct iproc_pll_aon_pwr_ctrl aon;
  124. struct iproc_asiu_gate asiu;
  125. struct iproc_pll_reset_ctrl reset;
  126. struct iproc_pll_dig_filter_ctrl dig_filter;
  127. struct iproc_pll_sw_ctrl sw_ctrl;
  128. struct iproc_clk_reg_op ndiv_int;
  129. struct iproc_clk_reg_op ndiv_frac;
  130. struct iproc_clk_reg_op pdiv;
  131. struct iproc_pll_vco_ctrl vco_ctrl;
  132. struct iproc_clk_reg_op status;
  133. };
  134. /*
  135. * Controls enabling/disabling a PLL derived clock
  136. */
  137. struct iproc_clk_enable_ctrl {
  138. unsigned int offset;
  139. unsigned int enable_shift;
  140. unsigned int hold_shift;
  141. unsigned int bypass_shift;
  142. };
  143. /*
  144. * Main clock control parameters for clocks derived from the PLLs
  145. */
  146. struct iproc_clk_ctrl {
  147. unsigned int channel;
  148. unsigned long flags;
  149. struct iproc_clk_enable_ctrl enable;
  150. struct iproc_clk_reg_op mdiv;
  151. };
  152. /*
  153. * Divisor of the ASIU clocks
  154. */
  155. struct iproc_asiu_div {
  156. unsigned int offset;
  157. unsigned int en_shift;
  158. unsigned int high_shift;
  159. unsigned int high_width;
  160. unsigned int low_shift;
  161. unsigned int low_width;
  162. };
  163. void __init iproc_armpll_setup(struct device_node *node);
  164. void __init iproc_pll_clk_setup(struct device_node *node,
  165. const struct iproc_pll_ctrl *pll_ctrl,
  166. const struct iproc_pll_vco_param *vco,
  167. unsigned int num_vco_entries,
  168. const struct iproc_clk_ctrl *clk_ctrl,
  169. unsigned int num_clks);
  170. void __init iproc_asiu_setup(struct device_node *node,
  171. const struct iproc_asiu_div *div,
  172. const struct iproc_asiu_gate *gate,
  173. unsigned int num_clks);
  174. #endif /* _CLK_IPROC_H */