Commit | Line | Data |
---|---|---|
34cc662f AJ |
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. | |
5 | * | |
6 | * Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net> | |
7 | */ | |
8 | ||
9 | #ifndef __BCM47XX_GPIO_H | |
10 | #define __BCM47XX_GPIO_H | |
11 | ||
b06f3e19 | 12 | #include <linux/ssb/ssb_embedded.h> |
c1d1c5d4 | 13 | #include <linux/bcma/bcma.h> |
b06f3e19 AJ |
14 | #include <asm/mach-bcm47xx/bcm47xx.h> |
15 | ||
34cc662f AJ |
16 | #define BCM47XX_EXTIF_GPIO_LINES 5 |
17 | #define BCM47XX_CHIPCO_GPIO_LINES 16 | |
18 | ||
b06f3e19 AJ |
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); | |
34cc662f | 22 | |
b06f3e19 | 23 | static inline int gpio_get_value(unsigned gpio) |
34cc662f | 24 | { |
08ccf572 | 25 | switch (bcm47xx_bus_type) { |
a656ffcb | 26 | #ifdef CONFIG_BCM47XX_SSB |
08ccf572 HM |
27 | case BCM47XX_BUS_TYPE_SSB: |
28 | return ssb_gpio_in(&bcm47xx_bus.ssb, 1 << gpio); | |
c1d1c5d4 HM |
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); | |
a656ffcb | 34 | #endif |
08ccf572 HM |
35 | } |
36 | return -EINVAL; | |
34cc662f AJ |
37 | } |
38 | ||
df55a66a FF |
39 | #define gpio_get_value_cansleep gpio_get_value |
40 | ||
b06f3e19 | 41 | static inline void gpio_set_value(unsigned gpio, int value) |
34cc662f | 42 | { |
08ccf572 | 43 | switch (bcm47xx_bus_type) { |
a656ffcb | 44 | #ifdef CONFIG_BCM47XX_SSB |
08ccf572 HM |
45 | case BCM47XX_BUS_TYPE_SSB: |
46 | ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio, | |
47 | value ? 1 << gpio : 0); | |
c1d1c5d4 HM |
48 | return; |
49 | #endif | |
50 | #ifdef CONFIG_BCM47XX_BCMA | |
51 | case BCM47XX_BUS_TYPE_BCMA: | |
52 | bcma_chipco_gpio_out(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio, | |
53 | value ? 1 << gpio : 0); | |
54 | return; | |
a656ffcb | 55 | #endif |
08ccf572 | 56 | } |
34cc662f AJ |
57 | } |
58 | ||
df55a66a FF |
59 | #define gpio_set_value_cansleep gpio_set_value |
60 | ||
61 | static inline int gpio_cansleep(unsigned gpio) | |
62 | { | |
63 | return 0; | |
64 | } | |
65 | ||
66 | static inline int gpio_is_valid(unsigned gpio) | |
67 | { | |
68 | return gpio < (BCM47XX_EXTIF_GPIO_LINES + BCM47XX_CHIPCO_GPIO_LINES); | |
69 | } | |
70 | ||
71 | ||
b06f3e19 | 72 | static inline int gpio_direction_input(unsigned gpio) |
34cc662f | 73 | { |
08ccf572 | 74 | switch (bcm47xx_bus_type) { |
a656ffcb | 75 | #ifdef CONFIG_BCM47XX_SSB |
08ccf572 HM |
76 | case BCM47XX_BUS_TYPE_SSB: |
77 | ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 0); | |
78 | return 0; | |
c1d1c5d4 HM |
79 | #endif |
80 | #ifdef CONFIG_BCM47XX_BCMA | |
81 | case BCM47XX_BUS_TYPE_BCMA: | |
82 | bcma_chipco_gpio_outen(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio, | |
83 | 0); | |
84 | return 0; | |
a656ffcb | 85 | #endif |
08ccf572 HM |
86 | } |
87 | return -EINVAL; | |
34cc662f AJ |
88 | } |
89 | ||
b06f3e19 | 90 | static inline int gpio_direction_output(unsigned gpio, int value) |
34cc662f | 91 | { |
08ccf572 | 92 | switch (bcm47xx_bus_type) { |
a656ffcb | 93 | #ifdef CONFIG_BCM47XX_SSB |
08ccf572 HM |
94 | case BCM47XX_BUS_TYPE_SSB: |
95 | /* first set the gpio out value */ | |
96 | ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio, | |
97 | value ? 1 << gpio : 0); | |
98 | /* then set the gpio mode */ | |
99 | ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 1 << gpio); | |
100 | return 0; | |
c1d1c5d4 HM |
101 | #endif |
102 | #ifdef CONFIG_BCM47XX_BCMA | |
103 | case BCM47XX_BUS_TYPE_BCMA: | |
104 | /* first set the gpio out value */ | |
105 | bcma_chipco_gpio_out(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio, | |
106 | value ? 1 << gpio : 0); | |
107 | /* then set the gpio mode */ | |
108 | bcma_chipco_gpio_outen(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio, | |
109 | 1 << gpio); | |
110 | return 0; | |
a656ffcb | 111 | #endif |
08ccf572 HM |
112 | } |
113 | return -EINVAL; | |
34cc662f AJ |
114 | } |
115 | ||
e0f7ad5f | 116 | static inline int gpio_intmask(unsigned gpio, int value) |
34cc662f | 117 | { |
08ccf572 | 118 | switch (bcm47xx_bus_type) { |
a656ffcb | 119 | #ifdef CONFIG_BCM47XX_SSB |
08ccf572 HM |
120 | case BCM47XX_BUS_TYPE_SSB: |
121 | ssb_gpio_intmask(&bcm47xx_bus.ssb, 1 << gpio, | |
122 | value ? 1 << gpio : 0); | |
123 | return 0; | |
c1d1c5d4 HM |
124 | #endif |
125 | #ifdef CONFIG_BCM47XX_BCMA | |
126 | case BCM47XX_BUS_TYPE_BCMA: | |
127 | bcma_chipco_gpio_intmask(&bcm47xx_bus.bcma.bus.drv_cc, | |
128 | 1 << gpio, value ? 1 << gpio : 0); | |
129 | return 0; | |
a656ffcb | 130 | #endif |
08ccf572 HM |
131 | } |
132 | return -EINVAL; | |
34cc662f AJ |
133 | } |
134 | ||
e0f7ad5f | 135 | static inline int gpio_polarity(unsigned gpio, int value) |
34cc662f | 136 | { |
08ccf572 | 137 | switch (bcm47xx_bus_type) { |
a656ffcb | 138 | #ifdef CONFIG_BCM47XX_SSB |
08ccf572 HM |
139 | case BCM47XX_BUS_TYPE_SSB: |
140 | ssb_gpio_polarity(&bcm47xx_bus.ssb, 1 << gpio, | |
141 | value ? 1 << gpio : 0); | |
142 | return 0; | |
c1d1c5d4 HM |
143 | #endif |
144 | #ifdef CONFIG_BCM47XX_BCMA | |
145 | case BCM47XX_BUS_TYPE_BCMA: | |
146 | bcma_chipco_gpio_polarity(&bcm47xx_bus.bcma.bus.drv_cc, | |
147 | 1 << gpio, value ? 1 << gpio : 0); | |
148 | return 0; | |
a656ffcb | 149 | #endif |
08ccf572 HM |
150 | } |
151 | return -EINVAL; | |
34cc662f AJ |
152 | } |
153 | ||
154 | ||
34cc662f | 155 | #endif /* __BCM47XX_GPIO_H */ |