s5p_mfc_dec.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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_MPLANE |
  213. V4L2_CAP_VIDEO_OUTPUT_MPLANE | 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,
  700. const struct v4l2_format *fmt, unsigned int *buf_count,
  701. unsigned int *plane_count, unsigned int psize[],
  702. void *allocators[])
  703. {
  704. struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
  705. /* Video output for decoding (source)
  706. * this can be set after getting an instance */
  707. if (ctx->state == MFCINST_INIT &&
  708. vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  709. /* A single plane is required for input */
  710. *plane_count = 1;
  711. if (*buf_count < 1)
  712. *buf_count = 1;
  713. if (*buf_count > MFC_MAX_BUFFERS)
  714. *buf_count = MFC_MAX_BUFFERS;
  715. /* Video capture for decoding (destination)
  716. * this can be set after the header was parsed */
  717. } else if (ctx->state == MFCINST_HEAD_PARSED &&
  718. vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  719. /* Output plane count is 2 - one for Y and one for CbCr */
  720. *plane_count = 2;
  721. /* Setup buffer count */
  722. if (*buf_count < ctx->dpb_count)
  723. *buf_count = ctx->dpb_count;
  724. if (*buf_count > ctx->dpb_count + MFC_MAX_EXTRA_DPB)
  725. *buf_count = ctx->dpb_count + MFC_MAX_EXTRA_DPB;
  726. if (*buf_count > MFC_MAX_BUFFERS)
  727. *buf_count = MFC_MAX_BUFFERS;
  728. } else {
  729. mfc_err("State seems invalid. State = %d, vq->type = %d\n",
  730. ctx->state, vq->type);
  731. return -EINVAL;
  732. }
  733. mfc_debug(2, "Buffer count=%d, plane count=%d\n",
  734. *buf_count, *plane_count);
  735. if (ctx->state == MFCINST_HEAD_PARSED &&
  736. vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  737. psize[0] = ctx->luma_size;
  738. psize[1] = ctx->chroma_size;
  739. allocators[0] = ctx->dev->alloc_ctx[MFC_BANK2_ALLOC_CTX];
  740. allocators[1] = ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
  741. } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE &&
  742. ctx->state == MFCINST_INIT) {
  743. psize[0] = ctx->dec_src_buf_size;
  744. allocators[0] = ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
  745. } else {
  746. mfc_err("This video node is dedicated to decoding. Decoding not initalised\n");
  747. return -EINVAL;
  748. }
  749. return 0;
  750. }
  751. static void s5p_mfc_unlock(struct vb2_queue *q)
  752. {
  753. struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
  754. struct s5p_mfc_dev *dev = ctx->dev;
  755. mutex_unlock(&dev->mfc_mutex);
  756. }
  757. static void s5p_mfc_lock(struct vb2_queue *q)
  758. {
  759. struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
  760. struct s5p_mfc_dev *dev = ctx->dev;
  761. mutex_lock(&dev->mfc_mutex);
  762. }
  763. static int s5p_mfc_buf_init(struct vb2_buffer *vb)
  764. {
  765. struct vb2_queue *vq = vb->vb2_queue;
  766. struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
  767. unsigned int i;
  768. if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  769. if (ctx->capture_state == QUEUE_BUFS_MMAPED)
  770. return 0;
  771. for (i = 0; i <= ctx->src_fmt->num_planes ; i++) {
  772. if (IS_ERR_OR_NULL(ERR_PTR(
  773. vb2_dma_contig_plane_dma_addr(vb, i)))) {
  774. mfc_err("Plane mem not allocated\n");
  775. return -EINVAL;
  776. }
  777. }
  778. if (vb2_plane_size(vb, 0) < ctx->luma_size ||
  779. vb2_plane_size(vb, 1) < ctx->chroma_size) {
  780. mfc_err("Plane buffer (CAPTURE) is too small\n");
  781. return -EINVAL;
  782. }
  783. i = vb->v4l2_buf.index;
  784. ctx->dst_bufs[i].b = vb;
  785. ctx->dst_bufs[i].cookie.raw.luma =
  786. vb2_dma_contig_plane_dma_addr(vb, 0);
  787. ctx->dst_bufs[i].cookie.raw.chroma =
  788. vb2_dma_contig_plane_dma_addr(vb, 1);
  789. ctx->dst_bufs_cnt++;
  790. } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  791. if (IS_ERR_OR_NULL(ERR_PTR(
  792. vb2_dma_contig_plane_dma_addr(vb, 0)))) {
  793. mfc_err("Plane memory not allocated\n");
  794. return -EINVAL;
  795. }
  796. if (vb2_plane_size(vb, 0) < ctx->dec_src_buf_size) {
  797. mfc_err("Plane buffer (OUTPUT) is too small\n");
  798. return -EINVAL;
  799. }
  800. i = vb->v4l2_buf.index;
  801. ctx->src_bufs[i].b = vb;
  802. ctx->src_bufs[i].cookie.stream =
  803. vb2_dma_contig_plane_dma_addr(vb, 0);
  804. ctx->src_bufs_cnt++;
  805. } else {
  806. mfc_err("s5p_mfc_buf_init: unknown queue type\n");
  807. return -EINVAL;
  808. }
  809. return 0;
  810. }
  811. static int s5p_mfc_start_streaming(struct vb2_queue *q, unsigned int count)
  812. {
  813. struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
  814. struct s5p_mfc_dev *dev = ctx->dev;
  815. unsigned long flags;
  816. v4l2_ctrl_handler_setup(&ctx->ctrl_handler);
  817. if (ctx->state == MFCINST_FINISHING ||
  818. ctx->state == MFCINST_FINISHED)
  819. ctx->state = MFCINST_RUNNING;
  820. /* If context is ready then dev = work->data;schedule it to run */
  821. if (s5p_mfc_ctx_ready(ctx)) {
  822. spin_lock_irqsave(&dev->condlock, flags);
  823. set_bit(ctx->num, &dev->ctx_work_bits);
  824. spin_unlock_irqrestore(&dev->condlock, flags);
  825. }
  826. s5p_mfc_try_run(dev);
  827. return 0;
  828. }
  829. static int s5p_mfc_stop_streaming(struct vb2_queue *q)
  830. {
  831. unsigned long flags;
  832. struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
  833. struct s5p_mfc_dev *dev = ctx->dev;
  834. int aborted = 0;
  835. if ((ctx->state == MFCINST_FINISHING ||
  836. ctx->state == MFCINST_RUNNING) &&
  837. dev->curr_ctx == ctx->num && dev->hw_lock) {
  838. ctx->state = MFCINST_ABORT;
  839. s5p_mfc_wait_for_done_ctx(ctx,
  840. S5P_FIMV_R2H_CMD_FRAME_DONE_RET, 0);
  841. aborted = 1;
  842. }
  843. spin_lock_irqsave(&dev->irqlock, flags);
  844. if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  845. s5p_mfc_cleanup_queue(&ctx->dst_queue, &ctx->vq_dst);
  846. INIT_LIST_HEAD(&ctx->dst_queue);
  847. ctx->dst_queue_cnt = 0;
  848. ctx->dpb_flush_flag = 1;
  849. ctx->dec_dst_flag = 0;
  850. }
  851. if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  852. s5p_mfc_cleanup_queue(&ctx->src_queue, &ctx->vq_src);
  853. INIT_LIST_HEAD(&ctx->src_queue);
  854. ctx->src_queue_cnt = 0;
  855. }
  856. if (aborted)
  857. ctx->state = MFCINST_RUNNING;
  858. spin_unlock_irqrestore(&dev->irqlock, flags);
  859. return 0;
  860. }
  861. static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
  862. {
  863. struct vb2_queue *vq = vb->vb2_queue;
  864. struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
  865. struct s5p_mfc_dev *dev = ctx->dev;
  866. unsigned long flags;
  867. struct s5p_mfc_buf *mfc_buf;
  868. if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  869. mfc_buf = &ctx->src_bufs[vb->v4l2_buf.index];
  870. mfc_buf->used = 0;
  871. spin_lock_irqsave(&dev->irqlock, flags);
  872. list_add_tail(&mfc_buf->list, &ctx->src_queue);
  873. ctx->src_queue_cnt++;
  874. spin_unlock_irqrestore(&dev->irqlock, flags);
  875. } else if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  876. mfc_buf = &ctx->dst_bufs[vb->v4l2_buf.index];
  877. mfc_buf->used = 0;
  878. /* Mark destination as available for use by MFC */
  879. spin_lock_irqsave(&dev->irqlock, flags);
  880. set_bit(vb->v4l2_buf.index, &ctx->dec_dst_flag);
  881. list_add_tail(&mfc_buf->list, &ctx->dst_queue);
  882. ctx->dst_queue_cnt++;
  883. spin_unlock_irqrestore(&dev->irqlock, flags);
  884. } else {
  885. mfc_err("Unsupported buffer type (%d)\n", vq->type);
  886. }
  887. if (s5p_mfc_ctx_ready(ctx)) {
  888. spin_lock_irqsave(&dev->condlock, flags);
  889. set_bit(ctx->num, &dev->ctx_work_bits);
  890. spin_unlock_irqrestore(&dev->condlock, flags);
  891. }
  892. s5p_mfc_try_run(dev);
  893. }
  894. static struct vb2_ops s5p_mfc_dec_qops = {
  895. .queue_setup = s5p_mfc_queue_setup,
  896. .wait_prepare = s5p_mfc_unlock,
  897. .wait_finish = s5p_mfc_lock,
  898. .buf_init = s5p_mfc_buf_init,
  899. .start_streaming = s5p_mfc_start_streaming,
  900. .stop_streaming = s5p_mfc_stop_streaming,
  901. .buf_queue = s5p_mfc_buf_queue,
  902. };
  903. struct s5p_mfc_codec_ops *get_dec_codec_ops(void)
  904. {
  905. return &decoder_codec_ops;
  906. }
  907. struct vb2_ops *get_dec_queue_ops(void)
  908. {
  909. return &s5p_mfc_dec_qops;
  910. }
  911. const struct v4l2_ioctl_ops *get_dec_v4l2_ioctl_ops(void)
  912. {
  913. return &s5p_mfc_dec_ioctl_ops;
  914. }
  915. #define IS_MFC51_PRIV(x) ((V4L2_CTRL_ID2CLASS(x) == V4L2_CTRL_CLASS_MPEG) \
  916. && V4L2_CTRL_DRIVER_PRIV(x))
  917. int s5p_mfc_dec_ctrls_setup(struct s5p_mfc_ctx *ctx)
  918. {
  919. struct v4l2_ctrl_config cfg;
  920. int i;
  921. v4l2_ctrl_handler_init(&ctx->ctrl_handler, NUM_CTRLS);
  922. if (ctx->ctrl_handler.error) {
  923. mfc_err("v4l2_ctrl_handler_init failed\n");
  924. return ctx->ctrl_handler.error;
  925. }
  926. for (i = 0; i < NUM_CTRLS; i++) {
  927. if (IS_MFC51_PRIV(controls[i].id)) {
  928. cfg.ops = &s5p_mfc_dec_ctrl_ops;
  929. cfg.id = controls[i].id;
  930. cfg.min = controls[i].minimum;
  931. cfg.max = controls[i].maximum;
  932. cfg.def = controls[i].default_value;
  933. cfg.name = controls[i].name;
  934. cfg.type = controls[i].type;
  935. cfg.step = controls[i].step;
  936. cfg.menu_skip_mask = 0;
  937. ctx->ctrls[i] = v4l2_ctrl_new_custom(&ctx->ctrl_handler,
  938. &cfg, NULL);
  939. } else {
  940. ctx->ctrls[i] = v4l2_ctrl_new_std(&ctx->ctrl_handler,
  941. &s5p_mfc_dec_ctrl_ops,
  942. controls[i].id, controls[i].minimum,
  943. controls[i].maximum, controls[i].step,
  944. controls[i].default_value);
  945. }
  946. if (ctx->ctrl_handler.error) {
  947. mfc_err("Adding control (%d) failed\n", i);
  948. return ctx->ctrl_handler.error;
  949. }
  950. if (controls[i].is_volatile && ctx->ctrls[i])
  951. ctx->ctrls[i]->flags |= V4L2_CTRL_FLAG_VOLATILE;
  952. }
  953. return 0;
  954. }
  955. void s5p_mfc_dec_ctrls_delete(struct s5p_mfc_ctx *ctx)
  956. {
  957. int i;
  958. v4l2_ctrl_handler_free(&ctx->ctrl_handler);
  959. for (i = 0; i < NUM_CTRLS; i++)
  960. ctx->ctrls[i] = NULL;
  961. }