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#ifndef ARCH_NR_GPIOS
22#define ARCH_NR_GPIOS 256
23#endif
24
25static inline int gpio_is_valid(int number)
26{
27
28 return ((unsigned)number) < ARCH_NR_GPIOS;
29}
30
31struct device;
32struct seq_file;
33struct module;
34
35
36
37
38
39
40
41
42
43
44
45
46
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
77struct gpio_chip {
78 const char *label;
79 struct device *dev;
80 struct module *owner;
81
82 int (*request)(struct gpio_chip *chip,
83 unsigned offset);
84 void (*free)(struct gpio_chip *chip,
85 unsigned offset);
86
87 int (*direction_input)(struct gpio_chip *chip,
88 unsigned offset);
89 int (*get)(struct gpio_chip *chip,
90 unsigned offset);
91 int (*direction_output)(struct gpio_chip *chip,
92 unsigned offset, int value);
93 int (*set_debounce)(struct gpio_chip *chip,
94 unsigned offset, unsigned debounce);
95
96 void (*set)(struct gpio_chip *chip,
97 unsigned offset, int value);
98
99 int (*to_irq)(struct gpio_chip *chip,
100 unsigned offset);
101
102 void (*dbg_show)(struct seq_file *s,
103 struct gpio_chip *chip);
104 int base;
105 u16 ngpio;
106 const char *const *names;
107 unsigned can_sleep:1;
108 unsigned exported:1;
109};
110
111extern const char *gpiochip_is_requested(struct gpio_chip *chip,
112 unsigned offset);
113extern int __must_check gpiochip_reserve(int start, int ngpio);
114
115
116extern int gpiochip_add(struct gpio_chip *chip);
117extern int __must_check gpiochip_remove(struct gpio_chip *chip);
118
119
120
121
122
123extern int gpio_request(unsigned gpio, const char *label);
124extern void gpio_free(unsigned gpio);
125
126extern int gpio_direction_input(unsigned gpio);
127extern int gpio_direction_output(unsigned gpio, int value);
128
129extern int gpio_set_debounce(unsigned gpio, unsigned debounce);
130
131extern int gpio_get_value_cansleep(unsigned gpio);
132extern void gpio_set_value_cansleep(unsigned gpio, int value);
133
134
135
136
137
138
139extern int __gpio_get_value(unsigned gpio);
140extern void __gpio_set_value(unsigned gpio, int value);
141
142extern int __gpio_cansleep(unsigned gpio);
143
144extern int __gpio_to_irq(unsigned gpio);
145
146#define GPIOF_DIR_OUT (0 << 0)
147#define GPIOF_DIR_IN (1 << 0)
148
149#define GPIOF_INIT_LOW (0 << 1)
150#define GPIOF_INIT_HIGH (1 << 1)
151
152#define GPIOF_IN (GPIOF_DIR_IN)
153#define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
154#define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
155
156
157
158
159
160
161
162struct gpio {
163 unsigned gpio;
164 unsigned long flags;
165 const char *label;
166};
167
168extern int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
169extern int gpio_request_array(struct gpio *array, size_t num);
170extern void gpio_free_array(struct gpio *array, size_t num);
171
172#ifdef CONFIG_GPIO_SYSFS
173
174
175
176
177
178extern int gpio_export(unsigned gpio, bool direction_may_change);
179extern int gpio_export_link(struct device *dev, const char *name,
180 unsigned gpio);
181extern int gpio_sysfs_set_active_low(unsigned gpio, int value);
182extern void gpio_unexport(unsigned gpio);
183
184#endif
185
186#else
187
188static inline int gpio_is_valid(int number)
189{
190
191 return number >= 0;
192}
193
194
195
196
197
198static inline int gpio_cansleep(unsigned gpio)
199{
200 return 0;
201}
202
203static inline int gpio_get_value_cansleep(unsigned gpio)
204{
205 might_sleep();
206 return gpio_get_value(gpio);
207}
208
209static inline void gpio_set_value_cansleep(unsigned gpio, int value)
210{
211 might_sleep();
212 gpio_set_value(gpio, value);
213}
214
215#endif
216
217#ifndef CONFIG_GPIO_SYSFS
218
219struct device;
220
221
222
223static inline int gpio_export(unsigned gpio, bool direction_may_change)
224{
225 return -ENOSYS;
226}
227
228static inline int gpio_export_link(struct device *dev, const char *name,
229 unsigned gpio)
230{
231 return -ENOSYS;
232}
233
234static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
235{
236 return -ENOSYS;
237}
238
239static inline void gpio_unexport(unsigned gpio)
240{
241}
242#endif
243
244#endif
245