/*-----------------------------------------------------------------------------
 * gpio-cxd4108.h
 *
 * a header file for gpio
 *
 * Copyright 2005,2006 Sony Corporation
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * 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 the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 *---------------------------------------------------------------------------*/
#ifndef __GPIO_CXD4108_H__
#define __GPIO_CXD4108_H__

/*[HEAD-START] (for "spec sheet generator")*/
/*=============================================================================
 * cxd4108 original infomation
 *
 *   cxd4108 special define here
 *
 *===========================================================================*/
/*-----------------------------------------------------------------------------
 * Port Number(ID) to GPIO function
 *---------------------------------------------------------------------------*/
/*-----[function]------[port number]-----------------------------------------*/
enum{
/*----[ GPIOsys ]----*/
    GPIO_0,	/* 0 */
    GPIO_1,
    GPIO_2,
    GPIO_3,
    GPIO_4,
    GPIO_5,
    GPIO_6,
    GPIO_7,
    GPIO_8,
    GPIO_9,
    GPIO_10,
    GPIO_11,
    GPIO_12,
    GPIO_13,
    GPIO_14,
    GPIO_15,
/*----[ GPIOeasy ]----*/
    GPIO0_0,	/* 16 */
    GPIO0_1,
    GPIO0_2,
    GPIO0_3,
    GPIO0_4,
    GPIO0_5,
    GPIO0_6,
    GPIO0_7,
    GPIO0_8,
    GPIO0_9,
    GPIO0_10,
    GPIO0_11,
    GPIO0_12,
    GPIO0_13,
    GPIO0_14,
    GPIO0_15,

    GPIO1_0,	/* 32 */
    GPIO1_1,
    GPIO1_2,
    GPIO1_3,
    GPIO1_4,
    GPIO1_5,
    GPIO1_6,
    GPIO1_7,
    GPIO1_8,
    GPIO1_9,
    GPIO1_10,
    GPIO1_11,
    GPIO1_12,
    GPIO1_13,
    GPIO1_14,
//    GPIO1_15,	/* not used */

    GPIO2_0,	/* 47 */
    GPIO2_1,
    GPIO2_2,
    GPIO2_3,
    GPIO2_4,
    GPIO2_5,
    GPIO2_6,
    GPIO2_7,
    GPIO2_8,
    GPIO2_9,
    GPIO2_10,
    GPIO2_11,
    GPIO2_12,
    GPIO2_13,
    GPIO2_14,
//    GPIO2_15,	/* not used */

    GPIO3_0,	/* 62 */
    GPIO3_1,
    GPIO3_2,
    GPIO3_3,
    GPIO3_4,
    GPIO3_5,
    GPIO3_6,
    GPIO3_7,
    GPIO3_8,
    GPIO3_9,
    GPIO3_10,
    GPIO3_11,
    GPIO3_12,
//    GPIO3_13,	/* not used */
//    GPIO3_14,	/* not used */
//    GPIO3_15,	/* not used */

    GPIO4_0,	/* 75 */
    GPIO4_1,
    GPIO4_2,
    GPIO4_3,
    GPIO4_4,
    GPIO4_5,
    GPIO4_6,
    GPIO4_7,
    GPIO4_8,
    GPIO4_9,
    GPIO4_10,
    GPIO4_11,
    GPIO4_12,
    GPIO4_13,
    GPIO4_14,
    GPIO4_15,

    GPIO5_0,	/* 91 */
    GPIO5_1,
    GPIO5_2,
    GPIO5_3,
    GPIO5_4,
    GPIO5_5,
    GPIO5_6,
    GPIO5_7,
    GPIO5_8,
    GPIO5_9,
    GPIO5_10,
    GPIO5_11,
    GPIO5_12,
    GPIO5_13,
//    GPIO5_14,	/* not used */
//    GPIO5_15,	/* not used */

    GPIOE_0,	/* 105 */
    GPIOE_1,
    GPIOE_2,
    GPIOE_3,
    GPIOE_4,
    GPIOE_5,
    GPIOE_6,
    GPIOE_7,
    GPIOE_8,
    GPIOE_9,
    GPIOE_10,
    GPIOE_11,
    GPIOE_12,
    GPIOE_13,
    GPIOE_14,
    GPIOE_15,
};

/*-----------------------------------------------------------------------------
 * MAX value
 *---------------------------------------------------------------------------*/
#define PORT_MAX	GPIOE_15	/* 120 */

/*-----------------------------------------------------------------------------
 * IO sel select.  common func define to arch depend function
 *---------------------------------------------------------------------------*/
/* GPIO0 sel */
#define GPIO_FUNC_TPU0			GPIO_FUNC_ARCH	/* 9 */
#define GPIO_FUNC_TPU1			(GPIO_FUNC_ARCH + 1)
#define GPIO_FUNC_TPU2			(GPIO_FUNC_ARCH + 2)
#define GPIO_FUNC_TPU3			(GPIO_FUNC_ARCH + 3)
#define GPIO_FUNC_UART0			(GPIO_FUNC_ARCH + 4)
#define GPIO_FUNC_UART1			(GPIO_FUNC_ARCH + 5)
#define GPIO_FUNC_I2C			(GPIO_FUNC_ARCH + 6)
/* GPIO1 sel */
#define GPIO_FUNC_SIO0			(GPIO_FUNC_ARCH + 7)
#define GPIO_FUNC_SIO1			(GPIO_FUNC_ARCH + 8)
#define GPIO_FUNC_SIO2			(GPIO_FUNC_ARCH + 9)
#define GPIO_FUNC_SIO3			(GPIO_FUNC_ARCH + 10)
#define GPIO_FUNC_SIR			(GPIO_FUNC_ARCH + 11)
#define GPIO_FUNC_USBVBUS		(GPIO_FUNC_ARCH + 12)
/* GPIO2 sel */
#define GPIO_FUNC_EMC			(GPIO_FUNC_ARCH + 13)
#define GPIO_FUNC_CAMPERI		(GPIO_FUNC_ARCH + 14)
/* GPIO3 sel */
#define GPIO_FUNC_ETC			(GPIO_FUNC_ARCH + 15)
#define GPIO_FUNC_AU			(GPIO_FUNC_ARCH + 16)
#define GPIO_FUNC_SA			(GPIO_FUNC_ARCH + 17)
/* GPIO4 sel */
#define GPIO_FUNC_BR3			(GPIO_FUNC_ARCH + 18)
#define GPIO_FUNC_TEST			(GPIO_FUNC_ARCH + 19)
/* GPIO5 sel */
#define GPIO_FUNC_MS			(GPIO_FUNC_ARCH + 20)
#define GPIO_FUNC_SD			(GPIO_FUNC_ARCH + 21)
/* All GPIO sel */
#define GPIO_FUNC_PERIHZ		(GPIO_FUNC_ARCH + 22)
#define GPIO_FUNC_PERIPU		(GPIO_FUNC_ARCH + 23)
#define GPIO_FUNC_PERIPD		(GPIO_FUNC_ARCH + 24)

/*-----------------------------------------------------------------[HEAD-END]*/

typedef struct{
    unsigned short dir;
    unsigned short rdata;
    unsigned short ints;
    unsigned short inthe;
    unsigned short intle;
    unsigned short intmask;
    unsigned short inen;
}RegGpioSys;

typedef struct{
    unsigned short dir;
    unsigned short rdata;
    unsigned short inen;
    unsigned short portsel;
}RegGpioEasy;

typedef struct{
    unsigned short drv2;
    unsigned short drv1;
    unsigned short resen;
    unsigned short pupd;
}RegGpioCtrl;

typedef struct{
    unsigned short misc3;
}RegGpioMisc;

typedef struct{
    RegGpioSys sys;
    RegGpioEasy easy[7];
    RegGpioCtrl ctrl[14];
    RegGpioMisc misc;
}RegGpio;

#endif /* __GPIO_CXD4108_H__ */
