1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright 2020-2021 NXP
4  */
5 
6 #ifndef _AMPHION_VPU_V4L2_H
7 #define _AMPHION_VPU_V4L2_H
8 
9 #include <linux/videodev2.h>
10 
11 void vpu_inst_lock(struct vpu_inst *inst);
12 void vpu_inst_unlock(struct vpu_inst *inst);
13 void vpu_set_buffer_state(struct vb2_v4l2_buffer *vbuf, unsigned int state);
14 unsigned int vpu_get_buffer_state(struct vb2_v4l2_buffer *vbuf);
15 
16 int vpu_v4l2_open(struct file *file, struct vpu_inst *inst);
17 int vpu_v4l2_close(struct file *file);
18 
19 const struct vpu_format *vpu_try_fmt_common(struct vpu_inst *inst, struct v4l2_format *f);
20 int vpu_process_output_buffer(struct vpu_inst *inst);
21 int vpu_process_capture_buffer(struct vpu_inst *inst);
22 struct vb2_v4l2_buffer *vpu_find_buf_by_sequence(struct vpu_inst *inst, u32 type, u32 sequence);
23 struct vb2_v4l2_buffer *vpu_find_buf_by_idx(struct vpu_inst *inst, u32 type, u32 idx);
24 void vpu_v4l2_set_error(struct vpu_inst *inst);
25 int vpu_notify_eos(struct vpu_inst *inst);
26 int vpu_notify_source_change(struct vpu_inst *inst);
27 int vpu_set_last_buffer_dequeued(struct vpu_inst *inst);
28 void vpu_vb2_buffers_return(struct vpu_inst *inst, unsigned int type, enum vb2_buffer_state state);
29 int vpu_get_num_buffers(struct vpu_inst *inst, u32 type);
30 
31 dma_addr_t vpu_get_vb_phy_addr(struct vb2_buffer *vb, u32 plane_no);
32 unsigned int vpu_get_vb_length(struct vb2_buffer *vb, u32 plane_no);
33 static inline struct vpu_format *vpu_get_format(struct vpu_inst *inst, u32 type)
34 {
35 	if (V4L2_TYPE_IS_OUTPUT(type))
36 		return &inst->out_format;
37 	else
38 		return &inst->cap_format;
39 }
40 
41 static inline char *vpu_type_name(u32 type)
42 {
43 	return V4L2_TYPE_IS_OUTPUT(type) ? "output" : "capture";
44 }
45 
46 static inline int vpu_vb_is_codecconfig(struct vb2_v4l2_buffer *vbuf)
47 {
48 #ifdef V4L2_BUF_FLAG_CODECCONFIG
49 	return (vbuf->flags & V4L2_BUF_FLAG_CODECCONFIG) ? 1 : 0;
50 #else
51 	return 0;
52 #endif
53 }
54 
55 #endif
56