1 // SPDX-License-Identifier: GPL-2.0
3 #include <media/v4l2-event.h>
4 #include <media/v4l2-mem2mem.h>
5 #include <media/videobuf2-dma-contig.h>
7 #include "mtk_vcodec_dec.h"
8 #include "mtk_vcodec_intr.h"
9 #include "mtk_vcodec_util.h"
10 #include "mtk_vcodec_dec_pm.h"
11 #include "vdec_drv_if.h"
13 static struct mtk_video_fmt mtk_video_formats[] = {
15 .fourcc = V4L2_PIX_FMT_H264,
18 .flags = V4L2_FMT_FLAG_DYN_RESOLUTION,
19 .frmsize = { MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16,
20 MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 },
23 .fourcc = V4L2_PIX_FMT_VP8,
26 .flags = V4L2_FMT_FLAG_DYN_RESOLUTION,
27 .frmsize = { MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16,
28 MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 },
31 .fourcc = V4L2_PIX_FMT_VP9,
34 .flags = V4L2_FMT_FLAG_DYN_RESOLUTION,
35 .frmsize = { MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16,
36 MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 },
39 .fourcc = V4L2_PIX_FMT_MT21C,
40 .type = MTK_FMT_FRAME,
45 static const unsigned int num_supported_formats =
46 ARRAY_SIZE(mtk_video_formats);
48 #define DEFAULT_OUT_FMT_IDX 0
49 #define DEFAULT_CAP_FMT_IDX 3
52 * This function tries to clean all display buffers, the buffers will return
54 * Note the buffers returned from codec driver may still be in driver's
57 static struct vb2_buffer *get_display_buffer(struct mtk_vcodec_dec_ctx *ctx)
59 struct vdec_fb *disp_frame_buffer = NULL;
60 struct mtk_video_dec_buf *dstbuf;
61 struct vb2_v4l2_buffer *vb;
63 mtk_v4l2_vdec_dbg(3, ctx, "[%d]", ctx->id);
64 if (vdec_if_get_param(ctx, GET_PARAM_DISP_FRAME_BUFFER,
65 &disp_frame_buffer)) {
66 mtk_v4l2_vdec_err(ctx, "[%d]Cannot get param : GET_PARAM_DISP_FRAME_BUFFER",
71 if (!disp_frame_buffer) {
72 mtk_v4l2_vdec_dbg(3, ctx, "No display frame buffer");
76 dstbuf = container_of(disp_frame_buffer, struct mtk_video_dec_buf,
78 vb = &dstbuf->m2m_buf.vb;
79 mutex_lock(&ctx->lock);
81 mtk_v4l2_vdec_dbg(2, ctx, "[%d]status=%x queue id=%d to done_list %d",
82 ctx->id, disp_frame_buffer->status,
83 vb->vb2_buf.index, dstbuf->queued_in_vb2);
85 v4l2_m2m_buf_done(vb, VB2_BUF_STATE_DONE);
86 ctx->decoded_frame_cnt++;
88 mutex_unlock(&ctx->lock);
93 * This function tries to clean all capture buffers that are not used as
94 * reference buffers by codec driver any more
95 * In this case, we need re-queue buffer to vb2 buffer if user space
96 * already returns this buffer to v4l2 or this buffer is just the output of
97 * previous sps/pps/resolution change decode, or do nothing if user
98 * space still owns this buffer
100 static struct vb2_buffer *get_free_buffer(struct mtk_vcodec_dec_ctx *ctx)
102 struct mtk_video_dec_buf *dstbuf;
103 struct vdec_fb *free_frame_buffer = NULL;
104 struct vb2_v4l2_buffer *vb;
106 if (vdec_if_get_param(ctx, GET_PARAM_FREE_FRAME_BUFFER,
107 &free_frame_buffer)) {
108 mtk_v4l2_vdec_err(ctx, "[%d] Error!! Cannot get param", ctx->id);
111 if (!free_frame_buffer) {
112 mtk_v4l2_vdec_dbg(3, ctx, " No free frame buffer");
116 mtk_v4l2_vdec_dbg(3, ctx, "[%d] tmp_frame_addr = 0x%p", ctx->id,
119 dstbuf = container_of(free_frame_buffer, struct mtk_video_dec_buf,
121 vb = &dstbuf->m2m_buf.vb;
123 mutex_lock(&ctx->lock);
125 if (dstbuf->queued_in_vb2 && dstbuf->queued_in_v4l2 &&
126 free_frame_buffer->status == FB_ST_FREE) {
128 * After decode sps/pps or non-display buffer, we don't
129 * need to return capture buffer to user space, but
130 * just re-queue this capture buffer to vb2 queue.
131 * This reduce overheads that dq/q unused capture
132 * buffer. In this case, queued_in_vb2 = true.
134 mtk_v4l2_vdec_dbg(2, ctx, "[%d]status=%x queue id=%d to rdy_queue %d",
135 ctx->id, free_frame_buffer->status,
136 vb->vb2_buf.index, dstbuf->queued_in_vb2);
137 v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
138 } else if (!dstbuf->queued_in_vb2 && dstbuf->queued_in_v4l2) {
140 * If buffer in v4l2 driver but not in vb2 queue yet,
141 * and we get this buffer from free_list, it means
142 * that codec driver do not use this buffer as
143 * reference buffer anymore. We should q buffer to vb2
144 * queue, so later work thread could get this buffer
145 * for decode. In this case, queued_in_vb2 = false
146 * means this buffer is not from previous decode
149 mtk_v4l2_vdec_dbg(2, ctx,
150 "[%d]status=%x queue id=%d to rdy_queue",
151 ctx->id, free_frame_buffer->status,
153 v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
154 dstbuf->queued_in_vb2 = true;
157 * Codec driver do not need to reference this capture
158 * buffer and this buffer is not in v4l2 driver.
159 * Then we don't need to do any thing, just add log when
160 * we need to debug buffer flow.
161 * When this buffer q from user space, it could
162 * directly q to vb2 buffer
164 mtk_v4l2_vdec_dbg(3, ctx, "[%d]status=%x err queue id=%d %d %d",
165 ctx->id, free_frame_buffer->status,
166 vb->vb2_buf.index, dstbuf->queued_in_vb2,
167 dstbuf->queued_in_v4l2);
169 dstbuf->used = false;
171 mutex_unlock(&ctx->lock);
175 static void clean_display_buffer(struct mtk_vcodec_dec_ctx *ctx)
177 while (get_display_buffer(ctx))
181 static void clean_free_buffer(struct mtk_vcodec_dec_ctx *ctx)
183 while (get_free_buffer(ctx))
187 static void mtk_vdec_queue_res_chg_event(struct mtk_vcodec_dec_ctx *ctx)
189 static const struct v4l2_event ev_src_ch = {
190 .type = V4L2_EVENT_SOURCE_CHANGE,
191 .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
194 mtk_v4l2_vdec_dbg(1, ctx, "[%d]", ctx->id);
195 v4l2_event_queue_fh(&ctx->fh, &ev_src_ch);
198 static int mtk_vdec_flush_decoder(struct mtk_vcodec_dec_ctx *ctx)
203 ret = vdec_if_decode(ctx, NULL, NULL, &res_chg);
205 mtk_v4l2_vdec_err(ctx, "DecodeFinal failed, ret=%d", ret);
207 clean_display_buffer(ctx);
208 clean_free_buffer(ctx);
213 static void mtk_vdec_update_fmt(struct mtk_vcodec_dec_ctx *ctx,
214 unsigned int pixelformat)
216 const struct mtk_video_fmt *fmt;
217 struct mtk_q_data *dst_q_data;
220 dst_q_data = &ctx->q_data[MTK_Q_DATA_DST];
221 for (k = 0; k < num_supported_formats; k++) {
222 fmt = &mtk_video_formats[k];
223 if (fmt->fourcc == pixelformat) {
224 mtk_v4l2_vdec_dbg(1, ctx, "Update cap fourcc(%d -> %d)",
225 dst_q_data->fmt->fourcc, pixelformat);
226 dst_q_data->fmt = fmt;
231 mtk_v4l2_vdec_err(ctx, "Cannot get fourcc(%d), using init value", pixelformat);
234 static int mtk_vdec_pic_info_update(struct mtk_vcodec_dec_ctx *ctx)
236 unsigned int dpbsize = 0;
239 if (vdec_if_get_param(ctx, GET_PARAM_PIC_INFO,
240 &ctx->last_decoded_picinfo)) {
241 mtk_v4l2_vdec_err(ctx, "[%d]Error!! Cannot get param : GET_PARAM_PICTURE_INFO ERR",
246 if (ctx->last_decoded_picinfo.pic_w == 0 ||
247 ctx->last_decoded_picinfo.pic_h == 0 ||
248 ctx->last_decoded_picinfo.buf_w == 0 ||
249 ctx->last_decoded_picinfo.buf_h == 0) {
250 mtk_v4l2_vdec_err(ctx, "Cannot get correct pic info");
254 if (ctx->last_decoded_picinfo.cap_fourcc != ctx->picinfo.cap_fourcc &&
255 ctx->picinfo.cap_fourcc != 0)
256 mtk_vdec_update_fmt(ctx, ctx->picinfo.cap_fourcc);
258 if (ctx->last_decoded_picinfo.pic_w == ctx->picinfo.pic_w ||
259 ctx->last_decoded_picinfo.pic_h == ctx->picinfo.pic_h)
262 mtk_v4l2_vdec_dbg(1, ctx, "[%d]-> new(%d,%d), old(%d,%d), real(%d,%d)", ctx->id,
263 ctx->last_decoded_picinfo.pic_w,
264 ctx->last_decoded_picinfo.pic_h, ctx->picinfo.pic_w,
265 ctx->picinfo.pic_h, ctx->last_decoded_picinfo.buf_w,
266 ctx->last_decoded_picinfo.buf_h);
268 ret = vdec_if_get_param(ctx, GET_PARAM_DPB_SIZE, &dpbsize);
270 mtk_v4l2_vdec_err(ctx, "Incorrect dpb size, ret=%d", ret);
272 ctx->dpb_size = dpbsize;
277 static void mtk_vdec_worker(struct work_struct *work)
279 struct mtk_vcodec_dec_ctx *ctx =
280 container_of(work, struct mtk_vcodec_dec_ctx, decode_work);
281 struct mtk_vcodec_dec_dev *dev = ctx->dev;
282 struct vb2_v4l2_buffer *src_buf, *dst_buf;
283 struct mtk_vcodec_mem buf;
285 bool res_chg = false;
287 struct mtk_video_dec_buf *dst_buf_info, *src_buf_info;
289 src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
291 v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
292 mtk_v4l2_vdec_dbg(1, ctx, "[%d] src_buf empty!!", ctx->id);
296 dst_buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
298 v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
299 mtk_v4l2_vdec_dbg(1, ctx, "[%d] dst_buf empty!!", ctx->id);
304 container_of(dst_buf, struct mtk_video_dec_buf, m2m_buf.vb);
306 pfb = &dst_buf_info->frame_buffer;
307 pfb->base_y.va = vb2_plane_vaddr(&dst_buf->vb2_buf, 0);
308 pfb->base_y.dma_addr =
309 vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0);
310 pfb->base_y.size = ctx->picinfo.fb_sz[0];
312 pfb->base_c.va = vb2_plane_vaddr(&dst_buf->vb2_buf, 1);
313 pfb->base_c.dma_addr =
314 vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 1);
315 pfb->base_c.size = ctx->picinfo.fb_sz[1];
317 mtk_v4l2_vdec_dbg(3, ctx, "===>[%d] vdec_if_decode() ===>", ctx->id);
319 mtk_v4l2_vdec_dbg(3, ctx,
320 "id=%d Framebuf pfb=%p VA=%p Y_DMA=%pad C_DMA=%pad Size=%zx",
321 dst_buf->vb2_buf.index, pfb, pfb->base_y.va,
322 &pfb->base_y.dma_addr, &pfb->base_c.dma_addr, pfb->base_y.size);
324 if (src_buf == &ctx->empty_flush_buf.vb) {
325 mtk_v4l2_vdec_dbg(1, ctx, "Got empty flush input buffer.");
326 src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
328 /* update dst buf status */
329 dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
330 mutex_lock(&ctx->lock);
331 dst_buf_info->used = false;
332 mutex_unlock(&ctx->lock);
334 vdec_if_decode(ctx, NULL, NULL, &res_chg);
335 clean_display_buffer(ctx);
336 vb2_set_plane_payload(&dst_buf->vb2_buf, 0, 0);
337 if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2)
338 vb2_set_plane_payload(&dst_buf->vb2_buf, 1, 0);
339 dst_buf->flags |= V4L2_BUF_FLAG_LAST;
340 v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_DONE);
341 clean_free_buffer(ctx);
342 v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
347 container_of(src_buf, struct mtk_video_dec_buf, m2m_buf.vb);
349 buf.va = vb2_plane_vaddr(&src_buf->vb2_buf, 0);
350 buf.dma_addr = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
351 buf.size = (size_t)src_buf->vb2_buf.planes[0].bytesused;
353 v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
354 mtk_v4l2_vdec_err(ctx, "[%d] id=%d src_addr is NULL!!", ctx->id,
355 src_buf->vb2_buf.index);
358 mtk_v4l2_vdec_dbg(3, ctx, "[%d] Bitstream VA=%p DMA=%pad Size=%zx vb=%p",
359 ctx->id, buf.va, &buf.dma_addr, buf.size, src_buf);
360 dst_buf->vb2_buf.timestamp = src_buf->vb2_buf.timestamp;
361 dst_buf->timecode = src_buf->timecode;
362 mutex_lock(&ctx->lock);
363 dst_buf_info->used = true;
364 mutex_unlock(&ctx->lock);
365 src_buf_info->used = true;
367 ret = vdec_if_decode(ctx, &buf, pfb, &res_chg);
370 mtk_v4l2_vdec_err(ctx,
371 "[%d] decode src[%d] sz=0x%zx pts=%llu dst[%d] ret=%d res_chg=%d",
372 ctx->id, src_buf->vb2_buf.index, buf.size,
373 src_buf->vb2_buf.timestamp, dst_buf->vb2_buf.index, ret, res_chg);
374 src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
376 mutex_lock(&ctx->lock);
377 src_buf_info->error = true;
378 mutex_unlock(&ctx->lock);
380 v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR);
381 } else if (!res_chg) {
383 * we only return src buffer with VB2_BUF_STATE_DONE
384 * when decode success without resolution change
386 src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
387 v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
390 dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
391 clean_display_buffer(ctx);
392 clean_free_buffer(ctx);
394 if (!ret && res_chg) {
395 mtk_vdec_pic_info_update(ctx);
397 * On encountering a resolution change in the stream.
398 * The driver must first process and decode all
399 * remaining buffers from before the resolution change
400 * point, so call flush decode here
402 mtk_vdec_flush_decoder(ctx);
404 * After all buffers containing decoded frames from
405 * before the resolution change point ready to be
406 * dequeued on the CAPTURE queue, the driver sends a
407 * V4L2_EVENT_SOURCE_CHANGE event for source change
408 * type V4L2_EVENT_SRC_CH_RESOLUTION
410 mtk_vdec_queue_res_chg_event(ctx);
412 v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
415 static void vb2ops_vdec_stateful_buf_queue(struct vb2_buffer *vb)
417 struct vb2_v4l2_buffer *src_buf;
418 struct mtk_vcodec_mem src_mem;
419 bool res_chg = false;
421 unsigned int dpbsize = 1, i;
422 struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
423 struct vb2_v4l2_buffer *vb2_v4l2;
424 struct mtk_q_data *dst_q_data;
426 mtk_v4l2_vdec_dbg(3, ctx, "[%d] (%d) id=%d, vb=%p", ctx->id,
427 vb->vb2_queue->type, vb->index, vb);
429 * check if this buffer is ready to be used after decode
431 if (vb->vb2_queue->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
432 struct mtk_video_dec_buf *buf;
434 vb2_v4l2 = to_vb2_v4l2_buffer(vb);
435 buf = container_of(vb2_v4l2, struct mtk_video_dec_buf,
437 mutex_lock(&ctx->lock);
439 v4l2_m2m_buf_queue(ctx->m2m_ctx, vb2_v4l2);
440 buf->queued_in_vb2 = true;
441 buf->queued_in_v4l2 = true;
443 buf->queued_in_vb2 = false;
444 buf->queued_in_v4l2 = true;
446 mutex_unlock(&ctx->lock);
450 v4l2_m2m_buf_queue(ctx->m2m_ctx, to_vb2_v4l2_buffer(vb));
452 if (ctx->state != MTK_STATE_INIT) {
453 mtk_v4l2_vdec_dbg(3, ctx, "[%d] already init driver %d", ctx->id, ctx->state);
457 src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
459 mtk_v4l2_vdec_err(ctx, "No src buffer");
463 if (src_buf == &ctx->empty_flush_buf.vb) {
464 /* This shouldn't happen. Just in case. */
465 mtk_v4l2_vdec_err(ctx, "Invalid flush buffer.");
466 v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
470 src_mem.va = vb2_plane_vaddr(&src_buf->vb2_buf, 0);
471 src_mem.dma_addr = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
472 src_mem.size = (size_t)src_buf->vb2_buf.planes[0].bytesused;
473 mtk_v4l2_vdec_dbg(2, ctx, "[%d] buf id=%d va=%p dma=%pad size=%zx", ctx->id,
474 src_buf->vb2_buf.index, src_mem.va, &src_mem.dma_addr, src_mem.size);
476 ret = vdec_if_decode(ctx, &src_mem, NULL, &res_chg);
477 if (ret || !res_chg) {
479 * fb == NULL means to parse SPS/PPS header or
480 * resolution info in src_mem. Decode can fail
481 * if there is no SPS header or picture info
485 src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
487 mtk_v4l2_vdec_err(ctx, "[%d] Unrecoverable error in vdec_if_decode.",
489 ctx->state = MTK_STATE_ABORT;
490 v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR);
492 v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
494 mtk_v4l2_vdec_dbg(ret ? 0 : 1, ctx,
495 "[%d] decode() src_buf=%d, size=%zu, fail=%d, res_chg=%d",
496 ctx->id, src_buf->vb2_buf.index, src_mem.size, ret, res_chg);
500 if (vdec_if_get_param(ctx, GET_PARAM_PIC_INFO, &ctx->picinfo)) {
501 mtk_v4l2_vdec_err(ctx, "[%d]Error!! Cannot get param : GET_PARAM_PICTURE_INFO ERR",
506 ctx->last_decoded_picinfo = ctx->picinfo;
507 dst_q_data = &ctx->q_data[MTK_Q_DATA_DST];
508 for (i = 0; i < dst_q_data->fmt->num_planes; i++) {
509 dst_q_data->sizeimage[i] = ctx->picinfo.fb_sz[i];
510 dst_q_data->bytesperline[i] = ctx->picinfo.buf_w;
513 mtk_v4l2_vdec_dbg(2, ctx, "[%d] init OK wxh=%dx%d pic wxh=%dx%d sz[0]=0x%x sz[1]=0x%x",
514 ctx->id, ctx->picinfo.buf_w, ctx->picinfo.buf_h, ctx->picinfo.pic_w,
515 ctx->picinfo.pic_h, dst_q_data->sizeimage[0], dst_q_data->sizeimage[1]);
517 ret = vdec_if_get_param(ctx, GET_PARAM_DPB_SIZE, &dpbsize);
519 mtk_v4l2_vdec_err(ctx, "[%d] GET_PARAM_DPB_SIZE fail=%d", ctx->id, ret);
521 ctx->dpb_size = dpbsize;
522 ctx->state = MTK_STATE_HEADER;
523 mtk_v4l2_vdec_dbg(1, ctx, "[%d] dpbsize=%d", ctx->id, ctx->dpb_size);
525 mtk_vdec_queue_res_chg_event(ctx);
528 static int mtk_vdec_g_v_ctrl(struct v4l2_ctrl *ctrl)
530 struct mtk_vcodec_dec_ctx *ctx = ctrl_to_dec_ctx(ctrl);
534 case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
535 if (ctx->state >= MTK_STATE_HEADER) {
536 ctrl->val = ctx->dpb_size;
538 mtk_v4l2_vdec_dbg(0, ctx, "Seqinfo not ready");
548 static const struct v4l2_ctrl_ops mtk_vcodec_dec_ctrl_ops = {
549 .g_volatile_ctrl = mtk_vdec_g_v_ctrl,
552 static int mtk_vcodec_dec_ctrls_setup(struct mtk_vcodec_dec_ctx *ctx)
554 struct v4l2_ctrl *ctrl;
556 v4l2_ctrl_handler_init(&ctx->ctrl_hdl, 1);
558 ctrl = v4l2_ctrl_new_std(&ctx->ctrl_hdl, &mtk_vcodec_dec_ctrl_ops,
559 V4L2_CID_MIN_BUFFERS_FOR_CAPTURE, 0, 32, 1, 1);
560 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
561 v4l2_ctrl_new_std_menu(&ctx->ctrl_hdl, &mtk_vcodec_dec_ctrl_ops,
562 V4L2_CID_MPEG_VIDEO_VP9_PROFILE,
563 V4L2_MPEG_VIDEO_VP9_PROFILE_0, 0,
564 V4L2_MPEG_VIDEO_VP9_PROFILE_0);
566 * H264. Baseline / Extended decoding is not supported.
568 v4l2_ctrl_new_std_menu(&ctx->ctrl_hdl, &mtk_vcodec_dec_ctrl_ops,
569 V4L2_CID_MPEG_VIDEO_H264_PROFILE, V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
570 BIT(V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
571 BIT(V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED),
572 V4L2_MPEG_VIDEO_H264_PROFILE_MAIN);
574 if (ctx->ctrl_hdl.error) {
575 mtk_v4l2_vdec_err(ctx, "Adding control failed %d", ctx->ctrl_hdl.error);
576 return ctx->ctrl_hdl.error;
579 v4l2_ctrl_handler_setup(&ctx->ctrl_hdl);
583 static void mtk_init_vdec_params(struct mtk_vcodec_dec_ctx *ctx)
587 if (!(ctx->dev->dec_capability & VCODEC_CAPABILITY_4K_DISABLED)) {
588 for (i = 0; i < num_supported_formats; i++) {
589 if (mtk_video_formats[i].type != MTK_FMT_DEC)
592 mtk_video_formats[i].frmsize.max_width =
593 VCODEC_DEC_4K_CODED_WIDTH;
594 mtk_video_formats[i].frmsize.max_height =
595 VCODEC_DEC_4K_CODED_HEIGHT;
600 static struct vb2_ops mtk_vdec_frame_vb2_ops = {
601 .queue_setup = vb2ops_vdec_queue_setup,
602 .buf_prepare = vb2ops_vdec_buf_prepare,
603 .wait_prepare = vb2_ops_wait_prepare,
604 .wait_finish = vb2_ops_wait_finish,
605 .start_streaming = vb2ops_vdec_start_streaming,
607 .buf_queue = vb2ops_vdec_stateful_buf_queue,
608 .buf_init = vb2ops_vdec_buf_init,
609 .buf_finish = vb2ops_vdec_buf_finish,
610 .stop_streaming = vb2ops_vdec_stop_streaming,
613 const struct mtk_vcodec_dec_pdata mtk_vdec_8173_pdata = {
614 .init_vdec_params = mtk_init_vdec_params,
615 .ctrls_setup = mtk_vcodec_dec_ctrls_setup,
616 .vdec_vb2_ops = &mtk_vdec_frame_vb2_ops,
617 .vdec_formats = mtk_video_formats,
618 .num_formats = &num_supported_formats,
619 .default_out_fmt = &mtk_video_formats[DEFAULT_OUT_FMT_IDX],
620 .default_cap_fmt = &mtk_video_formats[DEFAULT_CAP_FMT_IDX],
621 .worker = mtk_vdec_worker,
622 .flush_decoder = mtk_vdec_flush_decoder,
623 .is_subdev_supported = false,
624 .hw_arch = MTK_VDEC_PURE_SINGLE_CORE,