1 /*
2  * Copyright (c) 2016 MediaTek Inc.
3  * Author: PC Chen <pc.chen@mediatek.com>
4  *         Tiffany Lin <tiffany.lin@mediatek.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  */
15 
16 #ifndef _MTK_VCODEC_DEC_H_
17 #define _MTK_VCODEC_DEC_H_
18 
19 #include <media/videobuf2-core.h>
20 #include <media/videobuf2-v4l2.h>
21 
22 #define VCODEC_CAPABILITY_4K_DISABLED	0x10
23 #define VCODEC_DEC_4K_CODED_WIDTH	4096U
24 #define VCODEC_DEC_4K_CODED_HEIGHT	2304U
25 #define MTK_VDEC_MAX_W	2048U
26 #define MTK_VDEC_MAX_H	1088U
27 
28 #define MTK_VDEC_IRQ_STATUS_DEC_SUCCESS        0x10000
29 
30 /**
31  * struct vdec_fb  - decoder frame buffer
32  * @base_y	: Y plane memory info
33  * @base_c	: C plane memory info
34  * @status      : frame buffer status (vdec_fb_status)
35  */
36 struct vdec_fb {
37 	struct mtk_vcodec_mem	base_y;
38 	struct mtk_vcodec_mem	base_c;
39 	unsigned int	status;
40 };
41 
42 /**
43  * struct mtk_video_dec_buf - Private data related to each VB2 buffer.
44  * @b:		VB2 buffer
45  * @list:	link list
46  * @used:	Capture buffer contain decoded frame data and keep in
47  *			codec data structure
48  * @ready_to_display:	Capture buffer not display yet
49  * @queued_in_vb2:	Capture buffer is queue in vb2
50  * @queued_in_v4l2:	Capture buffer is in v4l2 driver, but not in vb2
51  *			queue yet
52  * @lastframe:		Intput buffer is last buffer - EOS
53  * @error:		An unrecoverable error occurs on this buffer.
54  * @frame_buffer:	Decode status, and buffer information of Capture buffer
55  *
56  * Note : These status information help us track and debug buffer state
57  */
58 struct mtk_video_dec_buf {
59 	struct vb2_v4l2_buffer	vb;
60 	struct list_head	list;
61 
62 	bool	used;
63 	bool	ready_to_display;
64 	bool	queued_in_vb2;
65 	bool	queued_in_v4l2;
66 	bool	lastframe;
67 	bool	error;
68 	struct vdec_fb	frame_buffer;
69 };
70 
71 extern const struct v4l2_ioctl_ops mtk_vdec_ioctl_ops;
72 extern const struct v4l2_m2m_ops mtk_vdec_m2m_ops;
73 
74 
75 /*
76  * mtk_vdec_lock/mtk_vdec_unlock are for ctx instance to
77  * get/release lock before/after access decoder hw.
78  * mtk_vdec_lock get decoder hw lock and set curr_ctx
79  * to ctx instance that get lock
80  */
81 void mtk_vdec_unlock(struct mtk_vcodec_ctx *ctx);
82 void mtk_vdec_lock(struct mtk_vcodec_ctx *ctx);
83 int mtk_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq,
84 			   struct vb2_queue *dst_vq);
85 void mtk_vcodec_dec_set_default_params(struct mtk_vcodec_ctx *ctx);
86 void mtk_vcodec_dec_release(struct mtk_vcodec_ctx *ctx);
87 int mtk_vcodec_dec_ctrls_setup(struct mtk_vcodec_ctx *ctx);
88 
89 
90 #endif /* _MTK_VCODEC_DEC_H_ */
91