xref: /OK3568_Linux_fs/external/mpp/mpp/hal/rkenc/common/vepu541_common.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright 2015 Rockchip Electronics Co. LTD
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef __VEPU541_COMMON_H__
17 #define __VEPU541_COMMON_H__
18 
19 #include "rk_venc_cmd.h"
20 #include "mpp_device.h"
21 
22 #define VEPU541_REG_BASE_HW_STATUS  0x0000001C
23 #define VEPU541_REG_BASE_STATISTICS 0x00000210
24 #define VEPU541_REG_BASE_OSD_PLT    0x00000400
25 #define VEPU541_REG_BASE_L2         0x00010004
26 
27 #define VEPU541_MAX_ROI_NUM         8
28 #define VEPU580_SLICE_FIFO_LEN      32
29 
30 typedef enum Vepu541Fmt_e {
31     VEPU541_FMT_BGRA8888,   // 0
32     VEPU541_FMT_BGR888,     // 1
33     VEPU541_FMT_BGR565,     // 2
34     VEPU541_FMT_NONE,       // 3
35     VEPU541_FMT_YUV422SP,   // 4
36     VEPU541_FMT_YUV422P,    // 5
37     VEPU541_FMT_YUV420SP,   // 6
38     VEPU541_FMT_YUV420P,    // 7
39     VEPU541_FMT_YUYV422,    // 8
40     VEPU541_FMT_UYVY422,    // 9
41     VEPU541_FMT_BUTT,       // 10
42 
43     /* vepu540 add YUV400 support */
44     VEPU540_FMT_YUV400      = VEPU541_FMT_BUTT,     // 10
45     VEPU540_FMT_BUTT,       // 11
46 
47     /* vepu580 add YUV444 support */
48     VEPU580_FMT_YUV444SP    = 12,
49     VEPU580_FMT_YUV444P     = 13,
50     VEPU580_FMT_BUTT,       // 14
51 } Vepu541Fmt;
52 
53 typedef struct VepuFmtCfg_t {
54     Vepu541Fmt      format;
55     RK_U32          alpha_swap;
56     RK_U32          rbuv_swap;
57     RK_U32          src_range;
58     RK_U32          src_endian;
59     const RK_S32    *weight;
60     const RK_S32    *offset;
61 } VepuFmtCfg;
62 
63 /*
64  * Vepu541RoiCfg
65  *
66  * Each Vepu541RoiCfg in roi buffer indicates a 16x16 cu encoding config at
67  * corresponding position.
68  *
69  * NOTE: roi buffer should be aligned to 64x64 each is 4 16x16 in horizontal
70  * and 4 16x16 in vertical. So the buffer need to be enlarged to avoid hardware
71  * access error.
72  */
73 typedef struct Vepu541RoiCfg_t {
74     /*
75      * Force_intra
76      * 1 - The corresponding 16x16cu is forced to be intra
77      * 0 - Not force to intra
78      */
79     RK_U16 force_intra  : 1;
80     RK_U16 reserved     : 3;
81     /*
82      * Qp area index
83      * The choosed qp area index.
84      */
85     RK_U16 qp_area_idx  : 3;
86     /*
87      * Area qp limit function enable flag
88      * Force to be true in vepu541
89      */
90     RK_U16 qp_area_en   : 1;
91     /*
92      * Qp_adj
93      * Qp_adj
94      * in absolute qp mode qp_adj is the final qp used by encoder
95      * in relative qp mode qp_adj is a adjustment to final qp
96      */
97     RK_S16 qp_adj       : 7;
98     /*
99      * Qp_adj_mode
100      * Qp adjustment mode
101      * 1 - absolute qp mode:
102      *     the 16x16 MB qp is set to the qp_adj value
103      * 0 - relative qp mode
104      *     the 16x16 MB qp is adjusted by qp_adj value
105      */
106     RK_U16 qp_adj_mode  : 1;
107 } Vepu541RoiCfg;
108 
109 typedef struct Vepu541OsdPos_t {
110     /* X coordinate/16 of OSD region's left-top point. */
111     RK_U32  osd_lt_x                : 8;
112     /* Y coordinate/16 of OSD region's left-top point. */
113     RK_U32  osd_lt_y                : 8;
114     /* X coordinate/16 of OSD region's right-bottom point. */
115     RK_U32  osd_rb_x                : 8;
116     /* Y coordinate/16 of OSD region's right-bottom point. */
117     RK_U32  osd_rb_y                : 8;
118 } Vepu541OsdPos;
119 
120 typedef struct Vepu580OsdPos_t {
121     /* X coordinate/16 of OSD region's left-top point. */
122     RK_U32  osd_lt_x                : 10;
123     RK_U32  reserved0               : 6;
124     /* Y coordinate/16 of OSD region's left-top point. */
125     RK_U32  osd_lt_y                : 10;
126     RK_U32  reserved1               : 6;
127     /* X coordinate/16 of OSD region's right-bottom point. */
128     RK_U32  osd_rb_x                : 10;
129     RK_U32  reserved2               : 6;
130     /* Y coordinate/16 of OSD region's right-bottom point. */
131     RK_U32  osd_rb_y                : 10;
132     RK_U32  reserved3               : 6;
133 } Vepu580OsdPos;
134 
135 typedef struct Vepu541B8NumQp_t {
136     RK_U32  b8num_qp                : 18;
137     RK_U32  reserved                : 14;
138 } Vepu541B8NumQp;
139 
140 typedef struct Vepu541OsdPltColor_t {
141     /* V component */
142     RK_U32  v                       : 8;
143     /* U component */
144     RK_U32  u                       : 8;
145     /* Y component */
146     RK_U32  y                       : 8;
147     /* Alpha */
148     RK_U32  alpha                   : 8;
149 } Vepu541OsdPltColor;
150 
151 typedef struct Vepu541OsdCfg_t {
152     void                *reg_base;
153     MppDev              dev;
154     MppDevRegOffCfgs    *reg_cfg;
155     MppEncOSDPltCfg     *plt_cfg;
156     MppEncOSDData       *osd_data;
157     MppEncOSDData2      *osd_data2;
158 } Vepu541OsdCfg;
159 
160 #ifdef __cplusplus
161 extern "C" {
162 #endif
163 
164 MPP_RET vepu541_set_fmt(VepuFmtCfg *cfg, MppFrameFormat format);
165 
166 /*
167  * roi function
168  *
169  * vepu541_get_roi_buf_size
170  * Calculate roi buffer size for image with size w * h
171  *
172  * vepu541_set_roi
173  * Setup roi config buffeer for image with mb count mb_w * mb_h
174  */
175 RK_S32  vepu541_get_roi_buf_size(RK_S32 w, RK_S32 h);
176 MPP_RET vepu541_set_roi(void *buf, MppEncROICfg *roi, RK_S32 w, RK_S32 h);
177 MPP_RET vepu541_set_one_roi(void *buf, MppEncROIRegion *region, RK_S32 w, RK_S32 h);
178 
179 MPP_RET vepu541_set_osd(Vepu541OsdCfg *cfg);
180 MPP_RET vepu540_set_osd(Vepu541OsdCfg *cfg);
181 MPP_RET vepu580_set_osd(Vepu541OsdCfg *cfg);
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 
187 #endif /* __VEPU541_COMMON_H__ */
188