diff --git a/drivers/amlogic/media/enhancement/amvecm/amcsc.c b/drivers/amlogic/media/enhancement/amvecm/amcsc.c index b60cd5123776..bf503aea716b 100644 --- a/drivers/amlogic/media/enhancement/amvecm/amcsc.c +++ b/drivers/amlogic/media/enhancement/amvecm/amcsc.c @@ -47,6 +47,8 @@ signed int vd1_contrast_offset; signed int saturation_offset; +static void vpp_set_mtx_en_write(void); + struct hdr_osd_reg_s hdr_osd_reg = { 0x00000001, /* VIU_OSD1_MATRIX_CTRL 0x1a90 */ 0x00ba0273, /* VIU_OSD1_MATRIX_COEF00_01 0x1a91 */ @@ -128,6 +130,8 @@ struct hdr_osd_reg_s hdr_osd_reg = { -1 /* shadow mode */ }; +#define HDR_VERSION "----v4_20180516-----\n" + static struct vframe_s *dbg_vf; static struct master_display_info_s dbg_hdr_send; static struct hdr_info receiver_hdr_info; @@ -185,6 +189,17 @@ static uint cur_hdr_process_mode = 2; /* 0: hdr->hdr, 1:hdr->sdr */ module_param(hdr_process_mode, uint, 0444); MODULE_PARM_DESC(hdr_process_mode, "\n current hdr_process_mode\n"); +/* 0: hlg->hlg, 1:hlg->hdr*/ +static uint hlg_process_mode = 1; +/* 0: hdr->hdr, 1:hdr->sdr 2:hlg->hdr*/ +static uint cur_hlg_process_mode = 2; +module_param(hlg_process_mode, uint, 0444); +MODULE_PARM_DESC(hlg_process_mode, "\n current hlg_process_mode\n"); + +static uint force_pure_hlg; +module_param(force_pure_hlg, uint, 0664); +MODULE_PARM_DESC(force_pure_hlg, "\n current force_pure_hlg\n"); + uint sdr_mode; /* 0: sdr->sdr, 1:sdr->hdr, 2:auto */ static uint sdr_process_mode = 2; /* 0: sdr->sdr, 1:sdr->hdr */ static uint cur_sdr_process_mode = 2; /* 0: sdr->sdr, 1:sdr->hdr */ @@ -204,6 +219,10 @@ static uint cur_hdr_support; module_param(cur_hdr_support, uint, 0664); MODULE_PARM_DESC(cur_hdr_support, "\n cur_hdr_support\n"); +static uint cur_hlg_support; +module_param(cur_hlg_support, uint, 0664); +MODULE_PARM_DESC(cur_hlg_support, "\n cur_hlg_support\n"); + static uint cur_output_mode; module_param(cur_output_mode, uint, 0664); MODULE_PARM_DESC(cur_output_mode, "\n cur_output_mode\n"); @@ -1167,6 +1186,84 @@ static int YUV709l_to_RGB709_coeff[MATRIX_5x3_COEF_SIZE] = { 0, 0, 0 /* mode, right_shift, clip_en */ }; +static int YUV709f_to_RGB709_coeff[MATRIX_5x3_COEF_SIZE] = { + 0, -512, -512, /* pre offset */ + COEFF_NORM(1.0), COEFF_NORM(0.00000), COEFF_NORM(1.575), + COEFF_NORM(1.0), COEFF_NORM(-0.187), COEFF_NORM(-0.468), + COEFF_NORM(1.0), COEFF_NORM(1.856), COEFF_NORM(0.00000), + 0, 0, 0, /* 30/31/32 */ + 0, 0, 0, /* 40/41/42 */ + 0, 0, 0, /* offset */ + 0, 0, 0 /* mode, right_shift, clip_en */ +}; + +static int YUV601l_to_YUV709l_coeff[MATRIX_5x3_COEF_SIZE] = { + -64, -512, -512, /* pre offset */ + COEFF_NORM(1.0), COEFF_NORM(-0.115), COEFF_NORM(-0.207), + COEFF_NORM(0), COEFF_NORM(1.018), COEFF_NORM(0.114), + COEFF_NORM(0), COEFF_NORM(0.075), COEFF_NORM(1.025), + 0, 0, 0, /* 30/31/32 */ + 0, 0, 0, /* 40/41/42 */ + 64, 512, 512, /* offset */ + 0, 0, 0 /* mode, right_shift, clip_en */ +}; + +static int YUV601f_to_YUV709f_coeff[MATRIX_5x3_COEF_SIZE] = { + 0, -512, -512, /* pre offset */ + COEFF_NORM(1.00000), COEFF_NORM(-0.118), COEFF_NORM(-0.212), + COEFF_NORM(0.00000), COEFF_NORM(1.018), COEFF_NORM(0.114), + COEFF_NORM(0.00000), COEFF_NORM(0.075), COEFF_NORM(1.025), + 0, 0, 0, /* 30/31/32 */ + 0, 0, 0, /* 40/41/42 */ + 0, 512, 512, /* offset */ + 0, 0, 0 /* mode, right_shift, clip_en */ +}; + +static int YUV709l_to_YUV601l_coeff[MATRIX_5x3_COEF_SIZE] = { + -64, -512, -512, /* pre offset */ + COEFF_NORM(1.0), COEFF_NORM(0.1), COEFF_NORM(0.192), + COEFF_NORM(0), COEFF_NORM(0.990), COEFF_NORM(-0.110), + COEFF_NORM(0), COEFF_NORM(-0.072), COEFF_NORM(0.984), + 0, 0, 0, /* 30/31/32 */ + 0, 0, 0, /* 40/41/42 */ + 64, 512, 512, /* offset */ + 0, 0, 0 /* mode, right_shift, clip_en */ +}; + +static int YUV601l_to_YUV709f_coeff[MATRIX_5x3_COEF_SIZE] = { + -64, -512, -512, /* pre offset */ + COEFF_NORM(1.164), COEFF_NORM(-0.134), COEFF_NORM(-0.241), + COEFF_NORM(0), COEFF_NORM(1.160), COEFF_NORM(-0.129), + COEFF_NORM(0), COEFF_NORM(-0.085), COEFF_NORM(1.167), + 0, 0, 0, /* 30/31/32 */ + 0, 0, 0, /* 40/41/42 */ + 0, 512, 512, /* offset */ + 0, 0, 0 /* mode, right_shift, clip_en */ +}; + +static int YUV601f_to_YUV709l_coeff[MATRIX_5x3_COEF_SIZE] = { + 0, -512, -512, /* pre offset */ + COEFF_NORM(0.859), COEFF_NORM(-0.101), COEFF_NORM(-0.182), + COEFF_NORM(0), COEFF_NORM(0.894), COEFF_NORM(-0.100), + COEFF_NORM(0), COEFF_NORM(-0.066), COEFF_NORM(0.900), + 0, 0, 0, /* 30/31/32 */ + 0, 0, 0, /* 40/41/42 */ + 64, 512, 512, /* offset */ + 0, 0, 0 /* mode, right_shift, clip_en */ +}; + +#if 0 +static int YUV709f_to_YUV601f_coeff[MATRIX_5x3_COEF_SIZE] = { + 0, -512, -512, /* pre offset */ + COEFF_NORM(1.00000), COEFF_NORM(0.08835), COEFF_NORM(0.37521), + COEFF_NORM(0.00000), COEFF_NORM(1.03570), COEFF_NORM(-0.20445), + COEFF_NORM(0.00000), COEFF_NORM(-0.11088), COEFF_NORM(1.57010), + 0, 0, 0, /* 30/31/32 */ + 0, 0, 0, /* 40/41/42 */ + 0, 512, 512, /* offset */ + 0, 0, 0 /* mode, right_shift, clip_en */ +}; +#endif #if 0 /* eotf matrix: RGB2020 to RGB709 */ static int eotf_RGB2020_to_RGB709_coeff[EOTF_COEFF_SIZE] = { @@ -1325,6 +1422,25 @@ static unsigned int osd_oetf_41_2084_mapping[OSD_OETF_LUT_SIZE] = { 1023 }; +/* osd eotf lut: sdr->hlg */ +static unsigned int osd_eotf_33_sdr2hlg_mapping[EOTF_LUT_SIZE] = { + 0, 512, 1024, 1536, 2048, 2560, 3072, 3584, + 4096, 4608, 5120, 5632, 6144, 6656, 7168, 7680, + 8192, 8704, 9216, 9728, 10240, 10752, 11264, 11776, + 12288, 12800, 13312, 13824, 14336, 14848, 15360, 15872, + 16383 +}; + +/* osd oetf lut: sdr->hlg */ +static unsigned int osd_oetf_41_sdr2hlg_mapping[OSD_OETF_LUT_SIZE] = { + 0, 23, 36, 43, 49, 54, 59, 64, + 69, 96, 127, 172, 218, 267, 316, 365, + 415, 468, 519, 567, 607, 643, 676, 706, + 733, 758, 782, 805, 826, 847, 866, 885, + 903, 920, 936, 951, 965, 980, 994, 1009, + 1023 +}; + /* sdr eotf lut: 709 */ static unsigned int eotf_33_sdr_709_mapping[EOTF_LUT_SIZE] = { 0, 512, 1024, 1536, 2048, 2560, 3072, 3584, @@ -1429,6 +1545,16 @@ static unsigned int oetf_289_2084_mapping[VIDEO_OETF_LUT_SIZE] = { 1023 }; +static int dvll_RGB_to_YUV709l_coeff[MATRIX_5x3_COEF_SIZE] = { + 0, 0, 0, /* pre offset */ + COEFF_NORM(0.181873), COEFF_NORM(0.611831), COEFF_NORM(0.061765), + COEFF_NORM(-0.100251), COEFF_NORM(-0.337249), COEFF_NORM(0.437500), + COEFF_NORM(0.437500), COEFF_NORM(-0.397384), COEFF_NORM(-0.040116), + 0, 0, 0, /* 10'/11'/12' */ + 0, 0, 0, /* 20'/21'/22' */ + 64, 512, 512, /* offset */ + 0, 0, 0 /* mode, right_shift, clip_en */ +}; /*static unsigned int oetf_289_709_mapping[VIDEO_OETF_LUT_SIZE] = {*/ /* 0, 0, 0, 0, 0, 0, 0, 0,*/ /* 0, 0, 0, 0, 0, 0, 0, 0,*/ @@ -1646,6 +1772,8 @@ static void print_vpp_matrix(int m_select, int *s, int on) } static int *cur_osd_mtx = RGB709_to_YUV709l_coeff; +static int *cur_post_mtx = bypass_coeff; +static int cur_post_on = CSC_OFF; void set_vpp_matrix(int m_select, int *s, int on) { int *m = NULL; @@ -1661,6 +1789,8 @@ void set_vpp_matrix(int m_select, int *s, int on) } else if (m_select == VPP_MATRIX_POST) { m = post_matrix_coeff; size = MATRIX_5x3_COEF_SIZE; + cur_post_mtx = s; + cur_post_on = on; } else if (m_select == VPP_MATRIX_VD1) { m = vd1_matrix_coeff; size = MATRIX_5x3_COEF_SIZE; @@ -1689,7 +1819,9 @@ void set_vpp_matrix(int m_select, int *s, int on) if (m_select == VPP_MATRIX_OSD) { /* osd matrix, VPP_MATRIX_0 */ - if (!is_meson_txlx_cpu()) { + if (!is_meson_txlx_cpu() && + !is_meson_gxlx_cpu() && + !is_meson_txhd_cpu()) { /* not enable latched */ hdr_osd_reg.viu_osd1_matrix_pre_offset0_1 = ((m[0] & 0xfff) << 16) | (m[1] & 0xfff); @@ -1734,57 +1866,132 @@ void set_vpp_matrix(int m_select, int *s, int on) } else { /* move the matrix from osd to vpp in txlx */ m = osd_matrix_coeff; - - if (on) { - reg_value = (reg_value & (~(7 << 8))) - | (4 << 8); - VSYNC_WR_MPEG_REG(VPP_MATRIX_CTRL, - reg_value); - VSYNC_WR_MPEG_REG(VPP_MATRIX_PRE_OFFSET0_1, - ((m[0] & 0xfff) << 16) - | (m[1] & 0xfff)); - VSYNC_WR_MPEG_REG(VPP_MATRIX_PRE_OFFSET2, - m[2] & 0xfff); - VSYNC_WR_MPEG_REG(VPP_MATRIX_COEF00_01, - ((m[3] & 0x1fff) << 16) - | (m[4] & 0x1fff)); - VSYNC_WR_MPEG_REG(VPP_MATRIX_COEF02_10, - ((m[5] & 0x1fff) << 16) - | (m[6] & 0x1fff)); - VSYNC_WR_MPEG_REG(VPP_MATRIX_COEF11_12, - ((m[7] & 0x1fff) << 16) - | (m[8] & 0x1fff)); - VSYNC_WR_MPEG_REG(VPP_MATRIX_COEF20_21, - ((m[9] & 0x1fff) << 16) - | (m[10] & 0x1fff)); - VSYNC_WR_MPEG_REG(VPP_MATRIX_COEF22, - m[11] & 0x1fff); - if (m[21]) { - VSYNC_WR_MPEG_REG(VPP_MATRIX_COEF13_14, - ((m[12] & 0x1fff) << 16) - | (m[13] & 0x1fff)); - VSYNC_WR_MPEG_REG(VPP_MATRIX_COEF15_25, - ((m[14] & 0x1fff) << 16) - | (m[17] & 0x1fff)); - VSYNC_WR_MPEG_REG(VPP_MATRIX_COEF23_24, - ((m[15] & 0x1fff) << 16) - | (m[16] & 0x1fff)); + if (is_meson_gxlx_cpu()) { + if (on) { + /*VSYNC_WR_MPEG_REG_BITS(*/ + /*VPP_MATRIX_CTRL,*/ + /*4, 8, 3);*/ + VSYNC_WR_MPEG_REG( + VIU_OSD1_MATRIX_PRE_OFFSET0_1, + ((m[0] & 0xfff) << 16) + | (m[1] & 0xfff)); + VSYNC_WR_MPEG_REG( + VIU_OSD1_MATRIX_PRE_OFFSET2, + m[2] & 0xfff); + VSYNC_WR_MPEG_REG( + VIU_OSD1_MATRIX_COEF00_01, + ((m[3] & 0x1fff) << 16) + | (m[4] & 0x1fff)); + VSYNC_WR_MPEG_REG( + VIU_OSD1_MATRIX_COEF02_10, + ((m[5] & 0x1fff) << 16) + | (m[6] & 0x1fff)); + VSYNC_WR_MPEG_REG( + VIU_OSD1_MATRIX_COEF11_12, + ((m[7] & 0x1fff) << 16) + | (m[8] & 0x1fff)); + VSYNC_WR_MPEG_REG( + VIU_OSD1_MATRIX_COEF20_21, + ((m[9] & 0x1fff) << 16) + | (m[10] & 0x1fff)); + VSYNC_WR_MPEG_REG( + VIU_OSD1_MATRIX_COLMOD_COEF42, + m[11] & 0x1fff); + VSYNC_WR_MPEG_REG( + VIU_OSD1_MATRIX_OFFSET0_1, + ((m[18] & 0xfff) << 16) + | (m[19] & 0xfff)); + VSYNC_WR_MPEG_REG( + VIU_OSD1_MATRIX_OFFSET2, + m[20] & 0xfff); } - VSYNC_WR_MPEG_REG(VPP_MATRIX_OFFSET0_1, - ((m[18] & 0xfff) << 16) - | (m[19] & 0xfff)); - VSYNC_WR_MPEG_REG(VPP_MATRIX_OFFSET2, - m[20] & 0xfff); - VSYNC_WR_MPEG_REG_BITS(VPP_MATRIX_CLIP, - m[21], 3, 2); - VSYNC_WR_MPEG_REG_BITS(VPP_MATRIX_CLIP, - m[22], 5, 3); + /*VSYNC_WR_MPEG_REG_BITS(VPP_MATRIX_CTRL,*/ + /*on, 7, 1);*/ + VSYNC_WR_MPEG_REG_BITS( + VIU_OSD1_MATRIX_CTRL, + on, 0, 1); + } else { + if (on) { + /*VSYNC_WR_MPEG_REG_BITS(*/ + /*VPP_MATRIX_CTRL,*/ + /*4, 8, 3);*/ + reg_value = (reg_value & + (~(7 << 8))) + | (4 << 8); + VSYNC_WR_MPEG_REG(VPP_MATRIX_CTRL, + reg_value); + VSYNC_WR_MPEG_REG( + VPP_MATRIX_PRE_OFFSET0_1, + ((m[0] & 0xfff) << 16) + | (m[1] & 0xfff)); + VSYNC_WR_MPEG_REG( + VPP_MATRIX_PRE_OFFSET2, + m[2] & 0xfff); + VSYNC_WR_MPEG_REG( + VPP_MATRIX_COEF00_01, + ((m[3] & 0x1fff) << 16) + | (m[4] & 0x1fff)); + VSYNC_WR_MPEG_REG( + VPP_MATRIX_COEF02_10, + ((m[5] & 0x1fff) << 16) + | (m[6] & 0x1fff)); + VSYNC_WR_MPEG_REG( + VPP_MATRIX_COEF11_12, + ((m[7] & 0x1fff) << 16) + | (m[8] & 0x1fff)); + VSYNC_WR_MPEG_REG( + VPP_MATRIX_COEF20_21, + ((m[9] & 0x1fff) << 16) + | (m[10] & 0x1fff)); + VSYNC_WR_MPEG_REG( + VPP_MATRIX_COEF22, + m[11] & 0x1fff); + if (m[21]) { + VSYNC_WR_MPEG_REG( + VPP_MATRIX_COEF13_14, + ((m[12] & 0x1fff) << 16) + | (m[13] & 0x1fff)); + VSYNC_WR_MPEG_REG( + VPP_MATRIX_COEF15_25, + ((m[14] & 0x1fff) << 16) + | (m[17] & 0x1fff)); + VSYNC_WR_MPEG_REG( + VPP_MATRIX_COEF23_24, + ((m[15] & 0x1fff) << 16) + | (m[16] & 0x1fff)); + } + if (is_meson_txhd_cpu()) { + VSYNC_WR_MPEG_REG( + VPP_MATRIX_OFFSET0_1, + (((m[18]>>2)&0xfff)<<16) + | ((m[19]>>2)&0xfff)); + VSYNC_WR_MPEG_REG( + VPP_MATRIX_OFFSET2, + (m[20] >> 2) & 0xfff); + } else { + VSYNC_WR_MPEG_REG( + VPP_MATRIX_OFFSET0_1, + ((m[18] & 0xfff) << 16) + | (m[19] & 0xfff)); + VSYNC_WR_MPEG_REG( + VPP_MATRIX_OFFSET2, + m[20] & 0xfff); + } + + VSYNC_WR_MPEG_REG_BITS( + VPP_MATRIX_CLIP, + m[21], 3, 2); + VSYNC_WR_MPEG_REG_BITS( + VPP_MATRIX_CLIP, + m[22], 5, 3); + } + /*VSYNC_WR_MPEG_REG_BITS(VPP_MATRIX_CTRL,*/ + /*on, 7, 1);*/ + if (on) + mtx_en_mux |= OSD1_MTX_EN_MASK; + else + mtx_en_mux &= ~OSD1_MTX_EN_MASK; } - /*VSYNC_WR_MPEG_REG_BITS(VPP_MATRIX_CTRL, on, 7, 1);*/ - if (on) - mtx_en_mux |= OSD1_MTX_EN_MASK; - else - mtx_en_mux &= ~OSD1_MTX_EN_MASK; } } else if (m_select == VPP_MATRIX_EOTF) { /* eotf matrix, VPP_MATRIX_EOTF */ @@ -1793,7 +2000,9 @@ void set_vpp_matrix(int m_select, int *s, int on) VSYNC_WR_MPEG_REG(VIU_EOTF_CTL + i + 1, ((m[i * 2] & 0x1fff) << 16) | (m[i * 2 + 1] & 0x1fff)); - if (is_meson_txlx_cpu()) { + if (is_meson_txlx_cpu() || + is_meson_gxlx_cpu() || + is_meson_txhd_cpu()) { VSYNC_WR_MPEG_REG(VIU_EOTF_CTL + 8, 0); VSYNC_WR_MPEG_REG(VIU_EOTF_CTL + 9, 0); } @@ -1801,7 +2010,9 @@ void set_vpp_matrix(int m_select, int *s, int on) WRITE_VPP_REG_BITS(VIU_EOTF_CTL, on, 31, 1); } else if (m_select == VPP_MATRIX_OSD_EOTF) { /* osd eotf matrix, VPP_MATRIX_OSD_EOTF */ - if (!is_meson_txlx_cpu()) { + if (!is_meson_txlx_cpu() && + !is_meson_gxlx_cpu() && + !is_meson_txhd_cpu()) { /* enable latched */ hdr_osd_reg.viu_osd1_eotf_coef00_01 = ((m[0 * 2] & 0x1fff) << 16) @@ -1986,11 +2197,21 @@ void set_vpp_matrix(int m_select, int *s, int on) ((m[15] & 0x1fff) << 16) | (m[16] & 0x1fff)); } - VSYNC_WR_MPEG_REG(VPP_MATRIX_OFFSET0_1, - ((m[18] & 0xfff) << 16) - | (m[19] & 0xfff)); - VSYNC_WR_MPEG_REG(VPP_MATRIX_OFFSET2, - m[20] & 0xfff); + if (is_meson_txhd_cpu() && + (m_select == VPP_MATRIX_XVYCC)) { + VSYNC_WR_MPEG_REG(VPP_MATRIX_OFFSET0_1, + (((m[18] >> 2) & 0xfff) << 16) + | ((m[19] >> 2) & 0xfff)); + VSYNC_WR_MPEG_REG( + VPP_MATRIX_OFFSET2, + (m[20] >> 2) & 0xfff); + } else { + VSYNC_WR_MPEG_REG(VPP_MATRIX_OFFSET0_1, + ((m[18] & 0xfff) << 16) + | (m[19] & 0xfff)); + VSYNC_WR_MPEG_REG(VPP_MATRIX_OFFSET2, + m[20] & 0xfff); + } VSYNC_WR_MPEG_REG_BITS(VPP_MATRIX_CLIP, m[21], 3, 2); VSYNC_WR_MPEG_REG_BITS(VPP_MATRIX_CLIP, @@ -2026,11 +2247,20 @@ void set_vpp_matrix(int m_select, int *s, int on) ((m[15] & 0x1fff) << 16) | (m[16] & 0x1fff)); } - WRITE_VPP_REG(VPP_MATRIX_OFFSET0_1, - ((m[18] & 0xfff) << 16) - | (m[19] & 0xfff)); - WRITE_VPP_REG(VPP_MATRIX_OFFSET2, - m[20] & 0xfff); + if (is_meson_txhd_cpu() && + (m_select == VPP_MATRIX_XVYCC)) { + WRITE_VPP_REG(VPP_MATRIX_OFFSET0_1, + (((m[18] >> 2) & 0xfff) << 16) + | ((m[19] >> 2) & 0xfff)); + WRITE_VPP_REG(VPP_MATRIX_OFFSET2, + (m[20] >> 2) & 0xfff); + } else { + WRITE_VPP_REG(VPP_MATRIX_OFFSET0_1, + ((m[18] & 0xfff) << 16) + | (m[19] & 0xfff)); + WRITE_VPP_REG(VPP_MATRIX_OFFSET2, + m[20] & 0xfff); + } WRITE_VPP_REG_BITS(VPP_MATRIX_CLIP, m[21], 3, 2); WRITE_VPP_REG_BITS(VPP_MATRIX_CLIP, @@ -2063,6 +2293,91 @@ void enable_osd_path(int on, int shadow_mode) } EXPORT_SYMBOL(enable_osd_path); +/* coeff: pointer to target coeff array */ +/* bits: how many bits for target coeff, could be 10 ~ 12, default 10 */ +static int32_t *post_mtx_backup; +static int32_t post_on_backup; +static bool restore_post_table; +int enable_rgb_to_yuv_matrix_for_dvll( + int32_t on, uint32_t *coeff_orig, uint32_t bits) +{ + int32_t i; + uint32_t coeff01, coeff23, coeff45, coeff67, coeff89; + uint32_t scale, shift, offset[3]; + int32_t *coeff = dvll_RGB_to_YUV709l_coeff; + + if ((bits < 10) || (bits > 12)) + return -1; + if (on && !coeff_orig) + return -2; + if (on) { + /* only store the start one */ + if (cur_post_mtx != + dvll_RGB_to_YUV709l_coeff) { + post_mtx_backup = cur_post_mtx; + post_on_backup = cur_post_on; + } + coeff01 = coeff_orig[0]; + coeff23 = coeff_orig[1]; + coeff45 = coeff_orig[2]; + coeff67 = coeff_orig[3]; + coeff89 = coeff_orig[4] & 0xffff; + scale = (coeff_orig[4] >> 16) & 0x0f; + offset[0] = coeff_orig[5]; + offset[1] = 0; /* coeff_orig[6]; */ + offset[2] = 0; /* coeff_orig[7]; */ + + coeff[0] = coeff[1] = coeff[2] = 0; /* pre offset */ + + coeff[5] = (int32_t)((coeff01 & 0xffff) << 16) >> 16; + coeff[3] = (int32_t)coeff01 >> 16; + coeff[4] = (int32_t)((coeff23 & 0xffff) << 16) >> 16; + coeff[8] = (int32_t)coeff23 >> 16; + coeff[6] = (int32_t)((coeff45 & 0xffff) << 16) >> 16; + coeff[7] = (int32_t)coeff45 >> 16; + coeff[11] = (int32_t)((coeff67 & 0xffff) << 16) >> 16; + coeff[9] = (int32_t)coeff67 >> 16; + coeff[10] = (int32_t)((coeff89 & 0xffff) << 16) >> 16; + + if (scale > 12) { + shift = scale - 12; + for (i = 3; i < 12; i++) + coeff[i] = + (coeff[i] + (1 << (shift - 1))) + >> shift; + } else if (scale < 12) { + shift = 12 - scale; + for (i = 3; i < 12; i++) + coeff[i] <<= shift; + } + + /* post offset */ + coeff[18] = offset[0]; + coeff[19] = offset[1]; + coeff[20] = offset[2]; + + coeff[5] = + ((coeff[3] + coeff[4] + coeff[5]) & 0xfffe) + - coeff[3] - coeff[4]; + coeff[8] = 0 - coeff[6] - coeff[7]; + coeff[11] = 0 - coeff[9] - coeff[10]; + coeff[18] -= (0x1000 - coeff[3] - coeff[4] - coeff[5]) >> 1; + + coeff[22] = 2; + set_vpp_matrix(VPP_MATRIX_POST, + coeff, CSC_ON); + vpp_set_mtx_en_write(); + restore_post_table = true; + } else if (restore_post_table) { + set_vpp_matrix(VPP_MATRIX_POST, + post_mtx_backup, post_on_backup); + vpp_set_mtx_en_write(); + restore_post_table = false; + } + return 0; +} +EXPORT_SYMBOL(enable_rgb_to_yuv_matrix_for_dvll); + const char lut_name[NUM_LUT][16] = { "OSD_EOTF", "OSD_OETF", @@ -2322,11 +2637,14 @@ void set_vpp_lut( WRITE_VPP_REG_BITS(VIU_OSD1_OETF_CTL, 1, 28, 1); if (on) { /* change to 12bit from txlx */ - for (i = 0; i < OSD_OETF_LUT_SIZE; i++) { - r_map[i] = 4 * r_map[i]; - g_map[i] = 4 * g_map[i]; - b_map[i] = 4 * b_map[i]; - } + if (is_meson_txlx_cpu()) + for (i = 0; + i < OSD_OETF_LUT_SIZE; + i++) { + r_map[i] = 4 * r_map[i]; + g_map[i] = 4 * g_map[i]; + b_map[i] = 4 * b_map[i]; + } for (i = 0; i < 20; i++) { VSYNC_WR_MPEG_REG(addr_port, i); VSYNC_WR_MPEG_REG(data_port, @@ -2370,7 +2688,9 @@ void set_vpp_lut( for (i = 0; i < EOTF_LUT_SIZE; i++) b_map[i] = b[i]; - if (!is_meson_txlx_cpu()) { + if (!is_meson_txlx_cpu() && + !is_meson_gxlx_cpu() && + !is_meson_txhd_cpu()) { for (i = 0; i < EOTF_LUT_SIZE; i++) { hdr_osd_reg.lut_val.r_map[i] = r_map[i]; hdr_osd_reg.lut_val.g_map[i] = g_map[i]; @@ -2426,7 +2746,9 @@ void set_vpp_lut( for (i = 0; i < EOTF_LUT_SIZE; i++) b_map[i] = b[i]; /*txlx add eotf latch ctl bit 26*/ - if (is_meson_txlx_cpu()) + if (is_meson_txlx_cpu() || + is_meson_gxlx_cpu() || + is_meson_txhd_cpu()) WRITE_VPP_REG_BITS(ctrl_port, 1, 26, 1); if (on) { @@ -2585,97 +2907,6 @@ static void vpp_set_mtx_en_read(void) OSD1_MTX_EN_MASK); } -/* dvll output 12bit */ -static int dvll_RGB_to_YUV709l_coeff[MATRIX_5x3_COEF_SIZE] = { - 0, 0, 0, /* pre offset */ - COEFF_NORM(0.181873), COEFF_NORM(0.611831), COEFF_NORM(0.061765), - COEFF_NORM(-0.100251), COEFF_NORM(-0.337249), COEFF_NORM(0.437500), - COEFF_NORM(0.437500), COEFF_NORM(-0.397384), COEFF_NORM(-0.040116), - 0, 0, 0, /* 10'/11'/12' */ - 0, 0, 0, /* 20'/21'/22' */ - 64, 512, 512, /* offset */ - 0, 0, 0 /* mode, right_shift, clip_en */ -}; -static int *cur_post_mtx = bypass_coeff; -static int cur_post_on = CSC_OFF; -static int32_t *post_mtx_backup; -static int32_t post_on_backup; -static bool restore_post_table; -/* coeff: pointer to target coeff array */ -/* bits: how many bits for target coeff, could be 10 ~ 12, default 10 */ -int enable_rgb_to_yuv_matrix_for_dvll( - int32_t on, uint32_t *coeff_orig, uint32_t bits) -{ - int32_t i, j; - uint32_t coeff01, coeff23, coeff45, coeff67; - uint32_t coeff8, scale, shift, offset[3]; - int32_t *coeff = dvll_RGB_to_YUV709l_coeff; - - if ((bits < 10) || (bits > 12)) - return -1; - if (on && !coeff_orig) - return -2; - if (on) { - /* only store the start one */ - if (cur_post_mtx != - dvll_RGB_to_YUV709l_coeff) { - post_mtx_backup = cur_post_mtx; - post_on_backup = cur_post_on; - } - coeff01 = coeff_orig[0]; - coeff23 = coeff_orig[1]; - coeff45 = coeff_orig[2]; - coeff67 = coeff_orig[3]; - coeff8 = coeff_orig[4] & 0xffff; - scale = (coeff_orig[4] >> 16) & 0x0f; - offset[0] = 0; /* coeff_orig[5]; */ - offset[1] = 0; /* coeff_orig[6]; */ - offset[2] = 0; /* coeff_orig[7]; */ - if (scale >= bits) { - shift = scale - bits; - coeff[5] = (coeff01 & 0xffff) >> shift; - coeff[3] = ((coeff01 >> 16) & 0xffff) >> shift; - coeff[4] = (coeff23 & 0xffff) >> shift; - coeff[8] = ((coeff23 >> 16) & 0xffff) >> shift; - coeff[6] = (coeff45 & 0xffff) >> shift; - coeff[7] = ((coeff45 >> 16) & 0xffff) >> shift; - coeff[11] = (coeff67 & 0xffff) >> shift; - coeff[9] = ((coeff67 >> 16) & 0xffff) >> shift; - coeff[10] = (coeff8 & 0xffff) >> shift; - } else { - shift = bits - scale; - coeff[5] = (coeff01 & 0xffff) << shift; - coeff[3] = ((coeff01 >> 16) & 0xffff) << shift; - coeff[4] = (coeff23 & 0xffff) << shift; - coeff[8] = ((coeff23 >> 16) & 0xffff) << shift; - coeff[6] = (coeff45 & 0xffff) << shift; - coeff[7] = ((coeff45 >> 16) & 0xffff) << shift; - coeff[11] = (coeff67 & 0xffff) << shift; - coeff[9] = ((coeff67 >> 16) & 0xffff) << shift; - coeff[10] = (coeff8 & 0xffff) << shift; - } - coeff[18] = offset[0] >> (12 - bits); - coeff[19] = offset[1] >> (12 - bits); - coeff[20] = offset[2] >> (12 - bits); - for (i = 3; i < 12; i++) { - if (coeff[i] & (1 << bits)) - for (j = bits + 1; j <= 12; j++) - coeff[i] |= 1 << j; - } - coeff[22] = bits - 10; - set_vpp_matrix(VPP_MATRIX_POST, - coeff, CSC_ON); - vpp_set_mtx_en_write(); - restore_post_table = true; - } else if (restore_post_table) { - set_vpp_matrix(VPP_MATRIX_POST, - post_mtx_backup, post_on_backup); - vpp_set_mtx_en_write(); - restore_post_table = false; - } - return 0; -} -EXPORT_SYMBOL(enable_rgb_to_yuv_matrix_for_dvll); static void vpp_set_matrix( enum vpp_matrix_sel_e vd1_or_vd2_or_post, unsigned int on, @@ -2690,7 +2921,8 @@ static void vpp_set_matrix( if (vd1_or_vd2_or_post == VPP_MATRIX_VD1) { /* vd1 matrix */ - reg_value = (reg_value & (~(7 << 8))) | (1 << 8); + reg_value = (reg_value & (~(7 << 8))) | + (1 << 8); VSYNC_WR_MPEG_REG(VPP_MATRIX_CTRL, reg_value); if (on) @@ -2699,7 +2931,8 @@ static void vpp_set_matrix( mtx_en_mux &= ~VD1_MTX_EN_MASK; } else if (vd1_or_vd2_or_post == VPP_MATRIX_VD2) { /* vd2 matrix */ - reg_value = (reg_value & (~(7 << 8))) | (2 << 8); + reg_value = (reg_value & (~(7 << 8))) | + (2 << 8); VSYNC_WR_MPEG_REG(VPP_MATRIX_CTRL, reg_value); if (on) @@ -2708,7 +2941,8 @@ static void vpp_set_matrix( mtx_en_mux &= ~VD2_MTX_EN_MASK; } else { /* post matrix */ - reg_value = (reg_value & (~(7 << 8))) | (0 << 8); + reg_value = (reg_value & (~(7 << 8))) | + (0 << 8); VSYNC_WR_MPEG_REG(VPP_MATRIX_CTRL, reg_value); if (on) @@ -2941,7 +3175,46 @@ static struct vframe_master_display_colour_s cur_master_display_colour = { #define SIG_HDR_MODE 0x10 #define SIG_HDR_SUPPORT 0x20 #define SIG_WB_CHG 0x40 +#define SIG_HLG_MODE 0x80 +#define SIG_HLG_SUPPORT 0x100 #define SIG_OP_CHG 0x200 +#define SIG_SRC_OUTPUT_CHG 0x400/*for box*/ + +unsigned int pre_vd1_mtx_sel = VPP_MATRIX_NULL; +module_param(pre_vd1_mtx_sel, uint, 0664); +MODULE_PARM_DESC(pre_vd1_mtx_sel, "\n pre_vd1_mtx_sel\n"); +unsigned int vd1_mtx_sel = VPP_MATRIX_NULL; +static int src_timing_outputmode_changed(struct vframe_s *vf, + struct vinfo_s *vinfo) +{ + unsigned int width, height; + + if (vinfo->viu_color_fmt == COLOR_FMT_RGB444) + return 0; + + width = (vf->type & VIDTYPE_COMPRESS) ? + vf->compWidth : vf->width; + height = (vf->type & VIDTYPE_COMPRESS) ? + vf->compHeight : vf->height; + + if ((height < 720) && (vinfo->height < 720)) + vd1_mtx_sel = VPP_MATRIX_NULL; + else if ((height < 720) && (vinfo->height >= 720)) + vd1_mtx_sel = VPP_MATRIX_YUV601L_YUV709L; + else if ((height >= 720) && (vinfo->height < 720)) + vd1_mtx_sel = VPP_MATRIX_YUV709L_YUV601L; + else if ((height >= 720) && (vinfo->height >= 720)) + vd1_mtx_sel = VPP_MATRIX_NULL; + else + vd1_mtx_sel = VPP_MATRIX_NULL; + + if (pre_vd1_mtx_sel != vd1_mtx_sel) { + pre_vd1_mtx_sel = vd1_mtx_sel; + return 1; + } + + return 0; +} int signal_type_changed(struct vframe_s *vf, struct vinfo_s *vinfo) { @@ -2953,6 +3226,9 @@ int signal_type_changed(struct vframe_s *vf, struct vinfo_s *vinfo) struct vframe_master_display_colour_s *p_new; struct vframe_master_display_colour_s cus; + if (!vf) + return 0; + if ((vf->source_type == VFRAME_SOURCE_TYPE_TUNER) || (vf->source_type == VFRAME_SOURCE_TYPE_CVBS) || (vf->source_type == VFRAME_SOURCE_TYPE_COMP) || @@ -3029,6 +3305,28 @@ int signal_type_changed(struct vframe_s *vf, struct vinfo_s *vinfo) cus.present_flag = 1; p_new = &cus; } + + /* For txhd, must skip HDR process */ + if (is_meson_txhd_cpu()) { + if (((signal_type & 0xff) != 1) && + ((signal_type & 0xff) != 3)) { + signal_type &= 0xffffff00; + signal_type |= 0x00000001; + } + if (((signal_type & 0xff00) != 1) && + ((signal_type & 0xff00) != 3)) { + signal_type &= 0xffff00ff; + signal_type |= 0x00000100; + } + if (((signal_type & 0xff0000) != 1) && + ((signal_type & 0xff0000) != 3)) { + signal_type &= 0xff00ffff; + signal_type |= 0x00010000; + } + /*pr_err("Signal type changed from 0x%x to 0x%x.\n",*/ + /*vf->signal_type, signal_type);*/ + } + if (p_new->present_flag & 1) { for (i = 0; i < 3; i++) for (j = 0; j < 2; j++) { @@ -3102,6 +3400,10 @@ int signal_type_changed(struct vframe_s *vf, struct vinfo_s *vinfo) pr_csc("HDR mode changed.\n"); change_flag |= SIG_HDR_MODE; } + if (cur_hlg_process_mode != hlg_process_mode) { + pr_csc("HLG mode changed.\n"); + change_flag |= SIG_HLG_MODE; + } if (cur_sdr_process_mode != sdr_process_mode) { pr_csc("SDR mode changed.\n"); change_flag |= SIG_HDR_MODE; @@ -3116,12 +3418,22 @@ int signal_type_changed(struct vframe_s *vf, struct vinfo_s *vinfo) change_flag |= SIG_OP_CHG; cur_output_mode = vinfo->viu_color_fmt; } + if (cur_hlg_support != (vinfo->hdr_info.hdr_support & 0x8)) { + pr_csc("Tx HLG support changed.\n"); + change_flag |= SIG_HLG_SUPPORT; + cur_hlg_support = vinfo->hdr_info.hdr_support & 0x8; + } + if ((cur_eye_protect_mode != wb_val[0]) || (cur_eye_protect_mode == 1)) { pr_csc(" eye protect mode changed.\n"); change_flag |= SIG_WB_CHG; } + if (src_timing_outputmode_changed(vf, vinfo)) { + pr_csc(" source timing output mode changed.\n"); + change_flag |= SIG_SRC_OUTPUT_CHG; + } return change_flag; } @@ -3207,6 +3519,18 @@ static int get_hdr_type(void) return change_flag; } +void get_hdr_source_type(void) +{ + if ((signal_transfer_characteristic == 18) || + (signal_transfer_characteristic == 14)) + hdr_source_type = HLG_SOURCE; + else if ((signal_color_primaries == 9) || + (signal_transfer_characteristic == 16)) + hdr_source_type = HDR10_SOURCE; + else + hdr_source_type = SDR_SOURCE; +} + static void cal_out_curve(uint panel_luma) { int index; @@ -3642,7 +3966,9 @@ static void amvecm_cp_hdr_info(struct master_display_info_s *hdr_data, customer_hdmi_display_param[12]; hdr_data->max_frame_average = customer_hdmi_display_param[13]; - } else if (((hdr_data->features >> 16) & 0xff) == 9) { + } else if ((((hdr_data->features >> 16) & 0xff) == 9) || + ((((hdr_data->features >> 8) & 0xff) >= 14) && + (((hdr_data->features >> 8) & 0xff) <= 18))) { if (p->present_flag & 1) { memcpy(hdr_data->primaries, p->primaries, @@ -3700,7 +4026,8 @@ static void vpp_lut_curve_set(enum vpp_lut_sel_e lut_sel) if (lut_sel == VPP_LUT_EOTF) { /* eotf lut 2048 */ if ((get_cpu_type() == MESON_CPU_MAJOR_ID_GXL) || - (get_cpu_type() == MESON_CPU_MAJOR_ID_GXM)) { + (get_cpu_type() == MESON_CPU_MAJOR_ID_GXM) || + (get_cpu_type() == MESON_CPU_MAJOR_ID_GXLX)) { if (video_lut_swtich == 1) /*350nit alpha_low = 0.12; */ set_vpp_lut(VPP_LUT_EOTF, @@ -3746,7 +4073,8 @@ static void vpp_lut_curve_set(enum vpp_lut_sel_e lut_sel) } else if (lut_sel == VPP_LUT_OETF) { /* oetf lut bypass */ if ((get_cpu_type() == MESON_CPU_MAJOR_ID_GXL) || - (get_cpu_type() == MESON_CPU_MAJOR_ID_GXM)) { + (get_cpu_type() == MESON_CPU_MAJOR_ID_GXM) || + (get_cpu_type() == MESON_CPU_MAJOR_ID_GXLX)) { if (video_lut_swtich == 1) set_vpp_lut(VPP_LUT_OETF, oetf_289_gamma22_mapping_level1_box, @@ -3919,7 +4247,11 @@ static int hdr_process( CSC_OFF); /*INV LUT*/ - set_vpp_lut(VPP_LUT_INV_EOTF, NULL, NULL, NULL, CSC_OFF); + set_vpp_lut(VPP_LUT_INV_EOTF, + NULL, + NULL, + NULL, + CSC_OFF); /* post matrix YUV2020 to RGB2020 */ set_vpp_matrix(VPP_MATRIX_POST, @@ -4086,11 +4418,18 @@ static int hlg_process( /* WRITE_VPP_REG_BITS(VIU_OSD1_BLK0_CFG_W0, */ /* 0, 7, 1); */ /* eotf lut 709 */ - set_vpp_lut(VPP_LUT_OSD_EOTF, - osd_eotf_33_709_mapping, /* R */ - osd_eotf_33_709_mapping, /* G */ - osd_eotf_33_709_mapping, /* B */ - CSC_ON); + if (get_hdr_type() & HLG_FLAG) + set_vpp_lut(VPP_LUT_OSD_EOTF, + osd_eotf_33_sdr2hlg_mapping, /* R */ + osd_eotf_33_sdr2hlg_mapping, /* G */ + osd_eotf_33_sdr2hlg_mapping, /* B */ + CSC_ON); + else + set_vpp_lut(VPP_LUT_OSD_EOTF, + osd_eotf_33_709_mapping, /* R */ + osd_eotf_33_709_mapping, /* G */ + osd_eotf_33_709_mapping, /* B */ + CSC_ON); /* eotf matrix 709->2020 */ osd_mtx[EOTF_COEFF_SIZE - 1] = osd_m.right_shift; @@ -4107,11 +4446,18 @@ static int hlg_process( CSC_ON); /* oetf lut 2084 */ - set_vpp_lut(VPP_LUT_OSD_OETF, - osd_oetf_41_2084_mapping, /* R */ - osd_oetf_41_2084_mapping, /* G */ - osd_oetf_41_2084_mapping, /* B */ - CSC_ON); + if (get_hdr_type() & HLG_FLAG) + set_vpp_lut(VPP_LUT_OSD_OETF, + osd_oetf_41_sdr2hlg_mapping, /* R */ + osd_oetf_41_sdr2hlg_mapping, /* G */ + osd_oetf_41_sdr2hlg_mapping, /* B */ + CSC_ON); + else + set_vpp_lut(VPP_LUT_OSD_OETF, + osd_oetf_41_2084_mapping, /* R */ + osd_oetf_41_2084_mapping, /* G */ + osd_oetf_41_2084_mapping, /* B */ + CSC_ON); /* osd matrix RGB2020 to YUV2020 limit */ set_vpp_matrix(VPP_MATRIX_OSD, @@ -4120,7 +4466,7 @@ static int hlg_process( } /************** VIDEO **************/ if ((get_cpu_type() > MESON_CPU_MAJOR_ID_GXTVBB) - && (csc_en & 0x4)) { + && (csc_en & 0x4)) { /* vd1 matrix bypass */ set_vpp_matrix(VPP_MATRIX_VD1, bypass_coeff, @@ -4158,7 +4504,8 @@ static int hlg_process( if (hdr_flag & 4) need_adjust_contrast_saturation |= 1; if (hdr_flag & 8) - saturation_offset = extra_sat_lut[1]; + saturation_offset = + extra_sat_lut[1]; } } /* eotf matrix RGB2020 to RGB709 */ @@ -4172,7 +4519,9 @@ static int hlg_process( mtx[i * 3 + j] = m.matrix[i][j]; } - set_vpp_matrix(VPP_MATRIX_EOTF, mtx, CSC_ON); + set_vpp_matrix(VPP_MATRIX_EOTF, + mtx, + CSC_ON); set_vpp_lut(VPP_LUT_OETF, oetf_289_gamma22_mapping, @@ -4188,9 +4537,11 @@ static int hlg_process( } if (get_cpu_type() <= MESON_CPU_MAJOR_ID_GXTVBB) { /* turn vd1 matrix on */ - vpp_set_matrix(VPP_MATRIX_VD1, CSC_ON, csc_type, NULL); + vpp_set_matrix(VPP_MATRIX_VD1, CSC_ON, + csc_type, NULL); /* turn post matrix on */ - vpp_set_matrix(VPP_MATRIX_POST, CSC_ON, csc_type, &m); + vpp_set_matrix(VPP_MATRIX_POST, CSC_ON, + csc_type, &m); /* xvycc lut on */ load_knee_lut(CSC_ON); @@ -4250,11 +4601,18 @@ static void bypass_hdr_process( (vinfo->viu_color_fmt != COLOR_FMT_RGB444))) { /* OSD convert to HDR to match HDR video */ /* osd eotf lut 709 */ - set_vpp_lut(VPP_LUT_OSD_EOTF, - osd_eotf_33_709_mapping, /* R */ - osd_eotf_33_709_mapping, /* G */ - osd_eotf_33_709_mapping, /* B */ - CSC_ON); + if (get_hdr_type() & HLG_FLAG) + set_vpp_lut(VPP_LUT_OSD_EOTF, + osd_eotf_33_sdr2hlg_mapping, /* R */ + osd_eotf_33_sdr2hlg_mapping, /* G */ + osd_eotf_33_sdr2hlg_mapping, /* B */ + CSC_ON); + else + set_vpp_lut(VPP_LUT_OSD_EOTF, + osd_eotf_33_709_mapping, /* R */ + osd_eotf_33_709_mapping, /* G */ + osd_eotf_33_709_mapping, /* B */ + CSC_ON); /* osd eotf matrix 709->2020 */ if (master_info->present_flag & 1) { @@ -4288,11 +4646,18 @@ static void bypass_hdr_process( CSC_ON); /* osd oetf lut 2084 */ - set_vpp_lut(VPP_LUT_OSD_OETF, - osd_oetf_41_2084_mapping, /* R */ - osd_oetf_41_2084_mapping, /* G */ - osd_oetf_41_2084_mapping, /* B */ - CSC_ON); + if (get_hdr_type() & HLG_FLAG) + set_vpp_lut(VPP_LUT_OSD_OETF, + osd_oetf_41_sdr2hlg_mapping, /* R */ + osd_oetf_41_sdr2hlg_mapping, /* G */ + osd_oetf_41_sdr2hlg_mapping, /* B */ + CSC_ON); + else + set_vpp_lut(VPP_LUT_OSD_OETF, + osd_oetf_41_2084_mapping, /* R */ + osd_oetf_41_2084_mapping, /* G */ + osd_oetf_41_2084_mapping, /* B */ + CSC_ON); /* osd matrix RGB2020 to YUV2020 limit */ set_vpp_matrix(VPP_MATRIX_OSD, @@ -4337,28 +4702,50 @@ static void bypass_hdr_process( bypass_coeff, CSC_OFF); /* limit->limit range */ else { - if (range_control) { - if (signal_range == 0) /* limit range */ - set_vpp_matrix(VPP_MATRIX_VD1, - YUV709l_to_YUV709f_coeff, + if (vinfo->viu_color_fmt == COLOR_FMT_RGB444) { + if (signal_range == 0) {/* limit range */ + if (csc_type == VPP_MATRIX_YUV601_RGB) + set_vpp_matrix(VPP_MATRIX_VD1, + range_control ? + YUV601l_to_YUV709f_coeff : + YUV601l_to_YUV709l_coeff, CSC_ON); - /* limit->full range */ - else - set_vpp_matrix(VPP_MATRIX_VD1, + else + set_vpp_matrix(VPP_MATRIX_VD1, + range_control ? + YUV709l_to_YUV709f_coeff : bypass_coeff, - CSC_OFF); - /* full->full range */ - } else { - if (signal_range == 0) /* limit range */ - set_vpp_matrix(VPP_MATRIX_VD1, - bypass_coeff, - CSC_OFF); - /* limit->limit range */ - else - set_vpp_matrix(VPP_MATRIX_VD1, + CSC_ON); + } else { + if (csc_type == VPP_MATRIX_YUV601_RGB) + set_vpp_matrix(VPP_MATRIX_VD1, + range_control ? + YUV601f_to_YUV709f_coeff : + YUV601f_to_YUV709l_coeff, + CSC_ON); + else + set_vpp_matrix(VPP_MATRIX_VD1, + range_control ? + bypass_coeff : YUV709f_to_YUV709l_coeff, CSC_ON); - /* full->limit range */ + } + } else { + /*default limit range */ + if (vd1_mtx_sel == VPP_MATRIX_NULL) + set_vpp_matrix(VPP_MATRIX_VD1, + bypass_coeff, + CSC_OFF); + else if (vd1_mtx_sel == + VPP_MATRIX_YUV601L_YUV709L) + set_vpp_matrix(VPP_MATRIX_VD1, + YUV601l_to_YUV709l_coeff, + CSC_ON); + else if (vd1_mtx_sel == + VPP_MATRIX_YUV709L_YUV601L) + set_vpp_matrix(VPP_MATRIX_VD1, + YUV709l_to_YUV601l_coeff, + CSC_ON); } } @@ -4368,10 +4755,16 @@ static void bypass_hdr_process( set_vpp_matrix(VPP_MATRIX_POST, bypass_coeff, CSC_OFF); - else /* matrix yuv2rgb for LCD */ - set_vpp_matrix(VPP_MATRIX_POST, - YUV709l_to_RGB709_coeff, - CSC_ON); + else {/* matrix yuv2rgb for LCD */ + if (range_control) + set_vpp_matrix(VPP_MATRIX_POST, + YUV709f_to_RGB709_coeff, + CSC_ON); + else + set_vpp_matrix(VPP_MATRIX_POST, + YUV709l_to_RGB709_coeff, + CSC_ON); + } /* xvycc inv lut */ if (sdr_process_mode && (csc_type < VPP_MATRIX_BT2020YUV_BT2020RGB) && @@ -4414,16 +4807,10 @@ static void bypass_hdr_process( set_vpp_matrix(VPP_MATRIX_XVYCC, bypass_coeff, CSC_OFF); - else { - if (range_control) - set_vpp_matrix(VPP_MATRIX_XVYCC, - YUV709f_to_YUV709l_coeff, - CSC_ON); - else - set_vpp_matrix(VPP_MATRIX_XVYCC, - bypass_coeff, - CSC_OFF); - } + else + set_vpp_matrix(VPP_MATRIX_XVYCC, + bypass_coeff, + CSC_OFF); } } else { /* OSD */ @@ -4435,9 +4822,11 @@ static void bypass_hdr_process( csc_type = VPP_MATRIX_YUV709_RGB; } /* vd1 matrix on to convert YUV to RGB */ - vpp_set_matrix(VPP_MATRIX_VD1, CSC_ON, csc_type, NULL); + vpp_set_matrix(VPP_MATRIX_VD1, CSC_ON, + csc_type, NULL); /* post matrix off */ - vpp_set_matrix(VPP_MATRIX_POST, CSC_OFF, csc_type, NULL); + vpp_set_matrix(VPP_MATRIX_POST, CSC_OFF, + csc_type, NULL); /* xvycc lut off */ load_knee_lut(CSC_OFF); /* xvycc inv lut */ @@ -4471,7 +4860,7 @@ static void bypass_hdr_process( vpp_set_mtx_en_write(); } -static void bypass_hlg_process( +static void hlg_hdr_process( enum vpp_matrix_csc_e csc_type, struct vinfo_s *vinfo, struct vframe_master_display_colour_s *master_info) @@ -4512,11 +4901,18 @@ static void bypass_hlg_process( (vinfo->viu_color_fmt != COLOR_FMT_RGB444))) { /* OSD convert to HDR to match HDR video */ /* osd eotf lut 709 */ - set_vpp_lut(VPP_LUT_OSD_EOTF, - osd_eotf_33_709_mapping, /* R */ - osd_eotf_33_709_mapping, /* G */ - osd_eotf_33_709_mapping, /* B */ - CSC_ON); + if (get_hdr_type() & HLG_FLAG) + set_vpp_lut(VPP_LUT_OSD_EOTF, + osd_eotf_33_sdr2hlg_mapping, /* R */ + osd_eotf_33_sdr2hlg_mapping, /* G */ + osd_eotf_33_sdr2hlg_mapping, /* B */ + CSC_ON); + else + set_vpp_lut(VPP_LUT_OSD_EOTF, + osd_eotf_33_709_mapping, /* R */ + osd_eotf_33_709_mapping, /* G */ + osd_eotf_33_709_mapping, /* B */ + CSC_ON); /* osd eotf matrix 709->2020 */ if (master_info->present_flag & 1) { @@ -4545,14 +4941,23 @@ static void bypass_hlg_process( osd_mtx[i * 3 + j] = osd_m.matrix[i][j]; } - set_vpp_matrix(VPP_MATRIX_OSD_EOTF, osd_mtx, CSC_ON); + set_vpp_matrix(VPP_MATRIX_OSD_EOTF, + osd_mtx, + CSC_ON); /* osd oetf lut 2084 */ - set_vpp_lut(VPP_LUT_OSD_OETF, - osd_oetf_41_2084_mapping, /* R */ - osd_oetf_41_2084_mapping, /* G */ - osd_oetf_41_2084_mapping, /* B */ - CSC_ON); + if (get_hdr_type() & HLG_FLAG) + set_vpp_lut(VPP_LUT_OSD_OETF, + osd_oetf_41_sdr2hlg_mapping, /* R */ + osd_oetf_41_sdr2hlg_mapping, /* G */ + osd_oetf_41_sdr2hlg_mapping, /* B */ + CSC_ON); + else + set_vpp_lut(VPP_LUT_OSD_OETF, + osd_oetf_41_2084_mapping, /* R */ + osd_oetf_41_2084_mapping, /* G */ + osd_oetf_41_2084_mapping, /* B */ + CSC_ON); /* osd matrix RGB2020 to YUV2020 limit */ set_vpp_matrix(VPP_MATRIX_OSD, @@ -4599,29 +5004,15 @@ static void bypass_hlg_process( bypass_coeff, CSC_OFF); /* limit->limit range */ else { - if (range_control) { - if (signal_range == 0) /* limit range */ - set_vpp_matrix(VPP_MATRIX_VD1, - YUV709l_to_YUV709f_coeff, - CSC_ON); - /* limit->full range */ - else - set_vpp_matrix(VPP_MATRIX_VD1, - bypass_coeff, - CSC_OFF); - /* full->full range */ - } else { - if (signal_range == 0) /* limit range */ - set_vpp_matrix(VPP_MATRIX_VD1, - bypass_coeff, - CSC_OFF); - /* limit->limit range */ - else - set_vpp_matrix(VPP_MATRIX_VD1, - YUV709f_to_YUV709l_coeff, - CSC_ON); - /* full->limit range */ - } + if (signal_range == 0) /* limit range */ + set_vpp_matrix(VPP_MATRIX_VD1, + bypass_coeff, + CSC_OFF); + /* limit->limit range */ + else + set_vpp_matrix(VPP_MATRIX_VD1, + YUV709f_to_YUV709l_coeff, + CSC_ON); } /*eo oo oe*/ int_lut_sel[0] |= INVLUT_HLG; @@ -4688,9 +5079,11 @@ static void bypass_hlg_process( csc_type = VPP_MATRIX_YUV709_RGB; } /* vd1 matrix on to convert YUV to RGB */ - vpp_set_matrix(VPP_MATRIX_VD1, CSC_ON, csc_type, NULL); + vpp_set_matrix(VPP_MATRIX_VD1, CSC_ON, + csc_type, NULL); /* post matrix off */ - vpp_set_matrix(VPP_MATRIX_POST, CSC_OFF, csc_type, NULL); + vpp_set_matrix(VPP_MATRIX_POST, CSC_OFF, + csc_type, NULL); /* xvycc lut off */ load_knee_lut(CSC_OFF); /* xvycc inv lut */ @@ -4730,7 +5123,8 @@ static void sdr_hdr_process( struct vframe_master_display_colour_s *master_info) { if ((get_cpu_type() == MESON_CPU_MAJOR_ID_GXL) || - (get_cpu_type() == MESON_CPU_MAJOR_ID_GXM)) { + (get_cpu_type() == MESON_CPU_MAJOR_ID_GXM) || + (get_cpu_type() == MESON_CPU_MAJOR_ID_GXLX)) { /*vpp matrix mux read*/ vpp_set_mtx_en_read(); /* OSD convert to 709 limited to match SDR video */ @@ -4910,18 +5304,47 @@ static int vpp_matrix_update( /* check hdr support info from Tx or Panel */ if (hdr_mode == 2) { /* auto */ - if (vinfo->hdr_info.hdr_support & 0x4) + /*hdr_support & bit2 is hdr10*/ + /*hdr_support & bit3 is hlg*/ + if ((vinfo->hdr_info.hdr_support & HDR_SUPPORT) && + (vinfo->hdr_info.hdr_support & HLG_SUPPORT)) { hdr_process_mode = 0; /* hdr->hdr*/ - else - hdr_process_mode = 1; /* hdr->sdr*/ - } else - hdr_process_mode = hdr_mode; + hlg_process_mode = 0; /* hlg->hlg*/ + } else if ((vinfo->hdr_info.hdr_support & HDR_SUPPORT) && + !(vinfo->hdr_info.hdr_support & HLG_SUPPORT)) { + hdr_process_mode = 0; /* hdr->hdr*/ + if (force_pure_hlg) + hlg_process_mode = 0; + else + hlg_process_mode = 1; /* hlg->hdr10*/ + } else if (!(vinfo->hdr_info.hdr_support & HDR_SUPPORT) && + (vinfo->hdr_info.hdr_support & HLG_SUPPORT)) { + hdr_process_mode = 1; + hlg_process_mode = 0; + } else { + hdr_process_mode = 1; + hlg_process_mode = 1; + } + } else if (hdr_mode == 1) { + hdr_process_mode = 1; + hlg_process_mode = 1; + } else { + hdr_process_mode = 0; + if (vinfo->hdr_info.hdr_support & HDR_SUPPORT) { + if (force_pure_hlg) + hlg_process_mode = 0; + else + hlg_process_mode = 1; + } else + hlg_process_mode = 0; + } if (sdr_mode == 2) { /* auto */ if ((vinfo->hdr_info.hdr_support & 0x4) && ((get_cpu_type() == MESON_CPU_MAJOR_ID_GXL) || - (get_cpu_type() == MESON_CPU_MAJOR_ID_GXM) - || (get_cpu_type() == MESON_CPU_MAJOR_ID_G12A))) + (get_cpu_type() == MESON_CPU_MAJOR_ID_GXM) || + (get_cpu_type() == MESON_CPU_MAJOR_ID_GXLX) || + (get_cpu_type() == MESON_CPU_MAJOR_ID_G12A))) sdr_process_mode = 1; /*box sdr->hdr*/ else if ((vinfo->viu_color_fmt == COLOR_FMT_RGB444) && ((get_cpu_type() == MESON_CPU_MAJOR_ID_GXTVBB) || @@ -4941,8 +5364,9 @@ static int vpp_matrix_update( csc_type = get_csc_type(); if ((vinfo->viu_color_fmt != COLOR_FMT_RGB444) && - ((vinfo->hdr_info.hdr_support & 0x4) || - (signal_change_flag & SIG_HDR_SUPPORT))) { + ((vinfo->hdr_info.hdr_support & 0xc) || + (signal_change_flag & SIG_HDR_SUPPORT) || + (signal_change_flag & SIG_HLG_SUPPORT))) { if (sdr_process_mode && (csc_type < VPP_MATRIX_BT2020YUV_BT2020RGB)) { /* sdr source convert to hdr */ @@ -4966,6 +5390,7 @@ static int vpp_matrix_update( hdmi_scs_type_changed = 1; } } else if ((hdr_process_mode == 0) && + (hlg_process_mode == 0) && (csc_type >= VPP_MATRIX_BT2020YUV_BT2020RGB)) { /* source is hdr, send hdr info */ /* use the features to discribe source info */ @@ -4988,14 +5413,85 @@ static int vpp_matrix_update( hdmi_csc_type = VPP_MATRIX_BT2020YUV_BT2020RGB; hdmi_scs_type_changed = 1; } + } else if ((hdr_process_mode == 0) && + (hlg_process_mode == 1) && + (csc_type >= VPP_MATRIX_BT2020YUV_BT2020RGB)) { + /* source is hdr, send hdr info */ + /* use the features to discribe source info */ + if (get_hdr_type() & HLG_FLAG) + send_info.features = + (1 << 29) /* video available */ + | (5 << 26) /* unspecified */ + | (0 << 25) /* limit */ + | (1 << 24) /* color available */ + /* bt2020 */ + | (9 << 16) + /* bt2020-10 */ + | (16 << 8) + | (10 << 0); /* bt2020c */ + else + send_info.features = + (1 << 29) /* video available */ + | (5 << 26) /* unspecified */ + | (0 << 25) /* limit */ + | (1 << 24) /* color available */ + /* bt2020 */ + | (signal_color_primaries << 16) + /* bt2020-10 */ + | (signal_transfer_characteristic << 8) + | (10 << 0); /* bt2020c */ + amvecm_cp_hdr_info(&send_info, p); + if (vdev) { + if (vdev->fresh_tx_hdr_pkt) + vdev->fresh_tx_hdr_pkt(&send_info); + } + if (hdmi_csc_type != VPP_MATRIX_BT2020YUV_BT2020RGB) { + hdmi_csc_type = VPP_MATRIX_BT2020YUV_BT2020RGB; + hdmi_scs_type_changed = 1; + } + } else if ((hdr_process_mode == 1) && + (hlg_process_mode == 0) && + (csc_type >= VPP_MATRIX_BT2020YUV_BT2020RGB)) { + /* source is hdr, send hdr info */ + /* use the features to discribe source info */ + if (get_hdr_type() & HLG_FLAG) + send_info.features = + (1 << 29) /* video available */ + | (5 << 26) /* unspecified */ + | (0 << 25) /* limit */ + | (1 << 24) /* color available */ + /* bt2020 */ + | (signal_color_primaries << 16) + /* bt2020-10 */ + | (signal_transfer_characteristic << 8) + | (10 << 0); /* bt2020c */ + else + send_info.features = + /* default 709 full */ + (1 << 29) /* video available */ + | (5 << 26) /* unspecified */ + | (0 << 25) /* limit */ + | (1 << 24) /* color available */ + | (1 << 16) /* bt709 */ + | (1 << 8) /* bt709 */ + | (1 << 0); /* bt709 */ + amvecm_cp_hdr_info(&send_info, p); + if (vdev) { + if (vdev->fresh_tx_hdr_pkt) + vdev->fresh_tx_hdr_pkt(&send_info); + } + if (hdmi_csc_type != VPP_MATRIX_BT2020YUV_BT2020RGB) { + hdmi_csc_type = VPP_MATRIX_BT2020YUV_BT2020RGB; + hdmi_scs_type_changed = 1; + } } else { /* sdr source send normal info*/ /* use the features to discribe source info */ send_info.features = - /* default 709 full */ + /* default 709 limit */ (1 << 29) /* video available */ | (5 << 26) /* unspecified */ - | (0 << 25) /* full */ + | (0 << 25) /* limit */ | (1 << 24) /* color available */ | (1 << 16) /* bt709 */ | (1 << 8) /* bt709 */ @@ -5023,18 +5519,22 @@ static int vpp_matrix_update( vecm_latch_flag |= FLAG_MATRIX_UPDATE; if ((cur_csc_type != csc_type) - || (signal_change_flag - & (SIG_PRI_INFO | SIG_KNEE_FACTOR | SIG_HDR_MODE | - SIG_HDR_SUPPORT | SIG_OP_CHG))) { + || (signal_change_flag + & (SIG_CS_CHG | SIG_PRI_INFO | SIG_KNEE_FACTOR | SIG_HDR_MODE | + SIG_HDR_SUPPORT | SIG_HLG_MODE | SIG_OP_CHG | + SIG_SRC_OUTPUT_CHG))) { /* decided by edid or panel info or user setting */ if ((csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB) && - hdr_process_mode) { - /* hdr->sdr */ + (hdr_process_mode == 1) && + (hlg_process_mode == 1)) { + /* hdr->sdr hlg->sdr */ if ((signal_change_flag & - (SIG_PRI_INFO | + (SIG_CS_CHG | + SIG_PRI_INFO | SIG_KNEE_FACTOR | SIG_HDR_MODE | - SIG_HDR_SUPPORT) + SIG_HDR_SUPPORT | + SIG_HLG_MODE) ) || (cur_csc_type < VPP_MATRIX_BT2020YUV_BT2020RGB)) { @@ -5052,34 +5552,81 @@ static int vpp_matrix_update( vinfo, p); } } + } else if ((csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB) && + (hdr_process_mode == 0) && + (hlg_process_mode == 1)) { + /* hdr->hdr hlg->hlg*/ + if ((signal_change_flag & + (SIG_CS_CHG | + SIG_PRI_INFO | + SIG_KNEE_FACTOR | + SIG_HDR_MODE | + SIG_HDR_SUPPORT | + SIG_HLG_MODE) + ) || + (cur_csc_type < + VPP_MATRIX_BT2020YUV_BT2020RGB)) { + if (get_hdr_type() & HLG_FLAG) + hlg_hdr_process(csc_type, vinfo, p); + else + bypass_hdr_process(csc_type, vinfo, p); + } + } else if ((csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB) && + (hdr_process_mode == 1) && (hlg_process_mode == 0)) { + /* hdr->sdr hlg->hlg*/ + if ((signal_change_flag & + (SIG_CS_CHG | + SIG_PRI_INFO | + SIG_KNEE_FACTOR | + SIG_HDR_MODE | + SIG_HDR_SUPPORT | + SIG_HLG_MODE) + ) || + (cur_csc_type < + VPP_MATRIX_BT2020YUV_BT2020RGB)) { + if (get_hdr_type() & HLG_FLAG) + bypass_hdr_process(csc_type, vinfo, p); + else + need_adjust_contrast_saturation = + hdr_process(csc_type, vinfo, p); + } + } else if ((csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB) && + (hdr_process_mode == 0) && (hlg_process_mode == 0)) { + /* hdr->hdr hlg->hlg*/ + if ((signal_change_flag & + (SIG_CS_CHG | + SIG_PRI_INFO | + SIG_KNEE_FACTOR | + SIG_HDR_MODE | + SIG_HDR_SUPPORT | + SIG_HLG_MODE)) || + (cur_csc_type < + VPP_MATRIX_BT2020YUV_BT2020RGB)) { + if (get_cpu_type() == MESON_CPU_MAJOR_ID_G12A) { + hdrbypass_func(VD1_HDR); + hdrbypass_func(OSD1_HDR); + } else + bypass_hdr_process(csc_type, vinfo, p); + } } else { if ((csc_type < VPP_MATRIX_BT2020YUV_BT2020RGB) && sdr_process_mode) { - /* for gxl and gxm SDR to HDR process */ - if (get_cpu_type() == - MESON_CPU_MAJOR_ID_G12A) { + if (get_cpu_type() == MESON_CPU_MAJOR_ID_G12A) { sdr2hdr_func(VD1_HDR); sdr2hdr_func(OSD1_HDR); } else - sdr_hdr_process(csc_type, - vinfo, p); + /* for gxl and gxm SDR to HDR process */ + sdr_hdr_process(csc_type, vinfo, p); } else { + if (get_cpu_type() == MESON_CPU_MAJOR_ID_G12A) { + hdrbypass_func(VD1_HDR); + hdrbypass_func(OSD1_HDR); + } else /* for gxtvbb and gxl HDR bypass process */ - if ((get_hdr_type() & HLG_FLAG) && - (vinfo->viu_color_fmt != - COLOR_FMT_RGB444)) - bypass_hlg_process(csc_type, vinfo, p); - else { - if (get_cpu_type() == - MESON_CPU_MAJOR_ID_G12A) { - hdrbypass_func(VD1_HDR); - hdrbypass_func(OSD1_HDR); - } else - bypass_hdr_process(csc_type, - vinfo, p); - } + bypass_hdr_process(csc_type, vinfo, p); } } + if (get_cpu_type() == MESON_CPU_MAJOR_ID_G12A) { if (vinfo->viu_color_fmt != COLOR_FMT_RGB444) mtx_setting(POST2_MTX, MATRIX_NULL, MTX_OFF); @@ -5098,6 +5645,11 @@ static int vpp_matrix_update( pr_csc("sdr_process_mode changed to %d", sdr_process_mode); } + if (cur_hlg_process_mode != hlg_process_mode) { + cur_hlg_process_mode = hlg_process_mode; + pr_csc("hlg_process_mode changed to %d", + hlg_process_mode); + } if (need_adjust_contrast_saturation & 1) { if (lut_289_en && (get_cpu_type() <= MESON_CPU_MAJOR_ID_GXTVBB)) @@ -5381,6 +5933,7 @@ int amvecm_hdr_dbg(u32 sel) content_light_level->max_pic_average); } + pr_err(HDR_VERSION); hdr_dump: pr_err("----HDR process info----\n"); pr_err("customer_master_display_en:0x%x\n", customer_master_display_en); @@ -5388,6 +5941,9 @@ hdr_dump: pr_err("hdr_mode:0x%x, hdr_process_mode:0x%x, cur_hdr_process_mode:0x%x\n", hdr_mode, hdr_process_mode, cur_hdr_process_mode); + pr_err("hlg_process_mode: 0x%x :0->hlg->hlg,1->hlg->sdr,2->hlg->hdr10\n", + hlg_process_mode); + pr_err("sdr_mode:0x%x, sdr_process_mode:0x%x, cur_sdr_process_mode:0x%x\n", sdr_mode, sdr_process_mode, cur_sdr_process_mode); @@ -5399,7 +5955,7 @@ hdr_dump: pr_err("knee_lut_on:0x%x,knee_interpolation_mode:0x%x,cur_knee_factor:0x%x\n", knee_lut_on, knee_interpolation_mode, cur_knee_factor); - if ((receiver_hdr_info.hdr_support & 0x4) == 0) + if ((receiver_hdr_info.hdr_support & 0xc) == 0) goto dbg_end; pr_err("----TV EDID info----\n"); pr_err("hdr_support:0x%x, lumi_max:%d, lumi_avg:%d, lumi_min:%d\n", diff --git a/drivers/amlogic/media/enhancement/amvecm/amcsc.h b/drivers/amlogic/media/enhancement/amvecm/amcsc.h index d22ccb1ac6a0..566e136d753e 100644 --- a/drivers/amlogic/media/enhancement/amvecm/amcsc.h +++ b/drivers/amlogic/media/enhancement/amvecm/amcsc.h @@ -69,6 +69,9 @@ enum vpp_matrix_csc_e { VPP_MATRIX_YUV709F_RGB = 0x24, VPP_MATRIX_YUV709F_YUV601 = 0x25, VPP_MATRIX_YUV709F_YUV709 = 0x26, + VPP_MATRIX_YUV601L_YUV709L = 0x27, + VPP_MATRIX_YUV709L_YUV601L = 0x28, + VPP_MATRIX_YUV709F_YUV601F = 0x29, VPP_MATRIX_BT2020YUV_BT2020RGB = 0x40, VPP_MATRIX_BT2020RGB_709RGB, VPP_MATRIX_BT2020RGB_CUSRGB, @@ -108,6 +111,9 @@ enum mtx_en_e { #define XVY_MTX_EN_MASK (1 << XVY_MTX_EN) #define OSD1_MTX_EN_MASK (1 << OSD1_MTX_EN) +#define HDR_SUPPORT (1 << 2) +#define HLG_SUPPORT (1 << 3) + #define LUT_289_SIZE 289 extern unsigned int lut_289_mapping[LUT_289_SIZE]; extern int dnlp_en; @@ -136,6 +142,6 @@ extern int VSYNC_WR_MPEG_REG(u32 adr, u32 val); #endif extern u32 get_video_enabled(void); - +extern void get_hdr_source_type(void); #endif /* AM_CSC_H */ diff --git a/drivers/amlogic/media/enhancement/amvecm/amvecm.c b/drivers/amlogic/media/enhancement/amvecm/amvecm.c index 1ac764b30d77..fc35a6cb310b 100644 --- a/drivers/amlogic/media/enhancement/amvecm/amvecm.c +++ b/drivers/amlogic/media/enhancement/amvecm/amvecm.c @@ -150,6 +150,7 @@ module_param(pq_user_latch_flag, uint, 0664); MODULE_PARM_DESC(pq_user_latch_flag, "\n pq_user_latch_flag\n"); unsigned int pq_user_value; +unsigned int hdr_source_type = 0x1; static int wb_init_bypass_coef[24] = { 0, 0, 0, /* pre offset */ @@ -929,6 +930,9 @@ int amvecm_on_vs( result = amvecm_matrix_process(NULL, NULL, flags); } + if (!is_dolby_vision_on()) + get_hdr_source_type(); + /* add some flag to trigger */ if (vf) { /*gxlx sharpness adaptive setting*/ @@ -4194,6 +4198,18 @@ static ssize_t amvecm_reg_store(struct class *cla, return count; } +static ssize_t amvecm_get_hdr_type_show(struct class *cla, + struct class_attribute *attr, char *buf) +{ + return sprintf(buf, "%x\n", hdr_source_type); +} + +static ssize_t amvecm_get_hdr_type_store(struct class *cls, + struct class_attribute *attr, + const char *buffer, size_t count) +{ + return count; +} /* #if (MESON_CPU_TYPE == MESON_CPU_TYPE_MESONG9TV) */ void init_pq_setting(void) @@ -4392,6 +4408,8 @@ static struct class_attribute amvecm_class_attrs[] = { amvecm_pq_user_show, amvecm_pq_user_store), __ATTR(pq_reg_rw, 0644, amvecm_write_reg_show, amvecm_write_reg_store), + __ATTR(get_hdr_type, 0644, + amvecm_get_hdr_type_show, amvecm_get_hdr_type_store), __ATTR_NULL }; diff --git a/include/linux/amlogic/media/amvecm/amvecm.h b/include/linux/amlogic/media/amvecm/amvecm.h index d9ea64ef6684..fe8b5edf2a5c 100644 --- a/include/linux/amlogic/media/amvecm/amvecm.h +++ b/include/linux/amlogic/media/amvecm/amvecm.h @@ -95,6 +95,10 @@ #define MTX_BYPASS_RGB_OGO (1 << 0) #define MTX_RGB2YUVL_RGB_OGO (1 << 1) +#define SDR_SOURCE (1 << 0) +#define HDR10_SOURCE (1 << 1) +#define HLG_SOURCE (1 << 2) + enum pq_table_name_e { TABLE_NAME_SHARPNESS0 = 0x1,/*in vpp*/ TABLE_NAME_SHARPNESS1 = 0x2,/*in vpp*/ @@ -292,6 +296,7 @@ static inline uint32_t READ_VPP_REG_BITS(uint32_t reg, extern signed int vd1_brightness, vd1_contrast; extern bool gamma_en; +extern unsigned int hdr_source_type; #define CSC_FLAG_TOGGLE_FRAME 1 #define CSC_FLAG_CHECK_OUTPUT 2