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