/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/


/*****************************************************************************
 *
 * Filename:
 * ---------
 *   $Workfile: mtk_edid.h
 *
 * Project:
 * --------
 *   MT5365
 *
 * Description:
 * ------------
 *   Edid customization
 *   
 * Author:
 * -------
 *   
 *
 * Unauthorized use, practice, perform, copy, distribution, reproduction,
 * or disclosure of this information in whole or in part is prohibited.
 *-----------------------------------------------------------------------------
 *
 * $Author: zhenyu.shi $
 * $Date: 2016/01/13 $
 * $RCSfile: mtk_vga.h,v $
 * $Revision: #6 $
 *
 *---------------------------------------------------------------------------*/
#ifndef _EDID_CUSTOMIZATION_H_
#define _EDID_CUSTOMIZATION_H_
#include "eeprom_if.h"
#include "panel_cust.h"
#include "drv_edid.h"

#include "x_os.h"
#include "x_stl_lib.h"
#include "x_drv_cli.h"

#ifdef __MW_CLI_DEF__
#include "x_mid_cli.h"
#else
#include "x_drv_cli.h"
#endif

#include "hdmi_debug.h"

#define HDMI_EDID_ENABLE_DEBUG
#define HDMI_EDID_SUBPPORT_MAXNUM   64

#define EDID_SART_ADDRESS_SELECT_TABLE_0    0x11 //Start address of ID select table LSB
#define EDID_SART_ADDRESS_SELECT_TABLE_1    0x10 //Start address of ID select table LSB
#define EDID_SART_ADDRESS_EEP_DATA_0    0x21 //Start address of each eep data LSB
#define EDID_SART_ADDRESS_EEP_DATA_1    0x20 //Start address of each eep data LSB

#define EDID_END_ADDRESS_EEP_DATA_2    0x26 //End address of  edid block
#define EDID_END_ADDRESS_EEP_DATA_1    0x27 //End address of  edid block
#define EDID_END_ADDRESS_EEP_DATA_0    0x28 //End address of  edid block

typedef struct
{
    //Byte0:1
    UINT8 u1ParticularReserve_8_f;
    UINT8 u1ParticularReserve_0: 1;
    UINT8 u1Panel_less: 1;
    UINT8 u1CBA: 1;
    UINT8 u1ParticularReserve_3_7: 5;

    //Byte2:3
    UINT8 u1GeneralReserve_8_f;
    UINT8 u1HDR: 1;
    UINT8 u1xvYCC: 1;
    UINT8 u1BT20201: 1;
    UINT8 u12D3D: 1;
    UINT8 u1JPN_WW: 1;  //JPN 1, WW 0
    UINT8 u1GeneralReserve_5_6: 2;
    UINT8 u1DolbyVision: 1;

    //Byte4:5
    UINT8 u1AdaptiveReserve_8_f;
    UINT8 u1ATMOS: 1;
    UINT8 u1AdaptiveReserve_1_7: 7;

    //Byte6:9
    UINT8 u1ReserveByte6;
    UINT8 u1ReserveByte7;
    UINT8 u1ReserveByte8;
    UINT8 u1ReserveByte9;

    //Byte10:12
    UINT8 u1MID_ID_Byte2;
    UINT8 u1MID_ID_Byte1;
    UINT8 u1MID_ID_Byte0;

    //Byte13:15
    UINT8 u1SID_ID_Byte2;
    UINT8 u1SID_ID_Byte1;
    UINT8 u1SID_ID_Byte0;

    UINT32 u4MID_ID;
    UINT32 u4SID_ID;
} Trinity_Table_T;

typedef struct
{
    //Byte0:1
    UINT8 u1ParticularReserve_8_f;
    UINT8 u1ParticularReserve_0: 1;
    UINT8 u1Panel_less: 1;
    UINT8 u1CBA: 1;
    UINT8 u1ParticularReserve_3_7: 5;

    //Byte2:3
    UINT8 u1GeneralReserve_8_f;
    UINT8 u1HDR: 1;
    UINT8 u1xvYCC: 1;
    UINT8 u1BT20201: 1;
    UINT8 u12D3D: 1;
    UINT8 u1JPN_WW: 1;  //JPN 1, WW 0
    UINT8 u14K2K: 2;        //0:2K, 1:4K
    UINT8 u1DolbyVision: 1;

    //Byte4:5
    UINT8 u1AdaptiveReserve_8_f;
    UINT8 u1ATMOS: 1;
    UINT8 u1AdaptiveReserve_1_7: 7;

    //Byte6:9
    UINT8 u1ReserveByte6;
    UINT8 u1ReserveByte7;
    UINT8 u1ReserveByte8;
    UINT8 u1ReserveByte9;

    //Byte10:12
    UINT8 u1MID_ID_Byte2;
    UINT8 u1MID_ID_Byte1;
    UINT8 u1MID_ID_Byte0;

    //Byte13:15
    UINT8 u1SID_ID_Byte2;
    UINT8 u1SID_ID_Byte1;
    UINT8 u1SID_ID_Byte0;

    UINT32 u4MID_ID;
    UINT32 u4SID_ID;
} Trinity3_Table_T;

typedef union
{
    Trinity_Table_T TrinityTable;
    Trinity3_Table_T Trinity3Table;
}uSelectTable;

typedef struct
{
    UINT32 u4PanelCtrl;
    UINT8 u1Panel_less;
    UINT8 u1Panel3DType;
    UINT8 u1PanelWCG;

    UINT8 u1MVIDestination;
    UINT8 u1ATMOS;
    UINT8 u1CBA;
    UINT8 u1MVINO_3D;
    UINT8 u1HFVSDBFlag;
    UINT8 u1HDR;

    UINT32 u4TableIDAddr;
    UINT16 u2TableSize;
    UINT32 u4EepHeaderAddr;
    UINT32 u4EepBlockEndAddr;
    UINT32 u4MID;
    UINT32 u4SID;

    UINT32 u4EepMIDStartAddr;
    UINT32 u4EepSIDStartAddr;

    UINT32 u4PanleSize;
    
    UINT8 u1DisByte0;
    UINT8 u1DisByte1;
    UINT8 u1ImageByte0;
    UINT8 u1ImageByte1;
    UINT8 u1ImageByte2;

    UINT8 u1TVStatus;
    UINT8 u1EARCStatus;

    UINT8 u1Platform;
    UINT8 u14K2K;
    UINT8 u1BankNum;

    UINT8 u1DolbyVision;   //1:Dolby 0:None
    UINT8 u1DolbyBlock[6];

    UINT8 u1BlockFlag; //1:find the edid whole block
    UINT16 u2BlockOffset;

    UINT8 *pTargetMIDEDID;
    UINT8 *pTargetSIDEDID;
    UINT8 *pEepBlock;
    UINT16 u2EepDataSize;
    uSelectTable uSelect;
} EDID_SELECT_INFO_T;

typedef enum {
    EDID_SPEC_TYPE_MID,
    EDID_SPEC_TYPE_SID,
} EDID_SPEC_TYPE;

typedef enum {
    CLI_FLAG_SETID,
    CLI_FLAG_SEARCH,
} CLI_FLAG_T;

typedef struct
{
    UINT32 u4FixedFlag; //changed flag.
    UINT8 u1Platform;
    UINT8 u14K2K;
    UINT8 u1BankNum;
    UINT32 u4PanelCtrl;
    UINT8 u1Panel_less;
    UINT8 u1Panel3DType;
    UINT8 u1PanelWCG;
    UINT8 u1MVIDestination;
    UINT8 u1ATMOS;
    UINT8 u1CBA;
    UINT8 u1MVINO_3D;
    UINT8 u1HFVSDBFlag;
    UINT8 u1HDR;
    UINT32 u4MID;
    UINT32 u4SID;
    UINT8 pu1SearchData[16];
    UINT8 u1DolbyVision;
    //add next for debug.
} CLI_DEBUG_INFO_T;

UINT8 u1EdidDebuglvl=0;
CLI_DEBUG_INFO_T t_cli_cust;
static UINT8* pHDMIEDIDEepData = NULL;

#ifndef CC_VGA_EDID_DISABLE
CODE UINT8 VGA_EDID_TABLE[256] =
{
	0x00, 0xFF, 0xFF, 0xFF,  0xFF, 0xFF, 0xFF, 0x00,   0x36, 0x8B, 0x10, 0x00,  0x01, 0x01, 0x01, 0x01, 
	0x07, 0x14, 0x01, 0x03,  0x1F, 0x5D, 0x34, 0x78,   0xCA, 0x31, 0xC3, 0xA3,  0x55, 0x4A, 0x9B, 0x24, 
	0x10, 0x47, 0x4A, 0xAF,  0xCF, 0x00, 0x01, 0x01,   0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x01, 0x01, 
	0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x1A, 0x36,   0x80, 0xA0, 0x70, 0x38,  0x1F, 0x40, 0x30, 0x20, 
	0x35, 0x00, 0xA2, 0x0B,  0x32, 0x00, 0x00, 0x1A,   0x00, 0x00, 0x00, 0xFD,  0x00, 0x32, 0x55, 0x1F, 
	0x46, 0x0F, 0x00, 0x0A,  0x20, 0x20, 0x20, 0x20,   0x20, 0x20, 0x00, 0x00,  0x00, 0xFF, 0x00, 0x53, 
	0x4B, 0x46, 0x4A, 0x42,  0x4C, 0x30, 0x37, 0x30,   0x32, 0x30, 0x32, 0x39,  0x00, 0x00, 0x00, 0xFC, 
	0x00, 0x53, 0x56, 0x34,  0x32, 0x32, 0x58, 0x56,   0x54, 0x0A, 0x20, 0x20,  0x20, 0x20, 0x00, 0x5D, 
	0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00
};
void vDrvLoadVgaEdid2Table(void)
{
    UINT64 u8Offset;
    UINT8 idx = 0;
    //read form eeprom or flash to VGA_EDID_TABLE

#ifdef CC_MULTI_EDID
    UINT32 u4EdidOffset;
    if(DRVCUST_InitQuery(eEdidVgaIndexOffset, &u4EdidOffset) == 0)
    {
        EEPROM_Read((UINT64)u4EdidOffset, (UINT32)&idx, 1);
    }
#endif

    if((idx+1)*VGA_EDID_SIZE > VGA_EDID_STORAGE_SIZE)
    {
        u8Offset = 0;
    }
    else
    {
        u8Offset = idx*VGA_EDID_SIZE;
    }
    //Printf("read edid from eeprom\n");
#ifndef CC_DISABLE_VGA_EDID_FROM_EEP //wait for eeprom ready
    if(EEPVGAEDID_Read(u8Offset,  (UINT32) VGA_EDID_TABLE, VGA_EDID_SIZE ))
    {
        Printf("read eeprom edid fail\n");
    }
#endif

}
#endif

#ifndef CC_HDMI_EDID_DISABLE
/*
All value of Port 0 is in HDMIEDID_CEC_192k_DeepColor12B_P0
Arrangement of HDMICEC_SETTING is
Port2 CEC physical address
Port3 CEC physical address
Port4 CEC physical address
*/
UINT8 HDMICEC_SETTING[3]=
{
	0x20, // Port2 CEC physical address
	0x30, // Port2 CEC physical address
	0x40, // Port2 CEC physical address
};

UINT8 HDMIEDID_table[256] =
{
    0x00, 0xFF, 0xFF, 0xFF,  0xFF, 0xFF, 0xFF, 0x00, 0x36, 0x8B, 0x01, 0x00,  0x01, 0x01, 0x01, 0x01,
    0x01, 0x0F, 0x01, 0x03,  0x80, 0x3C, 0x22, 0x78, 0x0A, 0x0D, 0xC9, 0xA0,  0x57, 0x47, 0x98, 0x27,
    0x12, 0x48, 0x4C, 0xBF,  0xEF, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x01, 0x01,
    0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x01, 0x1D, 0x00, 0x72, 0x51, 0xD0,  0x1E, 0x20, 0x6E, 0x28,
    0x55, 0x00, 0xC4, 0x8E,  0x21, 0x00, 0x00, 0x1E, 0x01, 0x1D, 0x80, 0x18,  0x71, 0x1C, 0x16, 0x20,
    0x58, 0x2C, 0x25, 0x00,  0xC4, 0x8E, 0x21, 0x00, 0x00, 0x9E, 0x00, 0x00,  0x00, 0xFC, 0x00, 0x4D,
    0x54, 0x4B, 0x20, 0x4C,  0x43, 0x44, 0x54, 0x56, 0x0A, 0x20, 0x20, 0x20,  0x00, 0x00, 0x00, 0xFD,
    0x00, 0x31, 0x4C, 0x0F,  0x50, 0x0E, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20,  0x20, 0x20, 0x01, 0x56,
    0x02, 0x03, 0x23, 0x74,  0x4B, 0x84, 0x10, 0x1F, 0x05, 0x13, 0x14, 0x01,  0x02, 0x11, 0x06, 0x15,
    0x26, 0x09, 0x7F, 0x03,  0x11, 0x7F, 0x18, 0x83, 0x01, 0x00, 0x00, 0x67,  0x03, 0x0C, 0x00, 0x10,
    0x00, 0xB8, 0x2D, 0x01,  0x1D, 0x00, 0xBC, 0x52, 0xD0, 0x1E, 0x20, 0xB8,  0x28, 0x55, 0x40, 0xC4,
    0x8E, 0x21, 0x00, 0x00,  0x1E, 0x01, 0x1D, 0x80, 0xD0, 0x72, 0x1C, 0x16,  0x20, 0x10, 0x2C, 0x25,
    0x80, 0xC4, 0x8E, 0x21,  0x00, 0x00, 0x9E, 0x8C, 0x0A, 0xD0, 0x8A, 0x20,  0xE0, 0x2D, 0x10, 0x10,
    0x3E, 0x96, 0x00, 0x13,  0x8E, 0x21, 0x00, 0x00, 0x18, 0x8C, 0x0A, 0xD0,  0x90, 0x20, 0x40, 0x31,
    0x20, 0x0C, 0x40, 0x55,  0x00, 0x13, 0x8E, 0x21, 0x00, 0x00, 0x18, 0x00,  0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x52
};

UINT8 HDMIEDID_CEC_192k_DeepColor12B_P0[256] =
{
    0x00, 0xFF, 0xFF, 0xFF,  0xFF, 0xFF, 0xFF, 0x00,   0x36, 0x8B, 0x01, 0x00,  0x01, 0x01, 0x01, 0x01,
    0x01, 0x0F, 0x01, 0x03,  0x80, 0x3C, 0x22, 0x78,   0x0A, 0x0D, 0xC9, 0xA0,  0x57, 0x47, 0x98, 0x27,
    0x12, 0x48, 0x4C, 0xBF,  0xEF, 0x00, 0x01, 0x01,   0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x01, 0x01,
    0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x01, 0x1D,   0x00, 0x72, 0x51, 0xD0,  0x1E, 0x20, 0x6E, 0x28,
    0x55, 0x00, 0xC4, 0x8E,  0x21, 0x00, 0x00, 0x1E,   0x01, 0x1D, 0x80, 0x18,  0x71, 0x1C, 0x16, 0x20,
    0x58, 0x2C, 0x25, 0x00,  0xC4, 0x8E, 0x21, 0x00,   0x00, 0x9E, 0x00, 0x00,  0x00, 0xFC, 0x00, 0x4D,
    0x54, 0x4B, 0x20, 0x4C,  0x43, 0x44, 0x54, 0x56,   0x0A, 0x20, 0x20, 0x20,  0x00, 0x00, 0x00, 0xFD,
    0x00, 0x31, 0x4C, 0x0F,  0x50, 0x0E, 0x00, 0x0A,   0x20, 0x20, 0x20, 0x20,  0x20, 0x20, 0x01, 0x56,
    0x02, 0x03, 0x23, 0x74,  0x4B, 0x84, 0x10, 0x1F,   0x05, 0x13, 0x14, 0x01,  0x02, 0x11, 0x06, 0x15,
    0x26, 0x09, 0x7F, 0x03,  0x11, 0x7F, 0x18, 0x83,   0x01, 0x00, 0x00, 0x67,  0x03, 0x0C, 0x00, 0x10,
    0x00, 0xB8, 0x2D, 0x01,  0x1D, 0x00, 0xBC, 0x52,   0xD0, 0x1E, 0x20, 0xB8,  0x28, 0x55, 0x40, 0xC4,
    0x8E, 0x21, 0x00, 0x00,  0x1E, 0x01, 0x1D, 0x80,   0xD0, 0x72, 0x1C, 0x16,  0x20, 0x10, 0x2C, 0x25,
    0x80, 0xC4, 0x8E, 0x21,  0x00, 0x00, 0x9E, 0x8C,   0x0A, 0xD0, 0x8A, 0x20,  0xE0, 0x2D, 0x10, 0x10,
    0x3E, 0x96, 0x00, 0x13,  0x8E, 0x21, 0x00, 0x00,   0x18, 0x8C, 0x0A, 0xD0,  0x90, 0x20, 0x40, 0x31,
    0x20, 0x0C, 0x40, 0x55,  0x00, 0x13, 0x8E, 0x21,   0x00, 0x00, 0x18, 0x00,  0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x52
};
UINT8 HDMIEDID_3D_CEC_192k_DeepColor12B_P0[256] =
{
	0x00, 0xFF, 0xFF, 0xFF,  0xFF, 0xFF, 0xFF, 0x00, 0x36, 0x8B, 0x01, 0x00,  0x01, 0x01, 0x01, 0x01, 
	0x01, 0x0F, 0x01, 0x03,  0x80, 0x3C, 0x22, 0x78, 0x0A, 0x0D, 0xC9, 0xA0,  0x57, 0x47, 0x98, 0x27, 
	0x12, 0x48, 0x4C, 0xBF,  0xEF, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x01, 0x01, 
	0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x01, 0x1D, 0x00, 0x72, 0x51, 0xD0,  0x1E, 0x20, 0x6E, 0x28, 
	0x55, 0x00, 0xC4, 0x8E,  0x21, 0x00, 0x00, 0x1E, 0x01, 0x1D, 0x80, 0x18,  0x71, 0x1C, 0x16, 0x20, 
	0x58, 0x2C, 0x25, 0x00,  0xC4, 0x8E, 0x21, 0x00, 0x00, 0x9E, 0x00, 0x00,  0x00, 0xFC, 0x00, 0x4D, 
	0x54, 0x4B, 0x20, 0x4C,  0x43, 0x44, 0x54, 0x56, 0x0A, 0x20, 0x20, 0x20,  0x00, 0x00, 0x00, 0xFD, 
	0x00, 0x31, 0x4C, 0x0F,  0x50, 0x0E, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20,  0x20, 0x20, 0x01, 0x56, 
	0x02, 0x03, 0x26, 0x74,  0x4B, 0x84, 0x10, 0x1F, 0x05, 0x13, 0x14, 0x01,  0x02, 0x11, 0x06, 0x15, 
	0x26, 0x09, 0x7F, 0x03,  0x11, 0x7F, 0x18, 0x83, 0x01, 0x00, 0x00, 0x6A,  0x03, 0x0C, 0x00, 0x10, 
	0x00, 0xF8, 0x2D, 0x2F,  0x80, 0x00, 0x01, 0x1D, 0x00, 0xBC, 0x52, 0xD0,  0x1E, 0x20, 0xB8, 0x28, 
	0x55, 0x40, 0xC4, 0x8E,  0x21, 0x00, 0x00, 0x1E, 0x01, 0x1D, 0x80, 0xD0,  0x72, 0x1C, 0x16, 0x20, 
	0x10, 0x2C, 0x25, 0x80,  0xC4, 0x8E, 0x21, 0x00, 0x00, 0x9E, 0x8C, 0x0A,  0xD0, 0x8A, 0x20, 0xE0, 
	0x2D, 0x10, 0x10, 0x3E,  0x96, 0x00, 0x13, 0x8E, 0x21, 0x00, 0x00, 0x18,  0x8C, 0x0A, 0xD0, 0x90, 
	0x20, 0x40, 0x31, 0x20,  0x0C, 0x40, 0x55, 0x00, 0x13, 0x8E, 0x21, 0x00,  0x00, 0x18, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x5D
};
UINT8 HDMIEDID_4K2K_P0[256] =
{
	0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x4d, 0xd9, 0xf3, 0xb4, 0x01, 0x01, 0x01, 0x01,
	0x31, 0x15, 0x01, 0x03, 0x80, 0xe0, 0x77, 0x78, 0x0a, 0x99, 0x55, 0xae, 0x51, 0x49, 0xb2, 0x24,
	0x0d, 0x50, 0x54, 0xa1, 0x08, 0x00, 0x90, 0x40, 0x81, 0x80, 0x81, 0x40, 0x01, 0x01, 0x01, 0x01,
	0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x3a, 0x80, 0x18, 0x71, 0x38, 0x2d, 0x40, 0x58, 0x2c,
	0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0e, 0x1f, 0x00, 0x80, 0x51, 0x00, 0x1e, 0x30,
	0x40, 0x80, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x17,
	0x40, 0x0f, 0x44, 0x0f, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc,
	0x00, 0x56, 0x50, 0x4c, 0x2d, 0x56, 0x57, 0x31, 0x30, 0x30, 0x30, 0x45, 0x53, 0x0a, 0x01, 0xb4,
	0x02, 0x03, 0x33, 0xf0, 0x4c, 0x10, 0x1f, 0x20, 0x05, 0x14, 0x04, 0x13, 0x03, 0x12, 0x07, 0x16,
	0x01, 0x26, 0x09, 0x7f, 0x03, 0x11, 0x7f, 0x18, 0x7a, 0x03, 0x0c, 0x00, 0x10, 0x00, 0xb8, 0x3c,
	0xe0, 0x1c, 0xff, 0x1c, 0xff, 0xc8, 0x88, 0x01, 0x02, 0x03, 0x00, 0x01, 0x40, 0x00, 0x63, 0x38, 
	0x10, 0x48, 0x10, 0x02, 0x3a, 0x80, 0xd0, 0x72, 0x38, 0x2d, 0x40, 0x10, 0x2c, 0x45, 0x80, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x1e, 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, 0x58, 0x2c, 0x25,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9e, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0, 0x2d, 0x10, 0x10,
	0x3e, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x8c, 0x0a, 0xd0, 0x90, 0x20, 0x40, 0x31,
	0x20, 0x0c, 0x40, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x39
};
UINT8 HDMI2EDID_table[256] = 
{
	0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x36, 0x8B, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 
	0x01, 0x0F, 0x01, 0x03, 0x80, 0x73, 0x41, 0x78, 0x0A, 0xCF, 0x74, 0xA3, 0x57, 0x4C, 0xB0, 0x23, 
	0x09, 0x48, 0x4C, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0xFF, 0x01, 0xFF, 0xFF, 0x01, 0x01, 0x01, 
	0x01, 0x01, 0x01, 0x01, 0x01, 0x20, 0x08, 0xE8, 0x00, 0x30, 0xF2, 0x70, 0x5A, 0x80, 0xB0, 0x58, 
	0x8A, 0x00, 0xC4, 0x8E, 0x21, 0x00, 0x00, 0x1E, 0x02, 0x3A, 0x80, 0x18, 0x71, 0x38, 0x2D, 0x40, 
	0x58, 0x2C, 0x45, 0x00, 0xC4, 0x8E, 0x21, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x4D, 
	0x53, 0x74, 0x61, 0x72, 0x20, 0x44, 0x65, 0x6D, 0x6F, 0x0A, 0x20, 0x20, 0x00, 0x00, 0x00, 0xFD, 
	0x00, 0x3B, 0x3C, 0x1F, 0x2D, 0x08, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x2C, 
	0x02, 0x03, 0x49, 0xF2, 0x57, 0x01, 0x02, 0x03, 0x84, 0x05, 0x06, 0x07, 0x90, 0x11, 0x12, 0x13, 
	0x14, 0x15, 0x16, 0x1F, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x65, 0x66, 0x26, 0x08, 0x1F, 0x07, 
	0x10, 0x1F, 0x0C, 0x6E, 0x03, 0x0C, 0x00, 0x10, 0x00, 0xF8, 0x3C, 0x20, 0x80, 0x80, 0x01, 0x02, 
	0x03, 0x04, 0x67, 0xD8, 0x5D, 0xC4, 0x01, 0x78, 0xC8, 0x07, 0x6E, 0x03, 0x0C, 0x00, 0x10, 0x00, 
	0xF8, 0x3C, 0x20, 0x80, 0x80, 0x01, 0x02, 0x03, 0x04, 0x8C, 0x0A, 0xD0, 0x8A, 0x20, 0xE0, 0x2D, 
	0x10, 0x10, 0x3E, 0x96, 0x00, 0xC4, 0x8E, 0x21, 0x00, 0x00, 0x18, 0x8C, 0x0A, 0xA0, 0x14, 0x51, 
	0xF0, 0x16, 0x00, 0x26, 0x7C, 0x43, 0x00, 0xC4, 0x8E, 0x21, 0x00, 0x00, 0x18, 0x01, 0x1D, 0x00, 
	0x72, 0x51, 0xD0, 0x1E, 0x20, 0x6E, 0x28, 0x55, 0x00, 0xC4, 0x8E, 0x21, 0x00, 0x00, 0x1E, 0x7C 
};

UINT8 u1Hdmi2Edid_20[FLASH_HDMI_2_0_EDID_SIZE]=
{
    0x00, 0xFF, 0xFF, 0xFF,  0xFF, 0xFF, 0xFF, 0x00,   0x4D, 0xD9, 0x03, 0x98,  0x01, 0x01, 0x01, 0x01, 
	0x01, 0x1A, 0x01, 0x03,  0x80, 0xA0, 0x5A, 0x78,   0x0A, 0x0D, 0xC9, 0xA0,  0x57, 0x47, 0x98, 0x27, 
	0x12, 0x48, 0x4C, 0x21,  0x08, 0x00, 0x81, 0x80,   0xA9, 0xC0, 0x71, 0x4F,  0xB3, 0x00, 0x01, 0x01, 
	0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x02, 0x3A,   0x80, 0x18, 0x71, 0x38,  0x2D, 0x40, 0x58, 0x2C, 
	0x45, 0x00, 0x40, 0x84,  0x63, 0x00, 0x00, 0x1E,   0x01, 0x1D, 0x00, 0x72,  0x51, 0xD0, 0x1E, 0x20, 
	0x6E, 0x28, 0x55, 0x00,  0x40, 0x84, 0x63, 0x00,   0x00, 0x1E, 0x00, 0x00,  0x00, 0xFC, 0x00, 0x53, 
	0x4F, 0x4E, 0x59, 0x20,  0x54, 0x56, 0x20, 0x20,   0x2A, 0x30, 0x30, 0x0A,  0x00, 0x00, 0x00, 0xFD, 
	0x00, 0x30, 0x3E, 0x0E,  0x46, 0x1E, 0x00, 0x0A,   0x20, 0x20, 0x20, 0x20,  0x20, 0x20, 0x01, 0xFD, 
	0x02, 0x03, 0x5F, 0xF0,  0x5B, 0x61, 0x60, 0x5D,   0x5E, 0x5F, 0x62, 0x1F,  0x10, 0x14, 0x05, 0x13, 
	0x04, 0x20, 0x22, 0x3C,  0x3E, 0x12, 0x16, 0x03,   0x07, 0x11, 0x15, 0x02,  0x06, 0x01, 0x65, 0x66, 
	0x2C, 0x0D, 0x7F, 0x07,  0x15, 0x07, 0x50, 0x35,   0x05, 0x50, 0x3D, 0x07,  0xBC, 0x83, 0x0F, 0x00, 
	0x00, 0x78, 0x03, 0x0C,  0x00, 0x10, 0x00, 0xB8,   0x30, 0x2F, 0xD0, 0x8A,  0x01, 0x02, 0x03, 0x04, 
	0x01, 0x40, 0x1F, 0xC0,  0x80, 0x90, 0xD0, 0xE0,   0xF0, 0xD6, 0x67, 0xD8,  0x5D, 0xC4, 0x01, 0x78, 
	0x80, 0x01, 0xE2, 0x00,  0xF9, 0xE3, 0x05, 0xFF,   0x01, 0xE5, 0x0F, 0x03,  0x00, 0x00, 0x06, 0x01, 
	0x1D, 0x80, 0x18, 0x71,  0x1C, 0x16, 0x20, 0x58,   0x2C, 0x25, 0x00, 0x40,  0x84, 0x63, 0x00, 0x00, 
	0x9E, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0xCD
};

UINT8 u1Hdmi2Edid_20_14[FLASH_HDMI_2_0_EDID_SIZE]=
{
    0x00, 0xFF, 0xFF, 0xFF,  0xFF, 0xFF, 0xFF, 0x00,   0x4D, 0xD9, 0x03, 0x95,  0x01, 0x01, 0x01, 0x01, 
	0x01, 0x1A, 0x01, 0x03,  0x80, 0xA0, 0x5A, 0x78,   0x0A, 0x0D, 0xC9, 0xA0,  0x57, 0x47, 0x98, 0x27, 
	0x12, 0x48, 0x4C, 0x21,  0x08, 0x00, 0x81, 0x80,   0xA9, 0xC0, 0x71, 0x4F,  0xB3, 0x00, 0x01, 0x01, 
	0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x02, 0x3A,   0x80, 0x18, 0x71, 0x38,  0x2D, 0x40, 0x58, 0x2C, 
	0x45, 0x00, 0x40, 0x84,  0x63, 0x00, 0x00, 0x1E,   0x01, 0x1D, 0x00, 0x72,  0x51, 0xD0, 0x1E, 0x20, 
	0x6E, 0x28, 0x55, 0x00,  0x40, 0x84, 0x63, 0x00,   0x00, 0x1E, 0x00, 0x00,  0x00, 0xFC, 0x00, 0x53, 
	0x4F, 0x4E, 0x59, 0x20,  0x54, 0x56, 0x20, 0x20,   0x2A, 0x30, 0x30, 0x0A,  0x00, 0x00, 0x00, 0xFD, 
	0x00, 0x30, 0x3E, 0x0E,  0x46, 0x1E, 0x00, 0x0A,   0x20, 0x20, 0x20, 0x20,  0x20, 0x20, 0x01, 0x00, 
	0x02, 0x03, 0x53, 0xF0,  0x57, 0x5D, 0x5E, 0x5F,   0x62, 0x1F, 0x10, 0x14,  0x05, 0x13, 0x04, 0x20, 
	0x22, 0x3C, 0x3E, 0x12,  0x16, 0x03, 0x07, 0x11,   0x15, 0x02, 0x06, 0x01,  0x2C, 0x0D, 0x7F, 0x07, 
	0x15, 0x07, 0x50, 0x35,  0x05, 0x50, 0x3D, 0x07,   0xBC, 0x83, 0x0F, 0x00,  0x00, 0x78, 0x03, 0x0C, 
	0x00, 0x10, 0x00, 0xB8,  0x3C, 0x2F, 0xD0, 0x8A,   0x01, 0x02, 0x03, 0x04,  0x01, 0x40, 0x07, 0xF0, 
	0x60, 0x70, 0xB0, 0xC0,  0xD0, 0xB6, 0xE2, 0x00,   0xF9, 0xE3, 0x05, 0xFF,  0x01, 0xE5, 0x0E, 0x60, 
	0x61, 0x65, 0x66, 0x01,  0x1D, 0x80, 0x18, 0x71,   0x1C, 0x16, 0x20, 0x58,  0x2C, 0x25, 0x00, 0x40, 
	0x84, 0x63, 0x00, 0x00,  0x9E, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0xDD
};

UINT8 u1Hdmi2Edid_14[FLASH_HDMI_2_0_EDID_SIZE]=
{
    0x00, 0xFF, 0xFF, 0xFF,  0xFF, 0xFF, 0xFF, 0x00,   0x4D, 0xD9, 0x03, 0x95,  0x01, 0x01, 0x01, 0x01, 
	0x01, 0x1A, 0x01, 0x03,  0x80, 0xA0, 0x5A, 0x78,   0x0A, 0x0D, 0xC9, 0xA0,  0x57, 0x47, 0x98, 0x27, 
	0x12, 0x48, 0x4C, 0x21,  0x08, 0x00, 0x81, 0x80,   0xA9, 0xC0, 0x71, 0x4F,  0xB3, 0x00, 0x01, 0x01, 
	0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x02, 0x3A,   0x80, 0x18, 0x71, 0x38,  0x2D, 0x40, 0x58, 0x2C, 
	0x45, 0x00, 0x40, 0x84,  0x63, 0x00, 0x00, 0x1E,   0x01, 0x1D, 0x00, 0x72,  0x51, 0xD0, 0x1E, 0x20, 
	0x6E, 0x28, 0x55, 0x00,  0x40, 0x84, 0x63, 0x00,   0x00, 0x1E, 0x00, 0x00,  0x00, 0xFC, 0x00, 0x53, 
	0x4F, 0x4E, 0x59, 0x20,  0x54, 0x56, 0x20, 0x20,   0x2A, 0x30, 0x30, 0x0A,  0x00, 0x00, 0x00, 0xFD, 
	0x00, 0x30, 0x3E, 0x0E,  0x46, 0x1E, 0x00, 0x0A,   0x20, 0x20, 0x20, 0x20,  0x20, 0x20, 0x01, 0x00, 
	0x02, 0x03, 0x53, 0xF0,  0x57, 0x5D, 0x5E, 0x5F,   0x62, 0x1F, 0x10, 0x14,  0x05, 0x13, 0x04, 0x20, 
	0x22, 0x3C, 0x3E, 0x12,  0x16, 0x03, 0x07, 0x11,   0x15, 0x02, 0x06, 0x01,  0x2C, 0x0D, 0x7F, 0x07, 
	0x15, 0x07, 0x50, 0x35,  0x05, 0x50, 0x3D, 0x07,   0xBC, 0x83, 0x0F, 0x00,  0x00, 0x78, 0x03, 0x0C, 
	0x00, 0x10, 0x00, 0xB8,  0x3C, 0x2F, 0xD0, 0x8A,   0x01, 0x02, 0x03, 0x04,  0x01, 0x40, 0x07, 0xF0, 
	0x60, 0x70, 0xB0, 0xC0,  0xD0, 0xB6, 0xE2, 0x00,   0xF9, 0xE3, 0x05, 0xFF,  0x01, 0xE5, 0x0E, 0x60, 
	0x61, 0x65, 0x66, 0x01,  0x1D, 0x80, 0x18, 0x71,   0x1C, 0x16, 0x20, 0x58,  0x2C, 0x25, 0x00, 0x40, 
	0x84, 0x63, 0x00, 0x00,  0x9E, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0xDD
};

UINT8 u1MhlEdid_P0[256]=
{
#if 0
	0x00, 0xFF, 0xFF, 0xFF,  0xFF, 0xFF, 0xFF, 0x00,   0x36, 0x8B, 0x01, 0x00,  0x01, 0x01, 0x01, 0x01,
    0x01, 0x0F, 0x01, 0x03,  0x80, 0x3C, 0x22, 0x78,   0x0A, 0x0D, 0xC9, 0xA0,  0x57, 0x47, 0x98, 0x27,
    0x12, 0x48, 0x4C, 0xBF,  0xEF, 0x00, 0x01, 0x01,   0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x01, 0x01,
    0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x01, 0x1D,   0x00, 0x72, 0x51, 0xD0,  0x1E, 0x20, 0x6E, 0x28,
    0x55, 0x00, 0xC4, 0x8E,  0x21, 0x00, 0x00, 0x1E,   0x01, 0x1D, 0x80, 0x18,  0x71, 0x1C, 0x16, 0x20,
    0x58, 0x2C, 0x25, 0x00,  0xC4, 0x8E, 0x21, 0x00,   0x00, 0x9E, 0x00, 0x00,  0x00, 0xFC, 0x00, 0x4D,
    0x54, 0x4B, 0x20, 0x4C,  0x43, 0x44, 0x54, 0x56,   0x0A, 0x20, 0x20, 0x20,  0x00, 0x00, 0x00, 0xFD,
    0x00, 0x31, 0x4C, 0x0F,  0x50, 0x0E, 0x00, 0x0A,   0x20, 0x20, 0x20, 0x20,  0x20, 0x20, 0x01, 0x56,
    0x02, 0x03, 0x23, 0x74,  0x4B, 0x84, 0x10, 0x1F,   0x05, 0x13, 0x14, 0x01,  0x02, 0x11, 0x06, 0x15,
    0x26, 0x09, 0x7F, 0x03,  0x11, 0x7F, 0x18, 0x83,   0x01, 0x00, 0x00, 0x67,  0x03, 0x0C, 0x00, 0x10,
    0x00, 0xB8, 0x2D, 0x01,  0x1D, 0x00, 0xBC, 0x52,   0xD0, 0x1E, 0x20, 0xB8,  0x28, 0x55, 0x40, 0xC4,
    0x8E, 0x21, 0x00, 0x00,  0x1E, 0x01, 0x1D, 0x80,   0xD0, 0x72, 0x1C, 0x16,  0x20, 0x10, 0x2C, 0x25,
    0x80, 0xC4, 0x8E, 0x21,  0x00, 0x00, 0x9E, 0x8C,   0x0A, 0xD0, 0x8A, 0x20,  0xE0, 0x2D, 0x10, 0x10,
    0x3E, 0x96, 0x00, 0x13,  0x8E, 0x21, 0x00, 0x00,   0x18, 0x8C, 0x0A, 0xD0,  0x90, 0x20, 0x40, 0x31,
    0x20, 0x0C, 0x40, 0x55,  0x00, 0x13, 0x8E, 0x21,   0x00, 0x00, 0x18, 0x00,  0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x52
#else
	0x00, 0xFF, 0xFF, 0xFF,  0xFF, 0xFF, 0xFF, 0x00,   0x36, 0x8B, 0x01, 0x00,  0x01, 0x01, 0x01, 0x01, 
	0x01, 0x0F, 0x01, 0x03,  0x80, 0x3C, 0x22, 0x78,   0x0A, 0x0D, 0xC9, 0xA0,  0x57, 0x47, 0x98, 0x27, 
	0x12, 0x48, 0x4C, 0xBF,  0xEF, 0x00, 0x01, 0x01,   0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x01, 0x01, 
	0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x01, 0x1D,   0x00, 0x72, 0x51, 0xD0,  0x1E, 0x20, 0x6E, 0x28, 
	0x55, 0x00, 0xC4, 0x8E,  0x21, 0x00, 0x00, 0x1E,   0x01, 0x1D, 0x80, 0x18,  0x71, 0x1C, 0x16, 0x20, 
	0x58, 0x2C, 0x25, 0x00,  0xC4, 0x8E, 0x21, 0x00,   0x00, 0x9E, 0x00, 0x00,  0x00, 0xFC, 0x00, 0x4D, 
	0x54, 0x4B, 0x20, 0x4C,  0x43, 0x44, 0x54, 0x56,   0x0A, 0x20, 0x20, 0x20,  0x00, 0x00, 0x00, 0xFD, 
	0x00, 0x31, 0x4C, 0x0F,  0x50, 0x0E, 0x00, 0x0A,   0x20, 0x20, 0x20, 0x20,  0x20, 0x20, 0x01, 0x56, 
	0x02, 0x03, 0x31, 0x74,  0x56, 0x84, 0x10, 0x1F,   0x05, 0x13, 0x14, 0x20,  0x02, 0x11, 0x06, 0x15, 
	0x22, 0x4E, 0x56, 0x57,  0x59, 0x5D, 0x5E, 0x5F,   0x62, 0x63, 0x64, 0x26,  0x0F, 0x7F, 0x01, 0x17, 
	0x7F, 0x18, 0x83, 0x01,  0x00, 0x00, 0x6A, 0x03,   0x0C, 0x00, 0x10, 0x00,  0xF8, 0x2D, 0x2F, 0x80, 
	0x00, 0x01, 0x1D, 0x00,  0xBC, 0x52, 0xD0, 0x1E,   0x20, 0xB8, 0x28, 0x55,  0x40, 0xC4, 0x8E, 0x21, 
	0x00, 0x00, 0x1E, 0x01,  0x1D, 0x80, 0xD0, 0x72,   0x1C, 0x16, 0x20, 0x10,  0x2C, 0x25, 0x80, 0xC4, 
	0x8E, 0x21, 0x00, 0x00,  0x9E, 0x8C, 0x0A, 0xD0,   0x8A, 0x20, 0xE0, 0x2D,  0x10, 0x10, 0x3E, 0x96, 
	0x00, 0x13, 0x8E, 0x21,  0x00, 0x00, 0x18, 0x8C,   0x0A, 0xD0, 0x90, 0x20,  0x40, 0x31, 0x20, 0x0C, 
	0x40, 0x55, 0x00, 0x13,  0x8E, 0x21, 0x00, 0x00,   0x18, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x65
#endif
};

void vDrvLoadHdmiEdid2Table(void)
{
#ifndef CC_FPGA
    UINT64 u8Offset;
    UINT8 idx = 0;
    //read form eeprom or flash to VGA_EDID_TABLE

#ifdef CC_MULTI_EDID
    UINT32 u4EdidOffset;
    if(DRVCUST_InitQuery(eEdidHdmiIndexOffset, &u4EdidOffset) == 0)
    {
        EEPROM_Read((UINT64)u4EdidOffset, (UINT32)&idx, 1);
    }
#endif

    if((idx+1)*HDMI_EDID_SIZE > HDMI_EDID_STORAGE_SIZE)
    {
        u8Offset = 0;
    }
    else
    {
        u8Offset = idx*HDMI_EDID_SIZE;
    }
    //read form eeprom or flash to HDMIEDID_CEC_192k_DeepColor12B_P0
    if (EEPHDMIEDID_Read(u8Offset,  (UINT32) HDMIEDID_table, HDMI_EDID_SIZE ))
    {
        Printf("read eeprom edid fail\n");
    }

#endif
}

#ifdef CC_HDMI_2_0_HDCP_BIN
void vHDMIDebugPrintf(char *str, void *pData, UINT32 u4Length)
{
    UINT32 i=0;
    UINT8 *pdata = (UINT8 *)pData;

    if(u1EdidDebuglvl == 0)
    {
        return;
    }
    if(str!=NULL)
    {
        LOG(1, "%s", str);
    }
    for(i=0;i<u4Length;i++)
    {   
        if((i%16) == 0)
        {
            Printf("\n");
        }
        Printf("0x%02x,", pdata[i]);
    }
    Printf("\n");
}

#ifndef CC_MTK_LOADER
void vHDMIEDIDCLIDebug(EDID_SELECT_INFO_T* prSelectInfo);
UINT8 u1CheckCLIFlag(CLI_FLAG_T tflag);
void vSetCLIFlag(CLI_FLAG_T tflag);
#endif

void vHDMIEDIDGetPlatformType(UINT8 *pu1Info)
{
    EEPROM_Read(0x10000, (UINT32)(pu1Info), 0x1);
}

void vHDMIEDIDGet4K2K(UINT8 *pu1Info)
{
    UINT32 u4Value = 0;
    //bit[1], 0:2k, 1:4k
    EEPROM_Read(0x10010, (UINT32)(&u4Value), 0x1);
    *pu1Info = (u4Value&0x02)?1:0;
}

void vHDMIEDIDGetDolbyVision(UINT8 *pu1Info)
{
    UINT32 u4Value = 0;
    //bit[3:1], 101:dolby vision, else:none.
    EEPROM_Read(0x10010, (UINT32)(&u4Value), 0x1);
    *pu1Info = (((u4Value>>1)&0x07)==0x5)?1:0;
}

void vHDMIEDIDGetBankNum(UINT8 *pu1Info)
{
    EEPROM_Read(0x1008E, (UINT32)(pu1Info), 0x1);
}

void vHDMIEDIDGetCBA(UINT8 *pu1Info)
{
    *pu1Info = 0;
}

void vHDMIEDIDGetDestination(UINT8 *pu1Info)
{
    EEPROM_Read(0x10200, (UINT32)(pu1Info), 0x1);
}

void vHDMIEDIDGet3D(UINT8 *pu1Info)
{
    EEPROM_Read(0x10206, (UINT32)(pu1Info), 0x1);
}

void vHDMIEDIDGetHDR(UINT8 *pu1Info)
{
    EEPROM_Read(0x10209, (UINT32)(pu1Info), 0x1);
}

void vHDMIEDIDGetHFVSDBFlag(UINT8 *pu1hfvsdbInfo)
{
    EEPROM_Read(0x38E, (UINT32)(pu1hfvsdbInfo), 0x1);
}
void vHDMIEDIDSetHFVSDBFlag(UINT8 *pu1hfvsdbInfo)
{
    EEPROM_Write(0x38E, (UINT32)(pu1hfvsdbInfo), 0x1);
}

void vHDMIEDIDGetLDDDP(UINT8 *pu1LDDP)
{
    EEPROM_Read(0x38F, (UINT32)(pu1LDDP), 0x1);
}

void vHDMIEDIDSetLDDDP(UINT8 *pu1LDDP)
{
    EEPROM_Write(0x38F, (UINT32)(pu1LDDP), 0x1);
}

BOOL bEEPHDMIEDIDRead(UINT32 u4MemPtr, UINT32 u4MemLen, UINT32 u4Offset)
{
    INT32 i4Ret = 0;
    UINT32 u4PartId = 0;

    u4PartId = (UINT32)DRVCUST_InitGet(eHDMI20EDIDNANDPartId);
	if(u4PartId == 0)
	{
        return FALSE;
	}

    i4Ret = EEPHDMI_Read(u4PartId, (UINT64)u4Offset, u4MemPtr, u4MemLen, FLASH_HDMI_EDID_DATA_SIZE);
    if(i4Ret)
    {
        return FALSE;
    }

    return TRUE;
}

BOOL _bHDMIEDIDCalculateChecksum(UINT8 *pu1EdidData)
{
    UINT8 u1CheckSum = 0;
    UINT8 i;

    if(pu1EdidData == NULL)
    {
        return FALSE;
    }
    for(i=0; i<=0x7E; i++)
    {
        u1CheckSum += *(pu1EdidData + i);
    }
    *(pu1EdidData + 0x7F) = 0x100 - u1CheckSum;

    u1CheckSum = 0;
    for(i=0x80; i<=0xFE; i++)
    {
        u1CheckSum += *(pu1EdidData + i);
    }
    *(pu1EdidData + 0xFF) = 0x100 - u1CheckSum;
    return TRUE;
}

BOOL bHDMIEDIDCalculateChecksum(EDID_SELECT_INFO_T* prSelectInfo)
{
    if(_bHDMIEDIDCalculateChecksum(prSelectInfo->pTargetMIDEDID) == FALSE)
    {
        LOG(0, "[EDID]Calculate Checksum Fail\n");
        return FALSE;
    }

    if(_bHDMIEDIDCalculateChecksum(prSelectInfo->pTargetSIDEDID) == FALSE)
    {
        LOG(0, "[EDID]Calculate Checksum Fail\n");
        return FALSE;
    }

    LOG(1, "[EDID]Calculate Checksum:\n");
    vHDMIDebugPrintf("[EDID]MID edid data:\n", prSelectInfo->pTargetMIDEDID, 256);
    vHDMIDebugPrintf("[EDID]SID edid data:\n", prSelectInfo->pTargetSIDEDID, 256);
    return TRUE;
}

BOOL bHDMIEDIDCreateSelectInfo(EDID_SELECT_INFO_T* prSelectInfo, UINT8 *pEdid14, UINT8 *pEdid20, UINT8 *pEepBlock, UINT16 u2EDIDDataSize)
{
#ifdef CC_PANEL_FROM_FLASH
    UINT32 u4PanelCtrl;
#endif

    if(prSelectInfo == NULL)
    {
        return FALSE;
    }
    x_memset(prSelectInfo, 0, sizeof(EDID_SELECT_INFO_T));

    vHDMIEDIDGetCBA(&prSelectInfo->u1CBA);
    vHDMIEDIDGetPlatformType(&prSelectInfo->u1Platform);
    vHDMIEDIDGetDestination(&prSelectInfo->u1MVIDestination);
    vHDMIEDIDGet3D(&prSelectInfo->u1MVINO_3D);
    vHDMIEDIDGetHDR(&prSelectInfo->u1HDR);
    vHDMIEDIDGetHFVSDBFlag(&prSelectInfo->u1HFVSDBFlag);
    vHDMIEDIDGetLDDDP(&prSelectInfo->u1ATMOS);
    vHDMIEDIDGetDolbyVision(&prSelectInfo->u1DolbyVision);

#ifdef CC_PANEL_FROM_FLASH
    u4PanelCtrl =  FlashPanel_GetControlWord3();
    prSelectInfo->u4PanelCtrl = u4PanelCtrl;
    prSelectInfo->u1Panel_less = ((u4PanelCtrl>>31) & (0x1))? 0 : 1;
    prSelectInfo->u1Panel3DType = (u4PanelCtrl & (0x0C000000))>>26;   // modify at Oct11; from "(0x70000000))>>28"
    prSelectInfo->u1PanelWCG = (u4PanelCtrl & 0x3);
    prSelectInfo->u4PanleSize = FlashPanel_GetInchSize();  // need to change to panelSizeApi;		
#else
    prSelectInfo->u1Panel_less = 0;
    prSelectInfo->u1Panel3DType = 0;
    prSelectInfo->u1PanelWCG = 0;
    prSelectInfo->u4PanleSize = 0x38;		
#endif
    //to do in detail
    if(prSelectInfo->u1Platform == 0x04)
    {
        //trinity3
        vHDMIEDIDGet4K2K(&prSelectInfo->u14K2K);
        vHDMIEDIDGetBankNum(&prSelectInfo->u1BankNum);
    }
#ifndef CC_MTK_LOADER
    vHDMIEDIDCLIDebug(prSelectInfo);
#endif
    prSelectInfo->u2BlockOffset = 0;
    prSelectInfo->u1BlockFlag = 0;
    prSelectInfo->pEepBlock = pEepBlock;
    prSelectInfo->u2EepDataSize = u2EDIDDataSize;
    prSelectInfo->pTargetMIDEDID = pEdid14;
    prSelectInfo->pTargetSIDEDID = pEdid20;
    return TRUE;
}

BOOL bHDMIEDIDGetWholeBlock(EDID_SELECT_INFO_T* prSelectInfo)
{
    UINT8 u1HeaderSize = 0x40;
    UINT32 u4Offset = 0;
    UINT32 u4NextOffset = 0;
    UINT16 u2SizeRemain=0;
    char pHeaderFlag[7] = "FMT300";
    UINT8 *pEDIDEepData = NULL;

    if(prSelectInfo == NULL)
    {
        return FALSE;
    }

    if(prSelectInfo->pEepBlock == NULL)
    {
        LOG(0, "EDID Buffer Error\n");
        return FALSE;
    }

    pEDIDEepData = prSelectInfo->pEepBlock;

    LOG(1, "[EDID]*******************Search Whole Block******************\n");
    //parse valid edid block data.
    while(1)
    {
        if(bEEPHDMIEDIDRead((UINT32)pEDIDEepData, (UINT32)u1HeaderSize, u4Offset) == TRUE)
        {
            //check format, must be same as "FMT300"
            if(x_memcmp(pEDIDEepData, pHeaderFlag,6) != 0)
            {
                LOG(0, "[EDID]edid header error!\n");
                break;
            }

            u4NextOffset = (*(pEDIDEepData + EDID_END_ADDRESS_EEP_DATA_2)<<16) |\
                           (*(pEDIDEepData + EDID_END_ADDRESS_EEP_DATA_1)<<8) |\
                           (*(pEDIDEepData + EDID_END_ADDRESS_EEP_DATA_0)) + 1;
            if(u4NextOffset < u4Offset + u1HeaderSize)
            {
                LOG(0, "[EDID]edid struct error!\n");
                break;
            }
            LOG(1, "[EDID]u4NextOffset:0x%x!\n",u4NextOffset);

            //check edid bank
            //if not same, check next bank
            if(*(pEDIDEepData + 0x06) != prSelectInfo->u1BankNum)
            {
                if(*(pEDIDEepData + 0x06) == 0)
                {
                    //save bank[0] offset
                    prSelectInfo->u2BlockOffset = u4Offset;
                    u2SizeRemain = u4NextOffset -u4Offset;
                    prSelectInfo->u1BlockFlag = 2;
                    LOG(0, "[EDID]edid bank[0] find!\n");
                }
                else
                {
                    LOG(0, "[EDID]current edid bank is 0x%x!\n",*(pEDIDEepData + 0x06));
                }
                u4Offset = u4NextOffset;
                continue;
            }
            //match the edid block
            prSelectInfo->u2BlockOffset = u4Offset;
            prSelectInfo->u1BlockFlag = 1;
            u2SizeRemain = u4NextOffset -u4Offset -u1HeaderSize;
            break;
        }
        else
        {
            LOG(0, "[EDID]EEP Read Fail!\n");
        }
        break;
    }

    if(prSelectInfo->u1BlockFlag == 1)
    {
        LOG(0, "[EDID]match edid block, offset:0x%x, remain size to read:0x%x\n",prSelectInfo->u2BlockOffset,u2SizeRemain);
        if(bEEPHDMIEDIDRead((UINT32)(pEDIDEepData + u1HeaderSize), (UINT32)u2SizeRemain, prSelectInfo->u2BlockOffset+ u1HeaderSize) == TRUE)
        {
            return TRUE;
        }
    }
    else if(prSelectInfo->u1BlockFlag == 2)
    {
        //the header data is broken, so the size to read should be the whole size.
        LOG(0, "[EDID]match edid bank[0], offset:0x%x, size:0x%x\n",prSelectInfo->u2BlockOffset,u2SizeRemain);
        if(bEEPHDMIEDIDRead((UINT32)(pEDIDEepData), (UINT32)u2SizeRemain, prSelectInfo->u2BlockOffset) == TRUE)
        {
            return TRUE;
        }
    }

    return FALSE;
}

void vHDMIEDIDPrintfSelectInfo(EDID_SELECT_INFO_T* prSelectInfo)
{
    LOG(1, "[EDID]MVIDestination:0x%x\n", prSelectInfo->u1MVIDestination);
    LOG(1, "[EDID]MVINO_3D:0x%x\n", prSelectInfo->u1MVINO_3D);
    LOG(1, "[EDID]IT4:0x%x\n", prSelectInfo->u1HFVSDBFlag);
    LOG(1, "[EDID]HDR:0x%x\n", prSelectInfo->u1HDR);
    LOG(1, "[EDID]LDDDP:0x%x\n", prSelectInfo->u1ATMOS);
    LOG(1, "[EDID]Panel ControlWord3:0x%x\n", prSelectInfo->u4PanelCtrl);
    LOG(1, "[EDID]Panel less:0x%x\n", prSelectInfo->u1Panel_less);
    LOG(1, "[EDID]Panel3DType:0x%x\n", prSelectInfo->u1Panel3DType);
    LOG(1, "[EDID]PanelWCG:0x%x\n", prSelectInfo->u1PanelWCG);
    LOG(1, "[EDID]PanelSize:0x%x\n", prSelectInfo->u4PanleSize);
    LOG(1, "[EDID]Platform:0x%x\n", prSelectInfo->u1Platform);
    LOG(1, "[EDID]4K2K:0x%x\n", prSelectInfo->u14K2K);
    LOG(1, "[EDID]BankNum:0x%x\n", prSelectInfo->u1BankNum);
    LOG(1, "[EDID]Dolby Vision:0x%x\n", prSelectInfo->u1DolbyVision);
    if(prSelectInfo->u1Platform >= 0x04)
    {
        LOG(1,"[EDID]Trinity3 platform\n");
    }
    else if(prSelectInfo->u1Platform == 0x03)
    {
        LOG(1,"[EDID]Trinity2 platform\n");
    }
    else if(prSelectInfo->u1Platform == 0x02)
    {
        LOG(1,"[EDID]Trinity platform\n");
    }
}

BOOL bHDMIEDIDGetTableAndEepHeader(EDID_SELECT_INFO_T* prSelectInfo)
{
    UINT32 u4TableIDAddr, u4EDIDEepAddr, u4EDIDEndAddr;
    UINT8* pEDIDEepData = NULL;

    if(prSelectInfo == NULL)
    {
        return FALSE;
    }
    if(prSelectInfo->pEepBlock == NULL)
    {
        LOG(0, "[EDID]pEDIDEepData Buffer NULL\n");
        return FALSE;
    }

    pEDIDEepData = prSelectInfo->pEepBlock;

    u4TableIDAddr = (*(pEDIDEepData + EDID_SART_ADDRESS_SELECT_TABLE_1)<<8) | (*(pEDIDEepData + EDID_SART_ADDRESS_SELECT_TABLE_0));
    u4EDIDEepAddr = (*(pEDIDEepData + EDID_SART_ADDRESS_EEP_DATA_1)<<8) | (*(pEDIDEepData + EDID_SART_ADDRESS_EEP_DATA_0));
    u4EDIDEndAddr = (*(pEDIDEepData + EDID_END_ADDRESS_EEP_DATA_2)<<16) |\
                                        (*(pEDIDEepData + EDID_END_ADDRESS_EEP_DATA_1)<<8) |\
                                        (*(pEDIDEepData + EDID_END_ADDRESS_EEP_DATA_0));
    if((u4TableIDAddr < (prSelectInfo->u2BlockOffset))||\
        (u4EDIDEepAddr< (prSelectInfo->u2BlockOffset))||\
        (u4EDIDEndAddr < (prSelectInfo->u2BlockOffset)))
    {
        LOG(0, "[EDID]edid internal address error!\n");
        return FALSE;
    }
    
    prSelectInfo->u2TableSize = (u4EDIDEepAddr - u4TableIDAddr);
    if(prSelectInfo->u2TableSize > 512)
    {
        prSelectInfo->u2TableSize = 512;
    }
    LOG(0, "[EDID]Table Size:%d, ID Addr:0x%x, Start Data addr:0x%x, End addr:0x%x\n",prSelectInfo->u2TableSize,u4TableIDAddr,u4EDIDEepAddr,u4EDIDEndAddr);
    prSelectInfo->u4TableIDAddr = u4TableIDAddr -prSelectInfo->u2BlockOffset;
    prSelectInfo->u4EepHeaderAddr = u4EDIDEepAddr -prSelectInfo->u2BlockOffset;
    prSelectInfo->u4EepBlockEndAddr = u4EDIDEndAddr -prSelectInfo->u2BlockOffset;

    return TRUE;
}

BOOL bHDMIEDIDGetTrinityMIDAndSID(EDID_SELECT_INFO_T* prSelectInfo ,Trinity_Table_T* prSelectTable)
{
    UINT32 u4Offset = 0;
    UINT16 u2Count, u2TableSize;
    Trinity_Table_T rSelectTableSrc;
    UINT8* pEDIDEepData = NULL;

    if(prSelectInfo == NULL)
    {
        return FALSE;
    }

    //Make search data
    if(prSelectInfo->u1MVIDestination == 0xF)
    {
        prSelectTable->u1JPN_WW = 1;
    }
    if((prSelectInfo->u1MVINO_3D == 0)&&(prSelectInfo->u1Panel3DType != 0))
    {
        prSelectTable->u12D3D = 1;
    }
    if(prSelectInfo->u1PanelWCG == 0)
    {
        prSelectTable->u1BT20201 = 0;
        prSelectTable->u1xvYCC = 0;
    }
    else
    {
        prSelectTable->u1BT20201 = 1;
        prSelectTable->u1xvYCC = 1;
    }
    prSelectTable->u1HDR = prSelectInfo->u1HDR;
    prSelectTable->u1ATMOS = prSelectInfo->u1ATMOS;
    prSelectTable->u1DolbyVision = prSelectInfo->u1DolbyVision;

    if(prSelectInfo->u1Panel_less == 1)
    {
        prSelectTable->u1Panel_less = 1;
    }

#ifndef CC_MTK_LOADER
    if(u1CheckCLIFlag(CLI_FLAG_SETID))
    {
        LOG(0, "[EDID]Set fixed MID_ID:0x%x, SID_ID:0x%x\n", prSelectInfo->u4MID, prSelectInfo->u4SID);
        return TRUE;
    }
    if(u1CheckCLIFlag(CLI_FLAG_SEARCH))
    {
        x_memcpy(prSelectTable, t_cli_cust.pu1SearchData, 16);
        LOG(0, "[EDID]Set fixed search condition, 0x%2x%2x%2x%2x\n", \
                                t_cli_cust.pu1SearchData[2],\
                                t_cli_cust.pu1SearchData[3],\
                                t_cli_cust.pu1SearchData[4],\
                                t_cli_cust.pu1SearchData[5]);
    }
#endif

    vHDMIDebugPrintf("[EDID]Target Eep Header:", (UINT8 *)prSelectTable, 16);
    LOG(1, "[EDID]*******************Search EEP Header******************\n");

    //Calculate MID&SID
    if(prSelectTable->u1CBA == 1)
    {
        if(prSelectTable->u1JPN_WW == 1)
        {
            prSelectInfo->u4MID = 0x01F100;
            prSelectInfo->u4SID = 0x01FC00;
        }
        else
        {
            prSelectInfo->u4MID = 0x01F000;
            prSelectInfo->u4SID = 0x01F600;
        }
    }
    else if(prSelectTable->u1Panel_less == 1)
    {
        if(prSelectTable->u1JPN_WW == 1)
        {
            prSelectInfo->u4MID = 0x023700;
            prSelectInfo->u4SID = 0x023F01;
        }
        else
        {
            prSelectInfo->u4MID = 0x023300;
            prSelectInfo->u4SID = 0x023B01;
        }
    }
    else
    {
        //Read whole header
        u4Offset = prSelectInfo->u4TableIDAddr;
        u2TableSize = prSelectInfo->u2TableSize;
        pEDIDEepData = prSelectInfo->pEepBlock;
        for(u2Count = 0; u2Count < (u2TableSize/16); u2Count++) 
        {
            x_memset(&rSelectTableSrc, 0, sizeof(Trinity_Table_T));
            x_memcpy(&rSelectTableSrc, (pEDIDEepData + u2Count*16 + u4Offset), 16);
            rSelectTableSrc.u4MID_ID = (rSelectTableSrc.u1MID_ID_Byte2<<16) |\
                                                                (rSelectTableSrc.u1MID_ID_Byte1<<8) |\
                                                                rSelectTableSrc.u1MID_ID_Byte0;
            rSelectTableSrc.u4SID_ID = (rSelectTableSrc.u1SID_ID_Byte2<<16)|\
                                                                (rSelectTableSrc.u1SID_ID_Byte1<<8) |\
                                                                rSelectTableSrc.u1SID_ID_Byte0;

            LOG(1, "[EDID]Header Addr:0x%x\n", prSelectInfo->u2BlockOffset + u2Count*16 + u4Offset);
            vHDMIDebugPrintf(NULL, &rSelectTableSrc, 16);

            if(x_memcmp(prSelectTable, &rSelectTableSrc, 6) == 0) //Compare 6 Bytes
            {
                break;
            }
        }
        if(u2Count>= (u2TableSize/16))
        {
            prSelectInfo->u4MID = 0x01ED00;
            prSelectInfo->u4SID = 0x01ED00;
        }
        else
        {
            prSelectInfo->u4MID = rSelectTableSrc.u4MID_ID;
            prSelectInfo->u4SID = rSelectTableSrc.u4SID_ID;
        }
    }
    LOG(0, "[EDID]Trinity MID_ID:0x%x, SID_ID:0x%x\n", prSelectInfo->u4MID, prSelectInfo->u4SID);
    return TRUE;
}

//0: search id successfully  1:fail
BOOL bHDMIEDIDTrinity3PreSearchID(EDID_SELECT_INFO_T* prSelectInfo, Trinity3_Table_T* prSelectTable)
{
    //any particlular bit is "1"?
    if((prSelectTable->u1CBA == 0)&&(prSelectTable->u1Panel_less == 0))
    {
        return 1;
    }
    
    if(prSelectInfo->u1BankNum == 0)
    {
        if(prSelectTable->u1CBA == 1)
        {
            if(prSelectTable->u1JPN_WW == 1)
            {
                prSelectInfo->u4MID = 0x01F100;
                prSelectInfo->u4SID = 0x01FC00;
            }
            else
            {
                prSelectInfo->u4MID = 0x01F000;
                prSelectInfo->u4SID = 0x01F600;
            }
        }
        else if(prSelectTable->u1Panel_less == 1)
        {
            if(prSelectTable->u1JPN_WW == 1)
            {
                prSelectInfo->u4MID = 0x023700;
                prSelectInfo->u4SID = 0x023F00;
            }
            else
            {
                prSelectInfo->u4MID = 0x023300;
                prSelectInfo->u4SID = 0x023B00;
            }
        }
        else
        {
            prSelectInfo->u4MID = 0x01ED00;
            prSelectInfo->u4SID = 0x01ED00;
        }
    }
    else if(prSelectInfo->u14K2K == 0)//2k
    {
        if(prSelectTable->u1CBA == 1)
        {
            if(prSelectTable->u1JPN_WW == 1)
            {
                prSelectInfo->u4MID = 0x050800;
            }
            else
            {
                prSelectInfo->u4MID = 0x050700;
            }
        }
        else if(prSelectTable->u1Panel_less == 1)
        {
            if(prSelectTable->u1JPN_WW == 1)
            {
                prSelectInfo->u4MID = 0x050600;
            }
            else
            {
                prSelectInfo->u4MID = 0x050500;
            }
        }
        else
        {
            prSelectInfo->u4MID = 0x04B000;
        }
        prSelectInfo->u4SID = prSelectInfo->u4MID;
    }
    else//4k
    {
        if(prSelectTable->u1CBA == 1)
        {
            if(prSelectTable->u1JPN_WW == 1)
            {
                prSelectInfo->u4MID = 0x048D00;
                prSelectInfo->u4SID = 0x048F00;
            }
            else
            {
                prSelectInfo->u4MID = 0x048C00;
                prSelectInfo->u4SID = 0x048E00;
            }
        }
        else if(prSelectTable->u1Panel_less == 1)
        {
            if(prSelectTable->u1JPN_WW == 1)
            {
                prSelectInfo->u4MID = 0x048900;
                prSelectInfo->u4SID = 0x048B00;
            }
            else
            {
                prSelectInfo->u4MID = 0x048800;
                prSelectInfo->u4SID = 0x048A00;
            }
        }
        else
        {
            prSelectInfo->u4MID = 0x049000;
            prSelectInfo->u4SID = 0x049000;
        }
    }
    return 0;
}

BOOL bHDMIEDIDGetTrinity3MIDAndSID(EDID_SELECT_INFO_T* prSelectInfo, Trinity3_Table_T* prSelectTable)
{
    UINT32 u4Offset = 0;
    UINT16 u2Count, u2TableSize;
    Trinity3_Table_T rSelectTableSrc;
    UINT8* pEDIDEepData = NULL;

    if(prSelectInfo == NULL)
    {
        return FALSE;
    }
    //Make search data
    if(prSelectInfo->u1MVIDestination == 0xF)
    {
        prSelectTable->u1JPN_WW = 1;
    }
    if((prSelectInfo->u1MVINO_3D == 0)&&(prSelectInfo->u1Panel3DType != 0))
    {
        prSelectTable->u12D3D = 1;
    }
    if(prSelectInfo->u1PanelWCG == 0)
    {
        prSelectTable->u1BT20201 = 0;
        prSelectTable->u1xvYCC = 0;
    }
    else
    {
        prSelectTable->u1BT20201 = 1;
        prSelectTable->u1xvYCC = 1;
    }
    prSelectTable->u1HDR = prSelectInfo->u1HDR;
    prSelectTable->u1ATMOS = prSelectInfo->u1ATMOS;
    prSelectTable->u14K2K = prSelectInfo->u14K2K;
    prSelectTable->u1DolbyVision = prSelectInfo->u1DolbyVision;

    if(prSelectInfo->u1Panel_less == 1)
    {
        prSelectTable->u1Panel_less = 1;
    }

#ifndef CC_MTK_LOADER
    if(u1CheckCLIFlag(CLI_FLAG_SETID))
    {
        LOG(0, "[EDID]Set fixed MID_ID:0x%x, SID_ID:0x%x\n", prSelectInfo->u4MID, prSelectInfo->u4SID);
        return TRUE;
    }
    if(u1CheckCLIFlag(CLI_FLAG_SEARCH))
    {
        x_memcpy(prSelectTable, t_cli_cust.pu1SearchData, 16);
        LOG(0, "[EDID]Set fixed search condition, 0x%2x%2x%2x%2x\n", \
                                t_cli_cust.pu1SearchData[2],\
                                t_cli_cust.pu1SearchData[3],\
                                t_cli_cust.pu1SearchData[4],\
                                t_cli_cust.pu1SearchData[5]);
    }
#endif

    vHDMIDebugPrintf("[EDID]Target Eep Header:", prSelectTable, 16);
    LOG(1, "[EDID]*******************Search EEP Header******************\n");

    //Calculate MID&SID
    if(bHDMIEDIDTrinity3PreSearchID(prSelectInfo, prSelectTable))
    {
        //Read whole header
        u4Offset = prSelectInfo->u4TableIDAddr;
        u2TableSize = prSelectInfo->u2TableSize;
        pEDIDEepData = prSelectInfo->pEepBlock;
        for(u2Count = 0; u2Count < (u2TableSize/16); u2Count++) 
        {
            x_memset(&rSelectTableSrc, 0, sizeof(Trinity3_Table_T));
            x_memcpy(&rSelectTableSrc, (pEDIDEepData + u2Count*16 + u4Offset), 16);
            rSelectTableSrc.u4MID_ID = (rSelectTableSrc.u1MID_ID_Byte2<<16) |\
                                                                (rSelectTableSrc.u1MID_ID_Byte1<<8) |\
                                                                rSelectTableSrc.u1MID_ID_Byte0;
            rSelectTableSrc.u4SID_ID = (rSelectTableSrc.u1SID_ID_Byte2<<16)|\
                                                                (rSelectTableSrc.u1SID_ID_Byte1<<8) |\
                                                                rSelectTableSrc.u1SID_ID_Byte0;

            LOG(1, "[EDID]Header Addr:0x%x\n", prSelectInfo->u2BlockOffset + u2Count*16 + u4Offset);
            vHDMIDebugPrintf(NULL, &rSelectTableSrc, 16);

            if(x_memcmp(prSelectTable, &rSelectTableSrc, 6) == 0) //Compare 6 Bytes
            {
                break;
            }
        }
        if(u2Count>= (u2TableSize/16))
        {
            if(prSelectInfo->u1BankNum == 0)
            {
                prSelectInfo->u4MID = 0x01ED00;
                prSelectInfo->u4SID = 0x01ED00;
            }
            else if(prSelectInfo->u14K2K == 0)//2k
            {
                prSelectInfo->u4MID = 0x04B000;
                prSelectInfo->u4SID = 0x04B000;
            }
            else
            {
                prSelectInfo->u4MID = 0x049000;
                prSelectInfo->u4SID = 0x049000;
            }
        }
        else
        {
            prSelectInfo->u4MID = rSelectTableSrc.u4MID_ID;
            prSelectInfo->u4SID = rSelectTableSrc.u4SID_ID;
        }
    }
    LOG(0, "[EDID]Trinity3 MID_ID:0x%x, SID_ID:0x%x\n\n\n", prSelectInfo->u4MID, prSelectInfo->u4SID);
    return TRUE;
}

BOOL bHDMIEDIDGetMIDAndSID(EDID_SELECT_INFO_T* prSelectInfo)
{
    if(prSelectInfo == NULL)
    {
        return FALSE;
    }
    x_memset(&prSelectInfo->uSelect, 0, sizeof(uSelectTable));

    //to do in detail
    if(prSelectInfo->u1Platform == 0x04)
    {
        return bHDMIEDIDGetTrinity3MIDAndSID(prSelectInfo, &prSelectInfo->uSelect.Trinity3Table);
    }
    else
    {
        return bHDMIEDIDGetTrinityMIDAndSID(prSelectInfo, &prSelectInfo->uSelect.TrinityTable);
    }
    
    return TRUE;
}

BOOL bHDMIEDIDSearchIDData(EDID_SELECT_INFO_T* prSelectInfo)
{
    UINT16 u2Count;
    UINT32 u4Offset, u4EdidID;
    UINT8 u1SearchResult = 0;
    UINT8* pEDIDEepData = NULL;

    if(prSelectInfo == NULL)
    {
        return FALSE;
    }

    if((prSelectInfo->pEepBlock == NULL)||\
        (prSelectInfo->pTargetMIDEDID == NULL)||\
        (prSelectInfo->pTargetSIDEDID == NULL))
    {
        LOG(0, "[EDID]Buffer NULL\n");
        return FALSE;
    }
    
    LOG(1, "[EDID]*******************Search ID Data******************\n");

    pEDIDEepData = prSelectInfo->pEepBlock;
    for(u2Count = 0; u2Count < HDMI_EDID_SUBPPORT_MAXNUM; u2Count++)//u2TableSize*2, MID and SID
    {
        u4Offset = prSelectInfo->u4EepHeaderAddr + u2Count*512;
        if(u4Offset > (prSelectInfo->u4EepBlockEndAddr))
        {
            LOG(0, "[EDID]Error, reach end of the edid block!\n");
            return FALSE;
        }

        //to do in detail
        if(prSelectInfo->u1Platform == 0x04)
        {
            u4EdidID = (*(pEDIDEepData + 2 + u4Offset)<<16) | (*(pEDIDEepData + 3 + u4Offset)<<8) | (*(pEDIDEepData + 4 + u4Offset));
        }
        else
        {
            u4EdidID = (*(pEDIDEepData + 2 + u4Offset)<<16) | (*(pEDIDEepData + 3 + u4Offset)<<8) | (*(pEDIDEepData + 4 + u4Offset));
        }

        LOG(1, "[EDID]Current ID: 0x%x, addr:0x%x\n", u4EdidID, prSelectInfo->u2BlockOffset + u4Offset);
        vHDMIDebugPrintf(NULL, pEDIDEepData + u4Offset, 16);

        if(u4EdidID == prSelectInfo->u4MID)
        {
            u1SearchResult |= 0x01;
            prSelectInfo->u4EepMIDStartAddr = u4Offset + 16;
            LOG(1, "[EDID]MID Data found, start addr:0x%x\n\n\n",prSelectInfo->u4EepMIDStartAddr + prSelectInfo->u2BlockOffset);
            LOG(1, "[EDID]*******************Found MID Data******************\n");
        }

        if(u4EdidID == prSelectInfo->u4SID)
        {
            u1SearchResult |= 0x02;
            prSelectInfo->u4EepSIDStartAddr = u4Offset + 16;
            LOG(1, "[EDID]SID Data found, start addr:0x%x\n\n\n",prSelectInfo->u4EepSIDStartAddr + prSelectInfo->u2BlockOffset);
            LOG(1, "[EDID]*******************Found SID Data******************\n");
        }

        if(u1SearchResult == 0x03)
        {
            break;
        }
    }

    if(u1SearchResult != 0x03)
    {
        LOG(0, "[EDID]Error, Search Result:0x%x!\n",u1SearchResult);
        return FALSE;
    }
    x_memcpy(prSelectInfo->pTargetMIDEDID, (pEDIDEepData + prSelectInfo->u4EepMIDStartAddr), 256);
    x_memcpy(prSelectInfo->pTargetSIDEDID, (pEDIDEepData + prSelectInfo->u4EepSIDStartAddr), 256);
    return TRUE;
}

BOOL bHDMIEDIDGetDisplaySize(EDID_SELECT_INFO_T* prSelectInfo)
{
    UINT32 u4DisplaySizeHTemp, u4DisplaySizeVTemp, u4DisplaySizeH, u4DisplaySizeV;

    if(prSelectInfo == NULL)
    {
        return FALSE;
    }

    u4DisplaySizeHTemp = ((UINT32)(16 * prSelectInfo->u4PanleSize * 2540 * 1000) / 183576);
    u4DisplaySizeVTemp = ((UINT32)(9 * prSelectInfo->u4PanleSize * 2540 * 1000)/ 183576); 

    u4DisplaySizeH = (u4DisplaySizeHTemp + 5)/10;
    u4DisplaySizeV = (u4DisplaySizeVTemp + 5)/10;
					
    prSelectInfo->u1DisByte0 = (u4DisplaySizeHTemp +50)/100;
    prSelectInfo->u1DisByte1 = (u4DisplaySizeVTemp +50)/100;

    prSelectInfo->u1ImageByte0 = (UINT8)u4DisplaySizeH;
    prSelectInfo->u1ImageByte1 = (UINT8)u4DisplaySizeV;
    prSelectInfo->u1ImageByte2 = (((u4DisplaySizeH>>8)&0x0F)<<4) |((u4DisplaySizeV>>8)&0x0F);

    LOG(1, "[EDID]Display Size:0x%x 0x%x\n", \
                                        prSelectInfo->u1DisByte0, \
                                        prSelectInfo->u1DisByte1);
    LOG(1, "[EDID]Image Size:0x%x 0x%x 0x%x\n\n", \
                                        prSelectInfo->u1ImageByte0, \
                                        prSelectInfo->u1ImageByte1, \
                                        prSelectInfo->u1ImageByte2);
    
    return TRUE;
}

BOOL _bHDMIEDIDFixDisplaySize(EDID_SELECT_INFO_T* prSelectInfo, UINT8 u1Type)
{
    UINT8 u1Count, u1ImageSizeAddr;
    UINT8 *pu1EdidData = NULL;
    UINT32 u4EepStartAddr;

    if(u1Type == EDID_SPEC_TYPE_SID)
    {
        u4EepStartAddr = prSelectInfo->u4EepSIDStartAddr;
        pu1EdidData = prSelectInfo->pTargetSIDEDID;
    }
    else if(u1Type == EDID_SPEC_TYPE_MID)
    {
        u4EepStartAddr = prSelectInfo->u4EepMIDStartAddr;
        pu1EdidData = prSelectInfo->pTargetMIDEDID;
    }
    else
    {
        return FALSE;
    }
    //Change eep infromation
    for(u1Count=1; u1Count<=0xf; u1Count++)
    {
        u1ImageSizeAddr = *(prSelectInfo->pEepBlock+ u4EepStartAddr + 256 + u1Count);
        if(u1ImageSizeAddr != 0xFF)
        {
            *(pu1EdidData + u1ImageSizeAddr) = prSelectInfo->u1ImageByte0;
            *(pu1EdidData + u1ImageSizeAddr + 1) = prSelectInfo->u1ImageByte1;
            *(pu1EdidData + u1ImageSizeAddr + 2) = prSelectInfo->u1ImageByte2;
        }
    }

    *(pu1EdidData + 0x15) = prSelectInfo->u1DisByte0;
    *(pu1EdidData + 0x16) = prSelectInfo->u1DisByte1;

    return TRUE;
}

BOOL bHDMIEDIDFixDisplaySize(EDID_SELECT_INFO_T* prSelectInfo)
{
    if(prSelectInfo == NULL)
    {
        return FALSE;
    }
    if((prSelectInfo->pEepBlock == NULL)||\
        (prSelectInfo->pTargetMIDEDID == NULL)||\
        (prSelectInfo->pTargetSIDEDID == NULL))
    {
        LOG(0, "[EDID]Buffer NULL\n");
        return FALSE;
    }

    if(bHDMIEDIDGetDisplaySize(prSelectInfo) == FALSE)
    {
        LOG(0, "[EDID]GetDisplayImageSize Fail\n");
        return FALSE;
    }

    //Change MID eep infromation
    if(_bHDMIEDIDFixDisplaySize(prSelectInfo, EDID_SPEC_TYPE_MID) == FALSE)
    {
        return FALSE;
    }

    //Change SID eep infromation
    if(prSelectInfo->u1HFVSDBFlag&0x3)
    {
        if(_bHDMIEDIDFixDisplaySize(prSelectInfo, EDID_SPEC_TYPE_SID) == FALSE)
        {
            return FALSE;
        }
    }
    else
    {
        x_memcpy(prSelectInfo->pTargetSIDEDID, prSelectInfo->pTargetMIDEDID, 256);
    }
    _bHDMIEDIDCalculateChecksum(prSelectInfo->pTargetMIDEDID);
    _bHDMIEDIDCalculateChecksum(prSelectInfo->pTargetSIDEDID);
    vHDMIDebugPrintf("[EDID]MID edid data:\n", prSelectInfo->pTargetMIDEDID, 256);
    vHDMIDebugPrintf("[EDID]SID edid data:\n", prSelectInfo->pTargetSIDEDID, 256);
    return TRUE;
}

BOOL _bHDMIEDIDFixDolbyBlock(EDID_SELECT_INFO_T* prSelectInfo, UINT8 u1Type)
{
    UINT8 u1Count, u1DolbyBlockAddr;
    UINT8 *pu1EdidData = NULL;
    UINT32 u4EepStartAddr;
    UINT8 u1Tmp=0;

    if(u1Type == EDID_SPEC_TYPE_SID)
    {
        u4EepStartAddr = prSelectInfo->u4EepSIDStartAddr;
        pu1EdidData = prSelectInfo->pTargetSIDEDID;
    }
    else if(u1Type == EDID_SPEC_TYPE_MID)
    {
        u4EepStartAddr = prSelectInfo->u4EepMIDStartAddr;
        pu1EdidData = prSelectInfo->pTargetMIDEDID;
    }
    else
    {
        return FALSE;
    }

    u1DolbyBlockAddr = *(prSelectInfo->pEepBlock+ u4EepStartAddr + 0x1c0);
    if(u1DolbyBlockAddr > 0xFA)
    {
        LOG(0, "[EDID]Dolby VSDB Addr:0x%x over 0xFA\n", u1DolbyBlockAddr);
        return TRUE;
    }
    LOG(1, "[EDID]Dolby VSDB Addr:0x%x\n", u1DolbyBlockAddr);

    x_memset(&(prSelectInfo->u1DolbyBlock[0]), 0, 6);
    x_memcpy(prSelectInfo->u1DolbyBlock, (pu1EdidData + u1DolbyBlockAddr), 4);

    u1Tmp = FlashPanel_GetDVTargetMinPQv2();
    prSelectInfo->u1DolbyBlock[0] = (u1Tmp&0xFB) + (prSelectInfo->u1DolbyBlock[0]&0x04);
    u1Tmp = FlashPanel_GetDVTargetMaxPQv2();
    prSelectInfo->u1DolbyBlock[1] = (u1Tmp&0xFB) + (prSelectInfo->u1DolbyBlock[1]&0x04);
    u1Tmp = FlashPanel_GetDVGx();
    prSelectInfo->u1DolbyBlock[2] = ((u1Tmp<<1)&0xfe) + (prSelectInfo->u1DolbyBlock[2]&0x01);
    u1Tmp = FlashPanel_GetDVGy();
    prSelectInfo->u1DolbyBlock[3] = ((u1Tmp<<1)&0xfe) + (prSelectInfo->u1DolbyBlock[3]&0x01);
    u1Tmp = FlashPanel_GetDVBx();
    prSelectInfo->u1DolbyBlock[4] = u1Tmp&0x7;
    u1Tmp = FlashPanel_GetDVBy();
    prSelectInfo->u1DolbyBlock[5] = u1Tmp&0x7;
    u1Tmp = FlashPanel_GetDVRx();
    prSelectInfo->u1DolbyBlock[4] += (u1Tmp<<3)&0xf8;
    u1Tmp = FlashPanel_GetDVRy();
    prSelectInfo->u1DolbyBlock[5] += (u1Tmp<<3)&0xf8;
    LOG(1, "[EDID]RAW Dolby PQ Data: 0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n",\
                                                                FlashPanel_GetDVTargetMinPQv2(),\
                                                                FlashPanel_GetDVTargetMaxPQv2(),\
                                                                FlashPanel_GetDVGx(),\
                                                                FlashPanel_GetDVGy(),\
                                                                FlashPanel_GetDVBx(),\
                                                                FlashPanel_GetDVBy(),\
                                                                FlashPanel_GetDVRx(),\
                                                                FlashPanel_GetDVRy());
    vHDMIDebugPrintf("[EDID]Dolby Color Data:\n", prSelectInfo->u1DolbyBlock, 6);
    x_memcpy((pu1EdidData + u1DolbyBlockAddr), prSelectInfo->u1DolbyBlock, 6);

    return TRUE;
}

BOOL bHDMIEDIDFixDolbyBlock(EDID_SELECT_INFO_T* prSelectInfo)
{
    if(prSelectInfo == NULL)
    {
        return FALSE;
    }
    if((prSelectInfo->pEepBlock == NULL)||\
        (prSelectInfo->pTargetMIDEDID == NULL)||\
        (prSelectInfo->pTargetSIDEDID == NULL))
    {
        LOG(0, "[EDID]Buffer NULL\n");
        return FALSE;
    }

    if(prSelectInfo->u1DolbyVision == 0)
    {
        return TRUE;
    }

    if(_bHDMIEDIDFixDolbyBlock(prSelectInfo, EDID_SPEC_TYPE_MID) == FALSE)
    {
        return FALSE;
    }

    if(prSelectInfo->u1HFVSDBFlag&0x3)
    {
        if(_bHDMIEDIDFixDolbyBlock(prSelectInfo, EDID_SPEC_TYPE_SID) == FALSE)
        {
            return FALSE;
        }
    }
    else
    {
        x_memcpy(prSelectInfo->pTargetSIDEDID, prSelectInfo->pTargetMIDEDID, 256);
    }

    LOG(1, "[EDID]Fix Dolby VSDB\n");
    return TRUE;
}

BOOL bHDMIMakeEDID(UINT8 *pEdid14, UINT8 *pEdid20)
{
    EDID_SELECT_INFO_T rSelectInfo;
    UINT32 u4Offset;
    UINT16 u2EDIDDataSize;
    BOOL bRet = TRUE;

    if((pEdid14 == NULL) || (pEdid20 == NULL))
    {
        return FALSE;
    }

    u2EDIDDataSize = (HDMI_EDID_SUBPPORT_MAXNUM * 512) + 1024;
    if(pHDMIEDIDEepData == NULL)
    {
        //Allocating 32k memory frequently will lead to memory shortage. 
        //So allocate memory once and don't free it until system shuts down.
        pHDMIEDIDEepData = (UINT8*) x_mem_alloc(sizeof(UINT8) * u2EDIDDataSize);
        if(pHDMIEDIDEepData == NULL)
        {
            LOG(0, "EDID Buffer malloc fail\n");
            bRet = FALSE;
            goto Exit;
        }
    }

    if(bHDMIEDIDCreateSelectInfo(&rSelectInfo, pEdid14, pEdid20, pHDMIEDIDEepData, u2EDIDDataSize) == FALSE)
    {
        LOG(0, "[EDID]CreatSelectInfo Fail\n");
        bRet = FALSE;
        goto Exit;
    }
    vHDMIEDIDPrintfSelectInfo(&rSelectInfo);

    if(bHDMIEDIDGetWholeBlock(&rSelectInfo) == FALSE)
    {
        LOG(0, "[EDID]bHDMIEDIDRead Fail\n");
        bRet = FALSE;
        goto Exit;
    }

    if(bHDMIEDIDGetTableAndEepHeader(&rSelectInfo) == FALSE)
    {
        LOG(0, "[EDID]GetTableAndEepHeader Fail\n");
        bRet = FALSE;
        goto Exit;
    }

    if(bHDMIEDIDGetMIDAndSID(&rSelectInfo) == FALSE)
    {
        LOG(0, "[EDID]GetMIDAndSID Fail\n");
        bRet = FALSE;
        goto Exit;
    }

    if(bHDMIEDIDSearchIDData(&rSelectInfo) == FALSE)
    {
        LOG(0, "[EDID]SearchIDData Fail\n");
        bRet = FALSE;
        goto Exit;
    }

    if(bHDMIEDIDFixDisplaySize(&rSelectInfo) == FALSE)
    {
        LOG(0, "[EDID]FixDisplayImageSize Fail\n");
        bRet = FALSE;
        goto Exit;
    }

    if(bHDMIEDIDFixDolbyBlock(&rSelectInfo) == FALSE)
    {
        LOG(0, "[EDID]FixDolbyBlock Fail\n");
        bRet = FALSE;
        goto Exit;
    }

    if(bHDMIEDIDCalculateChecksum(&rSelectInfo) == FALSE)
    {
        LOG(0, "[EDID]Calculate Checksum Fail\n");
        bRet = FALSE;
        goto Exit;
    }

Exit:
    return bRet;
}

void vHDMI20ReadSramEDID(UINT8 u1PortId)
{
    UINT16 u2EDIDIdx = 0;

    Printf("HDMI EDID Port %d:\n", u1PortId);
    while (u2EDIDIdx < 256)
    {
        if ((u2EDIDIdx % 16) == 0)
        {
            Printf("0x%08X ", u2EDIDIdx);
        }
        vIO32Write1B(PDWNC_EDID2_ADDR, u2EDIDIdx);

        if (u2EDIDIdx == IO32ReadFldAlign(PDWNC_EDID2_CTL1 + (u1PortId - 1) * 4, FLD_EDID2_OFFSET1) && (u1PortId != 0))
        {
            Printf("0x%02X ", IO32ReadFldAlign(PDWNC_EDID2_CTL1 + (u1PortId - 1) * 4, FLD_EDID2_PHY_ADDR1));
        }
        else if ((u2EDIDIdx == 255) && (u1PortId != 0))
        {
            Printf("0x%02X ", IO32ReadFldAlign(PDWNC_EDID2_CTL1 + (u1PortId - 1) * 4, FLD_EDID2_CHKSUM1));
        }
        else
        {
            Printf("0x%02X ", IO32ReadFldAlign(PDWNC_EDID2_DATA, FLD_EDID2_EDID_DATA));
        }
        if (((u2EDIDIdx + 1) % 16) == 0)
        {
            Printf("\n");
        }
        u2EDIDIdx++;
    }
}

void vHDMI14ReadSramEDID(UINT8 u1PortId)
{
    UINT16 u2EDIDIdx = 0;

    Printf("HDMI EDID Port %d:\n", u1PortId);
    while (u2EDIDIdx < 256)
    {
        if ((u2EDIDIdx % 16) == 0)
        {
            Printf("0x%08X ", u2EDIDIdx);
        }
        vIO32Write1B(PDWNC_EDID1_ADDR, u2EDIDIdx);

        if (u2EDIDIdx == IO32ReadFldAlign(PDWNC_EDID1_CTL1 + (u1PortId - 1) * 4, FLD_EDID1_OFFSET1) && (u1PortId != 0))
        {
            Printf("0x%02X ", IO32ReadFldAlign(PDWNC_EDID1_CTL1 + (u1PortId - 1) * 4, FLD_EDID1_PHY_ADDR1));
        }
        else if ((u2EDIDIdx == 255) && (u1PortId != 0))
        {
            Printf("0x%02X ", IO32ReadFldAlign(PDWNC_EDID1_CTL1 + (u1PortId - 1) * 4, FLD_EDID1_CHKSUM1));
        }
        else
        {
            Printf("0x%02X ", IO32ReadFldAlign(PDWNC_EDID1_DATA, FLD_EDID1_EDID_DATA));
        }
        if (((u2EDIDIdx + 1) % 16) == 0)
        {
            Printf("\n");
        }
        u2EDIDIdx++;
    }
}

void vHDMI20ReadEDIDFromSram(void)
{
    EDID_SELECT_INFO_T rSelectInfo;

    if(bHDMIEDIDCreateSelectInfo(&rSelectInfo, NULL, NULL, NULL, 0) == FALSE)
    {
        printf("[HDMI EDID]CreateSelectInfo Fail\n");
        return;
    }
    vHDMIEDIDPrintfSelectInfo(&rSelectInfo);

    vHDMI20ReadSramEDID(0);
    vHDMI20ReadSramEDID(1);
    vHDMI14ReadSramEDID(2);
    vHDMI14ReadSramEDID(3);
}

BOOL bHDMICustEDIDMake(UINT8 u1ParaCount, UINT8* pu1_SearchData, UINT8* pu1EDID14, UINT8* pu1EDID20)
{
    BOOL bRet = TRUE;

    if((pu1_SearchData == NULL)||(pu1EDID14 == NULL)||(pu1EDID20 == NULL))
    {
        return FALSE;
    }

    if(u1ParaCount == 1)
    {
        bRet = bHDMIMakeEDID(pu1EDID14, pu1EDID20);
        return bRet;
    }
    if(u1ParaCount== 5)
    {
        x_memcpy(t_cli_cust.pu1SearchData, pu1_SearchData, 16);
#ifndef CC_MTK_LOADER
        vSetCLIFlag(CLI_FLAG_SEARCH);
#endif
        bHDMIMakeEDID(pu1EDID14, pu1EDID20);
    }
    return TRUE;
}

void vMHL20EDIDReadFromEep(UINT8 *aupEdid)
{
	INT32 i4Ret;

	{
	    i4Ret = EEPMHL20EDID_Read((UINT32)aupEdid, FLASH_MHL_2_0_EDID_SIZE);
	    if (i4Ret)
		{
			Printf(" read edid data  fail\n");
		}
	}
}
#endif

UINT8* pu1DrvLoadHdmi14Edid(void)
{
#if (defined(CC_HDMI_2_0_HDCP_BIN)&&(!defined(CC_UBOOT)))
	if(bHDMIMakeEDID(HDMIEDID_table, HDMI2EDID_table) == FALSE)
	{
        Printf("HDMI Edid Data Fail\n");
	}
#endif
	return (UINT8 *)HDMIEDID_table;
}

UINT8* pu1DrvLoadHdmi20Edid(void)
{
	return (UINT8 *)HDMI2EDID_table;
}

UINT8* pu1DrvLoadMhlEdid(void)
{
	#ifdef CC_HDMI_2_0_HDCP_BIN
	vMHL20EDIDReadFromEep(u1MhlEdid_P0);
	#endif
	return (UINT8 *)u1MhlEdid_P0;
}
#endif//CC_HDMI_EDID_DISABLE

//CLI For Debug
#ifndef CC_MTK_LOADER
INT32 u4HDMIDebugLogCmd(INT32 i4Argc, const CHAR** szArgv)
{
    if(i4Argc != 2)
    {
        LOG(0, "usage: 0:disable log  1:enable log\n");
        return 0;
    }
    u1EdidDebuglvl = (UINT8)StrToInt(szArgv[1])?1:0;
    Printf("set debug lvl:0x%x\n",u1EdidDebuglvl);
    CLI_Parser_Arg("sif.hdmi.cust.d_l %d",u1EdidDebuglvl);
    return 0;
}

UINT8 u1CheckCLIFlag(CLI_FLAG_T tflag)
{
    UINT8 u1Ret=0;
    switch(tflag)
    {
        case CLI_FLAG_SETID:
            if(t_cli_cust.u4FixedFlag&(1<<15))
                u1Ret = 1;
            break;
        case CLI_FLAG_SEARCH:
            if(t_cli_cust.u4FixedFlag&(1<<16))
                u1Ret = 1;
            break;
        default:
            break;
    }
    return u1Ret;
}

void vSetCLIFlag(CLI_FLAG_T tflag)
{
    if(tflag == CLI_FLAG_SEARCH)
    {
        t_cli_cust.u4FixedFlag |= 1<<16;
    }
}

INT32 u4HDMIDebugSetStatusCmd(INT32 i4Argc, const CHAR** szArgv)
{
    UINT32 u4Type;
    UINT32 u4Status;

    if(i4Argc < 3)
    {
        LOG(0, "usage: type,status\n");
        Printf("type: \n"
            "0:Cancel\n"
            "1:Make Edid\n"
            "2:Platform\n"
            "3:4K2K\n"
            "4:BankNum\n"
            "5:PanelCtrl\n"
            "6:Panel_less\n"
            "7:Panel3DType\n");
        Printf("8:PanelWCG\n"
            "9:MVIDestination\n"
            "10:ATMOS\n"
            "11:CBA\n"
            "12:MVINO_3D\n"
            "13:HFVSDBFlag\n"
            "14:HDR\n"
            "15:MID_ID  SID_ID\n");
        Printf("16:General+Adaptive\n"
            "17:Dolby Vision\n"
              "\n");
        return 0;
    }

    u4Type = (UINT32)StrToInt(szArgv[1]);
    u4Status = (UINT32)StrToInt(szArgv[2]);

    if(u4Type>30)
    {
        return 0;
    }

    switch(u4Type)
    {
        case 0:
            LOG(0,"clear fixed flag\n");
            t_cli_cust.u4FixedFlag = 0;
            return 0;
            break;
        case 1:
            //only call to make edid.
            break;
        case 2:
            t_cli_cust.u1Platform = (UINT8)u4Status;
            break;
        case 3:
            t_cli_cust.u14K2K= (UINT8)u4Status;
            break;
        case 4:
            t_cli_cust.u1BankNum= (UINT8)u4Status;
            break;
        case 5:
            t_cli_cust.u4PanelCtrl= u4Status;
            break;
        case 6:
            t_cli_cust.u1Panel_less= (UINT8)u4Status;
            break;
        case 7:
            t_cli_cust.u1Panel3DType = (UINT8)u4Status;
            break;
        case 8:
            t_cli_cust.u1PanelWCG = (UINT8)u4Status;
            break;
        case 9:
            t_cli_cust.u1MVIDestination = (UINT8)u4Status;
            break;
        case 10:
            t_cli_cust.u1ATMOS = (UINT8)u4Status;
            break;
        case 11:
            t_cli_cust.u1CBA = (UINT8)u4Status;
            break;
        case 12:
            t_cli_cust.u1MVINO_3D = (UINT8)u4Status;
            break;
        case 13:
            t_cli_cust.u1HFVSDBFlag = (UINT8)u4Status;
            break;
        case 14:
            t_cli_cust.u1HDR = (UINT8)u4Status;
            break;
        case 15:
            if(i4Argc != 4)
            {
                return 0;
            }
            t_cli_cust.u4MID = u4Status;
            t_cli_cust.u4SID = (UINT32)StrToInt(szArgv[2]);
            LOG(0, "set mid:0x%x, sid:0x%x\n",t_cli_cust.u4MID, t_cli_cust.u4SID);
            break;
        case 16:
            if(i4Argc != 3)
            {
                return 0;
            }
            x_memset(&(t_cli_cust.pu1SearchData[0]), 0, 16);
            t_cli_cust.pu1SearchData[2] = (u4Status>>24)&0xff;
            t_cli_cust.pu1SearchData[3] = (u4Status>>16)&0xff;
            t_cli_cust.pu1SearchData[4] = (u4Status>>8)&0xff;
            t_cli_cust.pu1SearchData[5] = u4Status&0xff;
            LOG(0, "general+adaptive:0x%x, 0x%x,0x%x, 0x%x\n",\
                        t_cli_cust.pu1SearchData[2],\
                        t_cli_cust.pu1SearchData[3],\
                        t_cli_cust.pu1SearchData[4],\
                        t_cli_cust.pu1SearchData[5]);
            break;
        case 17:
            t_cli_cust.u1DolbyVision = (UINT8)u4Status;
            break;
        default:
            return 0;
            break;
    }
    t_cli_cust.u4FixedFlag |= 1<<u4Type;

    bHDMIMakeEDID(HDMIEDID_table, HDMI2EDID_table);
    return 0;
}

void vHDMIEDIDCLIDebug(EDID_SELECT_INFO_T* prSelectInfo)
{
    UINT32 u4Status = t_cli_cust.u4FixedFlag;
    UINT32 i=1;
    
    if(u4Status ==0)
    {
        return;
    }

    while((i<30)&&(u4Status>>=1))
    {
        //LOG(0,"cli debug status:0x%04x, i:0x%x\n",u4Status,i);
        if((u4Status&1) == 0)
        {
            i++;
            continue;
        }

        switch(i)
        {
            case 2:
                LOG(0, "[EDID]fix platform:0x%x\n",t_cli_cust.u1Platform);
                prSelectInfo->u1Platform = t_cli_cust.u1Platform;
                break;
            case 3:
                LOG(0, "[EDID]fix 4k2k:0x%x\n",t_cli_cust.u14K2K);
                prSelectInfo->u14K2K = t_cli_cust.u14K2K;
                break;
            case 4:
                LOG(0, "[EDID]fix bank num:0x%x\n",t_cli_cust.u1BankNum);
                prSelectInfo->u1BankNum = t_cli_cust.u1BankNum;
                break;
            case 5:
                LOG(0, "[EDID]fix PanelCtrl:0x%x\n",t_cli_cust.u4PanelCtrl);
                prSelectInfo->u4PanelCtrl = t_cli_cust.u4PanelCtrl;
                break;
            case 6:
                LOG(0, "[EDID]fix Panel_less:0x%x\n",t_cli_cust.u1Panel_less);
                prSelectInfo->u1Panel_less = t_cli_cust.u1Panel_less;
                break;
            case 7:
                LOG(0, "[EDID]fix Panel3DType:0x%x\n",t_cli_cust.u1Panel3DType);
                prSelectInfo->u1Panel3DType = t_cli_cust.u1Panel3DType;
                break;
            case 8:
                LOG(0, "[EDID]fix PanelWCG:0x%x\n",t_cli_cust.u1PanelWCG);
                prSelectInfo->u1PanelWCG = t_cli_cust.u1PanelWCG;
                break;
            case 9:
                LOG(0, "[EDID]fix MVIDestination:0x%x\n",t_cli_cust.u1MVIDestination);
                prSelectInfo->u1MVIDestination = t_cli_cust.u1MVIDestination;
                break;
            case 10:
                LOG(0, "[EDID]fix ATMOS:0x%x\n",t_cli_cust.u1ATMOS);
                prSelectInfo->u1ATMOS = t_cli_cust.u1ATMOS;
                break;
            case 11:
                LOG(0, "[EDID]fix CBA:0x%x\n",t_cli_cust.u1CBA);
                prSelectInfo->u1CBA = t_cli_cust.u1CBA;
                break;
            case 12:
                LOG(0, "[EDID]fix MVINO_3D:0x%x\n",t_cli_cust.u1MVINO_3D);
                prSelectInfo->u1MVINO_3D = t_cli_cust.u1MVINO_3D;
                break;
            case 13:
                LOG(0, "[EDID]fix HFVSDBFlag:0x%x\n",t_cli_cust.u1HFVSDBFlag);
                prSelectInfo->u1HFVSDBFlag = t_cli_cust.u1HFVSDBFlag;
                break;
            case 14:
                LOG(0, "[EDID]fix HDR:0x%x\n",t_cli_cust.u1HDR);
                prSelectInfo->u1HDR = t_cli_cust.u1HDR;
                break;
            case 15:
                prSelectInfo->u4MID = t_cli_cust.u4MID;
                prSelectInfo->u4SID = t_cli_cust.u4SID;
                break;
            case 17:
                LOG(0, "[EDID]fix DolbyVison:0x%x\n",t_cli_cust.u1DolbyVision);
                prSelectInfo->u1DolbyVision = t_cli_cust.u1DolbyVision;
                break;
            default:
                break;
        }
        i++;
    }
}

CLIMOD_DEBUG_FUNCTIONS(HDMI)
CLI_EXEC_T arSifHDMIcustCmdTbl[] = {
    CLIMOD_DEBUG_CLIENTRY(HDMI),
#ifdef CC_HDMI_2_0_HDCP_BIN
    {"dl", NULL, u4HDMIDebugLogCmd, NULL, "enable/disable log", CLI_GUEST},
    //{"earc", NULL, u4HDMIDebugEARCCmd, NULL, "test earc i2c", CLI_GUEST},
    {"ss", NULL, u4HDMIDebugSetStatusCmd, NULL, "set some status", CLI_GUEST},
#endif
    {NULL, NULL, NULL, NULL, NULL, CLI_SUPERVISOR}
};
#endif 
#endif // _EDID_CUSTOMIZATION_H_
