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/export.h>
10 #include <linux/ssb/ssb.h>
11 #include <linux/ssb/ssb_driver_chipcommon.h>
12 #include <linux/ssb/ssb_driver_extif.h>
13 #include <asm/mach-bcm47xx/bcm47xx.h>
14 #include <asm/mach-bcm47xx/gpio.h>
16 #if (BCM47XX_CHIPCO_GPIO_LINES > BCM47XX_EXTIF_GPIO_LINES)
17 static DECLARE_BITMAP(gpio_in_use, BCM47XX_CHIPCO_GPIO_LINES);
19 static DECLARE_BITMAP(gpio_in_use, BCM47XX_EXTIF_GPIO_LINES);
22 int gpio_request(unsigned gpio, const char *tag)
24 switch (bcm47xx_bus_type) {
25 #ifdef CONFIG_BCM47XX_SSB
26 case BCM47XX_BUS_TYPE_SSB:
27 if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco) &&
28 ((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES))
31 if (ssb_extif_available(&bcm47xx_bus.ssb.extif) &&
32 ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
35 if (test_and_set_bit(gpio, gpio_in_use))
40 #ifdef CONFIG_BCM47XX_BCMA
41 case BCM47XX_BUS_TYPE_BCMA:
42 if (gpio >= BCM47XX_CHIPCO_GPIO_LINES)
45 if (test_and_set_bit(gpio, gpio_in_use))
53 EXPORT_SYMBOL(gpio_request);
55 void gpio_free(unsigned gpio)
57 switch (bcm47xx_bus_type) {
58 #ifdef CONFIG_BCM47XX_SSB
59 case BCM47XX_BUS_TYPE_SSB:
60 if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco) &&
61 ((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES))
64 if (ssb_extif_available(&bcm47xx_bus.ssb.extif) &&
65 ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
68 clear_bit(gpio, gpio_in_use);
71 #ifdef CONFIG_BCM47XX_BCMA
72 case BCM47XX_BUS_TYPE_BCMA:
73 if (gpio >= BCM47XX_CHIPCO_GPIO_LINES)
76 clear_bit(gpio, gpio_in_use);
81 EXPORT_SYMBOL(gpio_free);
83 int gpio_to_irq(unsigned gpio)
85 switch (bcm47xx_bus_type) {
86 #ifdef CONFIG_BCM47XX_SSB
87 case BCM47XX_BUS_TYPE_SSB:
88 if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco))
89 return ssb_mips_irq(bcm47xx_bus.ssb.chipco.dev) + 2;
90 else if (ssb_extif_available(&bcm47xx_bus.ssb.extif))
91 return ssb_mips_irq(bcm47xx_bus.ssb.extif.dev) + 2;
95 #ifdef CONFIG_BCM47XX_BCMA
96 case BCM47XX_BUS_TYPE_BCMA:
97 return bcma_core_mips_irq(bcm47xx_bus.bcma.bus.drv_cc.core) + 2;
102 EXPORT_SYMBOL_GPL(gpio_to_irq);