vivid-vid-common.c 23 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * vivid-vid-common.c - common video support functions.
  4. *
  5. * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  6. */
  7. #include <linux/errno.h>
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <linux/videodev2.h>
  11. #include <linux/v4l2-dv-timings.h>
  12. #include <media/v4l2-common.h>
  13. #include <media/v4l2-event.h>
  14. #include <media/v4l2-dv-timings.h>
  15. #include "vivid-core.h"
  16. #include "vivid-vid-common.h"
  17. const struct v4l2_dv_timings_cap vivid_dv_timings_cap = {
  18. .type = V4L2_DV_BT_656_1120,
  19. /* keep this initialization for compatibility with GCC < 4.4.6 */
  20. .reserved = { 0 },
  21. V4L2_INIT_BT_TIMINGS(16, MAX_WIDTH, 16, MAX_HEIGHT, 14000000, 775000000,
  22. V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
  23. V4L2_DV_BT_STD_CVT | V4L2_DV_BT_STD_GTF,
  24. V4L2_DV_BT_CAP_PROGRESSIVE | V4L2_DV_BT_CAP_INTERLACED)
  25. };
  26. /* ------------------------------------------------------------------
  27. Basic structures
  28. ------------------------------------------------------------------*/
  29. struct vivid_fmt vivid_formats[] = {
  30. {
  31. .fourcc = V4L2_PIX_FMT_YUYV,
  32. .vdownsampling = { 1 },
  33. .bit_depth = { 16 },
  34. .color_enc = TGP_COLOR_ENC_YCBCR,
  35. .planes = 1,
  36. .buffers = 1,
  37. .data_offset = { PLANE0_DATA_OFFSET },
  38. },
  39. {
  40. .fourcc = V4L2_PIX_FMT_UYVY,
  41. .vdownsampling = { 1 },
  42. .bit_depth = { 16 },
  43. .color_enc = TGP_COLOR_ENC_YCBCR,
  44. .planes = 1,
  45. .buffers = 1,
  46. },
  47. {
  48. .fourcc = V4L2_PIX_FMT_YVYU,
  49. .vdownsampling = { 1 },
  50. .bit_depth = { 16 },
  51. .color_enc = TGP_COLOR_ENC_YCBCR,
  52. .planes = 1,
  53. .buffers = 1,
  54. },
  55. {
  56. .fourcc = V4L2_PIX_FMT_VYUY,
  57. .vdownsampling = { 1 },
  58. .bit_depth = { 16 },
  59. .color_enc = TGP_COLOR_ENC_YCBCR,
  60. .planes = 1,
  61. .buffers = 1,
  62. },
  63. {
  64. .fourcc = V4L2_PIX_FMT_YUV422P,
  65. .vdownsampling = { 1, 1, 1 },
  66. .bit_depth = { 8, 4, 4 },
  67. .color_enc = TGP_COLOR_ENC_YCBCR,
  68. .planes = 3,
  69. .buffers = 1,
  70. },
  71. {
  72. .fourcc = V4L2_PIX_FMT_YUV420,
  73. .vdownsampling = { 1, 2, 2 },
  74. .bit_depth = { 8, 4, 4 },
  75. .color_enc = TGP_COLOR_ENC_YCBCR,
  76. .planes = 3,
  77. .buffers = 1,
  78. },
  79. {
  80. .fourcc = V4L2_PIX_FMT_YVU420,
  81. .vdownsampling = { 1, 2, 2 },
  82. .bit_depth = { 8, 4, 4 },
  83. .color_enc = TGP_COLOR_ENC_YCBCR,
  84. .planes = 3,
  85. .buffers = 1,
  86. },
  87. {
  88. .fourcc = V4L2_PIX_FMT_NV12,
  89. .vdownsampling = { 1, 2 },
  90. .bit_depth = { 8, 8 },
  91. .color_enc = TGP_COLOR_ENC_YCBCR,
  92. .planes = 2,
  93. .buffers = 1,
  94. },
  95. {
  96. .fourcc = V4L2_PIX_FMT_NV21,
  97. .vdownsampling = { 1, 2 },
  98. .bit_depth = { 8, 8 },
  99. .color_enc = TGP_COLOR_ENC_YCBCR,
  100. .planes = 2,
  101. .buffers = 1,
  102. },
  103. {
  104. .fourcc = V4L2_PIX_FMT_NV16,
  105. .vdownsampling = { 1, 1 },
  106. .bit_depth = { 8, 8 },
  107. .color_enc = TGP_COLOR_ENC_YCBCR,
  108. .planes = 2,
  109. .buffers = 1,
  110. },
  111. {
  112. .fourcc = V4L2_PIX_FMT_NV61,
  113. .vdownsampling = { 1, 1 },
  114. .bit_depth = { 8, 8 },
  115. .color_enc = TGP_COLOR_ENC_YCBCR,
  116. .planes = 2,
  117. .buffers = 1,
  118. },
  119. {
  120. .fourcc = V4L2_PIX_FMT_NV24,
  121. .vdownsampling = { 1, 1 },
  122. .bit_depth = { 8, 16 },
  123. .color_enc = TGP_COLOR_ENC_YCBCR,
  124. .planes = 2,
  125. .buffers = 1,
  126. },
  127. {
  128. .fourcc = V4L2_PIX_FMT_NV42,
  129. .vdownsampling = { 1, 1 },
  130. .bit_depth = { 8, 16 },
  131. .color_enc = TGP_COLOR_ENC_YCBCR,
  132. .planes = 2,
  133. .buffers = 1,
  134. },
  135. {
  136. .fourcc = V4L2_PIX_FMT_YUV555, /* uuuvvvvv ayyyyyuu */
  137. .vdownsampling = { 1 },
  138. .bit_depth = { 16 },
  139. .planes = 1,
  140. .buffers = 1,
  141. .alpha_mask = 0x8000,
  142. },
  143. {
  144. .fourcc = V4L2_PIX_FMT_YUV565, /* uuuvvvvv yyyyyuuu */
  145. .vdownsampling = { 1 },
  146. .bit_depth = { 16 },
  147. .planes = 1,
  148. .buffers = 1,
  149. },
  150. {
  151. .fourcc = V4L2_PIX_FMT_YUV444, /* uuuuvvvv aaaayyyy */
  152. .vdownsampling = { 1 },
  153. .bit_depth = { 16 },
  154. .planes = 1,
  155. .buffers = 1,
  156. .alpha_mask = 0xf000,
  157. },
  158. {
  159. .fourcc = V4L2_PIX_FMT_YUV32, /* ayuv */
  160. .vdownsampling = { 1 },
  161. .bit_depth = { 32 },
  162. .planes = 1,
  163. .buffers = 1,
  164. .alpha_mask = 0x000000ff,
  165. },
  166. {
  167. .fourcc = V4L2_PIX_FMT_AYUV32,
  168. .vdownsampling = { 1 },
  169. .bit_depth = { 32 },
  170. .planes = 1,
  171. .buffers = 1,
  172. .alpha_mask = 0x000000ff,
  173. },
  174. {
  175. .fourcc = V4L2_PIX_FMT_XYUV32,
  176. .vdownsampling = { 1 },
  177. .bit_depth = { 32 },
  178. .planes = 1,
  179. .buffers = 1,
  180. },
  181. {
  182. .fourcc = V4L2_PIX_FMT_VUYA32,
  183. .vdownsampling = { 1 },
  184. .bit_depth = { 32 },
  185. .planes = 1,
  186. .buffers = 1,
  187. .alpha_mask = 0xff000000,
  188. },
  189. {
  190. .fourcc = V4L2_PIX_FMT_VUYX32,
  191. .vdownsampling = { 1 },
  192. .bit_depth = { 32 },
  193. .planes = 1,
  194. .buffers = 1,
  195. },
  196. {
  197. .fourcc = V4L2_PIX_FMT_GREY,
  198. .vdownsampling = { 1 },
  199. .bit_depth = { 8 },
  200. .color_enc = TGP_COLOR_ENC_LUMA,
  201. .planes = 1,
  202. .buffers = 1,
  203. },
  204. {
  205. .fourcc = V4L2_PIX_FMT_Y10,
  206. .vdownsampling = { 1 },
  207. .bit_depth = { 16 },
  208. .color_enc = TGP_COLOR_ENC_LUMA,
  209. .planes = 1,
  210. .buffers = 1,
  211. },
  212. {
  213. .fourcc = V4L2_PIX_FMT_Y12,
  214. .vdownsampling = { 1 },
  215. .bit_depth = { 16 },
  216. .color_enc = TGP_COLOR_ENC_LUMA,
  217. .planes = 1,
  218. .buffers = 1,
  219. },
  220. {
  221. .fourcc = V4L2_PIX_FMT_Y16,
  222. .vdownsampling = { 1 },
  223. .bit_depth = { 16 },
  224. .color_enc = TGP_COLOR_ENC_LUMA,
  225. .planes = 1,
  226. .buffers = 1,
  227. },
  228. {
  229. .fourcc = V4L2_PIX_FMT_Y16_BE,
  230. .vdownsampling = { 1 },
  231. .bit_depth = { 16 },
  232. .color_enc = TGP_COLOR_ENC_LUMA,
  233. .planes = 1,
  234. .buffers = 1,
  235. },
  236. {
  237. .fourcc = V4L2_PIX_FMT_RGB332, /* rrrgggbb */
  238. .vdownsampling = { 1 },
  239. .bit_depth = { 8 },
  240. .planes = 1,
  241. .buffers = 1,
  242. },
  243. {
  244. .fourcc = V4L2_PIX_FMT_RGB565, /* gggbbbbb rrrrrggg */
  245. .vdownsampling = { 1 },
  246. .bit_depth = { 16 },
  247. .planes = 1,
  248. .buffers = 1,
  249. .can_do_overlay = true,
  250. },
  251. {
  252. .fourcc = V4L2_PIX_FMT_RGB565X, /* rrrrrggg gggbbbbb */
  253. .vdownsampling = { 1 },
  254. .bit_depth = { 16 },
  255. .planes = 1,
  256. .buffers = 1,
  257. .can_do_overlay = true,
  258. },
  259. {
  260. .fourcc = V4L2_PIX_FMT_RGB444, /* ggggbbbb xxxxrrrr */
  261. .vdownsampling = { 1 },
  262. .bit_depth = { 16 },
  263. .planes = 1,
  264. .buffers = 1,
  265. },
  266. {
  267. .fourcc = V4L2_PIX_FMT_XRGB444, /* ggggbbbb xxxxrrrr */
  268. .vdownsampling = { 1 },
  269. .bit_depth = { 16 },
  270. .planes = 1,
  271. .buffers = 1,
  272. },
  273. {
  274. .fourcc = V4L2_PIX_FMT_ARGB444, /* ggggbbbb aaaarrrr */
  275. .vdownsampling = { 1 },
  276. .bit_depth = { 16 },
  277. .planes = 1,
  278. .buffers = 1,
  279. .alpha_mask = 0x00f0,
  280. },
  281. {
  282. .fourcc = V4L2_PIX_FMT_RGBX444, /* bbbbxxxx rrrrgggg */
  283. .vdownsampling = { 1 },
  284. .bit_depth = { 16 },
  285. .planes = 1,
  286. .buffers = 1,
  287. },
  288. {
  289. .fourcc = V4L2_PIX_FMT_RGBA444, /* bbbbaaaa rrrrgggg */
  290. .vdownsampling = { 1 },
  291. .bit_depth = { 16 },
  292. .planes = 1,
  293. .buffers = 1,
  294. .alpha_mask = 0x00f0,
  295. },
  296. {
  297. .fourcc = V4L2_PIX_FMT_XBGR444, /* ggggrrrr xxxxbbbb */
  298. .vdownsampling = { 1 },
  299. .bit_depth = { 16 },
  300. .planes = 1,
  301. .buffers = 1,
  302. },
  303. {
  304. .fourcc = V4L2_PIX_FMT_ABGR444, /* ggggrrrr aaaabbbb */
  305. .vdownsampling = { 1 },
  306. .bit_depth = { 16 },
  307. .planes = 1,
  308. .buffers = 1,
  309. .alpha_mask = 0x00f0,
  310. },
  311. {
  312. .fourcc = V4L2_PIX_FMT_BGRX444, /* rrrrxxxx bbbbgggg */
  313. .vdownsampling = { 1 },
  314. .bit_depth = { 16 },
  315. .planes = 1,
  316. .buffers = 1,
  317. },
  318. {
  319. .fourcc = V4L2_PIX_FMT_BGRA444, /* rrrraaaa bbbbgggg */
  320. .vdownsampling = { 1 },
  321. .bit_depth = { 16 },
  322. .planes = 1,
  323. .buffers = 1,
  324. .alpha_mask = 0x00f0,
  325. },
  326. {
  327. .fourcc = V4L2_PIX_FMT_RGB555, /* gggbbbbb xrrrrrgg */
  328. .vdownsampling = { 1 },
  329. .bit_depth = { 16 },
  330. .planes = 1,
  331. .buffers = 1,
  332. .can_do_overlay = true,
  333. },
  334. {
  335. .fourcc = V4L2_PIX_FMT_XRGB555, /* gggbbbbb xrrrrrgg */
  336. .vdownsampling = { 1 },
  337. .bit_depth = { 16 },
  338. .planes = 1,
  339. .buffers = 1,
  340. .can_do_overlay = true,
  341. },
  342. {
  343. .fourcc = V4L2_PIX_FMT_ARGB555, /* gggbbbbb arrrrrgg */
  344. .vdownsampling = { 1 },
  345. .bit_depth = { 16 },
  346. .planes = 1,
  347. .buffers = 1,
  348. .can_do_overlay = true,
  349. .alpha_mask = 0x8000,
  350. },
  351. {
  352. .fourcc = V4L2_PIX_FMT_RGBX555, /* ggbbbbbx rrrrrggg */
  353. .vdownsampling = { 1 },
  354. .bit_depth = { 16 },
  355. .planes = 1,
  356. .buffers = 1,
  357. .can_do_overlay = true,
  358. },
  359. {
  360. .fourcc = V4L2_PIX_FMT_RGBA555, /* ggbbbbba rrrrrggg */
  361. .vdownsampling = { 1 },
  362. .bit_depth = { 16 },
  363. .planes = 1,
  364. .buffers = 1,
  365. .can_do_overlay = true,
  366. .alpha_mask = 0x8000,
  367. },
  368. {
  369. .fourcc = V4L2_PIX_FMT_XBGR555, /* gggrrrrr xbbbbbgg */
  370. .vdownsampling = { 1 },
  371. .bit_depth = { 16 },
  372. .planes = 1,
  373. .buffers = 1,
  374. .can_do_overlay = true,
  375. },
  376. {
  377. .fourcc = V4L2_PIX_FMT_ABGR555, /* gggrrrrr abbbbbgg */
  378. .vdownsampling = { 1 },
  379. .bit_depth = { 16 },
  380. .planes = 1,
  381. .buffers = 1,
  382. .can_do_overlay = true,
  383. .alpha_mask = 0x8000,
  384. },
  385. {
  386. .fourcc = V4L2_PIX_FMT_BGRX555, /* ggrrrrrx bbbbbggg */
  387. .vdownsampling = { 1 },
  388. .bit_depth = { 16 },
  389. .planes = 1,
  390. .buffers = 1,
  391. .can_do_overlay = true,
  392. },
  393. {
  394. .fourcc = V4L2_PIX_FMT_BGRA555, /* ggrrrrra bbbbbggg */
  395. .vdownsampling = { 1 },
  396. .bit_depth = { 16 },
  397. .planes = 1,
  398. .buffers = 1,
  399. .can_do_overlay = true,
  400. .alpha_mask = 0x8000,
  401. },
  402. {
  403. .fourcc = V4L2_PIX_FMT_RGB555X, /* xrrrrrgg gggbbbbb */
  404. .vdownsampling = { 1 },
  405. .bit_depth = { 16 },
  406. .planes = 1,
  407. .buffers = 1,
  408. },
  409. {
  410. .fourcc = V4L2_PIX_FMT_XRGB555X, /* xrrrrrgg gggbbbbb */
  411. .vdownsampling = { 1 },
  412. .bit_depth = { 16 },
  413. .planes = 1,
  414. .buffers = 1,
  415. },
  416. {
  417. .fourcc = V4L2_PIX_FMT_ARGB555X, /* arrrrrgg gggbbbbb */
  418. .vdownsampling = { 1 },
  419. .bit_depth = { 16 },
  420. .planes = 1,
  421. .buffers = 1,
  422. .alpha_mask = 0x0080,
  423. },
  424. {
  425. .fourcc = V4L2_PIX_FMT_RGB24, /* rgb */
  426. .vdownsampling = { 1 },
  427. .bit_depth = { 24 },
  428. .planes = 1,
  429. .buffers = 1,
  430. },
  431. {
  432. .fourcc = V4L2_PIX_FMT_BGR24, /* bgr */
  433. .vdownsampling = { 1 },
  434. .bit_depth = { 24 },
  435. .planes = 1,
  436. .buffers = 1,
  437. },
  438. {
  439. .fourcc = V4L2_PIX_FMT_BGR666, /* bbbbbbgg ggggrrrr rrxxxxxx */
  440. .vdownsampling = { 1 },
  441. .bit_depth = { 32 },
  442. .planes = 1,
  443. .buffers = 1,
  444. },
  445. {
  446. .fourcc = V4L2_PIX_FMT_RGB32, /* xrgb */
  447. .vdownsampling = { 1 },
  448. .bit_depth = { 32 },
  449. .planes = 1,
  450. .buffers = 1,
  451. },
  452. {
  453. .fourcc = V4L2_PIX_FMT_BGR32, /* bgrx */
  454. .vdownsampling = { 1 },
  455. .bit_depth = { 32 },
  456. .planes = 1,
  457. .buffers = 1,
  458. },
  459. {
  460. .fourcc = V4L2_PIX_FMT_XRGB32, /* xrgb */
  461. .vdownsampling = { 1 },
  462. .bit_depth = { 32 },
  463. .planes = 1,
  464. .buffers = 1,
  465. },
  466. {
  467. .fourcc = V4L2_PIX_FMT_XBGR32, /* bgrx */
  468. .vdownsampling = { 1 },
  469. .bit_depth = { 32 },
  470. .planes = 1,
  471. .buffers = 1,
  472. },
  473. {
  474. .fourcc = V4L2_PIX_FMT_ARGB32, /* argb */
  475. .vdownsampling = { 1 },
  476. .bit_depth = { 32 },
  477. .planes = 1,
  478. .buffers = 1,
  479. .alpha_mask = 0x000000ff,
  480. },
  481. {
  482. .fourcc = V4L2_PIX_FMT_ABGR32, /* bgra */
  483. .vdownsampling = { 1 },
  484. .bit_depth = { 32 },
  485. .planes = 1,
  486. .buffers = 1,
  487. .alpha_mask = 0xff000000,
  488. },
  489. {
  490. .fourcc = V4L2_PIX_FMT_RGBX32, /* rgbx */
  491. .vdownsampling = { 1 },
  492. .bit_depth = { 32 },
  493. .planes = 1,
  494. .buffers = 1,
  495. },
  496. {
  497. .fourcc = V4L2_PIX_FMT_BGRX32, /* xbgr */
  498. .vdownsampling = { 1 },
  499. .bit_depth = { 32 },
  500. .planes = 1,
  501. .buffers = 1,
  502. },
  503. {
  504. .fourcc = V4L2_PIX_FMT_RGBA32, /* rgba */
  505. .vdownsampling = { 1 },
  506. .bit_depth = { 32 },
  507. .planes = 1,
  508. .buffers = 1,
  509. .alpha_mask = 0x000000ff,
  510. },
  511. {
  512. .fourcc = V4L2_PIX_FMT_BGRA32, /* abgr */
  513. .vdownsampling = { 1 },
  514. .bit_depth = { 32 },
  515. .planes = 1,
  516. .buffers = 1,
  517. .alpha_mask = 0xff000000,
  518. },
  519. {
  520. .fourcc = V4L2_PIX_FMT_SBGGR8, /* Bayer BG/GR */
  521. .vdownsampling = { 1 },
  522. .bit_depth = { 8 },
  523. .planes = 1,
  524. .buffers = 1,
  525. },
  526. {
  527. .fourcc = V4L2_PIX_FMT_SGBRG8, /* Bayer GB/RG */
  528. .vdownsampling = { 1 },
  529. .bit_depth = { 8 },
  530. .planes = 1,
  531. .buffers = 1,
  532. },
  533. {
  534. .fourcc = V4L2_PIX_FMT_SGRBG8, /* Bayer GR/BG */
  535. .vdownsampling = { 1 },
  536. .bit_depth = { 8 },
  537. .planes = 1,
  538. .buffers = 1,
  539. },
  540. {
  541. .fourcc = V4L2_PIX_FMT_SRGGB8, /* Bayer RG/GB */
  542. .vdownsampling = { 1 },
  543. .bit_depth = { 8 },
  544. .planes = 1,
  545. .buffers = 1,
  546. },
  547. {
  548. .fourcc = V4L2_PIX_FMT_SBGGR10, /* Bayer BG/GR */
  549. .vdownsampling = { 1 },
  550. .bit_depth = { 16 },
  551. .planes = 1,
  552. .buffers = 1,
  553. },
  554. {
  555. .fourcc = V4L2_PIX_FMT_SGBRG10, /* Bayer GB/RG */
  556. .vdownsampling = { 1 },
  557. .bit_depth = { 16 },
  558. .planes = 1,
  559. .buffers = 1,
  560. },
  561. {
  562. .fourcc = V4L2_PIX_FMT_SGRBG10, /* Bayer GR/BG */
  563. .vdownsampling = { 1 },
  564. .bit_depth = { 16 },
  565. .planes = 1,
  566. .buffers = 1,
  567. },
  568. {
  569. .fourcc = V4L2_PIX_FMT_SRGGB10, /* Bayer RG/GB */
  570. .vdownsampling = { 1 },
  571. .bit_depth = { 16 },
  572. .planes = 1,
  573. .buffers = 1,
  574. },
  575. {
  576. .fourcc = V4L2_PIX_FMT_SBGGR12, /* Bayer BG/GR */
  577. .vdownsampling = { 1 },
  578. .bit_depth = { 16 },
  579. .planes = 1,
  580. .buffers = 1,
  581. },
  582. {
  583. .fourcc = V4L2_PIX_FMT_SGBRG12, /* Bayer GB/RG */
  584. .vdownsampling = { 1 },
  585. .bit_depth = { 16 },
  586. .planes = 1,
  587. .buffers = 1,
  588. },
  589. {
  590. .fourcc = V4L2_PIX_FMT_SGRBG12, /* Bayer GR/BG */
  591. .vdownsampling = { 1 },
  592. .bit_depth = { 16 },
  593. .planes = 1,
  594. .buffers = 1,
  595. },
  596. {
  597. .fourcc = V4L2_PIX_FMT_SRGGB12, /* Bayer RG/GB */
  598. .vdownsampling = { 1 },
  599. .bit_depth = { 16 },
  600. .planes = 1,
  601. .buffers = 1,
  602. },
  603. {
  604. .fourcc = V4L2_PIX_FMT_SBGGR16, /* Bayer BG/GR */
  605. .vdownsampling = { 1 },
  606. .bit_depth = { 16 },
  607. .planes = 1,
  608. .buffers = 1,
  609. },
  610. {
  611. .fourcc = V4L2_PIX_FMT_SGBRG16, /* Bayer GB/RG */
  612. .vdownsampling = { 1 },
  613. .bit_depth = { 16 },
  614. .planes = 1,
  615. .buffers = 1,
  616. },
  617. {
  618. .fourcc = V4L2_PIX_FMT_SGRBG16, /* Bayer GR/BG */
  619. .vdownsampling = { 1 },
  620. .bit_depth = { 16 },
  621. .planes = 1,
  622. .buffers = 1,
  623. },
  624. {
  625. .fourcc = V4L2_PIX_FMT_SRGGB16, /* Bayer RG/GB */
  626. .vdownsampling = { 1 },
  627. .bit_depth = { 16 },
  628. .planes = 1,
  629. .buffers = 1,
  630. },
  631. {
  632. .fourcc = V4L2_PIX_FMT_HSV24, /* HSV 24bits */
  633. .color_enc = TGP_COLOR_ENC_HSV,
  634. .vdownsampling = { 1 },
  635. .bit_depth = { 24 },
  636. .planes = 1,
  637. .buffers = 1,
  638. },
  639. {
  640. .fourcc = V4L2_PIX_FMT_HSV32, /* HSV 32bits */
  641. .color_enc = TGP_COLOR_ENC_HSV,
  642. .vdownsampling = { 1 },
  643. .bit_depth = { 32 },
  644. .planes = 1,
  645. .buffers = 1,
  646. },
  647. /* Multiplanar formats */
  648. {
  649. .fourcc = V4L2_PIX_FMT_NV16M,
  650. .vdownsampling = { 1, 1 },
  651. .bit_depth = { 8, 8 },
  652. .color_enc = TGP_COLOR_ENC_YCBCR,
  653. .planes = 2,
  654. .buffers = 2,
  655. .data_offset = { PLANE0_DATA_OFFSET, 0 },
  656. },
  657. {
  658. .fourcc = V4L2_PIX_FMT_NV61M,
  659. .vdownsampling = { 1, 1 },
  660. .bit_depth = { 8, 8 },
  661. .color_enc = TGP_COLOR_ENC_YCBCR,
  662. .planes = 2,
  663. .buffers = 2,
  664. .data_offset = { 0, PLANE0_DATA_OFFSET },
  665. },
  666. {
  667. .fourcc = V4L2_PIX_FMT_YUV420M,
  668. .vdownsampling = { 1, 2, 2 },
  669. .bit_depth = { 8, 4, 4 },
  670. .color_enc = TGP_COLOR_ENC_YCBCR,
  671. .planes = 3,
  672. .buffers = 3,
  673. },
  674. {
  675. .fourcc = V4L2_PIX_FMT_YVU420M,
  676. .vdownsampling = { 1, 2, 2 },
  677. .bit_depth = { 8, 4, 4 },
  678. .color_enc = TGP_COLOR_ENC_YCBCR,
  679. .planes = 3,
  680. .buffers = 3,
  681. },
  682. {
  683. .fourcc = V4L2_PIX_FMT_NV12M,
  684. .vdownsampling = { 1, 2 },
  685. .bit_depth = { 8, 8 },
  686. .color_enc = TGP_COLOR_ENC_YCBCR,
  687. .planes = 2,
  688. .buffers = 2,
  689. },
  690. {
  691. .fourcc = V4L2_PIX_FMT_NV21M,
  692. .vdownsampling = { 1, 2 },
  693. .bit_depth = { 8, 8 },
  694. .color_enc = TGP_COLOR_ENC_YCBCR,
  695. .planes = 2,
  696. .buffers = 2,
  697. },
  698. {
  699. .fourcc = V4L2_PIX_FMT_YUV422M,
  700. .vdownsampling = { 1, 1, 1 },
  701. .bit_depth = { 8, 4, 4 },
  702. .color_enc = TGP_COLOR_ENC_YCBCR,
  703. .planes = 3,
  704. .buffers = 3,
  705. },
  706. {
  707. .fourcc = V4L2_PIX_FMT_YVU422M,
  708. .vdownsampling = { 1, 1, 1 },
  709. .bit_depth = { 8, 4, 4 },
  710. .color_enc = TGP_COLOR_ENC_YCBCR,
  711. .planes = 3,
  712. .buffers = 3,
  713. },
  714. {
  715. .fourcc = V4L2_PIX_FMT_YUV444M,
  716. .vdownsampling = { 1, 1, 1 },
  717. .bit_depth = { 8, 8, 8 },
  718. .color_enc = TGP_COLOR_ENC_YCBCR,
  719. .planes = 3,
  720. .buffers = 3,
  721. },
  722. {
  723. .fourcc = V4L2_PIX_FMT_YVU444M,
  724. .vdownsampling = { 1, 1, 1 },
  725. .bit_depth = { 8, 8, 8 },
  726. .color_enc = TGP_COLOR_ENC_YCBCR,
  727. .planes = 3,
  728. .buffers = 3,
  729. },
  730. };
  731. /* There are this many multiplanar formats in the list */
  732. #define VIVID_MPLANAR_FORMATS 10
  733. const struct vivid_fmt *vivid_get_format(struct vivid_dev *dev, u32 pixelformat)
  734. {
  735. const struct vivid_fmt *fmt;
  736. unsigned k;
  737. for (k = 0; k < ARRAY_SIZE(vivid_formats); k++) {
  738. fmt = &vivid_formats[k];
  739. if (fmt->fourcc == pixelformat)
  740. if (fmt->buffers == 1 || dev->multiplanar)
  741. return fmt;
  742. }
  743. return NULL;
  744. }
  745. bool vivid_vid_can_loop(struct vivid_dev *dev)
  746. {
  747. if (dev->src_rect.width != dev->sink_rect.width ||
  748. dev->src_rect.height != dev->sink_rect.height)
  749. return false;
  750. if (dev->fmt_cap->fourcc != dev->fmt_out->fourcc)
  751. return false;
  752. if (dev->field_cap != dev->field_out)
  753. return false;
  754. /*
  755. * While this can be supported, it is just too much work
  756. * to actually implement.
  757. */
  758. if (dev->field_cap == V4L2_FIELD_SEQ_TB ||
  759. dev->field_cap == V4L2_FIELD_SEQ_BT)
  760. return false;
  761. if (vivid_is_svid_cap(dev) && vivid_is_svid_out(dev)) {
  762. if (!(dev->std_cap[dev->input] & V4L2_STD_525_60) !=
  763. !(dev->std_out & V4L2_STD_525_60))
  764. return false;
  765. return true;
  766. }
  767. if (vivid_is_hdmi_cap(dev) && vivid_is_hdmi_out(dev))
  768. return true;
  769. return false;
  770. }
  771. void vivid_send_source_change(struct vivid_dev *dev, unsigned type)
  772. {
  773. struct v4l2_event ev = {
  774. .type = V4L2_EVENT_SOURCE_CHANGE,
  775. .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
  776. };
  777. unsigned i;
  778. for (i = 0; i < dev->num_inputs; i++) {
  779. ev.id = i;
  780. if (dev->input_type[i] == type) {
  781. if (video_is_registered(&dev->vid_cap_dev) && dev->has_vid_cap)
  782. v4l2_event_queue(&dev->vid_cap_dev, &ev);
  783. if (video_is_registered(&dev->vbi_cap_dev) && dev->has_vbi_cap)
  784. v4l2_event_queue(&dev->vbi_cap_dev, &ev);
  785. }
  786. }
  787. }
  788. /*
  789. * Conversion function that converts a single-planar format to a
  790. * single-plane multiplanar format.
  791. */
  792. void fmt_sp2mp(const struct v4l2_format *sp_fmt, struct v4l2_format *mp_fmt)
  793. {
  794. struct v4l2_pix_format_mplane *mp = &mp_fmt->fmt.pix_mp;
  795. struct v4l2_plane_pix_format *ppix = &mp->plane_fmt[0];
  796. const struct v4l2_pix_format *pix = &sp_fmt->fmt.pix;
  797. bool is_out = sp_fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT;
  798. memset(mp->reserved, 0, sizeof(mp->reserved));
  799. mp_fmt->type = is_out ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE :
  800. V4L2_CAP_VIDEO_CAPTURE_MPLANE;
  801. mp->width = pix->width;
  802. mp->height = pix->height;
  803. mp->pixelformat = pix->pixelformat;
  804. mp->field = pix->field;
  805. mp->colorspace = pix->colorspace;
  806. mp->xfer_func = pix->xfer_func;
  807. /* Also copies hsv_enc */
  808. mp->ycbcr_enc = pix->ycbcr_enc;
  809. mp->quantization = pix->quantization;
  810. mp->num_planes = 1;
  811. mp->flags = pix->flags;
  812. ppix->sizeimage = pix->sizeimage;
  813. ppix->bytesperline = pix->bytesperline;
  814. memset(ppix->reserved, 0, sizeof(ppix->reserved));
  815. }
  816. int fmt_sp2mp_func(struct file *file, void *priv,
  817. struct v4l2_format *f, fmtfunc func)
  818. {
  819. struct v4l2_format fmt;
  820. struct v4l2_pix_format_mplane *mp = &fmt.fmt.pix_mp;
  821. struct v4l2_plane_pix_format *ppix = &mp->plane_fmt[0];
  822. struct v4l2_pix_format *pix = &f->fmt.pix;
  823. int ret;
  824. /* Converts to a mplane format */
  825. fmt_sp2mp(f, &fmt);
  826. /* Passes it to the generic mplane format function */
  827. ret = func(file, priv, &fmt);
  828. /* Copies back the mplane data to the single plane format */
  829. pix->width = mp->width;
  830. pix->height = mp->height;
  831. pix->pixelformat = mp->pixelformat;
  832. pix->field = mp->field;
  833. pix->colorspace = mp->colorspace;
  834. pix->xfer_func = mp->xfer_func;
  835. /* Also copies hsv_enc */
  836. pix->ycbcr_enc = mp->ycbcr_enc;
  837. pix->quantization = mp->quantization;
  838. pix->sizeimage = ppix->sizeimage;
  839. pix->bytesperline = ppix->bytesperline;
  840. pix->flags = mp->flags;
  841. return ret;
  842. }
  843. int vivid_vid_adjust_sel(unsigned flags, struct v4l2_rect *r)
  844. {
  845. unsigned w = r->width;
  846. unsigned h = r->height;
  847. /* sanitize w and h in case someone passes ~0 as the value */
  848. w &= 0xffff;
  849. h &= 0xffff;
  850. if (!(flags & V4L2_SEL_FLAG_LE)) {
  851. w++;
  852. h++;
  853. if (w < 2)
  854. w = 2;
  855. if (h < 2)
  856. h = 2;
  857. }
  858. if (!(flags & V4L2_SEL_FLAG_GE)) {
  859. if (w > MAX_WIDTH)
  860. w = MAX_WIDTH;
  861. if (h > MAX_HEIGHT)
  862. h = MAX_HEIGHT;
  863. }
  864. w = w & ~1;
  865. h = h & ~1;
  866. if (w < 2 || h < 2)
  867. return -ERANGE;
  868. if (w > MAX_WIDTH || h > MAX_HEIGHT)
  869. return -ERANGE;
  870. if (r->top < 0)
  871. r->top = 0;
  872. if (r->left < 0)
  873. r->left = 0;
  874. /* sanitize left and top in case someone passes ~0 as the value */
  875. r->left &= 0xfffe;
  876. r->top &= 0xfffe;
  877. if (r->left + w > MAX_WIDTH)
  878. r->left = MAX_WIDTH - w;
  879. if (r->top + h > MAX_HEIGHT)
  880. r->top = MAX_HEIGHT - h;
  881. if ((flags & (V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE)) ==
  882. (V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE) &&
  883. (r->width != w || r->height != h))
  884. return -ERANGE;
  885. r->width = w;
  886. r->height = h;
  887. return 0;
  888. }
  889. int vivid_enum_fmt_vid(struct file *file, void *priv,
  890. struct v4l2_fmtdesc *f)
  891. {
  892. struct vivid_dev *dev = video_drvdata(file);
  893. const struct vivid_fmt *fmt;
  894. if (f->index >= ARRAY_SIZE(vivid_formats) -
  895. (dev->multiplanar ? 0 : VIVID_MPLANAR_FORMATS))
  896. return -EINVAL;
  897. fmt = &vivid_formats[f->index];
  898. f->pixelformat = fmt->fourcc;
  899. return 0;
  900. }
  901. int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
  902. {
  903. struct vivid_dev *dev = video_drvdata(file);
  904. struct video_device *vdev = video_devdata(file);
  905. if (vdev->vfl_dir == VFL_DIR_RX) {
  906. if (!vivid_is_sdtv_cap(dev))
  907. return -ENODATA;
  908. *id = dev->std_cap[dev->input];
  909. } else {
  910. if (!vivid_is_svid_out(dev))
  911. return -ENODATA;
  912. *id = dev->std_out;
  913. }
  914. return 0;
  915. }
  916. int vidioc_g_dv_timings(struct file *file, void *_fh,
  917. struct v4l2_dv_timings *timings)
  918. {
  919. struct vivid_dev *dev = video_drvdata(file);
  920. struct video_device *vdev = video_devdata(file);
  921. if (vdev->vfl_dir == VFL_DIR_RX) {
  922. if (!vivid_is_hdmi_cap(dev))
  923. return -ENODATA;
  924. *timings = dev->dv_timings_cap[dev->input];
  925. } else {
  926. if (!vivid_is_hdmi_out(dev))
  927. return -ENODATA;
  928. *timings = dev->dv_timings_out;
  929. }
  930. return 0;
  931. }
  932. int vidioc_enum_dv_timings(struct file *file, void *_fh,
  933. struct v4l2_enum_dv_timings *timings)
  934. {
  935. struct vivid_dev *dev = video_drvdata(file);
  936. struct video_device *vdev = video_devdata(file);
  937. if (vdev->vfl_dir == VFL_DIR_RX) {
  938. if (!vivid_is_hdmi_cap(dev))
  939. return -ENODATA;
  940. } else {
  941. if (!vivid_is_hdmi_out(dev))
  942. return -ENODATA;
  943. }
  944. return v4l2_enum_dv_timings_cap(timings, &vivid_dv_timings_cap,
  945. NULL, NULL);
  946. }
  947. int vidioc_dv_timings_cap(struct file *file, void *_fh,
  948. struct v4l2_dv_timings_cap *cap)
  949. {
  950. struct vivid_dev *dev = video_drvdata(file);
  951. struct video_device *vdev = video_devdata(file);
  952. if (vdev->vfl_dir == VFL_DIR_RX) {
  953. if (!vivid_is_hdmi_cap(dev))
  954. return -ENODATA;
  955. } else {
  956. if (!vivid_is_hdmi_out(dev))
  957. return -ENODATA;
  958. }
  959. *cap = vivid_dv_timings_cap;
  960. return 0;
  961. }
  962. int vidioc_g_edid(struct file *file, void *_fh,
  963. struct v4l2_edid *edid)
  964. {
  965. struct vivid_dev *dev = video_drvdata(file);
  966. struct video_device *vdev = video_devdata(file);
  967. struct cec_adapter *adap;
  968. memset(edid->reserved, 0, sizeof(edid->reserved));
  969. if (vdev->vfl_dir == VFL_DIR_RX) {
  970. if (edid->pad >= dev->num_inputs)
  971. return -EINVAL;
  972. if (dev->input_type[edid->pad] != HDMI)
  973. return -EINVAL;
  974. adap = dev->cec_rx_adap;
  975. } else {
  976. unsigned int bus_idx;
  977. if (edid->pad >= dev->num_outputs)
  978. return -EINVAL;
  979. if (dev->output_type[edid->pad] != HDMI)
  980. return -EINVAL;
  981. if (!dev->display_present[edid->pad])
  982. return -ENODATA;
  983. bus_idx = dev->cec_output2bus_map[edid->pad];
  984. adap = dev->cec_tx_adap[bus_idx];
  985. }
  986. if (edid->start_block == 0 && edid->blocks == 0) {
  987. edid->blocks = dev->edid_blocks;
  988. return 0;
  989. }
  990. if (dev->edid_blocks == 0)
  991. return -ENODATA;
  992. if (edid->start_block >= dev->edid_blocks)
  993. return -EINVAL;
  994. if (edid->blocks > dev->edid_blocks - edid->start_block)
  995. edid->blocks = dev->edid_blocks - edid->start_block;
  996. if (adap)
  997. v4l2_set_edid_phys_addr(dev->edid, dev->edid_blocks * 128, adap->phys_addr);
  998. memcpy(edid->edid, dev->edid + edid->start_block * 128, edid->blocks * 128);
  999. return 0;
  1000. }