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