xref: /rk3399_rockchip-uboot/drivers/video/drm/rockchip_post_csc.c (revision b12f8e1ca5bd364ce71bd1f17bcb536fb51e1152)
16027c871SZhang Yubing // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
26027c871SZhang Yubing /*
36027c871SZhang Yubing  * Copyright (c) 2022 Rockchip Electronics Co., Ltd.
46027c871SZhang Yubing  * Author: Zhang yubing <yubing.zhang@rock-chips.com>
56027c871SZhang Yubing  */
66027c871SZhang Yubing 
76027c871SZhang Yubing #include <stdio.h>
86027c871SZhang Yubing #include <linux/errno.h>
96027c871SZhang Yubing 
106027c871SZhang Yubing #include "rockchip_post_csc.h"
116027c871SZhang Yubing 
126027c871SZhang Yubing #define PQ_CSC_HUE_TABLE_NUM			256
136027c871SZhang Yubing #define PQ_CSC_MODE_COEF_COMMENT_LEN		32
146027c871SZhang Yubing #define PQ_CSC_SIMPLE_MAT_PARAM_FIX_BIT_WIDTH	10
156027c871SZhang Yubing #define PQ_CSC_SIMPLE_MAT_PARAM_FIX_NUM		(1 << PQ_CSC_SIMPLE_MAT_PARAM_FIX_BIT_WIDTH)
166027c871SZhang Yubing 
176027c871SZhang Yubing #define PQ_CALC_ENHANCE_BIT			6
186027c871SZhang Yubing /* csc convert coef fixed-point num bit width */
196027c871SZhang Yubing #define PQ_CSC_PARAM_FIX_BIT_WIDTH		10
206027c871SZhang Yubing /* csc convert coef half fixed-point num bit width */
216027c871SZhang Yubing #define PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH		(PQ_CSC_PARAM_FIX_BIT_WIDTH - 1)
226027c871SZhang Yubing /* csc convert coef fixed-point num */
236027c871SZhang Yubing #define PQ_CSC_PARAM_FIX_NUM			(1 << PQ_CSC_PARAM_FIX_BIT_WIDTH)
246027c871SZhang Yubing #define PQ_CSC_PARAM_HALF_FIX_NUM		(1 << PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH)
256027c871SZhang Yubing /* csc input param bit width */
266027c871SZhang Yubing #define PQ_CSC_IN_PARAM_NORM_BIT_WIDTH		9
276027c871SZhang Yubing /* csc input param normalization coef */
286027c871SZhang Yubing #define PQ_CSC_IN_PARAM_NORM_COEF		(1 << PQ_CSC_IN_PARAM_NORM_BIT_WIDTH)
296027c871SZhang Yubing 
306027c871SZhang Yubing /* csc hue table range [0,255] */
316027c871SZhang Yubing #define PQ_CSC_HUE_TABLE_DIV_COEF		2
326027c871SZhang Yubing /* csc brightness offset */
336027c871SZhang Yubing #define PQ_CSC_BRIGHTNESS_OFFSET		256
346027c871SZhang Yubing 
356027c871SZhang Yubing /* dc coef base bit width */
366027c871SZhang Yubing #define PQ_CSC_DC_COEF_BASE_BIT_WIDTH		10
376027c871SZhang Yubing /* input dc coef offset for 10bit data */
386027c871SZhang Yubing #define PQ_CSC_DC_IN_OFFSET			64
396027c871SZhang Yubing /* input and output dc coef offset for 10bit data u,v */
406027c871SZhang Yubing #define PQ_CSC_DC_IN_OUT_DEFAULT		512
416027c871SZhang Yubing /* r,g,b color temp div coef, range [-128,128] for 10bit data */
426027c871SZhang Yubing #define PQ_CSC_TEMP_OFFSET_DIV_COEF		2
436027c871SZhang Yubing 
446027c871SZhang Yubing #define	MAX(a, b)				((a) > (b) ? (a) : (b))
456027c871SZhang Yubing #define	MIN(a, b)				((a) < (b) ? (a) : (b))
466027c871SZhang Yubing #define	CLIP(x, min_v, max_v)			MIN(MAX(x, min_v), max_v)
476027c871SZhang Yubing 
486027c871SZhang Yubing enum rk_pq_csc_mode {
496027c871SZhang Yubing 	RK_PQ_CSC_YUV2RGB_601 = 0,             /* YCbCr_601 LIMIT-> RGB FULL */
506027c871SZhang Yubing 	RK_PQ_CSC_YUV2RGB_709,                 /* YCbCr_709 LIMIT-> RGB FULL */
516027c871SZhang Yubing 	RK_PQ_CSC_RGB2YUV_601,                 /* RGB FULL->YCbCr_601 LIMIT */
526027c871SZhang Yubing 	RK_PQ_CSC_RGB2YUV_709,                 /* RGB FULL->YCbCr_709 LIMIT */
536027c871SZhang Yubing 	RK_PQ_CSC_YUV2YUV_709_601,             /* YCbCr_709 LIMIT->YCbCr_601 LIMIT */
546027c871SZhang Yubing 	RK_PQ_CSC_YUV2YUV_601_709,             /* YCbCr_601 LIMIT->YCbCr_709 LIMIT */
556027c871SZhang Yubing 	RK_PQ_CSC_YUV2YUV,                     /* YCbCr LIMIT->YCbCr LIMIT */
566027c871SZhang Yubing 	RK_PQ_CSC_YUV2RGB_601_FULL,            /* YCbCr_601 FULL-> RGB FULL */
576027c871SZhang Yubing 	RK_PQ_CSC_YUV2RGB_709_FULL,            /* YCbCr_709 FULL-> RGB FULL */
586027c871SZhang Yubing 	RK_PQ_CSC_RGB2YUV_601_FULL,            /* RGB FULL->YCbCr_601 FULL */
596027c871SZhang Yubing 	RK_PQ_CSC_RGB2YUV_709_FULL,            /* RGB FULL->YCbCr_709 FULL */
606027c871SZhang Yubing 	RK_PQ_CSC_YUV2YUV_709_601_FULL,        /* YCbCr_709 FULL->YCbCr_601 FULL */
616027c871SZhang Yubing 	RK_PQ_CSC_YUV2YUV_601_709_FULL,        /* YCbCr_601 FULL->YCbCr_709 FULL */
626027c871SZhang Yubing 	RK_PQ_CSC_YUV2YUV_FULL,                /* YCbCr FULL->YCbCr FULL */
636027c871SZhang Yubing 	RK_PQ_CSC_YUV2YUV_LIMIT2FULL,          /* YCbCr  LIMIT->YCbCr  FULL */
646027c871SZhang Yubing 	RK_PQ_CSC_YUV2YUV_601_709_LIMIT2FULL,  /* YCbCr 601 LIMIT->YCbCr 709 FULL */
656027c871SZhang Yubing 	RK_PQ_CSC_YUV2YUV_709_601_LIMIT2FULL,  /* YCbCr 709 LIMIT->YCbCr 601 FULL */
666027c871SZhang Yubing 	RK_PQ_CSC_YUV2YUV_FULL2LIMIT,          /* YCbCr  FULL->YCbCr  LIMIT */
676027c871SZhang Yubing 	RK_PQ_CSC_YUV2YUV_601_709_FULL2LIMIT,  /* YCbCr 601 FULL->YCbCr 709 LIMIT */
686027c871SZhang Yubing 	RK_PQ_CSC_YUV2YUV_709_601_FULL2LIMIT,  /* YCbCr 709 FULL->YCbCr 601 LIMIT */
696027c871SZhang Yubing 	RK_PQ_CSC_YUV2RGBL_601,                /* YCbCr_601 LIMIT-> RGB LIMIT */
706027c871SZhang Yubing 	RK_PQ_CSC_YUV2RGBL_709,                /* YCbCr_709 LIMIT-> RGB LIMIT */
716027c871SZhang Yubing 	RK_PQ_CSC_RGBL2YUV_601,                /* RGB LIMIT->YCbCr_601 LIMIT */
726027c871SZhang Yubing 	RK_PQ_CSC_RGBL2YUV_709,                /* RGB LIMIT->YCbCr_709 LIMIT */
736027c871SZhang Yubing 	RK_PQ_CSC_YUV2RGBL_601_FULL,           /* YCbCr_601 FULL-> RGB LIMIT */
746027c871SZhang Yubing 	RK_PQ_CSC_YUV2RGBL_709_FULL,           /* YCbCr_709 FULL-> RGB LIMIT */
756027c871SZhang Yubing 	RK_PQ_CSC_RGBL2YUV_601_FULL,           /* RGB LIMIT->YCbCr_601 FULL */
766027c871SZhang Yubing 	RK_PQ_CSC_RGBL2YUV_709_FULL,           /* RGB LIMIT->YCbCr_709 FULL */
776027c871SZhang Yubing 	RK_PQ_CSC_RGB2RGBL,                    /* RGB FULL->RGB LIMIT */
786027c871SZhang Yubing 	RK_PQ_CSC_RGBL2RGB,                    /* RGB LIMIT->RGB FULL */
796027c871SZhang Yubing 	RK_PQ_CSC_RGBL2RGBL,                   /* RGB LIMIT->RGB LIMIT */
806027c871SZhang Yubing 	RK_PQ_CSC_RGB2RGB,                     /* RGB FULL->RGB FULL */
816027c871SZhang Yubing 	RK_PQ_CSC_YUV2RGB_2020,                /* YUV 2020 FULL->RGB  2020 FULL */
826027c871SZhang Yubing 	RK_PQ_CSC_RGB2YUV2020_LIMIT2FULL,      /* BT2020RGBLIMIT -> BT2020YUVFULL */
836027c871SZhang Yubing 	RK_PQ_CSC_RGB2YUV2020_LIMIT,           /* BT2020RGBLIMIT -> BT2020YUVLIMIT */
846027c871SZhang Yubing 	RK_PQ_CSC_RGB2YUV2020_FULL2LIMIT,      /* BT2020RGBFULL -> BT2020YUVLIMIT */
856027c871SZhang Yubing 	RK_PQ_CSC_RGB2YUV2020_FULL,            /* BT2020RGBFULL -> BT2020YUVFULL */
866027c871SZhang Yubing };
876027c871SZhang Yubing 
886027c871SZhang Yubing enum color_space_type {
896027c871SZhang Yubing 	OPTM_CS_E_UNKNOWN = 0,
906027c871SZhang Yubing 	OPTM_CS_E_ITU_R_BT_709 = 1,
916027c871SZhang Yubing 	OPTM_CS_E_FCC = 4,
926027c871SZhang Yubing 	OPTM_CS_E_ITU_R_BT_470_2_BG = 5,
936027c871SZhang Yubing 	OPTM_CS_E_SMPTE_170_M = 6,
946027c871SZhang Yubing 	OPTM_CS_E_SMPTE_240_M = 7,
956027c871SZhang Yubing 	OPTM_CS_E_XV_YCC_709 = OPTM_CS_E_ITU_R_BT_709,
966027c871SZhang Yubing 	OPTM_CS_E_XV_YCC_601 = 8,
976027c871SZhang Yubing 	OPTM_CS_E_RGB = 9,
986027c871SZhang Yubing 	OPTM_CS_E_XV_YCC_2020 = 10,
996027c871SZhang Yubing 	OPTM_CS_E_RGB_2020 = 11,
1006027c871SZhang Yubing };
1016027c871SZhang Yubing 
1026027c871SZhang Yubing enum vop_csc_format {
1036027c871SZhang Yubing 	CSC_BT601L,
1046027c871SZhang Yubing 	CSC_BT709L,
1056027c871SZhang Yubing 	CSC_BT601F,
1066027c871SZhang Yubing 	CSC_BT2020,
1076027c871SZhang Yubing 	CSC_BT709L_13BIT,
1086027c871SZhang Yubing 	CSC_BT709F_13BIT,
1096027c871SZhang Yubing 	CSC_BT2020L_13BIT,
1106027c871SZhang Yubing 	CSC_BT2020F_13BIT,
1116027c871SZhang Yubing };
1126027c871SZhang Yubing 
1136027c871SZhang Yubing struct rk_pq_csc_coef {
1146027c871SZhang Yubing 	s32 csc_coef00;
1156027c871SZhang Yubing 	s32 csc_coef01;
1166027c871SZhang Yubing 	s32 csc_coef02;
1176027c871SZhang Yubing 	s32 csc_coef10;
1186027c871SZhang Yubing 	s32 csc_coef11;
1196027c871SZhang Yubing 	s32 csc_coef12;
1206027c871SZhang Yubing 	s32 csc_coef20;
1216027c871SZhang Yubing 	s32 csc_coef21;
1226027c871SZhang Yubing 	s32 csc_coef22;
1236027c871SZhang Yubing };
1246027c871SZhang Yubing 
1256027c871SZhang Yubing struct rk_pq_csc_ventor {
1266027c871SZhang Yubing 	s32 csc_offset0;
1276027c871SZhang Yubing 	s32 csc_offset1;
1286027c871SZhang Yubing 	s32 csc_offset2;
1296027c871SZhang Yubing };
1306027c871SZhang Yubing 
1316027c871SZhang Yubing struct rk_pq_csc_dc_coef {
1326027c871SZhang Yubing 	s32 csc_in_dc0;
1336027c871SZhang Yubing 	s32 csc_in_dc1;
1346027c871SZhang Yubing 	s32 csc_in_dc2;
1356027c871SZhang Yubing 	s32 csc_out_dc0;
1366027c871SZhang Yubing 	s32 csc_out_dc1;
1376027c871SZhang Yubing 	s32 csc_out_dc2;
1386027c871SZhang Yubing };
1396027c871SZhang Yubing 
1406027c871SZhang Yubing /* color space param */
1416027c871SZhang Yubing struct rk_csc_colorspace_info {
1426027c871SZhang Yubing 	enum color_space_type input_color_space;
1436027c871SZhang Yubing 	enum color_space_type output_color_space;
1446027c871SZhang Yubing 	bool in_full_range;
1456027c871SZhang Yubing 	bool out_full_range;
1466027c871SZhang Yubing };
1476027c871SZhang Yubing 
1486027c871SZhang Yubing struct rk_csc_mode_coef {
1496027c871SZhang Yubing 	enum rk_pq_csc_mode csc_mode;
1506027c871SZhang Yubing 	char c_csc_comment[PQ_CSC_MODE_COEF_COMMENT_LEN];
1516027c871SZhang Yubing 	const struct rk_pq_csc_coef *pst_csc_coef;
1526027c871SZhang Yubing 	const struct rk_pq_csc_dc_coef *pst_csc_dc_coef;
1536027c871SZhang Yubing 	struct rk_csc_colorspace_info st_csc_color_info;
1546027c871SZhang Yubing };
1556027c871SZhang Yubing 
1566027c871SZhang Yubing /*
1576027c871SZhang Yubing  *CSC matrix
1586027c871SZhang Yubing  */
1596027c871SZhang Yubing /* xv_ycc BT.601 limit(i.e. SD) -> RGB full */
1606027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_xv_yccsdy_cb_cr_limit_to_rgb_full = {
1616027c871SZhang Yubing 	1196, 0, 1639,
1626027c871SZhang Yubing 	1196, -402, -835,
1636027c871SZhang Yubing 	1196, 2072, 0
1646027c871SZhang Yubing };
1656027c871SZhang Yubing 
1666027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_xv_yccsdy_cb_cr_limit_to_rgb_full = {
1676027c871SZhang Yubing 	-64, -512, -512,
1686027c871SZhang Yubing 	0, 0, 0
1696027c871SZhang Yubing };
1706027c871SZhang Yubing 
1716027c871SZhang Yubing /* BT.709 limit(i.e. HD) -> RGB full */
1726027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_hdy_cb_cr_limit_to_rgb_full = {
1736027c871SZhang Yubing 	1196, 0, 1841,
1746027c871SZhang Yubing 	1196, -219, -547,
1756027c871SZhang Yubing 	1196, 2169, 0
1766027c871SZhang Yubing };
1776027c871SZhang Yubing 
1786027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_hdy_cb_cr_limit_to_rgb_full = {
1796027c871SZhang Yubing 	-64, -512, -512,
1806027c871SZhang Yubing 	0, 0, 0
1816027c871SZhang Yubing };
1826027c871SZhang Yubing 
1836027c871SZhang Yubing /* RGB full-> YUV601 (i.e. SD) limit */
1846027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_rgb_to_xv_yccsdy_cb_cr = {
1856027c871SZhang Yubing 	262, 515, 100,
1866027c871SZhang Yubing 	-151, -297, 448,
1876027c871SZhang Yubing 	448, -376, -73
1886027c871SZhang Yubing };
1896027c871SZhang Yubing 
1906027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_rgb_to_xv_yccsdy_cb_cr = {
1916027c871SZhang Yubing 	0, 0, 0,
1926027c871SZhang Yubing 	64, 512, 512
1936027c871SZhang Yubing };
1946027c871SZhang Yubing 
1956027c871SZhang Yubing /* RGB full-> YUV709 (i.e. SD) limit */
1966027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_rgb_to_hdy_cb_cr = {
1976027c871SZhang Yubing 	186, 627, 63,
1986027c871SZhang Yubing 	-103, -346, 448,
1996027c871SZhang Yubing 	448, -407, -41
2006027c871SZhang Yubing };
2016027c871SZhang Yubing 
2026027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_rgb_to_hdy_cb_cr = {
2036027c871SZhang Yubing 	0, 0, 0,
2046027c871SZhang Yubing 	64, 512, 512
2056027c871SZhang Yubing };
2066027c871SZhang Yubing 
2076027c871SZhang Yubing /* BT.709 (i.e. HD) -> to xv_ycc BT.601 (i.e. SD) */
2086027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_hdy_cb_cr_to_xv_yccsdy_cb_cr = {
2096027c871SZhang Yubing 	1024, 104, 201,
2106027c871SZhang Yubing 	0, 1014, -113,
2116027c871SZhang Yubing 	0, -74, 1007
2126027c871SZhang Yubing };
2136027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_hdy_cb_cr_to_xv_yccsdy_cb_cr = {
2146027c871SZhang Yubing 	-64, -512, -512,
2156027c871SZhang Yubing 	64, 512, 512
2166027c871SZhang Yubing };
2176027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_hdy_cb_cr_full_to_xv_yccsdy_cb_cr_full = {
2186027c871SZhang Yubing 	0, -512, -512,
2196027c871SZhang Yubing 	0, 512, 512
2206027c871SZhang Yubing };
2216027c871SZhang Yubing 
2226027c871SZhang Yubing /* xv_ycc BT.601 (i.e. SD) -> to BT.709 (i.e. HD) */
2236027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_xv_yccsdy_cb_cr_to_hdy_cb_cr = {
2248b59e34dSZhang Yubing 	1024, -118, -213,
2258b59e34dSZhang Yubing 	0, 1043, 117,
2268b59e34dSZhang Yubing 	0, 77, 1050
2278b59e34dSZhang Yubing };
2288b59e34dSZhang Yubing 
2298b59e34dSZhang Yubing /* xv_ycc BT.601 full(i.e. SD) -> to BT.709 full(i.e. HD) */
2308b59e34dSZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_xv_yccsdy_cb_cr_full_to_hdy_cb_cr_full = {
2316027c871SZhang Yubing 	1024, -121, -218,
2326027c871SZhang Yubing 	0, 1043, 117,
2336027c871SZhang Yubing 	0, 77, 1050
2346027c871SZhang Yubing };
2356027c871SZhang Yubing 
2366027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_xv_yccsdy_cb_cr_to_hdy_cb_cr = {
2376027c871SZhang Yubing 	-64, -512, -512,
2386027c871SZhang Yubing 	64, 512, 512
2396027c871SZhang Yubing };
2406027c871SZhang Yubing 
2416027c871SZhang Yubing /* xv_ycc BT.601 full(i.e. SD) -> RGB full */
2426027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_xv_yccsdy_cb_cr_to_rgb_full = {
2436027c871SZhang Yubing 	1024, 0, 1436,
2446027c871SZhang Yubing 	1024, -352, -731,
2456027c871SZhang Yubing 	1024, 1815, 0
2466027c871SZhang Yubing };
2476027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_xv_yccsdy_cb_cr_to_rgb_full = {
2486027c871SZhang Yubing 	0, -512, -512,
2496027c871SZhang Yubing 	0, 0, 0
2506027c871SZhang Yubing };
2516027c871SZhang Yubing 
2526027c871SZhang Yubing /* BT.709 full(i.e. HD) -> RGB full */
2536027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_hdy_cb_cr_to_rgb_full = {
2546027c871SZhang Yubing 	1024, 0, 1613,
2556027c871SZhang Yubing 	1024, -192, -479,
2566027c871SZhang Yubing 	1024, 1900, 0
2576027c871SZhang Yubing };
2586027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_hdy_cb_cr_to_rgb_full = {
2596027c871SZhang Yubing 	0, -512, -512,
2606027c871SZhang Yubing 	0, 0, 0
2616027c871SZhang Yubing };
2626027c871SZhang Yubing 
2636027c871SZhang Yubing /* RGB full-> YUV601 full(i.e. SD) */
2646027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_rgb_to_xv_yccsdy_cb_cr_full = {
2656027c871SZhang Yubing 	306, 601, 117,
2666027c871SZhang Yubing 	-173, -339, 512,
2676027c871SZhang Yubing 	512, -429, -83
2686027c871SZhang Yubing };
2696027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_rgb_to_xv_yccsdy_cb_cr_full = {
2706027c871SZhang Yubing 	0, 0, 0,
2716027c871SZhang Yubing 	0, 512, 512
2726027c871SZhang Yubing };
2736027c871SZhang Yubing 
2746027c871SZhang Yubing /* RGB full-> YUV709 full (i.e. SD) */
2756027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_rgb_to_hdy_cb_cr_full = {
2766027c871SZhang Yubing 	218, 732, 74,
2776027c871SZhang Yubing 	-117, -395, 512,
2786027c871SZhang Yubing 	512, -465, -47
2796027c871SZhang Yubing };
2806027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_rgb_to_hdy_cb_cr_full = {
2816027c871SZhang Yubing 	0, 0, 0,
2826027c871SZhang Yubing 	0, 512, 512
2836027c871SZhang Yubing };
2846027c871SZhang Yubing 
2856027c871SZhang Yubing /* limit -> full */
2866027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_y_cb_cr_limit_to_y_cb_cr_full = {
2876027c871SZhang Yubing 	1196, 0, 0,
2886027c871SZhang Yubing 	0, 1169, 0,
2896027c871SZhang Yubing 	0, 0, 1169
2906027c871SZhang Yubing };
2916027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_identity_y_cb_cr_limit_to_y_cb_cr_full = {
2926027c871SZhang Yubing 	-64, -512, -512,
2936027c871SZhang Yubing 	0, 512, 512
2946027c871SZhang Yubing };
2956027c871SZhang Yubing 
2966027c871SZhang Yubing /* 601 limit -> 709 full */
2976027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_601_limit_to_709_full = {
2986027c871SZhang Yubing 	1196, -138, -249,
2996027c871SZhang Yubing 	0, 1191, 134,
3006027c871SZhang Yubing 	0, 88, 1199
3016027c871SZhang Yubing };
3026027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_identity_601_limit_to_709_full = {
3036027c871SZhang Yubing 	-64, -512, -512,
3046027c871SZhang Yubing 	0, 512, 512
3056027c871SZhang Yubing };
3066027c871SZhang Yubing 
3076027c871SZhang Yubing /* 709 limit -> 601 full */
3086027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_709_limit_to_601_full = {
3096027c871SZhang Yubing 	1196, 119, 229,
3106027c871SZhang Yubing 	0, 1157, -129,
3116027c871SZhang Yubing 	0, -85, 1150
3126027c871SZhang Yubing };
3136027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_identity_709_limit_to_601_full = {
3146027c871SZhang Yubing 	-64, -512, -512,
3156027c871SZhang Yubing 	0, 512, 512
3166027c871SZhang Yubing };
3176027c871SZhang Yubing 
3186027c871SZhang Yubing /* full ->   limit */
3196027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_y_cb_cr_full_to_y_cb_cr_limit = {
3206027c871SZhang Yubing 	877, 0, 0,
3216027c871SZhang Yubing 	0, 897, 0,
3226027c871SZhang Yubing 	0, 0, 897
3236027c871SZhang Yubing };
3246027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_identity_y_cb_cr_full_to_y_cb_cr_limit = {
3256027c871SZhang Yubing 	0, -512, -512,
3266027c871SZhang Yubing 	64, 512, 512
3276027c871SZhang Yubing };
3286027c871SZhang Yubing 
3296027c871SZhang Yubing /* 601 full ->  709 limit */
3306027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_y_cb_cr_601_full_to_y_cb_cr_709_limit = {
3316027c871SZhang Yubing 	877, -106, -191,
3326027c871SZhang Yubing 	0, 914, 103,
3336027c871SZhang Yubing 	0, 67, 920
3346027c871SZhang Yubing };
3356027c871SZhang Yubing static const struct rk_pq_csc_dc_coef
3366027c871SZhang Yubing rk_dc_csc_table_identity_y_cb_cr_601_full_to_y_cb_cr_709_limit = {
3376027c871SZhang Yubing 	0, -512, -512,
3386027c871SZhang Yubing 	64, 512, 512
3396027c871SZhang Yubing };
3406027c871SZhang Yubing 
3416027c871SZhang Yubing /* 709 full ->  601 limit */
3426027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_y_cb_cr_709_full_to_y_cb_cr_601_limit = {
3436027c871SZhang Yubing 	877, 91, 176,
3446027c871SZhang Yubing 	0, 888, -99,
3456027c871SZhang Yubing 	0, -65, 882
3466027c871SZhang Yubing };
3476027c871SZhang Yubing static const struct rk_pq_csc_dc_coef
3486027c871SZhang Yubing rk_dc_csc_table_identity_y_cb_cr_709_full_to_y_cb_cr_601_limit = {
3496027c871SZhang Yubing 	0, -512, -512,
3506027c871SZhang Yubing 	64, 512, 512
3516027c871SZhang Yubing };
3526027c871SZhang Yubing 
3536027c871SZhang Yubing /* xv_ycc BT.601 limit(i.e. SD) -> RGB limit */
3546027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_xv_yccsdy_cb_cr_limit_to_rgb_limit = {
3556027c871SZhang Yubing 	1024, 0, 1404,
3566027c871SZhang Yubing 	1024, -344, -715,
3576027c871SZhang Yubing 	1024, 1774, 0
3586027c871SZhang Yubing };
3596027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_xv_yccsdy_cb_cr_limit_to_rgb_limit = {
3606027c871SZhang Yubing 	-64, -512, -512,
3616027c871SZhang Yubing 	64, 64, 64
3626027c871SZhang Yubing };
3636027c871SZhang Yubing 
3646027c871SZhang Yubing /* BT.709 limit(i.e. HD) -> RGB limit */
3656027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_hdy_cb_cr_limit_to_rgb_limit = {
3666027c871SZhang Yubing 	1024, 0, 1577,
3676027c871SZhang Yubing 	1024, -188, -469,
3686027c871SZhang Yubing 	1024, 1858, 0
3696027c871SZhang Yubing };
3706027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_hdy_cb_cr_limit_to_rgb_limit = {
3716027c871SZhang Yubing 	-64, -512, -512,
3726027c871SZhang Yubing 	64, 64, 64
3736027c871SZhang Yubing };
3746027c871SZhang Yubing 
3756027c871SZhang Yubing /* RGB limit-> YUV601 (i.e. SD) limit */
3766027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_rgb_limit_to_xv_yccsdy_cb_cr = {
3776027c871SZhang Yubing 	306, 601, 117,
3786027c871SZhang Yubing 	-177, -347, 524,
3796027c871SZhang Yubing 	524, -439, -85
3806027c871SZhang Yubing };
3816027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_rgb_limit_to_xv_yccsdy_cb_cr = {
3826027c871SZhang Yubing 	-64, -64, -64,
3836027c871SZhang Yubing 	64, 512, 512
3846027c871SZhang Yubing };
3856027c871SZhang Yubing 
3866027c871SZhang Yubing /* RGB limit -> YUV709 (i.e. SD) limit */
3876027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_rgb_limit_to_hdy_cb_cr = {
3886027c871SZhang Yubing 	218, 732, 74,
3896027c871SZhang Yubing 	-120, -404, 524,
3906027c871SZhang Yubing 	524, -476, -48
3916027c871SZhang Yubing };
3926027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_rgb_limit_to_hdy_cb_cr = {
3936027c871SZhang Yubing 	-64, -64, -64,
3946027c871SZhang Yubing 	64, 512, 512
3956027c871SZhang Yubing };
3966027c871SZhang Yubing 
3976027c871SZhang Yubing /* xv_ycc BT.601 full(i.e. SD) -> RGB limit */
3986027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_xv_yccsdy_cb_cr_to_rgb_limit = {
3996027c871SZhang Yubing 	877, 0, 1229,
4006027c871SZhang Yubing 	877, -302, -626,
4016027c871SZhang Yubing 	877, 1554, 0
4026027c871SZhang Yubing };
4036027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_xv_yccsdy_cb_cr_to_rgb_limit = {
4046027c871SZhang Yubing 	0, -512, -512,
4056027c871SZhang Yubing 	64, 64, 64
4066027c871SZhang Yubing };
4076027c871SZhang Yubing 
4086027c871SZhang Yubing /* BT.709 full(i.e. HD) -> RGB limit */
4096027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_hdy_cb_cr_to_rgb_limit = {
4106027c871SZhang Yubing 	877, 0, 1381,
4116027c871SZhang Yubing 	877, -164, -410,
4126027c871SZhang Yubing 	877, 1627, 0
4136027c871SZhang Yubing };
4146027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_hdy_cb_cr_to_rgb_limit = {
4156027c871SZhang Yubing 	0, -512, -512,
4166027c871SZhang Yubing 	64, 64, 64
4176027c871SZhang Yubing };
4186027c871SZhang Yubing 
4196027c871SZhang Yubing /* RGB limit-> YUV601 full(i.e. SD) */
4206027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_rgb_limit_to_xv_yccsdy_cb_cr_full = {
4216027c871SZhang Yubing 	358, 702, 136,
4226027c871SZhang Yubing 	-202, -396, 598,
4236027c871SZhang Yubing 	598, -501, -97
4246027c871SZhang Yubing };
4256027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_rgb_limit_to_xv_yccsdy_cb_cr_full = {
4266027c871SZhang Yubing 	-64, -64, -64,
4276027c871SZhang Yubing 	0, 512, 512
4286027c871SZhang Yubing };
4296027c871SZhang Yubing 
4306027c871SZhang Yubing /* RGB limit-> YUV709 full (i.e. SD) */
4316027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_rgb_limit_to_hdy_cb_cr_full = {
4326027c871SZhang Yubing 	254, 855, 86,
4336027c871SZhang Yubing 	-137, -461, 598,
4346027c871SZhang Yubing 	598, -543, -55
4356027c871SZhang Yubing };
4366027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_rgb_limit_to_hdy_cb_cr_full = {
4376027c871SZhang Yubing 	-64, -64, -64,
4386027c871SZhang Yubing 	0, 512, 512
4396027c871SZhang Yubing };
4406027c871SZhang Yubing 
4416027c871SZhang Yubing /* RGB full -> RGB limit */
4426027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_rgb_to_rgb_limit = {
4436027c871SZhang Yubing 	877, 0, 0,
4446027c871SZhang Yubing 	0, 877, 0,
4456027c871SZhang Yubing 	0, 0, 877
4466027c871SZhang Yubing };
4476027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_identity_rgb_to_rgb_limit = {
4486027c871SZhang Yubing 	0, 0, 0,
4496027c871SZhang Yubing 	64, 64, 64
4506027c871SZhang Yubing };
4516027c871SZhang Yubing 
4526027c871SZhang Yubing /* RGB limit -> RGB full */
4536027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_rgb_limit_to_rgb = {
4546027c871SZhang Yubing 	1196, 0, 0,
4556027c871SZhang Yubing 	0, 1196, 0,
4566027c871SZhang Yubing 	0, 0, 1196
4576027c871SZhang Yubing };
4586027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_identity_rgb_limit_to_rgb = {
4596027c871SZhang Yubing 	-64, -64, -64,
4606027c871SZhang Yubing 	0, 0, 0
4616027c871SZhang Yubing };
4626027c871SZhang Yubing 
4636027c871SZhang Yubing /* RGB limit/full -> RGB limit/full */
4646027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_rgb_to_rgb = {
4656027c871SZhang Yubing 	1024, 0, 0,
4666027c871SZhang Yubing 	0, 1024, 0,
4676027c871SZhang Yubing 	0, 0, 1024
4686027c871SZhang Yubing };
4696027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_identity_rgb_to_rgb1 = {
4706027c871SZhang Yubing 	-64, -64, -64,
4716027c871SZhang Yubing 	64, 64, 64
4726027c871SZhang Yubing };
4736027c871SZhang Yubing 
4746027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_identity_rgb_to_rgb2 = {
4756027c871SZhang Yubing 	0, 0, 0,
4766027c871SZhang Yubing 	0, 0, 0
4776027c871SZhang Yubing };
4786027c871SZhang Yubing 
4796027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_yuv_to_rgb_2020 = {
4806027c871SZhang Yubing 	1024, 0, 1510,
4816027c871SZhang Yubing 	1024, -169, -585,
4826027c871SZhang Yubing 	1024, 1927, 0
4836027c871SZhang Yubing };
4846027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_identity_yuv_to_rgb_2020 = {
4856027c871SZhang Yubing 	0, -512, -512,
4866027c871SZhang Yubing 	0, 0, 0
4876027c871SZhang Yubing };
4886027c871SZhang Yubing 
4896027c871SZhang Yubing /* 2020 RGB LIMIT ->YUV LIMIT */
4906027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_rgb_limit_to_yuv_limit_2020 = {
4916027c871SZhang Yubing 	269, 694, 61,
4926027c871SZhang Yubing 	-146, -377, 524,
4936027c871SZhang Yubing 	524, -482, -42
4946027c871SZhang Yubing };
4956027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_identity_rgb_limit_to_yuv_limit_2020 = {
4966027c871SZhang Yubing 	-64, -64, -64,
4976027c871SZhang Yubing 	64, 512, 512
4986027c871SZhang Yubing };
4996027c871SZhang Yubing 
5006027c871SZhang Yubing /* 2020 RGB LIMIT ->YUV FULL */
5016027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_rgb_limit_to_yuv_full_2020 = {
5026027c871SZhang Yubing 	314, 811, 71,
5036027c871SZhang Yubing 	-167, -431, 598,
5046027c871SZhang Yubing 	598, -550, -48
5056027c871SZhang Yubing };
5066027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_identity_rgb_limit_to_yuv_full_2020 = {
5076027c871SZhang Yubing 	-64, -64, -64,
5086027c871SZhang Yubing 	0, 512, 512
5096027c871SZhang Yubing };
5106027c871SZhang Yubing 
5116027c871SZhang Yubing /* 2020 RGB FULL ->YUV LIMIT */
5126027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_rgb_full_to_yuv_limit_2020 = {
5136027c871SZhang Yubing 	230, 595, 52,
5146027c871SZhang Yubing 	-125, -323, 448,
5156027c871SZhang Yubing 	448, -412, -36
5166027c871SZhang Yubing };
5176027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_identity_rgb_full_to_yuv_limit_2020 = {
5186027c871SZhang Yubing 	0, 0, 0,
5196027c871SZhang Yubing 	64, 512, 512
5206027c871SZhang Yubing };
5216027c871SZhang Yubing 
5226027c871SZhang Yubing /* 2020 RGB FULL ->YUV FULL */
5236027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_rgb_full_to_yuv_full_2020 = {
5246027c871SZhang Yubing 	269, 694, 61,
5256027c871SZhang Yubing 	-143, -369, 512,
5266027c871SZhang Yubing 	512, -471, -41
5276027c871SZhang Yubing };
5286027c871SZhang Yubing static const struct rk_pq_csc_dc_coef rk_dc_csc_table_identity_rgb_full_to_yuv_full_2020 = {
5296027c871SZhang Yubing 	0, 0, 0,
5306027c871SZhang Yubing 	0, 512, 512
5316027c871SZhang Yubing };
5326027c871SZhang Yubing 
5336027c871SZhang Yubing /* identity matrix */
5346027c871SZhang Yubing static const struct rk_pq_csc_coef rk_csc_table_identity_y_cb_cr_to_y_cb_cr = {
5356027c871SZhang Yubing 	1024, 0, 0,
5366027c871SZhang Yubing 	0, 1024, 0,
5376027c871SZhang Yubing 	0, 0, 1024
5386027c871SZhang Yubing };
5396027c871SZhang Yubing 
5406027c871SZhang Yubing /* 10bit Hue Sin Look Up Table -> range[-30, 30] */
5416027c871SZhang Yubing static const s32 g_hue_sin_table[PQ_CSC_HUE_TABLE_NUM] = {
5426027c871SZhang Yubing 	512, 508, 505, 501, 497, 494, 490, 486,
5436027c871SZhang Yubing 	483, 479, 475, 472, 468, 464, 460, 457,
5446027c871SZhang Yubing 	453, 449, 445, 442, 438, 434, 430, 426,
5456027c871SZhang Yubing 	423, 419, 415, 411, 407, 403, 400, 396,
5466027c871SZhang Yubing 	392, 388, 384, 380, 376, 372, 369, 365,
5476027c871SZhang Yubing 	361, 357, 353, 349, 345, 341, 337, 333,
5486027c871SZhang Yubing 	329, 325, 321, 317, 313, 309, 305, 301,
5496027c871SZhang Yubing 	297, 293, 289, 285, 281, 277, 273, 269,
5506027c871SZhang Yubing 	265, 261, 257, 253, 249, 245, 241, 237,
5516027c871SZhang Yubing 	233, 228, 224, 220, 216, 212, 208, 204,
5526027c871SZhang Yubing 	200, 196, 192, 187, 183, 179, 175, 171,
5536027c871SZhang Yubing 	167, 163, 159, 154, 150, 146, 142, 138,
5546027c871SZhang Yubing 	134, 130, 125, 121, 117, 113, 109, 105,
5556027c871SZhang Yubing 	100, 96, 92, 88, 84, 80, 75, 71,
5566027c871SZhang Yubing 	67, 63, 59, 54, 50, 46, 42, 38,
5576027c871SZhang Yubing 	34, 29, 25, 21, 17, 13, 8, 4,
5586027c871SZhang Yubing 	0, -4, -8, -13, -17, -21, -25, -29,
5596027c871SZhang Yubing 	-34, -38, -42, -46, -50, -54, -59, -63,
5606027c871SZhang Yubing 	-67, -71, -75, -80, -84, -88, -92, -96,
5616027c871SZhang Yubing 	-100, -105, -109, -113, -117, -121, -125, -130,
5626027c871SZhang Yubing 	-134, -138, -142, -146, -150, -154, -159, -163,
5636027c871SZhang Yubing 	-167, -171, -175, -179, -183, -187, -192, -196,
5646027c871SZhang Yubing 	-200, -204, -208, -212, -216, -220, -224, -228,
5656027c871SZhang Yubing 	-233, -237, -241, -245, -249, -253, -257, -261,
5666027c871SZhang Yubing 	-265, -269, -273, -277, -281, -285, -289, -293,
5676027c871SZhang Yubing 	-297, -301, -305, -309, -313, -317, -321, -325,
5686027c871SZhang Yubing 	-329, -333, -337, -341, -345, -349, -353, -357,
5696027c871SZhang Yubing 	-361, -365, -369, -372, -376, -380, -384, -388,
5706027c871SZhang Yubing 	-392, -396, -400, -403, -407, -411, -415, -419,
5716027c871SZhang Yubing 	-423, -426, -430, -434, -438, -442, -445, -449,
5726027c871SZhang Yubing 	-453, -457, -460, -464, -468, -472, -475, -479,
5736027c871SZhang Yubing 	-483, -486, -490, -494, -497, -501, -505, -508,
5746027c871SZhang Yubing };
5756027c871SZhang Yubing 
5766027c871SZhang Yubing /* 10bit Hue Cos Look Up Table  -> range[-30, 30] */
5776027c871SZhang Yubing static const s32 g_hue_cos_table[PQ_CSC_HUE_TABLE_NUM] = {
5786027c871SZhang Yubing 	887, 889, 891, 893, 895, 897, 899, 901,
5796027c871SZhang Yubing 	903, 905, 907, 909, 911, 913, 915, 917,
5806027c871SZhang Yubing 	919, 920, 922, 924, 926, 928, 929, 931,
5816027c871SZhang Yubing 	933, 935, 936, 938, 940, 941, 943, 945,
5826027c871SZhang Yubing 	946, 948, 949, 951, 953, 954, 956, 957,
5836027c871SZhang Yubing 	959, 960, 962, 963, 964, 966, 967, 969,
5846027c871SZhang Yubing 	970, 971, 973, 974, 975, 976, 978, 979,
5856027c871SZhang Yubing 	980, 981, 983, 984, 985, 986, 987, 988,
5866027c871SZhang Yubing 	989, 990, 992, 993, 994, 995, 996, 997,
5876027c871SZhang Yubing 	998, 998, 999, 1000, 1001, 1002, 1003, 1004,
5886027c871SZhang Yubing 	1005, 1005, 1006, 1007, 1008, 1008, 1009, 1010,
5896027c871SZhang Yubing 	1011, 1011, 1012, 1013, 1013, 1014, 1014, 1015,
5906027c871SZhang Yubing 	1015, 1016, 1016, 1017, 1017, 1018, 1018, 1019,
5916027c871SZhang Yubing 	1019, 1020, 1020, 1020, 1021, 1021, 1021, 1022,
5926027c871SZhang Yubing 	1022, 1022, 1022, 1023, 1023, 1023, 1023, 1023,
5936027c871SZhang Yubing 	1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
5946027c871SZhang Yubing 	1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
5956027c871SZhang Yubing 	1023, 1023, 1023, 1023, 1023, 1022, 1022, 1022,
5966027c871SZhang Yubing 	1022, 1021, 1021, 1021, 1020, 1020, 1020, 1019,
5976027c871SZhang Yubing 	1019, 1018, 1018, 1017, 1017, 1016, 1016, 1015,
5986027c871SZhang Yubing 	1015, 1014, 1014, 1013, 1013, 1012, 1011, 1011,
5996027c871SZhang Yubing 	1010, 1009, 1008, 1008, 1007, 1006, 1005, 1005,
6006027c871SZhang Yubing 	1004, 1003, 1002, 1001, 1000, 999, 998, 998,
6016027c871SZhang Yubing 	997, 996, 995, 994, 993, 992, 990, 989,
6026027c871SZhang Yubing 	988, 987, 986, 985, 984, 983, 981, 980,
6036027c871SZhang Yubing 	979, 978, 976, 975, 974, 973, 971, 970,
6046027c871SZhang Yubing 	969, 967, 966, 964, 963, 962, 960, 959,
6056027c871SZhang Yubing 	957, 956, 954, 953, 951, 949, 948, 946,
6066027c871SZhang Yubing 	945, 943, 941, 940, 938, 936, 935, 933,
6076027c871SZhang Yubing 	931, 929, 928, 926, 924, 922, 920, 919,
6086027c871SZhang Yubing 	917, 915, 913, 911, 909, 907, 905, 903,
6096027c871SZhang Yubing 	901, 899, 897, 895, 893, 891, 889, 887
6106027c871SZhang Yubing };
6116027c871SZhang Yubing 
6126027c871SZhang Yubing /*
6136027c871SZhang Yubing  *CSC Param Struct
6146027c871SZhang Yubing  */
6156027c871SZhang Yubing static const struct rk_csc_mode_coef g_mode_csc_coef[] = {
6166027c871SZhang Yubing 	{
6176027c871SZhang Yubing 		RK_PQ_CSC_YUV2RGB_601, "YUV601 L->RGB F",
6186027c871SZhang Yubing 		&rk_csc_table_xv_yccsdy_cb_cr_limit_to_rgb_full,
6196027c871SZhang Yubing 		&rk_dc_csc_table_xv_yccsdy_cb_cr_limit_to_rgb_full,
6206027c871SZhang Yubing 		{
6216027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_601, OPTM_CS_E_RGB, false, true
6226027c871SZhang Yubing 		}
6236027c871SZhang Yubing 	},
6246027c871SZhang Yubing 	{
6256027c871SZhang Yubing 		RK_PQ_CSC_YUV2RGB_709, "YUV709 L->RGB F",
6266027c871SZhang Yubing 		&rk_csc_table_hdy_cb_cr_limit_to_rgb_full,
6276027c871SZhang Yubing 		&rk_dc_csc_table_hdy_cb_cr_limit_to_rgb_full,
6286027c871SZhang Yubing 		{
6296027c871SZhang Yubing 			OPTM_CS_E_ITU_R_BT_709, OPTM_CS_E_RGB, false, true
6306027c871SZhang Yubing 		}
6316027c871SZhang Yubing 	},
6326027c871SZhang Yubing 	{
6336027c871SZhang Yubing 		RK_PQ_CSC_RGB2YUV_601, "RGB F->YUV601 L",
6346027c871SZhang Yubing 		&rk_csc_table_rgb_to_xv_yccsdy_cb_cr,
6356027c871SZhang Yubing 		&rk_dc_csc_table_rgb_to_xv_yccsdy_cb_cr,
6366027c871SZhang Yubing 		{
6376027c871SZhang Yubing 			OPTM_CS_E_RGB, OPTM_CS_E_XV_YCC_601, true, false
6386027c871SZhang Yubing 		}
6396027c871SZhang Yubing 	},
6406027c871SZhang Yubing 	{
6416027c871SZhang Yubing 		RK_PQ_CSC_RGB2YUV_709, "RGB F->YUV709 L",
6426027c871SZhang Yubing 		&rk_csc_table_rgb_to_hdy_cb_cr,
6436027c871SZhang Yubing 		&rk_dc_csc_table_rgb_to_hdy_cb_cr,
6446027c871SZhang Yubing 		{
6456027c871SZhang Yubing 			OPTM_CS_E_RGB, OPTM_CS_E_ITU_R_BT_709, true, false
6466027c871SZhang Yubing 		}
6476027c871SZhang Yubing 	},
6486027c871SZhang Yubing 	{
6496027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_709_601, "YUV709 L->YUV601 L",
6506027c871SZhang Yubing 		&rk_csc_table_hdy_cb_cr_to_xv_yccsdy_cb_cr,
6516027c871SZhang Yubing 		&rk_dc_csc_table_hdy_cb_cr_to_xv_yccsdy_cb_cr,
6526027c871SZhang Yubing 		{
6536027c871SZhang Yubing 			OPTM_CS_E_ITU_R_BT_709, OPTM_CS_E_XV_YCC_601, false, false
6546027c871SZhang Yubing 		}
6556027c871SZhang Yubing 	},
6566027c871SZhang Yubing 	{
6576027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_601_709, "YUV601 L->YUV709 L",
6586027c871SZhang Yubing 		&rk_csc_table_xv_yccsdy_cb_cr_to_hdy_cb_cr,
6596027c871SZhang Yubing 		&rk_dc_csc_table_xv_yccsdy_cb_cr_to_hdy_cb_cr,
6606027c871SZhang Yubing 		{
6616027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_601, OPTM_CS_E_ITU_R_BT_709, false, false
6626027c871SZhang Yubing 		}
6636027c871SZhang Yubing 	},
6646027c871SZhang Yubing 	{
6656027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV, "YUV L->YUV L",
6668b59e34dSZhang Yubing 		&rk_csc_table_identity_y_cb_cr_to_y_cb_cr,
6676027c871SZhang Yubing 		&rk_dc_csc_table_xv_yccsdy_cb_cr_to_hdy_cb_cr,
6686027c871SZhang Yubing 		{
6696027c871SZhang Yubing 			OPTM_CS_E_ITU_R_BT_709, OPTM_CS_E_ITU_R_BT_709, false, false
6706027c871SZhang Yubing 		}
6716027c871SZhang Yubing 	},
6726027c871SZhang Yubing 	{
6736027c871SZhang Yubing 		RK_PQ_CSC_YUV2RGB_601_FULL, "YUV601 F->RGB F",
6746027c871SZhang Yubing 		&rk_csc_table_xv_yccsdy_cb_cr_to_rgb_full,
6756027c871SZhang Yubing 		&rk_dc_csc_table_xv_yccsdy_cb_cr_to_rgb_full,
6766027c871SZhang Yubing 		{
6776027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_601, OPTM_CS_E_RGB, true, true
6786027c871SZhang Yubing 		}
6796027c871SZhang Yubing 	},
6806027c871SZhang Yubing 		{
6816027c871SZhang Yubing 		RK_PQ_CSC_YUV2RGB_709_FULL, "YUV709 F->RGB F",
6826027c871SZhang Yubing 		&rk_csc_table_hdy_cb_cr_to_rgb_full,
6836027c871SZhang Yubing 		&rk_dc_csc_table_hdy_cb_cr_to_rgb_full,
6846027c871SZhang Yubing 		{
6856027c871SZhang Yubing 			OPTM_CS_E_ITU_R_BT_709, OPTM_CS_E_RGB, true, true
6866027c871SZhang Yubing 		}
6876027c871SZhang Yubing 	},
6886027c871SZhang Yubing 	{
6896027c871SZhang Yubing 		RK_PQ_CSC_RGB2YUV_601_FULL, "RGB F->YUV601 F",
6906027c871SZhang Yubing 		&rk_csc_table_rgb_to_xv_yccsdy_cb_cr_full,
6916027c871SZhang Yubing 		&rk_dc_csc_table_rgb_to_xv_yccsdy_cb_cr_full,
6926027c871SZhang Yubing 		{
6936027c871SZhang Yubing 			OPTM_CS_E_RGB, OPTM_CS_E_XV_YCC_601, true, true
6946027c871SZhang Yubing 		}
6956027c871SZhang Yubing 	},
6966027c871SZhang Yubing 	{
6976027c871SZhang Yubing 		RK_PQ_CSC_RGB2YUV_709_FULL, "RGB F->YUV709 F",
6986027c871SZhang Yubing 		&rk_csc_table_rgb_to_hdy_cb_cr_full,
6996027c871SZhang Yubing 		&rk_dc_csc_table_rgb_to_hdy_cb_cr_full,
7006027c871SZhang Yubing 		{
7016027c871SZhang Yubing 			OPTM_CS_E_RGB, OPTM_CS_E_ITU_R_BT_709, true, true
7026027c871SZhang Yubing 		}
7036027c871SZhang Yubing 	},
7046027c871SZhang Yubing 	{
7056027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_709_601_FULL, "YUV709 F->YUV601 F",
7066027c871SZhang Yubing 		&rk_csc_table_hdy_cb_cr_to_xv_yccsdy_cb_cr,
7076027c871SZhang Yubing 		&rk_dc_csc_table_hdy_cb_cr_full_to_xv_yccsdy_cb_cr_full,
7086027c871SZhang Yubing 		{
7096027c871SZhang Yubing 			OPTM_CS_E_ITU_R_BT_709, OPTM_CS_E_XV_YCC_601, true, true
7106027c871SZhang Yubing 		}
7116027c871SZhang Yubing 	},
7126027c871SZhang Yubing 	{
7136027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_601_709_FULL, "YUV601 F->YUV709 F",
7148b59e34dSZhang Yubing 		&rk_csc_table_xv_yccsdy_cb_cr_full_to_hdy_cb_cr_full,
7156027c871SZhang Yubing 		&rk_dc_csc_table_hdy_cb_cr_full_to_xv_yccsdy_cb_cr_full,
7166027c871SZhang Yubing 		{
7176027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_601, OPTM_CS_E_ITU_R_BT_709, true, true
7186027c871SZhang Yubing 		}
7196027c871SZhang Yubing 	},
7206027c871SZhang Yubing 	{
7216027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_FULL, "YUV F->YUV F",
7226027c871SZhang Yubing 		&rk_csc_table_identity_y_cb_cr_to_y_cb_cr,
7236027c871SZhang Yubing 		&rk_dc_csc_table_hdy_cb_cr_full_to_xv_yccsdy_cb_cr_full,
7246027c871SZhang Yubing 		{
7256027c871SZhang Yubing 			OPTM_CS_E_ITU_R_BT_709, OPTM_CS_E_ITU_R_BT_709, true, true
7266027c871SZhang Yubing 		}
7276027c871SZhang Yubing 	},
7286027c871SZhang Yubing 	{
7296027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_LIMIT2FULL, "YUV L->YUV F",
7306027c871SZhang Yubing 		&rk_csc_table_identity_y_cb_cr_limit_to_y_cb_cr_full,
7316027c871SZhang Yubing 		&rk_dc_csc_table_identity_y_cb_cr_limit_to_y_cb_cr_full,
7326027c871SZhang Yubing 		{
7336027c871SZhang Yubing 			OPTM_CS_E_ITU_R_BT_709, OPTM_CS_E_ITU_R_BT_709, false, true
7346027c871SZhang Yubing 		}
7356027c871SZhang Yubing 	},
7366027c871SZhang Yubing 	{
7376027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_601_709_LIMIT2FULL, "YUV601 L->YUV709 F",
7386027c871SZhang Yubing 		&rk_csc_table_identity_601_limit_to_709_full,
7396027c871SZhang Yubing 		&rk_dc_csc_table_identity_601_limit_to_709_full,
7406027c871SZhang Yubing 		{
7416027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_601, OPTM_CS_E_ITU_R_BT_709, false, true
7426027c871SZhang Yubing 		}
7436027c871SZhang Yubing 	},
7446027c871SZhang Yubing 	{
7456027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_709_601_LIMIT2FULL, "YUV709 L->YUV601 F",
7466027c871SZhang Yubing 		&rk_csc_table_identity_709_limit_to_601_full,
7476027c871SZhang Yubing 		&rk_dc_csc_table_identity_709_limit_to_601_full,
7486027c871SZhang Yubing 		{
7496027c871SZhang Yubing 			OPTM_CS_E_ITU_R_BT_709, OPTM_CS_E_XV_YCC_601, false, true
7506027c871SZhang Yubing 		}
7516027c871SZhang Yubing 	},
7526027c871SZhang Yubing 	{
7536027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_FULL2LIMIT, "YUV F->YUV L",
7546027c871SZhang Yubing 		&rk_csc_table_identity_y_cb_cr_full_to_y_cb_cr_limit,
7556027c871SZhang Yubing 		&rk_dc_csc_table_identity_y_cb_cr_full_to_y_cb_cr_limit,
7566027c871SZhang Yubing 		{
7576027c871SZhang Yubing 			OPTM_CS_E_ITU_R_BT_709, OPTM_CS_E_ITU_R_BT_709, true, false
7586027c871SZhang Yubing 		}
7596027c871SZhang Yubing 	},
7606027c871SZhang Yubing 	{
7616027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_601_709_FULL2LIMIT, "YUV601 F->YUV709 L",
7626027c871SZhang Yubing 		&rk_csc_table_identity_y_cb_cr_601_full_to_y_cb_cr_709_limit,
7636027c871SZhang Yubing 		&rk_dc_csc_table_identity_y_cb_cr_601_full_to_y_cb_cr_709_limit,
7646027c871SZhang Yubing 		{
7656027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_601, OPTM_CS_E_ITU_R_BT_709, true, false
7666027c871SZhang Yubing 		}
7676027c871SZhang Yubing 	},
7686027c871SZhang Yubing 	{
7696027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_709_601_FULL2LIMIT, "YUV709 F->YUV601 L",
7706027c871SZhang Yubing 		&rk_csc_table_identity_y_cb_cr_709_full_to_y_cb_cr_601_limit,
7716027c871SZhang Yubing 		&rk_dc_csc_table_identity_y_cb_cr_709_full_to_y_cb_cr_601_limit,
7726027c871SZhang Yubing 		{
7736027c871SZhang Yubing 			OPTM_CS_E_ITU_R_BT_709, OPTM_CS_E_XV_YCC_601, true, false
7746027c871SZhang Yubing 		}
7756027c871SZhang Yubing 	},
7766027c871SZhang Yubing 	{
7776027c871SZhang Yubing 		RK_PQ_CSC_YUV2RGBL_601, "YUV601 L->RGB L",
7786027c871SZhang Yubing 		&rk_csc_table_xv_yccsdy_cb_cr_limit_to_rgb_limit,
7796027c871SZhang Yubing 		&rk_dc_csc_table_xv_yccsdy_cb_cr_limit_to_rgb_limit,
7806027c871SZhang Yubing 		{
7816027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_601, OPTM_CS_E_RGB, false, false
7826027c871SZhang Yubing 		}
7836027c871SZhang Yubing 	},
7846027c871SZhang Yubing 	{
7856027c871SZhang Yubing 		RK_PQ_CSC_YUV2RGBL_709, "YUV709 L->RGB L",
7866027c871SZhang Yubing 		&rk_csc_table_hdy_cb_cr_limit_to_rgb_limit,
7876027c871SZhang Yubing 		&rk_dc_csc_table_hdy_cb_cr_limit_to_rgb_limit,
7886027c871SZhang Yubing 		{
7896027c871SZhang Yubing 			OPTM_CS_E_ITU_R_BT_709, OPTM_CS_E_RGB, false, false
7906027c871SZhang Yubing 		}
7916027c871SZhang Yubing 	},
7926027c871SZhang Yubing 	{
7936027c871SZhang Yubing 		RK_PQ_CSC_RGBL2YUV_601, "RGB L->YUV601 L",
7946027c871SZhang Yubing 		&rk_csc_table_rgb_limit_to_xv_yccsdy_cb_cr,
7956027c871SZhang Yubing 		&rk_dc_csc_table_rgb_limit_to_xv_yccsdy_cb_cr,
7966027c871SZhang Yubing 		{
7976027c871SZhang Yubing 			OPTM_CS_E_RGB, OPTM_CS_E_XV_YCC_601, false, false
7986027c871SZhang Yubing 		}
7996027c871SZhang Yubing 	},
8006027c871SZhang Yubing 	{
8016027c871SZhang Yubing 		RK_PQ_CSC_RGBL2YUV_709, "RGB L->YUV709 L",
8026027c871SZhang Yubing 		&rk_csc_table_rgb_limit_to_hdy_cb_cr,
8036027c871SZhang Yubing 		&rk_dc_csc_table_rgb_limit_to_hdy_cb_cr,
8046027c871SZhang Yubing 		{
8056027c871SZhang Yubing 			OPTM_CS_E_RGB, OPTM_CS_E_ITU_R_BT_709, false, false
8066027c871SZhang Yubing 		}
8076027c871SZhang Yubing 	},
8086027c871SZhang Yubing 	{
8096027c871SZhang Yubing 		RK_PQ_CSC_YUV2RGBL_601_FULL, "YUV601 F->RGB L",
8106027c871SZhang Yubing 		&rk_csc_table_xv_yccsdy_cb_cr_to_rgb_limit,
8116027c871SZhang Yubing 		&rk_dc_csc_table_xv_yccsdy_cb_cr_to_rgb_limit,
8126027c871SZhang Yubing 		{
8136027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_601, OPTM_CS_E_RGB, true, false
8146027c871SZhang Yubing 		}
8156027c871SZhang Yubing 	},
8166027c871SZhang Yubing 	{
8176027c871SZhang Yubing 		RK_PQ_CSC_YUV2RGBL_709_FULL, "YUV709 F->RGB L",
8186027c871SZhang Yubing 		&rk_csc_table_hdy_cb_cr_to_rgb_limit,
8196027c871SZhang Yubing 		&rk_dc_csc_table_hdy_cb_cr_to_rgb_limit,
8206027c871SZhang Yubing 		{
8216027c871SZhang Yubing 			OPTM_CS_E_ITU_R_BT_709, OPTM_CS_E_RGB, true, false
8226027c871SZhang Yubing 		}
8236027c871SZhang Yubing 	},
8246027c871SZhang Yubing 	{
8256027c871SZhang Yubing 		RK_PQ_CSC_RGBL2YUV_601_FULL, "RGB L->YUV601 F",
8266027c871SZhang Yubing 		&rk_csc_table_rgb_limit_to_xv_yccsdy_cb_cr_full,
8276027c871SZhang Yubing 		&rk_dc_csc_table_rgb_limit_to_xv_yccsdy_cb_cr_full,
8286027c871SZhang Yubing 		{
8296027c871SZhang Yubing 			OPTM_CS_E_RGB, OPTM_CS_E_XV_YCC_601, false, true
8306027c871SZhang Yubing 		}
8316027c871SZhang Yubing 	},
8326027c871SZhang Yubing 	{
8336027c871SZhang Yubing 		RK_PQ_CSC_RGBL2YUV_709_FULL, "RGB L->YUV709 F",
8346027c871SZhang Yubing 		&rk_csc_table_rgb_limit_to_hdy_cb_cr_full,
8356027c871SZhang Yubing 		&rk_dc_csc_table_rgb_limit_to_hdy_cb_cr_full,
8366027c871SZhang Yubing 		{
8376027c871SZhang Yubing 			OPTM_CS_E_RGB, OPTM_CS_E_ITU_R_BT_709, false, true
8386027c871SZhang Yubing 		}
8396027c871SZhang Yubing 	},
8406027c871SZhang Yubing 	{
8416027c871SZhang Yubing 		RK_PQ_CSC_RGB2RGBL, "RGB F->RGB L",
8426027c871SZhang Yubing 		&rk_csc_table_identity_rgb_to_rgb_limit,
8436027c871SZhang Yubing 		&rk_dc_csc_table_identity_rgb_to_rgb_limit,
8446027c871SZhang Yubing 		{
8456027c871SZhang Yubing 			OPTM_CS_E_RGB, OPTM_CS_E_RGB, true, false
8466027c871SZhang Yubing 		}
8476027c871SZhang Yubing 	},
8486027c871SZhang Yubing 	{
8496027c871SZhang Yubing 		RK_PQ_CSC_RGBL2RGB, "RGB L->RGB F",
8506027c871SZhang Yubing 		&rk_csc_table_identity_rgb_limit_to_rgb,
8516027c871SZhang Yubing 		&rk_dc_csc_table_identity_rgb_limit_to_rgb,
8526027c871SZhang Yubing 		{
8536027c871SZhang Yubing 			OPTM_CS_E_RGB, OPTM_CS_E_RGB, false, true
8546027c871SZhang Yubing 		}
8556027c871SZhang Yubing 	},
8566027c871SZhang Yubing 	{
8576027c871SZhang Yubing 		RK_PQ_CSC_RGBL2RGBL, "RGB L->RGB L",
8586027c871SZhang Yubing 		&rk_csc_table_identity_rgb_to_rgb,
8596027c871SZhang Yubing 		&rk_dc_csc_table_identity_rgb_to_rgb1,
8606027c871SZhang Yubing 		{
8616027c871SZhang Yubing 			OPTM_CS_E_RGB, OPTM_CS_E_RGB, false, false
8626027c871SZhang Yubing 		}
8636027c871SZhang Yubing 	},
8646027c871SZhang Yubing 	{
8656027c871SZhang Yubing 		RK_PQ_CSC_RGB2RGB, "RGB F->RGB F",
8666027c871SZhang Yubing 		&rk_csc_table_identity_rgb_to_rgb,
8676027c871SZhang Yubing 		&rk_dc_csc_table_identity_rgb_to_rgb2,
8686027c871SZhang Yubing 		{
8696027c871SZhang Yubing 			OPTM_CS_E_RGB, OPTM_CS_E_RGB, true, true
8706027c871SZhang Yubing 		}
8716027c871SZhang Yubing 	},
8726027c871SZhang Yubing 	{
8736027c871SZhang Yubing 		RK_PQ_CSC_YUV2RGB_2020, "YUV2020 F->RGB2020 F",
8746027c871SZhang Yubing 		&rk_csc_table_identity_yuv_to_rgb_2020,
8756027c871SZhang Yubing 		&rk_dc_csc_table_identity_yuv_to_rgb_2020,
8766027c871SZhang Yubing 		{
8776027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_2020, OPTM_CS_E_RGB_2020, true, true
8786027c871SZhang Yubing 		}
8796027c871SZhang Yubing 	},
8806027c871SZhang Yubing 	{
8816027c871SZhang Yubing 		RK_PQ_CSC_RGB2YUV2020_LIMIT2FULL, "RGB2020 L->YUV2020 F",
8826027c871SZhang Yubing 		&rk_csc_table_identity_rgb_limit_to_yuv_full_2020,
8836027c871SZhang Yubing 		&rk_dc_csc_table_identity_rgb_limit_to_yuv_full_2020,
8846027c871SZhang Yubing 		{
8856027c871SZhang Yubing 			OPTM_CS_E_RGB_2020, OPTM_CS_E_XV_YCC_2020, false, true
8866027c871SZhang Yubing 		}
8876027c871SZhang Yubing 	},
8886027c871SZhang Yubing 	{
8896027c871SZhang Yubing 		RK_PQ_CSC_RGB2YUV2020_LIMIT, "RGB2020 L->YUV2020 L",
8906027c871SZhang Yubing 		&rk_csc_table_identity_rgb_limit_to_yuv_limit_2020,
8916027c871SZhang Yubing 		&rk_dc_csc_table_identity_rgb_limit_to_yuv_limit_2020,
8926027c871SZhang Yubing 		{
8936027c871SZhang Yubing 			OPTM_CS_E_RGB_2020, OPTM_CS_E_XV_YCC_2020, false, false
8946027c871SZhang Yubing 		}
8956027c871SZhang Yubing 	},
8966027c871SZhang Yubing 	{
8976027c871SZhang Yubing 		RK_PQ_CSC_RGB2YUV2020_FULL2LIMIT, "RGB2020 F->YUV2020 L",
8986027c871SZhang Yubing 		&rk_csc_table_identity_rgb_full_to_yuv_limit_2020,
8996027c871SZhang Yubing 		&rk_dc_csc_table_identity_rgb_full_to_yuv_limit_2020,
9006027c871SZhang Yubing 		{
9016027c871SZhang Yubing 			OPTM_CS_E_RGB_2020, OPTM_CS_E_XV_YCC_2020, true, false
9026027c871SZhang Yubing 		}
9036027c871SZhang Yubing 	},
9046027c871SZhang Yubing 	{
9056027c871SZhang Yubing 		RK_PQ_CSC_RGB2YUV2020_FULL, "RGB2020 F->YUV2020 F",
9066027c871SZhang Yubing 		&rk_csc_table_identity_rgb_full_to_yuv_full_2020,
9076027c871SZhang Yubing 		&rk_dc_csc_table_identity_rgb_full_to_yuv_full_2020,
9086027c871SZhang Yubing 		{
9096027c871SZhang Yubing 			OPTM_CS_E_RGB_2020, OPTM_CS_E_XV_YCC_2020, true, true
9106027c871SZhang Yubing 		}
9116027c871SZhang Yubing 	},
9126027c871SZhang Yubing 	{
9136027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV, "YUV 601 L->YUV 601 L",
9148b59e34dSZhang Yubing 		&rk_csc_table_identity_y_cb_cr_to_y_cb_cr,
9156027c871SZhang Yubing 		&rk_dc_csc_table_xv_yccsdy_cb_cr_to_hdy_cb_cr,
9166027c871SZhang Yubing 		{
9176027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_601, OPTM_CS_E_XV_YCC_601, false, false
9186027c871SZhang Yubing 		}
9196027c871SZhang Yubing 	},
9206027c871SZhang Yubing 	{
9216027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_FULL, "YUV 601 F->YUV 601 F",
9226027c871SZhang Yubing 		&rk_csc_table_identity_y_cb_cr_to_y_cb_cr,
9236027c871SZhang Yubing 		&rk_dc_csc_table_hdy_cb_cr_full_to_xv_yccsdy_cb_cr_full,
9246027c871SZhang Yubing 		{
9256027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_601, OPTM_CS_E_XV_YCC_601, true, true
9266027c871SZhang Yubing 		}
9276027c871SZhang Yubing 	},
9286027c871SZhang Yubing 	{
9296027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_LIMIT2FULL, "YUV 601 L->YUV 601 F",
9306027c871SZhang Yubing 		&rk_csc_table_identity_y_cb_cr_limit_to_y_cb_cr_full,
9316027c871SZhang Yubing 		&rk_dc_csc_table_identity_y_cb_cr_limit_to_y_cb_cr_full,
9326027c871SZhang Yubing 		{
9336027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_601, OPTM_CS_E_XV_YCC_601,  false, true
9346027c871SZhang Yubing 		}
9356027c871SZhang Yubing 	},
9366027c871SZhang Yubing 	{
9376027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_FULL2LIMIT, "YUV 601 F->YUV 601 L",
9386027c871SZhang Yubing 		&rk_csc_table_identity_y_cb_cr_full_to_y_cb_cr_limit,
9396027c871SZhang Yubing 		&rk_dc_csc_table_identity_y_cb_cr_full_to_y_cb_cr_limit,
9406027c871SZhang Yubing 		{
9416027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_601, OPTM_CS_E_XV_YCC_601, true, false
9426027c871SZhang Yubing 		}
9436027c871SZhang Yubing 	},
9446027c871SZhang Yubing 	{
9456027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV, "YUV 2020 L->YUV 2020 L",
9468b59e34dSZhang Yubing 		&rk_csc_table_identity_y_cb_cr_to_y_cb_cr,
9476027c871SZhang Yubing 		&rk_dc_csc_table_xv_yccsdy_cb_cr_to_hdy_cb_cr,
9486027c871SZhang Yubing 		{
9496027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_2020, OPTM_CS_E_XV_YCC_2020, false, false
9506027c871SZhang Yubing 		}
9516027c871SZhang Yubing 	},
9526027c871SZhang Yubing 	{
9536027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_FULL, "YUV 2020 F->YUV 2020 F",
9546027c871SZhang Yubing 		&rk_csc_table_identity_y_cb_cr_to_y_cb_cr,
9556027c871SZhang Yubing 		&rk_dc_csc_table_hdy_cb_cr_full_to_xv_yccsdy_cb_cr_full,
9566027c871SZhang Yubing 		{
9576027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_2020, OPTM_CS_E_XV_YCC_2020, true, true
9586027c871SZhang Yubing 		}
9596027c871SZhang Yubing 	},
9606027c871SZhang Yubing 	{
9616027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_LIMIT2FULL, "YUV 2020 L->YUV 2020 F",
9626027c871SZhang Yubing 		&rk_csc_table_identity_y_cb_cr_limit_to_y_cb_cr_full,
9636027c871SZhang Yubing 		&rk_dc_csc_table_identity_y_cb_cr_limit_to_y_cb_cr_full,
9646027c871SZhang Yubing 		{
9656027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_2020, OPTM_CS_E_XV_YCC_2020, false, true
9666027c871SZhang Yubing 		}
9676027c871SZhang Yubing 	},
9686027c871SZhang Yubing 	{
9696027c871SZhang Yubing 		RK_PQ_CSC_YUV2YUV_FULL2LIMIT, "YUV 2020 F->YUV 2020 L",
9706027c871SZhang Yubing 		&rk_csc_table_identity_y_cb_cr_full_to_y_cb_cr_limit,
9716027c871SZhang Yubing 		&rk_dc_csc_table_identity_y_cb_cr_full_to_y_cb_cr_limit,
9726027c871SZhang Yubing 		{
9736027c871SZhang Yubing 			OPTM_CS_E_XV_YCC_2020, OPTM_CS_E_XV_YCC_2020, true, false
9746027c871SZhang Yubing 		}
9756027c871SZhang Yubing 	},
9766027c871SZhang Yubing 	{
9776027c871SZhang Yubing 		RK_PQ_CSC_RGB2RGBL, "RGB 2020 F->RGB 2020 L",
9786027c871SZhang Yubing 		&rk_csc_table_identity_rgb_to_rgb_limit,
9796027c871SZhang Yubing 		&rk_dc_csc_table_identity_rgb_to_rgb_limit,
9806027c871SZhang Yubing 		{
9816027c871SZhang Yubing 			OPTM_CS_E_RGB_2020, OPTM_CS_E_RGB_2020, true, false
9826027c871SZhang Yubing 		}
9836027c871SZhang Yubing 	},
9846027c871SZhang Yubing 	{
9856027c871SZhang Yubing 		RK_PQ_CSC_RGBL2RGB, "RGB 2020 L->RGB 2020 F",
9866027c871SZhang Yubing 		&rk_csc_table_identity_rgb_limit_to_rgb,
9876027c871SZhang Yubing 		&rk_dc_csc_table_identity_rgb_limit_to_rgb,
9886027c871SZhang Yubing 		{
9896027c871SZhang Yubing 			OPTM_CS_E_RGB_2020, OPTM_CS_E_RGB_2020, false, true
9906027c871SZhang Yubing 		}
9916027c871SZhang Yubing 	},
9926027c871SZhang Yubing 	{
9936027c871SZhang Yubing 		RK_PQ_CSC_RGBL2RGBL, "RGB 2020 L->RGB 2020 L",
9946027c871SZhang Yubing 		&rk_csc_table_identity_rgb_to_rgb,
9956027c871SZhang Yubing 		&rk_dc_csc_table_identity_rgb_to_rgb1,
9966027c871SZhang Yubing 		{
9976027c871SZhang Yubing 			OPTM_CS_E_RGB_2020, OPTM_CS_E_RGB_2020, false, false
9986027c871SZhang Yubing 		}
9996027c871SZhang Yubing 	},
10006027c871SZhang Yubing 	{
10016027c871SZhang Yubing 		RK_PQ_CSC_RGB2RGB, "RGB 2020 F->RGB 2020 F",
10026027c871SZhang Yubing 		&rk_csc_table_identity_rgb_to_rgb,
10036027c871SZhang Yubing 		&rk_dc_csc_table_identity_rgb_to_rgb2,
10046027c871SZhang Yubing 		{
10056027c871SZhang Yubing 			OPTM_CS_E_RGB_2020, OPTM_CS_E_RGB_2020, true, true
10066027c871SZhang Yubing 		}
10076027c871SZhang Yubing 	},
10086027c871SZhang Yubing };
10096027c871SZhang Yubing 
10106027c871SZhang Yubing struct csc_mapping {
10116027c871SZhang Yubing 	enum vop_csc_format csc_format;
10126027c871SZhang Yubing 	enum color_space_type rgb_color_space;
10136027c871SZhang Yubing 	enum color_space_type yuv_color_space;
10146027c871SZhang Yubing 	bool rgb_full_range;
10156027c871SZhang Yubing 	bool yuv_full_range;
10166027c871SZhang Yubing };
10176027c871SZhang Yubing 
10186027c871SZhang Yubing static const struct csc_mapping csc_mapping_table[] = {
10196027c871SZhang Yubing 	{
10206027c871SZhang Yubing 		CSC_BT601L,
10216027c871SZhang Yubing 		OPTM_CS_E_RGB,
10226027c871SZhang Yubing 		OPTM_CS_E_XV_YCC_601,
10236027c871SZhang Yubing 		true,
10246027c871SZhang Yubing 		false,
10256027c871SZhang Yubing 	},
10266027c871SZhang Yubing 	{
10276027c871SZhang Yubing 		CSC_BT709L,
10286027c871SZhang Yubing 		OPTM_CS_E_RGB,
10296027c871SZhang Yubing 		OPTM_CS_E_XV_YCC_709,
10306027c871SZhang Yubing 		true,
10316027c871SZhang Yubing 		false,
10326027c871SZhang Yubing 	},
10336027c871SZhang Yubing 	{
10346027c871SZhang Yubing 		CSC_BT601F,
10356027c871SZhang Yubing 		OPTM_CS_E_RGB,
10366027c871SZhang Yubing 		OPTM_CS_E_XV_YCC_601,
10376027c871SZhang Yubing 		true,
10386027c871SZhang Yubing 		true,
10396027c871SZhang Yubing 	},
10406027c871SZhang Yubing 	{
10416027c871SZhang Yubing 		CSC_BT2020,
10426027c871SZhang Yubing 		OPTM_CS_E_RGB_2020,
10436027c871SZhang Yubing 		OPTM_CS_E_XV_YCC_2020,
10446027c871SZhang Yubing 		true,
10456027c871SZhang Yubing 		true,
10466027c871SZhang Yubing 	},
10476027c871SZhang Yubing 	{
10486027c871SZhang Yubing 		CSC_BT709L_13BIT,
10496027c871SZhang Yubing 		OPTM_CS_E_RGB,
10506027c871SZhang Yubing 		OPTM_CS_E_XV_YCC_709,
10516027c871SZhang Yubing 		true,
10526027c871SZhang Yubing 		false,
10536027c871SZhang Yubing 	},
10546027c871SZhang Yubing 	{
10556027c871SZhang Yubing 		CSC_BT709F_13BIT,
10566027c871SZhang Yubing 		OPTM_CS_E_RGB,
10576027c871SZhang Yubing 		OPTM_CS_E_XV_YCC_709,
10586027c871SZhang Yubing 		true,
10596027c871SZhang Yubing 		true,
10606027c871SZhang Yubing 	},
10616027c871SZhang Yubing 	{
10626027c871SZhang Yubing 		CSC_BT2020L_13BIT,
10636027c871SZhang Yubing 		OPTM_CS_E_RGB_2020,
10646027c871SZhang Yubing 		OPTM_CS_E_XV_YCC_2020,
10656027c871SZhang Yubing 		true,
10666027c871SZhang Yubing 		false,
10676027c871SZhang Yubing 	},
10686027c871SZhang Yubing 	{
10696027c871SZhang Yubing 		CSC_BT2020F_13BIT,
10706027c871SZhang Yubing 		OPTM_CS_E_RGB_2020,
10716027c871SZhang Yubing 		OPTM_CS_E_XV_YCC_2020,
10726027c871SZhang Yubing 		true,
10736027c871SZhang Yubing 		true,
10746027c871SZhang Yubing 	},
10756027c871SZhang Yubing };
10766027c871SZhang Yubing 
10776027c871SZhang Yubing static const struct rk_pq_csc_coef r2y_for_y2y = {
10786027c871SZhang Yubing 	306, 601, 117,
10798b59e34dSZhang Yubing 	-173, -339, 512,
10808b59e34dSZhang Yubing 	512, -429, -83,
10816027c871SZhang Yubing };
10826027c871SZhang Yubing 
10836027c871SZhang Yubing static const struct rk_pq_csc_coef y2r_for_y2y = {
10848b59e34dSZhang Yubing 	1024, -1, 1436,
10858b59e34dSZhang Yubing 	1024, -353, -731,
10868b59e34dSZhang Yubing 	1024, 1814, 1,
10878b59e34dSZhang Yubing };
10888b59e34dSZhang Yubing 
10898b59e34dSZhang Yubing static const struct rk_pq_csc_coef r2y_for_r2r = {
10908b59e34dSZhang Yubing 	218, 732, 74,
10918b59e34dSZhang Yubing 	-117, -395, 512,
10928b59e34dSZhang Yubing 	512, -465, -47,
10936027c871SZhang Yubing };
10946027c871SZhang Yubing 
1095*b12f8e1cSDamon Ding static const struct rk_pq_csc_coef y2r_for_r2r = {
1096*b12f8e1cSDamon Ding 	1024, 0, 1612,
1097*b12f8e1cSDamon Ding 	1024, -192, -480,
1098*b12f8e1cSDamon Ding 	1024, 1900, -2,
1099*b12f8e1cSDamon Ding };
1100*b12f8e1cSDamon Ding 
11016027c871SZhang Yubing static const struct rk_pq_csc_coef rgb_input_swap_matrix = {
11026027c871SZhang Yubing 	0, 0, 1,
11036027c871SZhang Yubing 	1, 0, 0,
11046027c871SZhang Yubing 	0, 1, 0,
11056027c871SZhang Yubing };
11066027c871SZhang Yubing 
11076027c871SZhang Yubing static const struct rk_pq_csc_coef yuv_output_swap_matrix = {
11086027c871SZhang Yubing 	0, 0, 1,
11096027c871SZhang Yubing 	1, 0, 0,
11106027c871SZhang Yubing 	0, 1, 0,
11116027c871SZhang Yubing };
11126027c871SZhang Yubing 
csc_get_mode_index(int post_csc_mode,bool is_input_yuv,bool is_output_yuv)11136027c871SZhang Yubing static int csc_get_mode_index(int post_csc_mode, bool is_input_yuv, bool is_output_yuv)
11146027c871SZhang Yubing {
11156027c871SZhang Yubing 	const struct rk_csc_colorspace_info *colorspace_info;
11166027c871SZhang Yubing 	enum color_space_type input_color_space;
11176027c871SZhang Yubing 	enum color_space_type output_color_space;
11186027c871SZhang Yubing 	bool is_input_full_range;
11196027c871SZhang Yubing 	bool is_output_full_range;
11206027c871SZhang Yubing 	int i;
11216027c871SZhang Yubing 
11226027c871SZhang Yubing 	for (i = 0; i < ARRAY_SIZE(csc_mapping_table); i++) {
11236027c871SZhang Yubing 		if (post_csc_mode == csc_mapping_table[i].csc_format) {
11246027c871SZhang Yubing 			input_color_space = is_input_yuv ? csc_mapping_table[i].yuv_color_space :
11256027c871SZhang Yubing 					    csc_mapping_table[i].rgb_color_space;
11266027c871SZhang Yubing 			is_input_full_range = is_input_yuv ? csc_mapping_table[i].yuv_full_range :
11276027c871SZhang Yubing 					      csc_mapping_table[i].rgb_full_range;
11286027c871SZhang Yubing 			output_color_space = is_output_yuv ? csc_mapping_table[i].yuv_color_space :
11296027c871SZhang Yubing 					     csc_mapping_table[i].rgb_color_space;
11306027c871SZhang Yubing 			is_output_full_range = is_output_yuv ? csc_mapping_table[i].yuv_full_range :
11316027c871SZhang Yubing 					       csc_mapping_table[i].rgb_full_range;
11326027c871SZhang Yubing 			break;
11336027c871SZhang Yubing 		}
11346027c871SZhang Yubing 	}
11356027c871SZhang Yubing 	if (i >= ARRAY_SIZE(csc_mapping_table))
11366027c871SZhang Yubing 		return -EINVAL;
11376027c871SZhang Yubing 
11386027c871SZhang Yubing 	for (i = 0; i < ARRAY_SIZE(g_mode_csc_coef); i++) {
11396027c871SZhang Yubing 		colorspace_info = &g_mode_csc_coef[i].st_csc_color_info;
11406027c871SZhang Yubing 		if (colorspace_info->input_color_space == input_color_space &&
11416027c871SZhang Yubing 		    colorspace_info->output_color_space == output_color_space &&
11426027c871SZhang Yubing 		    colorspace_info->in_full_range == is_input_full_range &&
11436027c871SZhang Yubing 		    colorspace_info->out_full_range == is_output_full_range)
11446027c871SZhang Yubing 			return i;
11456027c871SZhang Yubing 	}
11466027c871SZhang Yubing 
11476027c871SZhang Yubing 	return -EINVAL;
11486027c871SZhang Yubing }
11496027c871SZhang Yubing 
csc_matrix_multiply(struct rk_pq_csc_coef * dst,const struct rk_pq_csc_coef * m0,const struct rk_pq_csc_coef * m1)11506027c871SZhang Yubing static void csc_matrix_multiply(struct rk_pq_csc_coef *dst, const struct rk_pq_csc_coef *m0,
11516027c871SZhang Yubing 				const struct rk_pq_csc_coef *m1)
11526027c871SZhang Yubing {
11536027c871SZhang Yubing 	dst->csc_coef00 = m0->csc_coef00 * m1->csc_coef00 +
11546027c871SZhang Yubing 			  m0->csc_coef01 * m1->csc_coef10 +
11556027c871SZhang Yubing 			  m0->csc_coef02 * m1->csc_coef20;
11566027c871SZhang Yubing 
11576027c871SZhang Yubing 	dst->csc_coef01 = m0->csc_coef00 * m1->csc_coef01 +
11586027c871SZhang Yubing 			  m0->csc_coef01 * m1->csc_coef11 +
11596027c871SZhang Yubing 			  m0->csc_coef02 * m1->csc_coef21;
11606027c871SZhang Yubing 
11616027c871SZhang Yubing 	dst->csc_coef02 = m0->csc_coef00 * m1->csc_coef02 +
11626027c871SZhang Yubing 			  m0->csc_coef01 * m1->csc_coef12 +
11636027c871SZhang Yubing 			  m0->csc_coef02 * m1->csc_coef22;
11646027c871SZhang Yubing 
11656027c871SZhang Yubing 	dst->csc_coef10 = m0->csc_coef10 * m1->csc_coef00 +
11666027c871SZhang Yubing 			  m0->csc_coef11 * m1->csc_coef10 +
11676027c871SZhang Yubing 			  m0->csc_coef12 * m1->csc_coef20;
11686027c871SZhang Yubing 
11696027c871SZhang Yubing 	dst->csc_coef11 = m0->csc_coef10 * m1->csc_coef01 +
11706027c871SZhang Yubing 			  m0->csc_coef11 * m1->csc_coef11 +
11716027c871SZhang Yubing 			  m0->csc_coef12 * m1->csc_coef21;
11726027c871SZhang Yubing 
11736027c871SZhang Yubing 	dst->csc_coef12 = m0->csc_coef10 * m1->csc_coef02 +
11746027c871SZhang Yubing 			  m0->csc_coef11 * m1->csc_coef12 +
11756027c871SZhang Yubing 			  m0->csc_coef12 * m1->csc_coef22;
11766027c871SZhang Yubing 
11776027c871SZhang Yubing 	dst->csc_coef20 = m0->csc_coef20 * m1->csc_coef00 +
11786027c871SZhang Yubing 			  m0->csc_coef21 * m1->csc_coef10 +
11796027c871SZhang Yubing 			  m0->csc_coef22 * m1->csc_coef20;
11806027c871SZhang Yubing 
11816027c871SZhang Yubing 	dst->csc_coef21 = m0->csc_coef20 * m1->csc_coef01 +
11826027c871SZhang Yubing 			  m0->csc_coef21 * m1->csc_coef11 +
11836027c871SZhang Yubing 			  m0->csc_coef22 * m1->csc_coef21;
11846027c871SZhang Yubing 
11856027c871SZhang Yubing 	dst->csc_coef22 = m0->csc_coef20 * m1->csc_coef02 +
11866027c871SZhang Yubing 			  m0->csc_coef21 * m1->csc_coef12 +
11876027c871SZhang Yubing 			  m0->csc_coef22 * m1->csc_coef22;
11886027c871SZhang Yubing }
11896027c871SZhang Yubing 
csc_matrix_ventor_multiply(struct rk_pq_csc_ventor * dst,const struct rk_pq_csc_coef * m0,const struct rk_pq_csc_ventor * v0)11906027c871SZhang Yubing static void csc_matrix_ventor_multiply(struct rk_pq_csc_ventor *dst,
11916027c871SZhang Yubing 				       const struct rk_pq_csc_coef *m0,
11926027c871SZhang Yubing 				       const struct rk_pq_csc_ventor *v0)
11936027c871SZhang Yubing {
11946027c871SZhang Yubing 	dst->csc_offset0 = m0->csc_coef00 * v0->csc_offset0 +
11956027c871SZhang Yubing 			   m0->csc_coef01 * v0->csc_offset1 +
11966027c871SZhang Yubing 			   m0->csc_coef02 * v0->csc_offset2;
11976027c871SZhang Yubing 
11986027c871SZhang Yubing 	dst->csc_offset1 = m0->csc_coef10 * v0->csc_offset0 +
11996027c871SZhang Yubing 			   m0->csc_coef11 * v0->csc_offset1 +
12006027c871SZhang Yubing 			   m0->csc_coef12 * v0->csc_offset2;
12016027c871SZhang Yubing 
12026027c871SZhang Yubing 	dst->csc_offset2 = m0->csc_coef20 * v0->csc_offset0 +
12036027c871SZhang Yubing 			   m0->csc_coef21 * v0->csc_offset1 +
12046027c871SZhang Yubing 			   m0->csc_coef22 * v0->csc_offset2;
12056027c871SZhang Yubing }
12066027c871SZhang Yubing 
csc_matrix_element_right_shift(struct rk_pq_csc_coef * m,int n)12078b59e34dSZhang Yubing static void csc_matrix_element_right_shift(struct rk_pq_csc_coef *m, int n)
12086027c871SZhang Yubing {
12096027c871SZhang Yubing 	m->csc_coef00 = m->csc_coef00 >> n;
12106027c871SZhang Yubing 	m->csc_coef01 = m->csc_coef01 >> n;
12116027c871SZhang Yubing 	m->csc_coef02 = m->csc_coef02 >> n;
12126027c871SZhang Yubing 	m->csc_coef10 = m->csc_coef10 >> n;
12136027c871SZhang Yubing 	m->csc_coef11 = m->csc_coef11 >> n;
12146027c871SZhang Yubing 	m->csc_coef12 = m->csc_coef12 >> n;
12156027c871SZhang Yubing 	m->csc_coef20 = m->csc_coef20 >> n;
12166027c871SZhang Yubing 	m->csc_coef21 = m->csc_coef21 >> n;
12176027c871SZhang Yubing 	m->csc_coef22 = m->csc_coef22 >> n;
12186027c871SZhang Yubing }
12196027c871SZhang Yubing 
csc_simple_round(s32 x,s32 n)12208b59e34dSZhang Yubing static inline s32 csc_simple_round(s32 x, s32 n)
12218b59e34dSZhang Yubing {
12228b59e34dSZhang Yubing 	s32 value = 0;
12238b59e34dSZhang Yubing 
12248b59e34dSZhang Yubing 	if (n == 0)
12258b59e34dSZhang Yubing 		return x;
12268b59e34dSZhang Yubing 
12278b59e34dSZhang Yubing 	value = (abs(x) + (1 << (n - 1))) >> (n);
12288b59e34dSZhang Yubing 	return (((x) >= 0) ? value : -value);
12298b59e34dSZhang Yubing }
12308b59e34dSZhang Yubing 
csc_matrix_element_right_shift_with_simple_round(struct rk_pq_csc_coef * m,int n)12318b59e34dSZhang Yubing static void csc_matrix_element_right_shift_with_simple_round(struct rk_pq_csc_coef *m, int n)
12328b59e34dSZhang Yubing {
12338b59e34dSZhang Yubing 	m->csc_coef00 = csc_simple_round(m->csc_coef00, n);
12348b59e34dSZhang Yubing 	m->csc_coef01 = csc_simple_round(m->csc_coef01, n);
12358b59e34dSZhang Yubing 	m->csc_coef02 = csc_simple_round(m->csc_coef02, n);
12368b59e34dSZhang Yubing 	m->csc_coef10 = csc_simple_round(m->csc_coef10, n);
12378b59e34dSZhang Yubing 	m->csc_coef11 = csc_simple_round(m->csc_coef11, n);
12388b59e34dSZhang Yubing 	m->csc_coef12 = csc_simple_round(m->csc_coef12, n);
12398b59e34dSZhang Yubing 	m->csc_coef20 = csc_simple_round(m->csc_coef20, n);
12408b59e34dSZhang Yubing 	m->csc_coef21 = csc_simple_round(m->csc_coef21, n);
12418b59e34dSZhang Yubing 	m->csc_coef22 = csc_simple_round(m->csc_coef22, n);
12428b59e34dSZhang Yubing }
12438b59e34dSZhang Yubing 
create_rgb_gain_matrix(s32 r_gain,s32 g_gain,s32 b_gain)12446027c871SZhang Yubing static struct rk_pq_csc_coef create_rgb_gain_matrix(s32 r_gain, s32 g_gain, s32 b_gain)
12456027c871SZhang Yubing {
12466027c871SZhang Yubing 	struct rk_pq_csc_coef m;
12476027c871SZhang Yubing 
12486027c871SZhang Yubing 	m.csc_coef00 = r_gain;
12496027c871SZhang Yubing 	m.csc_coef01 = 0;
12506027c871SZhang Yubing 	m.csc_coef02 = 0;
12516027c871SZhang Yubing 
12526027c871SZhang Yubing 	m.csc_coef10 = 0;
12536027c871SZhang Yubing 	m.csc_coef11 = g_gain;
12546027c871SZhang Yubing 	m.csc_coef12 = 0;
12556027c871SZhang Yubing 
12566027c871SZhang Yubing 	m.csc_coef20 = 0;
12576027c871SZhang Yubing 	m.csc_coef21 = 0;
12586027c871SZhang Yubing 	m.csc_coef22 = b_gain;
12596027c871SZhang Yubing 
12606027c871SZhang Yubing 	return m;
12616027c871SZhang Yubing }
12626027c871SZhang Yubing 
create_contrast_matrix(s32 contrast)12636027c871SZhang Yubing static struct rk_pq_csc_coef create_contrast_matrix(s32 contrast)
12646027c871SZhang Yubing {
12656027c871SZhang Yubing 	struct rk_pq_csc_coef m;
12666027c871SZhang Yubing 
12676027c871SZhang Yubing 	m.csc_coef00 = contrast;
12686027c871SZhang Yubing 	m.csc_coef01 = 0;
12696027c871SZhang Yubing 	m.csc_coef02 = 0;
12706027c871SZhang Yubing 
12716027c871SZhang Yubing 	m.csc_coef10 = 0;
12726027c871SZhang Yubing 	m.csc_coef11 = contrast;
12736027c871SZhang Yubing 	m.csc_coef12 = 0;
12746027c871SZhang Yubing 
12756027c871SZhang Yubing 	m.csc_coef20 = 0;
12766027c871SZhang Yubing 	m.csc_coef21 = 0;
12776027c871SZhang Yubing 	m.csc_coef22 = contrast;
12786027c871SZhang Yubing 
12796027c871SZhang Yubing 	return m;
12806027c871SZhang Yubing }
12816027c871SZhang Yubing 
create_hue_matrix(s32 hue)12826027c871SZhang Yubing static struct rk_pq_csc_coef create_hue_matrix(s32 hue)
12836027c871SZhang Yubing {
12846027c871SZhang Yubing 	struct rk_pq_csc_coef m;
12856027c871SZhang Yubing 	s32 hue_idx;
12866027c871SZhang Yubing 	s32 sin_hue;
12876027c871SZhang Yubing 	s32 cos_hue;
12886027c871SZhang Yubing 
12896027c871SZhang Yubing 	hue_idx = CLIP(hue / PQ_CSC_HUE_TABLE_DIV_COEF, 0, PQ_CSC_HUE_TABLE_NUM - 1);
12906027c871SZhang Yubing 	sin_hue = g_hue_sin_table[hue_idx];
12916027c871SZhang Yubing 	cos_hue = g_hue_cos_table[hue_idx];
12926027c871SZhang Yubing 
12936027c871SZhang Yubing 	m.csc_coef00 = 1024;
12946027c871SZhang Yubing 	m.csc_coef01 = 0;
12956027c871SZhang Yubing 	m.csc_coef02 = 0;
12966027c871SZhang Yubing 
12976027c871SZhang Yubing 	m.csc_coef10 = 0;
12986027c871SZhang Yubing 	m.csc_coef11 = cos_hue;
12996027c871SZhang Yubing 	m.csc_coef12 = sin_hue;
13006027c871SZhang Yubing 
13016027c871SZhang Yubing 	m.csc_coef20 = 0;
13026027c871SZhang Yubing 	m.csc_coef21 = -sin_hue;
13036027c871SZhang Yubing 	m.csc_coef22 = cos_hue;
13046027c871SZhang Yubing 
13056027c871SZhang Yubing 	return m;
13066027c871SZhang Yubing }
13076027c871SZhang Yubing 
create_saturation_matrix(s32 saturation)13086027c871SZhang Yubing static struct rk_pq_csc_coef create_saturation_matrix(s32 saturation)
13096027c871SZhang Yubing {
13106027c871SZhang Yubing 	struct rk_pq_csc_coef m;
13116027c871SZhang Yubing 
13126027c871SZhang Yubing 	m.csc_coef00 = 512;
13136027c871SZhang Yubing 	m.csc_coef01 = 0;
13146027c871SZhang Yubing 	m.csc_coef02 = 0;
13156027c871SZhang Yubing 
13166027c871SZhang Yubing 	m.csc_coef10 = 0;
13176027c871SZhang Yubing 	m.csc_coef11 = saturation;
13186027c871SZhang Yubing 	m.csc_coef12 = 0;
13196027c871SZhang Yubing 
13206027c871SZhang Yubing 	m.csc_coef20 = 0;
13216027c871SZhang Yubing 	m.csc_coef21 = 0;
13226027c871SZhang Yubing 	m.csc_coef22 = saturation;
13236027c871SZhang Yubing 
13246027c871SZhang Yubing 	return m;
13256027c871SZhang Yubing }
13266027c871SZhang Yubing 
csc_calc_adjust_output_coef(bool is_input_yuv,bool is_output_yuv,struct csc_info * csc_input_cfg,const struct rk_csc_mode_coef * csc_mode_cfg,struct rk_pq_csc_coef * out_matrix,struct rk_pq_csc_ventor * out_dc)13276027c871SZhang Yubing static int csc_calc_adjust_output_coef(bool is_input_yuv, bool is_output_yuv,
13286027c871SZhang Yubing 				       struct csc_info *csc_input_cfg,
13296027c871SZhang Yubing 				       const struct rk_csc_mode_coef *csc_mode_cfg,
13306027c871SZhang Yubing 				       struct rk_pq_csc_coef *out_matrix,
13316027c871SZhang Yubing 				       struct rk_pq_csc_ventor *out_dc)
13326027c871SZhang Yubing {
13336027c871SZhang Yubing 	struct rk_pq_csc_coef gain_matrix;
13346027c871SZhang Yubing 	struct rk_pq_csc_coef contrast_matrix;
13356027c871SZhang Yubing 	struct rk_pq_csc_coef hue_matrix;
13366027c871SZhang Yubing 	struct rk_pq_csc_coef saturation_matrix;
13376027c871SZhang Yubing 	struct rk_pq_csc_coef temp0, temp1;
13386027c871SZhang Yubing 	const struct rk_pq_csc_coef *r2y_matrix;
13396027c871SZhang Yubing 	const struct rk_pq_csc_coef *y2r_matrix;
13406027c871SZhang Yubing 	struct rk_pq_csc_ventor dc_in_ventor;
13416027c871SZhang Yubing 	struct rk_pq_csc_ventor dc_out_ventor;
13426027c871SZhang Yubing 	struct rk_pq_csc_ventor v;
13436027c871SZhang Yubing 	const struct rk_csc_colorspace_info *color_info;
13446027c871SZhang Yubing 	s32 contrast, saturation, brightness;
13456027c871SZhang Yubing 	s32 r_gain, g_gain, b_gain;
13466027c871SZhang Yubing 	s32 r_offset, g_offset, b_offset;
13476027c871SZhang Yubing 	s32 dc_in_offset, dc_out_offset;
13486027c871SZhang Yubing 
13496027c871SZhang Yubing 	contrast = csc_input_cfg->contrast * PQ_CSC_PARAM_FIX_NUM / PQ_CSC_IN_PARAM_NORM_COEF;
13506027c871SZhang Yubing 	saturation = csc_input_cfg->saturation  * PQ_CSC_PARAM_FIX_NUM / PQ_CSC_IN_PARAM_NORM_COEF;
13516027c871SZhang Yubing 	r_gain = csc_input_cfg->r_gain * PQ_CSC_PARAM_FIX_NUM / PQ_CSC_IN_PARAM_NORM_COEF;
13526027c871SZhang Yubing 	g_gain = csc_input_cfg->g_gain * PQ_CSC_PARAM_FIX_NUM / PQ_CSC_IN_PARAM_NORM_COEF;
13536027c871SZhang Yubing 	b_gain = csc_input_cfg->b_gain * PQ_CSC_PARAM_FIX_NUM / PQ_CSC_IN_PARAM_NORM_COEF;
13546027c871SZhang Yubing 	r_offset = ((s32)csc_input_cfg->r_offset - PQ_CSC_BRIGHTNESS_OFFSET) /
13556027c871SZhang Yubing 		   PQ_CSC_TEMP_OFFSET_DIV_COEF;
13566027c871SZhang Yubing 	g_offset = ((s32)csc_input_cfg->g_offset - PQ_CSC_BRIGHTNESS_OFFSET) /
13576027c871SZhang Yubing 		   PQ_CSC_TEMP_OFFSET_DIV_COEF;
13586027c871SZhang Yubing 	b_offset = ((s32)csc_input_cfg->b_offset - PQ_CSC_BRIGHTNESS_OFFSET) /
13596027c871SZhang Yubing 		   PQ_CSC_TEMP_OFFSET_DIV_COEF;
13606027c871SZhang Yubing 
13616027c871SZhang Yubing 	gain_matrix = create_rgb_gain_matrix(r_gain, g_gain, b_gain);
13626027c871SZhang Yubing 	contrast_matrix = create_contrast_matrix(contrast);
13636027c871SZhang Yubing 	hue_matrix = create_hue_matrix(csc_input_cfg->hue);
13646027c871SZhang Yubing 	saturation_matrix = create_saturation_matrix(saturation);
13656027c871SZhang Yubing 
13666027c871SZhang Yubing 	color_info = &csc_mode_cfg->st_csc_color_info;
13676027c871SZhang Yubing 	brightness = (s32)csc_input_cfg->brightness - PQ_CSC_BRIGHTNESS_OFFSET;
13686027c871SZhang Yubing 	dc_in_offset = color_info->in_full_range ? 0 : -PQ_CSC_DC_IN_OFFSET;
13696027c871SZhang Yubing 	dc_out_offset = color_info->out_full_range ? 0 : PQ_CSC_DC_IN_OFFSET;
13706027c871SZhang Yubing 
13716027c871SZhang Yubing 	/*
13726027c871SZhang Yubing 	 * M0 = hue_matrix * saturation_matrix,
13736027c871SZhang Yubing 	 * M1 = gain_matrix * constrast_matrix,
13746027c871SZhang Yubing 	 */
13756027c871SZhang Yubing 
13766027c871SZhang Yubing 	if (is_input_yuv && is_output_yuv) {
13776027c871SZhang Yubing 		/*
13786027c871SZhang Yubing 		 * yuv2yuv: output = T * M0 * N_r2y * M1 * N_y2r,
13796027c871SZhang Yubing 		 * so output = T * hue_matrix * saturation_matrix *
13806027c871SZhang Yubing 		 * N_r2y * gain_matrix * contrast_matrix * N_y2r
13816027c871SZhang Yubing 		 */
13826027c871SZhang Yubing 		r2y_matrix = &r2y_for_y2y;
13836027c871SZhang Yubing 		y2r_matrix = &y2r_for_y2y;
13846027c871SZhang Yubing 		csc_matrix_multiply(&temp0, csc_mode_cfg->pst_csc_coef, &hue_matrix);
13856027c871SZhang Yubing 		/*
13866027c871SZhang Yubing 		 * The value bits width is 32 bit, so every time 2 matirx multifly,
13878b59e34dSZhang Yubing 		 * right shift is necessary to avoid overflow. For enhancing the
13886027c871SZhang Yubing 		 * calculator precision, PQ_CALC_ENHANCE_BIT bits is reserved and
13898b59e34dSZhang Yubing 		 * right shift before get the final result.
13906027c871SZhang Yubing 		 */
13918b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp0, PQ_CSC_PARAM_FIX_BIT_WIDTH -
13926027c871SZhang Yubing 					       PQ_CALC_ENHANCE_BIT);
13936027c871SZhang Yubing 		csc_matrix_multiply(&temp1, &temp0, &saturation_matrix);
13948b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp1, PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH);
13956027c871SZhang Yubing 		csc_matrix_multiply(&temp0, &temp1, r2y_matrix);
13968b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp0, PQ_CSC_PARAM_FIX_BIT_WIDTH);
13976027c871SZhang Yubing 		csc_matrix_multiply(&temp1, &temp0, &gain_matrix);
13988b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp1, PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH);
13996027c871SZhang Yubing 		csc_matrix_multiply(&temp0, &temp1, &contrast_matrix);
14008b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp0, PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH);
14016027c871SZhang Yubing 		csc_matrix_multiply(out_matrix, &temp0, y2r_matrix);
14028b59e34dSZhang Yubing 		csc_matrix_element_right_shift_with_simple_round(out_matrix,
14038b59e34dSZhang Yubing 			PQ_CSC_PARAM_FIX_BIT_WIDTH + PQ_CALC_ENHANCE_BIT);
14046027c871SZhang Yubing 
14056027c871SZhang Yubing 		dc_in_ventor.csc_offset0 = dc_in_offset;
14066027c871SZhang Yubing 		dc_in_ventor.csc_offset1 = -PQ_CSC_DC_IN_OUT_DEFAULT;
14076027c871SZhang Yubing 		dc_in_ventor.csc_offset2 = -PQ_CSC_DC_IN_OUT_DEFAULT;
14086027c871SZhang Yubing 		dc_out_ventor.csc_offset0 = brightness + dc_out_offset;
14096027c871SZhang Yubing 		dc_out_ventor.csc_offset1 = PQ_CSC_DC_IN_OUT_DEFAULT;
14106027c871SZhang Yubing 		dc_out_ventor.csc_offset2 = PQ_CSC_DC_IN_OUT_DEFAULT;
14116027c871SZhang Yubing 	} else if (is_input_yuv && !is_output_yuv) {
14126027c871SZhang Yubing 		/*
14136027c871SZhang Yubing 		 * yuv2rgb: output = M1 * T * M0,
14146027c871SZhang Yubing 		 * so output = gain_matrix * contrast_matrix * T *
14156027c871SZhang Yubing 		 * hue_matrix * saturation_matrix
14166027c871SZhang Yubing 		 */
14176027c871SZhang Yubing 		csc_matrix_multiply(&temp0, csc_mode_cfg->pst_csc_coef, &hue_matrix);
14188b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp0, PQ_CSC_PARAM_FIX_BIT_WIDTH -
14196027c871SZhang Yubing 					       PQ_CALC_ENHANCE_BIT);
14206027c871SZhang Yubing 		csc_matrix_multiply(&temp1, &temp0, &saturation_matrix);
14218b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp1, PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH);
14226027c871SZhang Yubing 		csc_matrix_multiply(&temp0, &contrast_matrix, &temp1);
14238b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp0, PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH);
14246027c871SZhang Yubing 		csc_matrix_multiply(out_matrix, &gain_matrix, &temp0);
14258b59e34dSZhang Yubing 		csc_matrix_element_right_shift(out_matrix, PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH +
14266027c871SZhang Yubing 					       PQ_CALC_ENHANCE_BIT);
14276027c871SZhang Yubing 
14286027c871SZhang Yubing 		dc_in_ventor.csc_offset0 = dc_in_offset;
14296027c871SZhang Yubing 		dc_in_ventor.csc_offset1 = -PQ_CSC_DC_IN_OUT_DEFAULT;
14306027c871SZhang Yubing 		dc_in_ventor.csc_offset2 = -PQ_CSC_DC_IN_OUT_DEFAULT;
14316027c871SZhang Yubing 		dc_out_ventor.csc_offset0 = brightness + dc_out_offset + r_offset;
14326027c871SZhang Yubing 		dc_out_ventor.csc_offset1 = brightness + dc_out_offset + g_offset;
14336027c871SZhang Yubing 		dc_out_ventor.csc_offset2 = brightness + dc_out_offset + b_offset;
14346027c871SZhang Yubing 	} else if (!is_input_yuv && is_output_yuv) {
14356027c871SZhang Yubing 		/*
14366027c871SZhang Yubing 		 * rgb2yuv: output = M0 * T * M1,
14376027c871SZhang Yubing 		 * so output = hue_matrix * saturation_matrix * T *
14386027c871SZhang Yubing 		 * gain_matrix * contrast_matrix
14396027c871SZhang Yubing 		 */
14406027c871SZhang Yubing 		csc_matrix_multiply(&temp0, csc_mode_cfg->pst_csc_coef, &gain_matrix);
14418b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp0, PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH -
14426027c871SZhang Yubing 					       PQ_CALC_ENHANCE_BIT);
14436027c871SZhang Yubing 		csc_matrix_multiply(&temp1, &temp0, &contrast_matrix);
14448b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp1, PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH);
14456027c871SZhang Yubing 		csc_matrix_multiply(&temp0, &saturation_matrix, &temp1);
14468b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp0, PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH);
14476027c871SZhang Yubing 		csc_matrix_multiply(out_matrix, &hue_matrix, &temp0);
14488b59e34dSZhang Yubing 		csc_matrix_element_right_shift(out_matrix, PQ_CSC_PARAM_FIX_BIT_WIDTH +
14496027c871SZhang Yubing 					       PQ_CALC_ENHANCE_BIT);
14506027c871SZhang Yubing 
14516027c871SZhang Yubing 		dc_in_ventor.csc_offset0 = dc_in_offset;
14526027c871SZhang Yubing 		dc_in_ventor.csc_offset1 = dc_in_offset;
14536027c871SZhang Yubing 		dc_in_ventor.csc_offset2 = dc_in_offset;
14546027c871SZhang Yubing 		dc_out_ventor.csc_offset0 = brightness + dc_out_offset;
14556027c871SZhang Yubing 		dc_out_ventor.csc_offset1 = PQ_CSC_DC_IN_OUT_DEFAULT;
14566027c871SZhang Yubing 		dc_out_ventor.csc_offset2 = PQ_CSC_DC_IN_OUT_DEFAULT;
14576027c871SZhang Yubing 	} else {
14586027c871SZhang Yubing 		/*
14596027c871SZhang Yubing 		 * rgb2rgb: output = T * M1 * N_y2r * M0 * N_r2y,
14606027c871SZhang Yubing 		 * so output = T * gain_matrix * contrast_matrix *
14616027c871SZhang Yubing 		 * N_y2r * hue_matrix * saturation_matrix * N_r2y
14626027c871SZhang Yubing 		 */
14638b59e34dSZhang Yubing 		r2y_matrix = &r2y_for_r2r;
14648b59e34dSZhang Yubing 		y2r_matrix = &y2r_for_r2r;
14656027c871SZhang Yubing 
14666027c871SZhang Yubing 		csc_matrix_multiply(&temp0, &contrast_matrix, y2r_matrix);
14678b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp0, PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH -
14686027c871SZhang Yubing 					       PQ_CALC_ENHANCE_BIT);
14696027c871SZhang Yubing 		csc_matrix_multiply(&temp1, &gain_matrix, &temp0);
14708b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp1, PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH);
14716027c871SZhang Yubing 		csc_matrix_multiply(&temp0, &temp1, &hue_matrix);
14728b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp0, PQ_CSC_PARAM_FIX_BIT_WIDTH);
14736027c871SZhang Yubing 		csc_matrix_multiply(&temp1, &temp0, &saturation_matrix);
14748b59e34dSZhang Yubing 		csc_matrix_element_right_shift(&temp1, PQ_CSC_PARAM_HALF_FIX_BIT_WIDTH);
14756027c871SZhang Yubing 		csc_matrix_multiply(out_matrix, &temp1, r2y_matrix);
14768b59e34dSZhang Yubing 		csc_matrix_element_right_shift_with_simple_round(out_matrix,
14778b59e34dSZhang Yubing 			PQ_CSC_PARAM_FIX_BIT_WIDTH + PQ_CALC_ENHANCE_BIT);
14786027c871SZhang Yubing 
14796027c871SZhang Yubing 		dc_in_ventor.csc_offset0 = dc_in_offset;
14806027c871SZhang Yubing 		dc_in_ventor.csc_offset1 = dc_in_offset;
14816027c871SZhang Yubing 		dc_in_ventor.csc_offset2 = dc_in_offset;
14826027c871SZhang Yubing 		dc_out_ventor.csc_offset0 = brightness + dc_out_offset + r_offset;
14836027c871SZhang Yubing 		dc_out_ventor.csc_offset1 = brightness + dc_out_offset + g_offset;
14846027c871SZhang Yubing 		dc_out_ventor.csc_offset2 = brightness + dc_out_offset + b_offset;
14856027c871SZhang Yubing 	}
14866027c871SZhang Yubing 
14876027c871SZhang Yubing 	csc_matrix_ventor_multiply(&v, out_matrix, &dc_in_ventor);
14886027c871SZhang Yubing 	out_dc->csc_offset0 = v.csc_offset0 + dc_out_ventor.csc_offset0 *
14896027c871SZhang Yubing 			  PQ_CSC_SIMPLE_MAT_PARAM_FIX_NUM;
14906027c871SZhang Yubing 	out_dc->csc_offset1 = v.csc_offset1 + dc_out_ventor.csc_offset1 *
14916027c871SZhang Yubing 			  PQ_CSC_SIMPLE_MAT_PARAM_FIX_NUM;
14926027c871SZhang Yubing 	out_dc->csc_offset2 = v.csc_offset2 + dc_out_ventor.csc_offset2 *
14936027c871SZhang Yubing 			  PQ_CSC_SIMPLE_MAT_PARAM_FIX_NUM;
14946027c871SZhang Yubing 
14956027c871SZhang Yubing 	return 0;
14966027c871SZhang Yubing }
14976027c871SZhang Yubing 
csc_calc_default_output_coef(const struct rk_csc_mode_coef * csc_mode_cfg,struct rk_pq_csc_coef * out_matrix,struct rk_pq_csc_ventor * out_dc)14986027c871SZhang Yubing static int csc_calc_default_output_coef(const struct rk_csc_mode_coef *csc_mode_cfg,
14996027c871SZhang Yubing 					struct rk_pq_csc_coef *out_matrix,
15006027c871SZhang Yubing 					struct rk_pq_csc_ventor *out_dc)
15016027c871SZhang Yubing {
15026027c871SZhang Yubing 	const struct rk_pq_csc_coef *csc_coef;
15036027c871SZhang Yubing 	const struct rk_pq_csc_dc_coef *csc_dc_coef;
15046027c871SZhang Yubing 	struct rk_pq_csc_ventor dc_in_ventor;
15056027c871SZhang Yubing 	struct rk_pq_csc_ventor dc_out_ventor;
15066027c871SZhang Yubing 	struct rk_pq_csc_ventor v;
15076027c871SZhang Yubing 
15086027c871SZhang Yubing 	csc_coef = csc_mode_cfg->pst_csc_coef;
15096027c871SZhang Yubing 	csc_dc_coef = csc_mode_cfg->pst_csc_dc_coef;
15106027c871SZhang Yubing 
15116027c871SZhang Yubing 	out_matrix->csc_coef00 = csc_coef->csc_coef00;
15126027c871SZhang Yubing 	out_matrix->csc_coef01 = csc_coef->csc_coef01;
15136027c871SZhang Yubing 	out_matrix->csc_coef02 = csc_coef->csc_coef02;
15146027c871SZhang Yubing 	out_matrix->csc_coef10 = csc_coef->csc_coef10;
15156027c871SZhang Yubing 	out_matrix->csc_coef11 = csc_coef->csc_coef11;
15166027c871SZhang Yubing 	out_matrix->csc_coef12 = csc_coef->csc_coef12;
15176027c871SZhang Yubing 	out_matrix->csc_coef20 = csc_coef->csc_coef20;
15186027c871SZhang Yubing 	out_matrix->csc_coef21 = csc_coef->csc_coef21;
15196027c871SZhang Yubing 	out_matrix->csc_coef22 = csc_coef->csc_coef22;
15206027c871SZhang Yubing 
15216027c871SZhang Yubing 	dc_in_ventor.csc_offset0 = csc_dc_coef->csc_in_dc0;
15226027c871SZhang Yubing 	dc_in_ventor.csc_offset1 = csc_dc_coef->csc_in_dc1;
15236027c871SZhang Yubing 	dc_in_ventor.csc_offset2 = csc_dc_coef->csc_in_dc2;
15246027c871SZhang Yubing 	dc_out_ventor.csc_offset0 = csc_dc_coef->csc_out_dc0;
15256027c871SZhang Yubing 	dc_out_ventor.csc_offset1 = csc_dc_coef->csc_out_dc1;
15266027c871SZhang Yubing 	dc_out_ventor.csc_offset2 = csc_dc_coef->csc_out_dc2;
15276027c871SZhang Yubing 
15286027c871SZhang Yubing 	csc_matrix_ventor_multiply(&v, csc_coef, &dc_in_ventor);
15296027c871SZhang Yubing 	out_dc->csc_offset0 = v.csc_offset0 + dc_out_ventor.csc_offset0 *
15306027c871SZhang Yubing 			      PQ_CSC_SIMPLE_MAT_PARAM_FIX_NUM;
15316027c871SZhang Yubing 	out_dc->csc_offset1 = v.csc_offset1 + dc_out_ventor.csc_offset1 *
15326027c871SZhang Yubing 			      PQ_CSC_SIMPLE_MAT_PARAM_FIX_NUM;
15336027c871SZhang Yubing 	out_dc->csc_offset2 = v.csc_offset2 + dc_out_ventor.csc_offset2 *
15346027c871SZhang Yubing 			      PQ_CSC_SIMPLE_MAT_PARAM_FIX_NUM;
15356027c871SZhang Yubing 
15366027c871SZhang Yubing 	return 0;
15376027c871SZhang Yubing }
15386027c871SZhang Yubing 
rockchip_swap_color_channel(bool is_input_yuv,bool is_output_yuv,struct post_csc_coef * csc_simple_coef,struct rk_pq_csc_coef * out_matrix,struct rk_pq_csc_ventor * out_dc)15396027c871SZhang Yubing static void rockchip_swap_color_channel(bool is_input_yuv, bool is_output_yuv,
15406027c871SZhang Yubing 					struct post_csc_coef *csc_simple_coef,
15416027c871SZhang Yubing 					struct rk_pq_csc_coef *out_matrix,
15426027c871SZhang Yubing 					struct rk_pq_csc_ventor *out_dc)
15436027c871SZhang Yubing {
15446027c871SZhang Yubing 	struct rk_pq_csc_coef tmp_matrix;
15456027c871SZhang Yubing 	struct rk_pq_csc_ventor tmp_v;
15466027c871SZhang Yubing 
15476027c871SZhang Yubing 	if (!is_input_yuv) {
15486027c871SZhang Yubing 		memcpy(&tmp_matrix, out_matrix, sizeof(struct rk_pq_csc_coef));
15496027c871SZhang Yubing 		csc_matrix_multiply(out_matrix, &tmp_matrix, &rgb_input_swap_matrix);
15506027c871SZhang Yubing 	}
15516027c871SZhang Yubing 
15526027c871SZhang Yubing 	if (is_output_yuv) {
15536027c871SZhang Yubing 		memcpy(&tmp_matrix, out_matrix, sizeof(struct rk_pq_csc_coef));
15546027c871SZhang Yubing 		memcpy(&tmp_v, out_dc, sizeof(struct rk_pq_csc_ventor));
15556027c871SZhang Yubing 		csc_matrix_multiply(out_matrix, &yuv_output_swap_matrix, &tmp_matrix);
15566027c871SZhang Yubing 		csc_matrix_ventor_multiply(out_dc, &yuv_output_swap_matrix, &tmp_v);
15576027c871SZhang Yubing 	}
15586027c871SZhang Yubing 
15596027c871SZhang Yubing 	csc_simple_coef->csc_coef00 = out_matrix->csc_coef00;
15606027c871SZhang Yubing 	csc_simple_coef->csc_coef01 = out_matrix->csc_coef01;
15616027c871SZhang Yubing 	csc_simple_coef->csc_coef02 = out_matrix->csc_coef02;
15626027c871SZhang Yubing 	csc_simple_coef->csc_coef10 = out_matrix->csc_coef10;
15636027c871SZhang Yubing 	csc_simple_coef->csc_coef11 = out_matrix->csc_coef11;
15646027c871SZhang Yubing 	csc_simple_coef->csc_coef12 = out_matrix->csc_coef12;
15656027c871SZhang Yubing 	csc_simple_coef->csc_coef20 = out_matrix->csc_coef20;
15666027c871SZhang Yubing 	csc_simple_coef->csc_coef21 = out_matrix->csc_coef21;
15676027c871SZhang Yubing 	csc_simple_coef->csc_coef22 = out_matrix->csc_coef22;
15686027c871SZhang Yubing 	csc_simple_coef->csc_dc0 = out_dc->csc_offset0;
15696027c871SZhang Yubing 	csc_simple_coef->csc_dc1 = out_dc->csc_offset1;
15706027c871SZhang Yubing 	csc_simple_coef->csc_dc2 = out_dc->csc_offset2;
15716027c871SZhang Yubing }
15726027c871SZhang Yubing 
rockchip_calc_post_csc(struct csc_info * csc_cfg,struct post_csc_coef * csc_simple_coef,int csc_mode,bool is_input_yuv,bool is_output_yuv)15736027c871SZhang Yubing int rockchip_calc_post_csc(struct csc_info *csc_cfg, struct post_csc_coef *csc_simple_coef,
15746027c871SZhang Yubing 			   int csc_mode, bool is_input_yuv, bool is_output_yuv)
15756027c871SZhang Yubing {
15766027c871SZhang Yubing 	int ret = 0;
15776027c871SZhang Yubing 	struct rk_pq_csc_coef out_matrix;
15786027c871SZhang Yubing 	struct rk_pq_csc_ventor out_dc;
15796027c871SZhang Yubing 	const struct rk_csc_mode_coef *csc_mode_cfg;
15806027c871SZhang Yubing 	int bit_num = PQ_CSC_SIMPLE_MAT_PARAM_FIX_BIT_WIDTH;
15816027c871SZhang Yubing 
15826027c871SZhang Yubing 	ret = csc_get_mode_index(csc_mode, is_input_yuv, is_output_yuv);
15836027c871SZhang Yubing 	if (ret < 0) {
15846027c871SZhang Yubing 		printf("invalid csc_mode:%d\n", csc_mode);
15856027c871SZhang Yubing 		return ret;
15866027c871SZhang Yubing 	}
15876027c871SZhang Yubing 
15886027c871SZhang Yubing 	csc_mode_cfg = &g_mode_csc_coef[ret];
15896027c871SZhang Yubing 
15906027c871SZhang Yubing 	if (csc_cfg)
15916027c871SZhang Yubing 		ret = csc_calc_adjust_output_coef(is_input_yuv, is_output_yuv, csc_cfg,
15926027c871SZhang Yubing 						  csc_mode_cfg, &out_matrix, &out_dc);
15936027c871SZhang Yubing 	else
15946027c871SZhang Yubing 		ret = csc_calc_default_output_coef(csc_mode_cfg, &out_matrix, &out_dc);
15956027c871SZhang Yubing 
15966027c871SZhang Yubing 	rockchip_swap_color_channel(is_input_yuv, is_output_yuv, csc_simple_coef, &out_matrix,
15976027c871SZhang Yubing 				    &out_dc);
15986027c871SZhang Yubing 
15998b59e34dSZhang Yubing 	csc_simple_coef->csc_dc0 = csc_simple_round(csc_simple_coef->csc_dc0, bit_num);
16008b59e34dSZhang Yubing 	csc_simple_coef->csc_dc1 = csc_simple_round(csc_simple_coef->csc_dc1, bit_num);
16018b59e34dSZhang Yubing 	csc_simple_coef->csc_dc2 = csc_simple_round(csc_simple_coef->csc_dc2, bit_num);
16026027c871SZhang Yubing 	csc_simple_coef->range_type = csc_mode_cfg->st_csc_color_info.out_full_range;
16036027c871SZhang Yubing 
16046027c871SZhang Yubing 	return ret;
16056027c871SZhang Yubing }
1606