aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-01-17 15:32:01 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-17 15:32:01 -0500
commit58cf279acac3080ce03eeea5ca268210b3165fe1 (patch)
tree54997706fbfea2cd9fd4c4044edbd8ecdc154dfb /include/linux
parent6606b342febfd470b4a33acb73e360eeaca1d9bb (diff)
parentc474e348778bdf5b453a2cdff4b2b1f9e000f343 (diff)
Merge tag 'gpio-v4.5-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO updates from Linus Walleij: "Here is the bulk of GPIO changes for v4.5. Notably there are big refactorings mostly by myself, aimed at getting the gpio_chip into a shape that makes me believe I can proceed to preserve state for a proper userspace ABI (character device) that has already been proposed once, but resulted in the feedback that I need to go back and restructure stuff. So I've been restructuring stuff. On the way I ran into brokenness (return code from the get_value() callback) and had to fix it. Also, refactored generic GPIO to be simpler. Some of that is still waiting to trickle down from the subsystems all over the kernel that provide random gpio_chips, I've touched every single GPIO driver in the kernel now, oh man I didn't know I was responsible for so much... Apart from that we're churning along as usual. I took some effort to test and retest so it should merge nicely and we shook out a couple of bugs in -next. Infrastructural changes: - In struct gpio_chip, rename the .dev node to .parent to better reflect the fact that this is not the GPIO struct device abstraction. We will add that soon so this would be totallt confusing. - It was noted that the driver .get_value() callbacks was sometimes reporting negative -ERR values to the gpiolib core, expecting them to be propagated to consumer gpiod_get_value() and gpio_get_value() calls. This was not happening, so as there was a mess of drivers returning negative errors and some returning "anything else than zero" to indicate that a line was active. As some would have bit 31 set to indicate "line active" it clashed with negative error codes. This is fixed by the largeish series clamping values in all drivers with !!value to [0,1] and then augmenting the code to propagate error codes to consumers. (Includes some ACKed patches in other subsystems.) - Add a void *data pointer to struct gpio_chip. The container_of() design pattern is indeed very nice, but we want to reform the struct gpio_chip to be a non-volative, stateless business, and keep states internal to the gpiolib to be able to hold on to the state when adding a proper userspace ABI (character device) further down the road. To achieve this, drivers need a handle at the internal state that is not dependent on their struct gpio_chip() so we add gpiochip_add_data() and gpiochip_get_data() following the pattern of many other subsystems. All the "use gpiochip data pointer" patches transforms drivers to this scheme. - The Generic GPIO chip header has been merged into the general <linux/gpio/driver.h> header, and the custom header for that removed. Instead of having a separate mm_gpio_chip struct for these generic drivers, merge that into struct gpio_chip, simplifying the code and removing the need for separate and confusing includes. Misc improvements: - Stabilize the way GPIOs are looked up from the ACPI legacy specification. - Incremental driver features for PXA, PCA953X, Lantiq (patches from the OpenWRT community), RCAR, Zynq, PL061, 104-idi-48 New drivers: - Add a GPIO chip to the ALSA SoC AC97 driver. - Add a new Broadcom NSP SoC driver (this lands in the pinctrl dir, but the branch is merged here too to account for infrastructural changes). - The sx150x driver now supports the sx1502" * tag 'gpio-v4.5-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (220 commits) gpio: generic: make bgpio_pdata always visible gpiolib: fix chip order in gpio list gpio: mpc8xxx: Do not use gpiochip_get_data() in mpc8xxx_gpio_save_regs() gpio: mm-lantiq: Do not use gpiochip_get_data() in ltq_mm_save_regs() gpio: brcmstb: Allow building driver for BMIPS_GENERIC gpio: brcmstb: Set endian flags for big-endian MIPS gpio: moxart: fix build regression gpio: xilinx: Do not use gpiochip_get_data() in xgpio_save_regs() leds: pca9532: use gpiochip data pointer leds: tca6507: use gpiochip data pointer hid: cp2112: use gpiochip data pointer bcma: gpio: use gpiochip data pointer avr32: gpio: use gpiochip data pointer video: fbdev: via: use gpiochip data pointer gpio: pch: Optimize pch_gpio_get() Revert "pinctrl: lantiq: Implement gpio_chip.to_irq" pinctrl: nsp-gpio: use gpiochip data pointer pinctrl: vt8500-wmt: use gpiochip data pointer pinctrl: exynos5440: use gpiochip data pointer pinctrl: at91-pio4: use gpiochip data pointer ...
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/basic_mmio_gpio.h80
-rw-r--r--include/linux/gpio/driver.h75
-rw-r--r--include/linux/of_gpio.h13
-rw-r--r--include/linux/platform_data/gpio-rcar.h29
4 files changed, 81 insertions, 116 deletions
diff --git a/include/linux/basic_mmio_gpio.h b/include/linux/basic_mmio_gpio.h
deleted file mode 100644
index ed3768f4ecc7..000000000000
--- a/include/linux/basic_mmio_gpio.h
+++ /dev/null
@@ -1,80 +0,0 @@
1/*
2 * Basic memory-mapped GPIO controllers.
3 *
4 * Copyright 2008 MontaVista Software, Inc.
5 * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#ifndef __BASIC_MMIO_GPIO_H
14#define __BASIC_MMIO_GPIO_H
15
16#include <linux/gpio.h>
17#include <linux/types.h>
18#include <linux/compiler.h>
19#include <linux/spinlock_types.h>
20
21struct bgpio_pdata {
22 const char *label;
23 int base;
24 int ngpio;
25};
26
27struct device;
28
29struct bgpio_chip {
30 struct gpio_chip gc;
31
32 unsigned long (*read_reg)(void __iomem *reg);
33 void (*write_reg)(void __iomem *reg, unsigned long data);
34
35 void __iomem *reg_dat;
36 void __iomem *reg_set;
37 void __iomem *reg_clr;
38 void __iomem *reg_dir;
39
40 /* Number of bits (GPIOs): <register width> * 8. */
41 int bits;
42
43 /*
44 * Some GPIO controllers work with the big-endian bits notation,
45 * e.g. in a 8-bits register, GPIO7 is the least significant bit.
46 */
47 unsigned long (*pin2mask)(struct bgpio_chip *bgc, unsigned int pin);
48
49 /*
50 * Used to lock bgpio_chip->data. Also, this is needed to keep
51 * shadowed and real data registers writes together.
52 */
53 spinlock_t lock;
54
55 /* Shadowed data register to clear/set bits safely. */
56 unsigned long data;
57
58 /* Shadowed direction registers to clear/set direction safely. */
59 unsigned long dir;
60};
61
62static inline struct bgpio_chip *to_bgpio_chip(struct gpio_chip *gc)
63{
64 return container_of(gc, struct bgpio_chip, gc);
65}
66
67int bgpio_remove(struct bgpio_chip *bgc);
68int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
69 unsigned long sz, void __iomem *dat, void __iomem *set,
70 void __iomem *clr, void __iomem *dirout, void __iomem *dirin,
71 unsigned long flags);
72
73#define BGPIOF_BIG_ENDIAN BIT(0)
74#define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */
75#define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */
76#define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3)
77#define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */
78#define BGPIOF_NO_OUTPUT BIT(5) /* only input */
79
80#endif /* __BASIC_MMIO_GPIO_H */
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index d1baebf350d8..82fda487453f 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -8,6 +8,7 @@
8#include <linux/irqdomain.h> 8#include <linux/irqdomain.h>
9#include <linux/lockdep.h> 9#include <linux/lockdep.h>
10#include <linux/pinctrl/pinctrl.h> 10#include <linux/pinctrl/pinctrl.h>
11#include <linux/kconfig.h>
11 12
12struct device; 13struct device;
13struct gpio_desc; 14struct gpio_desc;
@@ -20,9 +21,10 @@ struct seq_file;
20/** 21/**
21 * struct gpio_chip - abstract a GPIO controller 22 * struct gpio_chip - abstract a GPIO controller
22 * @label: for diagnostics 23 * @label: for diagnostics
23 * @dev: optional device providing the GPIOs 24 * @parent: optional parent device providing the GPIOs
24 * @cdev: class device used by sysfs interface (may be NULL) 25 * @cdev: class device used by sysfs interface (may be NULL)
25 * @owner: helps prevent removal of modules exporting active GPIOs 26 * @owner: helps prevent removal of modules exporting active GPIOs
27 * @data: per-instance data assigned by the driver
26 * @list: links gpio_chips together for traversal 28 * @list: links gpio_chips together for traversal
27 * @request: optional hook for chip-specific activation, such as 29 * @request: optional hook for chip-specific activation, such as
28 * enabling module power and clock; may sleep 30 * enabling module power and clock; may sleep
@@ -32,8 +34,7 @@ struct seq_file;
32 * (same as GPIOF_DIR_XXX), or negative error 34 * (same as GPIOF_DIR_XXX), or negative error
33 * @direction_input: configures signal "offset" as input, or returns error 35 * @direction_input: configures signal "offset" as input, or returns error
34 * @direction_output: configures signal "offset" as output, or returns error 36 * @direction_output: configures signal "offset" as output, or returns error
35 * @get: returns value for signal "offset"; for output signals this 37 * @get: returns value for signal "offset", 0=low, 1=high, or negative error
36 * returns either the value actually sensed, or zero
37 * @set: assigns output value for signal "offset" 38 * @set: assigns output value for signal "offset"
38 * @set_multiple: assigns output values for multiple signals defined by "mask" 39 * @set_multiple: assigns output values for multiple signals defined by "mask"
39 * @set_debounce: optional hook for setting debounce time for specified gpio in 40 * @set_debounce: optional hook for setting debounce time for specified gpio in
@@ -65,6 +66,23 @@ struct seq_file;
65 * registers. 66 * registers.
66 * @irq_not_threaded: flag must be set if @can_sleep is set but the 67 * @irq_not_threaded: flag must be set if @can_sleep is set but the
67 * IRQs don't need to be threaded 68 * IRQs don't need to be threaded
69 * @read_reg: reader function for generic GPIO
70 * @write_reg: writer function for generic GPIO
71 * @pin2mask: some generic GPIO controllers work with the big-endian bits
72 * notation, e.g. in a 8-bits register, GPIO7 is the least significant
73 * bit. This callback assigns the right bit mask.
74 * @reg_dat: data (in) register for generic GPIO
75 * @reg_set: output set register (out=high) for generic GPIO
76 * @reg_clk: output clear register (out=low) for generic GPIO
77 * @reg_dir: direction setting register for generic GPIO
78 * @bgpio_bits: number of register bits used for a generic GPIO i.e.
79 * <register width> * 8
80 * @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep
81 * shadowed and real data registers writes together.
82 * @bgpio_data: shadowed data register for generic GPIO to clear/set bits
83 * safely.
84 * @bgpio_dir: shadowed direction register for generic GPIO to clear/set
85 * direction safely.
68 * @irqchip: GPIO IRQ chip impl, provided by GPIO driver 86 * @irqchip: GPIO IRQ chip impl, provided by GPIO driver
69 * @irqdomain: Interrupt translation domain; responsible for mapping 87 * @irqdomain: Interrupt translation domain; responsible for mapping
70 * between GPIO hwirq number and linux irq number 88 * between GPIO hwirq number and linux irq number
@@ -89,9 +107,10 @@ struct seq_file;
89 */ 107 */
90struct gpio_chip { 108struct gpio_chip {
91 const char *label; 109 const char *label;
92 struct device *dev; 110 struct device *parent;
93 struct device *cdev; 111 struct device *cdev;
94 struct module *owner; 112 struct module *owner;
113 void *data;
95 struct list_head list; 114 struct list_head list;
96 115
97 int (*request)(struct gpio_chip *chip, 116 int (*request)(struct gpio_chip *chip,
@@ -127,6 +146,20 @@ struct gpio_chip {
127 bool can_sleep; 146 bool can_sleep;
128 bool irq_not_threaded; 147 bool irq_not_threaded;
129 148
149#if IS_ENABLED(CONFIG_GPIO_GENERIC)
150 unsigned long (*read_reg)(void __iomem *reg);
151 void (*write_reg)(void __iomem *reg, unsigned long data);
152 unsigned long (*pin2mask)(struct gpio_chip *gc, unsigned int pin);
153 void __iomem *reg_dat;
154 void __iomem *reg_set;
155 void __iomem *reg_clr;
156 void __iomem *reg_dir;
157 int bgpio_bits;
158 spinlock_t bgpio_lock;
159 unsigned long bgpio_data;
160 unsigned long bgpio_dir;
161#endif
162
130#ifdef CONFIG_GPIOLIB_IRQCHIP 163#ifdef CONFIG_GPIOLIB_IRQCHIP
131 /* 164 /*
132 * With CONFIG_GPIOLIB_IRQCHIP we get an irqchip inside the gpiolib 165 * With CONFIG_GPIOLIB_IRQCHIP we get an irqchip inside the gpiolib
@@ -166,7 +199,11 @@ extern const char *gpiochip_is_requested(struct gpio_chip *chip,
166 unsigned offset); 199 unsigned offset);
167 200
168/* add/remove chips */ 201/* add/remove chips */
169extern int gpiochip_add(struct gpio_chip *chip); 202extern int gpiochip_add_data(struct gpio_chip *chip, void *data);
203static inline int gpiochip_add(struct gpio_chip *chip)
204{
205 return gpiochip_add_data(chip, NULL);
206}
170extern void gpiochip_remove(struct gpio_chip *chip); 207extern void gpiochip_remove(struct gpio_chip *chip);
171extern struct gpio_chip *gpiochip_find(void *data, 208extern struct gpio_chip *gpiochip_find(void *data,
172 int (*match)(struct gpio_chip *chip, void *data)); 209 int (*match)(struct gpio_chip *chip, void *data));
@@ -175,8 +212,36 @@ extern struct gpio_chip *gpiochip_find(void *data,
175int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset); 212int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset);
176void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset); 213void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset);
177 214
215/* get driver data */
216static inline void *gpiochip_get_data(struct gpio_chip *chip)
217{
218 return chip->data;
219}
220
178struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); 221struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc);
179 222
223struct bgpio_pdata {
224 const char *label;
225 int base;
226 int ngpio;
227};
228
229#if IS_ENABLED(CONFIG_GPIO_GENERIC)
230
231int bgpio_init(struct gpio_chip *gc, struct device *dev,
232 unsigned long sz, void __iomem *dat, void __iomem *set,
233 void __iomem *clr, void __iomem *dirout, void __iomem *dirin,
234 unsigned long flags);
235
236#define BGPIOF_BIG_ENDIAN BIT(0)
237#define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */
238#define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */
239#define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3)
240#define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */
241#define BGPIOF_NO_OUTPUT BIT(5) /* only input */
242
243#endif
244
180#ifdef CONFIG_GPIOLIB_IRQCHIP 245#ifdef CONFIG_GPIOLIB_IRQCHIP
181 246
182void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip, 247void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index 87d6d1632dd4..092186c62ff4 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -51,8 +51,14 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
51extern int of_get_named_gpio_flags(struct device_node *np, 51extern int of_get_named_gpio_flags(struct device_node *np,
52 const char *list_name, int index, enum of_gpio_flags *flags); 52 const char *list_name, int index, enum of_gpio_flags *flags);
53 53
54extern int of_mm_gpiochip_add(struct device_node *np, 54extern int of_mm_gpiochip_add_data(struct device_node *np,
55 struct of_mm_gpio_chip *mm_gc); 55 struct of_mm_gpio_chip *mm_gc,
56 void *data);
57static inline int of_mm_gpiochip_add(struct device_node *np,
58 struct of_mm_gpio_chip *mm_gc)
59{
60 return of_mm_gpiochip_add_data(np, mm_gc, NULL);
61}
56extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc); 62extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc);
57 63
58extern int of_gpiochip_add(struct gpio_chip *gc); 64extern int of_gpiochip_add(struct gpio_chip *gc);
@@ -67,6 +73,9 @@ extern int of_gpio_simple_xlate(struct gpio_chip *gc,
67static inline int of_get_named_gpio_flags(struct device_node *np, 73static inline int of_get_named_gpio_flags(struct device_node *np,
68 const char *list_name, int index, enum of_gpio_flags *flags) 74 const char *list_name, int index, enum of_gpio_flags *flags)
69{ 75{
76 if (flags)
77 *flags = 0;
78
70 return -ENOSYS; 79 return -ENOSYS;
71} 80}
72 81
diff --git a/include/linux/platform_data/gpio-rcar.h b/include/linux/platform_data/gpio-rcar.h
deleted file mode 100644
index 2d8d69432813..000000000000
--- a/include/linux/platform_data/gpio-rcar.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/*
2 * Renesas R-Car GPIO Support
3 *
4 * Copyright (C) 2013 Magnus Damm
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#ifndef __GPIO_RCAR_H__
17#define __GPIO_RCAR_H__
18
19struct gpio_rcar_config {
20 int gpio_base;
21 unsigned int irq_base;
22 unsigned int number_of_pins;
23 const char *pctl_name;
24 unsigned has_both_edge_trigger:1;
25};
26
27#define RCAR_GP_PIN(bank, pin) (((bank) * 32) + (pin))
28
29#endif /* __GPIO_RCAR_H__ */