aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-05-11 10:54:43 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-05-11 10:54:43 -0400
commit8148c17b179d8acad190551fe0fb90d8f5193990 (patch)
treee3f64bc75a87056b219243e10d52eac7fa1fff8b
parent6fe567df04a27468b306ae5c53fa7a1cd3acc5e1 (diff)
parent0fbee1df2078fa1f61e2da14f51ceb357c79ae69 (diff)
Merge tag 'gpio-v5.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull gpio updates from Linus Walleij: "This is the bulk of the GPIO changes for the v5.2 kernel cycle. A bit later than usual because I was ironing out my own mistakes. I'm holding some stuff back for the next kernel as a result, and this should be a healthy and well tested batch. Core changes: - The gpiolib MMIO driver has been enhanced to handle two direction registers, i.e. one register to set lines as input and one register to set lines as output. It turns out some silicon engineer thinks the ability to configure a line as input and output at the same time makes sense, this can be debated but includes a lot of analog electronics reasoning, and the registers are there and need to be handled consistently. Unsurprisingly, we enforce the lines to be either inputs or outputs in such schemes. - Send in the proper argument value to .set_config() dispatched to the pin control subsystem. Nobody used it before, now someone does, so fix it to work as expected. - The ACPI gpiolib portions can now handle pin bias setting (pull up or pull down). This has been in the ACPI spec for years and we finally have it properly integrated with Linux GPIOs. It was based on an observation from Andy Schevchenko that Thomas Petazzoni's changes to the core for biasing the PCA950x GPIO expander actually happen to fit hand-in-glove with what the ACPI core needed. Such nice synergies happen sometimes. New drivers: - A new driver for the Mellanox BlueField GPIO controller. This is using 64bit MMIO registers and can configure lines as inputs and outputs at the same time and after improving the MMIO library we handle it just fine. Interesting. - A new IXP4xx proper gpiochip driver with hierarchical interrupts should be coming in from the ARM SoC tree as well. Driver enhancements: - The PCA053x driver handles the CAT9554 GPIO expander. - The PCA053x driver handles the NXP PCAL6416 GPIO expander. - Wake-up support on PCA053x GPIO lines. - OMAP now does a nice asynchronous IRQ handling on wake-ups by letting everything wake up on edges, and this makes runtime PM work as expected too. Misc: - Several cleanups such as devres fixes. - Get rid of some languager comstructs that cause problems when compiling with LLVMs clang. - Documentation review and update" * tag 'gpio-v5.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (85 commits) gpio: Update documentation docs: gpio: convert docs to ReST and rename to *.rst gpio: sch: Remove write-only core_base gpio: pxa: Make two symbols static gpiolib: acpi: Respect pin bias setting gpiolib: acpi: Add acpi_gpio_update_gpiod_lookup_flags() helper gpiolib: acpi: Set pin value, based on bias, more accurately gpiolib: acpi: Change type of dflags gpiolib: Introduce GPIO_LOOKUP_FLAGS_DEFAULT gpiolib: Make use of enum gpio_lookup_flags consistent gpiolib: Indent entry values of enum gpio_lookup_flags gpio: pca953x: add support for pca6416 dt-bindings: gpio: pca953x: document the nxp,pca6416 gpio: pca953x: add pcal6416 to the of_device_id table gpio: gpio-omap: Remove conditional pm_runtime handling for GPIO interrupts gpio: gpio-omap: configure edge detection for level IRQs for idle wakeup tracing: stop making gpio tracing configurable gpio: pca953x: Configure wake-up path when wake-up is enabled gpio: of: Optimize quirk checks gpio: mmio: Drop bgpio_dir_inverted ...
-rw-r--r--Documentation/devicetree/bindings/gpio/gpio-pca953x.txt2
-rw-r--r--Documentation/driver-api/gpio/driver.rst361
-rw-r--r--Documentation/gpio/index.rst17
-rw-r--r--Documentation/gpio/sysfs.rst (renamed from Documentation/gpio/sysfs.txt)39
-rw-r--r--arch/arm/configs/aspeed_g4_defconfig1
-rw-r--r--arch/arm/configs/aspeed_g5_defconfig1
-rw-r--r--drivers/gpio/Kconfig83
-rw-r--r--drivers/gpio/Makefile1
-rw-r--r--drivers/gpio/gpio-74x164.c22
-rw-r--r--drivers/gpio/gpio-74xx-mmio.c4
-rw-r--r--drivers/gpio/gpio-amdpt.c8
-rw-r--r--drivers/gpio/gpio-aspeed.c4
-rw-r--r--drivers/gpio/gpio-bcm-kona.c4
-rw-r--r--drivers/gpio/gpio-cadence.c4
-rw-r--r--drivers/gpio/gpio-clps711x.c7
-rw-r--r--drivers/gpio/gpio-dwapb.c4
-rw-r--r--drivers/gpio/gpio-ftgpio010.c4
-rw-r--r--drivers/gpio/gpio-hlwd.c4
-rw-r--r--drivers/gpio/gpio-iop.c4
-rw-r--r--drivers/gpio/gpio-janz-ttl.c4
-rw-r--r--drivers/gpio/gpio-loongson1.c4
-rw-r--r--drivers/gpio/gpio-lpc18xx.c5
-rw-r--r--drivers/gpio/gpio-mb86s7x.c4
-rw-r--r--drivers/gpio/gpio-mlxbf.c152
-rw-r--r--drivers/gpio/gpio-mmio.c99
-rw-r--r--drivers/gpio/gpio-mt7621.c3
-rw-r--r--drivers/gpio/gpio-mvebu.c7
-rw-r--r--drivers/gpio/gpio-mxc.c4
-rw-r--r--drivers/gpio/gpio-octeon.c4
-rw-r--r--drivers/gpio/gpio-omap.c644
-rw-r--r--drivers/gpio/gpio-pca953x.c25
-rw-r--r--drivers/gpio/gpio-pxa.c12
-rw-r--r--drivers/gpio/gpio-rcar.c5
-rw-r--r--drivers/gpio/gpio-sch.c5
-rw-r--r--drivers/gpio/gpio-spear-spics.c4
-rw-r--r--drivers/gpio/gpio-sprd.c4
-rw-r--r--drivers/gpio/gpio-sta2x11.c5
-rw-r--r--drivers/gpio/gpio-stp-xway.c4
-rw-r--r--drivers/gpio/gpio-tb10x.c4
-rw-r--r--drivers/gpio/gpio-tegra.c4
-rw-r--r--drivers/gpio/gpio-timberdale.c4
-rw-r--r--drivers/gpio/gpio-ts4800.c4
-rw-r--r--drivers/gpio/gpio-uniphier.c4
-rw-r--r--drivers/gpio/gpio-vf610.c92
-rw-r--r--drivers/gpio/gpio-xgene-sb.c4
-rw-r--r--drivers/gpio/gpio-xlp.c7
-rw-r--r--drivers/gpio/gpio-zx.c4
-rw-r--r--drivers/gpio/gpio-zynq.c4
-rw-r--r--drivers/gpio/gpiolib-acpi.c115
-rw-r--r--drivers/gpio/gpiolib-of.c24
-rw-r--r--drivers/gpio/gpiolib.c43
-rw-r--r--drivers/gpio/gpiolib.h19
-rw-r--r--drivers/pinctrl/pinctrl-mcp23s08.c110
-rw-r--r--include/linux/gpio/driver.h15
-rw-r--r--include/linux/gpio/machine.h26
-rw-r--r--include/linux/platform_data/gpio-omap.h2
-rw-r--r--include/trace/events/gpio.h4
-rw-r--r--kernel/trace/Kconfig7
58 files changed, 1052 insertions, 1012 deletions
diff --git a/Documentation/devicetree/bindings/gpio/gpio-pca953x.txt b/Documentation/devicetree/bindings/gpio/gpio-pca953x.txt
index fb144e2b6522..dab537c20def 100644
--- a/Documentation/devicetree/bindings/gpio/gpio-pca953x.txt
+++ b/Documentation/devicetree/bindings/gpio/gpio-pca953x.txt
@@ -2,6 +2,7 @@
2 2
3Required properties: 3Required properties:
4 - compatible: Has to contain one of the following: 4 - compatible: Has to contain one of the following:
5 nxp,pca6416
5 nxp,pca9505 6 nxp,pca9505
6 nxp,pca9534 7 nxp,pca9534
7 nxp,pca9535 8 nxp,pca9535
@@ -30,6 +31,7 @@ Required properties:
30 ti,tca6424 31 ti,tca6424
31 ti,tca9539 32 ti,tca9539
32 ti,tca9554 33 ti,tca9554
34 onnn,cat9554
33 onnn,pca9654 35 onnn,pca9654
34 exar,xra1202 36 exar,xra1202
35 - gpio-controller: if used as gpio expander. 37 - gpio-controller: if used as gpio expander.
diff --git a/Documentation/driver-api/gpio/driver.rst b/Documentation/driver-api/gpio/driver.rst
index 3043167fc557..1ce7fcd0f989 100644
--- a/Documentation/driver-api/gpio/driver.rst
+++ b/Documentation/driver-api/gpio/driver.rst
@@ -1,10 +1,8 @@
1================================ 1=====================
2GPIO Descriptor Driver Interface 2GPIO Driver Interface
3================================ 3=====================
4 4
5This document serves as a guide for GPIO chip drivers writers. Note that it 5This document serves as a guide for writers of GPIO chip drivers.
6describes the new descriptor-based interface. For a description of the
7deprecated integer-based GPIO interface please refer to gpio-legacy.txt.
8 6
9Each GPIO controller driver needs to include the following header, which defines 7Each GPIO controller driver needs to include the following header, which defines
10the structures used to define a GPIO driver: 8the structures used to define a GPIO driver:
@@ -15,32 +13,49 @@ the structures used to define a GPIO driver:
15Internal Representation of GPIOs 13Internal Representation of GPIOs
16================================ 14================================
17 15
18Inside a GPIO driver, individual GPIOs are identified by their hardware number, 16A GPIO chip handles one or more GPIO lines. To be considered a GPIO chip, the
19which is a unique number between 0 and n, n being the number of GPIOs managed by 17lines must conform to the definition: General Purpose Input/Output. If the
20the chip. This number is purely internal: the hardware number of a particular 18line is not general purpose, it is not GPIO and should not be handled by a
21GPIO descriptor is never made visible outside of the driver. 19GPIO chip. The use case is the indicative: certain lines in a system may be
22 20called GPIO but serve a very particular purpose thus not meeting the criteria
23On top of this internal number, each GPIO also need to have a global number in 21of a general purpose I/O. On the other hand a LED driver line may be used as a
24the integer GPIO namespace so that it can be used with the legacy GPIO 22GPIO and should therefore still be handled by a GPIO chip driver.
23
24Inside a GPIO driver, individual GPIO lines are identified by their hardware
25number, sometime also referred to as ``offset``, which is a unique number
26between 0 and n-1, n being the number of GPIOs managed by the chip.
27
28The hardware GPIO number should be something intuitive to the hardware, for
29example if a system uses a memory-mapped set of I/O-registers where 32 GPIO
30lines are handled by one bit per line in a 32-bit register, it makes sense to
31use hardware offsets 0..31 for these, corresponding to bits 0..31 in the
32register.
33
34This number is purely internal: the hardware number of a particular GPIO
35line is never made visible outside of the driver.
36
37On top of this internal number, each GPIO line also needs to have a global
38number in the integer GPIO namespace so that it can be used with the legacy GPIO
25interface. Each chip must thus have a "base" number (which can be automatically 39interface. Each chip must thus have a "base" number (which can be automatically
26assigned), and for each GPIO the global number will be (base + hardware number). 40assigned), and for each GPIO line the global number will be (base + hardware
27Although the integer representation is considered deprecated, it still has many 41number). Although the integer representation is considered deprecated, it still
28users and thus needs to be maintained. 42has many users and thus needs to be maintained.
29 43
30So for example one platform could use numbers 32-159 for GPIOs, with a 44So for example one platform could use global numbers 32-159 for GPIOs, with a
31controller defining 128 GPIOs at a "base" of 32 ; while another platform uses 45controller defining 128 GPIOs at a "base" of 32 ; while another platform uses
32numbers 0..63 with one set of GPIO controllers, 64-79 with another type of GPIO 46global numbers 0..63 with one set of GPIO controllers, 64-79 with another type
33controller, and on one particular board 80-95 with an FPGA. The numbers need not 47of GPIO controller, and on one particular board 80-95 with an FPGA. The legacy
34be contiguous; either of those platforms could also use numbers 2000-2063 to 48numbers need not be contiguous; either of those platforms could also use numbers
35identify GPIOs in a bank of I2C GPIO expanders. 492000-2063 to identify GPIO lines in a bank of I2C GPIO expanders.
36 50
37 51
38Controller Drivers: gpio_chip 52Controller Drivers: gpio_chip
39============================= 53=============================
40 54
41In the gpiolib framework each GPIO controller is packaged as a "struct 55In the gpiolib framework each GPIO controller is packaged as a "struct
42gpio_chip" (see linux/gpio/driver.h for its complete definition) with members 56gpio_chip" (see <linux/gpio/driver.h> for its complete definition) with members
43common to each controller of that type: 57common to each controller of that type, these should be assigned by the
58driver code:
44 59
45 - methods to establish GPIO line direction 60 - methods to establish GPIO line direction
46 - methods used to access GPIO line values 61 - methods used to access GPIO line values
@@ -48,12 +63,12 @@ common to each controller of that type:
48 - method to return the IRQ number associated to a given GPIO line 63 - method to return the IRQ number associated to a given GPIO line
49 - flag saying whether calls to its methods may sleep 64 - flag saying whether calls to its methods may sleep
50 - optional line names array to identify lines 65 - optional line names array to identify lines
51 - optional debugfs dump method (showing extra state like pullup config) 66 - optional debugfs dump method (showing extra state information)
52 - optional base number (will be automatically assigned if omitted) 67 - optional base number (will be automatically assigned if omitted)
53 - optional label for diagnostics and GPIO chip mapping using platform data 68 - optional label for diagnostics and GPIO chip mapping using platform data
54 69
55The code implementing a gpio_chip should support multiple instances of the 70The code implementing a gpio_chip should support multiple instances of the
56controller, possibly using the driver model. That code will configure each 71controller, preferably using the driver model. That code will configure each
57gpio_chip and issue ``gpiochip_add[_data]()`` or ``devm_gpiochip_add_data()``. 72gpio_chip and issue ``gpiochip_add[_data]()`` or ``devm_gpiochip_add_data()``.
58Removing a GPIO controller should be rare; use ``[devm_]gpiochip_remove()`` 73Removing a GPIO controller should be rare; use ``[devm_]gpiochip_remove()``
59when it is unavoidable. 74when it is unavoidable.
@@ -62,24 +77,28 @@ Often a gpio_chip is part of an instance-specific structure with states not
62exposed by the GPIO interfaces, such as addressing, power management, and more. 77exposed by the GPIO interfaces, such as addressing, power management, and more.
63Chips such as audio codecs will have complex non-GPIO states. 78Chips such as audio codecs will have complex non-GPIO states.
64 79
65Any debugfs dump method should normally ignore signals which haven't been 80Any debugfs dump method should normally ignore lines which haven't been
66requested as GPIOs. They can use gpiochip_is_requested(), which returns either 81requested. They can use gpiochip_is_requested(), which returns either
67NULL or the label associated with that GPIO when it was requested. 82NULL or the label associated with that GPIO line when it was requested.
68 83
69RT_FULL: the GPIO driver should not use spinlock_t or any sleepable APIs 84Realtime considerations: the GPIO driver should not use spinlock_t or any
70(like PM runtime) in its gpio_chip implementation (.get/.set and direction 85sleepable APIs (like PM runtime) in its gpio_chip implementation (.get/.set
71control callbacks) if it is expected to call GPIO APIs from atomic context 86and direction control callbacks) if it is expected to call GPIO APIs from
72on -RT (inside hard IRQ handlers and similar contexts). Normally this should 87atomic context on realtime kernels (inside hard IRQ handlers and similar
73not be required. 88contexts). Normally this should not be required.
74 89
75 90
76GPIO electrical configuration 91GPIO electrical configuration
77----------------------------- 92-----------------------------
78 93
79GPIOs can be configured for several electrical modes of operation by using the 94GPIO lines can be configured for several electrical modes of operation by using
80.set_config() callback. Currently this API supports setting debouncing and 95the .set_config() callback. Currently this API supports setting:
81single-ended modes (open drain/open source). These settings are described 96
82below. 97- Debouncing
98- Single-ended modes (open drain/open source)
99- Pull up and pull down resistor enablement
100
101These settings are described below.
83 102
84The .set_config() callback uses the same enumerators and configuration 103The .set_config() callback uses the same enumerators and configuration
85semantics as the generic pin control drivers. This is not a coincidence: it is 104semantics as the generic pin control drivers. This is not a coincidence: it is
@@ -94,8 +113,8 @@ description needs to provide "GPIO ranges" mapping the GPIO line offsets to pin
94numbers on the pin controller so they can properly cross-reference each other. 113numbers on the pin controller so they can properly cross-reference each other.
95 114
96 115
97GPIOs with debounce support 116GPIO lines with debounce support
98--------------------------- 117--------------------------------
99 118
100Debouncing is a configuration set to a pin indicating that it is connected to 119Debouncing is a configuration set to a pin indicating that it is connected to
101a mechanical switch or button, or similar that may bounce. Bouncing means the 120a mechanical switch or button, or similar that may bounce. Bouncing means the
@@ -111,8 +130,8 @@ a certain number of milliseconds for debouncing, or just "on/off" if that time
111is not configurable. 130is not configurable.
112 131
113 132
114GPIOs with open drain/source support 133GPIO lines with open drain/source support
115------------------------------------ 134-----------------------------------------
116 135
117Open drain (CMOS) or open collector (TTL) means the line is not actively driven 136Open drain (CMOS) or open collector (TTL) means the line is not actively driven
118high: instead you provide the drain/collector as output, so when the transistor 137high: instead you provide the drain/collector as output, so when the transistor
@@ -132,13 +151,13 @@ This configuration is normally used as a way to achieve one of two things:
132- Level-shifting: to reach a logical level higher than that of the silicon 151- Level-shifting: to reach a logical level higher than that of the silicon
133 where the output resides. 152 where the output resides.
134 153
135- inverse wire-OR on an I/O line, for example a GPIO line, making it possible 154- Inverse wire-OR on an I/O line, for example a GPIO line, making it possible
136 for any driving stage on the line to drive it low even if any other output 155 for any driving stage on the line to drive it low even if any other output
137 to the same line is simultaneously driving it high. A special case of this 156 to the same line is simultaneously driving it high. A special case of this
138 is driving the SCL and SDA lines of an I2C bus, which is by definition a 157 is driving the SCL and SDA lines of an I2C bus, which is by definition a
139 wire-OR bus. 158 wire-OR bus.
140 159
141Both usecases require that the line be equipped with a pull-up resistor. This 160Both use cases require that the line be equipped with a pull-up resistor. This
142resistor will make the line tend to high level unless one of the transistors on 161resistor will make the line tend to high level unless one of the transistors on
143the rail actively pulls it down. 162the rail actively pulls it down.
144 163
@@ -208,27 +227,91 @@ For open source configuration the same principle is used, just that instead
208of actively driving the line low, it is set to input. 227of actively driving the line low, it is set to input.
209 228
210 229
230GPIO lines with pull up/down resistor support
231---------------------------------------------
232
233A GPIO line can support pull-up/down using the .set_config() callback. This
234means that a pull up or pull-down resistor is available on the output of the
235GPIO line, and this resistor is software controlled.
236
237In discrete designs, a pull-up or pull-down resistor is simply soldered on
238the circuit board. This is not something we deal or model in software. The
239most you will think about these lines is that they will very likely be
240configured as open drain or open source (see the section above).
241
242The .set_config() callback can only turn pull up or down on and off, and will
243no have any semantic knowledge about the resistance used. It will only say
244switch a bit in a register enabling or disabling pull-up or pull-down.
245
246If the GPIO line supports shunting in different resistance values for the
247pull-up or pull-down resistor, the GPIO chip callback .set_config() will not
248suffice. For these complex use cases, a combined GPIO chip and pin controller
249need to be implemented, as the pin config interface of a pin controller
250supports more versatile control over electrical properties and can handle
251different pull-up or pull-down resistance values.
252
253
211GPIO drivers providing IRQs 254GPIO drivers providing IRQs
212--------------------------- 255===========================
256
213It is custom that GPIO drivers (GPIO chips) are also providing interrupts, 257It is custom that GPIO drivers (GPIO chips) are also providing interrupts,
214most often cascaded off a parent interrupt controller, and in some special 258most often cascaded off a parent interrupt controller, and in some special
215cases the GPIO logic is melded with a SoC's primary interrupt controller. 259cases the GPIO logic is melded with a SoC's primary interrupt controller.
216 260
217The IRQ portions of the GPIO block are implemented using an irqchip, using 261The IRQ portions of the GPIO block are implemented using an irq_chip, using
218the header <linux/irq.h>. So basically such a driver is utilizing two sub- 262the header <linux/irq.h>. So basically such a driver is utilizing two sub-
219systems simultaneously: gpio and irq. 263systems simultaneously: gpio and irq.
220 264
221RT_FULL: a realtime compliant GPIO driver should not use spinlock_t or any 265It is legal for any IRQ consumer to request an IRQ from any irqchip even if it
222sleepable APIs (like PM runtime) as part of its irq_chip implementation. 266is a combined GPIO+IRQ driver. The basic premise is that gpio_chip and
267irq_chip are orthogonal, and offering their services independent of each
268other.
223 269
224* spinlock_t should be replaced with raw_spinlock_t [1]. 270gpiod_to_irq() is just a convenience function to figure out the IRQ for a
225* If sleepable APIs have to be used, these can be done from the .irq_bus_lock() 271certain GPIO line and should not be relied upon to have been called before
272the IRQ is used.
273
274Always prepare the hardware and make it ready for action in respective
275callbacks from the GPIO and irq_chip APIs. Do not rely on gpiod_to_irq() having
276been called first.
277
278We can divide GPIO irqchips in two broad categories:
279
280- CASCADED INTERRUPT CHIPS: this means that the GPIO chip has one common
281 interrupt output line, which is triggered by any enabled GPIO line on that
282 chip. The interrupt output line will then be routed to an parent interrupt
283 controller one level up, in the most simple case the systems primary
284 interrupt controller. This is modeled by an irqchip that will inspect bits
285 inside the GPIO controller to figure out which line fired it. The irqchip
286 part of the driver needs to inspect registers to figure this out and it
287 will likely also need to acknowledge that it is handling the interrupt
288 by clearing some bit (sometime implicitly, by just reading a status
289 register) and it will often need to set up the configuration such as
290 edge sensitivity (rising or falling edge, or high/low level interrupt for
291 example).
292
293- HIERARCHICAL INTERRUPT CHIPS: this means that each GPIO line has a dedicated
294 irq line to a parent interrupt controller one level up. There is no need
295 to inquire the GPIO hardware to figure out which line has figured, but it
296 may still be necessary to acknowledge the interrupt and set up the
297 configuration such as edge sensitivity.
298
299Realtime considerations: a realtime compliant GPIO driver should not use
300spinlock_t or any sleepable APIs (like PM runtime) as part of its irqchip
301implementation.
302
303- spinlock_t should be replaced with raw_spinlock_t [1].
304- If sleepable APIs have to be used, these can be done from the .irq_bus_lock()
226 and .irq_bus_unlock() callbacks, as these are the only slowpath callbacks 305 and .irq_bus_unlock() callbacks, as these are the only slowpath callbacks
227 on an irqchip. Create the callbacks if needed [2]. 306 on an irqchip. Create the callbacks if needed [2].
228 307
229GPIO irqchips usually fall in one of two categories:
230 308
231* CHAINED GPIO irqchips: these are usually the type that is embedded on 309Cascaded GPIO irqchips
310----------------------
311
312Cascaded GPIO irqchips usually fall in one of three categories:
313
314- CHAINED CASCADED GPIO IRQCHIPS: these are usually the type that is embedded on
232 an SoC. This means that there is a fast IRQ flow handler for the GPIOs that 315 an SoC. This means that there is a fast IRQ flow handler for the GPIOs that
233 gets called in a chain from the parent IRQ handler, most typically the 316 gets called in a chain from the parent IRQ handler, most typically the
234 system interrupt controller. This means that the GPIO irqchip handler will 317 system interrupt controller. This means that the GPIO irqchip handler will
@@ -245,16 +328,19 @@ GPIO irqchips usually fall in one of two categories:
245 struct gpio_chip, as everything happens directly in the callbacks: no 328 struct gpio_chip, as everything happens directly in the callbacks: no
246 slow bus traffic like I2C can be used. 329 slow bus traffic like I2C can be used.
247 330
248 RT_FULL: Note, chained IRQ handlers will not be forced threaded on -RT. 331 Realtime considerations: Note that chained IRQ handlers will not be forced
249 As result, spinlock_t or any sleepable APIs (like PM runtime) can't be used 332 threaded on -RT. As a result, spinlock_t or any sleepable APIs (like PM
250 in chained IRQ handler. 333 runtime) can't be used in a chained IRQ handler.
251 If required (and if it can't be converted to the nested threaded GPIO irqchip) 334
252 a chained IRQ handler can be converted to generic irq handler and this way 335 If required (and if it can't be converted to the nested threaded GPIO irqchip,
253 it will be a threaded IRQ handler on -RT and a hard IRQ handler on non-RT 336 see below) a chained IRQ handler can be converted to generic irq handler and
254 (for example, see [3]). 337 this way it will become a threaded IRQ handler on -RT and a hard IRQ handler
255 Know W/A: The generic_handle_irq() is expected to be called with IRQ disabled, 338 on non-RT (for example, see [3]).
339
340 The generic_handle_irq() is expected to be called with IRQ disabled,
256 so the IRQ core will complain if it is called from an IRQ handler which is 341 so the IRQ core will complain if it is called from an IRQ handler which is
257 forced to a thread. The "fake?" raw lock can be used to W/A this problem:: 342 forced to a thread. The "fake?" raw lock can be used to work around this
343 problem::
258 344
259 raw_spinlock_t wa_lock; 345 raw_spinlock_t wa_lock;
260 static irqreturn_t omap_gpio_irq_handler(int irq, void *gpiobank) 346 static irqreturn_t omap_gpio_irq_handler(int irq, void *gpiobank)
@@ -263,7 +349,7 @@ GPIO irqchips usually fall in one of two categories:
263 generic_handle_irq(irq_find_mapping(bank->chip.irq.domain, bit)); 349 generic_handle_irq(irq_find_mapping(bank->chip.irq.domain, bit));
264 raw_spin_unlock_irqrestore(&bank->wa_lock, wa_lock_flags); 350 raw_spin_unlock_irqrestore(&bank->wa_lock, wa_lock_flags);
265 351
266* GENERIC CHAINED GPIO irqchips: these are the same as "CHAINED GPIO irqchips", 352- GENERIC CHAINED GPIO IRQCHIPS: these are the same as "CHAINED GPIO irqchips",
267 but chained IRQ handlers are not used. Instead GPIO IRQs dispatching is 353 but chained IRQ handlers are not used. Instead GPIO IRQs dispatching is
268 performed by generic IRQ handler which is configured using request_irq(). 354 performed by generic IRQ handler which is configured using request_irq().
269 The GPIO irqchip will then end up calling something like this sequence in 355 The GPIO irqchip will then end up calling something like this sequence in
@@ -273,16 +359,19 @@ GPIO irqchips usually fall in one of two categories:
273 for each detected GPIO IRQ 359 for each detected GPIO IRQ
274 generic_handle_irq(...); 360 generic_handle_irq(...);
275 361
276 RT_FULL: Such kind of handlers will be forced threaded on -RT, as result IRQ 362 Realtime considerations: this kind of handlers will be forced threaded on -RT,
277 core will complain that generic_handle_irq() is called with IRQ enabled and 363 and as result the IRQ core will complain that generic_handle_irq() is called
278 the same W/A as for "CHAINED GPIO irqchips" can be applied. 364 with IRQ enabled and the same work around as for "CHAINED GPIO irqchips" can
365 be applied.
366
367- NESTED THREADED GPIO IRQCHIPS: these are off-chip GPIO expanders and any
368 other GPIO irqchip residing on the other side of a sleeping bus such as I2C
369 or SPI.
279 370
280* NESTED THREADED GPIO irqchips: these are off-chip GPIO expanders and any 371 Of course such drivers that need slow bus traffic to read out IRQ status and
281 other GPIO irqchip residing on the other side of a sleeping bus. Of course 372 similar, traffic which may in turn incur other IRQs to happen, cannot be
282 such drivers that need slow bus traffic to read out IRQ status and similar, 373 handled in a quick IRQ handler with IRQs disabled. Instead they need to spawn
283 traffic which may in turn incur other IRQs to happen, cannot be handled 374 a thread and then mask the parent IRQ line until the interrupt is handled
284 in a quick IRQ handler with IRQs disabled. Instead they need to spawn a
285 thread and then mask the parent IRQ line until the interrupt is handled
286 by the driver. The hallmark of this driver is to call something like 375 by the driver. The hallmark of this driver is to call something like
287 this in its interrupt handler:: 376 this in its interrupt handler::
288 377
@@ -294,36 +383,46 @@ GPIO irqchips usually fall in one of two categories:
294 flag on struct gpio_chip to true, indicating that this chip may sleep 383 flag on struct gpio_chip to true, indicating that this chip may sleep
295 when accessing the GPIOs. 384 when accessing the GPIOs.
296 385
386 These kinds of irqchips are inherently realtime tolerant as they are
387 already set up to handle sleeping contexts.
388
389
390Infrastructure helpers for GPIO irqchips
391----------------------------------------
392
297To help out in handling the set-up and management of GPIO irqchips and the 393To help out in handling the set-up and management of GPIO irqchips and the
298associated irqdomain and resource allocation callbacks, the gpiolib has 394associated irqdomain and resource allocation callbacks, the gpiolib has
299some helpers that can be enabled by selecting the GPIOLIB_IRQCHIP Kconfig 395some helpers that can be enabled by selecting the GPIOLIB_IRQCHIP Kconfig
300symbol: 396symbol:
301 397
302* gpiochip_irqchip_add(): adds a chained irqchip to a gpiochip. It will pass 398- gpiochip_irqchip_add(): adds a chained cascaded irqchip to a gpiochip. It
303 the struct gpio_chip* for the chip to all IRQ callbacks, so the callbacks 399 will pass the struct gpio_chip* for the chip to all IRQ callbacks, so the
304 need to embed the gpio_chip in its state container and obtain a pointer 400 callbacks need to embed the gpio_chip in its state container and obtain a
305 to the container using container_of(). 401 pointer to the container using container_of().
306 (See Documentation/driver-model/design-patterns.txt) 402 (See Documentation/driver-model/design-patterns.txt)
307 403
308* gpiochip_irqchip_add_nested(): adds a nested irqchip to a gpiochip. 404- gpiochip_irqchip_add_nested(): adds a nested cascaded irqchip to a gpiochip,
405 as discussed above regarding different types of cascaded irqchips. The
406 cascaded irq has to be handled by a threaded interrupt handler.
309 Apart from that it works exactly like the chained irqchip. 407 Apart from that it works exactly like the chained irqchip.
310 408
311* gpiochip_set_chained_irqchip(): sets up a chained irq handler for a 409- gpiochip_set_chained_irqchip(): sets up a chained cascaded irq handler for a
312 gpio_chip from a parent IRQ and passes the struct gpio_chip* as handler 410 gpio_chip from a parent IRQ and passes the struct gpio_chip* as handler
313 data. (Notice handler data, since the irqchip data is likely used by the 411 data. Notice that we pass is as the handler data, since the irqchip data is
314 parent irqchip!). 412 likely used by the parent irqchip.
315 413
316* gpiochip_set_nested_irqchip(): sets up a nested irq handler for a 414- gpiochip_set_nested_irqchip(): sets up a nested cascaded irq handler for a
317 gpio_chip from a parent IRQ. As the parent IRQ has usually been 415 gpio_chip from a parent IRQ. As the parent IRQ has usually been
318 explicitly requested by the driver, this does very little more than 416 explicitly requested by the driver, this does very little more than
319 mark all the child IRQs as having the other IRQ as parent. 417 mark all the child IRQs as having the other IRQ as parent.
320 418
321If there is a need to exclude certain GPIOs from the IRQ domain, you can 419If there is a need to exclude certain GPIO lines from the IRQ domain handled by
322set .irq.need_valid_mask of the gpiochip before gpiochip_add_data() is 420these helpers, we can set .irq.need_valid_mask of the gpiochip before
323called. This allocates an .irq.valid_mask with as many bits set as there 421[devm_]gpiochip_add_data() is called. This allocates an .irq.valid_mask with as
324are GPIOs in the chip. Drivers can exclude GPIOs by clearing bits from this 422many bits set as there are GPIO lines in the chip, each bit representing line
325mask. The mask must be filled in before gpiochip_irqchip_add() or 4230..n-1. Drivers can exclude GPIO lines by clearing bits from this mask. The mask
326gpiochip_irqchip_add_nested() is called. 424must be filled in before gpiochip_irqchip_add() or gpiochip_irqchip_add_nested()
425is called.
327 426
328To use the helpers please keep the following in mind: 427To use the helpers please keep the following in mind:
329 428
@@ -333,33 +432,24 @@ To use the helpers please keep the following in mind:
333 432
334- Nominally set all handlers to handle_bad_irq() in the setup call and pass 433- Nominally set all handlers to handle_bad_irq() in the setup call and pass
335 handle_bad_irq() as flow handler parameter in gpiochip_irqchip_add() if it is 434 handle_bad_irq() as flow handler parameter in gpiochip_irqchip_add() if it is
336 expected for GPIO driver that irqchip .set_type() callback have to be called 435 expected for GPIO driver that irqchip .set_type() callback will be called
337 before using/enabling GPIO IRQ. Then set the handler to handle_level_irq() 436 before using/enabling each GPIO IRQ. Then set the handler to
338 and/or handle_edge_irq() in the irqchip .set_type() callback depending on 437 handle_level_irq() and/or handle_edge_irq() in the irqchip .set_type()
339 what your controller supports. 438 callback depending on what your controller supports and what is requested
439 by the consumer.
340 440
341It is legal for any IRQ consumer to request an IRQ from any irqchip no matter
342if that is a combined GPIO+IRQ driver. The basic premise is that gpio_chip and
343irq_chip are orthogonal, and offering their services independent of each
344other.
345
346gpiod_to_irq() is just a convenience function to figure out the IRQ for a
347certain GPIO line and should not be relied upon to have been called before
348the IRQ is used.
349 441
350So always prepare the hardware and make it ready for action in respective 442Locking IRQ usage
351callbacks from the GPIO and irqchip APIs. Do not rely on gpiod_to_irq() having 443-----------------
352been called first.
353 444
354This orthogonality leads to ambiguities that we need to solve: if there is 445Since GPIO and irq_chip are orthogonal, we can get conflicts between different
355competition inside the subsystem which side is using the resource (a certain 446use cases. For example a GPIO line used for IRQs should be an input line,
356GPIO line and register for example) it needs to deny certain operations and 447it does not make sense to fire interrupts on an output GPIO.
357keep track of usage inside of the gpiolib subsystem. This is why the API
358below exists.
359 448
449If there is competition inside the subsystem which side is using the
450resource (a certain GPIO line and register for example) it needs to deny
451certain operations and keep track of usage inside of the gpiolib subsystem.
360 452
361Locking IRQ usage
362-----------------
363Input GPIOs can be used as IRQ signals. When this happens, a driver is requested 453Input GPIOs can be used as IRQ signals. When this happens, a driver is requested
364to mark the GPIO as being used as an IRQ:: 454to mark the GPIO as being used as an IRQ::
365 455
@@ -380,9 +470,15 @@ assigned.
380 470
381Disabling and enabling IRQs 471Disabling and enabling IRQs
382--------------------------- 472---------------------------
473
474In some (fringe) use cases, a driver may be using a GPIO line as input for IRQs,
475but occasionally switch that line over to drive output and then back to being
476an input with interrupts again. This happens on things like CEC (Consumer
477Electronics Control).
478
383When a GPIO is used as an IRQ signal, then gpiolib also needs to know if 479When a GPIO is used as an IRQ signal, then gpiolib also needs to know if
384the IRQ is enabled or disabled. In order to inform gpiolib about this, 480the IRQ is enabled or disabled. In order to inform gpiolib about this,
385a driver should call:: 481the irqchip driver should call::
386 482
387 void gpiochip_disable_irq(struct gpio_chip *chip, unsigned int offset) 483 void gpiochip_disable_irq(struct gpio_chip *chip, unsigned int offset)
388 484
@@ -398,40 +494,45 @@ irqchip.
398When using the gpiolib irqchip helpers, these callbacks are automatically 494When using the gpiolib irqchip helpers, these callbacks are automatically
399assigned. 495assigned.
400 496
497
401Real-Time compliance for GPIO IRQ chips 498Real-Time compliance for GPIO IRQ chips
402--------------------------------------- 499---------------------------------------
403 500
404Any provider of irqchips needs to be carefully tailored to support Real Time 501Any provider of irqchips needs to be carefully tailored to support Real-Time
405preemption. It is desirable that all irqchips in the GPIO subsystem keep this 502preemption. It is desirable that all irqchips in the GPIO subsystem keep this
406in mind and do the proper testing to assure they are real time-enabled. 503in mind and do the proper testing to assure they are real time-enabled.
407So, pay attention on above " RT_FULL:" notes, please.
408The following is a checklist to follow when preparing a driver for real
409time-compliance:
410 504
411- ensure spinlock_t is not used as part irq_chip implementation; 505So, pay attention on above realtime considerations in the documentation.
412- ensure that sleepable APIs are not used as part irq_chip implementation. 506
507The following is a checklist to follow when preparing a driver for real-time
508compliance:
509
510- ensure spinlock_t is not used as part irq_chip implementation
511- ensure that sleepable APIs are not used as part irq_chip implementation
413 If sleepable APIs have to be used, these can be done from the .irq_bus_lock() 512 If sleepable APIs have to be used, these can be done from the .irq_bus_lock()
414 and .irq_bus_unlock() callbacks; 513 and .irq_bus_unlock() callbacks
415- Chained GPIO irqchips: ensure spinlock_t or any sleepable APIs are not used 514- Chained GPIO irqchips: ensure spinlock_t or any sleepable APIs are not used
416 from chained IRQ handler; 515 from the chained IRQ handler
417- Generic chained GPIO irqchips: take care about generic_handle_irq() calls and 516- Generic chained GPIO irqchips: take care about generic_handle_irq() calls and
418 apply corresponding W/A; 517 apply corresponding work-around
419- Chained GPIO irqchips: get rid of chained IRQ handler and use generic irq 518- Chained GPIO irqchips: get rid of the chained IRQ handler and use generic irq
420 handler if possible :) 519 handler if possible
421- regmap_mmio: Sry, but you are in trouble :( if MMIO regmap is used as for 520- regmap_mmio: it is possible to disable internal locking in regmap by setting
422 GPIO IRQ chip implementation; 521 .disable_locking and handling the locking in the GPIO driver
423- Test your driver with the appropriate in-kernel real time test cases for both 522- Test your driver with the appropriate in-kernel real-time test cases for both
424 level and edge IRQs. 523 level and edge IRQs
524
525* [1] http://www.spinics.net/lists/linux-omap/msg120425.html
526* [2] https://lkml.org/lkml/2015/9/25/494
527* [3] https://lkml.org/lkml/2015/9/25/495
425 528
426 529
427Requesting self-owned GPIO pins 530Requesting self-owned GPIO pins
428------------------------------- 531===============================
429 532
430Sometimes it is useful to allow a GPIO chip driver to request its own GPIO 533Sometimes it is useful to allow a GPIO chip driver to request its own GPIO
431descriptors through the gpiolib API. Using gpio_request() for this purpose 534descriptors through the gpiolib API. A GPIO driver can use the following
432does not help since it pins the module to the kernel forever (it calls 535functions to request and free descriptors::
433try_module_get()). A GPIO driver can use the following functions instead
434to request and free descriptors without being pinned to the kernel forever::
435 536
436 struct gpio_desc *gpiochip_request_own_desc(struct gpio_desc *desc, 537 struct gpio_desc *gpiochip_request_own_desc(struct gpio_desc *desc,
437 u16 hwnum, 538 u16 hwnum,
@@ -446,7 +547,3 @@ gpiochip_free_own_desc().
446These functions must be used with care since they do not affect module use 547These functions must be used with care since they do not affect module use
447count. Do not use the functions to request gpio descriptors not owned by the 548count. Do not use the functions to request gpio descriptors not owned by the
448calling driver. 549calling driver.
449
450* [1] http://www.spinics.net/lists/linux-omap/msg120425.html
451* [2] https://lkml.org/lkml/2015/9/25/494
452* [3] https://lkml.org/lkml/2015/9/25/495
diff --git a/Documentation/gpio/index.rst b/Documentation/gpio/index.rst
new file mode 100644
index 000000000000..09a4a553f434
--- /dev/null
+++ b/Documentation/gpio/index.rst
@@ -0,0 +1,17 @@
1:orphan:
2
3====
4gpio
5====
6
7.. toctree::
8 :maxdepth: 1
9
10 sysfs
11
12.. only:: subproject and html
13
14 Indices
15 =======
16
17 * :ref:`genindex`
diff --git a/Documentation/gpio/sysfs.txt b/Documentation/gpio/sysfs.rst
index 58eeab81f349..ec09ffd983e7 100644
--- a/Documentation/gpio/sysfs.txt
+++ b/Documentation/gpio/sysfs.rst
@@ -1,10 +1,12 @@
1GPIO Sysfs Interface for Userspace 1GPIO Sysfs Interface for Userspace
2================================== 2==================================
3 3
4THIS ABI IS DEPRECATED, THE ABI DOCUMENTATION HAS BEEN MOVED TO 4.. warning::
5Documentation/ABI/obsolete/sysfs-gpio AND NEW USERSPACE CONSUMERS 5
6ARE SUPPOSED TO USE THE CHARACTER DEVICE ABI. THIS OLD SYSFS ABI WILL 6 THIS ABI IS DEPRECATED, THE ABI DOCUMENTATION HAS BEEN MOVED TO
7NOT BE DEVELOPED (NO NEW FEATURES), IT WILL JUST BE MAINTAINED. 7 Documentation/ABI/obsolete/sysfs-gpio AND NEW USERSPACE CONSUMERS
8 ARE SUPPOSED TO USE THE CHARACTER DEVICE ABI. THIS OLD SYSFS ABI WILL
9 NOT BE DEVELOPED (NO NEW FEATURES), IT WILL JUST BE MAINTAINED.
8 10
9Refer to the examples in tools/gpio/* for an introduction to the new 11Refer to the examples in tools/gpio/* for an introduction to the new
10character device ABI. Also see the userspace header in 12character device ABI. Also see the userspace header in
@@ -51,13 +53,15 @@ The control interfaces are write-only:
51 53
52 /sys/class/gpio/ 54 /sys/class/gpio/
53 55
54 "export" ... Userspace may ask the kernel to export control of 56 "export" ...
57 Userspace may ask the kernel to export control of
55 a GPIO to userspace by writing its number to this file. 58 a GPIO to userspace by writing its number to this file.
56 59
57 Example: "echo 19 > export" will create a "gpio19" node 60 Example: "echo 19 > export" will create a "gpio19" node
58 for GPIO #19, if that's not requested by kernel code. 61 for GPIO #19, if that's not requested by kernel code.
59 62
60 "unexport" ... Reverses the effect of exporting to userspace. 63 "unexport" ...
64 Reverses the effect of exporting to userspace.
61 65
62 Example: "echo 19 > unexport" will remove a "gpio19" 66 Example: "echo 19 > unexport" will remove a "gpio19"
63 node exported using the "export" file. 67 node exported using the "export" file.
@@ -67,7 +71,8 @@ and have the following read/write attributes:
67 71
68 /sys/class/gpio/gpioN/ 72 /sys/class/gpio/gpioN/
69 73
70 "direction" ... reads as either "in" or "out". This value may 74 "direction" ...
75 reads as either "in" or "out". This value may
71 normally be written. Writing as "out" defaults to 76 normally be written. Writing as "out" defaults to
72 initializing the value as low. To ensure glitch free 77 initializing the value as low. To ensure glitch free
73 operation, values "low" and "high" may be written to 78 operation, values "low" and "high" may be written to
@@ -78,7 +83,8 @@ and have the following read/write attributes:
78 it was exported by kernel code that didn't explicitly 83 it was exported by kernel code that didn't explicitly
79 allow userspace to reconfigure this GPIO's direction. 84 allow userspace to reconfigure this GPIO's direction.
80 85
81 "value" ... reads as either 0 (low) or 1 (high). If the GPIO 86 "value" ...
87 reads as either 0 (low) or 1 (high). If the GPIO
82 is configured as an output, this value may be written; 88 is configured as an output, this value may be written;
83 any nonzero value is treated as high. 89 any nonzero value is treated as high.
84 90
@@ -92,14 +98,16 @@ and have the following read/write attributes:
92 file and read the new value or close the file and re-open it 98 file and read the new value or close the file and re-open it
93 to read the value. 99 to read the value.
94 100
95 "edge" ... reads as either "none", "rising", "falling", or 101 "edge" ...
102 reads as either "none", "rising", "falling", or
96 "both". Write these strings to select the signal edge(s) 103 "both". Write these strings to select the signal edge(s)
97 that will make poll(2) on the "value" file return. 104 that will make poll(2) on the "value" file return.
98 105
99 This file exists only if the pin can be configured as an 106 This file exists only if the pin can be configured as an
100 interrupt generating input pin. 107 interrupt generating input pin.
101 108
102 "active_low" ... reads as either 0 (false) or 1 (true). Write 109 "active_low" ...
110 reads as either 0 (false) or 1 (true). Write
103 any nonzero value to invert the value attribute both 111 any nonzero value to invert the value attribute both
104 for reading and writing. Existing and subsequent 112 for reading and writing. Existing and subsequent
105 poll(2) support configuration via the edge attribute 113 poll(2) support configuration via the edge attribute
@@ -112,11 +120,14 @@ read-only attributes:
112 120
113 /sys/class/gpio/gpiochipN/ 121 /sys/class/gpio/gpiochipN/
114 122
115 "base" ... same as N, the first GPIO managed by this chip 123 "base" ...
124 same as N, the first GPIO managed by this chip
116 125
117 "label" ... provided for diagnostics (not always unique) 126 "label" ...
127 provided for diagnostics (not always unique)
118 128
119 "ngpio" ... how many GPIOs this manages (N to N + ngpio - 1) 129 "ngpio" ...
130 how many GPIOs this manages (N to N + ngpio - 1)
120 131
121Board documentation should in most cases cover what GPIOs are used for 132Board documentation should in most cases cover what GPIOs are used for
122what purposes. However, those numbers are not always stable; GPIOs on 133what purposes. However, those numbers are not always stable; GPIOs on
@@ -129,7 +140,7 @@ the correct GPIO number to use for a given signal.
129Exporting from Kernel code 140Exporting from Kernel code
130-------------------------- 141--------------------------
131Kernel code can explicitly manage exports of GPIOs which have already been 142Kernel code can explicitly manage exports of GPIOs which have already been
132requested using gpio_request(): 143requested using gpio_request()::
133 144
134 /* export the GPIO to userspace */ 145 /* export the GPIO to userspace */
135 int gpiod_export(struct gpio_desc *desc, bool direction_may_change); 146 int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
diff --git a/arch/arm/configs/aspeed_g4_defconfig b/arch/arm/configs/aspeed_g4_defconfig
index bdbade6af9c7..190d6e9d3296 100644
--- a/arch/arm/configs/aspeed_g4_defconfig
+++ b/arch/arm/configs/aspeed_g4_defconfig
@@ -247,7 +247,6 @@ CONFIG_PANIC_TIMEOUT=-1
247# CONFIG_SCHED_DEBUG is not set 247# CONFIG_SCHED_DEBUG is not set
248CONFIG_SCHED_STACK_END_CHECK=y 248CONFIG_SCHED_STACK_END_CHECK=y
249CONFIG_FUNCTION_TRACER=y 249CONFIG_FUNCTION_TRACER=y
250# CONFIG_TRACING_EVENTS_GPIO is not set
251# CONFIG_RUNTIME_TESTING_MENU is not set 250# CONFIG_RUNTIME_TESTING_MENU is not set
252CONFIG_DEBUG_WX=y 251CONFIG_DEBUG_WX=y
253CONFIG_DEBUG_USER=y 252CONFIG_DEBUG_USER=y
diff --git a/arch/arm/configs/aspeed_g5_defconfig b/arch/arm/configs/aspeed_g5_defconfig
index 4bde84eae4eb..407ffb7655a8 100644
--- a/arch/arm/configs/aspeed_g5_defconfig
+++ b/arch/arm/configs/aspeed_g5_defconfig
@@ -247,7 +247,6 @@ CONFIG_PANIC_TIMEOUT=-1
247# CONFIG_SCHED_DEBUG is not set 247# CONFIG_SCHED_DEBUG is not set
248CONFIG_SCHED_STACK_END_CHECK=y 248CONFIG_SCHED_STACK_END_CHECK=y
249CONFIG_FUNCTION_TRACER=y 249CONFIG_FUNCTION_TRACER=y
250# CONFIG_TRACING_EVENTS_GPIO is not set
251# CONFIG_RUNTIME_TESTING_MENU is not set 250# CONFIG_RUNTIME_TESTING_MENU is not set
252CONFIG_DEBUG_WX=y 251CONFIG_DEBUG_WX=y
253CONFIG_DEBUG_USER=y 252CONFIG_DEBUG_USER=y
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 0f91600c27ae..9370276fe7fe 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -26,12 +26,12 @@ config GPIOLIB_FASTPATH_LIMIT
26 range 32 512 26 range 32 512
27 default 512 27 default 512
28 help 28 help
29 This adjusts the point at which certain APIs will switch from 29 This adjusts the point at which certain APIs will switch from
30 using a stack allocated buffer to a dynamically allocated buffer. 30 using a stack allocated buffer to a dynamically allocated buffer.
31 31
32 You shouldn't need to change this unless you really need to 32 You shouldn't need to change this unless you really need to
33 optimize either stack space or performance. Change this carefully 33 optimize either stack space or performance. Change this carefully
34 since setting an incorrect value could cause stack corruption. 34 since setting an incorrect value could cause stack corruption.
35 35
36config OF_GPIO 36config OF_GPIO
37 def_bool y 37 def_bool y
@@ -319,7 +319,7 @@ config GPIO_MENZ127
319 depends on MCB 319 depends on MCB
320 select GPIO_GENERIC 320 select GPIO_GENERIC
321 help 321 help
322 Say yes here to support the MEN 16Z127 GPIO Controller 322 Say yes here to support the MEN 16Z127 GPIO Controller
323 323
324config GPIO_MM_LANTIQ 324config GPIO_MM_LANTIQ
325 bool "Lantiq Memory mapped GPIOs" 325 bool "Lantiq Memory mapped GPIOs"
@@ -329,20 +329,6 @@ config GPIO_MM_LANTIQ
329 (EBU) found on Lantiq SoCs. The gpios are output only as they are 329 (EBU) found on Lantiq SoCs. The gpios are output only as they are
330 created by attaching a 16bit latch to the bus. 330 created by attaching a 16bit latch to the bus.
331 331
332config GPIO_MOCKUP
333 tristate "GPIO Testing Driver"
334 depends on GPIOLIB && SYSFS
335 select GPIO_SYSFS
336 select GPIOLIB_IRQCHIP
337 select IRQ_SIM
338 help
339 This enables GPIO Testing driver, which provides a way to test GPIO
340 subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS
341 must be selected for this test.
342 User could use it through the script in
343 tools/testing/selftests/gpio/gpio-mockup.sh. Reference the usage in
344 it.
345
346config GPIO_MPC5200 332config GPIO_MPC5200
347 def_bool y 333 def_bool y
348 depends on PPC_MPC52xx 334 depends on PPC_MPC52xx
@@ -861,11 +847,11 @@ config GPIO_MAX732X
861 Input and Output (designed by 'P'). The combinations are listed 847 Input and Output (designed by 'P'). The combinations are listed
862 below: 848 below:
863 849
864 8 bits: max7319 (8I), max7320 (8O), max7321 (8P), 850 8 bits: max7319 (8I), max7320 (8O), max7321 (8P),
865 max7322 (4I4O), max7323 (4P4O) 851 max7322 (4I4O), max7323 (4P4O)
866 852
867 16 bits: max7324 (8I8O), max7325 (8P8O), 853 16 bits: max7324 (8I8O), max7325 (8P8O),
868 max7326 (4I12O), max7327 (4P12O) 854 max7326 (4I12O), max7327 (4P12O)
869 855
870 Board setup code must specify the model to use, and the start 856 Board setup code must specify the model to use, and the start
871 number for these GPIOs. 857 number for these GPIOs.
@@ -892,17 +878,17 @@ config GPIO_PCA953X
892 SMBus I/O expanders, made mostly by NXP or TI. Compatible 878 SMBus I/O expanders, made mostly by NXP or TI. Compatible
893 models include: 879 models include:
894 880
895 4 bits: pca9536, pca9537 881 4 bits: pca9536, pca9537
896 882
897 8 bits: max7310, max7315, pca6107, pca9534, pca9538, pca9554, 883 8 bits: max7310, max7315, pca6107, pca9534, pca9538, pca9554,
898 pca9556, pca9557, pca9574, tca6408, tca9554, xra1202 884 pca9556, pca9557, pca9574, tca6408, tca9554, xra1202
899 885
900 16 bits: max7312, max7313, pca9535, pca9539, pca9555, pca9575, 886 16 bits: max7312, max7313, pca9535, pca9539, pca9555, pca9575,
901 tca6416 887 tca6416
902 888
903 24 bits: tca6424 889 24 bits: tca6424
904 890
905 40 bits: pca9505, pca9698 891 40 bits: pca9505, pca9698
906 892
907config GPIO_PCA953X_IRQ 893config GPIO_PCA953X_IRQ
908 bool "Interrupt controller support for PCA953x" 894 bool "Interrupt controller support for PCA953x"
@@ -924,7 +910,7 @@ config GPIO_PCF857X
924 910
925 8 bits: pcf8574, pcf8574a, pca8574, pca8574a, 911 8 bits: pcf8574, pcf8574a, pca8574, pca8574a,
926 pca9670, pca9672, pca9674, pca9674a, 912 pca9670, pca9672, pca9674, pca9674a,
927 max7328, max7329 913 max7328, max7329
928 914
929 16 bits: pcf8575, pcf8575c, pca8575, 915 16 bits: pcf8575, pcf8575c, pca8575,
930 pca9671, pca9673, pca9675 916 pca9671, pca9673, pca9675
@@ -1046,9 +1032,9 @@ config HTC_EGPIO
1046 bool "HTC EGPIO support" 1032 bool "HTC EGPIO support"
1047 depends on GPIOLIB && ARM 1033 depends on GPIOLIB && ARM
1048 help 1034 help
1049 This driver supports the CPLD egpio chip present on 1035 This driver supports the CPLD egpio chip present on
1050 several HTC phones. It provides basic support for input 1036 several HTC phones. It provides basic support for input
1051 pins, output pins, and irqs. 1037 pins, output pins, and irqs.
1052 1038
1053config GPIO_JANZ_TTL 1039config GPIO_JANZ_TTL
1054 tristate "Janz VMOD-TTL Digital IO Module" 1040 tristate "Janz VMOD-TTL Digital IO Module"
@@ -1084,7 +1070,7 @@ config GPIO_LP873X
1084 on LP873X PMICs. 1070 on LP873X PMICs.
1085 1071
1086 This driver can also be built as a module. If so, the module will be 1072 This driver can also be built as a module. If so, the module will be
1087 called gpio-lp873x. 1073 called gpio-lp873x.
1088 1074
1089config GPIO_LP87565 1075config GPIO_LP87565
1090 tristate "TI LP87565 GPIO" 1076 tristate "TI LP87565 GPIO"
@@ -1315,6 +1301,13 @@ config GPIO_MERRIFIELD
1315 help 1301 help
1316 Say Y here to support Intel Merrifield GPIO. 1302 Say Y here to support Intel Merrifield GPIO.
1317 1303
1304config GPIO_MLXBF
1305 tristate "Mellanox BlueField SoC GPIO"
1306 depends on (MELLANOX_PLATFORM && ARM64 && ACPI) || (64BIT && COMPILE_TEST)
1307 select GPIO_GENERIC
1308 help
1309 Say Y here if you want GPIO support on Mellanox BlueField SoC.
1310
1318config GPIO_ML_IOH 1311config GPIO_ML_IOH
1319 tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support" 1312 tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support"
1320 depends on X86 || COMPILE_TEST 1313 depends on X86 || COMPILE_TEST
@@ -1435,10 +1428,22 @@ config GPIO_VIPERBOARD
1435 Say yes here to access the GPIO signals of Nano River 1428 Say yes here to access the GPIO signals of Nano River
1436 Technologies Viperboard. There are two GPIO chips on the 1429 Technologies Viperboard. There are two GPIO chips on the
1437 board: gpioa and gpiob. 1430 board: gpioa and gpiob.
1438 See viperboard API specification and Nano 1431 See viperboard API specification and Nano
1439 River Tech's viperboard.h for detailed meaning 1432 River Tech's viperboard.h for detailed meaning
1440 of the module parameters. 1433 of the module parameters.
1441 1434
1442endmenu 1435endmenu
1443 1436
1437config GPIO_MOCKUP
1438 tristate "GPIO Testing Driver"
1439 depends on GPIOLIB
1440 select IRQ_SIM
1441 help
1442 This enables GPIO Testing driver, which provides a way to test GPIO
1443 subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS
1444 must be selected for this test.
1445 User could use it through the script in
1446 tools/testing/selftests/gpio/gpio-mockup.sh. Reference the usage in
1447 it.
1448
1444endif 1449endif
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 54d55274b93a..db8d854f9aea 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -85,6 +85,7 @@ obj-$(CONFIG_GPIO_MENZ127) += gpio-menz127.o
85obj-$(CONFIG_GPIO_MERRIFIELD) += gpio-merrifield.o 85obj-$(CONFIG_GPIO_MERRIFIELD) += gpio-merrifield.o
86obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o 86obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o
87obj-$(CONFIG_GPIO_MC9S08DZ60) += gpio-mc9s08dz60.o 87obj-$(CONFIG_GPIO_MC9S08DZ60) += gpio-mc9s08dz60.o
88obj-$(CONFIG_GPIO_MLXBF) += gpio-mlxbf.o
88obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o 89obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o
89obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o 90obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o
90obj-$(CONFIG_GPIO_MOCKUP) += gpio-mockup.o 91obj-$(CONFIG_GPIO_MOCKUP) += gpio-mockup.o
diff --git a/drivers/gpio/gpio-74x164.c b/drivers/gpio/gpio-74x164.c
index fb7b620763a2..e81307f9754e 100644
--- a/drivers/gpio/gpio-74x164.c
+++ b/drivers/gpio/gpio-74x164.c
@@ -1,21 +1,18 @@
1// SPDX-License-Identifier: GPL-2.0-only
1/* 2/*
2 * 74Hx164 - Generic serial-in/parallel-out 8-bits shift register GPIO driver 3 * 74Hx164 - Generic serial-in/parallel-out 8-bits shift register GPIO driver
3 * 4 *
4 * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org> 5 * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2010 Miguel Gaio <miguel.gaio@efixo.com> 6 * Copyright (C) 2010 Miguel Gaio <miguel.gaio@efixo.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */ 7 */
11 8
12#include <linux/init.h>
13#include <linux/mutex.h>
14#include <linux/spi/spi.h>
15#include <linux/gpio/driver.h>
16#include <linux/gpio/consumer.h> 9#include <linux/gpio/consumer.h>
17#include <linux/slab.h> 10#include <linux/gpio/driver.h>
18#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/mutex.h>
13#include <linux/property.h>
14#include <linux/slab.h>
15#include <linux/spi/spi.h>
19 16
20#define GEN_74X164_NUMBER_GPIOS 8 17#define GEN_74X164_NUMBER_GPIOS 8
21 18
@@ -116,10 +113,9 @@ static int gen_74x164_probe(struct spi_device *spi)
116 if (ret < 0) 113 if (ret < 0)
117 return ret; 114 return ret;
118 115
119 if (of_property_read_u32(spi->dev.of_node, "registers-number", 116 ret = device_property_read_u32(&spi->dev, "registers-number", &nregs);
120 &nregs)) { 117 if (ret) {
121 dev_err(&spi->dev, 118 dev_err(&spi->dev, "Missing 'registers-number' property.\n");
122 "Missing registers-number property in the DT.\n");
123 return -EINVAL; 119 return -EINVAL;
124 } 120 }
125 121
diff --git a/drivers/gpio/gpio-74xx-mmio.c b/drivers/gpio/gpio-74xx-mmio.c
index 49616ec815ee..04247075091d 100644
--- a/drivers/gpio/gpio-74xx-mmio.c
+++ b/drivers/gpio/gpio-74xx-mmio.c
@@ -106,7 +106,6 @@ static int mmio_74xx_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
106static int mmio_74xx_gpio_probe(struct platform_device *pdev) 106static int mmio_74xx_gpio_probe(struct platform_device *pdev)
107{ 107{
108 struct mmio_74xx_gpio_priv *priv; 108 struct mmio_74xx_gpio_priv *priv;
109 struct resource *res;
110 void __iomem *dat; 109 void __iomem *dat;
111 int err; 110 int err;
112 111
@@ -116,8 +115,7 @@ static int mmio_74xx_gpio_probe(struct platform_device *pdev)
116 115
117 priv->flags = (uintptr_t)of_device_get_match_data(&pdev->dev); 116 priv->flags = (uintptr_t)of_device_get_match_data(&pdev->dev);
118 117
119 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 118 dat = devm_platform_ioremap_resource(pdev, 0);
120 dat = devm_ioremap_resource(&pdev->dev, res);
121 if (IS_ERR(dat)) 119 if (IS_ERR(dat))
122 return PTR_ERR(dat); 120 return PTR_ERR(dat);
123 121
diff --git a/drivers/gpio/gpio-amdpt.c b/drivers/gpio/gpio-amdpt.c
index 9b78dc837603..1ffd7c2d1285 100644
--- a/drivers/gpio/gpio-amdpt.c
+++ b/drivers/gpio/gpio-amdpt.c
@@ -78,7 +78,6 @@ static int pt_gpio_probe(struct platform_device *pdev)
78 struct acpi_device *acpi_dev; 78 struct acpi_device *acpi_dev;
79 acpi_handle handle = ACPI_HANDLE(dev); 79 acpi_handle handle = ACPI_HANDLE(dev);
80 struct pt_gpio_chip *pt_gpio; 80 struct pt_gpio_chip *pt_gpio;
81 struct resource *res_mem;
82 int ret = 0; 81 int ret = 0;
83 82
84 if (acpi_bus_get_device(handle, &acpi_dev)) { 83 if (acpi_bus_get_device(handle, &acpi_dev)) {
@@ -90,12 +89,7 @@ static int pt_gpio_probe(struct platform_device *pdev)
90 if (!pt_gpio) 89 if (!pt_gpio)
91 return -ENOMEM; 90 return -ENOMEM;
92 91
93 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 92 pt_gpio->reg_base = devm_platform_ioremap_resource(pdev, 0);
94 if (!res_mem) {
95 dev_err(&pdev->dev, "Failed to get MMIO resource for PT GPIO.\n");
96 return -EINVAL;
97 }
98 pt_gpio->reg_base = devm_ioremap_resource(dev, res_mem);
99 if (IS_ERR(pt_gpio->reg_base)) { 93 if (IS_ERR(pt_gpio->reg_base)) {
100 dev_err(&pdev->dev, "Failed to map MMIO resource for PT GPIO.\n"); 94 dev_err(&pdev->dev, "Failed to map MMIO resource for PT GPIO.\n");
101 return PTR_ERR(pt_gpio->reg_base); 95 return PTR_ERR(pt_gpio->reg_base);
diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
index 217507002dbc..0f1b55c7c361 100644
--- a/drivers/gpio/gpio-aspeed.c
+++ b/drivers/gpio/gpio-aspeed.c
@@ -1156,15 +1156,13 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev)
1156{ 1156{
1157 const struct of_device_id *gpio_id; 1157 const struct of_device_id *gpio_id;
1158 struct aspeed_gpio *gpio; 1158 struct aspeed_gpio *gpio;
1159 struct resource *res;
1160 int rc, i, banks; 1159 int rc, i, banks;
1161 1160
1162 gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 1161 gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
1163 if (!gpio) 1162 if (!gpio)
1164 return -ENOMEM; 1163 return -ENOMEM;
1165 1164
1166 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1165 gpio->base = devm_platform_ioremap_resource(pdev, 0);
1167 gpio->base = devm_ioremap_resource(&pdev->dev, res);
1168 if (IS_ERR(gpio->base)) 1166 if (IS_ERR(gpio->base))
1169 return PTR_ERR(gpio->base); 1167 return PTR_ERR(gpio->base);
1170 1168
diff --git a/drivers/gpio/gpio-bcm-kona.c b/drivers/gpio/gpio-bcm-kona.c
index c5536a509b59..9fa6d3a967d2 100644
--- a/drivers/gpio/gpio-bcm-kona.c
+++ b/drivers/gpio/gpio-bcm-kona.c
@@ -568,7 +568,6 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev)
568{ 568{
569 struct device *dev = &pdev->dev; 569 struct device *dev = &pdev->dev;
570 const struct of_device_id *match; 570 const struct of_device_id *match;
571 struct resource *res;
572 struct bcm_kona_gpio_bank *bank; 571 struct bcm_kona_gpio_bank *bank;
573 struct bcm_kona_gpio *kona_gpio; 572 struct bcm_kona_gpio *kona_gpio;
574 struct gpio_chip *chip; 573 struct gpio_chip *chip;
@@ -618,8 +617,7 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev)
618 return -ENXIO; 617 return -ENXIO;
619 } 618 }
620 619
621 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 620 kona_gpio->reg_base = devm_platform_ioremap_resource(pdev, 0);
622 kona_gpio->reg_base = devm_ioremap_resource(dev, res);
623 if (IS_ERR(kona_gpio->reg_base)) { 621 if (IS_ERR(kona_gpio->reg_base)) {
624 ret = -ENXIO; 622 ret = -ENXIO;
625 goto err_irq_domain; 623 goto err_irq_domain;
diff --git a/drivers/gpio/gpio-cadence.c b/drivers/gpio/gpio-cadence.c
index aec8d5df9f30..712ae212b0b4 100644
--- a/drivers/gpio/gpio-cadence.c
+++ b/drivers/gpio/gpio-cadence.c
@@ -148,7 +148,6 @@ static struct irq_chip cdns_gpio_irqchip = {
148static int cdns_gpio_probe(struct platform_device *pdev) 148static int cdns_gpio_probe(struct platform_device *pdev)
149{ 149{
150 struct cdns_gpio_chip *cgpio; 150 struct cdns_gpio_chip *cgpio;
151 struct resource *res;
152 int ret, irq; 151 int ret, irq;
153 u32 dir_prev; 152 u32 dir_prev;
154 u32 num_gpios = 32; 153 u32 num_gpios = 32;
@@ -157,8 +156,7 @@ static int cdns_gpio_probe(struct platform_device *pdev)
157 if (!cgpio) 156 if (!cgpio)
158 return -ENOMEM; 157 return -ENOMEM;
159 158
160 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 159 cgpio->regs = devm_platform_ioremap_resource(pdev, 0);
161 cgpio->regs = devm_ioremap_resource(&pdev->dev, res);
162 if (IS_ERR(cgpio->regs)) 160 if (IS_ERR(cgpio->regs))
163 return PTR_ERR(cgpio->regs); 161 return PTR_ERR(cgpio->regs);
164 162
diff --git a/drivers/gpio/gpio-clps711x.c b/drivers/gpio/gpio-clps711x.c
index 52fd63f02134..0fbbb0edc0ba 100644
--- a/drivers/gpio/gpio-clps711x.c
+++ b/drivers/gpio/gpio-clps711x.c
@@ -19,7 +19,6 @@ static int clps711x_gpio_probe(struct platform_device *pdev)
19 struct device_node *np = pdev->dev.of_node; 19 struct device_node *np = pdev->dev.of_node;
20 void __iomem *dat, *dir; 20 void __iomem *dat, *dir;
21 struct gpio_chip *gc; 21 struct gpio_chip *gc;
22 struct resource *res;
23 int err, id; 22 int err, id;
24 23
25 if (!np) 24 if (!np)
@@ -33,13 +32,11 @@ static int clps711x_gpio_probe(struct platform_device *pdev)
33 if (!gc) 32 if (!gc)
34 return -ENOMEM; 33 return -ENOMEM;
35 34
36 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 35 dat = devm_platform_ioremap_resource(pdev, 0);
37 dat = devm_ioremap_resource(&pdev->dev, res);
38 if (IS_ERR(dat)) 36 if (IS_ERR(dat))
39 return PTR_ERR(dat); 37 return PTR_ERR(dat);
40 38
41 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 39 dir = devm_platform_ioremap_resource(pdev, 1);
42 dir = devm_ioremap_resource(&pdev->dev, res);
43 if (IS_ERR(dir)) 40 if (IS_ERR(dir))
44 return PTR_ERR(dir); 41 return PTR_ERR(dir);
45 42
diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index 84ae04402f70..d3eda65fd6d3 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -655,7 +655,6 @@ MODULE_DEVICE_TABLE(acpi, dwapb_acpi_match);
655static int dwapb_gpio_probe(struct platform_device *pdev) 655static int dwapb_gpio_probe(struct platform_device *pdev)
656{ 656{
657 unsigned int i; 657 unsigned int i;
658 struct resource *res;
659 struct dwapb_gpio *gpio; 658 struct dwapb_gpio *gpio;
660 int err; 659 int err;
661 struct device *dev = &pdev->dev; 660 struct device *dev = &pdev->dev;
@@ -688,8 +687,7 @@ static int dwapb_gpio_probe(struct platform_device *pdev)
688 if (!gpio->ports) 687 if (!gpio->ports)
689 return -ENOMEM; 688 return -ENOMEM;
690 689
691 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 690 gpio->regs = devm_platform_ioremap_resource(pdev, 0);
692 gpio->regs = devm_ioremap_resource(&pdev->dev, res);
693 if (IS_ERR(gpio->regs)) 691 if (IS_ERR(gpio->regs))
694 return PTR_ERR(gpio->regs); 692 return PTR_ERR(gpio->regs);
695 693
diff --git a/drivers/gpio/gpio-ftgpio010.c b/drivers/gpio/gpio-ftgpio010.c
index 45fe125823a8..8ff8ce2970d9 100644
--- a/drivers/gpio/gpio-ftgpio010.c
+++ b/drivers/gpio/gpio-ftgpio010.c
@@ -225,7 +225,6 @@ static int ftgpio_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
225static int ftgpio_gpio_probe(struct platform_device *pdev) 225static int ftgpio_gpio_probe(struct platform_device *pdev)
226{ 226{
227 struct device *dev = &pdev->dev; 227 struct device *dev = &pdev->dev;
228 struct resource *res;
229 struct ftgpio_gpio *g; 228 struct ftgpio_gpio *g;
230 int irq; 229 int irq;
231 int ret; 230 int ret;
@@ -236,8 +235,7 @@ static int ftgpio_gpio_probe(struct platform_device *pdev)
236 235
237 g->dev = dev; 236 g->dev = dev;
238 237
239 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 238 g->base = devm_platform_ioremap_resource(pdev, 0);
240 g->base = devm_ioremap_resource(dev, res);
241 if (IS_ERR(g->base)) 239 if (IS_ERR(g->base))
242 return PTR_ERR(g->base); 240 return PTR_ERR(g->base);
243 241
diff --git a/drivers/gpio/gpio-hlwd.c b/drivers/gpio/gpio-hlwd.c
index a7b17897356e..e5fa00f8145f 100644
--- a/drivers/gpio/gpio-hlwd.c
+++ b/drivers/gpio/gpio-hlwd.c
@@ -208,7 +208,6 @@ static int hlwd_gpio_irq_set_type(struct irq_data *data, unsigned int flow_type)
208static int hlwd_gpio_probe(struct platform_device *pdev) 208static int hlwd_gpio_probe(struct platform_device *pdev)
209{ 209{
210 struct hlwd_gpio *hlwd; 210 struct hlwd_gpio *hlwd;
211 struct resource *regs_resource;
212 u32 ngpios; 211 u32 ngpios;
213 int res; 212 int res;
214 213
@@ -216,8 +215,7 @@ static int hlwd_gpio_probe(struct platform_device *pdev)
216 if (!hlwd) 215 if (!hlwd)
217 return -ENOMEM; 216 return -ENOMEM;
218 217
219 regs_resource = platform_get_resource(pdev, IORESOURCE_MEM, 0); 218 hlwd->regs = devm_platform_ioremap_resource(pdev, 0);
220 hlwd->regs = devm_ioremap_resource(&pdev->dev, regs_resource);
221 if (IS_ERR(hlwd->regs)) 219 if (IS_ERR(hlwd->regs))
222 return PTR_ERR(hlwd->regs); 220 return PTR_ERR(hlwd->regs);
223 221
diff --git a/drivers/gpio/gpio-iop.c b/drivers/gpio/gpio-iop.c
index 8d62db447ec1..11b77d868c89 100644
--- a/drivers/gpio/gpio-iop.c
+++ b/drivers/gpio/gpio-iop.c
@@ -21,7 +21,6 @@
21 21
22static int iop3xx_gpio_probe(struct platform_device *pdev) 22static int iop3xx_gpio_probe(struct platform_device *pdev)
23{ 23{
24 struct resource *res;
25 struct gpio_chip *gc; 24 struct gpio_chip *gc;
26 void __iomem *base; 25 void __iomem *base;
27 int err; 26 int err;
@@ -30,8 +29,7 @@ static int iop3xx_gpio_probe(struct platform_device *pdev)
30 if (!gc) 29 if (!gc)
31 return -ENOMEM; 30 return -ENOMEM;
32 31
33 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 32 base = devm_platform_ioremap_resource(pdev, 0);
34 base = devm_ioremap_resource(&pdev->dev, res);
35 if (IS_ERR(base)) 33 if (IS_ERR(base))
36 return PTR_ERR(base); 34 return PTR_ERR(base);
37 35
diff --git a/drivers/gpio/gpio-janz-ttl.c b/drivers/gpio/gpio-janz-ttl.c
index 6b9bf8b7bf16..b97a91166497 100644
--- a/drivers/gpio/gpio-janz-ttl.c
+++ b/drivers/gpio/gpio-janz-ttl.c
@@ -147,7 +147,6 @@ static int ttl_probe(struct platform_device *pdev)
147 struct device *dev = &pdev->dev; 147 struct device *dev = &pdev->dev;
148 struct ttl_module *mod; 148 struct ttl_module *mod;
149 struct gpio_chip *gpio; 149 struct gpio_chip *gpio;
150 struct resource *res;
151 int ret; 150 int ret;
152 151
153 pdata = dev_get_platdata(&pdev->dev); 152 pdata = dev_get_platdata(&pdev->dev);
@@ -164,8 +163,7 @@ static int ttl_probe(struct platform_device *pdev)
164 spin_lock_init(&mod->lock); 163 spin_lock_init(&mod->lock);
165 164
166 /* get access to the MODULbus registers for this module */ 165 /* get access to the MODULbus registers for this module */
167 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 166 mod->regs = devm_platform_ioremap_resource(pdev, 0);
168 mod->regs = devm_ioremap_resource(dev, res);
169 if (IS_ERR(mod->regs)) 167 if (IS_ERR(mod->regs))
170 return PTR_ERR(mod->regs); 168 return PTR_ERR(mod->regs);
171 169
diff --git a/drivers/gpio/gpio-loongson1.c b/drivers/gpio/gpio-loongson1.c
index fca84ccac35c..1b1ee94eeab4 100644
--- a/drivers/gpio/gpio-loongson1.c
+++ b/drivers/gpio/gpio-loongson1.c
@@ -47,15 +47,13 @@ static int ls1x_gpio_probe(struct platform_device *pdev)
47{ 47{
48 struct device *dev = &pdev->dev; 48 struct device *dev = &pdev->dev;
49 struct gpio_chip *gc; 49 struct gpio_chip *gc;
50 struct resource *res;
51 int ret; 50 int ret;
52 51
53 gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); 52 gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL);
54 if (!gc) 53 if (!gc)
55 return -ENOMEM; 54 return -ENOMEM;
56 55
57 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 56 gpio_reg_base = devm_platform_ioremap_resource(pdev, 0);
58 gpio_reg_base = devm_ioremap_resource(dev, res);
59 if (IS_ERR(gpio_reg_base)) 57 if (IS_ERR(gpio_reg_base))
60 return PTR_ERR(gpio_reg_base); 58 return PTR_ERR(gpio_reg_base);
61 59
diff --git a/drivers/gpio/gpio-lpc18xx.c b/drivers/gpio/gpio-lpc18xx.c
index d441dbaed7a3..d711ae06747e 100644
--- a/drivers/gpio/gpio-lpc18xx.c
+++ b/drivers/gpio/gpio-lpc18xx.c
@@ -340,10 +340,7 @@ static int lpc18xx_gpio_probe(struct platform_device *pdev)
340 index = of_property_match_string(dev->of_node, "reg-names", "gpio"); 340 index = of_property_match_string(dev->of_node, "reg-names", "gpio");
341 if (index < 0) { 341 if (index < 0) {
342 /* To support backward compatibility take the first resource */ 342 /* To support backward compatibility take the first resource */
343 struct resource *res; 343 gc->base = devm_platform_ioremap_resource(pdev, 0);
344
345 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
346 gc->base = devm_ioremap_resource(dev, res);
347 } else { 344 } else {
348 struct resource res; 345 struct resource res;
349 346
diff --git a/drivers/gpio/gpio-mb86s7x.c b/drivers/gpio/gpio-mb86s7x.c
index 3134c0d2bfe4..9308081e0a4a 100644
--- a/drivers/gpio/gpio-mb86s7x.c
+++ b/drivers/gpio/gpio-mb86s7x.c
@@ -146,7 +146,6 @@ static void mb86s70_gpio_set(struct gpio_chip *gc, unsigned gpio, int value)
146static int mb86s70_gpio_probe(struct platform_device *pdev) 146static int mb86s70_gpio_probe(struct platform_device *pdev)
147{ 147{
148 struct mb86s70_gpio_chip *gchip; 148 struct mb86s70_gpio_chip *gchip;
149 struct resource *res;
150 int ret; 149 int ret;
151 150
152 gchip = devm_kzalloc(&pdev->dev, sizeof(*gchip), GFP_KERNEL); 151 gchip = devm_kzalloc(&pdev->dev, sizeof(*gchip), GFP_KERNEL);
@@ -155,8 +154,7 @@ static int mb86s70_gpio_probe(struct platform_device *pdev)
155 154
156 platform_set_drvdata(pdev, gchip); 155 platform_set_drvdata(pdev, gchip);
157 156
158 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 157 gchip->base = devm_platform_ioremap_resource(pdev, 0);
159 gchip->base = devm_ioremap_resource(&pdev->dev, res);
160 if (IS_ERR(gchip->base)) 158 if (IS_ERR(gchip->base))
161 return PTR_ERR(gchip->base); 159 return PTR_ERR(gchip->base);
162 160
diff --git a/drivers/gpio/gpio-mlxbf.c b/drivers/gpio/gpio-mlxbf.c
new file mode 100644
index 000000000000..894aaf55fc96
--- /dev/null
+++ b/drivers/gpio/gpio-mlxbf.c
@@ -0,0 +1,152 @@
1// SPDX-License-Identifier: GPL-2.0
2
3#include <linux/acpi.h>
4#include <linux/bitops.h>
5#include <linux/device.h>
6#include <linux/gpio/driver.h>
7#include <linux/io.h>
8#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/platform_device.h>
11#include <linux/pm.h>
12#include <linux/resource.h>
13#include <linux/types.h>
14
15/* Number of pins on BlueField */
16#define MLXBF_GPIO_NR 54
17
18/* Pad Electrical Controls. */
19#define MLXBF_GPIO_PAD_CONTROL_FIRST_WORD 0x0700
20#define MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD 0x0708
21#define MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD 0x0710
22#define MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD 0x0718
23
24#define MLXBF_GPIO_PIN_DIR_I 0x1040
25#define MLXBF_GPIO_PIN_DIR_O 0x1048
26#define MLXBF_GPIO_PIN_STATE 0x1000
27#define MLXBF_GPIO_SCRATCHPAD 0x20
28
29#ifdef CONFIG_PM
30struct mlxbf_gpio_context_save_regs {
31 u64 scratchpad;
32 u64 pad_control[MLXBF_GPIO_NR];
33 u64 pin_dir_i;
34 u64 pin_dir_o;
35};
36#endif
37
38/* Device state structure. */
39struct mlxbf_gpio_state {
40 struct gpio_chip gc;
41
42 /* Memory Address */
43 void __iomem *base;
44
45#ifdef CONFIG_PM
46 struct mlxbf_gpio_context_save_regs csave_regs;
47#endif
48};
49
50static int mlxbf_gpio_probe(struct platform_device *pdev)
51{
52 struct mlxbf_gpio_state *gs;
53 struct device *dev = &pdev->dev;
54 struct gpio_chip *gc;
55 int ret;
56
57 gs = devm_kzalloc(&pdev->dev, sizeof(*gs), GFP_KERNEL);
58 if (!gs)
59 return -ENOMEM;
60
61 gs->base = devm_platform_ioremap_resource(pdev, 0);
62 if (IS_ERR(gs->base))
63 return PTR_ERR(gs->base);
64
65 gc = &gs->gc;
66 ret = bgpio_init(gc, dev, 8,
67 gs->base + MLXBF_GPIO_PIN_STATE,
68 NULL,
69 NULL,
70 gs->base + MLXBF_GPIO_PIN_DIR_O,
71 gs->base + MLXBF_GPIO_PIN_DIR_I,
72 0);
73 if (ret)
74 return -ENODEV;
75
76 gc->owner = THIS_MODULE;
77 gc->ngpio = MLXBF_GPIO_NR;
78
79 ret = devm_gpiochip_add_data(dev, &gs->gc, gs);
80 if (ret) {
81 dev_err(&pdev->dev, "Failed adding memory mapped gpiochip\n");
82 return ret;
83 }
84
85 platform_set_drvdata(pdev, gs);
86 dev_info(&pdev->dev, "registered Mellanox BlueField GPIO");
87 return 0;
88}
89
90#ifdef CONFIG_PM
91static int mlxbf_gpio_suspend(struct platform_device *pdev, pm_message_t state)
92{
93 struct mlxbf_gpio_state *gs = platform_get_drvdata(pdev);
94
95 gs->csave_regs.scratchpad = readq(gs->base + MLXBF_GPIO_SCRATCHPAD);
96 gs->csave_regs.pad_control[0] =
97 readq(gs->base + MLXBF_GPIO_PAD_CONTROL_FIRST_WORD);
98 gs->csave_regs.pad_control[1] =
99 readq(gs->base + MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD);
100 gs->csave_regs.pad_control[2] =
101 readq(gs->base + MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD);
102 gs->csave_regs.pad_control[3] =
103 readq(gs->base + MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD);
104 gs->csave_regs.pin_dir_i = readq(gs->base + MLXBF_GPIO_PIN_DIR_I);
105 gs->csave_regs.pin_dir_o = readq(gs->base + MLXBF_GPIO_PIN_DIR_O);
106
107 return 0;
108}
109
110static int mlxbf_gpio_resume(struct platform_device *pdev)
111{
112 struct mlxbf_gpio_state *gs = platform_get_drvdata(pdev);
113
114 writeq(gs->csave_regs.scratchpad, gs->base + MLXBF_GPIO_SCRATCHPAD);
115 writeq(gs->csave_regs.pad_control[0],
116 gs->base + MLXBF_GPIO_PAD_CONTROL_FIRST_WORD);
117 writeq(gs->csave_regs.pad_control[1],
118 gs->base + MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD);
119 writeq(gs->csave_regs.pad_control[2],
120 gs->base + MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD);
121 writeq(gs->csave_regs.pad_control[3],
122 gs->base + MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD);
123 writeq(gs->csave_regs.pin_dir_i, gs->base + MLXBF_GPIO_PIN_DIR_I);
124 writeq(gs->csave_regs.pin_dir_o, gs->base + MLXBF_GPIO_PIN_DIR_O);
125
126 return 0;
127}
128#endif
129
130static const struct acpi_device_id mlxbf_gpio_acpi_match[] = {
131 { "MLNXBF02", 0 },
132 {}
133};
134MODULE_DEVICE_TABLE(acpi, mlxbf_gpio_acpi_match);
135
136static struct platform_driver mlxbf_gpio_driver = {
137 .driver = {
138 .name = "mlxbf_gpio",
139 .acpi_match_table = ACPI_PTR(mlxbf_gpio_acpi_match),
140 },
141 .probe = mlxbf_gpio_probe,
142#ifdef CONFIG_PM
143 .suspend = mlxbf_gpio_suspend,
144 .resume = mlxbf_gpio_resume,
145#endif
146};
147
148module_platform_driver(mlxbf_gpio_driver);
149
150MODULE_DESCRIPTION("Mellanox BlueField GPIO Driver");
151MODULE_AUTHOR("Mellanox Technologies");
152MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c
index 50bdc29591c0..6f904c874678 100644
--- a/drivers/gpio/gpio-mmio.c
+++ b/drivers/gpio/gpio-mmio.c
@@ -134,17 +134,6 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio)
134 unsigned long pinmask = bgpio_line2mask(gc, gpio); 134 unsigned long pinmask = bgpio_line2mask(gc, gpio);
135 bool dir = !!(gc->bgpio_dir & pinmask); 135 bool dir = !!(gc->bgpio_dir & pinmask);
136 136
137 /*
138 * If the direction is OUT we read the value from the SET
139 * register, and if the direction is IN we read the value
140 * from the DAT register.
141 *
142 * If the direction bits are inverted, naturally this gets
143 * inverted too.
144 */
145 if (gc->bgpio_dir_inverted)
146 dir = !dir;
147
148 if (dir) 137 if (dir)
149 return !!(gc->read_reg(gc->reg_set) & pinmask); 138 return !!(gc->read_reg(gc->reg_set) & pinmask);
150 else 139 else
@@ -164,14 +153,8 @@ static int bgpio_get_set_multiple(struct gpio_chip *gc, unsigned long *mask,
164 /* Make sure we first clear any bits that are zero when we read the register */ 153 /* Make sure we first clear any bits that are zero when we read the register */
165 *bits &= ~*mask; 154 *bits &= ~*mask;
166 155
167 /* Exploit the fact that we know which directions are set */ 156 set_mask = *mask & gc->bgpio_dir;
168 if (gc->bgpio_dir_inverted) { 157 get_mask = *mask & ~gc->bgpio_dir;
169 set_mask = *mask & ~gc->bgpio_dir;
170 get_mask = *mask & gc->bgpio_dir;
171 } else {
172 set_mask = *mask & gc->bgpio_dir;
173 get_mask = *mask & ~gc->bgpio_dir;
174 }
175 158
176 if (set_mask) 159 if (set_mask)
177 *bits |= gc->read_reg(gc->reg_set) & set_mask; 160 *bits |= gc->read_reg(gc->reg_set) & set_mask;
@@ -372,11 +355,12 @@ static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
372 355
373 spin_lock_irqsave(&gc->bgpio_lock, flags); 356 spin_lock_irqsave(&gc->bgpio_lock, flags);
374 357
375 if (gc->bgpio_dir_inverted) 358 gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio);
376 gc->bgpio_dir |= bgpio_line2mask(gc, gpio); 359
377 else 360 if (gc->reg_dir_in)
378 gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio); 361 gc->write_reg(gc->reg_dir_in, ~gc->bgpio_dir);
379 gc->write_reg(gc->reg_dir, gc->bgpio_dir); 362 if (gc->reg_dir_out)
363 gc->write_reg(gc->reg_dir_out, gc->bgpio_dir);
380 364
381 spin_unlock_irqrestore(&gc->bgpio_lock, flags); 365 spin_unlock_irqrestore(&gc->bgpio_lock, flags);
382 366
@@ -385,11 +369,16 @@ static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
385 369
386static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) 370static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio)
387{ 371{
388 /* Return 0 if output, 1 of input */ 372 /* Return 0 if output, 1 if input */
389 if (gc->bgpio_dir_inverted) 373 if (gc->bgpio_dir_unreadable)
390 return !!(gc->read_reg(gc->reg_dir) & bgpio_line2mask(gc, gpio)); 374 return !(gc->bgpio_dir & bgpio_line2mask(gc, gpio));
391 else 375 if (gc->reg_dir_out)
392 return !(gc->read_reg(gc->reg_dir) & bgpio_line2mask(gc, gpio)); 376 return !(gc->read_reg(gc->reg_dir_out) & bgpio_line2mask(gc, gpio));
377 if (gc->reg_dir_in)
378 return !!(gc->read_reg(gc->reg_dir_in) & bgpio_line2mask(gc, gpio));
379
380 /* This should not happen */
381 return 1;
393} 382}
394 383
395static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 384static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
@@ -400,11 +389,12 @@ static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
400 389
401 spin_lock_irqsave(&gc->bgpio_lock, flags); 390 spin_lock_irqsave(&gc->bgpio_lock, flags);
402 391
403 if (gc->bgpio_dir_inverted) 392 gc->bgpio_dir |= bgpio_line2mask(gc, gpio);
404 gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio); 393
405 else 394 if (gc->reg_dir_in)
406 gc->bgpio_dir |= bgpio_line2mask(gc, gpio); 395 gc->write_reg(gc->reg_dir_in, ~gc->bgpio_dir);
407 gc->write_reg(gc->reg_dir, gc->bgpio_dir); 396 if (gc->reg_dir_out)
397 gc->write_reg(gc->reg_dir_out, gc->bgpio_dir);
408 398
409 spin_unlock_irqrestore(&gc->bgpio_lock, flags); 399 spin_unlock_irqrestore(&gc->bgpio_lock, flags);
410 400
@@ -537,19 +527,12 @@ static int bgpio_setup_direction(struct gpio_chip *gc,
537 void __iomem *dirin, 527 void __iomem *dirin,
538 unsigned long flags) 528 unsigned long flags)
539{ 529{
540 if (dirout && dirin) { 530 if (dirout || dirin) {
541 return -EINVAL; 531 gc->reg_dir_out = dirout;
542 } else if (dirout) { 532 gc->reg_dir_in = dirin;
543 gc->reg_dir = dirout;
544 gc->direction_output = bgpio_dir_out;
545 gc->direction_input = bgpio_dir_in;
546 gc->get_direction = bgpio_get_dir;
547 } else if (dirin) {
548 gc->reg_dir = dirin;
549 gc->direction_output = bgpio_dir_out; 533 gc->direction_output = bgpio_dir_out;
550 gc->direction_input = bgpio_dir_in; 534 gc->direction_input = bgpio_dir_in;
551 gc->get_direction = bgpio_get_dir; 535 gc->get_direction = bgpio_get_dir;
552 gc->bgpio_dir_inverted = true;
553 } else { 536 } else {
554 if (flags & BGPIOF_NO_OUTPUT) 537 if (flags & BGPIOF_NO_OUTPUT)
555 gc->direction_output = bgpio_dir_out_err; 538 gc->direction_output = bgpio_dir_out_err;
@@ -588,11 +571,11 @@ static int bgpio_request(struct gpio_chip *chip, unsigned gpio_pin)
588 * @dirout: MMIO address for the register to set the line as OUTPUT. It is assumed 571 * @dirout: MMIO address for the register to set the line as OUTPUT. It is assumed
589 * that setting a line to 1 in this register will turn that line into an 572 * that setting a line to 1 in this register will turn that line into an
590 * output line. Conversely, setting the line to 0 will turn that line into 573 * output line. Conversely, setting the line to 0 will turn that line into
591 * an input. Either this or @dirin can be defined, but never both. 574 * an input.
592 * @dirin: MMIO address for the register to set this line as INPUT. It is assumed 575 * @dirin: MMIO address for the register to set this line as INPUT. It is assumed
593 * that setting a line to 1 in this register will turn that line into an 576 * that setting a line to 1 in this register will turn that line into an
594 * input line. Conversely, setting the line to 0 will turn that line into 577 * input line. Conversely, setting the line to 0 will turn that line into
595 * an output. Either this or @dirout can be defined, but never both. 578 * an output.
596 * @flags: Different flags that will affect the behaviour of the device, such as 579 * @flags: Different flags that will affect the behaviour of the device, such as
597 * endianness etc. 580 * endianness etc.
598 */ 581 */
@@ -634,8 +617,28 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
634 if (gc->set == bgpio_set_set && 617 if (gc->set == bgpio_set_set &&
635 !(flags & BGPIOF_UNREADABLE_REG_SET)) 618 !(flags & BGPIOF_UNREADABLE_REG_SET))
636 gc->bgpio_data = gc->read_reg(gc->reg_set); 619 gc->bgpio_data = gc->read_reg(gc->reg_set);
637 if (gc->reg_dir && !(flags & BGPIOF_UNREADABLE_REG_DIR)) 620
638 gc->bgpio_dir = gc->read_reg(gc->reg_dir); 621 if (flags & BGPIOF_UNREADABLE_REG_DIR)
622 gc->bgpio_dir_unreadable = true;
623
624 /*
625 * Inspect hardware to find initial direction setting.
626 */
627 if ((gc->reg_dir_out || gc->reg_dir_in) &&
628 !(flags & BGPIOF_UNREADABLE_REG_DIR)) {
629 if (gc->reg_dir_out)
630 gc->bgpio_dir = gc->read_reg(gc->reg_dir_out);
631 else if (gc->reg_dir_in)
632 gc->bgpio_dir = ~gc->read_reg(gc->reg_dir_in);
633 /*
634 * If we have two direction registers, synchronise
635 * input setting to output setting, the library
636 * can not handle a line being input and output at
637 * the same time.
638 */
639 if (gc->reg_dir_out && gc->reg_dir_in)
640 gc->write_reg(gc->reg_dir_in, ~gc->bgpio_dir);
641 }
639 642
640 return ret; 643 return ret;
641} 644}
diff --git a/drivers/gpio/gpio-mt7621.c b/drivers/gpio/gpio-mt7621.c
index 74401e0adb29..79654fb2e50f 100644
--- a/drivers/gpio/gpio-mt7621.c
+++ b/drivers/gpio/gpio-mt7621.c
@@ -293,7 +293,6 @@ mediatek_gpio_bank_probe(struct device *dev,
293static int 293static int
294mediatek_gpio_probe(struct platform_device *pdev) 294mediatek_gpio_probe(struct platform_device *pdev)
295{ 295{
296 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
297 struct device *dev = &pdev->dev; 296 struct device *dev = &pdev->dev;
298 struct device_node *np = dev->of_node; 297 struct device_node *np = dev->of_node;
299 struct mtk *mtk; 298 struct mtk *mtk;
@@ -304,7 +303,7 @@ mediatek_gpio_probe(struct platform_device *pdev)
304 if (!mtk) 303 if (!mtk)
305 return -ENOMEM; 304 return -ENOMEM;
306 305
307 mtk->base = devm_ioremap_resource(dev, res); 306 mtk->base = devm_platform_ioremap_resource(pdev, 0);
308 if (IS_ERR(mtk->base)) 307 if (IS_ERR(mtk->base))
309 return PTR_ERR(mtk->base); 308 return PTR_ERR(mtk->base);
310 309
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index f97ed32b8beb..059094ac44cb 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -1038,11 +1038,9 @@ static const struct regmap_config mvebu_gpio_regmap_config = {
1038static int mvebu_gpio_probe_raw(struct platform_device *pdev, 1038static int mvebu_gpio_probe_raw(struct platform_device *pdev,
1039 struct mvebu_gpio_chip *mvchip) 1039 struct mvebu_gpio_chip *mvchip)
1040{ 1040{
1041 struct resource *res;
1042 void __iomem *base; 1041 void __iomem *base;
1043 1042
1044 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1043 base = devm_platform_ioremap_resource(pdev, 0);
1045 base = devm_ioremap_resource(&pdev->dev, res);
1046 if (IS_ERR(base)) 1044 if (IS_ERR(base))
1047 return PTR_ERR(base); 1045 return PTR_ERR(base);
1048 1046
@@ -1062,8 +1060,7 @@ static int mvebu_gpio_probe_raw(struct platform_device *pdev,
1062 * per-CPU registers 1060 * per-CPU registers
1063 */ 1061 */
1064 if (mvchip->soc_variant == MVEBU_GPIO_SOC_VARIANT_ARMADAXP) { 1062 if (mvchip->soc_variant == MVEBU_GPIO_SOC_VARIANT_ARMADAXP) {
1065 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 1063 base = devm_platform_ioremap_resource(pdev, 1);
1066 base = devm_ioremap_resource(&pdev->dev, res);
1067 if (IS_ERR(base)) 1064 if (IS_ERR(base))
1068 return PTR_ERR(base); 1065 return PTR_ERR(base);
1069 1066
diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
index e86e61dda4b7..b2813580c582 100644
--- a/drivers/gpio/gpio-mxc.c
+++ b/drivers/gpio/gpio-mxc.c
@@ -411,7 +411,6 @@ static int mxc_gpio_probe(struct platform_device *pdev)
411{ 411{
412 struct device_node *np = pdev->dev.of_node; 412 struct device_node *np = pdev->dev.of_node;
413 struct mxc_gpio_port *port; 413 struct mxc_gpio_port *port;
414 struct resource *iores;
415 int irq_base; 414 int irq_base;
416 int err; 415 int err;
417 416
@@ -423,8 +422,7 @@ static int mxc_gpio_probe(struct platform_device *pdev)
423 422
424 port->dev = &pdev->dev; 423 port->dev = &pdev->dev;
425 424
426 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 425 port->base = devm_platform_ioremap_resource(pdev, 0);
427 port->base = devm_ioremap_resource(&pdev->dev, iores);
428 if (IS_ERR(port->base)) 426 if (IS_ERR(port->base))
429 return PTR_ERR(port->base); 427 return PTR_ERR(port->base);
430 428
diff --git a/drivers/gpio/gpio-octeon.c b/drivers/gpio/gpio-octeon.c
index 1b19c88ea7bb..afb0e8a791e5 100644
--- a/drivers/gpio/gpio-octeon.c
+++ b/drivers/gpio/gpio-octeon.c
@@ -82,7 +82,6 @@ static int octeon_gpio_probe(struct platform_device *pdev)
82{ 82{
83 struct octeon_gpio *gpio; 83 struct octeon_gpio *gpio;
84 struct gpio_chip *chip; 84 struct gpio_chip *chip;
85 struct resource *res_mem;
86 void __iomem *reg_base; 85 void __iomem *reg_base;
87 int err = 0; 86 int err = 0;
88 87
@@ -91,8 +90,7 @@ static int octeon_gpio_probe(struct platform_device *pdev)
91 return -ENOMEM; 90 return -ENOMEM;
92 chip = &gpio->chip; 91 chip = &gpio->chip;
93 92
94 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 93 reg_base = devm_platform_ioremap_resource(pdev, 0);
95 reg_base = devm_ioremap_resource(&pdev->dev, res_mem);
96 if (IS_ERR(reg_base)) 94 if (IS_ERR(reg_base))
97 return PTR_ERR(reg_base); 95 return PTR_ERR(reg_base);
98 96
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index 7f33024b6d83..16289bafa001 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -31,8 +31,6 @@
31 31
32#define OMAP4_GPIO_DEBOUNCINGTIME_MASK 0xFF 32#define OMAP4_GPIO_DEBOUNCINGTIME_MASK 0xFF
33 33
34#define OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER BIT(2)
35
36struct gpio_regs { 34struct gpio_regs {
37 u32 irqenable1; 35 u32 irqenable1;
38 u32 irqenable2; 36 u32 irqenable2;
@@ -48,13 +46,6 @@ struct gpio_regs {
48 u32 debounce_en; 46 u32 debounce_en;
49}; 47};
50 48
51struct gpio_bank;
52
53struct gpio_omap_funcs {
54 void (*idle_enable_level_quirk)(struct gpio_bank *bank);
55 void (*idle_disable_level_quirk)(struct gpio_bank *bank);
56};
57
58struct gpio_bank { 49struct gpio_bank {
59 struct list_head node; 50 struct list_head node;
60 void __iomem *base; 51 void __iomem *base;
@@ -62,7 +53,6 @@ struct gpio_bank {
62 u32 non_wakeup_gpios; 53 u32 non_wakeup_gpios;
63 u32 enabled_non_wakeup_gpios; 54 u32 enabled_non_wakeup_gpios;
64 struct gpio_regs context; 55 struct gpio_regs context;
65 struct gpio_omap_funcs funcs;
66 u32 saved_datain; 56 u32 saved_datain;
67 u32 level_mask; 57 u32 level_mask;
68 u32 toggle_mask; 58 u32 toggle_mask;
@@ -83,8 +73,6 @@ struct gpio_bank {
83 int stride; 73 int stride;
84 u32 width; 74 u32 width;
85 int context_loss_count; 75 int context_loss_count;
86 bool workaround_enabled;
87 u32 quirks;
88 76
89 void (*set_dataout)(struct gpio_bank *bank, unsigned gpio, int enable); 77 void (*set_dataout)(struct gpio_bank *bank, unsigned gpio, int enable);
90 void (*set_dataout_multiple)(struct gpio_bank *bank, 78 void (*set_dataout_multiple)(struct gpio_bank *bank,
@@ -353,6 +341,22 @@ static void omap_clear_gpio_debounce(struct gpio_bank *bank, unsigned offset)
353 } 341 }
354} 342}
355 343
344/*
345 * Off mode wake-up capable GPIOs in bank(s) that are in the wakeup domain.
346 * See TRM section for GPIO for "Wake-Up Generation" for the list of GPIOs
347 * in wakeup domain. If bank->non_wakeup_gpios is not configured, assume none
348 * are capable waking up the system from off mode.
349 */
350static bool omap_gpio_is_off_wakeup_capable(struct gpio_bank *bank, u32 gpio_mask)
351{
352 u32 no_wake = bank->non_wakeup_gpios;
353
354 if (no_wake)
355 return !!(~no_wake & gpio_mask);
356
357 return false;
358}
359
356static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio, 360static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio,
357 unsigned trigger) 361 unsigned trigger)
358{ 362{
@@ -363,10 +367,16 @@ static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio,
363 trigger & IRQ_TYPE_LEVEL_LOW); 367 trigger & IRQ_TYPE_LEVEL_LOW);
364 omap_gpio_rmw(base, bank->regs->leveldetect1, gpio_bit, 368 omap_gpio_rmw(base, bank->regs->leveldetect1, gpio_bit,
365 trigger & IRQ_TYPE_LEVEL_HIGH); 369 trigger & IRQ_TYPE_LEVEL_HIGH);
370
371 /*
372 * We need the edge detection enabled for to allow the GPIO block
373 * to be woken from idle state. Set the appropriate edge detection
374 * in addition to the level detection.
375 */
366 omap_gpio_rmw(base, bank->regs->risingdetect, gpio_bit, 376 omap_gpio_rmw(base, bank->regs->risingdetect, gpio_bit,
367 trigger & IRQ_TYPE_EDGE_RISING); 377 trigger & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_HIGH));
368 omap_gpio_rmw(base, bank->regs->fallingdetect, gpio_bit, 378 omap_gpio_rmw(base, bank->regs->fallingdetect, gpio_bit,
369 trigger & IRQ_TYPE_EDGE_FALLING); 379 trigger & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW));
370 380
371 bank->context.leveldetect0 = 381 bank->context.leveldetect0 =
372 readl_relaxed(bank->base + bank->regs->leveldetect0); 382 readl_relaxed(bank->base + bank->regs->leveldetect0);
@@ -384,13 +394,7 @@ static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio,
384 } 394 }
385 395
386 /* This part needs to be executed always for OMAP{34xx, 44xx} */ 396 /* This part needs to be executed always for OMAP{34xx, 44xx} */
387 if (!bank->regs->irqctrl) { 397 if (!bank->regs->irqctrl && !omap_gpio_is_off_wakeup_capable(bank, gpio)) {
388 /* On omap24xx proceed only when valid GPIO bit is set */
389 if (bank->non_wakeup_gpios) {
390 if (!(bank->non_wakeup_gpios & gpio_bit))
391 goto exit;
392 }
393
394 /* 398 /*
395 * Log the edge gpio and manually trigger the IRQ 399 * Log the edge gpio and manually trigger the IRQ
396 * after resume if the input level changes 400 * after resume if the input level changes
@@ -403,7 +407,6 @@ static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio,
403 bank->enabled_non_wakeup_gpios &= ~gpio_bit; 407 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
404 } 408 }
405 409
406exit:
407 bank->level_mask = 410 bank->level_mask =
408 readl_relaxed(bank->base + bank->regs->leveldetect0) | 411 readl_relaxed(bank->base + bank->regs->leveldetect0) |
409 readl_relaxed(bank->base + bank->regs->leveldetect1); 412 readl_relaxed(bank->base + bank->regs->leveldetect1);
@@ -896,44 +899,6 @@ static void omap_gpio_unmask_irq(struct irq_data *d)
896 raw_spin_unlock_irqrestore(&bank->lock, flags); 899 raw_spin_unlock_irqrestore(&bank->lock, flags);
897} 900}
898 901
899/*
900 * Only edges can generate a wakeup event to the PRCM.
901 *
902 * Therefore, ensure any wake-up capable GPIOs have
903 * edge-detection enabled before going idle to ensure a wakeup
904 * to the PRCM is generated on a GPIO transition. (c.f. 34xx
905 * NDA TRM 25.5.3.1)
906 *
907 * The normal values will be restored upon ->runtime_resume()
908 * by writing back the values saved in bank->context.
909 */
910static void __maybe_unused
911omap2_gpio_enable_level_quirk(struct gpio_bank *bank)
912{
913 u32 wake_low, wake_hi;
914
915 /* Enable additional edge detection for level gpios for idle */
916 wake_low = bank->context.leveldetect0 & bank->context.wake_en;
917 if (wake_low)
918 writel_relaxed(wake_low | bank->context.fallingdetect,
919 bank->base + bank->regs->fallingdetect);
920
921 wake_hi = bank->context.leveldetect1 & bank->context.wake_en;
922 if (wake_hi)
923 writel_relaxed(wake_hi | bank->context.risingdetect,
924 bank->base + bank->regs->risingdetect);
925}
926
927static void __maybe_unused
928omap2_gpio_disable_level_quirk(struct gpio_bank *bank)
929{
930 /* Disable edge detection for level gpios after idle */
931 writel_relaxed(bank->context.fallingdetect,
932 bank->base + bank->regs->fallingdetect);
933 writel_relaxed(bank->context.risingdetect,
934 bank->base + bank->regs->risingdetect);
935}
936
937/*---------------------------------------------------------------------*/ 902/*---------------------------------------------------------------------*/
938 903
939static int omap_mpuio_suspend_noirq(struct device *dev) 904static int omap_mpuio_suspend_noirq(struct device *dev)
@@ -1251,203 +1216,70 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
1251 return ret; 1216 return ret;
1252} 1217}
1253 1218
1254static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context); 1219static void omap_gpio_init_context(struct gpio_bank *p)
1255static void omap_gpio_unidle(struct gpio_bank *bank);
1256
1257static int gpio_omap_cpu_notifier(struct notifier_block *nb,
1258 unsigned long cmd, void *v)
1259{ 1220{
1260 struct gpio_bank *bank; 1221 struct omap_gpio_reg_offs *regs = p->regs;
1261 unsigned long flags; 1222 void __iomem *base = p->base;
1262 1223
1263 bank = container_of(nb, struct gpio_bank, nb); 1224 p->context.ctrl = readl_relaxed(base + regs->ctrl);
1225 p->context.oe = readl_relaxed(base + regs->direction);
1226 p->context.wake_en = readl_relaxed(base + regs->wkup_en);
1227 p->context.leveldetect0 = readl_relaxed(base + regs->leveldetect0);
1228 p->context.leveldetect1 = readl_relaxed(base + regs->leveldetect1);
1229 p->context.risingdetect = readl_relaxed(base + regs->risingdetect);
1230 p->context.fallingdetect = readl_relaxed(base + regs->fallingdetect);
1231 p->context.irqenable1 = readl_relaxed(base + regs->irqenable);
1232 p->context.irqenable2 = readl_relaxed(base + regs->irqenable2);
1264 1233
1265 raw_spin_lock_irqsave(&bank->lock, flags); 1234 if (regs->set_dataout && p->regs->clr_dataout)
1266 switch (cmd) { 1235 p->context.dataout = readl_relaxed(base + regs->set_dataout);
1267 case CPU_CLUSTER_PM_ENTER: 1236 else
1268 if (bank->is_suspended) 1237 p->context.dataout = readl_relaxed(base + regs->dataout);
1269 break;
1270 omap_gpio_idle(bank, true);
1271 break;
1272 case CPU_CLUSTER_PM_ENTER_FAILED:
1273 case CPU_CLUSTER_PM_EXIT:
1274 if (bank->is_suspended)
1275 break;
1276 omap_gpio_unidle(bank);
1277 break;
1278 }
1279 raw_spin_unlock_irqrestore(&bank->lock, flags);
1280 1238
1281 return NOTIFY_OK; 1239 p->context_valid = true;
1282} 1240}
1283 1241
1284static const struct of_device_id omap_gpio_match[]; 1242static void omap_gpio_restore_context(struct gpio_bank *bank)
1285
1286static int omap_gpio_probe(struct platform_device *pdev)
1287{ 1243{
1288 struct device *dev = &pdev->dev; 1244 writel_relaxed(bank->context.wake_en,
1289 struct device_node *node = dev->of_node; 1245 bank->base + bank->regs->wkup_en);
1290 const struct of_device_id *match; 1246 writel_relaxed(bank->context.ctrl, bank->base + bank->regs->ctrl);
1291 const struct omap_gpio_platform_data *pdata; 1247 writel_relaxed(bank->context.leveldetect0,
1292 struct resource *res; 1248 bank->base + bank->regs->leveldetect0);
1293 struct gpio_bank *bank; 1249 writel_relaxed(bank->context.leveldetect1,
1294 struct irq_chip *irqc; 1250 bank->base + bank->regs->leveldetect1);
1295 int ret; 1251 writel_relaxed(bank->context.risingdetect,
1296 1252 bank->base + bank->regs->risingdetect);
1297 match = of_match_device(of_match_ptr(omap_gpio_match), dev); 1253 writel_relaxed(bank->context.fallingdetect,
1298 1254 bank->base + bank->regs->fallingdetect);
1299 pdata = match ? match->data : dev_get_platdata(dev); 1255 if (bank->regs->set_dataout && bank->regs->clr_dataout)
1300 if (!pdata) 1256 writel_relaxed(bank->context.dataout,
1301 return -EINVAL; 1257 bank->base + bank->regs->set_dataout);
1302 1258 else
1303 bank = devm_kzalloc(dev, sizeof(*bank), GFP_KERNEL); 1259 writel_relaxed(bank->context.dataout,
1304 if (!bank) 1260 bank->base + bank->regs->dataout);
1305 return -ENOMEM; 1261 writel_relaxed(bank->context.oe, bank->base + bank->regs->direction);
1306
1307 irqc = devm_kzalloc(dev, sizeof(*irqc), GFP_KERNEL);
1308 if (!irqc)
1309 return -ENOMEM;
1310
1311 irqc->irq_startup = omap_gpio_irq_startup,
1312 irqc->irq_shutdown = omap_gpio_irq_shutdown,
1313 irqc->irq_ack = omap_gpio_ack_irq,
1314 irqc->irq_mask = omap_gpio_mask_irq,
1315 irqc->irq_unmask = omap_gpio_unmask_irq,
1316 irqc->irq_set_type = omap_gpio_irq_type,
1317 irqc->irq_set_wake = omap_gpio_wake_enable,
1318 irqc->irq_bus_lock = omap_gpio_irq_bus_lock,
1319 irqc->irq_bus_sync_unlock = gpio_irq_bus_sync_unlock,
1320 irqc->name = dev_name(&pdev->dev);
1321 irqc->flags = IRQCHIP_MASK_ON_SUSPEND;
1322 irqc->parent_device = dev;
1323
1324 bank->irq = platform_get_irq(pdev, 0);
1325 if (bank->irq <= 0) {
1326 if (!bank->irq)
1327 bank->irq = -ENXIO;
1328 if (bank->irq != -EPROBE_DEFER)
1329 dev_err(dev,
1330 "can't get irq resource ret=%d\n", bank->irq);
1331 return bank->irq;
1332 }
1333
1334 bank->chip.parent = dev;
1335 bank->chip.owner = THIS_MODULE;
1336 bank->dbck_flag = pdata->dbck_flag;
1337 bank->quirks = pdata->quirks;
1338 bank->stride = pdata->bank_stride;
1339 bank->width = pdata->bank_width;
1340 bank->is_mpuio = pdata->is_mpuio;
1341 bank->non_wakeup_gpios = pdata->non_wakeup_gpios;
1342 bank->regs = pdata->regs;
1343#ifdef CONFIG_OF_GPIO
1344 bank->chip.of_node = of_node_get(node);
1345#endif
1346
1347 if (node) {
1348 if (!of_property_read_bool(node, "ti,gpio-always-on"))
1349 bank->loses_context = true;
1350 } else {
1351 bank->loses_context = pdata->loses_context;
1352
1353 if (bank->loses_context)
1354 bank->get_context_loss_count =
1355 pdata->get_context_loss_count;
1356 }
1357
1358 if (bank->regs->set_dataout && bank->regs->clr_dataout) {
1359 bank->set_dataout = omap_set_gpio_dataout_reg;
1360 bank->set_dataout_multiple = omap_set_gpio_dataout_reg_multiple;
1361 } else {
1362 bank->set_dataout = omap_set_gpio_dataout_mask;
1363 bank->set_dataout_multiple =
1364 omap_set_gpio_dataout_mask_multiple;
1365 }
1366
1367 if (bank->quirks & OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER) {
1368 bank->funcs.idle_enable_level_quirk =
1369 omap2_gpio_enable_level_quirk;
1370 bank->funcs.idle_disable_level_quirk =
1371 omap2_gpio_disable_level_quirk;
1372 }
1373
1374 raw_spin_lock_init(&bank->lock);
1375 raw_spin_lock_init(&bank->wa_lock);
1376
1377 /* Static mapping, never released */
1378 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1379 bank->base = devm_ioremap_resource(dev, res);
1380 if (IS_ERR(bank->base)) {
1381 return PTR_ERR(bank->base);
1382 }
1383
1384 if (bank->dbck_flag) {
1385 bank->dbck = devm_clk_get(dev, "dbclk");
1386 if (IS_ERR(bank->dbck)) {
1387 dev_err(dev,
1388 "Could not get gpio dbck. Disable debounce\n");
1389 bank->dbck_flag = false;
1390 } else {
1391 clk_prepare(bank->dbck);
1392 }
1393 }
1394
1395 platform_set_drvdata(pdev, bank);
1396
1397 pm_runtime_enable(dev);
1398 pm_runtime_get_sync(dev);
1399
1400 if (bank->is_mpuio)
1401 omap_mpuio_init(bank);
1402
1403 omap_gpio_mod_init(bank);
1404
1405 ret = omap_gpio_chip_init(bank, irqc);
1406 if (ret) {
1407 pm_runtime_put_sync(dev);
1408 pm_runtime_disable(dev);
1409 if (bank->dbck_flag)
1410 clk_unprepare(bank->dbck);
1411 return ret;
1412 }
1413
1414 omap_gpio_show_rev(bank);
1415 1262
1416 if (bank->funcs.idle_enable_level_quirk && 1263 if (bank->dbck_enable_mask) {
1417 bank->funcs.idle_disable_level_quirk) { 1264 writel_relaxed(bank->context.debounce, bank->base +
1418 bank->nb.notifier_call = gpio_omap_cpu_notifier; 1265 bank->regs->debounce);
1419 cpu_pm_register_notifier(&bank->nb); 1266 writel_relaxed(bank->context.debounce_en,
1267 bank->base + bank->regs->debounce_en);
1420 } 1268 }
1421 1269
1422 pm_runtime_put(dev); 1270 writel_relaxed(bank->context.irqenable1,
1423 1271 bank->base + bank->regs->irqenable);
1424 return 0; 1272 writel_relaxed(bank->context.irqenable2,
1425} 1273 bank->base + bank->regs->irqenable2);
1426
1427static int omap_gpio_remove(struct platform_device *pdev)
1428{
1429 struct gpio_bank *bank = platform_get_drvdata(pdev);
1430
1431 if (bank->nb.notifier_call)
1432 cpu_pm_unregister_notifier(&bank->nb);
1433 list_del(&bank->node);
1434 gpiochip_remove(&bank->chip);
1435 pm_runtime_disable(&pdev->dev);
1436 if (bank->dbck_flag)
1437 clk_unprepare(bank->dbck);
1438
1439 return 0;
1440} 1274}
1441 1275
1442static void omap_gpio_restore_context(struct gpio_bank *bank);
1443
1444static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context) 1276static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context)
1445{ 1277{
1446 struct device *dev = bank->chip.parent; 1278 struct device *dev = bank->chip.parent;
1447 u32 l1 = 0, l2 = 0; 1279 void __iomem *base = bank->base;
1280 u32 nowake;
1448 1281
1449 if (bank->funcs.idle_enable_level_quirk) 1282 bank->saved_datain = readl_relaxed(base + bank->regs->datain);
1450 bank->funcs.idle_enable_level_quirk(bank);
1451 1283
1452 if (!bank->enabled_non_wakeup_gpios) 1284 if (!bank->enabled_non_wakeup_gpios)
1453 goto update_gpio_context_count; 1285 goto update_gpio_context_count;
@@ -1456,22 +1288,15 @@ static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context)
1456 goto update_gpio_context_count; 1288 goto update_gpio_context_count;
1457 1289
1458 /* 1290 /*
1459 * If going to OFF, remove triggering for all 1291 * If going to OFF, remove triggering for all wkup domain
1460 * non-wakeup GPIOs. Otherwise spurious IRQs will be 1292 * non-wakeup GPIOs. Otherwise spurious IRQs will be
1461 * generated. See OMAP2420 Errata item 1.101. 1293 * generated. See OMAP2420 Errata item 1.101.
1462 */ 1294 */
1463 bank->saved_datain = readl_relaxed(bank->base + 1295 if (!bank->loses_context && bank->enabled_non_wakeup_gpios) {
1464 bank->regs->datain); 1296 nowake = bank->enabled_non_wakeup_gpios;
1465 l1 = bank->context.fallingdetect; 1297 omap_gpio_rmw(base, bank->regs->fallingdetect, nowake, ~nowake);
1466 l2 = bank->context.risingdetect; 1298 omap_gpio_rmw(base, bank->regs->risingdetect, nowake, ~nowake);
1467 1299 }
1468 l1 &= ~bank->enabled_non_wakeup_gpios;
1469 l2 &= ~bank->enabled_non_wakeup_gpios;
1470
1471 writel_relaxed(l1, bank->base + bank->regs->fallingdetect);
1472 writel_relaxed(l2, bank->base + bank->regs->risingdetect);
1473
1474 bank->workaround_enabled = true;
1475 1300
1476update_gpio_context_count: 1301update_gpio_context_count:
1477 if (bank->get_context_loss_count) 1302 if (bank->get_context_loss_count)
@@ -1481,8 +1306,6 @@ update_gpio_context_count:
1481 omap_gpio_dbck_disable(bank); 1306 omap_gpio_dbck_disable(bank);
1482} 1307}
1483 1308
1484static void omap_gpio_init_context(struct gpio_bank *p);
1485
1486static void omap_gpio_unidle(struct gpio_bank *bank) 1309static void omap_gpio_unidle(struct gpio_bank *bank)
1487{ 1310{
1488 struct device *dev = bank->chip.parent; 1311 struct device *dev = bank->chip.parent;
@@ -1504,9 +1327,6 @@ static void omap_gpio_unidle(struct gpio_bank *bank)
1504 1327
1505 omap_gpio_dbck_enable(bank); 1328 omap_gpio_dbck_enable(bank);
1506 1329
1507 if (bank->funcs.idle_disable_level_quirk)
1508 bank->funcs.idle_disable_level_quirk(bank);
1509
1510 if (bank->loses_context) { 1330 if (bank->loses_context) {
1511 if (!bank->get_context_loss_count) { 1331 if (!bank->get_context_loss_count) {
1512 omap_gpio_restore_context(bank); 1332 omap_gpio_restore_context(bank);
@@ -1518,11 +1338,14 @@ static void omap_gpio_unidle(struct gpio_bank *bank)
1518 return; 1338 return;
1519 } 1339 }
1520 } 1340 }
1341 } else {
1342 /* Restore changes done for OMAP2420 errata 1.101 */
1343 writel_relaxed(bank->context.fallingdetect,
1344 bank->base + bank->regs->fallingdetect);
1345 writel_relaxed(bank->context.risingdetect,
1346 bank->base + bank->regs->risingdetect);
1521 } 1347 }
1522 1348
1523 if (!bank->workaround_enabled)
1524 return;
1525
1526 l = readl_relaxed(bank->base + bank->regs->datain); 1349 l = readl_relaxed(bank->base + bank->regs->datain);
1527 1350
1528 /* 1351 /*
@@ -1572,117 +1395,35 @@ static void omap_gpio_unidle(struct gpio_bank *bank)
1572 writel_relaxed(old0, bank->base + bank->regs->leveldetect0); 1395 writel_relaxed(old0, bank->base + bank->regs->leveldetect0);
1573 writel_relaxed(old1, bank->base + bank->regs->leveldetect1); 1396 writel_relaxed(old1, bank->base + bank->regs->leveldetect1);
1574 } 1397 }
1575
1576 bank->workaround_enabled = false;
1577}
1578
1579static void omap_gpio_init_context(struct gpio_bank *p)
1580{
1581 struct omap_gpio_reg_offs *regs = p->regs;
1582 void __iomem *base = p->base;
1583
1584 p->context.ctrl = readl_relaxed(base + regs->ctrl);
1585 p->context.oe = readl_relaxed(base + regs->direction);
1586 p->context.wake_en = readl_relaxed(base + regs->wkup_en);
1587 p->context.leveldetect0 = readl_relaxed(base + regs->leveldetect0);
1588 p->context.leveldetect1 = readl_relaxed(base + regs->leveldetect1);
1589 p->context.risingdetect = readl_relaxed(base + regs->risingdetect);
1590 p->context.fallingdetect = readl_relaxed(base + regs->fallingdetect);
1591 p->context.irqenable1 = readl_relaxed(base + regs->irqenable);
1592 p->context.irqenable2 = readl_relaxed(base + regs->irqenable2);
1593
1594 if (regs->set_dataout && p->regs->clr_dataout)
1595 p->context.dataout = readl_relaxed(base + regs->set_dataout);
1596 else
1597 p->context.dataout = readl_relaxed(base + regs->dataout);
1598
1599 p->context_valid = true;
1600}
1601
1602static void omap_gpio_restore_context(struct gpio_bank *bank)
1603{
1604 writel_relaxed(bank->context.wake_en,
1605 bank->base + bank->regs->wkup_en);
1606 writel_relaxed(bank->context.ctrl, bank->base + bank->regs->ctrl);
1607 writel_relaxed(bank->context.leveldetect0,
1608 bank->base + bank->regs->leveldetect0);
1609 writel_relaxed(bank->context.leveldetect1,
1610 bank->base + bank->regs->leveldetect1);
1611 writel_relaxed(bank->context.risingdetect,
1612 bank->base + bank->regs->risingdetect);
1613 writel_relaxed(bank->context.fallingdetect,
1614 bank->base + bank->regs->fallingdetect);
1615 if (bank->regs->set_dataout && bank->regs->clr_dataout)
1616 writel_relaxed(bank->context.dataout,
1617 bank->base + bank->regs->set_dataout);
1618 else
1619 writel_relaxed(bank->context.dataout,
1620 bank->base + bank->regs->dataout);
1621 writel_relaxed(bank->context.oe, bank->base + bank->regs->direction);
1622
1623 if (bank->dbck_enable_mask) {
1624 writel_relaxed(bank->context.debounce, bank->base +
1625 bank->regs->debounce);
1626 writel_relaxed(bank->context.debounce_en,
1627 bank->base + bank->regs->debounce_en);
1628 }
1629
1630 writel_relaxed(bank->context.irqenable1,
1631 bank->base + bank->regs->irqenable);
1632 writel_relaxed(bank->context.irqenable2,
1633 bank->base + bank->regs->irqenable2);
1634} 1398}
1635 1399
1636static int __maybe_unused omap_gpio_runtime_suspend(struct device *dev) 1400static int gpio_omap_cpu_notifier(struct notifier_block *nb,
1401 unsigned long cmd, void *v)
1637{ 1402{
1638 struct gpio_bank *bank = dev_get_drvdata(dev); 1403 struct gpio_bank *bank;
1639 unsigned long flags; 1404 unsigned long flags;
1640 int error = 0;
1641
1642 raw_spin_lock_irqsave(&bank->lock, flags);
1643 /* Must be idled only by CPU_CLUSTER_PM_ENTER? */
1644 if (bank->irq_usage) {
1645 error = -EBUSY;
1646 goto unlock;
1647 }
1648 omap_gpio_idle(bank, true);
1649 bank->is_suspended = true;
1650unlock:
1651 raw_spin_unlock_irqrestore(&bank->lock, flags);
1652
1653 return error;
1654}
1655 1405
1656static int __maybe_unused omap_gpio_runtime_resume(struct device *dev) 1406 bank = container_of(nb, struct gpio_bank, nb);
1657{
1658 struct gpio_bank *bank = dev_get_drvdata(dev);
1659 unsigned long flags;
1660 int error = 0;
1661 1407
1662 raw_spin_lock_irqsave(&bank->lock, flags); 1408 raw_spin_lock_irqsave(&bank->lock, flags);
1663 /* Must be unidled only by CPU_CLUSTER_PM_ENTER? */ 1409 switch (cmd) {
1664 if (bank->irq_usage) { 1410 case CPU_CLUSTER_PM_ENTER:
1665 error = -EBUSY; 1411 if (bank->is_suspended)
1666 goto unlock; 1412 break;
1413 omap_gpio_idle(bank, true);
1414 break;
1415 case CPU_CLUSTER_PM_ENTER_FAILED:
1416 case CPU_CLUSTER_PM_EXIT:
1417 if (bank->is_suspended)
1418 break;
1419 omap_gpio_unidle(bank);
1420 break;
1667 } 1421 }
1668 omap_gpio_unidle(bank);
1669 bank->is_suspended = false;
1670unlock:
1671 raw_spin_unlock_irqrestore(&bank->lock, flags); 1422 raw_spin_unlock_irqrestore(&bank->lock, flags);
1672 1423
1673 return error; 1424 return NOTIFY_OK;
1674} 1425}
1675 1426
1676#ifdef CONFIG_ARCH_OMAP2PLUS
1677static const struct dev_pm_ops gpio_pm_ops = {
1678 SET_RUNTIME_PM_OPS(omap_gpio_runtime_suspend, omap_gpio_runtime_resume,
1679 NULL)
1680};
1681#else
1682static const struct dev_pm_ops gpio_pm_ops;
1683#endif /* CONFIG_ARCH_OMAP2PLUS */
1684
1685#if defined(CONFIG_OF)
1686static struct omap_gpio_reg_offs omap2_gpio_regs = { 1427static struct omap_gpio_reg_offs omap2_gpio_regs = {
1687 .revision = OMAP24XX_GPIO_REVISION, 1428 .revision = OMAP24XX_GPIO_REVISION,
1688 .direction = OMAP24XX_GPIO_OE, 1429 .direction = OMAP24XX_GPIO_OE,
@@ -1729,11 +1470,6 @@ static struct omap_gpio_reg_offs omap4_gpio_regs = {
1729 .fallingdetect = OMAP4_GPIO_FALLINGDETECT, 1470 .fallingdetect = OMAP4_GPIO_FALLINGDETECT,
1730}; 1471};
1731 1472
1732/*
1733 * Note that omap2 does not currently support idle modes with context loss so
1734 * no need to add OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER quirk flag to save
1735 * and restore context.
1736 */
1737static const struct omap_gpio_platform_data omap2_pdata = { 1473static const struct omap_gpio_platform_data omap2_pdata = {
1738 .regs = &omap2_gpio_regs, 1474 .regs = &omap2_gpio_regs,
1739 .bank_width = 32, 1475 .bank_width = 32,
@@ -1744,14 +1480,12 @@ static const struct omap_gpio_platform_data omap3_pdata = {
1744 .regs = &omap2_gpio_regs, 1480 .regs = &omap2_gpio_regs,
1745 .bank_width = 32, 1481 .bank_width = 32,
1746 .dbck_flag = true, 1482 .dbck_flag = true,
1747 .quirks = OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER,
1748}; 1483};
1749 1484
1750static const struct omap_gpio_platform_data omap4_pdata = { 1485static const struct omap_gpio_platform_data omap4_pdata = {
1751 .regs = &omap4_gpio_regs, 1486 .regs = &omap4_gpio_regs,
1752 .bank_width = 32, 1487 .bank_width = 32,
1753 .dbck_flag = true, 1488 .dbck_flag = true,
1754 .quirks = OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER,
1755}; 1489};
1756 1490
1757static const struct of_device_id omap_gpio_match[] = { 1491static const struct of_device_id omap_gpio_match[] = {
@@ -1770,15 +1504,187 @@ static const struct of_device_id omap_gpio_match[] = {
1770 { }, 1504 { },
1771}; 1505};
1772MODULE_DEVICE_TABLE(of, omap_gpio_match); 1506MODULE_DEVICE_TABLE(of, omap_gpio_match);
1507
1508static int omap_gpio_probe(struct platform_device *pdev)
1509{
1510 struct device *dev = &pdev->dev;
1511 struct device_node *node = dev->of_node;
1512 const struct of_device_id *match;
1513 const struct omap_gpio_platform_data *pdata;
1514 struct gpio_bank *bank;
1515 struct irq_chip *irqc;
1516 int ret;
1517
1518 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
1519
1520 pdata = match ? match->data : dev_get_platdata(dev);
1521 if (!pdata)
1522 return -EINVAL;
1523
1524 bank = devm_kzalloc(dev, sizeof(*bank), GFP_KERNEL);
1525 if (!bank)
1526 return -ENOMEM;
1527
1528 irqc = devm_kzalloc(dev, sizeof(*irqc), GFP_KERNEL);
1529 if (!irqc)
1530 return -ENOMEM;
1531
1532 irqc->irq_startup = omap_gpio_irq_startup,
1533 irqc->irq_shutdown = omap_gpio_irq_shutdown,
1534 irqc->irq_ack = omap_gpio_ack_irq,
1535 irqc->irq_mask = omap_gpio_mask_irq,
1536 irqc->irq_unmask = omap_gpio_unmask_irq,
1537 irqc->irq_set_type = omap_gpio_irq_type,
1538 irqc->irq_set_wake = omap_gpio_wake_enable,
1539 irqc->irq_bus_lock = omap_gpio_irq_bus_lock,
1540 irqc->irq_bus_sync_unlock = gpio_irq_bus_sync_unlock,
1541 irqc->name = dev_name(&pdev->dev);
1542 irqc->flags = IRQCHIP_MASK_ON_SUSPEND;
1543 irqc->parent_device = dev;
1544
1545 bank->irq = platform_get_irq(pdev, 0);
1546 if (bank->irq <= 0) {
1547 if (!bank->irq)
1548 bank->irq = -ENXIO;
1549 if (bank->irq != -EPROBE_DEFER)
1550 dev_err(dev,
1551 "can't get irq resource ret=%d\n", bank->irq);
1552 return bank->irq;
1553 }
1554
1555 bank->chip.parent = dev;
1556 bank->chip.owner = THIS_MODULE;
1557 bank->dbck_flag = pdata->dbck_flag;
1558 bank->stride = pdata->bank_stride;
1559 bank->width = pdata->bank_width;
1560 bank->is_mpuio = pdata->is_mpuio;
1561 bank->non_wakeup_gpios = pdata->non_wakeup_gpios;
1562 bank->regs = pdata->regs;
1563#ifdef CONFIG_OF_GPIO
1564 bank->chip.of_node = of_node_get(node);
1773#endif 1565#endif
1774 1566
1567 if (node) {
1568 if (!of_property_read_bool(node, "ti,gpio-always-on"))
1569 bank->loses_context = true;
1570 } else {
1571 bank->loses_context = pdata->loses_context;
1572
1573 if (bank->loses_context)
1574 bank->get_context_loss_count =
1575 pdata->get_context_loss_count;
1576 }
1577
1578 if (bank->regs->set_dataout && bank->regs->clr_dataout) {
1579 bank->set_dataout = omap_set_gpio_dataout_reg;
1580 bank->set_dataout_multiple = omap_set_gpio_dataout_reg_multiple;
1581 } else {
1582 bank->set_dataout = omap_set_gpio_dataout_mask;
1583 bank->set_dataout_multiple =
1584 omap_set_gpio_dataout_mask_multiple;
1585 }
1586
1587 raw_spin_lock_init(&bank->lock);
1588 raw_spin_lock_init(&bank->wa_lock);
1589
1590 /* Static mapping, never released */
1591 bank->base = devm_platform_ioremap_resource(pdev, 0);
1592 if (IS_ERR(bank->base)) {
1593 return PTR_ERR(bank->base);
1594 }
1595
1596 if (bank->dbck_flag) {
1597 bank->dbck = devm_clk_get(dev, "dbclk");
1598 if (IS_ERR(bank->dbck)) {
1599 dev_err(dev,
1600 "Could not get gpio dbck. Disable debounce\n");
1601 bank->dbck_flag = false;
1602 } else {
1603 clk_prepare(bank->dbck);
1604 }
1605 }
1606
1607 platform_set_drvdata(pdev, bank);
1608
1609 pm_runtime_enable(dev);
1610 pm_runtime_get_sync(dev);
1611
1612 if (bank->is_mpuio)
1613 omap_mpuio_init(bank);
1614
1615 omap_gpio_mod_init(bank);
1616
1617 ret = omap_gpio_chip_init(bank, irqc);
1618 if (ret) {
1619 pm_runtime_put_sync(dev);
1620 pm_runtime_disable(dev);
1621 if (bank->dbck_flag)
1622 clk_unprepare(bank->dbck);
1623 return ret;
1624 }
1625
1626 omap_gpio_show_rev(bank);
1627
1628 bank->nb.notifier_call = gpio_omap_cpu_notifier;
1629 cpu_pm_register_notifier(&bank->nb);
1630
1631 pm_runtime_put(dev);
1632
1633 return 0;
1634}
1635
1636static int omap_gpio_remove(struct platform_device *pdev)
1637{
1638 struct gpio_bank *bank = platform_get_drvdata(pdev);
1639
1640 cpu_pm_unregister_notifier(&bank->nb);
1641 list_del(&bank->node);
1642 gpiochip_remove(&bank->chip);
1643 pm_runtime_disable(&pdev->dev);
1644 if (bank->dbck_flag)
1645 clk_unprepare(bank->dbck);
1646
1647 return 0;
1648}
1649
1650static int __maybe_unused omap_gpio_runtime_suspend(struct device *dev)
1651{
1652 struct gpio_bank *bank = dev_get_drvdata(dev);
1653 unsigned long flags;
1654
1655 raw_spin_lock_irqsave(&bank->lock, flags);
1656 omap_gpio_idle(bank, true);
1657 bank->is_suspended = true;
1658 raw_spin_unlock_irqrestore(&bank->lock, flags);
1659
1660 return 0;
1661}
1662
1663static int __maybe_unused omap_gpio_runtime_resume(struct device *dev)
1664{
1665 struct gpio_bank *bank = dev_get_drvdata(dev);
1666 unsigned long flags;
1667
1668 raw_spin_lock_irqsave(&bank->lock, flags);
1669 omap_gpio_unidle(bank);
1670 bank->is_suspended = false;
1671 raw_spin_unlock_irqrestore(&bank->lock, flags);
1672
1673 return 0;
1674}
1675
1676static const struct dev_pm_ops gpio_pm_ops = {
1677 SET_RUNTIME_PM_OPS(omap_gpio_runtime_suspend, omap_gpio_runtime_resume,
1678 NULL)
1679};
1680
1775static struct platform_driver omap_gpio_driver = { 1681static struct platform_driver omap_gpio_driver = {
1776 .probe = omap_gpio_probe, 1682 .probe = omap_gpio_probe,
1777 .remove = omap_gpio_remove, 1683 .remove = omap_gpio_remove,
1778 .driver = { 1684 .driver = {
1779 .name = "omap_gpio", 1685 .name = "omap_gpio",
1780 .pm = &gpio_pm_ops, 1686 .pm = &gpio_pm_ops,
1781 .of_match_table = of_match_ptr(omap_gpio_match), 1687 .of_match_table = omap_gpio_match,
1782 }, 1688 },
1783}; 1689};
1784 1690
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 7e76830b3368..b7ef33f63392 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -73,6 +73,7 @@
73#define PCA_CHIP_TYPE(x) ((x) & PCA_TYPE_MASK) 73#define PCA_CHIP_TYPE(x) ((x) & PCA_TYPE_MASK)
74 74
75static const struct i2c_device_id pca953x_id[] = { 75static const struct i2c_device_id pca953x_id[] = {
76 { "pca6416", 16 | PCA953X_TYPE | PCA_INT, },
76 { "pca9505", 40 | PCA953X_TYPE | PCA_INT, }, 77 { "pca9505", 40 | PCA953X_TYPE | PCA_INT, },
77 { "pca9534", 8 | PCA953X_TYPE | PCA_INT, }, 78 { "pca9534", 8 | PCA953X_TYPE | PCA_INT, },
78 { "pca9535", 16 | PCA953X_TYPE | PCA_INT, }, 79 { "pca9535", 16 | PCA953X_TYPE | PCA_INT, },
@@ -153,6 +154,7 @@ struct pca953x_chip {
153 u8 irq_trig_fall[MAX_BANK]; 154 u8 irq_trig_fall[MAX_BANK];
154 struct irq_chip irq_chip; 155 struct irq_chip irq_chip;
155#endif 156#endif
157 atomic_t wakeup_path;
156 158
157 struct i2c_client *client; 159 struct i2c_client *client;
158 struct gpio_chip gpio_chip; 160 struct gpio_chip gpio_chip;
@@ -581,6 +583,11 @@ static int pca953x_irq_set_wake(struct irq_data *d, unsigned int on)
581 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 583 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
582 struct pca953x_chip *chip = gpiochip_get_data(gc); 584 struct pca953x_chip *chip = gpiochip_get_data(gc);
583 585
586 if (on)
587 atomic_inc(&chip->wakeup_path);
588 else
589 atomic_dec(&chip->wakeup_path);
590
584 return irq_set_irq_wake(chip->client->irq, on); 591 return irq_set_irq_wake(chip->client->irq, on);
585} 592}
586 593
@@ -1100,7 +1107,10 @@ static int pca953x_suspend(struct device *dev)
1100 1107
1101 regcache_cache_only(chip->regmap, true); 1108 regcache_cache_only(chip->regmap, true);
1102 1109
1103 regulator_disable(chip->regulator); 1110 if (atomic_read(&chip->wakeup_path))
1111 device_set_wakeup_path(dev);
1112 else
1113 regulator_disable(chip->regulator);
1104 1114
1105 return 0; 1115 return 0;
1106} 1116}
@@ -1110,10 +1120,12 @@ static int pca953x_resume(struct device *dev)
1110 struct pca953x_chip *chip = dev_get_drvdata(dev); 1120 struct pca953x_chip *chip = dev_get_drvdata(dev);
1111 int ret; 1121 int ret;
1112 1122
1113 ret = regulator_enable(chip->regulator); 1123 if (!atomic_read(&chip->wakeup_path)) {
1114 if (ret != 0) { 1124 ret = regulator_enable(chip->regulator);
1115 dev_err(dev, "Failed to enable regulator: %d\n", ret); 1125 if (ret != 0) {
1116 return 0; 1126 dev_err(dev, "Failed to enable regulator: %d\n", ret);
1127 return 0;
1128 }
1117 } 1129 }
1118 1130
1119 regcache_cache_only(chip->regmap, false); 1131 regcache_cache_only(chip->regmap, false);
@@ -1137,6 +1149,7 @@ static int pca953x_resume(struct device *dev)
1137#define OF_957X(__nrgpio, __int) (void *)(__nrgpio | PCA957X_TYPE | __int) 1149#define OF_957X(__nrgpio, __int) (void *)(__nrgpio | PCA957X_TYPE | __int)
1138 1150
1139static const struct of_device_id pca953x_dt_ids[] = { 1151static const struct of_device_id pca953x_dt_ids[] = {
1152 { .compatible = "nxp,pca6416", .data = OF_953X(16, PCA_INT), },
1140 { .compatible = "nxp,pca9505", .data = OF_953X(40, PCA_INT), }, 1153 { .compatible = "nxp,pca9505", .data = OF_953X(40, PCA_INT), },
1141 { .compatible = "nxp,pca9534", .data = OF_953X( 8, PCA_INT), }, 1154 { .compatible = "nxp,pca9534", .data = OF_953X( 8, PCA_INT), },
1142 { .compatible = "nxp,pca9535", .data = OF_953X(16, PCA_INT), }, 1155 { .compatible = "nxp,pca9535", .data = OF_953X(16, PCA_INT), },
@@ -1152,6 +1165,7 @@ static const struct of_device_id pca953x_dt_ids[] = {
1152 { .compatible = "nxp,pca9575", .data = OF_957X(16, PCA_INT), }, 1165 { .compatible = "nxp,pca9575", .data = OF_957X(16, PCA_INT), },
1153 { .compatible = "nxp,pca9698", .data = OF_953X(40, 0), }, 1166 { .compatible = "nxp,pca9698", .data = OF_953X(40, 0), },
1154 1167
1168 { .compatible = "nxp,pcal6416", .data = OF_953X(16, PCA_LATCH_INT), },
1155 { .compatible = "nxp,pcal6524", .data = OF_953X(24, PCA_LATCH_INT), }, 1169 { .compatible = "nxp,pcal6524", .data = OF_953X(24, PCA_LATCH_INT), },
1156 { .compatible = "nxp,pcal9555a", .data = OF_953X(16, PCA_LATCH_INT), }, 1170 { .compatible = "nxp,pcal9555a", .data = OF_953X(16, PCA_LATCH_INT), },
1157 1171
@@ -1167,6 +1181,7 @@ static const struct of_device_id pca953x_dt_ids[] = {
1167 { .compatible = "ti,tca6416", .data = OF_953X(16, PCA_INT), }, 1181 { .compatible = "ti,tca6416", .data = OF_953X(16, PCA_INT), },
1168 { .compatible = "ti,tca6424", .data = OF_953X(24, PCA_INT), }, 1182 { .compatible = "ti,tca6424", .data = OF_953X(24, PCA_INT), },
1169 1183
1184 { .compatible = "onnn,cat9554", .data = OF_953X( 8, PCA_INT), },
1170 { .compatible = "onnn,pca9654", .data = OF_953X( 8, PCA_INT), }, 1185 { .compatible = "onnn,pca9654", .data = OF_953X( 8, PCA_INT), },
1171 1186
1172 { .compatible = "exar,xra1202", .data = OF_953X( 8, 0), }, 1187 { .compatible = "exar,xra1202", .data = OF_953X( 8, 0), },
diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index bcc6be4a5cb2..26f77fdb217e 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -577,7 +577,7 @@ static int pxa_irq_domain_map(struct irq_domain *d, unsigned int irq,
577 return 0; 577 return 0;
578} 578}
579 579
580const struct irq_domain_ops pxa_irq_domain_ops = { 580static const struct irq_domain_ops pxa_irq_domain_ops = {
581 .map = pxa_irq_domain_map, 581 .map = pxa_irq_domain_map,
582 .xlate = irq_domain_xlate_twocell, 582 .xlate = irq_domain_xlate_twocell,
583}; 583};
@@ -622,7 +622,6 @@ static int pxa_gpio_probe(struct platform_device *pdev)
622{ 622{
623 struct pxa_gpio_chip *pchip; 623 struct pxa_gpio_chip *pchip;
624 struct pxa_gpio_bank *c; 624 struct pxa_gpio_bank *c;
625 struct resource *res;
626 struct clk *clk; 625 struct clk *clk;
627 struct pxa_gpio_platform_data *info; 626 struct pxa_gpio_platform_data *info;
628 void __iomem *gpio_reg_base; 627 void __iomem *gpio_reg_base;
@@ -665,11 +664,8 @@ static int pxa_gpio_probe(struct platform_device *pdev)
665 664
666 pchip->irq0 = irq0; 665 pchip->irq0 = irq0;
667 pchip->irq1 = irq1; 666 pchip->irq1 = irq1;
668 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 667
669 if (!res) 668 gpio_reg_base = devm_platform_ioremap_resource(pdev, 0);
670 return -EINVAL;
671 gpio_reg_base = devm_ioremap(&pdev->dev, res->start,
672 resource_size(res));
673 if (!gpio_reg_base) 669 if (!gpio_reg_base)
674 return -EINVAL; 670 return -EINVAL;
675 671
@@ -816,7 +812,7 @@ static void pxa_gpio_resume(void)
816#define pxa_gpio_resume NULL 812#define pxa_gpio_resume NULL
817#endif 813#endif
818 814
819struct syscore_ops pxa_gpio_syscore_ops = { 815static struct syscore_ops pxa_gpio_syscore_ops = {
820 .suspend = pxa_gpio_suspend, 816 .suspend = pxa_gpio_suspend,
821 .resume = pxa_gpio_resume, 817 .resume = pxa_gpio_resume,
822}; 818};
diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
index 500a3596aaf4..70e95fc4779f 100644
--- a/drivers/gpio/gpio-rcar.c
+++ b/drivers/gpio/gpio-rcar.c
@@ -430,7 +430,7 @@ static int gpio_rcar_parse_dt(struct gpio_rcar_priv *p, unsigned int *npins)
430static int gpio_rcar_probe(struct platform_device *pdev) 430static int gpio_rcar_probe(struct platform_device *pdev)
431{ 431{
432 struct gpio_rcar_priv *p; 432 struct gpio_rcar_priv *p;
433 struct resource *io, *irq; 433 struct resource *irq;
434 struct gpio_chip *gpio_chip; 434 struct gpio_chip *gpio_chip;
435 struct irq_chip *irq_chip; 435 struct irq_chip *irq_chip;
436 struct device *dev = &pdev->dev; 436 struct device *dev = &pdev->dev;
@@ -461,8 +461,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
461 goto err0; 461 goto err0;
462 } 462 }
463 463
464 io = platform_get_resource(pdev, IORESOURCE_MEM, 0); 464 p->base = devm_platform_ioremap_resource(pdev, 0);
465 p->base = devm_ioremap_resource(dev, io);
466 if (IS_ERR(p->base)) { 465 if (IS_ERR(p->base)) {
467 ret = PTR_ERR(p->base); 466 ret = PTR_ERR(p->base);
468 goto err0; 467 goto err0;
diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c
index c333046d02b8..fb143f28c386 100644
--- a/drivers/gpio/gpio-sch.c
+++ b/drivers/gpio/gpio-sch.c
@@ -23,7 +23,6 @@ struct sch_gpio {
23 struct gpio_chip chip; 23 struct gpio_chip chip;
24 spinlock_t lock; 24 spinlock_t lock;
25 unsigned short iobase; 25 unsigned short iobase;
26 unsigned short core_base;
27 unsigned short resume_base; 26 unsigned short resume_base;
28}; 27};
29 28
@@ -166,7 +165,6 @@ static int sch_gpio_probe(struct platform_device *pdev)
166 165
167 switch (pdev->id) { 166 switch (pdev->id) {
168 case PCI_DEVICE_ID_INTEL_SCH_LPC: 167 case PCI_DEVICE_ID_INTEL_SCH_LPC:
169 sch->core_base = 0;
170 sch->resume_base = 10; 168 sch->resume_base = 10;
171 sch->chip.ngpio = 14; 169 sch->chip.ngpio = 14;
172 170
@@ -185,19 +183,16 @@ static int sch_gpio_probe(struct platform_device *pdev)
185 break; 183 break;
186 184
187 case PCI_DEVICE_ID_INTEL_ITC_LPC: 185 case PCI_DEVICE_ID_INTEL_ITC_LPC:
188 sch->core_base = 0;
189 sch->resume_base = 5; 186 sch->resume_base = 5;
190 sch->chip.ngpio = 14; 187 sch->chip.ngpio = 14;
191 break; 188 break;
192 189
193 case PCI_DEVICE_ID_INTEL_CENTERTON_ILB: 190 case PCI_DEVICE_ID_INTEL_CENTERTON_ILB:
194 sch->core_base = 0;
195 sch->resume_base = 21; 191 sch->resume_base = 21;
196 sch->chip.ngpio = 30; 192 sch->chip.ngpio = 30;
197 break; 193 break;
198 194
199 case PCI_DEVICE_ID_INTEL_QUARK_X1000_ILB: 195 case PCI_DEVICE_ID_INTEL_QUARK_X1000_ILB:
200 sch->core_base = 0;
201 sch->resume_base = 2; 196 sch->resume_base = 2;
202 sch->chip.ngpio = 8; 197 sch->chip.ngpio = 8;
203 break; 198 break;
diff --git a/drivers/gpio/gpio-spear-spics.c b/drivers/gpio/gpio-spear-spics.c
index ee3039f091f4..6eca531b7d96 100644
--- a/drivers/gpio/gpio-spear-spics.c
+++ b/drivers/gpio/gpio-spear-spics.c
@@ -122,15 +122,13 @@ static int spics_gpio_probe(struct platform_device *pdev)
122{ 122{
123 struct device_node *np = pdev->dev.of_node; 123 struct device_node *np = pdev->dev.of_node;
124 struct spear_spics *spics; 124 struct spear_spics *spics;
125 struct resource *res;
126 int ret; 125 int ret;
127 126
128 spics = devm_kzalloc(&pdev->dev, sizeof(*spics), GFP_KERNEL); 127 spics = devm_kzalloc(&pdev->dev, sizeof(*spics), GFP_KERNEL);
129 if (!spics) 128 if (!spics)
130 return -ENOMEM; 129 return -ENOMEM;
131 130
132 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 131 spics->base = devm_platform_ioremap_resource(pdev, 0);
133 spics->base = devm_ioremap_resource(&pdev->dev, res);
134 if (IS_ERR(spics->base)) 132 if (IS_ERR(spics->base))
135 return PTR_ERR(spics->base); 133 return PTR_ERR(spics->base);
136 134
diff --git a/drivers/gpio/gpio-sprd.c b/drivers/gpio/gpio-sprd.c
index 55072d2b367f..f5c8b3a351d5 100644
--- a/drivers/gpio/gpio-sprd.c
+++ b/drivers/gpio/gpio-sprd.c
@@ -219,7 +219,6 @@ static int sprd_gpio_probe(struct platform_device *pdev)
219{ 219{
220 struct gpio_irq_chip *irq; 220 struct gpio_irq_chip *irq;
221 struct sprd_gpio *sprd_gpio; 221 struct sprd_gpio *sprd_gpio;
222 struct resource *res;
223 int ret; 222 int ret;
224 223
225 sprd_gpio = devm_kzalloc(&pdev->dev, sizeof(*sprd_gpio), GFP_KERNEL); 224 sprd_gpio = devm_kzalloc(&pdev->dev, sizeof(*sprd_gpio), GFP_KERNEL);
@@ -232,8 +231,7 @@ static int sprd_gpio_probe(struct platform_device *pdev)
232 return sprd_gpio->irq; 231 return sprd_gpio->irq;
233 } 232 }
234 233
235 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 234 sprd_gpio->base = devm_platform_ioremap_resource(pdev, 0);
236 sprd_gpio->base = devm_ioremap_resource(&pdev->dev, res);
237 if (IS_ERR(sprd_gpio->base)) 235 if (IS_ERR(sprd_gpio->base))
238 return PTR_ERR(sprd_gpio->base); 236 return PTR_ERR(sprd_gpio->base);
239 237
diff --git a/drivers/gpio/gpio-sta2x11.c b/drivers/gpio/gpio-sta2x11.c
index 2283c869ad5d..a51c310708b8 100644
--- a/drivers/gpio/gpio-sta2x11.c
+++ b/drivers/gpio/gpio-sta2x11.c
@@ -360,7 +360,6 @@ static int gsta_probe(struct platform_device *dev)
360 struct pci_dev *pdev; 360 struct pci_dev *pdev;
361 struct sta2x11_gpio_pdata *gpio_pdata; 361 struct sta2x11_gpio_pdata *gpio_pdata;
362 struct gsta_gpio *chip; 362 struct gsta_gpio *chip;
363 struct resource *res;
364 363
365 pdev = *(struct pci_dev **)dev_get_platdata(&dev->dev); 364 pdev = *(struct pci_dev **)dev_get_platdata(&dev->dev);
366 gpio_pdata = dev_get_platdata(&pdev->dev); 365 gpio_pdata = dev_get_platdata(&pdev->dev);
@@ -369,13 +368,11 @@ static int gsta_probe(struct platform_device *dev)
369 dev_err(&dev->dev, "no gpio config\n"); 368 dev_err(&dev->dev, "no gpio config\n");
370 pr_debug("gpio config: %p\n", gpio_pdata); 369 pr_debug("gpio config: %p\n", gpio_pdata);
371 370
372 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
373
374 chip = devm_kzalloc(&dev->dev, sizeof(*chip), GFP_KERNEL); 371 chip = devm_kzalloc(&dev->dev, sizeof(*chip), GFP_KERNEL);
375 if (!chip) 372 if (!chip)
376 return -ENOMEM; 373 return -ENOMEM;
377 chip->dev = &dev->dev; 374 chip->dev = &dev->dev;
378 chip->reg_base = devm_ioremap_resource(&dev->dev, res); 375 chip->reg_base = devm_platform_ioremap_resource(dev, 0);
379 if (IS_ERR(chip->reg_base)) 376 if (IS_ERR(chip->reg_base))
380 return PTR_ERR(chip->reg_base); 377 return PTR_ERR(chip->reg_base);
381 378
diff --git a/drivers/gpio/gpio-stp-xway.c b/drivers/gpio/gpio-stp-xway.c
index 19972084c45b..8a319d56c5de 100644
--- a/drivers/gpio/gpio-stp-xway.c
+++ b/drivers/gpio/gpio-stp-xway.c
@@ -210,7 +210,6 @@ static int xway_stp_hw_init(struct xway_stp *chip)
210 210
211static int xway_stp_probe(struct platform_device *pdev) 211static int xway_stp_probe(struct platform_device *pdev)
212{ 212{
213 struct resource *res;
214 u32 shadow, groups, dsl, phy; 213 u32 shadow, groups, dsl, phy;
215 struct xway_stp *chip; 214 struct xway_stp *chip;
216 struct clk *clk; 215 struct clk *clk;
@@ -220,8 +219,7 @@ static int xway_stp_probe(struct platform_device *pdev)
220 if (!chip) 219 if (!chip)
221 return -ENOMEM; 220 return -ENOMEM;
222 221
223 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 222 chip->virt = devm_platform_ioremap_resource(pdev, 0);
224 chip->virt = devm_ioremap_resource(&pdev->dev, res);
225 if (IS_ERR(chip->virt)) 223 if (IS_ERR(chip->virt))
226 return PTR_ERR(chip->virt); 224 return PTR_ERR(chip->virt);
227 225
diff --git a/drivers/gpio/gpio-tb10x.c b/drivers/gpio/gpio-tb10x.c
index d5e5d19f4c0a..6bbac6c83f29 100644
--- a/drivers/gpio/gpio-tb10x.c
+++ b/drivers/gpio/gpio-tb10x.c
@@ -120,7 +120,6 @@ static irqreturn_t tb10x_gpio_irq_cascade(int irq, void *data)
120static int tb10x_gpio_probe(struct platform_device *pdev) 120static int tb10x_gpio_probe(struct platform_device *pdev)
121{ 121{
122 struct tb10x_gpio *tb10x_gpio; 122 struct tb10x_gpio *tb10x_gpio;
123 struct resource *mem;
124 struct device *dev = &pdev->dev; 123 struct device *dev = &pdev->dev;
125 struct device_node *np = dev->of_node; 124 struct device_node *np = dev->of_node;
126 int ret = -EBUSY; 125 int ret = -EBUSY;
@@ -136,8 +135,7 @@ static int tb10x_gpio_probe(struct platform_device *pdev)
136 if (tb10x_gpio == NULL) 135 if (tb10x_gpio == NULL)
137 return -ENOMEM; 136 return -ENOMEM;
138 137
139 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 138 tb10x_gpio->base = devm_platform_ioremap_resource(pdev, 0);
140 tb10x_gpio->base = devm_ioremap_resource(dev, mem);
141 if (IS_ERR(tb10x_gpio->base)) 139 if (IS_ERR(tb10x_gpio->base))
142 return PTR_ERR(tb10x_gpio->base); 140 return PTR_ERR(tb10x_gpio->base);
143 141
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 1ececf2c3282..6d9b6906b9d0 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -569,7 +569,6 @@ static const struct dev_pm_ops tegra_gpio_pm_ops = {
569static int tegra_gpio_probe(struct platform_device *pdev) 569static int tegra_gpio_probe(struct platform_device *pdev)
570{ 570{
571 struct tegra_gpio_info *tgi; 571 struct tegra_gpio_info *tgi;
572 struct resource *res;
573 struct tegra_gpio_bank *bank; 572 struct tegra_gpio_bank *bank;
574 unsigned int gpio, i, j; 573 unsigned int gpio, i, j;
575 int ret; 574 int ret;
@@ -645,8 +644,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)
645 bank->tgi = tgi; 644 bank->tgi = tgi;
646 } 645 }
647 646
648 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 647 tgi->regs = devm_platform_ioremap_resource(pdev, 0);
649 tgi->regs = devm_ioremap_resource(&pdev->dev, res);
650 if (IS_ERR(tgi->regs)) 648 if (IS_ERR(tgi->regs))
651 return PTR_ERR(tgi->regs); 649 return PTR_ERR(tgi->regs);
652 650
diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdale.c
index 314e300d6ba3..1c70e831069c 100644
--- a/drivers/gpio/gpio-timberdale.c
+++ b/drivers/gpio/gpio-timberdale.c
@@ -229,7 +229,6 @@ static int timbgpio_probe(struct platform_device *pdev)
229 struct device *dev = &pdev->dev; 229 struct device *dev = &pdev->dev;
230 struct gpio_chip *gc; 230 struct gpio_chip *gc;
231 struct timbgpio *tgpio; 231 struct timbgpio *tgpio;
232 struct resource *iomem;
233 struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev); 232 struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
234 int irq = platform_get_irq(pdev, 0); 233 int irq = platform_get_irq(pdev, 0);
235 234
@@ -246,8 +245,7 @@ static int timbgpio_probe(struct platform_device *pdev)
246 245
247 spin_lock_init(&tgpio->lock); 246 spin_lock_init(&tgpio->lock);
248 247
249 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 248 tgpio->membase = devm_platform_ioremap_resource(pdev, 0);
250 tgpio->membase = devm_ioremap_resource(dev, iomem);
251 if (IS_ERR(tgpio->membase)) 249 if (IS_ERR(tgpio->membase))
252 return PTR_ERR(tgpio->membase); 250 return PTR_ERR(tgpio->membase);
253 251
diff --git a/drivers/gpio/gpio-ts4800.c b/drivers/gpio/gpio-ts4800.c
index c2a80b4cbf32..8c0d82d926dd 100644
--- a/drivers/gpio/gpio-ts4800.c
+++ b/drivers/gpio/gpio-ts4800.c
@@ -23,7 +23,6 @@ static int ts4800_gpio_probe(struct platform_device *pdev)
23{ 23{
24 struct device_node *node; 24 struct device_node *node;
25 struct gpio_chip *chip; 25 struct gpio_chip *chip;
26 struct resource *res;
27 void __iomem *base_addr; 26 void __iomem *base_addr;
28 int retval; 27 int retval;
29 u32 ngpios; 28 u32 ngpios;
@@ -32,8 +31,7 @@ static int ts4800_gpio_probe(struct platform_device *pdev)
32 if (!chip) 31 if (!chip)
33 return -ENOMEM; 32 return -ENOMEM;
34 33
35 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 34 base_addr = devm_platform_ioremap_resource(pdev, 0);
36 base_addr = devm_ioremap_resource(&pdev->dev, res);
37 if (IS_ERR(base_addr)) 35 if (IS_ERR(base_addr))
38 return PTR_ERR(base_addr); 36 return PTR_ERR(base_addr);
39 37
diff --git a/drivers/gpio/gpio-uniphier.c b/drivers/gpio/gpio-uniphier.c
index 0f662b297a95..93cdcc41e9fb 100644
--- a/drivers/gpio/gpio-uniphier.c
+++ b/drivers/gpio/gpio-uniphier.c
@@ -346,7 +346,6 @@ static int uniphier_gpio_probe(struct platform_device *pdev)
346 struct uniphier_gpio_priv *priv; 346 struct uniphier_gpio_priv *priv;
347 struct gpio_chip *chip; 347 struct gpio_chip *chip;
348 struct irq_chip *irq_chip; 348 struct irq_chip *irq_chip;
349 struct resource *regs;
350 unsigned int nregs; 349 unsigned int nregs;
351 u32 ngpios; 350 u32 ngpios;
352 int ret; 351 int ret;
@@ -370,8 +369,7 @@ static int uniphier_gpio_probe(struct platform_device *pdev)
370 if (!priv) 369 if (!priv)
371 return -ENOMEM; 370 return -ENOMEM;
372 371
373 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 372 priv->regs = devm_platform_ioremap_resource(pdev, 0);
374 priv->regs = devm_ioremap_resource(dev, regs);
375 if (IS_ERR(priv->regs)) 373 if (IS_ERR(priv->regs))
376 return PTR_ERR(priv->regs); 374 return PTR_ERR(priv->regs);
377 375
diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 541fa6ac399d..30aef41e3b7e 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -29,6 +29,7 @@ struct fsl_gpio_soc_data {
29 29
30struct vf610_gpio_port { 30struct vf610_gpio_port {
31 struct gpio_chip gc; 31 struct gpio_chip gc;
32 struct irq_chip ic;
32 void __iomem *base; 33 void __iomem *base;
33 void __iomem *gpio_base; 34 void __iomem *gpio_base;
34 const struct fsl_gpio_soc_data *sdata; 35 const struct fsl_gpio_soc_data *sdata;
@@ -60,8 +61,6 @@ struct vf610_gpio_port {
60#define PORT_INT_EITHER_EDGE 0xb 61#define PORT_INT_EITHER_EDGE 0xb
61#define PORT_INT_LOGIC_ONE 0xc 62#define PORT_INT_LOGIC_ONE 0xc
62 63
63static struct irq_chip vf610_gpio_irq_chip;
64
65static const struct fsl_gpio_soc_data imx_data = { 64static const struct fsl_gpio_soc_data imx_data = {
66 .have_paddr = true, 65 .have_paddr = true,
67}; 66};
@@ -86,28 +85,24 @@ static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio)
86{ 85{
87 struct vf610_gpio_port *port = gpiochip_get_data(gc); 86 struct vf610_gpio_port *port = gpiochip_get_data(gc);
88 unsigned long mask = BIT(gpio); 87 unsigned long mask = BIT(gpio);
89 void __iomem *addr; 88 unsigned long offset = GPIO_PDIR;
90 89
91 if (port->sdata && port->sdata->have_paddr) { 90 if (port->sdata && port->sdata->have_paddr) {
92 mask &= vf610_gpio_readl(port->gpio_base + GPIO_PDDR); 91 mask &= vf610_gpio_readl(port->gpio_base + GPIO_PDDR);
93 addr = mask ? port->gpio_base + GPIO_PDOR : 92 if (mask)
94 port->gpio_base + GPIO_PDIR; 93 offset = GPIO_PDOR;
95 return !!(vf610_gpio_readl(addr) & BIT(gpio));
96 } else {
97 return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR)
98 & BIT(gpio));
99 } 94 }
95
96 return !!(vf610_gpio_readl(port->gpio_base + offset) & BIT(gpio));
100} 97}
101 98
102static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 99static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
103{ 100{
104 struct vf610_gpio_port *port = gpiochip_get_data(gc); 101 struct vf610_gpio_port *port = gpiochip_get_data(gc);
105 unsigned long mask = BIT(gpio); 102 unsigned long mask = BIT(gpio);
103 unsigned long offset = val ? GPIO_PSOR : GPIO_PCOR;
106 104
107 if (val) 105 vf610_gpio_writel(mask, port->gpio_base + offset);
108 vf610_gpio_writel(mask, port->gpio_base + GPIO_PSOR);
109 else
110 vf610_gpio_writel(mask, port->gpio_base + GPIO_PCOR);
111} 106}
112 107
113static int vf610_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 108static int vf610_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
@@ -237,37 +232,31 @@ static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable)
237 return 0; 232 return 0;
238} 233}
239 234
240static struct irq_chip vf610_gpio_irq_chip = { 235static void vf610_gpio_disable_clk(void *data)
241 .name = "gpio-vf610", 236{
242 .irq_ack = vf610_gpio_irq_ack, 237 clk_disable_unprepare(data);
243 .irq_mask = vf610_gpio_irq_mask, 238}
244 .irq_unmask = vf610_gpio_irq_unmask,
245 .irq_set_type = vf610_gpio_irq_set_type,
246 .irq_set_wake = vf610_gpio_irq_set_wake,
247};
248 239
249static int vf610_gpio_probe(struct platform_device *pdev) 240static int vf610_gpio_probe(struct platform_device *pdev)
250{ 241{
251 struct device *dev = &pdev->dev; 242 struct device *dev = &pdev->dev;
252 struct device_node *np = dev->of_node; 243 struct device_node *np = dev->of_node;
253 struct vf610_gpio_port *port; 244 struct vf610_gpio_port *port;
254 struct resource *iores;
255 struct gpio_chip *gc; 245 struct gpio_chip *gc;
246 struct irq_chip *ic;
256 int i; 247 int i;
257 int ret; 248 int ret;
258 249
259 port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL); 250 port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
260 if (!port) 251 if (!port)
261 return -ENOMEM; 252 return -ENOMEM;
262 253
263 port->sdata = of_device_get_match_data(dev); 254 port->sdata = of_device_get_match_data(dev);
264 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 255 port->base = devm_platform_ioremap_resource(pdev, 0);
265 port->base = devm_ioremap_resource(dev, iores);
266 if (IS_ERR(port->base)) 256 if (IS_ERR(port->base))
267 return PTR_ERR(port->base); 257 return PTR_ERR(port->base);
268 258
269 iores = platform_get_resource(pdev, IORESOURCE_MEM, 1); 259 port->gpio_base = devm_platform_ioremap_resource(pdev, 1);
270 port->gpio_base = devm_ioremap_resource(dev, iores);
271 if (IS_ERR(port->gpio_base)) 260 if (IS_ERR(port->gpio_base))
272 return PTR_ERR(port->gpio_base); 261 return PTR_ERR(port->gpio_base);
273 262
@@ -275,11 +264,15 @@ static int vf610_gpio_probe(struct platform_device *pdev)
275 if (port->irq < 0) 264 if (port->irq < 0)
276 return port->irq; 265 return port->irq;
277 266
278 port->clk_port = devm_clk_get(&pdev->dev, "port"); 267 port->clk_port = devm_clk_get(dev, "port");
279 if (!IS_ERR(port->clk_port)) { 268 if (!IS_ERR(port->clk_port)) {
280 ret = clk_prepare_enable(port->clk_port); 269 ret = clk_prepare_enable(port->clk_port);
281 if (ret) 270 if (ret)
282 return ret; 271 return ret;
272 ret = devm_add_action_or_reset(dev, vf610_gpio_disable_clk,
273 port->clk_port);
274 if (ret)
275 return ret;
283 } else if (port->clk_port == ERR_PTR(-EPROBE_DEFER)) { 276 } else if (port->clk_port == ERR_PTR(-EPROBE_DEFER)) {
284 /* 277 /*
285 * Percolate deferrals, for anything else, 278 * Percolate deferrals, for anything else,
@@ -288,20 +281,19 @@ static int vf610_gpio_probe(struct platform_device *pdev)
288 return PTR_ERR(port->clk_port); 281 return PTR_ERR(port->clk_port);
289 } 282 }
290 283
291 port->clk_gpio = devm_clk_get(&pdev->dev, "gpio"); 284 port->clk_gpio = devm_clk_get(dev, "gpio");
292 if (!IS_ERR(port->clk_gpio)) { 285 if (!IS_ERR(port->clk_gpio)) {
293 ret = clk_prepare_enable(port->clk_gpio); 286 ret = clk_prepare_enable(port->clk_gpio);
294 if (ret) { 287 if (ret)
295 clk_disable_unprepare(port->clk_port); 288 return ret;
289 ret = devm_add_action_or_reset(dev, vf610_gpio_disable_clk,
290 port->clk_gpio);
291 if (ret)
296 return ret; 292 return ret;
297 }
298 } else if (port->clk_gpio == ERR_PTR(-EPROBE_DEFER)) { 293 } else if (port->clk_gpio == ERR_PTR(-EPROBE_DEFER)) {
299 clk_disable_unprepare(port->clk_port);
300 return PTR_ERR(port->clk_gpio); 294 return PTR_ERR(port->clk_gpio);
301 } 295 }
302 296
303 platform_set_drvdata(pdev, port);
304
305 gc = &port->gc; 297 gc = &port->gc;
306 gc->of_node = np; 298 gc->of_node = np;
307 gc->parent = dev; 299 gc->parent = dev;
@@ -316,7 +308,15 @@ static int vf610_gpio_probe(struct platform_device *pdev)
316 gc->direction_output = vf610_gpio_direction_output; 308 gc->direction_output = vf610_gpio_direction_output;
317 gc->set = vf610_gpio_set; 309 gc->set = vf610_gpio_set;
318 310
319 ret = gpiochip_add_data(gc, port); 311 ic = &port->ic;
312 ic->name = "gpio-vf610";
313 ic->irq_ack = vf610_gpio_irq_ack;
314 ic->irq_mask = vf610_gpio_irq_mask;
315 ic->irq_unmask = vf610_gpio_irq_unmask;
316 ic->irq_set_type = vf610_gpio_irq_set_type;
317 ic->irq_set_wake = vf610_gpio_irq_set_wake;
318
319 ret = devm_gpiochip_add_data(dev, gc, port);
320 if (ret < 0) 320 if (ret < 0)
321 return ret; 321 return ret;
322 322
@@ -327,39 +327,23 @@ static int vf610_gpio_probe(struct platform_device *pdev)
327 /* Clear the interrupt status register for all GPIO's */ 327 /* Clear the interrupt status register for all GPIO's */
328 vf610_gpio_writel(~0, port->base + PORT_ISFR); 328 vf610_gpio_writel(~0, port->base + PORT_ISFR);
329 329
330 ret = gpiochip_irqchip_add(gc, &vf610_gpio_irq_chip, 0, 330 ret = gpiochip_irqchip_add(gc, ic, 0, handle_edge_irq, IRQ_TYPE_NONE);
331 handle_edge_irq, IRQ_TYPE_NONE);
332 if (ret) { 331 if (ret) {
333 dev_err(dev, "failed to add irqchip\n"); 332 dev_err(dev, "failed to add irqchip\n");
334 gpiochip_remove(gc);
335 return ret; 333 return ret;
336 } 334 }
337 gpiochip_set_chained_irqchip(gc, &vf610_gpio_irq_chip, port->irq, 335 gpiochip_set_chained_irqchip(gc, ic, port->irq,
338 vf610_gpio_irq_handler); 336 vf610_gpio_irq_handler);
339 337
340 return 0; 338 return 0;
341} 339}
342 340
343static int vf610_gpio_remove(struct platform_device *pdev)
344{
345 struct vf610_gpio_port *port = platform_get_drvdata(pdev);
346
347 gpiochip_remove(&port->gc);
348 if (!IS_ERR(port->clk_port))
349 clk_disable_unprepare(port->clk_port);
350 if (!IS_ERR(port->clk_gpio))
351 clk_disable_unprepare(port->clk_gpio);
352
353 return 0;
354}
355
356static struct platform_driver vf610_gpio_driver = { 341static struct platform_driver vf610_gpio_driver = {
357 .driver = { 342 .driver = {
358 .name = "gpio-vf610", 343 .name = "gpio-vf610",
359 .of_match_table = vf610_gpio_dt_ids, 344 .of_match_table = vf610_gpio_dt_ids,
360 }, 345 },
361 .probe = vf610_gpio_probe, 346 .probe = vf610_gpio_probe,
362 .remove = vf610_gpio_remove,
363}; 347};
364 348
365builtin_platform_driver(vf610_gpio_driver); 349builtin_platform_driver(vf610_gpio_driver);
diff --git a/drivers/gpio/gpio-xgene-sb.c b/drivers/gpio/gpio-xgene-sb.c
index 2eb76f35aa7e..641a05181017 100644
--- a/drivers/gpio/gpio-xgene-sb.c
+++ b/drivers/gpio/gpio-xgene-sb.c
@@ -229,7 +229,6 @@ static int xgene_gpio_sb_probe(struct platform_device *pdev)
229{ 229{
230 struct xgene_gpio_sb *priv; 230 struct xgene_gpio_sb *priv;
231 int ret; 231 int ret;
232 struct resource *res;
233 void __iomem *regs; 232 void __iomem *regs;
234 struct irq_domain *parent_domain = NULL; 233 struct irq_domain *parent_domain = NULL;
235 u32 val32; 234 u32 val32;
@@ -238,8 +237,7 @@ static int xgene_gpio_sb_probe(struct platform_device *pdev)
238 if (!priv) 237 if (!priv)
239 return -ENOMEM; 238 return -ENOMEM;
240 239
241 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 240 regs = devm_platform_ioremap_resource(pdev, 0);
242 regs = devm_ioremap_resource(&pdev->dev, res);
243 if (IS_ERR(regs)) 241 if (IS_ERR(regs))
244 return PTR_ERR(regs); 242 return PTR_ERR(regs);
245 243
diff --git a/drivers/gpio/gpio-xlp.c b/drivers/gpio/gpio-xlp.c
index 0a3607fd21af..54d3359444f3 100644
--- a/drivers/gpio/gpio-xlp.c
+++ b/drivers/gpio/gpio-xlp.c
@@ -290,22 +290,17 @@ MODULE_DEVICE_TABLE(of, xlp_gpio_of_ids);
290static int xlp_gpio_probe(struct platform_device *pdev) 290static int xlp_gpio_probe(struct platform_device *pdev)
291{ 291{
292 struct gpio_chip *gc; 292 struct gpio_chip *gc;
293 struct resource *iores;
294 struct xlp_gpio_priv *priv; 293 struct xlp_gpio_priv *priv;
295 void __iomem *gpio_base; 294 void __iomem *gpio_base;
296 int irq_base, irq, err; 295 int irq_base, irq, err;
297 int ngpio; 296 int ngpio;
298 u32 soc_type; 297 u32 soc_type;
299 298
300 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
301 if (!iores)
302 return -ENODEV;
303
304 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 299 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
305 if (!priv) 300 if (!priv)
306 return -ENOMEM; 301 return -ENOMEM;
307 302
308 gpio_base = devm_ioremap_resource(&pdev->dev, iores); 303 gpio_base = devm_platform_ioremap_resource(pdev, 0);
309 if (IS_ERR(gpio_base)) 304 if (IS_ERR(gpio_base))
310 return PTR_ERR(gpio_base); 305 return PTR_ERR(gpio_base);
311 306
diff --git a/drivers/gpio/gpio-zx.c b/drivers/gpio/gpio-zx.c
index 5eacad9b2692..fb927559aefa 100644
--- a/drivers/gpio/gpio-zx.c
+++ b/drivers/gpio/gpio-zx.c
@@ -218,15 +218,13 @@ static int zx_gpio_probe(struct platform_device *pdev)
218{ 218{
219 struct device *dev = &pdev->dev; 219 struct device *dev = &pdev->dev;
220 struct zx_gpio *chip; 220 struct zx_gpio *chip;
221 struct resource *res;
222 int irq, id, ret; 221 int irq, id, ret;
223 222
224 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); 223 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
225 if (!chip) 224 if (!chip)
226 return -ENOMEM; 225 return -ENOMEM;
227 226
228 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 227 chip->base = devm_platform_ioremap_resource(pdev, 0);
229 chip->base = devm_ioremap_resource(dev, res);
230 if (IS_ERR(chip->base)) 228 if (IS_ERR(chip->base))
231 return PTR_ERR(chip->base); 229 return PTR_ERR(chip->base);
232 230
diff --git a/drivers/gpio/gpio-zynq.c b/drivers/gpio/gpio-zynq.c
index 00ff7b1fa8a1..9392edaeec3f 100644
--- a/drivers/gpio/gpio-zynq.c
+++ b/drivers/gpio/gpio-zynq.c
@@ -834,7 +834,6 @@ static int zynq_gpio_probe(struct platform_device *pdev)
834 int ret, bank_num; 834 int ret, bank_num;
835 struct zynq_gpio *gpio; 835 struct zynq_gpio *gpio;
836 struct gpio_chip *chip; 836 struct gpio_chip *chip;
837 struct resource *res;
838 const struct of_device_id *match; 837 const struct of_device_id *match;
839 838
840 gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 839 gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
@@ -849,8 +848,7 @@ static int zynq_gpio_probe(struct platform_device *pdev)
849 gpio->p_data = match->data; 848 gpio->p_data = match->data;
850 platform_set_drvdata(pdev, gpio); 849 platform_set_drvdata(pdev, gpio);
851 850
852 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 851 gpio->base_addr = devm_platform_ioremap_resource(pdev, 0);
853 gpio->base_addr = devm_ioremap_resource(&pdev->dev, res);
854 if (IS_ERR(gpio->base_addr)) 852 if (IS_ERR(gpio->base_addr))
855 return PTR_ERR(gpio->base_addr); 853 return PTR_ERR(gpio->base_addr);
856 854
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 30d0baf7ddae..c9fc9e232aaf 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -24,13 +24,13 @@
24 * 24 *
25 * @node: list-entry of the events list of the struct acpi_gpio_chip 25 * @node: list-entry of the events list of the struct acpi_gpio_chip
26 * @handle: handle of ACPI method to execute when the IRQ triggers 26 * @handle: handle of ACPI method to execute when the IRQ triggers
27 * @handler: irq_handler to pass to request_irq when requesting the IRQ 27 * @handler: handler function to pass to request_irq() when requesting the IRQ
28 * @pin: GPIO pin number on the gpio_chip 28 * @pin: GPIO pin number on the struct gpio_chip
29 * @irq: Linux IRQ number for the event, for request_ / free_irq 29 * @irq: Linux IRQ number for the event, for request_irq() / free_irq()
30 * @irqflags: flags to pass to request_irq when requesting the IRQ 30 * @irqflags: flags to pass to request_irq() when requesting the IRQ
31 * @irq_is_wake: If the ACPI flags indicate the IRQ is a wakeup source 31 * @irq_is_wake: If the ACPI flags indicate the IRQ is a wakeup source
32 * @irq_requested:True if request_irq has been done 32 * @irq_requested:True if request_irq() has been done
33 * @desc: gpio_desc for the GPIO pin for this event 33 * @desc: struct gpio_desc for the GPIO pin for this event
34 */ 34 */
35struct acpi_gpio_event { 35struct acpi_gpio_event {
36 struct list_head node; 36 struct list_head node;
@@ -65,10 +65,10 @@ struct acpi_gpio_chip {
65}; 65};
66 66
67/* 67/*
68 * For gpiochips which call acpi_gpiochip_request_interrupts() before late_init 68 * For GPIO chips which call acpi_gpiochip_request_interrupts() before late_init
69 * (so builtin drivers) we register the ACPI GpioInt IRQ handlers from a 69 * (so builtin drivers) we register the ACPI GpioInt IRQ handlers from a
70 * late_initcall_sync handler, so that other builtin drivers can register their 70 * late_initcall_sync() handler, so that other builtin drivers can register their
71 * OpRegions before the event handlers can run. This list contains gpiochips 71 * OpRegions before the event handlers can run. This list contains GPIO chips
72 * for which the acpi_gpiochip_request_irqs() call has been deferred. 72 * for which the acpi_gpiochip_request_irqs() call has been deferred.
73 */ 73 */
74static DEFINE_MUTEX(acpi_gpio_deferred_req_irqs_lock); 74static DEFINE_MUTEX(acpi_gpio_deferred_req_irqs_lock);
@@ -90,7 +90,7 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
90 * 90 *
91 * Return: GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR 91 * Return: GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR
92 * error value. Specifically returns %-EPROBE_DEFER if the referenced GPIO 92 * error value. Specifically returns %-EPROBE_DEFER if the referenced GPIO
93 * controller does not have gpiochip registered at the moment. This is to 93 * controller does not have GPIO chip registered at the moment. This is to
94 * support probe deferral. 94 * support probe deferral.
95 */ 95 */
96static struct gpio_desc *acpi_get_gpiod(char *path, int pin) 96static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
@@ -287,9 +287,9 @@ fail_free_desc:
287 * 287 *
288 * ACPI5 platforms can use GPIO signaled ACPI events. These GPIO interrupts are 288 * ACPI5 platforms can use GPIO signaled ACPI events. These GPIO interrupts are
289 * handled by ACPI event methods which need to be called from the GPIO 289 * handled by ACPI event methods which need to be called from the GPIO
290 * chip's interrupt handler. acpi_gpiochip_request_interrupts finds out which 290 * chip's interrupt handler. acpi_gpiochip_request_interrupts() finds out which
291 * gpio pins have acpi event methods and assigns interrupt handlers that calls 291 * GPIO pins have ACPI event methods and assigns interrupt handlers that calls
292 * the acpi event methods for those pins. 292 * the ACPI event methods for those pins.
293 */ 293 */
294void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) 294void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
295{ 295{
@@ -444,8 +444,6 @@ static bool acpi_get_driver_gpio_data(struct acpi_device *adev,
444static enum gpiod_flags 444static enum gpiod_flags
445acpi_gpio_to_gpiod_flags(const struct acpi_resource_gpio *agpio) 445acpi_gpio_to_gpiod_flags(const struct acpi_resource_gpio *agpio)
446{ 446{
447 bool pull_up = agpio->pin_config == ACPI_PIN_CONFIG_PULLUP;
448
449 switch (agpio->io_restriction) { 447 switch (agpio->io_restriction) {
450 case ACPI_IO_RESTRICT_INPUT: 448 case ACPI_IO_RESTRICT_INPUT:
451 return GPIOD_IN; 449 return GPIOD_IN;
@@ -454,16 +452,26 @@ acpi_gpio_to_gpiod_flags(const struct acpi_resource_gpio *agpio)
454 * ACPI GPIO resources don't contain an initial value for the 452 * ACPI GPIO resources don't contain an initial value for the
455 * GPIO. Therefore we deduce that value from the pull field 453 * GPIO. Therefore we deduce that value from the pull field
456 * instead. If the pin is pulled up we assume default to be 454 * instead. If the pin is pulled up we assume default to be
457 * high, otherwise low. 455 * high, if it is pulled down we assume default to be low,
456 * otherwise we leave pin untouched.
458 */ 457 */
459 return pull_up ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; 458 switch (agpio->pin_config) {
459 case ACPI_PIN_CONFIG_PULLUP:
460 return GPIOD_OUT_HIGH;
461 case ACPI_PIN_CONFIG_PULLDOWN:
462 return GPIOD_OUT_LOW;
463 default:
464 break;
465 }
460 default: 466 default:
461 /* 467 break;
462 * Assume that the BIOS has configured the direction and pull
463 * accordingly.
464 */
465 return GPIOD_ASIS;
466 } 468 }
469
470 /*
471 * Assume that the BIOS has configured the direction and pull
472 * accordingly.
473 */
474 return GPIOD_ASIS;
467} 475}
468 476
469static int 477static int
@@ -517,6 +525,26 @@ acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, struct acpi_gpio_info *inf
517 return ret; 525 return ret;
518} 526}
519 527
528int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
529 struct acpi_gpio_info *info)
530{
531 switch (info->pin_config) {
532 case ACPI_PIN_CONFIG_PULLUP:
533 *lookupflags |= GPIO_PULL_UP;
534 break;
535 case ACPI_PIN_CONFIG_PULLDOWN:
536 *lookupflags |= GPIO_PULL_DOWN;
537 break;
538 default:
539 break;
540 }
541
542 if (info->polarity == GPIO_ACTIVE_LOW)
543 *lookupflags |= GPIO_ACTIVE_LOW;
544
545 return 0;
546}
547
520struct acpi_gpio_lookup { 548struct acpi_gpio_lookup {
521 struct acpi_gpio_info info; 549 struct acpi_gpio_info info;
522 int index; 550 int index;
@@ -550,6 +578,7 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
550 578
551 lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr, 579 lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr,
552 agpio->pin_table[pin_index]); 580 agpio->pin_table[pin_index]);
581 lookup->info.pin_config = agpio->pin_config;
553 lookup->info.gpioint = gpioint; 582 lookup->info.gpioint = gpioint;
554 583
555 /* 584 /*
@@ -653,7 +682,7 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode,
653 * that case @index is used to select the GPIO entry in the property value 682 * that case @index is used to select the GPIO entry in the property value
654 * (in case of multiple). 683 * (in case of multiple).
655 * 684 *
656 * If the GPIO cannot be translated or there is an error an ERR_PTR is 685 * If the GPIO cannot be translated or there is an error, an ERR_PTR is
657 * returned. 686 * returned.
658 * 687 *
659 * Note: if the GPIO resource has multiple entries in the pin list, this 688 * Note: if the GPIO resource has multiple entries in the pin list, this
@@ -696,7 +725,7 @@ struct gpio_desc *acpi_find_gpio(struct device *dev,
696 const char *con_id, 725 const char *con_id,
697 unsigned int idx, 726 unsigned int idx,
698 enum gpiod_flags *dflags, 727 enum gpiod_flags *dflags,
699 enum gpio_lookup_flags *lookupflags) 728 unsigned long *lookupflags)
700{ 729{
701 struct acpi_device *adev = ACPI_COMPANION(dev); 730 struct acpi_device *adev = ACPI_COMPANION(dev);
702 struct acpi_gpio_info info; 731 struct acpi_gpio_info info;
@@ -737,10 +766,8 @@ struct gpio_desc *acpi_find_gpio(struct device *dev,
737 return ERR_PTR(-ENOENT); 766 return ERR_PTR(-ENOENT);
738 } 767 }
739 768
740 if (info.polarity == GPIO_ACTIVE_LOW)
741 *lookupflags |= GPIO_ACTIVE_LOW;
742
743 acpi_gpio_update_gpiod_flags(dflags, &info); 769 acpi_gpio_update_gpiod_flags(dflags, &info);
770 acpi_gpio_update_gpiod_lookup_flags(lookupflags, &info);
744 return desc; 771 return desc;
745} 772}
746 773
@@ -751,10 +778,13 @@ struct gpio_desc *acpi_find_gpio(struct device *dev,
751 * @index: index of GpioIo/GpioInt resource (starting from %0) 778 * @index: index of GpioIo/GpioInt resource (starting from %0)
752 * @info: info pointer to fill in (optional) 779 * @info: info pointer to fill in (optional)
753 * 780 *
754 * If @fwnode is an ACPI device object, call %acpi_get_gpiod_by_index() for it. 781 * If @fwnode is an ACPI device object, call acpi_get_gpiod_by_index() for it.
755 * Otherwise (ie. it is a data-only non-device object), use the property-based 782 * Otherwise (i.e. it is a data-only non-device object), use the property-based
756 * GPIO lookup to get to the GPIO resource with the relevant information and use 783 * GPIO lookup to get to the GPIO resource with the relevant information and use
757 * that to obtain the GPIO descriptor to return. 784 * that to obtain the GPIO descriptor to return.
785 *
786 * If the GPIO cannot be translated or there is an error an ERR_PTR is
787 * returned.
758 */ 788 */
759struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode, 789struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
760 const char *propname, int index, 790 const char *propname, int index,
@@ -816,6 +846,7 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
816 return PTR_ERR(desc); 846 return PTR_ERR(desc);
817 847
818 if (info.gpioint && idx++ == index) { 848 if (info.gpioint && idx++ == index) {
849 unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
819 char label[32]; 850 char label[32];
820 int irq; 851 int irq;
821 852
@@ -827,7 +858,7 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
827 return irq; 858 return irq;
828 859
829 snprintf(label, sizeof(label), "GpioInt() %d", index); 860 snprintf(label, sizeof(label), "GpioInt() %d", index);
830 ret = gpiod_configure_flags(desc, label, 0, info.flags); 861 ret = gpiod_configure_flags(desc, label, lflags, info.flags);
831 if (ret < 0) 862 if (ret < 0)
832 return ret; 863 return ret;
833 864
@@ -992,16 +1023,19 @@ static void acpi_gpiochip_free_regions(struct acpi_gpio_chip *achip)
992 } 1023 }
993} 1024}
994 1025
995static struct gpio_desc *acpi_gpiochip_parse_own_gpio( 1026static struct gpio_desc *
996 struct acpi_gpio_chip *achip, struct fwnode_handle *fwnode, 1027acpi_gpiochip_parse_own_gpio(struct acpi_gpio_chip *achip,
997 const char **name, unsigned int *lflags, unsigned int *dflags) 1028 struct fwnode_handle *fwnode,
1029 const char **name,
1030 unsigned long *lflags,
1031 enum gpiod_flags *dflags)
998{ 1032{
999 struct gpio_chip *chip = achip->chip; 1033 struct gpio_chip *chip = achip->chip;
1000 struct gpio_desc *desc; 1034 struct gpio_desc *desc;
1001 u32 gpios[2]; 1035 u32 gpios[2];
1002 int ret; 1036 int ret;
1003 1037
1004 *lflags = 0; 1038 *lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
1005 *dflags = 0; 1039 *dflags = 0;
1006 *name = NULL; 1040 *name = NULL;
1007 1041
@@ -1037,7 +1071,8 @@ static void acpi_gpiochip_scan_gpios(struct acpi_gpio_chip *achip)
1037 struct fwnode_handle *fwnode; 1071 struct fwnode_handle *fwnode;
1038 1072
1039 device_for_each_child_node(chip->parent, fwnode) { 1073 device_for_each_child_node(chip->parent, fwnode) {
1040 unsigned int lflags, dflags; 1074 unsigned long lflags;
1075 enum gpiod_flags dflags;
1041 struct gpio_desc *desc; 1076 struct gpio_desc *desc;
1042 const char *name; 1077 const char *name;
1043 int ret; 1078 int ret;
@@ -1158,11 +1193,13 @@ static int acpi_find_gpio_count(struct acpi_resource *ares, void *data)
1158} 1193}
1159 1194
1160/** 1195/**
1161 * acpi_gpio_count - return the number of GPIOs associated with a 1196 * acpi_gpio_count - count the GPIOs associated with a device / function
1162 * device / function or -ENOENT if no GPIO has been 1197 * @dev: GPIO consumer, can be %NULL for system-global GPIOs
1163 * assigned to the requested function.
1164 * @dev: GPIO consumer, can be NULL for system-global GPIOs
1165 * @con_id: function within the GPIO consumer 1198 * @con_id: function within the GPIO consumer
1199 *
1200 * Return:
1201 * The number of GPIOs associated with a device / function or %-ENOENT,
1202 * if no GPIO has been assigned to the requested function.
1166 */ 1203 */
1167int acpi_gpio_count(struct device *dev, const char *con_id) 1204int acpi_gpio_count(struct device *dev, const char *con_id)
1168{ 1205{
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 6a3ec575a404..aec7bd86ae7e 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -86,9 +86,9 @@ static void of_gpio_flags_quirks(struct device_node *np,
86 if (IS_ENABLED(CONFIG_REGULATOR) && 86 if (IS_ENABLED(CONFIG_REGULATOR) &&
87 (of_device_is_compatible(np, "regulator-fixed") || 87 (of_device_is_compatible(np, "regulator-fixed") ||
88 of_device_is_compatible(np, "reg-fixed-voltage") || 88 of_device_is_compatible(np, "reg-fixed-voltage") ||
89 (of_device_is_compatible(np, "regulator-gpio") && 89 (!(strcmp(propname, "enable-gpio") &&
90 !(strcmp(propname, "enable-gpio") && 90 strcmp(propname, "enable-gpios")) &&
91 strcmp(propname, "enable-gpios"))))) { 91 of_device_is_compatible(np, "regulator-gpio")))) {
92 /* 92 /*
93 * The regulator GPIO handles are specified such that the 93 * The regulator GPIO handles are specified such that the
94 * presence or absence of "enable-active-high" solely controls 94 * presence or absence of "enable-active-high" solely controls
@@ -119,9 +119,8 @@ static void of_gpio_flags_quirks(struct device_node *np,
119 * property named "cs-gpios" we need to inspect the child node 119 * property named "cs-gpios" we need to inspect the child node
120 * to determine if the flags should have inverted semantics. 120 * to determine if the flags should have inverted semantics.
121 */ 121 */
122 if (IS_ENABLED(CONFIG_SPI_MASTER) && 122 if (IS_ENABLED(CONFIG_SPI_MASTER) && !strcmp(propname, "cs-gpios") &&
123 of_property_read_bool(np, "cs-gpios") && 123 of_property_read_bool(np, "cs-gpios")) {
124 !strcmp(propname, "cs-gpios")) {
125 struct device_node *child; 124 struct device_node *child;
126 u32 cs; 125 u32 cs;
127 int ret; 126 int ret;
@@ -288,8 +287,7 @@ static struct gpio_desc *of_find_regulator_gpio(struct device *dev, const char *
288} 287}
289 288
290struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, 289struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
291 unsigned int idx, 290 unsigned int idx, unsigned long *flags)
292 enum gpio_lookup_flags *flags)
293{ 291{
294 char prop_name[32]; /* 32 is max size of property name */ 292 char prop_name[32]; /* 32 is max size of property name */
295 enum of_gpio_flags of_flags; 293 enum of_gpio_flags of_flags;
@@ -362,8 +360,8 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
362 * @chip: GPIO chip whose hog is parsed 360 * @chip: GPIO chip whose hog is parsed
363 * @idx: Index of the GPIO to parse 361 * @idx: Index of the GPIO to parse
364 * @name: GPIO line name 362 * @name: GPIO line name
365 * @lflags: gpio_lookup_flags - returned from of_find_gpio() or 363 * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
366 * of_parse_own_gpio() 364 * of_find_gpio() or of_parse_own_gpio()
367 * @dflags: gpiod_flags - optional GPIO initialization flags 365 * @dflags: gpiod_flags - optional GPIO initialization flags
368 * 366 *
369 * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno 367 * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno
@@ -372,7 +370,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
372static struct gpio_desc *of_parse_own_gpio(struct device_node *np, 370static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
373 struct gpio_chip *chip, 371 struct gpio_chip *chip,
374 unsigned int idx, const char **name, 372 unsigned int idx, const char **name,
375 enum gpio_lookup_flags *lflags, 373 unsigned long *lflags,
376 enum gpiod_flags *dflags) 374 enum gpiod_flags *dflags)
377{ 375{
378 struct device_node *chip_np; 376 struct device_node *chip_np;
@@ -388,7 +386,7 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
388 return ERR_PTR(-EINVAL); 386 return ERR_PTR(-EINVAL);
389 387
390 xlate_flags = 0; 388 xlate_flags = 0;
391 *lflags = 0; 389 *lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
392 *dflags = 0; 390 *dflags = 0;
393 391
394 ret = of_property_read_u32(chip_np, "#gpio-cells", &tmp); 392 ret = of_property_read_u32(chip_np, "#gpio-cells", &tmp);
@@ -445,7 +443,7 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
445 struct gpio_desc *desc = NULL; 443 struct gpio_desc *desc = NULL;
446 struct device_node *np; 444 struct device_node *np;
447 const char *name; 445 const char *name;
448 enum gpio_lookup_flags lflags; 446 unsigned long lflags;
449 enum gpiod_flags dflags; 447 enum gpiod_flags dflags;
450 unsigned int i; 448 unsigned int i;
451 int ret; 449 int ret;
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index bca3e7740ef6..e013d417a936 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2519,6 +2519,7 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
2519 const char *label, 2519 const char *label,
2520 enum gpiod_flags flags) 2520 enum gpiod_flags flags)
2521{ 2521{
2522 unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
2522 struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum); 2523 struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum);
2523 int err; 2524 int err;
2524 2525
@@ -2531,7 +2532,7 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
2531 if (err < 0) 2532 if (err < 0)
2532 return ERR_PTR(err); 2533 return ERR_PTR(err);
2533 2534
2534 err = gpiod_configure_flags(desc, label, 0, flags); 2535 err = gpiod_configure_flags(desc, label, lflags, flags);
2535 if (err) { 2536 if (err) {
2536 chip_err(chip, "setup of own GPIO %s failed\n", label); 2537 chip_err(chip, "setup of own GPIO %s failed\n", label);
2537 gpiod_free_commit(desc); 2538 gpiod_free_commit(desc);
@@ -2569,8 +2570,20 @@ EXPORT_SYMBOL_GPL(gpiochip_free_own_desc);
2569static int gpio_set_config(struct gpio_chip *gc, unsigned offset, 2570static int gpio_set_config(struct gpio_chip *gc, unsigned offset,
2570 enum pin_config_param mode) 2571 enum pin_config_param mode)
2571{ 2572{
2572 unsigned long config = { PIN_CONF_PACKED(mode, 0) }; 2573 unsigned long config;
2574 unsigned arg;
2573 2575
2576 switch (mode) {
2577 case PIN_CONFIG_BIAS_PULL_DOWN:
2578 case PIN_CONFIG_BIAS_PULL_UP:
2579 arg = 1;
2580 break;
2581
2582 default:
2583 arg = 0;
2584 }
2585
2586 config = PIN_CONF_PACKED(mode, arg);
2574 return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP; 2587 return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP;
2575} 2588}
2576 2589
@@ -3915,8 +3928,7 @@ found:
3915} 3928}
3916 3929
3917static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, 3930static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
3918 unsigned int idx, 3931 unsigned int idx, unsigned long *flags)
3919 enum gpio_lookup_flags *flags)
3920{ 3932{
3921 struct gpio_desc *desc = ERR_PTR(-ENOENT); 3933 struct gpio_desc *desc = ERR_PTR(-ENOENT);
3922 struct gpiod_lookup_table *table; 3934 struct gpiod_lookup_table *table;
@@ -4072,8 +4084,8 @@ EXPORT_SYMBOL_GPL(gpiod_get_optional);
4072 * gpiod_configure_flags - helper function to configure a given GPIO 4084 * gpiod_configure_flags - helper function to configure a given GPIO
4073 * @desc: gpio whose value will be assigned 4085 * @desc: gpio whose value will be assigned
4074 * @con_id: function within the GPIO consumer 4086 * @con_id: function within the GPIO consumer
4075 * @lflags: gpio_lookup_flags - returned from of_find_gpio() or 4087 * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
4076 * of_get_gpio_hog() 4088 * of_find_gpio() or of_get_gpio_hog()
4077 * @dflags: gpiod_flags - optional GPIO initialization flags 4089 * @dflags: gpiod_flags - optional GPIO initialization flags
4078 * 4090 *
4079 * Return 0 on success, -ENOENT if no GPIO has been assigned to the 4091 * Return 0 on success, -ENOENT if no GPIO has been assigned to the
@@ -4155,9 +4167,9 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
4155 unsigned int idx, 4167 unsigned int idx,
4156 enum gpiod_flags flags) 4168 enum gpiod_flags flags)
4157{ 4169{
4170 unsigned long lookupflags = GPIO_LOOKUP_FLAGS_DEFAULT;
4158 struct gpio_desc *desc = NULL; 4171 struct gpio_desc *desc = NULL;
4159 int status; 4172 int status;
4160 enum gpio_lookup_flags lookupflags = 0;
4161 /* Maybe we have a device name, maybe not */ 4173 /* Maybe we have a device name, maybe not */
4162 const char *devname = dev ? dev_name(dev) : "?"; 4174 const char *devname = dev ? dev_name(dev) : "?";
4163 4175
@@ -4242,8 +4254,8 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
4242 enum gpiod_flags dflags, 4254 enum gpiod_flags dflags,
4243 const char *label) 4255 const char *label)
4244{ 4256{
4257 unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
4245 struct gpio_desc *desc; 4258 struct gpio_desc *desc;
4246 unsigned long lflags = 0;
4247 enum of_gpio_flags flags; 4259 enum of_gpio_flags flags;
4248 bool active_low = false; 4260 bool active_low = false;
4249 bool single_ended = false; 4261 bool single_ended = false;
@@ -4321,8 +4333,8 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
4321 enum gpiod_flags dflags, 4333 enum gpiod_flags dflags,
4322 const char *label) 4334 const char *label)
4323{ 4335{
4336 unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
4324 struct gpio_desc *desc = ERR_PTR(-ENODEV); 4337 struct gpio_desc *desc = ERR_PTR(-ENODEV);
4325 unsigned long lflags = 0;
4326 int ret; 4338 int ret;
4327 4339
4328 if (!fwnode) 4340 if (!fwnode)
@@ -4342,9 +4354,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
4342 return desc; 4354 return desc;
4343 4355
4344 acpi_gpio_update_gpiod_flags(&dflags, &info); 4356 acpi_gpio_update_gpiod_flags(&dflags, &info);
4345 4357 acpi_gpio_update_gpiod_lookup_flags(&lflags, &info);
4346 if (info.polarity == GPIO_ACTIVE_LOW)
4347 lflags |= GPIO_ACTIVE_LOW;
4348 } 4358 }
4349 4359
4350 /* Currently only ACPI takes this path */ 4360 /* Currently only ACPI takes this path */
@@ -4395,8 +4405,8 @@ EXPORT_SYMBOL_GPL(gpiod_get_index_optional);
4395 * gpiod_hog - Hog the specified GPIO desc given the provided flags 4405 * gpiod_hog - Hog the specified GPIO desc given the provided flags
4396 * @desc: gpio whose value will be assigned 4406 * @desc: gpio whose value will be assigned
4397 * @name: gpio line name 4407 * @name: gpio line name
4398 * @lflags: gpio_lookup_flags - returned from of_find_gpio() or 4408 * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
4399 * of_get_gpio_hog() 4409 * of_find_gpio() or of_get_gpio_hog()
4400 * @dflags: gpiod_flags - optional GPIO initialization flags 4410 * @dflags: gpiod_flags - optional GPIO initialization flags
4401 */ 4411 */
4402int gpiod_hog(struct gpio_desc *desc, const char *name, 4412int gpiod_hog(struct gpio_desc *desc, const char *name,
@@ -4449,8 +4459,6 @@ int gpiod_hog(struct gpio_desc *desc, const char *name,
4449/** 4459/**
4450 * gpiochip_free_hogs - Scan gpio-controller chip and release GPIO hog 4460 * gpiochip_free_hogs - Scan gpio-controller chip and release GPIO hog
4451 * @chip: gpio chip to act on 4461 * @chip: gpio chip to act on
4452 *
4453 * This is only used by of_gpiochip_remove to free hogged gpios
4454 */ 4462 */
4455static void gpiochip_free_hogs(struct gpio_chip *chip) 4463static void gpiochip_free_hogs(struct gpio_chip *chip)
4456{ 4464{
@@ -4620,7 +4628,8 @@ EXPORT_SYMBOL_GPL(gpiod_get_array_optional);
4620 */ 4628 */
4621void gpiod_put(struct gpio_desc *desc) 4629void gpiod_put(struct gpio_desc *desc)
4622{ 4630{
4623 gpiod_free(desc); 4631 if (desc)
4632 gpiod_free(desc);
4624} 4633}
4625EXPORT_SYMBOL_GPL(gpiod_put); 4634EXPORT_SYMBOL_GPL(gpiod_put);
4626 4635
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 3243c1eb5c88..7a65dad43932 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -17,7 +17,6 @@
17#include <linux/cdev.h> 17#include <linux/cdev.h>
18 18
19enum of_gpio_flags; 19enum of_gpio_flags;
20enum gpio_lookup_flags;
21struct acpi_device; 20struct acpi_device;
22 21
23/** 22/**
@@ -75,6 +74,7 @@ struct gpio_device {
75 * @adev: reference to ACPI device which consumes GPIO resource 74 * @adev: reference to ACPI device which consumes GPIO resource
76 * @flags: GPIO initialization flags 75 * @flags: GPIO initialization flags
77 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo 76 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
77 * @pin_config: pin bias as provided by ACPI
78 * @polarity: interrupt polarity as provided by ACPI 78 * @polarity: interrupt polarity as provided by ACPI
79 * @triggering: triggering type as provided by ACPI 79 * @triggering: triggering type as provided by ACPI
80 * @quirks: Linux specific quirks as provided by struct acpi_gpio_mapping 80 * @quirks: Linux specific quirks as provided by struct acpi_gpio_mapping
@@ -83,6 +83,7 @@ struct acpi_gpio_info {
83 struct acpi_device *adev; 83 struct acpi_device *adev;
84 enum gpiod_flags flags; 84 enum gpiod_flags flags;
85 bool gpioint; 85 bool gpioint;
86 int pin_config;
86 int polarity; 87 int polarity;
87 int triggering; 88 int triggering;
88 unsigned int quirks; 89 unsigned int quirks;
@@ -95,7 +96,7 @@ static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" };
95struct gpio_desc *of_find_gpio(struct device *dev, 96struct gpio_desc *of_find_gpio(struct device *dev,
96 const char *con_id, 97 const char *con_id,
97 unsigned int idx, 98 unsigned int idx,
98 enum gpio_lookup_flags *flags); 99 unsigned long *lookupflags);
99struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, 100struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
100 const char *list_name, int index, enum of_gpio_flags *flags); 101 const char *list_name, int index, enum of_gpio_flags *flags);
101int of_gpiochip_add(struct gpio_chip *gc); 102int of_gpiochip_add(struct gpio_chip *gc);
@@ -104,7 +105,7 @@ void of_gpiochip_remove(struct gpio_chip *gc);
104static inline struct gpio_desc *of_find_gpio(struct device *dev, 105static inline struct gpio_desc *of_find_gpio(struct device *dev,
105 const char *con_id, 106 const char *con_id,
106 unsigned int idx, 107 unsigned int idx,
107 enum gpio_lookup_flags *flags) 108 unsigned long *lookupflags)
108{ 109{
109 return ERR_PTR(-ENOENT); 110 return ERR_PTR(-ENOENT);
110} 111}
@@ -126,12 +127,14 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
126 127
127int acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, 128int acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags,
128 struct acpi_gpio_info *info); 129 struct acpi_gpio_info *info);
130int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
131 struct acpi_gpio_info *info);
129 132
130struct gpio_desc *acpi_find_gpio(struct device *dev, 133struct gpio_desc *acpi_find_gpio(struct device *dev,
131 const char *con_id, 134 const char *con_id,
132 unsigned int idx, 135 unsigned int idx,
133 enum gpiod_flags *dflags, 136 enum gpiod_flags *dflags,
134 enum gpio_lookup_flags *lookupflags); 137 unsigned long *lookupflags);
135struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode, 138struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
136 const char *propname, int index, 139 const char *propname, int index,
137 struct acpi_gpio_info *info); 140 struct acpi_gpio_info *info);
@@ -154,11 +157,17 @@ acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, struct acpi_gpio_info *inf
154{ 157{
155 return 0; 158 return 0;
156} 159}
160static inline int
161acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
162 struct acpi_gpio_info *info)
163{
164 return 0;
165}
157 166
158static inline struct gpio_desc * 167static inline struct gpio_desc *
159acpi_find_gpio(struct device *dev, const char *con_id, 168acpi_find_gpio(struct device *dev, const char *con_id,
160 unsigned int idx, enum gpiod_flags *dflags, 169 unsigned int idx, enum gpiod_flags *dflags,
161 enum gpio_lookup_flags *lookupflags) 170 unsigned long *lookupflags)
162{ 171{
163 return ERR_PTR(-ENOENT); 172 return ERR_PTR(-ENOENT);
164} 173}
diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c
index fd9d6f026d70..f0cdb5234e49 100644
--- a/drivers/pinctrl/pinctrl-mcp23s08.c
+++ b/drivers/pinctrl/pinctrl-mcp23s08.c
@@ -655,115 +655,6 @@ static int mcp23s08_irqchip_setup(struct mcp23s08 *mcp)
655 655
656/*----------------------------------------------------------------------*/ 656/*----------------------------------------------------------------------*/
657 657
658#ifdef CONFIG_DEBUG_FS
659
660#include <linux/seq_file.h>
661
662/*
663 * This compares the chip's registers with the register
664 * cache and corrects any incorrectly set register. This
665 * can be used to fix state for MCP23xxx, that temporary
666 * lost its power supply.
667 */
668#define MCP23S08_CONFIG_REGS 7
669static int __check_mcp23s08_reg_cache(struct mcp23s08 *mcp)
670{
671 int cached[MCP23S08_CONFIG_REGS];
672 int err = 0, i;
673
674 /* read cached config registers */
675 for (i = 0; i < MCP23S08_CONFIG_REGS; i++) {
676 err = mcp_read(mcp, i, &cached[i]);
677 if (err)
678 goto out;
679 }
680
681 regcache_cache_bypass(mcp->regmap, true);
682
683 for (i = 0; i < MCP23S08_CONFIG_REGS; i++) {
684 int uncached;
685 err = mcp_read(mcp, i, &uncached);
686 if (err)
687 goto out;
688
689 if (uncached != cached[i]) {
690 dev_err(mcp->dev, "restoring reg 0x%02x from 0x%04x to 0x%04x (power-loss?)\n",
691 i, uncached, cached[i]);
692 mcp_write(mcp, i, cached[i]);
693 }
694 }
695
696out:
697 if (err)
698 dev_err(mcp->dev, "read error: reg=%02x, err=%d", i, err);
699 regcache_cache_bypass(mcp->regmap, false);
700 return err;
701}
702
703/*
704 * This shows more info than the generic gpio dump code:
705 * pullups, deglitching, open drain drive.
706 */
707static void mcp23s08_dbg_show(struct seq_file *s, struct gpio_chip *chip)
708{
709 struct mcp23s08 *mcp;
710 char bank;
711 int t;
712 unsigned mask;
713 int iodir, gpio, gppu;
714
715 mcp = gpiochip_get_data(chip);
716
717 /* NOTE: we only handle one bank for now ... */
718 bank = '0' + ((mcp->addr >> 1) & 0x7);
719
720 mutex_lock(&mcp->lock);
721
722 t = __check_mcp23s08_reg_cache(mcp);
723 if (t) {
724 seq_printf(s, " I/O Error\n");
725 goto done;
726 }
727 t = mcp_read(mcp, MCP_IODIR, &iodir);
728 if (t) {
729 seq_printf(s, " I/O Error\n");
730 goto done;
731 }
732 t = mcp_read(mcp, MCP_GPIO, &gpio);
733 if (t) {
734 seq_printf(s, " I/O Error\n");
735 goto done;
736 }
737 t = mcp_read(mcp, MCP_GPPU, &gppu);
738 if (t) {
739 seq_printf(s, " I/O Error\n");
740 goto done;
741 }
742
743 for (t = 0, mask = BIT(0); t < chip->ngpio; t++, mask <<= 1) {
744 const char *label;
745
746 label = gpiochip_is_requested(chip, t);
747 if (!label)
748 continue;
749
750 seq_printf(s, " gpio-%-3d P%c.%d (%-12s) %s %s %s\n",
751 chip->base + t, bank, t, label,
752 (iodir & mask) ? "in " : "out",
753 (gpio & mask) ? "hi" : "lo",
754 (gppu & mask) ? "up" : " ");
755 /* NOTE: ignoring the irq-related registers */
756 }
757done:
758 mutex_unlock(&mcp->lock);
759}
760
761#else
762#define mcp23s08_dbg_show NULL
763#endif
764
765/*----------------------------------------------------------------------*/
766
767static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, 658static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
768 void *data, unsigned addr, unsigned type, 659 void *data, unsigned addr, unsigned type,
769 unsigned int base, int cs) 660 unsigned int base, int cs)
@@ -784,7 +675,6 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
784 mcp->chip.get = mcp23s08_get; 675 mcp->chip.get = mcp23s08_get;
785 mcp->chip.direction_output = mcp23s08_direction_output; 676 mcp->chip.direction_output = mcp23s08_direction_output;
786 mcp->chip.set = mcp23s08_set; 677 mcp->chip.set = mcp23s08_set;
787 mcp->chip.dbg_show = mcp23s08_dbg_show;
788#ifdef CONFIG_OF_GPIO 678#ifdef CONFIG_OF_GPIO
789 mcp->chip.of_gpio_n_cells = 2; 679 mcp->chip.of_gpio_n_cells = 2;
790 mcp->chip.of_node = dev->of_node; 680 mcp->chip.of_node = dev->of_node;
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 951be1715c12..a1d273c96016 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -227,9 +227,10 @@ struct gpio_irq_chip {
227 * @reg_dat: data (in) register for generic GPIO 227 * @reg_dat: data (in) register for generic GPIO
228 * @reg_set: output set register (out=high) for generic GPIO 228 * @reg_set: output set register (out=high) for generic GPIO
229 * @reg_clr: output clear register (out=low) for generic GPIO 229 * @reg_clr: output clear register (out=low) for generic GPIO
230 * @reg_dir: direction setting register for generic GPIO 230 * @reg_dir_out: direction out setting register for generic GPIO
231 * @bgpio_dir_inverted: indicates that the direction register is inverted 231 * @reg_dir_in: direction in setting register for generic GPIO
232 * (gpiolib private state variable) 232 * @bgpio_dir_unreadable: indicates that the direction register(s) cannot
233 * be read and we need to rely on out internal state tracking.
233 * @bgpio_bits: number of register bits used for a generic GPIO i.e. 234 * @bgpio_bits: number of register bits used for a generic GPIO i.e.
234 * <register width> * 8 235 * <register width> * 8
235 * @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep 236 * @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep
@@ -237,7 +238,8 @@ struct gpio_irq_chip {
237 * @bgpio_data: shadowed data register for generic GPIO to clear/set bits 238 * @bgpio_data: shadowed data register for generic GPIO to clear/set bits
238 * safely. 239 * safely.
239 * @bgpio_dir: shadowed direction register for generic GPIO to clear/set 240 * @bgpio_dir: shadowed direction register for generic GPIO to clear/set
240 * direction safely. 241 * direction safely. A "1" in this word means the line is set as
242 * output.
241 * 243 *
242 * A gpio_chip can help platforms abstract various sources of GPIOs so 244 * A gpio_chip can help platforms abstract various sources of GPIOs so
243 * they can all be accessed through a common programing interface. 245 * they can all be accessed through a common programing interface.
@@ -298,8 +300,9 @@ struct gpio_chip {
298 void __iomem *reg_dat; 300 void __iomem *reg_dat;
299 void __iomem *reg_set; 301 void __iomem *reg_set;
300 void __iomem *reg_clr; 302 void __iomem *reg_clr;
301 void __iomem *reg_dir; 303 void __iomem *reg_dir_out;
302 bool bgpio_dir_inverted; 304 void __iomem *reg_dir_in;
305 bool bgpio_dir_unreadable;
303 int bgpio_bits; 306 int bgpio_bits;
304 spinlock_t bgpio_lock; 307 spinlock_t bgpio_lock;
305 unsigned long bgpio_data; 308 unsigned long bgpio_data;
diff --git a/include/linux/gpio/machine.h b/include/linux/gpio/machine.h
index 69673be10213..35f299d1f6a7 100644
--- a/include/linux/gpio/machine.h
+++ b/include/linux/gpio/machine.h
@@ -6,14 +6,16 @@
6#include <linux/list.h> 6#include <linux/list.h>
7 7
8enum gpio_lookup_flags { 8enum gpio_lookup_flags {
9 GPIO_ACTIVE_HIGH = (0 << 0), 9 GPIO_ACTIVE_HIGH = (0 << 0),
10 GPIO_ACTIVE_LOW = (1 << 0), 10 GPIO_ACTIVE_LOW = (1 << 0),
11 GPIO_OPEN_DRAIN = (1 << 1), 11 GPIO_OPEN_DRAIN = (1 << 1),
12 GPIO_OPEN_SOURCE = (1 << 2), 12 GPIO_OPEN_SOURCE = (1 << 2),
13 GPIO_PERSISTENT = (0 << 3), 13 GPIO_PERSISTENT = (0 << 3),
14 GPIO_TRANSITORY = (1 << 3), 14 GPIO_TRANSITORY = (1 << 3),
15 GPIO_PULL_UP = (1 << 4), 15 GPIO_PULL_UP = (1 << 4),
16 GPIO_PULL_DOWN = (1 << 5), 16 GPIO_PULL_DOWN = (1 << 5),
17
18 GPIO_LOOKUP_FLAGS_DEFAULT = GPIO_ACTIVE_HIGH | GPIO_PERSISTENT,
17}; 19};
18 20
19/** 21/**
@@ -22,7 +24,7 @@ enum gpio_lookup_flags {
22 * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO 24 * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
23 * @con_id: name of the GPIO from the device's point of view 25 * @con_id: name of the GPIO from the device's point of view
24 * @idx: index of the GPIO in case several GPIOs share the same name 26 * @idx: index of the GPIO in case several GPIOs share the same name
25 * @flags: mask of GPIO_* values 27 * @flags: bitmask of gpio_lookup_flags GPIO_* values
26 * 28 *
27 * gpiod_lookup is a lookup table for associating GPIOs to specific devices and 29 * gpiod_lookup is a lookup table for associating GPIOs to specific devices and
28 * functions using platform data. 30 * functions using platform data.
@@ -32,7 +34,7 @@ struct gpiod_lookup {
32 u16 chip_hwnum; 34 u16 chip_hwnum;
33 const char *con_id; 35 const char *con_id;
34 unsigned int idx; 36 unsigned int idx;
35 enum gpio_lookup_flags flags; 37 unsigned long flags;
36}; 38};
37 39
38struct gpiod_lookup_table { 40struct gpiod_lookup_table {
@@ -46,7 +48,7 @@ struct gpiod_lookup_table {
46 * @chip_label: name of the chip the GPIO belongs to 48 * @chip_label: name of the chip the GPIO belongs to
47 * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO 49 * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
48 * @line_name: consumer name for the hogged line 50 * @line_name: consumer name for the hogged line
49 * @lflags: mask of GPIO lookup flags 51 * @lflags: bitmask of gpio_lookup_flags GPIO_* values
50 * @dflags: GPIO flags used to specify the direction and value 52 * @dflags: GPIO flags used to specify the direction and value
51 */ 53 */
52struct gpiod_hog { 54struct gpiod_hog {
@@ -54,7 +56,7 @@ struct gpiod_hog {
54 const char *chip_label; 56 const char *chip_label;
55 u16 chip_hwnum; 57 u16 chip_hwnum;
56 const char *line_name; 58 const char *line_name;
57 enum gpio_lookup_flags lflags; 59 unsigned long lflags;
58 int dflags; 60 int dflags;
59}; 61};
60 62
diff --git a/include/linux/platform_data/gpio-omap.h b/include/linux/platform_data/gpio-omap.h
index 6d07eebb3f75..7c36370c062e 100644
--- a/include/linux/platform_data/gpio-omap.h
+++ b/include/linux/platform_data/gpio-omap.h
@@ -200,8 +200,6 @@ struct omap_gpio_platform_data {
200 bool is_mpuio; /* whether the bank is of type MPUIO */ 200 bool is_mpuio; /* whether the bank is of type MPUIO */
201 u32 non_wakeup_gpios; 201 u32 non_wakeup_gpios;
202 202
203 u32 quirks; /* Version specific quirks mask */
204
205 struct omap_gpio_reg_offs *regs; 203 struct omap_gpio_reg_offs *regs;
206 204
207 /* Return context loss count due to PM states changing */ 205 /* Return context loss count due to PM states changing */
diff --git a/include/trace/events/gpio.h b/include/trace/events/gpio.h
index 5c189a22c489..3aa9fd86d748 100644
--- a/include/trace/events/gpio.h
+++ b/include/trace/events/gpio.h
@@ -2,10 +2,6 @@
2#undef TRACE_SYSTEM 2#undef TRACE_SYSTEM
3#define TRACE_SYSTEM gpio 3#define TRACE_SYSTEM gpio
4 4
5#ifndef CONFIG_TRACING_EVENTS_GPIO
6#define NOTRACE
7#endif
8
9#if !defined(_TRACE_GPIO_H) || defined(TRACE_HEADER_MULTI_READ) 5#if !defined(_TRACE_GPIO_H) || defined(TRACE_HEADER_MULTI_READ)
10#define _TRACE_GPIO_H 6#define _TRACE_GPIO_H
11 7
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index 8bd1d6d001d7..5d965cef6c77 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -774,13 +774,6 @@ config TRACE_EVAL_MAP_FILE
774 774
775 If unsure, say N 775 If unsure, say N
776 776
777config TRACING_EVENTS_GPIO
778 bool "Trace gpio events"
779 depends on GPIOLIB
780 default y
781 help
782 Enable tracing events for gpio subsystem
783
784config GCOV_PROFILE_FTRACE 777config GCOV_PROFILE_FTRACE
785 bool "Enable GCOV profiling on ftrace subsystem" 778 bool "Enable GCOV profiling on ftrace subsystem"
786 depends on GCOV_KERNEL 779 depends on GCOV_KERNEL