1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (C) 2018 BayLibre, SAS
4  * Author: Maxime Jourdan <mjourdan@baylibre.com>
5  */
6 
7 #ifndef __MESON_VDEC_HELPERS_H_
8 #define __MESON_VDEC_HELPERS_H_
9 
10 #include "vdec.h"
11 
12 /**
13  * amvdec_set_canvases() - Map VB2 buffers to canvases
14  *
15  * @sess: current session
16  * @reg_base: Registry bases of where to write the canvas indexes
17  * @reg_num: number of contiguous registers after each reg_base (including it)
18  */
19 int amvdec_set_canvases(struct amvdec_session *sess,
20 			u32 reg_base[], u32 reg_num[]);
21 
22 /* Helpers to read/write to the various IPs (DOS, PARSER) */
23 u32 amvdec_read_dos(struct amvdec_core *core, u32 reg);
24 void amvdec_write_dos(struct amvdec_core *core, u32 reg, u32 val);
25 void amvdec_write_dos_bits(struct amvdec_core *core, u32 reg, u32 val);
26 void amvdec_clear_dos_bits(struct amvdec_core *core, u32 reg, u32 val);
27 u32 amvdec_read_parser(struct amvdec_core *core, u32 reg);
28 void amvdec_write_parser(struct amvdec_core *core, u32 reg, u32 val);
29 
30 u32 amvdec_am21c_body_size(u32 width, u32 height);
31 u32 amvdec_am21c_head_size(u32 width, u32 height);
32 u32 amvdec_am21c_size(u32 width, u32 height);
33 
34 /**
35  * amvdec_dst_buf_done_idx() - Signal that a buffer is done decoding
36  *
37  * @sess: current session
38  * @buf_idx: hardware buffer index
39  * @offset: VIFIFO bitstream offset corresponding to the buffer
40  * @field: V4L2 interlaced field
41  */
42 void amvdec_dst_buf_done_idx(struct amvdec_session *sess, u32 buf_idx,
43 			     u32 offset, u32 field);
44 void amvdec_dst_buf_done(struct amvdec_session *sess,
45 			 struct vb2_v4l2_buffer *vbuf, u32 field);
46 void amvdec_dst_buf_done_offset(struct amvdec_session *sess,
47 				struct vb2_v4l2_buffer *vbuf,
48 				u32 offset, u32 field, bool allow_drop);
49 
50 /**
51  * amvdec_add_ts() - Add a timestamp to the list
52  *
53  * @sess: current session
54  * @ts: timestamp to add
55  * @tc: timecode to add
56  * @offset: offset in the VIFIFO where the associated packet was written
57  * @flags: the vb2_v4l2_buffer flags
58  */
59 int amvdec_add_ts(struct amvdec_session *sess, u64 ts,
60 		  struct v4l2_timecode tc, u32 offset, u32 flags);
61 void amvdec_remove_ts(struct amvdec_session *sess, u64 ts);
62 
63 /**
64  * amvdec_set_par_from_dar() - Set Pixel Aspect Ratio from Display Aspect Ratio
65  *
66  * @sess: current session
67  * @dar_num: numerator of the DAR
68  * @dar_den: denominator of the DAR
69  */
70 void amvdec_set_par_from_dar(struct amvdec_session *sess,
71 			     u32 dar_num, u32 dar_den);
72 
73 /**
74  * amvdec_src_change() - Notify new resolution/DPB size to the core
75  *
76  * @sess: current session
77  * @width: picture width detected by the hardware
78  * @height: picture height detected by the hardware
79  * @dpb_size: Decoded Picture Buffer size (= amount of buffers for decoding)
80  */
81 void amvdec_src_change(struct amvdec_session *sess, u32 width,
82 		       u32 height, u32 dpb_size);
83 
84 /**
85  * amvdec_abort() - Abort the current decoding session
86  *
87  * @sess: current session
88  */
89 void amvdec_abort(struct amvdec_session *sess);
90 #endif
91