v4l2-dv-timings.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * v4l2-dv-timings - Internal header with dv-timings helper functions
  3. *
  4. * Copyright 2013 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  5. *
  6. * This program is free software; you may redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  11. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  13. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  14. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  15. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. * SOFTWARE.
  18. *
  19. */
  20. #ifndef __V4L2_DV_TIMINGS_H
  21. #define __V4L2_DV_TIMINGS_H
  22. #include <linux/videodev2.h>
  23. /** v4l2_dv_timings_presets: list of all dv_timings presets.
  24. */
  25. extern const struct v4l2_dv_timings v4l2_dv_timings_presets[];
  26. /** v4l2_valid_dv_timings() - are these timings valid?
  27. * @t: the v4l2_dv_timings struct.
  28. * @cap: the v4l2_dv_timings_cap capabilities.
  29. *
  30. * Returns true if the given dv_timings struct is supported by the
  31. * hardware capabilities, returns false otherwise.
  32. */
  33. bool v4l2_valid_dv_timings(const struct v4l2_dv_timings *t,
  34. const struct v4l2_dv_timings_cap *cap);
  35. /** v4l2_enum_dv_timings_cap() - Helper function to enumerate possible DV timings based on capabilities
  36. * @t: the v4l2_enum_dv_timings struct.
  37. * @cap: the v4l2_dv_timings_cap capabilities.
  38. *
  39. * This enumerates dv_timings using the full list of possible CEA-861 and DMT
  40. * timings, filtering out any timings that are not supported based on the
  41. * hardware capabilities.
  42. *
  43. * If a valid timing for the given index is found, it will fill in @t and
  44. * return 0, otherwise it returns -EINVAL.
  45. */
  46. int v4l2_enum_dv_timings_cap(struct v4l2_enum_dv_timings *t,
  47. const struct v4l2_dv_timings_cap *cap);
  48. /** v4l2_find_dv_timings_cap() - Find the closest timings struct
  49. * @t: the v4l2_enum_dv_timings struct.
  50. * @cap: the v4l2_dv_timings_cap capabilities.
  51. * @pclock_delta: maximum delta between t->pixelclock and the timing struct
  52. * under consideration.
  53. *
  54. * This function tries to map the given timings to an entry in the
  55. * full list of possible CEA-861 and DMT timings, filtering out any timings
  56. * that are not supported based on the hardware capabilities.
  57. *
  58. * On success it will fill in @t with the found timings and it returns true.
  59. * On failure it will return false.
  60. */
  61. bool v4l2_find_dv_timings_cap(struct v4l2_dv_timings *t,
  62. const struct v4l2_dv_timings_cap *cap,
  63. unsigned pclock_delta);
  64. /** v4l2_match_dv_timings() - do two timings match?
  65. * @measured: the measured timings data.
  66. * @standard: the timings according to the standard.
  67. * @pclock_delta: maximum delta in Hz between standard->pixelclock and
  68. * the measured timings.
  69. *
  70. * Returns true if the two timings match, returns false otherwise.
  71. */
  72. bool v4l2_match_dv_timings(const struct v4l2_dv_timings *measured,
  73. const struct v4l2_dv_timings *standard,
  74. unsigned pclock_delta);
  75. /** v4l2_print_dv_timings() - log the contents of a dv_timings struct
  76. * @dev_prefix:device prefix for each log line.
  77. * @prefix: additional prefix for each log line, may be NULL.
  78. * @t: the timings data.
  79. * @detailed: if true, give a detailed log.
  80. */
  81. void v4l2_print_dv_timings(const char *dev_prefix, const char *prefix,
  82. const struct v4l2_dv_timings *t, bool detailed);
  83. /** v4l2_detect_cvt - detect if the given timings follow the CVT standard
  84. * @frame_height - the total height of the frame (including blanking) in lines.
  85. * @hfreq - the horizontal frequency in Hz.
  86. * @vsync - the height of the vertical sync in lines.
  87. * @polarities - the horizontal and vertical polarities (same as struct
  88. * v4l2_bt_timings polarities).
  89. * @fmt - the resulting timings.
  90. *
  91. * This function will attempt to detect if the given values correspond to a
  92. * valid CVT format. If so, then it will return true, and fmt will be filled
  93. * in with the found CVT timings.
  94. */
  95. bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync,
  96. u32 polarities, struct v4l2_dv_timings *fmt);
  97. /** v4l2_detect_gtf - detect if the given timings follow the GTF standard
  98. * @frame_height - the total height of the frame (including blanking) in lines.
  99. * @hfreq - the horizontal frequency in Hz.
  100. * @vsync - the height of the vertical sync in lines.
  101. * @polarities - the horizontal and vertical polarities (same as struct
  102. * v4l2_bt_timings polarities).
  103. * @aspect - preferred aspect ratio. GTF has no method of determining the
  104. * aspect ratio in order to derive the image width from the
  105. * image height, so it has to be passed explicitly. Usually
  106. * the native screen aspect ratio is used for this. If it
  107. * is not filled in correctly, then 16:9 will be assumed.
  108. * @fmt - the resulting timings.
  109. *
  110. * This function will attempt to detect if the given values correspond to a
  111. * valid GTF format. If so, then it will return true, and fmt will be filled
  112. * in with the found GTF timings.
  113. */
  114. bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, unsigned vsync,
  115. u32 polarities, struct v4l2_fract aspect,
  116. struct v4l2_dv_timings *fmt);
  117. /** v4l2_calc_aspect_ratio - calculate the aspect ratio based on bytes
  118. * 0x15 and 0x16 from the EDID.
  119. * @hor_landscape - byte 0x15 from the EDID.
  120. * @vert_portrait - byte 0x16 from the EDID.
  121. *
  122. * Determines the aspect ratio from the EDID.
  123. * See VESA Enhanced EDID standard, release A, rev 2, section 3.6.2:
  124. * "Horizontal and Vertical Screen Size or Aspect Ratio"
  125. */
  126. struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait);
  127. #endif