2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net>
9 #include <linux/ssb/ssb.h>
10 #include <linux/ssb/ssb_driver_chipcommon.h>
11 #include <linux/ssb/ssb_driver_extif.h>
12 #include <asm/mach-bcm47xx/bcm47xx.h>
13 #include <asm/mach-bcm47xx/gpio.h>
15 #if (BCM47XX_CHIPCO_GPIO_LINES > BCM47XX_EXTIF_GPIO_LINES)
16 static DECLARE_BITMAP(gpio_in_use
, BCM47XX_CHIPCO_GPIO_LINES
);
18 static DECLARE_BITMAP(gpio_in_use
, BCM47XX_EXTIF_GPIO_LINES
);
21 int gpio_request(unsigned gpio
, const char *tag
)
23 switch (bcm47xx_bus_type
) {
24 #ifdef CONFIG_BCM47XX_SSB
25 case BCM47XX_BUS_TYPE_SSB
:
26 if (ssb_chipco_available(&bcm47xx_bus
.ssb
.chipco
) &&
27 ((unsigned)gpio
>= BCM47XX_CHIPCO_GPIO_LINES
))
30 if (ssb_extif_available(&bcm47xx_bus
.ssb
.extif
) &&
31 ((unsigned)gpio
>= BCM47XX_EXTIF_GPIO_LINES
))
34 if (test_and_set_bit(gpio
, gpio_in_use
))
39 #ifdef CONFIG_BCM47XX_BCMA
40 case BCM47XX_BUS_TYPE_BCMA
:
41 if (gpio
>= BCM47XX_CHIPCO_GPIO_LINES
)
44 if (test_and_set_bit(gpio
, gpio_in_use
))
52 EXPORT_SYMBOL(gpio_request
);
54 void gpio_free(unsigned gpio
)
56 switch (bcm47xx_bus_type
) {
57 #ifdef CONFIG_BCM47XX_SSB
58 case BCM47XX_BUS_TYPE_SSB
:
59 if (ssb_chipco_available(&bcm47xx_bus
.ssb
.chipco
) &&
60 ((unsigned)gpio
>= BCM47XX_CHIPCO_GPIO_LINES
))
63 if (ssb_extif_available(&bcm47xx_bus
.ssb
.extif
) &&
64 ((unsigned)gpio
>= BCM47XX_EXTIF_GPIO_LINES
))
67 clear_bit(gpio
, gpio_in_use
);
70 #ifdef CONFIG_BCM47XX_BCMA
71 case BCM47XX_BUS_TYPE_BCMA
:
72 if (gpio
>= BCM47XX_CHIPCO_GPIO_LINES
)
75 clear_bit(gpio
, gpio_in_use
);
80 EXPORT_SYMBOL(gpio_free
);
82 int gpio_to_irq(unsigned gpio
)
84 switch (bcm47xx_bus_type
) {
85 #ifdef CONFIG_BCM47XX_SSB
86 case BCM47XX_BUS_TYPE_SSB
:
87 if (ssb_chipco_available(&bcm47xx_bus
.ssb
.chipco
))
88 return ssb_mips_irq(bcm47xx_bus
.ssb
.chipco
.dev
) + 2;
89 else if (ssb_extif_available(&bcm47xx_bus
.ssb
.extif
))
90 return ssb_mips_irq(bcm47xx_bus
.ssb
.extif
.dev
) + 2;
94 #ifdef CONFIG_BCM47XX_BCMA
95 case BCM47XX_BUS_TYPE_BCMA
:
96 return bcma_core_mips_irq(bcm47xx_bus
.bcma
.bus
.drv_cc
.core
) + 2;
101 EXPORT_SYMBOL_GPL(gpio_to_irq
);