/* 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: brianpc.huang $
 * $Date: 2015/05/29 $
 * $RCSfile: drv_od.h,v $
 * $Revision: #1 $
 *
 *---------------------------------------------------------------------------*/

#ifndef _DRV_OD_H_
#define _DRV_OD_H_

#define OD_FW_WA3   1     //OD reset when mode change
//#define OD_EXT_FP     0     //OD use external frame protect
#define OD_TABLE_CONFIG OD_TABLE_17 // OD table size
#define OD_DMA_SIZE 6000
#define LOCAL_OD_TBL_SIZE 976     //61*16*20
#define LOCAL_OD_DMA_SIZE (LOCAL_OD_TBL_SIZE*20)

#define OD_TBL_S_DIM	17
#define OD_TBL_M_DIM	33
#define OD_TBL_L_DIM	41
#define FB_TBL_DIM	    17
#define PCID_TBL_DIM	17

#define OD_TBL_S_SIZE	(OD_TBL_S_DIM * OD_TBL_S_DIM)
#define OD_TBL_M_SIZE	(OD_TBL_M_DIM * OD_TBL_M_DIM)
#define OD_TBL_L_SIZE	(OD_TBL_L_DIM * OD_TBL_L_DIM)
#define FB_TBL_SIZE	    (FB_TBL_DIM * FB_TBL_DIM)
#define PCID_TBL_SIZE	(PCID_TBL_DIM * PCID_TBL_DIM)

#define OD_ONOFF        0x1
#define FB_ONOFF        0x2
#define PCID_ONOFF     0x4

extern UINT8 OD_Table[];
extern UINT8 FB_Table[FB_TBL_SIZE];
extern UINT8 PCID_Table[PCID_TBL_SIZE];


typedef struct
{
    UINT8 u1OD_ON;
    UINT8 u1FB_ON;
    UINT8 u1PCID_ON;
    UINT8 u1ODConfig;
    UINT8 u1ODTblSizeMode;
    UINT8 u1ODFlashPQEnable;
    UINT8 u1ODCurrentONOFF;
} OD_PARAM_T;

enum 
{
    OD_RED, 
    OD_GREEN, 
    OD_BLUE, 
    OD_ALL
};

enum 
{
    OD_TABLE_17,
    OD_TABLE_33,
    OD_TABLE_41_MODE1,
    OD_TABLE_41_MODE2,
    FB_TABLE_17,
    PCID_TABLE_17
};

enum 
{
    OD_DMA_SIZE_41,
    OD_DMA_SIZE_33,
    OD_DMA_SIZE_17,
};

enum 
{
    OD_DMA_READY,
    OD_DMA_WRITE,
    OD_DMA_WRITE_DONE,
};


extern OD_PARAM_T _ODParam;

void vDrvODOnOff(UINT8 u1OnOff);
void vDrvPCIDOnOff(UINT8 u1OnOff);
void vDrvFBOnOff(UINT8 u1OnOff);
void vDrvODBypass(UINT8 u1OnOff);
void vDrvODMode(UINT8 u1Mode);
void vDrvODSetPatternGen(UINT8 u1OnOff, UINT8 u1Type);
void vDrvODReset(void);
void vDrvODWriteTable(UINT8 TableSel, UINT8 ColorSel, UINT8* pTable);
UINT8 u1DrvODReadTable(UINT8 TableSel, UINT8 ColorSel, UINT8* pTable);
void vDrvODStressTest(UINT32 u4Mode, UINT32 u4Num, UINT32 u4Table, UINT32 u4LogCnt, UINT32 u4Delay);
void vDrvODDramOverflowReset(void);
UINT32 u4DrvODDramOverflow(void);
void vDrvODMloop(void);
void vDrvODInit(void);
void vDrvODSuspend(void);
void vDrvODResume(void);
void vDrvODCheckEnable(void);
void vDrvODQueryStatus(void);
void OD_OnOutputVSync(void);
void vDrvODLoadODTable(void);
void vDrvODLoadFBTable(void);
void vDrvODLoadPCIDTable(void);
void vDrvODSetTable(void);
void vDrvODSetDMA(UINT8 TableSel,UINT8* pTable, UINT32 u4Size);
void vDrvSetLocalODTbl(UINT8 u1Region , UINT8 u1TableIdx);
void vDrvOdDumpInit(void);
void vDrvOdDumpStart(void);
void vDrvOdDumpEnd(void);

#endif
