1#ifndef _ASM_GENERIC_GPIO_H
2#define _ASM_GENERIC_GPIO_H
3
4#include <linux/kernel.h>
5#include <linux/types.h>
6#include <linux/errno.h>
7#include <linux/of.h>
8
9#ifdef CONFIG_GPIOLIB
10
11#include <linux/compiler.h>
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#ifndef ARCH_NR_GPIOS
27#define ARCH_NR_GPIOS 256
28#endif
29
30
31
32
33
34
35
36
37
38
39static inline bool gpio_is_valid(int number)
40{
41 return number >= 0 && number < ARCH_NR_GPIOS;
42}
43
44struct device;
45struct gpio;
46struct seq_file;
47struct module;
48struct device_node;
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92struct gpio_chip {
93 const char *label;
94 struct device *dev;
95 struct module *owner;
96
97 int (*request)(struct gpio_chip *chip,
98 unsigned offset);
99 void (*free)(struct gpio_chip *chip,
100 unsigned offset);
101
102 int (*direction_input)(struct gpio_chip *chip,
103 unsigned offset);
104 int (*get)(struct gpio_chip *chip,
105 unsigned offset);
106 int (*direction_output)(struct gpio_chip *chip,
107 unsigned offset, int value);
108 int (*set_debounce)(struct gpio_chip *chip,
109 unsigned offset, unsigned debounce);
110
111 void (*set)(struct gpio_chip *chip,
112 unsigned offset, int value);
113
114 int (*to_irq)(struct gpio_chip *chip,
115 unsigned offset);
116
117 void (*dbg_show)(struct seq_file *s,
118 struct gpio_chip *chip);
119 int base;
120 u16 ngpio;
121 const char *const *names;
122 unsigned can_sleep:1;
123 unsigned exported:1;
124
125#if defined(CONFIG_OF_GPIO)
126
127
128
129
130 struct device_node *of_node;
131 int of_gpio_n_cells;
132 int (*of_xlate)(struct gpio_chip *gc,
133 const struct of_phandle_args *gpiospec, u32 *flags);
134#endif
135};
136
137extern const char *gpiochip_is_requested(struct gpio_chip *chip,
138 unsigned offset);
139extern struct gpio_chip *gpio_to_chip(unsigned gpio);
140extern int __must_check gpiochip_reserve(int start, int ngpio);
141
142
143extern int gpiochip_add(struct gpio_chip *chip);
144extern int __must_check gpiochip_remove(struct gpio_chip *chip);
145extern struct gpio_chip *gpiochip_find(void *data,
146 int (*match)(struct gpio_chip *chip,
147 void *data));
148
149
150
151
152
153extern int gpio_request(unsigned gpio, const char *label);
154extern void gpio_free(unsigned gpio);
155
156extern int gpio_direction_input(unsigned gpio);
157extern int gpio_direction_output(unsigned gpio, int value);
158
159extern int gpio_set_debounce(unsigned gpio, unsigned debounce);
160
161extern int gpio_get_value_cansleep(unsigned gpio);
162extern void gpio_set_value_cansleep(unsigned gpio, int value);
163
164
165
166
167
168
169extern int __gpio_get_value(unsigned gpio);
170extern void __gpio_set_value(unsigned gpio, int value);
171
172extern int __gpio_cansleep(unsigned gpio);
173
174extern int __gpio_to_irq(unsigned gpio);
175
176extern int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
177extern int gpio_request_array(const struct gpio *array, size_t num);
178extern void gpio_free_array(const struct gpio *array, size_t num);
179
180
181int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
182void devm_gpio_free(struct device *dev, unsigned int gpio);
183
184#ifdef CONFIG_GPIO_SYSFS
185
186
187
188
189
190extern int gpio_export(unsigned gpio, bool direction_may_change);
191extern int gpio_export_link(struct device *dev, const char *name,
192 unsigned gpio);
193extern int gpio_sysfs_set_active_low(unsigned gpio, int value);
194extern void gpio_unexport(unsigned gpio);
195
196#endif
197
198#else
199
200static inline bool gpio_is_valid(int number)
201{
202
203 return number >= 0;
204}
205
206
207
208
209
210static inline int gpio_cansleep(unsigned gpio)
211{
212 return 0;
213}
214
215static inline int gpio_get_value_cansleep(unsigned gpio)
216{
217 might_sleep();
218 return __gpio_get_value(gpio);
219}
220
221static inline void gpio_set_value_cansleep(unsigned gpio, int value)
222{
223 might_sleep();
224 __gpio_set_value(gpio, value);
225}
226
227#endif
228
229#ifndef CONFIG_GPIO_SYSFS
230
231struct device;
232
233
234
235static inline int gpio_export(unsigned gpio, bool direction_may_change)
236{
237 return -ENOSYS;
238}
239
240static inline int gpio_export_link(struct device *dev, const char *name,
241 unsigned gpio)
242{
243 return -ENOSYS;
244}
245
246static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
247{
248 return -ENOSYS;
249}
250
251static inline void gpio_unexport(unsigned gpio)
252{
253}
254#endif
255
256#endif
257