xref: /linux/drivers/staging/media/meson/vdec/vdec_helpers.h (revision 06ed6aa56ffac9241e03a24649e8d048f8f1b10c)
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  * @offset: offset in the VIFIFO where the associated packet was written
56  * @flags the vb2_v4l2_buffer flags
57  */
58 void amvdec_add_ts(struct amvdec_session *sess, u64 ts,
59 		   struct v4l2_timecode tc, u32 offset, u32 flags);
60 void amvdec_remove_ts(struct amvdec_session *sess, u64 ts);
61 
62 /**
63  * amvdec_set_par_from_dar() - Set Pixel Aspect Ratio from Display Aspect Ratio
64  *
65  * @sess: current session
66  * @dar_num: numerator of the DAR
67  * @dar_den: denominator of the DAR
68  */
69 void amvdec_set_par_from_dar(struct amvdec_session *sess,
70 			     u32 dar_num, u32 dar_den);
71 
72 /**
73  * amvdec_src_change() - Notify new resolution/DPB size to the core
74  *
75  * @sess: current session
76  * @width: picture width detected by the hardware
77  * @height: picture height detected by the hardware
78  * @dpb_size: Decoded Picture Buffer size (= amount of buffers for decoding)
79  */
80 void amvdec_src_change(struct amvdec_session *sess, u32 width,
81 		       u32 height, u32 dpb_size);
82 
83 /**
84  * amvdec_abort() - Abort the current decoding session
85  *
86  * @sess: current session
87  */
88 void amvdec_abort(struct amvdec_session *sess);
89 #endif
90