s5p_mfc_dec.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. /*
  2. * linux/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
  3. *
  4. * Copyright (C) 2011 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com/
  6. * Kamil Debski, <k.debski@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/io.h>
  16. #include <linux/module.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/sched.h>
  19. #include <linux/slab.h>
  20. #include <linux/version.h>
  21. #include <linux/videodev2.h>
  22. #include <linux/workqueue.h>
  23. #include <media/v4l2-ctrls.h>
  24. #include <media/videobuf2-core.h>
  25. #include "regs-mfc.h"
  26. #include "s5p_mfc_common.h"
  27. #include "s5p_mfc_debug.h"
  28. #include "s5p_mfc_dec.h"
  29. #include "s5p_mfc_intr.h"
  30. #include "s5p_mfc_opr.h"
  31. #include "s5p_mfc_pm.h"
  32. #include "s5p_mfc_shm.h"
  33. static struct s5p_mfc_fmt formats[] = {
  34. {
  35. .name = "4:2:0 2 Planes 64x32 Tiles",
  36. .fourcc = V4L2_PIX_FMT_NV12MT,
  37. .codec_mode = S5P_FIMV_CODEC_NONE,
  38. .type = MFC_FMT_RAW,
  39. .num_planes = 2,
  40. },
  41. {
  42. .name = "4:2:0 2 Planes",
  43. .fourcc = V4L2_PIX_FMT_NV12M,
  44. .codec_mode = S5P_FIMV_CODEC_NONE,
  45. .type = MFC_FMT_RAW,
  46. .num_planes = 2,
  47. },
  48. {
  49. .name = "H264 Encoded Stream",
  50. .fourcc = V4L2_PIX_FMT_H264,
  51. .codec_mode = S5P_FIMV_CODEC_H264_DEC,
  52. .type = MFC_FMT_DEC,
  53. .num_planes = 1,
  54. },
  55. {
  56. .name = "H263 Encoded Stream",
  57. .fourcc = V4L2_PIX_FMT_H263,
  58. .codec_mode = S5P_FIMV_CODEC_H263_DEC,
  59. .type = MFC_FMT_DEC,
  60. .num_planes = 1,
  61. },
  62. {
  63. .name = "MPEG1 Encoded Stream",
  64. .fourcc = V4L2_PIX_FMT_MPEG1,
  65. .codec_mode = S5P_FIMV_CODEC_MPEG2_DEC,
  66. .type = MFC_FMT_DEC,
  67. .num_planes = 1,
  68. },
  69. {
  70. .name = "MPEG2 Encoded Stream",
  71. .fourcc = V4L2_PIX_FMT_MPEG2,
  72. .codec_mode = S5P_FIMV_CODEC_MPEG2_DEC,
  73. .type = MFC_FMT_DEC,
  74. .num_planes = 1,
  75. },
  76. {
  77. .name = "MPEG4 Encoded Stream",
  78. .fourcc = V4L2_PIX_FMT_MPEG4,
  79. .codec_mode = S5P_FIMV_CODEC_MPEG4_DEC,
  80. .type = MFC_FMT_DEC,
  81. .num_planes = 1,
  82. },
  83. {
  84. .name = "XviD Encoded Stream",
  85. .fourcc = V4L2_PIX_FMT_XVID,
  86. .codec_mode = S5P_FIMV_CODEC_MPEG4_DEC,
  87. .type = MFC_FMT_DEC,
  88. .num_planes = 1,
  89. },
  90. {
  91. .name = "VC1 Encoded Stream",
  92. .fourcc = V4L2_PIX_FMT_VC1_ANNEX_G,
  93. .codec_mode = S5P_FIMV_CODEC_VC1_DEC,
  94. .type = MFC_FMT_DEC,
  95. .num_planes = 1,
  96. },
  97. {
  98. .name = "VC1 RCV Encoded Stream",
  99. .fourcc = V4L2_PIX_FMT_VC1_ANNEX_L,
  100. .codec_mode = S5P_FIMV_CODEC_VC1RCV_DEC,
  101. .type = MFC_FMT_DEC,
  102. .num_planes = 1,
  103. },
  104. };
  105. #define NUM_FORMATS ARRAY_SIZE(formats)
  106. /* Find selected format description */
  107. static struct s5p_mfc_fmt *find_format(struct v4l2_format *f, unsigned int t)
  108. {
  109. unsigned int i;
  110. for (i = 0; i < NUM_FORMATS; i++) {
  111. if (formats[i].fourcc == f->fmt.pix_mp.pixelformat &&
  112. formats[i].type == t)
  113. return &formats[i];
  114. }
  115. return NULL;
  116. }
  117. static struct mfc_control controls[] = {
  118. {
  119. .id = V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY,
  120. .type = V4L2_CTRL_TYPE_INTEGER,
  121. .name = "H264 Display Delay",
  122. .minimum = 0,
  123. .maximum = 16383,
  124. .step = 1,
  125. .default_value = 0,
  126. },
  127. {
  128. .id = V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE,
  129. .type = V4L2_CTRL_TYPE_BOOLEAN,
  130. .name = "H264 Display Delay Enable",
  131. .minimum = 0,
  132. .maximum = 1,
  133. .step = 1,
  134. .default_value = 0,
  135. },
  136. {
  137. .id = V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER,
  138. .type = V4L2_CTRL_TYPE_BOOLEAN,
  139. .name = "Mpeg4 Loop Filter Enable",
  140. .minimum = 0,
  141. .maximum = 1,
  142. .step = 1,
  143. .default_value = 0,
  144. },
  145. {
  146. .id = V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE,
  147. .type = V4L2_CTRL_TYPE_BOOLEAN,
  148. .name = "Slice Interface Enable",
  149. .minimum = 0,
  150. .maximum = 1,
  151. .step = 1,
  152. .default_value = 0,
  153. },
  154. {
  155. .id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE,
  156. .type = V4L2_CTRL_TYPE_INTEGER,
  157. .name = "Minimum number of cap bufs",
  158. .minimum = 1,
  159. .maximum = 32,
  160. .step = 1,
  161. .default_value = 1,
  162. .is_volatile = 1,
  163. },
  164. };
  165. #define NUM_CTRLS ARRAY_SIZE(controls)
  166. /* Check whether a context should be run on hardware */
  167. static int s5p_mfc_ctx_ready(struct s5p_mfc_ctx *ctx)
  168. {
  169. /* Context is to parse header */
  170. if (ctx->src_queue_cnt >= 1 && ctx->state == MFCINST_GOT_INST)
  171. return 1;
  172. /* Context is to decode a frame */
  173. if (ctx->src_queue_cnt >= 1 &&
  174. ctx->state == MFCINST_RUNNING &&
  175. ctx->dst_queue_cnt >= ctx->dpb_count)
  176. return 1;
  177. /* Context is to return last frame */
  178. if (ctx->state == MFCINST_FINISHING &&
  179. ctx->dst_queue_cnt >= ctx->dpb_count)
  180. return 1;
  181. /* Context is to set buffers */
  182. if (ctx->src_queue_cnt >= 1 &&
  183. ctx->state == MFCINST_HEAD_PARSED &&
  184. ctx->capture_state == QUEUE_BUFS_MMAPED)
  185. return 1;
  186. /* Resolution change */
  187. if ((ctx->state == MFCINST_RES_CHANGE_INIT ||
  188. ctx->state == MFCINST_RES_CHANGE_FLUSH) &&
  189. ctx->dst_queue_cnt >= ctx->dpb_count)
  190. return 1;
  191. if (ctx->state == MFCINST_RES_CHANGE_END &&
  192. ctx->src_queue_cnt >= 1)
  193. return 1;
  194. mfc_debug(2, "ctx is not ready\n");
  195. return 0;
  196. }
  197. static struct s5p_mfc_codec_ops decoder_codec_ops = {
  198. .pre_seq_start = NULL,
  199. .post_seq_start = NULL,
  200. .pre_frame_start = NULL,
  201. .post_frame_start = NULL,
  202. };
  203. /* Query capabilities of the device */
  204. static int vidioc_querycap(struct file *file, void *priv,
  205. struct v4l2_capability *cap)
  206. {
  207. struct s5p_mfc_dev *dev = video_drvdata(file);
  208. strncpy(cap->driver, dev->plat_dev->name, sizeof(cap->driver) - 1);
  209. strncpy(cap->card, dev->plat_dev->name, sizeof(cap->card) - 1);
  210. cap->bus_info[0] = 0;
  211. cap->version = KERNEL_VERSION(1, 0, 0);
  212. /*
  213. * This is only a mem-to-mem video device. The capture and output
  214. * device capability flags are left only for backward compatibility
  215. * and are scheduled for removal.
  216. */
  217. cap->capabilities = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING |
  218. V4L2_CAP_VIDEO_CAPTURE_MPLANE |
  219. V4L2_CAP_VIDEO_OUTPUT_MPLANE;
  220. return 0;
  221. }
  222. /* Enumerate format */
  223. static int vidioc_enum_fmt(struct v4l2_fmtdesc *f, bool mplane, bool out)
  224. {
  225. struct s5p_mfc_fmt *fmt;
  226. int i, j = 0;
  227. for (i = 0; i < ARRAY_SIZE(formats); ++i) {
  228. if (mplane && formats[i].num_planes == 1)
  229. continue;
  230. else if (!mplane && formats[i].num_planes > 1)
  231. continue;
  232. if (out && formats[i].type != MFC_FMT_DEC)
  233. continue;
  234. else if (!out && formats[i].type != MFC_FMT_RAW)
  235. continue;
  236. if (j == f->index)
  237. break;
  238. ++j;
  239. }
  240. if (i == ARRAY_SIZE(formats))
  241. return -EINVAL;
  242. fmt = &formats[i];
  243. strlcpy(f->description, fmt->name, sizeof(f->description));
  244. f->pixelformat = fmt->fourcc;
  245. return 0;
  246. }
  247. static int vidioc_enum_fmt_vid_cap(struct file *file, void *pirv,
  248. struct v4l2_fmtdesc *f)
  249. {
  250. return vidioc_enum_fmt(f, false, false);
  251. }
  252. static int vidioc_enum_fmt_vid_cap_mplane(struct file *file, void *pirv,
  253. struct v4l2_fmtdesc *f)
  254. {
  255. return vidioc_enum_fmt(f, true, false);
  256. }
  257. static int vidioc_enum_fmt_vid_out(struct file *file, void *prov,
  258. struct v4l2_fmtdesc *f)
  259. {
  260. return vidioc_enum_fmt(f, false, true);
  261. }
  262. static int vidioc_enum_fmt_vid_out_mplane(struct file *file, void *prov,
  263. struct v4l2_fmtdesc *f)
  264. {
  265. return vidioc_enum_fmt(f, true, true);
  266. }
  267. /* Get format */
  268. static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
  269. {
  270. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  271. struct v4l2_pix_format_mplane *pix_mp;
  272. mfc_debug_enter();
  273. pix_mp = &f->fmt.pix_mp;
  274. if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE &&
  275. (ctx->state == MFCINST_GOT_INST || ctx->state ==
  276. MFCINST_RES_CHANGE_END)) {
  277. /* If the MFC is parsing the header,
  278. * so wait until it is finished */
  279. s5p_mfc_clean_ctx_int_flags(ctx);
  280. s5p_mfc_wait_for_done_ctx(ctx, S5P_FIMV_R2H_CMD_SEQ_DONE_RET,
  281. 0);
  282. }
  283. if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE &&
  284. ctx->state >= MFCINST_HEAD_PARSED &&
  285. ctx->state < MFCINST_ABORT) {
  286. /* This is run on CAPTURE (decode output) */
  287. /* Width and height are set to the dimensions
  288. of the movie, the buffer is bigger and
  289. further processing stages should crop to this
  290. rectangle. */
  291. pix_mp->width = ctx->buf_width;
  292. pix_mp->height = ctx->buf_height;
  293. pix_mp->field = V4L2_FIELD_NONE;
  294. pix_mp->num_planes = 2;
  295. /* Set pixelformat to the format in which MFC
  296. outputs the decoded frame */
  297. pix_mp->pixelformat = V4L2_PIX_FMT_NV12MT;
  298. pix_mp->plane_fmt[0].bytesperline = ctx->buf_width;
  299. pix_mp->plane_fmt[0].sizeimage = ctx->luma_size;
  300. pix_mp->plane_fmt[1].bytesperline = ctx->buf_width;
  301. pix_mp->plane_fmt[1].sizeimage = ctx->chroma_size;
  302. } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  303. /* This is run on OUTPUT
  304. The buffer contains compressed image
  305. so width and height have no meaning */
  306. pix_mp->width = 0;
  307. pix_mp->height = 0;
  308. pix_mp->field = V4L2_FIELD_NONE;
  309. pix_mp->plane_fmt[0].bytesperline = ctx->dec_src_buf_size;
  310. pix_mp->plane_fmt[0].sizeimage = ctx->dec_src_buf_size;
  311. pix_mp->pixelformat = ctx->src_fmt->fourcc;
  312. pix_mp->num_planes = ctx->src_fmt->num_planes;
  313. } else {
  314. mfc_err("Format could not be read\n");
  315. mfc_debug(2, "%s-- with error\n", __func__);
  316. return -EINVAL;
  317. }
  318. mfc_debug_leave();
  319. return 0;
  320. }
  321. /* Try format */
  322. static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
  323. {
  324. struct s5p_mfc_fmt *fmt;
  325. if (f->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  326. mfc_err("This node supports decoding only\n");
  327. return -EINVAL;
  328. }
  329. fmt = find_format(f, MFC_FMT_DEC);
  330. if (!fmt) {
  331. mfc_err("Unsupported format\n");
  332. return -EINVAL;
  333. }
  334. if (fmt->type != MFC_FMT_DEC) {
  335. mfc_err("\n");
  336. return -EINVAL;
  337. }
  338. return 0;
  339. }
  340. /* Set format */
  341. static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
  342. {
  343. struct s5p_mfc_dev *dev = video_drvdata(file);
  344. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  345. int ret = 0;
  346. struct s5p_mfc_fmt *fmt;
  347. struct v4l2_pix_format_mplane *pix_mp;
  348. mfc_debug_enter();
  349. ret = vidioc_try_fmt(file, priv, f);
  350. pix_mp = &f->fmt.pix_mp;
  351. if (ret)
  352. return ret;
  353. if (ctx->vq_src.streaming || ctx->vq_dst.streaming) {
  354. v4l2_err(&dev->v4l2_dev, "%s queue busy\n", __func__);
  355. ret = -EBUSY;
  356. goto out;
  357. }
  358. fmt = find_format(f, MFC_FMT_DEC);
  359. if (!fmt || fmt->codec_mode == S5P_FIMV_CODEC_NONE) {
  360. mfc_err("Unknown codec\n");
  361. ret = -EINVAL;
  362. goto out;
  363. }
  364. if (fmt->type != MFC_FMT_DEC) {
  365. mfc_err("Wrong format selected, you should choose "
  366. "format for decoding\n");
  367. ret = -EINVAL;
  368. goto out;
  369. }
  370. ctx->src_fmt = fmt;
  371. ctx->codec_mode = fmt->codec_mode;
  372. mfc_debug(2, "The codec number is: %d\n", ctx->codec_mode);
  373. pix_mp->height = 0;
  374. pix_mp->width = 0;
  375. if (pix_mp->plane_fmt[0].sizeimage)
  376. ctx->dec_src_buf_size = pix_mp->plane_fmt[0].sizeimage;
  377. else
  378. pix_mp->plane_fmt[0].sizeimage = ctx->dec_src_buf_size =
  379. DEF_CPB_SIZE;
  380. pix_mp->plane_fmt[0].bytesperline = 0;
  381. ctx->state = MFCINST_INIT;
  382. out:
  383. mfc_debug_leave();
  384. return ret;
  385. }
  386. /* Reqeust buffers */
  387. static int vidioc_reqbufs(struct file *file, void *priv,
  388. struct v4l2_requestbuffers *reqbufs)
  389. {
  390. struct s5p_mfc_dev *dev = video_drvdata(file);
  391. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  392. int ret = 0;
  393. if (reqbufs->memory != V4L2_MEMORY_MMAP) {
  394. mfc_err("Only V4L2_MEMORY_MAP is supported\n");
  395. return -EINVAL;
  396. }
  397. if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  398. /* Can only request buffers after an instance has been opened.*/
  399. if (ctx->state == MFCINST_INIT) {
  400. ctx->src_bufs_cnt = 0;
  401. if (reqbufs->count == 0) {
  402. mfc_debug(2, "Freeing buffers\n");
  403. s5p_mfc_clock_on();
  404. ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
  405. s5p_mfc_clock_off();
  406. return ret;
  407. }
  408. /* Decoding */
  409. if (ctx->output_state != QUEUE_FREE) {
  410. mfc_err("Bufs have already been requested\n");
  411. return -EINVAL;
  412. }
  413. s5p_mfc_clock_on();
  414. ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
  415. s5p_mfc_clock_off();
  416. if (ret) {
  417. mfc_err("vb2_reqbufs on output failed\n");
  418. return ret;
  419. }
  420. mfc_debug(2, "vb2_reqbufs: %d\n", ret);
  421. ctx->output_state = QUEUE_BUFS_REQUESTED;
  422. }
  423. } else if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  424. ctx->dst_bufs_cnt = 0;
  425. if (reqbufs->count == 0) {
  426. mfc_debug(2, "Freeing buffers\n");
  427. s5p_mfc_clock_on();
  428. ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
  429. s5p_mfc_clock_off();
  430. return ret;
  431. }
  432. if (ctx->capture_state != QUEUE_FREE) {
  433. mfc_err("Bufs have already been requested\n");
  434. return -EINVAL;
  435. }
  436. ctx->capture_state = QUEUE_BUFS_REQUESTED;
  437. s5p_mfc_clock_on();
  438. ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
  439. s5p_mfc_clock_off();
  440. if (ret) {
  441. mfc_err("vb2_reqbufs on capture failed\n");
  442. return ret;
  443. }
  444. if (reqbufs->count < ctx->dpb_count) {
  445. mfc_err("Not enough buffers allocated\n");
  446. reqbufs->count = 0;
  447. s5p_mfc_clock_on();
  448. ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
  449. s5p_mfc_clock_off();
  450. return -ENOMEM;
  451. }
  452. ctx->total_dpb_count = reqbufs->count;
  453. ret = s5p_mfc_alloc_codec_buffers(ctx);
  454. if (ret) {
  455. mfc_err("Failed to allocate decoding buffers\n");
  456. reqbufs->count = 0;
  457. s5p_mfc_clock_on();
  458. ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
  459. s5p_mfc_clock_off();
  460. return -ENOMEM;
  461. }
  462. if (ctx->dst_bufs_cnt == ctx->total_dpb_count) {
  463. ctx->capture_state = QUEUE_BUFS_MMAPED;
  464. } else {
  465. mfc_err("Not all buffers passed to buf_init\n");
  466. reqbufs->count = 0;
  467. s5p_mfc_clock_on();
  468. ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
  469. s5p_mfc_release_codec_buffers(ctx);
  470. s5p_mfc_clock_off();
  471. return -ENOMEM;
  472. }
  473. if (s5p_mfc_ctx_ready(ctx))
  474. set_work_bit_irqsave(ctx);
  475. s5p_mfc_try_run(dev);
  476. s5p_mfc_wait_for_done_ctx(ctx,
  477. S5P_FIMV_R2H_CMD_INIT_BUFFERS_RET, 0);
  478. }
  479. return ret;
  480. }
  481. /* Query buffer */
  482. static int vidioc_querybuf(struct file *file, void *priv,
  483. struct v4l2_buffer *buf)
  484. {
  485. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  486. int ret;
  487. int i;
  488. if (buf->memory != V4L2_MEMORY_MMAP) {
  489. mfc_err("Only mmaped buffers can be used\n");
  490. return -EINVAL;
  491. }
  492. mfc_debug(2, "State: %d, buf->type: %d\n", ctx->state, buf->type);
  493. if (ctx->state == MFCINST_INIT &&
  494. buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  495. ret = vb2_querybuf(&ctx->vq_src, buf);
  496. } else if (ctx->state == MFCINST_RUNNING &&
  497. buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  498. ret = vb2_querybuf(&ctx->vq_dst, buf);
  499. for (i = 0; i < buf->length; i++)
  500. buf->m.planes[i].m.mem_offset += DST_QUEUE_OFF_BASE;
  501. } else {
  502. mfc_err("vidioc_querybuf called in an inappropriate state\n");
  503. ret = -EINVAL;
  504. }
  505. mfc_debug_leave();
  506. return ret;
  507. }
  508. /* Queue a buffer */
  509. static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
  510. {
  511. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  512. if (ctx->state == MFCINST_ERROR) {
  513. mfc_err("Call on QBUF after unrecoverable error\n");
  514. return -EIO;
  515. }
  516. if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
  517. return vb2_qbuf(&ctx->vq_src, buf);
  518. else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  519. return vb2_qbuf(&ctx->vq_dst, buf);
  520. return -EINVAL;
  521. }
  522. /* Dequeue a buffer */
  523. static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
  524. {
  525. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  526. if (ctx->state == MFCINST_ERROR) {
  527. mfc_err("Call on DQBUF after unrecoverable error\n");
  528. return -EIO;
  529. }
  530. if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
  531. return vb2_dqbuf(&ctx->vq_src, buf, file->f_flags & O_NONBLOCK);
  532. else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  533. return vb2_dqbuf(&ctx->vq_dst, buf, file->f_flags & O_NONBLOCK);
  534. return -EINVAL;
  535. }
  536. /* Stream on */
  537. static int vidioc_streamon(struct file *file, void *priv,
  538. enum v4l2_buf_type type)
  539. {
  540. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  541. struct s5p_mfc_dev *dev = ctx->dev;
  542. int ret = -EINVAL;
  543. mfc_debug_enter();
  544. if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  545. if (ctx->state == MFCINST_INIT) {
  546. ctx->dst_bufs_cnt = 0;
  547. ctx->src_bufs_cnt = 0;
  548. ctx->capture_state = QUEUE_FREE;
  549. ctx->output_state = QUEUE_FREE;
  550. s5p_mfc_alloc_instance_buffer(ctx);
  551. s5p_mfc_alloc_dec_temp_buffers(ctx);
  552. set_work_bit_irqsave(ctx);
  553. s5p_mfc_clean_ctx_int_flags(ctx);
  554. s5p_mfc_try_run(dev);
  555. if (s5p_mfc_wait_for_done_ctx(ctx,
  556. S5P_FIMV_R2H_CMD_OPEN_INSTANCE_RET, 0)) {
  557. /* Error or timeout */
  558. mfc_err("Error getting instance from hardware\n");
  559. s5p_mfc_release_instance_buffer(ctx);
  560. s5p_mfc_release_dec_desc_buffer(ctx);
  561. return -EIO;
  562. }
  563. mfc_debug(2, "Got instance number: %d\n", ctx->inst_no);
  564. }
  565. ret = vb2_streamon(&ctx->vq_src, type);
  566. }
  567. else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  568. ret = vb2_streamon(&ctx->vq_dst, type);
  569. mfc_debug_leave();
  570. return ret;
  571. }
  572. /* Stream off, which equals to a pause */
  573. static int vidioc_streamoff(struct file *file, void *priv,
  574. enum v4l2_buf_type type)
  575. {
  576. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  577. if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
  578. return vb2_streamoff(&ctx->vq_src, type);
  579. else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  580. return vb2_streamoff(&ctx->vq_dst, type);
  581. return -EINVAL;
  582. }
  583. /* Set controls - v4l2 control framework */
  584. static int s5p_mfc_dec_s_ctrl(struct v4l2_ctrl *ctrl)
  585. {
  586. struct s5p_mfc_ctx *ctx = ctrl_to_ctx(ctrl);
  587. switch (ctrl->id) {
  588. case V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY:
  589. ctx->display_delay = ctrl->val;
  590. break;
  591. case V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE:
  592. ctx->display_delay_enable = ctrl->val;
  593. break;
  594. case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER:
  595. ctx->loop_filter_mpeg4 = ctrl->val;
  596. break;
  597. case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE:
  598. ctx->slice_interface = ctrl->val;
  599. break;
  600. default:
  601. mfc_err("Invalid control 0x%08x\n", ctrl->id);
  602. return -EINVAL;
  603. }
  604. return 0;
  605. }
  606. static int s5p_mfc_dec_g_v_ctrl(struct v4l2_ctrl *ctrl)
  607. {
  608. struct s5p_mfc_ctx *ctx = ctrl_to_ctx(ctrl);
  609. struct s5p_mfc_dev *dev = ctx->dev;
  610. switch (ctrl->id) {
  611. case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
  612. if (ctx->state >= MFCINST_HEAD_PARSED &&
  613. ctx->state < MFCINST_ABORT) {
  614. ctrl->val = ctx->dpb_count;
  615. break;
  616. } else if (ctx->state != MFCINST_INIT) {
  617. v4l2_err(&dev->v4l2_dev, "Decoding not initialised\n");
  618. return -EINVAL;
  619. }
  620. /* Should wait for the header to be parsed */
  621. s5p_mfc_clean_ctx_int_flags(ctx);
  622. s5p_mfc_wait_for_done_ctx(ctx,
  623. S5P_FIMV_R2H_CMD_SEQ_DONE_RET, 0);
  624. if (ctx->state >= MFCINST_HEAD_PARSED &&
  625. ctx->state < MFCINST_ABORT) {
  626. ctrl->val = ctx->dpb_count;
  627. } else {
  628. v4l2_err(&dev->v4l2_dev, "Decoding not initialised\n");
  629. return -EINVAL;
  630. }
  631. break;
  632. }
  633. return 0;
  634. }
  635. static const struct v4l2_ctrl_ops s5p_mfc_dec_ctrl_ops = {
  636. .s_ctrl = s5p_mfc_dec_s_ctrl,
  637. .g_volatile_ctrl = s5p_mfc_dec_g_v_ctrl,
  638. };
  639. /* Get cropping information */
  640. static int vidioc_g_crop(struct file *file, void *priv,
  641. struct v4l2_crop *cr)
  642. {
  643. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  644. u32 left, right, top, bottom;
  645. if (ctx->state != MFCINST_HEAD_PARSED &&
  646. ctx->state != MFCINST_RUNNING && ctx->state != MFCINST_FINISHING
  647. && ctx->state != MFCINST_FINISHED) {
  648. mfc_err("Cannont set crop\n");
  649. return -EINVAL;
  650. }
  651. if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_H264) {
  652. left = s5p_mfc_read_shm(ctx, CROP_INFO_H);
  653. right = left >> S5P_FIMV_SHARED_CROP_RIGHT_SHIFT;
  654. left = left & S5P_FIMV_SHARED_CROP_LEFT_MASK;
  655. top = s5p_mfc_read_shm(ctx, CROP_INFO_V);
  656. bottom = top >> S5P_FIMV_SHARED_CROP_BOTTOM_SHIFT;
  657. top = top & S5P_FIMV_SHARED_CROP_TOP_MASK;
  658. cr->c.left = left;
  659. cr->c.top = top;
  660. cr->c.width = ctx->img_width - left - right;
  661. cr->c.height = ctx->img_height - top - bottom;
  662. mfc_debug(2, "Cropping info [h264]: l=%d t=%d "
  663. "w=%d h=%d (r=%d b=%d fw=%d fh=%d\n", left, top,
  664. cr->c.width, cr->c.height, right, bottom,
  665. ctx->buf_width, ctx->buf_height);
  666. } else {
  667. cr->c.left = 0;
  668. cr->c.top = 0;
  669. cr->c.width = ctx->img_width;
  670. cr->c.height = ctx->img_height;
  671. mfc_debug(2, "Cropping info: w=%d h=%d fw=%d "
  672. "fh=%d\n", cr->c.width, cr->c.height, ctx->buf_width,
  673. ctx->buf_height);
  674. }
  675. return 0;
  676. }
  677. /* v4l2_ioctl_ops */
  678. static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = {
  679. .vidioc_querycap = vidioc_querycap,
  680. .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  681. .vidioc_enum_fmt_vid_cap_mplane = vidioc_enum_fmt_vid_cap_mplane,
  682. .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out,
  683. .vidioc_enum_fmt_vid_out_mplane = vidioc_enum_fmt_vid_out_mplane,
  684. .vidioc_g_fmt_vid_cap_mplane = vidioc_g_fmt,
  685. .vidioc_g_fmt_vid_out_mplane = vidioc_g_fmt,
  686. .vidioc_try_fmt_vid_cap_mplane = vidioc_try_fmt,
  687. .vidioc_try_fmt_vid_out_mplane = vidioc_try_fmt,
  688. .vidioc_s_fmt_vid_cap_mplane = vidioc_s_fmt,
  689. .vidioc_s_fmt_vid_out_mplane = vidioc_s_fmt,
  690. .vidioc_reqbufs = vidioc_reqbufs,
  691. .vidioc_querybuf = vidioc_querybuf,
  692. .vidioc_qbuf = vidioc_qbuf,
  693. .vidioc_dqbuf = vidioc_dqbuf,
  694. .vidioc_streamon = vidioc_streamon,
  695. .vidioc_streamoff = vidioc_streamoff,
  696. .vidioc_g_crop = vidioc_g_crop,
  697. };
  698. static int s5p_mfc_queue_setup(struct vb2_queue *vq,
  699. const struct v4l2_format *fmt, unsigned int *buf_count,
  700. unsigned int *plane_count, unsigned int psize[],
  701. void *allocators[])
  702. {
  703. struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
  704. /* Video output for decoding (source)
  705. * this can be set after getting an instance */
  706. if (ctx->state == MFCINST_INIT &&
  707. vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  708. /* A single plane is required for input */
  709. *plane_count = 1;
  710. if (*buf_count < 1)
  711. *buf_count = 1;
  712. if (*buf_count > MFC_MAX_BUFFERS)
  713. *buf_count = MFC_MAX_BUFFERS;
  714. /* Video capture for decoding (destination)
  715. * this can be set after the header was parsed */
  716. } else if (ctx->state == MFCINST_HEAD_PARSED &&
  717. vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  718. /* Output plane count is 2 - one for Y and one for CbCr */
  719. *plane_count = 2;
  720. /* Setup buffer count */
  721. if (*buf_count < ctx->dpb_count)
  722. *buf_count = ctx->dpb_count;
  723. if (*buf_count > ctx->dpb_count + MFC_MAX_EXTRA_DPB)
  724. *buf_count = ctx->dpb_count + MFC_MAX_EXTRA_DPB;
  725. if (*buf_count > MFC_MAX_BUFFERS)
  726. *buf_count = MFC_MAX_BUFFERS;
  727. } else {
  728. mfc_err("State seems invalid. State = %d, vq->type = %d\n",
  729. ctx->state, vq->type);
  730. return -EINVAL;
  731. }
  732. mfc_debug(2, "Buffer count=%d, plane count=%d\n",
  733. *buf_count, *plane_count);
  734. if (ctx->state == MFCINST_HEAD_PARSED &&
  735. vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  736. psize[0] = ctx->luma_size;
  737. psize[1] = ctx->chroma_size;
  738. allocators[0] = ctx->dev->alloc_ctx[MFC_BANK2_ALLOC_CTX];
  739. allocators[1] = ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
  740. } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE &&
  741. ctx->state == MFCINST_INIT) {
  742. psize[0] = ctx->dec_src_buf_size;
  743. allocators[0] = ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
  744. } else {
  745. mfc_err("This video node is dedicated to decoding. Decoding not initalised\n");
  746. return -EINVAL;
  747. }
  748. return 0;
  749. }
  750. static void s5p_mfc_unlock(struct vb2_queue *q)
  751. {
  752. struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
  753. struct s5p_mfc_dev *dev = ctx->dev;
  754. mutex_unlock(&dev->mfc_mutex);
  755. }
  756. static void s5p_mfc_lock(struct vb2_queue *q)
  757. {
  758. struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
  759. struct s5p_mfc_dev *dev = ctx->dev;
  760. mutex_lock(&dev->mfc_mutex);
  761. }
  762. static int s5p_mfc_buf_init(struct vb2_buffer *vb)
  763. {
  764. struct vb2_queue *vq = vb->vb2_queue;
  765. struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
  766. unsigned int i;
  767. if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  768. if (ctx->capture_state == QUEUE_BUFS_MMAPED)
  769. return 0;
  770. for (i = 0; i <= ctx->src_fmt->num_planes ; i++) {
  771. if (IS_ERR_OR_NULL(ERR_PTR(
  772. vb2_dma_contig_plane_dma_addr(vb, i)))) {
  773. mfc_err("Plane mem not allocated\n");
  774. return -EINVAL;
  775. }
  776. }
  777. if (vb2_plane_size(vb, 0) < ctx->luma_size ||
  778. vb2_plane_size(vb, 1) < ctx->chroma_size) {
  779. mfc_err("Plane buffer (CAPTURE) is too small\n");
  780. return -EINVAL;
  781. }
  782. i = vb->v4l2_buf.index;
  783. ctx->dst_bufs[i].b = vb;
  784. ctx->dst_bufs[i].cookie.raw.luma =
  785. vb2_dma_contig_plane_dma_addr(vb, 0);
  786. ctx->dst_bufs[i].cookie.raw.chroma =
  787. vb2_dma_contig_plane_dma_addr(vb, 1);
  788. ctx->dst_bufs_cnt++;
  789. } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  790. if (IS_ERR_OR_NULL(ERR_PTR(
  791. vb2_dma_contig_plane_dma_addr(vb, 0)))) {
  792. mfc_err("Plane memory not allocated\n");
  793. return -EINVAL;
  794. }
  795. if (vb2_plane_size(vb, 0) < ctx->dec_src_buf_size) {
  796. mfc_err("Plane buffer (OUTPUT) is too small\n");
  797. return -EINVAL;
  798. }
  799. i = vb->v4l2_buf.index;
  800. ctx->src_bufs[i].b = vb;
  801. ctx->src_bufs[i].cookie.stream =
  802. vb2_dma_contig_plane_dma_addr(vb, 0);
  803. ctx->src_bufs_cnt++;
  804. } else {
  805. mfc_err("s5p_mfc_buf_init: unknown queue type\n");
  806. return -EINVAL;
  807. }
  808. return 0;
  809. }
  810. static int s5p_mfc_start_streaming(struct vb2_queue *q, unsigned int count)
  811. {
  812. struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
  813. struct s5p_mfc_dev *dev = ctx->dev;
  814. v4l2_ctrl_handler_setup(&ctx->ctrl_handler);
  815. if (ctx->state == MFCINST_FINISHING ||
  816. ctx->state == MFCINST_FINISHED)
  817. ctx->state = MFCINST_RUNNING;
  818. /* If context is ready then dev = work->data;schedule it to run */
  819. if (s5p_mfc_ctx_ready(ctx))
  820. set_work_bit_irqsave(ctx);
  821. s5p_mfc_try_run(dev);
  822. return 0;
  823. }
  824. static int s5p_mfc_stop_streaming(struct vb2_queue *q)
  825. {
  826. unsigned long flags;
  827. struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
  828. struct s5p_mfc_dev *dev = ctx->dev;
  829. int aborted = 0;
  830. if ((ctx->state == MFCINST_FINISHING ||
  831. ctx->state == MFCINST_RUNNING) &&
  832. dev->curr_ctx == ctx->num && dev->hw_lock) {
  833. ctx->state = MFCINST_ABORT;
  834. s5p_mfc_wait_for_done_ctx(ctx,
  835. S5P_FIMV_R2H_CMD_FRAME_DONE_RET, 0);
  836. aborted = 1;
  837. }
  838. spin_lock_irqsave(&dev->irqlock, flags);
  839. if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  840. s5p_mfc_cleanup_queue(&ctx->dst_queue, &ctx->vq_dst);
  841. INIT_LIST_HEAD(&ctx->dst_queue);
  842. ctx->dst_queue_cnt = 0;
  843. ctx->dpb_flush_flag = 1;
  844. ctx->dec_dst_flag = 0;
  845. }
  846. if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  847. s5p_mfc_cleanup_queue(&ctx->src_queue, &ctx->vq_src);
  848. INIT_LIST_HEAD(&ctx->src_queue);
  849. ctx->src_queue_cnt = 0;
  850. }
  851. if (aborted)
  852. ctx->state = MFCINST_RUNNING;
  853. spin_unlock_irqrestore(&dev->irqlock, flags);
  854. return 0;
  855. }
  856. static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
  857. {
  858. struct vb2_queue *vq = vb->vb2_queue;
  859. struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
  860. struct s5p_mfc_dev *dev = ctx->dev;
  861. unsigned long flags;
  862. struct s5p_mfc_buf *mfc_buf;
  863. if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  864. mfc_buf = &ctx->src_bufs[vb->v4l2_buf.index];
  865. mfc_buf->flags &= ~MFC_BUF_FLAG_USED;
  866. spin_lock_irqsave(&dev->irqlock, flags);
  867. list_add_tail(&mfc_buf->list, &ctx->src_queue);
  868. ctx->src_queue_cnt++;
  869. spin_unlock_irqrestore(&dev->irqlock, flags);
  870. } else if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  871. mfc_buf = &ctx->dst_bufs[vb->v4l2_buf.index];
  872. mfc_buf->flags &= ~MFC_BUF_FLAG_USED;
  873. /* Mark destination as available for use by MFC */
  874. spin_lock_irqsave(&dev->irqlock, flags);
  875. set_bit(vb->v4l2_buf.index, &ctx->dec_dst_flag);
  876. list_add_tail(&mfc_buf->list, &ctx->dst_queue);
  877. ctx->dst_queue_cnt++;
  878. spin_unlock_irqrestore(&dev->irqlock, flags);
  879. } else {
  880. mfc_err("Unsupported buffer type (%d)\n", vq->type);
  881. }
  882. if (s5p_mfc_ctx_ready(ctx))
  883. set_work_bit_irqsave(ctx);
  884. s5p_mfc_try_run(dev);
  885. }
  886. static struct vb2_ops s5p_mfc_dec_qops = {
  887. .queue_setup = s5p_mfc_queue_setup,
  888. .wait_prepare = s5p_mfc_unlock,
  889. .wait_finish = s5p_mfc_lock,
  890. .buf_init = s5p_mfc_buf_init,
  891. .start_streaming = s5p_mfc_start_streaming,
  892. .stop_streaming = s5p_mfc_stop_streaming,
  893. .buf_queue = s5p_mfc_buf_queue,
  894. };
  895. struct s5p_mfc_codec_ops *get_dec_codec_ops(void)
  896. {
  897. return &decoder_codec_ops;
  898. }
  899. struct vb2_ops *get_dec_queue_ops(void)
  900. {
  901. return &s5p_mfc_dec_qops;
  902. }
  903. const struct v4l2_ioctl_ops *get_dec_v4l2_ioctl_ops(void)
  904. {
  905. return &s5p_mfc_dec_ioctl_ops;
  906. }
  907. #define IS_MFC51_PRIV(x) ((V4L2_CTRL_ID2CLASS(x) == V4L2_CTRL_CLASS_MPEG) \
  908. && V4L2_CTRL_DRIVER_PRIV(x))
  909. int s5p_mfc_dec_ctrls_setup(struct s5p_mfc_ctx *ctx)
  910. {
  911. struct v4l2_ctrl_config cfg;
  912. int i;
  913. v4l2_ctrl_handler_init(&ctx->ctrl_handler, NUM_CTRLS);
  914. if (ctx->ctrl_handler.error) {
  915. mfc_err("v4l2_ctrl_handler_init failed\n");
  916. return ctx->ctrl_handler.error;
  917. }
  918. for (i = 0; i < NUM_CTRLS; i++) {
  919. if (IS_MFC51_PRIV(controls[i].id)) {
  920. memset(&cfg, 0, sizeof(struct v4l2_ctrl_config));
  921. cfg.ops = &s5p_mfc_dec_ctrl_ops;
  922. cfg.id = controls[i].id;
  923. cfg.min = controls[i].minimum;
  924. cfg.max = controls[i].maximum;
  925. cfg.def = controls[i].default_value;
  926. cfg.name = controls[i].name;
  927. cfg.type = controls[i].type;
  928. cfg.step = controls[i].step;
  929. cfg.menu_skip_mask = 0;
  930. ctx->ctrls[i] = v4l2_ctrl_new_custom(&ctx->ctrl_handler,
  931. &cfg, NULL);
  932. } else {
  933. ctx->ctrls[i] = v4l2_ctrl_new_std(&ctx->ctrl_handler,
  934. &s5p_mfc_dec_ctrl_ops,
  935. controls[i].id, controls[i].minimum,
  936. controls[i].maximum, controls[i].step,
  937. controls[i].default_value);
  938. }
  939. if (ctx->ctrl_handler.error) {
  940. mfc_err("Adding control (%d) failed\n", i);
  941. return ctx->ctrl_handler.error;
  942. }
  943. if (controls[i].is_volatile && ctx->ctrls[i])
  944. ctx->ctrls[i]->flags |= V4L2_CTRL_FLAG_VOLATILE;
  945. }
  946. return 0;
  947. }
  948. void s5p_mfc_dec_ctrls_delete(struct s5p_mfc_ctx *ctx)
  949. {
  950. int i;
  951. v4l2_ctrl_handler_free(&ctx->ctrl_handler);
  952. for (i = 0; i < NUM_CTRLS; i++)
  953. ctx->ctrls[i] = NULL;
  954. }