blob: 86f00d908e907468b09d8011dcfacaaf82ced1ef [file] [log] [blame]
Alexandre Courbot79a9bec2013-10-17 10:21:36 -07001#ifndef __LINUX_GPIO_DRIVER_H
2#define __LINUX_GPIO_DRIVER_H
3
Linus Walleijff2b1352015-10-20 11:10:38 +02004#include <linux/device.h>
Alexandre Courbot79a9bec2013-10-17 10:21:36 -07005#include <linux/types.h>
Linus Walleij14250522014-03-25 10:40:18 +01006#include <linux/irq.h>
7#include <linux/irqchip/chained_irq.h>
8#include <linux/irqdomain.h>
Grygorii Strashkoa0a8bcf2015-08-17 15:35:23 +03009#include <linux/lockdep.h>
Linus Walleij964cb342015-03-18 01:56:17 +010010#include <linux/pinctrl/pinctrl.h>
Mika Westerberg2956b5d2017-01-23 15:34:34 +030011#include <linux/pinctrl/pinconf-generic.h>
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070012
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070013struct gpio_desc;
Alexandre Courbotc9a99722013-11-25 18:34:24 +090014struct of_phandle_args;
15struct device_node;
Stephen Rothwellf3ed0b62013-10-29 01:06:23 +110016struct seq_file;
Linus Walleijff2b1352015-10-20 11:10:38 +020017struct gpio_device;
Paul Gortmakerd47529b2016-09-12 18:16:31 -040018struct module;
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070019
Alexandre Courbotbb1e88c2014-02-09 17:43:54 +090020#ifdef CONFIG_GPIOLIB
21
Thierry Redingc44eafd2017-11-07 19:15:45 +010022#ifdef CONFIG_GPIOLIB_IRQCHIP
23/**
24 * struct gpio_irq_chip - GPIO interrupt controller
25 */
26struct gpio_irq_chip {
27 /**
Thierry Redingda80ff82017-11-07 19:15:46 +010028 * @chip:
29 *
30 * GPIO IRQ chip implementation, provided by GPIO driver.
31 */
32 struct irq_chip *chip;
33
34 /**
Thierry Redingf0fbe7b2017-11-07 19:15:47 +010035 * @domain:
36 *
37 * Interrupt translation domain; responsible for mapping between GPIO
38 * hwirq number and Linux IRQ number.
39 */
40 struct irq_domain *domain;
41
42 /**
Thierry Redingc44eafd2017-11-07 19:15:45 +010043 * @domain_ops:
44 *
45 * Table of interrupt domain operations for this IRQ chip.
46 */
47 const struct irq_domain_ops *domain_ops;
48
49 /**
Thierry Redingc7a0aa52017-11-07 19:15:48 +010050 * @handler:
51 *
52 * The IRQ handler to use (often a predefined IRQ core function) for
53 * GPIO IRQs, provided by GPIO driver.
54 */
55 irq_flow_handler_t handler;
56
57 /**
Thierry Reding3634eeb2017-11-07 19:15:49 +010058 * @default_type:
59 *
60 * Default IRQ triggering type applied during GPIO driver
61 * initialization, provided by GPIO driver.
62 */
63 unsigned int default_type;
64
65 /**
Thierry Redingc44eafd2017-11-07 19:15:45 +010066 * @parent_handler:
67 *
68 * The interrupt handler for the GPIO chip's parent interrupts, may be
69 * NULL if the parent interrupts are nested rather than cascaded.
70 */
71 irq_flow_handler_t parent_handler;
72
73 /**
74 * @parent_handler_data:
75 *
76 * Data associated, and passed to, the handler for the parent
77 * interrupt.
78 */
79 void *parent_handler_data;
Thierry Reding39e5f092017-11-07 19:15:50 +010080
81 /**
82 * @num_parents:
83 *
84 * The number of interrupt parents of a GPIO chip.
85 */
86 unsigned int num_parents;
87
88 /**
89 * @parents:
90 *
91 * A list of interrupt parents of a GPIO chip. This is owned by the
92 * driver, so the core will only reference this list, not modify it.
93 */
94 unsigned int *parents;
Thierry Redingc44eafd2017-11-07 19:15:45 +010095};
Thierry Redingda80ff82017-11-07 19:15:46 +010096
97static inline struct gpio_irq_chip *to_gpio_irq_chip(struct irq_chip *chip)
98{
99 return container_of(chip, struct gpio_irq_chip, chip);
100}
Thierry Redingc44eafd2017-11-07 19:15:45 +0100101#endif
102
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700103/**
104 * struct gpio_chip - abstract a GPIO controller
Linus Walleijdf4878e2016-02-12 14:48:23 +0100105 * @label: a functional name for the GPIO device, such as a part
106 * number or the name of the SoC IP-block implementing it.
Linus Walleijff2b1352015-10-20 11:10:38 +0200107 * @gpiodev: the internal state holder, opaque struct
Linus Walleij58383c782015-11-04 09:56:26 +0100108 * @parent: optional parent device providing the GPIOs
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700109 * @owner: helps prevent removal of modules exporting active GPIOs
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700110 * @request: optional hook for chip-specific activation, such as
111 * enabling module power and clock; may sleep
112 * @free: optional hook for chip-specific deactivation, such as
113 * disabling module power and clock; may sleep
114 * @get_direction: returns direction for signal "offset", 0=out, 1=in,
115 * (same as GPIOF_DIR_XXX), or negative error
116 * @direction_input: configures signal "offset" as input, or returns error
117 * @direction_output: configures signal "offset" as output, or returns error
Vladimir Zapolskiy60befd22015-12-22 16:37:28 +0200118 * @get: returns value for signal "offset", 0=low, 1=high, or negative error
Lukas Wunnereec1d562017-10-12 12:40:10 +0200119 * @get_multiple: reads values for multiple signals defined by "mask" and
120 * stores them in "bits", returns 0 on success or negative error
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700121 * @set: assigns output value for signal "offset"
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100122 * @set_multiple: assigns output values for multiple signals defined by "mask"
Mika Westerberg2956b5d2017-01-23 15:34:34 +0300123 * @set_config: optional hook for all kinds of settings. Uses the same
124 * packed config format as generic pinconf.
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700125 * @to_irq: optional hook supporting non-static gpio_to_irq() mappings;
126 * implementation may not sleep
127 * @dbg_show: optional routine to show contents in debugfs; default code
128 * will be used when this is omitted, but custom code can show extra
129 * state (such as pullup/pulldown configuration).
Linus Walleijaf6c2352015-05-13 13:03:21 +0200130 * @base: identifies the first GPIO number handled by this chip;
131 * or, if negative during registration, requests dynamic ID allocation.
132 * DEPRECATION: providing anything non-negative and nailing the base
Geert Uytterhoeven30bb6fb2015-06-15 13:31:33 +0200133 * offset of GPIO chips is deprecated. Please pass -1 as base to
Linus Walleijaf6c2352015-05-13 13:03:21 +0200134 * let gpiolib select the chip base in all possible cases. We want to
135 * get rid of the static GPIO number space in the long run.
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700136 * @ngpio: the number of GPIOs handled by this controller; the last GPIO
137 * handled is (base + ngpio - 1).
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700138 * @names: if set, must be an array of strings to use as alternative
139 * names for the GPIOs in this chip. Any entry in the array
140 * may be NULL if there is no alias for the GPIO, however the
141 * array must be @ngpio entries long. A name can include a single printk
142 * format specifier for an unsigned int. It is substituted by the actual
143 * number of the gpio.
Linus Walleij9fb1f392013-12-04 14:42:46 +0100144 * @can_sleep: flag must be set iff get()/set() methods sleep, as they
Linus Walleij1c8732b2014-04-09 13:34:39 +0200145 * must while accessing GPIO expander chips over I2C or SPI. This
146 * implies that if the chip supports IRQs, these IRQs need to be threaded
147 * as the chip access may sleep when e.g. reading out the IRQ status
148 * registers.
Linus Walleij0f4630f2015-12-04 14:02:58 +0100149 * @read_reg: reader function for generic GPIO
150 * @write_reg: writer function for generic GPIO
Linus Walleij24efd942017-10-20 16:31:27 +0200151 * @be_bits: if the generic GPIO has big endian bit order (bit 31 is representing
152 * line 0, bit 30 is line 1 ... bit 0 is line 31) this is set to true by the
153 * generic GPIO core. It is for internal housekeeping only.
Linus Walleij0f4630f2015-12-04 14:02:58 +0100154 * @reg_dat: data (in) register for generic GPIO
155 * @reg_set: output set register (out=high) for generic GPIO
Anthony Best08bcd3e2016-10-04 14:15:42 -0600156 * @reg_clr: output clear register (out=low) for generic GPIO
Linus Walleij0f4630f2015-12-04 14:02:58 +0100157 * @reg_dir: direction setting register for generic GPIO
158 * @bgpio_bits: number of register bits used for a generic GPIO i.e.
159 * <register width> * 8
160 * @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep
161 * shadowed and real data registers writes together.
162 * @bgpio_data: shadowed data register for generic GPIO to clear/set bits
163 * safely.
164 * @bgpio_dir: shadowed direction register for generic GPIO to clear/set
165 * direction safely.
Linus Walleijd245b3f2016-11-24 10:57:25 +0100166 * @irq_nested: True if set the interrupt handling is nested.
Mika Westerberg79b804c2016-09-20 15:15:21 +0300167 * @irq_need_valid_mask: If set core allocates @irq_valid_mask with all
168 * bits set to one
169 * @irq_valid_mask: If not %NULL holds bitmask of GPIOs which are valid to
170 * be included in IRQ domain of the chip
Grygorii Strashko41d6bb42015-08-17 15:35:24 +0300171 * @lock_key: per GPIO IRQ chip lockdep class
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700172 *
173 * A gpio_chip can help platforms abstract various sources of GPIOs so
174 * they can all be accessed through a common programing interface.
175 * Example sources would be SOC controllers, FPGAs, multifunction
176 * chips, dedicated GPIO expanders, and so on.
177 *
178 * Each chip controls a number of signals, identified in method calls
179 * by "offset" values in the range 0..(@ngpio - 1). When those signals
180 * are referenced through calls like gpio_get_value(gpio), the offset
181 * is calculated by subtracting @base from the gpio number.
182 */
183struct gpio_chip {
184 const char *label;
Linus Walleijff2b1352015-10-20 11:10:38 +0200185 struct gpio_device *gpiodev;
Linus Walleij58383c782015-11-04 09:56:26 +0100186 struct device *parent;
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700187 struct module *owner;
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700188
189 int (*request)(struct gpio_chip *chip,
190 unsigned offset);
191 void (*free)(struct gpio_chip *chip,
192 unsigned offset);
193 int (*get_direction)(struct gpio_chip *chip,
194 unsigned offset);
195 int (*direction_input)(struct gpio_chip *chip,
196 unsigned offset);
197 int (*direction_output)(struct gpio_chip *chip,
198 unsigned offset, int value);
199 int (*get)(struct gpio_chip *chip,
200 unsigned offset);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200201 int (*get_multiple)(struct gpio_chip *chip,
202 unsigned long *mask,
203 unsigned long *bits);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700204 void (*set)(struct gpio_chip *chip,
205 unsigned offset, int value);
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100206 void (*set_multiple)(struct gpio_chip *chip,
207 unsigned long *mask,
208 unsigned long *bits);
Mika Westerberg2956b5d2017-01-23 15:34:34 +0300209 int (*set_config)(struct gpio_chip *chip,
210 unsigned offset,
211 unsigned long config);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700212 int (*to_irq)(struct gpio_chip *chip,
213 unsigned offset);
214
215 void (*dbg_show)(struct seq_file *s,
216 struct gpio_chip *chip);
217 int base;
218 u16 ngpio;
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700219 const char *const *names;
Linus Walleij9fb1f392013-12-04 14:42:46 +0100220 bool can_sleep;
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700221
Linus Walleij0f4630f2015-12-04 14:02:58 +0100222#if IS_ENABLED(CONFIG_GPIO_GENERIC)
223 unsigned long (*read_reg)(void __iomem *reg);
224 void (*write_reg)(void __iomem *reg, unsigned long data);
Linus Walleij24efd942017-10-20 16:31:27 +0200225 bool be_bits;
Linus Walleij0f4630f2015-12-04 14:02:58 +0100226 void __iomem *reg_dat;
227 void __iomem *reg_set;
228 void __iomem *reg_clr;
229 void __iomem *reg_dir;
230 int bgpio_bits;
231 spinlock_t bgpio_lock;
232 unsigned long bgpio_data;
233 unsigned long bgpio_dir;
234#endif
235
Linus Walleij14250522014-03-25 10:40:18 +0100236#ifdef CONFIG_GPIOLIB_IRQCHIP
237 /*
Paul Bolle7d75a872014-09-05 13:09:25 +0200238 * With CONFIG_GPIOLIB_IRQCHIP we get an irqchip inside the gpiolib
Linus Walleij14250522014-03-25 10:40:18 +0100239 * to handle IRQs for most practical cases.
240 */
Linus Walleijd245b3f2016-11-24 10:57:25 +0100241 bool irq_nested;
Mika Westerberg79b804c2016-09-20 15:15:21 +0300242 bool irq_need_valid_mask;
243 unsigned long *irq_valid_mask;
Grygorii Strashkoa0a8bcf2015-08-17 15:35:23 +0300244 struct lock_class_key *lock_key;
Thierry Redingc44eafd2017-11-07 19:15:45 +0100245
246 /**
247 * @irq:
248 *
249 * Integrates interrupt chip functionality with the GPIO chip. Can be
250 * used to handle IRQs for most practical cases.
251 */
252 struct gpio_irq_chip irq;
Linus Walleij14250522014-03-25 10:40:18 +0100253#endif
254
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700255#if defined(CONFIG_OF_GPIO)
256 /*
257 * If CONFIG_OF is enabled, then all GPIO controllers described in the
258 * device tree automatically may have an OF translation
259 */
Thierry Reding67049c52017-07-24 16:57:23 +0200260
261 /**
262 * @of_node:
263 *
264 * Pointer to a device tree node representing this GPIO controller.
265 */
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700266 struct device_node *of_node;
Thierry Reding67049c52017-07-24 16:57:23 +0200267
268 /**
269 * @of_gpio_n_cells:
270 *
271 * Number of cells used to form the GPIO specifier.
272 */
Thierry Redinge3b445d2017-07-24 16:57:28 +0200273 unsigned int of_gpio_n_cells;
Thierry Reding67049c52017-07-24 16:57:23 +0200274
275 /**
276 * @of_xlate:
277 *
278 * Callback to translate a device tree GPIO specifier into a chip-
279 * relative GPIO number and flags.
280 */
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700281 int (*of_xlate)(struct gpio_chip *gc,
282 const struct of_phandle_args *gpiospec, u32 *flags);
283#endif
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700284};
285
286extern const char *gpiochip_is_requested(struct gpio_chip *chip,
287 unsigned offset);
288
289/* add/remove chips */
Linus Walleijb08ea352015-12-03 15:14:13 +0100290extern int gpiochip_add_data(struct gpio_chip *chip, void *data);
291static inline int gpiochip_add(struct gpio_chip *chip)
292{
293 return gpiochip_add_data(chip, NULL);
294}
abdoulaye berthee1db1702014-07-05 18:28:50 +0200295extern void gpiochip_remove(struct gpio_chip *chip);
Laxman Dewangan0cf32922016-02-15 16:32:09 +0530296extern int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *chip,
297 void *data);
298extern void devm_gpiochip_remove(struct device *dev, struct gpio_chip *chip);
299
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700300extern struct gpio_chip *gpiochip_find(void *data,
301 int (*match)(struct gpio_chip *chip, void *data));
302
303/* lock/unlock as IRQ */
Alexandre Courbote3a2e872014-10-23 17:27:07 +0900304int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset);
305void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset);
Linus Walleij6cee3822016-02-11 20:16:45 +0100306bool gpiochip_line_is_irq(struct gpio_chip *chip, unsigned int offset);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700307
Linus Walleij143b65d2016-02-16 15:41:42 +0100308/* Line status inquiry for drivers */
309bool gpiochip_line_is_open_drain(struct gpio_chip *chip, unsigned int offset);
310bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset);
311
Charles Keepax05f479b2017-05-23 15:47:29 +0100312/* Sleep persistence inquiry for drivers */
313bool gpiochip_line_is_persistent(struct gpio_chip *chip, unsigned int offset);
314
Linus Walleijb08ea352015-12-03 15:14:13 +0100315/* get driver data */
Linus Walleij43c54ec2016-02-11 11:37:48 +0100316void *gpiochip_get_data(struct gpio_chip *chip);
Linus Walleijb08ea352015-12-03 15:14:13 +0100317
Alexandre Courbotbb1e88c2014-02-09 17:43:54 +0900318struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc);
319
Linus Walleij0f4630f2015-12-04 14:02:58 +0100320struct bgpio_pdata {
321 const char *label;
322 int base;
323 int ngpio;
324};
325
Arnd Bergmannc474e342016-01-09 22:16:42 +0100326#if IS_ENABLED(CONFIG_GPIO_GENERIC)
327
Linus Walleij0f4630f2015-12-04 14:02:58 +0100328int bgpio_init(struct gpio_chip *gc, struct device *dev,
329 unsigned long sz, void __iomem *dat, void __iomem *set,
330 void __iomem *clr, void __iomem *dirout, void __iomem *dirin,
331 unsigned long flags);
332
333#define BGPIOF_BIG_ENDIAN BIT(0)
334#define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */
335#define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */
336#define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3)
337#define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */
338#define BGPIOF_NO_OUTPUT BIT(5) /* only input */
339
340#endif
341
Linus Walleij14250522014-03-25 10:40:18 +0100342#ifdef CONFIG_GPIOLIB_IRQCHIP
343
344void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
345 struct irq_chip *irqchip,
Thierry Reding6f793092017-04-03 18:05:21 +0200346 unsigned int parent_irq,
Linus Walleij14250522014-03-25 10:40:18 +0100347 irq_flow_handler_t parent_handler);
348
Linus Walleijd245b3f2016-11-24 10:57:25 +0100349void gpiochip_set_nested_irqchip(struct gpio_chip *gpiochip,
350 struct irq_chip *irqchip,
Thierry Reding6f793092017-04-03 18:05:21 +0200351 unsigned int parent_irq);
Linus Walleijd245b3f2016-11-24 10:57:25 +0100352
Linus Walleij739e6f52017-01-11 13:37:07 +0100353int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip,
354 struct irq_chip *irqchip,
355 unsigned int first_irq,
356 irq_flow_handler_t handler,
357 unsigned int type,
358 bool nested,
359 struct lock_class_key *lock_key);
Grygorii Strashkoa0a8bcf2015-08-17 15:35:23 +0300360
Linus Walleij739e6f52017-01-11 13:37:07 +0100361#ifdef CONFIG_LOCKDEP
362
363/*
364 * Lockdep requires that each irqchip instance be created with a
365 * unique key so as to avoid unnecessary warnings. This upfront
366 * boilerplate static inlines provides such a key for each
367 * unique instance.
368 */
369static inline int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
370 struct irq_chip *irqchip,
371 unsigned int first_irq,
372 irq_flow_handler_t handler,
373 unsigned int type)
374{
375 static struct lock_class_key key;
376
377 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq,
378 handler, type, false, &key);
379}
380
Linus Walleijd245b3f2016-11-24 10:57:25 +0100381static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip,
382 struct irq_chip *irqchip,
383 unsigned int first_irq,
384 irq_flow_handler_t handler,
385 unsigned int type)
386{
Linus Walleij739e6f52017-01-11 13:37:07 +0100387
388 static struct lock_class_key key;
389
390 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq,
391 handler, type, true, &key);
392}
393#else
394static inline int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
395 struct irq_chip *irqchip,
396 unsigned int first_irq,
397 irq_flow_handler_t handler,
398 unsigned int type)
399{
400 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq,
401 handler, type, false, NULL);
Linus Walleijd245b3f2016-11-24 10:57:25 +0100402}
403
Linus Walleij739e6f52017-01-11 13:37:07 +0100404static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip,
405 struct irq_chip *irqchip,
406 unsigned int first_irq,
407 irq_flow_handler_t handler,
408 unsigned int type)
409{
410 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq,
411 handler, type, true, NULL);
412}
413#endif /* CONFIG_LOCKDEP */
Linus Walleij14250522014-03-25 10:40:18 +0100414
Paul Bolle7d75a872014-09-05 13:09:25 +0200415#endif /* CONFIG_GPIOLIB_IRQCHIP */
Linus Walleij14250522014-03-25 10:40:18 +0100416
Jonas Gorskic771c2f2015-10-11 17:34:15 +0200417int gpiochip_generic_request(struct gpio_chip *chip, unsigned offset);
418void gpiochip_generic_free(struct gpio_chip *chip, unsigned offset);
Mika Westerberg2956b5d2017-01-23 15:34:34 +0300419int gpiochip_generic_config(struct gpio_chip *chip, unsigned offset,
420 unsigned long config);
Jonas Gorskic771c2f2015-10-11 17:34:15 +0200421
Linus Walleij964cb342015-03-18 01:56:17 +0100422#ifdef CONFIG_PINCTRL
423
424/**
425 * struct gpio_pin_range - pin range controlled by a gpio chip
Thierry Reding950d55f52017-07-24 16:57:22 +0200426 * @node: list for maintaining set of pin ranges, used internally
Linus Walleij964cb342015-03-18 01:56:17 +0100427 * @pctldev: pinctrl device which handles corresponding pins
428 * @range: actual range of pins controlled by a gpio controller
429 */
Linus Walleij964cb342015-03-18 01:56:17 +0100430struct gpio_pin_range {
431 struct list_head node;
432 struct pinctrl_dev *pctldev;
433 struct pinctrl_gpio_range range;
434};
435
436int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
437 unsigned int gpio_offset, unsigned int pin_offset,
438 unsigned int npins);
439int gpiochip_add_pingroup_range(struct gpio_chip *chip,
440 struct pinctrl_dev *pctldev,
441 unsigned int gpio_offset, const char *pin_group);
442void gpiochip_remove_pin_ranges(struct gpio_chip *chip);
443
444#else
445
446static inline int
447gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
448 unsigned int gpio_offset, unsigned int pin_offset,
449 unsigned int npins)
450{
451 return 0;
452}
453static inline int
454gpiochip_add_pingroup_range(struct gpio_chip *chip,
455 struct pinctrl_dev *pctldev,
456 unsigned int gpio_offset, const char *pin_group)
457{
458 return 0;
459}
460
461static inline void
462gpiochip_remove_pin_ranges(struct gpio_chip *chip)
463{
464}
465
466#endif /* CONFIG_PINCTRL */
467
Alexandre Courbotabdc08a2014-08-19 10:06:09 -0700468struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
469 const char *label);
Guenter Roeckf7d4ad92014-07-22 08:01:01 -0700470void gpiochip_free_own_desc(struct gpio_desc *desc);
471
Alexandre Courbotbb1e88c2014-02-09 17:43:54 +0900472#else /* CONFIG_GPIOLIB */
473
474static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
475{
476 /* GPIO can never have been requested */
477 WARN_ON(1);
478 return ERR_PTR(-ENODEV);
479}
480
481#endif /* CONFIG_GPIOLIB */
482
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700483#endif