/* 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: purplearrow.jhang $
 * $Date: 2015/07/08 $
 * $RCSfile: ostg_if.h,v $
 * $Revision: #4 $
 *
 *---------------------------------------------------------------------------*/

/** @file ostg_if.h
 *  NPTV Output Stage interface for LVDS and Panel Setting
 */

#ifndef _OSTG_IF_H_
#define _OSTG_IF_H_

#include "x_typedef.h"
#include "sv_const.h"
#include "api_backlt.h"
#include "drv_tcon.h"

#define CC_SUPPORT_SCANPWM_FOR_SPI_INPUT
//-----------------------------------------------------------------------------
// Constant definitions
//-----------------------------------------------------------------------------
#define PANEL_OFF 0
#define PANEL_ON 1
// for backward compatible
//#define PANEL_DIMMER(bDimLevel) vApiSetPanelBright(bDimLevel)

///-----------------------------------------------------------------------------
/// Public functions
///-----------------------------------------------------------------------------

/** Set LVDS driving current
 *  @param bDriving: 0~15
 *  @return
 */
EXTERN void vApiLVDSSetDriving(UINT8 bDriving);

/**
 * @brief Set Panel output frame rate
 * @param wFrameRate
 * @ return
 */
EXTERN void vApiLCDSetFrameRate(UINT16 wFrameRate);

/**
 * Get Panel output frame rate
 * @param void
 * @ return output frame rate
 */
EXTERN UINT8  bApiLCDGetFrameRate(void);

#define DRV_TURN_ON_BACKLT  (vDrvTurnOnBacklt)
#define DRV_TURN_OFF_BACKLT (vDrvTurnOffBacklt)

void vDrvGpioSet(INT32 gpio, INT32 value);
// backlight power-------------------------------------------------------------
void vDrvTurnOnBacklt(void);
void vDrvTurnOffBacklt(void);
// PDP VsON------------------------------------------------------------------
void vDrvTurnOnPDPVs(void);
void vDrvTurnOffPDPVs(void);

extern void vApiTCONPower(VIDEO_TCON_POWER_SEQ_T eTconPowSeq, BOOL fgEnable);
extern void vApiPanelPowerSequence(BOOL bPMode);
#ifdef CC_S_PLATFORM
extern void vApiPanelPowerSequenceEx(BOOL bPMode);
#endif
#ifdef CC_SUPPORT_STR
extern void vDrvLVDSSuspend(void);
extern void vDrvLVDSResume(void);
#ifdef CC_S_PLATFORM
extern void ostg_set_fgPanelPowerState(BOOL onoff);
extern BOOL ostg_get_fgPanelPowerState(void);
#endif
#endif
extern void BeforeOutputFrameRateChange(UINT32 u4FrameRate);
extern void AfterOutputFrameRateChange(void);

extern UINT32 BACKLT_GetCurrentPanelBright(void);
extern void   BACKLT_SetDimming(UINT32 u4Frequency, UINT32 u4Dimming);
extern UINT32 BACKLT_GetDimmingFrequency(void);

extern void vApiSetPanelBright(UINT8 bBrightLevel);
extern void vApiBackltONOFF(BOOL bPMode);

void vApiSetDimming(UINT16 u2Freq, UINT16 u2Duty);
void vApiSetBooster(UINT16 wLevel);

extern UINT8 bIsPanelOn(void); 

#ifdef CC_SCPOS_3DTV_SUPPORT
EXTERN void vApiSetScanningPWM(UINT16 u2HTotal, UINT16 u2VTotal, UINT32 u4Start, UINT32 u4High);
#endif

#ifdef CC_FAST_INIT
extern void ostg_set_fgPanelOn(BOOL onoff);
#endif

extern UINT32 LDR_PmxDisplay(UINT32 u4Background) ;
extern void LDR_PmxDisplayHWInit(void);
extern void vDrvOstgHWInit_LOADER(void);

#ifdef CC_SUPPORT_SCANPWM_FOR_SPI_INPUT
#define SPI_BL_VSYNC SrcPWM2
#define SPI_BL_HSYNC SrcPWM1
#define SPI_CS0 SrcPWM3
#define SPI_CS1 SrcPWM4
#define SPI_CS2 SrcPWM5
#define SPI_CS3 SrcPWM6
#define SPI_EMIT SrcPWM7
#define SPI_ChangeBase SrcPWM8

extern void vDrvSetSCANPWMforSPIModeChange(void);
extern void vDrvSetSCANPWMforSPIOnOff(BOOL);
extern void vDrvSetSCANPWMforSPIInit(void);
extern void vDrvSetSCANPWMforSPISync(UINT8 IsVsync,UINT8 u1Mode);
extern void vDrvSetSCANPWMforSPICS(UINT8 u1Mode, UINT8 u1Duty);
extern void vDrvSetSCANPWMforSPIEmit(UINT8 u1Delay, UINT8 u1Duty);
extern void vDrvSetSCANPWMforSPIChangeBase(UINT8 u1Mode);
extern void vDrvSetSCANPWMforSPI(UINT8 u1PwmPort,UINT32 u4Freq,UINT16 u2Duty,UINT16 u2Phase);
#endif

#endif // _OSTG_IF_H_
 
