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

//----------------------------------------------------------------------------
// Constant definitions
//----------------------------------------------------------------------------
#include "x_typedef.h"
#include "x_pdwnc.h"
#include "sif_if.h"
#include "spi_comm_if.h"


//----------------------------------------------------------------------------
// Config
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// Constant definitions
//----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Macro definitions
//-----------------------------------------------------------------------------
#define T8032_HOLD_ENGINE() 0//(PDWNC_READ32(REG_RW_UP_CFG) & ENGINE_EN)
#define T8032_ALIVE() 0//  ((IO32ReadFldAlign(PDWNC_UP_CFG, FLD_T8032_RST) == 0) && (IO32ReadFldAlign(PDWNC_UP_CFG, FLD_VIR_EN) == 1))

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

/** PDWNC function table
 */
typedef struct {
    void (*pfnInit)(void);
    void (*pfnPowerDown)(UINT32, UINT32*);
	void (*pfnPowerResume)(void);
    void (*pfnReadWakeupReason)(UINT32*);
    void (*pfnWatchDogInit)(void);
    void (*pfnErrorHandleInit)(void);
    void (*pfnWriteErrorCode)(UINT8);
    void (*pfnReadErrorCode)(UINT8*);
    void (*pfnGetCurrentState)(UINT32*);
    void (*pfnDetermineNextState)(UINT32, UINT32, UINT32*, UINT32 *, UINT32 *);
    void (*pfnEnterNextState)(UINT32);
    INT32 (*pfnSet8032uPLedBlink)(UINT32);
    UINT32 (*pfnCustomRead)(UINT32, void *, UINT32);
    UINT32 (*pfnCustomWrite)(UINT32, void *, UINT32);
} PDWNC_FuncTbl;

typedef enum
{
    PDWNC_T8032_SET_NORMAL = 0,
    PDWNC_T8032_SET_STANDBY,
    PDWNC_T8032_SET_XDATA_ARM,
    PDWNC_T8032_SET_XDATA_T8032,
    PDWNC_T8032_SET_ENGINE_ARM,
    PDWNC_T8032_SET_ENGINE_T8032,
} E_PDWNC_T8032_SET_TYPE;

typedef enum
{
    BR_115200 = 0,
    BR_57600,
    BR_38400,
    BR_19200,
    BR_9600,
    BR_2400
} E_PDWNC_T8032_UART_PD_BAUDRATE;


//----------------------------------------------------------------------------
// Static variables
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// Public interface
//----------------------------------------------------------------------------
EXTERN PDWNC_FuncTbl* PDWNC_EXT_GetFunc(void);
EXTERN INT32 PDWNC_InitT8032(UPTR u4Addr, UINT32 u4Size);
EXTERN INT32 PDWNC_T8032Cmd(PDWNC_T8032_CMD_T* prCmd, PDWNC_T8032_RESPONSE_T* prResponse);
EXTERN INT32 PDWNC_ReadSwVersion(UINT32* pu4SwVersion);
EXTERN INT32 PDWNC_ReadT8032WakeupReason(UINT32* pu4WakReason , UINT32* pu4SubReason);
EXTERN INT32 PDWNC_SetLastTransactionFin(void);
EXTERN INT32 PDWNC_SetUartPDBaudrate(UINT8 u1baudrate);
EXTERN BOOL PDWNC_SetupFpWakeup(BOOL *pfgEnable);
EXTERN INT32 PDWNC_GpioEnable(INT32 i4Gpio, INT32 *pfgSet);
EXTERN INT32 PDWNC_GpioOutput(INT32 i4Gpio, INT32 *pfgSet);
EXTERN INT32 PDWNC_GpioInput(INT32 i4Gpio);
EXTERN INT32 PDWNC_GpioStatus(INT32 i4Gpio, INT32* pi4Pinmux, INT32* pi4Enable, INT32* pi4Output, INT32* pi4Input);
EXTERN INT32 PDWNC_ServoGpioRangeCheck(INT32 i4Gpio);
EXTERN UINT8 PDWNC_SetQueryRtcYear(const UINT8 *pu1Year);
EXTERN INT32 _PDWNC_SetT8032(UINT32 u4Set);
EXTERN UINT32 _PDWNC_ReadWakeupStatus(UINT32 u4Pdstat);
EXTERN void PDWNC_SetupPowerDown(void);
EXTERN void PDWNC_EnableIrLed(BOOL fgEnable);
EXTERN void PDWNC_InitServoADC(void);
EXTERN UINT8 PDWNC_SetQueryRtcYear(const UINT8 *pu1Year);
EXTERN INT32 PDWNC_GpioRangeCheck(INT32 i4Gpio);
EXTERN INT32 _PDWNC_GetT8302CECData(UINT32 u4XAddr, UINT32 u4Size, UINT8* pu1Data);
EXTERN INT32 _CopyToT8032_XDATA(UINT32 u4XAddr, UINT32 u4Size, UPTR u4RiscAddr);
EXTERN INT32 _CopyFromT8032_XDATA(UINT32 u4XAddr, UINT32 u4Size, UPTR u4RiscAddr);
EXTERN INT32 PDWNC_GpioSetIntExtParam(INT32 i4Gpio, UINT32 u4Arg);
EXTERN INT32 PDWNC_GpioGetIntExtParam(INT32 i4Gpio, UINT32 *pu4Arg);
EXTERN void PDWNC_CreateDCOnOffTestThread(void);

EXTERN void PDWNC_PwmSetPwmEnable(UINT32 u4Path, UINT32 u4Arg);
EXTERN UINT32 PDWNC_PwmSetPwm(UINT32 u4Path, UINT32 u4Enable,UINT32 u4Frequence, UINT32 u4DutyCycle);
EXTERN UINT32 PDWNC_PwmSetBreathLight(UINT32 u4Path, UINT32 u4Enable,UINT32 u4Cycle);
EXTERN INT32 PDWNC_SetupGpioWakeup(INT32 i4GpioNum, BOOL fgEnable, BOOL fgPolarity, BOOL fgStonly);
EXTERN INT32 PDWNC_GetWakeupGpioNum(UINT32 *u4GpioNum);


EXTERN void PDWNC_WdtIsrTestCase(UINT32 en);
EXTERN UINT32 PDWNC_IsWakeupFromSuspend(void);
EXTERN UINT32 PDWNC_SetWifiWowState (UINT32 u4WifiWowState);

#endif
