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

Merge tag 'gpio-v3.19-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio

Pull take two of the GPIO updates:
"Same stuff as last time, now with a fixup patch for the previous
compile error plus I ran a few extra rounds of compile-testing.

This is the bulk of GPIO changes for the v3.19 series:

- A new API that allows setting more than one GPIO at the time. This
is implemented for the new descriptor-based API only and makes it
possible to e.g. toggle a clock and data line at the same time, if
the hardware can do this with a single register write. Both
consumers and drivers need new calls, and the core will fall back
to driving individual lines where needed. Implemented for the
MPC8xxx driver initially

- Patched the mdio-mux-gpio and the serial mctrl driver that drives
modems to use the new multiple-setting API to set several signals
simultaneously

- Get rid of the global GPIO descriptor array, and instead allocate
descriptors dynamically for each GPIO on a certain GPIO chip. This
moves us closer to getting rid of the limitation of using the
global, static GPIO numberspace

- New driver and device tree bindings for 74xx ICs

- New driver and device tree bindings for the VF610 Vybrid

- Support the RCAR r8a7793 and r8a7794

- Guidelines for GPIO device tree bindings trying to get things a bit
more strict with the advent of combined device properties

- Suspend/resume support for the MVEBU driver

- A slew of minor fixes and improvements"

* tag 'gpio-v3.19-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (33 commits)
gpio: mcp23s08: fix up compilation error
gpio: pl061: document gpio-ranges property for bindings file
gpio: pl061: hook request if gpio-ranges avaiable
gpio: mcp23s08: Add option to configure IRQ output polarity as active high
gpio: fix deferred probe detection for legacy API
serial: mctrl_gpio: use gpiod_set_array function
mdio-mux-gpio: Use GPIO descriptor interface and new gpiod_set_array function
gpio: remove const modifier from gpiod_get_direction()
gpio: remove gpio_descs global array
gpio: mxs: implement get_direction callback
gpio: em: Use dynamic allocation of GPIOs
gpio: Check if base is positive before calling gpio_is_valid()
gpio: mcp23s08: Add simple IRQ support for SPI devices
gpio: mcp23s08: request a shared interrupt
gpio: mcp23s08: Do not free unrequested interrupt
gpio: rcar: Add r8a7793 and r8a7794 support
gpio-mpc8xxx: add mpc8xxx_gpio_set_multiple function
gpiolib: allow simultaneous setting of multiple GPIO outputs
gpio: mvebu: add suspend/resume support
gpio: gpio-davinci: remove duplicate check on resource
..

+1165 -161
+30
Documentation/devicetree/bindings/gpio/gpio-74xx-mmio.txt
··· 1 + * 74XX MMIO GPIO driver 2 + 3 + Required properties: 4 + - compatible: Should contain one of the following: 5 + "ti,741g125": for 741G125 (1-bit Input), 6 + "ti,741g174": for 741G74 (1-bit Output), 7 + "ti,742g125": for 742G125 (2-bit Input), 8 + "ti,7474" : for 7474 (2-bit Output), 9 + "ti,74125" : for 74125 (4-bit Input), 10 + "ti,74175" : for 74175 (4-bit Output), 11 + "ti,74365" : for 74365 (6-bit Input), 12 + "ti,74174" : for 74174 (6-bit Output), 13 + "ti,74244" : for 74244 (8-bit Input), 14 + "ti,74273" : for 74273 (8-bit Output), 15 + "ti,741624" : for 741624 (16-bit Input), 16 + "ti,7416374": for 7416374 (16-bit Output). 17 + - reg: Physical base address and length where IC resides. 18 + - gpio-controller: Marks the device node as a gpio controller. 19 + - #gpio-cells: Should be two. The first cell is the pin number and 20 + the second cell is used to specify the GPIO polarity: 21 + 0 = Active High, 22 + 1 = Active Low. 23 + 24 + Example: 25 + ctrl: gpio@30008004 { 26 + compatible = "ti,74174"; 27 + reg = <0x30008004 0x1>; 28 + gpio-controller; 29 + #gpio-cells = <2>; 30 + };
+2
Documentation/devicetree/bindings/gpio/gpio-mcp23s08.txt
··· 57 57 occurred on. If it is not set, the interrupt are only generated for the 58 58 bank they belong to. 59 59 On devices with only one interrupt output this property is useless. 60 + - microchip,irq-active-high: Sets the INTPOL flag in the IOCON register. This 61 + configures the IRQ output polarity as active high. 60 62 61 63 Example I2C (with interrupt): 62 64 gpiom1: gpio@20 {
+55
Documentation/devicetree/bindings/gpio/gpio-vf610.txt
··· 1 + * Freescale VF610 PORT/GPIO module 2 + 3 + The Freescale PORT/GPIO modules are two adjacent modules providing GPIO 4 + functionality. Each pair serves 32 GPIOs. The VF610 has 5 instances of 5 + each, and each PORT module has its own interrupt. 6 + 7 + Required properties for GPIO node: 8 + - compatible : Should be "fsl,<soc>-gpio", currently "fsl,vf610-gpio" 9 + - reg : The first reg tuple represents the PORT module, the second tuple 10 + the GPIO module. 11 + - interrupts : Should be the port interrupt shared by all 32 pins. 12 + - gpio-controller : Marks the device node as a gpio controller. 13 + - #gpio-cells : Should be two. The first cell is the pin number and 14 + the second cell is used to specify the gpio polarity: 15 + 0 = active high 16 + 1 = active low 17 + - interrupt-controller: Marks the device node as an interrupt controller. 18 + - #interrupt-cells : Should be 2. The first cell is the GPIO number. 19 + The second cell bits[3:0] is used to specify trigger type and level flags: 20 + 1 = low-to-high edge triggered. 21 + 2 = high-to-low edge triggered. 22 + 4 = active high level-sensitive. 23 + 8 = active low level-sensitive. 24 + 25 + Note: Each GPIO port should have an alias correctly numbered in "aliases" 26 + node. 27 + 28 + Examples: 29 + 30 + aliases { 31 + gpio0 = &gpio1; 32 + gpio1 = &gpio2; 33 + }; 34 + 35 + gpio1: gpio@40049000 { 36 + compatible = "fsl,vf610-gpio"; 37 + reg = <0x40049000 0x1000 0x400ff000 0x40>; 38 + interrupts = <0 107 IRQ_TYPE_LEVEL_HIGH>; 39 + gpio-controller; 40 + #gpio-cells = <2>; 41 + interrupt-controller; 42 + #interrupt-cells = <2>; 43 + gpio-ranges = <&iomuxc 0 0 32>; 44 + }; 45 + 46 + gpio2: gpio@4004a000 { 47 + compatible = "fsl,vf610-gpio"; 48 + reg = <0x4004a000 0x1000 0x400ff040 0x40>; 49 + interrupts = <0 108 IRQ_TYPE_LEVEL_HIGH>; 50 + gpio-controller; 51 + #gpio-cells = <2>; 52 + interrupt-controller; 53 + #interrupt-cells = <2>; 54 + gpio-ranges = <&iomuxc 0 32 32>; 55 + };
+26 -14
Documentation/devicetree/bindings/gpio/gpio.txt
··· 13 13 gpio-specifier : Array of #gpio-cells specifying specific gpio 14 14 (controller specific) 15 15 16 - GPIO properties should be named "[<name>-]gpios". The exact 17 - meaning of each gpios property must be documented in the device tree 18 - binding for each device. 16 + GPIO properties should be named "[<name>-]gpios", with <name> being the purpose 17 + of this GPIO for the device. While a non-existent <name> is considered valid 18 + for compatibility reasons (resolving to the "gpios" property), it is not allowed 19 + for new bindings. 19 20 20 - For example, the following could be used to describe GPIO pins used 21 - as chip select lines; with chip selects 0, 1 and 3 populated, and chip 22 - select 2 left empty: 21 + GPIO properties can contain one or more GPIO phandles, but only in exceptional 22 + cases should they contain more than one. If your device uses several GPIOs with 23 + distinct functions, reference each of them under its own property, giving it a 24 + meaningful name. The only case where an array of GPIOs is accepted is when 25 + several GPIOs serve the same function (e.g. a parallel data line). 26 + 27 + The exact purpose of each gpios property must be documented in the device tree 28 + binding of the device. 29 + 30 + The following example could be used to describe GPIO pins used as device enable 31 + and bit-banged data signals: 23 32 24 33 gpio1: gpio1 { 25 34 gpio-controller ··· 39 30 #gpio-cells = <1>; 40 31 }; 41 32 [...] 42 - chipsel-gpios = <&gpio1 12 0>, 43 - <&gpio1 13 0>, 44 - <0>, /* holes are permitted, means no GPIO 2 */ 45 - <&gpio2 2>; 33 + 34 + enable-gpios = <&gpio2 2>; 35 + data-gpios = <&gpio1 12 0>, 36 + <&gpio1 13 0>, 37 + <&gpio1 14 0>, 38 + <&gpio1 15 0>; 46 39 47 40 Note that gpio-specifier length is controller dependent. In the 48 41 above example, &gpio1 uses 2 cells to specify a gpio, while &gpio2 ··· 53 42 gpio-specifier may encode: bank, pin position inside the bank, 54 43 whether pin is open-drain and whether pin is logically inverted. 55 44 Exact meaning of each specifier cell is controller specific, and must 56 - be documented in the device tree binding for the device. 45 + be documented in the device tree binding for the device. Use the macros 46 + defined in include/dt-bindings/gpio/gpio.h whenever possible: 57 47 58 48 Example of a node using GPIOs: 59 49 60 50 node { 61 - gpios = <&qe_pio_e 18 0>; 51 + enable-gpios = <&qe_pio_e 18 GPIO_ACTIVE_HIGH>; 62 52 }; 63 53 64 - In this example gpio-specifier is "18 0" and encodes GPIO pin number, 65 - and GPIO flags as accepted by the "qe_pio_e" gpio-controller. 54 + GPIO_ACTIVE_HIGH is 0, so in this example gpio-specifier is "18 0" and encodes 55 + GPIO pin number, and GPIO flags as accepted by the "qe_pio_e" gpio-controller. 66 56 67 57 1.1) GPIO specifier best practices 68 58 ----------------------------------
+1 -1
Documentation/devicetree/bindings/gpio/pl061-gpio.txt
··· 7 7 - bit 0 specifies polarity (0 for normal, 1 for inverted) 8 8 - gpio-controller : Marks the device node as a GPIO controller. 9 9 - interrupts : Interrupt mapping for GPIO IRQ. 10 - 10 + - gpio-ranges : Interaction with the PINCTRL subsystem.
+3 -1
Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt
··· 6 6 - "renesas,gpio-r8a7778": for R8A7778 (R-Mobile M1) compatible GPIO controller. 7 7 - "renesas,gpio-r8a7779": for R8A7779 (R-Car H1) compatible GPIO controller. 8 8 - "renesas,gpio-r8a7790": for R8A7790 (R-Car H2) compatible GPIO controller. 9 - - "renesas,gpio-r8a7791": for R8A7791 (R-Car M2) compatible GPIO controller. 9 + - "renesas,gpio-r8a7791": for R8A7791 (R-Car M2-W) compatible GPIO controller. 10 + - "renesas,gpio-r8a7793": for R8A7793 (R-Car M2-N) compatible GPIO controller. 11 + - "renesas,gpio-r8a7794": for R8A7794 (R-Car E2) compatible GPIO controller. 10 12 - "renesas,gpio-rcar": for generic R-Car GPIO controller. 11 13 12 14 - reg: Base address and length of each memory resource used by the GPIO
+27
Documentation/gpio/consumer.txt
··· 199 199 Note that these functions should only be used with great moderation ; a driver 200 200 should not have to care about the physical line level. 201 201 202 + 203 + Set multiple GPIO outputs with a single function call 204 + ----------------------------------------------------- 205 + The following functions set the output values of an array of GPIOs: 206 + 207 + void gpiod_set_array(unsigned int array_size, 208 + struct gpio_desc **desc_array, 209 + int *value_array) 210 + void gpiod_set_raw_array(unsigned int array_size, 211 + struct gpio_desc **desc_array, 212 + int *value_array) 213 + void gpiod_set_array_cansleep(unsigned int array_size, 214 + struct gpio_desc **desc_array, 215 + int *value_array) 216 + void gpiod_set_raw_array_cansleep(unsigned int array_size, 217 + struct gpio_desc **desc_array, 218 + int *value_array) 219 + 220 + The array can be an arbitrary set of GPIOs. The functions will try to set 221 + GPIOs belonging to the same bank or chip simultaneously if supported by the 222 + corresponding chip driver. In that case a significantly improved performance 223 + can be expected. If simultaneous setting is not possible the GPIOs will be set 224 + sequentially. 225 + Note that for optimal performance GPIOs belonging to the same chip should be 226 + contiguous within the array of descriptors. 227 + 228 + 202 229 GPIOs mapped to IRQs 203 230 -------------------- 204 231 GPIO lines can quite often be used as IRQs. You can get the IRQ number
+2 -2
Documentation/gpio/driver.txt
··· 158 158 Input GPIOs can be used as IRQ signals. When this happens, a driver is requested 159 159 to mark the GPIO as being used as an IRQ: 160 160 161 - int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 161 + int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 162 162 163 163 This will prevent the use of non-irq related GPIO APIs until the GPIO IRQ lock 164 164 is released: 165 165 166 - void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) 166 + void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) 167 167 168 168 When implementing an irqchip inside a GPIO driver, these two functions should 169 169 typically be called in the .startup() and .shutdown() callbacks from the
+23
drivers/gpio/Kconfig
··· 112 112 113 113 comment "Memory mapped GPIO drivers:" 114 114 115 + config GPIO_74XX_MMIO 116 + tristate "GPIO driver for 74xx-ICs with MMIO access" 117 + depends on OF_GPIO 118 + select GPIO_GENERIC 119 + help 120 + Say yes here to support GPIO functionality for 74xx-compatible ICs 121 + with MMIO access. Compatible models include: 122 + 1 bit: 741G125 (Input), 741G74 (Output) 123 + 2 bits: 742G125 (Input), 7474 (Output) 124 + 4 bits: 74125 (Input), 74175 (Output) 125 + 6 bits: 74365 (Input), 74174 (Output) 126 + 8 bits: 74244 (Input), 74273 (Output) 127 + 16 bits: 741624 (Input), 7416374 (Output) 128 + 115 129 config GPIO_CLPS711X 116 130 tristate "CLPS711X GPIO support" 117 131 depends on ARCH_CLPS711X || COMPILE_TEST ··· 148 134 149 135 config GPIO_DWAPB 150 136 tristate "Synopsys DesignWare APB GPIO driver" 137 + depends on ARM 138 + depends on OF_GPIO 151 139 select GPIO_GENERIC 152 140 select GENERIC_IRQ_CHIP 153 141 help ··· 348 332 default y 349 333 help 350 334 Say yes here to support Toumaz Xenif TZ1090 PDC GPIOs. 335 + 336 + config GPIO_VF610 337 + def_bool y 338 + depends on ARCH_MXC && SOC_VF610 339 + select GPIOLIB_IRQCHIP 340 + help 341 + Say yes here to support Vybrid vf610 GPIOs. 351 342 352 343 config GPIO_XGENE 353 344 bool "APM X-Gene GPIO controller support"
+2
drivers/gpio/Makefile
··· 13 13 obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o 14 14 15 15 obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o 16 + obj-$(CONFIG_GPIO_74XX_MMIO) += gpio-74xx-mmio.o 16 17 obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o 17 18 obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o 18 19 obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o ··· 97 96 obj-$(CONFIG_GPIO_TZ1090) += gpio-tz1090.o 98 97 obj-$(CONFIG_GPIO_TZ1090_PDC) += gpio-tz1090-pdc.o 99 98 obj-$(CONFIG_GPIO_UCB1400) += gpio-ucb1400.o 99 + obj-$(CONFIG_GPIO_VF610) += gpio-vf610.o 100 100 obj-$(CONFIG_GPIO_VIPERBOARD) += gpio-viperboard.o 101 101 obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o 102 102 obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o
+170
drivers/gpio/gpio-74xx-mmio.c
··· 1 + /* 2 + * 74xx MMIO GPIO driver 3 + * 4 + * Copyright (C) 2014 Alexander Shiyan <shc_work@mail.ru> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + */ 11 + 12 + #include <linux/err.h> 13 + #include <linux/gpio.h> 14 + #include <linux/module.h> 15 + #include <linux/of_device.h> 16 + #include <linux/basic_mmio_gpio.h> 17 + #include <linux/platform_device.h> 18 + 19 + #define MMIO_74XX_DIR_IN (0 << 8) 20 + #define MMIO_74XX_DIR_OUT (1 << 8) 21 + #define MMIO_74XX_BIT_CNT(x) ((x) & 0xff) 22 + 23 + struct mmio_74xx_gpio_priv { 24 + struct bgpio_chip bgc; 25 + unsigned flags; 26 + }; 27 + 28 + static const struct of_device_id mmio_74xx_gpio_ids[] = { 29 + { 30 + .compatible = "ti,741g125", 31 + .data = (const void *)(MMIO_74XX_DIR_IN | 1), 32 + }, 33 + { 34 + .compatible = "ti,742g125", 35 + .data = (const void *)(MMIO_74XX_DIR_IN | 2), 36 + }, 37 + { 38 + .compatible = "ti,74125", 39 + .data = (const void *)(MMIO_74XX_DIR_IN | 4), 40 + }, 41 + { 42 + .compatible = "ti,74365", 43 + .data = (const void *)(MMIO_74XX_DIR_IN | 6), 44 + }, 45 + { 46 + .compatible = "ti,74244", 47 + .data = (const void *)(MMIO_74XX_DIR_IN | 8), 48 + }, 49 + { 50 + .compatible = "ti,741624", 51 + .data = (const void *)(MMIO_74XX_DIR_IN | 16), 52 + }, 53 + { 54 + .compatible = "ti,741g74", 55 + .data = (const void *)(MMIO_74XX_DIR_OUT | 1), 56 + }, 57 + { 58 + .compatible = "ti,7474", 59 + .data = (const void *)(MMIO_74XX_DIR_OUT | 2), 60 + }, 61 + { 62 + .compatible = "ti,74175", 63 + .data = (const void *)(MMIO_74XX_DIR_OUT | 4), 64 + }, 65 + { 66 + .compatible = "ti,74174", 67 + .data = (const void *)(MMIO_74XX_DIR_OUT | 6), 68 + }, 69 + { 70 + .compatible = "ti,74273", 71 + .data = (const void *)(MMIO_74XX_DIR_OUT | 8), 72 + }, 73 + { 74 + .compatible = "ti,7416374", 75 + .data = (const void *)(MMIO_74XX_DIR_OUT | 16), 76 + }, 77 + { } 78 + }; 79 + MODULE_DEVICE_TABLE(of, mmio_74xx_gpio_ids); 80 + 81 + static inline struct mmio_74xx_gpio_priv *to_74xx_gpio(struct gpio_chip *gc) 82 + { 83 + struct bgpio_chip *bgc = to_bgpio_chip(gc); 84 + 85 + return container_of(bgc, struct mmio_74xx_gpio_priv, bgc); 86 + } 87 + 88 + static int mmio_74xx_get_direction(struct gpio_chip *gc, unsigned offset) 89 + { 90 + struct mmio_74xx_gpio_priv *priv = to_74xx_gpio(gc); 91 + 92 + return (priv->flags & MMIO_74XX_DIR_OUT) ? GPIOF_DIR_OUT : GPIOF_DIR_IN; 93 + } 94 + 95 + static int mmio_74xx_dir_in(struct gpio_chip *gc, unsigned int gpio) 96 + { 97 + struct mmio_74xx_gpio_priv *priv = to_74xx_gpio(gc); 98 + 99 + return (priv->flags & MMIO_74XX_DIR_OUT) ? -ENOTSUPP : 0; 100 + } 101 + 102 + static int mmio_74xx_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 103 + { 104 + struct mmio_74xx_gpio_priv *priv = to_74xx_gpio(gc); 105 + 106 + if (priv->flags & MMIO_74XX_DIR_OUT) { 107 + gc->set(gc, gpio, val); 108 + return 0; 109 + } 110 + 111 + return -ENOTSUPP; 112 + } 113 + 114 + static int mmio_74xx_gpio_probe(struct platform_device *pdev) 115 + { 116 + const struct of_device_id *of_id = 117 + of_match_device(mmio_74xx_gpio_ids, &pdev->dev); 118 + struct mmio_74xx_gpio_priv *priv; 119 + struct resource *res; 120 + void __iomem *dat; 121 + int err; 122 + 123 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 124 + if (!priv) 125 + return -ENOMEM; 126 + 127 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 128 + dat = devm_ioremap_resource(&pdev->dev, res); 129 + if (IS_ERR(dat)) 130 + return PTR_ERR(dat); 131 + 132 + priv->flags = (unsigned)of_id->data; 133 + 134 + err = bgpio_init(&priv->bgc, &pdev->dev, 135 + DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8), 136 + dat, NULL, NULL, NULL, NULL, 0); 137 + if (err) 138 + return err; 139 + 140 + priv->bgc.gc.direction_input = mmio_74xx_dir_in; 141 + priv->bgc.gc.direction_output = mmio_74xx_dir_out; 142 + priv->bgc.gc.get_direction = mmio_74xx_get_direction; 143 + priv->bgc.gc.ngpio = MMIO_74XX_BIT_CNT(priv->flags); 144 + priv->bgc.gc.owner = THIS_MODULE; 145 + 146 + platform_set_drvdata(pdev, priv); 147 + 148 + return gpiochip_add(&priv->bgc.gc); 149 + } 150 + 151 + static int mmio_74xx_gpio_remove(struct platform_device *pdev) 152 + { 153 + struct mmio_74xx_gpio_priv *priv = platform_get_drvdata(pdev); 154 + 155 + return bgpio_remove(&priv->bgc); 156 + } 157 + 158 + static struct platform_driver mmio_74xx_gpio_driver = { 159 + .driver = { 160 + .name = "74xx-mmio-gpio", 161 + .of_match_table = mmio_74xx_gpio_ids, 162 + }, 163 + .probe = mmio_74xx_gpio_probe, 164 + .remove = mmio_74xx_gpio_remove, 165 + }; 166 + module_platform_driver(mmio_74xx_gpio_driver); 167 + 168 + MODULE_LICENSE("GPL"); 169 + MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>"); 170 + MODULE_DESCRIPTION("74xx MMIO GPIO driver");
+1
drivers/gpio/gpio-amd8111.c
··· 223 223 if (err) { 224 224 printk(KERN_ERR "GPIO registering failed (%d)\n", 225 225 err); 226 + ioport_unmap(gp.pm); 226 227 release_region(gp.pmbase + PMBASE_OFFSET, PMBASE_SIZE); 227 228 goto out; 228 229 }
+2 -2
drivers/gpio/gpio-bcm-kona.c
··· 470 470 { 471 471 struct bcm_kona_gpio *kona_gpio = irq_data_get_irq_chip_data(d); 472 472 473 - if (gpio_lock_as_irq(&kona_gpio->gpio_chip, d->hwirq)) { 473 + if (gpiochip_lock_as_irq(&kona_gpio->gpio_chip, d->hwirq)) { 474 474 dev_err(kona_gpio->gpio_chip.dev, 475 475 "unable to lock HW IRQ %lu for IRQ\n", 476 476 d->hwirq); ··· 483 483 { 484 484 struct bcm_kona_gpio *kona_gpio = irq_data_get_irq_chip_data(d); 485 485 486 - gpio_unlock_as_irq(&kona_gpio->gpio_chip, d->hwirq); 486 + gpiochip_unlock_as_irq(&kona_gpio->gpio_chip, d->hwirq); 487 487 } 488 488 489 489 static struct irq_chip bcm_gpio_irq_chip = {
+3 -8
drivers/gpio/gpio-cs5535.c
··· 322 322 goto done; 323 323 } 324 324 325 - if (!request_region(res->start, resource_size(res), pdev->name)) { 325 + if (!devm_request_region(&pdev->dev, res->start, resource_size(res), 326 + pdev->name)) { 326 327 dev_err(&pdev->dev, "can't request region\n"); 327 328 goto done; 328 329 } ··· 349 348 /* finally, register with the generic GPIO API */ 350 349 err = gpiochip_add(&cs5535_gpio_chip.chip); 351 350 if (err) 352 - goto release_region; 351 + goto done; 353 352 354 353 return 0; 355 354 356 - release_region: 357 - release_region(res->start, resource_size(res)); 358 355 done: 359 356 return err; 360 357 } 361 358 362 359 static int cs5535_gpio_remove(struct platform_device *pdev) 363 360 { 364 - struct resource *r; 365 - 366 361 gpiochip_remove(&cs5535_gpio_chip.chip); 367 362 368 - r = platform_get_resource(pdev, IORESOURCE_IO, 0); 369 - release_region(r->start, resource_size(r)); 370 363 return 0; 371 364 } 372 365
-5
drivers/gpio/gpio-davinci.c
··· 234 234 return -ENOMEM; 235 235 236 236 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 237 - if (!res) { 238 - dev_err(dev, "Invalid memory resource\n"); 239 - return -EBUSY; 240 - } 241 - 242 237 gpio_base = devm_ioremap_resource(dev, res); 243 238 if (IS_ERR(gpio_base)) 244 239 return PTR_ERR(gpio_base);
+2 -2
drivers/gpio/gpio-dwapb.c
··· 194 194 struct dwapb_gpio *gpio = igc->private; 195 195 struct bgpio_chip *bgc = &gpio->ports[0].bgc; 196 196 197 - if (gpio_lock_as_irq(&bgc->gc, irqd_to_hwirq(d))) { 197 + if (gpiochip_lock_as_irq(&bgc->gc, irqd_to_hwirq(d))) { 198 198 dev_err(gpio->dev, "unable to lock HW IRQ %lu for IRQ\n", 199 199 irqd_to_hwirq(d)); 200 200 return -EINVAL; ··· 208 208 struct dwapb_gpio *gpio = igc->private; 209 209 struct bgpio_chip *bgc = &gpio->ports[0].bgc; 210 210 211 - gpio_unlock_as_irq(&bgc->gc, irqd_to_hwirq(d)); 211 + gpiochip_unlock_as_irq(&bgc->gc, irqd_to_hwirq(d)); 212 212 } 213 213 214 214 static int dwapb_irq_set_type(struct irq_data *d, u32 type)
+3 -8
drivers/gpio/gpio-em.c
··· 103 103 { 104 104 struct em_gio_priv *p = irq_data_get_irq_chip_data(d); 105 105 106 - if (gpio_lock_as_irq(&p->gpio_chip, irqd_to_hwirq(d))) { 106 + if (gpiochip_lock_as_irq(&p->gpio_chip, irqd_to_hwirq(d))) { 107 107 dev_err(p->gpio_chip.dev, 108 108 "unable to lock HW IRQ %lu for IRQ\n", 109 109 irqd_to_hwirq(d)); ··· 116 116 { 117 117 struct em_gio_priv *p = irq_data_get_irq_chip_data(d); 118 118 119 - gpio_unlock_as_irq(&p->gpio_chip, irqd_to_hwirq(d)); 119 + gpiochip_unlock_as_irq(&p->gpio_chip, irqd_to_hwirq(d)); 120 120 } 121 121 122 122 ··· 330 330 goto err0; 331 331 } 332 332 333 - ret = of_alias_get_id(pdev->dev.of_node, "gpio"); 334 - if (ret < 0) { 335 - dev_err(&pdev->dev, "Couldn't get OF id\n"); 336 - goto err0; 337 - } 338 - pdata->gpio_base = ret * 32; /* 32 GPIOs per instance */ 333 + pdata->gpio_base = -1; 339 334 } 340 335 341 336 gpio_chip = &p->gpio_chip;
+1
drivers/gpio/gpio-grgpio.c
··· 441 441 err = gpiochip_add(gc); 442 442 if (err) { 443 443 dev_err(&ofdev->dev, "Could not add gpiochip\n"); 444 + irq_domain_remove(priv->domain); 444 445 return err; 445 446 } 446 447
+31 -10
drivers/gpio/gpio-mcp23s08.c
··· 65 65 66 66 struct mcp23s08 { 67 67 u8 addr; 68 + bool irq_active_high; 68 69 69 70 u16 cache[11]; 70 71 u16 irq_rise; ··· 445 444 { 446 445 struct mcp23s08 *mcp = irq_data_get_irq_chip_data(data); 447 446 448 - if (gpio_lock_as_irq(&mcp->chip, data->hwirq)) { 447 + if (gpiochip_lock_as_irq(&mcp->chip, data->hwirq)) { 449 448 dev_err(mcp->chip.dev, 450 449 "unable to lock HW IRQ %lu for IRQ usage\n", 451 450 data->hwirq); ··· 459 458 { 460 459 struct mcp23s08 *mcp = irq_data_get_irq_chip_data(data); 461 460 462 - gpio_unlock_as_irq(&mcp->chip, data->hwirq); 461 + gpiochip_unlock_as_irq(&mcp->chip, data->hwirq); 463 462 } 464 463 465 464 static struct irq_chip mcp23s08_irq_chip = { ··· 477 476 { 478 477 struct gpio_chip *chip = &mcp->chip; 479 478 int err, irq, j; 479 + unsigned long irqflags = IRQF_ONESHOT | IRQF_SHARED; 480 480 481 481 mutex_init(&mcp->irq_lock); 482 482 ··· 486 484 if (!mcp->irq_domain) 487 485 return -ENODEV; 488 486 487 + if (mcp->irq_active_high) 488 + irqflags |= IRQF_TRIGGER_HIGH; 489 + else 490 + irqflags |= IRQF_TRIGGER_LOW; 491 + 489 492 err = devm_request_threaded_irq(chip->dev, mcp->irq, NULL, mcp23s08_irq, 490 - IRQF_TRIGGER_LOW | IRQF_ONESHOT, 491 - dev_name(chip->dev), mcp); 493 + irqflags, dev_name(chip->dev), mcp); 492 494 if (err != 0) { 493 495 dev_err(chip->dev, "unable to request IRQ#%d: %d\n", 494 496 mcp->irq, err); ··· 519 513 static void mcp23s08_irq_teardown(struct mcp23s08 *mcp) 520 514 { 521 515 unsigned int irq, i; 522 - 523 - free_irq(mcp->irq, mcp); 524 516 525 517 for (i = 0; i < mcp->chip.ngpio; i++) { 526 518 irq = irq_find_mapping(mcp->irq_domain, i); ··· 594 590 595 591 mcp->data = data; 596 592 mcp->addr = addr; 593 + mcp->irq_active_high = false; 597 594 598 595 mcp->chip.direction_input = mcp23s08_direction_input; 599 596 mcp->chip.get = mcp23s08_get; ··· 654 649 goto fail; 655 650 656 651 mcp->irq_controller = pdata->irq_controller; 657 - if (mcp->irq && mcp->irq_controller && (type == MCP_TYPE_017)) 658 - mirror = pdata->mirror; 652 + if (mcp->irq && mcp->irq_controller) { 653 + mcp->irq_active_high = 654 + of_property_read_bool(mcp->chip.dev->of_node, 655 + "microchip,irq-active-high"); 659 656 660 - if ((status & IOCON_SEQOP) || !(status & IOCON_HAEN) || mirror) { 657 + if (type == MCP_TYPE_017) 658 + mirror = pdata->mirror; 659 + } 660 + 661 + if ((status & IOCON_SEQOP) || !(status & IOCON_HAEN) || mirror || 662 + mcp->irq_active_high) { 661 663 /* mcp23s17 has IOCON twice, make sure they are in sync */ 662 664 status &= ~(IOCON_SEQOP | (IOCON_SEQOP << 8)); 663 665 status |= IOCON_HAEN | (IOCON_HAEN << 8); 664 - status &= ~(IOCON_INTPOL | (IOCON_INTPOL << 8)); 666 + if (mcp->irq_active_high) 667 + status |= IOCON_INTPOL | (IOCON_INTPOL << 8); 668 + else 669 + status &= ~(IOCON_INTPOL | (IOCON_INTPOL << 8)); 670 + 665 671 if (mirror) 666 672 status |= IOCON_MIRROR | (IOCON_MIRROR << 8); 667 673 ··· 952 936 return -ENOMEM; 953 937 spi_set_drvdata(spi, data); 954 938 939 + spi->irq = irq_of_parse_and_map(spi->dev.of_node, 0); 940 + 955 941 for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) { 956 942 if (!(spi_present_mask & (1 << addr))) 957 943 continue; 958 944 chips--; 959 945 data->mcp[addr] = &data->chip[chips]; 946 + data->mcp[addr]->irq = spi->irq; 960 947 status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi, 961 948 0x40 | (addr << 1), type, pdata, 962 949 addr); ··· 1000 981 if (!data->mcp[addr]) 1001 982 continue; 1002 983 984 + if (spi->irq && data->mcp[addr]->irq_controller) 985 + mcp23s08_irq_teardown(data->mcp[addr]); 1003 986 gpiochip_remove(&data->mcp[addr]->chip); 1004 987 } 1005 988 kfree(data);
+27
drivers/gpio/gpio-mpc8xxx.c
··· 105 105 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 106 106 } 107 107 108 + static void mpc8xxx_gpio_set_multiple(struct gpio_chip *gc, 109 + unsigned long *mask, unsigned long *bits) 110 + { 111 + struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); 112 + struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); 113 + unsigned long flags; 114 + int i; 115 + 116 + spin_lock_irqsave(&mpc8xxx_gc->lock, flags); 117 + 118 + for (i = 0; i < gc->ngpio; i++) { 119 + if (*mask == 0) 120 + break; 121 + if (__test_and_clear_bit(i, mask)) { 122 + if (test_bit(i, bits)) 123 + mpc8xxx_gc->data |= mpc8xxx_gpio2mask(i); 124 + else 125 + mpc8xxx_gc->data &= ~mpc8xxx_gpio2mask(i); 126 + } 127 + } 128 + 129 + out_be32(mm->regs + GPIO_DAT, mpc8xxx_gc->data); 130 + 131 + spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); 132 + } 133 + 108 134 static int mpc8xxx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio) 109 135 { 110 136 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); ··· 370 344 gc->get = of_device_is_compatible(np, "fsl,mpc8572-gpio") ? 371 345 mpc8572_gpio_get : mpc8xxx_gpio_get; 372 346 gc->set = mpc8xxx_gpio_set; 347 + gc->set_multiple = mpc8xxx_gpio_set_multiple; 373 348 gc->to_irq = mpc8xxx_gpio_to_irq; 374 349 375 350 ret = of_mm_gpiochip_add(np, mm_gc);
+99
drivers/gpio/gpio-mvebu.c
··· 83 83 int irqbase; 84 84 struct irq_domain *domain; 85 85 int soc_variant; 86 + 87 + /* Used to preserve GPIO registers accross suspend/resume */ 88 + u32 out_reg; 89 + u32 io_conf_reg; 90 + u32 blink_en_reg; 91 + u32 in_pol_reg; 92 + u32 edge_mask_regs[4]; 93 + u32 level_mask_regs[4]; 86 94 }; 87 95 88 96 /* ··· 562 554 }; 563 555 MODULE_DEVICE_TABLE(of, mvebu_gpio_of_match); 564 556 557 + static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state) 558 + { 559 + struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev); 560 + int i; 561 + 562 + mvchip->out_reg = readl(mvebu_gpioreg_out(mvchip)); 563 + mvchip->io_conf_reg = readl(mvebu_gpioreg_io_conf(mvchip)); 564 + mvchip->blink_en_reg = readl(mvebu_gpioreg_blink(mvchip)); 565 + mvchip->in_pol_reg = readl(mvebu_gpioreg_in_pol(mvchip)); 566 + 567 + switch (mvchip->soc_variant) { 568 + case MVEBU_GPIO_SOC_VARIANT_ORION: 569 + mvchip->edge_mask_regs[0] = 570 + readl(mvchip->membase + GPIO_EDGE_MASK_OFF); 571 + mvchip->level_mask_regs[0] = 572 + readl(mvchip->membase + GPIO_LEVEL_MASK_OFF); 573 + break; 574 + case MVEBU_GPIO_SOC_VARIANT_MV78200: 575 + for (i = 0; i < 2; i++) { 576 + mvchip->edge_mask_regs[i] = 577 + readl(mvchip->membase + 578 + GPIO_EDGE_MASK_MV78200_OFF(i)); 579 + mvchip->level_mask_regs[i] = 580 + readl(mvchip->membase + 581 + GPIO_LEVEL_MASK_MV78200_OFF(i)); 582 + } 583 + break; 584 + case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: 585 + for (i = 0; i < 4; i++) { 586 + mvchip->edge_mask_regs[i] = 587 + readl(mvchip->membase + 588 + GPIO_EDGE_MASK_ARMADAXP_OFF(i)); 589 + mvchip->level_mask_regs[i] = 590 + readl(mvchip->membase + 591 + GPIO_LEVEL_MASK_ARMADAXP_OFF(i)); 592 + } 593 + break; 594 + default: 595 + BUG(); 596 + } 597 + 598 + return 0; 599 + } 600 + 601 + static int mvebu_gpio_resume(struct platform_device *pdev) 602 + { 603 + struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev); 604 + int i; 605 + 606 + writel(mvchip->out_reg, mvebu_gpioreg_out(mvchip)); 607 + writel(mvchip->io_conf_reg, mvebu_gpioreg_io_conf(mvchip)); 608 + writel(mvchip->blink_en_reg, mvebu_gpioreg_blink(mvchip)); 609 + writel(mvchip->in_pol_reg, mvebu_gpioreg_in_pol(mvchip)); 610 + 611 + switch (mvchip->soc_variant) { 612 + case MVEBU_GPIO_SOC_VARIANT_ORION: 613 + writel(mvchip->edge_mask_regs[0], 614 + mvchip->membase + GPIO_EDGE_MASK_OFF); 615 + writel(mvchip->level_mask_regs[0], 616 + mvchip->membase + GPIO_LEVEL_MASK_OFF); 617 + break; 618 + case MVEBU_GPIO_SOC_VARIANT_MV78200: 619 + for (i = 0; i < 2; i++) { 620 + writel(mvchip->edge_mask_regs[i], 621 + mvchip->membase + GPIO_EDGE_MASK_MV78200_OFF(i)); 622 + writel(mvchip->level_mask_regs[i], 623 + mvchip->membase + 624 + GPIO_LEVEL_MASK_MV78200_OFF(i)); 625 + } 626 + break; 627 + case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: 628 + for (i = 0; i < 4; i++) { 629 + writel(mvchip->edge_mask_regs[i], 630 + mvchip->membase + 631 + GPIO_EDGE_MASK_ARMADAXP_OFF(i)); 632 + writel(mvchip->level_mask_regs[i], 633 + mvchip->membase + 634 + GPIO_LEVEL_MASK_ARMADAXP_OFF(i)); 635 + } 636 + break; 637 + default: 638 + BUG(); 639 + } 640 + 641 + return 0; 642 + } 643 + 565 644 static int mvebu_gpio_probe(struct platform_device *pdev) 566 645 { 567 646 struct mvebu_gpio_chip *mvchip; ··· 671 576 mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip), GFP_KERNEL); 672 577 if (!mvchip) 673 578 return -ENOMEM; 579 + 580 + platform_set_drvdata(pdev, mvchip); 674 581 675 582 if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) { 676 583 dev_err(&pdev->dev, "Missing ngpios OF property\n"); ··· 832 735 .of_match_table = mvebu_gpio_of_match, 833 736 }, 834 737 .probe = mvebu_gpio_probe, 738 + .suspend = mvebu_gpio_suspend, 739 + .resume = mvebu_gpio_resume, 835 740 }; 836 741 module_platform_driver(mvebu_gpio_driver);
+13
drivers/gpio/gpio-mxs.c
··· 227 227 return irq_find_mapping(port->domain, offset); 228 228 } 229 229 230 + static int mxs_gpio_get_direction(struct gpio_chip *gc, unsigned offset) 231 + { 232 + struct bgpio_chip *bgc = to_bgpio_chip(gc); 233 + struct mxs_gpio_port *port = 234 + container_of(bgc, struct mxs_gpio_port, bgc); 235 + u32 mask = 1 << offset; 236 + u32 dir; 237 + 238 + dir = readl(port->base + PINCTRL_DOE(port)); 239 + return !(dir & mask); 240 + } 241 + 230 242 static struct platform_device_id mxs_gpio_ids[] = { 231 243 { 232 244 .name = "imx23-gpio", ··· 332 320 goto out_irqdesc_free; 333 321 334 322 port->bgc.gc.to_irq = mxs_gpio_to_irq; 323 + port->bgc.gc.get_direction = mxs_gpio_get_direction; 335 324 port->bgc.gc.base = port->id * 32; 336 325 337 326 err = gpiochip_add(&port->bgc.gc);
+1 -1
drivers/gpio/gpio-omap.c
··· 800 800 unsigned offset = GPIO_INDEX(bank, gpio); 801 801 802 802 spin_lock_irqsave(&bank->lock, flags); 803 - gpio_unlock_as_irq(&bank->chip, offset); 803 + gpiochip_unlock_as_irq(&bank->chip, offset); 804 804 bank->irq_usage &= ~(BIT(offset)); 805 805 omap_disable_gpio_module(bank, offset); 806 806 omap_reset_gpio(bank, gpio);
+14 -6
drivers/gpio/gpio-pl061.c
··· 52 52 53 53 void __iomem *base; 54 54 struct gpio_chip gc; 55 + bool uses_pinctrl; 55 56 56 57 #ifdef CONFIG_PM 57 58 struct pl061_context_save_regs csave_regs; 58 59 #endif 59 60 }; 60 61 61 - static int pl061_gpio_request(struct gpio_chip *chip, unsigned offset) 62 + static int pl061_gpio_request(struct gpio_chip *gc, unsigned offset) 62 63 { 63 64 /* 64 65 * Map back to global GPIO space and request muxing, the direction 65 66 * parameter does not matter for this controller. 66 67 */ 67 - int gpio = chip->base + offset; 68 + struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 69 + int gpio = gc->base + offset; 68 70 69 - return pinctrl_request_gpio(gpio); 71 + if (chip->uses_pinctrl) 72 + return pinctrl_request_gpio(gpio); 73 + return 0; 70 74 } 71 75 72 - static void pl061_gpio_free(struct gpio_chip *chip, unsigned offset) 76 + static void pl061_gpio_free(struct gpio_chip *gc, unsigned offset) 73 77 { 74 - int gpio = chip->base + offset; 78 + struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 79 + int gpio = gc->base + offset; 75 80 76 - pinctrl_free_gpio(gpio); 81 + if (chip->uses_pinctrl) 82 + pinctrl_free_gpio(gpio); 77 83 } 78 84 79 85 static int pl061_direction_input(struct gpio_chip *gc, unsigned offset) ··· 269 263 return PTR_ERR(chip->base); 270 264 271 265 spin_lock_init(&chip->lock); 266 + if (of_property_read_bool(dev->of_node, "gpio-ranges")) 267 + chip->uses_pinctrl = true; 272 268 273 269 chip->gc.request = pl061_gpio_request; 274 270 chip->gc.free = pl061_gpio_free;
+18 -9
drivers/gpio/gpio-rcar.c
··· 1 1 /* 2 2 * Renesas R-Car GPIO Support 3 3 * 4 + * Copyright (C) 2014 Renesas Electronics Corporation 4 5 * Copyright (C) 2013 Magnus Damm 5 6 * 6 7 * This program is free software; you can redistribute it and/or modify ··· 292 291 bool has_both_edge_trigger; 293 292 }; 294 293 294 + static const struct gpio_rcar_info gpio_rcar_info_gen1 = { 295 + .has_both_edge_trigger = false, 296 + }; 297 + 298 + static const struct gpio_rcar_info gpio_rcar_info_gen2 = { 299 + .has_both_edge_trigger = true, 300 + }; 301 + 295 302 static const struct of_device_id gpio_rcar_of_table[] = { 296 303 { 297 304 .compatible = "renesas,gpio-r8a7790", 298 - .data = (void *)&(const struct gpio_rcar_info) { 299 - .has_both_edge_trigger = true, 300 - }, 305 + .data = &gpio_rcar_info_gen2, 301 306 }, { 302 307 .compatible = "renesas,gpio-r8a7791", 303 - .data = (void *)&(const struct gpio_rcar_info) { 304 - .has_both_edge_trigger = true, 305 - }, 308 + .data = &gpio_rcar_info_gen2, 309 + }, { 310 + .compatible = "renesas,gpio-r8a7793", 311 + .data = &gpio_rcar_info_gen2, 312 + }, { 313 + .compatible = "renesas,gpio-r8a7794", 314 + .data = &gpio_rcar_info_gen2, 306 315 }, { 307 316 .compatible = "renesas,gpio-rcar", 308 - .data = (void *)&(const struct gpio_rcar_info) { 309 - .has_both_edge_trigger = false, 310 - }, 317 + .data = &gpio_rcar_info_gen1, 311 318 }, { 312 319 /* Terminator */ 313 320 },
+2 -6
drivers/gpio/gpio-stp-xway.c
··· 199 199 200 200 static int xway_stp_probe(struct platform_device *pdev) 201 201 { 202 - struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 202 + struct resource *res; 203 203 const __be32 *shadow, *groups, *dsl, *phy; 204 204 struct xway_stp *chip; 205 205 struct clk *clk; 206 206 int ret = 0; 207 207 208 - if (!res) { 209 - dev_err(&pdev->dev, "failed to request STP resource\n"); 210 - return -ENOENT; 211 - } 212 - 213 208 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); 214 209 if (!chip) 215 210 return -ENOMEM; 216 211 212 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 217 213 chip->virt = devm_ioremap_resource(&pdev->dev, res); 218 214 if (IS_ERR(chip->virt)) 219 215 return PTR_ERR(chip->virt);
+1 -6
drivers/gpio/gpio-tb10x.c
··· 195 195 if (of_property_read_u32(dn, "abilis,ngpio", &ngpio)) 196 196 return -EINVAL; 197 197 198 - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 199 - if (!mem) { 200 - dev_err(&pdev->dev, "No memory resource defined.\n"); 201 - return -EINVAL; 202 - } 203 - 204 198 tb10x_gpio = devm_kzalloc(&pdev->dev, sizeof(*tb10x_gpio), GFP_KERNEL); 205 199 if (tb10x_gpio == NULL) 206 200 return -ENOMEM; 207 201 208 202 spin_lock_init(&tb10x_gpio->spinlock); 209 203 204 + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 210 205 tb10x_gpio->base = devm_ioremap_resource(&pdev->dev, mem); 211 206 if (IS_ERR(tb10x_gpio->base)) 212 207 return PTR_ERR(tb10x_gpio->base);
+2 -2
drivers/gpio/gpio-tegra.c
··· 233 233 return -EINVAL; 234 234 } 235 235 236 - ret = gpio_lock_as_irq(&tegra_gpio_chip, gpio); 236 + ret = gpiochip_lock_as_irq(&tegra_gpio_chip, gpio); 237 237 if (ret) { 238 238 dev_err(dev, "unable to lock Tegra GPIO %d as IRQ\n", gpio); 239 239 return ret; ··· 263 263 { 264 264 int gpio = d->hwirq; 265 265 266 - gpio_unlock_as_irq(&tegra_gpio_chip, gpio); 266 + gpiochip_unlock_as_irq(&tegra_gpio_chip, gpio); 267 267 } 268 268 269 269 static void tegra_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
+295
drivers/gpio/gpio-vf610.c
··· 1 + /* 2 + * vf610 GPIO support through PORT and GPIO module 3 + * 4 + * Copyright (c) 2014 Toradex AG. 5 + * 6 + * Author: Stefan Agner <stefan@agner.ch>. 7 + * 8 + * This program is free software; you can redistribute it and/or 9 + * modify it under the terms of the GNU General Public License 10 + * as published by the Free Software Foundation; either version 2 11 + * of the License, or (at your option) any later version. 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/bitops.h> 19 + #include <linux/err.h> 20 + #include <linux/gpio.h> 21 + #include <linux/init.h> 22 + #include <linux/interrupt.h> 23 + #include <linux/io.h> 24 + #include <linux/ioport.h> 25 + #include <linux/irq.h> 26 + #include <linux/module.h> 27 + #include <linux/platform_device.h> 28 + #include <linux/of.h> 29 + #include <linux/of_device.h> 30 + #include <linux/of_irq.h> 31 + 32 + #define VF610_GPIO_PER_PORT 32 33 + 34 + struct vf610_gpio_port { 35 + struct gpio_chip gc; 36 + void __iomem *base; 37 + void __iomem *gpio_base; 38 + u8 irqc[VF610_GPIO_PER_PORT]; 39 + int irq; 40 + }; 41 + 42 + #define GPIO_PDOR 0x00 43 + #define GPIO_PSOR 0x04 44 + #define GPIO_PCOR 0x08 45 + #define GPIO_PTOR 0x0c 46 + #define GPIO_PDIR 0x10 47 + 48 + #define PORT_PCR(n) ((n) * 0x4) 49 + #define PORT_PCR_IRQC_OFFSET 16 50 + 51 + #define PORT_ISFR 0xa0 52 + #define PORT_DFER 0xc0 53 + #define PORT_DFCR 0xc4 54 + #define PORT_DFWR 0xc8 55 + 56 + #define PORT_INT_OFF 0x0 57 + #define PORT_INT_LOGIC_ZERO 0x8 58 + #define PORT_INT_RISING_EDGE 0x9 59 + #define PORT_INT_FALLING_EDGE 0xa 60 + #define PORT_INT_EITHER_EDGE 0xb 61 + #define PORT_INT_LOGIC_ONE 0xc 62 + 63 + static const struct of_device_id vf610_gpio_dt_ids[] = { 64 + { .compatible = "fsl,vf610-gpio" }, 65 + { /* sentinel */ } 66 + }; 67 + 68 + static inline void vf610_gpio_writel(u32 val, void __iomem *reg) 69 + { 70 + writel_relaxed(val, reg); 71 + } 72 + 73 + static inline u32 vf610_gpio_readl(void __iomem *reg) 74 + { 75 + return readl_relaxed(reg); 76 + } 77 + 78 + static int vf610_gpio_request(struct gpio_chip *chip, unsigned offset) 79 + { 80 + return pinctrl_request_gpio(chip->base + offset); 81 + } 82 + 83 + static void vf610_gpio_free(struct gpio_chip *chip, unsigned offset) 84 + { 85 + pinctrl_free_gpio(chip->base + offset); 86 + } 87 + 88 + static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio) 89 + { 90 + struct vf610_gpio_port *port = 91 + container_of(gc, struct vf610_gpio_port, gc); 92 + 93 + return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR) & BIT(gpio)); 94 + } 95 + 96 + static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 97 + { 98 + struct vf610_gpio_port *port = 99 + container_of(gc, struct vf610_gpio_port, gc); 100 + unsigned long mask = BIT(gpio); 101 + 102 + if (val) 103 + vf610_gpio_writel(mask, port->gpio_base + GPIO_PSOR); 104 + else 105 + vf610_gpio_writel(mask, port->gpio_base + GPIO_PCOR); 106 + } 107 + 108 + static int vf610_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 109 + { 110 + return pinctrl_gpio_direction_input(chip->base + gpio); 111 + } 112 + 113 + static int vf610_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, 114 + int value) 115 + { 116 + vf610_gpio_set(chip, gpio, value); 117 + 118 + return pinctrl_gpio_direction_output(chip->base + gpio); 119 + } 120 + 121 + static void vf610_gpio_irq_handler(u32 irq, struct irq_desc *desc) 122 + { 123 + struct vf610_gpio_port *port = irq_get_handler_data(irq); 124 + struct irq_chip *chip = irq_desc_get_chip(desc); 125 + int pin; 126 + unsigned long irq_isfr; 127 + 128 + chained_irq_enter(chip, desc); 129 + 130 + irq_isfr = vf610_gpio_readl(port->base + PORT_ISFR); 131 + 132 + for_each_set_bit(pin, &irq_isfr, VF610_GPIO_PER_PORT) { 133 + vf610_gpio_writel(BIT(pin), port->base + PORT_ISFR); 134 + 135 + generic_handle_irq(irq_find_mapping(port->gc.irqdomain, pin)); 136 + } 137 + 138 + chained_irq_exit(chip, desc); 139 + } 140 + 141 + static void vf610_gpio_irq_ack(struct irq_data *d) 142 + { 143 + struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 144 + int gpio = d->hwirq; 145 + 146 + vf610_gpio_writel(BIT(gpio), port->base + PORT_ISFR); 147 + } 148 + 149 + static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type) 150 + { 151 + struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 152 + u8 irqc; 153 + 154 + switch (type) { 155 + case IRQ_TYPE_EDGE_RISING: 156 + irqc = PORT_INT_RISING_EDGE; 157 + break; 158 + case IRQ_TYPE_EDGE_FALLING: 159 + irqc = PORT_INT_FALLING_EDGE; 160 + break; 161 + case IRQ_TYPE_EDGE_BOTH: 162 + irqc = PORT_INT_EITHER_EDGE; 163 + break; 164 + case IRQ_TYPE_LEVEL_LOW: 165 + irqc = PORT_INT_LOGIC_ZERO; 166 + break; 167 + case IRQ_TYPE_LEVEL_HIGH: 168 + irqc = PORT_INT_LOGIC_ONE; 169 + break; 170 + default: 171 + return -EINVAL; 172 + } 173 + 174 + port->irqc[d->hwirq] = irqc; 175 + 176 + return 0; 177 + } 178 + 179 + static void vf610_gpio_irq_mask(struct irq_data *d) 180 + { 181 + struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 182 + void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq); 183 + 184 + vf610_gpio_writel(0, pcr_base); 185 + } 186 + 187 + static void vf610_gpio_irq_unmask(struct irq_data *d) 188 + { 189 + struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 190 + void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq); 191 + 192 + vf610_gpio_writel(port->irqc[d->hwirq] << PORT_PCR_IRQC_OFFSET, 193 + pcr_base); 194 + } 195 + 196 + static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable) 197 + { 198 + struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 199 + 200 + if (enable) 201 + enable_irq_wake(port->irq); 202 + else 203 + disable_irq_wake(port->irq); 204 + 205 + return 0; 206 + } 207 + 208 + static struct irq_chip vf610_gpio_irq_chip = { 209 + .name = "gpio-vf610", 210 + .irq_ack = vf610_gpio_irq_ack, 211 + .irq_mask = vf610_gpio_irq_mask, 212 + .irq_unmask = vf610_gpio_irq_unmask, 213 + .irq_set_type = vf610_gpio_irq_set_type, 214 + .irq_set_wake = vf610_gpio_irq_set_wake, 215 + }; 216 + 217 + static int vf610_gpio_probe(struct platform_device *pdev) 218 + { 219 + struct device *dev = &pdev->dev; 220 + struct device_node *np = dev->of_node; 221 + struct vf610_gpio_port *port; 222 + struct resource *iores; 223 + struct gpio_chip *gc; 224 + int ret; 225 + 226 + port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL); 227 + if (!port) 228 + return -ENOMEM; 229 + 230 + iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 231 + port->base = devm_ioremap_resource(dev, iores); 232 + if (IS_ERR(port->base)) 233 + return PTR_ERR(port->base); 234 + 235 + iores = platform_get_resource(pdev, IORESOURCE_MEM, 1); 236 + port->gpio_base = devm_ioremap_resource(dev, iores); 237 + if (IS_ERR(port->gpio_base)) 238 + return PTR_ERR(port->gpio_base); 239 + 240 + port->irq = platform_get_irq(pdev, 0); 241 + if (port->irq < 0) 242 + return port->irq; 243 + 244 + gc = &port->gc; 245 + gc->of_node = np; 246 + gc->dev = dev; 247 + gc->label = "vf610-gpio", 248 + gc->ngpio = VF610_GPIO_PER_PORT, 249 + gc->base = of_alias_get_id(np, "gpio") * VF610_GPIO_PER_PORT; 250 + 251 + gc->request = vf610_gpio_request, 252 + gc->free = vf610_gpio_free, 253 + gc->direction_input = vf610_gpio_direction_input, 254 + gc->get = vf610_gpio_get, 255 + gc->direction_output = vf610_gpio_direction_output, 256 + gc->set = vf610_gpio_set, 257 + 258 + ret = gpiochip_add(gc); 259 + if (ret < 0) 260 + return ret; 261 + 262 + /* Clear the interrupt status register for all GPIO's */ 263 + vf610_gpio_writel(~0, port->base + PORT_ISFR); 264 + 265 + ret = gpiochip_irqchip_add(gc, &vf610_gpio_irq_chip, 0, 266 + handle_simple_irq, IRQ_TYPE_NONE); 267 + if (ret) { 268 + dev_err(dev, "failed to add irqchip\n"); 269 + gpiochip_remove(gc); 270 + return ret; 271 + } 272 + gpiochip_set_chained_irqchip(gc, &vf610_gpio_irq_chip, port->irq, 273 + vf610_gpio_irq_handler); 274 + 275 + return 0; 276 + } 277 + 278 + static struct platform_driver vf610_gpio_driver = { 279 + .driver = { 280 + .name = "gpio-vf610", 281 + .owner = THIS_MODULE, 282 + .of_match_table = vf610_gpio_dt_ids, 283 + }, 284 + .probe = vf610_gpio_probe, 285 + }; 286 + 287 + static int __init gpio_vf610_init(void) 288 + { 289 + return platform_driver_register(&vf610_gpio_driver); 290 + } 291 + device_initcall(gpio_vf610_init); 292 + 293 + MODULE_AUTHOR("Stefan Agner <stefan@agner.ch>"); 294 + MODULE_DESCRIPTION("Freescale VF610 GPIO"); 295 + MODULE_LICENSE("GPL v2");
+2 -2
drivers/gpio/gpio-vr41xx.c
··· 138 138 139 139 static unsigned int startup_giuint(struct irq_data *data) 140 140 { 141 - if (gpio_lock_as_irq(&vr41xx_gpio_chip, data->hwirq)) 141 + if (gpiochip_lock_as_irq(&vr41xx_gpio_chip, data->hwirq)) 142 142 dev_err(vr41xx_gpio_chip.dev, 143 143 "unable to lock HW IRQ %lu for IRQ\n", 144 144 data->hwirq); ··· 150 150 static void shutdown_giuint(struct irq_data *data) 151 151 { 152 152 mask_giuint_low(data); 153 - gpio_unlock_as_irq(&vr41xx_gpio_chip, data->hwirq); 153 + gpiochip_unlock_as_irq(&vr41xx_gpio_chip, data->hwirq); 154 154 } 155 155 156 156 static struct irq_chip giuint_low_irq_chip = {
+3 -3
drivers/gpio/gpiolib-acpi.c
··· 209 209 210 210 gpiod_direction_input(desc); 211 211 212 - ret = gpio_lock_as_irq(chip, pin); 212 + ret = gpiochip_lock_as_irq(chip, pin); 213 213 if (ret) { 214 214 dev_err(chip->dev, "Failed to lock GPIO as interrupt\n"); 215 215 goto fail_free_desc; ··· 265 265 fail_free_event: 266 266 kfree(event); 267 267 fail_unlock_irq: 268 - gpio_unlock_as_irq(chip, pin); 268 + gpiochip_unlock_as_irq(chip, pin); 269 269 fail_free_desc: 270 270 gpiochip_free_own_desc(desc); 271 271 ··· 336 336 desc = event->desc; 337 337 if (WARN_ON(IS_ERR(desc))) 338 338 continue; 339 - gpio_unlock_as_irq(chip, event->pin); 339 + gpiochip_unlock_as_irq(chip, event->pin); 340 340 gpiochip_free_own_desc(desc); 341 341 list_del(&event->node); 342 342 kfree(event);
+11 -1
drivers/gpio/gpiolib-legacy.c
··· 24 24 25 25 desc = gpio_to_desc(gpio); 26 26 27 + /* Compatibility: assume unavailable "valid" GPIOs will appear later */ 28 + if (!desc && gpio_is_valid(gpio)) 29 + return -EPROBE_DEFER; 30 + 27 31 err = gpiod_request(desc, label); 28 32 if (err) 29 33 return err; ··· 66 62 67 63 int gpio_request(unsigned gpio, const char *label) 68 64 { 69 - return gpiod_request(gpio_to_desc(gpio), label); 65 + struct gpio_desc *desc = gpio_to_desc(gpio); 66 + 67 + /* Compatibility: assume unavailable "valid" GPIOs will appear later */ 68 + if (!desc && gpio_is_valid(gpio)) 69 + return -EPROBE_DEFER; 70 + 71 + return gpiod_request(desc, label); 70 72 } 71 73 EXPORT_SYMBOL_GPL(gpio_request); 72 74
+3 -3
drivers/gpio/gpiolib-sysfs.c
··· 41 41 static ssize_t gpio_direction_show(struct device *dev, 42 42 struct device_attribute *attr, char *buf) 43 43 { 44 - const struct gpio_desc *desc = dev_get_drvdata(dev); 44 + struct gpio_desc *desc = dev_get_drvdata(dev); 45 45 ssize_t status; 46 46 47 47 mutex_lock(&sysfs_lock); ··· 161 161 desc->flags &= ~GPIO_TRIGGER_MASK; 162 162 163 163 if (!gpio_flags) { 164 - gpio_unlock_as_irq(desc->chip, gpio_chip_hwgpio(desc)); 164 + gpiochip_unlock_as_irq(desc->chip, gpio_chip_hwgpio(desc)); 165 165 ret = 0; 166 166 goto free_id; 167 167 } ··· 200 200 if (ret < 0) 201 201 goto free_id; 202 202 203 - ret = gpio_lock_as_irq(desc->chip, gpio_chip_hwgpio(desc)); 203 + ret = gpiochip_lock_as_irq(desc->chip, gpio_chip_hwgpio(desc)); 204 204 if (ret < 0) { 205 205 gpiod_warn(desc, "failed to flag the GPIO for IRQ\n"); 206 206 goto free_id;
+212 -29
drivers/gpio/gpiolib.c
··· 47 47 */ 48 48 DEFINE_SPINLOCK(gpio_lock); 49 49 50 - static struct gpio_desc gpio_desc[ARCH_NR_GPIOS]; 51 - 52 50 #define GPIO_OFFSET_VALID(chip, offset) (offset >= 0 && offset < chip->ngpio) 53 51 54 52 static DEFINE_MUTEX(gpio_lookup_lock); ··· 63 65 */ 64 66 struct gpio_desc *gpio_to_desc(unsigned gpio) 65 67 { 66 - if (WARN(!gpio_is_valid(gpio), "invalid GPIO %d\n", gpio)) 67 - return NULL; 68 - else 69 - return &gpio_desc[gpio]; 68 + struct gpio_chip *chip; 69 + unsigned long flags; 70 + 71 + spin_lock_irqsave(&gpio_lock, flags); 72 + 73 + list_for_each_entry(chip, &gpio_chips, list) { 74 + if (chip->base <= gpio && chip->base + chip->ngpio > gpio) { 75 + spin_unlock_irqrestore(&gpio_lock, flags); 76 + return &chip->desc[gpio - chip->base]; 77 + } 78 + } 79 + 80 + spin_unlock_irqrestore(&gpio_lock, flags); 81 + 82 + if (!gpio_is_valid(gpio)) 83 + WARN(1, "invalid GPIO %d\n", gpio); 84 + 85 + return NULL; 70 86 } 71 87 EXPORT_SYMBOL_GPL(gpio_to_desc); 72 88 ··· 103 91 */ 104 92 int desc_to_gpio(const struct gpio_desc *desc) 105 93 { 106 - return desc - &gpio_desc[0]; 94 + return desc->chip->base + (desc - &desc->chip->desc[0]); 107 95 } 108 96 EXPORT_SYMBOL_GPL(desc_to_gpio); 109 97 ··· 150 138 * 151 139 * This function may sleep if gpiod_cansleep() is true. 152 140 */ 153 - int gpiod_get_direction(const struct gpio_desc *desc) 141 + int gpiod_get_direction(struct gpio_desc *desc) 154 142 { 155 143 struct gpio_chip *chip; 156 144 unsigned offset; ··· 166 154 if (status > 0) { 167 155 /* GPIOF_DIR_IN, or other positive */ 168 156 status = 1; 169 - /* FLAG_IS_OUT is just a cache of the result of get_direction(), 170 - * so it does not affect constness per se */ 171 - clear_bit(FLAG_IS_OUT, &((struct gpio_desc *)desc)->flags); 157 + clear_bit(FLAG_IS_OUT, &desc->flags); 172 158 } 173 159 if (status == 0) { 174 160 /* GPIOF_DIR_OUT */ 175 - set_bit(FLAG_IS_OUT, &((struct gpio_desc *)desc)->flags); 161 + set_bit(FLAG_IS_OUT, &desc->flags); 176 162 } 177 163 return status; 178 164 } ··· 216 206 /** 217 207 * gpiochip_add() - register a gpio_chip 218 208 * @chip: the chip to register, with chip->base initialized 219 - * Context: potentially before irqs or kmalloc will work 209 + * Context: potentially before irqs will work 220 210 * 221 211 * Returns a negative errno if the chip can't be registered, such as 222 212 * because the chip->base is invalid or already associated with a ··· 236 226 int status = 0; 237 227 unsigned id; 238 228 int base = chip->base; 229 + struct gpio_desc *descs; 239 230 240 - if ((!gpio_is_valid(base) || !gpio_is_valid(base + chip->ngpio - 1)) 241 - && base >= 0) { 242 - status = -EINVAL; 243 - goto fail; 244 - } 231 + descs = kcalloc(chip->ngpio, sizeof(descs[0]), GFP_KERNEL); 232 + if (!descs) 233 + return -ENOMEM; 245 234 246 235 spin_lock_irqsave(&gpio_lock, flags); 247 236 ··· 256 247 status = gpiochip_add_to_list(chip); 257 248 258 249 if (status == 0) { 259 - chip->desc = &gpio_desc[chip->base]; 260 - 261 250 for (id = 0; id < chip->ngpio; id++) { 262 - struct gpio_desc *desc = &chip->desc[id]; 251 + struct gpio_desc *desc = &descs[id]; 263 252 desc->chip = chip; 264 253 265 254 /* REVISIT: most hardware initializes GPIOs as ··· 272 265 : 0; 273 266 } 274 267 } 268 + 269 + chip->desc = descs; 275 270 276 271 spin_unlock_irqrestore(&gpio_lock, flags); 277 272 ··· 300 291 unlock: 301 292 spin_unlock_irqrestore(&gpio_lock, flags); 302 293 fail: 294 + kfree(descs); 295 + chip->desc = NULL; 296 + 303 297 /* failures here can mean systems won't boot... */ 304 298 pr_err("%s: GPIOs %d..%d (%s) failed to register\n", __func__, 305 299 chip->base, chip->base + chip->ngpio - 1, ··· 343 331 list_del(&chip->list); 344 332 spin_unlock_irqrestore(&gpio_lock, flags); 345 333 gpiochip_unexport(chip); 334 + 335 + kfree(chip->desc); 336 + chip->desc = NULL; 346 337 } 347 338 EXPORT_SYMBOL_GPL(gpiochip_remove); 348 339 ··· 510 495 { 511 496 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 512 497 513 - if (gpio_lock_as_irq(chip, d->hwirq)) { 498 + if (gpiochip_lock_as_irq(chip, d->hwirq)) { 514 499 chip_err(chip, 515 500 "unable to lock HW IRQ %lu for IRQ\n", 516 501 d->hwirq); ··· 523 508 { 524 509 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 525 510 526 - gpio_unlock_as_irq(chip, d->hwirq); 511 + gpiochip_unlock_as_irq(chip, d->hwirq); 527 512 } 528 513 529 514 static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset) ··· 1269 1254 chip->set(chip, gpio_chip_hwgpio(desc), value); 1270 1255 } 1271 1256 1257 + /* 1258 + * set multiple outputs on the same chip; 1259 + * use the chip's set_multiple function if available; 1260 + * otherwise set the outputs sequentially; 1261 + * @mask: bit mask array; one bit per output; BITS_PER_LONG bits per word 1262 + * defines which outputs are to be changed 1263 + * @bits: bit value array; one bit per output; BITS_PER_LONG bits per word 1264 + * defines the values the outputs specified by mask are to be set to 1265 + */ 1266 + static void gpio_chip_set_multiple(struct gpio_chip *chip, 1267 + unsigned long *mask, unsigned long *bits) 1268 + { 1269 + if (chip->set_multiple) { 1270 + chip->set_multiple(chip, mask, bits); 1271 + } else { 1272 + int i; 1273 + for (i = 0; i < chip->ngpio; i++) { 1274 + if (mask[BIT_WORD(i)] == 0) { 1275 + /* no more set bits in this mask word; 1276 + * skip ahead to the next word */ 1277 + i = (BIT_WORD(i) + 1) * BITS_PER_LONG - 1; 1278 + continue; 1279 + } 1280 + /* set outputs if the corresponding mask bit is set */ 1281 + if (__test_and_clear_bit(i, mask)) { 1282 + chip->set(chip, i, test_bit(i, bits)); 1283 + } 1284 + } 1285 + } 1286 + } 1287 + 1288 + static void gpiod_set_array_priv(bool raw, bool can_sleep, 1289 + unsigned int array_size, 1290 + struct gpio_desc **desc_array, 1291 + int *value_array) 1292 + { 1293 + int i = 0; 1294 + 1295 + while (i < array_size) { 1296 + struct gpio_chip *chip = desc_array[i]->chip; 1297 + unsigned long mask[BITS_TO_LONGS(chip->ngpio)]; 1298 + unsigned long bits[BITS_TO_LONGS(chip->ngpio)]; 1299 + int count = 0; 1300 + 1301 + if (!can_sleep) { 1302 + WARN_ON(chip->can_sleep); 1303 + } 1304 + memset(mask, 0, sizeof(mask)); 1305 + do { 1306 + struct gpio_desc *desc = desc_array[i]; 1307 + int hwgpio = gpio_chip_hwgpio(desc); 1308 + int value = value_array[i]; 1309 + 1310 + if (!raw && test_bit(FLAG_ACTIVE_LOW, &desc->flags)) 1311 + value = !value; 1312 + trace_gpio_value(desc_to_gpio(desc), 0, value); 1313 + /* 1314 + * collect all normal outputs belonging to the same chip 1315 + * open drain and open source outputs are set individually 1316 + */ 1317 + if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { 1318 + _gpio_set_open_drain_value(desc,value); 1319 + } else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { 1320 + _gpio_set_open_source_value(desc, value); 1321 + } else { 1322 + __set_bit(hwgpio, mask); 1323 + if (value) { 1324 + __set_bit(hwgpio, bits); 1325 + } else { 1326 + __clear_bit(hwgpio, bits); 1327 + } 1328 + count++; 1329 + } 1330 + i++; 1331 + } while ((i < array_size) && (desc_array[i]->chip == chip)); 1332 + /* push collected bits to outputs */ 1333 + if (count != 0) { 1334 + gpio_chip_set_multiple(chip, mask, bits); 1335 + } 1336 + } 1337 + } 1338 + 1272 1339 /** 1273 1340 * gpiod_set_raw_value() - assign a gpio's raw value 1274 1341 * @desc: gpio whose value will be assigned ··· 1396 1299 EXPORT_SYMBOL_GPL(gpiod_set_value); 1397 1300 1398 1301 /** 1302 + * gpiod_set_raw_array() - assign values to an array of GPIOs 1303 + * @array_size: number of elements in the descriptor / value arrays 1304 + * @desc_array: array of GPIO descriptors whose values will be assigned 1305 + * @value_array: array of values to assign 1306 + * 1307 + * Set the raw values of the GPIOs, i.e. the values of the physical lines 1308 + * without regard for their ACTIVE_LOW status. 1309 + * 1310 + * This function should be called from contexts where we cannot sleep, and will 1311 + * complain if the GPIO chip functions potentially sleep. 1312 + */ 1313 + void gpiod_set_raw_array(unsigned int array_size, 1314 + struct gpio_desc **desc_array, int *value_array) 1315 + { 1316 + if (!desc_array) 1317 + return; 1318 + gpiod_set_array_priv(true, false, array_size, desc_array, value_array); 1319 + } 1320 + EXPORT_SYMBOL_GPL(gpiod_set_raw_array); 1321 + 1322 + /** 1323 + * gpiod_set_array() - assign values to an array of GPIOs 1324 + * @array_size: number of elements in the descriptor / value arrays 1325 + * @desc_array: array of GPIO descriptors whose values will be assigned 1326 + * @value_array: array of values to assign 1327 + * 1328 + * Set the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status 1329 + * into account. 1330 + * 1331 + * This function should be called from contexts where we cannot sleep, and will 1332 + * complain if the GPIO chip functions potentially sleep. 1333 + */ 1334 + void gpiod_set_array(unsigned int array_size, 1335 + struct gpio_desc **desc_array, int *value_array) 1336 + { 1337 + if (!desc_array) 1338 + return; 1339 + gpiod_set_array_priv(false, false, array_size, desc_array, value_array); 1340 + } 1341 + EXPORT_SYMBOL_GPL(gpiod_set_array); 1342 + 1343 + /** 1399 1344 * gpiod_cansleep() - report whether gpio value access may sleep 1400 1345 * @desc: gpio to check 1401 1346 * ··· 1471 1332 EXPORT_SYMBOL_GPL(gpiod_to_irq); 1472 1333 1473 1334 /** 1474 - * gpio_lock_as_irq() - lock a GPIO to be used as IRQ 1335 + * gpiochip_lock_as_irq() - lock a GPIO to be used as IRQ 1475 1336 * @chip: the chip the GPIO to lock belongs to 1476 1337 * @offset: the offset of the GPIO to lock as IRQ 1477 1338 * 1478 1339 * This is used directly by GPIO drivers that want to lock down 1479 1340 * a certain GPIO line to be used for IRQs. 1480 1341 */ 1481 - int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 1342 + int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 1482 1343 { 1483 1344 if (offset >= chip->ngpio) 1484 1345 return -EINVAL; ··· 1493 1354 set_bit(FLAG_USED_AS_IRQ, &chip->desc[offset].flags); 1494 1355 return 0; 1495 1356 } 1496 - EXPORT_SYMBOL_GPL(gpio_lock_as_irq); 1357 + EXPORT_SYMBOL_GPL(gpiochip_lock_as_irq); 1497 1358 1498 1359 /** 1499 - * gpio_unlock_as_irq() - unlock a GPIO used as IRQ 1360 + * gpiochip_unlock_as_irq() - unlock a GPIO used as IRQ 1500 1361 * @chip: the chip the GPIO to lock belongs to 1501 1362 * @offset: the offset of the GPIO to lock as IRQ 1502 1363 * 1503 1364 * This is used directly by GPIO drivers that want to indicate 1504 1365 * that a certain GPIO is no longer used exclusively for IRQ. 1505 1366 */ 1506 - void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) 1367 + void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) 1507 1368 { 1508 1369 if (offset >= chip->ngpio) 1509 1370 return; 1510 1371 1511 1372 clear_bit(FLAG_USED_AS_IRQ, &chip->desc[offset].flags); 1512 1373 } 1513 - EXPORT_SYMBOL_GPL(gpio_unlock_as_irq); 1374 + EXPORT_SYMBOL_GPL(gpiochip_unlock_as_irq); 1514 1375 1515 1376 /** 1516 1377 * gpiod_get_raw_value_cansleep() - return a gpio's raw value ··· 1595 1456 _gpiod_set_raw_value(desc, value); 1596 1457 } 1597 1458 EXPORT_SYMBOL_GPL(gpiod_set_value_cansleep); 1459 + 1460 + /** 1461 + * gpiod_set_raw_array_cansleep() - assign values to an array of GPIOs 1462 + * @array_size: number of elements in the descriptor / value arrays 1463 + * @desc_array: array of GPIO descriptors whose values will be assigned 1464 + * @value_array: array of values to assign 1465 + * 1466 + * Set the raw values of the GPIOs, i.e. the values of the physical lines 1467 + * without regard for their ACTIVE_LOW status. 1468 + * 1469 + * This function is to be called from contexts that can sleep. 1470 + */ 1471 + void gpiod_set_raw_array_cansleep(unsigned int array_size, 1472 + struct gpio_desc **desc_array, 1473 + int *value_array) 1474 + { 1475 + might_sleep_if(extra_checks); 1476 + if (!desc_array) 1477 + return; 1478 + gpiod_set_array_priv(true, true, array_size, desc_array, value_array); 1479 + } 1480 + EXPORT_SYMBOL_GPL(gpiod_set_raw_array_cansleep); 1481 + 1482 + /** 1483 + * gpiod_set_array_cansleep() - assign values to an array of GPIOs 1484 + * @array_size: number of elements in the descriptor / value arrays 1485 + * @desc_array: array of GPIO descriptors whose values will be assigned 1486 + * @value_array: array of values to assign 1487 + * 1488 + * Set the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status 1489 + * into account. 1490 + * 1491 + * This function is to be called from contexts that can sleep. 1492 + */ 1493 + void gpiod_set_array_cansleep(unsigned int array_size, 1494 + struct gpio_desc **desc_array, 1495 + int *value_array) 1496 + { 1497 + might_sleep_if(extra_checks); 1498 + if (!desc_array) 1499 + return; 1500 + gpiod_set_array_priv(false, true, array_size, desc_array, value_array); 1501 + } 1502 + EXPORT_SYMBOL_GPL(gpiod_set_array_cansleep); 1598 1503 1599 1504 /** 1600 1505 * gpiod_add_lookup_table() - register GPIO device consumers
+13 -24
drivers/net/phy/mdio-mux-gpio.c
··· 14 14 #include <linux/mdio-mux.h> 15 15 #include <linux/of_gpio.h> 16 16 17 - #define DRV_VERSION "1.0" 17 + #define DRV_VERSION "1.1" 18 18 #define DRV_DESCRIPTION "GPIO controlled MDIO bus multiplexer driver" 19 19 20 20 #define MDIO_MUX_GPIO_MAX_BITS 8 21 21 22 22 struct mdio_mux_gpio_state { 23 - int gpio[MDIO_MUX_GPIO_MAX_BITS]; 23 + struct gpio_desc *gpio[MDIO_MUX_GPIO_MAX_BITS]; 24 24 unsigned int num_gpios; 25 25 void *mux_handle; 26 26 }; ··· 28 28 static int mdio_mux_gpio_switch_fn(int current_child, int desired_child, 29 29 void *data) 30 30 { 31 - int change; 31 + int values[MDIO_MUX_GPIO_MAX_BITS]; 32 32 unsigned int n; 33 33 struct mdio_mux_gpio_state *s = data; 34 34 35 35 if (current_child == desired_child) 36 36 return 0; 37 37 38 - change = current_child == -1 ? -1 : current_child ^ desired_child; 39 - 40 38 for (n = 0; n < s->num_gpios; n++) { 41 - if (change & 1) 42 - gpio_set_value_cansleep(s->gpio[n], 43 - (desired_child & 1) != 0); 44 - change >>= 1; 45 - desired_child >>= 1; 39 + values[n] = (desired_child >> n) & 1; 46 40 } 41 + gpiod_set_array_cansleep(s->num_gpios, s->gpio, values); 47 42 48 43 return 0; 49 44 } 50 45 51 46 static int mdio_mux_gpio_probe(struct platform_device *pdev) 52 47 { 53 - enum of_gpio_flags f; 54 48 struct mdio_mux_gpio_state *s; 55 49 int num_gpios; 56 50 unsigned int n; ··· 64 70 s->num_gpios = num_gpios; 65 71 66 72 for (n = 0; n < num_gpios; ) { 67 - int gpio = of_get_gpio_flags(pdev->dev.of_node, n, &f); 68 - if (gpio < 0) { 69 - r = (gpio == -ENODEV) ? -EPROBE_DEFER : gpio; 73 + struct gpio_desc *gpio = gpiod_get_index(&pdev->dev, NULL, n, 74 + GPIOD_OUT_LOW); 75 + if (IS_ERR(gpio)) { 76 + r = PTR_ERR(gpio); 70 77 goto err; 71 78 } 72 79 s->gpio[n] = gpio; 73 - 74 80 n++; 75 - 76 - r = gpio_request(gpio, "mdio_mux_gpio"); 77 - if (r) 78 - goto err; 79 - 80 - r = gpio_direction_output(gpio, 0); 81 - if (r) 82 - goto err; 83 81 } 84 82 85 83 r = mdio_mux_init(&pdev->dev, ··· 84 98 err: 85 99 while (n) { 86 100 n--; 87 - gpio_free(s->gpio[n]); 101 + gpiod_put(s->gpio[n]); 88 102 } 89 103 return r; 90 104 } 91 105 92 106 static int mdio_mux_gpio_remove(struct platform_device *pdev) 93 107 { 108 + unsigned int n; 94 109 struct mdio_mux_gpio_state *s = dev_get_platdata(&pdev->dev); 95 110 mdio_mux_uninit(s->mux_handle); 111 + for (n = 0; n < s->num_gpios; n++) 112 + gpiod_put(s->gpio[n]); 96 113 return 0; 97 114 } 98 115
+2 -2
drivers/pinctrl/pinctrl-at91.c
··· 1471 1471 unsigned pin = d->hwirq; 1472 1472 int ret; 1473 1473 1474 - ret = gpio_lock_as_irq(&at91_gpio->chip, pin); 1474 + ret = gpiochip_lock_as_irq(&at91_gpio->chip, pin); 1475 1475 if (ret) { 1476 1476 dev_err(at91_gpio->chip.dev, "unable to lock pind %lu IRQ\n", 1477 1477 d->hwirq); ··· 1487 1487 unsigned pin = d->hwirq; 1488 1488 1489 1489 gpio_irq_mask(d); 1490 - gpio_unlock_as_irq(&at91_gpio->chip, pin); 1490 + gpiochip_unlock_as_irq(&at91_gpio->chip, pin); 1491 1491 } 1492 1492 1493 1493 #ifdef CONFIG_PM
+2 -2
drivers/pinctrl/samsung/pinctrl-exynos.c
··· 174 174 unsigned int con; 175 175 int ret; 176 176 177 - ret = gpio_lock_as_irq(&bank->gpio_chip, irqd->hwirq); 177 + ret = gpiochip_lock_as_irq(&bank->gpio_chip, irqd->hwirq); 178 178 if (ret) { 179 179 dev_err(bank->gpio_chip.dev, "unable to lock pin %s-%lu IRQ\n", 180 180 bank->name, irqd->hwirq); ··· 227 227 228 228 spin_unlock_irqrestore(&bank->slock, flags); 229 229 230 - gpio_unlock_as_irq(&bank->gpio_chip, irqd->hwirq); 230 + gpiochip_unlock_as_irq(&bank->gpio_chip, irqd->hwirq); 231 231 } 232 232 233 233 /*
+3 -3
drivers/pinctrl/sunxi/pinctrl-sunxi.c
··· 553 553 if (!func) 554 554 return -EINVAL; 555 555 556 - ret = gpio_lock_as_irq(pctl->chip, 556 + ret = gpiochip_lock_as_irq(pctl->chip, 557 557 pctl->irq_array[d->hwirq] - pctl->desc->pin_base); 558 558 if (ret) { 559 559 dev_err(pctl->dev, "unable to lock HW IRQ %lu for IRQ\n", ··· 571 571 { 572 572 struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); 573 573 574 - gpio_unlock_as_irq(pctl->chip, 575 - pctl->irq_array[d->hwirq] - pctl->desc->pin_base); 574 + gpiochip_unlock_as_irq(pctl->chip, 575 + pctl->irq_array[d->hwirq] - pctl->desc->pin_base); 576 576 } 577 577 578 578 static int sunxi_pinctrl_irq_set_type(struct irq_data *d, unsigned int type)
+9 -3
drivers/tty/serial/serial_mctrl_gpio.c
··· 44 44 void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl) 45 45 { 46 46 enum mctrl_gpio_idx i; 47 + struct gpio_desc *desc_array[UART_GPIO_MAX]; 48 + int value_array[UART_GPIO_MAX]; 49 + unsigned int count = 0; 47 50 48 51 if (IS_ERR_OR_NULL(gpios)) 49 52 return; 50 53 51 54 for (i = 0; i < UART_GPIO_MAX; i++) 52 55 if (!IS_ERR_OR_NULL(gpios->gpio[i]) && 53 - mctrl_gpios_desc[i].dir_out) 54 - gpiod_set_value(gpios->gpio[i], 55 - !!(mctrl & mctrl_gpios_desc[i].mctrl)); 56 + mctrl_gpios_desc[i].dir_out) { 57 + desc_array[count] = gpios->gpio[i]; 58 + value_array[count] = !!(mctrl & mctrl_gpios_desc[i].mctrl); 59 + count++; 60 + } 61 + gpiod_set_array(count, desc_array, value_array); 56 62 } 57 63 EXPORT_SYMBOL_GPL(mctrl_gpio_set); 58 64
+4 -3
include/linux/gpio.h
··· 216 216 return -EINVAL; 217 217 } 218 218 219 - static inline int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 219 + static inline int gpiochip_lock_as_irq(struct gpio_chip *chip, 220 + unsigned int offset) 220 221 { 221 222 WARN_ON(1); 222 223 return -EINVAL; 223 224 } 224 225 225 - static inline void gpio_unlock_as_irq(struct gpio_chip *chip, 226 - unsigned int offset) 226 + static inline void gpiochip_unlock_as_irq(struct gpio_chip *chip, 227 + unsigned int offset) 227 228 { 228 229 WARN_ON(1); 229 230 }
+39 -1
include/linux/gpio/consumer.h
··· 66 66 unsigned int index, enum gpiod_flags flags); 67 67 void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); 68 68 69 - int gpiod_get_direction(const struct gpio_desc *desc); 69 + int gpiod_get_direction(struct gpio_desc *desc); 70 70 int gpiod_direction_input(struct gpio_desc *desc); 71 71 int gpiod_direction_output(struct gpio_desc *desc, int value); 72 72 int gpiod_direction_output_raw(struct gpio_desc *desc, int value); ··· 74 74 /* Value get/set from non-sleeping context */ 75 75 int gpiod_get_value(const struct gpio_desc *desc); 76 76 void gpiod_set_value(struct gpio_desc *desc, int value); 77 + void gpiod_set_array(unsigned int array_size, 78 + struct gpio_desc **desc_array, int *value_array); 77 79 int gpiod_get_raw_value(const struct gpio_desc *desc); 78 80 void gpiod_set_raw_value(struct gpio_desc *desc, int value); 81 + void gpiod_set_raw_array(unsigned int array_size, 82 + struct gpio_desc **desc_array, int *value_array); 79 83 80 84 /* Value get/set from sleeping context */ 81 85 int gpiod_get_value_cansleep(const struct gpio_desc *desc); 82 86 void gpiod_set_value_cansleep(struct gpio_desc *desc, int value); 87 + void gpiod_set_array_cansleep(unsigned int array_size, 88 + struct gpio_desc **desc_array, 89 + int *value_array); 83 90 int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc); 84 91 void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value); 92 + void gpiod_set_raw_array_cansleep(unsigned int array_size, 93 + struct gpio_desc **desc_array, 94 + int *value_array); 85 95 86 96 int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); 87 97 ··· 227 217 /* GPIO can never have been requested */ 228 218 WARN_ON(1); 229 219 } 220 + static inline void gpiod_set_array(unsigned int array_size, 221 + struct gpio_desc **desc_array, 222 + int *value_array) 223 + { 224 + /* GPIO can never have been requested */ 225 + WARN_ON(1); 226 + } 230 227 static inline int gpiod_get_raw_value(const struct gpio_desc *desc) 231 228 { 232 229 /* GPIO can never have been requested */ ··· 241 224 return 0; 242 225 } 243 226 static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value) 227 + { 228 + /* GPIO can never have been requested */ 229 + WARN_ON(1); 230 + } 231 + static inline void gpiod_set_raw_array(unsigned int array_size, 232 + struct gpio_desc **desc_array, 233 + int *value_array) 244 234 { 245 235 /* GPIO can never have been requested */ 246 236 WARN_ON(1); ··· 264 240 /* GPIO can never have been requested */ 265 241 WARN_ON(1); 266 242 } 243 + static inline void gpiod_set_array_cansleep(unsigned int array_size, 244 + struct gpio_desc **desc_array, 245 + int *value_array) 246 + { 247 + /* GPIO can never have been requested */ 248 + WARN_ON(1); 249 + } 267 250 static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) 268 251 { 269 252 /* GPIO can never have been requested */ ··· 279 248 } 280 249 static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, 281 250 int value) 251 + { 252 + /* GPIO can never have been requested */ 253 + WARN_ON(1); 254 + } 255 + static inline void gpiod_set_raw_array_cansleep(unsigned int array_size, 256 + struct gpio_desc **desc_array, 257 + int *value_array) 282 258 { 283 259 /* GPIO can never have been requested */ 284 260 WARN_ON(1);
+6 -2
include/linux/gpio/driver.h
··· 32 32 * @get: returns value for signal "offset"; for output signals this 33 33 * returns either the value actually sensed, or zero 34 34 * @set: assigns output value for signal "offset" 35 + * @set_multiple: assigns output values for multiple signals defined by "mask" 35 36 * @set_debounce: optional hook for setting debounce time for specified gpio in 36 37 * interrupt triggered gpio chips 37 38 * @to_irq: optional hook supporting non-static gpio_to_irq() mappings; ··· 90 89 unsigned offset); 91 90 void (*set)(struct gpio_chip *chip, 92 91 unsigned offset, int value); 92 + void (*set_multiple)(struct gpio_chip *chip, 93 + unsigned long *mask, 94 + unsigned long *bits); 93 95 int (*set_debounce)(struct gpio_chip *chip, 94 96 unsigned offset, 95 97 unsigned debounce); ··· 153 149 int (*match)(struct gpio_chip *chip, void *data)); 154 150 155 151 /* lock/unlock as IRQ */ 156 - int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset); 157 - void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset); 152 + int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset); 153 + void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset); 158 154 159 155 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); 160 156