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.h44
1 files changed, 39 insertions, 5 deletions
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index ecf675a59d2..0f99ad38b01 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -1,7 +1,12 @@
1#ifndef _ASM_GENERIC_GPIO_H 1#ifndef _ASM_GENERIC_GPIO_H
2#define _ASM_GENERIC_GPIO_H 2#define _ASM_GENERIC_GPIO_H
3 3
4#ifdef CONFIG_HAVE_GPIO_LIB 4#include <linux/types.h>
5#include <linux/errno.h>
6
7#ifdef CONFIG_GPIOLIB
8
9#include <linux/compiler.h>
5 10
6/* Platforms may implement their GPIO interface with library code, 11/* Platforms may implement their GPIO interface with library code,
7 * at a small performance cost for non-inlined operations and some 12 * at a small performance cost for non-inlined operations and some
@@ -9,7 +14,7 @@
9 * 14 *
10 * While the GPIO programming interface defines valid GPIO numbers 15 * While the GPIO programming interface defines valid GPIO numbers
11 * 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
12 * smaller range 0..ARCH_NR_GPIOS. 17 * smaller range 0..ARCH_NR_GPIOS-1.
13 */ 18 */
14 19
15#ifndef ARCH_NR_GPIOS 20#ifndef ARCH_NR_GPIOS
@@ -28,6 +33,8 @@ struct module;
28/** 33/**
29 * struct gpio_chip - abstract a GPIO controller 34 * struct gpio_chip - abstract a GPIO controller
30 * @label: for diagnostics 35 * @label: for diagnostics
36 * @dev: optional device providing the GPIOs
37 * @owner: helps prevent removal of modules exporting active GPIOs
31 * @direction_input: configures signal "offset" as input, or returns error 38 * @direction_input: configures signal "offset" as input, or returns error
32 * @get: returns value for signal "offset"; for output signals this 39 * @get: returns value for signal "offset"; for output signals this
33 * returns either the value actually sensed, or zero 40 * returns either the value actually sensed, or zero
@@ -55,6 +62,7 @@ struct module;
55 */ 62 */
56struct gpio_chip { 63struct gpio_chip {
57 char *label; 64 char *label;
65 struct device *dev;
58 struct module *owner; 66 struct module *owner;
59 67
60 int (*direction_input)(struct gpio_chip *chip, 68 int (*direction_input)(struct gpio_chip *chip,
@@ -70,11 +78,12 @@ struct gpio_chip {
70 int base; 78 int base;
71 u16 ngpio; 79 u16 ngpio;
72 unsigned can_sleep:1; 80 unsigned can_sleep:1;
81 unsigned exported:1;
73}; 82};
74 83
75extern const char *gpiochip_is_requested(struct gpio_chip *chip, 84extern const char *gpiochip_is_requested(struct gpio_chip *chip,
76 unsigned offset); 85 unsigned offset);
77extern int __init __must_check gpiochip_reserve(int start, int ngpio); 86extern int __must_check gpiochip_reserve(int start, int ngpio);
78 87
79/* add/remove chips */ 88/* add/remove chips */
80extern int gpiochip_add(struct gpio_chip *chip); 89extern int gpiochip_add(struct gpio_chip *chip);
@@ -104,7 +113,18 @@ extern void __gpio_set_value(unsigned gpio, int value);
104extern int __gpio_cansleep(unsigned gpio); 113extern int __gpio_cansleep(unsigned gpio);
105 114
106 115
107#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 */
108 128
109static inline int gpio_is_valid(int number) 129static inline int gpio_is_valid(int number)
110{ 130{
@@ -133,6 +153,20 @@ static inline void gpio_set_value_cansleep(unsigned gpio, int value)
133 gpio_set_value(gpio, value); 153 gpio_set_value(gpio, value);
134} 154}
135 155
136#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 */
137 171
138#endif /* _ASM_GENERIC_GPIO_H */ 172#endif /* _ASM_GENERIC_GPIO_H */