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 #define MTK_VDEC_MIN_W	64U
20 #define MTK_VDEC_MIN_H	64U
21 
22 #define MTK_VDEC_IRQ_STATUS_DEC_SUCCESS        0x10000
23 
24 /**
25  * struct vdec_fb  - decoder frame buffer
26  * @base_y	: Y plane memory info
27  * @base_c	: C plane memory info
28  * @status      : frame buffer status (vdec_fb_status)
29  */
30 struct vdec_fb {
31 	struct mtk_vcodec_mem	base_y;
32 	struct mtk_vcodec_mem	base_c;
33 	unsigned int	status;
34 };
35 
36 /**
37  * struct mtk_video_dec_buf - Private data related to each VB2 buffer.
38  * @m2m_buf:	M2M buffer
39  * @list:	link list
40  * @used:	Capture buffer contain decoded frame data and keep in
41  *			codec data structure
42  * @queued_in_vb2:	Capture buffer is queue in vb2
43  * @queued_in_v4l2:	Capture buffer is in v4l2 driver, but not in vb2
44  *			queue yet
45  * @error:		An unrecoverable error occurs on this buffer.
46  * @frame_buffer:	Decode status, and buffer information of Capture buffer
47  * @bs_buffer:	Output buffer info
48  *
49  * Note : These status information help us track and debug buffer state
50  */
51 struct mtk_video_dec_buf {
52 	struct v4l2_m2m_buffer	m2m_buf;
53 
54 	bool	used;
55 	bool	queued_in_vb2;
56 	bool	queued_in_v4l2;
57 	bool	error;
58 
59 	union {
60 		struct vdec_fb	frame_buffer;
61 		struct mtk_vcodec_mem	bs_buffer;
62 	};
63 };
64 
65 extern const struct v4l2_ioctl_ops mtk_vdec_ioctl_ops;
66 extern const struct v4l2_m2m_ops mtk_vdec_m2m_ops;
67 extern const struct media_device_ops mtk_vcodec_media_ops;
68 extern const struct mtk_vcodec_dec_pdata mtk_vdec_8173_pdata;
69 extern const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata;
70 
71 
72 /*
73  * mtk_vdec_lock/mtk_vdec_unlock are for ctx instance to
74  * get/release lock before/after access decoder hw.
75  * mtk_vdec_lock get decoder hw lock and set curr_ctx
76  * to ctx instance that get lock
77  */
78 void mtk_vdec_unlock(struct mtk_vcodec_ctx *ctx);
79 void mtk_vdec_lock(struct mtk_vcodec_ctx *ctx);
80 int mtk_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq,
81 			   struct vb2_queue *dst_vq);
82 void mtk_vcodec_dec_set_default_params(struct mtk_vcodec_ctx *ctx);
83 void mtk_vcodec_dec_release(struct mtk_vcodec_ctx *ctx);
84 
85 /*
86  * VB2 ops
87  */
88 int vb2ops_vdec_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
89 			    unsigned int *nplanes, unsigned int sizes[],
90 			    struct device *alloc_devs[]);
91 int vb2ops_vdec_buf_prepare(struct vb2_buffer *vb);
92 void vb2ops_vdec_buf_finish(struct vb2_buffer *vb);
93 int vb2ops_vdec_buf_init(struct vb2_buffer *vb);
94 int vb2ops_vdec_start_streaming(struct vb2_queue *q, unsigned int count);
95 void vb2ops_vdec_stop_streaming(struct vb2_queue *q);
96 
97 
98 #endif /* _MTK_VCODEC_DEC_H_ */
99