1#ifndef __LINUX_GPIO_DRIVER_H
2#define __LINUX_GPIO_DRIVER_H
3
4#include <linux/types.h>
5#include <linux/module.h>
6#include <linux/irq.h>
7#include <linux/irqchip/chained_irq.h>
8#include <linux/irqdomain.h>
9#include <linux/lockdep.h>
10#include <linux/pinctrl/pinctrl.h>
11
12struct device;
13struct gpio_desc;
14struct of_phandle_args;
15struct device_node;
16struct seq_file;
17
18#ifdef CONFIG_GPIOLIB
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
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 device *cdev;
94 struct module *owner;
95 struct list_head list;
96
97 int (*request)(struct gpio_chip *chip,
98 unsigned offset);
99 void (*free)(struct gpio_chip *chip,
100 unsigned offset);
101 int (*get_direction)(struct gpio_chip *chip,
102 unsigned offset);
103 int (*direction_input)(struct gpio_chip *chip,
104 unsigned offset);
105 int (*direction_output)(struct gpio_chip *chip,
106 unsigned offset, int value);
107 int (*get)(struct gpio_chip *chip,
108 unsigned offset);
109 void (*set)(struct gpio_chip *chip,
110 unsigned offset, int value);
111 void (*set_multiple)(struct gpio_chip *chip,
112 unsigned long *mask,
113 unsigned long *bits);
114 int (*set_debounce)(struct gpio_chip *chip,
115 unsigned offset,
116 unsigned debounce);
117
118 int (*to_irq)(struct gpio_chip *chip,
119 unsigned offset);
120
121 void (*dbg_show)(struct seq_file *s,
122 struct gpio_chip *chip);
123 int base;
124 u16 ngpio;
125 struct gpio_desc *desc;
126 const char *const *names;
127 bool can_sleep;
128 bool irq_not_threaded;
129
130#ifdef CONFIG_GPIOLIB_IRQCHIP
131
132
133
134
135 struct irq_chip *irqchip;
136 struct irq_domain *irqdomain;
137 unsigned int irq_base;
138 irq_flow_handler_t irq_handler;
139 unsigned int irq_default_type;
140 int irq_parent;
141 struct lock_class_key *lock_key;
142#endif
143
144#if defined(CONFIG_OF_GPIO)
145
146
147
148
149 struct device_node *of_node;
150 int of_gpio_n_cells;
151 int (*of_xlate)(struct gpio_chip *gc,
152 const struct of_phandle_args *gpiospec, u32 *flags);
153#endif
154#ifdef CONFIG_PINCTRL
155
156
157
158
159
160
161 struct list_head pin_ranges;
162#endif
163};
164
165extern const char *gpiochip_is_requested(struct gpio_chip *chip,
166 unsigned offset);
167
168
169extern int gpiochip_add(struct gpio_chip *chip);
170extern void gpiochip_remove(struct gpio_chip *chip);
171extern struct gpio_chip *gpiochip_find(void *data,
172 int (*match)(struct gpio_chip *chip, void *data));
173
174
175int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset);
176void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset);
177
178struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc);
179
180#ifdef CONFIG_GPIOLIB_IRQCHIP
181
182void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
183 struct irq_chip *irqchip,
184 int parent_irq,
185 irq_flow_handler_t parent_handler);
186
187int _gpiochip_irqchip_add(struct gpio_chip *gpiochip,
188 struct irq_chip *irqchip,
189 unsigned int first_irq,
190 irq_flow_handler_t handler,
191 unsigned int type,
192 struct lock_class_key *lock_key);
193
194#ifdef CONFIG_LOCKDEP
195#define gpiochip_irqchip_add(...) \
196( \
197 ({ \
198 static struct lock_class_key _key; \
199 _gpiochip_irqchip_add(__VA_ARGS__, &_key); \
200 }) \
201)
202#else
203#define gpiochip_irqchip_add(...) \
204 _gpiochip_irqchip_add(__VA_ARGS__, NULL)
205#endif
206
207#endif
208
209#ifdef CONFIG_PINCTRL
210
211
212
213
214
215
216
217
218struct gpio_pin_range {
219 struct list_head node;
220 struct pinctrl_dev *pctldev;
221 struct pinctrl_gpio_range range;
222};
223
224int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
225 unsigned int gpio_offset, unsigned int pin_offset,
226 unsigned int npins);
227int gpiochip_add_pingroup_range(struct gpio_chip *chip,
228 struct pinctrl_dev *pctldev,
229 unsigned int gpio_offset, const char *pin_group);
230void gpiochip_remove_pin_ranges(struct gpio_chip *chip);
231
232#else
233
234static inline int
235gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
236 unsigned int gpio_offset, unsigned int pin_offset,
237 unsigned int npins)
238{
239 return 0;
240}
241static inline int
242gpiochip_add_pingroup_range(struct gpio_chip *chip,
243 struct pinctrl_dev *pctldev,
244 unsigned int gpio_offset, const char *pin_group)
245{
246 return 0;
247}
248
249static inline void
250gpiochip_remove_pin_ranges(struct gpio_chip *chip)
251{
252}
253
254#endif
255
256struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
257 const char *label);
258void gpiochip_free_own_desc(struct gpio_desc *desc);
259
260#else
261
262static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
263{
264
265 WARN_ON(1);
266 return ERR_PTR(-ENODEV);
267}
268
269#endif
270
271#endif
272