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


#ifndef _TVE_CTRL_H_
#define _TVE_CTRL_H_

#include "x_typedef.h"
#include "u_common.h"

/* TVE OUT Config */
enum
{
	SV_TVE_NA,
	SV_TVE_DAC_BYPASS_CVBS,		
	SV_TVE_DAC_BYPASS_DEMOD,
	SV_TVE_DAC_PIP,
	SV_TVE_DAC_VIDEO_IN, // Video In
	SV_TVE_HW_BYPASS, // Only for TV SCART
	SV_TVE_D2S_BYPASS, // Only for Monitor SCART
#ifdef CC_MT5363	
	SV_TVE_DAC_BYPASS_SIF,
#endif
	SV_TVE_MAX
};

/* TVE Src Type */
enum
{
	SV_TVE_SRC_ORI,
	SV_TVE_SRC_CVBS0,
	SV_TVE_SRC_CVBS1,
	SV_TVE_SRC_PREV,	
	SV_TVE_SRC_MAX
};

/* TVE Video Status Notify Type */
enum
{	
	SV_TVE_NOTIFY_VIDEO_NO_SIGNAL,
	SV_TVE_NOTIFY_VIDEO_STABLE_SIGNAL,		
	SV_TVE_NOTIFY_VIDEO_MODE_CHANGE,
	SV_TVE_NOTIFY_VIDEO_UNMUTE,
	SV_TVE_NOTIFY_MAX
};

/* Tuner Type */
enum
{
	SV_TVE_TUNER_ATV_DEFAULT,
	SV_TVE_TUNER_ATV,
	SV_TVE_TUNER_DTV,
	SV_TVE_TUNER_MAX,
        SV_TVE_TUNER_LAST_TYPE = SV_TVE_TUNER_MAX
};

/* Scart Type */
enum
{
	SV_TVE_SCART_DAC,
	SV_TVE_SCART_HW,
	SV_TVE_SCART_D2S,
	SV_TVE_SCART_MAX
};

/* Scart Out ID */
enum
{
	SV_TVE_SCART_OUT_1,
	SV_TVE_SCART_OUT_2,
	SV_TVE_SCART_OUT_MAX
};

/* Scart Out Fmt */
enum
{
	SV_TVE_OFMT_PAL,
	SV_TVE_OFMT_NTSC,
	SV_TVE_OFMT_MAX,
	SV_TVE_OFMT_NONE = SV_TVE_OFMT_MAX
};

/* SCART Src type */
#define TVE_SCART_DECODER 7

typedef struct {
	UINT8  type;
	UINT8  src;
	UINT8  reset_src_change;		
}  rtve_out_t;

typedef struct {
	rtve_out_t tve_out1;
	rtve_out_t tve_out2;	
       UINT8 tve_out_fmt_576i;	
#ifdef CC_SUPPORT_TVE_CTRL_BY_DRIVER_SLT
       UINT8 remap_msrc;
#endif	
}  rtve_config_t;

typedef struct TveUsage_s
{
    UINT8    TveIsUsedBy : 4;
    UINT8    TveReferenceCnt : 4;
} TveUsage_t;

#define TVE_DAC_MUTE_MASK_MW  (1)
#define TVE_DAC_MUTE_MASK_DRV (1<<1)

#define TVE_BYP_EXT_PATH   (1)
#define TVE_BYP_AVMUX_PATH (2)
#define TVE_BYP_PIP_PATH   (3)

#define TVE_BYP_EXT_MUX_PATH (0x80)

/******************************************************************************
* TVE CTRL API
******************************************************************************/
 void vApiTVECtrlEnable(UINT8 bEnable);
 UINT8 vApiTVEIsPIPEnable(void);
void vApiTVEPreCtrl(UINT8 bPath, UINT8 *bSrc,UINT8 bMainSrcOld,UINT8 bSubSrcOld);
void vApiTVEPostCtrl(UINT8 bSrc);
void vApiTVEVideoStatusNotify(UINT8 bPath, UINT8 bMode);
void vApiTVESetDacMuteMask(UINT8 u1DacId, UINT8 u1Mask, UINT8 u1OnOff);
UINT8 bApiTVEGetBypPath(UINT8 u1DacId);
void vApiTVESetTvScartOutCtrl(UINT8 u1SrcType, rtve_config_t *tTveConfig, void* pv_extra_arg);
void vApiTVESetMonitorScartOutCtrl(UINT8 u1SrcType, rtve_config_t *tTveConfig, void* pv_extra_arg, void* pv_extra_arg2);
void vApiTVESetScartOutCtrl(UINT8 u1Scart_id, UINT8 *u1SrcType, void* pv_extra_arg);
void vApiTVESetOutputFormat(UINT32 u4fmt);
void vApiTVEQueryStatus(void);

/* customization API */
extern void vApiTVEOutPathSelect(UINT8 out_id, UINT8 out_type);
extern void vApiTVEGetConfig(UINT8 u1SrcType, UINT8* pu1Type);
#endif /* _TVE_CTRL_H_ */

