ccs-pll.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * drivers/media/i2c/ccs-pll.h
  4. *
  5. * Generic MIPI CCS/SMIA/SMIA++ PLL calculator
  6. *
  7. * Copyright (C) 2020 Intel Corporation
  8. * Copyright (C) 2012 Nokia Corporation
  9. * Contact: Sakari Ailus <[email protected]>
  10. */
  11. #ifndef CCS_PLL_H
  12. #define CCS_PLL_H
  13. #include <linux/bits.h>
  14. /* CSI-2 or CCP-2 */
  15. #define CCS_PLL_BUS_TYPE_CSI2_DPHY 0x00
  16. #define CCS_PLL_BUS_TYPE_CSI2_CPHY 0x01
  17. /* Old SMIA and implementation specific flags */
  18. /* op pix clock is for all lanes in total normally */
  19. #define CCS_PLL_FLAG_OP_PIX_CLOCK_PER_LANE BIT(0)
  20. #define CCS_PLL_FLAG_NO_OP_CLOCKS BIT(1)
  21. /* CCS PLL flags */
  22. #define CCS_PLL_FLAG_LANE_SPEED_MODEL BIT(2)
  23. #define CCS_PLL_FLAG_LINK_DECOUPLED BIT(3)
  24. #define CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER BIT(4)
  25. #define CCS_PLL_FLAG_FLEXIBLE_OP_PIX_CLK_DIV BIT(5)
  26. #define CCS_PLL_FLAG_FIFO_DERATING BIT(6)
  27. #define CCS_PLL_FLAG_FIFO_OVERRATING BIT(7)
  28. #define CCS_PLL_FLAG_DUAL_PLL BIT(8)
  29. #define CCS_PLL_FLAG_OP_SYS_DDR BIT(9)
  30. #define CCS_PLL_FLAG_OP_PIX_DDR BIT(10)
  31. /**
  32. * struct ccs_pll_branch_fr - CCS PLL configuration (front)
  33. *
  34. * A single branch front-end of the CCS PLL tree.
  35. *
  36. * @pre_pll_clk_div: Pre-PLL clock divisor
  37. * @pll_multiplier: PLL multiplier
  38. * @pll_ip_clk_freq_hz: PLL input clock frequency
  39. * @pll_op_clk_freq_hz: PLL output clock frequency
  40. */
  41. struct ccs_pll_branch_fr {
  42. u16 pre_pll_clk_div;
  43. u16 pll_multiplier;
  44. u32 pll_ip_clk_freq_hz;
  45. u32 pll_op_clk_freq_hz;
  46. };
  47. /**
  48. * struct ccs_pll_branch_bk - CCS PLL configuration (back)
  49. *
  50. * A single branch back-end of the CCS PLL tree.
  51. *
  52. * @sys_clk_div: System clock divider
  53. * @pix_clk_div: Pixel clock divider
  54. * @sys_clk_freq_hz: System clock frequency
  55. * @pix_clk_freq_hz: Pixel clock frequency
  56. */
  57. struct ccs_pll_branch_bk {
  58. u16 sys_clk_div;
  59. u16 pix_clk_div;
  60. u32 sys_clk_freq_hz;
  61. u32 pix_clk_freq_hz;
  62. };
  63. /**
  64. * struct ccs_pll - Full CCS PLL configuration
  65. *
  66. * All information required to calculate CCS PLL configuration.
  67. *
  68. * @bus_type: Type of the data bus, CCS_PLL_BUS_TYPE_* (input)
  69. * @op_lanes: Number of operational lanes (input)
  70. * @vt_lanes: Number of video timing lanes (input)
  71. * @csi2: CSI-2 related parameters
  72. * @csi2.lanes: The number of the CSI-2 data lanes (input)
  73. * @binning_vertical: Vertical binning factor (input)
  74. * @binning_horizontal: Horizontal binning factor (input)
  75. * @scale_m: Downscaling factor, M component, [16, max] (input)
  76. * @scale_n: Downscaling factor, N component, typically 16 (input)
  77. * @bits_per_pixel: Bits per pixel on the output data bus (input)
  78. * @op_bits_per_lane: Number of bits per OP lane (input)
  79. * @flags: CCS_PLL_FLAG_* (input)
  80. * @link_freq: Chosen link frequency (input)
  81. * @ext_clk_freq_hz: External clock frequency, i.e. the sensor's input clock
  82. * (input)
  83. * @vt_fr: Video timing front-end configuration (output)
  84. * @vt_bk: Video timing back-end configuration (output)
  85. * @op_fr: Operational timing front-end configuration (output)
  86. * @op_bk: Operational timing back-end configuration (output)
  87. * @pixel_rate_csi: Pixel rate on the output data bus (output)
  88. * @pixel_rate_pixel_array: Nominal pixel rate in the sensor's pixel array
  89. * (output)
  90. */
  91. struct ccs_pll {
  92. /* input values */
  93. u8 bus_type;
  94. u8 op_lanes;
  95. u8 vt_lanes;
  96. struct {
  97. u8 lanes;
  98. } csi2;
  99. u8 binning_horizontal;
  100. u8 binning_vertical;
  101. u8 scale_m;
  102. u8 scale_n;
  103. u8 bits_per_pixel;
  104. u8 op_bits_per_lane;
  105. u16 flags;
  106. u32 link_freq;
  107. u32 ext_clk_freq_hz;
  108. /* output values */
  109. struct ccs_pll_branch_fr vt_fr;
  110. struct ccs_pll_branch_bk vt_bk;
  111. struct ccs_pll_branch_fr op_fr;
  112. struct ccs_pll_branch_bk op_bk;
  113. u32 pixel_rate_csi;
  114. u32 pixel_rate_pixel_array;
  115. };
  116. /**
  117. * struct ccs_pll_branch_limits_fr - CCS PLL front-end limits
  118. *
  119. * @min_pre_pll_clk_div: Minimum pre-PLL clock divider
  120. * @max_pre_pll_clk_div: Maximum pre-PLL clock divider
  121. * @min_pll_ip_clk_freq_hz: Minimum PLL input clock frequency
  122. * @max_pll_ip_clk_freq_hz: Maximum PLL input clock frequency
  123. * @min_pll_multiplier: Minimum PLL multiplier
  124. * @max_pll_multiplier: Maximum PLL multiplier
  125. * @min_pll_op_clk_freq_hz: Minimum PLL output clock frequency
  126. * @max_pll_op_clk_freq_hz: Maximum PLL output clock frequency
  127. */
  128. struct ccs_pll_branch_limits_fr {
  129. u16 min_pre_pll_clk_div;
  130. u16 max_pre_pll_clk_div;
  131. u32 min_pll_ip_clk_freq_hz;
  132. u32 max_pll_ip_clk_freq_hz;
  133. u16 min_pll_multiplier;
  134. u16 max_pll_multiplier;
  135. u32 min_pll_op_clk_freq_hz;
  136. u32 max_pll_op_clk_freq_hz;
  137. };
  138. /**
  139. * struct ccs_pll_branch_limits_bk - CCS PLL back-end limits
  140. *
  141. * @min_sys_clk_div: Minimum system clock divider
  142. * @max_sys_clk_div: Maximum system clock divider
  143. * @min_sys_clk_freq_hz: Minimum system clock frequency
  144. * @max_sys_clk_freq_hz: Maximum system clock frequency
  145. * @min_pix_clk_div: Minimum pixel clock divider
  146. * @max_pix_clk_div: Maximum pixel clock divider
  147. * @min_pix_clk_freq_hz: Minimum pixel clock frequency
  148. * @max_pix_clk_freq_hz: Maximum pixel clock frequency
  149. */
  150. struct ccs_pll_branch_limits_bk {
  151. u16 min_sys_clk_div;
  152. u16 max_sys_clk_div;
  153. u32 min_sys_clk_freq_hz;
  154. u32 max_sys_clk_freq_hz;
  155. u16 min_pix_clk_div;
  156. u16 max_pix_clk_div;
  157. u32 min_pix_clk_freq_hz;
  158. u32 max_pix_clk_freq_hz;
  159. };
  160. /**
  161. * struct ccs_pll_limits - CCS PLL limits
  162. *
  163. * @min_ext_clk_freq_hz: Minimum external clock frequency
  164. * @max_ext_clk_freq_hz: Maximum external clock frequency
  165. * @vt_fr: Video timing front-end limits
  166. * @vt_bk: Video timing back-end limits
  167. * @op_fr: Operational timing front-end limits
  168. * @op_bk: Operational timing back-end limits
  169. * @min_line_length_pck_bin: Minimum line length in pixels, with binning
  170. * @min_line_length_pck: Minimum line length in pixels without binning
  171. */
  172. struct ccs_pll_limits {
  173. /* Strict PLL limits */
  174. u32 min_ext_clk_freq_hz;
  175. u32 max_ext_clk_freq_hz;
  176. struct ccs_pll_branch_limits_fr vt_fr;
  177. struct ccs_pll_branch_limits_bk vt_bk;
  178. struct ccs_pll_branch_limits_fr op_fr;
  179. struct ccs_pll_branch_limits_bk op_bk;
  180. /* Other relevant limits */
  181. u32 min_line_length_pck_bin;
  182. u32 min_line_length_pck;
  183. };
  184. struct device;
  185. /**
  186. * ccs_pll_calculate - Calculate CCS PLL configuration based on input parameters
  187. *
  188. * @dev: Device pointer, used for printing messages
  189. * @limits: Limits specific to the sensor
  190. * @pll: Given PLL configuration
  191. *
  192. * Calculate the CCS PLL configuration based on the limits as well as given
  193. * device specific, system specific or user configured input data.
  194. */
  195. int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits,
  196. struct ccs_pll *pll);
  197. #endif /* CCS_PLL_H */