1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2016 MediaTek Inc.
4  * Author: PC Chen <pc.chen@mediatek.com>
5  *         Tiffany Lin <tiffany.lin@mediatek.com>
6  */
7 
8 #ifndef _MTK_VCODEC_DEC_H_
9 #define _MTK_VCODEC_DEC_H_
10 
11 #include <media/videobuf2-core.h>
12 #include <media/v4l2-mem2mem.h>
13 
14 #define VCODEC_CAPABILITY_4K_DISABLED	0x10
15 #define VCODEC_DEC_4K_CODED_WIDTH	4096U
16 #define VCODEC_DEC_4K_CODED_HEIGHT	2304U
17 #define MTK_VDEC_MAX_W	2048U
18 #define MTK_VDEC_MAX_H	1088U
19 
20 #define MTK_VDEC_IRQ_STATUS_DEC_SUCCESS        0x10000
21 
22 /**
23  * struct vdec_fb  - decoder frame buffer
24  * @base_y	: Y plane memory info
25  * @base_c	: C plane memory info
26  * @status      : frame buffer status (vdec_fb_status)
27  */
28 struct vdec_fb {
29 	struct mtk_vcodec_mem	base_y;
30 	struct mtk_vcodec_mem	base_c;
31 	unsigned int	status;
32 };
33 
34 /**
35  * struct mtk_video_dec_buf - Private data related to each VB2 buffer.
36  * @m2m_buf:	M2M buffer
37  * @list:	link list
38  * @used:	Capture buffer contain decoded frame data and keep in
39  *			codec data structure
40  * @queued_in_vb2:	Capture buffer is queue in vb2
41  * @queued_in_v4l2:	Capture buffer is in v4l2 driver, but not in vb2
42  *			queue yet
43  * @lastframe:		Intput buffer is last buffer - EOS
44  * @error:		An unrecoverable error occurs on this buffer.
45  * @frame_buffer:	Decode status, and buffer information of Capture buffer
46  *
47  * Note : These status information help us track and debug buffer state
48  */
49 struct mtk_video_dec_buf {
50 	struct v4l2_m2m_buffer	m2m_buf;
51 
52 	bool	used;
53 	bool	queued_in_vb2;
54 	bool	queued_in_v4l2;
55 	bool	lastframe;
56 	bool	error;
57 	struct vdec_fb	frame_buffer;
58 };
59 
60 extern const struct v4l2_ioctl_ops mtk_vdec_ioctl_ops;
61 extern const struct v4l2_m2m_ops mtk_vdec_m2m_ops;
62 
63 
64 /*
65  * mtk_vdec_lock/mtk_vdec_unlock are for ctx instance to
66  * get/release lock before/after access decoder hw.
67  * mtk_vdec_lock get decoder hw lock and set curr_ctx
68  * to ctx instance that get lock
69  */
70 void mtk_vdec_unlock(struct mtk_vcodec_ctx *ctx);
71 void mtk_vdec_lock(struct mtk_vcodec_ctx *ctx);
72 int mtk_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq,
73 			   struct vb2_queue *dst_vq);
74 void mtk_vcodec_dec_set_default_params(struct mtk_vcodec_ctx *ctx);
75 void mtk_vcodec_dec_release(struct mtk_vcodec_ctx *ctx);
76 int mtk_vcodec_dec_ctrls_setup(struct mtk_vcodec_ctx *ctx);
77 
78 
79 #endif /* _MTK_VCODEC_DEC_H_ */
80