1*0934d375SYunfei Dong // SPDX-License-Identifier: GPL-2.0
2*0934d375SYunfei Dong 
3*0934d375SYunfei Dong #include <media/v4l2-event.h>
4*0934d375SYunfei Dong #include <media/v4l2-mem2mem.h>
5*0934d375SYunfei Dong #include <media/videobuf2-dma-contig.h>
6*0934d375SYunfei Dong 
7*0934d375SYunfei Dong #include "mtk_vcodec_dec.h"
8*0934d375SYunfei Dong #include "mtk_vcodec_dec_pm.h"
9*0934d375SYunfei Dong #include "vdec_drv_if.h"
10*0934d375SYunfei Dong 
11*0934d375SYunfei Dong static struct mtk_video_fmt mtk_video_formats[] = {
12*0934d375SYunfei Dong 	{
13*0934d375SYunfei Dong 		.fourcc = V4L2_PIX_FMT_H264,
14*0934d375SYunfei Dong 		.type = MTK_FMT_DEC,
15*0934d375SYunfei Dong 		.num_planes = 1,
16*0934d375SYunfei Dong 		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION,
17*0934d375SYunfei Dong 		.frmsize = { MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16,
18*0934d375SYunfei Dong 			     MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 },
19*0934d375SYunfei Dong 	},
20*0934d375SYunfei Dong 	{
21*0934d375SYunfei Dong 		.fourcc = V4L2_PIX_FMT_VP8,
22*0934d375SYunfei Dong 		.type = MTK_FMT_DEC,
23*0934d375SYunfei Dong 		.num_planes = 1,
24*0934d375SYunfei Dong 		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION,
25*0934d375SYunfei Dong 		.frmsize = { MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16,
26*0934d375SYunfei Dong 			     MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 },
27*0934d375SYunfei Dong 	},
28*0934d375SYunfei Dong 	{
29*0934d375SYunfei Dong 		.fourcc = V4L2_PIX_FMT_VP9,
30*0934d375SYunfei Dong 		.type = MTK_FMT_DEC,
31*0934d375SYunfei Dong 		.num_planes = 1,
32*0934d375SYunfei Dong 		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION,
33*0934d375SYunfei Dong 		.frmsize = { MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16,
34*0934d375SYunfei Dong 			     MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 },
35*0934d375SYunfei Dong 	},
36*0934d375SYunfei Dong 	{
37*0934d375SYunfei Dong 		.fourcc = V4L2_PIX_FMT_MT21C,
38*0934d375SYunfei Dong 		.type = MTK_FMT_FRAME,
39*0934d375SYunfei Dong 		.num_planes = 2,
40*0934d375SYunfei Dong 	},
41*0934d375SYunfei Dong };
42*0934d375SYunfei Dong 
43*0934d375SYunfei Dong static const unsigned int num_supported_formats =
44*0934d375SYunfei Dong 	ARRAY_SIZE(mtk_video_formats);
45*0934d375SYunfei Dong 
46*0934d375SYunfei Dong #define DEFAULT_OUT_FMT_IDX 0
47*0934d375SYunfei Dong #define DEFAULT_CAP_FMT_IDX 3
48*0934d375SYunfei Dong 
49*0934d375SYunfei Dong /*
50*0934d375SYunfei Dong  * This function tries to clean all display buffers, the buffers will return
51*0934d375SYunfei Dong  * in display order.
52*0934d375SYunfei Dong  * Note the buffers returned from codec driver may still be in driver's
53*0934d375SYunfei Dong  * reference list.
54*0934d375SYunfei Dong  */
get_display_buffer(struct mtk_vcodec_dec_ctx * ctx)55*0934d375SYunfei Dong static struct vb2_buffer *get_display_buffer(struct mtk_vcodec_dec_ctx *ctx)
56*0934d375SYunfei Dong {
57*0934d375SYunfei Dong 	struct vdec_fb *disp_frame_buffer = NULL;
58*0934d375SYunfei Dong 	struct mtk_video_dec_buf *dstbuf;
59*0934d375SYunfei Dong 	struct vb2_v4l2_buffer *vb;
60*0934d375SYunfei Dong 
61*0934d375SYunfei Dong 	mtk_v4l2_vdec_dbg(3, ctx, "[%d]", ctx->id);
62*0934d375SYunfei Dong 	if (vdec_if_get_param(ctx, GET_PARAM_DISP_FRAME_BUFFER,
63*0934d375SYunfei Dong 			      &disp_frame_buffer)) {
64*0934d375SYunfei Dong 		mtk_v4l2_vdec_err(ctx, "[%d]Cannot get param : GET_PARAM_DISP_FRAME_BUFFER",
65*0934d375SYunfei Dong 				  ctx->id);
66*0934d375SYunfei Dong 		return NULL;
67*0934d375SYunfei Dong 	}
68*0934d375SYunfei Dong 
69*0934d375SYunfei Dong 	if (!disp_frame_buffer) {
70*0934d375SYunfei Dong 		mtk_v4l2_vdec_dbg(3, ctx, "No display frame buffer");
71*0934d375SYunfei Dong 		return NULL;
72*0934d375SYunfei Dong 	}
73*0934d375SYunfei Dong 
74*0934d375SYunfei Dong 	dstbuf = container_of(disp_frame_buffer, struct mtk_video_dec_buf,
75*0934d375SYunfei Dong 			      frame_buffer);
76*0934d375SYunfei Dong 	vb = &dstbuf->m2m_buf.vb;
77*0934d375SYunfei Dong 	mutex_lock(&ctx->lock);
78*0934d375SYunfei Dong 	if (dstbuf->used) {
79*0934d375SYunfei Dong 		mtk_v4l2_vdec_dbg(2, ctx, "[%d]status=%x queue id=%d to done_list %d",
80*0934d375SYunfei Dong 				  ctx->id, disp_frame_buffer->status,
81*0934d375SYunfei Dong 				  vb->vb2_buf.index, dstbuf->queued_in_vb2);
82*0934d375SYunfei Dong 
83*0934d375SYunfei Dong 		v4l2_m2m_buf_done(vb, VB2_BUF_STATE_DONE);
84*0934d375SYunfei Dong 		ctx->decoded_frame_cnt++;
85*0934d375SYunfei Dong 	}
86*0934d375SYunfei Dong 	mutex_unlock(&ctx->lock);
87*0934d375SYunfei Dong 	return &vb->vb2_buf;
88*0934d375SYunfei Dong }
89*0934d375SYunfei Dong 
90*0934d375SYunfei Dong /*
91*0934d375SYunfei Dong  * This function tries to clean all capture buffers that are not used as
92*0934d375SYunfei Dong  * reference buffers by codec driver any more
93*0934d375SYunfei Dong  * In this case, we need re-queue buffer to vb2 buffer if user space
94*0934d375SYunfei Dong  * already returns this buffer to v4l2 or this buffer is just the output of
95*0934d375SYunfei Dong  * previous sps/pps/resolution change decode, or do nothing if user
96*0934d375SYunfei Dong  * space still owns this buffer
97*0934d375SYunfei Dong  */
get_free_buffer(struct mtk_vcodec_dec_ctx * ctx)98*0934d375SYunfei Dong static struct vb2_buffer *get_free_buffer(struct mtk_vcodec_dec_ctx *ctx)
99*0934d375SYunfei Dong {
100*0934d375SYunfei Dong 	struct mtk_video_dec_buf *dstbuf;
101*0934d375SYunfei Dong 	struct vdec_fb *free_frame_buffer = NULL;
102*0934d375SYunfei Dong 	struct vb2_v4l2_buffer *vb;
103*0934d375SYunfei Dong 
104*0934d375SYunfei Dong 	if (vdec_if_get_param(ctx, GET_PARAM_FREE_FRAME_BUFFER,
105*0934d375SYunfei Dong 			      &free_frame_buffer)) {
106*0934d375SYunfei Dong 		mtk_v4l2_vdec_err(ctx, "[%d] Error!! Cannot get param", ctx->id);
107*0934d375SYunfei Dong 		return NULL;
108*0934d375SYunfei Dong 	}
109*0934d375SYunfei Dong 	if (!free_frame_buffer) {
110*0934d375SYunfei Dong 		mtk_v4l2_vdec_dbg(3, ctx, " No free frame buffer");
111*0934d375SYunfei Dong 		return NULL;
112*0934d375SYunfei Dong 	}
113*0934d375SYunfei Dong 
114*0934d375SYunfei Dong 	mtk_v4l2_vdec_dbg(3, ctx, "[%d] tmp_frame_addr = 0x%p", ctx->id,
115*0934d375SYunfei Dong 			  free_frame_buffer);
116*0934d375SYunfei Dong 
117*0934d375SYunfei Dong 	dstbuf = container_of(free_frame_buffer, struct mtk_video_dec_buf,
118*0934d375SYunfei Dong 			      frame_buffer);
119*0934d375SYunfei Dong 	vb = &dstbuf->m2m_buf.vb;
120*0934d375SYunfei Dong 
121*0934d375SYunfei Dong 	mutex_lock(&ctx->lock);
122*0934d375SYunfei Dong 	if (dstbuf->used) {
123*0934d375SYunfei Dong 		if (dstbuf->queued_in_vb2 && dstbuf->queued_in_v4l2 &&
124*0934d375SYunfei Dong 		    free_frame_buffer->status == FB_ST_FREE) {
125*0934d375SYunfei Dong 			/*
126*0934d375SYunfei Dong 			 * After decode sps/pps or non-display buffer, we don't
127*0934d375SYunfei Dong 			 * need to return capture buffer to user space, but
128*0934d375SYunfei Dong 			 * just re-queue this capture buffer to vb2 queue.
129*0934d375SYunfei Dong 			 * This reduce overheads that dq/q unused capture
130*0934d375SYunfei Dong 			 * buffer. In this case, queued_in_vb2 = true.
131*0934d375SYunfei Dong 			 */
132*0934d375SYunfei Dong 			mtk_v4l2_vdec_dbg(2, ctx, "[%d]status=%x queue id=%d to rdy_queue %d",
133*0934d375SYunfei Dong 					  ctx->id, free_frame_buffer->status,
134*0934d375SYunfei Dong 					  vb->vb2_buf.index, dstbuf->queued_in_vb2);
135*0934d375SYunfei Dong 			v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
136*0934d375SYunfei Dong 		} else if (!dstbuf->queued_in_vb2 && dstbuf->queued_in_v4l2) {
137*0934d375SYunfei Dong 			/*
138*0934d375SYunfei Dong 			 * If buffer in v4l2 driver but not in vb2 queue yet,
139*0934d375SYunfei Dong 			 * and we get this buffer from free_list, it means
140*0934d375SYunfei Dong 			 * that codec driver do not use this buffer as
141*0934d375SYunfei Dong 			 * reference buffer anymore. We should q buffer to vb2
142*0934d375SYunfei Dong 			 * queue, so later work thread could get this buffer
143*0934d375SYunfei Dong 			 * for decode. In this case, queued_in_vb2 = false
144*0934d375SYunfei Dong 			 * means this buffer is not from previous decode
145*0934d375SYunfei Dong 			 * output.
146*0934d375SYunfei Dong 			 */
147*0934d375SYunfei Dong 			mtk_v4l2_vdec_dbg(2, ctx,
148*0934d375SYunfei Dong 					  "[%d]status=%x queue id=%d to rdy_queue",
149*0934d375SYunfei Dong 					  ctx->id, free_frame_buffer->status,
150*0934d375SYunfei Dong 					  vb->vb2_buf.index);
151*0934d375SYunfei Dong 			v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
152*0934d375SYunfei Dong 			dstbuf->queued_in_vb2 = true;
153*0934d375SYunfei Dong 		} else {
154*0934d375SYunfei Dong 			/*
155*0934d375SYunfei Dong 			 * Codec driver do not need to reference this capture
156*0934d375SYunfei Dong 			 * buffer and this buffer is not in v4l2 driver.
157*0934d375SYunfei Dong 			 * Then we don't need to do any thing, just add log when
158*0934d375SYunfei Dong 			 * we need to debug buffer flow.
159*0934d375SYunfei Dong 			 * When this buffer q from user space, it could
160*0934d375SYunfei Dong 			 * directly q to vb2 buffer
161*0934d375SYunfei Dong 			 */
162*0934d375SYunfei Dong 			mtk_v4l2_vdec_dbg(3, ctx, "[%d]status=%x err queue id=%d %d %d",
163*0934d375SYunfei Dong 					  ctx->id, free_frame_buffer->status,
164*0934d375SYunfei Dong 					  vb->vb2_buf.index, dstbuf->queued_in_vb2,
165*0934d375SYunfei Dong 					  dstbuf->queued_in_v4l2);
166*0934d375SYunfei Dong 		}
167*0934d375SYunfei Dong 		dstbuf->used = false;
168*0934d375SYunfei Dong 	}
169*0934d375SYunfei Dong 	mutex_unlock(&ctx->lock);
170*0934d375SYunfei Dong 	return &vb->vb2_buf;
171*0934d375SYunfei Dong }
172*0934d375SYunfei Dong 
clean_display_buffer(struct mtk_vcodec_dec_ctx * ctx)173*0934d375SYunfei Dong static void clean_display_buffer(struct mtk_vcodec_dec_ctx *ctx)
174*0934d375SYunfei Dong {
175*0934d375SYunfei Dong 	while (get_display_buffer(ctx))
176*0934d375SYunfei Dong 		;
177*0934d375SYunfei Dong }
178*0934d375SYunfei Dong 
clean_free_buffer(struct mtk_vcodec_dec_ctx * ctx)179*0934d375SYunfei Dong static void clean_free_buffer(struct mtk_vcodec_dec_ctx *ctx)
180*0934d375SYunfei Dong {
181*0934d375SYunfei Dong 	while (get_free_buffer(ctx))
182*0934d375SYunfei Dong 		;
183*0934d375SYunfei Dong }
184*0934d375SYunfei Dong 
mtk_vdec_queue_res_chg_event(struct mtk_vcodec_dec_ctx * ctx)185*0934d375SYunfei Dong static void mtk_vdec_queue_res_chg_event(struct mtk_vcodec_dec_ctx *ctx)
186*0934d375SYunfei Dong {
187*0934d375SYunfei Dong 	static const struct v4l2_event ev_src_ch = {
188*0934d375SYunfei Dong 		.type = V4L2_EVENT_SOURCE_CHANGE,
189*0934d375SYunfei Dong 		.u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
190*0934d375SYunfei Dong 	};
191*0934d375SYunfei Dong 
192*0934d375SYunfei Dong 	mtk_v4l2_vdec_dbg(1, ctx, "[%d]", ctx->id);
193*0934d375SYunfei Dong 	v4l2_event_queue_fh(&ctx->fh, &ev_src_ch);
194*0934d375SYunfei Dong }
195*0934d375SYunfei Dong 
mtk_vdec_flush_decoder(struct mtk_vcodec_dec_ctx * ctx)196*0934d375SYunfei Dong static int mtk_vdec_flush_decoder(struct mtk_vcodec_dec_ctx *ctx)
197*0934d375SYunfei Dong {
198*0934d375SYunfei Dong 	bool res_chg;
199*0934d375SYunfei Dong 	int ret;
200*0934d375SYunfei Dong 
201*0934d375SYunfei Dong 	ret = vdec_if_decode(ctx, NULL, NULL, &res_chg);
202*0934d375SYunfei Dong 	if (ret)
203*0934d375SYunfei Dong 		mtk_v4l2_vdec_err(ctx, "DecodeFinal failed, ret=%d", ret);
204*0934d375SYunfei Dong 
205*0934d375SYunfei Dong 	clean_display_buffer(ctx);
206*0934d375SYunfei Dong 	clean_free_buffer(ctx);
207*0934d375SYunfei Dong 
208*0934d375SYunfei Dong 	return 0;
209*0934d375SYunfei Dong }
210*0934d375SYunfei Dong 
mtk_vdec_update_fmt(struct mtk_vcodec_dec_ctx * ctx,unsigned int pixelformat)211*0934d375SYunfei Dong static void mtk_vdec_update_fmt(struct mtk_vcodec_dec_ctx *ctx,
212*0934d375SYunfei Dong 				unsigned int pixelformat)
213*0934d375SYunfei Dong {
214*0934d375SYunfei Dong 	const struct mtk_video_fmt *fmt;
215*0934d375SYunfei Dong 	struct mtk_q_data *dst_q_data;
216*0934d375SYunfei Dong 	unsigned int k;
217*0934d375SYunfei Dong 
218*0934d375SYunfei Dong 	dst_q_data = &ctx->q_data[MTK_Q_DATA_DST];
219*0934d375SYunfei Dong 	for (k = 0; k < num_supported_formats; k++) {
220*0934d375SYunfei Dong 		fmt = &mtk_video_formats[k];
221*0934d375SYunfei Dong 		if (fmt->fourcc == pixelformat) {
222*0934d375SYunfei Dong 			mtk_v4l2_vdec_dbg(1, ctx, "Update cap fourcc(%d -> %d)",
223*0934d375SYunfei Dong 					  dst_q_data->fmt->fourcc, pixelformat);
224*0934d375SYunfei Dong 			dst_q_data->fmt = fmt;
225*0934d375SYunfei Dong 			return;
226*0934d375SYunfei Dong 		}
227*0934d375SYunfei Dong 	}
228*0934d375SYunfei Dong 
229*0934d375SYunfei Dong 	mtk_v4l2_vdec_err(ctx, "Cannot get fourcc(%d), using init value", pixelformat);
230*0934d375SYunfei Dong }
231*0934d375SYunfei Dong 
mtk_vdec_pic_info_update(struct mtk_vcodec_dec_ctx * ctx)232*0934d375SYunfei Dong static int mtk_vdec_pic_info_update(struct mtk_vcodec_dec_ctx *ctx)
233*0934d375SYunfei Dong {
234*0934d375SYunfei Dong 	unsigned int dpbsize = 0;
235*0934d375SYunfei Dong 	int ret;
236*0934d375SYunfei Dong 
237*0934d375SYunfei Dong 	if (vdec_if_get_param(ctx, GET_PARAM_PIC_INFO,
238*0934d375SYunfei Dong 			      &ctx->last_decoded_picinfo)) {
239*0934d375SYunfei Dong 		mtk_v4l2_vdec_err(ctx, "[%d]Error!! Cannot get param : GET_PARAM_PICTURE_INFO ERR",
240*0934d375SYunfei Dong 				  ctx->id);
241*0934d375SYunfei Dong 		return -EINVAL;
242*0934d375SYunfei Dong 	}
243*0934d375SYunfei Dong 
244*0934d375SYunfei Dong 	if (ctx->last_decoded_picinfo.pic_w == 0 ||
245*0934d375SYunfei Dong 	    ctx->last_decoded_picinfo.pic_h == 0 ||
246*0934d375SYunfei Dong 	    ctx->last_decoded_picinfo.buf_w == 0 ||
247*0934d375SYunfei Dong 	    ctx->last_decoded_picinfo.buf_h == 0) {
248*0934d375SYunfei Dong 		mtk_v4l2_vdec_err(ctx, "Cannot get correct pic info");
249*0934d375SYunfei Dong 		return -EINVAL;
250*0934d375SYunfei Dong 	}
251*0934d375SYunfei Dong 
252*0934d375SYunfei Dong 	if (ctx->last_decoded_picinfo.cap_fourcc != ctx->picinfo.cap_fourcc &&
253*0934d375SYunfei Dong 	    ctx->picinfo.cap_fourcc != 0)
254*0934d375SYunfei Dong 		mtk_vdec_update_fmt(ctx, ctx->picinfo.cap_fourcc);
255*0934d375SYunfei Dong 
256*0934d375SYunfei Dong 	if (ctx->last_decoded_picinfo.pic_w == ctx->picinfo.pic_w ||
257*0934d375SYunfei Dong 	    ctx->last_decoded_picinfo.pic_h == ctx->picinfo.pic_h)
258*0934d375SYunfei Dong 		return 0;
259*0934d375SYunfei Dong 
260*0934d375SYunfei Dong 	mtk_v4l2_vdec_dbg(1, ctx, "[%d]-> new(%d,%d), old(%d,%d), real(%d,%d)", ctx->id,
261*0934d375SYunfei Dong 			  ctx->last_decoded_picinfo.pic_w,
262*0934d375SYunfei Dong 			  ctx->last_decoded_picinfo.pic_h, ctx->picinfo.pic_w,
263*0934d375SYunfei Dong 			  ctx->picinfo.pic_h, ctx->last_decoded_picinfo.buf_w,
264*0934d375SYunfei Dong 			  ctx->last_decoded_picinfo.buf_h);
265*0934d375SYunfei Dong 
266*0934d375SYunfei Dong 	ret = vdec_if_get_param(ctx, GET_PARAM_DPB_SIZE, &dpbsize);
267*0934d375SYunfei Dong 	if (dpbsize == 0)
268*0934d375SYunfei Dong 		mtk_v4l2_vdec_err(ctx, "Incorrect dpb size, ret=%d", ret);
269*0934d375SYunfei Dong 
270*0934d375SYunfei Dong 	ctx->dpb_size = dpbsize;
271*0934d375SYunfei Dong 
272*0934d375SYunfei Dong 	return ret;
273*0934d375SYunfei Dong }
274*0934d375SYunfei Dong 
mtk_vdec_worker(struct work_struct * work)275*0934d375SYunfei Dong static void mtk_vdec_worker(struct work_struct *work)
276*0934d375SYunfei Dong {
277*0934d375SYunfei Dong 	struct mtk_vcodec_dec_ctx *ctx =
278*0934d375SYunfei Dong 		container_of(work, struct mtk_vcodec_dec_ctx, decode_work);
279*0934d375SYunfei Dong 	struct mtk_vcodec_dec_dev *dev = ctx->dev;
280*0934d375SYunfei Dong 	struct vb2_v4l2_buffer *src_buf, *dst_buf;
281*0934d375SYunfei Dong 	struct mtk_vcodec_mem buf;
282*0934d375SYunfei Dong 	struct vdec_fb *pfb;
283*0934d375SYunfei Dong 	bool res_chg = false;
284*0934d375SYunfei Dong 	int ret;
285*0934d375SYunfei Dong 	struct mtk_video_dec_buf *dst_buf_info, *src_buf_info;
286*0934d375SYunfei Dong 
287*0934d375SYunfei Dong 	src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
288*0934d375SYunfei Dong 	if (!src_buf) {
289*0934d375SYunfei Dong 		v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
290*0934d375SYunfei Dong 		mtk_v4l2_vdec_dbg(1, ctx, "[%d] src_buf empty!!", ctx->id);
291*0934d375SYunfei Dong 		return;
292*0934d375SYunfei Dong 	}
293*0934d375SYunfei Dong 
294*0934d375SYunfei Dong 	dst_buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
295*0934d375SYunfei Dong 	if (!dst_buf) {
296*0934d375SYunfei Dong 		v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
297*0934d375SYunfei Dong 		mtk_v4l2_vdec_dbg(1, ctx, "[%d] dst_buf empty!!", ctx->id);
298*0934d375SYunfei Dong 		return;
299*0934d375SYunfei Dong 	}
300*0934d375SYunfei Dong 
301*0934d375SYunfei Dong 	dst_buf_info =
302*0934d375SYunfei Dong 		container_of(dst_buf, struct mtk_video_dec_buf, m2m_buf.vb);
303*0934d375SYunfei Dong 
304*0934d375SYunfei Dong 	pfb = &dst_buf_info->frame_buffer;
305*0934d375SYunfei Dong 	pfb->base_y.va = vb2_plane_vaddr(&dst_buf->vb2_buf, 0);
306*0934d375SYunfei Dong 	pfb->base_y.dma_addr =
307*0934d375SYunfei Dong 		vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0);
308*0934d375SYunfei Dong 	pfb->base_y.size = ctx->picinfo.fb_sz[0];
309*0934d375SYunfei Dong 
310*0934d375SYunfei Dong 	pfb->base_c.va = vb2_plane_vaddr(&dst_buf->vb2_buf, 1);
311*0934d375SYunfei Dong 	pfb->base_c.dma_addr =
312*0934d375SYunfei Dong 		vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 1);
313*0934d375SYunfei Dong 	pfb->base_c.size = ctx->picinfo.fb_sz[1];
314*0934d375SYunfei Dong 	pfb->status = 0;
315*0934d375SYunfei Dong 	mtk_v4l2_vdec_dbg(3, ctx, "===>[%d] vdec_if_decode() ===>", ctx->id);
316*0934d375SYunfei Dong 
317*0934d375SYunfei Dong 	mtk_v4l2_vdec_dbg(3, ctx,
318*0934d375SYunfei Dong 			  "id=%d Framebuf  pfb=%p VA=%p Y_DMA=%pad C_DMA=%pad Size=%zx",
319*0934d375SYunfei Dong 			  dst_buf->vb2_buf.index, pfb, pfb->base_y.va,
320*0934d375SYunfei Dong 			  &pfb->base_y.dma_addr, &pfb->base_c.dma_addr, pfb->base_y.size);
321*0934d375SYunfei Dong 
322*0934d375SYunfei Dong 	if (src_buf == &ctx->empty_flush_buf.vb) {
323*0934d375SYunfei Dong 		mtk_v4l2_vdec_dbg(1, ctx, "Got empty flush input buffer.");
324*0934d375SYunfei Dong 		src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
325*0934d375SYunfei Dong 
326*0934d375SYunfei Dong 		/* update dst buf status */
327*0934d375SYunfei Dong 		dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
328*0934d375SYunfei Dong 		mutex_lock(&ctx->lock);
329*0934d375SYunfei Dong 		dst_buf_info->used = false;
330*0934d375SYunfei Dong 		mutex_unlock(&ctx->lock);
331*0934d375SYunfei Dong 
332*0934d375SYunfei Dong 		vdec_if_decode(ctx, NULL, NULL, &res_chg);
333*0934d375SYunfei Dong 		clean_display_buffer(ctx);
334*0934d375SYunfei Dong 		vb2_set_plane_payload(&dst_buf->vb2_buf, 0, 0);
335*0934d375SYunfei Dong 		if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2)
336*0934d375SYunfei Dong 			vb2_set_plane_payload(&dst_buf->vb2_buf, 1, 0);
337*0934d375SYunfei Dong 		dst_buf->flags |= V4L2_BUF_FLAG_LAST;
338*0934d375SYunfei Dong 		v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_DONE);
339*0934d375SYunfei Dong 		clean_free_buffer(ctx);
340*0934d375SYunfei Dong 		v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
341*0934d375SYunfei Dong 		return;
342*0934d375SYunfei Dong 	}
343*0934d375SYunfei Dong 
344*0934d375SYunfei Dong 	src_buf_info =
345*0934d375SYunfei Dong 		container_of(src_buf, struct mtk_video_dec_buf, m2m_buf.vb);
346*0934d375SYunfei Dong 
347*0934d375SYunfei Dong 	buf.va = vb2_plane_vaddr(&src_buf->vb2_buf, 0);
348*0934d375SYunfei Dong 	buf.dma_addr = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
349*0934d375SYunfei Dong 	buf.size = (size_t)src_buf->vb2_buf.planes[0].bytesused;
350*0934d375SYunfei Dong 	if (!buf.va) {
351*0934d375SYunfei Dong 		v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
352*0934d375SYunfei Dong 		mtk_v4l2_vdec_err(ctx, "[%d] id=%d src_addr is NULL!!", ctx->id,
353*0934d375SYunfei Dong 				  src_buf->vb2_buf.index);
354*0934d375SYunfei Dong 		return;
355*0934d375SYunfei Dong 	}
356*0934d375SYunfei Dong 	mtk_v4l2_vdec_dbg(3, ctx, "[%d] Bitstream VA=%p DMA=%pad Size=%zx vb=%p",
357*0934d375SYunfei Dong 			  ctx->id, buf.va, &buf.dma_addr, buf.size, src_buf);
358*0934d375SYunfei Dong 	dst_buf->vb2_buf.timestamp = src_buf->vb2_buf.timestamp;
359*0934d375SYunfei Dong 	dst_buf->timecode = src_buf->timecode;
360*0934d375SYunfei Dong 	mutex_lock(&ctx->lock);
361*0934d375SYunfei Dong 	dst_buf_info->used = true;
362*0934d375SYunfei Dong 	mutex_unlock(&ctx->lock);
363*0934d375SYunfei Dong 	src_buf_info->used = true;
364*0934d375SYunfei Dong 
365*0934d375SYunfei Dong 	ret = vdec_if_decode(ctx, &buf, pfb, &res_chg);
366*0934d375SYunfei Dong 
367*0934d375SYunfei Dong 	if (ret) {
368*0934d375SYunfei Dong 		mtk_v4l2_vdec_err(ctx,
369*0934d375SYunfei Dong 				  "[%d] decode src[%d] sz=0x%zx pts=%llu dst[%d] ret=%d res_chg=%d",
370*0934d375SYunfei Dong 				  ctx->id, src_buf->vb2_buf.index, buf.size,
371*0934d375SYunfei Dong 				  src_buf->vb2_buf.timestamp, dst_buf->vb2_buf.index, ret, res_chg);
372*0934d375SYunfei Dong 		src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
373*0934d375SYunfei Dong 		if (ret == -EIO) {
374*0934d375SYunfei Dong 			mutex_lock(&ctx->lock);
375*0934d375SYunfei Dong 			src_buf_info->error = true;
376*0934d375SYunfei Dong 			mutex_unlock(&ctx->lock);
377*0934d375SYunfei Dong 		}
378*0934d375SYunfei Dong 		v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR);
379*0934d375SYunfei Dong 	} else if (!res_chg) {
380*0934d375SYunfei Dong 		/*
381*0934d375SYunfei Dong 		 * we only return src buffer with VB2_BUF_STATE_DONE
382*0934d375SYunfei Dong 		 * when decode success without resolution change
383*0934d375SYunfei Dong 		 */
384*0934d375SYunfei Dong 		src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
385*0934d375SYunfei Dong 		v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
386*0934d375SYunfei Dong 	}
387*0934d375SYunfei Dong 
388*0934d375SYunfei Dong 	dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
389*0934d375SYunfei Dong 	clean_display_buffer(ctx);
390*0934d375SYunfei Dong 	clean_free_buffer(ctx);
391*0934d375SYunfei Dong 
392*0934d375SYunfei Dong 	if (!ret && res_chg) {
393*0934d375SYunfei Dong 		mtk_vdec_pic_info_update(ctx);
394*0934d375SYunfei Dong 		/*
395*0934d375SYunfei Dong 		 * On encountering a resolution change in the stream.
396*0934d375SYunfei Dong 		 * The driver must first process and decode all
397*0934d375SYunfei Dong 		 * remaining buffers from before the resolution change
398*0934d375SYunfei Dong 		 * point, so call flush decode here
399*0934d375SYunfei Dong 		 */
400*0934d375SYunfei Dong 		mtk_vdec_flush_decoder(ctx);
401*0934d375SYunfei Dong 		/*
402*0934d375SYunfei Dong 		 * After all buffers containing decoded frames from
403*0934d375SYunfei Dong 		 * before the resolution change point ready to be
404*0934d375SYunfei Dong 		 * dequeued on the CAPTURE queue, the driver sends a
405*0934d375SYunfei Dong 		 * V4L2_EVENT_SOURCE_CHANGE event for source change
406*0934d375SYunfei Dong 		 * type V4L2_EVENT_SRC_CH_RESOLUTION
407*0934d375SYunfei Dong 		 */
408*0934d375SYunfei Dong 		mtk_vdec_queue_res_chg_event(ctx);
409*0934d375SYunfei Dong 	}
410*0934d375SYunfei Dong 	v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
411*0934d375SYunfei Dong }
412*0934d375SYunfei Dong 
vb2ops_vdec_stateful_buf_queue(struct vb2_buffer * vb)413*0934d375SYunfei Dong static void vb2ops_vdec_stateful_buf_queue(struct vb2_buffer *vb)
414*0934d375SYunfei Dong {
415*0934d375SYunfei Dong 	struct vb2_v4l2_buffer *src_buf;
416*0934d375SYunfei Dong 	struct mtk_vcodec_mem src_mem;
417*0934d375SYunfei Dong 	bool res_chg = false;
418*0934d375SYunfei Dong 	int ret;
419*0934d375SYunfei Dong 	unsigned int dpbsize = 1, i;
420*0934d375SYunfei Dong 	struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
421*0934d375SYunfei Dong 	struct vb2_v4l2_buffer *vb2_v4l2;
422*0934d375SYunfei Dong 	struct mtk_q_data *dst_q_data;
423*0934d375SYunfei Dong 
424*0934d375SYunfei Dong 	mtk_v4l2_vdec_dbg(3, ctx, "[%d] (%d) id=%d, vb=%p", ctx->id,
425*0934d375SYunfei Dong 			  vb->vb2_queue->type, vb->index, vb);
426*0934d375SYunfei Dong 	/*
427*0934d375SYunfei Dong 	 * check if this buffer is ready to be used after decode
428*0934d375SYunfei Dong 	 */
429*0934d375SYunfei Dong 	if (vb->vb2_queue->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
430*0934d375SYunfei Dong 		struct mtk_video_dec_buf *buf;
431*0934d375SYunfei Dong 
432*0934d375SYunfei Dong 		vb2_v4l2 = to_vb2_v4l2_buffer(vb);
433*0934d375SYunfei Dong 		buf = container_of(vb2_v4l2, struct mtk_video_dec_buf,
434*0934d375SYunfei Dong 				   m2m_buf.vb);
435*0934d375SYunfei Dong 		mutex_lock(&ctx->lock);
436*0934d375SYunfei Dong 		if (!buf->used) {
437*0934d375SYunfei Dong 			v4l2_m2m_buf_queue(ctx->m2m_ctx, vb2_v4l2);
438*0934d375SYunfei Dong 			buf->queued_in_vb2 = true;
439*0934d375SYunfei Dong 			buf->queued_in_v4l2 = true;
440*0934d375SYunfei Dong 		} else {
441*0934d375SYunfei Dong 			buf->queued_in_vb2 = false;
442*0934d375SYunfei Dong 			buf->queued_in_v4l2 = true;
443*0934d375SYunfei Dong 		}
444*0934d375SYunfei Dong 		mutex_unlock(&ctx->lock);
445*0934d375SYunfei Dong 		return;
446*0934d375SYunfei Dong 	}
447*0934d375SYunfei Dong 
448*0934d375SYunfei Dong 	v4l2_m2m_buf_queue(ctx->m2m_ctx, to_vb2_v4l2_buffer(vb));
449*0934d375SYunfei Dong 
450*0934d375SYunfei Dong 	if (ctx->state != MTK_STATE_INIT) {
451*0934d375SYunfei Dong 		mtk_v4l2_vdec_dbg(3, ctx, "[%d] already init driver %d", ctx->id, ctx->state);
452*0934d375SYunfei Dong 		return;
453*0934d375SYunfei Dong 	}
454*0934d375SYunfei Dong 
455*0934d375SYunfei Dong 	src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
456*0934d375SYunfei Dong 	if (!src_buf) {
457*0934d375SYunfei Dong 		mtk_v4l2_vdec_err(ctx, "No src buffer");
458*0934d375SYunfei Dong 		return;
459*0934d375SYunfei Dong 	}
460*0934d375SYunfei Dong 
461*0934d375SYunfei Dong 	if (src_buf == &ctx->empty_flush_buf.vb) {
462*0934d375SYunfei Dong 		/* This shouldn't happen. Just in case. */
463*0934d375SYunfei Dong 		mtk_v4l2_vdec_err(ctx, "Invalid flush buffer.");
464*0934d375SYunfei Dong 		v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
465*0934d375SYunfei Dong 		return;
466*0934d375SYunfei Dong 	}
467*0934d375SYunfei Dong 
468*0934d375SYunfei Dong 	src_mem.va = vb2_plane_vaddr(&src_buf->vb2_buf, 0);
469*0934d375SYunfei Dong 	src_mem.dma_addr = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
470*0934d375SYunfei Dong 	src_mem.size = (size_t)src_buf->vb2_buf.planes[0].bytesused;
471*0934d375SYunfei Dong 	mtk_v4l2_vdec_dbg(2, ctx, "[%d] buf id=%d va=%p dma=%pad size=%zx", ctx->id,
472*0934d375SYunfei Dong 			  src_buf->vb2_buf.index, src_mem.va, &src_mem.dma_addr, src_mem.size);
473*0934d375SYunfei Dong 
474*0934d375SYunfei Dong 	ret = vdec_if_decode(ctx, &src_mem, NULL, &res_chg);
475*0934d375SYunfei Dong 	if (ret || !res_chg) {
476*0934d375SYunfei Dong 		/*
477*0934d375SYunfei Dong 		 * fb == NULL means to parse SPS/PPS header or
478*0934d375SYunfei Dong 		 * resolution info in src_mem. Decode can fail
479*0934d375SYunfei Dong 		 * if there is no SPS header or picture info
480*0934d375SYunfei Dong 		 * in bs
481*0934d375SYunfei Dong 		 */
482*0934d375SYunfei Dong 
483*0934d375SYunfei Dong 		src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
484*0934d375SYunfei Dong 		if (ret == -EIO) {
485*0934d375SYunfei Dong 			mtk_v4l2_vdec_err(ctx, "[%d] Unrecoverable error in vdec_if_decode.",
486*0934d375SYunfei Dong 					  ctx->id);
487*0934d375SYunfei Dong 			ctx->state = MTK_STATE_ABORT;
488*0934d375SYunfei Dong 			v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR);
489*0934d375SYunfei Dong 		} else {
490*0934d375SYunfei Dong 			v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
491*0934d375SYunfei Dong 		}
492*0934d375SYunfei Dong 		mtk_v4l2_vdec_dbg(ret ? 0 : 1, ctx,
493*0934d375SYunfei Dong 				  "[%d] decode() src_buf=%d, size=%zu, fail=%d, res_chg=%d",
494*0934d375SYunfei Dong 				  ctx->id, src_buf->vb2_buf.index, src_mem.size, ret, res_chg);
495*0934d375SYunfei Dong 		return;
496*0934d375SYunfei Dong 	}
497*0934d375SYunfei Dong 
498*0934d375SYunfei Dong 	if (vdec_if_get_param(ctx, GET_PARAM_PIC_INFO, &ctx->picinfo)) {
499*0934d375SYunfei Dong 		mtk_v4l2_vdec_err(ctx, "[%d]Error!! Cannot get param : GET_PARAM_PICTURE_INFO ERR",
500*0934d375SYunfei Dong 				  ctx->id);
501*0934d375SYunfei Dong 		return;
502*0934d375SYunfei Dong 	}
503*0934d375SYunfei Dong 
504*0934d375SYunfei Dong 	ctx->last_decoded_picinfo = ctx->picinfo;
505*0934d375SYunfei Dong 	dst_q_data = &ctx->q_data[MTK_Q_DATA_DST];
506*0934d375SYunfei Dong 	for (i = 0; i < dst_q_data->fmt->num_planes; i++) {
507*0934d375SYunfei Dong 		dst_q_data->sizeimage[i] = ctx->picinfo.fb_sz[i];
508*0934d375SYunfei Dong 		dst_q_data->bytesperline[i] = ctx->picinfo.buf_w;
509*0934d375SYunfei Dong 	}
510*0934d375SYunfei Dong 
511*0934d375SYunfei Dong 	mtk_v4l2_vdec_dbg(2, ctx, "[%d] init OK wxh=%dx%d pic wxh=%dx%d sz[0]=0x%x sz[1]=0x%x",
512*0934d375SYunfei Dong 			  ctx->id, ctx->picinfo.buf_w, ctx->picinfo.buf_h, ctx->picinfo.pic_w,
513*0934d375SYunfei Dong 			  ctx->picinfo.pic_h, dst_q_data->sizeimage[0], dst_q_data->sizeimage[1]);
514*0934d375SYunfei Dong 
515*0934d375SYunfei Dong 	ret = vdec_if_get_param(ctx, GET_PARAM_DPB_SIZE, &dpbsize);
516*0934d375SYunfei Dong 	if (dpbsize == 0)
517*0934d375SYunfei Dong 		mtk_v4l2_vdec_err(ctx, "[%d] GET_PARAM_DPB_SIZE fail=%d", ctx->id, ret);
518*0934d375SYunfei Dong 
519*0934d375SYunfei Dong 	ctx->dpb_size = dpbsize;
520*0934d375SYunfei Dong 	ctx->state = MTK_STATE_HEADER;
521*0934d375SYunfei Dong 	mtk_v4l2_vdec_dbg(1, ctx, "[%d] dpbsize=%d", ctx->id, ctx->dpb_size);
522*0934d375SYunfei Dong 
523*0934d375SYunfei Dong 	mtk_vdec_queue_res_chg_event(ctx);
524*0934d375SYunfei Dong }
525*0934d375SYunfei Dong 
mtk_vdec_g_v_ctrl(struct v4l2_ctrl * ctrl)526*0934d375SYunfei Dong static int mtk_vdec_g_v_ctrl(struct v4l2_ctrl *ctrl)
527*0934d375SYunfei Dong {
528*0934d375SYunfei Dong 	struct mtk_vcodec_dec_ctx *ctx = ctrl_to_dec_ctx(ctrl);
529*0934d375SYunfei Dong 	int ret = 0;
530*0934d375SYunfei Dong 
531*0934d375SYunfei Dong 	switch (ctrl->id) {
532*0934d375SYunfei Dong 	case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
533*0934d375SYunfei Dong 		if (ctx->state >= MTK_STATE_HEADER) {
534*0934d375SYunfei Dong 			ctrl->val = ctx->dpb_size;
535*0934d375SYunfei Dong 		} else {
536*0934d375SYunfei Dong 			mtk_v4l2_vdec_dbg(0, ctx, "Seqinfo not ready");
537*0934d375SYunfei Dong 			ctrl->val = 0;
538*0934d375SYunfei Dong 		}
539*0934d375SYunfei Dong 		break;
540*0934d375SYunfei Dong 	default:
541*0934d375SYunfei Dong 		ret = -EINVAL;
542*0934d375SYunfei Dong 	}
543*0934d375SYunfei Dong 	return ret;
544*0934d375SYunfei Dong }
545*0934d375SYunfei Dong 
546*0934d375SYunfei Dong static const struct v4l2_ctrl_ops mtk_vcodec_dec_ctrl_ops = {
547*0934d375SYunfei Dong 	.g_volatile_ctrl = mtk_vdec_g_v_ctrl,
548*0934d375SYunfei Dong };
549*0934d375SYunfei Dong 
mtk_vcodec_dec_ctrls_setup(struct mtk_vcodec_dec_ctx * ctx)550*0934d375SYunfei Dong static int mtk_vcodec_dec_ctrls_setup(struct mtk_vcodec_dec_ctx *ctx)
551*0934d375SYunfei Dong {
552*0934d375SYunfei Dong 	struct v4l2_ctrl *ctrl;
553*0934d375SYunfei Dong 
554*0934d375SYunfei Dong 	v4l2_ctrl_handler_init(&ctx->ctrl_hdl, 1);
555*0934d375SYunfei Dong 
556*0934d375SYunfei Dong 	ctrl = v4l2_ctrl_new_std(&ctx->ctrl_hdl, &mtk_vcodec_dec_ctrl_ops,
557*0934d375SYunfei Dong 				 V4L2_CID_MIN_BUFFERS_FOR_CAPTURE, 0, 32, 1, 1);
558*0934d375SYunfei Dong 	ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
559*0934d375SYunfei Dong 	v4l2_ctrl_new_std_menu(&ctx->ctrl_hdl, &mtk_vcodec_dec_ctrl_ops,
560*0934d375SYunfei Dong 			       V4L2_CID_MPEG_VIDEO_VP9_PROFILE,
561*0934d375SYunfei Dong 			       V4L2_MPEG_VIDEO_VP9_PROFILE_0, 0,
562*0934d375SYunfei Dong 			       V4L2_MPEG_VIDEO_VP9_PROFILE_0);
563*0934d375SYunfei Dong 	/*
564*0934d375SYunfei Dong 	 * H264. Baseline / Extended decoding is not supported.
565*0934d375SYunfei Dong 	 */
566*0934d375SYunfei Dong 	v4l2_ctrl_new_std_menu(&ctx->ctrl_hdl, &mtk_vcodec_dec_ctrl_ops,
567*0934d375SYunfei Dong 			       V4L2_CID_MPEG_VIDEO_H264_PROFILE, V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
568*0934d375SYunfei Dong 			       BIT(V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
569*0934d375SYunfei Dong 			       BIT(V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED),
570*0934d375SYunfei Dong 			       V4L2_MPEG_VIDEO_H264_PROFILE_MAIN);
571*0934d375SYunfei Dong 
572*0934d375SYunfei Dong 	if (ctx->ctrl_hdl.error) {
573*0934d375SYunfei Dong 		mtk_v4l2_vdec_err(ctx, "Adding control failed %d", ctx->ctrl_hdl.error);
574*0934d375SYunfei Dong 		return ctx->ctrl_hdl.error;
575*0934d375SYunfei Dong 	}
576*0934d375SYunfei Dong 
577*0934d375SYunfei Dong 	v4l2_ctrl_handler_setup(&ctx->ctrl_hdl);
578*0934d375SYunfei Dong 	return 0;
579*0934d375SYunfei Dong }
580*0934d375SYunfei Dong 
mtk_init_vdec_params(struct mtk_vcodec_dec_ctx * ctx)581*0934d375SYunfei Dong static void mtk_init_vdec_params(struct mtk_vcodec_dec_ctx *ctx)
582*0934d375SYunfei Dong {
583*0934d375SYunfei Dong 	unsigned int i;
584*0934d375SYunfei Dong 
585*0934d375SYunfei Dong 	if (!(ctx->dev->dec_capability & VCODEC_CAPABILITY_4K_DISABLED)) {
586*0934d375SYunfei Dong 		for (i = 0; i < num_supported_formats; i++) {
587*0934d375SYunfei Dong 			if (mtk_video_formats[i].type != MTK_FMT_DEC)
588*0934d375SYunfei Dong 				continue;
589*0934d375SYunfei Dong 
590*0934d375SYunfei Dong 			mtk_video_formats[i].frmsize.max_width =
591*0934d375SYunfei Dong 				VCODEC_DEC_4K_CODED_WIDTH;
592*0934d375SYunfei Dong 			mtk_video_formats[i].frmsize.max_height =
593*0934d375SYunfei Dong 				VCODEC_DEC_4K_CODED_HEIGHT;
594*0934d375SYunfei Dong 		}
595*0934d375SYunfei Dong 	}
596*0934d375SYunfei Dong }
597*0934d375SYunfei Dong 
598*0934d375SYunfei Dong static struct vb2_ops mtk_vdec_frame_vb2_ops = {
599*0934d375SYunfei Dong 	.queue_setup = vb2ops_vdec_queue_setup,
600*0934d375SYunfei Dong 	.buf_prepare = vb2ops_vdec_buf_prepare,
601*0934d375SYunfei Dong 	.wait_prepare = vb2_ops_wait_prepare,
602*0934d375SYunfei Dong 	.wait_finish = vb2_ops_wait_finish,
603*0934d375SYunfei Dong 	.start_streaming = vb2ops_vdec_start_streaming,
604*0934d375SYunfei Dong 
605*0934d375SYunfei Dong 	.buf_queue = vb2ops_vdec_stateful_buf_queue,
606*0934d375SYunfei Dong 	.buf_init = vb2ops_vdec_buf_init,
607*0934d375SYunfei Dong 	.buf_finish = vb2ops_vdec_buf_finish,
608*0934d375SYunfei Dong 	.stop_streaming = vb2ops_vdec_stop_streaming,
609*0934d375SYunfei Dong };
610*0934d375SYunfei Dong 
611*0934d375SYunfei Dong const struct mtk_vcodec_dec_pdata mtk_vdec_8173_pdata = {
612*0934d375SYunfei Dong 	.init_vdec_params = mtk_init_vdec_params,
613*0934d375SYunfei Dong 	.ctrls_setup = mtk_vcodec_dec_ctrls_setup,
614*0934d375SYunfei Dong 	.vdec_vb2_ops = &mtk_vdec_frame_vb2_ops,
615*0934d375SYunfei Dong 	.vdec_formats = mtk_video_formats,
616*0934d375SYunfei Dong 	.num_formats = &num_supported_formats,
617*0934d375SYunfei Dong 	.default_out_fmt = &mtk_video_formats[DEFAULT_OUT_FMT_IDX],
618*0934d375SYunfei Dong 	.default_cap_fmt = &mtk_video_formats[DEFAULT_CAP_FMT_IDX],
619*0934d375SYunfei Dong 	.worker = mtk_vdec_worker,
620*0934d375SYunfei Dong 	.flush_decoder = mtk_vdec_flush_decoder,
621*0934d375SYunfei Dong 	.is_subdev_supported = false,
622*0934d375SYunfei Dong 	.hw_arch = MTK_VDEC_PURE_SINGLE_CORE,
623*0934d375SYunfei Dong };
624