clk-iproc.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. * Some PLLs have an additional divide by 2 in master clock calculation;
  54. * MCLK = VCO_freq / (Mdiv * 2). Identify this to let the driver know
  55. * of modified calculations
  56. */
  57. #define IPROC_CLK_MCLK_DIV_BY_2 BIT(7)
  58. /*
  59. * Some PLLs provide a look up table for the leaf clock frequencies and
  60. * auto calculates VCO frequency parameters based on the provided leaf
  61. * clock frequencies. They have a user mode that allows the divider
  62. * controls to be determined by the user
  63. */
  64. #define IPROC_CLK_PLL_USER_MODE_ON BIT(8)
  65. /*
  66. * Some PLLs have an active low reset
  67. */
  68. #define IPROC_CLK_PLL_RESET_ACTIVE_LOW BIT(9)
  69. /*
  70. * Parameters for VCO frequency configuration
  71. *
  72. * VCO frequency =
  73. * ((ndiv_int + ndiv_frac / 2^20) * (ref freqeuncy / pdiv)
  74. */
  75. struct iproc_pll_vco_param {
  76. unsigned long rate;
  77. unsigned int ndiv_int;
  78. unsigned int ndiv_frac;
  79. unsigned int pdiv;
  80. };
  81. struct iproc_clk_reg_op {
  82. unsigned int offset;
  83. unsigned int shift;
  84. unsigned int width;
  85. };
  86. /*
  87. * Clock gating control at the top ASIU level
  88. */
  89. struct iproc_asiu_gate {
  90. unsigned int offset;
  91. unsigned int en_shift;
  92. };
  93. /*
  94. * Control of powering on/off of a PLL
  95. *
  96. * Before powering off a PLL, input isolation (ISO) needs to be enabled
  97. */
  98. struct iproc_pll_aon_pwr_ctrl {
  99. unsigned int offset;
  100. unsigned int pwr_width;
  101. unsigned int pwr_shift;
  102. unsigned int iso_shift;
  103. };
  104. /*
  105. * Control of the PLL reset
  106. */
  107. struct iproc_pll_reset_ctrl {
  108. unsigned int offset;
  109. unsigned int reset_shift;
  110. unsigned int p_reset_shift;
  111. };
  112. /*
  113. * Control of the Ki, Kp, and Ka parameters
  114. */
  115. struct iproc_pll_dig_filter_ctrl {
  116. unsigned int offset;
  117. unsigned int ki_shift;
  118. unsigned int ki_width;
  119. unsigned int kp_shift;
  120. unsigned int kp_width;
  121. unsigned int ka_shift;
  122. unsigned int ka_width;
  123. };
  124. /*
  125. * To enable SW control of the PLL
  126. */
  127. struct iproc_pll_sw_ctrl {
  128. unsigned int offset;
  129. unsigned int shift;
  130. };
  131. struct iproc_pll_vco_ctrl {
  132. unsigned int u_offset;
  133. unsigned int l_offset;
  134. };
  135. /*
  136. * Main PLL control parameters
  137. */
  138. struct iproc_pll_ctrl {
  139. unsigned long flags;
  140. struct iproc_pll_aon_pwr_ctrl aon;
  141. struct iproc_asiu_gate asiu;
  142. struct iproc_pll_reset_ctrl reset;
  143. struct iproc_pll_dig_filter_ctrl dig_filter;
  144. struct iproc_pll_sw_ctrl sw_ctrl;
  145. struct iproc_clk_reg_op ndiv_int;
  146. struct iproc_clk_reg_op ndiv_frac;
  147. struct iproc_clk_reg_op pdiv;
  148. struct iproc_pll_vco_ctrl vco_ctrl;
  149. struct iproc_clk_reg_op status;
  150. struct iproc_clk_reg_op macro_mode;
  151. };
  152. /*
  153. * Controls enabling/disabling a PLL derived clock
  154. */
  155. struct iproc_clk_enable_ctrl {
  156. unsigned int offset;
  157. unsigned int enable_shift;
  158. unsigned int hold_shift;
  159. unsigned int bypass_shift;
  160. };
  161. /*
  162. * Main clock control parameters for clocks derived from the PLLs
  163. */
  164. struct iproc_clk_ctrl {
  165. unsigned int channel;
  166. unsigned long flags;
  167. struct iproc_clk_enable_ctrl enable;
  168. struct iproc_clk_reg_op mdiv;
  169. };
  170. /*
  171. * Divisor of the ASIU clocks
  172. */
  173. struct iproc_asiu_div {
  174. unsigned int offset;
  175. unsigned int en_shift;
  176. unsigned int high_shift;
  177. unsigned int high_width;
  178. unsigned int low_shift;
  179. unsigned int low_width;
  180. };
  181. void iproc_armpll_setup(struct device_node *node);
  182. void iproc_pll_clk_setup(struct device_node *node,
  183. const struct iproc_pll_ctrl *pll_ctrl,
  184. const struct iproc_pll_vco_param *vco,
  185. unsigned int num_vco_entries,
  186. const struct iproc_clk_ctrl *clk_ctrl,
  187. unsigned int num_clks);
  188. void iproc_asiu_setup(struct device_node *node,
  189. const struct iproc_asiu_div *div,
  190. const struct iproc_asiu_gate *gate,
  191. unsigned int num_clks);
  192. #endif /* _CLK_IPROC_H */