Files
2026-08-24 10:03:24 +08:00

328 lines
14 KiB
C++

/*
* Copyright (c) 2014 Amlogic, Inc. All rights reserved.
*
* This source code is subject to the terms and conditions defined in the
* file 'LICENSE' which is part of this source code package.
*
* Description: header file
*/
#ifndef _C_TV_PANEL_H_
#define _C_TV_PANEL_H_
/*
#ifdef __cplusplus
#if __cplusplus
extern "C"
{
#endif
#endif
*/
#include <linux/amlogic/lcd.h>
//lcd
#define MAX_TABLE_SIZE 0x300000
#define CPQ_LCD_SYSFS "/dev/lcd0"
#define LCD_DEVICE_NAME "lcd0"
typedef struct am_pq_bin_param_s {
unsigned int table_index;
unsigned int table_len;
union {
void *table_ptr;
int64_t l_table;
};
} am_pq_bin_param_t;
typedef struct aml_path_s {
char string[256];
} aml_path_t;
#define DEV_I2C_0_PATH "/dev/i2c-0"
#define DEV_I2C_1_PATH "/dev/i2c-1"
#define DEV_I2C_2_PATH "/dev/i2c-2"
#define DEV_I2C_3_PATH "/dev/i2c-3"
#define DEV_I2C_4_PATH "/dev/i2c-4"
#define CC_MAX_FILE_LINE_LEN (1024)
#define SPI_DEVICE "/dev/mtd0"
//Demura file data check
#define PANEL_DEMURA_FILE_CHECK_PASS 0
#define PANEL_DEMURA_FILE_CHECK_FAIL (-1)
//Tconless file path
#ifndef TCONLESS_FILE_PATH
#define TCONLESS_FILE_PATH "/factory/"
#endif
#define PANLE_DEMURA_FILE "tcon_demura.bin"
#define PANLE_PGAMMA_FILE "tcon_pgamma.bin"
#define PANLE_PGAMMA_CMD_FILE "tcon_pgamma_CMD.bin"
#define PANLE_PGAMMA_FILE_60 "tcon_pgamma_DLG_60.bin"
#define PANLE_PGAMMA_FILE_120 "tcon_pgamma_DLG_120.bin"
#define PANLE_ACC_FILE "tcon_auto_acc.bin"
#define PANLE_DEMURA_FILE_PATH (TCONLESS_FILE_PATH PANLE_DEMURA_FILE)
#define PANLE_PGAMMA_FILE_PATH (TCONLESS_FILE_PATH PANLE_PGAMMA_FILE)
#define PANLE_PGAMMA_CMD_FILE_PATH (TCONLESS_FILE_PATH PANLE_PGAMMA_CMD_FILE)
#define PANLE_PGAMMA_FILE_PATH_60 (TCONLESS_FILE_PATH PANLE_PGAMMA_FILE_60)
#define PANLE_PGAMMA_FILE_PATH_120 (TCONLESS_FILE_PATH PANLE_PGAMMA_FILE_120)
#define PANLE_ACC_FILE_PATH (TCONLESS_FILE_PATH PANLE_ACC_FILE)
#define PANLE_PGAMMA_DEFLATE_BIN_ENV_DLG_60 "model_tcon_ext_b0_0"
#define PANLE_PGAMMA_DEFLATE_BIN_ENV_DLG_120 "model_tcon_ext_b0_1"
#define PANLE_PGAMMA_DEFLATE_BIN_ENV "model_tcon_ext_b0"
/*
*Remove tconless bin file:
*Data format description:
*config use 8bit
*bit[0] -> tcon_demura.bin
*bit[1] -> tcon_pgamma.bin
*bit[3] -> tcon_acc.bin
*/
#define PANLE_All_REMOVE_FLAG 0xff
#define PANLE_DEMURA_REMOVE_FLAG 0x1
#define PANLE_PGAMMA_REMOVE_FLAG 0x2
#define PANLE_ACC_REMOVE_FLAG 0x4
#define CC_ENDIAN_TYPE_LITTLE (0)
#define CC_ENDIAN_TYPE_BIG (1)
#define WRITE_TO_4_BUFFER(buffer, offset, value) \
do { \
buffer[offset] = (value) & 0xff; \
buffer[offset + 1] = ((value) >> 8) & 0xff; \
buffer[offset + 2] = ((value) >> 16) & 0xff; \
buffer[offset + 3] = ((value) >> 24) & 0xff; \
offset += 4; \
} while(0)
#define WRITE_TO_2_BUFFER(buffer, offset, value) \
do { \
buffer[offset] = (value) & 0xff; \
buffer[offset + 1] = ((value) >> 8) & 0xff; \
offset += 2; \
} while(0)
#define WRITE_TO_1_BUFFER(buffer, offset, value) \
do { \
buffer[offset] = (value) & 0xff; \
offset += 1; \
} while(0)
typedef struct {
const char *name;
unsigned int tuning_flag;
unsigned int part_type;
unsigned int reg_addr_byte_width;
unsigned int reg_data_byte_width;
unsigned int reg_addr;
unsigned int data_mask;
unsigned int data_value;
} BodyInfo;
typedef struct {
unsigned int mono_mode;
unsigned int layer_num;
unsigned int table_bitwidth;
unsigned int v_lut_num;
unsigned int h_lut_num;
unsigned int white_limit_r;
unsigned int white_limit_g;
unsigned int white_limit_b;
unsigned int black_limit_r;
unsigned int black_limit_g;
unsigned int black_limit_b;
unsigned int luma_level[15];
unsigned int plane_slope[18];
unsigned int rd_cmd_len;
}tcon_demura_bin_info_s;
enum tcon_demura_e {
TCON_DEMURA_CHOT = 1,
TCON_DEMURA_CSOT = 2,
TCON_DEMURA_HKC = 3,
TCON_DEMURA_AUO = 4,
TCON_DEMURA_INX = 5,
TCON_DEMURA_BOE = 6,
TCON_DEMURA_LG = 7,
TCON_DEMURA_SDP = 8,
tcon_demura_MAX,
};
#define DEMURA_SETTING_BYPASS_LIMIT 1<<0
#define DEMURA_SETTING_BYPASS_LEVEL 1<<1
#define DEMURA_SETTING_BYPASS_SLOPE 1<<2
#define DEMURA_SETTING_BYPASS_RGBMODE 1<<3
#define DEMURA_SETTING_BYPASS_DDR_IF 1<<4
#define DEMURA_SETTING_BYPASS_LAYER_NUM 1<<5
#define DEMURA_SETTING_BYPASS_OTHER 1<<6
struct tcon_demura_config_s {
unsigned int setting_offset;//flash demura setting offset
unsigned int setting_len;//flash demura setting len
unsigned int setting_bypass_flag;
unsigned int data_offset;//flash demura data offset
unsigned int data_len;//flash demura data len
unsigned int data_crc_offset;//flash demura data_crc offset
unsigned int data_crc_len;//flash demura data_crc len
unsigned int crc_endian_type;//flash demura data_crc endian
unsigned int mix_demura_flag;
unsigned int (*panel_crc_check)(unsigned int crc, const unsigned char *buffer, int buf_len);
int (*demura_setting)(unsigned char *buffer, tcon_demura_bin_info_s *demura_bin_info);
int (*demura_data_trans)(unsigned char *buf_flash_data, unsigned char *buf_flash_setting, unsigned int** panel_buf_plane, tcon_demura_bin_info_s *demura_bin_info);
};
typedef struct tagPGammaVolInfo {
int gam_ic_id; //The calculation methods of gamma and vcom
float verf; //Reference voltage
float vcom_max; //vcom max
float vcom_min; //vcom min
unsigned char data_buf[256]; //Bin data or flash data
float gam_vol[14]; //Gamma voltage
float vcom_vol[2]; //vcom voltage
} PGammaVolInfo;
enum tcon_Pgamma_e {
GAMMA_IC_CS602 = 1,
GAMMA_IC_LP6281 = 2,
GAMMA_IC_LP6298_HKC = 3, //The universal format for hkc auto_pgamma, but requires obtaining vref vcom_max vcom_min
GAMMA_IC_PT650GS03_1 = 4, //Auto_gamma requires a register to write control words
GAMMA_IC_LP6298 = 5,
GAMMA_IC_CS601 = 6,
GAMMA_IC_G2732P = 7,
GAMMA_IC_MAX,
};
enum tcon_Pgamma_type {
TCON_GAMMA_NORMAL = 0,
TCON_GAMMA_DLG_60 = 1,
TCON_GAMMA_DLG_120 = 2,
};
enum tcon_Pgamma_read_type {
TCON_GAMMA_SPI = 0,
TCON_GAMMA_I2C = 1,
};
struct tcon_pgamma_config_s {
unsigned int flash_data_offset; //flash pgamma data offset
unsigned int flash_data_len; //flash pgamma data len
unsigned int deflate_bin_len; //deflate bin len
unsigned int data_read_type; //spi or i2c
PGammaVolInfo flash_vol_info;
PGammaVolInfo bin_vol_info;
};
int demura_setting_CHOT(unsigned char *setting_buffer, tcon_demura_bin_info_s *demura_bin_info);
unsigned int panel_crc_check_CHOT(unsigned int crc, const unsigned char *buffer, int buf_len);
int demura_data_trans_CHOT(unsigned char *buf_flash_data, unsigned char *buf_flash_setting, unsigned int** panel_buf_plane, tcon_demura_bin_info_s *demura_bin_info);
int demura_setting_CSOT(unsigned char *setting_buffer, tcon_demura_bin_info_s *demura_bin_info);
unsigned int panel_crc_check_CSOT(unsigned int crc, const unsigned char *buffer, int buf_len);
int demura_data_trans_CSOT(unsigned char *buf_flash_data, unsigned char *buf_flash_setting, unsigned int** panel_buf_plane, tcon_demura_bin_info_s *demura_bin_info);
int PANEL_Demura_CHOT(int lut_offset, int lut_len);
int demura_setting_HKC(unsigned char *setting_buffer, tcon_demura_bin_info_s *demura_bin_info);
unsigned int panel_crc_check_HKC(unsigned int crc, const unsigned char *buffer, int buf_len);
int demura_data_trans_HKC(unsigned char *buf_flash_data, unsigned char *buf_flash_setting, unsigned int** panel_buf_plane, tcon_demura_bin_info_s *demura_bin_info);
int demura_setting_AUO(unsigned char *setting_buffer, tcon_demura_bin_info_s *demura_bin_info);
unsigned int panel_crc_check_AUO(unsigned int crc, const unsigned char *buffer, int buf_len);
int demura_data_trans_AUO(unsigned char *buf_flash_data, unsigned char *buf_flash_setting, unsigned int** panel_buf_plane, tcon_demura_bin_info_s *demura_bin_info);
unsigned int panel_crc_check_INX(unsigned int crc, const unsigned char *buffer, int buf_len);
int demura_setting_INX(unsigned char *setting_buffer, tcon_demura_bin_info_s *demura_bin_info);
unsigned int PANEL_Get_flash_ByteToInt(unsigned int flash_addr, unsigned int len, unsigned int endian_type);
int demura_setting_INX(unsigned char *setting_buffer, tcon_demura_bin_info_s *demura_bin_info);
int INX_Data_Decode(unsigned int *Code, unsigned int *Mode, int range, int min, unsigned int *DeLut);
unsigned int INX_Data_Decode_trans(unsigned int *res_buffer, unsigned char *all_buffer);
int demura_data_trans_INX(unsigned char *buf_flash_data, unsigned char *buf_flash_setting, unsigned int** panel_buf_plane, tcon_demura_bin_info_s *demura_bin_info);
int demura_setting_BOE(unsigned char *setting_buffer, tcon_demura_bin_info_s *demura_bin_info);
unsigned int panel_crc_check_BOE(unsigned int crc, const unsigned char *buffer, int buf_len);
int demura_data_trans_BOE(unsigned char *buf_flash_data, unsigned char *buf_flash_setting, unsigned int** panel_buf_plane, tcon_demura_bin_info_s *demura_bin_info);
int demura_setting_LG(unsigned char *setting_buffer, tcon_demura_bin_info_s *demura_bin_info);
unsigned int panel_crc_check_LG(unsigned int crc, const unsigned char *buffer, int buf_len);
int demura_data_trans_LG(unsigned char *buf_flash_data, unsigned char *buf_flash_setting, unsigned int** panel_buf_plane, tcon_demura_bin_info_s *demura_bin_info);
int demura_setting_SDP(unsigned char *setting_buffer, tcon_demura_bin_info_s *demura_bin_info);
unsigned int panel_crc_check_SDP(unsigned int crc, const unsigned char *buffer, int buf_len);
int demura_data_trans_SDP(unsigned char *buf_flash_data, unsigned char *buf_flash_setting, unsigned int** panel_buf_plane, tcon_demura_bin_info_s *demura_bin_info);
class CTvPanel {
public:
CTvPanel();
~CTvPanel();
static CTvPanel *getInstance();
int AM_PANEL_Init();
//panel tcon bin path
int PANEL_SetTconBinPath(const char* path);
//panel file path
int PANEL_SetFilePath(const char* path);
//panel info
int PANEL_Flash_Read(const char *partition_name, long offset,unsigned char *buffer, unsigned int length);
int PANEL_GrepStr(const char *partition_name, const char *str);
int PANEL_Flash_Write(const char *partition_name, long offset,unsigned char *buffer, unsigned int length);
int PANEL_File_Read(const char *filename, long offset, unsigned char *buffer, unsigned int length);
int PANEL_File_Write(const char *filename, long offset,unsigned char *buffer, unsigned int length);
int PANEL_SPI_Read(unsigned int offset, unsigned int ulength, unsigned char *pubuf);
int PANEL_I2C_Read(unsigned int offset, unsigned int ulength, unsigned char *pubuf);
const char* PANEL_READ_Env(const char *name);
int PANEL_File_Read_bin(const char *filename, unsigned char *buffer);
unsigned int PANEL_Get_flash_ByteToInt(unsigned int flash_addr, unsigned int len, unsigned int endian_type);
int PANEL_Demura_File_crc_check(unsigned char *buf, unsigned int len);
int PANEL_TconlessTypeChose();
int PANEL_RemoveTconlessBinFile(int config);
int PANEL_DemuraFileCheck(unsigned int crc_flash);
int PANEL_DemuraFormat(int flash_crc, unsigned char *buffer_lut, int len_lut, tcon_demura_bin_info_s *demura_bin_info);
void Demura_lut_multipartite(unsigned int** buf_plane, unsigned char *buf_lut,unsigned int layer_num,unsigned int buf_lut_offset);
void PANEL_Demura_lut_Synthesize(unsigned int** buf_plane, unsigned char *buf_res, unsigned int layer_num,
unsigned int buf_lut_offset, unsigned int demura_lut_num_H, unsigned int demura_lut_num_V);
unsigned int PANEL_DemuraFormatCrc(unsigned int crc, const unsigned char *ptr, int buf_len);
int PANEL_MixDemura(const char * BackLight_demura_file, const char * output_bin_path, int crc_flash,
const tcon_demura_bin_info_s& panel_demura_bin_info, unsigned int** panel_buf_plane);
int PANEL_Demura();
int PANEL_pgamma_flash_crc_check(const unsigned char * flash_data_buf, int buf_len);
int PANEL_CMD_Auto_gamma_Format(const char * output_bin_path, unsigned int *temp_gamma_buf);
int buf2gamma_CS602(PGammaVolInfo *cs602_info);
int PANEL_pgamma_trans_vol_data( PGammaVolInfo *flash_vol_info, PGammaVolInfo *bin_vol_info, unsigned char *res_buf);
int gamma2buf_CS602(PGammaVolInfo *cs602_info, unsigned char *res_buf);
int buf2gamma_LP6298_HKC(PGammaVolInfo *lp6298_info);
int gamma2buf_LP6281(PGammaVolInfo *LP6281_info, unsigned char * res_buf);
int buf2gamma_CS601(PGammaVolInfo *cs601_info);
int buf2gamma_HKC_PT650GS03_1(PGammaVolInfo *lp6298_info);
int gamma2buf_LP6298(PGammaVolInfo *LP6298_info, unsigned char * res_buf);
int gamma2buf_G2732P(PGammaVolInfo *LP6298_info, unsigned char * res_buf);
int gamma2buf_LP6281_HKC_PT650GS03_1(PGammaVolInfo *LP6281_info, unsigned char * res_buf);
int PANEL_Pgamma(int pgmma_type);
//tconless bin file load
int PANEL_File_Load_INIT(void);
int PANEL_File_Load_Uninit(void);
int PANEL_GetTconBinMaxCnt(unsigned int *cnt);
int PANEL_GetTconBinPath(aml_path_s *str);
int PANEL_SetTconBinData(am_pq_bin_param_s *param);
int AML_HAL_LCD_SetTconDataIndex(unsigned int index);
void InitTconlessBin(void);
int LoadTconlessBin(unsigned int index);
int LCD_SetTconBinDataFinish(unsigned int value);
private:
static CTvPanel *mInstance;
};
/*
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
*/
#endif