v4l2-dv-timings.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * v4l2-dv-timings - dv-timings helper functions
  4. *
  5. * Copyright 2013 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/types.h>
  9. #include <linux/kernel.h>
  10. #include <linux/errno.h>
  11. #include <linux/rational.h>
  12. #include <linux/videodev2.h>
  13. #include <linux/v4l2-dv-timings.h>
  14. #include <media/v4l2-dv-timings.h>
  15. #include <linux/math64.h>
  16. #include <linux/hdmi.h>
  17. MODULE_AUTHOR("Hans Verkuil");
  18. MODULE_DESCRIPTION("V4L2 DV Timings Helper Functions");
  19. MODULE_LICENSE("GPL");
  20. const struct v4l2_dv_timings v4l2_dv_timings_presets[] = {
  21. V4L2_DV_BT_CEA_640X480P59_94,
  22. V4L2_DV_BT_CEA_720X480I59_94,
  23. V4L2_DV_BT_CEA_720X480P59_94,
  24. V4L2_DV_BT_CEA_720X576I50,
  25. V4L2_DV_BT_CEA_720X576P50,
  26. V4L2_DV_BT_CEA_1280X720P24,
  27. V4L2_DV_BT_CEA_1280X720P25,
  28. V4L2_DV_BT_CEA_1280X720P30,
  29. V4L2_DV_BT_CEA_1280X720P50,
  30. V4L2_DV_BT_CEA_1280X720P60,
  31. V4L2_DV_BT_CEA_1920X1080P24,
  32. V4L2_DV_BT_CEA_1920X1080P25,
  33. V4L2_DV_BT_CEA_1920X1080P30,
  34. V4L2_DV_BT_CEA_1920X1080I50,
  35. V4L2_DV_BT_CEA_1920X1080P50,
  36. V4L2_DV_BT_CEA_1920X1080I60,
  37. V4L2_DV_BT_CEA_1920X1080P60,
  38. V4L2_DV_BT_DMT_640X350P85,
  39. V4L2_DV_BT_DMT_640X400P85,
  40. V4L2_DV_BT_DMT_720X400P85,
  41. V4L2_DV_BT_DMT_640X480P72,
  42. V4L2_DV_BT_DMT_640X480P75,
  43. V4L2_DV_BT_DMT_640X480P85,
  44. V4L2_DV_BT_DMT_800X600P56,
  45. V4L2_DV_BT_DMT_800X600P60,
  46. V4L2_DV_BT_DMT_800X600P72,
  47. V4L2_DV_BT_DMT_800X600P75,
  48. V4L2_DV_BT_DMT_800X600P85,
  49. V4L2_DV_BT_DMT_800X600P120_RB,
  50. V4L2_DV_BT_DMT_848X480P60,
  51. V4L2_DV_BT_DMT_1024X768I43,
  52. V4L2_DV_BT_DMT_1024X768P60,
  53. V4L2_DV_BT_DMT_1024X768P70,
  54. V4L2_DV_BT_DMT_1024X768P75,
  55. V4L2_DV_BT_DMT_1024X768P85,
  56. V4L2_DV_BT_DMT_1024X768P120_RB,
  57. V4L2_DV_BT_DMT_1152X864P75,
  58. V4L2_DV_BT_DMT_1280X768P60_RB,
  59. V4L2_DV_BT_DMT_1280X768P60,
  60. V4L2_DV_BT_DMT_1280X768P75,
  61. V4L2_DV_BT_DMT_1280X768P85,
  62. V4L2_DV_BT_DMT_1280X768P120_RB,
  63. V4L2_DV_BT_DMT_1280X800P60_RB,
  64. V4L2_DV_BT_DMT_1280X800P60,
  65. V4L2_DV_BT_DMT_1280X800P75,
  66. V4L2_DV_BT_DMT_1280X800P85,
  67. V4L2_DV_BT_DMT_1280X800P120_RB,
  68. V4L2_DV_BT_DMT_1280X960P60,
  69. V4L2_DV_BT_DMT_1280X960P85,
  70. V4L2_DV_BT_DMT_1280X960P120_RB,
  71. V4L2_DV_BT_DMT_1280X1024P60,
  72. V4L2_DV_BT_DMT_1280X1024P75,
  73. V4L2_DV_BT_DMT_1280X1024P85,
  74. V4L2_DV_BT_DMT_1280X1024P120_RB,
  75. V4L2_DV_BT_DMT_1360X768P60,
  76. V4L2_DV_BT_DMT_1360X768P120_RB,
  77. V4L2_DV_BT_DMT_1366X768P60,
  78. V4L2_DV_BT_DMT_1366X768P60_RB,
  79. V4L2_DV_BT_DMT_1400X1050P60_RB,
  80. V4L2_DV_BT_DMT_1400X1050P60,
  81. V4L2_DV_BT_DMT_1400X1050P75,
  82. V4L2_DV_BT_DMT_1400X1050P85,
  83. V4L2_DV_BT_DMT_1400X1050P120_RB,
  84. V4L2_DV_BT_DMT_1440X900P60_RB,
  85. V4L2_DV_BT_DMT_1440X900P60,
  86. V4L2_DV_BT_DMT_1440X900P75,
  87. V4L2_DV_BT_DMT_1440X900P85,
  88. V4L2_DV_BT_DMT_1440X900P120_RB,
  89. V4L2_DV_BT_DMT_1600X900P60_RB,
  90. V4L2_DV_BT_DMT_1600X1200P60,
  91. V4L2_DV_BT_DMT_1600X1200P65,
  92. V4L2_DV_BT_DMT_1600X1200P70,
  93. V4L2_DV_BT_DMT_1600X1200P75,
  94. V4L2_DV_BT_DMT_1600X1200P85,
  95. V4L2_DV_BT_DMT_1600X1200P120_RB,
  96. V4L2_DV_BT_DMT_1680X1050P60_RB,
  97. V4L2_DV_BT_DMT_1680X1050P60,
  98. V4L2_DV_BT_DMT_1680X1050P75,
  99. V4L2_DV_BT_DMT_1680X1050P85,
  100. V4L2_DV_BT_DMT_1680X1050P120_RB,
  101. V4L2_DV_BT_DMT_1792X1344P60,
  102. V4L2_DV_BT_DMT_1792X1344P75,
  103. V4L2_DV_BT_DMT_1792X1344P120_RB,
  104. V4L2_DV_BT_DMT_1856X1392P60,
  105. V4L2_DV_BT_DMT_1856X1392P75,
  106. V4L2_DV_BT_DMT_1856X1392P120_RB,
  107. V4L2_DV_BT_DMT_1920X1200P60_RB,
  108. V4L2_DV_BT_DMT_1920X1200P60,
  109. V4L2_DV_BT_DMT_1920X1200P75,
  110. V4L2_DV_BT_DMT_1920X1200P85,
  111. V4L2_DV_BT_DMT_1920X1200P120_RB,
  112. V4L2_DV_BT_DMT_1920X1440P60,
  113. V4L2_DV_BT_DMT_1920X1440P75,
  114. V4L2_DV_BT_DMT_1920X1440P120_RB,
  115. V4L2_DV_BT_DMT_2048X1152P60_RB,
  116. V4L2_DV_BT_DMT_2560X1600P60_RB,
  117. V4L2_DV_BT_DMT_2560X1600P60,
  118. V4L2_DV_BT_DMT_2560X1600P75,
  119. V4L2_DV_BT_DMT_2560X1600P85,
  120. V4L2_DV_BT_DMT_2560X1600P120_RB,
  121. V4L2_DV_BT_CEA_3840X2160P24,
  122. V4L2_DV_BT_CEA_3840X2160P25,
  123. V4L2_DV_BT_CEA_3840X2160P30,
  124. V4L2_DV_BT_CEA_3840X2160P50,
  125. V4L2_DV_BT_CEA_3840X2160P60,
  126. V4L2_DV_BT_CEA_4096X2160P24,
  127. V4L2_DV_BT_CEA_4096X2160P25,
  128. V4L2_DV_BT_CEA_4096X2160P30,
  129. V4L2_DV_BT_CEA_4096X2160P50,
  130. V4L2_DV_BT_DMT_4096X2160P59_94_RB,
  131. V4L2_DV_BT_CEA_4096X2160P60,
  132. { }
  133. };
  134. EXPORT_SYMBOL_GPL(v4l2_dv_timings_presets);
  135. bool v4l2_valid_dv_timings(const struct v4l2_dv_timings *t,
  136. const struct v4l2_dv_timings_cap *dvcap,
  137. v4l2_check_dv_timings_fnc fnc,
  138. void *fnc_handle)
  139. {
  140. const struct v4l2_bt_timings *bt = &t->bt;
  141. const struct v4l2_bt_timings_cap *cap = &dvcap->bt;
  142. u32 caps = cap->capabilities;
  143. if (t->type != V4L2_DV_BT_656_1120)
  144. return false;
  145. if (t->type != dvcap->type ||
  146. bt->height < cap->min_height ||
  147. bt->height > cap->max_height ||
  148. bt->width < cap->min_width ||
  149. bt->width > cap->max_width ||
  150. bt->pixelclock < cap->min_pixelclock ||
  151. bt->pixelclock > cap->max_pixelclock ||
  152. (!(caps & V4L2_DV_BT_CAP_CUSTOM) &&
  153. cap->standards && bt->standards &&
  154. !(bt->standards & cap->standards)) ||
  155. (bt->interlaced && !(caps & V4L2_DV_BT_CAP_INTERLACED)) ||
  156. (!bt->interlaced && !(caps & V4L2_DV_BT_CAP_PROGRESSIVE)))
  157. return false;
  158. return fnc == NULL || fnc(t, fnc_handle);
  159. }
  160. EXPORT_SYMBOL_GPL(v4l2_valid_dv_timings);
  161. int v4l2_enum_dv_timings_cap(struct v4l2_enum_dv_timings *t,
  162. const struct v4l2_dv_timings_cap *cap,
  163. v4l2_check_dv_timings_fnc fnc,
  164. void *fnc_handle)
  165. {
  166. u32 i, idx;
  167. memset(t->reserved, 0, sizeof(t->reserved));
  168. for (i = idx = 0; v4l2_dv_timings_presets[i].bt.width; i++) {
  169. if (v4l2_valid_dv_timings(v4l2_dv_timings_presets + i, cap,
  170. fnc, fnc_handle) &&
  171. idx++ == t->index) {
  172. t->timings = v4l2_dv_timings_presets[i];
  173. return 0;
  174. }
  175. }
  176. return -EINVAL;
  177. }
  178. EXPORT_SYMBOL_GPL(v4l2_enum_dv_timings_cap);
  179. bool v4l2_find_dv_timings_cap(struct v4l2_dv_timings *t,
  180. const struct v4l2_dv_timings_cap *cap,
  181. unsigned pclock_delta,
  182. v4l2_check_dv_timings_fnc fnc,
  183. void *fnc_handle)
  184. {
  185. int i;
  186. if (!v4l2_valid_dv_timings(t, cap, fnc, fnc_handle))
  187. return false;
  188. for (i = 0; i < v4l2_dv_timings_presets[i].bt.width; i++) {
  189. if (v4l2_valid_dv_timings(v4l2_dv_timings_presets + i, cap,
  190. fnc, fnc_handle) &&
  191. v4l2_match_dv_timings(t, v4l2_dv_timings_presets + i,
  192. pclock_delta, false)) {
  193. u32 flags = t->bt.flags & V4L2_DV_FL_REDUCED_FPS;
  194. *t = v4l2_dv_timings_presets[i];
  195. if (can_reduce_fps(&t->bt))
  196. t->bt.flags |= flags;
  197. return true;
  198. }
  199. }
  200. return false;
  201. }
  202. EXPORT_SYMBOL_GPL(v4l2_find_dv_timings_cap);
  203. bool v4l2_find_dv_timings_cea861_vic(struct v4l2_dv_timings *t, u8 vic)
  204. {
  205. unsigned int i;
  206. for (i = 0; i < v4l2_dv_timings_presets[i].bt.width; i++) {
  207. const struct v4l2_bt_timings *bt =
  208. &v4l2_dv_timings_presets[i].bt;
  209. if ((bt->flags & V4L2_DV_FL_HAS_CEA861_VIC) &&
  210. bt->cea861_vic == vic) {
  211. *t = v4l2_dv_timings_presets[i];
  212. return true;
  213. }
  214. }
  215. return false;
  216. }
  217. EXPORT_SYMBOL_GPL(v4l2_find_dv_timings_cea861_vic);
  218. /**
  219. * v4l2_match_dv_timings - check if two timings match
  220. * @t1: compare this v4l2_dv_timings struct...
  221. * @t2: with this struct.
  222. * @pclock_delta: the allowed pixelclock deviation.
  223. * @match_reduced_fps: if true, then fail if V4L2_DV_FL_REDUCED_FPS does not
  224. * match.
  225. *
  226. * Compare t1 with t2 with a given margin of error for the pixelclock.
  227. */
  228. bool v4l2_match_dv_timings(const struct v4l2_dv_timings *t1,
  229. const struct v4l2_dv_timings *t2,
  230. unsigned pclock_delta, bool match_reduced_fps)
  231. {
  232. if (t1->type != t2->type || t1->type != V4L2_DV_BT_656_1120)
  233. return false;
  234. if (t1->bt.width == t2->bt.width &&
  235. t1->bt.height == t2->bt.height &&
  236. t1->bt.interlaced == t2->bt.interlaced &&
  237. t1->bt.polarities == t2->bt.polarities &&
  238. t1->bt.pixelclock >= t2->bt.pixelclock - pclock_delta &&
  239. t1->bt.pixelclock <= t2->bt.pixelclock + pclock_delta &&
  240. t1->bt.hfrontporch == t2->bt.hfrontporch &&
  241. t1->bt.hsync == t2->bt.hsync &&
  242. t1->bt.hbackporch == t2->bt.hbackporch &&
  243. t1->bt.vfrontporch == t2->bt.vfrontporch &&
  244. t1->bt.vsync == t2->bt.vsync &&
  245. t1->bt.vbackporch == t2->bt.vbackporch &&
  246. (!match_reduced_fps ||
  247. (t1->bt.flags & V4L2_DV_FL_REDUCED_FPS) ==
  248. (t2->bt.flags & V4L2_DV_FL_REDUCED_FPS)) &&
  249. (!t1->bt.interlaced ||
  250. (t1->bt.il_vfrontporch == t2->bt.il_vfrontporch &&
  251. t1->bt.il_vsync == t2->bt.il_vsync &&
  252. t1->bt.il_vbackporch == t2->bt.il_vbackporch)))
  253. return true;
  254. return false;
  255. }
  256. EXPORT_SYMBOL_GPL(v4l2_match_dv_timings);
  257. void v4l2_print_dv_timings(const char *dev_prefix, const char *prefix,
  258. const struct v4l2_dv_timings *t, bool detailed)
  259. {
  260. const struct v4l2_bt_timings *bt = &t->bt;
  261. u32 htot, vtot;
  262. u32 fps;
  263. if (t->type != V4L2_DV_BT_656_1120)
  264. return;
  265. htot = V4L2_DV_BT_FRAME_WIDTH(bt);
  266. vtot = V4L2_DV_BT_FRAME_HEIGHT(bt);
  267. if (bt->interlaced)
  268. vtot /= 2;
  269. fps = (htot * vtot) > 0 ? div_u64((100 * (u64)bt->pixelclock),
  270. (htot * vtot)) : 0;
  271. if (prefix == NULL)
  272. prefix = "";
  273. pr_info("%s: %s%ux%u%s%u.%u (%ux%u)\n", dev_prefix, prefix,
  274. bt->width, bt->height, bt->interlaced ? "i" : "p",
  275. fps / 100, fps % 100, htot, vtot);
  276. if (!detailed)
  277. return;
  278. pr_info("%s: horizontal: fp = %u, %ssync = %u, bp = %u\n",
  279. dev_prefix, bt->hfrontporch,
  280. (bt->polarities & V4L2_DV_HSYNC_POS_POL) ? "+" : "-",
  281. bt->hsync, bt->hbackporch);
  282. pr_info("%s: vertical: fp = %u, %ssync = %u, bp = %u\n",
  283. dev_prefix, bt->vfrontporch,
  284. (bt->polarities & V4L2_DV_VSYNC_POS_POL) ? "+" : "-",
  285. bt->vsync, bt->vbackporch);
  286. if (bt->interlaced)
  287. pr_info("%s: vertical bottom field: fp = %u, %ssync = %u, bp = %u\n",
  288. dev_prefix, bt->il_vfrontporch,
  289. (bt->polarities & V4L2_DV_VSYNC_POS_POL) ? "+" : "-",
  290. bt->il_vsync, bt->il_vbackporch);
  291. pr_info("%s: pixelclock: %llu\n", dev_prefix, bt->pixelclock);
  292. pr_info("%s: flags (0x%x):%s%s%s%s%s%s%s%s%s%s\n",
  293. dev_prefix, bt->flags,
  294. (bt->flags & V4L2_DV_FL_REDUCED_BLANKING) ?
  295. " REDUCED_BLANKING" : "",
  296. ((bt->flags & V4L2_DV_FL_REDUCED_BLANKING) &&
  297. bt->vsync == 8) ? " (V2)" : "",
  298. (bt->flags & V4L2_DV_FL_CAN_REDUCE_FPS) ?
  299. " CAN_REDUCE_FPS" : "",
  300. (bt->flags & V4L2_DV_FL_REDUCED_FPS) ?
  301. " REDUCED_FPS" : "",
  302. (bt->flags & V4L2_DV_FL_HALF_LINE) ?
  303. " HALF_LINE" : "",
  304. (bt->flags & V4L2_DV_FL_IS_CE_VIDEO) ?
  305. " CE_VIDEO" : "",
  306. (bt->flags & V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE) ?
  307. " FIRST_FIELD_EXTRA_LINE" : "",
  308. (bt->flags & V4L2_DV_FL_HAS_PICTURE_ASPECT) ?
  309. " HAS_PICTURE_ASPECT" : "",
  310. (bt->flags & V4L2_DV_FL_HAS_CEA861_VIC) ?
  311. " HAS_CEA861_VIC" : "",
  312. (bt->flags & V4L2_DV_FL_HAS_HDMI_VIC) ?
  313. " HAS_HDMI_VIC" : "");
  314. pr_info("%s: standards (0x%x):%s%s%s%s%s\n", dev_prefix, bt->standards,
  315. (bt->standards & V4L2_DV_BT_STD_CEA861) ? " CEA" : "",
  316. (bt->standards & V4L2_DV_BT_STD_DMT) ? " DMT" : "",
  317. (bt->standards & V4L2_DV_BT_STD_CVT) ? " CVT" : "",
  318. (bt->standards & V4L2_DV_BT_STD_GTF) ? " GTF" : "",
  319. (bt->standards & V4L2_DV_BT_STD_SDI) ? " SDI" : "");
  320. if (bt->flags & V4L2_DV_FL_HAS_PICTURE_ASPECT)
  321. pr_info("%s: picture aspect (hor:vert): %u:%u\n", dev_prefix,
  322. bt->picture_aspect.numerator,
  323. bt->picture_aspect.denominator);
  324. if (bt->flags & V4L2_DV_FL_HAS_CEA861_VIC)
  325. pr_info("%s: CEA-861 VIC: %u\n", dev_prefix, bt->cea861_vic);
  326. if (bt->flags & V4L2_DV_FL_HAS_HDMI_VIC)
  327. pr_info("%s: HDMI VIC: %u\n", dev_prefix, bt->hdmi_vic);
  328. }
  329. EXPORT_SYMBOL_GPL(v4l2_print_dv_timings);
  330. struct v4l2_fract v4l2_dv_timings_aspect_ratio(const struct v4l2_dv_timings *t)
  331. {
  332. struct v4l2_fract ratio = { 1, 1 };
  333. unsigned long n, d;
  334. if (t->type != V4L2_DV_BT_656_1120)
  335. return ratio;
  336. if (!(t->bt.flags & V4L2_DV_FL_HAS_PICTURE_ASPECT))
  337. return ratio;
  338. ratio.numerator = t->bt.width * t->bt.picture_aspect.denominator;
  339. ratio.denominator = t->bt.height * t->bt.picture_aspect.numerator;
  340. rational_best_approximation(ratio.numerator, ratio.denominator,
  341. ratio.numerator, ratio.denominator, &n, &d);
  342. ratio.numerator = n;
  343. ratio.denominator = d;
  344. return ratio;
  345. }
  346. EXPORT_SYMBOL_GPL(v4l2_dv_timings_aspect_ratio);
  347. /** v4l2_calc_timeperframe - helper function to calculate timeperframe based
  348. * v4l2_dv_timings fields.
  349. * @t - Timings for the video mode.
  350. *
  351. * Calculates the expected timeperframe using the pixel clock value and
  352. * horizontal/vertical measures. This means that v4l2_dv_timings structure
  353. * must be correctly and fully filled.
  354. */
  355. struct v4l2_fract v4l2_calc_timeperframe(const struct v4l2_dv_timings *t)
  356. {
  357. const struct v4l2_bt_timings *bt = &t->bt;
  358. struct v4l2_fract fps_fract = { 1, 1 };
  359. unsigned long n, d;
  360. u32 htot, vtot, fps;
  361. u64 pclk;
  362. if (t->type != V4L2_DV_BT_656_1120)
  363. return fps_fract;
  364. htot = V4L2_DV_BT_FRAME_WIDTH(bt);
  365. vtot = V4L2_DV_BT_FRAME_HEIGHT(bt);
  366. pclk = bt->pixelclock;
  367. if ((bt->flags & V4L2_DV_FL_CAN_DETECT_REDUCED_FPS) &&
  368. (bt->flags & V4L2_DV_FL_REDUCED_FPS))
  369. pclk = div_u64(pclk * 1000ULL, 1001);
  370. fps = (htot * vtot) > 0 ? div_u64((100 * pclk), (htot * vtot)) : 0;
  371. if (!fps)
  372. return fps_fract;
  373. rational_best_approximation(fps, 100, fps, 100, &n, &d);
  374. fps_fract.numerator = d;
  375. fps_fract.denominator = n;
  376. return fps_fract;
  377. }
  378. EXPORT_SYMBOL_GPL(v4l2_calc_timeperframe);
  379. /*
  380. * CVT defines
  381. * Based on Coordinated Video Timings Standard
  382. * version 1.1 September 10, 2003
  383. */
  384. #define CVT_PXL_CLK_GRAN 250000 /* pixel clock granularity */
  385. #define CVT_PXL_CLK_GRAN_RB_V2 1000 /* granularity for reduced blanking v2*/
  386. /* Normal blanking */
  387. #define CVT_MIN_V_BPORCH 7 /* lines */
  388. #define CVT_MIN_V_PORCH_RND 3 /* lines */
  389. #define CVT_MIN_VSYNC_BP 550 /* min time of vsync + back porch (us) */
  390. #define CVT_HSYNC_PERCENT 8 /* nominal hsync as percentage of line */
  391. /* Normal blanking for CVT uses GTF to calculate horizontal blanking */
  392. #define CVT_CELL_GRAN 8 /* character cell granularity */
  393. #define CVT_M 600 /* blanking formula gradient */
  394. #define CVT_C 40 /* blanking formula offset */
  395. #define CVT_K 128 /* blanking formula scaling factor */
  396. #define CVT_J 20 /* blanking formula scaling factor */
  397. #define CVT_C_PRIME (((CVT_C - CVT_J) * CVT_K / 256) + CVT_J)
  398. #define CVT_M_PRIME (CVT_K * CVT_M / 256)
  399. /* Reduced Blanking */
  400. #define CVT_RB_MIN_V_BPORCH 7 /* lines */
  401. #define CVT_RB_V_FPORCH 3 /* lines */
  402. #define CVT_RB_MIN_V_BLANK 460 /* us */
  403. #define CVT_RB_H_SYNC 32 /* pixels */
  404. #define CVT_RB_H_BLANK 160 /* pixels */
  405. /* Reduce blanking Version 2 */
  406. #define CVT_RB_V2_H_BLANK 80 /* pixels */
  407. #define CVT_RB_MIN_V_FPORCH 3 /* lines */
  408. #define CVT_RB_V2_MIN_V_FPORCH 1 /* lines */
  409. #define CVT_RB_V_BPORCH 6 /* lines */
  410. /** v4l2_detect_cvt - detect if the given timings follow the CVT standard
  411. * @frame_height - the total height of the frame (including blanking) in lines.
  412. * @hfreq - the horizontal frequency in Hz.
  413. * @vsync - the height of the vertical sync in lines.
  414. * @active_width - active width of image (does not include blanking). This
  415. * information is needed only in case of version 2 of reduced blanking.
  416. * In other cases, this parameter does not have any effect on timings.
  417. * @polarities - the horizontal and vertical polarities (same as struct
  418. * v4l2_bt_timings polarities).
  419. * @interlaced - if this flag is true, it indicates interlaced format
  420. * @fmt - the resulting timings.
  421. *
  422. * This function will attempt to detect if the given values correspond to a
  423. * valid CVT format. If so, then it will return true, and fmt will be filled
  424. * in with the found CVT timings.
  425. */
  426. bool v4l2_detect_cvt(unsigned frame_height,
  427. unsigned hfreq,
  428. unsigned vsync,
  429. unsigned active_width,
  430. u32 polarities,
  431. bool interlaced,
  432. struct v4l2_dv_timings *fmt)
  433. {
  434. int v_fp, v_bp, h_fp, h_bp, hsync;
  435. int frame_width, image_height, image_width;
  436. bool reduced_blanking;
  437. bool rb_v2 = false;
  438. unsigned pix_clk;
  439. if (vsync < 4 || vsync > 8)
  440. return false;
  441. if (polarities == V4L2_DV_VSYNC_POS_POL)
  442. reduced_blanking = false;
  443. else if (polarities == V4L2_DV_HSYNC_POS_POL)
  444. reduced_blanking = true;
  445. else
  446. return false;
  447. if (reduced_blanking && vsync == 8)
  448. rb_v2 = true;
  449. if (rb_v2 && active_width == 0)
  450. return false;
  451. if (!rb_v2 && vsync > 7)
  452. return false;
  453. if (hfreq == 0)
  454. return false;
  455. /* Vertical */
  456. if (reduced_blanking) {
  457. if (rb_v2) {
  458. v_bp = CVT_RB_V_BPORCH;
  459. v_fp = (CVT_RB_MIN_V_BLANK * hfreq) / 1000000 + 1;
  460. v_fp -= vsync + v_bp;
  461. if (v_fp < CVT_RB_V2_MIN_V_FPORCH)
  462. v_fp = CVT_RB_V2_MIN_V_FPORCH;
  463. } else {
  464. v_fp = CVT_RB_V_FPORCH;
  465. v_bp = (CVT_RB_MIN_V_BLANK * hfreq) / 1000000 + 1;
  466. v_bp -= vsync + v_fp;
  467. if (v_bp < CVT_RB_MIN_V_BPORCH)
  468. v_bp = CVT_RB_MIN_V_BPORCH;
  469. }
  470. } else {
  471. v_fp = CVT_MIN_V_PORCH_RND;
  472. v_bp = (CVT_MIN_VSYNC_BP * hfreq) / 1000000 + 1 - vsync;
  473. if (v_bp < CVT_MIN_V_BPORCH)
  474. v_bp = CVT_MIN_V_BPORCH;
  475. }
  476. if (interlaced)
  477. image_height = (frame_height - 2 * v_fp - 2 * vsync - 2 * v_bp) & ~0x1;
  478. else
  479. image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1;
  480. if (image_height < 0)
  481. return false;
  482. /* Aspect ratio based on vsync */
  483. switch (vsync) {
  484. case 4:
  485. image_width = (image_height * 4) / 3;
  486. break;
  487. case 5:
  488. image_width = (image_height * 16) / 9;
  489. break;
  490. case 6:
  491. image_width = (image_height * 16) / 10;
  492. break;
  493. case 7:
  494. /* special case */
  495. if (image_height == 1024)
  496. image_width = (image_height * 5) / 4;
  497. else if (image_height == 768)
  498. image_width = (image_height * 15) / 9;
  499. else
  500. return false;
  501. break;
  502. case 8:
  503. image_width = active_width;
  504. break;
  505. default:
  506. return false;
  507. }
  508. if (!rb_v2)
  509. image_width = image_width & ~7;
  510. /* Horizontal */
  511. if (reduced_blanking) {
  512. int h_blank;
  513. int clk_gran;
  514. h_blank = rb_v2 ? CVT_RB_V2_H_BLANK : CVT_RB_H_BLANK;
  515. clk_gran = rb_v2 ? CVT_PXL_CLK_GRAN_RB_V2 : CVT_PXL_CLK_GRAN;
  516. pix_clk = (image_width + h_blank) * hfreq;
  517. pix_clk = (pix_clk / clk_gran) * clk_gran;
  518. h_bp = h_blank / 2;
  519. hsync = CVT_RB_H_SYNC;
  520. h_fp = h_blank - h_bp - hsync;
  521. frame_width = image_width + h_blank;
  522. } else {
  523. unsigned ideal_duty_cycle_per_myriad =
  524. 100 * CVT_C_PRIME - (CVT_M_PRIME * 100000) / hfreq;
  525. int h_blank;
  526. if (ideal_duty_cycle_per_myriad < 2000)
  527. ideal_duty_cycle_per_myriad = 2000;
  528. h_blank = image_width * ideal_duty_cycle_per_myriad /
  529. (10000 - ideal_duty_cycle_per_myriad);
  530. h_blank = (h_blank / (2 * CVT_CELL_GRAN)) * 2 * CVT_CELL_GRAN;
  531. pix_clk = (image_width + h_blank) * hfreq;
  532. pix_clk = (pix_clk / CVT_PXL_CLK_GRAN) * CVT_PXL_CLK_GRAN;
  533. h_bp = h_blank / 2;
  534. frame_width = image_width + h_blank;
  535. hsync = frame_width * CVT_HSYNC_PERCENT / 100;
  536. hsync = (hsync / CVT_CELL_GRAN) * CVT_CELL_GRAN;
  537. h_fp = h_blank - hsync - h_bp;
  538. }
  539. fmt->type = V4L2_DV_BT_656_1120;
  540. fmt->bt.polarities = polarities;
  541. fmt->bt.width = image_width;
  542. fmt->bt.height = image_height;
  543. fmt->bt.hfrontporch = h_fp;
  544. fmt->bt.vfrontporch = v_fp;
  545. fmt->bt.hsync = hsync;
  546. fmt->bt.vsync = vsync;
  547. fmt->bt.hbackporch = frame_width - image_width - h_fp - hsync;
  548. if (!interlaced) {
  549. fmt->bt.vbackporch = frame_height - image_height - v_fp - vsync;
  550. fmt->bt.interlaced = V4L2_DV_PROGRESSIVE;
  551. } else {
  552. fmt->bt.vbackporch = (frame_height - image_height - 2 * v_fp -
  553. 2 * vsync) / 2;
  554. fmt->bt.il_vbackporch = frame_height - image_height - 2 * v_fp -
  555. 2 * vsync - fmt->bt.vbackporch;
  556. fmt->bt.il_vfrontporch = v_fp;
  557. fmt->bt.il_vsync = vsync;
  558. fmt->bt.flags |= V4L2_DV_FL_HALF_LINE;
  559. fmt->bt.interlaced = V4L2_DV_INTERLACED;
  560. }
  561. fmt->bt.pixelclock = pix_clk;
  562. fmt->bt.standards = V4L2_DV_BT_STD_CVT;
  563. if (reduced_blanking)
  564. fmt->bt.flags |= V4L2_DV_FL_REDUCED_BLANKING;
  565. return true;
  566. }
  567. EXPORT_SYMBOL_GPL(v4l2_detect_cvt);
  568. /*
  569. * GTF defines
  570. * Based on Generalized Timing Formula Standard
  571. * Version 1.1 September 2, 1999
  572. */
  573. #define GTF_PXL_CLK_GRAN 250000 /* pixel clock granularity */
  574. #define GTF_MIN_VSYNC_BP 550 /* min time of vsync + back porch (us) */
  575. #define GTF_V_FP 1 /* vertical front porch (lines) */
  576. #define GTF_CELL_GRAN 8 /* character cell granularity */
  577. /* Default */
  578. #define GTF_D_M 600 /* blanking formula gradient */
  579. #define GTF_D_C 40 /* blanking formula offset */
  580. #define GTF_D_K 128 /* blanking formula scaling factor */
  581. #define GTF_D_J 20 /* blanking formula scaling factor */
  582. #define GTF_D_C_PRIME ((((GTF_D_C - GTF_D_J) * GTF_D_K) / 256) + GTF_D_J)
  583. #define GTF_D_M_PRIME ((GTF_D_K * GTF_D_M) / 256)
  584. /* Secondary */
  585. #define GTF_S_M 3600 /* blanking formula gradient */
  586. #define GTF_S_C 40 /* blanking formula offset */
  587. #define GTF_S_K 128 /* blanking formula scaling factor */
  588. #define GTF_S_J 35 /* blanking formula scaling factor */
  589. #define GTF_S_C_PRIME ((((GTF_S_C - GTF_S_J) * GTF_S_K) / 256) + GTF_S_J)
  590. #define GTF_S_M_PRIME ((GTF_S_K * GTF_S_M) / 256)
  591. /** v4l2_detect_gtf - detect if the given timings follow the GTF standard
  592. * @frame_height - the total height of the frame (including blanking) in lines.
  593. * @hfreq - the horizontal frequency in Hz.
  594. * @vsync - the height of the vertical sync in lines.
  595. * @polarities - the horizontal and vertical polarities (same as struct
  596. * v4l2_bt_timings polarities).
  597. * @interlaced - if this flag is true, it indicates interlaced format
  598. * @aspect - preferred aspect ratio. GTF has no method of determining the
  599. * aspect ratio in order to derive the image width from the
  600. * image height, so it has to be passed explicitly. Usually
  601. * the native screen aspect ratio is used for this. If it
  602. * is not filled in correctly, then 16:9 will be assumed.
  603. * @fmt - the resulting timings.
  604. *
  605. * This function will attempt to detect if the given values correspond to a
  606. * valid GTF format. If so, then it will return true, and fmt will be filled
  607. * in with the found GTF timings.
  608. */
  609. bool v4l2_detect_gtf(unsigned frame_height,
  610. unsigned hfreq,
  611. unsigned vsync,
  612. u32 polarities,
  613. bool interlaced,
  614. struct v4l2_fract aspect,
  615. struct v4l2_dv_timings *fmt)
  616. {
  617. int pix_clk;
  618. int v_fp, v_bp, h_fp, hsync;
  619. int frame_width, image_height, image_width;
  620. bool default_gtf;
  621. int h_blank;
  622. if (vsync != 3)
  623. return false;
  624. if (polarities == V4L2_DV_VSYNC_POS_POL)
  625. default_gtf = true;
  626. else if (polarities == V4L2_DV_HSYNC_POS_POL)
  627. default_gtf = false;
  628. else
  629. return false;
  630. if (hfreq == 0)
  631. return false;
  632. /* Vertical */
  633. v_fp = GTF_V_FP;
  634. v_bp = (GTF_MIN_VSYNC_BP * hfreq + 500000) / 1000000 - vsync;
  635. if (interlaced)
  636. image_height = (frame_height - 2 * v_fp - 2 * vsync - 2 * v_bp) & ~0x1;
  637. else
  638. image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1;
  639. if (image_height < 0)
  640. return false;
  641. if (aspect.numerator == 0 || aspect.denominator == 0) {
  642. aspect.numerator = 16;
  643. aspect.denominator = 9;
  644. }
  645. image_width = ((image_height * aspect.numerator) / aspect.denominator);
  646. image_width = (image_width + GTF_CELL_GRAN/2) & ~(GTF_CELL_GRAN - 1);
  647. /* Horizontal */
  648. if (default_gtf) {
  649. u64 num;
  650. u32 den;
  651. num = ((image_width * GTF_D_C_PRIME * (u64)hfreq) -
  652. ((u64)image_width * GTF_D_M_PRIME * 1000));
  653. den = (hfreq * (100 - GTF_D_C_PRIME) + GTF_D_M_PRIME * 1000) *
  654. (2 * GTF_CELL_GRAN);
  655. h_blank = div_u64((num + (den >> 1)), den);
  656. h_blank *= (2 * GTF_CELL_GRAN);
  657. } else {
  658. u64 num;
  659. u32 den;
  660. num = ((image_width * GTF_S_C_PRIME * (u64)hfreq) -
  661. ((u64)image_width * GTF_S_M_PRIME * 1000));
  662. den = (hfreq * (100 - GTF_S_C_PRIME) + GTF_S_M_PRIME * 1000) *
  663. (2 * GTF_CELL_GRAN);
  664. h_blank = div_u64((num + (den >> 1)), den);
  665. h_blank *= (2 * GTF_CELL_GRAN);
  666. }
  667. frame_width = image_width + h_blank;
  668. pix_clk = (image_width + h_blank) * hfreq;
  669. pix_clk = pix_clk / GTF_PXL_CLK_GRAN * GTF_PXL_CLK_GRAN;
  670. hsync = (frame_width * 8 + 50) / 100;
  671. hsync = ((hsync + GTF_CELL_GRAN / 2) / GTF_CELL_GRAN) * GTF_CELL_GRAN;
  672. h_fp = h_blank / 2 - hsync;
  673. fmt->type = V4L2_DV_BT_656_1120;
  674. fmt->bt.polarities = polarities;
  675. fmt->bt.width = image_width;
  676. fmt->bt.height = image_height;
  677. fmt->bt.hfrontporch = h_fp;
  678. fmt->bt.vfrontporch = v_fp;
  679. fmt->bt.hsync = hsync;
  680. fmt->bt.vsync = vsync;
  681. fmt->bt.hbackporch = frame_width - image_width - h_fp - hsync;
  682. if (!interlaced) {
  683. fmt->bt.vbackporch = frame_height - image_height - v_fp - vsync;
  684. fmt->bt.interlaced = V4L2_DV_PROGRESSIVE;
  685. } else {
  686. fmt->bt.vbackporch = (frame_height - image_height - 2 * v_fp -
  687. 2 * vsync) / 2;
  688. fmt->bt.il_vbackporch = frame_height - image_height - 2 * v_fp -
  689. 2 * vsync - fmt->bt.vbackporch;
  690. fmt->bt.il_vfrontporch = v_fp;
  691. fmt->bt.il_vsync = vsync;
  692. fmt->bt.flags |= V4L2_DV_FL_HALF_LINE;
  693. fmt->bt.interlaced = V4L2_DV_INTERLACED;
  694. }
  695. fmt->bt.pixelclock = pix_clk;
  696. fmt->bt.standards = V4L2_DV_BT_STD_GTF;
  697. if (!default_gtf)
  698. fmt->bt.flags |= V4L2_DV_FL_REDUCED_BLANKING;
  699. return true;
  700. }
  701. EXPORT_SYMBOL_GPL(v4l2_detect_gtf);
  702. /** v4l2_calc_aspect_ratio - calculate the aspect ratio based on bytes
  703. * 0x15 and 0x16 from the EDID.
  704. * @hor_landscape - byte 0x15 from the EDID.
  705. * @vert_portrait - byte 0x16 from the EDID.
  706. *
  707. * Determines the aspect ratio from the EDID.
  708. * See VESA Enhanced EDID standard, release A, rev 2, section 3.6.2:
  709. * "Horizontal and Vertical Screen Size or Aspect Ratio"
  710. */
  711. struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait)
  712. {
  713. struct v4l2_fract aspect = { 16, 9 };
  714. u8 ratio;
  715. /* Nothing filled in, fallback to 16:9 */
  716. if (!hor_landscape && !vert_portrait)
  717. return aspect;
  718. /* Both filled in, so they are interpreted as the screen size in cm */
  719. if (hor_landscape && vert_portrait) {
  720. aspect.numerator = hor_landscape;
  721. aspect.denominator = vert_portrait;
  722. return aspect;
  723. }
  724. /* Only one is filled in, so interpret them as a ratio:
  725. (val + 99) / 100 */
  726. ratio = hor_landscape | vert_portrait;
  727. /* Change some rounded values into the exact aspect ratio */
  728. if (ratio == 79) {
  729. aspect.numerator = 16;
  730. aspect.denominator = 9;
  731. } else if (ratio == 34) {
  732. aspect.numerator = 4;
  733. aspect.denominator = 3;
  734. } else if (ratio == 68) {
  735. aspect.numerator = 15;
  736. aspect.denominator = 9;
  737. } else {
  738. aspect.numerator = hor_landscape + 99;
  739. aspect.denominator = 100;
  740. }
  741. if (hor_landscape)
  742. return aspect;
  743. /* The aspect ratio is for portrait, so swap numerator and denominator */
  744. swap(aspect.denominator, aspect.numerator);
  745. return aspect;
  746. }
  747. EXPORT_SYMBOL_GPL(v4l2_calc_aspect_ratio);
  748. /** v4l2_hdmi_rx_colorimetry - determine HDMI colorimetry information
  749. * based on various InfoFrames.
  750. * @avi: the AVI InfoFrame
  751. * @hdmi: the HDMI Vendor InfoFrame, may be NULL
  752. * @height: the frame height
  753. *
  754. * Determines the HDMI colorimetry information, i.e. how the HDMI
  755. * pixel color data should be interpreted.
  756. *
  757. * Note that some of the newer features (DCI-P3, HDR) are not yet
  758. * implemented: the hdmi.h header needs to be updated to the HDMI 2.0
  759. * and CTA-861-G standards.
  760. */
  761. struct v4l2_hdmi_colorimetry
  762. v4l2_hdmi_rx_colorimetry(const struct hdmi_avi_infoframe *avi,
  763. const struct hdmi_vendor_infoframe *hdmi,
  764. unsigned int height)
  765. {
  766. struct v4l2_hdmi_colorimetry c = {
  767. V4L2_COLORSPACE_SRGB,
  768. V4L2_YCBCR_ENC_DEFAULT,
  769. V4L2_QUANTIZATION_FULL_RANGE,
  770. V4L2_XFER_FUNC_SRGB
  771. };
  772. bool is_ce = avi->video_code || (hdmi && hdmi->vic);
  773. bool is_sdtv = height <= 576;
  774. bool default_is_lim_range_rgb = avi->video_code > 1;
  775. switch (avi->colorspace) {
  776. case HDMI_COLORSPACE_RGB:
  777. /* RGB pixel encoding */
  778. switch (avi->colorimetry) {
  779. case HDMI_COLORIMETRY_EXTENDED:
  780. switch (avi->extended_colorimetry) {
  781. case HDMI_EXTENDED_COLORIMETRY_ADOBE_RGB:
  782. c.colorspace = V4L2_COLORSPACE_ADOBERGB;
  783. c.xfer_func = V4L2_XFER_FUNC_ADOBERGB;
  784. break;
  785. case HDMI_EXTENDED_COLORIMETRY_BT2020:
  786. c.colorspace = V4L2_COLORSPACE_BT2020;
  787. c.xfer_func = V4L2_XFER_FUNC_709;
  788. break;
  789. default:
  790. break;
  791. }
  792. break;
  793. default:
  794. break;
  795. }
  796. switch (avi->quantization_range) {
  797. case HDMI_QUANTIZATION_RANGE_LIMITED:
  798. c.quantization = V4L2_QUANTIZATION_LIM_RANGE;
  799. break;
  800. case HDMI_QUANTIZATION_RANGE_FULL:
  801. break;
  802. default:
  803. if (default_is_lim_range_rgb)
  804. c.quantization = V4L2_QUANTIZATION_LIM_RANGE;
  805. break;
  806. }
  807. break;
  808. default:
  809. /* YCbCr pixel encoding */
  810. c.quantization = V4L2_QUANTIZATION_LIM_RANGE;
  811. switch (avi->colorimetry) {
  812. case HDMI_COLORIMETRY_NONE:
  813. if (!is_ce)
  814. break;
  815. if (is_sdtv) {
  816. c.colorspace = V4L2_COLORSPACE_SMPTE170M;
  817. c.ycbcr_enc = V4L2_YCBCR_ENC_601;
  818. } else {
  819. c.colorspace = V4L2_COLORSPACE_REC709;
  820. c.ycbcr_enc = V4L2_YCBCR_ENC_709;
  821. }
  822. c.xfer_func = V4L2_XFER_FUNC_709;
  823. break;
  824. case HDMI_COLORIMETRY_ITU_601:
  825. c.colorspace = V4L2_COLORSPACE_SMPTE170M;
  826. c.ycbcr_enc = V4L2_YCBCR_ENC_601;
  827. c.xfer_func = V4L2_XFER_FUNC_709;
  828. break;
  829. case HDMI_COLORIMETRY_ITU_709:
  830. c.colorspace = V4L2_COLORSPACE_REC709;
  831. c.ycbcr_enc = V4L2_YCBCR_ENC_709;
  832. c.xfer_func = V4L2_XFER_FUNC_709;
  833. break;
  834. case HDMI_COLORIMETRY_EXTENDED:
  835. switch (avi->extended_colorimetry) {
  836. case HDMI_EXTENDED_COLORIMETRY_XV_YCC_601:
  837. c.colorspace = V4L2_COLORSPACE_REC709;
  838. c.ycbcr_enc = V4L2_YCBCR_ENC_XV709;
  839. c.xfer_func = V4L2_XFER_FUNC_709;
  840. break;
  841. case HDMI_EXTENDED_COLORIMETRY_XV_YCC_709:
  842. c.colorspace = V4L2_COLORSPACE_REC709;
  843. c.ycbcr_enc = V4L2_YCBCR_ENC_XV601;
  844. c.xfer_func = V4L2_XFER_FUNC_709;
  845. break;
  846. case HDMI_EXTENDED_COLORIMETRY_S_YCC_601:
  847. c.colorspace = V4L2_COLORSPACE_SRGB;
  848. c.ycbcr_enc = V4L2_YCBCR_ENC_601;
  849. c.xfer_func = V4L2_XFER_FUNC_SRGB;
  850. break;
  851. case HDMI_EXTENDED_COLORIMETRY_ADOBE_YCC_601:
  852. c.colorspace = V4L2_COLORSPACE_ADOBERGB;
  853. c.ycbcr_enc = V4L2_YCBCR_ENC_601;
  854. c.xfer_func = V4L2_XFER_FUNC_ADOBERGB;
  855. break;
  856. case HDMI_EXTENDED_COLORIMETRY_BT2020:
  857. c.colorspace = V4L2_COLORSPACE_BT2020;
  858. c.ycbcr_enc = V4L2_YCBCR_ENC_BT2020;
  859. c.xfer_func = V4L2_XFER_FUNC_709;
  860. break;
  861. case HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM:
  862. c.colorspace = V4L2_COLORSPACE_BT2020;
  863. c.ycbcr_enc = V4L2_YCBCR_ENC_BT2020_CONST_LUM;
  864. c.xfer_func = V4L2_XFER_FUNC_709;
  865. break;
  866. default: /* fall back to ITU_709 */
  867. c.colorspace = V4L2_COLORSPACE_REC709;
  868. c.ycbcr_enc = V4L2_YCBCR_ENC_709;
  869. c.xfer_func = V4L2_XFER_FUNC_709;
  870. break;
  871. }
  872. break;
  873. default:
  874. break;
  875. }
  876. /*
  877. * YCC Quantization Range signaling is more-or-less broken,
  878. * let's just ignore this.
  879. */
  880. break;
  881. }
  882. return c;
  883. }
  884. EXPORT_SYMBOL_GPL(v4l2_hdmi_rx_colorimetry);