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

#include "x_pdwnc.h"
#include "drv_pwm.h"
#ifndef CC_UBOOT
#include "CustomCtrl.h"
#else
#ifdef TARGET_SPEC_DRV_CUST_CUSTOMIZED_HDR_FILE
#include TARGET_SPEC_DRV_CUST_CUSTOMIZED_HDR_FILE
#endif
#endif
#ifdef CC_SAKURA_LED_ILLUMINATION
#include "pdwnc_if.h"
#endif
//---------------------------------------------------------------------------
// Customer function definitions
//---------------------------------------------------------------------------
#ifndef CC_UBOOT
#define GPIO_POWER_ON_FUNC                      (GPIO_CustomPowerOnFunc)
#define GPIO_POWER_OFF_FUNC                     (GPIO_CustomPowerOffFunc)
#define GPIO_LED_CTRL_FUNC                      (GPIO_CustomLedCtrlFunc)
#define GPIO_POWER_OFF_SELFDIAG_SHUTDOWN_FUNC   (CustomPowerOffSelfDiagShutDown)
#else
#define GPIO_POWER_ON_FUNC                      (NULL)
#define GPIO_POWER_OFF_FUNC                     (NULL)
#define GPIO_LED_CTRL_FUNC                      (NULL)
#define LOADER_ENV_INIT_FUNC                    (NULL)
#define GPIO_POWER_OFF_SELFDIAG_SHUTDOWN_FUNC   (NULL)
#endif

#ifdef CC_MTK_LOADER
//#define LOADER_UPGRADE_VER_CMP_FUNC             (NULL)
#ifndef CC_UBOOT
#define LOADER_USB_UPGRADE_CHECK_FUNC           (IsCustomLdrSkipUpgradeHE)
#define LOADER_LOGO_CHECK_FUNC                  (_LdrCustomLogoDisplay)
#define LOADER_UPGRADE_DLM_CB_FUNC              (_LdrUpgradeDlmCbFunc)
#define LOADER_UPGRADE_DLM_GET_TAG_VER_CB_FUNC  (_LdrUpgradeDlmGetTagVerCbFunc)
#define LOADER_UPGRADE_DLM_CMP_TAG_VER_CB_FUNC  (_LdrUpgradeDlmCmpTagVerCbFunc)
#define LOADER_IMG_DECOMPRESS_FUNC              (_LdrCustomImgDecompression)
#else
#define LOADER_USB_UPGRADE_CHECK_FUNC           (NULL)
#define LOADER_LOGO_CHECK_FUNC                  (NULL)
#define LOADER_UPGRADE_DLM_CB_FUNC              (NULL)
#define LOADER_UPGRADE_DLM_GET_TAG_VER_CB_FUNC  (NULL)
#define LOADER_UPGRADE_DLM_CMP_TAG_VER_CB_FUNC  (NULL)
#define LOADER_IMG_DECOMPRESS_FUNC              (NULL)
#endif
//#define LOADER_UPGRADE_BREAK_HANDLE_FUNC        (_LdrUpgradeBreakFunc)
#else
#define LOGO_NOTIFY_FUNC                        (CustomLogoNotifyFunc)
#define CUSTOMER_LOGO_DISPLAY_FUNC              (CustomDisplayLogo)
#ifdef CC_PAA_GET_COUNTRY_SUPPORT
#ifndef CC_UBOOT
#define APP_COUNTRY_SET_FUCTION                 (CustomSetAPPCountry)
#define APP_COUNTRY_GET_FUCTION                 (CustomGetAPPCountry)
#endif
#endif

#endif /* CC_MTK_LOADER */

#ifdef SONY_LOADER_POWER_SEQ
#ifndef CC_UBOOT
#define CUSTOMER_POWER_ON_SEQUENCE              (CustomPowerOnSequence)
#define CUSTOMER_POWER_OFF_SEQUENCE             (CustomPowerOffSequence)
#define CHECK_FRC_INIT_STATUS                   ((DRVCUST_Get_FRC_Type() == DRV_CUST_FRC_TYPE_VENDOR_N) ? CheckFRCInitStatusVendorN: CheckFRCInitStatusVendorM)
#define READ_FRC_VERSION_FROM_PANEL             ((DRVCUST_Get_FRC_Type() == DRV_CUST_FRC_TYPE_VENDOR_N) ? ReadFRCVersionFromPanelVendorN: ReadFRCVersionFromPanelVendorM)
#define FRC_UNMUTE                              ((DRVCUST_Get_FRC_Type() == DRV_CUST_FRC_TYPE_VENDOR_N) ? FRCUnmuteVendorN: FRCUnmuteVendorM)
#define ENTER_FRC_REGISTER_MODE                 ((DRVCUST_Get_FRC_Type() == DRV_CUST_FRC_TYPE_VENDOR_N) ? NULL: EnterFRCRegisterModeVendorM)
#define EXIT_FRC_REGISTER_MODE                  ((DRVCUST_Get_FRC_Type() == DRV_CUST_FRC_TYPE_VENDOR_N) ? NULL: ExitFRCRegisterModeVendorM)
#define ENABLE_FRC_VX1_OUT                      ((DRVCUST_Get_FRC_Type() == DRV_CUST_FRC_TYPE_VENDOR_N) ? NULL: EnableFRCVx1OutVendorM)
#define DISABLE_FRC_VX1_OUT                     ((DRVCUST_Get_FRC_Type() == DRV_CUST_FRC_TYPE_VENDOR_N) ? NULL: DisableFRCVx1OutVendorM)
#endif
#else
#define CUSTOMER_POWER_ON_SEQUENCE              (NULL)
#define CUSTOMER_POWER_OFF_SEQUENCE             (NULL)
#define CHECK_FRC_INIT_STATUS                   (NULL)
#define READ_FRC_VERSION_FROM_PANEL             (NULL)
#define FRC_UNMUTE                              (NULL)
#define ENTER_FRC_REGISTER_MODE                 (NULL)
#define EXIT_FRC_REGISTER_MODE                  (NULL)
#define ENABLE_FRC_VX1_OUT                      (NULL)
#define DISABLE_FRC_VX1_OUT                     (NULL)
#endif

#if 0//def CUSTOM_POWER_STATE_CTRL_ENABLE
#ifndef CC_UBOOT
#define LOADER_CEC_CONFIG_QUERY_FUNC            (CustomCheckCECCtrlState)
#define POWER_STATE_QUERY_FUNC                  (PDWNC_Custom_CheckPowerState)
#endif
#endif /* CUSTOM_POWER_STATE_CTRL_ENABLE */

#define DRV_TURN_ON_PANEL_FUNC   (NULL)
#define DRV_TURN_OFF_PANEL_FUNC  (NULL)
#define DRV_TURN_ON_BACKLT_FUNC  (NULL)
#define DRV_TURN_OFF_BACKLT_FUNC (NULL)

//---------------------------------------------------------------------------
// Constant definitions
//---------------------------------------------------------------------------
#define CUSTOM_IR_LED_BLINK_PERIOD              150         // 150ms

#define WIFI_MODUDLE_RST_GPIO                   (GPIO(237))  // PHYLED
#define WIFI_MODUDLE_RST_POLARITY               (0)

// Strap GPIO definitaion on PCB
#define CUSTOM_GPIO_PANEL_NVM_WP                (GPIO(54))    //BINT/X_WP
#define CUSTOM_GPIO_PANEL_ID_PIN_0              (GPIO(0xffffffff))
#define CUSTOM_GPIO_PANEL_DET_PIN               (GPIO(273))   //Sakura use it
#define CUSTOM_GPIO_PANELLESS_PIN               (GPIO(57))   // for non -BE model
#define CUSTOM_PCB_TYPE_1_WXGA                  0x00
#define CUSTOM_PCB_TYPE_1_FHD                   0x01
#define CUSTOM_PCB_TYPE_2                       0x02
#define CUSTOM_PCB_TYPE_3                       0x03
#define CUSTOM_PCB_TYPE_5                       0x05

#define CUSTOM_GPIO_PANEL_NONTCON               3
#define CUSTOM_GPIO_PANEL_OTHER                 2
#define CUSTOM_GPIO_PANEL_WXGA                  1
#define CUSTOM_GPIO_PANEL_FHD                   0
#define CUSTOM_GPIO_LVDS_OTHER_BIT              2
#define CUSTOM_GPIO_LVDS_10BIT                  1
#define CUSTOM_GPIO_LVDS_8BIT                   0
#define CUSTOM_GPIO_FACTORY_SONY                0
#define CUSTOM_GPIO_FACTORY_WISTRON             1
#define CUSTOM_GPIO_DVD_NA                      0
#define CUSTOM_GPIO_DVD_INCLUDE                 1
#define CUSTOM_GPIO_FHD_CMO_37                  0
#define CUSTOM_GPIO_FHD_OTHER                   1
#define CUSTOM_GPIO_AUD_NORMAL                  0
#define CUSTOM_GPIO_AUD_WOOFER                  1
#define CUSTOM_GPIO_LIGHT_SENSOR_INCLUDE        0
#define CUSTOM_GPIO_LIGHT_SENSOR_NA             1
#define CUSTOM_GPIO_THERMAL_SENSOR_NA           0
#define CUSTOM_GPIO_THERMAL_SENSOR_INCLUDE      1
#define CUSTOM_PCB_TYPE_1H                      0
#define CUSTOM_PCB_TYPE_2H                      1

#define CUSTOM_PANEL_WIDTH_FHD                  1920
#define CUSTOM_PANEL_WIDTH_WXGA                 1366
#if 1
// LED GPIO
#define CUSTOM_GPIO_LED_STANDBY                 0xffffffff//GPIO(206)

#ifdef CC_SAKURA_LED_ILLUMINATION
#define CUSTOM_GPIO_LED_RED                     (GPIO(233))     //LED R/G/B is used for Google talking
#define CUSTOM_GPIO_LED_GREEN                   (GPIO(234))
#define CUSTOM_GPIO_LED_BLUE                    (GPIO(235))
#define CUSTOM_GPIO_LED_WHITE                   (GPIO(236))
#define CUSTOM_GPIO_LED_AMBER                   (0xffffffff)// (OPCTRL(11))    // FY20 no amber LED , concel record LED.
#define CUSTOM_GPIO_LED_PWM_FREQ                (2500)  // request cycle = 400usec = 1sec / 2500

#define CUSTOM_SET_LED_RED_PWM(u4DutyCycle)     PDWNC_PwmSetPwm(CUSTOM_RED_PWM_PIN,1,CUSTOM_GPIO_LED_PWM_FREQ,u4DutyCycle)
#define CUSTOM_SET_LED_GREEN_PWM(u4DutyCycle)   PDWNC_PwmSetPwm(CUSTOM_GREEN_PWM_PIN,1,CUSTOM_GPIO_LED_PWM_FREQ,u4DutyCycle)
#define CUSTOM_SET_LED_BLUE_PWM(u4DutyCycle)    PDWNC_PwmSetPwm(CUSTOM_BLUE_PWM_PIN,1,CUSTOM_GPIO_LED_PWM_FREQ,u4DutyCycle)
#define CUSTOM_SET_LED_WHITE_PWM(u4DutyCycle)   PDWNC_PwmSetPwm(CUSTOM_WHITE_PWM_PIN,1,CUSTOM_GPIO_LED_PWM_FREQ,u4DutyCycle)
#define CUSTOM_SET_LED_TALLY_PWM(u4DutyCycle)   PDWNC_PwmSetPwm(CUSTOM_TALLY_PWM_PIN,1,CUSTOM_GPIO_LED_PWM_FREQ,u4DutyCycle)

#define LED_BETA                                (0)
#define ENTRY_CNT_W                             (1)
#define LOOP_CNT_W                              (2)
#define ENTRY_CNT_RGB                           (3)
#define LOOP_CNT_RGB                            (4)
#define LED_DUTY_W0                             (5)
#define LED_DURATION_W0                         (17)
#define LED_DUTY_R0                             (29)
#define LED_DUTY_G0                             (41)
#define LED_DUTY_B0                             (53)
#define LED_DURATION_RGB0                       (65)

//#define LED_ANIMA_W_FULLTYPE                  (77)
//#define LED_ANIMA_W_ONESHOT_TYPE              (78)
//#define LED_ANIMA_RGB_FULLTYPE                (79)
//#define LED_ANIMA_RGB_ONESHOT_TYPE            (80)

#define LED_ANIMA_PARA_TOTAL                    (77)
#define LED_ANIMA_POINT_NUM                     (12)
#define LED_ANIMA_DURATION_MS                   (50)
#define LED_ANIMA_UPDATE_FREQ                   (10)  // in ms
#define LED_ANIMA_REAL_DELAY_TIME               (8)  //10 to 8

#define LED_EVENT_ARRAY_TOTAL                   (20)

#endif

#ifdef CC_LED_PWM_MODE
#define CUSTOM_RED_PWM_PIN                      (0)         //LED_PWM_0
#define CUSTOM_GREEN_PWM_PIN                    (1)         //LED_PWM_1
#define CUSTOM_BLUE_PWM_PIN                     (2)         //LED_PWM_2
#define CUSTOM_WHITE_PWM_PIN                    (3)         //LED_PWM_3
#define CUSTOM_TALLY_PWM_PIN                    (5)         //LED_PWM_5
//#define CUSTOM_ERROR_LED_PIN                    (0xffffffff)    //M5 ERROR LED use GPIO cuntion
#define CUSTOM_ERROR_LED_PIN                    (CUSTOM_RED_PWM_PIN)    //M5 ERROR LED use GPIO cuntion
#define CUSTOM_ERROR_LED_NON_PWM_PIN            (GPIO(211)) //FY20 M3 /M5  it is not use LED_PWM pin, change to GPIO for ERR LED control
#define CUSTOM_ERROR_LED_ON_VAL                 (1)

#define CUSTOM_LED_POWER_ON_VAL                 1
#define CUSTOM_LED_STANDBY_ON_VAL               1
#define CUSTOM_LED_TIMER_ON_VAL                 1

#define CUSTOM_PWM_FREQ                         (50)
#define CUSTOM_PWM_ON_DUTY                      (6)
#define CUSTOM_PWM_OFF_DUTY                     (0)
#else
#define CUSTOM_GPIO_LED_POWER                   0xffffffff//GPIO(207)
#define CUSTOM_GPIO_LED_POWER_SECONDARY         0xffffffff//GPIO(206)
#define CUSTOM_GPIO_LED_TIMER_AMBER             0xffffffff  //OPCTRL(5)     // ADIN5
#define CUSTOM_GPIO_LED_TIMER_GREEN             0xffffffff  // GPIO 26
#define CUSTOM_LED_POWER_ON_VAL                 1
#define CUSTOM_LED_STANDBY_ON_VAL               1
#define CUSTOM_LED_TIMER_ON_VAL                 1
#endif
#define T8032_CTRL_ERR_LED                      CUSTOM_GPIO_LED_STANDBY
#define T8032_CTRL_ERR_LED_ON_VAL               CUSTOM_LED_STANDBY_ON_VAL

// Power Key
#define BUTTON_POWER_KEY                        (OPCTRL(15))
//#define BUTTON_POWER_KEY_SRV_NUM                SERVO(3)
//#define POWER_KEY_SRV_AD_HI_THR                 240
//#define POWER_KEY_SRV_AD_LOW_THR                210

#define CUSTOM_PANEL_PWR_DET_PIN                (0xffffffff) //(ADIN(3))  FY20 M3 & M5 no panel power detection . Atually FY18 M3 ADIN3 pull up directly.
#define CUSTON_PANLE_PWR_DET_ADC_VALUE          (358)
#define CUSTON_PANLE_PWR_DET_TRY_TIMES          (40)

// Shutdown status
#define CUSTOM_SHUTDOWN_ERROR                   (1 << 0)
#define CUSTOM_SHUTDOWN_AC_DET                  (1 << 1)
#define CUSTOM_SHUTDOWN_DISABLE_STANDBY_LED     (1 << 2)

#define CUSTOM_GPIO_HOTEL_MODE                  (OPCTRL(14))
#define CUSTOM_HOTEL_MODE_ON_VAL                0
#define CUSTOM_HOTEL_MODE_OFF_VAL               (1-CUSTOM_HOTEL_MODE_ON_VAL)

#define CUSTOM_GPIO_HOT_PLUG_TUNER_DET          (GPIO(80))  // SF_OUT for TUNER_DET

// DVD GPIO
#define CUSTOM_GPIO_DVD_RESET                   0xffffffff//GPIO(12)
#define CUSTOM_DVD_POWER_ON                     1
#define CUSTOM_DVD_POWER_OFF                    0
#endif

//-----------------------------------------------------------------------------
// Misc GPIO info.
//-----------------------------------------------------------------------------
#define CUSTOM_GPIO_AC_OFF_INFO                (0xffffffff)  //no use it
#define CUSTOM_GPIO_WIFI_BT_RESET              (GPIO(237))
#define CUSTOM_GPIO_MHL_VBUS_EN1               (0xffffffff)
#define CUSTOM_GPIO_AUDIO_MUTE_SCART           (0xffffffff)  // no scart
#define CUSTOM_GPIO_AUDIO_MUTE_SPHP            (GPIO(52))
#define CUSTOM_GPIO_DAMP_RESET                 (GPIO(114))
#define CUSTOM_GPIO_DAMP_MUTE                  (GPIO(117))
#define CUSTOM_GPIO_USB_PWR_EN0                (GPIO(45))
#define CUSTOM_GPIO_USB_PWR_EN1                (GPIO(43))
#define CUSTOM_GPIO_USB_PWR_EN2                (GPIO(44))
#define CUSTOM_GPIO_LED_R                      (GPIO(233))   // also change pinmux
#define CUSTOM_GPIO_LED_G                      (GPIO(234))   // also change pinmux
#define CUSTOM_GPIO_LED_B                      (GPIO(235))   // also change pinmux
#define CUSTOM_GPIO_LED_W                      (GPIO(236))   // also change pinmux
#define CUSTOM_GPIO_LED_REC                    (0xffffffff)  //(OPCTRL(11))  //  No record LED , change to error LED
#define CUSTOM_GPIO_LED_ERR                    (GPIO(211))

#define CUSTOM_GPIO_ETHER_PWR_EN               (GPIO(219))
#define CUSTOM_GPIO_DIGITAL_STBY               (0xffffffff)  // not use now .
#define CUSTOM_GPIO_HOTEL_CTRL                 (OPCTRL(14))
#define CUSTOM_GPIO_TU_CLK_EN                  (0xffffffff)  // for future tuner , M3/M5 not used .
#define CUSTOM_GPIO_C4_DISABLE                 (GPIO(55))    // RS323 disable
#define CUSTOM_GPIO_SPECAIL_REQ_1              (OPCTRL(17))  // it is for WIFI power control . also for DDR power control , but only one will be monted by HW
#define CUSTOM_GPIO_OPWRSB                     (GPIO(231))   // OPWRSB
#define CUSTOM_GPIO_STB_SDA                    (GPIO(227))
#define CUSTOM_GPIO_STB_SDL                    (GPIO(228))

// BM2&FBM IRB Pinmux
#define CUSTOM_GPIO_IRB_RX                     (0xffffffff)   // IRB use UART pin
#define CUSTOM_GPIO_IRB_TX                     (0xffffffff)   // IRB use UART pin

/* FY17 add */
#define CUSTOM_GPIO_PQ_RST                      (0xffffffff)  /* FY17 add for LPT Model */
#define CUSTOM_GPIO_FRC_RST                     (0xffffffff)  /* FY17 add for LPT Model */
#define CUSTOM_GPIO_I2C_OP_SDA                  (GPIO(200))
#define CUSTOM_GPIO_I2C_OP_SCL                  (GPIO(201))

/* Add for no use GPIO number directly */
#define CUSTOM_GPIO_BEL_BOOT_VX1_REQ_GPIO       (GPIO(113))
#define CUSTOM_GPIO_BEL_BOOT_UP_NOTIFY_GPIO     (GPIO(67))

/* LD or BE spi pin setting */
#define CUSTOM_GPIO_LD_SPI_CS_PIN               (PIN_GPIO6)
#define CUSTOM_GPIO_LD_SPI_CLK_PIN              (PIN_GPIO63)
#define CUSTOM_GPIO_LD_SPI_DO_PIN               (PIN_GPIO65)
#define CUSTOM_GPIO_LD_SPI_DI_PIN               (PIN_GPIO64)
//define CUSTOM_GPIO_LD_SPI_VSYNC_PIN             (PIN_SF_CE)    // LD model just reserve , 4K BE no use, 8K DEC for EARC
#define CUSTOM_GPIO_LD_SPI_EMIT_PIN             (PIN_SF_IN)    // 4K BE no use, 8K DEC for EARC
#define CUSTOM_GPIO_LD_SPI_READY_PIN            (PIN_GPIO7)    // 4KBE no USE , 8k DEC GPIO

#define CUSTOM_GPIO_FRC_DGB_UART_TX_PIN         (PIN_U1TX)
#define CUSTOM_GPIO_FRC_DGB_UART_RX_PIN         (PIN_U1RX)
#define CUSTOM_GPIO_BE_DMA_UART_TX_PIN          (PIN_U1TX)
#define CUSTOM_GPIO_BE_DMA_UART_RX_PIN          (PIN_U1RX)

#define CUSTOM_GPIO_BE_SPI_CS_PIN               (PIN_GPIO62)
#define CUSTOM_GPIO_BE_SPI_CLK_PIN              (PIN_GPIO63)
#define CUSTOM_GPIO_BE_SPI_DO_PIN               (PIN_GPIO64)
#define CUSTOM_GPIO_BE_SPI_DI_PIN               (PIN_GPIO65)

#define CUSTOM_GPIO_BL_FB_REF_PIN               (PIN_GPIO70)
#define CUSTOM_GPIO_BL_I_DUTY_GPIO              (GPIO(70))  // GPIO70   Backlight control (I-Duty)
#define CUSTOM_GPIO_BL_DC_DIMMER_PIN            (PIN_GPIO71)
#define CUSTOM_GPIO_BL_I_PEAK_GPIO              (GPIO(71))  // GPIO71	Backlight control (I-Peak)
#define CUSTOM_GPIO_BL_BLKING_OR_DIMMER_0_PIN   (PIN_GPIO6)
#define CUSTOM_GPIO_BL_BLK_PULSE_PORT0_GPIO     (GPIO(6))   // GPIO6    Backlight control (BLK-Pulse-Port0)
#define CUSTOM_GPIO_BL_DIMMER_1_PIN             (PIN_GPIO67)
#define CUSTOM_GPIO_BL_BLK_PULSE_PORT1_GPIO     (GPIO(67))  // GPIO67   Backlight control (BLK-Pulse-Port1)
#define CUSTOM_GPIO_BL_DIMMER_2_PIN             (PIN_GPIO68)
#define CUSTOM_GPIO_BL_BLK_PULSE_PORT2_GPIO     (GPIO(68))  // GPIO68   Backlight control (BLK-Pulse-Port2)
#define CUSTOM_GPIO_BL_DIMMER_3_PIN             (PIN_GPIO69)
#define CUSTOM_GPIO_BL_BLK_PULSE_PORT3_GPIO     (GPIO(69))  // GPIO69   Backlight control (BLK-Pulse-Port3)

#define CUSTOM_GPIO_LBH_POWER                   (0xffffffff)    // 8KSHV power on GPIO, current FY20 M3 only
#define CUSTOM_GPIO_LBH_RESET                   (0xffffffff)    // 8KSHV reset GPIO,current FY20 M3 only
#define CUSTOM_LBH_POWER_ON_VAL                 (1)
#define CUSTOM_LBH_POWER_OFF_VAL                (0)
#define CUSTOM_LBH_POWER_ON_DELAY               (10)  // unit: ms
#define CUSTOM_LBH_POWER_OFF_DELAY              (50)  // unit: ms

//-----------------------------------------------------------------------------
// Macros
//-----------------------------------------------------------------------------

#define INIT_SET_GPIO(gpio, onval)                                  \
    if (DRVCUST_InitQuery(gpio, &i)==0)                             \
    {                                                               \
        if ((i!=0xFFFFFFFF) && (DRVCUST_InitQuery(onval, (UINT32 *)&i4Val)==0))          \
        {                                                           \
            VERIFY(GPIO_Output((INT32)i, &i4Val) == i4Val);         \
        }                                                           \
    }

#define DOWN_SET_GPIO(gpio, onval)                                  \
    if (DRVCUST_InitQuery(gpio, &i)==0)                             \
    {                                                               \
        if ((i!=0xFFFFFFFF) && (DRVCUST_InitQuery(onval, (UINT32 *)&i4Val)==0))          \
        {                                                           \
            i4Val = !i4Val;                                         \
            VERIFY(GPIO_Output((INT32)i, &i4Val)== i4Val);          \
        }                                                           \
    }

#define UART_SELECTION_IS_TTY_USB_LOG() \
( \
{ \
    UINT32 uart_sel=0;\
    EEPROM_Read(CUSTOM_UART_SELECTION_ADDR, (UPTR)&uart_sel, 1);\
    ((uart_sel==UART_SELECTION_TTY_USB_LOG)); \
} \
)
#define _IS_USB_LOG_MODE UART_SELECTION_IS_TTY_USB_LOG()

//-----------------------------------------------------------------------------
// Structure definition
//-----------------------------------------------------------------------------
#ifdef CC_SAKURA_LED_ILLUMINATION

typedef enum
{
    eLedCenter = 0,
    eLedSide,
    eLedTypeTotal
}LED_TYPE_T;


typedef enum
{
    eLedWhite = 0,
    eLedRed,
    eLedGreen,
    eLedBlue,
    eLedColorTotal
}LED_COLOR_T;

typedef enum
{
    eLedOff,
    eLedAnimeLit,
    eLedAnimeLoop,
    eLedAnimeBlink,
    eLedAnimeOneShot,
    eLedAnimeOneShotLit,
    eLedAnimeOneShotLoop
}LED_ANIMATION_T;


/*
typedef struct _LedAnimaParameter
{
    UINT8 u1LedBeta;   //£]¡× ([LED_BETA] + 1) / 256 [0-255]
    UINT8 u1EntryCnt_W;  //number of Entry Action (One Shot) [0-12]
    UINT8 u1LoopCnt_W;   //number of loop Count [0-12]
    UINT8 u1EntryCnt_RGB;  //number of Entry Action (One Shot) [0-12]
    UINT8 u1LoopCnt_RGB;   //number of loop Count [0-12]
    UINT8 aru1LedDuty_W[12];         // PWM duty [0-255]
    UINT8 aru1LedDuration_W[12];   //PWM duratoin [0-255] * 50msec
    UINT8 aru1LedDuty_R[12];          // PWM duty [0-255]
    UINT8 aru1LedDuty_G[12];          // PWM duty [0-255]
    UINT8 aru1LedDuty_B[12];          // PWM duty [0-255]
    UINT8 aru1LedDuration_RGB[12];   //PWM duratoin [0-255] * 50msec

} LED_ANIMA_PARAMETER;
*/

typedef struct _LedEvent
{
    LED_PATTERN_IDX_T eLedPatternIdx;
    LED_ANIMATION_T eLedAnimeType[eLedTypeTotal];
    BOOL fgNewEvent[eLedTypeTotal];
    BOOL fgEventIsDone[eLedTypeTotal];
    UINT32 u4CurrTimePt[eLedTypeTotal];
} LED_EVENT_INFO;

//UINT8 u1EntryCnt;  //number of Entry Action (One Shot) [0-12]
//UINT8 u1LoopCnt;   //number of loop Count [0-12]
//UINT8 aru1LedDuty[12];	 // PWM duty [0-255]
//UINT8 aru1LedDuration[12];	//PWM duratoin [0-255] * 50msec
/*
typedef struct _LedAnima
{
    UINT32 u4LedBeta;        //£]¡× ([LED_BETA] + 1) / 256 [0-255]
    UINT8 u1EntryCnt_W;  //number of Entry Action (One Shot) [0-12]
    UINT8 u1LoopCnt_W;   //number of loop Count [0-12]
    UINT8 u1EntryCnt_RGB;  //number of Entry Action (One Shot) [0-12]
    UINT8 u1LoopCnt_RGB;   //number of loop Count [0-12]
    UINT8 aru1LedDuty_W[LED_ANIMA_POINT_NUM];         // PWM duty [0-255]
    UINT8 aru1LedDuration_W[LED_ANIMA_POINT_NUM];   //PWM duratoin [0-255] * 50msec
    UINT8 aru1LedDuty_R[LED_ANIMA_POINT_NUM];          // PWM duty [0-255]
    UINT8 aru1LedDuty_G[LED_ANIMA_POINT_NUM];          // PWM duty [0-255]
    UINT8 aru1LedDuty_B[LED_ANIMA_POINT_NUM];          // PWM duty [0-255]
    UINT8 aru1LedDuration_RGB[LED_ANIMA_POINT_NUM];   //PWM duratoin [0-255] * 50msec
    LED_ANIMATION_T eLedAnimaType_W;
    LED_ANIMATION_T eLedAnimaType_RGB;

} LED_ANIMATION_STATE;
*/


#else
typedef struct _LedCtrl
{
    D_LED_TYPE eLedType;
    UINT32 u4LedState;
} LED_CTRL_STATE;
#endif
//-----------------------------------------------------------------------------
// Prototypes
//-----------------------------------------------------------------------------
void GPIO_CustomPowerOnFunc(void);
void GPIO_CustomPowerOffFunc(UINT32 u4PowerDownEn);
#if (defined(CC_SAKURA_LED_ILLUMINATION) && !(defined(CC_MTK_LOADER) || defined(CC_MTK_PRELOADER)))
void GPIO_CustomLedCtrlFunc(LED_PATTERN_IDX_T eLedPatternIdx);
#else
void GPIO_CustomLedCtrlFunc(LED_STATUS_T eLedStatus);
#endif
void CustomPowerOffSelfDiagShutDown(void);
void CustomPowerOnSequence(void);
void CustomPowerOffSequence(void);
UINT32 CustomModelQueryFunc(VOID);
void _LdrUpgradeBreakFunc(void);
void _LdrUpgradeDlmCbFunc(UINT32 u4BufSize);
void _LdrUpgradeDlmGetTagVerCbFunc(UCHAR* ucTagName, CHAR *szCurVer);
INT32 _LdrUpgradeDlmCmpTagVerCbFunc(UCHAR* ucTagName, CHAR *szCurVer, CHAR *szUpgVer);
BOOL IsCustomLdrSkipUpgradeHE(void);
UINT32 _LdrCustomLogoDisplay(void);
UINT32 _LdrCustomImgDecompression(void);
UINT8 CheckFRCInitStatusVendorN(void);
void CheckFRCInitStatusVendorM(void);
UINT8 ReadFRCVersionFromPanelVendorN(void);
void ReadFRCVersionFromPanelVendorM(void);
UINT8 FRCUnmuteVendorN(void);
void FRCUnmuteVendorM(void);
void EnterFRCRegisterModeVendorM(void);
void ExitFRCRegisterModeVendorM(void);
void EnableFRCVx1OutVendorM(void);
void DisableFRCVx1OutVendorM(void);
BOOL CustomPowerSetForExternalDecoder(BOOL isOn);
BOOL CustomPowerGetForExternalDecoder(void);
#endif /* CUSTOM_GPIO_H*/

