clk-iproc.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (C) 2014 Broadcom Corporation */
  3. #ifndef _CLK_IPROC_H
  4. #define _CLK_IPROC_H
  5. #include <linux/kernel.h>
  6. #include <linux/list.h>
  7. #include <linux/spinlock.h>
  8. #include <linux/slab.h>
  9. #include <linux/device.h>
  10. #include <linux/of.h>
  11. #include <linux/clk-provider.h>
  12. #define IPROC_CLK_NAME_LEN 25
  13. #define IPROC_CLK_INVALID_OFFSET 0xffffffff
  14. #define bit_mask(width) ((1 << (width)) - 1)
  15. /* clocks that should not be disabled at runtime */
  16. #define IPROC_CLK_AON BIT(0)
  17. /* PLL that requires gating through ASIU */
  18. #define IPROC_CLK_PLL_ASIU BIT(1)
  19. /* PLL that has fractional part of the NDIV */
  20. #define IPROC_CLK_PLL_HAS_NDIV_FRAC BIT(2)
  21. /*
  22. * Some of the iProc PLL/clocks may have an ASIC bug that requires read back
  23. * of the same register following the write to flush the write transaction into
  24. * the intended register
  25. */
  26. #define IPROC_CLK_NEEDS_READ_BACK BIT(3)
  27. /*
  28. * Some PLLs require the PLL SW override bit to be set before changes can be
  29. * applied to the PLL
  30. */
  31. #define IPROC_CLK_PLL_NEEDS_SW_CFG BIT(4)
  32. /*
  33. * Some PLLs use a different way to control clock power, via the PWRDWN bit in
  34. * the PLL control register
  35. */
  36. #define IPROC_CLK_EMBED_PWRCTRL BIT(5)
  37. /*
  38. * Some PLLs have separate registers for Status and Control. Identify this to
  39. * let the driver know if additional registers need to be used
  40. */
  41. #define IPROC_CLK_PLL_SPLIT_STAT_CTRL BIT(6)
  42. /*
  43. * Some PLLs have an additional divide by 2 in master clock calculation;
  44. * MCLK = VCO_freq / (Mdiv * 2). Identify this to let the driver know
  45. * of modified calculations
  46. */
  47. #define IPROC_CLK_MCLK_DIV_BY_2 BIT(7)
  48. /*
  49. * Some PLLs provide a look up table for the leaf clock frequencies and
  50. * auto calculates VCO frequency parameters based on the provided leaf
  51. * clock frequencies. They have a user mode that allows the divider
  52. * controls to be determined by the user
  53. */
  54. #define IPROC_CLK_PLL_USER_MODE_ON BIT(8)
  55. /*
  56. * Some PLLs have an active low reset
  57. */
  58. #define IPROC_CLK_PLL_RESET_ACTIVE_LOW BIT(9)
  59. /*
  60. * Calculate the PLL parameters are runtime, instead of using table
  61. */
  62. #define IPROC_CLK_PLL_CALC_PARAM BIT(10)
  63. /*
  64. * Parameters for VCO frequency configuration
  65. *
  66. * VCO frequency =
  67. * ((ndiv_int + ndiv_frac / 2^20) * (ref frequency / pdiv)
  68. */
  69. struct iproc_pll_vco_param {
  70. unsigned long rate;
  71. unsigned int ndiv_int;
  72. unsigned int ndiv_frac;
  73. unsigned int pdiv;
  74. };
  75. struct iproc_clk_reg_op {
  76. unsigned int offset;
  77. unsigned int shift;
  78. unsigned int width;
  79. };
  80. /*
  81. * Clock gating control at the top ASIU level
  82. */
  83. struct iproc_asiu_gate {
  84. unsigned int offset;
  85. unsigned int en_shift;
  86. };
  87. /*
  88. * Control of powering on/off of a PLL
  89. *
  90. * Before powering off a PLL, input isolation (ISO) needs to be enabled
  91. */
  92. struct iproc_pll_aon_pwr_ctrl {
  93. unsigned int offset;
  94. unsigned int pwr_width;
  95. unsigned int pwr_shift;
  96. unsigned int iso_shift;
  97. };
  98. /*
  99. * Control of the PLL reset
  100. */
  101. struct iproc_pll_reset_ctrl {
  102. unsigned int offset;
  103. unsigned int reset_shift;
  104. unsigned int p_reset_shift;
  105. };
  106. /*
  107. * Control of the Ki, Kp, and Ka parameters
  108. */
  109. struct iproc_pll_dig_filter_ctrl {
  110. unsigned int offset;
  111. unsigned int ki_shift;
  112. unsigned int ki_width;
  113. unsigned int kp_shift;
  114. unsigned int kp_width;
  115. unsigned int ka_shift;
  116. unsigned int ka_width;
  117. };
  118. /*
  119. * To enable SW control of the PLL
  120. */
  121. struct iproc_pll_sw_ctrl {
  122. unsigned int offset;
  123. unsigned int shift;
  124. };
  125. struct iproc_pll_vco_ctrl {
  126. unsigned int u_offset;
  127. unsigned int l_offset;
  128. };
  129. /*
  130. * Main PLL control parameters
  131. */
  132. struct iproc_pll_ctrl {
  133. unsigned long flags;
  134. struct iproc_pll_aon_pwr_ctrl aon;
  135. struct iproc_asiu_gate asiu;
  136. struct iproc_pll_reset_ctrl reset;
  137. struct iproc_pll_dig_filter_ctrl dig_filter;
  138. struct iproc_pll_sw_ctrl sw_ctrl;
  139. struct iproc_clk_reg_op ndiv_int;
  140. struct iproc_clk_reg_op ndiv_frac;
  141. struct iproc_clk_reg_op pdiv;
  142. struct iproc_pll_vco_ctrl vco_ctrl;
  143. struct iproc_clk_reg_op status;
  144. struct iproc_clk_reg_op macro_mode;
  145. };
  146. /*
  147. * Controls enabling/disabling a PLL derived clock
  148. */
  149. struct iproc_clk_enable_ctrl {
  150. unsigned int offset;
  151. unsigned int enable_shift;
  152. unsigned int hold_shift;
  153. unsigned int bypass_shift;
  154. };
  155. /*
  156. * Main clock control parameters for clocks derived from the PLLs
  157. */
  158. struct iproc_clk_ctrl {
  159. unsigned int channel;
  160. unsigned long flags;
  161. struct iproc_clk_enable_ctrl enable;
  162. struct iproc_clk_reg_op mdiv;
  163. };
  164. /*
  165. * Divisor of the ASIU clocks
  166. */
  167. struct iproc_asiu_div {
  168. unsigned int offset;
  169. unsigned int en_shift;
  170. unsigned int high_shift;
  171. unsigned int high_width;
  172. unsigned int low_shift;
  173. unsigned int low_width;
  174. };
  175. void iproc_armpll_setup(struct device_node *node);
  176. void iproc_pll_clk_setup(struct device_node *node,
  177. const struct iproc_pll_ctrl *pll_ctrl,
  178. const struct iproc_pll_vco_param *vco,
  179. unsigned int num_vco_entries,
  180. const struct iproc_clk_ctrl *clk_ctrl,
  181. unsigned int num_clks);
  182. void iproc_asiu_setup(struct device_node *node,
  183. const struct iproc_asiu_div *div,
  184. const struct iproc_asiu_gate *gate,
  185. unsigned int num_clks);
  186. #endif /* _CLK_IPROC_H */