/* 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 _DRV_MUTE_H_
#define _DRV_MUTE_H_

#include "typedef.h"

#define FOREVER_MUTE            0xFFFFFFFF

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


typedef enum
{
    // Notice :::::::
    // Pleae update static CHAR _aszMuteModuleStr[MUTE_MODULE_MAX][MODULE_STR_LEN] when you add new mute module. 
    MUTE_MODULE_API_FORCE = 0,
    MUTE_MODULE_BLUE,
    MUTE_MODULE_BLACK,
    MUTE_MODULE_MDDI01,
    MUTE_MODULE_SCPOS_PLA_EN,
    MUTE_MODULE_SCPOS_DRAM,
    MUTE_MODULE_SCPOS_PATTERN,
    MUTE_MODULE_SCPOS_FIFO,
    MUTE_MODULE_SCPOS_DISP_TUNE,
    MUTE_MODULE_SCPOS_PRE_DOWN,
    MUTE_MODULE_REGEN,
    MUTE_MODULE_SCPOS_MISC,
    MUTE_MODULE_SCPOS_WA,
    MUTE_MODULE_SCPOS_TV3D,
    MUTE_MODULE_MODECHG,
    MUTE_MODULE_SRM,
    MUTE_MODULE_DTV,
    MUTE_MODULE_B2R,
    MUTE_MODULE_HDMI,
    MUTE_MODULE_MEMORY_TEST,
    MUTE_MODULE_PPCLOCK,
    MUTE_MODULE_NR,
    MUTE_MODULE_AUTOSEARH,
    MUTE_MODULE_MW_DISP_FMT,
    MUTE_MODULE_MJC,
    MUTE_MODULE_MJC_POST,
    MUTE_MODULE_TDC,
    MUTE_MODULE_FRC,
    MUTE_MODULE_TNR,
    MUTE_MODULE_SCALER_RESUME,
    MUTE_MODULE_POWER_SEQUENCE,
    MUTE_MODULE_PRE_MUTE,
    MUTE_MODULE_B2R_PENDING,
#ifdef CC_SUPPORT_DOLBY_VISION
    MUTE_MODULE_DOLBY,
#endif
    MUTE_MODULE_MAX
} MUTE_MODULE_ID;

typedef enum
{
    // Don't forget to update "_aszMuteInvalidStr"
    MUTE_INVALID_ON_NO_SIG = 0,
    MUTE_INVALID_ATV_CHG_CH_FREEZE,
    MUTE_INVALID_AUTO_SEARCH,
    MUTE_INVALID_CLI_FORCE,
    MUTE_INVALID_MAX
} MUTE_INVALID_MASK_ID;

typedef enum
{
    EVENT_VIDEO_MUTE_CHANGE = 0,
    EVENT_VIDEO_UNMUTE,
} MUTE_NOTIFY_TYPE;

typedef struct _strucVideoMuteInfo
{
    UINT32  u4InvalidMask;           // Valid module
	UINT32	u4Delay;	        // Unmute delay counter
	UINT32	u4InfoAddr;	        // Addr of debug information 
} VIDEO_MUTE_INFO;

typedef struct _strctVideoMuteCmd
{
	MUTE_MODULE_ID eModuleId;   // Mute module ID
	UINT8	u1Path;		        // Video path
	UPTR  u4ModuleStrAddr;    // Module name
	VIDEO_MUTE_INFO rMuteInfo;
} VIDEO_MUTE_CMD;

typedef struct _strctVideoMute
{
    MUTE_NOTIFY_TYPE eNotifyID;
    UINT32 u4Path;
    UINT32 u4Tag;
} VIDEO_MUTE_NOTIFY_MSG;

/// Callbalck function when the mute state is change
typedef VOID  (*MUTE_CALLBACK)(UINT8 u1Path, UINT8 u1Tag);

typedef struct _strctMuteCallBack
{
    MUTE_CALLBACK pfnCallBack;
    UINT32 u4NotifyTag;
    VOID * prNext;
} VIDEO_MUTE_CALLBACK_FUNC;

//-----------------------------------------------------------------------------
//function Declare
//-----------------------------------------------------------------------------

/**
 * @brief vDrvDumpVideoMuteModule
 * Dump delay counter of all mute modules
 * @param  u4Path
 * @param  u4ForceDumpInfo
 * @return void
 */
EXTERN VOID vDrvDumpVideoMuteModule(UINT32 u4Path, UINT32 u4ForceDumpInfo);

/**
 * @brief vDrvDumpVideoMuteInfo
 * Dump mute information of all modules
 * @param  u4Path
 * @return void
 */
EXTERN VOID vDrvDumpVideoMuteInfo(UINT32 u4Path);

/**
 * @brief _vDrvSendMuteCmd
 * Set mute/unmute information of the selected module
 * @param  prDrvMuteCmd
 * @return void
 */
EXTERN VOID _vDrvSendMuteCmd(VIDEO_MUTE_CMD *prDrvMuteCmd);

/**
 * @brief _u4DrvVideoGetMute
 * Get mute/unmute status of the selected videp path
 * @param  u4Path
 * @return Mute or not
 */
EXTERN UINT32 _u4DrvVideoGetMute(UINT32 u4Path);

UINT32 u4DrvGfxOutputMute(void);

UINT32 u4DrvVideoOutputMute(void);

/**
 * @brief _vDrvVideoGetMuteState
 * Set mute/unmute information of the selected module
 * @param  prDrvMuteCmd
 * @return void
 */
EXTERN VOID _vDrvVideoGetMuteStatus(VIDEO_MUTE_CMD *prDrvMuteCmd);

/**
 * @brief _vDrvVideoGetMuteStatus
 * Get the mute dealy of the selected module
 * @param  u4Path,eModule
 * @return UINT32
 */
EXTERN UINT32 _vDrvVideoGetMuteDelay(UINT32 u4Path, MUTE_MODULE_ID eModule);

/**
 * @brief _vDrvVideoSetMute
 * Set mute command of the selected module
 * @param  eModuel, u4Path, u4UnMuteDelay, bReplaceByLongerDelay
 * @return void
 */
EXTERN VOID _vDrvVideoSetMute(MUTE_MODULE_ID eModule, UINT32 u4Path,
                              UINT32 u4UnMuteDelay, BOOL bReplaceByLongerDelay);

/**
 * @brief _vDrvVideoSetMuteISR
 * Set mute command of the selected module,with take effect immediately
 * @param  eModuel, u4Path, u4UnMuteDelay, bReplaceByLongerDelay
 * @return void
 */
EXTERN VOID _vDrvVideoSetMuteISR(MUTE_MODULE_ID eModule, UINT32 u4Path,
                              UINT32 u4UnMuteDelay, BOOL bReplaceByLongerDelay);


/**
 * @brief _vDrvVideoSetMuteInvalidFlag
 * Set mute command of the selected module to be invalid
 * @param  eModuel, u4Path, bInvalid , eInvalidID
 * @return void
 */
EXTERN VOID _vDrvVideoSetMuteInvalidFlag(MUTE_MODULE_ID eModule, 
                                         UINT32 u4Path, BOOL bInvalid, MUTE_INVALID_MASK_ID eInvalidID);
/**
 * @brief _vDrvVideoForceUnMute
 * Set Force Mute Off for Main and PIP Channel
 * @param  u4Path
 * @param  bOnOff
 * @return void
 */
EXTERN VOID _vDrvVideoForceUnMute(UINT32 u4Path, BOOL bOnOff);

/**
 * @brief vDrvVideoHandleUnMute
 * Handle unmute delay counter and mute on/off for Main/PIP channel
 * @param  none
 * @return void
 */
EXTERN VOID vDrvVideoHandleUnMute(VOID);

/**
 * @brief _vDrvVideoRegisterMuteNotify
 * Register the notify function 
 * @param   prNotifyFunc, eNotifyType, u4Tag
 * @return  0: success
            0xFFFFFFFF : fail
 */
EXTERN UINT32 _vDrvVideoRegisterMuteNotify(MUTE_CALLBACK prNotifyFunc, 
                                    MUTE_NOTIFY_TYPE eNotifyType, UINT32 u4Tag);

/**
 * @brief vDrvSetForceUnmute
 * set force mute 
 * @param   path, type, enable
 * @return  void
 */
EXTERN VOID vDrvSetForceUmute(INT32 u4Path, UINT8 u1MuteType, BOOL bEnable);
#ifdef CC_MT5398
void vDrvMJCMuteOnOff(UINT8 bOnOff);
#endif
UINT32 fgDrvVideoMuteIsVsyncLatch(void);
void vDrvVideoMuteVsyncLatch(UINT32 fgOnOff);
void vDrvVideoMuteOnOff(UINT32 u4VdpId, UINT32 fgOnOff, BOOL bVsyncMode);
void vDrvVideoMuteColor(UINT32 u4VdpId, UINT32 u4MuteColor);
void vDrvVideoMuteValid(UINT32 u4VdpId, UINT32 u4Module, UINT32 fgOnOff);
#endif /* _DRV_MUTE_H */

#ifdef CC_SUPPORT_STR
VOID vDrvVideoMuteResume(VOID);
VOID vDrvVideoMuteSuspend(VOID);
#endif

void vDrvUnlockMuteSem(void);

UINT32 u4DrvGetVideoSpecialMute(void);
void vDrvSetPSCMute(UINT8 bOnOff);
void u4DrvSetVideoSpecialMute(UINT32 bOnOff);
UINT32 u4DrvGetMJCPscMute(void);
void u4DrvSetMJCPscMute(UINT32 bOnOff);

