/* 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$
 * $Date$
 * $RCSfile: mtk_vga.h,v $
 * $Revision$
 *
 *---------------------------------------------------------------------------*/
#ifndef _EDID_CUSTOMIZATION_H_
#define _EDID_CUSTOMIZATION_H_
#include "eeprom_if.h"
#include "drv_edid.h"
#include "drv_hdmi2.h"

//#include "drvcust_if.h"

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

//---------------------------------------------------------------------------
// Type definitions
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Static variables
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Public variables
//---------------------------------------------------------------------------
#ifndef CC_S_PLATFORM
#ifndef CC_MTK_LOADER
CLI_EXEC_T arSifHDMIcustCmdTbl[] = {
    {NULL, NULL, NULL, NULL, NULL, CLI_SUPERVISOR}
};
#endif

#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
};
#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 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, 0x6E, 0x03,  0x0C, 0x00, 0x10, 0x00,   0xF8, 0x3C, 0x20, 0x80,  0x80, 0x01, 0x02, 0x03,
    0x04, 0x67, 0xD8, 0x5D,  0xC4, 0x01, 0x78, 0xC8,   0x07, 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 u1MhlEdid_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, 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
};

static UINT8 _u1AtmosEnable = 1;
#endif

//---------------------------------------------------------------------------
// Static function
//---------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Public functions
//-----------------------------------------------------------------------------
#ifndef CC_VGA_EDID_DISABLE
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, (UPTR)&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,  (UPTR) VGA_EDID_TABLE, VGA_EDID_SIZE ))
    {
       // LOG(0,"read eeprom edid fail\n");
    }
#endif

}
#endif

#ifndef CC_HDMI_EDID_DISABLE
#ifdef CC_HDMI_2_0_HDCP_BIN
extern INT32 EEPHDMI21EDID_Read(UPTR u4MemPtr, UINT32 u4MemLen);
void vHDMI14EDIDReadFromEep(UINT8 *aupEdid)
{
    INT32 i4Ret;

    i4Ret = EEPHDMI14EDID_Read((UPTR)aupEdid, FLASH_HDMI_1_4_EDID_SIZE);
    if (i4Ret)
    {
        printf("[HDMI]Read edid data fail\n");
    }
}
void vHDMI20EDIDReadFromEep(UINT8 *aupEdid)
{
    INT32 i4Ret;

    i4Ret = EEPHDMI20EDID_Read((UPTR)aupEdid, FLASH_HDMI_2_0_EDID_SIZE);
    if (i4Ret)
    {
        printf("[HDMI]Read edid data fail\n");
    }
}

void vHDMI21EDIDReadFromEep(UINT8 *aupEdid)
{
    INT32 i4Ret;

    i4Ret = EEPHDMI21EDID_Read((UPTR)aupEdid, FLASH_HDMI_2_0_EDID_SIZE);
    if (i4Ret)
    {
        printf("[HDMI]Read edid data fail\n");
    }
}


void vMHL20EDIDReadFromEep(UINT8 *aupEdid)
{
    INT32 i4Ret;

    i4Ret = EEPMHL20EDID_Read((UPTR)aupEdid, FLASH_MHL_2_0_EDID_SIZE);
    if (i4Ret)
    {
        printf( "[HDMI]Read edid data fail\n");
    }
}
#endif

UINT8 u1DrvEDIDGetAtmosEnable(void)
{
    return _u1AtmosEnable;
}

void vDrvEDIDSetAtmosEnable(UINT8 u1Enable)
{
    _u1AtmosEnable = u1Enable;
}

BOOL fgDrvEdidAtmosHandleSAD(BOOL fgSet,UINT8 u1FormatNum,UINT8 *pu1AudioDataBlock)
{
    UINT8 u1i,u1AtmosBit = 0;
    if(fgSet)
    {
        if(NULL == pu1AudioDataBlock)
        {
           // LOG(0,"fgHDMIEDIDHandleSAD:pu1AudioDataBlock is NULL!\n");
            return FALSE;
        }
        for(u1i=0; u1i<u1FormatNum; u1i++)
        {
            if(HDMIEDID_AUDIO_FMT_TYPE_MASK_VALUE(*pu1AudioDataBlock) == HDMIEDID_AUDIO_EAC3_FMT_TYPE)
            {
                break;
            }
            else
            {
                pu1AudioDataBlock += HDMIEDID_AUDIO_DATA_BLOCK_SIZE;
            }
        }
        if(u1i >= u1FormatNum)
        {
            u1AtmosBit = 0;
        }
        else
        {
            u1AtmosBit = HDMIEDID_AUDIO_ATMOS_BIT_MASK_VALUE(pu1AudioDataBlock[2]);
        }
    }
    else
    {
       u1AtmosBit = u1DrvEDIDGetAtmosEnable();
    }
    if(u1AtmosBit != u1DrvEDIDGetAtmosEnable())
    {
        vDrvEDIDSetAtmosEnable(u1AtmosBit);
        return TRUE;
    }
    return FALSE;
}

//retval: 0 for select EDID1, 1 for select EDID2
UINT8 u1DrvGetHdmiEdidPortSel(UINT8 u1Port)
{
    UINT8 u1EdidIdx = 0;
    EEPHDMIEDID_Format_Read(u1Port,&u1EdidIdx); //Currently we don't implement EDID select by each port
    if(u1EdidIdx != 1)
    {
        u1EdidIdx = 0;
    }
    return u1EdidIdx;
}

UINT8* pu1DrvLoadHdmiStandardEdid(void)
{
#ifdef CC_HDMI_2_0_HDCP_BIN
    vHDMI14EDIDReadFromEep(HDMIEDID_table);
#endif
    return HDMIEDID_table;
}

UINT8* pu1DrvLoadHdmiEnhancedEdid(void)
{
#ifdef CC_HDMI_2_0_HDCP_BIN
    vHDMI20EDIDReadFromEep(HDMI2EDID_table);
#endif
    return HDMI2EDID_table;
}

UINT8* pu1DrvLoadHdmi21Edid(void)
{
#ifdef CC_HDMI_2_0_HDCP_BIN
    vHDMI21EDIDReadFromEep(HDMI2EDID_table);
#endif
    return HDMI2EDID_table;
}


UINT8* pu1DrvGetEdidStorage(UINT8 u1Port)
{
    UINT8 u1EdidIndex = 0;

    if(u1Port <= HDMI_SWITCH_4)
    {
        EEPHDMIEDID_Format_Read(u1Port,&u1EdidIndex);
        if(HDMI2_EDID_TYPE_ENHANCE == u1EdidIndex) //Enhanced EDID
        {
            return pu1DrvLoadHdmiEnhancedEdid();
        }
        else if(HDMI2_EDID_TYPE_STANDARD == u1EdidIndex)
        {
            return pu1DrvLoadHdmiStandardEdid();
        }
        else
        {
            return pu1DrvLoadHdmi21Edid(u1EdidIndex);
        }
    }
    return HDMI2EDID_table;
}

void vReplaceHdmiEdidAtmosBit(UINT8* pu1Edid)
{
    UINT8 u1DataTmp = 0;
    UINT8* pu1EdidBlock1 = pu1Edid + 128;
    UINT8 u1AtmosEnable = u1DrvEDIDGetAtmosEnable();
    UINT8 u1EAC3DataBlockIndex = u1HDMIEDIDGetAudioDataBlockIndex(pu1EdidBlock1,HDMIEDID_AUDIO_EAC3_FMT_TYPE);
    if(!fgGetEdidData(pu1EdidBlock1,u1EAC3DataBlockIndex+2,&u1DataTmp))
    {
        return;
    }

    //Got the EAC3 data block
    if(u1AtmosEnable)
    {
        u1DataTmp |= HDMIEDID_AUDIO_ATMOS_BIT_MASK;
    }
    else
    {
        u1DataTmp &= (~HDMIEDID_AUDIO_ATMOS_BIT_MASK);
    }
    fgSetEdidData(pu1EdidBlock1,u1EAC3DataBlockIndex+2,u1DataTmp);

    pu1EdidBlock1[127] = u1HDMIEDIDCalCheckSum(pu1EdidBlock1);
}

UINT16 u2DrvGetEdidSize(UINT8 u1Port)
{
    return 256;
}

void vPostHdmiEdidProcess(UINT8* pu1Edid)
{
    vReplaceHdmiEdidAtmosBit(pu1Edid);
}

UINT8* pu1DrvLoadHdmiEdid(UINT8 u1Port)
{
    UINT8* pu1Edid = pu1DrvGetEdidStorage(u1Port);
    vPostHdmiEdidProcess(pu1Edid);
    return pu1Edid;
}


UINT8* pu1DrvLoadHdmiEdid1(void)
{
    UINT8* pu1HDMIEdid1 = pu1DrvLoadHdmiStandardEdid();
    vPostHdmiEdidProcess(pu1HDMIEdid1);

    return pu1HDMIEdid1;
}

UINT8* pu1DrvLoadHdmiEdid2(void)
{
    UINT8* pu1HDMIEdid2 = pu1DrvLoadHdmiEnhancedEdid();
    vPostHdmiEdidProcess(pu1HDMIEdid2);

    return pu1HDMIEdid2;
}

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

UINT8* pu1DrvGetMhlEdidTable(void)
{
    return (UINT8 *)u1MhlEdid_P0;
}
#endif//CC_HDMI_EDID_DISABLE

//---------------------------------------------------------------------------
// Not loader part
//---------------------------------------------------------------------------
#ifndef CC_MTK_LOADER
#endif

#endif //CC_S_PLATFORM
#endif // _EDID_CUSTOMIZATION_H_
