v4l2-dv-timings.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * v4l2-dv-timings - 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. #include <linux/module.h>
  21. #include <linux/types.h>
  22. #include <linux/kernel.h>
  23. #include <linux/errno.h>
  24. #include <linux/videodev2.h>
  25. #include <linux/v4l2-dv-timings.h>
  26. #include <media/v4l2-common.h>
  27. #include <media/v4l2-dv-timings.h>
  28. static const struct v4l2_dv_timings timings[] = {
  29. V4L2_DV_BT_CEA_640X480P59_94,
  30. V4L2_DV_BT_CEA_720X480I59_94,
  31. V4L2_DV_BT_CEA_720X480P59_94,
  32. V4L2_DV_BT_CEA_720X576I50,
  33. V4L2_DV_BT_CEA_720X576P50,
  34. V4L2_DV_BT_CEA_1280X720P24,
  35. V4L2_DV_BT_CEA_1280X720P25,
  36. V4L2_DV_BT_CEA_1280X720P30,
  37. V4L2_DV_BT_CEA_1280X720P50,
  38. V4L2_DV_BT_CEA_1280X720P60,
  39. V4L2_DV_BT_CEA_1920X1080P24,
  40. V4L2_DV_BT_CEA_1920X1080P25,
  41. V4L2_DV_BT_CEA_1920X1080P30,
  42. V4L2_DV_BT_CEA_1920X1080I50,
  43. V4L2_DV_BT_CEA_1920X1080P50,
  44. V4L2_DV_BT_CEA_1920X1080I60,
  45. V4L2_DV_BT_CEA_1920X1080P60,
  46. V4L2_DV_BT_DMT_640X350P85,
  47. V4L2_DV_BT_DMT_640X400P85,
  48. V4L2_DV_BT_DMT_720X400P85,
  49. V4L2_DV_BT_DMT_640X480P72,
  50. V4L2_DV_BT_DMT_640X480P75,
  51. V4L2_DV_BT_DMT_640X480P85,
  52. V4L2_DV_BT_DMT_800X600P56,
  53. V4L2_DV_BT_DMT_800X600P60,
  54. V4L2_DV_BT_DMT_800X600P72,
  55. V4L2_DV_BT_DMT_800X600P75,
  56. V4L2_DV_BT_DMT_800X600P85,
  57. V4L2_DV_BT_DMT_800X600P120_RB,
  58. V4L2_DV_BT_DMT_848X480P60,
  59. V4L2_DV_BT_DMT_1024X768I43,
  60. V4L2_DV_BT_DMT_1024X768P60,
  61. V4L2_DV_BT_DMT_1024X768P70,
  62. V4L2_DV_BT_DMT_1024X768P75,
  63. V4L2_DV_BT_DMT_1024X768P85,
  64. V4L2_DV_BT_DMT_1024X768P120_RB,
  65. V4L2_DV_BT_DMT_1152X864P75,
  66. V4L2_DV_BT_DMT_1280X768P60_RB,
  67. V4L2_DV_BT_DMT_1280X768P60,
  68. V4L2_DV_BT_DMT_1280X768P75,
  69. V4L2_DV_BT_DMT_1280X768P85,
  70. V4L2_DV_BT_DMT_1280X768P120_RB,
  71. V4L2_DV_BT_DMT_1280X800P60_RB,
  72. V4L2_DV_BT_DMT_1280X800P60,
  73. V4L2_DV_BT_DMT_1280X800P75,
  74. V4L2_DV_BT_DMT_1280X800P85,
  75. V4L2_DV_BT_DMT_1280X800P120_RB,
  76. V4L2_DV_BT_DMT_1280X960P60,
  77. V4L2_DV_BT_DMT_1280X960P85,
  78. V4L2_DV_BT_DMT_1280X960P120_RB,
  79. V4L2_DV_BT_DMT_1280X1024P60,
  80. V4L2_DV_BT_DMT_1280X1024P75,
  81. V4L2_DV_BT_DMT_1280X1024P85,
  82. V4L2_DV_BT_DMT_1280X1024P120_RB,
  83. V4L2_DV_BT_DMT_1360X768P60,
  84. V4L2_DV_BT_DMT_1360X768P120_RB,
  85. V4L2_DV_BT_DMT_1366X768P60,
  86. V4L2_DV_BT_DMT_1366X768P60_RB,
  87. V4L2_DV_BT_DMT_1400X1050P60_RB,
  88. V4L2_DV_BT_DMT_1400X1050P60,
  89. V4L2_DV_BT_DMT_1400X1050P75,
  90. V4L2_DV_BT_DMT_1400X1050P85,
  91. V4L2_DV_BT_DMT_1400X1050P120_RB,
  92. V4L2_DV_BT_DMT_1440X900P60_RB,
  93. V4L2_DV_BT_DMT_1440X900P60,
  94. V4L2_DV_BT_DMT_1440X900P75,
  95. V4L2_DV_BT_DMT_1440X900P85,
  96. V4L2_DV_BT_DMT_1440X900P120_RB,
  97. V4L2_DV_BT_DMT_1600X900P60_RB,
  98. V4L2_DV_BT_DMT_1600X1200P60,
  99. V4L2_DV_BT_DMT_1600X1200P65,
  100. V4L2_DV_BT_DMT_1600X1200P70,
  101. V4L2_DV_BT_DMT_1600X1200P75,
  102. V4L2_DV_BT_DMT_1600X1200P85,
  103. V4L2_DV_BT_DMT_1600X1200P120_RB,
  104. V4L2_DV_BT_DMT_1680X1050P60_RB,
  105. V4L2_DV_BT_DMT_1680X1050P60,
  106. V4L2_DV_BT_DMT_1680X1050P75,
  107. V4L2_DV_BT_DMT_1680X1050P85,
  108. V4L2_DV_BT_DMT_1680X1050P120_RB,
  109. V4L2_DV_BT_DMT_1792X1344P60,
  110. V4L2_DV_BT_DMT_1792X1344P75,
  111. V4L2_DV_BT_DMT_1792X1344P120_RB,
  112. V4L2_DV_BT_DMT_1856X1392P60,
  113. V4L2_DV_BT_DMT_1856X1392P75,
  114. V4L2_DV_BT_DMT_1856X1392P120_RB,
  115. V4L2_DV_BT_DMT_1920X1200P60_RB,
  116. V4L2_DV_BT_DMT_1920X1200P60,
  117. V4L2_DV_BT_DMT_1920X1200P75,
  118. V4L2_DV_BT_DMT_1920X1200P85,
  119. V4L2_DV_BT_DMT_1920X1200P120_RB,
  120. V4L2_DV_BT_DMT_1920X1440P60,
  121. V4L2_DV_BT_DMT_1920X1440P75,
  122. V4L2_DV_BT_DMT_1920X1440P120_RB,
  123. V4L2_DV_BT_DMT_2048X1152P60_RB,
  124. V4L2_DV_BT_DMT_2560X1600P60_RB,
  125. V4L2_DV_BT_DMT_2560X1600P60,
  126. V4L2_DV_BT_DMT_2560X1600P75,
  127. V4L2_DV_BT_DMT_2560X1600P85,
  128. V4L2_DV_BT_DMT_2560X1600P120_RB,
  129. };
  130. bool v4l2_dv_valid_timings(const struct v4l2_dv_timings *t,
  131. const struct v4l2_dv_timings_cap *dvcap)
  132. {
  133. const struct v4l2_bt_timings *bt = &t->bt;
  134. const struct v4l2_bt_timings_cap *cap = &dvcap->bt;
  135. u32 caps = cap->capabilities;
  136. if (t->type != V4L2_DV_BT_656_1120)
  137. return false;
  138. if (t->type != dvcap->type ||
  139. bt->height < cap->min_height ||
  140. bt->height > cap->max_height ||
  141. bt->width < cap->min_width ||
  142. bt->width > cap->max_width ||
  143. bt->pixelclock < cap->min_pixelclock ||
  144. bt->pixelclock > cap->max_pixelclock ||
  145. (cap->standards && !(bt->standards & cap->standards)) ||
  146. (bt->interlaced && !(caps & V4L2_DV_BT_CAP_INTERLACED)) ||
  147. (!bt->interlaced && !(caps & V4L2_DV_BT_CAP_PROGRESSIVE)))
  148. return false;
  149. return true;
  150. }
  151. EXPORT_SYMBOL_GPL(v4l2_dv_valid_timings);
  152. int v4l2_enum_dv_timings_cap(struct v4l2_enum_dv_timings *t,
  153. const struct v4l2_dv_timings_cap *cap)
  154. {
  155. u32 i, idx;
  156. memset(t->reserved, 0, sizeof(t->reserved));
  157. for (i = idx = 0; i < ARRAY_SIZE(timings); i++) {
  158. if (v4l2_dv_valid_timings(timings + i, cap) &&
  159. idx++ == t->index) {
  160. t->timings = timings[i];
  161. return 0;
  162. }
  163. }
  164. return -EINVAL;
  165. }
  166. EXPORT_SYMBOL_GPL(v4l2_enum_dv_timings_cap);
  167. bool v4l2_find_dv_timings_cap(struct v4l2_dv_timings *t,
  168. const struct v4l2_dv_timings_cap *cap,
  169. unsigned pclock_delta)
  170. {
  171. int i;
  172. if (!v4l2_dv_valid_timings(t, cap))
  173. return false;
  174. for (i = 0; i < ARRAY_SIZE(timings); i++) {
  175. if (v4l2_dv_valid_timings(timings + i, cap) &&
  176. v4l_match_dv_timings(t, timings + i, pclock_delta)) {
  177. *t = timings[i];
  178. return true;
  179. }
  180. }
  181. return false;
  182. }
  183. EXPORT_SYMBOL_GPL(v4l2_find_dv_timings_cap);