Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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
...

+1667 -515
+2 -1
Documentation/ABI/testing/sysfs-gpio
··· 16 16 /sys/class/gpio 17 17 /export ... asks the kernel to export a GPIO to userspace 18 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 21 /value ... always readable, writes fail for input GPIOs 21 22 /direction ... r/w as: in, out (default low); write: high, low 22 23 /edge ... r/w as: none, falling, rising, both
+28 -7
Documentation/devicetree/bindings/gpio/brcm,brcmstb-gpio.txt
··· 33 33 - interrupt-parent: 34 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 43 - #interrupt-cells: 37 44 Should be <2>. The first cell is the GPIO number, the second should specify 38 45 flags. The following subset of flags is supported: ··· 54 47 - interrupt-controller: 55 48 Marks the device node as an interrupt controller 56 49 57 - - interrupt-names: 58 - The name of the IRQ resource used by this controller 50 + - wakeup-source: 51 + GPIOs for this controller can be used as a wakeup source 59 52 60 53 Example: 61 54 upg_gio: gpio@f040a700 { 62 - #gpio-cells = <0x2>; 63 - #interrupt-cells = <0x2>; 55 + #gpio-cells = <2>; 56 + #interrupt-cells = <2>; 64 57 compatible = "brcm,bcm7445-gpio", "brcm,brcmstb-gpio"; 65 58 gpio-controller; 66 59 interrupt-controller; 67 60 reg = <0xf040a700 0x80>; 68 - interrupt-parent = <0xf>; 61 + interrupt-parent = <&irq0_intc>; 69 62 interrupts = <0x6>; 70 - interrupt-names = "upg_gio"; 71 - brcm,gpio-bank-widths = <0x20 0x20 0x20 0x18>; 63 + brcm,gpio-bank-widths = <32 32 32 24>; 64 + }; 65 + 66 + upg_gio_aon: gpio@f04172c0 { 67 + #gpio-cells = <2>; 68 + #interrupt-cells = <2>; 69 + compatible = "brcm,bcm7445-gpio", "brcm,brcmstb-gpio"; 70 + gpio-controller; 71 + interrupt-controller; 72 + reg = <0xf04172c0 0x40>; 73 + interrupt-parent = <&irq0_aon_intc>; 74 + interrupts = <0x6>; 75 + interrupts-extended = <&irq0_aon_intc 0x6>, 76 + <&aon_pm_l2_intc 0x5>; 77 + wakeup-source; 78 + brcm,gpio-bank-widths = <18 4>; 72 79 };
+2 -1
Documentation/devicetree/bindings/gpio/gpio-etraxfs.txt
··· 2 2 3 3 Required properties: 4 4 5 - - compatible: 5 + - compatible: one of: 6 6 - "axis,etraxfs-gio" 7 + - "axis,artpec3-gio" 7 8 - reg: Physical base address and length of the controller's registers. 8 9 - #gpio-cells: Should be 3 9 10 - The first cell is the gpio offset number.
+22
Documentation/devicetree/bindings/gpio/gpio-mpc8xxx.txt
··· 1 + * Freescale MPC512x/MPC8xxx GPIO controller 2 + 3 + Required 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 + 14 + Example: 15 + 16 + gpio0: gpio@1100 { 17 + compatible = "fsl,mpc5125-gpio"; 18 + #gpio-cells = <2>; 19 + reg = <0x1100 0x080>; 20 + interrupts = <78 0x8>; 21 + status = "okay"; 22 + };
+1
Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt
··· 9 9 - "renesas,gpio-r8a7791": for R8A7791 (R-Car M2-W) compatible GPIO controller. 10 10 - "renesas,gpio-r8a7793": for R8A7793 (R-Car M2-N) compatible GPIO controller. 11 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 13 - "renesas,gpio-rcar": for generic R-Car GPIO controller. 13 14 14 15 - reg: Base address and length of each memory resource used by the GPIO
+24
Documentation/devicetree/bindings/gpio/zx296702-gpio.txt
··· 1 + ZTE ZX296702 GPIO controller 2 + 3 + Required 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 + 12 + gpio1: 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 + };
+3
Documentation/gpio/00-INDEX
··· 6 6 - How to obtain and use GPIOs in a driver 7 7 driver.txt 8 8 - How to write a GPIO driver 9 + drivers-on-gpio.txt: 10 + - Drivers in other subsystems that can use GPIO to provide more 11 + complex functionality. 9 12 board.txt 10 13 - How to assign GPIOs to a consumer device and a function 11 14 sysfs.txt
+33
Documentation/gpio/consumer.txt
··· 237 237 should not have to care about the physical line level. 238 238 239 239 240 + The active-low property 241 + ----------------------- 242 + 243 + As a driver should not have to care about the physical line level, all of the 244 + gpiod_set_value_xxx() or gpiod_set_array_value_xxx() functions operate with 245 + the *logical* value. With this they take the active-low property into account. 246 + This means that they check whether the GPIO is configured to be active-low, 247 + and if so, they manipulate the passed value before the physical line level is 248 + driven. 249 + 250 + With this, all the gpiod_set_(array)_value_xxx() functions interpret the 251 + parameter "value" as "active" ("1") or "inactive" ("0"). The physical line 252 + level will be driven accordingly. 253 + 254 + As an example, if the active-low property for a dedicated GPIO is set, and the 255 + gpiod_set_(array)_value_xxx() passes "active" ("1"), the physical line level 256 + will be driven low. 257 + 258 + To summarize: 259 + 260 + Function (example) active-low proporty physical line 261 + gpiod_set_raw_value(desc, 0); don't care low 262 + gpiod_set_raw_value(desc, 1); don't care high 263 + gpiod_set_value(desc, 0); default (active-high) low 264 + gpiod_set_value(desc, 1); default (active-high) high 265 + gpiod_set_value(desc, 0); active-low high 266 + gpiod_set_value(desc, 1); active-low low 267 + 268 + Please note again that the set_raw/get_raw functions should be avoided as much 269 + as possible, especially by drivers which should not care about the actual 270 + physical line level and worry about the logical value instead. 271 + 272 + 240 273 Set multiple GPIO outputs with a single function call 241 274 ----------------------------------------------------- 242 275 The following functions set the output values of an array of GPIOs:
+95
Documentation/gpio/drivers-on-gpio.txt
··· 1 + Subsystem drivers using GPIO 2 + ============================ 3 + 4 + Note that standard kernel drivers exist for common GPIO tasks and will provide 5 + the right in-kernel and userspace APIs/ABIs for the job, and that these 6 + drivers can quite easily interconnect with other kernel subsystems using 7 + hardware 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 + 86 + Apart from this there are special GPIO drivers in subsystems like MMC/SD to 87 + read card detect and write protect GPIO lines, and in the TTY serial subsystem 88 + to emulate MCTRL (modem control) signals CTS/RTS by using two GPIO lines. The 89 + MTD NOR flash has add-ons for extra GPIO lines too, though the address bus is 90 + usually connected directly to the flash. 91 + 92 + Use those instead of talking directly to the GPIOs using sysfs; they integrate 93 + with kernel frameworks better than your userspace code could. Needless to say, 94 + just using the apropriate kernel drivers will simplify and speed up your 95 + embedded hacking in particular by providing ready-made components.
+4 -5
Documentation/gpio/sysfs.txt
··· 20 20 standard kernels won't know about. And for some tasks, simple userspace 21 21 GPIO drivers could be all that the system really needs. 22 22 23 - Note that standard kernel drivers exist for common "LEDs and Buttons" 24 - GPIO tasks: "leds-gpio" and "gpio_keys", respectively. Use those 25 - instead of talking directly to the GPIOs; they integrate with kernel 26 - frameworks better than your userspace code could. 27 - 23 + DO NOT ABUSE SYFS TO CONTROL HARDWARE THAT HAS PROPER KERNEL DRIVERS. 24 + PLEASE READ THE DOCUMENT NAMED "drivers-on-gpio.txt" IN THIS DOCUMENTATION 25 + DIRECTORY TO AVOID REINVENTING KERNEL WHEELS IN USERSPACE. I MEAN IT. 26 + REALLY. 28 27 29 28 Paths in Sysfs 30 29 --------------
+8 -2
drivers/gpio/Kconfig
··· 113 113 config GPIO_ALTERA 114 114 tristate "Altera GPIO" 115 115 depends on OF_GPIO 116 - select GPIO_GENERIC 117 116 select GPIOLIB_IRQCHIP 118 117 help 119 118 Say Y or M here to build support for the Altera PIO device. ··· 130 131 default y if ARCH_BRCMSTB 131 132 depends on OF_GPIO && (ARCH_BRCMSTB || COMPILE_TEST) 132 133 select GPIO_GENERIC 134 + select GPIOLIB_IRQCHIP 133 135 help 134 136 Say yes here to enable GPIO support for Broadcom STB (BCM7XXX) SoCs. 135 137 ··· 172 172 depends on CRIS || COMPILE_TEST 173 173 depends on OF 174 174 select GPIO_GENERIC 175 + select GPIOLIB_IRQCHIP 175 176 help 176 177 Say yes here to support the GPIO controller on Axis ETRAX FS SoCs. 177 178 ··· 309 308 def_bool y 310 309 depends on PLAT_ORION 311 310 depends on OF 312 - select GPIO_GENERIC 313 311 select GENERIC_IRQ_CHIP 314 312 315 313 config GPIO_MXC ··· 1004 1004 help 1005 1005 SPI driver for Freescale MC33880 high-side/low-side switch. 1006 1006 This provides GPIO interface supporting inputs and outputs. 1007 + 1008 + config 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. 1007 1013 1008 1014 endmenu 1009 1015
+1
drivers/gpio/Makefile
··· 117 117 obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o 118 118 obj-$(CONFIG_GPIO_ZEVIO) += gpio-zevio.o 119 119 obj-$(CONFIG_GPIO_ZYNQ) += gpio-zynq.o 120 + obj-$(CONFIG_GPIO_ZX) += gpio-zx.o
+9 -9
drivers/gpio/devres.c
··· 59 59 * automatically disposed on driver detach. See gpiod_get() for detailed 60 60 * information about behavior and return values. 61 61 */ 62 - struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, 62 + struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, 63 63 const char *con_id, 64 64 enum gpiod_flags flags) 65 65 { 66 66 return devm_gpiod_get_index(dev, con_id, 0, flags); 67 67 } 68 - EXPORT_SYMBOL(__devm_gpiod_get); 68 + EXPORT_SYMBOL(devm_gpiod_get); 69 69 70 70 /** 71 71 * devm_gpiod_get_optional - Resource-managed gpiod_get_optional() ··· 77 77 * are automatically disposed on driver detach. See gpiod_get_optional() for 78 78 * detailed information about behavior and return values. 79 79 */ 80 - struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, 80 + struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, 81 81 const char *con_id, 82 82 enum gpiod_flags flags) 83 83 { 84 84 return devm_gpiod_get_index_optional(dev, con_id, 0, flags); 85 85 } 86 - EXPORT_SYMBOL(__devm_gpiod_get_optional); 86 + EXPORT_SYMBOL(devm_gpiod_get_optional); 87 87 88 88 /** 89 89 * devm_gpiod_get_index - Resource-managed gpiod_get_index() ··· 96 96 * automatically disposed on driver detach. See gpiod_get_index() for detailed 97 97 * information about behavior and return values. 98 98 */ 99 - struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev, 99 + struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, 100 100 const char *con_id, 101 101 unsigned int idx, 102 102 enum gpiod_flags flags) ··· 120 120 121 121 return desc; 122 122 } 123 - EXPORT_SYMBOL(__devm_gpiod_get_index); 123 + EXPORT_SYMBOL(devm_gpiod_get_index); 124 124 125 125 /** 126 126 * devm_get_gpiod_from_child - get a GPIO descriptor from a device's child node ··· 182 182 * gpiod_get_index_optional() for detailed information about behavior and 183 183 * return values. 184 184 */ 185 - struct gpio_desc *__must_check __devm_gpiod_get_index_optional(struct device *dev, 185 + struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev, 186 186 const char *con_id, 187 187 unsigned int index, 188 - enum gpiod_flags flags) 188 + enum gpiod_flags flags) 189 189 { 190 190 struct gpio_desc *desc; 191 191 ··· 197 197 198 198 return desc; 199 199 } 200 - EXPORT_SYMBOL(__devm_gpiod_get_index_optional); 200 + EXPORT_SYMBOL(devm_gpiod_get_index_optional); 201 201 202 202 /** 203 203 * devm_gpiod_get_array - Resource-managed gpiod_get_array()
+1 -1
drivers/gpio/gpio-74xx-mmio.c
··· 129 129 if (IS_ERR(dat)) 130 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 134 err = bgpio_init(&priv->bgc, &pdev->dev, 135 135 DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8),
+1 -9
drivers/gpio/gpio-adp5588.c
··· 305 305 irq_set_chip_and_handler(irq, &adp5588_irq_chip, 306 306 handle_level_irq); 307 307 irq_set_nested_thread(irq, 1); 308 - #ifdef CONFIG_ARM 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 308 + irq_modify_status(irq, IRQ_NOREQUEST, IRQ_NOPROBE); 317 309 } 318 310 319 311 ret = request_threaded_irq(client->irq,
+2 -2
drivers/gpio/gpio-altera.c
··· 338 338 { 339 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 346 346 static const struct of_device_id altera_gpio_of_match[] = {
+1 -16
drivers/gpio/gpio-bcm-kona.c
··· 438 438 void __iomem *reg_base; 439 439 int bit, bank_id; 440 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 442 struct irq_chip *chip = irq_desc_get_chip(desc); 443 443 444 444 chained_irq_enter(chip, desc); ··· 525 525 return ret; 526 526 irq_set_lockdep_class(irq, &gpio_lock_class); 527 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 528 irq_set_noprobe(irq); 532 - #endif 533 529 534 530 return 0; 535 531 } ··· 639 643 if (ret < 0) { 640 644 dev_err(dev, "Couldn't add GPIO chip -- %d\n", ret); 641 645 goto err_irq_domain; 642 - } 643 - for (i = 0; i < chip->ngpio; i++) { 644 - int irq = bcm_kona_gpio_to_irq(chip, i); 645 - irq_set_lockdep_class(irq, &gpio_lock_class); 646 - irq_set_chip_and_handler(irq, &bcm_gpio_irq_chip, 647 - handle_simple_irq); 648 - #ifdef CONFIG_ARM 649 - set_irq_flags(irq, IRQF_VALID); 650 - #else 651 - irq_set_noprobe(irq); 652 - #endif 653 646 } 654 647 for (i = 0; i < kona_gpio->num_bank; i++) { 655 648 bank = &kona_gpio->banks[i];
+300 -6
drivers/gpio/gpio-brcmstb.c
··· 17 17 #include <linux/of_irq.h> 18 18 #include <linux/module.h> 19 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 25 #define GIO_BANK_SIZE 0x20 22 26 #define GIO_ODEN(bank) (((bank) * GIO_BANK_SIZE) + 0x00) ··· 38 34 struct bgpio_chip bgc; 39 35 struct brcmstb_gpio_priv *parent_priv; 40 36 u32 width; 37 + struct irq_chip irq_chip; 41 38 }; 42 39 43 40 struct brcmstb_gpio_priv { 44 41 struct list_head bank_list; 45 42 void __iomem *reg_base; 46 - int num_banks; 47 43 struct platform_device *pdev; 44 + int parent_irq; 48 45 int gpio_base; 46 + bool can_wake; 47 + int parent_wake_irq; 48 + struct notifier_block reboot_notifier; 49 49 }; 50 50 51 51 #define MAX_GPIO_PER_BANK 32 ··· 69 61 { 70 62 struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); 71 63 return bank->parent_priv; 64 + } 65 + 66 + static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank, 67 + unsigned int offset, bool enable) 68 + { 69 + struct bgpio_chip *bgc = &bank->bgc; 70 + struct brcmstb_gpio_priv *priv = bank->parent_priv; 71 + u32 mask = bgc->pin2mask(bgc, offset); 72 + u32 imask; 73 + unsigned long flags; 74 + 75 + spin_lock_irqsave(&bgc->lock, flags); 76 + imask = bgc->read_reg(priv->reg_base + GIO_MASK(bank->id)); 77 + if (enable) 78 + imask |= mask; 79 + else 80 + imask &= ~mask; 81 + bgc->write_reg(priv->reg_base + GIO_MASK(bank->id), imask); 82 + spin_unlock_irqrestore(&bgc->lock, flags); 83 + } 84 + 85 + /* -------------------- IRQ chip functions -------------------- */ 86 + 87 + static void brcmstb_gpio_irq_mask(struct irq_data *d) 88 + { 89 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 90 + struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); 91 + 92 + brcmstb_gpio_set_imask(bank, d->hwirq, false); 93 + } 94 + 95 + static void brcmstb_gpio_irq_unmask(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, true); 101 + } 102 + 103 + static int brcmstb_gpio_irq_set_type(struct irq_data *d, unsigned int type) 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 + struct brcmstb_gpio_priv *priv = bank->parent_priv; 108 + u32 mask = BIT(d->hwirq); 109 + u32 edge_insensitive, iedge_insensitive; 110 + u32 edge_config, iedge_config; 111 + u32 level, ilevel; 112 + unsigned long flags; 113 + 114 + switch (type) { 115 + case IRQ_TYPE_LEVEL_LOW: 116 + level = 0; 117 + edge_config = 0; 118 + edge_insensitive = 0; 119 + break; 120 + case IRQ_TYPE_LEVEL_HIGH: 121 + level = mask; 122 + edge_config = 0; 123 + edge_insensitive = 0; 124 + break; 125 + case IRQ_TYPE_EDGE_FALLING: 126 + level = 0; 127 + edge_config = 0; 128 + edge_insensitive = 0; 129 + break; 130 + case IRQ_TYPE_EDGE_RISING: 131 + level = 0; 132 + edge_config = mask; 133 + edge_insensitive = 0; 134 + break; 135 + case IRQ_TYPE_EDGE_BOTH: 136 + level = 0; 137 + edge_config = 0; /* don't care, but want known value */ 138 + edge_insensitive = mask; 139 + break; 140 + default: 141 + return -EINVAL; 142 + } 143 + 144 + spin_lock_irqsave(&bank->bgc.lock, flags); 145 + 146 + iedge_config = bank->bgc.read_reg(priv->reg_base + 147 + GIO_EC(bank->id)) & ~mask; 148 + iedge_insensitive = bank->bgc.read_reg(priv->reg_base + 149 + GIO_EI(bank->id)) & ~mask; 150 + ilevel = bank->bgc.read_reg(priv->reg_base + 151 + GIO_LEVEL(bank->id)) & ~mask; 152 + 153 + bank->bgc.write_reg(priv->reg_base + GIO_EC(bank->id), 154 + iedge_config | edge_config); 155 + bank->bgc.write_reg(priv->reg_base + GIO_EI(bank->id), 156 + iedge_insensitive | edge_insensitive); 157 + bank->bgc.write_reg(priv->reg_base + GIO_LEVEL(bank->id), 158 + ilevel | level); 159 + 160 + spin_unlock_irqrestore(&bank->bgc.lock, flags); 161 + return 0; 162 + } 163 + 164 + static int brcmstb_gpio_priv_set_wake(struct brcmstb_gpio_priv *priv, 165 + unsigned int enable) 166 + { 167 + int ret = 0; 168 + 169 + /* 170 + * Only enable wake IRQ once for however many hwirqs can wake 171 + * since they all use the same wake IRQ. Mask will be set 172 + * up appropriately thanks to IRQCHIP_MASK_ON_SUSPEND flag. 173 + */ 174 + if (enable) 175 + ret = enable_irq_wake(priv->parent_wake_irq); 176 + else 177 + ret = disable_irq_wake(priv->parent_wake_irq); 178 + if (ret) 179 + dev_err(&priv->pdev->dev, "failed to %s wake-up interrupt\n", 180 + enable ? "enable" : "disable"); 181 + return ret; 182 + } 183 + 184 + static int brcmstb_gpio_irq_set_wake(struct irq_data *d, unsigned int enable) 185 + { 186 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 187 + struct brcmstb_gpio_priv *priv = brcmstb_gpio_gc_to_priv(gc); 188 + 189 + return brcmstb_gpio_priv_set_wake(priv, enable); 190 + } 191 + 192 + static irqreturn_t brcmstb_gpio_wake_irq_handler(int irq, void *data) 193 + { 194 + struct brcmstb_gpio_priv *priv = data; 195 + 196 + if (!priv || irq != priv->parent_wake_irq) 197 + return IRQ_NONE; 198 + pm_wakeup_event(&priv->pdev->dev, 0); 199 + return IRQ_HANDLED; 200 + } 201 + 202 + static void brcmstb_gpio_irq_bank_handler(struct brcmstb_gpio_bank *bank) 203 + { 204 + struct brcmstb_gpio_priv *priv = bank->parent_priv; 205 + struct irq_domain *irq_domain = bank->bgc.gc.irqdomain; 206 + void __iomem *reg_base = priv->reg_base; 207 + unsigned long status; 208 + unsigned long flags; 209 + 210 + spin_lock_irqsave(&bank->bgc.lock, flags); 211 + while ((status = bank->bgc.read_reg(reg_base + GIO_STAT(bank->id)) & 212 + bank->bgc.read_reg(reg_base + GIO_MASK(bank->id)))) { 213 + int bit; 214 + 215 + for_each_set_bit(bit, &status, 32) { 216 + u32 stat = bank->bgc.read_reg(reg_base + 217 + GIO_STAT(bank->id)); 218 + if (bit >= bank->width) 219 + dev_warn(&priv->pdev->dev, 220 + "IRQ for invalid GPIO (bank=%d, offset=%d)\n", 221 + bank->id, bit); 222 + bank->bgc.write_reg(reg_base + GIO_STAT(bank->id), 223 + stat | BIT(bit)); 224 + generic_handle_irq(irq_find_mapping(irq_domain, bit)); 225 + } 226 + } 227 + spin_unlock_irqrestore(&bank->bgc.lock, flags); 228 + } 229 + 230 + /* Each UPG GIO block has one IRQ for all banks */ 231 + static void brcmstb_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) 232 + { 233 + struct gpio_chip *gc = irq_desc_get_handler_data(desc); 234 + struct brcmstb_gpio_priv *priv = brcmstb_gpio_gc_to_priv(gc); 235 + struct irq_chip *chip = irq_desc_get_chip(desc); 236 + struct list_head *pos; 237 + 238 + /* Interrupts weren't properly cleared during probe */ 239 + BUG_ON(!priv || !chip); 240 + 241 + chained_irq_enter(chip, desc); 242 + list_for_each(pos, &priv->bank_list) { 243 + struct brcmstb_gpio_bank *bank = 244 + list_entry(pos, struct brcmstb_gpio_bank, node); 245 + brcmstb_gpio_irq_bank_handler(bank); 246 + } 247 + chained_irq_exit(chip, desc); 248 + } 249 + 250 + static int brcmstb_gpio_reboot(struct notifier_block *nb, 251 + unsigned long action, void *data) 252 + { 253 + struct brcmstb_gpio_priv *priv = 254 + container_of(nb, struct brcmstb_gpio_priv, reboot_notifier); 255 + 256 + /* Enable GPIO for S5 cold boot */ 257 + if (action == SYS_POWER_OFF) 258 + brcmstb_gpio_priv_set_wake(priv, 1); 259 + 260 + return NOTIFY_DONE; 72 261 } 73 262 74 263 /* Make sure that the number of banks matches up between properties */ ··· 305 100 bank = list_entry(pos, struct brcmstb_gpio_bank, node); 306 101 ret = bgpio_remove(&bank->bgc); 307 102 if (ret) 308 - dev_err(&pdev->dev, "gpiochip_remove fail in cleanup"); 103 + dev_err(&pdev->dev, "gpiochip_remove fail in cleanup\n"); 104 + } 105 + if (priv->reboot_notifier.notifier_call) { 106 + ret = unregister_reboot_notifier(&priv->reboot_notifier); 107 + if (ret) 108 + dev_err(&pdev->dev, 109 + "failed to unregister reboot notifier\n"); 309 110 } 310 111 return ret; 311 112 } ··· 332 121 return -EINVAL; 333 122 334 123 offset = gpiospec->args[0] - (gc->base - priv->gpio_base); 335 - if (offset >= gc->ngpio) 124 + if (offset >= gc->ngpio || offset < 0) 336 125 return -EINVAL; 337 126 338 127 if (unlikely(offset >= bank->width)) { ··· 347 136 return offset; 348 137 } 349 138 139 + /* Before calling, must have bank->parent_irq set and gpiochip registered */ 140 + static int brcmstb_gpio_irq_setup(struct platform_device *pdev, 141 + struct brcmstb_gpio_bank *bank) 142 + { 143 + struct brcmstb_gpio_priv *priv = bank->parent_priv; 144 + struct device *dev = &pdev->dev; 145 + struct device_node *np = dev->of_node; 146 + 147 + bank->irq_chip.name = dev_name(dev); 148 + bank->irq_chip.irq_mask = brcmstb_gpio_irq_mask; 149 + bank->irq_chip.irq_unmask = brcmstb_gpio_irq_unmask; 150 + bank->irq_chip.irq_set_type = brcmstb_gpio_irq_set_type; 151 + 152 + /* Ensures that all non-wakeup IRQs are disabled at suspend */ 153 + bank->irq_chip.flags = IRQCHIP_MASK_ON_SUSPEND; 154 + 155 + if (IS_ENABLED(CONFIG_PM_SLEEP) && !priv->can_wake && 156 + of_property_read_bool(np, "wakeup-source")) { 157 + priv->parent_wake_irq = platform_get_irq(pdev, 1); 158 + if (priv->parent_wake_irq < 0) { 159 + dev_warn(dev, 160 + "Couldn't get wake IRQ - GPIOs will not be able to wake from sleep"); 161 + } else { 162 + int err; 163 + 164 + /* 165 + * Set wakeup capability before requesting wakeup 166 + * interrupt, so we can process boot-time "wakeups" 167 + * (e.g., from S5 cold boot) 168 + */ 169 + device_set_wakeup_capable(dev, true); 170 + device_wakeup_enable(dev); 171 + err = devm_request_irq(dev, priv->parent_wake_irq, 172 + brcmstb_gpio_wake_irq_handler, 0, 173 + "brcmstb-gpio-wake", priv); 174 + 175 + if (err < 0) { 176 + dev_err(dev, "Couldn't request wake IRQ"); 177 + return err; 178 + } 179 + 180 + priv->reboot_notifier.notifier_call = 181 + brcmstb_gpio_reboot; 182 + register_reboot_notifier(&priv->reboot_notifier); 183 + priv->can_wake = true; 184 + } 185 + } 186 + 187 + if (priv->can_wake) 188 + bank->irq_chip.irq_set_wake = brcmstb_gpio_irq_set_wake; 189 + 190 + gpiochip_irqchip_add(&bank->bgc.gc, &bank->irq_chip, 0, 191 + handle_simple_irq, IRQ_TYPE_NONE); 192 + gpiochip_set_chained_irqchip(&bank->bgc.gc, &bank->irq_chip, 193 + priv->parent_irq, brcmstb_gpio_irq_handler); 194 + 195 + return 0; 196 + } 197 + 350 198 static int brcmstb_gpio_probe(struct platform_device *pdev) 351 199 { 352 200 struct device *dev = &pdev->dev; ··· 416 146 struct property *prop; 417 147 const __be32 *p; 418 148 u32 bank_width; 149 + int num_banks = 0; 419 150 int err; 420 151 static int gpio_base; 421 152 ··· 435 164 priv->reg_base = reg_base; 436 165 priv->pdev = pdev; 437 166 167 + if (of_property_read_bool(np, "interrupt-controller")) { 168 + priv->parent_irq = platform_get_irq(pdev, 0); 169 + if (priv->parent_irq <= 0) { 170 + dev_err(dev, "Couldn't get IRQ"); 171 + return -ENOENT; 172 + } 173 + } else { 174 + priv->parent_irq = -ENOENT; 175 + } 176 + 438 177 if (brcmstb_gpio_sanity_check_banks(dev, np, res)) 439 178 return -EINVAL; 440 179 ··· 461 180 } 462 181 463 182 bank->parent_priv = priv; 464 - bank->id = priv->num_banks; 183 + bank->id = num_banks; 465 184 if (bank_width <= 0 || bank_width > MAX_GPIO_PER_BANK) { 466 185 dev_err(dev, "Invalid bank width %d\n", bank_width); 467 186 goto fail; ··· 493 212 /* not all ngpio lines are valid, will use bank width later */ 494 213 gc->ngpio = MAX_GPIO_PER_BANK; 495 214 215 + /* 216 + * Mask all interrupts by default, since wakeup interrupts may 217 + * be retained from S5 cold boot 218 + */ 219 + bank->bgc.write_reg(reg_base + GIO_MASK(bank->id), 0); 220 + 496 221 err = gpiochip_add(gc); 497 222 if (err) { 498 223 dev_err(dev, "Could not add gpiochip for bank %d\n", ··· 506 219 goto fail; 507 220 } 508 221 gpio_base += gc->ngpio; 222 + 223 + if (priv->parent_irq > 0) { 224 + err = brcmstb_gpio_irq_setup(pdev, bank); 225 + if (err) 226 + goto fail; 227 + } 228 + 509 229 dev_dbg(dev, "bank=%d, base=%d, ngpio=%d, width=%d\n", bank->id, 510 230 gc->base, gc->ngpio, bank->width); 511 231 512 232 /* Everything looks good, so add bank to list */ 513 233 list_add(&bank->node, &priv->bank_list); 514 234 515 - priv->num_banks++; 235 + num_banks++; 516 236 } 517 237 518 238 dev_info(dev, "Registered %d banks (GPIO(s): %d-%d)\n", 519 - priv->num_banks, priv->gpio_base, gpio_base - 1); 239 + num_banks, priv->gpio_base, gpio_base - 1); 520 240 521 241 return 0; 522 242
+8 -8
drivers/gpio/gpio-davinci.c
··· 65 65 return ptr; 66 66 } 67 67 68 - static inline struct davinci_gpio_regs __iomem *irq2regs(int irq) 68 + static inline struct davinci_gpio_regs __iomem *irq2regs(struct irq_data *d) 69 69 { 70 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 74 return g; 75 75 } ··· 287 287 288 288 static 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 291 u32 mask = (u32) irq_data_get_irq_handler_data(d); 292 292 293 293 writel_relaxed(mask, &g->clr_falling); ··· 296 296 297 297 static 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 300 u32 mask = (u32) irq_data_get_irq_handler_data(d); 301 301 unsigned status = irqd_get_trigger_type(d); 302 302 ··· 327 327 }; 328 328 329 329 static void 330 - gpio_irq_handler(unsigned irq, struct irq_desc *desc) 330 + gpio_irq_handler(unsigned __irq, struct irq_desc *desc) 331 331 { 332 + unsigned int irq = irq_desc_get_irq(desc); 332 333 struct davinci_gpio_regs __iomem *g; 333 334 u32 mask = 0xffff; 334 335 struct davinci_gpio_controller *d; ··· 397 396 struct davinci_gpio_regs __iomem *g; 398 397 u32 mask; 399 398 400 - d = (struct davinci_gpio_controller *)data->handler_data; 399 + d = (struct davinci_gpio_controller *)irq_data_get_irq_handler_data(data); 401 400 g = (struct davinci_gpio_regs __iomem *)d->regs; 402 401 mask = __gpio_mask(data->irq - d->gpio_irq); 403 402 ··· 423 422 irq_set_irq_type(irq, IRQ_TYPE_NONE); 424 423 irq_set_chip_data(irq, (__force void *)g); 425 424 irq_set_handler_data(irq, (void *)__gpio_mask(hw)); 426 - set_irq_flags(irq, IRQF_VALID); 427 425 428 426 return 0; 429 427 } ··· 545 545 chips[0].chip.to_irq = gpio_to_irq_unbanked; 546 546 chips[0].gpio_irq = bank_irq; 547 547 chips[0].gpio_unbanked = pdata->gpio_unbanked; 548 - binten = BIT(0); 548 + binten = GENMASK(pdata->gpio_unbanked / 16, 0); 549 549 550 550 /* AINTC handles mask/unmask; GPIO handles triggering */ 551 551 irq = bank_irq;
+1 -1
drivers/gpio/gpio-dwapb.c
··· 149 149 150 150 static 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 153 struct irq_chip *chip = irq_desc_get_chip(desc); 154 154 155 155 dwapb_do_irq(gpio);
+8 -27
drivers/gpio/gpio-em.c
··· 31 31 #include <linux/slab.h> 32 32 #include <linux/module.h> 33 33 #include <linux/pinctrl/consumer.h> 34 - #include <linux/platform_data/gpio-em.h> 35 34 36 35 struct em_gio_priv { 37 36 void __iomem *base0; ··· 261 262 262 263 irq_set_chip_data(irq, h->host_data); 263 264 irq_set_chip_and_handler(irq, &p->irq_chip, handle_level_irq); 264 - set_irq_flags(irq, IRQF_VALID); /* kill me now */ 265 265 return 0; 266 266 } 267 267 ··· 271 273 272 274 static int em_gio_probe(struct platform_device *pdev) 273 275 { 274 - struct gpio_em_config pdata_dt; 275 - struct gpio_em_config *pdata = dev_get_platdata(&pdev->dev); 276 276 struct em_gio_priv *p; 277 277 struct resource *io[2], *irq[2]; 278 278 struct gpio_chip *gpio_chip; 279 279 struct irq_chip *irq_chip; 280 280 const char *name = dev_name(&pdev->dev); 281 + unsigned int ngpios; 281 282 int ret; 282 283 283 284 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); ··· 316 319 goto err0; 317 320 } 318 321 319 - if (!pdata) { 320 - memset(&pdata_dt, 0, sizeof(pdata_dt)); 321 - pdata = &pdata_dt; 322 - 323 - if (of_property_read_u32(pdev->dev.of_node, "ngpios", 324 - &pdata->number_of_pins)) { 325 - dev_err(&pdev->dev, "Missing ngpios OF property\n"); 326 - ret = -EINVAL; 327 - goto err0; 328 - } 329 - 330 - pdata->gpio_base = -1; 322 + if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) { 323 + dev_err(&pdev->dev, "Missing ngpios OF property\n"); 324 + ret = -EINVAL; 325 + goto err0; 331 326 } 332 327 333 328 gpio_chip = &p->gpio_chip; ··· 334 345 gpio_chip->label = name; 335 346 gpio_chip->dev = &pdev->dev; 336 347 gpio_chip->owner = THIS_MODULE; 337 - gpio_chip->base = pdata->gpio_base; 338 - gpio_chip->ngpio = pdata->number_of_pins; 348 + gpio_chip->base = -1; 349 + gpio_chip->ngpio = ngpios; 339 350 340 351 irq_chip = &p->irq_chip; 341 352 irq_chip->name = name; ··· 346 357 irq_chip->irq_release_resources = em_gio_irq_relres; 347 358 irq_chip->flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND; 348 359 349 - p->irq_domain = irq_domain_add_simple(pdev->dev.of_node, 350 - pdata->number_of_pins, 351 - pdata->irq_base, 360 + p->irq_domain = irq_domain_add_simple(pdev->dev.of_node, ngpios, 0, 352 361 &em_gio_irq_domain_ops, p); 353 362 if (!p->irq_domain) { 354 363 ret = -ENXIO; ··· 374 387 goto err1; 375 388 } 376 389 377 - if (pdata->pctl_name) { 378 - ret = gpiochip_add_pin_range(gpio_chip, pdata->pctl_name, 0, 379 - gpio_chip->base, gpio_chip->ngpio); 380 - if (ret < 0) 381 - dev_warn(&pdev->dev, "failed to add pin range\n"); 382 - } 383 390 return 0; 384 391 385 392 err1:
+5 -3
drivers/gpio/gpio-ep93xx.c
··· 100 100 } 101 101 } 102 102 103 - static void ep93xx_gpio_f_irq_handler(unsigned int irq, struct irq_desc *desc) 103 + static void ep93xx_gpio_f_irq_handler(unsigned int __irq, 104 + struct irq_desc *desc) 104 105 { 105 106 /* 106 107 * map discontiguous hw irq range to continuous sw irq range: 107 108 * 108 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 112 int port_f_idx = ((irq + 1) & 7) ^ 4; /* {19..22,47..50} -> {0..7} */ 111 113 int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_F(0)) + port_f_idx; 112 114 ··· 210 208 return -EINVAL; 211 209 } 212 210 213 - __irq_set_handler_locked(d->irq, handler); 211 + irq_set_handler_locked(d, handler); 214 212 215 213 gpio_int_enabled[port] |= port_mask; 216 214 ··· 236 234 gpio_irq <= gpio_to_irq(EP93XX_GPIO_LINE_MAX_IRQ); ++gpio_irq) { 237 235 irq_set_chip_and_handler(gpio_irq, &ep93xx_gpio_irq_chip, 238 236 handle_level_irq); 239 - set_irq_flags(gpio_irq, IRQF_VALID); 237 + irq_clear_status_flags(gpio_irq, IRQ_NOREQUEST); 240 238 } 241 239 242 240 irq_set_chained_handler(IRQ_EP93XX_GPIO_AB,
+314 -15
drivers/gpio/gpio-etraxfs.c
··· 1 1 #include <linux/kernel.h> 2 2 #include <linux/init.h> 3 3 #include <linux/gpio.h> 4 + #include <linux/gpio/driver.h> 4 5 #include <linux/of_gpio.h> 5 6 #include <linux/io.h> 7 + #include <linux/interrupt.h> 6 8 #include <linux/platform_device.h> 7 9 #include <linux/basic_mmio_gpio.h> 8 10 ··· 15 13 #define ETRAX_FS_rw_intr_mask 16 16 14 #define ETRAX_FS_rw_ack_intr 20 17 15 #define ETRAX_FS_r_intr 24 16 + #define ETRAX_FS_r_masked_intr 28 18 17 #define ETRAX_FS_rw_pb_dout 32 19 18 #define ETRAX_FS_r_pb_din 36 20 19 #define ETRAX_FS_rw_pb_oe 40 ··· 29 26 #define ETRAX_FS_r_pe_din 84 30 27 #define ETRAX_FS_rw_pe_oe 88 31 28 29 + #define ARTPEC3_r_pa_din 0 30 + #define ARTPEC3_rw_pa_dout 4 31 + #define ARTPEC3_rw_pa_oe 8 32 + #define ARTPEC3_r_pb_din 44 33 + #define ARTPEC3_rw_pb_dout 48 34 + #define ARTPEC3_rw_pb_oe 52 35 + #define ARTPEC3_r_pc_din 88 36 + #define ARTPEC3_rw_pc_dout 92 37 + #define ARTPEC3_rw_pc_oe 96 38 + #define ARTPEC3_r_pd_din 116 39 + #define ARTPEC3_rw_intr_cfg 120 40 + #define ARTPEC3_rw_intr_pins 124 41 + #define ARTPEC3_rw_intr_mask 128 42 + #define ARTPEC3_rw_ack_intr 132 43 + #define ARTPEC3_r_masked_intr 140 44 + 45 + #define GIO_CFG_OFF 0 46 + #define GIO_CFG_HI 1 47 + #define GIO_CFG_LO 2 48 + #define GIO_CFG_SET 3 49 + #define GIO_CFG_POSEDGE 5 50 + #define GIO_CFG_NEGEDGE 6 51 + #define GIO_CFG_ANYEDGE 7 52 + 53 + struct etraxfs_gpio_info; 54 + 55 + struct etraxfs_gpio_block { 56 + spinlock_t lock; 57 + u32 mask; 58 + u32 cfg; 59 + u32 pins; 60 + unsigned int group[8]; 61 + 62 + void __iomem *regs; 63 + const struct etraxfs_gpio_info *info; 64 + }; 65 + 66 + struct etraxfs_gpio_chip { 67 + struct bgpio_chip bgc; 68 + struct etraxfs_gpio_block *block; 69 + }; 70 + 32 71 struct etraxfs_gpio_port { 33 72 const char *label; 34 73 unsigned int oe; ··· 82 37 struct etraxfs_gpio_info { 83 38 unsigned int num_ports; 84 39 const struct etraxfs_gpio_port *ports; 40 + 41 + unsigned int rw_ack_intr; 42 + unsigned int rw_intr_mask; 43 + unsigned int rw_intr_cfg; 44 + unsigned int rw_intr_pins; 45 + unsigned int r_masked_intr; 85 46 }; 86 47 87 48 static const struct etraxfs_gpio_port etraxfs_gpio_etraxfs_ports[] = { ··· 131 80 static const struct etraxfs_gpio_info etraxfs_gpio_etraxfs = { 132 81 .num_ports = ARRAY_SIZE(etraxfs_gpio_etraxfs_ports), 133 82 .ports = etraxfs_gpio_etraxfs_ports, 83 + .rw_ack_intr = ETRAX_FS_rw_ack_intr, 84 + .rw_intr_mask = ETRAX_FS_rw_intr_mask, 85 + .rw_intr_cfg = ETRAX_FS_rw_intr_cfg, 86 + .r_masked_intr = ETRAX_FS_r_masked_intr, 134 87 }; 88 + 89 + static const struct etraxfs_gpio_port etraxfs_gpio_artpec3_ports[] = { 90 + { 91 + .label = "A", 92 + .ngpio = 32, 93 + .oe = ARTPEC3_rw_pa_oe, 94 + .dout = ARTPEC3_rw_pa_dout, 95 + .din = ARTPEC3_r_pa_din, 96 + }, 97 + { 98 + .label = "B", 99 + .ngpio = 32, 100 + .oe = ARTPEC3_rw_pb_oe, 101 + .dout = ARTPEC3_rw_pb_dout, 102 + .din = ARTPEC3_r_pb_din, 103 + }, 104 + { 105 + .label = "C", 106 + .ngpio = 16, 107 + .oe = ARTPEC3_rw_pc_oe, 108 + .dout = ARTPEC3_rw_pc_dout, 109 + .din = ARTPEC3_r_pc_din, 110 + }, 111 + { 112 + .label = "D", 113 + .ngpio = 32, 114 + .din = ARTPEC3_r_pd_din, 115 + }, 116 + }; 117 + 118 + static const struct etraxfs_gpio_info etraxfs_gpio_artpec3 = { 119 + .num_ports = ARRAY_SIZE(etraxfs_gpio_artpec3_ports), 120 + .ports = etraxfs_gpio_artpec3_ports, 121 + .rw_ack_intr = ARTPEC3_rw_ack_intr, 122 + .rw_intr_mask = ARTPEC3_rw_intr_mask, 123 + .rw_intr_cfg = ARTPEC3_rw_intr_cfg, 124 + .r_masked_intr = ARTPEC3_r_masked_intr, 125 + .rw_intr_pins = ARTPEC3_rw_intr_pins, 126 + }; 127 + 128 + static unsigned int etraxfs_gpio_chip_to_port(struct gpio_chip *gc) 129 + { 130 + return gc->label[0] - 'A'; 131 + } 135 132 136 133 static int etraxfs_gpio_of_xlate(struct gpio_chip *gc, 137 134 const struct of_phandle_args *gpiospec, ··· 189 90 * Port numbers are A to E, and the properties are integers, so we 190 91 * specify them as 0xA - 0xE. 191 92 */ 192 - if (gc->label[0] - 'A' + 0xA != gpiospec->args[2]) 93 + if (etraxfs_gpio_chip_to_port(gc) + 0xA != gpiospec->args[2]) 193 94 return -EINVAL; 194 95 195 96 return of_gpio_simple_xlate(gc, gpiospec, flags); ··· 200 101 .compatible = "axis,etraxfs-gio", 201 102 .data = &etraxfs_gpio_etraxfs, 202 103 }, 104 + { 105 + .compatible = "axis,artpec3-gio", 106 + .data = &etraxfs_gpio_artpec3, 107 + }, 203 108 {}, 204 109 }; 110 + 111 + static unsigned int etraxfs_gpio_to_group_irq(unsigned int gpio) 112 + { 113 + return gpio % 8; 114 + } 115 + 116 + static unsigned int etraxfs_gpio_to_group_pin(struct etraxfs_gpio_chip *chip, 117 + unsigned int gpio) 118 + { 119 + return 4 * etraxfs_gpio_chip_to_port(&chip->bgc.gc) + gpio / 8; 120 + } 121 + 122 + static void etraxfs_gpio_irq_ack(struct irq_data *d) 123 + { 124 + struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d); 125 + struct etraxfs_gpio_block *block = chip->block; 126 + unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 127 + 128 + writel(BIT(grpirq), block->regs + block->info->rw_ack_intr); 129 + } 130 + 131 + static void etraxfs_gpio_irq_mask(struct irq_data *d) 132 + { 133 + struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d); 134 + struct etraxfs_gpio_block *block = chip->block; 135 + unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 136 + 137 + spin_lock(&block->lock); 138 + block->mask &= ~BIT(grpirq); 139 + writel(block->mask, block->regs + block->info->rw_intr_mask); 140 + spin_unlock(&block->lock); 141 + } 142 + 143 + static void etraxfs_gpio_irq_unmask(struct irq_data *d) 144 + { 145 + struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d); 146 + struct etraxfs_gpio_block *block = chip->block; 147 + unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 148 + 149 + spin_lock(&block->lock); 150 + block->mask |= BIT(grpirq); 151 + writel(block->mask, block->regs + block->info->rw_intr_mask); 152 + spin_unlock(&block->lock); 153 + } 154 + 155 + static int etraxfs_gpio_irq_set_type(struct irq_data *d, u32 type) 156 + { 157 + struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d); 158 + struct etraxfs_gpio_block *block = chip->block; 159 + unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 160 + u32 cfg; 161 + 162 + switch (type) { 163 + case IRQ_TYPE_EDGE_RISING: 164 + cfg = GIO_CFG_POSEDGE; 165 + break; 166 + case IRQ_TYPE_EDGE_FALLING: 167 + cfg = GIO_CFG_NEGEDGE; 168 + break; 169 + case IRQ_TYPE_EDGE_BOTH: 170 + cfg = GIO_CFG_ANYEDGE; 171 + break; 172 + case IRQ_TYPE_LEVEL_LOW: 173 + cfg = GIO_CFG_LO; 174 + break; 175 + case IRQ_TYPE_LEVEL_HIGH: 176 + cfg = GIO_CFG_HI; 177 + break; 178 + default: 179 + return -EINVAL; 180 + } 181 + 182 + spin_lock(&block->lock); 183 + block->cfg &= ~(0x7 << (grpirq * 3)); 184 + block->cfg |= (cfg << (grpirq * 3)); 185 + writel(block->cfg, block->regs + block->info->rw_intr_cfg); 186 + spin_unlock(&block->lock); 187 + 188 + return 0; 189 + } 190 + 191 + static int etraxfs_gpio_irq_request_resources(struct irq_data *d) 192 + { 193 + struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d); 194 + struct etraxfs_gpio_block *block = chip->block; 195 + unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 196 + int ret = -EBUSY; 197 + 198 + spin_lock(&block->lock); 199 + if (block->group[grpirq]) 200 + goto out; 201 + 202 + ret = gpiochip_lock_as_irq(&chip->bgc.gc, d->hwirq); 203 + if (ret) 204 + goto out; 205 + 206 + block->group[grpirq] = d->irq; 207 + if (block->info->rw_intr_pins) { 208 + unsigned int pin = etraxfs_gpio_to_group_pin(chip, d->hwirq); 209 + 210 + block->pins &= ~(0xf << (grpirq * 4)); 211 + block->pins |= (pin << (grpirq * 4)); 212 + 213 + writel(block->pins, block->regs + block->info->rw_intr_pins); 214 + } 215 + 216 + out: 217 + spin_unlock(&block->lock); 218 + return ret; 219 + } 220 + 221 + static void etraxfs_gpio_irq_release_resources(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 + spin_lock(&block->lock); 228 + block->group[grpirq] = 0; 229 + gpiochip_unlock_as_irq(&chip->bgc.gc, d->hwirq); 230 + spin_unlock(&block->lock); 231 + } 232 + 233 + static struct irq_chip etraxfs_gpio_irq_chip = { 234 + .name = "gpio-etraxfs", 235 + .irq_ack = etraxfs_gpio_irq_ack, 236 + .irq_mask = etraxfs_gpio_irq_mask, 237 + .irq_unmask = etraxfs_gpio_irq_unmask, 238 + .irq_set_type = etraxfs_gpio_irq_set_type, 239 + .irq_request_resources = etraxfs_gpio_irq_request_resources, 240 + .irq_release_resources = etraxfs_gpio_irq_release_resources, 241 + }; 242 + 243 + static irqreturn_t etraxfs_gpio_interrupt(int irq, void *dev_id) 244 + { 245 + struct etraxfs_gpio_block *block = dev_id; 246 + unsigned long intr = readl(block->regs + block->info->r_masked_intr); 247 + int bit; 248 + 249 + for_each_set_bit(bit, &intr, 8) 250 + generic_handle_irq(block->group[bit]); 251 + 252 + return IRQ_RETVAL(intr & 0xff); 253 + } 205 254 206 255 static int etraxfs_gpio_probe(struct platform_device *pdev) 207 256 { 208 257 struct device *dev = &pdev->dev; 209 258 const struct etraxfs_gpio_info *info; 210 259 const struct of_device_id *match; 211 - struct bgpio_chip *chips; 212 - struct resource *res; 260 + struct etraxfs_gpio_block *block; 261 + struct etraxfs_gpio_chip *chips; 262 + struct resource *res, *irq; 263 + bool allportsirq = false; 213 264 void __iomem *regs; 214 265 int ret; 215 266 int i; 216 267 217 268 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 218 269 regs = devm_ioremap_resource(dev, res); 219 - if (!regs) 220 - return -ENOMEM; 270 + if (IS_ERR(regs)) 271 + return PTR_ERR(regs); 221 272 222 273 match = of_match_node(etraxfs_gpio_of_table, dev->of_node); 223 274 if (!match) ··· 379 130 if (!chips) 380 131 return -ENOMEM; 381 132 133 + irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 134 + if (!irq) 135 + return -EINVAL; 136 + 137 + block = devm_kzalloc(dev, sizeof(*block), GFP_KERNEL); 138 + if (!block) 139 + return -ENOMEM; 140 + 141 + spin_lock_init(&block->lock); 142 + 143 + block->regs = regs; 144 + block->info = info; 145 + 146 + writel(0, block->regs + info->rw_intr_mask); 147 + writel(0, block->regs + info->rw_intr_cfg); 148 + if (info->rw_intr_pins) { 149 + allportsirq = true; 150 + writel(0, block->regs + info->rw_intr_pins); 151 + } 152 + 153 + ret = devm_request_irq(dev, irq->start, etraxfs_gpio_interrupt, 154 + IRQF_SHARED, dev_name(dev), block); 155 + if (ret) { 156 + dev_err(dev, "Unable to request irq %d\n", ret); 157 + return ret; 158 + } 159 + 382 160 for (i = 0; i < info->num_ports; i++) { 383 - struct bgpio_chip *bgc = &chips[i]; 161 + struct etraxfs_gpio_chip *chip = &chips[i]; 162 + struct bgpio_chip *bgc = &chip->bgc; 384 163 const struct etraxfs_gpio_port *port = &info->ports[i]; 164 + unsigned long flags = BGPIOF_READ_OUTPUT_REG_SET; 165 + void __iomem *dat = regs + port->din; 166 + void __iomem *set = regs + port->dout; 167 + void __iomem *dirout = regs + port->oe; 168 + 169 + chip->block = block; 170 + 171 + if (dirout == set) { 172 + dirout = set = NULL; 173 + flags = BGPIOF_NO_OUTPUT; 174 + } 385 175 386 176 ret = bgpio_init(bgc, dev, 4, 387 - regs + port->din, /* dat */ 388 - regs + port->dout, /* set */ 389 - NULL, /* clr */ 390 - regs + port->oe, /* dirout */ 391 - NULL, /* dirin */ 392 - BGPIOF_UNREADABLE_REG_SET); 393 - if (ret) 394 - return ret; 177 + dat, set, NULL, dirout, NULL, 178 + flags); 179 + if (ret) { 180 + dev_err(dev, "Unable to init port %s\n", 181 + port->label); 182 + continue; 183 + } 395 184 396 185 bgc->gc.ngpio = port->ngpio; 397 186 bgc->gc.label = port->label; ··· 439 152 bgc->gc.of_xlate = etraxfs_gpio_of_xlate; 440 153 441 154 ret = gpiochip_add(&bgc->gc); 442 - if (ret) 155 + if (ret) { 443 156 dev_err(dev, "Unable to register port %s\n", 444 157 bgc->gc.label); 158 + continue; 159 + } 160 + 161 + if (i > 0 && !allportsirq) 162 + continue; 163 + 164 + ret = gpiochip_irqchip_add(&bgc->gc, &etraxfs_gpio_irq_chip, 0, 165 + handle_level_irq, IRQ_TYPE_NONE); 166 + if (ret) { 167 + dev_err(dev, "Unable to add irqchip to port %s\n", 168 + bgc->gc.label); 169 + } 445 170 } 446 171 447 172 return 0;
+38 -3
drivers/gpio/gpio-generic.c
··· 153 153 return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio)); 154 154 } 155 155 156 + static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val) 157 + { 158 + } 159 + 156 160 static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 157 161 { 158 162 struct bgpio_chip *bgc = to_bgpio_chip(gc); ··· 283 279 return 0; 284 280 } 285 281 282 + static int bgpio_dir_out_err(struct gpio_chip *gc, unsigned int gpio, 283 + int val) 284 + { 285 + return -EINVAL; 286 + } 287 + 286 288 static int bgpio_simple_dir_out(struct gpio_chip *gc, unsigned int gpio, 287 289 int val) 288 290 { ··· 310 300 spin_unlock_irqrestore(&bgc->lock, flags); 311 301 312 302 return 0; 303 + } 304 + 305 + static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) 306 + { 307 + struct bgpio_chip *bgc = to_bgpio_chip(gc); 308 + 309 + return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ? 310 + GPIOF_DIR_OUT : GPIOF_DIR_IN; 313 311 } 314 312 315 313 static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) ··· 367 349 spin_unlock_irqrestore(&bgc->lock, flags); 368 350 369 351 return 0; 352 + } 353 + 354 + static int bgpio_get_dir_inv(struct gpio_chip *gc, unsigned int gpio) 355 + { 356 + struct bgpio_chip *bgc = to_bgpio_chip(gc); 357 + 358 + return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ? 359 + GPIOF_DIR_IN : GPIOF_DIR_OUT; 370 360 } 371 361 372 362 static int bgpio_setup_accessors(struct device *dev, ··· 470 444 bgc->reg_set = set; 471 445 bgc->gc.set = bgpio_set_set; 472 446 bgc->gc.set_multiple = bgpio_set_multiple_set; 447 + } else if (flags & BGPIOF_NO_OUTPUT) { 448 + bgc->gc.set = bgpio_set_none; 449 + bgc->gc.set_multiple = NULL; 473 450 } else { 474 451 bgc->gc.set = bgpio_set; 475 452 bgc->gc.set_multiple = bgpio_set_multiple; ··· 489 460 490 461 static int bgpio_setup_direction(struct bgpio_chip *bgc, 491 462 void __iomem *dirout, 492 - void __iomem *dirin) 463 + void __iomem *dirin, 464 + unsigned long flags) 493 465 { 494 466 if (dirout && dirin) { 495 467 return -EINVAL; ··· 498 468 bgc->reg_dir = dirout; 499 469 bgc->gc.direction_output = bgpio_dir_out; 500 470 bgc->gc.direction_input = bgpio_dir_in; 471 + bgc->gc.get_direction = bgpio_get_dir; 501 472 } else if (dirin) { 502 473 bgc->reg_dir = dirin; 503 474 bgc->gc.direction_output = bgpio_dir_out_inv; 504 475 bgc->gc.direction_input = bgpio_dir_in_inv; 476 + bgc->gc.get_direction = bgpio_get_dir_inv; 505 477 } else { 506 - bgc->gc.direction_output = bgpio_simple_dir_out; 478 + if (flags & BGPIOF_NO_OUTPUT) 479 + bgc->gc.direction_output = bgpio_dir_out_err; 480 + else 481 + bgc->gc.direction_output = bgpio_simple_dir_out; 507 482 bgc->gc.direction_input = bgpio_simple_dir_in; 508 483 } 509 484 ··· 560 525 if (ret) 561 526 return ret; 562 527 563 - ret = bgpio_setup_direction(bgc, dirout, dirin); 528 + ret = bgpio_setup_direction(bgc, dirout, dirin, flags); 564 529 if (ret) 565 530 return ret; 566 531
+10 -13
drivers/gpio/gpio-grgpio.c
··· 104 104 { 105 105 struct bgpio_chip *bgc = &priv->bgc; 106 106 unsigned long mask = bgc->pin2mask(bgc, offset); 107 - unsigned long flags; 108 - 109 - spin_lock_irqsave(&bgc->lock, flags); 110 107 111 108 if (val) 112 109 priv->imask |= mask; 113 110 else 114 111 priv->imask &= ~mask; 115 112 bgc->write_reg(priv->regs + GRGPIO_IMASK, priv->imask); 116 - 117 - spin_unlock_irqrestore(&bgc->lock, flags); 118 113 } 119 114 120 115 static int grgpio_to_irq(struct gpio_chip *gc, unsigned offset) ··· 175 180 { 176 181 struct grgpio_priv *priv = irq_data_get_irq_chip_data(d); 177 182 int offset = d->hwirq; 183 + unsigned long flags; 184 + 185 + spin_lock_irqsave(&priv->bgc.lock, flags); 178 186 179 187 grgpio_set_imask(priv, offset, 0); 188 + 189 + spin_unlock_irqrestore(&priv->bgc.lock, flags); 180 190 } 181 191 182 192 static void grgpio_irq_unmask(struct irq_data *d) 183 193 { 184 194 struct grgpio_priv *priv = irq_data_get_irq_chip_data(d); 185 195 int offset = d->hwirq; 196 + unsigned long flags; 197 + 198 + spin_lock_irqsave(&priv->bgc.lock, flags); 186 199 187 200 grgpio_set_imask(priv, offset, 1); 201 + 202 + spin_unlock_irqrestore(&priv->bgc.lock, flags); 188 203 } 189 204 190 205 static struct irq_chip grgpio_irq_chip = { ··· 286 281 irq_set_chip_data(irq, priv); 287 282 irq_set_chip_and_handler(irq, &grgpio_irq_chip, 288 283 handle_simple_irq); 289 - irq_clear_status_flags(irq, IRQ_NOREQUEST); 290 - #ifdef CONFIG_ARM 291 - set_irq_flags(irq, IRQF_VALID); 292 - #else 293 284 irq_set_noprobe(irq); 294 - #endif 295 285 296 286 return ret; 297 287 } ··· 301 301 int ngpio = priv->bgc.gc.ngpio; 302 302 int i; 303 303 304 - #ifdef CONFIG_ARM 305 - set_irq_flags(irq, 0); 306 - #endif 307 304 irq_set_chip_and_handler(irq, NULL, NULL); 308 305 irq_set_chip_data(irq, NULL); 309 306
+8 -3
drivers/gpio/gpio-max732x.c
··· 685 685 686 686 mutex_init(&chip->lock); 687 687 688 - max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]); 689 - if (nr_port > 8) 690 - max732x_readb(chip, is_group_a(chip, 8), &chip->reg_out[1]); 688 + ret = max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]); 689 + if (ret) 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 697 ret = gpiochip_add(&chip->gpio_chip); 693 698 if (ret)
-4
drivers/gpio/gpio-mcp23s08.c
··· 507 507 irq_set_chip_data(irq, mcp); 508 508 irq_set_chip(irq, &mcp23s08_irq_chip); 509 509 irq_set_nested_thread(irq, true); 510 - #ifdef CONFIG_ARM 511 - set_irq_flags(irq, IRQF_VALID); 512 - #else 513 510 irq_set_noprobe(irq); 514 - #endif 515 511 } 516 512 return 0; 517 513 }
+81 -40
drivers/gpio/gpio-mpc8xxx.c
··· 32 32 33 33 struct mpc8xxx_gpio_chip { 34 34 struct of_mm_gpio_chip mm_gc; 35 - spinlock_t lock; 35 + raw_spinlock_t lock; 36 36 37 37 /* 38 38 * shadowed data register to be able to clear/set output pins in ··· 95 95 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); 96 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 100 if (val) 101 101 mpc8xxx_gc->data |= mpc8xxx_gpio2mask(gpio); ··· 104 104 105 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 110 110 static void mpc8xxx_gpio_set_multiple(struct gpio_chip *gc, ··· 115 115 unsigned long flags; 116 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 120 for (i = 0; i < gc->ngpio; i++) { 121 121 if (*mask == 0) ··· 130 130 131 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 136 136 static int mpc8xxx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio) ··· 139 139 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); 140 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 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 148 return 0; 149 149 } ··· 156 156 157 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 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 165 return 0; 166 166 } ··· 169 169 { 170 170 /* GPIO 28..31 are input only on MPC5121 */ 171 171 if (gpio >= 28) 172 + return -EINVAL; 173 + 174 + return mpc8xxx_gpio_dir_out(gc, gpio, val); 175 + } 176 + 177 + static 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) 172 181 return -EINVAL; 173 182 174 183 return mpc8xxx_gpio_dir_out(gc, gpio, val); ··· 215 206 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc; 216 207 unsigned long flags; 217 208 218 - spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 209 + raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 219 210 220 211 setbits32(mm->regs + GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d))); 221 212 222 - spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 213 + raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 223 214 } 224 215 225 216 static void mpc8xxx_irq_mask(struct irq_data *d) ··· 228 219 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc; 229 220 unsigned long flags; 230 221 231 - spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 222 + raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 232 223 233 224 clrbits32(mm->regs + GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d))); 234 225 235 - spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 226 + raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 236 227 } 237 228 238 229 static void mpc8xxx_irq_ack(struct irq_data *d) ··· 251 242 252 243 switch (flow_type) { 253 244 case IRQ_TYPE_EDGE_FALLING: 254 - spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 245 + raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 255 246 setbits32(mm->regs + GPIO_ICR, 256 247 mpc8xxx_gpio2mask(irqd_to_hwirq(d))); 257 - spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 248 + raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 258 249 break; 259 250 260 251 case IRQ_TYPE_EDGE_BOTH: 261 - spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 252 + raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 262 253 clrbits32(mm->regs + GPIO_ICR, 263 254 mpc8xxx_gpio2mask(irqd_to_hwirq(d))); 264 - spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 255 + raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 265 256 break; 266 257 267 258 default: ··· 291 282 switch (flow_type) { 292 283 case IRQ_TYPE_EDGE_FALLING: 293 284 case IRQ_TYPE_LEVEL_LOW: 294 - spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 285 + raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 295 286 clrsetbits_be32(reg, 3 << shift, 2 << shift); 296 - spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 287 + raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 297 288 break; 298 289 299 290 case IRQ_TYPE_EDGE_RISING: 300 291 case IRQ_TYPE_LEVEL_HIGH: 301 - spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 292 + raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 302 293 clrsetbits_be32(reg, 3 << shift, 1 << shift); 303 - spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 294 + raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 304 295 break; 305 296 306 297 case IRQ_TYPE_EDGE_BOTH: 307 - spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 298 + raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 308 299 clrbits32(reg, 3 << shift); 309 - spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 300 + raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 310 301 break; 311 302 312 303 default: ··· 321 312 .irq_unmask = mpc8xxx_irq_unmask, 322 313 .irq_mask = mpc8xxx_irq_mask, 323 314 .irq_ack = mpc8xxx_irq_ack, 315 + /* this might get overwritten in mpc8xxx_probe() */ 324 316 .irq_set_type = mpc8xxx_irq_set_type, 325 317 }; 326 318 327 319 static int mpc8xxx_gpio_irq_map(struct irq_domain *h, unsigned int irq, 328 320 irq_hw_number_t hwirq) 329 321 { 330 - struct mpc8xxx_gpio_chip *mpc8xxx_gc = h->host_data; 331 - 332 - if (mpc8xxx_gc->of_dev_id_data) 333 - mpc8xxx_irq_chip.irq_set_type = mpc8xxx_gc->of_dev_id_data; 334 - 335 322 irq_set_chip_data(irq, h->host_data); 336 323 irq_set_chip_and_handler(irq, &mpc8xxx_irq_chip, handle_level_irq); 337 324 ··· 339 334 .xlate = irq_domain_xlate_twocell, 340 335 }; 341 336 342 - static struct of_device_id mpc8xxx_gpio_ids[] = { 337 + struct mpc8xxx_gpio_devtype { 338 + int (*gpio_dir_out)(struct gpio_chip *, unsigned int, int); 339 + int (*gpio_get)(struct gpio_chip *, unsigned int); 340 + int (*irq_set_type)(struct irq_data *, unsigned int); 341 + }; 342 + 343 + static const struct mpc8xxx_gpio_devtype mpc512x_gpio_devtype = { 344 + .gpio_dir_out = mpc5121_gpio_dir_out, 345 + .irq_set_type = mpc512x_irq_set_type, 346 + }; 347 + 348 + static const struct mpc8xxx_gpio_devtype mpc5125_gpio_devtype = { 349 + .gpio_dir_out = mpc5125_gpio_dir_out, 350 + .irq_set_type = mpc512x_irq_set_type, 351 + }; 352 + 353 + static const struct mpc8xxx_gpio_devtype mpc8572_gpio_devtype = { 354 + .gpio_get = mpc8572_gpio_get, 355 + }; 356 + 357 + static const struct mpc8xxx_gpio_devtype mpc8xxx_gpio_devtype_default = { 358 + .gpio_dir_out = mpc8xxx_gpio_dir_out, 359 + .gpio_get = mpc8xxx_gpio_get, 360 + .irq_set_type = mpc8xxx_irq_set_type, 361 + }; 362 + 363 + static const struct of_device_id mpc8xxx_gpio_ids[] = { 343 364 { .compatible = "fsl,mpc8349-gpio", }, 344 - { .compatible = "fsl,mpc8572-gpio", }, 365 + { .compatible = "fsl,mpc8572-gpio", .data = &mpc8572_gpio_devtype, }, 345 366 { .compatible = "fsl,mpc8610-gpio", }, 346 - { .compatible = "fsl,mpc5121-gpio", .data = mpc512x_irq_set_type, }, 367 + { .compatible = "fsl,mpc5121-gpio", .data = &mpc512x_gpio_devtype, }, 368 + { .compatible = "fsl,mpc5125-gpio", .data = &mpc5125_gpio_devtype, }, 347 369 { .compatible = "fsl,pq3-gpio", }, 348 370 { .compatible = "fsl,qoriq-gpio", }, 349 371 {} ··· 383 351 struct of_mm_gpio_chip *mm_gc; 384 352 struct gpio_chip *gc; 385 353 const struct of_device_id *id; 354 + const struct mpc8xxx_gpio_devtype *devtype = 355 + of_device_get_match_data(&pdev->dev); 386 356 int ret; 387 357 388 358 mpc8xxx_gc = devm_kzalloc(&pdev->dev, sizeof(*mpc8xxx_gc), GFP_KERNEL); ··· 393 359 394 360 platform_set_drvdata(pdev, mpc8xxx_gc); 395 361 396 - spin_lock_init(&mpc8xxx_gc->lock); 362 + raw_spin_lock_init(&mpc8xxx_gc->lock); 397 363 398 364 mm_gc = &mpc8xxx_gc->mm_gc; 399 365 gc = &mm_gc->gc; ··· 401 367 mm_gc->save_regs = mpc8xxx_gpio_save_regs; 402 368 gc->ngpio = MPC8XXX_GPIO_PINS; 403 369 gc->direction_input = mpc8xxx_gpio_dir_in; 404 - gc->direction_output = of_device_is_compatible(np, "fsl,mpc5121-gpio") ? 405 - mpc5121_gpio_dir_out : mpc8xxx_gpio_dir_out; 406 - gc->get = of_device_is_compatible(np, "fsl,mpc8572-gpio") ? 407 - mpc8572_gpio_get : mpc8xxx_gpio_get; 370 + 371 + if (!devtype) 372 + devtype = &mpc8xxx_gpio_devtype_default; 373 + 374 + /* 375 + * It's assumed that only a single type of gpio controller is available 376 + * on the current machine, so overwriting global data is fine. 377 + */ 378 + mpc8xxx_irq_chip.irq_set_type = devtype->irq_set_type; 379 + 380 + gc->direction_output = devtype->gpio_dir_out ?: mpc8xxx_gpio_dir_out; 381 + gc->get = devtype->gpio_get ?: mpc8xxx_gpio_get; 408 382 gc->set = mpc8xxx_gpio_set; 409 383 gc->set_multiple = mpc8xxx_gpio_set_multiple; 410 384 gc->to_irq = mpc8xxx_gpio_to_irq; ··· 438 396 out_be32(mm_gc->regs + GPIO_IER, 0xffffffff); 439 397 out_be32(mm_gc->regs + GPIO_IMR, 0); 440 398 441 - irq_set_handler_data(mpc8xxx_gc->irqn, mpc8xxx_gc); 442 - irq_set_chained_handler(mpc8xxx_gc->irqn, mpc8xxx_gpio_irq_cascade); 399 + irq_set_chained_handler_and_data(mpc8xxx_gc->irqn, 400 + mpc8xxx_gpio_irq_cascade, mpc8xxx_gc); 443 401 444 402 return 0; 445 403 } ··· 449 407 struct mpc8xxx_gpio_chip *mpc8xxx_gc = platform_get_drvdata(pdev); 450 408 451 409 if (mpc8xxx_gc->irq) { 452 - irq_set_handler_data(mpc8xxx_gc->irqn, NULL); 453 - irq_set_chained_handler(mpc8xxx_gc->irqn, NULL); 410 + irq_set_chained_handler_and_data(mpc8xxx_gc->irqn, NULL, NULL); 454 411 irq_domain_remove(mpc8xxx_gc->irq); 455 412 } 456 413
+7 -16
drivers/gpio/gpio-msm-v2.c
··· 187 187 return irq_create_mapping(domain, offset); 188 188 } 189 189 190 - static 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 190 /* For dual-edge interrupts in software, since the hardware has no 199 191 * such support: 200 192 * ··· 230 238 231 239 static void msm_gpio_irq_ack(struct irq_data *d) 232 240 { 233 - int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq); 241 + int gpio = d->hwirq; 234 242 235 243 writel(BIT(INTR_STATUS), GPIO_INTR_STATUS(gpio)); 236 244 if (test_bit(gpio, msm_gpio.dual_edge_irqs)) ··· 239 247 240 248 static void msm_gpio_irq_mask(struct irq_data *d) 241 249 { 242 - int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq); 243 250 unsigned long irq_flags; 251 + int gpio = d->hwirq; 244 252 245 253 spin_lock_irqsave(&tlmm_lock, irq_flags); 246 254 writel(TARGET_PROC_NONE, GPIO_INTR_CFG_SU(gpio)); ··· 251 259 252 260 static void msm_gpio_irq_unmask(struct irq_data *d) 253 261 { 254 - int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq); 255 262 unsigned long irq_flags; 263 + int gpio = d->hwirq; 256 264 257 265 spin_lock_irqsave(&tlmm_lock, irq_flags); 258 266 __set_bit(gpio, msm_gpio.enabled_irqs); ··· 263 271 264 272 static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int flow_type) 265 273 { 266 - int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq); 267 274 unsigned long irq_flags; 275 + int gpio = d->hwirq; 268 276 uint32_t bits; 269 277 270 278 spin_lock_irqsave(&tlmm_lock, irq_flags); ··· 273 281 274 282 if (flow_type & IRQ_TYPE_EDGE_BOTH) { 275 283 bits |= BIT(INTR_DECT_CTL); 276 - __irq_set_handler_locked(d->irq, handle_edge_irq); 284 + irq_set_handler_locked(d, handle_edge_irq); 277 285 if ((flow_type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) 278 286 __set_bit(gpio, msm_gpio.dual_edge_irqs); 279 287 else 280 288 __clear_bit(gpio, msm_gpio.dual_edge_irqs); 281 289 } else { 282 290 bits &= ~BIT(INTR_DECT_CTL); 283 - __irq_set_handler_locked(d->irq, handle_level_irq); 291 + irq_set_handler_locked(d, handle_level_irq); 284 292 __clear_bit(gpio, msm_gpio.dual_edge_irqs); 285 293 } 286 294 ··· 323 331 324 332 static int msm_gpio_irq_set_wake(struct irq_data *d, unsigned int on) 325 333 { 326 - int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq); 334 + int gpio = d->hwirq; 327 335 328 336 if (on) { 329 337 if (bitmap_empty(msm_gpio.wake_irqs, MAX_NR_GPIO)) ··· 355 363 irq_set_lockdep_class(irq, &msm_gpio_lock_class); 356 364 irq_set_chip_and_handler(irq, &msm_gpio_irq_chip, 357 365 handle_level_irq); 358 - set_irq_flags(irq, IRQF_VALID); 359 366 360 367 return 0; 361 368 }
+4 -4
drivers/gpio/gpio-mvebu.c
··· 458 458 return 0; 459 459 } 460 460 461 - static void mvebu_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) 461 + static 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 464 struct irq_chip *chip = irq_desc_get_chip(desc); 465 465 u32 cause, type; 466 466 int i; ··· 787 787 788 788 if (irq < 0) 789 789 continue; 790 - irq_set_handler_data(irq, mvchip); 791 - irq_set_chained_handler(irq, mvebu_gpio_irq_handler); 790 + irq_set_chained_handler_and_data(irq, mvebu_gpio_irq_handler, 791 + mvchip); 792 792 } 793 793 794 794 mvchip->irqbase = irq_alloc_descs(-1, 0, ngpios, -1);
+5 -4
drivers/gpio/gpio-mxc.c
··· 275 275 static void mx3_gpio_irq_handler(u32 irq, struct irq_desc *desc) 276 276 { 277 277 u32 irq_stat; 278 - struct mxc_gpio_port *port = irq_get_handler_data(irq); 279 - struct irq_chip *chip = irq_get_chip(irq); 278 + struct mxc_gpio_port *port = irq_desc_get_handler_data(desc); 279 + struct irq_chip *chip = irq_desc_get_chip(desc); 280 280 281 281 chained_irq_enter(chip, desc); 282 282 ··· 292 292 { 293 293 u32 irq_msk, irq_stat; 294 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 297 chained_irq_enter(chip, desc); 298 298 ··· 339 339 return 0; 340 340 } 341 341 342 - static void __init mxc_gpio_init_gc(struct mxc_gpio_port *port, int irq_base) 342 + static void mxc_gpio_init_gc(struct mxc_gpio_port *port, int irq_base) 343 343 { 344 344 struct irq_chip_generic *gc; 345 345 struct irq_chip_type *ct; ··· 354 354 ct->chip.irq_unmask = irq_gc_mask_set_bit; 355 355 ct->chip.irq_set_type = gpio_set_irq_type; 356 356 ct->chip.irq_set_wake = gpio_set_wake_irq; 357 + ct->chip.flags = IRQCHIP_MASK_ON_SUSPEND; 357 358 ct->regs.ack = GPIO_ISR; 358 359 ct->regs.mask = GPIO_IMR; 359 360
+1 -1
drivers/gpio/gpio-mxs.c
··· 157 157 static void mxs_gpio_irq_handler(u32 irq, struct irq_desc *desc) 158 158 { 159 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 162 desc->irq_data.chip->irq_ack(&desc->irq_data); 163 163
+88 -68
drivers/gpio/gpio-omap.c
··· 29 29 #include <linux/platform_data/gpio-omap.h> 30 30 31 31 #define OFF_MODE 1 32 + #define OMAP4_GPIO_DEBOUNCINGTIME_MASK 0xFF 32 33 33 34 static LIST_HEAD(omap_gpio_list); 34 35 ··· 58 57 u32 saved_datain; 59 58 u32 level_mask; 60 59 u32 toggle_mask; 61 - spinlock_t lock; 60 + raw_spinlock_t lock; 62 61 struct gpio_chip chip; 63 62 struct clk *dbck; 64 63 u32 mod_usage; ··· 176 175 static inline void omap_gpio_dbck_enable(struct gpio_bank *bank) 177 176 { 178 177 if (bank->dbck_enable_mask && !bank->dbck_enabled) { 179 - clk_prepare_enable(bank->dbck); 178 + clk_enable(bank->dbck); 180 179 bank->dbck_enabled = true; 181 180 182 181 writel_relaxed(bank->dbck_enable_mask, ··· 194 193 */ 195 194 writel_relaxed(0, bank->base + bank->regs->debounce_en); 196 195 197 - clk_disable_unprepare(bank->dbck); 196 + clk_disable(bank->dbck); 198 197 bank->dbck_enabled = false; 199 198 } 200 199 } ··· 205 204 * @offset: the gpio number on this @bank 206 205 * @debounce: debounce time to use 207 206 * 208 - * OMAP's debounce time is in 31us steps so we need 209 - * to convert and round up to the closest unit. 207 + * OMAP's debounce time is in 31us steps 208 + * <debounce time> = (GPIO_DEBOUNCINGTIME[7:0].DEBOUNCETIME + 1) x 31 209 + * so we need to convert and round up to the closest unit. 210 210 */ 211 211 static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset, 212 212 unsigned debounce) ··· 215 213 void __iomem *reg; 216 214 u32 val; 217 215 u32 l; 216 + bool enable = !!debounce; 218 217 219 218 if (!bank->dbck_flag) 220 219 return; 221 220 222 - if (debounce < 32) 223 - debounce = 0x01; 224 - else if (debounce > 7936) 225 - debounce = 0xff; 226 - else 227 - debounce = (debounce / 0x1f) - 1; 221 + if (enable) { 222 + debounce = DIV_ROUND_UP(debounce, 31) - 1; 223 + debounce &= OMAP4_GPIO_DEBOUNCINGTIME_MASK; 224 + } 228 225 229 226 l = BIT(offset); 230 227 231 - clk_prepare_enable(bank->dbck); 228 + clk_enable(bank->dbck); 232 229 reg = bank->base + bank->regs->debounce; 233 230 writel_relaxed(debounce, reg); 234 231 235 232 reg = bank->base + bank->regs->debounce_en; 236 233 val = readl_relaxed(reg); 237 234 238 - if (debounce) 235 + if (enable) 239 236 val |= l; 240 237 else 241 238 val &= ~l; 242 239 bank->dbck_enable_mask = val; 243 240 244 241 writel_relaxed(val, reg); 245 - clk_disable_unprepare(bank->dbck); 242 + clk_disable(bank->dbck); 246 243 /* 247 244 * Enable debounce clock per module. 248 245 * This call is mandatory because in omap_gpio_request() when ··· 286 285 bank->context.debounce = 0; 287 286 writel_relaxed(bank->context.debounce, bank->base + 288 287 bank->regs->debounce); 289 - clk_disable_unprepare(bank->dbck); 288 + clk_disable(bank->dbck); 290 289 bank->dbck_enabled = false; 291 290 } 292 291 } ··· 499 498 if (!BANK_USED(bank)) 500 499 pm_runtime_get_sync(bank->dev); 501 500 502 - spin_lock_irqsave(&bank->lock, flags); 501 + raw_spin_lock_irqsave(&bank->lock, flags); 503 502 retval = omap_set_gpio_triggering(bank, offset, type); 504 503 if (retval) { 505 - spin_unlock_irqrestore(&bank->lock, flags); 504 + raw_spin_unlock_irqrestore(&bank->lock, flags); 506 505 goto error; 507 506 } 508 507 omap_gpio_init_irq(bank, offset); 509 508 if (!omap_gpio_is_input(bank, offset)) { 510 - spin_unlock_irqrestore(&bank->lock, flags); 509 + raw_spin_unlock_irqrestore(&bank->lock, flags); 511 510 retval = -EINVAL; 512 511 goto error; 513 512 } 514 - spin_unlock_irqrestore(&bank->lock, flags); 513 + raw_spin_unlock_irqrestore(&bank->lock, flags); 515 514 516 515 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) 517 - __irq_set_handler_locked(d->irq, handle_level_irq); 516 + irq_set_handler_locked(d, handle_level_irq); 518 517 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) 519 - __irq_set_handler_locked(d->irq, handle_edge_irq); 518 + irq_set_handler_locked(d, handle_edge_irq); 520 519 521 520 return 0; 522 521 ··· 637 636 return -EINVAL; 638 637 } 639 638 640 - spin_lock_irqsave(&bank->lock, flags); 639 + raw_spin_lock_irqsave(&bank->lock, flags); 641 640 if (enable) 642 641 bank->context.wake_en |= gpio_bit; 643 642 else 644 643 bank->context.wake_en &= ~gpio_bit; 645 644 646 645 writel_relaxed(bank->context.wake_en, bank->base + bank->regs->wkup_en); 647 - spin_unlock_irqrestore(&bank->lock, flags); 646 + raw_spin_unlock_irqrestore(&bank->lock, flags); 648 647 649 648 return 0; 650 649 } ··· 670 669 if (!BANK_USED(bank)) 671 670 pm_runtime_get_sync(bank->dev); 672 671 673 - spin_lock_irqsave(&bank->lock, flags); 672 + raw_spin_lock_irqsave(&bank->lock, flags); 674 673 omap_enable_gpio_module(bank, offset); 675 674 bank->mod_usage |= BIT(offset); 676 - spin_unlock_irqrestore(&bank->lock, flags); 675 + raw_spin_unlock_irqrestore(&bank->lock, flags); 677 676 678 677 return 0; 679 678 } ··· 683 682 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); 684 683 unsigned long flags; 685 684 686 - spin_lock_irqsave(&bank->lock, flags); 685 + raw_spin_lock_irqsave(&bank->lock, flags); 687 686 bank->mod_usage &= ~(BIT(offset)); 688 687 if (!LINE_USED(bank->irq_usage, offset)) { 689 688 omap_set_gpio_direction(bank, offset, 1); 690 689 omap_clear_gpio_debounce(bank, offset); 691 690 } 692 691 omap_disable_gpio_module(bank, offset); 693 - spin_unlock_irqrestore(&bank->lock, flags); 692 + raw_spin_unlock_irqrestore(&bank->lock, flags); 694 693 695 694 /* 696 695 * If this is the last gpio to be freed in the bank, ··· 717 716 struct gpio_bank *bank; 718 717 int unmasked = 0; 719 718 struct irq_chip *irqchip = irq_desc_get_chip(desc); 720 - struct gpio_chip *chip = irq_get_handler_data(irq); 719 + struct gpio_chip *chip = irq_desc_get_handler_data(desc); 720 + unsigned long lock_flags; 721 721 722 722 chained_irq_enter(irqchip, desc); 723 723 ··· 733 731 u32 isr_saved, level_mask = 0; 734 732 u32 enabled; 735 733 734 + raw_spin_lock_irqsave(&bank->lock, lock_flags); 735 + 736 736 enabled = omap_get_gpio_irqbank_mask(bank); 737 737 isr_saved = isr = readl_relaxed(isr_reg) & enabled; 738 738 ··· 747 743 omap_disable_gpio_irqbank(bank, isr_saved & ~level_mask); 748 744 omap_clear_gpio_irqbank(bank, isr_saved & ~level_mask); 749 745 omap_enable_gpio_irqbank(bank, isr_saved & ~level_mask); 746 + 747 + raw_spin_unlock_irqrestore(&bank->lock, lock_flags); 750 748 751 749 /* if there is only edge sensitive GPIO pin interrupts 752 750 configured, we could unmask GPIO bank interrupt immediately */ ··· 764 758 bit = __ffs(isr); 765 759 isr &= ~(BIT(bit)); 766 760 761 + raw_spin_lock_irqsave(&bank->lock, lock_flags); 767 762 /* 768 763 * Some chips can't respond to both rising and falling 769 764 * at the same time. If this irq was requested with ··· 774 767 */ 775 768 if (bank->toggle_mask & (BIT(bit))) 776 769 omap_toggle_gpio_edge_triggering(bank, bit); 770 + 771 + raw_spin_unlock_irqrestore(&bank->lock, lock_flags); 777 772 778 773 generic_handle_irq(irq_find_mapping(bank->chip.irqdomain, 779 774 bit)); ··· 800 791 if (!BANK_USED(bank)) 801 792 pm_runtime_get_sync(bank->dev); 802 793 803 - spin_lock_irqsave(&bank->lock, flags); 794 + raw_spin_lock_irqsave(&bank->lock, flags); 804 795 805 796 if (!LINE_USED(bank->mod_usage, offset)) 806 797 omap_set_gpio_direction(bank, offset, 1); ··· 809 800 omap_enable_gpio_module(bank, offset); 810 801 bank->irq_usage |= BIT(offset); 811 802 812 - spin_unlock_irqrestore(&bank->lock, flags); 803 + raw_spin_unlock_irqrestore(&bank->lock, flags); 813 804 omap_gpio_unmask_irq(d); 814 805 815 806 return 0; 816 807 err: 817 - spin_unlock_irqrestore(&bank->lock, flags); 808 + raw_spin_unlock_irqrestore(&bank->lock, flags); 818 809 if (!BANK_USED(bank)) 819 810 pm_runtime_put(bank->dev); 820 811 return -EINVAL; ··· 826 817 unsigned long flags; 827 818 unsigned offset = d->hwirq; 828 819 829 - spin_lock_irqsave(&bank->lock, flags); 820 + raw_spin_lock_irqsave(&bank->lock, flags); 830 821 bank->irq_usage &= ~(BIT(offset)); 831 822 omap_set_gpio_irqenable(bank, offset, 0); 832 823 omap_clear_gpio_irqstatus(bank, offset); ··· 834 825 if (!LINE_USED(bank->mod_usage, offset)) 835 826 omap_clear_gpio_debounce(bank, offset); 836 827 omap_disable_gpio_module(bank, offset); 837 - spin_unlock_irqrestore(&bank->lock, flags); 828 + raw_spin_unlock_irqrestore(&bank->lock, flags); 838 829 839 830 /* 840 831 * If this is the last IRQ to be freed in the bank, ··· 858 849 unsigned offset = d->hwirq; 859 850 unsigned long flags; 860 851 861 - spin_lock_irqsave(&bank->lock, flags); 852 + raw_spin_lock_irqsave(&bank->lock, flags); 862 853 omap_set_gpio_irqenable(bank, offset, 0); 863 854 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); 864 - spin_unlock_irqrestore(&bank->lock, flags); 855 + raw_spin_unlock_irqrestore(&bank->lock, flags); 865 856 } 866 857 867 858 static void omap_gpio_unmask_irq(struct irq_data *d) ··· 871 862 u32 trigger = irqd_get_trigger_type(d); 872 863 unsigned long flags; 873 864 874 - spin_lock_irqsave(&bank->lock, flags); 865 + raw_spin_lock_irqsave(&bank->lock, flags); 875 866 if (trigger) 876 867 omap_set_gpio_triggering(bank, offset, trigger); 877 868 ··· 883 874 } 884 875 885 876 omap_set_gpio_irqenable(bank, offset, 1); 886 - spin_unlock_irqrestore(&bank->lock, flags); 877 + raw_spin_unlock_irqrestore(&bank->lock, flags); 887 878 } 888 879 889 880 /*---------------------------------------------------------------------*/ ··· 896 887 OMAP_MPUIO_GPIO_MASKIT / bank->stride; 897 888 unsigned long flags; 898 889 899 - spin_lock_irqsave(&bank->lock, flags); 890 + raw_spin_lock_irqsave(&bank->lock, flags); 900 891 writel_relaxed(0xffff & ~bank->context.wake_en, mask_reg); 901 - spin_unlock_irqrestore(&bank->lock, flags); 892 + raw_spin_unlock_irqrestore(&bank->lock, flags); 902 893 903 894 return 0; 904 895 } ··· 911 902 OMAP_MPUIO_GPIO_MASKIT / bank->stride; 912 903 unsigned long flags; 913 904 914 - spin_lock_irqsave(&bank->lock, flags); 905 + raw_spin_lock_irqsave(&bank->lock, flags); 915 906 writel_relaxed(bank->context.wake_en, mask_reg); 916 - spin_unlock_irqrestore(&bank->lock, flags); 907 + raw_spin_unlock_irqrestore(&bank->lock, flags); 917 908 918 909 return 0; 919 910 } ··· 959 950 960 951 bank = container_of(chip, struct gpio_bank, chip); 961 952 reg = bank->base + bank->regs->direction; 962 - spin_lock_irqsave(&bank->lock, flags); 953 + raw_spin_lock_irqsave(&bank->lock, flags); 963 954 dir = !!(readl_relaxed(reg) & BIT(offset)); 964 - spin_unlock_irqrestore(&bank->lock, flags); 955 + raw_spin_unlock_irqrestore(&bank->lock, flags); 965 956 return dir; 966 957 } 967 958 ··· 971 962 unsigned long flags; 972 963 973 964 bank = container_of(chip, struct gpio_bank, chip); 974 - spin_lock_irqsave(&bank->lock, flags); 965 + raw_spin_lock_irqsave(&bank->lock, flags); 975 966 omap_set_gpio_direction(bank, offset, 1); 976 - spin_unlock_irqrestore(&bank->lock, flags); 967 + raw_spin_unlock_irqrestore(&bank->lock, flags); 977 968 return 0; 978 969 } 979 970 ··· 995 986 unsigned long flags; 996 987 997 988 bank = container_of(chip, struct gpio_bank, chip); 998 - spin_lock_irqsave(&bank->lock, flags); 989 + raw_spin_lock_irqsave(&bank->lock, flags); 999 990 bank->set_dataout(bank, offset, value); 1000 991 omap_set_gpio_direction(bank, offset, 0); 1001 - spin_unlock_irqrestore(&bank->lock, flags); 992 + raw_spin_unlock_irqrestore(&bank->lock, flags); 1002 993 return 0; 1003 994 } 1004 995 ··· 1010 1001 1011 1002 bank = container_of(chip, struct gpio_bank, chip); 1012 1003 1013 - spin_lock_irqsave(&bank->lock, flags); 1004 + raw_spin_lock_irqsave(&bank->lock, flags); 1014 1005 omap2_set_gpio_debounce(bank, offset, debounce); 1015 - spin_unlock_irqrestore(&bank->lock, flags); 1006 + raw_spin_unlock_irqrestore(&bank->lock, flags); 1016 1007 1017 1008 return 0; 1018 1009 } ··· 1023 1014 unsigned long flags; 1024 1015 1025 1016 bank = container_of(chip, struct gpio_bank, chip); 1026 - spin_lock_irqsave(&bank->lock, flags); 1017 + raw_spin_lock_irqsave(&bank->lock, flags); 1027 1018 bank->set_dataout(bank, offset, value); 1028 - spin_unlock_irqrestore(&bank->lock, flags); 1019 + raw_spin_unlock_irqrestore(&bank->lock, flags); 1029 1020 } 1030 1021 1031 1022 /*---------------------------------------------------------------------*/ ··· 1070 1061 /* Initialize interface clk ungated, module enabled */ 1071 1062 if (bank->regs->ctrl) 1072 1063 writel_relaxed(0, base + bank->regs->ctrl); 1073 - 1074 - bank->dbck = clk_get(bank->dev, "dbclk"); 1075 - if (IS_ERR(bank->dbck)) 1076 - dev_err(bank->dev, "Could not get gpio dbck\n"); 1077 1064 } 1078 1065 1079 1066 static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc) ··· 1183 1178 irqc->irq_set_wake = omap_gpio_wake_enable, 1184 1179 irqc->name = dev_name(&pdev->dev); 1185 1180 1186 - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1187 - if (unlikely(!res)) { 1188 - dev_err(dev, "Invalid IRQ resource\n"); 1189 - return -ENODEV; 1181 + bank->irq = platform_get_irq(pdev, 0); 1182 + if (bank->irq <= 0) { 1183 + if (!bank->irq) 1184 + bank->irq = -ENXIO; 1185 + if (bank->irq != -EPROBE_DEFER) 1186 + dev_err(dev, 1187 + "can't get irq resource ret=%d\n", bank->irq); 1188 + return bank->irq; 1190 1189 } 1191 1190 1192 - bank->irq = res->start; 1193 1191 bank->dev = dev; 1194 1192 bank->chip.dev = dev; 1195 1193 bank->chip.owner = THIS_MODULE; ··· 1221 1213 else 1222 1214 bank->set_dataout = omap_set_gpio_dataout_mask; 1223 1215 1224 - spin_lock_init(&bank->lock); 1216 + raw_spin_lock_init(&bank->lock); 1225 1217 1226 1218 /* Static mapping, never released */ 1227 1219 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1228 1220 bank->base = devm_ioremap_resource(dev, res); 1229 1221 if (IS_ERR(bank->base)) { 1230 - irq_domain_remove(bank->chip.irqdomain); 1231 1222 return PTR_ERR(bank->base); 1223 + } 1224 + 1225 + if (bank->dbck_flag) { 1226 + bank->dbck = devm_clk_get(bank->dev, "dbclk"); 1227 + if (IS_ERR(bank->dbck)) { 1228 + dev_err(bank->dev, 1229 + "Could not get gpio dbck. Disable debounce\n"); 1230 + bank->dbck_flag = false; 1231 + } else { 1232 + clk_prepare(bank->dbck); 1233 + } 1232 1234 } 1233 1235 1234 1236 platform_set_drvdata(pdev, bank); ··· 1272 1254 list_del(&bank->node); 1273 1255 gpiochip_remove(&bank->chip); 1274 1256 pm_runtime_disable(bank->dev); 1257 + if (bank->dbck_flag) 1258 + clk_unprepare(bank->dbck); 1275 1259 1276 1260 return 0; 1277 1261 } ··· 1291 1271 unsigned long flags; 1292 1272 u32 wake_low, wake_hi; 1293 1273 1294 - spin_lock_irqsave(&bank->lock, flags); 1274 + raw_spin_lock_irqsave(&bank->lock, flags); 1295 1275 1296 1276 /* 1297 1277 * Only edges can generate a wakeup event to the PRCM. ··· 1344 1324 bank->get_context_loss_count(bank->dev); 1345 1325 1346 1326 omap_gpio_dbck_disable(bank); 1347 - spin_unlock_irqrestore(&bank->lock, flags); 1327 + raw_spin_unlock_irqrestore(&bank->lock, flags); 1348 1328 1349 1329 return 0; 1350 1330 } ··· 1359 1339 unsigned long flags; 1360 1340 int c; 1361 1341 1362 - spin_lock_irqsave(&bank->lock, flags); 1342 + raw_spin_lock_irqsave(&bank->lock, flags); 1363 1343 1364 1344 /* 1365 1345 * On the first resume during the probe, the context has not ··· 1395 1375 if (c != bank->context_loss_count) { 1396 1376 omap_gpio_restore_context(bank); 1397 1377 } else { 1398 - spin_unlock_irqrestore(&bank->lock, flags); 1378 + raw_spin_unlock_irqrestore(&bank->lock, flags); 1399 1379 return 0; 1400 1380 } 1401 1381 } 1402 1382 } 1403 1383 1404 1384 if (!bank->workaround_enabled) { 1405 - spin_unlock_irqrestore(&bank->lock, flags); 1385 + raw_spin_unlock_irqrestore(&bank->lock, flags); 1406 1386 return 0; 1407 1387 } 1408 1388 ··· 1457 1437 } 1458 1438 1459 1439 bank->workaround_enabled = false; 1460 - spin_unlock_irqrestore(&bank->lock, flags); 1440 + raw_spin_unlock_irqrestore(&bank->lock, flags); 1461 1441 1462 1442 return 0; 1463 1443 }
+5 -9
drivers/gpio/gpio-pcf857x.c
··· 88 88 struct gpio_chip chip; 89 89 struct i2c_client *client; 90 90 struct mutex lock; /* protect 'out' */ 91 - spinlock_t slock; /* protect irq demux */ 92 91 unsigned out; /* software latch */ 93 92 unsigned status; /* current status */ 94 93 unsigned int irq_parent; ··· 184 185 static irqreturn_t pcf857x_irq(int irq, void *data) 185 186 { 186 187 struct pcf857x *gpio = data; 187 - unsigned long change, i, status, flags; 188 + unsigned long change, i, status; 188 189 189 190 status = gpio->read(gpio->client); 190 - 191 - spin_lock_irqsave(&gpio->slock, flags); 192 191 193 192 /* 194 193 * call the interrupt handler iff gpio is used as 195 194 * interrupt source, just to avoid bad irqs 196 195 */ 197 - 196 + mutex_lock(&gpio->lock); 198 197 change = (gpio->status ^ status) & gpio->irq_enabled; 198 + gpio->status = status; 199 + mutex_unlock(&gpio->lock); 200 + 199 201 for_each_set_bit(i, &change, gpio->chip.ngpio) 200 202 handle_nested_irq(irq_find_mapping(gpio->chip.irqdomain, i)); 201 - gpio->status = status; 202 - 203 - spin_unlock_irqrestore(&gpio->slock, flags); 204 203 205 204 return IRQ_HANDLED; 206 205 } ··· 290 293 return -ENOMEM; 291 294 292 295 mutex_init(&gpio->lock); 293 - spin_lock_init(&gpio->slock); 294 296 295 297 gpio->chip.base = pdata ? pdata->gpio_base : -1; 296 298 gpio->chip.can_sleep = true;
+2 -2
drivers/gpio/gpio-pch.c
··· 281 281 282 282 /* And the handler */ 283 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 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 288 288 unlock: 289 289 spin_unlock_irqrestore(&chip->spinlock, flags);
+4 -4
drivers/gpio/gpio-pxa.c
··· 524 524 { 525 525 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 526 526 handle_edge_irq); 527 - set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); 527 + irq_set_noprobe(irq); 528 528 return 0; 529 529 } 530 530 ··· 643 643 irq = gpio_to_irq(0); 644 644 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 645 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 648 if (irq1 > 0) { 649 649 irq = gpio_to_irq(1); 650 650 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 651 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 655 for (irq = gpio_to_irq(gpio_offset); 656 656 irq <= gpio_to_irq(pxa_last_gpio); irq++) { 657 657 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 658 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
+20 -4
drivers/gpio/gpio-rcar.c
··· 251 251 252 252 static 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 257 268 static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset) 258 269 { 270 + struct gpio_rcar_priv *p = gpio_to_priv(chip); 271 + 259 272 pinctrl_free_gpio(chip->base + offset); 260 273 261 274 /* Set the GPIO as an input to ensure that the next GPIO request won't 262 275 * drive the GPIO pin as an output. 263 276 */ 264 277 gpio_rcar_config_general_input_output_mode(chip, offset, false); 278 + 279 + pm_runtime_put(&p->pdev->dev); 265 280 } 266 281 267 282 static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset) ··· 340 325 .data = &gpio_rcar_info_gen2, 341 326 }, { 342 327 .compatible = "renesas,gpio-r8a7794", 328 + .data = &gpio_rcar_info_gen2, 329 + }, { 330 + .compatible = "renesas,gpio-r8a7795", 331 + /* Gen3 GPIO is identical to Gen2. */ 343 332 .data = &gpio_rcar_info_gen2, 344 333 }, { 345 334 .compatible = "renesas,gpio-rcar", ··· 424 405 } 425 406 426 407 pm_runtime_enable(dev); 427 - pm_runtime_get_sync(dev); 428 408 429 409 io = platform_get_resource(pdev, IORESOURCE_MEM, 0); 430 410 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); ··· 505 487 err1: 506 488 gpiochip_remove(gpio_chip); 507 489 err0: 508 - pm_runtime_put(dev); 509 490 pm_runtime_disable(dev); 510 491 return ret; 511 492 } ··· 515 498 516 499 gpiochip_remove(&p->gpio_chip); 517 500 518 - pm_runtime_put(&pdev->dev); 519 501 pm_runtime_disable(&pdev->dev); 520 502 return 0; 521 503 }
+3 -3
drivers/gpio/gpio-sa1100.c
··· 155 155 { 156 156 irq_set_chip_and_handler(irq, &sa1100_gpio_irq_chip, 157 157 handle_edge_irq); 158 - set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); 158 + irq_set_noprobe(irq); 159 159 160 160 return 0; 161 161 } ··· 173 173 * and call the handler. 174 174 */ 175 175 static void 176 - sa1100_gpio_handler(unsigned int irq, struct irq_desc *desc) 176 + sa1100_gpio_handler(unsigned int __irq, struct irq_desc *desc) 177 177 { 178 - unsigned int mask; 178 + unsigned int irq, mask; 179 179 180 180 mask = GEDR; 181 181 do {
+1 -1
drivers/gpio/gpio-sta2x11.c
··· 346 346 i = chip->irq_base + j; 347 347 irq_set_chip_and_handler(i, &ct->chip, ct->handler); 348 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 351 gc->irq_cnt = i - gc->irq_base; 352 352 }
+5 -5
drivers/gpio/gpio-tc3589x.c
··· 102 102 static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type) 103 103 { 104 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 106 int offset = d->hwirq; 107 107 int regoffset = offset / 8; 108 108 int mask = 1 << (offset % 8); ··· 130 130 static void tc3589x_gpio_irq_lock(struct irq_data *d) 131 131 { 132 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 135 mutex_lock(&tc3589x_gpio->irq_lock); 136 136 } ··· 138 138 static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d) 139 139 { 140 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 142 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 143 143 static const u8 regmap[] = { 144 144 [REG_IBE] = TC3589x_GPIOIBE0, ··· 167 167 static void tc3589x_gpio_irq_mask(struct irq_data *d) 168 168 { 169 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 171 int offset = d->hwirq; 172 172 int regoffset = offset / 8; 173 173 int mask = 1 << (offset % 8); ··· 178 178 static void tc3589x_gpio_irq_unmask(struct irq_data *d) 179 179 { 180 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 182 int offset = d->hwirq; 183 183 int regoffset = offset / 8; 184 184 int mask = 1 << (offset % 8);
+3 -6
drivers/gpio/gpio-tegra.c
··· 252 252 tegra_gpio_enable(gpio); 253 253 254 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 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 259 return 0; 260 260 } ··· 268 268 269 269 static void tegra_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) 270 270 { 271 - struct tegra_gpio_bank *bank; 272 271 int port; 273 272 int pin; 274 273 int unmasked = 0; 275 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 277 chained_irq_enter(chip, desc); 278 - 279 - bank = irq_get_handler_data(irq); 280 278 281 279 for (port = 0; port < 4; port++) { 282 280 int gpio = tegra_gpio_compose(bank->bank, port, 0); ··· 507 509 irq_set_chip_data(irq, bank); 508 510 irq_set_chip_and_handler(irq, &tegra_gpio_irq_chip, 509 511 handle_simple_irq); 510 - set_irq_flags(irq, IRQF_VALID); 511 512 } 512 513 513 514 for (i = 0; i < tegra_gpio_bank_count; i++) {
+5 -7
drivers/gpio/gpio-timberdale.c
··· 194 194 195 195 static 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 199 unsigned long ipr; 199 200 int offset; 200 201 201 - desc->irq_data.chip->irq_ack(irq_get_irq_data(irq)); 202 + data->chip->irq_ack(data); 202 203 ipr = ioread32(tgpio->membase + TGPIO_IPR); 203 204 iowrite32(ipr, tgpio->membase + TGPIO_ICR); 204 205 ··· 295 294 irq_set_chip_and_handler(tgpio->irq_base + i, 296 295 &timbgpio_irqchip, handle_simple_irq); 297 296 irq_set_chip_data(tgpio->irq_base + i, tgpio); 298 - #ifdef CONFIG_ARM 299 - set_irq_flags(tgpio->irq_base + i, IRQF_VALID | IRQF_PROBE); 300 - #endif 297 + irq_clear_status_flags(tgpio->irq_base + i, IRQ_NOREQUEST | IRQ_NOPROBE); 301 298 } 302 299 303 - irq_set_handler_data(irq, tgpio); 304 - irq_set_chained_handler(irq, timbgpio_irq); 300 + irq_set_chained_handler_and_data(irq, timbgpio_irq, tgpio); 305 301 306 302 return 0; 307 303 }
+2 -2
drivers/gpio/gpio-tz1090.c
··· 510 510 gc->chip_types[1].chip.flags = IRQCHIP_MASK_ON_SUSPEND; 511 511 512 512 /* Setup chained handler for this GPIO bank */ 513 - irq_set_handler_data(bank->irq, bank); 514 - irq_set_chained_handler(bank->irq, tz1090_gpio_irq_handler); 513 + irq_set_chained_handler_and_data(bank->irq, tz1090_gpio_irq_handler, 514 + bank); 515 515 516 516 return 0; 517 517 }
+9 -2
drivers/gpio/gpio-vf610.c
··· 60 60 #define PORT_INT_EITHER_EDGE 0xb 61 61 #define PORT_INT_LOGIC_ONE 0xc 62 62 63 + static struct irq_chip vf610_gpio_irq_chip; 64 + 63 65 static const struct of_device_id vf610_gpio_dt_ids[] = { 64 66 { .compatible = "fsl,vf610-gpio" }, 65 67 { /* sentinel */ } ··· 122 120 123 121 static void vf610_gpio_irq_handler(u32 irq, struct irq_desc *desc) 124 122 { 125 - struct vf610_gpio_port *port = irq_get_handler_data(irq); 123 + struct vf610_gpio_port *port = irq_desc_get_handler_data(desc); 126 124 struct irq_chip *chip = irq_desc_get_chip(desc); 127 125 int pin; 128 126 unsigned long irq_isfr; ··· 174 172 } 175 173 176 174 port->irqc[d->hwirq] = irqc; 175 + 176 + if (type & IRQ_TYPE_LEVEL_MASK) 177 + __irq_set_handler_locked(d->irq, handle_level_irq); 178 + else 179 + __irq_set_handler_locked(d->irq, handle_edge_irq); 177 180 178 181 return 0; 179 182 } ··· 270 263 vf610_gpio_writel(~0, port->base + PORT_ISFR); 271 264 272 265 ret = gpiochip_irqchip_add(gc, &vf610_gpio_irq_chip, 0, 273 - handle_simple_irq, IRQ_TYPE_NONE); 266 + handle_edge_irq, IRQ_TYPE_NONE); 274 267 if (ret) { 275 268 dev_err(dev, "failed to add irqchip\n"); 276 269 gpiochip_remove(gc);
+1 -1
drivers/gpio/gpio-xlp.c
··· 387 387 irq_base = irq_alloc_descs(-1, XLP_GPIO_IRQ_BASE, gc->ngpio, 0); 388 388 if (irq_base < 0) { 389 389 dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n"); 390 - return err; 390 + return -ENODEV; 391 391 } 392 392 393 393 err = gpiochip_add(gc);
+324
drivers/gpio/gpio-zx.c
··· 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 + 39 + struct zx_gpio { 40 + spinlock_t lock; 41 + 42 + void __iomem *base; 43 + struct gpio_chip gc; 44 + bool uses_pinctrl; 45 + }; 46 + 47 + static inline struct zx_gpio *to_zx(struct gpio_chip *gc) 48 + { 49 + return container_of(gc, struct zx_gpio, gc); 50 + } 51 + 52 + static 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 + 62 + static 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 + 71 + static 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 + 89 + static 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 + 113 + static 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 + 120 + static 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 + 130 + static 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 + 180 + static 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 + 201 + static 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 + 216 + static 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 + 231 + static 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 + 238 + static 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 + 304 + static const struct of_device_id zx_gpio_match[] = { 305 + { 306 + .compatible = "zte,zx296702-gpio", 307 + }, 308 + { }, 309 + }; 310 + MODULE_DEVICE_TABLE(of, zx_gpio_match); 311 + 312 + static 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 + 320 + module_platform_driver(zx_gpio_driver) 321 + 322 + MODULE_AUTHOR("Jun Nie <jun.nie@linaro.org>"); 323 + MODULE_DESCRIPTION("ZTE ZX296702 GPIO driver"); 324 + MODULE_LICENSE("GPL");
+9 -3
drivers/gpio/gpio-zynq.c
··· 441 441 gpio->base_addr + ZYNQ_GPIO_INTANY_OFFSET(bank_num)); 442 442 443 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 445 &zynq_gpio_level_irqchip, handle_fasteoi_irq, NULL); 446 446 } else { 447 - __irq_set_chip_handler_name_locked(irq_data->irq, 447 + irq_set_chip_handler_name_locked(irq_data, 448 448 &zynq_gpio_edge_irqchip, handle_level_irq, NULL); 449 449 } 450 450 ··· 518 518 { 519 519 u32 int_sts, int_enb; 520 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 522 struct irq_chip *irqchip = irq_desc_get_chip(desc); 523 523 524 524 chained_irq_enter(irqchip, desc); ··· 781 781 return platform_driver_register(&zynq_gpio_driver); 782 782 } 783 783 postcore_initcall(zynq_gpio_init); 784 + 785 + static void __exit zynq_gpio_exit(void) 786 + { 787 + platform_driver_unregister(&zynq_gpio_driver); 788 + } 789 + module_exit(zynq_gpio_exit); 784 790 785 791 MODULE_AUTHOR("Xilinx Inc."); 786 792 MODULE_DESCRIPTION("Zynq GPIO driver");
+20 -14
drivers/gpio/gpiolib-of.c
··· 136 136 { 137 137 struct device_node *chip_np; 138 138 enum of_gpio_flags xlate_flags; 139 - struct gpio_desc *desc; 140 139 struct gg_data gg_data = { 141 140 .flags = &xlate_flags, 142 141 }; ··· 192 193 if (name && of_property_read_string(np, "line-name", name)) 193 194 *name = np->name; 194 195 195 - desc = gg_data.out_gpio; 196 - 197 - return desc; 196 + return gg_data.out_gpio; 198 197 } 199 198 200 199 /** ··· 335 338 EXPORT_SYMBOL(of_mm_gpiochip_remove); 336 339 337 340 #ifdef CONFIG_PINCTRL 338 - static void of_gpiochip_add_pin_range(struct gpio_chip *chip) 341 + static int of_gpiochip_add_pin_range(struct gpio_chip *chip) 339 342 { 340 343 struct device_node *np = chip->of_node; 341 344 struct of_phandle_args pinspec; ··· 346 349 struct property *group_names; 347 350 348 351 if (!np) 349 - return; 352 + return 0; 350 353 351 354 group_names = of_find_property(np, group_names_propname, NULL); 352 355 ··· 358 361 359 362 pctldev = of_pinctrl_get(pinspec.np); 360 363 if (!pctldev) 361 - break; 364 + return -EPROBE_DEFER; 362 365 363 366 if (pinspec.args[2]) { 364 367 if (group_names) { 365 - ret = of_property_read_string_index(np, 368 + of_property_read_string_index(np, 366 369 group_names_propname, 367 370 index, &name); 368 371 if (strlen(name)) { ··· 378 381 pinspec.args[1], 379 382 pinspec.args[2]); 380 383 if (ret) 381 - break; 384 + return ret; 382 385 } else { 383 386 /* npins == 0: special range */ 384 387 if (pinspec.args[1]) { ··· 408 411 ret = gpiochip_add_pingroup_range(chip, pctldev, 409 412 pinspec.args[0], name); 410 413 if (ret) 411 - break; 414 + return ret; 412 415 } 413 416 } 417 + 418 + return 0; 414 419 } 415 420 416 421 #else 417 - static void of_gpiochip_add_pin_range(struct gpio_chip *chip) {} 422 + static int of_gpiochip_add_pin_range(struct gpio_chip *chip) { return 0; } 418 423 #endif 419 424 420 - void of_gpiochip_add(struct gpio_chip *chip) 425 + int of_gpiochip_add(struct gpio_chip *chip) 421 426 { 427 + int status; 428 + 422 429 if ((!chip->of_node) && (chip->dev)) 423 430 chip->of_node = chip->dev->of_node; 424 431 425 432 if (!chip->of_node) 426 - return; 433 + return 0; 427 434 428 435 if (!chip->of_xlate) { 429 436 chip->of_gpio_n_cells = 2; 430 437 chip->of_xlate = of_gpio_simple_xlate; 431 438 } 432 439 433 - of_gpiochip_add_pin_range(chip); 440 + status = of_gpiochip_add_pin_range(chip); 441 + if (status) 442 + return status; 443 + 434 444 of_node_get(chip->of_node); 435 445 436 446 of_gpiochip_scan_hogs(chip); 447 + 448 + return 0; 437 449 } 438 450 439 451 void of_gpiochip_remove(struct gpio_chip *chip)
+49 -35
drivers/gpio/gpiolib.c
··· 190 190 */ 191 191 static int gpiochip_add_to_list(struct gpio_chip *chip) 192 192 { 193 - struct list_head *pos = &gpio_chips; 193 + struct list_head *pos; 194 194 struct gpio_chip *_chip; 195 195 int err = 0; 196 196 ··· 287 287 INIT_LIST_HEAD(&chip->pin_ranges); 288 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 297 acpi_gpiochip_add(chip); 292 298 293 299 status = gpiochip_sysfs_register(chip); ··· 449 443 * The parent irqchip is already using the chip_data for this 450 444 * irqchip, so our callbacks simply use the handler_data. 451 445 */ 452 - irq_set_handler_data(parent_irq, gpiochip); 453 - irq_set_chained_handler(parent_irq, parent_handler); 446 + irq_set_chained_handler_and_data(parent_irq, parent_handler, 447 + gpiochip); 454 448 455 449 gpiochip->irq_parent = parent_irq; 456 450 } ··· 461 455 parent_irq); 462 456 } 463 457 EXPORT_SYMBOL_GPL(gpiochip_set_chained_irqchip); 464 - 465 - /* 466 - * This lock class tells lockdep that GPIO irqs are in a different 467 - * category than their parents, so it won't report false recursion. 468 - */ 469 - static struct lock_class_key gpiochip_irq_lock_class; 470 458 471 459 /** 472 460 * gpiochip_irq_map() - maps an IRQ into a GPIO irqchip ··· 478 478 struct gpio_chip *chip = d->host_data; 479 479 480 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 486 irq_set_chip_and_handler(irq, chip->irqchip, chip->irq_handler); 483 487 /* Chips that can sleep need nested thread handlers */ 484 488 if (chip->can_sleep && !chip->irq_not_threaded) 485 489 irq_set_nested_thread(irq, 1); 486 - #ifdef CONFIG_ARM 487 - set_irq_flags(irq, IRQF_VALID); 488 - #else 489 490 irq_set_noprobe(irq); 490 - #endif 491 + 491 492 /* 492 493 * No set-up of the hardware will happen if IRQ_TYPE_NONE 493 494 * is passed as default type. ··· 503 502 { 504 503 struct gpio_chip *chip = d->host_data; 505 504 506 - #ifdef CONFIG_ARM 507 - set_irq_flags(irq, 0); 508 - #endif 509 505 if (chip->can_sleep) 510 506 irq_set_nested_thread(irq, 0); 511 507 irq_set_chip_and_handler(irq, NULL, NULL); ··· 520 522 { 521 523 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 522 524 525 + if (!try_module_get(chip->owner)) 526 + return -ENODEV; 527 + 523 528 if (gpiochip_lock_as_irq(chip, d->hwirq)) { 524 529 chip_err(chip, 525 530 "unable to lock HW IRQ %lu for IRQ\n", 526 531 d->hwirq); 532 + module_put(chip->owner); 527 533 return -EINVAL; 528 534 } 529 535 return 0; ··· 538 536 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 539 537 540 538 gpiochip_unlock_as_irq(chip, d->hwirq); 539 + module_put(chip->owner); 541 540 } 542 541 543 542 static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset) ··· 587 584 * @handler: the irq handler to use (often a predefined irq core function) 588 585 * @type: the default type for IRQs on this irqchip, pass IRQ_TYPE_NONE 589 586 * to have the core avoid setting up any default type in the hardware. 587 + * @lock_key: lockdep class 590 588 * 591 589 * This function closely associates a certain irqchip with a certain 592 590 * gpiochip, providing an irq domain to translate the local IRQs to ··· 603 599 * the pins on the gpiochip can generate a unique IRQ. Everything else 604 600 * need to be open coded. 605 601 */ 606 - int gpiochip_irqchip_add(struct gpio_chip *gpiochip, 607 - struct irq_chip *irqchip, 608 - unsigned int first_irq, 609 - irq_flow_handler_t handler, 610 - unsigned int type) 602 + int _gpiochip_irqchip_add(struct gpio_chip *gpiochip, 603 + struct irq_chip *irqchip, 604 + unsigned int first_irq, 605 + irq_flow_handler_t handler, 606 + unsigned int type, 607 + struct lock_class_key *lock_key) 611 608 { 612 609 struct device_node *of_node; 613 610 unsigned int offset; ··· 634 629 gpiochip->irq_handler = handler; 635 630 gpiochip->irq_default_type = type; 636 631 gpiochip->to_irq = gpiochip_to_irq; 632 + gpiochip->lock_key = lock_key; 637 633 gpiochip->irqdomain = irq_domain_add_simple(of_node, 638 634 gpiochip->ngpio, first_irq, 639 635 &gpiochip_domain_ops, gpiochip); ··· 642 636 gpiochip->irqchip = NULL; 643 637 return -EINVAL; 644 638 } 645 - irqchip->irq_request_resources = gpiochip_irq_reqres; 646 - irqchip->irq_release_resources = gpiochip_irq_relres; 639 + 640 + /* 641 + * It is possible for a driver to override this, but only if the 642 + * alternative functions are both implemented. 643 + */ 644 + if (!irqchip->irq_request_resources && 645 + !irqchip->irq_release_resources) { 646 + irqchip->irq_request_resources = gpiochip_irq_reqres; 647 + irqchip->irq_release_resources = gpiochip_irq_relres; 648 + } 647 649 648 650 /* 649 651 * Prepare the mapping since the irqchip shall be orthogonal to ··· 672 658 673 659 return 0; 674 660 } 675 - EXPORT_SYMBOL_GPL(gpiochip_irqchip_add); 661 + EXPORT_SYMBOL_GPL(_gpiochip_irqchip_add); 676 662 677 663 #else /* CONFIG_GPIOLIB_IRQCHIP */ 678 664 ··· 685 671 /** 686 672 * gpiochip_add_pingroup_range() - add a range for GPIO <-> pin mapping 687 673 * @chip: the gpiochip to add the range for 688 - * @pinctrl: the dev_name() of the pin controller to map to 674 + * @pctldev: the pin controller to map to 689 675 * @gpio_offset: the start offset in the current gpio_chip number space 690 676 * @pin_group: name of the pin group inside the pin controller 691 677 */ ··· 1908 1894 * dev, -ENOENT if no GPIO has been assigned to the requested function, or 1909 1895 * another IS_ERR() code if an error occurred while trying to acquire the GPIO. 1910 1896 */ 1911 - struct gpio_desc *__must_check __gpiod_get(struct device *dev, const char *con_id, 1897 + struct gpio_desc *__must_check gpiod_get(struct device *dev, const char *con_id, 1912 1898 enum gpiod_flags flags) 1913 1899 { 1914 1900 return gpiod_get_index(dev, con_id, 0, flags); 1915 1901 } 1916 - EXPORT_SYMBOL_GPL(__gpiod_get); 1902 + EXPORT_SYMBOL_GPL(gpiod_get); 1917 1903 1918 1904 /** 1919 1905 * gpiod_get_optional - obtain an optional GPIO for a given GPIO function ··· 1925 1911 * the requested function it will return NULL. This is convenient for drivers 1926 1912 * that need to handle optional GPIOs. 1927 1913 */ 1928 - struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev, 1914 + struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, 1929 1915 const char *con_id, 1930 1916 enum gpiod_flags flags) 1931 1917 { 1932 1918 return gpiod_get_index_optional(dev, con_id, 0, flags); 1933 1919 } 1934 - EXPORT_SYMBOL_GPL(__gpiod_get_optional); 1920 + EXPORT_SYMBOL_GPL(gpiod_get_optional); 1935 1921 1936 1922 1937 1923 /** ··· 1988 1974 * requested function and/or index, or another IS_ERR() code if an error 1989 1975 * occurred while trying to acquire the GPIO. 1990 1976 */ 1991 - struct gpio_desc *__must_check __gpiod_get_index(struct device *dev, 1977 + struct gpio_desc *__must_check gpiod_get_index(struct device *dev, 1992 1978 const char *con_id, 1993 1979 unsigned int idx, 1994 1980 enum gpiod_flags flags) ··· 2037 2023 2038 2024 return desc; 2039 2025 } 2040 - EXPORT_SYMBOL_GPL(__gpiod_get_index); 2026 + EXPORT_SYMBOL_GPL(gpiod_get_index); 2041 2027 2042 2028 /** 2043 2029 * fwnode_get_named_gpiod - obtain a GPIO from firmware node ··· 2106 2092 * specified index was assigned to the requested function it will return NULL. 2107 2093 * This is convenient for drivers that need to handle optional GPIOs. 2108 2094 */ 2109 - struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, 2095 + struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev, 2110 2096 const char *con_id, 2111 2097 unsigned int index, 2112 2098 enum gpiod_flags flags) ··· 2121 2107 2122 2108 return desc; 2123 2109 } 2124 - EXPORT_SYMBOL_GPL(__gpiod_get_index_optional); 2110 + EXPORT_SYMBOL_GPL(gpiod_get_index_optional); 2125 2111 2126 2112 /** 2127 2113 * gpiod_hog - Hog the specified GPIO desc given the provided flags
+2 -15
drivers/gpu/drm/msm/edp/edp_ctrl.c
··· 373 373 struct device *dev = &ctrl->pdev->dev; 374 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 377 if (IS_ERR(ctrl->panel_hpd_gpio)) { 378 378 ret = PTR_ERR(ctrl->panel_hpd_gpio); 379 379 ctrl->panel_hpd_gpio = NULL; ··· 381 381 return ret; 382 382 } 383 383 384 - ret = gpiod_direction_input(ctrl->panel_hpd_gpio); 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"); 384 + ctrl->panel_en_gpio = devm_gpiod_get(dev, "panel-en", GPIOD_OUT_LOW); 391 385 if (IS_ERR(ctrl->panel_en_gpio)) { 392 386 ret = PTR_ERR(ctrl->panel_en_gpio); 393 387 ctrl->panel_en_gpio = NULL; 394 388 pr_err("%s: cannot get panel-en-gpios, %d\n", __func__, ret); 395 - return ret; 396 - } 397 - 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 389 return ret; 403 390 } 404 391
+7 -15
drivers/gpu/drm/tilcdc/tilcdc_panel.c
··· 375 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 380 if (IS_ERR(panel_mod->enable_gpio)) { 380 381 ret = PTR_ERR(panel_mod->enable_gpio); 381 - if (ret != -ENOENT) { 382 - dev_err(&pdev->dev, "failed to request enable GPIO\n"); 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"); 382 + dev_err(&pdev->dev, "failed to request enable GPIO\n"); 383 + goto fail_backlight; 395 384 } 385 + 386 + if (panel_mod->enable_gpio) 387 + dev_info(&pdev->dev, "found enable GPIO\n"); 396 388 397 389 mod = &panel_mod->base; 398 390 pdev->dev.platform_data = mod;
+1 -5
drivers/iio/light/stk3310.c
··· 469 469 dev = &client->dev; 470 470 471 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 473 if (IS_ERR(gpio)) { 474 474 dev_err(dev, "acpi gpio get index failed\n"); 475 475 return PTR_ERR(gpio); 476 476 } 477 - 478 - ret = gpiod_direction_input(gpio); 479 - if (ret) 480 - return ret; 481 477 482 478 ret = gpiod_to_irq(gpio); 483 479 dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
+1 -5
drivers/iio/magnetometer/bmc150_magn.c
··· 845 845 dev = &client->dev; 846 846 847 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 849 if (IS_ERR(gpio)) { 850 850 dev_err(dev, "ACPI GPIO get index failed\n"); 851 851 return PTR_ERR(gpio); 852 852 } 853 - 854 - ret = gpiod_direction_input(gpio); 855 - if (ret) 856 - return ret; 857 853 858 854 ret = gpiod_to_irq(gpio); 859 855
+1 -1
drivers/media/i2c/adp1653.c
··· 465 465 466 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 469 if (!pd->enable_gpio) { 470 470 dev_err(&client->dev, "Error getting GPIO\n"); 471 471 return -EINVAL;
+3 -7
drivers/nfc/nxp-nci/i2c.c
··· 318 318 struct i2c_client *client = phy->i2c_dev; 319 319 struct gpio_desc *gpiod_en, *gpiod_fw, *gpiod_irq; 320 320 321 - gpiod_en = devm_gpiod_get_index(&client->dev, NULL, 2); 322 - gpiod_fw = devm_gpiod_get_index(&client->dev, NULL, 1); 323 - gpiod_irq = devm_gpiod_get_index(&client->dev, NULL, 0); 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, GPIOD_OUT_LOW); 323 + gpiod_irq = devm_gpiod_get_index(&client->dev, NULL, 0, GPIOD_IN); 324 324 325 325 if (IS_ERR(gpiod_en) || IS_ERR(gpiod_fw) || IS_ERR(gpiod_irq)) { 326 326 nfc_err(&client->dev, "No GPIOs\n"); 327 327 return -EINVAL; 328 328 } 329 - 330 - gpiod_direction_output(gpiod_en, 0); 331 - gpiod_direction_output(gpiod_fw, 0); 332 - gpiod_direction_input(gpiod_irq); 333 329 334 330 client->irq = gpiod_to_irq(gpiod_irq); 335 331 if (client->irq < 0) {
+12 -18
drivers/phy/phy-tusb1210.c
··· 61 61 62 62 static int tusb1210_probe(struct ulpi *ulpi) 63 63 { 64 - struct gpio_desc *gpio; 65 64 struct tusb1210 *tusb; 66 65 u8 val, reg; 67 - int ret; 68 66 69 67 tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL); 70 68 if (!tusb) 71 69 return -ENOMEM; 72 70 73 - gpio = devm_gpiod_get(&ulpi->dev, "reset"); 74 - if (!IS_ERR(gpio)) { 75 - ret = gpiod_direction_output(gpio, 0); 76 - if (ret) 77 - return ret; 78 - gpiod_set_value_cansleep(gpio, 1); 79 - tusb->gpio_reset = gpio; 80 - } 71 + tusb->gpio_reset = devm_gpiod_get_optional(&ulpi->dev, "reset", 72 + GPIOD_OUT_LOW); 73 + if (IS_ERR(tusb->gpio_reset)) 74 + return PTR_ERR(tusb->gpio_reset); 81 75 82 - gpio = devm_gpiod_get(&ulpi->dev, "cs"); 83 - if (!IS_ERR(gpio)) { 84 - ret = gpiod_direction_output(gpio, 0); 85 - if (ret) 86 - return ret; 87 - gpiod_set_value_cansleep(gpio, 1); 88 - tusb->gpio_cs = gpio; 89 - } 76 + gpiod_set_value_cansleep(tusb->gpio_reset, 1); 77 + 78 + tusb->gpio_cs = devm_gpiod_get_optional(&ulpi->dev, "cs", 79 + GPIOD_OUT_LOW); 80 + if (IS_ERR(tusb->gpio_cs)) 81 + return PTR_ERR(tusb->gpio_cs); 82 + 83 + gpiod_set_value_cansleep(tusb->gpio_cs, 1); 90 84 91 85 /* 92 86 * VENDOR_SPECIFIC2 register in TUSB1210 can be used for configuring eye
+1
include/linux/basic_mmio_gpio.h
··· 75 75 #define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */ 76 76 #define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3) 77 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 80 #endif /* __BASIC_MMIO_GPIO_H */
+28 -64
include/linux/gpio/consumer.h
··· 47 47 int gpiod_count(struct device *dev, const char *con_id); 48 48 49 49 /* Acquire and dispose GPIOs */ 50 - struct gpio_desc *__must_check __gpiod_get(struct device *dev, 50 + struct gpio_desc *__must_check gpiod_get(struct device *dev, 51 51 const char *con_id, 52 52 enum gpiod_flags flags); 53 - struct gpio_desc *__must_check __gpiod_get_index(struct device *dev, 53 + struct gpio_desc *__must_check gpiod_get_index(struct device *dev, 54 54 const char *con_id, 55 55 unsigned int idx, 56 56 enum gpiod_flags flags); 57 - struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev, 57 + struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, 58 58 const char *con_id, 59 59 enum gpiod_flags flags); 60 - struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, 60 + struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev, 61 61 const char *con_id, 62 62 unsigned int index, 63 63 enum gpiod_flags flags); ··· 70 70 void gpiod_put(struct gpio_desc *desc); 71 71 void gpiod_put_array(struct gpio_descs *descs); 72 72 73 - struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, 73 + struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, 74 74 const char *con_id, 75 75 enum gpiod_flags flags); 76 - struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev, 76 + struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, 77 77 const char *con_id, 78 78 unsigned int idx, 79 79 enum gpiod_flags flags); 80 - struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, 80 + struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, 81 81 const char *con_id, 82 82 enum gpiod_flags flags); 83 83 struct gpio_desc *__must_check 84 - __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 84 + devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 85 85 unsigned int index, enum gpiod_flags flags); 86 86 struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev, 87 87 const char *con_id, ··· 146 146 return 0; 147 147 } 148 148 149 - static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev, 150 - const char *con_id, 151 - enum gpiod_flags flags) 149 + static inline struct gpio_desc *__must_check gpiod_get(struct device *dev, 150 + const char *con_id, 151 + enum gpiod_flags flags) 152 152 { 153 153 return ERR_PTR(-ENOSYS); 154 154 } 155 155 static inline struct gpio_desc *__must_check 156 - __gpiod_get_index(struct device *dev, 157 - const char *con_id, 158 - unsigned int idx, 159 - enum gpiod_flags flags) 160 - { 161 - return ERR_PTR(-ENOSYS); 162 - } 163 - 164 - static inline struct gpio_desc *__must_check 165 - __gpiod_get_optional(struct device *dev, const char *con_id, 166 - enum gpiod_flags flags) 156 + gpiod_get_index(struct device *dev, 157 + const char *con_id, 158 + unsigned int idx, 159 + enum gpiod_flags flags) 167 160 { 168 161 return ERR_PTR(-ENOSYS); 169 162 } 170 163 171 164 static inline struct gpio_desc *__must_check 172 - __gpiod_get_index_optional(struct device *dev, const char *con_id, 173 - unsigned int index, enum gpiod_flags flags) 165 + gpiod_get_optional(struct device *dev, const char *con_id, 166 + enum gpiod_flags flags) 167 + { 168 + return ERR_PTR(-ENOSYS); 169 + } 170 + 171 + static inline struct gpio_desc *__must_check 172 + gpiod_get_index_optional(struct device *dev, const char *con_id, 173 + unsigned int index, enum gpiod_flags flags) 174 174 { 175 175 return ERR_PTR(-ENOSYS); 176 176 } ··· 206 206 } 207 207 208 208 static inline struct gpio_desc *__must_check 209 - __devm_gpiod_get(struct device *dev, 209 + devm_gpiod_get(struct device *dev, 210 210 const char *con_id, 211 211 enum gpiod_flags flags) 212 212 { ··· 214 214 } 215 215 static inline 216 216 struct gpio_desc *__must_check 217 - __devm_gpiod_get_index(struct device *dev, 217 + devm_gpiod_get_index(struct device *dev, 218 218 const char *con_id, 219 219 unsigned int idx, 220 220 enum gpiod_flags flags) ··· 223 223 } 224 224 225 225 static inline struct gpio_desc *__must_check 226 - __devm_gpiod_get_optional(struct device *dev, const char *con_id, 226 + devm_gpiod_get_optional(struct device *dev, const char *con_id, 227 227 enum gpiod_flags flags) 228 228 { 229 229 return ERR_PTR(-ENOSYS); 230 230 } 231 231 232 232 static inline struct gpio_desc *__must_check 233 - __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 233 + devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 234 234 unsigned int index, enum gpiod_flags flags) 235 235 { 236 236 return ERR_PTR(-ENOSYS); ··· 423 423 } 424 424 425 425 #endif /* CONFIG_GPIOLIB */ 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 426 463 427 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) 464 428
+32 -5
include/linux/gpio/driver.h
··· 6 6 #include <linux/irq.h> 7 7 #include <linux/irqchip/chained_irq.h> 8 8 #include <linux/irqdomain.h> 9 + #include <linux/lockdep.h> 9 10 #include <linux/pinctrl/pinctrl.h> 10 11 11 12 struct device; ··· 65 64 * registers. 66 65 * @irq_not_threaded: flag must be set if @can_sleep is set but the 67 66 * IRQs don't need to be threaded 67 + * @irqchip: GPIO IRQ chip impl, provided by GPIO driver 68 + * @irqdomain: Interrupt translation domain; responsible for mapping 69 + * between GPIO hwirq number and linux irq number 70 + * @irq_base: first linux IRQ number assigned to GPIO IRQ chip (deprecated) 71 + * @irq_handler: the irq handler to use (often a predefined irq core function) 72 + * for GPIO IRQs, provided by GPIO driver 73 + * @irq_default_type: default IRQ triggering type applied during GPIO driver 74 + * initialization, provided by GPIO driver 75 + * @irq_parent: GPIO IRQ chip parent/bank linux irq number, 76 + * provided by GPIO driver 77 + * @lock_key: per GPIO IRQ chip lockdep class 68 78 * 69 79 * A gpio_chip can help platforms abstract various sources of GPIOs so 70 80 * they can all be accessed through a common programing interface. ··· 138 126 irq_flow_handler_t irq_handler; 139 127 unsigned int irq_default_type; 140 128 int irq_parent; 129 + struct lock_class_key *lock_key; 141 130 #endif 142 131 143 132 #if defined(CONFIG_OF_GPIO) ··· 184 171 int parent_irq, 185 172 irq_flow_handler_t parent_handler); 186 173 187 - int gpiochip_irqchip_add(struct gpio_chip *gpiochip, 188 - struct irq_chip *irqchip, 189 - unsigned int first_irq, 190 - irq_flow_handler_t handler, 191 - unsigned int type); 174 + int _gpiochip_irqchip_add(struct gpio_chip *gpiochip, 175 + struct irq_chip *irqchip, 176 + unsigned int first_irq, 177 + irq_flow_handler_t handler, 178 + unsigned int type, 179 + struct lock_class_key *lock_key); 180 + 181 + #ifdef CONFIG_LOCKDEP 182 + #define gpiochip_irqchip_add(...) \ 183 + ( \ 184 + ({ \ 185 + static struct lock_class_key _key; \ 186 + _gpiochip_irqchip_add(__VA_ARGS__, &_key); \ 187 + }) \ 188 + ) 189 + #else 190 + #define gpiochip_irqchip_add(...) \ 191 + _gpiochip_irqchip_add(__VA_ARGS__, NULL) 192 + #endif 192 193 193 194 #endif /* CONFIG_GPIOLIB_IRQCHIP */ 194 195
+2 -2
include/linux/of_gpio.h
··· 54 54 struct of_mm_gpio_chip *mm_gc); 55 55 extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc); 56 56 57 - extern void of_gpiochip_add(struct gpio_chip *gc); 57 + extern int of_gpiochip_add(struct gpio_chip *gc); 58 58 extern void of_gpiochip_remove(struct gpio_chip *gc); 59 59 extern int of_gpio_simple_xlate(struct gpio_chip *gc, 60 60 const struct of_phandle_args *gpiospec, ··· 76 76 return -ENOSYS; 77 77 } 78 78 79 - static inline void of_gpiochip_add(struct gpio_chip *gc) { } 79 + static inline int of_gpiochip_add(struct gpio_chip *gc) { return 0; } 80 80 static inline void of_gpiochip_remove(struct gpio_chip *gc) { } 81 81 82 82 #endif /* CONFIG_OF_GPIO */
-11
include/linux/platform_data/gpio-em.h
··· 1 - #ifndef __GPIO_EM_H__ 2 - #define __GPIO_EM_H__ 3 - 4 - struct 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__ */