Add linux-next specific files for 20110831
[linux-2.6/next.git] / arch / mips / include / asm / mach-bcm47xx / gpio.h
blob76961cabeedfe1cdac4caaef7e9989ca04a345be
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 #ifndef __BCM47XX_GPIO_H
10 #define __BCM47XX_GPIO_H
12 #include <linux/ssb/ssb_embedded.h>
13 #include <linux/bcma/bcma.h>
14 #include <asm/mach-bcm47xx/bcm47xx.h>
16 #define BCM47XX_EXTIF_GPIO_LINES 5
17 #define BCM47XX_CHIPCO_GPIO_LINES 16
19 extern int gpio_request(unsigned gpio, const char *label);
20 extern void gpio_free(unsigned gpio);
21 extern int gpio_to_irq(unsigned gpio);
23 static inline int gpio_get_value(unsigned gpio)
25 switch (bcm47xx_bus_type) {
26 #ifdef CONFIG_BCM47XX_SSB
27 case BCM47XX_BUS_TYPE_SSB:
28 return ssb_gpio_in(&bcm47xx_bus.ssb, 1 << gpio);
29 #endif
30 #ifdef CONFIG_BCM47XX_BCMA
31 case BCM47XX_BUS_TYPE_BCMA:
32 return bcma_chipco_gpio_in(&bcm47xx_bus.bcma.bus.drv_cc,
33 1 << gpio);
34 #endif
36 return -EINVAL;
39 static inline void gpio_set_value(unsigned gpio, int value)
41 switch (bcm47xx_bus_type) {
42 #ifdef CONFIG_BCM47XX_SSB
43 case BCM47XX_BUS_TYPE_SSB:
44 ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
45 value ? 1 << gpio : 0);
46 return;
47 #endif
48 #ifdef CONFIG_BCM47XX_BCMA
49 case BCM47XX_BUS_TYPE_BCMA:
50 bcma_chipco_gpio_out(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
51 value ? 1 << gpio : 0);
52 return;
53 #endif
57 static inline int gpio_direction_input(unsigned gpio)
59 switch (bcm47xx_bus_type) {
60 #ifdef CONFIG_BCM47XX_SSB
61 case BCM47XX_BUS_TYPE_SSB:
62 ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 0);
63 return 0;
64 #endif
65 #ifdef CONFIG_BCM47XX_BCMA
66 case BCM47XX_BUS_TYPE_BCMA:
67 bcma_chipco_gpio_outen(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
68 0);
69 return 0;
70 #endif
72 return -EINVAL;
75 static inline int gpio_direction_output(unsigned gpio, int value)
77 switch (bcm47xx_bus_type) {
78 #ifdef CONFIG_BCM47XX_SSB
79 case BCM47XX_BUS_TYPE_SSB:
80 /* first set the gpio out value */
81 ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
82 value ? 1 << gpio : 0);
83 /* then set the gpio mode */
84 ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 1 << gpio);
85 return 0;
86 #endif
87 #ifdef CONFIG_BCM47XX_BCMA
88 case BCM47XX_BUS_TYPE_BCMA:
89 /* first set the gpio out value */
90 bcma_chipco_gpio_out(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
91 value ? 1 << gpio : 0);
92 /* then set the gpio mode */
93 bcma_chipco_gpio_outen(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
94 1 << gpio);
95 return 0;
96 #endif
98 return -EINVAL;
101 static inline int gpio_intmask(unsigned gpio, int value)
103 switch (bcm47xx_bus_type) {
104 #ifdef CONFIG_BCM47XX_SSB
105 case BCM47XX_BUS_TYPE_SSB:
106 ssb_gpio_intmask(&bcm47xx_bus.ssb, 1 << gpio,
107 value ? 1 << gpio : 0);
108 return 0;
109 #endif
110 #ifdef CONFIG_BCM47XX_BCMA
111 case BCM47XX_BUS_TYPE_BCMA:
112 bcma_chipco_gpio_intmask(&bcm47xx_bus.bcma.bus.drv_cc,
113 1 << gpio, value ? 1 << gpio : 0);
114 return 0;
115 #endif
117 return -EINVAL;
120 static inline int gpio_polarity(unsigned gpio, int value)
122 switch (bcm47xx_bus_type) {
123 #ifdef CONFIG_BCM47XX_SSB
124 case BCM47XX_BUS_TYPE_SSB:
125 ssb_gpio_polarity(&bcm47xx_bus.ssb, 1 << gpio,
126 value ? 1 << gpio : 0);
127 return 0;
128 #endif
129 #ifdef CONFIG_BCM47XX_BCMA
130 case BCM47XX_BUS_TYPE_BCMA:
131 bcma_chipco_gpio_polarity(&bcm47xx_bus.bcma.bus.drv_cc,
132 1 << gpio, value ? 1 << gpio : 0);
133 return 0;
134 #endif
136 return -EINVAL;
140 /* cansleep wrappers */
141 #include <asm-generic/gpio.h>
143 #endif /* __BCM47XX_GPIO_H */