aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/gpio/cortina,gemini-gpio.txt24
-rw-r--r--Documentation/devicetree/bindings/gpio/gpio-pca953x.txt4
-rw-r--r--Documentation/devicetree/bindings/gpio/gpio.txt8
-rw-r--r--Documentation/gpio/driver.txt64
-rw-r--r--drivers/gpio/Kconfig18
-rw-r--r--drivers/gpio/Makefile2
-rw-r--r--drivers/gpio/devres.c11
-rw-r--r--drivers/gpio/gpio-104-dio-48e.c91
-rw-r--r--drivers/gpio/gpio-104-idi-48.c45
-rw-r--r--drivers/gpio/gpio-104-idio-16.c60
-rw-r--r--drivers/gpio/gpio-bcm-kona.c14
-rw-r--r--drivers/gpio/gpio-davinci.c177
-rw-r--r--drivers/gpio/gpio-dln2.c12
-rw-r--r--drivers/gpio/gpio-dwapb.c14
-rw-r--r--drivers/gpio/gpio-ep93xx.c11
-rw-r--r--drivers/gpio/gpio-exar.c200
-rw-r--r--drivers/gpio/gpio-f7188x.c19
-rw-r--r--drivers/gpio/gpio-gemini.c236
-rw-r--r--drivers/gpio/gpio-gpio-mm.c68
-rw-r--r--drivers/gpio/gpio-intel-mid.c2
-rw-r--r--drivers/gpio/gpio-lp873x.c14
-rw-r--r--drivers/gpio/gpio-max77620.c20
-rw-r--r--drivers/gpio/gpio-mcp23s08.c320
-rw-r--r--drivers/gpio/gpio-menz127.c34
-rw-r--r--drivers/gpio/gpio-merrifield.c14
-rw-r--r--drivers/gpio/gpio-mm-lantiq.c2
-rw-r--r--drivers/gpio/gpio-mockup.c23
-rw-r--r--drivers/gpio/gpio-mvebu.c2
-rw-r--r--drivers/gpio/gpio-omap.c14
-rw-r--r--drivers/gpio/gpio-pca953x.c9
-rw-r--r--drivers/gpio/gpio-rcar.c21
-rw-r--r--drivers/gpio/gpio-stp-xway.c2
-rw-r--r--drivers/gpio/gpio-tc3589x.c15
-rw-r--r--drivers/gpio/gpio-tegra.c14
-rw-r--r--drivers/gpio/gpio-tps65218.c14
-rw-r--r--drivers/gpio/gpio-vx855.c13
-rw-r--r--drivers/gpio/gpio-wcove.c13
-rw-r--r--drivers/gpio/gpio-wm831x.c21
-rw-r--r--drivers/gpio/gpio-wm8994.c13
-rw-r--r--drivers/gpio/gpio-ws16c48.c90
-rw-r--r--drivers/gpio/gpiolib-acpi.c5
-rw-r--r--drivers/gpio/gpiolib-of.c31
-rw-r--r--drivers/gpio/gpiolib.c81
-rw-r--r--drivers/gpio/gpiolib.h3
-rw-r--r--drivers/pinctrl/bcm/pinctrl-bcm281xx.c6
-rw-r--r--drivers/pinctrl/bcm/pinctrl-iproc-gpio.c2
-rw-r--r--drivers/pinctrl/bcm/pinctrl-ns2-mux.c6
-rw-r--r--drivers/pinctrl/bcm/pinctrl-nsp-gpio.c6
-rw-r--r--drivers/pinctrl/core.c29
-rw-r--r--drivers/pinctrl/intel/pinctrl-cherryview.c4
-rw-r--r--drivers/pinctrl/mediatek/pinctrl-mtk-common.c14
-rw-r--r--drivers/pinctrl/meson/pinctrl-meson.c2
-rw-r--r--drivers/pinctrl/pinconf.c12
-rw-r--r--drivers/pinctrl/pinconf.h9
-rw-r--r--drivers/pinctrl/pinctrl-amd.c14
-rw-r--r--drivers/pinctrl/pinctrl-da850-pupd.c2
-rw-r--r--drivers/pinctrl/pinctrl-lpc18xx.c10
-rw-r--r--drivers/pinctrl/pinctrl-max77620.c2
-rw-r--r--drivers/pinctrl/pinctrl-palmas.c2
-rw-r--r--drivers/pinctrl/pinctrl-rockchip.c2
-rw-r--r--drivers/pinctrl/pinctrl-single.c2
-rw-r--r--drivers/pinctrl/pinctrl-sx150x.c55
-rw-r--r--drivers/pinctrl/sirf/pinctrl-atlas7.c3
-rw-r--r--drivers/pinctrl/sunxi/pinctrl-sunxi.c2
-rw-r--r--drivers/pinctrl/uniphier/pinctrl-uniphier-core.c4
-rw-r--r--drivers/pinctrl/vt8500/pinctrl-wmt.c2
-rw-r--r--drivers/rtc/rtc-omap.c2
-rw-r--r--drivers/staging/greybus/gpio.c15
-rw-r--r--drivers/usb/serial/cp210x.c13
-rw-r--r--include/linux/gpio/driver.h37
-rw-r--r--include/linux/pinctrl/consumer.h6
-rw-r--r--include/linux/pinctrl/pinconf-generic.h52
-rw-r--r--include/linux/platform_data/gpio-davinci.h15
-rw-r--r--tools/gpio/.gitignore4
-rw-r--r--tools/gpio/gpio-hammer.c2
75 files changed, 1469 insertions, 735 deletions
diff --git a/Documentation/devicetree/bindings/gpio/cortina,gemini-gpio.txt b/Documentation/devicetree/bindings/gpio/cortina,gemini-gpio.txt
new file mode 100644
index 000000000000..5c9246c054e5
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/cortina,gemini-gpio.txt
@@ -0,0 +1,24 @@
1Cortina Systems Gemini GPIO Controller
2
3Required properties:
4
5- compatible : Must be "cortina,gemini-gpio"
6- reg : Should contain registers location and length
7- interrupts : Should contain the interrupt line for the GPIO block
8- gpio-controller : marks this as a GPIO controller
9- #gpio-cells : Should be 2, see gpio/gpio.txt
10- interrupt-controller : marks this as an interrupt controller
11- #interrupt-cells : a standard two-cell interrupt flag, see
12 interrupt-controller/interrupts.txt
13
14Example:
15
16gpio@4d000000 {
17 compatible = "cortina,gemini-gpio";
18 reg = <0x4d000000 0x100>;
19 interrupts = <22 IRQ_TYPE_LEVEL_HIGH>;
20 gpio-controller;
21 #gpio-cells = <2>;
22 interrupt-controller;
23 #interrupt-cells = <2>;
24};
diff --git a/Documentation/devicetree/bindings/gpio/gpio-pca953x.txt b/Documentation/devicetree/bindings/gpio/gpio-pca953x.txt
index 08dd15f89ba9..e63935710011 100644
--- a/Documentation/devicetree/bindings/gpio/gpio-pca953x.txt
+++ b/Documentation/devicetree/bindings/gpio/gpio-pca953x.txt
@@ -29,6 +29,10 @@ Required properties:
29 onsemi,pca9654 29 onsemi,pca9654
30 exar,xra1202 30 exar,xra1202
31 31
32Optional properties:
33 - reset-gpios: GPIO specification for the RESET input. This is an
34 active low signal to the PCA953x.
35
32Example: 36Example:
33 37
34 38
diff --git a/Documentation/devicetree/bindings/gpio/gpio.txt b/Documentation/devicetree/bindings/gpio/gpio.txt
index 68d28f62a6f4..84ede036f73d 100644
--- a/Documentation/devicetree/bindings/gpio/gpio.txt
+++ b/Documentation/devicetree/bindings/gpio/gpio.txt
@@ -187,10 +187,10 @@ gpio-controller's driver probe function.
187 187
188Each GPIO hog definition is represented as a child node of the GPIO controller. 188Each GPIO hog definition is represented as a child node of the GPIO controller.
189Required properties: 189Required properties:
190- gpio-hog: A property specifying that this child node represent a GPIO hog. 190- gpio-hog: A property specifying that this child node represents a GPIO hog.
191- gpios: Store the GPIO information (id, flags, ...). Shall contain the 191- gpios: Store the GPIO information (id, flags, ...) for each GPIO to
192 number of cells specified in its parent node (GPIO controller 192 affect. Shall contain an integer multiple of the number of cells
193 node). 193 specified in its parent node (GPIO controller node).
194Only one of the following properties scanned in the order shown below. 194Only one of the following properties scanned in the order shown below.
195This means that when multiple properties are present they will be searched 195This means that when multiple properties are present they will be searched
196in the order presented below and the first match is taken as the intended 196in the order presented below and the first match is taken as the intended
diff --git a/Documentation/gpio/driver.txt b/Documentation/gpio/driver.txt
index 747c721776ed..fc1d2f83564d 100644
--- a/Documentation/gpio/driver.txt
+++ b/Documentation/gpio/driver.txt
@@ -41,34 +41,71 @@ In the gpiolib framework each GPIO controller is packaged as a "struct
41gpio_chip" (see linux/gpio/driver.h for its complete definition) with members 41gpio_chip" (see linux/gpio/driver.h for its complete definition) with members
42common to each controller of that type: 42common to each controller of that type:
43 43
44 - methods to establish GPIO direction 44 - methods to establish GPIO line direction
45 - methods used to access GPIO values 45 - methods used to access GPIO line values
46 - method to return the IRQ number associated to a given GPIO 46 - method to set electrical configuration to a a given GPIO line
47 - method to return the IRQ number associated to a given GPIO line
47 - flag saying whether calls to its methods may sleep 48 - flag saying whether calls to its methods may sleep
49 - optional line names array to identify lines
48 - optional debugfs dump method (showing extra state like pullup config) 50 - optional debugfs dump method (showing extra state like pullup config)
49 - optional base number (will be automatically assigned if omitted) 51 - optional base number (will be automatically assigned if omitted)
50 - label for diagnostics and GPIOs mapping using platform data 52 - optional label for diagnostics and GPIO chip mapping using platform data
51 53
52The code implementing a gpio_chip should support multiple instances of the 54The code implementing a gpio_chip should support multiple instances of the
53controller, possibly using the driver model. That code will configure each 55controller, possibly using the driver model. That code will configure each
54gpio_chip and issue gpiochip_add(). Removing a GPIO controller should be rare; 56gpio_chip and issue gpiochip_add[_data]() or devm_gpiochip_add_data().
55use gpiochip_remove() when it is unavoidable. 57Removing a GPIO controller should be rare; use [devm_]gpiochip_remove() when
58it is unavoidable.
56 59
57Most often a gpio_chip is part of an instance-specific structure with state not 60Often a gpio_chip is part of an instance-specific structure with states not
58exposed by the GPIO interfaces, such as addressing, power management, and more. 61exposed by the GPIO interfaces, such as addressing, power management, and more.
59Chips such as codecs will have complex non-GPIO state. 62Chips such as audio codecs will have complex non-GPIO states.
60 63
61Any debugfs dump method should normally ignore signals which haven't been 64Any debugfs dump method should normally ignore signals which haven't been
62requested as GPIOs. They can use gpiochip_is_requested(), which returns either 65requested as GPIOs. They can use gpiochip_is_requested(), which returns either
63NULL or the label associated with that GPIO when it was requested. 66NULL or the label associated with that GPIO when it was requested.
64 67
65RT_FULL: GPIO driver should not use spinlock_t or any sleepable APIs 68RT_FULL: the GPIO driver should not use spinlock_t or any sleepable APIs
66(like PM runtime) in its gpio_chip implementation (.get/.set and direction 69(like PM runtime) in its gpio_chip implementation (.get/.set and direction
67control callbacks) if it is expected to call GPIO APIs from atomic context 70control callbacks) if it is expected to call GPIO APIs from atomic context
68on -RT (inside hard IRQ handlers and similar contexts). Normally this should 71on -RT (inside hard IRQ handlers and similar contexts). Normally this should
69not be required. 72not be required.
70 73
71 74
75GPIO electrical configuration
76-----------------------------
77
78GPIOs can be configured for several electrical modes of operation by using the
79.set_config() callback. Currently this API supports setting debouncing and
80single-ended modes (open drain/open source). These settings are described
81below.
82
83The .set_config() callback uses the same enumerators and configuration
84semantics as the generic pin control drivers. This is not a coincidence: it is
85possible to assign the .set_config() to the function gpiochip_generic_config()
86which will result in pinctrl_gpio_set_config() being called and eventually
87ending up in the pin control back-end "behind" the GPIO controller, usually
88closer to the actual pins. This way the pin controller can manage the below
89listed GPIO configurations.
90
91
92GPIOs with debounce support
93---------------------------
94
95Debouncing is a configuration set to a pin indicating that it is connected to
96a mechanical switch or button, or similar that may bounce. Bouncing means the
97line is pulled high/low quickly at very short intervals for mechanical
98reasons. This can result in the value being unstable or irqs fireing repeatedly
99unless the line is debounced.
100
101Debouncing in practice involves setting up a timer when something happens on
102the line, wait a little while and then sample the line again, so see if it
103still has the same value (low or high). This could also be repeated by a clever
104state machine, waiting for a line to become stable. In either case, it sets
105a certain number of milliseconds for debouncing, or just "on/off" if that time
106is not configurable.
107
108
72GPIOs with open drain/source support 109GPIOs with open drain/source support
73------------------------------------ 110------------------------------------
74 111
@@ -146,10 +183,11 @@ a pull-up resistor is needed on the outgoing rail to complete the circuit, and
146in the second case, a pull-down resistor is needed on the rail. 183in the second case, a pull-down resistor is needed on the rail.
147 184
148Hardware that supports open drain or open source or both, can implement a 185Hardware that supports open drain or open source or both, can implement a
149special callback in the gpio_chip: .set_single_ended() that takes an enum flag 186special callback in the gpio_chip: .set_config() that takes a generic
150telling whether to configure the line as open drain, open source or push-pull. 187pinconf packed value telling whether to configure the line as open drain,
151This will happen in response to the GPIO_OPEN_DRAIN or GPIO_OPEN_SOURCE flag 188open source or push-pull. This will happen in response to the
152set in the machine file, or coming from other hardware descriptions. 189GPIO_OPEN_DRAIN or GPIO_OPEN_SOURCE flag set in the machine file, or coming
190from other hardware descriptions.
153 191
154If this state can not be configured in hardware, i.e. if the GPIO hardware does 192If this state can not be configured in hardware, i.e. if the GPIO hardware does
155not support open drain/open source in hardware, the GPIO library will instead 193not support open drain/open source in hardware, the GPIO library will instead
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index d5d36549ecc1..28e621900a14 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -185,6 +185,13 @@ config GPIO_ETRAXFS
185 help 185 help
186 Say yes here to support the GPIO controller on Axis ETRAX FS SoCs. 186 Say yes here to support the GPIO controller on Axis ETRAX FS SoCs.
187 187
188config GPIO_EXAR
189 tristate "Support for GPIO pins on XR17V352/354/358"
190 depends on SERIAL_8250_EXAR
191 help
192 Selecting this option will enable handling of GPIO pins present
193 on Exar XR17V352/354/358 chips.
194
188config GPIO_GE_FPGA 195config GPIO_GE_FPGA
189 bool "GE FPGA based GPIO" 196 bool "GE FPGA based GPIO"
190 depends on GE_FPGA 197 depends on GE_FPGA
@@ -197,6 +204,15 @@ config GPIO_GE_FPGA
197 and write pin state) for GPIO implemented in a number of GE single 204 and write pin state) for GPIO implemented in a number of GE single
198 board computers. 205 board computers.
199 206
207config GPIO_GEMINI
208 bool "Gemini GPIO"
209 depends on ARCH_GEMINI
210 depends on OF_GPIO
211 select GPIO_GENERIC
212 select GPIOLIB_IRQCHIP
213 help
214 Support for common GPIOs found in Cortina systems Gemini platforms.
215
200config GPIO_GENERIC_PLATFORM 216config GPIO_GENERIC_PLATFORM
201 tristate "Generic memory-mapped GPIO controller support (MMIO platform device)" 217 tristate "Generic memory-mapped GPIO controller support (MMIO platform device)"
202 select GPIO_GENERIC 218 select GPIO_GENERIC
@@ -1197,6 +1213,8 @@ config GPIO_MCP23S08
1197 tristate "Microchip MCP23xxx I/O expander" 1213 tristate "Microchip MCP23xxx I/O expander"
1198 depends on OF_GPIO 1214 depends on OF_GPIO
1199 select GPIOLIB_IRQCHIP 1215 select GPIOLIB_IRQCHIP
1216 select REGMAP_I2C if I2C
1217 select REGMAP if SPI_MASTER
1200 help 1218 help
1201 SPI/I2C driver for Microchip MCP23S08/MCP23S17/MCP23008/MCP23017 1219 SPI/I2C driver for Microchip MCP23S08/MCP23S17/MCP23008/MCP23017
1202 I/O expanders. 1220 I/O expanders.
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index a7676b82de6f..ee8b0dcac623 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -46,8 +46,10 @@ obj-$(CONFIG_GPIO_DWAPB) += gpio-dwapb.o
46obj-$(CONFIG_GPIO_EM) += gpio-em.o 46obj-$(CONFIG_GPIO_EM) += gpio-em.o
47obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o 47obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o
48obj-$(CONFIG_GPIO_ETRAXFS) += gpio-etraxfs.o 48obj-$(CONFIG_GPIO_ETRAXFS) += gpio-etraxfs.o
49obj-$(CONFIG_GPIO_EXAR) += gpio-exar.o
49obj-$(CONFIG_GPIO_F7188X) += gpio-f7188x.o 50obj-$(CONFIG_GPIO_F7188X) += gpio-f7188x.o
50obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o 51obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o
52obj-$(CONFIG_GPIO_GEMINI) += gpio-gemini.o
51obj-$(CONFIG_GPIO_GPIO_MM) += gpio-gpio-mm.o 53obj-$(CONFIG_GPIO_GPIO_MM) += gpio-gpio-mm.o
52obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o 54obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o
53obj-$(CONFIG_HTC_EGPIO) += gpio-htc-egpio.o 55obj-$(CONFIG_HTC_EGPIO) += gpio-htc-egpio.o
diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c
index b2bbcaae6a1f..7031eea165c9 100644
--- a/drivers/gpio/devres.c
+++ b/drivers/gpio/devres.c
@@ -11,7 +11,7 @@
11 * 11 *
12 * This file is based on kernel/irq/devres.c 12 * This file is based on kernel/irq/devres.c
13 * 13 *
14 * Copyright (c) 2011 John Crispin <blogic@openwrt.org> 14 * Copyright (c) 2011 John Crispin <john@phrozen.org>
15 */ 15 */
16 16
17#include <linux/module.h> 17#include <linux/module.h>
@@ -21,6 +21,8 @@
21#include <linux/device.h> 21#include <linux/device.h>
22#include <linux/gfp.h> 22#include <linux/gfp.h>
23 23
24#include "gpiolib.h"
25
24static void devm_gpiod_release(struct device *dev, void *res) 26static void devm_gpiod_release(struct device *dev, void *res)
25{ 27{
26 struct gpio_desc **desc = res; 28 struct gpio_desc **desc = res;
@@ -143,7 +145,6 @@ struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
143 enum gpiod_flags flags, 145 enum gpiod_flags flags,
144 const char *label) 146 const char *label)
145{ 147{
146 static const char * const suffixes[] = { "gpios", "gpio" };
147 char prop_name[32]; /* 32 is max size of property name */ 148 char prop_name[32]; /* 32 is max size of property name */
148 struct gpio_desc **dr; 149 struct gpio_desc **dr;
149 struct gpio_desc *desc; 150 struct gpio_desc *desc;
@@ -154,13 +155,13 @@ struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
154 if (!dr) 155 if (!dr)
155 return ERR_PTR(-ENOMEM); 156 return ERR_PTR(-ENOMEM);
156 157
157 for (i = 0; i < ARRAY_SIZE(suffixes); i++) { 158 for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
158 if (con_id) 159 if (con_id)
159 snprintf(prop_name, sizeof(prop_name), "%s-%s", 160 snprintf(prop_name, sizeof(prop_name), "%s-%s",
160 con_id, suffixes[i]); 161 con_id, gpio_suffixes[i]);
161 else 162 else
162 snprintf(prop_name, sizeof(prop_name), "%s", 163 snprintf(prop_name, sizeof(prop_name), "%s",
163 suffixes[i]); 164 gpio_suffixes[i]);
164 165
165 desc = fwnode_get_named_gpiod(child, prop_name, index, flags, 166 desc = fwnode_get_named_gpiod(child, prop_name, index, flags,
166 label); 167 label);
diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c
index fcf776971ca9..17bd2ab4ebe2 100644
--- a/drivers/gpio/gpio-104-dio-48e.c
+++ b/drivers/gpio/gpio-104-dio-48e.c
@@ -48,7 +48,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-DIO-48E interrupt line numbers");
48 * @control: Control registers state 48 * @control: Control registers state
49 * @lock: synchronization lock to prevent I/O race conditions 49 * @lock: synchronization lock to prevent I/O race conditions
50 * @base: base port address of the GPIO device 50 * @base: base port address of the GPIO device
51 * @irq: Interrupt line number
52 * @irq_mask: I/O bits affected by interrupts 51 * @irq_mask: I/O bits affected by interrupts
53 */ 52 */
54struct dio48e_gpio { 53struct dio48e_gpio {
@@ -58,7 +57,6 @@ struct dio48e_gpio {
58 unsigned char control[2]; 57 unsigned char control[2];
59 spinlock_t lock; 58 spinlock_t lock;
60 unsigned base; 59 unsigned base;
61 unsigned irq;
62 unsigned char irq_mask; 60 unsigned char irq_mask;
63}; 61};
64 62
@@ -204,6 +202,44 @@ static void dio48e_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
204 spin_unlock_irqrestore(&dio48egpio->lock, flags); 202 spin_unlock_irqrestore(&dio48egpio->lock, flags);
205} 203}
206 204
205static void dio48e_gpio_set_multiple(struct gpio_chip *chip,
206 unsigned long *mask, unsigned long *bits)
207{
208 struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
209 unsigned int i;
210 const unsigned int gpio_reg_size = 8;
211 unsigned int port;
212 unsigned int out_port;
213 unsigned int bitmask;
214 unsigned long flags;
215
216 /* set bits are evaluated a gpio register size at a time */
217 for (i = 0; i < chip->ngpio; i += gpio_reg_size) {
218 /* no more set bits in this mask word; skip to the next word */
219 if (!mask[BIT_WORD(i)]) {
220 i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size;
221 continue;
222 }
223
224 port = i / gpio_reg_size;
225 out_port = (port > 2) ? port + 1 : port;
226 bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)];
227
228 spin_lock_irqsave(&dio48egpio->lock, flags);
229
230 /* update output state data and set device gpio register */
231 dio48egpio->out_state[port] &= ~mask[BIT_WORD(i)];
232 dio48egpio->out_state[port] |= bitmask;
233 outb(dio48egpio->out_state[port], dio48egpio->base + out_port);
234
235 spin_unlock_irqrestore(&dio48egpio->lock, flags);
236
237 /* prepare for next gpio register set */
238 mask[BIT_WORD(i)] >>= gpio_reg_size;
239 bits[BIT_WORD(i)] >>= gpio_reg_size;
240 }
241}
242
207static void dio48e_irq_ack(struct irq_data *data) 243static void dio48e_irq_ack(struct irq_data *data)
208{ 244{
209} 245}
@@ -302,6 +338,26 @@ static irqreturn_t dio48e_irq_handler(int irq, void *dev_id)
302 return IRQ_HANDLED; 338 return IRQ_HANDLED;
303} 339}
304 340
341#define DIO48E_NGPIO 48
342static const char *dio48e_names[DIO48E_NGPIO] = {
343 "PPI Group 0 Port A 0", "PPI Group 0 Port A 1", "PPI Group 0 Port A 2",
344 "PPI Group 0 Port A 3", "PPI Group 0 Port A 4", "PPI Group 0 Port A 5",
345 "PPI Group 0 Port A 6", "PPI Group 0 Port A 7", "PPI Group 0 Port B 0",
346 "PPI Group 0 Port B 1", "PPI Group 0 Port B 2", "PPI Group 0 Port B 3",
347 "PPI Group 0 Port B 4", "PPI Group 0 Port B 5", "PPI Group 0 Port B 6",
348 "PPI Group 0 Port B 7", "PPI Group 0 Port C 0", "PPI Group 0 Port C 1",
349 "PPI Group 0 Port C 2", "PPI Group 0 Port C 3", "PPI Group 0 Port C 4",
350 "PPI Group 0 Port C 5", "PPI Group 0 Port C 6", "PPI Group 0 Port C 7",
351 "PPI Group 1 Port A 0", "PPI Group 1 Port A 1", "PPI Group 1 Port A 2",
352 "PPI Group 1 Port A 3", "PPI Group 1 Port A 4", "PPI Group 1 Port A 5",
353 "PPI Group 1 Port A 6", "PPI Group 1 Port A 7", "PPI Group 1 Port B 0",
354 "PPI Group 1 Port B 1", "PPI Group 1 Port B 2", "PPI Group 1 Port B 3",
355 "PPI Group 1 Port B 4", "PPI Group 1 Port B 5", "PPI Group 1 Port B 6",
356 "PPI Group 1 Port B 7", "PPI Group 1 Port C 0", "PPI Group 1 Port C 1",
357 "PPI Group 1 Port C 2", "PPI Group 1 Port C 3", "PPI Group 1 Port C 4",
358 "PPI Group 1 Port C 5", "PPI Group 1 Port C 6", "PPI Group 1 Port C 7"
359};
360
305static int dio48e_probe(struct device *dev, unsigned int id) 361static int dio48e_probe(struct device *dev, unsigned int id)
306{ 362{
307 struct dio48e_gpio *dio48egpio; 363 struct dio48e_gpio *dio48egpio;
@@ -322,20 +378,19 @@ static int dio48e_probe(struct device *dev, unsigned int id)
322 dio48egpio->chip.parent = dev; 378 dio48egpio->chip.parent = dev;
323 dio48egpio->chip.owner = THIS_MODULE; 379 dio48egpio->chip.owner = THIS_MODULE;
324 dio48egpio->chip.base = -1; 380 dio48egpio->chip.base = -1;
325 dio48egpio->chip.ngpio = 48; 381 dio48egpio->chip.ngpio = DIO48E_NGPIO;
382 dio48egpio->chip.names = dio48e_names;
326 dio48egpio->chip.get_direction = dio48e_gpio_get_direction; 383 dio48egpio->chip.get_direction = dio48e_gpio_get_direction;
327 dio48egpio->chip.direction_input = dio48e_gpio_direction_input; 384 dio48egpio->chip.direction_input = dio48e_gpio_direction_input;
328 dio48egpio->chip.direction_output = dio48e_gpio_direction_output; 385 dio48egpio->chip.direction_output = dio48e_gpio_direction_output;
329 dio48egpio->chip.get = dio48e_gpio_get; 386 dio48egpio->chip.get = dio48e_gpio_get;
330 dio48egpio->chip.set = dio48e_gpio_set; 387 dio48egpio->chip.set = dio48e_gpio_set;
388 dio48egpio->chip.set_multiple = dio48e_gpio_set_multiple;
331 dio48egpio->base = base[id]; 389 dio48egpio->base = base[id];
332 dio48egpio->irq = irq[id];
333 390
334 spin_lock_init(&dio48egpio->lock); 391 spin_lock_init(&dio48egpio->lock);
335 392
336 dev_set_drvdata(dev, dio48egpio); 393 err = devm_gpiochip_add_data(dev, &dio48egpio->chip, dio48egpio);
337
338 err = gpiochip_add_data(&dio48egpio->chip, dio48egpio);
339 if (err) { 394 if (err) {
340 dev_err(dev, "GPIO registering failed (%d)\n", err); 395 dev_err(dev, "GPIO registering failed (%d)\n", err);
341 return err; 396 return err;
@@ -360,30 +415,17 @@ static int dio48e_probe(struct device *dev, unsigned int id)
360 handle_edge_irq, IRQ_TYPE_NONE); 415 handle_edge_irq, IRQ_TYPE_NONE);
361 if (err) { 416 if (err) {
362 dev_err(dev, "Could not add irqchip (%d)\n", err); 417 dev_err(dev, "Could not add irqchip (%d)\n", err);
363 goto err_gpiochip_remove; 418 return err;
364 } 419 }
365 420
366 err = request_irq(irq[id], dio48e_irq_handler, 0, name, dio48egpio); 421 err = devm_request_irq(dev, irq[id], dio48e_irq_handler, 0, name,
422 dio48egpio);
367 if (err) { 423 if (err) {
368 dev_err(dev, "IRQ handler registering failed (%d)\n", err); 424 dev_err(dev, "IRQ handler registering failed (%d)\n", err);
369 goto err_gpiochip_remove; 425 return err;
370 } 426 }
371 427
372 return 0; 428 return 0;
373
374err_gpiochip_remove:
375 gpiochip_remove(&dio48egpio->chip);
376 return err;
377}
378
379static int dio48e_remove(struct device *dev, unsigned int id)
380{
381 struct dio48e_gpio *const dio48egpio = dev_get_drvdata(dev);
382
383 free_irq(dio48egpio->irq, dio48egpio);
384 gpiochip_remove(&dio48egpio->chip);
385
386 return 0;
387} 429}
388 430
389static struct isa_driver dio48e_driver = { 431static struct isa_driver dio48e_driver = {
@@ -391,7 +433,6 @@ static struct isa_driver dio48e_driver = {
391 .driver = { 433 .driver = {
392 .name = "104-dio-48e" 434 .name = "104-dio-48e"
393 }, 435 },
394 .remove = dio48e_remove
395}; 436};
396module_isa_driver(dio48e_driver, num_dio48e); 437module_isa_driver(dio48e_driver, num_dio48e);
397 438
diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c
index 2d2763ea1a68..568375a7ebc2 100644
--- a/drivers/gpio/gpio-104-idi-48.c
+++ b/drivers/gpio/gpio-104-idi-48.c
@@ -47,7 +47,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-IDI-48 interrupt line numbers");
47 * @ack_lock: synchronization lock to prevent IRQ handler race conditions 47 * @ack_lock: synchronization lock to prevent IRQ handler race conditions
48 * @irq_mask: input bits affected by interrupts 48 * @irq_mask: input bits affected by interrupts
49 * @base: base port address of the GPIO device 49 * @base: base port address of the GPIO device
50 * @irq: Interrupt line number
51 * @cos_enb: Change-Of-State IRQ enable boundaries mask 50 * @cos_enb: Change-Of-State IRQ enable boundaries mask
52 */ 51 */
53struct idi_48_gpio { 52struct idi_48_gpio {
@@ -56,7 +55,6 @@ struct idi_48_gpio {
56 spinlock_t ack_lock; 55 spinlock_t ack_lock;
57 unsigned char irq_mask[6]; 56 unsigned char irq_mask[6];
58 unsigned base; 57 unsigned base;
59 unsigned irq;
60 unsigned char cos_enb; 58 unsigned char cos_enb;
61}; 59};
62 60
@@ -219,6 +217,18 @@ static irqreturn_t idi_48_irq_handler(int irq, void *dev_id)
219 return IRQ_HANDLED; 217 return IRQ_HANDLED;
220} 218}
221 219
220#define IDI48_NGPIO 48
221static const char *idi48_names[IDI48_NGPIO] = {
222 "Bit 0 A", "Bit 1 A", "Bit 2 A", "Bit 3 A", "Bit 4 A", "Bit 5 A",
223 "Bit 6 A", "Bit 7 A", "Bit 8 A", "Bit 9 A", "Bit 10 A", "Bit 11 A",
224 "Bit 12 A", "Bit 13 A", "Bit 14 A", "Bit 15 A", "Bit 16 A", "Bit 17 A",
225 "Bit 18 A", "Bit 19 A", "Bit 20 A", "Bit 21 A", "Bit 22 A", "Bit 23 A",
226 "Bit 0 B", "Bit 1 B", "Bit 2 B", "Bit 3 B", "Bit 4 B", "Bit 5 B",
227 "Bit 6 B", "Bit 7 B", "Bit 8 B", "Bit 9 B", "Bit 10 B", "Bit 11 B",
228 "Bit 12 B", "Bit 13 B", "Bit 14 B", "Bit 15 B", "Bit 16 B", "Bit 17 B",
229 "Bit 18 B", "Bit 19 B", "Bit 20 B", "Bit 21 B", "Bit 22 B", "Bit 23 B"
230};
231
222static int idi_48_probe(struct device *dev, unsigned int id) 232static int idi_48_probe(struct device *dev, unsigned int id)
223{ 233{
224 struct idi_48_gpio *idi48gpio; 234 struct idi_48_gpio *idi48gpio;
@@ -239,19 +249,17 @@ static int idi_48_probe(struct device *dev, unsigned int id)
239 idi48gpio->chip.parent = dev; 249 idi48gpio->chip.parent = dev;
240 idi48gpio->chip.owner = THIS_MODULE; 250 idi48gpio->chip.owner = THIS_MODULE;
241 idi48gpio->chip.base = -1; 251 idi48gpio->chip.base = -1;
242 idi48gpio->chip.ngpio = 48; 252 idi48gpio->chip.ngpio = IDI48_NGPIO;
253 idi48gpio->chip.names = idi48_names;
243 idi48gpio->chip.get_direction = idi_48_gpio_get_direction; 254 idi48gpio->chip.get_direction = idi_48_gpio_get_direction;
244 idi48gpio->chip.direction_input = idi_48_gpio_direction_input; 255 idi48gpio->chip.direction_input = idi_48_gpio_direction_input;
245 idi48gpio->chip.get = idi_48_gpio_get; 256 idi48gpio->chip.get = idi_48_gpio_get;
246 idi48gpio->base = base[id]; 257 idi48gpio->base = base[id];
247 idi48gpio->irq = irq[id];
248 258
249 spin_lock_init(&idi48gpio->lock); 259 spin_lock_init(&idi48gpio->lock);
250 spin_lock_init(&idi48gpio->ack_lock); 260 spin_lock_init(&idi48gpio->ack_lock);
251 261
252 dev_set_drvdata(dev, idi48gpio); 262 err = devm_gpiochip_add_data(dev, &idi48gpio->chip, idi48gpio);
253
254 err = gpiochip_add_data(&idi48gpio->chip, idi48gpio);
255 if (err) { 263 if (err) {
256 dev_err(dev, "GPIO registering failed (%d)\n", err); 264 dev_err(dev, "GPIO registering failed (%d)\n", err);
257 return err; 265 return err;
@@ -265,31 +273,17 @@ static int idi_48_probe(struct device *dev, unsigned int id)
265 handle_edge_irq, IRQ_TYPE_NONE); 273 handle_edge_irq, IRQ_TYPE_NONE);
266 if (err) { 274 if (err) {
267 dev_err(dev, "Could not add irqchip (%d)\n", err); 275 dev_err(dev, "Could not add irqchip (%d)\n", err);
268 goto err_gpiochip_remove; 276 return err;
269 } 277 }
270 278
271 err = request_irq(irq[id], idi_48_irq_handler, IRQF_SHARED, name, 279 err = devm_request_irq(dev, irq[id], idi_48_irq_handler, IRQF_SHARED,
272 idi48gpio); 280 name, idi48gpio);
273 if (err) { 281 if (err) {
274 dev_err(dev, "IRQ handler registering failed (%d)\n", err); 282 dev_err(dev, "IRQ handler registering failed (%d)\n", err);
275 goto err_gpiochip_remove; 283 return err;
276 } 284 }
277 285
278 return 0; 286 return 0;
279
280err_gpiochip_remove:
281 gpiochip_remove(&idi48gpio->chip);
282 return err;
283}
284
285static int idi_48_remove(struct device *dev, unsigned int id)
286{
287 struct idi_48_gpio *const idi48gpio = dev_get_drvdata(dev);
288
289 free_irq(idi48gpio->irq, idi48gpio);
290 gpiochip_remove(&idi48gpio->chip);
291
292 return 0;
293} 287}
294 288
295static struct isa_driver idi_48_driver = { 289static struct isa_driver idi_48_driver = {
@@ -297,7 +291,6 @@ static struct isa_driver idi_48_driver = {
297 .driver = { 291 .driver = {
298 .name = "104-idi-48" 292 .name = "104-idi-48"
299 }, 293 },
300 .remove = idi_48_remove
301}; 294};
302module_isa_driver(idi_48_driver, num_idi_48); 295module_isa_driver(idi_48_driver, num_idi_48);
303 296
diff --git a/drivers/gpio/gpio-104-idio-16.c b/drivers/gpio/gpio-104-idio-16.c
index 6787b8fcf0d8..7053cf736648 100644
--- a/drivers/gpio/gpio-104-idio-16.c
+++ b/drivers/gpio/gpio-104-idio-16.c
@@ -46,7 +46,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-IDIO-16 interrupt line numbers");
46 * @lock: synchronization lock to prevent I/O race conditions 46 * @lock: synchronization lock to prevent I/O race conditions
47 * @irq_mask: I/O bits affected by interrupts 47 * @irq_mask: I/O bits affected by interrupts
48 * @base: base port address of the GPIO device 48 * @base: base port address of the GPIO device
49 * @irq: Interrupt line number
50 * @out_state: output bits state 49 * @out_state: output bits state
51 */ 50 */
52struct idio_16_gpio { 51struct idio_16_gpio {
@@ -54,7 +53,6 @@ struct idio_16_gpio {
54 spinlock_t lock; 53 spinlock_t lock;
55 unsigned long irq_mask; 54 unsigned long irq_mask;
56 unsigned base; 55 unsigned base;
57 unsigned irq;
58 unsigned out_state; 56 unsigned out_state;
59}; 57};
60 58
@@ -116,6 +114,25 @@ static void idio_16_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
116 spin_unlock_irqrestore(&idio16gpio->lock, flags); 114 spin_unlock_irqrestore(&idio16gpio->lock, flags);
117} 115}
118 116
117static void idio_16_gpio_set_multiple(struct gpio_chip *chip,
118 unsigned long *mask, unsigned long *bits)
119{
120 struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
121 unsigned long flags;
122
123 spin_lock_irqsave(&idio16gpio->lock, flags);
124
125 idio16gpio->out_state &= ~*mask;
126 idio16gpio->out_state |= *mask & *bits;
127
128 if (*mask & 0xFF)
129 outb(idio16gpio->out_state, idio16gpio->base);
130 if ((*mask >> 8) & 0xFF)
131 outb(idio16gpio->out_state >> 8, idio16gpio->base + 4);
132
133 spin_unlock_irqrestore(&idio16gpio->lock, flags);
134}
135
119static void idio_16_irq_ack(struct irq_data *data) 136static void idio_16_irq_ack(struct irq_data *data)
120{ 137{
121} 138}
@@ -193,6 +210,14 @@ static irqreturn_t idio_16_irq_handler(int irq, void *dev_id)
193 return IRQ_HANDLED; 210 return IRQ_HANDLED;
194} 211}
195 212
213#define IDIO_16_NGPIO 32
214static const char *idio_16_names[IDIO_16_NGPIO] = {
215 "OUT0", "OUT1", "OUT2", "OUT3", "OUT4", "OUT5", "OUT6", "OUT7",
216 "OUT8", "OUT9", "OUT10", "OUT11", "OUT12", "OUT13", "OUT14", "OUT15",
217 "IIN0", "IIN1", "IIN2", "IIN3", "IIN4", "IIN5", "IIN6", "IIN7",
218 "IIN8", "IIN9", "IIN10", "IIN11", "IIN12", "IIN13", "IIN14", "IIN15"
219};
220
196static int idio_16_probe(struct device *dev, unsigned int id) 221static int idio_16_probe(struct device *dev, unsigned int id)
197{ 222{
198 struct idio_16_gpio *idio16gpio; 223 struct idio_16_gpio *idio16gpio;
@@ -213,21 +238,20 @@ static int idio_16_probe(struct device *dev, unsigned int id)
213 idio16gpio->chip.parent = dev; 238 idio16gpio->chip.parent = dev;
214 idio16gpio->chip.owner = THIS_MODULE; 239 idio16gpio->chip.owner = THIS_MODULE;
215 idio16gpio->chip.base = -1; 240 idio16gpio->chip.base = -1;
216 idio16gpio->chip.ngpio = 32; 241 idio16gpio->chip.ngpio = IDIO_16_NGPIO;
242 idio16gpio->chip.names = idio_16_names;
217 idio16gpio->chip.get_direction = idio_16_gpio_get_direction; 243 idio16gpio->chip.get_direction = idio_16_gpio_get_direction;
218 idio16gpio->chip.direction_input = idio_16_gpio_direction_input; 244 idio16gpio->chip.direction_input = idio_16_gpio_direction_input;
219 idio16gpio->chip.direction_output = idio_16_gpio_direction_output; 245 idio16gpio->chip.direction_output = idio_16_gpio_direction_output;
220 idio16gpio->chip.get = idio_16_gpio_get; 246 idio16gpio->chip.get = idio_16_gpio_get;
221 idio16gpio->chip.set = idio_16_gpio_set; 247 idio16gpio->chip.set = idio_16_gpio_set;
248 idio16gpio->chip.set_multiple = idio_16_gpio_set_multiple;
222 idio16gpio->base = base[id]; 249 idio16gpio->base = base[id];
223 idio16gpio->irq = irq[id];
224 idio16gpio->out_state = 0xFFFF; 250 idio16gpio->out_state = 0xFFFF;
225 251
226 spin_lock_init(&idio16gpio->lock); 252 spin_lock_init(&idio16gpio->lock);
227 253
228 dev_set_drvdata(dev, idio16gpio); 254 err = devm_gpiochip_add_data(dev, &idio16gpio->chip, idio16gpio);
229
230 err = gpiochip_add_data(&idio16gpio->chip, idio16gpio);
231 if (err) { 255 if (err) {
232 dev_err(dev, "GPIO registering failed (%d)\n", err); 256 dev_err(dev, "GPIO registering failed (%d)\n", err);
233 return err; 257 return err;
@@ -241,30 +265,17 @@ static int idio_16_probe(struct device *dev, unsigned int id)
241 handle_edge_irq, IRQ_TYPE_NONE); 265 handle_edge_irq, IRQ_TYPE_NONE);
242 if (err) { 266 if (err) {
243 dev_err(dev, "Could not add irqchip (%d)\n", err); 267 dev_err(dev, "Could not add irqchip (%d)\n", err);
244 goto err_gpiochip_remove; 268 return err;
245 } 269 }
246 270
247 err = request_irq(irq[id], idio_16_irq_handler, 0, name, idio16gpio); 271 err = devm_request_irq(dev, irq[id], idio_16_irq_handler, 0, name,
272 idio16gpio);
248 if (err) { 273 if (err) {
249 dev_err(dev, "IRQ handler registering failed (%d)\n", err); 274 dev_err(dev, "IRQ handler registering failed (%d)\n", err);
250 goto err_gpiochip_remove; 275 return err;
251 } 276 }
252 277
253 return 0; 278 return 0;
254
255err_gpiochip_remove:
256 gpiochip_remove(&idio16gpio->chip);
257 return err;
258}
259
260static int idio_16_remove(struct device *dev, unsigned int id)
261{
262 struct idio_16_gpio *const idio16gpio = dev_get_drvdata(dev);
263
264 free_irq(idio16gpio->irq, idio16gpio);
265 gpiochip_remove(&idio16gpio->chip);
266
267 return 0;
268} 279}
269 280
270static struct isa_driver idio_16_driver = { 281static struct isa_driver idio_16_driver = {
@@ -272,7 +283,6 @@ static struct isa_driver idio_16_driver = {
272 .driver = { 283 .driver = {
273 .name = "104-idio-16" 284 .name = "104-idio-16"
274 }, 285 },
275 .remove = idio_16_remove
276}; 286};
277 287
278module_isa_driver(idio_16_driver, num_idio_16); 288module_isa_driver(idio_16_driver, num_idio_16);
diff --git a/drivers/gpio/gpio-bcm-kona.c b/drivers/gpio/gpio-bcm-kona.c
index 3d1cf018e8e7..41d0ac142580 100644
--- a/drivers/gpio/gpio-bcm-kona.c
+++ b/drivers/gpio/gpio-bcm-kona.c
@@ -308,6 +308,18 @@ static int bcm_kona_gpio_set_debounce(struct gpio_chip *chip, unsigned gpio,
308 return 0; 308 return 0;
309} 309}
310 310
311static int bcm_kona_gpio_set_config(struct gpio_chip *chip, unsigned gpio,
312 unsigned long config)
313{
314 u32 debounce;
315
316 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
317 return -ENOTSUPP;
318
319 debounce = pinconf_to_config_argument(config);
320 return bcm_kona_gpio_set_debounce(chip, gpio, debounce);
321}
322
311static const struct gpio_chip template_chip = { 323static const struct gpio_chip template_chip = {
312 .label = "bcm-kona-gpio", 324 .label = "bcm-kona-gpio",
313 .owner = THIS_MODULE, 325 .owner = THIS_MODULE,
@@ -318,7 +330,7 @@ static const struct gpio_chip template_chip = {
318 .get = bcm_kona_gpio_get, 330 .get = bcm_kona_gpio_get,
319 .direction_output = bcm_kona_gpio_direction_output, 331 .direction_output = bcm_kona_gpio_direction_output,
320 .set = bcm_kona_gpio_set, 332 .set = bcm_kona_gpio_set,
321 .set_debounce = bcm_kona_gpio_set_debounce, 333 .set_config = bcm_kona_gpio_set_config,
322 .to_irq = bcm_kona_gpio_to_irq, 334 .to_irq = bcm_kona_gpio_to_irq,
323 .base = 0, 335 .base = 0,
324}; 336};
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 9191056548fe..72f49d1e110d 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -43,25 +43,7 @@ typedef struct irq_chip *(*gpio_get_irq_chip_cb_t)(unsigned int irq);
43#define MAX_LABEL_SIZE 20 43#define MAX_LABEL_SIZE 20
44 44
45static void __iomem *gpio_base; 45static void __iomem *gpio_base;
46 46static unsigned int offset_array[5] = {0x10, 0x38, 0x60, 0x88, 0xb0};
47static struct davinci_gpio_regs __iomem *gpio2regs(unsigned gpio)
48{
49 void __iomem *ptr;
50
51 if (gpio < 32 * 1)
52 ptr = gpio_base + 0x10;
53 else if (gpio < 32 * 2)
54 ptr = gpio_base + 0x38;
55 else if (gpio < 32 * 3)
56 ptr = gpio_base + 0x60;
57 else if (gpio < 32 * 4)
58 ptr = gpio_base + 0x88;
59 else if (gpio < 32 * 5)
60 ptr = gpio_base + 0xb0;
61 else
62 ptr = NULL;
63 return ptr;
64}
65 47
66static inline struct davinci_gpio_regs __iomem *irq2regs(struct irq_data *d) 48static inline struct davinci_gpio_regs __iomem *irq2regs(struct irq_data *d)
67{ 49{
@@ -81,11 +63,13 @@ static inline int __davinci_direction(struct gpio_chip *chip,
81 unsigned offset, bool out, int value) 63 unsigned offset, bool out, int value)
82{ 64{
83 struct davinci_gpio_controller *d = gpiochip_get_data(chip); 65 struct davinci_gpio_controller *d = gpiochip_get_data(chip);
84 struct davinci_gpio_regs __iomem *g = d->regs; 66 struct davinci_gpio_regs __iomem *g;
85 unsigned long flags; 67 unsigned long flags;
86 u32 temp; 68 u32 temp;
87 u32 mask = 1 << offset; 69 int bank = offset / 32;
70 u32 mask = __gpio_mask(offset);
88 71
72 g = d->regs[bank];
89 spin_lock_irqsave(&d->lock, flags); 73 spin_lock_irqsave(&d->lock, flags);
90 temp = readl_relaxed(&g->dir); 74 temp = readl_relaxed(&g->dir);
91 if (out) { 75 if (out) {
@@ -121,9 +105,12 @@ davinci_direction_out(struct gpio_chip *chip, unsigned offset, int value)
121static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset) 105static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset)
122{ 106{
123 struct davinci_gpio_controller *d = gpiochip_get_data(chip); 107 struct davinci_gpio_controller *d = gpiochip_get_data(chip);
124 struct davinci_gpio_regs __iomem *g = d->regs; 108 struct davinci_gpio_regs __iomem *g;
109 int bank = offset / 32;
125 110
126 return !!((1 << offset) & readl_relaxed(&g->in_data)); 111 g = d->regs[bank];
112
113 return !!(__gpio_mask(offset) & readl_relaxed(&g->in_data));
127} 114}
128 115
129/* 116/*
@@ -133,9 +120,13 @@ static void
133davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 120davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
134{ 121{
135 struct davinci_gpio_controller *d = gpiochip_get_data(chip); 122 struct davinci_gpio_controller *d = gpiochip_get_data(chip);
136 struct davinci_gpio_regs __iomem *g = d->regs; 123 struct davinci_gpio_regs __iomem *g;
124 int bank = offset / 32;
137 125
138 writel_relaxed((1 << offset), value ? &g->set_data : &g->clr_data); 126 g = d->regs[bank];
127
128 writel_relaxed(__gpio_mask(offset),
129 value ? &g->set_data : &g->clr_data);
139} 130}
140 131
141static struct davinci_gpio_platform_data * 132static struct davinci_gpio_platform_data *
@@ -172,34 +163,13 @@ of_err:
172 return NULL; 163 return NULL;
173} 164}
174 165
175#ifdef CONFIG_OF_GPIO
176static int davinci_gpio_of_xlate(struct gpio_chip *gc,
177 const struct of_phandle_args *gpiospec,
178 u32 *flags)
179{
180 struct davinci_gpio_controller *chips = dev_get_drvdata(gc->parent);
181 struct davinci_gpio_platform_data *pdata = dev_get_platdata(gc->parent);
182
183 if (gpiospec->args[0] > pdata->ngpio)
184 return -EINVAL;
185
186 if (gc != &chips[gpiospec->args[0] / 32].chip)
187 return -EINVAL;
188
189 if (flags)
190 *flags = gpiospec->args[1];
191
192 return gpiospec->args[0] % 32;
193}
194#endif
195
196static int davinci_gpio_probe(struct platform_device *pdev) 166static int davinci_gpio_probe(struct platform_device *pdev)
197{ 167{
198 int i, base; 168 static int ctrl_num, bank_base;
169 int gpio, bank;
199 unsigned ngpio, nbank; 170 unsigned ngpio, nbank;
200 struct davinci_gpio_controller *chips; 171 struct davinci_gpio_controller *chips;
201 struct davinci_gpio_platform_data *pdata; 172 struct davinci_gpio_platform_data *pdata;
202 struct davinci_gpio_regs __iomem *regs;
203 struct device *dev = &pdev->dev; 173 struct device *dev = &pdev->dev;
204 struct resource *res; 174 struct resource *res;
205 char label[MAX_LABEL_SIZE]; 175 char label[MAX_LABEL_SIZE];
@@ -238,41 +208,31 @@ static int davinci_gpio_probe(struct platform_device *pdev)
238 if (IS_ERR(gpio_base)) 208 if (IS_ERR(gpio_base))
239 return PTR_ERR(gpio_base); 209 return PTR_ERR(gpio_base);
240 210
241 for (i = 0, base = 0; base < ngpio; i++, base += 32) { 211 snprintf(label, MAX_LABEL_SIZE, "davinci_gpio.%d", ctrl_num++);
242 snprintf(label, MAX_LABEL_SIZE, "davinci_gpio.%d", i); 212 chips->chip.label = devm_kstrdup(dev, label, GFP_KERNEL);
243 chips[i].chip.label = devm_kstrdup(dev, label, GFP_KERNEL); 213 if (!chips->chip.label)
244 if (!chips[i].chip.label)
245 return -ENOMEM; 214 return -ENOMEM;
246 215
247 chips[i].chip.direction_input = davinci_direction_in; 216 chips->chip.direction_input = davinci_direction_in;
248 chips[i].chip.get = davinci_gpio_get; 217 chips->chip.get = davinci_gpio_get;
249 chips[i].chip.direction_output = davinci_direction_out; 218 chips->chip.direction_output = davinci_direction_out;
250 chips[i].chip.set = davinci_gpio_set; 219 chips->chip.set = davinci_gpio_set;
251 220
252 chips[i].chip.base = base; 221 chips->chip.ngpio = ngpio;
253 chips[i].chip.ngpio = ngpio - base; 222 chips->chip.base = bank_base;
254 if (chips[i].chip.ngpio > 32)
255 chips[i].chip.ngpio = 32;
256 223
257#ifdef CONFIG_OF_GPIO 224#ifdef CONFIG_OF_GPIO
258 chips[i].chip.of_gpio_n_cells = 2; 225 chips->chip.of_gpio_n_cells = 2;
259 chips[i].chip.of_xlate = davinci_gpio_of_xlate; 226 chips->chip.parent = dev;
260 chips[i].chip.parent = dev; 227 chips->chip.of_node = dev->of_node;
261 chips[i].chip.of_node = dev->of_node;
262#endif 228#endif
263 spin_lock_init(&chips[i].lock); 229 spin_lock_init(&chips->lock);
264 230 bank_base += ngpio;
265 regs = gpio2regs(base);
266 if (!regs)
267 return -ENXIO;
268 chips[i].regs = regs;
269 chips[i].set_data = &regs->set_data;
270 chips[i].clr_data = &regs->clr_data;
271 chips[i].in_data = &regs->in_data;
272 231
273 gpiochip_add_data(&chips[i].chip, &chips[i]); 232 for (gpio = 0, bank = 0; gpio < ngpio; gpio += 32, bank++)
274 } 233 chips->regs[bank] = gpio_base + offset_array[bank];
275 234
235 gpiochip_add_data(&chips->chip, chips);
276 platform_set_drvdata(pdev, chips); 236 platform_set_drvdata(pdev, chips);
277 davinci_gpio_irq_setup(pdev); 237 davinci_gpio_irq_setup(pdev);
278 return 0; 238 return 0;
@@ -333,16 +293,19 @@ static struct irq_chip gpio_irqchip = {
333 293
334static void gpio_irq_handler(struct irq_desc *desc) 294static void gpio_irq_handler(struct irq_desc *desc)
335{ 295{
336 unsigned int irq = irq_desc_get_irq(desc);
337 struct davinci_gpio_regs __iomem *g; 296 struct davinci_gpio_regs __iomem *g;
338 u32 mask = 0xffff; 297 u32 mask = 0xffff;
298 int bank_num;
339 struct davinci_gpio_controller *d; 299 struct davinci_gpio_controller *d;
300 struct davinci_gpio_irq_data *irqdata;
340 301
341 d = (struct davinci_gpio_controller *)irq_desc_get_handler_data(desc); 302 irqdata = (struct davinci_gpio_irq_data *)irq_desc_get_handler_data(desc);
342 g = (struct davinci_gpio_regs __iomem *)d->regs; 303 bank_num = irqdata->bank_num;
304 g = irqdata->regs;
305 d = irqdata->chip;
343 306
344 /* we only care about one bank */ 307 /* we only care about one bank */
345 if (irq & 1) 308 if ((bank_num % 2) == 1)
346 mask <<= 16; 309 mask <<= 16;
347 310
348 /* temporarily mask (level sensitive) parent IRQ */ 311 /* temporarily mask (level sensitive) parent IRQ */
@@ -350,6 +313,7 @@ static void gpio_irq_handler(struct irq_desc *desc)
350 while (1) { 313 while (1) {
351 u32 status; 314 u32 status;
352 int bit; 315 int bit;
316 irq_hw_number_t hw_irq;
353 317
354 /* ack any irqs */ 318 /* ack any irqs */
355 status = readl_relaxed(&g->intstat) & mask; 319 status = readl_relaxed(&g->intstat) & mask;
@@ -362,9 +326,13 @@ static void gpio_irq_handler(struct irq_desc *desc)
362 while (status) { 326 while (status) {
363 bit = __ffs(status); 327 bit = __ffs(status);
364 status &= ~BIT(bit); 328 status &= ~BIT(bit);
329 /* Max number of gpios per controller is 144 so
330 * hw_irq will be in [0..143]
331 */
332 hw_irq = (bank_num / 2) * 32 + bit;
333
365 generic_handle_irq( 334 generic_handle_irq(
366 irq_find_mapping(d->irq_domain, 335 irq_find_mapping(d->irq_domain, hw_irq));
367 d->chip.base + bit));
368 } 336 }
369 } 337 }
370 chained_irq_exit(irq_desc_get_chip(desc), desc); 338 chained_irq_exit(irq_desc_get_chip(desc), desc);
@@ -376,7 +344,7 @@ static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset)
376 struct davinci_gpio_controller *d = gpiochip_get_data(chip); 344 struct davinci_gpio_controller *d = gpiochip_get_data(chip);
377 345
378 if (d->irq_domain) 346 if (d->irq_domain)
379 return irq_create_mapping(d->irq_domain, d->chip.base + offset); 347 return irq_create_mapping(d->irq_domain, offset);
380 else 348 else
381 return -ENXIO; 349 return -ENXIO;
382} 350}
@@ -390,7 +358,7 @@ static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset)
390 * can provide direct-mapped IRQs to AINTC (up to 32 GPIOs). 358 * can provide direct-mapped IRQs to AINTC (up to 32 GPIOs).
391 */ 359 */
392 if (offset < d->gpio_unbanked) 360 if (offset < d->gpio_unbanked)
393 return d->gpio_irq + offset; 361 return d->base_irq + offset;
394 else 362 else
395 return -ENODEV; 363 return -ENODEV;
396} 364}
@@ -403,7 +371,7 @@ static int gpio_irq_type_unbanked(struct irq_data *data, unsigned trigger)
403 371
404 d = (struct davinci_gpio_controller *)irq_data_get_irq_handler_data(data); 372 d = (struct davinci_gpio_controller *)irq_data_get_irq_handler_data(data);
405 g = (struct davinci_gpio_regs __iomem *)d->regs; 373 g = (struct davinci_gpio_regs __iomem *)d->regs;
406 mask = __gpio_mask(data->irq - d->gpio_irq); 374 mask = __gpio_mask(data->irq - d->base_irq);
407 375
408 if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) 376 if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
409 return -EINVAL; 377 return -EINVAL;
@@ -420,7 +388,9 @@ static int
420davinci_gpio_irq_map(struct irq_domain *d, unsigned int irq, 388davinci_gpio_irq_map(struct irq_domain *d, unsigned int irq,
421 irq_hw_number_t hw) 389 irq_hw_number_t hw)
422{ 390{
423 struct davinci_gpio_regs __iomem *g = gpio2regs(hw); 391 struct davinci_gpio_controller *chips =
392 (struct davinci_gpio_controller *)d->host_data;
393 struct davinci_gpio_regs __iomem *g = chips->regs[hw / 32];
424 394
425 irq_set_chip_and_handler_name(irq, &gpio_irqchip, handle_simple_irq, 395 irq_set_chip_and_handler_name(irq, &gpio_irqchip, handle_simple_irq,
426 "davinci_gpio"); 396 "davinci_gpio");
@@ -478,6 +448,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
478 struct irq_domain *irq_domain = NULL; 448 struct irq_domain *irq_domain = NULL;
479 const struct of_device_id *match; 449 const struct of_device_id *match;
480 struct irq_chip *irq_chip; 450 struct irq_chip *irq_chip;
451 struct davinci_gpio_irq_data *irqdata;
481 gpio_get_irq_chip_cb_t gpio_get_irq_chip; 452 gpio_get_irq_chip_cb_t gpio_get_irq_chip;
482 453
483 /* 454 /*
@@ -533,10 +504,8 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
533 * IRQs, while the others use banked IRQs, would need some setup 504 * IRQs, while the others use banked IRQs, would need some setup
534 * tweaks to recognize hardware which can do that. 505 * tweaks to recognize hardware which can do that.
535 */ 506 */
536 for (gpio = 0, bank = 0; gpio < ngpio; bank++, gpio += 32) { 507 chips->chip.to_irq = gpio_to_irq_banked;
537 chips[bank].chip.to_irq = gpio_to_irq_banked; 508 chips->irq_domain = irq_domain;
538 chips[bank].irq_domain = irq_domain;
539 }
540 509
541 /* 510 /*
542 * AINTC can handle direct/unbanked IRQs for GPIOs, with the GPIO 511 * AINTC can handle direct/unbanked IRQs for GPIOs, with the GPIO
@@ -545,9 +514,9 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
545 */ 514 */
546 if (pdata->gpio_unbanked) { 515 if (pdata->gpio_unbanked) {
547 /* pass "bank 0" GPIO IRQs to AINTC */ 516 /* pass "bank 0" GPIO IRQs to AINTC */
548 chips[0].chip.to_irq = gpio_to_irq_unbanked; 517 chips->chip.to_irq = gpio_to_irq_unbanked;
549 chips[0].gpio_irq = bank_irq; 518 chips->base_irq = bank_irq;
550 chips[0].gpio_unbanked = pdata->gpio_unbanked; 519 chips->gpio_unbanked = pdata->gpio_unbanked;
551 binten = GENMASK(pdata->gpio_unbanked / 16, 0); 520 binten = GENMASK(pdata->gpio_unbanked / 16, 0);
552 521
553 /* AINTC handles mask/unmask; GPIO handles triggering */ 522 /* AINTC handles mask/unmask; GPIO handles triggering */
@@ -557,14 +526,14 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
557 irq_chip->irq_set_type = gpio_irq_type_unbanked; 526 irq_chip->irq_set_type = gpio_irq_type_unbanked;
558 527
559 /* default trigger: both edges */ 528 /* default trigger: both edges */
560 g = gpio2regs(0); 529 g = chips->regs[0];
561 writel_relaxed(~0, &g->set_falling); 530 writel_relaxed(~0, &g->set_falling);
562 writel_relaxed(~0, &g->set_rising); 531 writel_relaxed(~0, &g->set_rising);
563 532
564 /* set the direct IRQs up to use that irqchip */ 533 /* set the direct IRQs up to use that irqchip */
565 for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++, irq++) { 534 for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++, irq++) {
566 irq_set_chip(irq, irq_chip); 535 irq_set_chip(irq, irq_chip);
567 irq_set_handler_data(irq, &chips[gpio / 32]); 536 irq_set_handler_data(irq, chips);
568 irq_set_status_flags(irq, IRQ_TYPE_EDGE_BOTH); 537 irq_set_status_flags(irq, IRQ_TYPE_EDGE_BOTH);
569 } 538 }
570 539
@@ -576,8 +545,11 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
576 * then chain through our own handler. 545 * then chain through our own handler.
577 */ 546 */
578 for (gpio = 0, bank = 0; gpio < ngpio; bank++, bank_irq++, gpio += 16) { 547 for (gpio = 0, bank = 0; gpio < ngpio; bank++, bank_irq++, gpio += 16) {
579 /* disabled by default, enabled only as needed */ 548 /* disabled by default, enabled only as needed
580 g = gpio2regs(gpio); 549 * There are register sets for 32 GPIOs. 2 banks of 16
550 * GPIOs are covered by each set of registers hence divide by 2
551 */
552 g = chips->regs[bank / 2];
581 writel_relaxed(~0, &g->clr_falling); 553 writel_relaxed(~0, &g->clr_falling);
582 writel_relaxed(~0, &g->clr_rising); 554 writel_relaxed(~0, &g->clr_rising);
583 555
@@ -586,8 +558,19 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
586 * gpio irqs. Pass the irq bank's corresponding controller to 558 * gpio irqs. Pass the irq bank's corresponding controller to
587 * the chained irq handler. 559 * the chained irq handler.
588 */ 560 */
561 irqdata = devm_kzalloc(&pdev->dev,
562 sizeof(struct
563 davinci_gpio_irq_data),
564 GFP_KERNEL);
565 if (!irqdata)
566 return -ENOMEM;
567
568 irqdata->regs = g;
569 irqdata->bank_num = bank;
570 irqdata->chip = chips;
571
589 irq_set_chained_handler_and_data(bank_irq, gpio_irq_handler, 572 irq_set_chained_handler_and_data(bank_irq, gpio_irq_handler,
590 &chips[gpio / 32]); 573 irqdata);
591 574
592 binten |= BIT(bank); 575 binten |= BIT(bank);
593 } 576 }
diff --git a/drivers/gpio/gpio-dln2.c b/drivers/gpio/gpio-dln2.c
index 5d38b08d1ee2..aecb847166f5 100644
--- a/drivers/gpio/gpio-dln2.c
+++ b/drivers/gpio/gpio-dln2.c
@@ -272,12 +272,16 @@ static int dln2_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
272 return dln2_gpio_set_direction(chip, offset, DLN2_GPIO_DIRECTION_OUT); 272 return dln2_gpio_set_direction(chip, offset, DLN2_GPIO_DIRECTION_OUT);
273} 273}
274 274
275static int dln2_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, 275static int dln2_gpio_set_config(struct gpio_chip *chip, unsigned offset,
276 unsigned debounce) 276 unsigned long config)
277{ 277{
278 struct dln2_gpio *dln2 = gpiochip_get_data(chip); 278 struct dln2_gpio *dln2 = gpiochip_get_data(chip);
279 __le32 duration = cpu_to_le32(debounce); 279 __le32 duration;
280 280
281 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
282 return -ENOTSUPP;
283
284 duration = cpu_to_le32(pinconf_to_config_argument(config));
281 return dln2_transfer_tx(dln2->pdev, DLN2_GPIO_SET_DEBOUNCE, 285 return dln2_transfer_tx(dln2->pdev, DLN2_GPIO_SET_DEBOUNCE,
282 &duration, sizeof(duration)); 286 &duration, sizeof(duration));
283} 287}
@@ -474,7 +478,7 @@ static int dln2_gpio_probe(struct platform_device *pdev)
474 dln2->gpio.get_direction = dln2_gpio_get_direction; 478 dln2->gpio.get_direction = dln2_gpio_get_direction;
475 dln2->gpio.direction_input = dln2_gpio_direction_input; 479 dln2->gpio.direction_input = dln2_gpio_direction_input;
476 dln2->gpio.direction_output = dln2_gpio_direction_output; 480 dln2->gpio.direction_output = dln2_gpio_direction_output;
477 dln2->gpio.set_debounce = dln2_gpio_set_debounce; 481 dln2->gpio.set_config = dln2_gpio_set_config;
478 482
479 platform_set_drvdata(pdev, dln2); 483 platform_set_drvdata(pdev, dln2);
480 484
diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index 6193f62c0df4..9c15ee4ef4e9 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -279,6 +279,18 @@ static int dwapb_gpio_set_debounce(struct gpio_chip *gc,
279 return 0; 279 return 0;
280} 280}
281 281
282static int dwapb_gpio_set_config(struct gpio_chip *gc, unsigned offset,
283 unsigned long config)
284{
285 u32 debounce;
286
287 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
288 return -ENOTSUPP;
289
290 debounce = pinconf_to_config_argument(config);
291 return dwapb_gpio_set_debounce(gc, offset, debounce);
292}
293
282static irqreturn_t dwapb_irq_handler_mfd(int irq, void *dev_id) 294static irqreturn_t dwapb_irq_handler_mfd(int irq, void *dev_id)
283{ 295{
284 u32 worked; 296 u32 worked;
@@ -426,7 +438,7 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
426 438
427 /* Only port A support debounce */ 439 /* Only port A support debounce */
428 if (pp->idx == 0) 440 if (pp->idx == 0)
429 port->gc.set_debounce = dwapb_gpio_set_debounce; 441 port->gc.set_config = dwapb_gpio_set_config;
430 442
431 if (pp->irq) 443 if (pp->irq)
432 dwapb_configure_irqs(gpio, port, pp); 444 dwapb_configure_irqs(gpio, port, pp);
diff --git a/drivers/gpio/gpio-ep93xx.c b/drivers/gpio/gpio-ep93xx.c
index d054219e18b9..45d384039e9b 100644
--- a/drivers/gpio/gpio-ep93xx.c
+++ b/drivers/gpio/gpio-ep93xx.c
@@ -291,15 +291,20 @@ static struct ep93xx_gpio_bank ep93xx_gpio_banks[] = {
291 EP93XX_GPIO_BANK("H", 0x40, 0x44, 56, false), 291 EP93XX_GPIO_BANK("H", 0x40, 0x44, 56, false),
292}; 292};
293 293
294static int ep93xx_gpio_set_debounce(struct gpio_chip *chip, 294static int ep93xx_gpio_set_config(struct gpio_chip *chip, unsigned offset,
295 unsigned offset, unsigned debounce) 295 unsigned long config)
296{ 296{
297 int gpio = chip->base + offset; 297 int gpio = chip->base + offset;
298 int irq = gpio_to_irq(gpio); 298 int irq = gpio_to_irq(gpio);
299 u32 debounce;
300
301 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
302 return -ENOTSUPP;
299 303
300 if (irq < 0) 304 if (irq < 0)
301 return -EINVAL; 305 return -EINVAL;
302 306
307 debounce = pinconf_to_config_argument(config);
303 ep93xx_gpio_int_debounce(irq, debounce ? true : false); 308 ep93xx_gpio_int_debounce(irq, debounce ? true : false);
304 309
305 return 0; 310 return 0;
@@ -335,7 +340,7 @@ static int ep93xx_gpio_add_bank(struct gpio_chip *gc, struct device *dev,
335 gc->base = bank->base; 340 gc->base = bank->base;
336 341
337 if (bank->has_debounce) { 342 if (bank->has_debounce) {
338 gc->set_debounce = ep93xx_gpio_set_debounce; 343 gc->set_config = ep93xx_gpio_set_config;
339 gc->to_irq = ep93xx_gpio_to_irq; 344 gc->to_irq = ep93xx_gpio_to_irq;
340 } 345 }
341 346
diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c
new file mode 100644
index 000000000000..05c8946d6446
--- /dev/null
+++ b/drivers/gpio/gpio-exar.c
@@ -0,0 +1,200 @@
1/*
2 * GPIO driver for Exar XR17V35X chip
3 *
4 * Copyright (C) 2015 Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
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 version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/bitops.h>
11#include <linux/device.h>
12#include <linux/gpio/driver.h>
13#include <linux/init.h>
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/pci.h>
17#include <linux/platform_device.h>
18
19#define EXAR_OFFSET_MPIOLVL_LO 0x90
20#define EXAR_OFFSET_MPIOSEL_LO 0x93
21#define EXAR_OFFSET_MPIOLVL_HI 0x96
22#define EXAR_OFFSET_MPIOSEL_HI 0x99
23
24#define DRIVER_NAME "gpio_exar"
25
26static DEFINE_IDA(ida_index);
27
28struct exar_gpio_chip {
29 struct gpio_chip gpio_chip;
30 struct mutex lock;
31 int index;
32 void __iomem *regs;
33 char name[20];
34};
35
36static void exar_update(struct gpio_chip *chip, unsigned int reg, int val,
37 unsigned int offset)
38{
39 struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip);
40 int temp;
41
42 mutex_lock(&exar_gpio->lock);
43 temp = readb(exar_gpio->regs + reg);
44 temp &= ~BIT(offset);
45 if (val)
46 temp |= BIT(offset);
47 writeb(temp, exar_gpio->regs + reg);
48 mutex_unlock(&exar_gpio->lock);
49}
50
51static int exar_set_direction(struct gpio_chip *chip, int direction,
52 unsigned int offset)
53{
54 unsigned int bank = offset / 8;
55 unsigned int addr;
56
57 addr = bank ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
58 exar_update(chip, addr, direction, offset % 8);
59 return 0;
60}
61
62static int exar_direction_output(struct gpio_chip *chip, unsigned int offset,
63 int value)
64{
65 return exar_set_direction(chip, 0, offset);
66}
67
68static int exar_direction_input(struct gpio_chip *chip, unsigned int offset)
69{
70 return exar_set_direction(chip, 1, offset);
71}
72
73static int exar_get(struct gpio_chip *chip, unsigned int reg)
74{
75 struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip);
76 int value;
77
78 mutex_lock(&exar_gpio->lock);
79 value = readb(exar_gpio->regs + reg);
80 mutex_unlock(&exar_gpio->lock);
81
82 return !!value;
83}
84
85static int exar_get_direction(struct gpio_chip *chip, unsigned int offset)
86{
87 unsigned int bank = offset / 8;
88 unsigned int addr;
89 int val;
90
91 addr = bank ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
92 val = exar_get(chip, addr) >> (offset % 8);
93
94 return !!val;
95}
96
97static int exar_get_value(struct gpio_chip *chip, unsigned int offset)
98{
99 unsigned int bank = offset / 8;
100 unsigned int addr;
101 int val;
102
103 addr = bank ? EXAR_OFFSET_MPIOLVL_LO : EXAR_OFFSET_MPIOLVL_HI;
104 val = exar_get(chip, addr) >> (offset % 8);
105
106 return !!val;
107}
108
109static void exar_set_value(struct gpio_chip *chip, unsigned int offset,
110 int value)
111{
112 unsigned int bank = offset / 8;
113 unsigned int addr;
114
115 addr = bank ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
116 exar_update(chip, addr, value, offset % 8);
117}
118
119static int gpio_exar_probe(struct platform_device *pdev)
120{
121 struct pci_dev *pcidev = platform_get_drvdata(pdev);
122 struct exar_gpio_chip *exar_gpio;
123 void __iomem *p;
124 int index, ret;
125
126 if (pcidev->vendor != PCI_VENDOR_ID_EXAR)
127 return -ENODEV;
128
129 /*
130 * Map the pci device to get the register addresses.
131 * We will need to read and write those registers to control
132 * the GPIO pins.
133 * Using managed functions will save us from unmaping on exit.
134 * As the device is enabled using managed functions by the
135 * UART driver we can also use managed functions here.
136 */
137 p = pcim_iomap(pcidev, 0, 0);
138 if (!p)
139 return -ENOMEM;
140
141 exar_gpio = devm_kzalloc(&pcidev->dev, sizeof(*exar_gpio), GFP_KERNEL);
142 if (!exar_gpio)
143 return -ENOMEM;
144
145 mutex_init(&exar_gpio->lock);
146
147 index = ida_simple_get(&ida_index, 0, 0, GFP_KERNEL);
148
149 sprintf(exar_gpio->name, "exar_gpio%d", index);
150 exar_gpio->gpio_chip.label = exar_gpio->name;
151 exar_gpio->gpio_chip.parent = &pcidev->dev;
152 exar_gpio->gpio_chip.direction_output = exar_direction_output;
153 exar_gpio->gpio_chip.direction_input = exar_direction_input;
154 exar_gpio->gpio_chip.get_direction = exar_get_direction;
155 exar_gpio->gpio_chip.get = exar_get_value;
156 exar_gpio->gpio_chip.set = exar_set_value;
157 exar_gpio->gpio_chip.base = -1;
158 exar_gpio->gpio_chip.ngpio = 16;
159 exar_gpio->regs = p;
160 exar_gpio->index = index;
161
162 ret = devm_gpiochip_add_data(&pcidev->dev,
163 &exar_gpio->gpio_chip, exar_gpio);
164 if (ret)
165 goto err_destroy;
166
167 platform_set_drvdata(pdev, exar_gpio);
168
169 return 0;
170
171err_destroy:
172 ida_simple_remove(&ida_index, index);
173 mutex_destroy(&exar_gpio->lock);
174 return ret;
175}
176
177static int gpio_exar_remove(struct platform_device *pdev)
178{
179 struct exar_gpio_chip *exar_gpio = platform_get_drvdata(pdev);
180
181 ida_simple_remove(&ida_index, exar_gpio->index);
182 mutex_destroy(&exar_gpio->lock);
183
184 return 0;
185}
186
187static struct platform_driver gpio_exar_driver = {
188 .probe = gpio_exar_probe,
189 .remove = gpio_exar_remove,
190 .driver = {
191 .name = DRIVER_NAME,
192 },
193};
194
195module_platform_driver(gpio_exar_driver);
196
197MODULE_ALIAS("platform:" DRIVER_NAME);
198MODULE_DESCRIPTION("Exar GPIO driver");
199MODULE_AUTHOR("Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>");
200MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/gpio-f7188x.c b/drivers/gpio/gpio-f7188x.c
index e8accde62aa7..56bd76c33767 100644
--- a/drivers/gpio/gpio-f7188x.c
+++ b/drivers/gpio/gpio-f7188x.c
@@ -131,9 +131,8 @@ static int f7188x_gpio_get(struct gpio_chip *chip, unsigned offset);
131static int f7188x_gpio_direction_out(struct gpio_chip *chip, 131static int f7188x_gpio_direction_out(struct gpio_chip *chip,
132 unsigned offset, int value); 132 unsigned offset, int value);
133static void f7188x_gpio_set(struct gpio_chip *chip, unsigned offset, int value); 133static void f7188x_gpio_set(struct gpio_chip *chip, unsigned offset, int value);
134static int f7188x_gpio_set_single_ended(struct gpio_chip *gc, 134static int f7188x_gpio_set_config(struct gpio_chip *chip, unsigned offset,
135 unsigned offset, 135 unsigned long config);
136 enum single_ended_mode mode);
137 136
138#define F7188X_GPIO_BANK(_base, _ngpio, _regbase) \ 137#define F7188X_GPIO_BANK(_base, _ngpio, _regbase) \
139 { \ 138 { \
@@ -145,7 +144,7 @@ static int f7188x_gpio_set_single_ended(struct gpio_chip *gc,
145 .get = f7188x_gpio_get, \ 144 .get = f7188x_gpio_get, \
146 .direction_output = f7188x_gpio_direction_out, \ 145 .direction_output = f7188x_gpio_direction_out, \
147 .set = f7188x_gpio_set, \ 146 .set = f7188x_gpio_set, \
148 .set_single_ended = f7188x_gpio_set_single_ended, \ 147 .set_config = f7188x_gpio_set_config, \
149 .base = _base, \ 148 .base = _base, \
150 .ngpio = _ngpio, \ 149 .ngpio = _ngpio, \
151 .can_sleep = true, \ 150 .can_sleep = true, \
@@ -326,17 +325,17 @@ static void f7188x_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
326 superio_exit(sio->addr); 325 superio_exit(sio->addr);
327} 326}
328 327
329static int f7188x_gpio_set_single_ended(struct gpio_chip *chip, 328static int f7188x_gpio_set_config(struct gpio_chip *chip, unsigned offset,
330 unsigned offset, 329 unsigned long config)
331 enum single_ended_mode mode)
332{ 330{
333 int err; 331 int err;
332 enum pin_config_param param = pinconf_to_config_param(config);
334 struct f7188x_gpio_bank *bank = gpiochip_get_data(chip); 333 struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
335 struct f7188x_sio *sio = bank->data->sio; 334 struct f7188x_sio *sio = bank->data->sio;
336 u8 data; 335 u8 data;
337 336
338 if (mode != LINE_MODE_OPEN_DRAIN && 337 if (param != PIN_CONFIG_DRIVE_OPEN_DRAIN &&
339 mode != LINE_MODE_PUSH_PULL) 338 param != PIN_CONFIG_DRIVE_PUSH_PULL)
340 return -ENOTSUPP; 339 return -ENOTSUPP;
341 340
342 err = superio_enter(sio->addr); 341 err = superio_enter(sio->addr);
@@ -345,7 +344,7 @@ static int f7188x_gpio_set_single_ended(struct gpio_chip *chip,
345 superio_select(sio->addr, SIO_LD_GPIO); 344 superio_select(sio->addr, SIO_LD_GPIO);
346 345
347 data = superio_inb(sio->addr, gpio_out_mode(bank->regbase)); 346 data = superio_inb(sio->addr, gpio_out_mode(bank->regbase));
348 if (mode == LINE_MODE_OPEN_DRAIN) 347 if (param == PIN_CONFIG_DRIVE_OPEN_DRAIN)
349 data &= ~BIT(offset); 348 data &= ~BIT(offset);
350 else 349 else
351 data |= BIT(offset); 350 data |= BIT(offset);
diff --git a/drivers/gpio/gpio-gemini.c b/drivers/gpio/gpio-gemini.c
new file mode 100644
index 000000000000..962485163b7f
--- /dev/null
+++ b/drivers/gpio/gpio-gemini.c
@@ -0,0 +1,236 @@
1/*
2 * Gemini gpiochip and interrupt routines
3 * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
4 *
5 * Based on arch/arm/mach-gemini/gpio.c:
6 * Copyright (C) 2008-2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
7 *
8 * Based on plat-mxc/gpio.c:
9 * MXC GPIO support. (c) 2008 Daniel Mack <daniel@caiaq.de>
10 * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
11 */
12#include <linux/gpio/driver.h>
13#include <linux/io.h>
14#include <linux/interrupt.h>
15#include <linux/platform_device.h>
16#include <linux/of_gpio.h>
17#include <linux/bitops.h>
18
19/* GPIO registers definition */
20#define GPIO_DATA_OUT 0x00
21#define GPIO_DATA_IN 0x04
22#define GPIO_DIR 0x08
23#define GPIO_DATA_SET 0x10
24#define GPIO_DATA_CLR 0x14
25#define GPIO_PULL_EN 0x18
26#define GPIO_PULL_TYPE 0x1C
27#define GPIO_INT_EN 0x20
28#define GPIO_INT_STAT 0x24
29#define GPIO_INT_MASK 0x2C
30#define GPIO_INT_CLR 0x30
31#define GPIO_INT_TYPE 0x34
32#define GPIO_INT_BOTH_EDGE 0x38
33#define GPIO_INT_LEVEL 0x3C
34#define GPIO_DEBOUNCE_EN 0x40
35#define GPIO_DEBOUNCE_PRESCALE 0x44
36
37/**
38 * struct gemini_gpio - Gemini GPIO state container
39 * @dev: containing device for this instance
40 * @gc: gpiochip for this instance
41 */
42struct gemini_gpio {
43 struct device *dev;
44 struct gpio_chip gc;
45 void __iomem *base;
46};
47
48static void gemini_gpio_ack_irq(struct irq_data *d)
49{
50 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
51 struct gemini_gpio *g = gpiochip_get_data(gc);
52
53 writel(BIT(irqd_to_hwirq(d)), g->base + GPIO_INT_CLR);
54}
55
56static void gemini_gpio_mask_irq(struct irq_data *d)
57{
58 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
59 struct gemini_gpio *g = gpiochip_get_data(gc);
60 u32 val;
61
62 val = readl(g->base + GPIO_INT_EN);
63 val &= ~BIT(irqd_to_hwirq(d));
64 writel(val, g->base + GPIO_INT_EN);
65}
66
67static void gemini_gpio_unmask_irq(struct irq_data *d)
68{
69 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
70 struct gemini_gpio *g = gpiochip_get_data(gc);
71 u32 val;
72
73 val = readl(g->base + GPIO_INT_EN);
74 val |= BIT(irqd_to_hwirq(d));
75 writel(val, g->base + GPIO_INT_EN);
76}
77
78static int gemini_gpio_set_irq_type(struct irq_data *d, unsigned int type)
79{
80 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
81 struct gemini_gpio *g = gpiochip_get_data(gc);
82 u32 mask = BIT(irqd_to_hwirq(d));
83 u32 reg_both, reg_level, reg_type;
84
85 reg_type = readl(g->base + GPIO_INT_TYPE);
86 reg_level = readl(g->base + GPIO_INT_LEVEL);
87 reg_both = readl(g->base + GPIO_INT_BOTH_EDGE);
88
89 switch (type) {
90 case IRQ_TYPE_EDGE_BOTH:
91 irq_set_handler_locked(d, handle_edge_irq);
92 reg_type &= ~mask;
93 reg_both |= mask;
94 break;
95 case IRQ_TYPE_EDGE_RISING:
96 irq_set_handler_locked(d, handle_edge_irq);
97 reg_type &= ~mask;
98 reg_both &= ~mask;
99 reg_level &= ~mask;
100 break;
101 case IRQ_TYPE_EDGE_FALLING:
102 irq_set_handler_locked(d, handle_edge_irq);
103 reg_type &= ~mask;
104 reg_both &= ~mask;
105 reg_level |= mask;
106 break;
107 case IRQ_TYPE_LEVEL_HIGH:
108 irq_set_handler_locked(d, handle_level_irq);
109 reg_type |= mask;
110 reg_level &= ~mask;
111 break;
112 case IRQ_TYPE_LEVEL_LOW:
113 irq_set_handler_locked(d, handle_level_irq);
114 reg_type |= mask;
115 reg_level |= mask;
116 break;
117 default:
118 irq_set_handler_locked(d, handle_bad_irq);
119 return -EINVAL;
120 }
121
122 writel(reg_type, g->base + GPIO_INT_TYPE);
123 writel(reg_level, g->base + GPIO_INT_LEVEL);
124 writel(reg_both, g->base + GPIO_INT_BOTH_EDGE);
125
126 gemini_gpio_ack_irq(d);
127
128 return 0;
129}
130
131static struct irq_chip gemini_gpio_irqchip = {
132 .name = "GPIO",
133 .irq_ack = gemini_gpio_ack_irq,
134 .irq_mask = gemini_gpio_mask_irq,
135 .irq_unmask = gemini_gpio_unmask_irq,
136 .irq_set_type = gemini_gpio_set_irq_type,
137};
138
139static void gemini_gpio_irq_handler(struct irq_desc *desc)
140{
141 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
142 struct gemini_gpio *g = gpiochip_get_data(gc);
143 struct irq_chip *irqchip = irq_desc_get_chip(desc);
144 int offset;
145 unsigned long stat;
146
147 chained_irq_enter(irqchip, desc);
148
149 stat = readl(g->base + GPIO_INT_STAT);
150 if (stat)
151 for_each_set_bit(offset, &stat, gc->ngpio)
152 generic_handle_irq(irq_find_mapping(gc->irqdomain,
153 offset));
154
155 chained_irq_exit(irqchip, desc);
156}
157
158static int gemini_gpio_probe(struct platform_device *pdev)
159{
160 struct device *dev = &pdev->dev;
161 struct resource *res;
162 struct gemini_gpio *g;
163 int irq;
164 int ret;
165
166 g = devm_kzalloc(dev, sizeof(*g), GFP_KERNEL);
167 if (!g)
168 return -ENOMEM;
169
170 g->dev = dev;
171
172 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
173 g->base = devm_ioremap_resource(dev, res);
174 if (IS_ERR(g->base))
175 return PTR_ERR(g->base);
176
177 irq = platform_get_irq(pdev, 0);
178 if (!irq)
179 return -EINVAL;
180
181 ret = bgpio_init(&g->gc, dev, 4,
182 g->base + GPIO_DATA_IN,
183 g->base + GPIO_DATA_SET,
184 g->base + GPIO_DATA_CLR,
185 g->base + GPIO_DIR,
186 NULL,
187 0);
188 if (ret) {
189 dev_err(dev, "unable to init generic GPIO\n");
190 return ret;
191 }
192 g->gc.label = "Gemini";
193 g->gc.base = -1;
194 g->gc.parent = dev;
195 g->gc.owner = THIS_MODULE;
196 /* ngpio is set by bgpio_init() */
197
198 ret = devm_gpiochip_add_data(dev, &g->gc, g);
199 if (ret)
200 return ret;
201
202 /* Disable, unmask and clear all interrupts */
203 writel(0x0, g->base + GPIO_INT_EN);
204 writel(0x0, g->base + GPIO_INT_MASK);
205 writel(~0x0, g->base + GPIO_INT_CLR);
206
207 ret = gpiochip_irqchip_add(&g->gc, &gemini_gpio_irqchip,
208 0, handle_bad_irq,
209 IRQ_TYPE_NONE);
210 if (ret) {
211 dev_info(dev, "could not add irqchip\n");
212 return ret;
213 }
214 gpiochip_set_chained_irqchip(&g->gc, &gemini_gpio_irqchip,
215 irq, gemini_gpio_irq_handler);
216
217 dev_info(dev, "Gemini GPIO @%p registered\n", g->base);
218
219 return 0;
220}
221
222static const struct of_device_id gemini_gpio_of_match[] = {
223 {
224 .compatible = "cortina,gemini-gpio",
225 },
226 {},
227};
228
229static struct platform_driver gemini_gpio_driver = {
230 .driver = {
231 .name = "gemini-gpio",
232 .of_match_table = of_match_ptr(gemini_gpio_of_match),
233 },
234 .probe = gemini_gpio_probe,
235};
236builtin_platform_driver(gemini_gpio_driver);
diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c
index 1e7def9449ce..fa4baa2543db 100644
--- a/drivers/gpio/gpio-gpio-mm.c
+++ b/drivers/gpio/gpio-gpio-mm.c
@@ -192,6 +192,56 @@ static void gpiomm_gpio_set(struct gpio_chip *chip, unsigned int offset,
192 spin_unlock_irqrestore(&gpiommgpio->lock, flags); 192 spin_unlock_irqrestore(&gpiommgpio->lock, flags);
193} 193}
194 194
195static void gpiomm_gpio_set_multiple(struct gpio_chip *chip,
196 unsigned long *mask, unsigned long *bits)
197{
198 struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip);
199 unsigned int i;
200 const unsigned int gpio_reg_size = 8;
201 unsigned int port;
202 unsigned int out_port;
203 unsigned int bitmask;
204 unsigned long flags;
205
206 /* set bits are evaluated a gpio register size at a time */
207 for (i = 0; i < chip->ngpio; i += gpio_reg_size) {
208 /* no more set bits in this mask word; skip to the next word */
209 if (!mask[BIT_WORD(i)]) {
210 i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size;
211 continue;
212 }
213
214 port = i / gpio_reg_size;
215 out_port = (port > 2) ? port + 1 : port;
216 bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)];
217
218 spin_lock_irqsave(&gpiommgpio->lock, flags);
219
220 /* update output state data and set device gpio register */
221 gpiommgpio->out_state[port] &= ~mask[BIT_WORD(i)];
222 gpiommgpio->out_state[port] |= bitmask;
223 outb(gpiommgpio->out_state[port], gpiommgpio->base + out_port);
224
225 spin_unlock_irqrestore(&gpiommgpio->lock, flags);
226
227 /* prepare for next gpio register set */
228 mask[BIT_WORD(i)] >>= gpio_reg_size;
229 bits[BIT_WORD(i)] >>= gpio_reg_size;
230 }
231}
232
233#define GPIOMM_NGPIO 48
234static const char *gpiomm_names[GPIOMM_NGPIO] = {
235 "Port 1A0", "Port 1A1", "Port 1A2", "Port 1A3", "Port 1A4", "Port 1A5",
236 "Port 1A6", "Port 1A7", "Port 1B0", "Port 1B1", "Port 1B2", "Port 1B3",
237 "Port 1B4", "Port 1B5", "Port 1B6", "Port 1B7", "Port 1C0", "Port 1C1",
238 "Port 1C2", "Port 1C3", "Port 1C4", "Port 1C5", "Port 1C6", "Port 1C7",
239 "Port 2A0", "Port 2A1", "Port 2A2", "Port 2A3", "Port 2A4", "Port 2A5",
240 "Port 2A6", "Port 2A7", "Port 2B0", "Port 2B1", "Port 2B2", "Port 2B3",
241 "Port 2B4", "Port 2B5", "Port 2B6", "Port 2B7", "Port 2C0", "Port 2C1",
242 "Port 2C2", "Port 2C3", "Port 2C4", "Port 2C5", "Port 2C6", "Port 2C7",
243};
244
195static int gpiomm_probe(struct device *dev, unsigned int id) 245static int gpiomm_probe(struct device *dev, unsigned int id)
196{ 246{
197 struct gpiomm_gpio *gpiommgpio; 247 struct gpiomm_gpio *gpiommgpio;
@@ -212,19 +262,19 @@ static int gpiomm_probe(struct device *dev, unsigned int id)
212 gpiommgpio->chip.parent = dev; 262 gpiommgpio->chip.parent = dev;
213 gpiommgpio->chip.owner = THIS_MODULE; 263 gpiommgpio->chip.owner = THIS_MODULE;
214 gpiommgpio->chip.base = -1; 264 gpiommgpio->chip.base = -1;
215 gpiommgpio->chip.ngpio = 48; 265 gpiommgpio->chip.ngpio = GPIOMM_NGPIO;
266 gpiommgpio->chip.names = gpiomm_names;
216 gpiommgpio->chip.get_direction = gpiomm_gpio_get_direction; 267 gpiommgpio->chip.get_direction = gpiomm_gpio_get_direction;
217 gpiommgpio->chip.direction_input = gpiomm_gpio_direction_input; 268 gpiommgpio->chip.direction_input = gpiomm_gpio_direction_input;
218 gpiommgpio->chip.direction_output = gpiomm_gpio_direction_output; 269 gpiommgpio->chip.direction_output = gpiomm_gpio_direction_output;
219 gpiommgpio->chip.get = gpiomm_gpio_get; 270 gpiommgpio->chip.get = gpiomm_gpio_get;
220 gpiommgpio->chip.set = gpiomm_gpio_set; 271 gpiommgpio->chip.set = gpiomm_gpio_set;
272 gpiommgpio->chip.set_multiple = gpiomm_gpio_set_multiple;
221 gpiommgpio->base = base[id]; 273 gpiommgpio->base = base[id];
222 274
223 spin_lock_init(&gpiommgpio->lock); 275 spin_lock_init(&gpiommgpio->lock);
224 276
225 dev_set_drvdata(dev, gpiommgpio); 277 err = devm_gpiochip_add_data(dev, &gpiommgpio->chip, gpiommgpio);
226
227 err = gpiochip_add_data(&gpiommgpio->chip, gpiommgpio);
228 if (err) { 278 if (err) {
229 dev_err(dev, "GPIO registering failed (%d)\n", err); 279 dev_err(dev, "GPIO registering failed (%d)\n", err);
230 return err; 280 return err;
@@ -243,21 +293,11 @@ static int gpiomm_probe(struct device *dev, unsigned int id)
243 return 0; 293 return 0;
244} 294}
245 295
246static int gpiomm_remove(struct device *dev, unsigned int id)
247{
248 struct gpiomm_gpio *const gpiommgpio = dev_get_drvdata(dev);
249
250 gpiochip_remove(&gpiommgpio->chip);
251
252 return 0;
253}
254
255static struct isa_driver gpiomm_driver = { 296static struct isa_driver gpiomm_driver = {
256 .probe = gpiomm_probe, 297 .probe = gpiomm_probe,
257 .driver = { 298 .driver = {
258 .name = "gpio-mm" 299 .name = "gpio-mm"
259 }, 300 },
260 .remove = gpiomm_remove
261}; 301};
262 302
263module_isa_driver(gpiomm_driver, num_gpiomm); 303module_isa_driver(gpiomm_driver, num_gpiomm);
diff --git a/drivers/gpio/gpio-intel-mid.c b/drivers/gpio/gpio-intel-mid.c
index a1e44c221f66..b76ecee82c3f 100644
--- a/drivers/gpio/gpio-intel-mid.c
+++ b/drivers/gpio/gpio-intel-mid.c
@@ -321,7 +321,7 @@ static void intel_mid_irq_init_hw(struct intel_mid_gpio *priv)
321 } 321 }
322} 322}
323 323
324static int intel_gpio_runtime_idle(struct device *dev) 324static int __maybe_unused intel_gpio_runtime_idle(struct device *dev)
325{ 325{
326 int err = pm_schedule_suspend(dev, 500); 326 int err = pm_schedule_suspend(dev, 500);
327 return err ?: -EBUSY; 327 return err ?: -EBUSY;
diff --git a/drivers/gpio/gpio-lp873x.c b/drivers/gpio/gpio-lp873x.c
index 218c706359aa..df0ad2cef0d2 100644
--- a/drivers/gpio/gpio-lp873x.c
+++ b/drivers/gpio/gpio-lp873x.c
@@ -100,21 +100,21 @@ static int lp873x_gpio_request(struct gpio_chip *gc, unsigned int offset)
100 return 0; 100 return 0;
101} 101}
102 102
103static int lp873x_gpio_set_single_ended(struct gpio_chip *gc, 103static int lp873x_gpio_set_config(struct gpio_chip *gc, unsigned offset,
104 unsigned int offset, 104 unsigned long config)
105 enum single_ended_mode mode)
106{ 105{
107 struct lp873x_gpio *gpio = gpiochip_get_data(gc); 106 struct lp873x_gpio *gpio = gpiochip_get_data(gc);
108 107
109 switch (mode) { 108 switch (pinconf_to_config_param(config)) {
110 case LINE_MODE_OPEN_DRAIN: 109 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
111 return regmap_update_bits(gpio->lp873->regmap, 110 return regmap_update_bits(gpio->lp873->regmap,
112 LP873X_REG_GPO_CTRL, 111 LP873X_REG_GPO_CTRL,
113 BIT(offset * BITS_PER_GPO + 112 BIT(offset * BITS_PER_GPO +
114 LP873X_GPO_CTRL_OD), 113 LP873X_GPO_CTRL_OD),
115 BIT(offset * BITS_PER_GPO + 114 BIT(offset * BITS_PER_GPO +
116 LP873X_GPO_CTRL_OD)); 115 LP873X_GPO_CTRL_OD));
117 case LINE_MODE_PUSH_PULL: 116
117 case PIN_CONFIG_DRIVE_PUSH_PULL:
118 return regmap_update_bits(gpio->lp873->regmap, 118 return regmap_update_bits(gpio->lp873->regmap,
119 LP873X_REG_GPO_CTRL, 119 LP873X_REG_GPO_CTRL,
120 BIT(offset * BITS_PER_GPO + 120 BIT(offset * BITS_PER_GPO +
@@ -133,7 +133,7 @@ static const struct gpio_chip template_chip = {
133 .direction_output = lp873x_gpio_direction_output, 133 .direction_output = lp873x_gpio_direction_output,
134 .get = lp873x_gpio_get, 134 .get = lp873x_gpio_get,
135 .set = lp873x_gpio_set, 135 .set = lp873x_gpio_set,
136 .set_single_ended = lp873x_gpio_set_single_ended, 136 .set_config = lp873x_gpio_set_config,
137 .base = -1, 137 .base = -1,
138 .ngpio = 2, 138 .ngpio = 2,
139 .can_sleep = true, 139 .can_sleep = true,
diff --git a/drivers/gpio/gpio-max77620.c b/drivers/gpio/gpio-max77620.c
index ec8de4190db9..743459d9477d 100644
--- a/drivers/gpio/gpio-max77620.c
+++ b/drivers/gpio/gpio-max77620.c
@@ -152,11 +152,10 @@ static int max77620_gpio_dir_output(struct gpio_chip *gc, unsigned int offset,
152 return ret; 152 return ret;
153} 153}
154 154
155static int max77620_gpio_set_debounce(struct gpio_chip *gc, 155static int max77620_gpio_set_debounce(struct max77620_gpio *mgpio,
156 unsigned int offset, 156 unsigned int offset,
157 unsigned int debounce) 157 unsigned int debounce)
158{ 158{
159 struct max77620_gpio *mgpio = gpiochip_get_data(gc);
160 u8 val; 159 u8 val;
161 int ret; 160 int ret;
162 161
@@ -202,21 +201,23 @@ static void max77620_gpio_set(struct gpio_chip *gc, unsigned int offset,
202 dev_err(mgpio->dev, "CNFG_GPIO_OUT update failed: %d\n", ret); 201 dev_err(mgpio->dev, "CNFG_GPIO_OUT update failed: %d\n", ret);
203} 202}
204 203
205static int max77620_gpio_set_single_ended(struct gpio_chip *gc, 204static int max77620_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
206 unsigned int offset, 205 unsigned long config)
207 enum single_ended_mode mode)
208{ 206{
209 struct max77620_gpio *mgpio = gpiochip_get_data(gc); 207 struct max77620_gpio *mgpio = gpiochip_get_data(gc);
210 208
211 switch (mode) { 209 switch (pinconf_to_config_param(config)) {
212 case LINE_MODE_OPEN_DRAIN: 210 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
213 return regmap_update_bits(mgpio->rmap, GPIO_REG_ADDR(offset), 211 return regmap_update_bits(mgpio->rmap, GPIO_REG_ADDR(offset),
214 MAX77620_CNFG_GPIO_DRV_MASK, 212 MAX77620_CNFG_GPIO_DRV_MASK,
215 MAX77620_CNFG_GPIO_DRV_OPENDRAIN); 213 MAX77620_CNFG_GPIO_DRV_OPENDRAIN);
216 case LINE_MODE_PUSH_PULL: 214 case PIN_CONFIG_DRIVE_PUSH_PULL:
217 return regmap_update_bits(mgpio->rmap, GPIO_REG_ADDR(offset), 215 return regmap_update_bits(mgpio->rmap, GPIO_REG_ADDR(offset),
218 MAX77620_CNFG_GPIO_DRV_MASK, 216 MAX77620_CNFG_GPIO_DRV_MASK,
219 MAX77620_CNFG_GPIO_DRV_PUSHPULL); 217 MAX77620_CNFG_GPIO_DRV_PUSHPULL);
218 case PIN_CONFIG_INPUT_DEBOUNCE:
219 return max77620_gpio_set_debounce(mgpio, offset,
220 pinconf_to_config_argument(config));
220 default: 221 default:
221 break; 222 break;
222 } 223 }
@@ -257,9 +258,8 @@ static int max77620_gpio_probe(struct platform_device *pdev)
257 mgpio->gpio_chip.direction_input = max77620_gpio_dir_input; 258 mgpio->gpio_chip.direction_input = max77620_gpio_dir_input;
258 mgpio->gpio_chip.get = max77620_gpio_get; 259 mgpio->gpio_chip.get = max77620_gpio_get;
259 mgpio->gpio_chip.direction_output = max77620_gpio_dir_output; 260 mgpio->gpio_chip.direction_output = max77620_gpio_dir_output;
260 mgpio->gpio_chip.set_debounce = max77620_gpio_set_debounce;
261 mgpio->gpio_chip.set = max77620_gpio_set; 261 mgpio->gpio_chip.set = max77620_gpio_set;
262 mgpio->gpio_chip.set_single_ended = max77620_gpio_set_single_ended; 262 mgpio->gpio_chip.set_config = max77620_gpio_set_config;
263 mgpio->gpio_chip.to_irq = max77620_gpio_to_irq; 263 mgpio->gpio_chip.to_irq = max77620_gpio_to_irq;
264 mgpio->gpio_chip.ngpio = MAX77620_GPIO_NR; 264 mgpio->gpio_chip.ngpio = MAX77620_GPIO_NR;
265 mgpio->gpio_chip.can_sleep = 1; 265 mgpio->gpio_chip.can_sleep = 1;
diff --git a/drivers/gpio/gpio-mcp23s08.c b/drivers/gpio/gpio-mcp23s08.c
index 504550665091..bdb692345428 100644
--- a/drivers/gpio/gpio-mcp23s08.c
+++ b/drivers/gpio/gpio-mcp23s08.c
@@ -23,6 +23,7 @@
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/of_irq.h> 24#include <linux/of_irq.h>
25#include <linux/of_device.h> 25#include <linux/of_device.h>
26#include <linux/regmap.h>
26 27
27/** 28/**
28 * MCP types supported by driver 29 * MCP types supported by driver
@@ -58,16 +59,10 @@
58 59
59struct mcp23s08; 60struct mcp23s08;
60 61
61struct mcp23s08_ops {
62 int (*read)(struct mcp23s08 *mcp, unsigned reg);
63 int (*write)(struct mcp23s08 *mcp, unsigned reg, unsigned val);
64 int (*read_regs)(struct mcp23s08 *mcp, unsigned reg,
65 u16 *vals, unsigned n);
66};
67
68struct mcp23s08 { 62struct mcp23s08 {
69 u8 addr; 63 u8 addr;
70 bool irq_active_high; 64 bool irq_active_high;
65 bool reg_shift;
71 66
72 u16 cache[11]; 67 u16 cache[11];
73 u16 irq_rise; 68 u16 irq_rise;
@@ -80,188 +75,126 @@ struct mcp23s08 {
80 75
81 struct gpio_chip chip; 76 struct gpio_chip chip;
82 77
83 const struct mcp23s08_ops *ops; 78 struct regmap *regmap;
84 void *data; /* ops specific data */ 79 struct device *dev;
85}; 80};
86 81
87/* A given spi_device can represent up to eight mcp23sxx chips 82static const struct regmap_config mcp23x08_regmap = {
88 * sharing the same chipselect but using different addresses 83 .reg_bits = 8,
89 * (e.g. chips #0 and #3 might be populated, but not #1 or $2). 84 .val_bits = 8,
90 * Driver data holds all the per-chip data.
91 */
92struct mcp23s08_driver_data {
93 unsigned ngpio;
94 struct mcp23s08 *mcp[8];
95 struct mcp23s08 chip[];
96};
97 85
98/*----------------------------------------------------------------------*/ 86 .reg_stride = 1,
99 87 .max_register = MCP_OLAT,
100#if IS_ENABLED(CONFIG_I2C)
101
102static int mcp23008_read(struct mcp23s08 *mcp, unsigned reg)
103{
104 return i2c_smbus_read_byte_data(mcp->data, reg);
105}
106
107static int mcp23008_write(struct mcp23s08 *mcp, unsigned reg, unsigned val)
108{
109 return i2c_smbus_write_byte_data(mcp->data, reg, val);
110}
111
112static int
113mcp23008_read_regs(struct mcp23s08 *mcp, unsigned reg, u16 *vals, unsigned n)
114{
115 while (n--) {
116 int ret = mcp23008_read(mcp, reg++);
117 if (ret < 0)
118 return ret;
119 *vals++ = ret;
120 }
121
122 return 0;
123}
124
125static int mcp23017_read(struct mcp23s08 *mcp, unsigned reg)
126{
127 return i2c_smbus_read_word_data(mcp->data, reg << 1);
128}
129
130static int mcp23017_write(struct mcp23s08 *mcp, unsigned reg, unsigned val)
131{
132 return i2c_smbus_write_word_data(mcp->data, reg << 1, val);
133}
134
135static int
136mcp23017_read_regs(struct mcp23s08 *mcp, unsigned reg, u16 *vals, unsigned n)
137{
138 while (n--) {
139 int ret = mcp23017_read(mcp, reg++);
140 if (ret < 0)
141 return ret;
142 *vals++ = ret;
143 }
144
145 return 0;
146}
147
148static const struct mcp23s08_ops mcp23008_ops = {
149 .read = mcp23008_read,
150 .write = mcp23008_write,
151 .read_regs = mcp23008_read_regs,
152}; 88};
153 89
154static const struct mcp23s08_ops mcp23017_ops = { 90static const struct regmap_config mcp23x17_regmap = {
155 .read = mcp23017_read, 91 .reg_bits = 8,
156 .write = mcp23017_write, 92 .val_bits = 16,
157 .read_regs = mcp23017_read_regs,
158};
159 93
160#endif /* CONFIG_I2C */ 94 .reg_stride = 2,
95 .max_register = MCP_OLAT << 1,
96 .val_format_endian = REGMAP_ENDIAN_LITTLE,
97};
161 98
162/*----------------------------------------------------------------------*/ 99/*----------------------------------------------------------------------*/
163 100
164#ifdef CONFIG_SPI_MASTER 101#ifdef CONFIG_SPI_MASTER
165 102
166static int mcp23s08_read(struct mcp23s08 *mcp, unsigned reg) 103static int mcp23sxx_spi_write(void *context, const void *data, size_t count)
167{ 104{
168 u8 tx[2], rx[1]; 105 struct mcp23s08 *mcp = context;
169 int status; 106 struct spi_device *spi = to_spi_device(mcp->dev);
107 struct spi_message m;
108 struct spi_transfer t[2] = { { .tx_buf = &mcp->addr, .len = 1, },
109 { .tx_buf = data, .len = count, }, };
170 110
171 tx[0] = mcp->addr | 0x01; 111 spi_message_init(&m);
172 tx[1] = reg; 112 spi_message_add_tail(&t[0], &m);
173 status = spi_write_then_read(mcp->data, tx, sizeof(tx), rx, sizeof(rx)); 113 spi_message_add_tail(&t[1], &m);
174 return (status < 0) ? status : rx[0]; 114
115 return spi_sync(spi, &m);
175} 116}
176 117
177static int mcp23s08_write(struct mcp23s08 *mcp, unsigned reg, unsigned val) 118static int mcp23sxx_spi_gather_write(void *context,
119 const void *reg, size_t reg_size,
120 const void *val, size_t val_size)
178{ 121{
179 u8 tx[3]; 122 struct mcp23s08 *mcp = context;
123 struct spi_device *spi = to_spi_device(mcp->dev);
124 struct spi_message m;
125 struct spi_transfer t[3] = { { .tx_buf = &mcp->addr, .len = 1, },
126 { .tx_buf = reg, .len = reg_size, },
127 { .tx_buf = val, .len = val_size, }, };
180 128
181 tx[0] = mcp->addr; 129 spi_message_init(&m);
182 tx[1] = reg; 130 spi_message_add_tail(&t[0], &m);
183 tx[2] = val; 131 spi_message_add_tail(&t[1], &m);
184 return spi_write_then_read(mcp->data, tx, sizeof(tx), NULL, 0); 132 spi_message_add_tail(&t[2], &m);
133
134 return spi_sync(spi, &m);
185} 135}
186 136
187static int 137static int mcp23sxx_spi_read(void *context, const void *reg, size_t reg_size,
188mcp23s08_read_regs(struct mcp23s08 *mcp, unsigned reg, u16 *vals, unsigned n) 138 void *val, size_t val_size)
189{ 139{
190 u8 tx[2], *tmp; 140 struct mcp23s08 *mcp = context;
191 int status; 141 struct spi_device *spi = to_spi_device(mcp->dev);
142 u8 tx[2];
192 143
193 if ((n + reg) > sizeof(mcp->cache)) 144 if (reg_size != 1)
194 return -EINVAL; 145 return -EINVAL;
146
195 tx[0] = mcp->addr | 0x01; 147 tx[0] = mcp->addr | 0x01;
196 tx[1] = reg; 148 tx[1] = *((u8 *) reg);
197 149
198 tmp = (u8 *)vals; 150 return spi_write_then_read(spi, tx, sizeof(tx), val, val_size);
199 status = spi_write_then_read(mcp->data, tx, sizeof(tx), tmp, n);
200 if (status >= 0) {
201 while (n--)
202 vals[n] = tmp[n]; /* expand to 16bit */
203 }
204 return status;
205} 151}
206 152
207static int mcp23s17_read(struct mcp23s08 *mcp, unsigned reg) 153static const struct regmap_bus mcp23sxx_spi_regmap = {
208{ 154 .write = mcp23sxx_spi_write,
209 u8 tx[2], rx[2]; 155 .gather_write = mcp23sxx_spi_gather_write,
210 int status; 156 .read = mcp23sxx_spi_read,
157};
211 158
212 tx[0] = mcp->addr | 0x01; 159#endif /* CONFIG_SPI_MASTER */
213 tx[1] = reg << 1;
214 status = spi_write_then_read(mcp->data, tx, sizeof(tx), rx, sizeof(rx));
215 return (status < 0) ? status : (rx[0] | (rx[1] << 8));
216}
217 160
218static int mcp23s17_write(struct mcp23s08 *mcp, unsigned reg, unsigned val) 161static int mcp_read(struct mcp23s08 *mcp, unsigned int reg, unsigned int *val)
219{ 162{
220 u8 tx[4]; 163 return regmap_read(mcp->regmap, reg << mcp->reg_shift, val);
221
222 tx[0] = mcp->addr;
223 tx[1] = reg << 1;
224 tx[2] = val;
225 tx[3] = val >> 8;
226 return spi_write_then_read(mcp->data, tx, sizeof(tx), NULL, 0);
227} 164}
228 165
229static int 166static int mcp_write(struct mcp23s08 *mcp, unsigned int reg, unsigned int val)
230mcp23s17_read_regs(struct mcp23s08 *mcp, unsigned reg, u16 *vals, unsigned n)
231{ 167{
232 u8 tx[2]; 168 return regmap_write(mcp->regmap, reg << mcp->reg_shift, val);
233 int status; 169}
234 170
235 if ((n + reg) > sizeof(mcp->cache)) 171static int mcp_update_cache(struct mcp23s08 *mcp)
236 return -EINVAL; 172{
237 tx[0] = mcp->addr | 0x01; 173 int ret, reg, i;
238 tx[1] = reg << 1;
239 174
240 status = spi_write_then_read(mcp->data, tx, sizeof(tx), 175 for (i = 0; i < ARRAY_SIZE(mcp->cache); i++) {
241 (u8 *)vals, n * 2); 176 ret = mcp_read(mcp, i, &reg);
242 if (status >= 0) { 177 if (ret < 0)
243 while (n--) 178 return ret;
244 vals[n] = __le16_to_cpu((__le16)vals[n]); 179 mcp->cache[i] = reg;
245 } 180 }
246 181
247 return status; 182 return 0;
248} 183}
249 184
250static const struct mcp23s08_ops mcp23s08_ops = { 185/*----------------------------------------------------------------------*/
251 .read = mcp23s08_read,
252 .write = mcp23s08_write,
253 .read_regs = mcp23s08_read_regs,
254};
255 186
256static const struct mcp23s08_ops mcp23s17_ops = { 187/* A given spi_device can represent up to eight mcp23sxx chips
257 .read = mcp23s17_read, 188 * sharing the same chipselect but using different addresses
258 .write = mcp23s17_write, 189 * (e.g. chips #0 and #3 might be populated, but not #1 or $2).
259 .read_regs = mcp23s17_read_regs, 190 * Driver data holds all the per-chip data.
191 */
192struct mcp23s08_driver_data {
193 unsigned ngpio;
194 struct mcp23s08 *mcp[8];
195 struct mcp23s08 chip[];
260}; 196};
261 197
262#endif /* CONFIG_SPI_MASTER */
263
264/*----------------------------------------------------------------------*/
265 198
266static int mcp23s08_direction_input(struct gpio_chip *chip, unsigned offset) 199static int mcp23s08_direction_input(struct gpio_chip *chip, unsigned offset)
267{ 200{
@@ -270,7 +203,7 @@ static int mcp23s08_direction_input(struct gpio_chip *chip, unsigned offset)
270 203
271 mutex_lock(&mcp->lock); 204 mutex_lock(&mcp->lock);
272 mcp->cache[MCP_IODIR] |= (1 << offset); 205 mcp->cache[MCP_IODIR] |= (1 << offset);
273 status = mcp->ops->write(mcp, MCP_IODIR, mcp->cache[MCP_IODIR]); 206 status = mcp_write(mcp, MCP_IODIR, mcp->cache[MCP_IODIR]);
274 mutex_unlock(&mcp->lock); 207 mutex_unlock(&mcp->lock);
275 return status; 208 return status;
276} 209}
@@ -278,13 +211,13 @@ static int mcp23s08_direction_input(struct gpio_chip *chip, unsigned offset)
278static int mcp23s08_get(struct gpio_chip *chip, unsigned offset) 211static int mcp23s08_get(struct gpio_chip *chip, unsigned offset)
279{ 212{
280 struct mcp23s08 *mcp = gpiochip_get_data(chip); 213 struct mcp23s08 *mcp = gpiochip_get_data(chip);
281 int status; 214 int status, ret;
282 215
283 mutex_lock(&mcp->lock); 216 mutex_lock(&mcp->lock);
284 217
285 /* REVISIT reading this clears any IRQ ... */ 218 /* REVISIT reading this clears any IRQ ... */
286 status = mcp->ops->read(mcp, MCP_GPIO); 219 ret = mcp_read(mcp, MCP_GPIO, &status);
287 if (status < 0) 220 if (ret < 0)
288 status = 0; 221 status = 0;
289 else { 222 else {
290 mcp->cache[MCP_GPIO] = status; 223 mcp->cache[MCP_GPIO] = status;
@@ -303,7 +236,7 @@ static int __mcp23s08_set(struct mcp23s08 *mcp, unsigned mask, int value)
303 else 236 else
304 olat &= ~mask; 237 olat &= ~mask;
305 mcp->cache[MCP_OLAT] = olat; 238 mcp->cache[MCP_OLAT] = olat;
306 return mcp->ops->write(mcp, MCP_OLAT, olat); 239 return mcp_write(mcp, MCP_OLAT, olat);
307} 240}
308 241
309static void mcp23s08_set(struct gpio_chip *chip, unsigned offset, int value) 242static void mcp23s08_set(struct gpio_chip *chip, unsigned offset, int value)
@@ -327,7 +260,7 @@ mcp23s08_direction_output(struct gpio_chip *chip, unsigned offset, int value)
327 status = __mcp23s08_set(mcp, mask, value); 260 status = __mcp23s08_set(mcp, mask, value);
328 if (status == 0) { 261 if (status == 0) {
329 mcp->cache[MCP_IODIR] &= ~mask; 262 mcp->cache[MCP_IODIR] &= ~mask;
330 status = mcp->ops->write(mcp, MCP_IODIR, mcp->cache[MCP_IODIR]); 263 status = mcp_write(mcp, MCP_IODIR, mcp->cache[MCP_IODIR]);
331 } 264 }
332 mutex_unlock(&mcp->lock); 265 mutex_unlock(&mcp->lock);
333 return status; 266 return status;
@@ -341,16 +274,14 @@ static irqreturn_t mcp23s08_irq(int irq, void *data)
341 unsigned int child_irq; 274 unsigned int child_irq;
342 275
343 mutex_lock(&mcp->lock); 276 mutex_lock(&mcp->lock);
344 intf = mcp->ops->read(mcp, MCP_INTF); 277 if (mcp_read(mcp, MCP_INTF, &intf) < 0) {
345 if (intf < 0) {
346 mutex_unlock(&mcp->lock); 278 mutex_unlock(&mcp->lock);
347 return IRQ_HANDLED; 279 return IRQ_HANDLED;
348 } 280 }
349 281
350 mcp->cache[MCP_INTF] = intf; 282 mcp->cache[MCP_INTF] = intf;
351 283
352 intcap = mcp->ops->read(mcp, MCP_INTCAP); 284 if (mcp_read(mcp, MCP_INTCAP, &intcap) < 0) {
353 if (intcap < 0) {
354 mutex_unlock(&mcp->lock); 285 mutex_unlock(&mcp->lock);
355 return IRQ_HANDLED; 286 return IRQ_HANDLED;
356 } 287 }
@@ -435,9 +366,9 @@ static void mcp23s08_irq_bus_unlock(struct irq_data *data)
435 struct mcp23s08 *mcp = gpiochip_get_data(gc); 366 struct mcp23s08 *mcp = gpiochip_get_data(gc);
436 367
437 mutex_lock(&mcp->lock); 368 mutex_lock(&mcp->lock);
438 mcp->ops->write(mcp, MCP_GPINTEN, mcp->cache[MCP_GPINTEN]); 369 mcp_write(mcp, MCP_GPINTEN, mcp->cache[MCP_GPINTEN]);
439 mcp->ops->write(mcp, MCP_DEFVAL, mcp->cache[MCP_DEFVAL]); 370 mcp_write(mcp, MCP_DEFVAL, mcp->cache[MCP_DEFVAL]);
440 mcp->ops->write(mcp, MCP_INTCON, mcp->cache[MCP_INTCON]); 371 mcp_write(mcp, MCP_INTCON, mcp->cache[MCP_INTCON]);
441 mutex_unlock(&mcp->lock); 372 mutex_unlock(&mcp->lock);
442 mutex_unlock(&mcp->irq_lock); 373 mutex_unlock(&mcp->irq_lock);
443} 374}
@@ -514,7 +445,7 @@ static void mcp23s08_dbg_show(struct seq_file *s, struct gpio_chip *chip)
514 bank = '0' + ((mcp->addr >> 1) & 0x7); 445 bank = '0' + ((mcp->addr >> 1) & 0x7);
515 446
516 mutex_lock(&mcp->lock); 447 mutex_lock(&mcp->lock);
517 t = mcp->ops->read_regs(mcp, 0, mcp->cache, ARRAY_SIZE(mcp->cache)); 448 t = mcp_update_cache(mcp);
518 if (t < 0) { 449 if (t < 0) {
519 seq_printf(s, " I/O ERROR %d\n", t); 450 seq_printf(s, " I/O ERROR %d\n", t);
520 goto done; 451 goto done;
@@ -549,12 +480,12 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
549 void *data, unsigned addr, unsigned type, 480 void *data, unsigned addr, unsigned type,
550 struct mcp23s08_platform_data *pdata, int cs) 481 struct mcp23s08_platform_data *pdata, int cs)
551{ 482{
552 int status; 483 int status, ret;
553 bool mirror = false; 484 bool mirror = false;
554 485
555 mutex_init(&mcp->lock); 486 mutex_init(&mcp->lock);
556 487
557 mcp->data = data; 488 mcp->dev = dev;
558 mcp->addr = addr; 489 mcp->addr = addr;
559 mcp->irq_active_high = false; 490 mcp->irq_active_high = false;
560 491
@@ -571,19 +502,25 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
571 switch (type) { 502 switch (type) {
572#ifdef CONFIG_SPI_MASTER 503#ifdef CONFIG_SPI_MASTER
573 case MCP_TYPE_S08: 504 case MCP_TYPE_S08:
574 mcp->ops = &mcp23s08_ops; 505 mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp,
506 &mcp23x08_regmap);
507 mcp->reg_shift = 0;
575 mcp->chip.ngpio = 8; 508 mcp->chip.ngpio = 8;
576 mcp->chip.label = "mcp23s08"; 509 mcp->chip.label = "mcp23s08";
577 break; 510 break;
578 511
579 case MCP_TYPE_S17: 512 case MCP_TYPE_S17:
580 mcp->ops = &mcp23s17_ops; 513 mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp,
514 &mcp23x17_regmap);
515 mcp->reg_shift = 1;
581 mcp->chip.ngpio = 16; 516 mcp->chip.ngpio = 16;
582 mcp->chip.label = "mcp23s17"; 517 mcp->chip.label = "mcp23s17";
583 break; 518 break;
584 519
585 case MCP_TYPE_S18: 520 case MCP_TYPE_S18:
586 mcp->ops = &mcp23s17_ops; 521 mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp,
522 &mcp23x17_regmap);
523 mcp->reg_shift = 1;
587 mcp->chip.ngpio = 16; 524 mcp->chip.ngpio = 16;
588 mcp->chip.label = "mcp23s18"; 525 mcp->chip.label = "mcp23s18";
589 break; 526 break;
@@ -591,13 +528,15 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
591 528
592#if IS_ENABLED(CONFIG_I2C) 529#if IS_ENABLED(CONFIG_I2C)
593 case MCP_TYPE_008: 530 case MCP_TYPE_008:
594 mcp->ops = &mcp23008_ops; 531 mcp->regmap = devm_regmap_init_i2c(data, &mcp23x08_regmap);
532 mcp->reg_shift = 0;
595 mcp->chip.ngpio = 8; 533 mcp->chip.ngpio = 8;
596 mcp->chip.label = "mcp23008"; 534 mcp->chip.label = "mcp23008";
597 break; 535 break;
598 536
599 case MCP_TYPE_017: 537 case MCP_TYPE_017:
600 mcp->ops = &mcp23017_ops; 538 mcp->regmap = devm_regmap_init_i2c(data, &mcp23x17_regmap);
539 mcp->reg_shift = 1;
601 mcp->chip.ngpio = 16; 540 mcp->chip.ngpio = 16;
602 mcp->chip.label = "mcp23017"; 541 mcp->chip.label = "mcp23017";
603 break; 542 break;
@@ -608,6 +547,9 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
608 return -EINVAL; 547 return -EINVAL;
609 } 548 }
610 549
550 if (IS_ERR(mcp->regmap))
551 return PTR_ERR(mcp->regmap);
552
611 mcp->chip.base = pdata->base; 553 mcp->chip.base = pdata->base;
612 mcp->chip.can_sleep = true; 554 mcp->chip.can_sleep = true;
613 mcp->chip.parent = dev; 555 mcp->chip.parent = dev;
@@ -617,8 +559,8 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
617 * and MCP_IOCON.HAEN = 1, so we work with all chips. 559 * and MCP_IOCON.HAEN = 1, so we work with all chips.
618 */ 560 */
619 561
620 status = mcp->ops->read(mcp, MCP_IOCON); 562 ret = mcp_read(mcp, MCP_IOCON, &status);
621 if (status < 0) 563 if (ret < 0)
622 goto fail; 564 goto fail;
623 565
624 mcp->irq_controller = pdata->irq_controller; 566 mcp->irq_controller = pdata->irq_controller;
@@ -646,51 +588,49 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
646 if (type == MCP_TYPE_S18) 588 if (type == MCP_TYPE_S18)
647 status |= IOCON_INTCC | (IOCON_INTCC << 8); 589 status |= IOCON_INTCC | (IOCON_INTCC << 8);
648 590
649 status = mcp->ops->write(mcp, MCP_IOCON, status); 591 ret = mcp_write(mcp, MCP_IOCON, status);
650 if (status < 0) 592 if (ret < 0)
651 goto fail; 593 goto fail;
652 } 594 }
653 595
654 /* configure ~100K pullups */ 596 /* configure ~100K pullups */
655 status = mcp->ops->write(mcp, MCP_GPPU, pdata->chip[cs].pullups); 597 ret = mcp_write(mcp, MCP_GPPU, pdata->chip[cs].pullups);
656 if (status < 0) 598 if (ret < 0)
657 goto fail; 599 goto fail;
658 600
659 status = mcp->ops->read_regs(mcp, 0, mcp->cache, ARRAY_SIZE(mcp->cache)); 601 ret = mcp_update_cache(mcp);
660 if (status < 0) 602 if (ret < 0)
661 goto fail; 603 goto fail;
662 604
663 /* disable inverter on input */ 605 /* disable inverter on input */
664 if (mcp->cache[MCP_IPOL] != 0) { 606 if (mcp->cache[MCP_IPOL] != 0) {
665 mcp->cache[MCP_IPOL] = 0; 607 mcp->cache[MCP_IPOL] = 0;
666 status = mcp->ops->write(mcp, MCP_IPOL, 0); 608 ret = mcp_write(mcp, MCP_IPOL, 0);
667 if (status < 0) 609 if (ret < 0)
668 goto fail; 610 goto fail;
669 } 611 }
670 612
671 /* disable irqs */ 613 /* disable irqs */
672 if (mcp->cache[MCP_GPINTEN] != 0) { 614 if (mcp->cache[MCP_GPINTEN] != 0) {
673 mcp->cache[MCP_GPINTEN] = 0; 615 mcp->cache[MCP_GPINTEN] = 0;
674 status = mcp->ops->write(mcp, MCP_GPINTEN, 0); 616 ret = mcp_write(mcp, MCP_GPINTEN, 0);
675 if (status < 0) 617 if (ret < 0)
676 goto fail; 618 goto fail;
677 } 619 }
678 620
679 status = gpiochip_add_data(&mcp->chip, mcp); 621 ret = gpiochip_add_data(&mcp->chip, mcp);
680 if (status < 0) 622 if (ret < 0)
681 goto fail; 623 goto fail;
682 624
683 if (mcp->irq && mcp->irq_controller) { 625 if (mcp->irq && mcp->irq_controller) {
684 status = mcp23s08_irq_setup(mcp); 626 ret = mcp23s08_irq_setup(mcp);
685 if (status) { 627 if (ret)
686 goto fail; 628 goto fail;
687 }
688 } 629 }
689fail: 630fail:
690 if (status < 0) 631 if (ret < 0)
691 dev_dbg(dev, "can't setup chip %d, --> %d\n", 632 dev_dbg(dev, "can't setup chip %d, --> %d\n", addr, ret);
692 addr, status); 633 return ret;
693 return status;
694} 634}
695 635
696/*----------------------------------------------------------------------*/ 636/*----------------------------------------------------------------------*/
diff --git a/drivers/gpio/gpio-menz127.c b/drivers/gpio/gpio-menz127.c
index a1210e330571..e1037582e34d 100644
--- a/drivers/gpio/gpio-menz127.c
+++ b/drivers/gpio/gpio-menz127.c
@@ -89,22 +89,18 @@ static int men_z127_debounce(struct gpio_chip *gc, unsigned gpio,
89 89
90static int men_z127_set_single_ended(struct gpio_chip *gc, 90static int men_z127_set_single_ended(struct gpio_chip *gc,
91 unsigned offset, 91 unsigned offset,
92 enum single_ended_mode mode) 92 enum pin_config_param param)
93{ 93{
94 struct men_z127_gpio *priv = gpiochip_get_data(gc); 94 struct men_z127_gpio *priv = gpiochip_get_data(gc);
95 u32 od_en; 95 u32 od_en;
96 96
97 if (mode != LINE_MODE_OPEN_DRAIN &&
98 mode != LINE_MODE_PUSH_PULL)
99 return -ENOTSUPP;
100
101 spin_lock(&gc->bgpio_lock); 97 spin_lock(&gc->bgpio_lock);
102 od_en = readl(priv->reg_base + MEN_Z127_ODER); 98 od_en = readl(priv->reg_base + MEN_Z127_ODER);
103 99
104 if (mode == LINE_MODE_OPEN_DRAIN) 100 if (param == PIN_CONFIG_DRIVE_OPEN_DRAIN)
105 od_en |= BIT(offset); 101 od_en |= BIT(offset);
106 else 102 else
107 /* Implicitly LINE_MODE_PUSH_PULL */ 103 /* Implicitly PIN_CONFIG_DRIVE_PUSH_PULL */
108 od_en &= ~BIT(offset); 104 od_en &= ~BIT(offset);
109 105
110 writel(od_en, priv->reg_base + MEN_Z127_ODER); 106 writel(od_en, priv->reg_base + MEN_Z127_ODER);
@@ -113,6 +109,27 @@ static int men_z127_set_single_ended(struct gpio_chip *gc,
113 return 0; 109 return 0;
114} 110}
115 111
112static int men_z127_set_config(struct gpio_chip *gc, unsigned offset,
113 unsigned long config)
114{
115 enum pin_config_param param = pinconf_to_config_param(config);
116
117 switch (param) {
118 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
119 case PIN_CONFIG_DRIVE_PUSH_PULL:
120 return men_z127_set_single_ended(gc, offset, param);
121
122 case PIN_CONFIG_INPUT_DEBOUNCE:
123 return men_z127_debounce(gc, offset,
124 pinconf_to_config_argument(config));
125
126 default:
127 break;
128 }
129
130 return -ENOTSUPP;
131}
132
116static int men_z127_probe(struct mcb_device *mdev, 133static int men_z127_probe(struct mcb_device *mdev,
117 const struct mcb_device_id *id) 134 const struct mcb_device_id *id)
118{ 135{
@@ -149,8 +166,7 @@ static int men_z127_probe(struct mcb_device *mdev,
149 if (ret) 166 if (ret)
150 goto err_unmap; 167 goto err_unmap;
151 168
152 men_z127_gpio->gc.set_debounce = men_z127_debounce; 169 men_z127_gpio->gc.set_config = men_z127_set_config;
153 men_z127_gpio->gc.set_single_ended = men_z127_set_single_ended;
154 170
155 ret = gpiochip_add_data(&men_z127_gpio->gc, men_z127_gpio); 171 ret = gpiochip_add_data(&men_z127_gpio->gc, men_z127_gpio);
156 if (ret) { 172 if (ret) {
diff --git a/drivers/gpio/gpio-merrifield.c b/drivers/gpio/gpio-merrifield.c
index 69e0f4ace465..f40088d268c1 100644
--- a/drivers/gpio/gpio-merrifield.c
+++ b/drivers/gpio/gpio-merrifield.c
@@ -190,6 +190,18 @@ static int mrfld_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,
190 return 0; 190 return 0;
191} 191}
192 192
193static int mrfld_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
194 unsigned long config)
195{
196 u32 debounce;
197
198 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
199 return -ENOTSUPP;
200
201 debounce = pinconf_to_config_argument(config);
202 return mrfld_gpio_set_debounce(chip, offset, debounce);
203}
204
193static void mrfld_irq_ack(struct irq_data *d) 205static void mrfld_irq_ack(struct irq_data *d)
194{ 206{
195 struct mrfld_gpio *priv = irq_data_get_irq_chip_data(d); 207 struct mrfld_gpio *priv = irq_data_get_irq_chip_data(d);
@@ -414,7 +426,7 @@ static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *id
414 priv->chip.get = mrfld_gpio_get; 426 priv->chip.get = mrfld_gpio_get;
415 priv->chip.set = mrfld_gpio_set; 427 priv->chip.set = mrfld_gpio_set;
416 priv->chip.get_direction = mrfld_gpio_get_direction; 428 priv->chip.get_direction = mrfld_gpio_get_direction;
417 priv->chip.set_debounce = mrfld_gpio_set_debounce; 429 priv->chip.set_config = mrfld_gpio_set_config;
418 priv->chip.base = gpio_base; 430 priv->chip.base = gpio_base;
419 priv->chip.ngpio = MRFLD_NGPIO; 431 priv->chip.ngpio = MRFLD_NGPIO;
420 priv->chip.can_sleep = false; 432 priv->chip.can_sleep = false;
diff --git a/drivers/gpio/gpio-mm-lantiq.c b/drivers/gpio/gpio-mm-lantiq.c
index 54e5d8257d34..b1cf76dd84ba 100644
--- a/drivers/gpio/gpio-mm-lantiq.c
+++ b/drivers/gpio/gpio-mm-lantiq.c
@@ -3,7 +3,7 @@
3 * under the terms of the GNU General Public License version 2 as published 3 * under the terms of the GNU General Public License version 2 as published
4 * by the Free Software Foundation. 4 * by the Free Software Foundation.
5 * 5 *
6 * Copyright (C) 2012 John Crispin <blogic@openwrt.org> 6 * Copyright (C) 2012 John Crispin <john@phrozen.org>
7 */ 7 */
8 8
9#include <linux/init.h> 9#include <linux/init.h>
diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index 1ef85b0c2b1f..82a9efd021db 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -43,7 +43,7 @@ static int gpio_mockup_ranges[MAX_GC << 1];
43static int gpio_mockup_params_nr; 43static int gpio_mockup_params_nr;
44module_param_array(gpio_mockup_ranges, int, &gpio_mockup_params_nr, 0400); 44module_param_array(gpio_mockup_ranges, int, &gpio_mockup_params_nr, 0400);
45 45
46const char pins_name_start = 'A'; 46static const char pins_name_start = 'A';
47 47
48static int mockup_gpio_get(struct gpio_chip *gc, unsigned int offset) 48static int mockup_gpio_get(struct gpio_chip *gc, unsigned int offset)
49{ 49{
@@ -120,13 +120,10 @@ err:
120 120
121static int mockup_gpio_probe(struct platform_device *pdev) 121static int mockup_gpio_probe(struct platform_device *pdev)
122{ 122{
123 struct device *dev = &pdev->dev;
124 struct mockup_gpio_controller *cntr; 123 struct mockup_gpio_controller *cntr;
125 int ret; 124 struct device *dev = &pdev->dev;
126 int i; 125 int ret, i, base, ngpio;
127 int base; 126 char *chip_name;
128 int ngpio;
129 char chip_name[sizeof(GPIO_NAME) + 3];
130 127
131 if (gpio_mockup_params_nr < 2) 128 if (gpio_mockup_params_nr < 2)
132 return -EINVAL; 129 return -EINVAL;
@@ -146,8 +143,12 @@ static int mockup_gpio_probe(struct platform_device *pdev)
146 ngpio = gpio_mockup_ranges[i * 2 + 1] - base; 143 ngpio = gpio_mockup_ranges[i * 2 + 1] - base;
147 144
148 if (ngpio >= 0) { 145 if (ngpio >= 0) {
149 sprintf(chip_name, "%s-%c", GPIO_NAME, 146 chip_name = devm_kasprintf(dev, GFP_KERNEL,
150 pins_name_start + i); 147 "%s-%c", GPIO_NAME,
148 pins_name_start + i);
149 if (!chip_name)
150 return -ENOMEM;
151
151 ret = mockup_gpio_add(dev, &cntr[i], 152 ret = mockup_gpio_add(dev, &cntr[i],
152 chip_name, base, ngpio); 153 chip_name, base, ngpio);
153 } else { 154 } else {
@@ -170,8 +171,8 @@ static int mockup_gpio_probe(struct platform_device *pdev)
170 171
171static struct platform_driver mockup_gpio_driver = { 172static struct platform_driver mockup_gpio_driver = {
172 .driver = { 173 .driver = {
173 .name = GPIO_NAME, 174 .name = GPIO_NAME,
174 }, 175 },
175 .probe = mockup_gpio_probe, 176 .probe = mockup_gpio_probe,
176}; 177};
177 178
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 1ed6132b993c..a649556ac3ca 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -659,7 +659,7 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
659 659
660 match = of_match_device(mvebu_gpio_of_match, &pdev->dev); 660 match = of_match_device(mvebu_gpio_of_match, &pdev->dev);
661 if (match) 661 if (match)
662 soc_variant = (int) match->data; 662 soc_variant = (unsigned long) match->data;
663 else 663 else
664 soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION; 664 soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION;
665 665
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index b98ede78c9d8..efc85a279d54 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -974,6 +974,18 @@ static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset,
974 return 0; 974 return 0;
975} 975}
976 976
977static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset,
978 unsigned long config)
979{
980 u32 debounce;
981
982 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
983 return -ENOTSUPP;
984
985 debounce = pinconf_to_config_argument(config);
986 return omap_gpio_debounce(chip, offset, debounce);
987}
988
977static void omap_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 989static void omap_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
978{ 990{
979 struct gpio_bank *bank; 991 struct gpio_bank *bank;
@@ -1045,7 +1057,7 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
1045 bank->chip.direction_input = omap_gpio_input; 1057 bank->chip.direction_input = omap_gpio_input;
1046 bank->chip.get = omap_gpio_get; 1058 bank->chip.get = omap_gpio_get;
1047 bank->chip.direction_output = omap_gpio_output; 1059 bank->chip.direction_output = omap_gpio_output;
1048 bank->chip.set_debounce = omap_gpio_debounce; 1060 bank->chip.set_config = omap_gpio_set_config;
1049 bank->chip.set = omap_gpio_set; 1061 bank->chip.set = omap_gpio_set;
1050 if (bank->is_mpuio) { 1062 if (bank->is_mpuio) {
1051 bank->chip.label = "mpuio"; 1063 bank->chip.label = "mpuio";
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index d5d72d84b719..d44232aadb6c 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -14,6 +14,7 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/gpio/consumer.h>
17#include <linux/interrupt.h> 18#include <linux/interrupt.h>
18#include <linux/i2c.h> 19#include <linux/i2c.h>
19#include <linux/platform_data/pca953x.h> 20#include <linux/platform_data/pca953x.h>
@@ -754,8 +755,16 @@ static int pca953x_probe(struct i2c_client *client,
754 invert = pdata->invert; 755 invert = pdata->invert;
755 chip->names = pdata->names; 756 chip->names = pdata->names;
756 } else { 757 } else {
758 struct gpio_desc *reset_gpio;
759
757 chip->gpio_start = -1; 760 chip->gpio_start = -1;
758 irq_base = 0; 761 irq_base = 0;
762
763 /* See if we need to de-assert a reset pin */
764 reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
765 GPIOD_OUT_LOW);
766 if (IS_ERR(reset_gpio))
767 return PTR_ERR(reset_gpio);
759 } 768 }
760 769
761 chip->client = client; 770 chip->client = client;
diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
index 2be48f5eba36..31ad288846af 100644
--- a/drivers/gpio/gpio-rcar.c
+++ b/drivers/gpio/gpio-rcar.c
@@ -242,11 +242,24 @@ static void gpio_rcar_config_general_input_output_mode(struct gpio_chip *chip,
242 242
243static int gpio_rcar_request(struct gpio_chip *chip, unsigned offset) 243static int gpio_rcar_request(struct gpio_chip *chip, unsigned offset)
244{ 244{
245 return pinctrl_request_gpio(chip->base + offset); 245 struct gpio_rcar_priv *p = gpiochip_get_data(chip);
246 int error;
247
248 error = pm_runtime_get_sync(&p->pdev->dev);
249 if (error < 0)
250 return error;
251
252 error = pinctrl_request_gpio(chip->base + offset);
253 if (error)
254 pm_runtime_put(&p->pdev->dev);
255
256 return error;
246} 257}
247 258
248static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset) 259static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset)
249{ 260{
261 struct gpio_rcar_priv *p = gpiochip_get_data(chip);
262
250 pinctrl_free_gpio(chip->base + offset); 263 pinctrl_free_gpio(chip->base + offset);
251 264
252 /* 265 /*
@@ -254,6 +267,8 @@ static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset)
254 * drive the GPIO pin as an output. 267 * drive the GPIO pin as an output.
255 */ 268 */
256 gpio_rcar_config_general_input_output_mode(chip, offset, false); 269 gpio_rcar_config_general_input_output_mode(chip, offset, false);
270
271 pm_runtime_put(&p->pdev->dev);
257} 272}
258 273
259static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset) 274static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset)
@@ -426,7 +441,6 @@ static int gpio_rcar_probe(struct platform_device *pdev)
426 } 441 }
427 442
428 pm_runtime_enable(dev); 443 pm_runtime_enable(dev);
429 pm_runtime_get_sync(dev);
430 444
431 io = platform_get_resource(pdev, IORESOURCE_MEM, 0); 445 io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
432 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 446 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -460,6 +474,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
460 474
461 irq_chip = &p->irq_chip; 475 irq_chip = &p->irq_chip;
462 irq_chip->name = name; 476 irq_chip->name = name;
477 irq_chip->parent_device = dev;
463 irq_chip->irq_mask = gpio_rcar_irq_disable; 478 irq_chip->irq_mask = gpio_rcar_irq_disable;
464 irq_chip->irq_unmask = gpio_rcar_irq_enable; 479 irq_chip->irq_unmask = gpio_rcar_irq_enable;
465 irq_chip->irq_set_type = gpio_rcar_irq_set_type; 480 irq_chip->irq_set_type = gpio_rcar_irq_set_type;
@@ -494,7 +509,6 @@ static int gpio_rcar_probe(struct platform_device *pdev)
494err1: 509err1:
495 gpiochip_remove(gpio_chip); 510 gpiochip_remove(gpio_chip);
496err0: 511err0:
497 pm_runtime_put(dev);
498 pm_runtime_disable(dev); 512 pm_runtime_disable(dev);
499 return ret; 513 return ret;
500} 514}
@@ -505,7 +519,6 @@ static int gpio_rcar_remove(struct platform_device *pdev)
505 519
506 gpiochip_remove(&p->gpio_chip); 520 gpiochip_remove(&p->gpio_chip);
507 521
508 pm_runtime_put(&pdev->dev);
509 pm_runtime_disable(&pdev->dev); 522 pm_runtime_disable(&pdev->dev);
510 return 0; 523 return 0;
511} 524}
diff --git a/drivers/gpio/gpio-stp-xway.c b/drivers/gpio/gpio-stp-xway.c
index 19e654f88b3a..c07385b71403 100644
--- a/drivers/gpio/gpio-stp-xway.c
+++ b/drivers/gpio/gpio-stp-xway.c
@@ -3,7 +3,7 @@
3 * under the terms of the GNU General Public License version 2 as published 3 * under the terms of the GNU General Public License version 2 as published
4 * by the Free Software Foundation. 4 * by the Free Software Foundation.
5 * 5 *
6 * Copyright (C) 2012 John Crispin <blogic@openwrt.org> 6 * Copyright (C) 2012 John Crispin <john@phrozen.org>
7 * 7 *
8 */ 8 */
9 9
diff --git a/drivers/gpio/gpio-tc3589x.c b/drivers/gpio/gpio-tc3589x.c
index be97101c2c9a..433b45ef332e 100644
--- a/drivers/gpio/gpio-tc3589x.c
+++ b/drivers/gpio/gpio-tc3589x.c
@@ -100,9 +100,8 @@ static int tc3589x_gpio_get_direction(struct gpio_chip *chip,
100 return !(ret & BIT(pos)); 100 return !(ret & BIT(pos));
101} 101}
102 102
103static int tc3589x_gpio_set_single_ended(struct gpio_chip *chip, 103static int tc3589x_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
104 unsigned int offset, 104 unsigned long config)
105 enum single_ended_mode mode)
106{ 105{
107 struct tc3589x_gpio *tc3589x_gpio = gpiochip_get_data(chip); 106 struct tc3589x_gpio *tc3589x_gpio = gpiochip_get_data(chip);
108 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 107 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
@@ -116,22 +115,22 @@ static int tc3589x_gpio_set_single_ended(struct gpio_chip *chip,
116 unsigned int pos = offset % 8; 115 unsigned int pos = offset % 8;
117 int ret; 116 int ret;
118 117
119 switch(mode) { 118 switch (pinconf_to_config_param(config)) {
120 case LINE_MODE_OPEN_DRAIN: 119 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
121 /* Set open drain mode */ 120 /* Set open drain mode */
122 ret = tc3589x_set_bits(tc3589x, odmreg, BIT(pos), 0); 121 ret = tc3589x_set_bits(tc3589x, odmreg, BIT(pos), 0);
123 if (ret) 122 if (ret)
124 return ret; 123 return ret;
125 /* Enable open drain/source mode */ 124 /* Enable open drain/source mode */
126 return tc3589x_set_bits(tc3589x, odereg, BIT(pos), BIT(pos)); 125 return tc3589x_set_bits(tc3589x, odereg, BIT(pos), BIT(pos));
127 case LINE_MODE_OPEN_SOURCE: 126 case PIN_CONFIG_DRIVE_OPEN_SOURCE:
128 /* Set open source mode */ 127 /* Set open source mode */
129 ret = tc3589x_set_bits(tc3589x, odmreg, BIT(pos), BIT(pos)); 128 ret = tc3589x_set_bits(tc3589x, odmreg, BIT(pos), BIT(pos));
130 if (ret) 129 if (ret)
131 return ret; 130 return ret;
132 /* Enable open drain/source mode */ 131 /* Enable open drain/source mode */
133 return tc3589x_set_bits(tc3589x, odereg, BIT(pos), BIT(pos)); 132 return tc3589x_set_bits(tc3589x, odereg, BIT(pos), BIT(pos));
134 case LINE_MODE_PUSH_PULL: 133 case PIN_CONFIG_DRIVE_PUSH_PULL:
135 /* Disable open drain/source mode */ 134 /* Disable open drain/source mode */
136 return tc3589x_set_bits(tc3589x, odereg, BIT(pos), 0); 135 return tc3589x_set_bits(tc3589x, odereg, BIT(pos), 0);
137 default: 136 default:
@@ -148,7 +147,7 @@ static const struct gpio_chip template_chip = {
148 .direction_output = tc3589x_gpio_direction_output, 147 .direction_output = tc3589x_gpio_direction_output,
149 .direction_input = tc3589x_gpio_direction_input, 148 .direction_input = tc3589x_gpio_direction_input,
150 .get_direction = tc3589x_gpio_get_direction, 149 .get_direction = tc3589x_gpio_get_direction,
151 .set_single_ended = tc3589x_gpio_set_single_ended, 150 .set_config = tc3589x_gpio_set_config,
152 .can_sleep = true, 151 .can_sleep = true,
153}; 152};
154 153
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 661b0e34e067..88529d3c06c9 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -238,6 +238,18 @@ static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,
238 return 0; 238 return 0;
239} 239}
240 240
241static int tegra_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
242 unsigned long config)
243{
244 u32 debounce;
245
246 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
247 return -ENOTSUPP;
248
249 debounce = pinconf_to_config_argument(config);
250 return tegra_gpio_set_debounce(chip, offset, debounce);
251}
252
241static int tegra_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 253static int tegra_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
242{ 254{
243 struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 255 struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
@@ -615,7 +627,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)
615 platform_set_drvdata(pdev, tgi); 627 platform_set_drvdata(pdev, tgi);
616 628
617 if (config->debounce_supported) 629 if (config->debounce_supported)
618 tgi->gc.set_debounce = tegra_gpio_set_debounce; 630 tgi->gc.set_config = tegra_gpio_set_config;
619 631
620 tgi->bank_info = devm_kzalloc(&pdev->dev, tgi->bank_count * 632 tgi->bank_info = devm_kzalloc(&pdev->dev, tgi->bank_count *
621 sizeof(*tgi->bank_info), GFP_KERNEL); 633 sizeof(*tgi->bank_info), GFP_KERNEL);
diff --git a/drivers/gpio/gpio-tps65218.c b/drivers/gpio/gpio-tps65218.c
index 46e6dcc089cb..a379bba57d31 100644
--- a/drivers/gpio/gpio-tps65218.c
+++ b/drivers/gpio/gpio-tps65218.c
@@ -139,28 +139,28 @@ static int tps65218_gpio_request(struct gpio_chip *gc, unsigned offset)
139 return 0; 139 return 0;
140} 140}
141 141
142static int tps65218_gpio_set_single_ended(struct gpio_chip *gc, 142static int tps65218_gpio_set_config(struct gpio_chip *gc, unsigned offset,
143 unsigned offset, 143 unsigned long config)
144 enum single_ended_mode mode)
145{ 144{
146 struct tps65218_gpio *tps65218_gpio = gpiochip_get_data(gc); 145 struct tps65218_gpio *tps65218_gpio = gpiochip_get_data(gc);
147 struct tps65218 *tps65218 = tps65218_gpio->tps65218; 146 struct tps65218 *tps65218 = tps65218_gpio->tps65218;
147 enum pin_config_param param = pinconf_to_config_param(config);
148 148
149 switch (offset) { 149 switch (offset) {
150 case 0: 150 case 0:
151 case 2: 151 case 2:
152 /* GPO1 is hardwired to be open drain */ 152 /* GPO1 is hardwired to be open drain */
153 if (mode == LINE_MODE_OPEN_DRAIN) 153 if (param == PIN_CONFIG_DRIVE_OPEN_DRAIN)
154 return 0; 154 return 0;
155 return -ENOTSUPP; 155 return -ENOTSUPP;
156 case 1: 156 case 1:
157 /* GPO2 is push-pull by default, can be set as open drain. */ 157 /* GPO2 is push-pull by default, can be set as open drain. */
158 if (mode == LINE_MODE_OPEN_DRAIN) 158 if (param == PIN_CONFIG_DRIVE_OPEN_DRAIN)
159 return tps65218_clear_bits(tps65218, 159 return tps65218_clear_bits(tps65218,
160 TPS65218_REG_CONFIG1, 160 TPS65218_REG_CONFIG1,
161 TPS65218_CONFIG1_GPO2_BUF, 161 TPS65218_CONFIG1_GPO2_BUF,
162 TPS65218_PROTECT_L1); 162 TPS65218_PROTECT_L1);
163 if (mode == LINE_MODE_PUSH_PULL) 163 if (param == PIN_CONFIG_DRIVE_PUSH_PULL)
164 return tps65218_set_bits(tps65218, 164 return tps65218_set_bits(tps65218,
165 TPS65218_REG_CONFIG1, 165 TPS65218_REG_CONFIG1,
166 TPS65218_CONFIG1_GPO2_BUF, 166 TPS65218_CONFIG1_GPO2_BUF,
@@ -181,7 +181,7 @@ static const struct gpio_chip template_chip = {
181 .direction_input = tps65218_gpio_input, 181 .direction_input = tps65218_gpio_input,
182 .get = tps65218_gpio_get, 182 .get = tps65218_gpio_get,
183 .set = tps65218_gpio_set, 183 .set = tps65218_gpio_set,
184 .set_single_ended = tps65218_gpio_set_single_ended, 184 .set_config = tps65218_gpio_set_config,
185 .can_sleep = true, 185 .can_sleep = true,
186 .ngpio = 3, 186 .ngpio = 3,
187 .base = -1, 187 .base = -1,
diff --git a/drivers/gpio/gpio-vx855.c b/drivers/gpio/gpio-vx855.c
index 4e450121129b..98a6f1fcc561 100644
--- a/drivers/gpio/gpio-vx855.c
+++ b/drivers/gpio/gpio-vx855.c
@@ -186,23 +186,24 @@ static int vx855gpio_direction_output(struct gpio_chip *gpio,
186 return 0; 186 return 0;
187} 187}
188 188
189static int vx855gpio_set_single_ended(struct gpio_chip *gpio, 189static int vx855gpio_set_config(struct gpio_chip *gpio, unsigned int nr,
190 unsigned int nr, 190 unsigned long config)
191 enum single_ended_mode mode)
192{ 191{
192 enum pin_config_param param = pinconf_to_config_param(config);
193
193 /* The GPI cannot be single-ended */ 194 /* The GPI cannot be single-ended */
194 if (nr < NR_VX855_GPI) 195 if (nr < NR_VX855_GPI)
195 return -EINVAL; 196 return -EINVAL;
196 197
197 /* The GPO's are push-pull */ 198 /* The GPO's are push-pull */
198 if (nr < NR_VX855_GPInO) { 199 if (nr < NR_VX855_GPInO) {
199 if (mode != LINE_MODE_PUSH_PULL) 200 if (param != PIN_CONFIG_DRIVE_PUSH_PULL)
200 return -ENOTSUPP; 201 return -ENOTSUPP;
201 return 0; 202 return 0;
202 } 203 }
203 204
204 /* The GPIO's are open drain */ 205 /* The GPIO's are open drain */
205 if (mode != LINE_MODE_OPEN_DRAIN) 206 if (param != PIN_CONFIG_DRIVE_OPEN_DRAIN)
206 return -ENOTSUPP; 207 return -ENOTSUPP;
207 208
208 return 0; 209 return 0;
@@ -231,7 +232,7 @@ static void vx855gpio_gpio_setup(struct vx855_gpio *vg)
231 c->direction_output = vx855gpio_direction_output; 232 c->direction_output = vx855gpio_direction_output;
232 c->get = vx855gpio_get; 233 c->get = vx855gpio_get;
233 c->set = vx855gpio_set; 234 c->set = vx855gpio_set;
234 c->set_single_ended = vx855gpio_set_single_ended; 235 c->set_config = vx855gpio_set_config,
235 c->dbg_show = NULL; 236 c->dbg_show = NULL;
236 c->base = 0; 237 c->base = 0;
237 c->ngpio = NR_VX855_GP; 238 c->ngpio = NR_VX855_GP;
diff --git a/drivers/gpio/gpio-wcove.c b/drivers/gpio/gpio-wcove.c
index 34baee5b1dd6..97613de5304e 100644
--- a/drivers/gpio/gpio-wcove.c
+++ b/drivers/gpio/gpio-wcove.c
@@ -202,17 +202,16 @@ static void wcove_gpio_set(struct gpio_chip *chip,
202 regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT), 1, 0); 202 regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT), 1, 0);
203} 203}
204 204
205static int wcove_gpio_set_single_ended(struct gpio_chip *chip, 205static int wcove_gpio_set_config(struct gpio_chip *chip, unsigned int gpio,
206 unsigned int gpio, 206 unsigned long config)
207 enum single_ended_mode mode)
208{ 207{
209 struct wcove_gpio *wg = gpiochip_get_data(chip); 208 struct wcove_gpio *wg = gpiochip_get_data(chip);
210 209
211 switch (mode) { 210 switch (pinconf_to_config_param(config)) {
212 case LINE_MODE_OPEN_DRAIN: 211 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
213 return regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT), 212 return regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT),
214 CTLO_DRV_MASK, CTLO_DRV_OD); 213 CTLO_DRV_MASK, CTLO_DRV_OD);
215 case LINE_MODE_PUSH_PULL: 214 case PIN_CONFIG_DRIVE_PUSH_PULL:
216 return regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT), 215 return regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT),
217 CTLO_DRV_MASK, CTLO_DRV_CMOS); 216 CTLO_DRV_MASK, CTLO_DRV_CMOS);
218 default: 217 default:
@@ -411,7 +410,7 @@ static int wcove_gpio_probe(struct platform_device *pdev)
411 wg->chip.get_direction = wcove_gpio_get_direction; 410 wg->chip.get_direction = wcove_gpio_get_direction;
412 wg->chip.get = wcove_gpio_get; 411 wg->chip.get = wcove_gpio_get;
413 wg->chip.set = wcove_gpio_set; 412 wg->chip.set = wcove_gpio_set;
414 wg->chip.set_single_ended = wcove_gpio_set_single_ended, 413 wg->chip.set_config = wcove_gpio_set_config,
415 wg->chip.base = -1; 414 wg->chip.base = -1;
416 wg->chip.ngpio = WCOVE_VGPIO_NUM; 415 wg->chip.ngpio = WCOVE_VGPIO_NUM;
417 wg->chip.can_sleep = true; 416 wg->chip.can_sleep = true;
diff --git a/drivers/gpio/gpio-wm831x.c b/drivers/gpio/gpio-wm831x.c
index 533707f943f4..00e3839b3f96 100644
--- a/drivers/gpio/gpio-wm831x.c
+++ b/drivers/gpio/gpio-wm831x.c
@@ -101,11 +101,9 @@ static int wm831x_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
101 WM831X_IRQ_GPIO_1 + offset); 101 WM831X_IRQ_GPIO_1 + offset);
102} 102}
103 103
104static int wm831x_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, 104static int wm831x_gpio_set_debounce(struct wm831x *wm831x, unsigned offset,
105 unsigned debounce) 105 unsigned debounce)
106{ 106{
107 struct wm831x_gpio *wm831x_gpio = gpiochip_get_data(chip);
108 struct wm831x *wm831x = wm831x_gpio->wm831x;
109 int reg = WM831X_GPIO1_CONTROL + offset; 107 int reg = WM831X_GPIO1_CONTROL + offset;
110 int ret, fn; 108 int ret, fn;
111 109
@@ -132,21 +130,23 @@ static int wm831x_gpio_set_debounce(struct gpio_chip *chip, unsigned offset,
132 return wm831x_set_bits(wm831x, reg, WM831X_GPN_FN_MASK, fn); 130 return wm831x_set_bits(wm831x, reg, WM831X_GPN_FN_MASK, fn);
133} 131}
134 132
135static int wm831x_set_single_ended(struct gpio_chip *chip, 133static int wm831x_set_config(struct gpio_chip *chip, unsigned int offset,
136 unsigned int offset, 134 unsigned long config)
137 enum single_ended_mode mode)
138{ 135{
139 struct wm831x_gpio *wm831x_gpio = gpiochip_get_data(chip); 136 struct wm831x_gpio *wm831x_gpio = gpiochip_get_data(chip);
140 struct wm831x *wm831x = wm831x_gpio->wm831x; 137 struct wm831x *wm831x = wm831x_gpio->wm831x;
141 int reg = WM831X_GPIO1_CONTROL + offset; 138 int reg = WM831X_GPIO1_CONTROL + offset;
142 139
143 switch (mode) { 140 switch (pinconf_to_config_param(config)) {
144 case LINE_MODE_OPEN_DRAIN: 141 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
145 return wm831x_set_bits(wm831x, reg, 142 return wm831x_set_bits(wm831x, reg,
146 WM831X_GPN_OD_MASK, WM831X_GPN_OD); 143 WM831X_GPN_OD_MASK, WM831X_GPN_OD);
147 case LINE_MODE_PUSH_PULL: 144 case PIN_CONFIG_DRIVE_PUSH_PULL:
148 return wm831x_set_bits(wm831x, reg, 145 return wm831x_set_bits(wm831x, reg,
149 WM831X_GPN_OD_MASK, 0); 146 WM831X_GPN_OD_MASK, 0);
147 case PIN_CONFIG_INPUT_DEBOUNCE:
148 return wm831x_gpio_set_debounce(wm831x, offset,
149 pinconf_to_config_argument(config));
150 default: 150 default:
151 break; 151 break;
152 } 152 }
@@ -255,8 +255,7 @@ static const struct gpio_chip template_chip = {
255 .direction_output = wm831x_gpio_direction_out, 255 .direction_output = wm831x_gpio_direction_out,
256 .set = wm831x_gpio_set, 256 .set = wm831x_gpio_set,
257 .to_irq = wm831x_gpio_to_irq, 257 .to_irq = wm831x_gpio_to_irq,
258 .set_debounce = wm831x_gpio_set_debounce, 258 .set_config = wm831x_set_config,
259 .set_single_ended = wm831x_set_single_ended,
260 .dbg_show = wm831x_gpio_dbg_show, 259 .dbg_show = wm831x_gpio_dbg_show,
261 .can_sleep = true, 260 .can_sleep = true,
262}; 261};
diff --git a/drivers/gpio/gpio-wm8994.c b/drivers/gpio/gpio-wm8994.c
index 68410fda6138..1e35756ac55b 100644
--- a/drivers/gpio/gpio-wm8994.c
+++ b/drivers/gpio/gpio-wm8994.c
@@ -103,19 +103,18 @@ static void wm8994_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
103 wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset, WM8994_GPN_LVL, value); 103 wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset, WM8994_GPN_LVL, value);
104} 104}
105 105
106static int wm8994_gpio_set_single_ended(struct gpio_chip *chip, 106static int wm8994_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
107 unsigned int offset, 107 unsigned long config)
108 enum single_ended_mode mode)
109{ 108{
110 struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip); 109 struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip);
111 struct wm8994 *wm8994 = wm8994_gpio->wm8994; 110 struct wm8994 *wm8994 = wm8994_gpio->wm8994;
112 111
113 switch (mode) { 112 switch (pinconf_to_config_param(config)) {
114 case LINE_MODE_OPEN_DRAIN: 113 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
115 return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset, 114 return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset,
116 WM8994_GPN_OP_CFG_MASK, 115 WM8994_GPN_OP_CFG_MASK,
117 WM8994_GPN_OP_CFG); 116 WM8994_GPN_OP_CFG);
118 case LINE_MODE_PUSH_PULL: 117 case PIN_CONFIG_DRIVE_PUSH_PULL:
119 return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset, 118 return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset,
120 WM8994_GPN_OP_CFG_MASK, 0); 119 WM8994_GPN_OP_CFG_MASK, 0);
121 default: 120 default:
@@ -257,7 +256,7 @@ static const struct gpio_chip template_chip = {
257 .get = wm8994_gpio_get, 256 .get = wm8994_gpio_get,
258 .direction_output = wm8994_gpio_direction_out, 257 .direction_output = wm8994_gpio_direction_out,
259 .set = wm8994_gpio_set, 258 .set = wm8994_gpio_set,
260 .set_single_ended = wm8994_gpio_set_single_ended, 259 .set_config = wm8994_gpio_set_config,
261 .to_irq = wm8994_gpio_to_irq, 260 .to_irq = wm8994_gpio_to_irq,
262 .dbg_show = wm8994_gpio_dbg_show, 261 .dbg_show = wm8994_gpio_dbg_show,
263 .can_sleep = true, 262 .can_sleep = true,
diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c
index eaa71d440ccf..901b5ccb032d 100644
--- a/drivers/gpio/gpio-ws16c48.c
+++ b/drivers/gpio/gpio-ws16c48.c
@@ -46,7 +46,6 @@ MODULE_PARM_DESC(irq, "WinSystems WS16C48 interrupt line numbers");
46 * @irq_mask: I/O bits affected by interrupts 46 * @irq_mask: I/O bits affected by interrupts
47 * @flow_mask: IRQ flow type mask for the respective I/O bits 47 * @flow_mask: IRQ flow type mask for the respective I/O bits
48 * @base: base port address of the GPIO device 48 * @base: base port address of the GPIO device
49 * @irq: Interrupt line number
50 */ 49 */
51struct ws16c48_gpio { 50struct ws16c48_gpio {
52 struct gpio_chip chip; 51 struct gpio_chip chip;
@@ -56,7 +55,6 @@ struct ws16c48_gpio {
56 unsigned long irq_mask; 55 unsigned long irq_mask;
57 unsigned long flow_mask; 56 unsigned long flow_mask;
58 unsigned base; 57 unsigned base;
59 unsigned irq;
60}; 58};
61 59
62static int ws16c48_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 60static int ws16c48_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
@@ -155,6 +153,46 @@ static void ws16c48_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
155 spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 153 spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
156} 154}
157 155
156static void ws16c48_gpio_set_multiple(struct gpio_chip *chip,
157 unsigned long *mask, unsigned long *bits)
158{
159 struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip);
160 unsigned int i;
161 const unsigned int gpio_reg_size = 8;
162 unsigned int port;
163 unsigned int iomask;
164 unsigned int bitmask;
165 unsigned long flags;
166
167 /* set bits are evaluated a gpio register size at a time */
168 for (i = 0; i < chip->ngpio; i += gpio_reg_size) {
169 /* no more set bits in this mask word; skip to the next word */
170 if (!mask[BIT_WORD(i)]) {
171 i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size;
172 continue;
173 }
174
175 port = i / gpio_reg_size;
176
177 /* mask out GPIO configured for input */
178 iomask = mask[BIT_WORD(i)] & ~ws16c48gpio->io_state[port];
179 bitmask = iomask & bits[BIT_WORD(i)];
180
181 spin_lock_irqsave(&ws16c48gpio->lock, flags);
182
183 /* update output state data and set device gpio register */
184 ws16c48gpio->out_state[port] &= ~iomask;
185 ws16c48gpio->out_state[port] |= bitmask;
186 outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port);
187
188 spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
189
190 /* prepare for next gpio register set */
191 mask[BIT_WORD(i)] >>= gpio_reg_size;
192 bits[BIT_WORD(i)] >>= gpio_reg_size;
193 }
194}
195
158static void ws16c48_irq_ack(struct irq_data *data) 196static void ws16c48_irq_ack(struct irq_data *data)
159{ 197{
160 struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 198 struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
@@ -303,6 +341,22 @@ static irqreturn_t ws16c48_irq_handler(int irq, void *dev_id)
303 return IRQ_HANDLED; 341 return IRQ_HANDLED;
304} 342}
305 343
344#define WS16C48_NGPIO 48
345static const char *ws16c48_names[WS16C48_NGPIO] = {
346 "Port 0 Bit 0", "Port 0 Bit 1", "Port 0 Bit 2", "Port 0 Bit 3",
347 "Port 0 Bit 4", "Port 0 Bit 5", "Port 0 Bit 6", "Port 0 Bit 7",
348 "Port 1 Bit 0", "Port 1 Bit 1", "Port 1 Bit 2", "Port 1 Bit 3",
349 "Port 1 Bit 4", "Port 1 Bit 5", "Port 1 Bit 6", "Port 1 Bit 7",
350 "Port 2 Bit 0", "Port 2 Bit 1", "Port 2 Bit 2", "Port 2 Bit 3",
351 "Port 2 Bit 4", "Port 2 Bit 5", "Port 2 Bit 6", "Port 2 Bit 7",
352 "Port 3 Bit 0", "Port 3 Bit 1", "Port 3 Bit 2", "Port 3 Bit 3",
353 "Port 3 Bit 4", "Port 3 Bit 5", "Port 3 Bit 6", "Port 3 Bit 7",
354 "Port 4 Bit 0", "Port 4 Bit 1", "Port 4 Bit 2", "Port 4 Bit 3",
355 "Port 4 Bit 4", "Port 4 Bit 5", "Port 4 Bit 6", "Port 4 Bit 7",
356 "Port 5 Bit 0", "Port 5 Bit 1", "Port 5 Bit 2", "Port 5 Bit 3",
357 "Port 5 Bit 4", "Port 5 Bit 5", "Port 5 Bit 6", "Port 5 Bit 7"
358};
359
306static int ws16c48_probe(struct device *dev, unsigned int id) 360static int ws16c48_probe(struct device *dev, unsigned int id)
307{ 361{
308 struct ws16c48_gpio *ws16c48gpio; 362 struct ws16c48_gpio *ws16c48gpio;
@@ -323,20 +377,19 @@ static int ws16c48_probe(struct device *dev, unsigned int id)
323 ws16c48gpio->chip.parent = dev; 377 ws16c48gpio->chip.parent = dev;
324 ws16c48gpio->chip.owner = THIS_MODULE; 378 ws16c48gpio->chip.owner = THIS_MODULE;
325 ws16c48gpio->chip.base = -1; 379 ws16c48gpio->chip.base = -1;
326 ws16c48gpio->chip.ngpio = 48; 380 ws16c48gpio->chip.ngpio = WS16C48_NGPIO;
381 ws16c48gpio->chip.names = ws16c48_names;
327 ws16c48gpio->chip.get_direction = ws16c48_gpio_get_direction; 382 ws16c48gpio->chip.get_direction = ws16c48_gpio_get_direction;
328 ws16c48gpio->chip.direction_input = ws16c48_gpio_direction_input; 383 ws16c48gpio->chip.direction_input = ws16c48_gpio_direction_input;
329 ws16c48gpio->chip.direction_output = ws16c48_gpio_direction_output; 384 ws16c48gpio->chip.direction_output = ws16c48_gpio_direction_output;
330 ws16c48gpio->chip.get = ws16c48_gpio_get; 385 ws16c48gpio->chip.get = ws16c48_gpio_get;
331 ws16c48gpio->chip.set = ws16c48_gpio_set; 386 ws16c48gpio->chip.set = ws16c48_gpio_set;
387 ws16c48gpio->chip.set_multiple = ws16c48_gpio_set_multiple;
332 ws16c48gpio->base = base[id]; 388 ws16c48gpio->base = base[id];
333 ws16c48gpio->irq = irq[id];
334 389
335 spin_lock_init(&ws16c48gpio->lock); 390 spin_lock_init(&ws16c48gpio->lock);
336 391
337 dev_set_drvdata(dev, ws16c48gpio); 392 err = devm_gpiochip_add_data(dev, &ws16c48gpio->chip, ws16c48gpio);
338
339 err = gpiochip_add_data(&ws16c48gpio->chip, ws16c48gpio);
340 if (err) { 393 if (err) {
341 dev_err(dev, "GPIO registering failed (%d)\n", err); 394 dev_err(dev, "GPIO registering failed (%d)\n", err);
342 return err; 395 return err;
@@ -353,31 +406,17 @@ static int ws16c48_probe(struct device *dev, unsigned int id)
353 handle_edge_irq, IRQ_TYPE_NONE); 406 handle_edge_irq, IRQ_TYPE_NONE);
354 if (err) { 407 if (err) {
355 dev_err(dev, "Could not add irqchip (%d)\n", err); 408 dev_err(dev, "Could not add irqchip (%d)\n", err);
356 goto err_gpiochip_remove; 409 return err;
357 } 410 }
358 411
359 err = request_irq(irq[id], ws16c48_irq_handler, IRQF_SHARED, name, 412 err = devm_request_irq(dev, irq[id], ws16c48_irq_handler, IRQF_SHARED,
360 ws16c48gpio); 413 name, ws16c48gpio);
361 if (err) { 414 if (err) {
362 dev_err(dev, "IRQ handler registering failed (%d)\n", err); 415 dev_err(dev, "IRQ handler registering failed (%d)\n", err);
363 goto err_gpiochip_remove; 416 return err;
364 } 417 }
365 418
366 return 0; 419 return 0;
367
368err_gpiochip_remove:
369 gpiochip_remove(&ws16c48gpio->chip);
370 return err;
371}
372
373static int ws16c48_remove(struct device *dev, unsigned int id)
374{
375 struct ws16c48_gpio *const ws16c48gpio = dev_get_drvdata(dev);
376
377 free_irq(ws16c48gpio->irq, ws16c48gpio);
378 gpiochip_remove(&ws16c48gpio->chip);
379
380 return 0;
381} 420}
382 421
383static struct isa_driver ws16c48_driver = { 422static struct isa_driver ws16c48_driver = {
@@ -385,7 +424,6 @@ static struct isa_driver ws16c48_driver = {
385 .driver = { 424 .driver = {
386 .name = "ws16c48" 425 .name = "ws16c48"
387 }, 426 },
388 .remove = ws16c48_remove
389}; 427};
390 428
391module_isa_driver(ws16c48_driver, num_ws16c48); 429module_isa_driver(ws16c48_driver, num_ws16c48);
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index a3faefa44f68..9b37a3692b3f 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -416,9 +416,8 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
416 agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT; 416 agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT;
417 417
418 /* 418 /*
419 * ActiveLow is only specified for GpioInt resource. If 419 * Polarity and triggering are only specified for GpioInt
420 * GpioIo is used then the only way to set the flag is 420 * resource.
421 * to use _DSD "gpios" property.
422 * Note: we expect here: 421 * Note: we expect here:
423 * - ACPI_ACTIVE_LOW == GPIO_ACTIVE_LOW 422 * - ACPI_ACTIVE_LOW == GPIO_ACTIVE_LOW
424 * - ACPI_ACTIVE_HIGH == GPIO_ACTIVE_HIGH 423 * - ACPI_ACTIVE_HIGH == GPIO_ACTIVE_HIGH
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 92b185f19232..975b9f6cf408 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -160,6 +160,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
160 * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API 160 * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API
161 * @np: device node to get GPIO from 161 * @np: device node to get GPIO from
162 * @chip: GPIO chip whose hog is parsed 162 * @chip: GPIO chip whose hog is parsed
163 * @idx: Index of the GPIO to parse
163 * @name: GPIO line name 164 * @name: GPIO line name
164 * @lflags: gpio_lookup_flags - returned from of_find_gpio() or 165 * @lflags: gpio_lookup_flags - returned from of_find_gpio() or
165 * of_parse_own_gpio() 166 * of_parse_own_gpio()
@@ -170,7 +171,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
170 */ 171 */
171static struct gpio_desc *of_parse_own_gpio(struct device_node *np, 172static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
172 struct gpio_chip *chip, 173 struct gpio_chip *chip,
173 const char **name, 174 unsigned int idx, const char **name,
174 enum gpio_lookup_flags *lflags, 175 enum gpio_lookup_flags *lflags,
175 enum gpiod_flags *dflags) 176 enum gpiod_flags *dflags)
176{ 177{
@@ -178,6 +179,7 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
178 enum of_gpio_flags xlate_flags; 179 enum of_gpio_flags xlate_flags;
179 struct of_phandle_args gpiospec; 180 struct of_phandle_args gpiospec;
180 struct gpio_desc *desc; 181 struct gpio_desc *desc;
182 unsigned int i;
181 u32 tmp; 183 u32 tmp;
182 int ret; 184 int ret;
183 185
@@ -196,9 +198,12 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
196 gpiospec.np = chip_np; 198 gpiospec.np = chip_np;
197 gpiospec.args_count = tmp; 199 gpiospec.args_count = tmp;
198 200
199 ret = of_property_read_u32_array(np, "gpios", gpiospec.args, tmp); 201 for (i = 0; i < tmp; i++) {
200 if (ret) 202 ret = of_property_read_u32_index(np, "gpios", idx * tmp + i,
201 return ERR_PTR(ret); 203 &gpiospec.args[i]);
204 if (ret)
205 return ERR_PTR(ret);
206 }
202 207
203 desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, &xlate_flags); 208 desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, &xlate_flags);
204 if (IS_ERR(desc)) 209 if (IS_ERR(desc))
@@ -240,20 +245,24 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
240 const char *name; 245 const char *name;
241 enum gpio_lookup_flags lflags; 246 enum gpio_lookup_flags lflags;
242 enum gpiod_flags dflags; 247 enum gpiod_flags dflags;
248 unsigned int i;
243 int ret; 249 int ret;
244 250
245 for_each_available_child_of_node(chip->of_node, np) { 251 for_each_available_child_of_node(chip->of_node, np) {
246 if (!of_property_read_bool(np, "gpio-hog")) 252 if (!of_property_read_bool(np, "gpio-hog"))
247 continue; 253 continue;
248 254
249 desc = of_parse_own_gpio(np, chip, &name, &lflags, &dflags); 255 for (i = 0;; i++) {
250 if (IS_ERR(desc)) 256 desc = of_parse_own_gpio(np, chip, i, &name, &lflags,
251 continue; 257 &dflags);
258 if (IS_ERR(desc))
259 break;
252 260
253 ret = gpiod_hog(desc, name, lflags, dflags); 261 ret = gpiod_hog(desc, name, lflags, dflags);
254 if (ret < 0) { 262 if (ret < 0) {
255 of_node_put(np); 263 of_node_put(np);
256 return ret; 264 return ret;
265 }
257 } 266 }
258 } 267 }
259 268
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 5e5d48c3512c..19fce24ea4a0 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1,3 +1,4 @@
1#include <linux/bitops.h>
1#include <linux/kernel.h> 2#include <linux/kernel.h>
2#include <linux/module.h> 3#include <linux/module.h>
3#include <linux/interrupt.h> 4#include <linux/interrupt.h>
@@ -982,7 +983,7 @@ static int gpio_chrdev_open(struct inode *inode, struct file *filp)
982 struct gpio_device, chrdev); 983 struct gpio_device, chrdev);
983 984
984 /* Fail on open if the backing gpiochip is gone */ 985 /* Fail on open if the backing gpiochip is gone */
985 if (!gdev || !gdev->chip) 986 if (!gdev->chip)
986 return -ENODEV; 987 return -ENODEV;
987 get_device(&gdev->dev); 988 get_device(&gdev->dev);
988 filp->private_data = gdev; 989 filp->private_data = gdev;
@@ -1001,8 +1002,6 @@ static int gpio_chrdev_release(struct inode *inode, struct file *filp)
1001 struct gpio_device *gdev = container_of(inode->i_cdev, 1002 struct gpio_device *gdev = container_of(inode->i_cdev,
1002 struct gpio_device, chrdev); 1003 struct gpio_device, chrdev);
1003 1004
1004 if (!gdev)
1005 return -ENODEV;
1006 put_device(&gdev->dev); 1005 put_device(&gdev->dev);
1007 return 0; 1006 return 0;
1008} 1007}
@@ -1423,8 +1422,7 @@ void devm_gpiochip_remove(struct device *dev, struct gpio_chip *chip)
1423 1422
1424 ret = devres_release(dev, devm_gpio_chip_release, 1423 ret = devres_release(dev, devm_gpio_chip_release,
1425 devm_gpio_chip_match, chip); 1424 devm_gpio_chip_match, chip);
1426 if (!ret) 1425 WARN_ON(ret);
1427 WARN_ON(ret);
1428} 1426}
1429EXPORT_SYMBOL_GPL(devm_gpiochip_remove); 1427EXPORT_SYMBOL_GPL(devm_gpiochip_remove);
1430 1428
@@ -1876,6 +1874,19 @@ void gpiochip_generic_free(struct gpio_chip *chip, unsigned offset)
1876} 1874}
1877EXPORT_SYMBOL_GPL(gpiochip_generic_free); 1875EXPORT_SYMBOL_GPL(gpiochip_generic_free);
1878 1876
1877/**
1878 * gpiochip_generic_config() - apply configuration for a pin
1879 * @chip: the gpiochip owning the GPIO
1880 * @offset: the offset of the GPIO to apply the configuration
1881 * @config: the configuration to be applied
1882 */
1883int gpiochip_generic_config(struct gpio_chip *chip, unsigned offset,
1884 unsigned long config)
1885{
1886 return pinctrl_gpio_set_config(chip->gpiodev->base + offset, config);
1887}
1888EXPORT_SYMBOL_GPL(gpiochip_generic_config);
1889
1879#ifdef CONFIG_PINCTRL 1890#ifdef CONFIG_PINCTRL
1880 1891
1881/** 1892/**
@@ -2264,6 +2275,14 @@ int gpiod_direction_input(struct gpio_desc *desc)
2264} 2275}
2265EXPORT_SYMBOL_GPL(gpiod_direction_input); 2276EXPORT_SYMBOL_GPL(gpiod_direction_input);
2266 2277
2278static int gpio_set_drive_single_ended(struct gpio_chip *gc, unsigned offset,
2279 enum pin_config_param mode)
2280{
2281 unsigned long config = { PIN_CONF_PACKED(mode, 0) };
2282
2283 return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP;
2284}
2285
2267static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value) 2286static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value)
2268{ 2287{
2269 struct gpio_chip *gc = desc->gdev->chip; 2288 struct gpio_chip *gc = desc->gdev->chip;
@@ -2280,32 +2299,25 @@ static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value)
2280 2299
2281 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { 2300 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) {
2282 /* First see if we can enable open drain in hardware */ 2301 /* First see if we can enable open drain in hardware */
2283 if (gc->set_single_ended) { 2302 ret = gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc),
2284 ret = gc->set_single_ended(gc, gpio_chip_hwgpio(desc), 2303 PIN_CONFIG_DRIVE_OPEN_DRAIN);
2285 LINE_MODE_OPEN_DRAIN); 2304 if (!ret)
2286 if (!ret) 2305 goto set_output_value;
2287 goto set_output_value;
2288 }
2289 /* Emulate open drain by not actively driving the line high */ 2306 /* Emulate open drain by not actively driving the line high */
2290 if (val) 2307 if (val)
2291 return gpiod_direction_input(desc); 2308 return gpiod_direction_input(desc);
2292 } 2309 }
2293 else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { 2310 else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) {
2294 if (gc->set_single_ended) { 2311 ret = gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc),
2295 ret = gc->set_single_ended(gc, gpio_chip_hwgpio(desc), 2312 PIN_CONFIG_DRIVE_OPEN_SOURCE);
2296 LINE_MODE_OPEN_SOURCE); 2313 if (!ret)
2297 if (!ret) 2314 goto set_output_value;
2298 goto set_output_value;
2299 }
2300 /* Emulate open source by not actively driving the line low */ 2315 /* Emulate open source by not actively driving the line low */
2301 if (!val) 2316 if (!val)
2302 return gpiod_direction_input(desc); 2317 return gpiod_direction_input(desc);
2303 } else { 2318 } else {
2304 /* Make sure to disable open drain/source hardware, if any */ 2319 gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc),
2305 if (gc->set_single_ended) 2320 PIN_CONFIG_DRIVE_PUSH_PULL);
2306 gc->set_single_ended(gc,
2307 gpio_chip_hwgpio(desc),
2308 LINE_MODE_PUSH_PULL);
2309 } 2321 }
2310 2322
2311set_output_value: 2323set_output_value:
@@ -2376,17 +2388,19 @@ EXPORT_SYMBOL_GPL(gpiod_direction_output);
2376int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) 2388int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
2377{ 2389{
2378 struct gpio_chip *chip; 2390 struct gpio_chip *chip;
2391 unsigned long config;
2379 2392
2380 VALIDATE_DESC(desc); 2393 VALIDATE_DESC(desc);
2381 chip = desc->gdev->chip; 2394 chip = desc->gdev->chip;
2382 if (!chip->set || !chip->set_debounce) { 2395 if (!chip->set || !chip->set_config) {
2383 gpiod_dbg(desc, 2396 gpiod_dbg(desc,
2384 "%s: missing set() or set_debounce() operations\n", 2397 "%s: missing set() or set_config() operations\n",
2385 __func__); 2398 __func__);
2386 return -ENOTSUPP; 2399 return -ENOTSUPP;
2387 } 2400 }
2388 2401
2389 return chip->set_debounce(chip, gpio_chip_hwgpio(desc), debounce); 2402 config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
2403 return chip->set_config(chip, gpio_chip_hwgpio(desc), config);
2390} 2404}
2391EXPORT_SYMBOL_GPL(gpiod_set_debounce); 2405EXPORT_SYMBOL_GPL(gpiod_set_debounce);
2392 2406
@@ -2570,18 +2584,11 @@ static void gpio_chip_set_multiple(struct gpio_chip *chip,
2570 if (chip->set_multiple) { 2584 if (chip->set_multiple) {
2571 chip->set_multiple(chip, mask, bits); 2585 chip->set_multiple(chip, mask, bits);
2572 } else { 2586 } else {
2573 int i; 2587 unsigned int i;
2574 for (i = 0; i < chip->ngpio; i++) { 2588
2575 if (mask[BIT_WORD(i)] == 0) { 2589 /* set outputs if the corresponding mask bit is set */
2576 /* no more set bits in this mask word; 2590 for_each_set_bit(i, mask, chip->ngpio)
2577 * skip ahead to the next word */ 2591 chip->set(chip, i, test_bit(i, bits));
2578 i = (BIT_WORD(i) + 1) * BITS_PER_LONG - 1;
2579 continue;
2580 }
2581 /* set outputs if the corresponding mask bit is set */
2582 if (__test_and_clear_bit(i, mask))
2583 chip->set(chip, i, test_bit(i, bits));
2584 }
2585 } 2592 }
2586} 2593}
2587 2594
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index d10eaf520860..2495b7ee1b42 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -76,7 +76,8 @@ struct gpio_device {
76/** 76/**
77 * struct acpi_gpio_info - ACPI GPIO specific information 77 * struct acpi_gpio_info - ACPI GPIO specific information
78 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo 78 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
79 * @active_low: in case of @gpioint, the pin is active low 79 * @polarity: interrupt polarity as provided by ACPI
80 * @triggering: triggering type as provided by ACPI
80 */ 81 */
81struct acpi_gpio_info { 82struct acpi_gpio_info {
82 bool gpioint; 83 bool gpioint;
diff --git a/drivers/pinctrl/bcm/pinctrl-bcm281xx.c b/drivers/pinctrl/bcm/pinctrl-bcm281xx.c
index a5331fdfc795..810a81786f62 100644
--- a/drivers/pinctrl/bcm/pinctrl-bcm281xx.c
+++ b/drivers/pinctrl/bcm/pinctrl-bcm281xx.c
@@ -1106,7 +1106,7 @@ static int bcm281xx_std_pin_update(struct pinctrl_dev *pctldev,
1106 struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev); 1106 struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
1107 int i; 1107 int i;
1108 enum pin_config_param param; 1108 enum pin_config_param param;
1109 u16 arg; 1109 u32 arg;
1110 1110
1111 for (i = 0; i < num_configs; i++) { 1111 for (i = 0; i < num_configs; i++) {
1112 param = pinconf_to_config_param(configs[i]); 1112 param = pinconf_to_config_param(configs[i]);
@@ -1222,7 +1222,7 @@ static int bcm281xx_i2c_pin_update(struct pinctrl_dev *pctldev,
1222 struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev); 1222 struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
1223 int i, j; 1223 int i, j;
1224 enum pin_config_param param; 1224 enum pin_config_param param;
1225 u16 arg; 1225 u32 arg;
1226 1226
1227 for (i = 0; i < num_configs; i++) { 1227 for (i = 0; i < num_configs; i++) {
1228 param = pinconf_to_config_param(configs[i]); 1228 param = pinconf_to_config_param(configs[i]);
@@ -1292,7 +1292,7 @@ static int bcm281xx_hdmi_pin_update(struct pinctrl_dev *pctldev,
1292 struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev); 1292 struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
1293 int i; 1293 int i;
1294 enum pin_config_param param; 1294 enum pin_config_param param;
1295 u16 arg; 1295 u32 arg;
1296 1296
1297 for (i = 0; i < num_configs; i++) { 1297 for (i = 0; i < num_configs; i++) {
1298 param = pinconf_to_config_param(configs[i]); 1298 param = pinconf_to_config_param(configs[i]);
diff --git a/drivers/pinctrl/bcm/pinctrl-iproc-gpio.c b/drivers/pinctrl/bcm/pinctrl-iproc-gpio.c
index 5d1e505c3c63..3ca925dfefd1 100644
--- a/drivers/pinctrl/bcm/pinctrl-iproc-gpio.c
+++ b/drivers/pinctrl/bcm/pinctrl-iproc-gpio.c
@@ -619,7 +619,7 @@ static int iproc_pin_config_set(struct pinctrl_dev *pctldev, unsigned pin,
619{ 619{
620 struct iproc_gpio *chip = pinctrl_dev_get_drvdata(pctldev); 620 struct iproc_gpio *chip = pinctrl_dev_get_drvdata(pctldev);
621 enum pin_config_param param; 621 enum pin_config_param param;
622 u16 arg; 622 u32 arg;
623 unsigned i, gpio = iproc_pin_to_gpio(pin); 623 unsigned i, gpio = iproc_pin_to_gpio(pin);
624 int ret = -ENOTSUPP; 624 int ret = -ENOTSUPP;
625 625
diff --git a/drivers/pinctrl/bcm/pinctrl-ns2-mux.c b/drivers/pinctrl/bcm/pinctrl-ns2-mux.c
index 13a4c2774157..4b5cf0e0f16e 100644
--- a/drivers/pinctrl/bcm/pinctrl-ns2-mux.c
+++ b/drivers/pinctrl/bcm/pinctrl-ns2-mux.c
@@ -703,7 +703,7 @@ static int ns2_pin_get_enable(struct pinctrl_dev *pctrldev, unsigned int pin)
703} 703}
704 704
705static int ns2_pin_set_slew(struct pinctrl_dev *pctrldev, unsigned int pin, 705static int ns2_pin_set_slew(struct pinctrl_dev *pctrldev, unsigned int pin,
706 u16 slew) 706 u32 slew)
707{ 707{
708 struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrldev); 708 struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrldev);
709 struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data; 709 struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data;
@@ -793,7 +793,7 @@ static void ns2_pin_get_pull(struct pinctrl_dev *pctrldev,
793} 793}
794 794
795static int ns2_pin_set_strength(struct pinctrl_dev *pctrldev, unsigned int pin, 795static int ns2_pin_set_strength(struct pinctrl_dev *pctrldev, unsigned int pin,
796 u16 strength) 796 u32 strength)
797{ 797{
798 struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrldev); 798 struct ns2_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrldev);
799 struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data; 799 struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data;
@@ -904,7 +904,7 @@ static int ns2_pin_config_set(struct pinctrl_dev *pctrldev, unsigned int pin,
904 struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data; 904 struct ns2_pin *pin_data = pctrldev->desc->pins[pin].drv_data;
905 enum pin_config_param param; 905 enum pin_config_param param;
906 unsigned int i; 906 unsigned int i;
907 u16 arg; 907 u32 arg;
908 int ret = -ENOTSUPP; 908 int ret = -ENOTSUPP;
909 909
910 if (pin_data->pin_conf.base == -1) 910 if (pin_data->pin_conf.base == -1)
diff --git a/drivers/pinctrl/bcm/pinctrl-nsp-gpio.c b/drivers/pinctrl/bcm/pinctrl-nsp-gpio.c
index c8deb8be1da7..91ea32dc1e7f 100644
--- a/drivers/pinctrl/bcm/pinctrl-nsp-gpio.c
+++ b/drivers/pinctrl/bcm/pinctrl-nsp-gpio.c
@@ -366,7 +366,7 @@ static const struct pinctrl_ops nsp_pctrl_ops = {
366 .dt_free_map = pinctrl_utils_free_map, 366 .dt_free_map = pinctrl_utils_free_map,
367}; 367};
368 368
369static int nsp_gpio_set_slew(struct nsp_gpio *chip, unsigned gpio, u16 slew) 369static int nsp_gpio_set_slew(struct nsp_gpio *chip, unsigned gpio, u32 slew)
370{ 370{
371 if (slew) 371 if (slew)
372 nsp_set_bit(chip, IO_CTRL, NSP_GPIO_SLEW_RATE_EN, gpio, true); 372 nsp_set_bit(chip, IO_CTRL, NSP_GPIO_SLEW_RATE_EN, gpio, true);
@@ -403,7 +403,7 @@ static void nsp_gpio_get_pull(struct nsp_gpio *chip, unsigned gpio,
403} 403}
404 404
405static int nsp_gpio_set_strength(struct nsp_gpio *chip, unsigned gpio, 405static int nsp_gpio_set_strength(struct nsp_gpio *chip, unsigned gpio,
406 u16 strength) 406 u32 strength)
407{ 407{
408 u32 offset, shift, i; 408 u32 offset, shift, i;
409 u32 val; 409 u32 val;
@@ -522,7 +522,7 @@ static int nsp_pin_config_set(struct pinctrl_dev *pctldev, unsigned pin,
522{ 522{
523 struct nsp_gpio *chip = pinctrl_dev_get_drvdata(pctldev); 523 struct nsp_gpio *chip = pinctrl_dev_get_drvdata(pctldev);
524 enum pin_config_param param; 524 enum pin_config_param param;
525 u16 arg; 525 u32 arg;
526 unsigned int i, gpio; 526 unsigned int i, gpio;
527 int ret = -ENOTSUPP; 527 int ret = -ENOTSUPP;
528 528
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index fb38e208f32d..597d4641e348 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -688,6 +688,35 @@ int pinctrl_gpio_direction_output(unsigned gpio)
688} 688}
689EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output); 689EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
690 690
691/**
692 * pinctrl_gpio_set_config() - Apply config to given GPIO pin
693 * @gpio: the GPIO pin number from the GPIO subsystem number space
694 * @config: the configuration to apply to the GPIO
695 *
696 * This function should *ONLY* be used from gpiolib-based GPIO drivers, if
697 * they need to call the underlying pin controller to change GPIO config
698 * (for example set debounce time).
699 */
700int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
701{
702 unsigned long configs[] = { config };
703 struct pinctrl_gpio_range *range;
704 struct pinctrl_dev *pctldev;
705 int ret, pin;
706
707 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
708 if (ret)
709 return ret;
710
711 mutex_lock(&pctldev->mutex);
712 pin = gpio_to_pin(range, gpio);
713 ret = pinconf_set_config(pctldev, pin, configs, ARRAY_SIZE(configs));
714 mutex_unlock(&pctldev->mutex);
715
716 return ret;
717}
718EXPORT_SYMBOL_GPL(pinctrl_gpio_set_config);
719
691static struct pinctrl_state *find_state(struct pinctrl *p, 720static struct pinctrl_state *find_state(struct pinctrl *p,
692 const char *name) 721 const char *name)
693{ 722{
diff --git a/drivers/pinctrl/intel/pinctrl-cherryview.c b/drivers/pinctrl/intel/pinctrl-cherryview.c
index 5e66860a5e67..f80134e3e0b6 100644
--- a/drivers/pinctrl/intel/pinctrl-cherryview.c
+++ b/drivers/pinctrl/intel/pinctrl-cherryview.c
@@ -1059,7 +1059,7 @@ static int chv_config_get(struct pinctrl_dev *pctldev, unsigned pin,
1059} 1059}
1060 1060
1061static int chv_config_set_pull(struct chv_pinctrl *pctrl, unsigned pin, 1061static int chv_config_set_pull(struct chv_pinctrl *pctrl, unsigned pin,
1062 enum pin_config_param param, u16 arg) 1062 enum pin_config_param param, u32 arg)
1063{ 1063{
1064 void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL0); 1064 void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL0);
1065 unsigned long flags; 1065 unsigned long flags;
@@ -1151,7 +1151,7 @@ static int chv_config_set(struct pinctrl_dev *pctldev, unsigned pin,
1151 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 1151 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
1152 enum pin_config_param param; 1152 enum pin_config_param param;
1153 int i, ret; 1153 int i, ret;
1154 u16 arg; 1154 u32 arg;
1155 1155
1156 if (chv_pad_locked(pctrl, pin)) 1156 if (chv_pad_locked(pctrl, pin))
1157 return -EBUSY; 1157 return -EBUSY;
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
index f9aef2ac03a1..3cf384f8b122 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
@@ -1054,6 +1054,18 @@ static int mtk_gpio_set_debounce(struct gpio_chip *chip, unsigned offset,
1054 return 0; 1054 return 0;
1055} 1055}
1056 1056
1057static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned offset,
1058 unsigned long config)
1059{
1060 u32 debounce;
1061
1062 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
1063 return -ENOTSUPP;
1064
1065 debounce = pinconf_to_config_argument(config);
1066 return mtk_gpio_set_debounce(chip, offset, debounce);
1067}
1068
1057static const struct gpio_chip mtk_gpio_chip = { 1069static const struct gpio_chip mtk_gpio_chip = {
1058 .owner = THIS_MODULE, 1070 .owner = THIS_MODULE,
1059 .request = gpiochip_generic_request, 1071 .request = gpiochip_generic_request,
@@ -1064,7 +1076,7 @@ static const struct gpio_chip mtk_gpio_chip = {
1064 .get = mtk_gpio_get, 1076 .get = mtk_gpio_get,
1065 .set = mtk_gpio_set, 1077 .set = mtk_gpio_set,
1066 .to_irq = mtk_gpio_to_irq, 1078 .to_irq = mtk_gpio_to_irq,
1067 .set_debounce = mtk_gpio_set_debounce, 1079 .set_config = mtk_gpio_set_config,
1068 .of_gpio_n_cells = 2, 1080 .of_gpio_n_cells = 2,
1069}; 1081};
1070 1082
diff --git a/drivers/pinctrl/meson/pinctrl-meson.c b/drivers/pinctrl/meson/pinctrl-meson.c
index a579126832af..8fbb571f50de 100644
--- a/drivers/pinctrl/meson/pinctrl-meson.c
+++ b/drivers/pinctrl/meson/pinctrl-meson.c
@@ -260,7 +260,6 @@ static int meson_pinconf_set(struct pinctrl_dev *pcdev, unsigned int pin,
260 enum pin_config_param param; 260 enum pin_config_param param;
261 unsigned int reg, bit; 261 unsigned int reg, bit;
262 int i, ret; 262 int i, ret;
263 u16 arg;
264 263
265 ret = meson_get_bank(pc, pin, &bank); 264 ret = meson_get_bank(pc, pin, &bank);
266 if (ret) 265 if (ret)
@@ -268,7 +267,6 @@ static int meson_pinconf_set(struct pinctrl_dev *pcdev, unsigned int pin,
268 267
269 for (i = 0; i < num_configs; i++) { 268 for (i = 0; i < num_configs; i++) {
270 param = pinconf_to_config_param(configs[i]); 269 param = pinconf_to_config_param(configs[i]);
271 arg = pinconf_to_config_argument(configs[i]);
272 270
273 switch (param) { 271 switch (param) {
274 case PIN_CONFIG_BIAS_DISABLE: 272 case PIN_CONFIG_BIAS_DISABLE:
diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c
index 799048f3c8d4..c1c1ccc58267 100644
--- a/drivers/pinctrl/pinconf.c
+++ b/drivers/pinctrl/pinconf.c
@@ -200,6 +200,18 @@ int pinconf_apply_setting(struct pinctrl_setting const *setting)
200 return 0; 200 return 0;
201} 201}
202 202
203int pinconf_set_config(struct pinctrl_dev *pctldev, unsigned pin,
204 unsigned long *configs, size_t nconfigs)
205{
206 const struct pinconf_ops *ops;
207
208 ops = pctldev->desc->confops;
209 if (!ops)
210 return -ENOTSUPP;
211
212 return ops->pin_config_set(pctldev, pin, configs, nconfigs);
213}
214
203#ifdef CONFIG_DEBUG_FS 215#ifdef CONFIG_DEBUG_FS
204 216
205static void pinconf_show_config(struct seq_file *s, struct pinctrl_dev *pctldev, 217static void pinconf_show_config(struct seq_file *s, struct pinctrl_dev *pctldev,
diff --git a/drivers/pinctrl/pinconf.h b/drivers/pinctrl/pinconf.h
index 55c75780b3b2..bf8aff9abf32 100644
--- a/drivers/pinctrl/pinconf.h
+++ b/drivers/pinctrl/pinconf.h
@@ -20,6 +20,9 @@ int pinconf_map_to_setting(struct pinctrl_map const *map,
20void pinconf_free_setting(struct pinctrl_setting const *setting); 20void pinconf_free_setting(struct pinctrl_setting const *setting);
21int pinconf_apply_setting(struct pinctrl_setting const *setting); 21int pinconf_apply_setting(struct pinctrl_setting const *setting);
22 22
23int pinconf_set_config(struct pinctrl_dev *pctldev, unsigned pin,
24 unsigned long *configs, size_t nconfigs);
25
23/* 26/*
24 * You will only be interested in these if you're using PINCONF 27 * You will only be interested in these if you're using PINCONF
25 * so don't supply any stubs for these. 28 * so don't supply any stubs for these.
@@ -56,6 +59,12 @@ static inline int pinconf_apply_setting(struct pinctrl_setting const *setting)
56 return 0; 59 return 0;
57} 60}
58 61
62static inline int pinconf_set_config(struct pinctrl_dev *pctldev, unsigned pin,
63 unsigned long *configs, size_t nconfigs)
64{
65 return -ENOTSUPP;
66}
67
59#endif 68#endif
60 69
61#if defined(CONFIG_PINCONF) && defined(CONFIG_DEBUG_FS) 70#if defined(CONFIG_PINCONF) && defined(CONFIG_DEBUG_FS)
diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
index aea310a91821..e440665ecc35 100644
--- a/drivers/pinctrl/pinctrl-amd.c
+++ b/drivers/pinctrl/pinctrl-amd.c
@@ -164,6 +164,18 @@ static int amd_gpio_set_debounce(struct gpio_chip *gc, unsigned offset,
164 return ret; 164 return ret;
165} 165}
166 166
167static int amd_gpio_set_config(struct gpio_chip *gc, unsigned offset,
168 unsigned long config)
169{
170 u32 debounce;
171
172 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
173 return -ENOTSUPP;
174
175 debounce = pinconf_to_config_argument(config);
176 return amd_gpio_set_debounce(gc, offset, debounce);
177}
178
167#ifdef CONFIG_DEBUG_FS 179#ifdef CONFIG_DEBUG_FS
168static void amd_gpio_dbg_show(struct seq_file *s, struct gpio_chip *gc) 180static void amd_gpio_dbg_show(struct seq_file *s, struct gpio_chip *gc)
169{ 181{
@@ -761,7 +773,7 @@ static int amd_gpio_probe(struct platform_device *pdev)
761 gpio_dev->gc.direction_output = amd_gpio_direction_output; 773 gpio_dev->gc.direction_output = amd_gpio_direction_output;
762 gpio_dev->gc.get = amd_gpio_get_value; 774 gpio_dev->gc.get = amd_gpio_get_value;
763 gpio_dev->gc.set = amd_gpio_set_value; 775 gpio_dev->gc.set = amd_gpio_set_value;
764 gpio_dev->gc.set_debounce = amd_gpio_set_debounce; 776 gpio_dev->gc.set_config = amd_gpio_set_config;
765 gpio_dev->gc.dbg_show = amd_gpio_dbg_show; 777 gpio_dev->gc.dbg_show = amd_gpio_dbg_show;
766 778
767 gpio_dev->gc.base = 0; 779 gpio_dev->gc.base = 0;
diff --git a/drivers/pinctrl/pinctrl-da850-pupd.c b/drivers/pinctrl/pinctrl-da850-pupd.c
index b36a90a3f3e4..44d5f5f5b07f 100644
--- a/drivers/pinctrl/pinctrl-da850-pupd.c
+++ b/drivers/pinctrl/pinctrl-da850-pupd.c
@@ -113,7 +113,6 @@ static int da850_pupd_pin_config_group_set(struct pinctrl_dev *pctldev,
113 struct da850_pupd_data *data = pinctrl_dev_get_drvdata(pctldev); 113 struct da850_pupd_data *data = pinctrl_dev_get_drvdata(pctldev);
114 u32 ena, sel; 114 u32 ena, sel;
115 enum pin_config_param param; 115 enum pin_config_param param;
116 u16 arg;
117 int i; 116 int i;
118 117
119 ena = readl(data->base + DA850_PUPD_ENA); 118 ena = readl(data->base + DA850_PUPD_ENA);
@@ -121,7 +120,6 @@ static int da850_pupd_pin_config_group_set(struct pinctrl_dev *pctldev,
121 120
122 for (i = 0; i < num_configs; i++) { 121 for (i = 0; i < num_configs; i++) {
123 param = pinconf_to_config_param(configs[i]); 122 param = pinconf_to_config_param(configs[i]);
124 arg = pinconf_to_config_argument(configs[i]);
125 123
126 switch (param) { 124 switch (param) {
127 case PIN_CONFIG_BIAS_DISABLE: 125 case PIN_CONFIG_BIAS_DISABLE:
diff --git a/drivers/pinctrl/pinctrl-lpc18xx.c b/drivers/pinctrl/pinctrl-lpc18xx.c
index e053f1fa5512..d090f37ca4a1 100644
--- a/drivers/pinctrl/pinctrl-lpc18xx.c
+++ b/drivers/pinctrl/pinctrl-lpc18xx.c
@@ -904,7 +904,7 @@ static int lpc18xx_pconf_get(struct pinctrl_dev *pctldev, unsigned pin,
904 904
905static int lpc18xx_pconf_set_usb1(struct pinctrl_dev *pctldev, 905static int lpc18xx_pconf_set_usb1(struct pinctrl_dev *pctldev,
906 enum pin_config_param param, 906 enum pin_config_param param,
907 u16 param_val, u32 *reg) 907 u32 param_val, u32 *reg)
908{ 908{
909 switch (param) { 909 switch (param) {
910 case PIN_CONFIG_LOW_POWER_MODE: 910 case PIN_CONFIG_LOW_POWER_MODE:
@@ -932,7 +932,7 @@ static int lpc18xx_pconf_set_usb1(struct pinctrl_dev *pctldev,
932 932
933static int lpc18xx_pconf_set_i2c0(struct pinctrl_dev *pctldev, 933static int lpc18xx_pconf_set_i2c0(struct pinctrl_dev *pctldev,
934 enum pin_config_param param, 934 enum pin_config_param param,
935 u16 param_val, u32 *reg, 935 u32 param_val, u32 *reg,
936 unsigned pin) 936 unsigned pin)
937{ 937{
938 u8 shift; 938 u8 shift;
@@ -982,7 +982,7 @@ static int lpc18xx_pconf_set_i2c0(struct pinctrl_dev *pctldev,
982} 982}
983 983
984static int lpc18xx_pconf_set_gpio_pin_int(struct pinctrl_dev *pctldev, 984static int lpc18xx_pconf_set_gpio_pin_int(struct pinctrl_dev *pctldev,
985 u16 param_val, unsigned pin) 985 u32 param_val, unsigned pin)
986{ 986{
987 struct lpc18xx_scu_data *scu = pinctrl_dev_get_drvdata(pctldev); 987 struct lpc18xx_scu_data *scu = pinctrl_dev_get_drvdata(pctldev);
988 u32 val, reg_val, reg_offset = LPC18XX_SCU_PINTSEL0; 988 u32 val, reg_val, reg_offset = LPC18XX_SCU_PINTSEL0;
@@ -1008,7 +1008,7 @@ static int lpc18xx_pconf_set_gpio_pin_int(struct pinctrl_dev *pctldev,
1008} 1008}
1009 1009
1010static int lpc18xx_pconf_set_pin(struct pinctrl_dev *pctldev, unsigned param, 1010static int lpc18xx_pconf_set_pin(struct pinctrl_dev *pctldev, unsigned param,
1011 u16 param_val, u32 *reg, unsigned pin, 1011 u32 param_val, u32 *reg, unsigned pin,
1012 struct lpc18xx_pin_caps *pin_cap) 1012 struct lpc18xx_pin_caps *pin_cap)
1013{ 1013{
1014 switch (param) { 1014 switch (param) {
@@ -1088,7 +1088,7 @@ static int lpc18xx_pconf_set(struct pinctrl_dev *pctldev, unsigned pin,
1088 struct lpc18xx_scu_data *scu = pinctrl_dev_get_drvdata(pctldev); 1088 struct lpc18xx_scu_data *scu = pinctrl_dev_get_drvdata(pctldev);
1089 struct lpc18xx_pin_caps *pin_cap; 1089 struct lpc18xx_pin_caps *pin_cap;
1090 enum pin_config_param param; 1090 enum pin_config_param param;
1091 u16 param_val; 1091 u32 param_val;
1092 u32 reg; 1092 u32 reg;
1093 int ret; 1093 int ret;
1094 int i; 1094 int i;
diff --git a/drivers/pinctrl/pinctrl-max77620.c b/drivers/pinctrl/pinctrl-max77620.c
index d9ff53e8f715..b8d2180a2bea 100644
--- a/drivers/pinctrl/pinctrl-max77620.c
+++ b/drivers/pinctrl/pinctrl-max77620.c
@@ -402,7 +402,7 @@ static int max77620_pinconf_set(struct pinctrl_dev *pctldev,
402 struct device *dev = mpci->dev; 402 struct device *dev = mpci->dev;
403 struct max77620_fps_config *fps_config; 403 struct max77620_fps_config *fps_config;
404 int param; 404 int param;
405 u16 param_val; 405 u32 param_val;
406 unsigned int val; 406 unsigned int val;
407 unsigned int pu_val; 407 unsigned int pu_val;
408 unsigned int pd_val; 408 unsigned int pd_val;
diff --git a/drivers/pinctrl/pinctrl-palmas.c b/drivers/pinctrl/pinctrl-palmas.c
index a30146da7ffd..4d6a5015b927 100644
--- a/drivers/pinctrl/pinctrl-palmas.c
+++ b/drivers/pinctrl/pinctrl-palmas.c
@@ -860,7 +860,7 @@ static int palmas_pinconf_set(struct pinctrl_dev *pctldev,
860{ 860{
861 struct palmas_pctrl_chip_info *pci = pinctrl_dev_get_drvdata(pctldev); 861 struct palmas_pctrl_chip_info *pci = pinctrl_dev_get_drvdata(pctldev);
862 enum pin_config_param param; 862 enum pin_config_param param;
863 u16 param_val; 863 u32 param_val;
864 const struct palmas_pingroup *g; 864 const struct palmas_pingroup *g;
865 const struct palmas_pin_info *opt; 865 const struct palmas_pin_info *opt;
866 int ret; 866 int ret;
diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
index 08765f58253c..7813599e43fa 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -1441,7 +1441,7 @@ static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
1441 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); 1441 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1442 struct rockchip_pin_bank *bank = pin_to_bank(info, pin); 1442 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
1443 enum pin_config_param param; 1443 enum pin_config_param param;
1444 u16 arg; 1444 u32 arg;
1445 int i; 1445 int i;
1446 int rc; 1446 int rc;
1447 1447
diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index a5a0392ab817..f71f2e813ea6 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -622,7 +622,7 @@ static int pcs_pinconf_set(struct pinctrl_dev *pctldev,
622 struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev); 622 struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev);
623 struct pcs_function *func; 623 struct pcs_function *func;
624 unsigned offset = 0, shift = 0, i, data, ret; 624 unsigned offset = 0, shift = 0, i, data, ret;
625 u16 arg; 625 u32 arg;
626 int j; 626 int j;
627 627
628 ret = pcs_get_function(pctldev, pin, &func); 628 ret = pcs_get_function(pctldev, pin, &func);
diff --git a/drivers/pinctrl/pinctrl-sx150x.c b/drivers/pinctrl/pinctrl-sx150x.c
index 29fb7403d24e..7450f5118445 100644
--- a/drivers/pinctrl/pinctrl-sx150x.c
+++ b/drivers/pinctrl/pinctrl-sx150x.c
@@ -424,41 +424,6 @@ static int sx150x_gpio_get(struct gpio_chip *chip, unsigned int offset)
424 return !!(value & BIT(offset)); 424 return !!(value & BIT(offset));
425} 425}
426 426
427static int sx150x_gpio_set_single_ended(struct gpio_chip *chip,
428 unsigned int offset,
429 enum single_ended_mode mode)
430{
431 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
432 int ret;
433
434 switch (mode) {
435 case LINE_MODE_PUSH_PULL:
436 if (pctl->data->model != SX150X_789 ||
437 sx150x_pin_is_oscio(pctl, offset))
438 return 0;
439
440 ret = regmap_write_bits(pctl->regmap,
441 pctl->data->pri.x789.reg_drain,
442 BIT(offset), 0);
443 break;
444
445 case LINE_MODE_OPEN_DRAIN:
446 if (pctl->data->model != SX150X_789 ||
447 sx150x_pin_is_oscio(pctl, offset))
448 return -ENOTSUPP;
449
450 ret = regmap_write_bits(pctl->regmap,
451 pctl->data->pri.x789.reg_drain,
452 BIT(offset), BIT(offset));
453 break;
454 default:
455 ret = -ENOTSUPP;
456 break;
457 }
458
459 return ret;
460}
461
462static int __sx150x_gpio_set(struct sx150x_pinctrl *pctl, unsigned int offset, 427static int __sx150x_gpio_set(struct sx150x_pinctrl *pctl, unsigned int offset,
463 int value) 428 int value)
464{ 429{
@@ -811,16 +776,26 @@ static int sx150x_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
811 break; 776 break;
812 777
813 case PIN_CONFIG_DRIVE_OPEN_DRAIN: 778 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
814 ret = sx150x_gpio_set_single_ended(&pctl->gpio, 779 if (pctl->data->model != SX150X_789 ||
815 pin, LINE_MODE_OPEN_DRAIN); 780 sx150x_pin_is_oscio(pctl, pin))
781 return -ENOTSUPP;
782
783 ret = regmap_write_bits(pctl->regmap,
784 pctl->data->pri.x789.reg_drain,
785 BIT(pin), BIT(pin));
816 if (ret < 0) 786 if (ret < 0)
817 return ret; 787 return ret;
818 788
819 break; 789 break;
820 790
821 case PIN_CONFIG_DRIVE_PUSH_PULL: 791 case PIN_CONFIG_DRIVE_PUSH_PULL:
822 ret = sx150x_gpio_set_single_ended(&pctl->gpio, 792 if (pctl->data->model != SX150X_789 ||
823 pin, LINE_MODE_PUSH_PULL); 793 sx150x_pin_is_oscio(pctl, pin))
794 return 0;
795
796 ret = regmap_write_bits(pctl->regmap,
797 pctl->data->pri.x789.reg_drain,
798 BIT(pin), 0);
824 if (ret < 0) 799 if (ret < 0)
825 return ret; 800 return ret;
826 801
@@ -1178,7 +1153,7 @@ static int sx150x_probe(struct i2c_client *client,
1178 pctl->gpio.direction_output = sx150x_gpio_direction_output; 1153 pctl->gpio.direction_output = sx150x_gpio_direction_output;
1179 pctl->gpio.get = sx150x_gpio_get; 1154 pctl->gpio.get = sx150x_gpio_get;
1180 pctl->gpio.set = sx150x_gpio_set; 1155 pctl->gpio.set = sx150x_gpio_set;
1181 pctl->gpio.set_single_ended = sx150x_gpio_set_single_ended; 1156 pctl->gpio.set_config = gpiochip_generic_config;
1182 pctl->gpio.parent = dev; 1157 pctl->gpio.parent = dev;
1183#ifdef CONFIG_OF_GPIO 1158#ifdef CONFIG_OF_GPIO
1184 pctl->gpio.of_node = dev->of_node; 1159 pctl->gpio.of_node = dev->of_node;
diff --git a/drivers/pinctrl/sirf/pinctrl-atlas7.c b/drivers/pinctrl/sirf/pinctrl-atlas7.c
index 7f3041697813..82b8a429743d 100644
--- a/drivers/pinctrl/sirf/pinctrl-atlas7.c
+++ b/drivers/pinctrl/sirf/pinctrl-atlas7.c
@@ -5322,7 +5322,8 @@ static int atlas7_pin_config_set(struct pinctrl_dev *pctldev,
5322 unsigned pin, unsigned long *configs, 5322 unsigned pin, unsigned long *configs,
5323 unsigned num_configs) 5323 unsigned num_configs)
5324{ 5324{
5325 u16 param, arg; 5325 u16 param;
5326 u32 arg;
5326 int idx, err; 5327 int idx, err;
5327 5328
5328 for (idx = 0; idx < num_configs; idx++) { 5329 for (idx = 0; idx < num_configs; idx++) {
diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index 0eb51e33cb1b..28bfa5f413e4 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -540,7 +540,7 @@ static int sunxi_pconf_group_set(struct pinctrl_dev *pctldev,
540 enum pin_config_param param; 540 enum pin_config_param param;
541 unsigned long flags; 541 unsigned long flags;
542 u32 offset, shift, mask, reg; 542 u32 offset, shift, mask, reg;
543 u16 arg, val; 543 u32 arg, val;
544 int ret; 544 int ret;
545 545
546 param = pinconf_to_config_param(configs[i]); 546 param = pinconf_to_config_param(configs[i]);
diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c b/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c
index 9b2ee717bccc..546f23c9040c 100644
--- a/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c
+++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c
@@ -297,7 +297,7 @@ static int uniphier_conf_pin_config_get(struct pinctrl_dev *pctldev,
297 297
298static int uniphier_conf_pin_bias_set(struct pinctrl_dev *pctldev, 298static int uniphier_conf_pin_bias_set(struct pinctrl_dev *pctldev,
299 const struct pin_desc *desc, 299 const struct pin_desc *desc,
300 enum pin_config_param param, u16 arg) 300 enum pin_config_param param, u32 arg)
301{ 301{
302 struct uniphier_pinctrl_priv *priv = pinctrl_dev_get_drvdata(pctldev); 302 struct uniphier_pinctrl_priv *priv = pinctrl_dev_get_drvdata(pctldev);
303 enum uniphier_pin_pull_dir pull_dir = 303 enum uniphier_pin_pull_dir pull_dir =
@@ -468,7 +468,7 @@ static int uniphier_conf_pin_config_set(struct pinctrl_dev *pctldev,
468 for (i = 0; i < num_configs; i++) { 468 for (i = 0; i < num_configs; i++) {
469 enum pin_config_param param = 469 enum pin_config_param param =
470 pinconf_to_config_param(configs[i]); 470 pinconf_to_config_param(configs[i]);
471 u16 arg = pinconf_to_config_argument(configs[i]); 471 u32 arg = pinconf_to_config_argument(configs[i]);
472 472
473 switch (param) { 473 switch (param) {
474 case PIN_CONFIG_BIAS_DISABLE: 474 case PIN_CONFIG_BIAS_DISABLE:
diff --git a/drivers/pinctrl/vt8500/pinctrl-wmt.c b/drivers/pinctrl/vt8500/pinctrl-wmt.c
index 270ca2a47a8c..c207e60b734f 100644
--- a/drivers/pinctrl/vt8500/pinctrl-wmt.c
+++ b/drivers/pinctrl/vt8500/pinctrl-wmt.c
@@ -428,7 +428,7 @@ static int wmt_pinconf_set(struct pinctrl_dev *pctldev, unsigned pin,
428{ 428{
429 struct wmt_pinctrl_data *data = pinctrl_dev_get_drvdata(pctldev); 429 struct wmt_pinctrl_data *data = pinctrl_dev_get_drvdata(pctldev);
430 enum pin_config_param param; 430 enum pin_config_param param;
431 u16 arg; 431 u32 arg;
432 u32 bank = WMT_BANK_FROM_PIN(pin); 432 u32 bank = WMT_BANK_FROM_PIN(pin);
433 u32 bit = WMT_BIT_FROM_PIN(pin); 433 u32 bit = WMT_BIT_FROM_PIN(pin);
434 u32 reg_pull_en = data->banks[bank].reg_pull_en; 434 u32 reg_pull_en = data->banks[bank].reg_pull_en;
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 51e52446eacb..73594f38c453 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -610,7 +610,7 @@ static int rtc_pinconf_set(struct pinctrl_dev *pctldev,
610 struct omap_rtc *rtc = pinctrl_dev_get_drvdata(pctldev); 610 struct omap_rtc *rtc = pinctrl_dev_get_drvdata(pctldev);
611 u32 val; 611 u32 val;
612 unsigned int param; 612 unsigned int param;
613 u16 param_val; 613 u32 param_val;
614 int i; 614 int i;
615 615
616 rtc->type->unlock(rtc); 616 rtc->type->unlock(rtc);
diff --git a/drivers/staging/greybus/gpio.c b/drivers/staging/greybus/gpio.c
index 250caa00de5e..51384bdde450 100644
--- a/drivers/staging/greybus/gpio.c
+++ b/drivers/staging/greybus/gpio.c
@@ -474,17 +474,20 @@ static void gb_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
474 gb_gpio_set_value_operation(ggc, (u8)offset, !!value); 474 gb_gpio_set_value_operation(ggc, (u8)offset, !!value);
475} 475}
476 476
477static int gb_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, 477static int gb_gpio_set_config(struct gpio_chip *chip, unsigned offset,
478 unsigned debounce) 478 unsigned long config)
479{ 479{
480 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip); 480 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip);
481 u16 usec; 481 u32 debounce;
482 482
483 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
484 return -ENOTSUPP;
485
486 debounce = pinconf_to_config_argument(config);
483 if (debounce > U16_MAX) 487 if (debounce > U16_MAX)
484 return -EINVAL; 488 return -EINVAL;
485 usec = (u16)debounce;
486 489
487 return gb_gpio_set_debounce_operation(ggc, (u8)offset, usec); 490 return gb_gpio_set_debounce_operation(ggc, (u8)offset, (u16)debounce);
488} 491}
489 492
490static int gb_gpio_controller_setup(struct gb_gpio_controller *ggc) 493static int gb_gpio_controller_setup(struct gb_gpio_controller *ggc)
@@ -689,7 +692,7 @@ static int gb_gpio_probe(struct gbphy_device *gbphy_dev,
689 gpio->direction_output = gb_gpio_direction_output; 692 gpio->direction_output = gb_gpio_direction_output;
690 gpio->get = gb_gpio_get; 693 gpio->get = gb_gpio_get;
691 gpio->set = gb_gpio_set; 694 gpio->set = gb_gpio_set;
692 gpio->set_debounce = gb_gpio_set_debounce; 695 gpio->set_config = gb_gpio_set_config;
693 gpio->to_irq = gb_gpio_to_irq; 696 gpio->to_irq = gb_gpio_to_irq;
694 gpio->base = -1; /* Allocate base dynamically */ 697 gpio->base = -1; /* Allocate base dynamically */
695 gpio->ngpio = ggc->line_max + 1; 698 gpio->ngpio = ggc->line_max + 1;
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index fff718352e0c..5d61d0871f2e 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -1329,17 +1329,20 @@ static int cp210x_gpio_direction_output(struct gpio_chip *gc, unsigned int gpio,
1329 return 0; 1329 return 0;
1330} 1330}
1331 1331
1332static int cp210x_gpio_set_single_ended(struct gpio_chip *gc, unsigned int gpio, 1332static int cp210x_gpio_set_config(struct gpio_chip *gc, unsigned int gpio,
1333 enum single_ended_mode mode) 1333 unsigned long config)
1334{ 1334{
1335 struct usb_serial *serial = gpiochip_get_data(gc); 1335 struct usb_serial *serial = gpiochip_get_data(gc);
1336 struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1336 struct cp210x_serial_private *priv = usb_get_serial_data(serial);
1337 enum pin_config_param param = pinconf_to_config_param(config);
1337 1338
1338 /* Succeed only if in correct mode (this can't be set at runtime) */ 1339 /* Succeed only if in correct mode (this can't be set at runtime) */
1339 if ((mode == LINE_MODE_PUSH_PULL) && (priv->gpio_mode & BIT(gpio))) 1340 if ((param == PIN_CONFIG_DRIVE_PUSH_PULL) &&
1341 (priv->gpio_mode & BIT(gpio)))
1340 return 0; 1342 return 0;
1341 1343
1342 if ((mode == LINE_MODE_OPEN_DRAIN) && !(priv->gpio_mode & BIT(gpio))) 1344 if ((param == PIN_CONFIG_DRIVE_OPEN_DRAIN) &&
1345 !(priv->gpio_mode & BIT(gpio)))
1343 return 0; 1346 return 0;
1344 1347
1345 return -ENOTSUPP; 1348 return -ENOTSUPP;
@@ -1402,7 +1405,7 @@ static int cp2105_shared_gpio_init(struct usb_serial *serial)
1402 priv->gc.direction_output = cp210x_gpio_direction_output; 1405 priv->gc.direction_output = cp210x_gpio_direction_output;
1403 priv->gc.get = cp210x_gpio_get; 1406 priv->gc.get = cp210x_gpio_get;
1404 priv->gc.set = cp210x_gpio_set; 1407 priv->gc.set = cp210x_gpio_set;
1405 priv->gc.set_single_ended = cp210x_gpio_set_single_ended; 1408 priv->gc.set_config = cp210x_gpio_set_config;
1406 priv->gc.owner = THIS_MODULE; 1409 priv->gc.owner = THIS_MODULE;
1407 priv->gc.parent = &serial->interface->dev; 1410 priv->gc.parent = &serial->interface->dev;
1408 priv->gc.base = -1; 1411 priv->gc.base = -1;
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index c2748accea71..db2022910caf 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/pinctrl/pinconf-generic.h>
11 12
12struct gpio_desc; 13struct gpio_desc;
13struct of_phandle_args; 14struct of_phandle_args;
@@ -19,18 +20,6 @@ struct module;
19#ifdef CONFIG_GPIOLIB 20#ifdef CONFIG_GPIOLIB
20 21
21/** 22/**
22 * enum single_ended_mode - mode for single ended operation
23 * @LINE_MODE_PUSH_PULL: normal mode for a GPIO line, drive actively high/low
24 * @LINE_MODE_OPEN_DRAIN: set line to be open drain
25 * @LINE_MODE_OPEN_SOURCE: set line to be open source
26 */
27enum single_ended_mode {
28 LINE_MODE_PUSH_PULL,
29 LINE_MODE_OPEN_DRAIN,
30 LINE_MODE_OPEN_SOURCE,
31};
32
33/**
34 * struct gpio_chip - abstract a GPIO controller 23 * struct gpio_chip - abstract a GPIO controller
35 * @label: a functional name for the GPIO device, such as a part 24 * @label: a functional name for the GPIO device, such as a part
36 * number or the name of the SoC IP-block implementing it. 25 * number or the name of the SoC IP-block implementing it.
@@ -48,16 +37,8 @@ enum single_ended_mode {
48 * @get: returns value for signal "offset", 0=low, 1=high, or negative error 37 * @get: returns value for signal "offset", 0=low, 1=high, or negative error
49 * @set: assigns output value for signal "offset" 38 * @set: assigns output value for signal "offset"
50 * @set_multiple: assigns output values for multiple signals defined by "mask" 39 * @set_multiple: assigns output values for multiple signals defined by "mask"
51 * @set_debounce: optional hook for setting debounce time for specified gpio in 40 * @set_config: optional hook for all kinds of settings. Uses the same
52 * interrupt triggered gpio chips 41 * packed config format as generic pinconf.
53 * @set_single_ended: optional hook for setting a line as open drain, open
54 * source, or non-single ended (restore from open drain/source to normal
55 * push-pull mode) this should be implemented if the hardware supports
56 * open drain or open source settings. The GPIOlib will otherwise try
57 * to emulate open drain/source by not actively driving lines high/low
58 * if a consumer request this. The driver may return -ENOTSUPP if e.g.
59 * it supports just open drain but not open source and is called
60 * with LINE_MODE_OPEN_SOURCE as mode argument.
61 * @to_irq: optional hook supporting non-static gpio_to_irq() mappings; 42 * @to_irq: optional hook supporting non-static gpio_to_irq() mappings;
62 * implementation may not sleep 43 * implementation may not sleep
63 * @dbg_show: optional routine to show contents in debugfs; default code 44 * @dbg_show: optional routine to show contents in debugfs; default code
@@ -150,13 +131,9 @@ struct gpio_chip {
150 void (*set_multiple)(struct gpio_chip *chip, 131 void (*set_multiple)(struct gpio_chip *chip,
151 unsigned long *mask, 132 unsigned long *mask,
152 unsigned long *bits); 133 unsigned long *bits);
153 int (*set_debounce)(struct gpio_chip *chip, 134 int (*set_config)(struct gpio_chip *chip,
154 unsigned offset, 135 unsigned offset,
155 unsigned debounce); 136 unsigned long config);
156 int (*set_single_ended)(struct gpio_chip *chip,
157 unsigned offset,
158 enum single_ended_mode mode);
159
160 int (*to_irq)(struct gpio_chip *chip, 137 int (*to_irq)(struct gpio_chip *chip,
161 unsigned offset); 138 unsigned offset);
162 139
@@ -310,6 +287,8 @@ static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip,
310 287
311int gpiochip_generic_request(struct gpio_chip *chip, unsigned offset); 288int gpiochip_generic_request(struct gpio_chip *chip, unsigned offset);
312void gpiochip_generic_free(struct gpio_chip *chip, unsigned offset); 289void gpiochip_generic_free(struct gpio_chip *chip, unsigned offset);
290int gpiochip_generic_config(struct gpio_chip *chip, unsigned offset,
291 unsigned long config);
313 292
314#ifdef CONFIG_PINCTRL 293#ifdef CONFIG_PINCTRL
315 294
diff --git a/include/linux/pinctrl/consumer.h b/include/linux/pinctrl/consumer.h
index d7e5d608faa7..a0f2aba72fa9 100644
--- a/include/linux/pinctrl/consumer.h
+++ b/include/linux/pinctrl/consumer.h
@@ -29,6 +29,7 @@ extern int pinctrl_request_gpio(unsigned gpio);
29extern void pinctrl_free_gpio(unsigned gpio); 29extern void pinctrl_free_gpio(unsigned gpio);
30extern int pinctrl_gpio_direction_input(unsigned gpio); 30extern int pinctrl_gpio_direction_input(unsigned gpio);
31extern int pinctrl_gpio_direction_output(unsigned gpio); 31extern int pinctrl_gpio_direction_output(unsigned gpio);
32extern int pinctrl_gpio_set_config(unsigned gpio, unsigned long config);
32 33
33extern struct pinctrl * __must_check pinctrl_get(struct device *dev); 34extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
34extern void pinctrl_put(struct pinctrl *p); 35extern void pinctrl_put(struct pinctrl *p);
@@ -80,6 +81,11 @@ static inline int pinctrl_gpio_direction_output(unsigned gpio)
80 return 0; 81 return 0;
81} 82}
82 83
84static inline int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
85{
86 return 0;
87}
88
83static inline struct pinctrl * __must_check pinctrl_get(struct device *dev) 89static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
84{ 90{
85 return NULL; 91 return NULL;
diff --git a/include/linux/pinctrl/pinconf-generic.h b/include/linux/pinctrl/pinconf-generic.h
index 12343caa114e..7620eb127cff 100644
--- a/include/linux/pinctrl/pinconf-generic.h
+++ b/include/linux/pinctrl/pinconf-generic.h
@@ -12,12 +12,6 @@
12#ifndef __LINUX_PINCTRL_PINCONF_GENERIC_H 12#ifndef __LINUX_PINCTRL_PINCONF_GENERIC_H
13#define __LINUX_PINCTRL_PINCONF_GENERIC_H 13#define __LINUX_PINCTRL_PINCONF_GENERIC_H
14 14
15/*
16 * You shouldn't even be able to compile with these enums etc unless you're
17 * using generic pin config. That is why this is defined out.
18 */
19#ifdef CONFIG_GENERIC_PINCONF
20
21/** 15/**
22 * enum pin_config_param - possible pin configuration parameters 16 * enum pin_config_param - possible pin configuration parameters
23 * @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it 17 * @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it
@@ -92,6 +86,8 @@
92 * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if 86 * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if
93 * you need to pass in custom configurations to the pin controller, use 87 * you need to pass in custom configurations to the pin controller, use
94 * PIN_CONFIG_END+1 as the base offset. 88 * PIN_CONFIG_END+1 as the base offset.
89 * @PIN_CONFIG_MAX: this is the maximum configuration value that can be
90 * presented using the packed format.
95 */ 91 */
96enum pin_config_param { 92enum pin_config_param {
97 PIN_CONFIG_BIAS_BUS_HOLD, 93 PIN_CONFIG_BIAS_BUS_HOLD,
@@ -112,49 +108,53 @@ enum pin_config_param {
112 PIN_CONFIG_OUTPUT, 108 PIN_CONFIG_OUTPUT,
113 PIN_CONFIG_POWER_SOURCE, 109 PIN_CONFIG_POWER_SOURCE,
114 PIN_CONFIG_SLEW_RATE, 110 PIN_CONFIG_SLEW_RATE,
115 PIN_CONFIG_END = 0x7FFF, 111 PIN_CONFIG_END = 0x7F,
116}; 112 PIN_CONFIG_MAX = 0xFF,
117
118#ifdef CONFIG_DEBUG_FS
119#define PCONFDUMP(a, b, c, d) { .param = a, .display = b, .format = c, \
120 .has_arg = d }
121
122struct pin_config_item {
123 const enum pin_config_param param;
124 const char * const display;
125 const char * const format;
126 bool has_arg;
127}; 113};
128#endif /* CONFIG_DEBUG_FS */
129 114
130/* 115/*
131 * Helpful configuration macro to be used in tables etc. 116 * Helpful configuration macro to be used in tables etc.
132 */ 117 */
133#define PIN_CONF_PACKED(p, a) ((a << 16) | ((unsigned long) p & 0xffffUL)) 118#define PIN_CONF_PACKED(p, a) ((a << 8) | ((unsigned long) p & 0xffUL))
134 119
135/* 120/*
136 * The following inlines stuffs a configuration parameter and data value 121 * The following inlines stuffs a configuration parameter and data value
137 * into and out of an unsigned long argument, as used by the generic pin config 122 * into and out of an unsigned long argument, as used by the generic pin config
138 * system. We put the parameter in the lower 16 bits and the argument in the 123 * system. We put the parameter in the lower 8 bits and the argument in the
139 * upper 16 bits. 124 * upper 24 bits.
140 */ 125 */
141 126
142static inline enum pin_config_param pinconf_to_config_param(unsigned long config) 127static inline enum pin_config_param pinconf_to_config_param(unsigned long config)
143{ 128{
144 return (enum pin_config_param) (config & 0xffffUL); 129 return (enum pin_config_param) (config & 0xffUL);
145} 130}
146 131
147static inline u16 pinconf_to_config_argument(unsigned long config) 132static inline u32 pinconf_to_config_argument(unsigned long config)
148{ 133{
149 return (enum pin_config_param) ((config >> 16) & 0xffffUL); 134 return (u32) ((config >> 8) & 0xffffffUL);
150} 135}
151 136
152static inline unsigned long pinconf_to_config_packed(enum pin_config_param param, 137static inline unsigned long pinconf_to_config_packed(enum pin_config_param param,
153 u16 argument) 138 u32 argument)
154{ 139{
155 return PIN_CONF_PACKED(param, argument); 140 return PIN_CONF_PACKED(param, argument);
156} 141}
157 142
143#ifdef CONFIG_GENERIC_PINCONF
144
145#ifdef CONFIG_DEBUG_FS
146#define PCONFDUMP(a, b, c, d) { \
147 .param = a, .display = b, .format = c, .has_arg = d \
148 }
149
150struct pin_config_item {
151 const enum pin_config_param param;
152 const char * const display;
153 const char * const format;
154 bool has_arg;
155};
156#endif /* CONFIG_DEBUG_FS */
157
158#ifdef CONFIG_OF 158#ifdef CONFIG_OF
159 159
160#include <linux/device.h> 160#include <linux/device.h>
diff --git a/include/linux/platform_data/gpio-davinci.h b/include/linux/platform_data/gpio-davinci.h
index 6ace3fd32b6a..90ae19ca828f 100644
--- a/include/linux/platform_data/gpio-davinci.h
+++ b/include/linux/platform_data/gpio-davinci.h
@@ -21,23 +21,28 @@
21 21
22#include <asm-generic/gpio.h> 22#include <asm-generic/gpio.h>
23 23
24#define MAX_REGS_BANKS 5
25
24struct davinci_gpio_platform_data { 26struct davinci_gpio_platform_data {
25 u32 ngpio; 27 u32 ngpio;
26 u32 gpio_unbanked; 28 u32 gpio_unbanked;
27}; 29};
28 30
31struct davinci_gpio_irq_data {
32 void __iomem *regs;
33 struct davinci_gpio_controller *chip;
34 int bank_num;
35};
29 36
30struct davinci_gpio_controller { 37struct davinci_gpio_controller {
31 struct gpio_chip chip; 38 struct gpio_chip chip;
32 struct irq_domain *irq_domain; 39 struct irq_domain *irq_domain;
33 /* Serialize access to GPIO registers */ 40 /* Serialize access to GPIO registers */
34 spinlock_t lock; 41 spinlock_t lock;
35 void __iomem *regs; 42 void __iomem *regs[MAX_REGS_BANKS];
36 void __iomem *set_data;
37 void __iomem *clr_data;
38 void __iomem *in_data;
39 int gpio_unbanked; 43 int gpio_unbanked;
40 unsigned gpio_irq; 44 unsigned int base_irq;
45 unsigned int base;
41}; 46};
42 47
43/* 48/*
diff --git a/tools/gpio/.gitignore b/tools/gpio/.gitignore
new file mode 100644
index 000000000000..9e9dd4b681b2
--- /dev/null
+++ b/tools/gpio/.gitignore
@@ -0,0 +1,4 @@
1gpio-event-mon
2gpio-hammer
3lsgpio
4
diff --git a/tools/gpio/gpio-hammer.c b/tools/gpio/gpio-hammer.c
index f1eab587dfea..4bcb234c0fca 100644
--- a/tools/gpio/gpio-hammer.c
+++ b/tools/gpio/gpio-hammer.c
@@ -38,7 +38,7 @@ int hammer_device(const char *device_name, unsigned int *lines, int nlines,
38 memset(&data.values, 0, sizeof(data.values)); 38 memset(&data.values, 0, sizeof(data.values));
39 ret = gpiotools_request_linehandle(device_name, lines, nlines, 39 ret = gpiotools_request_linehandle(device_name, lines, nlines,
40 GPIOHANDLE_REQUEST_OUTPUT, &data, 40 GPIOHANDLE_REQUEST_OUTPUT, &data,
41 "gpio-hammler"); 41 "gpio-hammer");
42 if (ret < 0) 42 if (ret < 0)
43 goto exit_error; 43 goto exit_error;
44 else 44 else