1#ifndef __LINUX_GPIO_DRIVER_H
2#define __LINUX_GPIO_DRIVER_H
3
4#include <linux/device.h>
5#include <linux/types.h>
6#include <linux/module.h>
7#include <linux/irq.h>
8#include <linux/irqchip/chained_irq.h>
9#include <linux/irqdomain.h>
10#include <linux/pinctrl/pinctrl.h>
11#include <linux/pinctrl/pinconf-generic.h>
12
13struct gpio_desc;
14struct of_phandle_args;
15struct device_node;
16struct seq_file;
17struct gpio_device;
18
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
71struct gpio_chip {
72 const char *label;
73 struct gpio_device *gpiodev;
74 struct device *dev;
75 struct module *owner;
76 void *data;
77
78 int (*request)(struct gpio_chip *chip,
79 unsigned offset);
80 void (*free)(struct gpio_chip *chip,
81 unsigned offset);
82 int (*get_direction)(struct gpio_chip *chip,
83 unsigned offset);
84 int (*direction_input)(struct gpio_chip *chip,
85 unsigned offset);
86 int (*direction_output)(struct gpio_chip *chip,
87 unsigned offset, int value);
88 int (*get)(struct gpio_chip *chip,
89 unsigned offset);
90 void (*set)(struct gpio_chip *chip,
91 unsigned offset, int value);
92 int (*set_config)(struct gpio_chip *chip,
93 unsigned offset,
94 unsigned long config);
95 int (*to_irq)(struct gpio_chip *chip,
96 unsigned offset);
97
98 void (*dbg_show)(struct seq_file *s,
99 struct gpio_chip *chip);
100 int base;
101 u16 ngpio;
102 struct gpio_desc *desc;
103 const char *const *names;
104 bool can_sleep;
105 bool exported;
106
107#ifdef CONFIG_GPIOLIB_IRQCHIP
108
109
110
111
112 struct irq_chip *irqchip;
113 struct irq_domain *irqdomain;
114 unsigned int irq_base;
115 irq_flow_handler_t irq_handler;
116 unsigned int irq_default_type;
117#endif
118
119#if defined(CONFIG_OF_GPIO)
120
121
122
123
124 struct device_node *of_node;
125 int of_gpio_n_cells;
126 int (*of_xlate)(struct gpio_chip *gc,
127 const struct of_phandle_args *gpiospec, u32 *flags);
128#endif
129#ifdef CONFIG_PINCTRL
130
131
132
133
134
135
136 struct list_head pin_ranges;
137#endif
138};
139
140extern const char *gpiochip_is_requested(struct gpio_chip *chip,
141 unsigned offset);
142
143
144extern int gpiochip_add_data(struct gpio_chip *chip, void *data);
145static inline int gpiochip_add(struct gpio_chip *chip)
146{
147 return gpiochip_add_data(chip, NULL);
148}
149extern int gpiochip_remove(struct gpio_chip *chip);
150extern struct gpio_chip *gpiochip_find(void *data,
151 int (*match)(struct gpio_chip *chip, void *data));
152
153
154int gpiod_lock_as_irq(struct gpio_desc *desc);
155void gpiod_unlock_as_irq(struct gpio_desc *desc);
156bool gpiochip_line_is_irq(struct gpio_chip *chip, unsigned int offset);
157
158
159static inline void *gpiochip_get_data(struct gpio_chip *chip)
160{
161 return chip->data;
162}
163
164enum gpio_lookup_flags {
165 GPIO_ACTIVE_HIGH = (0 << 0),
166 GPIO_ACTIVE_LOW = (1 << 0),
167 GPIO_OPEN_DRAIN = (1 << 1),
168 GPIO_OPEN_SOURCE = (1 << 2),
169};
170
171
172
173
174
175
176
177
178
179
180
181
182struct gpiod_lookup {
183 const char *chip_label;
184 u16 chip_hwnum;
185 const char *con_id;
186 unsigned int idx;
187 enum gpio_lookup_flags flags;
188};
189
190struct gpiod_lookup_table {
191 struct list_head list;
192 const char *dev_id;
193 struct gpiod_lookup table[];
194};
195
196
197
198
199#define GPIO_LOOKUP(_chip_label, _chip_hwnum, _con_id, _flags) \
200 GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, 0, _flags)
201
202
203
204
205
206
207#define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, _idx, _flags) \
208{ \
209 .chip_label = _chip_label, \
210 .chip_hwnum = _chip_hwnum, \
211 .con_id = _con_id, \
212 .idx = _idx, \
213 .flags = _flags, \
214}
215
216void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
217
218#ifdef CONFIG_GPIOLIB_IRQCHIP
219
220void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
221 struct irq_chip *irqchip,
222 int parent_irq,
223 irq_flow_handler_t parent_handler);
224
225int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
226 struct irq_chip *irqchip,
227 unsigned int first_irq,
228 irq_flow_handler_t handler,
229 unsigned int type);
230
231#endif
232
233int gpiochip_generic_config(struct gpio_chip *chip, unsigned offset,
234 unsigned long config);
235
236#endif
237