/* 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: cec_if.h,v $
 * $Revision$
 *
 *---------------------------------------------------------------------------*/
#ifndef _CEC_IF_H_
#define _CEC_IF_H_

#include "x_typedef.h"

// *********************************************************************
// Type definitions
// *********************************************************************
typedef struct
{
    UINT8 destination : 4;
    UINT8 initiator   : 4;
} CEC_HEADER_BLOCK;

typedef struct
{
    CEC_HEADER_BLOCK header;
    UINT8 opcode;
    UINT8 operand[16];
} CEC_FRAME_BLOCK;

typedef struct
{
    UINT8 size; // Actual frame block size.
    UINT8 sendidx;
    UINT8 reTXcnt;
    void* txtag;
    CEC_FRAME_BLOCK blocks;
} CEC_FRAME_DESCRIPTION;
typedef struct
{
    UINT8 tvLA1:4;
    UINT8 tvLA2:4;
}CEC_TV_LA_t;
#ifdef CC_FOR_POC_DEMO
typedef struct
{
    BOOL         fgActSrcReved;
    CEC_FRAME_DESCRIPTION eFrameDescription;
}CEC_FRAME_ACTSRCREVED;
#else
typedef struct
{
    BOOL         fgActSrcReved;
    UINT8        u1PhyAddr[2];
}CEC_FRAME_ACTSRCREVED;
#endif
#if defined(LG_CEC) || defined(CC_TCL_CEC)
typedef struct
{
    UINT8 ui1_txResult;
    CEC_FRAME_DESCRIPTION tFrame;
}CEC_TX_RESULT;
#endif

/* Notify function */
typedef void (*x_cec_drv_nfy_data_arrival) (CEC_FRAME_DESCRIPTION* frame);
typedef void (*x_cec_drv_nfy_tx_result) (UINT8 result,CEC_FRAME_DESCRIPTION *frame, void* txtag);
typedef void (*x_cec_drv_nfy_tx_header_result) (UINT8 result, CEC_FRAME_DESCRIPTION *frame, UINT8 u1Dstination);

//#define CECNFY5VSTATUS 0
#ifdef CECNFY5VSTATUS
typedef void (*x_cec_drv_nfy_5v_status) (UINT8 bSwitch, BOOL fgIs5VOn,void *arg);
#endif

// *********************************************************************
// Constant definitions
// *********************************************************************

// *********************************************************************
// Export API
// *********************************************************************
EXTERN void CEC_SetRxCallback(x_cec_drv_nfy_data_arrival nfyinfo,void *arg);
EXTERN void CEC_SetTxCallback(x_cec_drv_nfy_tx_result nfyinfo,void *arg);

#ifdef CECNFY5VSTATUS
EXTERN void CEC_Set5VCallback(x_cec_drv_nfy_5v_status nfyfp,void *arg);
EXTERN void _Cec_Notify5VStatus(UINT8 u1Port, UINT8 u15vStatus);
#endif

EXTERN void CEC_SetTxHeaderCallback(x_cec_drv_nfy_tx_header_result nfyfp,void *arg);
#if defined(SYS_ANDROID_TV_TIF_SUPPORT)
EXTERN void CEC_HALSetMWReady(UINT8 mwrdy_val);
#else
EXTERN void CEC_SetMWReady(void);
#endif
EXTERN void CEC_SetLogicAddress(UINT8 u1LogicalAddr);
EXTERN void CEC_ClrLogicAddress(void);
EXTERN void CEC_SendStandby(UINT8 u1Standby);
EXTERN void CEC_SetWakeUp(UINT8 u1WakeUp);
EXTERN void CEC_SendStandardCmd(UINT8 u1StandardCmd);
EXTERN void CEC_SetEnable(BOOL fgEnable);
EXTERN UINT8 CEC_GetLogicalAddr(void);
EXTERN void CEC_CheckActiveSource(CEC_FRAME_ACTSRCREVED *prActiveSrc);
EXTERN void CEC_Init(void);
EXTERN void CEC_Mainloop(void);
EXTERN void CEC_SetSysVtrl(UINT8 u1Onoff);
EXTERN void CECSetDbgLvl(UINT8 u1dbglvl);
EXTERN UINT8 u1CecDbgLvl;

#ifdef CECNFY5VSTATUS
EXTERN void _Cec_Notify5VStatus(UINT8 u1Port, UINT8 u15vStatus);
#endif
EXTERN UINT8 CEC_EnqueueTx(CEC_FRAME_DESCRIPTION* frame);
EXTERN void _CEC_TestCmd(UINT8 cmd);
#ifdef CC_TCL_CEC
EXTERN UINT8 CEC_RecordMsgRxCnt(void);
EXTERN UINT8 CEC_RecordMsgTxCnt(void);
#endif
//cec Arc control
#if defined (CC_HDMI_ARC_SPDIF_CTRL)|| defined (CC_HDMI_ARC_SPDIF_CTRL_89)
EXTERN void CEC_SetArcEnable(BOOL fgEnable);
EXTERN void CEC_LogArcEnable(void);
#endif

extern void vHDMISetARCSwitch(UINT8 u1Port);
#ifdef SYS_ANDROID_TV_TIF_SUPPORT
EXTERN void CEC_SetArcSwitch(UINT8 u1Port);
#endif

#if defined(LG_CEC) || defined(CC_TCL_CEC)
EXTERN void CEC_ReadRxCommand(CEC_FRAME_DESCRIPTION *pt_frame);
EXTERN void CEC_ReadTxResult(CEC_TX_RESULT *pt_txResult);
EXTERN UINT16 CEC_ReadResponse(void);
#endif

#ifdef CC_FOR_POC_DEMO
typedef void (*x_philips_cec_drv_nfy_5v_status) (UINT8 u1HdmiChangeType,UINT8 bSwitch, BOOL fgIs5VOn);
extern void CEC_SetPhilips5VCallback(x_philips_cec_drv_nfy_5v_status nfyfp);
#endif
extern void vHDMIGetCECVendorID(UINT32 *pID);

#endif /* _CEC_IF_H_ */

