s5p_mfc_dec.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. /*
  2. * linux/drivers/media/video/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. cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT
  213. | V4L2_CAP_STREAMING;
  214. return 0;
  215. }
  216. /* Enumerate format */
  217. static int vidioc_enum_fmt(struct v4l2_fmtdesc *f, bool mplane, bool out)
  218. {
  219. struct s5p_mfc_fmt *fmt;
  220. int i, j = 0;
  221. for (i = 0; i < ARRAY_SIZE(formats); ++i) {
  222. if (mplane && formats[i].num_planes == 1)
  223. continue;
  224. else if (!mplane && formats[i].num_planes > 1)
  225. continue;
  226. if (out && formats[i].type != MFC_FMT_DEC)
  227. continue;
  228. else if (!out && formats[i].type != MFC_FMT_RAW)
  229. continue;
  230. if (j == f->index)
  231. break;
  232. ++j;
  233. }
  234. if (i == ARRAY_SIZE(formats))
  235. return -EINVAL;
  236. fmt = &formats[i];
  237. strlcpy(f->description, fmt->name, sizeof(f->description));
  238. f->pixelformat = fmt->fourcc;
  239. return 0;
  240. }
  241. static int vidioc_enum_fmt_vid_cap(struct file *file, void *pirv,
  242. struct v4l2_fmtdesc *f)
  243. {
  244. return vidioc_enum_fmt(f, false, false);
  245. }
  246. static int vidioc_enum_fmt_vid_cap_mplane(struct file *file, void *pirv,
  247. struct v4l2_fmtdesc *f)
  248. {
  249. return vidioc_enum_fmt(f, true, false);
  250. }
  251. static int vidioc_enum_fmt_vid_out(struct file *file, void *prov,
  252. struct v4l2_fmtdesc *f)
  253. {
  254. return vidioc_enum_fmt(f, false, true);
  255. }
  256. static int vidioc_enum_fmt_vid_out_mplane(struct file *file, void *prov,
  257. struct v4l2_fmtdesc *f)
  258. {
  259. return vidioc_enum_fmt(f, true, true);
  260. }
  261. /* Get format */
  262. static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
  263. {
  264. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  265. struct v4l2_pix_format_mplane *pix_mp;
  266. mfc_debug_enter();
  267. pix_mp = &f->fmt.pix_mp;
  268. if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE &&
  269. (ctx->state == MFCINST_GOT_INST || ctx->state ==
  270. MFCINST_RES_CHANGE_END)) {
  271. /* If the MFC is parsing the header,
  272. * so wait until it is finished */
  273. s5p_mfc_clean_ctx_int_flags(ctx);
  274. s5p_mfc_wait_for_done_ctx(ctx, S5P_FIMV_R2H_CMD_SEQ_DONE_RET,
  275. 0);
  276. }
  277. if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE &&
  278. ctx->state >= MFCINST_HEAD_PARSED &&
  279. ctx->state < MFCINST_ABORT) {
  280. /* This is run on CAPTURE (decode output) */
  281. /* Width and height are set to the dimensions
  282. of the movie, the buffer is bigger and
  283. further processing stages should crop to this
  284. rectangle. */
  285. pix_mp->width = ctx->buf_width;
  286. pix_mp->height = ctx->buf_height;
  287. pix_mp->field = V4L2_FIELD_NONE;
  288. pix_mp->num_planes = 2;
  289. /* Set pixelformat to the format in which MFC
  290. outputs the decoded frame */
  291. pix_mp->pixelformat = V4L2_PIX_FMT_NV12MT;
  292. pix_mp->plane_fmt[0].bytesperline = ctx->buf_width;
  293. pix_mp->plane_fmt[0].sizeimage = ctx->luma_size;
  294. pix_mp->plane_fmt[1].bytesperline = ctx->buf_width;
  295. pix_mp->plane_fmt[1].sizeimage = ctx->chroma_size;
  296. } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  297. /* This is run on OUTPUT
  298. The buffer contains compressed image
  299. so width and height have no meaning */
  300. pix_mp->width = 0;
  301. pix_mp->height = 0;
  302. pix_mp->field = V4L2_FIELD_NONE;
  303. pix_mp->plane_fmt[0].bytesperline = ctx->dec_src_buf_size;
  304. pix_mp->plane_fmt[0].sizeimage = ctx->dec_src_buf_size;
  305. pix_mp->pixelformat = ctx->src_fmt->fourcc;
  306. pix_mp->num_planes = ctx->src_fmt->num_planes;
  307. } else {
  308. mfc_err("Format could not be read\n");
  309. mfc_debug(2, "%s-- with error\n", __func__);
  310. return -EINVAL;
  311. }
  312. mfc_debug_leave();
  313. return 0;
  314. }
  315. /* Try format */
  316. static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
  317. {
  318. struct s5p_mfc_fmt *fmt;
  319. if (f->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  320. mfc_err("This node supports decoding only\n");
  321. return -EINVAL;
  322. }
  323. fmt = find_format(f, MFC_FMT_DEC);
  324. if (!fmt) {
  325. mfc_err("Unsupported format\n");
  326. return -EINVAL;
  327. }
  328. if (fmt->type != MFC_FMT_DEC) {
  329. mfc_err("\n");
  330. return -EINVAL;
  331. }
  332. return 0;
  333. }
  334. /* Set format */
  335. static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
  336. {
  337. struct s5p_mfc_dev *dev = video_drvdata(file);
  338. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  339. int ret = 0;
  340. struct s5p_mfc_fmt *fmt;
  341. struct v4l2_pix_format_mplane *pix_mp;
  342. mfc_debug_enter();
  343. ret = vidioc_try_fmt(file, priv, f);
  344. pix_mp = &f->fmt.pix_mp;
  345. if (ret)
  346. return ret;
  347. if (ctx->vq_src.streaming || ctx->vq_dst.streaming) {
  348. v4l2_err(&dev->v4l2_dev, "%s queue busy\n", __func__);
  349. ret = -EBUSY;
  350. goto out;
  351. }
  352. fmt = find_format(f, MFC_FMT_DEC);
  353. if (!fmt || fmt->codec_mode == S5P_FIMV_CODEC_NONE) {
  354. mfc_err("Unknown codec\n");
  355. ret = -EINVAL;
  356. goto out;
  357. }
  358. if (fmt->type != MFC_FMT_DEC) {
  359. mfc_err("Wrong format selected, you should choose "
  360. "format for decoding\n");
  361. ret = -EINVAL;
  362. goto out;
  363. }
  364. ctx->src_fmt = fmt;
  365. ctx->codec_mode = fmt->codec_mode;
  366. mfc_debug(2, "The codec number is: %d\n", ctx->codec_mode);
  367. pix_mp->height = 0;
  368. pix_mp->width = 0;
  369. if (pix_mp->plane_fmt[0].sizeimage)
  370. ctx->dec_src_buf_size = pix_mp->plane_fmt[0].sizeimage;
  371. else
  372. pix_mp->plane_fmt[0].sizeimage = ctx->dec_src_buf_size =
  373. DEF_CPB_SIZE;
  374. pix_mp->plane_fmt[0].bytesperline = 0;
  375. ctx->state = MFCINST_INIT;
  376. out:
  377. mfc_debug_leave();
  378. return ret;
  379. }
  380. /* Reqeust buffers */
  381. static int vidioc_reqbufs(struct file *file, void *priv,
  382. struct v4l2_requestbuffers *reqbufs)
  383. {
  384. struct s5p_mfc_dev *dev = video_drvdata(file);
  385. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  386. int ret = 0;
  387. unsigned long flags;
  388. if (reqbufs->memory != V4L2_MEMORY_MMAP) {
  389. mfc_err("Only V4L2_MEMORY_MAP is supported\n");
  390. return -EINVAL;
  391. }
  392. if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  393. /* Can only request buffers after an instance has been opened.*/
  394. if (ctx->state == MFCINST_INIT) {
  395. ctx->src_bufs_cnt = 0;
  396. if (reqbufs->count == 0) {
  397. mfc_debug(2, "Freeing buffers\n");
  398. s5p_mfc_clock_on();
  399. ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
  400. s5p_mfc_clock_off();
  401. return ret;
  402. }
  403. /* Decoding */
  404. if (ctx->output_state != QUEUE_FREE) {
  405. mfc_err("Bufs have already been requested\n");
  406. return -EINVAL;
  407. }
  408. s5p_mfc_clock_on();
  409. ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
  410. s5p_mfc_clock_off();
  411. if (ret) {
  412. mfc_err("vb2_reqbufs on output failed\n");
  413. return ret;
  414. }
  415. mfc_debug(2, "vb2_reqbufs: %d\n", ret);
  416. ctx->output_state = QUEUE_BUFS_REQUESTED;
  417. }
  418. } else if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  419. ctx->dst_bufs_cnt = 0;
  420. if (reqbufs->count == 0) {
  421. mfc_debug(2, "Freeing buffers\n");
  422. s5p_mfc_clock_on();
  423. ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
  424. s5p_mfc_clock_off();
  425. return ret;
  426. }
  427. if (ctx->capture_state != QUEUE_FREE) {
  428. mfc_err("Bufs have already been requested\n");
  429. return -EINVAL;
  430. }
  431. ctx->capture_state = QUEUE_BUFS_REQUESTED;
  432. s5p_mfc_clock_on();
  433. ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
  434. s5p_mfc_clock_off();
  435. if (ret) {
  436. mfc_err("vb2_reqbufs on capture failed\n");
  437. return ret;
  438. }
  439. if (reqbufs->count < ctx->dpb_count) {
  440. mfc_err("Not enough buffers allocated\n");
  441. reqbufs->count = 0;
  442. s5p_mfc_clock_on();
  443. ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
  444. s5p_mfc_clock_off();
  445. return -ENOMEM;
  446. }
  447. ctx->total_dpb_count = reqbufs->count;
  448. ret = s5p_mfc_alloc_codec_buffers(ctx);
  449. if (ret) {
  450. mfc_err("Failed to allocate decoding buffers\n");
  451. reqbufs->count = 0;
  452. s5p_mfc_clock_on();
  453. ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
  454. s5p_mfc_clock_off();
  455. return -ENOMEM;
  456. }
  457. if (ctx->dst_bufs_cnt == ctx->total_dpb_count) {
  458. ctx->capture_state = QUEUE_BUFS_MMAPED;
  459. } else {
  460. mfc_err("Not all buffers passed to buf_init\n");
  461. reqbufs->count = 0;
  462. s5p_mfc_clock_on();
  463. ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
  464. s5p_mfc_release_codec_buffers(ctx);
  465. s5p_mfc_clock_off();
  466. return -ENOMEM;
  467. }
  468. if (s5p_mfc_ctx_ready(ctx)) {
  469. spin_lock_irqsave(&dev->condlock, flags);
  470. set_bit(ctx->num, &dev->ctx_work_bits);
  471. spin_unlock_irqrestore(&dev->condlock, flags);
  472. }
  473. s5p_mfc_try_run(dev);
  474. s5p_mfc_wait_for_done_ctx(ctx,
  475. S5P_FIMV_R2H_CMD_INIT_BUFFERS_RET, 0);
  476. }
  477. return ret;
  478. }
  479. /* Query buffer */
  480. static int vidioc_querybuf(struct file *file, void *priv,
  481. struct v4l2_buffer *buf)
  482. {
  483. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  484. int ret;
  485. int i;
  486. if (buf->memory != V4L2_MEMORY_MMAP) {
  487. mfc_err("Only mmaped buffers can be used\n");
  488. return -EINVAL;
  489. }
  490. mfc_debug(2, "State: %d, buf->type: %d\n", ctx->state, buf->type);
  491. if (ctx->state == MFCINST_INIT &&
  492. buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  493. ret = vb2_querybuf(&ctx->vq_src, buf);
  494. } else if (ctx->state == MFCINST_RUNNING &&
  495. buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  496. ret = vb2_querybuf(&ctx->vq_dst, buf);
  497. for (i = 0; i < buf->length; i++)
  498. buf->m.planes[i].m.mem_offset += DST_QUEUE_OFF_BASE;
  499. } else {
  500. mfc_err("vidioc_querybuf called in an inappropriate state\n");
  501. ret = -EINVAL;
  502. }
  503. mfc_debug_leave();
  504. return ret;
  505. }
  506. /* Queue a buffer */
  507. static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
  508. {
  509. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  510. if (ctx->state == MFCINST_ERROR) {
  511. mfc_err("Call on QBUF after unrecoverable error\n");
  512. return -EIO;
  513. }
  514. if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
  515. return vb2_qbuf(&ctx->vq_src, buf);
  516. else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  517. return vb2_qbuf(&ctx->vq_dst, buf);
  518. return -EINVAL;
  519. }
  520. /* Dequeue a buffer */
  521. static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
  522. {
  523. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  524. if (ctx->state == MFCINST_ERROR) {
  525. mfc_err("Call on DQBUF after unrecoverable error\n");
  526. return -EIO;
  527. }
  528. if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
  529. return vb2_dqbuf(&ctx->vq_src, buf, file->f_flags & O_NONBLOCK);
  530. else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  531. return vb2_dqbuf(&ctx->vq_dst, buf, file->f_flags & O_NONBLOCK);
  532. return -EINVAL;
  533. }
  534. /* Stream on */
  535. static int vidioc_streamon(struct file *file, void *priv,
  536. enum v4l2_buf_type type)
  537. {
  538. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  539. struct s5p_mfc_dev *dev = ctx->dev;
  540. unsigned long flags;
  541. int ret = -EINVAL;
  542. mfc_debug_enter();
  543. if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  544. if (ctx->state == MFCINST_INIT) {
  545. ctx->dst_bufs_cnt = 0;
  546. ctx->src_bufs_cnt = 0;
  547. ctx->capture_state = QUEUE_FREE;
  548. ctx->output_state = QUEUE_FREE;
  549. s5p_mfc_alloc_instance_buffer(ctx);
  550. s5p_mfc_alloc_dec_temp_buffers(ctx);
  551. spin_lock_irqsave(&dev->condlock, flags);
  552. set_bit(ctx->num, &dev->ctx_work_bits);
  553. spin_unlock_irqrestore(&dev->condlock, flags);
  554. s5p_mfc_clean_ctx_int_flags(ctx);
  555. s5p_mfc_try_run(dev);
  556. if (s5p_mfc_wait_for_done_ctx(ctx,
  557. S5P_FIMV_R2H_CMD_OPEN_INSTANCE_RET, 0)) {
  558. /* Error or timeout */
  559. mfc_err("Error getting instance from hardware\n");
  560. s5p_mfc_release_instance_buffer(ctx);
  561. s5p_mfc_release_dec_desc_buffer(ctx);
  562. return -EIO;
  563. }
  564. mfc_debug(2, "Got instance number: %d\n", ctx->inst_no);
  565. }
  566. ret = vb2_streamon(&ctx->vq_src, type);
  567. }
  568. else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  569. ret = vb2_streamon(&ctx->vq_dst, type);
  570. mfc_debug_leave();
  571. return ret;
  572. }
  573. /* Stream off, which equals to a pause */
  574. static int vidioc_streamoff(struct file *file, void *priv,
  575. enum v4l2_buf_type type)
  576. {
  577. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  578. if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
  579. return vb2_streamoff(&ctx->vq_src, type);
  580. else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  581. return vb2_streamoff(&ctx->vq_dst, type);
  582. return -EINVAL;
  583. }
  584. /* Set controls - v4l2 control framework */
  585. static int s5p_mfc_dec_s_ctrl(struct v4l2_ctrl *ctrl)
  586. {
  587. struct s5p_mfc_ctx *ctx = ctrl_to_ctx(ctrl);
  588. switch (ctrl->id) {
  589. case V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY:
  590. ctx->loop_filter_mpeg4 = ctrl->val;
  591. break;
  592. case V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE:
  593. ctx->display_delay_enable = ctrl->val;
  594. break;
  595. case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER:
  596. ctx->display_delay = ctrl->val;
  597. break;
  598. case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE:
  599. ctx->slice_interface = ctrl->val;
  600. break;
  601. default:
  602. mfc_err("Invalid control 0x%08x\n", ctrl->id);
  603. return -EINVAL;
  604. }
  605. return 0;
  606. }
  607. static int s5p_mfc_dec_g_v_ctrl(struct v4l2_ctrl *ctrl)
  608. {
  609. struct s5p_mfc_ctx *ctx = ctrl_to_ctx(ctrl);
  610. struct s5p_mfc_dev *dev = ctx->dev;
  611. switch (ctrl->id) {
  612. case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
  613. if (ctx->state >= MFCINST_HEAD_PARSED &&
  614. ctx->state < MFCINST_ABORT) {
  615. ctrl->val = ctx->dpb_count;
  616. break;
  617. } else if (ctx->state != MFCINST_INIT) {
  618. v4l2_err(&dev->v4l2_dev, "Decoding not initialised\n");
  619. return -EINVAL;
  620. }
  621. /* Should wait for the header to be parsed */
  622. s5p_mfc_clean_ctx_int_flags(ctx);
  623. s5p_mfc_wait_for_done_ctx(ctx,
  624. S5P_FIMV_R2H_CMD_SEQ_DONE_RET, 0);
  625. if (ctx->state >= MFCINST_HEAD_PARSED &&
  626. ctx->state < MFCINST_ABORT) {
  627. ctrl->val = ctx->dpb_count;
  628. } else {
  629. v4l2_err(&dev->v4l2_dev, "Decoding not initialised\n");
  630. return -EINVAL;
  631. }
  632. break;
  633. }
  634. return 0;
  635. }
  636. static const struct v4l2_ctrl_ops s5p_mfc_dec_ctrl_ops = {
  637. .s_ctrl = s5p_mfc_dec_s_ctrl,
  638. .g_volatile_ctrl = s5p_mfc_dec_g_v_ctrl,
  639. };
  640. /* Get cropping information */
  641. static int vidioc_g_crop(struct file *file, void *priv,
  642. struct v4l2_crop *cr)
  643. {
  644. struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
  645. u32 left, right, top, bottom;
  646. if (ctx->state != MFCINST_HEAD_PARSED &&
  647. ctx->state != MFCINST_RUNNING && ctx->state != MFCINST_FINISHING
  648. && ctx->state != MFCINST_FINISHED) {
  649. mfc_err("Cannont set crop\n");
  650. return -EINVAL;
  651. }
  652. if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_H264) {
  653. left = s5p_mfc_read_shm(ctx, CROP_INFO_H);
  654. right = left >> S5P_FIMV_SHARED_CROP_RIGHT_SHIFT;
  655. left = left & S5P_FIMV_SHARED_CROP_LEFT_MASK;
  656. top = s5p_mfc_read_shm(ctx, CROP_INFO_V);
  657. bottom = top >> S5P_FIMV_SHARED_CROP_BOTTOM_SHIFT;
  658. top = top & S5P_FIMV_SHARED_CROP_TOP_MASK;
  659. cr->c.left = left;
  660. cr->c.top = top;
  661. cr->c.width = ctx->img_width - left - right;
  662. cr->c.height = ctx->img_height - top - bottom;
  663. mfc_debug(2, "Cropping info [h264]: l=%d t=%d "
  664. "w=%d h=%d (r=%d b=%d fw=%d fh=%d\n", left, top,
  665. cr->c.width, cr->c.height, right, bottom,
  666. ctx->buf_width, ctx->buf_height);
  667. } else {
  668. cr->c.left = 0;
  669. cr->c.top = 0;
  670. cr->c.width = ctx->img_width;
  671. cr->c.height = ctx->img_height;
  672. mfc_debug(2, "Cropping info: w=%d h=%d fw=%d "
  673. "fh=%d\n", cr->c.width, cr->c.height, ctx->buf_width,
  674. ctx->buf_height);
  675. }
  676. return 0;
  677. }
  678. /* v4l2_ioctl_ops */
  679. static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = {
  680. .vidioc_querycap = vidioc_querycap,
  681. .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  682. .vidioc_enum_fmt_vid_cap_mplane = vidioc_enum_fmt_vid_cap_mplane,
  683. .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out,
  684. .vidioc_enum_fmt_vid_out_mplane = vidioc_enum_fmt_vid_out_mplane,
  685. .vidioc_g_fmt_vid_cap_mplane = vidioc_g_fmt,
  686. .vidioc_g_fmt_vid_out_mplane = vidioc_g_fmt,
  687. .vidioc_try_fmt_vid_cap_mplane = vidioc_try_fmt,
  688. .vidioc_try_fmt_vid_out_mplane = vidioc_try_fmt,
  689. .vidioc_s_fmt_vid_cap_mplane = vidioc_s_fmt,
  690. .vidioc_s_fmt_vid_out_mplane = vidioc_s_fmt,
  691. .vidioc_reqbufs = vidioc_reqbufs,
  692. .vidioc_querybuf = vidioc_querybuf,
  693. .vidioc_qbuf = vidioc_qbuf,
  694. .vidioc_dqbuf = vidioc_dqbuf,
  695. .vidioc_streamon = vidioc_streamon,
  696. .vidioc_streamoff = vidioc_streamoff,
  697. .vidioc_g_crop = vidioc_g_crop,
  698. };
  699. static int s5p_mfc_queue_setup(struct vb2_queue *vq, 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_paddr(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_paddr(vb, 0);
  786. ctx->dst_bufs[i].cookie.raw.chroma =
  787. vb2_dma_contig_plane_paddr(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_paddr(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_paddr(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)
  811. {
  812. struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
  813. struct s5p_mfc_dev *dev = ctx->dev;
  814. unsigned long flags;
  815. v4l2_ctrl_handler_setup(&ctx->ctrl_handler);
  816. if (ctx->state == MFCINST_FINISHING ||
  817. ctx->state == MFCINST_FINISHED)
  818. ctx->state = MFCINST_RUNNING;
  819. /* If context is ready then dev = work->data;schedule it to run */
  820. if (s5p_mfc_ctx_ready(ctx)) {
  821. spin_lock_irqsave(&dev->condlock, flags);
  822. set_bit(ctx->num, &dev->ctx_work_bits);
  823. spin_unlock_irqrestore(&dev->condlock, flags);
  824. }
  825. s5p_mfc_try_run(dev);
  826. return 0;
  827. }
  828. static int s5p_mfc_stop_streaming(struct vb2_queue *q)
  829. {
  830. unsigned long flags;
  831. struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
  832. struct s5p_mfc_dev *dev = ctx->dev;
  833. int aborted = 0;
  834. if ((ctx->state == MFCINST_FINISHING ||
  835. ctx->state == MFCINST_RUNNING) &&
  836. dev->curr_ctx == ctx->num && dev->hw_lock) {
  837. ctx->state = MFCINST_ABORT;
  838. s5p_mfc_wait_for_done_ctx(ctx,
  839. S5P_FIMV_R2H_CMD_FRAME_DONE_RET, 0);
  840. aborted = 1;
  841. }
  842. spin_lock_irqsave(&dev->irqlock, flags);
  843. if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  844. s5p_mfc_cleanup_queue(&ctx->dst_queue, &ctx->vq_dst);
  845. INIT_LIST_HEAD(&ctx->dst_queue);
  846. ctx->dst_queue_cnt = 0;
  847. ctx->dpb_flush_flag = 1;
  848. ctx->dec_dst_flag = 0;
  849. }
  850. if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  851. s5p_mfc_cleanup_queue(&ctx->src_queue, &ctx->vq_src);
  852. INIT_LIST_HEAD(&ctx->src_queue);
  853. ctx->src_queue_cnt = 0;
  854. }
  855. if (aborted)
  856. ctx->state = MFCINST_RUNNING;
  857. spin_unlock_irqrestore(&dev->irqlock, flags);
  858. return 0;
  859. }
  860. static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
  861. {
  862. struct vb2_queue *vq = vb->vb2_queue;
  863. struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
  864. struct s5p_mfc_dev *dev = ctx->dev;
  865. unsigned long flags;
  866. struct s5p_mfc_buf *mfc_buf;
  867. if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  868. mfc_buf = &ctx->src_bufs[vb->v4l2_buf.index];
  869. mfc_buf->used = 0;
  870. spin_lock_irqsave(&dev->irqlock, flags);
  871. list_add_tail(&mfc_buf->list, &ctx->src_queue);
  872. ctx->src_queue_cnt++;
  873. spin_unlock_irqrestore(&dev->irqlock, flags);
  874. } else if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  875. mfc_buf = &ctx->dst_bufs[vb->v4l2_buf.index];
  876. mfc_buf->used = 0;
  877. /* Mark destination as available for use by MFC */
  878. spin_lock_irqsave(&dev->irqlock, flags);
  879. set_bit(vb->v4l2_buf.index, &ctx->dec_dst_flag);
  880. list_add_tail(&mfc_buf->list, &ctx->dst_queue);
  881. ctx->dst_queue_cnt++;
  882. spin_unlock_irqrestore(&dev->irqlock, flags);
  883. } else {
  884. mfc_err("Unsupported buffer type (%d)\n", vq->type);
  885. }
  886. if (s5p_mfc_ctx_ready(ctx)) {
  887. spin_lock_irqsave(&dev->condlock, flags);
  888. set_bit(ctx->num, &dev->ctx_work_bits);
  889. spin_unlock_irqrestore(&dev->condlock, flags);
  890. }
  891. s5p_mfc_try_run(dev);
  892. }
  893. static struct vb2_ops s5p_mfc_dec_qops = {
  894. .queue_setup = s5p_mfc_queue_setup,
  895. .wait_prepare = s5p_mfc_unlock,
  896. .wait_finish = s5p_mfc_lock,
  897. .buf_init = s5p_mfc_buf_init,
  898. .start_streaming = s5p_mfc_start_streaming,
  899. .stop_streaming = s5p_mfc_stop_streaming,
  900. .buf_queue = s5p_mfc_buf_queue,
  901. };
  902. struct s5p_mfc_codec_ops *get_dec_codec_ops(void)
  903. {
  904. return &decoder_codec_ops;
  905. }
  906. struct vb2_ops *get_dec_queue_ops(void)
  907. {
  908. return &s5p_mfc_dec_qops;
  909. }
  910. const struct v4l2_ioctl_ops *get_dec_v4l2_ioctl_ops(void)
  911. {
  912. return &s5p_mfc_dec_ioctl_ops;
  913. }
  914. #define IS_MFC51_PRIV(x) ((V4L2_CTRL_ID2CLASS(x) == V4L2_CTRL_CLASS_MPEG) \
  915. && V4L2_CTRL_DRIVER_PRIV(x))
  916. int s5p_mfc_dec_ctrls_setup(struct s5p_mfc_ctx *ctx)
  917. {
  918. struct v4l2_ctrl_config cfg;
  919. int i;
  920. v4l2_ctrl_handler_init(&ctx->ctrl_handler, NUM_CTRLS);
  921. if (ctx->ctrl_handler.error) {
  922. mfc_err("v4l2_ctrl_handler_init failed\n");
  923. return ctx->ctrl_handler.error;
  924. }
  925. for (i = 0; i < NUM_CTRLS; i++) {
  926. if (IS_MFC51_PRIV(controls[i].id)) {
  927. cfg.ops = &s5p_mfc_dec_ctrl_ops;
  928. cfg.id = controls[i].id;
  929. cfg.min = controls[i].minimum;
  930. cfg.max = controls[i].maximum;
  931. cfg.def = controls[i].default_value;
  932. cfg.name = controls[i].name;
  933. cfg.type = controls[i].type;
  934. cfg.step = controls[i].step;
  935. cfg.menu_skip_mask = 0;
  936. ctx->ctrls[i] = v4l2_ctrl_new_custom(&ctx->ctrl_handler,
  937. &cfg, NULL);
  938. } else {
  939. ctx->ctrls[i] = v4l2_ctrl_new_std(&ctx->ctrl_handler,
  940. &s5p_mfc_dec_ctrl_ops,
  941. controls[i].id, controls[i].minimum,
  942. controls[i].maximum, controls[i].step,
  943. controls[i].default_value);
  944. }
  945. if (ctx->ctrl_handler.error) {
  946. mfc_err("Adding control (%d) failed\n", i);
  947. return ctx->ctrl_handler.error;
  948. }
  949. if (controls[i].is_volatile && ctx->ctrls[i])
  950. ctx->ctrls[i]->is_volatile = 1;
  951. }
  952. return 0;
  953. }
  954. void s5p_mfc_dec_ctrls_delete(struct s5p_mfc_ctx *ctx)
  955. {
  956. int i;
  957. v4l2_ctrl_handler_free(&ctx->ctrl_handler);
  958. for (i = 0; i < NUM_CTRLS; i++)
  959. ctx->ctrls[i] = NULL;
  960. }