MIPS: Yosemite, Emma: Fix off-by-two in arcs_cmdline buffer size check
[linux-2.6/linux-mips.git] / arch / mips / bcm47xx / gpio.c
blob57b425fd4d412b2e685804065255fef55af7affc
1 /*
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
4 * for more details.
6 * Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net>
7 */
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);
17 #else
18 static DECLARE_BITMAP(gpio_in_use, BCM47XX_EXTIF_GPIO_LINES);
19 #endif
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))
28 return -EINVAL;
30 if (ssb_extif_available(&bcm47xx_bus.ssb.extif) &&
31 ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
32 return -EINVAL;
34 if (test_and_set_bit(gpio, gpio_in_use))
35 return -EBUSY;
37 return 0;
38 #endif
39 #ifdef CONFIG_BCM47XX_BCMA
40 case BCM47XX_BUS_TYPE_BCMA:
41 if (gpio >= BCM47XX_CHIPCO_GPIO_LINES)
42 return -EINVAL;
44 if (test_and_set_bit(gpio, gpio_in_use))
45 return -EBUSY;
47 return 0;
48 #endif
50 return -EINVAL;
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))
61 return;
63 if (ssb_extif_available(&bcm47xx_bus.ssb.extif) &&
64 ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
65 return;
67 clear_bit(gpio, gpio_in_use);
68 return;
69 #endif
70 #ifdef CONFIG_BCM47XX_BCMA
71 case BCM47XX_BUS_TYPE_BCMA:
72 if (gpio >= BCM47XX_CHIPCO_GPIO_LINES)
73 return;
75 clear_bit(gpio, gpio_in_use);
76 return;
77 #endif
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;
91 else
92 return -EINVAL;
93 #endif
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;
97 #endif
99 return -EINVAL;
101 EXPORT_SYMBOL_GPL(gpio_to_irq);