aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-generic/gpio.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-generic/gpio.h')
-rw-r--r--include/asm-generic/gpio.h38
1 files changed, 34 insertions, 4 deletions
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 6be061d09da9..0f99ad38b012 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -2,8 +2,9 @@
2#define _ASM_GENERIC_GPIO_H 2#define _ASM_GENERIC_GPIO_H
3 3
4#include <linux/types.h> 4#include <linux/types.h>
5#include <linux/errno.h>
5 6
6#ifdef CONFIG_HAVE_GPIO_LIB 7#ifdef CONFIG_GPIOLIB
7 8
8#include <linux/compiler.h> 9#include <linux/compiler.h>
9 10
@@ -13,7 +14,7 @@
13 * 14 *
14 * While the GPIO programming interface defines valid GPIO numbers 15 * While the GPIO programming interface defines valid GPIO numbers
15 * to be in the range 0..MAX_INT, this library restricts them to the 16 * to be in the range 0..MAX_INT, this library restricts them to the
16 * smaller range 0..ARCH_NR_GPIOS. 17 * smaller range 0..ARCH_NR_GPIOS-1.
17 */ 18 */
18 19
19#ifndef ARCH_NR_GPIOS 20#ifndef ARCH_NR_GPIOS
@@ -32,6 +33,8 @@ struct module;
32/** 33/**
33 * struct gpio_chip - abstract a GPIO controller 34 * struct gpio_chip - abstract a GPIO controller
34 * @label: for diagnostics 35 * @label: for diagnostics
36 * @dev: optional device providing the GPIOs
37 * @owner: helps prevent removal of modules exporting active GPIOs
35 * @direction_input: configures signal "offset" as input, or returns error 38 * @direction_input: configures signal "offset" as input, or returns error
36 * @get: returns value for signal "offset"; for output signals this 39 * @get: returns value for signal "offset"; for output signals this
37 * returns either the value actually sensed, or zero 40 * returns either the value actually sensed, or zero
@@ -59,6 +62,7 @@ struct module;
59 */ 62 */
60struct gpio_chip { 63struct gpio_chip {
61 char *label; 64 char *label;
65 struct device *dev;
62 struct module *owner; 66 struct module *owner;
63 67
64 int (*direction_input)(struct gpio_chip *chip, 68 int (*direction_input)(struct gpio_chip *chip,
@@ -74,6 +78,7 @@ struct gpio_chip {
74 int base; 78 int base;
75 u16 ngpio; 79 u16 ngpio;
76 unsigned can_sleep:1; 80 unsigned can_sleep:1;
81 unsigned exported:1;
77}; 82};
78 83
79extern const char *gpiochip_is_requested(struct gpio_chip *chip, 84extern const char *gpiochip_is_requested(struct gpio_chip *chip,
@@ -108,7 +113,18 @@ extern void __gpio_set_value(unsigned gpio, int value);
108extern int __gpio_cansleep(unsigned gpio); 113extern int __gpio_cansleep(unsigned gpio);
109 114
110 115
111#else 116#ifdef CONFIG_GPIO_SYSFS
117
118/*
119 * A sysfs interface can be exported by individual drivers if they want,
120 * but more typically is configured entirely from userspace.
121 */
122extern int gpio_export(unsigned gpio, bool direction_may_change);
123extern void gpio_unexport(unsigned gpio);
124
125#endif /* CONFIG_GPIO_SYSFS */
126
127#else /* !CONFIG_HAVE_GPIO_LIB */
112 128
113static inline int gpio_is_valid(int number) 129static inline int gpio_is_valid(int number)
114{ 130{
@@ -137,6 +153,20 @@ static inline void gpio_set_value_cansleep(unsigned gpio, int value)
137 gpio_set_value(gpio, value); 153 gpio_set_value(gpio, value);
138} 154}
139 155
140#endif 156#endif /* !CONFIG_HAVE_GPIO_LIB */
157
158#ifndef CONFIG_GPIO_SYSFS
159
160/* sysfs support is only available with gpiolib, where it's optional */
161
162static inline int gpio_export(unsigned gpio, bool direction_may_change)
163{
164 return -ENOSYS;
165}
166
167static inline void gpio_unexport(unsigned gpio)
168{
169}
170#endif /* CONFIG_GPIO_SYSFS */
141 171
142#endif /* _ASM_GENERIC_GPIO_H */ 172#endif /* _ASM_GENERIC_GPIO_H */