161890ccaSMoudy Ho /* SPDX-License-Identifier: GPL-2.0-only */
261890ccaSMoudy Ho /*
361890ccaSMoudy Ho  * Copyright (c) 2022 MediaTek Inc.
461890ccaSMoudy Ho  * Author: Ping-Hsun Wu <ping-hsun.wu@mediatek.com>
561890ccaSMoudy Ho  */
661890ccaSMoudy Ho 
761890ccaSMoudy Ho #ifndef __MTK_MDP3_REGS_H__
861890ccaSMoudy Ho #define __MTK_MDP3_REGS_H__
961890ccaSMoudy Ho 
1061890ccaSMoudy Ho #include <linux/videodev2.h>
1161890ccaSMoudy Ho #include <media/videobuf2-core.h>
1261890ccaSMoudy Ho #include "mtk-img-ipi.h"
1361890ccaSMoudy Ho 
1461890ccaSMoudy Ho /*
1561890ccaSMoudy Ho  * MDP native color code
1661890ccaSMoudy Ho  * Plane count: 1, 2, 3
1761890ccaSMoudy Ho  * H-subsample: 0, 1, 2
1861890ccaSMoudy Ho  * V-subsample: 0, 1
1961890ccaSMoudy Ho  * Color group: 0-RGB, 1-YUV, 2-raw
2061890ccaSMoudy Ho  */
21*a5b400eaSMoudy Ho #define MDP_COLOR(COMPRESS, PACKED, LOOSE, VIDEO, PLANE, HF, VF, BITS, GROUP, SWAP, ID)\
22*a5b400eaSMoudy Ho 	(((COMPRESS) << 29) | ((PACKED) << 27) | ((LOOSE) << 26) | ((VIDEO) << 23) |\
2361890ccaSMoudy Ho 	 ((PLANE) << 21) | ((HF) << 19) | ((VF) << 18) | ((BITS) << 8) |\
2461890ccaSMoudy Ho 	 ((GROUP) << 6) | ((SWAP) << 5) | ((ID) << 0))
2561890ccaSMoudy Ho 
26*a5b400eaSMoudy Ho #define MDP_COLOR_IS_COMPRESS(c)        ((0x20000000 & (c)) >> 29)
2761890ccaSMoudy Ho #define MDP_COLOR_IS_10BIT_PACKED(c)	((0x08000000 & (c)) >> 27)
2861890ccaSMoudy Ho #define MDP_COLOR_IS_10BIT_LOOSE(c)	(((0x0c000000 & (c)) >> 26) == 1)
2961890ccaSMoudy Ho #define MDP_COLOR_IS_10BIT_TILE(c)	(((0x0c000000 & (c)) >> 26) == 3)
3061890ccaSMoudy Ho #define MDP_COLOR_IS_UFP(c)		((0x02000000 & (c)) >> 25)
3161890ccaSMoudy Ho #define MDP_COLOR_IS_INTERLACED(c)	((0x01000000 & (c)) >> 24)
3261890ccaSMoudy Ho #define MDP_COLOR_IS_BLOCK_MODE(c)	((0x00800000 & (c)) >> 23)
3361890ccaSMoudy Ho #define MDP_COLOR_GET_PLANE_COUNT(c)	((0x00600000 & (c)) >> 21)
3461890ccaSMoudy Ho #define MDP_COLOR_GET_H_SUBSAMPLE(c)	((0x00180000 & (c)) >> 19)
3561890ccaSMoudy Ho #define MDP_COLOR_GET_V_SUBSAMPLE(c)	((0x00040000 & (c)) >> 18)
3661890ccaSMoudy Ho #define MDP_COLOR_BITS_PER_PIXEL(c)	((0x0003ff00 & (c)) >>  8)
3761890ccaSMoudy Ho #define MDP_COLOR_GET_GROUP(c)		((0x000000c0 & (c)) >>  6)
3861890ccaSMoudy Ho #define MDP_COLOR_IS_SWAPPED(c)		((0x00000020 & (c)) >>  5)
3961890ccaSMoudy Ho #define MDP_COLOR_GET_UNIQUE_ID(c)	((0x0000001f & (c)) >>  0)
4061890ccaSMoudy Ho #define MDP_COLOR_GET_HW_FORMAT(c)	((0x0000001f & (c)) >>  0)
4161890ccaSMoudy Ho 
4261890ccaSMoudy Ho #define MDP_COLOR_IS_RGB(c)		(MDP_COLOR_GET_GROUP(c) == 0)
4361890ccaSMoudy Ho #define MDP_COLOR_IS_YUV(c)		(MDP_COLOR_GET_GROUP(c) == 1)
4461890ccaSMoudy Ho 
4561890ccaSMoudy Ho enum mdp_color {
4661890ccaSMoudy Ho 	MDP_COLOR_UNKNOWN	= 0,
4761890ccaSMoudy Ho 
48*a5b400eaSMoudy Ho 	/* MDP_COLOR_FULLG8 */
49*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG8_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0,  8, 2,  0, 21),
50*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG8_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1,  8, 2,  0, 21),
51*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG8_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0,  8, 2,  0, 21),
52*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG8_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1,  8, 2,  0, 21),
5361890ccaSMoudy Ho 	MDP_COLOR_FULLG8	= MDP_COLOR_FULLG8_BGGR,
5461890ccaSMoudy Ho 
55*a5b400eaSMoudy Ho 	/* MDP_COLOR_FULLG10 */
56*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG10_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 10, 2,  0, 21),
57*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG10_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 10, 2,  0, 21),
58*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG10_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 10, 2,  0, 21),
59*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG10_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 10, 2,  0, 21),
6061890ccaSMoudy Ho 	MDP_COLOR_FULLG10	= MDP_COLOR_FULLG10_BGGR,
6161890ccaSMoudy Ho 
62*a5b400eaSMoudy Ho 	/* MDP_COLOR_FULLG12 */
63*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG12_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 12, 2,  0, 21),
64*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG12_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 12, 2,  0, 21),
65*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG12_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 12, 2,  0, 21),
66*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG12_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 12, 2,  0, 21),
6761890ccaSMoudy Ho 	MDP_COLOR_FULLG12	= MDP_COLOR_FULLG12_BGGR,
6861890ccaSMoudy Ho 
69*a5b400eaSMoudy Ho 	/* MDP_COLOR_FULLG14 */
70*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG14_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 14, 2,  0, 21),
71*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG14_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 14, 2,  0, 21),
72*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG14_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 14, 2,  0, 21),
73*a5b400eaSMoudy Ho 	MDP_COLOR_FULLG14_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 14, 2,  0, 21),
7461890ccaSMoudy Ho 	MDP_COLOR_FULLG14	= MDP_COLOR_FULLG14_BGGR,
7561890ccaSMoudy Ho 
76*a5b400eaSMoudy Ho 	MDP_COLOR_UFO10		= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 10, 2,  0, 24),
7761890ccaSMoudy Ho 
78*a5b400eaSMoudy Ho 	/* MDP_COLOR_BAYER8 */
79*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER8_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0,  8, 2,  0, 20),
80*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER8_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1,  8, 2,  0, 20),
81*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER8_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0,  8, 2,  0, 20),
82*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER8_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1,  8, 2,  0, 20),
8361890ccaSMoudy Ho 	MDP_COLOR_BAYER8	= MDP_COLOR_BAYER8_BGGR,
8461890ccaSMoudy Ho 
85*a5b400eaSMoudy Ho 	/* MDP_COLOR_BAYER10 */
86*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER10_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 10, 2,  0, 20),
87*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER10_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 10, 2,  0, 20),
88*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER10_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 10, 2,  0, 20),
89*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER10_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 10, 2,  0, 20),
9061890ccaSMoudy Ho 	MDP_COLOR_BAYER10	= MDP_COLOR_BAYER10_BGGR,
9161890ccaSMoudy Ho 
92*a5b400eaSMoudy Ho 	/* MDP_COLOR_BAYER12 */
93*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER12_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 12, 2,  0, 20),
94*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER12_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 12, 2,  0, 20),
95*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER12_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 12, 2,  0, 20),
96*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER12_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 12, 2,  0, 20),
9761890ccaSMoudy Ho 	MDP_COLOR_BAYER12	= MDP_COLOR_BAYER12_BGGR,
9861890ccaSMoudy Ho 
99*a5b400eaSMoudy Ho 	/* MDP_COLOR_BAYER14 */
100*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER14_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 14, 2,  0, 20),
101*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER14_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 14, 2,  0, 20),
102*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER14_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 14, 2,  0, 20),
103*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER14_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 14, 2,  0, 20),
10461890ccaSMoudy Ho 	MDP_COLOR_BAYER14	= MDP_COLOR_BAYER14_BGGR,
10561890ccaSMoudy Ho 
106*a5b400eaSMoudy Ho 	MDP_COLOR_RGB48		= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 48, 0,  0, 23),
10761890ccaSMoudy Ho 	/* For bayer+mono raw-16 */
108*a5b400eaSMoudy Ho 	MDP_COLOR_RGB565_RAW	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 16, 2,  0, 0),
10961890ccaSMoudy Ho 
110*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER8_UNPAK	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0,  8, 2,  0, 22),
111*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER10_UNPAK	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 10, 2,  0, 22),
112*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER12_UNPAK	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 12, 2,  0, 22),
113*a5b400eaSMoudy Ho 	MDP_COLOR_BAYER14_UNPAK	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 14, 2,  0, 22),
11461890ccaSMoudy Ho 
11561890ccaSMoudy Ho 	/* Unified formats */
116*a5b400eaSMoudy Ho 	MDP_COLOR_GREY		= MDP_COLOR(0, 0, 0, 0, 1, 0, 0,  8, 1,  0, 7),
11761890ccaSMoudy Ho 
118*a5b400eaSMoudy Ho 	MDP_COLOR_RGB565	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 16, 0,  0, 0),
119*a5b400eaSMoudy Ho 	MDP_COLOR_BGR565	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 16, 0,  1, 0),
120*a5b400eaSMoudy Ho 	MDP_COLOR_RGB888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 24, 0,  1, 1),
121*a5b400eaSMoudy Ho 	MDP_COLOR_BGR888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 24, 0,  0, 1),
122*a5b400eaSMoudy Ho 	MDP_COLOR_RGBA8888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 32, 0,  1, 2),
123*a5b400eaSMoudy Ho 	MDP_COLOR_BGRA8888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 32, 0,  0, 2),
124*a5b400eaSMoudy Ho 	MDP_COLOR_ARGB8888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 32, 0,  1, 3),
125*a5b400eaSMoudy Ho 	MDP_COLOR_ABGR8888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 32, 0,  0, 3),
12661890ccaSMoudy Ho 
127*a5b400eaSMoudy Ho 	MDP_COLOR_UYVY		= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 16, 1,  0, 4),
128*a5b400eaSMoudy Ho 	MDP_COLOR_VYUY		= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 16, 1,  1, 4),
129*a5b400eaSMoudy Ho 	MDP_COLOR_YUYV		= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 16, 1,  0, 5),
130*a5b400eaSMoudy Ho 	MDP_COLOR_YVYU		= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 16, 1,  1, 5),
13161890ccaSMoudy Ho 
132*a5b400eaSMoudy Ho 	MDP_COLOR_I420		= MDP_COLOR(0, 0, 0, 0, 3, 1, 1,  8, 1,  0, 8),
133*a5b400eaSMoudy Ho 	MDP_COLOR_YV12		= MDP_COLOR(0, 0, 0, 0, 3, 1, 1,  8, 1,  1, 8),
134*a5b400eaSMoudy Ho 	MDP_COLOR_I422		= MDP_COLOR(0, 0, 0, 0, 3, 1, 0,  8, 1,  0, 9),
135*a5b400eaSMoudy Ho 	MDP_COLOR_YV16		= MDP_COLOR(0, 0, 0, 0, 3, 1, 0,  8, 1,  1, 9),
136*a5b400eaSMoudy Ho 	MDP_COLOR_I444		= MDP_COLOR(0, 0, 0, 0, 3, 0, 0,  8, 1,  0, 10),
137*a5b400eaSMoudy Ho 	MDP_COLOR_YV24		= MDP_COLOR(0, 0, 0, 0, 3, 0, 0,  8, 1,  1, 10),
13861890ccaSMoudy Ho 
139*a5b400eaSMoudy Ho 	MDP_COLOR_NV12		= MDP_COLOR(0, 0, 0, 0, 2, 1, 1,  8, 1,  0, 12),
140*a5b400eaSMoudy Ho 	MDP_COLOR_NV21		= MDP_COLOR(0, 0, 0, 0, 2, 1, 1,  8, 1,  1, 12),
141*a5b400eaSMoudy Ho 	MDP_COLOR_NV16		= MDP_COLOR(0, 0, 0, 0, 2, 1, 0,  8, 1,  0, 13),
142*a5b400eaSMoudy Ho 	MDP_COLOR_NV61		= MDP_COLOR(0, 0, 0, 0, 2, 1, 0,  8, 1,  1, 13),
143*a5b400eaSMoudy Ho 	MDP_COLOR_NV24		= MDP_COLOR(0, 0, 0, 0, 2, 0, 0,  8, 1,  0, 14),
144*a5b400eaSMoudy Ho 	MDP_COLOR_NV42		= MDP_COLOR(0, 0, 0, 0, 2, 0, 0,  8, 1,  1, 14),
14561890ccaSMoudy Ho 
14661890ccaSMoudy Ho 	/* MediaTek proprietary formats */
14761890ccaSMoudy Ho 	/* UFO encoded block mode */
148*a5b400eaSMoudy Ho 	MDP_COLOR_420_BLK_UFO	= MDP_COLOR(0, 0, 0, 5, 2, 1, 1, 256, 1, 0, 12),
14961890ccaSMoudy Ho 	/* Block mode */
150*a5b400eaSMoudy Ho 	MDP_COLOR_420_BLK	= MDP_COLOR(0, 0, 0, 1, 2, 1, 1, 256, 1, 0, 12),
15161890ccaSMoudy Ho 	/* Block mode + field mode */
152*a5b400eaSMoudy Ho 	MDP_COLOR_420_BLKI	= MDP_COLOR(0, 0, 0, 3, 2, 1, 1, 256, 1, 0, 12),
15361890ccaSMoudy Ho 	/* Block mode */
154*a5b400eaSMoudy Ho 	MDP_COLOR_422_BLK	= MDP_COLOR(0, 0, 0, 1, 1, 1, 0, 512, 1, 0, 4),
15561890ccaSMoudy Ho 
156*a5b400eaSMoudy Ho 	MDP_COLOR_IYU2		= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 24,  1, 0, 25),
157*a5b400eaSMoudy Ho 	MDP_COLOR_YUV444	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 24,  1, 0, 30),
15861890ccaSMoudy Ho 
15961890ccaSMoudy Ho 	/* Packed 10-bit formats */
160*a5b400eaSMoudy Ho 	MDP_COLOR_RGBA1010102	= MDP_COLOR(0, 1, 0, 0, 1, 0, 0, 32,  0, 1, 2),
161*a5b400eaSMoudy Ho 	MDP_COLOR_BGRA1010102	= MDP_COLOR(0, 1, 0, 0, 1, 0, 0, 32,  0, 0, 2),
16261890ccaSMoudy Ho 	/* Packed 10-bit UYVY */
163*a5b400eaSMoudy Ho 	MDP_COLOR_UYVY_10P	= MDP_COLOR(0, 1, 0, 0, 1, 1, 0, 20,  1, 0, 4),
16461890ccaSMoudy Ho 	/* Packed 10-bit NV21 */
165*a5b400eaSMoudy Ho 	MDP_COLOR_NV21_10P	= MDP_COLOR(0, 1, 0, 0, 2, 1, 1, 10,  1, 1, 12),
16661890ccaSMoudy Ho 	/* 10-bit block mode */
167*a5b400eaSMoudy Ho 	MDP_COLOR_420_BLK_10_H	= MDP_COLOR(0, 1, 0, 1, 2, 1, 1, 320, 1, 0, 12),
16861890ccaSMoudy Ho 	/* 10-bit HEVC tile mode */
169*a5b400eaSMoudy Ho 	MDP_COLOR_420_BLK_10_V	= MDP_COLOR(0, 1, 1, 1, 2, 1, 1, 320, 1, 0, 12),
17061890ccaSMoudy Ho 	/* UFO encoded 10-bit block mode */
171*a5b400eaSMoudy Ho 	MDP_COLOR_420_BLK_U10_H	= MDP_COLOR(0, 1, 0, 5, 2, 1, 1, 320, 1, 0, 12),
17261890ccaSMoudy Ho 	/* UFO encoded 10-bit HEVC tile mode */
173*a5b400eaSMoudy Ho 	MDP_COLOR_420_BLK_U10_V	= MDP_COLOR(0, 1, 1, 5, 2, 1, 1, 320, 1, 0, 12),
17461890ccaSMoudy Ho 
17561890ccaSMoudy Ho 	/* Loose 10-bit formats */
176*a5b400eaSMoudy Ho 	MDP_COLOR_UYVY_10L	= MDP_COLOR(0, 0, 1, 0, 1, 1, 0, 20,  1, 0, 4),
177*a5b400eaSMoudy Ho 	MDP_COLOR_VYUY_10L	= MDP_COLOR(0, 0, 1, 0, 1, 1, 0, 20,  1, 1, 4),
178*a5b400eaSMoudy Ho 	MDP_COLOR_YUYV_10L	= MDP_COLOR(0, 0, 1, 0, 1, 1, 0, 20,  1, 0, 5),
179*a5b400eaSMoudy Ho 	MDP_COLOR_YVYU_10L	= MDP_COLOR(0, 0, 1, 0, 1, 1, 0, 20,  1, 1, 5),
180*a5b400eaSMoudy Ho 	MDP_COLOR_NV12_10L	= MDP_COLOR(0, 0, 1, 0, 2, 1, 1, 10,  1, 0, 12),
181*a5b400eaSMoudy Ho 	MDP_COLOR_NV21_10L	= MDP_COLOR(0, 0, 1, 0, 2, 1, 1, 10,  1, 1, 12),
182*a5b400eaSMoudy Ho 	MDP_COLOR_NV16_10L	= MDP_COLOR(0, 0, 1, 0, 2, 1, 0, 10,  1, 0, 13),
183*a5b400eaSMoudy Ho 	MDP_COLOR_NV61_10L	= MDP_COLOR(0, 0, 1, 0, 2, 1, 0, 10,  1, 1, 13),
184*a5b400eaSMoudy Ho 	MDP_COLOR_YV12_10L	= MDP_COLOR(0, 0, 1, 0, 3, 1, 1, 10,  1, 1, 8),
185*a5b400eaSMoudy Ho 	MDP_COLOR_I420_10L	= MDP_COLOR(0, 0, 1, 0, 3, 1, 1, 10,  1, 0, 8),
18661890ccaSMoudy Ho };
18761890ccaSMoudy Ho 
MDP_COLOR_IS_UV_COPLANE(enum mdp_color c)18861890ccaSMoudy Ho static inline bool MDP_COLOR_IS_UV_COPLANE(enum mdp_color c)
18961890ccaSMoudy Ho {
19061890ccaSMoudy Ho 	return (MDP_COLOR_GET_PLANE_COUNT(c) == 2 && MDP_COLOR_IS_YUV(c));
19161890ccaSMoudy Ho }
19261890ccaSMoudy Ho 
19361890ccaSMoudy Ho /* Minimum Y stride that is accepted by MDP HW */
mdp_color_get_min_y_stride(enum mdp_color c,u32 width)19461890ccaSMoudy Ho static inline u32 mdp_color_get_min_y_stride(enum mdp_color c, u32 width)
19561890ccaSMoudy Ho {
19661890ccaSMoudy Ho 	return ((MDP_COLOR_BITS_PER_PIXEL(c) * width) + 4) >> 3;
19761890ccaSMoudy Ho }
19861890ccaSMoudy Ho 
19961890ccaSMoudy Ho /* Minimum UV stride that is accepted by MDP HW */
mdp_color_get_min_uv_stride(enum mdp_color c,u32 width)20061890ccaSMoudy Ho static inline u32 mdp_color_get_min_uv_stride(enum mdp_color c, u32 width)
20161890ccaSMoudy Ho {
20261890ccaSMoudy Ho 	u32 min_stride;
20361890ccaSMoudy Ho 
20461890ccaSMoudy Ho 	if (MDP_COLOR_GET_PLANE_COUNT(c) == 1)
20561890ccaSMoudy Ho 		return 0;
20661890ccaSMoudy Ho 	min_stride = mdp_color_get_min_y_stride(c, width)
20761890ccaSMoudy Ho 		>> MDP_COLOR_GET_H_SUBSAMPLE(c);
20861890ccaSMoudy Ho 	if (MDP_COLOR_IS_UV_COPLANE(c) && !MDP_COLOR_IS_BLOCK_MODE(c))
20961890ccaSMoudy Ho 		min_stride = min_stride * 2;
21061890ccaSMoudy Ho 	return min_stride;
21161890ccaSMoudy Ho }
21261890ccaSMoudy Ho 
21361890ccaSMoudy Ho /* Minimum Y plane size that is necessary in buffer */
mdp_color_get_min_y_size(enum mdp_color c,u32 width,u32 height)21461890ccaSMoudy Ho static inline u32 mdp_color_get_min_y_size(enum mdp_color c,
21561890ccaSMoudy Ho 					   u32 width, u32 height)
21661890ccaSMoudy Ho {
21761890ccaSMoudy Ho 	if (MDP_COLOR_IS_BLOCK_MODE(c))
21861890ccaSMoudy Ho 		return ((MDP_COLOR_BITS_PER_PIXEL(c) * width) >> 8) * height;
21961890ccaSMoudy Ho 	return mdp_color_get_min_y_stride(c, width) * height;
22061890ccaSMoudy Ho }
22161890ccaSMoudy Ho 
22261890ccaSMoudy Ho /* Minimum UV plane size that is necessary in buffer */
mdp_color_get_min_uv_size(enum mdp_color c,u32 width,u32 height)22361890ccaSMoudy Ho static inline u32 mdp_color_get_min_uv_size(enum mdp_color c,
22461890ccaSMoudy Ho 					    u32 width, u32 height)
22561890ccaSMoudy Ho {
22661890ccaSMoudy Ho 	height = height >> MDP_COLOR_GET_V_SUBSAMPLE(c);
22761890ccaSMoudy Ho 	if (MDP_COLOR_IS_BLOCK_MODE(c) && (MDP_COLOR_GET_PLANE_COUNT(c) > 1))
22861890ccaSMoudy Ho 		return ((MDP_COLOR_BITS_PER_PIXEL(c) * width) >> 8) * height;
22961890ccaSMoudy Ho 	return mdp_color_get_min_uv_stride(c, width) * height;
23061890ccaSMoudy Ho }
23161890ccaSMoudy Ho 
23261890ccaSMoudy Ho /* Combine colorspace, xfer_func, ycbcr_encoding, and quantization */
23361890ccaSMoudy Ho enum mdp_ycbcr_profile {
23461890ccaSMoudy Ho 	/* V4L2_YCBCR_ENC_601 and V4L2_QUANTIZATION_LIM_RANGE */
23561890ccaSMoudy Ho 	MDP_YCBCR_PROFILE_BT601,
23661890ccaSMoudy Ho 	/* V4L2_YCBCR_ENC_709 and V4L2_QUANTIZATION_LIM_RANGE */
23761890ccaSMoudy Ho 	MDP_YCBCR_PROFILE_BT709,
23861890ccaSMoudy Ho 	/* V4L2_YCBCR_ENC_601 and V4L2_QUANTIZATION_FULL_RANGE */
23961890ccaSMoudy Ho 	MDP_YCBCR_PROFILE_JPEG,
24061890ccaSMoudy Ho 	MDP_YCBCR_PROFILE_FULL_BT601 = MDP_YCBCR_PROFILE_JPEG,
24161890ccaSMoudy Ho 
24261890ccaSMoudy Ho 	/* Colorspaces not support for capture */
24361890ccaSMoudy Ho 	/* V4L2_YCBCR_ENC_BT2020 and V4L2_QUANTIZATION_LIM_RANGE */
24461890ccaSMoudy Ho 	MDP_YCBCR_PROFILE_BT2020,
24561890ccaSMoudy Ho 	/* V4L2_YCBCR_ENC_709 and V4L2_QUANTIZATION_FULL_RANGE */
24661890ccaSMoudy Ho 	MDP_YCBCR_PROFILE_FULL_BT709,
24761890ccaSMoudy Ho 	/* V4L2_YCBCR_ENC_BT2020 and V4L2_QUANTIZATION_FULL_RANGE */
24861890ccaSMoudy Ho 	MDP_YCBCR_PROFILE_FULL_BT2020,
24961890ccaSMoudy Ho };
25061890ccaSMoudy Ho 
25161890ccaSMoudy Ho #define MDP_FMT_FLAG_OUTPUT	BIT(0)
25261890ccaSMoudy Ho #define MDP_FMT_FLAG_CAPTURE	BIT(1)
25361890ccaSMoudy Ho 
25461890ccaSMoudy Ho struct mdp_format {
25561890ccaSMoudy Ho 	u32	pixelformat;
25661890ccaSMoudy Ho 	u32	mdp_color;
25761890ccaSMoudy Ho 	u8	depth[VIDEO_MAX_PLANES];
25861890ccaSMoudy Ho 	u8	row_depth[VIDEO_MAX_PLANES];
25961890ccaSMoudy Ho 	u8	num_planes;
26061890ccaSMoudy Ho 	u8	walign;
26161890ccaSMoudy Ho 	u8	halign;
26261890ccaSMoudy Ho 	u8	salign;
26361890ccaSMoudy Ho 	u32	flags;
26461890ccaSMoudy Ho };
26561890ccaSMoudy Ho 
26661890ccaSMoudy Ho struct mdp_pix_limit {
26761890ccaSMoudy Ho 	u32	wmin;
26861890ccaSMoudy Ho 	u32	hmin;
26961890ccaSMoudy Ho 	u32	wmax;
27061890ccaSMoudy Ho 	u32	hmax;
27161890ccaSMoudy Ho };
27261890ccaSMoudy Ho 
27361890ccaSMoudy Ho struct mdp_limit {
27461890ccaSMoudy Ho 	struct mdp_pix_limit	out_limit;
27561890ccaSMoudy Ho 	struct mdp_pix_limit	cap_limit;
27661890ccaSMoudy Ho 	u32			h_scale_up_max;
27761890ccaSMoudy Ho 	u32			v_scale_up_max;
27861890ccaSMoudy Ho 	u32			h_scale_down_max;
27961890ccaSMoudy Ho 	u32			v_scale_down_max;
28061890ccaSMoudy Ho };
28161890ccaSMoudy Ho 
28261890ccaSMoudy Ho enum mdp_stream_type {
28361890ccaSMoudy Ho 	MDP_STREAM_TYPE_UNKNOWN,
28461890ccaSMoudy Ho 	MDP_STREAM_TYPE_BITBLT,
28561890ccaSMoudy Ho 	MDP_STREAM_TYPE_GPU_BITBLT,
28661890ccaSMoudy Ho 	MDP_STREAM_TYPE_DUAL_BITBLT,
28761890ccaSMoudy Ho 	MDP_STREAM_TYPE_2ND_BITBLT,
28861890ccaSMoudy Ho 	MDP_STREAM_TYPE_ISP_IC,
28961890ccaSMoudy Ho 	MDP_STREAM_TYPE_ISP_VR,
29061890ccaSMoudy Ho 	MDP_STREAM_TYPE_ISP_ZSD,
29161890ccaSMoudy Ho 	MDP_STREAM_TYPE_ISP_IP,
29261890ccaSMoudy Ho 	MDP_STREAM_TYPE_ISP_VSS,
29361890ccaSMoudy Ho 	MDP_STREAM_TYPE_ISP_ZSD_SLOW,
29461890ccaSMoudy Ho 	MDP_STREAM_TYPE_WPE,
29561890ccaSMoudy Ho 	MDP_STREAM_TYPE_WPE2,
29661890ccaSMoudy Ho };
29761890ccaSMoudy Ho 
29861890ccaSMoudy Ho struct mdp_crop {
29961890ccaSMoudy Ho 	struct v4l2_rect	c;
30061890ccaSMoudy Ho 	struct v4l2_fract	left_subpix;
30161890ccaSMoudy Ho 	struct v4l2_fract	top_subpix;
30261890ccaSMoudy Ho 	struct v4l2_fract	width_subpix;
30361890ccaSMoudy Ho 	struct v4l2_fract	height_subpix;
30461890ccaSMoudy Ho };
30561890ccaSMoudy Ho 
30661890ccaSMoudy Ho struct mdp_frame {
30761890ccaSMoudy Ho 	struct v4l2_format	format;
30861890ccaSMoudy Ho 	const struct mdp_format	*mdp_fmt;
30961890ccaSMoudy Ho 	u32			ycbcr_prof;	/* enum mdp_ycbcr_profile */
31061890ccaSMoudy Ho 	u32			usage;		/* enum mdp_buffer_usage */
31161890ccaSMoudy Ho 	struct mdp_crop		crop;
31261890ccaSMoudy Ho 	struct v4l2_rect	compose;
31361890ccaSMoudy Ho 	s32			rotation;
31461890ccaSMoudy Ho 	u32			hflip:1;
31561890ccaSMoudy Ho 	u32			vflip:1;
31661890ccaSMoudy Ho 	u32			hdr:1;
31761890ccaSMoudy Ho 	u32			dre:1;
31861890ccaSMoudy Ho 	u32			sharpness:1;
31961890ccaSMoudy Ho 	u32			dither:1;
32061890ccaSMoudy Ho };
32161890ccaSMoudy Ho 
mdp_target_is_crop(u32 target)32261890ccaSMoudy Ho static inline bool mdp_target_is_crop(u32 target)
32361890ccaSMoudy Ho {
32461890ccaSMoudy Ho 	return (target == V4L2_SEL_TGT_CROP) ||
32561890ccaSMoudy Ho 		(target == V4L2_SEL_TGT_CROP_DEFAULT) ||
32661890ccaSMoudy Ho 		(target == V4L2_SEL_TGT_CROP_BOUNDS);
32761890ccaSMoudy Ho }
32861890ccaSMoudy Ho 
mdp_target_is_compose(u32 target)32961890ccaSMoudy Ho static inline bool mdp_target_is_compose(u32 target)
33061890ccaSMoudy Ho {
33161890ccaSMoudy Ho 	return (target == V4L2_SEL_TGT_COMPOSE) ||
33261890ccaSMoudy Ho 		(target == V4L2_SEL_TGT_COMPOSE_DEFAULT) ||
33361890ccaSMoudy Ho 		(target == V4L2_SEL_TGT_COMPOSE_BOUNDS);
33461890ccaSMoudy Ho }
33561890ccaSMoudy Ho 
33661890ccaSMoudy Ho #define MDP_MAX_CAPTURES	IMG_MAX_HW_OUTPUTS
33761890ccaSMoudy Ho 
33861890ccaSMoudy Ho #define MDP_VPU_INIT		BIT(0)
33961890ccaSMoudy Ho #define MDP_M2M_CTX_ERROR	BIT(1)
34061890ccaSMoudy Ho 
34161890ccaSMoudy Ho struct mdp_frameparam {
34261890ccaSMoudy Ho 	struct list_head	list;
34361890ccaSMoudy Ho 	struct mdp_m2m_ctx	*ctx;
34461890ccaSMoudy Ho 	atomic_t		state;
34561890ccaSMoudy Ho 	const struct mdp_limit	*limit;
34661890ccaSMoudy Ho 	u32			type;	/* enum mdp_stream_type */
34761890ccaSMoudy Ho 	u32			frame_no;
34861890ccaSMoudy Ho 	struct mdp_frame	output;
34961890ccaSMoudy Ho 	struct mdp_frame	captures[MDP_MAX_CAPTURES];
35061890ccaSMoudy Ho 	u32			num_captures;
35161890ccaSMoudy Ho 	enum v4l2_colorspace		colorspace;
35261890ccaSMoudy Ho 	enum v4l2_ycbcr_encoding	ycbcr_enc;
35361890ccaSMoudy Ho 	enum v4l2_xfer_func		xfer_func;
35461890ccaSMoudy Ho 	enum v4l2_quantization		quant;
35561890ccaSMoudy Ho };
35661890ccaSMoudy Ho 
3576b8910e3SMoudy Ho struct mdp_dev;
3586b8910e3SMoudy Ho 
3596b8910e3SMoudy Ho int mdp_enum_fmt_mplane(struct mdp_dev *mdp, struct v4l2_fmtdesc *f);
3606b8910e3SMoudy Ho const struct mdp_format *mdp_try_fmt_mplane(struct mdp_dev *mdp,
3616b8910e3SMoudy Ho 					    struct v4l2_format *f,
36261890ccaSMoudy Ho 					    struct mdp_frameparam *param,
36361890ccaSMoudy Ho 					    u32 ctx_id);
36461890ccaSMoudy Ho enum mdp_ycbcr_profile mdp_map_ycbcr_prof_mplane(struct v4l2_format *f,
36561890ccaSMoudy Ho 						 u32 mdp_color);
36661890ccaSMoudy Ho int mdp_try_crop(struct mdp_m2m_ctx *ctx, struct v4l2_rect *r,
36761890ccaSMoudy Ho 		 const struct v4l2_selection *s, struct mdp_frame *frame);
36861890ccaSMoudy Ho int mdp_check_scaling_ratio(const struct v4l2_rect *crop,
36961890ccaSMoudy Ho 			    const struct v4l2_rect *compose, s32 rotation,
37061890ccaSMoudy Ho 	const struct mdp_limit *limit);
37161890ccaSMoudy Ho void mdp_set_src_config(struct img_input *in,
37261890ccaSMoudy Ho 			struct mdp_frame *frame, struct vb2_buffer *vb);
37361890ccaSMoudy Ho void mdp_set_dst_config(struct img_output *out,
37461890ccaSMoudy Ho 			struct mdp_frame *frame, struct vb2_buffer *vb);
3756b8910e3SMoudy Ho int mdp_frameparam_init(struct mdp_dev *mdp, struct mdp_frameparam *param);
37661890ccaSMoudy Ho 
37761890ccaSMoudy Ho #endif  /* __MTK_MDP3_REGS_H__ */
378