v4l2-dv-timings.h 8.7 KB

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