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/pinctrl/pinctrl.h>
10
11struct device;
12struct gpio_desc;
13struct of_phandle_args;
14struct device_node;
15struct seq_file;
16
17#ifdef CONFIG_GPIOLIB
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
71
72
73
74struct gpio_chip {
75 const char *label;
76 struct device *dev;
77 struct module *owner;
78 struct list_head list;
79
80 int (*request)(struct gpio_chip *chip,
81 unsigned offset);
82 void (*free)(struct gpio_chip *chip,
83 unsigned offset);
84 int (*get_direction)(struct gpio_chip *chip,
85 unsigned offset);
86 int (*direction_input)(struct gpio_chip *chip,
87 unsigned offset);
88 int (*direction_output)(struct gpio_chip *chip,
89 unsigned offset, int value);
90 int (*get)(struct gpio_chip *chip,
91 unsigned offset);
92 void (*set)(struct gpio_chip *chip,
93 unsigned offset, int value);
94 void (*set_multiple)(struct gpio_chip *chip,
95 unsigned long *mask,
96 unsigned long *bits);
97 int (*set_debounce)(struct gpio_chip *chip,
98 unsigned offset,
99 unsigned debounce);
100
101 int (*to_irq)(struct gpio_chip *chip,
102 unsigned offset);
103
104 void (*dbg_show)(struct seq_file *s,
105 struct gpio_chip *chip);
106 int base;
107 u16 ngpio;
108 struct gpio_desc *desc;
109 const char *const *names;
110 bool can_sleep;
111 bool irq_not_threaded;
112 bool exported;
113
114#ifdef CONFIG_GPIOLIB_IRQCHIP
115
116
117
118
119 struct irq_chip *irqchip;
120 struct irq_domain *irqdomain;
121 unsigned int irq_base;
122 irq_flow_handler_t irq_handler;
123 unsigned int irq_default_type;
124#endif
125
126#if defined(CONFIG_OF_GPIO)
127
128
129
130
131 struct device_node *of_node;
132 int of_gpio_n_cells;
133 int (*of_xlate)(struct gpio_chip *gc,
134 const struct of_phandle_args *gpiospec, u32 *flags);
135#endif
136#ifdef CONFIG_PINCTRL
137
138
139
140
141
142
143 struct list_head pin_ranges;
144#endif
145};
146
147extern const char *gpiochip_is_requested(struct gpio_chip *chip,
148 unsigned offset);
149
150
151extern int gpiochip_add(struct gpio_chip *chip);
152extern void gpiochip_remove(struct gpio_chip *chip);
153extern struct gpio_chip *gpiochip_find(void *data,
154 int (*match)(struct gpio_chip *chip, void *data));
155
156
157int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset);
158void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset);
159
160struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc);
161
162#ifdef CONFIG_GPIOLIB_IRQCHIP
163
164void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
165 struct irq_chip *irqchip,
166 int parent_irq,
167 irq_flow_handler_t parent_handler);
168
169int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
170 struct irq_chip *irqchip,
171 unsigned int first_irq,
172 irq_flow_handler_t handler,
173 unsigned int type);
174
175#endif
176
177#ifdef CONFIG_PINCTRL
178
179
180
181
182
183
184
185
186struct gpio_pin_range {
187 struct list_head node;
188 struct pinctrl_dev *pctldev;
189 struct pinctrl_gpio_range range;
190};
191
192int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
193 unsigned int gpio_offset, unsigned int pin_offset,
194 unsigned int npins);
195int gpiochip_add_pingroup_range(struct gpio_chip *chip,
196 struct pinctrl_dev *pctldev,
197 unsigned int gpio_offset, const char *pin_group);
198void gpiochip_remove_pin_ranges(struct gpio_chip *chip);
199
200#else
201
202static inline int
203gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
204 unsigned int gpio_offset, unsigned int pin_offset,
205 unsigned int npins)
206{
207 return 0;
208}
209static inline int
210gpiochip_add_pingroup_range(struct gpio_chip *chip,
211 struct pinctrl_dev *pctldev,
212 unsigned int gpio_offset, const char *pin_group)
213{
214 return 0;
215}
216
217static inline void
218gpiochip_remove_pin_ranges(struct gpio_chip *chip)
219{
220}
221
222#endif
223
224struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
225 const char *label);
226void gpiochip_free_own_desc(struct gpio_desc *desc);
227
228#else
229
230static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
231{
232
233 WARN_ON(1);
234 return ERR_PTR(-ENODEV);
235}
236
237#endif
238
239#endif
240