162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2022 MediaTek Inc.
462306a36Sopenharmony_ci * Author: Ping-Hsun Wu <ping-hsun.wu@mediatek.com>
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef __MTK_MDP3_REGS_H__
862306a36Sopenharmony_ci#define __MTK_MDP3_REGS_H__
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/videodev2.h>
1162306a36Sopenharmony_ci#include <media/videobuf2-core.h>
1262306a36Sopenharmony_ci#include "mtk-img-ipi.h"
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/*
1562306a36Sopenharmony_ci * MDP native color code
1662306a36Sopenharmony_ci * Plane count: 1, 2, 3
1762306a36Sopenharmony_ci * H-subsample: 0, 1, 2
1862306a36Sopenharmony_ci * V-subsample: 0, 1
1962306a36Sopenharmony_ci * Color group: 0-RGB, 1-YUV, 2-raw
2062306a36Sopenharmony_ci */
2162306a36Sopenharmony_ci#define MDP_COLOR(COMPRESS, PACKED, LOOSE, VIDEO, PLANE, HF, VF, BITS, GROUP, SWAP, ID)\
2262306a36Sopenharmony_ci	(((COMPRESS) << 29) | ((PACKED) << 27) | ((LOOSE) << 26) | ((VIDEO) << 23) |\
2362306a36Sopenharmony_ci	 ((PLANE) << 21) | ((HF) << 19) | ((VF) << 18) | ((BITS) << 8) |\
2462306a36Sopenharmony_ci	 ((GROUP) << 6) | ((SWAP) << 5) | ((ID) << 0))
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define MDP_COLOR_IS_COMPRESS(c)        ((0x20000000 & (c)) >> 29)
2762306a36Sopenharmony_ci#define MDP_COLOR_IS_10BIT_PACKED(c)	((0x08000000 & (c)) >> 27)
2862306a36Sopenharmony_ci#define MDP_COLOR_IS_10BIT_LOOSE(c)	(((0x0c000000 & (c)) >> 26) == 1)
2962306a36Sopenharmony_ci#define MDP_COLOR_IS_10BIT_TILE(c)	(((0x0c000000 & (c)) >> 26) == 3)
3062306a36Sopenharmony_ci#define MDP_COLOR_IS_UFP(c)		((0x02000000 & (c)) >> 25)
3162306a36Sopenharmony_ci#define MDP_COLOR_IS_INTERLACED(c)	((0x01000000 & (c)) >> 24)
3262306a36Sopenharmony_ci#define MDP_COLOR_IS_BLOCK_MODE(c)	((0x00800000 & (c)) >> 23)
3362306a36Sopenharmony_ci#define MDP_COLOR_GET_PLANE_COUNT(c)	((0x00600000 & (c)) >> 21)
3462306a36Sopenharmony_ci#define MDP_COLOR_GET_H_SUBSAMPLE(c)	((0x00180000 & (c)) >> 19)
3562306a36Sopenharmony_ci#define MDP_COLOR_GET_V_SUBSAMPLE(c)	((0x00040000 & (c)) >> 18)
3662306a36Sopenharmony_ci#define MDP_COLOR_BITS_PER_PIXEL(c)	((0x0003ff00 & (c)) >>  8)
3762306a36Sopenharmony_ci#define MDP_COLOR_GET_GROUP(c)		((0x000000c0 & (c)) >>  6)
3862306a36Sopenharmony_ci#define MDP_COLOR_IS_SWAPPED(c)		((0x00000020 & (c)) >>  5)
3962306a36Sopenharmony_ci#define MDP_COLOR_GET_UNIQUE_ID(c)	((0x0000001f & (c)) >>  0)
4062306a36Sopenharmony_ci#define MDP_COLOR_GET_HW_FORMAT(c)	((0x0000001f & (c)) >>  0)
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#define MDP_COLOR_IS_RGB(c)		(MDP_COLOR_GET_GROUP(c) == 0)
4362306a36Sopenharmony_ci#define MDP_COLOR_IS_YUV(c)		(MDP_COLOR_GET_GROUP(c) == 1)
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_cienum mdp_color {
4662306a36Sopenharmony_ci	MDP_COLOR_UNKNOWN	= 0,
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci	/* MDP_COLOR_FULLG8 */
4962306a36Sopenharmony_ci	MDP_COLOR_FULLG8_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0,  8, 2,  0, 21),
5062306a36Sopenharmony_ci	MDP_COLOR_FULLG8_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1,  8, 2,  0, 21),
5162306a36Sopenharmony_ci	MDP_COLOR_FULLG8_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0,  8, 2,  0, 21),
5262306a36Sopenharmony_ci	MDP_COLOR_FULLG8_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1,  8, 2,  0, 21),
5362306a36Sopenharmony_ci	MDP_COLOR_FULLG8	= MDP_COLOR_FULLG8_BGGR,
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci	/* MDP_COLOR_FULLG10 */
5662306a36Sopenharmony_ci	MDP_COLOR_FULLG10_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 10, 2,  0, 21),
5762306a36Sopenharmony_ci	MDP_COLOR_FULLG10_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 10, 2,  0, 21),
5862306a36Sopenharmony_ci	MDP_COLOR_FULLG10_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 10, 2,  0, 21),
5962306a36Sopenharmony_ci	MDP_COLOR_FULLG10_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 10, 2,  0, 21),
6062306a36Sopenharmony_ci	MDP_COLOR_FULLG10	= MDP_COLOR_FULLG10_BGGR,
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci	/* MDP_COLOR_FULLG12 */
6362306a36Sopenharmony_ci	MDP_COLOR_FULLG12_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 12, 2,  0, 21),
6462306a36Sopenharmony_ci	MDP_COLOR_FULLG12_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 12, 2,  0, 21),
6562306a36Sopenharmony_ci	MDP_COLOR_FULLG12_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 12, 2,  0, 21),
6662306a36Sopenharmony_ci	MDP_COLOR_FULLG12_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 12, 2,  0, 21),
6762306a36Sopenharmony_ci	MDP_COLOR_FULLG12	= MDP_COLOR_FULLG12_BGGR,
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci	/* MDP_COLOR_FULLG14 */
7062306a36Sopenharmony_ci	MDP_COLOR_FULLG14_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 14, 2,  0, 21),
7162306a36Sopenharmony_ci	MDP_COLOR_FULLG14_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 14, 2,  0, 21),
7262306a36Sopenharmony_ci	MDP_COLOR_FULLG14_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 14, 2,  0, 21),
7362306a36Sopenharmony_ci	MDP_COLOR_FULLG14_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 14, 2,  0, 21),
7462306a36Sopenharmony_ci	MDP_COLOR_FULLG14	= MDP_COLOR_FULLG14_BGGR,
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci	MDP_COLOR_UFO10		= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 10, 2,  0, 24),
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci	/* MDP_COLOR_BAYER8 */
7962306a36Sopenharmony_ci	MDP_COLOR_BAYER8_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0,  8, 2,  0, 20),
8062306a36Sopenharmony_ci	MDP_COLOR_BAYER8_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1,  8, 2,  0, 20),
8162306a36Sopenharmony_ci	MDP_COLOR_BAYER8_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0,  8, 2,  0, 20),
8262306a36Sopenharmony_ci	MDP_COLOR_BAYER8_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1,  8, 2,  0, 20),
8362306a36Sopenharmony_ci	MDP_COLOR_BAYER8	= MDP_COLOR_BAYER8_BGGR,
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci	/* MDP_COLOR_BAYER10 */
8662306a36Sopenharmony_ci	MDP_COLOR_BAYER10_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 10, 2,  0, 20),
8762306a36Sopenharmony_ci	MDP_COLOR_BAYER10_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 10, 2,  0, 20),
8862306a36Sopenharmony_ci	MDP_COLOR_BAYER10_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 10, 2,  0, 20),
8962306a36Sopenharmony_ci	MDP_COLOR_BAYER10_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 10, 2,  0, 20),
9062306a36Sopenharmony_ci	MDP_COLOR_BAYER10	= MDP_COLOR_BAYER10_BGGR,
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci	/* MDP_COLOR_BAYER12 */
9362306a36Sopenharmony_ci	MDP_COLOR_BAYER12_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 12, 2,  0, 20),
9462306a36Sopenharmony_ci	MDP_COLOR_BAYER12_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 12, 2,  0, 20),
9562306a36Sopenharmony_ci	MDP_COLOR_BAYER12_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 12, 2,  0, 20),
9662306a36Sopenharmony_ci	MDP_COLOR_BAYER12_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 12, 2,  0, 20),
9762306a36Sopenharmony_ci	MDP_COLOR_BAYER12	= MDP_COLOR_BAYER12_BGGR,
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci	/* MDP_COLOR_BAYER14 */
10062306a36Sopenharmony_ci	MDP_COLOR_BAYER14_RGGB	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 14, 2,  0, 20),
10162306a36Sopenharmony_ci	MDP_COLOR_BAYER14_GRBG	= MDP_COLOR(0, 0, 0, 0, 1, 0, 1, 14, 2,  0, 20),
10262306a36Sopenharmony_ci	MDP_COLOR_BAYER14_GBRG	= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 14, 2,  0, 20),
10362306a36Sopenharmony_ci	MDP_COLOR_BAYER14_BGGR	= MDP_COLOR(0, 0, 0, 0, 1, 1, 1, 14, 2,  0, 20),
10462306a36Sopenharmony_ci	MDP_COLOR_BAYER14	= MDP_COLOR_BAYER14_BGGR,
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci	MDP_COLOR_RGB48		= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 48, 0,  0, 23),
10762306a36Sopenharmony_ci	/* For bayer+mono raw-16 */
10862306a36Sopenharmony_ci	MDP_COLOR_RGB565_RAW	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 16, 2,  0, 0),
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci	MDP_COLOR_BAYER8_UNPAK	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0,  8, 2,  0, 22),
11162306a36Sopenharmony_ci	MDP_COLOR_BAYER10_UNPAK	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 10, 2,  0, 22),
11262306a36Sopenharmony_ci	MDP_COLOR_BAYER12_UNPAK	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 12, 2,  0, 22),
11362306a36Sopenharmony_ci	MDP_COLOR_BAYER14_UNPAK	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 14, 2,  0, 22),
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci	/* Unified formats */
11662306a36Sopenharmony_ci	MDP_COLOR_GREY		= MDP_COLOR(0, 0, 0, 0, 1, 0, 0,  8, 1,  0, 7),
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci	MDP_COLOR_RGB565	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 16, 0,  0, 0),
11962306a36Sopenharmony_ci	MDP_COLOR_BGR565	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 16, 0,  1, 0),
12062306a36Sopenharmony_ci	MDP_COLOR_RGB888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 24, 0,  1, 1),
12162306a36Sopenharmony_ci	MDP_COLOR_BGR888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 24, 0,  0, 1),
12262306a36Sopenharmony_ci	MDP_COLOR_RGBA8888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 32, 0,  1, 2),
12362306a36Sopenharmony_ci	MDP_COLOR_BGRA8888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 32, 0,  0, 2),
12462306a36Sopenharmony_ci	MDP_COLOR_ARGB8888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 32, 0,  1, 3),
12562306a36Sopenharmony_ci	MDP_COLOR_ABGR8888	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 32, 0,  0, 3),
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci	MDP_COLOR_UYVY		= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 16, 1,  0, 4),
12862306a36Sopenharmony_ci	MDP_COLOR_VYUY		= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 16, 1,  1, 4),
12962306a36Sopenharmony_ci	MDP_COLOR_YUYV		= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 16, 1,  0, 5),
13062306a36Sopenharmony_ci	MDP_COLOR_YVYU		= MDP_COLOR(0, 0, 0, 0, 1, 1, 0, 16, 1,  1, 5),
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci	MDP_COLOR_I420		= MDP_COLOR(0, 0, 0, 0, 3, 1, 1,  8, 1,  0, 8),
13362306a36Sopenharmony_ci	MDP_COLOR_YV12		= MDP_COLOR(0, 0, 0, 0, 3, 1, 1,  8, 1,  1, 8),
13462306a36Sopenharmony_ci	MDP_COLOR_I422		= MDP_COLOR(0, 0, 0, 0, 3, 1, 0,  8, 1,  0, 9),
13562306a36Sopenharmony_ci	MDP_COLOR_YV16		= MDP_COLOR(0, 0, 0, 0, 3, 1, 0,  8, 1,  1, 9),
13662306a36Sopenharmony_ci	MDP_COLOR_I444		= MDP_COLOR(0, 0, 0, 0, 3, 0, 0,  8, 1,  0, 10),
13762306a36Sopenharmony_ci	MDP_COLOR_YV24		= MDP_COLOR(0, 0, 0, 0, 3, 0, 0,  8, 1,  1, 10),
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci	MDP_COLOR_NV12		= MDP_COLOR(0, 0, 0, 0, 2, 1, 1,  8, 1,  0, 12),
14062306a36Sopenharmony_ci	MDP_COLOR_NV21		= MDP_COLOR(0, 0, 0, 0, 2, 1, 1,  8, 1,  1, 12),
14162306a36Sopenharmony_ci	MDP_COLOR_NV16		= MDP_COLOR(0, 0, 0, 0, 2, 1, 0,  8, 1,  0, 13),
14262306a36Sopenharmony_ci	MDP_COLOR_NV61		= MDP_COLOR(0, 0, 0, 0, 2, 1, 0,  8, 1,  1, 13),
14362306a36Sopenharmony_ci	MDP_COLOR_NV24		= MDP_COLOR(0, 0, 0, 0, 2, 0, 0,  8, 1,  0, 14),
14462306a36Sopenharmony_ci	MDP_COLOR_NV42		= MDP_COLOR(0, 0, 0, 0, 2, 0, 0,  8, 1,  1, 14),
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci	/* MediaTek proprietary formats */
14762306a36Sopenharmony_ci	/* UFO encoded block mode */
14862306a36Sopenharmony_ci	MDP_COLOR_420_BLK_UFO	= MDP_COLOR(0, 0, 0, 5, 2, 1, 1, 256, 1, 0, 12),
14962306a36Sopenharmony_ci	/* Block mode */
15062306a36Sopenharmony_ci	MDP_COLOR_420_BLK	= MDP_COLOR(0, 0, 0, 1, 2, 1, 1, 256, 1, 0, 12),
15162306a36Sopenharmony_ci	/* Block mode + field mode */
15262306a36Sopenharmony_ci	MDP_COLOR_420_BLKI	= MDP_COLOR(0, 0, 0, 3, 2, 1, 1, 256, 1, 0, 12),
15362306a36Sopenharmony_ci	/* Block mode */
15462306a36Sopenharmony_ci	MDP_COLOR_422_BLK	= MDP_COLOR(0, 0, 0, 1, 1, 1, 0, 512, 1, 0, 4),
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci	MDP_COLOR_IYU2		= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 24,  1, 0, 25),
15762306a36Sopenharmony_ci	MDP_COLOR_YUV444	= MDP_COLOR(0, 0, 0, 0, 1, 0, 0, 24,  1, 0, 30),
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci	/* Packed 10-bit formats */
16062306a36Sopenharmony_ci	MDP_COLOR_RGBA1010102	= MDP_COLOR(0, 1, 0, 0, 1, 0, 0, 32,  0, 1, 2),
16162306a36Sopenharmony_ci	MDP_COLOR_BGRA1010102	= MDP_COLOR(0, 1, 0, 0, 1, 0, 0, 32,  0, 0, 2),
16262306a36Sopenharmony_ci	/* Packed 10-bit UYVY */
16362306a36Sopenharmony_ci	MDP_COLOR_UYVY_10P	= MDP_COLOR(0, 1, 0, 0, 1, 1, 0, 20,  1, 0, 4),
16462306a36Sopenharmony_ci	/* Packed 10-bit NV21 */
16562306a36Sopenharmony_ci	MDP_COLOR_NV21_10P	= MDP_COLOR(0, 1, 0, 0, 2, 1, 1, 10,  1, 1, 12),
16662306a36Sopenharmony_ci	/* 10-bit block mode */
16762306a36Sopenharmony_ci	MDP_COLOR_420_BLK_10_H	= MDP_COLOR(0, 1, 0, 1, 2, 1, 1, 320, 1, 0, 12),
16862306a36Sopenharmony_ci	/* 10-bit HEVC tile mode */
16962306a36Sopenharmony_ci	MDP_COLOR_420_BLK_10_V	= MDP_COLOR(0, 1, 1, 1, 2, 1, 1, 320, 1, 0, 12),
17062306a36Sopenharmony_ci	/* UFO encoded 10-bit block mode */
17162306a36Sopenharmony_ci	MDP_COLOR_420_BLK_U10_H	= MDP_COLOR(0, 1, 0, 5, 2, 1, 1, 320, 1, 0, 12),
17262306a36Sopenharmony_ci	/* UFO encoded 10-bit HEVC tile mode */
17362306a36Sopenharmony_ci	MDP_COLOR_420_BLK_U10_V	= MDP_COLOR(0, 1, 1, 5, 2, 1, 1, 320, 1, 0, 12),
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci	/* Loose 10-bit formats */
17662306a36Sopenharmony_ci	MDP_COLOR_UYVY_10L	= MDP_COLOR(0, 0, 1, 0, 1, 1, 0, 20,  1, 0, 4),
17762306a36Sopenharmony_ci	MDP_COLOR_VYUY_10L	= MDP_COLOR(0, 0, 1, 0, 1, 1, 0, 20,  1, 1, 4),
17862306a36Sopenharmony_ci	MDP_COLOR_YUYV_10L	= MDP_COLOR(0, 0, 1, 0, 1, 1, 0, 20,  1, 0, 5),
17962306a36Sopenharmony_ci	MDP_COLOR_YVYU_10L	= MDP_COLOR(0, 0, 1, 0, 1, 1, 0, 20,  1, 1, 5),
18062306a36Sopenharmony_ci	MDP_COLOR_NV12_10L	= MDP_COLOR(0, 0, 1, 0, 2, 1, 1, 10,  1, 0, 12),
18162306a36Sopenharmony_ci	MDP_COLOR_NV21_10L	= MDP_COLOR(0, 0, 1, 0, 2, 1, 1, 10,  1, 1, 12),
18262306a36Sopenharmony_ci	MDP_COLOR_NV16_10L	= MDP_COLOR(0, 0, 1, 0, 2, 1, 0, 10,  1, 0, 13),
18362306a36Sopenharmony_ci	MDP_COLOR_NV61_10L	= MDP_COLOR(0, 0, 1, 0, 2, 1, 0, 10,  1, 1, 13),
18462306a36Sopenharmony_ci	MDP_COLOR_YV12_10L	= MDP_COLOR(0, 0, 1, 0, 3, 1, 1, 10,  1, 1, 8),
18562306a36Sopenharmony_ci	MDP_COLOR_I420_10L	= MDP_COLOR(0, 0, 1, 0, 3, 1, 1, 10,  1, 0, 8),
18662306a36Sopenharmony_ci};
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_cistatic inline bool MDP_COLOR_IS_UV_COPLANE(enum mdp_color c)
18962306a36Sopenharmony_ci{
19062306a36Sopenharmony_ci	return (MDP_COLOR_GET_PLANE_COUNT(c) == 2 && MDP_COLOR_IS_YUV(c));
19162306a36Sopenharmony_ci}
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci/* Minimum Y stride that is accepted by MDP HW */
19462306a36Sopenharmony_cistatic inline u32 mdp_color_get_min_y_stride(enum mdp_color c, u32 width)
19562306a36Sopenharmony_ci{
19662306a36Sopenharmony_ci	return ((MDP_COLOR_BITS_PER_PIXEL(c) * width) + 4) >> 3;
19762306a36Sopenharmony_ci}
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci/* Minimum UV stride that is accepted by MDP HW */
20062306a36Sopenharmony_cistatic inline u32 mdp_color_get_min_uv_stride(enum mdp_color c, u32 width)
20162306a36Sopenharmony_ci{
20262306a36Sopenharmony_ci	u32 min_stride;
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci	if (MDP_COLOR_GET_PLANE_COUNT(c) == 1)
20562306a36Sopenharmony_ci		return 0;
20662306a36Sopenharmony_ci	min_stride = mdp_color_get_min_y_stride(c, width)
20762306a36Sopenharmony_ci		>> MDP_COLOR_GET_H_SUBSAMPLE(c);
20862306a36Sopenharmony_ci	if (MDP_COLOR_IS_UV_COPLANE(c) && !MDP_COLOR_IS_BLOCK_MODE(c))
20962306a36Sopenharmony_ci		min_stride = min_stride * 2;
21062306a36Sopenharmony_ci	return min_stride;
21162306a36Sopenharmony_ci}
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci/* Minimum Y plane size that is necessary in buffer */
21462306a36Sopenharmony_cistatic inline u32 mdp_color_get_min_y_size(enum mdp_color c,
21562306a36Sopenharmony_ci					   u32 width, u32 height)
21662306a36Sopenharmony_ci{
21762306a36Sopenharmony_ci	if (MDP_COLOR_IS_BLOCK_MODE(c))
21862306a36Sopenharmony_ci		return ((MDP_COLOR_BITS_PER_PIXEL(c) * width) >> 8) * height;
21962306a36Sopenharmony_ci	return mdp_color_get_min_y_stride(c, width) * height;
22062306a36Sopenharmony_ci}
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_ci/* Minimum UV plane size that is necessary in buffer */
22362306a36Sopenharmony_cistatic inline u32 mdp_color_get_min_uv_size(enum mdp_color c,
22462306a36Sopenharmony_ci					    u32 width, u32 height)
22562306a36Sopenharmony_ci{
22662306a36Sopenharmony_ci	height = height >> MDP_COLOR_GET_V_SUBSAMPLE(c);
22762306a36Sopenharmony_ci	if (MDP_COLOR_IS_BLOCK_MODE(c) && (MDP_COLOR_GET_PLANE_COUNT(c) > 1))
22862306a36Sopenharmony_ci		return ((MDP_COLOR_BITS_PER_PIXEL(c) * width) >> 8) * height;
22962306a36Sopenharmony_ci	return mdp_color_get_min_uv_stride(c, width) * height;
23062306a36Sopenharmony_ci}
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_ci/* Combine colorspace, xfer_func, ycbcr_encoding, and quantization */
23362306a36Sopenharmony_cienum mdp_ycbcr_profile {
23462306a36Sopenharmony_ci	/* V4L2_YCBCR_ENC_601 and V4L2_QUANTIZATION_LIM_RANGE */
23562306a36Sopenharmony_ci	MDP_YCBCR_PROFILE_BT601,
23662306a36Sopenharmony_ci	/* V4L2_YCBCR_ENC_709 and V4L2_QUANTIZATION_LIM_RANGE */
23762306a36Sopenharmony_ci	MDP_YCBCR_PROFILE_BT709,
23862306a36Sopenharmony_ci	/* V4L2_YCBCR_ENC_601 and V4L2_QUANTIZATION_FULL_RANGE */
23962306a36Sopenharmony_ci	MDP_YCBCR_PROFILE_JPEG,
24062306a36Sopenharmony_ci	MDP_YCBCR_PROFILE_FULL_BT601 = MDP_YCBCR_PROFILE_JPEG,
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci	/* Colorspaces not support for capture */
24362306a36Sopenharmony_ci	/* V4L2_YCBCR_ENC_BT2020 and V4L2_QUANTIZATION_LIM_RANGE */
24462306a36Sopenharmony_ci	MDP_YCBCR_PROFILE_BT2020,
24562306a36Sopenharmony_ci	/* V4L2_YCBCR_ENC_709 and V4L2_QUANTIZATION_FULL_RANGE */
24662306a36Sopenharmony_ci	MDP_YCBCR_PROFILE_FULL_BT709,
24762306a36Sopenharmony_ci	/* V4L2_YCBCR_ENC_BT2020 and V4L2_QUANTIZATION_FULL_RANGE */
24862306a36Sopenharmony_ci	MDP_YCBCR_PROFILE_FULL_BT2020,
24962306a36Sopenharmony_ci};
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ci#define MDP_FMT_FLAG_OUTPUT	BIT(0)
25262306a36Sopenharmony_ci#define MDP_FMT_FLAG_CAPTURE	BIT(1)
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_cistruct mdp_format {
25562306a36Sopenharmony_ci	u32	pixelformat;
25662306a36Sopenharmony_ci	u32	mdp_color;
25762306a36Sopenharmony_ci	u8	depth[VIDEO_MAX_PLANES];
25862306a36Sopenharmony_ci	u8	row_depth[VIDEO_MAX_PLANES];
25962306a36Sopenharmony_ci	u8	num_planes;
26062306a36Sopenharmony_ci	u8	walign;
26162306a36Sopenharmony_ci	u8	halign;
26262306a36Sopenharmony_ci	u8	salign;
26362306a36Sopenharmony_ci	u32	flags;
26462306a36Sopenharmony_ci};
26562306a36Sopenharmony_ci
26662306a36Sopenharmony_cistruct mdp_pix_limit {
26762306a36Sopenharmony_ci	u32	wmin;
26862306a36Sopenharmony_ci	u32	hmin;
26962306a36Sopenharmony_ci	u32	wmax;
27062306a36Sopenharmony_ci	u32	hmax;
27162306a36Sopenharmony_ci};
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_cistruct mdp_limit {
27462306a36Sopenharmony_ci	struct mdp_pix_limit	out_limit;
27562306a36Sopenharmony_ci	struct mdp_pix_limit	cap_limit;
27662306a36Sopenharmony_ci	u32			h_scale_up_max;
27762306a36Sopenharmony_ci	u32			v_scale_up_max;
27862306a36Sopenharmony_ci	u32			h_scale_down_max;
27962306a36Sopenharmony_ci	u32			v_scale_down_max;
28062306a36Sopenharmony_ci};
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_cienum mdp_stream_type {
28362306a36Sopenharmony_ci	MDP_STREAM_TYPE_UNKNOWN,
28462306a36Sopenharmony_ci	MDP_STREAM_TYPE_BITBLT,
28562306a36Sopenharmony_ci	MDP_STREAM_TYPE_GPU_BITBLT,
28662306a36Sopenharmony_ci	MDP_STREAM_TYPE_DUAL_BITBLT,
28762306a36Sopenharmony_ci	MDP_STREAM_TYPE_2ND_BITBLT,
28862306a36Sopenharmony_ci	MDP_STREAM_TYPE_ISP_IC,
28962306a36Sopenharmony_ci	MDP_STREAM_TYPE_ISP_VR,
29062306a36Sopenharmony_ci	MDP_STREAM_TYPE_ISP_ZSD,
29162306a36Sopenharmony_ci	MDP_STREAM_TYPE_ISP_IP,
29262306a36Sopenharmony_ci	MDP_STREAM_TYPE_ISP_VSS,
29362306a36Sopenharmony_ci	MDP_STREAM_TYPE_ISP_ZSD_SLOW,
29462306a36Sopenharmony_ci	MDP_STREAM_TYPE_WPE,
29562306a36Sopenharmony_ci	MDP_STREAM_TYPE_WPE2,
29662306a36Sopenharmony_ci};
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_cistruct mdp_crop {
29962306a36Sopenharmony_ci	struct v4l2_rect	c;
30062306a36Sopenharmony_ci	struct v4l2_fract	left_subpix;
30162306a36Sopenharmony_ci	struct v4l2_fract	top_subpix;
30262306a36Sopenharmony_ci	struct v4l2_fract	width_subpix;
30362306a36Sopenharmony_ci	struct v4l2_fract	height_subpix;
30462306a36Sopenharmony_ci};
30562306a36Sopenharmony_ci
30662306a36Sopenharmony_cistruct mdp_frame {
30762306a36Sopenharmony_ci	struct v4l2_format	format;
30862306a36Sopenharmony_ci	const struct mdp_format	*mdp_fmt;
30962306a36Sopenharmony_ci	u32			ycbcr_prof;	/* enum mdp_ycbcr_profile */
31062306a36Sopenharmony_ci	u32			usage;		/* enum mdp_buffer_usage */
31162306a36Sopenharmony_ci	struct mdp_crop		crop;
31262306a36Sopenharmony_ci	struct v4l2_rect	compose;
31362306a36Sopenharmony_ci	s32			rotation;
31462306a36Sopenharmony_ci	u32			hflip:1;
31562306a36Sopenharmony_ci	u32			vflip:1;
31662306a36Sopenharmony_ci	u32			hdr:1;
31762306a36Sopenharmony_ci	u32			dre:1;
31862306a36Sopenharmony_ci	u32			sharpness:1;
31962306a36Sopenharmony_ci	u32			dither:1;
32062306a36Sopenharmony_ci};
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_cistatic inline bool mdp_target_is_crop(u32 target)
32362306a36Sopenharmony_ci{
32462306a36Sopenharmony_ci	return (target == V4L2_SEL_TGT_CROP) ||
32562306a36Sopenharmony_ci		(target == V4L2_SEL_TGT_CROP_DEFAULT) ||
32662306a36Sopenharmony_ci		(target == V4L2_SEL_TGT_CROP_BOUNDS);
32762306a36Sopenharmony_ci}
32862306a36Sopenharmony_ci
32962306a36Sopenharmony_cistatic inline bool mdp_target_is_compose(u32 target)
33062306a36Sopenharmony_ci{
33162306a36Sopenharmony_ci	return (target == V4L2_SEL_TGT_COMPOSE) ||
33262306a36Sopenharmony_ci		(target == V4L2_SEL_TGT_COMPOSE_DEFAULT) ||
33362306a36Sopenharmony_ci		(target == V4L2_SEL_TGT_COMPOSE_BOUNDS);
33462306a36Sopenharmony_ci}
33562306a36Sopenharmony_ci
33662306a36Sopenharmony_ci#define MDP_MAX_CAPTURES	IMG_MAX_HW_OUTPUTS
33762306a36Sopenharmony_ci
33862306a36Sopenharmony_ci#define MDP_VPU_INIT		BIT(0)
33962306a36Sopenharmony_ci#define MDP_M2M_CTX_ERROR	BIT(1)
34062306a36Sopenharmony_ci
34162306a36Sopenharmony_cistruct mdp_frameparam {
34262306a36Sopenharmony_ci	struct list_head	list;
34362306a36Sopenharmony_ci	struct mdp_m2m_ctx	*ctx;
34462306a36Sopenharmony_ci	atomic_t		state;
34562306a36Sopenharmony_ci	const struct mdp_limit	*limit;
34662306a36Sopenharmony_ci	u32			type;	/* enum mdp_stream_type */
34762306a36Sopenharmony_ci	u32			frame_no;
34862306a36Sopenharmony_ci	struct mdp_frame	output;
34962306a36Sopenharmony_ci	struct mdp_frame	captures[MDP_MAX_CAPTURES];
35062306a36Sopenharmony_ci	u32			num_captures;
35162306a36Sopenharmony_ci	enum v4l2_colorspace		colorspace;
35262306a36Sopenharmony_ci	enum v4l2_ycbcr_encoding	ycbcr_enc;
35362306a36Sopenharmony_ci	enum v4l2_xfer_func		xfer_func;
35462306a36Sopenharmony_ci	enum v4l2_quantization		quant;
35562306a36Sopenharmony_ci};
35662306a36Sopenharmony_ci
35762306a36Sopenharmony_cistruct mdp_dev;
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_ciint mdp_enum_fmt_mplane(struct mdp_dev *mdp, struct v4l2_fmtdesc *f);
36062306a36Sopenharmony_ciconst struct mdp_format *mdp_try_fmt_mplane(struct mdp_dev *mdp,
36162306a36Sopenharmony_ci					    struct v4l2_format *f,
36262306a36Sopenharmony_ci					    struct mdp_frameparam *param,
36362306a36Sopenharmony_ci					    u32 ctx_id);
36462306a36Sopenharmony_cienum mdp_ycbcr_profile mdp_map_ycbcr_prof_mplane(struct v4l2_format *f,
36562306a36Sopenharmony_ci						 u32 mdp_color);
36662306a36Sopenharmony_ciint mdp_try_crop(struct mdp_m2m_ctx *ctx, struct v4l2_rect *r,
36762306a36Sopenharmony_ci		 const struct v4l2_selection *s, struct mdp_frame *frame);
36862306a36Sopenharmony_ciint mdp_check_scaling_ratio(const struct v4l2_rect *crop,
36962306a36Sopenharmony_ci			    const struct v4l2_rect *compose, s32 rotation,
37062306a36Sopenharmony_ci	const struct mdp_limit *limit);
37162306a36Sopenharmony_civoid mdp_set_src_config(struct img_input *in,
37262306a36Sopenharmony_ci			struct mdp_frame *frame, struct vb2_buffer *vb);
37362306a36Sopenharmony_civoid mdp_set_dst_config(struct img_output *out,
37462306a36Sopenharmony_ci			struct mdp_frame *frame, struct vb2_buffer *vb);
37562306a36Sopenharmony_ciint mdp_frameparam_init(struct mdp_dev *mdp, struct mdp_frameparam *param);
37662306a36Sopenharmony_ci
37762306a36Sopenharmony_ci#endif  /* __MTK_MDP3_REGS_H__ */
378