v4l2-dv-timings.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * v4l2-dv-timings - Internal header with dv-timings helper functions
  4. *
  5. * Copyright 2013 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  6. */
  7. #ifndef __V4L2_DV_TIMINGS_H
  8. #define __V4L2_DV_TIMINGS_H
  9. #include <linux/videodev2.h>
  10. /**
  11. * v4l2_calc_timeperframe - helper function to calculate timeperframe based
  12. * v4l2_dv_timings fields.
  13. * @t: Timings for the video mode.
  14. *
  15. * Calculates the expected timeperframe using the pixel clock value and
  16. * horizontal/vertical measures. This means that v4l2_dv_timings structure
  17. * must be correctly and fully filled.
  18. */
  19. struct v4l2_fract v4l2_calc_timeperframe(const struct v4l2_dv_timings *t);
  20. /*
  21. * v4l2_dv_timings_presets: list of all dv_timings presets.
  22. */
  23. extern const struct v4l2_dv_timings v4l2_dv_timings_presets[];
  24. /**
  25. * typedef v4l2_check_dv_timings_fnc - timings check callback
  26. *
  27. * @t: the v4l2_dv_timings struct.
  28. * @handle: a handle from the driver.
  29. *
  30. * Returns true if the given timings are valid.
  31. */
  32. typedef bool v4l2_check_dv_timings_fnc(const struct v4l2_dv_timings *t, void *handle);
  33. /**
  34. * v4l2_valid_dv_timings() - are these timings valid?
  35. *
  36. * @t: the v4l2_dv_timings struct.
  37. * @cap: the v4l2_dv_timings_cap capabilities.
  38. * @fnc: callback to check if this timing is OK. May be NULL.
  39. * @fnc_handle: a handle that is passed on to @fnc.
  40. *
  41. * Returns true if the given dv_timings struct is supported by the
  42. * hardware capabilities and the callback function (if non-NULL), returns
  43. * false otherwise.
  44. */
  45. bool v4l2_valid_dv_timings(const struct v4l2_dv_timings *t,
  46. const struct v4l2_dv_timings_cap *cap,
  47. v4l2_check_dv_timings_fnc fnc,
  48. void *fnc_handle);
  49. /**
  50. * v4l2_enum_dv_timings_cap() - Helper function to enumerate possible DV
  51. * timings based on capabilities
  52. *
  53. * @t: the v4l2_enum_dv_timings struct.
  54. * @cap: the v4l2_dv_timings_cap capabilities.
  55. * @fnc: callback to check if this timing is OK. May be NULL.
  56. * @fnc_handle: a handle that is passed on to @fnc.
  57. *
  58. * This enumerates dv_timings using the full list of possible CEA-861 and DMT
  59. * timings, filtering out any timings that are not supported based on the
  60. * hardware capabilities and the callback function (if non-NULL).
  61. *
  62. * If a valid timing for the given index is found, it will fill in @t and
  63. * return 0, otherwise it returns -EINVAL.
  64. */
  65. int v4l2_enum_dv_timings_cap(struct v4l2_enum_dv_timings *t,
  66. const struct v4l2_dv_timings_cap *cap,
  67. v4l2_check_dv_timings_fnc fnc,
  68. void *fnc_handle);
  69. /**
  70. * v4l2_find_dv_timings_cap() - Find the closest timings struct
  71. *
  72. * @t: the v4l2_enum_dv_timings struct.
  73. * @cap: the v4l2_dv_timings_cap capabilities.
  74. * @pclock_delta: maximum delta between t->pixelclock and the timing struct
  75. * under consideration.
  76. * @fnc: callback to check if a given timings struct is OK. May be NULL.
  77. * @fnc_handle: a handle that is passed on to @fnc.
  78. *
  79. * This function tries to map the given timings to an entry in the
  80. * full list of possible CEA-861 and DMT timings, filtering out any timings
  81. * that are not supported based on the hardware capabilities and the callback
  82. * function (if non-NULL).
  83. *
  84. * On success it will fill in @t with the found timings and it returns true.
  85. * On failure it will return false.
  86. */
  87. bool v4l2_find_dv_timings_cap(struct v4l2_dv_timings *t,
  88. const struct v4l2_dv_timings_cap *cap,
  89. unsigned pclock_delta,
  90. v4l2_check_dv_timings_fnc fnc,
  91. void *fnc_handle);
  92. /**
  93. * v4l2_find_dv_timings_cea861_vic() - find timings based on CEA-861 VIC
  94. * @t: the timings data.
  95. * @vic: CEA-861 VIC code
  96. *
  97. * On success it will fill in @t with the found timings and it returns true.
  98. * On failure it will return false.
  99. */
  100. bool v4l2_find_dv_timings_cea861_vic(struct v4l2_dv_timings *t, u8 vic);
  101. /**
  102. * v4l2_match_dv_timings() - do two timings match?
  103. *
  104. * @measured: the measured timings data.
  105. * @standard: the timings according to the standard.
  106. * @pclock_delta: maximum delta in Hz between standard->pixelclock and
  107. * the measured timings.
  108. * @match_reduced_fps: if true, then fail if V4L2_DV_FL_REDUCED_FPS does not
  109. * match.
  110. *
  111. * Returns true if the two timings match, returns false otherwise.
  112. */
  113. bool v4l2_match_dv_timings(const struct v4l2_dv_timings *measured,
  114. const struct v4l2_dv_timings *standard,
  115. unsigned pclock_delta, bool match_reduced_fps);
  116. /**
  117. * v4l2_print_dv_timings() - log the contents of a dv_timings struct
  118. * @dev_prefix:device prefix for each log line.
  119. * @prefix: additional prefix for each log line, may be NULL.
  120. * @t: the timings data.
  121. * @detailed: if true, give a detailed log.
  122. */
  123. void v4l2_print_dv_timings(const char *dev_prefix, const char *prefix,
  124. const struct v4l2_dv_timings *t, bool detailed);
  125. /**
  126. * v4l2_detect_cvt - detect if the given timings follow the CVT standard
  127. *
  128. * @frame_height: the total height of the frame (including blanking) in lines.
  129. * @hfreq: the horizontal frequency in Hz.
  130. * @vsync: the height of the vertical sync in lines.
  131. * @active_width: active width of image (does not include blanking). This
  132. * information is needed only in case of version 2 of reduced blanking.
  133. * In other cases, this parameter does not have any effect on timings.
  134. * @polarities: the horizontal and vertical polarities (same as struct
  135. * v4l2_bt_timings polarities).
  136. * @interlaced: if this flag is true, it indicates interlaced format
  137. * @fmt: the resulting timings.
  138. *
  139. * This function will attempt to detect if the given values correspond to a
  140. * valid CVT format. If so, then it will return true, and fmt will be filled
  141. * in with the found CVT timings.
  142. */
  143. bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync,
  144. unsigned active_width, u32 polarities, bool interlaced,
  145. struct v4l2_dv_timings *fmt);
  146. /**
  147. * v4l2_detect_gtf - detect if the given timings follow the GTF standard
  148. *
  149. * @frame_height: the total height of the frame (including blanking) in lines.
  150. * @hfreq: the horizontal frequency in Hz.
  151. * @vsync: the height of the vertical sync in lines.
  152. * @polarities: the horizontal and vertical polarities (same as struct
  153. * v4l2_bt_timings polarities).
  154. * @interlaced: if this flag is true, it indicates interlaced format
  155. * @aspect: preferred aspect ratio. GTF has no method of determining the
  156. * aspect ratio in order to derive the image width from the
  157. * image height, so it has to be passed explicitly. Usually
  158. * the native screen aspect ratio is used for this. If it
  159. * is not filled in correctly, then 16:9 will be assumed.
  160. * @fmt: the resulting timings.
  161. *
  162. * This function will attempt to detect if the given values correspond to a
  163. * valid GTF format. If so, then it will return true, and fmt will be filled
  164. * in with the found GTF timings.
  165. */
  166. bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, unsigned vsync,
  167. u32 polarities, bool interlaced, struct v4l2_fract aspect,
  168. struct v4l2_dv_timings *fmt);
  169. /**
  170. * v4l2_calc_aspect_ratio - calculate the aspect ratio based on bytes
  171. * 0x15 and 0x16 from the EDID.
  172. *
  173. * @hor_landscape: byte 0x15 from the EDID.
  174. * @vert_portrait: byte 0x16 from the EDID.
  175. *
  176. * Determines the aspect ratio from the EDID.
  177. * See VESA Enhanced EDID standard, release A, rev 2, section 3.6.2:
  178. * "Horizontal and Vertical Screen Size or Aspect Ratio"
  179. */
  180. struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait);
  181. /**
  182. * v4l2_dv_timings_aspect_ratio - calculate the aspect ratio based on the
  183. * v4l2_dv_timings information.
  184. *
  185. * @t: the timings data.
  186. */
  187. struct v4l2_fract v4l2_dv_timings_aspect_ratio(const struct v4l2_dv_timings *t);
  188. /**
  189. * can_reduce_fps - check if conditions for reduced fps are true.
  190. * @bt: v4l2 timing structure
  191. *
  192. * For different timings reduced fps is allowed if the following conditions
  193. * are met:
  194. *
  195. * - For CVT timings: if reduced blanking v2 (vsync == 8) is true.
  196. * - For CEA861 timings: if %V4L2_DV_FL_CAN_REDUCE_FPS flag is true.
  197. */
  198. static inline bool can_reduce_fps(struct v4l2_bt_timings *bt)
  199. {
  200. if ((bt->standards & V4L2_DV_BT_STD_CVT) && (bt->vsync == 8))
  201. return true;
  202. if ((bt->standards & V4L2_DV_BT_STD_CEA861) &&
  203. (bt->flags & V4L2_DV_FL_CAN_REDUCE_FPS))
  204. return true;
  205. return false;
  206. }
  207. /**
  208. * struct v4l2_hdmi_colorimetry - describes the HDMI colorimetry information
  209. * @colorspace: enum v4l2_colorspace, the colorspace
  210. * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
  211. * @quantization: enum v4l2_quantization, colorspace quantization
  212. * @xfer_func: enum v4l2_xfer_func, colorspace transfer function
  213. */
  214. struct v4l2_hdmi_colorimetry {
  215. enum v4l2_colorspace colorspace;
  216. enum v4l2_ycbcr_encoding ycbcr_enc;
  217. enum v4l2_quantization quantization;
  218. enum v4l2_xfer_func xfer_func;
  219. };
  220. struct hdmi_avi_infoframe;
  221. struct hdmi_vendor_infoframe;
  222. struct v4l2_hdmi_colorimetry
  223. v4l2_hdmi_rx_colorimetry(const struct hdmi_avi_infoframe *avi,
  224. const struct hdmi_vendor_infoframe *hdmi,
  225. unsigned int height);
  226. u16 v4l2_get_edid_phys_addr(const u8 *edid, unsigned int size,
  227. unsigned int *offset);
  228. void v4l2_set_edid_phys_addr(u8 *edid, unsigned int size, u16 phys_addr);
  229. u16 v4l2_phys_addr_for_input(u16 phys_addr, u8 input);
  230. int v4l2_phys_addr_validate(u16 phys_addr, u16 *parent, u16 *port);
  231. #endif