2007-09-25 15:42:09 +02:00
/*
* This file is subject to the terms and conditions of the GNU General Public
* License . See the file " COPYING " in the main directory of this archive
* for more details .
*
* Copyright ( C ) 2007 Aurelien Jarno < aurelien @ aurel32 . net >
*/
# include <linux/ssb/ssb.h>
# include <linux/ssb/ssb_driver_chipcommon.h>
# include <linux/ssb/ssb_driver_extif.h>
# include <asm/mach-bcm47xx/bcm47xx.h>
# include <asm/mach-bcm47xx/gpio.h>
2008-10-14 11:44:26 +02:00
# if (BCM47XX_CHIPCO_GPIO_LINES > BCM47XX_EXTIF_GPIO_LINES)
static DECLARE_BITMAP ( gpio_in_use , BCM47XX_CHIPCO_GPIO_LINES ) ;
# else
static DECLARE_BITMAP ( gpio_in_use , BCM47XX_EXTIF_GPIO_LINES ) ;
# endif
int gpio_request ( unsigned gpio , const char * tag )
2007-09-25 15:42:09 +02:00
{
2008-10-14 11:44:26 +02:00
if ( ssb_chipco_available ( & ssb_bcm47xx . chipco ) & &
( ( unsigned ) gpio > = BCM47XX_CHIPCO_GPIO_LINES ) )
2007-09-25 15:42:09 +02:00
return - EINVAL ;
2008-10-14 11:44:26 +02:00
if ( ssb_extif_available ( & ssb_bcm47xx . extif ) & &
( ( unsigned ) gpio > = BCM47XX_EXTIF_GPIO_LINES ) )
return - EINVAL ;
2007-09-25 15:42:09 +02:00
2008-10-14 11:44:26 +02:00
if ( test_and_set_bit ( gpio , gpio_in_use ) )
return - EBUSY ;
2007-09-25 15:42:09 +02:00
return 0 ;
}
2008-10-14 11:44:26 +02:00
EXPORT_SYMBOL ( gpio_request ) ;
2007-09-25 15:42:09 +02:00
2008-10-14 11:44:26 +02:00
void gpio_free ( unsigned gpio )
2007-09-25 15:42:09 +02:00
{
2008-10-14 11:44:26 +02:00
if ( ssb_chipco_available ( & ssb_bcm47xx . chipco ) & &
( ( unsigned ) gpio > = BCM47XX_CHIPCO_GPIO_LINES ) )
return ;
if ( ssb_extif_available ( & ssb_bcm47xx . extif ) & &
( ( unsigned ) gpio > = BCM47XX_EXTIF_GPIO_LINES ) )
return ;
clear_bit ( gpio , gpio_in_use ) ;
}
EXPORT_SYMBOL ( gpio_free ) ;
2007-09-25 15:42:09 +02:00
2008-10-14 11:44:26 +02:00
int gpio_to_irq ( unsigned gpio )
{
if ( ssb_chipco_available ( & ssb_bcm47xx . chipco ) )
return ssb_mips_irq ( ssb_bcm47xx . chipco . dev ) + 2 ;
else if ( ssb_extif_available ( & ssb_bcm47xx . extif ) )
return ssb_mips_irq ( ssb_bcm47xx . extif . dev ) + 2 ;
2007-09-25 15:42:09 +02:00
else
return - EINVAL ;
}
2008-10-14 11:44:26 +02:00
EXPORT_SYMBOL_GPL ( gpio_to_irq ) ;
2007-09-25 15:42:09 +02:00