/* 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.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 *
 * $Author$
 * $Date$
 * $RCSfile: drv_tcon.h,v $
 * $Revision$
 *
 *---------------------------------------------------------------------------*/

#ifndef _DRV_TCON_H_
#define _DRV_TCON_H_

#define HISENSE_IPS_2010_PANEL 0

enum 
{
  TCON_TP_OFF,
  TCON_TP_R,
  TCON_TP_G,
  TCON_TP_B,
  TCON_TP_BLACK,
  TCON_TP_WHITE,
  TCON_TP_COLORRAMP,
  TCON_TP_MOVING,
  TCON_TP_AUTO,
  TCON_TP_2SEC,
  TCON_TP_4SEC,
  TCON_TP_8SEC,
  TCON_TP_MAX,
};

typedef enum
{
    VIDEO_TCON_GST,		/**< refer to panel cas */
    VIDEO_TCON_MCLK,	/**< refer to panel cas */
    VIDEO_TCON_GCLK,	/**< refer to panel cas */
    VIDEO_TCON_EO,		/**< refer to panel cas */
    VIDEO_TCON_VCOM_DYN,/**< refer to panel cas */
    VIDEO_TCON_EPISIGNAL,/**< refer to panel cas */
    VIDEO_TCON_ALL,/**< refer to panel cas */

    VIDEO_TCON_POW_SEQ_NUMS
} VIDEO_TCON_POWER_SEQ_T;

typedef enum
{
    EPIV13FHD60_32,       
    EPIV13FHD60_42,       
    EPIV13FHD60_47,
    EPIV13FHD60_55,
    EPIV13FHD120_42,
    EPIV13FHD120_47,
    EPIV13FHD120_55,
    EPIV12FHD60_47,       // for debug with V12 panel
    EPIV12FHD120_47,     // for debug with V12 panel

} VIDEO_TCON_TABLE_T;


struct sTCONREGTABLE {
    UINT32 u4Addr;
	UINT32 u4Val;
	UINT32 u4Msk;
};

typedef enum
{
    VIDEO_TCON_MINI_0,   /**< refer to panel cas */
    VIDEO_TCON_MINI_1,   /**< refer to panel cas */
    VIDEO_TCON_MINI_2,   /**< refer to panel cas */
    VIDEO_TCON_MINI_3,   /**< refer to panel cas */
    VIDEO_TCON_MINI_4,   /**< refer to panel cas */
    VIDEO_TCON_MINI_5,   /**< refer to panel cas */
    VIDEO_TCON_MINI_6,   /**< refer to panel cas */
    VIDEO_TCON_MINI_7,   /**< refer to panel cas */
    VIDEO_TCON_MINI_8,   /**< refer to panel cas */
    VIDEO_TCON_MINI_9,   /**< refer to panel cas */
    VIDEO_TCON_MINI_A,   /**< refer to panel cas */
    VIDEO_TCON_MINI_B,   /**< refer to panel cas */
    VIDEO_TCON_MINI_C,   /**< refer to panel cas */
    VIDEO_TCON_MINI_D,   /**< refer to panel cas */
    VIDEO_TCON_MINI_E,   /**< refer to panel cas */
    VIDEO_TCON_MINI_F,   /**< refer to panel cas */
    VIDEO_TCON_MINISIGNAL,  /**< refer to panel cas */
    VIDEO_TCON_MINI_ALL, /**< refer to panel cas */
    
    VIDEO_TCON_MINI_POW_SEQ_NUMS
}VIDEO_TCON_MINI_POWER_SEQ_T;

// flash tcon
#define FLASH_TCON_SIZE (64*1024) //Total Flash AQ size on NAND Flash partition.
#define FLASH_TCON_BUF_SIZE (1024)

void vTconRegWrite(UINT32 u4addr, UINT32 val);
UINT32 u4TconRegRead(UINT32 u4addr);


//TCON
UINT8 u1DrvTconInit(void);
void u1DrvTcon_Enable(BOOL fgOnOff);
UINT8 u1DrvTconIsReady(void);
void vDrvTCONSel(VIDEO_TCON_TABLE_T eTconTableSel);

//TCON Customization
UINT8 u1TconCustTgInit(void);
void vDrvTCONCustSel(VIDEO_TCON_TABLE_T eTconTableSel);

UINT8 u1TconCustGammaInit(void);
UINT8  u1TconCustGammaFlashing(void);

UINT8 u1TconCustDPMCtrlEN1(UINT8 val);
UINT8 u1TconCustDPMCtrlEN2(UINT8 val);

// For Debugging
UINT8 u1DrvTconTP(UINT8 val);
//UINT8 u1DrvTconRegDump(void);
//UINT8 u1DrvTconRegDiff(void);

//Error Handle
void vErrorHandleSetByTiming(void);
void vErrorHandleInit(void);
void vErrorHandleStatus(void);
void vScEhSta(void);
void u1ErrorHandleFixEnable(UINT8 val);
void u1ErrorHandleMuteEnable(UINT8 val);
void vErrorHandleSetByPanel(void);
void vDrvMLVDSPatternGen(UINT8 u1OnOff);
void u1ErrorHandlingSourceSet(UINT8 val);
UINT8 u1ErrorHandlingSourceGet(void);
void vVByOneOsdARGBMap_SM0ToInhouse(void);

void vDrvTCONISRSetLineCounter(UINT32 u4VFp, UINT32 u4VActive, UINT32 u4VBp);
void vDrvTCONTimingGenFrameCounterRst(void);
void vDrvTCONIntrEn(void);
void vDrvTCONIntrDisable(void);
void vDrvTCONIntrClr(void);
BOOL fgIsTCONIntrEn(void);
void vDrvTCONDisableBIMInt(void);
void vDrvTCONEnableBIMInt(void);
BOOL fgIsTCONIntrInit(void);
void vDrvTCONInitISR(void);
#ifndef CC_MTK_LOADER
void vDrvTCONRegisterISR(void);
#endif

// flash tcon
#ifdef CC_SUPPORT_FLASH_TCON
INT32 i4FlashTconRead(UINT16 u2Offset, UINT8 *u1Data, UINT32 u4Length);
void vFlashTconWrite(UINT16 u2Offset, UINT8 *u1Data, UINT32 u4size);
void vFlashTconInit(void);
void vFlashTconWriteDefault(void);
void vFlashTconSave(void);
struct sTCONREGTABLE * pTconCustTgGet(UINT32 *u4Length);
#endif  /*#ifdef CC_SUPPORT_FLASH_TCON*/
#endif

void _vDrvTconSetPinMux(void);
void vDrvTCLKPLLRst(void);
