2007-09-25 07:42:09 -06: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>
|
|
|
|
*/
|
|
|
|
|
2011-07-28 16:46:31 -06:00
|
|
|
#include <linux/export.h>
|
2007-09-25 07:42:09 -06:00
|
|
|
#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 03:44:26 -06: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 07:42:09 -06:00
|
|
|
{
|
2011-07-22 17:20:12 -06:00
|
|
|
switch (bcm47xx_bus_type) {
|
2011-07-22 17:20:13 -06:00
|
|
|
#ifdef CONFIG_BCM47XX_SSB
|
2011-07-22 17:20:12 -06:00
|
|
|
case BCM47XX_BUS_TYPE_SSB:
|
|
|
|
if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco) &&
|
|
|
|
((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES))
|
|
|
|
return -EINVAL;
|
2007-09-25 07:42:09 -06:00
|
|
|
|
2011-07-22 17:20:12 -06:00
|
|
|
if (ssb_extif_available(&bcm47xx_bus.ssb.extif) &&
|
|
|
|
((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
|
|
|
|
return -EINVAL;
|
2007-09-25 07:42:09 -06:00
|
|
|
|
2011-07-22 17:20:12 -06:00
|
|
|
if (test_and_set_bit(gpio, gpio_in_use))
|
|
|
|
return -EBUSY;
|
2007-09-25 07:42:09 -06:00
|
|
|
|
2011-07-22 17:20:12 -06:00
|
|
|
return 0;
|
2011-07-22 17:20:13 -06:00
|
|
|
#endif
|
2011-07-22 17:20:14 -06:00
|
|
|
#ifdef CONFIG_BCM47XX_BCMA
|
|
|
|
case BCM47XX_BUS_TYPE_BCMA:
|
|
|
|
if (gpio >= BCM47XX_CHIPCO_GPIO_LINES)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (test_and_set_bit(gpio, gpio_in_use))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
#endif
|
2011-07-22 17:20:12 -06:00
|
|
|
}
|
|
|
|
return -EINVAL;
|
2007-09-25 07:42:09 -06:00
|
|
|
}
|
2008-10-14 03:44:26 -06:00
|
|
|
EXPORT_SYMBOL(gpio_request);
|
2007-09-25 07:42:09 -06:00
|
|
|
|
2008-10-14 03:44:26 -06:00
|
|
|
void gpio_free(unsigned gpio)
|
2007-09-25 07:42:09 -06:00
|
|
|
{
|
2011-07-22 17:20:12 -06:00
|
|
|
switch (bcm47xx_bus_type) {
|
2011-07-22 17:20:13 -06:00
|
|
|
#ifdef CONFIG_BCM47XX_SSB
|
2011-07-22 17:20:12 -06:00
|
|
|
case BCM47XX_BUS_TYPE_SSB:
|
|
|
|
if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco) &&
|
|
|
|
((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES))
|
|
|
|
return;
|
2008-10-14 03:44:26 -06:00
|
|
|
|
2011-07-22 17:20:12 -06:00
|
|
|
if (ssb_extif_available(&bcm47xx_bus.ssb.extif) &&
|
|
|
|
((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
|
|
|
|
return;
|
2008-10-14 03:44:26 -06:00
|
|
|
|
2011-07-22 17:20:12 -06:00
|
|
|
clear_bit(gpio, gpio_in_use);
|
|
|
|
return;
|
2011-07-22 17:20:13 -06:00
|
|
|
#endif
|
2011-07-22 17:20:14 -06:00
|
|
|
#ifdef CONFIG_BCM47XX_BCMA
|
|
|
|
case BCM47XX_BUS_TYPE_BCMA:
|
|
|
|
if (gpio >= BCM47XX_CHIPCO_GPIO_LINES)
|
|
|
|
return;
|
|
|
|
|
|
|
|
clear_bit(gpio, gpio_in_use);
|
|
|
|
return;
|
|
|
|
#endif
|
2011-07-22 17:20:12 -06:00
|
|
|
}
|
2008-10-14 03:44:26 -06:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(gpio_free);
|
2007-09-25 07:42:09 -06:00
|
|
|
|
2008-10-14 03:44:26 -06:00
|
|
|
int gpio_to_irq(unsigned gpio)
|
|
|
|
{
|
2011-07-22 17:20:12 -06:00
|
|
|
switch (bcm47xx_bus_type) {
|
2011-07-22 17:20:13 -06:00
|
|
|
#ifdef CONFIG_BCM47XX_SSB
|
2011-07-22 17:20:12 -06:00
|
|
|
case BCM47XX_BUS_TYPE_SSB:
|
|
|
|
if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco))
|
|
|
|
return ssb_mips_irq(bcm47xx_bus.ssb.chipco.dev) + 2;
|
|
|
|
else if (ssb_extif_available(&bcm47xx_bus.ssb.extif))
|
|
|
|
return ssb_mips_irq(bcm47xx_bus.ssb.extif.dev) + 2;
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
2011-07-22 17:20:14 -06:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_BCM47XX_BCMA
|
|
|
|
case BCM47XX_BUS_TYPE_BCMA:
|
|
|
|
return bcma_core_mips_irq(bcm47xx_bus.bcma.bus.drv_cc.core) + 2;
|
2011-07-22 17:20:13 -06:00
|
|
|
#endif
|
2011-07-22 17:20:12 -06:00
|
|
|
}
|
|
|
|
return -EINVAL;
|
2007-09-25 07:42:09 -06:00
|
|
|
}
|
2008-10-14 03:44:26 -06:00
|
|
|
EXPORT_SYMBOL_GPL(gpio_to_irq);
|