1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2022 MediaTek Inc.
4  * Author: Ping-Hsun Wu <ping-hsun.wu@mediatek.com>
5  */
6 
7 #ifndef __MTK_MDP3_REGS_H__
8 #define __MTK_MDP3_REGS_H__
9 
10 #include <linux/videodev2.h>
11 #include <media/videobuf2-core.h>
12 #include "mtk-img-ipi.h"
13 
14 /*
15  * MDP native color code
16  * Plane count: 1, 2, 3
17  * H-subsample: 0, 1, 2
18  * V-subsample: 0, 1
19  * Color group: 0-RGB, 1-YUV, 2-raw
20  */
21 #define MDP_COLOR(COMPRESS, PACKED, LOOSE, VIDEO, PLANE, HF, VF, BITS, GROUP, SWAP, ID)\
22 	(((COMPRESS) << 29) | ((PACKED) << 27) | ((LOOSE) << 26) | ((VIDEO) << 23) |\
23 	 ((PLANE) << 21) | ((HF) << 19) | ((VF) << 18) | ((BITS) << 8) |\
24 	 ((GROUP) << 6) | ((SWAP) << 5) | ((ID) << 0))
25 
26 #define MDP_COLOR_IS_COMPRESS(c)        ((0x20000000 & (c)) >> 29)
27 #define MDP_COLOR_IS_10BIT_PACKED(c)	((0x08000000 & (c)) >> 27)
28 #define MDP_COLOR_IS_10BIT_LOOSE(c)	(((0x0c000000 & (c)) >> 26) == 1)
29 #define MDP_COLOR_IS_10BIT_TILE(c)	(((0x0c000000 & (c)) >> 26) == 3)
30 #define MDP_COLOR_IS_UFP(c)		((0x02000000 & (c)) >> 25)
31 #define MDP_COLOR_IS_INTERLACED(c)	((0x01000000 & (c)) >> 24)
32 #define MDP_COLOR_IS_BLOCK_MODE(c)	((0x00800000 & (c)) >> 23)
33 #define MDP_COLOR_GET_PLANE_COUNT(c)	((0x00600000 & (c)) >> 21)
34 #define MDP_COLOR_GET_H_SUBSAMPLE(c)	((0x00180000 & (c)) >> 19)
35 #define MDP_COLOR_GET_V_SUBSAMPLE(c)	((0x00040000 & (c)) >> 18)
36 #define MDP_COLOR_BITS_PER_PIXEL(c)	((0x0003ff00 & (c)) >>  8)
37 #define MDP_COLOR_GET_GROUP(c)		((0x000000c0 & (c)) >>  6)
38 #define MDP_COLOR_IS_SWAPPED(c)		((0x00000020 & (c)) >>  5)
39 #define MDP_COLOR_GET_UNIQUE_ID(c)	((0x0000001f & (c)) >>  0)
40 #define MDP_COLOR_GET_HW_FORMAT(c)	((0x0000001f & (c)) >>  0)
41 
42 #define MDP_COLOR_IS_RGB(c)		(MDP_COLOR_GET_GROUP(c) == 0)
43 #define MDP_COLOR_IS_YUV(c)		(MDP_COLOR_GET_GROUP(c) == 1)
44 
45 enum mdp_color {
46 	MDP_COLOR_UNKNOWN	= 0,
47 
48 	/* MDP_COLOR_FULLG8 */
49 	MDP_COLOR_FULLG8_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0,  8, 2,  0, 21),
50 	MDP_COLOR_FULLG8_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1,  8, 2,  0, 21),
51 	MDP_COLOR_FULLG8_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0,  8, 2,  0, 21),
52 	MDP_COLOR_FULLG8_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1,  8, 2,  0, 21),
53 	MDP_COLOR_FULLG8	= MDP_COLOR_FULLG8_BGGR,
54 
55 	/* MDP_COLOR_FULLG10 */
56 	MDP_COLOR_FULLG10_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 10, 2,  0, 21),
57 	MDP_COLOR_FULLG10_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 10, 2,  0, 21),
58 	MDP_COLOR_FULLG10_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 10, 2,  0, 21),
59 	MDP_COLOR_FULLG10_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 10, 2,  0, 21),
60 	MDP_COLOR_FULLG10	= MDP_COLOR_FULLG10_BGGR,
61 
62 	/* MDP_COLOR_FULLG12 */
63 	MDP_COLOR_FULLG12_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 12, 2,  0, 21),
64 	MDP_COLOR_FULLG12_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 12, 2,  0, 21),
65 	MDP_COLOR_FULLG12_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 12, 2,  0, 21),
66 	MDP_COLOR_FULLG12_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 12, 2,  0, 21),
67 	MDP_COLOR_FULLG12	= MDP_COLOR_FULLG12_BGGR,
68 
69 	/* MDP_COLOR_FULLG14 */
70 	MDP_COLOR_FULLG14_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 14, 2,  0, 21),
71 	MDP_COLOR_FULLG14_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 14, 2,  0, 21),
72 	MDP_COLOR_FULLG14_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 14, 2,  0, 21),
73 	MDP_COLOR_FULLG14_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 14, 2,  0, 21),
74 	MDP_COLOR_FULLG14	= MDP_COLOR_FULLG14_BGGR,
75 
76 	MDP_COLOR_UFO10		= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 10, 2,  0, 24),
77 
78 	/* MDP_COLOR_BAYER8 */
79 	MDP_COLOR_BAYER8_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0,  8, 2,  0, 20),
80 	MDP_COLOR_BAYER8_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1,  8, 2,  0, 20),
81 	MDP_COLOR_BAYER8_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0,  8, 2,  0, 20),
82 	MDP_COLOR_BAYER8_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1,  8, 2,  0, 20),
83 	MDP_COLOR_BAYER8	= MDP_COLOR_BAYER8_BGGR,
84 
85 	/* MDP_COLOR_BAYER10 */
86 	MDP_COLOR_BAYER10_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 10, 2,  0, 20),
87 	MDP_COLOR_BAYER10_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 10, 2,  0, 20),
88 	MDP_COLOR_BAYER10_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 10, 2,  0, 20),
89 	MDP_COLOR_BAYER10_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 10, 2,  0, 20),
90 	MDP_COLOR_BAYER10	= MDP_COLOR_BAYER10_BGGR,
91 
92 	/* MDP_COLOR_BAYER12 */
93 	MDP_COLOR_BAYER12_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 12, 2,  0, 20),
94 	MDP_COLOR_BAYER12_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 12, 2,  0, 20),
95 	MDP_COLOR_BAYER12_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 12, 2,  0, 20),
96 	MDP_COLOR_BAYER12_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 12, 2,  0, 20),
97 	MDP_COLOR_BAYER12	= MDP_COLOR_BAYER12_BGGR,
98 
99 	/* MDP_COLOR_BAYER14 */
100 	MDP_COLOR_BAYER14_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 14, 2,  0, 20),
101 	MDP_COLOR_BAYER14_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 14, 2,  0, 20),
102 	MDP_COLOR_BAYER14_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 14, 2,  0, 20),
103 	MDP_COLOR_BAYER14_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 14, 2,  0, 20),
104 	MDP_COLOR_BAYER14	= MDP_COLOR_BAYER14_BGGR,
105 
106 	MDP_COLOR_RGB48		= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 48, 0,  0, 23),
107 	/* For bayer+mono raw-16 */
108 	MDP_COLOR_RGB565_RAW	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 16, 2,  0, 0),
109 
110 	MDP_COLOR_BAYER8_UNPAK	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0,  8, 2,  0, 22),
111 	MDP_COLOR_BAYER10_UNPAK	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 10, 2,  0, 22),
112 	MDP_COLOR_BAYER12_UNPAK	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 12, 2,  0, 22),
113 	MDP_COLOR_BAYER14_UNPAK	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 14, 2,  0, 22),
114 
115 	/* Unified formats */
116 	MDP_COLOR_GREY		= MDP_COLOR(0, 0, 0, 0, 1, 0, 0,  8, 1,  0, 7),
117 
118 	MDP_COLOR_RGB565	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 16, 0,  0, 0),
119 	MDP_COLOR_BGR565	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 16, 0,  1, 0),
120 	MDP_COLOR_RGB888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 24, 0,  1, 1),
121 	MDP_COLOR_BGR888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 24, 0,  0, 1),
122 	MDP_COLOR_RGBA8888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 32, 0,  1, 2),
123 	MDP_COLOR_BGRA8888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 32, 0,  0, 2),
124 	MDP_COLOR_ARGB8888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 32, 0,  1, 3),
125 	MDP_COLOR_ABGR8888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 32, 0,  0, 3),
126 
127 	MDP_COLOR_UYVY		= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 16, 1,  0, 4),
128 	MDP_COLOR_VYUY		= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 16, 1,  1, 4),
129 	MDP_COLOR_YUYV		= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 16, 1,  0, 5),
130 	MDP_COLOR_YVYU		= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 16, 1,  1, 5),
131 
132 	MDP_COLOR_I420		= MDP_COLOR(0, 0, 0, 0, 3, 1, 1,  8, 1,  0, 8),
133 	MDP_COLOR_YV12		= MDP_COLOR(0, 0, 0, 0, 3, 1, 1,  8, 1,  1, 8),
134 	MDP_COLOR_I422		= MDP_COLOR(0, 0, 0, 0, 3, 1, 0,  8, 1,  0, 9),
135 	MDP_COLOR_YV16		= MDP_COLOR(0, 0, 0, 0, 3, 1, 0,  8, 1,  1, 9),
136 	MDP_COLOR_I444		= MDP_COLOR(0, 0, 0, 0, 3, 0, 0,  8, 1,  0, 10),
137 	MDP_COLOR_YV24		= MDP_COLOR(0, 0, 0, 0, 3, 0, 0,  8, 1,  1, 10),
138 
139 	MDP_COLOR_NV12		= MDP_COLOR(0, 0, 0, 0, 2, 1, 1,  8, 1,  0, 12),
140 	MDP_COLOR_NV21		= MDP_COLOR(0, 0, 0, 0, 2, 1, 1,  8, 1,  1, 12),
141 	MDP_COLOR_NV16		= MDP_COLOR(0, 0, 0, 0, 2, 1, 0,  8, 1,  0, 13),
142 	MDP_COLOR_NV61		= MDP_COLOR(0, 0, 0, 0, 2, 1, 0,  8, 1,  1, 13),
143 	MDP_COLOR_NV24		= MDP_COLOR(0, 0, 0, 0, 2, 0, 0,  8, 1,  0, 14),
144 	MDP_COLOR_NV42		= MDP_COLOR(0, 0, 0, 0, 2, 0, 0,  8, 1,  1, 14),
145 
146 	/* MediaTek proprietary formats */
147 	/* UFO encoded block mode */
148 	MDP_COLOR_420_BLK_UFO	= MDP_COLOR(0, 0, 0, 5, 2, 1, 1, 256, 1, 0, 12),
149 	/* Block mode */
150 	MDP_COLOR_420_BLK	= MDP_COLOR(0, 0, 0, 1, 2, 1, 1, 256, 1, 0, 12),
151 	/* Block mode + field mode */
152 	MDP_COLOR_420_BLKI	= MDP_COLOR(0, 0, 0, 3, 2, 1, 1, 256, 1, 0, 12),
153 	/* Block mode */
154 	MDP_COLOR_422_BLK	= MDP_COLOR(0, 0, 0, 1, 1, 1, 0, 512, 1, 0, 4),
155 
156 	MDP_COLOR_IYU2		= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 24,  1, 0, 25),
157 	MDP_COLOR_YUV444	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 24,  1, 0, 30),
158 
159 	/* Packed 10-bit formats */
160 	MDP_COLOR_RGBA1010102	= MDP_COLOR(0, 1, 0, 0, 1, 0, 0, 32,  0, 1, 2),
161 	MDP_COLOR_BGRA1010102	= MDP_COLOR(0, 1, 0, 0, 1, 0, 0, 32,  0, 0, 2),
162 	/* Packed 10-bit UYVY */
163 	MDP_COLOR_UYVY_10P	= MDP_COLOR(0, 1, 0, 0, 1, 1, 0, 20,  1, 0, 4),
164 	/* Packed 10-bit NV21 */
165 	MDP_COLOR_NV21_10P	= MDP_COLOR(0, 1, 0, 0, 2, 1, 1, 10,  1, 1, 12),
166 	/* 10-bit block mode */
167 	MDP_COLOR_420_BLK_10_H	= MDP_COLOR(0, 1, 0, 1, 2, 1, 1, 320, 1, 0, 12),
168 	/* 10-bit HEVC tile mode */
169 	MDP_COLOR_420_BLK_10_V	= MDP_COLOR(0, 1, 1, 1, 2, 1, 1, 320, 1, 0, 12),
170 	/* UFO encoded 10-bit block mode */
171 	MDP_COLOR_420_BLK_U10_H	= MDP_COLOR(0, 1, 0, 5, 2, 1, 1, 320, 1, 0, 12),
172 	/* UFO encoded 10-bit HEVC tile mode */
173 	MDP_COLOR_420_BLK_U10_V	= MDP_COLOR(0, 1, 1, 5, 2, 1, 1, 320, 1, 0, 12),
174 
175 	/* Loose 10-bit formats */
176 	MDP_COLOR_UYVY_10L	= MDP_COLOR(0, 0, 1, 0, 1, 1, 0, 20,  1, 0, 4),
177 	MDP_COLOR_VYUY_10L	= MDP_COLOR(0, 0, 1, 0, 1, 1, 0, 20,  1, 1, 4),
178 	MDP_COLOR_YUYV_10L	= MDP_COLOR(0, 0, 1, 0, 1, 1, 0, 20,  1, 0, 5),
179 	MDP_COLOR_YVYU_10L	= MDP_COLOR(0, 0, 1, 0, 1, 1, 0, 20,  1, 1, 5),
180 	MDP_COLOR_NV12_10L	= MDP_COLOR(0, 0, 1, 0, 2, 1, 1, 10,  1, 0, 12),
181 	MDP_COLOR_NV21_10L	= MDP_COLOR(0, 0, 1, 0, 2, 1, 1, 10,  1, 1, 12),
182 	MDP_COLOR_NV16_10L	= MDP_COLOR(0, 0, 1, 0, 2, 1, 0, 10,  1, 0, 13),
183 	MDP_COLOR_NV61_10L	= MDP_COLOR(0, 0, 1, 0, 2, 1, 0, 10,  1, 1, 13),
184 	MDP_COLOR_YV12_10L	= MDP_COLOR(0, 0, 1, 0, 3, 1, 1, 10,  1, 1, 8),
185 	MDP_COLOR_I420_10L	= MDP_COLOR(0, 0, 1, 0, 3, 1, 1, 10,  1, 0, 8),
186 };
187 
188 static inline bool MDP_COLOR_IS_UV_COPLANE(enum mdp_color c)
189 {
190 	return (MDP_COLOR_GET_PLANE_COUNT(c) == 2 && MDP_COLOR_IS_YUV(c));
191 }
192 
193 /* Minimum Y stride that is accepted by MDP HW */
194 static inline u32 mdp_color_get_min_y_stride(enum mdp_color c, u32 width)
195 {
196 	return ((MDP_COLOR_BITS_PER_PIXEL(c) * width) + 4) >> 3;
197 }
198 
199 /* Minimum UV stride that is accepted by MDP HW */
200 static inline u32 mdp_color_get_min_uv_stride(enum mdp_color c, u32 width)
201 {
202 	u32 min_stride;
203 
204 	if (MDP_COLOR_GET_PLANE_COUNT(c) == 1)
205 		return 0;
206 	min_stride = mdp_color_get_min_y_stride(c, width)
207 		>> MDP_COLOR_GET_H_SUBSAMPLE(c);
208 	if (MDP_COLOR_IS_UV_COPLANE(c) && !MDP_COLOR_IS_BLOCK_MODE(c))
209 		min_stride = min_stride * 2;
210 	return min_stride;
211 }
212 
213 /* Minimum Y plane size that is necessary in buffer */
214 static inline u32 mdp_color_get_min_y_size(enum mdp_color c,
215 					   u32 width, u32 height)
216 {
217 	if (MDP_COLOR_IS_BLOCK_MODE(c))
218 		return ((MDP_COLOR_BITS_PER_PIXEL(c) * width) >> 8) * height;
219 	return mdp_color_get_min_y_stride(c, width) * height;
220 }
221 
222 /* Minimum UV plane size that is necessary in buffer */
223 static inline u32 mdp_color_get_min_uv_size(enum mdp_color c,
224 					    u32 width, u32 height)
225 {
226 	height = height >> MDP_COLOR_GET_V_SUBSAMPLE(c);
227 	if (MDP_COLOR_IS_BLOCK_MODE(c) && (MDP_COLOR_GET_PLANE_COUNT(c) > 1))
228 		return ((MDP_COLOR_BITS_PER_PIXEL(c) * width) >> 8) * height;
229 	return mdp_color_get_min_uv_stride(c, width) * height;
230 }
231 
232 /* Combine colorspace, xfer_func, ycbcr_encoding, and quantization */
233 enum mdp_ycbcr_profile {
234 	/* V4L2_YCBCR_ENC_601 and V4L2_QUANTIZATION_LIM_RANGE */
235 	MDP_YCBCR_PROFILE_BT601,
236 	/* V4L2_YCBCR_ENC_709 and V4L2_QUANTIZATION_LIM_RANGE */
237 	MDP_YCBCR_PROFILE_BT709,
238 	/* V4L2_YCBCR_ENC_601 and V4L2_QUANTIZATION_FULL_RANGE */
239 	MDP_YCBCR_PROFILE_JPEG,
240 	MDP_YCBCR_PROFILE_FULL_BT601 = MDP_YCBCR_PROFILE_JPEG,
241 
242 	/* Colorspaces not support for capture */
243 	/* V4L2_YCBCR_ENC_BT2020 and V4L2_QUANTIZATION_LIM_RANGE */
244 	MDP_YCBCR_PROFILE_BT2020,
245 	/* V4L2_YCBCR_ENC_709 and V4L2_QUANTIZATION_FULL_RANGE */
246 	MDP_YCBCR_PROFILE_FULL_BT709,
247 	/* V4L2_YCBCR_ENC_BT2020 and V4L2_QUANTIZATION_FULL_RANGE */
248 	MDP_YCBCR_PROFILE_FULL_BT2020,
249 };
250 
251 #define MDP_FMT_FLAG_OUTPUT	BIT(0)
252 #define MDP_FMT_FLAG_CAPTURE	BIT(1)
253 
254 struct mdp_format {
255 	u32	pixelformat;
256 	u32	mdp_color;
257 	u8	depth[VIDEO_MAX_PLANES];
258 	u8	row_depth[VIDEO_MAX_PLANES];
259 	u8	num_planes;
260 	u8	walign;
261 	u8	halign;
262 	u8	salign;
263 	u32	flags;
264 };
265 
266 struct mdp_pix_limit {
267 	u32	wmin;
268 	u32	hmin;
269 	u32	wmax;
270 	u32	hmax;
271 };
272 
273 struct mdp_limit {
274 	struct mdp_pix_limit	out_limit;
275 	struct mdp_pix_limit	cap_limit;
276 	u32			h_scale_up_max;
277 	u32			v_scale_up_max;
278 	u32			h_scale_down_max;
279 	u32			v_scale_down_max;
280 };
281 
282 enum mdp_stream_type {
283 	MDP_STREAM_TYPE_UNKNOWN,
284 	MDP_STREAM_TYPE_BITBLT,
285 	MDP_STREAM_TYPE_GPU_BITBLT,
286 	MDP_STREAM_TYPE_DUAL_BITBLT,
287 	MDP_STREAM_TYPE_2ND_BITBLT,
288 	MDP_STREAM_TYPE_ISP_IC,
289 	MDP_STREAM_TYPE_ISP_VR,
290 	MDP_STREAM_TYPE_ISP_ZSD,
291 	MDP_STREAM_TYPE_ISP_IP,
292 	MDP_STREAM_TYPE_ISP_VSS,
293 	MDP_STREAM_TYPE_ISP_ZSD_SLOW,
294 	MDP_STREAM_TYPE_WPE,
295 	MDP_STREAM_TYPE_WPE2,
296 };
297 
298 struct mdp_crop {
299 	struct v4l2_rect	c;
300 	struct v4l2_fract	left_subpix;
301 	struct v4l2_fract	top_subpix;
302 	struct v4l2_fract	width_subpix;
303 	struct v4l2_fract	height_subpix;
304 };
305 
306 struct mdp_frame {
307 	struct v4l2_format	format;
308 	const struct mdp_format	*mdp_fmt;
309 	u32			ycbcr_prof;	/* enum mdp_ycbcr_profile */
310 	u32			usage;		/* enum mdp_buffer_usage */
311 	struct mdp_crop		crop;
312 	struct v4l2_rect	compose;
313 	s32			rotation;
314 	u32			hflip:1;
315 	u32			vflip:1;
316 	u32			hdr:1;
317 	u32			dre:1;
318 	u32			sharpness:1;
319 	u32			dither:1;
320 };
321 
322 static inline bool mdp_target_is_crop(u32 target)
323 {
324 	return (target == V4L2_SEL_TGT_CROP) ||
325 		(target == V4L2_SEL_TGT_CROP_DEFAULT) ||
326 		(target == V4L2_SEL_TGT_CROP_BOUNDS);
327 }
328 
329 static inline bool mdp_target_is_compose(u32 target)
330 {
331 	return (target == V4L2_SEL_TGT_COMPOSE) ||
332 		(target == V4L2_SEL_TGT_COMPOSE_DEFAULT) ||
333 		(target == V4L2_SEL_TGT_COMPOSE_BOUNDS);
334 }
335 
336 #define MDP_MAX_CAPTURES	IMG_MAX_HW_OUTPUTS
337 
338 #define MDP_VPU_INIT		BIT(0)
339 #define MDP_M2M_CTX_ERROR	BIT(1)
340 
341 struct mdp_frameparam {
342 	struct list_head	list;
343 	struct mdp_m2m_ctx	*ctx;
344 	atomic_t		state;
345 	const struct mdp_limit	*limit;
346 	u32			type;	/* enum mdp_stream_type */
347 	u32			frame_no;
348 	struct mdp_frame	output;
349 	struct mdp_frame	captures[MDP_MAX_CAPTURES];
350 	u32			num_captures;
351 	enum v4l2_colorspace		colorspace;
352 	enum v4l2_ycbcr_encoding	ycbcr_enc;
353 	enum v4l2_xfer_func		xfer_func;
354 	enum v4l2_quantization		quant;
355 };
356 
357 struct mdp_dev;
358 
359 int mdp_enum_fmt_mplane(struct mdp_dev *mdp, struct v4l2_fmtdesc *f);
360 const struct mdp_format *mdp_try_fmt_mplane(struct mdp_dev *mdp,
361 					    struct v4l2_format *f,
362 					    struct mdp_frameparam *param,
363 					    u32 ctx_id);
364 enum mdp_ycbcr_profile mdp_map_ycbcr_prof_mplane(struct v4l2_format *f,
365 						 u32 mdp_color);
366 int mdp_try_crop(struct mdp_m2m_ctx *ctx, struct v4l2_rect *r,
367 		 const struct v4l2_selection *s, struct mdp_frame *frame);
368 int mdp_check_scaling_ratio(const struct v4l2_rect *crop,
369 			    const struct v4l2_rect *compose, s32 rotation,
370 	const struct mdp_limit *limit);
371 void mdp_set_src_config(struct img_input *in,
372 			struct mdp_frame *frame, struct vb2_buffer *vb);
373 void mdp_set_dst_config(struct img_output *out,
374 			struct mdp_frame *frame, struct vb2_buffer *vb);
375 int mdp_frameparam_init(struct mdp_dev *mdp, struct mdp_frameparam *param);
376 
377 #endif  /* __MTK_MDP3_REGS_H__ */
378