/****************************************************************************
 *
 *
 * Copyright (C) Jungo LTD 2004
 *
 * 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., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA.
 *
 * Developed by Jungo LTD.
 * Residential Gateway Software Division
 * www.jungo.com
 * info@jungo.com
 */

#ifndef GPIO_LED_BTN_H
#define GPIO_LED_BTN_H 1

#define CARDID_LBV2ULT  (1<<8)
#define CARDID_FTTHV2   (2<<8)
#define CARDID_LIVEBOX2 (3<<8)

/* This file is the public interface of the gpio_led_btn driver for Livebox 2
   plateform based on VOX160 processor.
*/

/* List of the hardware plugged on the GPIO pins */
/* The buttons are wired active low, BUT the POLARITY register is used to make
 * them active high, so no need to invert them in software .
 */
typedef enum {
#ifdef CONFIG_SAGEM_GENERIC_CARD_SUPPORT
  /* Liste de tous les GPIOS existants pour les box generiques*/
  GPIO_0_UNUSED,		/* Unused					*/
  GPIO_RST_Z_N,			/* FXS/FXO reset			*/
  GPIO_SPI_CS_Z_N,		/* FXS SPI Chip Select		*/
  GPIO_SPI_CS_FXO_N,	/* FXO Chip Select			*/
  GPIO_CONFIG_0,		/* Config Bit 1				*/
  GPIO_CONFIG_1,		/* Config Bit 2				*/
  GPIO_CONFIG_2,		/* Config Bit 3				*/
  GPIO_LED_WIRLS,		/* Led Wireless				*/
  GPIO_LED_PHONE,		/* Led Phone 				*/
  GPIO_LED_LAN,			/* Led Lan					*/
  GPIO_LED_ON,			/* Led Power				*/
  GPIO_LED_DWNLD,		/* Led Upgrade				*/
  GPIO_LED_WAN_RED,		/* Led Wan Red				*/
  GPIO_LED_WAN_GRN,		/* Led Wan Green			*/
  GPIO_CMD_NL,			/* Load CLIP Command		*/
  GPIO_FXS_EXT_LINE1,	/* Line 1 relay				*/
  GPIO_FXS_EXT_LINE2,	/* Line 2 relay				*/
  GPIO_USBH_PWR_EN,		/* USB Host Power enable	*/
  GPIO_USBH2_PWR_EN,	/* USB Host 2 Power enable	*/
  GPIO_AFE_RST_N,
  GPIO_SUR_I_VUSBH,		/* USB overcurent			*/
  GPIO_MII_DEDICATED1,	/* Dedicated MII2 interface	*/
  GPIO_MII_DEDICATED2,	/* Dedicated MII2 interface */
  GPIO_MII_DEDICATED3,	/* Dedicated MII2 interface */
  GPIO_MII_DEDICATED4,	/* Dedicated MII2 interface */
  GPIO_DYING_GASP_N,	/* Dying Gasp				*/
  GPIO_ASSOC_WIFI_N,	/* Button association wifi	*/
  GPIO_RST_CONFIG_N,	/* Button Default Config	*/
  GPIO_RST_LAN_N,
  GPIO_CMD_POWER_OFF,	/* Command Power Off		*/
  GPIO_POWER_OFF_N,
  GPIO_USB_HUB_RST,		/* Hub USB reset			*/

  #ifdef CONFIG_SAGEM_LBV2ULT
  GPIO_BAD_POS_N,		/* Bad Position detect		*/
  GPIO_HDD_CONNECTED,	/* Hdd detection			*/
  GPIO_ALT_WINFIN_INT,
  GPIO_CP_USB_HDD,		/* Button copy usb to disk	*/
  GPIO_LED_HDD,			/* Led Hdd Activity			*/
  #endif

  GPIO_LAST,
  /* GPIO FLAG 1 */
  /* GPIO FLAG 2 */

  /* Definition d' "alias" pour certains GPIO */
  GPIO_LED_ADSL			= GPIO_LED_WAN_GRN,	   /* GPIO27 */
  GPIO_LED_ADSL_RED 	= GPIO_LED_WAN_RED,	   /* GPIO10 */
 #if defined(CONFIG_SAGEM_BOXER) || defined(CONFIG_SAGEM_FTTHV2)
  GPIO_LED_WAN          = GPIO_LAST,
  GPIO_LED_WIFI         = GPIO_LED_WIRLS,
  GPIO_FXS_EXT_LINE2_N  = GPIO_FXS_EXT_LINE2,
  GPIO_FXS_EXT_LINE_N   = GPIO_FXS_EXT_LINE1,
  GPIO_LEDS_CONFIG      = GPIO_LAST,
 #endif

 #ifdef CONFIG_SAGEM_LBV2ULT
  GPIO_LED_WAN			= GPIO_LED_ADSL_RED,
  GPIO_CMD_REBOOT_N		= GPIO_POWER_OFF_N,
  GPIO_CMD_RESET_N		= GPIO_RST_CONFIG_N,
  GPIO_SHUTDOWN_BOX     = GPIO_CMD_POWER_OFF,
 #endif

#else // CONFIG_SAGEM_GENERIC_CARD_SUPPORT

#ifdef CONFIG_SAGEM_FAST34XX
  /* GPIO FLAG 1 */
  GPIO_SPI_DECT_INT = 0,       /* GPIO0  */
  GPIO_SPI_CS_Z_N,             /* GPIO1  */
  GPIO_SPI_CS_FXO_N,           /* GPIO2  */
  GPIO_DECT_RXD,               /* GPIO3  */
  GPIO_TXD,                    /* GPIO4  */
  GPIO_SPI_DECT_CS,            /* GPIO5  */
  GPIO_CTS_R,                  /* GPIO6  */
  GPIO_CB_DETECT,              /* GPIO7  */
  GPIO_CMD_NL,                 /* GPIO8  */
  GPIO_LEDS_CONFIG,            /* GPIO9  */
  GPIO_RST_Z_N,                /* GPIO10 */
  GPIO_RST_LAN_N,              /* GPIO11 */
  GPIO_USB_EN,                 /* GPIO12 */
  GPIO_USB_PWRDET,             /* GPIO13 */
  GPIO_FXS_EXT_LINE2_N,        /* GPIO14 */
  GPIO_RESET_DECT,             /* GPIO15 */
  /* GPIO FLAG 2 */
  GPIO_USBH_PWR_EN,            /* GPIO16 */
  GPIO_SUR_I_VUSBH,            /* GPIO17 */
  GPIO_CB_FRAME_EN,            /* GPIO18 */
  GPIO_FXS_EXT_LINE_N,         /* GPIO19 */
  GPIO_MII_DEDICATED1,         /* GPIO20 */
  GPIO_MII_DEDICATED2,         /* GPIO21 */
  GPIO_MII_DEDICATED3,         /* GPIO22 */
  GPIO_MII_DEDICATED4,         /* GPIO23 */
  GPIO_RST_CONFIG_N,           /* GPIO24 */
  GPIO_DYING_GASP_N,           /* GPIO25 */
  GPIO_ASSOC_WIFI_N,           /* GPIO26 */
  GPIO_LED_DATA,               /* GPIO27 */
  GPIO_LED_ADSL,               /* GPIO28 */
  GPIO_LED_PHONE,              /* GPIO29 */
  GPIO_LED_WIFI,               /* GPIO30 */
  GPIO_LED_ALARM,              /* GPIO31 */
  GPIO_LAST,				   /* GPIO32 */

  GPIO_LED_WAN_GRN    		= GPIO_LED_ADSL,
  GPIO_LED_WAN              = GPIO_LED_ADSL,
  GPIO_LED_ON         		= GPIO_LED_DATA,
  GPIO_LED_LAN              = GPIO_LED_DATA,
  GPIO_LED_WIRLS      		= GPIO_LED_WIFI,
  GPIO_LED_DWNLD      		= GPIO_LED_ALARM,
  GPIO_FXS_EXT_LINE2  		= GPIO_FXS_EXT_LINE2_N,
  GPIO_FXS_EXT_LINE1  		= GPIO_FXS_EXT_LINE_N,

  GPIO_PLACEBO          	= GPIO_LAST-1,
#endif

#if ( defined(CONFIG_SAGEM_BOXER) && ! defined(CONFIG_SAGEM_GPIO_ULT_FOR_BOXER_FW) ) || ( defined(CONFIG_SAGEM_LBV2ULT) && defined(CONFIG_SAGEM_GPIO_BOXER_FOR_ULT_FW) )
  /* GPIO FLAG 1 */
  GPIO_NOT_USED_0 = 0,         /* GPIO0  */
  GPIO_SPI_CS_Z_N,             /* GPIO1  */
  GPIO_SPI_CS_FXO_N,           /* GPIO2  */
  GPIO_RST_Z_N,                /* GPIO3  */
  GPIO_CONFIG_0,               /* GPIO4  */
  GPIO_CONFIG_1,               /* GPIO5  */
  GPIO_CONFIG_2,               /* GPIO6  */
  GPIO_LED_WIRLS,			   /* GPIO7  */
  GPIO_LED_PHONE,			   /* GPIO8  */
  GPIO_LED_LAN,				   /* GPIO9  */
  GPIO_LED_ADSL_RED,		   /* GPIO10 */
  GPIO_LED_ON,				   /* GPIO11 */
  GPIO_NOT_USED_1,             /* GPIO12 */
  GPIO_CMD_NL,                 /* GPIO13 */
  GPIO_FXS_EXT_LINE2,		   /* GPIO14 */
  GPIO_USBH_PWR_EN,            /* GPIO15 */
  /* GPIO FLAG 2 */
  GPIO_AFE_RST_N,              /* GPIO16 */
  GPIO_SUR_I_VUSBH,            /* GPIO17 */
  GPIO_NOT_USED_2,             /* GPIO18 */
  GPIO_FXS_EXT_LINE1,		   /* GPIO19 */
  GPIO_MII_DEDICATED1,         /* GPIO20 */
  GPIO_MII_DEDICATED2,         /* GPIO21 */
  GPIO_MII_DEDICATED3,         /* GPIO22 */
  GPIO_MII_DEDICATED4,         /* GPIO23 */
  GPIO_RST_CONFIG_N,		   /* GPIO24 */
  GPIO_DYING_GASP_N,           /* GPIO25 */
  GPIO_ASSOC_WIFI_N,		   /* GPIO26 */
  GPIO_LED_ADSL,			   /* GPIO27 */
  GPIO_RST_LAN_N,              /* GPIO28 */
  GPIO_CMD_POWER_OFF,          /* GPIO29 */
  GPIO_POWER_OFF_N,			   /* GPIO30 */
  GPIO_LED_DWNLD,			   /* GPIO31 */

 #ifdef CONFIG_SAGEM_BOXER
  GPIO_LAST,
  GPIO_LED_WAN_GRN      = GPIO_LAST,
  GPIO_LED_WAN          = GPIO_LAST,
  GPIO_LED_WIFI         = GPIO_LED_WIRLS,
  GPIO_FXS_EXT_LINE2_N  = GPIO_FXS_EXT_LINE2,
  GPIO_FXS_EXT_LINE_N   = GPIO_FXS_EXT_LINE1,
  GPIO_LEDS_CONFIG      = GPIO_LAST,
  GPIO_PLACEBO          = GPIO_LAST-1,  // for compilation because "GPIO_LAST" must be the last of this enum
 #endif

 #ifdef CONFIG_SAGEM_LBV2ULT
  GPIO_LAST,
  GPIO_LED_WAN_GRN		= GPIO_LED_ADSL,
  GPIO_LED_WAN			= GPIO_LED_ADSL_RED,
  GPIO_FXS_EXT_LINE_N	= GPIO_FXS_EXT_LINE1, 
  GPIO_CMD_REBOOT_N		= GPIO_POWER_OFF_N,
  GPIO_CMD_RESET_N		= GPIO_RST_CONFIG_N,
  GPIO_SHUTDOWN_BOX     = GPIO_CMD_POWER_OFF,
  GPIO_USB_HUB_RST		= GPIO_USBH_PWR_EN,
  GPIO_PLACEBO          = GPIO_LAST-1,	// for compilation because "GPIO_LAST" must be the last of this enum
 #endif
#endif

#if ( defined(CONFIG_SAGEM_LBV2ULT) && ! defined(CONFIG_SAGEM_GPIO_BOXER_FOR_ULT_FW) ) || ( defined(CONFIG_SAGEM_BOXER) && defined(CONFIG_SAGEM_GPIO_ULT_FOR_BOXER_FW) )
  /* GPIO FLAG 1 */
  GPIO_RST_Z_N = 0,
  GPIO_BAD_POS_N,
  GPIO_RST_BRIDGE_N,
  GPIO_HDD_CONNECTED,
  GPIO_SHUTDOWN_BOX,
  GPIO_LED_WIRLS,
  GPIO_LED_PHONE,
  GPIO_LED_LAN,
  GPIO_LED_WAN, /* RED */
  GPIO_LED_ON,
  GPIO_LED_HDD,
  GPIO_CMD_NL,
  GPIO_USB_HUB_RST,
  GPIO_USBH_PWR_EN, /*  GPIO_USBH_EN  modified for compatibility */
  /* GPIO FLAG 2 */
  GPIO_AFE_RST_N,
  GPIO_SUR_I_VUSBH,
  GPIO_CMD_REBOOT_N, //  GPIO_RST_CONFIG_N,
  GPIO_FXS_EXT_LINE_N,
  GPIO_CMD_RESET_N,
  GPIO_LED_DWNLD, /* GPIO_LED_UPGRADE modified for compatibility */
  GPIO_ASSOC_WIFI_N,
  GPIO_LED_WAN_GRN,
  GPIO_DYING_GASP,
  GPIO_RST_LAN_N,
  GPIO_ALT_WINFIN_INT,
  GPIO_CP_USB_HDD,
#endif // CONFIG_SAGEM_LBV2ULT
#ifdef CONFIG_SAGEM_LBV2BABY
  /* GPIO FLAG 1 */
  GPIO_RST_Z_N = 0,
  GPIO_SPI_CS_Z_N,
  GPIO_SPI_CS_FXO_N,
  GPIO_LED_WIRLS,
  GPIO_LED_PHONE,
  GPIO_LED_LAN,
  GPIO_LED_WAN, /* RED */
  GPIO_LED_ON,
  GPIO_LED_REINJECTION,	
  GPIO_FXS_EXT_LINE2,
  /* GPIO FLAG 2 */
  GPIO_AFE_RST_N,
//  GPIO_SUR_I_VUSBH,
  GPIO_CMD_RESET_N,
  GPIO_FXS_EXT_LINE_N,
  GPIO_ASSOC_WIFI_N,
  GPIO_INT_Z_N,
  GPIO_RST_LAN_1_N,
  GPIO_RST_LAN_2_N,
  GPIO_CRS_ETH0,
  GPIO_CRS_ETH1,
#endif // CONFIG_SAGEM_LBV2BABY
#ifdef CONFIG_SAGEM_LBV2MINI
  /* GPIO FLAG 1 */
  GPIO_RST_Z_N = 0,
  GPIO_SPI_CS_Z_N,
  GPIO_SPI_CS_FXO_N,
  GPIO_ACT_ETH0_N,
  GPIO_ACT_ETH1_N,
  GPIO_LED_WIRLS,
  GPIO_LED_PHONE,
  GPIO_LED_LAN,
  GPIO_LED_WAN, /* RED */
  GPIO_LED_ON,
  GPIO_CMD_NL,
  GPIO_USBH_PWR_EN, /*  GPIO_USBH_EN  modified for compatibility */
  /* GPIO FLAG 2 */
  GPIO_AFE_RST_N,
  GPIO_SUR_I_VUSBH,
  GPIO_CMD_RESET_N,
  GPIO_FXS_EXT_LINE_N,
  GPIO_CMD_REBOOT_N, //  GPIO_RST_CONFIG_N,
  GPIO_LED_DWNLD, /* GPIO_LED_UPGRADE modified for compatibility */
  GPIO_ASSOC_WIFI_N,
  GPIO_LED_WAN_GRN,
  GPIO_RST_LAN_1_N,
  GPIO_RST_LAN_2_N,
  GPIO_CRS_ETH0,
  GPIO_CRS_ETH1,
#endif // CONFIG_SAGEM_LBV2MINI
#ifdef CONFIG_SAGEM_LBV2STD
  GPIO_CMD_RESET_N = 0,
  GPIO_SPI_CS_Z_N,
  GPIO_SPI_CS_FXO_N,
  GPIO_BT_RXD,
  GPIO_BT_TXD,
  GPIO_BT_RTS,
  GPIO_BT_CTS,
  GPIO_CB_DETECT,
  GPIO_USBH_PWR_EN,    // GPIO_USBH_EN  modified for compatibility
  GPIO_USB_PWR_DET ,
  GPIO_RST_Z_N,
  GPIO_RST_LAN_N,
  GPIO_RST_BT_N,
  GPIO_CMD_NL,
  GPIO_LUMIN0,
  GPIO_LUMIN1,
  GPIO_AFE_RST_N,
  GPIO_SUR_I_VUSBH,
  GPIO_CB_FRAME_EN,
  GPIO_FXS_EXT_LINE_N,
  GPIO_CMD_REBOOT_N,   // GPIO_RST_CONFIG_N  modified for compatibility
  GPIO_CTRL_PULSE,
  GPIO_ASSOC_WIFI_N,
  GPIO_LED_ON,
  GPIO_LED_WAN,
  GPIO_LED_PHONE,
  GPIO_LED_WIRLS,
  GPIO_LED_DWNLD,
#endif // CONFIG_SAGEM_LBV2STD
  GPIO_LAST
#endif // CONFIG_SAGEM_GENERIC_CARD_SUPPORT
} GPIO_Devices_t;

/* Access functions to the GPIO lines */
int gpio_led_btn_setup(void);
int gpio_led_btn_close(void);

int gpio_led_btn_set(GPIO_Devices_t device_number);
int gpio_led_btn_reset(GPIO_Devices_t device_number);
int gpio_led_btn_toggle(GPIO_Devices_t device_number);
int gpio_led_btn_read(GPIO_Devices_t device_number);
unsigned long gpio_led_btn_get_all_input(void);
void gpio_led_btn_set_all_output(unsigned long set_value);
#ifdef CONFIG_SAGEM_BOXER
void gpio_reset_interrupt(void);
#endif

#ifdef CONFIG_SAGEM_GENERIC_CARD_SUPPORT
extern int gpio_get_card_id(void);
#endif

#endif
