From 2eb9b669f4bacb97656d2de14ed432f2c3a89693 Mon Sep 17 00:00:00 2001 From: TreeHugger Robot Date: Tue, 4 Jan 2022 20:28:48 +0000 Subject: [PATCH] Merge changes Ifc5bd922,I57affad1,I92d3d3ce into android-tv-deadpool-4.9-android12 * changes: VPP: VPP code style modify [1/1] vpp: coding style modify [1/1] vpp: coding style modify [2/6] --- drivers/amlogic/media/di_multi/dolby_sys.c | 56 +- drivers/amlogic/media/di_multi/dolby_sys.h | 75 - .../amdolby_vision/amdolby_vision.c | 10062 ++++++++++------ .../amdolby_vision/amdolby_vision.h | 1049 +- .../amvecm/arch/vpp_dolbyvision_regs.h | 135 - .../vout/hdmitx/hdmi_tx_20/dv_emp_vsem.c | 240 +- .../vout/hdmitx/hdmi_tx_20/dv_emp_vsem.h | 45 +- .../media/amdolbyvision/dolby_vision.h | 211 +- include/linux/amlogic/media/vout/vinfo.h | 2 +- 9 files changed, 7474 insertions(+), 4401 deletions(-) diff --git a/drivers/amlogic/media/di_multi/dolby_sys.c b/drivers/amlogic/media/di_multi/dolby_sys.c index 967647e8b567..b9750ae48217 100644 --- a/drivers/amlogic/media/di_multi/dolby_sys.c +++ b/drivers/amlogic/media/di_multi/dolby_sys.c @@ -49,32 +49,12 @@ #include "register.h" #include #include + #define OP_BYPASS_CVM 0x01 #define OP_BYPASS_CSC 0x02 #define OP_CLKGATE_WHEN_LOAD_LUT 0x04 -/* general control config change */ -#define FLAG_CHANGE_CFG 0x000001 -/* general metadata change */ -#define FLAG_CHANGE_MDS 0x000002 -/* metadata config (below level 2) change */ -#define FLAG_CHANGE_MDS_CFG 0x000004 -/* global dimming change */ -#define FLAG_CHANGE_GD 0x000008 -/* tone curve lut change */ -#define FLAG_CHANGE_TC 0x000010 -/* 2nd tone curve (graphics) lut change */ -#define FLAG_CHANGE_TC2 0x000020 -/* L2NL lut change (for DM3.1) */ -#define FLAG_CHANGE_L2NL 0x000040 -/* 3D lut change (for DM2.12) */ -#define FLAG_CHANGE_3DLUT 0x000080 -/* 0xX00000 for other status */ -/* (video) tone mapping to a constant */ -#define FLAG_CONST_TC 0x100000 -/* 2nd tone mapping to a constant */ -#define FLAG_CONST_TC2 0x200000 -#define FLAG_CHANGE_ALL 0xffffffff +#define DI_FLAG_CHANGE_TC 0x000010 #define DIFLAG_FORCE_CVM 0x01 #define DIFLAG_BYPASS_CVM 0x02 @@ -110,13 +90,13 @@ struct di_dolby_hw_s { u32 dm_count; u32 comp_count; u32 lut_count; - struct dicomposer_register_ipcore_s *comp_reg; - struct didm_register_ipcore_1_s *dm_reg; - struct didm_lut_ipcore_s *dm_lut; + struct composer_reg_ipcore *comp_reg; + struct dm_reg_ipcore1 *dm_reg; + struct dm_lut_ipcore *dm_lut; - struct dicomposer_register_ipcore_s *last_comp_reg; - struct didm_register_ipcore_1_s *last_dm_reg; - struct didm_lut_ipcore_s *last_dm_lut; + struct composer_reg_ipcore *last_comp_reg; + struct dm_reg_ipcore1 *last_dm_reg; + struct dm_lut_ipcore *last_dm_lut; }; enum disignal_format_e { @@ -144,9 +124,9 @@ struct di_dolby_dev_s { //struct mutex di_mutex; u32 update_flag[2]; - struct dicomposer_register_ipcore_s comp_reg[2]; - struct didm_register_ipcore_1_s dm_reg[2]; - struct didm_lut_ipcore_s dm_lut[2]; + struct composer_reg_ipcore comp_reg[2]; + struct dm_reg_ipcore1 dm_reg[2]; + struct dm_lut_ipcore dm_lut[2]; struct di_dolby_hw_s hw; }; @@ -196,7 +176,7 @@ static int di_dolby_core_set(struct di_dolby_hw_s *hw, //reset = true; - if (update_flag & FLAG_CHANGE_TC) + if (update_flag & DI_FLAG_CHANGE_TC) set_lut = true; DIM_DI_WR(DOLBY_CORE1C_CLKGATE_CTRL, 0); @@ -337,9 +317,9 @@ int di_dolby_do_setting(void /*struct di_dolby_dev_s *dev*/) return 0; } -int di_dolby_update_setting(struct didm_register_ipcore_1_s *dm_reg, - struct dicomposer_register_ipcore_s *comp_reg, - struct didm_lut_ipcore_s *dm_lut, +int di_dolby_update_setting(struct dm_reg_ipcore1 *dm_reg, + struct composer_reg_ipcore *comp_reg, + struct dm_lut_ipcore *dm_lut, u32 dm_count, u32 comp_count, u32 lut_count, @@ -347,9 +327,9 @@ int di_dolby_update_setting(struct didm_register_ipcore_1_s *dm_reg, u32 hsize, u32 vsize) { - struct didm_register_ipcore_1_s *new_dm_reg; - struct dicomposer_register_ipcore_s *new_comp_reg; - struct didm_lut_ipcore_s *new_dm_lut; + struct dm_reg_ipcore1 *new_dm_reg; + struct composer_reg_ipcore *new_comp_reg; + struct dm_lut_ipcore *new_dm_lut; if (!dm_reg || !comp_reg || !dm_lut || !dm_count || !comp_count || !lut_count) diff --git a/drivers/amlogic/media/di_multi/dolby_sys.h b/drivers/amlogic/media/di_multi/dolby_sys.h index d6cb649af4cb..0f28747c5e3e 100644 --- a/drivers/amlogic/media/di_multi/dolby_sys.h +++ b/drivers/amlogic/media/di_multi/dolby_sys.h @@ -27,81 +27,6 @@ #include #include -#define DIDEF_G2L_LUT_SIZE 0x100 - -struct didm_lut_ipcore_s { - u32 tmluti[64 * 4]; - u32 tmluts[64 * 4]; - u32 smluti[64 * 4]; - u32 smluts[64 * 4]; - u32 G2L[DIDEF_G2L_LUT_SIZE]; -}; - -struct didm_register_ipcore_1_s { - u32 srange; - u32 srange_inverse; - u32 frame_format_1; - u32 frame_format_2; - u32 frame_pixel_def; - u32 y2rgb_coefficient_1; - u32 y2rgb_coefficient_2; - u32 y2rgb_coefficient_3; - u32 y2rgb_coefficient_4; - u32 y2rgb_coefficient_5; - u32 y2rgb_offset_1; - u32 y2rgb_offset_2; - u32 y2rgb_offset_3; - u32 eotf; -/* u32 Sparam_1;*/ -/* u32 Sparam_2;*/ -/* u32 Sgamma; */ - u32 a2b_coefficient_1; - u32 a2b_coefficient_2; - u32 a2b_coefficient_3; - u32 a2b_coefficient_4; - u32 a2b_coefficient_5; - u32 c2d_coefficient_1; - u32 c2d_coefficient_2; - u32 c2d_coefficient_3; - u32 c2d_coefficient_4; - u32 c2d_coefficient_5; - u32 c2d_offset; - u32 active_area_left_top; - u32 active_area_bottom_right; -}; - -struct dicomposer_register_ipcore_s { - /* offset 0xc8 */ - u32 composer_mode; - u32 vdr_resolution; - u32 bit_depth; - u32 coefficient_log2_denominator; - u32 bl_num_pivots_y; - u32 bl_pivot[5]; - u32 bl_order; - u32 bl_coefficient_y[8][3]; - u32 el_nlq_offset_y; - u32 el_coefficient_y[3]; - u32 mapping_idc_u; - u32 bl_num_pivots_u; - u32 bl_pivot_u[3]; - u32 bl_crder_u; - u32 bl_coefficient_u[4][3]; - u32 mmr_coefficient_u[22][2]; - u32 mmr_order_u; - u32 el_nlq_offset_u; - u32 el_coefficient_u[3]; - u32 mapping_idc_v; - u32 bl_num_pivots_v; - u32 bl_pivot_v[3]; - u32 bl_order_v; - u32 bl_coefficient_v[4][3]; - u32 mmr_coefficient_v[22][2]; - u32 mmr_order_V; - u32 el_nlq_offset_v; - u32 el_coefficient_v[3]; -}; - #define DOLBY_CORE1C_REG_START 0x1800 #define DOLBY_CORE1C_CLKGATE_CTRL 0x18f2 #define DOLBY_CORE1C_SWAP_CTRL0 0x18f3 diff --git a/drivers/amlogic/media/enhancement/amdolby_vision/amdolby_vision.c b/drivers/amlogic/media/enhancement/amdolby_vision/amdolby_vision.c index aab1779698b7..8918f9860bec 100644 --- a/drivers/amlogic/media/enhancement/amdolby_vision/amdolby_vision.c +++ b/drivers/amlogic/media/enhancement/amdolby_vision/amdolby_vision.c @@ -60,15 +60,19 @@ #include #include #include +#include "../../common/vfm/vfm.h" DEFINE_SPINLOCK(dovi_lock); +static unsigned int dolby_vision_probe_ok; static const struct dolby_vision_func_s *p_funcs_stb; static const struct dolby_vision_func_s *p_funcs_tv; #define AMDOLBY_VISION_NAME "amdolby_vision" #define AMDOLBY_VISION_CLASS_NAME "amdolby_vision" +#undef V2_4_3 +/*#define V2_4_3*/ struct amdolby_vision_dev_s { dev_t devt; struct cdev cdev; @@ -102,13 +106,13 @@ module_param(primary_debug, uint, 0664); MODULE_PARM_DESC(primary_debug, "\n primary_debug\n"); /* STB: if sink support DV, always output DV*/ /* else always output SDR/HDR */ -/* TV: when source is DV, convert to SDR */ +/* TV: when source is DV/HDR10/HLG, convert to SDR */ /* #define DOLBY_VISION_FOLLOW_SINK 0 */ /* STB: output DV only if source is DV*/ /* and sink support DV*/ /* else always output SDR/HDR */ -/* TV: when source is DV or HDR, convert to SDR */ +/* TV: when source is DV, convert to SDR */ /* #define DOLBY_VISION_FOLLOW_SOURCE 1 */ /* STB: always follow dolby_vision_mode */ @@ -152,16 +156,12 @@ static bool dolby_vision_enable; module_param(dolby_vision_enable, bool, 0664); MODULE_PARM_DESC(dolby_vision_enable, "\n dolby_vision_enable\n"); -static bool force_stb_mode; - static bool dolby_vision_efuse_bypass; module_param(dolby_vision_efuse_bypass, bool, 0664); MODULE_PARM_DESC(dolby_vision_efuse_bypass, "\n dolby_vision_efuse_bypass\n"); static bool efuse_mode; static bool el_mode; -module_param(force_stb_mode, bool, 0664); -MODULE_PARM_DESC(force_stb_mode, "\n force_stb_mode\n"); static uint dolby_vision_mask = 7; module_param(dolby_vision_mask, uint, 0664); @@ -171,6 +171,7 @@ MODULE_PARM_DESC(dolby_vision_mask, "\n dolby_vision_mask\n"); #define SDR_PROCESS 1 #define HDR_PROCESS 2 #define DV_PROCESS 3 +#define HLG_PROCESS 4 static uint dolby_vision_status; module_param(dolby_vision_status, uint, 0664); MODULE_PARM_DESC(dolby_vision_status, "\n dolby_vision_status\n"); @@ -207,11 +208,10 @@ static uint dolby_vision_reset_delay = module_param(dolby_vision_reset_delay, uint, 0664); MODULE_PARM_DESC(dolby_vision_reset_delay, "\n dolby_vision_reset_delay\n"); -static unsigned int dolby_vision_tunning_mode; -module_param(dolby_vision_tunning_mode, uint, 0664); -MODULE_PARM_DESC(dolby_vision_tunning_mode, "\n dolby_vision_tunning_mode\n"); +static unsigned int dolby_vision_tuning_mode; +module_param(dolby_vision_tuning_mode, uint, 0664); +MODULE_PARM_DESC(dolby_vision_tuning_mode, "\n dolby_vision_tuning_mode\n"); -#ifdef V2_4 static unsigned int dv_ll_output_mode = DOLBY_VISION_OUTPUT_MODE_HDR10; module_param(dv_ll_output_mode, uint, 0664); MODULE_PARM_DESC(dv_ll_output_mode, "\n dv_ll_output_mode\n"); @@ -223,12 +223,45 @@ static u32 dolby_vision_ll_policy = DOLBY_VISION_LL_DISABLE; module_param(dolby_vision_ll_policy, uint, 0664); MODULE_PARM_DESC(dolby_vision_ll_policy, "\n dolby_vision_ll_policy\n"); static u32 last_dolby_vision_ll_policy = DOLBY_VISION_LL_DISABLE; + +#ifdef V2_4_3 +#define DOLBY_VISION_STD_RGB_TUNNEL 0 +#define DOLBY_VISION_STD_YUV422 1 +static u32 dolby_vision_std_policy = DOLBY_VISION_STD_RGB_TUNNEL; +module_param(dolby_vision_std_policy, uint, 0664); +MODULE_PARM_DESC(dolby_vision_std_policy, "\n dolby_vision_ll_policy\n"); +/*static u32 last_dolby_vision_std_policy = DOLBY_VISION_STD_RGB_TUNNEL;*/ +static bool force_support_emp; #endif static unsigned int dolby_vision_src_format; module_param(dolby_vision_src_format, uint, 0664); MODULE_PARM_DESC(dolby_vision_src_format, "\n dolby_vision_src_format\n"); +static unsigned int force_mel; +module_param(force_mel, uint, 0664); +MODULE_PARM_DESC(force_mel, "\n force_mel\n"); + +static unsigned int force_best_pq; +module_param(force_best_pq, uint, 0664); +MODULE_PARM_DESC(force_best_pq, "\n force_best_pq\n"); + +/* by default, both std and ll use same cfg: */ +/* cfg 0.01_700_POWER_2.4_NARROW_v1-12.txt */ + +/*0:cfg 0.005_500_BT1886_2.4_NARROW_v0.txt -tid 0 */ +/*1:cfg 0.01_700_POWER_2.4_NARROW_v1-12.txt -tid 2 */ +static unsigned int cfg_id = 1;/*dv cert need cfg_id=0*/ +module_param(cfg_id, uint, 0664); +MODULE_PARM_DESC(cfg_id, "\n cfg_id\n"); + +/*0:cfg 0.001_6300_POWER_2.4_NARROW_v2.txt -tid2*/ +/*1:cfg 0.034_890_BT1886_2.2_NARROW_v2.txt -tid2*/ +/*2:cfg 0.01_700_POWER_2.4_NARROW_v1-12.txt -tid2*/ +static unsigned int cfg_ll_id = 2; +module_param(cfg_ll_id, uint, 0664); +MODULE_PARM_DESC(cfg_ll_id, "\n cfg_ll_id\n"); + /*bit0: 0-> efuse, 1->no efuse; */ /*bit1: 1->ko loaded*/ /*bit2: 1-> value updated*/ @@ -239,6 +272,8 @@ int get_dv_support_info(void) } EXPORT_SYMBOL(get_dv_support_info); +char cur_crc[32] = "invalid"; + static uint dolby_vision_on_count; static bool dolby_vision_el_disable; @@ -266,6 +301,7 @@ static bool dolby_vision_el_disable; #define FLAG_COPY_CORE1S0 0x2000000 #define FLAG_MUTE 0x4000000 #define FLAG_FORCE_HDMI_PKT 0x8000000 +#define FLAG_RX_EMP_VSEM 0x20000000 #define FLAG_TOGGLE_FRAME 0x80000000 #define FLAG_FRAME_DELAY_MASK 0xf @@ -324,10 +360,11 @@ static bool force_reset_core2; static int core1_switch; static int core3_switch; static bool force_set_lut; +static bool ambient_update; +static struct ambient_cfg_s ambient_config_new; /*core reg must be set at first time. bit0 is for core2, bit1 is for core3*/ static u32 first_reseted; - static char *ko_info; module_param(vtotal_add, uint, 0664); @@ -343,19 +380,11 @@ module_param(g_vtiming, uint, 0664); MODULE_PARM_DESC(g_vtiming, "\n vpotch\n"); static unsigned int dolby_vision_target_min = 50; /* 0.0001 */ -#ifdef V2_4 static unsigned int dolby_vision_target_max[3][3] = { { 4000, 1000, 100 }, /* DOVI => DOVI/HDR/SDR */ { 1000, 1000, 100 }, /* HDR => DOVI/HDR/SDR */ { 600, 1000, 100 }, /* SDR => DOVI/HDR/SDR */ }; -#else -static unsigned int dolby_vision_target_max[3][3] = { - { 4000, 4000, 100 }, /* DOVI => DOVI/HDR/SDR */ - { 1000, 1000, 100 }, /* HDR => DOVI/HDR/SDR */ - { 600, 1000, 100 }, /* SDR => DOVI/HDR/SDR */ -}; -#endif static unsigned int dolby_vision_default_max[3][3] = { { 4000, 4000, 100 }, /* DOVI => DOVI/HDR/SDR */ @@ -408,7 +437,15 @@ static unsigned int dolby_vision_graphics_priority; module_param(dolby_vision_graphics_priority, uint, 0664); MODULE_PARM_DESC(dolby_vision_graphics_priority, "\n dolby_vision_graphics_priority\n"); -uint16_t L2PQ_100_500[] = { +/*1:HDR10, 2:HLG, 3: DV LL*/ +static int force_hdmin_fmt; +static unsigned int atsc_sei; +module_param(atsc_sei, uint, 0664); +MODULE_PARM_DESC(atsc_sei, "\n atsc_sei\n"); + +static struct dv_atsc p_atsc_md; + +u16 L2PQ_100_500[] = { 2081, /* 100 */ 2157, /* 120 */ 2221, /* 140 */ @@ -432,7 +469,7 @@ uint16_t L2PQ_100_500[] = { 2771, /* 500 */ }; -uint16_t L2PQ_500_4000[] = { +u16 L2PQ_500_4000[] = { 2771, /* 500 */ 2852, /* 600 */ 2920, /* 700 */ @@ -471,114 +508,191 @@ uint16_t L2PQ_500_4000[] = { 3697, /* 4000 */ }; -static uint32_t tv_max_lin = 200; -static uint16_t tv_max_pq = 2372; +static u32 tv_max_lin = 200; +static u16 tv_max_pq = 2372; static unsigned int panel_max_lumin = 350; module_param(panel_max_lumin, uint, 0664); MODULE_PARM_DESC(panel_max_lumin, "\n panel_max_lumin\n"); -#ifdef V1_5 -struct TargetDisplayConfig def_tgt_display_cfg = { - 4095, /* gain */ - 0, /* offset */ - 39322, /* gamma */ - 0, /* eotf */ - 12, /* bitDepth */ - 0, /* rangeSpec */ - 42, /* diagSize */ - 2771, /* maxPq */ - 62, /* minPq */ - 2048, /* mSWeight */ - 16380, /* mSEdgeWeight */ - 0, /* minPQBias */ - 0, /* midPQBias */ - 0, /* maxPQBias */ - 0, /* trimSlopeBias */ - 0, /* trimOffsetBias */ - 0, /* trimPowerBias */ - 0, /* msWeightBias */ - 0, /* brightness */ - 0, /* contrast */ - 0, /* chromaWeightBias */ - 0, /* saturationGainBias */ - 2048, /* chromaWeight */ - 2048, /* saturationGain */ - 655, /* crossTalk */ - 0, /* tuningMode */ - 0, /* reserved0 */ - 0, /* dbgExecParamsPrintPeriod */ - 0, /* dbgDmMdPrintPeriod */ - 0, /* dbgDmCfgPrintPeriod */ - 2771, /* maxPq_dupli */ - 62, /* minPq_dupli */ - 12288, /* keyWeight */ - 24576, /* intensityVectorWeight */ - 24576, /* chromaVectorWeight */ - 0, /* chip_fpga_lowcomplex */ - { - -245, - -208, - -171, - -130, - -93, - -56, - -19, - 20, - 57, - 94, - 131, - 172, - 209, - 246, - }, - { - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - }, +static unsigned int sdr_ref_mode; +module_param(sdr_ref_mode, uint, 0664); +MODULE_PARM_DESC(sdr_ref_mode, "\n sdr_ref_mode\n"); + +static unsigned int ambient_test_mode; +module_param(ambient_test_mode, uint, 0664); +MODULE_PARM_DESC(ambient_test_mode, "\n ambient_test_mode\n"); + +static int content_fps = 24; +static int gd_rf_adjust; +static int enable_vf_check; +static u32 last_vf_valid_crc; + +#define MAX_DV_PICTUREMODES 40 +struct pq_config *bin_to_cfg; + +static struct dv_cfg_info_s cfg_info[MAX_DV_PICTUREMODES]; + +static s16 pq_center[MAX_DV_PICTUREMODES][4]; +struct dv_pq_range_s pq_range[4]; +u8 current_vsvdb[7]; + +#define USE_CENTER_0 0 + +int num_picture_mode; +static int default_pic_mode = 1;/*bright(standard) mode as default*/ +static int cur_pic_mode;/*current picture mode id*/ +static bool load_bin_config; +static bool need_update_cfg; + +static const s16 EXTER_MIN_PQ = -256; +static const s16 EXTER_MAX_PQ = 256; +static const s16 INTER_MIN_PQ = -4096; +static const s16 INTER_MAX_PQ = 4095; + +#define LEFT_RANGE_BRIGHTNESS (-3074) /*limit the range*/ +#define RIGHT_RANGE_BRIGHTNESS (3074) +#define LEFT_RANGE_CONTRAST (-3074) +#define RIGHT_RANGE_CONTRAST (3074) +#define LEFT_RANGE_COLORSHIFT (-3074) +#define RIGHT_RANGE_COLORSHIFT (3074) +#define LEFT_RANGE_SATURATION (-3074) +#define RIGHT_RANGE_SATURATION (3074) + +const char *pq_item_str[] = {"brightness", + "contrast", + "colorshift", + "saturation"}; + +const char *eotf_str[] = {"bt1886", "pq", "power"}; + +static u32 cur_debug_tprimary[3][2]; +static int debug_tprimary; + +/*0: set exter pq [-256,256]. 1:set inter pq [-4096,4095]*/ +static int set_inter_pq; +static DEFINE_SPINLOCK(cfg_lock); + +#define AMBIENT_CFG_FRAMES 46 +struct ambient_cfg_s ambient_test_cfg[AMBIENT_CFG_FRAMES] = { + /* update_flag, ambient, rear, front, whitex, whitey */ + { 12, 65536, 0, 0, 0, 0 }, + { 4, 0, 0, 0, 32768, 0 }, + { 4, 0, 0, 0, 0, 32768 }, + { 4, 0, 0, 0, 32768, 32768 }, + { 6, 0, 0, 0, 10246, 10780 }, + { 2, 0, 10000, 0, 0, 0 }, + { 3, 0, 5, 0, 0, 0 }, + { 1, 0, 0, 30000, 0, 0 }, + { 8, 0, 0, 0, 0, 0 }, + { 8, 65536, 0, 0, 0, 0 }, + { 7, 0, 2204, 23229, 589, 30638 }, + { 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0 }, + { 1, 0, 0, 24942, 0, 0 }, + { 7, 0, 4646, 25899, 31686, 9764 }, + { 0, 0, 0, 0, 0, 0 }, + { 4, 0, 0, 0, 491, 30113 }, + { 4, 0, 0, 0, 11632, 13402 }, + { 4, 0, 0, 0, 22282, 31162 }, + { 6, 0, 6276, 0, 98, 16056 }, + { 6, 0, 5276, 0, 8454, 6946 }, + { 2, 0, 6558, 0, 0, 0 }, + { 2, 0, 355, 0, 0, 0 }, + { 7, 0, 6898, 9651, 30539, 17104 }, + { 3, 0, 5558, 838, 0, 0 }, + { 5, 0, 0, 8462, 7438, 655 }, + { 8, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0 }, + { 9, 65536, 0, 12792, 0, 0 }, + { 4, 0, 0, 0, 30179, 14909 }, + { 3, 0, 1287, 16711, 0, 0 }, + { 7, 0, 991, 9667, 14450, 9699 }, + { 4, 0, 0, 0, 12746, 5636 }, + { 2, 0, 1382, 0, 0, 0 }, + { 1, 0, 0, 14647, 0, 0 }, + { 2, 0, 9080, 0, 0, 0 }, + { 4, 0, 0, 0, 21921, 16056 }, + { 3, 0, 6840, 13834, 0, 0 }, + { 5, 0, 0, 21597, 25755, 26673 }, + { 0, 0, 0, 0, 0, 0 }, + { 5, 0, 0, 19217, 17825, 17989 }, + { 6, 0, 2185, 0, 13828, 5406 }, + { 2, 0, 3587, 0, 0, 0 }, + { 5, 0, 0, 17788, 3571, 28508 }, + { 4, 0, 0, 0, 32636, 5799 } +}; + +/*tv cert: OTT mode/HDMI MODE(5010~5013 and 5232,5272,5332) use this cfg*/ +struct target_config def_tgt_display_cfg = { + 39322, + 0, + 0, + 2771, + 62, + 2771, + 1311, + 131072000, + 131072000, { - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, + 42949672, + 22145926, + 20132660, + 40265320, + 10066330, + 4026532, + 20984942, + 22078816 }, + 2048, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 4095, + 0, + 0, + 0, { + 1, + 13, + 131072000, + 1310720, + 82897208, + 4095, + 2048, + 0, + 1, + { + {5960, 20047, 2023}, + {-3286, -11052, 14336}, + {14336, -13022, -1316} + }, + 15, + 1, + {2048, 16384, 16384}, + 414486, + 82897, 0, + 5, + 2771, + 1015, 0, 0, 0, + 4095, + 4095, 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, + 444596224, + {0, 0, 0} }, { 0, @@ -589,161 +703,126 @@ struct TargetDisplayConfig def_tgt_display_cfg = { 0, 0, 0, - 0, - 0, - 0, - 0, - 0, - 0, + {0, 0, 0} }, { - -3685, - -3070, - -2456, - -1842, - -1228, - -613, - 0, - 0, - 0, - 0, - 0, + 65536, 0, + 4096, + 5, + 4096, + {10247, 10781}, + 32768, + 3277, 0, - 0, - }, - { - 1, /* gdEnable */ - 6553, /* gdWMin */ - 131072000, /* gdWMax */ - 26214400, /* gdWMm */ - 16579442, /* gdWDynRngSqrt */ - 4096, /* gdWeightMean */ - 4096, /* gdWeightStd */ - 0, /* gdDelayMilliSec_hdmi */ - 1, /* gdRgb2YuvExt */ - { - {5960, 20047, 2023}, - {-3286, -11052, 14336}, - {14336, -13022, -1316} - }, /* gdM33Rgb2Yuv[3][3] */ - 15, /* gdM33Rgb2YuvScale2P */ - 1, /* gdRgb2YuvOffExt */ - {2048, 16384, 16384},/* gdV3Rgb2YuvOff[3] */ - 2072430, /* gdUpBound */ - 414486, /* gdLowBound */ - 0, /* lastMaxPq */ - 137, /*gdWMinPq */ - 2771, /*gdWMaxPq */ - 2081, /*gdWMmPq */ - 0, /*gdTriggerPeriod */ - 0, /* gdTriggerLinThresh */ - 0, /* gdDelayMilliSec_ott */ -#ifdef V1_5 - {0, 0, 0, 0, 0, 0}, -#else - {0, 0, 0, 0, 0, 0, 0, 0, 0} -#endif + 1365, + 1365 }, -#ifdef V1_5 - {0, 0, 0, 68, 124, 49, 230}, - {0, 0, 0, 0, 0}, -#endif - 1311, /* min_lin */ - 131072000, /* max_lin */ - 0, /* backlight_scaler */ - 1311, /* min_lin_dupli */ - 131072000, /* max_lin_dupli */ + /*{0, 0, 0, 68, 124, 49, 230},*/ + {4, 216, 163, 84, 218, 76, 153}, + 1, + 2, + 0, + {0}, + 0, { - /* lms2RgbMat[3][3] */ { {22416, -19015, 695}, {-4609, 9392, -688}, {122, -791, 4765} }, - 12, /* lms2RgbMatScale */ - {128, 128, 128}, /* whitePoint */ - 7, /* whitePointScale */ - {0, 0, 0} /* reserved[3] */ + 12, + {0, 0, 0}, + 0, + {0, 0, 0} }, - 0, /* reserved00 */ - 0, /* brightnessPreservation */ - 81920, /* iintensityVectorWeight */ - 24576, /* ichromaVectorWeight */ - 0, /* isaturationGainBias */ - 0, /* chip_12b_ocsc */ - 0, /* chip_512_tonecurve */ - 0, /* chip_nolvl5 */ - {0, 0, 0, 0, 0, 0, 0, 0} /* padding[8] */ + 4096, + 1, + 1, + {50, 100, 300, 500, 800, 1000, 2000, 3000}, + {65536, 65536, 65536, 65536, 65536, 65536, 65536, 65536}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + 0, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0} /* padding */ }; -struct TargetDisplayConfig def_tgt_display_cfg_ll = { - 4095, /* gain */ - 0, /* offset */ - 39322, /* gamma */ - 2, /* eotf */ - 12, /* bitDepth */ - 0, /* rangeSpec */ - 42, /* diagSize */ - 2873, /* maxPq */ - 263, /* minPq */ - 2048, /* mSWeight */ - 16380, /* mSEdgeWeight */ - 0, /* minPQBias */ - 0, /* midPQBias */ - 0, /* maxPQBias */ - 0, /* trimSlopeBias */ - 0, /* trimOffsetBias */ - 0, /* trimPowerBias */ - 0, /* msWeightBias */ - 0, /* brightness */ - 0, /* contrast */ - 0, /* chromaWeightBias */ - 0, /* saturationGainBias */ - 2048, /* chromaWeight */ - 2048, /* saturationGain */ - 655, /* crossTalk */ - 0, /* tuningMode */ - 0, /* reserved0 */ - 0, /* dbgExecParamsPrintPeriod */ - 0, /* dbgDmMdPrintPeriod */ - 0, /* dbgDmCfgPrintPeriod */ - 2873, /* maxPq_dupli */ - 263, /* minPq_dupli */ - 12288, /* keyWeight */ - 24576, /* intensityVectorWeight */ - 24576, /* chromaVectorWeight */ - 0, /* chip_fpga_lowcomplex */ + +struct target_config def_tgt_display_cfg_bestpq = { + 36045, + 2, + 0, + 2920, + 88, + 2920, + 2621, + 183500800, + 183500800, { - -245, - -208, - -171, - -130, - -93, - -56, - -19, - 20, - 57, - 94, - 131, - 172, - 209, - 246, + 45305196, + 20964810, + 17971754, + 43708004, + 10415296, + 3180960, + 20984942, + 22078816 }, + 2048, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1229, + 0, + 0, + 0, + 4095, + 0, + 0, + 0, { 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, + 131, + 183500800, + 13107200, + 82897208, + 4095, + 2048, + 100, + 1, + { + {5961, 20053, 2024}, + {-3287, -11053, 14340}, + {14340, -13026, -1313} + }, + 15, + 1, + {2048, 16384, 16384}, + 580280, + 82897, + 0, + 17, + 2920, + 1803, + 0, + 0, + 50, + 3276, + 3276, + 200, + 444596224, + {0, 0, 0} }, { 0, @@ -754,28 +833,126 @@ struct TargetDisplayConfig def_tgt_display_cfg_ll = { 0, 0, 0, - 0, - 0, - 0, - 0, - 0, - 0, + {0, 0, 0} }, { + 65536, 0, + 4096, + 5, + 4096, + {10247, 10781}, + 32768, + 3277, 0, + 1365, + 1365 + }, + {4, 216, 163, 84, 218, 76, 153}, + 0, + 2, + 0, + {0}, + 0, + { + { + {18835, -15103, 363}, + {-3457, 8025, -472}, + {155, -605, 4546} + }, + 12, + {0, 0, 0}, 0, + {0, 0, 0} + }, + 4096, + 1, + 1, + {50, 100, 300, 500, 800, 1000, 2000, 3000}, + {65536, 65536, 65536, 65536, 65536, 65536, 65536, 65536}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + 0, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0} /* padding */ +}; + +/*tv cert: DV LL case 5053 use this cfg */ +struct target_config def_tgt_display_cfg_ll = { + 39322, + 2, + 0, + 3895, + 26, + 3246, + 262, + 1651507200, + 381117088, + { + 44922672, + 22152636, + 17844246, + 44969648, + 9489194, + 3342022, + 20984942, + 22078816 + }, + 2048, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 4095, + 0, + 0, + 0, + 4095, + 0, + 0, + 0, + { + 1, 0, + 1651507200, + 1310720, + 657976192, + 4095, + 2048, 0, + 1, + { + {5967, 20067, 2026}, + {-3289, -11061, 14350}, + {14350, -13034, -1316} + }, + 15, + 1, + {2048, 16384, 16384}, + 657976, + 10444, 0, 0, + 3895, + 1015, 0, 0, 0, + 1400, + 2940, 0, - 0, - 0, - 0, + 2239627264u, + {0, 0, 0} }, { 0, @@ -786,163 +963,126 @@ struct TargetDisplayConfig def_tgt_display_cfg_ll = { 0, 0, 0, - 0, - 0, - 0, - 0, - 0, - 0, + {0, 0, 0} }, { - -3685, - -3070, - -2456, - -1842, - -1228, - -613, - 0, - 0, 0, 0, + 4096, + 5, + 4096, + {10247, 10781}, + 32768, + 3277, 0, - 0, - 0, - 0, - }, - { - 1, /* gdEnable */ - 4452, /* gdWMin */ - 165150720, /* gdWMax */ - 26214400, /* gdWMm */ - 20114920, /* gdWDynRngSqrt */ - 4096, /* gdWeightMean */ - 4096, /* gdWeightStd */ - 0, /* gdDelayMilliSec_hdmi */ - 1, /* gdRgb2YuvExt */ - { - {5967, 20067, 2026}, - {-3289, -11061, 14350}, - {14350, -13034, -1316} - }, /* gdM33Rgb2Yuv[3][3] */ - 15, /* gdM33Rgb2YuvScale2P */ - 1, /* gdRgb2YuvOffExt */ - {2048, 16384, 16384},/* gdV3Rgb2YuvOff[3] */ - 2152296, /* gdUpBound */ - 341634, /* gdLowBound */ - 0, /* lastMaxPq */ - 114, /*gdWMinPq */ - 2873, /*gdWMaxPq */ - 2081, /*gdWMmPq */ - 0, /*gdTriggerPeriod */ - 0, /* gdTriggerLinThresh */ - 0, /* gdDelayMilliSec_ott */ -#ifdef V1_5 - {0, 0, 0, 0, 0, 0}, -#else - {0, 0, 0, 0, 0, 0, 0, 0, 0} -#endif + 1365, + 1365 }, -#ifdef V1_5 - {36, 23, 83, 181, 139, 88, 101}, - {0, 0, 0, 0, 0}, -#endif - 28049, /* min_lin */ - 165150720, /* max_lin */ - 0, /* backlight_scaler */ - 28049, /* min_lin_dupli */ - 165150720, /* max_lin_dupli */ + {72, 15, 234, 136, 88, 92, 173}, + 1, + 2, + 0, + {0}, + 0, { - /* lms2RgbMat[3][3] */ { {17486, -13950, 560}, {-4081, 8776, -599}, {257, -562, 4401} }, - 12, /* lms2RgbMatScale */ - {128, 128, 128}, /* whitePoint */ - 7, /* whitePointScale */ - {0, 0, 0} /* reserved[3] */ + 12, + {0, 0, 0}, + 0, + {0, 0, 0} }, - 0, /* reserved00 */ - 0, /* brightnessPreservation */ - 81920, /* iintensityVectorWeight */ - 24576, /* ichromaVectorWeight */ - 0, /* isaturationGainBias */ - 0, /* chip_12b_ocsc */ - 0, /* chip_512_tonecurve */ - 0, /* chip_nolvl5 */ - {0, 0, 0, 0, 0, 0, 0, 0} /* padding[8] */ + 4096, + 1, + 1, + {50, 100, 300, 500, 800, 1000, 2000, 3000}, + {65536, 65536, 65536, 65536, 65536, 65536, 65536, 65536}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + 0, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0} /* padding */ }; -#else -struct TargetDisplayConfig def_tgt_display_cfg = { - 2048, /* gain */ - 4095, /* offset */ - 39322, /* gamma */ - 0, /* eotf */ - 12, /* bitDepth */ - 0, /* rangeSpec */ - 42, /* diagSize */ - 2372, /* maxPq */ - 62, /* minPq */ - 2048, /* mSWeight */ - 16380, /* mSEdgeWeight */ - 0, /* minPQBias */ - 0, /* midPQBias */ - 0, /* maxPQBias */ - 0, /* trimSlopeBias */ - 0, /* trimOffsetBias */ - 0, /* trimPowerBias */ - 0, /* msWeightBias */ - 0, /* brightness */ - 0, /* contrast */ - 0, /* chromaWeightBias */ - 0, /* saturationGainBias */ - 2048, /* chromaWeight */ - 2048, /* saturationGain */ - 655, /* crossTalk */ - 0, /* tuningMode */ - 0, /* reserved0 */ - 0, /* dbgExecParamsPrintPeriod */ - 0, /* dbgDmMdPrintPeriod */ - 0, /* dbgDmCfgPrintPeriod */ - 2372, /* maxPq_dupli */ - 62, /* minPq_dupli */ - 12288, /* keyWeight */ - 24576, /* intensityVectorWeight */ - 24576, /* chromaVectorWeight */ - 0, /* chip_fpga_lowcomplex */ +/*tv cert: DV LL case 5052 use this cfg */ +struct target_config def_tgt_display_cfg_ll_1 = { + 36045, + 0, + 0, + 3027, + 159, + 2383, + 8913, + 233308160, + 53840348, { - -245, - -207, - -169, - -131, - -94, - -56, - -18, - 19, - 57, - 95, - 132, - 170, - 208, - 246, + 42781900, + 22434494, + 20179636, + 41016936, + 10153572, + 3684277, + 20984942, + 22078816 }, + 2048, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 4095, + 0, + 0, + 0, + 4095, + 0, + 0, + 0, { + 1, + 50, + 233308160, + 1310720, + 42412656, + 4095, + 2048, + 0, + 1, + { + {5961, 20053, 2024}, + {-3287, -11053, 14340}, + {14340, -13026, -1313} + }, + 15, + 1, + {2048, 16384, 16384}, + 1442030, + 162025, 0, + 10, + 3027, + 1015, 0, 0, 0, + 4095, + 4095, 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, + 2567036928u, + {0, 0, 0} }, { 0, @@ -953,44 +1093,126 @@ struct TargetDisplayConfig def_tgt_display_cfg = { 0, 0, 0, - 0, - 0, - 0, - 0, - 0, - 0, + {0, 0, 0} }, { 0, 0, + 4096, + 5, + 4096, + {10247, 10781}, + 32768, + 3277, 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, + 1365, + 1365 }, + {72, 63, 122, 154, 56, 31, 182}, + 1, + 2, + 0, + {0}, + 0, { + { + {22406, -18942, 632}, + {-4730, 9453, -627}, + {81, -650, 4665} + }, + 12, + {0, 0, 0}, 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, + {0, 0, 0} + }, + 4096, + 1, + 1, + {50, 100, 300, 500, 800, 1000, 2000, 3000}, + {65536, 65536, 65536, 65536, 65536, 65536, 65536, 65536}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + 0, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0} /* padding */ +}; + +/*tv cert: DV LL case 5051 and 5055 use this cfg */ +struct target_config def_tgt_display_cfg_ll_2 = { + 36045, + 2, + 0, + 2920, + 88, + 2920, + 2621, + 183500800, + 183500800, + { + 45305196, + 20964810, + 17971754, + 43708004, + 10415296, + 3180960, + 20984942, + 22078816 + }, + 2048, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + { + 1, + 187, + 183500800, + 13107200, + 69356784, + 4095, + 2048, + 100, + 1, + { + {5961, 20053, 2024}, + {-3287, -11053, 14340}, + {14340, -13026, -1313} + }, + 15, + 1, + {2048, 16384, 16384}, + 693567, + 99081, + 0, + 21, + 2920, + 1803, + 0, + 0, + 50, + 3276, + 3276, + 200, + 1170210816u, + {0, 0, 0} }, { 0, @@ -1001,80 +1223,74 @@ struct TargetDisplayConfig def_tgt_display_cfg = { 0, 0, 0, + {0, 0, 0} + }, + { 0, 0, + 4096, + 5, + 4096, + {10247, 10781}, + 32768, + 3277, 0, - 0, - 0, - 0, + 1365, + 1365 }, + {42, 25, 25, 241, 138, 78, 108}, + 1, + 2, + 0, + {0}, + 0, { - 0, /* gdEnable */ - 262, /* gdWMin */ - 131072000, /* gdWMax */ - 26214400, /* gdWMm */ - 82897211, /* gdWDynRngSqrt */ - 4096, /* gdWeightMean */ - 4096, /* gdWeightStd */ - 0, /* gdDelayMilliSec_hdmi */ - 1, /* gdRgb2YuvExt */ { - {5960, 20047, 2023}, - {-3286, -11052, 14336}, - {14336, -13022, -1316} - }, /* gdM33Rgb2Yuv[3][3] */ - 15, /* gdM33Rgb2YuvScale2P */ - 1, /* gdRgb2YuvOffExt */ - {2048, 16384, 16384},/* gdV3Rgb2YuvOff[3] */ - 414486, /* gdUpBound */ - 82897, /* gdLowBound */ - 0, /* lastMaxPq */ - 26, /*gdWMinPq */ - 2771, /*gdWMaxPq */ - 2081, /*gdWMmPq */ - 0, /*gdTriggerPeriod */ - 0, /* gdTriggerLinThresh */ - 0, /* gdDelayMilliSec_ott */ -#ifdef V1_5 - {0, 0, 0, 0, 0, 0}, -#else - {0, 0, 0, 0, 0, 0, 0, 0, 0} -#endif + {18835, -15103, 363}, + {-3457, 8025, -472}, + {155, -605, 4546} + }, + 12, + {0, 0, 0}, + 0, + {0, 0, 0} }, -#ifdef V1_5 + 4096, + 1, + 1, + {50, 100, 300, 500, 800, 1000, 2000, 3000}, + {65536, 65536, 65536, 65536, 65536, 65536, 65536, 65536}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, + 0, {0, 0, 0, 0, 0}, -#endif - 1311, /* min_lin */ - 200 << 18, /* max_lin 131072000 */ - 4096, /* backlight_scaler */ - 1311, /* min_lin_dupli */ - 200 << 18, /* max_lin_dupli 131072000 */ - { - /* lms2RgbMat[3][3] */ - { - {17507, -14019, 608}, - {-3765, 8450, -589}, - {285, -640, 4451} - }, - 12, /* lms2RgbMatScale */ - {128, 128, 128}, /* whitePoint */ - 7, /* whitePointScale */ - {0, 0, 0} /* reserved[3] */ - }, - 0, /* reserved00 */ - 0, /* brightnessPreservation */ - 81920, /* iintensityVectorWeight */ - 24576, /* ichromaVectorWeight */ - 0, /* isaturationGainBias */ - 0, /* chip_12b_ocsc */ - 0, /* chip_512_tonecurve */ - 0, /* chip_nolvl5 */ - {0, 0, 0, 0, 0, 0, 0, 0} /* padding[8] */ + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0} /* padding */ +}; + +struct target_config *DV_cfg_ll[3] = { + /*tv cert: DV LL case 5053 use this cfg */ + &def_tgt_display_cfg_ll, + /*tv cert: DV LL case 5052 use this cfg */ + &def_tgt_display_cfg_ll_1, + /*tv cert: DV LL case 5051 and 5055 use this cfg */ + &def_tgt_display_cfg_ll_2 +}; + +struct target_config *DV_cfg[2] = { + /*tv cert: OTT mode/HDMI mode(DV STD)use this cfg*/ + &def_tgt_display_cfg, + /*tv cert: DV LL case 5051 and 5055 use this cfg */ + &def_tgt_display_cfg_ll_2 }; -#endif -static unsigned int debug_dolby; +unsigned int debug_dolby; module_param(debug_dolby, uint, 0664); MODULE_PARM_DESC(debug_dolby, "\n debug_dolby\n"); @@ -1099,18 +1315,21 @@ MODULE_PARM_DESC(debug_dolby_frame, "\n debug_dolby_frame\n"); (debug_dolby & 0x80)) #define DV_CORE1_RECONFIG_CNT 2 +#define DV_CORE2_RECONFIG_CNT 120 static bool dolby_vision_on; static bool dolby_vision_core1_on; static u32 dolby_vision_core1_on_cnt; static bool dolby_vision_wait_on; +static u32 dolby_vision_core2_on_cnt; module_param(dolby_vision_wait_on, bool, 0664); MODULE_PARM_DESC(dolby_vision_wait_on, "\n dolby_vision_wait_on\n"); static bool dolby_vision_on_in_uboot; static bool dolby_vision_wait_init; static unsigned int frame_count; -static struct hdr10_param_s hdr10_param; +static struct hdr10_parameter hdr10_param; +static struct hdr10_parameter last_hdr10_param; static struct master_display_info_s hdr10_data; static char *md_buf[2]; @@ -1118,7 +1337,13 @@ static char *comp_buf[2]; static char *drop_md_buf[2]; static char *drop_comp_buf[2]; +#define VSEM_IF_BUF_SIZE 4096 +static char *vsem_if_buf;/* buffer for vsem or vsif */ +static char *vsem_md_buf; +#define VSEM_PKT_SIZE 31 + static int current_id = 1; + static int backup_comp_size; static int backup_md_size; static struct dovi_setting_s dovi_setting; @@ -1127,47 +1352,67 @@ static struct dovi_setting_s new_dovi_setting; void *pq_config_fake; struct tv_dovi_setting_s *tv_dovi_setting; static bool pq_config_set_flag; -struct ui_menu_params_s menu_param = {50, 50, 50}; + +static bool best_pq_config_set_flag; +struct ui_menu_params menu_param = {50, 50, 50}; static bool tv_dovi_setting_change_flag; static bool tv_dovi_setting_update_flag; static bool dovi_setting_video_flag; static struct platform_device *dovi_pdev; static bool vsvdb_config_set_flag; -/* general control config change */ -#define FLAG_CHANGE_CFG 0x000001 -/* general metadata change */ -#define FLAG_CHANGE_MDS 0x000002 -/* metadata config (below level 2) change */ -#define FLAG_CHANGE_MDS_CFG 0x000004 -/* global dimming change */ -#define FLAG_CHANGE_GD 0x000008 -/* tone curve lut change */ -#define FLAG_CHANGE_TC 0x000010 -/* 2nd tone curve (graphics) lut change */ -#define FLAG_CHANGE_TC2 0x000020 -/* L2NL lut change (for DM3.1) */ -#define FLAG_CHANGE_L2NL 0x000040 -/* 3D lut change (for DM2.12) */ -#define FLAG_CHANGE_3DLUT 0x000080 -/* 0xX00000 for other status */ -/* (video) tone mapping to a constant */ -#define FLAG_CONST_TC 0x100000 -/* 2nd tone mapping to a constant */ -#define FLAG_CONST_TC2 0x200000 -#define FLAG_CHANGE_ALL 0xffffffff +#define CP_FLAG_CHANGE_CFG 0x000001 +#define CP_FLAG_CHANGE_MDS 0x000002 +#define CP_FLAG_CHANGE_MDS_CFG 0x000004 +#define CP_FLAG_CHANGE_GD 0x000008 +#define CP_FLAG_CHANGE_TC 0x000010 +#define CP_FLAG_CHANGE_TC2 0x000020 +#define CP_FLAG_CHANGE_L2NL 0x000040 +#define CP_FLAG_CHANGE_3DLUT 0x000080 +#define CP_FLAG_CONST_TC 0x100000 +#define CP_FLAG_CONST_TC2 0x200000 +#define CP_FLAG_CHANGE_ALL 0xffffffff /* update all core */ -static u32 stb_core_setting_update_flag = FLAG_CHANGE_ALL; +static u32 stb_core_setting_update_flag = CP_FLAG_CHANGE_ALL; static bool stb_core2_const_flag; /* 256+(256*4+256*2)*4/8 64bit */ #define STB_DMA_TBL_SIZE (256+(256*4+256*2)*4/8) -static uint64_t stb_core1_lut[STB_DMA_TBL_SIZE]; +static u64 stb_core1_lut[STB_DMA_TBL_SIZE]; static bool tv_mode; static bool mel_mode; static bool osd_update; static bool enable_fel; +static u32 tv_backlight; +static bool tv_backlight_changed; +static bool tv_backlight_force_update; +static int force_disable_dv_backlight; +static bool dv_control_backlight_status; +static bool bypass_all_vpp_pq; +static int use_target_lum_from_cfg = true; + +/*0: not debug mode; 1:force bypass vpp pq; 2:force enable vpp pq*/ +/*3: force do nothing*/ +static u32 debug_bypass_vpp_pq; + +static int bl_delay_cnt; +static int set_backlight_delay_vsync = 2; +module_param(set_backlight_delay_vsync, int, 0664); +MODULE_PARM_DESC(set_backlight_delay_vsync, "\n set_backlight_delay_vsync\n"); + +s16 brightness_off[8][2] = { + {0, 150}, /* DV OTT DM3, DM4 */ + {0, 150}, /* DV Sink-led DM3, DM4 */ + {0, 0}, /* DV Source-led DM3, DM4, actually no dm3 for source-led*/ + {0, 300}, /* HDR OTT DM3, DM4, actually no dm3 for HDR */ + {0, 0}, /* HLG OTT DM3, DM4, actually no dm3 for HLG */ + {0, 0}, /* reserved1 */ + {0, 0}, /* reserved2 */ + {0, 0}, /* reserved3 */ +}; + +struct tv_input_info_s *tv_input_info; static bool module_installed; @@ -1214,7 +1459,7 @@ static bool is_meson_txlx(void) static bool is_meson_txlx_tvmode(void) { - if ((is_meson_txlx()) && (tv_mode == 1)) + if (is_meson_txlx() && tv_mode == 1) return true; else return false; @@ -1222,7 +1467,7 @@ static bool is_meson_txlx_tvmode(void) static bool is_meson_txlx_stbmode(void) { - if ((is_meson_txlx()) && (tv_mode == 0)) + if (is_meson_txlx() && tv_mode == 0) return true; else return false; @@ -1231,7 +1476,7 @@ static bool is_meson_txlx_stbmode(void) static bool is_meson_tm2(void) { if (dv_meson_dev.cpu_id == _CPU_MAJOR_ID_TM2 || - dv_meson_dev.cpu_id == _CPU_MAJOR_ID_TM2_REVB) + dv_meson_dev.cpu_id == _CPU_MAJOR_ID_TM2_REVB) return true; else return false; @@ -1247,7 +1492,7 @@ static bool is_meson_tm2_revb(void) static bool is_meson_tm2_tvmode(void) { - if ((is_meson_tm2()) && (tv_mode == 1)) + if (is_meson_tm2() && tv_mode == 1) return true; else return false; @@ -1255,7 +1500,7 @@ static bool is_meson_tm2_tvmode(void) static bool is_meson_tm2_stbmode(void) { - if ((is_meson_tm2()) && (tv_mode == 0)) + if (is_meson_tm2() && tv_mode == 0) return true; else return false; @@ -1265,7 +1510,7 @@ static bool is_meson_tm2_stb_hdmimode(void) { if ((is_meson_tm2_stbmode()) && module_installed && tv_dovi_setting && - (tv_dovi_setting->input_mode == INPUT_MODE_HDMI) && + (tv_dovi_setting->input_mode == IN_MODE_HDMI) && hdmi_to_stb_policy) return true; else @@ -1386,40 +1631,40 @@ static unsigned int amdolby_vision_poll(struct file *file, poll_table *wait) return mask; } -static void dump_tv_setting( - struct tv_dovi_setting_s *setting, - int frame_cnt, int debug_flag) +static void dump_tv_setting + (struct tv_dovi_setting_s *setting, + int frame_cnt, int debug_flag) { int i; - uint64_t *p; + u64 *p; if ((debug_flag & 0x10) && dump_enable) { pr_info("\nreg\n"); - p = (uint64_t *)&setting->core1_reg_lut[0]; + p = (u64 *)&setting->core1_reg_lut[0]; for (i = 0; i < 222; i += 2) - pr_info("%016llx, %016llx,\n", p[i], p[i+1]); + pr_info("%016llx, %016llx,\n", p[i], p[i + 1]); } if ((debug_flag & 0x20) && dump_enable) { pr_info("\ng2l_lut\n"); - p = (uint64_t *)&setting->core1_reg_lut[0]; + p = (u64 *)&setting->core1_reg_lut[0]; for (i = 222; i < 222 + 256; i += 2) - pr_info("%016llx %016llx\n", p[i], p[i+1]); + pr_info("%016llx %016llx\n", p[i], p[i + 1]); } if ((debug_flag & 0x40) && dump_enable) { pr_info("\n3d_lut\n"); - p = (uint64_t *)&setting->core1_reg_lut[0]; + p = (u64 *)&setting->core1_reg_lut[0]; for (i = 222 + 256; i < 222 + 256 + 3276; i += 2) - pr_info("%016llx %016llx\n", p[i], p[i+1]); + pr_info("%016llx %016llx\n", p[i], p[i + 1]); pr_info("\n"); } } void dolby_vision_update_pq_config(char *pq_config_buf) { - memcpy((struct pq_config_s *)pq_config_fake, - pq_config_buf, sizeof(struct pq_config_s)); + memcpy((struct pq_config *)pq_config_fake, + pq_config_buf, sizeof(struct pq_config)); pr_info("update_pq_config[%zu] %x %x %x %x\n", - sizeof(struct pq_config_s), + sizeof(struct pq_config), pq_config_buf[1], pq_config_buf[2], pq_config_buf[3], @@ -1429,10 +1674,8 @@ void dolby_vision_update_pq_config(char *pq_config_buf) void dolby_vision_update_vsvdb_config(char *vsvdb_buf, u32 tbl_size) { -#ifdef V2_4 if (tbl_size > sizeof(new_dovi_setting.vsvdb_tbl)) { - pr_info( - "update_vsvdb_config tbl size overflow %d\n", tbl_size); + pr_info("update_vsvdb_config tbl size overflow %d\n", tbl_size); return; } memset(&new_dovi_setting.vsvdb_tbl[0], @@ -1443,79 +1686,78 @@ void dolby_vision_update_vsvdb_config(char *vsvdb_buf, u32 tbl_size) new_dovi_setting.vsvdb_changed = 1; dolby_vision_set_toggle_flag(1); if (tbl_size >= 8) - pr_info( - "update_vsvdb_config[%d] %x %x %x %x %x %x %x %x\n", - tbl_size, - vsvdb_buf[0], - vsvdb_buf[1], - vsvdb_buf[2], - vsvdb_buf[3], - vsvdb_buf[4], - vsvdb_buf[5], - vsvdb_buf[6], - vsvdb_buf[7]); -#endif + pr_info + ("update_vsvdb_config[%d] %x %x %x %x %x %x %x %x\n", + tbl_size, + vsvdb_buf[0], + vsvdb_buf[1], + vsvdb_buf[2], + vsvdb_buf[3], + vsvdb_buf[4], + vsvdb_buf[5], + vsvdb_buf[6], + vsvdb_buf[7]); vsvdb_config_set_flag = true; } -static int prepare_stb_dolby_core1_reg( - uint32_t run_mode, - uint32_t *p_core1_dm_regs, - uint32_t *p_core1_comp_regs) +static int prepare_stb_dolby_core1_reg + (u32 run_mode, + u32 *p_core1_dm_regs, + u32 *p_core1_comp_regs) { int index = 0; int i; /* 4 */ - stb_core1_lut[index++] = ((uint64_t)4 << 32) | 4; - stb_core1_lut[index++] = ((uint64_t)4 << 32) | 4; - stb_core1_lut[index++] = ((uint64_t)3 << 32) | 1; - stb_core1_lut[index++] = ((uint64_t)2 << 32) | 1; + stb_core1_lut[index++] = ((u64)4 << 32) | 4; + stb_core1_lut[index++] = ((u64)4 << 32) | 4; + stb_core1_lut[index++] = ((u64)3 << 32) | 1; + stb_core1_lut[index++] = ((u64)2 << 32) | 1; /* 1 + 14 + 10 + 1 */ - stb_core1_lut[index++] = ((uint64_t)1 << 32) | run_mode; + stb_core1_lut[index++] = ((u64)1 << 32) | run_mode; for (i = 0; i < 14; i++) stb_core1_lut[index++] = - ((uint64_t)(6 + i) << 32) + ((u64)(6 + i) << 32) | p_core1_dm_regs[i]; for (i = 17; i < 27; i++) stb_core1_lut[index++] = - ((uint64_t)(6 + i) << 32) - | p_core1_dm_regs[i-3]; - stb_core1_lut[index++] = ((uint64_t)(6 + 27) << 32) | 0; + ((u64)(6 + i) << 32) + | p_core1_dm_regs[i - 3]; + stb_core1_lut[index++] = ((u64)(6 + 27) << 32) | 0; /* 173 + 1 */ for (i = 0; i < 173; i++) stb_core1_lut[index++] = - ((uint64_t)(6 + 44 + i) << 32) + ((u64)(6 + 44 + i) << 32) | p_core1_comp_regs[i]; - stb_core1_lut[index++] = ((uint64_t)3 << 32) | 1; + stb_core1_lut[index++] = ((u64)3 << 32) | 1; if (index & 1) { pr_dolby_error("stb core1 reg tbl odd size\n"); - stb_core1_lut[index++] = ((uint64_t)3 << 32) | 1; + stb_core1_lut[index++] = ((u64)3 << 32) | 1; } return index; } -static void prepare_stb_dolby_core1_lut(uint32_t base, uint32_t *p_core1_lut) +static void prepare_stb_dolby_core1_lut(u32 base, u32 *p_core1_lut) { - uint32_t *p_lut; + u32 *p_lut; int i; - p_lut = &p_core1_lut[256*4]; /* g2l */ + p_lut = &p_core1_lut[256 * 4]; /* g2l */ for (i = 0; i < 128; i++) { - stb_core1_lut[base+i] = - stb_core1_lut[base+i+128] = - ((uint64_t)p_lut[1] << 32) | - ((uint64_t)p_lut[0] & 0xffffffff); + stb_core1_lut[base + i] = + stb_core1_lut[base + i + 128] = + ((u64)p_lut[1] << 32) | + ((u64)p_lut[0] & 0xffffffff); p_lut += 2; } p_lut = &p_core1_lut[0]; /* 4 lut */ for (i = 256; i < 768; i++) { - stb_core1_lut[base+i] = - ((uint64_t)p_lut[1] << 32) | - ((uint64_t)p_lut[0] & 0xffffffff); + stb_core1_lut[base + i] = + ((u64)p_lut[1] << 32) | + ((u64)p_lut[0] & 0xffffffff); p_lut += 2; } } @@ -1557,61 +1799,52 @@ static bool need_skip_cvm(unsigned int is_graphic) return false; if (dolby_vision_flags & FLAG_FORCE_CVM) return false; -#ifdef V2_4 + return skip_cvm_tbl[is_graphic] [dolby_vision_graphics_priority] [new_dovi_setting.src_format == FORMAT_INVALID ? FORMAT_SDR : new_dovi_setting.src_format] [new_dovi_setting.dovi_ll_enable ? FORMAT_DOVI_LL : new_dovi_setting.dst_format]; -#else - return skip_cvm_tbl[is_graphic] - [dolby_vision_graphics_priority] - [new_dovi_setting.src_format == FORMAT_INVALID ? - FORMAT_SDR : new_dovi_setting.src_format] - [new_dovi_setting.dst_format]; -#endif } -static int stb_dolby_core1_set( - uint32_t dm_count, - uint32_t comp_count, - uint32_t lut_count, - uint32_t *p_core1_dm_regs, - uint32_t *p_core1_comp_regs, - uint32_t *p_core1_lut, - int hsize, - int vsize, - int bl_enable, - int el_enable, - int el_41_mode, - int scramble_en, - bool dovi_src, - int lut_endian, - bool reset) -{ - uint32_t bypass_flag = 0; +static int stb_dolby_core1_set + (u32 dm_count, + u32 comp_count, + u32 lut_count, + u32 *p_core1_dm_regs, + u32 *p_core1_comp_regs, + u32 *p_core1_lut, + int hsize, + int vsize, + int bl_enable, + int el_enable, + int el_41_mode, + int scramble_en, + bool dovi_src, + int lut_endian, + bool reset) +{ + u32 bypass_flag = 0; int composer_enable = el_enable; - uint32_t run_mode = 0; + u32 run_mode = 0; int reg_size = 0; - bool bypass_core1 = (!hsize || !vsize - || !(dolby_vision_mask & 1)); + bool bypass_core1 = (!hsize || !vsize || + !(dolby_vision_mask & 1)); - if (dolby_vision_on - && (dolby_vision_flags & - FLAG_DISABE_CORE_SETTING)) + if (dolby_vision_on && + (dolby_vision_flags & FLAG_DISABE_CORE_SETTING)) return 0; - WRITE_VPP_DV_REG( - DOLBY_TV_CLKGATE_CTRL, 0x2800); + WRITE_VPP_DV_REG(DOLBY_TV_CLKGATE_CTRL, 0x2800); if (reset) { if (!dolby_vision_core1_on) { VSYNC_WR_DV_REG(VIU_SW_RESET, 1 << 9); VSYNC_WR_DV_REG(VIU_SW_RESET, 0); - VSYNC_WR_DV_REG( - DOLBY_TV_CLKGATE_CTRL, 0x2800); - } else + VSYNC_WR_DV_REG(DOLBY_TV_CLKGATE_CTRL, 0x2800); + } else { reset = 0; + } } if (!bl_enable) @@ -1628,33 +1861,32 @@ static int stb_dolby_core1_set( VSYNC_WR_DV_REG(DOLBY_TV_SWAP_CTRL6, 0xba000000); if (dolby_vision_flags & FLAG_DISABLE_COMPOSER) composer_enable = 0; - VSYNC_WR_DV_REG(DOLBY_TV_SWAP_CTRL0, - /* el dly 3, bl dly 1 after de*/ - (el_41_mode ? (0x3 << 4) : (0x1 << 8)) | - bl_enable << 0 | composer_enable << 1 | el_41_mode << 2); + VSYNC_WR_DV_REG + (DOLBY_TV_SWAP_CTRL0, + /* el dly 3, bl dly 1 after de*/ + (el_41_mode ? (0x3 << 4) : (0x1 << 8)) | + bl_enable << 0 | composer_enable << 1 | el_41_mode << 2); if (el_enable && (dolby_vision_mask & 1)) - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* vd2 to core1 */ - 0, 17, 1); + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* vd2 to core1 */ + 0, 17, 1); else - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* vd2 to vpp */ - 1, 17, 1); - if (dolby_vision_core1_on - && !bypass_core1) - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* enable core 1 */ - 0, 16, 1); - else if (dolby_vision_core1_on - && bypass_core1) - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* bypass core 1 */ - 1, 16, 1); + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* vd2 to vpp */ + 1, 17, 1); + if (dolby_vision_core1_on && !bypass_core1) + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* enable core 1 */ + 0, 16, 1); + else if (dolby_vision_core1_on && bypass_core1) + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* bypass core 1 */ + 1, 16, 1); /* run mode = bypass, when fake frame */ if (!bl_enable) bypass_flag |= 1; @@ -1665,33 +1897,32 @@ static int stb_dolby_core1_set( if (need_skip_cvm(0)) bypass_flag |= 1 << 13; /* bypass CVM when tunnel out */ /* bypass composer to get 12bit when SDR and HDR source */ -#ifndef V2_4 +#ifdef OLD_VERSION if (!dovi_src) bypass_flag |= 1 << 14; /* bypass composer */ #endif - if (dolby_vision_run_mode != 0xff) + if (dolby_vision_run_mode != 0xff) { run_mode = dolby_vision_run_mode; - else { + } else { run_mode = (0x7 << 6) | ((el_41_mode ? 3 : 1) << 2) | bypass_flag; if (dolby_vision_on_count < dolby_vision_run_mode_delay) { run_mode |= 1; VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC0, - (0x200 << 10) | 0x200); + (0x200 << 10) | 0x200); VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC1, - (0x200 << 10) | 0x200); + (0x200 << 10) | 0x200); } else if (dolby_vision_on_count == dolby_vision_run_mode_delay) { VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC0, - (0x200 << 10) | 0x200); + (0x200 << 10) | 0x200); VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC1, - (0x200 << 10) | 0x200); + (0x200 << 10) | 0x200); } else { VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC0, - (0x3ff << 20) | (0x3ff << 10) | 0x3ff); - VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC1, - 0); + (0x3ff << 20) | (0x3ff << 10) | 0x3ff); + VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC1, 0); } } if (reset) @@ -1704,30 +1935,30 @@ static int stb_dolby_core1_set( VSYNC_WR_DV_REG(DOLBY_TV_SWAP_CTRL5, 0xa); /* axi dma for reg table */ - reg_size = prepare_stb_dolby_core1_reg( - run_mode, p_core1_dm_regs, p_core1_comp_regs); + reg_size = prepare_stb_dolby_core1_reg + (run_mode, p_core1_dm_regs, p_core1_comp_regs); /* axi dma for lut table */ prepare_stb_dolby_core1_lut(reg_size, p_core1_lut); if (!dolby_vision_on) { /* dma1:11-0 tv_oo+g2l size, dma2:23-12 3d lut size */ WRITE_VPP_DV_REG(DOLBY_TV_AXI2DMA_CTRL1, - 0x00000080 | (reg_size << 23)); + 0x00000080 | (reg_size << 23)); WRITE_VPP_DV_REG(DOLBY_TV_AXI2DMA_CTRL2, (u32)dma_paddr); /* dma3:23-12 cvm size */ WRITE_VPP_DV_REG(DOLBY_TV_AXI2DMA_CTRL3, - 0x80100000 | dma_start_line); + 0x80100000 | dma_start_line); WRITE_VPP_DV_REG(DOLBY_TV_AXI2DMA_CTRL0, 0x01000062); WRITE_VPP_DV_REG(DOLBY_TV_AXI2DMA_CTRL0, 0x80400042); } if (reset) { /* dma1:11-0 tv_oo+g2l size, dma2:23-12 3d lut size */ VSYNC_WR_DV_REG(DOLBY_TV_AXI2DMA_CTRL1, - 0x00000080 | (reg_size << 23)); + 0x00000080 | (reg_size << 23)); VSYNC_WR_DV_REG(DOLBY_TV_AXI2DMA_CTRL2, (u32)dma_paddr); /* dma3:23-12 cvm size */ VSYNC_WR_DV_REG(DOLBY_TV_AXI2DMA_CTRL3, - 0x80100000 | dma_start_line); + 0x80100000 | dma_start_line); VSYNC_WR_DV_REG(DOLBY_TV_AXI2DMA_CTRL0, 0x01000062); VSYNC_WR_DV_REG(DOLBY_TV_AXI2DMA_CTRL0, 0x80400042); } @@ -1736,9 +1967,9 @@ static int stb_dolby_core1_set( return 0; } -static uint32_t tv_run_mode(int vsize, bool hdmi, bool hdr10, int el_41_mode) +static u32 tv_run_mode(int vsize, bool hdmi, bool hdr10, int el_41_mode) { - uint32_t run_mode = 1; + u32 run_mode = 1; if (hdmi) { if (vsize > 1080) @@ -1751,9 +1982,6 @@ static uint32_t tv_run_mode(int vsize, bool hdmi, bool hdr10, int el_41_mode) if (hdr10) { run_mode = 0x0000004c; -#ifndef V1_5 - run_mode |= 1 << 14; /* bypass COMPOSER */ -#endif } else { if (el_41_mode) run_mode = @@ -1765,21 +1993,130 @@ static uint32_t tv_run_mode(int vsize, bool hdmi, bool hdr10, int el_41_mode) } if (dolby_vision_flags & FLAG_BYPASS_CSC) run_mode |= 1 << 12; /* bypass CSC */ - if ((dolby_vision_flags & FLAG_BYPASS_CVM) - && !(dolby_vision_flags & FLAG_FORCE_CVM)) + if ((dolby_vision_flags & FLAG_BYPASS_CVM) && + !(dolby_vision_flags & FLAG_FORCE_CVM)) run_mode |= 1 << 13; /* bypass CVM */ return run_mode; } +static void adjust_vpotch(void) +{ + const struct vinfo_s *vinfo = get_current_vinfo(); + int sync_duration_num = 60; + + if (is_meson_txlx_stbmode()) { + if (vinfo && vinfo->width >= 1920 && + vinfo->height >= 1080 && + vinfo->field_height >= 1080) + dma_start_line = 0x400; + else + dma_start_line = 0x180; + /* adjust core2 setting to work around*/ + /* fixing with 1080p24hz and 480p60hz */ + if (vinfo && vinfo->width < 1280 && + vinfo->height < 720 && + vinfo->field_height < 720) + g_vpotch = 0x60; + else + g_vpotch = 0x20; + } else if (is_meson_g12()) { + if (vinfo) { + if (vinfo->sync_duration_den) + sync_duration_num = vinfo->sync_duration_num / + vinfo->sync_duration_den; + if (debug_dolby & 2) + pr_dolby_dbg("vinfo %d %d %d %d %d %d\n", + vinfo->width, + vinfo->height, + vinfo->field_height, + vinfo->sync_duration_num, + vinfo->sync_duration_den, + sync_duration_num); + if (vinfo->width < 1280 && + vinfo->height < 720 && + vinfo->field_height < 720) + g_vpotch = 0x60; + else if (vinfo->width == 1280 && + vinfo->height == 720) + g_vpotch = 0x38; + else if (vinfo->width == 1280 && + vinfo->height == 720 && + vinfo->field_height < 720) + g_vpotch = 0x60; + else if (vinfo->width == 1920 && + vinfo->height == 1080 && + sync_duration_num < 30) + g_vpotch = 0x60; + else if (vinfo->width == 1920 && + vinfo->height == 1080 && + vinfo->field_height < 1080) + g_vpotch = 0x60; + else + g_vpotch = 0x20; + if (vinfo->width > 1920) + htotal_add = 0xc0; + else + htotal_add = 0x140; + } else { + g_vpotch = 0x20; + } + } else if (is_meson_tm2_stbmode()) { + if (vinfo) { + if (debug_dolby & 2) + pr_dolby_dbg("vinfo %d %d %d\n", + vinfo->width, + vinfo->height, + vinfo->field_height); + if ((vinfo->width < 1280) && + (vinfo->height < 720) && + (vinfo->field_height < 720)) + g_vpotch = 0x60; + else if ((vinfo->width <= 1920) && + (vinfo->height <= 1080) && + (vinfo->field_height <= 1080)) + g_vpotch = 0x50; + else + g_vpotch = 0x20; + } else { + g_vpotch = 0x20; + } + } else if (is_meson_sc2()) { + if (vinfo) { + if (debug_dolby & 2) + pr_dolby_dbg("vinfo %d %d %d\n", + vinfo->width, + vinfo->height, + vinfo->field_height); + if (vinfo->width < 1280 && + vinfo->height < 720 && + vinfo->field_height < 720) + g_vpotch = 0x60; + else if (vinfo->width <= 1920 && + vinfo->height <= 1080 && + vinfo->field_height <= 1080) + g_vpotch = 0x50; + else + g_vpotch = 0x20; + + if (vinfo->width > 1920) + htotal_add = 0xc0; + else + htotal_add = 0x140; + } else { + g_vpotch = 0x20; + } + } +} + static void adjust_vpotch_tv(void) { const struct vinfo_s *vinfo = get_current_vinfo(); if (is_meson_tm2()) { if (vinfo) { - if (vinfo && (vinfo->width >= 1920) && - (vinfo->height >= 1080) && - (vinfo->field_height >= 1080)) + if (vinfo && vinfo->width >= 1920 && + vinfo->height >= 1080 && + vinfo->field_height >= 1080) dma_start_line = 0x400; else dma_start_line = 0x180; @@ -1817,27 +2154,26 @@ static void dolby_core_reset(enum core_type type) } } -static int tv_dolby_core1_set( - uint64_t *dma_data, - int hsize, - int vsize, - int bl_enable, - int el_enable, - int el_41_mode, - int src_chroma_format, - bool hdmi, - bool hdr10, - bool reset) +static int tv_dolby_core1_set + (u64 *dma_data, + int hsize, + int vsize, + int bl_enable, + int el_enable, + int el_41_mode, + int src_chroma_format, + bool hdmi, + bool hdr10, + bool reset) { - uint64_t run_mode; + u64 run_mode; int composer_enable = el_enable; - bool bypass_core1 = (!hsize || !vsize - || !(dolby_vision_mask & 1)); + bool bypass_core1 = (!hsize || !vsize || + !(dolby_vision_mask & 1)); static int start_render; - if (dolby_vision_on - && (dolby_vision_flags & - FLAG_DISABE_CORE_SETTING)) + if (dolby_vision_on && + (dolby_vision_flags & FLAG_DISABE_CORE_SETTING)) return 0; adjust_vpotch_tv(); @@ -1864,23 +2200,22 @@ static int tv_dolby_core1_set( } } } - WRITE_VPP_DV_REG( - DOLBY_TV_CLKGATE_CTRL, 0x2800); + WRITE_VPP_DV_REG(DOLBY_TV_CLKGATE_CTRL, 0x2800); if (reset) { dolby_core_reset(DOLBY_TVCORE); - VSYNC_WR_DV_REG( - DOLBY_TV_CLKGATE_CTRL, 0x2800); + VSYNC_WR_DV_REG(DOLBY_TV_CLKGATE_CTRL, 0x2800); } if (dolby_vision_flags & FLAG_DISABLE_COMPOSER) composer_enable = 0; - VSYNC_WR_DV_REG(DOLBY_TV_SWAP_CTRL0, - /* el dly 3, bl dly 1 after de*/ - (el_41_mode ? (0x3 << 4) : (0x1 << 8)) | - bl_enable << 0 | composer_enable << 1 | el_41_mode << 2); + VSYNC_WR_DV_REG + (DOLBY_TV_SWAP_CTRL0, + /* el dly 3, bl dly 1 after de*/ + (el_41_mode ? (0x3 << 4) : (0x1 << 8)) | + bl_enable << 0 | composer_enable << 1 | el_41_mode << 2); VSYNC_WR_DV_REG(DOLBY_TV_SWAP_CTRL1, - ((hsize + 0x80) << 16 | (vsize + 0x40))); + ((hsize + 0x80) << 16 | (vsize + 0x40))); VSYNC_WR_DV_REG(DOLBY_TV_SWAP_CTRL3, (hwidth << 16) | vwidth); VSYNC_WR_DV_REG(DOLBY_TV_SWAP_CTRL4, (hpotch << 16) | vpotch); VSYNC_WR_DV_REG(DOLBY_TV_SWAP_CTRL2, (hsize << 16) | vsize); @@ -1888,11 +2223,12 @@ static int tv_dolby_core1_set( VSYNC_WR_DV_REG_BITS(DOLBY_TV_SWAP_CTRL5, 0x2c2d0, 14, 18); VSYNC_WR_DV_REG_BITS(DOLBY_TV_SWAP_CTRL5, 0xa, 0, 4); - if ((hdmi) && (!hdr10)) { + if (hdmi && !hdr10) { /*hdmi DV STD and DV LL: need detunnel*/ VSYNC_WR_DV_REG_BITS(DOLBY_TV_SWAP_CTRL5, 1, 4, 1); - } else + } else { VSYNC_WR_DV_REG_BITS(DOLBY_TV_SWAP_CTRL5, 0, 4, 1); + } /*set diag reg to 0xb can bypass dither, not need set swap ctrl6 */ if (!is_meson_tm2()) { @@ -1908,79 +2244,81 @@ static int tv_dolby_core1_set( VSYNC_WR_DV_REG_BITS(DOLBY_TV_SWAP_CTRL7, 12, 0, 4); if (el_enable && (dolby_vision_mask & 1)) - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* vd2 to core1 */ - 0, 17, 1); + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* vd2 to core1 */ + 0, 17, 1); else - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* vd2 to vpp */ - 1, 17, 1); + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* vd2 to vpp */ + 1, 17, 1); if (dolby_vision_core1_on && !bypass_core1) { if (is_meson_tm2()) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, 8, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, 10, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, 24, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 16, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 20, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 0, el_enable ? 2 : 1); - } else - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* enable core 1 */ - 0, 16, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, 8, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, 10, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, 24, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 16, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 20, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + el_enable ? 0 : 2, 0, 2); + } else { + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* enable core 1 */ + 0, 16, 1); + } } else if (dolby_vision_core1_on && bypass_core1) { if (is_meson_tm2()) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 3, 0, 2); - } else - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* bypass core 1 */ - 1, 16, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 3, 0, 2); + } else { + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* bypass core 1 */ + 1, 16, 1); + } } - if (dolby_vision_run_mode != 0xff) + if (dolby_vision_run_mode != 0xff) { run_mode = dolby_vision_run_mode; - else { + } else { run_mode = tv_run_mode(vsize, hdmi, hdr10, el_41_mode); if (dolby_vision_on_count < dolby_vision_run_mode_delay) { run_mode = (run_mode & 0xfffffffc) | 1; VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC0, - (0x200 << 10) | 0x200); + (0x200 << 10) | 0x200); VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC1, - (0x200 << 10) | 0x200); + (0x200 << 10) | 0x200); start_render = 0; } else if (dolby_vision_on_count == - dolby_vision_run_mode_delay) { + dolby_vision_run_mode_delay) { VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC0, - (0x200 << 10) | 0x200); + (0x200 << 10) | 0x200); VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC1, - (0x200 << 10) | 0x200); + (0x200 << 10) | 0x200); start_render = 0; } else { if (start_render == 0) { VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC0, - (0x3ff << 20) | (0x3ff << 10) | 0x3ff); + (0x3ff << 20) | (0x3ff << 10) | 0x3ff); VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC1, - 0); + 0); } start_render = 1; } @@ -1990,7 +2328,7 @@ static int tv_dolby_core1_set( if (reset) VSYNC_WR_DV_REG(DOLBY_TV_REG_START + 1, run_mode); if (is_meson_tm2_stbmode()) - VSYNC_WR_DV_REG(DOLBY_TV_REG_START + 0xe7, 1); + VSYNC_WR_DV_REG(DOLBY_TV_DIAG_CTRL, 1); if (!dolby_vision_on || (!dolby_vision_core1_on && @@ -2017,10 +2355,10 @@ static int tv_dolby_core1_set( int dolby_vision_update_setting(void) { - uint64_t *dma_data; - uint32_t size = 0; + u64 *dma_data; + u32 size = 0; int i; - uint64_t *p; + u64 *p; if (!p_funcs_stb && !p_funcs_tv) return -1; @@ -2032,24 +2370,24 @@ int dolby_vision_update_setting(void) setting_update_count++; return -1; } - if (dma_vaddr == NULL) + if (!dma_vaddr) return -1; if (efuse_mode == 1) { tv_dovi_setting_update_flag = false; setting_update_count++; return -1; } - if (is_meson_tvmode() && !force_stb_mode) { + if ((is_meson_tvmode() || is_meson_tm2_stb_hdmimode())) { dma_data = tv_dovi_setting->core1_reg_lut; size = 8 * TV_DMA_TBL_SIZE; memcpy(dma_vaddr, dma_data, size); - } else if (is_meson_txlx_stbmode() || force_stb_mode) { + } else if (is_meson_txlx_stbmode()) { dma_data = stb_core1_lut; size = 8 * STB_DMA_TBL_SIZE; memcpy(dma_vaddr, dma_data, size); } if (size && (debug_dolby & 0x800)) { - p = (uint64_t *)dma_vaddr; + p = (u64 *)dma_vaddr; pr_info("dma size = %d\n", STB_DMA_TBL_SIZE); for (i = 0; i < size / 8; i += 2) pr_info("%016llx, %016llx\n", p[i], p[i+1]); @@ -2060,31 +2398,31 @@ int dolby_vision_update_setting(void) } EXPORT_SYMBOL(dolby_vision_update_setting); -static int dolby_core1_set( - uint32_t dm_count, - uint32_t comp_count, - uint32_t lut_count, - uint32_t *p_core1_dm_regs, - uint32_t *p_core1_comp_regs, - uint32_t *p_core1_lut, - int hsize, - int vsize, - int bl_enable, - int el_enable, - int el_41_mode, - int scramble_en, - bool dovi_src, - int lut_endian, - bool reset) -{ - uint32_t count; - uint32_t bypass_flag = 0; +static int dolby_core1_set + (u32 dm_count, + u32 comp_count, + u32 lut_count, + u32 *p_core1_dm_regs, + u32 *p_core1_comp_regs, + u32 *p_core1_lut, + int hsize, + int vsize, + int bl_enable, + int el_enable, + int el_41_mode, + int scramble_en, + bool dovi_src, + int lut_endian, + bool reset) +{ + u32 count; + u32 bypass_flag = 0; int composer_enable = bl_enable && el_enable && (dolby_vision_mask & 1); int i; bool set_lut = false; - uint32_t *last_dm = (uint32_t *)&dovi_setting.dm_reg1; - uint32_t *last_comp = (uint32_t *)&dovi_setting.comp_reg; + u32 *last_dm = (u32 *)&dovi_setting.dm_reg1; + u32 *last_comp = (u32 *)&dovi_setting.comp_reg; bool bypass_core1 = (!hsize || !vsize || !(dolby_vision_mask & 1)); int dolby_copy_core1s0 = (dolby_vision_flags & FLAG_COPY_CORE1S0) && @@ -2097,31 +2435,30 @@ static int dolby_core1_set( if ((is_meson_g12() || is_meson_tm2_stbmode() || is_meson_sc2()) && frame_count == 1 && dolby_vision_core1_on == 0) { pr_dolby_dbg("((%s %d, register DOLBY_PATH_CTRL: %x))\n", - __func__, __LINE__, - VSYNC_RD_DV_REG(DOLBY_PATH_CTRL)); + __func__, __LINE__, + VSYNC_RD_DV_REG(DOLBY_PATH_CTRL)); if ((VSYNC_RD_DV_REG(DOLBY_PATH_CTRL) & 0x1) != 0) { pr_dolby_dbg("BL is disable for 1st frame.Re-enable BL\n"); VSYNC_WR_DV_REG_BITS(DOLBY_PATH_CTRL, 0, 0, 1); pr_dolby_dbg("((%s %d, enable_bl, DOLBY_PATH_CTRL: %x))\n", - __func__, __LINE__, - VSYNC_RD_DV_REG(DOLBY_PATH_CTRL)); + __func__, __LINE__, + VSYNC_RD_DV_REG(DOLBY_PATH_CTRL)); } if (el_enable) { if ((VSYNC_RD_DV_REG(DOLBY_PATH_CTRL) & 0x10) != 0) { pr_dolby_dbg("((%s %d enable el))\n", - __func__, __LINE__); + __func__, __LINE__); VSYNC_WR_DV_REG_BITS(DOLBY_PATH_CTRL, - 0, 1, 1); + 0, 1, 1); pr_dolby_dbg("((%s %d, enable_el, DOLBY_PATH_CTRL: %x))\n", - __func__, __LINE__, - VSYNC_RD_DV_REG(DOLBY_PATH_CTRL)); + __func__, __LINE__, + VSYNC_RD_DV_REG(DOLBY_PATH_CTRL)); } } } - if (dolby_vision_on - && (dolby_vision_flags & - FLAG_DISABE_CORE_SETTING)) + if (dolby_vision_on && + (dolby_vision_flags & FLAG_DISABE_CORE_SETTING)) return 0; if (dolby_vision_flags & FLAG_DISABLE_COMPOSER) @@ -2146,12 +2483,12 @@ static int dolby_core1_set( reset = true; if (dolby_vision_core1_on && - (dolby_vision_core1_on_cnt < DV_CORE1_RECONFIG_CNT)) { + dolby_vision_core1_on_cnt < DV_CORE1_RECONFIG_CNT) { reset = true; dolby_vision_core1_on_cnt++; } - if (stb_core_setting_update_flag & FLAG_CHANGE_TC) + if (stb_core_setting_update_flag & CP_FLAG_CHANGE_TC) set_lut = true; if ((bl_enable && el_enable && (dolby_vision_mask & 1)) || @@ -2162,21 +2499,21 @@ static int dolby_core1_set( /* vd2 to core1 */ 0, 1, 1); else - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* vd2 to core1 */ - 0, 17, 1); + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* vd2 to core1 */ + 0, 17, 1); } else { if (is_meson_g12() || is_meson_sc2() || is_meson_tm2_stbmode()) - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, /* vd2 to vpp */ 1, 1, 1); else - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* vd2 to vpp */ - 1, 17, 1); + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* vd2 to vpp */ + 1, 17, 1); } if (is_meson_tm2_stbmode() || is_meson_g12() || is_meson_sc2()) { if (get_vpu_mem_pd_vmod(VPU_DOLBY1A) == VPU_MEM_POWER_DOWN || @@ -2225,7 +2562,7 @@ static int dolby_core1_set( } /* bypass composer to get 12bit when SDR and HDR source */ -#ifndef V2_4 +#ifdef OLD_VERSION if (!dovi_src) bypass_flag |= 1 << 0; #endif @@ -2270,16 +2607,14 @@ static int dolby_core1_set( else count = comp_count; for (i = 0; i < count; i++) - if (reset || - (p_core1_comp_regs[i] != - last_comp[i])) { - VSYNC_WR_DV_REG( - DOLBY_CORE1_REG_START + 6 + 44 + i, - p_core1_comp_regs[i]); + if (reset || p_core1_comp_regs[i] != last_comp[i]) { + VSYNC_WR_DV_REG + (DOLBY_CORE1_REG_START + 6 + 44 + i, + p_core1_comp_regs[i]); if (dolby_copy_core1s0) - VSYNC_WR_DV_REG( - DOLBY_CORE1_1_REG_START + 6 + 44 + i, - p_core1_comp_regs[i]); + VSYNC_WR_DV_REG + (DOLBY_CORE1_1_REG_START + 6 + 44 + i, + p_core1_comp_regs[i]); } /* metadata program done */ VSYNC_WR_DV_REG(DOLBY_CORE1_REG_START + 3, 1); @@ -2345,117 +2680,117 @@ static int dolby_core1_set( if (dolby_vision_on_count < dolby_vision_run_mode_delay) { - VSYNC_WR_DV_REG( - VPP_VD1_CLIP_MISC0, - (0x200 << 10) | 0x200); - VSYNC_WR_DV_REG( - VPP_VD1_CLIP_MISC1, - (0x200 << 10) | 0x200); + VSYNC_WR_DV_REG + (VPP_VD1_CLIP_MISC0, + (0x200 << 10) | 0x200); + VSYNC_WR_DV_REG + (VPP_VD1_CLIP_MISC1, + (0x200 << 10) | 0x200); if (is_meson_g12()) - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, - 0, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, + 0, 1); else - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - 1, 16, 1); + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + 1, 16, 1); } else { if (dolby_vision_on_count > dolby_vision_run_mode_delay) { - VSYNC_WR_DV_REG( - VPP_VD1_CLIP_MISC0, - (0x3ff << 20) | - (0x3ff << 10) | - 0x3ff); - VSYNC_WR_DV_REG( - VPP_VD1_CLIP_MISC1, - 0); - } - if (dolby_vision_core1_on - && !bypass_core1) { - if (is_meson_g12()) - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 0, 1); - else if (is_meson_tm2_stbmode()) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 8, 2); + VSYNC_WR_DV_REG + (VPP_VD1_CLIP_MISC0, + (0x3ff << 20) | + (0x3ff << 10) | + 0x3ff); + VSYNC_WR_DV_REG + (VPP_VD1_CLIP_MISC1, + 0); + } + if (dolby_vision_core1_on && + !bypass_core1) { + if (is_meson_g12()) { + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 0, 1); + } else if (is_meson_tm2_stbmode()) { + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 8, 2); if (dolby_copy_core1s0) - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 3, 10, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 3, 10, 2); else - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 10, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 17, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 21, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 24, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 10, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 17, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 21, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 24, 2); if (dolby_copy_core1s0) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, 19, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, 23, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 3, 26, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, 19, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, 23, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 3, 26, 2); } - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, 0, 0, 1); /* core1 */ } else if (is_meson_sc2()) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 8, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 10, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 17, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 21, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 24, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 0, 1); /* core1 */ + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 8, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 10, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 17, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 21, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 24, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 0, 1); /* core1 */ } else - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* enable core 1 */ - 0, 16, 1); - } else if (dolby_vision_core1_on - && bypass_core1) { + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* enable core 1 */ + 0, 16, 1); + } else if (dolby_vision_core1_on && + bypass_core1) { if (is_meson_g12()) - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, 0, 1); - else if (is_meson_tm2_stbmode()) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 3, 0, 2); /* core1 */ - } else if (is_meson_sc2()) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 3, 0, 2); /* core1 */ - } else - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* bypass core 1 */ - 1, 16, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, 0, 1); + else if (is_meson_tm2_stbmode()) + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 3, 0, 2); /* core1 */ + else if (is_meson_sc2()) + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 3, 0, 2); /* core1 */ + else + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* bypass core 1 */ + 1, 16, 1); } } @@ -2480,26 +2815,25 @@ static int dolby_core1_set( return 0; } -static int dolby_core2_set( - uint32_t dm_count, - uint32_t lut_count, - uint32_t *p_core2_dm_regs, - uint32_t *p_core2_lut, - int hsize, - int vsize, - int dolby_enable, - int lut_endian) +static int dolby_core2_set + (u32 dm_count, + u32 lut_count, + u32 *p_core2_dm_regs, + u32 *p_core2_lut, + int hsize, + int vsize, + int dolby_enable, + int lut_endian) { - uint32_t count; + u32 count; int i; bool set_lut = false; bool reset = false; - uint32_t *last_dm = (uint32_t *)&dovi_setting.dm_reg2; - uint32_t bypass_flag = 0; + u32 *last_dm = (u32 *)&dovi_setting.dm_reg2; + u32 bypass_flag = 0; - if (dolby_vision_on - && (dolby_vision_flags & - FLAG_DISABE_CORE_SETTING)) + if (dolby_vision_on && + (dolby_vision_flags & FLAG_DISABE_CORE_SETTING)) return 0; if (!dolby_vision_on || force_reset_core2) { @@ -2527,8 +2861,6 @@ static int dolby_core2_set( if (force_update_reg & 2) reset = true; - if (stb_core_setting_update_flag & FLAG_CHANGE_TC2) - set_lut = true; if (is_meson_tm2_stbmode() || is_meson_g12() || is_meson_sc2()) { if (get_vpu_mem_pd_vmod(VPU_DOLBY2) == VPU_MEM_POWER_DOWN || get_dv_mem_power_flag(VPU_DOLBY2) == VPU_MEM_POWER_DOWN) @@ -2538,27 +2870,29 @@ static int dolby_core2_set( VSYNC_WR_DV_REG(DOLBY_CORE2A_CLKGATE_CTRL, 0); VSYNC_WR_DV_REG(DOLBY_CORE2A_SWAP_CTRL0, 0); if (is_meson_box() || is_meson_tm2_stbmode() || reset) { - VSYNC_WR_DV_REG(DOLBY_CORE2A_SWAP_CTRL1, + VSYNC_WR_DV_REG + (DOLBY_CORE2A_SWAP_CTRL1, ((hsize + g_htotal_add) << 16) | (vsize - + ((g_vtiming & 0xff000000) ? - ((g_vtiming >> 24) & 0xff) : g_vtotal_add) - + ((g_vtiming & 0xff0000) ? - ((g_vtiming >> 16) & 0xff) : g_vsize_add))); - VSYNC_WR_DV_REG(DOLBY_CORE2A_SWAP_CTRL2, - (hsize << 16) | (vsize - + ((g_vtiming & 0xff0000) ? - ((g_vtiming >> 16) & 0xff) : g_vsize_add))); + + ((g_vtiming & 0xff000000) ? + ((g_vtiming >> 24) & 0xff) : g_vtotal_add) + + ((g_vtiming & 0xff0000) ? + ((g_vtiming >> 16) & 0xff) : g_vsize_add))); + VSYNC_WR_DV_REG + (DOLBY_CORE2A_SWAP_CTRL2, + (hsize << 16) | (vsize + + ((g_vtiming & 0xff0000) ? + ((g_vtiming >> 16) & 0xff) : g_vsize_add))); } if (debug_dolby & 2) pr_dolby_dbg("core2a g_hpotch %x, g_vpotch %x, reset %d, set_lut %d\n", g_hpotch, g_vpotch, reset, set_lut); VSYNC_WR_DV_REG(DOLBY_CORE2A_SWAP_CTRL3, - (g_hwidth << 16) | ((g_vtiming & 0xff00) ? - ((g_vtiming >> 8) & 0xff) : g_vwidth)); + (g_hwidth << 16) | ((g_vtiming & 0xff00) ? + ((g_vtiming >> 8) & 0xff) : g_vwidth)); VSYNC_WR_DV_REG(DOLBY_CORE2A_SWAP_CTRL4, - (g_hpotch << 16) | ((g_vtiming & 0xff) ? - (g_vtiming & 0xff) : g_vpotch)); - if (is_meson_txlx_stbmode() || force_stb_mode) + (g_hpotch << 16) | ((g_vtiming & 0xff) ? + (g_vtiming & 0xff) : g_vpotch)); + if (is_meson_txlx_stbmode()) VSYNC_WR_DV_REG(DOLBY_CORE2A_SWAP_CTRL5, 0xf8000000); else if (is_meson_g12() || is_meson_tm2_stbmode() || is_meson_sc2()) VSYNC_WR_DV_REG(DOLBY_CORE2A_SWAP_CTRL5, 0xa8000000); @@ -2570,11 +2904,10 @@ static int dolby_core2_set( bypass_flag |= 1 << 0; VSYNC_WR_DV_REG(DOLBY_CORE2A_REG_START + 2, 1); VSYNC_WR_DV_REG(DOLBY_CORE2A_REG_START + 1, - 2 | bypass_flag); + 2 | bypass_flag); VSYNC_WR_DV_REG(DOLBY_CORE2A_REG_START + 1, - 2 | bypass_flag); + 2 | bypass_flag); VSYNC_WR_DV_REG(DOLBY_CORE2A_CTRL, 0); - VSYNC_WR_DV_REG(DOLBY_CORE2A_CTRL, 0); if (dm_count == 0) @@ -2583,15 +2916,17 @@ static int dolby_core2_set( count = dm_count; for (i = 0; i < count; i++) if (reset || - (p_core2_dm_regs[i] != - last_dm[i])) { - VSYNC_WR_DV_REG( - DOLBY_CORE2A_REG_START + 6 + i, - p_core2_dm_regs[i]); + p_core2_dm_regs[i] != + last_dm[i]) { + VSYNC_WR_DV_REG + (DOLBY_CORE2A_REG_START + 6 + i, + p_core2_dm_regs[i]); set_lut = true; } - if (stb_core_setting_update_flag & FLAG_CONST_TC2) + if (stb_core_setting_update_flag & CP_FLAG_CHANGE_TC2) + set_lut = true; + else if (stb_core_setting_update_flag & CP_FLAG_CONST_TC2) set_lut = false; /* core2 metadata program done */ @@ -2607,26 +2942,29 @@ static int dolby_core2_set( VSYNC_WR_DV_REG_BITS(DOLBY_CORE2A_CLKGATE_CTRL, 2, 2, 2); VSYNC_WR_DV_REG(DOLBY_CORE2A_DMA_CTRL, 0x1401); - if (lut_endian) + + if (lut_endian) { for (i = 0; i < count; i += 4) { VSYNC_WR_DV_REG(DOLBY_CORE2A_DMA_PORT, - p_core2_lut[i+3]); + p_core2_lut[i + 3]); VSYNC_WR_DV_REG(DOLBY_CORE2A_DMA_PORT, - p_core2_lut[i+2]); + p_core2_lut[i + 2]); VSYNC_WR_DV_REG(DOLBY_CORE2A_DMA_PORT, - p_core2_lut[i+1]); + p_core2_lut[i + 1]); VSYNC_WR_DV_REG(DOLBY_CORE2A_DMA_PORT, p_core2_lut[i]); } - else - for (i = 0; i < count; i++) + } else { + for (i = 0; i < count; i++) { VSYNC_WR_DV_REG(DOLBY_CORE2A_DMA_PORT, p_core2_lut[i]); + } + } /* core2 lookup table program done */ if (is_meson_gxm() && (dolby_vision_flags & FLAG_CLKGATE_WHEN_LOAD_LUT)) - VSYNC_WR_DV_REG_BITS( - DOLBY_CORE2A_CLKGATE_CTRL, 0, 2, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_CORE2A_CLKGATE_CTRL, 0, 2, 2); } force_set_lut = false; @@ -2642,39 +2980,79 @@ bool is_core3_mute_reg(int index) (index >= 5 && index <= 9); /* lms2rgb coeff for rgb */ } -static int dolby_core3_set( - uint32_t dm_count, - uint32_t md_count, - uint32_t *p_core3_dm_regs, - uint32_t *p_core3_md_regs, - int hsize, - int vsize, - int dolby_enable, - int scramble_en, - u8 pps_state) +#ifdef V2_4_3 +static unsigned char hdmi_metadata[211 * 8]; +static unsigned int hdmi_metadata_size; +static void convert_hdmi_metadata(u32 *md) +{ + int i = 0; + u32 *p = md; + int shift = 0; + u32 size = md[0] >> 8; + + if (size > 211 * 8) + size = 211 * 8; + + hdmi_metadata[0] = *p++ & 0xff; + shift = 0; + for (i = 1; i < size; i++) { + hdmi_metadata[i] = (*p >> shift) & 0xff; + shift += 8; + if (shift == 32) { + p++; + shift = 0; + } + } + hdmi_metadata_size = size; +} + +bool need_send_emp_meta(const struct vinfo_s *vinfo) { - uint32_t count; + if (!vinfo || !vinfo->vout_device || !vinfo->vout_device->dv_info) + return false; + return is_meson_tm2_stbmode() && + (vinfo->vout_device->dv_info->dv_emp_cap || force_support_emp) && + ((dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL) || + dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_IPT) && + (dolby_vision_ll_policy == DOLBY_VISION_LL_DISABLE) && + (dolby_vision_std_policy == DOLBY_VISION_STD_YUV422); +} +#endif + +static int dolby_core3_set + (u32 dm_count, + u32 md_count, + u32 *p_core3_dm_regs, + u32 *p_core3_md_regs, + int hsize, + int vsize, + int dolby_enable, + int scramble_en, + u8 pps_state) +{ + u32 count; int i; int vsize_hold = 0x10; - uint32_t diag_mode = 0; - uint32_t cur_dv_mode = dolby_vision_mode; - uint32_t *last_dm = (uint32_t *)&dovi_setting.dm_reg3; + u32 diag_mode = 0; + u32 cur_dv_mode = dolby_vision_mode; + u32 *last_dm = (u32 *)&dovi_setting.dm_reg3; bool reset = false; -#ifdef V2_4 u32 diag_enable = 0; bool reset_post_table = false; - - if (new_dovi_setting.diagnostic_enable - || new_dovi_setting.dovi_ll_enable) - diag_enable = 1; +#ifdef V2_4_3 + const struct vinfo_s *vinfo = get_current_vinfo(); #endif - if (dolby_vision_on - && (dolby_vision_flags & - FLAG_DISABE_CORE_SETTING)) + if (new_dovi_setting.diagnostic_enable || + new_dovi_setting.dovi_ll_enable) + diag_enable = 1; + + if (dolby_vision_on && + (dolby_vision_flags & + FLAG_DISABE_CORE_SETTING)) return 0; if (!dolby_vision_on || - (dolby_vision_flags & FLAG_CERTIFICAION)) + (dolby_vision_flags & FLAG_CERTIFICAION)) reset = true; if (force_update_reg & 4) @@ -2689,10 +3067,8 @@ static int dolby_core3_set( if (dolby_vision_on_count == 0) reset = true; } -#ifdef V2_4 - if (((cur_dv_mode == DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL) - || (cur_dv_mode == DOLBY_VISION_OUTPUT_MODE_IPT)) - && diag_enable) { + if ((cur_dv_mode == DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL || + cur_dv_mode == DOLBY_VISION_OUTPUT_MODE_IPT) && diag_enable) { cur_dv_mode = dv_ll_output_mode & 0xff; if (is_meson_g12() || @@ -2702,15 +3078,21 @@ static int dolby_core3_set( diag_mode = 0x20; else diag_mode = 3; - } else + } else { diag_mode = 3; + } } +#ifdef V2_4_3 + else if (need_send_emp_meta(vinfo)) + diag_mode = 1; +#endif + if (dolby_vision_on && - ((last_dolby_vision_ll_policy != - dolby_vision_ll_policy) || - new_dovi_setting.mode_changed || - new_dovi_setting.vsvdb_changed || - pps_state)) { + (last_dolby_vision_ll_policy != + dolby_vision_ll_policy || + new_dovi_setting.mode_changed || + new_dovi_setting.vsvdb_changed || + pps_state)) { last_dolby_vision_ll_policy = dolby_vision_ll_policy; new_dovi_setting.vsvdb_changed = 0; @@ -2720,79 +3102,76 @@ static int dolby_core3_set( is_meson_tm2_stbmode() || is_meson_sc2()) { if (new_dovi_setting.dovi_ll_enable && - new_dovi_setting.diagnostic_enable == 0) { - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, - 3, 6, 2); /* post matrix */ - VSYNC_WR_DV_REG_BITS( - VPP_MATRIX_CTRL, - 1, 0, 1); /* post matrix */ + new_dovi_setting.diagnostic_enable == 0) { + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, + 3, 6, 2); /* post matrix */ + VSYNC_WR_DV_REG_BITS + (VPP_MATRIX_CTRL, + 1, 0, 1); /* post matrix */ } else { - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, - 0, 6, 2); /* post matrix */ - VSYNC_WR_DV_REG_BITS( - VPP_MATRIX_CTRL, - 0, 0, 1); /* post matrix */ + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, + 0, 6, 2); /* post matrix */ + VSYNC_WR_DV_REG_BITS + (VPP_MATRIX_CTRL, + 0, 0, 1); /* post matrix */ } - } else if (is_meson_txlx_stbmode() - || force_stb_mode) { + } else if (is_meson_txlx_stbmode()) { if (pps_state == 2) { - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, - 1, 0, 1); /* skip pps/dither/cm */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA0, 0x08000800); + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, + 1, 0, 1); /* skip pps/dither/cm */ + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA0, 0x08000800); } else if (pps_state == 1) { - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, - 0, 0, 1); /* enable pps/dither/cm */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA0, 0x20002000); + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, + 0, 0, 1); /* enable pps/dither/cm */ + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA0, 0x20002000); } if (new_dovi_setting.dovi_ll_enable && new_dovi_setting.diagnostic_enable == 0) { /*bypass gainoff to vks */ /*enable wn tp vks*/ - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, 0, 2, 1); - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, 1, 1, 1); - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA1, 0x8000800); - VSYNC_WR_DV_REG_BITS( - VPP_MATRIX_CTRL, - 1, 0, 1); /* post matrix */ + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, 0, 2, 1); + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, 1, 1, 1); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA1, 0x8000800); + VSYNC_WR_DV_REG_BITS + (VPP_MATRIX_CTRL, + 1, 0, 1); /* post matrix */ } else { /* bypass wm tp vks*/ - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, 1, 2, 1); - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, 0, 1, 1); - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA1, 0x20002000); + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, 1, 2, 1); + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, 0, 1, 1); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA1, 0x20002000); if (is_meson_tvmode()) - enable_rgb_to_yuv_matrix_for_dvll( - 0, NULL, 12); + enable_rgb_to_yuv_matrix_for_dvll + (0, NULL, 12); else - VSYNC_WR_DV_REG_BITS( - VPP_MATRIX_CTRL, - 0, 0, 1); + VSYNC_WR_DV_REG_BITS + (VPP_MATRIX_CTRL, + 0, 0, 1); } } reset_post_table = true; } /* flush post matrix table when ll mode on and setting changed */ if (new_dovi_setting.dovi_ll_enable && - (new_dovi_setting.diagnostic_enable == 0) && - dolby_vision_on && - (reset_post_table || reset || - memcmp(&p_core3_dm_regs[18], - &last_dm[18], 32))) - enable_rgb_to_yuv_matrix_for_dvll( - 1, &p_core3_dm_regs[18], 12); -#endif - + new_dovi_setting.diagnostic_enable == 0 && + dolby_vision_on && + (reset_post_table || reset || + memcmp(&p_core3_dm_regs[18], + &last_dm[18], 32))) + enable_rgb_to_yuv_matrix_for_dvll + (1, &p_core3_dm_regs[18], 12); if (is_meson_tm2_stbmode() || is_meson_g12() || is_meson_sc2()) { if (get_vpu_mem_pd_vmod(VPU_DOLBY_CORE3) == VPU_MEM_POWER_DOWN || @@ -2803,21 +3182,21 @@ static int dolby_core3_set( VSYNC_WR_DV_REG(DOLBY_CORE3_CLKGATE_CTRL, 0); VSYNC_WR_DV_REG(DOLBY_CORE3_SWAP_CTRL1, - ((hsize + htotal_add) << 16) - | (vsize + vtotal_add + vsize_add + vsize_hold * 2)); + ((hsize + htotal_add) << 16) + | (vsize + vtotal_add + vsize_add + vsize_hold * 2)); VSYNC_WR_DV_REG(DOLBY_CORE3_SWAP_CTRL2, - (hsize << 16) | (vsize + vsize_add)); + (hsize << 16) | (vsize + vsize_add)); VSYNC_WR_DV_REG(DOLBY_CORE3_SWAP_CTRL3, - (0x80 << 16) | vsize_hold); + (0x80 << 16) | vsize_hold); VSYNC_WR_DV_REG(DOLBY_CORE3_SWAP_CTRL4, - (0x04 << 16) | vsize_hold); + (0x04 << 16) | vsize_hold); VSYNC_WR_DV_REG(DOLBY_CORE3_SWAP_CTRL5, 0x0000); if (cur_dv_mode != DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL) VSYNC_WR_DV_REG(DOLBY_CORE3_SWAP_CTRL6, 0); else VSYNC_WR_DV_REG(DOLBY_CORE3_SWAP_CTRL6, - 0x10000000); /* swap UV */ + 0x10000000); /* swap UV */ VSYNC_WR_DV_REG(DOLBY_CORE3_REG_START + 5, 7); VSYNC_WR_DV_REG(DOLBY_CORE3_REG_START + 4, 4); VSYNC_WR_DV_REG(DOLBY_CORE3_REG_START + 4, 2); @@ -2837,17 +3216,17 @@ static int dolby_core3_set( else count = dm_count; for (i = 0; i < count; i++) { - if (reset || (p_core3_dm_regs[i] != - last_dm[i]) || is_core3_mute_reg(i)) { + if (reset || p_core3_dm_regs[i] != last_dm[i] || + is_core3_mute_reg(i)) { if ((dolby_vision_flags & FLAG_MUTE) && is_core3_mute_reg(i)) - VSYNC_WR_DV_REG( - DOLBY_CORE3_REG_START + 0x6 + i, - 0); + VSYNC_WR_DV_REG + (DOLBY_CORE3_REG_START + 0x6 + i, + 0); else - VSYNC_WR_DV_REG( - DOLBY_CORE3_REG_START + 0x6 + i, - p_core3_dm_regs[i]); + VSYNC_WR_DV_REG + (DOLBY_CORE3_REG_START + 0x6 + i, + p_core3_dm_regs[i]); } } /* from addr 0x18 */ @@ -2860,15 +3239,18 @@ static int dolby_core3_set( count = md_count; for (i = 0; i < count; i++) { #ifdef FORCE_HDMI_META - if ((i == 20) && - (p_core3_md_regs[i] == 0x5140a3e)) - VSYNC_WR_DV_REG(DOLBY_CORE3_REG_START + - 0x24 + i, (p_core3_md_regs[i] & - 0xffffff00) | 0x80); + if (i == 20 && + p_core3_md_regs[i] == 0x5140a3e) + VSYNC_WR_DV_REG + (DOLBY_CORE3_REG_START + + 0x24 + i, + (p_core3_md_regs[i] & + 0xffffff00) | 0x80); else #endif - VSYNC_WR_DV_REG(DOLBY_CORE3_REG_START + - 0x24 + i, p_core3_md_regs[i]); + VSYNC_WR_DV_REG + (DOLBY_CORE3_REG_START + + 0x24 + i, p_core3_md_regs[i]); } for (; i < (MAX_CORE3_MD_SIZE + 1); i++) VSYNC_WR_DV_REG(DOLBY_CORE3_REG_START + @@ -2880,12 +3262,10 @@ static int dolby_core3_set( /* core3 metadata program done */ VSYNC_WR_DV_REG(DOLBY_CORE3_REG_START + 3, 1); - VSYNC_WR_DV_REG( - DOLBY_CORE3_DIAG_CTRL, - diag_mode); + VSYNC_WR_DV_REG(DOLBY_CORE3_DIAG_CTRL, diag_mode); - if ((dolby_vision_flags & FLAG_CERTIFICAION) - && !(dolby_vision_flags & FLAG_DISABLE_CRC)) + if ((dolby_vision_flags & FLAG_CERTIFICAION) && + !(dolby_vision_flags & FLAG_DISABLE_CRC)) VSYNC_WR_DV_REG(DOLBY_CORE3_CRC_CTRL, 1); /* enable core3 */ VSYNC_WR_DV_REG(DOLBY_CORE3_SWAP_CTRL0, (dolby_enable << 0)); @@ -2893,7 +3273,7 @@ static int dolby_core3_set( } void update_graphic_width_height(unsigned int width, - unsigned int height) + unsigned int height) { new_osd_graphic_width = width; new_osd_graphic_height = height; @@ -2956,6 +3336,25 @@ static int is_graphic_changed(void) return ret; } +static bool is_hdr10_src_primary_changed(void) +{ + if (hdr10_param.r_x != last_hdr10_param.r_x || + hdr10_param.r_y != last_hdr10_param.r_y || + hdr10_param.g_x != last_hdr10_param.g_x || + hdr10_param.g_y != last_hdr10_param.g_y || + hdr10_param.b_x != last_hdr10_param.b_x || + hdr10_param.b_y != last_hdr10_param.b_y) { + last_hdr10_param.r_x = hdr10_param.r_x; + last_hdr10_param.r_y = hdr10_param.r_y; + last_hdr10_param.g_x = hdr10_param.g_x; + last_hdr10_param.g_y = hdr10_param.g_y; + last_hdr10_param.b_x = hdr10_param.b_x; + last_hdr10_param.b_y = hdr10_param.b_y; + return 1; + } + return 0; +} + static int cur_mute_type; static char mute_type_str[4][4] = { "NON", @@ -2980,232 +3379,121 @@ int get_mute_type(void) return MUTE_TYPE_NONE; } -static void adjust_vpotch(void) +static void apply_stb_core_settings + (int enable, unsigned int mask, + bool reset, u32 frame_size, u8 pps_state) { const struct vinfo_s *vinfo = get_current_vinfo(); - int sync_duration_num = 60; - - if (is_meson_txlx_stbmode() - || force_stb_mode) { - if (vinfo && (vinfo->width >= 1920) && - (vinfo->height >= 1080) && - (vinfo->field_height >= 1080)) - dma_start_line = 0x400; - else - dma_start_line = 0x180; - /* adjust core2 setting to work around*/ - /* fixing with 1080p24hz and 480p60hz */ - if (vinfo && (vinfo->width < 1280) && - (vinfo->height < 720) && - (vinfo->field_height < 720)) - g_vpotch = 0x60; - else - g_vpotch = 0x20; - } else if (is_meson_g12()) { - if (vinfo) { - if (vinfo->sync_duration_den) - sync_duration_num = vinfo->sync_duration_num / - vinfo->sync_duration_den; - if (debug_dolby & 2) - pr_dolby_dbg("vinfo %d %d %d %d %d %d\n", - vinfo->width, - vinfo->height, - vinfo->field_height, - vinfo->sync_duration_num, - vinfo->sync_duration_den, - sync_duration_num); - if ((vinfo->width < 1280) && - (vinfo->height < 720) && - (vinfo->field_height < 720)) - g_vpotch = 0x60; - else if ((vinfo->width == 1280) && - (vinfo->height == 720)) - g_vpotch = 0x38; - else if ((vinfo->width == 1280) && - (vinfo->height == 720) && - (vinfo->field_height < 720)) - g_vpotch = 0x60; - else if ((vinfo->width == 1920) && - (vinfo->height == 1080) && - (sync_duration_num < 30)) - g_vpotch = 0x60; - else if ((vinfo->width == 1920) && - (vinfo->height == 1080) && - (vinfo->field_height < 1080)) - g_vpotch = 0x60; - else - g_vpotch = 0x20; - if (vinfo->width > 1920) - htotal_add = 0xc0; - else - htotal_add = 0x140; - } else - g_vpotch = 0x20; - } else if (is_meson_tm2_stbmode()) { - if (vinfo) { - if (debug_dolby & 2) - pr_dolby_dbg("vinfo %d %d %d\n", - vinfo->width, - vinfo->height, - vinfo->field_height); - if ((vinfo->width < 1280) && - (vinfo->height < 720) && - (vinfo->field_height < 720)) - g_vpotch = 0x60; - else if ((vinfo->width <= 1920) && - (vinfo->height <= 1080) && - (vinfo->field_height <= 1080)) - g_vpotch = 0x50; - else - g_vpotch = 0x20; - } else - g_vpotch = 0x20; - } else if (is_meson_sc2()) { - if (vinfo) { - if (debug_dolby & 2) - pr_dolby_dbg("vinfo %d %d %d\n", - vinfo->width, - vinfo->height, - vinfo->field_height); - if ((vinfo->width < 1280) && - (vinfo->height < 720) && - (vinfo->field_height < 720)) - g_vpotch = 0x60; - else if ((vinfo->width <= 1920) && - (vinfo->height <= 1080) && - (vinfo->field_height <= 1080)) - g_vpotch = 0x50; - else - g_vpotch = 0x20; - - if (vinfo->width > 1920) - htotal_add = 0xc0; - else - htotal_add = 0x140; - } else { - g_vpotch = 0x20; - } - } - -} - -static void apply_stb_core_settings( - int enable, unsigned int mask, - bool reset, u32 frame_size, u8 pps_state) -{ - const struct vinfo_s *vinfo = get_current_vinfo(); - u32 h_size = (frame_size >> 16) & 0xffff; - u32 v_size = frame_size & 0xffff; -#ifdef V2_4 - u32 core1_dm_count = 27; -#else - u32 core1_dm_count = 24; -#endif - u32 graphics_w = osd_graphic_width; - u32 graphics_h = osd_graphic_height; - u32 update_bk = stb_core_setting_update_flag; - static u32 update_flag_more; - int mute_type; + u32 h_size = (frame_size >> 16) & 0xffff; + u32 v_size = frame_size & 0xffff; + u32 core1_dm_count = 27; + u32 graphics_w = osd_graphic_width; + u32 graphics_h = osd_graphic_height; + u32 update_bk = stb_core_setting_update_flag; + static u32 update_flag_more; + int mute_type; if (h_size == 0xffff) h_size = 0; if (v_size == 0xffff) v_size = 0; - if ((stb_core_setting_update_flag != update_flag_more) && + if (stb_core_setting_update_flag != update_flag_more && (debug_dolby & 2)) - pr_dolby_dbg( - "apply_stb_core_settings update setting again %x->%x\n", - stb_core_setting_update_flag, update_flag_more); + pr_dolby_dbg + ("%s update setting again %x->%x\n", + __func__, stb_core_setting_update_flag, + update_flag_more); stb_core_setting_update_flag |= update_flag_more; - if (is_dolby_vision_stb_mode() - && (dolby_vision_flags & FLAG_CERTIFICAION)) { + if (is_dolby_vision_stb_mode() && + (dolby_vision_flags & FLAG_CERTIFICAION)) { graphics_w = dv_cert_graphic_width; graphics_h = dv_cert_graphic_height; } adjust_vpotch(); if (mask & 1) { - if (is_meson_txlx_stbmode() - || force_stb_mode) { - stb_dolby_core1_set( - 27, 173, 256 * 5, - (uint32_t *)&new_dovi_setting.dm_reg1, - (uint32_t *)&new_dovi_setting.comp_reg, - (uint32_t *)&new_dovi_setting.dm_lut1, - h_size, - v_size, - /* BL enable */ - enable, - /* EL enable */ - enable && new_dovi_setting.el_flag, - new_dovi_setting.el_halfsize_flag, - dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL, - new_dovi_setting.src_format == FORMAT_DOVI, - 1, - reset); - } else - dolby_core1_set( - core1_dm_count, 173, 256 * 5, - (uint32_t *)&new_dovi_setting.dm_reg1, - (uint32_t *)&new_dovi_setting.comp_reg, - (uint32_t *)&new_dovi_setting.dm_lut1, - h_size, - v_size, - /* BL enable */ - enable, - /* EL enable */ - enable && new_dovi_setting.el_flag, - new_dovi_setting.el_halfsize_flag, - dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL, - new_dovi_setting.src_format == FORMAT_DOVI, - 1, - reset); + if (is_meson_txlx_stbmode()) { + stb_dolby_core1_set + (27, 173, 256 * 5, + (u32 *)&new_dovi_setting.dm_reg1, + (u32 *)&new_dovi_setting.comp_reg, + (u32 *)&new_dovi_setting.dm_lut1, + h_size, + v_size, + /* BL enable */ + enable, + /* EL enable */ + enable && new_dovi_setting.el_flag, + new_dovi_setting.el_halfsize_flag, + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL, + new_dovi_setting.src_format == FORMAT_DOVI, + 1, + reset); + } else { + dolby_core1_set + (core1_dm_count, 173, 256 * 5, + (u32 *)&new_dovi_setting.dm_reg1, + (u32 *)&new_dovi_setting.comp_reg, + (u32 *)&new_dovi_setting.dm_lut1, + h_size, + v_size, + /* BL enable */ + enable, + /* EL enable */ + enable && new_dovi_setting.el_flag, + new_dovi_setting.el_halfsize_flag, + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL, + new_dovi_setting.src_format == FORMAT_DOVI, + 1, + reset); + } } if (mask & 2) { - if (stb_core_setting_update_flag != FLAG_CHANGE_ALL) { - /* when FLAG_CONST_TC2 is set, */ + if (stb_core_setting_update_flag != CP_FLAG_CHANGE_ALL) { + /* when CP_FLAG_CONST_TC2 is set, */ /* set the stb_core_setting_update_flag */ - /* until only meeting the FLAG_CHANGE_TC2 */ - if (stb_core_setting_update_flag & FLAG_CONST_TC2) + /* until only meeting the CP_FLAG_CONST_TC2 */ + if (stb_core_setting_update_flag & + CP_FLAG_CONST_TC2) stb_core2_const_flag = true; - else if (stb_core_setting_update_flag & FLAG_CHANGE_TC2) + else if (stb_core_setting_update_flag & + CP_FLAG_CHANGE_TC2) stb_core2_const_flag = false; } - /* revert the core2 lut as last corret one when const case */ if (stb_core2_const_flag) memcpy(&new_dovi_setting.dm_lut2, &dovi_setting.dm_lut2, - sizeof(struct dm_lut_ipcore_s)); + sizeof(struct dm_lut_ipcore)); dolby_core2_set( 24, 256 * 5, - (uint32_t *)&new_dovi_setting.dm_reg2, - (uint32_t *)&new_dovi_setting.dm_lut2, + (u32 *)&new_dovi_setting.dm_reg2, + (u32 *)&new_dovi_setting.dm_lut2, graphics_w, graphics_h, 1, 1); } if (mask & 4) { v_size = vinfo->height; - if (((vinfo->width == 720) && - (vinfo->height == 480) && - (vinfo->height != vinfo->field_height)) || - ((vinfo->width == 720) && - (vinfo->height == 576) && - (vinfo->height != vinfo->field_height)) || - ((vinfo->width == 1920) && - (vinfo->height == 1080) && - (vinfo->height != vinfo->field_height)) || - ((vinfo->width == 1920) && - (vinfo->height == 1080) && - (vinfo->height != vinfo->field_height) && - (vinfo->sync_duration_num - / vinfo->sync_duration_den == 50))) + if ((vinfo->width == 720 && + vinfo->height == 480 && + vinfo->height != vinfo->field_height) || + (vinfo->width == 720 && + vinfo->height == 576 && + vinfo->height != vinfo->field_height) || + (vinfo->width == 1920 && + vinfo->height == 1080 && + vinfo->height != vinfo->field_height) || + (vinfo->width == 1920 && + vinfo->height == 1080 && + vinfo->height != vinfo->field_height && + vinfo->sync_duration_num + / vinfo->sync_duration_den == 50)) v_size = v_size / 2; mute_type = get_mute_type(); if ((get_video_mute() == VIDEO_MUTE_ON_DV) && @@ -3231,15 +3519,29 @@ static void apply_stb_core_settings( cur_mute_type = MUTE_TYPE_NONE; dolby_vision_flags &= ~FLAG_MUTE; } - dolby_core3_set( - 26, new_dovi_setting.md_reg3.size, - (uint32_t *)&new_dovi_setting.dm_reg3, - new_dovi_setting.md_reg3.raw_metadata, - vinfo->width, v_size, - 1, - dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL, - pps_state); + dolby_core3_set + (26, new_dovi_setting.md_reg3.size, + (u32 *)&new_dovi_setting.dm_reg3, + new_dovi_setting.md_reg3.raw_metadata, + vinfo->width, v_size, + 1, + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL, + pps_state); +#ifdef V2_4_3 + if (need_send_emp_meta(vinfo)) { + convert_hdmi_metadata + (new_dovi_setting.md_reg3.raw_metadata); + send_emp(EOTF_T_DOLBYVISION, + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL + ? RGB_8BIT : YUV422_BIT12, + NULL, + hdmi_metadata, + hdmi_metadata_size, + false); + } +#endif } stb_core_setting_update_flag = 0; update_flag_more = update_bk; @@ -3247,9 +3549,9 @@ static void apply_stb_core_settings( static void osd_bypass(int bypass) { - static uint32_t osd_backup_ctrl; - static uint32_t osd_backup_eotf; - static uint32_t osd_backup_mtx; + static u32 osd_backup_ctrl; + static u32 osd_backup_eotf; + static u32 osd_backup_mtx; if (bypass) { osd_backup_ctrl = VSYNC_RD_DV_REG(VIU_OSD1_CTRL_STAT); @@ -3278,6 +3580,27 @@ static bool is_video_effect_bypass; static void video_effect_bypass(int bypass) { + if (is_meson_tm2_tvmode()) { + /*only bypass vpp pq for dovi source*/ + if (!debug_bypass_vpp_pq && + (dolby_vision_src_format != 3 && + !(dolby_vision_flags & FLAG_CERTIFICAION))) + return; + } + if (debug_bypass_vpp_pq == 1) { + if ((dolby_vision_flags & FLAG_CERTIFICAION) || + bypass_all_vpp_pq || is_meson_tvmode()) + dv_pq_ctl(DV_PQ_CERT); + else + dv_pq_ctl(DV_PQ_BYPASS); + return; + } else if (debug_bypass_vpp_pq == 2) { + dv_pq_ctl(DV_PQ_REC); + return; + } else if (debug_bypass_vpp_pq == 3) { + return; + } + if (bypass) { if (!is_video_effect_bypass) { if (is_meson_txlx()) { @@ -3304,37 +3627,38 @@ static void video_effect_bypass(int bypass) VSYNC_WR_DV_REG(XVYCC_INV_LUT_CTL, 0); VSYNC_WR_DV_REG(VPP_VADJ_CTRL, 0); VSYNC_WR_DV_REG(XVYCC_VD1_RGB_CTRST, 0); - VSYNC_WR_DV_REG(VPP_GAINOFF_CTRL0, 0); VSYNC_WR_DV_REG(VPP_VE_ENABLE_CTRL, 0); + VSYNC_WR_DV_REG(VPP_GAINOFF_CTRL0, 0); } else { - if (dolby_vision_flags & FLAG_CERTIFICAION) + if ((dolby_vision_flags & FLAG_CERTIFICAION) || + bypass_all_vpp_pq || is_meson_tvmode()) dv_pq_ctl(DV_PQ_CERT); else dv_pq_ctl(DV_PQ_BYPASS); } } else if (is_video_effect_bypass) { if (is_meson_txlx()) { - VSYNC_WR_DV_REG( - VIU_EOTF_CTL, - viu_eotf_ctrl_backup); - VSYNC_WR_DV_REG( - XVYCC_LUT_CTL, - xvycc_lut_ctrl_backup); - VSYNC_WR_DV_REG( - XVYCC_INV_LUT_CTL, + VSYNC_WR_DV_REG + (VIU_EOTF_CTL, + viu_eotf_ctrl_backup); + VSYNC_WR_DV_REG + (XVYCC_LUT_CTL, + xvycc_lut_ctrl_backup); + VSYNC_WR_DV_REG + (XVYCC_INV_LUT_CTL, inv_lut_ctrl_backup); - VSYNC_WR_DV_REG( - VPP_VADJ_CTRL, - vpp_vadj_backup); - VSYNC_WR_DV_REG( - XVYCC_VD1_RGB_CTRST, - xvycc_vd1_rgb_ctrst_backup); - VSYNC_WR_DV_REG( - VPP_GAINOFF_CTRL0, - vpp_gainoff_backup); - VSYNC_WR_DV_REG( - VPP_VE_ENABLE_CTRL, + VSYNC_WR_DV_REG + (VPP_VADJ_CTRL, + vpp_vadj_backup); + VSYNC_WR_DV_REG + (XVYCC_VD1_RGB_CTRST, + xvycc_vd1_rgb_ctrst_backup); + VSYNC_WR_DV_REG + (VPP_VE_ENABLE_CTRL, vpp_ve_enable_ctrl_backup); + VSYNC_WR_DV_REG + (VPP_GAINOFF_CTRL0, + vpp_gainoff_backup); } else { dv_pq_ctl(DV_PQ_REC); } @@ -3358,147 +3682,147 @@ static void osd_path_enable(int on) if ((hdr_osd_reg.viu_osd1_eotf_ctl & 0x80000000) != 0) { addr_port = VIU_OSD1_EOTF_LUT_ADDR_PORT; data_port = VIU_OSD1_EOTF_LUT_DATA_PORT; - VSYNC_WR_DV_REG( - addr_port, 0); + VSYNC_WR_DV_REG + (addr_port, 0); for (i = 0; i < 16; i++) - VSYNC_WR_DV_REG( - data_port, - lut->r_map[i * 2] - | (lut->r_map[i * 2 + 1] << 16)); - VSYNC_WR_DV_REG( - data_port, - lut->r_map[EOTF_LUT_SIZE - 1] - | (lut->g_map[0] << 16)); + VSYNC_WR_DV_REG + (data_port, + lut->r_map[i * 2] + | (lut->r_map[i * 2 + 1] << 16)); + VSYNC_WR_DV_REG + (data_port, + lut->r_map[EOTF_LUT_SIZE - 1] + | (lut->g_map[0] << 16)); for (i = 0; i < 16; i++) - VSYNC_WR_DV_REG( - data_port, - lut->g_map[i * 2 + 1] - | (lut->b_map[i * 2 + 2] << 16)); + VSYNC_WR_DV_REG + (data_port, + lut->g_map[i * 2 + 1] + | (lut->b_map[i * 2 + 2] << 16)); for (i = 0; i < 16; i++) - VSYNC_WR_DV_REG( - data_port, - lut->b_map[i * 2] - | (lut->b_map[i * 2 + 1] << 16)); - VSYNC_WR_DV_REG( - data_port, lut->b_map[EOTF_LUT_SIZE - 1]); + VSYNC_WR_DV_REG + (data_port, + lut->b_map[i * 2] + | (lut->b_map[i * 2 + 1] << 16)); + VSYNC_WR_DV_REG + (data_port, lut->b_map[EOTF_LUT_SIZE - 1]); /* load eotf matrix */ - VSYNC_WR_DV_REG( - VIU_OSD1_EOTF_COEF00_01, - hdr_osd_reg.viu_osd1_eotf_coef00_01); - VSYNC_WR_DV_REG( - VIU_OSD1_EOTF_COEF02_10, - hdr_osd_reg.viu_osd1_eotf_coef02_10); - VSYNC_WR_DV_REG( - VIU_OSD1_EOTF_COEF11_12, - hdr_osd_reg.viu_osd1_eotf_coef11_12); - VSYNC_WR_DV_REG( - VIU_OSD1_EOTF_COEF20_21, - hdr_osd_reg.viu_osd1_eotf_coef20_21); - VSYNC_WR_DV_REG( - VIU_OSD1_EOTF_COEF22_RS, - hdr_osd_reg.viu_osd1_eotf_coef22_rs); - VSYNC_WR_DV_REG( - VIU_OSD1_EOTF_CTL, - hdr_osd_reg.viu_osd1_eotf_ctl); + VSYNC_WR_DV_REG + (VIU_OSD1_EOTF_COEF00_01, + hdr_osd_reg.viu_osd1_eotf_coef00_01); + VSYNC_WR_DV_REG + (VIU_OSD1_EOTF_COEF02_10, + hdr_osd_reg.viu_osd1_eotf_coef02_10); + VSYNC_WR_DV_REG + (VIU_OSD1_EOTF_COEF11_12, + hdr_osd_reg.viu_osd1_eotf_coef11_12); + VSYNC_WR_DV_REG + (VIU_OSD1_EOTF_COEF20_21, + hdr_osd_reg.viu_osd1_eotf_coef20_21); + VSYNC_WR_DV_REG + (VIU_OSD1_EOTF_COEF22_RS, + hdr_osd_reg.viu_osd1_eotf_coef22_rs); + VSYNC_WR_DV_REG + (VIU_OSD1_EOTF_CTL, + hdr_osd_reg.viu_osd1_eotf_ctl); } /* restore oetf lut */ if ((hdr_osd_reg.viu_osd1_oetf_ctl & 0xe0000000) != 0) { addr_port = VIU_OSD1_OETF_LUT_ADDR_PORT; data_port = VIU_OSD1_OETF_LUT_DATA_PORT; for (i = 0; i < 20; i++) { - VSYNC_WR_DV_REG( - addr_port, i); - VSYNC_WR_DV_REG( - data_port, - lut->or_map[i * 2] - | (lut->or_map[i * 2 + 1] << 16)); + VSYNC_WR_DV_REG + (addr_port, i); + VSYNC_WR_DV_REG + (data_port, + lut->or_map[i * 2] + | (lut->or_map[i * 2 + 1] << 16)); } - VSYNC_WR_DV_REG( - addr_port, 20); - VSYNC_WR_DV_REG( - data_port, - lut->or_map[41 - 1] - | (lut->og_map[0] << 16)); + VSYNC_WR_DV_REG + (addr_port, 20); + VSYNC_WR_DV_REG + (data_port, + lut->or_map[41 - 1] + | (lut->og_map[0] << 16)); for (i = 0; i < 20; i++) { - VSYNC_WR_DV_REG( - addr_port, 21 + i); - VSYNC_WR_DV_REG( - data_port, - lut->og_map[i * 2 + 1] - | (lut->og_map[i * 2 + 2] << 16)); + VSYNC_WR_DV_REG + (addr_port, 21 + i); + VSYNC_WR_DV_REG + (data_port, + lut->og_map[i * 2 + 1] + | (lut->og_map[i * 2 + 2] << 16)); } for (i = 0; i < 20; i++) { - VSYNC_WR_DV_REG( - addr_port, 41 + i); - VSYNC_WR_DV_REG( - data_port, - lut->ob_map[i * 2] - | (lut->ob_map[i * 2 + 1] << 16)); + VSYNC_WR_DV_REG + (addr_port, 41 + i); + VSYNC_WR_DV_REG + (data_port, + lut->ob_map[i * 2] + | (lut->ob_map[i * 2 + 1] << 16)); } - VSYNC_WR_DV_REG( - addr_port, 61); - VSYNC_WR_DV_REG( - data_port, - lut->ob_map[41 - 1]); - VSYNC_WR_DV_REG( - VIU_OSD1_OETF_CTL, - hdr_osd_reg.viu_osd1_oetf_ctl); - } - } - VSYNC_WR_DV_REG( - VIU_OSD1_MATRIX_PRE_OFFSET0_1, - hdr_osd_reg.viu_osd1_matrix_pre_offset0_1); - VSYNC_WR_DV_REG( - VIU_OSD1_MATRIX_PRE_OFFSET2, - hdr_osd_reg.viu_osd1_matrix_pre_offset2); - VSYNC_WR_DV_REG( - VIU_OSD1_MATRIX_COEF00_01, - hdr_osd_reg.viu_osd1_matrix_coef00_01); - VSYNC_WR_DV_REG( - VIU_OSD1_MATRIX_COEF02_10, - hdr_osd_reg.viu_osd1_matrix_coef02_10); - VSYNC_WR_DV_REG( - VIU_OSD1_MATRIX_COEF11_12, - hdr_osd_reg.viu_osd1_matrix_coef11_12); - VSYNC_WR_DV_REG( - VIU_OSD1_MATRIX_COEF20_21, - hdr_osd_reg.viu_osd1_matrix_coef20_21); - VSYNC_WR_DV_REG( - VIU_OSD1_MATRIX_COEF22_30, - hdr_osd_reg.viu_osd1_matrix_coef22_30); - VSYNC_WR_DV_REG( - VIU_OSD1_MATRIX_COEF31_32, - hdr_osd_reg.viu_osd1_matrix_coef31_32); - VSYNC_WR_DV_REG( - VIU_OSD1_MATRIX_COEF40_41, - hdr_osd_reg.viu_osd1_matrix_coef40_41); - VSYNC_WR_DV_REG( - VIU_OSD1_MATRIX_COLMOD_COEF42, - hdr_osd_reg.viu_osd1_matrix_colmod_coef42); - VSYNC_WR_DV_REG( - VIU_OSD1_MATRIX_OFFSET0_1, - hdr_osd_reg.viu_osd1_matrix_offset0_1); - VSYNC_WR_DV_REG( - VIU_OSD1_MATRIX_OFFSET2, - hdr_osd_reg.viu_osd1_matrix_offset2); - VSYNC_WR_DV_REG( - VIU_OSD1_MATRIX_CTRL, - hdr_osd_reg.viu_osd1_matrix_ctrl); + VSYNC_WR_DV_REG + (addr_port, 61); + VSYNC_WR_DV_REG + (data_port, + lut->ob_map[41 - 1]); + VSYNC_WR_DV_REG + (VIU_OSD1_OETF_CTL, + hdr_osd_reg.viu_osd1_oetf_ctl); + } + } + VSYNC_WR_DV_REG + (VIU_OSD1_MATRIX_PRE_OFFSET0_1, + hdr_osd_reg.viu_osd1_matrix_pre_offset0_1); + VSYNC_WR_DV_REG + (VIU_OSD1_MATRIX_PRE_OFFSET2, + hdr_osd_reg.viu_osd1_matrix_pre_offset2); + VSYNC_WR_DV_REG + (VIU_OSD1_MATRIX_COEF00_01, + hdr_osd_reg.viu_osd1_matrix_coef00_01); + VSYNC_WR_DV_REG + (VIU_OSD1_MATRIX_COEF02_10, + hdr_osd_reg.viu_osd1_matrix_coef02_10); + VSYNC_WR_DV_REG + (VIU_OSD1_MATRIX_COEF11_12, + hdr_osd_reg.viu_osd1_matrix_coef11_12); + VSYNC_WR_DV_REG + (VIU_OSD1_MATRIX_COEF20_21, + hdr_osd_reg.viu_osd1_matrix_coef20_21); + VSYNC_WR_DV_REG + (VIU_OSD1_MATRIX_COEF22_30, + hdr_osd_reg.viu_osd1_matrix_coef22_30); + VSYNC_WR_DV_REG + (VIU_OSD1_MATRIX_COEF31_32, + hdr_osd_reg.viu_osd1_matrix_coef31_32); + VSYNC_WR_DV_REG + (VIU_OSD1_MATRIX_COEF40_41, + hdr_osd_reg.viu_osd1_matrix_coef40_41); + VSYNC_WR_DV_REG + (VIU_OSD1_MATRIX_COLMOD_COEF42, + hdr_osd_reg.viu_osd1_matrix_colmod_coef42); + VSYNC_WR_DV_REG + (VIU_OSD1_MATRIX_OFFSET0_1, + hdr_osd_reg.viu_osd1_matrix_offset0_1); + VSYNC_WR_DV_REG + (VIU_OSD1_MATRIX_OFFSET2, + hdr_osd_reg.viu_osd1_matrix_offset2); + VSYNC_WR_DV_REG + (VIU_OSD1_MATRIX_CTRL, + hdr_osd_reg.viu_osd1_matrix_ctrl); } static u32 dolby_ctrl_backup = 0x22000; -static uint32_t viu_misc_ctrl_backup; -static uint32_t vpp_matrix_backup; -static uint32_t vpp_dummy1_backup; -static uint32_t vpp_data_conv_para0_backup; -static uint32_t vpp_data_conv_para1_backup; +static u32 viu_misc_ctrl_backup; +static u32 vpp_matrix_backup; +static u32 vpp_dummy1_backup; +static u32 vpp_data_conv_para0_backup; +static u32 vpp_data_conv_para1_backup; void enable_dolby_vision(int enable) { u32 size = 0; u64 *dma_data = tv_dovi_setting->core1_reg_lut; u32 core_flag = 0; - + int gd_en = 0; if (enable) { if (!dolby_vision_on) { dolby_vision_wait_on = true; @@ -3517,27 +3841,26 @@ void enable_dolby_vision(int enable) VSYNC_RD_DV_REG(VPP_DAT_CONV_PARA1); setting_update_count = 0; } - if (is_meson_tvmode() && !force_stb_mode) { + if (is_meson_tvmode()) { if (efuse_mode == 1) { size = 8 * TV_DMA_TBL_SIZE; memset(dma_vaddr, 0x0, size); - memcpy((uint64_t *)dma_vaddr + 1, - dma_data + 1, - 8); + memcpy((u64 *)dma_vaddr + 1, + dma_data + 1, 8); } if (is_meson_txlx_tvmode()) { - if ((dolby_vision_mask & 1) - && dovi_setting_video_flag) { - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - 0, - 16, 1); /* core1 */ + if ((dolby_vision_mask & 1) && + dovi_setting_video_flag) { + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + 0, + 16, 1); /* core1 */ dolby_vision_core1_on = true; } else { - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - 1, - 16, 1); /* core1 */ + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + 1, + 16, 1); /* core1 */ dolby_vision_core1_on = false; } } else if (is_meson_tm2_tvmode()) { @@ -3547,35 +3870,34 @@ void enable_dolby_vision(int enable) if (dolby_vision_flags & FLAG_CERTIFICAION) hdr_vd1_off(); - if ((dolby_vision_mask & 1) - && dovi_setting_video_flag) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, 8, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, 10, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, 24, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 16, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 20, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 0, - (tv_dovi_setting-> - el_flag ? 2 : 1)); + if ((dolby_vision_mask & 1) && + dovi_setting_video_flag) { + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, 8, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, 10, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, 24, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 16, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 20, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + tv_dovi_setting->el_flag ? + 0 : 2, 0, 2); dolby_vision_core1_on = true; } else { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 3, 0, 2); - VSYNC_WR_DV_REG( - DOLBY_TV_CLKGATE_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 3, 0, 2); + VSYNC_WR_DV_REG + (DOLBY_TV_CLKGATE_CTRL, 0x55555555); dv_mem_power_off(VPU_DOLBY0); dolby_vision_core1_on = false; @@ -3584,8 +3906,8 @@ void enable_dolby_vision(int enable) if (dolby_vision_flags & FLAG_CERTIFICAION) { /* bypass dither/PPS/SR/CM, EO/OE */ - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, 3, 0, 2); + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, 3, 0, 2); /* bypass all video effect */ video_effect_bypass(1); if (is_meson_txlx_tvmode()) { @@ -3593,138 +3915,145 @@ void enable_dolby_vision(int enable) /* before vadj1 */ /* 12 bit sign to unsign*/ /* before post blend */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA0, 0x08000800); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA0, + 0x08000800); /* 12->10 before vadj2*/ /* 10->12 after gainoff */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA1, 0x20002000); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA1, + 0x20002000); } WRITE_VPP_DV_REG(DOLBY_TV_DIAG_CTRL, 0xb); } else { /* bypass all video effect */ - if (dolby_vision_flags - & FLAG_BYPASS_VPP) + if (dolby_vision_flags & + FLAG_BYPASS_VPP) video_effect_bypass(1); if (is_meson_txlx_tvmode()) { /* 12->10 before vadj1*/ /* 10->12 before post blend */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA0, 0x20002000); - /* 12->10 before vadj2*/ - /* 10->12 after gainoff */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA1, 0x20002000); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA0, + 0x20002000); + /* 12->10 before vadj2*/ + /* 10->12 after gainoff */ + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA1, + 0x20002000); } } - VSYNC_WR_DV_REG( - VPP_DUMMY_DATA1, - 0x80200); + VSYNC_WR_DV_REG + (VPP_DUMMY_DATA1, + 0x80200); /* osd rgb to yuv, vpp out yuv to rgb */ VSYNC_WR_DV_REG(VPP_MATRIX_CTRL, 0x81); pr_info("Dolby Vision TV core turn on\n"); - } else if (is_meson_txlx_stbmode() - || force_stb_mode) { + } else if (is_meson_txlx_stbmode()) { size = 8 * STB_DMA_TBL_SIZE; if (efuse_mode == 1) memset(dma_vaddr, 0x0, size); osd_bypass(1); if (dolby_vision_mask & 4) - VSYNC_WR_DV_REG_BITS(VPP_DOLBY_CTRL, - 1, 3, 1); /* core3 enable */ - if ((dolby_vision_mask & 1) - && dovi_setting_video_flag) { - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - 0, - 16, 1); /* core1 */ + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, + 1, 3, 1); /* core3 enable */ + if ((dolby_vision_mask & 1) && + dovi_setting_video_flag) { + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + 0, + 16, 1); /* core1 */ dolby_vision_core1_on = true; } else { - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - 1, - 16, 1); /* core1 */ + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + 1, + 16, 1); /* core1 */ dolby_vision_core1_on = false; } - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - (((dolby_vision_mask & 1) - && dovi_setting_video_flag) - ? 0 : 1), - 16, 1); /* core1 */ - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - ((dolby_vision_mask & 2) ? 0 : 1), - 18, 1); /* core2 */ + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + (((dolby_vision_mask & 1) && + dovi_setting_video_flag) + ? 0 : 1), + 16, 1); /* core1 */ + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + ((dolby_vision_mask & 2) ? 0 : 1), + 18, 1); /* core2 */ if (dolby_vision_flags & FLAG_CERTIFICAION) { /* bypass dither/PPS/SR/CM*/ /* bypass EO/OE*/ /* bypass vadj2/mtx/gainoff */ - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, 7, 0, 3); + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, 7, 0, 3); /* bypass all video effect */ video_effect_bypass(1); /* 12 bit unsigned to sign*/ /* before vadj1 */ /* 12 bit sign to unsign*/ /* before post blend */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA0, 0x08000800); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA0, + 0x08000800); /* 12->10 before vadj2*/ /* 10->12 after gainoff */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA1, 0x20002000); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA1, + 0x20002000); } else { /* bypass all video effect */ - if (dolby_vision_flags - & FLAG_BYPASS_VPP) + if (dolby_vision_flags & + FLAG_BYPASS_VPP) video_effect_bypass(1); /* 12->10 before vadj1*/ /* 10->12 before post blend */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA0, 0x20002000); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA0, + 0x20002000); /* 12->10 before vadj2*/ /* 10->12 after gainoff */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA1, 0x20002000); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA1, + 0x20002000); } - VSYNC_WR_DV_REG(VPP_DUMMY_DATA1, - 0x80200); + VSYNC_WR_DV_REG(VPP_DUMMY_DATA1, 0x80200); if (is_meson_tvmode()) VSYNC_WR_DV_REG(VPP_MATRIX_CTRL, 1); else VSYNC_WR_DV_REG(VPP_MATRIX_CTRL, 0); -#ifdef V2_4 - if (((dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL) - || (dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_IPT)) && - (dovi_setting.diagnostic_enable == 0) && - dovi_setting.dovi_ll_enable) { + + if ((dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL || + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_IPT) && + dovi_setting.diagnostic_enable == 0 && + dovi_setting.dovi_ll_enable) { u32 *reg = (u32 *)&dovi_setting.dm_reg3; /* input u12 -0x800 to s12 */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA1, 0x8000800); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA1, 0x8000800); /* bypass vadj */ - VSYNC_WR_DV_REG( - VPP_VADJ_CTRL, 0); + VSYNC_WR_DV_REG + (VPP_VADJ_CTRL, 0); /* bypass gainoff */ - VSYNC_WR_DV_REG( - VPP_GAINOFF_CTRL0, 0); + VSYNC_WR_DV_REG + (VPP_GAINOFF_CTRL0, 0); /* enable wm tp vks*/ /* bypass gainoff to vks */ - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, 1, 1, 2); - enable_rgb_to_yuv_matrix_for_dvll( - 1, ®[18], 12); - } else - enable_rgb_to_yuv_matrix_for_dvll( - 0, NULL, 12); + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, 1, 1, 2); + enable_rgb_to_yuv_matrix_for_dvll + (1, ®[18], 12); + } else { + enable_rgb_to_yuv_matrix_for_dvll + (0, NULL, 12); + } last_dolby_vision_ll_policy = dolby_vision_ll_policy; -#endif pr_info("Dolby Vision STB cores turn on\n"); } else if (is_meson_g12() || is_meson_tm2_stbmode() || @@ -3739,97 +4068,94 @@ void enable_dolby_vision(int enable) else VSYNC_WR_DV_REG_BITS(VPP_DOLBY_CTRL, 0, 3, 1); /* bypass core3 */ - if (dolby_vision_mask & 2) - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, - 2, 1);/*core2 enable*/ + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, + 2, 1);/*core2 enable*/ else - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, - 2, 1);/*core2 bypass*/ + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, + 2, 1);/*core2 bypass*/ if (is_meson_g12()) { hdr_vd1_off(); - if ((dolby_vision_mask & 1) - && dovi_setting_video_flag) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, - 0, 1); /* core1 on */ + if ((dolby_vision_mask & 1) && + dovi_setting_video_flag) { + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, + 0, 1); /* core1 on*/ dolby_vision_core1_on = true; } else { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, - 0, 1); /* core1 off */ + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, + 0, 1); /* core1 off*/ dv_mem_power_off(VPU_DOLBY1A); - dv_mem_power_off( - VPU_PRIME_DOLBY_RAM); - VSYNC_WR_DV_REG( - DOLBY_CORE1_CLKGATE_CTRL, - 0x55555455); + dv_mem_power_off + (VPU_PRIME_DOLBY_RAM); + VSYNC_WR_DV_REG + (DOLBY_CORE1_CLKGATE_CTRL, + 0x55555455); dolby_vision_core1_on = false; } - } else if (is_meson_tm2_stbmode() || + } else if (is_meson_tm2_stbmode() || is_meson_sc2()) { if (is_meson_tm2_stb_hdmimode()) core_flag = 1; - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, core_flag, 8, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, core_flag, 10, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, core_flag, 24, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, 0, 16, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, 0, 17, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, 0, 20, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, 0, 21, 1); if ((dolby_vision_mask & 1) && dovi_setting_video_flag) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, 0, 0, 2); /* core1 on */ dolby_vision_core1_on = true; } else { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 3, - 0, 2); /* core1 off */ - + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 3, 0, 2); /*core1 off*/ dv_mem_power_off(VPU_DOLBY1A); - dv_mem_power_off( - VPU_PRIME_DOLBY_RAM); - VSYNC_WR_DV_REG( - DOLBY_CORE1_CLKGATE_CTRL, - 0x55555455); + dv_mem_power_off + (VPU_PRIME_DOLBY_RAM); + VSYNC_WR_DV_REG + (DOLBY_CORE1_CLKGATE_CTRL, + 0x55555455); dolby_vision_core1_on = false; } if (core_flag && dolby_vision_core1_on) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, 3, 0, 2); /* core1 off */ dv_mem_power_off(VPU_DOLBY1A); - dv_mem_power_off( - VPU_PRIME_DOLBY_RAM); - VSYNC_WR_DV_REG( - DOLBY_CORE1_CLKGATE_CTRL, - 0x55555455); + dv_mem_power_off + (VPU_PRIME_DOLBY_RAM); + VSYNC_WR_DV_REG + (DOLBY_CORE1_CLKGATE_CTRL, + 0x55555455); /* hdr core on */ hdr_vd1_iptmap(); } @@ -3838,267 +4164,269 @@ void enable_dolby_vision(int enable) /* bypass dither/PPS/SR/CM*/ /* bypass EO/OE*/ /* bypass vadj2/mtx/gainoff */ - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, 7, 0, 3); + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, 7, 0, 3); /* bypass all video effect */ video_effect_bypass(1); /* 12 bit unsigned to sign*/ /* before vadj1 */ /* 12 bit sign to unsign*/ /* before post blend */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA0, 0x08000800); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA0, + 0x08000800); /* 12->10 before vadj2*/ /* 10->12 after gainoff */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA1, 0x20002000); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA1, + 0x20002000); } else { /* bypass all video effect */ - if (dolby_vision_flags - & FLAG_BYPASS_VPP) + if (dolby_vision_flags & + FLAG_BYPASS_VPP) video_effect_bypass(1); /* 12->10 before vadj1*/ /* 10->12 before post blend */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA0, 0x20002000); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA0, + 0x20002000); /* 12->10 before vadj2*/ /* 10->12 after gainoff */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA1, 0x20002000); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA1, + 0x20002000); } VSYNC_WR_DV_REG(VPP_MATRIX_CTRL, 0); - VSYNC_WR_DV_REG(VPP_DUMMY_DATA1, - 0x80200); -#ifdef V2_4 - if (((dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL) - || (dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_IPT)) && - (dovi_setting.diagnostic_enable == 0) && - dovi_setting.dovi_ll_enable) { + VSYNC_WR_DV_REG(VPP_DUMMY_DATA1, 0x80200); + if ((dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL || + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_IPT) && + dovi_setting.diagnostic_enable == 0 && + dovi_setting.dovi_ll_enable) { u32 *reg = (u32 *)&dovi_setting.dm_reg3; /* input u12 -0x800 to s12 */ - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA1, 0x8000800); + VSYNC_WR_DV_REG + (VPP_DAT_CONV_PARA1, 0x8000800); /* bypass vadj */ - VSYNC_WR_DV_REG( - VPP_VADJ_CTRL, 0); + VSYNC_WR_DV_REG + (VPP_VADJ_CTRL, 0); /* bypass gainoff */ - VSYNC_WR_DV_REG( - VPP_GAINOFF_CTRL0, 0); + VSYNC_WR_DV_REG + (VPP_GAINOFF_CTRL0, 0); /* enable wm tp vks*/ /* bypass gainoff to vks */ - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, 1, 1, 2); - enable_rgb_to_yuv_matrix_for_dvll( - 1, ®[18], - (dv_ll_output_mode >> 8) - & 0xff); - } else - enable_rgb_to_yuv_matrix_for_dvll( - 0, NULL, 12); + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, 1, 1, 2); + enable_rgb_to_yuv_matrix_for_dvll + (1, ®[18], + (dv_ll_output_mode >> 8) + & 0xff); + } else { + enable_rgb_to_yuv_matrix_for_dvll + (0, NULL, 12); + } last_dolby_vision_ll_policy = dolby_vision_ll_policy; -#endif - pr_dolby_dbg( - "Dolby Vision G12a turn on%s\n", + pr_dolby_dbg + ("Dolby Vision G12a turn on%s\n", dolby_vision_core1_on ? ", core1 on" : ""); if (!dolby_vision_core1_on) frame_count = 0; } else { - VSYNC_WR_DV_REG(VPP_DOLBY_CTRL, - /* cm_datx4_mode */ - (0x0<<21) | - /* reg_front_cti_bit_mode */ - (0x0<<20) | - /* vpp_clip_ext_mode 19:17 */ - (0x0<<17) | - /* vpp_dolby2_en core3 */ - (((dolby_vision_mask & 4) ? - (1 << 0) : (0 << 0)) << 16) | - /* mat_xvy_dat_mode */ - (0x0<<15) | - /* vpp_ve_din_mode */ - (0x1<<14) | - /* mat_vd2_dat_mode 13:12 */ - (0x1<<12) | - /* vpp_dpath_sel 10:8 */ - (0x3<<8) | - /* vpp_uns2s_mode 7:0 */ - 0x1f); - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* 23-20 ext mode */ - (0 << 2) | - /* 19 osd2 enable */ - ((dolby_vision_flags - & FLAG_CERTIFICAION) - ? (0 << 1) : (1 << 1)) | - /* 18 core2 bypass */ - ((dolby_vision_mask & 2) ? - 0 : 1), - 18, 6); - if ((dolby_vision_mask & 1) - && dovi_setting_video_flag) { - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - 0, - 16, 1); /* core1 */ + VSYNC_WR_DV_REG + (VPP_DOLBY_CTRL, + /* cm_datx4_mode */ + (0x0 << 21) | + /* reg_front_cti_bit_mode */ + (0x0 << 20) | + /* vpp_clip_ext_mode 19:17 */ + (0x0 << 17) | + /* vpp_dolby2_en core3 */ + (((dolby_vision_mask & 4) ? + (1 << 0) : (0 << 0)) << 16) | + /* mat_xvy_dat_mode */ + (0x0 << 15) | + /* vpp_ve_din_mode */ + (0x1 << 14) | + /* mat_vd2_dat_mode 13:12 */ + (0x1 << 12) | + /* vpp_dpath_sel 10:8 */ + (0x3 << 8) | + /* vpp_uns2s_mode 7:0 */ + 0x1f); + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* 23-20 ext mode */ + (0 << 2) | + /* 19 osd2 enable */ + ((dolby_vision_flags + & FLAG_CERTIFICAION) + ? (0 << 1) : (1 << 1)) | + /* 18 core2 bypass */ + ((dolby_vision_mask & 2) ? + 0 : 1), + 18, 6); + if ((dolby_vision_mask & 1) && + dovi_setting_video_flag) { + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + 0, + 16, 1); /* core1 */ dolby_vision_core1_on = true; } else { - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - 1, - 16, 1); /* core1 */ + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + 1, + 16, 1); /* core1 */ dolby_vision_core1_on = false; } /* bypass all video effect */ - if ((dolby_vision_flags & FLAG_BYPASS_VPP) - || (dolby_vision_flags & FLAG_CERTIFICAION)) + if ((dolby_vision_flags & FLAG_BYPASS_VPP) || + (dolby_vision_flags & FLAG_CERTIFICAION)) video_effect_bypass(1); VSYNC_WR_DV_REG(VPP_MATRIX_CTRL, 0); VSYNC_WR_DV_REG(VPP_DUMMY_DATA1, 0x20000000); -#ifdef V2_4 - if (((dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL) - || (dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_IPT)) && - (dovi_setting.diagnostic_enable == 0) && - dovi_setting.dovi_ll_enable) { + if ((dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL || + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_IPT) && + dovi_setting.diagnostic_enable == 0 && + dovi_setting.dovi_ll_enable) { u32 *reg = (u32 *)&dovi_setting.dm_reg3; - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, 3, 6, 2); /* post matrix */ - enable_rgb_to_yuv_matrix_for_dvll( - 1, ®[18], 12); - } else - enable_rgb_to_yuv_matrix_for_dvll( - 0, NULL, 12); + enable_rgb_to_yuv_matrix_for_dvll + (1, ®[18], 12); + } else { + enable_rgb_to_yuv_matrix_for_dvll + (0, NULL, 12); + } last_dolby_vision_ll_policy = dolby_vision_ll_policy; -#endif /* disable osd effect and shadow mode */ osd_path_enable(0); - pr_dolby_dbg( - "Dolby Vision turn on%s\n", - dolby_vision_core1_on ? - ", core1 on" : ""); + pr_dolby_dbg("Dolby Vision turn on%s\n", + dolby_vision_core1_on ? + ", core1 on" : ""); } dolby_vision_core1_on_cnt = 0; } else { - if (!dolby_vision_core1_on - && (dolby_vision_mask & 1) - && dovi_setting_video_flag) { + if (!dolby_vision_core1_on && + (dolby_vision_mask & 1) && + dovi_setting_video_flag) { if (is_meson_g12() || is_meson_tm2_stbmode() || is_meson_sc2()) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, /* enable core1 */ 0, 0, 2); if (is_meson_tm2_stb_hdmimode()) { /* core1 off */ - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, 3, 0, 2); dv_mem_power_off(VPU_DOLBY1A); - dv_mem_power_off( - VPU_PRIME_DOLBY_RAM); - VSYNC_WR_DV_REG( - DOLBY_CORE1_CLKGATE_CTRL, - 0x55555455); + dv_mem_power_off + (VPU_PRIME_DOLBY_RAM); + VSYNC_WR_DV_REG + (DOLBY_CORE1_CLKGATE_CTRL, + 0x55555455); /* hdr core on */ hdr_vd1_iptmap(); } else { hdr_vd1_off(); } } else if (is_meson_tm2_tvmode()) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, 8, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, 10, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 1, 24, 2); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 16, 1); - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 20, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, 8, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, 10, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 1, 24, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 16, 1); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 0, 20, 1); /* enable core1 */ - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 0, 0, - (tv_dovi_setting->el_flag ? - 2 : 1)); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + /* enable core1 */ + tv_dovi_setting->el_flag ? + 0 : 2, 0, 2); } else - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - 0, - 16, 1); /* core1 */ + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + 0, + 16, 1); /* core1 */ dolby_vision_core1_on = true; dolby_vision_core1_on_cnt = 0; pr_dolby_dbg("Dolby Vision core1 turn on\n"); - } else if (dolby_vision_core1_on - && (!(dolby_vision_mask & 1) - || !dovi_setting_video_flag)) { + } else if (dolby_vision_core1_on && + (!(dolby_vision_mask & 1) || + !dovi_setting_video_flag)) { if (is_meson_g12() || is_meson_tm2_stbmode() || is_meson_sc2()) { /* core1a */ - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 3, 0, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, + 3, 0, 2); dv_mem_power_off(VPU_DOLBY1A); dv_mem_power_off(VPU_PRIME_DOLBY_RAM); - VSYNC_WR_DV_REG( - DOLBY_CORE1_CLKGATE_CTRL, + VSYNC_WR_DV_REG + (DOLBY_CORE1_CLKGATE_CTRL, 0x55555455); if (is_meson_tm2_stbmode()) { /* core1b */ dv_mem_power_off(VPU_DOLBY1B); - VSYNC_WR_DV_REG( - DOLBY_CORE1_1_CLKGATE_CTRL, - 0x55555455); + VSYNC_WR_DV_REG + (DOLBY_CORE1_1_CLKGATE_CTRL, + 0x55555455); /* coretv */ - VSYNC_WR_DV_REG_BITS( - DOLBY_TV_SWAP_CTRL7, - 0xf, 4, 4); - VSYNC_WR_DV_REG( - DOLBY_TV_CLKGATE_CTRL, - 0x55555455); + VSYNC_WR_DV_REG_BITS + (DOLBY_TV_SWAP_CTRL7, + 0xf, 4, 4); + VSYNC_WR_DV_REG + (DOLBY_TV_CLKGATE_CTRL, + 0x55555455); dv_mem_power_off(VPU_DOLBY0); /* hdr core */ hdr_vd1_off(); } } else if (is_meson_tm2_tvmode()) { /* disable coretv */ - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, - 3, 0, 2); + VSYNC_WR_DV_REG_BITS(DOLBY_PATH_CTRL, + 3, 0, 2); VSYNC_WR_DV_REG(DOLBY_TV_AXI2DMA_CTRL0, 0x01000042); - VSYNC_WR_DV_REG_BITS( - DOLBY_TV_SWAP_CTRL7, + VSYNC_WR_DV_REG_BITS + (DOLBY_TV_SWAP_CTRL7, 0xf, 4, 4); - VSYNC_WR_DV_REG( - DOLBY_TV_CLKGATE_CTRL, + VSYNC_WR_DV_REG + (DOLBY_TV_CLKGATE_CTRL, 0x55555455); dv_mem_power_off(VPU_DOLBY0); - } else - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - 1, - 16, 1); /* core1 */ + } else { + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + 1, + 16, 1); /* core1 */ + } dolby_vision_core1_on = false; dolby_vision_core1_on_cnt = 0; frame_count = 0; + last_vf_valid_crc = 0; pr_dolby_dbg("Dolby Vision core1 turn off\n"); } } @@ -4109,70 +4437,70 @@ void enable_dolby_vision(int enable) vsync_count = 0; } else { if (dolby_vision_on) { - if (is_meson_tvmode() && !force_stb_mode) { - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, - /* vd2 connect to vpp */ - (1 << 1) | - /* 16 core1 bl bypass */ - (1 << 0), - 16, 2); + if (is_meson_tvmode()) { + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, + /* vd2 connect to vpp */ + (1 << 1) | + /* 16 core1 bl bypass */ + (1 << 0), + 16, 2); if (is_meson_tm2_tvmode()) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, 3, 0, 2); + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, 3, 0, 2); VSYNC_WR_DV_REG(DOLBY_TV_AXI2DMA_CTRL0, 0x01000042); - VSYNC_WR_DV_REG_BITS( - DOLBY_TV_SWAP_CTRL7, + VSYNC_WR_DV_REG_BITS + (DOLBY_TV_SWAP_CTRL7, 0xf, 4, 4); - VSYNC_WR_DV_REG( - DOLBY_TV_CLKGATE_CTRL, + VSYNC_WR_DV_REG + (DOLBY_TV_CLKGATE_CTRL, 0x55555555); dv_mem_power_off(VPU_DOLBY0); } -#ifdef V1_5 if (p_funcs_tv) /* destroy ctx */ - p_funcs_tv->tv_control_path( - FORMAT_INVALID, 0, + p_funcs_tv->tv_control_path + (FORMAT_INVALID, 0, NULL, 0, NULL, 0, 0, 0, - SIG_RANGE_SMPTE, + SIGNAL_RANGE_SMPTE, NULL, NULL, 0, NULL, + NULL, + NULL, 0, + NULL, NULL); -#endif pr_dolby_dbg("Dolby Vision TV core turn off\n"); if (tv_dovi_setting) tv_dovi_setting->src_format = FORMAT_SDR; - } else if (is_meson_txlx_stbmode() - || force_stb_mode) { - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, + } else if (is_meson_txlx_stbmode()) { + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, (1 << 2) | /* core2 bypass */ (1 << 1) | /* vd2 connect to vpp */ (1 << 0), /* core1 bl bypass */ 16, 3); - VSYNC_WR_DV_REG_BITS(VPP_DOLBY_CTRL, - 0, 3, 1); /* core3 disable */ + VSYNC_WR_DV_REG_BITS + (VPP_DOLBY_CTRL, + 0, 3, 1);/* core3 disable */ osd_bypass(0); -#ifdef V2_4 if (p_funcs_stb) /* destroy ctx */ - p_funcs_stb->control_path( - FORMAT_INVALID, 0, - comp_buf[current_id], 0, - md_buf[current_id], 0, - 0, 0, 0, SIG_RANGE_SMPTE, - 0, 0, 0, 0, - 0, - &hdr10_param, - &new_dovi_setting); + p_funcs_stb->control_path + (FORMAT_INVALID, 0, + comp_buf[current_id], 0, + md_buf[current_id], 0, + 0, 0, 0, SIGNAL_RANGE_SMPTE, + 0, 0, 0, 0, + 0, + &hdr10_param, + &new_dovi_setting); last_dolby_vision_ll_policy = DOLBY_VISION_LL_DISABLE; -#endif - stb_core_setting_update_flag = FLAG_CHANGE_ALL; + stb_core_setting_update_flag = + CP_FLAG_CHANGE_ALL; stb_core2_const_flag = false; memset(&dovi_setting, 0, sizeof(dovi_setting)); dovi_setting.src_format = FORMAT_SDR; @@ -4180,8 +4508,8 @@ void enable_dolby_vision(int enable) } else if (is_meson_g12() || is_meson_tm2_stbmode() || is_meson_sc2()) { - VSYNC_WR_DV_REG_BITS( - DOLBY_PATH_CTRL, + VSYNC_WR_DV_REG_BITS + (DOLBY_PATH_CTRL, (1 << 2) | /* core2 bypass */ (1 << 1) | /* vd2 connect to vpp */ (1 << 0), /* core1 bl bypass */ @@ -4189,86 +4517,84 @@ void enable_dolby_vision(int enable) VSYNC_WR_DV_REG_BITS(VPP_DOLBY_CTRL, 0, 3, 1); /* core3 disable */ /* core1a */ - VSYNC_WR_DV_REG( - DOLBY_CORE1_CLKGATE_CTRL, + VSYNC_WR_DV_REG + (DOLBY_CORE1_CLKGATE_CTRL, 0x55555455); dv_mem_power_off(VPU_DOLBY1A); dv_mem_power_off(VPU_PRIME_DOLBY_RAM); /* core2 */ - VSYNC_WR_DV_REG( - DOLBY_CORE2A_CLKGATE_CTRL, + VSYNC_WR_DV_REG + (DOLBY_CORE2A_CLKGATE_CTRL, 0x55555555); dv_mem_power_off(VPU_DOLBY2); /* core3 */ - VSYNC_WR_DV_REG( - DOLBY_CORE3_CLKGATE_CTRL, + VSYNC_WR_DV_REG + (DOLBY_CORE3_CLKGATE_CTRL, 0x55555555); dv_mem_power_off(VPU_DOLBY_CORE3); if (is_meson_tm2_stbmode()) { /* core1b */ - VSYNC_WR_DV_REG( - DOLBY_CORE1_1_CLKGATE_CTRL, - 0x55555555); + VSYNC_WR_DV_REG + (DOLBY_CORE1_1_CLKGATE_CTRL, + 0x55555555); dv_mem_power_off(VPU_DOLBY1B); /* tv core */ VSYNC_WR_DV_REG(DOLBY_TV_AXI2DMA_CTRL0, 0x01000042); - VSYNC_WR_DV_REG_BITS( - DOLBY_TV_SWAP_CTRL7, + VSYNC_WR_DV_REG_BITS + (DOLBY_TV_SWAP_CTRL7, 0xf, 4, 4); - VSYNC_WR_DV_REG( - DOLBY_TV_CLKGATE_CTRL, + VSYNC_WR_DV_REG + (DOLBY_TV_CLKGATE_CTRL, 0x55555555); /* hdr core */ hdr_vd1_off(); dv_mem_power_off(VPU_DOLBY0); } -#ifdef V2_4 if (p_funcs_stb) /* destroy ctx */ - p_funcs_stb->control_path( - FORMAT_INVALID, 0, - comp_buf[current_id], 0, - md_buf[current_id], 0, - 0, 0, 0, SIG_RANGE_SMPTE, - 0, 0, 0, 0, - 0, - &hdr10_param, - &new_dovi_setting); + p_funcs_stb->control_path + (FORMAT_INVALID, 0, + comp_buf[current_id], 0, + md_buf[current_id], 0, + 0, 0, 0, SIGNAL_RANGE_SMPTE, + 0, 0, 0, 0, + 0, + &hdr10_param, + &new_dovi_setting); last_dolby_vision_ll_policy = DOLBY_VISION_LL_DISABLE; -#endif - stb_core_setting_update_flag = FLAG_CHANGE_ALL; + stb_core_setting_update_flag = + CP_FLAG_CHANGE_ALL; stb_core2_const_flag = false; memset(&dovi_setting, 0, sizeof(dovi_setting)); dovi_setting.src_format = FORMAT_SDR; pr_dolby_dbg("Dolby Vision G12a turn off\n"); } else { - VSYNC_WR_DV_REG_BITS( - VIU_MISC_CTRL1, + VSYNC_WR_DV_REG_BITS + (VIU_MISC_CTRL1, (1 << 2) | /* core2 bypass */ (1 << 1) | /* vd2 connect to vpp */ (1 << 0), /* core1 bl bypass */ 16, 3); VSYNC_WR_DV_REG_BITS(VPP_DOLBY_CTRL, - 0, 16, 1); /* core3 disable */ + 0, 16, 1);/*core3 disable*/ /* enable osd effect and*/ /* use default shadow mode */ osd_path_enable(1); -#ifdef V2_4 if (p_funcs_stb) /* destroy ctx */ - p_funcs_stb->control_path( - FORMAT_INVALID, 0, - comp_buf[current_id], 0, - md_buf[current_id], 0, - 0, 0, 0, SIG_RANGE_SMPTE, - 0, 0, 0, 0, - 0, - &hdr10_param, - &new_dovi_setting); + p_funcs_stb->control_path + (FORMAT_INVALID, 0, + comp_buf[current_id], 0, + md_buf[current_id], 0, + 0, 0, 0, SIGNAL_RANGE_SMPTE, + 0, 0, 0, 0, + 0, + &hdr10_param, + &new_dovi_setting); last_dolby_vision_ll_policy = DOLBY_VISION_LL_DISABLE; -#endif - stb_core_setting_update_flag = FLAG_CHANGE_ALL; + stb_core_setting_update_flag = + CP_FLAG_CHANGE_ALL; stb_core2_const_flag = false; memset(&dovi_setting, 0, sizeof(dovi_setting)); dovi_setting.src_format = FORMAT_SDR; @@ -4278,39 +4604,32 @@ void enable_dolby_vision(int enable) VSYNC_WR_DV_REG(VIU_SW_RESET, 0); if (is_meson_txlx()) { VSYNC_WR_DV_REG(VPP_DAT_CONV_PARA0, - vpp_data_conv_para0_backup); + vpp_data_conv_para0_backup); VSYNC_WR_DV_REG(VPP_DAT_CONV_PARA1, - vpp_data_conv_para1_backup); - VSYNC_WR_DV_REG( - DOLBY_TV_CLKGATE_CTRL, - 0x2414); - VSYNC_WR_DV_REG( - DOLBY_CORE2A_CLKGATE_CTRL, - 0x4); - VSYNC_WR_DV_REG( - DOLBY_CORE3_CLKGATE_CTRL, - 0x414); + vpp_data_conv_para1_backup); + VSYNC_WR_DV_REG(DOLBY_TV_CLKGATE_CTRL, + 0x2414); + VSYNC_WR_DV_REG(DOLBY_CORE2A_CLKGATE_CTRL, + 0x4); + VSYNC_WR_DV_REG(DOLBY_CORE3_CLKGATE_CTRL, + 0x414); VSYNC_WR_DV_REG(DOLBY_TV_AXI2DMA_CTRL0, - 0x01000042); + 0x01000042); } if (is_meson_gxm()) { - VSYNC_WR_DV_REG( - DOLBY_CORE1_CLKGATE_CTRL, - 0x55555555); - VSYNC_WR_DV_REG( - DOLBY_CORE2A_CLKGATE_CTRL, - 0x55555555); - VSYNC_WR_DV_REG( - DOLBY_CORE3_CLKGATE_CTRL, - 0x55555555); + VSYNC_WR_DV_REG + (DOLBY_CORE1_CLKGATE_CTRL, + 0x55555555); + VSYNC_WR_DV_REG + (DOLBY_CORE2A_CLKGATE_CTRL, + 0x55555555); + VSYNC_WR_DV_REG + (DOLBY_CORE3_CLKGATE_CTRL, + 0x55555555); } - VSYNC_WR_DV_REG( - VPP_VD1_CLIP_MISC0, - (0x3ff << 20) - | (0x3ff << 10) | 0x3ff); - VSYNC_WR_DV_REG( - VPP_VD1_CLIP_MISC1, - 0); + VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC0, + (0x3ff << 20) | (0x3ff << 10) | 0x3ff); + VSYNC_WR_DV_REG(VPP_VD1_CLIP_MISC1, 0); video_effect_bypass(0); if (is_meson_gxm()) VSYNC_WR_DV_REG(VPP_DOLBY_CTRL, @@ -4330,14 +4649,14 @@ void enable_dolby_vision(int enable) } } VSYNC_WR_DV_REG(VIU_MISC_CTRL1, - viu_misc_ctrl_backup - | (3 << 16)); + viu_misc_ctrl_backup | (3 << 16)); VSYNC_WR_DV_REG(VPP_MATRIX_CTRL, - vpp_matrix_backup); + vpp_matrix_backup); VSYNC_WR_DV_REG(VPP_DUMMY_DATA1, - vpp_dummy1_backup); + vpp_dummy1_backup); } frame_count = 0; + last_vf_valid_crc = 0; core1_disp_hsize = 0; core1_disp_vsize = 0; dolby_vision_on = false; @@ -4360,6 +4679,15 @@ void enable_dolby_vision(int enable) hdr_osd_off(); hdr_vd1_off(); } + /*dv release control of pwm*/ + if (is_meson_tvmode()) { + gd_en = 0; +#ifdef COMPILE_ERR + aml_lcd_atomic_notifier_call_chain + (LCD_EVENT_BACKLIGHT_DV_SEL, &gd_en); + dv_control_backlight_status = false; +#endif + } } } EXPORT_SYMBOL(enable_dolby_vision); @@ -4465,7 +4793,7 @@ void dolby_vision_init_receiver(void *pdev) pr_info("%s(%s)\n", __func__, DVEL_RECV_NAME); vf_receiver_init(&dvel_vf_recv, DVEL_RECV_NAME, - &dvel_vf_receiver, &dvel_vf_recv); + &dvel_vf_receiver, &dvel_vf_recv); vf_reg_receiver(&dvel_vf_recv); pr_info("%s: %s\n", __func__, dvel_vf_recv.name); dovi_pdev = (struct platform_device *)pdev; @@ -4475,18 +4803,24 @@ void dolby_vision_init_receiver(void *pdev) alloc_size, &dma_paddr, GFP_KERNEL); for (i = 0; i < 2; i++) { md_buf[i] = vmalloc(MD_BUF_SIZE); - if (md_buf[i] != NULL) + if (md_buf[i]) memset(md_buf[i], 0, MD_BUF_SIZE); comp_buf[i] = vmalloc(COMP_BUF_SIZE); - if (comp_buf[i] != NULL) + if (comp_buf[i]) memset(comp_buf[i], 0, COMP_BUF_SIZE); drop_md_buf[i] = vmalloc(MD_BUF_SIZE); - if (drop_md_buf[i] != NULL) + if (drop_md_buf[i]) memset(drop_md_buf[i], 0, MD_BUF_SIZE); drop_comp_buf[i] = vmalloc(COMP_BUF_SIZE); - if (drop_comp_buf[i] != NULL) + if (drop_comp_buf[i]) memset(drop_comp_buf[i], 0, COMP_BUF_SIZE); } + vsem_if_buf = vmalloc(VSEM_IF_BUF_SIZE); + if (vsem_if_buf) + memset(vsem_if_buf, 0, VSEM_IF_BUF_SIZE); + vsem_md_buf = vmalloc(VSEM_IF_BUF_SIZE); + if (vsem_md_buf) + memset(vsem_md_buf, 0, VSEM_IF_BUF_SIZE); } void dolby_vision_clear_buf(void) @@ -4511,8 +4845,10 @@ static const char dm_reg_core3_file[] = "%s_dm_core3.%04d.reg"; static const char dm_lut_core1_file[] = "%s_dm_core1.%04d.lut"; static const char dm_lut_core2_file[] = "%s_dm_core2.%04d.lut"; -static void dump_struct(void *structure, int struct_length, - const char file_string[], int frame_nr) +static void dump_struct(void *structure, + int struct_length, + const char file_string[], + int frame_nr) { char fn[MAX_FILENAME_LENGTH]; struct file *fp; @@ -4523,11 +4859,11 @@ static void dump_struct(void *structure, int struct_length, return; set_fs(KERNEL_DS); snprintf(fn, MAX_FILENAME_LENGTH, file_string, - "/data/tmp/tmp", frame_nr-1); - fp = filp_open(fn, O_RDWR|O_CREAT, 0666); - if (fp == NULL) + "/data/tmp/tmp", frame_nr - 1); + fp = filp_open(fn, O_RDWR | O_CREAT, 0666); + if (!fp) { pr_info("Error open file for writing NULL\n"); - else { + } else { vfs_write(fp, structure, struct_length, &pos); vfs_fsync(fp, 0); filp_close(fp, NULL); @@ -4538,47 +4874,47 @@ static void dump_struct(void *structure, int struct_length, void dolby_vision_dump_struct(void) { dump_struct(&dovi_setting.dm_reg1, - sizeof(dovi_setting.dm_reg1), - dm_reg_core1_file, frame_count); + sizeof(dovi_setting.dm_reg1), + dm_reg_core1_file, frame_count); if (dovi_setting.el_flag) dump_struct(&dovi_setting.comp_reg, - sizeof(dovi_setting.comp_reg), - comp_file, frame_count); + sizeof(dovi_setting.comp_reg), + comp_file, frame_count); if (!is_graphics_output_off()) dump_struct(&dovi_setting.dm_reg2, - sizeof(dovi_setting.dm_reg2), - dm_reg_core2_file, frame_count); + sizeof(dovi_setting.dm_reg2), + dm_reg_core2_file, frame_count); dump_struct(&dovi_setting.dm_reg3, - sizeof(dovi_setting.dm_reg3), - dm_reg_core3_file, frame_count); + sizeof(dovi_setting.dm_reg3), + dm_reg_core3_file, frame_count); dump_struct(&dovi_setting.dm_lut1, - sizeof(dovi_setting.dm_lut1), - dm_lut_core1_file, frame_count); + sizeof(dovi_setting.dm_lut1), + dm_lut_core1_file, frame_count); if (!is_graphics_output_off()) dump_struct(&dovi_setting.dm_lut2, - sizeof(dovi_setting.dm_lut2), - dm_lut_core2_file, frame_count); + sizeof(dovi_setting.dm_lut2), + dm_lut_core2_file, frame_count); pr_dolby_dbg("setting for frame %d dumped\n", frame_count); } EXPORT_SYMBOL(dolby_vision_dump_struct); -static void dump_setting( - struct dovi_setting_s *setting, - int frame_cnt, int debug_flag) +static void dump_setting + (struct dovi_setting_s *setting, + int frame_cnt, int debug_flag) { int i; - uint32_t *p; + u32 *p; if ((debug_flag & 0x10) && dump_enable) { pr_info("core1\n"); - p = (uint32_t *)&setting->dm_reg1; + p = (u32 *)&setting->dm_reg1; for (i = 0; i < 27; i++) pr_info("%08x\n", p[i]); pr_info("\ncomposer\n"); - p = (uint32_t *)&setting->comp_reg; + p = (u32 *)&setting->comp_reg; for (i = 0; i < 173; i++) pr_info("%08x\n", p[i]); if (is_meson_gxm()) { @@ -4616,36 +4952,41 @@ static void dump_setting( if ((debug_flag & 0x20) && dump_enable) { pr_info("\ncore1lut\n"); - p = (uint32_t *)&setting->dm_lut1.TmLutI; + p = (u32 *)&setting->dm_lut1.tm_lut_i; for (i = 0; i < 64; i++) - pr_info("%08x, %08x, %08x, %08x\n", - p[i*4+3], p[i*4+2], p[i*4+1], p[i*4]); + pr_info + ("%08x, %08x, %08x, %08x\n", + p[i * 4 + 3], p[i * 4 + 2], p[i * 4 + 1], p[i * 4]); pr_info("\n"); - p = (uint32_t *)&setting->dm_lut1.TmLutS; + p = (u32 *)&setting->dm_lut1.tm_lut_s; for (i = 0; i < 64; i++) - pr_info("%08x, %08x, %08x, %08x\n", - p[i*4+3], p[i*4+2], p[i*4+1], p[i*4]); + pr_info + ("%08x, %08x, %08x, %08x\n", + p[i * 4 + 3], p[i * 4 + 2], p[i * 4 + 1], p[i * 4]); pr_info("\n"); - p = (uint32_t *)&setting->dm_lut1.SmLutI; + p = (u32 *)&setting->dm_lut1.sm_lut_i; for (i = 0; i < 64; i++) - pr_info("%08x, %08x, %08x, %08x\n", - p[i*4+3], p[i*4+2], p[i*4+1], p[i*4]); + pr_info + ("%08x, %08x, %08x, %08x\n", + p[i * 4 + 3], p[i * 4 + 2], p[i * 4 + 1], p[i * 4]); pr_info("\n"); - p = (uint32_t *)&setting->dm_lut1.SmLutS; + p = (u32 *)&setting->dm_lut1.sm_lut_s; for (i = 0; i < 64; i++) - pr_info("%08x, %08x, %08x, %08x\n", - p[i*4+3], p[i*4+2], p[i*4+1], p[i*4]); + pr_info + ("%08x, %08x, %08x, %08x\n", + p[i * 4 + 3], p[i * 4 + 2], p[i * 4 + 1], p[i * 4]); pr_info("\n"); - p = (uint32_t *)&setting->dm_lut1.G2L; + p = (u32 *)&setting->dm_lut1.g_2_l; for (i = 0; i < 64; i++) - pr_info("%08x, %08x, %08x, %08x\n", - p[i*4+3], p[i*4+2], p[i*4+1], p[i*4]); + pr_info + ("%08x, %08x, %08x, %08x\n", + p[i * 4 + 3], p[i * 4 + 2], p[i * 4 + 1], p[i * 4]); pr_info("\n"); } if ((debug_flag & 0x10) && dump_enable && !is_graphics_output_off()) { pr_info("core2\n"); - p = (uint32_t *)&setting->dm_reg2; + p = (u32 *)&setting->dm_reg2; for (i = 0; i < 24; i++) pr_info("%08x\n", p[i]); pr_info("core2 swap\n"); @@ -4662,36 +5003,41 @@ static void dump_setting( if ((debug_flag & 0x20) && dump_enable && !is_graphics_output_off()) { pr_info("\ncore2lut\n"); - p = (uint32_t *)&setting->dm_lut2.TmLutI; + p = (u32 *)&setting->dm_lut2.tm_lut_i; for (i = 0; i < 64; i++) - pr_info("%08x, %08x, %08x, %08x\n", - p[i*4+3], p[i*4+2], p[i*4+1], p[i*4]); + pr_info + ("%08x, %08x, %08x, %08x\n", + p[i * 4 + 3], p[i * 4 + 2], p[i * 4 + 1], p[i * 4]); pr_info("\n"); - p = (uint32_t *)&setting->dm_lut2.TmLutS; + p = (u32 *)&setting->dm_lut2.tm_lut_s; for (i = 0; i < 64; i++) - pr_info("%08x, %08x, %08x, %08x\n", - p[i*4+3], p[i*4+2], p[i*4+1], p[i*4]); + pr_info + ("%08x, %08x, %08x, %08x\n", + p[i * 4 + 3], p[i * 4 + 2], p[i * 4 + 1], p[i * 4]); pr_info("\n"); - p = (uint32_t *)&setting->dm_lut2.SmLutI; + p = (u32 *)&setting->dm_lut2.sm_lut_i; for (i = 0; i < 64; i++) - pr_info("%08x, %08x, %08x, %08x\n", - p[i*4+3], p[i*4+2], p[i*4+1], p[i*4]); + pr_info + ("%08x, %08x, %08x, %08x\n", + p[i * 4 + 3], p[i * 4 + 2], p[i * 4 + 1], p[i * 4]); pr_info("\n"); - p = (uint32_t *)&setting->dm_lut2.SmLutS; + p = (u32 *)&setting->dm_lut2.sm_lut_s; for (i = 0; i < 64; i++) - pr_info("%08x, %08x, %08x, %08x\n", - p[i*4+3], p[i*4+2], p[i*4+1], p[i*4]); + pr_info + ("%08x, %08x, %08x, %08x\n", + p[i * 4 + 3], p[i * 4 + 2], p[i * 4 + 1], p[i * 4]); pr_info("\n"); - p = (uint32_t *)&setting->dm_lut2.G2L; + p = (u32 *)&setting->dm_lut2.g_2_l; for (i = 0; i < 64; i++) - pr_info("%08x, %08x, %08x, %08x\n", - p[i*4+3], p[i*4+2], p[i*4+1], p[i*4]); + pr_info + ("%08x, %08x, %08x, %08x\n", + p[i * 4 + 3], p[i * 4 + 2], p[i * 4 + 1], p[i * 4]); pr_info("\n"); } if ((debug_flag & 0x10) && dump_enable) { pr_info("core3\n"); - p = (uint32_t *)&setting->dm_reg3; + p = (u32 *)&setting->dm_reg3; for (i = 0; i < 26; i++) pr_info("%08x\n", p[i]); pr_info("core3 swap\n"); @@ -4706,8 +5052,8 @@ static void dump_setting( i, READ_VPP_DV_REG(i)); } - if ((debug_flag & 0x40) && dump_enable - && (dolby_vision_mode <= DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL)) { + if ((debug_flag & 0x40) && dump_enable && + dolby_vision_mode <= DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL) { pr_info("\ncore3_meta %d\n", setting->md_reg3.size); p = setting->md_reg3.raw_metadata; for (i = 0; i < setting->md_reg3.size; i++) @@ -4719,7 +5065,7 @@ static void dump_setting( void dolby_vision_dump_setting(int debug_flag) { pr_dolby_dbg("\n====== setting for frame %d ======\n", frame_count); - if (is_meson_tvmode() && !force_stb_mode) + if (is_meson_tvmode()) dump_tv_setting(tv_dovi_setting, frame_count, debug_flag); else @@ -4796,10 +5142,41 @@ static const char *input_str[8] = { "MVC" }; -static void update_src_format( - enum signal_format_e src_format, struct vframe_s *vf) +/*update pwm control when src changed or pic mode changed*/ +/*control pwm only in case : src=dovi and gdEnable=1*/ +static void update_pwm_control(void) +{ + int gd_en = 0; + + if (is_meson_tvmode()) { + if (pq_config_fake && + ((struct pq_config *) + pq_config_fake)->tdc.gd_config.gd_enable && + dolby_vision_src_format == 3) + gd_en = 1; + else + gd_en = 0; + + pr_dolby_dbg("%s: %s, src %d, gd_en %d, bl %d\n", + __func__, cfg_info[cur_pic_mode].pic_mode_name, + dolby_vision_src_format, gd_en, tv_backlight); + +#ifdef COMPILE_ERR + if (!force_disable_dv_backlight) { + aml_lcd_atomic_notifier_call_chain + (LCD_EVENT_BACKLIGHT_DV_SEL, &gd_en); + dv_control_backlight_status = gd_en > 0 ? true : false; + if (gd_en) + tv_backlight_force_update = true; + } +#endif + } +} + +static void update_src_format + (enum signal_format_enum src_format, struct vframe_s *vf) { - enum signal_format_e cur_format = dolby_vision_src_format; + enum signal_format_enum cur_format = dolby_vision_src_format; if (src_format == FORMAT_DOVI || src_format == FORMAT_DOVI_LL) { @@ -4819,12 +5196,13 @@ static void update_src_format( } } if (cur_format != dolby_vision_src_format) { - pr_dolby_dbg( - "dolby_vision_src_format changed: %s => %s, signal_type = 0x%x, src_format = %d\n", - input_str[cur_format], - input_str[dolby_vision_src_format], - vf->signal_type, - src_format); + update_pwm_control(); + pr_dolby_dbg + ("update src fmt: %s => %s, signal_type 0x%x, src fmt %d\n", + input_str[cur_format], + input_str[dolby_vision_src_format], + vf ? vf->signal_type : 0, + src_format); cur_format = dolby_vision_src_format; } } @@ -4835,10 +5213,10 @@ int get_dolby_vision_src_format(void) } EXPORT_SYMBOL(get_dolby_vision_src_format); -static enum signal_format_e get_cur_src_format(void) +static enum signal_format_enum get_cur_src_format(void) { int cur_format = dolby_vision_src_format; - enum signal_format_e ret = FORMAT_SDR; + enum signal_format_enum ret = FORMAT_SDR; switch (cur_format) { case 1: /* HDR10 */ @@ -4865,56 +5243,56 @@ static enum signal_format_e get_cur_src_format(void) return ret; } -static int dolby_vision_policy_process( - int *mode, enum signal_format_e src_format) +static int dolby_vision_policy_process + (int *mode, enum signal_format_enum src_format) { const struct vinfo_s *vinfo; int mode_change = 0; - if ((!dolby_vision_enable) || ((!p_funcs_stb) && (!p_funcs_tv))) + if (!dolby_vision_enable || (!p_funcs_stb && !p_funcs_tv)) return mode_change; - if (is_meson_tvmode() && !force_stb_mode) { + if (is_meson_tvmode()) { if (dolby_vision_policy == DOLBY_VISION_FORCE_OUTPUT_MODE) { if (*mode == DOLBY_VISION_OUTPUT_MODE_BYPASS) { if (dolby_vision_mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) { pr_dolby_dbg("dovi tv output mode change %d -> %d\n", - dolby_vision_mode, *mode); + dolby_vision_mode, *mode); mode_change = 1; } } else if (*mode == DOLBY_VISION_OUTPUT_MODE_SDR8) { if (dolby_vision_mode != DOLBY_VISION_OUTPUT_MODE_SDR8) { - pr_dolby_dbg("dovi tv output mode change %d -> %d\n", - dolby_vision_mode, *mode); + pr_dolby_dbg + ("dovi tv output mode change %d->%d\n", + dolby_vision_mode, *mode); mode_change = 1; } } else { - pr_dolby_error( - "not support dovi output mode %d\n", - *mode); + pr_dolby_error + ("not support dovi output mode %d\n", + *mode); return mode_change; } } else if (dolby_vision_policy == DOLBY_VISION_FOLLOW_SINK) { /* bypass dv_mode with efuse */ - if ((efuse_mode == 1) && !dolby_vision_efuse_bypass) { + if (efuse_mode == 1 && !dolby_vision_efuse_bypass) { if (dolby_vision_mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) { *mode = DOLBY_VISION_OUTPUT_MODE_BYPASS; mode_change = 1; - } else + } else { mode_change = 0; + } return mode_change; } - if ((cur_csc_type[VD1_PATH] != 0xffff) && - (get_hdr_module_status(VD1_PATH) - == HDR_MODULE_ON)) { + if (cur_csc_type[VD1_PATH] != 0xffff && + (get_hdr_module_status(VD1_PATH) == HDR_MODULE_ON)) { if (dolby_vision_mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) { - pr_dolby_dbg( - "src=%d, hdr module=ON, dovi tv output -> DOLBY_VISION_OUTPUT_MODE_BYPASS\n", + pr_dolby_dbg("src=%d, hdr module=ON, dovi tv output -> BYPASS\n", src_format); *mode = DOLBY_VISION_OUTPUT_MODE_BYPASS; mode_change = 1; @@ -4928,18 +5306,16 @@ static int dolby_vision_policy_process( (dolby_vision_hdr10_policy & HLG_BY_DV_F_SINK))) { if (dolby_vision_mode != - DOLBY_VISION_OUTPUT_MODE_SDR8) { - pr_dolby_dbg( - "src=%d, dovi tv output -> DOLBY_VISION_OUTPUT_MODE_SDR8\n", + DOLBY_VISION_OUTPUT_MODE_SDR8) { + pr_dolby_dbg("src=%d, dovi tv output -> SDR8\n", src_format); *mode = DOLBY_VISION_OUTPUT_MODE_SDR8; mode_change = 1; } } else { if (dolby_vision_mode != - DOLBY_VISION_OUTPUT_MODE_BYPASS) { - pr_dolby_dbg( - "src=%d, dovi tv output -> DOLBY_VISION_OUTPUT_MODE_BYPASS\n", + DOLBY_VISION_OUTPUT_MODE_BYPASS) { + pr_dolby_dbg("src=%d, dovi tv output -> BYPASS\n", src_format); *mode = DOLBY_VISION_OUTPUT_MODE_BYPASS; mode_change = 1; @@ -4947,22 +5323,21 @@ static int dolby_vision_policy_process( } } else if (dolby_vision_policy == DOLBY_VISION_FOLLOW_SOURCE) { /* bypass dv_mode with efuse */ - if ((efuse_mode == 1) && !dolby_vision_efuse_bypass) { + if (efuse_mode == 1 && !dolby_vision_efuse_bypass) { if (dolby_vision_mode != - DOLBY_VISION_OUTPUT_MODE_BYPASS) { + DOLBY_VISION_OUTPUT_MODE_BYPASS) { *mode = DOLBY_VISION_OUTPUT_MODE_BYPASS; mode_change = 1; - } else + } else { mode_change = 0; + } return mode_change; } if ((cur_csc_type[VD1_PATH] != 0xffff) && - (get_hdr_module_status(VD1_PATH) - == HDR_MODULE_ON)) { + (get_hdr_module_status(VD1_PATH) == HDR_MODULE_ON)) { if (dolby_vision_mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) { - pr_dolby_dbg( - "src=%d, hdr module=ON, dovi tv output -> DOLBY_VISION_OUTPUT_MODE_BYPASS\n", + pr_dolby_dbg("src=%d, hdr module=ON, dovi tv output -> BYPASS\n", src_format); *mode = DOLBY_VISION_OUTPUT_MODE_BYPASS; mode_change = 1; @@ -4977,8 +5352,7 @@ static int dolby_vision_policy_process( HLG_BY_DV_F_SRC))) { if (dolby_vision_mode != DOLBY_VISION_OUTPUT_MODE_SDR8) { - pr_dolby_dbg( - "src=%d, dovi tv output -> DOLBY_VISION_OUTPUT_MODE_SDR8\n", + pr_dolby_dbg("src=%d, dovi tv output -> SDR8\n", src_format); *mode = DOLBY_VISION_OUTPUT_MODE_SDR8; mode_change = 1; @@ -4986,8 +5360,7 @@ static int dolby_vision_policy_process( } else { if (dolby_vision_mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) { - pr_dolby_dbg( - "src=%d, dovi tv output -> DOLBY_VISION_OUTPUT_MODE_BYPASS\n", + pr_dolby_dbg("src=%d, dovi tv output -> BYPASS\n", src_format); *mode = DOLBY_VISION_OUTPUT_MODE_BYPASS; mode_change = 1; @@ -4995,7 +5368,7 @@ static int dolby_vision_policy_process( } } if (src_format == FORMAT_SDR && - (mode_change || (*mode == dolby_vision_mode))) { + (mode_change || *mode == dolby_vision_mode)) { if (*mode == DOLBY_VISION_OUTPUT_MODE_BYPASS) dolby_vision_hdr10_policy &= ~SDR_BY_DV; else @@ -5009,8 +5382,8 @@ static int dolby_vision_policy_process( if (dolby_vision_mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) { if (debug_dolby & 2) - pr_dolby_dbg( - "mvc, dovi output -> DOLBY_VISION_OUTPUT_MODE_BYPASS\n"); + pr_dolby_dbg + ("mvc, dovi output -> BYPASS\n"); *mode = DOLBY_VISION_OUTPUT_MODE_BYPASS; mode_change = 1; } else { @@ -5020,46 +5393,60 @@ static int dolby_vision_policy_process( } if (dolby_vision_policy == DOLBY_VISION_FOLLOW_SINK) { /* bypass dv_mode with efuse */ - if ((efuse_mode == 1) && !dolby_vision_efuse_bypass) { + if (efuse_mode == 1 && !dolby_vision_efuse_bypass) { if (dolby_vision_mode != - DOLBY_VISION_OUTPUT_MODE_BYPASS) { + DOLBY_VISION_OUTPUT_MODE_BYPASS) { *mode = DOLBY_VISION_OUTPUT_MODE_BYPASS; mode_change = 1; - } else + } else { mode_change = 0; + } return mode_change; } - if ((src_format == FORMAT_HLG) || - ((src_format == FORMAT_HDR10PLUS) && + if (src_format == FORMAT_HLG || + (src_format == FORMAT_HDR10PLUS && !(dolby_vision_hdr10_policy & HDRP_BY_DV))) { if (dolby_vision_mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) { if (debug_dolby & 2) - pr_dolby_dbg( - "hlg/hdr+, dovi output -> DOLBY_VISION_OUTPUT_MODE_BYPASS\n"); + pr_dolby_dbg("hlg/hdr+, dovi output -> BYPASS\n"); *mode = DOLBY_VISION_OUTPUT_MODE_BYPASS; mode_change = 1; } - } else if ((cur_csc_type[VD1_PATH] != 0xffff) && + } else if (cur_csc_type[VD1_PATH] != 0xffff && (get_hdr_module_status(VD1_PATH) == HDR_MODULE_ON)) { /*if vpp is playing hlg/hdr10+*/ /*dolby need bypass at this time*/ if (dolby_vision_mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) { if (debug_dolby & 2) - pr_dolby_dbg( - "src=%d, hdr module on, dovi output -> DOLBY_VISION_OUTPUT_MODE_BYPASS\n", - src_format); + pr_dolby_dbg + ("src=%d, hdr module on, dovi output->BYPASS\n", + src_format); *mode = DOLBY_VISION_OUTPUT_MODE_BYPASS; mode_change = 1; } return mode_change; + } else if (is_meson_tm2_stb_hdmimode() && + (src_format == FORMAT_DOVI) && + sink_support_dolby_vision(vinfo)) { + /* HDMI DV sink-led in and TV support dv */ + if (dolby_vision_ll_policy != + DOLBY_VISION_LL_DISABLE && + !dolby_vision_core1_on) + pr_dolby_error + ("hdmi in sink-led but output source-led\n"); + if (dolby_vision_mode != + DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL) { + pr_dolby_dbg("hdmi dovi, dovi output -> DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL\n"); + *mode = DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL; + mode_change = 1; + } } else if (vinfo && sink_support_dolby_vision(vinfo)) { /* TV support DOVI, All -> DOVI */ if (dolby_vision_mode != - DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL) { - pr_dolby_dbg( - "src=%d, dovi output -> DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL\n", + DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL) { + pr_dolby_dbg("src=%d, dovi output -> DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL\n", src_format); *mode = DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL; mode_change = 1; @@ -5068,16 +5455,15 @@ static int dolby_vision_policy_process( /* TV support HDR, All -> HDR */ if (dolby_vision_mode != DOLBY_VISION_OUTPUT_MODE_HDR10) { - pr_dolby_dbg( - "src=%d, dovi output -> DOLBY_VISION_OUTPUT_MODE_HDR10\n", + pr_dolby_dbg("src=%d, dovi output -> DOLBY_VISION_OUTPUT_MODE_HDR10\n", src_format); *mode = DOLBY_VISION_OUTPUT_MODE_HDR10; mode_change = 1; } } else { /* TV not support DOVI and HDR */ - if ((src_format == FORMAT_DOVI) || - (src_format == FORMAT_DOVI_LL)) { + if (src_format == FORMAT_DOVI || + src_format == FORMAT_DOVI_LL) { /* DOVI to SDR */ if (dolby_vision_mode != DOLBY_VISION_OUTPUT_MODE_SDR8) { @@ -5122,13 +5508,14 @@ static int dolby_vision_policy_process( } } else if (dolby_vision_policy == DOLBY_VISION_FOLLOW_SOURCE) { /* bypass dv_mode with efuse */ - if ((efuse_mode == 1) && !dolby_vision_efuse_bypass) { + if (efuse_mode == 1 && !dolby_vision_efuse_bypass) { if (dolby_vision_mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) { *mode = DOLBY_VISION_OUTPUT_MODE_BYPASS; mode_change = 1; - } else + } else { mode_change = 0; + } return mode_change; } if ((cur_csc_type[VD1_PATH] != 0xffff) && @@ -5143,6 +5530,40 @@ static int dolby_vision_policy_process( mode_change = 1; } return mode_change; + } else if (is_meson_tm2_stb_hdmimode() && + (src_format == FORMAT_DOVI)) { + /* HDMI DV sink-led in and TV support */ + if (sink_support_dolby_vision(vinfo)) { + /* support dv sink-led or source-led*/ + if (dolby_vision_ll_policy != + DOLBY_VISION_LL_DISABLE && + !dolby_vision_core1_on) + pr_dolby_error + ("hdmi in sink-led but output source-led\n"); + if (dolby_vision_mode != + DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL) { + pr_dolby_dbg("hdmi dovi, dovi output -> DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL\n"); + *mode = + DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL; + mode_change = 1; + } + } else if (vinfo && sink_support_hdr(vinfo)) { + /* TV support HDR, DOVI -> HDR */ + if (dolby_vision_mode != + DOLBY_VISION_OUTPUT_MODE_HDR10) { + pr_dolby_dbg("hdmi dovi, dovi output -> DOLBY_VISION_OUTPUT_MODE_HDR10\n"); + *mode = DOLBY_VISION_OUTPUT_MODE_HDR10; + mode_change = 1; + } + } else { + /* TV not support DOVI and HDR, DOVI -> SDR */ + if (dolby_vision_mode != + DOLBY_VISION_OUTPUT_MODE_SDR8) { + pr_dolby_dbg("hdmi dovi,, dovi output -> DOLBY_VISION_OUTPUT_MODE_SDR8\n"); + *mode = DOLBY_VISION_OUTPUT_MODE_SDR8; + mode_change = 1; + } + } } else if ((src_format == FORMAT_DOVI) || (src_format == FORMAT_DOVI_LL)) { /* DOVI source */ @@ -5207,7 +5628,7 @@ static int dolby_vision_policy_process( } if (src_format == FORMAT_SDR && - (mode_change || (*mode == dolby_vision_mode))) { + (mode_change || *mode == dolby_vision_mode)) { if (*mode == DOLBY_VISION_OUTPUT_MODE_BYPASS) dolby_vision_hdr10_policy &= ~SDR_BY_DV; else @@ -5229,7 +5650,8 @@ void dolby_vision_set_provider(char *prov_name) } EXPORT_SYMBOL(dolby_vision_set_provider); -bool is_dovi_frame(struct vframe_s *vf) +/* 0: no dv, 1: dv std, 2: dv ll */ +int is_dovi_frame(struct vframe_s *vf) { struct provider_aux_req_s req; char *p; @@ -5238,7 +5660,7 @@ bool is_dovi_frame(struct vframe_s *vf) enum vframe_signal_fmt_e fmt; if (!vf) - return false; + return 0; fmt = get_vframe_src_fmt(vf); if (fmt == VFRAME_SIGNAL_FMT_DOVI) @@ -5252,24 +5674,43 @@ bool is_dovi_frame(struct vframe_s *vf) req.aux_buf = NULL; req.aux_size = 0; req.dv_enhance_exist = 0; - - if ((vf->source_type == VFRAME_SOURCE_TYPE_HDMI) - && is_meson_tvmode() && !force_stb_mode) { - vf_notify_provider_by_name("dv_vdin", - VFRAME_EVENT_RECEIVER_GET_AUX_DATA, - (void *)&req); + req.low_latency = 0; + + if (vf->source_type == VFRAME_SOURCE_TYPE_HDMI && + (is_meson_tvmode() || + ((is_meson_tm2_stbmode()) && hdmi_to_stb_policy))) { + vf_notify_provider_by_name + ("dv_vdin", + VFRAME_EVENT_RECEIVER_GET_AUX_DATA, + (void *)&req); + if (debug_dolby & 2) + pr_dolby_dbg("is_dovi: vf %p, emp.size %d, aux_size %d\n", + vf, vf->emp.size, + req.aux_size); if ((req.aux_buf && req.aux_size) || (dolby_vision_flags & FLAG_FORCE_DOVI_LL)) return 1; - else - return 0; + if (req.low_latency) + return 2; + p = vf->emp.addr; + if (p && vf->emp.size > 0 && + p[0] == 0x7f && + p[10] == 0x46 && + p[11] == 0xd0) { + if (p[13] == 0) + return 1; + else + return 2; + } + return 0; } else if (vf->source_type == VFRAME_SOURCE_TYPE_OTHERS) { - vf_notify_provider_by_name( - dv_provider, - VFRAME_EVENT_RECEIVER_GET_AUX_DATA, - (void *)&req); + if (!strcmp(dv_provider, "dvbldec")) + vf_notify_provider_by_name + (dv_provider, + VFRAME_EVENT_RECEIVER_GET_AUX_DATA, + (void *)&req); if (req.dv_enhance_exist) - return true; + return 1; if (!req.aux_buf || !req.aux_size) return 0; p = req.aux_buf; @@ -5284,11 +5725,11 @@ bool is_dovi_frame(struct vframe_s *vf) type = (type << 8) | *p++; if (type == DV_SEI || (type & 0xffff0000) == DV_AV1_SEI) - return true; + return 1; p += size; } } - return false; + return 0; } EXPORT_SYMBOL(is_dovi_frame); @@ -5306,8 +5747,8 @@ bool is_dovi_dual_layer_frame(struct vframe_s *vf) fmt = get_vframe_src_fmt(vf); /* valid src_fmt = DOVI or invalid src_fmt will check dual layer */ /* otherwise, it certainly is a non-dv vframe */ - if ((fmt != VFRAME_SIGNAL_FMT_DOVI) && - (fmt != VFRAME_SIGNAL_FMT_INVALID)) + if (fmt != VFRAME_SIGNAL_FMT_DOVI && + fmt != VFRAME_SIGNAL_FMT_INVALID) return false; req.vf = vf; @@ -5317,9 +5758,10 @@ bool is_dovi_dual_layer_frame(struct vframe_s *vf) req.dv_enhance_exist = 0; if (vf->source_type == VFRAME_SOURCE_TYPE_OTHERS) { - vf_notify_provider_by_name("dvbldec", - VFRAME_EVENT_RECEIVER_GET_AUX_DATA, - (void *)&req); + if (!strcmp(dv_provider, "dvbldec")) + vf_notify_provider_by_name(dv_provider, + VFRAME_EVENT_RECEIVER_GET_AUX_DATA, + (void *)&req); if (req.dv_enhance_exist) return true; } @@ -5333,9 +5775,9 @@ EXPORT_SYMBOL(is_dovi_dual_layer_frame); static bool vf_is_hlg(struct vframe_s *vf) { - if (((signal_transfer_characteristic == 14) || - (signal_transfer_characteristic == 18)) && - (signal_color_primaries == 9)) + if ((signal_transfer_characteristic == 14 || + signal_transfer_characteristic == 18) && + signal_color_primaries == 9) return true; return false; } @@ -5344,19 +5786,28 @@ static bool is_hlg_frame(struct vframe_s *vf) { if (!vf) return false; - if (((get_dolby_vision_hdr_policy() & 2) == 0) && - ((signal_transfer_characteristic == 14) || - (signal_transfer_characteristic == 18)) && - (signal_color_primaries == 9)) + if ((is_meson_tm2_tvmode() || + (get_dolby_vision_hdr_policy() & 2) == 0) && + (signal_transfer_characteristic == 14 || + signal_transfer_characteristic == 18) && + signal_color_primaries == 9) return true; + return false; } static bool vf_is_hdr10_plus(struct vframe_s *vf) { - if ((signal_transfer_characteristic == 0x30) - && ((signal_color_primaries == 9) - || (signal_color_primaries == 2))) + if (signal_transfer_characteristic == 0x30 && + (signal_color_primaries == 9 || + signal_color_primaries == 2)) + return true; + return false; +} + +static bool is_cuva_frame(struct vframe_s *vf) +{ + if ((vf->signal_type >> 31) & 1) return true; return false; } @@ -5371,10 +5822,10 @@ static bool is_hdr10plus_frame(struct vframe_s *vf) /* report hdr10 for the content hdr10+ and * sink is hdr10+ case */ - if ((signal_transfer_characteristic == 0x30) - && (sink_support_hdr10_plus(vinfo)) - && ((signal_color_primaries == 9) - || (signal_color_primaries == 2))) + if (signal_transfer_characteristic == 0x30 && + (is_meson_tvmode() || sink_support_hdr10_plus(vinfo)) && + (signal_color_primaries == 9 || + signal_color_primaries == 2)) return true; } return false; @@ -5382,9 +5833,9 @@ static bool is_hdr10plus_frame(struct vframe_s *vf) static bool vf_is_hdr10(struct vframe_s *vf) { - if ((signal_transfer_characteristic == 16) - && ((signal_color_primaries == 9) - || (signal_color_primaries == 2))) + if (signal_transfer_characteristic == 16 && + (signal_color_primaries == 9 || + signal_color_primaries == 2)) return true; return false; } @@ -5395,16 +5846,16 @@ static bool is_hdr10_frame(struct vframe_s *vf) if (!vf) return false; - if (((signal_transfer_characteristic == 16) || + if ((signal_transfer_characteristic == 16 || /* report as hdr10 for the content hdr10+ and * sink not support hdr10+ or use DV to handle * hdr10+ as hdr10 */ - ((signal_transfer_characteristic == 0x30) && - ((!sink_support_hdr10_plus(vinfo)) || - (dolby_vision_hdr10_policy & HDRP_BY_DV)))) - && ((signal_color_primaries == 9) - || (signal_color_primaries == 2))) + (signal_transfer_characteristic == 0x30 && + ((!sink_support_hdr10_plus(vinfo) && !is_meson_tvmode()) || + (dolby_vision_hdr10_policy & HDRP_BY_DV)))) && + (signal_color_primaries == 9 || + signal_color_primaries == 2)) return true; return false; } @@ -5425,11 +5876,10 @@ int dolby_vision_check_mvc(struct vframe_s *vf) if (is_mvc_frame(vf) && dolby_vision_on) { /* mvc source, but dovi enabled, need bypass dv */ mode = dolby_vision_mode; - if (dolby_vision_policy_process( - &mode, FORMAT_MVC)) { - if ((mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) && - (dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_BYPASS)) + if (dolby_vision_policy_process(&mode, FORMAT_MVC)) { + if (mode != DOLBY_VISION_OUTPUT_MODE_BYPASS && + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_BYPASS) dolby_vision_wait_on = true; dolby_vision_target_mode = mode; return 1; @@ -5443,14 +5893,13 @@ int dolby_vision_check_hlg(struct vframe_s *vf) { int mode; - if (is_hlg_frame(vf) && !dolby_vision_on) { - /* dovi source, but dovi not enabled */ + if (!is_dovi_frame(vf) && is_hlg_frame(vf) && !dolby_vision_on) { + /* hlg source, but dovi not enabled */ mode = dolby_vision_mode; - if (dolby_vision_policy_process( - &mode, FORMAT_HLG)) { - if ((mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) - && (dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_BYPASS)) + if (dolby_vision_policy_process(&mode, FORMAT_HLG)) { + if (mode != DOLBY_VISION_OUTPUT_MODE_BYPASS && + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_BYPASS) dolby_vision_wait_on = true; dolby_vision_target_mode = mode; return 1; @@ -5464,14 +5913,13 @@ int dolby_vision_check_hdr10plus(struct vframe_s *vf) { int mode; - if (is_hdr10plus_frame(vf) && !dolby_vision_on) { - /* dovi source, but dovi not enabled */ + if (!is_dovi_frame(vf) && is_hdr10plus_frame(vf) && !dolby_vision_on) { + /* hdr10+ source, but dovi not enabled */ mode = dolby_vision_mode; - if (dolby_vision_policy_process( - &mode, FORMAT_HDR10PLUS)) { - if ((mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) - && (dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_BYPASS)) + if (dolby_vision_policy_process(&mode, FORMAT_HDR10PLUS)) { + if (mode != DOLBY_VISION_OUTPUT_MODE_BYPASS && + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_BYPASS) dolby_vision_wait_on = true; dolby_vision_target_mode = mode; return 1; @@ -5481,17 +5929,16 @@ int dolby_vision_check_hdr10plus(struct vframe_s *vf) } EXPORT_SYMBOL(dolby_vision_check_hdr10plus); -int dolby_vision_check_hdr10(struct vframe_s *vf) +int dolby_vision_check_cuva(struct vframe_s *vf) { int mode; - if (is_hdr10_frame(vf) && !dolby_vision_on) { + if (is_cuva_frame(vf) && !dolby_vision_on) { /* dovi source, but dovi not enabled */ mode = dolby_vision_mode; - if (dolby_vision_policy_process( - &mode, FORMAT_HDR10)) { - if ((mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) - && (dolby_vision_mode == + if (dolby_vision_policy_process(&mode, FORMAT_CUVA)) { + if ((mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) && + (dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_BYPASS)) dolby_vision_wait_on = true; dolby_vision_target_mode = mode; @@ -5500,6 +5947,26 @@ int dolby_vision_check_hdr10(struct vframe_s *vf) } return 0; } +EXPORT_SYMBOL(dolby_vision_check_cuva); + +int dolby_vision_check_hdr10(struct vframe_s *vf) +{ + int mode; + + if (!is_dovi_frame(vf) && is_hdr10_frame(vf) && !dolby_vision_on) { + /* hdr10 source, but dovi not enabled */ + mode = dolby_vision_mode; + if (dolby_vision_policy_process(&mode, FORMAT_HDR10)) { + if (mode != DOLBY_VISION_OUTPUT_MODE_BYPASS && + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_BYPASS) + dolby_vision_wait_on = true; + dolby_vision_target_mode = mode; + return 1; + } + } + return 0; +} EXPORT_SYMBOL(dolby_vision_check_hdr10); void dolby_vision_vf_put(struct vframe_s *vf) @@ -5511,10 +5978,11 @@ void dolby_vision_vf_put(struct vframe_s *vf) if (dv_vf[i][0] == vf) { if (dv_vf[i][1]) { if (debug_dolby & 2) - pr_dolby_dbg("--- put bl(%p-%lld) with el(%p-%lld) ---\n", - vf, vf->pts_us64, - dv_vf[i][1], - dv_vf[i][1]->pts_us64); + pr_dolby_dbg + ("put bl(%p-%lld) with el(%p-%lld)\n", + vf, vf->pts_us64, + dv_vf[i][1], + dv_vf[i][1]->pts_us64); dvel_vf_put(dv_vf[i][1]); } else if (debug_dolby & 2) { pr_dolby_dbg("--- put bl(%p-%lld) ---\n", @@ -5534,9 +6002,9 @@ struct vframe_s *dolby_vision_vf_peek_el(struct vframe_s *vf) if (dolby_vision_flags && (p_funcs_stb || p_funcs_tv)) { for (i = 0; i < 16; i++) { if (dv_vf[i][0] == vf) { - if (dv_vf[i][1] - && (dolby_vision_status == BYPASS_PROCESS) - && !is_dolby_vision_on()) + if (dv_vf[i][1] && + dolby_vision_status == BYPASS_PROCESS && + !is_dolby_vision_on()) dv_vf[i][1]->type |= VIDTYPE_VD2; return dv_vf[i][1]; } @@ -5551,7 +6019,7 @@ static void dolby_vision_vf_add(struct vframe_s *vf, struct vframe_s *el_vf) int i; for (i = 0; i < 16; i++) { - if (dv_vf[i][0] == NULL) { + if (!dv_vf[i][0]) { dv_vf[i][0] = vf; dv_vf[i][1] = el_vf; break; @@ -5568,14 +6036,14 @@ static int dolby_vision_vf_check(struct vframe_s *vf) if (debug_dolby & 2) { if (dv_vf[i][1]) pr_dolby_dbg("=== bl(%p-%lld) with el(%p-%lld) toggled ===\n", - vf, - vf->pts_us64, - dv_vf[i][1], - dv_vf[i][1]->pts_us64); + vf, + vf->pts_us64, + dv_vf[i][1], + dv_vf[i][1]->pts_us64); else pr_dolby_dbg("=== bl(%p-%lld) toggled ===\n", - vf, - vf->pts_us64); + vf, + vf->pts_us64); } return 0; } @@ -5584,16 +6052,15 @@ static int dolby_vision_vf_check(struct vframe_s *vf) } /*return 0: parse ok; 1,2,3: parse err */ -int parse_sei_and_meta_ext( - struct vframe_s *vf, - char *aux_buf, - int aux_size, - int *total_comp_size, - int *total_md_size, - void *fmt, - int *ret_flags, - char *md_buf, - char *comp_buf) +int parse_sei_and_meta_ext(struct vframe_s *vf, + char *aux_buf, + int aux_size, + int *total_comp_size, + int *total_md_size, + void *fmt, + int *ret_flags, + char *md_buf, + char *comp_buf) { int i; char *p; @@ -5606,8 +6073,9 @@ int parse_sei_and_meta_ext( unsigned long flags; bool parser_overflow = false; int rpu_ret = 0; + int reset_flag = 0; unsigned int rpu_size = 0; - enum signal_format_e *src_format = (enum signal_format_e *)fmt; + enum signal_format_enum *src_format = (enum signal_format_enum *)fmt; static int parse_process_count; int dump_size = 100; @@ -5638,8 +6106,8 @@ int parse_sei_and_meta_ext( ret = 1; goto parse_err; } - if ((type == DV_SEI) || /* hevc t35 sei */ - ((type & 0xffff0000) == DV_AV1_SEI)) { /* av1 t35 obu */ + if (type == DV_SEI || /* hevc t35 sei */ + (type & 0xffff0000) == DV_AV1_SEI) { /* av1 t35 obu */ *total_comp_size = 0; *total_md_size = 0; @@ -5666,8 +6134,8 @@ int parse_sei_and_meta_ext( rpu_size |= (p[11] & 0x0f) << 4; rpu_size |= (p[12] >> 4) & 0x0f; if (p[12] & 0x08) { - pr_dolby_error( - "rpu in obu exceed 512 bytes\n"); + pr_dolby_error + ("rpu exceed 512 bytes\n"); break; } for (i = 0; i < rpu_size; i++) { @@ -5734,78 +6202,76 @@ int parse_sei_and_meta_ext( /* prepare metadata parser */ spin_lock_irqsave(&dovi_lock, flags); parser_ready = 0; - if (metadata_parser == NULL) { + if (!metadata_parser) { if (is_meson_tvmode()) { metadata_parser = - p_funcs_tv->metadata_parser_init( - dolby_vision_flags - & FLAG_CHANGE_SEQ_HEAD - ? 1 : 0); + p_funcs_tv->metadata_parser_init + (dolby_vision_flags + & FLAG_CHANGE_SEQ_HEAD + ? 1 : 0); p_funcs_tv->metadata_parser_reset(1); } else { metadata_parser = - p_funcs_stb->metadata_parser_init( - dolby_vision_flags - & FLAG_CHANGE_SEQ_HEAD - ? 1 : 0); + p_funcs_stb->metadata_parser_init + (dolby_vision_flags + & FLAG_CHANGE_SEQ_HEAD + ? 1 : 0); p_funcs_stb->metadata_parser_reset(1); } - if (metadata_parser != NULL) { + if (metadata_parser) { parser_ready = 1; if (debug_dolby & 1) pr_dolby_dbg("metadata parser init OK\n"); } } else { if (is_meson_tvmode()) { - if (p_funcs_tv->metadata_parser_reset( - metadata_parser_reset_flag - ) == 0) + if (p_funcs_tv->metadata_parser_reset + (metadata_parser_reset_flag) == 0) metadata_parser_reset_flag = 0; } else { - if (p_funcs_stb->metadata_parser_reset( - metadata_parser_reset_flag - ) == 0) + if (p_funcs_stb->metadata_parser_reset + (metadata_parser_reset_flag) == 0) metadata_parser_reset_flag = 0; } parser_ready = 1; } if (!parser_ready) { spin_unlock_irqrestore(&dovi_lock, flags); - pr_dolby_error( - "meta(%d), pts(%lld) -> metadata parser init fail\n", - rpu_size, vf->pts_us64); + pr_dolby_error + ("meta(%d), pts(%lld) -> parser init fail\n", + size, vf->pts_us64); *total_comp_size = backup_comp_size; *total_md_size = backup_md_size; ret = 2; goto parse_err; } - md_size = comp_size = 0; + md_size = 0; + comp_size = 0; + if (is_meson_tvmode()) rpu_ret = - p_funcs_tv->metadata_parser_process( - meta_buf, rpu_size, - comp_buf + - *total_comp_size, - &comp_size, - md_buf + *total_md_size, - &md_size, - true); + p_funcs_tv->metadata_parser_process + (meta_buf, rpu_size, + comp_buf + *total_comp_size, + &comp_size, + md_buf + *total_md_size, + &md_size, + true); else rpu_ret = - p_funcs_stb->metadata_parser_process( - meta_buf, rpu_size, - comp_buf + - *total_comp_size, - &comp_size, - md_buf + *total_md_size, - &md_size, - true); + p_funcs_stb->metadata_parser_process + (meta_buf, rpu_size, + comp_buf + *total_comp_size, + &comp_size, + md_buf + *total_md_size, + &md_size, + true); if (rpu_ret < 0) { - pr_dolby_error( - "meta(%d), pts(%lld) -> metadata parser process fail\n", - rpu_size, vf->pts_us64); + pr_dolby_error + ("meta(%d), pts(%lld) -> parser process fail\n", + rpu_size, vf->pts_us64); ret = 3; } else { if (*total_comp_size + comp_size @@ -5836,32 +6302,31 @@ int parse_sei_and_meta_ext( } p += size; } -#ifdef V1_6_1 if (atsc_sei) { - struct _dv_vui_param_s_ vui_param; + struct dv_vui_parameters vui_param; u32 len_2086_sei = 0; u32 len_2094_sei = 0; - u8 payload_2086_sei[MAX_LENGTH_2086_SEI]; - u8 payload_2094_sei[MAX_LENGTH_2094_SEI]; + u8 payload_2086_sei[MAX_LEN_2086_SEI]; + u8 payload_2094_sei[MAX_LEN_2094_SEI]; unsigned char nal_type; unsigned char sei_payload_type = 0; unsigned char sei_payload_size = 0; - vui_param.i_video_format = (vf->signal_type >> 26) & 7; - vui_param.b_video_full_range = (vf->signal_type >> 24) & 2; - vui_param.b_colour_description = (vf->signal_type >> 24) & 1; - vui_param.i_colour_primaries = (vf->signal_type >> 16) & 0xff; - vui_param.i_transfer_characteristics = + vui_param.video_fmt_i = (vf->signal_type >> 26) & 7; + vui_param.video_fullrange_b = (vf->signal_type >> 25) & 1; + vui_param.color_description_b = (vf->signal_type >> 24) & 1; + vui_param.color_primaries_i = (vf->signal_type >> 16) & 0xff; + vui_param.trans_characteristic_i = (vf->signal_type >> 8) & 0xff; - vui_param.i_matrix_coefficients = (vf->signal_type) & 0xff; + vui_param.matrix_coeff_i = (vf->signal_type) & 0xff; if (debug_dolby & 2) pr_dolby_dbg("vui_param %d, %d, %d, %d, %d, %d\n", - vui_param.i_video_format, - vui_param.b_video_full_range, - vui_param.b_colour_description, - vui_param.i_colour_primaries, - vui_param.i_transfer_characteristics, - vui_param.i_matrix_coefficients); + vui_param.video_fmt_i, + vui_param.video_fullrange_b, + vui_param.color_description_b, + vui_param.color_primaries_i, + vui_param.trans_characteristic_i, + vui_param.matrix_coeff_i); p = aux_buf; @@ -5899,8 +6364,8 @@ int parse_sei_and_meta_ext( pr_dolby_dbg("nal_type: %d\n", nal_type); - if (nal_type == PREFIX_SEI_NUT || - nal_type == SUFFIX_SEI_NUT) { + if (nal_type == PREFIX_SEI_NUT_NAL || + nal_type == SUFFIX_SEI_NUT_NAL) { sei_payload_type = *(p + 2); sei_payload_size = *(p + 3); if (debug_dolby & 2) @@ -5908,13 +6373,13 @@ int parse_sei_and_meta_ext( sei_payload_type, sei_payload_size); if (sei_payload_type == - SEI_MASTERING_DISPLAY_COLOUR_VOLUME) { + SEI_TYPE_MASTERING_DISP_COLOUR_VOLUME) { len_2086_sei = sei_payload_size; memcpy(payload_2086_sei, p + 4, len_2086_sei); } else if (sei_payload_type == - SEI_USER_DATA_REGISTERED_ITU_T_T35) { + SEI_TYPE_USERDATA_REGISTERED_ITUT_T35) { len_2094_sei = sei_payload_size; memcpy(payload_2094_sei, p + 4, @@ -5933,13 +6398,13 @@ int parse_sei_and_meta_ext( *total_md_size = 0; *src_format = FORMAT_DOVI; p_atsc_md.vui_param = vui_param; - p_atsc_md.length_2086_sei = len_2086_sei; - memcpy(p_atsc_md.payload_2086_sei, payload_2086_sei, + p_atsc_md.len_2086_sei = len_2086_sei; + memcpy(p_atsc_md.sei_2086, payload_2086_sei, len_2086_sei); - p_atsc_md.length_2094_sei = len_2094_sei; - memcpy(p_atsc_md.payload_2094_sei, payload_2094_sei, + p_atsc_md.len_2094_sei = len_2094_sei; + memcpy(p_atsc_md.sei_2094, payload_2094_sei, len_2094_sei); - size = sizeof(struct _dv_atsc_s_); + size = sizeof(struct dv_atsc); if (size > sizeof(meta_buf)) size = sizeof(meta_buf); memcpy(meta_buf, (unsigned char *)(&p_atsc_md), size); @@ -5971,23 +6436,24 @@ int parse_sei_and_meta_ext( spin_lock_irqsave(&dovi_lock, flags); parser_ready = 0; reset_flag = 2; /*flag: bit0 flag, bit1 0->dv, 1->atsc*/ + if (!metadata_parser) { if (is_meson_tvmode()) { metadata_parser = - p_funcs_tv->metadata_parser_init( - dolby_vision_flags + p_funcs_tv->metadata_parser_init + (dolby_vision_flags & FLAG_CHANGE_SEQ_HEAD ? 1 : 0); - p_funcs_tv->metadata_parser_reset( - reset_flag | 1); + p_funcs_tv->metadata_parser_reset + (reset_flag | 1); } else { metadata_parser = - p_funcs_stb->metadata_parser_init( - dolby_vision_flags + p_funcs_stb->metadata_parser_init + (dolby_vision_flags & FLAG_CHANGE_SEQ_HEAD ? 1 : 0); - p_funcs_stb->metadata_parser_reset( - reset_flag | 1); + p_funcs_stb->metadata_parser_reset + (reset_flag | 1); } if (metadata_parser) { parser_ready = 1; @@ -5996,14 +6462,14 @@ int parse_sei_and_meta_ext( } } else { if (is_meson_tvmode()) { - if (p_funcs_tv->metadata_parser_reset( - reset_flag | + if (p_funcs_tv->metadata_parser_reset + (reset_flag | metadata_parser_reset_flag ) == 0) metadata_parser_reset_flag = 0; } else { - if (p_funcs_stb->metadata_parser_reset( - reset_flag | + if (p_funcs_stb->metadata_parser_reset + (reset_flag | metadata_parser_reset_flag ) == 0) metadata_parser_reset_flag = 0; @@ -6012,9 +6478,9 @@ int parse_sei_and_meta_ext( } if (!parser_ready) { spin_unlock_irqrestore(&dovi_lock, flags); - pr_dolby_error( - "meta(%d), pts(%lld) -> metadata parser init fail\n", - size, vf->pts_us64); + pr_dolby_error + ("meta(%d), pts(%lld) -> parser init fail\n", + size, vf->pts_us64); *total_comp_size = backup_comp_size; *total_md_size = backup_md_size; ret = 2; @@ -6026,8 +6492,8 @@ int parse_sei_and_meta_ext( if (is_meson_tvmode()) rpu_ret = - p_funcs_tv->metadata_parser_process( - meta_buf, size, + p_funcs_tv->metadata_parser_process + (meta_buf, size, comp_buf + *total_comp_size, &comp_size, md_buf + *total_md_size, @@ -6035,8 +6501,8 @@ int parse_sei_and_meta_ext( true); else rpu_ret = - p_funcs_stb->metadata_parser_process( - meta_buf, size, + p_funcs_stb->metadata_parser_process + (meta_buf, size, comp_buf + *total_comp_size, &comp_size, md_buf + *total_md_size, @@ -6044,9 +6510,9 @@ int parse_sei_and_meta_ext( true); if (rpu_ret < 0) { - pr_dolby_error( - "meta(%d), pts(%lld) -> metadata parser process fail\n", - size, vf->pts_us64); + pr_dolby_error + ("meta(%d), pts(%lld)->parser process fail\n", + size, vf->pts_us64); ret = 3; } else { if (*total_comp_size + comp_size @@ -6065,19 +6531,17 @@ int parse_sei_and_meta_ext( ret = 0; } spin_unlock_irqrestore(&dovi_lock, flags); - if (parser_overflow) { + if (parser_overflow) ret = 2; - } } } -#endif if (*total_md_size) { if (debug_dolby & 1) - pr_dolby_dbg( - "meta(%d), pts(%lld) -> md(%d), comp(%d)\n", - size, vf->pts_us64, - *total_md_size, *total_comp_size); + pr_dolby_dbg + ("meta(%d), pts(%lld) -> md(%d), comp(%d)\n", + size, vf->pts_us64, + *total_md_size, *total_comp_size); if ((debug_dolby & 4) && dump_enable) { pr_dolby_dbg("parsed md(%d):\n", *total_md_size); for (i = 0; i < *total_md_size + 7; i += 8) { @@ -6112,13 +6576,13 @@ parse_err: } EXPORT_SYMBOL(parse_sei_and_meta_ext); -static int parse_sei_and_meta( - struct vframe_s *vf, - struct provider_aux_req_s *req, - int *total_comp_size, - int *total_md_size, - enum signal_format_e *src_format, - int *ret_flags, bool drop_flag) +static int parse_sei_and_meta + (struct vframe_s *vf, + struct provider_aux_req_s *req, + int *total_comp_size, + int *total_md_size, + enum signal_format_enum *src_format, + int *ret_flags, bool drop_flag) { int ret = 2; char *p_md_buf; @@ -6158,7 +6622,6 @@ static int parse_sei_and_meta( } #define INORM 50000 - static u32 bt2020_primaries[3][2] = { {0.17 * INORM + 0.5, 0.797 * INORM + 0.5}, /* G */ {0.131 * INORM + 0.5, 0.046 * INORM + 0.5}, /* B */ @@ -6179,71 +6642,50 @@ static u32 p3_white_point[2] = { 0.3127 * INORM + 0.5, 0.3290 * INORM + 0.5 }; -void prepare_hdr10_param( - struct vframe_master_display_colour_s *p_mdc, - struct hdr10_param_s *p_hdr10_param) +void prepare_hdr10_param(struct vframe_master_display_colour_s *p_mdc, + struct hdr10_parameter *p_hdr10_param) { struct vframe_content_light_level_s *p_cll = &p_mdc->content_light_level; - uint8_t flag = 0; - uint32_t max_lum = 1000 * 10000; - uint32_t min_lum = 50; + u8 flag = 0; + u32 max_lum = 1000 * 10000; + u32 min_lum = 50; int primaries_type = 0; if (get_primary_policy() == PRIMARIES_NATIVE || primary_debug == 1 || - (dolby_vision_flags & FLAG_CERTIFICAION)) { - p_hdr10_param-> - min_display_mastering_luminance - = min_lum; - p_hdr10_param-> - max_display_mastering_luminance - = max_lum; - p_hdr10_param->Rx - = bt2020_primaries[2][0]; - p_hdr10_param->Ry - = bt2020_primaries[2][1]; - p_hdr10_param->Gx - = bt2020_primaries[0][0]; - p_hdr10_param->Gy - = bt2020_primaries[0][1]; - p_hdr10_param->Bx - = bt2020_primaries[1][0]; - p_hdr10_param->By - = bt2020_primaries[1][1]; - p_hdr10_param->Wx - = bt2020_white_point[0]; - p_hdr10_param->Wy - = bt2020_white_point[1]; + (dolby_vision_flags & FLAG_CERTIFICAION) || + !strcasecmp(cfg_info[cur_pic_mode].pic_mode_name, + "hdr10_dark")) { + p_hdr10_param->min_display_mastering_lum = + min_lum; + p_hdr10_param->max_display_mastering_lum = + max_lum; + p_hdr10_param->r_x = bt2020_primaries[2][0]; + p_hdr10_param->r_y = bt2020_primaries[2][1]; + p_hdr10_param->g_x = bt2020_primaries[0][0]; + p_hdr10_param->g_y = bt2020_primaries[0][1]; + p_hdr10_param->b_x = bt2020_primaries[1][0]; + p_hdr10_param->b_y = bt2020_primaries[1][1]; + p_hdr10_param->w_x = bt2020_white_point[0]; + p_hdr10_param->w_y = bt2020_white_point[1]; p_hdr10_param->max_content_light_level = 0; - p_hdr10_param->max_pic_average_light_level = 0; + p_hdr10_param->max_frame_avg_light_level = 0; return; } else if (get_primary_policy() == PRIMARIES_AUTO || primary_debug == 2) { - p_hdr10_param-> - min_display_mastering_luminance - = min_lum; - p_hdr10_param-> - max_display_mastering_luminance - = max_lum; - p_hdr10_param->Rx - = p3_primaries[2][0]; - p_hdr10_param->Ry - = p3_primaries[2][1]; - p_hdr10_param->Gx - = p3_primaries[0][0]; - p_hdr10_param->Gy - = p3_primaries[0][1]; - p_hdr10_param->Bx - = p3_primaries[1][0]; - p_hdr10_param->By - = p3_primaries[1][1]; - p_hdr10_param->Wx - = p3_white_point[0]; - p_hdr10_param->Wy - = p3_white_point[1]; + p_hdr10_param->min_display_mastering_lum = min_lum; + p_hdr10_param->max_display_mastering_lum = max_lum; + p_hdr10_param->r_x = p3_primaries[2][0]; + p_hdr10_param->r_y = p3_primaries[2][1]; + p_hdr10_param->g_x = p3_primaries[0][0]; + p_hdr10_param->g_y = p3_primaries[0][1]; + p_hdr10_param->b_x = p3_primaries[1][0]; + p_hdr10_param->b_y = p3_primaries[1][1]; + p_hdr10_param->w_x = p3_white_point[0]; + p_hdr10_param->w_y = p3_white_point[1]; p_hdr10_param->max_content_light_level = 0; - p_hdr10_param->max_pic_average_light_level = 0; + p_hdr10_param->max_frame_avg_light_level = 0; return; } @@ -6252,246 +6694,182 @@ void prepare_hdr10_param( /* GBR -> RGB as dolby will swap back to GBR * in send_hdmi_pkt */ - if ((p_hdr10_param-> - max_display_mastering_luminance - != p_mdc->luminance[0]) - || (p_hdr10_param-> - min_display_mastering_luminance - != p_mdc->luminance[1]) - || (p_hdr10_param->Rx - != p_mdc->primaries[2][0]) - || (p_hdr10_param->Ry - != p_mdc->primaries[2][1]) - || (p_hdr10_param->Gx - != p_mdc->primaries[0][0]) - || (p_hdr10_param->Gy - != p_mdc->primaries[0][1]) - || (p_hdr10_param->Bx - != p_mdc->primaries[1][0]) - || (p_hdr10_param->By - != p_mdc->primaries[1][1]) - || (p_hdr10_param->Wx - != p_mdc->white_point[0]) - || (p_hdr10_param->Wy - != p_mdc->white_point[1])) { + if (p_hdr10_param->max_display_mastering_lum != + p_mdc->luminance[0] || + p_hdr10_param->min_display_mastering_lum != + p_mdc->luminance[1] || + p_hdr10_param->r_x != p_mdc->primaries[2][0] || + p_hdr10_param->r_y != p_mdc->primaries[2][1] || + p_hdr10_param->g_x != p_mdc->primaries[0][0] || + p_hdr10_param->g_y != p_mdc->primaries[0][1] || + p_hdr10_param->b_x != p_mdc->primaries[1][0] || + p_hdr10_param->b_y != p_mdc->primaries[1][1] || + p_hdr10_param->w_x != p_mdc->white_point[0] || + p_hdr10_param->w_y != p_mdc->white_point[1]) { flag |= 1; - p_hdr10_param-> - max_display_mastering_luminance - = p_mdc->luminance[0]; - p_hdr10_param-> - min_display_mastering_luminance - = p_mdc->luminance[1]; - p_hdr10_param->Rx - = p_mdc->primaries[2][0]; - p_hdr10_param->Ry - = p_mdc->primaries[2][1]; - p_hdr10_param->Gx - = p_mdc->primaries[0][0]; - p_hdr10_param->Gy - = p_mdc->primaries[0][1]; - p_hdr10_param->Bx - = p_mdc->primaries[1][0]; - p_hdr10_param->By - = p_mdc->primaries[1][1]; - p_hdr10_param->Wx - = p_mdc->white_point[0]; - p_hdr10_param->Wy - = p_mdc->white_point[1]; + p_hdr10_param->max_display_mastering_lum = + p_mdc->luminance[0]; + p_hdr10_param->min_display_mastering_lum = + p_mdc->luminance[1]; + p_hdr10_param->r_x = p_mdc->primaries[2][0]; + p_hdr10_param->r_y = p_mdc->primaries[2][1]; + p_hdr10_param->g_x = p_mdc->primaries[0][0]; + p_hdr10_param->g_y = p_mdc->primaries[0][1]; + p_hdr10_param->b_x = p_mdc->primaries[1][0]; + p_hdr10_param->b_y = p_mdc->primaries[1][1]; + p_hdr10_param->w_x = p_mdc->white_point[0]; + p_hdr10_param->w_y = p_mdc->white_point[1]; } } else if (primaries_type == 1) { /* RGB -> RGB and dolby will swap to send as GBR * in send_hdmi_pkt */ - if ((p_hdr10_param-> - max_display_mastering_luminance - != p_mdc->luminance[0]) - || (p_hdr10_param-> - min_display_mastering_luminance - != p_mdc->luminance[1]) - || (p_hdr10_param->Rx - != p_mdc->primaries[0][0]) - || (p_hdr10_param->Ry - != p_mdc->primaries[0][1]) - || (p_hdr10_param->Gx - != p_mdc->primaries[1][0]) - || (p_hdr10_param->Gy - != p_mdc->primaries[1][1]) - || (p_hdr10_param->Bx - != p_mdc->primaries[2][0]) - || (p_hdr10_param->By - != p_mdc->primaries[2][1]) - || (p_hdr10_param->Wx - != p_mdc->white_point[0]) - || (p_hdr10_param->Wy - != p_mdc->white_point[1])) { + if (p_hdr10_param->max_display_mastering_lum != + p_mdc->luminance[0] || + p_hdr10_param->min_display_mastering_lum != + p_mdc->luminance[1] || + p_hdr10_param->r_x != p_mdc->primaries[0][0] || + p_hdr10_param->r_y != p_mdc->primaries[0][1] || + p_hdr10_param->g_x != p_mdc->primaries[1][0] || + p_hdr10_param->g_y != p_mdc->primaries[1][1] || + p_hdr10_param->b_x != p_mdc->primaries[2][0] || + p_hdr10_param->b_y != p_mdc->primaries[2][1] || + p_hdr10_param->w_x != p_mdc->white_point[0] || + p_hdr10_param->w_y != p_mdc->white_point[1]) { flag |= 1; - p_hdr10_param-> - max_display_mastering_luminance - = p_mdc->luminance[0]; - p_hdr10_param-> - min_display_mastering_luminance - = p_mdc->luminance[1]; - p_hdr10_param->Rx - = p_mdc->primaries[0][0]; - p_hdr10_param->Ry - = p_mdc->primaries[0][1]; - p_hdr10_param->Gx - = p_mdc->primaries[1][0]; - p_hdr10_param->Gy - = p_mdc->primaries[1][1]; - p_hdr10_param->Bx - = p_mdc->primaries[2][0]; - p_hdr10_param->By - = p_mdc->primaries[2][1]; - p_hdr10_param->Wx - = p_mdc->white_point[0]; - p_hdr10_param->Wy - = p_mdc->white_point[1]; + p_hdr10_param->max_display_mastering_lum = + p_mdc->luminance[0]; + p_hdr10_param->min_display_mastering_lum = + p_mdc->luminance[1]; + p_hdr10_param->r_x = p_mdc->primaries[0][0]; + p_hdr10_param->r_y = p_mdc->primaries[0][1]; + p_hdr10_param->g_x = p_mdc->primaries[1][0]; + p_hdr10_param->g_y = p_mdc->primaries[1][1]; + p_hdr10_param->b_x = p_mdc->primaries[2][0]; + p_hdr10_param->b_y = p_mdc->primaries[2][1]; + p_hdr10_param->w_x = p_mdc->white_point[0]; + p_hdr10_param->w_y = p_mdc->white_point[1]; } } else { /* GBR -> RGB as dolby will swap back to GBR * in send_hdmi_pkt */ - if ((p_hdr10_param-> - min_display_mastering_luminance - != min_lum) - || (p_hdr10_param-> - max_display_mastering_luminance - != max_lum) - || (p_hdr10_param->Rx - != bt2020_primaries[2][0]) - || (p_hdr10_param->Ry - != bt2020_primaries[2][1]) - || (p_hdr10_param->Gx - != bt2020_primaries[0][0]) - || (p_hdr10_param->Gy - != bt2020_primaries[0][1]) - || (p_hdr10_param->Bx - != bt2020_primaries[1][0]) - || (p_hdr10_param->By - != bt2020_primaries[1][1]) - || (p_hdr10_param->Wx - != bt2020_white_point[0]) - || (p_hdr10_param->Wy - != bt2020_white_point[1])) { + if (p_hdr10_param->min_display_mastering_lum != + min_lum || + p_hdr10_param->max_display_mastering_lum != + max_lum || + p_hdr10_param->r_x != bt2020_primaries[2][0] || + p_hdr10_param->r_y != bt2020_primaries[2][1] || + p_hdr10_param->g_x != bt2020_primaries[0][0] || + p_hdr10_param->g_y != bt2020_primaries[0][1] || + p_hdr10_param->b_x != bt2020_primaries[1][0] || + p_hdr10_param->b_y != bt2020_primaries[1][1] || + p_hdr10_param->w_x != bt2020_white_point[0] || + p_hdr10_param->w_y != bt2020_white_point[1]) { flag |= 2; - p_hdr10_param-> - min_display_mastering_luminance - = min_lum; - p_hdr10_param-> - max_display_mastering_luminance - = max_lum; - p_hdr10_param->Rx - = bt2020_primaries[2][0]; - p_hdr10_param->Ry - = bt2020_primaries[2][1]; - p_hdr10_param->Gx - = bt2020_primaries[0][0]; - p_hdr10_param->Gy - = bt2020_primaries[0][1]; - p_hdr10_param->Bx - = bt2020_primaries[1][0]; - p_hdr10_param->By - = bt2020_primaries[1][1]; - p_hdr10_param->Wx - = bt2020_white_point[0]; - p_hdr10_param->Wy - = bt2020_white_point[1]; + p_hdr10_param->min_display_mastering_lum = + min_lum; + p_hdr10_param->max_display_mastering_lum = + max_lum; + p_hdr10_param->r_x = bt2020_primaries[2][0]; + p_hdr10_param->r_y = bt2020_primaries[2][1]; + p_hdr10_param->g_x = bt2020_primaries[0][0]; + p_hdr10_param->g_y = bt2020_primaries[0][1]; + p_hdr10_param->b_x = bt2020_primaries[1][0]; + p_hdr10_param->b_y = bt2020_primaries[1][1]; + p_hdr10_param->w_x = bt2020_white_point[0]; + p_hdr10_param->w_y = bt2020_white_point[1]; } } if (p_cll->present_flag) { - if ((p_hdr10_param->max_content_light_level - != p_cll->max_content) - || (p_hdr10_param->max_pic_average_light_level - != p_cll->max_pic_average)) + if (p_hdr10_param->max_content_light_level + != p_cll->max_content || + p_hdr10_param->max_frame_avg_light_level + != p_cll->max_pic_average) flag |= 4; if (flag & 4) { - p_hdr10_param->max_content_light_level - = p_cll->max_content; - p_hdr10_param->max_pic_average_light_level - = p_cll->max_pic_average; + p_hdr10_param->max_content_light_level = + p_cll->max_content; + p_hdr10_param->max_frame_avg_light_level = + p_cll->max_pic_average; } } else { - if ((p_hdr10_param->max_content_light_level != 0) - || (p_hdr10_param->max_pic_average_light_level != 0)) { + if (p_hdr10_param->max_content_light_level != 0 || + p_hdr10_param->max_frame_avg_light_level != 0) { p_hdr10_param->max_content_light_level = 0; - p_hdr10_param->max_pic_average_light_level = 0; + p_hdr10_param->max_frame_avg_light_level = 0; flag |= 8; } } - if (flag) { - pr_dolby_dbg( - "HDR10: primaries %d, maxcontent %d, flag %d, type %d\n", - p_mdc->present_flag, - p_cll->present_flag, - flag, - primaries_type); - pr_dolby_dbg("\tR = %04x, %04x\n", - p_hdr10_param->Rx, - p_hdr10_param->Ry); - pr_dolby_dbg("\tG = %04x, %04x\n", - p_hdr10_param->Gx, - p_hdr10_param->Gy); - pr_dolby_dbg("\tB = %04x, %04x\n", - p_hdr10_param->Bx, - p_hdr10_param->By); - pr_dolby_dbg("\tW = %04x, %04x\n", - p_hdr10_param->Wx, - p_hdr10_param->Wy); - pr_dolby_dbg("\tMax = %d\n", - p_hdr10_param-> - max_display_mastering_luminance); - pr_dolby_dbg("\tMin = %d\n", - p_hdr10_param-> - min_display_mastering_luminance); - pr_dolby_dbg("\tMCLL = %d\n", - p_hdr10_param-> - max_content_light_level); - pr_dolby_dbg("\tMPALL = %d\n\n", - p_hdr10_param-> - max_pic_average_light_level); - } -} - -#ifdef V2_4 -static int prepare_vsif_pkt( - struct dv_vsif_para *vsif, + if (flag && (debug_dolby & 1)) { + pr_dolby_dbg + ("HDR10: present %d, %d, %d, %d\n", + p_mdc->present_flag, p_cll->max_content, + flag, primaries_type); + pr_dolby_dbg + ("\tR = %04x, %04x\n", + p_hdr10_param->r_x, p_hdr10_param->r_y); + pr_dolby_dbg + ("\tG = %04x, %04x\n", + p_hdr10_param->g_x, p_hdr10_param->g_y); + pr_dolby_dbg + ("\tB = %04x, %04x\n", + p_hdr10_param->b_x, p_hdr10_param->b_y); + pr_dolby_dbg + ("\tW = %04x, %04x\n", + p_hdr10_param->w_x, p_hdr10_param->w_y); + pr_dolby_dbg + ("\tMax = %d\n", + p_hdr10_param->max_display_mastering_lum); + pr_dolby_dbg + ("\tMin = %d\n", + p_hdr10_param->min_display_mastering_lum); + pr_dolby_dbg + ("\tMCLL = %d\n", + p_hdr10_param->max_content_light_level); + pr_dolby_dbg + ("\tMPALL = %d\n\n", + p_hdr10_param->max_frame_avg_light_level); + } +} + +static int prepare_vsif_pkt + (struct dv_vsif_para *vsif, struct dovi_setting_s *setting, const struct vinfo_s *vinfo) { if (!vsif || !vinfo || !setting || - !vinfo->vout_device || !vinfo->vout_device->dv_info) + !vinfo->vout_device || !vinfo->vout_device->dv_info) return -1; vsif->vers.ver2.low_latency = setting->dovi_ll_enable; vsif->vers.ver2.dobly_vision_signal = 1; - if (vinfo->vout_device->dv_info - && vinfo->vout_device->dv_info->sup_backlight_control - && (setting->ext_md.available_level_mask - & EXT_MD_AVAIL_LEVEL_2)) { + if (vinfo->vout_device->dv_info && + vinfo->vout_device->dv_info->sup_backlight_control && + (setting->ext_md.avail_level_mask & EXT_MD_LEVEL_2)) { vsif->vers.ver2.backlt_ctrl_MD_present = 1; vsif->vers.ver2.eff_tmax_PQ_hi = - setting->ext_md.level_2.target_max_PQ_hi & 0xf; + setting->ext_md.level_2.target_max_pq_h & 0xf; vsif->vers.ver2.eff_tmax_PQ_low = - setting->ext_md.level_2.target_max_PQ_lo; + setting->ext_md.level_2.target_max_pq_l; } else { vsif->vers.ver2.backlt_ctrl_MD_present = 0; vsif->vers.ver2.eff_tmax_PQ_hi = 0; vsif->vers.ver2.eff_tmax_PQ_low = 0; } - if (setting->dovi_ll_enable - && (setting->ext_md.available_level_mask - & EXT_MD_AVAIL_LEVEL_255)) { + if (setting->dovi_ll_enable && + (setting->ext_md.avail_level_mask + & EXT_MD_LEVEL_255)) { vsif->vers.ver2.auxiliary_MD_present = 1; vsif->vers.ver2.auxiliary_runmode = - setting->ext_md.level_255.dm_run_mode; + setting->ext_md.level_255.run_mode; vsif->vers.ver2.auxiliary_runversion = - setting->ext_md.level_255.dm_run_version; + setting->ext_md.level_255.run_version; vsif->vers.ver2.auxiliary_debug0 = - setting->ext_md.level_255.dm_debug0; + setting->ext_md.level_255.dm_debug_0; } else { vsif->vers.ver2.auxiliary_MD_present = 0; vsif->vers.ver2.auxiliary_runmode = 0; @@ -6500,8 +6878,43 @@ static int prepare_vsif_pkt( } return 0; } -#endif +unsigned char vsif_emp[32]; +static int prepare_emp_vsif_pkt + (unsigned char *vsif_PB, + struct dovi_setting_s *setting, + const struct vinfo_s *vinfo) +{ + if (!vinfo || !setting || + !vinfo->vout_device || !vinfo->vout_device->dv_info) + return -1; + memset(vsif_PB, 0, 32); + /* low_latency */ + if (setting->dovi_ll_enable) + vsif_PB[0] = 1 << 0; + /* dovi_signal_type */ + vsif_PB[0] |= 1 << 1; + /* source_dm_version */ + vsif_PB[0] |= 3 << 5; + + if (vinfo->vout_device->dv_info->sup_backlight_control && + (setting->ext_md.avail_level_mask & EXT_MD_LEVEL_2)) { + vsif_PB[1] |= 1 << 7; + vsif_PB[1] |= + setting->ext_md.level_2.target_max_pq_h & 0xf; + vsif_PB[2] = + setting->ext_md.level_2.target_max_pq_l; + } + + if (setting->dovi_ll_enable && (setting->ext_md.avail_level_mask + & EXT_MD_LEVEL_255)) { + vsif_PB[1] |= 1 << 6; + vsif_PB[3] = setting->ext_md.level_255.run_mode; + vsif_PB[4] = setting->ext_md.level_255.run_version; + vsif_PB[5] = setting->ext_md.level_255.dm_debug_0; + } + return 0; +} static int notify_vd_signal_to_amvideo(struct vd_signal_info_s *vd_signal) { static int pre_signal = -1; @@ -6522,12 +6935,12 @@ static int notify_vd_signal_to_amvideo(struct vd_signal_info_s *vd_signal) /* #define HDMI_SEND_ALL_PKT */ static u32 last_dst_format = FORMAT_SDR; -static bool send_hdmi_pkt( - enum signal_format_e src_format, - enum signal_format_e dst_format, - const struct vinfo_s *vinfo, struct vframe_s *vf) +static bool send_hdmi_pkt + (enum signal_format_enum src_format, + enum signal_format_enum dst_format, + const struct vinfo_s *vinfo, struct vframe_s *vf) { - struct hdr_10_infoframe_s *p_hdr; + struct hdr10_infoframe *p_hdr; int i; bool flag = false; static int sdr_transition_delay; @@ -6547,160 +6960,171 @@ static bool send_hdmi_pkt( if (src_format != FORMAT_HDR10PLUS) { /* keep as r,g,b when src not HDR+ */ if (hdr10_data.primaries[0][0] != - ((p_hdr->display_primaries_x_0_MSB << 8) - | p_hdr->display_primaries_x_0_LSB)) + ((p_hdr->primaries_x_0_msb << 8) + | p_hdr->primaries_x_0_lsb)) flag = true; hdr10_data.primaries[0][0] = - (p_hdr->display_primaries_x_0_MSB << 8) - | p_hdr->display_primaries_x_0_LSB; + (p_hdr->primaries_x_0_msb << 8) + | p_hdr->primaries_x_0_lsb; if (hdr10_data.primaries[0][1] != - ((p_hdr->display_primaries_y_0_MSB << 8) - | p_hdr->display_primaries_y_0_LSB)) + ((p_hdr->primaries_y_0_msb << 8) + | p_hdr->primaries_y_0_lsb)) flag = true; hdr10_data.primaries[0][1] = - (p_hdr->display_primaries_y_0_MSB << 8) - | p_hdr->display_primaries_y_0_LSB; + (p_hdr->primaries_y_0_msb << 8) + | p_hdr->primaries_y_0_lsb; if (hdr10_data.primaries[1][0] != - ((p_hdr->display_primaries_x_1_MSB << 8) - | p_hdr->display_primaries_x_1_LSB)) + ((p_hdr->primaries_x_1_msb << 8) + | p_hdr->primaries_x_1_lsb)) flag = true; hdr10_data.primaries[1][0] = - (p_hdr->display_primaries_x_1_MSB << 8) - | p_hdr->display_primaries_x_1_LSB; + (p_hdr->primaries_x_1_msb << 8) + | p_hdr->primaries_x_1_lsb; if (hdr10_data.primaries[1][1] != - ((p_hdr->display_primaries_y_1_MSB << 8) - | p_hdr->display_primaries_y_1_LSB)) + ((p_hdr->primaries_y_1_msb << 8) + | p_hdr->primaries_y_1_lsb)) flag = true; hdr10_data.primaries[1][1] = - (p_hdr->display_primaries_y_1_MSB << 8) - | p_hdr->display_primaries_y_1_LSB; + (p_hdr->primaries_y_1_msb << 8) + | p_hdr->primaries_y_1_lsb; if (hdr10_data.primaries[2][0] != - ((p_hdr->display_primaries_x_2_MSB << 8) - | p_hdr->display_primaries_x_2_LSB)) + ((p_hdr->primaries_x_2_msb << 8) + | p_hdr->primaries_x_2_lsb)) flag = true; hdr10_data.primaries[2][0] = - (p_hdr->display_primaries_x_2_MSB << 8) - | p_hdr->display_primaries_x_2_LSB; + (p_hdr->primaries_x_2_msb << 8) + | p_hdr->primaries_x_2_lsb; if (hdr10_data.primaries[2][1] != - ((p_hdr->display_primaries_y_2_MSB << 8) - | p_hdr->display_primaries_y_2_LSB)) + ((p_hdr->primaries_y_2_msb << 8) + | p_hdr->primaries_y_2_lsb)) flag = true; hdr10_data.primaries[2][1] = - (p_hdr->display_primaries_y_2_MSB << 8) - | p_hdr->display_primaries_y_2_LSB; + (p_hdr->primaries_y_2_msb << 8) + | p_hdr->primaries_y_2_lsb; } else { /* need invert to g,b,r */ if (hdr10_data.primaries[0][0] != - ((p_hdr->display_primaries_x_1_MSB << 8) - | p_hdr->display_primaries_x_1_LSB)) + ((p_hdr->primaries_x_1_msb << 8) + | p_hdr->primaries_x_1_lsb)) flag = true; hdr10_data.primaries[0][0] = - (p_hdr->display_primaries_x_1_MSB << 8) - | p_hdr->display_primaries_x_1_LSB; + (p_hdr->primaries_x_1_msb << 8) + | p_hdr->primaries_x_1_lsb; if (hdr10_data.primaries[0][1] != - ((p_hdr->display_primaries_y_1_MSB << 8) - | p_hdr->display_primaries_y_1_LSB)) + ((p_hdr->primaries_y_1_msb << 8) + | p_hdr->primaries_y_1_lsb)) flag = true; hdr10_data.primaries[0][1] = - (p_hdr->display_primaries_y_1_MSB << 8) - | p_hdr->display_primaries_y_1_LSB; + (p_hdr->primaries_y_1_msb << 8) + | p_hdr->primaries_y_1_lsb; if (hdr10_data.primaries[1][0] != - ((p_hdr->display_primaries_x_2_MSB << 8) - | p_hdr->display_primaries_x_2_LSB)) + ((p_hdr->primaries_x_2_msb << 8) + | p_hdr->primaries_x_2_lsb)) flag = true; hdr10_data.primaries[1][0] = - (p_hdr->display_primaries_x_2_MSB << 8) - | p_hdr->display_primaries_x_2_LSB; + (p_hdr->primaries_x_2_msb << 8) + | p_hdr->primaries_x_2_lsb; if (hdr10_data.primaries[1][1] != - ((p_hdr->display_primaries_y_2_MSB << 8) - | p_hdr->display_primaries_y_2_LSB)) + ((p_hdr->primaries_y_2_msb << 8) + | p_hdr->primaries_y_2_lsb)) flag = true; hdr10_data.primaries[1][1] = - (p_hdr->display_primaries_y_2_MSB << 8) - | p_hdr->display_primaries_y_2_LSB; + (p_hdr->primaries_y_2_msb << 8) + | p_hdr->primaries_y_2_lsb; if (hdr10_data.primaries[2][0] != - ((p_hdr->display_primaries_x_0_MSB << 8) - | p_hdr->display_primaries_x_0_LSB)) + ((p_hdr->primaries_x_0_msb << 8) + | p_hdr->primaries_x_0_lsb)) flag = true; hdr10_data.primaries[2][0] = - (p_hdr->display_primaries_x_0_MSB << 8) - | p_hdr->display_primaries_x_0_LSB; + (p_hdr->primaries_x_0_msb << 8) + | p_hdr->primaries_x_0_lsb; if (hdr10_data.primaries[2][1] != - ((p_hdr->display_primaries_y_0_MSB << 8) - | p_hdr->display_primaries_y_0_LSB)) + ((p_hdr->primaries_y_0_msb << 8) + | p_hdr->primaries_y_0_lsb)) flag = true; hdr10_data.primaries[2][1] = - (p_hdr->display_primaries_y_0_MSB << 8) - | p_hdr->display_primaries_y_0_LSB; + (p_hdr->primaries_y_0_msb << 8) + | p_hdr->primaries_y_0_lsb; } if (hdr10_data.white_point[0] != - ((p_hdr->white_point_x_MSB << 8) - | p_hdr->white_point_x_LSB)) + ((p_hdr->white_point_x_msb << 8) + | p_hdr->white_point_x_lsb)) flag = true; hdr10_data.white_point[0] = - (p_hdr->white_point_x_MSB << 8) - | p_hdr->white_point_x_LSB; + (p_hdr->white_point_x_msb << 8) + | p_hdr->white_point_x_lsb; if (hdr10_data.white_point[1] != - ((p_hdr->white_point_y_MSB << 8) - | p_hdr->white_point_y_LSB)) + ((p_hdr->white_point_y_msb << 8) + | p_hdr->white_point_y_lsb)) flag = true; hdr10_data.white_point[1] = - (p_hdr->white_point_y_MSB << 8) - | p_hdr->white_point_y_LSB; + (p_hdr->white_point_y_msb << 8) + | p_hdr->white_point_y_lsb; if (hdr10_data.luminance[0] != - ((p_hdr->max_display_mastering_luminance_MSB << 8) - | p_hdr->max_display_mastering_luminance_LSB)) + ((p_hdr->max_display_mastering_lum_msb << 8) + | p_hdr->max_display_mastering_lum_lsb)) flag = true; hdr10_data.luminance[0] = - (p_hdr->max_display_mastering_luminance_MSB << 8) - | p_hdr->max_display_mastering_luminance_LSB; + (p_hdr->max_display_mastering_lum_msb << 8) + | p_hdr->max_display_mastering_lum_lsb; if (hdr10_data.luminance[1] != - ((p_hdr->min_display_mastering_luminance_MSB << 8) - | p_hdr->min_display_mastering_luminance_LSB)) + ((p_hdr->min_display_mastering_lum_msb << 8) + | p_hdr->min_display_mastering_lum_lsb)) flag = true; hdr10_data.luminance[1] = - (p_hdr->min_display_mastering_luminance_MSB << 8) - | p_hdr->min_display_mastering_luminance_LSB; + (p_hdr->min_display_mastering_lum_msb << 8) + | p_hdr->min_display_mastering_lum_lsb; if (hdr10_data.max_content != - ((p_hdr->max_content_light_level_MSB << 8) - | p_hdr->max_content_light_level_LSB)) + ((p_hdr->max_content_light_level_msb << 8) + | p_hdr->max_content_light_level_lsb)) flag = true; hdr10_data.max_content = - (p_hdr->max_content_light_level_MSB << 8) - | p_hdr->max_content_light_level_LSB; + (p_hdr->max_content_light_level_msb << 8) + | p_hdr->max_content_light_level_lsb; if (hdr10_data.max_frame_average != - ((p_hdr->max_frame_average_light_level_MSB << 8) - | p_hdr->max_frame_average_light_level_LSB)) + ((p_hdr->max_frame_avg_light_level_msb << 8) + | p_hdr->max_frame_avg_light_level_lsb)) flag = true; hdr10_data.max_frame_average = - (p_hdr->max_frame_average_light_level_MSB << 8) - | p_hdr->max_frame_average_light_level_LSB; + (p_hdr->max_frame_avg_light_level_msb << 8) + | p_hdr->max_frame_avg_light_level_lsb; if (vinfo && vinfo->vout_device && - vinfo->vout_device->fresh_tx_hdr_pkt) + vinfo->vout_device->fresh_tx_hdr_pkt) vinfo->vout_device->fresh_tx_hdr_pkt(&hdr10_data); #ifdef HDMI_SEND_ALL_PKT if (vinfo && vinfo->vout_device && - vinfo->vout_device->fresh_tx_vsif_pkt) - vinfo->vout_device->fresh_tx_vsif_pkt(0, 0, NULL, true); + vinfo->vout_device->fresh_tx_vsif_pkt) { +#ifdef V2_4_3 + send_emp(EOTF_T_NULL, + YUV422_BIT12, + (struct dv_vsif_para *)NULL, + (unsigned char *)NULL, + 0, + true); +#else + vinfo->vout_device->fresh_tx_vsif_pkt + (0, 0, NULL, true); +#endif + } #endif - if ((last_dst_format != FORMAT_HDR10) || + if (last_dst_format != FORMAT_HDR10 || (dolby_vision_flags & FLAG_FORCE_HDMI_PKT)) - pr_dolby_dbg("send_hdmi_pkt: HDR10\n"); + pr_dolby_dbg("send hdmi pkt: HDR10\n"); last_dst_format = dst_format; vd_signal.signal_type = SIGNAL_HDR10; @@ -6708,11 +7132,10 @@ static bool send_hdmi_pkt( if (flag && debug_dolby & 8) { pr_dolby_dbg("Info frame for hdr10 changed:\n"); for (i = 0; i < 3; i++) - pr_dolby_dbg( - "\tprimaries[%1d] = %04x, %04x\n", - i, - hdr10_data.primaries[i][0], - hdr10_data.primaries[i][1]); + pr_dolby_dbg("\tprimaries[%1d] = %04x, %04x\n", + i, + hdr10_data.primaries[i][0], + hdr10_data.primaries[i][1]); pr_dolby_dbg("\twhite_point = %04x, %04x\n", hdr10_data.white_point[0], hdr10_data.white_point[1]); @@ -6730,11 +7153,12 @@ static bool send_hdmi_pkt( sdr_transition_delay = 0; memset(&vsif, 0, sizeof(vsif)); -#ifdef V2_4 - if (vinfo) - prepare_vsif_pkt( - &vsif, &dovi_setting, vinfo); -#endif + if (vinfo) { + prepare_vsif_pkt + (&vsif, &dovi_setting, vinfo); + prepare_emp_vsif_pkt + (vsif_emp, &dovi_setting, vinfo); + } #ifdef HDMI_SEND_ALL_PKT hdr10_data.features = (1 << 29) /* video available */ @@ -6755,30 +7179,47 @@ static bool send_hdmi_pkt( hdr10_data.max_content = 0; hdr10_data.max_frame_average = 0; if (vinfo && vinfo->vout_device && - vinfo->vout_device->fresh_tx_hdr_pkt) + vinfo->vout_device->fresh_tx_hdr_pkt) vinfo->vout_device->fresh_tx_hdr_pkt(&hdr10_data); #endif if (vinfo && vinfo->vout_device && - vinfo->vout_device->fresh_tx_vsif_pkt) { -#ifdef V2_4 - if (dovi_setting.dovi_ll_enable) - vinfo->vout_device->fresh_tx_vsif_pkt( - EOTF_T_LL_MODE, + vinfo->vout_device->fresh_tx_vsif_pkt) { + if (dovi_setting.dovi_ll_enable) { +#ifdef V2_4_3 + send_emp(EOTF_T_LL_MODE, + dovi_setting.diagnostic_enable + ? RGB_10_12BIT : YUV422_BIT12, + &vsif, vsif_emp, 15, false); +#else + vinfo->vout_device->fresh_tx_vsif_pkt + (EOTF_T_LL_MODE, dovi_setting.diagnostic_enable ? RGB_10_12BIT : YUV422_BIT12, &vsif, false); - else #endif - vinfo->vout_device->fresh_tx_vsif_pkt( - EOTF_T_DOLBYVISION, - dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL - ? RGB_8BIT : YUV422_BIT12, &vsif, - false); + } else { +#ifdef V2_4_3 + send_emp(EOTF_T_DOLBYVISION, + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL + ? RGB_8BIT : YUV422_BIT12, + NULL, + hdmi_metadata, + hdmi_metadata_size, + false); +#else + vinfo->vout_device->fresh_tx_vsif_pkt + (EOTF_T_DOLBYVISION, + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL + ? RGB_8BIT : YUV422_BIT12, &vsif, + false); +#endif + } } - if ((last_dst_format != FORMAT_DOVI) || + if (last_dst_format != FORMAT_DOVI || (dolby_vision_flags & FLAG_FORCE_HDMI_PKT)) - pr_dolby_dbg("send_hdmi_pkt: %s\n", + pr_dolby_dbg("send hdmi pkt: %s\n", dovi_setting.dovi_ll_enable ? "LL" : "DV"); last_dst_format = dst_format; vd_signal.signal_type = SIGNAL_DOVI; @@ -6814,29 +7255,60 @@ static bool send_hdmi_pkt( last_dst_format = dst_format; } else if (last_dst_format == FORMAT_DOVI) { if (vinfo && vinfo->vout_device && - vinfo->vout_device->fresh_tx_vsif_pkt) { + vinfo->vout_device->fresh_tx_vsif_pkt) { if (vf && (is_hlg_frame(vf) || is_hdr10plus_frame(vf))) { /* HLG/HDR10+ case: first switch to SDR * immediately. */ - pr_dolby_dbg("send_hdmi_pkt: HDR10+/HLG: signal SDR first\n"); - vinfo->vout_device->fresh_tx_vsif_pkt( - 0, 0, NULL, true); + pr_dolby_dbg + ("send pkt: HDR10+/HLG: signal SDR first\n"); +#ifdef V2_4_3 + send_emp(EOTF_T_NULL, + YUV422_BIT12, + (struct dv_vsif_para *)NULL, + (unsigned char *)NULL, + 0, + true); +#else + vinfo->vout_device->fresh_tx_vsif_pkt + (0, 0, NULL, true); +#endif + last_dst_format = dst_format; sdr_transition_delay = 0; } else if (sdr_transition_delay >= - MAX_TRANSITION_DELAY) { - pr_dolby_dbg("send_hdmi_pkt: VSIF disabled, signal SDR\n"); - vinfo->vout_device->fresh_tx_vsif_pkt( - 0, 0, NULL, true); + MAX_TRANSITION_DELAY) { + pr_dolby_dbg + ("send pkt: VSIF disabled, signal SDR\n"); +#ifdef V2_4_3 + send_emp(EOTF_T_NULL, + YUV422_BIT12, + (struct dv_vsif_para *)NULL, + (unsigned char *)NULL, + 0, + true); +#else + vinfo->vout_device->fresh_tx_vsif_pkt + (0, 0, NULL, true); +#endif last_dst_format = dst_format; sdr_transition_delay = 0; } else { if (sdr_transition_delay == 0) { - pr_dolby_dbg("send_hdmi_pkt: disable Dovi/H14b VSIF\n"); - vinfo->vout_device->fresh_tx_vsif_pkt( - 0, 0, NULL, false); + pr_dolby_dbg("send pkt: disable Dovi/H14b VSIF\n"); + +#ifdef V2_4_3 + send_emp(EOTF_T_NULL, + YUV422_BIT12, + (struct dv_vsif_para *)NULL, + (unsigned char *)NULL, + 0, + false); +#else + vinfo->vout_device->fresh_tx_vsif_pkt + (0, 0, NULL, false); +#endif } sdr_transition_delay++; } @@ -6850,8 +7322,8 @@ static bool send_hdmi_pkt( return flag; } -static void send_hdmi_pkt_ahead( - enum signal_format_e dst_format, +static void send_hdmi_pkt_ahead + (enum signal_format_enum dst_format, const struct vinfo_s *vinfo) { bool dovi_ll_enable = false; @@ -6882,14 +7354,14 @@ static void send_hdmi_pkt_ahead( if (vinfo && vinfo->vout_device && vinfo->vout_device->fresh_tx_vsif_pkt) { if (dovi_ll_enable) - vinfo->vout_device->fresh_tx_vsif_pkt( - EOTF_T_DV_AHEAD, + vinfo->vout_device->fresh_tx_vsif_pkt + (EOTF_T_DV_AHEAD, diagnostic_enable ? RGB_10_12BIT : YUV422_BIT12, &vsif, false); else - vinfo->vout_device->fresh_tx_vsif_pkt( - EOTF_T_DV_AHEAD, + vinfo->vout_device->fresh_tx_vsif_pkt + (EOTF_T_DV_AHEAD, dolby_vision_target_mode == dovi_ll_enable ? YUV422_BIT12 : RGB_8BIT, &vsif, @@ -6900,17 +7372,17 @@ static void send_hdmi_pkt_ahead( } } -static uint32_t null_vf_cnt; +static u32 null_vf_cnt; static bool video_off_handled; static int is_video_output_off(struct vframe_s *vf) { - if ((READ_VPP_DV_REG(VPP_MISC) & (1<<10)) == 0) { + if ((READ_VPP_DV_REG(VPP_MISC) & (1 << 10)) == 0) { /*Not reset frame0/1 clipping*/ /*when core off to avoid green garbage*/ - if (is_meson_tvmode() && (vf == NULL) && - (dolby_vision_on_count <= dolby_vision_run_mode_delay)) + if (is_meson_tvmode() && !vf && + dolby_vision_on_count <= dolby_vision_run_mode_delay) return 0; - if (vf == NULL) + if (!vf) null_vf_cnt++; else null_vf_cnt = 0; @@ -6920,18 +7392,21 @@ static int is_video_output_off(struct vframe_s *vf) } if (video_off_handled) return 1; - } else + } else { video_off_handled = 0; + } return 0; } -static void calculate_panel_max_pq( - const struct vinfo_s *vinfo, - struct TargetDisplayConfig *config) +static void calculate_panel_max_pq + (const struct vinfo_s *vinfo, + struct target_config *config) { - uint32_t max_lin = tv_max_lin; - uint16_t max_pq = tv_max_pq; + u32 max_lin = tv_max_lin; + u16 max_pq = tv_max_pq; + if (use_target_lum_from_cfg) + return; if (dolby_vision_flags & FLAG_CERTIFICAION) return; if (panel_max_lumin) @@ -6952,48 +7427,272 @@ static void calculate_panel_max_pq( max_lin = (max_lin / 100) * 100 + 500; max_pq = L2PQ_500_4000[(max_lin - 500) / 100]; } - if (debug_dolby & 2) + if (tv_max_lin != max_lin || tv_max_pq != max_pq) pr_dolby_dbg("panel max lumin changed from %d(%d) to %d(%d)\n", tv_max_lin, tv_max_pq, max_lin, max_pq); tv_max_lin = max_lin; tv_max_pq = max_pq; - config->max_lin = - config->max_lin_dupli = - tv_max_lin << 18; - config->maxPq = - config->maxPq_dupli = - tv_max_pq; + config->max_lin = tv_max_lin << 18; + config->max_lin_dm3 = config->max_lin; + config->max_pq = tv_max_pq; + config->max_pq_dm3 = config->max_pq; } } -bool is_dv_standard_es( - int dvel, int mflag, int width) +bool is_dv_standard_es(int dvel, int mflag, int width) { - if ((dolby_vision_profile == 4) && - (dvel == 1) && (mflag == 0) && - (width >= 3840)) + if (dolby_vision_profile == 4 && + dvel == 1 && mflag == 0 && + width >= 3840) return false; else return true; } +static int prepare_dv_meta + (struct md_reg_ipcore3 *out, + unsigned char *p_md, int size) +{ + int i, shift; + u32 value; + unsigned char *p; + u32 *p_out; + + /* calculate md size in double word */ + out->size = 1 + (size - 1 + 3) / 4; + + /* write metadata into register structure*/ + p = p_md; + p_out = out->raw_metadata; + *p_out++ = (size << 8) | p[0]; + shift = 0; value = 0; + for (i = 1; i < size; i++) { + value = value | (p[i] << shift); + shift += 8; + if (shift == 32) { + *p_out++ = value; + shift = 0; value = 0; + } + } + if (shift != 0) + *p_out++ = value; + + return out->size; +} + +#define VSEM_BUF_SIZE 0x1000 +#define VSIF_PAYLOAD_LEN 24 +#define VSEM_PKT_BODY_SIZE 28 +#define VSEM_FIRST_PKT_EDR_DATA_SIZE 15 + +struct vsem_data_pkt { + unsigned char pkt_type; + unsigned char hb1; + unsigned char seq_index; + unsigned char pb[VSEM_PKT_BODY_SIZE]; +}; + +#define HEADER_MASK_FIRST 0x80 +#define HEADER_MASK_LAST 0x40 + +unsigned short get_data_len(struct vsem_data_pkt *pkt) +{ + return (pkt->pb[5] << 8) + pkt->pb[6]; +} + +unsigned char get_vsem_byte(u8 md_byte, u8 mask) +{ + u8 field_lsb_off = 0; + u8 field_mask = mask; + + while (!(field_mask & 1)) { + field_mask >>= 1; + field_lsb_off++; + } + + return ((md_byte & mask) >> field_lsb_off); +} + +static u32 crc32_table[256] = { + 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, + 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, + 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7, + 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, + 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, + 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, + 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef, + 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, + 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, + 0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, + 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, + 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, + 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, + 0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, + 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, + 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, + 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, + 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, + 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050, + 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, + 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, + 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, + 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1, + 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, + 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, + 0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, + 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9, + 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, + 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, + 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, + 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, + 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, + 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, + 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, + 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, + 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, + 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, + 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, + 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676, + 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, + 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, + 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, + 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 +}; + +static u32 get_crc32(const void *data, size_t data_size) +{ + const u8 *p = (u8 *)data; + u32 crc = 0xFFFFFFFF; + + while (data_size) { + crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *p) & 0xff]; + p++; + data_size--; + } + + return crc; +} + +int vsem_check(unsigned char *control_data, unsigned char *vsem_payload) +{ + struct vsem_data_pkt *cur_pkt; + unsigned char *p_buf = NULL; + u16 cur_len = 0; + int rv = 0; + u32 crc; + u32 data_length = 0; + bool last = false; + + cur_pkt = (struct vsem_data_pkt *)(control_data); + p_buf = vsem_payload; + + if (!get_vsem_byte(cur_pkt->hb1, HEADER_MASK_FIRST)) { + rv = -1; + return rv; + } + data_length = get_data_len(cur_pkt); + memcpy(p_buf, &cur_pkt->pb[0], VSEM_PKT_BODY_SIZE); + cur_len = VSEM_PKT_BODY_SIZE - 7; + p_buf += VSEM_PKT_BODY_SIZE; + while (!last) { + cur_pkt += 1; + if (get_vsem_byte(cur_pkt->hb1, HEADER_MASK_LAST)) { + memcpy(p_buf, &cur_pkt->pb[0], + data_length - cur_len); + last = true; + } else { + memcpy(p_buf, &cur_pkt->pb[0], + VSEM_PKT_BODY_SIZE); + cur_len += VSEM_PKT_BODY_SIZE; + p_buf += VSEM_PKT_BODY_SIZE; + } + if (cur_len >= data_length) { + pr_info("didn't find last pkt! %d >= %d\n", + cur_len, data_length); + break; + } + if (cur_len >= VSEM_BUF_SIZE - VSEM_PKT_BODY_SIZE) { + pr_info("vsem payload buffer is too small!\n"); + break; + } + } + + /* crc check */ + crc = get_crc32(vsem_payload + 13, data_length - 6); + if (crc != 0) { + pr_info("Error: crc error while reading control data\n"); + rv = -1; + return rv; + } + + return rv; +} + +/*for hdmi cert: not run cp when vf not change*/ +/*sometimes even if frame is same but frame crc changed,*/ +/*maybe ucd or rx not stable,*/ +/*so need to check few more frames*/ +bool check_vf_changed(struct vframe_s *vf) +{ +#define MAX_VF_CRC_CHECK_CUONT 4 + + static u32 new_vf_crc; + static u32 vf_crc_repeat_cnt; + bool changed = false; + + if (!vf) + return true; + + if (debug_dolby & 1) + pr_dolby_dbg("vf %p, crc %x, last valid crc %x, rpt %d\n", + vf, vf->crc, last_vf_valid_crc, + vf_crc_repeat_cnt); + + if (vf->crc == 0) { + /*invalid crc, maybe vdin dropped last frame*/ + return changed; + } + if (last_vf_valid_crc == 0) { + last_vf_valid_crc = vf->crc; + changed = true; + pr_dolby_dbg("first frame\n"); + } else if (vf->crc != last_vf_valid_crc) { + if (vf->crc != new_vf_crc) + vf_crc_repeat_cnt = 0; + else + ++vf_crc_repeat_cnt; + + if (vf_crc_repeat_cnt >= MAX_VF_CRC_CHECK_CUONT) { + vf_crc_repeat_cnt = 0; + last_vf_valid_crc = vf->crc; + changed = true; + pr_dolby_dbg("new frame\n"); + } + } else { + vf_crc_repeat_cnt = 0; + } + new_vf_crc = vf->crc; + return changed; +} + static u32 last_total_md_size; static u32 last_total_comp_size; /* toggle mode: 0: not toggle; 1: toggle frame; 2: use keep frame */ -int dolby_vision_parse_metadata( - struct vframe_s *vf, u8 toggle_mode, - bool bypass_release, bool drop_flag) +int dolby_vision_parse_metadata(struct vframe_s *vf, + u8 toggle_mode, + bool bypass_release, + bool drop_flag) { const struct vinfo_s *vinfo = get_current_vinfo(); struct vframe_s *el_vf; struct provider_aux_req_s req; struct provider_aux_req_s el_req; int flag; - enum signal_format_e src_format = FORMAT_SDR; - enum signal_format_e check_format; - enum signal_format_e dst_format; - enum signal_format_e cur_src_format; - enum signal_format_e cur_dst_format; + enum signal_format_enum src_format = FORMAT_SDR; + enum signal_format_enum check_format; + enum signal_format_enum dst_format; + enum signal_format_enum cur_src_format; + enum signal_format_enum cur_dst_format; int total_md_size = 0; int total_comp_size = 0; bool el_flag = 0; @@ -7008,9 +7707,9 @@ int dolby_vision_parse_metadata( int i; struct vframe_master_display_colour_s *p_mdc; unsigned int current_mode = dolby_vision_mode; - uint32_t target_lumin_max = 0; - enum input_mode_e input_mode = INPUT_MODE_OTT; - enum priority_mode_e pri_mode = VIDEO_PRIORITY; + u32 target_lumin_max = 0; + enum input_mode_enum input_mode = IN_MODE_OTT; + enum priority_mode_enum pri_mode = V_PRIORITY; u32 graphic_min = 50; /* 0.0001 */ u32 graphic_max = 100; /* 1 */ int ret_flags = 0; @@ -7018,7 +7717,18 @@ int dolby_vision_parse_metadata( static int last_current_format; int ret = -1; bool mel_flag = false; + int vsem_size = 0; + int vsem_if_size = 0; + bool dump_emp = false; + bool dv_vsem = false; + bool hdr10_src_primary_changed = false; + unsigned long time_use = 0; + struct timeval start; + struct timeval end; int dump_size = 100; + bool run_control_path = true; + bool vf_changed = true; + char *dvel_provider = NULL; memset(&req, 0, (sizeof(struct provider_aux_req_s))); memset(&el_req, 0, (sizeof(struct provider_aux_req_s))); @@ -7034,8 +7744,8 @@ int dolby_vision_parse_metadata( vf->compHeight : vf->height; } - if (is_meson_tvmode() && !force_stb_mode && vf - && (vf->source_type == VFRAME_SOURCE_TYPE_HDMI)) { + if (is_meson_tvmode() && vf && + vf->source_type == VFRAME_SOURCE_TYPE_HDMI) { req.vf = vf; req.bot_flag = 0; req.aux_buf = NULL; @@ -7043,27 +7753,147 @@ int dolby_vision_parse_metadata( req.dv_enhance_exist = 0; req.low_latency = 0; vf_notify_provider_by_name("dv_vdin", - VFRAME_EVENT_RECEIVER_GET_AUX_DATA, - (void *)&req); - input_mode = INPUT_MODE_HDMI; - if (debug_dolby & 1) - pr_dolby_dbg("vdin0 get aux data %p %x, ll:%d\n", - req.aux_buf, req.aux_size, req.low_latency); + VFRAME_EVENT_RECEIVER_GET_AUX_DATA, + (void *)&req); + input_mode = IN_MODE_HDMI; + + if ((dolby_vision_flags & FLAG_CERTIFICAION) && enable_vf_check) + vf_changed = check_vf_changed(vf); + + /* meta */ + if ((dolby_vision_flags & FLAG_RX_EMP_VSEM) && + vf->emp.size > 0) { + vsem_size = vf->emp.size * VSEM_PKT_SIZE; + memcpy(vsem_if_buf, vf->emp.addr, vsem_size); + if (vsem_if_buf[0] == 0x7f && + vsem_if_buf[10] == 0x46 && + vsem_if_buf[11] == 0xd0) { + dv_vsem = true; + if (!vsem_check(vsem_if_buf, vsem_md_buf)) { + vsem_if_size = vsem_size; + if (!vsem_md_buf[10]) { + req.aux_buf = + &vsem_md_buf[13]; + req.aux_size = + (vsem_md_buf[5] << 8) + + vsem_md_buf[6] + - 6 - 4; + /* cancel vsem, use md */ + /* vsem_if_size = 0; */ + } else { + req.low_latency = 1; + } + } else { + /* emp error, use previous md */ + pr_dolby_dbg("EMP packet error %d\n", + vf->emp.size); + dump_emp = true; + vsem_if_size = 0; + req.aux_buf = NULL; + req.aux_size = + last_total_md_size; + } + } else if (debug_dolby & 4) { + pr_dolby_dbg("EMP packet not DV vsem %d\n", + vf->emp.size); + dump_emp = true; + } + if ((debug_dolby & 4) || dump_emp) { + pr_info("vsem pkt count = %d\n", vf->emp.size); + for (i = 0; i < vsem_size; i += 8) { + pr_info("%02x %02x %02x %02x %02x %02x %02x %02x\n", + vsem_if_buf[i], + vsem_if_buf[i + 1], + vsem_if_buf[i + 2], + vsem_if_buf[i + 3], + vsem_if_buf[i + 4], + vsem_if_buf[i + 5], + vsem_if_buf[i + 6], + vsem_if_buf[i + 7]); + } + } + } + + /* w/t vsif and no dv_vsem */ + if (vf->vsif.size && !dv_vsem) { + memset(vsem_if_buf, 0, VSEM_IF_BUF_SIZE); + memcpy(vsem_if_buf, vf->vsif.addr, vf->vsif.size); + vsem_if_size = vf->vsif.size; + if (debug_dolby & 4) { + pr_info("vsif size = %d\n", vf->vsif.size); + for (i = 0; i < vsem_if_size; i += 8) { + pr_info("%02x %02x %02x %02x %02x %02x %02x %02x\n", + vsem_if_buf[i], + vsem_if_buf[i + 1], + vsem_if_buf[i + 2], + vsem_if_buf[i + 3], + vsem_if_buf[i + 4], + vsem_if_buf[i + 5], + vsem_if_buf[i + 6], + vsem_if_buf[i + 7]); + } + } + } - if ((dolby_vision_flags & FLAG_FORCE_DOVI_LL) - || (req.low_latency == 1)) { + if (debug_dolby & 1) { + if (dv_vsem || vsem_if_size) + pr_dolby_dbg("vdin get %s:%d, md:%p %d,ll:%d,bit %x\n", + dv_vsem ? "vsem" : "vsif", + dv_vsem ? vsem_size : vsem_if_size, + req.aux_buf, req.aux_size, + req.low_latency, + vf->bitdepth); + else + pr_dolby_dbg("vdin get md %p %d,ll:%d,bit %x\n", + req.aux_buf, req.aux_size, + req.low_latency, vf->bitdepth); + } + + /*check vsem_if_buf */ + if (vsem_if_size && + !(vsem_if_buf[0] == 0x81 && + vsem_if_buf[1] == 0x1)) { + /*not vsif, continue to check vsem*/ + if (!(vsem_if_buf[0] == 0x7F && + vsem_if_buf[1] == 0x80 && + vsem_if_buf[10] == 0x46 && + vsem_if_buf[11] == 0xd0 && + vsem_if_buf[12] == 0x00)) { + pr_dolby_error("vsem_if_buf is invalid!\n"); + vsem_if_size = 0; + pr_info("%x %x %x %x %x %x %x %x %x %x %x %x\n", + vsem_if_buf[0], + vsem_if_buf[1], + vsem_if_buf[2], + vsem_if_buf[3], + vsem_if_buf[4], + vsem_if_buf[5], + vsem_if_buf[6], + vsem_if_buf[7], + vsem_if_buf[8], + vsem_if_buf[9], + vsem_if_buf[10], + vsem_if_buf[11]); + } + } + if ((dolby_vision_flags & FLAG_FORCE_DOVI_LL) || + req.low_latency == 1) { src_format = FORMAT_DOVI_LL; src_chroma_format = 0; for (i = 0; i < 2; i++) { - if (md_buf[i] != NULL) + if (md_buf[i]) memset(md_buf[i], 0, MD_BUF_SIZE); - if (comp_buf[i] != NULL) + if (comp_buf[i]) memset(comp_buf[i], 0, COMP_BUF_SIZE); } req.aux_size = 0; req.aux_buf = NULL; - } else if (req.aux_buf && req.aux_size) { - memcpy(md_buf[current_id], req.aux_buf, req.aux_size); + } else if (req.aux_size) { + if (req.aux_buf) { + current_id = current_id ^ 1; + memcpy(md_buf[current_id], + req.aux_buf, req.aux_size); + } src_format = FORMAT_DOVI; } else { if (toggle_mode == 2) @@ -7071,12 +7901,25 @@ int dolby_vision_parse_metadata( if (vf->type & VIDTYPE_VIU_422) src_chroma_format = 1; p_mdc = &vf->prop.master_display_colour; - if (is_hdr10_frame(vf)) { + if (is_hdr10_frame(vf) || force_hdmin_fmt == 1) { src_format = FORMAT_HDR10; /* prepare parameter from hdmi for hdr10 */ p_mdc->luminance[0] *= 10000; - prepare_hdr10_param( - p_mdc, &hdr10_param); + prepare_hdr10_param + (p_mdc, &hdr10_param); + req.dv_enhance_exist = 0; + src_bdp = 12; + } + if (is_meson_tm2_tvmode()) { + if ((src_format != FORMAT_DOVI) && + (is_hlg_frame(vf) || + force_hdmin_fmt == 2)) { + src_format = FORMAT_HLG; + src_bdp = 12; + } + if (src_format == FORMAT_SDR && + !req.dv_enhance_exist) + src_bdp = 12; } } if ((debug_dolby & 4) && req.aux_size) { @@ -7104,9 +7947,8 @@ int dolby_vision_parse_metadata( total_comp_size = last_total_comp_size; } if (debug_dolby & 1) - pr_dolby_dbg( - "frame %d pts %lld, format: %s\n", - frame_count, vf->pts_us64, + pr_dolby_dbg("frame %d, %p, pts %lld, format: %s\n", + frame_count, vf, vf->pts_us64, (src_format == FORMAT_HDR10) ? "HDR10" : ((src_format == FORMAT_DOVI) ? "DOVI" : ((src_format == FORMAT_DOVI_LL) ? "DOVI_LL" : @@ -7114,16 +7956,15 @@ int dolby_vision_parse_metadata( if (toggle_mode == 1) { if (debug_dolby & 2) - pr_dolby_dbg( - "+++ get bl(%p-%lld) +++\n", - vf, vf->pts_us64); + pr_dolby_dbg + ("+++ get bl(%p-%lld) +++\n", + vf, vf->pts_us64); dolby_vision_vf_add(vf, NULL); } } else if (vf && (vf->source_type == VFRAME_SOURCE_TYPE_OTHERS)) { enum vframe_signal_fmt_e fmt; - input_mode = INPUT_MODE_OTT; - + input_mode = IN_MODE_OTT; req.vf = vf; req.bot_flag = 0; req.aux_buf = NULL; @@ -7153,8 +7994,8 @@ int dolby_vision_parse_metadata( req.dv_enhance_exist, dv_provider); - sei = (char *)get_sei_from_src_fmt( - vf, &sei_size); + sei = (char *)get_sei_from_src_fmt + (vf, &sei_size); if (sei && sei_size) { req.aux_buf = sei; req.aux_size = sei_size; @@ -7198,11 +8039,11 @@ int dolby_vision_parse_metadata( md_buf[current_id][i + 5], md_buf[current_id][i + 6], md_buf[current_id][i + 7]); - pr_dolby_dbg("get comp(%d):\n", + pr_dolby_dbg("comp(%d):\n", vf->src_fmt.comp_size); if (vf->src_fmt.comp_size < dump_size) dump_size = - vf->src_fmt.comp_size; + vf->src_fmt.comp_size; for (i = 0; i < dump_size; i += 8) pr_info("%02x %02x %02x %02x %02x %02x %02x %02x\n", comp_buf[current_id][i], @@ -7216,26 +8057,28 @@ int dolby_vision_parse_metadata( } } else { /*no parse or parse failed*/ meta_flag_bl = - parse_sei_and_meta( - vf, &req, - &total_comp_size, - &total_md_size, - &src_format, - &ret_flags, drop_flag); + parse_sei_and_meta + (vf, &req, + &total_comp_size, + &total_md_size, + &src_format, + &ret_flags, drop_flag); } + if (force_mel) + ret_flags = 1; if (ret_flags && req.dv_enhance_exist) { if (!strcmp(dv_provider, "dvbldec")) - vf_notify_provider_by_name( - dv_provider, - VFRAME_EVENT_RECEIVER_DOLBY_BYPASS_EL, - (void *)&req); + vf_notify_provider_by_name + (dv_provider, + VFRAME_EVENT_RECEIVER_DOLBY_BYPASS_EL, + (void *)&req); pr_dolby_dbg("bypass mel\n"); } if (ret_flags == 1) mel_flag = true; if (!is_dv_standard_es(req.dv_enhance_exist, - ret_flags, w)) { + ret_flags, w)) { src_format = FORMAT_SDR; /* dovi_setting.src_format = src_format; */ total_comp_size = 0; @@ -7243,7 +8086,7 @@ int dolby_vision_parse_metadata( src_bdp = 10; bypass_release = true; } - if ((is_meson_tm2_stbmode() || is_meson_sc2()) && + if ((is_meson_tm2_stbmode() || is_meson_sc2()) && (req.dv_enhance_exist && !mel_flag && ((dolby_vision_flags & FLAG_CERTIFICAION) == 0)) && !enable_fel) { @@ -7254,13 +8097,24 @@ int dolby_vision_parse_metadata( src_bdp = 10; bypass_release = true; } - } else if (is_dolby_vision_stb_mode()) + if (is_meson_tvmode() && + (req.dv_enhance_exist && !mel_flag)) { + src_format = FORMAT_SDR; + /* dovi_setting.src_format = src_format; */ + total_comp_size = 0; + total_md_size = 0; + src_bdp = 10; + bypass_release = true; + if (debug_dolby & 1) + pr_dolby_dbg("tv: bypass fel\n"); + } + } else if (is_dolby_vision_stb_mode()) { src_format = dovi_setting.src_format; - else if (is_meson_tvmode()) + } else if (is_meson_tvmode()) { src_format = tv_dovi_setting->src_format; + } - if ((src_format != FORMAT_DOVI) - && is_hdr10_frame(vf)) { + if (src_format != FORMAT_DOVI && is_hdr10_frame(vf)) { src_format = FORMAT_HDR10; /* prepare parameter from SEI for hdr10 */ p_mdc = &vf->prop.master_display_colour; @@ -7270,50 +8124,57 @@ int dolby_vision_parse_metadata( req.dv_enhance_exist = 0; } - if ((src_format != FORMAT_DOVI) - && is_hlg_frame(vf)) { + if (src_format != FORMAT_DOVI && is_hlg_frame(vf)) { src_format = FORMAT_HLG; + if (is_meson_tm2_tvmode()) + src_bdp = 10; } - if ((src_format != FORMAT_DOVI) - && is_hdr10plus_frame(vf)) { + if (src_format != FORMAT_DOVI && is_hdr10plus_frame(vf)) src_format = FORMAT_HDR10PLUS; - } - if ((src_format != FORMAT_DOVI) && - is_mvc_frame(vf)) { + if (src_format != FORMAT_DOVI && is_mvc_frame(vf)) src_format = FORMAT_MVC; + + if ((src_format != FORMAT_CUVA) && + is_cuva_frame(vf)) { + src_format = FORMAT_CUVA; } -#ifdef V2_4 /* TODO: need 962e ? */ - if ((src_format == FORMAT_SDR) - && is_dolby_vision_stb_mode() - && !req.dv_enhance_exist) + if (src_format == FORMAT_SDR && + is_dolby_vision_stb_mode() && + !req.dv_enhance_exist) src_bdp = 10; -#endif - if (((debug_dolby & 1) - || (frame_count == 0)) - && (toggle_mode == 1)) - pr_info( - "DV:[%d,%lld,%d,%s,%d,%d]\n", - frame_count, vf->pts_us64, src_bdp, - (src_format == FORMAT_HDR10) ? "HDR10" : - (src_format == FORMAT_DOVI ? "DOVI" : - (src_format == FORMAT_HLG ? "HLG" : - (src_format == FORMAT_HDR10PLUS ? "HDR10+" : - (req.dv_enhance_exist ? "DOVI (el meta)" : "SDR")))), - req.aux_size, req.dv_enhance_exist); - if ((src_format != FORMAT_DOVI) - && !req.dv_enhance_exist) + + if (src_format == FORMAT_SDR && + is_meson_tvmode() && + !req.dv_enhance_exist) + src_bdp = 10; + + if (((debug_dolby & 1) || frame_count == 0) && toggle_mode == 1) + pr_info + ("DV:[%d,%lld,%d,%s,%d,%d]\n", + frame_count, vf->pts_us64, src_bdp, + (src_format == FORMAT_HDR10) ? "HDR10" : + (src_format == FORMAT_DOVI ? "DOVI" : + (src_format == FORMAT_HLG ? "HLG" : + (src_format == FORMAT_HDR10PLUS ? "HDR10+" : + (src_format == FORMAT_CUVA ? "CUVA" : + (req.dv_enhance_exist ? "DOVI (el meta)" : "SDR"))))), + req.aux_size, req.dv_enhance_exist); + if (src_format != FORMAT_DOVI && !req.dv_enhance_exist) memset(&req, 0, sizeof(req)); - if (req.dv_enhance_exist && - (toggle_mode == 1) && - (!(is_meson_sc2() && !enable_fel))) { + + /* check dvel decoder is active, if active, should */ + /* get/put el data, otherwise, dvbl is stuck */ + dvel_provider = vf_get_provider_name(DVEL_RECV_NAME); + if (req.dv_enhance_exist && toggle_mode == 1 && + dvel_provider && !strcmp(dvel_provider, "dveldec")) { el_vf = dvel_vf_get(); - if (el_vf && - ((el_vf->pts_us64 == vf->pts_us64) - || !(dolby_vision_flags & FLAG_CHECK_ES_PTS))) { + if (el_vf && (el_vf->pts_us64 == vf->pts_us64 || + !(dolby_vision_flags & + FLAG_CHECK_ES_PTS))) { if (debug_dolby & 2) pr_dolby_dbg("+++ get bl(%p-%lld) with el(%p-%lld) +++\n", vf, vf->pts_us64, @@ -7326,18 +8187,20 @@ int dolby_vision_parse_metadata( el_req.bot_flag = 0; el_req.aux_buf = NULL; el_req.aux_size = 0; - vf_notify_provider_by_name("dveldec", + if (!strcmp(dv_provider, "dvbldec")) + vf_notify_provider_by_name + ("dveldec", VFRAME_EVENT_RECEIVER_GET_AUX_DATA, - (void *)&el_req); - if (el_req.aux_buf - && el_req.aux_size) { + (void *)&el_req); + if (el_req.aux_buf && + el_req.aux_size) { meta_flag_el = - parse_sei_and_meta( - el_vf, &el_req, - &el_comp_size, - &el_md_size, - &src_format, - &ret_flags, drop_flag); + parse_sei_and_meta + (el_vf, &el_req, + &el_comp_size, + &el_md_size, + &src_format, + &ret_flags, drop_flag); } if (!meta_flag_el) { total_comp_size = @@ -7348,20 +8211,20 @@ int dolby_vision_parse_metadata( } /* force set format as DOVI*/ /* when meta data error */ - if (meta_flag_el - && el_req.aux_buf - && el_req.aux_size) + if (meta_flag_el && + el_req.aux_buf && + el_req.aux_size) src_format = FORMAT_DOVI; if (debug_dolby & 2) - pr_dolby_dbg( - "meta data el mode: el_src_format: %d, meta_flag_el: %d\n", - src_format, - meta_flag_el); + pr_dolby_dbg + ("el mode:src_fmt:%d,meta_flag_el:%d\n", + src_format, + meta_flag_el); if (meta_flag_el && frame_count == 0) - pr_dolby_dbg( - "DOVI el meta mode, but parser meta error, el vf %p, size:%d\n", - el_req.aux_buf, - el_req.aux_size); + pr_info + ("el mode:parser err,aux %p,size:%d\n", + el_req.aux_buf, + el_req.aux_size); } dolby_vision_vf_add(vf, el_vf); el_flag = 1; @@ -7369,25 +8232,23 @@ int dolby_vision_parse_metadata( el_halfsize_flag = 0; } else { if (!el_vf) - pr_dolby_error( - "bl(%p-%lld) not found el\n", - vf, vf->pts_us64); + pr_dolby_error + ("bl(%p-%lld) not found el\n", + vf, vf->pts_us64); else - pr_dolby_error( - "bl(%p-%lld) not found el(%p-%lld)\n", - vf, vf->pts_us64, - el_vf, el_vf->pts_us64); + pr_dolby_error + ("bl(%p-%lld) not found el(%p-%lld)\n", + vf, vf->pts_us64, + el_vf, el_vf->pts_us64); } } else if (toggle_mode == 1) { if (debug_dolby & 2) - pr_dolby_dbg( - "+++ get bl(%p-%lld) +++\n", - vf, vf->pts_us64); + pr_dolby_dbg("+++ get bl(%p-%lld) +++\n", + vf, vf->pts_us64); dolby_vision_vf_add(vf, NULL); } - if ((toggle_mode == 0) - && req.dv_enhance_exist) + if (req.dv_enhance_exist) el_flag = 1; if (toggle_mode != 2) { @@ -7405,13 +8266,12 @@ int dolby_vision_parse_metadata( mel_flag = mel_mode; if (debug_dolby & 2) pr_dolby_dbg("update el_flag %d, melFlag %d\n", - el_flag, mel_flag); + el_flag, mel_flag); meta_flag_bl = 0; } - if ((is_meson_tm2_stbmode() || is_meson_sc2()) && - (el_flag && !mel_flag && - ((dolby_vision_flags & FLAG_CERTIFICAION) == 0)) && + if (el_flag && !mel_flag && + ((dolby_vision_flags & FLAG_CERTIFICAION) == 0) && !enable_fel) { el_flag = 0; dolby_vision_el_disable = true; @@ -7420,27 +8280,96 @@ int dolby_vision_parse_metadata( el_flag = 0; mel_flag = 0; } - if ((src_format == FORMAT_DOVI) - && meta_flag_bl && meta_flag_el) { + if (src_format == FORMAT_DOVI && + meta_flag_bl && meta_flag_el) { /* dovi frame no meta or meta error */ /* use old setting for this frame */ pr_dolby_dbg("no meta or meta err!\n"); return -1; } - } + } else if (vf && (vf->source_type == VFRAME_SOURCE_TYPE_HDMI) && + is_meson_tm2_stbmode() && hdmi_to_stb_policy) { + req.vf = vf; + req.bot_flag = 0; + req.aux_buf = NULL; + req.aux_size = 0; + req.dv_enhance_exist = 0; + req.low_latency = 0; + if (!strcmp(dv_provider, "dv_vdin")) + vf_notify_provider_by_name(dv_provider, + VFRAME_EVENT_RECEIVER_GET_AUX_DATA, + (void *)&req); + if (req.low_latency == 1) { + src_format = FORMAT_HDR10; + if (!vf_is_hdr10(vf)) { + vf->signal_type &= 0xff0000ff; + vf->signal_type |= 0x00091000; + } + p_mdc = &vf->prop.master_display_colour; + prepare_hdr10_param(p_mdc, &hdr10_param); + src_bdp = 10; + req.aux_size = 0; + req.aux_buf = NULL; + } else if (req.aux_size) { + if (req.aux_buf) { + current_id = current_id ^ 1; + memcpy(md_buf[current_id], + req.aux_buf, req.aux_size); + } + src_format = FORMAT_DOVI; + input_mode = IN_MODE_HDMI; + src_bdp = 12; + meta_flag_bl = 0; + el_flag = 0; + mel_flag = 0; + if ((debug_dolby & 4) && dump_enable) { + pr_dolby_dbg("metadata(%d):\n", req.aux_size); + for (i = 0; i < req.aux_size; i += 8) + pr_info("\t%02x %02x %02x %02x %02x %02x %02x %02x\n", + md_buf[current_id][i], + md_buf[current_id][i + 1], + md_buf[current_id][i + 2], + md_buf[current_id][i + 3], + md_buf[current_id][i + 4], + md_buf[current_id][i + 5], + md_buf[current_id][i + 6], + md_buf[current_id][i + 7]); + } + } else { + if (toggle_mode == 2) + src_format = dovi_setting.src_format; - if ((src_format == FORMAT_DOVI) - && meta_flag_bl && meta_flag_el) { - /* dovi frame no meta or meta error */ - /* use old setting for this frame */ - pr_dolby_dbg("no meta or meta err!\n"); + if (is_hdr10_frame(vf) || force_hdmin_fmt == 1) { + src_format = FORMAT_HDR10; + p_mdc = &vf->prop.master_display_colour; + if (p_mdc->present_flag) + p_mdc->luminance[0] *= 10000; + prepare_hdr10_param(p_mdc, &hdr10_param); + } + + if (is_hlg_frame(vf) || force_hdmin_fmt == 2) + src_format = FORMAT_HLG; + + if (is_hdr10plus_frame(vf)) + src_format = FORMAT_HDR10PLUS; + + src_bdp = 10; + } + total_md_size = req.aux_size; + total_comp_size = 0; + } + + if (src_format == FORMAT_DOVI && meta_flag_bl && meta_flag_el) { + /* dovi frame no meta or meta error */ + /* use old setting for this frame */ + pr_dolby_dbg("no meta or meta err!\n"); return -1; } /* if not DOVI, release metadata_parser */ - if ((src_format != FORMAT_DOVI) - && metadata_parser - && !bypass_release) { + if (vf && src_format != FORMAT_DOVI && + metadata_parser && + !bypass_release) { if (p_funcs_stb) p_funcs_stb->metadata_parser_release(); if (p_funcs_tv) @@ -7464,43 +8393,44 @@ int dolby_vision_parse_metadata( dolby_vision_request_mode = 0xff; } current_mode = dolby_vision_mode; - if (dolby_vision_policy_process( - ¤t_mode, check_format)) { + if (dolby_vision_policy_process + (¤t_mode, check_format)) { if (!dolby_vision_wait_init) dolby_vision_set_toggle_flag(1); - pr_dolby_dbg( - "[dolby_vision_parse_metadata] output change from %d to %d\n", - dolby_vision_mode, current_mode); + pr_info("[%s]output change from %d to %d\n", + __func__, dolby_vision_mode, current_mode); dolby_vision_target_mode = current_mode; dolby_vision_mode = current_mode; if (is_dolby_vision_stb_mode()) new_dovi_setting.mode_changed = 1; - pr_dolby_dbg("[dolby_vision_parse_metadata] output change from %d to %d(%d, %p, %d)\n", - dolby_vision_mode, current_mode, - toggle_mode, vf, src_format); + pr_dolby_dbg("[%s]output change from %d to %d(%d, %p, %d)\n", + __func__, dolby_vision_mode, current_mode, + toggle_mode, vf, src_format); } else { dolby_vision_target_mode = dolby_vision_mode; } - if ((get_hdr_module_status(VD1_PATH) != HDR_MODULE_ON) - && (check_format == FORMAT_SDR)) { + if (get_hdr_module_status(VD1_PATH) != HDR_MODULE_ON && + check_format == FORMAT_SDR) { /* insert 2 SDR frames before send DOVI */ - if (((dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL) - || (dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_IPT)) - && ((last_current_format == FORMAT_HLG) - || (last_current_format == FORMAT_HDR10PLUS))) { + if ((dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL || + dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_IPT) && + (last_current_format == FORMAT_HLG || + last_current_format == FORMAT_HDR10PLUS)) { bypass_frame = 0; - pr_dolby_dbg("[dolby_vision_parse_metadata] source transition from %d to %d\n", - last_current_format, check_format); + pr_dolby_dbg + ("[%s] source transition from %d to %d\n", + __func__, last_current_format, check_format); } last_current_format = check_format; } - if ((bypass_frame >= 0) && (bypass_frame < MIN_TRANSITION_DELAY)) { + if (bypass_frame >= 0 && bypass_frame < MIN_TRANSITION_DELAY) { dolby_vision_mode = DOLBY_VISION_OUTPUT_MODE_BYPASS; bypass_frame++; - } else + } else { bypass_frame = -1; + } if (dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_BYPASS) { new_dovi_setting.video_width = 0; @@ -7521,101 +8451,290 @@ int dolby_vision_parse_metadata( } /* TV core */ - if (is_meson_tvmode() && !force_stb_mode) { - if (src_format != tv_dovi_setting->src_format) + if (is_meson_tvmode()) { + if (src_format != tv_dovi_setting->src_format || + (dolby_vision_flags & FLAG_CERTIFICAION)) { pq_config_set_flag = false; + best_pq_config_set_flag = false; + } if (!pq_config_set_flag) { - if ((dolby_vision_flags & FLAG_FORCE_DOVI_LL) - || (req.low_latency == 1)) - memcpy(&(((struct pq_config_s *) - pq_config_fake)->target_display_config), - &def_tgt_display_cfg_ll, + if (debug_dolby & 2) + pr_dolby_dbg("update def_tgt_display_cfg\n"); + if (!load_bin_config) { + if ((dolby_vision_flags & FLAG_FORCE_DOVI_LL) || + req.low_latency == 1) { + memcpy(&(((struct pq_config *) + pq_config_fake)->tdc), + DV_cfg_ll[cfg_ll_id], + sizeof(def_tgt_display_cfg_ll)); - else - memcpy(&(((struct pq_config_s *) - pq_config_fake)->target_display_config), - &def_tgt_display_cfg, - sizeof(def_tgt_display_cfg)); + } else { + /* cert: need cfg_id = 0 */ + if (dolby_vision_flags & + FLAG_CERTIFICAION) + cfg_id = 0; + else + cfg_id = 1; + + memcpy(&(((struct pq_config *) + pq_config_fake)->tdc), + DV_cfg[cfg_id], + sizeof(def_tgt_display_cfg)); + /* cert: need dm31_avail=0*/ + if (dolby_vision_flags & + FLAG_CERTIFICAION) + ((struct pq_config *) + pq_config_fake)->tdc.dm31_avail = + 0; + } + } pq_config_set_flag = true; } - calculate_panel_max_pq( - vinfo, - &(((struct pq_config_s *) - pq_config_fake)->target_display_config)); - tv_dovi_setting->video_width = w << 16; - tv_dovi_setting->video_height = h << 16; - ((struct pq_config_s *) - pq_config_fake)->target_display_config.tuningMode = - dolby_vision_tunning_mode; + if (force_best_pq && !best_pq_config_set_flag) { + pr_dolby_dbg("update best def_tgt_display_cfg\n"); + memcpy(&(((struct pq_config *) + pq_config_fake)->tdc), + &def_tgt_display_cfg_bestpq, + sizeof(def_tgt_display_cfg_bestpq)); + best_pq_config_set_flag = true; + + if (p_funcs_tv && p_funcs_tv->tv_control_path) + p_funcs_tv->tv_control_path + (FORMAT_INVALID, 0, + NULL, 0, + NULL, 0, + 0, 0, + SIGNAL_RANGE_SMPTE, + NULL, NULL, + 0, + NULL, + NULL, + NULL, 0, + NULL, + NULL); + } + calculate_panel_max_pq(vinfo, + &(((struct pq_config *) + pq_config_fake)->tdc)); + + ((struct pq_config *) + pq_config_fake)->tdc.tuning_mode = + dolby_vision_tuning_mode; if (dolby_vision_flags & FLAG_DISABLE_COMPOSER) { - ((struct pq_config_s *)pq_config_fake) - ->target_display_config.tuningMode |= - TUNINGMODE_EL_FORCEDDISABLE; + ((struct pq_config *)pq_config_fake) + ->tdc.tuning_mode |= + TUNING_MODE_EL_FORCE_DISABLE; el_halfsize_flag = 0; - } else - ((struct pq_config_s *)pq_config_fake) - ->target_display_config.tuningMode &= - (~TUNINGMODE_EL_FORCEDDISABLE); -#ifdef V1_5 - /* disable global dimming */ - if (dolby_vision_flags & FLAG_CERTIFICAION) - ((struct pq_config_s *)pq_config_fake) - ->target_display_config.tuningMode &= - (~TUNINGMODE_EXTLEVEL4_DISABLE); - else - ((struct pq_config_s *)pq_config_fake) - ->target_display_config.tuningMode |= - TUNINGMODE_EXTLEVEL4_DISABLE; - - if (src_format != tv_dovi_setting->src_format) { - if (p_funcs_tv && (p_funcs_tv->tv_control_path)) - p_funcs_tv->tv_control_path( - FORMAT_INVALID, 0, + } else { + ((struct pq_config *)pq_config_fake) + ->tdc.tuning_mode &= + (~TUNING_MODE_EL_FORCE_DISABLE); + } + if ((dolby_vision_flags & FLAG_CERTIFICAION) && sdr_ref_mode) { + ((struct pq_config *) + pq_config_fake)->tdc.ambient_config.ambient = + 0; + ((struct pq_config *)pq_config_fake) + ->tdc.ref_mode_dark_id = 0; + ((struct pq_config *)pq_config_fake) + ->tdc.dm31_avail = 1; + } + if (is_hdr10_src_primary_changed()) { + hdr10_src_primary_changed = true; + pr_dolby_dbg("hdr10 src primary changed!\n"); + } + if (src_format != tv_dovi_setting->src_format || + tv_dovi_setting->video_width != w || + tv_dovi_setting->video_height != h || + hdr10_src_primary_changed) { + pr_dolby_dbg("reset control_path fmt %d->%d, w %d->%d, h %d->%d\n", + tv_dovi_setting->src_format, src_format, + tv_dovi_setting->video_width, w, + tv_dovi_setting->video_height, h); + /*for hdmi in cert*/ + if (dolby_vision_flags & FLAG_CERTIFICAION) + vf_changed = true; + if (p_funcs_tv && p_funcs_tv->tv_control_path) + p_funcs_tv->tv_control_path + (FORMAT_INVALID, 0, NULL, 0, NULL, 0, 0, 0, - SIG_RANGE_SMPTE, + SIGNAL_RANGE_SMPTE, NULL, NULL, 0, NULL, + NULL, + NULL, 0, + NULL, NULL); } -#endif - if ((!p_funcs_tv) || (!p_funcs_tv->tv_control_path)) + tv_dovi_setting->video_width = w << 16; + tv_dovi_setting->video_height = h << 16; + if (!p_funcs_tv || !p_funcs_tv->tv_control_path) return -1; - flag = p_funcs_tv->tv_control_path( - src_format, input_mode, - comp_buf[current_id], total_comp_size, - md_buf[current_id], total_md_size, - src_bdp, - src_chroma_format, - SIG_RANGE_SMPTE, /* bit/chroma/range */ - (struct pq_config_s *)pq_config_fake, &menu_param, - (!el_flag) || - (dolby_vision_flags & FLAG_DISABLE_COMPOSER), - &hdr10_param, - tv_dovi_setting); - if (flag >= 0) { - if (input_mode == INPUT_MODE_HDMI) { - if (h > 1080) - tv_dovi_setting->core1_reg_lut[1] = - 0x0000000100000043; - else - tv_dovi_setting->core1_reg_lut[1] = - 0x0000000100000042; + if (!(dolby_vision_flags & FLAG_CERTIFICAION) && + (strstr(cfg_info[cur_pic_mode].pic_mode_name, "dark") || + strstr(cfg_info[cur_pic_mode].pic_mode_name, "Dark") || + strstr(cfg_info[cur_pic_mode].pic_mode_name, "DARK"))) { + memcpy(tv_input_info, + brightness_off, + sizeof(brightness_off)); + } else { + memset(tv_input_info, 0, sizeof(brightness_off)); + } + + /*config source fps and gd_rf_adjust, dmcfg_id*/ + tv_input_info->content_fps = content_fps * (1 << 16); + tv_input_info->gd_rf_adjust = gd_rf_adjust; + + if (debug_dolby & 0x400) + do_gettimeofday(&start); + + /*for hdmi in cert, only run control_path for different frame*/ + if ((dolby_vision_flags & FLAG_CERTIFICAION) && + !vf_changed && input_mode == IN_MODE_HDMI) { + run_control_path = false; + } + if (run_control_path) { + flag = p_funcs_tv->tv_control_path + (src_format, input_mode, + comp_buf[current_id], + (src_format == FORMAT_DOVI) ? + total_comp_size : 0, + md_buf[current_id], + (src_format == FORMAT_DOVI) ? total_md_size : 0, + src_bdp, + src_chroma_format, + SIGNAL_RANGE_SMPTE, /* bit/chroma/range */ + (struct pq_config *)pq_config_fake, &menu_param, + (!el_flag) || + (dolby_vision_flags & FLAG_DISABLE_COMPOSER), + &hdr10_param, + tv_dovi_setting, + vsem_if_buf, vsem_if_size, + ambient_update ? &ambient_config_new : + ((ambient_test_mode != 0 && toggle_mode == 1 && + frame_count < AMBIENT_CFG_FRAMES) ? + &ambient_test_cfg[frame_count] : + (struct ambient_cfg_s *)NULL), + tv_input_info); + + if (debug_dolby & 0x400) { + do_gettimeofday(&end); + time_use = (end.tv_sec - start.tv_sec) * + 1000000 + (end.tv_usec - start.tv_usec); + pr_info("controlpath time: %5ld us\n", + time_use); + } + if (flag >= 0) { + if (input_mode == IN_MODE_HDMI) { + u64 *p = + &tv_dovi_setting->core1_reg_lut[1]; + if (h > 1080) + *p = 0x0000000100000043; + else + *p = 0x0000000100000042; + if (get_video_reverse() && + (src_format == FORMAT_DOVI || + src_format == FORMAT_DOVI_LL)) { + u32 coeff[3][3]; + + p = + &tv_dovi_setting->core1_reg_lut[9]; + coeff[0][1] = + (p[0] >> 16) & 0xffff; + coeff[0][2] = p[1] & 0xffff; + coeff[1][1] = p[2] & 0xffff; + coeff[1][2] = + (p[2] >> 16) & 0xffff; + coeff[2][1] = + (p[3] >> 16) & 0xffff; + coeff[2][2] = p[4] & 0xffff; + + p[0] = (p[0] & + 0xffffffff0000ffff) | + (coeff[0][2] << 16); + p[1] = (p[1] & + 0xffffffffffff0000) | + coeff[0][1]; + p[2] = (p[2] & + 0xffffffff00000000) | + (coeff[1][1] << 16) | + coeff[1][2]; + p[3] = (p[3] & + 0xffffffff0000ffff) | + (coeff[2][2] << 16); + p[4] = (p[4] & + 0xffffffffffff0000) | + coeff[2][1]; + } + } else { + u64 *p = + &tv_dovi_setting->core1_reg_lut[1]; + if (src_format == FORMAT_HDR10) + *p = 0x000000010000404c; + else if (el_halfsize_flag) + *p = 0x000000010000004c; + else + *p = 0x0000000100000044; + } + /* enable CRC */ + if ((dolby_vision_flags & FLAG_CERTIFICAION) && + !(dolby_vision_flags & FLAG_DISABLE_CRC)) + tv_dovi_setting->core1_reg_lut[3] = + 0x000000ea00000001; + tv_dovi_setting->src_format = src_format; + tv_dovi_setting->el_flag = el_flag; + tv_dovi_setting + ->el_halfsize_flag = el_halfsize_flag; + tv_dovi_setting->video_width = w; + tv_dovi_setting->video_height = h; + tv_dovi_setting + ->input_mode = input_mode; + tv_dovi_setting_change_flag = true; + dovi_setting_video_flag = video_frame; + + if (debug_dolby & 1) { + if (el_flag) + pr_dolby_dbg + ("tv %s-%d:flag=%x,md=%d,comp=%d\n", + input_mode == IN_MODE_HDMI ? + "hdmi" : "ott", + src_format, + flag, + total_md_size, + total_comp_size); + else + pr_dolby_dbg + ("tv setting %s-%d:flag=%x,md=%d\n", + input_mode == IN_MODE_HDMI ? + "hdmi" : "ott", + src_format, + flag, + total_md_size); + } + dump_tv_setting(tv_dovi_setting, + frame_count, debug_dolby); + el_mode = el_flag; + mel_mode = mel_flag; + ret = 0; /* setting updated */ } else { - if (src_format == FORMAT_HDR10) - tv_dovi_setting->core1_reg_lut[1] = - 0x000000010000404c; - else if (el_halfsize_flag) - tv_dovi_setting->core1_reg_lut[1] = - 0x000000010000004c; - else - tv_dovi_setting->core1_reg_lut[1] = - 0x0000000100000044; + tv_dovi_setting->video_width = 0; + tv_dovi_setting->video_height = 0; + pr_dolby_error("tv_control_path() failed\n"); } + } else { /*for cert: vf no change, not run cp*/ + if (h > 1080) + tv_dovi_setting->core1_reg_lut[1] = + 0x0000000100000043; + else + tv_dovi_setting->core1_reg_lut[1] = + 0x0000000100000042; + /* enable CRC */ - if (dolby_vision_flags & FLAG_CERTIFICAION) + if ((dolby_vision_flags & FLAG_CERTIFICAION) && + !(dolby_vision_flags & FLAG_DISABLE_CRC)) tv_dovi_setting->core1_reg_lut[3] = 0x000000ea00000001; tv_dovi_setting->src_format = src_format; @@ -7628,39 +8747,28 @@ int dolby_vision_parse_metadata( ->input_mode = input_mode; tv_dovi_setting_change_flag = true; dovi_setting_video_flag = video_frame; - if (debug_dolby & 1) { - if (el_flag) - pr_dolby_dbg("tv setting %s-%d: flag=%02x,md=%d,comp=%d\n", - input_mode == INPUT_MODE_HDMI ? - "hdmi" : "ott", - src_format, - flag, - total_md_size, - total_comp_size); - else - pr_dolby_dbg("tv setting %s-%d: flag=%02x,md=%d\n", - input_mode == INPUT_MODE_HDMI ? - "hdmi" : "ott", - src_format, - flag, - total_md_size); - } - dump_tv_setting(tv_dovi_setting, - frame_count, debug_dolby); - el_mode = el_flag; - mel_mode = mel_flag; - ret = 0; /* setting updated */ - } else { - tv_dovi_setting->video_width = 0; - tv_dovi_setting->video_height = 0; - pr_dolby_error("tv_control_path() failed\n"); + ret = 0; } return ret; } + /* update input mode for HDMI in STB core */ + if (is_meson_tm2_stbmode()) { + tv_dovi_setting->input_mode = input_mode; + if (is_meson_tm2_stb_hdmimode()) { + tv_dovi_setting->src_format = src_format; + tv_dovi_setting->video_width = w; + tv_dovi_setting->video_height = h; + tv_dovi_setting->el_flag = false; + tv_dovi_setting->el_halfsize_flag = false; + dolby_vision_run_mode_delay = RUN_MODE_DELAY; + } else { + dolby_vision_run_mode_delay = 0; + } + } /* check dst format */ - if ((dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL) - || (dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_IPT)) + if (dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_IPT_TUNNEL || + dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_IPT) dst_format = FORMAT_DOVI; else if (dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_HDR10) dst_format = FORMAT_HDR10; @@ -7670,11 +8778,11 @@ int dolby_vision_parse_metadata( /* STB core */ /* check target luminance */ graphic_min = dolby_vision_graphic_min; - if (dolby_vision_graphic_max != 0) + if (dolby_vision_graphic_max != 0) { graphic_max = dolby_vision_graphic_max; - else { + } else { if ((dolby_vision_flags & FLAG_FORCE_DOVI_LL) || - (dolby_vision_ll_policy >= DOLBY_VISION_LL_YUV422)) { + dolby_vision_ll_policy >= DOLBY_VISION_LL_YUV422) { graphic_max = dv_target_graphics_LL_max [src_format][dst_format]; @@ -7683,9 +8791,8 @@ int dolby_vision_parse_metadata( dv_target_graphics_max [src_format][dst_format]; } - if (dv_graphic_blend_test && dst_format == FORMAT_HDR10) { + if (dv_graphic_blend_test && dst_format == FORMAT_HDR10) graphic_max = dv_HDR10_graphics_max; - } } if (dolby_vision_flags & FLAG_USE_SINK_MIN_MAX) { @@ -7734,17 +8841,17 @@ int dolby_vision_parse_metadata( dolby_vision_target_max[2][1] = target_lumin_max; } else { - memcpy( - dolby_vision_target_max, - dolby_vision_default_max, - sizeof(dolby_vision_target_max)); + memcpy(dolby_vision_target_max, + dolby_vision_default_max, + sizeof(dolby_vision_target_max)); } } - if (is_osd_off) - graphic_min = graphic_max = 0; + if (is_osd_off) { + graphic_min = 0; + graphic_max = 0; + } -#ifdef V2_4 if (new_dovi_setting.video_width && new_dovi_setting.video_height) { /* Toggle multiple frames in one vsync case: */ /* new_dovi_setting.video_width will be available, but not be applied */ @@ -7757,102 +8864,100 @@ int dolby_vision_parse_metadata( cur_dst_format = dovi_setting.dst_format; } - if ((src_format != cur_src_format) || - (dst_format != cur_dst_format)) { - pr_dolby_dbg( - "reset control path: format changed: src:%d->%d, dst:%d-%d, frame_count:%d, dolby_vision_flags:0x%x\n", - cur_src_format, src_format, - cur_dst_format, dst_format, - frame_count, dolby_vision_flags); - p_funcs_stb->control_path( - FORMAT_INVALID, 0, - comp_buf[current_id], 0, - md_buf[current_id], 0, - 0, 0, 0, SIG_RANGE_SMPTE, - 0, 0, 0, 0, - 0, - &hdr10_param, - &new_dovi_setting); + if (src_format != cur_src_format || + dst_format != cur_dst_format) { + pr_dolby_dbg + ("reset: src:%d-%d, dst:%d-%d, frame_count:%d, flags:0x%x\n", + cur_src_format, src_format, + cur_dst_format, dst_format, + frame_count, dolby_vision_flags); + p_funcs_stb->control_path + (FORMAT_INVALID, 0, + comp_buf[current_id], 0, + md_buf[current_id], 0, + 0, 0, 0, SIGNAL_RANGE_SMPTE, + 0, 0, 0, 0, + 0, + &hdr10_param, + &new_dovi_setting); } if (!vsvdb_config_set_flag) { memset(&new_dovi_setting.vsvdb_tbl[0], - 0, sizeof(new_dovi_setting.vsvdb_tbl)); + 0, sizeof(new_dovi_setting.vsvdb_tbl)); new_dovi_setting.vsvdb_len = 0; new_dovi_setting.vsvdb_changed = 1; vsvdb_config_set_flag = true; } - if ((dolby_vision_flags & - FLAG_DISABLE_LOAD_VSVDB) == 0) { + if ((dolby_vision_flags & FLAG_DISABLE_LOAD_VSVDB) == 0) { /* check if vsvdb is changed */ if (vinfo && vinfo->vout_device && - vinfo->vout_device->dv_info && - (vinfo->vout_device->dv_info->ieeeoui == 0x00d046) - && (vinfo->vout_device->dv_info - ->block_flag == CORRECT)) { + vinfo->vout_device->dv_info && + vinfo->vout_device->dv_info->ieeeoui == 0x00d046 && + vinfo->vout_device->dv_info->block_flag == CORRECT) { if (new_dovi_setting.vsvdb_len != vinfo->vout_device->dv_info->length + 1) new_dovi_setting.vsvdb_changed = 1; - else if (memcmp(&new_dovi_setting.vsvdb_tbl[0], - &vinfo->vout_device->dv_info->rawdata[0], - vinfo->vout_device->dv_info->length + 1)) + else if (memcmp + (&new_dovi_setting.vsvdb_tbl[0], + &vinfo->vout_device->dv_info->rawdata[0], + vinfo->vout_device->dv_info->length + 1)) new_dovi_setting.vsvdb_changed = 1; memset(&new_dovi_setting.vsvdb_tbl[0], - 0, sizeof(new_dovi_setting.vsvdb_tbl)); + 0, sizeof(new_dovi_setting.vsvdb_tbl)); memcpy(&new_dovi_setting.vsvdb_tbl[0], - &vinfo->vout_device->dv_info->rawdata[0], - vinfo->vout_device->dv_info->length + 1); + &vinfo->vout_device->dv_info->rawdata[0], + vinfo->vout_device->dv_info->length + 1); new_dovi_setting.vsvdb_len = vinfo->vout_device->dv_info->length + 1; - if (new_dovi_setting.vsvdb_changed - && new_dovi_setting.vsvdb_len) { + if (new_dovi_setting.vsvdb_changed && + new_dovi_setting.vsvdb_len) { int k = 0; - pr_dolby_dbg( - "new vsvdb[%d]:\n", - new_dovi_setting.vsvdb_len); - pr_dolby_dbg( - "---%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x\n", - new_dovi_setting.vsvdb_tbl[k + 0], - new_dovi_setting.vsvdb_tbl[k + 1], - new_dovi_setting.vsvdb_tbl[k + 2], - new_dovi_setting.vsvdb_tbl[k + 3], - new_dovi_setting.vsvdb_tbl[k + 4], - new_dovi_setting.vsvdb_tbl[k + 5], - new_dovi_setting.vsvdb_tbl[k + 6], - new_dovi_setting.vsvdb_tbl[k + 7]); + pr_dolby_dbg("new vsvdb[%d]:\n", + new_dovi_setting.vsvdb_len); + pr_dolby_dbg + ("%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n", + new_dovi_setting.vsvdb_tbl[k + 0], + new_dovi_setting.vsvdb_tbl[k + 1], + new_dovi_setting.vsvdb_tbl[k + 2], + new_dovi_setting.vsvdb_tbl[k + 3], + new_dovi_setting.vsvdb_tbl[k + 4], + new_dovi_setting.vsvdb_tbl[k + 5], + new_dovi_setting.vsvdb_tbl[k + 6], + new_dovi_setting.vsvdb_tbl[k + 7]); k += 8; - pr_dolby_dbg( - "---%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x\n", - new_dovi_setting.vsvdb_tbl[k + 0], - new_dovi_setting.vsvdb_tbl[k + 1], - new_dovi_setting.vsvdb_tbl[k + 2], - new_dovi_setting.vsvdb_tbl[k + 3], - new_dovi_setting.vsvdb_tbl[k + 4], - new_dovi_setting.vsvdb_tbl[k + 5], - new_dovi_setting.vsvdb_tbl[k + 6], - new_dovi_setting.vsvdb_tbl[k + 7]); + pr_dolby_dbg + ("%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n", + new_dovi_setting.vsvdb_tbl[k + 0], + new_dovi_setting.vsvdb_tbl[k + 1], + new_dovi_setting.vsvdb_tbl[k + 2], + new_dovi_setting.vsvdb_tbl[k + 3], + new_dovi_setting.vsvdb_tbl[k + 4], + new_dovi_setting.vsvdb_tbl[k + 5], + new_dovi_setting.vsvdb_tbl[k + 6], + new_dovi_setting.vsvdb_tbl[k + 7]); k += 8; - pr_dolby_dbg( - "---%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x\n", - new_dovi_setting.vsvdb_tbl[k + 0], - new_dovi_setting.vsvdb_tbl[k + 1], - new_dovi_setting.vsvdb_tbl[k + 2], - new_dovi_setting.vsvdb_tbl[k + 3], - new_dovi_setting.vsvdb_tbl[k + 4], - new_dovi_setting.vsvdb_tbl[k + 5], - new_dovi_setting.vsvdb_tbl[k + 6], - new_dovi_setting.vsvdb_tbl[k + 7]); + pr_dolby_dbg + ("%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n", + new_dovi_setting.vsvdb_tbl[k + 0], + new_dovi_setting.vsvdb_tbl[k + 1], + new_dovi_setting.vsvdb_tbl[k + 2], + new_dovi_setting.vsvdb_tbl[k + 3], + new_dovi_setting.vsvdb_tbl[k + 4], + new_dovi_setting.vsvdb_tbl[k + 5], + new_dovi_setting.vsvdb_tbl[k + 6], + new_dovi_setting.vsvdb_tbl[k + 7]); k += 8; - pr_dolby_dbg( - "---%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x\n", - new_dovi_setting.vsvdb_tbl[k + 0], - new_dovi_setting.vsvdb_tbl[k + 1], - new_dovi_setting.vsvdb_tbl[k + 2], - new_dovi_setting.vsvdb_tbl[k + 3], - new_dovi_setting.vsvdb_tbl[k + 4], - new_dovi_setting.vsvdb_tbl[k + 5], - new_dovi_setting.vsvdb_tbl[k + 6], - new_dovi_setting.vsvdb_tbl[k + 7]); + pr_dolby_dbg + ("%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n", + new_dovi_setting.vsvdb_tbl[k + 0], + new_dovi_setting.vsvdb_tbl[k + 1], + new_dovi_setting.vsvdb_tbl[k + 2], + new_dovi_setting.vsvdb_tbl[k + 3], + new_dovi_setting.vsvdb_tbl[k + 4], + new_dovi_setting.vsvdb_tbl[k + 5], + new_dovi_setting.vsvdb_tbl[k + 6], + new_dovi_setting.vsvdb_tbl[k + 7]); } } else { if (new_dovi_setting.vsvdb_len) @@ -7861,6 +8966,7 @@ int dolby_vision_parse_metadata( 0, sizeof(new_dovi_setting.vsvdb_tbl)); new_dovi_setting.vsvdb_len = 0; } + } /* check video/graphics priority on the fly */ @@ -7874,24 +8980,19 @@ int dolby_vision_parse_metadata( dolby_vision_graphics_priority = 1; } if (dolby_vision_graphics_priority || - (dolby_vision_flags & - FLAG_PRIORITY_GRAPHIC)) - pri_mode = GRAPHIC_PRIORITY; + (dolby_vision_flags & FLAG_PRIORITY_GRAPHIC)) + pri_mode = G_PRIORITY; else - pri_mode = VIDEO_PRIORITY; + pri_mode = V_PRIORITY; if (dst_format == FORMAT_DOVI) { - if ((dolby_vision_flags - & FLAG_FORCE_DOVI_LL) || - (dolby_vision_ll_policy - >= DOLBY_VISION_LL_YUV422)) + if ((dolby_vision_flags & FLAG_FORCE_DOVI_LL) || + dolby_vision_ll_policy >= DOLBY_VISION_LL_YUV422) new_dovi_setting.use_ll_flag = 1; else new_dovi_setting.use_ll_flag = 0; - if ((dolby_vision_ll_policy == - DOLBY_VISION_LL_RGB444) - || (dolby_vision_flags - & FLAG_FORCE_RGB_OUTPUT)) + if (dolby_vision_ll_policy == DOLBY_VISION_LL_RGB444 || + (dolby_vision_flags & FLAG_FORCE_RGB_OUTPUT)) new_dovi_setting.ll_rgb_desired = 1; else new_dovi_setting.ll_rgb_desired = 0; @@ -7899,8 +9000,8 @@ int dolby_vision_parse_metadata( new_dovi_setting.use_ll_flag = 0; new_dovi_setting.ll_rgb_desired = 0; } - if ((dst_format == FORMAT_HDR10) && - (dolby_vision_flags & FLAG_DOVI2HDR10_NOMAPPING)) + if (dst_format == FORMAT_HDR10 && + (dolby_vision_flags & FLAG_DOVI2HDR10_NOMAPPING)) new_dovi_setting.dovi2hdr10_nomapping = 1; else new_dovi_setting.dovi2hdr10_nomapping = 0; @@ -7908,7 +9009,7 @@ int dolby_vision_parse_metadata( /* always use rgb setting */ #if 1 new_dovi_setting.g_bitdepth = 8; - new_dovi_setting.g_format = GF_SDR_RGB; + new_dovi_setting.g_format = G_SDR_RGB; #else if (dolby_vision_flags & FLAG_CERTIFICAION) { new_dovi_setting.g_bitdepth = 8; @@ -7929,19 +9030,44 @@ int dolby_vision_parse_metadata( new_dovi_setting.vout_height = 0; } memset(&new_dovi_setting.ext_md, 0, sizeof(struct ext_md_s)); -#endif new_dovi_setting.video_width = w << 16; new_dovi_setting.video_height = h << 16; - flag = p_funcs_stb->control_path( - src_format, dst_format, + + if (debug_dolby & 0x400) + do_gettimeofday(&start); + if (is_meson_tm2_stb_hdmimode()) { + /* generate core2/core3 setting */ + flag = p_funcs_stb->control_path + (src_format, dst_format, + comp_buf[current_id], + (src_format == FORMAT_DOVI) ? total_comp_size : 0, + md_buf[current_id], + (src_format == FORMAT_DOVI) ? total_md_size : 0, + V_PRIORITY, + src_bdp, 0, SIGNAL_RANGE_SMPTE, + graphic_min, + graphic_max * 10000, + dolby_vision_target_min, + dolby_vision_target_max + [src_format][dst_format] * 10000, + false, + &hdr10_param, + &new_dovi_setting); + /* overwrite core3 meta by hdmi input */ + if (dst_format == FORMAT_DOVI && + dolby_vision_ll_policy == DOLBY_VISION_LL_DISABLE) + prepare_dv_meta + (&new_dovi_setting.md_reg3, + md_buf[current_id], total_md_size); + } else { + flag = p_funcs_stb->control_path + (src_format, dst_format, comp_buf[current_id], - ((src_format == FORMAT_DOVI) - || (src_format == FORMAT_DOVI_LL)) ? total_comp_size : 0, + (src_format == FORMAT_DOVI) ? total_comp_size : 0, md_buf[current_id], - ((src_format == FORMAT_DOVI) - || (src_format == FORMAT_DOVI_LL)) ? total_md_size : 0, + (src_format == FORMAT_DOVI) ? total_md_size : 0, pri_mode, - src_bdp, 0, SIG_RANGE_SMPTE, /* bit/chroma/range */ + src_bdp, 0, SIGNAL_RANGE_SMPTE, /* bit/chroma/range */ graphic_min, graphic_max * 10000, dolby_vision_target_min, @@ -7950,27 +9076,30 @@ int dolby_vision_parse_metadata( (dolby_vision_flags & FLAG_DISABLE_COMPOSER), &hdr10_param, &new_dovi_setting); + } + if (debug_dolby & 0x400) { + do_gettimeofday(&end); + time_use = (end.tv_sec - start.tv_sec) * 1000000 + + (end.tv_usec - start.tv_usec); + + pr_info("controlpath time: %5ld us\n", time_use); + } if (flag >= 0) { -#ifdef V2_4 stb_core_setting_update_flag |= flag; - if ((dolby_vision_flags - & FLAG_FORCE_DOVI_LL) - && (dst_format == FORMAT_DOVI)) + if ((dolby_vision_flags & FLAG_FORCE_DOVI_LL) && + dst_format == FORMAT_DOVI) new_dovi_setting.dovi_ll_enable = 1; - if ((dolby_vision_flags - & FLAG_FORCE_RGB_OUTPUT) - && (dst_format == FORMAT_DOVI)) { + if ((dolby_vision_flags & FLAG_FORCE_RGB_OUTPUT) && + dst_format == FORMAT_DOVI) { new_dovi_setting.dovi_ll_enable = 1; new_dovi_setting.diagnostic_enable = 1; new_dovi_setting.diagnostic_mux_select = 1; } if (debug_dolby & 2) - pr_dolby_dbg( - "ll_enable=%d,diagnostic=%d,ll_policy=%d\n", - new_dovi_setting.dovi_ll_enable, - new_dovi_setting.diagnostic_enable, - dolby_vision_ll_policy); -#endif + pr_dolby_dbg("ll_enable=%d,diagnostic=%d,ll_policy=%d\n", + new_dovi_setting.dovi_ll_enable, + new_dovi_setting.diagnostic_enable, + dolby_vision_ll_policy); new_dovi_setting.src_format = src_format; new_dovi_setting.dst_format = dst_format; new_dovi_setting.el_flag = el_flag; @@ -7980,35 +9109,54 @@ int dolby_vision_parse_metadata( dovi_setting_video_flag = video_frame; if (debug_dolby & 1) { if (is_video_output_off(vf)) - pr_dolby_dbg("setting %d->%d(T:%d-%d), osd:%dx%d\n", + pr_dolby_dbg + ("setting %d->%d(T:%d-%d), osd:%dx%d\n", + src_format, dst_format, + dolby_vision_target_min, + dolby_vision_target_max + [src_format][dst_format], + osd_graphic_width, + osd_graphic_height); + if (el_flag) { + pr_dolby_dbg + ("v %d: %dx%d %d->%d(T:%d-%d),g %d: %dx%d %d->%d,%s\n", + dovi_setting_video_flag, + w == 0xffff ? 0 : w, + h == 0xffff ? 0 : h, src_format, dst_format, dolby_vision_target_min, - dolby_vision_target_max[src_format][dst_format], + dolby_vision_target_max + [src_format][dst_format], + !is_graphics_output_off(), osd_graphic_width, - osd_graphic_height); - if (el_flag) - pr_dolby_dbg("video %d:%dx%d setting %d->%d(T:%d-%d): flag=%x, md=%d,comp=%d, frame:%d\n", - dovi_setting_video_flag, - w == 0xffff ? 0 : w, - h == 0xffff ? 0 : h, - src_format, dst_format, - dolby_vision_target_min, - dolby_vision_target_max - [src_format][dst_format], - flag, - total_md_size, total_comp_size, - frame_count); - else - pr_dolby_dbg("video %d:%dx%d setting %d->%d(T:%d-%d): flag=%x, md=%d, frame:%d\n", - dovi_setting_video_flag, - w == 0xffff ? 0 : w, - h == 0xffff ? 0 : h, - src_format, dst_format, - dolby_vision_target_min, - dolby_vision_target_max - [src_format][dst_format], - flag, - total_md_size, frame_count); + osd_graphic_height, + graphic_min, + graphic_max * 10000, + pri_mode == V_PRIORITY ? + "vpr" : "gpr"); + pr_dolby_dbg + ("flag=%x, md=%d, comp=%d, frame:%d\n", + flag, total_md_size, total_comp_size, + frame_count); + } else { + pr_dolby_dbg("v %d: %dx%d %d->%d(T:%d-%d), g %d: %dx%d %d->%d, %s, flag=%x, md=%d, frame:%d\n", + dovi_setting_video_flag, + w == 0xffff ? 0 : w, + h == 0xffff ? 0 : h, + src_format, dst_format, + dolby_vision_target_min, + dolby_vision_target_max + [src_format][dst_format], + !is_graphics_output_off(), + osd_graphic_width, + osd_graphic_height, + graphic_min, + graphic_max * 10000, + pri_mode == V_PRIORITY ? + "vpr" : "gpr", + flag, + total_md_size, frame_count); + } } dump_setting(&new_dovi_setting, frame_count, debug_dolby); el_mode = el_flag; @@ -8016,9 +9164,19 @@ int dolby_vision_parse_metadata( return 0; /* setting updated */ } if (flag < 0) { + pr_dolby_dbg("video %d:%dx%d setting %d->%d(T:%d-%d): pri_mode=%d, no_el=%d, md=%d, frame:%d\n", + dovi_setting_video_flag, + w == 0xffff ? 0 : w, + h == 0xffff ? 0 : h, + src_format, dst_format, + dolby_vision_target_min, + dolby_vision_target_max + [src_format][dst_format], + pri_mode, + (!el_flag && !mel_flag), + total_md_size, frame_count); new_dovi_setting.video_width = 0; new_dovi_setting.video_height = 0; - pr_dolby_error("control_path(%d, %d) failed %d\n", src_format, dst_format, flag); if ((debug_dolby & 0x2000) && dump_enable && @@ -8056,8 +9214,8 @@ bool vf_is_fel(struct vframe_s *vf) if (fmt == VFRAME_SIGNAL_FMT_DOVI) { if (debug_dolby & 0x1) pr_dolby_dbg("dual layer %d, parse ret flags %d\n", - - vf->src_fmt.dual_layer, vf->src_fmt.parse_ret_flags); + vf->src_fmt.dual_layer, + vf->src_fmt.parse_ret_flags); if (vf->src_fmt.dual_layer && vf->src_fmt.parse_ret_flags != 1) fel = true; } @@ -8073,7 +9231,7 @@ int dolby_vision_wait_metadata(struct vframe_s *vf) struct vframe_s *el_vf; int ret = 0; unsigned int mode = dolby_vision_mode; - enum signal_format_e check_format; + enum signal_format_enum check_format; const struct vinfo_s *vinfo = get_current_vinfo(); bool vd1_on = false; @@ -8088,13 +9246,18 @@ int dolby_vision_wait_metadata(struct vframe_s *vf) if (dolby_vision_flags & FLAG_CERTIFICAION) { bool ott_mode = true; - if (is_meson_tvmode() - && !force_stb_mode) + if (is_meson_tvmode()) ott_mode = tv_dovi_setting->input_mode != - INPUT_MODE_HDMI; - if ((setting_update_count > crc_count) - && (ott_mode == true)) - return 1; + IN_MODE_HDMI; + if (debug_dolby & 0x1000) + pr_dolby_dbg("setting_update_count %d, crc_count %d, flag %x\n", + setting_update_count, crc_count, + dolby_vision_flags); + if (setting_update_count > crc_count && + !(dolby_vision_flags & FLAG_DISABLE_CRC)) { + if (ott_mode) + return 1; + } } if (is_dovi_dual_layer_frame(vf)) { @@ -8102,25 +9265,26 @@ int dolby_vision_wait_metadata(struct vframe_s *vf) while (el_vf) { if (debug_dolby & 2) pr_dolby_dbg("=== peek bl(%p-%lld) with el(%p-%lld) ===\n", - vf, vf->pts_us64, - el_vf, el_vf->pts_us64); - if ((el_vf->pts_us64 == vf->pts_us64) - || !(dolby_vision_flags & FLAG_CHECK_ES_PTS)) { + vf, vf->pts_us64, + el_vf, el_vf->pts_us64); + if (el_vf->pts_us64 == vf->pts_us64 || + !(dolby_vision_flags & FLAG_CHECK_ES_PTS)) { /* found el */ ret = 3; break; } else if (el_vf->pts_us64 < vf->pts_us64) { if (debug_dolby & 2) pr_dolby_dbg("bl(%p-%lld) => skip el pts(%p-%lld)\n", - vf, vf->pts_us64, - el_vf, el_vf->pts_us64); + vf, vf->pts_us64, + el_vf, el_vf->pts_us64); el_vf = dvel_vf_get(); dvel_vf_put(el_vf); - vf_notify_provider(DVEL_RECV_NAME, - VFRAME_EVENT_RECEIVER_PUT, NULL); + vf_notify_provider + (DVEL_RECV_NAME, + VFRAME_EVENT_RECEIVER_PUT, NULL); if (debug_dolby & 2) pr_dolby_dbg("=== get & put el(%p-%lld) ===\n", - el_vf, el_vf->pts_us64); + el_vf, el_vf->pts_us64); /* skip old el and peek new */ el_vf = dvel_vf_peek(); @@ -8131,40 +9295,48 @@ int dolby_vision_wait_metadata(struct vframe_s *vf) } } /* need wait el */ - if (el_vf == NULL) { + if (!el_vf) { if (debug_dolby & 2) - pr_dolby_dbg( - "=== bl wait el(%p-%lld) ===\n", - vf, vf->pts_us64); + pr_dolby_dbg("=== bl wait el(%p-%lld) ===\n", + vf, vf->pts_us64); ret = 1; } } if (ret == 1) return ret; - if (!dolby_vision_wait_init - && !dolby_vision_core1_on) { - if (is_dovi_frame(vf)) - check_format = FORMAT_DOVI; - else if (is_hdr10_frame(vf)) + if (!dolby_vision_wait_init && !dolby_vision_core1_on) { + ret = is_dovi_frame(vf); + if (ret) { + /* STB hdmi LL input as HDR */ + if (vf->source_type == VFRAME_SOURCE_TYPE_HDMI && + ret == 2 && hdmi_to_stb_policy && + is_meson_tm2_stbmode()) + check_format = FORMAT_HDR10; + else + check_format = FORMAT_DOVI; + ret = 0; + } else if (is_hdr10_frame(vf)) { check_format = FORMAT_HDR10; - else if (is_hlg_frame(vf)) + } else if (is_hlg_frame(vf)) { check_format = FORMAT_HLG; - else if (is_hdr10plus_frame(vf)) + } else if (is_hdr10plus_frame(vf)) { check_format = FORMAT_HDR10PLUS; - else if (is_mvc_frame(vf)) + } else if (is_mvc_frame(vf)) { check_format = FORMAT_MVC; - else + } else if (is_cuva_frame(vf)) { + check_format = FORMAT_CUVA; + } else { check_format = FORMAT_SDR; + } if (vf) update_src_format(check_format, vf); - if (dolby_vision_policy_process( - &mode, check_format)) { - if ((mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) - && (dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_BYPASS)) { + if (dolby_vision_policy_process(&mode, check_format)) { + if (mode != DOLBY_VISION_OUTPUT_MODE_BYPASS && + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_BYPASS) { dolby_vision_wait_init = true; dolby_vision_target_mode = mode; dolby_vision_wait_on = true; @@ -8221,8 +9393,8 @@ int dolby_vision_wait_metadata(struct vframe_s *vf) pr_dolby_dbg("clear dolby_vision_wait_on\n"); } ret = 1; - } else if (dolby_vision_core1_on - && (dolby_vision_on_count <= + } else if (dolby_vision_core1_on && + (dolby_vision_on_count <= dolby_vision_run_mode_delay)) ret = 1; @@ -8244,8 +9416,7 @@ int dolby_vision_update_metadata(struct vframe_s *vf, bool drop_flag) dolby_vision_clear_buf(); if (vf && dolby_vision_vf_check(vf)) { - ret = dolby_vision_parse_metadata( - vf, 1, false, drop_flag); + ret = dolby_vision_parse_metadata(vf, 1, false, drop_flag); frame_count++; } @@ -8257,7 +9428,8 @@ EXPORT_SYMBOL(dolby_vision_update_metadata); int dolby_vision_update_src_format(struct vframe_s *vf, u8 toggle_mode) { unsigned int mode = dolby_vision_mode; - enum signal_format_e check_format; + enum signal_format_enum check_format; + int ret = 0; if (!dolby_vision_enable || !vf) return -1; @@ -8270,35 +9442,45 @@ int dolby_vision_update_src_format(struct vframe_s *vf, u8 toggle_mode) if (dolby_vision_vf_check(vf)) return 0; - if (is_dovi_frame(vf)) - check_format = FORMAT_DOVI; - else if (is_hdr10_frame(vf)) + ret = is_dovi_frame(vf); + if (ret) { + /* STB hdmi LL input as HDR */ + if (vf->source_type == VFRAME_SOURCE_TYPE_HDMI && + is_meson_tm2_stbmode() && + hdmi_to_stb_policy && ret == 2) + check_format = FORMAT_HDR10; + else + check_format = FORMAT_DOVI; + } else if (is_hdr10_frame(vf)) { check_format = FORMAT_HDR10; - else if (is_hlg_frame(vf)) + } else if (is_hlg_frame(vf)) { check_format = FORMAT_HLG; - else if (is_hdr10plus_frame(vf)) + } else if (is_hdr10plus_frame(vf)) { check_format = FORMAT_HDR10PLUS; - else if (is_mvc_frame(vf)) + } else if (is_mvc_frame(vf)) { check_format = FORMAT_MVC; - else + } else if (is_cuva_frame(vf)) { + check_format = FORMAT_CUVA; + } else { check_format = FORMAT_SDR; + } if (vf) update_src_format(check_format, vf); if (!dolby_vision_wait_init && !dolby_vision_core1_on && - (dolby_vision_src_format != 0)) { - if (dolby_vision_policy_process( - &mode, check_format)) { - if ((mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) && - (dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_BYPASS)) { + dolby_vision_src_format != 0) { + if (dolby_vision_policy_process + (&mode, check_format)) { + if (mode != DOLBY_VISION_OUTPUT_MODE_BYPASS && + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_BYPASS) { dolby_vision_wait_init = true; dolby_vision_target_mode = mode; dolby_vision_wait_on = true; - pr_dolby_dbg( - "dolby_vision_need_wait src=%d mode=%d\n", - check_format, mode); + pr_dolby_dbg + ("dolby_vision_need_wait src=%d mode=%d\n", + check_format, mode); } } /* don't use run mode when sdr -> dv and vd1 not disable */ @@ -8307,33 +9489,38 @@ int dolby_vision_update_src_format(struct vframe_s *vf, u8 toggle_mode) dolby_vision_on_count = dolby_vision_run_mode_delay + 1; } - pr_dolby_dbg( - "dolby_vision_update_src_format done vf:%p, src=%d, toggle mode:%d\n", - vf, dolby_vision_src_format, toggle_mode); + pr_dolby_dbg + ("%s done vf:%p, src=%d, toggle mode:%d\n", + __func__, vf, dolby_vision_src_format, toggle_mode); return 1; } EXPORT_SYMBOL(dolby_vision_update_src_format); -static void update_dolby_vision_status(enum signal_format_e src_format) +static void update_dolby_vision_status(enum signal_format_enum src_format) { - if (((src_format == FORMAT_DOVI) - || (src_format == FORMAT_DOVI_LL)) - && (dolby_vision_status != DV_PROCESS)) { - pr_dolby_dbg( - "Dolby Vision mode changed to DV_PROCESS %d\n", - src_format); + if ((src_format == FORMAT_DOVI || src_format == FORMAT_DOVI_LL) && + dolby_vision_status != DV_PROCESS) { + pr_dolby_dbg("Dolby Vision mode changed to DV_PROCESS %d\n", + src_format); dolby_vision_status = DV_PROCESS; - } else if ((src_format == FORMAT_HDR10) - && (dolby_vision_status != HDR_PROCESS)) { - pr_dolby_dbg( - "Dolby Vision mode changed to HDR_PROCESS %d\n", - src_format); + } else if (src_format == FORMAT_HDR10 && + dolby_vision_status != HDR_PROCESS) { + pr_dolby_dbg("Dolby Vision mode changed to HDR_PROCESS %d\n", + src_format); dolby_vision_status = HDR_PROCESS; - } else if ((src_format == FORMAT_SDR) - && (dolby_vision_status != SDR_PROCESS)) { - pr_dolby_dbg( - "Dolby Vision mode changed to SDR_PROCESS %d\n", + + } else if (src_format == FORMAT_HLG && + dolby_vision_status != HLG_PROCESS && + is_meson_tm2_tvmode()) { + pr_dolby_dbg + ("Dolby Vision mode changed to HLG_PROCESS %d\n", src_format); + dolby_vision_status = HLG_PROCESS; + + } else if (src_format == FORMAT_SDR && + dolby_vision_status != SDR_PROCESS) { + pr_dolby_dbg("Dolby Vision mode changed to SDR_PROCESS %d\n", + src_format); dolby_vision_status = SDR_PROCESS; } } @@ -8341,32 +9528,27 @@ static void update_dolby_vision_status(enum signal_format_e src_format) static u8 last_pps_state; static void bypass_pps_path(u8 pps_state) { - if (is_meson_txlx_package_962E() - || force_stb_mode) { + if (is_meson_txlx_package_962E()) { if (pps_state == 2) { - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, 1, 0, 1); - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA0, 0x08000800); + VSYNC_WR_DV_REG_BITS(VPP_DOLBY_CTRL, 1, 0, 1); + VSYNC_WR_DV_REG(VPP_DAT_CONV_PARA0, 0x08000800); } else if (pps_state == 1) { - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, 0, 0, 1); - VSYNC_WR_DV_REG( - VPP_DAT_CONV_PARA0, 0x20002000); + VSYNC_WR_DV_REG_BITS(VPP_DOLBY_CTRL, 0, 0, 1); + VSYNC_WR_DV_REG(VPP_DAT_CONV_PARA0, 0x20002000); } } if (pps_state && last_pps_state != pps_state) { pr_dolby_dbg("pps_state %d => %d\n", - last_pps_state, pps_state); + last_pps_state, pps_state); last_pps_state = pps_state; } } /* toggle mode: 0: not toggle; 1: toggle frame; 2: use keep frame */ /* pps_state 0: no change, 1: pps enable, 2: pps disable */ -int dolby_vision_process( - struct vframe_s *vf, u32 display_size, - u8 toggle_mode, u8 pps_state) +int dolby_vision_process(struct vframe_s *vf, + u32 display_size, + u8 toggle_mode, u8 pps_state) { int src_chroma_format = 0; u32 h_size = (display_size >> 16) & 0xffff; @@ -8383,11 +9565,17 @@ int dolby_vision_process( int policy_changed = 0; int sink_changed = 0; int format_changed = 0; - + bool src_is_42210bit = false; + u8 core_mask = 0x7; + static bool reverse_status; + bool reverse = false; + bool reverse_changed = false; + static u8 last_toggle_mode; + struct vout_device_s *p_vout = NULL; if (!is_meson_box() && !is_meson_txlx() && !is_meson_tm2()) return -1; - if ((dolby_vision_enable == 1) && (tv_mode == 1)) + if (dolby_vision_enable == 1 && tv_mode == 1) amdolby_vision_wakeup_queue(); if (dolby_vision_flags & FLAG_CERTIFICAION) { @@ -8402,54 +9590,87 @@ int dolby_vision_process( } dolby_vision_on_count = 1 + dolby_vision_run_mode_delay; - } - if (dolby_vision_flags & FLAG_TOGGLE_FRAME) { + if (is_meson_tm2_tvmode()) { + /*for vdin1 loop back, 444,12bit->422,12bit->444,8bit*/ + if (enable_tunnel) { + if (vpp_data_422T0444_backup == 0) { + vpp_data_422T0444_backup = + VSYNC_RD_DV_REG(VPU_422T0444_CTRL1); + pr_dolby_dbg("vpp_data_422T0444_backup %x\n", + vpp_data_422T0444_backup); + } + VSYNC_WR_DV_REG(VPU_422T0444_CTRL1, 0x04c0ba14); + /* reset RST bit1 to reset tunnel module */ + VSYNC_WR_DV_REG(VPU_422T0444_RST, 0x2); + VSYNC_WR_DV_REG(VPU_422T0444_RST, 0); + } else { + if (vpp_data_422T0444_backup) { + VSYNC_WR_DV_REG(VPU_422T0444_CTRL1, + vpp_data_422T0444_backup); + } + } + } + } + if (dolby_vision_flags & FLAG_TOGGLE_FRAME) { h_size = (display_size >> 16) & 0xffff; v_size = display_size & 0xffff; - if (new_dovi_setting.video_width & 0xffff && - new_dovi_setting.video_height & 0xffff) { - if (new_dovi_setting.video_width != h_size || - new_dovi_setting.video_height != v_size) { + if (!is_meson_tvmode()) { + /* stb control path case */ + if (new_dovi_setting.video_width & 0xffff && + new_dovi_setting.video_height & 0xffff) { + if (new_dovi_setting.video_width != h_size || + new_dovi_setting.video_height != v_size) { + if (debug_dolby & 8) + pr_dolby_dbg + ("stb update disp size %d %d->%d %d\n", + new_dovi_setting.video_width, + new_dovi_setting.video_height, + h_size, v_size); + } + if (h_size && v_size) { + new_dovi_setting.video_width = h_size; + new_dovi_setting.video_height = v_size; + } else { + new_dovi_setting.video_width = 0xffff; + new_dovi_setting.video_height = 0xffff; + } + /* tvcore need force config for res change */ + if (is_meson_tm2_stb_hdmimode() && + (core1_disp_hsize != h_size || + core1_disp_vsize != v_size)) + force_set = true; + } else if (core1_disp_hsize != h_size || + core1_disp_vsize != v_size) { if (debug_dolby & 8) pr_dolby_dbg( - "update display size %d %d -> %d %d\n", - new_dovi_setting.video_width, - new_dovi_setting.video_height, + "stb update display size %d %d->%d %d\n", + core1_disp_hsize, + core1_disp_vsize, h_size, v_size); + if (h_size && v_size) { + new_dovi_setting.video_width = h_size; + new_dovi_setting.video_height = v_size; + } else { + new_dovi_setting.video_width = 0xffff; + new_dovi_setting.video_height = 0xffff; + } } - if (h_size && v_size) { - new_dovi_setting.video_width = h_size; - new_dovi_setting.video_height = v_size; - } else { - new_dovi_setting.video_width = 0xffff; - new_dovi_setting.video_height = 0xffff; - } - - /* tvcore need a reset for resolution change */ - /* remove txlx tv case by Brian.zhu 20191102 */ - /* TODO: need check for tm2 */ - if (is_meson_tm2_tvmode() && - ((core1_disp_hsize != h_size) || - (core1_disp_vsize != v_size))) + } else { + /* tv control path case */ + if (core1_disp_hsize != h_size || + core1_disp_vsize != v_size) { + /* tvcore need force config for res change */ force_set = true; - } else if (core1_disp_hsize != h_size || - core1_disp_vsize != v_size) { - if (debug_dolby & 8) - pr_dolby_dbg( - "vpp update display size %d %d -> %d %d\n", - core1_disp_hsize, - core1_disp_vsize, - h_size, v_size); - if (h_size && v_size) { - new_dovi_setting.video_width = h_size; - new_dovi_setting.video_height = v_size; - } else { - new_dovi_setting.video_width = 0xffff; - new_dovi_setting.video_height = 0xffff; + if (debug_dolby & 8) + pr_dolby_dbg( + "tv cur-cp update display size %d %d -> %d %d\n", + core1_disp_hsize, + core1_disp_vsize, + h_size, v_size); } } - if ((!vf || (toggle_mode != 1)) && !sdr_delay) { + if ((!vf || toggle_mode != 1) && !sdr_delay) { /* log to monitor if has dv toggles not needed */ /* !sdr_delay: except in transition from DV to SDR */ pr_dolby_dbg("NULL/RPT frame %p, hdr module %s, video %s\n", @@ -8460,35 +9681,68 @@ int dolby_vision_process( } } - if ((dolby_vision_flags & FLAG_CERTIFICAION) - && (setting_update_count > crc_count) - && is_dolby_vision_on()) { + /* release metadata_parser when stop playing */ + if (last_toggle_mode != 2 && toggle_mode == 2) { + if (metadata_parser) { + if (p_funcs_stb) + p_funcs_stb->metadata_parser_release(); + if (p_funcs_tv) + p_funcs_tv->metadata_parser_release(); + metadata_parser = NULL; + pr_dolby_dbg("release parser\n"); + } + } + last_toggle_mode = toggle_mode; + if (debug_dolby & 0x1000) + pr_dolby_dbg("setting_update_count %d, crc_count %d\n", + setting_update_count, crc_count); + if ((dolby_vision_flags & FLAG_CERTIFICAION) && + !(dolby_vision_flags & FLAG_DISABLE_CRC) && + setting_update_count > crc_count && + is_dolby_vision_on()) { s32 delay_count = (dolby_vision_flags >> FLAG_FRAME_DELAY_SHIFT) & FLAG_FRAME_DELAY_MASK; bool ott_mode = true; - if (is_meson_tvmode() - && !force_stb_mode) + if (is_meson_tvmode()) ott_mode = (tv_dovi_setting->input_mode != - INPUT_MODE_HDMI); + IN_MODE_HDMI); + if ((is_meson_txlx_stbmode() || is_meson_tm2_stbmode() || - is_meson_box() || force_stb_mode) - && (setting_update_count == 1) - && (crc_read_delay == 1)) { + is_meson_box()) && + setting_update_count == 1 && + crc_read_delay == 1) { /* work around to enable crc for frame 0 */ VSYNC_WR_DV_REG(DOLBY_CORE3_CRC_CTRL, 1); crc_read_delay++; } else { crc_read_delay++; - if ((crc_read_delay > delay_count) - && (ott_mode == true)) { - tv_dolby_vision_insert_crc( - (crc_count == 0) ? true : false); - crc_read_delay = 0; + if (debug_dolby & 0x1000) + pr_dolby_dbg("crc_read_delay %d, delay_count %d\n", + crc_read_delay, delay_count); + if (crc_read_delay > delay_count) { + if (ott_mode) { + tv_dolby_vision_insert_crc + ((crc_count == 0) ? true : false); + crc_read_delay = 0; + } else if (is_meson_tm2_tvmode()) { + /* hdmi mode*/ + if (READ_VPP_DV_REG + (DOLBY_TV_DIAG_CTRL) == 0xb) { + u32 crc = + READ_VPP_DV_REG + (DOLBY_TV_OUTPUT_DM_CRC); + snprintf(cur_crc, + sizeof(cur_crc), + "0x%08x", crc); + } + crc_count++; + crc_read_delay = 0; + } } } } @@ -8521,9 +9775,30 @@ int dolby_vision_process( sink_changed = (is_sink_cap_changed(vinfo, ¤t_hdr_cap, ¤t_sink_available) & 2) ? 1 : 0; + + if (is_meson_tvmode()) { + reverse = get_video_reverse(); + if (reverse != reverse_status) { + reverse_status = reverse; + reverse_changed = true; + } + sink_changed = false; + graphic_status = 0; + dolby_vision_flags &= ~FLAG_FORCE_HDMI_PKT; + if (policy_changed || format_changed || + video_status == 1 || reverse_changed) + pr_dolby_dbg("tv %s %s %s %s\n", + policy_changed ? "policy changed" : "", + video_status ? "video_status changed" : "", + format_changed ? "format_changed" : "", + reverse_changed ? "reverse_changed" : ""); + } + if (sink_changed || policy_changed || format_changed || - (video_status == 1) || (graphic_status & 2) || - (dolby_vision_flags & FLAG_FORCE_HDMI_PKT)) { + (video_status == 1 && !(dolby_vision_flags & FLAG_CERTIFICAION)) || + (graphic_status & 2) || + (dolby_vision_flags & FLAG_FORCE_HDMI_PKT) || + need_update_cfg || reverse_changed) { if (debug_dolby & 1) pr_dolby_dbg("sink %s,cap 0x%x,video %s,osd %s,vf %p,toggle %d\n", current_sink_available ? "on" : "off", @@ -8535,14 +9810,17 @@ int dolby_vision_process( if (toggle_mode == 1) toggle_mode = 0; if (vf && - !dolby_vision_parse_metadata( - vf, toggle_mode, false, false)) { + !dolby_vision_parse_metadata + (vf, toggle_mode, false, false)) { h_size = (display_size >> 16) & 0xffff; v_size = display_size & 0xffff; - new_dovi_setting.video_width = h_size; - new_dovi_setting.video_height = v_size; + if (!is_meson_tvmode()) { + new_dovi_setting.video_width = h_size; + new_dovi_setting.video_height = v_size; + } dolby_vision_set_toggle_flag(1); } + need_update_cfg = false; } if (debug_dolby & 8) @@ -8563,29 +9841,35 @@ int dolby_vision_process( dolby_vision_set_toggle_flag(0); dolby_vision_wait_on = false; dolby_vision_wait_init = false; - } else + } else { dolby_vision_set_toggle_flag(1); + } } - if (dolby_vision_flags & FLAG_TOGGLE_FRAME) { - if (debug_dolby & 1) - pr_dolby_dbg("update when video off\n"); - dolby_vision_parse_metadata( - NULL, 1, false, false); + if ((dolby_vision_flags & FLAG_TOGGLE_FRAME) || + ((video_status == -1) && dolby_vision_core1_on)) { + pr_dolby_dbg("update when video off\n"); + dolby_vision_parse_metadata(NULL, 1, false, false); + dolby_vision_set_toggle_flag(1); + } + if (!vf && video_turn_off && + !dolby_vision_core1_on && + dolby_vision_src_format != 0) { + pr_dolby_dbg("update src_fmt when video off\n"); + dolby_vision_src_format = 0; } } if (dolby_vision_mode == DOLBY_VISION_OUTPUT_MODE_BYPASS) { - if (!is_meson_tvmode() || force_stb_mode) { + if (!is_meson_tvmode()) { if (vinfo && vinfo->vout_device && - (!vinfo->vout_device->dv_info) - && (vsync_count < FLAG_VSYNC_CNT)) { + !vinfo->vout_device->dv_info && + vsync_count < FLAG_VSYNC_CNT) { vsync_count++; return 0; } } if (dolby_vision_status != BYPASS_PROCESS) { - if (vinfo && !is_meson_tvmode() && - !force_stb_mode) { + if (vinfo && !is_meson_tvmode()) { if (vf && is_hdr10plus_frame(vf)) { /* disable dolby immediately */ pr_dolby_dbg("Dolby bypass: HDR10+: Switched to SDR first\n"); @@ -8623,24 +9907,38 @@ int dolby_vision_process( (get_video_mute() == VIDEO_MUTE_OFF && dolby_vision_flags & FLAG_MUTE)) /* core 3 only */ - apply_stb_core_settings( - dovi_setting_video_flag, - 0x4, - 0, - (dovi_setting.video_width << 16) - | dovi_setting.video_height, - pps_state); + apply_stb_core_settings + (dovi_setting_video_flag, + dolby_vision_mask & 0x4, + 0, + (dovi_setting.video_width + << 16) + | dovi_setting.video_height, + pps_state); send_hdmi_pkt(dolby_vision_src_format, FORMAT_SDR, vinfo, vf); if (sdr_delay >= MAX_TRANSITION_DELAY) { pr_dolby_dbg("Dolby bypass: Done - Switched to SDR\n"); enable_dolby_vision(0); sdr_delay = 0; - } else + } else { sdr_delay++; + } } - } else + /* if tv ko loaded for tm2 stb*/ + /* switch to tv vore */ + if (is_meson_tm2_stbmode() && + p_funcs_tv && !p_funcs_stb && + !is_dolby_vision_on()) { + pr_dolby_dbg("Switch from STB to TV core Done\n"); + tv_mode = 1; + support_info |= 1 << 3; + dolby_vision_run_mode_delay = + RUN_MODE_DELAY; + } + } else { enable_dolby_vision(0); + } } if (sdr_delay == 0) dolby_vision_flags &= ~FLAG_TOGGLE_FRAME; @@ -8650,8 +9948,8 @@ int dolby_vision_process( sdr_delay = 0; } - if ((dolby_vision_flags & FLAG_CERTIFICAION) - || (dolby_vision_flags & FLAG_BYPASS_VPP)) + if ((dolby_vision_flags & FLAG_CERTIFICAION) || + (dolby_vision_flags & FLAG_BYPASS_VPP)) video_effect_bypass(1); if (!p_funcs_stb && !p_funcs_tv) { @@ -8661,65 +9959,107 @@ int dolby_vision_process( new_dovi_setting.video_height = 0; return 0; } - if ((debug_dolby & 2) && force_set - && !(dolby_vision_flags & FLAG_CERTIFICAION)) - pr_dolby_dbg( - "core1 size changed--old: %d x %d, new: %d x %d\n", - core1_disp_hsize, core1_disp_vsize, - h_size, v_size); - + if ((debug_dolby & 2) && force_set && + !(dolby_vision_flags & FLAG_CERTIFICAION)) + pr_dolby_dbg + ("core1 size changed--old: %d x %d, new: %d x %d\n", + core1_disp_hsize, core1_disp_vsize, + h_size, v_size); if (dolby_vision_core1_on && - (dolby_vision_core1_on_cnt < DV_CORE1_RECONFIG_CNT) && - !(dolby_vision_flags & FLAG_TOGGLE_FRAME)) { + dolby_vision_core1_on_cnt < DV_CORE1_RECONFIG_CNT && + !(dolby_vision_flags & FLAG_TOGGLE_FRAME) && + !is_meson_tvmode()) { dolby_vision_set_toggle_flag(1); - pr_dolby_dbg( - "Need update core1 setting first %d times, force toggle frame\n", + if (!(dolby_vision_flags & FLAG_CERTIFICAION)) + pr_dolby_dbg + ("Need update core1 setting first %d times\n", dolby_vision_core1_on_cnt); } - + if (dolby_vision_on && !dolby_vision_core1_on && + dolby_vision_core2_on_cnt && + dolby_vision_core2_on_cnt < DV_CORE2_RECONFIG_CNT && + !(dolby_vision_flags & FLAG_TOGGLE_FRAME) && + !is_meson_tvmode() && + !(dolby_vision_flags & FLAG_CERTIFICAION)) { + force_set_lut = true; + dolby_vision_set_toggle_flag(1); + if (debug_dolby & 2) + pr_dolby_dbg("Need update core2 first %d times\n", + dolby_vision_core2_on_cnt); + } if (dolby_vision_flags & FLAG_TOGGLE_FRAME) { if (!(dolby_vision_flags & FLAG_CERTIFICAION)) reset_flag = - (dolby_vision_reset & 1) - && (!dolby_vision_core1_on) - && (dolby_vision_on_count == 0); - if (is_meson_tvmode() && !force_stb_mode) { - if (tv_dovi_setting_change_flag) { + (dolby_vision_reset & 1) && + (!dolby_vision_core1_on) && + (dolby_vision_on_count == 0); + if (is_meson_tvmode()) { + if (tv_dovi_setting_change_flag || force_set) { if (vf && (vf->type & VIDTYPE_VIU_422)) src_chroma_format = 2; else if (vf) src_chroma_format = 1; + /* mark by brian.zhu 2021.4.27 */ +#ifdef NEED_REMOVE if (force_set && - !(dolby_vision_flags - & FLAG_CERTIFICAION)) + !(dolby_vision_flags & FLAG_CERTIFICAION)) reset_flag = true; - tv_dolby_core1_set( - tv_dovi_setting->core1_reg_lut, - h_size, - v_size, - dovi_setting_video_flag, /* BL enable */ - dovi_setting_video_flag - && (tv_dovi_setting->el_flag), +#endif + if ((dolby_vision_flags & FLAG_CERTIFICAION)) { + if (tv_dovi_setting->src_format == + FORMAT_HDR10 || + tv_dovi_setting->src_format == + FORMAT_HLG || + tv_dovi_setting->src_format == + FORMAT_SDR) + src_is_42210bit = true; + } else { + if (tv_dovi_setting->src_format == + FORMAT_HDR10 || + tv_dovi_setting->src_format == + FORMAT_HLG) + src_is_42210bit = true; + } + tv_dolby_core1_set + (tv_dovi_setting->core1_reg_lut, + h_size, + v_size, + dovi_setting_video_flag,/*BL enable*/ + dovi_setting_video_flag && + tv_dovi_setting->el_flag && !mel_mode, tv_dovi_setting->el_halfsize_flag, - src_chroma_format, - tv_dovi_setting->input_mode == - INPUT_MODE_HDMI, - tv_dovi_setting->src_format == - FORMAT_HDR10, - reset_flag + src_chroma_format, + tv_dovi_setting->input_mode == + IN_MODE_HDMI, + src_is_42210bit, + reset_flag ); if (!h_size || !v_size) dovi_setting_video_flag = false; - if (dovi_setting_video_flag - && (dolby_vision_on_count == 0)) + if (dovi_setting_video_flag && + dolby_vision_on_count == 0) pr_dolby_dbg("first frame reset %d\n", - reset_flag); + reset_flag); enable_dolby_vision(1); + if (tv_dovi_setting->backlight != + tv_backlight || + (dovi_setting_video_flag && + dolby_vision_on_count == 0) || + tv_backlight_force_update) { + pr_dolby_dbg("backlight %d -> %d\n", + tv_backlight, + tv_dovi_setting->backlight); + tv_backlight = + tv_dovi_setting->backlight; + tv_backlight_changed = true; + bl_delay_cnt = 0; + tv_backlight_force_update = false; + } tv_dovi_setting_change_flag = false; core1_disp_hsize = h_size; core1_disp_vsize = v_size; - update_dolby_vision_status( - tv_dovi_setting->src_format); + update_dolby_vision_status + (tv_dovi_setting->src_format); } } else { if ((new_dovi_setting.video_width & 0xffff) @@ -8728,47 +10068,69 @@ int dolby_vision_process( new_dovi_setting.video_width = 0; if (new_dovi_setting.video_height == 0xffff) new_dovi_setting.video_height = 0; + if (vf && (vf->type & VIDTYPE_VIU_422)) + src_chroma_format = 2; + else if (vf) + src_chroma_format = 1; + + if (is_meson_tm2_stb_hdmimode()) { + core_mask = 0x6; + tv_dolby_core1_set + (tv_dovi_setting->core1_reg_lut, + new_dovi_setting.video_width, + new_dovi_setting.video_height, + dovi_setting_video_flag, + false, + false, + 2, + true, + false, + reset_flag + ); + } + if (force_set && !(dolby_vision_flags & FLAG_CERTIFICAION)) reset_flag = true; - apply_stb_core_settings( - dovi_setting_video_flag, - dolby_vision_mask & 0x7, - reset_flag, - (new_dovi_setting.video_width << 16) - | new_dovi_setting.video_height, - pps_state); + apply_stb_core_settings + (dovi_setting_video_flag, + dolby_vision_mask & core_mask, + reset_flag, + (new_dovi_setting.video_width << 16) + | new_dovi_setting.video_height, + pps_state); memcpy(&dovi_setting, &new_dovi_setting, - sizeof(dovi_setting)); + sizeof(dovi_setting)); if (core1_disp_hsize != dovi_setting.video_width || core1_disp_vsize != dovi_setting.video_height) if (core1_disp_hsize && core1_disp_vsize) - pr_dolby_dbg( - "frame size %d %d->%d %d\n", - core1_disp_hsize, - core1_disp_vsize, - dovi_setting.video_width, - dovi_setting.video_height); + pr_dolby_dbg + ("frame size %d %d->%d %d\n", + core1_disp_hsize, + core1_disp_vsize, + dovi_setting.video_width, + dovi_setting.video_height); new_dovi_setting.video_width = new_dovi_setting.video_height = 0; if (!dovi_setting.video_width || !dovi_setting.video_height) dovi_setting_video_flag = false; - if (dovi_setting_video_flag - && (dolby_vision_on_count == 0)) + if (dovi_setting_video_flag && + dolby_vision_on_count == 0) pr_dolby_dbg("first frame reset %d\n", - reset_flag); + reset_flag); /* clr hdr+ pkt when enable dv */ if (!dolby_vision_on && - vinfo && vinfo->vout_device && - vinfo->vout_device->fresh_tx_hdr10plus_pkt) - vinfo->vout_device-> - fresh_tx_hdr10plus_pkt( - 0, NULL); + vinfo && vinfo->vout_device) { + p_vout = vinfo->vout_device; + if (p_vout->fresh_tx_hdr10plus_pkt) + p_vout->fresh_tx_hdr10plus_pkt + (0, NULL); + } enable_dolby_vision(1); bypass_pps_path(pps_state); core1_disp_hsize = @@ -8776,35 +10138,35 @@ int dolby_vision_process( core1_disp_vsize = dovi_setting.video_height; /* send HDMI packet according to dst_format */ - if (vinfo && !force_stb_mode) - send_hdmi_pkt( - dovi_setting.src_format, - dovi_setting.dst_format, - vinfo, vf); - update_dolby_vision_status( - dovi_setting.src_format); + if (vinfo) + send_hdmi_pkt + (dovi_setting.src_format, + dovi_setting.dst_format, + vinfo, vf); + update_dolby_vision_status + (dovi_setting.src_format); } else { if ((get_video_mute() == VIDEO_MUTE_ON_DV && !(dolby_vision_flags & FLAG_MUTE)) || (get_video_mute() == VIDEO_MUTE_OFF && dolby_vision_flags & FLAG_MUTE) || - (last_dolby_vision_ll_policy != - dolby_vision_ll_policy)) + last_dolby_vision_ll_policy != + dolby_vision_ll_policy) /* core 3 only */ - apply_stb_core_settings( - dovi_setting_video_flag, - 0x4, - reset_flag, - (dovi_setting.video_width << 16) - | dovi_setting.video_height, - pps_state); + apply_stb_core_settings + (dovi_setting_video_flag, + dolby_vision_mask & 0x4, + reset_flag, + (dovi_setting.video_width << 16) + | dovi_setting.video_height, + pps_state); /* force send hdmi pkt */ if (dolby_vision_flags & FLAG_FORCE_HDMI_PKT) { - if (vinfo && !force_stb_mode) - send_hdmi_pkt( - dovi_setting.src_format, - dovi_setting.dst_format, - vinfo, vf); + if (vinfo) + send_hdmi_pkt + (dovi_setting.src_format, + dovi_setting.dst_format, + vinfo, vf); } } } @@ -8812,58 +10174,69 @@ int dolby_vision_process( } else if (dolby_vision_core1_on && !(dolby_vision_flags & FLAG_CERTIFICAION)) { bool reset_flag = - (dolby_vision_reset & 2) - && (dolby_vision_on_count - <= (dolby_vision_reset_delay >> 8)) - && (dolby_vision_on_count - >= (dolby_vision_reset_delay & 0xff)); - if (is_meson_txlx_stbmode() - || force_stb_mode) { - if ((dolby_vision_on_count <= - dolby_vision_run_mode_delay) - || force_set) { + (dolby_vision_reset & 2) && + (dolby_vision_on_count <= + (dolby_vision_reset_delay >> 8)) && + (dolby_vision_on_count >= + (dolby_vision_reset_delay & 0xff)); + if (is_meson_txlx_stbmode()) { + if (dolby_vision_on_count <= + dolby_vision_run_mode_delay || force_set) { if (force_set) reset_flag = true; - apply_stb_core_settings( - dovi_setting_video_flag, - /* core 1 only */ - dolby_vision_mask & 0x1, - reset_flag, - (h_size << 16) | v_size, - pps_state); + apply_stb_core_settings + (dovi_setting_video_flag, + /* core 1 only */ + dolby_vision_mask & 0x1, + reset_flag, + (h_size << 16) | v_size, + pps_state); bypass_pps_path(pps_state); core1_disp_hsize = h_size; core1_disp_vsize = v_size; if (dolby_vision_on_count <= dolby_vision_run_mode_delay) pr_dolby_dbg("fake frame %d reset %d\n", - dolby_vision_on_count, - reset_flag); + dolby_vision_on_count, + reset_flag); } } else if (is_meson_tvmode()) { - if ((dolby_vision_on_count <= - dolby_vision_run_mode_delay) - || force_set) { + if (dolby_vision_on_count <= + dolby_vision_run_mode_delay + 1 || force_set) { if (force_set) reset_flag = true; - tv_dolby_core1_set( - tv_dovi_setting->core1_reg_lut, - h_size, - v_size, - dovi_setting_video_flag, /* BL enable */ - dovi_setting_video_flag && - tv_dovi_setting->el_flag, /*ELenable*/ - tv_dovi_setting->el_halfsize_flag, - src_chroma_format, - tv_dovi_setting->input_mode == - INPUT_MODE_HDMI, + if (dolby_vision_flags & FLAG_CERTIFICAION) { + if (tv_dovi_setting->src_format == + FORMAT_HDR10 || + tv_dovi_setting->src_format == + FORMAT_HLG || tv_dovi_setting->src_format == - FORMAT_HDR10, - reset_flag); + FORMAT_SDR) + src_is_42210bit = true; + } else { + if (tv_dovi_setting->src_format == + FORMAT_HDR10 || + tv_dovi_setting->src_format == + FORMAT_HLG) + src_is_42210bit = true; + } + tv_dolby_core1_set + (tv_dovi_setting->core1_reg_lut, + h_size, + v_size, + dovi_setting_video_flag,/* BL enable */ + dovi_setting_video_flag && + tv_dovi_setting->el_flag && !mel_mode, + tv_dovi_setting->el_halfsize_flag, + src_chroma_format, + tv_dovi_setting->input_mode == + IN_MODE_HDMI, + src_is_42210bit, + reset_flag); core1_disp_hsize = h_size; core1_disp_vsize = v_size; if (dolby_vision_on_count <= - dolby_vision_run_mode_delay) + dolby_vision_run_mode_delay + 1) pr_dolby_dbg("fake frame %d reset %d\n", dolby_vision_on_count, reset_flag); @@ -8874,14 +10247,28 @@ int dolby_vision_process( || force_set) { if (force_set) reset_flag = true; - apply_stb_core_settings( - true, /* always enable */ - /* core 1 only */ - dolby_vision_mask & 0x1, - reset_flag, - (core1_disp_hsize << 16) - | core1_disp_vsize, - pps_state); + if (is_meson_tm2_stb_hdmimode()) + tv_dolby_core1_set + (tv_dovi_setting->core1_reg_lut, + core1_disp_hsize, + core1_disp_vsize, + dovi_setting_video_flag, + false, + false, + 2, + true, + false, + reset_flag + ); + else + apply_stb_core_settings + (true, /* always enable */ + /* core 1 only */ + dolby_vision_mask & 0x1, + reset_flag, + (core1_disp_hsize << 16) + | core1_disp_vsize, + pps_state); if (dolby_vision_on_count < dolby_vision_run_mode_delay) pr_dolby_dbg("fake frame (%d %d) %d reset %d\n", @@ -8894,10 +10281,11 @@ int dolby_vision_process( } if (dolby_vision_core1_on) { if (dolby_vision_on_count <= - dolby_vision_run_mode_delay) + dolby_vision_run_mode_delay + 1) dolby_vision_on_count++; - } else + } else { dolby_vision_on_count = 0; + } return 0; } EXPORT_SYMBOL(dolby_vision_process); @@ -8909,9 +10297,9 @@ EXPORT_SYMBOL(dolby_vision_process); */ bool is_dolby_vision_on(void) { - return dolby_vision_on - || dolby_vision_wait_on - || dolby_vision_on_in_uboot; + return dolby_vision_on || + dolby_vision_wait_on || + dolby_vision_on_in_uboot; } EXPORT_SYMBOL(is_dolby_vision_on); @@ -8928,7 +10316,14 @@ bool for_dolby_vision_certification(void) } EXPORT_SYMBOL(for_dolby_vision_certification); -void dolby_vision_set_toggle_flag(int flag) +bool for_dolby_vision_video_effect(void) +{ + return is_dolby_vision_on() && + dolby_vision_flags & FLAG_BYPASS_VPP; +} +EXPORT_SYMBOL(for_dolby_vision_video_effect); + +void dolby_vision_set_toggle_flag(int flag) { if (flag) { dolby_vision_flags |= FLAG_TOGGLE_FRAME; @@ -8940,6 +10335,12 @@ void dolby_vision_set_toggle_flag(int flag) } EXPORT_SYMBOL(dolby_vision_set_toggle_flag); +bool is_dv_control_backlight(void) +{ + return dv_control_backlight_status; +} +EXPORT_SYMBOL(is_dv_control_backlight); + void set_dolby_vision_mode(int mode) { if ((is_meson_box() || is_meson_txlx() || is_meson_tm2()) @@ -8948,9 +10349,9 @@ void set_dolby_vision_mode(int mode) if (dolby_vision_policy_process( &mode, get_cur_src_format())) { dolby_vision_set_toggle_flag(1); - if ((mode != DOLBY_VISION_OUTPUT_MODE_BYPASS) - && (dolby_vision_mode == - DOLBY_VISION_OUTPUT_MODE_BYPASS)) + if (mode != DOLBY_VISION_OUTPUT_MODE_BYPASS && + dolby_vision_mode == + DOLBY_VISION_OUTPUT_MODE_BYPASS) dolby_vision_wait_on = true; pr_info("DOVI output change from %d to %d\n", dolby_vision_mode, mode); @@ -8981,8 +10382,7 @@ EXPORT_SYMBOL(is_dolby_vision_enable); bool is_dolby_vision_stb_mode(void) { - return force_stb_mode || - is_meson_txlx_stbmode() || + return is_meson_txlx_stbmode() || is_meson_tm2_stbmode() || is_meson_box(); } @@ -9033,6 +10433,1257 @@ int get_dolby_vision_hdr_policy(void) } EXPORT_SYMBOL(get_dolby_vision_hdr_policy); +void dolby_vision_update_backlight(void) +{ +#ifdef COMPILE_ERR + if (is_meson_tvmode()) { + if (!force_disable_dv_backlight) { + bl_delay_cnt++; + if (tv_backlight_changed && + set_backlight_delay_vsync == bl_delay_cnt) { + pr_dolby_dbg("dv set backlight %d\n", + tv_backlight); + aml_lcd_atomic_notifier_call_chain + (LCD_EVENT_BACKLIGHT_DV_DIM, + &tv_backlight); + tv_backlight_changed = false; + } + } + } +#endif +} +EXPORT_SYMBOL(dolby_vision_update_backlight); + +void dolby_vision_disable_backlight(void) +{ +#ifdef COMPILE_ERR + int gd_en = 0; + + pr_dolby_dbg("disable dv backlight\n"); + + if (is_meson_tvmode()) { + aml_lcd_atomic_notifier_call_chain + (LCD_EVENT_BACKLIGHT_GD_SEL, &gd_en); + dv_control_backlight_status = false; + } +#endif +} + +static void parse_param_amdolby_vision(char *buf_orig, char **parm) +{ + char *ps, *token; + unsigned int n = 0; + char delim1[3] = " "; + char delim2[2] = "\n"; + + ps = buf_orig; + strcat(delim1, delim2); + while (1) { + token = strsep(&ps, delim1); + if (!token) + break; + if (*token == '\0') + continue; + parm[n++] = token; + if (n >= MAX_PARAM) + break; + } +} + +static inline s16 clamps(s16 value, s16 v_min, s16 v_max) +{ + if (value > v_max) + return v_max; + if (value < v_min) + return v_min; + return value; +} + +/*to do*/ +static void update_vsvdb_to_rx(void) +{ + u8 *p = cfg_info[cur_pic_mode].vsvdb; + + if (memcmp(¤t_vsvdb[0], p, sizeof(current_vsvdb))) { + memcpy(¤t_vsvdb[0], p, sizeof(current_vsvdb)); + pr_info("%s: %d %d %d %d %d %d %d\n", + __func__, p[0], p[1], p[2], p[3], p[4], p[5], p[6]); + } +} + +static void update_cp_cfg(void) +{ + unsigned long lockflags; + struct target_config *tdc; + + if (cur_pic_mode >= num_picture_mode || num_picture_mode == 0 || + !bin_to_cfg) { + pr_info("%s, invalid para %d/%d, bin_to_cfg %p", + __func__, cur_pic_mode, num_picture_mode, bin_to_cfg); + return; + } + + memcpy(pq_config_fake, + &bin_to_cfg[cur_pic_mode], + sizeof(struct pq_config)); + tdc = &(((struct pq_config *)pq_config_fake)->tdc); + tdc->d_brightness = cfg_info[cur_pic_mode].brightness; + tdc->d_contrast = cfg_info[cur_pic_mode].contrast; + tdc->d_color_shift = cfg_info[cur_pic_mode].colorshift; + tdc->d_saturation = cfg_info[cur_pic_mode].saturation; + + if (debug_tprimary) { + tdc->t_primaries[0] = cur_debug_tprimary[0][0]; /*rx*/ + tdc->t_primaries[1] = cur_debug_tprimary[0][1]; /*ry*/ + tdc->t_primaries[2] = cur_debug_tprimary[1][0]; /*gx*/ + tdc->t_primaries[3] = cur_debug_tprimary[1][1]; /*gy*/ + tdc->t_primaries[4] = cur_debug_tprimary[2][0]; /*bx*/ + tdc->t_primaries[5] = cur_debug_tprimary[2][1]; /*by*/ + } + + spin_lock_irqsave(&cfg_lock, lockflags); + need_update_cfg = true; + spin_unlock_irqrestore(&cfg_lock, lockflags); +} + +/*0: reset picture mode and reset pq for all picture mode*/ +/*1: reset pq for all picture mode*/ +/*2: reset pq for current picture mode */ +static void restore_dv_pq_setting(enum pq_reset_e pq_reset) +{ + int mode = 0; + + if (pq_reset == RESET_ALL) + cur_pic_mode = default_pic_mode; + + for (mode = 0; mode < num_picture_mode; mode++) { + if (pq_reset == RESET_PQ_FOR_CUR && mode != cur_pic_mode) + continue; + cfg_info[mode].brightness = + bin_to_cfg[mode].tdc.d_brightness; + cfg_info[mode].contrast = + bin_to_cfg[mode].tdc.d_contrast; + cfg_info[mode].colorshift = + bin_to_cfg[mode].tdc.d_color_shift; + cfg_info[mode].saturation = + bin_to_cfg[mode].tdc.d_saturation; + memcpy(cfg_info[mode].vsvdb, + bin_to_cfg[mode].tdc.vsvdb, + sizeof(cfg_info[mode].vsvdb)); + } + cur_debug_tprimary[0][0] = + bin_to_cfg[0].tdc.t_primaries[0]; + cur_debug_tprimary[0][1] = + bin_to_cfg[0].tdc.t_primaries[1]; + cur_debug_tprimary[1][0] = + bin_to_cfg[0].tdc.t_primaries[2]; + cur_debug_tprimary[1][1] = + bin_to_cfg[0].tdc.t_primaries[3]; + cur_debug_tprimary[2][0] = + bin_to_cfg[0].tdc.t_primaries[4]; + cur_debug_tprimary[2][1] = + bin_to_cfg[0].tdc.t_primaries[5]; + + update_cp_cfg(); + if (debug_dolby & 0x200) + pr_info("reset pq %d\n", pq_reset); +} + +static void set_dv_pq_center(void) +{ + int mode = 0; +#if USE_CENTER_0 + for (mode = 0; mode < num_picture_mode; mode++) { + pq_center[mode][0] = 0; + pq_center[mode][1] = 0; + pq_center[mode][2] = 0; + pq_center[mode][3] = 0; + } +#else + for (mode = 0; mode < num_picture_mode; mode++) { + pq_center[mode][0] = + bin_to_cfg[mode].tdc.d_brightness; + pq_center[mode][1] = + bin_to_cfg[mode].tdc.d_contrast; + pq_center[mode][2] = + bin_to_cfg[mode].tdc.d_color_shift; + pq_center[mode][3] = + bin_to_cfg[mode].tdc.d_saturation; + } +#endif +} + +static void set_dv_pq_range(void) +{ + pq_range[PQ_BRIGHTNESS].left = LEFT_RANGE_BRIGHTNESS; + pq_range[PQ_BRIGHTNESS].right = RIGHT_RANGE_BRIGHTNESS; + pq_range[PQ_CONTRAST].left = LEFT_RANGE_CONTRAST; + pq_range[PQ_CONTRAST].right = RIGHT_RANGE_CONTRAST; + pq_range[PQ_COLORSHIFT].left = LEFT_RANGE_COLORSHIFT; + pq_range[PQ_COLORSHIFT].right = RIGHT_RANGE_COLORSHIFT; + pq_range[PQ_SATURATION].left = LEFT_RANGE_SATURATION; + pq_range[PQ_SATURATION].right = RIGHT_RANGE_SATURATION; +} + +static void remove_comments(char *p_buf) +{ + if (!p_buf) + return; + while (*p_buf && *p_buf != '#' && *p_buf != '%') + p_buf++; + + *p_buf = 0; +} + +#define MAX_READ_SIZE 1536 +static char cur_line[MAX_READ_SIZE]; + +/*read one line from cfg, return eof flag*/ +static bool get_one_line(char **cfg_buf, char *line_buf) +{ + char *line_end; + size_t line_len = 0; + bool eof_flag = false; + + if (!cfg_buf || !(*cfg_buf) || !line_buf) + return true; + + line_buf[0] = '\0'; + while (*line_buf == '\0') { + line_end = memchr(*cfg_buf, '\n', MAX_READ_SIZE); + if (!line_end) + line_end = memchr(*cfg_buf, '\r', MAX_READ_SIZE); + + if (!line_end) { + line_len = strlen(*cfg_buf); + eof_flag = true; + } else { + line_len = (size_t)(line_end - *cfg_buf); + } + memcpy(line_buf, *cfg_buf, line_len); + line_buf[line_len] = '\0'; + + if (line_len > 0 && line_buf[line_len - 1] == '\r') + line_buf[line_len - 1] = '\0'; + + *cfg_buf = *cfg_buf + line_len + 1; + remove_comments(line_buf); + while (isspace(*line_buf)) + line_buf++; + if (**cfg_buf == '\0') + eof_flag = true; + if (eof_flag) + break; + } + return eof_flag; +} + +static void get_picture_mode_info(char *cfg_buf) +{ + char *ptr_line; + char name[32]; + int picmode_count = 0; + int ret = 0; + bool eof_flag = false; + + while (!eof_flag) { + eof_flag = get_one_line(&cfg_buf, (char *)&cur_line); + ptr_line = cur_line; + if (eof_flag && (strlen(cur_line) == 0)) + break; + if ((strncmp(ptr_line, "PictureModeName", + strlen("PictureModeName")) == 0)) { + ret = sscanf(ptr_line, "PictureModeName = %s", name); + if (ret == 1) { + cfg_info[picmode_count].id = + picmode_count; + strcpy(cfg_info[picmode_count].pic_mode_name, + name); + if (debug_dolby & 0x200) + pr_info("update cfg_info[%d]: %s\n", + picmode_count, name); + picmode_count++; + if (picmode_count >= num_picture_mode) + break; + } + } + } +} + +static bool load_dv_pq_config_data(char *bin_path, char *txt_path) +{ + struct file *filp = NULL; + struct file *filp_txt = NULL; + bool ret = true; + loff_t pos = 0; + mm_segment_t old_fs = get_fs(); + struct kstat stat; + unsigned int length = 0; + unsigned int cfg_len = sizeof(struct pq_config) * MAX_DV_PICTUREMODES; + char *txt_buf = NULL; + int i = 0; + int error; + + if (!module_installed) + return false; + + if (!bin_to_cfg) + bin_to_cfg = vmalloc(cfg_len); + if (!bin_to_cfg) + return false; + + set_fs(KERNEL_DS); + filp = filp_open(bin_path, O_RDONLY, 0444); + if (IS_ERR(filp)) { + ret = false; + pr_info("[%s] failed to open file: |%s|\n", __func__, bin_path); + goto LOAD_END; + } + + error = vfs_stat(bin_path, &stat); + if (error < 0) + ret = false; + length = (stat.size > cfg_len) ? cfg_len : stat.size; + num_picture_mode = length / sizeof(struct pq_config); + + if (num_picture_mode > + sizeof(cfg_info) / sizeof(struct dv_cfg_info_s)) { + pr_info("dv_config.bin size(%d) bigger than cfg_info(%d)\n", + num_picture_mode, + (int)(sizeof(cfg_info) / sizeof(struct dv_cfg_info_s))); + num_picture_mode = + sizeof(cfg_info) / sizeof(struct dv_cfg_info_s); + } + if (num_picture_mode == 1) + default_pic_mode = 0; + vfs_read(filp, (char *)bin_to_cfg, length, &pos); + + for (i = 0; i < num_picture_mode; i++) { + cfg_info[i].id = i; + strcpy(cfg_info[i].pic_mode_name, "uninitialized"); + } + + /***read cfg txt to get picture mode name****/ + filp_txt = filp_open(txt_path, O_RDONLY, 0444); + pos = 0; + if (IS_ERR(filp_txt)) { + ret = false; + pr_info("[%s] failed to open file: |%s|\n", __func__, txt_path); + } else { + error = vfs_stat(txt_path, &stat); + if (error < 0) + ret = false; + length = stat.size; + txt_buf = vmalloc(length); + + if (txt_buf) { + vfs_read(filp_txt, txt_buf, length, &pos); + get_picture_mode_info(txt_buf); + } + } + /*************read cfg txt done***********/ + + set_dv_pq_center(); + set_dv_pq_range(); + restore_dv_pq_setting(RESET_ALL); + update_vsvdb_to_rx(); + + filp_close(filp, NULL); + + pr_info("DV config: load %d picture mode\n", num_picture_mode); + +LOAD_END: + if (txt_buf) + vfree(txt_buf); + set_fs(old_fs); + return ret; +} + +/*internal range -> external range*/ +static s16 map_pq_inter_to_exter + (enum pq_item_e pq_item, + s16 inter_value) +{ + s16 inter_pq_min; + s16 inter_pq_max; + s16 exter_pq_min; + s16 exter_pq_max; + s16 exter_value; + s16 inter_range; + s16 exter_range; + s16 tmp; + s16 left_range = pq_range[pq_item].left; + s16 right_range = pq_range[pq_item].right; + s16 center = pq_center[cur_pic_mode][pq_item]; + + if (inter_value >= center) { + exter_pq_min = 0; + exter_pq_max = EXTER_MAX_PQ; + inter_pq_min = center; + inter_pq_max = right_range; + } else { + exter_pq_min = EXTER_MIN_PQ; + exter_pq_max = 0; + inter_pq_min = left_range; + inter_pq_max = center; + } + inter_pq_min = clamps(inter_pq_min, INTER_MIN_PQ, INTER_MAX_PQ); + inter_pq_max = clamps(inter_pq_max, INTER_MIN_PQ, INTER_MAX_PQ); + tmp = clamps(inter_value, inter_pq_min, inter_pq_max); + + inter_range = inter_pq_max - inter_pq_min; + exter_range = exter_pq_max - exter_pq_min; + + if (inter_range == 0) { + inter_range = INTER_MAX_PQ; + pr_info("invalid inter_range, set to INTER_MAX_PQ\n"); + } + + exter_value = exter_pq_min + + (tmp - inter_pq_min) * exter_range / inter_range; + + if (debug_dolby & 0x200) + pr_info("%s: %s [%d]->[%d]\n", + __func__, pq_item_str[pq_item], + inter_value, exter_value); + return exter_value; +} + +/*external range -> internal range*/ +static s16 map_pq_exter_to_inter + (enum pq_item_e pq_item, + s16 exter_value) +{ + s16 inter_pq_min; + s16 inter_pq_max; + s16 exter_pq_min; + s16 exter_pq_max; + s16 inter_value; + s16 inter_range; + s16 exter_range; + s16 tmp; + s16 left_range = pq_range[pq_item].left; + s16 right_range = pq_range[pq_item].right; + s16 center = pq_center[cur_pic_mode][pq_item]; + + if (exter_value >= 0) { + exter_pq_min = 0; + exter_pq_max = EXTER_MAX_PQ; + inter_pq_min = center; + inter_pq_max = right_range; + } else { + exter_pq_min = EXTER_MIN_PQ; + exter_pq_max = 0; + inter_pq_min = left_range; + inter_pq_max = center; + } + + inter_pq_min = clamps(inter_pq_min, INTER_MIN_PQ, INTER_MAX_PQ); + inter_pq_max = clamps(inter_pq_max, INTER_MIN_PQ, INTER_MAX_PQ); + tmp = clamps(exter_value, exter_pq_min, exter_pq_max); + + inter_range = inter_pq_max - inter_pq_min; + exter_range = exter_pq_max - exter_pq_min; + + inter_value = inter_pq_min + + (tmp - exter_pq_min) * inter_range / exter_range; + + if (debug_dolby & 0x200) + pr_info("%s: %s [%d]->[%d]\n", + __func__, pq_item_str[pq_item], + exter_value, inter_value); + return inter_value; +} + +static bool is_valid_pic_mode(int mode) +{ + if (mode < num_picture_mode && mode >= 0) + return true; + else + return false; +} + +static bool is_valid_pq_exter_value(s16 exter_value) +{ + if (exter_value <= EXTER_MAX_PQ && exter_value >= EXTER_MIN_PQ) + return true; + + pr_info("pq %d is out of range[%d, %d]\n", + exter_value, EXTER_MIN_PQ, EXTER_MAX_PQ); + return false; +} + +static bool is_valid_pq_inter_value(s16 exter_value) +{ + if (exter_value <= INTER_MAX_PQ && exter_value >= INTER_MIN_PQ) + return true; + + pr_info("pq %d is out of range[%d, %d]\n", + exter_value, INTER_MIN_PQ, INTER_MAX_PQ); + return false; +} + +static void set_pic_mode(int mode) +{ + if (cur_pic_mode != mode) { + cur_pic_mode = mode; + update_cp_cfg(); + update_vsvdb_to_rx(); + update_pwm_control(); + } +} + +static int get_pic_mode_num(void) +{ + return num_picture_mode; +} + +static int get_pic_mode(void) +{ + return cur_pic_mode; +} + +static char *get_pic_mode_name(int mode) +{ + if (!is_valid_pic_mode(mode)) + return "errmode"; + + return cfg_info[mode].pic_mode_name; +} + +static s16 get_single_pq_value(int mode, enum pq_item_e item) +{ + s16 exter_value = 0; + s16 inter_value = 0; + + if (!is_valid_pic_mode(mode)) { + pr_err("err picture mode %d\n", mode); + return exter_value; + } + switch (item) { + case PQ_BRIGHTNESS: + inter_value = cfg_info[mode].brightness; + break; + case PQ_CONTRAST: + inter_value = cfg_info[mode].contrast; + break; + case PQ_COLORSHIFT: + inter_value = cfg_info[mode].colorshift; + break; + case PQ_SATURATION: + inter_value = cfg_info[mode].saturation; + break; + default: + pr_err("err pq_item %d\n", item); + break; + } + + exter_value = map_pq_inter_to_exter(item, inter_value); + + if (debug_dolby & 0x200) + pr_info("%s: mode:%d, item:%s, [inter: %d, exter: %d]\n", + __func__, mode, pq_item_str[item], + inter_value, exter_value); + return exter_value; +} + +static struct dv_full_pq_info_s get_full_pq_value(int mode) +{ + s16 exter_value = 0; + struct dv_full_pq_info_s full_pq_info = {mode, 0, 0, 0, 0}; + + if (!is_valid_pic_mode(mode)) { + pr_err("err picture mode %d\n", mode); + return full_pq_info; + } + + exter_value = map_pq_inter_to_exter(PQ_BRIGHTNESS, + cfg_info[mode].brightness); + full_pq_info.brightness = exter_value; + + exter_value = map_pq_inter_to_exter(PQ_CONTRAST, + cfg_info[mode].contrast); + full_pq_info.contrast = exter_value; + + exter_value = map_pq_inter_to_exter(PQ_COLORSHIFT, + cfg_info[mode].colorshift); + full_pq_info.colorshift = exter_value; + + exter_value = map_pq_inter_to_exter(PQ_SATURATION, + cfg_info[mode].saturation); + full_pq_info.saturation = exter_value; + + if (debug_dolby & 0x200) { + pr_info("----------%s: mode:%d-----------\n", __func__, mode); + pr_info("%s: value[inter: %d, exter: %d]\n", + pq_item_str[PQ_BRIGHTNESS], + cfg_info[mode].brightness, + full_pq_info.brightness); + pr_info("%s: value[inter: %d, exter: %d]\n", + pq_item_str[PQ_CONTRAST], + cfg_info[mode].contrast, + full_pq_info.contrast); + pr_info("%s: value[inter: %d, exter: %d]\n", + pq_item_str[PQ_COLORSHIFT], + cfg_info[mode].colorshift, + full_pq_info.colorshift); + pr_info("%s: value[inter: %d, exter: %d]\n", + pq_item_str[PQ_SATURATION], + cfg_info[mode].saturation, + full_pq_info.saturation); + } + + return full_pq_info; +} + +static void set_single_pq_value(int mode, enum pq_item_e item, s16 value) +{ + s16 inter_value = 0; + s16 exter_value = value; + bool pq_changed = false; + + if (!is_valid_pic_mode(mode)) { + pr_err("err picture mode %d\n", mode); + return; + } + if (!set_inter_pq) { + if (!is_valid_pq_exter_value(exter_value)) { + exter_value = + clamps(exter_value, EXTER_MIN_PQ, EXTER_MAX_PQ); + pr_info("clamps %s to %d\n", + pq_item_str[item], exter_value); + } + inter_value = map_pq_exter_to_inter(item, exter_value); + if (debug_dolby & 0x200) { + pr_info("%s: mode:%d, item:%s, [inter:%d, exter:%d]\n", + __func__, mode, pq_item_str[item], + inter_value, exter_value); + } + } else { + inter_value = value; + if (!is_valid_pq_inter_value(inter_value)) { + inter_value = + clamps(inter_value, INTER_MIN_PQ, INTER_MAX_PQ); + pr_info("clamps %s to %d\n", + pq_item_str[item], inter_value); + } + if (debug_dolby & 0x200) { + exter_value = map_pq_inter_to_exter(item, inter_value); + pr_info("%s: mode:%d, item:%s, [inter:%d, exter:%d]\n", + __func__, mode, pq_item_str[item], + inter_value, exter_value); + } + } + switch (item) { + case PQ_BRIGHTNESS: + if (cfg_info[cur_pic_mode].brightness != inter_value) { + cfg_info[cur_pic_mode].brightness = inter_value; + pq_changed = true; + } + break; + case PQ_CONTRAST: + if (cfg_info[cur_pic_mode].contrast != inter_value) { + cfg_info[cur_pic_mode].contrast = inter_value; + pq_changed = true; + } + break; + case PQ_COLORSHIFT: + if (cfg_info[cur_pic_mode].colorshift != inter_value) { + cfg_info[cur_pic_mode].colorshift = inter_value; + pq_changed = true; + } + break; + case PQ_SATURATION: + if (cfg_info[cur_pic_mode].saturation != inter_value) { + cfg_info[cur_pic_mode].saturation = inter_value; + pq_changed = true; + } + break; + default: + pr_err("err pq_item %d\n", item); + break; + } + if (pq_changed) + update_cp_cfg(); +} + +static void set_full_pq_value(struct dv_full_pq_info_s full_pq_info) +{ + s16 inter_value = 0; + s16 exter_value = 0; + int mode = full_pq_info.pic_mode_id; + + if (!is_valid_pic_mode(mode)) { + pr_err("err picture mode %d\n", mode); + return; + } + /*------------set brightness----------*/ + if (!set_inter_pq) { + exter_value = full_pq_info.brightness; + if (!is_valid_pq_exter_value(exter_value)) { + exter_value = + clamps(exter_value, EXTER_MIN_PQ, EXTER_MAX_PQ); + pr_info("clamps brightness from %d to %d\n", + full_pq_info.brightness, exter_value); + } + inter_value = map_pq_exter_to_inter(PQ_BRIGHTNESS, exter_value); + } else { + inter_value = full_pq_info.brightness; + if (!is_valid_pq_inter_value(inter_value)) { + inter_value = + clamps(inter_value, INTER_MIN_PQ, INTER_MAX_PQ); + pr_info("clamps brightness from %d to %d\n", + full_pq_info.brightness, inter_value); + } + } + cfg_info[cur_pic_mode].brightness = inter_value; + + /*-------------set contrast-----------*/ + if (!set_inter_pq) { + exter_value = full_pq_info.contrast; + if (!is_valid_pq_exter_value(exter_value)) { + exter_value = + clamps(exter_value, EXTER_MIN_PQ, EXTER_MAX_PQ); + pr_info("clamps contrast from %d to %d\n", + full_pq_info.contrast, exter_value); + } + inter_value = map_pq_exter_to_inter(PQ_CONTRAST, exter_value); + } else { + inter_value = full_pq_info.contrast; + if (!is_valid_pq_inter_value(inter_value)) { + inter_value = + clamps(inter_value, INTER_MIN_PQ, INTER_MAX_PQ); + pr_info("clamps contrast from %d to %d\n", + full_pq_info.contrast, inter_value); + } + } + cfg_info[cur_pic_mode].contrast = inter_value; + + /*-------------set colorshift-----------*/ + if (!set_inter_pq) { + exter_value = full_pq_info.colorshift; + if (!is_valid_pq_exter_value(exter_value)) { + exter_value = + clamps(exter_value, EXTER_MIN_PQ, EXTER_MAX_PQ); + pr_info("clamps colorshift from %d to %d\n", + full_pq_info.colorshift, exter_value); + } + inter_value = map_pq_exter_to_inter(PQ_COLORSHIFT, exter_value); + } else { + inter_value = full_pq_info.colorshift; + if (!is_valid_pq_inter_value(inter_value)) { + inter_value = + clamps(inter_value, INTER_MIN_PQ, INTER_MAX_PQ); + pr_info("clamps colorshift from %d to %d\n", + full_pq_info.colorshift, inter_value); + } + } + cfg_info[cur_pic_mode].colorshift = inter_value; + + /*-------------set colorshift-----------*/ + if (!set_inter_pq) { + exter_value = full_pq_info.saturation; + if (!is_valid_pq_exter_value(exter_value)) { + exter_value = + clamps(exter_value, EXTER_MIN_PQ, EXTER_MAX_PQ); + pr_info("clamps saturation from %d to %d\n", + full_pq_info.saturation, exter_value); + } + inter_value = map_pq_exter_to_inter(PQ_SATURATION, exter_value); + } else { + inter_value = full_pq_info.saturation; + if (!is_valid_pq_inter_value(inter_value)) { + inter_value = + clamps(inter_value, INTER_MIN_PQ, INTER_MAX_PQ); + pr_info("clamps saturation from %d to %d\n", + full_pq_info.saturation, inter_value); + } + } + cfg_info[cur_pic_mode].saturation = inter_value; + + update_cp_cfg(); + + if (debug_dolby & 0x200) { + pr_info("----------%s: mode:%d----------\n", __func__, mode); + exter_value = map_pq_inter_to_exter(PQ_BRIGHTNESS, + cfg_info[mode].brightness); + pr_info("%s: [inter:%d, exter:%d]\n", + pq_item_str[PQ_BRIGHTNESS], + cfg_info[mode].brightness, + exter_value); + + exter_value = map_pq_inter_to_exter(PQ_CONTRAST, + cfg_info[mode].contrast); + pr_info("%s: [inter:%d, exter:%d]\n", + pq_item_str[PQ_CONTRAST], + cfg_info[mode].contrast, + exter_value); + + exter_value = map_pq_inter_to_exter(PQ_COLORSHIFT, + cfg_info[mode].colorshift); + pr_info("%s: [inter:%d, exter:%d]\n", + pq_item_str[PQ_COLORSHIFT], + cfg_info[mode].colorshift, + exter_value); + + exter_value = map_pq_inter_to_exter(PQ_SATURATION, + cfg_info[mode].saturation); + pr_info("%s: [inter:%d, exter:%d]\n", + pq_item_str[PQ_SATURATION], + cfg_info[mode].saturation, + exter_value); + } +} + +static ssize_t amdolby_vision_set_inter_pq_show + (struct class *cla, + struct class_attribute *attr, + char *buf) +{ + return snprintf(buf, 40, "%d\n", + set_inter_pq); +} + +static ssize_t amdolby_vision_set_inter_pq_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) + +{ + size_t r; + + pr_info("cmd: %s\n", buf); + r = kstrtoint(buf, 0, &set_inter_pq); + if (r != 0) + return -EINVAL; + return count; +} + +static ssize_t amdolby_vision_load_cfg_status_show + (struct class *cla, + struct class_attribute *attr, + char *buf) +{ + return snprintf(buf, 40, "%d\n", + load_bin_config); +} + +static ssize_t amdolby_vision_load_cfg_status_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) +{ + size_t r; + int value = 0; + + pr_info("%s: cmd: %s\n", __func__, buf); + r = kstrtoint(buf, 0, &value); + if (r != 0) + return -EINVAL; + load_bin_config = value; + if (load_bin_config) + update_cp_cfg(); + else + pq_config_set_flag = false; + return count; +} + +static ssize_t amdolby_vision_pq_info_show + (struct class *cla, + struct class_attribute *attr, char *buf) +{ + int pos = 0; + int exter_value = 0; + int inter_value = 0; + int i = 0; + const char *pq_usage_str = { + "\n" + "------------------------- set pq usage ------------------------\n" + "echo picture_mode value > /sys/class/amdolby_vision/dv_pq_info;\n" + "echo brightness value > /sys/class/amdolby_vision/dv_pq_info;\n" + "echo contrast value > /sys/class/amdolby_vision/dv_pq_info;\n" + "echo colorshift value > /sys/class/amdolby_vision/dv_pq_info;\n" + "echo saturation value > /sys/class/amdolby_vision/dv_pq_info;\n" + "echo all v1 v2 v3 v4 v5 > /sys/class/amdolby_vision/dv_pq_info;\n" + "echo reset value > /sys/class/amdolby_vision/dv_pq_info;\n" + "\n" + "picture_mode range: [0, num_picture_mode-1]\n" + "brightness range: [-256, 256]\n" + "contrast range: [-256, 256]\n" + "colorshift range: [-256, 256]\n" + "saturation range: [-256, 256]\n" + "reset 0: reset pict mode/all pq for all pict mode]\n" + " 1: reset pq for all picture mode]\n" + " 2: reset pq for current picture mode]\n" + "---------------------------------------------------------------\n" + }; + + if (!load_bin_config) { + pr_info("no load_bin_config\n"); + return 0; + } + + pos += sprintf(buf + pos, + "\n==== show current picture mode info ====\n"); + + pos += sprintf(buf + pos, + "num_picture_mode: [%d]\n", num_picture_mode); + for (i = 0; i < num_picture_mode; i++) { + pos += sprintf(buf + pos, + "picture_mode %d: [%s]\n", + cfg_info[i].id, cfg_info[i].pic_mode_name); + } + pos += sprintf(buf + pos, "\n\n"); + pos += sprintf(buf + pos, + "current picture mode: [%d]\n", cur_pic_mode); + + pos += sprintf(buf + pos, + "current picture mode name: [%s]\n", + cfg_info[cur_pic_mode].pic_mode_name); + + inter_value = cfg_info[cur_pic_mode].brightness; + exter_value = map_pq_inter_to_exter(PQ_BRIGHTNESS, inter_value); + pos += sprintf(buf + pos, + "current brightness: [inter:%d][exter:%d]\n", + inter_value, exter_value); + + inter_value = cfg_info[cur_pic_mode].contrast; + exter_value = map_pq_inter_to_exter(PQ_CONTRAST, inter_value); + pos += sprintf(buf + pos, + "current contrast: [inter:%d][exter:%d]\n", + inter_value, exter_value); + + inter_value = cfg_info[cur_pic_mode].colorshift; + exter_value = map_pq_inter_to_exter(PQ_COLORSHIFT, inter_value); + pos += sprintf(buf + pos, + "current colorshift: [inter:%d][exter:%d]\n", + inter_value, exter_value); + + inter_value = cfg_info[cur_pic_mode].saturation; + exter_value = map_pq_inter_to_exter(PQ_SATURATION, inter_value); + pos += sprintf(buf + pos, + "current saturation: [inter:%d][exter:%d]\n", + inter_value, exter_value); + pos += sprintf(buf + pos, "========================================\n"); + + pos += sprintf(buf + pos, "%s\n", pq_usage_str); + + return pos; +} + +static ssize_t amdolby_vision_pq_info_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) +{ + char *buf_orig; + char *parm[MAX_PARAM] = {NULL}; + struct dv_full_pq_info_s full_pq_info; + enum pq_reset_e pq_reset; + int val = 0; + int val1 = 0; + int val2 = 0; + int val3 = 0; + int val4 = 0; + int val5 = 0; + int item = -1; + + if (!load_bin_config) + return count; + if (!buf) + return count; + buf_orig = kstrdup(buf, GFP_KERNEL); + + pr_info("%s: cmd: %s\n", __func__, buf_orig); + parse_param_amdolby_vision(buf_orig, (char **)&parm); + if (!parm[0] || !parm[1]) + goto ERR; + + if (!strcmp(parm[0], "picture_mode")) { + if (kstrtoint(parm[1], 10, &val) != 0) + goto ERR; + if (is_valid_pic_mode(val)) + set_pic_mode(val); + else + pr_info("err picture_mode\n"); + } else if (!strcmp(parm[0], "brightness")) { + if (kstrtoint(parm[1], 10, &val) != 0) + goto ERR; + + item = PQ_BRIGHTNESS; + } else if (!strcmp(parm[0], "contrast")) { + if (kstrtoint(parm[1], 10, &val) != 0) + goto ERR; + + item = PQ_CONTRAST; + } else if (!strcmp(parm[0], "colorshift")) { + if (kstrtoint(parm[1], 10, &val) != 0) + goto ERR; + + item = PQ_COLORSHIFT; + } else if (!strcmp(parm[0], "saturation")) { + if (kstrtoint(parm[1], 10, &val) != 0) + goto ERR; + item = PQ_SATURATION; + } else if (!strcmp(parm[0], "all")) { + if (kstrtoint(parm[1], 10, &val1) != 0 || + kstrtoint(parm[2], 10, &val2) != 0 || + kstrtoint(parm[3], 10, &val3) != 0 || + kstrtoint(parm[4], 10, &val4) != 0 || + kstrtoint(parm[5], 10, &val5) != 0) + goto ERR; + full_pq_info.pic_mode_id = val1; + full_pq_info.brightness = val2; + full_pq_info.contrast = val3; + full_pq_info.colorshift = val4; + full_pq_info.saturation = val5; + set_full_pq_value(full_pq_info); + } else if (!strcmp(parm[0], "reset")) { + if (kstrtoint(parm[1], 10, &val) != 0) + goto ERR; + pq_reset = val; + restore_dv_pq_setting(pq_reset); + } else { + pr_info("unsupport cmd\n"); + } + if (item != -1) + set_single_pq_value(cur_pic_mode, item, val); +ERR: + kfree(buf_orig); + return count; +} + +static ssize_t amdolby_vision_bin_config_show + (struct class *cla, + struct class_attribute *attr, + char *buf) +{ + int mode = 0; + struct pq_config *pq_config = NULL; + struct target_config *config = NULL; + + if (!load_bin_config) { + pr_info("no load_bin_config\n"); + return 0; + } + + pr_info("There are %d picture modes\n", num_picture_mode); + for (mode = 0; mode < num_picture_mode; mode++) { + pr_info("================ Picture Mode: %s =================\n", + cfg_info[mode].pic_mode_name); + pq_config = &bin_to_cfg[mode]; + config = &pq_config->tdc; + pr_info("gamma: %d\n", + config->gamma); + pr_info("eotf: %d-%s\n", + config->eotf, + eotf_str[config->eotf]); + pr_info("range_spec: %d\n", + config->range_spec); + pr_info("max_pq: %d\n", + config->max_pq); + pr_info("min_pq: %d\n", + config->min_pq); + pr_info("max_pq_dm3: %d\n", + config->max_pq_dm3); + pr_info("min_lin: %d\n", + config->min_lin); + pr_info("max_lin: %d\n", + config->max_lin); + pr_info("max_lin_dm3: %d\n", + config->max_lin_dm3); + pr_info("tPrimaries: %d,%d,%d,%d,%d,%d,%d,%d\n", + config->t_primaries[0], + config->t_primaries[1], + config->t_primaries[2], + config->t_primaries[3], + config->t_primaries[4], + config->t_primaries[5], + config->t_primaries[6], + config->t_primaries[7]); + pr_info("m_sweight: %d\n", + config->m_sweight); + pr_info("trim_slope_bias: %d\n", + config->trim_slope_bias); + pr_info("trim_offset_bias: %d\n", + config->trim_offset_bias); + pr_info("trim_power_bias: %d\n", + config->trim_power_bias); + pr_info("ms_weight_bias: %d\n", + config->ms_weight_bias); + pr_info("chroma_weight_bias: %d\n", + config->chroma_weight_bias); + pr_info("saturation_gain_bias: %d\n", + config->saturation_gain_bias); + pr_info("d_brightness: %d\n", + config->d_brightness); + pr_info("d_contrast: %d\n", + config->d_contrast); + pr_info("d_color_shift: %d\n", + config->d_color_shift); + pr_info("d_saturation: %d\n", + config->d_saturation); + pr_info("d_backlight: %d\n", + config->d_backlight); + pr_info("dbg_exec_paramsprint: %d\n", + config->dbg_exec_params_print_period); + pr_info("dbg_dm_md_print_period:%d\n", + config->dbg_dm_md_print_period); + pr_info("dbg_dmcfg_print_period:%d\n", + config->dbg_dm_cfg_print_period); + pr_info("\n"); + pr_info("------ Global Dimming configuration ------\n"); + pr_info("gd_enable: %d\n", + config->gd_config.gd_enable); + pr_info("gd_wmin: %d\n", + config->gd_config.gd_wmin); + pr_info("gd_wmax: %d\n", + config->gd_config.gd_wmax); + pr_info("gd_wmm: %d\n", + config->gd_config.gd_wmm); + pr_info("gd_wdyn_rng_sqrt: %d\n", + config->gd_config.gd_wdyn_rng_sqrt); + pr_info("gd_weight_mean: %d\n", + config->gd_config.gd_weight_mean); + pr_info("gd_weight_std: %d\n", + config->gd_config.gd_weight_std); + pr_info("gd_delay_ms_hdmi: %d\n", + config->gd_config.gd_delay_msec_hdmi); + pr_info("gd_rgb2yuv_ext: %d\n", + config->gd_config.gd_rgb2yuv_ext); + pr_info("gd_wdyn_rng_sqrt: %d\n", + config->gd_config.gd_wdyn_rng_sqrt); + pr_info("gd_m33_rgb2yuv: %d,%d,%d\n", + config->gd_config.gd_m33_rgb2yuv[0][0], + config->gd_config.gd_m33_rgb2yuv[0][1], + config->gd_config.gd_m33_rgb2yuv[0][2]); + pr_info(" %d,%d,%d\n", + config->gd_config.gd_m33_rgb2yuv[1][0], + config->gd_config.gd_m33_rgb2yuv[1][1], + config->gd_config.gd_m33_rgb2yuv[1][2]); + pr_info(" %d,%d,%d\n", + config->gd_config.gd_m33_rgb2yuv[2][0], + config->gd_config.gd_m33_rgb2yuv[2][1], + config->gd_config.gd_m33_rgb2yuv[2][2]); + pr_info("gd_m33_rgb2yuv_scale2p:%d\n", + config->gd_config.gd_m33_rgb2yuv_scale2p); + pr_info("gd_rgb2yuv_off_ext: %d\n", + config->gd_config.gd_rgb2yuv_off_ext); + pr_info("gd_rgb2yuv_off: %d,%d,%d\n", + config->gd_config.gd_rgb2yuv_off[0], + config->gd_config.gd_rgb2yuv_off[1], + config->gd_config.gd_rgb2yuv_off[2]); + pr_info("gd_up_bound: %d\n", + config->gd_config.gd_up_bound); + pr_info("gd_low_bound: %d\n", + config->gd_config.gd_low_bound); + pr_info("last_max_pq: %d\n", + config->gd_config.last_max_pq); + pr_info("gd_wmin_pq: %d\n", + config->gd_config.gd_wmin_pq); + pr_info("gd_wmax_pq: %d\n", + config->gd_config.gd_wmax_pq); + pr_info("gd_wm_pq: %d\n", + config->gd_config.gd_wm_pq); + pr_info("gd_trigger_period: %d\n", + config->gd_config.gd_trigger_period); + pr_info("gd_trigger_lin_thresh: %d\n", + config->gd_config.gd_trigger_lin_thresh); + pr_info("gdDelayMilliSec_ott: %d\n", + config->gd_config.gd_delay_msec_ott); + pr_info("gd_rise_weight: %d\n", + config->gd_config.gd_rise_weight); + pr_info("gd_fall_weight: %d\n", + config->gd_config.gd_fall_weight); + pr_info("gd_delay_msec_ll: %d\n", + config->gd_config.gd_delay_msec_ll); + pr_info("gd_contrast: %d\n", + config->gd_config.gd_contrast); + pr_info("\n"); + + pr_info("------ Adaptive boost configuration ------\n"); + pr_info("ab_enable: %d\n", + config->ab_config.ab_enable); + pr_info("ab_highest_tmax: %d\n", + config->ab_config.ab_highest_tmax); + pr_info("ab_lowest_tmax: %d\n", + config->ab_config.ab_lowest_tmax); + pr_info("ab_rise_weight: %d\n", + config->ab_config.ab_rise_weight); + pr_info("ab_fall_weight: %d\n", + config->ab_config.ab_fall_weight); + pr_info("ab_delay_msec_hdmi: %d\n", + config->ab_config.ab_delay_msec_hdmi); + pr_info("ab_delay_msec_ott: %d\n", + config->ab_config.ab_delay_msec_ott); + pr_info("ab_delay_msec_ll: %d\n", + config->ab_config.ab_delay_msec_ll); + pr_info("\n"); + + pr_info("------- Ambient light configuration ------\n"); + pr_info("ambient: %d\n", + config->ambient_config.ambient); + pr_info("t_front_lux: %d\n", + config->ambient_config.t_front_lux); + pr_info("t_front_lux_scale: %d\n", + config->ambient_config.t_front_lux_scale); + pr_info("t_rear_lum: %d\n", + config->ambient_config.t_rear_lum); + pr_info("t_rear_lum_scale: %d\n", + config->ambient_config.t_rear_lum_scale); + pr_info("t_whitexy: %d, %d\n", + config->ambient_config.t_whitexy[0], + config->ambient_config.t_whitexy[1]); + pr_info("t_surround_reflecti:%d\n", + config->ambient_config.t_surround_reflection); + pr_info("t_screen_reflection:%d\n", + config->ambient_config.t_screen_reflection); + pr_info("al_delay: %d\n", + config->ambient_config.al_delay); + pr_info("al_rise: %d\n", + config->ambient_config.al_rise); + pr_info("al_fall: %d\n", + config->ambient_config.al_fall); + + pr_info("vsvdb: %x,%x,%x,%x,%x,%x,%x\n", + config->vsvdb[0], + config->vsvdb[1], + config->vsvdb[2], + config->vsvdb[3], + config->vsvdb[4], + config->vsvdb[5], + config->vsvdb[6]); + pr_info("\n"); + pr_info("---------------- ocsc_config --------------\n"); + pr_info("lms2rgb_mat: %d,%d,%d\n", + config->ocsc_config.lms2rgb_mat[0][0], + config->ocsc_config.lms2rgb_mat[0][1], + config->ocsc_config.lms2rgb_mat[0][2]); + pr_info(" %d,%d,%d\n", + config->ocsc_config.lms2rgb_mat[1][0], + config->ocsc_config.lms2rgb_mat[1][1], + config->ocsc_config.lms2rgb_mat[1][2]); + pr_info(" %d,%d,%d\n", + config->ocsc_config.lms2rgb_mat[2][0], + config->ocsc_config.lms2rgb_mat[2][1], + config->ocsc_config.lms2rgb_mat[2][2]); + pr_info("lms2rgb_mat_scale: %d\n", + config->ocsc_config.lms2rgb_mat_scale); + pr_info("\n"); + + pr_info("dm31_avail: %d\n", + config->dm31_avail); + pr_info("bright_preservation:%d\n", + config->bright_preservation); + pr_info("total_viewing_modes:%d\n", + config->total_viewing_modes_num); + pr_info("viewing_mode_valid: %d\n", + config->viewing_mode_valid); + pr_info("\n"); + } + return 0; +} + bool chip_support_dv(void) { if (is_meson_txlx() || is_meson_gxm() || @@ -9048,10 +11699,15 @@ int register_dv_functions(const struct dolby_vision_func_s *func) int ret = -1; unsigned int reg_clk; unsigned int reg_value; - struct pq_config_s *pq_config; + struct pq_config *pq_cfg; const struct vinfo_s *vinfo = get_current_vinfo(); unsigned int ko_info_len = 0; + if (dolby_vision_probe_ok == 0) { + pr_info("error:(%s) dv probe fail cannot register\n", __func__); + return -ENOMEM; + } + /*when dv ko load into kernel, this flag will be disabled *otherwise it will effect hdr module */ @@ -9086,6 +11742,12 @@ int register_dv_functions(const struct dolby_vision_func_s *func) } } p_funcs_stb = func; + if (is_meson_tm2()) { + tv_dovi_setting = + vmalloc(sizeof(struct tv_dovi_setting_s)); + if (!tv_dovi_setting) + return -ENOMEM; + } } else if (func->tv_control_path && !p_funcs_tv) { pr_info("*** register_dv_tv_functions\n"); if (!ko_info) { @@ -9098,8 +11760,39 @@ int register_dv_functions(const struct dolby_vision_func_s *func) } } p_funcs_tv = func; - } else + if (is_meson_txlx() || is_meson_tm2()) { + pq_cfg = + vmalloc(sizeof(struct pq_config)); + if (!pq_cfg) + return -ENOMEM; + pq_config_fake = + (struct pq_config *)pq_cfg; + tv_dovi_setting = + vmalloc(sizeof(struct tv_dovi_setting_s)); + if (!tv_dovi_setting) { + vfree(pq_config_fake); + pq_config_fake = NULL; + p_funcs_tv = NULL; + return -ENOMEM; + } + tv_dovi_setting->src_format = FORMAT_SDR; + + tv_input_info = + vmalloc(sizeof(struct tv_input_info_s)); + if (!tv_input_info) { + vfree(pq_config_fake); + pq_config_fake = NULL; + p_funcs_tv = NULL; + vfree(tv_dovi_setting); + tv_dovi_setting = NULL; + return -ENOMEM; + } + memset(tv_input_info, 0, + sizeof(struct tv_input_info_s)); + } + } else { return ret; + } ret = 0; /* get efuse flag*/ @@ -9125,6 +11818,9 @@ int register_dv_functions(const struct dolby_vision_func_s *func) support_info = efuse_mode ? 0 : 1;/*bit0=1 => no efuse*/ support_info = support_info | (1 << 1); /*bit1=1 => ko loaded*/ support_info = support_info | (1 << 2); /*bit2=1 => updated*/ + if (tv_mode) + support_info |= 1 << 3; /*bit3=1 => tv*/ + pr_info("dv capability %d\n", support_info); dovi_setting.src_format = FORMAT_SDR; @@ -9133,27 +11829,27 @@ int register_dv_functions(const struct dolby_vision_func_s *func) /*stb core doesn't need run mode*/ /*TV core need run mode and the value is 2*/ if (is_meson_g12() || is_meson_txlx_stbmode() || - is_meson_tm2_stbmode() || force_stb_mode || - is_meson_sc2()) + is_meson_tm2_stbmode() || is_meson_sc2()) dolby_vision_run_mode_delay = 0; else if (is_meson_gxm()) dolby_vision_run_mode_delay = RUN_MODE_DELAY_GXM; else dolby_vision_run_mode_delay = RUN_MODE_DELAY; - if (is_meson_txlx() || is_meson_tm2()) { - pq_config = vmalloc(sizeof(struct pq_config_s)); - if (!pq_config) - return -ENOMEM; - pq_config_fake = (struct pq_config_s *)pq_config; - - tv_dovi_setting = - vmalloc(sizeof(struct tv_dovi_setting_s)); - if (!tv_dovi_setting) - return -ENOMEM; - tv_dovi_setting->src_format = FORMAT_SDR; - } adjust_vpotch(); + adjust_vpotch_tv(); + + if (is_meson_tm2_stbmode() && + p_funcs_tv && !p_funcs_stb) { + /* if tv ko loaded and no stb ko */ + /* turn off stb core and force SDR output */ + set_force_output(BT709); + if (is_dolby_vision_on()) { + pr_dolby_dbg("Switch from STB to TV core ...\n"); + dolby_vision_mode = + DOLBY_VISION_OUTPUT_MODE_BYPASS; + } + } } module_installed = true; return ret; @@ -9167,7 +11863,7 @@ int unregister_dv_functions(void) module_installed = false; if (p_funcs_stb || p_funcs_tv) { - pr_info("*** unregister_dv_functions ***\n"); + pr_info("*** %s ***\n", __func__); if (pq_config_fake) { vfree(pq_config_fake); pq_config_fake = NULL; @@ -9176,6 +11872,14 @@ int unregister_dv_functions(void) vfree(tv_dovi_setting); tv_dovi_setting = NULL; } + if (tv_input_info) { + vfree(tv_input_info); + tv_input_info = NULL; + } + if (bin_to_cfg) { + vfree(bin_to_cfg); + bin_to_cfg = NULL; + } if (ko_info) { vfree(ko_info); ko_info = NULL; @@ -9196,18 +11900,15 @@ void tv_dolby_vision_crc_clear(int flag) setting_update_count = 0; if (!crc_output_buf) crc_output_buf = vmalloc(CRC_BUFF_SIZE); - pr_info( - "tv_dolby_vision_crc_clear, crc_output_buf %p\n", - crc_output_buf); + pr_info("clear crc_output_buf\n"); if (crc_output_buf) memset(crc_output_buf, 0, CRC_BUFF_SIZE); + strcpy(cur_crc, "invalid"); } char *tv_dolby_vision_get_crc(u32 *len) { - if ((!crc_output_buf) || - (!len) || - (crc_output_buff_off == 0)) + if (!crc_output_buf || !len || crc_output_buff_off == 0) return NULL; *len = crc_output_buff_off; return crc_output_buf; @@ -9225,15 +11926,16 @@ void tv_dolby_vision_insert_crc(bool print) crc_count++; return; } - if (is_meson_tvmode() - && !force_stb_mode) { + if (is_meson_tvmode()) { crc_enable = (READ_VPP_DV_REG(DOLBY_TV_DIAG_CTRL) == 0xb); crc = READ_VPP_DV_REG(DOLBY_TV_OUTPUT_DM_CRC); } else { crc_enable = true; /* (READ_VPP_DV_REG(0x36fb) & 1); */ crc = READ_VPP_DV_REG(0x36fd); } - if ((crc == 0) || (crc_enable == false) || (!crc_output_buf)) { + if (debug_dolby & 0x1000) + pr_dolby_dbg("crc_enable %d, crc %x\n", crc_enable, crc); + if (crc == 0 || !crc_enable || !crc_output_buf) { crc_bypass_count++; crc_count++; return; @@ -9246,25 +11948,24 @@ void tv_dolby_vision_insert_crc(bool print) len = strlen(str); str[len] = 0xa; len++; - memcpy( - &crc_output_buf[crc_output_buff_off], - &str[0], len); + memcpy(&crc_output_buf[crc_output_buff_off], + &str[0], len); crc_output_buff_off += len; - if (print || (debug_dolby & 2)) + //if (print || (debug_dolby & 2)) pr_info("%s\n", str); crc_count++; } -void tv_dolby_vision_dma_table_modify(u32 tbl_id, uint64_t value) +void tv_dolby_vision_dma_table_modify(u32 tbl_id, u64 value) { - uint64_t *tbl = NULL; + u64 *tbl = NULL; - if (!dma_vaddr || (tbl_id >= 3754)) { + if (!dma_vaddr || tbl_id >= 3754) { pr_info("No dma table %p to write or id %d overflow\n", dma_vaddr, tbl_id); return; } - tbl = (uint64_t *)dma_vaddr; + tbl = (u64 *)dma_vaddr; pr_info("dma_vaddr:%p, modify table[%d]=0x%llx -> 0x%llx\n", dma_vaddr, tbl_id, tbl[tbl_id], value); tbl[tbl_id] = value; @@ -9272,7 +11973,7 @@ void tv_dolby_vision_dma_table_modify(u32 tbl_id, uint64_t value) void tv_dolby_vision_efuse_info(void) { - if (p_funcs_tv != NULL) { + if (p_funcs_tv) { pr_info("\n dv efuse info:\n"); pr_info("efuse_mode:%d, version: %s\n", efuse_mode, p_funcs_tv->version_info); @@ -9298,70 +11999,69 @@ static int amdolby_vision_open(struct inode *inode, struct file *file) } static char *pq_config_buf; -static uint32_t pq_config_level; -static ssize_t amdolby_vision_write( - struct file *file, +static u32 pq_config_level; +static ssize_t amdolby_vision_write + (struct file *file, const char __user *buf, size_t len, loff_t *off) { int max_len, w_len; - if (pq_config_buf == NULL) { - pq_config_buf = vmalloc(108*1024); + if (!pq_config_buf) { + pq_config_buf = vmalloc(108 * 1024); pq_config_level = 0; - if (pq_config_buf == NULL) + if (!pq_config_buf) return -ENOSPC; } - max_len = sizeof(struct pq_config_s) - pq_config_level; + max_len = sizeof(struct pq_config) - pq_config_level; w_len = len < max_len ? len : max_len; - pr_info("amdolby_vision_write len %d, w_len %d, level %d\n", + pr_info("write len %d, w_len %d, level %d\n", (int)len, w_len, pq_config_level); if (copy_from_user(pq_config_buf + pq_config_level, buf, w_len)) return -EFAULT; pq_config_level += w_len; - if (pq_config_level == sizeof(struct pq_config_s)) { + if (pq_config_level == sizeof(struct pq_config)) { dolby_vision_update_pq_config(pq_config_buf); pq_config_level = 0; } if (len <= 0x1f) { - dolby_vision_update_vsvdb_config( - pq_config_buf, len); + dolby_vision_update_vsvdb_config(pq_config_buf, len); pq_config_level = 0; } return len; } -static ssize_t amdolby_vision_read( - struct file *file, char __user *buf, +static ssize_t amdolby_vision_read + (struct file *file, char __user *buf, size_t count, loff_t *ppos) { char *out; - u32 data_size = 0, res, retVal = -1; + u32 data_size = 0, res, ret_val = -1; if (!is_dolby_vision_enable()) - return retVal; + return ret_val; out = tv_dolby_vision_get_crc(&data_size); if (data_size > CRC_BUFF_SIZE) { pr_err("crc_output_buff_off is out of bound\n"); tv_dolby_vision_crc_clear(0); - return retVal; + return ret_val; } if (out && data_size > 0) { res = copy_to_user((void *)buf, (void *)out, data_size); - retVal = data_size - res; - pr_info( - "amdolby_vision_read crc size %d, res: %d, ret: %d\n", - data_size, res, retVal); + ret_val = data_size - res; + pr_info + ("%s crc size %d, res: %d, ret: %d\n", + __func__, data_size, res, ret_val); tv_dolby_vision_crc_clear(0); } - return retVal; + return ret_val; } static int amdolby_vision_release(struct inode *inode, struct file *file) @@ -9373,9 +12073,189 @@ static int amdolby_vision_release(struct inode *inode, struct file *file) static long amdolby_vision_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - return 0; -} +#define MAX_BYTES (256) + int ret = 0; + int mode_num = 0; + int mode_id = 0; + s16 pq_value = 0; + enum pq_item_e pq_item; + enum pq_reset_e pq_reset; + + struct pic_mode_info_s pic_info; + struct dv_pq_info_s pq_info; + struct dv_full_pq_info_s pq_full_info; + struct dv_config_file_s config_file; + void __user *argp = (void __user *)arg; + unsigned char bin_name[MAX_BYTES] = ""; + unsigned char cfg_name[MAX_BYTES] = ""; + + if (debug_dolby & 0x200) + pr_info("[DV]: %s: cmd_nr = 0x%x\n", + __func__, _IOC_NR(cmd)); + + if (!module_installed) { + pr_info("[DV] module not install\n"); + return ret; + } + + if (!load_bin_config && cmd != DV_IOC_SET_DV_CONFIG_FILE) { + pr_info("[DV] no config file, pq ioctl disable!\n"); + return ret; + } + switch (cmd) { + case DV_IOC_GET_DV_PIC_MODE_NUM: + mode_num = get_pic_mode_num(); + put_user(mode_num, (u32 __user *)argp); + break; + case DV_IOC_GET_DV_PIC_MODE_NAME: + if (copy_from_user(&pic_info, argp, + sizeof(struct pic_mode_info_s)) == 0) { + mode_id = pic_info.pic_mode_id; + strcpy(pic_info.name, get_pic_mode_name(mode_id)); + if (debug_dolby & 0x200) + pr_info("[DV]: get mode %d, name %s\n", + pic_info.pic_mode_id, pic_info.name); + if (copy_to_user(argp, + &pic_info, + sizeof(struct pic_mode_info_s))) + ret = -EFAULT; + } else { + ret = -EFAULT; + } + break; + case DV_IOC_GET_DV_PIC_MODE_ID: + mode_id = get_pic_mode(); + put_user(mode_id, (u32 __user *)argp); + break; + case DV_IOC_SET_DV_PIC_MODE_ID: + if (copy_from_user(&mode_id, argp, sizeof(s32)) == 0) { + if (debug_dolby & 0x200) + pr_info("[DV]: set mode %d\n", mode_id); + set_pic_mode(mode_id); + } else { + ret = -EFAULT; + } + break; + case DV_IOC_GET_DV_SINGLE_PQ_VALUE: + if (copy_from_user(&pq_info, argp, + sizeof(struct dv_pq_info_s)) == 0) { + mode_id = pq_info.pic_mode_id; + pq_item = pq_info.item; + pq_info.value = get_single_pq_value(mode_id, pq_item); + + if (debug_dolby & 0x200) + pr_info("[DV]: get mode %d, pq %s, value %d\n", + mode_id, + pq_item_str[pq_item], + pq_info.value); + + if (copy_to_user(argp, + &pq_info, + sizeof(struct dv_pq_info_s))) + ret = -EFAULT; + } else { + ret = -EFAULT; + } + break; + case DV_IOC_GET_DV_FULL_PQ_VALUE: + if (copy_from_user(&pq_full_info, argp, + sizeof(struct dv_full_pq_info_s)) == 0) { + mode_id = pq_full_info.pic_mode_id; + pq_full_info = get_full_pq_value(mode_id); + + if (copy_to_user(argp, + &pq_full_info, + sizeof(struct dv_full_pq_info_s))) + ret = -EFAULT; + } else { + ret = -EFAULT; + } + break; + case DV_IOC_SET_DV_SINGLE_PQ_VALUE: + if (copy_from_user(&pq_info, argp, + sizeof(struct dv_pq_info_s)) == 0) { + mode_id = pq_info.pic_mode_id; + pq_item = pq_info.item; + pq_value = pq_info.value; + set_single_pq_value(mode_id, pq_item, pq_value); + + if (debug_dolby & 0x200) + pr_info("[DV]: set mode %d, pq %s, value %d\n", + mode_id, + pq_item_str[pq_item], + pq_value); + } else { + ret = -EFAULT; + } + break; + case DV_IOC_SET_DV_FULL_PQ_VALUE: + if (copy_from_user(&pq_full_info, argp, + sizeof(struct dv_full_pq_info_s)) == 0) { + set_full_pq_value(pq_full_info); + } else { + ret = -EFAULT; + } + break; + case DV_IOC_SET_DV_PQ_RESET: + if (copy_from_user(&pq_reset, argp, + sizeof(enum pq_reset_e)) == 0) { + restore_dv_pq_setting(pq_reset); + if (debug_dolby & 0x200) + pr_info("[DV]: reset mode %d\n", pq_reset); + } else { + ret = -EFAULT; + } + break; + case DV_IOC_SET_DV_CONFIG_FILE: + if (copy_from_user(&config_file, argp, + sizeof(struct dv_config_file_s)) == 0) { + if (is_meson_tm2_tvmode() || p_funcs_tv) { + memcpy(bin_name, config_file.bin_name, + MAX_BYTES - 1); + memcpy(cfg_name, config_file.cfg_name, + MAX_BYTES - 1); + bin_name[MAX_BYTES - 1] = '\0'; + cfg_name[MAX_BYTES - 1] = '\0'; + if (load_dv_pq_config_data(bin_name, cfg_name)) + load_bin_config = true; + } + if (debug_dolby & 0x200) + pr_info("[DV]: config_file %s, %s\n", + config_file.bin_name, + config_file.cfg_name); + } else { + ret = -EFAULT; + } + break; + case DV_IOC_CONFIG_DV_BL: + if (copy_from_user(&force_disable_dv_backlight, + argp, sizeof(s32)) == 0) { + if (debug_dolby & 0x200) + pr_info("[DV]: disable dv bl %d\n", + force_disable_dv_backlight); + if (force_disable_dv_backlight) + dolby_vision_disable_backlight(); + else + update_pwm_control(); + } else { + ret = -EFAULT; + } + break; + case DV_IOC_SET_DV_AMBIENT: + if (copy_from_user(&ambient_config_new, argp, + sizeof(struct ambient_cfg_s)) == 0) { + ambient_update = true; + } else { + ret = -EFAULT; + } + break; + default: + ret = -EINVAL; + break; + } + return ret; +} #ifdef CONFIG_COMPAT static long amdolby_vision_compat_ioctl(struct file *file, unsigned int cmd, @@ -9402,44 +12282,39 @@ static const struct file_operations amdolby_vision_fops = { .poll = amdolby_vision_poll, }; -static void parse_param_amdolby_vision(char *buf_orig, char **parm) -{ - char *ps, *token; - unsigned int n = 0; - char delim1[3] = " "; - char delim2[2] = "\n"; - - ps = buf_orig; - strcat(delim1, delim2); - while (1) { - token = strsep(&ps, delim1); - if (token == NULL) - break; - if (*token == '\0') - continue; - parm[n++] = token; - if (n >= MAX_PARAM) - break; - } -} - static const char *amdolby_vision_debug_usage_str = { "Usage:\n" "echo dolby_crc 0/1 > /sys/class/amdolby_vision/debug; dolby_crc insert or clr\n" "echo dolby_dma index(D) value(H) > /sys/class/amdolby_vision/debug; dolby dma table modify\n" "echo dv_efuse > /sys/class/amdolby_vision/debug; get dv efuse info\n" "echo dv_el > /sys/class/amdolby_vision/debug; get dv enhanced layer info\n" + "echo force_support_emp 1/0 > /sys/class/amdolby_vision/debug; send emp\n" + "echo set_backlight_delay 0 > /sys/class/amdolby_vision/debug; set backlight no delay\n" + "echo set_backlight_delay 1 > /sys/class/amdolby_vision/debug; set backlight delay one vysnc\n" + "echo enable_vpu_probe 1 > /sys/class/amdolby_vision/debug; enable vpu probe\n" + "echo debug_bypass_vpp_pq 0 > /sys/class/amdolby_vision/debug; not debug mode\n" + "echo debug_bypass_vpp_pq 1 > /sys/class/amdolby_vision/debug; force disable vpp pq\n" + "echo debug_bypass_vpp_pq 2 > /sys/class/amdolby_vision/debug; force enable vpp pq\n" + "echo bypass_all_vpp_pq 1 > /sys/class/amdolby_vision/debug; force bypass vpp pq in cert mode\n" + "echo enable_vpu_probe 1 > /sys/class/amdolby_vision/debug; enable vpu probe\n" "echo ko_info > /sys/class/amdolby_vision/debug; query ko info\n" + "echo enable_vf_check 1 > /sys/class/amdolby_vision/debug;\n" + "echo enable_vf_check 0 > /sys/class/amdolby_vision/debug;\n" + "echo force_hdmin_fmt value > /sys/class/amdolby_vision/debug; 1:HDR10 2:HLG 3:DV LL\n" + }; -static ssize_t amdolby_vision_debug_show(struct class *cla, - struct class_attribute *attr, char *buf) + +static ssize_t amdolby_vision_debug_show + (struct class *cla, + struct class_attribute *attr, char *buf) { return sprintf(buf, "%s\n", amdolby_vision_debug_usage_str); } -static ssize_t amdolby_vision_debug_store(struct class *cla, - struct class_attribute *attr, - const char *buf, size_t count) +static ssize_t amdolby_vision_debug_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) { char *buf_orig, *parm[MAX_PARAM] = {NULL}; long val = 0; @@ -9463,16 +12338,21 @@ static ssize_t amdolby_vision_debug_store(struct class *cla, return -EINVAL; if (kstrtoul(parm[2], 16, &value) < 0) return -EINVAL; - tv_dolby_vision_dma_table_modify((u32)tbl_id, (uint64_t)value); + tv_dolby_vision_dma_table_modify((u32)tbl_id, (u64)value); } else if (!strcmp(parm[0], "dv_efuse")) { tv_dolby_vision_efuse_info(); } else if (!strcmp(parm[0], "dv_el")) { tv_dolby_vision_el_info(); - } else if (!strcmp(parm[0], "enable_fel")) { +#ifdef V2_4_3 + } else if (!strcmp(parm[0], "force_support_emp")) { if (kstrtoul(parm[1], 10, &val) < 0) return -EINVAL; - enable_fel = val; - pr_info("enable_fel %d\n", enable_fel); + if (val == 0) + force_support_emp = 0; + else + force_support_emp = 1; + pr_info("force_support_emp %d\n", force_support_emp); +#endif } else if (!strcmp(parm[0], "enable_tunnel")) { if (kstrtoul(parm[1], 10, &val) < 0) return -EINVAL; @@ -9495,9 +12375,43 @@ static ssize_t amdolby_vision_debug_store(struct class *cla, vpp_data_422T0444_backup); } } + } else if (!strcmp(parm[0], "debug_bypass_vpp_pq")) { + if (kstrtoul(parm[1], 10, &val) < 0) + return -EINVAL; + debug_bypass_vpp_pq = val; + pr_info("set debug_bypass_vpp_pq %d\n", + debug_bypass_vpp_pq); + } else if (!strcmp(parm[0], "force_cert_bypass_vpp_pq")) { + if (kstrtoul(parm[1], 10, &val) < 0) + return -EINVAL; + if (val == 0) + bypass_all_vpp_pq = 0; + else + bypass_all_vpp_pq = 1; + pr_info("set bypass_all_vpp_pq %d\n", + bypass_all_vpp_pq); + } else if (!strcmp(parm[0], "enable_fel")) { + if (kstrtoul(parm[1], 10, &val) < 0) + return -EINVAL; + enable_fel = val; + pr_info("enable_fel %d\n", enable_fel); } else if (!strcmp(parm[0], "ko_info")) { if (ko_info) pr_info("ko info: %s\n", ko_info); + } else if (!strcmp(parm[0], "enable_vf_check")) { + if (kstrtoul(parm[1], 10, &val) < 0) + return -EINVAL; + if (val == 0) + enable_vf_check = 0; + else + enable_vf_check = 1; + pr_info("set enable_vf_check %d\n", + enable_vf_check); + } else if (!strcmp(parm[0], "force_hdmin_fmt")) { + if (kstrtoul(parm[1], 10, &val) < 0) + return -EINVAL; + force_hdmin_fmt = val; + pr_info("set force_hdmin_fmt %d\n", force_hdmin_fmt); } else { pr_info("unsupport cmd\n"); } @@ -9506,6 +12420,210 @@ static ssize_t amdolby_vision_debug_store(struct class *cla, return count; } +static ssize_t amdolby_vision_primary_show + (struct class *cla, + struct class_attribute *attr, char *buf) +{ + return snprintf(buf, 100, "debug %d, tprimary %d %d %d %d %d %d\n", + debug_tprimary, + cur_debug_tprimary[0][0], cur_debug_tprimary[0][1], + cur_debug_tprimary[1][0], cur_debug_tprimary[1][1], + cur_debug_tprimary[2][0], cur_debug_tprimary[2][1]); +} + +static ssize_t amdolby_vision_primary_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) +{ + char *buf_orig, *parm[MAX_PARAM] = {NULL}; + + if (!buf) + return count; + + buf_orig = kstrdup(buf, GFP_KERNEL); + parse_param_amdolby_vision(buf_orig, (char **)&parm); + if (!strcmp(parm[0], "primary_r")) { + if (kstrtoint(parm[1], 10, &cur_debug_tprimary[0][0]) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if (kstrtoint(parm[2], 10, &cur_debug_tprimary[0][1]) < 0) { + kfree(buf_orig); + return -EINVAL; + } + } else if (!strcmp(parm[0], "primary_g")) { + if (kstrtoint(parm[1], 10, &cur_debug_tprimary[1][0]) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if (kstrtoint(parm[2], 10, &cur_debug_tprimary[1][1]) < 0) { + kfree(buf_orig); + return -EINVAL; + } + } else if (!strcmp(parm[0], "primary_b")) { + if (kstrtoint(parm[1], 10, &cur_debug_tprimary[2][0]) < 0) { + kfree(buf_orig); + return -EINVAL; + } + if (kstrtoint(parm[2], 10, &cur_debug_tprimary[2][1]) < 0) { + kfree(buf_orig); + return -EINVAL; + } + } else if (!strcmp(parm[0], "debug_tprimary")) { + if (kstrtoint(parm[1], 10, &debug_tprimary) < 0) { + kfree(buf_orig); + return -EINVAL; + } + } + kfree(buf_orig); + update_cp_cfg(); + return count; +} + +static ssize_t amdolby_vision_config_file_show + (struct class *cla, + struct class_attribute *attr, char *buf) +{ + const char *str = + "echo bin cfg > /sys/class/amdolby_vision/config_file"; + return sprintf(buf, "%s\n", str); +} + +static ssize_t amdolby_vision_config_file_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) +{ + char *buf_orig, *parm[MAX_PARAM] = {NULL}; + + if (!buf) + return count; + + buf_orig = kstrdup(buf, GFP_KERNEL); + parse_param_amdolby_vision(buf_orig, (char **)&parm); + if (!parm[0] || !parm[1]) { + pr_info("missing parameter... param1:bin param2:cfg\n"); + kfree(buf_orig); + return -EINVAL; + } + pr_info("parm[0]: %s, parm[1]: %s\n", parm[0], parm[1]); + if (is_meson_tm2_tvmode() || p_funcs_tv) { + if (load_dv_pq_config_data(parm[0], parm[1])) + load_bin_config = true; + } + kfree(buf_orig); + return count; +} + +static ssize_t amdolby_vision_content_fps_show + (struct class *cla, + struct class_attribute *attr, char *buf) +{ + return sprintf(buf, "content_fps: %d\n", content_fps); +} + +static ssize_t amdolby_vision_content_fps_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) +{ + size_t r; + + if (!buf) + return count; + + r = kstrtoint(buf, 0, &content_fps); + if (r != 0) + return -EINVAL; + + return count; +} + +static ssize_t amdolby_vision_gd_rf_adjust_show + (struct class *cla, + struct class_attribute *attr, char *buf) +{ + return sprintf(buf, "gd_rf_adjust: %d\n", gd_rf_adjust); +} + +static ssize_t amdolby_vision_gd_rf_adjust_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) +{ + size_t r; + + if (!buf) + return count; + + r = kstrtoint(buf, 0, &gd_rf_adjust); + if (r != 0) + return -EINVAL; + + return count; +} + +static ssize_t amdolby_vision_force_disable_bl_show + (struct class *cla, + struct class_attribute *attr, char *buf) +{ + return sprintf(buf, "force disable dv bl: %d\n", + force_disable_dv_backlight); +} + +static ssize_t amdolby_vision_force_disable_bl_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) +{ + size_t r; + + if (!buf) + return count; + + r = kstrtoint(buf, 0, &force_disable_dv_backlight); + if (r != 0) + return -EINVAL; + + pr_info("update force_disable_dv_backlight to %d\n", + force_disable_dv_backlight); + if (force_disable_dv_backlight) + dolby_vision_disable_backlight(); + else + update_pwm_control(); + + return count; +} + +static ssize_t amdolby_vision_use_cfg_target_lum_show + (struct class *cla, + struct class_attribute *attr, char *buf) +{ + return sprintf(buf, "use_target_lum_from_cfg: %d\n", + use_target_lum_from_cfg); +} + +static ssize_t amdolby_vision_use_cfg_target_lum_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) +{ + size_t r; + + if (!buf) + return count; + + r = kstrtoint(buf, 0, &use_target_lum_from_cfg); + if (r != 0) + return -EINVAL; + + pr_info("update use_target_lum_from_cfg to %d\n", + use_target_lum_from_cfg); + + return count; +} + /* supported mode: IPT_TUNNEL/HDR10/SDR10 */ static const int dv_mode_table[6] = { 5, /*DOLBY_VISION_OUTPUT_MODE_BYPASS*/ @@ -9607,15 +12725,15 @@ unsigned int dolby_vision_check_enable(void) } if (vinfo && vinfo->vout_device && vinfo->vout_device->fresh_tx_vsif_pkt) { - vinfo->vout_device->fresh_tx_vsif_pkt( - 0, 0, NULL, true); + vinfo->vout_device->fresh_tx_vsif_pkt + (0, 0, NULL, true); } enable_dolby_vision(0); dolby_vision_on_in_uboot = 0; } else { dolby_vision_enable = 1; - if ((uboot_dv_mode == dv_mode_table[2]) && - (uboot_dv_source_led_yuv == 1)) { + if (uboot_dv_mode == dv_mode_table[2] && + uboot_dv_source_led_yuv == 1) { /*LL YUV422 mode*/ /*set_dolby_vision_mode(dv_mode);*/ dolby_vision_mode = uboot_dv_mode; @@ -9625,9 +12743,9 @@ unsigned int dolby_vision_check_enable(void) last_dst_format = FORMAT_DOVI; pr_info("dovi enable in uboot and mode is LL 422\n"); } else if ((uboot_dv_mode == - dv_mode_table[2]) && - (uboot_dv_source_led_rgb - == 1)) { + dv_mode_table[2]) && + (uboot_dv_source_led_rgb == + 1)) { /*LL RGB444 mode*/ /*set_dolby_vision_mode(dv_mode);*/ dolby_vision_mode = uboot_dv_mode; @@ -9674,18 +12792,18 @@ unsigned int dolby_vision_check_enable(void) /* core1a */ dv_mem_power_off(VPU_DOLBY1A); dv_mem_power_off(VPU_PRIME_DOLBY_RAM); - VSYNC_WR_DV_REG( - DOLBY_CORE1_CLKGATE_CTRL, + VSYNC_WR_DV_REG + (DOLBY_CORE1_CLKGATE_CTRL, 0x55555455); /* core2 */ dv_mem_power_off(VPU_DOLBY2); - VSYNC_WR_DV_REG( - DOLBY_CORE2A_CLKGATE_CTRL, + VSYNC_WR_DV_REG + (DOLBY_CORE2A_CLKGATE_CTRL, 0x55555555); /* core3 */ dv_mem_power_off(VPU_DOLBY_CORE3); - VSYNC_WR_DV_REG( - DOLBY_CORE3_CLKGATE_CTRL, + VSYNC_WR_DV_REG + (DOLBY_CORE3_CLKGATE_CTRL, 0x55555555); pr_info("g12 dovi disable in uboot\n"); } @@ -9745,9 +12863,11 @@ static ssize_t amdolby_vision_dv_mode_show(struct class *cla, pr_info("current dv_mode = off\n"); return 0; } -static ssize_t amdolby_vision_dv_mode_store(struct class *cla, - struct class_attribute *attr, - const char *buf, size_t count) + +static ssize_t amdolby_vision_dv_mode_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) { size_t r; int val; @@ -9756,7 +12876,7 @@ static ssize_t amdolby_vision_dv_mode_store(struct class *cla, if (r != 0) return -EINVAL; - if ((val >= 0) && (val < 6)) + if (val >= 0 && val < 6) set_dolby_vision_mode(dv_mode_table[val]); else if (val & 0x200) dolby_vision_dump_struct(); @@ -9776,7 +12896,7 @@ static void parse_param(char *buf_orig, char **parm) strcat(delim1, delim2); while (1) { token = strsep(&ps, delim1); - if (token == NULL) + if (!token) break; if (*token == '\0') continue; @@ -9784,9 +12904,10 @@ static void parse_param(char *buf_orig, char **parm) } } -static ssize_t amdolby_vision_reg_store(struct class *cla, - struct class_attribute *attr, - const char *buf, size_t count) +static ssize_t amdolby_vision_reg_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) { char *buf_orig, *parm[8] = {NULL}; long val = 0; @@ -9826,16 +12947,18 @@ static ssize_t amdolby_vision_reg_store(struct class *cla, } -static ssize_t amdolby_vision_core1_switch_show(struct class *cla, - struct class_attribute *attr, char *buf) +static ssize_t amdolby_vision_core1_switch_show + (struct class *cla, + struct class_attribute *attr, char *buf) { return snprintf(buf, 40, "%d\n", core1_switch); } -static ssize_t amdolby_vision_core1_switch_store(struct class *cla, - struct class_attribute *attr, - const char *buf, size_t count) +static ssize_t amdolby_vision_core1_switch_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) { size_t r; u32 reg = 0, mask = 0xfaa1f00, set = 0; @@ -9849,51 +12972,49 @@ static ssize_t amdolby_vision_core1_switch_store(struct class *cla, case NO_SWITCH: reg &= ~mask; set = reg | 0x0c880c00; - VSYNC_WR_DV_REG( - DOLBY_PATH_CTRL, set); + VSYNC_WR_DV_REG(DOLBY_PATH_CTRL, set); break; case SWITCH_BEFORE_DVCORE_1: reg &= ~mask; set = reg | 0x0c881c00; - VSYNC_WR_DV_REG( - DOLBY_PATH_CTRL, set); + VSYNC_WR_DV_REG(DOLBY_PATH_CTRL, set); break; case SWITCH_BEFORE_DVCORE_2: reg &= ~mask; set = reg | 0x0c820300; - VSYNC_WR_DV_REG( - DOLBY_PATH_CTRL, set); + VSYNC_WR_DV_REG(DOLBY_PATH_CTRL, set); break; case SWITCH_AFTER_DVCORE: reg &= ~mask; set = reg | 0x03280c00; - VSYNC_WR_DV_REG( - DOLBY_PATH_CTRL, set); + VSYNC_WR_DV_REG(DOLBY_PATH_CTRL, set); break; } } return count; } -static ssize_t amdolby_vision_core3_switch_show(struct class *cla, - struct class_attribute *attr, char *buf) +static ssize_t amdolby_vision_core3_switch_show + (struct class *cla, + struct class_attribute *attr, char *buf) { return snprintf(buf, 40, "%d\n", core3_switch); } -static ssize_t amdolby_vision_dv_support_info_show( - struct class *cla, - struct class_attribute *attr, char *buf) +static ssize_t amdolby_vision_dv_support_info_show + (struct class *cla, + struct class_attribute *attr, char *buf) { pr_dolby_dbg("show dv capability %d\n", support_info); return snprintf(buf, 40, "%d\n", support_info); } -static ssize_t amdolby_vision_core3_switch_store(struct class *cla, - struct class_attribute *attr, - const char *buf, size_t count) +static ssize_t amdolby_vision_core3_switch_store + (struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) { size_t r; @@ -9903,25 +13024,28 @@ static ssize_t amdolby_vision_core3_switch_store(struct class *cla, if (is_meson_tm2_stbmode()) { switch (core3_switch) { case CORE3_AFTER_WM: - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, - 0, 24, 2); + VSYNC_WR_DV_REG_BITS(VPP_DOLBY_CTRL, + 0, 24, 2); break; case CORE3_AFTER_OSD1_HDR: - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, - 1, 24, 2); + VSYNC_WR_DV_REG_BITS(VPP_DOLBY_CTRL, + 1, 24, 2); break; case CORE3_AFTER_VD2_HDR: - VSYNC_WR_DV_REG_BITS( - VPP_DOLBY_CTRL, - 2, 24, 2); + VSYNC_WR_DV_REG_BITS(VPP_DOLBY_CTRL, + 2, 24, 2); break; } } return count; } +static ssize_t amdolby_vision_crc_show(struct class *cla, + struct class_attribute *attr, char *buf) +{ + return sprintf(buf, "%s\n", cur_crc); +} + static struct class_attribute amdolby_vision_class_attrs[] = { __ATTR(debug, 0644, amdolby_vision_debug_show, amdolby_vision_debug_store), @@ -9933,9 +13057,40 @@ static struct class_attribute amdolby_vision_class_attrs[] = { amdolby_vision_core1_switch_show, amdolby_vision_core1_switch_store), __ATTR(core3_switch, 0644, amdolby_vision_core3_switch_show, amdolby_vision_core3_switch_store), - __ATTR( - support_info, 0444, - amdolby_vision_dv_support_info_show, NULL), + __ATTR(dv_bin_config, 0644, + amdolby_vision_bin_config_show, NULL), + __ATTR(dv_pq_info, 0644, + amdolby_vision_pq_info_show, + amdolby_vision_pq_info_store), + __ATTR(dv_set_inter_pq, 0644, + amdolby_vision_set_inter_pq_show, + amdolby_vision_set_inter_pq_store), + __ATTR(dv_load_cfg_status, 0644, + amdolby_vision_load_cfg_status_show, + amdolby_vision_load_cfg_status_store), + __ATTR(support_info, 0444, + amdolby_vision_dv_support_info_show, NULL), + __ATTR(tprimary, 0644, + amdolby_vision_primary_show, + amdolby_vision_primary_store), + __ATTR(config_file, 0644, + amdolby_vision_config_file_show, + amdolby_vision_config_file_store), + __ATTR(content_fps, 0644, + amdolby_vision_content_fps_show, + amdolby_vision_content_fps_store), + __ATTR(gd_rf_adjust, 0644, + amdolby_vision_gd_rf_adjust_show, + amdolby_vision_gd_rf_adjust_store), + __ATTR(cur_crc, 0644, + amdolby_vision_crc_show, + NULL), + __ATTR(force_disable_dv_backlight, 0644, + amdolby_vision_force_disable_bl_show, + amdolby_vision_force_disable_bl_store), + __ATTR(use_target_lum_from_cfg, 0644, + amdolby_vision_use_cfg_target_lum_show, + amdolby_vision_use_cfg_target_lum_store), __ATTR_NULL }; @@ -10015,25 +13170,35 @@ static int amdolby_vision_probe(struct platform_device *pdev) match = of_match_node(amlogic_dolby_vision_match, of_node); if (match) { dv_meson = (struct dv_device_data_s *)match->data; - if (dv_meson) + if (dv_meson) { memcpy(&dv_meson_dev, dv_meson, - sizeof(struct dv_device_data_s)); - else { + sizeof(struct dv_device_data_s)); + } else { pr_err("%s data NOT match\n", __func__); + dolby_vision_probe_ok = 0; return -ENODEV; } } else { - pr_err("%s NOT match\n", __func__); - return -ENODEV; + pr_err("%s NOT match\n", __func__); + dolby_vision_probe_ok = 0; + return -ENODEV; } ret = of_property_read_u32(of_node, "tv_mode", &val); if (ret) pr_info("Can't find tv_mode.\n"); else tv_mode = val; + if (tv_mode) + support_info |= 1 << 3; } pr_info("\n cpu_id=%d tvmode=%d\n", dv_meson_dev.cpu_id, tv_mode); memset(devp, 0, (sizeof(struct amdolby_vision_dev_s))); + if (is_meson_tm2_tvmode()) { + dolby_vision_hdr10_policy |= HLG_BY_DV_F_SINK; + pr_info("enable DV HLG when follow sink.\n"); + dolby_vision_flags |= FLAG_RX_EMP_VSEM; + pr_info("enable DV VSEM.\n"); + } ret = alloc_chrdev_region(&devp->devno, 0, 1, AMDOLBY_VISION_NAME); if (ret < 0) goto fail_alloc_region; @@ -10065,6 +13230,7 @@ static int amdolby_vision_probe(struct platform_device *pdev) init_waitqueue_head(&devp->dv_queue); pr_info("%s: ok\n", __func__); dolby_vision_check_enable(); + dolby_vision_probe_ok = 1; return 0; fail_create_device: @@ -10085,6 +13251,7 @@ fail_create_class: fail_alloc_region: pr_info("[amdolby_vision.] : amdolby_vision alloc error.\n"); pr_info("[amdolby_vision.] : amdolby_vision_init.\n"); + dolby_vision_probe_ok = 0; return ret; @@ -10099,7 +13266,6 @@ static int __exit amdolby_vision_remove(struct platform_device *pdev) vfree(pq_config_buf); pq_config_buf = NULL; } - for (i = 0; i < 2; i++) { if (md_buf[i]) { vfree(md_buf[i]); @@ -10118,7 +13284,14 @@ static int __exit amdolby_vision_remove(struct platform_device *pdev) drop_comp_buf[i] = NULL; } } - + if (vsem_if_buf) { + vfree(vsem_if_buf); + vsem_if_buf = NULL; + } + if (vsem_md_buf) { + vfree(vsem_md_buf); + vsem_md_buf = NULL; + } device_destroy(devp->clsp, devp->devno); cdev_del(&devp->cdev); class_destroy(devp->clsp); @@ -10150,6 +13323,7 @@ static int __init get_dolby_uboot_status(char *str) } return 0; } + __setup("dolby_vision_on=", get_dolby_uboot_status); static int __init amdolby_vision_init(void) diff --git a/drivers/amlogic/media/enhancement/amdolby_vision/amdolby_vision.h b/drivers/amlogic/media/enhancement/amdolby_vision/amdolby_vision.h index c8e222aad9a4..d1cf265a2b08 100644 --- a/drivers/amlogic/media/enhancement/amdolby_vision/amdolby_vision.h +++ b/drivers/amlogic/media/enhancement/amdolby_vision/amdolby_vision.h @@ -17,37 +17,28 @@ #ifndef _AMDV_H_ #define _AMDV_H_ -#define V1_5 -#define V2_4 /* driver version */ #define DRIVER_VER "20181220" #include -#define DEF_G2L_LUT_SIZE_2P 8 -#define DEF_G2L_LUT_SIZE (1 << DEF_G2L_LUT_SIZE_2P) - -#ifdef V2_4 -#define EXT_MD_AVAIL_LEVEL_1 (1 << 0) -#define EXT_MD_AVAIL_LEVEL_2 (1 << 1) -#define EXT_MD_AVAIL_LEVEL_4 (1 << 2) -#define EXT_MD_AVAIL_LEVEL_5 (1 << 3) -#define EXT_MD_AVAIL_LEVEL_6 (1 << 4) -#define EXT_MD_AVAIL_LEVEL_255 (1 << 31) -#endif -#define PQ2G_LUT_SIZE (4 + 1024 * 4 + 16 * 3) -#define GM_LUT_HDR_SIZE (13 + 2*9) -#define LUT_DIM 17 -#define GM_LUT_SIZE (3 * LUT_DIM * LUT_DIM * LUT_DIM * 2) -#define BACLIGHT_LUT_SIZE 4096 -#define TUNING_LUT_ENTRIES 14 - -#define TUNINGMODE_FORCE_ABSOLUTE 0x1 -#define TUNINGMODE_EXTLEVEL1_DISABLE 0x2 -#define TUNINGMODE_EXTLEVEL2_DISABLE 0x4 -#define TUNINGMODE_EXTLEVEL4_DISABLE 0x8 -#define TUNINGMODE_EXTLEVEL5_DISABLE 0x10 -#define TUNINGMODE_EL_FORCEDDISABLE 0x20 +#define EXT_MD_LEVEL_1 BIT(0) +#define EXT_MD_LEVEL_2 BIT(1) +#define EXT_MD_LEVEL_4 BIT(2) +#define EXT_MD_LEVEL_5 BIT(3) +#define EXT_MD_LEVEL_6 BIT(4) +#define EXT_MD_LEVEL_255 BIT(31) +#define BACKLIGHT_LUT_SIZE 4096 +#define AMBIENT_LUT_SIZE 8 +#define TUNING_LUT_SIZE 14 +#define DM4_TUNING_LUT_SIZE 7 + +#define TUNING_MODE_FORCE_ABSOLUTE 0x1 +#define TUNING_MODE_EXTLEVEL_1_DISABLE 0x2 +#define TUNING_MODE_EXTLEVEL_2_DISABLE 0x4 +#define TUNING_MODE_EXTLEVEL_4_DISABLE 0x8 +#define TUNING_MODE_EXTLEVEL_5_DISABLE 0x10 +#define TUNING_MODE_EL_FORCE_DISABLE 0x20 enum core1_switch_type { NO_SWITCH = 0, @@ -72,144 +63,152 @@ enum core_type { DOLBY_CORE2C, }; -/*! @brief Output CSC configuration.*/ # pragma pack(push, 1) -struct TgtOutCscCfg { - int32_t lms2RgbMat[3][3]; /**<@brief LMS to RGB matrix */ - int32_t lms2RgbMatScale; /**<@brief LMS 2 RGB matrix scale */ - uint8_t whitePoint[3]; /**<@brief White point */ - uint8_t whitePointScale; /**<@brief White point scale */ - int32_t reserved[3]; +struct tgt_out_csc_cfg { + s32 lms2rgb_mat[3][3]; + s32 lms2rgb_mat_scale; + u8 white_point[3]; + u8 white_point_scale; + s32 reserved[3]; }; #pragma pack(pop) -/*! @brief Global dimming configuration.*/ # pragma pack(push, 1) -struct TgtGDCfg { - int32_t gdEnable; - uint32_t gdWMin; - uint32_t gdWMax; - uint32_t gdWMm; - uint32_t gdWDynRngSqrt; - uint32_t gdWeightMean; - uint32_t gdWeightStd; - uint32_t gdDelayMilliSec_hdmi; - int32_t gdRgb2YuvExt; - int32_t gdM33Rgb2Yuv[3][3]; - int32_t gdM33Rgb2YuvScale2P; - int32_t gdRgb2YuvOffExt; - int32_t gdV3Rgb2YuvOff[3]; - uint32_t gdUpBound; - uint32_t gdLowBound; - uint32_t lastMaxPq; - uint16_t gdWMinPq; - uint16_t gdWMaxPq; - uint16_t gdWMmPq; - uint16_t gdTriggerPeriod; - uint32_t gdTriggerLinThresh; - uint32_t gdDelayMilliSec_ott; -#ifdef V1_5 - uint32_t reserved[6]; -#else - uint32_t reserved[9]; -#endif +struct tgt_gc_cfg { + s32 gd_enable; + u32 gd_wmin; + u32 gd_wmax; + u32 gd_wmm; + u32 gd_wdyn_rng_sqrt; + u32 gd_weight_mean; + u32 gd_weight_std; + u32 gd_delay_msec_hdmi; + s32 gd_rgb2yuv_ext; + s32 gd_m33_rgb2yuv[3][3]; + s32 gd_m33_rgb2yuv_scale2p; + s32 gd_rgb2yuv_off_ext; + s32 gd_rgb2yuv_off[3]; + u32 gd_up_bound; + u32 gd_low_bound; + u32 last_max_pq; + u16 gd_wmin_pq; + u16 gd_wmax_pq; + u16 gd_wm_pq; + u16 gd_trigger_period; + u32 gd_trigger_lin_thresh; + u32 gd_delay_msec_ott; + s16 gd_rise_weight; + s16 gd_fall_weight; + u32 gd_delay_msec_ll; + u32 gd_contrast; + u32 reserved[3]; }; #pragma pack(pop) -/*! @defgroup general Enumerations and data structures*/ # pragma pack(push, 1) -struct TargetDisplayConfig { - uint16_t gain; - uint16_t offset; - uint16_t gamma; /**<@brief Gamma */ - uint16_t eotf; - uint16_t bitDepth; /**<@brief Bit Depth */ - uint16_t rangeSpec; - uint16_t diagSize; /**<@brief Diagonal Size */ - uint16_t maxPq; - uint16_t minPq; - uint16_t mSWeight; - uint16_t mSEdgeWeight; - int16_t minPQBias; - int16_t midPQBias; - int16_t maxPQBias; - int16_t trimSlopeBias; - int16_t trimOffsetBias; - int16_t trimPowerBias; - int16_t msWeightBias; - int16_t brightness; /**<@brief Brighness */ - int16_t contrast; /**<@brief Contrast */ - int16_t chromaWeightBias; - int16_t saturationGainBias; - uint16_t chromaWeight; - uint16_t saturationGain; - uint16_t crossTalk; - uint16_t tuningMode; - int16_t reserved0; - int16_t dbgExecParamsPrintPeriod; - int16_t dbgDmMdPrintPeriod; - int16_t dbgDmCfgPrintPeriod; - uint16_t maxPq_dupli; - uint16_t minPq_dupli; - int32_t keyWeight; - int32_t intensityVectorWeight; - int32_t chromaVectorWeight; - int16_t chip_fpga_lowcomplex; - int16_t midPQBiasLut[TUNING_LUT_ENTRIES]; - int16_t saturationGainBiasLut[TUNING_LUT_ENTRIES]; - int16_t chromaWeightBiasLut[TUNING_LUT_ENTRIES]; - int16_t slopeBiasLut[TUNING_LUT_ENTRIES]; - int16_t offsetBiasLut[TUNING_LUT_ENTRIES]; - int16_t backlightBiasLut[TUNING_LUT_ENTRIES]; - struct TgtGDCfg gdConfig; -#ifdef V1_5 - uint8_t vsvdb[7]; - uint8_t reserved1[5]; -#endif - int32_t min_lin; - int32_t max_lin; - int16_t backlight_scaler; - int32_t min_lin_dupli; - int32_t max_lin_dupli; - struct TgtOutCscCfg ocscConfig; -#ifdef V1_5 - int16_t reserved2; -#else - int16_t reserved00; -#endif - int16_t brightnessPreservation; - int32_t iintensityVectorWeight; - int32_t ichromaVectorWeight; - int16_t isaturationGainBias; - int16_t chip_12b_ocsc; - int16_t chip_512_tonecurve; - int16_t chip_nolvl5; - int16_t padding[8]; +struct ambient_cfg { + u32 ambient; + u32 t_front_lux; + u32 t_front_lux_scale; + u32 t_rear_lum; + u32 t_rear_lum_scale; + u32 t_whitexy[2]; + u32 t_surround_reflection; + u32 t_screen_reflection; + u32 al_delay; + u32 al_rise; + u32 al_fall; +}; + +#pragma pack(pop) + +# pragma pack(push, 1) +struct tgt_ab_cfg { + s32 ab_enable; + u32 ab_highest_tmax; + u32 ab_lowest_tmax; + s16 ab_rise_weight; + s16 ab_fall_weight; + u32 ab_delay_msec_hdmi; + u32 ab_delay_msec_ott; + u32 ab_delay_msec_ll; + u32 reserved[3]; }; + +#pragma pack(pop) + +# pragma pack(push, 1) +struct target_config { + u16 gamma; + u16 eotf; + u16 range_spec; + u16 max_pq; + u16 min_pq; + u16 max_pq_dm3; + s32 min_lin; + s32 max_lin; + s32 max_lin_dm3; + s32 t_primaries[8]; + u16 m_sweight; + s16 trim_slope_bias; + s16 trim_offset_bias; + s16 trim_power_bias; + s16 ms_weight_bias; + s16 chroma_weight_bias; + s16 saturation_gain_bias; + u16 tuning_mode; + s16 d_brightness; + s16 d_contrast; + s16 d_color_shift; + s16 d_saturation; + s16 d_backlight; + s16 dbg_exec_params_print_period; + s16 dbg_dm_md_print_period; + s16 dbg_dm_cfg_print_period; + struct tgt_gc_cfg gd_config; + struct tgt_ab_cfg ab_config; + struct ambient_cfg ambient_config; + u8 vsvdb[7]; + u8 dm31_avail; + u8 ref_mode_dark_id; + u8 apply_l11; + u8 reserved1[1]; + s16 backlight_scaler; + struct tgt_out_csc_cfg ocsc_config; + s16 bright_preservation; + u8 total_viewing_modes_num; + u8 viewing_mode_valid; + u32 ambient_frontlux[AMBIENT_LUT_SIZE]; + u32 ambient_complevel[AMBIENT_LUT_SIZE]; + s16 mid_pq_bias_lut[TUNING_LUT_SIZE]; + s16 slope_bias_lut[TUNING_LUT_SIZE]; + s16 backlight_bias_lut[TUNING_LUT_SIZE]; + s16 user_brightness_ui_lut[DM4_TUNING_LUT_SIZE]; + s16 padding2; + s16 blu_pwm[5]; + s16 blu_light[5]; + s16 padding[36]; +}; + #pragma pack(pop) -/*! @brief PQ config main data structure.*/ -struct pq_config_s { - unsigned char default_gm_lut[GM_LUT_HDR_SIZE + GM_LUT_SIZE]; - unsigned char gd_gm_lut_min[GM_LUT_HDR_SIZE + GM_LUT_SIZE]; - unsigned char gd_gm_lut_max[GM_LUT_HDR_SIZE + GM_LUT_SIZE]; - unsigned char pq2gamma[sizeof(int32_t)*PQ2G_LUT_SIZE]; - unsigned char backlight_lut[BACLIGHT_LUT_SIZE]; - struct TargetDisplayConfig target_display_config; +struct pq_config { + unsigned char backlight_lut[BACKLIGHT_LUT_SIZE]; + struct target_config tdc; }; -enum input_mode_e { - INPUT_MODE_OTT = 0, - INPUT_MODE_HDMI = 1 +enum input_mode_enum { + IN_MODE_OTT = 0, + IN_MODE_HDMI = 1 }; -struct ui_menu_params_s { - uint16_t u16BackLightUIVal; - uint16_t u16BrightnessUIVal; - uint16_t u16ContrastUIVal; +struct ui_menu_params { + u16 u16_backlight_ui_val; + u16 u16_brightness_ui_val; + u16 u16_contrast_ui_val; }; -enum signal_format_e { +enum signal_format_enum { FORMAT_INVALID = -1, FORMAT_DOVI = 0, FORMAT_HDR10 = 1, @@ -218,338 +217,309 @@ enum signal_format_e { FORMAT_HLG = 4, FORMAT_HDR10PLUS = 5, FORMAT_SDR_2020 = 6, - FORMAT_MVC = 7 -}; - -enum priority_mode_e { - VIDEO_PRIORITY = 0, - GRAPHIC_PRIORITY = 1, - /* same as video priority, but will only switch to video*/ - /* priority after scene refresh flag has been received */ - VIDEO_PRIORITY_DELAYED = 2 -}; - -enum cp_signal_range_e { - SIG_RANGE_SMPTE = 0, /* head range */ - SIG_RANGE_FULL = 1, /* full range */ - SIG_RANGE_SDI = 2 /* PQ */ -}; - -enum graphics_format_e { - GF_SDR_YUV = 0, /* BT.709 YUV BT1886 */ - GF_SDR_RGB = 1, /* BT.709 RGB BT1886 */ - GF_HDR_YUV = 2, /* BT.2020 YUV PQ */ - GF_HDR_RGB = 3 /* BT.2020 RGB PQ */ -}; - -struct run_mode_s { - uint16_t width; - uint16_t height; - uint16_t el_width; - uint16_t el_height; - uint16_t hdmi_mode; -}; - -struct composer_register_ipcore_s { - /* offset 0xc8 */ - uint32_t Composer_Mode; - uint32_t VDR_Resolution; - uint32_t Bit_Depth; - uint32_t Coefficient_Log2_Denominator; - uint32_t BL_Num_Pivots_Y; - uint32_t BL_Pivot[5]; - uint32_t BL_Order; - uint32_t BL_Coefficient_Y[8][3]; - uint32_t EL_NLQ_Offset_Y; - uint32_t EL_Coefficient_Y[3]; - uint32_t Mapping_IDC_U; - uint32_t BL_Num_Pivots_U; - uint32_t BL_Pivot_U[3]; - uint32_t BL_Order_U; - uint32_t BL_Coefficient_U[4][3]; - uint32_t MMR_Coefficient_U[22][2]; - uint32_t MMR_Order_U; - uint32_t EL_NLQ_Offset_U; - uint32_t EL_Coefficient_U[3]; - uint32_t Mapping_IDC_V; - uint32_t BL_Num_Pivots_V; - uint32_t BL_Pivot_V[3]; - uint32_t BL_Order_V; - uint32_t BL_Coefficient_V[4][3]; - uint32_t MMR_Coefficient_V[22][2]; - uint32_t MMR_Order_V; - uint32_t EL_NLQ_Offset_V; - uint32_t EL_Coefficient_V[3]; -}; - -/** @brief DM registers for IPCORE 1 */ -struct dm_register_ipcore_1_s { - uint32_t SRange; - uint32_t Srange_Inverse; - uint32_t Frame_Format_1; - uint32_t Frame_Format_2; - uint32_t Frame_Pixel_Def; - uint32_t Y2RGB_Coefficient_1; - uint32_t Y2RGB_Coefficient_2; - uint32_t Y2RGB_Coefficient_3; - uint32_t Y2RGB_Coefficient_4; - uint32_t Y2RGB_Coefficient_5; - uint32_t Y2RGB_Offset_1; - uint32_t Y2RGB_Offset_2; - uint32_t Y2RGB_Offset_3; - uint32_t EOTF; -/* uint32_t Sparam_1;*/ -/* uint32_t Sparam_2;*/ -/* uint32_t Sgamma; */ - uint32_t A2B_Coefficient_1; - uint32_t A2B_Coefficient_2; - uint32_t A2B_Coefficient_3; - uint32_t A2B_Coefficient_4; - uint32_t A2B_Coefficient_5; - uint32_t C2D_Coefficient_1; - uint32_t C2D_Coefficient_2; - uint32_t C2D_Coefficient_3; - uint32_t C2D_Coefficient_4; - uint32_t C2D_Coefficient_5; - uint32_t C2D_Offset; - uint32_t Active_area_left_top; - uint32_t Active_area_bottom_right; -}; - -/** @brief DM registers for IPCORE 2 */ -struct dm_register_ipcore_2_s { - uint32_t SRange; - uint32_t Srange_Inverse; - uint32_t Y2RGB_Coefficient_1; - uint32_t Y2RGB_Coefficient_2; - uint32_t Y2RGB_Coefficient_3; - uint32_t Y2RGB_Coefficient_4; - uint32_t Y2RGB_Coefficient_5; - uint32_t Y2RGB_Offset_1; - uint32_t Y2RGB_Offset_2; - uint32_t Y2RGB_Offset_3; - uint32_t Frame_Format; - uint32_t EOTF; - uint32_t A2B_Coefficient_1; - uint32_t A2B_Coefficient_2; - uint32_t A2B_Coefficient_3; - uint32_t A2B_Coefficient_4; - uint32_t A2B_Coefficient_5; - uint32_t C2D_Coefficient_1; - uint32_t C2D_Coefficient_2; - uint32_t C2D_Coefficient_3; - uint32_t C2D_Coefficient_4; - uint32_t C2D_Coefficient_5; - uint32_t C2D_Offset; - uint32_t VDR_Resolution; -}; - -/** @brief DM registers for IPCORE 3 */ -struct dm_register_ipcore_3_s { - uint32_t D2C_coefficient_1; - uint32_t D2C_coefficient_2; - uint32_t D2C_coefficient_3; - uint32_t D2C_coefficient_4; - uint32_t D2C_coefficient_5; - uint32_t B2A_Coefficient_1; - uint32_t B2A_Coefficient_2; - uint32_t B2A_Coefficient_3; - uint32_t B2A_Coefficient_4; - uint32_t B2A_Coefficient_5; - uint32_t Eotf_param_1; - uint32_t Eotf_param_2; - uint32_t IPT_Scale; - uint32_t IPT_Offset_1; - uint32_t IPT_Offset_2; - uint32_t IPT_Offset_3; - uint32_t Output_range_1; - uint32_t Output_range_2; - uint32_t RGB2YUV_coefficient_register1; - uint32_t RGB2YUV_coefficient_register2; - uint32_t RGB2YUV_coefficient_register3; - uint32_t RGB2YUV_coefficient_register4; - uint32_t RGB2YUV_coefficient_register5; - uint32_t RGB2YUV_offset_0; - uint32_t RGB2YUV_offset_1; - uint32_t RGB2YUV_offset_2; -}; - -/** @brief DM luts for IPCORE 1 and 2 */ -struct dm_lut_ipcore_s { - uint32_t TmLutI[64*4]; - uint32_t TmLutS[64*4]; - uint32_t SmLutI[64*4]; - uint32_t SmLutS[64*4]; - uint32_t G2L[DEF_G2L_LUT_SIZE]; -}; - -/** @brief hdmi metadata for IPCORE 3 */ -struct md_reister_ipcore_3_s { - uint32_t raw_metadata[512]; - uint32_t size; -}; - -struct hdr_10_infoframe_s { - uint8_t infoframe_type_code; - uint8_t infoframe_version_number; - uint8_t length_of_info_frame; - uint8_t data_byte_1; - uint8_t data_byte_2; - uint8_t display_primaries_x_0_LSB; - uint8_t display_primaries_x_0_MSB; - uint8_t display_primaries_y_0_LSB; - uint8_t display_primaries_y_0_MSB; - uint8_t display_primaries_x_1_LSB; - uint8_t display_primaries_x_1_MSB; - uint8_t display_primaries_y_1_LSB; - uint8_t display_primaries_y_1_MSB; - uint8_t display_primaries_x_2_LSB; - uint8_t display_primaries_x_2_MSB; - uint8_t display_primaries_y_2_LSB; - uint8_t display_primaries_y_2_MSB; - uint8_t white_point_x_LSB; - uint8_t white_point_x_MSB; - uint8_t white_point_y_LSB; - uint8_t white_point_y_MSB; - uint8_t max_display_mastering_luminance_LSB; - uint8_t max_display_mastering_luminance_MSB; - uint8_t min_display_mastering_luminance_LSB; - uint8_t min_display_mastering_luminance_MSB; - uint8_t max_content_light_level_LSB; - uint8_t max_content_light_level_MSB; - uint8_t max_frame_average_light_level_LSB; - uint8_t max_frame_average_light_level_MSB; -}; - -struct hdr10_param_s { - uint32_t min_display_mastering_luminance; - uint32_t max_display_mastering_luminance; - uint16_t Rx; - uint16_t Ry; - uint16_t Gx; - uint16_t Gy; - uint16_t Bx; - uint16_t By; - uint16_t Wx; - uint16_t Wy; - uint16_t max_content_light_level; - uint16_t max_pic_average_light_level; -}; - -#ifdef V2_4 -struct ext_level_1_s { - uint8_t min_PQ_hi; - uint8_t min_PQ_lo; - uint8_t max_PQ_hi; - uint8_t max_PQ_lo; - uint8_t avg_PQ_hi; - uint8_t avg_PQ_lo; -}; - -struct ext_level_2_s { - uint8_t target_max_PQ_hi; - uint8_t target_max_PQ_lo; - uint8_t trim_slope_hi; - uint8_t trim_slope_lo; - uint8_t trim_offset_hi; - uint8_t trim_offset_lo; - uint8_t trim_power_hi; - uint8_t trim_power_lo; - uint8_t trim_chroma_weight_hi; - uint8_t trim_chroma_weight_lo; - uint8_t trim_saturation_gain_hi; - uint8_t trim_saturation_gain_lo; - uint8_t ms_weight_hi; - uint8_t ms_weight_lo; -}; - -struct ext_level_4_s { - uint8_t anchor_PQ_hi; - uint8_t anchor_PQ_lo; - uint8_t anchor_power_hi; - uint8_t anchor_power_lo; -}; - -struct ext_level_5_s { - uint8_t active_area_left_offset_hi; - uint8_t active_area_left_offset_lo; - uint8_t active_area_right_offset_hi; - uint8_t active_area_right_offset_lo; - uint8_t active_area_top_offset_hi; - uint8_t active_area_top_offset_lo; - uint8_t active_area_bottom_offset_hi; - uint8_t active_area_bottom_offset_lo; -}; - -struct ext_level_6_s { - uint8_t max_display_mastering_luminance_hi; - uint8_t max_display_mastering_luminance_lo; - uint8_t min_display_mastering_luminance_hi; - uint8_t min_display_mastering_luminance_lo; - uint8_t max_content_light_level_hi; - uint8_t max_content_light_level_lo; - uint8_t max_frame_average_light_level_hi; - uint8_t max_frame_average_light_level_lo; -}; - -struct ext_level_255_s { - uint8_t dm_run_mode; - uint8_t dm_run_version; - uint8_t dm_debug0; - uint8_t dm_debug1; - uint8_t dm_debug2; - uint8_t dm_debug3; + FORMAT_MVC = 7, + FORMAT_CUVA = 8 +}; + +enum priority_mode_enum { + V_PRIORITY = 0, + G_PRIORITY = 1, + VIDEO_PRIORITY_DELAY = 2 +}; + +enum cp_signal_range_enum { + SIGNAL_RANGE_SMPTE = 0, + SIGNAL_RANGE_FULL = 1, + SIGNAL_RANGE_SDI = 2 +}; + +enum graphics_format_enum { + G_SDR_YUV = 0, + G_SDR_RGB = 1, + G_HDR_YUV = 2, + G_HDR_RGB = 3 +}; + +struct dm_reg_ipcore2 { + u32 s_range; + u32 s_range_inverse; + u32 y2rgb_coeff1; + u32 y2rgb_coeff2; + u32 y2rgb_coeff3; + u32 y2rgb_coeff4; + u32 y2rgb_coeff5; + u32 y2rgb_off1; + u32 y2rgb_off2; + u32 y2rgb_off3; + u32 frame_fmt; + u32 eotf; + u32 a2b_coeff1; + u32 a2b_coeff2; + u32 a2b_coeff3; + u32 a2b_coeff4; + u32 a2b_coeff5; + u32 c2d_coeff1; + u32 c2d_coeff2; + u32 c2d_coeff3; + u32 c2d_coeff4; + u32 c2d_coeff5; + u32 c2d_off; + u32 vdr_res; +}; + +struct dm_reg_ipcore3 { + u32 d2c_coeff1; + u32 d2c_coeff2; + u32 d2c_coeff3; + u32 d2c_coeff4; + u32 d2c_coeff5; + u32 b2a_coeff1; + u32 b2a_coeff2; + u32 b2a_coeff3; + u32 b2a_coeff4; + u32 b2a_coeff5; + u32 eotf_param1; + u32 eotf_param2; + u32 ipt_scale; + u32 ipt_off1; + u32 ipt_off2; + u32 ipt_off3; + u32 output_range1; + u32 output_range2; + u32 rgb2yuv_coeff_reg1; + u32 rgb2yuv_coeff_reg2; + u32 rgb2yuv_coeff_reg3; + u32 rgb2yuv_coeff_reg4; + u32 rgb2yuv_coeff_reg5; + u32 rgb2yuv_off0; + u32 rgb2yuv_off1; + u32 rgb2yuv_off2; +}; + +/*hdmi metadata for core3 */ +struct md_reg_ipcore3 { + u32 raw_metadata[512]; + u32 size; +}; + +struct hdr10_infoframe { + u8 type_code; + u8 version_number; + u8 len_of_info_frame; + u8 data_byte1; + u8 data_byte2; + u8 primaries_x_0_lsb; + u8 primaries_x_0_msb; + u8 primaries_y_0_lsb; + u8 primaries_y_0_msb; + u8 primaries_x_1_lsb; + u8 primaries_x_1_msb; + u8 primaries_y_1_lsb; + u8 primaries_y_1_msb; + u8 primaries_x_2_lsb; + u8 primaries_x_2_msb; + u8 primaries_y_2_lsb; + u8 primaries_y_2_msb; + u8 white_point_x_lsb; + u8 white_point_x_msb; + u8 white_point_y_lsb; + u8 white_point_y_msb; + u8 max_display_mastering_lum_lsb; + u8 max_display_mastering_lum_msb; + u8 min_display_mastering_lum_lsb; + u8 min_display_mastering_lum_msb; + u8 max_content_light_level_lsb; + u8 max_content_light_level_msb; + u8 max_frame_avg_light_level_lsb; + u8 max_frame_avg_light_level_msb; +}; + +struct hdr10_parameter { + u32 min_display_mastering_lum; + u32 max_display_mastering_lum; + u16 r_x; + u16 r_y; + u16 g_x; + u16 g_y; + u16 b_x; + u16 b_y; + u16 w_x; + u16 w_y; + u16 max_content_light_level; + u16 max_frame_avg_light_level; +}; + +struct ext_level_1 { + u8 min_pq_h; + u8 min_pq_l; + u8 max_pq_h; + u8 max_pq_l; + u8 avg_pq_h; + u8 avg_pq_l; +}; + +struct ext_level_2 { + u8 target_max_pq_h; + u8 target_max_pq_l; + u8 trim_slope_h; + u8 trim_slope_l; + u8 trim_off_h; + u8 trim_off_l; + u8 trim_power_h; + u8 trim_power_l; + u8 trim_chroma_weight_h; + u8 trim_chroma_weight_l; + u8 trim_sat_gain_h; + u8 trim_sat_gain_l; + u8 ms_weight_h; + u8 ms_weight_l; +}; + +struct ext_level_4 { + u8 anchor_pq_h; + u8 anchor_pq_l; + u8 anchor_power_h; + u8 anchor_power_l; +}; + +struct ext_level_5 { + u8 active_area_left_off_h; + u8 active_area_left_off_l; + u8 active_area_right_off_h; + u8 active_area_right_off_l; + u8 active_area_top_off_h; + u8 active_area_top_off_l; + u8 active_area_bot_off_h; + u8 active_area_bot_off_l; +}; + +struct ext_level_6 { + u8 max_display_mastering_lum_h; + u8 max_display_mastering_lum_l; + u8 min_display_mastering_lum_h; + u8 min_display_mastering_lum_l; + u8 max_content_light_level_h; + u8 max_content_light_level_l; + u8 max_frame_avg_light_level_h; + u8 max_frame_avg_light_level_l; +}; + +struct ext_level_254 { + u8 mode; + u8 version_index; +}; + +struct ext_level_255 { + u8 run_mode; + u8 run_version; + u8 dm_debug_0; + u8 dm_debug_1; + u8 dm_debug_2; + u8 dm_debug_3; }; struct ext_md_s { - uint32_t available_level_mask; - struct ext_level_1_s level_1; - struct ext_level_2_s level_2; - struct ext_level_4_s level_4; - struct ext_level_5_s level_5; - struct ext_level_6_s level_6; - struct ext_level_255_s level_255; + u32 avail_level_mask; + struct ext_level_1 level_1; + struct ext_level_2 level_2; + struct ext_level_4 level_4; + struct ext_level_5 level_5; + struct ext_level_6 level_6; + struct ext_level_255 level_255; }; -#endif struct dovi_setting_s { - struct composer_register_ipcore_s comp_reg; - struct dm_register_ipcore_1_s dm_reg1; - struct dm_register_ipcore_2_s dm_reg2; - struct dm_register_ipcore_3_s dm_reg3; - struct dm_lut_ipcore_s dm_lut1; - struct dm_lut_ipcore_s dm_lut2; + struct composer_reg_ipcore comp_reg; + struct dm_reg_ipcore1 dm_reg1; + struct dm_reg_ipcore2 dm_reg2; + struct dm_reg_ipcore3 dm_reg3; + struct dm_lut_ipcore dm_lut1; + struct dm_lut_ipcore dm_lut2; /* for dovi output */ - struct md_reister_ipcore_3_s md_reg3; + struct md_reg_ipcore3 md_reg3; /* for hdr10 output */ - struct hdr_10_infoframe_s hdr_info; + struct hdr10_infoframe hdr_info; /* current process */ - enum signal_format_e src_format; - enum signal_format_e dst_format; + enum signal_format_enum src_format; + enum signal_format_enum dst_format; /* enhanced layer */ bool el_flag; bool el_halfsize_flag; /* frame width & height */ - uint32_t video_width; - uint32_t video_height; -#ifdef V2_4 + u32 video_width; + u32 video_height; /* use for stb 2.4 */ - enum graphics_format_e g_format; - uint32_t g_bitdepth; - uint32_t dovi2hdr10_nomapping; - uint32_t use_ll_flag; - uint32_t ll_rgb_desired; - uint32_t diagnostic_enable; - uint32_t diagnostic_mux_select; - uint32_t dovi_ll_enable; - uint32_t vout_width; - uint32_t vout_height; + enum graphics_format_enum g_format; + u32 g_bitdepth; + u32 dovi2hdr10_nomapping; + u32 use_ll_flag; + u32 ll_rgb_desired; + u32 diagnostic_enable; + u32 diagnostic_mux_select; + u32 dovi_ll_enable; + u32 vout_width; + u32 vout_height; u8 vsvdb_tbl[32]; struct ext_md_s ext_md; - uint32_t vsvdb_len; - uint32_t vsvdb_changed; - uint32_t mode_changed; -#endif + u32 vsvdb_len; + u32 vsvdb_changed; + u32 mode_changed; +}; + +struct dv_cfg_info_s { + int id; + char pic_mode_name[32]; + s16 brightness; /*Brightness */ + s16 contrast; /*Contrast */ + s16 colorshift; /*ColorShift or Tint*/ + s16 saturation; /*Saturation or color */ + u8 vsvdb[7]; +}; + +struct dv_pq_center_value_s { + s16 brightness; /*Brightness */ + s16 contrast; /*Contrast */ + s16 colorshift; /*ColorShift or Tint*/ + s16 saturation; /*Saturation or color */ +}; + +struct dv_pq_range_s { + s16 left; + s16 right; +}; + +struct tv_input_info_s { + s16 brightness_off[8][2]; + s32 content_fps; + s32 gd_rf_adjust; + s32 debug_buf[498]; +}; + +#define PREFIX_SEI_NUT_NAL 39 +#define SUFFIX_SEI_NUT_NAL 40 +#define SEI_TYPE_USERDATA_REGISTERED_ITUT_T35 4 +#define SEI_TYPE_MASTERING_DISP_COLOUR_VOLUME 137 + +#define MAX_LEN_2086_SEI 256 +#define MAX_LEN_2094_SEI 256 + +/* vui params for ATSC 3.0*/ +struct dv_vui_parameters { + s32 video_fmt_i; + s32 video_fullrange_b; + s32 color_description_b; + s32 color_primaries_i; + s32 trans_characteristic_i; + s32 matrix_coeff_i; +}; + +/* atsc related params.*/ +struct dv_atsc { + struct dv_vui_parameters vui_param; + u32 len_2086_sei; + u8 sei_2086[MAX_LEN_2086_SEI]; + u32 len_2094_sei; + u8 sei_2094[MAX_LEN_2094_SEI]; }; enum cpuID_e { @@ -573,99 +543,108 @@ struct amdolby_vision_port_t { void *runtime; }; -extern int control_path( - enum signal_format_e in_format, - enum signal_format_e out_format, - char *in_comp, int in_comp_size, - char *in_md, int in_md_size, - enum priority_mode_e set_priority, - int set_bit_depth, int set_chroma_format, int set_yuv_range, - int set_graphic_min_lum, int set_graphic_max_lum, - int set_target_min_lum, int set_target_max_lum, - int set_no_el, - struct hdr10_param_s *hdr10_param, - struct dovi_setting_s *output); +int control_path + (enum signal_format_enum in_format, + enum signal_format_enum out_format, + char *in_comp, int in_comp_size, + char *in_md, int in_md_size, + enum priority_mode_enum set_priority, + int set_bit_depth, int set_chroma_format, int set_yuv_range, + int set_graphic_min_lum, int set_graphic_max_lum, + int set_target_min_lum, int set_target_max_lum, + int set_no_el, + struct hdr10_parameter *hdr10_param, + struct dovi_setting_s *output); struct tv_dovi_setting_s { - uint64_t core1_reg_lut[3754]; + u64 core1_reg_lut[3754]; /* current process */ - enum signal_format_e src_format; - enum signal_format_e dst_format; + enum signal_format_enum src_format; + enum signal_format_enum dst_format; /* enhanced layer */ bool el_flag; bool el_halfsize_flag; /* frame width & height */ - uint32_t video_width; - uint32_t video_height; - enum input_mode_e input_mode; -}; - -extern int tv_control_path( - enum signal_format_e in_format, - enum input_mode_e in_mode, - char *in_comp, int in_comp_size, - char *in_md, int in_md_size, - int set_bit_depth, int set_chroma_format, int set_yuv_range, - struct pq_config_s *pq_config, - struct ui_menu_params_s *menu_param, - int set_no_el, - struct hdr10_param_s *hdr10_param, - struct tv_dovi_setting_s *output); - -extern void *metadata_parser_init(int flag); -extern int metadata_parser_reset(int flag); -extern int metadata_parser_process( - char *src_rpu, int rpu_len, - char *dst_comp, int *comp_len, - char *dst_md, int *md_len, bool src_eos); -extern void metadata_parser_release(void); + u32 video_width; + u32 video_height; + enum input_mode_enum input_mode; + u16 backlight; +}; + +int tv_control_path + (enum signal_format_enum in_format, + enum input_mode_enum in_mode, + char *in_comp, int in_comp_size, + char *in_md, int in_md_size, + int set_bit_depth, int set_chroma_format, int set_yuv_range, + struct pq_config *pq_config, + struct ui_menu_params *menu_param, + int set_no_el, + struct hdr10_parameter *hdr10_param, + struct tv_dovi_setting_s *output, + char *vsem_if, int vsem_if_size, + struct ambient_cfg_s *ambient_cfg, + struct tv_input_info_s *input_info); + +void *metadata_parser_init(int flag); +int metadata_parser_reset(int flag); +int metadata_parser_process + (char *src_rpu, int rpu_len, + char *dst_comp, int *comp_len, + char *dst_md, int *md_len, bool src_eos); +void metadata_parser_release(void); struct dolby_vision_func_s { const char *version_info; void * (*metadata_parser_init)(int flag); + /*flag: bit0 flag, bit1 0->dv, 1->atsc*/ int (*metadata_parser_reset)(int flag); - int (*metadata_parser_process)( - char *src_rpu, int rpu_len, - char *dst_comp, int *comp_len, - char *dst_md, int *md_len, bool src_eos); + int (*metadata_parser_process) + (char *src_rpu, int rpu_len, + char *dst_comp, int *comp_len, + char *dst_md, int *md_len, bool src_eos); void (*metadata_parser_release)(void); - int (*control_path)( - enum signal_format_e in_format, - enum signal_format_e out_format, - char *in_comp, int in_comp_size, - char *in_md, int in_md_size, - enum priority_mode_e set_priority, - int set_bit_depth, int set_chroma_format, int set_yuv_range, - int set_graphic_min_lum, int set_graphic_max_lum, - int set_target_min_lum, int set_target_max_lum, - int set_no_el, - struct hdr10_param_s *hdr10_param, - struct dovi_setting_s *output); - int (*tv_control_path)( - enum signal_format_e in_format, - enum input_mode_e in_mode, - char *in_comp, int in_comp_size, - char *in_md, int in_md_size, - int set_bit_depth, int set_chroma_format, int set_yuv_range, - struct pq_config_s *pq_config, - struct ui_menu_params_s *menu_param, - int set_no_el, - struct hdr10_param_s *hdr10_param, - struct tv_dovi_setting_s *output); -}; - -extern int register_dv_functions(const struct dolby_vision_func_s *func); -extern int unregister_dv_functions(void); + int (*control_path) + (enum signal_format_enum in_format, + enum signal_format_enum out_format, + char *in_comp, int in_comp_size, + char *in_md, int in_md_size, + enum priority_mode_enum set_priority, + int set_bit_depth, int set_chroma_format, int set_yuv_range, + int set_graphic_min_lum, int set_graphic_max_lum, + int set_target_min_lum, int set_target_max_lum, + int set_no_el, + struct hdr10_parameter *hdr10_param, + struct dovi_setting_s *output); + int (*tv_control_path) + (enum signal_format_enum in_format, + enum input_mode_enum in_mode, + char *in_comp, int in_comp_size, + char *in_md, int in_md_size, + int set_bit_depth, int set_chroma_format, int set_yuv_range, + struct pq_config *pq_config, + struct ui_menu_params *menu_param, + int set_no_el, + struct hdr10_parameter *hdr10_param, + struct tv_dovi_setting_s *output, + char *vsem_if, int vsem_if_size, + struct ambient_cfg_s *ambient_cfg, + struct tv_input_info_s *input_info); +}; + +int register_dv_functions(const struct dolby_vision_func_s *func); +int unregister_dv_functions(void); #ifndef CONFIG_AMLOGIC_MEDIA_VSYNC_RDMA #define VSYNC_WR_MPEG_REG(adr, val) WRITE_VPP_REG(adr, val) #define VSYNC_RD_MPEG_REG(adr) READ_VPP_REG(adr) #define VSYNC_WR_MPEG_REG_BITS(adr, val, start, len) \ WRITE_VPP_REG_BITS(adr, val, start, len) #else -extern int VSYNC_WR_MPEG_REG_BITS(u32 adr, u32 val, u32 start, u32 len); -extern u32 VSYNC_RD_MPEG_REG(u32 adr); -extern int VSYNC_WR_MPEG_REG(u32 adr, u32 val); +int VSYNC_WR_MPEG_REG_BITS(u32 adr, u32 val, u32 start, u32 len); +u32 VSYNC_RD_MPEG_REG(u32 adr); +int VSYNC_WR_MPEG_REG(u32 adr, u32 val); #endif + void dv_mem_power_on(enum vpu_mod_e mode); void dv_mem_power_off(enum vpu_mod_e mode); int get_dv_mem_power_flag(enum vpu_mod_e mode); diff --git a/drivers/amlogic/media/enhancement/amvecm/arch/vpp_dolbyvision_regs.h b/drivers/amlogic/media/enhancement/amvecm/arch/vpp_dolbyvision_regs.h index 8d202bdff8ad..774bb29e41b0 100644 --- a/drivers/amlogic/media/enhancement/amvecm/arch/vpp_dolbyvision_regs.h +++ b/drivers/amlogic/media/enhancement/amvecm/arch/vpp_dolbyvision_regs.h @@ -107,7 +107,6 @@ #define DOLBY_TV_CRC_CTRL (0xea + CORETV_OFFSET) #define DOLBY_TV_OUTPUT_DM_CRC (0xef + CORETV_OFFSET) - #define VPP_WRAP_OSD1_MATRIX_EN_CTRL 0x3d6d #define VPP_WRAP_OSD2_MATRIX_EN_CTRL 0x3d7d #define VPP_WRAP_OSD3_MATRIX_EN_CTRL 0x3dbd @@ -121,138 +120,4 @@ #define VPU_422T0444_CTRL2 0x274d #define VPU_422T0444_RST 0x274a -#if 0 -/* core 1 display manager 24 registers */ -struct dm_register_ipcore_1_s { - uint32_t SRange; - uint32_t Srange_Inverse; - uint32_t Frame_Format_1; - uint32_t Frame_Format_2; - uint32_t Frame_Pixel_Def; - uint32_t Y2RGB_Coefficient_1; - uint32_t Y2RGB_Coefficient_2; - uint32_t Y2RGB_Coefficient_3; - uint32_t Y2RGB_Coefficient_4; - uint32_t Y2RGB_Coefficient_5; - uint32_t Y2RGB_Offset_1; - uint32_t Y2RGB_Offset_2; - uint32_t Y2RGB_Offset_3; - uint32_t EOTF; - uint32_t A2B_Coefficient_1; - uint32_t A2B_Coefficient_2; - uint32_t A2B_Coefficient_3; - uint32_t A2B_Coefficient_4; - uint32_t A2B_Coefficient_5; - uint32_t C2D_Coefficient_1; - uint32_t C2D_Coefficient_2; - uint32_t C2D_Coefficient_3; - uint32_t C2D_Coefficient_4; - uint32_t C2D_Coefficient_5; -}; - -/* core 1 composer 173 registers */ -struct composer_register_ipcore_s { - uint32_t Composer_Mode; - uint32_t VDR_Resolution; - uint32_t Bit_Depth; - uint32_t Coefficient_Log2_Denominator; - uint32_t BL_Num_Pivots_Y; - uint32_t BL_Pivot[5]; - uint32_t BL_Order; - uint32_t BL_Coefficient_Y[8][3]; - uint32_t EL_NLQ_Offset_Y; - uint32_t EL_Coefficient_Y[3]; - uint32_t Mapping_IDC_U; - uint32_t BL_Num_Pivots_U; - uint32_t BL_Pivot_U[3]; - uint32_t BL_Order_U; - uint32_t BL_Coefficient_U[4][3]; - uint32_t MMR_Coefficient_U[22][2]; - uint32_t MMR_Order_U; - uint32_t EL_NLQ_Offset_U; - uint32_t EL_Coefficient_U[3]; - uint32_t Mapping_IDC_V; - uint32_t BL_Num_Pivots_V; - uint32_t BL_Pivot_V[3]; - uint32_t BL_Order_V; - uint32_t BL_Coefficient_V[4][3]; - uint32_t MMR_Coefficient_V[22][2]; - uint32_t MMR_Order_V; - uint32_t EL_NLQ_Offset_V; - uint32_t EL_Coefficient_V[3]; -}; - -/* core 2 display manager 24 registers */ -struct dm_register_ipcore_2_s { - uint32_t SRange; - uint32_t Srange_Inverse; - uint32_t Y2RGB_Coefficient_1; - uint32_t Y2RGB_Coefficient_2; - uint32_t Y2RGB_Coefficient_3; - uint32_t Y2RGB_Coefficient_4; - uint32_t Y2RGB_Coefficient_5; - uint32_t Y2RGB_Offset_1; - uint32_t Y2RGB_Offset_2; - uint32_t Y2RGB_Offset_3; - uint32_t Frame_Format; - uint32_t EOTF; - uint32_t A2B_Coefficient_1; - uint32_t A2B_Coefficient_2; - uint32_t A2B_Coefficient_3; - uint32_t A2B_Coefficient_4; - uint32_t A2B_Coefficient_5; - uint32_t C2D_Coefficient_1; - uint32_t C2D_Coefficient_2; - uint32_t C2D_Coefficient_3; - uint32_t C2D_Coefficient_4; - uint32_t C2D_Coefficient_5; - uint32_t C2D_Offset; - uint32_t VDR_Resolution; -}; - -/* core 3 display manager 26 registers */ -struct dm_register_ipcore_3_s { - uint32_t D2C_coefficient_1; - uint32_t D2C_coefficient_2; - uint32_t D2C_coefficient_3; - uint32_t D2C_coefficient_4; - uint32_t D2C_coefficient_5; - uint32_t B2A_Coefficient_1; - uint32_t B2A_Coefficient_2; - uint32_t B2A_Coefficient_3; - uint32_t B2A_Coefficient_4; - uint32_t B2A_Coefficient_5; - uint32_t Eotf_param_1; - uint32_t Eotf_param_2; - uint32_t IPT_Scale; - uint32_t IPT_Offset_1; - uint32_t IPT_Offset_2; - uint32_t IPT_Offset_3; - uint32_t Output_range_1; - uint32_t Output_range_2; - uint32_t RGB2YUV_coefficient_register1; - uint32_t RGB2YUV_coefficient_register2; - uint32_t RGB2YUV_coefficient_register3; - uint32_t RGB2YUV_coefficient_register4; - uint32_t RGB2YUV_coefficient_register5; - uint32_t RGB2YUV_offset_0; - uint32_t RGB2YUV_offset_1; - uint32_t RGB2YUV_offset_2; -}; - -/* lut 5 * 256 for core 1 and core 2 */ -struct dm_lut_ipcore_s { - uint32_t TmLutI[64*4]; - uint32_t TmLutS[64*4]; - uint32_t SmLutI[64*4]; - uint32_t SmLutS[64*4]; - uint32_t G2L[256]; -}; - -/* core 3 metadata 128 registers */ -struct md_reister_ipcore_3_s { - uint32_t raw_metadata[128]; -}; -#endif - #endif diff --git a/drivers/amlogic/media/vout/hdmitx/hdmi_tx_20/dv_emp_vsem.c b/drivers/amlogic/media/vout/hdmitx/hdmi_tx_20/dv_emp_vsem.c index a0be4c9b525a..6f650ff3b049 100644 --- a/drivers/amlogic/media/vout/hdmitx/hdmi_tx_20/dv_emp_vsem.c +++ b/drivers/amlogic/media/vout/hdmitx/hdmi_tx_20/dv_emp_vsem.c @@ -54,9 +54,9 @@ #include "dv_emp_vsem.h" #undef pr_fmt -#define pr_fmt(fmt) "dvemp: " fmt +#define pr_fmt(fmt) "emp: " fmt -static unsigned int crc32_lut[256] = { +static unsigned int crc32_lut_table[256] = { 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7, @@ -102,47 +102,44 @@ static unsigned int crc32_lut[256] = { 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 }; -void SetByteField(unsigned char *meta_byte, - unsigned char field_value, - unsigned char field_mask) +void set_byte(unsigned char *meta, + unsigned char value, + unsigned char mask) { unsigned int count; unsigned int test_val; unsigned int set_val; unsigned char test_mask; - test_mask = field_mask; + test_mask = mask; count = 0; while ((test_mask > 0) && (count < 8)) { test_val = 1 << count; - if ((test_val & field_mask) == test_val) { - set_val = (field_value & 1); - field_value >>= 1; + if ((test_val & mask) == test_val) { + set_val = (value & 1); + value >>= 1; if (set_val > 0) - *meta_byte |= 1 << count; + *meta |= 1 << count; else - *meta_byte &= ~(1 << count); + *meta &= ~(1 << count); test_mask &= ~(1 << count); } count++; } } -/* given metadata length, figure out how many packets are needed */ -unsigned int vsem_get_num_packets(unsigned int metadata_len, - unsigned int *last_packet_len) +u32 get_vsem_pkt_num(u32 metadata_len, u32 *last_packet_len) { - unsigned int num_packets = 1; + u32 num_packets = 1; if (metadata_len == 0) return 0; - /* how many packets are needed */ *last_packet_len = metadata_len; - if (*last_packet_len > VSEM_FIRST_PACKET_EDR_DATA_LEN) { - *last_packet_len -= VSEM_FIRST_PACKET_EDR_DATA_LEN; - while (*last_packet_len > VSEM_PACKET_BODY_LEN) { - *last_packet_len -= VSEM_PACKET_BODY_LEN; + if (*last_packet_len > VSEM_FIRST_PKT_EDR_DATA_SIZE) { + *last_packet_len -= VSEM_FIRST_PKT_EDR_DATA_SIZE; + while (*last_packet_len > VSEM_PKT_BODY_SIZE) { + *last_packet_len -= VSEM_PKT_BODY_SIZE; num_packets++; } if (*last_packet_len > 0) @@ -152,13 +149,13 @@ unsigned int vsem_get_num_packets(unsigned int metadata_len, return num_packets; } -unsigned int crc32(unsigned int crc, const void *buf, unsigned int size) +unsigned int get_crc32(u32 crc, const void *buf, u32 size) { - const unsigned char *p = (unsigned char *)buf; + const u8 *p = (u8 *)buf; crc = ~crc; while (size) { - crc = (crc << 8) ^ crc32_lut[((crc >> 24) ^ *p) & 0xff]; + crc = (crc << 8) ^ crc32_lut_table[((crc >> 24) ^ *p) & 0xff]; p++; size--; } @@ -171,10 +168,10 @@ static int pack_vsemds(struct emp_edr_config *pconfig, int metadata_len, unsigned char data_version) { - struct vsem_data_packet *cur_packet; + struct vsem_pkt *cur_pkt; int count, acrc_loc, frt_loc; unsigned int p; - unsigned int num_packets = 1; + unsigned int num_pkts = 1; unsigned int last_packet_len = 0; unsigned int cur_packet_len; unsigned int crc; @@ -183,128 +180,127 @@ static int pack_vsemds(struct emp_edr_config *pconfig, unsigned char PB0; unsigned char HB1; - edr_data_len = metadata_len + VSEM_CRC_LENGTH; + edr_data_len = metadata_len + VSEM_CRC_LEN; pcrcfrt = NULL; - /* how many packets are needed */ - num_packets = vsem_get_num_packets(edr_data_len, &last_packet_len); - if (num_packets > MAX_VSEM_NUM) + num_pkts = get_vsem_pkt_num(edr_data_len, &last_packet_len); + if (num_pkts > MAX_VSEM_NUM) pr_info("vsem metada_len is too big\n"); - /* allocate packets memory */ - pconfig->num_packets = num_packets; + pconfig->num_packets = num_pkts; if (pconfig->vsem_packets == NULL) { pr_info("vsem_packets don't alloc\n"); return -1; } - memset(pconfig->vsem_packets, 0, - sizeof(struct vsem_data_packet) * num_packets); + memset(pconfig->vsem_packets, 0, sizeof(struct vsem_pkt) * num_pkts); - /*compute CRC*/ - crc = crc32(0, p_metadata, metadata_len); + crc = get_crc32(0, p_metadata, metadata_len); - /* process the first packet */ + /* first pkt */ p = 0; - cur_packet = &pconfig->vsem_packets[p]; - pcrc = cur_packet->PB; - cur_packet->packet_type = 0x7F; + cur_pkt = &pconfig->vsem_packets[p]; + pcrc = cur_pkt->pb; + cur_pkt->pkt_type = 0x7F; HB1 = 0; - SetByteField(&HB1, 1, FIELD_MASK_FIRST); - SetByteField(&HB1, 0, FIELD_MASK_LAST); - cur_packet->HB1 = HB1; - cur_packet->sequence_index = p; + set_byte(&HB1, 1, FIELD_FIRST); + set_byte(&HB1, 0, FIELD_LAST); + cur_pkt->hb1 = HB1; + cur_pkt->seq_index = p; edr_data_len += 6; /* PB0~12 */ PB0 = 0; - SetByteField(&PB0, 1, FIELD_MASK_NEW); - SetByteField(&PB0, 1, FIELD_MASK_END); - SetByteField(&PB0, 2, FIELD_MASK_DS_TYPE); - SetByteField(&PB0, 1, FIELD_MASK_AFR); - SetByteField(&PB0, 1, FIELD_MASK_VFR); - SetByteField(&PB0, 1, FIELD_MASK_SYNC); - cur_packet->PB[0] = PB0; - cur_packet->PB[1] = 0x00; /* Reserved */ - cur_packet->PB[2] = 0x00; /* Organization ID */ - cur_packet->PB[3] = 0x00; /* Data Set Tag hi = 0 */ - cur_packet->PB[4] = 0x00; /* Data Set Tag low = 0 */ - cur_packet->PB[5] = edr_data_len >> 8; /* Data Set Length hi */ - cur_packet->PB[6] = edr_data_len & 0xff; /* Data Set Length low */ - cur_packet->PB[7] = 0x46; /* MD0 */ - cur_packet->PB[8] = 0xD0; /* MD1 */ - cur_packet->PB[9] = 0x00; /* MD2 */ - cur_packet->PB[10] = data_version; /* data_version */ - cur_packet->PB[11] = 0x00; /* Reserved */ - cur_packet->PB[12] = 0x00; /* Reserved */ - cur_packet_len = VSEM_FIRST_PACKET_EDR_DATA_LEN; + set_byte(&PB0, 1, FIELD_NEW); + set_byte(&PB0, 1, FIELD_END); + set_byte(&PB0, 2, FIELD_DS_TYPE); + set_byte(&PB0, 1, FIELD_AFR); + set_byte(&PB0, 1, FIELD_VFR); + set_byte(&PB0, 1, FIELD_SYNC); + cur_pkt->pb[0] = PB0; + cur_pkt->pb[1] = 0x00; + cur_pkt->pb[2] = 0x00; + cur_pkt->pb[3] = 0x00; + cur_pkt->pb[4] = 0x00; + cur_pkt->pb[5] = edr_data_len >> 8; + cur_pkt->pb[6] = edr_data_len & 0xff; + cur_pkt->pb[7] = 0x46; + cur_pkt->pb[8] = 0xD0; + cur_pkt->pb[9] = 0x00; + cur_pkt->pb[10] = data_version; + cur_pkt->pb[11] = 0x00; + cur_pkt->pb[12] = 0x00; + cur_packet_len = VSEM_FIRST_PKT_EDR_DATA_SIZE; if (cur_packet_len > metadata_len) cur_packet_len = metadata_len; - memcpy(&cur_packet->PB[13], p_metadata, cur_packet_len); - pcrc = &cur_packet->PB[13]; + memcpy(&cur_pkt->pb[13], p_metadata, cur_packet_len); + pcrc = &cur_pkt->pb[13]; p_metadata += cur_packet_len; metadata_len -= cur_packet_len; - num_packets--; + num_pkts--; p++; - /* process following packets */ - while (num_packets > 0) { + /*other pkts */ + while (num_pkts > 0) { if (p == 1) frt_loc = 13 + cur_packet_len - 1; else frt_loc = cur_packet_len - 1; pcrcfrt = - &pconfig->vsem_packets[p - 1].PB[frt_loc]; - cur_packet = &pconfig->vsem_packets[p]; - cur_packet->packet_type = 0x7F; + &pconfig->vsem_packets[p - 1].pb[frt_loc]; + cur_pkt = &pconfig->vsem_packets[p]; + cur_pkt->pkt_type = 0x7F; HB1 = 0x00; - SetByteField(&HB1, 0, FIELD_MASK_FIRST); - if (num_packets == 1) { - SetByteField(&HB1, 1, FIELD_MASK_LAST); + set_byte(&HB1, 0, FIELD_FIRST); + if (num_pkts == 1) { + set_byte(&HB1, 1, FIELD_LAST); cur_packet_len = last_packet_len; } else { - SetByteField(&HB1, 0, FIELD_MASK_LAST); - cur_packet_len = VSEM_PACKET_BODY_LEN; + set_byte(&HB1, 0, FIELD_LAST); + cur_packet_len = VSEM_PKT_BODY_SIZE; } - cur_packet->HB1 = HB1; - cur_packet->sequence_index = (unsigned char)p; + cur_pkt->hb1 = HB1; + cur_pkt->seq_index = (unsigned char)p; if (metadata_len > 0) { if (metadata_len >= cur_packet_len) { - memcpy(cur_packet->PB, p_metadata, cur_packet_len); + memcpy(cur_pkt->pb, + p_metadata, cur_packet_len); metadata_len -= cur_packet_len; p_metadata += cur_packet_len; } else { - memcpy(cur_packet->PB, p_metadata, metadata_len); + memcpy(cur_pkt->pb, + p_metadata, metadata_len); p_metadata += metadata_len; metadata_len = 0; } } - pcrc = &cur_packet->PB[0]; - num_packets--; + pcrc = &cur_pkt->pb[0]; + num_pkts--; p++; } - /*write CRC*/ + /*crc*/ acrc[0] = (crc & 0xff000000) >> 24; acrc[1] = (crc & 0xff0000) >> 16; acrc[2] = (crc & 0xff00) >> 8; acrc[3] = crc & 0xff; - if (last_packet_len >= VSEM_CRC_LENGTH) { - pcrc += last_packet_len - VSEM_CRC_LENGTH; + if (last_packet_len >= VSEM_CRC_LEN) { + pcrc += last_packet_len - VSEM_CRC_LEN; for (count = 0; count < 4; count++) { pcrc[count] = acrc[count]; } } else { if (pcrcfrt != NULL) { - /*last packet*/ - pcrc = &cur_packet->PB[0]; + /*last pkt*/ + pcrc = &cur_pkt->pb[0]; for (count = last_packet_len - 1; count >= 0; count--) { - /*VSEM_CRC_LENGTH - 1 - (last_packet_len - 1 - count)*/ - acrc_loc = VSEM_CRC_LENGTH - last_packet_len + count; + /*LEN - 1 - (last_packet_len - 1 - count)*/ + acrc_loc = VSEM_CRC_LEN - + last_packet_len + count; pcrc[count] = acrc[acrc_loc]; } - /*the packet before last packet*/ - pcrcfrt -= VSEM_CRC_LENGTH - last_packet_len; + /*the pkt before last pkt*/ + pcrcfrt -= VSEM_CRC_LEN - last_packet_len; pcrcfrt++; for (count = 0; - count < VSEM_CRC_LENGTH - last_packet_len; + count < VSEM_CRC_LEN - last_packet_len; count++) { pcrcfrt[count] = acrc[count]; } @@ -313,25 +309,25 @@ static int pack_vsemds(struct emp_edr_config *pconfig, return 0; } -static struct dv_emp_hdmi_cfg dv_emp_cfg_val; -static void hdmitx_set_dv_emp_pkt(struct emp_edr_config *pconfig) +static struct emp_hdmi_cfg emp_cfg_val; +static void hdmitx_set_emp_pkt(struct emp_edr_config *pconfig) { struct hdmitx_dev *hdev; - hdev = dv_emp_cfg_val.hdev; + hdev = emp_cfg_val.hdev; hdev->hwop.cntlconfig(hdev, CONF_EMP_PHY_ADDR, pconfig->phys_ptr); hdev->hwop.cntlconfig(hdev, CONF_EMP_NUMBER, pconfig->num_packets); } -static void hdmitx_disable_dv_emp_pkt(void) +static void hdmitx_disable_emp_pkt(void) { struct hdmitx_dev *hdev; - hdev = dv_emp_cfg_val.hdev; + hdev = emp_cfg_val.hdev; hdev->hwop.cntlconfig(hdev, CONF_EMP_NUMBER, 0); } -static void hdmitx_emp_dv_infoframe(struct hdmitx_dev *hdev, +static void hdmitx_emp_infoframe(struct hdmitx_dev *hdev, enum eotf_type type, enum eotf_type type_save, bool signal_sdr) @@ -385,7 +381,7 @@ static void hdmitx_emp_dv_infoframe(struct hdmitx_dev *hdev, } } -int send_dv_emp(enum eotf_type type, +int send_emp(enum eotf_type type, enum mode_type tunnel_mode, struct dv_vsif_para *vsif_data, unsigned char *p_vsem, @@ -394,7 +390,7 @@ int send_dv_emp(enum eotf_type type, { struct emp_edr_config config; int rv; - struct hdmitx_dev *hdev = dv_emp_cfg_val.hdev; + struct hdmitx_dev *hdev = emp_cfg_val.hdev; unsigned char data_version = 0; static enum eotf_type type_save = EOTF_T_NULL; static bool vsem_flag = false; @@ -417,12 +413,12 @@ int send_dv_emp(enum eotf_type type, pr_info("EMP hdmitx_set_vsif_pkt: type = %d\n", type); hdr_status_pos = 2; hdev->hdmi_current_eotf_type = type; - hdmitx_emp_dv_infoframe(hdev, type, type_save, signal_sdr); + hdmitx_emp_infoframe(hdev, type, type_save, signal_sdr); type_save = type; if ((type != EOTF_T_DOLBYVISION) && (type != EOTF_T_LL_MODE)) { if (vsem_flag == true) { /*exit from Dolby VS-EMDS*/ - hdmitx_disable_dv_emp_pkt(); + hdmitx_disable_emp_pkt(); } else { /*exit from Dolby VSIF*/ hdmitx_set_vsif_pkt(type, tunnel_mode, vsif_data, signal_sdr); } @@ -441,36 +437,36 @@ int send_dv_emp(enum eotf_type type, dma_sync_single_for_cpu( hdev->hdtx_dev, - dv_emp_cfg_val.pkts_phy_addr, - dv_emp_cfg_val.size, + emp_cfg_val.pkts_phy_addr, + emp_cfg_val.size, DMA_TO_DEVICE); config.num_packets = 0; - config.phys_ptr = dv_emp_cfg_val.pkts_phy_addr; - config.vsem_packets = dv_emp_cfg_val.p_pkts; + config.phys_ptr = emp_cfg_val.pkts_phy_addr; + config.vsem_packets = emp_cfg_val.p_pkts; rv = pack_vsemds(&config, p_vsem, vsem_len, data_version); if (rv != 0) { pr_info("pack_vsem fail!\n"); return -1; } - /*Disable Dolby VSIF send*/ + /*Disable VSIF send*/ hdev->hwop.setpacket(HDMI_PACKET_VEND, NULL, NULL); - /*Enable Dolby VS-EMDS send*/ + /*Enable VS-EMDS send*/ dma_sync_single_for_device( hdev->hdtx_dev, - dv_emp_cfg_val.pkts_phy_addr, - dv_emp_cfg_val.size, + emp_cfg_val.pkts_phy_addr, + emp_cfg_val.size, DMA_TO_DEVICE); - hdmitx_set_dv_emp_pkt(&config); - } else { /*Dolby VSIF or HDMI 14b VSIF*/ + hdmitx_set_emp_pkt(&config); + } else { vsem_flag = false; - /*Disable Dolby VS-EMDS send*/ - hdmitx_disable_dv_emp_pkt(); - /*Enable Dolby VSIF send*/ + /*Disable VS-EMDS send*/ + hdmitx_disable_emp_pkt(); + /*Enable VSIF send*/ hdmitx_set_vsif_pkt(type, tunnel_mode, vsif_data, signal_sdr); } return 1; } -EXPORT_SYMBOL(send_dv_emp); +EXPORT_SYMBOL(send_emp); void vsem_init_cfg(struct hdmitx_dev *hdev) { @@ -478,7 +474,7 @@ void vsem_init_cfg(struct hdmitx_dev *hdev) void *virt_ptr; dma_addr_t paddr; - alloc_len = sizeof(struct vsem_data_packet) * MAX_VSEM_NUM; + alloc_len = sizeof(struct vsem_pkt) * MAX_VSEM_NUM; alloc_size = (alloc_len + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); virt_ptr = kmalloc(alloc_size, GFP_KERNEL | GFP_DMA); @@ -494,9 +490,9 @@ void vsem_init_cfg(struct hdmitx_dev *hdev) return; } - dv_emp_cfg_val.hdev = hdev; - dv_emp_cfg_val.p_pkts = (struct vsem_data_packet *)virt_ptr; - dv_emp_cfg_val.pkts_phy_addr = paddr; - dv_emp_cfg_val.size = alloc_size; - dv_emp_cfg_val.send_vsemds = send_dv_emp; + emp_cfg_val.hdev = hdev; + emp_cfg_val.p_pkts = (struct vsem_pkt *)virt_ptr; + emp_cfg_val.pkts_phy_addr = paddr; + emp_cfg_val.size = alloc_size; + emp_cfg_val.send_vsemds = send_emp; } diff --git a/drivers/amlogic/media/vout/hdmitx/hdmi_tx_20/dv_emp_vsem.h b/drivers/amlogic/media/vout/hdmitx/hdmi_tx_20/dv_emp_vsem.h index 82f7073fad96..3b214a831e64 100644 --- a/drivers/amlogic/media/vout/hdmitx/hdmi_tx_20/dv_emp_vsem.h +++ b/drivers/amlogic/media/vout/hdmitx/hdmi_tx_20/dv_emp_vsem.h @@ -20,44 +20,41 @@ #ifndef _EDR_METADATA_OVER_HDMI_H_ #define _EDR_METADATA_OVER_HDMI_H_ -#define VSEM_CRC_LENGTH 4 #define VSIF_PAYLOAD_LEN 24 -#define VSEM_PACKET_BODY_LEN 28 -#define VSEM_FIRST_PACKET_EDR_DATA_LEN 15 +#define VSEM_PKT_BODY_SIZE 28 +#define VSEM_FIRST_PKT_EDR_DATA_SIZE 15 +#define VSEM_CRC_LEN 4 -struct vsem_data_packet { - unsigned char packet_type; - unsigned char HB1; - unsigned char sequence_index; - unsigned char PB[VSEM_PACKET_BODY_LEN]; +struct vsem_pkt { + unsigned char pkt_type; + unsigned char hb1; + unsigned char seq_index; + unsigned char pb[VSEM_PKT_BODY_SIZE]; unsigned char padding; }; + #define MAX_VSEM_NUM 128 -#define MAX_VSEM_SIZE (MAX_VSEM_NUM * sizeof(struct vsem_data_packet)) +#define MAX_VSEM_SIZE (MAX_VSEM_NUM * sizeof(struct vsem_pkt)) -/* header field masks */ -/* second header byte */ -#define FIELD_MASK_FIRST 0x80 -#define FIELD_MASK_LAST 0x40 +#define FIELD_FIRST 0x80 +#define FIELD_LAST 0x40 -/* packet field masks */ -/* first packet byte */ -#define FIELD_MASK_NEW 0x80 -#define FIELD_MASK_END 0x40 -#define FIELD_MASK_DS_TYPE 0x30 -#define FIELD_MASK_AFR 0x08 -#define FIELD_MASK_VFR 0x04 -#define FIELD_MASK_SYNC 0x02 +#define FIELD_NEW 0x80 +#define FIELD_END 0x40 +#define FIELD_DS_TYPE 0x30 +#define FIELD_AFR 0x08 +#define FIELD_VFR 0x04 +#define FIELD_SYNC 0x02 struct emp_edr_config { - struct vsem_data_packet *vsem_packets; + struct vsem_pkt *vsem_packets; unsigned long phys_ptr; unsigned int num_packets; }; -struct dv_emp_hdmi_cfg { +struct emp_hdmi_cfg { struct hdmitx_dev *hdev; - struct vsem_data_packet *p_pkts; + struct vsem_pkt *p_pkts; dma_addr_t pkts_phy_addr; size_t size; int (*send_vsemds)(enum eotf_type type, diff --git a/include/linux/amlogic/media/amdolbyvision/dolby_vision.h b/include/linux/amlogic/media/amdolbyvision/dolby_vision.h index 7873cf055cdd..460cba0ef931 100644 --- a/include/linux/amlogic/media/amdolbyvision/dolby_vision.h +++ b/include/linux/amlogic/media/amdolbyvision/dolby_vision.h @@ -18,8 +18,6 @@ #ifndef _DV_H_ #define _DV_H_ -#define V1_5 -#define V2_4 #include #include @@ -60,6 +58,163 @@ #define DV_AV1_SEI 0x14000000 #define HDR10P 0x02000000 +enum pq_item_e { + PQ_BRIGHTNESS = 0, /*Brightness */ + PQ_CONTRAST = 1, /*Contrast */ + PQ_COLORSHIFT = 2, /*ColorShift or Tint*/ + PQ_SATURATION = 3 /*Saturation or color */ +}; + +enum pq_reset_e { + RESET_ALL = 0, /*reset picture mode / pq for all picture mode*/ + RESET_PQ_FOR_ALL = 1, /*reset pq for all picture mode*/ + RESET_PQ_FOR_CUR = 2 /*reset pq for current picture mode */ +}; + +struct pic_mode_info_s { + int pic_mode_id; + unsigned char name[32]; +} __aligned(8); + +struct dv_pq_info_s { + int pic_mode_id; + enum pq_item_e item; + s16 value; +} __aligned(8); + +struct dv_full_pq_info_s { + int pic_mode_id; + s16 brightness; /*Brightness */ + s16 contrast; /*Contrast */ + s16 colorshift; /*ColorShift or Tint*/ + s16 saturation; /*Saturation or color */ +} __aligned(8); + +struct dv_config_file_s { + unsigned char bin_name[256]; + unsigned char cfg_name[256]; +} __aligned(8); + +struct ambient_cfg_s { + u32 update_flag; + u32 ambient; /* 1<<16 */ + u32 t_rearLum; + u32 t_frontLux; + u32 t_whiteX; /* 1<<15 */ + u32 t_whiteY; /* 1<<15 */ +} __aligned(8); + +#define DV_M 'D' + +/* get Number of Picture Mode */ +#define DV_IOC_GET_DV_PIC_MODE_NUM _IOR((DV_M), 0x0, int) + +/* get Picture Mode Name of input pic_mode_id */ +#define DV_IOC_GET_DV_PIC_MODE_NAME _IOWR((DV_M), 0x1, struct pic_mode_info_s) + +/* get current active picture mode */ +#define DV_IOC_GET_DV_PIC_MODE_ID _IOR((DV_M), 0x2, int) + +/* select active picture mode */ +#define DV_IOC_SET_DV_PIC_MODE_ID _IOW((DV_M), 0x3, int) + +/* get single pq(contrast or brightness or colorshift or saturation) */ +#define DV_IOC_GET_DV_SINGLE_PQ_VALUE _IOWR((DV_M), 0x4, struct dv_pq_info_s) + +/* get all pq(contrast, brightness,colorshift ,saturation) */ +#define DV_IOC_GET_DV_FULL_PQ_VALUE _IOWR((DV_M), 0x5, struct dv_full_pq_info_s) + +/* set single pq(contrast or brightness or colorshift or saturation) */ +#define DV_IOC_SET_DV_SINGLE_PQ_VALUE _IOWR((DV_M), 0x6, struct dv_pq_info_s) + +/* set all pq(contrast,brightness ,colorshift , saturation) */ +#define DV_IOC_SET_DV_FULL_PQ_VALUE _IOWR((DV_M), 0x7, struct dv_full_pq_info_s) + +/* reset all pq item for current picture mode */ +#define DV_IOC_SET_DV_PQ_RESET _IOWR((DV_M), 0x8, enum pq_reset_e) + +/* set Amlogic_cfg.txt and dv_config.bin dir */ +#define DV_IOC_SET_DV_CONFIG_FILE _IOW((DV_M), 0x9, struct dv_config_file_s) + +/* set ambient light */ +#define DV_IOC_SET_DV_AMBIENT _IOW((DV_M), 0xa, struct ambient_cfg_s) + +/*1: disable dv GD, 0: restore dv GD*/ +#define DV_IOC_CONFIG_DV_BL _IOW((DV_M), 0xb, int) + +extern unsigned int debug_dolby; + +struct composer_reg_ipcore { + /* offset 0xc8 */ + u32 composer_mode; + u32 vdr_resolution; + u32 bit_depth; + u32 coefficient_log2_denominator; + u32 bl_num_pivots_y; + u32 bl_pivot[5]; + u32 bl_order; + u32 bl_coefficient_y[8][3]; + u32 el_nlq_offset_y; + u32 el_coefficient_y[3]; + u32 mapping_idc_u; + u32 bl_num_pivots_u; + u32 bl_pivot_u[3]; + u32 bl_order_u; + u32 bl_coefficient_u[4][3]; + u32 mmr_coefficient_u[22][2]; + u32 mmr_order_u; + u32 el_nlq_offset_u; + u32 el_coefficient_u[3]; + u32 mapping_idc_v; + u32 bl_num_pivots_v; + u32 bl_pivot_v[3]; + u32 bl_order_v; + u32 bl_coefficient_v[4][3]; + u32 mmr_coefficient_v[22][2]; + u32 mmr_order_v; + u32 el_nlq_off_v; + u32 el_coefficient_v[3]; +}; + +struct dm_reg_ipcore1 { + u32 s_range; + u32 s_range_inverse; + u32 frame_fmt1; + u32 frame_fmt2; + u32 frame_pixel_def; + u32 y2rgb_coeff1; + u32 y2rgb_coeff2; + u32 y2rgb_coeff3; + u32 y2rgb_coeff4; + u32 y2rgb_coeff5; + u32 y2rgb_off1; + u32 y2rgb_off2; + u32 y2rgb_off3; + u32 eotf; + u32 a2b_coeff1; + u32 a2b_coeff2; + u32 a2b_coeff3; + u32 a2b_coeff4; + u32 a2b_coeff5; + u32 c2d_coeff1; + u32 c2d_coeff2; + u32 c2d_coeff3; + u32 c2d_coeff4; + u32 c2d_coeff5; + u32 c2d_off; + u32 active_left_top; + u32 active_bottom_right; +}; + +/*dm luts for core1 and core2 */ +struct dm_lut_ipcore { + u32 tm_lut_i[64 * 4]; + u32 tm_lut_s[64 * 4]; + u32 sm_lut_i[64 * 4]; + u32 sm_lut_s[64 * 4]; + u32 g_2_l[256]; +}; + void enable_dolby_vision(int enable); bool is_dolby_vision_enable(void); bool is_dolby_vision_on(void); @@ -72,8 +227,8 @@ void dolby_vision_set_toggle_flag(int flag); int dolby_vision_wait_metadata(struct vframe_s *vf); int dolby_vision_pop_metadata(void); int dolby_vision_update_metadata(struct vframe_s *vf, bool drop_flag); -int dolby_vision_process( - struct vframe_s *vf, u32 display_size, +int dolby_vision_process + (struct vframe_s *vf, u32 display_size, u8 toggle_mode, u8 pps_state); void dolby_vision_init_receiver(void *pdev); void dolby_vision_vf_put(struct vframe_s *vf); @@ -82,8 +237,7 @@ void dolby_vision_dump_setting(int debug_flag); void dolby_vision_dump_struct(void); void enable_osd_path(int on, int shadow_mode); void tv_dolby_vision_config(int config); -void dolby_vision_update_pq_config( - char *pq_config_buf); +void dolby_vision_update_pq_config(char *pq_config_buf); int dolby_vision_update_setting(void); bool is_dolby_vision_stb_mode(void); void tv_dolby_vision_crc_clear(int flag); @@ -92,20 +246,21 @@ void tv_dolby_vision_insert_crc(bool print); int dolby_vision_check_hdr10(struct vframe_s *vf); int dolby_vision_check_hlg(struct vframe_s *vf); int dolby_vision_check_hdr10plus(struct vframe_s *vf); -void tv_dolby_vision_dma_table_modify( - u32 tbl_id, uint64_t value); +int dolby_vision_check_cuva(struct vframe_s *vf); +void tv_dolby_vision_dma_table_modify + (u32 tbl_id, uint64_t value); void tv_dolby_vision_efuse_info(void); -int dolby_vision_parse_metadata( - struct vframe_s *vf, u8 toggle_mode, - bool bypass_release, bool drop_flag); -void dolby_vision_update_vsvdb_config( - char *vsvdb_buf, u32 tbl_size); +int dolby_vision_parse_metadata + (struct vframe_s *vf, u8 toggle_mode, + bool bypass_release, bool drop_flag); +void dolby_vision_update_vsvdb_config + (char *vsvdb_buf, u32 tbl_size); void tv_dolby_vision_el_info(void); -int enable_rgb_to_yuv_matrix_for_dvll( - int32_t on, uint32_t *coeff_orig, uint32_t bits); +int enable_rgb_to_yuv_matrix_for_dvll + (s32 on, uint32_t *coeff_orig, uint32_t bits); -bool is_dovi_frame(struct vframe_s *vf); +int is_dovi_frame(struct vframe_s *vf); void update_graphic_width_height(unsigned int width, unsigned int height); int get_dolby_vision_policy(void); void set_dolby_vision_policy(int policy); @@ -114,20 +269,22 @@ bool is_dolby_vision_el_disable(void); bool is_dovi_dual_layer_frame(struct vframe_s *vf); void dolby_vision_set_provider(char *prov_name); int dolby_vision_check_mvc(struct vframe_s *vf); +bool for_dolby_vision_video_effect(void); int get_dolby_vision_hdr_policy(void); int get_dv_support_info(void); +void dolby_vision_update_backlight(void); int dolby_vision_update_src_format(struct vframe_s *vf, u8 toggle_mode); void update_graphic_status(void); -int parse_sei_and_meta_ext( - struct vframe_s *vf, - char *aux_buf, - int aux_size, - int *total_comp_size, - int *total_md_size, - void *fmt, - int *ret_flags, - char *md_buf, - char *comp_buf); +int parse_sei_and_meta_ext + (struct vframe_s *vf, + char *aux_buf, + int aux_size, + int *total_comp_size, + int *total_md_size, + void *fmt, + int *ret_flags, + char *md_buf, + char *comp_buf); void dolby_vision_clear_buf(void); - +bool is_dv_control_backlight(void); #endif diff --git a/include/linux/amlogic/media/vout/vinfo.h b/include/linux/amlogic/media/vout/vinfo.h index bf213017c63d..5de26e8671fd 100644 --- a/include/linux/amlogic/media/vout/vinfo.h +++ b/include/linux/amlogic/media/vout/vinfo.h @@ -267,7 +267,7 @@ struct vout_device_s { unsigned int size); }; -extern int send_dv_emp(enum eotf_type type, +int send_emp(enum eotf_type type, enum mode_type tunnel_mode, struct dv_vsif_para *vsif_data, unsigned char *p_vsem, -- 2.20.1