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

UINT32 _gu4SysPinmuxInit[][2] = 
{
    // Audio
    {PIN_ALIN, PINMUX_FUNCTION1},
    {PIN_ASPDIF0, PINMUX_FUNCTION1},
    {PIN_ASPDIF1, PINMUX_FUNCTION1},
    {PIN_AOMCLK, PINMUX_FUNCTION1},
    {PIN_AOBCK, PINMUX_FUNCTION1},
    {PIN_AOLRCK, PINMUX_FUNCTION1},
    {PIN_AOSDATA0, PINMUX_FUNCTION1},
    {PIN_AOSDATA1, PINMUX_FUNCTION1},
    {PIN_AOSDATA2, PINMUX_FUNCTION1},
    {PIN_AOSDATA3, PINMUX_FUNCTION1},
    {PIN_AOSDATA4, PINMUX_FUNCTION1},

    // UART 0
    //{PIN_U0TX, PINMUX_FUNCTION0},
    //{PIN_U0RX, PINMUX_FUNCTION0},
	// UART 1
	// UART1 uart_dma for BE chip.
	{PIN_U1TX, PINMUX_FUNCTION2},
	{PIN_U1RX, PINMUX_FUNCTION2},

	    // SIF
    {PIN_OSDA0, PINMUX_FUNCTION1},   // sif m0, eeprom  /* channel 0 */
    {PIN_OSCL0, PINMUX_FUNCTION1},
    {PIN_OSDA1, PINMUX_FUNCTION1},   // sif m1,             /* channel 1 */
    {PIN_OSCL1, PINMUX_FUNCTION1},
    {PIN_OSDA2, PINMUX_FUNCTION3},   // sif m2,           /* channel 2 */
    {PIN_OSCL2, PINMUX_FUNCTION3},


    {PIN_OPCTRL0, PINMUX_FUNCTION1}, // pdwnc sif m0 /* channel 3 */
    {PIN_OPCTRL1, PINMUX_FUNCTION1},
    {PIN_STB_SDA, PINMUX_FUNCTION1}, // pdwnc sif m1 /* channel 4 */
    {PIN_STB_SCL, PINMUX_FUNCTION1},
    {PIN_OPCTRL2, PINMUX_FUNCTION4}, // sif m3,          /* channel 5 */
    {PIN_OPCTRL3, PINMUX_FUNCTION4},
    
    // Demod ATD IF_AGC or IF_AGC_S just only one enable
    {PIN_IF_AGC, PINMUX_FUNCTION1},
    {PIN_IF_AGC_S, PINMUX_FUNCTION0},
    // First demod serial input , 2bit data
    {PIN_DEMOD_TSCLK, PINMUX_FUNCTION1},
    {PIN_DEMOD_TSVAL, PINMUX_FUNCTION1},
    {PIN_DEMOD_TSSYNC, PINMUX_FUNCTION1},
    {PIN_DEMOD_TSDATA0, PINMUX_FUNCTION1}, // data0
    {PIN_DEMOD_TSDATA5, PINMUX_FUNCTION2}, // data1
    //Second demod serial input ,2bit data
    {PIN_DEMOD_TSDATA1, PINMUX_FUNCTION2},
    {PIN_DEMOD_TSDATA2, PINMUX_FUNCTION2},
    {PIN_DEMOD_TSDATA3, PINMUX_FUNCTION2},
    {PIN_DEMOD_TSDATA4, PINMUX_FUNCTION2}, //data0
    {PIN_DEMOD_TSDATA6, PINMUX_FUNCTION2}, //data1
    
    {PIN_DEMOD_TSDATA7, PINMUX_FUNCTION0}, // keep GPIO function AC_DEC_IN/BE_GPIO2
    // SD card
    //{PIN_GPIO63,  PINMUX_FUNCTION0 },//GPIO 63 SDIO PWR SWITCH
    //{PIN_ADIN7,  PINMUX_FUNCTION1 },//GPIO 236  SDCARD DETECT

#ifdef LVDS_GPIO_SUPPORT
    //set the following lvds pins as gpio function
    {PIN_BE4P,  PINMUX_FUNCTION1 },//GPIO 160  FE_PWR_ON/DSQ_SW_CTRL
    {PIN_BE4N,  PINMUX_FUNCTION1 },//GPIO 161  FE_PWR2_ON/FE_SAT_XRST
    {PIN_BE3P,  PINMUX_FUNCTION1 },//GPIO 162
    {PIN_BE3N,  PINMUX_FUNCTION1 },//GPIO 163  HP_DET
    {PIN_BECKP, PINMUX_FUNCTION1 },//GPIO 164  COMP_DET
    {PIN_BECKN, PINMUX_FUNCTION1 },//GPIO 165  SDCARD WP
    {PIN_BE2P,  PINMUX_FUNCTION1 },//GPIO 166  SDCARD VOL CNT
    {PIN_BE2N,  PINMUX_FUNCTION1 },//GPIO 167  USB_OCP1
    {PIN_BE1P,  PINMUX_FUNCTION1 },//GPIO 168  FE_XRST
    {PIN_BE1N,  PINMUX_FUNCTION1 },//GPIO 169  BL_ECO
    {PIN_BE0P,  PINMUX_FUNCTION1 },//GPIO 170  USB_VBUS3
    {PIN_BE0N,  PINMUX_FUNCTION1 },//GPIO 171  USB_OCP3
    {PIN_BO4P,  PINMUX_FUNCTION1 },//GPIO 172  HDMI_RST
    {PIN_BO4N,  PINMUX_FUNCTION1 },//GPIO 173  PANEL_TEST_ON
    {PIN_BO3P,  PINMUX_FUNCTION1 },//GPIO 174
    {PIN_BO3N,  PINMUX_FUNCTION1 },//GPIO 175  PANEL_VCOM_WP
    {PIN_BOCKP, PINMUX_FUNCTION1 },//GPIO 176  AMP_XRST
    {PIN_BOCKN, PINMUX_FUNCTION1 },//GPIO 177  NT_DONE
    {PIN_BO2P,  PINMUX_FUNCTION1 },//GPIO 178  MAIN_FAN_ON
    {PIN_BO2N,  PINMUX_FUNCTION1 },//GPIO 179  FAN_MAX
    {PIN_BO1P,  PINMUX_FUNCTION1 },//GPIO 180  FAN_SOO
#endif


    //{PIN_GPIO0, PINMUX_FUNCTION0 },//GPIO 0
    //{PIN_GPIO6, PINMUX_FUNCTION1 },//GPIO 6
    //{PIN_GPIO7, PINMUX_FUNCTION1 },//GPIO 7
    // SPI 
    {PIN_GPIO1, PINMUX_FUNCTION6 },//GPIO 1
    {PIN_GPIO2, PINMUX_FUNCTION6 },//GPIO 2
    {PIN_GPIO3, PINMUX_FUNCTION6 },//GPIO 3
    {PIN_GPIO8, PINMUX_FUNCTION6 },//GPIO 8
    //PCIE
    {PIN_GPIO4, PINMUX_FUNCTION1 },//GPIO 4
    {PIN_GPIO5, PINMUX_FUNCTION1 },//GPIO 5
    {PIN_OPCTRL24, PINMUX_FUNCTION2},

    //CI pin setting 
    {PIN_SPI_CLK,   PINMUX_FUNCTION1 },
    {PIN_SPI_CS,    PINMUX_FUNCTION1 },
    {PIN_SPI_DO,    PINMUX_FUNCTION1 },
    {PIN_SPI_DI,    PINMUX_FUNCTION1 },
    {PIN_INT,       PINMUX_FUNCTION1 },
    {PIN_CI_RESET,         PINMUX_FUNCTION1 },
    {PIN_CIL_RX1_D1,       PINMUX_FUNCTION1 },
    {PIN_CIL_RX1_D0,       PINMUX_FUNCTION1 },
    {PIN_CIL_TX1_D1,       PINMUX_FUNCTION1 },
    {PIN_CIL_TX1_D0,       PINMUX_FUNCTION1 },
    {PIN_CIL_DEMOD1_CLK,   PINMUX_FUNCTION1 },
    {PIN_CIL_RX0_D1,       PINMUX_FUNCTION1 },
    {PIN_CIL_RX0_D0,       PINMUX_FUNCTION1 },
    {PIN_CIL_TX0_D1,       PINMUX_FUNCTION1 },
    {PIN_CIL_TX0_D0,       PINMUX_FUNCTION1 },
    {PIN_CIL_TX_CLK,       PINMUX_FUNCTION1 },
    {PIN_CIL_DEMOD0_CLK,   PINMUX_FUNCTION1 },
    {PIN_DEMOD_RST, PINMUX_FUNCTION3 },

    // scanning backlight
    // PWM
    // move to Gpioctrl.c#StartPWM_Init() for waveform spec reqeusted
#if 0
    {PIN_SF_CE,   PINMUX_FUNCTION3},
    {PIN_SF_CLK,  PINMUX_FUNCTION3},
    {PIN_GPIO6,   PINMUX_FUNCTION3},
    {PIN_GPIO67,  PINMUX_FUNCTION3},
    {PIN_GPIO68,  PINMUX_FUNCTION3},
    {PIN_GPIO69,  PINMUX_FUNCTION3},
#endif

    // Front LED control
    {PIN_LED_PWM0, PINMUX_FUNCTION1},
    {PIN_LED_PWM1, PINMUX_FUNCTION1},
    {PIN_LED_PWM2, PINMUX_FUNCTION1},
    {PIN_LED_PWM3, PINMUX_FUNCTION1},
    {PIN_PHYLED1,  PINMUX_FUNCTION2},   //Tally LED
    {PIN_OPCTRL11, PINMUX_FUNCTION0},   // ERR LED

    // VGA
    //{PIN_VGA_SCL, PINMUX_FUNCTION2},
    //{PIN_VGA_SDA, PINMUX_FUNCTION2},



#ifdef CC_ENABLE_HDMI_JTAG
    {PIN_GPIO57, PINMUX_FUNCTION1 },        // default JTCK
    {PIN_HDMI_1_SCL, PINMUX_FUNCTION2 },    // ice_jtms
    {PIN_HDMI_1_SDA, PINMUX_FUNCTION2 },    // ice_jtck
    {PIN_HDMI_2_SCL, PINMUX_FUNCTION2 },    // ice_jtdo
    {PIN_HDMI_2_SDA, PINMUX_FUNCTION2 },    // ice_jtdi
    {PIN_HDMI_2_HPD, PINMUX_FUNCTION2 },    // ice_jtrst
#else // deticated JTAG
    //{PIN_GPIO57, PINMUX_FUNCTION0 },        // default JTCK
#endif
    // HDMI Detect .
    {PIN_ADIN3, PINMUX_FUNCTION1},
    {PIN_ADIN4, PINMUX_FUNCTION1},
    {PIN_ADIN5, PINMUX_FUNCTION1},
    {PIN_ADIN6, PINMUX_FUNCTION1},

    //{PIN_U2RX, PINMUX_FUNCTION0},//demod reset
    //{PIN_U2TX, PINMUX_FUNCTION0},// tuner wakeup need to input
    {PIN_OPCTRL20, PINMUX_FUNCTION0},// ewbs tuner power control    set to GPIO

    // Change USB power GPIO to GPIO function
    {PIN_GPIO43, PINMUX_FUNCTION0},
    {PIN_GPIO44, PINMUX_FUNCTION0},
    {PIN_GPIO45, PINMUX_FUNCTION0},
    {PIN_GPIO46, PINMUX_FUNCTION0},
    {PIN_GPIO58, PINMUX_FUNCTION1},    //default JTAG
    {PIN_GPIO61, PINMUX_FUNCTION0},

    //Misc setting.
    //Panel less detection
    {PIN_GPIO57, PINMUX_FUNCTION1},    //default JTAG
    //VEDIO detection
    {PIN_GPIO56, PINMUX_FUNCTION1},    //default JTAG
    //CR detection
    {PIN_GPIO49, PINMUX_FUNCTION0},    //default JTAG
    //LD_ERR or TCON_INT_ERR
    {PIN_GPIO59, PINMUX_FUNCTION1},    //default JTAG
    //AC_DET/BE_RESET
    {PIN_GPIO51, PINMUX_FUNCTION0},
    //DC_OFF_detection , for AC off detection
    {PIN_OPCTRL16, PINMUX_FUNCTION0},
    //POEWR key GPIO
    {PIN_OPCTRL15, PINMUX_FUNCTION0},
    //PANEL_CAL_DONE
    {PIN_SF_IN, PINMUX_FUNCTION1},
    //reserved(PQ_VMUTE)
    {PIN_SF_OUT, PINMUX_FUNCTION1},
    //x_DMP_ERR
    {PIN_GPIO53, PINMUX_FUNCTION0},

    //AI I2S
    #if 0  // 4KBE use OPWM0/2/3 for stripping mode , so need to keep default function before VBO boot
    {PIN_GPIO60, PINMUX_FUNCTION8},
    {PIN_OPWM0, PINMUX_FUNCTION9},
    {PIN_OPWM1, PINMUX_FUNCTION9},
    {PIN_OPWM2, PINMUX_FUNCTION9},
    {PIN_AOSDATA1, PINMUX_FUNCTION8},   // AI data1 for resove
    #endif

    //AO I2S
    {PIN_AOBCK, PINMUX_FUNCTION1},
    {PIN_AOLRCK, PINMUX_FUNCTION1},
    {PIN_AOMCLK, PINMUX_FUNCTION1},
    {PIN_AOSDATA0, PINMUX_FUNCTION1},
    {PIN_AOSDATA2, PINMUX_FUNCTION1},
    {PIN_AOSDATA3, PINMUX_FUNCTION1},
    {PIN_AOSDATA4, PINMUX_FUNCTION1},

    //PDMIC
     {PIN_OPCTRL13, PINMUX_FUNCTION0},    //Mic power on
     {PIN_OPCTRL4, PINMUX_FUNCTION5},
     {PIN_OPCTRL6, PINMUX_FUNCTION5},
     {PIN_OPCTRL7, PINMUX_FUNCTION5},
     //{PIN_OPCTRL9, PINMUX_FUNCTION5}, // Only use one clk for both L/R data

    //spdif  and ARC
     {PIN_ASPDIF0, PINMUX_FUNCTION1},
     {PIN_ASPDIF1, PINMUX_FUNCTION2},

    {PIN_LAST_PINMUX, PINMUX_FUNCTION0}//always put last!
};

#endif /* MTK_FUNCNO_PIN_SETUP_H */

