aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/gpio/driver.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-11-14 20:23:44 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-11-14 20:23:44 -0500
commit6aa2f9441f1ef21f10c41f45e6453b135e9cd736 (patch)
tree334e67c4693eddff47a098b9afad63ca2ccfcd55 /include/linux/gpio/driver.h
parente37e0ee0190034a059c9faea8adfb4982fb24ddd (diff)
parent24f0966c3e3f52a96e888504d60810d9df5b2d42 (diff)
Merge tag 'gpio-v4.15-1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO updates from Linus Walleij: "This is the bulk of GPIO changes for the v4.15 kernel cycle: Core: - Fix the semantics of raw GPIO to actually be raw. No inversion semantics as before, but also no open draining, and allow the raw operations to affect lines used for interrupts as the caller supposedly knows what they are doing if they are getting the big hammer. - Rewrote the __inner_function() notation calls to names that make more sense. I just find this kind of code disturbing. - Drop the .irq_base() field from the gpiochip since now all IRQs are mapped dynamically. This is nice. - Support for .get_multiple() in the core driver API. This allows us to read several GPIO lines with a single register read. This has high value for some usecases: it can be used to create oscilloscopes and signal analyzers and other things that rely on reading several lines at exactly the same instant. Also a generally nice optimization. This uses the new assign_bit() macro from the bitops lib that was ACKed by Andrew Morton and is implemented for two drivers, one of them being the generic MMIO driver so everyone using that will be able to benefit from this. - Do not allow requests of Open Drain and Open Source setting of a GPIO line simultaneously. If the hardware actually supports enabling both at the same time the electrical result would be disastrous. - A new interrupt chip core helper. This will be helpful to deal with "banked" GPIOs, which means GPIO controllers with several logical blocks of GPIO inside them. This is several gpiochips per device in the device model, in contrast to the case when there is a 1-to-1 relationship between a device and a gpiochip. New drivers: - Maxim MAX3191x industrial serializer, a very interesting piece of professional I/O hardware. - Uniphier GPIO driver. This is the GPIO block from the recent Socionext (ex Fujitsu and Panasonic) platform. - Tegra 186 driver. This is based on the new banked GPIO infrastructure. Other improvements: - Some documentation improvements. - Wakeup support for the DesignWare DWAPB GPIO controller. - Reset line support on the DesignWare DWAPB GPIO controller. - Several non-critical bug fixes and improvements for the Broadcom BRCMSTB driver. - Misc non-critical bug fixes like exotic errorpaths, removal of dead code etc. - Explicit comments on fall-through switch() statements" * tag 'gpio-v4.15-1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (65 commits) gpio: tegra186: Remove tegra186_gpio_lock_class gpio: rcar: Add r8a77995 (R-Car D3) support pinctrl: bcm2835: Fix some merge fallout gpio: Fix undefined lock_dep_class gpio: Automatically add lockdep keys gpio: Introduce struct gpio_irq_chip.first gpio: Disambiguate struct gpio_irq_chip.nested gpio: Add Tegra186 support gpio: Export gpiochip_irq_{map,unmap}() gpio: Implement tighter IRQ chip integration gpio: Move lock_key into struct gpio_irq_chip gpio: Move irq_valid_mask into struct gpio_irq_chip gpio: Move irq_nested into struct gpio_irq_chip gpio: Move irq_chained_parent to struct gpio_irq_chip gpio: Move irq_default_type to struct gpio_irq_chip gpio: Move irq_handler to struct gpio_irq_chip gpio: Move irqdomain into struct gpio_irq_chip gpio: Move irqchip into struct gpio_irq_chip gpio: Introduce struct gpio_irq_chip pinctrl: armada-37xx: remove unused variable ...
Diffstat (limited to 'include/linux/gpio/driver.h')
-rw-r--r--include/linux/gpio/driver.h215
1 files changed, 182 insertions, 33 deletions
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 424e5139ff10..55e672592fa9 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -20,6 +20,131 @@ struct module;
20 20
21#ifdef CONFIG_GPIOLIB 21#ifdef CONFIG_GPIOLIB
22 22
23#ifdef CONFIG_GPIOLIB_IRQCHIP
24/**
25 * struct gpio_irq_chip - GPIO interrupt controller
26 */
27struct gpio_irq_chip {
28 /**
29 * @chip:
30 *
31 * GPIO IRQ chip implementation, provided by GPIO driver.
32 */
33 struct irq_chip *chip;
34
35 /**
36 * @domain:
37 *
38 * Interrupt translation domain; responsible for mapping between GPIO
39 * hwirq number and Linux IRQ number.
40 */
41 struct irq_domain *domain;
42
43 /**
44 * @domain_ops:
45 *
46 * Table of interrupt domain operations for this IRQ chip.
47 */
48 const struct irq_domain_ops *domain_ops;
49
50 /**
51 * @handler:
52 *
53 * The IRQ handler to use (often a predefined IRQ core function) for
54 * GPIO IRQs, provided by GPIO driver.
55 */
56 irq_flow_handler_t handler;
57
58 /**
59 * @default_type:
60 *
61 * Default IRQ triggering type applied during GPIO driver
62 * initialization, provided by GPIO driver.
63 */
64 unsigned int default_type;
65
66 /**
67 * @lock_key:
68 *
69 * Per GPIO IRQ chip lockdep class.
70 */
71 struct lock_class_key *lock_key;
72
73 /**
74 * @parent_handler:
75 *
76 * The interrupt handler for the GPIO chip's parent interrupts, may be
77 * NULL if the parent interrupts are nested rather than cascaded.
78 */
79 irq_flow_handler_t parent_handler;
80
81 /**
82 * @parent_handler_data:
83 *
84 * Data associated, and passed to, the handler for the parent
85 * interrupt.
86 */
87 void *parent_handler_data;
88
89 /**
90 * @num_parents:
91 *
92 * The number of interrupt parents of a GPIO chip.
93 */
94 unsigned int num_parents;
95
96 /**
97 * @parents:
98 *
99 * A list of interrupt parents of a GPIO chip. This is owned by the
100 * driver, so the core will only reference this list, not modify it.
101 */
102 unsigned int *parents;
103
104 /**
105 * @map:
106 *
107 * A list of interrupt parents for each line of a GPIO chip.
108 */
109 unsigned int *map;
110
111 /**
112 * @threaded:
113 *
114 * True if set the interrupt handling uses nested threads.
115 */
116 bool threaded;
117
118 /**
119 * @need_valid_mask:
120 *
121 * If set core allocates @valid_mask with all bits set to one.
122 */
123 bool need_valid_mask;
124
125 /**
126 * @valid_mask:
127 *
128 * If not %NULL holds bitmask of GPIOs which are valid to be included
129 * in IRQ domain of the chip.
130 */
131 unsigned long *valid_mask;
132
133 /**
134 * @first:
135 *
136 * Required for static IRQ allocation. If set, irq_domain_add_simple()
137 * will allocate and map all IRQs during initialization.
138 */
139 unsigned int first;
140};
141
142static inline struct gpio_irq_chip *to_gpio_irq_chip(struct irq_chip *chip)
143{
144 return container_of(chip, struct gpio_irq_chip, chip);
145}
146#endif
147
23/** 148/**
24 * struct gpio_chip - abstract a GPIO controller 149 * struct gpio_chip - abstract a GPIO controller
25 * @label: a functional name for the GPIO device, such as a part 150 * @label: a functional name for the GPIO device, such as a part
@@ -36,6 +161,8 @@ struct module;
36 * @direction_input: configures signal "offset" as input, or returns error 161 * @direction_input: configures signal "offset" as input, or returns error
37 * @direction_output: configures signal "offset" as output, or returns error 162 * @direction_output: configures signal "offset" as output, or returns error
38 * @get: returns value for signal "offset", 0=low, 1=high, or negative error 163 * @get: returns value for signal "offset", 0=low, 1=high, or negative error
164 * @get_multiple: reads values for multiple signals defined by "mask" and
165 * stores them in "bits", returns 0 on success or negative error
39 * @set: assigns output value for signal "offset" 166 * @set: assigns output value for signal "offset"
40 * @set_multiple: assigns output values for multiple signals defined by "mask" 167 * @set_multiple: assigns output values for multiple signals defined by "mask"
41 * @set_config: optional hook for all kinds of settings. Uses the same 168 * @set_config: optional hook for all kinds of settings. Uses the same
@@ -66,9 +193,9 @@ struct module;
66 * registers. 193 * registers.
67 * @read_reg: reader function for generic GPIO 194 * @read_reg: reader function for generic GPIO
68 * @write_reg: writer function for generic GPIO 195 * @write_reg: writer function for generic GPIO
69 * @pin2mask: some generic GPIO controllers work with the big-endian bits 196 * @be_bits: if the generic GPIO has big endian bit order (bit 31 is representing
70 * notation, e.g. in a 8-bits register, GPIO7 is the least significant 197 * line 0, bit 30 is line 1 ... bit 0 is line 31) this is set to true by the
71 * bit. This callback assigns the right bit mask. 198 * generic GPIO core. It is for internal housekeeping only.
72 * @reg_dat: data (in) register for generic GPIO 199 * @reg_dat: data (in) register for generic GPIO
73 * @reg_set: output set register (out=high) for generic GPIO 200 * @reg_set: output set register (out=high) for generic GPIO
74 * @reg_clr: output clear register (out=low) for generic GPIO 201 * @reg_clr: output clear register (out=low) for generic GPIO
@@ -81,23 +208,6 @@ struct module;
81 * safely. 208 * safely.
82 * @bgpio_dir: shadowed direction register for generic GPIO to clear/set 209 * @bgpio_dir: shadowed direction register for generic GPIO to clear/set
83 * direction safely. 210 * direction safely.
84 * @irqchip: GPIO IRQ chip impl, provided by GPIO driver
85 * @irqdomain: Interrupt translation domain; responsible for mapping
86 * between GPIO hwirq number and linux irq number
87 * @irq_base: first linux IRQ number assigned to GPIO IRQ chip (deprecated)
88 * @irq_handler: the irq handler to use (often a predefined irq core function)
89 * for GPIO IRQs, provided by GPIO driver
90 * @irq_default_type: default IRQ triggering type applied during GPIO driver
91 * initialization, provided by GPIO driver
92 * @irq_chained_parent: GPIO IRQ chip parent/bank linux irq number,
93 * provided by GPIO driver for chained interrupt (not for nested
94 * interrupts).
95 * @irq_nested: True if set the interrupt handling is nested.
96 * @irq_need_valid_mask: If set core allocates @irq_valid_mask with all
97 * bits set to one
98 * @irq_valid_mask: If not %NULL holds bitmask of GPIOs which are valid to
99 * be included in IRQ domain of the chip
100 * @lock_key: per GPIO IRQ chip lockdep class
101 * 211 *
102 * A gpio_chip can help platforms abstract various sources of GPIOs so 212 * A gpio_chip can help platforms abstract various sources of GPIOs so
103 * they can all be accessed through a common programing interface. 213 * they can all be accessed through a common programing interface.
@@ -127,6 +237,9 @@ struct gpio_chip {
127 unsigned offset, int value); 237 unsigned offset, int value);
128 int (*get)(struct gpio_chip *chip, 238 int (*get)(struct gpio_chip *chip,
129 unsigned offset); 239 unsigned offset);
240 int (*get_multiple)(struct gpio_chip *chip,
241 unsigned long *mask,
242 unsigned long *bits);
130 void (*set)(struct gpio_chip *chip, 243 void (*set)(struct gpio_chip *chip,
131 unsigned offset, int value); 244 unsigned offset, int value);
132 void (*set_multiple)(struct gpio_chip *chip, 245 void (*set_multiple)(struct gpio_chip *chip,
@@ -148,7 +261,7 @@ struct gpio_chip {
148#if IS_ENABLED(CONFIG_GPIO_GENERIC) 261#if IS_ENABLED(CONFIG_GPIO_GENERIC)
149 unsigned long (*read_reg)(void __iomem *reg); 262 unsigned long (*read_reg)(void __iomem *reg);
150 void (*write_reg)(void __iomem *reg, unsigned long data); 263 void (*write_reg)(void __iomem *reg, unsigned long data);
151 unsigned long (*pin2mask)(struct gpio_chip *gc, unsigned int pin); 264 bool be_bits;
152 void __iomem *reg_dat; 265 void __iomem *reg_dat;
153 void __iomem *reg_set; 266 void __iomem *reg_set;
154 void __iomem *reg_clr; 267 void __iomem *reg_clr;
@@ -164,16 +277,14 @@ struct gpio_chip {
164 * With CONFIG_GPIOLIB_IRQCHIP we get an irqchip inside the gpiolib 277 * With CONFIG_GPIOLIB_IRQCHIP we get an irqchip inside the gpiolib
165 * to handle IRQs for most practical cases. 278 * to handle IRQs for most practical cases.
166 */ 279 */
167 struct irq_chip *irqchip; 280
168 struct irq_domain *irqdomain; 281 /**
169 unsigned int irq_base; 282 * @irq:
170 irq_flow_handler_t irq_handler; 283 *
171 unsigned int irq_default_type; 284 * Integrates interrupt chip functionality with the GPIO chip. Can be
172 unsigned int irq_chained_parent; 285 * used to handle IRQs for most practical cases.
173 bool irq_nested; 286 */
174 bool irq_need_valid_mask; 287 struct gpio_irq_chip irq;
175 unsigned long *irq_valid_mask;
176 struct lock_class_key *lock_key;
177#endif 288#endif
178 289
179#if defined(CONFIG_OF_GPIO) 290#if defined(CONFIG_OF_GPIO)
@@ -211,7 +322,41 @@ extern const char *gpiochip_is_requested(struct gpio_chip *chip,
211 unsigned offset); 322 unsigned offset);
212 323
213/* add/remove chips */ 324/* add/remove chips */
214extern int gpiochip_add_data(struct gpio_chip *chip, void *data); 325extern int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
326 struct lock_class_key *lock_key);
327
328/**
329 * gpiochip_add_data() - register a gpio_chip
330 * @chip: the chip to register, with chip->base initialized
331 * @data: driver-private data associated with this chip
332 *
333 * Context: potentially before irqs will work
334 *
335 * When gpiochip_add_data() is called very early during boot, so that GPIOs
336 * can be freely used, the chip->parent device must be registered before
337 * the gpio framework's arch_initcall(). Otherwise sysfs initialization
338 * for GPIOs will fail rudely.
339 *
340 * gpiochip_add_data() must only be called after gpiolib initialization,
341 * ie after core_initcall().
342 *
343 * If chip->base is negative, this requests dynamic assignment of
344 * a range of valid GPIOs.
345 *
346 * Returns:
347 * A negative errno if the chip can't be registered, such as because the
348 * chip->base is invalid or already associated with a different chip.
349 * Otherwise it returns zero as a success code.
350 */
351#ifdef CONFIG_LOCKDEP
352#define gpiochip_add_data(chip, data) ({ \
353 static struct lock_class_key key; \
354 gpiochip_add_data_with_key(chip, data, &key); \
355 })
356#else
357#define gpiochip_add_data(chip, data) gpiochip_add_data_with_key(chip, data, NULL)
358#endif
359
215static inline int gpiochip_add(struct gpio_chip *chip) 360static inline int gpiochip_add(struct gpio_chip *chip)
216{ 361{
217 return gpiochip_add_data(chip, NULL); 362 return gpiochip_add_data(chip, NULL);
@@ -265,6 +410,10 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
265 410
266#ifdef CONFIG_GPIOLIB_IRQCHIP 411#ifdef CONFIG_GPIOLIB_IRQCHIP
267 412
413int gpiochip_irq_map(struct irq_domain *d, unsigned int irq,
414 irq_hw_number_t hwirq);
415void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq);
416
268void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip, 417void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
269 struct irq_chip *irqchip, 418 struct irq_chip *irqchip,
270 unsigned int parent_irq, 419 unsigned int parent_irq,
@@ -279,7 +428,7 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip,
279 unsigned int first_irq, 428 unsigned int first_irq,
280 irq_flow_handler_t handler, 429 irq_flow_handler_t handler,
281 unsigned int type, 430 unsigned int type,
282 bool nested, 431 bool threaded,
283 struct lock_class_key *lock_key); 432 struct lock_class_key *lock_key);
284 433
285#ifdef CONFIG_LOCKDEP 434#ifdef CONFIG_LOCKDEP