/* 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.
 *
 *****************************************************************************/


/** @file pinmux.h
 *  pinmux.h declare all pinmux/gpio private related function and parameters.
 */

#ifndef X_PINMUX_H
#define X_PINMUX_H

//-----------------------------------------------------------------------------
// Include files
//-----------------------------------------------------------------------------

#include "x_lint.h"
#include "hw_ckgen.h"
#include "x_ckgen.h"
#include "x_gpio.h"

//=====================================================================
// IC information
#define TOTAL_PIN_REG           ( 27 )
#define CKGEN_PIN_REG           ( 17 )
#define GPIO_NUM(x)    ((x)<<16) 
 
//=====================================================================
// Register definitions
 
#define MX0	((1U << 5) | BASIC_MASK) //MX0
#define MX1	((2U << 5) | BASIC_MASK) //MX1
#define MX2	((3U << 5) | BASIC_MASK) //MX2
#define MX3	((4U << 5) | BASIC_MASK) //MX3
#define MX4	((5U << 5) | BASIC_MASK) //MX4
#define MX5	((6U << 5) | BASIC_MASK) //MX5
#define MX6	((7U << 5) | BASIC_MASK) //MX6
#define MX7	((8U << 5) | BASIC_MASK) //MX7
#define MX8	((9U << 5) | BASIC_MASK) //MX8
#define MX9	((10U << 5) | BASIC_MASK) //MX9
#define MX10	((11U << 5) | BASIC_MASK) //MX10
#define MX11	((12U << 5) | BASIC_MASK) //MX11
#define MX12	((13U << 5) | BASIC_MASK) //MX12
#define MX13	((14U << 5) | BASIC_MASK) //MX13
#define MX14	((15U << 5) | BASIC_MASK) //MX14
#define MX15	((16U << 5) | BASIC_MASK) //MX15
#define MX16	((17U << 5) | BASIC_MASK) //MX16
#define PDMX0	((18U << 5) | BASIC_MASK) //PDMX0
#define PDMX1	((19U << 5) | BASIC_MASK) //PDMX1
#define PDMX2	((20U << 5) | BASIC_MASK) //PDMX2
#define PDMX3	((21U << 5) | BASIC_MASK) //PDMX3
#define PDMX4	((22U << 5) | BASIC_MASK) //PDMX4
#define PDMX5	((23U << 5) | BASIC_MASK) //PDMX5
#define PDMX6	((24U << 5) | BASIC_MASK) //PDMX6
#define PDMX7	((25U << 5) | BASIC_MASK) //PDMX7
#define PDMX8	((26U << 5) | BASIC_MASK) //PDMX8
#define PMISC         MX6
#define PIN_NOPINMUX        ( PMISC | 31)
#define PIN_LAST_PINMUX      PIN_NOPINMUX 

#define PIN_ADIN9   (GPIO_NUM(264)|PDMX7|OFFSETMASK(3,0))
#define PIN_ADIN8   (GPIO_NUM(263)|PDMX7|OFFSETMASK(7,4))
#define PIN_ADIN7   (GPIO_NUM(262)|PDMX7|OFFSETMASK(11,8))
#define PIN_ADIN6   (GPIO_NUM(261)|PDMX7|OFFSETMASK(15,12))
#define PIN_ADIN5   (GPIO_NUM(260)|PDMX7|OFFSETMASK(19,16))
#define PIN_ADIN4   (GPIO_NUM(259)|PDMX7|OFFSETMASK(23,20))
#define PIN_ADIN3   (GPIO_NUM(258)|PDMX7|OFFSETMASK(27,24))
#define PIN_ADIN2   (GPIO_NUM(257)|PDMX7|OFFSETMASK(31,28))
#define PIN_ADIN1   (GPIO_NUM(256)|PDMX8|OFFSETMASK(3,0))
#define PIN_HDMI_1_HPD   (GPIO_NUM(255)|PDMX6|OFFSETMASK(31,28))
#define PIN_HDMI_1_SCL   (GPIO_NUM(254)|PDMX6|OFFSETMASK(27,24))
#define PIN_HDMI_1_SDA   (GPIO_NUM(253)|PDMX6|OFFSETMASK(23,20))
#define PIN_HDMI_1_PWR5V   (GPIO_NUM(252)|PDMX6|OFFSETMASK(19,16))
#define PIN_HDMI_3_PWR5V   (GPIO_NUM(251)|PDMX6|OFFSETMASK(15,12))
#define PIN_HDMI_0_HPD   (GPIO_NUM(250)|PDMX6|OFFSETMASK(11,8))
#define PIN_HDMI_0_PWR5V   (GPIO_NUM(249)|PDMX6|OFFSETMASK(7,4))
#define PIN_HDMI_CEC   (GPIO_NUM(248)|PDMX6|OFFSETMASK(3,0))
#define PIN_HDMI_CEC_1   (PDMX6|OFFSETMASK(3,0))
#define PIN_HDMI_0_SCL   (GPIO_NUM(247)|PDMX5|OFFSETMASK(31,28))
#define PIN_HDMI_0_SDA   (GPIO_NUM(246)|PDMX5|OFFSETMASK(27,24))
#define PIN_HDMI_3_SCL   (GPIO_NUM(245)|PDMX5|OFFSETMASK(23,20))
#define PIN_HDMI_3_SDA   (GPIO_NUM(244)|PDMX5|OFFSETMASK(19,16))
#define PIN_HDMI_3_HPD   (GPIO_NUM(243)|PDMX5|OFFSETMASK(15,12))
#define PIN_HDMI_2_SCL   (GPIO_NUM(242)|PDMX5|OFFSETMASK(11,8))
#define PIN_HDMI_2_SDA   (GPIO_NUM(241)|PDMX5|OFFSETMASK(7,4))
#define PIN_HDMI_2_PWR5V   (GPIO_NUM(240)|PDMX5|OFFSETMASK(3,0))
#define PIN_HDMI_2_HPD   (GPIO_NUM(239)|PDMX4|OFFSETMASK(31,28))
#define PIN_PHYLED1   (GPIO_NUM(238)|PDMX4|OFFSETMASK(27,24))
#define PIN_PHYLED0   (GPIO_NUM(237)|PDMX4|OFFSETMASK(23,20))
#define PIN_LED_PWM3   (GPIO_NUM(236)|PDMX4|OFFSETMASK(19,16))
#define PIN_LED_PWM2   (GPIO_NUM(235)|PDMX4|OFFSETMASK(15,12))
#define PIN_LED_PWM1   (GPIO_NUM(234)|PDMX4|OFFSETMASK(11,8))
#define PIN_LED_PWM0   (GPIO_NUM(233)|PDMX4|OFFSETMASK(7,4))
#define PIN_OIRI   (GPIO_NUM(232)|PDMX4|OFFSETMASK(3,0))
#define PIN_OPWRSB   (GPIO_NUM(231)|PDMX3|OFFSETMASK(31,28))
#define PIN_U0RX   (GPIO_NUM(230)|PDMX3|OFFSETMASK(27,24))
#define PIN_U0TX   (GPIO_NUM(229)|PDMX3|OFFSETMASK(23,20))
#define PIN_STB_SCL   (GPIO_NUM(228)|PDMX3|OFFSETMASK(19,16))
#define PIN_STB_SDA   (GPIO_NUM(227)|PDMX3|OFFSETMASK(15,12))
#define PIN_VGA_SCL   (GPIO_NUM(226)|PDMX3|OFFSETMASK(11,8))
#define PIN_VGA_SDA   (GPIO_NUM(225)|PDMX3|OFFSETMASK(7,4))
#define PIN_OPCTRL24   (GPIO_NUM(224)|PDMX3|OFFSETMASK(3,0))
#define PIN_OPCTRL23   (GPIO_NUM(223)|PDMX2|OFFSETMASK(31,28))
#define PIN_OPCTRL22   (GPIO_NUM(222)|PDMX2|OFFSETMASK(27,24))
#define PIN_OPCTRL21   (GPIO_NUM(221)|PDMX2|OFFSETMASK(23,20))
#define PIN_OPCTRL20   (GPIO_NUM(220)|PDMX2|OFFSETMASK(19,16))
#define PIN_OPCTRL19   (GPIO_NUM(219)|PDMX2|OFFSETMASK(15,12))
#define PIN_OPCTRL18   (GPIO_NUM(218)|PDMX2|OFFSETMASK(11,8))
#define PIN_OPCTRL17   (GPIO_NUM(217)|PDMX2|OFFSETMASK(7,4))
#define PIN_OPCTRL16   (GPIO_NUM(216)|PDMX2|OFFSETMASK(3,0))
#define PIN_OPCTRL15   (GPIO_NUM(215)|PDMX1|OFFSETMASK(31,28))
#define PIN_OPCTRL14   (GPIO_NUM(214)|PDMX1|OFFSETMASK(27,24))
#define PIN_OPCTRL13   (GPIO_NUM(213)|PDMX1|OFFSETMASK(23,20))
#define PIN_OPCTRL12   (GPIO_NUM(212)|PDMX1|OFFSETMASK(19,16))
#define PIN_OPCTRL11   (GPIO_NUM(211)|PDMX1|OFFSETMASK(15,12))
#define PIN_OPCTRL10   (GPIO_NUM(210)|PDMX1|OFFSETMASK(11,8))
#define PIN_OPCTRL9   (GPIO_NUM(209)|PDMX1|OFFSETMASK(7,4))
#define PIN_OPCTRL8   (GPIO_NUM(208)|PDMX1|OFFSETMASK(3,0))
#define PIN_OPCTRL7   (GPIO_NUM(207)|PDMX0|OFFSETMASK(31,28))
#define PIN_OPCTRL6   (GPIO_NUM(206)|PDMX0|OFFSETMASK(27,24))
#define PIN_OPCTRL5   (GPIO_NUM(205)|PDMX0|OFFSETMASK(23,20))
#define PIN_OPCTRL4   (GPIO_NUM(204)|PDMX0|OFFSETMASK(19,16))
#define PIN_OPCTRL3   (GPIO_NUM(203)|PDMX0|OFFSETMASK(15,12))
#define PIN_OPCTRL2   (GPIO_NUM(202)|PDMX0|OFFSETMASK(11,8))
#define PIN_OPCTRL1   (GPIO_NUM(201)|PDMX0|OFFSETMASK(7,4))
#define PIN_OPCTRL0   (GPIO_NUM(200)|PDMX0|OFFSETMASK(3,0))
#define PIN_MCUSYS_AGPIO   (GPIO_NUM(126)|MX16|0)
#define PIN_USB_DP_P3   (GPIO_NUM(125)|MX1|OFFSETMASK(31,28))
#define PIN_USB_DM_P3   (GPIO_NUM(124)|MX1|OFFSETMASK(27,24))
#define PIN_USB_DP_P2   (GPIO_NUM(123)|MX1|OFFSETMASK(23,20))
#define PIN_USB_DM_P2   (GPIO_NUM(122)|MX1|OFFSETMASK(19,16))
#define PIN_USB_DP_P1   (GPIO_NUM(121)|MX1|OFFSETMASK(15,12))
#define PIN_USB_DM_P1   (GPIO_NUM(120)|MX1|OFFSETMASK(11,8))
#define PIN_USB_DP_P0   (GPIO_NUM(119)|MX1|OFFSETMASK(7,4))
#define PIN_USB_DM_P0   (GPIO_NUM(118)|MX1|OFFSETMASK(3,0))
#define PIN_SD_D3   (GPIO_NUM(117)|MX0|OFFSETMASK(23,20)| MULTI_GPIO_FLAG)
#define PIN_SD_D2   (GPIO_NUM(116)|MX0|OFFSETMASK(19,16))
#define PIN_SD_D1   (GPIO_NUM(115)|MX0|OFFSETMASK(15,12))
#define PIN_SD_D0   (GPIO_NUM(114)|MX0|OFFSETMASK(11,8))
#define PIN_SD_CLK   (GPIO_NUM(113)|MX0|OFFSETMASK(7,4))
#define PIN_SD_CMD   (GPIO_NUM(112)|MX0|OFFSETMASK(3,0))
#define PIN_ALIN   (GPIO_NUM(111)|MX4|OFFSETMASK(11,8))
#define PIN_EMMC_D7   (GPIO_NUM(110)|MX15|OFFSETMASK(31,28))
#define PIN_EMMC_D6   (GPIO_NUM(109)|MX15|OFFSETMASK(27,24))
#define PIN_EMMC_D5   (GPIO_NUM(108)|MX15|OFFSETMASK(23,20))
#define PIN_EMMC_D4   (GPIO_NUM(107)|MX15|OFFSETMASK(19,16))
#define PIN_EMMC_D3   (GPIO_NUM(106)|MX15|OFFSETMASK(15,12))
#define PIN_EMMC_D2   (GPIO_NUM(105)|MX15|OFFSETMASK(11,8))
#define PIN_EMMC_D1   (GPIO_NUM(104)|MX15|OFFSETMASK(7,4))
#define PIN_EMMC_D0   (GPIO_NUM(103)|MX15|OFFSETMASK(3,0))
#define PIN_EMMC_CMD   (GPIO_NUM(102)|MX14|OFFSETMASK(31,28))
#define PIN_EMMC_DS   (GPIO_NUM(101)|MX14|OFFSETMASK(27,24))
#define PIN_EMMC_CLK   (GPIO_NUM(100)|MX14|OFFSETMASK(23,20))
#define PIN_EMMC_RST   (GPIO_NUM(99)|MX14|OFFSETMASK(19,16))
#define PIN_DEMOD_TSDATA7   (GPIO_NUM(98)|MX14|OFFSETMASK(15,12))
#define PIN_DEMOD_TSDATA6   (GPIO_NUM(97)|MX14|OFFSETMASK(11,8))
#define PIN_DEMOD_TSDATA5   (GPIO_NUM(96)|MX14|OFFSETMASK(7,4))
#define PIN_DEMOD_TSDATA4   (GPIO_NUM(95)|MX14|OFFSETMASK(3,0))
#define PIN_DEMOD_TSDATA3   (GPIO_NUM(94)|MX13|OFFSETMASK(31,28))
#define PIN_DEMOD_TSDATA2   (GPIO_NUM(93)|MX13|OFFSETMASK(27,24))
#define PIN_DEMOD_TSDATA1   (GPIO_NUM(92)|MX13|OFFSETMASK(23,20))
#define PIN_DEMOD_TSDATA0   (GPIO_NUM(91)|MX13|OFFSETMASK(19,16))
#define PIN_DEMOD_TSSYNC   (GPIO_NUM(90)|MX13|OFFSETMASK(15,12))
#define PIN_DEMOD_TSVAL   (GPIO_NUM(89)|MX13|OFFSETMASK(11,8))
#define PIN_DEMOD_TSCLK   (GPIO_NUM(88)|MX13|OFFSETMASK(7,4))
#define PIN_IF_AGC_S   (GPIO_NUM(87)|MX13|OFFSETMASK(3,0)| MULTI_GPIO_FLAG)
#define PIN_ASPDIF1   (GPIO_NUM(86)|MX12|OFFSETMASK(31,28)| MULTI_GPIO_FLAG)
#define PIN_DEMOD_RST   (GPIO_NUM(85)|MX12|OFFSETMASK(27,24)| MULTI_GPIO_FLAG)
#define PIN_OSCL2   (GPIO_NUM(84)|MX12|OFFSETMASK(19,16))
#define PIN_OSDA2   (GPIO_NUM(83)|MX12|OFFSETMASK(15,12))
#define PIN_U1TX   (GPIO_NUM(82)|MX7|OFFSETMASK(3,0))
#define PIN_U1RX   (GPIO_NUM(81)|MX6|OFFSETMASK(31,28))
#define PIN_SF_OUT   (GPIO_NUM(80)|MX6|OFFSETMASK(27,24))
#define PIN_SF_IN   (GPIO_NUM(79)|MX6|OFFSETMASK(23,20))
#define PIN_SF_CLK   (GPIO_NUM(78)|MX6|OFFSETMASK(19,16))
#define PIN_SF_CE   (GPIO_NUM(77)|MX6|OFFSETMASK(15,12))
#define PIN_OSCL1   (GPIO_NUM(76)|MX6|OFFSETMASK(11,8))
#define PIN_OSDA1   (GPIO_NUM(75)|MX6|OFFSETMASK(7,4))
#define PIN_OSCL0   (GPIO_NUM(74)|MX6|OFFSETMASK(3,0))
#define PIN_OSDA0   (GPIO_NUM(73)|MX5|OFFSETMASK(31,28))
#define PIN_GPIO72   (GPIO_NUM(72)|MX4|OFFSETMASK(7,4)| MULTI_GPIO_FLAG)
#define PIN_GPIO71   (GPIO_NUM(71)|MX4|OFFSETMASK(3,0)| MULTI_GPIO_FLAG)
#define PIN_GPIO70   (GPIO_NUM(70)|MX3|OFFSETMASK(31,28)| MULTI_GPIO_FLAG)
#define PIN_GPIO69   (GPIO_NUM(69)|MX3|OFFSETMASK(27,24))
#define PIN_GPIO68   (GPIO_NUM(68)|MX3|OFFSETMASK(23,20))
#define PIN_GPIO67   (GPIO_NUM(67)|MX3|OFFSETMASK(19,16))
#define PIN_GPIO66   (GPIO_NUM(66)|MX12|OFFSETMASK(11,8))
#define PIN_GPIO65   (GPIO_NUM(65)|MX12|OFFSETMASK(7,4)| MULTI_GPIO_FLAG)
#define PIN_GPIO64   (GPIO_NUM(64)|MX12|OFFSETMASK(3,0))
#define PIN_GPIO63   (GPIO_NUM(63)|MX11|OFFSETMASK(31,28))
#define PIN_GPIO62   (GPIO_NUM(62)|MX11|OFFSETMASK(27,24))
#define PIN_GPIO61   (GPIO_NUM(61)|MX11|OFFSETMASK(23,20)| MULTI_GPIO_FLAG)
#define PIN_GPIO60   (GPIO_NUM(60)|MX3|OFFSETMASK(15,12))
#define PIN_GPIO59   (GPIO_NUM(59)|MX3|OFFSETMASK(11,8))
#define PIN_GPIO58   (GPIO_NUM(58)|MX3|OFFSETMASK(7,4))
#define PIN_GPIO57   (GPIO_NUM(57)|MX3|OFFSETMASK(3,0))
#define PIN_GPIO56   (GPIO_NUM(56)|MX2|OFFSETMASK(31,28))
#define PIN_GPIO55   (GPIO_NUM(55)|MX2|OFFSETMASK(27,24)| MULTI_GPIO_FLAG)
#define PIN_GPIO54   (GPIO_NUM(54)|MX2|OFFSETMASK(23,20)| MULTI_GPIO_FLAG)
#define PIN_GPIO53   (GPIO_NUM(53)|MX2|OFFSETMASK(19,16))
#define PIN_GPIO52   (GPIO_NUM(52)|MX2|OFFSETMASK(15,12))
#define PIN_GPIO51   (GPIO_NUM(51)|MX2|OFFSETMASK(11,8)| MULTI_GPIO_FLAG)
#define PIN_GPIO50   (GPIO_NUM(50)|MX2|OFFSETMASK(7,4))
#define PIN_GPIO49   (GPIO_NUM(49)|MX2|OFFSETMASK(3,0))
#define PIN_GPIO48   (GPIO_NUM(48)|MX11|OFFSETMASK(19,16))
#define PIN_IF_AGC   (GPIO_NUM(47)|MX12|OFFSETMASK(23,20)| MULTI_GPIO_FLAG)
#define PIN_GPIO46   (GPIO_NUM(46)|MX11|OFFSETMASK(15,12)| MULTI_GPIO_FLAG)
#define PIN_GPIO45   (GPIO_NUM(45)|MX11|OFFSETMASK(11,8)| MULTI_GPIO_FLAG)
#define PIN_GPIO44   (GPIO_NUM(44)|MX11|OFFSETMASK(7,4))
#define PIN_GPIO43   (GPIO_NUM(43)|MX11|OFFSETMASK(3,0)| MULTI_GPIO_FLAG)
#define PIN_GPIO42   (GPIO_NUM(42)|MX10|OFFSETMASK(31,28))
#define PIN_CI_RESET   (GPIO_NUM(41)|MX10|OFFSETMASK(27,24)| MULTI_GPIO_FLAG)
#define PIN_CIL_RX1_D1   (GPIO_NUM(40)|MX10|OFFSETMASK(23,20))
#define PIN_CIL_RX1_D0   (GPIO_NUM(39)|MX10|OFFSETMASK(19,16))
#define PIN_CIL_TX1_D1   (GPIO_NUM(38)|MX10|OFFSETMASK(15,12))
#define PIN_CIL_TX1_D0   (GPIO_NUM(37)|MX10|OFFSETMASK(11,8))
#define PIN_CIL_DEMOD1_CLK   (GPIO_NUM(36)|MX10|OFFSETMASK(7,4))
#define PIN_CIL_RX0_D1   (GPIO_NUM(35)|MX10|OFFSETMASK(3,0)| MULTI_GPIO_FLAG)
#define PIN_CIL_RX0_D0   (GPIO_NUM(34)|MX9|OFFSETMASK(31,28)| MULTI_GPIO_FLAG)
#define PIN_CIL_RX_CLK   (GPIO_NUM(33)|MX9|OFFSETMASK(27,24))
#define PIN_CIL_TX0_D1   (GPIO_NUM(32)|MX9|OFFSETMASK(23,20))
#define PIN_CIL_TX0_D0   (GPIO_NUM(31)|MX9|OFFSETMASK(19,16))
#define PIN_CIL_TX_CLK   (GPIO_NUM(30)|MX9|OFFSETMASK(15,12))
#define PIN_CIL_DEMOD0_CLK   (GPIO_NUM(29)|MX9|OFFSETMASK(11,8)| MULTI_GPIO_FLAG)
#define PIN_INT   (GPIO_NUM(28)|MX9|OFFSETMASK(7,4))
#define PIN_SPI_CS   (GPIO_NUM(27)|MX9|OFFSETMASK(3,0))
#define PIN_SPI_DO   (GPIO_NUM(26)|MX8|OFFSETMASK(31,28))
#define PIN_SPI_DI   (GPIO_NUM(25)|MX8|OFFSETMASK(27,24))
#define PIN_SPI_CLK   (GPIO_NUM(24)|MX8|OFFSETMASK(23,20))
#define PIN_OPWM2   (GPIO_NUM(23)|MX5|OFFSETMASK(27,24))
#define PIN_OPWM1   (GPIO_NUM(22)|MX5|OFFSETMASK(23,20)| MULTI_GPIO_FLAG)
#define PIN_OPWM0   (GPIO_NUM(21)|MX5|OFFSETMASK(19,16)| MULTI_GPIO_FLAG)
#define PIN_AOSDATA4   (GPIO_NUM(20)|MX5|OFFSETMASK(15,12)| MULTI_GPIO_FLAG)
#define PIN_AOSDATA3   (GPIO_NUM(19)|MX5|OFFSETMASK(11,8)| MULTI_GPIO_FLAG)
#define PIN_AOSDATA2   (GPIO_NUM(18)|MX5|OFFSETMASK(7,4)| MULTI_GPIO_FLAG)
#define PIN_AOSDATA1   (GPIO_NUM(17)|MX5|OFFSETMASK(3,0)| MULTI_GPIO_FLAG)
#define PIN_AOSDATA0   (GPIO_NUM(16)|MX4|OFFSETMASK(31,28)| MULTI_GPIO_FLAG)
#define PIN_AOBCK   (GPIO_NUM(15)|MX4|OFFSETMASK(27,24)| MULTI_GPIO_FLAG)
#define PIN_AOLRCK   (GPIO_NUM(14)|MX4|OFFSETMASK(23,20)| MULTI_GPIO_FLAG)
#define PIN_AOMCLK   (GPIO_NUM(13)|MX4|OFFSETMASK(19,16))
#define PIN_ASPDIF0   (GPIO_NUM(12)|MX4|OFFSETMASK(15,12))
#define PIN_TUNER_FREEZE_SEQ   (GPIO_NUM(11)|MX8|OFFSETMASK(19,16))
#define PIN_DISEQC_IN_DIG   (GPIO_NUM(10)|MX8|OFFSETMASK(15,12))
#define PIN_DISEQC_OUT_DIG   (GPIO_NUM(9)|MX8|OFFSETMASK(11,8))
#define PIN_GPIO8   (GPIO_NUM(8)|MX8|OFFSETMASK(7,4)| MULTI_GPIO_FLAG)
#define PIN_GPIO7   (GPIO_NUM(7)|MX7|OFFSETMASK(19,16))
#define PIN_GPIO6   (GPIO_NUM(6)|MX7|OFFSETMASK(15,12))
#define PIN_GPIO5   (GPIO_NUM(5)|MX7|OFFSETMASK(11,8))
#define PIN_GPIO4   (GPIO_NUM(4)|MX7|OFFSETMASK(7,4))
#define PIN_GPIO3   (GPIO_NUM(3)|MX8|OFFSETMASK(3,0))
#define PIN_GPIO2   (GPIO_NUM(2)|MX7|OFFSETMASK(31,28))
#define PIN_GPIO1   (GPIO_NUM(1)|MX7|OFFSETMASK(27,24))
#define PIN_GPIO0   (GPIO_NUM(0)|MX7|OFFSETMASK(23,20))
//-----------------------------------------------------------------------
//Macro defintions (IC independant)
//-----------------------------------------------------------------------
#define PINMUX_FUNCTION0         0
#define PINMUX_FUNCTION1         1
#define PINMUX_FUNCTION2         2
#define PINMUX_FUNCTION3         3
#define PINMUX_FUNCTION4         4
#define PINMUX_FUNCTION5         5
#define PINMUX_FUNCTION6         6
#define PINMUX_FUNCTION7         7
#define PINMUX_FUNCTION8         8
#define PINMUX_FUNCTION9         9
#define PINMUX_FUNCTION10         10
#define NO_GPIO_FUNCTION         11
#define IS_VALID_MUX_REG(pin)   (((pin) & (0x1fU << 5)) != 0)
#define OFFSETMASK(ebit, sbit)  ((BITNUM_TO_MASK((ebit) - (sbit)) << 12) | (sbit))
#define MUXHIB(x)               ((x) << 16)
#define MAX_FUNC(pin)           (LO_MAX_FUNC(pin) | (HI_MAX_FUNC(pin) << (MASK_TO_BITNUM(LO_MAX_FUNC(pin))+1)))
#define BITNUM_TO_MASK(m)       (((m) > 1) ? (((m)==2) ? 7 : 15) : (((m)==1) ? 3 : 1))
#define MASK_TO_BITNUM(m)       (((m) > 3) ? (((m)==7) ? 2 : 3) : (((m)==1) ? 0 : 1))
#define MULTI_GPIO_FLAG         (1U << 10)
#define BASIC_MASK              (1U << 12)
 
#define LO_BIT_OFFSET(pin)      ((pin >> 0) & 0x1fU)
#define LO_MUX_REG(pin)         (((pin) >> 5) & 0x1fU)
#define LO_MAX_FUNC(pin)        (((pin) >> 12) & 0x0fU)
#define LO_MASK(pin)            (LO_MAX_FUNC(pin))
#define HI_BIT_OFFSET(pin)      (((pin) >> 16) & 0x1fU)
#define HI_MUX_REG(pin)         (((pin) >> 21) & 0x0fU)
#define HI_MAX_FUNC(pin)        (((pin) >> 28) & 0x0fU)
#define HI_MASK(pin)            (HI_MAX_FUNC(pin))


 

//-----------------------------------------------------------------------------
// Public function declaration
//-----------------------------------------------------------------------------

/* Pinmux function. */
extern INT32 BSP_PinSet(UINT32 u4PinSel, INT32 i4Func);
extern INT32 BSP_PinGet(UINT32 u4PinSel);
extern INT32 BSP_PinGpioSel(INT32 i4Gpio);
extern INT32 BSP_PinGpioGet(INT32 i4Gpio, UINT32 *pu4PinSel);

#endif
