aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-09-04 13:07:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-09-04 13:07:45 -0400
commit8d2faea672606827c2018143ec7d88c760f2d6de (patch)
treeca92a524910afbd68b87a800fba64ad93abf5d67
parent02cf1da2548d318ad4db9eb4cf8656e24b11aefc (diff)
parent01e2dae991771adb1257eb5cd3cecfda1aa09ba9 (diff)
Merge tag 'gpio-v4.3-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 GPIO changes for the v4.3 kernel cycle. There is quite a lot going on in the GPIO subsystem this merge window, so the main matter is decribed below. The hits in other subsystems when making the GPIO flags optional are all ACKed by their respective subsystem maintainers. Core changes: - Root out the wrapper devm_gpiod_get() and gpiod_get() etc versions of the descriptor calls that did not use the flags argument on the end. This was around for too long and eventually Uwe Kleine-König took the time to clean it out and the last users are removed along with the macros in this tag. In several cases the use of flags simplifies the code. For this reason we have (ACKed) patches hitting in DRM, IIO, media, NFC, USB+PHY up until we hammer in the nail with removing the macros. - Add a fat document describing how much ready-made GPIO stuff we have i the kernel to discourage people from reinventing a square wheel in userspace, as so often happens. - Create a separate lockdep class for each instance of a GPIO IRQ chip instead of using one class for all chips, as the current code will not work with systems with several GPIO chips doing lockdep debugging. - Protect against driver unloading also when a GPIO line is only used as IRQ for the GPIOLIB_IRQCHIP helpers. - If the GPIO chip has no designated owner, assign the parent device driver owner as owner. - Consolidation of chained IRQ handler install/remove replacing all call sites where irq_set_handler_data() and irq_set_chained_handler() were done in succession with a combined call to irq_set_chained_handler_and_data(). This series was created by Thomas Gleixner after the problem was observed by Russell King. - Tglx also made another series of patches switching __irq_set_handler_locked() for irq_set_handler_locked() which is way cleaner. - Tglx and Jiang Liu wrote a good bunch of patches to make use of irq_desc_get_xxx() accessors and avoid looking up irq_descs from IRQ numbers. The goal is to get rid of the irq number from the handlers in the IRQ flow which is nice. - Rob Herring killed off the set_irq_flags() for all GPIO drivers. This was an ARM specific function that is replaced with the generic irq_modify_status() where special flags are actually needed. - When an OF node has a pin range for its GPIOs, return -EPROBE_DEFER if the pin controller isn't available. Pretty logical, yet needed to be fixed. - If a driver using GPIOLIB_IRQCHIP has its own irq_*_resources call back, then call these instead of the defaults provided by the GPIOLIB. - Fix an undocumented ABI hole: named GPIOs were not properly documented. Driver improvements: - Add get_direction() support to the generic GPIO driver, it's strange that we didn't have that before. - Make it possible to have input-only GPIO chips using the generic GPIO driver. - Clean out platform data support from the Emma Mobile (EM) driver - Finegrained runtime PM support for the RCAR driver. - Support r8a7795 (R-car H3) in the RCAR driver. - Support interrupts on GPIOs 16 thru 31 in the DaVinci driver. - Some consolidation and new support in the MPC8xxx driver, we now support MPC5125. - Preempt-RT-friendly patches: the OMAP, MPC8xxx, drivers uses raw spinlocks making it work better with the realime patches. - Interrupt support for the EXTRAXFS GPIO driver. - Make the ETRAXFS GPIO driver support also ARTPEC-3. - Interrupt and wakeup support for the BRCMSTB driver, also for wakeup from S5 cold boot. - Mask MXC IRQs during suspend. - Improve OMAP2 GPIO set_debounce() to work according to spec. - The VF610 driver handles IRQs properly. New drivers: - ZTE ZX GPIO driver" * tag 'gpio-v4.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (87 commits) Revert "gpio: extraxfs: fix returnvar.cocci warnings" gpio: tc3589x: use static container helper gpio: xlp: fix error return code gpio: vf610: handle level IRQ's properly gpio: max732x: Fix error handling in probe() gpio: omap: fix clk_prepare/unprepare usage gpio: omap: protect regs access in omap_gpio_irq_handler gpio: omap: fix omap2_set_gpio_debounce gpio: omap: switch to use platform_get_irq gpio: omap: remove wrong irq_domain_remove usage in probe gpiolib: add description for gpio irqchip fields in struct gpio_chip gpio: extraxfs: fix returnvar.cocci warnings gpiolib: irqchip: use different lockdep class for each gpio irqchip gpio/grgpio: fix deadlock in grgpio_irq_unmap() Documentation: gpio: consumer: describe active low property gpio: mxc: fix section mismatch warning gpio/mxc: mask gpio interrupts in suspend gpio: omap: Fix missing raw locks conversion gpio: brcmstb: support wakeup from S5 cold boot gpio: brcmstb: Add interrupt and wakeup source support ...
-rw-r--r--Documentation/ABI/testing/sysfs-gpio3
-rw-r--r--Documentation/devicetree/bindings/gpio/brcm,brcmstb-gpio.txt35
-rw-r--r--Documentation/devicetree/bindings/gpio/gpio-etraxfs.txt3
-rw-r--r--Documentation/devicetree/bindings/gpio/gpio-mpc8xxx.txt22
-rw-r--r--Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt1
-rw-r--r--Documentation/devicetree/bindings/gpio/zx296702-gpio.txt24
-rw-r--r--Documentation/gpio/00-INDEX3
-rw-r--r--Documentation/gpio/consumer.txt33
-rw-r--r--Documentation/gpio/drivers-on-gpio.txt95
-rw-r--r--Documentation/gpio/sysfs.txt9
-rw-r--r--drivers/gpio/Kconfig10
-rw-r--r--drivers/gpio/Makefile1
-rw-r--r--drivers/gpio/devres.c18
-rw-r--r--drivers/gpio/gpio-74xx-mmio.c2
-rw-r--r--drivers/gpio/gpio-adp5588.c10
-rw-r--r--drivers/gpio/gpio-altera.c4
-rw-r--r--drivers/gpio/gpio-bcm-kona.c17
-rw-r--r--drivers/gpio/gpio-brcmstb.c306
-rw-r--r--drivers/gpio/gpio-davinci.c16
-rw-r--r--drivers/gpio/gpio-dwapb.c2
-rw-r--r--drivers/gpio/gpio-em.c35
-rw-r--r--drivers/gpio/gpio-ep93xx.c8
-rw-r--r--drivers/gpio/gpio-etraxfs.c329
-rw-r--r--drivers/gpio/gpio-generic.c41
-rw-r--r--drivers/gpio/gpio-grgpio.c23
-rw-r--r--drivers/gpio/gpio-max732x.c11
-rw-r--r--drivers/gpio/gpio-mcp23s08.c4
-rw-r--r--drivers/gpio/gpio-mpc8xxx.c121
-rw-r--r--drivers/gpio/gpio-msm-v2.c23
-rw-r--r--drivers/gpio/gpio-mvebu.c8
-rw-r--r--drivers/gpio/gpio-mxc.c9
-rw-r--r--drivers/gpio/gpio-mxs.c2
-rw-r--r--drivers/gpio/gpio-omap.c156
-rw-r--r--drivers/gpio/gpio-pcf857x.c14
-rw-r--r--drivers/gpio/gpio-pch.c4
-rw-r--r--drivers/gpio/gpio-pxa.c8
-rw-r--r--drivers/gpio/gpio-rcar.c24
-rw-r--r--drivers/gpio/gpio-sa1100.c6
-rw-r--r--drivers/gpio/gpio-sta2x11.c2
-rw-r--r--drivers/gpio/gpio-tc3589x.c10
-rw-r--r--drivers/gpio/gpio-tegra.c9
-rw-r--r--drivers/gpio/gpio-timberdale.c12
-rw-r--r--drivers/gpio/gpio-tz1090.c4
-rw-r--r--drivers/gpio/gpio-vf610.c11
-rw-r--r--drivers/gpio/gpio-xlp.c2
-rw-r--r--drivers/gpio/gpio-zx.c324
-rw-r--r--drivers/gpio/gpio-zynq.c12
-rw-r--r--drivers/gpio/gpiolib-of.c34
-rw-r--r--drivers/gpio/gpiolib.c84
-rw-r--r--drivers/gpu/drm/msm/edp/edp_ctrl.c17
-rw-r--r--drivers/gpu/drm/tilcdc/tilcdc_panel.c22
-rw-r--r--drivers/iio/light/stk3310.c6
-rw-r--r--drivers/iio/magnetometer/bmc150_magn.c6
-rw-r--r--drivers/media/i2c/adp1653.c2
-rw-r--r--drivers/nfc/nxp-nci/i2c.c10
-rw-r--r--drivers/phy/phy-tusb1210.c30
-rw-r--r--include/linux/basic_mmio_gpio.h1
-rw-r--r--include/linux/gpio/consumer.h82
-rw-r--r--include/linux/gpio/driver.h37
-rw-r--r--include/linux/of_gpio.h4
-rw-r--r--include/linux/platform_data/gpio-em.h11
61 files changed, 1662 insertions, 510 deletions
diff --git a/Documentation/ABI/testing/sysfs-gpio b/Documentation/ABI/testing/sysfs-gpio
index 80f4c94c7bef..55ffa2df1c10 100644
--- a/Documentation/ABI/testing/sysfs-gpio
+++ b/Documentation/ABI/testing/sysfs-gpio
@@ -16,7 +16,8 @@ Description:
16 /sys/class/gpio 16 /sys/class/gpio
17 /export ... asks the kernel to export a GPIO to userspace 17 /export ... asks the kernel to export a GPIO to userspace
18 /unexport ... to return a GPIO to the kernel 18 /unexport ... to return a GPIO to the kernel
19 /gpioN ... for each exported GPIO #N 19 /gpioN ... for each exported GPIO #N OR
20 /<LINE-NAME> ... for a properly named GPIO line
20 /value ... always readable, writes fail for input GPIOs 21 /value ... always readable, writes fail for input GPIOs
21 /direction ... r/w as: in, out (default low); write: high, low 22 /direction ... r/w as: in, out (default low); write: high, low
22 /edge ... r/w as: none, falling, rising, both 23 /edge ... r/w as: none, falling, rising, both
diff --git a/Documentation/devicetree/bindings/gpio/brcm,brcmstb-gpio.txt b/Documentation/devicetree/bindings/gpio/brcm,brcmstb-gpio.txt
index 435f1bcca341..b405b4410bfb 100644
--- a/Documentation/devicetree/bindings/gpio/brcm,brcmstb-gpio.txt
+++ b/Documentation/devicetree/bindings/gpio/brcm,brcmstb-gpio.txt
@@ -33,6 +33,13 @@ Optional properties:
33- interrupt-parent: 33- interrupt-parent:
34 phandle of the parent interrupt controller 34 phandle of the parent interrupt controller
35 35
36- interrupts-extended:
37 Alternate form of specifying interrupts and parents that allows for
38 multiple parents. This takes precedence over 'interrupts' and
39 'interrupt-parent'. Wakeup-capable GPIO controllers often route their
40 wakeup interrupt lines through a different interrupt controller than the
41 primary interrupt line, making this property necessary.
42
36- #interrupt-cells: 43- #interrupt-cells:
37 Should be <2>. The first cell is the GPIO number, the second should specify 44 Should be <2>. The first cell is the GPIO number, the second should specify
38 flags. The following subset of flags is supported: 45 flags. The following subset of flags is supported:
@@ -47,19 +54,33 @@ Optional properties:
47- interrupt-controller: 54- interrupt-controller:
48 Marks the device node as an interrupt controller 55 Marks the device node as an interrupt controller
49 56
50- interrupt-names: 57- wakeup-source:
51 The name of the IRQ resource used by this controller 58 GPIOs for this controller can be used as a wakeup source
52 59
53Example: 60Example:
54 upg_gio: gpio@f040a700 { 61 upg_gio: gpio@f040a700 {
55 #gpio-cells = <0x2>; 62 #gpio-cells = <2>;
56 #interrupt-cells = <0x2>; 63 #interrupt-cells = <2>;
57 compatible = "brcm,bcm7445-gpio", "brcm,brcmstb-gpio"; 64 compatible = "brcm,bcm7445-gpio", "brcm,brcmstb-gpio";
58 gpio-controller; 65 gpio-controller;
59 interrupt-controller; 66 interrupt-controller;
60 reg = <0xf040a700 0x80>; 67 reg = <0xf040a700 0x80>;
61 interrupt-parent = <0xf>; 68 interrupt-parent = <&irq0_intc>;
69 interrupts = <0x6>;
70 brcm,gpio-bank-widths = <32 32 32 24>;
71 };
72
73 upg_gio_aon: gpio@f04172c0 {
74 #gpio-cells = <2>;
75 #interrupt-cells = <2>;
76 compatible = "brcm,bcm7445-gpio", "brcm,brcmstb-gpio";
77 gpio-controller;
78 interrupt-controller;
79 reg = <0xf04172c0 0x40>;
80 interrupt-parent = <&irq0_aon_intc>;
62 interrupts = <0x6>; 81 interrupts = <0x6>;
63 interrupt-names = "upg_gio"; 82 interrupts-extended = <&irq0_aon_intc 0x6>,
64 brcm,gpio-bank-widths = <0x20 0x20 0x20 0x18>; 83 <&aon_pm_l2_intc 0x5>;
84 wakeup-source;
85 brcm,gpio-bank-widths = <18 4>;
65 }; 86 };
diff --git a/Documentation/devicetree/bindings/gpio/gpio-etraxfs.txt b/Documentation/devicetree/bindings/gpio/gpio-etraxfs.txt
index abf4db736c6e..170194af3027 100644
--- a/Documentation/devicetree/bindings/gpio/gpio-etraxfs.txt
+++ b/Documentation/devicetree/bindings/gpio/gpio-etraxfs.txt
@@ -2,8 +2,9 @@ Axis ETRAX FS General I/O controller bindings
2 2
3Required properties: 3Required properties:
4 4
5- compatible: 5- compatible: one of:
6 - "axis,etraxfs-gio" 6 - "axis,etraxfs-gio"
7 - "axis,artpec3-gio"
7- reg: Physical base address and length of the controller's registers. 8- reg: Physical base address and length of the controller's registers.
8- #gpio-cells: Should be 3 9- #gpio-cells: Should be 3
9 - The first cell is the gpio offset number. 10 - The first cell is the gpio offset number.
diff --git a/Documentation/devicetree/bindings/gpio/gpio-mpc8xxx.txt b/Documentation/devicetree/bindings/gpio/gpio-mpc8xxx.txt
new file mode 100644
index 000000000000..805ddcd79a57
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/gpio-mpc8xxx.txt
@@ -0,0 +1,22 @@
1* Freescale MPC512x/MPC8xxx GPIO controller
2
3Required properties:
4- compatible : Should be "fsl,<soc>-gpio"
5 The following <soc>s are known to be supported:
6 mpc5121, mpc5125, mpc8349, mpc8572, mpc8610, pq3, qoriq
7- reg : Address and length of the register set for the device
8- interrupts : Should be the port interrupt shared by all 32 pins.
9- #gpio-cells : Should be two. The first cell is the pin number and
10 the second cell is used to specify the gpio polarity:
11 0 = active high
12 1 = active low
13
14Example:
15
16gpio0: gpio@1100 {
17 compatible = "fsl,mpc5125-gpio";
18 #gpio-cells = <2>;
19 reg = <0x1100 0x080>;
20 interrupts = <78 0x8>;
21 status = "okay";
22};
diff --git a/Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt b/Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt
index 38fb86f28ba2..f60e2f477e93 100644
--- a/Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt
+++ b/Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt
@@ -9,6 +9,7 @@ Required Properties:
9 - "renesas,gpio-r8a7791": for R8A7791 (R-Car M2-W) compatible GPIO controller. 9 - "renesas,gpio-r8a7791": for R8A7791 (R-Car M2-W) compatible GPIO controller.
10 - "renesas,gpio-r8a7793": for R8A7793 (R-Car M2-N) compatible GPIO controller. 10 - "renesas,gpio-r8a7793": for R8A7793 (R-Car M2-N) compatible GPIO controller.
11 - "renesas,gpio-r8a7794": for R8A7794 (R-Car E2) compatible GPIO controller. 11 - "renesas,gpio-r8a7794": for R8A7794 (R-Car E2) compatible GPIO controller.
12 - "renesas,gpio-r8a7795": for R8A7795 (R-Car H3) compatible GPIO controller.
12 - "renesas,gpio-rcar": for generic R-Car GPIO controller. 13 - "renesas,gpio-rcar": for generic R-Car GPIO controller.
13 14
14 - reg: Base address and length of each memory resource used by the GPIO 15 - reg: Base address and length of each memory resource used by the GPIO
diff --git a/Documentation/devicetree/bindings/gpio/zx296702-gpio.txt b/Documentation/devicetree/bindings/gpio/zx296702-gpio.txt
new file mode 100644
index 000000000000..0dab156fcf41
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/zx296702-gpio.txt
@@ -0,0 +1,24 @@
1ZTE ZX296702 GPIO controller
2
3Required properties:
4- compatible : "zte,zx296702-gpio"
5- #gpio-cells : Should be two. The first cell is the pin number and the
6 second cell is used to specify optional parameters:
7 - bit 0 specifies polarity (0 for normal, 1 for inverted)
8- gpio-controller : Marks the device node as a GPIO controller.
9- interrupts : Interrupt mapping for GPIO IRQ.
10- gpio-ranges : Interaction with the PINCTRL subsystem.
11
12gpio1: gpio@b008040 {
13 compatible = "zte,zx296702-gpio";
14 reg = <0xb008040 0x40>;
15 gpio-controller;
16 #gpio-cells = <2>;
17 gpio-ranges = < &pmx0 0 54 2 &pmx0 2 59 14>;
18 interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
19 interrupt-parent = <&intc>;
20 interrupt-controller;
21 #interrupt-cells = <2>;
22 clock-names = "gpio_pclk";
23 clocks = <&lsp0clk ZX296702_GPIO_CLK>;
24};
diff --git a/Documentation/gpio/00-INDEX b/Documentation/gpio/00-INDEX
index 1de43ae46ae6..179beb234f98 100644
--- a/Documentation/gpio/00-INDEX
+++ b/Documentation/gpio/00-INDEX
@@ -6,6 +6,9 @@ consumer.txt
6 - How to obtain and use GPIOs in a driver 6 - How to obtain and use GPIOs in a driver
7driver.txt 7driver.txt
8 - How to write a GPIO driver 8 - How to write a GPIO driver
9drivers-on-gpio.txt:
10 - Drivers in other subsystems that can use GPIO to provide more
11 complex functionality.
9board.txt 12board.txt
10 - How to assign GPIOs to a consumer device and a function 13 - How to assign GPIOs to a consumer device and a function
11sysfs.txt 14sysfs.txt
diff --git a/Documentation/gpio/consumer.txt b/Documentation/gpio/consumer.txt
index 75542b91b766..a206639454ab 100644
--- a/Documentation/gpio/consumer.txt
+++ b/Documentation/gpio/consumer.txt
@@ -237,6 +237,39 @@ Note that these functions should only be used with great moderation ; a driver
237should not have to care about the physical line level. 237should not have to care about the physical line level.
238 238
239 239
240The active-low property
241-----------------------
242
243As a driver should not have to care about the physical line level, all of the
244gpiod_set_value_xxx() or gpiod_set_array_value_xxx() functions operate with
245the *logical* value. With this they take the active-low property into account.
246This means that they check whether the GPIO is configured to be active-low,
247and if so, they manipulate the passed value before the physical line level is
248driven.
249
250With this, all the gpiod_set_(array)_value_xxx() functions interpret the
251parameter "value" as "active" ("1") or "inactive" ("0"). The physical line
252level will be driven accordingly.
253
254As an example, if the active-low property for a dedicated GPIO is set, and the
255gpiod_set_(array)_value_xxx() passes "active" ("1"), the physical line level
256will be driven low.
257
258To summarize:
259
260Function (example) active-low proporty physical line
261gpiod_set_raw_value(desc, 0); don't care low
262gpiod_set_raw_value(desc, 1); don't care high
263gpiod_set_value(desc, 0); default (active-high) low
264gpiod_set_value(desc, 1); default (active-high) high
265gpiod_set_value(desc, 0); active-low high
266gpiod_set_value(desc, 1); active-low low
267
268Please note again that the set_raw/get_raw functions should be avoided as much
269as possible, especially by drivers which should not care about the actual
270physical line level and worry about the logical value instead.
271
272
240Set multiple GPIO outputs with a single function call 273Set multiple GPIO outputs with a single function call
241----------------------------------------------------- 274-----------------------------------------------------
242The following functions set the output values of an array of GPIOs: 275The following functions set the output values of an array of GPIOs:
diff --git a/Documentation/gpio/drivers-on-gpio.txt b/Documentation/gpio/drivers-on-gpio.txt
new file mode 100644
index 000000000000..f6121328630f
--- /dev/null
+++ b/Documentation/gpio/drivers-on-gpio.txt
@@ -0,0 +1,95 @@
1Subsystem drivers using GPIO
2============================
3
4Note that standard kernel drivers exist for common GPIO tasks and will provide
5the right in-kernel and userspace APIs/ABIs for the job, and that these
6drivers can quite easily interconnect with other kernel subsystems using
7hardware descriptions such as device tree or ACPI:
8
9- leds-gpio: drivers/leds/leds-gpio.c will handle LEDs connected to GPIO
10 lines, giving you the LED sysfs interface
11
12- ledtrig-gpio: drivers/leds/trigger/ledtrig-gpio.c will provide a LED trigger,
13 i.e. a LED will turn on/off in response to a GPIO line going high or low
14 (and that LED may in turn use the leds-gpio as per above).
15
16- gpio-keys: drivers/input/keyboard/gpio_keys.c is used when your GPIO line
17 can generate interrupts in response to a key press. Also supports debounce.
18
19- gpio-keys-polled: drivers/input/keyboard/gpio_keys_polled.c is used when your
20 GPIO line cannot generate interrupts, so it needs to be periodically polled
21 by a timer.
22
23- gpio_mouse: drivers/input/mouse/gpio_mouse.c is used to provide a mouse with
24 up to three buttons by simply using GPIOs and no mouse port. You can cut the
25 mouse cable and connect the wires to GPIO lines or solder a mouse connector
26 to the lines for a more permanent solution of this type.
27
28- gpio-beeper: drivers/input/misc/gpio-beeper.c is used to provide a beep from
29 an external speaker connected to a GPIO line.
30
31- gpio-tilt-polled: drivers/input/misc/gpio_tilt_polled.c provides tilt
32 detection switches using GPIO, which is useful for your homebrewn pinball
33 machine if for nothing else. It can detect different tilt angles of the
34 monitored object.
35
36- extcon-gpio: drivers/extcon/extcon-gpio.c is used when you need to read an
37 external connector status, such as a headset line for an audio driver or an
38 HDMI connector. It will provide a better userspace sysfs interface than GPIO.
39
40- restart-gpio: drivers/power/gpio-restart.c is used to restart/reboot the
41 system by pulling a GPIO line and will register a restart handler so
42 userspace can issue the right system call to restart the system.
43
44- poweroff-gpio: drivers/power/gpio-poweroff.c is used to power the system down
45 by pulling a GPIO line and will register a pm_power_off() callback so that
46 userspace can issue the right system call to power down the system.
47
48- gpio-gate-clock: drivers/clk/clk-gpio-gate.c is used to control a gated clock
49 (off/on) that uses a GPIO, and integrated with the clock subsystem.
50
51- i2c-gpio: drivers/i2c/busses/i2c-gpio.c is used to drive an I2C bus
52 (two wires, SDA and SCL lines) by hammering (bitbang) two GPIO lines. It will
53 appear as any other I2C bus to the system and makes it possible to connect
54 drivers for the I2C devices on the bus like any other I2C bus driver.
55
56- spi_gpio: drivers/spi/spi-gpio.c is used to drive an SPI bus (variable number
57 of wires, atleast SCK and optionally MISO, MOSI and chip select lines) using
58 GPIO hammering (bitbang). It will appear as any other SPI bus on the system
59 and makes it possible to connect drivers for SPI devices on the bus like
60 any other SPI bus driver. For example any MMC/SD card can then be connected
61 to this SPI by using the mmc_spi host from the MMC/SD card subsystem.
62
63- w1-gpio: drivers/w1/masters/w1-gpio.c is used to drive a one-wire bus using
64 a GPIO line, integrating with the W1 subsystem and handling devices on
65 the bus like any other W1 device.
66
67- gpio-fan: drivers/hwmon/gpio-fan.c is used to control a fan for cooling the
68 system, connected to a GPIO line (and optionally a GPIO alarm line),
69 presenting all the right in-kernel and sysfs interfaces to make your system
70 not overheat.
71
72- gpio-regulator: drivers/regulator/gpio-regulator.c is used to control a
73 regulator providing a certain voltage by pulling a GPIO line, integrating
74 with the regulator subsystem and giving you all the right interfaces.
75
76- gpio-wdt: drivers/watchdog/gpio_wdt.c is used to provide a watchdog timer
77 that will periodically "ping" a hardware connected to a GPIO line by toggling
78 it from 1-to-0-to-1. If that hardware does not recieve its "ping"
79 periodically, it will reset the system.
80
81- gpio-nand: drivers/mtd/nand/gpio.c is used to connect a NAND flash chip to
82 a set of simple GPIO lines: RDY, NCE, ALE, CLE, NWP. It interacts with the
83 NAND flash MTD subsystem and provides chip access and partition parsing like
84 any other NAND driving hardware.
85
86Apart from this there are special GPIO drivers in subsystems like MMC/SD to
87read card detect and write protect GPIO lines, and in the TTY serial subsystem
88to emulate MCTRL (modem control) signals CTS/RTS by using two GPIO lines. The
89MTD NOR flash has add-ons for extra GPIO lines too, though the address bus is
90usually connected directly to the flash.
91
92Use those instead of talking directly to the GPIOs using sysfs; they integrate
93with kernel frameworks better than your userspace code could. Needless to say,
94just using the apropriate kernel drivers will simplify and speed up your
95embedded hacking in particular by providing ready-made components.
diff --git a/Documentation/gpio/sysfs.txt b/Documentation/gpio/sysfs.txt
index 535b6a8a7a7c..0700b55637f5 100644
--- a/Documentation/gpio/sysfs.txt
+++ b/Documentation/gpio/sysfs.txt
@@ -20,11 +20,10 @@ userspace GPIO can be used to determine system configuration data that
20standard kernels won't know about. And for some tasks, simple userspace 20standard kernels won't know about. And for some tasks, simple userspace
21GPIO drivers could be all that the system really needs. 21GPIO drivers could be all that the system really needs.
22 22
23Note that standard kernel drivers exist for common "LEDs and Buttons" 23DO NOT ABUSE SYFS TO CONTROL HARDWARE THAT HAS PROPER KERNEL DRIVERS.
24GPIO tasks: "leds-gpio" and "gpio_keys", respectively. Use those 24PLEASE READ THE DOCUMENT NAMED "drivers-on-gpio.txt" IN THIS DOCUMENTATION
25instead of talking directly to the GPIOs; they integrate with kernel 25DIRECTORY TO AVOID REINVENTING KERNEL WHEELS IN USERSPACE. I MEAN IT.
26frameworks better than your userspace code could. 26REALLY.
27
28 27
29Paths in Sysfs 28Paths in Sysfs
30-------------- 29--------------
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 8f1fe739c985..b4fc9e4d24c6 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -113,7 +113,6 @@ config GPIO_74XX_MMIO
113config GPIO_ALTERA 113config GPIO_ALTERA
114 tristate "Altera GPIO" 114 tristate "Altera GPIO"
115 depends on OF_GPIO 115 depends on OF_GPIO
116 select GPIO_GENERIC
117 select GPIOLIB_IRQCHIP 116 select GPIOLIB_IRQCHIP
118 help 117 help
119 Say Y or M here to build support for the Altera PIO device. 118 Say Y or M here to build support for the Altera PIO device.
@@ -131,6 +130,7 @@ config GPIO_BRCMSTB
131 default y if ARCH_BRCMSTB 130 default y if ARCH_BRCMSTB
132 depends on OF_GPIO && (ARCH_BRCMSTB || COMPILE_TEST) 131 depends on OF_GPIO && (ARCH_BRCMSTB || COMPILE_TEST)
133 select GPIO_GENERIC 132 select GPIO_GENERIC
133 select GPIOLIB_IRQCHIP
134 help 134 help
135 Say yes here to enable GPIO support for Broadcom STB (BCM7XXX) SoCs. 135 Say yes here to enable GPIO support for Broadcom STB (BCM7XXX) SoCs.
136 136
@@ -172,6 +172,7 @@ config GPIO_ETRAXFS
172 depends on CRIS || COMPILE_TEST 172 depends on CRIS || COMPILE_TEST
173 depends on OF 173 depends on OF
174 select GPIO_GENERIC 174 select GPIO_GENERIC
175 select GPIOLIB_IRQCHIP
175 help 176 help
176 Say yes here to support the GPIO controller on Axis ETRAX FS SoCs. 177 Say yes here to support the GPIO controller on Axis ETRAX FS SoCs.
177 178
@@ -308,7 +309,6 @@ config GPIO_MVEBU
308 def_bool y 309 def_bool y
309 depends on PLAT_ORION 310 depends on PLAT_ORION
310 depends on OF 311 depends on OF
311 select GPIO_GENERIC
312 select GENERIC_IRQ_CHIP 312 select GENERIC_IRQ_CHIP
313 313
314config GPIO_MXC 314config GPIO_MXC
@@ -1005,6 +1005,12 @@ config GPIO_MC33880
1005 SPI driver for Freescale MC33880 high-side/low-side switch. 1005 SPI driver for Freescale MC33880 high-side/low-side switch.
1006 This provides GPIO interface supporting inputs and outputs. 1006 This provides GPIO interface supporting inputs and outputs.
1007 1007
1008config GPIO_ZX
1009 bool "ZTE ZX GPIO support"
1010 select GPIOLIB_IRQCHIP
1011 help
1012 Say yes here to support the GPIO device on ZTE ZX SoCs.
1013
1008endmenu 1014endmenu
1009 1015
1010menu "USB GPIO expanders" 1016menu "USB GPIO expanders"
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 2b64f6177e33..f79a7c482a99 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -117,3 +117,4 @@ obj-$(CONFIG_GPIO_XLP) += gpio-xlp.o
117obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o 117obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o
118obj-$(CONFIG_GPIO_ZEVIO) += gpio-zevio.o 118obj-$(CONFIG_GPIO_ZEVIO) += gpio-zevio.o
119obj-$(CONFIG_GPIO_ZYNQ) += gpio-zynq.o 119obj-$(CONFIG_GPIO_ZYNQ) += gpio-zynq.o
120obj-$(CONFIG_GPIO_ZX) += gpio-zx.o
diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c
index 07ba82317ece..903fcf4d04a0 100644
--- a/drivers/gpio/devres.c
+++ b/drivers/gpio/devres.c
@@ -59,13 +59,13 @@ static int devm_gpiod_match_array(struct device *dev, void *res, void *data)
59 * automatically disposed on driver detach. See gpiod_get() for detailed 59 * automatically disposed on driver detach. See gpiod_get() for detailed
60 * information about behavior and return values. 60 * information about behavior and return values.
61 */ 61 */
62struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, 62struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
63 const char *con_id, 63 const char *con_id,
64 enum gpiod_flags flags) 64 enum gpiod_flags flags)
65{ 65{
66 return devm_gpiod_get_index(dev, con_id, 0, flags); 66 return devm_gpiod_get_index(dev, con_id, 0, flags);
67} 67}
68EXPORT_SYMBOL(__devm_gpiod_get); 68EXPORT_SYMBOL(devm_gpiod_get);
69 69
70/** 70/**
71 * devm_gpiod_get_optional - Resource-managed gpiod_get_optional() 71 * devm_gpiod_get_optional - Resource-managed gpiod_get_optional()
@@ -77,13 +77,13 @@ EXPORT_SYMBOL(__devm_gpiod_get);
77 * are automatically disposed on driver detach. See gpiod_get_optional() for 77 * are automatically disposed on driver detach. See gpiod_get_optional() for
78 * detailed information about behavior and return values. 78 * detailed information about behavior and return values.
79 */ 79 */
80struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, 80struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
81 const char *con_id, 81 const char *con_id,
82 enum gpiod_flags flags) 82 enum gpiod_flags flags)
83{ 83{
84 return devm_gpiod_get_index_optional(dev, con_id, 0, flags); 84 return devm_gpiod_get_index_optional(dev, con_id, 0, flags);
85} 85}
86EXPORT_SYMBOL(__devm_gpiod_get_optional); 86EXPORT_SYMBOL(devm_gpiod_get_optional);
87 87
88/** 88/**
89 * devm_gpiod_get_index - Resource-managed gpiod_get_index() 89 * devm_gpiod_get_index - Resource-managed gpiod_get_index()
@@ -96,7 +96,7 @@ EXPORT_SYMBOL(__devm_gpiod_get_optional);
96 * automatically disposed on driver detach. See gpiod_get_index() for detailed 96 * automatically disposed on driver detach. See gpiod_get_index() for detailed
97 * information about behavior and return values. 97 * information about behavior and return values.
98 */ 98 */
99struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev, 99struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
100 const char *con_id, 100 const char *con_id,
101 unsigned int idx, 101 unsigned int idx,
102 enum gpiod_flags flags) 102 enum gpiod_flags flags)
@@ -120,7 +120,7 @@ struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev,
120 120
121 return desc; 121 return desc;
122} 122}
123EXPORT_SYMBOL(__devm_gpiod_get_index); 123EXPORT_SYMBOL(devm_gpiod_get_index);
124 124
125/** 125/**
126 * devm_get_gpiod_from_child - get a GPIO descriptor from a device's child node 126 * devm_get_gpiod_from_child - get a GPIO descriptor from a device's child node
@@ -182,10 +182,10 @@ EXPORT_SYMBOL(devm_get_gpiod_from_child);
182 * gpiod_get_index_optional() for detailed information about behavior and 182 * gpiod_get_index_optional() for detailed information about behavior and
183 * return values. 183 * return values.
184 */ 184 */
185struct gpio_desc *__must_check __devm_gpiod_get_index_optional(struct device *dev, 185struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev,
186 const char *con_id, 186 const char *con_id,
187 unsigned int index, 187 unsigned int index,
188 enum gpiod_flags flags) 188 enum gpiod_flags flags)
189{ 189{
190 struct gpio_desc *desc; 190 struct gpio_desc *desc;
191 191
@@ -197,7 +197,7 @@ struct gpio_desc *__must_check __devm_gpiod_get_index_optional(struct device *de
197 197
198 return desc; 198 return desc;
199} 199}
200EXPORT_SYMBOL(__devm_gpiod_get_index_optional); 200EXPORT_SYMBOL(devm_gpiod_get_index_optional);
201 201
202/** 202/**
203 * devm_gpiod_get_array - Resource-managed gpiod_get_array() 203 * devm_gpiod_get_array - Resource-managed gpiod_get_array()
diff --git a/drivers/gpio/gpio-74xx-mmio.c b/drivers/gpio/gpio-74xx-mmio.c
index 0763655cca6c..6ed7c0fb3378 100644
--- a/drivers/gpio/gpio-74xx-mmio.c
+++ b/drivers/gpio/gpio-74xx-mmio.c
@@ -129,7 +129,7 @@ static int mmio_74xx_gpio_probe(struct platform_device *pdev)
129 if (IS_ERR(dat)) 129 if (IS_ERR(dat))
130 return PTR_ERR(dat); 130 return PTR_ERR(dat);
131 131
132 priv->flags = (unsigned)of_id->data; 132 priv->flags = (uintptr_t) of_id->data;
133 133
134 err = bgpio_init(&priv->bgc, &pdev->dev, 134 err = bgpio_init(&priv->bgc, &pdev->dev,
135 DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8), 135 DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8),
diff --git a/drivers/gpio/gpio-adp5588.c b/drivers/gpio/gpio-adp5588.c
index d3fe6a6776da..984186ee58a0 100644
--- a/drivers/gpio/gpio-adp5588.c
+++ b/drivers/gpio/gpio-adp5588.c
@@ -305,15 +305,7 @@ static int adp5588_irq_setup(struct adp5588_gpio *dev)
305 irq_set_chip_and_handler(irq, &adp5588_irq_chip, 305 irq_set_chip_and_handler(irq, &adp5588_irq_chip,
306 handle_level_irq); 306 handle_level_irq);
307 irq_set_nested_thread(irq, 1); 307 irq_set_nested_thread(irq, 1);
308#ifdef CONFIG_ARM 308 irq_modify_status(irq, IRQ_NOREQUEST, IRQ_NOPROBE);
309 /*
310 * ARM needs us to explicitly flag the IRQ as VALID,
311 * once we do so, it will also set the noprobe.
312 */
313 set_irq_flags(irq, IRQF_VALID);
314#else
315 irq_set_noprobe(irq);
316#endif
317 } 309 }
318 310
319 ret = request_threaded_irq(client->irq, 311 ret = request_threaded_irq(client->irq,
diff --git a/drivers/gpio/gpio-altera.c b/drivers/gpio/gpio-altera.c
index 0f3d336d6303..9b7e0b3db387 100644
--- a/drivers/gpio/gpio-altera.c
+++ b/drivers/gpio/gpio-altera.c
@@ -338,9 +338,9 @@ static int altera_gpio_remove(struct platform_device *pdev)
338{ 338{
339 struct altera_gpio_chip *altera_gc = platform_get_drvdata(pdev); 339 struct altera_gpio_chip *altera_gc = platform_get_drvdata(pdev);
340 340
341 gpiochip_remove(&altera_gc->mmchip.gc); 341 of_mm_gpiochip_remove(&altera_gc->mmchip);
342 342
343 return -EIO; 343 return 0;
344} 344}
345 345
346static const struct of_device_id altera_gpio_of_match[] = { 346static const struct of_device_id altera_gpio_of_match[] = {
diff --git a/drivers/gpio/gpio-bcm-kona.c b/drivers/gpio/gpio-bcm-kona.c
index 40343fa92c7b..31b90ac15204 100644
--- a/drivers/gpio/gpio-bcm-kona.c
+++ b/drivers/gpio/gpio-bcm-kona.c
@@ -438,7 +438,7 @@ static void bcm_kona_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
438 void __iomem *reg_base; 438 void __iomem *reg_base;
439 int bit, bank_id; 439 int bit, bank_id;
440 unsigned long sta; 440 unsigned long sta;
441 struct bcm_kona_gpio_bank *bank = irq_get_handler_data(irq); 441 struct bcm_kona_gpio_bank *bank = irq_desc_get_handler_data(desc);
442 struct irq_chip *chip = irq_desc_get_chip(desc); 442 struct irq_chip *chip = irq_desc_get_chip(desc);
443 443
444 chained_irq_enter(chip, desc); 444 chained_irq_enter(chip, desc);
@@ -525,11 +525,7 @@ static int bcm_kona_gpio_irq_map(struct irq_domain *d, unsigned int irq,
525 return ret; 525 return ret;
526 irq_set_lockdep_class(irq, &gpio_lock_class); 526 irq_set_lockdep_class(irq, &gpio_lock_class);
527 irq_set_chip_and_handler(irq, &bcm_gpio_irq_chip, handle_simple_irq); 527 irq_set_chip_and_handler(irq, &bcm_gpio_irq_chip, handle_simple_irq);
528#ifdef CONFIG_ARM
529 set_irq_flags(irq, IRQF_VALID);
530#else
531 irq_set_noprobe(irq); 528 irq_set_noprobe(irq);
532#endif
533 529
534 return 0; 530 return 0;
535} 531}
@@ -644,17 +640,6 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev)
644 dev_err(dev, "Couldn't add GPIO chip -- %d\n", ret); 640 dev_err(dev, "Couldn't add GPIO chip -- %d\n", ret);
645 goto err_irq_domain; 641 goto err_irq_domain;
646 } 642 }
647 for (i = 0; i < chip->ngpio; i++) {
648 int irq = bcm_kona_gpio_to_irq(chip, i);
649 irq_set_lockdep_class(irq, &gpio_lock_class);
650 irq_set_chip_and_handler(irq, &bcm_gpio_irq_chip,
651 handle_simple_irq);
652#ifdef CONFIG_ARM
653 set_irq_flags(irq, IRQF_VALID);
654#else
655 irq_set_noprobe(irq);
656#endif
657 }
658 for (i = 0; i < kona_gpio->num_bank; i++) { 643 for (i = 0; i < kona_gpio->num_bank; i++) {
659 bank = &kona_gpio->banks[i]; 644 bank = &kona_gpio->banks[i];
660 irq_set_chained_handler_and_data(bank->irq, 645 irq_set_chained_handler_and_data(bank->irq,
diff --git a/drivers/gpio/gpio-brcmstb.c b/drivers/gpio/gpio-brcmstb.c
index 4630a8133ea6..9ea86d2ac054 100644
--- a/drivers/gpio/gpio-brcmstb.c
+++ b/drivers/gpio/gpio-brcmstb.c
@@ -17,6 +17,10 @@
17#include <linux/of_irq.h> 17#include <linux/of_irq.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/basic_mmio_gpio.h> 19#include <linux/basic_mmio_gpio.h>
20#include <linux/irqdomain.h>
21#include <linux/irqchip/chained_irq.h>
22#include <linux/interrupt.h>
23#include <linux/reboot.h>
20 24
21#define GIO_BANK_SIZE 0x20 25#define GIO_BANK_SIZE 0x20
22#define GIO_ODEN(bank) (((bank) * GIO_BANK_SIZE) + 0x00) 26#define GIO_ODEN(bank) (((bank) * GIO_BANK_SIZE) + 0x00)
@@ -34,14 +38,18 @@ struct brcmstb_gpio_bank {
34 struct bgpio_chip bgc; 38 struct bgpio_chip bgc;
35 struct brcmstb_gpio_priv *parent_priv; 39 struct brcmstb_gpio_priv *parent_priv;
36 u32 width; 40 u32 width;
41 struct irq_chip irq_chip;
37}; 42};
38 43
39struct brcmstb_gpio_priv { 44struct brcmstb_gpio_priv {
40 struct list_head bank_list; 45 struct list_head bank_list;
41 void __iomem *reg_base; 46 void __iomem *reg_base;
42 int num_banks;
43 struct platform_device *pdev; 47 struct platform_device *pdev;
48 int parent_irq;
44 int gpio_base; 49 int gpio_base;
50 bool can_wake;
51 int parent_wake_irq;
52 struct notifier_block reboot_notifier;
45}; 53};
46 54
47#define MAX_GPIO_PER_BANK 32 55#define MAX_GPIO_PER_BANK 32
@@ -63,6 +71,203 @@ brcmstb_gpio_gc_to_priv(struct gpio_chip *gc)
63 return bank->parent_priv; 71 return bank->parent_priv;
64} 72}
65 73
74static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank,
75 unsigned int offset, bool enable)
76{
77 struct bgpio_chip *bgc = &bank->bgc;
78 struct brcmstb_gpio_priv *priv = bank->parent_priv;
79 u32 mask = bgc->pin2mask(bgc, offset);
80 u32 imask;
81 unsigned long flags;
82
83 spin_lock_irqsave(&bgc->lock, flags);
84 imask = bgc->read_reg(priv->reg_base + GIO_MASK(bank->id));
85 if (enable)
86 imask |= mask;
87 else
88 imask &= ~mask;
89 bgc->write_reg(priv->reg_base + GIO_MASK(bank->id), imask);
90 spin_unlock_irqrestore(&bgc->lock, flags);
91}
92
93/* -------------------- IRQ chip functions -------------------- */
94
95static void brcmstb_gpio_irq_mask(struct irq_data *d)
96{
97 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
98 struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc);
99
100 brcmstb_gpio_set_imask(bank, d->hwirq, false);
101}
102
103static void brcmstb_gpio_irq_unmask(struct irq_data *d)
104{
105 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
106 struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc);
107
108 brcmstb_gpio_set_imask(bank, d->hwirq, true);
109}
110
111static int brcmstb_gpio_irq_set_type(struct irq_data *d, unsigned int type)
112{
113 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
114 struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc);
115 struct brcmstb_gpio_priv *priv = bank->parent_priv;
116 u32 mask = BIT(d->hwirq);
117 u32 edge_insensitive, iedge_insensitive;
118 u32 edge_config, iedge_config;
119 u32 level, ilevel;
120 unsigned long flags;
121
122 switch (type) {
123 case IRQ_TYPE_LEVEL_LOW:
124 level = 0;
125 edge_config = 0;
126 edge_insensitive = 0;
127 break;
128 case IRQ_TYPE_LEVEL_HIGH:
129 level = mask;
130 edge_config = 0;
131 edge_insensitive = 0;
132 break;
133 case IRQ_TYPE_EDGE_FALLING:
134 level = 0;
135 edge_config = 0;
136 edge_insensitive = 0;
137 break;
138 case IRQ_TYPE_EDGE_RISING:
139 level = 0;
140 edge_config = mask;
141 edge_insensitive = 0;
142 break;
143 case IRQ_TYPE_EDGE_BOTH:
144 level = 0;
145 edge_config = 0; /* don't care, but want known value */
146 edge_insensitive = mask;
147 break;
148 default:
149 return -EINVAL;
150 }
151
152 spin_lock_irqsave(&bank->bgc.lock, flags);
153
154 iedge_config = bank->bgc.read_reg(priv->reg_base +
155 GIO_EC(bank->id)) & ~mask;
156 iedge_insensitive = bank->bgc.read_reg(priv->reg_base +
157 GIO_EI(bank->id)) & ~mask;
158 ilevel = bank->bgc.read_reg(priv->reg_base +
159 GIO_LEVEL(bank->id)) & ~mask;
160
161 bank->bgc.write_reg(priv->reg_base + GIO_EC(bank->id),
162 iedge_config | edge_config);
163 bank->bgc.write_reg(priv->reg_base + GIO_EI(bank->id),
164 iedge_insensitive | edge_insensitive);
165 bank->bgc.write_reg(priv->reg_base + GIO_LEVEL(bank->id),
166 ilevel | level);
167
168 spin_unlock_irqrestore(&bank->bgc.lock, flags);
169 return 0;
170}
171
172static int brcmstb_gpio_priv_set_wake(struct brcmstb_gpio_priv *priv,
173 unsigned int enable)
174{
175 int ret = 0;
176
177 /*
178 * Only enable wake IRQ once for however many hwirqs can wake
179 * since they all use the same wake IRQ. Mask will be set
180 * up appropriately thanks to IRQCHIP_MASK_ON_SUSPEND flag.
181 */
182 if (enable)
183 ret = enable_irq_wake(priv->parent_wake_irq);
184 else
185 ret = disable_irq_wake(priv->parent_wake_irq);
186 if (ret)
187 dev_err(&priv->pdev->dev, "failed to %s wake-up interrupt\n",
188 enable ? "enable" : "disable");
189 return ret;
190}
191
192static int brcmstb_gpio_irq_set_wake(struct irq_data *d, unsigned int enable)
193{
194 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
195 struct brcmstb_gpio_priv *priv = brcmstb_gpio_gc_to_priv(gc);
196
197 return brcmstb_gpio_priv_set_wake(priv, enable);
198}
199
200static irqreturn_t brcmstb_gpio_wake_irq_handler(int irq, void *data)
201{
202 struct brcmstb_gpio_priv *priv = data;
203
204 if (!priv || irq != priv->parent_wake_irq)
205 return IRQ_NONE;
206 pm_wakeup_event(&priv->pdev->dev, 0);
207 return IRQ_HANDLED;
208}
209
210static void brcmstb_gpio_irq_bank_handler(struct brcmstb_gpio_bank *bank)
211{
212 struct brcmstb_gpio_priv *priv = bank->parent_priv;
213 struct irq_domain *irq_domain = bank->bgc.gc.irqdomain;
214 void __iomem *reg_base = priv->reg_base;
215 unsigned long status;
216 unsigned long flags;
217
218 spin_lock_irqsave(&bank->bgc.lock, flags);
219 while ((status = bank->bgc.read_reg(reg_base + GIO_STAT(bank->id)) &
220 bank->bgc.read_reg(reg_base + GIO_MASK(bank->id)))) {
221 int bit;
222
223 for_each_set_bit(bit, &status, 32) {
224 u32 stat = bank->bgc.read_reg(reg_base +
225 GIO_STAT(bank->id));
226 if (bit >= bank->width)
227 dev_warn(&priv->pdev->dev,
228 "IRQ for invalid GPIO (bank=%d, offset=%d)\n",
229 bank->id, bit);
230 bank->bgc.write_reg(reg_base + GIO_STAT(bank->id),
231 stat | BIT(bit));
232 generic_handle_irq(irq_find_mapping(irq_domain, bit));
233 }
234 }
235 spin_unlock_irqrestore(&bank->bgc.lock, flags);
236}
237
238/* Each UPG GIO block has one IRQ for all banks */
239static void brcmstb_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
240{
241 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
242 struct brcmstb_gpio_priv *priv = brcmstb_gpio_gc_to_priv(gc);
243 struct irq_chip *chip = irq_desc_get_chip(desc);
244 struct list_head *pos;
245
246 /* Interrupts weren't properly cleared during probe */
247 BUG_ON(!priv || !chip);
248
249 chained_irq_enter(chip, desc);
250 list_for_each(pos, &priv->bank_list) {
251 struct brcmstb_gpio_bank *bank =
252 list_entry(pos, struct brcmstb_gpio_bank, node);
253 brcmstb_gpio_irq_bank_handler(bank);
254 }
255 chained_irq_exit(chip, desc);
256}
257
258static int brcmstb_gpio_reboot(struct notifier_block *nb,
259 unsigned long action, void *data)
260{
261 struct brcmstb_gpio_priv *priv =
262 container_of(nb, struct brcmstb_gpio_priv, reboot_notifier);
263
264 /* Enable GPIO for S5 cold boot */
265 if (action == SYS_POWER_OFF)
266 brcmstb_gpio_priv_set_wake(priv, 1);
267
268 return NOTIFY_DONE;
269}
270
66/* Make sure that the number of banks matches up between properties */ 271/* Make sure that the number of banks matches up between properties */
67static int brcmstb_gpio_sanity_check_banks(struct device *dev, 272static int brcmstb_gpio_sanity_check_banks(struct device *dev,
68 struct device_node *np, struct resource *res) 273 struct device_node *np, struct resource *res)
@@ -100,7 +305,13 @@ static int brcmstb_gpio_remove(struct platform_device *pdev)
100 bank = list_entry(pos, struct brcmstb_gpio_bank, node); 305 bank = list_entry(pos, struct brcmstb_gpio_bank, node);
101 ret = bgpio_remove(&bank->bgc); 306 ret = bgpio_remove(&bank->bgc);
102 if (ret) 307 if (ret)
103 dev_err(&pdev->dev, "gpiochip_remove fail in cleanup"); 308 dev_err(&pdev->dev, "gpiochip_remove fail in cleanup\n");
309 }
310 if (priv->reboot_notifier.notifier_call) {
311 ret = unregister_reboot_notifier(&priv->reboot_notifier);
312 if (ret)
313 dev_err(&pdev->dev,
314 "failed to unregister reboot notifier\n");
104 } 315 }
105 return ret; 316 return ret;
106} 317}
@@ -121,7 +332,7 @@ static int brcmstb_gpio_of_xlate(struct gpio_chip *gc,
121 return -EINVAL; 332 return -EINVAL;
122 333
123 offset = gpiospec->args[0] - (gc->base - priv->gpio_base); 334 offset = gpiospec->args[0] - (gc->base - priv->gpio_base);
124 if (offset >= gc->ngpio) 335 if (offset >= gc->ngpio || offset < 0)
125 return -EINVAL; 336 return -EINVAL;
126 337
127 if (unlikely(offset >= bank->width)) { 338 if (unlikely(offset >= bank->width)) {
@@ -136,6 +347,65 @@ static int brcmstb_gpio_of_xlate(struct gpio_chip *gc,
136 return offset; 347 return offset;
137} 348}
138 349
350/* Before calling, must have bank->parent_irq set and gpiochip registered */
351static int brcmstb_gpio_irq_setup(struct platform_device *pdev,
352 struct brcmstb_gpio_bank *bank)
353{
354 struct brcmstb_gpio_priv *priv = bank->parent_priv;
355 struct device *dev = &pdev->dev;
356 struct device_node *np = dev->of_node;
357
358 bank->irq_chip.name = dev_name(dev);
359 bank->irq_chip.irq_mask = brcmstb_gpio_irq_mask;
360 bank->irq_chip.irq_unmask = brcmstb_gpio_irq_unmask;
361 bank->irq_chip.irq_set_type = brcmstb_gpio_irq_set_type;
362
363 /* Ensures that all non-wakeup IRQs are disabled at suspend */
364 bank->irq_chip.flags = IRQCHIP_MASK_ON_SUSPEND;
365
366 if (IS_ENABLED(CONFIG_PM_SLEEP) && !priv->can_wake &&
367 of_property_read_bool(np, "wakeup-source")) {
368 priv->parent_wake_irq = platform_get_irq(pdev, 1);
369 if (priv->parent_wake_irq < 0) {
370 dev_warn(dev,
371 "Couldn't get wake IRQ - GPIOs will not be able to wake from sleep");
372 } else {
373 int err;
374
375 /*
376 * Set wakeup capability before requesting wakeup
377 * interrupt, so we can process boot-time "wakeups"
378 * (e.g., from S5 cold boot)
379 */
380 device_set_wakeup_capable(dev, true);
381 device_wakeup_enable(dev);
382 err = devm_request_irq(dev, priv->parent_wake_irq,
383 brcmstb_gpio_wake_irq_handler, 0,
384 "brcmstb-gpio-wake", priv);
385
386 if (err < 0) {
387 dev_err(dev, "Couldn't request wake IRQ");
388 return err;
389 }
390
391 priv->reboot_notifier.notifier_call =
392 brcmstb_gpio_reboot;
393 register_reboot_notifier(&priv->reboot_notifier);
394 priv->can_wake = true;
395 }
396 }
397
398 if (priv->can_wake)
399 bank->irq_chip.irq_set_wake = brcmstb_gpio_irq_set_wake;
400
401 gpiochip_irqchip_add(&bank->bgc.gc, &bank->irq_chip, 0,
402 handle_simple_irq, IRQ_TYPE_NONE);
403 gpiochip_set_chained_irqchip(&bank->bgc.gc, &bank->irq_chip,
404 priv->parent_irq, brcmstb_gpio_irq_handler);
405
406 return 0;
407}
408
139static int brcmstb_gpio_probe(struct platform_device *pdev) 409static int brcmstb_gpio_probe(struct platform_device *pdev)
140{ 410{
141 struct device *dev = &pdev->dev; 411 struct device *dev = &pdev->dev;
@@ -146,6 +416,7 @@ static int brcmstb_gpio_probe(struct platform_device *pdev)
146 struct property *prop; 416 struct property *prop;
147 const __be32 *p; 417 const __be32 *p;
148 u32 bank_width; 418 u32 bank_width;
419 int num_banks = 0;
149 int err; 420 int err;
150 static int gpio_base; 421 static int gpio_base;
151 422
@@ -164,6 +435,16 @@ static int brcmstb_gpio_probe(struct platform_device *pdev)
164 priv->reg_base = reg_base; 435 priv->reg_base = reg_base;
165 priv->pdev = pdev; 436 priv->pdev = pdev;
166 437
438 if (of_property_read_bool(np, "interrupt-controller")) {
439 priv->parent_irq = platform_get_irq(pdev, 0);
440 if (priv->parent_irq <= 0) {
441 dev_err(dev, "Couldn't get IRQ");
442 return -ENOENT;
443 }
444 } else {
445 priv->parent_irq = -ENOENT;
446 }
447
167 if (brcmstb_gpio_sanity_check_banks(dev, np, res)) 448 if (brcmstb_gpio_sanity_check_banks(dev, np, res))
168 return -EINVAL; 449 return -EINVAL;
169 450
@@ -180,7 +461,7 @@ static int brcmstb_gpio_probe(struct platform_device *pdev)
180 } 461 }
181 462
182 bank->parent_priv = priv; 463 bank->parent_priv = priv;
183 bank->id = priv->num_banks; 464 bank->id = num_banks;
184 if (bank_width <= 0 || bank_width > MAX_GPIO_PER_BANK) { 465 if (bank_width <= 0 || bank_width > MAX_GPIO_PER_BANK) {
185 dev_err(dev, "Invalid bank width %d\n", bank_width); 466 dev_err(dev, "Invalid bank width %d\n", bank_width);
186 goto fail; 467 goto fail;
@@ -212,6 +493,12 @@ static int brcmstb_gpio_probe(struct platform_device *pdev)
212 /* not all ngpio lines are valid, will use bank width later */ 493 /* not all ngpio lines are valid, will use bank width later */
213 gc->ngpio = MAX_GPIO_PER_BANK; 494 gc->ngpio = MAX_GPIO_PER_BANK;
214 495
496 /*
497 * Mask all interrupts by default, since wakeup interrupts may
498 * be retained from S5 cold boot
499 */
500 bank->bgc.write_reg(reg_base + GIO_MASK(bank->id), 0);
501
215 err = gpiochip_add(gc); 502 err = gpiochip_add(gc);
216 if (err) { 503 if (err) {
217 dev_err(dev, "Could not add gpiochip for bank %d\n", 504 dev_err(dev, "Could not add gpiochip for bank %d\n",
@@ -219,17 +506,24 @@ static int brcmstb_gpio_probe(struct platform_device *pdev)
219 goto fail; 506 goto fail;
220 } 507 }
221 gpio_base += gc->ngpio; 508 gpio_base += gc->ngpio;
509
510 if (priv->parent_irq > 0) {
511 err = brcmstb_gpio_irq_setup(pdev, bank);
512 if (err)
513 goto fail;
514 }
515
222 dev_dbg(dev, "bank=%d, base=%d, ngpio=%d, width=%d\n", bank->id, 516 dev_dbg(dev, "bank=%d, base=%d, ngpio=%d, width=%d\n", bank->id,
223 gc->base, gc->ngpio, bank->width); 517 gc->base, gc->ngpio, bank->width);
224 518
225 /* Everything looks good, so add bank to list */ 519 /* Everything looks good, so add bank to list */
226 list_add(&bank->node, &priv->bank_list); 520 list_add(&bank->node, &priv->bank_list);
227 521
228 priv->num_banks++; 522 num_banks++;
229 } 523 }
230 524
231 dev_info(dev, "Registered %d banks (GPIO(s): %d-%d)\n", 525 dev_info(dev, "Registered %d banks (GPIO(s): %d-%d)\n",
232 priv->num_banks, priv->gpio_base, gpio_base - 1); 526 num_banks, priv->gpio_base, gpio_base - 1);
233 527
234 return 0; 528 return 0;
235 529
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index c246ac3dda7c..94b0ab709721 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -65,11 +65,11 @@ static struct davinci_gpio_regs __iomem *gpio2regs(unsigned gpio)
65 return ptr; 65 return ptr;
66} 66}
67 67
68static inline struct davinci_gpio_regs __iomem *irq2regs(int irq) 68static inline struct davinci_gpio_regs __iomem *irq2regs(struct irq_data *d)
69{ 69{
70 struct davinci_gpio_regs __iomem *g; 70 struct davinci_gpio_regs __iomem *g;
71 71
72 g = (__force struct davinci_gpio_regs __iomem *)irq_get_chip_data(irq); 72 g = (__force struct davinci_gpio_regs __iomem *)irq_data_get_irq_chip_data(d);
73 73
74 return g; 74 return g;
75} 75}
@@ -287,7 +287,7 @@ static int davinci_gpio_probe(struct platform_device *pdev)
287 287
288static void gpio_irq_disable(struct irq_data *d) 288static void gpio_irq_disable(struct irq_data *d)
289{ 289{
290 struct davinci_gpio_regs __iomem *g = irq2regs(d->irq); 290 struct davinci_gpio_regs __iomem *g = irq2regs(d);
291 u32 mask = (u32) irq_data_get_irq_handler_data(d); 291 u32 mask = (u32) irq_data_get_irq_handler_data(d);
292 292
293 writel_relaxed(mask, &g->clr_falling); 293 writel_relaxed(mask, &g->clr_falling);
@@ -296,7 +296,7 @@ static void gpio_irq_disable(struct irq_data *d)
296 296
297static void gpio_irq_enable(struct irq_data *d) 297static void gpio_irq_enable(struct irq_data *d)
298{ 298{
299 struct davinci_gpio_regs __iomem *g = irq2regs(d->irq); 299 struct davinci_gpio_regs __iomem *g = irq2regs(d);
300 u32 mask = (u32) irq_data_get_irq_handler_data(d); 300 u32 mask = (u32) irq_data_get_irq_handler_data(d);
301 unsigned status = irqd_get_trigger_type(d); 301 unsigned status = irqd_get_trigger_type(d);
302 302
@@ -327,8 +327,9 @@ static struct irq_chip gpio_irqchip = {
327}; 327};
328 328
329static void 329static void
330gpio_irq_handler(unsigned irq, struct irq_desc *desc) 330gpio_irq_handler(unsigned __irq, struct irq_desc *desc)
331{ 331{
332 unsigned int irq = irq_desc_get_irq(desc);
332 struct davinci_gpio_regs __iomem *g; 333 struct davinci_gpio_regs __iomem *g;
333 u32 mask = 0xffff; 334 u32 mask = 0xffff;
334 struct davinci_gpio_controller *d; 335 struct davinci_gpio_controller *d;
@@ -396,7 +397,7 @@ static int gpio_irq_type_unbanked(struct irq_data *data, unsigned trigger)
396 struct davinci_gpio_regs __iomem *g; 397 struct davinci_gpio_regs __iomem *g;
397 u32 mask; 398 u32 mask;
398 399
399 d = (struct davinci_gpio_controller *)data->handler_data; 400 d = (struct davinci_gpio_controller *)irq_data_get_irq_handler_data(data);
400 g = (struct davinci_gpio_regs __iomem *)d->regs; 401 g = (struct davinci_gpio_regs __iomem *)d->regs;
401 mask = __gpio_mask(data->irq - d->gpio_irq); 402 mask = __gpio_mask(data->irq - d->gpio_irq);
402 403
@@ -422,7 +423,6 @@ davinci_gpio_irq_map(struct irq_domain *d, unsigned int irq,
422 irq_set_irq_type(irq, IRQ_TYPE_NONE); 423 irq_set_irq_type(irq, IRQ_TYPE_NONE);
423 irq_set_chip_data(irq, (__force void *)g); 424 irq_set_chip_data(irq, (__force void *)g);
424 irq_set_handler_data(irq, (void *)__gpio_mask(hw)); 425 irq_set_handler_data(irq, (void *)__gpio_mask(hw));
425 set_irq_flags(irq, IRQF_VALID);
426 426
427 return 0; 427 return 0;
428} 428}
@@ -545,7 +545,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
545 chips[0].chip.to_irq = gpio_to_irq_unbanked; 545 chips[0].chip.to_irq = gpio_to_irq_unbanked;
546 chips[0].gpio_irq = bank_irq; 546 chips[0].gpio_irq = bank_irq;
547 chips[0].gpio_unbanked = pdata->gpio_unbanked; 547 chips[0].gpio_unbanked = pdata->gpio_unbanked;
548 binten = BIT(0); 548 binten = GENMASK(pdata->gpio_unbanked / 16, 0);
549 549
550 /* AINTC handles mask/unmask; GPIO handles triggering */ 550 /* AINTC handles mask/unmask; GPIO handles triggering */
551 irq = bank_irq; 551 irq = bank_irq;
diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index 55fa9853a7f2..c5be4b9b8baf 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -149,7 +149,7 @@ static u32 dwapb_do_irq(struct dwapb_gpio *gpio)
149 149
150static void dwapb_irq_handler(u32 irq, struct irq_desc *desc) 150static void dwapb_irq_handler(u32 irq, struct irq_desc *desc)
151{ 151{
152 struct dwapb_gpio *gpio = irq_get_handler_data(irq); 152 struct dwapb_gpio *gpio = irq_desc_get_handler_data(desc);
153 struct irq_chip *chip = irq_desc_get_chip(desc); 153 struct irq_chip *chip = irq_desc_get_chip(desc);
154 154
155 dwapb_do_irq(gpio); 155 dwapb_do_irq(gpio);
diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
index fbf287307c4c..6bca1e125e12 100644
--- a/drivers/gpio/gpio-em.c
+++ b/drivers/gpio/gpio-em.c
@@ -31,7 +31,6 @@
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/pinctrl/consumer.h> 33#include <linux/pinctrl/consumer.h>
34#include <linux/platform_data/gpio-em.h>
35 34
36struct em_gio_priv { 35struct em_gio_priv {
37 void __iomem *base0; 36 void __iomem *base0;
@@ -262,7 +261,6 @@ static int em_gio_irq_domain_map(struct irq_domain *h, unsigned int irq,
262 261
263 irq_set_chip_data(irq, h->host_data); 262 irq_set_chip_data(irq, h->host_data);
264 irq_set_chip_and_handler(irq, &p->irq_chip, handle_level_irq); 263 irq_set_chip_and_handler(irq, &p->irq_chip, handle_level_irq);
265 set_irq_flags(irq, IRQF_VALID); /* kill me now */
266 return 0; 264 return 0;
267} 265}
268 266
@@ -273,13 +271,12 @@ static const struct irq_domain_ops em_gio_irq_domain_ops = {
273 271
274static int em_gio_probe(struct platform_device *pdev) 272static int em_gio_probe(struct platform_device *pdev)
275{ 273{
276 struct gpio_em_config pdata_dt;
277 struct gpio_em_config *pdata = dev_get_platdata(&pdev->dev);
278 struct em_gio_priv *p; 274 struct em_gio_priv *p;
279 struct resource *io[2], *irq[2]; 275 struct resource *io[2], *irq[2];
280 struct gpio_chip *gpio_chip; 276 struct gpio_chip *gpio_chip;
281 struct irq_chip *irq_chip; 277 struct irq_chip *irq_chip;
282 const char *name = dev_name(&pdev->dev); 278 const char *name = dev_name(&pdev->dev);
279 unsigned int ngpios;
283 int ret; 280 int ret;
284 281
285 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); 282 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
@@ -319,18 +316,10 @@ static int em_gio_probe(struct platform_device *pdev)
319 goto err0; 316 goto err0;
320 } 317 }
321 318
322 if (!pdata) { 319 if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) {
323 memset(&pdata_dt, 0, sizeof(pdata_dt)); 320 dev_err(&pdev->dev, "Missing ngpios OF property\n");
324 pdata = &pdata_dt; 321 ret = -EINVAL;
325 322 goto err0;
326 if (of_property_read_u32(pdev->dev.of_node, "ngpios",
327 &pdata->number_of_pins)) {
328 dev_err(&pdev->dev, "Missing ngpios OF property\n");
329 ret = -EINVAL;
330 goto err0;
331 }
332
333 pdata->gpio_base = -1;
334 } 323 }
335 324
336 gpio_chip = &p->gpio_chip; 325 gpio_chip = &p->gpio_chip;
@@ -345,8 +334,8 @@ static int em_gio_probe(struct platform_device *pdev)
345 gpio_chip->label = name; 334 gpio_chip->label = name;
346 gpio_chip->dev = &pdev->dev; 335 gpio_chip->dev = &pdev->dev;
347 gpio_chip->owner = THIS_MODULE; 336 gpio_chip->owner = THIS_MODULE;
348 gpio_chip->base = pdata->gpio_base; 337 gpio_chip->base = -1;
349 gpio_chip->ngpio = pdata->number_of_pins; 338 gpio_chip->ngpio = ngpios;
350 339
351 irq_chip = &p->irq_chip; 340 irq_chip = &p->irq_chip;
352 irq_chip->name = name; 341 irq_chip->name = name;
@@ -357,9 +346,7 @@ static int em_gio_probe(struct platform_device *pdev)
357 irq_chip->irq_release_resources = em_gio_irq_relres; 346 irq_chip->irq_release_resources = em_gio_irq_relres;
358 irq_chip->flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND; 347 irq_chip->flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND;
359 348
360 p->irq_domain = irq_domain_add_simple(pdev->dev.of_node, 349 p->irq_domain = irq_domain_add_simple(pdev->dev.of_node, ngpios, 0,
361 pdata->number_of_pins,
362 pdata->irq_base,
363 &em_gio_irq_domain_ops, p); 350 &em_gio_irq_domain_ops, p);
364 if (!p->irq_domain) { 351 if (!p->irq_domain) {
365 ret = -ENXIO; 352 ret = -ENXIO;
@@ -387,12 +374,6 @@ static int em_gio_probe(struct platform_device *pdev)
387 goto err1; 374 goto err1;
388 } 375 }
389 376
390 if (pdata->pctl_name) {
391 ret = gpiochip_add_pin_range(gpio_chip, pdata->pctl_name, 0,
392 gpio_chip->base, gpio_chip->ngpio);
393 if (ret < 0)
394 dev_warn(&pdev->dev, "failed to add pin range\n");
395 }
396 return 0; 377 return 0;
397 378
398err1: 379err1:
diff --git a/drivers/gpio/gpio-ep93xx.c b/drivers/gpio/gpio-ep93xx.c
index 45684f36ddb1..9d90366ea259 100644
--- a/drivers/gpio/gpio-ep93xx.c
+++ b/drivers/gpio/gpio-ep93xx.c
@@ -100,13 +100,15 @@ static void ep93xx_gpio_ab_irq_handler(unsigned int irq, struct irq_desc *desc)
100 } 100 }
101} 101}
102 102
103static void ep93xx_gpio_f_irq_handler(unsigned int irq, struct irq_desc *desc) 103static void ep93xx_gpio_f_irq_handler(unsigned int __irq,
104 struct irq_desc *desc)
104{ 105{
105 /* 106 /*
106 * map discontiguous hw irq range to continuous sw irq range: 107 * map discontiguous hw irq range to continuous sw irq range:
107 * 108 *
108 * IRQ_EP93XX_GPIO{0..7}MUX -> gpio_to_irq(EP93XX_GPIO_LINE_F({0..7}) 109 * IRQ_EP93XX_GPIO{0..7}MUX -> gpio_to_irq(EP93XX_GPIO_LINE_F({0..7})
109 */ 110 */
111 unsigned int irq = irq_desc_get_irq(desc);
110 int port_f_idx = ((irq + 1) & 7) ^ 4; /* {19..22,47..50} -> {0..7} */ 112 int port_f_idx = ((irq + 1) & 7) ^ 4; /* {19..22,47..50} -> {0..7} */
111 int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_F(0)) + port_f_idx; 113 int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_F(0)) + port_f_idx;
112 114
@@ -208,7 +210,7 @@ static int ep93xx_gpio_irq_type(struct irq_data *d, unsigned int type)
208 return -EINVAL; 210 return -EINVAL;
209 } 211 }
210 212
211 __irq_set_handler_locked(d->irq, handler); 213 irq_set_handler_locked(d, handler);
212 214
213 gpio_int_enabled[port] |= port_mask; 215 gpio_int_enabled[port] |= port_mask;
214 216
@@ -234,7 +236,7 @@ static void ep93xx_gpio_init_irq(void)
234 gpio_irq <= gpio_to_irq(EP93XX_GPIO_LINE_MAX_IRQ); ++gpio_irq) { 236 gpio_irq <= gpio_to_irq(EP93XX_GPIO_LINE_MAX_IRQ); ++gpio_irq) {
235 irq_set_chip_and_handler(gpio_irq, &ep93xx_gpio_irq_chip, 237 irq_set_chip_and_handler(gpio_irq, &ep93xx_gpio_irq_chip,
236 handle_level_irq); 238 handle_level_irq);
237 set_irq_flags(gpio_irq, IRQF_VALID); 239 irq_clear_status_flags(gpio_irq, IRQ_NOREQUEST);
238 } 240 }
239 241
240 irq_set_chained_handler(IRQ_EP93XX_GPIO_AB, 242 irq_set_chained_handler(IRQ_EP93XX_GPIO_AB,
diff --git a/drivers/gpio/gpio-etraxfs.c b/drivers/gpio/gpio-etraxfs.c
index 28071f4a5672..2ffcd9fdd1f2 100644
--- a/drivers/gpio/gpio-etraxfs.c
+++ b/drivers/gpio/gpio-etraxfs.c
@@ -1,8 +1,10 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/init.h> 2#include <linux/init.h>
3#include <linux/gpio.h> 3#include <linux/gpio.h>
4#include <linux/gpio/driver.h>
4#include <linux/of_gpio.h> 5#include <linux/of_gpio.h>
5#include <linux/io.h> 6#include <linux/io.h>
7#include <linux/interrupt.h>
6#include <linux/platform_device.h> 8#include <linux/platform_device.h>
7#include <linux/basic_mmio_gpio.h> 9#include <linux/basic_mmio_gpio.h>
8 10
@@ -13,6 +15,7 @@
13#define ETRAX_FS_rw_intr_mask 16 15#define ETRAX_FS_rw_intr_mask 16
14#define ETRAX_FS_rw_ack_intr 20 16#define ETRAX_FS_rw_ack_intr 20
15#define ETRAX_FS_r_intr 24 17#define ETRAX_FS_r_intr 24
18#define ETRAX_FS_r_masked_intr 28
16#define ETRAX_FS_rw_pb_dout 32 19#define ETRAX_FS_rw_pb_dout 32
17#define ETRAX_FS_r_pb_din 36 20#define ETRAX_FS_r_pb_din 36
18#define ETRAX_FS_rw_pb_oe 40 21#define ETRAX_FS_rw_pb_oe 40
@@ -26,6 +29,48 @@
26#define ETRAX_FS_r_pe_din 84 29#define ETRAX_FS_r_pe_din 84
27#define ETRAX_FS_rw_pe_oe 88 30#define ETRAX_FS_rw_pe_oe 88
28 31
32#define ARTPEC3_r_pa_din 0
33#define ARTPEC3_rw_pa_dout 4
34#define ARTPEC3_rw_pa_oe 8
35#define ARTPEC3_r_pb_din 44
36#define ARTPEC3_rw_pb_dout 48
37#define ARTPEC3_rw_pb_oe 52
38#define ARTPEC3_r_pc_din 88
39#define ARTPEC3_rw_pc_dout 92
40#define ARTPEC3_rw_pc_oe 96
41#define ARTPEC3_r_pd_din 116
42#define ARTPEC3_rw_intr_cfg 120
43#define ARTPEC3_rw_intr_pins 124
44#define ARTPEC3_rw_intr_mask 128
45#define ARTPEC3_rw_ack_intr 132
46#define ARTPEC3_r_masked_intr 140
47
48#define GIO_CFG_OFF 0
49#define GIO_CFG_HI 1
50#define GIO_CFG_LO 2
51#define GIO_CFG_SET 3
52#define GIO_CFG_POSEDGE 5
53#define GIO_CFG_NEGEDGE 6
54#define GIO_CFG_ANYEDGE 7
55
56struct etraxfs_gpio_info;
57
58struct etraxfs_gpio_block {
59 spinlock_t lock;
60 u32 mask;
61 u32 cfg;
62 u32 pins;
63 unsigned int group[8];
64
65 void __iomem *regs;
66 const struct etraxfs_gpio_info *info;
67};
68
69struct etraxfs_gpio_chip {
70 struct bgpio_chip bgc;
71 struct etraxfs_gpio_block *block;
72};
73
29struct etraxfs_gpio_port { 74struct etraxfs_gpio_port {
30 const char *label; 75 const char *label;
31 unsigned int oe; 76 unsigned int oe;
@@ -37,6 +82,12 @@ struct etraxfs_gpio_port {
37struct etraxfs_gpio_info { 82struct etraxfs_gpio_info {
38 unsigned int num_ports; 83 unsigned int num_ports;
39 const struct etraxfs_gpio_port *ports; 84 const struct etraxfs_gpio_port *ports;
85
86 unsigned int rw_ack_intr;
87 unsigned int rw_intr_mask;
88 unsigned int rw_intr_cfg;
89 unsigned int rw_intr_pins;
90 unsigned int r_masked_intr;
40}; 91};
41 92
42static const struct etraxfs_gpio_port etraxfs_gpio_etraxfs_ports[] = { 93static const struct etraxfs_gpio_port etraxfs_gpio_etraxfs_ports[] = {
@@ -80,8 +131,56 @@ static const struct etraxfs_gpio_port etraxfs_gpio_etraxfs_ports[] = {
80static const struct etraxfs_gpio_info etraxfs_gpio_etraxfs = { 131static const struct etraxfs_gpio_info etraxfs_gpio_etraxfs = {
81 .num_ports = ARRAY_SIZE(etraxfs_gpio_etraxfs_ports), 132 .num_ports = ARRAY_SIZE(etraxfs_gpio_etraxfs_ports),
82 .ports = etraxfs_gpio_etraxfs_ports, 133 .ports = etraxfs_gpio_etraxfs_ports,
134 .rw_ack_intr = ETRAX_FS_rw_ack_intr,
135 .rw_intr_mask = ETRAX_FS_rw_intr_mask,
136 .rw_intr_cfg = ETRAX_FS_rw_intr_cfg,
137 .r_masked_intr = ETRAX_FS_r_masked_intr,
138};
139
140static const struct etraxfs_gpio_port etraxfs_gpio_artpec3_ports[] = {
141 {
142 .label = "A",
143 .ngpio = 32,
144 .oe = ARTPEC3_rw_pa_oe,
145 .dout = ARTPEC3_rw_pa_dout,
146 .din = ARTPEC3_r_pa_din,
147 },
148 {
149 .label = "B",
150 .ngpio = 32,
151 .oe = ARTPEC3_rw_pb_oe,
152 .dout = ARTPEC3_rw_pb_dout,
153 .din = ARTPEC3_r_pb_din,
154 },
155 {
156 .label = "C",
157 .ngpio = 16,
158 .oe = ARTPEC3_rw_pc_oe,
159 .dout = ARTPEC3_rw_pc_dout,
160 .din = ARTPEC3_r_pc_din,
161 },
162 {
163 .label = "D",
164 .ngpio = 32,
165 .din = ARTPEC3_r_pd_din,
166 },
167};
168
169static const struct etraxfs_gpio_info etraxfs_gpio_artpec3 = {
170 .num_ports = ARRAY_SIZE(etraxfs_gpio_artpec3_ports),
171 .ports = etraxfs_gpio_artpec3_ports,
172 .rw_ack_intr = ARTPEC3_rw_ack_intr,
173 .rw_intr_mask = ARTPEC3_rw_intr_mask,
174 .rw_intr_cfg = ARTPEC3_rw_intr_cfg,
175 .r_masked_intr = ARTPEC3_r_masked_intr,
176 .rw_intr_pins = ARTPEC3_rw_intr_pins,
83}; 177};
84 178
179static unsigned int etraxfs_gpio_chip_to_port(struct gpio_chip *gc)
180{
181 return gc->label[0] - 'A';
182}
183
85static int etraxfs_gpio_of_xlate(struct gpio_chip *gc, 184static int etraxfs_gpio_of_xlate(struct gpio_chip *gc,
86 const struct of_phandle_args *gpiospec, 185 const struct of_phandle_args *gpiospec,
87 u32 *flags) 186 u32 *flags)
@@ -90,7 +189,7 @@ static int etraxfs_gpio_of_xlate(struct gpio_chip *gc,
90 * Port numbers are A to E, and the properties are integers, so we 189 * Port numbers are A to E, and the properties are integers, so we
91 * specify them as 0xA - 0xE. 190 * specify them as 0xA - 0xE.
92 */ 191 */
93 if (gc->label[0] - 'A' + 0xA != gpiospec->args[2]) 192 if (etraxfs_gpio_chip_to_port(gc) + 0xA != gpiospec->args[2])
94 return -EINVAL; 193 return -EINVAL;
95 194
96 return of_gpio_simple_xlate(gc, gpiospec, flags); 195 return of_gpio_simple_xlate(gc, gpiospec, flags);
@@ -101,24 +200,174 @@ static const struct of_device_id etraxfs_gpio_of_table[] = {
101 .compatible = "axis,etraxfs-gio", 200 .compatible = "axis,etraxfs-gio",
102 .data = &etraxfs_gpio_etraxfs, 201 .data = &etraxfs_gpio_etraxfs,
103 }, 202 },
203 {
204 .compatible = "axis,artpec3-gio",
205 .data = &etraxfs_gpio_artpec3,
206 },
104 {}, 207 {},
105}; 208};
106 209
210static unsigned int etraxfs_gpio_to_group_irq(unsigned int gpio)
211{
212 return gpio % 8;
213}
214
215static unsigned int etraxfs_gpio_to_group_pin(struct etraxfs_gpio_chip *chip,
216 unsigned int gpio)
217{
218 return 4 * etraxfs_gpio_chip_to_port(&chip->bgc.gc) + gpio / 8;
219}
220
221static void etraxfs_gpio_irq_ack(struct irq_data *d)
222{
223 struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d);
224 struct etraxfs_gpio_block *block = chip->block;
225 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
226
227 writel(BIT(grpirq), block->regs + block->info->rw_ack_intr);
228}
229
230static void etraxfs_gpio_irq_mask(struct irq_data *d)
231{
232 struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d);
233 struct etraxfs_gpio_block *block = chip->block;
234 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
235
236 spin_lock(&block->lock);
237 block->mask &= ~BIT(grpirq);
238 writel(block->mask, block->regs + block->info->rw_intr_mask);
239 spin_unlock(&block->lock);
240}
241
242static void etraxfs_gpio_irq_unmask(struct irq_data *d)
243{
244 struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d);
245 struct etraxfs_gpio_block *block = chip->block;
246 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
247
248 spin_lock(&block->lock);
249 block->mask |= BIT(grpirq);
250 writel(block->mask, block->regs + block->info->rw_intr_mask);
251 spin_unlock(&block->lock);
252}
253
254static int etraxfs_gpio_irq_set_type(struct irq_data *d, u32 type)
255{
256 struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d);
257 struct etraxfs_gpio_block *block = chip->block;
258 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
259 u32 cfg;
260
261 switch (type) {
262 case IRQ_TYPE_EDGE_RISING:
263 cfg = GIO_CFG_POSEDGE;
264 break;
265 case IRQ_TYPE_EDGE_FALLING:
266 cfg = GIO_CFG_NEGEDGE;
267 break;
268 case IRQ_TYPE_EDGE_BOTH:
269 cfg = GIO_CFG_ANYEDGE;
270 break;
271 case IRQ_TYPE_LEVEL_LOW:
272 cfg = GIO_CFG_LO;
273 break;
274 case IRQ_TYPE_LEVEL_HIGH:
275 cfg = GIO_CFG_HI;
276 break;
277 default:
278 return -EINVAL;
279 }
280
281 spin_lock(&block->lock);
282 block->cfg &= ~(0x7 << (grpirq * 3));
283 block->cfg |= (cfg << (grpirq * 3));
284 writel(block->cfg, block->regs + block->info->rw_intr_cfg);
285 spin_unlock(&block->lock);
286
287 return 0;
288}
289
290static int etraxfs_gpio_irq_request_resources(struct irq_data *d)
291{
292 struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d);
293 struct etraxfs_gpio_block *block = chip->block;
294 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
295 int ret = -EBUSY;
296
297 spin_lock(&block->lock);
298 if (block->group[grpirq])
299 goto out;
300
301 ret = gpiochip_lock_as_irq(&chip->bgc.gc, d->hwirq);
302 if (ret)
303 goto out;
304
305 block->group[grpirq] = d->irq;
306 if (block->info->rw_intr_pins) {
307 unsigned int pin = etraxfs_gpio_to_group_pin(chip, d->hwirq);
308
309 block->pins &= ~(0xf << (grpirq * 4));
310 block->pins |= (pin << (grpirq * 4));
311
312 writel(block->pins, block->regs + block->info->rw_intr_pins);
313 }
314
315out:
316 spin_unlock(&block->lock);
317 return ret;
318}
319
320static void etraxfs_gpio_irq_release_resources(struct irq_data *d)
321{
322 struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d);
323 struct etraxfs_gpio_block *block = chip->block;
324 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
325
326 spin_lock(&block->lock);
327 block->group[grpirq] = 0;
328 gpiochip_unlock_as_irq(&chip->bgc.gc, d->hwirq);
329 spin_unlock(&block->lock);
330}
331
332static struct irq_chip etraxfs_gpio_irq_chip = {
333 .name = "gpio-etraxfs",
334 .irq_ack = etraxfs_gpio_irq_ack,
335 .irq_mask = etraxfs_gpio_irq_mask,
336 .irq_unmask = etraxfs_gpio_irq_unmask,
337 .irq_set_type = etraxfs_gpio_irq_set_type,
338 .irq_request_resources = etraxfs_gpio_irq_request_resources,
339 .irq_release_resources = etraxfs_gpio_irq_release_resources,
340};
341
342static irqreturn_t etraxfs_gpio_interrupt(int irq, void *dev_id)
343{
344 struct etraxfs_gpio_block *block = dev_id;
345 unsigned long intr = readl(block->regs + block->info->r_masked_intr);
346 int bit;
347
348 for_each_set_bit(bit, &intr, 8)
349 generic_handle_irq(block->group[bit]);
350
351 return IRQ_RETVAL(intr & 0xff);
352}
353
107static int etraxfs_gpio_probe(struct platform_device *pdev) 354static int etraxfs_gpio_probe(struct platform_device *pdev)
108{ 355{
109 struct device *dev = &pdev->dev; 356 struct device *dev = &pdev->dev;
110 const struct etraxfs_gpio_info *info; 357 const struct etraxfs_gpio_info *info;
111 const struct of_device_id *match; 358 const struct of_device_id *match;
112 struct bgpio_chip *chips; 359 struct etraxfs_gpio_block *block;
113 struct resource *res; 360 struct etraxfs_gpio_chip *chips;
361 struct resource *res, *irq;
362 bool allportsirq = false;
114 void __iomem *regs; 363 void __iomem *regs;
115 int ret; 364 int ret;
116 int i; 365 int i;
117 366
118 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 367 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
119 regs = devm_ioremap_resource(dev, res); 368 regs = devm_ioremap_resource(dev, res);
120 if (!regs) 369 if (IS_ERR(regs))
121 return -ENOMEM; 370 return PTR_ERR(regs);
122 371
123 match = of_match_node(etraxfs_gpio_of_table, dev->of_node); 372 match = of_match_node(etraxfs_gpio_of_table, dev->of_node);
124 if (!match) 373 if (!match)
@@ -130,19 +379,57 @@ static int etraxfs_gpio_probe(struct platform_device *pdev)
130 if (!chips) 379 if (!chips)
131 return -ENOMEM; 380 return -ENOMEM;
132 381
382 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
383 if (!irq)
384 return -EINVAL;
385
386 block = devm_kzalloc(dev, sizeof(*block), GFP_KERNEL);
387 if (!block)
388 return -ENOMEM;
389
390 spin_lock_init(&block->lock);
391
392 block->regs = regs;
393 block->info = info;
394
395 writel(0, block->regs + info->rw_intr_mask);
396 writel(0, block->regs + info->rw_intr_cfg);
397 if (info->rw_intr_pins) {
398 allportsirq = true;
399 writel(0, block->regs + info->rw_intr_pins);
400 }
401
402 ret = devm_request_irq(dev, irq->start, etraxfs_gpio_interrupt,
403 IRQF_SHARED, dev_name(dev), block);
404 if (ret) {
405 dev_err(dev, "Unable to request irq %d\n", ret);
406 return ret;
407 }
408
133 for (i = 0; i < info->num_ports; i++) { 409 for (i = 0; i < info->num_ports; i++) {
134 struct bgpio_chip *bgc = &chips[i]; 410 struct etraxfs_gpio_chip *chip = &chips[i];
411 struct bgpio_chip *bgc = &chip->bgc;
135 const struct etraxfs_gpio_port *port = &info->ports[i]; 412 const struct etraxfs_gpio_port *port = &info->ports[i];
413 unsigned long flags = BGPIOF_READ_OUTPUT_REG_SET;
414 void __iomem *dat = regs + port->din;
415 void __iomem *set = regs + port->dout;
416 void __iomem *dirout = regs + port->oe;
417
418 chip->block = block;
419
420 if (dirout == set) {
421 dirout = set = NULL;
422 flags = BGPIOF_NO_OUTPUT;
423 }
136 424
137 ret = bgpio_init(bgc, dev, 4, 425 ret = bgpio_init(bgc, dev, 4,
138 regs + port->din, /* dat */ 426 dat, set, NULL, dirout, NULL,
139 regs + port->dout, /* set */ 427 flags);
140 NULL, /* clr */ 428 if (ret) {
141 regs + port->oe, /* dirout */ 429 dev_err(dev, "Unable to init port %s\n",
142 NULL, /* dirin */ 430 port->label);
143 BGPIOF_UNREADABLE_REG_SET); 431 continue;
144 if (ret) 432 }
145 return ret;
146 433
147 bgc->gc.ngpio = port->ngpio; 434 bgc->gc.ngpio = port->ngpio;
148 bgc->gc.label = port->label; 435 bgc->gc.label = port->label;
@@ -152,9 +439,21 @@ static int etraxfs_gpio_probe(struct platform_device *pdev)
152 bgc->gc.of_xlate = etraxfs_gpio_of_xlate; 439 bgc->gc.of_xlate = etraxfs_gpio_of_xlate;
153 440
154 ret = gpiochip_add(&bgc->gc); 441 ret = gpiochip_add(&bgc->gc);
155 if (ret) 442 if (ret) {
156 dev_err(dev, "Unable to register port %s\n", 443 dev_err(dev, "Unable to register port %s\n",
157 bgc->gc.label); 444 bgc->gc.label);
445 continue;
446 }
447
448 if (i > 0 && !allportsirq)
449 continue;
450
451 ret = gpiochip_irqchip_add(&bgc->gc, &etraxfs_gpio_irq_chip, 0,
452 handle_level_irq, IRQ_TYPE_NONE);
453 if (ret) {
454 dev_err(dev, "Unable to add irqchip to port %s\n",
455 bgc->gc.label);
456 }
158 } 457 }
159 458
160 return 0; 459 return 0;
diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
index 9bda3727fac1..a3f07537fe62 100644
--- a/drivers/gpio/gpio-generic.c
+++ b/drivers/gpio/gpio-generic.c
@@ -153,6 +153,10 @@ static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
153 return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio)); 153 return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio));
154} 154}
155 155
156static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val)
157{
158}
159
156static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 160static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
157{ 161{
158 struct bgpio_chip *bgc = to_bgpio_chip(gc); 162 struct bgpio_chip *bgc = to_bgpio_chip(gc);
@@ -279,6 +283,12 @@ static int bgpio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio)
279 return 0; 283 return 0;
280} 284}
281 285
286static int bgpio_dir_out_err(struct gpio_chip *gc, unsigned int gpio,
287 int val)
288{
289 return -EINVAL;
290}
291
282static int bgpio_simple_dir_out(struct gpio_chip *gc, unsigned int gpio, 292static int bgpio_simple_dir_out(struct gpio_chip *gc, unsigned int gpio,
283 int val) 293 int val)
284{ 294{
@@ -302,6 +312,14 @@ static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
302 return 0; 312 return 0;
303} 313}
304 314
315static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio)
316{
317 struct bgpio_chip *bgc = to_bgpio_chip(gc);
318
319 return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ?
320 GPIOF_DIR_OUT : GPIOF_DIR_IN;
321}
322
305static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 323static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
306{ 324{
307 struct bgpio_chip *bgc = to_bgpio_chip(gc); 325 struct bgpio_chip *bgc = to_bgpio_chip(gc);
@@ -351,6 +369,14 @@ static int bgpio_dir_out_inv(struct gpio_chip *gc, unsigned int gpio, int val)
351 return 0; 369 return 0;
352} 370}
353 371
372static int bgpio_get_dir_inv(struct gpio_chip *gc, unsigned int gpio)
373{
374 struct bgpio_chip *bgc = to_bgpio_chip(gc);
375
376 return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ?
377 GPIOF_DIR_IN : GPIOF_DIR_OUT;
378}
379
354static int bgpio_setup_accessors(struct device *dev, 380static int bgpio_setup_accessors(struct device *dev,
355 struct bgpio_chip *bgc, 381 struct bgpio_chip *bgc,
356 bool bit_be, 382 bool bit_be,
@@ -444,6 +470,9 @@ static int bgpio_setup_io(struct bgpio_chip *bgc,
444 bgc->reg_set = set; 470 bgc->reg_set = set;
445 bgc->gc.set = bgpio_set_set; 471 bgc->gc.set = bgpio_set_set;
446 bgc->gc.set_multiple = bgpio_set_multiple_set; 472 bgc->gc.set_multiple = bgpio_set_multiple_set;
473 } else if (flags & BGPIOF_NO_OUTPUT) {
474 bgc->gc.set = bgpio_set_none;
475 bgc->gc.set_multiple = NULL;
447 } else { 476 } else {
448 bgc->gc.set = bgpio_set; 477 bgc->gc.set = bgpio_set;
449 bgc->gc.set_multiple = bgpio_set_multiple; 478 bgc->gc.set_multiple = bgpio_set_multiple;
@@ -460,7 +489,8 @@ static int bgpio_setup_io(struct bgpio_chip *bgc,
460 489
461static int bgpio_setup_direction(struct bgpio_chip *bgc, 490static int bgpio_setup_direction(struct bgpio_chip *bgc,
462 void __iomem *dirout, 491 void __iomem *dirout,
463 void __iomem *dirin) 492 void __iomem *dirin,
493 unsigned long flags)
464{ 494{
465 if (dirout && dirin) { 495 if (dirout && dirin) {
466 return -EINVAL; 496 return -EINVAL;
@@ -468,12 +498,17 @@ static int bgpio_setup_direction(struct bgpio_chip *bgc,
468 bgc->reg_dir = dirout; 498 bgc->reg_dir = dirout;
469 bgc->gc.direction_output = bgpio_dir_out; 499 bgc->gc.direction_output = bgpio_dir_out;
470 bgc->gc.direction_input = bgpio_dir_in; 500 bgc->gc.direction_input = bgpio_dir_in;
501 bgc->gc.get_direction = bgpio_get_dir;
471 } else if (dirin) { 502 } else if (dirin) {
472 bgc->reg_dir = dirin; 503 bgc->reg_dir = dirin;
473 bgc->gc.direction_output = bgpio_dir_out_inv; 504 bgc->gc.direction_output = bgpio_dir_out_inv;
474 bgc->gc.direction_input = bgpio_dir_in_inv; 505 bgc->gc.direction_input = bgpio_dir_in_inv;
506 bgc->gc.get_direction = bgpio_get_dir_inv;
475 } else { 507 } else {
476 bgc->gc.direction_output = bgpio_simple_dir_out; 508 if (flags & BGPIOF_NO_OUTPUT)
509 bgc->gc.direction_output = bgpio_dir_out_err;
510 else
511 bgc->gc.direction_output = bgpio_simple_dir_out;
477 bgc->gc.direction_input = bgpio_simple_dir_in; 512 bgc->gc.direction_input = bgpio_simple_dir_in;
478 } 513 }
479 514
@@ -525,7 +560,7 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
525 if (ret) 560 if (ret)
526 return ret; 561 return ret;
527 562
528 ret = bgpio_setup_direction(bgc, dirout, dirin); 563 ret = bgpio_setup_direction(bgc, dirout, dirin, flags);
529 if (ret) 564 if (ret)
530 return ret; 565 return ret;
531 566
diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c
index 0a8f7617e72e..801423fe8143 100644
--- a/drivers/gpio/gpio-grgpio.c
+++ b/drivers/gpio/gpio-grgpio.c
@@ -104,17 +104,12 @@ static void grgpio_set_imask(struct grgpio_priv *priv, unsigned int offset,
104{ 104{
105 struct bgpio_chip *bgc = &priv->bgc; 105 struct bgpio_chip *bgc = &priv->bgc;
106 unsigned long mask = bgc->pin2mask(bgc, offset); 106 unsigned long mask = bgc->pin2mask(bgc, offset);
107 unsigned long flags;
108
109 spin_lock_irqsave(&bgc->lock, flags);
110 107
111 if (val) 108 if (val)
112 priv->imask |= mask; 109 priv->imask |= mask;
113 else 110 else
114 priv->imask &= ~mask; 111 priv->imask &= ~mask;
115 bgc->write_reg(priv->regs + GRGPIO_IMASK, priv->imask); 112 bgc->write_reg(priv->regs + GRGPIO_IMASK, priv->imask);
116
117 spin_unlock_irqrestore(&bgc->lock, flags);
118} 113}
119 114
120static int grgpio_to_irq(struct gpio_chip *gc, unsigned offset) 115static int grgpio_to_irq(struct gpio_chip *gc, unsigned offset)
@@ -180,16 +175,26 @@ static void grgpio_irq_mask(struct irq_data *d)
180{ 175{
181 struct grgpio_priv *priv = irq_data_get_irq_chip_data(d); 176 struct grgpio_priv *priv = irq_data_get_irq_chip_data(d);
182 int offset = d->hwirq; 177 int offset = d->hwirq;
178 unsigned long flags;
179
180 spin_lock_irqsave(&priv->bgc.lock, flags);
183 181
184 grgpio_set_imask(priv, offset, 0); 182 grgpio_set_imask(priv, offset, 0);
183
184 spin_unlock_irqrestore(&priv->bgc.lock, flags);
185} 185}
186 186
187static void grgpio_irq_unmask(struct irq_data *d) 187static void grgpio_irq_unmask(struct irq_data *d)
188{ 188{
189 struct grgpio_priv *priv = irq_data_get_irq_chip_data(d); 189 struct grgpio_priv *priv = irq_data_get_irq_chip_data(d);
190 int offset = d->hwirq; 190 int offset = d->hwirq;
191 unsigned long flags;
192
193 spin_lock_irqsave(&priv->bgc.lock, flags);
191 194
192 grgpio_set_imask(priv, offset, 1); 195 grgpio_set_imask(priv, offset, 1);
196
197 spin_unlock_irqrestore(&priv->bgc.lock, flags);
193} 198}
194 199
195static struct irq_chip grgpio_irq_chip = { 200static struct irq_chip grgpio_irq_chip = {
@@ -281,12 +286,7 @@ static int grgpio_irq_map(struct irq_domain *d, unsigned int irq,
281 irq_set_chip_data(irq, priv); 286 irq_set_chip_data(irq, priv);
282 irq_set_chip_and_handler(irq, &grgpio_irq_chip, 287 irq_set_chip_and_handler(irq, &grgpio_irq_chip,
283 handle_simple_irq); 288 handle_simple_irq);
284 irq_clear_status_flags(irq, IRQ_NOREQUEST);
285#ifdef CONFIG_ARM
286 set_irq_flags(irq, IRQF_VALID);
287#else
288 irq_set_noprobe(irq); 289 irq_set_noprobe(irq);
289#endif
290 290
291 return ret; 291 return ret;
292} 292}
@@ -301,9 +301,6 @@ static void grgpio_irq_unmap(struct irq_domain *d, unsigned int irq)
301 int ngpio = priv->bgc.gc.ngpio; 301 int ngpio = priv->bgc.gc.ngpio;
302 int i; 302 int i;
303 303
304#ifdef CONFIG_ARM
305 set_irq_flags(irq, 0);
306#endif
307 irq_set_chip_and_handler(irq, NULL, NULL); 304 irq_set_chip_and_handler(irq, NULL, NULL);
308 irq_set_chip_data(irq, NULL); 305 irq_set_chip_data(irq, NULL);
309 306
diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c
index 7d3c90e9da71..8c5252c6c327 100644
--- a/drivers/gpio/gpio-max732x.c
+++ b/drivers/gpio/gpio-max732x.c
@@ -685,9 +685,14 @@ static int max732x_probe(struct i2c_client *client,
685 685
686 mutex_init(&chip->lock); 686 mutex_init(&chip->lock);
687 687
688 max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]); 688 ret = max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]);
689 if (nr_port > 8) 689 if (ret)
690 max732x_readb(chip, is_group_a(chip, 8), &chip->reg_out[1]); 690 goto out_failed;
691 if (nr_port > 8) {
692 ret = max732x_readb(chip, is_group_a(chip, 8), &chip->reg_out[1]);
693 if (ret)
694 goto out_failed;
695 }
691 696
692 ret = gpiochip_add(&chip->gpio_chip); 697 ret = gpiochip_add(&chip->gpio_chip);
693 if (ret) 698 if (ret)
diff --git a/drivers/gpio/gpio-mcp23s08.c b/drivers/gpio/gpio-mcp23s08.c
index 2fc7ff852d16..73db7ecd7ffd 100644
--- a/drivers/gpio/gpio-mcp23s08.c
+++ b/drivers/gpio/gpio-mcp23s08.c
@@ -507,11 +507,7 @@ static int mcp23s08_irq_setup(struct mcp23s08 *mcp)
507 irq_set_chip_data(irq, mcp); 507 irq_set_chip_data(irq, mcp);
508 irq_set_chip(irq, &mcp23s08_irq_chip); 508 irq_set_chip(irq, &mcp23s08_irq_chip);
509 irq_set_nested_thread(irq, true); 509 irq_set_nested_thread(irq, true);
510#ifdef CONFIG_ARM
511 set_irq_flags(irq, IRQF_VALID);
512#else
513 irq_set_noprobe(irq); 510 irq_set_noprobe(irq);
514#endif
515 } 511 }
516 return 0; 512 return 0;
517} 513}
diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 20aa66f34f6e..8ef7a12de983 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -32,7 +32,7 @@
32 32
33struct mpc8xxx_gpio_chip { 33struct mpc8xxx_gpio_chip {
34 struct of_mm_gpio_chip mm_gc; 34 struct of_mm_gpio_chip mm_gc;
35 spinlock_t lock; 35 raw_spinlock_t lock;
36 36
37 /* 37 /*
38 * shadowed data register to be able to clear/set output pins in 38 * shadowed data register to be able to clear/set output pins in
@@ -95,7 +95,7 @@ static void mpc8xxx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
95 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); 95 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
96 unsigned long flags; 96 unsigned long flags;
97 97
98 spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 98 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
99 99
100 if (val) 100 if (val)
101 mpc8xxx_gc->data |= mpc8xxx_gpio2mask(gpio); 101 mpc8xxx_gc->data |= mpc8xxx_gpio2mask(gpio);
@@ -104,7 +104,7 @@ static void mpc8xxx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
104 104
105 out_be32(mm->regs + GPIO_DAT, mpc8xxx_gc->data); 105 out_be32(mm->regs + GPIO_DAT, mpc8xxx_gc->data);
106 106
107 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 107 raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
108} 108}
109 109
110static void mpc8xxx_gpio_set_multiple(struct gpio_chip *gc, 110static void mpc8xxx_gpio_set_multiple(struct gpio_chip *gc,
@@ -115,7 +115,7 @@ static void mpc8xxx_gpio_set_multiple(struct gpio_chip *gc,
115 unsigned long flags; 115 unsigned long flags;
116 int i; 116 int i;
117 117
118 spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 118 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
119 119
120 for (i = 0; i < gc->ngpio; i++) { 120 for (i = 0; i < gc->ngpio; i++) {
121 if (*mask == 0) 121 if (*mask == 0)
@@ -130,7 +130,7 @@ static void mpc8xxx_gpio_set_multiple(struct gpio_chip *gc,
130 130
131 out_be32(mm->regs + GPIO_DAT, mpc8xxx_gc->data); 131 out_be32(mm->regs + GPIO_DAT, mpc8xxx_gc->data);
132 132
133 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 133 raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
134} 134}
135 135
136static int mpc8xxx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio) 136static int mpc8xxx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
@@ -139,11 +139,11 @@ static int mpc8xxx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
139 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); 139 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
140 unsigned long flags; 140 unsigned long flags;
141 141
142 spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 142 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
143 143
144 clrbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio)); 144 clrbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio));
145 145
146 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 146 raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
147 147
148 return 0; 148 return 0;
149} 149}
@@ -156,11 +156,11 @@ static int mpc8xxx_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val
156 156
157 mpc8xxx_gpio_set(gc, gpio, val); 157 mpc8xxx_gpio_set(gc, gpio, val);
158 158
159 spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 159 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
160 160
161 setbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio)); 161 setbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio));
162 162
163 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 163 raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
164 164
165 return 0; 165 return 0;
166} 166}
@@ -174,6 +174,15 @@ static int mpc5121_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val
174 return mpc8xxx_gpio_dir_out(gc, gpio, val); 174 return mpc8xxx_gpio_dir_out(gc, gpio, val);
175} 175}
176 176
177static int mpc5125_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
178{
179 /* GPIO 0..3 are input only on MPC5125 */
180 if (gpio <= 3)
181 return -EINVAL;
182
183 return mpc8xxx_gpio_dir_out(gc, gpio, val);
184}
185
177static int mpc8xxx_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 186static int mpc8xxx_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
178{ 187{
179 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); 188 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
@@ -206,11 +215,11 @@ static void mpc8xxx_irq_unmask(struct irq_data *d)
206 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc; 215 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc;
207 unsigned long flags; 216 unsigned long flags;
208 217
209 spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 218 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
210 219
211 setbits32(mm->regs + GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d))); 220 setbits32(mm->regs + GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
212 221
213 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 222 raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
214} 223}
215 224
216static void mpc8xxx_irq_mask(struct irq_data *d) 225static void mpc8xxx_irq_mask(struct irq_data *d)
@@ -219,11 +228,11 @@ static void mpc8xxx_irq_mask(struct irq_data *d)
219 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc; 228 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc;
220 unsigned long flags; 229 unsigned long flags;
221 230
222 spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 231 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
223 232
224 clrbits32(mm->regs + GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d))); 233 clrbits32(mm->regs + GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
225 234
226 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 235 raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
227} 236}
228 237
229static void mpc8xxx_irq_ack(struct irq_data *d) 238static void mpc8xxx_irq_ack(struct irq_data *d)
@@ -242,17 +251,17 @@ static int mpc8xxx_irq_set_type(struct irq_data *d, unsigned int flow_type)
242 251
243 switch (flow_type) { 252 switch (flow_type) {
244 case IRQ_TYPE_EDGE_FALLING: 253 case IRQ_TYPE_EDGE_FALLING:
245 spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 254 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
246 setbits32(mm->regs + GPIO_ICR, 255 setbits32(mm->regs + GPIO_ICR,
247 mpc8xxx_gpio2mask(irqd_to_hwirq(d))); 256 mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
248 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 257 raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
249 break; 258 break;
250 259
251 case IRQ_TYPE_EDGE_BOTH: 260 case IRQ_TYPE_EDGE_BOTH:
252 spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 261 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
253 clrbits32(mm->regs + GPIO_ICR, 262 clrbits32(mm->regs + GPIO_ICR,
254 mpc8xxx_gpio2mask(irqd_to_hwirq(d))); 263 mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
255 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 264 raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
256 break; 265 break;
257 266
258 default: 267 default:
@@ -282,22 +291,22 @@ static int mpc512x_irq_set_type(struct irq_data *d, unsigned int flow_type)
282 switch (flow_type) { 291 switch (flow_type) {
283 case IRQ_TYPE_EDGE_FALLING: 292 case IRQ_TYPE_EDGE_FALLING:
284 case IRQ_TYPE_LEVEL_LOW: 293 case IRQ_TYPE_LEVEL_LOW:
285 spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 294 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
286 clrsetbits_be32(reg, 3 << shift, 2 << shift); 295 clrsetbits_be32(reg, 3 << shift, 2 << shift);
287 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 296 raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
288 break; 297 break;
289 298
290 case IRQ_TYPE_EDGE_RISING: 299 case IRQ_TYPE_EDGE_RISING:
291 case IRQ_TYPE_LEVEL_HIGH: 300 case IRQ_TYPE_LEVEL_HIGH:
292 spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 301 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
293 clrsetbits_be32(reg, 3 << shift, 1 << shift); 302 clrsetbits_be32(reg, 3 << shift, 1 << shift);
294 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 303 raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
295 break; 304 break;
296 305
297 case IRQ_TYPE_EDGE_BOTH: 306 case IRQ_TYPE_EDGE_BOTH:
298 spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 307 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
299 clrbits32(reg, 3 << shift); 308 clrbits32(reg, 3 << shift);
300 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 309 raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
301 break; 310 break;
302 311
303 default: 312 default:
@@ -312,17 +321,13 @@ static struct irq_chip mpc8xxx_irq_chip = {
312 .irq_unmask = mpc8xxx_irq_unmask, 321 .irq_unmask = mpc8xxx_irq_unmask,
313 .irq_mask = mpc8xxx_irq_mask, 322 .irq_mask = mpc8xxx_irq_mask,
314 .irq_ack = mpc8xxx_irq_ack, 323 .irq_ack = mpc8xxx_irq_ack,
324 /* this might get overwritten in mpc8xxx_probe() */
315 .irq_set_type = mpc8xxx_irq_set_type, 325 .irq_set_type = mpc8xxx_irq_set_type,
316}; 326};
317 327
318static int mpc8xxx_gpio_irq_map(struct irq_domain *h, unsigned int irq, 328static int mpc8xxx_gpio_irq_map(struct irq_domain *h, unsigned int irq,
319 irq_hw_number_t hwirq) 329 irq_hw_number_t hwirq)
320{ 330{
321 struct mpc8xxx_gpio_chip *mpc8xxx_gc = h->host_data;
322
323 if (mpc8xxx_gc->of_dev_id_data)
324 mpc8xxx_irq_chip.irq_set_type = mpc8xxx_gc->of_dev_id_data;
325
326 irq_set_chip_data(irq, h->host_data); 331 irq_set_chip_data(irq, h->host_data);
327 irq_set_chip_and_handler(irq, &mpc8xxx_irq_chip, handle_level_irq); 332 irq_set_chip_and_handler(irq, &mpc8xxx_irq_chip, handle_level_irq);
328 333
@@ -334,11 +339,38 @@ static const struct irq_domain_ops mpc8xxx_gpio_irq_ops = {
334 .xlate = irq_domain_xlate_twocell, 339 .xlate = irq_domain_xlate_twocell,
335}; 340};
336 341
337static struct of_device_id mpc8xxx_gpio_ids[] = { 342struct mpc8xxx_gpio_devtype {
343 int (*gpio_dir_out)(struct gpio_chip *, unsigned int, int);
344 int (*gpio_get)(struct gpio_chip *, unsigned int);
345 int (*irq_set_type)(struct irq_data *, unsigned int);
346};
347
348static const struct mpc8xxx_gpio_devtype mpc512x_gpio_devtype = {
349 .gpio_dir_out = mpc5121_gpio_dir_out,
350 .irq_set_type = mpc512x_irq_set_type,
351};
352
353static const struct mpc8xxx_gpio_devtype mpc5125_gpio_devtype = {
354 .gpio_dir_out = mpc5125_gpio_dir_out,
355 .irq_set_type = mpc512x_irq_set_type,
356};
357
358static const struct mpc8xxx_gpio_devtype mpc8572_gpio_devtype = {
359 .gpio_get = mpc8572_gpio_get,
360};
361
362static const struct mpc8xxx_gpio_devtype mpc8xxx_gpio_devtype_default = {
363 .gpio_dir_out = mpc8xxx_gpio_dir_out,
364 .gpio_get = mpc8xxx_gpio_get,
365 .irq_set_type = mpc8xxx_irq_set_type,
366};
367
368static const struct of_device_id mpc8xxx_gpio_ids[] = {
338 { .compatible = "fsl,mpc8349-gpio", }, 369 { .compatible = "fsl,mpc8349-gpio", },
339 { .compatible = "fsl,mpc8572-gpio", }, 370 { .compatible = "fsl,mpc8572-gpio", .data = &mpc8572_gpio_devtype, },
340 { .compatible = "fsl,mpc8610-gpio", }, 371 { .compatible = "fsl,mpc8610-gpio", },
341 { .compatible = "fsl,mpc5121-gpio", .data = mpc512x_irq_set_type, }, 372 { .compatible = "fsl,mpc5121-gpio", .data = &mpc512x_gpio_devtype, },
373 { .compatible = "fsl,mpc5125-gpio", .data = &mpc5125_gpio_devtype, },
342 { .compatible = "fsl,pq3-gpio", }, 374 { .compatible = "fsl,pq3-gpio", },
343 { .compatible = "fsl,qoriq-gpio", }, 375 { .compatible = "fsl,qoriq-gpio", },
344 {} 376 {}
@@ -351,6 +383,8 @@ static int mpc8xxx_probe(struct platform_device *pdev)
351 struct of_mm_gpio_chip *mm_gc; 383 struct of_mm_gpio_chip *mm_gc;
352 struct gpio_chip *gc; 384 struct gpio_chip *gc;
353 const struct of_device_id *id; 385 const struct of_device_id *id;
386 const struct mpc8xxx_gpio_devtype *devtype =
387 of_device_get_match_data(&pdev->dev);
354 int ret; 388 int ret;
355 389
356 mpc8xxx_gc = devm_kzalloc(&pdev->dev, sizeof(*mpc8xxx_gc), GFP_KERNEL); 390 mpc8xxx_gc = devm_kzalloc(&pdev->dev, sizeof(*mpc8xxx_gc), GFP_KERNEL);
@@ -359,7 +393,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)
359 393
360 platform_set_drvdata(pdev, mpc8xxx_gc); 394 platform_set_drvdata(pdev, mpc8xxx_gc);
361 395
362 spin_lock_init(&mpc8xxx_gc->lock); 396 raw_spin_lock_init(&mpc8xxx_gc->lock);
363 397
364 mm_gc = &mpc8xxx_gc->mm_gc; 398 mm_gc = &mpc8xxx_gc->mm_gc;
365 gc = &mm_gc->gc; 399 gc = &mm_gc->gc;
@@ -367,10 +401,18 @@ static int mpc8xxx_probe(struct platform_device *pdev)
367 mm_gc->save_regs = mpc8xxx_gpio_save_regs; 401 mm_gc->save_regs = mpc8xxx_gpio_save_regs;
368 gc->ngpio = MPC8XXX_GPIO_PINS; 402 gc->ngpio = MPC8XXX_GPIO_PINS;
369 gc->direction_input = mpc8xxx_gpio_dir_in; 403 gc->direction_input = mpc8xxx_gpio_dir_in;
370 gc->direction_output = of_device_is_compatible(np, "fsl,mpc5121-gpio") ? 404
371 mpc5121_gpio_dir_out : mpc8xxx_gpio_dir_out; 405 if (!devtype)
372 gc->get = of_device_is_compatible(np, "fsl,mpc8572-gpio") ? 406 devtype = &mpc8xxx_gpio_devtype_default;
373 mpc8572_gpio_get : mpc8xxx_gpio_get; 407
408 /*
409 * It's assumed that only a single type of gpio controller is available
410 * on the current machine, so overwriting global data is fine.
411 */
412 mpc8xxx_irq_chip.irq_set_type = devtype->irq_set_type;
413
414 gc->direction_output = devtype->gpio_dir_out ?: mpc8xxx_gpio_dir_out;
415 gc->get = devtype->gpio_get ?: mpc8xxx_gpio_get;
374 gc->set = mpc8xxx_gpio_set; 416 gc->set = mpc8xxx_gpio_set;
375 gc->set_multiple = mpc8xxx_gpio_set_multiple; 417 gc->set_multiple = mpc8xxx_gpio_set_multiple;
376 gc->to_irq = mpc8xxx_gpio_to_irq; 418 gc->to_irq = mpc8xxx_gpio_to_irq;
@@ -396,8 +438,8 @@ static int mpc8xxx_probe(struct platform_device *pdev)
396 out_be32(mm_gc->regs + GPIO_IER, 0xffffffff); 438 out_be32(mm_gc->regs + GPIO_IER, 0xffffffff);
397 out_be32(mm_gc->regs + GPIO_IMR, 0); 439 out_be32(mm_gc->regs + GPIO_IMR, 0);
398 440
399 irq_set_handler_data(mpc8xxx_gc->irqn, mpc8xxx_gc); 441 irq_set_chained_handler_and_data(mpc8xxx_gc->irqn,
400 irq_set_chained_handler(mpc8xxx_gc->irqn, mpc8xxx_gpio_irq_cascade); 442 mpc8xxx_gpio_irq_cascade, mpc8xxx_gc);
401 443
402 return 0; 444 return 0;
403} 445}
@@ -407,8 +449,7 @@ static int mpc8xxx_remove(struct platform_device *pdev)
407 struct mpc8xxx_gpio_chip *mpc8xxx_gc = platform_get_drvdata(pdev); 449 struct mpc8xxx_gpio_chip *mpc8xxx_gc = platform_get_drvdata(pdev);
408 450
409 if (mpc8xxx_gc->irq) { 451 if (mpc8xxx_gc->irq) {
410 irq_set_handler_data(mpc8xxx_gc->irqn, NULL); 452 irq_set_chained_handler_and_data(mpc8xxx_gc->irqn, NULL, NULL);
411 irq_set_chained_handler(mpc8xxx_gc->irqn, NULL);
412 irq_domain_remove(mpc8xxx_gc->irq); 453 irq_domain_remove(mpc8xxx_gc->irq);
413 } 454 }
414 455
diff --git a/drivers/gpio/gpio-msm-v2.c b/drivers/gpio/gpio-msm-v2.c
index 52ff18229fdc..d2012cfb5571 100644
--- a/drivers/gpio/gpio-msm-v2.c
+++ b/drivers/gpio/gpio-msm-v2.c
@@ -187,14 +187,6 @@ static int msm_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
187 return irq_create_mapping(domain, offset); 187 return irq_create_mapping(domain, offset);
188} 188}
189 189
190static inline int msm_irq_to_gpio(struct gpio_chip *chip, unsigned irq)
191{
192 struct irq_data *irq_data = irq_get_irq_data(irq);
193
194 return irq_data->hwirq;
195}
196
197
198/* For dual-edge interrupts in software, since the hardware has no 190/* For dual-edge interrupts in software, since the hardware has no
199 * such support: 191 * such support:
200 * 192 *
@@ -238,7 +230,7 @@ static void msm_gpio_update_dual_edge_pos(unsigned gpio)
238 230
239static void msm_gpio_irq_ack(struct irq_data *d) 231static void msm_gpio_irq_ack(struct irq_data *d)
240{ 232{
241 int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq); 233 int gpio = d->hwirq;
242 234
243 writel(BIT(INTR_STATUS), GPIO_INTR_STATUS(gpio)); 235 writel(BIT(INTR_STATUS), GPIO_INTR_STATUS(gpio));
244 if (test_bit(gpio, msm_gpio.dual_edge_irqs)) 236 if (test_bit(gpio, msm_gpio.dual_edge_irqs))
@@ -247,8 +239,8 @@ static void msm_gpio_irq_ack(struct irq_data *d)
247 239
248static void msm_gpio_irq_mask(struct irq_data *d) 240static void msm_gpio_irq_mask(struct irq_data *d)
249{ 241{
250 int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq);
251 unsigned long irq_flags; 242 unsigned long irq_flags;
243 int gpio = d->hwirq;
252 244
253 spin_lock_irqsave(&tlmm_lock, irq_flags); 245 spin_lock_irqsave(&tlmm_lock, irq_flags);
254 writel(TARGET_PROC_NONE, GPIO_INTR_CFG_SU(gpio)); 246 writel(TARGET_PROC_NONE, GPIO_INTR_CFG_SU(gpio));
@@ -259,8 +251,8 @@ static void msm_gpio_irq_mask(struct irq_data *d)
259 251
260static void msm_gpio_irq_unmask(struct irq_data *d) 252static void msm_gpio_irq_unmask(struct irq_data *d)
261{ 253{
262 int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq);
263 unsigned long irq_flags; 254 unsigned long irq_flags;
255 int gpio = d->hwirq;
264 256
265 spin_lock_irqsave(&tlmm_lock, irq_flags); 257 spin_lock_irqsave(&tlmm_lock, irq_flags);
266 __set_bit(gpio, msm_gpio.enabled_irqs); 258 __set_bit(gpio, msm_gpio.enabled_irqs);
@@ -271,8 +263,8 @@ static void msm_gpio_irq_unmask(struct irq_data *d)
271 263
272static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int flow_type) 264static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int flow_type)
273{ 265{
274 int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq);
275 unsigned long irq_flags; 266 unsigned long irq_flags;
267 int gpio = d->hwirq;
276 uint32_t bits; 268 uint32_t bits;
277 269
278 spin_lock_irqsave(&tlmm_lock, irq_flags); 270 spin_lock_irqsave(&tlmm_lock, irq_flags);
@@ -281,14 +273,14 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int flow_type)
281 273
282 if (flow_type & IRQ_TYPE_EDGE_BOTH) { 274 if (flow_type & IRQ_TYPE_EDGE_BOTH) {
283 bits |= BIT(INTR_DECT_CTL); 275 bits |= BIT(INTR_DECT_CTL);
284 __irq_set_handler_locked(d->irq, handle_edge_irq); 276 irq_set_handler_locked(d, handle_edge_irq);
285 if ((flow_type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) 277 if ((flow_type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
286 __set_bit(gpio, msm_gpio.dual_edge_irqs); 278 __set_bit(gpio, msm_gpio.dual_edge_irqs);
287 else 279 else
288 __clear_bit(gpio, msm_gpio.dual_edge_irqs); 280 __clear_bit(gpio, msm_gpio.dual_edge_irqs);
289 } else { 281 } else {
290 bits &= ~BIT(INTR_DECT_CTL); 282 bits &= ~BIT(INTR_DECT_CTL);
291 __irq_set_handler_locked(d->irq, handle_level_irq); 283 irq_set_handler_locked(d, handle_level_irq);
292 __clear_bit(gpio, msm_gpio.dual_edge_irqs); 284 __clear_bit(gpio, msm_gpio.dual_edge_irqs);
293 } 285 }
294 286
@@ -331,7 +323,7 @@ static void msm_summary_irq_handler(unsigned int irq, struct irq_desc *desc)
331 323
332static int msm_gpio_irq_set_wake(struct irq_data *d, unsigned int on) 324static int msm_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
333{ 325{
334 int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq); 326 int gpio = d->hwirq;
335 327
336 if (on) { 328 if (on) {
337 if (bitmap_empty(msm_gpio.wake_irqs, MAX_NR_GPIO)) 329 if (bitmap_empty(msm_gpio.wake_irqs, MAX_NR_GPIO))
@@ -363,7 +355,6 @@ static int msm_gpio_irq_domain_map(struct irq_domain *d, unsigned int irq,
363 irq_set_lockdep_class(irq, &msm_gpio_lock_class); 355 irq_set_lockdep_class(irq, &msm_gpio_lock_class);
364 irq_set_chip_and_handler(irq, &msm_gpio_irq_chip, 356 irq_set_chip_and_handler(irq, &msm_gpio_irq_chip,
365 handle_level_irq); 357 handle_level_irq);
366 set_irq_flags(irq, IRQF_VALID);
367 358
368 return 0; 359 return 0;
369} 360}
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 1a54205860f5..b396bf3bf294 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -458,9 +458,9 @@ static int mvebu_gpio_irq_set_type(struct irq_data *d, unsigned int type)
458 return 0; 458 return 0;
459} 459}
460 460
461static void mvebu_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) 461static void mvebu_gpio_irq_handler(unsigned int __irq, struct irq_desc *desc)
462{ 462{
463 struct mvebu_gpio_chip *mvchip = irq_get_handler_data(irq); 463 struct mvebu_gpio_chip *mvchip = irq_desc_get_handler_data(desc);
464 struct irq_chip *chip = irq_desc_get_chip(desc); 464 struct irq_chip *chip = irq_desc_get_chip(desc);
465 u32 cause, type; 465 u32 cause, type;
466 int i; 466 int i;
@@ -787,8 +787,8 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
787 787
788 if (irq < 0) 788 if (irq < 0)
789 continue; 789 continue;
790 irq_set_handler_data(irq, mvchip); 790 irq_set_chained_handler_and_data(irq, mvebu_gpio_irq_handler,
791 irq_set_chained_handler(irq, mvebu_gpio_irq_handler); 791 mvchip);
792 } 792 }
793 793
794 mvchip->irqbase = irq_alloc_descs(-1, 0, ngpios, -1); 794 mvchip->irqbase = irq_alloc_descs(-1, 0, ngpios, -1);
diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
index ec1eb1b7250f..b752b560126e 100644
--- a/drivers/gpio/gpio-mxc.c
+++ b/drivers/gpio/gpio-mxc.c
@@ -275,8 +275,8 @@ static void mxc_gpio_irq_handler(struct mxc_gpio_port *port, u32 irq_stat)
275static void mx3_gpio_irq_handler(u32 irq, struct irq_desc *desc) 275static void mx3_gpio_irq_handler(u32 irq, struct irq_desc *desc)
276{ 276{
277 u32 irq_stat; 277 u32 irq_stat;
278 struct mxc_gpio_port *port = irq_get_handler_data(irq); 278 struct mxc_gpio_port *port = irq_desc_get_handler_data(desc);
279 struct irq_chip *chip = irq_get_chip(irq); 279 struct irq_chip *chip = irq_desc_get_chip(desc);
280 280
281 chained_irq_enter(chip, desc); 281 chained_irq_enter(chip, desc);
282 282
@@ -292,7 +292,7 @@ static void mx2_gpio_irq_handler(u32 irq, struct irq_desc *desc)
292{ 292{
293 u32 irq_msk, irq_stat; 293 u32 irq_msk, irq_stat;
294 struct mxc_gpio_port *port; 294 struct mxc_gpio_port *port;
295 struct irq_chip *chip = irq_get_chip(irq); 295 struct irq_chip *chip = irq_desc_get_chip(desc);
296 296
297 chained_irq_enter(chip, desc); 297 chained_irq_enter(chip, desc);
298 298
@@ -339,7 +339,7 @@ static int gpio_set_wake_irq(struct irq_data *d, u32 enable)
339 return 0; 339 return 0;
340} 340}
341 341
342static void __init mxc_gpio_init_gc(struct mxc_gpio_port *port, int irq_base) 342static void mxc_gpio_init_gc(struct mxc_gpio_port *port, int irq_base)
343{ 343{
344 struct irq_chip_generic *gc; 344 struct irq_chip_generic *gc;
345 struct irq_chip_type *ct; 345 struct irq_chip_type *ct;
@@ -354,6 +354,7 @@ static void __init mxc_gpio_init_gc(struct mxc_gpio_port *port, int irq_base)
354 ct->chip.irq_unmask = irq_gc_mask_set_bit; 354 ct->chip.irq_unmask = irq_gc_mask_set_bit;
355 ct->chip.irq_set_type = gpio_set_irq_type; 355 ct->chip.irq_set_type = gpio_set_irq_type;
356 ct->chip.irq_set_wake = gpio_set_wake_irq; 356 ct->chip.irq_set_wake = gpio_set_wake_irq;
357 ct->chip.flags = IRQCHIP_MASK_ON_SUSPEND;
357 ct->regs.ack = GPIO_ISR; 358 ct->regs.ack = GPIO_ISR;
358 ct->regs.mask = GPIO_IMR; 359 ct->regs.mask = GPIO_IMR;
359 360
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c
index 551d15d7c369..b7f383eb18d9 100644
--- a/drivers/gpio/gpio-mxs.c
+++ b/drivers/gpio/gpio-mxs.c
@@ -157,7 +157,7 @@ static void mxs_flip_edge(struct mxs_gpio_port *port, u32 gpio)
157static void mxs_gpio_irq_handler(u32 irq, struct irq_desc *desc) 157static void mxs_gpio_irq_handler(u32 irq, struct irq_desc *desc)
158{ 158{
159 u32 irq_stat; 159 u32 irq_stat;
160 struct mxs_gpio_port *port = irq_get_handler_data(irq); 160 struct mxs_gpio_port *port = irq_desc_get_handler_data(desc);
161 161
162 desc->irq_data.chip->irq_ack(&desc->irq_data); 162 desc->irq_data.chip->irq_ack(&desc->irq_data);
163 163
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index 61a731ff9a07..2ae0d47e9554 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -29,6 +29,7 @@
29#include <linux/platform_data/gpio-omap.h> 29#include <linux/platform_data/gpio-omap.h>
30 30
31#define OFF_MODE 1 31#define OFF_MODE 1
32#define OMAP4_GPIO_DEBOUNCINGTIME_MASK 0xFF
32 33
33static LIST_HEAD(omap_gpio_list); 34static LIST_HEAD(omap_gpio_list);
34 35
@@ -57,7 +58,7 @@ struct gpio_bank {
57 u32 saved_datain; 58 u32 saved_datain;
58 u32 level_mask; 59 u32 level_mask;
59 u32 toggle_mask; 60 u32 toggle_mask;
60 spinlock_t lock; 61 raw_spinlock_t lock;
61 struct gpio_chip chip; 62 struct gpio_chip chip;
62 struct clk *dbck; 63 struct clk *dbck;
63 u32 mod_usage; 64 u32 mod_usage;
@@ -175,7 +176,7 @@ static inline void omap_gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set
175static inline void omap_gpio_dbck_enable(struct gpio_bank *bank) 176static inline void omap_gpio_dbck_enable(struct gpio_bank *bank)
176{ 177{
177 if (bank->dbck_enable_mask && !bank->dbck_enabled) { 178 if (bank->dbck_enable_mask && !bank->dbck_enabled) {
178 clk_prepare_enable(bank->dbck); 179 clk_enable(bank->dbck);
179 bank->dbck_enabled = true; 180 bank->dbck_enabled = true;
180 181
181 writel_relaxed(bank->dbck_enable_mask, 182 writel_relaxed(bank->dbck_enable_mask,
@@ -193,7 +194,7 @@ static inline void omap_gpio_dbck_disable(struct gpio_bank *bank)
193 */ 194 */
194 writel_relaxed(0, bank->base + bank->regs->debounce_en); 195 writel_relaxed(0, bank->base + bank->regs->debounce_en);
195 196
196 clk_disable_unprepare(bank->dbck); 197 clk_disable(bank->dbck);
197 bank->dbck_enabled = false; 198 bank->dbck_enabled = false;
198 } 199 }
199} 200}
@@ -204,8 +205,9 @@ static inline void omap_gpio_dbck_disable(struct gpio_bank *bank)
204 * @offset: the gpio number on this @bank 205 * @offset: the gpio number on this @bank
205 * @debounce: debounce time to use 206 * @debounce: debounce time to use
206 * 207 *
207 * OMAP's debounce time is in 31us steps so we need 208 * OMAP's debounce time is in 31us steps
208 * to convert and round up to the closest unit. 209 * <debounce time> = (GPIO_DEBOUNCINGTIME[7:0].DEBOUNCETIME + 1) x 31
210 * so we need to convert and round up to the closest unit.
209 */ 211 */
210static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset, 212static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset,
211 unsigned debounce) 213 unsigned debounce)
@@ -213,34 +215,33 @@ static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset,
213 void __iomem *reg; 215 void __iomem *reg;
214 u32 val; 216 u32 val;
215 u32 l; 217 u32 l;
218 bool enable = !!debounce;
216 219
217 if (!bank->dbck_flag) 220 if (!bank->dbck_flag)
218 return; 221 return;
219 222
220 if (debounce < 32) 223 if (enable) {
221 debounce = 0x01; 224 debounce = DIV_ROUND_UP(debounce, 31) - 1;
222 else if (debounce > 7936) 225 debounce &= OMAP4_GPIO_DEBOUNCINGTIME_MASK;
223 debounce = 0xff; 226 }
224 else
225 debounce = (debounce / 0x1f) - 1;
226 227
227 l = BIT(offset); 228 l = BIT(offset);
228 229
229 clk_prepare_enable(bank->dbck); 230 clk_enable(bank->dbck);
230 reg = bank->base + bank->regs->debounce; 231 reg = bank->base + bank->regs->debounce;
231 writel_relaxed(debounce, reg); 232 writel_relaxed(debounce, reg);
232 233
233 reg = bank->base + bank->regs->debounce_en; 234 reg = bank->base + bank->regs->debounce_en;
234 val = readl_relaxed(reg); 235 val = readl_relaxed(reg);
235 236
236 if (debounce) 237 if (enable)
237 val |= l; 238 val |= l;
238 else 239 else
239 val &= ~l; 240 val &= ~l;
240 bank->dbck_enable_mask = val; 241 bank->dbck_enable_mask = val;
241 242
242 writel_relaxed(val, reg); 243 writel_relaxed(val, reg);
243 clk_disable_unprepare(bank->dbck); 244 clk_disable(bank->dbck);
244 /* 245 /*
245 * Enable debounce clock per module. 246 * Enable debounce clock per module.
246 * This call is mandatory because in omap_gpio_request() when 247 * This call is mandatory because in omap_gpio_request() when
@@ -285,7 +286,7 @@ static void omap_clear_gpio_debounce(struct gpio_bank *bank, unsigned offset)
285 bank->context.debounce = 0; 286 bank->context.debounce = 0;
286 writel_relaxed(bank->context.debounce, bank->base + 287 writel_relaxed(bank->context.debounce, bank->base +
287 bank->regs->debounce); 288 bank->regs->debounce);
288 clk_disable_unprepare(bank->dbck); 289 clk_disable(bank->dbck);
289 bank->dbck_enabled = false; 290 bank->dbck_enabled = false;
290 } 291 }
291} 292}
@@ -498,24 +499,24 @@ static int omap_gpio_irq_type(struct irq_data *d, unsigned type)
498 if (!BANK_USED(bank)) 499 if (!BANK_USED(bank))
499 pm_runtime_get_sync(bank->dev); 500 pm_runtime_get_sync(bank->dev);
500 501
501 spin_lock_irqsave(&bank->lock, flags); 502 raw_spin_lock_irqsave(&bank->lock, flags);
502 retval = omap_set_gpio_triggering(bank, offset, type); 503 retval = omap_set_gpio_triggering(bank, offset, type);
503 if (retval) { 504 if (retval) {
504 spin_unlock_irqrestore(&bank->lock, flags); 505 raw_spin_unlock_irqrestore(&bank->lock, flags);
505 goto error; 506 goto error;
506 } 507 }
507 omap_gpio_init_irq(bank, offset); 508 omap_gpio_init_irq(bank, offset);
508 if (!omap_gpio_is_input(bank, offset)) { 509 if (!omap_gpio_is_input(bank, offset)) {
509 spin_unlock_irqrestore(&bank->lock, flags); 510 raw_spin_unlock_irqrestore(&bank->lock, flags);
510 retval = -EINVAL; 511 retval = -EINVAL;
511 goto error; 512 goto error;
512 } 513 }
513 spin_unlock_irqrestore(&bank->lock, flags); 514 raw_spin_unlock_irqrestore(&bank->lock, flags);
514 515
515 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) 516 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
516 __irq_set_handler_locked(d->irq, handle_level_irq); 517 irq_set_handler_locked(d, handle_level_irq);
517 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) 518 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
518 __irq_set_handler_locked(d->irq, handle_edge_irq); 519 irq_set_handler_locked(d, handle_edge_irq);
519 520
520 return 0; 521 return 0;
521 522
@@ -636,14 +637,14 @@ static int omap_set_gpio_wakeup(struct gpio_bank *bank, unsigned offset,
636 return -EINVAL; 637 return -EINVAL;
637 } 638 }
638 639
639 spin_lock_irqsave(&bank->lock, flags); 640 raw_spin_lock_irqsave(&bank->lock, flags);
640 if (enable) 641 if (enable)
641 bank->context.wake_en |= gpio_bit; 642 bank->context.wake_en |= gpio_bit;
642 else 643 else
643 bank->context.wake_en &= ~gpio_bit; 644 bank->context.wake_en &= ~gpio_bit;
644 645
645 writel_relaxed(bank->context.wake_en, bank->base + bank->regs->wkup_en); 646 writel_relaxed(bank->context.wake_en, bank->base + bank->regs->wkup_en);
646 spin_unlock_irqrestore(&bank->lock, flags); 647 raw_spin_unlock_irqrestore(&bank->lock, flags);
647 648
648 return 0; 649 return 0;
649} 650}
@@ -669,10 +670,10 @@ static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
669 if (!BANK_USED(bank)) 670 if (!BANK_USED(bank))
670 pm_runtime_get_sync(bank->dev); 671 pm_runtime_get_sync(bank->dev);
671 672
672 spin_lock_irqsave(&bank->lock, flags); 673 raw_spin_lock_irqsave(&bank->lock, flags);
673 omap_enable_gpio_module(bank, offset); 674 omap_enable_gpio_module(bank, offset);
674 bank->mod_usage |= BIT(offset); 675 bank->mod_usage |= BIT(offset);
675 spin_unlock_irqrestore(&bank->lock, flags); 676 raw_spin_unlock_irqrestore(&bank->lock, flags);
676 677
677 return 0; 678 return 0;
678} 679}
@@ -682,14 +683,14 @@ static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
682 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); 683 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
683 unsigned long flags; 684 unsigned long flags;
684 685
685 spin_lock_irqsave(&bank->lock, flags); 686 raw_spin_lock_irqsave(&bank->lock, flags);
686 bank->mod_usage &= ~(BIT(offset)); 687 bank->mod_usage &= ~(BIT(offset));
687 if (!LINE_USED(bank->irq_usage, offset)) { 688 if (!LINE_USED(bank->irq_usage, offset)) {
688 omap_set_gpio_direction(bank, offset, 1); 689 omap_set_gpio_direction(bank, offset, 1);
689 omap_clear_gpio_debounce(bank, offset); 690 omap_clear_gpio_debounce(bank, offset);
690 } 691 }
691 omap_disable_gpio_module(bank, offset); 692 omap_disable_gpio_module(bank, offset);
692 spin_unlock_irqrestore(&bank->lock, flags); 693 raw_spin_unlock_irqrestore(&bank->lock, flags);
693 694
694 /* 695 /*
695 * If this is the last gpio to be freed in the bank, 696 * If this is the last gpio to be freed in the bank,
@@ -716,7 +717,8 @@ static void omap_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
716 struct gpio_bank *bank; 717 struct gpio_bank *bank;
717 int unmasked = 0; 718 int unmasked = 0;
718 struct irq_chip *irqchip = irq_desc_get_chip(desc); 719 struct irq_chip *irqchip = irq_desc_get_chip(desc);
719 struct gpio_chip *chip = irq_get_handler_data(irq); 720 struct gpio_chip *chip = irq_desc_get_handler_data(desc);
721 unsigned long lock_flags;
720 722
721 chained_irq_enter(irqchip, desc); 723 chained_irq_enter(irqchip, desc);
722 724
@@ -731,6 +733,8 @@ static void omap_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
731 u32 isr_saved, level_mask = 0; 733 u32 isr_saved, level_mask = 0;
732 u32 enabled; 734 u32 enabled;
733 735
736 raw_spin_lock_irqsave(&bank->lock, lock_flags);
737
734 enabled = omap_get_gpio_irqbank_mask(bank); 738 enabled = omap_get_gpio_irqbank_mask(bank);
735 isr_saved = isr = readl_relaxed(isr_reg) & enabled; 739 isr_saved = isr = readl_relaxed(isr_reg) & enabled;
736 740
@@ -744,6 +748,8 @@ static void omap_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
744 omap_clear_gpio_irqbank(bank, isr_saved & ~level_mask); 748 omap_clear_gpio_irqbank(bank, isr_saved & ~level_mask);
745 omap_enable_gpio_irqbank(bank, isr_saved & ~level_mask); 749 omap_enable_gpio_irqbank(bank, isr_saved & ~level_mask);
746 750
751 raw_spin_unlock_irqrestore(&bank->lock, lock_flags);
752
747 /* if there is only edge sensitive GPIO pin interrupts 753 /* if there is only edge sensitive GPIO pin interrupts
748 configured, we could unmask GPIO bank interrupt immediately */ 754 configured, we could unmask GPIO bank interrupt immediately */
749 if (!level_mask && !unmasked) { 755 if (!level_mask && !unmasked) {
@@ -758,6 +764,7 @@ static void omap_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
758 bit = __ffs(isr); 764 bit = __ffs(isr);
759 isr &= ~(BIT(bit)); 765 isr &= ~(BIT(bit));
760 766
767 raw_spin_lock_irqsave(&bank->lock, lock_flags);
761 /* 768 /*
762 * Some chips can't respond to both rising and falling 769 * Some chips can't respond to both rising and falling
763 * at the same time. If this irq was requested with 770 * at the same time. If this irq was requested with
@@ -768,6 +775,8 @@ static void omap_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
768 if (bank->toggle_mask & (BIT(bit))) 775 if (bank->toggle_mask & (BIT(bit)))
769 omap_toggle_gpio_edge_triggering(bank, bit); 776 omap_toggle_gpio_edge_triggering(bank, bit);
770 777
778 raw_spin_unlock_irqrestore(&bank->lock, lock_flags);
779
771 generic_handle_irq(irq_find_mapping(bank->chip.irqdomain, 780 generic_handle_irq(irq_find_mapping(bank->chip.irqdomain,
772 bit)); 781 bit));
773 } 782 }
@@ -791,7 +800,7 @@ static unsigned int omap_gpio_irq_startup(struct irq_data *d)
791 if (!BANK_USED(bank)) 800 if (!BANK_USED(bank))
792 pm_runtime_get_sync(bank->dev); 801 pm_runtime_get_sync(bank->dev);
793 802
794 spin_lock_irqsave(&bank->lock, flags); 803 raw_spin_lock_irqsave(&bank->lock, flags);
795 804
796 if (!LINE_USED(bank->mod_usage, offset)) 805 if (!LINE_USED(bank->mod_usage, offset))
797 omap_set_gpio_direction(bank, offset, 1); 806 omap_set_gpio_direction(bank, offset, 1);
@@ -800,12 +809,12 @@ static unsigned int omap_gpio_irq_startup(struct irq_data *d)
800 omap_enable_gpio_module(bank, offset); 809 omap_enable_gpio_module(bank, offset);
801 bank->irq_usage |= BIT(offset); 810 bank->irq_usage |= BIT(offset);
802 811
803 spin_unlock_irqrestore(&bank->lock, flags); 812 raw_spin_unlock_irqrestore(&bank->lock, flags);
804 omap_gpio_unmask_irq(d); 813 omap_gpio_unmask_irq(d);
805 814
806 return 0; 815 return 0;
807err: 816err:
808 spin_unlock_irqrestore(&bank->lock, flags); 817 raw_spin_unlock_irqrestore(&bank->lock, flags);
809 if (!BANK_USED(bank)) 818 if (!BANK_USED(bank))
810 pm_runtime_put(bank->dev); 819 pm_runtime_put(bank->dev);
811 return -EINVAL; 820 return -EINVAL;
@@ -817,7 +826,7 @@ static void omap_gpio_irq_shutdown(struct irq_data *d)
817 unsigned long flags; 826 unsigned long flags;
818 unsigned offset = d->hwirq; 827 unsigned offset = d->hwirq;
819 828
820 spin_lock_irqsave(&bank->lock, flags); 829 raw_spin_lock_irqsave(&bank->lock, flags);
821 bank->irq_usage &= ~(BIT(offset)); 830 bank->irq_usage &= ~(BIT(offset));
822 omap_set_gpio_irqenable(bank, offset, 0); 831 omap_set_gpio_irqenable(bank, offset, 0);
823 omap_clear_gpio_irqstatus(bank, offset); 832 omap_clear_gpio_irqstatus(bank, offset);
@@ -825,7 +834,7 @@ static void omap_gpio_irq_shutdown(struct irq_data *d)
825 if (!LINE_USED(bank->mod_usage, offset)) 834 if (!LINE_USED(bank->mod_usage, offset))
826 omap_clear_gpio_debounce(bank, offset); 835 omap_clear_gpio_debounce(bank, offset);
827 omap_disable_gpio_module(bank, offset); 836 omap_disable_gpio_module(bank, offset);
828 spin_unlock_irqrestore(&bank->lock, flags); 837 raw_spin_unlock_irqrestore(&bank->lock, flags);
829 838
830 /* 839 /*
831 * If this is the last IRQ to be freed in the bank, 840 * If this is the last IRQ to be freed in the bank,
@@ -849,10 +858,10 @@ static void omap_gpio_mask_irq(struct irq_data *d)
849 unsigned offset = d->hwirq; 858 unsigned offset = d->hwirq;
850 unsigned long flags; 859 unsigned long flags;
851 860
852 spin_lock_irqsave(&bank->lock, flags); 861 raw_spin_lock_irqsave(&bank->lock, flags);
853 omap_set_gpio_irqenable(bank, offset, 0); 862 omap_set_gpio_irqenable(bank, offset, 0);
854 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); 863 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
855 spin_unlock_irqrestore(&bank->lock, flags); 864 raw_spin_unlock_irqrestore(&bank->lock, flags);
856} 865}
857 866
858static void omap_gpio_unmask_irq(struct irq_data *d) 867static void omap_gpio_unmask_irq(struct irq_data *d)
@@ -862,7 +871,7 @@ static void omap_gpio_unmask_irq(struct irq_data *d)
862 u32 trigger = irqd_get_trigger_type(d); 871 u32 trigger = irqd_get_trigger_type(d);
863 unsigned long flags; 872 unsigned long flags;
864 873
865 spin_lock_irqsave(&bank->lock, flags); 874 raw_spin_lock_irqsave(&bank->lock, flags);
866 if (trigger) 875 if (trigger)
867 omap_set_gpio_triggering(bank, offset, trigger); 876 omap_set_gpio_triggering(bank, offset, trigger);
868 877
@@ -874,7 +883,7 @@ static void omap_gpio_unmask_irq(struct irq_data *d)
874 } 883 }
875 884
876 omap_set_gpio_irqenable(bank, offset, 1); 885 omap_set_gpio_irqenable(bank, offset, 1);
877 spin_unlock_irqrestore(&bank->lock, flags); 886 raw_spin_unlock_irqrestore(&bank->lock, flags);
878} 887}
879 888
880/*---------------------------------------------------------------------*/ 889/*---------------------------------------------------------------------*/
@@ -887,9 +896,9 @@ static int omap_mpuio_suspend_noirq(struct device *dev)
887 OMAP_MPUIO_GPIO_MASKIT / bank->stride; 896 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
888 unsigned long flags; 897 unsigned long flags;
889 898
890 spin_lock_irqsave(&bank->lock, flags); 899 raw_spin_lock_irqsave(&bank->lock, flags);
891 writel_relaxed(0xffff & ~bank->context.wake_en, mask_reg); 900 writel_relaxed(0xffff & ~bank->context.wake_en, mask_reg);
892 spin_unlock_irqrestore(&bank->lock, flags); 901 raw_spin_unlock_irqrestore(&bank->lock, flags);
893 902
894 return 0; 903 return 0;
895} 904}
@@ -902,9 +911,9 @@ static int omap_mpuio_resume_noirq(struct device *dev)
902 OMAP_MPUIO_GPIO_MASKIT / bank->stride; 911 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
903 unsigned long flags; 912 unsigned long flags;
904 913
905 spin_lock_irqsave(&bank->lock, flags); 914 raw_spin_lock_irqsave(&bank->lock, flags);
906 writel_relaxed(bank->context.wake_en, mask_reg); 915 writel_relaxed(bank->context.wake_en, mask_reg);
907 spin_unlock_irqrestore(&bank->lock, flags); 916 raw_spin_unlock_irqrestore(&bank->lock, flags);
908 917
909 return 0; 918 return 0;
910} 919}
@@ -950,9 +959,9 @@ static int omap_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
950 959
951 bank = container_of(chip, struct gpio_bank, chip); 960 bank = container_of(chip, struct gpio_bank, chip);
952 reg = bank->base + bank->regs->direction; 961 reg = bank->base + bank->regs->direction;
953 spin_lock_irqsave(&bank->lock, flags); 962 raw_spin_lock_irqsave(&bank->lock, flags);
954 dir = !!(readl_relaxed(reg) & BIT(offset)); 963 dir = !!(readl_relaxed(reg) & BIT(offset));
955 spin_unlock_irqrestore(&bank->lock, flags); 964 raw_spin_unlock_irqrestore(&bank->lock, flags);
956 return dir; 965 return dir;
957} 966}
958 967
@@ -962,9 +971,9 @@ static int omap_gpio_input(struct gpio_chip *chip, unsigned offset)
962 unsigned long flags; 971 unsigned long flags;
963 972
964 bank = container_of(chip, struct gpio_bank, chip); 973 bank = container_of(chip, struct gpio_bank, chip);
965 spin_lock_irqsave(&bank->lock, flags); 974 raw_spin_lock_irqsave(&bank->lock, flags);
966 omap_set_gpio_direction(bank, offset, 1); 975 omap_set_gpio_direction(bank, offset, 1);
967 spin_unlock_irqrestore(&bank->lock, flags); 976 raw_spin_unlock_irqrestore(&bank->lock, flags);
968 return 0; 977 return 0;
969} 978}
970 979
@@ -986,10 +995,10 @@ static int omap_gpio_output(struct gpio_chip *chip, unsigned offset, int value)
986 unsigned long flags; 995 unsigned long flags;
987 996
988 bank = container_of(chip, struct gpio_bank, chip); 997 bank = container_of(chip, struct gpio_bank, chip);
989 spin_lock_irqsave(&bank->lock, flags); 998 raw_spin_lock_irqsave(&bank->lock, flags);
990 bank->set_dataout(bank, offset, value); 999 bank->set_dataout(bank, offset, value);
991 omap_set_gpio_direction(bank, offset, 0); 1000 omap_set_gpio_direction(bank, offset, 0);
992 spin_unlock_irqrestore(&bank->lock, flags); 1001 raw_spin_unlock_irqrestore(&bank->lock, flags);
993 return 0; 1002 return 0;
994} 1003}
995 1004
@@ -1001,9 +1010,9 @@ static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset,
1001 1010
1002 bank = container_of(chip, struct gpio_bank, chip); 1011 bank = container_of(chip, struct gpio_bank, chip);
1003 1012
1004 spin_lock_irqsave(&bank->lock, flags); 1013 raw_spin_lock_irqsave(&bank->lock, flags);
1005 omap2_set_gpio_debounce(bank, offset, debounce); 1014 omap2_set_gpio_debounce(bank, offset, debounce);
1006 spin_unlock_irqrestore(&bank->lock, flags); 1015 raw_spin_unlock_irqrestore(&bank->lock, flags);
1007 1016
1008 return 0; 1017 return 0;
1009} 1018}
@@ -1014,9 +1023,9 @@ static void omap_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1014 unsigned long flags; 1023 unsigned long flags;
1015 1024
1016 bank = container_of(chip, struct gpio_bank, chip); 1025 bank = container_of(chip, struct gpio_bank, chip);
1017 spin_lock_irqsave(&bank->lock, flags); 1026 raw_spin_lock_irqsave(&bank->lock, flags);
1018 bank->set_dataout(bank, offset, value); 1027 bank->set_dataout(bank, offset, value);
1019 spin_unlock_irqrestore(&bank->lock, flags); 1028 raw_spin_unlock_irqrestore(&bank->lock, flags);
1020} 1029}
1021 1030
1022/*---------------------------------------------------------------------*/ 1031/*---------------------------------------------------------------------*/
@@ -1061,10 +1070,6 @@ static void omap_gpio_mod_init(struct gpio_bank *bank)
1061 /* Initialize interface clk ungated, module enabled */ 1070 /* Initialize interface clk ungated, module enabled */
1062 if (bank->regs->ctrl) 1071 if (bank->regs->ctrl)
1063 writel_relaxed(0, base + bank->regs->ctrl); 1072 writel_relaxed(0, base + bank->regs->ctrl);
1064
1065 bank->dbck = clk_get(bank->dev, "dbclk");
1066 if (IS_ERR(bank->dbck))
1067 dev_err(bank->dev, "Could not get gpio dbck\n");
1068} 1073}
1069 1074
1070static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc) 1075static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
@@ -1178,13 +1183,16 @@ static int omap_gpio_probe(struct platform_device *pdev)
1178 irqc->irq_set_wake = omap_gpio_wake_enable, 1183 irqc->irq_set_wake = omap_gpio_wake_enable,
1179 irqc->name = dev_name(&pdev->dev); 1184 irqc->name = dev_name(&pdev->dev);
1180 1185
1181 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1186 bank->irq = platform_get_irq(pdev, 0);
1182 if (unlikely(!res)) { 1187 if (bank->irq <= 0) {
1183 dev_err(dev, "Invalid IRQ resource\n"); 1188 if (!bank->irq)
1184 return -ENODEV; 1189 bank->irq = -ENXIO;
1190 if (bank->irq != -EPROBE_DEFER)
1191 dev_err(dev,
1192 "can't get irq resource ret=%d\n", bank->irq);
1193 return bank->irq;
1185 } 1194 }
1186 1195
1187 bank->irq = res->start;
1188 bank->dev = dev; 1196 bank->dev = dev;
1189 bank->chip.dev = dev; 1197 bank->chip.dev = dev;
1190 bank->chip.owner = THIS_MODULE; 1198 bank->chip.owner = THIS_MODULE;
@@ -1213,16 +1221,26 @@ static int omap_gpio_probe(struct platform_device *pdev)
1213 else 1221 else
1214 bank->set_dataout = omap_set_gpio_dataout_mask; 1222 bank->set_dataout = omap_set_gpio_dataout_mask;
1215 1223
1216 spin_lock_init(&bank->lock); 1224 raw_spin_lock_init(&bank->lock);
1217 1225
1218 /* Static mapping, never released */ 1226 /* Static mapping, never released */
1219 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1227 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1220 bank->base = devm_ioremap_resource(dev, res); 1228 bank->base = devm_ioremap_resource(dev, res);
1221 if (IS_ERR(bank->base)) { 1229 if (IS_ERR(bank->base)) {
1222 irq_domain_remove(bank->chip.irqdomain);
1223 return PTR_ERR(bank->base); 1230 return PTR_ERR(bank->base);
1224 } 1231 }
1225 1232
1233 if (bank->dbck_flag) {
1234 bank->dbck = devm_clk_get(bank->dev, "dbclk");
1235 if (IS_ERR(bank->dbck)) {
1236 dev_err(bank->dev,
1237 "Could not get gpio dbck. Disable debounce\n");
1238 bank->dbck_flag = false;
1239 } else {
1240 clk_prepare(bank->dbck);
1241 }
1242 }
1243
1226 platform_set_drvdata(pdev, bank); 1244 platform_set_drvdata(pdev, bank);
1227 1245
1228 pm_runtime_enable(bank->dev); 1246 pm_runtime_enable(bank->dev);
@@ -1254,6 +1272,8 @@ static int omap_gpio_remove(struct platform_device *pdev)
1254 list_del(&bank->node); 1272 list_del(&bank->node);
1255 gpiochip_remove(&bank->chip); 1273 gpiochip_remove(&bank->chip);
1256 pm_runtime_disable(bank->dev); 1274 pm_runtime_disable(bank->dev);
1275 if (bank->dbck_flag)
1276 clk_unprepare(bank->dbck);
1257 1277
1258 return 0; 1278 return 0;
1259} 1279}
@@ -1271,7 +1291,7 @@ static int omap_gpio_runtime_suspend(struct device *dev)
1271 unsigned long flags; 1291 unsigned long flags;
1272 u32 wake_low, wake_hi; 1292 u32 wake_low, wake_hi;
1273 1293
1274 spin_lock_irqsave(&bank->lock, flags); 1294 raw_spin_lock_irqsave(&bank->lock, flags);
1275 1295
1276 /* 1296 /*
1277 * Only edges can generate a wakeup event to the PRCM. 1297 * Only edges can generate a wakeup event to the PRCM.
@@ -1324,7 +1344,7 @@ update_gpio_context_count:
1324 bank->get_context_loss_count(bank->dev); 1344 bank->get_context_loss_count(bank->dev);
1325 1345
1326 omap_gpio_dbck_disable(bank); 1346 omap_gpio_dbck_disable(bank);
1327 spin_unlock_irqrestore(&bank->lock, flags); 1347 raw_spin_unlock_irqrestore(&bank->lock, flags);
1328 1348
1329 return 0; 1349 return 0;
1330} 1350}
@@ -1339,7 +1359,7 @@ static int omap_gpio_runtime_resume(struct device *dev)
1339 unsigned long flags; 1359 unsigned long flags;
1340 int c; 1360 int c;
1341 1361
1342 spin_lock_irqsave(&bank->lock, flags); 1362 raw_spin_lock_irqsave(&bank->lock, flags);
1343 1363
1344 /* 1364 /*
1345 * On the first resume during the probe, the context has not 1365 * On the first resume during the probe, the context has not
@@ -1375,14 +1395,14 @@ static int omap_gpio_runtime_resume(struct device *dev)
1375 if (c != bank->context_loss_count) { 1395 if (c != bank->context_loss_count) {
1376 omap_gpio_restore_context(bank); 1396 omap_gpio_restore_context(bank);
1377 } else { 1397 } else {
1378 spin_unlock_irqrestore(&bank->lock, flags); 1398 raw_spin_unlock_irqrestore(&bank->lock, flags);
1379 return 0; 1399 return 0;
1380 } 1400 }
1381 } 1401 }
1382 } 1402 }
1383 1403
1384 if (!bank->workaround_enabled) { 1404 if (!bank->workaround_enabled) {
1385 spin_unlock_irqrestore(&bank->lock, flags); 1405 raw_spin_unlock_irqrestore(&bank->lock, flags);
1386 return 0; 1406 return 0;
1387 } 1407 }
1388 1408
@@ -1437,7 +1457,7 @@ static int omap_gpio_runtime_resume(struct device *dev)
1437 } 1457 }
1438 1458
1439 bank->workaround_enabled = false; 1459 bank->workaround_enabled = false;
1440 spin_unlock_irqrestore(&bank->lock, flags); 1460 raw_spin_unlock_irqrestore(&bank->lock, flags);
1441 1461
1442 return 0; 1462 return 0;
1443} 1463}
diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c
index 404f3c61ef9b..1d4d9bc8b69d 100644
--- a/drivers/gpio/gpio-pcf857x.c
+++ b/drivers/gpio/gpio-pcf857x.c
@@ -88,7 +88,6 @@ struct pcf857x {
88 struct gpio_chip chip; 88 struct gpio_chip chip;
89 struct i2c_client *client; 89 struct i2c_client *client;
90 struct mutex lock; /* protect 'out' */ 90 struct mutex lock; /* protect 'out' */
91 spinlock_t slock; /* protect irq demux */
92 unsigned out; /* software latch */ 91 unsigned out; /* software latch */
93 unsigned status; /* current status */ 92 unsigned status; /* current status */
94 unsigned int irq_parent; 93 unsigned int irq_parent;
@@ -185,23 +184,21 @@ static void pcf857x_set(struct gpio_chip *chip, unsigned offset, int value)
185static irqreturn_t pcf857x_irq(int irq, void *data) 184static irqreturn_t pcf857x_irq(int irq, void *data)
186{ 185{
187 struct pcf857x *gpio = data; 186 struct pcf857x *gpio = data;
188 unsigned long change, i, status, flags; 187 unsigned long change, i, status;
189 188
190 status = gpio->read(gpio->client); 189 status = gpio->read(gpio->client);
191 190
192 spin_lock_irqsave(&gpio->slock, flags);
193
194 /* 191 /*
195 * call the interrupt handler iff gpio is used as 192 * call the interrupt handler iff gpio is used as
196 * interrupt source, just to avoid bad irqs 193 * interrupt source, just to avoid bad irqs
197 */ 194 */
198 195 mutex_lock(&gpio->lock);
199 change = (gpio->status ^ status) & gpio->irq_enabled; 196 change = (gpio->status ^ status) & gpio->irq_enabled;
200 for_each_set_bit(i, &change, gpio->chip.ngpio)
201 handle_nested_irq(irq_find_mapping(gpio->chip.irqdomain, i));
202 gpio->status = status; 197 gpio->status = status;
198 mutex_unlock(&gpio->lock);
203 199
204 spin_unlock_irqrestore(&gpio->slock, flags); 200 for_each_set_bit(i, &change, gpio->chip.ngpio)
201 handle_nested_irq(irq_find_mapping(gpio->chip.irqdomain, i));
205 202
206 return IRQ_HANDLED; 203 return IRQ_HANDLED;
207} 204}
@@ -293,7 +290,6 @@ static int pcf857x_probe(struct i2c_client *client,
293 return -ENOMEM; 290 return -ENOMEM;
294 291
295 mutex_init(&gpio->lock); 292 mutex_init(&gpio->lock);
296 spin_lock_init(&gpio->slock);
297 293
298 gpio->chip.base = pdata ? pdata->gpio_base : -1; 294 gpio->chip.base = pdata ? pdata->gpio_base : -1;
299 gpio->chip.can_sleep = true; 295 gpio->chip.can_sleep = true;
diff --git a/drivers/gpio/gpio-pch.c b/drivers/gpio/gpio-pch.c
index 2d9a950ca2d4..34ed176df15a 100644
--- a/drivers/gpio/gpio-pch.c
+++ b/drivers/gpio/gpio-pch.c
@@ -281,9 +281,9 @@ static int pch_irq_type(struct irq_data *d, unsigned int type)
281 281
282 /* And the handler */ 282 /* And the handler */
283 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) 283 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
284 __irq_set_handler_locked(d->irq, handle_level_irq); 284 irq_set_handler_locked(d, handle_level_irq);
285 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) 285 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
286 __irq_set_handler_locked(d->irq, handle_edge_irq); 286 irq_set_handler_locked(d, handle_edge_irq);
287 287
288unlock: 288unlock:
289 spin_unlock_irqrestore(&chip->spinlock, flags); 289 spin_unlock_irqrestore(&chip->spinlock, flags);
diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index cdbbcf0faf9d..55a11de3d5b7 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -524,7 +524,7 @@ static int pxa_irq_domain_map(struct irq_domain *d, unsigned int irq,
524{ 524{
525 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 525 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip,
526 handle_edge_irq); 526 handle_edge_irq);
527 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); 527 irq_set_noprobe(irq);
528 return 0; 528 return 0;
529} 529}
530 530
@@ -643,20 +643,20 @@ static int pxa_gpio_probe(struct platform_device *pdev)
643 irq = gpio_to_irq(0); 643 irq = gpio_to_irq(0);
644 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 644 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip,
645 handle_edge_irq); 645 handle_edge_irq);
646 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); 646 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
647 } 647 }
648 if (irq1 > 0) { 648 if (irq1 > 0) {
649 irq = gpio_to_irq(1); 649 irq = gpio_to_irq(1);
650 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 650 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip,
651 handle_edge_irq); 651 handle_edge_irq);
652 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); 652 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
653 } 653 }
654 654
655 for (irq = gpio_to_irq(gpio_offset); 655 for (irq = gpio_to_irq(gpio_offset);
656 irq <= gpio_to_irq(pxa_last_gpio); irq++) { 656 irq <= gpio_to_irq(pxa_last_gpio); irq++) {
657 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 657 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip,
658 handle_edge_irq); 658 handle_edge_irq);
659 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); 659 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
660 } 660 }
661 } 661 }
662 662
diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
index 1e14a6c74ed1..2a8122444614 100644
--- a/drivers/gpio/gpio-rcar.c
+++ b/drivers/gpio/gpio-rcar.c
@@ -251,17 +251,32 @@ static void gpio_rcar_config_general_input_output_mode(struct gpio_chip *chip,
251 251
252static int gpio_rcar_request(struct gpio_chip *chip, unsigned offset) 252static int gpio_rcar_request(struct gpio_chip *chip, unsigned offset)
253{ 253{
254 return pinctrl_request_gpio(chip->base + offset); 254 struct gpio_rcar_priv *p = gpio_to_priv(chip);
255 int error;
256
257 error = pm_runtime_get_sync(&p->pdev->dev);
258 if (error < 0)
259 return error;
260
261 error = pinctrl_request_gpio(chip->base + offset);
262 if (error)
263 pm_runtime_put(&p->pdev->dev);
264
265 return error;
255} 266}
256 267
257static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset) 268static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset)
258{ 269{
270 struct gpio_rcar_priv *p = gpio_to_priv(chip);
271
259 pinctrl_free_gpio(chip->base + offset); 272 pinctrl_free_gpio(chip->base + offset);
260 273
261 /* Set the GPIO as an input to ensure that the next GPIO request won't 274 /* Set the GPIO as an input to ensure that the next GPIO request won't
262 * drive the GPIO pin as an output. 275 * drive the GPIO pin as an output.
263 */ 276 */
264 gpio_rcar_config_general_input_output_mode(chip, offset, false); 277 gpio_rcar_config_general_input_output_mode(chip, offset, false);
278
279 pm_runtime_put(&p->pdev->dev);
265} 280}
266 281
267static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset) 282static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset)
@@ -327,6 +342,10 @@ static const struct of_device_id gpio_rcar_of_table[] = {
327 .compatible = "renesas,gpio-r8a7794", 342 .compatible = "renesas,gpio-r8a7794",
328 .data = &gpio_rcar_info_gen2, 343 .data = &gpio_rcar_info_gen2,
329 }, { 344 }, {
345 .compatible = "renesas,gpio-r8a7795",
346 /* Gen3 GPIO is identical to Gen2. */
347 .data = &gpio_rcar_info_gen2,
348 }, {
330 .compatible = "renesas,gpio-rcar", 349 .compatible = "renesas,gpio-rcar",
331 .data = &gpio_rcar_info_gen1, 350 .data = &gpio_rcar_info_gen1,
332 }, { 351 }, {
@@ -405,7 +424,6 @@ static int gpio_rcar_probe(struct platform_device *pdev)
405 } 424 }
406 425
407 pm_runtime_enable(dev); 426 pm_runtime_enable(dev);
408 pm_runtime_get_sync(dev);
409 427
410 io = platform_get_resource(pdev, IORESOURCE_MEM, 0); 428 io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
411 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 429 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -487,7 +505,6 @@ static int gpio_rcar_probe(struct platform_device *pdev)
487err1: 505err1:
488 gpiochip_remove(gpio_chip); 506 gpiochip_remove(gpio_chip);
489err0: 507err0:
490 pm_runtime_put(dev);
491 pm_runtime_disable(dev); 508 pm_runtime_disable(dev);
492 return ret; 509 return ret;
493} 510}
@@ -498,7 +515,6 @@ static int gpio_rcar_remove(struct platform_device *pdev)
498 515
499 gpiochip_remove(&p->gpio_chip); 516 gpiochip_remove(&p->gpio_chip);
500 517
501 pm_runtime_put(&pdev->dev);
502 pm_runtime_disable(&pdev->dev); 518 pm_runtime_disable(&pdev->dev);
503 return 0; 519 return 0;
504} 520}
diff --git a/drivers/gpio/gpio-sa1100.c b/drivers/gpio/gpio-sa1100.c
index 3fa22dade243..67bd2f5d89e8 100644
--- a/drivers/gpio/gpio-sa1100.c
+++ b/drivers/gpio/gpio-sa1100.c
@@ -155,7 +155,7 @@ static int sa1100_gpio_irqdomain_map(struct irq_domain *d,
155{ 155{
156 irq_set_chip_and_handler(irq, &sa1100_gpio_irq_chip, 156 irq_set_chip_and_handler(irq, &sa1100_gpio_irq_chip,
157 handle_edge_irq); 157 handle_edge_irq);
158 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); 158 irq_set_noprobe(irq);
159 159
160 return 0; 160 return 0;
161} 161}
@@ -173,9 +173,9 @@ static struct irq_domain *sa1100_gpio_irqdomain;
173 * and call the handler. 173 * and call the handler.
174 */ 174 */
175static void 175static void
176sa1100_gpio_handler(unsigned int irq, struct irq_desc *desc) 176sa1100_gpio_handler(unsigned int __irq, struct irq_desc *desc)
177{ 177{
178 unsigned int mask; 178 unsigned int irq, mask;
179 179
180 mask = GEDR; 180 mask = GEDR;
181 do { 181 do {
diff --git a/drivers/gpio/gpio-sta2x11.c b/drivers/gpio/gpio-sta2x11.c
index 18579ac65b2b..55e47828ddfc 100644
--- a/drivers/gpio/gpio-sta2x11.c
+++ b/drivers/gpio/gpio-sta2x11.c
@@ -346,7 +346,7 @@ static void gsta_alloc_irq_chip(struct gsta_gpio *chip)
346 i = chip->irq_base + j; 346 i = chip->irq_base + j;
347 irq_set_chip_and_handler(i, &ct->chip, ct->handler); 347 irq_set_chip_and_handler(i, &ct->chip, ct->handler);
348 irq_set_chip_data(i, gc); 348 irq_set_chip_data(i, gc);
349 irq_modify_status(i, IRQ_NOREQUEST | IRQ_NOPROBE, 0); 349 irq_clear_status_flags(i, IRQ_NOREQUEST | IRQ_NOPROBE);
350 } 350 }
351 gc->irq_cnt = i - gc->irq_base; 351 gc->irq_cnt = i - gc->irq_base;
352 } 352 }
diff --git a/drivers/gpio/gpio-tc3589x.c b/drivers/gpio/gpio-tc3589x.c
index 31b244cffabb..d1d585ddb9ab 100644
--- a/drivers/gpio/gpio-tc3589x.c
+++ b/drivers/gpio/gpio-tc3589x.c
@@ -102,7 +102,7 @@ static struct gpio_chip template_chip = {
102static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type) 102static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type)
103{ 103{
104 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 104 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
105 struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip); 105 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(gc);
106 int offset = d->hwirq; 106 int offset = d->hwirq;
107 int regoffset = offset / 8; 107 int regoffset = offset / 8;
108 int mask = 1 << (offset % 8); 108 int mask = 1 << (offset % 8);
@@ -130,7 +130,7 @@ static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type)
130static void tc3589x_gpio_irq_lock(struct irq_data *d) 130static void tc3589x_gpio_irq_lock(struct irq_data *d)
131{ 131{
132 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 132 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
133 struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip); 133 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(gc);
134 134
135 mutex_lock(&tc3589x_gpio->irq_lock); 135 mutex_lock(&tc3589x_gpio->irq_lock);
136} 136}
@@ -138,7 +138,7 @@ static void tc3589x_gpio_irq_lock(struct irq_data *d)
138static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d) 138static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d)
139{ 139{
140 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 140 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
141 struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip); 141 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(gc);
142 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 142 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
143 static const u8 regmap[] = { 143 static const u8 regmap[] = {
144 [REG_IBE] = TC3589x_GPIOIBE0, 144 [REG_IBE] = TC3589x_GPIOIBE0,
@@ -167,7 +167,7 @@ static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d)
167static void tc3589x_gpio_irq_mask(struct irq_data *d) 167static void tc3589x_gpio_irq_mask(struct irq_data *d)
168{ 168{
169 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 169 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
170 struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip); 170 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(gc);
171 int offset = d->hwirq; 171 int offset = d->hwirq;
172 int regoffset = offset / 8; 172 int regoffset = offset / 8;
173 int mask = 1 << (offset % 8); 173 int mask = 1 << (offset % 8);
@@ -178,7 +178,7 @@ static void tc3589x_gpio_irq_mask(struct irq_data *d)
178static void tc3589x_gpio_irq_unmask(struct irq_data *d) 178static void tc3589x_gpio_irq_unmask(struct irq_data *d)
179{ 179{
180 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 180 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
181 struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip); 181 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(gc);
182 int offset = d->hwirq; 182 int offset = d->hwirq;
183 int regoffset = offset / 8; 183 int regoffset = offset / 8;
184 int mask = 1 << (offset % 8); 184 int mask = 1 << (offset % 8);
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 9b25c90f725c..9b14aafb576d 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -252,9 +252,9 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
252 tegra_gpio_enable(gpio); 252 tegra_gpio_enable(gpio);
253 253
254 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) 254 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
255 __irq_set_handler_locked(d->irq, handle_level_irq); 255 irq_set_handler_locked(d, handle_level_irq);
256 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) 256 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
257 __irq_set_handler_locked(d->irq, handle_edge_irq); 257 irq_set_handler_locked(d, handle_edge_irq);
258 258
259 return 0; 259 return 0;
260} 260}
@@ -268,16 +268,14 @@ static void tegra_gpio_irq_shutdown(struct irq_data *d)
268 268
269static void tegra_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) 269static void tegra_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
270{ 270{
271 struct tegra_gpio_bank *bank;
272 int port; 271 int port;
273 int pin; 272 int pin;
274 int unmasked = 0; 273 int unmasked = 0;
275 struct irq_chip *chip = irq_desc_get_chip(desc); 274 struct irq_chip *chip = irq_desc_get_chip(desc);
275 struct tegra_gpio_bank *bank = irq_desc_get_handler_data(desc);
276 276
277 chained_irq_enter(chip, desc); 277 chained_irq_enter(chip, desc);
278 278
279 bank = irq_get_handler_data(irq);
280
281 for (port = 0; port < 4; port++) { 279 for (port = 0; port < 4; port++) {
282 int gpio = tegra_gpio_compose(bank->bank, port, 0); 280 int gpio = tegra_gpio_compose(bank->bank, port, 0);
283 unsigned long sta = tegra_gpio_readl(GPIO_INT_STA(gpio)) & 281 unsigned long sta = tegra_gpio_readl(GPIO_INT_STA(gpio)) &
@@ -509,7 +507,6 @@ static int tegra_gpio_probe(struct platform_device *pdev)
509 irq_set_chip_data(irq, bank); 507 irq_set_chip_data(irq, bank);
510 irq_set_chip_and_handler(irq, &tegra_gpio_irq_chip, 508 irq_set_chip_and_handler(irq, &tegra_gpio_irq_chip,
511 handle_simple_irq); 509 handle_simple_irq);
512 set_irq_flags(irq, IRQF_VALID);
513 } 510 }
514 511
515 for (i = 0; i < tegra_gpio_bank_count; i++) { 512 for (i = 0; i < tegra_gpio_bank_count; i++) {
diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdale.c
index e8f97e03c9bb..5a492054589f 100644
--- a/drivers/gpio/gpio-timberdale.c
+++ b/drivers/gpio/gpio-timberdale.c
@@ -194,11 +194,12 @@ out:
194 194
195static void timbgpio_irq(unsigned int irq, struct irq_desc *desc) 195static void timbgpio_irq(unsigned int irq, struct irq_desc *desc)
196{ 196{
197 struct timbgpio *tgpio = irq_get_handler_data(irq); 197 struct timbgpio *tgpio = irq_desc_get_handler_data(desc);
198 struct irq_data *data = irq_desc_get_irq_data(desc);
198 unsigned long ipr; 199 unsigned long ipr;
199 int offset; 200 int offset;
200 201
201 desc->irq_data.chip->irq_ack(irq_get_irq_data(irq)); 202 data->chip->irq_ack(data);
202 ipr = ioread32(tgpio->membase + TGPIO_IPR); 203 ipr = ioread32(tgpio->membase + TGPIO_IPR);
203 iowrite32(ipr, tgpio->membase + TGPIO_ICR); 204 iowrite32(ipr, tgpio->membase + TGPIO_ICR);
204 205
@@ -294,13 +295,10 @@ static int timbgpio_probe(struct platform_device *pdev)
294 irq_set_chip_and_handler(tgpio->irq_base + i, 295 irq_set_chip_and_handler(tgpio->irq_base + i,
295 &timbgpio_irqchip, handle_simple_irq); 296 &timbgpio_irqchip, handle_simple_irq);
296 irq_set_chip_data(tgpio->irq_base + i, tgpio); 297 irq_set_chip_data(tgpio->irq_base + i, tgpio);
297#ifdef CONFIG_ARM 298 irq_clear_status_flags(tgpio->irq_base + i, IRQ_NOREQUEST | IRQ_NOPROBE);
298 set_irq_flags(tgpio->irq_base + i, IRQF_VALID | IRQF_PROBE);
299#endif
300 } 299 }
301 300
302 irq_set_handler_data(irq, tgpio); 301 irq_set_chained_handler_and_data(irq, timbgpio_irq, tgpio);
303 irq_set_chained_handler(irq, timbgpio_irq);
304 302
305 return 0; 303 return 0;
306} 304}
diff --git a/drivers/gpio/gpio-tz1090.c b/drivers/gpio/gpio-tz1090.c
index 445660adc898..bbac92ae4c32 100644
--- a/drivers/gpio/gpio-tz1090.c
+++ b/drivers/gpio/gpio-tz1090.c
@@ -510,8 +510,8 @@ static int tz1090_gpio_bank_probe(struct tz1090_gpio_bank_info *info)
510 gc->chip_types[1].chip.flags = IRQCHIP_MASK_ON_SUSPEND; 510 gc->chip_types[1].chip.flags = IRQCHIP_MASK_ON_SUSPEND;
511 511
512 /* Setup chained handler for this GPIO bank */ 512 /* Setup chained handler for this GPIO bank */
513 irq_set_handler_data(bank->irq, bank); 513 irq_set_chained_handler_and_data(bank->irq, tz1090_gpio_irq_handler,
514 irq_set_chained_handler(bank->irq, tz1090_gpio_irq_handler); 514 bank);
515 515
516 return 0; 516 return 0;
517} 517}
diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 7bd9f209ffa8..3d5714d4f405 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -60,6 +60,8 @@ struct vf610_gpio_port {
60#define PORT_INT_EITHER_EDGE 0xb 60#define PORT_INT_EITHER_EDGE 0xb
61#define PORT_INT_LOGIC_ONE 0xc 61#define PORT_INT_LOGIC_ONE 0xc
62 62
63static struct irq_chip vf610_gpio_irq_chip;
64
63static const struct of_device_id vf610_gpio_dt_ids[] = { 65static const struct of_device_id vf610_gpio_dt_ids[] = {
64 { .compatible = "fsl,vf610-gpio" }, 66 { .compatible = "fsl,vf610-gpio" },
65 { /* sentinel */ } 67 { /* sentinel */ }
@@ -120,7 +122,7 @@ static int vf610_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
120 122
121static void vf610_gpio_irq_handler(u32 irq, struct irq_desc *desc) 123static void vf610_gpio_irq_handler(u32 irq, struct irq_desc *desc)
122{ 124{
123 struct vf610_gpio_port *port = irq_get_handler_data(irq); 125 struct vf610_gpio_port *port = irq_desc_get_handler_data(desc);
124 struct irq_chip *chip = irq_desc_get_chip(desc); 126 struct irq_chip *chip = irq_desc_get_chip(desc);
125 int pin; 127 int pin;
126 unsigned long irq_isfr; 128 unsigned long irq_isfr;
@@ -173,6 +175,11 @@ static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type)
173 175
174 port->irqc[d->hwirq] = irqc; 176 port->irqc[d->hwirq] = irqc;
175 177
178 if (type & IRQ_TYPE_LEVEL_MASK)
179 __irq_set_handler_locked(d->irq, handle_level_irq);
180 else
181 __irq_set_handler_locked(d->irq, handle_edge_irq);
182
176 return 0; 183 return 0;
177} 184}
178 185
@@ -263,7 +270,7 @@ static int vf610_gpio_probe(struct platform_device *pdev)
263 vf610_gpio_writel(~0, port->base + PORT_ISFR); 270 vf610_gpio_writel(~0, port->base + PORT_ISFR);
264 271
265 ret = gpiochip_irqchip_add(gc, &vf610_gpio_irq_chip, 0, 272 ret = gpiochip_irqchip_add(gc, &vf610_gpio_irq_chip, 0,
266 handle_simple_irq, IRQ_TYPE_NONE); 273 handle_edge_irq, IRQ_TYPE_NONE);
267 if (ret) { 274 if (ret) {
268 dev_err(dev, "failed to add irqchip\n"); 275 dev_err(dev, "failed to add irqchip\n");
269 gpiochip_remove(gc); 276 gpiochip_remove(gc);
diff --git a/drivers/gpio/gpio-xlp.c b/drivers/gpio/gpio-xlp.c
index 9bdab7203d65..e02499a15e72 100644
--- a/drivers/gpio/gpio-xlp.c
+++ b/drivers/gpio/gpio-xlp.c
@@ -387,7 +387,7 @@ static int xlp_gpio_probe(struct platform_device *pdev)
387 irq_base = irq_alloc_descs(-1, XLP_GPIO_IRQ_BASE, gc->ngpio, 0); 387 irq_base = irq_alloc_descs(-1, XLP_GPIO_IRQ_BASE, gc->ngpio, 0);
388 if (irq_base < 0) { 388 if (irq_base < 0) {
389 dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n"); 389 dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n");
390 return err; 390 return -ENODEV;
391 } 391 }
392 392
393 err = gpiochip_add(gc); 393 err = gpiochip_add(gc);
diff --git a/drivers/gpio/gpio-zx.c b/drivers/gpio/gpio-zx.c
new file mode 100644
index 000000000000..12ee1969298c
--- /dev/null
+++ b/drivers/gpio/gpio-zx.c
@@ -0,0 +1,324 @@
1/*
2 * Copyright (C) 2015 Linaro Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8#include <linux/bitops.h>
9#include <linux/device.h>
10#include <linux/errno.h>
11#include <linux/gpio/driver.h>
12#include <linux/irqchip/chained_irq.h>
13#include <linux/module.h>
14#include <linux/of.h>
15#include <linux/pinctrl/consumer.h>
16#include <linux/platform_device.h>
17#include <linux/pm.h>
18#include <linux/slab.h>
19#include <linux/spinlock.h>
20
21#define ZX_GPIO_DIR 0x00
22#define ZX_GPIO_IVE 0x04
23#define ZX_GPIO_IV 0x08
24#define ZX_GPIO_IEP 0x0C
25#define ZX_GPIO_IEN 0x10
26#define ZX_GPIO_DI 0x14
27#define ZX_GPIO_DO1 0x18
28#define ZX_GPIO_DO0 0x1C
29#define ZX_GPIO_DO 0x20
30
31#define ZX_GPIO_IM 0x28
32#define ZX_GPIO_IE 0x2C
33
34#define ZX_GPIO_MIS 0x30
35#define ZX_GPIO_IC 0x34
36
37#define ZX_GPIO_NR 16
38
39struct zx_gpio {
40 spinlock_t lock;
41
42 void __iomem *base;
43 struct gpio_chip gc;
44 bool uses_pinctrl;
45};
46
47static inline struct zx_gpio *to_zx(struct gpio_chip *gc)
48{
49 return container_of(gc, struct zx_gpio, gc);
50}
51
52static int zx_gpio_request(struct gpio_chip *gc, unsigned offset)
53{
54 struct zx_gpio *chip = to_zx(gc);
55 int gpio = gc->base + offset;
56
57 if (chip->uses_pinctrl)
58 return pinctrl_request_gpio(gpio);
59 return 0;
60}
61
62static void zx_gpio_free(struct gpio_chip *gc, unsigned offset)
63{
64 struct zx_gpio *chip = to_zx(gc);
65 int gpio = gc->base + offset;
66
67 if (chip->uses_pinctrl)
68 pinctrl_free_gpio(gpio);
69}
70
71static int zx_direction_input(struct gpio_chip *gc, unsigned offset)
72{
73 struct zx_gpio *chip = to_zx(gc);
74 unsigned long flags;
75 u16 gpiodir;
76
77 if (offset >= gc->ngpio)
78 return -EINVAL;
79
80 spin_lock_irqsave(&chip->lock, flags);
81 gpiodir = readw_relaxed(chip->base + ZX_GPIO_DIR);
82 gpiodir &= ~BIT(offset);
83 writew_relaxed(gpiodir, chip->base + ZX_GPIO_DIR);
84 spin_unlock_irqrestore(&chip->lock, flags);
85
86 return 0;
87}
88
89static int zx_direction_output(struct gpio_chip *gc, unsigned offset,
90 int value)
91{
92 struct zx_gpio *chip = to_zx(gc);
93 unsigned long flags;
94 u16 gpiodir;
95
96 if (offset >= gc->ngpio)
97 return -EINVAL;
98
99 spin_lock_irqsave(&chip->lock, flags);
100 gpiodir = readw_relaxed(chip->base + ZX_GPIO_DIR);
101 gpiodir |= BIT(offset);
102 writew_relaxed(gpiodir, chip->base + ZX_GPIO_DIR);
103
104 if (value)
105 writew_relaxed(BIT(offset), chip->base + ZX_GPIO_DO1);
106 else
107 writew_relaxed(BIT(offset), chip->base + ZX_GPIO_DO0);
108 spin_unlock_irqrestore(&chip->lock, flags);
109
110 return 0;
111}
112
113static int zx_get_value(struct gpio_chip *gc, unsigned offset)
114{
115 struct zx_gpio *chip = to_zx(gc);
116
117 return !!(readw_relaxed(chip->base + ZX_GPIO_DI) & BIT(offset));
118}
119
120static void zx_set_value(struct gpio_chip *gc, unsigned offset, int value)
121{
122 struct zx_gpio *chip = to_zx(gc);
123
124 if (value)
125 writew_relaxed(BIT(offset), chip->base + ZX_GPIO_DO1);
126 else
127 writew_relaxed(BIT(offset), chip->base + ZX_GPIO_DO0);
128}
129
130static int zx_irq_type(struct irq_data *d, unsigned trigger)
131{
132 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
133 struct zx_gpio *chip = to_zx(gc);
134 int offset = irqd_to_hwirq(d);
135 unsigned long flags;
136 u16 gpiois, gpioi_epos, gpioi_eneg, gpioiev;
137 u16 bit = BIT(offset);
138
139 if (offset < 0 || offset >= ZX_GPIO_NR)
140 return -EINVAL;
141
142 spin_lock_irqsave(&chip->lock, flags);
143
144 gpioiev = readw_relaxed(chip->base + ZX_GPIO_IV);
145 gpiois = readw_relaxed(chip->base + ZX_GPIO_IVE);
146 gpioi_epos = readw_relaxed(chip->base + ZX_GPIO_IEP);
147 gpioi_eneg = readw_relaxed(chip->base + ZX_GPIO_IEN);
148
149 if (trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
150 gpiois |= bit;
151 if (trigger & IRQ_TYPE_LEVEL_HIGH)
152 gpioiev |= bit;
153 else
154 gpioiev &= ~bit;
155 } else
156 gpiois &= ~bit;
157
158 if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) {
159 gpioi_epos |= bit;
160 gpioi_eneg |= bit;
161 } else {
162 if (trigger & IRQ_TYPE_EDGE_RISING) {
163 gpioi_epos |= bit;
164 gpioi_eneg &= ~bit;
165 } else if (trigger & IRQ_TYPE_EDGE_FALLING) {
166 gpioi_eneg |= bit;
167 gpioi_epos &= ~bit;
168 }
169 }
170
171 writew_relaxed(gpiois, chip->base + ZX_GPIO_IVE);
172 writew_relaxed(gpioi_epos, chip->base + ZX_GPIO_IEP);
173 writew_relaxed(gpioi_eneg, chip->base + ZX_GPIO_IEN);
174 writew_relaxed(gpioiev, chip->base + ZX_GPIO_IV);
175 spin_unlock_irqrestore(&chip->lock, flags);
176
177 return 0;
178}
179
180static void zx_irq_handler(unsigned irq, struct irq_desc *desc)
181{
182 unsigned long pending;
183 int offset;
184 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
185 struct zx_gpio *chip = to_zx(gc);
186 struct irq_chip *irqchip = irq_desc_get_chip(desc);
187
188 chained_irq_enter(irqchip, desc);
189
190 pending = readw_relaxed(chip->base + ZX_GPIO_MIS);
191 writew_relaxed(pending, chip->base + ZX_GPIO_IC);
192 if (pending) {
193 for_each_set_bit(offset, &pending, ZX_GPIO_NR)
194 generic_handle_irq(irq_find_mapping(gc->irqdomain,
195 offset));
196 }
197
198 chained_irq_exit(irqchip, desc);
199}
200
201static void zx_irq_mask(struct irq_data *d)
202{
203 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
204 struct zx_gpio *chip = to_zx(gc);
205 u16 mask = BIT(irqd_to_hwirq(d) % ZX_GPIO_NR);
206 u16 gpioie;
207
208 spin_lock(&chip->lock);
209 gpioie = readw_relaxed(chip->base + ZX_GPIO_IM) | mask;
210 writew_relaxed(gpioie, chip->base + ZX_GPIO_IM);
211 gpioie = readw_relaxed(chip->base + ZX_GPIO_IE) & ~mask;
212 writew_relaxed(gpioie, chip->base + ZX_GPIO_IE);
213 spin_unlock(&chip->lock);
214}
215
216static void zx_irq_unmask(struct irq_data *d)
217{
218 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
219 struct zx_gpio *chip = to_zx(gc);
220 u16 mask = BIT(irqd_to_hwirq(d) % ZX_GPIO_NR);
221 u16 gpioie;
222
223 spin_lock(&chip->lock);
224 gpioie = readw_relaxed(chip->base + ZX_GPIO_IM) & ~mask;
225 writew_relaxed(gpioie, chip->base + ZX_GPIO_IM);
226 gpioie = readw_relaxed(chip->base + ZX_GPIO_IE) | mask;
227 writew_relaxed(gpioie, chip->base + ZX_GPIO_IE);
228 spin_unlock(&chip->lock);
229}
230
231static struct irq_chip zx_irqchip = {
232 .name = "zx-gpio",
233 .irq_mask = zx_irq_mask,
234 .irq_unmask = zx_irq_unmask,
235 .irq_set_type = zx_irq_type,
236};
237
238static int zx_gpio_probe(struct platform_device *pdev)
239{
240 struct device *dev = &pdev->dev;
241 struct zx_gpio *chip;
242 struct resource *res;
243 int irq, id, ret;
244
245 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
246 if (!chip)
247 return -ENOMEM;
248
249 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
250 chip->base = devm_ioremap_resource(dev, res);
251 if (IS_ERR(chip->base))
252 return PTR_ERR(chip->base);
253
254 spin_lock_init(&chip->lock);
255 if (of_property_read_bool(dev->of_node, "gpio-ranges"))
256 chip->uses_pinctrl = true;
257
258 id = of_alias_get_id(dev->of_node, "gpio");
259 chip->gc.request = zx_gpio_request;
260 chip->gc.free = zx_gpio_free;
261 chip->gc.direction_input = zx_direction_input;
262 chip->gc.direction_output = zx_direction_output;
263 chip->gc.get = zx_get_value;
264 chip->gc.set = zx_set_value;
265 chip->gc.base = ZX_GPIO_NR * id;
266 chip->gc.ngpio = ZX_GPIO_NR;
267 chip->gc.label = dev_name(dev);
268 chip->gc.dev = dev;
269 chip->gc.owner = THIS_MODULE;
270
271 ret = gpiochip_add(&chip->gc);
272 if (ret)
273 return ret;
274
275 /*
276 * irq_chip support
277 */
278 writew_relaxed(0xffff, chip->base + ZX_GPIO_IM);
279 writew_relaxed(0, chip->base + ZX_GPIO_IE);
280 irq = platform_get_irq(pdev, 0);
281 if (irq < 0) {
282 dev_err(dev, "invalid IRQ\n");
283 gpiochip_remove(&chip->gc);
284 return -ENODEV;
285 }
286
287 ret = gpiochip_irqchip_add(&chip->gc, &zx_irqchip,
288 0, handle_simple_irq,
289 IRQ_TYPE_NONE);
290 if (ret) {
291 dev_err(dev, "could not add irqchip\n");
292 gpiochip_remove(&chip->gc);
293 return ret;
294 }
295 gpiochip_set_chained_irqchip(&chip->gc, &zx_irqchip,
296 irq, zx_irq_handler);
297
298 platform_set_drvdata(pdev, chip);
299 dev_info(dev, "ZX GPIO chip registered\n");
300
301 return 0;
302}
303
304static const struct of_device_id zx_gpio_match[] = {
305 {
306 .compatible = "zte,zx296702-gpio",
307 },
308 { },
309};
310MODULE_DEVICE_TABLE(of, zx_gpio_match);
311
312static struct platform_driver zx_gpio_driver = {
313 .probe = zx_gpio_probe,
314 .driver = {
315 .name = "zx_gpio",
316 .of_match_table = of_match_ptr(zx_gpio_match),
317 },
318};
319
320module_platform_driver(zx_gpio_driver)
321
322MODULE_AUTHOR("Jun Nie <jun.nie@linaro.org>");
323MODULE_DESCRIPTION("ZTE ZX296702 GPIO driver");
324MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/gpio-zynq.c b/drivers/gpio/gpio-zynq.c
index a78882389836..27348e7cb705 100644
--- a/drivers/gpio/gpio-zynq.c
+++ b/drivers/gpio/gpio-zynq.c
@@ -441,10 +441,10 @@ static int zynq_gpio_set_irq_type(struct irq_data *irq_data, unsigned int type)
441 gpio->base_addr + ZYNQ_GPIO_INTANY_OFFSET(bank_num)); 441 gpio->base_addr + ZYNQ_GPIO_INTANY_OFFSET(bank_num));
442 442
443 if (type & IRQ_TYPE_LEVEL_MASK) { 443 if (type & IRQ_TYPE_LEVEL_MASK) {
444 __irq_set_chip_handler_name_locked(irq_data->irq, 444 irq_set_chip_handler_name_locked(irq_data,
445 &zynq_gpio_level_irqchip, handle_fasteoi_irq, NULL); 445 &zynq_gpio_level_irqchip, handle_fasteoi_irq, NULL);
446 } else { 446 } else {
447 __irq_set_chip_handler_name_locked(irq_data->irq, 447 irq_set_chip_handler_name_locked(irq_data,
448 &zynq_gpio_edge_irqchip, handle_level_irq, NULL); 448 &zynq_gpio_edge_irqchip, handle_level_irq, NULL);
449 } 449 }
450 450
@@ -518,7 +518,7 @@ static void zynq_gpio_irqhandler(unsigned int irq, struct irq_desc *desc)
518{ 518{
519 u32 int_sts, int_enb; 519 u32 int_sts, int_enb;
520 unsigned int bank_num; 520 unsigned int bank_num;
521 struct zynq_gpio *gpio = irq_get_handler_data(irq); 521 struct zynq_gpio *gpio = irq_desc_get_handler_data(desc);
522 struct irq_chip *irqchip = irq_desc_get_chip(desc); 522 struct irq_chip *irqchip = irq_desc_get_chip(desc);
523 523
524 chained_irq_enter(irqchip, desc); 524 chained_irq_enter(irqchip, desc);
@@ -782,6 +782,12 @@ static int __init zynq_gpio_init(void)
782} 782}
783postcore_initcall(zynq_gpio_init); 783postcore_initcall(zynq_gpio_init);
784 784
785static void __exit zynq_gpio_exit(void)
786{
787 platform_driver_unregister(&zynq_gpio_driver);
788}
789module_exit(zynq_gpio_exit);
790
785MODULE_AUTHOR("Xilinx Inc."); 791MODULE_AUTHOR("Xilinx Inc.");
786MODULE_DESCRIPTION("Zynq GPIO driver"); 792MODULE_DESCRIPTION("Zynq GPIO driver");
787MODULE_LICENSE("GPL"); 793MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 9a0ec48a4737..fa6e3c8823d6 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -136,7 +136,6 @@ static struct gpio_desc *of_get_gpio_hog(struct device_node *np,
136{ 136{
137 struct device_node *chip_np; 137 struct device_node *chip_np;
138 enum of_gpio_flags xlate_flags; 138 enum of_gpio_flags xlate_flags;
139 struct gpio_desc *desc;
140 struct gg_data gg_data = { 139 struct gg_data gg_data = {
141 .flags = &xlate_flags, 140 .flags = &xlate_flags,
142 }; 141 };
@@ -193,9 +192,7 @@ static struct gpio_desc *of_get_gpio_hog(struct device_node *np,
193 if (name && of_property_read_string(np, "line-name", name)) 192 if (name && of_property_read_string(np, "line-name", name))
194 *name = np->name; 193 *name = np->name;
195 194
196 desc = gg_data.out_gpio; 195 return gg_data.out_gpio;
197
198 return desc;
199} 196}
200 197
201/** 198/**
@@ -338,7 +335,7 @@ void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc)
338EXPORT_SYMBOL(of_mm_gpiochip_remove); 335EXPORT_SYMBOL(of_mm_gpiochip_remove);
339 336
340#ifdef CONFIG_PINCTRL 337#ifdef CONFIG_PINCTRL
341static void of_gpiochip_add_pin_range(struct gpio_chip *chip) 338static int of_gpiochip_add_pin_range(struct gpio_chip *chip)
342{ 339{
343 struct device_node *np = chip->of_node; 340 struct device_node *np = chip->of_node;
344 struct of_phandle_args pinspec; 341 struct of_phandle_args pinspec;
@@ -349,7 +346,7 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
349 struct property *group_names; 346 struct property *group_names;
350 347
351 if (!np) 348 if (!np)
352 return; 349 return 0;
353 350
354 group_names = of_find_property(np, group_names_propname, NULL); 351 group_names = of_find_property(np, group_names_propname, NULL);
355 352
@@ -361,11 +358,11 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
361 358
362 pctldev = of_pinctrl_get(pinspec.np); 359 pctldev = of_pinctrl_get(pinspec.np);
363 if (!pctldev) 360 if (!pctldev)
364 break; 361 return -EPROBE_DEFER;
365 362
366 if (pinspec.args[2]) { 363 if (pinspec.args[2]) {
367 if (group_names) { 364 if (group_names) {
368 ret = of_property_read_string_index(np, 365 of_property_read_string_index(np,
369 group_names_propname, 366 group_names_propname,
370 index, &name); 367 index, &name);
371 if (strlen(name)) { 368 if (strlen(name)) {
@@ -381,7 +378,7 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
381 pinspec.args[1], 378 pinspec.args[1],
382 pinspec.args[2]); 379 pinspec.args[2]);
383 if (ret) 380 if (ret)
384 break; 381 return ret;
385 } else { 382 } else {
386 /* npins == 0: special range */ 383 /* npins == 0: special range */
387 if (pinspec.args[1]) { 384 if (pinspec.args[1]) {
@@ -411,32 +408,41 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
411 ret = gpiochip_add_pingroup_range(chip, pctldev, 408 ret = gpiochip_add_pingroup_range(chip, pctldev,
412 pinspec.args[0], name); 409 pinspec.args[0], name);
413 if (ret) 410 if (ret)
414 break; 411 return ret;
415 } 412 }
416 } 413 }
414
415 return 0;
417} 416}
418 417
419#else 418#else
420static void of_gpiochip_add_pin_range(struct gpio_chip *chip) {} 419static int of_gpiochip_add_pin_range(struct gpio_chip *chip) { return 0; }
421#endif 420#endif
422 421
423void of_gpiochip_add(struct gpio_chip *chip) 422int of_gpiochip_add(struct gpio_chip *chip)
424{ 423{
424 int status;
425
425 if ((!chip->of_node) && (chip->dev)) 426 if ((!chip->of_node) && (chip->dev))
426 chip->of_node = chip->dev->of_node; 427 chip->of_node = chip->dev->of_node;
427 428
428 if (!chip->of_node) 429 if (!chip->of_node)
429 return; 430 return 0;
430 431
431 if (!chip->of_xlate) { 432 if (!chip->of_xlate) {
432 chip->of_gpio_n_cells = 2; 433 chip->of_gpio_n_cells = 2;
433 chip->of_xlate = of_gpio_simple_xlate; 434 chip->of_xlate = of_gpio_simple_xlate;
434 } 435 }
435 436
436 of_gpiochip_add_pin_range(chip); 437 status = of_gpiochip_add_pin_range(chip);
438 if (status)
439 return status;
440
437 of_node_get(chip->of_node); 441 of_node_get(chip->of_node);
438 442
439 of_gpiochip_scan_hogs(chip); 443 of_gpiochip_scan_hogs(chip);
444
445 return 0;
440} 446}
441 447
442void of_gpiochip_remove(struct gpio_chip *chip) 448void of_gpiochip_remove(struct gpio_chip *chip)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index bf4bd1d120c3..b562dd36c4af 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -190,7 +190,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_direction);
190 */ 190 */
191static int gpiochip_add_to_list(struct gpio_chip *chip) 191static int gpiochip_add_to_list(struct gpio_chip *chip)
192{ 192{
193 struct list_head *pos = &gpio_chips; 193 struct list_head *pos;
194 struct gpio_chip *_chip; 194 struct gpio_chip *_chip;
195 int err = 0; 195 int err = 0;
196 196
@@ -287,7 +287,13 @@ int gpiochip_add(struct gpio_chip *chip)
287 INIT_LIST_HEAD(&chip->pin_ranges); 287 INIT_LIST_HEAD(&chip->pin_ranges);
288#endif 288#endif
289 289
290 of_gpiochip_add(chip); 290 if (!chip->owner && chip->dev && chip->dev->driver)
291 chip->owner = chip->dev->driver->owner;
292
293 status = of_gpiochip_add(chip);
294 if (status)
295 goto err_remove_chip;
296
291 acpi_gpiochip_add(chip); 297 acpi_gpiochip_add(chip);
292 298
293 status = gpiochip_sysfs_register(chip); 299 status = gpiochip_sysfs_register(chip);
@@ -443,8 +449,8 @@ void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
443 * The parent irqchip is already using the chip_data for this 449 * The parent irqchip is already using the chip_data for this
444 * irqchip, so our callbacks simply use the handler_data. 450 * irqchip, so our callbacks simply use the handler_data.
445 */ 451 */
446 irq_set_handler_data(parent_irq, gpiochip); 452 irq_set_chained_handler_and_data(parent_irq, parent_handler,
447 irq_set_chained_handler(parent_irq, parent_handler); 453 gpiochip);
448 454
449 gpiochip->irq_parent = parent_irq; 455 gpiochip->irq_parent = parent_irq;
450 } 456 }
@@ -456,12 +462,6 @@ void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
456} 462}
457EXPORT_SYMBOL_GPL(gpiochip_set_chained_irqchip); 463EXPORT_SYMBOL_GPL(gpiochip_set_chained_irqchip);
458 464
459/*
460 * This lock class tells lockdep that GPIO irqs are in a different
461 * category than their parents, so it won't report false recursion.
462 */
463static struct lock_class_key gpiochip_irq_lock_class;
464
465/** 465/**
466 * gpiochip_irq_map() - maps an IRQ into a GPIO irqchip 466 * gpiochip_irq_map() - maps an IRQ into a GPIO irqchip
467 * @d: the irqdomain used by this irqchip 467 * @d: the irqdomain used by this irqchip
@@ -478,16 +478,17 @@ static int gpiochip_irq_map(struct irq_domain *d, unsigned int irq,
478 struct gpio_chip *chip = d->host_data; 478 struct gpio_chip *chip = d->host_data;
479 479
480 irq_set_chip_data(irq, chip); 480 irq_set_chip_data(irq, chip);
481 irq_set_lockdep_class(irq, &gpiochip_irq_lock_class); 481 /*
482 * This lock class tells lockdep that GPIO irqs are in a different
483 * category than their parents, so it won't report false recursion.
484 */
485 irq_set_lockdep_class(irq, chip->lock_key);
482 irq_set_chip_and_handler(irq, chip->irqchip, chip->irq_handler); 486 irq_set_chip_and_handler(irq, chip->irqchip, chip->irq_handler);
483 /* Chips that can sleep need nested thread handlers */ 487 /* Chips that can sleep need nested thread handlers */
484 if (chip->can_sleep && !chip->irq_not_threaded) 488 if (chip->can_sleep && !chip->irq_not_threaded)
485 irq_set_nested_thread(irq, 1); 489 irq_set_nested_thread(irq, 1);
486#ifdef CONFIG_ARM
487 set_irq_flags(irq, IRQF_VALID);
488#else
489 irq_set_noprobe(irq); 490 irq_set_noprobe(irq);
490#endif 491
491 /* 492 /*
492 * No set-up of the hardware will happen if IRQ_TYPE_NONE 493 * No set-up of the hardware will happen if IRQ_TYPE_NONE
493 * is passed as default type. 494 * is passed as default type.
@@ -502,9 +503,6 @@ static void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq)
502{ 503{
503 struct gpio_chip *chip = d->host_data; 504 struct gpio_chip *chip = d->host_data;
504 505
505#ifdef CONFIG_ARM
506 set_irq_flags(irq, 0);
507#endif
508 if (chip->can_sleep) 506 if (chip->can_sleep)
509 irq_set_nested_thread(irq, 0); 507 irq_set_nested_thread(irq, 0);
510 irq_set_chip_and_handler(irq, NULL, NULL); 508 irq_set_chip_and_handler(irq, NULL, NULL);
@@ -522,10 +520,14 @@ static int gpiochip_irq_reqres(struct irq_data *d)
522{ 520{
523 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 521 struct gpio_chip *chip = irq_data_get_irq_chip_data(d);
524 522
523 if (!try_module_get(chip->owner))
524 return -ENODEV;
525
525 if (gpiochip_lock_as_irq(chip, d->hwirq)) { 526 if (gpiochip_lock_as_irq(chip, d->hwirq)) {
526 chip_err(chip, 527 chip_err(chip,
527 "unable to lock HW IRQ %lu for IRQ\n", 528 "unable to lock HW IRQ %lu for IRQ\n",
528 d->hwirq); 529 d->hwirq);
530 module_put(chip->owner);
529 return -EINVAL; 531 return -EINVAL;
530 } 532 }
531 return 0; 533 return 0;
@@ -536,6 +538,7 @@ static void gpiochip_irq_relres(struct irq_data *d)
536 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 538 struct gpio_chip *chip = irq_data_get_irq_chip_data(d);
537 539
538 gpiochip_unlock_as_irq(chip, d->hwirq); 540 gpiochip_unlock_as_irq(chip, d->hwirq);
541 module_put(chip->owner);
539} 542}
540 543
541static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset) 544static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset)
@@ -584,6 +587,7 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
584 * @handler: the irq handler to use (often a predefined irq core function) 587 * @handler: the irq handler to use (often a predefined irq core function)
585 * @type: the default type for IRQs on this irqchip, pass IRQ_TYPE_NONE 588 * @type: the default type for IRQs on this irqchip, pass IRQ_TYPE_NONE
586 * to have the core avoid setting up any default type in the hardware. 589 * to have the core avoid setting up any default type in the hardware.
590 * @lock_key: lockdep class
587 * 591 *
588 * This function closely associates a certain irqchip with a certain 592 * This function closely associates a certain irqchip with a certain
589 * gpiochip, providing an irq domain to translate the local IRQs to 593 * gpiochip, providing an irq domain to translate the local IRQs to
@@ -599,11 +603,12 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
599 * the pins on the gpiochip can generate a unique IRQ. Everything else 603 * the pins on the gpiochip can generate a unique IRQ. Everything else
600 * need to be open coded. 604 * need to be open coded.
601 */ 605 */
602int gpiochip_irqchip_add(struct gpio_chip *gpiochip, 606int _gpiochip_irqchip_add(struct gpio_chip *gpiochip,
603 struct irq_chip *irqchip, 607 struct irq_chip *irqchip,
604 unsigned int first_irq, 608 unsigned int first_irq,
605 irq_flow_handler_t handler, 609 irq_flow_handler_t handler,
606 unsigned int type) 610 unsigned int type,
611 struct lock_class_key *lock_key)
607{ 612{
608 struct device_node *of_node; 613 struct device_node *of_node;
609 unsigned int offset; 614 unsigned int offset;
@@ -629,6 +634,7 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
629 gpiochip->irq_handler = handler; 634 gpiochip->irq_handler = handler;
630 gpiochip->irq_default_type = type; 635 gpiochip->irq_default_type = type;
631 gpiochip->to_irq = gpiochip_to_irq; 636 gpiochip->to_irq = gpiochip_to_irq;
637 gpiochip->lock_key = lock_key;
632 gpiochip->irqdomain = irq_domain_add_simple(of_node, 638 gpiochip->irqdomain = irq_domain_add_simple(of_node,
633 gpiochip->ngpio, first_irq, 639 gpiochip->ngpio, first_irq,
634 &gpiochip_domain_ops, gpiochip); 640 &gpiochip_domain_ops, gpiochip);
@@ -636,8 +642,16 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
636 gpiochip->irqchip = NULL; 642 gpiochip->irqchip = NULL;
637 return -EINVAL; 643 return -EINVAL;
638 } 644 }
639 irqchip->irq_request_resources = gpiochip_irq_reqres; 645
640 irqchip->irq_release_resources = gpiochip_irq_relres; 646 /*
647 * It is possible for a driver to override this, but only if the
648 * alternative functions are both implemented.
649 */
650 if (!irqchip->irq_request_resources &&
651 !irqchip->irq_release_resources) {
652 irqchip->irq_request_resources = gpiochip_irq_reqres;
653 irqchip->irq_release_resources = gpiochip_irq_relres;
654 }
641 655
642 /* 656 /*
643 * Prepare the mapping since the irqchip shall be orthogonal to 657 * Prepare the mapping since the irqchip shall be orthogonal to
@@ -658,7 +672,7 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
658 672
659 return 0; 673 return 0;
660} 674}
661EXPORT_SYMBOL_GPL(gpiochip_irqchip_add); 675EXPORT_SYMBOL_GPL(_gpiochip_irqchip_add);
662 676
663#else /* CONFIG_GPIOLIB_IRQCHIP */ 677#else /* CONFIG_GPIOLIB_IRQCHIP */
664 678
@@ -671,7 +685,7 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip) {}
671/** 685/**
672 * gpiochip_add_pingroup_range() - add a range for GPIO <-> pin mapping 686 * gpiochip_add_pingroup_range() - add a range for GPIO <-> pin mapping
673 * @chip: the gpiochip to add the range for 687 * @chip: the gpiochip to add the range for
674 * @pinctrl: the dev_name() of the pin controller to map to 688 * @pctldev: the pin controller to map to
675 * @gpio_offset: the start offset in the current gpio_chip number space 689 * @gpio_offset: the start offset in the current gpio_chip number space
676 * @pin_group: name of the pin group inside the pin controller 690 * @pin_group: name of the pin group inside the pin controller
677 */ 691 */
@@ -1894,12 +1908,12 @@ EXPORT_SYMBOL_GPL(gpiod_count);
1894 * dev, -ENOENT if no GPIO has been assigned to the requested function, or 1908 * dev, -ENOENT if no GPIO has been assigned to the requested function, or
1895 * another IS_ERR() code if an error occurred while trying to acquire the GPIO. 1909 * another IS_ERR() code if an error occurred while trying to acquire the GPIO.
1896 */ 1910 */
1897struct gpio_desc *__must_check __gpiod_get(struct device *dev, const char *con_id, 1911struct gpio_desc *__must_check gpiod_get(struct device *dev, const char *con_id,
1898 enum gpiod_flags flags) 1912 enum gpiod_flags flags)
1899{ 1913{
1900 return gpiod_get_index(dev, con_id, 0, flags); 1914 return gpiod_get_index(dev, con_id, 0, flags);
1901} 1915}
1902EXPORT_SYMBOL_GPL(__gpiod_get); 1916EXPORT_SYMBOL_GPL(gpiod_get);
1903 1917
1904/** 1918/**
1905 * gpiod_get_optional - obtain an optional GPIO for a given GPIO function 1919 * gpiod_get_optional - obtain an optional GPIO for a given GPIO function
@@ -1911,13 +1925,13 @@ EXPORT_SYMBOL_GPL(__gpiod_get);
1911 * the requested function it will return NULL. This is convenient for drivers 1925 * the requested function it will return NULL. This is convenient for drivers
1912 * that need to handle optional GPIOs. 1926 * that need to handle optional GPIOs.
1913 */ 1927 */
1914struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev, 1928struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
1915 const char *con_id, 1929 const char *con_id,
1916 enum gpiod_flags flags) 1930 enum gpiod_flags flags)
1917{ 1931{
1918 return gpiod_get_index_optional(dev, con_id, 0, flags); 1932 return gpiod_get_index_optional(dev, con_id, 0, flags);
1919} 1933}
1920EXPORT_SYMBOL_GPL(__gpiod_get_optional); 1934EXPORT_SYMBOL_GPL(gpiod_get_optional);
1921 1935
1922 1936
1923/** 1937/**
@@ -1974,7 +1988,7 @@ static int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
1974 * requested function and/or index, or another IS_ERR() code if an error 1988 * requested function and/or index, or another IS_ERR() code if an error
1975 * occurred while trying to acquire the GPIO. 1989 * occurred while trying to acquire the GPIO.
1976 */ 1990 */
1977struct gpio_desc *__must_check __gpiod_get_index(struct device *dev, 1991struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
1978 const char *con_id, 1992 const char *con_id,
1979 unsigned int idx, 1993 unsigned int idx,
1980 enum gpiod_flags flags) 1994 enum gpiod_flags flags)
@@ -2023,7 +2037,7 @@ struct gpio_desc *__must_check __gpiod_get_index(struct device *dev,
2023 2037
2024 return desc; 2038 return desc;
2025} 2039}
2026EXPORT_SYMBOL_GPL(__gpiod_get_index); 2040EXPORT_SYMBOL_GPL(gpiod_get_index);
2027 2041
2028/** 2042/**
2029 * fwnode_get_named_gpiod - obtain a GPIO from firmware node 2043 * fwnode_get_named_gpiod - obtain a GPIO from firmware node
@@ -2092,7 +2106,7 @@ EXPORT_SYMBOL_GPL(fwnode_get_named_gpiod);
2092 * specified index was assigned to the requested function it will return NULL. 2106 * specified index was assigned to the requested function it will return NULL.
2093 * This is convenient for drivers that need to handle optional GPIOs. 2107 * This is convenient for drivers that need to handle optional GPIOs.
2094 */ 2108 */
2095struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, 2109struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
2096 const char *con_id, 2110 const char *con_id,
2097 unsigned int index, 2111 unsigned int index,
2098 enum gpiod_flags flags) 2112 enum gpiod_flags flags)
@@ -2107,7 +2121,7 @@ struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev,
2107 2121
2108 return desc; 2122 return desc;
2109} 2123}
2110EXPORT_SYMBOL_GPL(__gpiod_get_index_optional); 2124EXPORT_SYMBOL_GPL(gpiod_get_index_optional);
2111 2125
2112/** 2126/**
2113 * gpiod_hog - Hog the specified GPIO desc given the provided flags 2127 * gpiod_hog - Hog the specified GPIO desc given the provided flags
diff --git a/drivers/gpu/drm/msm/edp/edp_ctrl.c b/drivers/gpu/drm/msm/edp/edp_ctrl.c
index 7991069dd492..81200e9be382 100644
--- a/drivers/gpu/drm/msm/edp/edp_ctrl.c
+++ b/drivers/gpu/drm/msm/edp/edp_ctrl.c
@@ -373,7 +373,7 @@ static int edp_gpio_config(struct edp_ctrl *ctrl)
373 struct device *dev = &ctrl->pdev->dev; 373 struct device *dev = &ctrl->pdev->dev;
374 int ret; 374 int ret;
375 375
376 ctrl->panel_hpd_gpio = devm_gpiod_get(dev, "panel-hpd"); 376 ctrl->panel_hpd_gpio = devm_gpiod_get(dev, "panel-hpd", GPIOD_IN);
377 if (IS_ERR(ctrl->panel_hpd_gpio)) { 377 if (IS_ERR(ctrl->panel_hpd_gpio)) {
378 ret = PTR_ERR(ctrl->panel_hpd_gpio); 378 ret = PTR_ERR(ctrl->panel_hpd_gpio);
379 ctrl->panel_hpd_gpio = NULL; 379 ctrl->panel_hpd_gpio = NULL;
@@ -381,13 +381,7 @@ static int edp_gpio_config(struct edp_ctrl *ctrl)
381 return ret; 381 return ret;
382 } 382 }
383 383
384 ret = gpiod_direction_input(ctrl->panel_hpd_gpio); 384 ctrl->panel_en_gpio = devm_gpiod_get(dev, "panel-en", GPIOD_OUT_LOW);
385 if (ret) {
386 pr_err("%s: Set direction for hpd failed, %d\n", __func__, ret);
387 return ret;
388 }
389
390 ctrl->panel_en_gpio = devm_gpiod_get(dev, "panel-en");
391 if (IS_ERR(ctrl->panel_en_gpio)) { 385 if (IS_ERR(ctrl->panel_en_gpio)) {
392 ret = PTR_ERR(ctrl->panel_en_gpio); 386 ret = PTR_ERR(ctrl->panel_en_gpio);
393 ctrl->panel_en_gpio = NULL; 387 ctrl->panel_en_gpio = NULL;
@@ -395,13 +389,6 @@ static int edp_gpio_config(struct edp_ctrl *ctrl)
395 return ret; 389 return ret;
396 } 390 }
397 391
398 ret = gpiod_direction_output(ctrl->panel_en_gpio, 0);
399 if (ret) {
400 pr_err("%s: Set direction for panel_en failed, %d\n",
401 __func__, ret);
402 return ret;
403 }
404
405 DBG("gpio on"); 392 DBG("gpio on");
406 393
407 return 0; 394 return 0;
diff --git a/drivers/gpu/drm/tilcdc/tilcdc_panel.c b/drivers/gpu/drm/tilcdc/tilcdc_panel.c
index 7a0315855e90..0af8bed7ce1e 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_panel.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_panel.c
@@ -375,25 +375,17 @@ static int panel_probe(struct platform_device *pdev)
375 dev_info(&pdev->dev, "found backlight\n"); 375 dev_info(&pdev->dev, "found backlight\n");
376 } 376 }
377 377
378 panel_mod->enable_gpio = devm_gpiod_get(&pdev->dev, "enable"); 378 panel_mod->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable",
379 GPIOD_OUT_LOW);
379 if (IS_ERR(panel_mod->enable_gpio)) { 380 if (IS_ERR(panel_mod->enable_gpio)) {
380 ret = PTR_ERR(panel_mod->enable_gpio); 381 ret = PTR_ERR(panel_mod->enable_gpio);
381 if (ret != -ENOENT) { 382 dev_err(&pdev->dev, "failed to request enable GPIO\n");
382 dev_err(&pdev->dev, "failed to request enable GPIO\n"); 383 goto fail_backlight;
383 goto fail_backlight;
384 }
385
386 /* Optional GPIO is not here, continue silently. */
387 panel_mod->enable_gpio = NULL;
388 } else {
389 ret = gpiod_direction_output(panel_mod->enable_gpio, 0);
390 if (ret < 0) {
391 dev_err(&pdev->dev, "failed to setup GPIO\n");
392 goto fail_backlight;
393 }
394 dev_info(&pdev->dev, "found enable GPIO\n");
395 } 384 }
396 385
386 if (panel_mod->enable_gpio)
387 dev_info(&pdev->dev, "found enable GPIO\n");
388
397 mod = &panel_mod->base; 389 mod = &panel_mod->base;
398 pdev->dev.platform_data = mod; 390 pdev->dev.platform_data = mod;
399 391
diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
index f101bb5bddc7..993eb201148e 100644
--- a/drivers/iio/light/stk3310.c
+++ b/drivers/iio/light/stk3310.c
@@ -469,16 +469,12 @@ static int stk3310_gpio_probe(struct i2c_client *client)
469 dev = &client->dev; 469 dev = &client->dev;
470 470
471 /* gpio interrupt pin */ 471 /* gpio interrupt pin */
472 gpio = devm_gpiod_get_index(dev, STK3310_GPIO, 0); 472 gpio = devm_gpiod_get_index(dev, STK3310_GPIO, 0, GPIOD_IN);
473 if (IS_ERR(gpio)) { 473 if (IS_ERR(gpio)) {
474 dev_err(dev, "acpi gpio get index failed\n"); 474 dev_err(dev, "acpi gpio get index failed\n");
475 return PTR_ERR(gpio); 475 return PTR_ERR(gpio);
476 } 476 }
477 477
478 ret = gpiod_direction_input(gpio);
479 if (ret)
480 return ret;
481
482 ret = gpiod_to_irq(gpio); 478 ret = gpiod_to_irq(gpio);
483 dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); 479 dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
484 480
diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
index e330205f8194..d8e614ca069f 100644
--- a/drivers/iio/magnetometer/bmc150_magn.c
+++ b/drivers/iio/magnetometer/bmc150_magn.c
@@ -845,16 +845,12 @@ static int bmc150_magn_gpio_probe(struct i2c_client *client)
845 dev = &client->dev; 845 dev = &client->dev;
846 846
847 /* data ready GPIO interrupt pin */ 847 /* data ready GPIO interrupt pin */
848 gpio = devm_gpiod_get_index(dev, BMC150_MAGN_GPIO_INT, 0); 848 gpio = devm_gpiod_get_index(dev, BMC150_MAGN_GPIO_INT, 0, GPIOD_IN);
849 if (IS_ERR(gpio)) { 849 if (IS_ERR(gpio)) {
850 dev_err(dev, "ACPI GPIO get index failed\n"); 850 dev_err(dev, "ACPI GPIO get index failed\n");
851 return PTR_ERR(gpio); 851 return PTR_ERR(gpio);
852 } 852 }
853 853
854 ret = gpiod_direction_input(gpio);
855 if (ret)
856 return ret;
857
858 ret = gpiod_to_irq(gpio); 854 ret = gpiod_to_irq(gpio);
859 855
860 dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); 856 dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
diff --git a/drivers/media/i2c/adp1653.c b/drivers/media/i2c/adp1653.c
index c70ababce954..5dd39775d6ca 100644
--- a/drivers/media/i2c/adp1653.c
+++ b/drivers/media/i2c/adp1653.c
@@ -465,7 +465,7 @@ static int adp1653_of_init(struct i2c_client *client,
465 465
466 of_node_put(child); 466 of_node_put(child);
467 467
468 pd->enable_gpio = devm_gpiod_get(&client->dev, "enable"); 468 pd->enable_gpio = devm_gpiod_get(&client->dev, "enable", GPIOD_OUT_LOW);
469 if (!pd->enable_gpio) { 469 if (!pd->enable_gpio) {
470 dev_err(&client->dev, "Error getting GPIO\n"); 470 dev_err(&client->dev, "Error getting GPIO\n");
471 return -EINVAL; 471 return -EINVAL;
diff --git a/drivers/nfc/nxp-nci/i2c.c b/drivers/nfc/nxp-nci/i2c.c
index 2f77f1d03638..fac80c691914 100644
--- a/drivers/nfc/nxp-nci/i2c.c
+++ b/drivers/nfc/nxp-nci/i2c.c
@@ -318,19 +318,15 @@ static int nxp_nci_i2c_acpi_config(struct nxp_nci_i2c_phy *phy)
318 struct i2c_client *client = phy->i2c_dev; 318 struct i2c_client *client = phy->i2c_dev;
319 struct gpio_desc *gpiod_en, *gpiod_fw, *gpiod_irq; 319 struct gpio_desc *gpiod_en, *gpiod_fw, *gpiod_irq;
320 320
321 gpiod_en = devm_gpiod_get_index(&client->dev, NULL, 2); 321 gpiod_en = devm_gpiod_get_index(&client->dev, NULL, 2, GPIOD_OUT_LOW);
322 gpiod_fw = devm_gpiod_get_index(&client->dev, NULL, 1); 322 gpiod_fw = devm_gpiod_get_index(&client->dev, NULL, 1, GPIOD_OUT_LOW);
323 gpiod_irq = devm_gpiod_get_index(&client->dev, NULL, 0); 323 gpiod_irq = devm_gpiod_get_index(&client->dev, NULL, 0, GPIOD_IN);
324 324
325 if (IS_ERR(gpiod_en) || IS_ERR(gpiod_fw) || IS_ERR(gpiod_irq)) { 325 if (IS_ERR(gpiod_en) || IS_ERR(gpiod_fw) || IS_ERR(gpiod_irq)) {
326 nfc_err(&client->dev, "No GPIOs\n"); 326 nfc_err(&client->dev, "No GPIOs\n");
327 return -EINVAL; 327 return -EINVAL;
328 } 328 }
329 329
330 gpiod_direction_output(gpiod_en, 0);
331 gpiod_direction_output(gpiod_fw, 0);
332 gpiod_direction_input(gpiod_irq);
333
334 client->irq = gpiod_to_irq(gpiod_irq); 330 client->irq = gpiod_to_irq(gpiod_irq);
335 if (client->irq < 0) { 331 if (client->irq < 0) {
336 nfc_err(&client->dev, "No IRQ\n"); 332 nfc_err(&client->dev, "No IRQ\n");
diff --git a/drivers/phy/phy-tusb1210.c b/drivers/phy/phy-tusb1210.c
index 2535d792d57a..4f6d5e71507d 100644
--- a/drivers/phy/phy-tusb1210.c
+++ b/drivers/phy/phy-tusb1210.c
@@ -61,32 +61,26 @@ static const struct phy_ops phy_ops = {
61 61
62static int tusb1210_probe(struct ulpi *ulpi) 62static int tusb1210_probe(struct ulpi *ulpi)
63{ 63{
64 struct gpio_desc *gpio;
65 struct tusb1210 *tusb; 64 struct tusb1210 *tusb;
66 u8 val, reg; 65 u8 val, reg;
67 int ret;
68 66
69 tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL); 67 tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL);
70 if (!tusb) 68 if (!tusb)
71 return -ENOMEM; 69 return -ENOMEM;
72 70
73 gpio = devm_gpiod_get(&ulpi->dev, "reset"); 71 tusb->gpio_reset = devm_gpiod_get_optional(&ulpi->dev, "reset",
74 if (!IS_ERR(gpio)) { 72 GPIOD_OUT_LOW);
75 ret = gpiod_direction_output(gpio, 0); 73 if (IS_ERR(tusb->gpio_reset))
76 if (ret) 74 return PTR_ERR(tusb->gpio_reset);
77 return ret;
78 gpiod_set_value_cansleep(gpio, 1);
79 tusb->gpio_reset = gpio;
80 }
81 75
82 gpio = devm_gpiod_get(&ulpi->dev, "cs"); 76 gpiod_set_value_cansleep(tusb->gpio_reset, 1);
83 if (!IS_ERR(gpio)) { 77
84 ret = gpiod_direction_output(gpio, 0); 78 tusb->gpio_cs = devm_gpiod_get_optional(&ulpi->dev, "cs",
85 if (ret) 79 GPIOD_OUT_LOW);
86 return ret; 80 if (IS_ERR(tusb->gpio_cs))
87 gpiod_set_value_cansleep(gpio, 1); 81 return PTR_ERR(tusb->gpio_cs);
88 tusb->gpio_cs = gpio; 82
89 } 83 gpiod_set_value_cansleep(tusb->gpio_cs, 1);
90 84
91 /* 85 /*
92 * VENDOR_SPECIFIC2 register in TUSB1210 can be used for configuring eye 86 * VENDOR_SPECIFIC2 register in TUSB1210 can be used for configuring eye
diff --git a/include/linux/basic_mmio_gpio.h b/include/linux/basic_mmio_gpio.h
index 14eea946e640..ed3768f4ecc7 100644
--- a/include/linux/basic_mmio_gpio.h
+++ b/include/linux/basic_mmio_gpio.h
@@ -75,5 +75,6 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
75#define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */ 75#define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */
76#define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3) 76#define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3)
77#define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */ 77#define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */
78#define BGPIOF_NO_OUTPUT BIT(5) /* only input */
78 79
79#endif /* __BASIC_MMIO_GPIO_H */ 80#endif /* __BASIC_MMIO_GPIO_H */
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index adac255aee86..14cac67c2012 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -47,17 +47,17 @@ enum gpiod_flags {
47int gpiod_count(struct device *dev, const char *con_id); 47int gpiod_count(struct device *dev, const char *con_id);
48 48
49/* Acquire and dispose GPIOs */ 49/* Acquire and dispose GPIOs */
50struct gpio_desc *__must_check __gpiod_get(struct device *dev, 50struct gpio_desc *__must_check gpiod_get(struct device *dev,
51 const char *con_id, 51 const char *con_id,
52 enum gpiod_flags flags); 52 enum gpiod_flags flags);
53struct gpio_desc *__must_check __gpiod_get_index(struct device *dev, 53struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
54 const char *con_id, 54 const char *con_id,
55 unsigned int idx, 55 unsigned int idx,
56 enum gpiod_flags flags); 56 enum gpiod_flags flags);
57struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev, 57struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
58 const char *con_id, 58 const char *con_id,
59 enum gpiod_flags flags); 59 enum gpiod_flags flags);
60struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, 60struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
61 const char *con_id, 61 const char *con_id,
62 unsigned int index, 62 unsigned int index,
63 enum gpiod_flags flags); 63 enum gpiod_flags flags);
@@ -70,18 +70,18 @@ struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
70void gpiod_put(struct gpio_desc *desc); 70void gpiod_put(struct gpio_desc *desc);
71void gpiod_put_array(struct gpio_descs *descs); 71void gpiod_put_array(struct gpio_descs *descs);
72 72
73struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, 73struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
74 const char *con_id, 74 const char *con_id,
75 enum gpiod_flags flags); 75 enum gpiod_flags flags);
76struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev, 76struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
77 const char *con_id, 77 const char *con_id,
78 unsigned int idx, 78 unsigned int idx,
79 enum gpiod_flags flags); 79 enum gpiod_flags flags);
80struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, 80struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
81 const char *con_id, 81 const char *con_id,
82 enum gpiod_flags flags); 82 enum gpiod_flags flags);
83struct gpio_desc *__must_check 83struct gpio_desc *__must_check
84__devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 84devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
85 unsigned int index, enum gpiod_flags flags); 85 unsigned int index, enum gpiod_flags flags);
86struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev, 86struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
87 const char *con_id, 87 const char *con_id,
@@ -146,31 +146,31 @@ static inline int gpiod_count(struct device *dev, const char *con_id)
146 return 0; 146 return 0;
147} 147}
148 148
149static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev, 149static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
150 const char *con_id, 150 const char *con_id,
151 enum gpiod_flags flags) 151 enum gpiod_flags flags)
152{ 152{
153 return ERR_PTR(-ENOSYS); 153 return ERR_PTR(-ENOSYS);
154} 154}
155static inline struct gpio_desc *__must_check 155static inline struct gpio_desc *__must_check
156__gpiod_get_index(struct device *dev, 156gpiod_get_index(struct device *dev,
157 const char *con_id, 157 const char *con_id,
158 unsigned int idx, 158 unsigned int idx,
159 enum gpiod_flags flags) 159 enum gpiod_flags flags)
160{ 160{
161 return ERR_PTR(-ENOSYS); 161 return ERR_PTR(-ENOSYS);
162} 162}
163 163
164static inline struct gpio_desc *__must_check 164static inline struct gpio_desc *__must_check
165__gpiod_get_optional(struct device *dev, const char *con_id, 165gpiod_get_optional(struct device *dev, const char *con_id,
166 enum gpiod_flags flags) 166 enum gpiod_flags flags)
167{ 167{
168 return ERR_PTR(-ENOSYS); 168 return ERR_PTR(-ENOSYS);
169} 169}
170 170
171static inline struct gpio_desc *__must_check 171static inline struct gpio_desc *__must_check
172__gpiod_get_index_optional(struct device *dev, const char *con_id, 172gpiod_get_index_optional(struct device *dev, const char *con_id,
173 unsigned int index, enum gpiod_flags flags) 173 unsigned int index, enum gpiod_flags flags)
174{ 174{
175 return ERR_PTR(-ENOSYS); 175 return ERR_PTR(-ENOSYS);
176} 176}
@@ -206,7 +206,7 @@ static inline void gpiod_put_array(struct gpio_descs *descs)
206} 206}
207 207
208static inline struct gpio_desc *__must_check 208static inline struct gpio_desc *__must_check
209__devm_gpiod_get(struct device *dev, 209devm_gpiod_get(struct device *dev,
210 const char *con_id, 210 const char *con_id,
211 enum gpiod_flags flags) 211 enum gpiod_flags flags)
212{ 212{
@@ -214,7 +214,7 @@ __devm_gpiod_get(struct device *dev,
214} 214}
215static inline 215static inline
216struct gpio_desc *__must_check 216struct gpio_desc *__must_check
217__devm_gpiod_get_index(struct device *dev, 217devm_gpiod_get_index(struct device *dev,
218 const char *con_id, 218 const char *con_id,
219 unsigned int idx, 219 unsigned int idx,
220 enum gpiod_flags flags) 220 enum gpiod_flags flags)
@@ -223,14 +223,14 @@ __devm_gpiod_get_index(struct device *dev,
223} 223}
224 224
225static inline struct gpio_desc *__must_check 225static inline struct gpio_desc *__must_check
226__devm_gpiod_get_optional(struct device *dev, const char *con_id, 226devm_gpiod_get_optional(struct device *dev, const char *con_id,
227 enum gpiod_flags flags) 227 enum gpiod_flags flags)
228{ 228{
229 return ERR_PTR(-ENOSYS); 229 return ERR_PTR(-ENOSYS);
230} 230}
231 231
232static inline struct gpio_desc *__must_check 232static inline struct gpio_desc *__must_check
233__devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 233devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
234 unsigned int index, enum gpiod_flags flags) 234 unsigned int index, enum gpiod_flags flags)
235{ 235{
236 return ERR_PTR(-ENOSYS); 236 return ERR_PTR(-ENOSYS);
@@ -424,42 +424,6 @@ static inline struct gpio_desc *devm_get_gpiod_from_child(
424 424
425#endif /* CONFIG_GPIOLIB */ 425#endif /* CONFIG_GPIOLIB */
426 426
427/*
428 * Vararg-hacks! This is done to transition the kernel to always pass
429 * the options flags argument to the below functions. During a transition
430 * phase these vararg macros make both old-and-newstyle code compile,
431 * but when all calls to the elder API are removed, these should go away
432 * and the __gpiod_get() etc functions above be renamed just gpiod_get()
433 * etc.
434 */
435#define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags)
436#define gpiod_get(varargs...) __gpiod_get(varargs, GPIOD_ASIS)
437#define __gpiod_get_index(dev, con_id, index, flags, ...) \
438 __gpiod_get_index(dev, con_id, index, flags)
439#define gpiod_get_index(varargs...) __gpiod_get_index(varargs, GPIOD_ASIS)
440#define __gpiod_get_optional(dev, con_id, flags, ...) \
441 __gpiod_get_optional(dev, con_id, flags)
442#define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, GPIOD_ASIS)
443#define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \
444 __gpiod_get_index_optional(dev, con_id, index, flags)
445#define gpiod_get_index_optional(varargs...) \
446 __gpiod_get_index_optional(varargs, GPIOD_ASIS)
447#define __devm_gpiod_get(dev, con_id, flags, ...) \
448 __devm_gpiod_get(dev, con_id, flags)
449#define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, GPIOD_ASIS)
450#define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \
451 __devm_gpiod_get_index(dev, con_id, index, flags)
452#define devm_gpiod_get_index(varargs...) \
453 __devm_gpiod_get_index(varargs, GPIOD_ASIS)
454#define __devm_gpiod_get_optional(dev, con_id, flags, ...) \
455 __devm_gpiod_get_optional(dev, con_id, flags)
456#define devm_gpiod_get_optional(varargs...) \
457 __devm_gpiod_get_optional(varargs, GPIOD_ASIS)
458#define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \
459 __devm_gpiod_get_index_optional(dev, con_id, index, flags)
460#define devm_gpiod_get_index_optional(varargs...) \
461 __devm_gpiod_get_index_optional(varargs, GPIOD_ASIS)
462
463#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) 427#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
464 428
465int gpiod_export(struct gpio_desc *desc, bool direction_may_change); 429int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index c8393cd4d44f..1aed31c5ffba 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -6,6 +6,7 @@
6#include <linux/irq.h> 6#include <linux/irq.h>
7#include <linux/irqchip/chained_irq.h> 7#include <linux/irqchip/chained_irq.h>
8#include <linux/irqdomain.h> 8#include <linux/irqdomain.h>
9#include <linux/lockdep.h>
9#include <linux/pinctrl/pinctrl.h> 10#include <linux/pinctrl/pinctrl.h>
10 11
11struct device; 12struct device;
@@ -64,6 +65,17 @@ struct seq_file;
64 * registers. 65 * registers.
65 * @irq_not_threaded: flag must be set if @can_sleep is set but the 66 * @irq_not_threaded: flag must be set if @can_sleep is set but the
66 * IRQs don't need to be threaded 67 * IRQs don't need to be threaded
68 * @irqchip: GPIO IRQ chip impl, provided by GPIO driver
69 * @irqdomain: Interrupt translation domain; responsible for mapping
70 * between GPIO hwirq number and linux irq number
71 * @irq_base: first linux IRQ number assigned to GPIO IRQ chip (deprecated)
72 * @irq_handler: the irq handler to use (often a predefined irq core function)
73 * for GPIO IRQs, provided by GPIO driver
74 * @irq_default_type: default IRQ triggering type applied during GPIO driver
75 * initialization, provided by GPIO driver
76 * @irq_parent: GPIO IRQ chip parent/bank linux irq number,
77 * provided by GPIO driver
78 * @lock_key: per GPIO IRQ chip lockdep class
67 * 79 *
68 * A gpio_chip can help platforms abstract various sources of GPIOs so 80 * A gpio_chip can help platforms abstract various sources of GPIOs so
69 * they can all be accessed through a common programing interface. 81 * they can all be accessed through a common programing interface.
@@ -126,6 +138,7 @@ struct gpio_chip {
126 irq_flow_handler_t irq_handler; 138 irq_flow_handler_t irq_handler;
127 unsigned int irq_default_type; 139 unsigned int irq_default_type;
128 int irq_parent; 140 int irq_parent;
141 struct lock_class_key *lock_key;
129#endif 142#endif
130 143
131#if defined(CONFIG_OF_GPIO) 144#if defined(CONFIG_OF_GPIO)
@@ -171,11 +184,25 @@ void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
171 int parent_irq, 184 int parent_irq,
172 irq_flow_handler_t parent_handler); 185 irq_flow_handler_t parent_handler);
173 186
174int gpiochip_irqchip_add(struct gpio_chip *gpiochip, 187int _gpiochip_irqchip_add(struct gpio_chip *gpiochip,
175 struct irq_chip *irqchip, 188 struct irq_chip *irqchip,
176 unsigned int first_irq, 189 unsigned int first_irq,
177 irq_flow_handler_t handler, 190 irq_flow_handler_t handler,
178 unsigned int type); 191 unsigned int type,
192 struct lock_class_key *lock_key);
193
194#ifdef CONFIG_LOCKDEP
195#define gpiochip_irqchip_add(...) \
196( \
197 ({ \
198 static struct lock_class_key _key; \
199 _gpiochip_irqchip_add(__VA_ARGS__, &_key); \
200 }) \
201)
202#else
203#define gpiochip_irqchip_add(...) \
204 _gpiochip_irqchip_add(__VA_ARGS__, NULL)
205#endif
179 206
180#endif /* CONFIG_GPIOLIB_IRQCHIP */ 207#endif /* CONFIG_GPIOLIB_IRQCHIP */
181 208
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index 69dbe312b11b..f3191828f037 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -54,7 +54,7 @@ extern int of_mm_gpiochip_add(struct device_node *np,
54 struct of_mm_gpio_chip *mm_gc); 54 struct of_mm_gpio_chip *mm_gc);
55extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc); 55extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc);
56 56
57extern void of_gpiochip_add(struct gpio_chip *gc); 57extern int of_gpiochip_add(struct gpio_chip *gc);
58extern void of_gpiochip_remove(struct gpio_chip *gc); 58extern void of_gpiochip_remove(struct gpio_chip *gc);
59extern int of_gpio_simple_xlate(struct gpio_chip *gc, 59extern int of_gpio_simple_xlate(struct gpio_chip *gc,
60 const struct of_phandle_args *gpiospec, 60 const struct of_phandle_args *gpiospec,
@@ -76,7 +76,7 @@ static inline int of_gpio_simple_xlate(struct gpio_chip *gc,
76 return -ENOSYS; 76 return -ENOSYS;
77} 77}
78 78
79static inline void of_gpiochip_add(struct gpio_chip *gc) { } 79static inline int of_gpiochip_add(struct gpio_chip *gc) { return 0; }
80static inline void of_gpiochip_remove(struct gpio_chip *gc) { } 80static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
81 81
82#endif /* CONFIG_OF_GPIO */ 82#endif /* CONFIG_OF_GPIO */
diff --git a/include/linux/platform_data/gpio-em.h b/include/linux/platform_data/gpio-em.h
deleted file mode 100644
index 7c5a519d2dcd..000000000000
--- a/include/linux/platform_data/gpio-em.h
+++ /dev/null
@@ -1,11 +0,0 @@
1#ifndef __GPIO_EM_H__
2#define __GPIO_EM_H__
3
4struct gpio_em_config {
5 unsigned int gpio_base;
6 unsigned int irq_base;
7 unsigned int number_of_pins;
8 const char *pctl_name;
9};
10
11#endif /* __GPIO_EM_H__ */