285 lines
6.9 KiB
C++
285 lines
6.9 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: c++ file
|
||
|
|
*/
|
||
|
|
|
||
|
|
#define LOG_NDEBUG 0
|
||
|
|
|
||
|
|
#define LOG_MODULE_TAG "TV"
|
||
|
|
#define LOG_CLASS_TAG "CTvPanelFile"
|
||
|
|
|
||
|
|
#include <CTvLog.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <string.h>
|
||
|
|
#include <tvutils.h>
|
||
|
|
#include "CTvPanel.h"
|
||
|
|
#include <sys/ioctl.h>
|
||
|
|
#include <cstdio>
|
||
|
|
#include <cerrno>
|
||
|
|
#include <fcntl.h>
|
||
|
|
#include <unistd.h>
|
||
|
|
#include <cstdint>
|
||
|
|
#include "../tvutils/tvutils.h"
|
||
|
|
|
||
|
|
static int mLcdFd = -1;
|
||
|
|
static int mLcdFdIsOpened = 0;
|
||
|
|
|
||
|
|
int CTvPanel::PANEL_File_Load_INIT(void)
|
||
|
|
{
|
||
|
|
if (mLcdFdIsOpened) {
|
||
|
|
LOGD("%s LcdFd has been opened.\n", __FUNCTION__);
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (mLcdFd < 0) {
|
||
|
|
mLcdFd = open("/dev/" LCD_DEVICE_NAME, O_RDWR);
|
||
|
|
LOGD("%s mLcdFd = %d.\n", __FUNCTION__, mLcdFd);
|
||
|
|
}
|
||
|
|
|
||
|
|
mLcdFdIsOpened = 1;
|
||
|
|
|
||
|
|
if (mLcdFd < 0) {
|
||
|
|
LOGE("%s failed.\n", __FUNCTION__);
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
LOGD("%s mLcdFd=%d.\n", __FUNCTION__, mLcdFd);
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
int CTvPanel::PANEL_File_Load_Uninit(void)
|
||
|
|
{
|
||
|
|
if (mLcdFd >= 0) {
|
||
|
|
close(mLcdFd);
|
||
|
|
mLcdFd = -1;
|
||
|
|
mLcdFdIsOpened = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
int CTvPanel::PANEL_GetTconBinMaxCnt(unsigned int *cnt)
|
||
|
|
{
|
||
|
|
if (cnt == NULL) {
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (mLcdFd < 0) {
|
||
|
|
LOGE("%s OPEN /dev/%s fail\n", __FUNCTION__,LCD_DEVICE_NAME);
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (ioctl(mLcdFd, LCD_IOC_CMD_GET_TCON_BIN_MAX_CNT_INFO, cnt) < 0) {
|
||
|
|
LOGE("%s VBE ioctl LCD_IOC_CMD_NR_SET_HDR_INFO fail\n", __FUNCTION__);
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
int CTvPanel::PANEL_GetTconBinPath(aml_path_s *str)
|
||
|
|
{
|
||
|
|
if (str == NULL) {
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (mLcdFd < 0) {
|
||
|
|
LOGE("%s OPEN /dev/%s fail\n", __FUNCTION__,LCD_DEVICE_NAME);
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (ioctl(mLcdFd, LCD_IOC_CMD_GET_TCON_BIN_PATH_INFO, str) < 0) {
|
||
|
|
LOGE("%s VBE ioctl LCD_IOC_CMD_GET_TCON_BIN_PATH_INFO fail\n", __FUNCTION__);
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
int CTvPanel::PANEL_SetTconBinData(am_pq_bin_param_s *param)
|
||
|
|
{
|
||
|
|
if (param == NULL) {
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (mLcdFd < 0) {
|
||
|
|
LOGE("%s OPEN /dev/%s fail\n", __FUNCTION__,LCD_DEVICE_NAME);
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (ioctl(mLcdFd, LCD_IOC_CMD_SET_TCON_BIN_DATA_INFO, param) < 0) {
|
||
|
|
LOGE("%s VBE ioctl LCD_IOC_CMD_SET_TCON_BIN_DATA_INFO fail\n", __FUNCTION__);
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
int CTvPanel::AML_HAL_LCD_SetTconDataIndex(unsigned int index)
|
||
|
|
{
|
||
|
|
if (mLcdFd < 0) {
|
||
|
|
LOGE("%s OPEN /dev/%s fail\n", __FUNCTION__,LCD_DEVICE_NAME);
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (ioctl(mLcdFd, LCD_IOC_CMD_SET_TCON_DATA_INDEX_INFO, &index) < 0) {
|
||
|
|
LOGE("%s VBE ioctl LCD_IOC_CMD_SET_TCON_DATA_INDEX_INFO fail\n", __FUNCTION__);
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
void CTvPanel::InitTconlessBin(void)
|
||
|
|
{
|
||
|
|
unsigned int i;
|
||
|
|
unsigned int finish = 1;
|
||
|
|
unsigned int max_cnt = 0;
|
||
|
|
|
||
|
|
|
||
|
|
if (PANEL_File_Load_INIT() != 0) {
|
||
|
|
LOGE("%s PANEL_File_Load_INIT FAIL\n", __FUNCTION__);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
if (PANEL_GetTconBinMaxCnt(&max_cnt) != 0) {
|
||
|
|
LOGE("%s AML_HAL_LCD_GetTconBinMaxCnt FAIL max_cnt = %d \n", __FUNCTION__, max_cnt);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
for (i = 0; i < max_cnt; i++) {
|
||
|
|
if (LoadTconlessBin(i) < 0) {
|
||
|
|
LOGE("%s table %d is not exist \n", __FUNCTION__, i);
|
||
|
|
} else {
|
||
|
|
LOGD("%s LOAD tcon bin index: %d \n", __FUNCTION__, i);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (LCD_SetTconBinDataFinish(finish) != 0) {
|
||
|
|
LOGD("%s AMHal_VPQ_Set_TonlessBinDataFinish Fail \n", __FUNCTION__);
|
||
|
|
}
|
||
|
|
|
||
|
|
PANEL_File_Load_Uninit();
|
||
|
|
}
|
||
|
|
|
||
|
|
int CTvPanel::LoadTconlessBin(unsigned int index)
|
||
|
|
{
|
||
|
|
int ret = 0;
|
||
|
|
int fd = -1;
|
||
|
|
int sizeData = 0;
|
||
|
|
unsigned char * dataBuff = NULL;
|
||
|
|
int count_retry = 20;
|
||
|
|
|
||
|
|
am_pq_bin_param_s param;
|
||
|
|
aml_path_t path;
|
||
|
|
memset(¶m, 0, sizeof(am_pq_bin_param_t));
|
||
|
|
memset(&path, 0, sizeof(aml_path_t));
|
||
|
|
|
||
|
|
//set index to driver
|
||
|
|
if (AML_HAL_LCD_SetTconDataIndex(index) != 0) {
|
||
|
|
LOGE("%s AML_HAL_LCD_SetTconDataIndex fail \n", __FUNCTION__);
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
// get bin path
|
||
|
|
if (PANEL_GetTconBinPath((aml_path_s *)&path) != 0) {
|
||
|
|
LOGE("%s AML_HAL_LCD_GetTconBinPath fail \n", __FUNCTION__);
|
||
|
|
return -1;
|
||
|
|
} else {
|
||
|
|
LOGD("%s INDEX:{ %d } ====> GetBinPath = %s!\n",__FUNCTION__, index, path.string);
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
if (strstr(path.string, "demura")) {
|
||
|
|
char propbuf[PROPERTY_VALUE_MAX] = {0};
|
||
|
|
bool autogen = false;
|
||
|
|
if (property_get(PROP_DEMURA_AUTO_GEN, propbuf, "0") > 0) {
|
||
|
|
LOGD("Prop [%s]=%s\n", PROP_DEMURA_AUTO_GEN, propbuf);
|
||
|
|
if (!strcasecmp(propbuf, "true") || !strcmp(propbuf, "1"))
|
||
|
|
autogen = true;
|
||
|
|
} else {
|
||
|
|
LOGE("getprop [%s] fail\n", PROP_DEMURA_AUTO_GEN);
|
||
|
|
}
|
||
|
|
if (autogen) {
|
||
|
|
LOGD("Detect demura binary, try to gen %s...\n", path.string);
|
||
|
|
CTconDemura *demuraDev = CTconDemura::GetInstance();
|
||
|
|
if (demuraDev && !demuraDev->Init(NULL)) {
|
||
|
|
demuraDev->PrintInfo(-1);
|
||
|
|
if (demuraDev->GenerateBin(path.string) < 0)
|
||
|
|
LOGE("Gen %s failed, exit...\n", path.string);
|
||
|
|
else
|
||
|
|
LOGD("Gen %s Ok\n", path.string);
|
||
|
|
}
|
||
|
|
if (demuraDev)
|
||
|
|
demuraDev->UnInit();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
*/
|
||
|
|
|
||
|
|
// read bin data
|
||
|
|
if (isFileExist(path.string) == false) {
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
if ((fd = open(path.string, O_RDONLY)) < 0) {
|
||
|
|
LOGE("Open %s error(%s)!\n", path.string, strerror(errno));
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
dataBuff = (unsigned char *)calloc(MAX_TABLE_SIZE, sizeof(char));
|
||
|
|
if (dataBuff == NULL) {
|
||
|
|
LOGE("%s malloc memory fail \n", __FUNCTION__);
|
||
|
|
ret = -1;
|
||
|
|
goto exit;
|
||
|
|
}
|
||
|
|
sizeData = read(fd, dataBuff, MAX_TABLE_SIZE);
|
||
|
|
if (sizeData <= 0) {
|
||
|
|
free(dataBuff);
|
||
|
|
LOGE("%s ERROR !!!data size[%d]\n", __FUNCTION__,sizeData);
|
||
|
|
ret = -1;
|
||
|
|
goto exit;
|
||
|
|
} else {
|
||
|
|
param.table_index= index;
|
||
|
|
param.table_len= sizeData;
|
||
|
|
param.table_ptr = dataBuff;
|
||
|
|
ret = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
//set bin data to driver
|
||
|
|
while (count_retry) {
|
||
|
|
if (PANEL_SetTconBinData((am_pq_bin_param_s *)¶m) != 0) {
|
||
|
|
LOGE("%s, error(%s), errno(%d)\n", __FUNCTION__, strerror(errno), errno);
|
||
|
|
if (errno == EBUSY) {
|
||
|
|
LOGE("%s, %s, retry...\n", __FUNCTION__, strerror(errno));
|
||
|
|
count_retry--;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
close(fd);
|
||
|
|
free(dataBuff);
|
||
|
|
return ret;
|
||
|
|
|
||
|
|
exit:
|
||
|
|
close(fd);
|
||
|
|
return ret;
|
||
|
|
}
|
||
|
|
|
||
|
|
int CTvPanel::LCD_SetTconBinDataFinish(unsigned int value)
|
||
|
|
{
|
||
|
|
if (ioctl(mLcdFd, LCD_IOC_CMD_SET_TCON_BIN_DATA_FINISH, &value) < 0) {
|
||
|
|
LOGE("LCD_IOC_CMD_SET_TCON_BIN_DATA_FINISH fail\n");
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|